SaveState: add absolute path for disk & hdd images. (#1290, PR #1294)

This commit is contained in:
Andrea 2024-10-06 20:44:24 +01:00 committed by GitHub
parent e8641555e8
commit 3033f3445b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 8 deletions

View File

@ -45,10 +45,12 @@
<li>Alternate ROM</li> <li>Alternate ROM</li>
<li>Alternate video ROM</li> <li>Alternate video ROM</li>
</ul> </ul>
<p>Note: Only the file names of the disk images are stored in the .yaml file (not the <p>
full path). This allows you to move your disk image around or distribute them. Note: Both the file name and absolute path are stored in the .yaml file.
If AppleWin can't locate the disk image(s), then it will prompt for the new This allows you to move your disk image around or distribute them.
location.</p> If AppleWin still can't locate the disk image(s), then it will prompt for the new
location.
</p>
<p>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, <p>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).</p> then immediately save it (and it'll be saved in the v2 format).</p>
</body> </body>

View File

@ -2217,7 +2217,8 @@ BYTE __stdcall Disk2InterfaceCard::IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE
// 6: Added: Drive Connected & Motor On Cycle // 6: Added: Drive Connected & Motor On Cycle
// 7: Deprecated SS_YAML_KEY_LSS_RESET_SEQUENCER, SS_YAML_KEY_DISK_ACCESSED // 7: Deprecated SS_YAML_KEY_LSS_RESET_SEQUENCER, SS_YAML_KEY_DISK_ACCESSED
// 8: Added: deferred stepper: event, address & cycle // 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][" #define SS_YAML_VALUE_CARD_DISK2 "Disk]["
@ -2249,6 +2250,7 @@ static const UINT kUNIT_VERSION = 8;
#define SS_YAML_KEY_FLOPPY "Floppy" #define SS_YAML_KEY_FLOPPY "Floppy"
#define SS_YAML_KEY_FILENAME "Filename" #define SS_YAML_KEY_FILENAME "Filename"
#define SS_YAML_KEY_ABSOLUTE_PATH "Absolute Path"
#define SS_YAML_KEY_BYTE "Byte" #define SS_YAML_KEY_BYTE "Byte"
#define SS_YAML_KEY_NIBBLES "Nibbles" #define SS_YAML_KEY_NIBBLES "Nibbles"
#define SS_YAML_KEY_BIT_OFFSET "Bit Offset" #define SS_YAML_KEY_BIT_OFFSET "Bit Offset"
@ -2271,6 +2273,7 @@ void Disk2InterfaceCard::SaveSnapshotFloppy(YamlSaveHelper& yamlSaveHelper, UINT
{ {
YamlSaveHelper::Label label(yamlSaveHelper, "%s:\n", SS_YAML_KEY_FLOPPY); 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_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_BYTE, m_floppyDrive[unit].m_disk.m_byte);
yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_NIBBLES, m_floppyDrive[unit].m_disk.m_nibbles); 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 yamlSaveHelper.SaveHexUint32(SS_YAML_KEY_BIT_OFFSET, m_floppyDrive[unit].m_disk.m_bitOffset); // v4
@ -2328,14 +2331,26 @@ void Disk2InterfaceCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
bool Disk2InterfaceCard::LoadSnapshotFloppy(YamlLoadHelper& yamlLoadHelper, UINT unit, UINT version, std::vector<BYTE>& track) bool Disk2InterfaceCard::LoadSnapshotFloppy(YamlLoadHelper& yamlLoadHelper, UINT unit, UINT version, std::vector<BYTE>& 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(); bool bImageError = filename.empty();
if (!bImageError) if (!bImageError)
{ {
DWORD dwAttributes = GetFileAttributes(filename.c_str()); 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) if (dwAttributes == INVALID_FILE_ATTRIBUTES)
{ {
// ignore absolute name when opening the file dialog
filename = simpleFilename;
// Get user to browse for file // Get user to browse for file
UserSelectNewDiskImage(unit, filename.c_str()); UserSelectNewDiskImage(unit, filename.c_str());

View File

@ -1151,7 +1151,8 @@ bool HarddiskInterfaceCard::ImageSwap(void)
// 4: Updated $Csnn firmware to fix GH#1264 // 4: Updated $Csnn firmware to fix GH#1264
// 5: Added: SP Status Code, FIFO Index & 256-byte firmware // 5: Added: SP Status Code, FIFO Index & 256-byte firmware
// Units are 1-based (up to v4 they were 0-based) // Units are 1-based (up to v4 they were 0-based)
static const UINT kUNIT_VERSION = 5; // 6: Added: absolute path
static const UINT kUNIT_VERSION = 6;
#define SS_YAML_VALUE_CARD_HDD "Generic HDD" #define SS_YAML_VALUE_CARD_HDD "Generic HDD"
@ -1160,6 +1161,7 @@ static const UINT kUNIT_VERSION = 5;
#define SS_YAML_KEY_HDDUNIT "Unit" #define SS_YAML_KEY_HDDUNIT "Unit"
#define SS_YAML_KEY_FILENAME "Filename" #define SS_YAML_KEY_FILENAME "Filename"
#define SS_YAML_KEY_ABSOLUTE_PATH "Absolute Path"
#define SS_YAML_KEY_ERROR "Error" #define SS_YAML_KEY_ERROR "Error"
#define SS_YAML_KEY_MEMBLOCK "MemBlock" #define SS_YAML_KEY_MEMBLOCK "MemBlock"
#define SS_YAML_KEY_DISKBLOCK "DiskBlock" #define SS_YAML_KEY_DISKBLOCK "DiskBlock"
@ -1185,6 +1187,7 @@ void HarddiskInterfaceCard::SaveSnapshotHDDUnit(YamlSaveHelper& yamlSaveHelper,
YamlSaveHelper::Label label(yamlSaveHelper, "%s%d:\n", SS_YAML_KEY_HDDUNIT, baseUnitNum + unit); YamlSaveHelper::Label label(yamlSaveHelper, "%s%d:\n", SS_YAML_KEY_HDDUNIT, baseUnitNum + unit);
yamlSaveHelper.SaveString(SS_YAML_KEY_FILENAME, m_hardDiskDrive[unit].m_fullname); 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.SaveHexUint8(SS_YAML_KEY_ERROR, m_hardDiskDrive[unit].m_error);
yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_MEMBLOCK, m_hardDiskDrive[unit].m_memblock); yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_MEMBLOCK, m_hardDiskDrive[unit].m_memblock);
yamlSaveHelper.SaveHexUint32(SS_YAML_KEY_DISKBLOCK, m_hardDiskDrive[unit].m_diskblock); yamlSaveHelper.SaveHexUint32(SS_YAML_KEY_DISKBLOCK, m_hardDiskDrive[unit].m_diskblock);
@ -1238,7 +1241,8 @@ bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper,
m_hardDiskDrive[unit].m_status_next = DISK_STATUS_OFF; m_hardDiskDrive[unit].m_status_next = DISK_STATUS_OFF;
m_hardDiskDrive[unit].m_status_prev = 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 >= 6 ? yamlLoadHelper.LoadString(SS_YAML_KEY_ABSOLUTE_PATH) : "";
m_hardDiskDrive[unit].m_error = yamlLoadHelper.LoadUint(SS_YAML_KEY_ERROR); 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_memblock = yamlLoadHelper.LoadUint(SS_YAML_KEY_MEMBLOCK);
m_hardDiskDrive[unit].m_diskblock = yamlLoadHelper.LoadUint(SS_YAML_KEY_DISKBLOCK); m_hardDiskDrive[unit].m_diskblock = yamlLoadHelper.LoadUint(SS_YAML_KEY_DISKBLOCK);
@ -1260,11 +1264,21 @@ bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper,
bool userSelectedImageFolder = false; bool userSelectedImageFolder = false;
std::string filename = simpleFilename;
if (!filename.empty()) if (!filename.empty())
{ {
DWORD dwAttributes = GetFileAttributes(filename.c_str()); 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) if (dwAttributes == INVALID_FILE_ATTRIBUTES)
{ {
// ignore absolute name when opening the file dialog
filename = simpleFilename;
// Get user to browse for file // Get user to browse for file
userSelectedImageFolder = SelectImage(unit, filename.c_str()); userSelectedImageFolder = SelectImage(unit, filename.c_str());