(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);
char outFilename[MAX_PATH];
char outFilename[MAX_PATH] = "";
OPENFILENAME ofn;
ZeroMemory(&ofn,sizeof(ofn));
@ -249,30 +249,30 @@ void HK_PrintScreen(int param, bool justPressed)
ofn.lpstrDefExt = "png";
ofn.Flags = OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST;
std::string filename = path.getpath(path.SCREENSHOTS);
char file[MAX_PATH];
ZeroMemory(file, sizeof(file));
path.formatname(file);
filename += file;
std::string dir = path.getpath(path.SCREENSHOTS);
ofn.lpstrInitialDir = dir.c_str();
path.formatname(outFilename);
if(path.imageformat() == PathInfo::PNG)
{
filename += ".png";
strcat(outFilename, ".png");
ofn.lpstrDefExt = "png";
ofn.nFilterIndex = 1;
}
else if(path.imageformat() == PathInfo::BMP)
{
filename += ".bmp";
strcat(outFilename, ".bmp");
ofn.lpstrDefExt = "bmp";
ofn.nFilterIndex = 2;
}
strcpy(outFilename,filename.c_str());
if(GetSaveFileName(&ofn))
{
DoScreenshot(outFilename);
dir = Path::GetFileDirectoryPath(outFilename);
path.setpath(path.SCREENSHOTS, dir);
WritePrivateProfileString(SECTION, SCREENSHOTKEY, dir.c_str(), IniName);
}
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);
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);
if (res)
{
@ -197,8 +201,8 @@ bool importSave(HWND hwnd, HINSTANCE hAppInst)
printf("Save was not successfully imported");
return res;
}
return (res == (MAX_SAVE_TYPES + 1));
else // user canceled
return (res == (MAX_SAVE_TYPES + 1));
}
bool exportSave(HWND hwnd, HINSTANCE hAppInst)
@ -219,6 +223,10 @@ bool exportSave(HWND hwnd, HINSTANCE hAppInst)
if (!GetSaveFileName(&ofn))
return true;
dir = Path::GetFileDirectoryPath(SavFName);
path.setpath(path.BATTERY, dir);
WritePrivateProfileString(SECTION, BATTERYKEY, dir.c_str(), IniName);
if (ofn.nFilterIndex == 2) strcat(SavFName, "*");
return !MMU_new.backupDevice.exportData(SavFName);

View File

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

View File

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

View File

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

View File

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

View File

@ -672,7 +672,7 @@ void scan_savestates()
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 ;
sprintf(filename+strlen(filename), ".ds%d", i);
@ -692,7 +692,7 @@ void savestate_slot(int num)
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 ;
sprintf(filename+strlen(filename), ".ds%d", num);
@ -726,7 +726,7 @@ void loadstate_slot(int num)
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 ;
sprintf(filename+strlen(filename), ".ds%d", num);