From 96e48e549269c442b84aa49e1833a9093cdae7a5 Mon Sep 17 00:00:00 2001 From: Martin Otto Date: Fri, 4 Mar 2022 09:44:52 +0000 Subject: [PATCH] Make settings loader differentiate between engine and editor (fixes #6658). --- apps/opencs/model/prefs/state.cpp | 2 +- components/settings/settings.cpp | 29 ++++++++++++++++++++++------- components/settings/settings.hpp | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index ee0cbbed5a..0981ae4401 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -16,7 +16,7 @@ CSMPrefs::State *CSMPrefs::State::sThis = nullptr; void CSMPrefs::State::load() { - mSettings.load(mConfigurationManager); + mSettings.load(mConfigurationManager, true); } void CSMPrefs::State::declare() diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index b8ff700492..4c17394836 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -20,29 +20,44 @@ void Manager::clear() mChangedSettings.clear(); } -std::string Manager::load(const Files::ConfigurationManager& cfgMgr) +std::string Manager::load(const Files::ConfigurationManager& cfgMgr, bool loadEditorSettings) { SettingsFileParser parser; const std::vector& paths = cfgMgr.getActiveConfigPaths(); if (paths.empty()) throw std::runtime_error("No config dirs! ConfigurationManager::readConfiguration must be called first."); + // Create file name strings for either the engine or the editor. + std::string defaultSettingsFile = ""; + std::string userSettingsFile = ""; + + if (!loadEditorSettings) + { + defaultSettingsFile = "defaults.bin"; + userSettingsFile = "settings.cfg"; + } + else + { + defaultSettingsFile = "defaults-cs.bin"; + userSettingsFile = "openmw-cs.cfg"; + } + // Create the settings manager and load default settings file. - const std::string defaultsBin = (paths.front() / "defaults.bin").string(); + const std::string defaultsBin = (paths.front() / defaultSettingsFile).string(); if (!boost::filesystem::exists(defaultsBin)) - throw std::runtime_error ("No default settings file found! Make sure the file \"defaults.bin\" was properly installed."); + throw std::runtime_error ("No default settings file found! Make sure the file \"" + defaultSettingsFile + "\" was properly installed."); parser.loadSettingsFile(defaultsBin, mDefaultSettings, true, false); - // Load "settings.cfg" from every config dir except the last one as additional default settings. + // Load "settings.cfg" or "openmw-cs.cfg" from every config dir except the last one as additional default settings. for (int i = 0; i < static_cast(paths.size()) - 1; ++i) { - const std::string additionalDefaults = (paths[i] / "settings.cfg").string(); + const std::string additionalDefaults = (paths[i] / userSettingsFile).string(); if (boost::filesystem::exists(additionalDefaults)) parser.loadSettingsFile(additionalDefaults, mDefaultSettings, false, true); } - // Load "settings.cfg" from the last config as user settings if they exist. This path will be used to save modified settings. - std::string settingspath = (paths.back() / "settings.cfg").string(); + // Load "settings.cfg" or "openmw-cs.cfg" from the last config dir as user settings. This path will be used to save modified settings. + std::string settingspath = (paths.back() / userSettingsFile).string(); if (boost::filesystem::exists(settingspath)) parser.loadSettingsFile(settingspath, mUserSettings, false, false); diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index 04831ef171..c23d8d878e 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -31,7 +31,7 @@ namespace Settings void clear(); ///< clears all settings and default settings - std::string load(const Files::ConfigurationManager& cfgMgr); + std::string load(const Files::ConfigurationManager& cfgMgr, bool loadEditorSettings = false); ///< load settings from all active config dirs. Returns the path of the last loaded file. void saveUser (const std::string& file);