Skip to content

Commit

Permalink
When settings are not found/corrupted, construct a valid blank XML do…
Browse files Browse the repository at this point in the history
…cument
  • Loading branch information
malensek committed May 20, 2015
1 parent be836f1 commit 95fc458
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion 3RVX/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,25 @@ void Settings::Load() {
std::string u8FileName = StringUtils::Narrow(_file);
tinyxml2::XMLError result = _xml.LoadFile(u8FileName.c_str());
if (result != tinyxml2::XMLError::XML_SUCCESS) {
_xml.Clear();
Error::ErrorMessage(GENERR_SETTINGSFILE, _file);
LoadEmptySettings();
return;
}

_root = _xml.GetDocument()->FirstChildElement("settings");
if (_root == NULL) {
Error::ErrorMessage(GENERR_MISSING_XML, L"<settings>");
LoadEmptySettings();
return;
}

}

void Settings::LoadEmptySettings() {
_xml.Clear();
_xml.InsertFirstChild(_xml.NewDeclaration());
_root = _xml.NewElement("settings");
_xml.GetDocument()->InsertEndChild(_root);
}

int Settings::Save() {
Expand Down
1 change: 1 addition & 0 deletions 3RVX/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Settings {
static Settings *Instance();

void Load();
void LoadEmptySettings();
int Save();

static std::wstring AppDir();
Expand Down

0 comments on commit 95fc458

Please sign in to comment.