From f0a3f8cf21179d05e44862c318318c12b0895490 Mon Sep 17 00:00:00 2001 From: CaH4e3 Date: Sat, 8 May 2010 09:27:42 +0000 Subject: [PATCH] redundant code removed, let windows doing it on by own --- src/drivers/win/cdlogger.cpp | 32 ++++++++++++++++---------------- src/drivers/win/input.cpp | 6 +----- src/drivers/win/memview.cpp | 14 ++------------ src/drivers/win/memwatch.cpp | 8 ++------ src/drivers/win/ramwatch.cpp | 12 +----------- src/drivers/win/replay.cpp | 6 +----- src/drivers/win/state.cpp | 8 +------- src/drivers/win/tasedit.cpp | 12 ++---------- src/drivers/win/texthook.cpp | 6 +----- src/drivers/win/tracer.cpp | 1 - src/drivers/win/wave.cpp | 8 +------- src/drivers/win/window.cpp | 14 ++------------ 12 files changed, 30 insertions(+), 97 deletions(-) diff --git a/src/drivers/win/cdlogger.cpp b/src/drivers/win/cdlogger.cpp index e0f186bf..b8cf66d3 100644 --- a/src/drivers/win/cdlogger.cpp +++ b/src/drivers/win/cdlogger.cpp @@ -237,7 +237,10 @@ void LoadCDLogFile(){ } void SaveCDLogFileAs(){ + //don't be stupid const char filter[]="Code Data Log File (*.CDL)\0*.cdl\0All Files (*.*)\0*.*\0\0"; + //this feature not for select desired file extension for saved filename + //this feature only for filter file list only for desired file extension. char nameo[2048]; OPENFILENAME ofn; memset(&ofn,0,sizeof(ofn)); @@ -246,16 +249,23 @@ void SaveCDLogFileAs(){ ofn.lpstrTitle="Save Code Data Log File As..."; ofn.lpstrFilter=filter; strcpy(nameo,GetRomName()); - AddExtensionIfMissing(nameo, sizeof(nameo), ".cdl"); + //don't be stupid, + ofn.lpstrDefExt = "cdl"; + //do this automatically with system function, it is doing exactly what it written for + //why do you need to do this one more time? All we need here, filled extension in dialog window + //BEFORE saving it, there is no other options. ofn.lpstrFile=nameo; - //ofn.lpstrDefExt = "cdl"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; ofn.hwndOwner = hCDLogger; + //after that we will get complete file with ext added automatically from DefExt string + //change ext in Save Dialog and it will be saved if(!GetSaveFileName(&ofn))return; - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(nameo, sizeof(nameo), ".cdl"); + //there is bad if something is written AFTER i selectdesired file extension in Save Dialog + //when I want NOT to have any extension, it will write me default one, that is stupid, + //in addition, this is silently forcing default extension to file, but user didn't know about it at all + //that's all what needed to work. I checked this and it works exactly what it should strcpy(loadedcdfile,nameo); SaveCDLogFile(); return; @@ -334,26 +344,16 @@ void SaveStrippedRom(){ //this is based off of iNesSave() strcpy(sromfilename,GetRomName()); if (GameInfo->type==GIT_NSF) { ofn.lpstrFilter=NSFfilter; - //ofn.lpstrDefExt = "nsf"; - AddExtensionIfMissing(sromfilename, sizeof(sromfilename), ".nsf"); + ofn.lpstrDefExt = "nsf"; } else { ofn.lpstrFilter=NESfilter; - //ofn.lpstrDefExt = "nes"; - AddExtensionIfMissing(sromfilename, sizeof(sromfilename), ".nes"); + ofn.lpstrDefExt = "nes"; } ofn.lpstrFile=sromfilename; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; ofn.hwndOwner = hCDLogger; if(!GetSaveFileName(&ofn))return; - - if (ofn.nFilterIndex == 1) { - if (GameInfo->type==GIT_NSF) { - AddExtensionIfMissing(sromfilename, sizeof(sromfilename), ".nsf"); - } else { - AddExtensionIfMissing(sromfilename, sizeof(sromfilename), ".nes"); - } - } fp = fopen(sromfilename,"wb"); diff --git a/src/drivers/win/input.cpp b/src/drivers/win/input.cpp index 172a2f4b..effef0dc 100644 --- a/src/drivers/win/input.cpp +++ b/src/drivers/win/input.cpp @@ -1565,9 +1565,8 @@ static void PresetExport(int preset) ofn.lpstrTitle="Export Input Preset To..."; ofn.lpstrFilter=filter; nameo[0]=0; //No default filename - //AddExtensionIfMissing(nameo, sizeof(nameo), ".pre"); ofn.lpstrFile=nameo; - //ofn.lpstrDefExt="pre"; + ofn.lpstrDefExt="pre"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT; std::string initdir = FCEU_GetPath(FCEUMKF_INPUT).c_str(); @@ -1583,9 +1582,6 @@ static void PresetExport(int preset) InputPresetDir[ofn.nFileOffset]=0; } - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(nameo, sizeof(nameo), ".pre"); - FILE *fp=FCEUD_UTF8fopen(nameo,"w"); switch(preset) { diff --git a/src/drivers/win/memview.cpp b/src/drivers/win/memview.cpp index 0e19a326..ed6c1add 100644 --- a/src/drivers/win/memview.cpp +++ b/src/drivers/win/memview.cpp @@ -299,19 +299,13 @@ void SaveRomAs() ofn.lpstrTitle="Save Nes ROM as..."; ofn.lpstrFilter=filter; strcpy(nameo,GetRomName()); - AddExtensionIfMissing(nameo, sizeof(nameo), ".nes"); ofn.lpstrFile=nameo; - //ofn.lpstrDefExt="nes"; + ofn.lpstrDefExt="nes"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; ofn.hwndOwner = hMemView; if (GetSaveFileName(&ofn)) - { - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(nameo, sizeof(nameo), ".nes"); - iNesSaveAs(nameo); - } } int LoadTable(const char* nameo) @@ -648,17 +642,13 @@ void dumpToFile(const char* buffer, unsigned int size) ofn.lpstrTitle="Save to file ..."; ofn.lpstrFilter="Binary File (*.BIN)\0*.bin\0All Files (*.*)\0*.*\0\0"; strcpy(name,GetRomName()); - AddExtensionIfMissing(name, sizeof(name), ".bin"); ofn.lpstrFile=name; - //ofn.lpstrDefExt="bin"; + ofn.lpstrDefExt="bin"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY; if (GetSaveFileName(&ofn)) { - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(name, sizeof(name), ".bin"); - FILE* memfile = fopen(name, "wb"); if (!memfile || fwrite(buffer, 1, size, memfile) != size) diff --git a/src/drivers/win/memwatch.cpp b/src/drivers/win/memwatch.cpp index 8892db14..fc2ba2c9 100644 --- a/src/drivers/win/memwatch.cpp +++ b/src/drivers/win/memwatch.cpp @@ -406,15 +406,14 @@ static void SaveMemWatch() ofn.hInstance=fceu_hInstance; ofn.lpstrTitle="Save Memory Watch As..."; ofn.lpstrFilter=filter; - //ofn.lpstrDefExt="txt"; + ofn.lpstrDefExt="txt"; char nameo[2048]; if (!memwLastFilename[0]) strcpy(nameo,GetRomName()); else strcpy(nameo,memwLastFilename); - AddExtensionIfMissing(nameo, sizeof(nameo), ".txt"); ofn.lpstrFile=nameo; - //ofn.lpstrDefExt="txt"; + ofn.lpstrDefExt="txt"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT; string initdir = FCEU_GetPath(FCEUMKF_MEMW); @@ -432,9 +431,6 @@ static void SaveMemWatch() MemWatchDir[ofn.nFileOffset]=0; } - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(nameo, sizeof(nameo), ".txt"); - strcpy(memwLastFilename,nameo); SaveStrings(); diff --git a/src/drivers/win/ramwatch.cpp b/src/drivers/win/ramwatch.cpp index b3c68948..fb37f405 100644 --- a/src/drivers/win/ramwatch.cpp +++ b/src/drivers/win/ramwatch.cpp @@ -481,11 +481,6 @@ int Change_File_S(char *Dest, char *Dir, char *Titre, char *Filter, char *Ext, H { OPENFILENAME ofn; - char *TempExt = 0; - TempExt=(char*)malloc(sizeof(Ext)+2); - strcpy(TempExt, "."); - strcat(TempExt, Ext); - SetCurrentDirectory(applicationPath); if (!strcmp(Dest, "")) @@ -499,20 +494,16 @@ int Change_File_S(char *Dest, char *Dir, char *Titre, char *Filter, char *Ext, H ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.hInstance = hInst; - AddExtensionIfMissing(Dest, 1024, TempExt); //1024 checked manually ofn.lpstrFile = Dest; ofn.nMaxFile = 2047; ofn.lpstrFilter = Filter; ofn.nFilterIndex = 1; ofn.lpstrInitialDir = Dir; ofn.lpstrTitle = Titre; - //ofn.lpstrDefExt = Ext; + ofn.lpstrDefExt = Ext; ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (GetSaveFileName(&ofn)) { - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(Dest, 1024, TempExt); //1024 checked manually - return 1; } @@ -525,7 +516,6 @@ bool Save_Watches() strcpy(Str_Tmp,slash ? slash+1 : gamefilename); char* dot = strrchr(Str_Tmp, '.'); if(dot) *dot = 0; - strcat(Str_Tmp,".wch"); if(Change_File_S(Str_Tmp, applicationPath, "Save Watches", "Watchlist (*.wch)\0*.wch\0All Files (*.*)\0*.*\0\0", "wch", RamWatchHWnd)) { FILE *WatchFile = fopen(Str_Tmp,"r+b"); diff --git a/src/drivers/win/replay.cpp b/src/drivers/win/replay.cpp index 9e98b693..5d5caf1a 100644 --- a/src/drivers/win/replay.cpp +++ b/src/drivers/win/replay.cpp @@ -921,15 +921,11 @@ static BOOL CALLBACK RecordDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwndDlg; ofn.lpstrFilter = "FCEUX Movie File (*.fm2)\0*.fm2\0All Files (*.*)\0*.*\0\0"; - AddExtensionIfMissing(szChoice, sizeof(szChoice), ".fm2"); ofn.lpstrFile = szChoice; - //ofn.lpstrDefExt = "fm2"; + ofn.lpstrDefExt = "fm2"; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if(GetSaveFileName(&ofn)) { - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(szChoice, sizeof(szChoice), ".fm2"); - UpdateRecordDialogPath(hwndDlg,szChoice); } } diff --git a/src/drivers/win/state.cpp b/src/drivers/win/state.cpp index d8534ffb..dfe14ec8 100644 --- a/src/drivers/win/state.cpp +++ b/src/drivers/win/state.cpp @@ -25,21 +25,15 @@ void FCEUD_SaveStateAs() ofn.lpstrTitle = "Save State As..."; ofn.lpstrFilter = filter; strcpy(nameo,FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0).c_str()); - AddExtensionIfMissing(nameo, sizeof(nameo), ".fcs"); ofn.lpstrFile = nameo; - //ofn.lpstrDefExt = "fcs"; + ofn.lpstrDefExt = "fcs"; std::string initdir = FCEU_GetPath(FCEUMKF_STATE); ofn.lpstrInitialDir = initdir.c_str(); ofn.nMaxFile = 256; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; if(GetSaveFileName(&ofn)) - { - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(nameo, sizeof(nameo), ".fcs"); - FCEUI_SaveState(nameo); - } } /** diff --git a/src/drivers/win/tasedit.cpp b/src/drivers/win/tasedit.cpp index 28bbc115..3dc1bfe3 100644 --- a/src/drivers/win/tasedit.cpp +++ b/src/drivers/win/tasedit.cpp @@ -892,9 +892,8 @@ static void SaveProjectAs() char nameo[2048]; //File name strcpy(nameo, GetRomName()); //For now, just use ROM name - AddExtensionIfMissing(nameo, sizeof(nameo), ".tas"); ofn.lpstrFile=nameo; //More parameters - //ofn.lpstrDefExt="tas"; + ofn.lpstrDefExt="tas"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT; string initdir = FCEU_GetPath(FCEUMKF_MOVIE); //Initial directory @@ -902,9 +901,6 @@ static void SaveProjectAs() if(GetSaveFileName(&ofn)) //If it is a valid filename { - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(nameo, sizeof(nameo), ".tas"); - std::string tempstr = nameo; //Make a temporary string for filename char drv[512], dir[512], name[512], ext[512]; //For getting the filename! @@ -948,17 +944,13 @@ static void Export() ofn.hInstance=fceu_hInstance; ofn.lpstrTitle="Export TAS as..."; ofn.lpstrFilter=filter; - AddExtensionIfMissing(fname, sizeof(fname), ".fm2"); ofn.lpstrFile=fname; - //ofn.lpstrDefExt="fm2"; + ofn.lpstrDefExt="fm2"; ofn.nMaxFile=256; std::string initdir = FCEU_GetPath(FCEUMKF_MOVIE); ofn.lpstrInitialDir=initdir.c_str(); if(GetSaveFileName(&ofn)) { - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(fname, sizeof(fname), ".fm2"); - fstream* osRecordingMovie = FCEUD_UTF8_fstream(fname, "wb"); currMovieData.dump(osRecordingMovie,false); delete osRecordingMovie; diff --git a/src/drivers/win/texthook.cpp b/src/drivers/win/texthook.cpp index 9e66f10e..1347d8ed 100644 --- a/src/drivers/win/texthook.cpp +++ b/src/drivers/win/texthook.cpp @@ -692,9 +692,8 @@ int TextHookerSaveTableFile(){ ofn.lpstrTitle="Load Table File..."; ofn.lpstrFilter=filter; strcpy(nameo,GetRomName()); - AddExtensionIfMissing(nameo, sizeof(nameo), ".tht"); ofn.lpstrFile=nameo; - //ofn.lpstrDefExt="tht"; + ofn.lpstrDefExt="tht"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_EXTENSIONDIFFERENT; ofn.hwndOwner = hCDLogger; @@ -702,9 +701,6 @@ int TextHookerSaveTableFile(){ //get the file name or quit if(!GetSaveFileName(&ofn))return 0; - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(nameo, sizeof(nameo), ".tht"); - //open the file FP = fopen(nameo,"wb"); line = 0; //init the line counter diff --git a/src/drivers/win/tracer.cpp b/src/drivers/win/tracer.cpp index fbe1ee1c..8f937576 100644 --- a/src/drivers/win/tracer.cpp +++ b/src/drivers/win/tracer.cpp @@ -593,7 +593,6 @@ void ShowLogDirDialog(void){ ofn.lpstrFilter=filter; strcpy(nameo,GetRomName()); ofn.lpstrFile=nameo; - //ofn.lpstrDefExt="log"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; ofn.hwndOwner = hTracer; diff --git a/src/drivers/win/wave.cpp b/src/drivers/win/wave.cpp index 5858181d..67d4ecc4 100644 --- a/src/drivers/win/wave.cpp +++ b/src/drivers/win/wave.cpp @@ -45,19 +45,13 @@ bool CreateSoundSave() ofn.lpstrTitle="Log Sound As..."; ofn.lpstrFilter=filter; strcpy(nameo,GetRomName()); - AddExtensionIfMissing(nameo, sizeof(nameo), ".wav"); ofn.lpstrFile=nameo; - //ofn.lpstrDefExt="wav"; + ofn.lpstrDefExt="wav"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; if(GetSaveFileName(&ofn)) - { - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(nameo, sizeof(nameo), ".wav"); - return FCEUI_BeginWaveRecord(nameo); - } return false; } diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index f1e61fde..69cae5a9 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -2421,21 +2421,15 @@ void FCEUD_AviRecordTo(void) ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hAppWnd; ofn.lpstrFilter = "AVI Files (*.avi)\0*.avi\0All Files (*.*)\0*.*\0\0"; - AddExtensionIfMissing(szChoice, sizeof(szChoice), ".avi"); ofn.lpstrFile = szChoice; - //ofn.lpstrDefExt = "avi"; + ofn.lpstrDefExt = "avi"; ofn.lpstrTitle = "Save AVI as"; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if(GetSaveFileName(&ofn)) - { - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(szChoice, sizeof(szChoice), ".avi"); - FCEUI_AviBegin(szChoice); - } } //Stop AVI recording @@ -2707,9 +2701,8 @@ void SaveMovieAs() ofn.lpstrTitle="Save Movie as..."; ofn.lpstrFilter=filter; strcpy(nameo,curMovieFilename); - AddExtensionIfMissing(tempName, ".fm2"); ofn.lpstrFile=nameo; - //ofn.lpstrDefExt="fm2"; + ofn.lpstrDefExt="fm2"; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; ofn.hwndOwner = hMemView; @@ -2717,9 +2710,6 @@ void SaveMovieAs() { tempName = nameo; - if (ofn.nFilterIndex == 1) - AddExtensionIfMissing(tempName, ".fm2"); - FCEUI_CreateMovieFile(tempName); } }