(Windows) Save and use all config paths.

Add StateSlots path to avoid losing saved slot states when user manually selects a file to load elsewhere.
This commit is contained in:
SuuperW 2018-09-05 00:27:49 -05:00
parent e2d83f99fe
commit aaad5e63c5
7 changed files with 53 additions and 16 deletions

View File

@ -236,7 +236,7 @@ void HK_PrintScreen(int param, bool justPressed)
bool unpause = NDS_Pause(false); bool unpause = NDS_Pause(false);
char outFilename[MAX_PATH]; char outFilename[MAX_PATH] = "";
OPENFILENAME ofn; OPENFILENAME ofn;
ZeroMemory(&ofn,sizeof(ofn)); ZeroMemory(&ofn,sizeof(ofn));
@ -249,30 +249,30 @@ void HK_PrintScreen(int param, bool justPressed)
ofn.lpstrDefExt = "png"; ofn.lpstrDefExt = "png";
ofn.Flags = OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST; ofn.Flags = OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST;
std::string filename = path.getpath(path.SCREENSHOTS); std::string dir = path.getpath(path.SCREENSHOTS);
ofn.lpstrInitialDir = dir.c_str();
char file[MAX_PATH];
ZeroMemory(file, sizeof(file));
path.formatname(file);
filename += file;
path.formatname(outFilename);
if(path.imageformat() == PathInfo::PNG) if(path.imageformat() == PathInfo::PNG)
{ {
filename += ".png"; strcat(outFilename, ".png");
ofn.lpstrDefExt = "png"; ofn.lpstrDefExt = "png";
ofn.nFilterIndex = 1; ofn.nFilterIndex = 1;
} }
else if(path.imageformat() == PathInfo::BMP) else if(path.imageformat() == PathInfo::BMP)
{ {
filename += ".bmp"; strcat(outFilename, ".bmp");
ofn.lpstrDefExt = "bmp"; ofn.lpstrDefExt = "bmp";
ofn.nFilterIndex = 2; ofn.nFilterIndex = 2;
} }
strcpy(outFilename,filename.c_str());
if(GetSaveFileName(&ofn)) if(GetSaveFileName(&ofn))
{ {
DoScreenshot(outFilename); DoScreenshot(outFilename);
dir = Path::GetFileDirectoryPath(outFilename);
path.setpath(path.SCREENSHOTS, dir);
WritePrivateProfileString(SECTION, SCREENSHOTKEY, dir.c_str(), IniName);
} }
if(unpause) NDS_UnPause(false); if(unpause) NDS_UnPause(false);

View File

@ -187,6 +187,10 @@ bool importSave(HWND hwnd, HINSTANCE hAppInst)
u32 res = DialogBoxW(hAppInst, MAKEINTRESOURCEW(IDD_IMPORT_SAVE_SIZE), hwnd, (DLGPROC)ImportSizeSelect_Proc); u32 res = DialogBoxW(hAppInst, MAKEINTRESOURCEW(IDD_IMPORT_SAVE_SIZE), hwnd, (DLGPROC)ImportSizeSelect_Proc);
if (res < MAX_SAVE_TYPES) if (res < MAX_SAVE_TYPES)
{ {
std::string dir = Path::GetFileDirectoryPath(SavFName);
path.setpath(path.BATTERY, dir);
WritePrivateProfileString(SECTION, BATTERYKEY, dir.c_str(), IniName);
res = MMU_new.backupDevice.importData(SavFName, save_types[res+1].size); res = MMU_new.backupDevice.importData(SavFName, save_types[res+1].size);
if (res) if (res)
{ {
@ -197,8 +201,8 @@ bool importSave(HWND hwnd, HINSTANCE hAppInst)
printf("Save was not successfully imported"); printf("Save was not successfully imported");
return res; return res;
} }
else // user canceled
return (res == (MAX_SAVE_TYPES + 1)); return (res == (MAX_SAVE_TYPES + 1));
} }
bool exportSave(HWND hwnd, HINSTANCE hAppInst) bool exportSave(HWND hwnd, HINSTANCE hAppInst)
@ -219,6 +223,10 @@ bool exportSave(HWND hwnd, HINSTANCE hAppInst)
if (!GetSaveFileName(&ofn)) if (!GetSaveFileName(&ofn))
return true; return true;
dir = Path::GetFileDirectoryPath(SavFName);
path.setpath(path.BATTERY, dir);
WritePrivateProfileString(SECTION, BATTERYKEY, dir.c_str(), IniName);
if (ofn.nFilterIndex == 2) strcat(SavFName, "*"); if (ofn.nFilterIndex == 2) strcat(SavFName, "*");
return !MMU_new.backupDevice.exportData(SavFName); return !MMU_new.backupDevice.exportData(SavFName);

View File

@ -2896,6 +2896,10 @@ void AviRecordTo()
LOG("AVI recording started."); LOG("AVI recording started.");
driver->AddLine("AVI recording started."); driver->AddLine("AVI recording started.");
} }
std::string dir = Path::GetFileDirectoryPath(folder);
path.setpath(path.AVI_FILES, dir);
WritePrivateProfileString(SECTION, AVIKEY, dir.c_str(), IniName);
} }
NDS_UnPause(); NDS_UnPause();
@ -4661,6 +4665,10 @@ DOKEYDOWN:
return 0; return 0;
} }
dir = Path::GetFileDirectoryPath(SavName);
path.setpath(path.STATES, dir);
WritePrivateProfileString(SECTION, STATEKEY, dir.c_str(), IniName);
savestate_load(SavName); savestate_load(SavName);
UpdateToolWindows(); UpdateToolWindows();
NDS_UnPause(); NDS_UnPause();
@ -4687,6 +4695,11 @@ DOKEYDOWN:
savestate_save(SavName); savestate_save(SavName);
LoadSaveStateInfo(); LoadSaveStateInfo();
} }
dir = Path::GetFileDirectoryPath(SavName);
path.setpath(path.STATES, dir);
WritePrivateProfileString(SECTION, STATEKEY, dir.c_str(), IniName);
if(unpause) NDS_UnPause(); if(unpause) NDS_UnPause();
return 0; return 0;
} }
@ -5958,6 +5971,10 @@ LRESULT CALLBACK EmulationSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, L
if(GetOpenFileName(&ofn)) if(GetOpenFileName(&ofn))
{ {
std::string dir = Path::GetFileDirectoryPath(fileName);
path.setpath(path.FIRMWARE, dir);
WritePrivateProfileString(SECTION, FIRMWAREKEY, dir.c_str(), IniName);
HWND cur; HWND cur;
switch(LOWORD(wParam)) switch(LOWORD(wParam))
@ -6074,6 +6091,10 @@ LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
if(GetOpenFileName(&ofn)) if(GetOpenFileName(&ofn))
{ {
std::string dir = Path::GetFileDirectoryPath(fileName);
path.setpath(path.SOUNDS, dir);
WritePrivateProfileString(SECTION, SOUNDKEY, dir.c_str(), IniName);
HWND cur; HWND cur;
switch(LOWORD(wParam)) switch(LOWORD(wParam))

View File

@ -108,6 +108,7 @@ void WritePathSettings()
WritePrivateProfileString(SECTION, ROMKEY, path.pathToRoms, IniName); WritePrivateProfileString(SECTION, ROMKEY, path.pathToRoms, IniName);
WritePrivateProfileString(SECTION, BATTERYKEY, path.pathToBattery, IniName); WritePrivateProfileString(SECTION, BATTERYKEY, path.pathToBattery, IniName);
WritePrivateProfileString(SECTION, STATEKEY, path.pathToStates, IniName); WritePrivateProfileString(SECTION, STATEKEY, path.pathToStates, IniName);
WritePrivateProfileString(SECTION, STATESLOTKEY, path.pathToStateSlots, IniName);
WritePrivateProfileString(SECTION, SCREENSHOTKEY, path.pathToScreenshots, IniName); WritePrivateProfileString(SECTION, SCREENSHOTKEY, path.pathToScreenshots, IniName);
WritePrivateProfileString(SECTION, AVIKEY, path.pathToAviFiles, IniName); WritePrivateProfileString(SECTION, AVIKEY, path.pathToAviFiles, IniName);
WritePrivateProfileString(SECTION, CHEATKEY, path.pathToCheats, IniName); WritePrivateProfileString(SECTION, CHEATKEY, path.pathToCheats, IniName);

View File

@ -254,6 +254,7 @@ void PathInfo::ReadPathSettings()
ReadKey(pathToRoms, ROMKEY); ReadKey(pathToRoms, ROMKEY);
ReadKey(pathToBattery, BATTERYKEY); ReadKey(pathToBattery, BATTERYKEY);
ReadKey(pathToStates, STATEKEY); ReadKey(pathToStates, STATEKEY);
ReadKey(pathToStateSlots, STATESLOTKEY);
ReadKey(pathToScreenshots, SCREENSHOTKEY); ReadKey(pathToScreenshots, SCREENSHOTKEY);
ReadKey(pathToAviFiles, AVIKEY); ReadKey(pathToAviFiles, AVIKEY);
ReadKey(pathToCheats, CHEATKEY); ReadKey(pathToCheats, CHEATKEY);
@ -295,6 +296,9 @@ void PathInfo::SwitchPath(Action action, KnownPath path, char *buffer)
case STATES: case STATES:
pathToCopy = pathToStates; pathToCopy = pathToStates;
break; break;
case STATE_SLOTS:
pathToCopy = pathToStateSlots;
break;
case SCREENSHOTS: case SCREENSHOTS:
pathToCopy = pathToScreenshots; pathToCopy = pathToScreenshots;
break; break;

View File

@ -73,6 +73,7 @@ public:
#define ROMKEY "Roms" #define ROMKEY "Roms"
#define BATTERYKEY "Battery" #define BATTERYKEY "Battery"
#define STATEKEY "States" #define STATEKEY "States"
#define STATESLOTKEY "StateSlots"
#define SCREENSHOTKEY "Screenshots" #define SCREENSHOTKEY "Screenshots"
#define AVIKEY "AviFiles" #define AVIKEY "AviFiles"
#define CHEATKEY "Cheats" #define CHEATKEY "Cheats"
@ -93,7 +94,8 @@ public:
FIRSTKNOWNPATH = 0, FIRSTKNOWNPATH = 0,
ROMS = 0, ROMS = 0,
BATTERY, BATTERY,
STATES, STATES,
STATE_SLOTS,
SCREENSHOTS, SCREENSHOTS,
AVI_FILES, AVI_FILES,
CHEATS, CHEATS,
@ -107,6 +109,7 @@ public:
char pathToRoms[MAX_PATH]; char pathToRoms[MAX_PATH];
char pathToBattery[MAX_PATH]; char pathToBattery[MAX_PATH];
char pathToStates[MAX_PATH]; char pathToStates[MAX_PATH];
char pathToStateSlots[MAX_PATH];
char pathToScreenshots[MAX_PATH]; char pathToScreenshots[MAX_PATH];
char pathToAviFiles[MAX_PATH]; char pathToAviFiles[MAX_PATH];
char pathToCheats[MAX_PATH]; char pathToCheats[MAX_PATH];

View File

@ -672,7 +672,7 @@ void scan_savestates()
for(int i = 0; i < NB_STATES; i++ ) for(int i = 0; i < NB_STATES; i++ )
{ {
path.getpathnoext(path.STATES, filename); path.getpathnoext(path.STATE_SLOTS, filename);
if (strlen(filename) + strlen(".dst") + strlen("-2147483648") /* = biggest string for i */ >MAX_PATH) return ; if (strlen(filename) + strlen(".dst") + strlen("-2147483648") /* = biggest string for i */ >MAX_PATH) return ;
sprintf(filename+strlen(filename), ".ds%d", i); sprintf(filename+strlen(filename), ".ds%d", i);
@ -692,7 +692,7 @@ void savestate_slot(int num)
lastSaveState = num; //Set last savestate used lastSaveState = num; //Set last savestate used
path.getpathnoext(path.STATES, filename); path.getpathnoext(path.STATE_SLOTS, filename);
if (strlen(filename) + strlen(".dsx") + strlen("-2147483648") /* = biggest string for num */ >MAX_PATH) return ; if (strlen(filename) + strlen(".dsx") + strlen("-2147483648") /* = biggest string for num */ >MAX_PATH) return ;
sprintf(filename+strlen(filename), ".ds%d", num); sprintf(filename+strlen(filename), ".ds%d", num);
@ -726,7 +726,7 @@ void loadstate_slot(int num)
lastSaveState = num; //Set last savestate used lastSaveState = num; //Set last savestate used
path.getpathnoext(path.STATES, filename); path.getpathnoext(path.STATE_SLOTS, filename);
if (strlen(filename) + strlen(".dsx") + strlen("-2147483648") /* = biggest string for num */ >MAX_PATH) return ; if (strlen(filename) + strlen(".dsx") + strlen("-2147483648") /* = biggest string for num */ >MAX_PATH) return ;
sprintf(filename+strlen(filename), ".ds%d", num); sprintf(filename+strlen(filename), ".ds%d", num);