mirror of
https://github.com/ladislav-zezula/StormLib.git
synced 2026-01-20 14:47:22 +01:00
nError -> dwErrCode
This commit is contained in:
@@ -427,7 +427,7 @@ ULONGLONG CalculateRawSectorOffset(
|
||||
}
|
||||
|
||||
// This function converts the MPQ header so it always looks like version 4
|
||||
int ConvertMpqHeaderToFormat4(
|
||||
DWORD ConvertMpqHeaderToFormat4(
|
||||
TMPQArchive * ha,
|
||||
ULONGLONG ByteOffset,
|
||||
ULONGLONG FileSize,
|
||||
@@ -442,7 +442,7 @@ int ConvertMpqHeaderToFormat4(
|
||||
USHORT wFormatVersion = BSWAP_INT16_UNSIGNED(pHeader->wFormatVersion);
|
||||
bool bHashBlockOffsetOK = false;
|
||||
bool bHetBetOffsetOK = false;
|
||||
int nError = ERROR_SUCCESS;
|
||||
DWORD dwErrCode = ERROR_SUCCESS;
|
||||
|
||||
// If version 1.0 is forced, then the format version is forced to be 1.0
|
||||
// Reason: Storm.dll in Warcraft III ignores format version value
|
||||
@@ -721,7 +721,7 @@ int ConvertMpqHeaderToFormat4(
|
||||
// Used by BOBA protector
|
||||
if(BlockTablePos64 < ByteOffset)
|
||||
ha->dwFlags |= MPQ_FLAG_MALFORMED;
|
||||
return nError;
|
||||
return dwErrCode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -882,7 +882,7 @@ static TMPQHash * DefragmentHashTable(
|
||||
return pHashTable;
|
||||
}
|
||||
|
||||
static int BuildFileTableFromBlockTable(
|
||||
static DWORD BuildFileTableFromBlockTable(
|
||||
TMPQArchive * ha,
|
||||
TMPQBlock * pBlockTable)
|
||||
{
|
||||
@@ -1167,7 +1167,7 @@ TMPQExtHeader * LoadExtTable(
|
||||
return pExtTable;
|
||||
}
|
||||
|
||||
static int SaveMpqTable(
|
||||
static DWORD SaveMpqTable(
|
||||
TMPQArchive * ha,
|
||||
void * pMpqTable,
|
||||
ULONGLONG ByteOffset,
|
||||
@@ -1178,7 +1178,7 @@ static int SaveMpqTable(
|
||||
{
|
||||
ULONGLONG FileOffset;
|
||||
void * pCompressed = NULL;
|
||||
int nError = ERROR_SUCCESS;
|
||||
DWORD dwErrCode = ERROR_SUCCESS;
|
||||
|
||||
// Do we have to compress the table?
|
||||
if(bCompress)
|
||||
@@ -1224,15 +1224,15 @@ static int SaveMpqTable(
|
||||
BSWAP_ARRAY32_UNSIGNED(pMpqTable, Size);
|
||||
FileOffset = ha->MpqPos + ByteOffset;
|
||||
if(!FileStream_Write(ha->pStream, &FileOffset, pMpqTable, (DWORD)Size))
|
||||
nError = GetLastError();
|
||||
dwErrCode = GetLastError();
|
||||
|
||||
// Free the compressed table, if any
|
||||
if(pCompressed != NULL)
|
||||
STORM_FREE(pCompressed);
|
||||
return nError;
|
||||
return dwErrCode;
|
||||
}
|
||||
|
||||
static int SaveExtTable(
|
||||
static DWORD SaveExtTable(
|
||||
TMPQArchive * ha,
|
||||
TMPQExtHeader * pExtTable,
|
||||
ULONGLONG ByteOffset,
|
||||
@@ -1245,7 +1245,7 @@ static int SaveExtTable(
|
||||
ULONGLONG FileOffset;
|
||||
TMPQExtHeader * pCompressed = NULL;
|
||||
DWORD cbTotalSize = 0;
|
||||
int nError = ERROR_SUCCESS;
|
||||
DWORD dwErrCode = ERROR_SUCCESS;
|
||||
|
||||
// Do we have to compress the table?
|
||||
if(bCompress)
|
||||
@@ -1295,12 +1295,12 @@ static int SaveExtTable(
|
||||
if(FileStream_Write(ha->pStream, &FileOffset, pExtTable, dwTableSize))
|
||||
cbTotalSize += dwTableSize;
|
||||
else
|
||||
nError = GetLastError();
|
||||
dwErrCode = GetLastError();
|
||||
|
||||
// We have to write raw data MD5
|
||||
if(nError == ERROR_SUCCESS && ha->pHeader->dwRawChunkSize != 0)
|
||||
if(dwErrCode == ERROR_SUCCESS && ha->pHeader->dwRawChunkSize != 0)
|
||||
{
|
||||
nError = WriteMemDataMD5(ha->pStream,
|
||||
dwErrCode = WriteMemDataMD5(ha->pStream,
|
||||
FileOffset,
|
||||
pExtTable,
|
||||
dwTableSize,
|
||||
@@ -1315,7 +1315,7 @@ static int SaveExtTable(
|
||||
// Free the compressed table, if any
|
||||
if(pCompressed != NULL)
|
||||
STORM_FREE(pCompressed);
|
||||
return nError;
|
||||
return dwErrCode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -1411,7 +1411,7 @@ TMPQHetTable * CreateHetTable(DWORD dwEntryCount, DWORD dwTotalCount, DWORD dwNa
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int InsertHetEntry(TMPQHetTable * pHetTable, ULONGLONG FileNameHash, DWORD dwFileIndex)
|
||||
static DWORD InsertHetEntry(TMPQHetTable * pHetTable, ULONGLONG FileNameHash, DWORD dwFileIndex)
|
||||
{
|
||||
DWORD StartIndex;
|
||||
DWORD Index;
|
||||
@@ -2123,7 +2123,7 @@ TFileEntry * AllocateFileEntry(TMPQArchive * ha, const char * szFileName, LCID l
|
||||
return pFreeEntry;
|
||||
}
|
||||
|
||||
int RenameFileEntry(
|
||||
DWORD RenameFileEntry(
|
||||
TMPQArchive * ha,
|
||||
TMPQFile * hf,
|
||||
const char * szNewFileName)
|
||||
@@ -2171,7 +2171,7 @@ int RenameFileEntry(
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int DeleteFileEntry(TMPQArchive * ha, TMPQFile * hf)
|
||||
DWORD DeleteFileEntry(TMPQArchive * ha, TMPQFile * hf)
|
||||
{
|
||||
TFileEntry * pFileEntry = hf->pFileEntry;
|
||||
TMPQHash * pHashEntry = hf->pHashEntry;
|
||||
@@ -2214,7 +2214,7 @@ DWORD InvalidateInternalFile(TMPQArchive * ha, const char * szFileName, DWORD dw
|
||||
{
|
||||
TMPQFile * hf = NULL;
|
||||
DWORD dwFileFlags = MPQ_FILE_DEFAULT_INTERNAL;
|
||||
int nError = ERROR_FILE_NOT_FOUND;
|
||||
DWORD dwErrCode = ERROR_FILE_NOT_FOUND;
|
||||
|
||||
// Open the file from the MPQ
|
||||
if(SFileOpenFileEx((HANDLE)ha, szFileName, SFILE_OPEN_BASE_FILE, (HANDLE *)&hf))
|
||||
@@ -2223,8 +2223,8 @@ DWORD InvalidateInternalFile(TMPQArchive * ha, const char * szFileName, DWORD dw
|
||||
dwFileFlags = hf->pFileEntry->dwFlags;
|
||||
|
||||
// Delete the file entry
|
||||
nError = DeleteFileEntry(ha, hf);
|
||||
if(nError == ERROR_SUCCESS)
|
||||
dwErrCode = DeleteFileEntry(ha, hf);
|
||||
if(dwErrCode == ERROR_SUCCESS)
|
||||
dwForceAddTheFile = 1;
|
||||
|
||||
// Close the file
|
||||
@@ -2284,7 +2284,7 @@ void InvalidateInternalFiles(TMPQArchive * ha)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Support for file tables - hash table, block table, hi-block table
|
||||
|
||||
int CreateHashTable(TMPQArchive * ha, DWORD dwHashTableSize)
|
||||
DWORD CreateHashTable(TMPQArchive * ha, DWORD dwHashTableSize)
|
||||
{
|
||||
TMPQHash * pHashTable;
|
||||
|
||||
@@ -2359,7 +2359,7 @@ static TMPQHash * LoadHashTable(TMPQArchive * ha)
|
||||
return pHashTable;
|
||||
}
|
||||
|
||||
int CreateFileTable(TMPQArchive * ha, DWORD dwFileTableSize)
|
||||
DWORD CreateFileTable(TMPQArchive * ha, DWORD dwFileTableSize)
|
||||
{
|
||||
ha->pFileTable = STORM_ALLOC(TFileEntry, dwFileTableSize);
|
||||
if(ha->pFileTable == NULL)
|
||||
@@ -2465,7 +2465,7 @@ TMPQBetTable * LoadBetTable(TMPQArchive * ha)
|
||||
return pBetTable;
|
||||
}
|
||||
|
||||
int LoadAnyHashTable(TMPQArchive * ha)
|
||||
DWORD LoadAnyHashTable(TMPQArchive * ha)
|
||||
{
|
||||
TMPQHeader * pHeader = ha->pHeader;
|
||||
|
||||
@@ -2494,11 +2494,11 @@ int LoadAnyHashTable(TMPQArchive * ha)
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static int BuildFileTable_Classic(TMPQArchive * ha)
|
||||
static DWORD BuildFileTable_Classic(TMPQArchive * ha)
|
||||
{
|
||||
TMPQHeader * pHeader = ha->pHeader;
|
||||
TMPQBlock * pBlockTable;
|
||||
int nError = ERROR_SUCCESS;
|
||||
DWORD dwErrCode = ERROR_SUCCESS;
|
||||
|
||||
// Sanity checks
|
||||
assert(ha->pHashTable != NULL);
|
||||
@@ -2514,16 +2514,16 @@ static int BuildFileTable_Classic(TMPQArchive * ha)
|
||||
pBlockTable = (TMPQBlock *)LoadBlockTable(ha);
|
||||
if(pBlockTable != NULL)
|
||||
{
|
||||
nError = BuildFileTableFromBlockTable(ha, pBlockTable);
|
||||
dwErrCode = BuildFileTableFromBlockTable(ha, pBlockTable);
|
||||
STORM_FREE(pBlockTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
nError = ERROR_NOT_ENOUGH_MEMORY;
|
||||
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
// Load the hi-block table
|
||||
if(nError == ERROR_SUCCESS && pHeader->HiBlockTablePos64 != 0)
|
||||
if(dwErrCode == ERROR_SUCCESS && pHeader->HiBlockTablePos64 != 0)
|
||||
{
|
||||
ULONGLONG ByteOffset;
|
||||
USHORT * pHiBlockTable = NULL;
|
||||
@@ -2537,10 +2537,10 @@ static int BuildFileTable_Classic(TMPQArchive * ha)
|
||||
// Load the hi-block table. It is not encrypted, nor compressed
|
||||
ByteOffset = ha->MpqPos + pHeader->HiBlockTablePos64;
|
||||
if(!FileStream_Read(ha->pStream, &ByteOffset, pHiBlockTable, dwTableSize))
|
||||
nError = GetLastError();
|
||||
dwErrCode = GetLastError();
|
||||
|
||||
// Now merge the hi-block table to the file table
|
||||
if(nError == ERROR_SUCCESS)
|
||||
if(dwErrCode == ERROR_SUCCESS)
|
||||
{
|
||||
TFileEntry * pFileEntry = ha->pFileTable;
|
||||
|
||||
@@ -2557,14 +2557,14 @@ static int BuildFileTable_Classic(TMPQArchive * ha)
|
||||
}
|
||||
else
|
||||
{
|
||||
nError = ERROR_NOT_ENOUGH_MEMORY;
|
||||
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return nError;
|
||||
return dwErrCode;
|
||||
}
|
||||
|
||||
static int BuildFileTable_HetBet(TMPQArchive * ha)
|
||||
static DWORD BuildFileTable_HetBet(TMPQArchive * ha)
|
||||
{
|
||||
TMPQHetTable * pHetTable = ha->pHetTable;
|
||||
TMPQBetTable * pBetTable;
|
||||
@@ -2572,7 +2572,7 @@ static int BuildFileTable_HetBet(TMPQArchive * ha)
|
||||
TMPQBits * pBitArray;
|
||||
DWORD dwBitPosition = 0;
|
||||
DWORD i;
|
||||
int nError = ERROR_FILE_CORRUPT;
|
||||
DWORD dwErrCode = ERROR_FILE_CORRUPT;
|
||||
|
||||
// Load the BET table from the MPQ
|
||||
pBetTable = LoadBetTable(ha);
|
||||
@@ -2665,17 +2665,17 @@ static int BuildFileTable_HetBet(TMPQArchive * ha)
|
||||
|
||||
// Set the current size of the file table
|
||||
FreeBetTable(pBetTable);
|
||||
nError = ERROR_SUCCESS;
|
||||
dwErrCode = ERROR_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
nError = ERROR_FILE_CORRUPT;
|
||||
dwErrCode = ERROR_FILE_CORRUPT;
|
||||
}
|
||||
|
||||
return nError;
|
||||
return dwErrCode;
|
||||
}
|
||||
|
||||
int BuildFileTable(TMPQArchive * ha)
|
||||
DWORD BuildFileTable(TMPQArchive * ha)
|
||||
{
|
||||
DWORD dwFileTableSize;
|
||||
bool bFileTableCreated = false;
|
||||
@@ -2742,7 +2742,7 @@ void UpdateBlockTableSize(TMPQArchive * ha)
|
||||
*/
|
||||
|
||||
// Defragment the file table so it does not contain any gaps
|
||||
int DefragmentFileTable(TMPQArchive * ha)
|
||||
DWORD DefragmentFileTable(TMPQArchive * ha)
|
||||
{
|
||||
TFileEntry * pFileTableEnd = ha->pFileTable + ha->dwFileTableSize;
|
||||
TFileEntry * pSource = ha->pFileTable;
|
||||
@@ -2778,13 +2778,13 @@ int DefragmentFileTable(TMPQArchive * ha)
|
||||
// Update the block table size
|
||||
dwBlockTableSize = (DWORD)(pTarget - ha->pFileTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If there is file name left, free it
|
||||
if(pSource->szFileName != NULL)
|
||||
STORM_FREE(pSource->szFileName);
|
||||
pSource->szFileName = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If there is file name left, free it
|
||||
if(pSource->szFileName != NULL)
|
||||
STORM_FREE(pSource->szFileName);
|
||||
pSource->szFileName = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Did we defragment something?
|
||||
@@ -2825,13 +2825,13 @@ int DefragmentFileTable(TMPQArchive * ha)
|
||||
|
||||
// Rebuilds the HET table from scratch based on the file table
|
||||
// Used after a modifying operation (add, rename, delete)
|
||||
int RebuildHetTable(TMPQArchive * ha)
|
||||
DWORD RebuildHetTable(TMPQArchive * ha)
|
||||
{
|
||||
TMPQHetTable * pOldHetTable = ha->pHetTable;
|
||||
TFileEntry * pFileTableEnd;
|
||||
TFileEntry * pFileEntry;
|
||||
DWORD dwBlockTableSize = ha->dwFileTableSize;
|
||||
int nError = ERROR_SUCCESS;
|
||||
DWORD dwErrCode = ERROR_SUCCESS;
|
||||
|
||||
// If we are in the state of saving MPQ tables, the real size of block table
|
||||
// must already have been calculated. Use that value instead
|
||||
@@ -2853,8 +2853,8 @@ int RebuildHetTable(TMPQArchive * ha)
|
||||
if(pFileEntry->dwFlags & MPQ_FILE_EXISTS)
|
||||
{
|
||||
// Get the high
|
||||
nError = InsertHetEntry(ha->pHetTable, pFileEntry->FileNameHash, (DWORD)(pFileEntry - ha->pFileTable));
|
||||
if(nError != ERROR_SUCCESS)
|
||||
dwErrCode = InsertHetEntry(ha->pHetTable, pFileEntry->FileNameHash, (DWORD)(pFileEntry - ha->pFileTable));
|
||||
if(dwErrCode != ERROR_SUCCESS)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2862,19 +2862,19 @@ int RebuildHetTable(TMPQArchive * ha)
|
||||
|
||||
// Free the old HET table
|
||||
FreeHetTable(pOldHetTable);
|
||||
return nError;
|
||||
return dwErrCode;
|
||||
}
|
||||
|
||||
// Rebuilds the file table, removing all deleted file entries.
|
||||
// Used when compacting the archive
|
||||
int RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize)
|
||||
DWORD RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize)
|
||||
{
|
||||
TFileEntry * pFileEntry;
|
||||
TMPQHash * pHashTableEnd = ha->pHashTable + ha->pHeader->dwHashTableSize;
|
||||
TMPQHash * pOldHashTable = ha->pHashTable;
|
||||
TMPQHash * pHashTable = NULL;
|
||||
TMPQHash * pHash;
|
||||
int nError = ERROR_SUCCESS;
|
||||
DWORD dwErrCode = ERROR_SUCCESS;
|
||||
|
||||
// The new hash table size must be greater or equal to the current hash table size
|
||||
assert(dwNewHashTableSize >= ha->pHeader->dwHashTableSize);
|
||||
@@ -2893,15 +2893,15 @@ int RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize)
|
||||
}
|
||||
|
||||
// Allocate new hash table
|
||||
if(nError == ERROR_SUCCESS)
|
||||
if(dwErrCode == ERROR_SUCCESS)
|
||||
{
|
||||
pHashTable = STORM_ALLOC(TMPQHash, dwNewHashTableSize);
|
||||
if(pHashTable == NULL)
|
||||
nError = ERROR_NOT_ENOUGH_MEMORY;
|
||||
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
// If both succeeded, we need to rebuild the file table
|
||||
if(nError == ERROR_SUCCESS)
|
||||
if(dwErrCode == ERROR_SUCCESS)
|
||||
{
|
||||
// Make sure that the hash table is properly filled
|
||||
memset(pHashTable, 0xFF, sizeof(TMPQHash) * dwNewHashTableSize);
|
||||
@@ -2929,11 +2929,11 @@ int RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize)
|
||||
// Now free the remaining entries
|
||||
if(pOldHashTable != NULL)
|
||||
STORM_FREE(pOldHashTable);
|
||||
return nError;
|
||||
return dwErrCode;
|
||||
}
|
||||
|
||||
// Saves MPQ header, hash table, block table and hi-block table.
|
||||
int SaveMPQTables(TMPQArchive * ha)
|
||||
DWORD SaveMPQTables(TMPQArchive * ha)
|
||||
{
|
||||
TMPQExtHeader * pHetTable = NULL;
|
||||
TMPQExtHeader * pBetTable = NULL;
|
||||
@@ -2949,7 +2949,7 @@ int SaveMPQTables(TMPQArchive * ha)
|
||||
USHORT * pHiBlockTable = NULL;
|
||||
DWORD cbTotalSize;
|
||||
bool bNeedHiBlockTable = false;
|
||||
int nError = ERROR_SUCCESS;
|
||||
DWORD dwErrCode = ERROR_SUCCESS;
|
||||
|
||||
// We expect this function to be called only when tables have been changed
|
||||
assert(ha->dwFlags & MPQ_FLAG_CHANGED);
|
||||
@@ -2958,87 +2958,87 @@ int SaveMPQTables(TMPQArchive * ha)
|
||||
TablePos = FindFreeMpqSpace(ha);
|
||||
|
||||
// If the MPQ has HET table, we prepare a ready-to-save version
|
||||
if(nError == ERROR_SUCCESS && ha->pHetTable != NULL)
|
||||
if(dwErrCode == ERROR_SUCCESS && ha->pHetTable != NULL)
|
||||
{
|
||||
pHetTable = TranslateHetTable(ha->pHetTable, &HetTableSize64);
|
||||
if(pHetTable == NULL)
|
||||
nError = ERROR_NOT_ENOUGH_MEMORY;
|
||||
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
// If the MPQ has HET table, we also must create BET table to be saved
|
||||
if(nError == ERROR_SUCCESS && ha->pHetTable != NULL)
|
||||
if(dwErrCode == ERROR_SUCCESS && ha->pHetTable != NULL)
|
||||
{
|
||||
pBetTable = TranslateBetTable(ha, &BetTableSize64);
|
||||
if(pBetTable == NULL)
|
||||
nError = ERROR_NOT_ENOUGH_MEMORY;
|
||||
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
// Now create hash table
|
||||
if(nError == ERROR_SUCCESS && ha->pHashTable != NULL)
|
||||
if(dwErrCode == ERROR_SUCCESS && ha->pHashTable != NULL)
|
||||
{
|
||||
pHashTable = TranslateHashTable(ha, &HashTableSize64);
|
||||
if(pHashTable == NULL)
|
||||
nError = ERROR_NOT_ENOUGH_MEMORY;
|
||||
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
// Create block table
|
||||
if(nError == ERROR_SUCCESS && ha->pFileTable != NULL)
|
||||
if(dwErrCode == ERROR_SUCCESS && ha->pFileTable != NULL)
|
||||
{
|
||||
pBlockTable = TranslateBlockTable(ha, &BlockTableSize64, &bNeedHiBlockTable);
|
||||
if(pBlockTable == NULL)
|
||||
nError = ERROR_NOT_ENOUGH_MEMORY;
|
||||
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
// Create hi-block table, if needed
|
||||
if(nError == ERROR_SUCCESS && bNeedHiBlockTable)
|
||||
if(dwErrCode == ERROR_SUCCESS && bNeedHiBlockTable)
|
||||
{
|
||||
pHiBlockTable = TranslateHiBlockTable(ha, &HiBlockTableSize64);
|
||||
if(pHiBlockTable == NULL)
|
||||
nError = ERROR_NOT_ENOUGH_MEMORY;
|
||||
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
// Write the HET table, if any
|
||||
if(nError == ERROR_SUCCESS && pHetTable != NULL)
|
||||
if(dwErrCode == ERROR_SUCCESS && pHetTable != NULL)
|
||||
{
|
||||
pHeader->HetTableSize64 = HetTableSize64;
|
||||
pHeader->HetTablePos64 = TablePos;
|
||||
nError = SaveExtTable(ha, pHetTable, TablePos, (DWORD)HetTableSize64, pHeader->MD5_HetTable, MPQ_KEY_HASH_TABLE, false, &cbTotalSize);
|
||||
dwErrCode = SaveExtTable(ha, pHetTable, TablePos, (DWORD)HetTableSize64, pHeader->MD5_HetTable, MPQ_KEY_HASH_TABLE, false, &cbTotalSize);
|
||||
TablePos += cbTotalSize;
|
||||
}
|
||||
|
||||
// Write the BET table, if any
|
||||
if(nError == ERROR_SUCCESS && pBetTable != NULL)
|
||||
if(dwErrCode == ERROR_SUCCESS && pBetTable != NULL)
|
||||
{
|
||||
pHeader->BetTableSize64 = BetTableSize64;
|
||||
pHeader->BetTablePos64 = TablePos;
|
||||
nError = SaveExtTable(ha, pBetTable, TablePos, (DWORD)BetTableSize64, pHeader->MD5_BetTable, MPQ_KEY_BLOCK_TABLE, false, &cbTotalSize);
|
||||
dwErrCode = SaveExtTable(ha, pBetTable, TablePos, (DWORD)BetTableSize64, pHeader->MD5_BetTable, MPQ_KEY_BLOCK_TABLE, false, &cbTotalSize);
|
||||
TablePos += cbTotalSize;
|
||||
}
|
||||
|
||||
// Write the hash table, if we have any
|
||||
if(nError == ERROR_SUCCESS && pHashTable != NULL)
|
||||
if(dwErrCode == ERROR_SUCCESS && pHashTable != NULL)
|
||||
{
|
||||
pHeader->HashTableSize64 = HashTableSize64;
|
||||
pHeader->wHashTablePosHi = (USHORT)(TablePos >> 32);
|
||||
pHeader->dwHashTableSize = (DWORD)(HashTableSize64 / sizeof(TMPQHash));
|
||||
pHeader->dwHashTablePos = (DWORD)TablePos;
|
||||
nError = SaveMpqTable(ha, pHashTable, TablePos, (size_t)HashTableSize64, pHeader->MD5_HashTable, MPQ_KEY_HASH_TABLE, false);
|
||||
dwErrCode = SaveMpqTable(ha, pHashTable, TablePos, (size_t)HashTableSize64, pHeader->MD5_HashTable, MPQ_KEY_HASH_TABLE, false);
|
||||
TablePos += HashTableSize64;
|
||||
}
|
||||
|
||||
// Write the block table, if we have any
|
||||
if(nError == ERROR_SUCCESS && pBlockTable != NULL)
|
||||
if(dwErrCode == ERROR_SUCCESS && pBlockTable != NULL)
|
||||
{
|
||||
pHeader->BlockTableSize64 = BlockTableSize64;
|
||||
pHeader->wBlockTablePosHi = (USHORT)(TablePos >> 32);
|
||||
pHeader->dwBlockTableSize = (DWORD)(BlockTableSize64 / sizeof(TMPQBlock));
|
||||
pHeader->dwBlockTablePos = (DWORD)TablePos;
|
||||
nError = SaveMpqTable(ha, pBlockTable, TablePos, (size_t)BlockTableSize64, pHeader->MD5_BlockTable, MPQ_KEY_BLOCK_TABLE, false);
|
||||
dwErrCode = SaveMpqTable(ha, pBlockTable, TablePos, (size_t)BlockTableSize64, pHeader->MD5_BlockTable, MPQ_KEY_BLOCK_TABLE, false);
|
||||
TablePos += BlockTableSize64;
|
||||
}
|
||||
|
||||
// Write the hi-block table, if we have any
|
||||
if(nError == ERROR_SUCCESS && pHiBlockTable != NULL)
|
||||
if(dwErrCode == ERROR_SUCCESS && pHiBlockTable != NULL)
|
||||
{
|
||||
ULONGLONG ByteOffset = ha->MpqPos + TablePos;
|
||||
|
||||
@@ -3047,21 +3047,21 @@ int SaveMPQTables(TMPQArchive * ha)
|
||||
BSWAP_ARRAY16_UNSIGNED(pHiBlockTable, HiBlockTableSize64);
|
||||
|
||||
if(!FileStream_Write(ha->pStream, &ByteOffset, pHiBlockTable, (DWORD)HiBlockTableSize64))
|
||||
nError = GetLastError();
|
||||
dwErrCode = GetLastError();
|
||||
TablePos += HiBlockTableSize64;
|
||||
}
|
||||
|
||||
// Cut the MPQ
|
||||
if(nError == ERROR_SUCCESS)
|
||||
if(dwErrCode == ERROR_SUCCESS)
|
||||
{
|
||||
ULONGLONG FileSize = ha->MpqPos + TablePos;
|
||||
|
||||
if(!FileStream_SetSize(ha->pStream, FileSize))
|
||||
nError = GetLastError();
|
||||
dwErrCode = GetLastError();
|
||||
}
|
||||
|
||||
// Write the MPQ header
|
||||
if(nError == ERROR_SUCCESS)
|
||||
if(dwErrCode == ERROR_SUCCESS)
|
||||
{
|
||||
TMPQHeader SaveMpqHeader;
|
||||
|
||||
@@ -3079,11 +3079,11 @@ int SaveMPQTables(TMPQArchive * ha)
|
||||
BSWAP_TMPQHEADER(&SaveMpqHeader, MPQ_FORMAT_VERSION_3);
|
||||
BSWAP_TMPQHEADER(&SaveMpqHeader, MPQ_FORMAT_VERSION_4);
|
||||
if(!FileStream_Write(ha->pStream, &ha->MpqPos, &SaveMpqHeader, pHeader->dwHeaderSize))
|
||||
nError = GetLastError();
|
||||
dwErrCode = GetLastError();
|
||||
}
|
||||
|
||||
// Clear the changed flag
|
||||
if(nError == ERROR_SUCCESS)
|
||||
if(dwErrCode == ERROR_SUCCESS)
|
||||
ha->dwFlags &= ~MPQ_FLAG_CHANGED;
|
||||
|
||||
// Cleanup and exit
|
||||
@@ -3097,5 +3097,5 @@ int SaveMPQTables(TMPQArchive * ha)
|
||||
STORM_FREE(pBlockTable);
|
||||
if(pHiBlockTable != NULL)
|
||||
STORM_FREE(pHiBlockTable);
|
||||
return nError;
|
||||
return dwErrCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user