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

Function BuildFileTable

extern/StormLib/src/SBaseFileTable.cpp:2696–2740  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2694}
2695
2696DWORD BuildFileTable(TMPQArchive * ha)
2697{
2698 DWORD dwFileTableSize;
2699 bool bFileTableCreated = false;
2700
2701 // Sanity checks
2702 assert(ha->pFileTable == NULL);
2703 assert(ha->dwFileTableSize == 0);
2704 assert(ha->dwMaxFileCount != 0);
2705
2706 // Determine the allocation size for the file table
2707 dwFileTableSize = STORMLIB_MAX(ha->pHeader->dwBlockTableSize, ha->dwMaxFileCount);
2708
2709 // Allocate the file table with size determined before
2710 ha->pFileTable = STORM_ALLOC(TFileEntry, dwFileTableSize);
2711 if(ha->pFileTable == NULL)
2712 return ERROR_NOT_ENOUGH_MEMORY;
2713
2714 // Fill the table with zeros
2715 memset(ha->pFileTable, 0, dwFileTableSize * sizeof(TFileEntry));
2716 ha->dwFileTableSize = dwFileTableSize;
2717
2718 // If we have HET table, we load file table from the BET table
2719 // Note: If BET table is corrupt or missing, we set the archive as read only
2720 if(ha->pHetTable != NULL)
2721 {
2722 if(BuildFileTable_HetBet(ha) != ERROR_SUCCESS)
2723 ha->dwFlags |= MPQ_FLAG_READ_ONLY;
2724 else
2725 bFileTableCreated = true;
2726 }
2727
2728 // If we have hash table, we load the file table from the block table
2729 // Note: If block table is corrupt or missing, we set the archive as read only
2730 if(ha->pHashTable != NULL)
2731 {
2732 if(BuildFileTable_Classic(ha) != ERROR_SUCCESS)
2733 ha->dwFlags |= MPQ_FLAG_READ_ONLY;
2734 else
2735 bFileTableCreated = true;
2736 }
2737
2738 // Return result
2739 return bFileTableCreated ? ERROR_SUCCESS : ERROR_FILE_CORRUPT;
2740}
2741
2742/*
2743void UpdateBlockTableSize(TMPQArchive * ha)

Callers 1

SFileOpenArchiveFunction · 0.85

Calls 2

BuildFileTable_HetBetFunction · 0.85
BuildFileTable_ClassicFunction · 0.85

Tested by

no test coverage detected