diff options
author | unknown <E:\Ladik\Mail> | 2015-05-01 07:06:29 +0200 |
---|---|---|
committer | unknown <E:\Ladik\Mail> | 2015-05-01 07:06:29 +0200 |
commit | 46930855f500c1b494e3b16bb7a3323c07d4d5fb (patch) | |
tree | 6220cc643761137a930841d8ec828db9f3db53cf /src/SFileOpenArchive.cpp | |
parent | a205159d004871efbedd7cbfb686b8fe82bfb532 (diff) |
+ Removed back reference of FileTable -> HashTable, as it is logically incorrect
+ Optimized patching process so it consimes less memory
+ Added hash table and block table defragmenting for malformed War3 maps
Diffstat (limited to 'src/SFileOpenArchive.cpp')
-rw-r--r-- | src/SFileOpenArchive.cpp | 61 |
1 files changed, 10 insertions, 51 deletions
diff --git a/src/SFileOpenArchive.cpp b/src/SFileOpenArchive.cpp index ffd5bfe..5ce4290 100644 --- a/src/SFileOpenArchive.cpp +++ b/src/SFileOpenArchive.cpp @@ -339,8 +339,9 @@ bool WINAPI SFileOpenArchive( ha->UserDataPos = SearchOffset; // Set the position of the MPQ header - ha->pHeader = (TMPQHeader *)ha->HeaderData; - ha->MpqPos = SearchOffset; + ha->pHeader = (TMPQHeader *)ha->HeaderData; + ha->MpqPos = SearchOffset; + ha->FileSize = FileSize; // Sector size must be nonzero. if(SearchOffset >= FileSize || ha->pHeader->wSectorSize == 0) @@ -395,14 +396,6 @@ bool WINAPI SFileOpenArchive( nError = BuildFileTable(ha); } - // We now have both hash table and block table loaded. - // If any malformation was detected in the MPQ, - // we perform hash table and block table validation (and eventual defragmentation) - if(nError == ERROR_SUCCESS && ha->pHeader->wFormatVersion == MPQ_FORMAT_VERSION_1 && (ha->dwFlags & MPQ_FLAG_MALFORMED)) - { - nError = ShrinkMalformedMpqTables(ha); - } - // Load the internal listfile and include it to the file table if(nError == ERROR_SUCCESS && (dwFlags & MPQ_OPEN_NO_LISTFILE) == 0) { @@ -492,7 +485,6 @@ bool WINAPI SFileSetDownloadCallback(HANDLE hMpq, SFILE_DOWNLOAD_CALLBACK Downlo bool WINAPI SFileFlushArchive(HANDLE hMpq) { - TFileEntry * pFileEntry; TMPQArchive * ha; int nResultError = ERROR_SUCCESS; int nError; @@ -510,44 +502,7 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq) // Indicate that we are saving MPQ internal structures ha->dwFlags |= MPQ_FLAG_SAVING_TABLES; - // - // Invalidate entries for each internal file - // - - if(ha->dwFlags & MPQ_FLAG_LISTFILE_INVALID) - { - pFileEntry = GetFileEntryExact(ha, LISTFILE_NAME, LANG_NEUTRAL); - if(pFileEntry != NULL) - { - DeleteFileEntry(ha, pFileEntry); - ha->dwReservedFiles++; - } - } - - if(ha->dwFlags & MPQ_FLAG_ATTRIBUTES_INVALID) - { - pFileEntry = GetFileEntryExact(ha, ATTRIBUTES_NAME, LANG_NEUTRAL); - if(pFileEntry != NULL) - { - DeleteFileEntry(ha, pFileEntry); - ha->dwReservedFiles++; - } - } - - if(ha->dwFlags & MPQ_FLAG_SIGNATURE_INVALID) - { - pFileEntry = GetFileEntryExact(ha, SIGNATURE_NAME, LANG_NEUTRAL); - if(pFileEntry != NULL) - { - DeleteFileEntry(ha, pFileEntry); - ha->dwReservedFiles++; - } - } - - // // Defragment the file table. This will allow us to put the internal files to the end - // - DefragmentFileTable(ha); // @@ -555,21 +510,21 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq) // Note that the (signature) file is usually before (listfile) in the file table // - if(ha->dwFlags & MPQ_FLAG_SIGNATURE_INVALID) + if(ha->dwFlags & MPQ_FLAG_SIGNATURE_NEW) { nError = SSignFileCreate(ha); if(nError != ERROR_SUCCESS) nResultError = nError; } - if(ha->dwFlags & MPQ_FLAG_LISTFILE_INVALID) + if(ha->dwFlags & MPQ_FLAG_LISTFILE_NEW) { nError = SListFileSaveToMpq(ha); if(nError != ERROR_SUCCESS) nResultError = nError; } - if(ha->dwFlags & MPQ_FLAG_ATTRIBUTES_INVALID) + if(ha->dwFlags & MPQ_FLAG_ATTRIBUTES_NEW) { nError = SAttrFileSaveToMpq(ha); if(nError != ERROR_SUCCESS) @@ -579,6 +534,10 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq) // Save HET table, BET table, hash table, block table, hi-block table if(ha->dwFlags & MPQ_FLAG_CHANGED) { + // Rebuild the HET table + if(ha->pHetTable != NULL) + RebuildHetTable(ha); + // Save all MPQ tables first nError = SaveMPQTables(ha); if(nError != ERROR_SUCCESS) |