diff --git a/AppleWin/docs/History.txt b/AppleWin/docs/History.txt index a3ca5be1..90967784 100644 --- a/AppleWin/docs/History.txt +++ b/AppleWin/docs/History.txt @@ -24,7 +24,8 @@ Changes: . Support auto-fire for all 3 joystick buttons (via Config->Input) . Debugger: Added "disk info" command . Added confirmation message box for reboot (F2) -. Added -no-printscreen-dlg to surpress the warning if AppleWin failed to capture the PrintScreen key +. Added -no-printscreen-dlg to surpress the warning if AppleWin failed to capture the PrintScreen key +. Changed save-state file persisted to Registry from filename to pathame Fixes: . [Bug #19154] ProDOS Order 2IMG crashing . [Support #103098] Sometimes swapping disk could cause INIT to fail with ERROR #8 diff --git a/AppleWin/source/Applewin.cpp b/AppleWin/source/Applewin.cpp index 9d0895aa..9a1b471f 100644 --- a/AppleWin/source/Applewin.cpp +++ b/AppleWin/source/Applewin.cpp @@ -549,20 +549,26 @@ void LoadConfiguration(void) // char szFilename[MAX_PATH] = {0}; + + // Current/Starting Dir is the "root" of where the user keeps his disk images + RegLoadString(TEXT(REG_PREFS), TEXT(REGVALUE_PREF_START_DIR), 1, szFilename, MAX_PATH); + if (szFilename[0] == 0) + GetCurrentDirectory(sizeof(szFilename), szFilename); + SetCurrentImageDir(szFilename); + + Disk_LoadLastDiskImage(DRIVE_1); + Disk_LoadLastDiskImage(DRIVE_2); + + // + + szFilename[0] = 0; RegLoadString(TEXT(REG_CONFIG),TEXT(REGVALUE_SAVESTATE_FILENAME),1,szFilename,sizeof(szFilename)); - Snapshot_SetFilename(szFilename); // If not in Registry than default will be used + Snapshot_SetFilename(szFilename); // If not in Registry than default will be used (ie. g_sCurrentDir + default filename) szFilename[0] = 0; RegLoadString(TEXT(REG_CONFIG),TEXT(REGVALUE_PRINTER_FILENAME),1,szFilename,sizeof(szFilename)); Printer_SetFilename(szFilename); // If not in Registry than default will be used - // Current/Starting Dir is the "root" of where the user keeps his disk images - RegLoadString(TEXT(REG_PREFS),TEXT(REGVALUE_PREF_START_DIR),1,g_sCurrentDir,MAX_PATH); - SetCurrentImageDir(); - - Disk_LoadLastDiskImage(DRIVE_1); - Disk_LoadLastDiskImage(DRIVE_2); - dwTmp = 10; REGLOAD(TEXT(REGVALUE_PRINTER_IDLE_LIMIT), &dwTmp); Printer_SetIdleLimit(dwTmp); @@ -577,8 +583,9 @@ void LoadConfiguration(void) //=========================================================================== -void SetCurrentImageDir(void) +void SetCurrentImageDir(const char* pszImageDir) { + strcpy(g_sCurrentDir, pszImageDir); SetCurrentDirectory(g_sCurrentDir); } diff --git a/AppleWin/source/Applewin.h b/AppleWin/source/Applewin.h index 924efea2..af17cebc 100644 --- a/AppleWin/source/Applewin.h +++ b/AppleWin/source/Applewin.h @@ -1,7 +1,7 @@ #pragma once void SetCurrentCLK6502(); -void SetCurrentImageDir(); +void SetCurrentImageDir(const char* pszImageDir); extern char VERSIONSTRING[]; // Contructed in WinMain() diff --git a/AppleWin/source/Configuration/PageAdvanced.cpp b/AppleWin/source/Configuration/PageAdvanced.cpp index 9464ffc1..ffd05ca2 100644 --- a/AppleWin/source/Configuration/PageAdvanced.cpp +++ b/AppleWin/source/Configuration/PageAdvanced.cpp @@ -56,7 +56,7 @@ BOOL CPageAdvanced::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPAR case IDC_SAVESTATE_FILENAME: break; case IDC_SAVESTATE_BROWSE: - if(m_PropertySheetHelper.SaveStateSelectImage(hWnd, TEXT("Select Save State file"), true)) + if(m_PropertySheetHelper.SaveStateSelectImage(hWnd, TEXT("Select Save State file"), false)) SendDlgItemMessage(hWnd, IDC_SAVESTATE_FILENAME, WM_SETTEXT, 0, (LPARAM)m_PropertySheetHelper.GetSSNewFilename()); break; case IDC_PRINTER_DUMP_FILENAME_BROWSE: diff --git a/AppleWin/source/Configuration/PropertySheetHelper.cpp b/AppleWin/source/Configuration/PropertySheetHelper.cpp index 1324aedf..01c61c39 100644 --- a/AppleWin/source/Configuration/PropertySheetHelper.cpp +++ b/AppleWin/source/Configuration/PropertySheetHelper.cpp @@ -166,12 +166,12 @@ void CPropertySheetHelper::SaveStateUpdate() { if (m_bSSNewFilename) { - Snapshot_SetFilename(m_szSSNewFilename); + Snapshot_SetFilename(m_szSSNewPathname); - RegSaveString(TEXT(REG_CONFIG), REGVALUE_SAVESTATE_FILENAME, 1, Snapshot_GetFilename()); + RegSaveString(TEXT(REG_CONFIG), REGVALUE_SAVESTATE_FILENAME, 1, m_szSSNewPathname); if(m_szSSNewDirectory[0]) - RegSaveString(TEXT(REG_PREFS), REGVALUE_PREF_START_DIR, 1 ,m_szSSNewDirectory); + RegSaveString(TEXT(REG_PREFS), REGVALUE_PREF_START_DIR, 1, m_szSSNewDirectory); } } @@ -201,7 +201,7 @@ int CPropertySheetHelper::SaveStateSelectImage(HWND hWindow, TCHAR* pszTitle, bo strcpy(szFilename, Snapshot_GetFilename()); } } - else // Load + else // Load (or Browse) { // Attempt to use the Prop Sheet's filename first // Else attempt to use drive1's image name as the name for the .aws file @@ -210,9 +210,12 @@ int CPropertySheetHelper::SaveStateSelectImage(HWND hWindow, TCHAR* pszTitle, bo { GetDiskBaseNameWithAWS(szFilename); } + + strcpy(szDirectory, Snapshot_GetPath()); } - RegLoadString(TEXT(REG_PREFS),REGVALUE_PREF_START_DIR,1,szDirectory,MAX_PATH); + if (szDirectory[0] == 0) + strcpy(szDirectory, g_sCurrentDir); // @@ -229,7 +232,7 @@ int CPropertySheetHelper::SaveStateSelectImage(HWND hWindow, TCHAR* pszTitle, bo ofn.lpstrInitialDir = szDirectory; ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrTitle = pszTitle; - + int nRes = bSave ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn); if(nRes) @@ -246,6 +249,8 @@ int CPropertySheetHelper::SaveStateSelectImage(HWND hWindow, TCHAR* pszTitle, bo strcpy(&m_szSSNewFilename[uStrLenFile], szAWS_EXT); } + strcpy(m_szSSNewPathname, szFilename); + szFilename[ofn.nFileOffset] = 0; if (_tcsicmp(szDirectory, szFilename)) strcpy(m_szSSNewDirectory, szFilename); diff --git a/AppleWin/source/Configuration/PropertySheetHelper.h b/AppleWin/source/Configuration/PropertySheetHelper.h index ae040fb4..d600dcb4 100644 --- a/AppleWin/source/Configuration/PropertySheetHelper.h +++ b/AppleWin/source/Configuration/PropertySheetHelper.h @@ -55,6 +55,7 @@ private: bool m_bSSNewFilename; char m_szSSNewDirectory[MAX_PATH]; char m_szSSNewFilename[MAX_PATH]; + char m_szSSNewPathname[MAX_PATH]; CConfigNeedingRestart m_ConfigOld; CConfigNeedingRestart m_ConfigNew; bool m_bDoBenchmark; diff --git a/AppleWin/source/SaveState.cpp b/AppleWin/source/SaveState.cpp index 5e1e1819..ac31a9c1 100644 --- a/AppleWin/source/SaveState.cpp +++ b/AppleWin/source/SaveState.cpp @@ -33,21 +33,50 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA bool g_bSaveStateOnExit = false; -static char g_szSaveStateFilename[MAX_PATH] = {0}; +static std::string g_strSaveStateFilename; +static std::string g_strSaveStatePathname; +static std::string g_strSaveStatePath; //----------------------------------------------------------------------------- -char* Snapshot_GetFilename() +void Snapshot_SetFilename(std::string strPathname) { - return g_szSaveStateFilename; + if (strPathname.empty()) + { + g_strSaveStateFilename = DEFAULT_SNAPSHOT_NAME; + + g_strSaveStatePathname = g_sCurrentDir; + if (g_strSaveStatePathname.length() && g_strSaveStatePathname[g_strSaveStatePathname.length()-1] != '\\') + g_strSaveStatePathname += "\\"; + g_strSaveStatePathname.append(DEFAULT_SNAPSHOT_NAME); + + g_strSaveStatePath = g_sCurrentDir; + + return; + } + + std::string strFilename = strPathname; // Set default, as maybe there's no path + g_strSaveStatePath.clear(); + + int nIdx = strPathname.find_last_of('\\'); + if (nIdx >= 0 && nIdx+1 < (int)strPathname.length()) + { + strFilename = &strPathname[nIdx+1]; + g_strSaveStatePath = strPathname.substr(0, nIdx); + } + + g_strSaveStateFilename = strFilename; + g_strSaveStatePathname = strPathname; } -void Snapshot_SetFilename(char* pszFilename) +const char* Snapshot_GetFilename() { - if(*pszFilename) - strcpy(g_szSaveStateFilename, (const char *) pszFilename); - else - strcpy(g_szSaveStateFilename, DEFAULT_SNAPSHOT_NAME); + return g_strSaveStateFilename.c_str(); +} + +const char* Snapshot_GetPath() +{ + return g_strSaveStatePath.c_str(); } //----------------------------------------------------------------------------- @@ -55,11 +84,15 @@ void Snapshot_SetFilename(char* pszFilename) void Snapshot_LoadState() { char szMessage[32 + MAX_PATH]; + std::string strOldImageDir; APPLEWIN_SNAPSHOT* pSS = (APPLEWIN_SNAPSHOT*) new char[sizeof(APPLEWIN_SNAPSHOT)]; try { + strOldImageDir = g_sCurrentDir; + SetCurrentImageDir(g_strSaveStatePath.c_str()); // Allow .dsk's load without prompting + if(pSS == NULL) throw(0); @@ -67,7 +100,7 @@ void Snapshot_LoadState() // - HANDLE hFile = CreateFile( g_szSaveStateFilename, + HANDLE hFile = CreateFile( g_strSaveStatePathname.c_str(), GENERIC_READ, 0, NULL, @@ -78,7 +111,7 @@ void Snapshot_LoadState() if(hFile == INVALID_HANDLE_VALUE) { strcpy(szMessage, "File not found: "); - strcpy(szMessage + strlen(szMessage), g_szSaveStateFilename); + strcpy(szMessage + strlen(szMessage), g_strSaveStatePathname.c_str()); throw(0); } @@ -158,6 +191,8 @@ void Snapshot_LoadState() szMessage, TEXT("Load State"), MB_ICONEXCLAMATION | MB_SETFOREGROUND); + + SetCurrentImageDir(strOldImageDir.c_str()); } delete [] pSS; @@ -230,7 +265,7 @@ void Snapshot_SaveState() // - HANDLE hFile = CreateFile( g_szSaveStateFilename, + HANDLE hFile = CreateFile( g_strSaveStatePathname.c_str(), GENERIC_WRITE, 0, NULL, diff --git a/AppleWin/source/SaveState.h b/AppleWin/source/SaveState.h index d8a29da3..1df5ec8b 100644 --- a/AppleWin/source/SaveState.h +++ b/AppleWin/source/SaveState.h @@ -2,8 +2,9 @@ extern bool g_bSaveStateOnExit; -char* Snapshot_GetFilename(); -void Snapshot_SetFilename(char* pszFilename); +void Snapshot_SetFilename(std::string strPathname); +const char* Snapshot_GetFilename(); +const char* Snapshot_GetPath(); void Snapshot_LoadState(); void Snapshot_SaveState(); void Snapshot_Startup();