diff options
author | Johannes Schickel | 2016-01-29 19:56:20 +0100 |
---|---|---|
committer | Johannes Schickel | 2016-02-02 09:16:40 +0100 |
commit | dde89c36f53558c64c5fce2c87850028b89ca45d (patch) | |
tree | 3dd8acdec657a5f23168159c0e723a0c59922a98 /backends/platform/sdl/posix/posix.cpp | |
parent | 79acfd28e9e774631f2e0af2bba34a3c0de9b40f (diff) | |
download | scummvm-rg350-dde89c36f53558c64c5fce2c87850028b89ca45d.tar.gz scummvm-rg350-dde89c36f53558c64c5fce2c87850028b89ca45d.tar.bz2 scummvm-rg350-dde89c36f53558c64c5fce2c87850028b89ca45d.zip |
POSIX: Move default config file location to '$XDG_CONFIG_HOME/scummvm/scummvm.ini'.
This is what the XDG Base Directory Specification suggests to use. We still
use the old location of '~/.scummvmrc' in case that is present.
This tackles an aspect of bug #6036 "POSIX: Use XDG dirs instead of HOME".
Diffstat (limited to 'backends/platform/sdl/posix/posix.cpp')
-rw-r--r-- | backends/platform/sdl/posix/posix.cpp | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index 4812d34a5a..a082a2218e 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -150,11 +150,54 @@ bool OSystem_POSIX::hasFeature(Feature f) { Common::String OSystem_POSIX::getDefaultConfigFileName() { Common::String configFile; - // On POSIX type systems, by default we store the config file inside - // to the HOME directory of the user. - const char *home = getenv("HOME"); - if (home != NULL && (strlen(home) + 1 + _baseConfigName.size()) < MAXPATHLEN) { - configFile = Common::String::format("%s/%s", home, _baseConfigName.c_str()); + Common::String prefix; +#ifdef MACOSX + prefix = getenv("HOME"); +#elif !defined(SAMSUNGTV) + const char *envVar; + // Our old configuration file path for POSIX systems was ~/.scummvmrc. + // If that file exists, we still use it. + envVar = getenv("HOME"); + if (envVar && *envVar) { + configFile = envVar; + configFile += '/'; + configFile += ".scummvmrc"; + + if (configFile.size() < MAXPATHLEN) { + struct stat sb; + if (stat(configFile.c_str(), &sb) == 0) { + return configFile; + } + } + } + + // On POSIX systems we follow the XDG Base Directory Specification for + // where to store files. The version we based our code upon can be found + // over here: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html + envVar = getenv("XDG_CONFIG_HOME"); + if (!envVar || !*envVar) { + envVar = getenv("HOME"); + if (!envVar) { + return 0; + } + + if (assureDirectoryExists(".config", envVar)) { + prefix = envVar; + prefix += "/.config"; + } + } else { + prefix = envVar; + } + + if (!prefix.empty() && assureDirectoryExists("scummvm", prefix.c_str())) { + prefix += "/scummvm"; + } +#endif + + if (!prefix.empty() && (prefix.size() + 1 + _baseConfigName.size()) < MAXPATHLEN) { + configFile = prefix; + configFile += '/'; + configFile += _baseConfigName; } else { configFile = _baseConfigName; } |