fix crash on exit when no user settings exist

actorid
scrawl 13 years ago
parent c2a82c3d89
commit 5accca385c

@ -315,7 +315,7 @@ void OMW::Engine::go()
boost::filesystem::create_directories(configPath); boost::filesystem::create_directories(configPath);
} }
// Create the settings manager and load default and user settings file // Create the settings manager and load default settings file
Settings::Manager settings; Settings::Manager settings;
const std::string localdefault = mCfgMgr.getLocalPath().string() + "/settings-default.cfg"; const std::string localdefault = mCfgMgr.getLocalPath().string() + "/settings-default.cfg";
const std::string globaldefault = mCfgMgr.getGlobalPath().string() + "/settings-default.cfg"; const std::string globaldefault = mCfgMgr.getGlobalPath().string() + "/settings-default.cfg";
@ -326,11 +326,14 @@ void OMW::Engine::go()
else if (boost::filesystem::exists(globaldefault)) else if (boost::filesystem::exists(globaldefault))
settings.loadDefault(globaldefault); settings.loadDefault(globaldefault);
// load user settings if they exist, otherwise just load the default settings as user settings
const std::string settingspath = mCfgMgr.getUserPath().string() + "/settings.cfg"; const std::string settingspath = mCfgMgr.getUserPath().string() + "/settings.cfg";
if (boost::filesystem::exists(settingspath)) if (boost::filesystem::exists(settingspath))
settings.loadUser(settingspath); settings.loadUser(settingspath);
else else if (boost::filesystem::exists(localdefault))
settings.copyDefaultToUserSettings(); settings.loadUser(localdefault);
else if (boost::filesystem::exists(globaldefault))
settings.loadUser(globaldefault);
mOgre->configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), mOgre->configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()),
mCfgMgr.getOgreConfigPath().string(), mCfgMgr.getOgreConfigPath().string(),

@ -22,11 +22,6 @@ void Manager::loadDefault (const std::string& file)
mDefaultFile.load(file); mDefaultFile.load(file);
} }
void Manager::copyDefaultToUserSettings ()
{
mFile = mDefaultFile;
}
void Manager::saveUser(const std::string& file) void Manager::saveUser(const std::string& file)
{ {
std::fstream fout(file.c_str(), std::ios::out); std::fstream fout(file.c_str(), std::ios::out);

@ -27,9 +27,6 @@ namespace Settings
void loadDefault (const std::string& file); void loadDefault (const std::string& file);
///< load file as the default settings (can be overridden by user settings) ///< load file as the default settings (can be overridden by user settings)
void copyDefaultToUserSettings ();
///< copy the default settings to the user settings (useful when there are no user settings yet)
void loadUser (const std::string& file); void loadUser (const std::string& file);
///< load file as user settings ///< load file as user settings

Loading…
Cancel
Save