Browse Source

pfile: add assert comments to pfile_rename_temp_to_perm

Based on @galaxyhaxz code in https://github.com/diasurgical/devilution/pull/1294#issuecomment-509018789

Also, per suggestion of @sskras.
pull/189/head^2
Robin Eklind 7 years ago committed by Anders Jenbo
parent
commit
4e09aeb3a8
  1. 38
      Source/pfile.cpp

38
Source/pfile.cpp

@ -566,27 +566,31 @@ BOOL __stdcall GetTempSaveNames(DWORD dwIndex, char *szTemp)
void pfile_rename_temp_to_perm()
{
DWORD save_num, i;
char TempName[MAX_PATH];
char PermName[MAX_PATH];
save_num = pfile_get_save_num_from_name(plr[myplr]._pName);
if (!pfile_open_archive(FALSE, save_num))
DWORD dwChar, dwIndex;
BOOL bResult;
char szTemp[MAX_PATH];
char szPerm[MAX_PATH];
dwChar = pfile_get_save_num_from_name(plr[myplr]._pName);
/// ASSERT: assert(dwChar < MAX_CHARACTERS);
/// ASSERT: assert(gbMaxPlayers == 1);
if (!pfile_open_archive(FALSE, dwChar))
app_fatal("Unable to write to save file archive");
i = 0;
while (GetTempSaveNames(i, TempName)) {
GetPermSaveNames(i, PermName);
i++;
if (mpqapi_has_file(TempName)) {
if (mpqapi_has_file(PermName))
mpqapi_remove_hash_entry(PermName);
mpqapi_rename(TempName, PermName);
dwIndex = 0;
while (GetTempSaveNames(dwIndex, szTemp)) {
bResult = GetPermSaveNames(dwIndex, szPerm);
/// ASSERT: assert(bResult);
dwIndex++;
if (mpqapi_has_file(szTemp)) {
if (mpqapi_has_file(szPerm))
mpqapi_remove_hash_entry(szPerm);
mpqapi_rename(szTemp, szPerm);
}
}
// BUGFIX: function call has no purpose
GetPermSaveNames(i, PermName);
pfile_flush(TRUE, save_num);
/// ASSERT: assert(! GetPermSaveNames(dwIndex,szPerm));
GetPermSaveNames(dwIndex, szPerm);
pfile_flush(TRUE, dwChar);
}
BOOL __stdcall GetPermSaveNames(DWORD dwIndex, char *szPerm)

Loading…
Cancel
Save