diff --git a/CHANGELOG.md b/CHANGELOG.md index 56d0910d22..a181a35098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,7 @@ Bug #6579: OpenMW compilation error when using OSG doubles for BoundingSphere Feature #890: OpenMW-CS: Column filtering Feature #1465: "Reset" argument for AI functions + Feature #2491: Ability to make OpenMW "portable" Feature #2554: Modifying an object triggers the instances table to scroll to the corresponding record Feature #2780: A way to see current OpenMW version in the console Feature #3616: Allow Zoom levels on the World Map diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 9e2e1aedad..50053b8b76 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -520,20 +520,26 @@ void OMW::Engine::setSkipMenu (bool skipMenu, bool newGame) std::string OMW::Engine::loadSettings (Settings::Manager & settings) { - // Create the settings manager and load default settings file - const std::string localdefault = (mCfgMgr.getLocalPath() / "defaults.bin").string(); - const std::string globaldefault = (mCfgMgr.getGlobalPath() / "defaults.bin").string(); + const std::vector& paths = mCfgMgr.getActiveConfigPaths(); + if (paths.empty()) + throw std::runtime_error("No config dirs! ConfigurationManager::readConfiguration must be called first."); - // prefer local - if (boost::filesystem::exists(localdefault)) - settings.loadDefault(localdefault); - else if (boost::filesystem::exists(globaldefault)) - settings.loadDefault(globaldefault); - else + // Create the settings manager and load default settings file. + const std::string defaultsBin = (paths.front() / "defaults.bin").string(); + if (!boost::filesystem::exists(defaultsBin)) throw std::runtime_error ("No default settings file found! Make sure the file \"defaults.bin\" was properly installed."); + settings.loadDefault(defaultsBin); + + // Load "settings.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(); + if (boost::filesystem::exists(additionalDefaults)) + settings.loadDefault(additionalDefaults, true); + } - // load user settings if they exist - std::string settingspath = (mCfgMgr.getUserConfigPath() / "settings.cfg").string(); + // 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(); if (boost::filesystem::exists(settingspath)) settings.loadUser(settingspath); diff --git a/components/settings/parser.cpp b/components/settings/parser.cpp index f2419dfdd6..dd1b8c1a20 100644 --- a/components/settings/parser.cpp +++ b/components/settings/parser.cpp @@ -9,7 +9,8 @@ #include -void Settings::SettingsFileParser::loadSettingsFile(const std::string& file, CategorySettingValueMap& settings, bool base64Encoded) +void Settings::SettingsFileParser::loadSettingsFile(const std::string& file, CategorySettingValueMap& settings, + bool base64Encoded, bool overrideExisting) { mFile = file; boost::filesystem::ifstream fstream; @@ -73,7 +74,9 @@ void Settings::SettingsFileParser::loadSettingsFile(const std::string& file, Cat std::string value = line.substr(valueBegin); Misc::StringUtils::trim(value); - if (settings.insert(std::make_pair(std::make_pair(currentCategory, setting), value)).second == false) + if (overrideExisting) + settings[std::make_pair(currentCategory, setting)] = value; + else if (settings.insert(std::make_pair(std::make_pair(currentCategory, setting), value)).second == false) fail(std::string("duplicate setting: [" + currentCategory + "] " + setting)); } } diff --git a/components/settings/parser.hpp b/components/settings/parser.hpp index 45b1a18f72..c934fbea07 100644 --- a/components/settings/parser.hpp +++ b/components/settings/parser.hpp @@ -10,7 +10,8 @@ namespace Settings class SettingsFileParser { public: - void loadSettingsFile(const std::string& file, CategorySettingValueMap& settings, bool base64encoded = false); + void loadSettingsFile(const std::string& file, CategorySettingValueMap& settings, + bool base64encoded = false, bool overrideExisting = false); void saveSettingsFile(const std::string& file, const CategorySettingValueMap& settings); diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 7fa625e4ab..09e74b348b 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -19,10 +19,10 @@ void Manager::clear() mChangedSettings.clear(); } -void Manager::loadDefault(const std::string &file) +void Manager::loadDefault(const std::string &file, bool overrideExisting) { SettingsFileParser parser; - parser.loadSettingsFile(file, mDefaultSettings, true); + parser.loadSettingsFile(file, mDefaultSettings, true, overrideExisting); } void Manager::loadUser(const std::string &file) diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index a4b1cf3a54..84e7066fbd 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -26,7 +26,7 @@ namespace Settings void clear(); ///< clears all settings and default settings - void loadDefault (const std::string& file); + void loadDefault (const std::string& file, bool overrideExisting = false); ///< load file as the default settings (can be overridden by user settings) void loadUser (const std::string& file);