From a3332c7c9bc36f13aace6543ebc719f833882dfc Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Mon, 17 May 2021 10:04:06 +0200 Subject: nError -> dwErrCode --- src/FileStream.cpp | 22 +- src/SBaseCommon.cpp | 57 ++-- src/SBaseFileTable.cpp | 170 +++++----- src/SBaseSubTypes.cpp | 18 +- src/SFileAddFile.cpp | 322 +++++++++--------- src/SFileAttributes.cpp | 24 +- src/SFileCompactArchive.cpp | 180 +++++----- src/SFileCreateArchive.cpp | 38 +-- src/SFileExtractFile.cpp | 28 +- src/SFileFindFile.cpp | 58 ++-- src/SFileGetFileInfo.cpp | 58 ++-- src/SFileListFile.cpp | 40 +-- src/SFileOpenArchive.cpp | 98 +++--- src/SFileOpenFileEx.cpp | 32 +- src/SFilePatchArchives.cpp | 82 ++--- src/SFileReadFile.cpp | 146 ++++---- src/SFileVerify.cpp | 36 +- src/StormCommon.h | 66 ++-- src/StormLib.h | 8 +- test/StormTest.cpp | 801 ++++++++++++++++++++++---------------------- 20 files changed, 1143 insertions(+), 1141 deletions(-) diff --git a/src/FileStream.cpp b/src/FileStream.cpp index 2266518..d15316a 100644 --- a/src/FileStream.cpp +++ b/src/FileStream.cpp @@ -34,16 +34,16 @@ // Local functions - platform-specific functions #ifndef STORMLIB_WINDOWS -static thread_local DWORD nLastError = ERROR_SUCCESS; +static thread_local DWORD dwLastError = ERROR_SUCCESS; DWORD GetLastError() { - return nLastError; + return dwLastError; } void SetLastError(DWORD dwErrCode) { - nLastError = dwErrCode; + dwLastError = dwErrCode; } #endif @@ -113,7 +113,7 @@ static bool BaseFile_Create(TFileStream * pStream) if(handle == -1) { pStream->Base.File.hFile = INVALID_HANDLE_VALUE; - nLastError = errno; + dwLastError = errno; return false; } @@ -166,7 +166,7 @@ static bool BaseFile_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD if(handle == -1) { pStream->Base.File.hFile = INVALID_HANDLE_VALUE; - nLastError = errno; + dwLastError = errno; return false; } @@ -174,7 +174,7 @@ static bool BaseFile_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD if(fstat64(handle, &fileinfo) == -1) { pStream->Base.File.hFile = INVALID_HANDLE_VALUE; - nLastError = errno; + dwLastError = errno; close(handle); return false; } @@ -244,7 +244,7 @@ static bool BaseFile_Read( bytes_read = read((intptr_t)pStream->Base.File.hFile, pvBuffer, (size_t)dwBytesToRead); if(bytes_read == -1) { - nLastError = errno; + dwLastError = errno; return false; } @@ -313,7 +313,7 @@ static bool BaseFile_Write(TFileStream * pStream, ULONGLONG * pByteOffset, const bytes_written = write((intptr_t)pStream->Base.File.hFile, pvBuffer, (size_t)dwBytesToWrite); if(bytes_written == -1) { - nLastError = errno; + dwLastError = errno; return false; } @@ -368,7 +368,7 @@ static bool BaseFile_Resize(TFileStream * pStream, ULONGLONG NewFileSize) { if(ftruncate64((intptr_t)pStream->Base.File.hFile, (off64_t)NewFileSize) == -1) { - nLastError = errno; + dwLastError = errno; return false; } @@ -412,7 +412,7 @@ static bool BaseFile_Replace(TFileStream * pStream, TFileStream * pNewStream) // "rename" on Linux also works if the target file exists if(rename(pNewStream->szFileName, pStream->szFileName) == -1) { - nLastError = errno; + dwLastError = errno; return false; } @@ -594,7 +594,7 @@ static bool BaseMap_Open(TFileStream * pStream, LPCTSTR szFileName, DWORD dwStre // Did the mapping fail? if(bResult == false) - nLastError = errno; + dwLastError = errno; return bResult; #else diff --git a/src/SBaseCommon.cpp b/src/SBaseCommon.cpp index 2f30a71..43113a1 100644 --- a/src/SBaseCommon.cpp +++ b/src/SBaseCommon.cpp @@ -443,6 +443,9 @@ void DecryptMpqBlock(void * pvDataBlock, DWORD dwLength, DWORD dwKey1) DWORD dwValue32; DWORD dwKey2 = 0xEEEEEEEE; + // Check for alignment + //assert(((size_t)(pvDataBlock) & 0x03) == 0); + // Round to DWORDs dwLength >>= 2; @@ -921,7 +924,7 @@ void * LoadMpqTable( LPBYTE pbMpqTable; LPBYTE pbToRead; DWORD dwBytesToRead = dwCompressedSize; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Allocate the MPQ table pbMpqTable = pbToRead = STORM_ALLOC(BYTE, dwTableSize); @@ -972,15 +975,15 @@ void * LoadMpqTable( // Verify the MD5 of the table, if present if(!VerifyDataBlockHash(pbToRead, dwBytesToRead, pbTableHash)) { - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } else { - nError = GetLastError(); + dwErrCode = GetLastError(); } - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // First of all, decrypt the table if(dwKey != 0) @@ -997,7 +1000,7 @@ void * LoadMpqTable( int cbInBuffer = (int)dwCompressedSize; if(!SCompDecompress2(pbMpqTable, &cbOutBuffer, pbCompressed, cbInBuffer)) - nError = GetLastError(); + dwErrCode = GetLastError(); } // Make sure that the table is properly byte-swapped @@ -1005,7 +1008,7 @@ void * LoadMpqTable( } // If read failed, free the table and return - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) { STORM_FREE(pbMpqTable); pbMpqTable = NULL; @@ -1045,7 +1048,7 @@ unsigned char * AllocateMd5Buffer( } // Allocates sector buffer and sector offset table -int AllocateSectorBuffer(TMPQFile * hf) +DWORD AllocateSectorBuffer(TMPQFile * hf) { TMPQArchive * ha = hf->ha; @@ -1064,11 +1067,11 @@ int AllocateSectorBuffer(TMPQFile * hf) hf->dwSectorOffs = SFILE_INVALID_POS; // Return result - return (hf->pbFileSector != NULL) ? (int)ERROR_SUCCESS : (int)ERROR_NOT_ENOUGH_MEMORY; + return (hf->pbFileSector != NULL) ? ERROR_SUCCESS : ERROR_NOT_ENOUGH_MEMORY; } // Allocates sector offset table -int AllocatePatchInfo(TMPQFile * hf, bool bLoadFromFile) +DWORD AllocatePatchInfo(TMPQFile * hf, bool bLoadFromFile) { TMPQArchive * ha = hf->ha; DWORD dwLength = sizeof(TPatchInfo); @@ -1132,7 +1135,7 @@ __AllocateAndLoadPatchInfo: } // Allocates sector offset table -int AllocateSectorOffsets(TMPQFile * hf, bool bLoadFromFile) +DWORD AllocateSectorOffsets(TMPQFile * hf, bool bLoadFromFile) { TMPQArchive * ha = hf->ha; TFileEntry * pFileEntry = hf->pFileEntry; @@ -1288,7 +1291,7 @@ int AllocateSectorOffsets(TMPQFile * hf, bool bLoadFromFile) return ERROR_SUCCESS; } -int AllocateSectorChecksums(TMPQFile * hf, bool bLoadFromFile) +DWORD AllocateSectorChecksums(TMPQFile * hf, bool bLoadFromFile) { TMPQArchive * ha = hf->ha; TFileEntry * pFileEntry = hf->pFileEntry; @@ -1365,7 +1368,7 @@ int AllocateSectorChecksums(TMPQFile * hf, bool bLoadFromFile) return ERROR_SUCCESS; } -int WritePatchInfo(TMPQFile * hf) +DWORD WritePatchInfo(TMPQFile * hf) { TMPQArchive * ha = hf->ha; TPatchInfo * pPatchInfo = hf->pPatchInfo; @@ -1382,7 +1385,7 @@ int WritePatchInfo(TMPQFile * hf) return ERROR_SUCCESS; } -int WriteSectorOffsets(TMPQFile * hf) +DWORD WriteSectorOffsets(TMPQFile * hf) { TMPQArchive * ha = hf->ha; TFileEntry * pFileEntry = hf->pFileEntry; @@ -1414,16 +1417,16 @@ int WriteSectorOffsets(TMPQFile * hf) return ERROR_SUCCESS; } -int WriteSectorChecksums(TMPQFile * hf) +DWORD WriteSectorChecksums(TMPQFile * hf) { TMPQArchive * ha = hf->ha; ULONGLONG RawFilePos; TFileEntry * pFileEntry = hf->pFileEntry; LPBYTE pbCompressed; DWORD dwCompressedSize = 0; + DWORD dwErrCode = ERROR_SUCCESS; DWORD dwCrcSize; int nOutSize; - int nError = ERROR_SUCCESS; // The caller must make sure that this function is only called // when the following is true. @@ -1459,7 +1462,7 @@ int WriteSectorChecksums(TMPQFile * hf) if(hf->pPatchInfo != NULL) RawFilePos += hf->pPatchInfo->dwLength; if(!FileStream_Write(ha->pStream, &RawFilePos, pbCompressed, dwCompressedSize)) - nError = GetLastError(); + dwErrCode = GetLastError(); // Not necessary, as the sector checksums // are going to be freed when this is done. @@ -1469,10 +1472,10 @@ int WriteSectorChecksums(TMPQFile * hf) hf->SectorOffsets[hf->dwSectorCount + 1] = hf->SectorOffsets[hf->dwSectorCount] + dwCompressedSize; pFileEntry->dwCmpSize += dwCompressedSize; STORM_FREE(pbCompressed); - return nError; + return dwErrCode; } -int WriteMemDataMD5( +DWORD WriteMemDataMD5( TFileStream * pStream, ULONGLONG RawDataOffs, void * pvRawData, @@ -1485,7 +1488,7 @@ int WriteMemDataMD5( LPBYTE pbRawData = (LPBYTE)pvRawData; DWORD dwBytesRemaining = dwRawDataSize; DWORD dwMd5ArraySize = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Allocate buffer for array of MD5 md5_array = md5 = AllocateMd5Buffer(dwRawDataSize, dwChunkSize, &dwMd5ArraySize); @@ -1510,7 +1513,7 @@ int WriteMemDataMD5( // Write the array od MD5's to the file RawDataOffs += dwRawDataSize; if(!FileStream_Write(pStream, &RawDataOffs, md5_array, dwMd5ArraySize)) - nError = GetLastError(); + dwErrCode = GetLastError(); // Give the caller the size of the MD5 array if(pcbTotalSize != NULL) @@ -1518,12 +1521,12 @@ int WriteMemDataMD5( // Free buffers and exit STORM_FREE(md5_array); - return nError; + return dwErrCode; } // Writes the MD5 for each chunk of the raw file data -int WriteMpqDataMD5( +DWORD WriteMpqDataMD5( TFileStream * pStream, ULONGLONG RawDataOffs, DWORD dwRawDataSize, @@ -1534,7 +1537,7 @@ int WriteMpqDataMD5( LPBYTE pbFileChunk; DWORD dwMd5ArraySize = 0; DWORD dwToRead = dwRawDataSize; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Allocate buffer for array of MD5 md5_array = md5 = AllocateMd5Buffer(dwRawDataSize, dwChunkSize, &dwMd5ArraySize); @@ -1558,7 +1561,7 @@ int WriteMpqDataMD5( // Read the chunk if(!FileStream_Read(pStream, &RawDataOffs, pbFileChunk, dwToRead)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -1572,16 +1575,16 @@ int WriteMpqDataMD5( } // Write the array od MD5's to the file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(!FileStream_Write(pStream, NULL, md5_array, dwMd5ArraySize)) - nError = GetLastError(); + dwErrCode = GetLastError(); } // Free buffers and exit STORM_FREE(pbFileChunk); STORM_FREE(md5_array); - return nError; + return dwErrCode; } // Frees the structure for MPQ file diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index 3d74fb1..7d52f7c 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -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; } diff --git a/src/SBaseSubTypes.cpp b/src/SBaseSubTypes.cpp index afa7311..6ab4a99 100644 --- a/src/SBaseSubTypes.cpp +++ b/src/SBaseSubTypes.cpp @@ -92,7 +92,7 @@ typedef struct _TSQPBlock // Functions - SQP file format // This function converts SQP file header into MPQ file header -int ConvertSqpHeaderToFormat4( +DWORD ConvertSqpHeaderToFormat4( TMPQArchive * ha, ULONGLONG FileSize, DWORD dwFlags) @@ -187,7 +187,7 @@ TMPQHash * LoadSqpHashTable(TMPQArchive * ha) TSQPHash * pSqpHashEnd; TSQPHash * pSqpHash; TMPQHash * pMpqHash; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Load the hash table pSqpHashTable = (TSQPHash *)LoadSqpTable(ha, pHeader->dwHashTablePos, pHeader->dwHashTableSize * sizeof(TSQPHash), MPQ_KEY_HASH_TABLE); @@ -203,11 +203,11 @@ TMPQHash * LoadSqpHashTable(TMPQArchive * ha) { // Check block index against the size of the block table if(pHeader->dwBlockTableSize <= MPQ_BLOCK_INDEX(pSqpHash) && pSqpHash->dwBlockIndex < HASH_ENTRY_DELETED) - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; // We do not support nonzero locale and platform ID if(pSqpHash->dwAlwaysZero != 0 && pSqpHash->dwAlwaysZero != HASH_ENTRY_FREE) - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; // Store the file name hash pMpqHash->dwName1 = pSqpHash->dwName1; @@ -222,7 +222,7 @@ TMPQHash * LoadSqpHashTable(TMPQArchive * ha) } // If an error occured, we need to free the hash table - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) { STORM_FREE(pSqpHashTable); pSqpHashTable = NULL; @@ -242,7 +242,7 @@ TMPQBlock * LoadSqpBlockTable(TMPQArchive * ha) TSQPBlock * pSqpBlock; TMPQBlock * pMpqBlock; DWORD dwFlags; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Load the hash table pSqpBlockTable = (TSQPBlock *)LoadSqpTable(ha, pHeader->dwBlockTablePos, pHeader->dwBlockTableSize * sizeof(TSQPBlock), MPQ_KEY_BLOCK_TABLE); @@ -255,7 +255,7 @@ TMPQBlock * LoadSqpBlockTable(TMPQArchive * ha) { // Check for valid flags if(pSqpBlock->dwFlags & ~MPQ_FILE_VALID_FLAGS) - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; // Convert SQP block table entry to MPQ block table entry dwFlags = pSqpBlock->dwFlags; @@ -265,7 +265,7 @@ TMPQBlock * LoadSqpBlockTable(TMPQArchive * ha) } // If an error occured, we need to free the hash table - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) { STORM_FREE(pSqpBlockTable); pSqpBlockTable = NULL; @@ -384,7 +384,7 @@ static const unsigned char MpkDecryptionKey[512] = // Functions - MPK file format // This function converts MPK file header into MPQ file header -int ConvertMpkHeaderToFormat4( +DWORD ConvertMpkHeaderToFormat4( TMPQArchive * ha, ULONGLONG FileSize, DWORD dwFlags) diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp index 4599ca4..7b88c12 100644 --- a/src/SFileAddFile.cpp +++ b/src/SFileAddFile.cpp @@ -114,7 +114,7 @@ static int FillWritableHandle( // Call the callback, if needed if(ha->pfnAddFileCB != NULL) ha->pfnAddFileCB(ha->pvAddFileUserData, 0, hf->dwDataSize, false); - hf->nAddFileError = ERROR_SUCCESS; + hf->dwAddFileError = ERROR_SUCCESS; return ERROR_SUCCESS; } @@ -122,7 +122,7 @@ static int FillWritableHandle( //----------------------------------------------------------------------------- // MPQ write data functions -static int WriteDataToMpqFile( +static DWORD WriteDataToMpqFile( TMPQArchive * ha, TMPQFile * hf, LPBYTE pbFileData, @@ -133,8 +133,8 @@ static int WriteDataToMpqFile( ULONGLONG ByteOffset; LPBYTE pbCompressed = NULL; // Compressed (target) data LPBYTE pbToWrite = hf->pbFileSector; // Data to write to the file + DWORD dwErrCode = ERROR_SUCCESS; int nCompressionLevel; // ADPCM compression level (only used for wave files) - int nError = ERROR_SUCCESS; // Make sure that the caller won't overrun the previously initiated file size assert(hf->dwFilePos + dwDataSize <= pFileEntry->dwFileSize); @@ -144,7 +144,7 @@ static int WriteDataToMpqFile( return ERROR_DISK_FULL; // Now write all data to the file sector buffer - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { DWORD dwBytesInSector = hf->dwFilePos % hf->dwSectorSize; DWORD dwSectorIndex = hf->dwFilePos / hf->dwSectorSize; @@ -193,7 +193,7 @@ static int WriteDataToMpqFile( pbToWrite = pbCompressed = STORM_ALLOC(BYTE, hf->dwSectorSize + 0x100); if(pbCompressed == NULL) { - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; break; } } @@ -249,7 +249,7 @@ static int WriteDataToMpqFile( // Write the file sector if(!FileStream_Write(ha->pStream, &ByteOffset, pbToWrite, dwBytesInSector)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -268,13 +268,13 @@ static int WriteDataToMpqFile( // Cleanup if(pbCompressed != NULL) STORM_FREE(pbCompressed); - return nError; + return dwErrCode; } //----------------------------------------------------------------------------- // Recrypts file data for file renaming -static int RecryptFileData( +static DWORD RecryptFileData( TMPQArchive * ha, TMPQFile * hf, const char * szFileName, @@ -285,7 +285,7 @@ static int RecryptFileData( DWORD dwBytesToRecrypt = pFileEntry->dwCmpSize; DWORD dwOldKey; DWORD dwNewKey; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // The file must be encrypted assert(pFileEntry->dwFlags & MPQ_FILE_ENCRYPTED); @@ -308,15 +308,15 @@ static int RecryptFileData( hf->RawFilePos = ha->MpqPos + hf->MpqFilePos; // Allocate buffer for file transfer - nError = AllocateSectorBuffer(hf); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = AllocateSectorBuffer(hf); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; // Also allocate buffer for sector offsets // Note: Don't load sector checksums, we don't need to recrypt them - nError = AllocateSectorOffsets(hf, true); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = AllocateSectorOffsets(hf, true); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; // If we have sector offsets, recrypt these as well if(hf->SectorOffsets != NULL) @@ -335,13 +335,13 @@ static int RecryptFileData( // Write the recrypted array back if(!FileStream_Write(ha->pStream, &hf->RawFilePos, SectorOffsetsCopy, dwSectorOffsLen)) - nError = GetLastError(); + dwErrCode = GetLastError(); STORM_FREE(SectorOffsetsCopy); } // Now we have to recrypt all file sectors. We do it without // recompression, because recompression is not necessary in this case - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { for(DWORD dwSector = 0; dwSector < hf->dwSectorCount; dwSector++) { @@ -365,7 +365,7 @@ static int RecryptFileData( // Read the file sector if(!FileStream_Read(ha->pStream, &RawFilePos, hf->pbFileSector, dwRawDataInSector)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -380,7 +380,7 @@ static int RecryptFileData( // Write the sector back if(!FileStream_Write(ha->pStream, &RawFilePos, hf->pbFileSector, dwRawDataInSector)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -389,13 +389,13 @@ static int RecryptFileData( } } - return nError; + return dwErrCode; } //----------------------------------------------------------------------------- // Internal support for MPQ modifications -int SFileAddFile_Init( +DWORD SFileAddFile_Init( TMPQArchive * ha, const char * szFileName, ULONGLONG FileTime, @@ -407,7 +407,7 @@ int SFileAddFile_Init( TFileEntry * pFileEntry = NULL; TMPQFile * hf = NULL; // File structure for newly added file DWORD dwHashIndex = HASH_ENTRY_FREE; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // // Note: This is an internal function so no validity checks are done. @@ -438,7 +438,7 @@ int SFileAddFile_Init( return false; // Allocate file entry in the MPQ - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Check if the file already exists in the archive pFileEntry = GetFileEntryExact(ha, szFileName, lcLocale, &dwHashIndex); @@ -447,7 +447,7 @@ int SFileAddFile_Init( if(dwFlags & MPQ_FILE_REPLACEEXISTING) InvalidateInternalFiles(ha); else - nError = ERROR_ALREADY_EXISTS; + dwErrCode = ERROR_ALREADY_EXISTS; } else { @@ -456,7 +456,7 @@ int SFileAddFile_Init( if(pFileEntry != NULL) InvalidateInternalFiles(ha); else - nError = ERROR_DISK_FULL; + dwErrCode = ERROR_DISK_FULL; } // Set the file entry to the file structure @@ -464,40 +464,40 @@ int SFileAddFile_Init( } // Prepare the pointer to hash table entry - if(nError == ERROR_SUCCESS && ha->pHashTable != NULL && dwHashIndex < ha->pHeader->dwHashTableSize) + if(dwErrCode == ERROR_SUCCESS && ha->pHashTable != NULL && dwHashIndex < ha->pHeader->dwHashTableSize) { hf->pHashEntry = ha->pHashTable + dwHashIndex; hf->pHashEntry->lcLocale = (USHORT)lcLocale; } // Prepare the file key - if(nError == ERROR_SUCCESS && (dwFlags & MPQ_FILE_ENCRYPTED)) + if(dwErrCode == ERROR_SUCCESS && (dwFlags & MPQ_FILE_ENCRYPTED)) { hf->dwFileKey = DecryptFileKey(szFileName, hf->MpqFilePos, dwFileSize, dwFlags); if(hf->dwFileKey == 0) - nError = ERROR_UNKNOWN_FILE_KEY; + dwErrCode = ERROR_UNKNOWN_FILE_KEY; } // Fill the file entry and TMPQFile structure - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // At this point, the file name in the file entry must be set assert(pFileEntry->szFileName != NULL); assert(_stricmp(pFileEntry->szFileName, szFileName) == 0); - nError = FillWritableHandle(ha, hf, FileTime, dwFileSize, dwFlags); + dwErrCode = FillWritableHandle(ha, hf, FileTime, dwFileSize, dwFlags); } // Free the file handle if failed - if(nError != ERROR_SUCCESS && hf != NULL) + if(dwErrCode != ERROR_SUCCESS && hf != NULL) FreeFileHandle(hf); // Give the handle to the caller *phf = hf; - return nError; + return dwErrCode; } -int SFileAddFile_Init( +DWORD SFileAddFile_Init( TMPQArchive * ha, TMPQFile * hfSrc, TMPQFile ** phf) @@ -507,16 +507,16 @@ int SFileAddFile_Init( ULONGLONG FileTime = hfSrc->pFileEntry->FileTime; DWORD dwFileSize = hfSrc->pFileEntry->dwFileSize; DWORD dwFlags = hfSrc->pFileEntry->dwFlags; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Allocate the TMPQFile entry for newly added file hf = CreateWritableHandle(ha, dwFileSize); if(hf == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; // We need to keep the file entry index the same like in the source archive // This is because multiple hash table entries can point to the same file entry - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Retrieve the file entry for the target file pFileEntry = ha->pFileTable + (hfSrc->pFileEntry - hfSrc->ha->pFileTable); @@ -528,47 +528,47 @@ int SFileAddFile_Init( pFileEntry->szFileName = NULL; } else - nError = ERROR_ALREADY_EXISTS; + dwErrCode = ERROR_ALREADY_EXISTS; // Set the file entry to the file structure hf->pFileEntry = pFileEntry; } // Prepare the pointer to hash table entry - if(nError == ERROR_SUCCESS && ha->pHashTable != NULL && hfSrc->pHashEntry != NULL) + if(dwErrCode == ERROR_SUCCESS && ha->pHashTable != NULL && hfSrc->pHashEntry != NULL) { hf->dwHashIndex = (DWORD)(hfSrc->pHashEntry - hfSrc->ha->pHashTable); hf->pHashEntry = ha->pHashTable + hf->dwHashIndex; } // Prepare the file key (copy from source file) - if(nError == ERROR_SUCCESS && (dwFlags & MPQ_FILE_ENCRYPTED)) + if(dwErrCode == ERROR_SUCCESS && (dwFlags & MPQ_FILE_ENCRYPTED)) { hf->dwFileKey = hfSrc->dwFileKey; if(hf->dwFileKey == 0) - nError = ERROR_UNKNOWN_FILE_KEY; + dwErrCode = ERROR_UNKNOWN_FILE_KEY; } // Fill the file entry and TMPQFile structure - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = FillWritableHandle(ha, hf, FileTime, dwFileSize, dwFlags); + dwErrCode = FillWritableHandle(ha, hf, FileTime, dwFileSize, dwFlags); } // Free the file handle if failed - if(nError != ERROR_SUCCESS && hf != NULL) + if(dwErrCode != ERROR_SUCCESS && hf != NULL) FreeFileHandle(hf); // Give the handle to the caller *phf = hf; - return nError; + return dwErrCode; } -int SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD dwCompression) +DWORD SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD dwCompression) { TMPQArchive * ha; TFileEntry * pFileEntry; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Don't bother if the caller gave us zero size if(pvData == NULL || dwSize == 0) @@ -584,9 +584,9 @@ int SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD d ULONGLONG RawFilePos = hf->RawFilePos; // Allocate buffer for file sector - hf->nAddFileError = nError = AllocateSectorBuffer(hf); - if(nError != ERROR_SUCCESS) - return nError; + hf->dwAddFileError = dwErrCode = AllocateSectorBuffer(hf); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; // Allocate patch info, if the data is patch if(hf->pPatchInfo == NULL && IsIncrementalPatchFile(pvData, dwSize, &hf->dwPatchedFileSize)) @@ -595,32 +595,32 @@ int SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD d pFileEntry->dwFlags |= MPQ_FILE_PATCH_FILE; // Allocate the patch info - hf->nAddFileError = nError = AllocatePatchInfo(hf, false); - if(nError != ERROR_SUCCESS) - return nError; + hf->dwAddFileError = dwErrCode = AllocatePatchInfo(hf, false); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; } // Allocate sector offsets if(hf->SectorOffsets == NULL) { - hf->nAddFileError = nError = AllocateSectorOffsets(hf, false); - if(nError != ERROR_SUCCESS) - return nError; + hf->dwAddFileError = dwErrCode = AllocateSectorOffsets(hf, false); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; } // Create array of sector checksums if(hf->SectorChksums == NULL && (pFileEntry->dwFlags & MPQ_FILE_SECTOR_CRC)) { - hf->nAddFileError = nError = AllocateSectorChecksums(hf, false); - if(nError != ERROR_SUCCESS) - return nError; + hf->dwAddFileError = dwErrCode = AllocateSectorChecksums(hf, false); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; } // Pre-save the patch info, if any if(hf->pPatchInfo != NULL) { if(!FileStream_Write(ha->pStream, &RawFilePos, hf->pPatchInfo, hf->pPatchInfo->dwLength)) - nError = GetLastError(); + dwErrCode = GetLastError(); pFileEntry->dwCmpSize += hf->pPatchInfo->dwLength; RawFilePos += hf->pPatchInfo->dwLength; @@ -632,7 +632,7 @@ int SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD d if(hf->SectorOffsets != NULL) { if(!FileStream_Write(ha->pStream, &RawFilePos, hf->SectorOffsets, hf->SectorOffsets[0])) - nError = GetLastError(); + dwErrCode = GetLastError(); pFileEntry->dwCmpSize += hf->SectorOffsets[0]; RawFilePos += hf->SectorOffsets[0]; @@ -640,7 +640,7 @@ int SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD d } // Write the MPQ data to the file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Save the first sector compression to the file structure // Note that the entire first file sector will be compressed @@ -649,12 +649,12 @@ int SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD d hf->dwCompression0 = dwCompression; // Write the data to the MPQ - nError = WriteDataToMpqFile(ha, hf, (LPBYTE)pvData, dwSize, dwCompression); + dwErrCode = WriteDataToMpqFile(ha, hf, (LPBYTE)pvData, dwSize, dwCompression); } // If it succeeded and we wrote all the file data, // we need to re-save sector offset table - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(hf->dwFilePos >= pFileEntry->dwFileSize) { @@ -667,7 +667,7 @@ int SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD d // If we also have sector checksums, write them to the file if(hf->SectorChksums != NULL) { - nError = WriteSectorChecksums(hf); + dwErrCode = WriteSectorChecksums(hf); } // Now write patch info @@ -676,22 +676,22 @@ int SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD d memcpy(hf->pPatchInfo->md5, pFileEntry->md5, MD5_DIGEST_SIZE); hf->pPatchInfo->dwDataSize = pFileEntry->dwFileSize; pFileEntry->dwFileSize = hf->dwPatchedFileSize; - nError = WritePatchInfo(hf); + dwErrCode = WritePatchInfo(hf); } // Now write sector offsets to the file if(hf->SectorOffsets != NULL) { - nError = WriteSectorOffsets(hf); + dwErrCode = WriteSectorOffsets(hf); } // Write the MD5 hashes of each file chunk, if required if(ha->pHeader->dwRawChunkSize != 0) { - nError = WriteMpqDataMD5(ha->pStream, - ha->MpqPos + pFileEntry->ByteOffset, - hf->pFileEntry->dwCmpSize, - ha->pHeader->dwRawChunkSize); + dwErrCode = WriteMpqDataMD5(ha->pStream, + ha->MpqPos + pFileEntry->ByteOffset, + hf->pFileEntry->dwCmpSize, + ha->pHeader->dwRawChunkSize); } } } @@ -701,41 +701,41 @@ int SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD d ha->FileSize = ha->MpqPos + pFileEntry->ByteOffset + pFileEntry->dwCmpSize; // Store the error code from the Write File operation - hf->nAddFileError = nError; - return nError; + hf->dwAddFileError = dwErrCode; + return dwErrCode; } -int SFileAddFile_Finish(TMPQFile * hf) +DWORD SFileAddFile_Finish(TMPQFile * hf) { TMPQArchive * ha = hf->ha; TFileEntry * pFileEntry = hf->pFileEntry; - int nError = hf->nAddFileError; + DWORD dwErrCode = hf->dwAddFileError; // If all previous operations succeeded, we can update the MPQ - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Verify if the caller wrote the file properly if(hf->pPatchInfo == NULL) { assert(pFileEntry != NULL); if(hf->dwFilePos != pFileEntry->dwFileSize) - nError = ERROR_CAN_NOT_COMPLETE; + dwErrCode = ERROR_CAN_NOT_COMPLETE; } else { if(hf->dwFilePos != hf->pPatchInfo->dwDataSize) - nError = ERROR_CAN_NOT_COMPLETE; + dwErrCode = ERROR_CAN_NOT_COMPLETE; } } // Now we need to recreate the HET table, if exists - if(nError == ERROR_SUCCESS && ha->pHetTable != NULL) + if(dwErrCode == ERROR_SUCCESS && ha->pHetTable != NULL) { - nError = RebuildHetTable(ha); + dwErrCode = RebuildHetTable(ha); } // Update the block table size - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Call the user callback, if any if(ha->pfnAddFileCB != NULL) @@ -750,7 +750,7 @@ int SFileAddFile_Finish(TMPQFile * hf) // Clear the add file callback FreeFileHandle(hf); - return nError; + return dwErrCode; } //----------------------------------------------------------------------------- @@ -766,50 +766,50 @@ bool WINAPI SFileCreateFile( HANDLE * phFile) { TMPQArchive * ha = (TMPQArchive *)hMpq; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Check valid parameters if(!IsValidMpqHandle(hMpq)) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(szArchivedName == NULL || *szArchivedName == 0) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; if(phFile == NULL) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; // Don't allow to add file if the MPQ is open for read only - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(ha->dwFlags & MPQ_FLAG_READ_ONLY) - nError = ERROR_ACCESS_DENIED; + dwErrCode = ERROR_ACCESS_DENIED; // Don't allow to add a file under pseudo-file name if(IsPseudoFileName(szArchivedName, NULL)) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; // Don't allow to add any of the internal files if(IsInternalMpqFileName(szArchivedName)) - nError = ERROR_INTERNAL_FILE; + dwErrCode = ERROR_INTERNAL_FILE; } // Perform validity check of the MPQ flags - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Mask all unsupported flags out dwFlags &= (ha->dwFlags & MPQ_FLAG_WAR3_MAP) ? MPQ_FILE_VALID_FLAGS_W3X : MPQ_FILE_VALID_FLAGS; // Check for valid flag combinations if((dwFlags & (MPQ_FILE_IMPLODE | MPQ_FILE_COMPRESS)) == (MPQ_FILE_IMPLODE | MPQ_FILE_COMPRESS)) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; } // Initiate the add file operation - if(nError == ERROR_SUCCESS) - nError = SFileAddFile_Init(ha, szArchivedName, FileTime, dwFileSize, lcLocale, dwFlags, (TMPQFile **)phFile); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = SFileAddFile_Init(ha, szArchivedName, FileTime, dwFileSize, lcLocale, dwFlags, (TMPQFile **)phFile); // Deal with the errors - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } bool WINAPI SFileWriteFile( @@ -819,16 +819,16 @@ bool WINAPI SFileWriteFile( DWORD dwCompression) { TMPQFile * hf = (TMPQFile *)hFile; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Check the proper parameters if(!IsValidFileHandle(hFile)) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(hf->bIsWriteHandle == false) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; // Special checks for single unit files - if(nError == ERROR_SUCCESS && (hf->pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT)) + if(dwErrCode == ERROR_SUCCESS && (hf->pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT)) { // // Note: Blizzard doesn't support single unit files @@ -837,46 +837,46 @@ bool WINAPI SFileWriteFile( // // if(dwFlags & MPQ_FILE_IMPLODE) -// nError = ERROR_INVALID_PARAMETER; +// dwErrCode = ERROR_INVALID_PARAMETER; // // if(dwFlags & MPQ_FILE_ENCRYPTED) -// nError = ERROR_INVALID_PARAMETER; +// dwErrCode = ERROR_INVALID_PARAMETER; // Lossy compression is not allowed on single unit files if(dwCompression & MPQ_LOSSY_COMPRESSION_MASK) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; } // Write the data to the file - if(nError == ERROR_SUCCESS) - nError = SFileAddFile_Write(hf, pvData, dwSize, dwCompression); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = SFileAddFile_Write(hf, pvData, dwSize, dwCompression); // Deal with errors - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } bool WINAPI SFileFinishFile(HANDLE hFile) { TMPQFile * hf = (TMPQFile *)hFile; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Check the proper parameters if(!IsValidFileHandle(hFile)) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(hf->bIsWriteHandle == false) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; // Finish the file - if(nError == ERROR_SUCCESS) - nError = SFileAddFile_Finish(hf); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = SFileAddFile_Finish(hf); // Deal with errors - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } //----------------------------------------------------------------------------- @@ -901,7 +901,7 @@ bool WINAPI SFileAddFileEx( DWORD dwChannels = 0; bool bIsAdpcmCompression = false; bool bIsFirstSector = true; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Check parameters if(hMpq == NULL || szFileName == NULL || *szFileName == 0) @@ -919,19 +919,19 @@ bool WINAPI SFileAddFileEx( FileStream_GetTime(pStream, &FileTime); FileStream_GetSize(pStream, &FileSize); if(FileSize >> 32) - nError = ERROR_DISK_FULL; + dwErrCode = ERROR_DISK_FULL; // Allocate data buffer for reading from the source file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { dwBytesRemaining = (DWORD)FileSize; pbFileData = STORM_ALLOC(BYTE, dwSectorSize); if(pbFileData == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } // Deal with various combination of compressions - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // When the compression for next blocks is set to default, // we will copy the compression for the first sector @@ -955,11 +955,11 @@ bool WINAPI SFileAddFileEx( // Initiate adding file to the MPQ if(!SFileCreateFile(hMpq, szArchivedName, FileTime, (DWORD)FileSize, g_lcFileLocale, dwFlags, &hMpqFile)) - nError = GetLastError(); + dwErrCode = GetLastError(); } // Write the file data to the MPQ - while(nError == ERROR_SUCCESS && dwBytesRemaining != 0) + while(dwErrCode == ERROR_SUCCESS && dwBytesRemaining != 0) { // Get the number of bytes remaining in the source file dwBytesToRead = dwBytesRemaining; @@ -969,7 +969,7 @@ bool WINAPI SFileAddFileEx( // Read data from the local file if(!FileStream_Read(pStream, NULL, pbFileData, dwBytesToRead)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -995,7 +995,7 @@ bool WINAPI SFileAddFileEx( // Add the file sectors to the MPQ if(!SFileWriteFile(hMpqFile, pbFileData, dwBytesToRead, dwCompression)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -1008,7 +1008,7 @@ bool WINAPI SFileAddFileEx( if(hMpqFile != NULL) { if(!SFileFinishFile(hMpqFile)) - nError = GetLastError(); + dwErrCode = GetLastError(); } // Cleanup and exit @@ -1016,9 +1016,9 @@ bool WINAPI SFileAddFileEx( STORM_FREE(pbFileData); if(pStream != NULL) FileStream_Close(pStream); - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } // Adds a data file into the archive @@ -1086,43 +1086,43 @@ bool WINAPI SFileRemoveFile(HANDLE hMpq, const char * szFileName, DWORD dwSearch { TMPQArchive * ha = IsValidMpqHandle(hMpq); TMPQFile * hf = NULL; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Keep compiler happy dwSearchScope = dwSearchScope; // Check the parameters if(ha == NULL) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(szFileName == NULL || *szFileName == 0) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; if(IsInternalMpqFileName(szFileName)) - nError = ERROR_INTERNAL_FILE; + dwErrCode = ERROR_INTERNAL_FILE; // Do not allow to remove files from read-only or patched MPQs - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if((ha->dwFlags & MPQ_FLAG_READ_ONLY) || (ha->haPatch != NULL)) - nError = ERROR_ACCESS_DENIED; + dwErrCode = ERROR_ACCESS_DENIED; } // If all checks have passed, we can delete the file from the MPQ - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Open the file from the MPQ if(SFileOpenFileEx(hMpq, szFileName, SFILE_OPEN_BASE_FILE, (HANDLE *)&hf)) { // Delete the file entry - nError = DeleteFileEntry(ha, hf); + dwErrCode = DeleteFileEntry(ha, hf); FreeFileHandle(hf); } else - nError = GetLastError(); + dwErrCode = GetLastError(); } // If the file has been deleted, we need to invalidate // the internal files and recreate HET table - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Invalidate the entries for internal files // After we are done with MPQ changes, we need to re-create them anyway @@ -1135,9 +1135,9 @@ bool WINAPI SFileRemoveFile(HANDLE hMpq, const char * szFileName, DWORD dwSearch } // Resolve error and exit - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } // Renames the file within the archive. @@ -1145,32 +1145,32 @@ bool WINAPI SFileRenameFile(HANDLE hMpq, const char * szFileName, const char * s { TMPQArchive * ha = IsValidMpqHandle(hMpq); TMPQFile * hf; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Test the valid parameters if(ha == NULL) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(szFileName == NULL || *szFileName == 0 || szNewFileName == NULL || *szNewFileName == 0) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; if(IsInternalMpqFileName(szFileName) || IsInternalMpqFileName(szNewFileName)) - nError = ERROR_INTERNAL_FILE; + dwErrCode = ERROR_INTERNAL_FILE; // Do not allow to rename files in MPQ open for read only - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(ha->dwFlags & MPQ_FLAG_READ_ONLY) - nError = ERROR_ACCESS_DENIED; + dwErrCode = ERROR_ACCESS_DENIED; } // Open the new file. If exists, we don't allow rename operation - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(GetFileEntryLocale(ha, szNewFileName, g_lcFileLocale) != NULL) - nError = ERROR_ALREADY_EXISTS; + dwErrCode = ERROR_ALREADY_EXISTS; } // Open the file from the MPQ - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Attempt to open the file if(SFileOpenFileEx(hMpq, szFileName, SFILE_OPEN_BASE_FILE, (HANDLE *)&hf)) @@ -1182,17 +1182,17 @@ bool WINAPI SFileRenameFile(HANDLE hMpq, const char * szFileName, const char * s InvalidateInternalFiles(ha); // Rename the file entry in the table - nError = RenameFileEntry(ha, hf, szNewFileName); + dwErrCode = RenameFileEntry(ha, hf, szNewFileName); // If the file is encrypted, we have to re-crypt the file content // with the new decryption key - if((nError == ERROR_SUCCESS) && (pFileEntry->dwFlags & MPQ_FILE_ENCRYPTED)) + if((dwErrCode == ERROR_SUCCESS) && (pFileEntry->dwFlags & MPQ_FILE_ENCRYPTED)) { // Recrypt the file data in the MPQ - nError = RecryptFileData(ha, hf, szFileName, szNewFileName); + dwErrCode = RecryptFileData(ha, hf, szFileName, szNewFileName); // Update the MD5 of the raw block - if(nError == ERROR_SUCCESS && ha->pHeader->dwRawChunkSize != 0) + if(dwErrCode == ERROR_SUCCESS && ha->pHeader->dwRawChunkSize != 0) { RawDataOffs = ha->MpqPos + pFileEntry->ByteOffset; WriteMpqDataMD5(ha->pStream, @@ -1207,18 +1207,18 @@ bool WINAPI SFileRenameFile(HANDLE hMpq, const char * szFileName, const char * s } else { - nError = GetLastError(); + dwErrCode = GetLastError(); } } // We also need to rebuild the HET table, if present - if(nError == ERROR_SUCCESS && ha->pHetTable != NULL) - nError = RebuildHetTable(ha); + if(dwErrCode == ERROR_SUCCESS && ha->pHetTable != NULL) + dwErrCode = RebuildHetTable(ha); // Resolve error and exit - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } //----------------------------------------------------------------------------- diff --git a/src/SFileAttributes.cpp b/src/SFileAttributes.cpp index 77464f0..f998e47 100644 --- a/src/SFileAttributes.cpp +++ b/src/SFileAttributes.cpp @@ -140,7 +140,7 @@ static DWORD CheckSizeOfAttributesFile(DWORD cbAttrFile, DWORD dwAttrFlags, DWOR return 0; } -static int LoadAttributesFile(TMPQArchive * ha, LPBYTE pbAttrFile, DWORD cbAttrFile) +static DWORD LoadAttributesFile(TMPQArchive * ha, LPBYTE pbAttrFile, DWORD cbAttrFile) { LPBYTE pbAttrFileEnd = pbAttrFile + cbAttrFile; LPBYTE pbAttrPtr = pbAttrFile; @@ -357,13 +357,13 @@ static LPBYTE CreateAttributesFile(TMPQArchive * ha, DWORD * pcbAttrFile) //----------------------------------------------------------------------------- // Public functions (internal use by StormLib) -int SAttrLoadAttributes(TMPQArchive * ha) +DWORD SAttrLoadAttributes(TMPQArchive * ha) { HANDLE hFile = NULL; LPBYTE pbAttrFile; DWORD dwBytesRead; DWORD cbAttrFile = 0; - int nError = ERROR_FILE_CORRUPT; + DWORD dwErrCode = ERROR_FILE_CORRUPT; // File table must be initialized assert(ha->pFileTable != NULL); @@ -393,7 +393,7 @@ int SAttrLoadAttributes(TMPQArchive * ha) // Load the entire file to memory SFileReadFile(hFile, pbAttrFile, cbAttrFile, &dwBytesRead, NULL); if(dwBytesRead == cbAttrFile) - nError = LoadAttributesFile(ha, pbAttrFile, cbAttrFile); + dwErrCode = LoadAttributesFile(ha, pbAttrFile, cbAttrFile); // Free the buffer STORM_FREE(pbAttrFile); @@ -404,16 +404,16 @@ int SAttrLoadAttributes(TMPQArchive * ha) SFileCloseFile(hFile); } - return nError; + return dwErrCode; } // Saves the (attributes) to the MPQ -int SAttrFileSaveToMpq(TMPQArchive * ha) +DWORD SAttrFileSaveToMpq(TMPQArchive * ha) { TMPQFile * hf = NULL; LPBYTE pbAttrFile; DWORD cbAttrFile = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Only save the attributes if we should do so if(ha->dwFileFlags2 != 0) @@ -433,7 +433,7 @@ int SAttrFileSaveToMpq(TMPQArchive * ha) ha->dwFileFlags2 = GetDefaultSpecialFileFlags(cbAttrFile, ha->pHeader->wFormatVersion); // Create the attributes file in the MPQ - nError = SFileAddFile_Init(ha, ATTRIBUTES_NAME, + dwErrCode = SFileAddFile_Init(ha, ATTRIBUTES_NAME, 0, cbAttrFile, LANG_NEUTRAL, @@ -441,10 +441,10 @@ int SAttrFileSaveToMpq(TMPQArchive * ha) &hf); // Write the attributes file raw data to it - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Write the content of the attributes file to the MPQ - nError = SFileAddFile_Write(hf, pbAttrFile, cbAttrFile, MPQ_COMPRESSION_ZLIB); + dwErrCode = SFileAddFile_Write(hf, pbAttrFile, cbAttrFile, MPQ_COMPRESSION_ZLIB); SFileAddFile_Finish(hf); } @@ -458,11 +458,11 @@ int SAttrFileSaveToMpq(TMPQArchive * ha) else { // If the (attributes) file would be empty, its OK - nError = (cbAttrFile == 0) ? ERROR_SUCCESS : ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = (cbAttrFile == 0) ? ERROR_SUCCESS : ERROR_NOT_ENOUGH_MEMORY; } } - return nError; + return dwErrCode; } //----------------------------------------------------------------------------- diff --git a/src/SFileCompactArchive.cpp b/src/SFileCompactArchive.cpp index 1fed524..d4525b6 100644 --- a/src/SFileCompactArchive.cpp +++ b/src/SFileCompactArchive.cpp @@ -18,15 +18,15 @@ /* Local functions */ /*****************************************************************************/ -static int CheckIfAllFilesKnown(TMPQArchive * ha) +static DWORD CheckIfAllFilesKnown(TMPQArchive * ha) { TFileEntry * pFileTableEnd = ha->pFileTable + ha->dwFileTableSize; TFileEntry * pFileEntry; DWORD dwBlockIndex = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Verify the file table - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { for(pFileEntry = ha->pFileTable; pFileEntry < pFileTableEnd; pFileEntry++, dwBlockIndex++) { @@ -36,22 +36,22 @@ static int CheckIfAllFilesKnown(TMPQArchive * ha) // The name must be valid and must not be a pseudo-name if(pFileEntry->szFileName == NULL || IsPseudoFileName(pFileEntry->szFileName, NULL)) { - nError = ERROR_UNKNOWN_FILE_NAMES; + dwErrCode = ERROR_UNKNOWN_FILE_NAMES; break; } } } } - return nError; + return dwErrCode; } -static int CheckIfAllKeysKnown(TMPQArchive * ha, const TCHAR * szListFile, LPDWORD pFileKeys) +static DWORD CheckIfAllKeysKnown(TMPQArchive * ha, const TCHAR * szListFile, LPDWORD pFileKeys) { TFileEntry * pFileTableEnd = ha->pFileTable + ha->dwFileTableSize; TFileEntry * pFileEntry; DWORD dwBlockIndex = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Add the listfile to the MPQ if(szListFile != NULL) @@ -60,11 +60,11 @@ static int CheckIfAllKeysKnown(TMPQArchive * ha, const TCHAR * szListFile, LPDWO if(ha->pfnCompactCB != NULL) ha->pfnCompactCB(ha->pvCompactUserData, CCB_CHECKING_FILES, ha->CompactBytesProcessed, ha->CompactTotalBytes); - nError = SFileAddListFile((HANDLE)ha, szListFile); + dwErrCode = SFileAddListFile((HANDLE)ha, szListFile); } // Verify the file table - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { for(pFileEntry = ha->pFileTable; pFileEntry < pFileTableEnd; pFileEntry++, dwBlockIndex++) { @@ -84,16 +84,16 @@ static int CheckIfAllKeysKnown(TMPQArchive * ha, const TCHAR * szListFile, LPDWO // We don't know the encryption key of this file, // thus we cannot compact the file - nError = ERROR_UNKNOWN_FILE_NAMES; + dwErrCode = ERROR_UNKNOWN_FILE_NAMES; break; } } } - return nError; + return dwErrCode; } -static int CopyNonMpqData( +static DWORD CopyNonMpqData( TMPQArchive * ha, TFileStream * pSrcStream, TFileStream * pTrgStream, @@ -103,7 +103,7 @@ static int CopyNonMpqData( ULONGLONG DataSize = ByteCount; DWORD dwToRead; char DataBuffer[0x1000]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Copy the data while(DataSize > 0) @@ -116,14 +116,14 @@ static int CopyNonMpqData( // Read from the source stream if(!FileStream_Read(pSrcStream, &ByteOffset, DataBuffer, dwToRead)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } // Write to the target stream if(!FileStream_Write(pTrgStream, NULL, DataBuffer, dwToRead)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -139,11 +139,11 @@ static int CopyNonMpqData( DataSize -= dwToRead; } - return nError; + return dwErrCode; } // Copies all file sectors into another archive. -static int CopyMpqFileSectors( +static DWORD CopyMpqFileSectors( TMPQArchive * ha, TMPQFile * hf, TFileStream * pNewStream, @@ -156,11 +156,11 @@ static int CopyMpqFileSectors( DWORD dwFileKey1 = 0; // File key used for decryption DWORD dwFileKey2 = 0; // File key used for encryption DWORD dwCmpSize = 0; // Compressed file size, including patch header - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Resolve decryption keys. Note that the file key given // in the TMPQFile structure also includes the key adjustment - if(nError == ERROR_SUCCESS && (pFileEntry->dwFlags & MPQ_FILE_ENCRYPTED)) + if(dwErrCode == ERROR_SUCCESS && (pFileEntry->dwFlags & MPQ_FILE_ENCRYPTED)) { dwFileKey2 = dwFileKey1 = hf->dwFileKey; if(pFileEntry->dwFlags & MPQ_FILE_FIX_KEY) @@ -171,18 +171,18 @@ static int CopyMpqFileSectors( } // If we have to save patch header, do it - if(nError == ERROR_SUCCESS && hf->pPatchInfo != NULL) + if(dwErrCode == ERROR_SUCCESS && hf->pPatchInfo != NULL) { BSWAP_ARRAY32_UNSIGNED(hf->pPatchInfo, sizeof(DWORD) * 3); if(!FileStream_Write(pNewStream, NULL, hf->pPatchInfo, hf->pPatchInfo->dwLength)) - nError = GetLastError(); + dwErrCode = GetLastError(); // Save the size of the patch info dwPatchSize = hf->pPatchInfo->dwLength; } // If we have to save sector offset table, do it. - if(nError == ERROR_SUCCESS && hf->SectorOffsets != NULL) + if(dwErrCode == ERROR_SUCCESS && hf->SectorOffsets != NULL) { DWORD * SectorOffsetsCopy = STORM_ALLOC(DWORD, hf->SectorOffsets[0] / sizeof(DWORD)); DWORD dwSectorOffsLen = hf->SectorOffsets[0]; @@ -191,10 +191,10 @@ static int CopyMpqFileSectors( assert(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK); if(SectorOffsetsCopy == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; // Encrypt the secondary sector offset table and write it to the target file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { memcpy(SectorOffsetsCopy, hf->SectorOffsets, dwSectorOffsLen); if(pFileEntry->dwFlags & MPQ_FILE_ENCRYPTED) @@ -202,7 +202,7 @@ static int CopyMpqFileSectors( BSWAP_ARRAY32_UNSIGNED(SectorOffsetsCopy, dwSectorOffsLen); if(!FileStream_Write(pNewStream, NULL, SectorOffsetsCopy, dwSectorOffsLen)) - nError = GetLastError(); + dwErrCode = GetLastError(); dwBytesToCopy -= dwSectorOffsLen; dwCmpSize += dwSectorOffsLen; @@ -220,7 +220,7 @@ static int CopyMpqFileSectors( // Now we have to copy all file sectors. We do it without // recompression, because recompression is not necessary in this case - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { for(DWORD dwSector = 0; dwSector < hf->dwSectorCount; dwSector++) { @@ -244,7 +244,7 @@ static int CopyMpqFileSectors( // Read the file sector if(!FileStream_Read(ha->pStream, &RawFilePos, hf->pbFileSector, dwRawDataInSector)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -262,7 +262,7 @@ static int CopyMpqFileSectors( // Now write the sector back to the file if(!FileStream_Write(pNewStream, NULL, hf->pbFileSector, dwRawDataInSector)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -281,7 +281,7 @@ static int CopyMpqFileSectors( // Copy the sector CRCs, if any // Sector CRCs are always compressed (not imploded) and unencrypted - if(nError == ERROR_SUCCESS && hf->SectorOffsets != NULL && hf->SectorChksums != NULL) + if(dwErrCode == ERROR_SUCCESS && hf->SectorOffsets != NULL && hf->SectorChksums != NULL) { DWORD dwCrcLength; @@ -289,10 +289,10 @@ static int CopyMpqFileSectors( if(dwCrcLength != 0) { if(!FileStream_Read(ha->pStream, NULL, hf->SectorChksums, dwCrcLength)) - nError = GetLastError(); + dwErrCode = GetLastError(); if(!FileStream_Write(pNewStream, NULL, hf->SectorChksums, dwCrcLength)) - nError = GetLastError(); + dwErrCode = GetLastError(); // Update compact progress if(ha->pfnCompactCB != NULL) @@ -312,7 +312,7 @@ static int CopyMpqFileSectors( // Examples: // 2012 - WoW\15354\locale-enGB.MPQ:DBFilesClient\SpellLevels.dbc // 2012 - WoW\15354\locale-enGB.MPQ:Interface\AddOns\Blizzard_AuctionUI\Blizzard_AuctionUI.xml - if(nError == ERROR_SUCCESS && dwBytesToCopy != 0) + if(dwErrCode == ERROR_SUCCESS && dwBytesToCopy != 0) { LPBYTE pbExtraData; @@ -321,30 +321,30 @@ static int CopyMpqFileSectors( if(pbExtraData != NULL) { if(!FileStream_Read(ha->pStream, NULL, pbExtraData, dwBytesToCopy)) - nError = GetLastError(); + dwErrCode = GetLastError(); if(!FileStream_Write(pNewStream, NULL, pbExtraData, dwBytesToCopy)) - nError = GetLastError(); + dwErrCode = GetLastError(); // Include these extra data in the compressed size dwCmpSize += dwBytesToCopy; STORM_FREE(pbExtraData); } else - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } // Write the MD5's of the raw file data, if needed - if(nError == ERROR_SUCCESS && ha->pHeader->dwRawChunkSize != 0) + if(dwErrCode == ERROR_SUCCESS && ha->pHeader->dwRawChunkSize != 0) { - nError = WriteMpqDataMD5(pNewStream, + dwErrCode = WriteMpqDataMD5(pNewStream, ha->MpqPos + MpqFilePos, pFileEntry->dwCmpSize, ha->pHeader->dwRawChunkSize); } // Verify the number of bytes written - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // At this point, number of bytes written should be exactly // the same like the compressed file size. If it isn't, @@ -362,21 +362,21 @@ static int CopyMpqFileSectors( if(!(dwCmpSize <= pFileEntry->dwCmpSize && pFileEntry->dwCmpSize <= dwCmpSize + dwPatchSize)) { - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; assert(false); } } - return nError; + return dwErrCode; } -static int CopyMpqFiles(TMPQArchive * ha, LPDWORD pFileKeys, TFileStream * pNewStream) +static DWORD CopyMpqFiles(TMPQArchive * ha, LPDWORD pFileKeys, TFileStream * pNewStream) { TFileEntry * pFileTableEnd = ha->pFileTable + ha->dwFileTableSize; TFileEntry * pFileEntry; TMPQFile * hf = NULL; ULONGLONG MpqFilePos; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Walk through all files and write them to the destination MPQ archive for(pFileEntry = ha->pFileTable; pFileEntry < pFileTableEnd; pFileEntry++) @@ -403,32 +403,32 @@ static int CopyMpqFiles(TMPQArchive * ha, LPDWORD pFileKeys, TFileStream * pNewS // If the file is a patch file, load the patch header if(pFileEntry->dwFlags & MPQ_FILE_PATCH_FILE) { - nError = AllocatePatchInfo(hf, true); - if(nError != ERROR_SUCCESS) + dwErrCode = AllocatePatchInfo(hf, true); + if(dwErrCode != ERROR_SUCCESS) break; } // Allocate buffers for file sector and sector offset table - nError = AllocateSectorBuffer(hf); - if(nError != ERROR_SUCCESS) + dwErrCode = AllocateSectorBuffer(hf); + if(dwErrCode != ERROR_SUCCESS) break; // Also allocate sector offset table and sector checksum table - nError = AllocateSectorOffsets(hf, true); - if(nError != ERROR_SUCCESS) + dwErrCode = AllocateSectorOffsets(hf, true); + if(dwErrCode != ERROR_SUCCESS) break; // Also load sector checksums, if any if(pFileEntry->dwFlags & MPQ_FILE_SECTOR_CRC) { - nError = AllocateSectorChecksums(hf, false); - if(nError != ERROR_SUCCESS) + dwErrCode = AllocateSectorChecksums(hf, false); + if(dwErrCode != ERROR_SUCCESS) break; } // Copy all file sectors - nError = CopyMpqFileSectors(ha, hf, pNewStream, MpqFilePos); - if(nError != ERROR_SUCCESS) + dwErrCode = CopyMpqFileSectors(ha, hf, pNewStream, MpqFilePos); + if(dwErrCode != ERROR_SUCCESS) break; // Free buffers. This also sets "hf" to NULL. @@ -443,7 +443,7 @@ static int CopyMpqFiles(TMPQArchive * ha, LPDWORD pFileKeys, TFileStream * pNewS // Cleanup and exit if(hf != NULL) FreeFileHandle(hf); - return nError; + return dwErrCode; } /*****************************************************************************/ @@ -464,45 +464,45 @@ bool WINAPI SFileSetMaxFileCount(HANDLE hMpq, DWORD dwMaxFileCount) { TMPQArchive * ha = (TMPQArchive *)hMpq; DWORD dwNewHashTableSize = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Test the valid parameters if(!IsValidMpqHandle(hMpq)) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(ha->dwFlags & MPQ_FLAG_READ_ONLY) - nError = ERROR_ACCESS_DENIED; + dwErrCode = ERROR_ACCESS_DENIED; if(dwMaxFileCount < ha->dwFileTableSize) - nError = ERROR_DISK_FULL; + dwErrCode = ERROR_DISK_FULL; // ALL file names must be known in order to be able to rebuild hash table - if(nError == ERROR_SUCCESS && ha->pHashTable != NULL) + if(dwErrCode == ERROR_SUCCESS && ha->pHashTable != NULL) { - nError = CheckIfAllFilesKnown(ha); - if(nError == ERROR_SUCCESS) + dwErrCode = CheckIfAllFilesKnown(ha); + if(dwErrCode == ERROR_SUCCESS) { // Calculate the hash table size for the new file limit dwNewHashTableSize = GetNearestPowerOfTwo(dwMaxFileCount); // Rebuild both file tables - nError = RebuildFileTable(ha, dwNewHashTableSize); + dwErrCode = RebuildFileTable(ha, dwNewHashTableSize); } } // We always have to rebuild the (attributes) file due to file table change - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Invalidate (listfile) and (attributes) InvalidateInternalFiles(ha); // Rebuild the HET table, if we have any if(ha->pHetTable != NULL) - nError = RebuildHetTable(ha); + dwErrCode = RebuildHetTable(ha); } // Return the error - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } //----------------------------------------------------------------------------- @@ -531,41 +531,41 @@ bool WINAPI SFileCompactArchive(HANDLE hMpq, const TCHAR * szListFile, bool /* b ULONGLONG ByteCount; LPDWORD pFileKeys = NULL; TCHAR szTempFile[MAX_PATH+1] = _T(""); - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Test the valid parameters if(!IsValidMpqHandle(hMpq)) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(ha->dwFlags & MPQ_FLAG_READ_ONLY) - nError = ERROR_ACCESS_DENIED; + dwErrCode = ERROR_ACCESS_DENIED; // If the MPQ is changed at this moment, we have to flush the archive - if(nError == ERROR_SUCCESS && (ha->dwFlags & MPQ_FLAG_CHANGED)) + if(dwErrCode == ERROR_SUCCESS && (ha->dwFlags & MPQ_FLAG_CHANGED)) { SFileFlushArchive(hMpq); } // Create the table with file keys - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if((pFileKeys = STORM_ALLOC(DWORD, ha->dwFileTableSize)) != NULL) memset(pFileKeys, 0, sizeof(DWORD) * ha->dwFileTableSize); else - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } // First of all, we have to check of we are able to decrypt all files. // If not, sorry, but the archive cannot be compacted. - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Initialize the progress variables for compact callback FileStream_GetSize(ha->pStream, &(ha->CompactTotalBytes)); ha->CompactBytesProcessed = 0; - nError = CheckIfAllKeysKnown(ha, szListFile, pFileKeys); + dwErrCode = CheckIfAllKeysKnown(ha, szListFile, pFileKeys); } // Get the temporary file name and create it - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Create temporary file name. Prevent buffer overflow StringCopy(szTempFile, _countof(szTempFile), FileStream_GetFileName(ha->pStream)); @@ -574,11 +574,11 @@ bool WINAPI SFileCompactArchive(HANDLE hMpq, const TCHAR * szListFile, bool /* b // Create temporary file pTempStream = FileStream_CreateFile(szTempFile, STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE); if(pTempStream == NULL) - nError = GetLastError(); + dwErrCode = GetLastError(); } // Write the data before MPQ user data (if any) - if(nError == ERROR_SUCCESS && ha->UserDataPos != 0) + if(dwErrCode == ERROR_SUCCESS && ha->UserDataPos != 0) { // Inform the application about the progress if(ha->pfnCompactCB != NULL) @@ -586,11 +586,11 @@ bool WINAPI SFileCompactArchive(HANDLE hMpq, const TCHAR * szListFile, bool /* b ByteOffset = 0; ByteCount = ha->UserDataPos; - nError = CopyNonMpqData(ha, ha->pStream, pTempStream, ByteOffset, ByteCount); + dwErrCode = CopyNonMpqData(ha, ha->pStream, pTempStream, ByteOffset, ByteCount); } // Write the MPQ user data (if any) - if(nError == ERROR_SUCCESS && ha->MpqPos > ha->UserDataPos) + if(dwErrCode == ERROR_SUCCESS && ha->MpqPos > ha->UserDataPos) { // At this point, we assume that the user data size is equal // to pUserData->dwHeaderOffs. @@ -600,11 +600,11 @@ bool WINAPI SFileCompactArchive(HANDLE hMpq, const TCHAR * szListFile, bool /* b assert(ha->pUserData != NULL); assert(ha->pUserData->dwHeaderOffs == ByteCount); - nError = CopyNonMpqData(ha, ha->pStream, pTempStream, ByteOffset, ByteCount); + dwErrCode = CopyNonMpqData(ha, ha->pStream, pTempStream, ByteOffset, ByteCount); } // Write the MPQ header - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { TMPQHeader SaveMpqHeader; @@ -615,28 +615,28 @@ bool WINAPI SFileCompactArchive(HANDLE hMpq, const TCHAR * szListFile, bool /* b BSWAP_TMPQHEADER(&SaveMpqHeader, MPQ_FORMAT_VERSION_3); BSWAP_TMPQHEADER(&SaveMpqHeader, MPQ_FORMAT_VERSION_4); if(!FileStream_Write(pTempStream, NULL, &SaveMpqHeader, ha->pHeader->dwHeaderSize)) - nError = GetLastError(); + dwErrCode = GetLastError(); // Update the progress ha->CompactBytesProcessed += ha->pHeader->dwHeaderSize; } // Now copy all files - if(nError == ERROR_SUCCESS) - nError = CopyMpqFiles(ha, pFileKeys, pTempStream); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = CopyMpqFiles(ha, pFileKeys, pTempStream); // If succeeded, switch the streams - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { ha->dwFlags |= MPQ_FLAG_CHANGED; if(FileStream_Replace(ha->pStream, pTempStream)) pTempStream = NULL; else - nError = ERROR_CAN_NOT_COMPLETE; + dwErrCode = ERROR_CAN_NOT_COMPLETE; } // Final user notification - if(nError == ERROR_SUCCESS && ha->pfnCompactCB != NULL) + if(dwErrCode == ERROR_SUCCESS && ha->pfnCompactCB != NULL) { ha->CompactBytesProcessed += (ha->pHeader->dwHashTableSize * sizeof(TMPQHash)); ha->CompactBytesProcessed += (ha->dwFileTableSize * sizeof(TMPQBlock)); @@ -648,7 +648,7 @@ bool WINAPI SFileCompactArchive(HANDLE hMpq, const TCHAR * szListFile, bool /* b FileStream_Close(pTempStream); if(pFileKeys != NULL) STORM_FREE(pFileKeys); - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } diff --git a/src/SFileCreateArchive.cpp b/src/SFileCreateArchive.cpp index 4185f3d..742b829 100644 --- a/src/SFileCreateArchive.cpp +++ b/src/SFileCreateArchive.cpp @@ -40,12 +40,12 @@ static USHORT GetSectorSizeShift(DWORD dwSectorSize) return wSectorSizeShift; } -static int WriteNakedMPQHeader(TMPQArchive * ha) +static DWORD WriteNakedMPQHeader(TMPQArchive * ha) { TMPQHeader * pHeader = ha->pHeader; TMPQHeader Header; DWORD dwBytesToWrite = pHeader->dwHeaderSize; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Prepare the naked MPQ header memset(&Header, 0, sizeof(TMPQHeader)); @@ -61,9 +61,9 @@ static int WriteNakedMPQHeader(TMPQArchive * ha) BSWAP_TMPQHEADER(&Header, MPQ_FORMAT_VERSION_3); BSWAP_TMPQHEADER(&Header, MPQ_FORMAT_VERSION_4); if(!FileStream_Write(ha->pStream, &ha->MpqPos, &Header, dwBytesToWrite)) - nError = GetLastError(); + dwErrCode = GetLastError(); - return nError; + return dwErrCode; } //----------------------------------------------------------------------------- @@ -109,7 +109,7 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea DWORD dwHashTableSize = 0; DWORD dwReservedFiles = 0; // Number of reserved file entries DWORD dwMpqFlags = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Check the parameters, if they are valid if(szMpqName == NULL || *szMpqName == 0 || pCreateInfo == NULL || phMpq == NULL) @@ -184,7 +184,7 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea FileStream_GetSize(pStream, &MpqPos); MpqPos = (MpqPos + 0x1FF) & (ULONGLONG)0xFFFFFFFFFFFFFE00ULL; if(!FileStream_SetSize(pStream, MpqPos)) - nError = GetLastError(); + dwErrCode = GetLastError(); #ifdef _DEBUG // Debug code, used for testing StormLib @@ -192,14 +192,14 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea #endif // Create the archive handle - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if((ha = STORM_ALLOC(TMPQArchive, 1)) == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } // Fill the MPQ archive handle structure - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { memset(ha, 0, sizeof(TMPQArchive)); ha->pfnHashString = HashStringSlash; @@ -236,39 +236,39 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea pHeader->dwRawChunkSize = pCreateInfo->dwRawChunkSize; // Write the naked MPQ header - nError = WriteNakedMPQHeader(ha); + dwErrCode = WriteNakedMPQHeader(ha); } // Create initial HET table, if the caller required an MPQ format 3.0 or newer - if(nError == ERROR_SUCCESS && pCreateInfo->dwMpqVersion >= MPQ_FORMAT_VERSION_3 && pCreateInfo->dwMaxFileCount != 0) + if(dwErrCode == ERROR_SUCCESS && pCreateInfo->dwMpqVersion >= MPQ_FORMAT_VERSION_3 && pCreateInfo->dwMaxFileCount != 0) { ha->pHetTable = CreateHetTable(ha->dwFileTableSize, 0, 0x40, NULL); if(ha->pHetTable == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } // Create initial hash table - if(nError == ERROR_SUCCESS && dwHashTableSize != 0) + if(dwErrCode == ERROR_SUCCESS && dwHashTableSize != 0) { - nError = CreateHashTable(ha, dwHashTableSize); + dwErrCode = CreateHashTable(ha, dwHashTableSize); } // Create initial file table - if(nError == ERROR_SUCCESS && ha->dwMaxFileCount != 0) + if(dwErrCode == ERROR_SUCCESS && ha->dwMaxFileCount != 0) { - nError = CreateFileTable(ha, ha->dwMaxFileCount); + dwErrCode = CreateFileTable(ha, ha->dwMaxFileCount); } // Cleanup : If an error, delete all buffers and return - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) { FileStream_Close(pStream); FreeArchiveHandle(ha); - SetLastError(nError); + SetLastError(dwErrCode); ha = NULL; } // Return the values *phMpq = (HANDLE)ha; - return (nError == ERROR_SUCCESS); + return (dwErrCode == ERROR_SUCCESS); } diff --git a/src/SFileExtractFile.cpp b/src/SFileExtractFile.cpp index cabde49..6b3b767 100644 --- a/src/SFileExtractFile.cpp +++ b/src/SFileExtractFile.cpp @@ -16,41 +16,41 @@ bool WINAPI SFileExtractFile(HANDLE hMpq, const char * szToExtract, const TCHAR { TFileStream * pLocalFile = NULL; HANDLE hMpqFile = NULL; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Open the MPQ file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(!SFileOpenFileEx(hMpq, szToExtract, dwSearchScope, &hMpqFile)) - nError = GetLastError(); + dwErrCode = GetLastError(); } // Create the local file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { pLocalFile = FileStream_CreateFile(szExtracted, 0); if(pLocalFile == NULL) - nError = GetLastError(); + dwErrCode = GetLastError(); } // Copy the file's content - while(nError == ERROR_SUCCESS) + while(dwErrCode == ERROR_SUCCESS) { char szBuffer[0x1000]; DWORD dwTransferred = 0; // dwTransferred is only set to nonzero if something has been read. - // nError can be ERROR_SUCCESS or ERROR_HANDLE_EOF + // dwErrCode can be ERROR_SUCCESS or ERROR_HANDLE_EOF if(!SFileReadFile(hMpqFile, szBuffer, sizeof(szBuffer), &dwTransferred, NULL)) - nError = GetLastError(); - if(nError == ERROR_HANDLE_EOF) - nError = ERROR_SUCCESS; + dwErrCode = GetLastError(); + if(dwErrCode == ERROR_HANDLE_EOF) + dwErrCode = ERROR_SUCCESS; if(dwTransferred == 0) break; // If something has been actually read, write it if(!FileStream_Write(pLocalFile, NULL, szBuffer, dwTransferred)) - nError = GetLastError(); + dwErrCode = GetLastError(); } // Close the files @@ -58,7 +58,7 @@ bool WINAPI SFileExtractFile(HANDLE hMpq, const char * szToExtract, const TCHAR SFileCloseFile(hMpqFile); if(pLocalFile != NULL) FileStream_Close(pLocalFile); - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } diff --git a/src/SFileFindFile.cpp b/src/SFileFindFile.cpp index a05d5c5..ef8b834 100644 --- a/src/SFileFindFile.cpp +++ b/src/SFileFindFile.cpp @@ -291,7 +291,7 @@ static bool DoMPQSearch_FileEntry( return false; } -static int DoMPQSearch_HashTable(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData, TMPQArchive * ha) +static DWORD DoMPQSearch_HashTable(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData, TMPQArchive * ha) { TMPQHash * pHashTableEnd = ha->pHashTable + ha->pHeader->dwHashTableSize; TMPQHash * pHash; @@ -315,7 +315,7 @@ static int DoMPQSearch_HashTable(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileDa return ERROR_NO_MORE_FILES; } -static int DoMPQSearch_FileTable(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData, TMPQArchive * ha) +static DWORD DoMPQSearch_FileTable(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData, TMPQArchive * ha) { TFileEntry * pFileTableEnd = ha->pFileTable + ha->dwFileTableSize; TFileEntry * pFileEntry; @@ -336,10 +336,10 @@ static int DoMPQSearch_FileTable(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileDa } // Performs one MPQ search -static int DoMPQSearch(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData) +static DWORD DoMPQSearch(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData) { TMPQArchive * ha = hs->ha; - int nError; + DWORD dwErrCode; // Start searching with base MPQ while(ha != NULL) @@ -348,10 +348,10 @@ static int DoMPQSearch(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData) // in order to catch hash table index and file locale. // Note: If multiple hash table entries, point to the same block entry, // we need, to report them all - nError = (ha->pHashTable != NULL) ? DoMPQSearch_HashTable(hs, lpFindFileData, ha) - : DoMPQSearch_FileTable(hs, lpFindFileData, ha); - if(nError == ERROR_SUCCESS) - return nError; + dwErrCode = (ha->pHashTable != NULL) ? DoMPQSearch_HashTable(hs, lpFindFileData, ha) + : DoMPQSearch_FileTable(hs, lpFindFileData, ha); + if(dwErrCode == ERROR_SUCCESS) + return dwErrCode; // If there is no more patches in the chain, stop it. // This also keeps hs->ha non-NULL, which is required @@ -387,30 +387,30 @@ HANDLE WINAPI SFileFindFirstFile(HANDLE hMpq, const char * szMask, SFILE_FIND_DA TMPQArchive * ha = (TMPQArchive *)hMpq; TMPQSearch * hs = NULL; size_t nSize = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Check for the valid parameters if(!IsValidMpqHandle(hMpq)) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(szMask == NULL || lpFindFileData == NULL) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; // Include the listfile into the MPQ's internal listfile // Note that if the listfile name is NULL, do nothing because the // internal listfile is always included. - if(nError == ERROR_SUCCESS && szListFile != NULL && *szListFile != 0) - nError = SFileAddListFile((HANDLE)ha, szListFile); + if(dwErrCode == ERROR_SUCCESS && szListFile != NULL && *szListFile != 0) + dwErrCode = SFileAddListFile((HANDLE)ha, szListFile); // Allocate the structure for MPQ search - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { nSize = sizeof(TMPQSearch) + strlen(szMask) + 1; if((hs = (TMPQSearch *)STORM_ALLOC(char, nSize)) == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } // Perform the first search - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { memset(hs, 0, sizeof(TMPQSearch)); strcpy(hs->szSearchMask, szMask); @@ -427,21 +427,21 @@ HANDLE WINAPI SFileFindFirstFile(HANDLE hMpq, const char * szMask, SFILE_FIND_DA if(hs->pSearchTable != NULL) memset(hs->pSearchTable, 0, hs->dwSearchTableItems * sizeof(TFileEntry *)); else - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } } // Perform first item searching - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = DoMPQSearch(hs, lpFindFileData); + dwErrCode = DoMPQSearch(hs, lpFindFileData); } // Cleanup - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) { FreeMPQSearch(hs); - SetLastError(nError); + SetLastError(dwErrCode); } // Return the result value @@ -451,20 +451,20 @@ HANDLE WINAPI SFileFindFirstFile(HANDLE hMpq, const char * szMask, SFILE_FIND_DA bool WINAPI SFileFindNextFile(HANDLE hFind, SFILE_FIND_DATA * lpFindFileData) { TMPQSearch * hs = IsValidSearchHandle(hFind); - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Check the parameters if(hs == NULL) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(lpFindFileData == NULL) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; - if(nError == ERROR_SUCCESS) - nError = DoMPQSearch(hs, lpFindFileData); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = DoMPQSearch(hs, lpFindFileData); - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } bool WINAPI SFileFindClose(HANDLE hFind) diff --git a/src/SFileGetFileInfo.cpp b/src/SFileGetFileInfo.cpp index ff1a479..6c217a6 100644 --- a/src/SFileGetFileInfo.cpp +++ b/src/SFileGetFileInfo.cpp @@ -42,7 +42,7 @@ static DWORD GetMpqFileCount(TMPQArchive * ha) return dwFileCount; } -static bool GetInfo_ReturnError(DWORD dwErrCode) +static bool GetInfo_ReturdwErrCode(DWORD dwErrCode) { SetLastError(dwErrCode); return false; @@ -56,11 +56,11 @@ static bool GetInfo_BufferCheck(void * pvFileInfo, DWORD cbFileInfo, DWORD cbDat // Check for sufficient buffer if(cbData > cbFileInfo) - return GetInfo_ReturnError(ERROR_INSUFFICIENT_BUFFER); + return GetInfo_ReturdwErrCode(ERROR_INSUFFICIENT_BUFFER); // If the buffer size is sufficient, check for valid user buffer if(pvFileInfo == NULL) - return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); + return GetInfo_ReturdwErrCode(ERROR_INVALID_PARAMETER); // Buffers and sizes are OK, we are ready to proceed file copying return true; @@ -150,7 +150,7 @@ static bool GetInfo_PatchChain(TMPQFile * hf, void * pvFileInfo, DWORD cbFileInf // Patch chain is only supported on MPQ files. Local files are not supported. if(hf->pStream != NULL) - return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); + return GetInfo_ReturdwErrCode(ERROR_INVALID_PARAMETER); // Calculate the necessary length of the multi-string for(hfTemp = hf; hfTemp != NULL; hfTemp = hfTemp->hfPatch) @@ -208,13 +208,13 @@ bool WINAPI SFileGetFileInfo( if((int)InfoClass <= (int)SFileMpqFlags) { if((ha = IsValidMpqHandle(hMpqOrFile)) == NULL) - return GetInfo_ReturnError(ERROR_INVALID_HANDLE); + return GetInfo_ReturdwErrCode(ERROR_INVALID_HANDLE); pHeader = ha->pHeader; } else { if((hf = IsValidFileHandle(hMpqOrFile)) == NULL) - return GetInfo_ReturnError(ERROR_INVALID_HANDLE); + return GetInfo_ReturdwErrCode(ERROR_INVALID_HANDLE); pFileEntry = hf->pFileEntry; } @@ -234,12 +234,12 @@ bool WINAPI SFileGetFileInfo( case SFileMpqUserDataHeader: if(ha->pUserData == NULL) - return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); + return GetInfo_ReturdwErrCode(ERROR_INVALID_PARAMETER); return GetInfo_ReadFromFile(pvFileInfo, cbFileInfo, ha->pStream, ha->UserDataPos, sizeof(TMPQUserData), pcbLengthNeeded); case SFileMpqUserData: if(ha->pUserData == NULL) - return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); + return GetInfo_ReturdwErrCode(ERROR_INVALID_PARAMETER); return GetInfo_ReadFromFile(pvFileInfo, cbFileInfo, ha->pStream, ha->UserDataPos + sizeof(TMPQUserData), ha->pUserData->dwHeaderOffs - sizeof(TMPQUserData), pcbLengthNeeded); case SFileMpqHeaderOffset: @@ -260,12 +260,12 @@ bool WINAPI SFileGetFileInfo( case SFileMpqHetHeader: pvSrcFileInfo = LoadExtTable(ha, pHeader->HetTablePos64, (size_t)pHeader->HetTableSize64, HET_TABLE_SIGNATURE, MPQ_KEY_HASH_TABLE); if(pvSrcFileInfo == NULL) - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); return GetInfo_Allocated(pvFileInfo, cbFileInfo, pvSrcFileInfo, sizeof(TMPQHetHeader), pcbLengthNeeded); case SFileMpqHetTable: if((pvSrcFileInfo = LoadHetTable(ha)) == NULL) - return GetInfo_ReturnError(ERROR_NOT_ENOUGH_MEMORY); + return GetInfo_ReturdwErrCode(ERROR_NOT_ENOUGH_MEMORY); return GetInfo_TablePointer(pvFileInfo, cbFileInfo, pvSrcFileInfo, InfoClass, pcbLengthNeeded); case SFileMpqBetTableOffset: @@ -279,7 +279,7 @@ bool WINAPI SFileGetFileInfo( // Retrieve the table and its size pvSrcFileInfo = LoadExtTable(ha, pHeader->BetTablePos64, (size_t)pHeader->BetTableSize64, BET_TABLE_SIGNATURE, MPQ_KEY_BLOCK_TABLE); if(pvSrcFileInfo == NULL) - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); cbSrcFileInfo = sizeof(TMPQBetHeader) + ((TMPQBetHeader *)pvSrcFileInfo)->dwFlagCount * sizeof(DWORD); // It is allowed for the caller to only require BET header @@ -289,7 +289,7 @@ bool WINAPI SFileGetFileInfo( case SFileMpqBetTable: if((pvSrcFileInfo = LoadBetTable(ha)) == NULL) - return GetInfo_ReturnError(ERROR_NOT_ENOUGH_MEMORY); + return GetInfo_ReturdwErrCode(ERROR_NOT_ENOUGH_MEMORY); return GetInfo_TablePointer(pvFileInfo, cbFileInfo, pvSrcFileInfo, InfoClass, pcbLengthNeeded); case SFileMpqHashTableOffset: @@ -318,7 +318,7 @@ bool WINAPI SFileGetFileInfo( case SFileMpqBlockTable: if(MAKE_OFFSET64(pHeader->wBlockTablePosHi, pHeader->dwBlockTablePos) >= ha->FileSize) - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); cbSrcFileInfo = pHeader->dwBlockTableSize * sizeof(TMPQBlock); pvSrcFileInfo = LoadBlockTable(ha, true); return GetInfo_Allocated(pvFileInfo, cbFileInfo, pvSrcFileInfo, cbSrcFileInfo, pcbLengthNeeded); @@ -330,27 +330,27 @@ bool WINAPI SFileGetFileInfo( return GetInfo(pvFileInfo, cbFileInfo, &pHeader->HiBlockTableSize64, sizeof(ULONGLONG), pcbLengthNeeded); case SFileMpqHiBlockTable: - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); case SFileMpqSignatures: if(!QueryMpqSignatureInfo(ha, &SignatureInfo)) - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); return GetInfo(pvFileInfo, cbFileInfo, &SignatureInfo.SignatureTypes, sizeof(DWORD), pcbLengthNeeded); case SFileMpqStrongSignatureOffset: if(QueryMpqSignatureInfo(ha, &SignatureInfo) == false || (SignatureInfo.SignatureTypes & SIGNATURE_TYPE_STRONG) == 0) - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); return GetInfo(pvFileInfo, cbFileInfo, &SignatureInfo.EndMpqData, sizeof(ULONGLONG), pcbLengthNeeded); case SFileMpqStrongSignatureSize: if(QueryMpqSignatureInfo(ha, &SignatureInfo) == false || (SignatureInfo.SignatureTypes & SIGNATURE_TYPE_STRONG) == 0) - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); dwInt32Value = MPQ_STRONG_SIGNATURE_SIZE + 4; return GetInfo(pvFileInfo, cbFileInfo, &dwInt32Value, sizeof(DWORD), pcbLengthNeeded); case SFileMpqStrongSignature: if(QueryMpqSignatureInfo(ha, &SignatureInfo) == false || (SignatureInfo.SignatureTypes & SIGNATURE_TYPE_STRONG) == 0) - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); return GetInfo(pvFileInfo, cbFileInfo, SignatureInfo.Signature, MPQ_STRONG_SIGNATURE_SIZE + 4, pcbLengthNeeded); case SFileMpqArchiveSize64: @@ -374,7 +374,7 @@ bool WINAPI SFileGetFileInfo( case SFileMpqRawChunkSize: if(pHeader->dwRawChunkSize == 0) - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); return GetInfo(pvFileInfo, cbFileInfo, &pHeader->dwRawChunkSize, sizeof(DWORD), pcbLengthNeeded); case SFileMpqStreamFlags: @@ -389,7 +389,7 @@ bool WINAPI SFileGetFileInfo( case SFileInfoFileEntry: if(pFileEntry == NULL) - return GetInfo_ReturnError(ERROR_FILE_NOT_FOUND); + return GetInfo_ReturdwErrCode(ERROR_FILE_NOT_FOUND); return GetInfo_FileEntry(pvFileInfo, cbFileInfo, pFileEntry, pcbLengthNeeded); case SFileInfoHashEntry: @@ -444,7 +444,7 @@ bool WINAPI SFileGetFileInfo( } // Invalid info class - return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); + return GetInfo_ReturdwErrCode(ERROR_INVALID_PARAMETER); } bool WINAPI SFileFreeFileInfo(void * pvFileInfo, SFileInfoClass InfoClass) @@ -518,7 +518,7 @@ static TFileHeader2Ext data2ext[] = {0, 0, 0, 0, NULL} // Terminator }; -static int CreatePseudoFileName(HANDLE hFile, TFileEntry * pFileEntry, char * szFileName) +static DWORD CreatePseudoFileName(HANDLE hFile, TFileEntry * pFileEntry, char * szFileName) { TMPQFile * hf = (TMPQFile *)hFile; // MPQ File handle DWORD FirstBytes[2] = {0, 0}; // The first 4 bytes of the file @@ -563,7 +563,7 @@ static int CreatePseudoFileName(HANDLE hFile, TFileEntry * pFileEntry, char * sz bool WINAPI SFileGetFileName(HANDLE hFile, char * szFileName) { TMPQFile * hf = (TMPQFile *)hFile; // MPQ File handle - int nError = ERROR_INVALID_HANDLE; + DWORD dwErrCode = ERROR_INVALID_HANDLE; // Check valid parameters if(IsValidFileHandle(hFile)) @@ -577,13 +577,13 @@ bool WINAPI SFileGetFileName(HANDLE hFile, char * szFileName) { // If the file name is not there yet, create a pseudo name if(pFileEntry->szFileName == NULL) - nError = CreatePseudoFileName(hFile, pFileEntry, szFileName); + dwErrCode = CreatePseudoFileName(hFile, pFileEntry, szFileName); // Copy the file name to the output buffer, if any if(pFileEntry->szFileName && szFileName) { strcpy(szFileName, pFileEntry->szFileName); - nError = ERROR_SUCCESS; + dwErrCode = ERROR_SUCCESS; } } } @@ -596,12 +596,12 @@ bool WINAPI SFileGetFileName(HANDLE hFile, char * szFileName) const TCHAR * szStreamName = FileStream_GetFileName(hf->pStream); StringCopy(szFileName, MAX_PATH, szStreamName); } - nError = ERROR_SUCCESS; + dwErrCode = ERROR_SUCCESS; } } - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } diff --git a/src/SFileListFile.cpp b/src/SFileListFile.cpp index f94f955..e2b8166 100644 --- a/src/SFileListFile.cpp +++ b/src/SFileListFile.cpp @@ -402,7 +402,7 @@ static LPBYTE CreateListFile(TMPQArchive * ha, DWORD * pcbListFile) // Adds a name into the list of all names. For each locale in the MPQ, // one entry will be created // If the file name is already there, does nothing. -static int SListFileCreateNodeForAllLocales(TMPQArchive * ha, const char * szFileName) +static DWORD SListFileCreateNodeForAllLocales(TMPQArchive * ha, const char * szFileName) { TFileEntry * pFileEntry; TMPQHash * pFirstHash; @@ -442,12 +442,12 @@ static int SListFileCreateNodeForAllLocales(TMPQArchive * ha, const char * szFil } // Saves the whole listfile to the MPQ -int SListFileSaveToMpq(TMPQArchive * ha) +DWORD SListFileSaveToMpq(TMPQArchive * ha) { TMPQFile * hf = NULL; LPBYTE pbListFile; DWORD cbListFile = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Only save the listfile if we should do so if(ha->dwFileFlags1 != 0) @@ -468,7 +468,7 @@ int SListFileSaveToMpq(TMPQArchive * ha) ha->dwFileFlags1 = GetDefaultSpecialFileFlags(cbListFile, ha->pHeader->wFormatVersion); // Create the listfile in the MPQ - nError = SFileAddFile_Init(ha, LISTFILE_NAME, + dwErrCode = SFileAddFile_Init(ha, LISTFILE_NAME, 0, cbListFile, LANG_NEUTRAL, @@ -476,10 +476,10 @@ int SListFileSaveToMpq(TMPQArchive * ha) &hf); // Write the listfile raw data to it - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Write the content of the listfile to the MPQ - nError = SFileAddFile_Write(hf, pbListFile, cbListFile, MPQ_COMPRESSION_ZLIB); + dwErrCode = SFileAddFile_Write(hf, pbListFile, cbListFile, MPQ_COMPRESSION_ZLIB); SFileAddFile_Finish(hf); } @@ -493,14 +493,14 @@ int SListFileSaveToMpq(TMPQArchive * ha) else { // If the (listfile) file would be empty, its OK - nError = (cbListFile == 0) ? ERROR_SUCCESS : ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = (cbListFile == 0) ? ERROR_SUCCESS : ERROR_NOT_ENOUGH_MEMORY; } } - return nError; + return dwErrCode; } -static int SFileAddArbitraryListFile( +static DWORD SFileAddArbitraryListFile( TMPQArchive * ha, HANDLE hMpq, const TCHAR * szListFile, @@ -530,7 +530,7 @@ static int SFileAddArbitraryListFile( return (pCache != NULL) ? ERROR_SUCCESS : ERROR_FILE_CORRUPT; } -static int SFileAddInternalListFile( +static DWORD SFileAddInternalListFile( TMPQArchive * ha, HANDLE hMpq) { @@ -538,7 +538,7 @@ static int SFileAddInternalListFile( TMPQHash * pHash; LCID lcSaveLocale = g_lcFileLocale; DWORD dwMaxSize = MAX_LISTFILE_SIZE; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // If there is hash table, we need to support multiple listfiles // with different locales (BrooDat.mpq) @@ -549,13 +549,13 @@ static int SFileAddInternalListFile( dwMaxSize = 0x40000; pFirstHash = pHash = GetFirstHashEntry(ha, LISTFILE_NAME); - while(nError == ERROR_SUCCESS && pHash != NULL) + while(dwErrCode == ERROR_SUCCESS && pHash != NULL) { // Set the prefered locale to that from list file SFileSetLocale(pHash->lcLocale); // Add that listfile - nError = SFileAddArbitraryListFile(ha, hMpq, NULL, dwMaxSize); + dwErrCode = SFileAddArbitraryListFile(ha, hMpq, NULL, dwMaxSize); // Move to the next hash pHash = GetNextHashEntry(ha, pFirstHash, pHash); @@ -567,11 +567,11 @@ static int SFileAddInternalListFile( else { // Add the single listfile - nError = SFileAddArbitraryListFile(ha, hMpq, NULL, dwMaxSize); + dwErrCode = SFileAddArbitraryListFile(ha, hMpq, NULL, dwMaxSize); } // Return the result of the operation - return nError; + return dwErrCode; } static bool DoListFileSearch(TListFileCache * pCache, SFILE_FIND_DATA * lpFindFileData) @@ -608,18 +608,18 @@ static bool DoListFileSearch(TListFileCache * pCache, SFILE_FIND_DATA * lpFindFi // File functions // Adds a listfile into the MPQ archive. -int WINAPI SFileAddListFile(HANDLE hMpq, const TCHAR * szListFile) +DWORD WINAPI SFileAddListFile(HANDLE hMpq, const TCHAR * szListFile) { TMPQArchive * ha = (TMPQArchive *)hMpq; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Add the listfile for each MPQ in the patch chain while(ha != NULL) { if(szListFile != NULL) - nError = SFileAddArbitraryListFile(ha, NULL, szListFile, MAX_LISTFILE_SIZE); + dwErrCode = SFileAddArbitraryListFile(ha, NULL, szListFile, MAX_LISTFILE_SIZE); else - nError = SFileAddInternalListFile(ha, hMpq); + dwErrCode = SFileAddInternalListFile(ha, hMpq); // Also, add three special files to the listfile: // (listfile) itself, (attributes) and (signature) @@ -631,7 +631,7 @@ int WINAPI SFileAddListFile(HANDLE hMpq, const TCHAR * szListFile) ha = ha->haPatch; } - return nError; + return dwErrCode; } //----------------------------------------------------------------------------- diff --git a/src/SFileOpenArchive.cpp b/src/SFileOpenArchive.cpp index cda8140..ea29850 100644 --- a/src/SFileOpenArchive.cpp +++ b/src/SFileOpenArchive.cpp @@ -96,7 +96,7 @@ static TMPQUserData * IsValidMpqUserData(ULONGLONG ByteOffset, ULONGLONG FileSiz } // This function gets the right positions of the hash table and the block table. -static int VerifyMpqTablePositions(TMPQArchive * ha, ULONGLONG FileSize) +static DWORD VerifyMpqTablePositions(TMPQArchive * ha, ULONGLONG FileSize) { TMPQHeader * pHeader = ha->pHeader; ULONGLONG ByteOffset; @@ -216,7 +216,7 @@ bool WINAPI SFileOpenArchive( LPBYTE pbHeaderBuffer = NULL; // Buffer for searching MPQ header DWORD dwStreamFlags = (dwFlags & STREAM_FLAGS_MASK); MTYPE MapType = MapTypeNotChecked; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Verify the parameters if(szMpqName == NULL || *szMpqName == 0 || phMpq == NULL) @@ -238,30 +238,30 @@ bool WINAPI SFileOpenArchive( return false; // Check the file size. There must be at least 0x20 bytes - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { FileStream_GetSize(pStream, &FileSize); if(FileSize < MPQ_HEADER_SIZE_V1) - nError = ERROR_BAD_FORMAT; + dwErrCode = ERROR_BAD_FORMAT; } // Allocate the MPQhandle - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if((ha = STORM_ALLOC(TMPQArchive, 1)) == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } // Allocate buffer for searching MPQ header - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { pbHeaderBuffer = STORM_ALLOC(BYTE, HEADER_SEARCH_BUFFER_SIZE); if(pbHeaderBuffer == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } // Find the position of MPQ header - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { ULONGLONG ByteOffset = 0; ULONGLONG EndOfSearch = FileSize; @@ -303,7 +303,7 @@ bool WINAPI SFileOpenArchive( // Read the eventual MPQ header if(!FileStream_Read(ha->pStream, &ByteOffset, pbHeaderBuffer, dwBytesAvailable)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -313,7 +313,7 @@ bool WINAPI SFileOpenArchive( // Do nothing if the file is an AVI file if((MapType = CheckMapType(szMpqName, pbHeaderBuffer, dwBytesAvailable)) == MapTypeAviFile) { - nError = ERROR_AVI_FILE; + dwErrCode = ERROR_AVI_FILE; break; } } @@ -355,8 +355,8 @@ bool WINAPI SFileOpenArchive( if(dwHeaderID == g_dwMpqSignature && dwHeaderSize >= MPQ_HEADER_SIZE_V1) { // Now convert the header to version 4 - nError = ConvertMpqHeaderToFormat4(ha, ByteOffset, FileSize, dwFlags, MapType); - if(nError != ERROR_FAKE_MPQ_HEADER) + dwErrCode = ConvertMpqHeaderToFormat4(ha, ByteOffset, FileSize, dwFlags, MapType); + if(dwErrCode != ERROR_FAKE_MPQ_HEADER) { bSearchComplete = true; break; @@ -367,7 +367,7 @@ bool WINAPI SFileOpenArchive( if(MapType == MapTypeNotRecognized && dwHeaderID == ID_MPK) { // Now convert the MPK header to MPQ Header version 4 - nError = ConvertMpkHeaderToFormat4(ha, FileSize, dwFlags); + dwErrCode = ConvertMpkHeaderToFormat4(ha, FileSize, dwFlags); bSearchComplete = true; break; } @@ -375,7 +375,7 @@ bool WINAPI SFileOpenArchive( // If searching for the MPQ header is disabled, return an error if(dwFlags & MPQ_OPEN_NO_HEADER_SEARCH) { - nError = ERROR_NOT_SUPPORTED; + dwErrCode = ERROR_NOT_SUPPORTED; bSearchComplete = true; break; } @@ -386,7 +386,7 @@ bool WINAPI SFileOpenArchive( } // Did we identify one of the supported headers? - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Set the user data position to the MPQ header, if none if(ha->pUserData == NULL) @@ -399,12 +399,12 @@ bool WINAPI SFileOpenArchive( // Sector size must be nonzero. if(ByteOffset >= FileSize || ha->pHeader->wSectorSize == 0) - nError = ERROR_BAD_FORMAT; + dwErrCode = ERROR_BAD_FORMAT; } } // Fix table positions according to format - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Dump the header // DumpMpqHeader(ha->pHeader); @@ -444,25 +444,25 @@ bool WINAPI SFileOpenArchive( ha->dwSectorSize = (0x200 << ha->pHeader->wSectorSize); // Verify if any of the tables doesn't start beyond the end of the file - nError = VerifyMpqTablePositions(ha, FileSize); + dwErrCode = VerifyMpqTablePositions(ha, FileSize); } // Read the hash table. Ignore the result, as hash table is no longer required // Read HET table. Ignore the result, as HET table is no longer required - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = LoadAnyHashTable(ha); + dwErrCode = LoadAnyHashTable(ha); } // Now, build the file table. It will be built by combining // the block table, BET table, hi-block table, (attributes) and (listfile). - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = BuildFileTable(ha); + dwErrCode = BuildFileTable(ha); } // Load the internal listfile and include it to the file table - if(nError == ERROR_SUCCESS && (dwFlags & MPQ_OPEN_NO_LISTFILE) == 0) + if(dwErrCode == ERROR_SUCCESS && (dwFlags & MPQ_OPEN_NO_LISTFILE) == 0) { // Quick check for (listfile) pFileEntry = GetFileEntryLocale(ha, LISTFILE_NAME, LANG_NEUTRAL); @@ -475,7 +475,7 @@ bool WINAPI SFileOpenArchive( } // Load the "(attributes)" file and merge it to the file table - if(nError == ERROR_SUCCESS && (dwFlags & MPQ_OPEN_NO_ATTRIBUTES) == 0 && (ha->dwFlags & MPQ_FLAG_BLOCK_TABLE_CUT) == 0) + if(dwErrCode == ERROR_SUCCESS && (dwFlags & MPQ_OPEN_NO_ATTRIBUTES) == 0 && (ha->dwFlags & MPQ_FLAG_BLOCK_TABLE_CUT) == 0) { // Quick check for (attributes) pFileEntry = GetFileEntryLocale(ha, ATTRIBUTES_NAME, LANG_NEUTRAL); @@ -488,7 +488,7 @@ bool WINAPI SFileOpenArchive( } // Remember whether the archive has weak signature. Only for MPQs format 1.0. - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Quick check for (signature) pFileEntry = GetFileEntryLocale(ha, SIGNATURE_NAME, LANG_NEUTRAL); @@ -504,11 +504,11 @@ bool WINAPI SFileOpenArchive( } // Cleanup and exit - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) { FileStream_Close(pStream); FreeArchiveHandle(ha); - SetLastError(nError); + SetLastError(dwErrCode); ha = NULL; } @@ -517,7 +517,7 @@ bool WINAPI SFileOpenArchive( STORM_FREE(pbHeaderBuffer); if(phMpq != NULL) *phMpq = ha; - return (nError == ERROR_SUCCESS); + return (dwErrCode == ERROR_SUCCESS); } //----------------------------------------------------------------------------- @@ -552,8 +552,8 @@ bool WINAPI SFileSetDownloadCallback(HANDLE hMpq, SFILE_DOWNLOAD_CALLBACK Downlo bool WINAPI SFileFlushArchive(HANDLE hMpq) { TMPQArchive * ha; - int nResultError = ERROR_SUCCESS; - int nError; + DWORD dwResultError = ERROR_SUCCESS; + DWORD dwErrCode; // Do nothing if 'hMpq' is bad parameter if((ha = IsValidMpqHandle(hMpq)) == NULL) @@ -578,23 +578,23 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq) if(ha->dwFlags & MPQ_FLAG_SIGNATURE_NEW) { - nError = SSignFileCreate(ha); - if(nError != ERROR_SUCCESS) - nResultError = nError; + dwErrCode = SSignFileCreate(ha); + if(dwErrCode != ERROR_SUCCESS) + dwResultError = dwErrCode; } if(ha->dwFlags & (MPQ_FLAG_LISTFILE_NEW | MPQ_FLAG_LISTFILE_FORCE)) { - nError = SListFileSaveToMpq(ha); - if(nError != ERROR_SUCCESS) - nResultError = nError; + dwErrCode = SListFileSaveToMpq(ha); + if(dwErrCode != ERROR_SUCCESS) + dwResultError = dwErrCode; } if(ha->dwFlags & MPQ_FLAG_ATTRIBUTES_NEW) { - nError = SAttrFileSaveToMpq(ha); - if(nError != ERROR_SUCCESS) - nResultError = nError; + dwErrCode = SAttrFileSaveToMpq(ha); + if(dwErrCode != ERROR_SUCCESS) + dwResultError = dwErrCode; } // Save HET table, BET table, hash table, block table, hi-block table @@ -605,16 +605,16 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq) RebuildHetTable(ha); // Save all MPQ tables first - nError = SaveMPQTables(ha); - if(nError != ERROR_SUCCESS) - nResultError = nError; + dwErrCode = SaveMPQTables(ha); + if(dwErrCode != ERROR_SUCCESS) + dwResultError = dwErrCode; // If the archive has weak signature, we need to finish it if(ha->dwFileFlags3 != 0) { - nError = SSignFileFinish(ha); - if(nError != ERROR_SUCCESS) - nResultError = nError; + dwErrCode = SSignFileFinish(ha); + if(dwErrCode != ERROR_SUCCESS) + dwResultError = dwErrCode; } } @@ -623,9 +623,9 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq) } // Return the error - if(nResultError != ERROR_SUCCESS) - SetLastError(nResultError); - return (nResultError == ERROR_SUCCESS); + if(dwResultError != ERROR_SUCCESS) + SetLastError(dwResultError); + return (dwResultError == ERROR_SUCCESS); } //----------------------------------------------------------------------------- diff --git a/src/SFileOpenFileEx.cpp b/src/SFileOpenFileEx.cpp index 1e02a22..d77f25e 100644 --- a/src/SFileOpenFileEx.cpp +++ b/src/SFileOpenFileEx.cpp @@ -173,7 +173,7 @@ bool OpenPatchedFile(HANDLE hMpq, const char * szFileName, HANDLE * PtrFile) // pointed by plcLocales. There must be enough entries to copy the localed, // otherwise the function returns ERROR_INSUFFICIENT_BUFFER. -int WINAPI SFileEnumLocales( +DWORD WINAPI SFileEnumLocales( HANDLE hMpq, const char * szFileName, LCID * PtrLocales, @@ -236,23 +236,23 @@ bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearch TMPQFile * hf = NULL; DWORD dwHashIndex = HASH_ENTRY_FREE; DWORD dwFileIndex = 0; + DWORD dwErrCode = ERROR_SUCCESS; bool bOpenByIndex = false; - int nError = ERROR_SUCCESS; // Don't accept NULL pointer to file handle if(szFileName == NULL || *szFileName == 0) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; // When opening a file from MPQ, the handle must be valid if(dwSearchScope != SFILE_OPEN_LOCAL_FILE && ha == NULL) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; // When not checking for existence, the pointer to file handle must be valid if(dwSearchScope != SFILE_OPEN_CHECK_EXISTS && PtrFile == NULL) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; // Prepare the file opening - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { switch(dwSearchScope) { @@ -289,13 +289,13 @@ bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearch default: // Don't accept any other value - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; break; } } // Check whether the file really exists in the MPQ - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // If we didn't find the file, try to open it using pseudo file name ("File if (pFileEntry == NULL || (pFileEntry->dwFlags & MPQ_FILE_EXISTS) == 0) @@ -313,7 +313,7 @@ bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearch // Still not found? if (pFileEntry == NULL) { - nError = ERROR_FILE_NOT_FOUND; + dwErrCode = ERROR_FILE_NOT_FOUND; } } @@ -325,21 +325,21 @@ bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearch // If the file is not compressed, its size cannot be bigger than archive size if ((pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK) == 0 && (pFileEntry->dwFileSize > ha->FileSize)) { - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; pFileEntry = NULL; } // Ignore unknown loading flags (example: MPQ_2016_v1_WME4_4.w3x) // if(pFileEntry->dwFlags & ~MPQ_FILE_VALID_FLAGS) // { -// nError = ERROR_NOT_SUPPORTED; +// dwErrCode = ERROR_NOT_SUPPORTED; // pFileEntry = NULL; // } } } // Did the caller just wanted to know if the file exists? - if(nError == ERROR_SUCCESS && dwSearchScope != SFILE_OPEN_CHECK_EXISTS) + if(dwErrCode == ERROR_SUCCESS && dwSearchScope != SFILE_OPEN_CHECK_EXISTS) { // Allocate file handle hf = CreateFileHandle(ha, pFileEntry); @@ -374,7 +374,7 @@ bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearch } else { - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; } } @@ -383,9 +383,9 @@ bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearch PtrFile[0] = hf; // Return error code - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } //----------------------------------------------------------------------------- diff --git a/src/SFilePatchArchives.cpp b/src/SFilePatchArchives.cpp index 83cb501..89f05a0 100644 --- a/src/SFilePatchArchives.cpp +++ b/src/SFilePatchArchives.cpp @@ -146,7 +146,7 @@ static void Decompress_RLE(LPBYTE pbDecompressed, DWORD cbDecompressed, LPBYTE p } } -static int LoadFilePatch_COPY(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch) +static DWORD LoadFilePatch_COPY(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch) { DWORD cbBytesToRead = pFullPatch->dwSizeOfPatchData - sizeof(MPQ_PATCH_HEADER); DWORD cbBytesRead = 0; @@ -156,14 +156,14 @@ static int LoadFilePatch_COPY(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch) return (cbBytesRead == cbBytesToRead) ? ERROR_SUCCESS : ERROR_FILE_CORRUPT; } -static int LoadFilePatch_BSD0(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch) +static DWORD LoadFilePatch_BSD0(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch) { LPBYTE pbDecompressed = (LPBYTE)(pFullPatch + 1); LPBYTE pbCompressed = NULL; DWORD cbDecompressed = 0; DWORD cbCompressed = 0; DWORD dwBytesRead = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Calculate the size of compressed data cbDecompressed = pFullPatch->dwSizeOfPatchData - sizeof(MPQ_PATCH_HEADER); @@ -174,18 +174,18 @@ static int LoadFilePatch_BSD0(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch) { pbCompressed = STORM_ALLOC(BYTE, cbCompressed); if(pbCompressed == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; // Read the compressed patch data - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { SFileReadFile((HANDLE)hf, pbCompressed, cbCompressed, &dwBytesRead, NULL); if(dwBytesRead != cbCompressed) - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } // Decompress the data - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) Decompress_RLE(pbDecompressed, cbDecompressed, pbCompressed, cbCompressed); if(pbCompressed != NULL) @@ -195,13 +195,13 @@ static int LoadFilePatch_BSD0(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch) { SFileReadFile((HANDLE)hf, pbDecompressed, cbDecompressed, &dwBytesRead, NULL); if(dwBytesRead != cbDecompressed) - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } - return nError; + return dwErrCode; } -static int ApplyFilePatch_COPY( +static DWORD ApplyFilePatch_COPY( TMPQPatcher * pPatcher, PMPQ_PATCH_HEADER pFullPatch, LPBYTE pbTarget, @@ -216,7 +216,7 @@ static int ApplyFilePatch_COPY( return ERROR_SUCCESS; } -static int ApplyFilePatch_BSD0( +static DWORD ApplyFilePatch_BSD0( TMPQPatcher * pPatcher, PMPQ_PATCH_HEADER pFullPatch, LPBYTE pbTarget, @@ -318,7 +318,7 @@ static int ApplyFilePatch_BSD0( static PMPQ_PATCH_HEADER LoadFullFilePatch(TMPQFile * hf, MPQ_PATCH_HEADER & PatchHeader) { PMPQ_PATCH_HEADER pFullPatch; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // BSWAP the entire header, if needed BSWAP_ARRAY32_UNSIGNED(&PatchHeader, sizeof(DWORD) * 6); @@ -336,26 +336,26 @@ static PMPQ_PATCH_HEADER LoadFullFilePatch(TMPQFile * hf, MPQ_PATCH_HEADER & Pat memcpy(pFullPatch, &PatchHeader, sizeof(MPQ_PATCH_HEADER)); // Read the patch, depending on patch type - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { switch(PatchHeader.dwPatchType) { case 0x59504f43: // 'COPY' - nError = LoadFilePatch_COPY(hf, pFullPatch); + dwErrCode = LoadFilePatch_COPY(hf, pFullPatch); break; case 0x30445342: // 'BSD0' - nError = LoadFilePatch_BSD0(hf, pFullPatch); + dwErrCode = LoadFilePatch_BSD0(hf, pFullPatch); break; default: - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; break; } } // If something failed, free the patch buffer - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) { STORM_FREE(pFullPatch); pFullPatch = NULL; @@ -366,13 +366,13 @@ static PMPQ_PATCH_HEADER LoadFullFilePatch(TMPQFile * hf, MPQ_PATCH_HEADER & Pat return pFullPatch; } -static int ApplyFilePatch( +static DWORD ApplyFilePatch( TMPQPatcher * pPatcher, PMPQ_PATCH_HEADER pFullPatch) { LPBYTE pbSource = (pPatcher->nCounter & 0x1) ? pPatcher->pbFileData2 : pPatcher->pbFileData1; LPBYTE pbTarget = (pPatcher->nCounter & 0x1) ? pPatcher->pbFileData1 : pPatcher->pbFileData2; - int nError; + DWORD dwErrCode; // Sanity checks assert(pFullPatch->dwSizeAfterPatch <= pPatcher->cbMaxFileData); @@ -381,30 +381,30 @@ static int ApplyFilePatch( switch(pFullPatch->dwPatchType) { case 0x59504f43: // 'COPY' - nError = ApplyFilePatch_COPY(pPatcher, pFullPatch, pbTarget, pbSource); + dwErrCode = ApplyFilePatch_COPY(pPatcher, pFullPatch, pbTarget, pbSource); break; case 0x30445342: // 'BSD0' - nError = ApplyFilePatch_BSD0(pPatcher, pFullPatch, pbTarget, pbSource); + dwErrCode = ApplyFilePatch_BSD0(pPatcher, pFullPatch, pbTarget, pbSource); break; default: - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; break; } // Verify MD5 after patch - if(nError == ERROR_SUCCESS && pFullPatch->dwSizeAfterPatch != 0) + if(dwErrCode == ERROR_SUCCESS && pFullPatch->dwSizeAfterPatch != 0) { // Verify the patched file if(!VerifyDataBlockHash(pbTarget, pFullPatch->dwSizeAfterPatch, pFullPatch->md5_after_patch)) - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; // Copy the MD5 of the new block memcpy(pPatcher->this_md5, pFullPatch->md5_after_patch, MD5_DIGEST_SIZE); } - return nError; + return dwErrCode; } //----------------------------------------------------------------------------- @@ -934,7 +934,7 @@ bool IsIncrementalPatchFile(const void * pvData, DWORD cbData, LPDWORD pdwPatche return false; } -int Patch_InitPatcher(TMPQPatcher * pPatcher, TMPQFile * hf) +DWORD Patch_InitPatcher(TMPQPatcher * pPatcher, TMPQFile * hf) { DWORD cbMaxFileData = 0; @@ -987,14 +987,14 @@ int Patch_InitPatcher(TMPQPatcher * pPatcher, TMPQFile * hf) // 9 patches in a row, each requiring 70 MB memory (35 MB patch data + 35 MB work buffer) // -int Patch_Process(TMPQPatcher * pPatcher, TMPQFile * hf) +DWORD Patch_Process(TMPQPatcher * pPatcher, TMPQFile * hf) { PMPQ_PATCH_HEADER pFullPatch; MPQ_PATCH_HEADER PatchHeader1; MPQ_PATCH_HEADER PatchHeader2 = {0}; TMPQFile * hfBase = hf; DWORD cbBytesRead = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Move to the first patch assert(hfBase->pbFileData == NULL); @@ -1007,7 +1007,7 @@ int Patch_Process(TMPQPatcher * pPatcher, TMPQFile * hf) return ERROR_FILE_CORRUPT; // Perform the patching process - while(nError == ERROR_SUCCESS && hf != NULL) + while(dwErrCode == ERROR_SUCCESS && hf != NULL) { // Try to read the next patch header. If the md5_before_patch // still matches we go directly to the next one and repeat @@ -1032,12 +1032,12 @@ int Patch_Process(TMPQPatcher * pPatcher, TMPQFile * hf) if(pFullPatch != NULL) { // Apply the patch - nError = ApplyFilePatch(pPatcher, pFullPatch); + dwErrCode = ApplyFilePatch(pPatcher, pFullPatch); STORM_FREE(pFullPatch); } else { - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } // Move to the next patch @@ -1047,7 +1047,7 @@ int Patch_Process(TMPQPatcher * pPatcher, TMPQFile * hf) } // Put the result data to the file structure - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Swap the pointer to the file data structure if(pPatcher->nCounter & 0x01) @@ -1094,16 +1094,16 @@ bool WINAPI SFileOpenPatchArchive( TMPQArchive * haPatch; TMPQArchive * ha = (TMPQArchive *)hMpq; HANDLE hPatchMpq = NULL; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Keep compiler happy dwFlags = dwFlags; // Verify input parameters if(!IsValidMpqHandle(hMpq)) - nError = ERROR_INVALID_HANDLE; + dwErrCode = ERROR_INVALID_HANDLE; if(szPatchMpqName == NULL || *szPatchMpqName == 0) - nError = ERROR_INVALID_PARAMETER; + dwErrCode = ERROR_INVALID_PARAMETER; // // We don't allow adding patches to archives that have been open for write @@ -1117,14 +1117,14 @@ bool WINAPI SFileOpenPatchArchive( // 5) Now what ? // - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(!(ha->dwFlags & MPQ_FLAG_READ_ONLY)) - nError = ERROR_ACCESS_DENIED; + dwErrCode = ERROR_ACCESS_DENIED; } // Open the archive like it is normal archive - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(SFileOpenArchive(szPatchMpqName, 0, MPQ_OPEN_READ_ONLY | MPQ_OPEN_PATCH, &hPatchMpq)) { @@ -1151,15 +1151,15 @@ bool WINAPI SFileOpenPatchArchive( // Close the archive SFileCloseArchive(hPatchMpq); - nError = ERROR_CANT_FIND_PATCH_PREFIX; + dwErrCode = ERROR_CANT_FIND_PATCH_PREFIX; } else { - nError = GetLastError(); + dwErrCode = GetLastError(); } } - SetLastError(nError); + SetLastError(dwErrCode); return false; } diff --git a/src/SFileReadFile.cpp b/src/SFileReadFile.cpp index 192d212..34edc06 100644 --- a/src/SFileReadFile.cpp +++ b/src/SFileReadFile.cpp @@ -21,7 +21,7 @@ // dwByteOffset - Position of sector in the file (relative to file begin) // dwBytesToRead - Number of bytes to read. Must be multiplier of sector size. // pdwBytesRead - Stored number of bytes loaded -static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DWORD dwBytesToRead, LPDWORD pdwBytesRead) +static DWORD ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DWORD dwBytesToRead, LPDWORD pdwBytesRead) { ULONGLONG RawFilePos; TMPQArchive * ha = hf->ha; @@ -35,7 +35,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW DWORD dwSectorIndex = dwByteOffset / ha->dwSectorSize; DWORD dwSectorsDone = 0; DWORD dwBytesRead = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Note that dwByteOffset must be aligned to size of one sector // Note that dwBytesToRead must be a multiplier of one sector size @@ -53,9 +53,9 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW // If the sector positions are not loaded yet, do it if(hf->SectorOffsets == NULL) { - nError = AllocateSectorOffsets(hf, true); - if(nError != ERROR_SUCCESS || hf->SectorOffsets == NULL) - return nError; + dwErrCode = AllocateSectorOffsets(hf, true); + if(dwErrCode != ERROR_SUCCESS || hf->SectorOffsets == NULL) + return dwErrCode; } // If the sector checksums are not loaded yet, load them now. @@ -76,9 +76,9 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW // Only do it if the MPQ is of format 4.0 // if(ha->pHeader->wFormatVersion >= MPQ_FORMAT_VERSION_4 && ha->pHeader->dwRawChunkSize != 0) // { -// nError = AllocateRawMD5s(hf, true); -// if(nError != ERROR_SUCCESS) -// return nError; +// dwErrCode = AllocateRawMD5s(hf, true); +// if(dwErrCode != ERROR_SUCCESS) +// return dwErrCode; // } // Assign the temporary buffer as target for read operation @@ -126,7 +126,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW hf->dwFileKey = DetectFileKeyByContent(pbInSector, dwBytesInThisSector, hf->dwDataSize); if(hf->dwFileKey == 0) { - nError = ERROR_UNKNOWN_FILE_KEY; + dwErrCode = ERROR_UNKNOWN_FILE_KEY; break; } } @@ -148,7 +148,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW dwAdlerValue = adler32(0, pbInSector, dwRawBytesInThisSector); if(dwAdlerValue != dwAdlerExpected) { - nError = ERROR_CHECKSUM_ERROR; + dwErrCode = ERROR_CHECKSUM_ERROR; break; } } @@ -185,7 +185,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW // Did the decompression fail ? if(nResult == 0) { - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; break; } } @@ -206,7 +206,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW } else { - nError = GetLastError(); + dwErrCode = GetLastError(); } // Free all used buffers @@ -215,24 +215,24 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW // Give the caller thenumber of bytes read *pdwBytesRead = dwBytesRead; - return nError; + return dwErrCode; } -static int ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead) +static DWORD ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead) { ULONGLONG RawFilePos = hf->RawFilePos; TMPQArchive * ha = hf->ha; TFileEntry * pFileEntry = hf->pFileEntry; LPBYTE pbCompressed = NULL; LPBYTE pbRawData; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // If the file buffer is not allocated yet, do it. if(hf->pbFileSector == NULL) { - nError = AllocateSectorBuffer(hf); - if(nError != ERROR_SUCCESS || hf->pbFileSector == NULL) - return nError; + dwErrCode = AllocateSectorBuffer(hf); + if(dwErrCode != ERROR_SUCCESS || hf->pbFileSector == NULL) + return dwErrCode; } // If the file is a patch file, adjust raw data offset @@ -308,7 +308,7 @@ static int ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos else if(pFileEntry->dwFlags & MPQ_FILE_IMPLODE) nResult = SCompExplode(hf->pbFileSector, &cbOutBuffer, pbRawData, cbInBuffer); - nError = (nResult != 0) ? ERROR_SUCCESS : ERROR_FILE_CORRUPT; + dwErrCode = (nResult != 0) ? ERROR_SUCCESS : ERROR_FILE_CORRUPT; } else { @@ -326,7 +326,7 @@ static int ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos // At this moment, we have the file loaded into the file buffer. // Copy as much as the caller wants - if(nError == ERROR_SUCCESS && hf->dwSectorOffs == 0) + if(dwErrCode == ERROR_SUCCESS && hf->dwSectorOffs == 0) { // File position is greater or equal to file size ? if(dwFilePos >= hf->dwDataSize) @@ -347,17 +347,17 @@ static int ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos } // An error, sorry - return nError; + return dwErrCode; } -static int ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead) +static DWORD ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead) { ULONGLONG RawFilePos = hf->RawFilePos + 0x0C; // For some reason, MPK files start at position (hf->RawFilePos + 0x0C) TMPQArchive * ha = hf->ha; TFileEntry * pFileEntry = hf->pFileEntry; LPBYTE pbCompressed = NULL; LPBYTE pbRawData = hf->pbFileSector; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // We do not support patch files in MPK archives assert(hf->pPatchInfo == NULL); @@ -365,9 +365,9 @@ static int ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos // If the file buffer is not allocated yet, do it. if(hf->pbFileSector == NULL) { - nError = AllocateSectorBuffer(hf); - if(nError != ERROR_SUCCESS || hf->pbFileSector == NULL) - return nError; + dwErrCode = AllocateSectorBuffer(hf); + if(dwErrCode != ERROR_SUCCESS || hf->pbFileSector == NULL) + return dwErrCode; pbRawData = hf->pbFileSector; } @@ -404,7 +404,7 @@ static int ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos hf->dwCompression0 = pbRawData[0]; if(!SCompDecompressMpk(hf->pbFileSector, &cbOutBuffer, pbRawData, (int)pFileEntry->dwCmpSize)) - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } else { @@ -422,7 +422,7 @@ static int ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos // At this moment, we have the file loaded into the file buffer. // Copy as much as the caller wants - if(nError == ERROR_SUCCESS && hf->dwSectorOffs == 0) + if(dwErrCode == ERROR_SUCCESS && hf->dwSectorOffs == 0) { // File position is greater or equal to file size ? if(dwFilePos >= hf->dwDataSize) @@ -448,7 +448,7 @@ static int ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos } -static int ReadMpqFileSectorFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwBytesToRead, LPDWORD pdwBytesRead) +static DWORD ReadMpqFileSectorFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwBytesToRead, LPDWORD pdwBytesRead) { TMPQArchive * ha = hf->ha; LPBYTE pbBuffer = (BYTE *)pvBuffer; @@ -456,7 +456,7 @@ static int ReadMpqFileSectorFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos DWORD dwSectorSizeMask = ha->dwSectorSize - 1; // Mask for block size, usually 0x0FFF DWORD dwFileSectorPos; // File offset of the loaded sector DWORD dwBytesRead; // Number of bytes read (temporary variable) - int nError; + DWORD dwErrCode; // If the file position is at or beyond end of file, do nothing if(dwFilePos >= hf->dwDataSize) @@ -475,9 +475,9 @@ static int ReadMpqFileSectorFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos // If the file sector buffer is not allocated yet, do it now if(hf->pbFileSector == NULL) { - nError = AllocateSectorBuffer(hf); - if(nError != ERROR_SUCCESS || hf->pbFileSector == NULL) - return nError; + dwErrCode = AllocateSectorBuffer(hf); + if(dwErrCode != ERROR_SUCCESS || hf->pbFileSector == NULL) + return dwErrCode; } // Load the first (incomplete) file sector @@ -491,9 +491,9 @@ static int ReadMpqFileSectorFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos if(hf->dwSectorOffs != dwFileSectorPos) { // Load one MPQ sector into archive buffer - nError = ReadMpqSectors(hf, hf->pbFileSector, dwFileSectorPos, ha->dwSectorSize, &dwBytesInSector); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = ReadMpqSectors(hf, hf->pbFileSector, dwFileSectorPos, ha->dwSectorSize, &dwBytesInSector); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; // Remember that the data loaded to the sector have new file offset hf->dwSectorOffs = dwFileSectorPos; @@ -525,9 +525,9 @@ static int ReadMpqFileSectorFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos DWORD dwBlockBytes = dwBytesToRead & ~dwSectorSizeMask; // Load all sectors to the output buffer - nError = ReadMpqSectors(hf, pbBuffer, dwFileSectorPos, dwBlockBytes, &dwBytesRead); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = ReadMpqSectors(hf, pbBuffer, dwFileSectorPos, dwBlockBytes, &dwBytesRead); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; // Update pointers dwTotalBytesRead += dwBytesRead; @@ -545,9 +545,9 @@ static int ReadMpqFileSectorFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos if(hf->dwSectorOffs != dwFileSectorPos) { // Load one MPQ sector into archive buffer - nError = ReadMpqSectors(hf, hf->pbFileSector, dwFileSectorPos, ha->dwSectorSize, &dwBytesRead); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = ReadMpqSectors(hf, hf->pbFileSector, dwFileSectorPos, ha->dwSectorSize, &dwBytesRead); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; // Remember that the data loaded to the sector have new file offset hf->dwSectorOffs = dwFileSectorPos; @@ -569,33 +569,33 @@ static int ReadMpqFileSectorFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos return ERROR_SUCCESS; } -static int ReadMpqFilePatchFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead) +static DWORD ReadMpqFilePatchFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead) { TMPQPatcher Patcher; DWORD dwBytesToRead = dwToRead; DWORD dwBytesRead = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Make sure that the patch file is loaded completely - if(nError == ERROR_SUCCESS && hf->pbFileData == NULL) + if(dwErrCode == ERROR_SUCCESS && hf->pbFileData == NULL) { // Initialize patching process and allocate data - nError = Patch_InitPatcher(&Patcher, hf); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = Patch_InitPatcher(&Patcher, hf); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; // Set the current data size Patcher.cbFileData = hf->pFileEntry->dwFileSize; // Initialize the patcher object with initial file data if(hf->pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT) - nError = ReadMpqFileSingleUnit(hf, Patcher.pbFileData1, 0, Patcher.cbFileData, &dwBytesRead); + dwErrCode = ReadMpqFileSingleUnit(hf, Patcher.pbFileData1, 0, Patcher.cbFileData, &dwBytesRead); else - nError = ReadMpqFileSectorFile(hf, Patcher.pbFileData1, 0, Patcher.cbFileData, &dwBytesRead); + dwErrCode = ReadMpqFileSectorFile(hf, Patcher.pbFileData1, 0, Patcher.cbFileData, &dwBytesRead); // Perform the patching process - if(nError == ERROR_SUCCESS) - nError = Patch_Process(&Patcher, hf); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = Patch_Process(&Patcher, hf); // Finalize the patcher structure Patch_Finalize(&Patcher); @@ -603,7 +603,7 @@ static int ReadMpqFilePatchFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, } // If there is something to read, do it - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(dwFilePos < hf->cbFileData) { @@ -617,21 +617,21 @@ static int ReadMpqFilePatchFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, } // Set the proper error code - nError = (dwBytesRead == dwBytesToRead) ? ERROR_SUCCESS : ERROR_HANDLE_EOF; + dwErrCode = (dwBytesRead == dwBytesToRead) ? ERROR_SUCCESS : ERROR_HANDLE_EOF; } // Give the result to the caller if(pdwBytesRead != NULL) *pdwBytesRead = dwBytesRead; - return nError; + return dwErrCode; } -static int ReadMpqFileLocalFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead) +static DWORD ReadMpqFileLocalFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead) { ULONGLONG FilePosition1 = dwFilePos; ULONGLONG FilePosition2; DWORD dwBytesRead = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; assert(hf->pStream != NULL); @@ -643,7 +643,7 @@ static int ReadMpqFileLocalFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, if(!FileStream_Read(hf->pStream, &FilePosition1, pvBuffer, dwToRead)) { // If not all bytes have been read, then return the number of bytes read - if((nError = GetLastError()) == ERROR_HANDLE_EOF) + if((dwErrCode = GetLastError()) == ERROR_HANDLE_EOF) { FileStream_GetPos(hf->pStream, &FilePosition2); dwBytesRead = (DWORD)(FilePosition2 - FilePosition1); @@ -655,7 +655,7 @@ static int ReadMpqFileLocalFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, } *pdwBytesRead = dwBytesRead; - return nError; + return dwErrCode; } //----------------------------------------------------------------------------- @@ -665,7 +665,7 @@ bool WINAPI SFileReadFile(HANDLE hFile, void * pvBuffer, DWORD dwToRead, LPDWORD { TMPQFile * hf = (TMPQFile *)hFile; DWORD dwBytesRead = 0; // Number of bytes read - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Always zero the result if(pdwRead != NULL) @@ -688,10 +688,10 @@ bool WINAPI SFileReadFile(HANDLE hFile, void * pvBuffer, DWORD dwToRead, LPDWORD // If we didn't load the patch info yet, do it now if(hf->pFileEntry != NULL && (hf->pFileEntry->dwFlags & MPQ_FILE_PATCH_FILE) && hf->pPatchInfo == NULL) { - nError = AllocatePatchInfo(hf, true); - if(nError != ERROR_SUCCESS || hf->pPatchInfo == NULL) + dwErrCode = AllocatePatchInfo(hf, true); + if(dwErrCode != ERROR_SUCCESS || hf->pPatchInfo == NULL) { - SetLastError(nError); + SetLastError(dwErrCode); return false; } } @@ -702,31 +702,31 @@ bool WINAPI SFileReadFile(HANDLE hFile, void * pvBuffer, DWORD dwToRead, LPDWORD // If the file is local file, read the data directly from the stream if(hf->pStream != NULL) { - nError = ReadMpqFileLocalFile(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); + dwErrCode = ReadMpqFileLocalFile(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); } // If the file is a patch file, we have to read it special way else if(hf->hfPatch != NULL && (hf->pFileEntry->dwFlags & MPQ_FILE_PATCH_FILE) == 0) { - nError = ReadMpqFilePatchFile(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); + dwErrCode = ReadMpqFilePatchFile(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); } // If the archive is a MPK archive, we need special way to read the file else if(hf->ha->dwSubType == MPQ_SUBTYPE_MPK) { - nError = ReadMpkFileSingleUnit(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); + dwErrCode = ReadMpkFileSingleUnit(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); } // If the file is single unit file, redirect it to read file else if(hf->pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT) { - nError = ReadMpqFileSingleUnit(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); + dwErrCode = ReadMpqFileSingleUnit(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); } // Otherwise read it as sector based MPQ file else { - nError = ReadMpqFileSectorFile(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); + dwErrCode = ReadMpqFileSectorFile(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); } // Increment the file position @@ -738,13 +738,13 @@ bool WINAPI SFileReadFile(HANDLE hFile, void * pvBuffer, DWORD dwToRead, LPDWORD // If the read operation succeeded, but not full number of bytes was read, // set the last error to ERROR_HANDLE_EOF - if(nError == ERROR_SUCCESS && (dwBytesRead < dwToRead)) - nError = ERROR_HANDLE_EOF; + if(dwErrCode == ERROR_SUCCESS && (dwBytesRead < dwToRead)) + dwErrCode = ERROR_HANDLE_EOF; // If something failed, set the last error value - if(nError != ERROR_SUCCESS) - SetLastError(nError); - return (nError == ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) + SetLastError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } //----------------------------------------------------------------------------- diff --git a/src/SFileVerify.cpp b/src/SFileVerify.cpp index 1b885b4..4465562 100644 --- a/src/SFileVerify.cpp +++ b/src/SFileVerify.cpp @@ -344,7 +344,7 @@ static bool CalculateMpqHashSha1( return true; } -static int VerifyRawMpqData( +static DWORD VerifyRawMpqData( TMPQArchive * ha, ULONGLONG ByteOffset, DWORD dwDataSize) @@ -357,7 +357,7 @@ static int VerifyRawMpqData( DWORD dwChunkCount; DWORD dwChunkSize = ha->pHeader->dwRawChunkSize; DWORD dwMD5Size; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Don't verify zero-sized blocks if(dwDataSize == 0) @@ -377,10 +377,10 @@ static int VerifyRawMpqData( pbMD5Array1 = STORM_ALLOC(BYTE, dwMD5Size); pbMD5Array2 = STORM_ALLOC(BYTE, dwMD5Size); if(pbMD5Array1 == NULL || pbMD5Array2 == NULL) - nError = ERROR_NOT_ENOUGH_MEMORY; + dwErrCode = ERROR_NOT_ENOUGH_MEMORY; // Calculate MD5 of each data chunk - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { LPBYTE pbMD5 = pbMD5Array1; @@ -392,7 +392,7 @@ static int VerifyRawMpqData( // Read the data chunk if(!FileStream_Read(ha->pStream, &DataOffset, pbDataChunk, dwBytesInChunk)) { - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; break; } @@ -407,19 +407,19 @@ static int VerifyRawMpqData( } // Read the MD5 array - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Read the array of MD5 if(!FileStream_Read(ha->pStream, &DataOffset, pbMD5Array2, dwMD5Size)) - nError = GetLastError(); + dwErrCode = GetLastError(); } // Compare the array of MD5 - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Compare the MD5 if(memcmp(pbMD5Array1, pbMD5Array2, dwMD5Size)) - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } // Free memory and return result @@ -429,7 +429,7 @@ static int VerifyRawMpqData( STORM_FREE(pbMD5Array1); if(pbDataChunk != NULL) STORM_FREE(pbDataChunk); - return nError; + return dwErrCode; } static DWORD VerifyWeakSignature( @@ -780,11 +780,11 @@ bool QueryMpqSignatureInfo( //----------------------------------------------------------------------------- // Support for weak signature -int SSignFileCreate(TMPQArchive * ha) +DWORD SSignFileCreate(TMPQArchive * ha) { TMPQFile * hf = NULL; BYTE EmptySignature[MPQ_SIGNATURE_FILE_SIZE]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Only save the signature if we should do so if(ha->dwFileFlags3 != 0) @@ -796,7 +796,7 @@ int SSignFileCreate(TMPQArchive * ha) // Create the (signature) file file in the MPQ // Note that the file must not be compressed or encrypted - nError = SFileAddFile_Init(ha, SIGNATURE_NAME, + dwErrCode = SFileAddFile_Init(ha, SIGNATURE_NAME, 0, sizeof(EmptySignature), LANG_NEUTRAL, @@ -804,11 +804,11 @@ int SSignFileCreate(TMPQArchive * ha) &hf); // Write the empty signature file to the archive - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Write the empty zeroed file to the MPQ memset(EmptySignature, 0, sizeof(EmptySignature)); - nError = SFileAddFile_Write(hf, EmptySignature, (DWORD)sizeof(EmptySignature), 0); + dwErrCode = SFileAddFile_Write(hf, EmptySignature, (DWORD)sizeof(EmptySignature), 0); SFileAddFile_Finish(hf); // Clear the invalid mark @@ -817,10 +817,10 @@ int SSignFileCreate(TMPQArchive * ha) } } - return nError; + return dwErrCode; } -int SSignFileFinish(TMPQArchive * ha) +DWORD SSignFileFinish(TMPQArchive * ha) { MPQ_SIGNATURE_INFO si; unsigned long signature_len = MPQ_WEAK_SIGNATURE_SIZE; @@ -903,7 +903,7 @@ DWORD WINAPI SFileVerifyFile(HANDLE hMpq, const char * szFileName, DWORD dwFlags } // Verifies raw data of the archive Only works for MPQs version 4 or newer -int WINAPI SFileVerifyRawData(HANDLE hMpq, DWORD dwWhatToVerify, const char * szFileName) +DWORD WINAPI SFileVerifyRawData(HANDLE hMpq, DWORD dwWhatToVerify, const char * szFileName) { TMPQArchive * ha = (TMPQArchive *)hMpq; TFileEntry * pFileEntry; diff --git a/src/StormCommon.h b/src/StormCommon.h index f8023c4..ff14a32 100644 --- a/src/StormCommon.h +++ b/src/StormCommon.h @@ -242,7 +242,7 @@ TMPQFile * IsValidFileHandle(HANDLE hFile); ULONGLONG FileOffsetFromMpqOffset(TMPQArchive * ha, ULONGLONG MpqOffset); ULONGLONG CalculateRawSectorOffset(TMPQFile * hf, DWORD dwSectorOffset); -int ConvertMpqHeaderToFormat4(TMPQArchive * ha, ULONGLONG MpqOffset, ULONGLONG FileSize, DWORD dwFlags, MTYPE MapType); +DWORD ConvertMpqHeaderToFormat4(TMPQArchive * ha, ULONGLONG MpqOffset, ULONGLONG FileSize, DWORD dwFlags, MTYPE MapType); bool IsValidHashEntry(TMPQArchive * ha, TMPQHash * pHash); @@ -261,15 +261,15 @@ TMPQBlock * TranslateBlockTable(TMPQArchive * ha, ULONGLONG * pcbTableSize, bool ULONGLONG FindFreeMpqSpace(TMPQArchive * ha); // Functions that load the HET and BET tables -int CreateHashTable(TMPQArchive * ha, DWORD dwHashTableSize); -int LoadAnyHashTable(TMPQArchive * ha); -int BuildFileTable(TMPQArchive * ha); -int DefragmentFileTable(TMPQArchive * ha); +DWORD CreateHashTable(TMPQArchive * ha, DWORD dwHashTableSize); +DWORD LoadAnyHashTable(TMPQArchive * ha); +DWORD BuildFileTable(TMPQArchive * ha); +DWORD DefragmentFileTable(TMPQArchive * ha); -int CreateFileTable(TMPQArchive * ha, DWORD dwFileTableSize); -int RebuildHetTable(TMPQArchive * ha); -int RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize); -int SaveMPQTables(TMPQArchive * ha); +DWORD CreateFileTable(TMPQArchive * ha, DWORD dwFileTableSize); +DWORD RebuildHetTable(TMPQArchive * ha); +DWORD RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize); +DWORD SaveMPQTables(TMPQArchive * ha); TMPQHetTable * CreateHetTable(DWORD dwEntryCount, DWORD dwTotalCount, DWORD dwHashBitSize, LPBYTE pbSrcData); void FreeHetTable(TMPQHetTable * pHetTable); @@ -287,8 +287,8 @@ void AllocateFileName(TMPQArchive * ha, TFileEntry * pFileEntry, const char * sz // Allocates new file entry in the MPQ tables. Reuses existing, if possible TFileEntry * AllocateFileEntry(TMPQArchive * ha, const char * szFileName, LCID lcLocale, LPDWORD PtrHashIndex); -int RenameFileEntry(TMPQArchive * ha, TMPQFile * hf, const char * szNewFileName); -int DeleteFileEntry(TMPQArchive * ha, TMPQFile * hf); +DWORD RenameFileEntry(TMPQArchive * ha, TMPQFile * hf, const char * szNewFileName); +DWORD DeleteFileEntry(TMPQArchive * ha, TMPQFile * hf); // Invalidates entries for (listfile) and (attributes) void InvalidateInternalFiles(TMPQArchive * ha); @@ -299,11 +299,11 @@ bool QueryMpqSignatureInfo(TMPQArchive * ha, PMPQ_SIGNATURE_INFO pSignatureInfo) //----------------------------------------------------------------------------- // Support for alternate file formats (SBaseSubTypes.cpp) -int ConvertSqpHeaderToFormat4(TMPQArchive * ha, ULONGLONG FileSize, DWORD dwFlags); +DWORD ConvertSqpHeaderToFormat4(TMPQArchive * ha, ULONGLONG FileSize, DWORD dwFlags); TMPQHash * LoadSqpHashTable(TMPQArchive * ha); TMPQBlock * LoadSqpBlockTable(TMPQArchive * ha); -int ConvertMpkHeaderToFormat4(TMPQArchive * ha, ULONGLONG FileSize, DWORD dwFlags); +DWORD ConvertMpkHeaderToFormat4(TMPQArchive * ha, ULONGLONG FileSize, DWORD dwFlags); void DecryptMpkTable(void * pvMpkTable, size_t cbSize); TMPQHash * LoadMpkHashTable(TMPQArchive * ha); TMPQBlock * LoadMpkBlockTable(TMPQArchive * ha); @@ -315,15 +315,15 @@ int SCompDecompressMpk(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer TMPQFile * CreateFileHandle(TMPQArchive * ha, TFileEntry * pFileEntry); TMPQFile * CreateWritableHandle(TMPQArchive * ha, DWORD dwFileSize); void * LoadMpqTable(TMPQArchive * ha, ULONGLONG ByteOffset, LPBYTE pbTableHash, DWORD dwCompressedSize, DWORD dwRealSize, DWORD dwKey, bool * pbTableIsCut); -int AllocateSectorBuffer(TMPQFile * hf); -int AllocatePatchInfo(TMPQFile * hf, bool bLoadFromFile); -int AllocateSectorOffsets(TMPQFile * hf, bool bLoadFromFile); -int AllocateSectorChecksums(TMPQFile * hf, bool bLoadFromFile); -int WritePatchInfo(TMPQFile * hf); -int WriteSectorOffsets(TMPQFile * hf); -int WriteSectorChecksums(TMPQFile * hf); -int WriteMemDataMD5(TFileStream * pStream, ULONGLONG RawDataOffs, void * pvRawData, DWORD dwRawDataSize, DWORD dwChunkSize, LPDWORD pcbTotalSize); -int WriteMpqDataMD5(TFileStream * pStream, ULONGLONG RawDataOffs, DWORD dwRawDataSize, DWORD dwChunkSize); +DWORD AllocateSectorBuffer(TMPQFile * hf); +DWORD AllocatePatchInfo(TMPQFile * hf, bool bLoadFromFile); +DWORD AllocateSectorOffsets(TMPQFile * hf, bool bLoadFromFile); +DWORD AllocateSectorChecksums(TMPQFile * hf, bool bLoadFromFile); +DWORD WritePatchInfo(TMPQFile * hf); +DWORD WriteSectorOffsets(TMPQFile * hf); +DWORD WriteSectorChecksums(TMPQFile * hf); +DWORD WriteMemDataMD5(TFileStream * pStream, ULONGLONG RawDataOffs, void * pvRawData, DWORD dwRawDataSize, DWORD dwChunkSize, LPDWORD pcbTotalSize); +DWORD WriteMpqDataMD5(TFileStream * pStream, ULONGLONG RawDataOffs, DWORD dwRawDataSize, DWORD dwChunkSize); void FreeFileHandle(TMPQFile *& hf); void FreeArchiveHandle(TMPQArchive *& ha); @@ -343,8 +343,8 @@ typedef struct _TMPQPatcher } TMPQPatcher; bool IsIncrementalPatchFile(const void * pvData, DWORD cbData, LPDWORD pdwPatchedFileSize); -int Patch_InitPatcher(TMPQPatcher * pPatcher, TMPQFile * hf); -int Patch_Process(TMPQPatcher * pPatcher, TMPQFile * hf); +DWORD Patch_InitPatcher(TMPQPatcher * pPatcher, TMPQFile * hf); +DWORD Patch_Process(TMPQPatcher * pPatcher, TMPQFile * hf); void Patch_Finalize(TMPQPatcher * pPatcher); //----------------------------------------------------------------------------- @@ -370,7 +370,7 @@ const XCHAR * GetPlainFileName(const XCHAR * szFileName) //----------------------------------------------------------------------------- // Internal support for MPQ modifications -int SFileAddFile_Init( +DWORD SFileAddFile_Init( TMPQArchive * ha, const char * szArchivedName, ULONGLONG ft, @@ -380,39 +380,39 @@ int SFileAddFile_Init( TMPQFile ** phf ); -int SFileAddFile_Init( +DWORD SFileAddFile_Init( TMPQArchive * ha, TMPQFile * hfSrc, TMPQFile ** phf ); -int SFileAddFile_Write( +DWORD SFileAddFile_Write( TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD dwCompression ); -int SFileAddFile_Finish( +DWORD SFileAddFile_Finish( TMPQFile * hf ); //----------------------------------------------------------------------------- // Attributes support -int SAttrLoadAttributes(TMPQArchive * ha); -int SAttrFileSaveToMpq(TMPQArchive * ha); +DWORD SAttrLoadAttributes(TMPQArchive * ha); +DWORD SAttrFileSaveToMpq(TMPQArchive * ha); //----------------------------------------------------------------------------- // Listfile functions -int SListFileSaveToMpq(TMPQArchive * ha); +DWORD SListFileSaveToMpq(TMPQArchive * ha); //----------------------------------------------------------------------------- // Weak signature support -int SSignFileCreate(TMPQArchive * ha); -int SSignFileFinish(TMPQArchive * ha); +DWORD SSignFileCreate(TMPQArchive * ha); +DWORD SSignFileFinish(TMPQArchive * ha); //----------------------------------------------------------------------------- // Dump data support diff --git a/src/StormLib.h b/src/StormLib.h index 145cf58..0e4c411 100644 --- a/src/StormLib.h +++ b/src/StormLib.h @@ -884,7 +884,7 @@ typedef struct _TMPQFile unsigned char hctx[HASH_STATE_SIZE]; // Hash state for MD5. Used when saving file to MPQ DWORD dwCrc32; // CRC32 value, used when saving file to MPQ - int nAddFileError; // Result of the "Add File" operations + DWORD dwAddFileError; // Result of the "Add File" operations bool bLoadedSectorCRCs; // If true, we already tried to load sector CRCs bool bCheckSectorCRCs; // If true, then SFileReadFile will check sector CRCs when reading the file @@ -1009,7 +1009,7 @@ bool WINAPI SFileCloseArchive(HANDLE hMpq); // Adds another listfile into MPQ. The currently added listfile(s) remain, // so you can use this API to combining more listfiles. // Note that this function is internally called by SFileFindFirstFile -int WINAPI SFileAddListFile(HANDLE hMpq, const TCHAR * szListFile); +DWORD WINAPI SFileAddListFile(HANDLE hMpq, const TCHAR * szListFile); // Archive compacting bool WINAPI SFileSetCompactCallback(HANDLE hMpq, SFILE_COMPACT_CALLBACK CompactCB, void * pvUserData); @@ -1060,7 +1060,7 @@ bool WINAPI SFileGetFileChecksums(HANDLE hMpq, const char * szFileName, LPDWOR DWORD WINAPI SFileVerifyFile(HANDLE hMpq, const char * szFileName, DWORD dwFlags); // Verifies raw data of the archive. Only works for MPQs version 4 or newer -int WINAPI SFileVerifyRawData(HANDLE hMpq, DWORD dwWhatToVerify, const char * szFileName); +DWORD WINAPI SFileVerifyRawData(HANDLE hMpq, DWORD dwWhatToVerify, const char * szFileName); // Verifies the signature, if present bool WINAPI SFileSignArchive(HANDLE hMpq, DWORD dwSignatureType); @@ -1078,7 +1078,7 @@ bool WINAPI SListFileFindNextFile(HANDLE hFind, SFILE_FIND_DATA * lpFindFileDa bool WINAPI SListFileFindClose(HANDLE hFind); // Locale support -int WINAPI SFileEnumLocales(HANDLE hMpq, const char * szFileName, LCID * plcLocales, LPDWORD pdwMaxLocales, DWORD dwSearchScope); +DWORD WINAPI SFileEnumLocales(HANDLE hMpq, const char * szFileName, LCID * plcLocales, LPDWORD pdwMaxLocales, DWORD dwSearchScope); //----------------------------------------------------------------------------- // Support for adding files to the MPQ diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 0c1aea4..20d606e 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -81,8 +81,7 @@ static const TCHAR szListFileDir[] = { '1', '9', '9', '5', ' ', '-', ' ', 'T', ' static LPCTSTR szMpqSubDir = _T("1995 - Test MPQs"); static LPCTSTR szMpqPatchDir = _T("1995 - Test MPQs\\patches"); -typedef int (*FIND_FILE_CALLBACK)(LPCTSTR szFullPath); -typedef int (*FIND_PAIR_CALLBACK)(LPCTSTR szFullPath1, LPCTSTR szFullPath2); +typedef DWORD (*FIND_FILE_CALLBACK)(LPCTSTR szFullPath); #define ERROR_UNDETERMINED_RESULT 0xC000FFFF @@ -598,7 +597,7 @@ static void CreateFullPathName(char * szBuffer, size_t cchBuffer, LPCTSTR szSubD } #endif -static int CalculateFileSha1(TLogHelper * pLogger, LPCTSTR szFullPath, TCHAR * szFileSha1) +static DWORD CalculateFileSha1(TLogHelper * pLogger, LPCTSTR szFullPath, TCHAR * szFileSha1) { TFileStream * pStream; unsigned char sha1_digest[SHA1_DIGEST_SIZE]; @@ -609,7 +608,7 @@ static int CalculateFileSha1(TLogHelper * pLogger, LPCTSTR szFullPath, TCHAR * s BYTE * pbFileBlock; DWORD cbBytesToRead; DWORD cbFileBlock = 0x100000; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Notify the user pLogger->PrintProgress(_T("Hashing file %s"), szShortPlainName); @@ -639,7 +638,7 @@ static int CalculateFileSha1(TLogHelper * pLogger, LPCTSTR szFullPath, TCHAR * s cbBytesToRead = ((FileSize - ByteOffset) > cbFileBlock) ? cbFileBlock : (DWORD)(FileSize - ByteOffset); if(!FileStream_Read(pStream, &ByteOffset, pbFileBlock, cbBytesToRead)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -663,9 +662,9 @@ static int CalculateFileSha1(TLogHelper * pLogger, LPCTSTR szFullPath, TCHAR * s } // If we calculated something, return OK - if(nError == ERROR_SUCCESS && szFileSha1[0] == 0) - nError = ERROR_CAN_NOT_COMPLETE; - return nError; + if(dwErrCode == ERROR_SUCCESS && szFileSha1[0] == 0) + dwErrCode = ERROR_CAN_NOT_COMPLETE; + return dwErrCode; } //----------------------------------------------------------------------------- @@ -751,14 +750,14 @@ static void FreeDirectorySearch(HANDLE hFind) #endif } -static int FindFilesInternal(FIND_FILE_CALLBACK pfnTest, TCHAR * szDirectory) +static DWORD FindFilesInternal(FIND_FILE_CALLBACK pfnTest, TCHAR * szDirectory) { TCHAR * szPlainName; HANDLE hFind; size_t nLength; TCHAR szDirEntry[MAX_PATH]; bool IsDirectory = false; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; if(szDirectory != NULL) { @@ -772,7 +771,7 @@ static int FindFilesInternal(FIND_FILE_CALLBACK pfnTest, TCHAR * szDirectory) szPlainName = szDirectory + nLength; // Skip the first entry, since it's always "." or ".." - while(SearchDirectory(hFind, szDirEntry, _countof(szDirEntry), IsDirectory) && nError == ERROR_SUCCESS) + while(SearchDirectory(hFind, szDirEntry, _countof(szDirEntry), IsDirectory) && dwErrCode == ERROR_SUCCESS) { // Copy the directory entry name to both names _tcscpy(szPlainName, szDirEntry); @@ -782,14 +781,14 @@ static int FindFilesInternal(FIND_FILE_CALLBACK pfnTest, TCHAR * szDirectory) { if(szDirEntry[0] != '.') { - nError = FindFilesInternal(pfnTest, szDirectory); + dwErrCode = FindFilesInternal(pfnTest, szDirectory); } } else { if(pfnTest != NULL) { - nError = pfnTest(szDirectory); + dwErrCode = pfnTest(szDirectory); } } } @@ -799,10 +798,10 @@ static int FindFilesInternal(FIND_FILE_CALLBACK pfnTest, TCHAR * szDirectory) } // Free the path buffer, if any - return nError; + return dwErrCode; } -static int FindFiles(FIND_FILE_CALLBACK pfnFindFile, LPCTSTR szSubDirectory) +static DWORD FindFiles(FIND_FILE_CALLBACK pfnFindFile, LPCTSTR szSubDirectory) { TCHAR szWorkBuff[MAX_PATH]; @@ -810,7 +809,7 @@ static int FindFiles(FIND_FILE_CALLBACK pfnFindFile, LPCTSTR szSubDirectory) return FindFilesInternal(pfnFindFile, szWorkBuff); } -static int InitializeMpqDirectory(TCHAR * argv[], int argc) +static DWORD InitializeMpqDirectory(TCHAR * argv[], int argc) { TLogHelper Logger("InitWorkDir"); TFileStream * pStream; @@ -995,10 +994,10 @@ static DWORD VerifyFilePosition( return dwErrCode; } -static int VerifyFileMpqHeader(TLogHelper * pLogger, TFileStream * pStream, ULONGLONG * pByteOffset) +static DWORD VerifyFileMpqHeader(TLogHelper * pLogger, TFileStream * pStream, ULONGLONG * pByteOffset) { TMPQHeader Header; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; memset(&Header, 0xFE, sizeof(TMPQHeader)); if(FileStream_Read(pStream, pByteOffset, &Header, sizeof(TMPQHeader))) @@ -1006,25 +1005,25 @@ static int VerifyFileMpqHeader(TLogHelper * pLogger, TFileStream * pStream, ULON if(Header.dwID != g_dwMpqSignature) { pLogger->PrintMessage(_T("Read error - the data is not a MPQ header")); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } else { - nError = pLogger->PrintError(_T("Failed to read the MPQ header")); + dwErrCode = pLogger->PrintError(_T("Failed to read the MPQ header")); } - return nError; + return dwErrCode; } -static int WriteMpqUserDataHeader( +static DWORD WriteMpqUserDataHeader( TLogHelper * pLogger, TFileStream * pStream, ULONGLONG ByteOffset, DWORD dwByteCount) { TMPQUserData UserData; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Notify the user pLogger->PrintProgress("Writing user data header..."); @@ -1035,11 +1034,11 @@ static int WriteMpqUserDataHeader( UserData.dwHeaderOffs = (dwByteCount + sizeof(TMPQUserData)); UserData.cbUserDataHeader = dwByteCount / 2; if(!FileStream_Write(pStream, &ByteOffset, &UserData, sizeof(TMPQUserData))) - nError = GetLastError(); - return nError; + dwErrCode = GetLastError(); + return dwErrCode; } -static int WriteFileData( +static DWORD WriteFileData( TLogHelper * pLogger, TFileStream * pStream, ULONGLONG ByteOffset, @@ -1049,7 +1048,7 @@ static int WriteFileData( ULONGLONG BytesWritten = 0; LPBYTE pbDataBuffer; DWORD cbDataBuffer = 0x10000; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Write some data pbDataBuffer = new BYTE[cbDataBuffer]; @@ -1069,7 +1068,7 @@ static int WriteFileData( // Write the data if(!FileStream_Write(pStream, &ByteOffset, pbDataBuffer, cbToWrite)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -1080,10 +1079,10 @@ static int WriteFileData( delete [] pbDataBuffer; } - return nError; + return dwErrCode; } -static int CopyFileData( +static DWORD CopyFileData( TLogHelper * pLogger, TFileStream * pStream1, TFileStream * pStream2, @@ -1095,7 +1094,7 @@ static int CopyFileData( LPBYTE pbCopyBuffer; DWORD BytesToRead; DWORD BlockLength = 0x100000; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Allocate copy buffer pbCopyBuffer = STORM_ALLOC(BYTE, BlockLength); @@ -1107,14 +1106,14 @@ static int CopyFileData( BytesToRead = ((EndOffset - ByteOffset) > BlockLength) ? BlockLength : (DWORD)(EndOffset - ByteOffset); if(!FileStream_Read(pStream1, &ByteOffset, pbCopyBuffer, BytesToRead)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } // Write to the destination file if(!FileStream_Write(pStream2, NULL, pbCopyBuffer, BytesToRead)) { - nError = GetLastError(); + dwErrCode = GetLastError(); break; } @@ -1129,11 +1128,11 @@ static int CopyFileData( STORM_FREE(pbCopyBuffer); } - return nError; + return dwErrCode; } // Support function for copying file -static int CreateFileCopy( +static DWORD CreateFileCopy( TLogHelper * pLogger, LPCTSTR szPlainName, LPCTSTR szFileCopy, @@ -1148,7 +1147,7 @@ static int CreateFileCopy( ULONGLONG FileSize = 0; TCHAR szFileName1[MAX_PATH]; TCHAR szFileName2[MAX_PATH]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Notify the user szPlainName += FileStream_Prefix(szPlainName, NULL); @@ -1178,17 +1177,17 @@ static int CreateFileCopy( // If we should write some pre-MPQ data to the target file, do it if(PreMpqDataSize != 0) { - nError = WriteFileData(pLogger, pStream2, ByteOffset, PreMpqDataSize); + dwErrCode = WriteFileData(pLogger, pStream2, ByteOffset, PreMpqDataSize); ByteOffset += PreMpqDataSize; } // If we should write some MPQ user data, write the header first if(UserDataSize != 0) { - nError = WriteMpqUserDataHeader(pLogger, pStream2, ByteOffset, (DWORD)UserDataSize); + dwErrCode = WriteMpqUserDataHeader(pLogger, pStream2, ByteOffset, (DWORD)UserDataSize); ByteOffset += sizeof(TMPQUserData); - nError = WriteFileData(pLogger, pStream2, ByteOffset, UserDataSize); + dwErrCode = WriteFileData(pLogger, pStream2, ByteOffset, UserDataSize); ByteOffset += UserDataSize; } @@ -1196,7 +1195,7 @@ static int CreateFileCopy( FileStream_GetSize(pStream1, &FileSize); if(FileSize != 0) { - nError = CopyFileData(pLogger, pStream1, pStream2, 0, FileSize); + dwErrCode = CopyFileData(pLogger, pStream1, pStream2, 0, FileSize); ByteOffset += FileSize; } FileStream_Close(pStream2); @@ -1210,12 +1209,12 @@ static int CreateFileCopy( CreateFullPathName(szBuffer, cchBuffer, NULL, szFileCopy); // Report error, if any - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) pLogger->PrintError("Failed to create copy of MPQ"); - return nError; + return dwErrCode; } -static int CreateMasterAndMirrorPaths( +static DWORD CreateMasterAndMirrorPaths( TLogHelper * pLogger, TCHAR * szMirrorPath, TCHAR * szMasterPath, @@ -1224,7 +1223,7 @@ static int CreateMasterAndMirrorPaths( bool bCopyMirrorFile) { TCHAR szCopyPath[MAX_PATH]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Always delete the mirror file CreateFullPathName(szMasterPath, MAX_PATH, szMpqSubDir, szMasterName); @@ -1233,13 +1232,13 @@ static int CreateMasterAndMirrorPaths( // Copy the mirrored file from the source to the work directory if(bCopyMirrorFile) - nError = CreateFileCopy(pLogger, szMirrorName, szMirrorName); + dwErrCode = CreateFileCopy(pLogger, szMirrorName, szMirrorName); // Create the mirror*master path - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) _stprintf(szMirrorPath, _T("%s*%s"), szCopyPath, szMasterPath); - return nError; + return dwErrCode; } static void WINAPI AddFileCallback(void * pvUserData, DWORD dwBytesWritten, DWORD dwTotalBytes, bool bFinalCall) @@ -1376,7 +1375,7 @@ static TFileData * LoadLocalFile(TLogHelper * pLogger, LPCTSTR szFileName, bool return pFileData; } -static int CompareTwoLocalFilesRR( +static DWORD CompareTwoLocalFilesRR( TLogHelper * pLogger, TFileStream * pStream1, // Master file TFileStream * pStream2, // Mirror file @@ -1392,7 +1391,7 @@ static int CompareTwoLocalFilesRR( LPBYTE pbBuffer1; LPBYTE pbBuffer2; DWORD cbBuffer = 0x100000; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Compare file sizes FileStream_GetSize(pStream1, &FileSize1); @@ -1433,7 +1432,7 @@ static int CompareTwoLocalFilesRR( if(!CompareBlocks(pbBuffer1, pbBuffer2, BytesToRead, &Difference)) { pLogger->PrintMessage("Difference at %u (Offset " I64X_a ", Length %X)", Difference, ByteOffset, BytesToRead); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; break; } @@ -1449,10 +1448,10 @@ static int CompareTwoLocalFilesRR( STORM_FREE(pbBuffer2); if(pbBuffer1 != NULL) STORM_FREE(pbBuffer1); - return nError; + return dwErrCode; } -static TFileData * LoadMpqFile(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szFileName, LCID lcLocale = 0, bool bIgnoreOpenErrors = false) +static TFileData * LoadMpqFile(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szFileName, LCID lcLocale = 0, bool bIgnoreOpedwErrCodes = false) { TFileData * pFileData = NULL; HANDLE hFile; @@ -1542,7 +1541,7 @@ static TFileData * LoadMpqFile(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szFileN } else { - if(bIgnoreOpenErrors == false) + if(bIgnoreOpedwErrCodes == false) { dwErrCode = pLogger->PrintError("Open failed: %s", szFileName); } @@ -1592,7 +1591,7 @@ static DWORD SearchArchive( TCHAR szListFile[MAX_PATH] = _T(""); char szMostPatched[MAX_PATH] = ""; DWORD dwErrCode = ERROR_SUCCESS; - bool bIgnoreOpenErrors = (dwSearchFlags & SEARCH_FLAG_IGNORE_ERRORS) ? true : false; + bool bIgnoreOpedwErrCodes = (dwSearchFlags & SEARCH_FLAG_IGNORE_ERRORS) ? true : false; bool bFound = true; int nMaxPatchCount = 0; int nPatchCount = 0; @@ -1640,7 +1639,7 @@ static DWORD SearchArchive( if(dwSearchFlags & SEARCH_FLAG_LOAD_FILES) { // Load the entire file to the MPQ - pFileData = LoadMpqFile(pLogger, hMpq, sf.cFileName, sf.lcLocale, bIgnoreOpenErrors); + pFileData = LoadMpqFile(pLogger, hMpq, sf.cFileName, sf.lcLocale, bIgnoreOpedwErrCodes); if(pFileData != NULL) { // Hash the file data, if needed @@ -1675,7 +1674,7 @@ static DWORD SearchArchive( return dwErrCode; } -static int CreateNewArchive(TLogHelper * pLogger, LPCTSTR szPlainName, DWORD dwCreateFlags, DWORD dwMaxFileCount, HANDLE * phMpq) +static DWORD CreateNewArchive(TLogHelper * pLogger, LPCTSTR szPlainName, DWORD dwCreateFlags, DWORD dwMaxFileCount, HANDLE * phMpq) { HANDLE hMpq = NULL; TCHAR szMpqName[MAX_PATH]; @@ -1699,7 +1698,7 @@ static int CreateNewArchive(TLogHelper * pLogger, LPCTSTR szPlainName, DWORD dwC return ERROR_SUCCESS; } -static int CreateNewArchive_V2(TLogHelper * pLogger, LPCTSTR szPlainName, DWORD dwCreateFlags, DWORD dwMaxFileCount, HANDLE * phMpq) +static DWORD CreateNewArchive_V2(TLogHelper * pLogger, LPCTSTR szPlainName, DWORD dwCreateFlags, DWORD dwMaxFileCount, HANDLE * phMpq) { SFILE_CREATE_MPQ CreateInfo; HANDLE hMpq = NULL; @@ -1740,7 +1739,7 @@ static int CreateNewArchive_V2(TLogHelper * pLogger, LPCTSTR szPlainName, DWORD } // Creates new archive with UNICODE name. Adds prefix to the name -static int CreateNewArchiveU(TLogHelper * pLogger, const wchar_t * szPlainName, DWORD dwCreateFlags, DWORD dwMaxFileCount) +static DWORD CreateNewArchiveU(TLogHelper * pLogger, const wchar_t * szPlainName, DWORD dwCreateFlags, DWORD dwMaxFileCount) { #ifdef _UNICODE HANDLE hMpq = NULL; @@ -1770,11 +1769,11 @@ static int CreateNewArchiveU(TLogHelper * pLogger, const wchar_t * szPlainName, return ERROR_SUCCESS; } -static int OpenExistingArchive(TLogHelper * pLogger, LPCTSTR szFullPath, DWORD dwFlags, HANDLE * phMpq) +static DWORD OpenExistingArchive(TLogHelper * pLogger, LPCTSTR szFullPath, DWORD dwFlags, HANDLE * phMpq) { HANDLE hMpq = NULL; // bool bReopenResult; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Is it an encrypted MPQ ? if(_tcsstr(szFullPath, _T(".MPQE")) != NULL) @@ -1790,16 +1789,16 @@ static int OpenExistingArchive(TLogHelper * pLogger, LPCTSTR szFullPath, DWORD d pLogger->PrintProgress(_T("Opening archive %s ..."), GetShortPlainName(szFullPath)); if(!SFileOpenArchive(szFullPath, 0, dwFlags, &hMpq)) { - switch(nError = GetLastError()) + switch(dwErrCode = GetLastError()) { // case ERROR_BAD_FORMAT: // If the error is ERROR_BAD_FORMAT, try to open with MPQ_OPEN_FORCE_MPQ_V1 // bReopenResult = SFileOpenArchive(szMpqName, 0, dwFlags | MPQ_OPEN_FORCE_MPQ_V1, &hMpq); -// nError = (bReopenResult == false) ? GetLastError() : ERROR_SUCCESS; +// dwErrCode = (bReopenResult == false) ? GetLastError() : ERROR_SUCCESS; // break; case ERROR_AVI_FILE: // Ignore the error if it's an AVI file or if the file is incomplete case ERROR_FILE_INCOMPLETE: - return nError; + return dwErrCode; } // Show the open error to the user @@ -1811,27 +1810,27 @@ static int OpenExistingArchive(TLogHelper * pLogger, LPCTSTR szFullPath, DWORD d SFileCloseArchive(hMpq); else *phMpq = hMpq; - return nError; + return dwErrCode; } -static int OpenPatchArchive(TLogHelper * pLogger, HANDLE hMpq, LPCTSTR szFullPath) +static DWORD OpenPatchArchive(TLogHelper * pLogger, HANDLE hMpq, LPCTSTR szFullPath) { TCHAR szPatchName[MAX_PATH]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; pLogger->PrintProgress(_T("Adding patch %s ..."), GetShortPlainName(szFullPath)); StringCopy(szPatchName, _countof(szPatchName), szFullPath); if(!SFileOpenPatchArchive(hMpq, szPatchName, NULL, 0)) - nError = pLogger->PrintError(_T("Failed to add patch %s ..."), szFullPath); + dwErrCode = pLogger->PrintError(_T("Failed to add patch %s ..."), szFullPath); - return nError; + return dwErrCode; } -static int OpenExistingArchiveWithCopy(TLogHelper * pLogger, LPCTSTR szFileName, LPCTSTR szCopyName, HANDLE * phMpq) +static DWORD OpenExistingArchiveWithCopy(TLogHelper * pLogger, LPCTSTR szFileName, LPCTSTR szCopyName, HANDLE * phMpq) { DWORD dwFlags = 0; TCHAR szFullPath[MAX_PATH]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // We expect MPQ directory to be already prepared by InitializeMpqDirectory assert(szMpqDirectory[0] != 0); @@ -1842,9 +1841,9 @@ static int OpenExistingArchiveWithCopy(TLogHelper * pLogger, LPCTSTR szFileName, // If both names entered, create a copy if(szFileName != NULL && szCopyName != NULL) { - nError = CreateFileCopy(pLogger, szFileName, szCopyName, szFullPath, _countof(szFullPath)); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = CreateFileCopy(pLogger, szFileName, szCopyName, szFullPath, _countof(szFullPath)); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; } // If only source name entered, open it for read-only access @@ -1864,33 +1863,33 @@ static int OpenExistingArchiveWithCopy(TLogHelper * pLogger, LPCTSTR szFileName, return OpenExistingArchive(pLogger, szFullPath, dwFlags, phMpq); } -static int OpenPatchedArchive(TLogHelper * pLogger, HANDLE * phMpq, LPCTSTR PatchList[]) +static DWORD OpenPatchedArchive(TLogHelper * pLogger, HANDLE * phMpq, LPCTSTR PatchList[]) { HANDLE hMpq = NULL; TCHAR szFullPath[MAX_PATH]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // The first file is expected to be valid assert(PatchList[0] != NULL); // Open the primary MPQ CreateFullPathName(szFullPath, _countof(szFullPath), szMpqSubDir, PatchList[0]); - nError = OpenExistingArchive(pLogger, szFullPath, MPQ_OPEN_READ_ONLY, &hMpq); + dwErrCode = OpenExistingArchive(pLogger, szFullPath, MPQ_OPEN_READ_ONLY, &hMpq); // Add all patches - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { for(size_t i = 1; PatchList[i] != NULL; i++) { CreateFullPathName(szFullPath, _countof(szFullPath), szMpqPatchDir, PatchList[i]); - nError = OpenPatchArchive(pLogger, hMpq, szFullPath); - if(nError != ERROR_SUCCESS) + dwErrCode = OpenPatchArchive(pLogger, hMpq, szFullPath); + if(dwErrCode != ERROR_SUCCESS) break; } } // If anything failed, close the MPQ handle - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) { SFileCloseArchive(hMpq); hMpq = NULL; @@ -1899,21 +1898,21 @@ static int OpenPatchedArchive(TLogHelper * pLogger, HANDLE * phMpq, LPCTSTR Patc // Give the archive handle to the caller if(phMpq != NULL) *phMpq = hMpq; - return nError; + return dwErrCode; } -static int AddFileToMpq( +static DWORD AddFileToMpq( TLogHelper * pLogger, HANDLE hMpq, LPCSTR szFileName, LPCSTR szFileData, DWORD dwFlags = 0, DWORD dwCompression = 0, - int nExpectedError = ERROR_SUCCESS) + DWORD dwExpectedError = ERROR_SUCCESS) { HANDLE hFile = NULL; DWORD dwFileSize = (DWORD)strlen(szFileData); - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Notify the user pLogger->PrintProgress("Adding file %s ...", szFileName); @@ -1929,21 +1928,21 @@ static int AddFileToMpq( { // Write the file if(!SFileWriteFile(hFile, szFileData, dwFileSize, dwCompression)) - nError = pLogger->PrintError("Failed to write data to the MPQ"); + dwErrCode = pLogger->PrintError("Failed to write data to the MPQ"); SFileCloseFile(hFile); } else { - nError = GetLastError(); + dwErrCode = GetLastError(); } // Check the expected error code - if(nExpectedError != ERROR_UNDETERMINED_RESULT && nError != nExpectedError) + if(dwExpectedError != ERROR_UNDETERMINED_RESULT && dwErrCode != dwExpectedError) return pLogger->PrintError("Unexpected result from SFileCreateFile(%s)", szFileName); - return nError; + return dwErrCode; } -static int AddLocalFileToMpq( +static DWORD AddLocalFileToMpq( TLogHelper * pLogger, HANDLE hMpq, LPCSTR szArchivedName, @@ -1992,34 +1991,34 @@ static int AddLocalFileToMpq( return ERROR_SUCCESS; } -static int RenameMpqFile(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szOldFileName, LPCSTR szNewFileName, int nExpectedError) +static DWORD RenameMpqFile(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szOldFileName, LPCSTR szNewFileName, DWORD dwExpectedError) { - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Notify the user pLogger->PrintProgress("Renaming %s to %s ...", szOldFileName, szNewFileName); // Perform the deletion if(!SFileRenameFile(hMpq, szOldFileName, szNewFileName)) - nError = GetLastError(); + dwErrCode = GetLastError(); - if(nError != nExpectedError) + if(dwErrCode != dwExpectedError) return pLogger->PrintErrorVa("Unexpected result from SFileRenameFile(%s -> %s)", szOldFileName, szNewFileName); return ERROR_SUCCESS; } -static int RemoveMpqFile(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szFileName, int nExpectedError) +static DWORD RemoveMpqFile(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szFileName, DWORD dwExpectedError) { - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Notify the user pLogger->PrintProgress("Removing file %s ...", szFileName); // Perform the deletion if(!SFileRemoveFile(hMpq, szFileName, 0)) - nError = GetLastError(); + dwErrCode = GetLastError(); - if(nError != nExpectedError) + if(dwErrCode != dwExpectedError) return pLogger->PrintError("Unexpected result from SFileRemoveFile(%s)", szFileName); return ERROR_SUCCESS; } @@ -2036,34 +2035,34 @@ static ULONGLONG SFileGetFilePointer(HANDLE hFile) //----------------------------------------------------------------------------- // Tests -static int TestSetFilePointer( +static DWORD TestSetFilePointer( HANDLE hFile, LONGLONG DeltaPos, ULONGLONG ExpectedPos, DWORD dwMoveMethod, bool bUseFilePosHigh, - int nError) + DWORD dwErrCode) { ULONGLONG NewPos = 0; LONG DeltaPosHi = (LONG)(DeltaPos >> 32); LONG DeltaPosLo = (LONG)(DeltaPos); // If there was an error before, do nothing - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { SFileSetFilePointer(hFile, DeltaPosLo, bUseFilePosHigh ? &DeltaPosHi : NULL, dwMoveMethod); NewPos = SFileGetFilePointer(hFile); if(NewPos != ExpectedPos) - nError = ERROR_HANDLE_EOF; + dwErrCode = ERROR_HANDLE_EOF; } - return nError; + return dwErrCode; } -static int TestSetFilePointers(HANDLE hFile, bool bUseFilePosHigh) +static DWORD TestSetFilePointers(HANDLE hFile, bool bUseFilePosHigh) { LONGLONG FileSize; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // We expect the file to be at least 2 pages long FileSize = SFileGetFileSize(hFile, NULL); @@ -2071,21 +2070,21 @@ static int TestSetFilePointers(HANDLE hFile, bool bUseFilePosHigh) return ERROR_NOT_SUPPORTED; // Move 0x20 bytes from the beginning. Expected new pos is 0x20 - nError = TestSetFilePointer(hFile, 0x20, 0x20, FILE_BEGIN, bUseFilePosHigh, nError); + dwErrCode = TestSetFilePointer(hFile, 0x20, 0x20, FILE_BEGIN, bUseFilePosHigh, dwErrCode); // Move 0x20 bytes from the current position. Expected new pos is 0x20 - nError = TestSetFilePointer(hFile, 0x20, 0x40, FILE_CURRENT, bUseFilePosHigh, nError); + dwErrCode = TestSetFilePointer(hFile, 0x20, 0x40, FILE_CURRENT, bUseFilePosHigh, dwErrCode); // Move 0x40 bytes back. Because the offset can't be moved to negative position, it will be zero - nError = TestSetFilePointer(hFile, -64, 0x00, FILE_CURRENT, bUseFilePosHigh, nError); + dwErrCode = TestSetFilePointer(hFile, -64, 0x00, FILE_CURRENT, bUseFilePosHigh, dwErrCode); // Move 0x40 bytes before the end of the file - nError = TestSetFilePointer(hFile, -64, FileSize-64, FILE_END, bUseFilePosHigh, nError); + dwErrCode = TestSetFilePointer(hFile, -64, FileSize-64, FILE_END, bUseFilePosHigh, dwErrCode); // Move 0x80 bytes forward. Should be at end of file - nError = TestSetFilePointer(hFile, 0x80, FileSize, FILE_CURRENT, bUseFilePosHigh, nError); + dwErrCode = TestSetFilePointer(hFile, 0x80, FileSize, FILE_CURRENT, bUseFilePosHigh, dwErrCode); - return nError; + return dwErrCode; } @@ -2224,7 +2223,7 @@ static void WINAPI TestReadFile_DownloadCallback( } // Open a file stream with mirroring a master file -static int TestReadFile_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterName, bool bCopyMirrorFile) +static DWORD TestReadFile_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterName, bool bCopyMirrorFile) { TFileStream * pStream1; // Master file TFileStream * pStream2; // Mirror file @@ -2233,7 +2232,7 @@ static int TestReadFile_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterName, TCHAR szMasterPath[MAX_PATH]; DWORD dwProvider = 0; int nIterations = 0x10000; - int nError; + DWORD dwErrCode; // Retrieve the provider FileStream_Prefix(szMasterName, &dwProvider); @@ -2244,8 +2243,8 @@ static int TestReadFile_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterName, #endif // Create copy of the file to serve as mirror, keep master there - nError = CreateMasterAndMirrorPaths(&Logger, szMirrorPath, szMasterPath, szMirrorName, szMasterName, bCopyMirrorFile); - if(nError == ERROR_SUCCESS) + dwErrCode = CreateMasterAndMirrorPaths(&Logger, szMirrorPath, szMasterPath, szMirrorName, szMasterName, bCopyMirrorFile); + if(dwErrCode == ERROR_SUCCESS) { // Open both master and mirror file pStream1 = FileStream_OpenFile(szMasterPath, STREAM_FLAG_READ_ONLY); @@ -2257,7 +2256,7 @@ static int TestReadFile_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterName, nIterations = 0x80; FileStream_SetCallback(pStream2, TestReadFile_DownloadCallback, &Logger); - nError = CompareTwoLocalFilesRR(&Logger, pStream1, pStream2, nIterations); + dwErrCode = CompareTwoLocalFilesRR(&Logger, pStream1, pStream2, nIterations); } if(pStream2 != NULL) @@ -2266,11 +2265,11 @@ static int TestReadFile_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterName, FileStream_Close(pStream1); } - return nError; + return dwErrCode; } // Test of the TFileStream object -static int TestFileStreamOperations(LPCTSTR szPlainName, DWORD dwStreamFlags) +static DWORD TestFileStreamOperations(LPCTSTR szPlainName, DWORD dwStreamFlags) { TFileStream * pStream = NULL; TLogHelper Logger("FileStreamTest", szPlainName); @@ -2279,16 +2278,16 @@ static int TestFileStreamOperations(LPCTSTR szPlainName, DWORD dwStreamFlags) TCHAR szFullPath[MAX_PATH]; DWORD dwRequiredFlags = 0; BYTE Buffer[0x10]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Copy the file so we won't screw up if((dwStreamFlags & STREAM_PROVIDER_MASK) == STREAM_PROVIDER_BLOCK4) CreateFullPathName(szFullPath, _countof(szFullPath), szMpqSubDir, szPlainName); else - nError = CreateFileCopy(&Logger, szPlainName, szPlainName, szFullPath, _countof(szFullPath)); + dwErrCode = CreateFileCopy(&Logger, szPlainName, szPlainName, szFullPath, _countof(szFullPath)); // Open the file stream - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { pStream = FileStream_OpenFile(szFullPath, dwStreamFlags); if(pStream == NULL) @@ -2296,13 +2295,13 @@ static int TestFileStreamOperations(LPCTSTR szPlainName, DWORD dwStreamFlags) } // Get the size of the file stream - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(!FileStream_GetFlags(pStream, &dwStreamFlags)) - nError = Logger.PrintError("Failed to retrieve the stream flags"); + dwErrCode = Logger.PrintError("Failed to retrieve the stream flags"); if(!FileStream_GetSize(pStream, &FileSize)) - nError = Logger.PrintError("Failed to retrieve the file size"); + dwErrCode = Logger.PrintError("Failed to retrieve the file size"); // Any other stream except STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE should be read-only if((dwStreamFlags & STREAM_PROVIDERS_MASK) != (STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE)) @@ -2314,35 +2313,35 @@ static int TestFileStreamOperations(LPCTSTR szPlainName, DWORD dwStreamFlags) if((dwStreamFlags & dwRequiredFlags) != dwRequiredFlags) { Logger.PrintMessage("The stream should be read-only but it isn't"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // After successful open, the stream position must be zero - if(nError == ERROR_SUCCESS) - nError = VerifyFilePosition(&Logger, pStream, 0); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = VerifyFilePosition(&Logger, pStream, 0); // Read the MPQ header from the current file offset. - if(nError == ERROR_SUCCESS) - nError = VerifyFileMpqHeader(&Logger, pStream, NULL); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = VerifyFileMpqHeader(&Logger, pStream, NULL); // After successful open, the stream position must sizeof(TMPQHeader) - if(nError == ERROR_SUCCESS) - nError = VerifyFilePosition(&Logger, pStream, sizeof(TMPQHeader)); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = VerifyFilePosition(&Logger, pStream, sizeof(TMPQHeader)); // Now try to read the MPQ header from the offset 0 - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { ByteOffset = 0; - nError = VerifyFileMpqHeader(&Logger, pStream, &ByteOffset); + dwErrCode = VerifyFileMpqHeader(&Logger, pStream, &ByteOffset); } // After successful open, the stream position must sizeof(TMPQHeader) - if(nError == ERROR_SUCCESS) - nError = VerifyFilePosition(&Logger, pStream, sizeof(TMPQHeader)); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = VerifyFilePosition(&Logger, pStream, sizeof(TMPQHeader)); // Try a write operation - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { bool bExpectedResult = (dwStreamFlags & STREAM_FLAG_READ_ONLY) ? false : true; bool bResult; @@ -2355,57 +2354,57 @@ static int TestFileStreamOperations(LPCTSTR szPlainName, DWORD dwStreamFlags) if(bResult != bExpectedResult) { Logger.PrintMessage("FileStream_Write result is different than expected"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Move the position 9 bytes from the end and try to read 10 bytes. // This must fail, because stream reading functions are "all or nothing" - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { ByteOffset = FileSize - 9; if(FileStream_Read(pStream, &ByteOffset, Buffer, 10)) { Logger.PrintMessage("FileStream_Read succeeded, but it shouldn't"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Try again with 9 bytes. This must succeed, unless the file block is not available - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { ByteOffset = FileSize - 9; if(!FileStream_Read(pStream, &ByteOffset, Buffer, 9)) { Logger.PrintMessage("FileStream_Read from the end of the file failed"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Verify file position - it must be at the end of the file - if(nError == ERROR_SUCCESS) - nError = VerifyFilePosition(&Logger, pStream, FileSize); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = VerifyFilePosition(&Logger, pStream, FileSize); // Close the stream if(pStream != NULL) FileStream_Close(pStream); - return nError; + return dwErrCode; } -static DWORD TestArchive_LoadFiles(TLogHelper * pLogger, HANDLE hMpq, bool bIgnoreOpenErrors, ...) +static DWORD TestArchive_LoadFiles(TLogHelper * pLogger, HANDLE hMpq, bool bIgnoreOpedwErrCodes, ...) { TFileData * pFileData; const char * szFileName; va_list argList; DWORD dwErrCode = ERROR_SUCCESS; - va_start(argList, bIgnoreOpenErrors); + va_start(argList, bIgnoreOpedwErrCodes); while((szFileName = va_arg(argList, const char *)) != NULL) { if(SFileHasFile(hMpq, szFileName)) { pFileData = LoadMpqFile(pLogger, hMpq, szFileName); - if(pFileData == NULL && bIgnoreOpenErrors == false) + if(pFileData == NULL && bIgnoreOpedwErrCodes == false) { pLogger->PrintError("Error loading the file %s", szFileName); dwErrCode = ERROR_FILE_CORRUPT; @@ -2465,7 +2464,7 @@ static DWORD TestArchive( TCHAR szFullName[MAX_PATH]; BYTE ExpectedMD5[MD5_DIGEST_SIZE]; BYTE OverallMD5[MD5_DIGEST_SIZE]; - bool bIgnoreOpenErrors = false; + bool bIgnoreOpedwErrCodes = false; // If the file is a partial MPQ, don't load all files if(_tcsstr(szPlainName, _T(".MPQ.part")) == NULL) @@ -2489,7 +2488,7 @@ static DWORD TestArchive( if(dwMpqFlags & MPQ_FLAG_MALFORMED) { dwSearchFlags |= SEARCH_FLAG_IGNORE_ERRORS; - bIgnoreOpenErrors = true; + bIgnoreOpedwErrCodes = true; } // If the listfile was given, add it to the MPQ @@ -2502,7 +2501,7 @@ static DWORD TestArchive( } // Attempt to open the (listfile), (attributes), (signature) - dwErrCode = TestArchive_LoadFiles(&Logger, hMpq, bIgnoreOpenErrors, LISTFILE_NAME, ATTRIBUTES_NAME, SIGNATURE_NAME, NULL); + dwErrCode = TestArchive_LoadFiles(&Logger, hMpq, bIgnoreOpedwErrCodes, LISTFILE_NAME, ATTRIBUTES_NAME, SIGNATURE_NAME, NULL); if(dwErrCode != ERROR_SUCCESS) break; @@ -2594,7 +2593,7 @@ static DWORD TestArchive( } // Open an empty archive (found in WoW cache - it's just a header) -static int TestOpenArchive_WillFail(LPCTSTR szPlainName) +static DWORD TestOpenArchive_WillFail(LPCTSTR szPlainName) { TLogHelper Logger("FailMpqTest", szPlainName); HANDLE hMpq = NULL; @@ -2615,7 +2614,7 @@ static int TestOpenArchive_WillFail(LPCTSTR szPlainName) return ERROR_CAN_NOT_COMPLETE; } -static int TestOpenArchive_Corrupt(LPCTSTR szPlainName) +static DWORD TestOpenArchive_Corrupt(LPCTSTR szPlainName) { TLogHelper Logger("OpenCorruptMpqTest", szPlainName); HANDLE hMpq = NULL; @@ -2678,7 +2677,7 @@ static DWORD TestOpenArchive_Patched(LPCTSTR PatchList[], LPCSTR szPatchedFile, } // Open an archive for read-only access -static int TestOpenArchive_ReadOnly(LPCTSTR szPlainName, bool bReadOnly) +static DWORD TestOpenArchive_ReadOnly(LPCTSTR szPlainName, bool bReadOnly) { TLogHelper Logger("ReadOnlyTest", szPlainName); LPCTSTR szCopyName; @@ -2686,32 +2685,32 @@ static int TestOpenArchive_ReadOnly(LPCTSTR szPlainName, bool bReadOnly) TCHAR szFullPath[MAX_PATH]; DWORD dwFlags = bReadOnly ? MPQ_OPEN_READ_ONLY : 0;; int nExpectedError; - int nError; + DWORD dwErrCode; // Copy the fiel so we wont screw up something szCopyName = bReadOnly ? _T("StormLibTest_ReadOnly.mpq") : _T("StormLibTest_ReadWrite.mpq"); - nError = CreateFileCopy(&Logger, szPlainName, szCopyName, szFullPath, _countof(szFullPath)); + dwErrCode = CreateFileCopy(&Logger, szPlainName, szCopyName, szFullPath, _countof(szFullPath)); // Now open the archive for read-only access - if(nError == ERROR_SUCCESS) - nError = OpenExistingArchive(&Logger, szFullPath, dwFlags, &hMpq); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = OpenExistingArchive(&Logger, szFullPath, dwFlags, &hMpq); // Now try to add a file. This must fail if the MPQ is read only - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { nExpectedError = (bReadOnly) ? ERROR_ACCESS_DENIED : ERROR_SUCCESS; AddFileToMpq(&Logger, hMpq, "AddedFile.txt", "This is an added file.", MPQ_FILE_COMPRESS | MPQ_FILE_ENCRYPTED, 0, nExpectedError); } // Now try to rename a file in the MPQ. This must only succeed if the MPQ is not read only - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { nExpectedError = (bReadOnly) ? ERROR_ACCESS_DENIED : ERROR_SUCCESS; RenameMpqFile(&Logger, hMpq, "spawn.mpq", "spawn-renamed.mpq", nExpectedError); } // Now try to delete a file in the MPQ. This must only succeed if the MPQ is not read only - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { nExpectedError = (bReadOnly) ? ERROR_ACCESS_DENIED : ERROR_SUCCESS; RemoveMpqFile(&Logger, hMpq, "spawn-renamed.mpq", nExpectedError); @@ -2720,10 +2719,10 @@ static int TestOpenArchive_ReadOnly(LPCTSTR szPlainName, bool bReadOnly) // Close the archive if(hMpq != NULL) SFileCloseArchive(hMpq); - return nError; + return dwErrCode; } -static int TestOpenArchive_GetFileInfo(LPCTSTR szPlainName1, LPCTSTR szPlainName4) +static DWORD TestOpenArchive_GetFileInfo(LPCTSTR szPlainName1, LPCTSTR szPlainName4) { TLogHelper Logger("GetFileInfoTest", szPlainName1, szPlainName4); HANDLE hFile; @@ -2731,13 +2730,13 @@ static int TestOpenArchive_GetFileInfo(LPCTSTR szPlainName1, LPCTSTR szPlainName HANDLE hMpq1; DWORD cbLength; BYTE DataBuff[0x400]; - int nError1; - int nError4; + DWORD dwErrCode1; + DWORD dwErrCode4; // Copy the archive so we won't fuck up the original one - nError1 = OpenExistingArchiveWithCopy(&Logger, szPlainName1, NULL, &hMpq1); - nError4 = OpenExistingArchiveWithCopy(&Logger, szPlainName4, NULL, &hMpq4); - if(nError1 == ERROR_SUCCESS && nError4 == ERROR_SUCCESS) + dwErrCode1 = OpenExistingArchiveWithCopy(&Logger, szPlainName1, NULL, &hMpq1); + dwErrCode4 = OpenExistingArchiveWithCopy(&Logger, szPlainName4, NULL, &hMpq4); + if(dwErrCode1 == ERROR_SUCCESS && dwErrCode4 == ERROR_SUCCESS) { // Invalid handle - expected (false, ERROR_INVALID_HANDLE) TestGetFileInfo(&Logger, NULL, SFileMpqBetHeader, NULL, 0, NULL, false, ERROR_INVALID_HANDLE); @@ -2800,7 +2799,7 @@ static int TestOpenArchive_GetFileInfo(LPCTSTR szPlainName1, LPCTSTR szPlainName return ERROR_SUCCESS; } -static int TestOpenArchive_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterName, LPCSTR szFileToExtract, bool bCopyMirrorFile) +static DWORD TestOpenArchive_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterName, LPCSTR szFileToExtract, bool bCopyMirrorFile) { TFileData * pFileData; TLogHelper Logger("OpenServerMirror", szMirrorName); @@ -2809,41 +2808,41 @@ static int TestOpenArchive_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterNa DWORD dwVerifyResult; TCHAR szMirrorPath[MAX_PATH + MAX_PATH]; // Combined name TCHAR szMasterPath[MAX_PATH]; // Original (server) name - int nError; + DWORD dwErrCode; // Create both paths - nError = CreateMasterAndMirrorPaths(&Logger, szMirrorPath, szMasterPath, szMirrorName, szMasterName, bCopyMirrorFile); + dwErrCode = CreateMasterAndMirrorPaths(&Logger, szMirrorPath, szMasterPath, szMirrorName, szMasterName, bCopyMirrorFile); // Now open both archives as local-server pair - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = OpenExistingArchive(&Logger, szMirrorPath, 0, &hMpq); + dwErrCode = OpenExistingArchive(&Logger, szMirrorPath, 0, &hMpq); } // The MPQ must be read-only. Writing to mirrored MPQ is not allowed - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(SFileCreateFile(hMpq, "AddedFile.bin", 0, 0x10, 0, MPQ_FILE_COMPRESS, &hFile)) { SFileCloseFile(hFile); Logger.PrintMessage("The archive is writable, although it should not be"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Verify the file - if(nError == ERROR_SUCCESS && szFileToExtract != NULL) + if(dwErrCode == ERROR_SUCCESS && szFileToExtract != NULL) { dwVerifyResult = SFileVerifyFile(hMpq, szFileToExtract, SFILE_VERIFY_ALL); if(dwVerifyResult & VERIFY_FILE_ERROR_MASK) { Logger.PrintMessage("File verification failed"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Load the file to memory - if(nError == ERROR_SUCCESS && szFileToExtract) + if(dwErrCode == ERROR_SUCCESS && szFileToExtract) { pFileData = LoadMpqFile(&Logger, hMpq, szFileToExtract); if(pFileData != NULL) @@ -2852,21 +2851,21 @@ static int TestOpenArchive_MasterMirror(LPCTSTR szMirrorName, LPCTSTR szMasterNa if(hMpq != NULL) SFileCloseArchive(hMpq); - return nError; + return dwErrCode; } -static int TestOpenArchive_VerifySignature(LPCTSTR szPlainName, LPCTSTR szOriginalName) +static DWORD TestOpenArchive_VerifySignature(LPCTSTR szPlainName, LPCTSTR szOriginalName) { TLogHelper Logger("VerifySignatureTest", szPlainName); HANDLE hMpq; DWORD dwSignatures = 0; + DWORD dwErrCode = ERROR_SUCCESS; int nVerifyError; - int nError = ERROR_SUCCESS; // We need original name for the signature check - nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szOriginalName, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, szPlainName, szOriginalName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Query the signature types Logger.PrintProgress("Retrieving signatures ..."); @@ -2880,31 +2879,31 @@ static int TestOpenArchive_VerifySignature(LPCTSTR szPlainName, LPCTSTR szOrigin if((dwSignatures & SIGNATURE_TYPE_STRONG) && (nVerifyError != ERROR_STRONG_SIGNATURE_OK)) { Logger.PrintMessage("Strong signature verification error"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } // Verify the result if((dwSignatures & SIGNATURE_TYPE_WEAK) && (nVerifyError != ERROR_WEAK_SIGNATURE_OK)) { Logger.PrintMessage("Weak signature verification error"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } SFileCloseArchive(hMpq); } - return nError; + return dwErrCode; } -static int TestOpenArchive_ModifySigned(LPCTSTR szPlainName, LPCTSTR szOriginalName) +static DWORD TestOpenArchive_ModifySigned(LPCTSTR szPlainName, LPCTSTR szOriginalName) { TLogHelper Logger("ModifySignedTest", szPlainName); HANDLE hMpq = NULL; int nVerifyError; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // We need original name for the signature check - nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szOriginalName, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, szPlainName, szOriginalName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Verify the weak signature Logger.PrintProgress("Verifying archive signature ..."); @@ -2914,20 +2913,20 @@ static int TestOpenArchive_ModifySigned(LPCTSTR szPlainName, LPCTSTR szOriginalN if(nVerifyError != ERROR_WEAK_SIGNATURE_OK) { Logger.PrintMessage("Weak signature verification error"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Add a file and verify the signature again - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Verify any of the present signatures Logger.PrintProgress("Modifying signed archive ..."); - nError = AddFileToMpq(&Logger, hMpq, "AddedFile01.txt", "This is a file added to signed MPQ", 0, 0, ERROR_SUCCESS); + dwErrCode = AddFileToMpq(&Logger, hMpq, "AddedFile01.txt", "This is a file added to signed MPQ", 0, 0, ERROR_SUCCESS); } // Verify the signature again - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Verify the weak signature Logger.PrintProgress("Verifying archive signature ..."); @@ -2937,26 +2936,26 @@ static int TestOpenArchive_ModifySigned(LPCTSTR szPlainName, LPCTSTR szOriginalN if(nVerifyError != ERROR_WEAK_SIGNATURE_OK) { Logger.PrintMessage("Weak signature verification error"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Close the MPQ if(hMpq != NULL) SFileCloseArchive(hMpq); - return nError; + return dwErrCode; } -static int TestOpenArchive_SignExisting(LPCTSTR szPlainName) +static DWORD TestOpenArchive_SignExisting(LPCTSTR szPlainName) { TLogHelper Logger("SignExistingMpq", szPlainName); HANDLE hMpq = NULL; int nVerifyError; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // We need original name for the signature check - nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szPlainName, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, szPlainName, szPlainName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Verify the weak signature Logger.PrintProgress("Verifying archive signature ..."); @@ -2966,24 +2965,24 @@ static int TestOpenArchive_SignExisting(LPCTSTR szPlainName) if(nVerifyError != ERROR_NO_SIGNATURE) { Logger.PrintMessage("There already is a signature in the MPQ"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Add a file and verify the signature again - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Verify any of the present signatures Logger.PrintProgress("Signing the MPQ ..."); if(!SFileSignArchive(hMpq, SIGNATURE_TYPE_WEAK)) { Logger.PrintMessage("Failed to create archive signature"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Verify the signature again - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Verify the weak signature Logger.PrintProgress("Verifying archive signature ..."); @@ -2993,14 +2992,14 @@ static int TestOpenArchive_SignExisting(LPCTSTR szPlainName) if(nVerifyError != ERROR_WEAK_SIGNATURE_OK) { Logger.PrintMessage("Weak signature verification error"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Close the MPQ if(hMpq != NULL) SFileCloseArchive(hMpq); - return nError; + return dwErrCode; } static DWORD TestOpenArchive_CompactArchive(LPCTSTR szPlainName, LPCTSTR szCopyName, bool bAddUserData) @@ -3083,14 +3082,14 @@ static DWORD TestOpenArchive_CompactArchive(LPCTSTR szPlainName, LPCTSTR szCopyN return dwErrCode; } -static int ForEachFile_VerifyFileChecksum(LPCTSTR szFullPath) +static DWORD ForEachFile_VerifyFileChecksum(LPCTSTR szFullPath) { TFileData * pFileData; TCHAR * szExtension; TCHAR szShaFileName[MAX_PATH+1]; TCHAR szSha1Text[0x40]; char szSha1TextA[0x40]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Try to load the file with the SHA extension StringCopy(szShaFileName, _countof(szShaFileName), szFullPath); @@ -3110,8 +3109,8 @@ static int ForEachFile_VerifyFileChecksum(LPCTSTR szFullPath) TLogHelper Logger("VerifyFileHash"); // Calculate SHA1 of the entire file - nError = CalculateFileSha1(&Logger, szFullPath, szSha1Text); - if(nError == ERROR_SUCCESS) + dwErrCode = CalculateFileSha1(&Logger, szFullPath, szSha1Text); + if(dwErrCode == ERROR_SUCCESS) { // Compare with what we loaded from the file if(pFileData->dwFileSize >= (SHA1_DIGEST_SIZE * 2)) @@ -3120,7 +3119,7 @@ static int ForEachFile_VerifyFileChecksum(LPCTSTR szFullPath) StringCopy(szSha1TextA, _countof(szSha1TextA), szSha1Text); if(_strnicmp(szSha1TextA, (char *)pFileData->FileData, (SHA1_DIGEST_SIZE * 2))) { - SetLastError(nError = ERROR_FILE_CORRUPT); + SetLastError(dwErrCode = ERROR_FILE_CORRUPT); Logger.PrintError(_T("File CRC check failed: %s"), szFullPath); } } @@ -3129,15 +3128,15 @@ static int ForEachFile_VerifyFileChecksum(LPCTSTR szFullPath) STORM_FREE(pFileData); } - return nError; + return dwErrCode; } // Opens a found archive -static int ForEachFile_OpenArchive(LPCTSTR szFullPath) +static DWORD ForEachFile_OpenArchive(LPCTSTR szFullPath) { HANDLE hMpq = NULL; DWORD dwFileCount = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Check if it's a MPQ file type if(IsMpqExtension(szFullPath)) @@ -3145,14 +3144,14 @@ static int ForEachFile_OpenArchive(LPCTSTR szFullPath) TLogHelper Logger("OpenEachMpqTest", GetShortPlainName(szFullPath)); // Open the MPQ name - nError = OpenExistingArchive(&Logger, szFullPath, 0, &hMpq); - if(nError == ERROR_AVI_FILE || nError == ERROR_FILE_CORRUPT || nError == ERROR_BAD_FORMAT) + dwErrCode = OpenExistingArchive(&Logger, szFullPath, 0, &hMpq); + if(dwErrCode == ERROR_AVI_FILE || dwErrCode == ERROR_FILE_CORRUPT || dwErrCode == ERROR_BAD_FORMAT) return ERROR_SUCCESS; // Search the archive and load every file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = SearchArchive(&Logger, hMpq, 0, &dwFileCount); + dwErrCode = SearchArchive(&Logger, hMpq, 0, &dwFileCount); SFileCloseArchive(hMpq); } @@ -3164,36 +3163,36 @@ static int ForEachFile_OpenArchive(LPCTSTR szFullPath) } // Correct some errors - if(nError == ERROR_FILE_CORRUPT || nError == ERROR_FILE_INCOMPLETE) + if(dwErrCode == ERROR_FILE_CORRUPT || dwErrCode == ERROR_FILE_INCOMPLETE) return ERROR_SUCCESS; - return nError; + return dwErrCode; } // Adding a file to MPQ that had size of the file table equal // or greater than hash table, but has free entries -static int TestAddFile_FullTable(LPCTSTR szFullMpqName) +static DWORD TestAddFile_FullTable(LPCTSTR szFullMpqName) { TLogHelper Logger("FullMpqTest", szFullMpqName); LPCSTR szFileName = "AddedFile001.txt"; LPCSTR szFileData = "0123456789ABCDEF"; HANDLE hMpq = NULL; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Copy the archive so we won't fuck up the original one - nError = OpenExistingArchiveWithCopy(&Logger, szFullMpqName, szFullMpqName, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, szFullMpqName, szFullMpqName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Attempt to add a file - nError = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, MPQ_FILE_IMPLODE, MPQ_COMPRESSION_PKWARE, ERROR_SUCCESS); + dwErrCode = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, MPQ_FILE_IMPLODE, MPQ_COMPRESSION_PKWARE, ERROR_SUCCESS); SFileCloseArchive(hMpq); } - return nError; + return dwErrCode; } // Adding a file to MPQ that had no (listfile) and no (attributes). // We expect that neither of these will be present after the archive is closed -static int TestAddFile_ListFileTest(LPCTSTR szSourceMpq, bool bShouldHaveListFile, bool bShouldHaveAttributes) +static DWORD TestAddFile_ListFileTest(LPCTSTR szSourceMpq, bool bShouldHaveListFile, bool bShouldHaveAttributes) { TLogHelper Logger("ListFileTest", szSourceMpq); TFileData * pFileData = NULL; @@ -3202,27 +3201,27 @@ static int TestAddFile_ListFileTest(LPCTSTR szSourceMpq, bool bShouldHaveListFil LPCSTR szFileData = "0123456789ABCDEF"; HANDLE hMpq = NULL; DWORD dwFileSize = (DWORD)strlen(szFileData); - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Copy the archive so we won't fuck up the original one - nError = OpenExistingArchiveWithCopy(&Logger, szSourceMpq, szBackupMpq, &hMpq); + dwErrCode = OpenExistingArchiveWithCopy(&Logger, szSourceMpq, szBackupMpq, &hMpq); // Add a file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Now add a file - nError = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, MPQ_FILE_IMPLODE, MPQ_COMPRESSION_PKWARE); + dwErrCode = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, MPQ_FILE_IMPLODE, MPQ_COMPRESSION_PKWARE); SFileCloseArchive(hMpq); hMpq = NULL; } // Now reopen the archive - if(nError == ERROR_SUCCESS) - nError = OpenExistingArchiveWithCopy(&Logger, NULL, szBackupMpq, &hMpq); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, NULL, szBackupMpq, &hMpq); // Now the file has been written and the MPQ has been saved. // We Reopen the MPQ and check if there is no (listfile) nor (attributes). - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Verify presence of (listfile) and (attributes) CheckIfFileIsPresent(&Logger, hMpq, LISTFILE_NAME, bShouldHaveListFile); @@ -3239,13 +3238,13 @@ static int TestAddFile_ListFileTest(LPCTSTR szSourceMpq, bool bShouldHaveListFil if(memcmp(pFileData->FileData, szFileData, dwFileSize)) { Logger.PrintError("The data of the added file does not match"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } else { Logger.PrintError("The size of the added file does not match"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } // Delete the file data @@ -3253,17 +3252,17 @@ static int TestAddFile_ListFileTest(LPCTSTR szSourceMpq, bool bShouldHaveListFil } else { - nError = Logger.PrintError("Failed to open the file previously added"); + dwErrCode = Logger.PrintError("Failed to open the file previously added"); } } // Close the MPQ archive if(hMpq != NULL) SFileCloseArchive(hMpq); - return nError; + return dwErrCode; } /* -static int TestCreateArchive_Deprotect(LPCSTR szPlainName) +static DWORD TestCreateArchive_Deprotect(LPCSTR szPlainName) { TLogHelper Logger("DeprotectTest", szPlainName); HANDLE hMpq1 = NULL; @@ -3275,49 +3274,49 @@ static int TestCreateArchive_Deprotect(LPCSTR szPlainName) DWORD dwFileCount1 = 0; DWORD dwFileCount2 = 0; DWORD dwTestFlags = SEARCH_FLAG_LOAD_FILES | SEARCH_FLAG_HASH_FILES; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // First copy: The original (untouched) file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { AddStringBeforeExtension(szMpqName1, szPlainName, "_original"); - nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szMpqName1, &hMpq1); - if(nError != ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, szPlainName, szMpqName1, &hMpq1); + if(dwErrCode != ERROR_SUCCESS) Logger.PrintMessage("Open failed: %s", szMpqName1); } // Second copy: Will be deprotected - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { AddStringBeforeExtension(szMpqName2, szPlainName, "_deprotected"); - nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szMpqName2, &hMpq2); - if(nError != ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, szPlainName, szMpqName2, &hMpq2); + if(dwErrCode != ERROR_SUCCESS) Logger.PrintMessage("Open failed: %s", szMpqName2); } // Deprotect the second map - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { SFileSetCompactCallback(hMpq2, CompactCallback, &Logger); if(!SFileCompactArchive(hMpq2, NULL, false)) - nError = Logger.PrintError("Failed to deprotect archive %s", szMpqName2); + dwErrCode = Logger.PrintError("Failed to deprotect archive %s", szMpqName2); } // Calculate number of files and compare their hash (archive 1) - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { memset(FileHash1, 0, sizeof(FileHash1)); - nError = SearchArchive(&Logger, hMpq1, dwTestFlags, &dwFileCount1, FileHash1); + dwErrCode = SearchArchive(&Logger, hMpq1, dwTestFlags, &dwFileCount1, FileHash1); } // Calculate number of files and compare their hash (archive 2) - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { memset(FileHash1, 0, sizeof(FileHash2)); - nError = SearchArchive(&Logger, hMpq2, dwTestFlags, &dwFileCount2, FileHash2); + dwErrCode = SearchArchive(&Logger, hMpq2, dwTestFlags, &dwFileCount2, FileHash2); } - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(dwFileCount1 != dwFileCount2) Logger.PrintMessage("Different file count (%u in %s; %u in %s)", dwFileCount1, szMpqName1, dwFileCount2, szMpqName2); @@ -3330,30 +3329,30 @@ static int TestCreateArchive_Deprotect(LPCSTR szPlainName) SFileCloseArchive(hMpq2); if(hMpq1 != NULL) SFileCloseArchive(hMpq1); - return nError; + return dwErrCode; } */ -static int TestCreateArchive_EmptyMpq(LPCTSTR szPlainName, DWORD dwCreateFlags) +static DWORD TestCreateArchive_EmptyMpq(LPCTSTR szPlainName, DWORD dwCreateFlags) { TLogHelper Logger("CreateEmptyMpq", szPlainName); HANDLE hMpq = NULL; DWORD dwFileCount = 0; - int nError; + DWORD dwErrCode; // Create the full path name - nError = CreateNewArchive(&Logger, szPlainName, dwCreateFlags, 0, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = CreateNewArchive(&Logger, szPlainName, dwCreateFlags, 0, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { SearchArchive(&Logger, hMpq); SFileCloseArchive(hMpq); } // Reopen the empty MPQ - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { SFileGetFileInfo(hMpq, SFileMpqNumberOfFiles, &dwFileCount, sizeof(dwFileCount), NULL); @@ -3364,10 +3363,10 @@ static int TestCreateArchive_EmptyMpq(LPCTSTR szPlainName, DWORD dwCreateFlags) } } - return nError; + return dwErrCode; } -static int TestCreateArchive_TestGaps(LPCTSTR szPlainName) +static DWORD TestCreateArchive_TestGaps(LPCTSTR szPlainName) { TLogHelper Logger("CreateGapsTest", szPlainName); ULONGLONG ByteOffset1 = 0xFFFFFFFF; @@ -3375,25 +3374,25 @@ static int TestCreateArchive_TestGaps(LPCTSTR szPlainName) HANDLE hMpq = NULL; HANDLE hFile = NULL; TCHAR szFullPath[MAX_PATH]; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Create new MPQ - nError = CreateNewArchive_V2(&Logger, szPlainName, MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_FORMAT_VERSION_4, 4000, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = CreateNewArchive_V2(&Logger, szPlainName, MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_FORMAT_VERSION_4, 4000, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Add one file and flush the archive - nError = AddFileToMpq(&Logger, hMpq, "AddedFile01.txt", "This is the file data.", MPQ_FILE_COMPRESS); + dwErrCode = AddFileToMpq(&Logger, hMpq, "AddedFile01.txt", "This is the file data.", MPQ_FILE_COMPRESS); SFileCloseArchive(hMpq); hMpq = NULL; } // Reopen the MPQ and add another file. // The new file must be added to the position of the (listfile) - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { CreateFullPathName(szFullPath, _countof(szFullPath), NULL, szPlainName); - nError = OpenExistingArchive(&Logger, szFullPath, 0, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = OpenExistingArchive(&Logger, szFullPath, 0, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Retrieve the position of the (listfile) if(SFileOpenFileEx(hMpq, LISTFILE_NAME, 0, &hFile)) @@ -3402,17 +3401,17 @@ static int TestCreateArchive_TestGaps(LPCTSTR szPlainName) SFileCloseFile(hFile); } else - nError = GetLastError(); + dwErrCode = GetLastError(); } } // Add another file and check its position. It must be at the position of the former listfile - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { LPCSTR szAddedFile = "AddedFile02.txt"; // Add another file - nError = AddFileToMpq(&Logger, hMpq, szAddedFile, "This is the second added file.", MPQ_FILE_COMPRESS); + dwErrCode = AddFileToMpq(&Logger, hMpq, szAddedFile, "This is the second added file.", MPQ_FILE_COMPRESS); // Retrieve the position of the (listfile) if(SFileOpenFileEx(hMpq, szAddedFile, 0, &hFile)) @@ -3421,34 +3420,34 @@ static int TestCreateArchive_TestGaps(LPCTSTR szPlainName) SFileCloseFile(hFile); } else - nError = GetLastError(); + dwErrCode = GetLastError(); } // Now check the positions - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(ByteOffset1 != ByteOffset2) { Logger.PrintError("The added file was not written to the position of (listfile)"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Close the archive if needed if(hMpq != NULL) SFileCloseArchive(hMpq); - return nError; + return dwErrCode; } -static int TestCreateArchive_NonStdNames(LPCTSTR szPlainName) +static DWORD TestCreateArchive_NonStdNames(LPCTSTR szPlainName) { TLogHelper Logger("NonStdNamesTest", szPlainName); HANDLE hMpq = NULL; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Create new MPQ - nError = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_FORMAT_VERSION_1, 4000, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_FORMAT_VERSION_1, 4000, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Add few files and close the archive AddFileToMpq(&Logger, hMpq, "AddedFile000.txt", "This is the file data 000.", MPQ_FILE_COMPRESS); @@ -3479,37 +3478,37 @@ static int TestCreateArchive_NonStdNames(LPCTSTR szPlainName) return ERROR_SUCCESS; } -static int TestCreateArchive_Signed(LPCTSTR szPlainName, bool bSignAtCreate) +static DWORD TestCreateArchive_Signed(LPCTSTR szPlainName, bool bSignAtCreate) { TLogHelper Logger("CreateSignedMpq", szPlainName); HANDLE hMpq = NULL; DWORD dwCreateFlags = MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_FORMAT_VERSION_1; DWORD dwSignatures = 0; DWORD nVerifyError = 0; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Method 1: Create the archive as signed if(bSignAtCreate) dwCreateFlags |= MPQ_CREATE_SIGNATURE; // Create new MPQ - nError = CreateNewArchive_V2(&Logger, szPlainName, dwCreateFlags, 4000, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = CreateNewArchive_V2(&Logger, szPlainName, dwCreateFlags, 4000, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Add one file and flush the archive - nError = AddFileToMpq(&Logger, hMpq, "AddedFile01.txt", "This is the file data.", MPQ_FILE_COMPRESS); + dwErrCode = AddFileToMpq(&Logger, hMpq, "AddedFile01.txt", "This is the file data.", MPQ_FILE_COMPRESS); } // Sign the archive with weak signature - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { if(!SFileSignArchive(hMpq, SIGNATURE_TYPE_WEAK)) - nError = ERROR_SUCCESS; + dwErrCode = ERROR_SUCCESS; } // Reopen the MPQ and add another file. // The new file must be added to the position of the (listfile) - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { // Query the signature types Logger.PrintProgress("Retrieving signatures ..."); @@ -3523,31 +3522,31 @@ static int TestCreateArchive_Signed(LPCTSTR szPlainName, bool bSignAtCreate) if((dwSignatures != SIGNATURE_TYPE_WEAK) && (nVerifyError != ERROR_WEAK_SIGNATURE_OK)) { Logger.PrintMessage("Weak signature verification error"); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } // Close the archive if(hMpq != NULL) SFileCloseArchive(hMpq); - return nError; + return dwErrCode; } -static int TestCreateArchive_MpqEditor(LPCTSTR szPlainName, LPCSTR szFileName) +static DWORD TestCreateArchive_MpqEditor(LPCTSTR szPlainName, LPCSTR szFileName) { TLogHelper Logger("CreateMpqEditor", szPlainName); HANDLE hMpq = NULL; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; // Create new MPQ - nError = CreateNewArchive_V2(&Logger, szPlainName, MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, 4000, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = CreateNewArchive_V2(&Logger, szPlainName, MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, 4000, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Flush the archive first SFileFlushArchive(hMpq); // Add one file - nError = AddFileToMpq(&Logger, hMpq, szFileName, "This is the file data.", MPQ_FILE_COMPRESS); + dwErrCode = AddFileToMpq(&Logger, hMpq, szFileName, "This is the file data.", MPQ_FILE_COMPRESS); // Flush the archive again SFileFlushArchive(hMpq); @@ -3555,13 +3554,13 @@ static int TestCreateArchive_MpqEditor(LPCTSTR szPlainName, LPCSTR szFileName) } else { - nError = GetLastError(); + dwErrCode = GetLastError(); } - return nError; + return dwErrCode; } -static int TestCreateArchive_FillArchive(LPCTSTR szPlainName, DWORD dwCreateFlags) +static DWORD TestCreateArchive_FillArchive(LPCTSTR szPlainName, DWORD dwCreateFlags) { TLogHelper Logger("CreateFullMpq", szPlainName); LPCSTR szFileData = "TestCreateArchive_FillArchive: Testing file data"; @@ -3570,7 +3569,7 @@ static int TestCreateArchive_FillArchive(LPCTSTR szPlainName, DWORD dwCreateFlag DWORD dwMaxFileCount = 6; DWORD dwCompression = MPQ_COMPRESSION_ZLIB; DWORD dwFlags = MPQ_FILE_ENCRYPTED | MPQ_FILE_COMPRESS; - int nError; + DWORD dwErrCode; // // Note that StormLib will round the maxfile count @@ -3582,8 +3581,8 @@ static int TestCreateArchive_FillArchive(LPCTSTR szPlainName, DWORD dwCreateFlag dwMaxFileCount++; // Create the new MPQ archive - nError = CreateNewArchive_V2(&Logger, szPlainName, dwCreateFlags, dwMaxFileCount, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = CreateNewArchive_V2(&Logger, szPlainName, dwCreateFlags, dwMaxFileCount, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { // Flush the archive first SFileFlushArchive(hMpq); @@ -3592,8 +3591,8 @@ static int TestCreateArchive_FillArchive(LPCTSTR szPlainName, DWORD dwCreateFlag for(unsigned int i = 0; i < dwMaxFileCount; i++) { sprintf(szFileName, "AddedFile%03u.txt", i); - nError = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, dwFlags, dwCompression); - if(nError != ERROR_SUCCESS) + dwErrCode = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, dwFlags, dwCompression); + if(dwErrCode != ERROR_SUCCESS) break; } @@ -3602,11 +3601,11 @@ static int TestCreateArchive_FillArchive(LPCTSTR szPlainName, DWORD dwCreateFlag } // Now the MPQ should be full. It must not be possible to add another file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = AddFileToMpq(&Logger, hMpq, "ShouldNotBeHere.txt", szFileData, MPQ_FILE_COMPRESS, MPQ_COMPRESSION_ZLIB, ERROR_DISK_FULL); - assert(nError != ERROR_SUCCESS); - nError = ERROR_SUCCESS; + dwErrCode = AddFileToMpq(&Logger, hMpq, "ShouldNotBeHere.txt", szFileData, MPQ_FILE_COMPRESS, MPQ_COMPRESSION_ZLIB, ERROR_DISK_FULL); + assert(dwErrCode != ERROR_SUCCESS); + dwErrCode = ERROR_SUCCESS; } // Close the archive to enforce saving all tables @@ -3615,48 +3614,48 @@ static int TestCreateArchive_FillArchive(LPCTSTR szPlainName, DWORD dwCreateFlag hMpq = NULL; // Reopen the archive again - if(nError == ERROR_SUCCESS) - nError = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); // The archive should still be full - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { CheckIfFileIsPresent(&Logger, hMpq, LISTFILE_NAME, (dwCreateFlags & MPQ_CREATE_LISTFILE) ? true : false); CheckIfFileIsPresent(&Logger, hMpq, ATTRIBUTES_NAME, (dwCreateFlags & MPQ_CREATE_ATTRIBUTES) ? true : false); - nError = AddFileToMpq(&Logger, hMpq, "ShouldNotBeHere.txt", szFileData, MPQ_FILE_COMPRESS, MPQ_COMPRESSION_ZLIB, ERROR_DISK_FULL); - assert(nError != ERROR_SUCCESS); - nError = ERROR_SUCCESS; + dwErrCode = AddFileToMpq(&Logger, hMpq, "ShouldNotBeHere.txt", szFileData, MPQ_FILE_COMPRESS, MPQ_COMPRESSION_ZLIB, ERROR_DISK_FULL); + assert(dwErrCode != ERROR_SUCCESS); + dwErrCode = ERROR_SUCCESS; } // The (listfile) and (attributes) must be present - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { CheckIfFileIsPresent(&Logger, hMpq, LISTFILE_NAME, (dwCreateFlags & MPQ_CREATE_LISTFILE) ? true : false); CheckIfFileIsPresent(&Logger, hMpq, ATTRIBUTES_NAME, (dwCreateFlags & MPQ_CREATE_ATTRIBUTES) ? true : false); - nError = RemoveMpqFile(&Logger, hMpq, szFileName, ERROR_SUCCESS); + dwErrCode = RemoveMpqFile(&Logger, hMpq, szFileName, ERROR_SUCCESS); } // Now add the file again. This time, it should be possible OK - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, dwFlags, dwCompression, ERROR_SUCCESS); - assert(nError == ERROR_SUCCESS); + dwErrCode = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, dwFlags, dwCompression, ERROR_SUCCESS); + assert(dwErrCode == ERROR_SUCCESS); } // Now add the file again. This time, it should fail - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, dwFlags, dwCompression, ERROR_ALREADY_EXISTS); - assert(nError != ERROR_SUCCESS); - nError = ERROR_SUCCESS; + dwErrCode = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, dwFlags, dwCompression, ERROR_ALREADY_EXISTS); + assert(dwErrCode != ERROR_SUCCESS); + dwErrCode = ERROR_SUCCESS; } // Now add the file again. This time, it should fail - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = AddFileToMpq(&Logger, hMpq, "ShouldNotBeHere.txt", szFileData, dwFlags, dwCompression, ERROR_DISK_FULL); - assert(nError != ERROR_SUCCESS); - nError = ERROR_SUCCESS; + dwErrCode = AddFileToMpq(&Logger, hMpq, "ShouldNotBeHere.txt", szFileData, dwFlags, dwCompression, ERROR_DISK_FULL); + assert(dwErrCode != ERROR_SUCCESS); + dwErrCode = ERROR_SUCCESS; } // Close the archive and return @@ -3665,10 +3664,10 @@ static int TestCreateArchive_FillArchive(LPCTSTR szPlainName, DWORD dwCreateFlag hMpq = NULL; // Reopen the archive for the third time to verify that both internal files are there - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { CheckIfFileIsPresent(&Logger, hMpq, LISTFILE_NAME, (dwCreateFlags & MPQ_CREATE_LISTFILE) ? true : false); CheckIfFileIsPresent(&Logger, hMpq, ATTRIBUTES_NAME, (dwCreateFlags & MPQ_CREATE_ATTRIBUTES) ? true : false); @@ -3676,44 +3675,44 @@ static int TestCreateArchive_FillArchive(LPCTSTR szPlainName, DWORD dwCreateFlag } } - return nError; + return dwErrCode; } -static int TestCreateArchive_IncMaxFileCount(LPCTSTR szPlainName) +static DWORD TestCreateArchive_IncMaxFileCount(LPCTSTR szPlainName) { TLogHelper Logger("IncMaxFileCount", szPlainName); LPCSTR szFileData = "TestCreateArchive_IncMaxFileCount: Testing file data"; char szFileName[MAX_PATH]; HANDLE hMpq = NULL; DWORD dwMaxFileCount = 1; - int nError; + DWORD dwErrCode; // Create the new MPQ - nError = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_ARCHIVE_V4 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, dwMaxFileCount, &hMpq); + dwErrCode = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_ARCHIVE_V4 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, dwMaxFileCount, &hMpq); // Now add exactly one file - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = AddFileToMpq(&Logger, hMpq, "AddFile_base.txt", szFileData); + dwErrCode = AddFileToMpq(&Logger, hMpq, "AddFile_base.txt", szFileData); SFileFlushArchive(hMpq); SFileCloseArchive(hMpq); } // Now add 10 files. Each time we cannot add the file due to archive being full, // we increment the max file count - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { for(unsigned int i = 0; i < 10; i++) { // Open the archive again - nError = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); - if(nError != ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); + if(dwErrCode != ERROR_SUCCESS) break; // Add one file sprintf(szFileName, "AddFile_%04u.txt", i); - nError = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, 0, 0, ERROR_UNDETERMINED_RESULT); - if(nError != ERROR_SUCCESS) + dwErrCode = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, 0, 0, ERROR_UNDETERMINED_RESULT); + if(dwErrCode != ERROR_SUCCESS) { // Increment the max file count by one dwMaxFileCount = SFileGetMaxFileCount(hMpq) + 1; @@ -3721,52 +3720,52 @@ static int TestCreateArchive_IncMaxFileCount(LPCTSTR szPlainName) SFileSetMaxFileCount(hMpq, dwMaxFileCount); // Attempt to create the file again - nError = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, 0, 0, ERROR_SUCCESS); + dwErrCode = AddFileToMpq(&Logger, hMpq, szFileName, szFileData, 0, 0, ERROR_SUCCESS); } // Compact the archive and close it SFileSetCompactCallback(hMpq, CompactCallback, &Logger); SFileCompactArchive(hMpq, NULL, false); SFileCloseArchive(hMpq); - if(nError != ERROR_SUCCESS) + if(dwErrCode != ERROR_SUCCESS) break; } } - return nError; + return dwErrCode; } -static int TestCreateArchive_UnicodeNames() +static DWORD TestCreateArchive_UnicodeNames() { TLogHelper Logger("MpqUnicodeName"); DWORD dwCreateFlags = MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES; - int nError = ERROR_SUCCESS; + DWORD dwErrCode = ERROR_SUCCESS; - nError = CreateNewArchiveU(&Logger, szUnicodeName1, dwCreateFlags | MPQ_CREATE_ARCHIVE_V1, 15); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = CreateNewArchiveU(&Logger, szUnicodeName1, dwCreateFlags | MPQ_CREATE_ARCHIVE_V1, 15); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; - nError = CreateNewArchiveU(&Logger, szUnicodeName2, dwCreateFlags | MPQ_CREATE_ARCHIVE_V2, 58); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = CreateNewArchiveU(&Logger, szUnicodeName2, dwCreateFlags | MPQ_CREATE_ARCHIVE_V2, 58); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; - nError = CreateNewArchiveU(&Logger, szUnicodeName3, dwCreateFlags | MPQ_CREATE_ARCHIVE_V3, 15874); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = CreateNewArchiveU(&Logger, szUnicodeName3, dwCreateFlags | MPQ_CREATE_ARCHIVE_V3, 15874); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; - nError = CreateNewArchiveU(&Logger, szUnicodeName4, dwCreateFlags | MPQ_CREATE_ARCHIVE_V4, 87541); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = CreateNewArchiveU(&Logger, szUnicodeName4, dwCreateFlags | MPQ_CREATE_ARCHIVE_V4, 87541); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; - nError = CreateNewArchiveU(&Logger, szUnicodeName5, dwCreateFlags | MPQ_CREATE_ARCHIVE_V3, 87541); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = CreateNewArchiveU(&Logger, szUnicodeName5, dwCreateFlags | MPQ_CREATE_ARCHIVE_V3, 87541); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; - nError = CreateNewArchiveU(&Logger, szUnicodeName5, dwCreateFlags | MPQ_CREATE_ARCHIVE_V2, 87541); - if(nError != ERROR_SUCCESS) - return nError; + dwErrCode = CreateNewArchiveU(&Logger, szUnicodeName5, dwCreateFlags | MPQ_CREATE_ARCHIVE_V2, 87541); + if(dwErrCode != ERROR_SUCCESS) + return dwErrCode; - return nError; + return dwErrCode; } static DWORD TestCreateArchive_FileFlagTest(LPCTSTR szPlainName) @@ -3926,7 +3925,7 @@ static DWORD TestCreateArchive_FileFlagTest(LPCTSTR szPlainName) return dwErrCode; } -static int TestCreateArchive_WaveCompressionsTest(LPCTSTR szPlainName, LPCTSTR szWaveFile) +static DWORD TestCreateArchive_WaveCompressionsTest(LPCTSTR szPlainName, LPCTSTR szWaveFile) { TLogHelper Logger("CompressionsTest", szPlainName); HANDLE hMpq = NULL; // Handle of created archive @@ -3935,23 +3934,23 @@ static int TestCreateArchive_WaveCompressionsTest(LPCTSTR szPlainName, LPCTSTR s DWORD dwCmprCount = sizeof(WaveCompressions) / sizeof(DWORD); DWORD dwAddedFiles = 0; DWORD dwFoundFiles = 0; - int nError; + DWORD dwErrCode; // Create paths for local file to be added CreateFullPathName(szFileName, _countof(szFileName), szMpqSubDir, szWaveFile); // Create new archive - nError = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_ARCHIVE_V1 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, 0x40, &hMpq); + dwErrCode = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_ARCHIVE_V1 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, 0x40, &hMpq); // Add the same file multiple times - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { Logger.UserTotal = dwCmprCount; for(unsigned int i = 0; i < dwCmprCount; i++) { sprintf(szArchivedName, "WaveFile_%02u.wav", i + 1); - nError = AddLocalFileToMpq(&Logger, hMpq, szArchivedName, szFileName, MPQ_FILE_COMPRESS | MPQ_FILE_ENCRYPTED | MPQ_FILE_SECTOR_CRC, WaveCompressions[i]); - if(nError != ERROR_SUCCESS) + dwErrCode = AddLocalFileToMpq(&Logger, hMpq, szArchivedName, szFileName, MPQ_FILE_COMPRESS | MPQ_FILE_ENCRYPTED | MPQ_FILE_SECTOR_CRC, WaveCompressions[i]); + if(dwErrCode != ERROR_SUCCESS) break; Logger.UserCount++; @@ -3962,10 +3961,10 @@ static int TestCreateArchive_WaveCompressionsTest(LPCTSTR szPlainName, LPCTSTR s } // Reopen the archive extract each WAVE file and try to play it - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { - nError = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { SearchArchive(&Logger, hMpq, SEARCH_FLAG_LOAD_FILES | SEARCH_FLAG_PLAY_WAVES, &dwFoundFiles, NULL); SFileCloseArchive(hMpq); @@ -3976,14 +3975,14 @@ static int TestCreateArchive_WaveCompressionsTest(LPCTSTR szPlainName, LPCTSTR s if(dwFoundFiles != (dwAddedFiles + 2)) { Logger.PrintError("Number of found files does not match number of added files."); - nError = ERROR_FILE_CORRUPT; + dwErrCode = ERROR_FILE_CORRUPT; } } - return nError; + return dwErrCode; } -static int TestCreateArchive_ListFilePos(LPCTSTR szPlainName) +static DWORD TestCreateArchive_ListFilePos(LPCTSTR szPlainName) { TFileData * pFileData; LPCSTR szReaddedFile = "AddedFile_##.txt"; @@ -3994,19 +3993,19 @@ static int TestCreateArchive_ListFilePos(LPCTSTR szPlainName) DWORD dwMaxFileCount = 0x0E; DWORD dwFileCount = 0; size_t i; - int nError; + DWORD dwErrCode; // Create a new archive with the limit of 0x20 files - nError = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_ARCHIVE_V4 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, dwMaxFileCount, &hMpq); + dwErrCode = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_ARCHIVE_V4 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, dwMaxFileCount, &hMpq); // Add maximum files files - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { for(i = 0; i < dwMaxFileCount; i++) { sprintf(szArchivedName, szFileMask, i); - nError = AddFileToMpq(&Logger, hMpq, szArchivedName, "This is a text data.", 0, 0, ERROR_SUCCESS); - if(nError != ERROR_SUCCESS) + dwErrCode = AddFileToMpq(&Logger, hMpq, szArchivedName, "This is a text data.", 0, 0, ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) break; dwFileCount++; @@ -4014,13 +4013,13 @@ static int TestCreateArchive_ListFilePos(LPCTSTR szPlainName) } // Delete few middle files - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { for(i = 0; i < (dwMaxFileCount / 2); i++) { sprintf(szArchivedName, szFileMask, i); - nError = RemoveMpqFile(&Logger, hMpq, szArchivedName, ERROR_SUCCESS); - if(nError != ERROR_SUCCESS) + dwErrCode = RemoveMpqFile(&Logger, hMpq, szArchivedName, ERROR_SUCCESS); + if(dwErrCode != ERROR_SUCCESS) break; dwFileCount--; @@ -4033,11 +4032,11 @@ static int TestCreateArchive_ListFilePos(LPCTSTR szPlainName) hMpq = NULL; // Reopen the archive to catch any asserts - if(nError == ERROR_SUCCESS) - nError = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); // Check that (listfile) is at the end - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { pFileData = LoadMpqFile(&Logger, hMpq, LISTFILE_NAME); if(pFileData != NULL) @@ -4056,8 +4055,8 @@ static int TestCreateArchive_ListFilePos(LPCTSTR szPlainName) } // Add new file to the archive. It should be added to the last position - nError = AddFileToMpq(&Logger, hMpq, szReaddedFile, "This is a re-added file.", 0, 0, ERROR_SUCCESS); - if(nError == ERROR_SUCCESS) + dwErrCode = AddFileToMpq(&Logger, hMpq, szReaddedFile, "This is a re-added file.", 0, 0, ERROR_SUCCESS); + if(dwErrCode == ERROR_SUCCESS) { // Force update of the tables SFileFlushArchive(hMpq); @@ -4075,10 +4074,10 @@ static int TestCreateArchive_ListFilePos(LPCTSTR szPlainName) SFileCloseArchive(hMpq); } - return nError; + return dwErrCode; } -static int TestCreateArchive_BigArchive(LPCTSTR szPlainName) +static DWORD TestCreateArchive_BigArchive(LPCTSTR szPlainName) { TLogHelper Logger("BigMpqTest", szPlainName); HANDLE hMpq = NULL; // Handle of created archive @@ -4087,11 +4086,11 @@ static int TestCreateArchive_BigArchive(LPCTSTR szPlainName) DWORD dwMaxFileCount = 0x20; DWORD dwAddedCount = 0; size_t i; - int nError; + DWORD dwErrCode; // Create a new archive with the limit of 0x20 files - nError = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_ARCHIVE_V3 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, dwMaxFileCount, &hMpq); - if(nError == ERROR_SUCCESS) + dwErrCode = CreateNewArchive(&Logger, szPlainName, MPQ_CREATE_ARCHIVE_V3 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, dwMaxFileCount, &hMpq); + if(dwErrCode == ERROR_SUCCESS) { LPCSTR szFileMask = "AddedFile_%02u.txt"; @@ -4102,8 +4101,8 @@ static int TestCreateArchive_BigArchive(LPCTSTR szPlainName) for(i = 0; i < dwMaxFileCount / 2; i++) { sprintf(szArchivedName, szFileMask, i + 1); - nError = AddLocalFileToMpq(&Logger, hMpq, szArchivedName, szLocalFileName, 0, 0, true); - if(nError != ERROR_SUCCESS) + dwErrCode = AddLocalFileToMpq(&Logger, hMpq, szArchivedName, szLocalFileName, 0, 0, true); + if(dwErrCode != ERROR_SUCCESS) break; Logger.UserCount++; @@ -4117,11 +4116,11 @@ static int TestCreateArchive_BigArchive(LPCTSTR szPlainName) hMpq = NULL; // Reopen the archive to catch any asserts - if(nError == ERROR_SUCCESS) - nError = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); + if(dwErrCode == ERROR_SUCCESS) + dwErrCode = OpenExistingArchiveWithCopy(&Logger, NULL, szPlainName, &hMpq); // Check that (listfile) is at the end - if(nError == ERROR_SUCCESS) + if(dwErrCode == ERROR_SUCCESS) { CheckIfFileIsPresent(&Logger, hMpq, LISTFILE_NAME, true); CheckIfFileIsPresent(&Logger, hMpq, ATTRIBUTES_NAME, true); @@ -4129,7 +4128,7 @@ static int TestCreateArchive_BigArchive(LPCTSTR szPlainName) SFileCloseArchive(hMpq); } - return nError; + return dwErrCode; } // "MPQ_2014_v4_Heroes_Replay.MPQ", "AddFile-replay.message.events" @@ -4286,13 +4285,13 @@ int _tmain(int argc, TCHAR * argv[]) // // Tests on a local listfile // - + /* if(dwErrCode == ERROR_SUCCESS) { TestOnLocalListFile(_T("FLAT-MAP:ListFile_Blizzard.txt")); dwErrCode = TestOnLocalListFile(_T("ListFile_Blizzard.txt")); } - + */ // // Open all files from the command line // -- cgit v1.2.3