Fix #268 - Use the User's profile directory under Windows

This commit is contained in:
Sebastian Wilzbach 2018-04-02 02:16:32 +02:00
parent 845f363d79
commit 75274faedb

View file

@ -407,24 +407,28 @@ version (OSX) version = useXDG;
*/ */
string getDefaultConfigurationLocation() string getDefaultConfigurationLocation()
{ {
import std.process : environment;
import std.exception : enforce;
version (useXDG) version (useXDG)
{ {
import std.process : environment;
string configDir = environment.get("XDG_CONFIG_HOME", null); string configDir = environment.get("XDG_CONFIG_HOME", null);
if (configDir is null) if (configDir is null)
{ {
configDir = environment.get("HOME", null); configDir = environment.get("HOME", null);
if (configDir is null) enforce(configDir !is null, "Both $XDG_CONFIG_HOME and $HOME are unset");
throw new Exception("Both $XDG_CONFIG_HOME and $HOME are unset");
configDir = buildPath(configDir, ".config", "dscanner", CONFIG_FILE_NAME); configDir = buildPath(configDir, ".config", "dscanner", CONFIG_FILE_NAME);
} }
else else
configDir = buildPath(configDir, "dscanner", CONFIG_FILE_NAME); configDir = buildPath(configDir, "dscanner", CONFIG_FILE_NAME);
return configDir; return configDir;
} }
else version (Windows) else version(Windows)
return CONFIG_FILE_NAME; {
string configDir = environment.get("APPDATA", null);
enforce(configDir !is null, "%APPDATA% is unset");
configDir = buildPath(configDir, "dscanner", CONFIG_FILE_NAME);
return configDir;
}
} }
/** /**