diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 17ab8339d..887c22ce9 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -34,6 +34,9 @@ Settings::Settings() { myRespository = make_shared(); + // If no version is recorded with the persisted settings, we set it to zero + setPermanent(SETTINGS_VERSION_KEY, 0); + // Video-related options setPermanent("video", ""); setPermanent("speed", "1.0"); @@ -225,6 +228,8 @@ void Settings::load(const Options& options) for (const auto& opt: fromFile) setValue(opt.first, opt.second, false); + migrate(); + // Apply commandline options, which override those from settings file for(const auto& opt: options) setValue(opt.first, opt.second, false); @@ -648,3 +653,29 @@ void Settings::setTemporary(const string& key, const Variant& value) { myTemporarySettings[key] = value; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Settings::migrateOne() +{ + const int version = getInt(SETTINGS_VERSION_KEY); + if (version >= SETTINGS_VERSION) return; + + switch (version) { + case 0: + #if defined BSPF_MACOS || defined DARWIN + setPermanent("video", ""); + #endif + + break; + } + + setPermanent(SETTINGS_VERSION_KEY, version + 1); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Settings::migrate() +{ + while (getInt(SETTINGS_VERSION_KEY) < SETTINGS_VERSION) migrateOne(); + + myRespository->save(SETTINGS_VERSION_KEY, SETTINGS_VERSION); +} diff --git a/src/emucore/Settings.hxx b/src/emucore/Settings.hxx index f151dd814..eb1398e22 100644 --- a/src/emucore/Settings.hxx +++ b/src/emucore/Settings.hxx @@ -51,6 +51,9 @@ class Settings using Options = std::map; + static constexpr int SETTINGS_VERSION = 1; + static constexpr const char* SETTINGS_VERSION_KEY = "settings.version"; + public: /** This method should be called to display usage information. @@ -134,6 +137,16 @@ class Settings */ void validate(); + /** + Migrate settings over one version. + */ + void migrateOne(); + + /** + Migrate settings. + */ + void migrate(); + private: // Holds key/value pairs that are necessary for Stella to // function and must be saved on each program exit.