MCPcopy Create free account
hub / github.com/Kenix3/libultraship / SFileOpenFileEx

Function SFileOpenFileEx

extern/StormLib/src/SFileOpenFileEx.cpp:232–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 15

GetFilePatchCountFunction · 0.85
CheckIfFileIsPresentFunction · 0.85
LoadMpqFileFunction · 0.85
TestOnLocalListFileFunction · 0.85
TestArchive_SetPosFunction · 0.85
TestArchive_PatchedFunction · 0.85
VerifyFileFunction · 0.85
IsMatchingPatchFileFunction · 0.85
InvalidateInternalFileFunction · 0.85
SFileRemoveFileFunction · 0.85

Calls 10

IsValidMpqHandleFunction · 0.85
GetFileEntryLocaleFunction · 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 8

GetFilePatchCountFunction · 0.68
CheckIfFileIsPresentFunction · 0.68
LoadMpqFileFunction · 0.68
TestOnLocalListFileFunction · 0.68
TestArchive_SetPosFunction · 0.68
TestArchive_PatchedFunction · 0.68