Movie auto-back feature implemented

This commit is contained in:
adelikat 2008-12-23 01:07:55 +00:00
parent 6fb09465ca
commit d8d239e35d
6 changed files with 106 additions and 95 deletions

View File

@ -1,4 +1,5 @@
---version 2.0.4 yet to be released---
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
22-dec-2008 - adelikat - Win32 - context menu item "create backup" for backing up movie files
21-dec-2008 - adelikat - Win32 - Name Table Viewer - Refresh value default to 15, Refresh value stored in config file

View File

@ -94,7 +94,6 @@ void ShowNetplayConsole(void); //mbg merge 7/17/06 YECH had to add
void MapInput(void);
extern BOOL CALLBACK ReplayMetadataDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); //Metadata dialog
extern void MakeBackupMovie(bool dispMessage); //Makes a backup of current movie file
extern bool CheckFileExists(const char* filename); //Receives a filename (fullpath) and checks to see if that file exists
//AutoFire-----------------------------------------------
@ -1315,7 +1314,7 @@ UpdateContextMenuItems(hfceuxcontextsub, whichContext);
//Create a backup movie file
case FCEUX_CONTEXT_MAKEBACKUP:
MakeBackupMovie(true);
FCEUI_MakeBackupMovie(true);
break;
//Game + Movie - Help
case FCEU_CONTEXT_MOVIEHELP:

View File

@ -74,11 +74,6 @@ bool justLagged = false;
bool frameAdvanceLagSkip = false; //If this is true, frame advance will skip over lag frame (i.e. it will emulate 2 frames instead of 1)
bool movieSubtitles = true; //Toggle for displaying movie subtitles
bool autoMovieBackup = false; //Toggle that determines if movies should be backed up automatically before altering them
// Function declarations
void MakeBackupMovie(bool dispMessage); //Makes a backup of current movie file
bool CheckFileExists(const char* filename); //Receives a filename (fullpath) and checks to see if that file exists
FCEUGI::FCEUGI()
: filename(0)
@ -1088,87 +1083,4 @@ uint8 FCEU_ReadRomByte(uint32 i) {
if(i < 16+PRGsize[0])return PRGptr[0][i-16];
if(i < 16+PRGsize[0]+CHRsize[0])return CHRptr[0][i-16-PRGsize[0]];
return 0;
}
void MakeBackupMovie(bool dispMessage)
{
//This function generates backup movie files
string currentFn; //Current movie fillename
string backupFn; //Target backup filename
string tempFn; //temp used in back filename creation
stringstream stream;
int x; //Temp variable for string manip
bool exist = false; //Used to test if filename exists
bool overflow = false; //Used for special situation when backup numbering exceeds limit
currentFn = curMovieFilename; //Get current moviefilename
backupFn = curMovieFilename; //Make backup filename the same as current moviefilename
x = backupFn.find_last_of("."); //Find file extension
backupFn = backupFn.substr(0,x); //Remove extension
tempFn = backupFn; //Store the filename at this point
for (unsigned int backNum=0;backNum<999;backNum++) //999 = arbituary limit to backup files
{
stream.str(""); //Clear stream
if (backNum > 99)
stream << "-" << backNum; //assign backNum to stream
else if (backNum <=99 && backNum >= 10)
stream << "-0"; //Make it 010, etc if two digits
else
stream << "-00" << backNum; //Make it 001, etc if single digit
backupFn.append(stream.str()); //add number to bak filename
backupFn.append(".bak"); //add extension
exist = CheckFileExists(backupFn.c_str()); //Check if file exists
if (!exist)
break; //Yeah yeah, I should use a do loop or something
else
{
backupFn = tempFn; //Before we loop again, reset the filename
if (backNum == 999) //If 999 exists, we have overflowed, let's handle that
{
backupFn.append("-001.bak"); //We are going to simply overwrite 001.bak
overflow = true; //Flag that we have exceeded limit
break; //Just in case
}
}
}
MovieData md = currMovieData; //Get current movie data
std::fstream* outf = FCEUD_UTF8_fstream(backupFn, "wb"); //open/create file
md.dump(outf,false); //dump movie data
delete outf; //clean up, delete file object
//TODO, decide if fstream successfully opened the file and print error message if it doesn't
if (dispMessage) //If we should inform the user
{
if (overflow)
FCEUI_DispMessage("Overwriting %s",backupFn.c_str()); //Inform user of overflow
else
FCEUI_DispMessage("%s created",backupFn.c_str()); //Inform user of backup filename
}
}
bool CheckFileExists(const char* filename)
{
//This function simply checks to see if the given filename exists
string checkFilename;
checkFilename = filename;
//Check if this filename exists
fstream test;
test.open(checkFilename.c_str(),fstream::in);
if (test.fail())
{
test.close();
return false;
}
else
{
test.close();
return true;
}
}

View File

@ -46,6 +46,12 @@ std::vector<int> subtitleFrames; //Frame numbers for subtitle messages
std::vector<string> subtitleMessages; //Messages of subtitles
bool subtitlesOnAVI = false;
bool autoMovieBackup = false; //Toggle that determines if movies should be backed up automatically before altering them
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
//which the user would have already converted from fcm
@ -620,6 +626,7 @@ void FCEUI_StopMovie()
StopRecording();
curMovieFilename[0] = 0;
freshMovie = false;
}
static void poweron(bool shouldDisableBatteryLoading)
@ -734,6 +741,8 @@ void FCEUI_LoadMovie(const char *fname, bool _read_only, bool tasedit, int _paus
LoadSubtitles();
delete fp;
freshMovie = true; //Movie has been loaded, so it must be unaltered
//fully reload the game to reinitialize everything before playing any movie
poweron(true);
@ -1227,3 +1236,86 @@ void FCEU_DisplaySubtitles(char *format, ...)
subtitleMessage.howlong = 300;
subtitleMessage.isMovieMessage = subtitlesOnAVI;
}
void FCEUI_MakeBackupMovie(bool dispMessage)
{
//This function generates backup movie files
string currentFn; //Current movie fillename
string backupFn; //Target backup filename
string tempFn; //temp used in back filename creation
stringstream stream;
int x; //Temp variable for string manip
bool exist = false; //Used to test if filename exists
bool overflow = false; //Used for special situation when backup numbering exceeds limit
currentFn = curMovieFilename; //Get current moviefilename
backupFn = curMovieFilename; //Make backup filename the same as current moviefilename
x = backupFn.find_last_of("."); //Find file extension
backupFn = backupFn.substr(0,x); //Remove extension
tempFn = backupFn; //Store the filename at this point
for (unsigned int backNum=0;backNum<999;backNum++) //999 = arbituary limit to backup files
{
stream.str(""); //Clear stream
if (backNum > 99)
stream << "-" << backNum; //assign backNum to stream
else if (backNum <=99 && backNum >= 10)
stream << "-0"; //Make it 010, etc if two digits
else
stream << "-00" << backNum; //Make it 001, etc if single digit
backupFn.append(stream.str()); //add number to bak filename
backupFn.append(".bak"); //add extension
exist = CheckFileExists(backupFn.c_str()); //Check if file exists
if (!exist)
break; //Yeah yeah, I should use a do loop or something
else
{
backupFn = tempFn; //Before we loop again, reset the filename
if (backNum == 999) //If 999 exists, we have overflowed, let's handle that
{
backupFn.append("-001.bak"); //We are going to simply overwrite 001.bak
overflow = true; //Flag that we have exceeded limit
break; //Just in case
}
}
}
MovieData md = currMovieData; //Get current movie data
std::fstream* outf = FCEUD_UTF8_fstream(backupFn, "wb"); //open/create file
md.dump(outf,false); //dump movie data
delete outf; //clean up, delete file object
//TODO, decide if fstream successfully opened the file and print error message if it doesn't
if (dispMessage) //If we should inform the user
{
if (overflow)
FCEUI_DispMessage("Overwriting %s",backupFn.c_str()); //Inform user of overflow
else
FCEUI_DispMessage("%s created",backupFn.c_str()); //Inform user of backup filename
}
}
bool CheckFileExists(const char* filename)
{
//This function simply checks to see if the given filename exists
string checkFilename;
checkFilename = filename;
//Check if this filename exists
fstream test;
test.open(checkFilename.c_str(),fstream::in);
if (test.fail())
{
test.close();
return false;
}
else
{
test.close();
return true;
}
}

View File

@ -234,8 +234,12 @@ extern MovieData currMovieData;
extern int currFrameCounter;
extern char curMovieFilename[512];
extern bool subtitlesOnAVI;
//---------
extern bool freshMovie;
extern bool movie_readonly;
extern bool autoMovieBackup;
//--------------------------------------------------
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);
void FCEUI_MoviePlayFromBeginning(void);
@ -251,6 +255,4 @@ void LoadSubtitles(void);
void ProcessSubtitles(void);
void FCEU_DisplaySubtitles(char *format, ...);
#endif //__MOVIE_H_
#endif //__MOVIE_H_

View File

@ -799,7 +799,11 @@ void FCEUI_LoadState(const char *fname)
from this ;)).
*/
BackupSaveState();
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
{
FCEUI_MakeBackupMovie(false); //Backup the movie before the contents get altered, but do not display messages
}
if(FCEUSS_Load(fname))
{
//mbg todo netplay
@ -825,6 +829,7 @@ void FCEUI_LoadState(const char *fname)
free(fn);
}*/
freshMovie = false; //The movie has been altered so it is no longer fresh
}
else
{