Skip to content

Commit 4ad0bff

Browse files
author
Ladislav Zezula
committed
+ When opening a file by special name, the file is first checked whether that file is there.
1 parent 7292399 commit 4ad0bff

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

StormLib_vs08_test.vcproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
OutputDirectory="./bin/$(ProjectName)/$(PlatformName)/$(ConfigurationName)"
2828
IntermediateDirectory="./bin/$(ProjectName)/$(PlatformName)/$(ConfigurationName)"
2929
ConfigurationType="1"
30-
CharacterSet="2"
30+
CharacterSet="1"
3131
>
3232
<Tool
3333
Name="VCPreBuildEventTool"

src/SFileOpenFileEx.cpp

+18-17
Original file line numberDiff line numberDiff line change
@@ -259,27 +259,16 @@ bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearch
259259
case SFILE_OPEN_BASE_FILE:
260260
case SFILE_OPEN_CHECK_EXISTS:
261261

262-
// Check the pseudo-file name
263-
if((bOpenByIndex = IsPseudoFileName(szFileName, &dwFileIndex)) == true)
262+
// If this MPQ has no patches, open the file from this MPQ directly
263+
if(ha->haPatch == NULL || dwSearchScope == SFILE_OPEN_BASE_FILE)
264264
{
265-
// Get the file entry for the file
266-
if(dwFileIndex > ha->dwFileTableSize)
267-
break;
268-
pFileEntry = ha->pFileTable + dwFileIndex;
265+
pFileEntry = GetFileEntryLocale2(ha, szFileName, lcFileLocale, &dwHashIndex);
269266
}
267+
268+
// If this MPQ is a patched archive, open the file as patched
270269
else
271270
{
272-
// If this MPQ has no patches, open the file from this MPQ directly
273-
if(ha->haPatch == NULL || dwSearchScope == SFILE_OPEN_BASE_FILE)
274-
{
275-
pFileEntry = GetFileEntryLocale2(ha, szFileName, lcFileLocale, &dwHashIndex);
276-
}
277-
278-
// If this MPQ is a patched archive, open the file as patched
279-
else
280-
{
281-
return OpenPatchedFile(hMpq, szFileName, PtrFile);
282-
}
271+
return OpenPatchedFile(hMpq, szFileName, PtrFile);
283272
}
284273
break;
285274

@@ -308,7 +297,19 @@ bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearch
308297
if(nError == ERROR_SUCCESS)
309298
{
310299
if(pFileEntry == NULL || (pFileEntry->dwFlags & MPQ_FILE_EXISTS) == 0)
300+
{
301+
// Check the pseudo-file name
302+
if((bOpenByIndex = IsPseudoFileName(szFileName, &dwFileIndex)) == true)
303+
{
304+
// Get the file entry for the file
305+
if(dwFileIndex < ha->dwFileTableSize)
306+
{
307+
pFileEntry = ha->pFileTable + dwFileIndex;
308+
}
309+
}
310+
311311
nError = ERROR_FILE_NOT_FOUND;
312+
}
312313

313314
// Ignore unknown loading flags (example: MPQ_2016_v1_WME4_4.w3x)
314315
// if(pFileEntry != NULL && pFileEntry->dwFlags & ~MPQ_FILE_VALID_FLAGS)

src/StormLib.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ bool WINAPI SFileCreateFile(HANDLE hMpq, const char * szArchivedName, ULONGLON
10771077
bool WINAPI SFileWriteFile(HANDLE hFile, const void * pvData, DWORD dwSize, DWORD dwCompression);
10781078
bool WINAPI SFileFinishFile(HANDLE hFile);
10791079

1080-
bool WINAPI SFileAddFileEx(HANDLE hMpq, const TCHAR * szFileName, const char * szArchivedName, DWORD dwFlags, DWORD dwCompression, DWORD dwCompressionNext);
1080+
bool WINAPI SFileAddFileEx(HANDLE hMpq, const TCHAR * szFileName, const char * szArchivedName, DWORD dwFlags, DWORD dwCompression, DWORD dwCompressionNext = MPQ_COMPRESSION_NEXT_SAME);
10811081
bool WINAPI SFileAddFile(HANDLE hMpq, const TCHAR * szFileName, const char * szArchivedName, DWORD dwFlags);
10821082
bool WINAPI SFileAddWave(HANDLE hMpq, const TCHAR * szFileName, const char * szArchivedName, DWORD dwFlags, DWORD dwQuality);
10831083
bool WINAPI SFileRemoveFile(HANDLE hMpq, const char * szFileName, DWORD dwSearchScope);

test/StormTest.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -4406,7 +4406,7 @@ int _tmain(int argc, TCHAR * argv[])
44064406
// Not a test, but rather a tool for creating links to duplicated files
44074407
// if(nError == ERROR_SUCCESS)
44084408
// nError = FindFilePairs(ForEachFile_CreateArchiveLink, "2004 - WoW\\06080", "2004 - WoW\\06299");
4409-
4409+
/*
44104410
// Search all testing archives and verify their SHA1 hash
44114411
if(nError == ERROR_SUCCESS)
44124412
nError = FindFiles(ForEachFile_VerifyFileChecksum, szMpqSubDir);
@@ -4482,7 +4482,10 @@ int _tmain(int argc, TCHAR * argv[])
44824482
// Open the update MPQ from Diablo II (patch 2016)
44834483
if(nError == ERROR_SUCCESS)
44844484
nError = TestOpenFile_OpenByName(_T("MPQ_2016_v1_D2XP_IX86_1xx_114a.mpq"), "waitingroombkgd.dc6");
4485-
4485+
*/
4486+
if(nError == ERROR_SUCCESS)
4487+
nError = TestOpenFile_OpenByName(_T("MPQ_2018_v1_icon_error.w3m"), "file00000002.blp");
4488+
/*
44864489
// Open a file whose archive's (signature) file has flags = 0x90000000
44874490
if(nError == ERROR_SUCCESS)
44884491
nError = TestOpenArchive(_T("MPQ_1997_v1_Diablo1_STANDARD.SNP"), _T("ListFile_Blizzard.txt"));
@@ -4832,7 +4835,7 @@ int _tmain(int argc, TCHAR * argv[])
48324835
// Test replacing a file with zero size file
48334836
if(nError == ERROR_SUCCESS)
48344837
nError = TestModifyArchive_ReplaceFile(_T("MPQ_2014_v4_Base.StormReplay"), _T("AddFile-replay.message.events"));
4835-
4838+
*/
48364839
#ifdef _MSC_VER
48374840
_CrtDumpMemoryLeaks();
48384841
#endif // _MSC_VER

0 commit comments

Comments
 (0)