diff --git a/src/drivers/win/config.cpp b/src/drivers/win/config.cpp index 1b82abdd..a2bbdb5e 100644 --- a/src/drivers/win/config.cpp +++ b/src/drivers/win/config.cpp @@ -49,6 +49,8 @@ extern bool frameAdvanceLagSkip; extern int ClipSidesOffset; extern bool movieSubtitles; extern bool subtitlesOnAVI; +extern bool autoMovieBackup; +extern bool bindSavestate; extern int PPUViewRefresh; extern int NTViewRefresh; extern uint8 gNoBGFillColor; diff --git a/src/drivers/win/movieoptions.cpp b/src/drivers/win/movieoptions.cpp index 6e69c1ea..61cfd72c 100644 --- a/src/drivers/win/movieoptions.cpp +++ b/src/drivers/win/movieoptions.cpp @@ -23,13 +23,14 @@ //internal variables int pauseAfterPlayback = 0; //Flag for pausing emulator when movie is finished -bool bindSavestate = true; //Toggle that determines if a savestate filename will include the movie filename -bool autoMovieBackup = false; //Toggle that determines if movies should be backed up automatically before altering them + //external extern int status_icon; //In main.cpp - For displaying movie status icons (play,record,pause) extern bool movieSubtitles; //In fceu.cpp - Toggle for displaying movie subtitles extern bool subtitlesOnAVI; //In movie.cpp - Toggle for putting movie subtitles in an AVI +extern bool autoMovieBackup;//In fceu.cpp - Toggle that determines if movies should be backed up automatically before altering them +extern bool bindSavestate ; //Toggle that determines if a savestate filename will include the movie filename void UpdateCheckBoxes(HWND hwndDlg) { diff --git a/src/drivers/win/movieoptions.h b/src/drivers/win/movieoptions.h index 05a6ac11..76782962 100644 --- a/src/drivers/win/movieoptions.h +++ b/src/drivers/win/movieoptions.h @@ -1,5 +1,3 @@ void OpenMovieOptions(); -extern int pauseAfterPlayback; -extern bool bindSavestate; -extern bool autoMovieBackup; \ No newline at end of file +extern int pauseAfterPlayback; \ No newline at end of file diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 0a7136f8..902b0c49 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -94,9 +94,8 @@ 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 -// 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 +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----------------------------------------------- void SetAutoFirePattern(int onframes, int offframes); @@ -2042,87 +2041,4 @@ void UpdateMenuHotkeys() combo = GetKeyComboName(FCEUD_CommandMapping[EMUCMD_TOOL_OPENCDLOGGER]); combined = "Code/Data Logger...\t" + combo; ChangeMenuItemText(MENU_CDLOGGER, combined); -} - -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; - } } \ No newline at end of file diff --git a/src/fceu.cpp b/src/fceu.cpp index f24ad118..cec1a944 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -50,6 +50,9 @@ #include "vsuni.h" #include "ines.h" +#include +#include + #ifdef _S9XLUA_H #include "fceulua.h" #endif @@ -64,12 +67,18 @@ #include "drivers/sdl/sdl.h" #endif +using namespace std; int AFon = 1, AFoff = 1, AutoFireOffset = 0; //For keeping track of autofire settings 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) @@ -1079,4 +1088,87 @@ 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; + } } \ No newline at end of file diff --git a/src/file.cpp b/src/file.cpp index 6d50f6c9..7e194054 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -48,7 +48,7 @@ using namespace std; - +bool bindSavestate = true; //Toggle that determines if a savestate filename will include the movie filename static std::string BaseDirectory; static char FileExt[2048]; //Includes the . character, as in ".nes" char FileBase[2048];