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

Function SFileFindFirstFile

3rdParty/StormLib/src/SFileFindFile.cpp:381–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379// Public functions
380
381HANDLE STORMAPI SFileFindFirstFile(HANDLE hMpq, const char * szMask, SFILE_FIND_DATA * lpFindFileData, const TCHAR * szListFile)
382{
383 TMPQArchive * ha = (TMPQArchive *)hMpq;
384 TMPQSearch * hs = NULL;
385 size_t nSize = 0;
386 int nError = ERROR_SUCCESS;
387
388 // Check for the valid parameters
389 if(!IsValidMpqHandle(hMpq))
390 nError = ERROR_INVALID_HANDLE;
391 if(szMask == NULL || lpFindFileData == NULL)
392 nError = ERROR_INVALID_PARAMETER;
393
394#ifdef FULL
395 // Include the listfile into the MPQ's internal listfile
396 // Note that if the listfile name is NULL, do nothing because the
397 // internal listfile is always included.
398 if(nError == ERROR_SUCCESS && szListFile != NULL && *szListFile != 0)
399 nError = SFileAddListFile((HANDLE)ha, szListFile);
400#endif
401
402 // Allocate the structure for MPQ search
403 if(nError == ERROR_SUCCESS)
404 {
405 nSize = sizeof(TMPQSearch) + strlen(szMask) + 1;
406 if((hs = (TMPQSearch *)STORM_ALLOC(char, nSize)) == NULL)
407 nError = ERROR_NOT_ENOUGH_MEMORY;
408 }
409
410 // Perform the first search
411 if(nError == 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 nError = ERROR_NOT_ENOUGH_MEMORY;
429 }
430 }
431
432 // Perform first item searching
433 if(nError == ERROR_SUCCESS)
434 {
435 nError = DoMPQSearch(hs, lpFindFileData);
436 }
437
438 // Cleanup

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected