diff options
-rw-r--r-- | README | 10 | ||||
-rw-r--r-- | backends/platform/sdl/posix/posix.cpp | 53 | ||||
-rw-r--r-- | backends/platform/sdl/posix/posix.h | 2 |
3 files changed, 58 insertions, 7 deletions
@@ -2329,7 +2329,15 @@ By default, the configuration file is saved in, and loaded from: previous default location of '<windir>\scummvm.ini' will be kept. Unix: - ~/.scummvmrc + We follow the XDG Base Directory Specification. This means our + configuration can be found in: + $XDG_CONFIG_HOME/scummvm/scummvm.ini + + If XDG_CONFIG_HOME is not defined or empty, '~/.config' will be used + as value for XDG_CONFIG_HOME in accordance with the specification. + + If an earlier version of ScummVM was installed on your system, the + previous default location of '~/.scummvmrc' will be kept. Mac OS X: ~/Library/Preferences/ScummVM Preferences 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; } diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h index 01a01528cd..f67515ddb3 100644 --- a/backends/platform/sdl/posix/posix.h +++ b/backends/platform/sdl/posix/posix.h @@ -28,7 +28,7 @@ class OSystem_POSIX : public OSystem_SDL { public: // Let the subclasses be able to change _baseConfigName in the constructor - OSystem_POSIX(Common::String baseConfigName = ".scummvmrc"); + OSystem_POSIX(Common::String baseConfigName = "scummvm.ini"); virtual ~OSystem_POSIX() {} virtual bool hasFeature(Feature f); |