Remove some StringCb* functions and fix assertion. (PR #1239)

. Return an error for an invalid .bin image.
This commit is contained in:
Andrea 2023-06-17 20:41:48 +01:00 committed by GitHub
parent 03ce472e63
commit 2759527f0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 24 deletions

View File

@ -243,13 +243,11 @@ void Disk2InterfaceCard::SaveLastDiskImage(const int drive)
if (m_slot != SLOT6 || drive != DRIVE_1)
return;
TCHAR szPathName[MAX_PATH];
StringCbCopy(szPathName, MAX_PATH, pathName.c_str());
TCHAR* slash = _tcsrchr(szPathName, PATH_SEPARATOR);
if (slash != NULL)
const size_t slash = pathName.find_last_of(PATH_SEPARATOR);
if (slash != std::string::npos)
{
slash[1] = '\0';
RegSaveString(REG_PREFS, REGVALUE_PREF_START_DIR, 1, szPathName);
const std::string dirName = pathName.substr(0, slash + 1);
RegSaveString(REG_PREFS, REGVALUE_PREF_START_DIR, 1, dirName);
}
}
@ -887,9 +885,10 @@ bool Disk2InterfaceCard::IsConditionForFullSpeed(void)
//===========================================================================
void Disk2InterfaceCard::NotifyInvalidImage(const int drive, LPCTSTR pszImageFilename, const ImageError_e Error)
void Disk2InterfaceCard::NotifyInvalidImage(const int drive, const std::string & szImageFilename, const ImageError_e Error)
{
std::string strText;
const char * pszImageFilename = szImageFilename.c_str();
switch (Error)
{
@ -1842,17 +1841,18 @@ bool Disk2InterfaceCard::UserSelectNewDiskImage(const int drive, LPCSTR pszFilen
if (GetOpenFileName(&ofn))
{
std::string openFilename = filename;
if ((!ofn.nFileExtension) || !filename[ofn.nFileExtension])
StringCbCat(filename, MAX_PATH, TEXT(".dsk"));
openFilename += TEXT(".dsk");
ImageError_e Error = InsertDisk(drive, filename, ofn.Flags & OFN_READONLY, IMAGE_CREATE);
ImageError_e Error = InsertDisk(drive, openFilename, ofn.Flags & OFN_READONLY, IMAGE_CREATE);
if (Error == eIMAGE_ERROR_NONE)
{
bRes = true;
}
else
{
NotifyInvalidImage(drive, filename, Error);
NotifyInvalidImage(drive, openFilename, Error);
}
}

View File

@ -159,7 +159,7 @@ public:
void UnplugDrive(const int drive);
bool IsConditionForFullSpeed(void);
void NotifyInvalidImage(const int drive, LPCTSTR pszImageFilename, const ImageError_e Error);
void NotifyInvalidImage(const int drive, const std::string & szImageFilename, const ImageError_e Error);
UINT GetCurrentBitOffset(void);
UINT GetCurrentFirmware(void) { return m_is13SectorFirmware ? 13 : 16; }

View File

@ -78,7 +78,8 @@ ImageError_e ImageOpen( const std::string & pszImageFilename,
if (!bExpectFloppy)
return eIMAGE_ERROR_UNSUPPORTED;
_ASSERT(pImageInfo->uNumTracks);
if (!pImageInfo->uNumTracks)
return eIMAGE_ERROR_UNSUPPORTED;
*pWriteProtected = pImageInfo->bWriteProtected;

View File

@ -197,12 +197,12 @@ void HarddiskInterfaceCard::CleanupDrive(const int iDrive)
//===========================================================================
void HarddiskInterfaceCard::NotifyInvalidImage(TCHAR* pszImageFilename)
void HarddiskInterfaceCard::NotifyInvalidImage(const std::string & szImageFilename)
{
// TC: TO DO - see Disk2InterfaceCard::NotifyInvalidImage()
std::string strText = StrFormat("Unable to open the file %s.",
pszImageFilename);
szImageFilename.c_str());
GetFrame().FrameMessageBox(strText.c_str(),
g_pAppTitle.c_str(),
@ -263,13 +263,11 @@ void HarddiskInterfaceCard::SaveLastDiskImage(const int drive)
if (m_slot != SLOT7 || drive != HARDDISK_1)
return;
TCHAR szPathName[MAX_PATH];
StringCbCopy(szPathName, MAX_PATH, pathName.c_str());
TCHAR* slash = _tcsrchr(szPathName, PATH_SEPARATOR);
if (slash != NULL)
const size_t slash = pathName.find_last_of(PATH_SEPARATOR);
if (slash != std::string::npos)
{
slash[1] = '\0';
RegSaveString(REG_PREFS, REGVALUE_PREF_HDV_START_DIR, 1, szPathName);
const std::string dirName = pathName.substr(0, slash + 1);
RegSaveString(REG_PREFS, REGVALUE_PREF_HDV_START_DIR, 1, dirName);
}
}
@ -410,16 +408,17 @@ bool HarddiskInterfaceCard::SelectImage(const int drive, LPCSTR pszFilename)
if (GetOpenFileName(&ofn))
{
std::string openFilename = filename;
if ((!ofn.nFileExtension) || !filename[ofn.nFileExtension])
StringCbCat(filename, MAX_PATH, TEXT(".hdv"));
openFilename += TEXT(".hdv");
if (Insert(drive, filename))
if (Insert(drive, openFilename))
{
bRes = true;
}
else
{
NotifyInvalidImage(filename);
NotifyInvalidImage(openFilename);
}
}

View File

@ -112,7 +112,7 @@ public:
private:
void CleanupDriveInternal(const int iDrive);
void CleanupDrive(const int iDrive);
void NotifyInvalidImage(TCHAR* pszImageFilename);
void NotifyInvalidImage(const std::string & szImageFilename);
void SaveLastDiskImage(const int drive);
const std::string& DiskGetBaseName(const int iDrive);
bool SelectImage(const int drive, LPCSTR pszFilename);