impr: Keep a safety backup of the last crash backup around

This commit is contained in:
WerWolv 2024-05-19 23:13:43 +02:00
parent bfdb9b4019
commit bba4cf9578
1 changed files with 13 additions and 1 deletions

View File

@ -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;
}