Browse Source

Change the default location of the configuration file.

The location of the PRISM configuration file is now OS-dependent. On UNIX-like systems, following the XDG base directory specification, it is prism.settings in ~/.config (or in $XDG_CONFIG_HOME if that overrides it). On OS X, it is prism.settings in ~/Library/Preferences. On anything else it remains in ~/.prism.

If an existing configuration file exists in ~/.prism, that file is still used regardless of the OS.

Closes #38.
master
hentom 8 years ago
committed by Dave Parker
parent
commit
52ff6bad3e
  1. 38
      prism/src/prism/PrismSettings.java

38
prism/src/prism/PrismSettings.java

@ -630,7 +630,43 @@ public class PrismSettings implements Observer
public File getLocationForSettingsFile()
{
return new File(System.getProperty("user.home")+File.separator+".prism");
File legacyConfigFile = new File(System.getProperty("user.home") +
File.separator + ".prism");
if (legacyConfigFile.exists() && !legacyConfigFile.isDirectory())
{
return legacyConfigFile;
}
// Check for operating system, try XDG base directory specification if
// UNIX-like system (except for MacOS) is found
String os = System.getProperty("os.name").toLowerCase();
File config;
if (os.indexOf("win") >= 0) { // Windows
// use "$HOME\.prism"
config = new File(System.getProperty("user.home") +
File.separator + ".prism");
} else if (os.indexOf("mac") >= 0) { // MacOS
// use "$HOME/Library/Preferences/prism/prism.settings"
config = new File(System.getProperty("user.home") +
"/Library/Preferences/prism.settings");
} else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 ||
os.indexOf("aix") >= 0 || os.indexOf("sunos") >= 0 ||
os.indexOf("bsd") >= 0) { // Linux, AIX, Solaris, *BSD
// check for $XDG_CONFIG_HOME
String configBase = System.getenv("XDG_CONFIG_HOME");
if (configBase == null) {
configBase = System.getProperty("user.home") + "/.config";
}
if (configBase.endsWith("/")) {
configBase = configBase.substring(0, configBase.length() - 1);
}
config = new File(configBase + "/prism.settings");
} else { // unknown operating system
// use "$HOME\.prism"
config = new File(System.getProperty("user.home") +
File.separator + ".prism");
}
return config;
}
public synchronized void saveSettingsFile() throws PrismException

Loading…
Cancel
Save