aboutsummaryrefslogtreecommitdiff
path: root/src/SBaseFileTable.cpp
diff options
context:
space:
mode:
authorLadislav Zezula <zezula@volny.cz>2016-05-18 20:35:11 +0200
committerLadislav Zezula <zezula@volny.cz>2016-05-18 20:35:11 +0200
commitb86b4e7f6385ced4b34c1c84785ac5dc19be660f (patch)
treef18abed6d3ed9f718ebd9521acab3338c9470b09 /src/SBaseFileTable.cpp
parent3224eac75e07dd198d60fb754d408fa1861ec3f0 (diff)
+ Fixed bug on compacting archive
Diffstat (limited to 'src/SBaseFileTable.cpp')
-rw-r--r--src/SBaseFileTable.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp
index 43c68a0..49e4de2 100644
--- a/src/SBaseFileTable.cpp
+++ b/src/SBaseFileTable.cpp
@@ -785,7 +785,7 @@ static int BuildFileTableFromBlockTable(
// Determine the new block index
if(DefragmentTable != NULL)
{
- // Need to handle case when multile hash
+ // Need to handle case when multiple hash
// entries point to the same block entry
if(DefragmentTable[dwBlockIndex] == HASH_ENTRY_FREE)
{
@@ -2602,6 +2602,13 @@ int DefragmentFileTable(TMPQArchive * ha)
// Update the block table size
dwBlockTableSize = (DWORD)(pSource - ha->pFileTable) + 1;
}
+ else
+ {
+ // If there is file name left, free it
+ if(pSource->szFileName != NULL)
+ STORM_FREE(pSource->szFileName);
+ pSource->szFileName = NULL;
+ }
}
// Did we defragment something?
@@ -2615,14 +2622,17 @@ int DefragmentFileTable(TMPQArchive * ha)
{
TMPQHash * pHashTableEnd = ha->pHashTable + ha->pHeader->dwHashTableSize;
TMPQHash * pHash;
+ DWORD dwNewBlockIndex;
for(pHash = ha->pHashTable; pHash < pHashTableEnd; pHash++)
{
if(pHash->dwBlockIndex < ha->dwFileTableSize)
- {
- assert(DefragmentTable[pHash->dwBlockIndex] != HASH_ENTRY_FREE);
- pHash->dwBlockIndex = DefragmentTable[pHash->dwBlockIndex];
- }
+ {
+ // If that block entry is there, set it to the hash entry
+ // If not, set it as DELETED
+ dwNewBlockIndex = DefragmentTable[pHash->dwBlockIndex];
+ pHash->dwBlockIndex = (dwNewBlockIndex != HASH_ENTRY_FREE) ? dwNewBlockIndex : HASH_ENTRY_DELETED;
+ }
}
}
}