Backup savestate system added. CheckFileExists checks for null filename.
This commit is contained in:
parent
3ee98c538f
commit
20ef5a722c
|
@ -1,4 +1,5 @@
|
|||
---version 2.0.4 yet to be released---
|
||||
22-dec-2008 - adelikat - backupSavestate system added.
|
||||
22-dec-2008 - shinydoofy - sdl - added Shift+M for toggling automatic movie backups for SDL
|
||||
22-dec-2008 - adelikat - Movie auto-backup feature implemented
|
||||
22-dec-2008 - adelikat - win32 - moved movie related menu items to a movie options dialog box
|
||||
|
|
|
@ -50,7 +50,6 @@ bool autoMovieBackup = false; //Toggle that determines if movies should be backe
|
|||
bool freshMovie = false; //True when a movie loads, false when movie is altered. Used to determine if a movie has been altered since opening
|
||||
|
||||
// Function declarations------------------------
|
||||
bool CheckFileExists(const char* filename); //Receives a filename (fullpath) and checks to see if that file exists
|
||||
|
||||
|
||||
//TODO - remove the synchack stuff from the replay gui and require it to be put into the fm2 file
|
||||
|
@ -1301,8 +1300,10 @@ void FCEUI_MakeBackupMovie(bool dispMessage)
|
|||
bool CheckFileExists(const char* filename)
|
||||
{
|
||||
//This function simply checks to see if the given filename exists
|
||||
string checkFilename;
|
||||
checkFilename = filename;
|
||||
string checkFilename;
|
||||
|
||||
if (filename)
|
||||
checkFilename = filename;
|
||||
|
||||
//Check if this filename exists
|
||||
fstream test;
|
||||
|
|
|
@ -238,7 +238,7 @@ extern bool freshMovie;
|
|||
extern bool movie_readonly;
|
||||
extern bool autoMovieBackup;
|
||||
//--------------------------------------------------
|
||||
|
||||
bool CheckFileExists(const char* filename); //Receives a filename (fullpath) and checks to see if that file exists
|
||||
void FCEUI_MakeBackupMovie(bool dispMessage);
|
||||
void FCEUI_SaveMovie(const char *fname, EMOVIE_FLAG flags, std::wstring author);
|
||||
void FCEUI_LoadMovie(const char *fname, bool read_only, bool tasedit, int _stopframe);
|
||||
|
|
|
@ -432,6 +432,10 @@ void FCEUSS_Save(const char *fname)
|
|||
//FCEU_PrintError("daCurrentState=%d",CurrentState);
|
||||
fn = strdup(FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0).c_str());
|
||||
st = FCEUD_UTF8_fstream(fn,"wb");
|
||||
|
||||
//backup existing savestate first
|
||||
if (CheckFileExists(fn)) CreateBackupSaveState(fn);
|
||||
|
||||
free(fn);
|
||||
}
|
||||
|
||||
|
@ -441,7 +445,6 @@ void FCEUSS_Save(const char *fname)
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
if(FCEUMOV_Mode(MOVIEMODE_INACTIVE))
|
||||
FCEUSS_SaveMS(st,-1);
|
||||
else
|
||||
|
@ -780,7 +783,7 @@ void FCEUI_SaveState(const char *fname)
|
|||
if(!FCEU_IsValidUI(FCEUI_SAVESTATE)) return;
|
||||
|
||||
StateShow=0;
|
||||
|
||||
|
||||
FCEUSS_Save(fname);
|
||||
}
|
||||
|
||||
|
@ -798,7 +801,7 @@ void FCEUI_LoadState(const char *fname)
|
|||
information expected in newer save states, desynchronization won't occur(at least not
|
||||
from this ;)).
|
||||
*/
|
||||
BackupSaveState();
|
||||
BackupLoadState(); //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
|
||||
{
|
||||
|
@ -847,6 +850,8 @@ void FCEU_DrawSaveStates(uint8 *XBuf)
|
|||
|
||||
string GetBackupFileName()
|
||||
{
|
||||
//This backup savestate is a special one specifically made whenever a loadstate occurs so that the user's place in a movie/game is never lost
|
||||
//particularly from unintentional loadstating
|
||||
string filename;
|
||||
int x;
|
||||
|
||||
|
@ -858,7 +863,31 @@ string GetBackupFileName()
|
|||
return filename;
|
||||
}
|
||||
|
||||
void BackupSaveState()
|
||||
void CreateBackupSaveState(const char *fname)
|
||||
{
|
||||
string filename;
|
||||
filename = fname; //Convert fname to a string object
|
||||
int x = filename.find_last_of("."); //Find file extension
|
||||
filename.insert(x-1,"-bak"); //add "-bak" before the dot. Ex: smb.fc0 becomes smb-bak.fc0
|
||||
|
||||
std::fstream* st = 0;
|
||||
st = FCEUD_UTF8_fstream(filename.c_str(),"wb");
|
||||
|
||||
if(st == NULL)
|
||||
{
|
||||
FCEU_DispMessage("State %d save error.",CurrentState);
|
||||
return;
|
||||
}
|
||||
|
||||
if(FCEUMOV_Mode(MOVIEMODE_INACTIVE))
|
||||
FCEUSS_SaveMS(st,-1);
|
||||
else
|
||||
FCEUSS_SaveMS(st,0);
|
||||
|
||||
delete st;
|
||||
}
|
||||
|
||||
void BackupLoadState()
|
||||
{
|
||||
string filename = GetBackupFileName();
|
||||
FCEUSS_Save(filename.c_str());
|
||||
|
|
|
@ -61,5 +61,6 @@ void AddExState(void *v, uint32 s, int type, char *desc);
|
|||
|
||||
void FCEU_DrawSaveStates(uint8 *XBuf);
|
||||
|
||||
void BackupSaveState(); //Makes a backupsavestate
|
||||
void CreateBackupSaveState(const char *fname); //backsup a savestate before overwriting it with a new one
|
||||
void BackupLoadState(); //Makes a backup savestate before any loadstate
|
||||
void LoadBackup(); //Loads the backupsavestate
|
Loading…
Reference in New Issue