| 2533 | #endif |
| 2534 | |
| 2535 | int BuildFileTable(TMPQArchive * ha) |
| 2536 | { |
| 2537 | DWORD dwFileTableSize; |
| 2538 | bool bFileTableCreated = false; |
| 2539 | |
| 2540 | // Sanity checks |
| 2541 | assert(ha->pFileTable == NULL); |
| 2542 | assert(ha->dwFileTableSize == 0); |
| 2543 | assert(ha->dwMaxFileCount != 0); |
| 2544 | |
| 2545 | // Determine the allocation size for the file table |
| 2546 | dwFileTableSize = STORMLIB_MAX(ha->pHeader->dwBlockTableSize, ha->dwMaxFileCount); |
| 2547 | |
| 2548 | // Allocate the file table with size determined before |
| 2549 | ha->pFileTable = STORM_ALLOC(TFileEntry, dwFileTableSize); |
| 2550 | if(ha->pFileTable == NULL) |
| 2551 | return ERROR_NOT_ENOUGH_MEMORY; |
| 2552 | |
| 2553 | // Fill the table with zeros |
| 2554 | memset(ha->pFileTable, 0, dwFileTableSize * sizeof(TFileEntry)); |
| 2555 | ha->dwFileTableSize = dwFileTableSize; |
| 2556 | |
| 2557 | #ifdef FULL |
| 2558 | // If we have HET table, we load file table from the BET table |
| 2559 | // Note: If BET table is corrupt or missing, we set the archive as read only |
| 2560 | if(ha->pHetTable != NULL) |
| 2561 | { |
| 2562 | if(BuildFileTable_HetBet(ha) != ERROR_SUCCESS) |
| 2563 | ha->dwFlags |= MPQ_FLAG_READ_ONLY; |
| 2564 | else |
| 2565 | bFileTableCreated = true; |
| 2566 | } |
| 2567 | #endif |
| 2568 | |
| 2569 | // If we have hash table, we load the file table from the block table |
| 2570 | // Note: If block table is corrupt or missing, we set the archive as read only |
| 2571 | if(ha->pHashTable != NULL) |
| 2572 | { |
| 2573 | if(BuildFileTable_Classic(ha) != ERROR_SUCCESS) |
| 2574 | ha->dwFlags |= MPQ_FLAG_READ_ONLY; |
| 2575 | else |
| 2576 | bFileTableCreated = true; |
| 2577 | } |
| 2578 | |
| 2579 | // Return result |
| 2580 | return bFileTableCreated ? ERROR_SUCCESS : ERROR_FILE_CORRUPT; |
| 2581 | } |
| 2582 | |
| 2583 | /* |
| 2584 | void UpdateBlockTableSize(TMPQArchive * ha) |
no test coverage detected