From 92068d8760adf147205e11b7bd16f7d7841ff41b Mon Sep 17 00:00:00 2001 From: Shawwwn Date: Fri, 16 May 2014 14:25:11 -0700 Subject: [PATCH] Added decompress file function --- H2OExtractor.dsp | 4 ++ Sample/Cursors.H2O | Bin 9967 -> 0 bytes Source/Archive.cpp | 89 ++++++++++++++++++----------- Source/Archive.h | 1 + Source/ArchiveCompressedFileData.h | 13 +++++ 5 files changed, 75 insertions(+), 32 deletions(-) delete mode 100644 Sample/Cursors.H2O create mode 100644 Source/ArchiveCompressedFileData.h diff --git a/H2OExtractor.dsp b/H2OExtractor.dsp index f8d3ff5..2b7f9db 100644 --- a/H2OExtractor.dsp +++ b/H2OExtractor.dsp @@ -104,6 +104,10 @@ SOURCE=.\Source\ArchiveComment.h # End Source File # Begin Source File +SOURCE=.\Source\ArchiveCompressedFileData.h +# End Source File +# Begin Source File + SOURCE=.\Source\ArchiveCompressedStringChunk.h # End Source File # Begin Source File diff --git a/Sample/Cursors.H2O b/Sample/Cursors.H2O deleted file mode 100644 index e776e2d0f2dc3a560227e0e1dea8aacc614aac90..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9967 zcmbW+3tUWT9|!QMSP@~{3ZWA(xpb8zW*XJ9!q$?chOSG?CD$y{W{D-2w$`<) zN>jOpN~?=olWNymCAL@_VUgbdKhHV)ug^B`=Y5~g=Wk}t^PT6M&U4N)XMa1xY38Rh zrjBtDi7rm+)x+F;)c@7Y&GEY&=NK9s5)>R_1_N@co27;M7)x^tD~{v8D_;;CvN&iN zH%|2zq1V!Cg0;%kjn zr_GjZ;$15=KiGx?bF3Vh`+33E65c^qThoAlIaWc;nY`?8#yi}fHB=X7ICwq4++W=a zs;IMvzOKX-GUxS!{aETIgTZscv3ky2Ntdp7sQV21yAfxo4v#RR8g+OXX+v?WT$$S@-d;}K$I#!KxOL2BkNR!{vLIMp&yTtcNzTg%~YyWHv|k$74Pmb zXY<30@2MLK2LBe`Y2krDYx!gTIO_fd+i(bul?`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jGw$M!&7qdlbzg2PlV!lXij0%exBeh$J?YLHB&PeSyDlBG= z)NUgd?_;}1cZK@`^G0g76Ki~=yLe#3Z-T|lk=iTd{C2$7F?Xc)DzW&Rb#1*&IKP-Z zQVS3C!rEu4nbhtc!u*liLKPM>NNS6S?K|$Bo&H^C;X1<{lGLJT>dvUyeUnrX)stgXP8S;Thew6AFf|KUV8mvHc4$1IfhX6 z0pj7c8p61kPf}Y>{-3X7Q~wYOAQ z%q^+CO)Rd}bp6HblG;1Op3w1;Hl_W&u48^lZ3VF%*J{i#sZ|n-#NxBEYizu5onfv? zZ4I%C!Cj^BQ5YAqO=?#YYtYL_GG(`1u$XUBn?jzI@%e$?Zum!R(V-uMT#G%_`yiV*W|3PX|kn0W(l)Q_1m)&)t;lnzvTC9xw-`Hj}JT9nUXj zq10v(+wpJ1Je1lqDlBHA)Ml%&n2S=2`DAD37qd}nF?;OHVm?Z(Az1#}F}XcJ^3*e5 zIA@rVQfs8bVopjer@~@ZO6?F87V}bShpMocnNo`pZfAcR=BCtQ{Mnhs?3CK!DlF!w z)Z+is?QC4kP^rbNvNMZ0Dz%uCcQ(hErBaJ|HE%m!>zJofiaLs{jB1 diff --git a/Source/Archive.cpp b/Source/Archive.cpp index 63b2cc2..20df2c8 100644 --- a/Source/Archive.cpp +++ b/Source/Archive.cpp @@ -205,7 +205,7 @@ void Archive::open(char* szFilePath) DB::debugLog("\nDirectoryParents Section: ", "", NULL); curPos = readDirectoryParents(curPos); - + bool success; // Parse compressed file names success = parseStringChunk(m_FileNameDesc, m_FileNameChunk, m_pCompressedFileNameChunk, m_FileNameList); @@ -244,29 +244,17 @@ void Archive::open(char* szFilePath) DB::debugLog("---------------", "", ""); #endif #endif + } // TODO: Refactor this function. void Archive::extractByIndex(uint32_t index) { - ArchiveFile& rFile = m_FileList[index]; - char* buffer = new char[rFile.CompressedSize]; - m_hH2O.seekg(rFile.Offest, std::ios::beg); - m_hH2O.read(buffer, rFile.CompressedSize); - - const char* dirPath = "output/"; - if (checkPathType(dirPath)!=TYPE_DIR) - mkdir(dirPath); - - /* - // generate file name and create directory - char fileName[128]; - char fullPath[128]; - getFileName(index, ".wav", fileName); - getFullPath("output/", fileName, fullPath); - */ - + // + // Generate File Name + // + // TODO: Add folder structure char fileName[128]; memset(fileName, 0, 128); if (m_FileList[index].FileNameIndex==-1) @@ -277,35 +265,72 @@ void Archive::extractByIndex(uint32_t index) { wtoc(m_FileNameList[index], fileName); } - /* - char pathName[128]; - memset(pathName, 0, 128); - if(m_FileList[index].FolderNameIndex==-1) + char fullPath[256]; + getFullPath("output/", fileName, fullPath); +#ifdef H2O_PRINT_WHEN_EXTRACT + DB::debugLog(fileName, "", ""); +#endif + + // + // Extract File + // + ArchiveFile& rFile = m_FileList[index]; + char* pFileBuffer; + m_hH2O.seekg(rFile.Offest, std::ios::beg); + + // Decompress buffer if compressed + if (rFile.CompressionTag!=0) { + ArchiveCompressedFileData tFileDesc; + m_hH2O.read((char*)&tFileDesc, sizeof(ArchiveCompressedFileData)); + #ifdef H2O_PRINT_WHEN_EXTRACT + DB::debugLog("- CompressedSize: ", tFileDesc.CompressedSize, ""); + DB::debugLog("- RawSize: ", tFileDesc.RawSize, ""); + DB::debugLog("- CRC32[hex]: ", tFileDesc.CRC32, NULL, true); + #endif + pFileBuffer = new char[rFile.CompressedSize]; + m_hH2O.read(pFileBuffer, rFile.CompressedSize); + char* pDecompressedBuffer = new char[tFileDesc.RawSize]; + bool result = runblast_mem2mem(pFileBuffer, tFileDesc.RawSize, pDecompressedBuffer, *(uint32_t*)(tFileDesc.CRC32)); + if (result) + { + #ifdef H2O_PRINT_WHEN_EXTRACT + DB::debugLog("- Decompress: ", "Success!", " - output decompressed data"); + #endif + delete[] pFileBuffer; // delete the compressed buffer since we don't need it anymore + pFileBuffer = pDecompressedBuffer; + } + else + { + #ifdef H2O_PRINT_WHEN_EXTRACT + DB::debugLog("- Decompress: ", "Fail!", " - output compressed data"); + #endif + delete[] pDecompressedBuffer; + } + pDecompressedBuffer = NULL; } else { - wtoc(m_DirectoryNameList[index], pathName); + pFileBuffer = new char[rFile.CompressedSize]; + m_hH2O.read(pFileBuffer, rFile.CompressedSize); } - */ - char fullPath[256]; - getFullPath("output/", fileName, fullPath); // write file std::ofstream destFile; destFile.open(fullPath, std::ofstream::binary); - destFile.write(buffer, rFile.CompressedSize); + destFile.write(pFileBuffer, rFile.CompressedSize); destFile.close(); - delete[] buffer; - -#ifdef H2O_PRINT_WHEN_EXTRACT - DB::debugLog(fileName, "", ""); -#endif + delete[] pFileBuffer; + pFileBuffer = NULL; } void Archive::extractAll() { + const char* dirPath = "output/"; + if (checkPathType(dirPath)!=TYPE_DIR) + mkdir(dirPath); + for (int i=0; i