LoadBackup function added, Win32 - Undo Loadstate context menu item added.

This commit is contained in:
adelikat 2008-12-20 02:47:33 +00:00
parent 7b035bb3bc
commit d9471d1f75
7 changed files with 93 additions and 25 deletions

View File

@ -1,4 +1,5 @@
---version 2.0.4 yet to be released--- ---version 2.0.4 yet to be released---
19-dec-2008 - adelikat - Loadbackup function added, Win32 - Undo Loadstate context menu item
19-dec-2008 - adelikat - Backup savestate is made before loading a state 19-dec-2008 - adelikat - Backup savestate is made before loading a state
18-dec-2008 - adelikat - win32 - turbo bypasses sound better if muteturbo is checked 18-dec-2008 - adelikat - win32 - turbo bypasses sound better if muteturbo is checked
18-dec-2008 - shinydoofy - sdl - fixed compiling errors for SDL due to r1037 18-dec-2008 - shinydoofy - sdl - fixed compiling errors for SDL due to r1037

View File

@ -340,6 +340,7 @@ BEGIN
MENUITEM "&Replay Movie", FCEUX_CONTEXT_REPLAYMOVIE MENUITEM "&Replay Movie", FCEUX_CONTEXT_REPLAYMOVIE
MENUITEM "Record Movie", FCEUX_CONTEXT_RECORDMOVIE MENUITEM "Record Movie", FCEUX_CONTEXT_RECORDMOVIE
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "Undo loadstate", FCEUX_CONTEXT_UNDOLOADSTATE
MENUITEM "Rewind to last auto-save", FCEUX_CONTEXT_REWINDTOLASTAUTO MENUITEM "Rewind to last auto-save", FCEUX_CONTEXT_REWINDTOLASTAUTO
MENUITEM "Screenshot", FCEUX_CONTEXT_SCREENSHOT MENUITEM "Screenshot", FCEUX_CONTEXT_SCREENSHOT
MENUITEM SEPARATOR MENUITEM SEPARATOR
@ -357,6 +358,7 @@ BEGIN
MENUITEM "Stop Movie Recording", FCEU_CONTEXT_STOPMOVIE MENUITEM "Stop Movie Recording", FCEU_CONTEXT_STOPMOVIE
MENUITEM "View comments and subtitles", FCEUX_CONTEXT_VIEWCOMMENTSSUBTITLES MENUITEM "View comments and subtitles", FCEUX_CONTEXT_VIEWCOMMENTSSUBTITLES
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "Undo loadstate", FCEUX_CONTEXT_UNDOLOADSTATE
MENUITEM "Rewind to last auto-save", FCEUX_CONTEXT_REWINDTOLASTAUTO MENUITEM "Rewind to last auto-save", FCEUX_CONTEXT_REWINDTOLASTAUTO
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "Help...", FCEU_CONTEXT_MOVIEHELP MENUITEM "Help...", FCEU_CONTEXT_MOVIEHELP

View File

@ -383,7 +383,6 @@
#define MEMW_EDIT02RMADDRESS 1190 #define MEMW_EDIT02RMADDRESS 1190
#define INSERTCS_STATIC 1190 #define INSERTCS_STATIC 1190
#define MEMW_EDIT03RMADDRESS 1191 #define MEMW_EDIT03RMADDRESS 1191
#define IDC_DEBUG_RESTORESIZE 1191
#define IDC_DEBUGGER_RESTORESIZE 1191 #define IDC_DEBUGGER_RESTORESIZE 1191
#define MEMW_EDIT04RMADDRESS 1192 #define MEMW_EDIT04RMADDRESS 1192
#define EDIT00_RESULTS 1193 #define EDIT00_RESULTS 1193
@ -625,6 +624,10 @@
#define ID_GAME_VIEWCOMMENTSSUBTITLES40312 40312 #define ID_GAME_VIEWCOMMENTSSUBTITLES40312 40312
#define ID_OPTIONS_COLLAPSETO1COLUMN 40313 #define ID_OPTIONS_COLLAPSETO1COLUMN 40313
#define MEMW_OPTIONS_EXPANDCOLLAPSE 40314 #define MEMW_OPTIONS_EXPANDCOLLAPSE 40314
#define ID_GAME_UNDOLOADSTATE 40315
#define FCEUX_CONTEXT_UNDOLOADSTATE 40316
#define ID_GAME_UNDOLOADSTATE40317 40317
#define ID_GAME_UNDOLOADSTATE40318 40318
#define IDC_DEBUGGER_ICONTRAY 55535 #define IDC_DEBUGGER_ICONTRAY 55535
#define MW_ValueLabel2 65423 #define MW_ValueLabel2 65423
#define MW_ValueLabel1 65426 #define MW_ValueLabel1 65426
@ -634,7 +637,7 @@
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 125 #define _APS_NEXT_RESOURCE_VALUE 125
#define _APS_NEXT_COMMAND_VALUE 40315 #define _APS_NEXT_COMMAND_VALUE 40319
#define _APS_NEXT_CONTROL_VALUE 1192 #define _APS_NEXT_CONTROL_VALUE 1192
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif

View File

@ -6,7 +6,9 @@
using namespace std; using namespace std;
//Externs //Externs
extern int CurrentState; //Declared in src/state.cpp extern int CurrentState; //Declared in src/state.cpp
extern bool FCEUSS_Load(const char *fname); //Declared in src/state.cpp
extern string GetBackupFileName(); //Declared in src/state.cpp
bool CheckBackupSaveStateExist(); //Checks if backupsavestate exists bool CheckBackupSaveStateExist(); //Checks if backupsavestate exists
/** /**
@ -69,26 +71,21 @@ void FCEUD_LoadStateFrom()
bool CheckBackupSaveStateExist() bool CheckBackupSaveStateExist()
{ {
//This function simply checks to see if the backup savestate of the appropriate filename exists //This function simply checks to see if the backup savestate of the appropriate filename exists
string filename; string filename = GetBackupFileName(); //Get backup savestate filename
int x;
filename = strdup(FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0).c_str()); //Generate normal savestate filename
x = filename.find_last_of("."); //Find last dot
filename = filename.substr(0,x); //Chop off file extension
filename.append(".bak"); //add .bak
//Check if this filename exists //Check if this filename exists
fstream test; fstream test;
test.open(filename.c_str(),fstream::in); test.open(filename.c_str(),fstream::in);
FCEUI_printf("Checking %s\n",filename.c_str());
if (test.fail()) if (test.fail())
{ {
test.close(); test.close(); FCEUI_printf("Fail\n");
return false; return false;
} }
else else
{ {
test.close(); test.close(); FCEUI_printf("Succeed\n");
return true; return true;
} }
} }

View File

@ -93,6 +93,7 @@ void ShowNetplayConsole(void); //mbg merge 7/17/06 YECH had to add
void MapInput(void); void MapInput(void);
extern BOOL CALLBACK ReplayMetadataDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); //Metadata dialog extern BOOL CALLBACK ReplayMetadataDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); //Metadata dialog
extern bool CheckBackupSaveStateExist(); //Checks if backupsavestate exists extern bool CheckBackupSaveStateExist(); //Checks if backupsavestate exists
extern void LoadBackup();
//AutoFire----------------------------------------------- //AutoFire-----------------------------------------------
static int CheckedAutoFirePattern = MENU_AUTOFIRE_PATTERN_1; static int CheckedAutoFirePattern = MENU_AUTOFIRE_PATTERN_1;
@ -409,6 +410,34 @@ void UpdateCheckedMenuItems()
} }
} }
void UpdateContextMenuItems(HMENU context, int whichContext)
{
bool exist;
switch(whichContext)
{
//0 = Game + Movie in read only
case 0:
break;
//1 = Game + No Movie
case 1:
exist = CheckBackupSaveStateExist();
EnableMenuItem(context,FCEUX_CONTEXT_UNDOLOADSTATE,MF_BYCOMMAND | exist ? MF_ENABLED : MF_GRAYED);
break;
//2 = No Game
case 2:
break;
//3 = Game + Movie in read + write
case 3:
exist = CheckBackupSaveStateExist();
EnableMenuItem(context,FCEUX_CONTEXT_UNDOLOADSTATE,MF_BYCOMMAND | exist ? MF_ENABLED : MF_GRAYED);
break;
default:
break;
}
}
/// Updates recent files / recent directories menu /// Updates recent files / recent directories menu
/// @param menu Menu handle of the main window's menu /// @param menu Menu handle of the main window's menu
/// @param strs Strings to add to the menu /// @param strs Strings to add to the menu
@ -721,6 +750,8 @@ void GetMouseData(uint32 (&md)[3])
//Message loop of the main window //Message loop of the main window
LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{ {
int whichContext = 0;
switch(msg) switch(msg)
{ {
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
@ -734,22 +765,36 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
hfceuxcontext = LoadMenu(fceu_hInstance,"FCEUCONTEXTMENUS"); hfceuxcontext = LoadMenu(fceu_hInstance,"FCEUCONTEXTMENUS");
//If There is a movie loaded in read only //If There is a movie loaded in read only
if (GameInfo && FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_RECORD) && movie_readonly) if (GameInfo && FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_RECORD) && movie_readonly)
{
hfceuxcontextsub = GetSubMenu(hfceuxcontext,0); hfceuxcontextsub = GetSubMenu(hfceuxcontext,0);
whichContext = 0;
}
//If there is a movie loaded in read+write //If there is a movie loaded in read+write
else if (GameInfo && FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_RECORD) && !movie_readonly) else if (GameInfo && FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_RECORD) && !movie_readonly)
{
hfceuxcontextsub = GetSubMenu(hfceuxcontext,3); hfceuxcontextsub = GetSubMenu(hfceuxcontext,3);
whichContext = 3;
}
//If there is a ROM loaded but no movie //If there is a ROM loaded but no movie
else if (GameInfo) else if (GameInfo)
{
hfceuxcontextsub = GetSubMenu(hfceuxcontext,1); hfceuxcontextsub = GetSubMenu(hfceuxcontext,1);
whichContext = 1;
}
//Else no ROM //Else no ROM
else else
{
hfceuxcontextsub = GetSubMenu(hfceuxcontext,2); hfceuxcontextsub = GetSubMenu(hfceuxcontext,2);
whichContext = 2;
}
UpdateContextMenuItems(hfceuxcontextsub, whichContext);
TrackPopupMenu(hfceuxcontextsub,0,(MainWindow_wndx+mousex),(MainWindow_wndy+mousey),TPM_RIGHTBUTTON,hWnd,0); TrackPopupMenu(hfceuxcontextsub,0,(MainWindow_wndx+mousex),(MainWindow_wndy+mousey),TPM_RIGHTBUTTON,hWnd,0);
} }
case WM_MOVE: case WM_MOVE:
@ -1268,18 +1313,25 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
//View comments and subtitles //View comments and subtitles
case FCEUX_CONTEXT_VIEWCOMMENTSSUBTITLES: case FCEUX_CONTEXT_VIEWCOMMENTSSUBTITLES:
CreateDialog(fceu_hInstance, "IDD_REPLAY_METADATA", hWnd, ReplayMetadataDialogProc, (LPARAM)0); CreateDialog(fceu_hInstance, "IDD_REPLAY_METADATA", hWnd, ReplayMetadataDialogProc, (LPARAM)0);
break;
//Undo Loadstate
case FCEUX_CONTEXT_UNDOLOADSTATE:
if (CheckBackupSaveStateExist())
LoadBackup();
break;
//Load last auto-save //Load last auto-save
case FCEUX_CONTEXT_REWINDTOLASTAUTO: case FCEUX_CONTEXT_REWINDTOLASTAUTO:
FCEUI_Autosave(); FCEUI_Autosave();
break; break;
//Movie help //Game + Movie - Help
case FCEU_CONTEXT_MOVIEHELP: case FCEU_CONTEXT_MOVIEHELP:
OpenHelpWindow(moviehelp); OpenHelpWindow(moviehelp);
break; break;
//No Game //No Game - Help
case FCEU_CONTEXT_FCEUHELP: case FCEU_CONTEXT_FCEUHELP:
OpenHelpWindow(gettingstartedhelp); OpenHelpWindow(gettingstartedhelp);
break; break;

View File

@ -839,16 +839,28 @@ void FCEU_DrawSaveStates(uint8 *XBuf)
StateShow--; StateShow--;
} }
void BackupSaveState() string GetBackupFileName()
{ {
//Everytime a load state is loaded, this is run prior so that the user has a backup of the previous emulator state
string filename; string filename;
int x; int x;
filename = strdup(FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0).c_str()); //Generate normal savestate filename filename = strdup(FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0).c_str()); //Generate normal savestate filename
x = filename.find_last_of("."); //Find last dot x = filename.find_last_of("."); //Find last dot
filename = filename.substr(0,x); //Chop off file extension filename = filename.substr(0,x); //Chop off file extension
filename.append(".bak"); //add .bak filename.append(".bak.fc0"); //add .bak
FCEUI_printf("%s\n",filename.c_str());
return filename;
} }
void BackupSaveState()
{
string filename = GetBackupFileName();
FCEUSS_Save(filename.c_str());
FCEUI_printf("File %s loaded.\n",filename.c_str());
}
void LoadBackup()
{
string filename = GetBackupFileName();
FCEUSS_Load(filename.c_str());
}

View File

@ -61,4 +61,5 @@ void AddExState(void *v, uint32 s, int type, char *desc);
void FCEU_DrawSaveStates(uint8 *XBuf); void FCEU_DrawSaveStates(uint8 *XBuf);
void BackupSaveState(); //Makes a backupsavestate void BackupSaveState(); //Makes a backupsavestate
void LoadBackup(); //Loads the backupsavestate