Make settings loader differentiate between engine and editor (fixes #6658).

pull/3226/head
Martin Otto 3 years ago committed by Petr Mikheev
parent 3afa46b25e
commit 96e48e5492

@ -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()

@ -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<boost::filesystem::path>& 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<int>(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);

@ -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);

Loading…
Cancel
Save