From bebea985ce38556485a2a88006f91c3f3b5e7a4b Mon Sep 17 00:00:00 2001 From: "avihal@gmail.com" Date: Sun, 20 Mar 2011 08:01:16 +0000 Subject: [PATCH] Save-state: 1. Added load from backup. 2. Removed save/load "Other..." (not connected to anything anyway) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4461 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/gui/App.h | 3 ++- pcsx2/gui/AppSaveStates.h | 5 ++++- pcsx2/gui/GlobalCommands.cpp | 6 ++++++ pcsx2/gui/MainFrame.cpp | 22 ++++++++++++++------ pcsx2/gui/MainFrame.h | 2 +- pcsx2/gui/MainMenuClicks.cpp | 6 ++++++ pcsx2/gui/Saveslots.cpp | 40 ++++++++++++++++++++++++++++++++++-- pcsx2/gui/SysState.cpp | 6 +++--- 8 files changed, 76 insertions(+), 14 deletions(-) diff --git a/pcsx2/gui/App.h b/pcsx2/gui/App.h index a447fe782f..343105ea52 100644 --- a/pcsx2/gui/App.h +++ b/pcsx2/gui/App.h @@ -107,7 +107,8 @@ enum MenuIdentifiers MenuId_State_Load, MenuId_State_LoadOther, MenuId_State_Load01, // first of many load slots - MenuId_State_Save = MenuId_State_Load01+20, + MenuId_State_LoadBackup = MenuId_State_Load01+20, + MenuId_State_Save, MenuId_State_SaveOther, MenuId_State_Save01, // first of many save slots diff --git a/pcsx2/gui/AppSaveStates.h b/pcsx2/gui/AppSaveStates.h index 47c1c5c22c..998807eb23 100644 --- a/pcsx2/gui/AppSaveStates.h +++ b/pcsx2/gui/AppSaveStates.h @@ -59,9 +59,12 @@ protected: extern void StateCopy_SaveToFile( const wxString& file ); extern void StateCopy_LoadFromFile( const wxString& file ); extern void StateCopy_SaveToSlot( uint num ); -extern void StateCopy_LoadFromSlot( uint slot ); +extern void StateCopy_LoadFromSlot( uint slot, bool isFromBackup = false ); + +extern void States_registerLoadBackupMenuItem( wxMenuItem* loadBackupMenuItem ); extern bool States_isSlotUsed(int num); +extern void States_DefrostCurrentSlotBackup(); extern void States_DefrostCurrentSlot(); extern void States_FreezeCurrentSlot(); extern void States_CycleSlotForward(); diff --git a/pcsx2/gui/GlobalCommands.cpp b/pcsx2/gui/GlobalCommands.cpp index f7cc4bae25..94239d1f71 100644 --- a/pcsx2/gui/GlobalCommands.cpp +++ b/pcsx2/gui/GlobalCommands.cpp @@ -275,6 +275,12 @@ static const GlobalCommandDescriptor CommandDeclarations[] = pxL( "Loads a virtual machine state from the current slot." ), }, + { "States_DefrostCurrentSlotBackup", + States_DefrostCurrentSlotBackup, + pxL( "Load State Backup" ), + pxL( "Loads virtual machine state backup for current slot." ), + }, + { "States_CycleSlotForward", States_CycleSlotForward, pxL( "Cycle to next slot" ), diff --git a/pcsx2/gui/MainFrame.cpp b/pcsx2/gui/MainFrame.cpp index 4c6e14f7fb..3f0b1b9c19 100644 --- a/pcsx2/gui/MainFrame.cpp +++ b/pcsx2/gui/MainFrame.cpp @@ -29,7 +29,7 @@ #endif // ------------------------------------------------------------------------ -wxMenu* MainEmuFrame::MakeStatesSubMenu( int baseid ) const +wxMenu* MainEmuFrame::MakeStatesSubMenu( int baseid, int loadBackupId ) const { wxMenu* mnuSubstates = new wxMenu(); @@ -37,8 +37,16 @@ wxMenu* MainEmuFrame::MakeStatesSubMenu( int baseid ) const { mnuSubstates->Append( baseid+i+1, wxsFormat(_("Slot %d"), i) ); } - mnuSubstates->AppendSeparator(); - mnuSubstates->Append( baseid - 1, _("Other...") ); + if( loadBackupId>=0 ) + { + mnuSubstates->AppendSeparator(); + + wxMenuItem* m = mnuSubstates->Append( loadBackupId, _("Backup") ); + m->Enable( false ); + States_registerLoadBackupMenuItem( m ); + } + + //mnuSubstates->Append( baseid - 1, _("Other...") ); return mnuSubstates; } @@ -210,11 +218,13 @@ void MainEmuFrame::ConnectMenus() ConnectMenu( MenuId_Sys_Restart, Menu_SysReset_Click ); ConnectMenu( MenuId_Sys_Shutdown, Menu_SysShutdown_Click ); - ConnectMenu( MenuId_State_LoadOther, Menu_LoadStateOther_Click ); + //ConnectMenu( MenuId_State_LoadOther, Menu_LoadStateOther_Click ); ConnectMenuRange(MenuId_State_Load01+1, 10, Menu_LoadStates_Click); + ConnectMenu( MenuId_State_LoadBackup, Menu_LoadStates_Click ); + - ConnectMenu( MenuId_State_SaveOther, Menu_SaveStateOther_Click ); + //ConnectMenu( MenuId_State_SaveOther, Menu_SaveStateOther_Click ); ConnectMenuRange(MenuId_State_Save01+1, 10, Menu_SaveStates_Click); @@ -306,7 +316,7 @@ MainEmuFrame::MainEmuFrame(wxWindow* parent, const wxString& title) , m_menuMisc ( *new wxMenu() ) , m_menuDebug ( *new wxMenu() ) - , m_LoadStatesSubmenu( *MakeStatesSubMenu( MenuId_State_Load01 ) ) + , m_LoadStatesSubmenu( *MakeStatesSubMenu( MenuId_State_Load01, MenuId_State_LoadBackup ) ) , m_SaveStatesSubmenu( *MakeStatesSubMenu( MenuId_State_Save01 ) ) , m_MenuItem_Console( *new wxMenuItem( &m_menuMisc, MenuId_Console, _("Show Console"), wxEmptyString, wxITEM_CHECK ) ) diff --git a/pcsx2/gui/MainFrame.h b/pcsx2/gui/MainFrame.h index fd9c4fa8f3..29cc8f8592 100644 --- a/pcsx2/gui/MainFrame.h +++ b/pcsx2/gui/MainFrame.h @@ -213,7 +213,7 @@ protected: // MainEmuFram Internal API for Populating Main Menu Contents // ------------------------------------------------------------------------ - wxMenu* MakeStatesSubMenu( int baseid ) const; + wxMenu* MakeStatesSubMenu( int baseid, int loadBackupId=-1 ) const; wxMenu* MakeStatesMenu(); wxMenu* MakeLanguagesMenu() const; diff --git a/pcsx2/gui/MainMenuClicks.cpp b/pcsx2/gui/MainMenuClicks.cpp index 8c05c61d27..c2109020a6 100644 --- a/pcsx2/gui/MainMenuClicks.cpp +++ b/pcsx2/gui/MainMenuClicks.cpp @@ -450,6 +450,12 @@ void MainEmuFrame::Menu_OpenELF_Click(wxCommandEvent&) void MainEmuFrame::Menu_LoadStates_Click(wxCommandEvent &event) { + if( event.GetId() == MenuId_State_LoadBackup ) + { + States_DefrostCurrentSlotBackup(); + return; + } + States_SetCurrentSlot( event.GetId() - MenuId_State_Load01 - 1 ); States_DefrostCurrentSlot(); } diff --git a/pcsx2/gui/Saveslots.cpp b/pcsx2/gui/Saveslots.cpp index f116cea7af..51aef54964 100644 --- a/pcsx2/gui/Saveslots.cpp +++ b/pcsx2/gui/Saveslots.cpp @@ -28,6 +28,7 @@ static int StatesC = 0; static const int StateSlotsCount = 10; +static wxMenuItem* g_loadBackupMenuItem =NULL; bool States_isSlotUsed(int num) { @@ -60,6 +61,8 @@ protected: } }; +void Sstates_updateLoadBackupMenuItem( bool isBeforeSave = false); + void States_FreezeCurrentSlot() { // FIXME : Use of the IsSavingOrLoading flag is mostly a hack until we implement a @@ -70,6 +73,7 @@ void States_FreezeCurrentSlot() Console.WriteLn( "Load or save action is already pending." ); return; } + Sstates_updateLoadBackupMenuItem( true ); GSchangeSaveState( StatesC, SaveStateBase::GetFilename( StatesC ).ToUTF8() ); StateCopy_SaveToSlot( StatesC ); @@ -77,7 +81,7 @@ void States_FreezeCurrentSlot() GetSysExecutorThread().PostIdleEvent( SysExecEvent_ClearSavingLoadingFlag() ); } -void States_DefrostCurrentSlot() +void _States_DefrostCurrentSlot( bool isFromBackup ) { if( AtomicExchange(IsSavingOrLoading, true) ) { @@ -86,9 +90,27 @@ void States_DefrostCurrentSlot() } GSchangeSaveState( StatesC, SaveStateBase::GetFilename( StatesC ).ToUTF8() ); - StateCopy_LoadFromSlot( StatesC ); + StateCopy_LoadFromSlot( StatesC, isFromBackup ); GetSysExecutorThread().PostIdleEvent( SysExecEvent_ClearSavingLoadingFlag() ); + + Sstates_updateLoadBackupMenuItem(); +} + +void States_DefrostCurrentSlot() +{ + _States_DefrostCurrentSlot( false ); +} + +void States_DefrostCurrentSlotBackup() +{ + _States_DefrostCurrentSlot( true ); +} + + +void States_registerLoadBackupMenuItem( wxMenuItem* loadBackupMenuItem ) +{ + g_loadBackupMenuItem = loadBackupMenuItem; } static void OnSlotChanged() @@ -97,6 +119,8 @@ static void OnSlotChanged() if( GSchangeSaveState != NULL ) GSchangeSaveState(StatesC, SaveStateBase::GetFilename(StatesC).mb_str()); + + Sstates_updateLoadBackupMenuItem(); } int States_GetCurrentSlot() @@ -104,6 +128,18 @@ int States_GetCurrentSlot() return StatesC; } +void Sstates_updateLoadBackupMenuItem( bool isBeforeSave ) +{ + if( !g_loadBackupMenuItem ) return; + + int slot = States_GetCurrentSlot(); + wxString file = SaveStateBase::GetFilename( slot ); + g_loadBackupMenuItem->Enable( wxFileExists( isBeforeSave && g_Conf->EmuOptions.BackupSavestate ? file : file + L".backup" ) ); + wxString label; + label.Printf(L"%s %d", _("Backup"), slot ); + g_loadBackupMenuItem->SetText( label ); +} + void States_SetCurrentSlot( int slot ) { StatesC = std::min( std::max( slot, 0 ), StateSlotsCount ); diff --git a/pcsx2/gui/SysState.cpp b/pcsx2/gui/SysState.cpp index 6aef6735dc..bff7252d9e 100644 --- a/pcsx2/gui/SysState.cpp +++ b/pcsx2/gui/SysState.cpp @@ -670,9 +670,9 @@ void StateCopy_SaveToSlot( uint num ) StateCopy_SaveToFile( file ); } -void StateCopy_LoadFromSlot( uint slot ) +void StateCopy_LoadFromSlot( uint slot, bool isFromBackup ) { - wxString file( SaveStateBase::GetFilename( slot ) ); + wxString file( SaveStateBase::GetFilename( slot ) + wxString( isFromBackup?L".backup":L"" ) ); if( !wxFileExists( file ) ) { @@ -680,7 +680,7 @@ void StateCopy_LoadFromSlot( uint slot ) return; } - Console.WriteLn( Color_StrongGreen, "Loading savestate from slot %d...", slot ); + Console.WriteLn( Color_StrongGreen, L"Loading savestate from slot %d...%s", slot, wxString( isFromBackup?L" (backup)":L"" ).c_str() ); Console.Indent().WriteLn( Color_StrongGreen, L"filename: %s", file.c_str() ); StateCopy_LoadFromFile( file );