MCPcopy Create free account
hub / github.com/diasurgical/devilution / SFileOpenFileEx

Function SFileOpenFileEx

3rdParty/StormLib/src/SFileOpenFileEx.cpp:231–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229// PtrFile - Pointer to store opened file handle
230
231bool STORMAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearchScope, HANDLE * PtrFile)
232{
233 TMPQArchive * ha = IsValidMpqHandle(hMpq);
234 TFileEntry * pFileEntry = NULL;
235 TMPQFile * hf = NULL;
236 DWORD dwHashIndex = HASH_ENTRY_FREE;
237 DWORD dwFileIndex = 0;
238 bool bOpenByIndex = false;
239 int nError = ERROR_SUCCESS;
240
241 // Don't accept NULL pointer to file handle
242 if(szFileName == NULL || *szFileName == 0)
243 nError = ERROR_INVALID_PARAMETER;
244
245 // When opening a file from MPQ, the handle must be valid
246 if(dwSearchScope != SFILE_OPEN_LOCAL_FILE && ha == NULL)
247 nError = ERROR_INVALID_HANDLE;
248
249 // When not checking for existence, the pointer to file handle must be valid
250 if(dwSearchScope != SFILE_OPEN_CHECK_EXISTS && PtrFile == NULL)
251 nError = ERROR_INVALID_PARAMETER;
252
253 // Prepare the file opening
254 if(nError == ERROR_SUCCESS)
255 {
256 switch(dwSearchScope)
257 {
258 case SFILE_OPEN_FROM_MPQ:
259 case SFILE_OPEN_BASE_FILE:
260 case SFILE_OPEN_CHECK_EXISTS:
261
262 // If this MPQ has no patches, open the file from this MPQ directly
263 if(ha->haPatch == NULL || dwSearchScope == SFILE_OPEN_BASE_FILE)
264 {
265 pFileEntry = GetFileEntryLocale2(ha, szFileName, lcFileLocale, &dwHashIndex);
266 }
267
268 // If this MPQ is a patched archive, open the file as patched
269 else
270 {
271 return OpenPatchedFile(hMpq, szFileName, PtrFile);
272 }
273 break;
274
275 case SFILE_OPEN_ANY_LOCALE:
276
277 // This open option is reserved for opening MPQ internal listfile.
278 // No argument validation. Tries to open file with neutral locale first,
279 // then any other available.
280 pFileEntry = GetFileEntryLocale2(ha, szFileName, 0, &dwHashIndex);
281 break;
282
283 case SFILE_OPEN_LOCAL_FILE:
284
285 // Open a local file
286 return OpenLocalFile(szFileName, PtrFile);
287
288 default:

Callers 9

SFileOpenFileFunction · 0.85
pfile_read_heroFunction · 0.85
pfile_readFunction · 0.85
InvalidateInternalFileFunction · 0.85
SFileExtractFileFunction · 0.85
OpenPatchedFileFunction · 0.85
SFileHasFileFunction · 0.85
DoMPQSearch_FileEntryFunction · 0.85

Calls 10

IsValidMpqHandleFunction · 0.85
GetFileEntryLocale2Function · 0.85
OpenPatchedFileFunction · 0.85
OpenLocalFileFunction · 0.85
IsPseudoFileNameFunction · 0.85
CreateFileHandleFunction · 0.85
FindHashIndexFunction · 0.85
AllocateFileNameFunction · 0.85
DecryptFileKeyFunction · 0.85
SetLastErrorFunction · 0.85

Tested by

no test coverage detected