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
case FCEUX_CONTEXT_REWINDTOLASTAUTO:
FCEUI_Autosave();
FCEUI_RewindToLastAutosave();
break;
//Create a backup movie file

View File

@ -150,7 +150,7 @@ static void FCEU_CloseGame(void)
if (AutoResumePlay)
{
// 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
@ -497,10 +497,8 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen
if (AutoResumePlay)
{
// 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);
else
FCEU_DispMessage("", 0);
}
ResetScreenshotsCounter();
@ -968,7 +966,7 @@ void UpdateAutosave(void) {
AutosaveCounter = 0;
AutosaveIndex = (AutosaveIndex + 1) % AutosaveQty;
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
free(f);
f = NULL;
@ -976,7 +974,7 @@ void UpdateAutosave(void) {
}
}
void FCEUI_Autosave(void) {
void FCEUI_RewindToLastAutosave(void) {
if (!EnableAutosave || !AutoSS)
return;

View File

@ -31,7 +31,7 @@ void PowerNES(void);
void SetAutoFireOffset(int offset);
void SetAutoFirePattern(int onframes, int offframes);
void AutoFire(void);
void FCEUI_Autosave(void);
void FCEUI_RewindToLastAutosave(void);
//mbg 7/23/06
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_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_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_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 },

View File

@ -451,9 +451,10 @@ void FCEUSS_Save(const char *fname, bool display_message)
EMUFILE* st = 0;
char fn[2048];
if(geniestage==1)
if (geniestage==1)
{
FCEU_DispMessage("Cannot save FCS in GG screen.",0);
if (display_message)
FCEU_DispMessage("Cannot save FCS in GG screen.",0);
return;
}
@ -480,9 +481,10 @@ void FCEUSS_Save(const char *fname, bool display_message)
st = FCEUD_UTF8_fstream(fn,"wb");
}
if(display_message && st == NULL || st->get_fp() == NULL)
if (st == NULL || st->get_fp() == NULL)
{
FCEU_DispMessage("State %d save error.",0,CurrentState);
if (display_message)
FCEU_DispMessage("State %d save error.", 0, CurrentState);
return;
}
@ -519,10 +521,11 @@ void FCEUSS_Save(const char *fname, bool display_message)
delete st;
if(display_message && !fname)
if(!fname)
{
SaveStateStatus[CurrentState]=1;
FCEU_DispMessage("State %d saved.",0,CurrentState);
SaveStateStatus[CurrentState] = 1;
if (display_message)
FCEU_DispMessage("State %d saved.", 0, CurrentState);
}
redoSS = false; //we have a new savestate so redo is not possible
}
@ -713,52 +716,56 @@ bool FCEUSS_Load(const char *fname, bool display_message)
// MovieFlushHeader();
//}
if(geniestage==1)
if (geniestage == 1)
{
FCEU_DispMessage("Cannot load FCS in GG screen.",0);
if (display_message)
FCEU_DispMessage("Cannot load FCS in GG screen.",0);
return false;
}
if(fname)
if (fname)
{
st=FCEUD_UTF8_fstream(fname, "rb");
st = FCEUD_UTF8_fstream(fname, "rb");
strcpy(fn, fname);
}
else
} else
{
strcpy(fn, FCEU_MakeFName(FCEUMKF_STATE,CurrentState,fname).c_str());
st=FCEUD_UTF8_fstream(fn,"rb");
strcpy(lastLoadstateMade,fn);
}
if(display_message && st == NULL || (st->get_fp() == NULL))
if (st == NULL || (st->get_fp() == NULL))
{
FCEU_DispMessage("State %d load error.",0,CurrentState);
//FCEU_DispMessage("State %d load error. Filename: %s",0,CurrentState, fn);
SaveStateStatus[CurrentState]=0;
if (display_message)
{
FCEU_DispMessage("State %d load error.", 0, CurrentState);
//FCEU_DispMessage("State %d load error. Filename: %s", 0, CurrentState, fn);
}
SaveStateStatus[CurrentState] = 0;
return false;
}
//If in bot mode, don't do a backup when loading.
//Otherwise you eat at the hard disk, since so many
//states are being loaded.
if(FCEUSS_LoadFP(st, backupSavestates ? SSLOADPARAM_BACKUP : SSLOADPARAM_NOBACKUP))
if (FCEUSS_LoadFP(st, backupSavestates ? SSLOADPARAM_BACKUP : SSLOADPARAM_NOBACKUP))
{
if(fname)
if (fname)
{
char szFilename[260]={0};
splitpath(fname, 0, 0, szFilename, 0);
if (display_message){
FCEU_DispMessage("State %s loaded.",0,szFilename);
if (display_message)
{
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) {
FCEU_DispMessage("State %d loaded.",0,CurrentState);
if (display_message)
{
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;
@ -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)
return true;
}
else
} else
{
if(!fname)
SaveStateStatus[CurrentState] = 1;
if (display_message)
{
SaveStateStatus[CurrentState]=1;
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!",0,CurrentState);
//FCEU_DispMessage("Error(s) reading state %d! Filename: %s",0,CurrentState, fn);
delete st;
return 0;
}
@ -921,7 +929,7 @@ void FCEUI_SaveState(const char *fname, bool display_message)
{
if(!FCEU_IsValidUI(FCEUI_SAVESTATE)) return;
StateShow=0;
StateShow = 0;
FCEUSS_Save(fname, display_message);
}
@ -938,7 +946,6 @@ bool file_exists(const char * filename)
return false;
}
void FCEUI_LoadState(const char *fname, bool display_message)
{
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
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
{
@ -961,7 +969,7 @@ void FCEUI_LoadState(const char *fname, bool display_message)
loadStateFailed = 1;
return; // state doesn't exist; exit cleanly
}
if(FCEUSS_Load(fname, display_message))
if (FCEUSS_Load(fname, display_message))
{
//mbg todo netplay
#if 0
@ -989,8 +997,7 @@ void FCEUI_LoadState(const char *fname, bool display_message)
}
#endif
freshMovie = false; //The movie has been altered so it is no longer fresh
}
else
} else
{
loadStateFailed = 1;
}