(Windows) Set default path for exporting a save to path.BATTERY (same as importing a save)

This commit is contained in:
SuuperW 2018-09-03 06:02:01 -05:00
parent c8ef38ad20
commit 407b01b39d
3 changed files with 33 additions and 25 deletions

View File

@ -26,7 +26,7 @@
#include "resource.h" #include "resource.h"
char ImportSavFName[MAX_PATH] = {0}; char SavFName[MAX_PATH] = {0};
u32 fileSaveSize = 0; u32 fileSaveSize = 0;
u32 fileSaveType = 0xFF; u32 fileSaveType = 0xFF;
@ -79,7 +79,7 @@ BOOL CALLBACK ImportSizeSelect_Proc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM l
} }
SendDlgItemMessage(hDlg, IDC_IMP_MANUAL_SIZE, CB_SETCURSEL, fileInfo.type, 0); SendDlgItemMessage(hDlg, IDC_IMP_MANUAL_SIZE, CB_SETCURSEL, fileInfo.type, 0);
fileSaveSize = MMU_new.backupDevice.importDataSize(ImportSavFName); fileSaveSize = MMU_new.backupDevice.importDataSize(SavFName);
if (fileSaveSize > 0) if (fileSaveSize > 0)
{ {
@ -174,7 +174,7 @@ bool importSave(HWND hwnd, HINSTANCE hAppInst)
ofn.hwndOwner = hwnd; ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "All supported types\0*.sav;*.duc;*.dss\0Raw/No$GBA Save format (*.sav)\0*.sav\0Action Replay DS Save (*.duc,*.dss)\0*.duc;*.dss\0\0"; ofn.lpstrFilter = "All supported types\0*.sav;*.duc;*.dss\0Raw/No$GBA Save format (*.sav)\0*.sav\0Action Replay DS Save (*.duc,*.dss)\0*.duc;*.dss\0\0";
ofn.nFilterIndex = 1; ofn.nFilterIndex = 1;
ofn.lpstrFile = ImportSavFName; ofn.lpstrFile = SavFName;
ofn.nMaxFile = MAX_PATH; ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "sav"; ofn.lpstrDefExt = "sav";
ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST; ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
@ -190,7 +190,7 @@ 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)
{ {
res = MMU_new.backupDevice.importData(ImportSavFName, save_types[res+1].size); res = MMU_new.backupDevice.importData(SavFName, save_types[res+1].size);
if (res) if (res)
{ {
printf("Save was successfully imported\n"); printf("Save was successfully imported\n");
@ -203,3 +203,29 @@ bool importSave(HWND hwnd, HINSTANCE hAppInst)
return (res == (MAX_SAVE_TYPES + 1)); return (res == (MAX_SAVE_TYPES + 1));
} }
bool exportSave(HWND hwnd, HINSTANCE hAppInst)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Raw Save format (*.sav)\0*.sav\0No$GBA Save format (*.sav)\0*.sav\0\0";
ofn.nFilterIndex = 0;
ofn.lpstrFile = SavFName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "sav";
ofn.Flags = OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
char buffer[MAX_PATH] = { 0 };
ZeroMemory(buffer, sizeof(buffer));
path.getpath(path.BATTERY, buffer);
ofn.lpstrInitialDir = buffer;
if (!GetSaveFileName(&ofn))
return true;
if (ofn.nFilterIndex == 2) strcat(SavFName, "*");
return !MMU_new.backupDevice.exportData(SavFName);
}

View File

@ -22,5 +22,6 @@
#include <windows.h> #include <windows.h>
extern bool importSave(HWND hwnd, HINSTANCE hAppInst); extern bool importSave(HWND hwnd, HINSTANCE hAppInst);
extern bool exportSave(HWND hwnd, HINSTANCE hAppInst);
#endif #endif

View File

@ -4741,27 +4741,8 @@ DOKEYDOWN:
} }
case IDM_EXPORTBACKUPMEMORY: case IDM_EXPORTBACKUPMEMORY:
{ {
OPENFILENAME ofn;
NDS_Pause(); NDS_Pause();
ZeroMemory(&ofn, sizeof(ofn)); if (!exportSave(hwnd, hAppInst))
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Raw Save format (*.sav)\0*.sav\0No$GBA Save format (*.sav)\0*.sav\0\0";
ofn.nFilterIndex = 0;
ofn.lpstrFile = ImportSavName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "sav";
ofn.Flags = OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
if(!GetSaveFileName(&ofn))
{
NDS_UnPause();
return 0;
}
if (ofn.nFilterIndex == 2) strcat(ImportSavName, "*");
if (!MMU_new.backupDevice.exportData(ImportSavName))
MessageBox(hwnd,"Save was not successfully exported","Error",MB_OK); MessageBox(hwnd,"Save was not successfully exported","Error",MB_OK);
NDS_UnPause(); NDS_UnPause();
return 0; return 0;