From 9ee1449a74b35ad0ff42cec7b65a03a2ccf14aaa Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 25 May 2009 20:30:32 +0000 Subject: [PATCH] Win32 - new Context Menu item - Save Movie As.. available when a movie is loaded in read+write mode. --- changelog.txt | 1 + src/drivers/win/res.rc | 1 + src/drivers/win/resource.h | 4 +++- src/drivers/win/window.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/movie.cpp | 16 ++++++++++------ src/movie.h | 1 + 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/changelog.txt b/changelog.txt index 344d5d93..e08f2be6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,4 @@ +23-may-2009 - adelikat - win32 - context menu - Save Movie As... menu item (for when a movie is loaded in read+write mode) 23-may-2009 - adelikat - win32 - added opton to remove a recent item to the roms, lua, and movie recent menus 23-may-2009 - adelikat - win32 - Added a remove recent item function and hooked it up to memwatch recent menu, now if a bad recent item is clicked, the user has a choice to remove it from the list 23-may-2009 - adelikat - win32 - Load Last Movie context menu item added diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 94ac2e0f..78acdf5f 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -369,6 +369,7 @@ BEGIN MENUITEM "Stop Movie Recording", FCEU_CONTEXT_STOPMOVIE MENUITEM "View comments and subtitles", FCEUX_CONTEXT_VIEWCOMMENTSSUBTITLES MENUITEM "Make backup", FCEUX_CONTEXT_MAKEBACKUP + MENUITEM "Save Movie As...", FCEUX_CONTEXT_SAVEMOVIEAS MENUITEM SEPARATOR MENUITEM "Undo savestate", FCEUX_CONTEXT_UNDOSAVESTATE MENUITEM "Undo loadstate", FCEUX_CONTEXT_UNDOLOADSTATE diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index 4818f062..b3f240bd 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -684,6 +684,8 @@ #define MENU_MOVIE_RECENT 40354 #define ID_GAME_LOADLASTMOVIE 40355 #define FCEUX_CONTEXT_LOADLASTMOVIE 40356 +#define ID_GAME_SAVEMOVIEAS 40357 +#define FCEUX_CONTEXT_SAVEMOVIEAS 40358 #define IDC_DEBUGGER_ICONTRAY 55535 #define MW_ValueLabel2 65423 #define MW_ValueLabel1 65426 @@ -693,7 +695,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 125 -#define _APS_NEXT_COMMAND_VALUE 40357 +#define _APS_NEXT_COMMAND_VALUE 40359 #define _APS_NEXT_CONTROL_VALUE 1204 #define _APS_NEXT_SYMED_VALUE 101 #endif diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index adcea3b2..d58a4abd 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -129,6 +129,7 @@ bool rightClickEnabled = true; //If set to false, the right click context menu //Function Prototypes void ChangeMenuItemText(int menuitem, string text); //Alters a menu item name void ChangeContextMenuItemText(int menuitem, string text, HMENU menu); //Alters a context menu item name +void SaveMovieAs(); //Gets a filename for Save Movie As... //Recent Menu Strings ------------------------------------ char *recent_files[] = { 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; @@ -1758,6 +1759,7 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) } break; + //Recent Movie 1 case FCEUX_CONTEXT_LOADLASTMOVIE: if(recent_movie[0]) { @@ -1801,6 +1803,12 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) case FCEUX_CONTEXT_MAKEBACKUP: FCEUI_MakeBackupMovie(true); break; + + //Create a backup based on user entering a filename + case FCEUX_CONTEXT_SAVEMOVIEAS: + SaveMovieAs(); + break; + //Game + Movie - Help case FCEU_CONTEXT_MOVIEHELP: OpenHelpWindow(moviehelp); @@ -2580,4 +2588,34 @@ void UpdateMenuHotkeys() combo = GetKeyComboName(FCEUD_CommandMapping[EMUCMD_TOOL_OPENCDLOGGER]); combined = "&Code/Data Logger...\t" + combo; ChangeMenuItemText(MENU_CDLOGGER, combined); +} + +//This function is for the context menu item Save Movie As... +//It gets a filename from the user then calls CreateMovie() +void SaveMovieAs() +{ + const char filter[]="NES Movie file (*.fm2)\0*.fm2\0"; + char nameo[2048]; + std::string tempName; + int x; + + OPENFILENAME ofn; + memset(&ofn,0,sizeof(ofn)); + ofn.lStructSize=sizeof(ofn); + ofn.hInstance=fceu_hInstance; + ofn.lpstrTitle="Save Movie as..."; + ofn.lpstrFilter=filter; + strcpy(nameo,curMovieFilename); + ofn.lpstrFile=nameo; + ofn.nMaxFile=256; + ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; + ofn.hwndOwner = hMemView; + if (GetSaveFileName(&ofn)) + { + tempName = nameo; + x = tempName.find_last_of("."); //Check to see if the user provided a file extension + if (x < 0) + tempName.append(".fm2"); //If not, make it .fm2 + FCEUI_CreateMovieFile(tempName); + } } \ No newline at end of file diff --git a/src/movie.cpp b/src/movie.cpp index 1e129586..e2da3430 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -1293,6 +1293,14 @@ void FCEU_DisplaySubtitles(char *format, ...) subtitleMessage.isMovieMessage = subtitlesOnAVI; } +void FCEUI_CreateMovieFile(std::string fn) +{ + MovieData md = currMovieData; //Get current movie data + std::fstream* outf = FCEUD_UTF8_fstream(fn, "wb"); //open/create file + md.dump(outf,false); //dump movie data + delete outf; //clean up, delete file object +} + void FCEUI_MakeBackupMovie(bool dispMessage) { //This function generates backup movie files @@ -1337,12 +1345,8 @@ void FCEUI_MakeBackupMovie(bool dispMessage) } } } - - 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 - + FCEUI_CreateMovieFile(backupFn); + //TODO, decide if fstream successfully opened the file and print error message if it doesn't if (dispMessage) //If we should inform the user diff --git a/src/movie.h b/src/movie.h index be919b39..700f6f0b 100644 --- a/src/movie.h +++ b/src/movie.h @@ -242,6 +242,7 @@ 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_CreateMovieFile(std::string fn); void FCEUI_SaveMovie(const char *fname, EMOVIE_FLAG flags, std::wstring author); bool FCEUI_LoadMovie(const char *fname, bool read_only, bool tasedit, int _stopframe); void FCEUI_MoviePlayFromBeginning(void);