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

Function SFileFindFirstFile

extern/StormLib/src/SFileFindFile.cpp:383–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381// Public functions
382
383HANDLE WINAPI SFileFindFirstFile(HANDLE hMpq, const char * szMask, SFILE_FIND_DATA * lpFindFileData, const TCHAR * szListFile)
384{
385 TMPQArchive * ha = (TMPQArchive *)hMpq;
386 TMPQSearch * hs = NULL;
387 size_t nSize = 0;
388 DWORD dwErrCode = ERROR_SUCCESS;
389
390 // Check for the valid parameters
391 if(!IsValidMpqHandle(hMpq))
392 dwErrCode = ERROR_INVALID_HANDLE;
393 if(szMask == NULL || lpFindFileData == NULL)
394 dwErrCode = ERROR_INVALID_PARAMETER;
395
396 // Include the listfile into the MPQ's internal listfile
397 // Note that if the listfile name is NULL, do nothing because the
398 // internal listfile is always included.
399 if(dwErrCode == ERROR_SUCCESS && szListFile != NULL && *szListFile != 0)
400 dwErrCode = SFileAddListFile((HANDLE)ha, szListFile);
401
402 // Allocate the structure for MPQ search
403 if(dwErrCode == ERROR_SUCCESS)
404 {
405 nSize = sizeof(TMPQSearch) + strlen(szMask) + 1;
406 if((hs = (TMPQSearch *)STORM_ALLOC(char, nSize)) == NULL)
407 dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
408 }
409
410 // Perform the first search
411 if(dwErrCode == ERROR_SUCCESS)
412 {
413 memset(hs, 0, sizeof(TMPQSearch));
414 strcpy(hs->szSearchMask, szMask);
415 hs->dwFlagMask = MPQ_FILE_EXISTS;
416 hs->ha = ha;
417
418 // If the archive is patched archive, we have to create a merge table
419 // to prevent files being repeated
420 if(ha->haPatch != NULL)
421 {
422 hs->dwSearchTableItems = GetSearchTableItems(ha);
423 hs->pSearchTable = STORM_ALLOC(TFileEntry *, hs->dwSearchTableItems);
424 hs->dwFlagMask = MPQ_FILE_EXISTS | MPQ_FILE_PATCH_FILE;
425 if(hs->pSearchTable != NULL)
426 memset(hs->pSearchTable, 0, hs->dwSearchTableItems * sizeof(TFileEntry *));
427 else
428 dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
429 }
430 }
431
432 // Perform first item searching
433 if(dwErrCode == ERROR_SUCCESS)
434 {
435 dwErrCode = DoMPQSearch(hs, lpFindFileData);
436 }
437
438 // Cleanup
439 if(dwErrCode != ERROR_SUCCESS)
440 {

Callers 2

SearchArchiveFunction · 0.85
FindFilesMethod · 0.85

Calls 6

IsValidMpqHandleFunction · 0.85
SFileAddListFileFunction · 0.85
GetSearchTableItemsFunction · 0.85
DoMPQSearchFunction · 0.85
FreeMPQSearchFunction · 0.85
SetLastErrorFunction · 0.85

Tested by 1

SearchArchiveFunction · 0.68