From ca3b87d7034a0bd395b2851229d0f43ec1eeac45 Mon Sep 17 00:00:00 2001 From: morfidon <57798071+morfidon@users.noreply.github.com> Date: Tue, 10 Mar 2026 10:59:24 +0100 Subject: [PATCH] Refine full save backup helper API Narrow the backup save helper to full game saves only. Replace pfile_write_hero_with_backup(bool writeGameData) with pfile_write_game_with_backup(), and always write full game data before validating the resulting archive with ArchiveContainsGame(). This makes the helper's name, behavior, and post-write validation consistent, and removes an API parameter that made the function look more general than its actual responsibility. Also update SaveGame() to use the new helper name and a clearer local variable. --- Source/loadsave.cpp | 4 ++-- Source/pfile.cpp | 4 ++-- Source/pfile.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 4773a8262..a2b302c94 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -2934,8 +2934,8 @@ void SaveGame() pfile_write_hero(/*writeGameData=*/true); sfile_write_stash(); #else - const bool heroSaved = pfile_write_hero_with_backup(/*writeGameData=*/true); - if (!heroSaved) { + const bool gameSaved = pfile_write_game_with_backup(); + if (!gameSaved) { gbValidSaveFile = false; return; } diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 48fee9ebc..251c70205 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -644,7 +644,7 @@ void pfile_write_hero(bool writeGameData) } #if !(defined(UNPACKED_SAVES) && defined(DVL_NO_FILESYSTEM)) -bool pfile_write_hero_with_backup(bool writeGameData) +bool pfile_write_game_with_backup() { const std::string backupPrefix = "backup_"; const std::string backupLocation = GetSavePath(gSaveNumber, backupPrefix); @@ -653,7 +653,7 @@ bool pfile_write_hero_with_backup(bool writeGameData) if (FileExists(saveLocation) || DirectoryExists(saveLocation.c_str())) CopySaveLocation(saveLocation, backupLocation); - pfile_write_hero(writeGameData); + pfile_write_hero(/*writeGameData=*/true); auto archive = OpenSaveArchive(gSaveNumber); const bool saveIsValid = archive && ArchiveContainsGame(*archive); diff --git a/Source/pfile.h b/Source/pfile.h index 2e1b54f7c..9375c979e 100644 --- a/Source/pfile.h +++ b/Source/pfile.h @@ -100,8 +100,8 @@ std::optional OpenSaveArchive(uint32_t saveNum); std::optional OpenStashArchive(); const char *pfile_get_password(); std::unique_ptr ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen = nullptr); -void pfile_write_hero(bool writeGameData = false); -bool pfile_write_hero_with_backup(bool writeGameData = false); +void pfile_write_hero(bool writeGameData = false); +bool pfile_write_game_with_backup(); bool pfile_write_stash_with_backup(); #ifndef DISABLE_DEMOMODE