Pre: pathname likely to include path (but can also just be filename)
| 421 | |
| 422 | // Pre: pathname likely to include path (but can also just be filename) |
| 423 | bool HarddiskInterfaceCard::Insert(const int iDrive, const std::string& pathname) |
| 424 | { |
| 425 | if (m_hardDiskDrive[iDrive].m_imageloaded) |
| 426 | Unplug(iDrive); |
| 427 | |
| 428 | if (pathname.empty()) |
| 429 | return true; |
| 430 | |
| 431 | const DWORD dwAttributes = GetFileAttributes(pathname.c_str()); |
| 432 | if (dwAttributes == INVALID_FILE_ATTRIBUTES) |
| 433 | m_hardDiskDrive[iDrive].m_bWriteProtected = false; // File doesn't exist - so ImageOpen() below will fail |
| 434 | else |
| 435 | m_hardDiskDrive[iDrive].m_bWriteProtected = (dwAttributes & FILE_ATTRIBUTE_READONLY) ? true : false; |
| 436 | |
| 437 | // Check if image is being used by any other HDD, and unplug it in order to be swapped |
| 438 | for (UINT i = HARDDISK_1; i < NUM_HARDDISKS; i++) |
| 439 | { |
| 440 | if (i == iDrive) |
| 441 | continue; |
| 442 | |
| 443 | const std::string& pszOtherPathname = HarddiskGetFullPathName(i); |
| 444 | |
| 445 | char szCurrentPathname[MAX_PATH]; |
| 446 | DWORD uNameLen = GetFullPathName(pathname.c_str(), MAX_PATH, szCurrentPathname, NULL); |
| 447 | if (uNameLen == 0 || uNameLen >= MAX_PATH) |
| 448 | strcpy_s(szCurrentPathname, MAX_PATH, pathname.c_str()); |
| 449 | |
| 450 | if (!strcmp(pszOtherPathname.c_str(), szCurrentPathname)) |
| 451 | { |
| 452 | Unplug(i); |
| 453 | GetFrame().FrameRefreshStatus(DRAW_LEDS | DRAW_DISK_STATUS); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | const bool bCreateIfNecessary = false; // NB. Don't allow creation of HDV files |
| 458 | const bool bExpectFloppy = false; |
| 459 | const bool bIsHarddisk = true; |
| 460 | ImageError_e Error = ImageOpen(pathname, |
| 461 | &m_hardDiskDrive[iDrive].m_imagehandle, |
| 462 | &m_hardDiskDrive[iDrive].m_bWriteProtected, |
| 463 | bCreateIfNecessary, |
| 464 | m_hardDiskDrive[iDrive].m_strFilenameInZip, // TODO: Use this |
| 465 | bExpectFloppy); |
| 466 | |
| 467 | m_hardDiskDrive[iDrive].m_imageloaded = (Error == eIMAGE_ERROR_NONE); |
| 468 | |
| 469 | m_hardDiskDrive[iDrive].m_status_next = DISK_STATUS_OFF; |
| 470 | m_hardDiskDrive[iDrive].m_status_prev = DISK_STATUS_OFF; |
| 471 | |
| 472 | if (Error == eIMAGE_ERROR_NONE) |
| 473 | { |
| 474 | GetImageTitle(pathname.c_str(), m_hardDiskDrive[iDrive].m_imagename, m_hardDiskDrive[iDrive].m_fullname); |
| 475 | Snapshot_UpdatePath(); |
| 476 | } |
| 477 | |
| 478 | SaveLastDiskImage(iDrive); |
| 479 | |
| 480 | return m_hardDiskDrive[iDrive].m_imageloaded; |