Skip to content

Commit

Permalink
Backup config files before updating them just to be safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemason committed Sep 5, 2022
1 parent 5217c6e commit 07af259
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/headers/AppData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,18 @@ class AppData
resetEntries();
}

void backupConfigFile()
{
std::ifstream src(SAVE_FILE_NAME, std::ios::binary);
std::ofstream dst(SAVE_FILE_NAME ".backup", std::ios::binary);

dst << src.rdbuf();
}

void updateSaveFileFormat()
{
WARN("Updating to the new Save File Format");
backupConfigFile();
std::ifstream in;
in.open("./" SAVE_FILE_NAME);
if (!in)
Expand All @@ -220,6 +229,8 @@ class AppData
bool isMultiline = false;
bool isHiddenField = false;

int abortCounter = 0;
int abortLimit = 10000;
while (!in.eof())
{
in >> isMultiline;
Expand All @@ -236,6 +247,14 @@ class AppData
strcpy(toAdd.expandsTo, expandsTo.c_str());
entries.push_back(toAdd);
}

abortCounter++;
if (abortCounter > abortLimit)
{
ERR("Failure to parse and update Save File. Aborting update and loading clean slate.");
entries = {};
return;
}
}
in.close();

Expand Down

0 comments on commit 07af259

Please sign in to comment.