Skip to content

Commit

Permalink
gui: Simplify function and solve unlikely edge-case
Browse files Browse the repository at this point in the history
If backups are enabled, the .backup file will have already been created via renaming the original save-state. The asynchronous process is dumping the current emulation state, but by the time we've hit this function the rename has already taken place so we have a guarantee.

    This solves a potential bug in the existing code (which probably would have never been hit):
        Save to slot that has no current backup
        Rename fails
        Update method looks for the file without .backup, which is still there.
        Load backup option is enabled despite there not actually being a backup to load.
  • Loading branch information
xTVaser authored and refractionpcsx2 committed Mar 12, 2021
1 parent 288c8fe commit 7176774
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions pcsx2/gui/Saveslots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void States_FreezeCurrentSlot()
Console.WriteLn("Load or save action is already pending.");
return;
}
States_updateLoadBackupMenuItem(true);

GSchangeSaveState(StatesC, SaveStateBase::GetFilename(StatesC).ToUTF8());
StateCopy_SaveToSlot(StatesC);
Expand All @@ -81,6 +80,8 @@ void States_FreezeCurrentSlot()
#endif

GetSysExecutorThread().PostIdleEvent(SysExecEvent_ClearSavingLoadingFlag());

States_updateLoadBackupMenuItem();
}

void _States_DefrostCurrentSlot(bool isFromBackup)
Expand Down Expand Up @@ -115,14 +116,9 @@ void States_DefrostCurrentSlotBackup()
_States_DefrostCurrentSlot(true);
}

void States_updateLoadBackupMenuItem(bool isBeforeSave)
void States_updateLoadBackupMenuItem()
{
wxString file = SaveStateBase::GetFilename(StatesC);

if (!(isBeforeSave && g_Conf->EmuOptions.BackupSavestate))
{
file = file + L".backup";
}
wxString file = SaveStateBase::GetFilename(StatesC) + ".backup";

sMainFrame.EnableMenuItem(MenuId_State_LoadBackup, wxFileExists(file));
sMainFrame.SetMenuItemLabel(MenuId_State_LoadBackup, wxsFormat(L"%s %d", _("Backup"), StatesC));
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/gui/Saveslots.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ extern void States_CycleSlotForward();
extern void States_CycleSlotBackward();
extern void States_SetCurrentSlot(int slot);
extern int States_GetCurrentSlot();
extern void States_updateLoadBackupMenuItem(bool isBeforeSave = false);
extern void States_updateLoadBackupMenuItem();

0 comments on commit 7176774

Please sign in to comment.