From bba4cf95780e432a4b4dc4e1152d1f389ec76a2c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 19 May 2024 23:13:43 +0200 Subject: [PATCH] impr: Keep a safety backup of the last crash backup around --- plugins/builtin/source/content/welcome_screen.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index 4dd59bf5e..d1828f910 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -552,14 +552,26 @@ namespace hex::plugin::builtin { bool hasProject = !crashFileData.value("project", "").empty(); auto backupFilePath = path / BackupFileName; + auto backupFilePathOld = path / BackupFileName; + backupFilePathOld.replace_extension(".hexproj.old"); + bool hasBackupFile = wolv::io::fs::exists(backupFilePath); if (!hasProject && !hasBackupFile) { log::warn("No project file or backup file found in crash.json file"); crashFile.close(); + + // Delete crash.json file wolv::io::fs::remove(crashFilePath); - wolv::io::fs::remove(backupFilePath); + + // Delete old backup file + wolv::io::fs::remove(backupFilePathOld); + + // Try to move current backup file to the old backup location + if (wolv::io::fs::copyFile(backupFilePath, backupFilePathOld)) { + wolv::io::fs::remove(backupFilePath); + } continue; }