aboutsummaryrefslogtreecommitdiff
path: root/src/SFileReadFile.cpp
diff options
context:
space:
mode:
authorLadislav Zezula <ladislav.zezula@avg.com>2014-03-14 10:17:34 +0100
committerLadislav Zezula <ladislav.zezula@avg.com>2014-03-14 10:17:34 +0100
commit568f189ea5a850a9259c8c89ba5f28a0630a2ce0 (patch)
tree80f02483aced5969b3bc4e8ed52415d0bfa0d8e9 /src/SFileReadFile.cpp
parentca93a8cb76edb459a94e56a85c45a29a881dfc16 (diff)
+ Improved key detection for archives with large sector sizes
Diffstat (limited to 'src/SFileReadFile.cpp')
-rw-r--r--src/SFileReadFile.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/SFileReadFile.cpp b/src/SFileReadFile.cpp
index 1e1ae56..3d6a2ee 100644
--- a/src/SFileReadFile.cpp
+++ b/src/SFileReadFile.cpp
@@ -125,7 +125,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW
// If we don't know the key, try to detect it by file content
if(hf->dwFileKey == 0)
{
- hf->dwFileKey = DetectFileKeyByContent(pbInSector, dwBytesInThisSector);
+ hf->dwFileKey = DetectFileKeyByContent(pbInSector, dwBytesInThisSector, hf->dwDataSize);
if(hf->dwFileKey == 0)
{
nError = ERROR_UNKNOWN_FILE_KEY;
@@ -565,7 +565,7 @@ static int ReadMpqFilePatchFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos,
int nError = ERROR_SUCCESS;
// Make sure that the patch file is loaded completely
- if(hf->pbFileData == NULL)
+ if(nError == ERROR_SUCCESS && hf->pbFileData == NULL)
{
// Load the original file and store its content to "pbOldData"
hf->pbFileData = STORM_ALLOC(BYTE, hf->pFileEntry->dwFileSize);
@@ -672,6 +672,17 @@ bool WINAPI SFileReadFile(HANDLE hFile, void * pvBuffer, DWORD dwToRead, LPDWORD
return false;
}
+ // 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)
+ {
+ SetLastError(nError);
+ return false;
+ }
+ }
+
// If the file is local file, read the data directly from the stream
if(hf->pStream != NULL)
{