Savestates: fixed errors handling (broken by previous commit)

This commit is contained in:
ansstuff 2013-04-19 12:58:14 +00:00
parent c497432785
commit 510b8a770b
5 changed files with 53 additions and 48 deletions

View File

@ -2245,7 +2245,7 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
//Load last auto-save //Load last auto-save
case FCEUX_CONTEXT_REWINDTOLASTAUTO: case FCEUX_CONTEXT_REWINDTOLASTAUTO:
FCEUI_Autosave(); FCEUI_RewindToLastAutosave();
break; break;
//Create a backup movie file //Create a backup movie file

View File

@ -150,7 +150,7 @@ static void FCEU_CloseGame(void)
if (AutoResumePlay) if (AutoResumePlay)
{ {
// save "-resume" savestate // save "-resume" savestate
FCEUSS_Save(FCEU_MakeFName(FCEUMKF_RESUMESTATE, 0, 0).c_str()); FCEUSS_Save(FCEU_MakeFName(FCEUMKF_RESUMESTATE, 0, 0).c_str(), false);
} }
#ifdef WIN32 #ifdef WIN32
@ -497,10 +497,8 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen
if (AutoResumePlay) if (AutoResumePlay)
{ {
// load "-resume" savestate // load "-resume" savestate
if (FCEUSS_Load(FCEU_MakeFName(FCEUMKF_RESUMESTATE, 0, 0).c_str())) if (FCEUSS_Load(FCEU_MakeFName(FCEUMKF_RESUMESTATE, 0, 0).c_str(), false))
FCEU_DispMessage("Old play session resumed.", 0); FCEU_DispMessage("Old play session resumed.", 0);
else
FCEU_DispMessage("", 0);
} }
ResetScreenshotsCounter(); ResetScreenshotsCounter();
@ -968,7 +966,7 @@ void UpdateAutosave(void) {
AutosaveCounter = 0; AutosaveCounter = 0;
AutosaveIndex = (AutosaveIndex + 1) % AutosaveQty; AutosaveIndex = (AutosaveIndex + 1) % AutosaveQty;
f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str()); f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str());
FCEUSS_Save(f); FCEUSS_Save(f, false);
AutoSS = true; //Flag that an auto-savestate was made AutoSS = true; //Flag that an auto-savestate was made
free(f); free(f);
f = NULL; f = NULL;
@ -976,7 +974,7 @@ void UpdateAutosave(void) {
} }
} }
void FCEUI_Autosave(void) { void FCEUI_RewindToLastAutosave(void) {
if (!EnableAutosave || !AutoSS) if (!EnableAutosave || !AutoSS)
return; return;

View File

@ -31,7 +31,7 @@ void PowerNES(void);
void SetAutoFireOffset(int offset); void SetAutoFireOffset(int offset);
void SetAutoFirePattern(int onframes, int offframes); void SetAutoFirePattern(int onframes, int offframes);
void AutoFire(void); void AutoFire(void);
void FCEUI_Autosave(void); void FCEUI_RewindToLastAutosave(void);
//mbg 7/23/06 //mbg 7/23/06
char *FCEUI_GetAboutString(); char *FCEUI_GetAboutString();

View File

@ -759,7 +759,7 @@ struct EMUCMDTABLE FCEUI_CommandTable[]=
{ EMUCMD_VSUNI_TOGGLE_DIP_7, EMUCMDTYPE_VSUNI, CommandToggleDip, 0, 0, "Toggle Dipswitch 7", 0 }, { EMUCMD_VSUNI_TOGGLE_DIP_7, EMUCMDTYPE_VSUNI, CommandToggleDip, 0, 0, "Toggle Dipswitch 7", 0 },
{ EMUCMD_VSUNI_TOGGLE_DIP_8, EMUCMDTYPE_VSUNI, CommandToggleDip, 0, 0, "Toggle Dipswitch 8", 0 }, { EMUCMD_VSUNI_TOGGLE_DIP_8, EMUCMDTYPE_VSUNI, CommandToggleDip, 0, 0, "Toggle Dipswitch 8", 0 },
{ EMUCMD_VSUNI_TOGGLE_DIP_9, EMUCMDTYPE_VSUNI, CommandToggleDip, 0, 0, "Toggle Dipswitch 9", 0 }, { EMUCMD_VSUNI_TOGGLE_DIP_9, EMUCMDTYPE_VSUNI, CommandToggleDip, 0, 0, "Toggle Dipswitch 9", 0 },
{ EMUCMD_MISC_AUTOSAVE, EMUCMDTYPE_MISC, FCEUI_Autosave, 0, 0, "Load Last Auto-save", 0}, { EMUCMD_MISC_AUTOSAVE, EMUCMDTYPE_MISC, FCEUI_RewindToLastAutosave, 0, 0, "Load Last Auto-save", 0},
{ EMUCMD_MISC_SHOWSTATES, EMUCMDTYPE_MISC, ViewSlots, 0, 0, "View save slots", 0 }, { EMUCMD_MISC_SHOWSTATES, EMUCMDTYPE_MISC, ViewSlots, 0, 0, "View save slots", 0 },
{ EMUCMD_MISC_USE_INPUT_PRESET_1, EMUCMDTYPE_MISC, CommandUsePreset, 0, 0, "Use Input Preset 1", EMUCMDFLAG_TASEDITOR }, { EMUCMD_MISC_USE_INPUT_PRESET_1, EMUCMDTYPE_MISC, CommandUsePreset, 0, 0, "Use Input Preset 1", EMUCMDFLAG_TASEDITOR },
{ EMUCMD_MISC_USE_INPUT_PRESET_2, EMUCMDTYPE_MISC, CommandUsePreset, 0, 0, "Use Input Preset 2", EMUCMDFLAG_TASEDITOR }, { EMUCMD_MISC_USE_INPUT_PRESET_2, EMUCMDTYPE_MISC, CommandUsePreset, 0, 0, "Use Input Preset 2", EMUCMDFLAG_TASEDITOR },

View File

@ -453,6 +453,7 @@ void FCEUSS_Save(const char *fname, bool display_message)
if (geniestage==1) if (geniestage==1)
{ {
if (display_message)
FCEU_DispMessage("Cannot save FCS in GG screen.",0); FCEU_DispMessage("Cannot save FCS in GG screen.",0);
return; return;
} }
@ -480,8 +481,9 @@ void FCEUSS_Save(const char *fname, bool display_message)
st = FCEUD_UTF8_fstream(fn,"wb"); st = FCEUD_UTF8_fstream(fn,"wb");
} }
if(display_message && st == NULL || st->get_fp() == NULL) if (st == NULL || st->get_fp() == NULL)
{ {
if (display_message)
FCEU_DispMessage("State %d save error.", 0, CurrentState); FCEU_DispMessage("State %d save error.", 0, CurrentState);
return; return;
} }
@ -519,9 +521,10 @@ void FCEUSS_Save(const char *fname, bool display_message)
delete st; delete st;
if(display_message && !fname) if(!fname)
{ {
SaveStateStatus[CurrentState] = 1; SaveStateStatus[CurrentState] = 1;
if (display_message)
FCEU_DispMessage("State %d saved.", 0, CurrentState); FCEU_DispMessage("State %d saved.", 0, CurrentState);
} }
redoSS = false; //we have a new savestate so redo is not possible redoSS = false; //we have a new savestate so redo is not possible
@ -715,6 +718,7 @@ bool FCEUSS_Load(const char *fname, bool display_message)
if (geniestage == 1) if (geniestage == 1)
{ {
if (display_message)
FCEU_DispMessage("Cannot load FCS in GG screen.",0); FCEU_DispMessage("Cannot load FCS in GG screen.",0);
return false; return false;
} }
@ -722,18 +726,20 @@ bool FCEUSS_Load(const char *fname, bool display_message)
{ {
st = FCEUD_UTF8_fstream(fname, "rb"); st = FCEUD_UTF8_fstream(fname, "rb");
strcpy(fn, fname); strcpy(fn, fname);
} } else
else
{ {
strcpy(fn, FCEU_MakeFName(FCEUMKF_STATE,CurrentState,fname).c_str()); strcpy(fn, FCEU_MakeFName(FCEUMKF_STATE,CurrentState,fname).c_str());
st=FCEUD_UTF8_fstream(fn,"rb"); st=FCEUD_UTF8_fstream(fn,"rb");
strcpy(lastLoadstateMade,fn); strcpy(lastLoadstateMade,fn);
} }
if(display_message && st == NULL || (st->get_fp() == NULL)) if (st == NULL || (st->get_fp() == NULL))
{
if (display_message)
{ {
FCEU_DispMessage("State %d load error.", 0, CurrentState); FCEU_DispMessage("State %d load error.", 0, CurrentState);
//FCEU_DispMessage("State %d load error. Filename: %s", 0, CurrentState, fn); //FCEU_DispMessage("State %d load error. Filename: %s", 0, CurrentState, fn);
}
SaveStateStatus[CurrentState] = 0; SaveStateStatus[CurrentState] = 0;
return false; return false;
} }
@ -747,17 +753,18 @@ bool FCEUSS_Load(const char *fname, bool display_message)
{ {
char szFilename[260]={0}; char szFilename[260]={0};
splitpath(fname, 0, 0, szFilename, 0); splitpath(fname, 0, 0, szFilename, 0);
if (display_message){ if (display_message)
{
FCEU_DispMessage("State %s loaded.", 0, szFilename); FCEU_DispMessage("State %s loaded.", 0, szFilename);
}
//FCEU_DispMessage("State %s loaded. Filename: %s", 0, szFilename, fn); //FCEU_DispMessage("State %s loaded. Filename: %s", 0, szFilename, fn);
} }
else } else
{
if (display_message)
{ {
if (display_message) {
FCEU_DispMessage("State %d loaded.", 0, CurrentState); FCEU_DispMessage("State %d loaded.", 0, CurrentState);
}
//FCEU_DispMessage("State %d loaded. Filename: %s", 0, CurrentState, fn); //FCEU_DispMessage("State %d loaded. Filename: %s", 0, CurrentState, fn);
}
SaveStateStatus[CurrentState] = 1; SaveStateStatus[CurrentState] = 1;
} }
delete st; delete st;
@ -793,15 +800,16 @@ bool FCEUSS_Load(const char *fname, bool display_message)
cur_input_display = FCEU_GetJoyJoy(); //Input display should show the last buttons pressed (stored in the savestate) cur_input_display = FCEU_GetJoyJoy(); //Input display should show the last buttons pressed (stored in the savestate)
return true; return true;
} } else
else
{ {
if(!fname) if(!fname)
{
SaveStateStatus[CurrentState] = 1; SaveStateStatus[CurrentState] = 1;
}
if (display_message)
{
FCEU_DispMessage("Error(s) reading state %d!", 0, CurrentState); FCEU_DispMessage("Error(s) reading state %d!", 0, CurrentState);
//FCEU_DispMessage("Error(s) reading state %d! Filename: %s", 0, CurrentState, fn); //FCEU_DispMessage("Error(s) reading state %d! Filename: %s", 0, CurrentState, fn);
}
delete st; delete st;
return 0; return 0;
} }
@ -938,7 +946,6 @@ bool file_exists(const char * filename)
return false; return false;
} }
void FCEUI_LoadState(const char *fname, bool display_message) void FCEUI_LoadState(const char *fname, bool display_message)
{ {
if(!FCEU_IsValidUI(FCEUI_LOADSTATE)) return; if(!FCEU_IsValidUI(FCEUI_LOADSTATE)) return;
@ -950,7 +957,8 @@ void FCEUI_LoadState(const char *fname, bool display_message)
information expected in newer save states, desynchronization won't occur(at least not information expected in newer save states, desynchronization won't occur(at least not
from this ;)). from this ;)).
*/ */
if (backupSavestates) BackupLoadState(); //If allowed, backup the current state before loading a new one if (backupSavestates)
BackupLoadState(); // If allowed, backup the current state before loading a new one
if (!movie_readonly && autoMovieBackup && freshMovie) //If auto-backup is on, movie has not been altered this session and the movie is in read+write mode if (!movie_readonly && autoMovieBackup && freshMovie) //If auto-backup is on, movie has not been altered this session and the movie is in read+write mode
{ {
@ -989,8 +997,7 @@ void FCEUI_LoadState(const char *fname, bool display_message)
} }
#endif #endif
freshMovie = false; //The movie has been altered so it is no longer fresh freshMovie = false; //The movie has been altered so it is no longer fresh
} } else
else
{ {
loadStateFailed = 1; loadStateFailed = 1;
} }