From c5fb5c7dfa40ae1304ac2ebf1431a9d6a2ba4d13 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Tue, 6 Jul 2021 22:47:39 +0200 Subject: Beautifying --- src/SCompression.cpp | 48 ++++++++++++++++++++++-------------------------- test/StormTest.cpp | 4 +--- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/SCompression.cpp b/src/SCompression.cpp index ae7082b..1d0f679 100644 --- a/src/SCompression.cpp +++ b/src/SCompression.cpp @@ -175,7 +175,7 @@ int Decompress_ZLIB(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, i *pcbOutBuffer = z.total_out; inflateEnd(&z); } - + return (nResult >= Z_OK); } @@ -279,33 +279,29 @@ static void Compress_PKLIB(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBu static int Decompress_PKLIB(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer) { TDataInfo Info; // Data information - char * work_buf = STORM_ALLOC(char, EXP_BUFFER_SIZE);// Pklib's work buffer - - // Handle no-memory condition - if(work_buf == NULL) - return 0; - - // Fill data information structure - memset(work_buf, 0, EXP_BUFFER_SIZE); - Info.pbInBuff = (unsigned char *)pvInBuffer; - Info.pbInBuffEnd = (unsigned char *)pvInBuffer + cbInBuffer; - Info.pbOutBuff = (unsigned char *)pvOutBuffer; - Info.pbOutBuffEnd = (unsigned char *)pvOutBuffer + *pcbOutBuffer; - - // Do the decompression - explode(ReadInputData, WriteOutputData, work_buf, &Info); - - // If PKLIB is unable to decompress the data, return 0; - if(Info.pbOutBuff == pvOutBuffer) - { + char * work_buf; + int nResult = 0; + + // Allocate Pklib's work buffer + if((work_buf = STORM_ALLOC(char, EXP_BUFFER_SIZE)) != NULL) + { + // Fill data information structure + memset(work_buf, 0, EXP_BUFFER_SIZE); + Info.pbInBuff = (unsigned char *)pvInBuffer; + Info.pbInBuffEnd = (unsigned char *)pvInBuffer + cbInBuffer; + Info.pbOutBuff = (unsigned char *)pvOutBuffer; + Info.pbOutBuffEnd = (unsigned char *)pvOutBuffer + *pcbOutBuffer; + + // Do the decompression + if(explode(ReadInputData, WriteOutputData, work_buf, &Info) == CMP_NO_ERROR) + nResult = 1; + + // Give away the number of decompressed bytes + *pcbOutBuffer = (int)(Info.pbOutBuff - (unsigned char *)pvOutBuffer); STORM_FREE(work_buf); - return 0; - } + } - // Give away the number of decompressed bytes - *pcbOutBuffer = (int)(Info.pbOutBuff - (unsigned char *)pvOutBuffer); - STORM_FREE(work_buf); - return 1; + return nResult; } /******************************************************************************/ diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 44d65de..651d8e9 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -4224,8 +4224,6 @@ static const TEST_INFO TestList_MasterMirror[] = static const TEST_INFO Test_Mpqs[] = { - {_T("ProblemMpqArchive.SC2Replay"), NULL, 0, "replay.game.events"}, - // Correct or damaged archives {_T("MPQ_1997_v1_Diablo1_DIABDAT.MPQ"), NULL, 0, "music\\dintro.wav", "File00000023.xxx"}, {_T("MPQ_2016_v1_D2XP_IX86_1xx_114a.mpq"), NULL, 0, "waitingroombkgd.dc6"}, // Update MPQ from Diablo II (patch 2016) @@ -4307,7 +4305,7 @@ int _tmain(int argc, TCHAR * argv[]) TestArchive(_T("ProblemMpqArchive.SC2Replay"), NULL, 0, "replay.game.events", NULL); for(int i = 1; i < argc; i++) { - ForEachFile_OpenArchive(argv[i]); + TestOpenArchive_CompactArchive(argv[i], _T("TestArchiveCopy.mpq"), false); } // -- cgit v1.2.3