MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / ImageOpen

Function ImageOpen

source/DiskImage.cpp:42–97  ·  view source on GitHub ↗

Pre: *pWriteProtected_ already set to file's r/w status - see DiskInsert()

Source from the content-addressed store, hash-verified

40
41// Pre: *pWriteProtected_ already set to file's r/w status - see DiskInsert()
42ImageError_e ImageOpen( const std::string & pszImageFilename,
43 ImageInfo** ppImageInfo,
44 bool* pWriteProtected,
45 const bool bCreateIfNecessary,
46 std::string& strFilenameInZip,
47 const bool bExpectFloppy /*=true*/)
48{
49 if (!(!pszImageFilename.empty() && ppImageInfo && pWriteProtected))
50 return eIMAGE_ERROR_BAD_POINTER;
51
52 // CREATE A RECORD FOR THE FILE
53 *ppImageInfo = new ImageInfo();
54
55 ImageInfo* pImageInfo = *ppImageInfo;
56 pImageInfo->bWriteProtected = *pWriteProtected;
57 if (bExpectFloppy) pImageInfo->pImageHelper = &sg_DiskImageHelper;
58 else pImageInfo->pImageHelper = &sg_HardDiskImageHelper;
59
60 ImageError_e Err = pImageInfo->pImageHelper->Open(pszImageFilename.c_str(), pImageInfo, bCreateIfNecessary, strFilenameInZip);
61 if (Err != eIMAGE_ERROR_NONE)
62 {
63 ImageClose(*ppImageInfo);
64 *ppImageInfo = NULL;
65 return Err;
66 }
67
68 if (pImageInfo->pImageType && pImageInfo->pImageType->GetType() == eImageHDV)
69 {
70 if (bExpectFloppy)
71 {
72 ImageClose(*ppImageInfo);
73 *ppImageInfo = NULL;
74 Err = eIMAGE_ERROR_UNSUPPORTED_HDV;
75 }
76
77 if (Err == eIMAGE_ERROR_NONE)
78 *pWriteProtected = pImageInfo->bWriteProtected;
79
80 return Err;
81 }
82
83 // THE FILE MATCHES A KNOWN FORMAT
84
85 _ASSERT(bExpectFloppy);
86 const eImageType type = pImageInfo->pImageType ? pImageInfo->pImageType->GetType() : eImageUNKNOWN;
87 if (!bExpectFloppy || (!pImageInfo->uNumTracks && type != eImageAPL && type != eImagePRG))
88 {
89 ImageClose(*ppImageInfo);
90 *ppImageInfo = NULL;
91 return eIMAGE_ERROR_UNSUPPORTED;
92 }
93
94 *pWriteProtected = pImageInfo->bWriteProtected;
95
96 return eIMAGE_ERROR_NONE;
97}
98
99//===========================================================================

Callers 2

InsertDiskMethod · 0.85
InsertMethod · 0.85

Calls 3

ImageCloseFunction · 0.85
OpenMethod · 0.80
GetTypeMethod · 0.45

Tested by

no test coverage detected