From bad365c97ea86ef4f0fe722ca4e94e8fb820c579 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Fri, 5 Jun 2020 19:43:03 +0200 Subject: [PATCH] COMMON: Add a helper to update a ConfMan entry and flush to disk --- common/config-manager.cpp | 13 +++++++++++++ common/config-manager.h | 6 ++++++ common/gui_options.cpp | 7 +------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/common/config-manager.cpp b/common/config-manager.cpp index 40c974574d7..83d4aacdaaf 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -527,6 +527,19 @@ void ConfigManager::set(const String &key, const String &value) { _appDomain[key] = value; } +void ConfigManager::setAndFlush(const String &key, const Common::String &value) { + if (value.empty() && !hasKey(key)) { + return; + } + + if (hasKey(key) && get(key) == value) { + return; + } + + set(key, value); + flushToDisk(); +} + void ConfigManager::set(const String &key, const String &value, const String &domName) { // FIXME: For now we continue to allow empty domName to indicate // "use 'default' domain". This is mainly needed for the SCUMM ConfigDialog diff --git a/common/config-manager.h b/common/config-manager.h index 06e8ea372d4..0295abf1709 100644 --- a/common/config-manager.h +++ b/common/config-manager.h @@ -118,6 +118,12 @@ public: const String & get(const String &key) const; void set(const String &key, const String &value); + /** + * Update a configuration entry for the active domain and flush + * the configuration file to disk if the value changed + */ + void setAndFlush(const String &key, const Common::String &value); + #if 1 // // Domain specific access methods: Acces *one specific* domain and modify it. diff --git a/common/gui_options.cpp b/common/gui_options.cpp index 08ee553ea6a..2786701c858 100644 --- a/common/gui_options.cpp +++ b/common/gui_options.cpp @@ -128,12 +128,7 @@ const String getGameGUIOptionsDescription(const String &options) { void updateGameGUIOptions(const String &options, const String &langOption) { const String newOptionString = getGameGUIOptionsDescription(options) + " " + langOption; - - if ((!options.empty() && !ConfMan.hasKey("guioptions")) || - (ConfMan.hasKey("guioptions") && ConfMan.get("guioptions") != newOptionString)) { - ConfMan.set("guioptions", newOptionString); - ConfMan.flushToDisk(); - } + ConfMan.setAndFlush("guioptions", newOptionString); }