Browse Source

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.
pull/8497/head
morfidon 7 days ago
parent
commit
ca3b87d703
  1. 4
      Source/loadsave.cpp
  2. 4
      Source/pfile.cpp
  3. 4
      Source/pfile.h

4
Source/loadsave.cpp

@ -2934,8 +2934,8 @@ void SaveGame()
pfile_write_hero(/*writeGameData=*/true); pfile_write_hero(/*writeGameData=*/true);
sfile_write_stash(); sfile_write_stash();
#else #else
const bool heroSaved = pfile_write_hero_with_backup(/*writeGameData=*/true); const bool gameSaved = pfile_write_game_with_backup();
if (!heroSaved) { if (!gameSaved) {
gbValidSaveFile = false; gbValidSaveFile = false;
return; return;
} }

4
Source/pfile.cpp

@ -644,7 +644,7 @@ void pfile_write_hero(bool writeGameData)
} }
#if !(defined(UNPACKED_SAVES) && defined(DVL_NO_FILESYSTEM)) #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 backupPrefix = "backup_";
const std::string backupLocation = GetSavePath(gSaveNumber, backupPrefix); 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())) if (FileExists(saveLocation) || DirectoryExists(saveLocation.c_str()))
CopySaveLocation(saveLocation, backupLocation); CopySaveLocation(saveLocation, backupLocation);
pfile_write_hero(writeGameData); pfile_write_hero(/*writeGameData=*/true);
auto archive = OpenSaveArchive(gSaveNumber); auto archive = OpenSaveArchive(gSaveNumber);
const bool saveIsValid = archive && ArchiveContainsGame(*archive); const bool saveIsValid = archive && ArchiveContainsGame(*archive);

4
Source/pfile.h

@ -100,8 +100,8 @@ std::optional<SaveReader> OpenSaveArchive(uint32_t saveNum);
std::optional<SaveReader> OpenStashArchive(); std::optional<SaveReader> OpenStashArchive();
const char *pfile_get_password(); const char *pfile_get_password();
std::unique_ptr<std::byte[]> ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen = nullptr); std::unique_ptr<std::byte[]> ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen = nullptr);
void pfile_write_hero(bool writeGameData = false); void pfile_write_hero(bool writeGameData = false);
bool pfile_write_hero_with_backup(bool writeGameData = false); bool pfile_write_game_with_backup();
bool pfile_write_stash_with_backup(); bool pfile_write_stash_with_backup();
#ifndef DISABLE_DEMOMODE #ifndef DISABLE_DEMOMODE

Loading…
Cancel
Save