From b1c9e7382fad582212a672f2f3b033210e286c77 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 20 Dec 2014 22:24:02 -0800 Subject: [PATCH] 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. --- Core/SaveState.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 0b62c55341..9c490f92ac 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -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);