Rebuilds the HET table from scratch based on the file table Used after a modifying operation (add, rename, delete)
| 2686 | // Rebuilds the HET table from scratch based on the file table |
| 2687 | // Used after a modifying operation (add, rename, delete) |
| 2688 | int RebuildHetTable(TMPQArchive * ha) |
| 2689 | { |
| 2690 | TMPQHetTable * pOldHetTable = ha->pHetTable; |
| 2691 | TFileEntry * pFileTableEnd; |
| 2692 | TFileEntry * pFileEntry; |
| 2693 | DWORD dwBlockTableSize = ha->dwFileTableSize; |
| 2694 | int nError = ERROR_SUCCESS; |
| 2695 | |
| 2696 | // If we are in the state of saving MPQ tables, the real size of block table |
| 2697 | // must already have been calculated. Use that value instead |
| 2698 | if(ha->dwFlags & MPQ_FLAG_SAVING_TABLES) |
| 2699 | { |
| 2700 | assert(ha->pHeader->dwBlockTableSize != 0); |
| 2701 | dwBlockTableSize = ha->pHeader->dwBlockTableSize; |
| 2702 | } |
| 2703 | |
| 2704 | // Create new HET table based on the total number of entries in the file table |
| 2705 | // Note that if we fail to create it, we just stop using HET table |
| 2706 | ha->pHetTable = CreateHetTable(dwBlockTableSize, 0, 0x40, NULL); |
| 2707 | if(ha->pHetTable != NULL) |
| 2708 | { |
| 2709 | // Go through the file table again and insert all existing files |
| 2710 | pFileTableEnd = ha->pFileTable + dwBlockTableSize; |
| 2711 | for(pFileEntry = ha->pFileTable; pFileEntry < pFileTableEnd; pFileEntry++) |
| 2712 | { |
| 2713 | if(pFileEntry->dwFlags & MPQ_FILE_EXISTS) |
| 2714 | { |
| 2715 | // Get the high |
| 2716 | nError = InsertHetEntry(ha->pHetTable, pFileEntry->FileNameHash, (DWORD)(pFileEntry - ha->pFileTable)); |
| 2717 | if(nError != ERROR_SUCCESS) |
| 2718 | break; |
| 2719 | } |
| 2720 | } |
| 2721 | } |
| 2722 | |
| 2723 | // Free the old HET table |
| 2724 | FreeHetTable(pOldHetTable); |
| 2725 | return nError; |
| 2726 | } |
| 2727 | |
| 2728 | // Rebuilds the file table, removing all deleted file entries. |
| 2729 | // Used when compacting the archive |
no test coverage detected