From 1d654258e8898e7f2c500a7506eb44181dbe1c08 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Sun, 21 Apr 2024 13:38:21 +0100 Subject: [PATCH] SaveState: add absolute path for disks. https://github.com/AppleWin/AppleWin/issues/1290 --- help/savestate.html | 6 +++--- source/Disk.cpp | 19 +++++++++++++++++-- source/Harddisk.cpp | 24 +++++++++++++++++++----- source/Harddisk.h | 2 +- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/help/savestate.html b/help/savestate.html index e90740bc..4c3ca617 100644 --- a/help/savestate.html +++ b/help/savestate.html @@ -45,9 +45,9 @@
  • Alternate ROM
  • Alternate video ROM
  • -

    Note: Only the file names of the disk images are stored in the .yaml file (not the - full path). This allows you to move your disk image around or distribute them. - If AppleWin can't locate the disk image(s), then it will prompt for the new +

    Note: Both the file names and absolute paths are stored in the .yaml file. + This allows you to move your disk image around or distribute them. + If AppleWin still can't locate the disk image(s), then it will prompt for the new location.

    NB. Loading of the old v1 file format (.aws file) is no longer supported. Use AppleWin 1.27.13 to load it at the AppleWin start-up/logo screen, then immediately save it (and it'll be saved in the v2 format).

    diff --git a/source/Disk.cpp b/source/Disk.cpp index 84ab0c7c..6fda2644 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -2206,7 +2206,8 @@ BYTE __stdcall Disk2InterfaceCard::IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE // 6: Added: Drive Connected & Motor On Cycle // 7: Deprecated SS_YAML_KEY_LSS_RESET_SEQUENCER, SS_YAML_KEY_DISK_ACCESSED // 8: Added: deferred stepper: event, address & cycle -static const UINT kUNIT_VERSION = 8; +// 9: Added: absolute path +static const UINT kUNIT_VERSION = 9; #define SS_YAML_VALUE_CARD_DISK2 "Disk][" @@ -2238,6 +2239,7 @@ static const UINT kUNIT_VERSION = 8; #define SS_YAML_KEY_FLOPPY "Floppy" #define SS_YAML_KEY_FILENAME "Filename" +#define SS_YAML_KEY_ABSOLUTE_PATH "Absolute Path" #define SS_YAML_KEY_BYTE "Byte" #define SS_YAML_KEY_NIBBLES "Nibbles" #define SS_YAML_KEY_BIT_OFFSET "Bit Offset" @@ -2260,6 +2262,7 @@ void Disk2InterfaceCard::SaveSnapshotFloppy(YamlSaveHelper& yamlSaveHelper, UINT { YamlSaveHelper::Label label(yamlSaveHelper, "%s:\n", SS_YAML_KEY_FLOPPY); yamlSaveHelper.SaveString(SS_YAML_KEY_FILENAME, m_floppyDrive[unit].m_disk.m_fullname); + yamlSaveHelper.SaveString(SS_YAML_KEY_ABSOLUTE_PATH, ImageGetPathname(m_floppyDrive[unit].m_disk.m_imagehandle)); yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_BYTE, m_floppyDrive[unit].m_disk.m_byte); yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_NIBBLES, m_floppyDrive[unit].m_disk.m_nibbles); yamlSaveHelper.SaveHexUint32(SS_YAML_KEY_BIT_OFFSET, m_floppyDrive[unit].m_disk.m_bitOffset); // v4 @@ -2317,14 +2320,26 @@ void Disk2InterfaceCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper) bool Disk2InterfaceCard::LoadSnapshotFloppy(YamlLoadHelper& yamlLoadHelper, UINT unit, UINT version, std::vector& track) { - std::string filename = yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME); + const std::string simpleFilename = yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME); + const std::string absolutePath = version >= 9 ? yamlLoadHelper.LoadString(SS_YAML_KEY_ABSOLUTE_PATH) : ""; + + std::string filename = simpleFilename; bool bImageError = filename.empty(); if (!bImageError) { DWORD dwAttributes = GetFileAttributes(filename.c_str()); + if (dwAttributes == INVALID_FILE_ATTRIBUTES && !absolutePath.empty()) + { + // try the absolute path if present + filename = absolutePath; + dwAttributes = GetFileAttributes(filename.c_str()); + } + if (dwAttributes == INVALID_FILE_ATTRIBUTES) { + // ignore absolute name when opening the file dialog + filename = simpleFilename; // Get user to browse for file UserSelectNewDiskImage(unit, filename.c_str()); diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index f26a0e2b..dc66a36c 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -796,7 +796,8 @@ bool HarddiskInterfaceCard::ImageSwap(void) // 3: Updated $Csnn firmware to fix GH#996 (now slot-independent code) // Added: Not Busy Cycle // 4: Updated $Csnn firmware to fix GH#1264 -static const UINT kUNIT_VERSION = 4; +// 5: Added: absolute path +static const UINT kUNIT_VERSION = 5; #define SS_YAML_VALUE_CARD_HDD "Generic HDD" @@ -805,6 +806,7 @@ static const UINT kUNIT_VERSION = 4; #define SS_YAML_KEY_HDDUNIT "Unit" #define SS_YAML_KEY_FILENAME "Filename" +#define SS_YAML_KEY_ABSOLUTE_PATH "Absolute Path" #define SS_YAML_KEY_ERROR "Error" #define SS_YAML_KEY_MEMBLOCK "MemBlock" #define SS_YAML_KEY_DISKBLOCK "DiskBlock" @@ -825,6 +827,7 @@ void HarddiskInterfaceCard::SaveSnapshotHDDUnit(YamlSaveHelper& yamlSaveHelper, { YamlSaveHelper::Label label(yamlSaveHelper, "%s%d:\n", SS_YAML_KEY_HDDUNIT, unit); yamlSaveHelper.SaveString(SS_YAML_KEY_FILENAME, m_hardDiskDrive[unit].m_fullname); + yamlSaveHelper.SaveString(SS_YAML_KEY_ABSOLUTE_PATH, ImageGetPathname(m_hardDiskDrive[unit].m_imagehandle)); yamlSaveHelper.SaveHexUint8(SS_YAML_KEY_ERROR, m_hardDiskDrive[unit].m_error); yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_MEMBLOCK, m_hardDiskDrive[unit].m_memblock); yamlSaveHelper.SaveHexUint32(SS_YAML_KEY_DISKBLOCK, m_hardDiskDrive[unit].m_diskblock); @@ -853,7 +856,7 @@ void HarddiskInterfaceCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper) SaveSnapshotHDDUnit(yamlSaveHelper, HARDDISK_2); } -bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper, UINT unit) +bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper, UINT unit, UINT version) { std::string hddUnitName = std::string(SS_YAML_KEY_HDDUNIT) + (unit == HARDDISK_1 ? std::string("0") : std::string("1")); if (!yamlLoadHelper.GetSubMap(hddUnitName)) @@ -865,7 +868,8 @@ bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper, m_hardDiskDrive[unit].m_status_next = DISK_STATUS_OFF; m_hardDiskDrive[unit].m_status_prev = DISK_STATUS_OFF; - std::string filename = yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME); + const std::string simpleFilename = yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME); + const std::string absolutePath = version >= 5 ? yamlLoadHelper.LoadString(SS_YAML_KEY_ABSOLUTE_PATH) : ""; m_hardDiskDrive[unit].m_error = yamlLoadHelper.LoadUint(SS_YAML_KEY_ERROR); m_hardDiskDrive[unit].m_memblock = yamlLoadHelper.LoadUint(SS_YAML_KEY_MEMBLOCK); m_hardDiskDrive[unit].m_diskblock = yamlLoadHelper.LoadUint(SS_YAML_KEY_DISKBLOCK); @@ -887,11 +891,21 @@ bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper, bool bResSelectImage = false; + std::string filename = simpleFilename; if (!filename.empty()) { DWORD dwAttributes = GetFileAttributes(filename.c_str()); + if (dwAttributes == INVALID_FILE_ATTRIBUTES && !absolutePath.empty()) + { + // try the absolute path if present + filename = absolutePath; + dwAttributes = GetFileAttributes(filename.c_str()); + } + if (dwAttributes == INVALID_FILE_ATTRIBUTES) { + // ignore absolute name when opening the file dialog + filename = simpleFilename; // Get user to browse for file bResSelectImage = SelectImage(unit, filename.c_str()); @@ -940,8 +954,8 @@ bool HarddiskInterfaceCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT ve m_hardDiskDrive[i].clear(); } - bool bResSelectImage1 = LoadSnapshotHDDUnit(yamlLoadHelper, HARDDISK_1); - bool bResSelectImage2 = LoadSnapshotHDDUnit(yamlLoadHelper, HARDDISK_2); + bool bResSelectImage1 = LoadSnapshotHDDUnit(yamlLoadHelper, HARDDISK_1, version); + bool bResSelectImage2 = LoadSnapshotHDDUnit(yamlLoadHelper, HARDDISK_2, version); if (!bResSelectImage1 && !bResSelectImage2) RegSaveString(TEXT(REG_PREFS), TEXT(REGVALUE_PREF_HDV_START_DIR), 1, Snapshot_GetPath()); diff --git a/source/Harddisk.h b/source/Harddisk.h index 4733c5c0..d876d071 100644 --- a/source/Harddisk.h +++ b/source/Harddisk.h @@ -123,7 +123,7 @@ private: void UpdateLightStatus(HardDiskDrive* pHDD); UINT GetImageSizeInBlocks(ImageInfo* const pImageInfo); void SaveSnapshotHDDUnit(YamlSaveHelper& yamlSaveHelper, UINT unit); - bool LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper, UINT unit); + bool LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper, UINT unit, UINT version); //