Saves MPQ header, hash table, block table and hi-block table.
| 2794 | |
| 2795 | // Saves MPQ header, hash table, block table and hi-block table. |
| 2796 | int SaveMPQTables(TMPQArchive * ha) |
| 2797 | { |
| 2798 | TMPQExtHeader * pHetTable = NULL; |
| 2799 | TMPQExtHeader * pBetTable = NULL; |
| 2800 | TMPQHeader * pHeader = ha->pHeader; |
| 2801 | TMPQBlock * pBlockTable = NULL; |
| 2802 | TMPQHash * pHashTable = NULL; |
| 2803 | ULONGLONG HetTableSize64 = 0; |
| 2804 | ULONGLONG BetTableSize64 = 0; |
| 2805 | ULONGLONG HashTableSize64 = 0; |
| 2806 | ULONGLONG BlockTableSize64 = 0; |
| 2807 | ULONGLONG HiBlockTableSize64 = 0; |
| 2808 | ULONGLONG TablePos = 0; // A table position, relative to the begin of the MPQ |
| 2809 | USHORT * pHiBlockTable = NULL; |
| 2810 | DWORD cbTotalSize; |
| 2811 | bool bNeedHiBlockTable = false; |
| 2812 | int nError = ERROR_SUCCESS; |
| 2813 | |
| 2814 | // We expect this function to be called only when tables have been changed |
| 2815 | assert(ha->dwFlags & MPQ_FLAG_CHANGED); |
| 2816 | |
| 2817 | // Find the space where the MPQ tables will be saved |
| 2818 | TablePos = FindFreeMpqSpace(ha); |
| 2819 | |
| 2820 | // If the MPQ has HET table, we prepare a ready-to-save version |
| 2821 | if(nError == ERROR_SUCCESS && ha->pHetTable != NULL) |
| 2822 | { |
| 2823 | pHetTable = TranslateHetTable(ha->pHetTable, &HetTableSize64); |
| 2824 | if(pHetTable == NULL) |
| 2825 | nError = ERROR_NOT_ENOUGH_MEMORY; |
| 2826 | } |
| 2827 | |
| 2828 | // If the MPQ has HET table, we also must create BET table to be saved |
| 2829 | if(nError == ERROR_SUCCESS && ha->pHetTable != NULL) |
| 2830 | { |
| 2831 | pBetTable = TranslateBetTable(ha, &BetTableSize64); |
| 2832 | if(pBetTable == NULL) |
| 2833 | nError = ERROR_NOT_ENOUGH_MEMORY; |
| 2834 | } |
| 2835 | |
| 2836 | // Now create hash table |
| 2837 | if(nError == ERROR_SUCCESS && ha->pHashTable != NULL) |
| 2838 | { |
| 2839 | pHashTable = TranslateHashTable(ha, &HashTableSize64); |
| 2840 | if(pHashTable == NULL) |
| 2841 | nError = ERROR_NOT_ENOUGH_MEMORY; |
| 2842 | } |
| 2843 | |
| 2844 | // Create block table |
| 2845 | if(nError == ERROR_SUCCESS && ha->pFileTable != NULL) |
| 2846 | { |
| 2847 | pBlockTable = TranslateBlockTable(ha, &BlockTableSize64, &bNeedHiBlockTable); |
| 2848 | if(pBlockTable == NULL) |
| 2849 | nError = ERROR_NOT_ENOUGH_MEMORY; |
| 2850 | } |
| 2851 | |
| 2852 | // Create hi-block table, if needed |
| 2853 | if(nError == ERROR_SUCCESS && bNeedHiBlockTable) |
no test coverage detected