Added 'AddExtensionIfMissing', which replaces every other means of adding a missing extension to a file, and allows one to use All File to save with any extension. Added 'All Files' option to all dialogs that didn't have it. Uses the file extension a user manually selects to pick what extension to add to a filename.

Also did other save dialog optimizations and normalizations, because I was looking at all of them over and over again.
This commit is contained in:
ugetab 2010-05-06 21:48:23 +00:00
parent 63ad8f4bbf
commit 672c187177
15 changed files with 149 additions and 112 deletions

View File

@ -219,7 +219,7 @@ void LoadCDLog (const char* nameo)
} }
void LoadCDLogFile(){ void LoadCDLogFile(){
const char filter[]="Code Data Log File(*.CDL)\0*.cdl\0"; const char filter[]="Code Data Log File(*.CDL)\0*.cdl\0\0";
char nameo[2048]; char nameo[2048];
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -237,7 +237,7 @@ void LoadCDLogFile(){
} }
void SaveCDLogFileAs(){ void SaveCDLogFileAs(){
const char filter[]="Code Data Log File(*.CDL)\0*.cdl\0"; const char filter[]="Code Data Log File(*.CDL)\0*.cdl\0All Files (*.*)\0*.*\0\0";
char nameo[2048]; char nameo[2048];
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -245,13 +245,16 @@ void SaveCDLogFileAs(){
ofn.hInstance=fceu_hInstance; ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Save Code Data Log File As..."; ofn.lpstrTitle="Save Code Data Log File As...";
ofn.lpstrFilter=filter; ofn.lpstrFilter=filter;
ofn.lpstrDefExt = "cdl"; //ofn.lpstrDefExt = "cdl";
strcpy(nameo,GetRomName()); strcpy(nameo,GetRomName());
ofn.lpstrFile=nameo; ofn.lpstrFile=nameo;
ofn.nMaxFile=256; ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
ofn.hwndOwner = hCDLogger; ofn.hwndOwner = hCDLogger;
if(!GetSaveFileName(&ofn))return; if(!GetSaveFileName(&ofn))return;
if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(nameo, sizeof(nameo), ".cdl");
strcpy(loadedcdfile,nameo); strcpy(loadedcdfile,nameo);
SaveCDLogFile(); SaveCDLogFile();
return; return;
@ -307,8 +310,8 @@ void UpdateCDLogger(){
void SaveStrippedRom(){ //this is based off of iNesSave() void SaveStrippedRom(){ //this is based off of iNesSave()
//todo: make this support nsfs //todo: make this support nsfs
const char NESfilter[]="Stripped iNes Rom file(*.NES)\0*.nes\0"; const char NESfilter[]="Stripped iNes Rom file(*.NES)\0*.nes\0All Files (*.*)\0*.*\0\0";
const char NSFfilter[]="Stripped NSF file(*.NSF)\0*.nsf\0"; const char NSFfilter[]="Stripped NSF file(*.NSF)\0*.nsf\0All Files (*.*)\0*.*\0\0";
char sromfilename[MAX_PATH]; char sromfilename[MAX_PATH];
FILE *fp; FILE *fp;
OPENFILENAME ofn; OPENFILENAME ofn;
@ -329,11 +332,10 @@ void SaveStrippedRom(){ //this is based off of iNesSave()
ofn.lpstrTitle="Save Stripped File As..."; ofn.lpstrTitle="Save Stripped File As...";
if (GameInfo->type==GIT_NSF) { if (GameInfo->type==GIT_NSF) {
ofn.lpstrFilter=NSFfilter; ofn.lpstrFilter=NSFfilter;
ofn.lpstrDefExt = "nsf"; //ofn.lpstrDefExt = "nsf";
} } else {
else {
ofn.lpstrFilter=NESfilter; ofn.lpstrFilter=NESfilter;
ofn.lpstrDefExt = "nes"; //ofn.lpstrDefExt = "nes";
} }
strcpy(sromfilename,GetRomName()); strcpy(sromfilename,GetRomName());
ofn.lpstrFile=sromfilename; ofn.lpstrFile=sromfilename;
@ -342,6 +344,14 @@ void SaveStrippedRom(){ //this is based off of iNesSave()
ofn.hwndOwner = hCDLogger; ofn.hwndOwner = hCDLogger;
if(!GetSaveFileName(&ofn))return; 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"); fp = fopen(sromfilename,"wb");
if(GameInfo->type==GIT_NSF) if(GameInfo->type==GIT_NSF)

View File

@ -25,3 +25,33 @@ void WindowBoundsCheckNoResize(int &windowPosX, int &windowPosY, long windowRigh
windowPosY = -18; windowPosY = -18;
} }
} }
// Check if a filename/path has an extension. Extensions can be up to 4 characters.
// Extension strings must begin with a . or they won't work right.
void AddExtensionIfMissing(char * name,unsigned int maxsize,const char * extension) {
//if user did not add an extension, add it for them
std::string tempName = name;
//Non-null terminated lengths of both strings, +1 for null termination
if ((strlen(name) + strlen(extension) + 1) <= maxsize) {
unsigned int x = tempName.find_last_of(".");
//If the extension(".????") is longer then 5 characters, it's probably part of the filename. If x == -1, wasn't found
if ((x < (tempName.size() - 6)) || (x == -1)) {
//If everything above passed, append the extension, and update the string
tempName.append(extension);
strcpy(name, tempName.c_str());
}
}
}
// Overloaded operator of above, which deals with native std::string variants.
void AddExtensionIfMissing(std::string &name,const char * extension) {
//if user did not add an extension, add it for them
unsigned int x = name.find_last_of(".");
//If the extension(".????") is longer then 5 characters, it's probably part of the filename. If x == -1, wasn't found
if ((x < (name.size() - 6)) || (x == -1))
name.append(extension);
}

View File

@ -52,4 +52,6 @@ extern int eoptions;
bool directoryExists(const char* dirname); bool directoryExists(const char* dirname);
void WindowBoundsCheckResize(int &windowPosX, int &windowPosY, int windowSizeX, long windowRight); void WindowBoundsCheckResize(int &windowPosX, int &windowPosY, int windowSizeX, long windowRight);
void WindowBoundsCheckNoResize(int &windowPosX, int &windowPosY, long windowRight); void WindowBoundsCheckNoResize(int &windowPosX, int &windowPosY, long windowRight);
void AddExtensionIfMissing(char * name,unsigned int maxsize,const char * extension);
void AddExtensionIfMissing(std::string &name,const char * extension);
#endif #endif

View File

@ -1556,7 +1556,7 @@ void FCEUI_UseInputPreset(int preset)
static void PresetExport(int preset) static void PresetExport(int preset)
{ {
const char filter[]="Input Preset File(*.pre)\0*.pre\0"; const char filter[]="Input Preset File(*.pre)\0*.pre\0All Files (*.*)\0*.*\0\0";
char nameo[2048]; char nameo[2048];
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -1572,7 +1572,6 @@ static void PresetExport(int preset)
ofn.lpstrInitialDir=initdir.c_str(); ofn.lpstrInitialDir=initdir.c_str();
if(GetSaveFileName(&ofn)) if(GetSaveFileName(&ofn))
{ {
int i;
//Save the directory //Save the directory
if(ofn.nFileOffset < 1024) if(ofn.nFileOffset < 1024)
{ {
@ -1582,24 +1581,8 @@ static void PresetExport(int preset)
InputPresetDir[ofn.nFileOffset]=0; InputPresetDir[ofn.nFileOffset]=0;
} }
//quick get length of nameo if (ofn.nFilterIndex == 1)
for(i=0;i<2048;i++) AddExtensionIfMissing(nameo, sizeof(nameo), ".pre");
{
if(nameo[i] == 0)
{
break;
}
}
//add .pre if nameo doesn't have it
if((i < 4 || nameo[i-4] != '.') && i < 2040)
{
nameo[i] = '.';
nameo[i+1] = 'p';
nameo[i+2] = 'r';
nameo[i+3] = 'e';
nameo[i+4] = 0;
}
FILE *fp=FCEUD_UTF8fopen(nameo,"w"); FILE *fp=FCEUD_UTF8fopen(nameo,"w");
switch(preset) switch(preset)
@ -1614,7 +1597,7 @@ static void PresetExport(int preset)
static void PresetImport(int preset) static void PresetImport(int preset)
{ {
const char filter[]="Input Preset File(*.pre)\0*.pre\0"; const char filter[]="Input Preset File(*.pre)\0*.pre\0\0";
char nameo[2048]; char nameo[2048];
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));

View File

@ -281,13 +281,10 @@ static int GetRomFileSize(){ //todo: fix or remove this?
return 0; return 0;
} }
void SaveRomAs() void SaveRomAs()
{ {
const char filter[]="NES ROM file (*.nes)\0*.nes\0"; const char filter[]="NES ROM file (*.nes)\0*.nes\0All Files (*.*)\0*.*\0\0";
char nameo[2048]; char nameo[2048];
std::string tempName;
int x;
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -295,7 +292,7 @@ void SaveRomAs()
ofn.hInstance=fceu_hInstance; ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Save Nes ROM as..."; ofn.lpstrTitle="Save Nes ROM as...";
ofn.lpstrFilter=filter; ofn.lpstrFilter=filter;
ofn.lpstrDefExt="nes"; //ofn.lpstrDefExt="nes";
strcpy(nameo,GetRomName()); strcpy(nameo,GetRomName());
ofn.lpstrFile=nameo; ofn.lpstrFile=nameo;
ofn.nMaxFile=256; ofn.nMaxFile=256;
@ -303,12 +300,9 @@ void SaveRomAs()
ofn.hwndOwner = hMemView; ofn.hwndOwner = hMemView;
if (GetSaveFileName(&ofn)) if (GetSaveFileName(&ofn))
{ {
//if user did not add .nes, add it for them if (ofn.nFilterIndex == 1)
tempName = nameo; AddExtensionIfMissing(nameo, sizeof(nameo), ".nes");
x = tempName.find_last_of(".nes");
if (x < 0)
tempName.append(".nes");
strcpy(nameo, tempName.c_str());
iNesSaveAs(nameo); iNesSaveAs(nameo);
} }
} }
@ -371,7 +365,7 @@ int LoadTable(const char* nameo)
//should return -1, otherwise returns the line number it had the error on //should return -1, otherwise returns the line number it had the error on
int LoadTableFile(){ int LoadTableFile(){
const char filter[]="Table Files (*.TBL)\0*.tbl\0All files (*.*)\0*.*\0"; const char filter[]="Table Files (*.TBL)\0*.tbl\0All files (*.*)\0*.*\0\0";
char nameo[2048]; //todo: possibly no need for this? can lpstrfilter point to loadedcdfile instead? char nameo[2048]; //todo: possibly no need for this? can lpstrfilter point to loadedcdfile instead?
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -645,16 +639,19 @@ void dumpToFile(const char* buffer, unsigned int size)
ofn.lStructSize=sizeof(ofn); ofn.lStructSize=sizeof(ofn);
ofn.hInstance=fceu_hInstance; ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Save to file ..."; ofn.lpstrTitle="Save to file ...";
ofn.lpstrFilter="Binary File (*.BIN)\0*.bin\0"; ofn.lpstrFilter="Binary File (*.BIN)\0*.bin\0All Files (*.*)\0*.*\0\0";
ofn.lpstrDefExt="bin"; //ofn.lpstrDefExt="bin";
strcpy(name,GetRomName()); strcpy(name,GetRomName());
ofn.lpstrFile=name; ofn.lpstrFile=name;
ofn.nMaxFile=256; ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY; ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY;
if (GetOpenFileName(&ofn)) if (GetSaveFileName(&ofn))
{ {
FILE* memfile = fopen(ofn.lpstrFile, "wb"); if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(name, sizeof(name), ".bin");
FILE* memfile = fopen(name, "wb");
if (!memfile || fwrite(buffer, 1, size, memfile) != size) if (!memfile || fwrite(buffer, 1, size, memfile) != size)
{ {

View File

@ -398,7 +398,7 @@ bool iftextchanged()
//Save as... //Save as...
static void SaveMemWatch() static void SaveMemWatch()
{ {
const char filter[]="Memory address list(*.txt)\0*.txt\0"; const char filter[]="Memory address list(*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0";
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -406,7 +406,7 @@ static void SaveMemWatch()
ofn.hInstance=fceu_hInstance; ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Save Memory Watch As..."; ofn.lpstrTitle="Save Memory Watch As...";
ofn.lpstrFilter=filter; ofn.lpstrFilter=filter;
ofn.lpstrDefExt="txt"; //ofn.lpstrDefExt="txt";
char nameo[2048]; char nameo[2048];
if (!memwLastFilename[0]) if (!memwLastFilename[0])
strcpy(nameo,GetRomName()); strcpy(nameo,GetRomName());
@ -430,25 +430,10 @@ static void SaveMemWatch()
MemWatchDir[ofn.nFileOffset]=0; MemWatchDir[ofn.nFileOffset]=0;
} }
//quick get length of memwLastFilename if (ofn.nFilterIndex == 1)
strcpy(memwLastFilename,nameo); AddExtensionIfMissing(nameo, sizeof(nameo), ".txt");
for(i=0;i<2048;i++)
{
if(memwLastFilename[i] == 0)
{
break;
}
}
//add .txt if memwLastFilename doesn't have it strcpy(memwLastFilename,nameo);
if((i < 4 || memwLastFilename[i-4] != '.') && i < 2040)
{
memwLastFilename[i] = '.';
memwLastFilename[i+1] = 't';
memwLastFilename[i+2] = 'x';
memwLastFilename[i+3] = 't';
memwLastFilename[i+4] = 0;
}
SaveStrings(); SaveStrings();
FILE *fp=FCEUD_UTF8fopen(memwLastFilename,"w"); FILE *fp=FCEUD_UTF8fopen(memwLastFilename,"w");
@ -512,7 +497,7 @@ static void QuickSaveMemWatch() //Save rather than Save as
//Open Memwatch File //Open Memwatch File
static void LoadMemWatch() static void LoadMemWatch()
{ {
const char filter[]="Memory address list(*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; const char filter[]="Memory address list(*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0";
char watchfcontents[2048]; char watchfcontents[2048];
//Now clear last file used variable (memwLastFilename) //Now clear last file used variable (memwLastFilename)

View File

@ -31,7 +31,7 @@ bool SetPalette(const char* nameo)
**/ **/
int LoadPaletteFile() int LoadPaletteFile()
{ {
const char filter[]="All usable files(*.pal)\0*.pal\0All files (*.*)\0*.*\0"; const char filter[]="All usable files(*.pal)\0*.pal\0All files (*.*)\0*.*\0\0";
bool success = false; bool success = false;
char nameo[2048]; char nameo[2048];

View File

@ -480,6 +480,8 @@ int Change_File_S(char *Dest, char *Dir, char *Titre, char *Filter, char *Ext, H
{ {
OPENFILENAME ofn; OPENFILENAME ofn;
char *TempExt = 0;
SetCurrentDirectory(applicationPath); SetCurrentDirectory(applicationPath);
if (!strcmp(Dest, "")) if (!strcmp(Dest, ""))
@ -499,10 +501,19 @@ int Change_File_S(char *Dest, char *Dir, char *Titre, char *Filter, char *Ext, H
ofn.nFilterIndex = 1; ofn.nFilterIndex = 1;
ofn.lpstrInitialDir = Dir; ofn.lpstrInitialDir = Dir;
ofn.lpstrTitle = Titre; ofn.lpstrTitle = Titre;
ofn.lpstrDefExt = Ext; //ofn.lpstrDefExt = Ext;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
if (GetSaveFileName(&ofn)) return 1; if (GetSaveFileName(&ofn)) {
TempExt=(char*)malloc(sizeof(Ext)+2);
strcpy(TempExt, ".");
strcat(TempExt, Ext);
if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(Dest, 1024, TempExt); //1024 checked manually
return 1;
}
return 0; return 0;
} }
@ -514,7 +525,7 @@ bool Save_Watches()
char* dot = strrchr(Str_Tmp, '.'); char* dot = strrchr(Str_Tmp, '.');
if(dot) *dot = 0; if(dot) *dot = 0;
strcat(Str_Tmp,".wch"); strcat(Str_Tmp,".wch");
if(Change_File_S(Str_Tmp, applicationPath, "Save Watches", "Watchlist\0*.wch\0All Files\0*.*\0\0", "wch", RamWatchHWnd)) 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"); FILE *WatchFile = fopen(Str_Tmp,"r+b");
if (!WatchFile) WatchFile = fopen(Str_Tmp,"w+b"); if (!WatchFile) WatchFile = fopen(Str_Tmp,"w+b");
@ -618,7 +629,7 @@ bool Load_Watches(bool clear)
char* dot = strrchr(Str_Tmp, '.'); char* dot = strrchr(Str_Tmp, '.');
if(dot) *dot = 0; if(dot) *dot = 0;
strcat(Str_Tmp,".wch"); strcat(Str_Tmp,".wch");
if(Change_File_L(Str_Tmp, applicationPath, "Load Watches", "Watchlist\0*.wch\0All Files\0*.*\0\0", "wch", RamWatchHWnd)) if(Change_File_L(Str_Tmp, applicationPath, "Load Watches", "Watchlist (*.wch)\0*.wch\0All Files (*.*)\0*.*\0\0", "wch", RamWatchHWnd))
{ {
return Load_Watches(clear, Str_Tmp); return Load_Watches(clear, Str_Tmp);
} }

View File

@ -907,12 +907,16 @@ static BOOL CALLBACK RecordDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP
ofn.hwndOwner = hwndDlg; ofn.hwndOwner = hwndDlg;
ofn.lpstrFilter = "FCEUX Movie File (*.fm2)\0*.fm2\0All files(*.*)\0*.*\0\0"; ofn.lpstrFilter = "FCEUX Movie File (*.fm2)\0*.fm2\0All files(*.*)\0*.*\0\0";
ofn.lpstrFile = szChoice; ofn.lpstrFile = szChoice;
ofn.lpstrDefExt = "fm2"; //ofn.lpstrDefExt = "fm2";
ofn.nMaxFile = MAX_PATH; ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if(GetSaveFileName(&ofn)) if(GetSaveFileName(&ofn)) {
if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(szChoice, sizeof(szChoice), ".fm2");
UpdateRecordDialogPath(hwndDlg,szChoice); UpdateRecordDialogPath(hwndDlg,szChoice);
} }
}
return TRUE; return TRUE;
} }
} }

View File

@ -15,7 +15,7 @@ extern string GetBackupFileName(); //Declared in src/state.cpp
**/ **/
void FCEUD_SaveStateAs() void FCEUD_SaveStateAs()
{ {
const char filter[] = FCEU_NAME" Save State (*.fc?)\0*.fc?\0"; const char filter[] = FCEU_NAME" Save State (*.fc?)\0*.fc?\0All Files (*.*)\0*.*\0\0";
char nameo[2048]; char nameo[2048];
OPENFILENAME ofn; OPENFILENAME ofn;
@ -24,7 +24,7 @@ void FCEUD_SaveStateAs()
ofn.hInstance = fceu_hInstance; ofn.hInstance = fceu_hInstance;
ofn.lpstrTitle = "Save State As..."; ofn.lpstrTitle = "Save State As...";
ofn.lpstrFilter = filter; ofn.lpstrFilter = filter;
ofn.lpstrDefExt = "fcs"; //ofn.lpstrDefExt = "fcs";
strcpy(nameo,FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0).c_str()); strcpy(nameo,FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0).c_str());
ofn.lpstrFile = nameo; ofn.lpstrFile = nameo;
std::string initdir = FCEU_GetPath(FCEUMKF_STATE); std::string initdir = FCEU_GetPath(FCEUMKF_STATE);
@ -34,6 +34,9 @@ void FCEUD_SaveStateAs()
if(GetSaveFileName(&ofn)) if(GetSaveFileName(&ofn))
{ {
if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(nameo, sizeof(nameo), ".fcs");
FCEUI_SaveState(nameo); FCEUI_SaveState(nameo);
} }
} }
@ -43,7 +46,7 @@ void FCEUD_SaveStateAs()
**/ **/
void FCEUD_LoadStateFrom() void FCEUD_LoadStateFrom()
{ {
const char filter[]= FCEU_NAME" Save State (*.fc?)\0*.fc?\0All Files (*.*)\0*.*\0"; const char filter[]= FCEU_NAME" Save State (*.fc?)\0*.fc?\0All Files (*.*)\0*.*\0\0";
char nameo[2048]; char nameo[2048];
OPENFILENAME ofn; OPENFILENAME ofn;

View File

@ -830,7 +830,7 @@ static void OpenProject()
//close current project //close current project
//open dialog for new project file //open dialog for new project file
const char TPfilter[]="TASEdit Project (*.tas)\0*.tas\0"; //Filetype filter const char TPfilter[]="TASEdit Project (*.tas)\0*.tas\0\0"; //Filetype filter
OPENFILENAME ofn; //New instance of OPENFILENAME OPENFILENAME ofn; //New instance of OPENFILENAME
memset(&ofn,0,sizeof(ofn)); //Set aside some memory memset(&ofn,0,sizeof(ofn)); //Set aside some memory
@ -880,7 +880,7 @@ static void SaveProjectAs()
//flag project as not changed //flag project as not changed
//Creation of a save window //Creation of a save window
const char TPfilter[]="TASEdit Project (*.tas)\0*.tas\0"; //Filetype filter const char TPfilter[]="TASEdit Project (*.tas)\0*.tas\0All Files (*.*)\0*.*\0\0"; //Filetype filter
OPENFILENAME ofn; //New instance of OPENFILENAME OPENFILENAME ofn; //New instance of OPENFILENAME
memset(&ofn,0,sizeof(ofn)); //Set aside some memory memset(&ofn,0,sizeof(ofn)); //Set aside some memory
@ -900,21 +900,17 @@ static void SaveProjectAs()
if(GetSaveFileName(&ofn)) //If it is a valid filename 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 std::string tempstr = nameo; //Make a temporary string for filename
char drv[512], dir[512], name[512], ext[512]; //For getting the filename! char drv[512], dir[512], name[512], ext[512]; //For getting the filename!
if(tempstr.rfind(".tas") == std::string::npos) //If they haven't put ".tas" after it
{
tempstr.append(".tas"); //Stick it on ourselves
splitpath(tempstr.c_str(), drv, dir, name, ext); //Split the path...
std::string filename = name; //Get the filename
filename.append(ext); //Shove the extension back onto it...
project.SetProjectFile(filename); //And update the project's filename.
} else { //If they've been nice and done it for us...
splitpath(tempstr.c_str(), drv, dir, name, ext); //Split it up... splitpath(tempstr.c_str(), drv, dir, name, ext); //Split it up...
std::string filename = name; //Grab the name... std::string filename = name; //Grab the name...
filename.append(ext); //Stick extension back on... filename.append(ext); //Stick extension back on...
project.SetProjectFile(filename); //And update the project's filename. project.SetProjectFile(filename); //And update the project's filename.
}
project.SetProjectName(GetRomName()); //Set the project's name to the ROM name project.SetProjectName(GetRomName()); //Set the project's name to the ROM name
std::string thisfm2name = project.GetProjectName(); std::string thisfm2name = project.GetProjectName();
thisfm2name.append(".fm2"); //Setup the fm2 name thisfm2name.append(".fm2"); //Setup the fm2 name
@ -942,7 +938,7 @@ static void Import()
//Takes current inputlog and saves it as a .fm2 file //Takes current inputlog and saves it as a .fm2 file
static void Export() static void Export()
{ {
const char filter[]="FCEUX Movie File(*.fm2)\0*.fm2\0"; const char filter[]="FCEUX Movie File(*.fm2)\0*.fm2\0All Files (*.*)\0*.*\0\0";
char fname[2048] = {0}; char fname[2048] = {0};
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -956,7 +952,10 @@ static void Export()
ofn.lpstrInitialDir=initdir.c_str(); ofn.lpstrInitialDir=initdir.c_str();
if(GetSaveFileName(&ofn)) if(GetSaveFileName(&ofn))
{ {
fstream* osRecordingMovie = FCEUD_UTF8_fstream(ofn.lpstrFile, "wb"); if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(fname, sizeof(fname), ".fm2");
fstream* osRecordingMovie = FCEUD_UTF8_fstream(fname, "wb");
currMovieData.dump(osRecordingMovie,false); currMovieData.dump(osRecordingMovie,false);
delete osRecordingMovie; delete osRecordingMovie;
osRecordingMovie = 0; osRecordingMovie = 0;

View File

@ -643,7 +643,7 @@ int TextHookerLoadTable(const char* nameo)
int TextHookerLoadTableFile(){ int TextHookerLoadTableFile(){
//initialize the "File open" dialogue box //initialize the "File open" dialogue box
const char filter[]="Table Files (*.THT)\0*.tht\0All Files (*.*)\0*.*\0"; const char filter[]="Table Files (*.THT)\0*.tht\0All Files (*.*)\0*.*\0\0";
char nameo[2048]; //todo: possibly no need for this? can lpstrfilter point to loadedcdfile instead? char nameo[2048]; //todo: possibly no need for this? can lpstrfilter point to loadedcdfile instead?
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -682,7 +682,7 @@ int TextHookerSaveTableFile(){
int i, line; //counters int i, line; //counters
//init the "Save File" dialogue //init the "Save File" dialogue
const char filter[]="Table Files (*.THT)\0*.tht\0"; const char filter[]="Table Files (*.THT)\0*.tht\0All Files (*.*)\0*.*\0\0";
char nameo[2048]; //todo: possibly no need for this? can lpstrfilter point to loadedcdfile instead? char nameo[2048]; //todo: possibly no need for this? can lpstrfilter point to loadedcdfile instead?
OPENFILENAME ofn; OPENFILENAME ofn;
//StopSound(); //mbg merge 6/30/08 //StopSound(); //mbg merge 6/30/08
@ -693,7 +693,7 @@ int TextHookerSaveTableFile(){
ofn.lpstrFilter=filter; ofn.lpstrFilter=filter;
strcpy(nameo,GetRomName()); strcpy(nameo,GetRomName());
ofn.lpstrFile=nameo; ofn.lpstrFile=nameo;
ofn.lpstrDefExt="tht"; //ofn.lpstrDefExt="tht";
ofn.nMaxFile=256; ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_EXTENSIONDIFFERENT; ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_EXTENSIONDIFFERENT;
ofn.hwndOwner = hCDLogger; ofn.hwndOwner = hCDLogger;
@ -701,6 +701,9 @@ int TextHookerSaveTableFile(){
//get the file name or quit //get the file name or quit
if(!GetSaveFileName(&ofn))return 0; if(!GetSaveFileName(&ofn))return 0;
if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(nameo, sizeof(nameo), ".tht");
//open the file //open the file
FP = fopen(nameo,"wb"); FP = fopen(nameo,"wb");
line = 0; //init the line counter line = 0; //init the line counter

View File

@ -583,7 +583,7 @@ int PromptForCDLogger(void){
} }
void ShowLogDirDialog(void){ void ShowLogDirDialog(void){
const char filter[]="6502 Trace Log File(*.log,*.txt)\0*.log;*.txt\0"; const char filter[]="6502 Trace Log File(*.log)\0*.log;*.txt\0" "6502 Trace Log File(*.txt)\0*.log;*.txt\0All Files (*.*)\0*.*\0\0"; //'" "' used to prevent octal conversion on the numbers
char nameo[2048]; char nameo[2048];
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -591,14 +591,18 @@ void ShowLogDirDialog(void){
ofn.hInstance=fceu_hInstance; ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Log Trace As..."; ofn.lpstrTitle="Log Trace As...";
ofn.lpstrFilter=filter; ofn.lpstrFilter=filter;
ofn.lpstrDefExt="log"; //ofn.lpstrDefExt="log";
strcpy(nameo,GetRomName()); strcpy(nameo,GetRomName());
ofn.lpstrFile=nameo; ofn.lpstrFile=nameo;
ofn.nMaxFile=256; ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
ofn.hwndOwner = hTracer; ofn.hwndOwner = hTracer;
GetSaveFileName(&ofn); if(GetSaveFileName(&ofn)){
if(nameo[0]){ if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(nameo, sizeof(nameo), ".log");
else if (ofn.nFilterIndex == 2)
AddExtensionIfMissing(nameo, sizeof(nameo), ".txt");
if(logfilename)free(logfilename); if(logfilename)free(logfilename);
logfilename = (char*)malloc(strlen(nameo)+1); //mbg merge 7/19/06 added cast logfilename = (char*)malloc(strlen(nameo)+1); //mbg merge 7/19/06 added cast
strcpy(logfilename,nameo); strcpy(logfilename,nameo);

View File

@ -33,7 +33,7 @@ int CloseWave()
/// @return Flag that indicates failure (0) or success (1). /// @return Flag that indicates failure (0) or success (1).
bool CreateSoundSave() bool CreateSoundSave()
{ {
const char filter[]="MS WAVE(*.wav)\0*.wav\0"; const char filter[]="MS WAVE(*.wav)\0*.wav\0All Files (*.*)\0*.*\0\0";
char nameo[2048]; char nameo[2048];
OPENFILENAME ofn; OPENFILENAME ofn;
@ -44,7 +44,7 @@ bool CreateSoundSave()
ofn.hInstance=fceu_hInstance; ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Log Sound As..."; ofn.lpstrTitle="Log Sound As...";
ofn.lpstrFilter=filter; ofn.lpstrFilter=filter;
ofn.lpstrDefExt="wav"; //ofn.lpstrDefExt="wav";
strcpy(nameo,GetRomName()); strcpy(nameo,GetRomName());
ofn.lpstrFile=nameo; ofn.lpstrFile=nameo;
ofn.nMaxFile=256; ofn.nMaxFile=256;
@ -52,6 +52,9 @@ bool CreateSoundSave()
if(GetSaveFileName(&ofn)) if(GetSaveFileName(&ofn))
{ {
if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(nameo, sizeof(nameo), ".wav");
return FCEUI_BeginWaveRecord(nameo); return FCEUI_BeginWaveRecord(nameo);
} }

View File

@ -1077,7 +1077,7 @@ bool ALoad(char *nameo, char* innerFilename)
/// @param initialdir Directory that's pre-selected in the Open File dialog. /// @param initialdir Directory that's pre-selected in the Open File dialog.
void LoadNewGamey(HWND hParent, const char *initialdir) void LoadNewGamey(HWND hParent, const char *initialdir)
{ {
const char filter[] = "All usable files(*.nes,*.nsf,*.fds,*.unf,*.zip,*.rar,*.7z,*.gz)\0*.nes;*.nsf;*.fds;*.unf;*.zip;*.rar;*.7z;*.gz\0All non-compressed usable files(*.nes,*.nsf,*.fds,*.unf)\0*.nes;*.nsf;*.fds;*.unf\0All files (*.*)\0*.*\0"; const char filter[] = "All usable files(*.nes,*.nsf,*.fds,*.unf,*.zip,*.rar,*.7z,*.gz)\0*.nes;*.nsf;*.fds;*.unf;*.zip;*.rar;*.7z;*.gz\0All non-compressed usable files(*.nes,*.nsf,*.fds,*.unf)\0*.nes;*.nsf;*.fds;*.unf\0All files (*.*)\0*.*\0\0";
char nameo[2048]; char nameo[2048];
// Create the Open File dialog // Create the Open File dialog
@ -2413,9 +2413,9 @@ void FCEUD_AviRecordTo(void)
memset(&ofn, 0, sizeof(ofn)); memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hAppWnd; ofn.hwndOwner = hAppWnd;
ofn.lpstrFilter = "AVI Files (*.avi)\0*.avi\0\0"; ofn.lpstrFilter = "AVI Files (*.avi)\0*.avi\0All Files (*.*)\0*.*\0\0";
ofn.lpstrFile = szChoice; ofn.lpstrFile = szChoice;
ofn.lpstrDefExt = "avi"; //ofn.lpstrDefExt = "avi";
ofn.lpstrTitle = "Save AVI as"; ofn.lpstrTitle = "Save AVI as";
ofn.nMaxFile = MAX_PATH; ofn.nMaxFile = MAX_PATH;
@ -2423,6 +2423,9 @@ void FCEUD_AviRecordTo(void)
if(GetSaveFileName(&ofn)) if(GetSaveFileName(&ofn))
{ {
if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(szChoice, sizeof(szChoice), ".avi");
FCEUI_AviBegin(szChoice); FCEUI_AviBegin(szChoice);
} }
} }
@ -2685,10 +2688,9 @@ void UpdateMenuHotkeys()
//It gets a filename from the user then calls CreateMovie() //It gets a filename from the user then calls CreateMovie()
void SaveMovieAs() void SaveMovieAs()
{ {
const char filter[]="NES Movie file (*.fm2)\0*.fm2\0"; const char filter[]="NES Movie file (*.fm2)\0*.fm2\0All Files (*.*)\0*.*\0\0";
char nameo[2048]; char nameo[2048];
std::string tempName; std::string tempName;
int x;
OPENFILENAME ofn; OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn));
@ -2704,9 +2706,10 @@ void SaveMovieAs()
if (GetSaveFileName(&ofn)) if (GetSaveFileName(&ofn))
{ {
tempName = nameo; tempName = nameo;
x = tempName.find_last_of("."); //Check to see if the user provided a file extension
if (x < 0) if (ofn.nFilterIndex == 1)
tempName.append(".fm2"); //If not, make it .fm2 AddExtensionIfMissing(tempName, ".fm2");
FCEUI_CreateMovieFile(tempName); FCEUI_CreateMovieFile(tempName);
} }
} }