From 3d0cdd55d1462c2b61d5b5f496d81c81333df92e Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 11 Jul 2021 12:06:29 +0100 Subject: [PATCH 1/3] Make a few utility funcs static --- source/Utilities.cpp | 4 ++-- source/Utilities.h | 2 -- source/Windows/AppleWin.cpp | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/source/Utilities.cpp b/source/Utilities.cpp index 7aa8b688..f511fd54 100644 --- a/source/Utilities.cpp +++ b/source/Utilities.cpp @@ -349,7 +349,7 @@ static void SetCurrentDir(std::string pathname) SetCurrentImageDir(path); } -bool DoDiskInsert(const UINT slot, const int nDrive, LPCSTR szFileName) +static bool DoDiskInsert(const UINT slot, const int nDrive, LPCSTR szFileName) { Disk2InterfaceCard& disk2Card = dynamic_cast(GetCardMgr().GetRef(slot)); @@ -369,7 +369,7 @@ bool DoDiskInsert(const UINT slot, const int nDrive, LPCSTR szFileName) return res; } -bool DoHardDiskInsert(const int nDrive, LPCSTR szFileName) +static bool DoHardDiskInsert(const int nDrive, LPCSTR szFileName) { if (szFileName[0] == '\0') { diff --git a/source/Utilities.h b/source/Utilities.h index 47dc1b31..c5f7586b 100644 --- a/source/Utilities.h +++ b/source/Utilities.h @@ -5,8 +5,6 @@ void LoadConfiguration(); -bool DoDiskInsert(const UINT slot, const int nDrive, LPCSTR szFileName); -bool DoHardDiskInsert(const int nDrive, LPCSTR szFileName); void InsertFloppyDisks(const UINT slot, LPSTR szImageName_drive[NUM_DRIVES], bool driveConnected[NUM_DRIVES], bool& bBoot); void InsertHardDisks(LPSTR szImageName_harddisk[NUM_HARDDISKS], bool& bBoot); void UnplugHardDiskControllerCard(void); diff --git a/source/Windows/AppleWin.cpp b/source/Windows/AppleWin.cpp index a0fdff91..4fc8e0c8 100644 --- a/source/Windows/AppleWin.cpp +++ b/source/Windows/AppleWin.cpp @@ -780,7 +780,7 @@ static void RepeatInitialization(void) InsertHardDisks(g_cmdLine.szImageName_harddisk, g_cmdLine.bBoot); g_cmdLine.szImageName_harddisk[HARDDISK_1] = g_cmdLine.szImageName_harddisk[HARDDISK_2] = NULL; // Don't insert on a restart - if (g_cmdLine.bSlotEmpty[7]) + if (g_cmdLine.bSlotEmpty[SLOT7]) { HD_SetEnabled(false); // Disable HDD controller, but don't persist this to Registry/conf.ini (consistent with other '-sn empty' cmds) Snapshot_UpdatePath(); // If save-state's filename is a harddisk, and the floppy is in the same path, then the filename won't be updated From 4f45202baf5f60eaaeacf392597a5fa5c30f261d Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 13 Jul 2021 21:24:29 +0100 Subject: [PATCH 2/3] Save full pathname to registry. (#960 PR #959) This was already happening for Hard Disks (although in a convoluted way). Extend to Floppy Disks. --- source/Configuration/PageDisk.cpp | 3 --- source/Disk.cpp | 4 ++-- source/Harddisk.cpp | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/source/Configuration/PageDisk.cpp b/source/Configuration/PageDisk.cpp index 71a566a0..5d972e9a 100644 --- a/source/Configuration/PageDisk.cpp +++ b/source/Configuration/PageDisk.cpp @@ -226,9 +226,6 @@ void CPageDisk::DlgOK(HWND hWnd) m_PropertySheetHelper.GetConfigNew().m_bEnableHDD = bNewHDDIsEnabled; } - RegSaveString(TEXT(REG_PREFS), TEXT(REGVALUE_PREF_LAST_HARDDISK_1), 1, HD_GetFullPathName(HARDDISK_1)); - RegSaveString(TEXT(REG_PREFS), TEXT(REGVALUE_PREF_LAST_HARDDISK_2), 1, HD_GetFullPathName(HARDDISK_2)); - m_PropertySheetHelper.PostMsgAfterClose(hWnd, m_Page); } diff --git a/source/Disk.cpp b/source/Disk.cpp index 21188e2a..6ee702ac 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -191,7 +191,7 @@ void Disk2InterfaceCard::SaveLastDiskImage(const int drive) if (!m_saveDiskImage) return; - const std::string & pFileName = m_floppyDrive[drive].m_disk.m_fullname; + const std::string & pFileName = DiskGetFullPathName(drive); if (drive == DRIVE_1) RegSaveString(TEXT(REG_PREFS), TEXT(REGVALUE_PREF_LAST_DISK_1), TRUE, pFileName); @@ -201,7 +201,7 @@ void Disk2InterfaceCard::SaveLastDiskImage(const int drive) // TCHAR szPathName[MAX_PATH]; - StringCbCopy(szPathName, MAX_PATH, DiskGetFullPathName(drive).c_str()); + StringCbCopy(szPathName, MAX_PATH, pFileName.c_str()); TCHAR* slash = _tcsrchr(szPathName, TEXT(PATH_SEPARATOR)); if (slash != NULL) { diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index c9159af8..c84c1202 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -236,7 +236,7 @@ static void HD_SaveLastDiskImage(const int iDrive) if (!g_bSaveDiskImage) return; - const std::string & pFileName = g_HardDisk[iDrive].fullname; + const std::string & pFileName = HD_GetFullPathName(iDrive); if (iDrive == HARDDISK_1) RegSaveString(TEXT(REG_PREFS), REGVALUE_PREF_LAST_HARDDISK_1, TRUE, pFileName); @@ -246,7 +246,7 @@ static void HD_SaveLastDiskImage(const int iDrive) // char szPathName[MAX_PATH]; - strcpy(szPathName, HD_GetFullPathName(iDrive).c_str()); + strcpy(szPathName, pFileName.c_str()); if (_tcsrchr(szPathName, TEXT(PATH_SEPARATOR))) { char* pPathEnd = _tcsrchr(szPathName, TEXT(PATH_SEPARATOR))+1; From 71bea524198424f466bf17b09afa15b6f22a63b7 Mon Sep 17 00:00:00 2001 From: tomcw Date: Thu, 15 Jul 2021 19:23:01 +0100 Subject: [PATCH 3/3] Disk/Harddisk: Insert() - fix comment and rename var --- source/Disk.cpp | 14 +++++++------- source/Disk.h | 2 +- source/Harddisk.cpp | 16 ++++++++-------- source/Harddisk.h | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source/Disk.cpp b/source/Disk.cpp index 6ee702ac..39ed0d0c 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -654,8 +654,8 @@ void Disk2InterfaceCard::GetLightStatus(Disk_Status_e *pDisk1Status, Disk_Status //=========================================================================== -// Pre: pszImageFilename is *not* qualified with path -ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary) +// Pre: pathname likely to include path (but can also just be filename) +ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, const std::string& pathname, const bool bForceWriteProtected, const bool bCreateIfNecessary) { FloppyDrive* pDrive = &m_floppyDrive[drive]; FloppyDisk* pFloppy = &pDrive->m_disk; @@ -667,7 +667,7 @@ ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFil // . Changing the disk (in the drive) doesn't affect the drive's attributes. pFloppy->clear(); - const DWORD dwAttributes = GetFileAttributes(pszImageFilename); + const DWORD dwAttributes = GetFileAttributes(pathname.c_str()); if (dwAttributes == INVALID_FILE_ATTRIBUTES) pFloppy->m_bWriteProtected = false; // Assume this is a new file to create (so it must be write-enabled to allow it to be formatted) else @@ -678,9 +678,9 @@ ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFil const std::string & pszOtherPathname = DiskGetFullPathName(!drive); char szCurrentPathname[MAX_PATH]; - DWORD uNameLen = GetFullPathName(pszImageFilename, MAX_PATH, szCurrentPathname, NULL); + DWORD uNameLen = GetFullPathName(pathname.c_str(), MAX_PATH, szCurrentPathname, NULL); if (uNameLen == 0 || uNameLen >= MAX_PATH) - strcpy_s(szCurrentPathname, MAX_PATH, pszImageFilename); + strcpy_s(szCurrentPathname, MAX_PATH, pathname.c_str()); if (!strcmp(pszOtherPathname.c_str(), szCurrentPathname)) { @@ -689,7 +689,7 @@ ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFil } } - ImageError_e Error = ImageOpen(pszImageFilename, + ImageError_e Error = ImageOpen(pathname, &pFloppy->m_imagehandle, &pFloppy->m_bWriteProtected, bCreateIfNecessary, @@ -709,7 +709,7 @@ ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFil if (Error == eIMAGE_ERROR_NONE) { - GetImageTitle(pszImageFilename, pFloppy->m_imagename, pFloppy->m_fullname); + GetImageTitle(pathname.c_str(), pFloppy->m_imagename, pFloppy->m_fullname); Snapshot_UpdatePath(); GetFrame().Video_ResetScreenshotCounter(pFloppy->m_imagename); diff --git a/source/Disk.h b/source/Disk.h index 24612c19..484e5adf 100644 --- a/source/Disk.h +++ b/source/Disk.h @@ -142,7 +142,7 @@ public: void GetFilenameAndPathForSaveState(std::string& filename, std::string& path); void GetLightStatus (Disk_Status_e* pDisk1Status, Disk_Status_e* pDisk2Status); - ImageError_e InsertDisk(const int drive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary); + ImageError_e InsertDisk(const int drive, const std::string& pathname, const bool bForceWriteProtected, const bool bCreateIfNecessary); void EjectDisk(const int drive); void UnplugDrive(const int drive); diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index c84c1202..ae55f048 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -207,7 +207,7 @@ static void NotifyInvalidImage(TCHAR* pszImageFilename) //=========================================================================== -BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename); +BOOL HD_Insert(const int iDrive, const std::string& pathname); void HD_LoadLastDiskImage(const int iDrive) { @@ -384,10 +384,10 @@ void HD_Destroy(void) g_bSaveDiskImage = true; } -// Pre: pszImageFilename is qualified with path -BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename) +// Pre: pathname likely to include path (but can also just be filename) +BOOL HD_Insert(const int iDrive, const std::string& pathname) { - if (pszImageFilename.empty()) + if (pathname.empty()) return FALSE; if (g_HardDisk[iDrive].hd_imageloaded) @@ -398,9 +398,9 @@ BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename) const std::string & pszOtherPathname = HD_GetFullPathName(!iDrive); char szCurrentPathname[MAX_PATH]; - DWORD uNameLen = GetFullPathName(pszImageFilename.c_str(), MAX_PATH, szCurrentPathname, NULL); + DWORD uNameLen = GetFullPathName(pathname.c_str(), MAX_PATH, szCurrentPathname, NULL); if (uNameLen == 0 || uNameLen >= MAX_PATH) - strcpy_s(szCurrentPathname, MAX_PATH, pszImageFilename.c_str()); + strcpy_s(szCurrentPathname, MAX_PATH, pathname.c_str()); if (!strcmp(pszOtherPathname.c_str(), szCurrentPathname)) { @@ -412,7 +412,7 @@ BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename) const bool bCreateIfNecessary = false; // NB. Don't allow creation of HDV files const bool bExpectFloppy = false; const bool bIsHarddisk = true; - ImageError_e Error = ImageOpen(pszImageFilename, + ImageError_e Error = ImageOpen(pathname, &g_HardDisk[iDrive].imagehandle, &g_HardDisk[iDrive].bWriteProtected, bCreateIfNecessary, @@ -428,7 +428,7 @@ BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename) if (Error == eIMAGE_ERROR_NONE) { - GetImageTitle(pszImageFilename.c_str(), g_HardDisk[iDrive].imagename, g_HardDisk[iDrive].fullname); + GetImageTitle(pathname.c_str(), g_HardDisk[iDrive].imagename, g_HardDisk[iDrive].fullname); Snapshot_UpdatePath(); } diff --git a/source/Harddisk.h b/source/Harddisk.h index 0faa768e..61df86b1 100644 --- a/source/Harddisk.h +++ b/source/Harddisk.h @@ -44,7 +44,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA void HD_Reset(void); void HD_Load_Rom(const LPBYTE pCxRomPeripheral, const UINT uSlot); bool HD_Select(const int iDrive); - BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename); + BOOL HD_Insert(const int iDrive, const std::string& pathname); void HD_Unplug(const int iDrive); bool HD_IsDriveUnplugged(const int iDrive); void HD_LoadLastDiskImage(const int iDrive);