SaveState: add absolute path for disks.

https://github.com/AppleWin/AppleWin/issues/1290
This commit is contained in:
Andrea Odetti 2024-04-21 13:38:21 +01:00
parent 664d7c2d86
commit 1d654258e8
4 changed files with 40 additions and 11 deletions

View File

@ -45,9 +45,9 @@
<li>Alternate ROM</li>
<li>Alternate video ROM</li>
</ul>
<p>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
<p>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.</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,
then immediately save it (and it'll be saved in the v2 format).</p>

View File

@ -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<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();
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());

View File

@ -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());

View File

@ -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);
//