mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-25 15:33:57 +00:00
fix crash when usersettings fail to load
This commit is contained in:
parent
60dd1d7bc7
commit
af6c6a31aa
2 changed files with 23 additions and 21 deletions
|
@ -315,43 +315,40 @@ static void readInt(XMLElement *xml, const char *elem, const char *att, int *toC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserSettings::loadDefaults(bool doApply)
|
bool UserSettings::loadDefaults(bool doApply)
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::string fn = "default_usersettings.xml";
|
||||||
os << "default-" << VERSION_USERSETTINGS << ".xml";
|
if (exists(fn))
|
||||||
if (exists(os.str()))
|
|
||||||
{
|
{
|
||||||
load(doApply, os.str());
|
return load(doApply, fn);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exists("default_usersettings.xml"))
|
return false;
|
||||||
{
|
|
||||||
load(doApply, "default_usersettings.xml");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorLog("No default user settings file found! Controls may be broken.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserSettings::load(bool doApply, const std::string &overrideFile)
|
bool UserSettings::load(bool doApply, const std::string &overrideFile)
|
||||||
{
|
{
|
||||||
std::string filename;
|
std::string filename;
|
||||||
|
|
||||||
#if defined(BBGE_BUILD_UNIX)
|
|
||||||
filename = dsq->getPreferencesFolder() + "/" + userSettingsFilename;
|
|
||||||
#elif defined(BBGE_BUILD_WINDOWS)
|
|
||||||
if (!overrideFile.empty())
|
if (!overrideFile.empty())
|
||||||
filename = overrideFile;
|
filename = overrideFile;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
#if defined(BBGE_BUILD_UNIX)
|
||||||
|
filename = dsq->getPreferencesFolder() + "/" + userSettingsFilename;
|
||||||
|
#else
|
||||||
filename = userSettingsFilename;
|
filename = userSettingsFilename;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!exists(filename))
|
||||||
|
return false;
|
||||||
|
|
||||||
XMLDocument doc;
|
XMLDocument doc;
|
||||||
if(readXML(filename, doc) != XML_SUCCESS)
|
if(readXML(filename, doc) != XML_SUCCESS)
|
||||||
{
|
{
|
||||||
errorLog("UserSettings: Malformed XML, continuing with defaults");
|
errorLog("UserSettings [" + filename + "]: Error, malformed XML");
|
||||||
doc.Clear(); // just in case
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
version.settingsVersion = 0;
|
version.settingsVersion = 0;
|
||||||
|
@ -510,6 +507,9 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(control.actionSets.empty())
|
||||||
|
control.actionSets.resize(1);
|
||||||
|
|
||||||
if(control.actionSets.size() == 1)
|
if(control.actionSets.size() == 1)
|
||||||
control.actionSets[0].enabled = true;
|
control.actionSets[0].enabled = true;
|
||||||
|
|
||||||
|
@ -570,6 +570,8 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
|
||||||
|
|
||||||
if (doApply)
|
if (doApply)
|
||||||
apply();
|
apply();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserSettings::apply()
|
void UserSettings::apply()
|
||||||
|
|
|
@ -128,8 +128,8 @@ public:
|
||||||
std::string masterServer;
|
std::string masterServer;
|
||||||
} network;
|
} network;
|
||||||
|
|
||||||
void loadDefaults(bool doApply=true);
|
bool loadDefaults(bool doApply=true);
|
||||||
void load(bool doApply=true, const std::string &overrideFile="");
|
bool load(bool doApply=true, const std::string &overrideFile="");
|
||||||
void save();
|
void save();
|
||||||
void apply();
|
void apply();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue