diff options
author | Ladislav Zezula <ladislav.zezula@avast.com> | 2021-05-17 10:04:06 +0200 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avast.com> | 2021-05-17 10:04:06 +0200 |
commit | a3332c7c9bc36f13aace6543ebc719f833882dfc (patch) | |
tree | 6f785736f3b5a61bcf162b15181c5fab92ccf24d /src | |
parent | a7ebfbccb7eb16f4852a7fd3bd6a738ecb7db423 (diff) |
nError -> dwErrCode
Diffstat (limited to 'src')
-rw-r--r-- | src/FileStream.cpp | 22 | ||||
-rw-r--r-- | src/SBaseCommon.cpp | 57 | ||||
-rw-r--r-- | src/SBaseFileTable.cpp | 170 | ||||
-rw-r--r-- | src/SBaseSubTypes.cpp | 18 | ||||
-rw-r--r-- | src/SFileAddFile.cpp | 322 | ||||
-rw-r--r-- | src/SFileAttributes.cpp | 24 | ||||
-rw-r--r-- | src/SFileCompactArchive.cpp | 180 | ||||
-rw-r--r-- | src/SFileCreateArchive.cpp | 38 | ||||
-rw-r--r-- | src/SFileExtractFile.cpp | 28 | ||||
-rw-r--r-- | src/SFileFindFile.cpp | 58 | ||||
-rw-r--r-- | src/SFileGetFileInfo.cpp | 58 | ||||
-rw-r--r-- | src/SFileListFile.cpp | 40 | ||||
-rw-r--r-- | src/SFileOpenArchive.cpp | 98 | ||||
-rw-r--r-- | src/SFileOpenFileEx.cpp | 32 | ||||
-rw-r--r-- | src/SFilePatchArchives.cpp | 82 | ||||
-rw-r--r-- | src/SFileReadFile.cpp | 146 | ||||
-rw-r--r-- | src/SFileVerify.cpp | 36 | ||||
-rw-r--r-- | src/StormCommon.h | 66 | ||||
-rw-r--r-- | src/StormLib.h | 8 |
19 files changed, 743 insertions, 740 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 |