diff options
author | Max Horn | 2003-11-10 23:17:11 +0000 |
---|---|---|
committer | Max Horn | 2003-11-10 23:17:11 +0000 |
commit | 5c2a3da7f2f8f45e20b732defbaed7aa47af00c8 (patch) | |
tree | 8b973869cb90d51e08d8770f4c56ecca1ca2aa9e | |
parent | deef1ef32b2f4dbfe87bd5a3b9268dc77beca7db (diff) | |
download | scummvm-rg350-5c2a3da7f2f8f45e20b732defbaed7aa47af00c8.tar.gz scummvm-rg350-5c2a3da7f2f8f45e20b732defbaed7aa47af00c8.tar.bz2 scummvm-rg350-5c2a3da7f2f8f45e20b732defbaed7aa47af00c8.zip |
fix for bug #833537 (Config manager saves "save_slot")
svn-id: r11254
-rw-r--r-- | base/gameDetector.cpp | 54 | ||||
-rw-r--r-- | common/config-manager.cpp | 56 | ||||
-rw-r--r-- | common/config-manager.h | 5 |
3 files changed, 67 insertions, 48 deletions
diff --git a/base/gameDetector.cpp b/base/gameDetector.cpp index ef12840b24..3db94c4cd9 100644 --- a/base/gameDetector.cpp +++ b/base/gameDetector.cpp @@ -279,6 +279,9 @@ GameSettings GameDetector::findGame(const String &gameName, const Plugin **plugi continue; \ } + +static const Common::String &kTransientDomain = Common::ConfigManager::kTransientDomain; + void GameDetector::parseCommandLine(int argc, char **argv) { int i; char *s; @@ -312,14 +315,15 @@ void GameDetector::parseCommandLine(int argc, char **argv) { s += 2; DO_OPTION('b', "boot-param") - ConfMan.set("boot_param", (int)strtol(option, 0, 10)); + ConfMan.set("boot_param", (int)strtol(option, 0, 10), kTransientDomain); END_OPTION DO_OPTION_OPT('d', "debuglevel") if (option != NULL) - ConfMan.set("debuglevel", (int)strtol(option, 0, 10)); - if (ConfMan.getInt("debuglevel")) - printf("Debuglevel (from command line): %d\n", ConfMan.getInt("debuglevel")); + ConfMan.set("debuglevel", (int)strtol(option, 0, 10), kTransientDomain); + int debuglevel = ConfMan.getInt("debuglevel"); + if (debuglevel) + printf("Debuglevel (from command line): %d\n", debuglevel); else printf("Debuglevel (from command line): 0 - Game only\n"); END_OPTION @@ -331,11 +335,11 @@ void GameDetector::parseCommandLine(int argc, char **argv) { // Available driver: ..." if (parseMusicDriver(option) < 0) goto ShowHelpAndExit; - ConfMan.set("music_driver", option); + ConfMan.set("music_driver", option, kTransientDomain); END_OPTION DO_OPTION_BOOL('f', "fullscreen") - ConfMan.set("fullscreen", cmdValue); + ConfMan.set("fullscreen", cmdValue, kTransientDomain); END_OPTION DO_OPTION('g', "gfx-mode") @@ -346,7 +350,7 @@ void GameDetector::parseCommandLine(int argc, char **argv) { // Available graphic modes: ..." if (gfx_mode == -1) goto ShowHelpAndExit; - ConfMan.set("gfx_mode", option); + ConfMan.set("gfx_mode", option, kTransientDomain); END_OPTION DO_OPTION_CMD('h', "help") @@ -355,30 +359,30 @@ void GameDetector::parseCommandLine(int argc, char **argv) { END_OPTION DO_OPTION('m', "music-volume") - ConfMan.set("music_volume", (int)strtol(option, 0, 10)); + ConfMan.set("music_volume", (int)strtol(option, 0, 10), kTransientDomain); END_OPTION DO_OPTION_BOOL('n', "nosubtitles") - ConfMan.set("nosubtitles", cmdValue); + ConfMan.set("nosubtitles", cmdValue, kTransientDomain); END_OPTION DO_OPTION('o', "master-volume") - ConfMan.set("master_volume", (int)strtol(option, 0, 10)); + ConfMan.set("master_volume", (int)strtol(option, 0, 10), kTransientDomain); END_OPTION DO_OPTION('p', "path") // TODO: Verify whether the path is valid - ConfMan.set("path", option); + ConfMan.set("path", option, kTransientDomain); END_OPTION DO_OPTION('q', "language") if (Common::parseLanguage(option) == Common::UNK_LANG) goto ShowHelpAndExit; - ConfMan.set("language", option); + ConfMan.set("language", option, kTransientDomain); END_OPTION DO_OPTION('s', "sfx-volume") - ConfMan.set("sfx_volume", (int)strtol(option, 0, 10)); + ConfMan.set("sfx_volume", (int)strtol(option, 0, 10), kTransientDomain); END_OPTION DO_OPTION_CMD('t', "list-targets") @@ -396,7 +400,7 @@ void GameDetector::parseCommandLine(int argc, char **argv) { END_OPTION DO_OPTION('x', "save-slot") - ConfMan.set("save_slot", (option != NULL) ? (int)strtol(option, 0, 10) : 0); + ConfMan.set("save_slot", (option != NULL) ? (int)strtol(option, 0, 10) : 0, kTransientDomain); END_OPTION DO_OPTION_CMD('z', "list-games") @@ -405,11 +409,11 @@ void GameDetector::parseCommandLine(int argc, char **argv) { END_OPTION DO_LONG_OPTION("cdrom") - ConfMan.set("cdrom", (int)strtol(option, 0, 10)); + ConfMan.set("cdrom", (int)strtol(option, 0, 10), kTransientDomain); END_OPTION DO_LONG_OPTION_OPT("joystick") - ConfMan.set("joystick_num", (option != NULL) ? (int)strtol(option, 0, 10) : 0); + ConfMan.set("joystick_num", (option != NULL) ? (int)strtol(option, 0, 10) : 0, kTransientDomain); END_OPTION DO_LONG_OPTION("platform") @@ -417,19 +421,19 @@ void GameDetector::parseCommandLine(int argc, char **argv) { if (platform == Common::kPlatformUnknown) goto ShowHelpAndExit; - ConfMan.set("platform", platform); + ConfMan.set("platform", platform, kTransientDomain); END_OPTION DO_LONG_OPTION_BOOL("multi-midi") - ConfMan.set("multi_midi", cmdValue); + ConfMan.set("multi_midi", cmdValue, kTransientDomain); END_OPTION DO_LONG_OPTION_BOOL("native-mt32") - ConfMan.set("native_mt32", cmdValue); + ConfMan.set("native_mt32", cmdValue, kTransientDomain); END_OPTION DO_LONG_OPTION_BOOL("aspect-ratio") - ConfMan.set("aspect_ratio", cmdValue); + ConfMan.set("aspect_ratio", cmdValue, kTransientDomain); END_OPTION #ifndef DISABLE_SCUMM @@ -437,21 +441,21 @@ void GameDetector::parseCommandLine(int argc, char **argv) { // Use the special value '0' for the base in (int)strtol. // Doing that makes it possible to enter hex values // as "0x1234", but also decimal values ("123"). - ConfMan.set("tempo", (int)strtol(option, 0, 0)); + ConfMan.set("tempo", (int)strtol(option, 0, 0), kTransientDomain); END_OPTION DO_LONG_OPTION("talkspeed") - ConfMan.set("talkspeed", (int)strtol(option, 0, 10)); + ConfMan.set("talkspeed", (int)strtol(option, 0, 10), kTransientDomain); END_OPTION DO_LONG_OPTION_BOOL("demo-mode") - ConfMan.set("demo_mode", cmdValue); + ConfMan.set("demo_mode", cmdValue, kTransientDomain); END_OPTION #endif #ifndef DISABLE_SKY DO_LONG_OPTION_BOOL("floppy-intro") - ConfMan.set("floppy_intro", cmdValue); + ConfMan.set("floppy_intro", cmdValue, kTransientDomain); END_OPTION #endif @@ -579,7 +583,7 @@ bool GameDetector::detectMain() { #endif && gameDataPath.lastChar() != '\\') { gameDataPath += '/'; - ConfMan.set("path", gameDataPath); + ConfMan.set("path", gameDataPath, kTransientDomain); #endif } diff --git a/common/config-manager.cpp b/common/config-manager.cpp index ad51b14407..90297779d5 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -56,6 +56,7 @@ static char *rtrim(char *t) { namespace Common { const String ConfigManager::kApplicationDomain("scummvm"); +const String ConfigManager::kTransientDomain("__TRANSIENT"); const String trueStr("true"); const String falseStr("false"); @@ -206,13 +207,13 @@ void ConfigManager::writeDomain(FILE *file, const String &name, const Domain &do bool ConfigManager::hasKey(const String &key) const { // Search the domains in the following order: - // 1) Run time domain + // 1) Transient domain // 2) Active game domain (if any) // 3) All global domains // The defaults domain is explicitly *not* checked. -// if (_transientDomain.contain(key)) -// return true; + if (_transientDomain.contains(key)) + return true; if (!_activeDomain.isEmpty() && _gameDomains[_activeDomain].contains(key)) return true; @@ -229,6 +230,8 @@ bool ConfigManager::hasKey(const String &key) const { bool ConfigManager::hasKey(const String &key, const String &dom) const { assert(!dom.isEmpty()); + if (dom == kTransientDomain) + return _transientDomain.contains(key); if (_gameDomains.contains(dom)) return _gameDomains[dom].contains(key); if (_globalDomains.contains(dom)) @@ -240,7 +243,9 @@ bool ConfigManager::hasKey(const String &key, const String &dom) const { void ConfigManager::removeKey(const String &key, const String &dom) { assert(!dom.isEmpty()); - if (_gameDomains.contains(dom)) + if (dom == kTransientDomain) + _transientDomain.remove(key); + else if (_gameDomains.contains(dom)) _gameDomains[dom].remove(key); else if (_globalDomains.contains(dom)) _globalDomains[dom].remove(key); @@ -252,21 +257,21 @@ void ConfigManager::removeKey(const String &key, const String &dom) { #pragma mark - -const String & ConfigManager::get(const String &key, const String &dom) const { +const String & ConfigManager::get(const String &key, const String &domain) const { // Search the domains in the following order: - // 1) Run time domain + // 1) Transient domain // 2) Active game domain (if any) // 3) All global domains // 4) The defaults -// if (_transientDomain.contain(key)) -// return true; - if (!dom.isEmpty()) { - if (_gameDomains.contains(dom) && _gameDomains[dom].contains(key)) - return _gameDomains[dom][key]; - } else if (!_activeDomain.isEmpty() && _gameDomains[_activeDomain].contains(key)) - return _gameDomains[_activeDomain][key]; + if ((domain.isEmpty() || domain == kTransientDomain) && _transientDomain.contains(key)) + return _transientDomain[key]; + + const String &dom = domain.isEmpty() ? _activeDomain : domain; + + if (!dom.isEmpty() && _gameDomains.contains(dom) && _gameDomains[dom].contains(key)) + return _gameDomains[dom][key]; DomainMap::ConstIterator iter; for (iter = _globalDomains.begin(); iter != _globalDomains.end(); ++iter) { @@ -296,15 +301,13 @@ bool ConfigManager::getBool(const String &key, const String &dom) const { void ConfigManager::set(const String &key, const String &value) { -#if 0 - // TODO ?!? -// _transientDomain[key] = value; -#else + // Remove the transient domain value + _transientDomain.remove(key); + if (_activeDomain.isEmpty()) _globalDomains[kApplicationDomain][key] = value; else _gameDomains[_activeDomain][key] = value; -#endif } void ConfigManager::set(const String &key, const String &value, const String &dom) { @@ -313,10 +316,19 @@ void ConfigManager::set(const String &key, const String &value, const String &do return; } - if (_globalDomains.contains(dom)) - _globalDomains[dom][key] = value; - else - _gameDomains[dom][key] = value; + if (dom == kTransientDomain) + _transientDomain[key] = value; + else { + if (_globalDomains.contains(dom)) { + _globalDomains[dom][key] = value; + if (_activeDomain.isEmpty() || !_gameDomains[_activeDomain].contains(key)) + _transientDomain.remove(key); + } else { + _gameDomains[dom][key] = value; + if (dom == _activeDomain) + _transientDomain.remove(key); + } + } } void ConfigManager::set(const String &key, const char *value, const String &dom) { diff --git a/common/config-manager.h b/common/config-manager.h index 335c7d9dd5..62e824623b 100644 --- a/common/config-manager.h +++ b/common/config-manager.h @@ -58,6 +58,9 @@ public: /** The name of the application domain (normally 'scummvm'). */ static const String kApplicationDomain; + /** The transient (pseudo) domain. */ + static const String kTransientDomain; + bool hasKey(const String &key) const; bool hasKey(const String &key, const String &dom) const; @@ -104,7 +107,7 @@ private: void loadFile(const String &filename); void writeDomain(FILE *file, const String &name, const Domain &domain); -// Domain _transientDomain; + Domain _transientDomain; DomainMap _gameDomains; DomainMap _globalDomains; Domain _defaultsDomain; |