|
|
|
@ -713,34 +713,60 @@ bool pfile_write_auto_game() |
|
|
|
return saveIsValid; |
|
|
|
return saveIsValid; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool pfile_write_stash_with_backup() |
|
|
|
bool WriteStashAndRestoreOnFailure(std::string_view restorePrefix, bool deleteRestoreLocationOnSuccess) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!Stash.dirty) |
|
|
|
if (!Stash.dirty) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
const std::string backupPrefix = "backup_"; |
|
|
|
const std::string restoreLocation = GetStashSavePath(restorePrefix); |
|
|
|
const std::string backupLocation = GetStashSavePath(backupPrefix); |
|
|
|
|
|
|
|
const std::string stashLocation = GetStashSavePath(); |
|
|
|
const std::string stashLocation = GetStashSavePath(); |
|
|
|
|
|
|
|
|
|
|
|
if (SaveLocationExists(stashLocation)) |
|
|
|
|
|
|
|
CopySaveLocation(stashLocation, backupLocation); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SaveWriter stashWriter = GetStashWriter(); |
|
|
|
SaveWriter stashWriter = GetStashWriter(); |
|
|
|
SaveStash(stashWriter); |
|
|
|
SaveStash(stashWriter); |
|
|
|
|
|
|
|
|
|
|
|
auto archive = OpenStashArchive(); |
|
|
|
auto archive = OpenStashArchive(); |
|
|
|
const char *stashFileName = gbIsMultiplayer ? "mpstashitems" : "spstashitems"; |
|
|
|
const char *stashFileName = gbIsMultiplayer ? "mpstashitems" : "spstashitems"; |
|
|
|
const bool stashIsValid = archive && ReadArchive(*archive, stashFileName) != nullptr; |
|
|
|
const bool stashIsValid = archive && ReadArchive(*archive, stashFileName) != nullptr; |
|
|
|
if (stashIsValid || !SaveLocationExists(backupLocation)) { |
|
|
|
if (stashIsValid) { |
|
|
|
if (stashIsValid) |
|
|
|
Stash.dirty = false; |
|
|
|
Stash.dirty = false; |
|
|
|
if (deleteRestoreLocationOnSuccess) |
|
|
|
return stashIsValid; |
|
|
|
DeleteSaveLocation(restoreLocation); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RestoreSaveLocation(stashLocation, backupLocation); |
|
|
|
if (!SaveLocationExists(restoreLocation)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RestoreSaveLocation(stashLocation, restoreLocation); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool pfile_write_manual_stash_with_backup() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const std::string backupPrefix = "backup_"; |
|
|
|
|
|
|
|
const std::string backupLocation = GetStashSavePath(backupPrefix); |
|
|
|
|
|
|
|
const std::string stashLocation = GetStashSavePath(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (SaveLocationExists(stashLocation)) |
|
|
|
|
|
|
|
CopySaveLocation(stashLocation, backupLocation); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return WriteStashAndRestoreOnFailure(backupPrefix, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool pfile_write_auto_stash() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const std::string restorePrefix = "autosave_restore_"; |
|
|
|
|
|
|
|
const std::string restoreLocation = GetStashSavePath(restorePrefix); |
|
|
|
|
|
|
|
const std::string stashLocation = GetStashSavePath(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (SaveLocationExists(stashLocation)) |
|
|
|
|
|
|
|
CopySaveLocation(stashLocation, restoreLocation); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const bool stashIsValid = WriteStashAndRestoreOnFailure(restorePrefix, true); |
|
|
|
|
|
|
|
if (!stashIsValid && SaveLocationExists(restoreLocation)) |
|
|
|
|
|
|
|
DeleteSaveLocation(restoreLocation); |
|
|
|
|
|
|
|
return stashIsValid; |
|
|
|
|
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_DEMOMODE |
|
|
|
#ifndef DISABLE_DEMOMODE |
|
|
|
|