+ 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
This commit is contained in:
unknown
2015-05-01 07:06:29 +02:00
parent a205159d00
commit 46930855f5
19 changed files with 1443 additions and 1610 deletions

View File

@@ -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)