Pre: pathname likely to include path (but can also just be filename)
| 825 | |
| 826 | // Pre: pathname likely to include path (but can also just be filename) |
| 827 | ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, const std::string& pathname, const bool bForceWriteProtected, const bool bCreateIfNecessary) |
| 828 | { |
| 829 | FloppyDrive* pDrive = &m_floppyDrive[drive]; |
| 830 | FloppyDisk* pFloppy = &pDrive->m_disk; |
| 831 | |
| 832 | if (pFloppy->m_imagehandle) |
| 833 | EjectDisk(drive); |
| 834 | |
| 835 | // Reset the disk's attributes, but preserve the drive's attributes (GH#138/Platoon, GH#640) |
| 836 | // . Changing the disk (in the drive) doesn't affect the drive's attributes. |
| 837 | pFloppy->clear(); |
| 838 | |
| 839 | if (pathname.empty()) |
| 840 | return eIMAGE_ERROR_NONE; |
| 841 | |
| 842 | const DWORD dwAttributes = GetFileAttributes(pathname.c_str()); |
| 843 | if (dwAttributes == INVALID_FILE_ATTRIBUTES) |
| 844 | pFloppy->m_bWriteProtected = false; // Assume this is a new file to create (so it must be write-enabled to allow it to be formatted) |
| 845 | else |
| 846 | pFloppy->m_bWriteProtected = bForceWriteProtected ? true : (dwAttributes & FILE_ATTRIBUTE_READONLY); |
| 847 | |
| 848 | // Check if image is being used by the other drive, and if so remove it in order so it can be swapped |
| 849 | { |
| 850 | const std::string & pszOtherPathname = DiskGetFullPathName(!drive); |
| 851 | |
| 852 | char szCurrentPathname[MAX_PATH]; |
| 853 | DWORD uNameLen = GetFullPathName(pathname.c_str(), MAX_PATH, szCurrentPathname, NULL); |
| 854 | if (uNameLen == 0 || uNameLen >= MAX_PATH) |
| 855 | strcpy_s(szCurrentPathname, MAX_PATH, pathname.c_str()); |
| 856 | |
| 857 | if (!strcmp(pszOtherPathname.c_str(), szCurrentPathname)) |
| 858 | { |
| 859 | EjectDisk(!drive); |
| 860 | GetFrame().FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES | DRAW_DISK_STATUS); |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | ImageError_e Error = ImageOpen(pathname, |
| 865 | &pFloppy->m_imagehandle, |
| 866 | &pFloppy->m_bWriteProtected, |
| 867 | bCreateIfNecessary, |
| 868 | pFloppy->m_strFilenameInZip); |
| 869 | |
| 870 | if (Error == eIMAGE_ERROR_NONE && ImageIsMultiFileZip(pFloppy->m_imagehandle)) |
| 871 | { |
| 872 | std::string strText = StrFormat("Only the first file in a multi-file zip is supported\n" |
| 873 | "Use disk image '%s' ?", |
| 874 | pFloppy->m_strFilenameInZip.c_str()); |
| 875 | int nRes = GetFrame().FrameMessageBox(strText.c_str(), "Multi-Zip Warning", MB_ICONWARNING | MB_YESNO | MB_SETFOREGROUND); |
| 876 | if (nRes == IDNO) |
| 877 | { |
| 878 | EjectDisk(drive); |
| 879 | Error = eIMAGE_ERROR_REJECTED_MULTI_ZIP; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | if (Error == eIMAGE_ERROR_NONE) |
| 884 | { |
no test coverage detected