mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 08:45:33 +00:00
Read settings.cfg from all active config dirs
This commit is contained in:
parent
5ca56a4f8a
commit
1bcc4a8bcc
6 changed files with 28 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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<boost::filesystem::path>& 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 user settings if they exist
|
||||
std::string settingspath = (mCfgMgr.getUserConfigPath() / "settings.cfg").string();
|
||||
// Load "settings.cfg" from every config dir except the last one as additional default settings.
|
||||
for (int i = 0; i < static_cast<int>(paths.size()) - 1; ++i)
|
||||
{
|
||||
const std::string additionalDefaults = (paths[i] / "settings.cfg").string();
|
||||
if (boost::filesystem::exists(additionalDefaults))
|
||||
settings.loadDefault(additionalDefaults, 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();
|
||||
if (boost::filesystem::exists(settingspath))
|
||||
settings.loadUser(settingspath);
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
#include <Base64.h>
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue