From e29081de7a4b5cb7da5e7786f3a4e240a5c9ad04 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 15 Nov 2008 02:38:12 +0000 Subject: [PATCH] Win32 - texthooker and memory watch use ROM name as default file name in Save as dialog box --- src/drivers/win/main.cpp | 20 ++++++++++++++++++++ src/drivers/win/main.h | 2 ++ src/drivers/win/memwatch.cpp | 7 +++++-- src/drivers/win/texthook.cpp | 5 ++--- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 166968d1..0d19dbac 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -63,6 +63,8 @@ #include "sound.h" #include "wave.h" #include "video.h" +#include "utils/xstring.h" +#include //--------------------------- //mbg merge 6/29/06 - new aboutbox @@ -880,3 +882,21 @@ void FCEUD_ToggleStatusIcon(void) UpdateCheckedMenuItems(); } +char *GetRomName() +{ + //The purpose of this function is to format the ROM name stored in LoadedRomFName + //And return a char array with just the name with path or extension + //The purpose of this function is to populate a save as dialog with the ROM name as a default filename + extern char LoadedRomFName[2048]; //Contains full path of ROM + std::string Rom; //Will contain the formatted path + if(GameInfo) //If ROM is loaded + { + char drv[PATH_MAX], dir[PATH_MAX], name[PATH_MAX], ext[PATH_MAX]; + splitpath(LoadedRomFName,drv,dir,name,ext); //Extract components of the ROM path + Rom = name; //Pull out the Name only + } + char*mystring = (char*)malloc(2048*sizeof(char)); + strcpy(mystring, Rom.c_str()); //Convert string to char* + + return mystring; +} diff --git a/src/drivers/win/main.h b/src/drivers/win/main.h index 4f2a3f55..aa2c0e0b 100644 --- a/src/drivers/win/main.h +++ b/src/drivers/win/main.h @@ -48,6 +48,8 @@ extern int vmod; extern char* directory_names[14]; +char *GetRomName(); //Checks if rom is loaded, if so, outputs the Rom name with no directory path or file extension + ///Contains the names of the default directories. static const char *default_directory_names[13] = { "", // roms diff --git a/src/drivers/win/memwatch.cpp b/src/drivers/win/memwatch.cpp index e1dac0cc..3ddf6968 100644 --- a/src/drivers/win/memwatch.cpp +++ b/src/drivers/win/memwatch.cpp @@ -26,6 +26,7 @@ #include "../../utils/xstring.h" #include "help.h" #include +#include "main.h" const int NUMWATCHES = 24; const int LABELLENGTH = 64; const int ADDRESSLENGTH = 16; @@ -366,8 +367,10 @@ static void SaveMemWatch() ofn.hInstance=fceu_hInstance; ofn.lpstrTitle="Save Memory Watch As..."; ofn.lpstrFilter=filter; - memwLastFilename[0]=0; - ofn.lpstrFile=memwLastFilename; + char nameo[2048]; + if (!memwLastFilename[0]) + strcpy(nameo,GetRomName()); + ofn.lpstrFile=nameo; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT; std::string initdir = FCEU_GetPath(FCEUMKF_MEMW); diff --git a/src/drivers/win/texthook.cpp b/src/drivers/win/texthook.cpp index 95efde8c..996a9dec 100644 --- a/src/drivers/win/texthook.cpp +++ b/src/drivers/win/texthook.cpp @@ -40,13 +40,12 @@ #include "..\..\video.h" //needed for XBuf #include "cdlogger.h" //needed for TextHookerLoadTable #include "fceu.h" - +#include "main.h" char *textToTrans; // buffer to hold the text that needs translating char *transText; //holds the translated text extern void FCEUD_BlitScreen(uint8 *XBuf); //needed for pause, not sure where this is defined... - //adelikat merge 7/1/08 - had to add these extern variables //------------------------------ extern uint8 PALRAM[0x20]; @@ -686,7 +685,7 @@ int TextHookerSaveTableFile(){ ofn.hInstance=fceu_hInstance; ofn.lpstrTitle="Load Table File..."; ofn.lpstrFilter=filter; - nameo[0]=0; + strcpy(nameo,GetRomName()); ofn.lpstrFile=nameo; ofn.lpstrDefExt="tht"; ofn.nMaxFile=256;