Save state to a temp file and rename.

This way, if you run out of disk or hit a bug, at least you have your old
state.  Better than having neither.
This commit is contained in:
Unknown W. Brackets committed 2014-12-20 22:24:02 -08:00
1 parent 3f0b759746
commit b1c9e7382f
1 file changed
+12 -1
+12 -1
View File
@@ -327,7 +327,18 @@ namespace SaveState
{
std::string fn = GenerateSaveSlotFilename(slot, STATE_EXTENSION);
if (!fn.empty()) {
Save(fn + ".tmp", callback, cbUserData);
auto renameCallback = [=](bool status, void *data) {
if (status) {
if (File::Exists(fn)) {
File::Delete(fn);
}
File::Rename(fn + ".tmp", fn);
}
if (callback) {
callback(status, data);
}
};
Save(fn + ".tmp", renameCallback, cbUserData);
} else {
I18NCategory *s = GetI18NCategory("Screen");
osm.Show("Failed to save state. Error in the file system.", 2.0);