From 0d31856af86ac47801ade118ea93092eab62a101 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Mon, 6 Feb 2023 18:30:15 +0100 Subject: Fixed bug in the LZMA compression --- test/StormTest.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/StormTest.cpp') diff --git a/test/StormTest.cpp b/test/StormTest.cpp index e8a52dc..916eed0 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -4184,6 +4184,33 @@ int _tmain(int argc, TCHAR * argv[]) printf("==== Test Suite for StormLib version %s ====\n", STORMLIB_VERSION_STRING); dwErrCode = InitializeMpqDirectory(argv, argc); +/* + // Check creation of the MPQ with LZMA compression + LPCTSTR szArchiveName = _T("E:\\new-mpq.mpq"); + HANDLE hFile = NULL; + HANDLE hMpq = NULL; + + DeleteFile(szArchiveName); + if(SFileCreateArchive(szArchiveName, MPQ_CREATE_ARCHIVE_V2 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, 0x1000, &hMpq)) + { + SFileAddFileEx(hMpq, _T("e:\\DlgSetFileAssoc.cpp"), "DlgSetFileAssoc.cpp", MPQ_FILE_SINGLE_UNIT | MPQ_FILE_COMPRESS, MPQ_COMPRESSION_LZMA, MPQ_COMPRESSION_NEXT_SAME); + SFileCloseArchive(hMpq); + + if(SFileOpenArchive(szArchiveName, 0, 0, &hMpq)) + { + if(SFileOpenFileEx(hMpq, "DlgSetFileAssoc.cpp", 0, &hFile)) + { + DWORD dwBytesRead = 0; + BYTE Buffer[0x100]; + + SFileReadFile(hFile, Buffer, sizeof(Buffer), &dwBytesRead, NULL); + SFileCloseFile(hFile); + } + SFileCloseArchive(hMpq); + } + } +*/ + #ifdef TEST_COMMAND_LINE // Test-open MPQs from the command line. They must be plain name // and must be placed in the Test-MPQs folder -- cgit v1.2.3 From 01e940f998e64ceb60d39a30d0e40c33be430744 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Tue, 7 Feb 2023 07:31:47 +0100 Subject: Fixed regression for W3 maps --- src/SFileCreateArchive.cpp | 9 ++++++++- src/StormLib.h | 1 - test/StormTest.cpp | 12 ++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'test/StormTest.cpp') diff --git a/src/SFileCreateArchive.cpp b/src/SFileCreateArchive.cpp index 4266070..c0ea367 100644 --- a/src/SFileCreateArchive.cpp +++ b/src/SFileCreateArchive.cpp @@ -27,6 +27,13 @@ static const DWORD MpqHeaderSizes[] = //----------------------------------------------------------------------------- // Local functions +static DWORD GetValidFileFlags(DWORD dwMpqVersion) +{ + if(dwMpqVersion > MPQ_FORMAT_VERSION_1) + return MPQ_FILE_VALID_FLAGS; + return MPQ_FILE_VALID_FLAGS_W3X; +} + static USHORT GetSectorSizeShift(DWORD dwSectorSize) { USHORT wSectorSizeShift = 0; @@ -211,7 +218,7 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea ha->dwMaxFileCount = dwHashTableSize; ha->dwFileTableSize = 0; ha->dwReservedFiles = dwReservedFiles; - ha->dwValidFileFlags = (pCreateInfo->dwMpqVersion > 1) ? MPQ_FILE_VALID_FLAGS : MPQ_FILE_VALID_FLAGS_W3X; + ha->dwValidFileFlags = GetValidFileFlags(pCreateInfo->dwMpqVersion); ha->dwFileFlags1 = pCreateInfo->dwFileFlags1; ha->dwFileFlags2 = pCreateInfo->dwFileFlags2; ha->dwFileFlags3 = pCreateInfo->dwFileFlags3 ? MPQ_FILE_EXISTS : 0; diff --git a/src/StormLib.h b/src/StormLib.h index dad9fc8..e45f99d 100644 --- a/src/StormLib.h +++ b/src/StormLib.h @@ -247,7 +247,6 @@ extern "C" { MPQ_FILE_COMPRESS | \ MPQ_FILE_ENCRYPTED | \ MPQ_FILE_FIX_KEY | \ - MPQ_FILE_SINGLE_UNIT | \ MPQ_FILE_DELETE_MARKER | \ MPQ_FILE_SECTOR_CRC | \ MPQ_FILE_SIGNATURE | \ diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 916eed0..2f45e96 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -4183,7 +4183,6 @@ int _tmain(int argc, TCHAR * argv[]) // Initialize storage and mix the random number generator printf("==== Test Suite for StormLib version %s ====\n", STORMLIB_VERSION_STRING); dwErrCode = InitializeMpqDirectory(argv, argc); - /* // Check creation of the MPQ with LZMA compression LPCTSTR szArchiveName = _T("E:\\new-mpq.mpq"); @@ -4193,12 +4192,12 @@ int _tmain(int argc, TCHAR * argv[]) DeleteFile(szArchiveName); if(SFileCreateArchive(szArchiveName, MPQ_CREATE_ARCHIVE_V2 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES, 0x1000, &hMpq)) { - SFileAddFileEx(hMpq, _T("e:\\DlgSetFileAssoc.cpp"), "DlgSetFileAssoc.cpp", MPQ_FILE_SINGLE_UNIT | MPQ_FILE_COMPRESS, MPQ_COMPRESSION_LZMA, MPQ_COMPRESSION_NEXT_SAME); + SFileAddFileEx(hMpq, _T("e:\\DlgSearchFile.cpp"), "DlgSearchFile.cpp", MPQ_FILE_SINGLE_UNIT | MPQ_FILE_COMPRESS, MPQ_COMPRESSION_LZMA, MPQ_COMPRESSION_NEXT_SAME); SFileCloseArchive(hMpq); if(SFileOpenArchive(szArchiveName, 0, 0, &hMpq)) { - if(SFileOpenFileEx(hMpq, "DlgSetFileAssoc.cpp", 0, &hFile)) + if(SFileOpenFileEx(hMpq, "DlgSearchFile.cpp", 0, &hFile)) { DWORD dwBytesRead = 0; BYTE Buffer[0x100]; @@ -4210,7 +4209,6 @@ int _tmain(int argc, TCHAR * argv[]) } } */ - #ifdef TEST_COMMAND_LINE // Test-open MPQs from the command line. They must be plain name // and must be placed in the Test-MPQs folder @@ -4260,8 +4258,7 @@ int _tmain(int argc, TCHAR * argv[]) for(size_t i = 0; i < _countof(Test_OpenMpqs); i++) { dwErrCode = TestOpenArchive(Test_OpenMpqs[i]); - //if(dwErrCode != ERROR_SUCCESS) - // break; + dwErrCode = ERROR_SUCCESS; } } #endif // TEST_OPEN_MPQ @@ -4275,8 +4272,7 @@ int _tmain(int argc, TCHAR * argv[]) dwErrCode = TestReopenArchive(Test_ReopenMpqs[i].szName1, Test_ReopenMpqs[i].szDataHash, Test_ReopenMpqs[i].dwFlags); - //if(dwErrCode != ERROR_SUCCESS) - // break; + dwErrCode = ERROR_SUCCESS; } } #endif -- cgit v1.2.3