From 4ad0bff21da0163917e1552960e6a43679586b89 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Wed, 13 Jun 2018 15:49:23 +0200 Subject: + When opening a file by special name, the file is first checked whether that file is there. --- StormLib_vs08_test.vcproj | 2 +- src/SFileOpenFileEx.cpp | 35 ++++++++++++++++++----------------- src/StormLib.h | 2 +- test/StormTest.cpp | 9 ++++++--- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/StormLib_vs08_test.vcproj b/StormLib_vs08_test.vcproj index 1cd9596..7e9e485 100644 --- a/StormLib_vs08_test.vcproj +++ b/StormLib_vs08_test.vcproj @@ -27,7 +27,7 @@ OutputDirectory="./bin/$(ProjectName)/$(PlatformName)/$(ConfigurationName)" IntermediateDirectory="./bin/$(ProjectName)/$(PlatformName)/$(ConfigurationName)" ConfigurationType="1" - CharacterSet="2" + CharacterSet="1" > haPatch == NULL || dwSearchScope == SFILE_OPEN_BASE_FILE) { - // Get the file entry for the file - if(dwFileIndex > ha->dwFileTableSize) - break; - pFileEntry = ha->pFileTable + dwFileIndex; + pFileEntry = GetFileEntryLocale2(ha, szFileName, lcFileLocale, &dwHashIndex); } + + // If this MPQ is a patched archive, open the file as patched else { - // If this MPQ has no patches, open the file from this MPQ directly - if(ha->haPatch == NULL || dwSearchScope == SFILE_OPEN_BASE_FILE) - { - pFileEntry = GetFileEntryLocale2(ha, szFileName, lcFileLocale, &dwHashIndex); - } - - // If this MPQ is a patched archive, open the file as patched - else - { - return OpenPatchedFile(hMpq, szFileName, PtrFile); - } + return OpenPatchedFile(hMpq, szFileName, PtrFile); } break; @@ -308,7 +297,19 @@ bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearch if(nError == ERROR_SUCCESS) { if(pFileEntry == NULL || (pFileEntry->dwFlags & MPQ_FILE_EXISTS) == 0) + { + // Check the pseudo-file name + if((bOpenByIndex = IsPseudoFileName(szFileName, &dwFileIndex)) == true) + { + // Get the file entry for the file + if(dwFileIndex < ha->dwFileTableSize) + { + pFileEntry = ha->pFileTable + dwFileIndex; + } + } + nError = ERROR_FILE_NOT_FOUND; + } // Ignore unknown loading flags (example: MPQ_2016_v1_WME4_4.w3x) // if(pFileEntry != NULL && pFileEntry->dwFlags & ~MPQ_FILE_VALID_FLAGS) diff --git a/src/StormLib.h b/src/StormLib.h index a0738d1..b9f60a4 100644 --- a/src/StormLib.h +++ b/src/StormLib.h @@ -1077,7 +1077,7 @@ bool WINAPI SFileCreateFile(HANDLE hMpq, const char * szArchivedName, ULONGLON bool WINAPI SFileWriteFile(HANDLE hFile, const void * pvData, DWORD dwSize, DWORD dwCompression); bool WINAPI SFileFinishFile(HANDLE hFile); -bool WINAPI SFileAddFileEx(HANDLE hMpq, const TCHAR * szFileName, const char * szArchivedName, DWORD dwFlags, DWORD dwCompression, DWORD dwCompressionNext); +bool WINAPI SFileAddFileEx(HANDLE hMpq, const TCHAR * szFileName, const char * szArchivedName, DWORD dwFlags, DWORD dwCompression, DWORD dwCompressionNext = MPQ_COMPRESSION_NEXT_SAME); bool WINAPI SFileAddFile(HANDLE hMpq, const TCHAR * szFileName, const char * szArchivedName, DWORD dwFlags); bool WINAPI SFileAddWave(HANDLE hMpq, const TCHAR * szFileName, const char * szArchivedName, DWORD dwFlags, DWORD dwQuality); bool WINAPI SFileRemoveFile(HANDLE hMpq, const char * szFileName, DWORD dwSearchScope); diff --git a/test/StormTest.cpp b/test/StormTest.cpp index e6ca2cb..f1f6970 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -4406,7 +4406,7 @@ int _tmain(int argc, TCHAR * argv[]) // Not a test, but rather a tool for creating links to duplicated files // if(nError == ERROR_SUCCESS) // nError = FindFilePairs(ForEachFile_CreateArchiveLink, "2004 - WoW\\06080", "2004 - WoW\\06299"); - +/* // Search all testing archives and verify their SHA1 hash if(nError == ERROR_SUCCESS) nError = FindFiles(ForEachFile_VerifyFileChecksum, szMpqSubDir); @@ -4482,7 +4482,10 @@ int _tmain(int argc, TCHAR * argv[]) // Open the update MPQ from Diablo II (patch 2016) if(nError == ERROR_SUCCESS) nError = TestOpenFile_OpenByName(_T("MPQ_2016_v1_D2XP_IX86_1xx_114a.mpq"), "waitingroombkgd.dc6"); - +*/ + if(nError == ERROR_SUCCESS) + nError = TestOpenFile_OpenByName(_T("MPQ_2018_v1_icon_error.w3m"), "file00000002.blp"); +/* // Open a file whose archive's (signature) file has flags = 0x90000000 if(nError == ERROR_SUCCESS) nError = TestOpenArchive(_T("MPQ_1997_v1_Diablo1_STANDARD.SNP"), _T("ListFile_Blizzard.txt")); @@ -4832,7 +4835,7 @@ int _tmain(int argc, TCHAR * argv[]) // Test replacing a file with zero size file if(nError == ERROR_SUCCESS) nError = TestModifyArchive_ReplaceFile(_T("MPQ_2014_v4_Base.StormReplay"), _T("AddFile-replay.message.events")); - +*/ #ifdef _MSC_VER _CrtDumpMemoryLeaks(); #endif // _MSC_VER -- cgit v1.2.3