diff --git a/.gitignore b/.gitignore index 994873e..1f3424e 100644 --- a/.gitignore +++ b/.gitignore @@ -94,4 +94,6 @@ packages/ *.dep *.pch *.ncb -*.exp \ No newline at end of file +*.exp + +[Ss]ample/ \ No newline at end of file diff --git a/H2OExtractor.dsp b/H2OExtractor.dsp index 85b1b4d..e631589 100644 --- a/H2OExtractor.dsp +++ b/H2OExtractor.dsp @@ -108,6 +108,14 @@ SOURCE=.\Source\ArchiveFile.h # End Source File # Begin Source File +SOURCE=.\Source\ArchiveFileName.h +# End Source File +# Begin Source File + +SOURCE=.\Source\ArchiveFileNameChunk.h +# End Source File +# Begin Source File + SOURCE=.\Source\ArchiveFileNameDesc.h # End Source File # Begin Source File @@ -132,6 +140,14 @@ SOURCE=.\Source\ArchiveFile.cpp # End Source File # Begin Source File +SOURCE=.\Source\ArchiveFileName.cpp +# End Source File +# Begin Source File + +SOURCE=.\Source\ArchiveFileNameChunk.cpp +# End Source File +# Begin Source File + SOURCE=.\Source\ArchiveFileNameDesc.cpp # End Source File # Begin Source File @@ -165,6 +181,22 @@ SOURCE=.\Source\DebugUtils.h # End Source File # Begin Source File +SOURCE=.\Source\FileUtils.cpp +# End Source File +# Begin Source File + +SOURCE=.\Source\FileUtils.h +# End Source File +# Begin Source File + +SOURCE=.\Source\StringUtils.cpp +# End Source File +# Begin Source File + +SOURCE=.\Source\StringUtils.h +# End Source File +# Begin Source File + SOURCE=.\Source\Types.h # End Source File # End Group diff --git a/Source/Archive.cpp b/Source/Archive.cpp index 2def4a1..f888999 100644 --- a/Source/Archive.cpp +++ b/Source/Archive.cpp @@ -23,12 +23,8 @@ uint64_t Archive::readComment(uint64_t streamPos) // Read Header m_hH2O.read(m_Comment.szHeader, 8); - DB::debugLog("- ArchiveHeader: ", m_Comment.szHeader, NULL); - // Read VersionInfo - m_hH2O.read((char*)&m_Comment.VersionInfo, 4); - DB::debugLog("- VersionInfo: ", m_Comment.VersionInfo, NULL); - + m_hH2O.read((char*)&m_Comment.VersionInfo, 4); // Read Comments uint64_t beg = m_hH2O.tellg(); char curByte = 0x0; @@ -42,7 +38,12 @@ uint64_t Archive::readComment(uint64_t streamPos) m_Comment.szComments = new char[length]; memset(m_Comment.szComments, 0, length); m_hH2O.read(m_Comment.szComments, length-1); + +//#if _DEBUG + DB::debugLog("- ArchiveHeader: ", m_Comment.szHeader, NULL); + DB::debugLog("- VersionInfo: ", m_Comment.VersionInfo, NULL); DB::debugLog("- Comments: ", m_Comment.szComments, NULL); +//#endif return end; } @@ -50,23 +51,86 @@ uint64_t Archive::readHeader(uint64_t streamPos) { m_hH2O.seekg(streamPos, std::ios::beg); m_hH2O.read((char*)&m_Header, sizeof(ArchiveHeader)); - DB::debugLog("size: ", sizeof(m_Header.CompressedSize), NULL); + +//#if _DEBUG DB::debugLog("- Version: ", m_Header.Version, NULL); DB::debugLog("- FileCount: ", m_Header.FileCount, NULL); DB::debugLog("- CompressedSize: ", m_Header.CompressedSize, NULL); DB::debugLog("- RawSize: ", m_Header.RawSize, NULL); - return 0; +//#endif + return m_hH2O.tellg(); +} + +uint64_t Archive::readFileList(uint64_t streamPos) +{ + m_hH2O.seekg(streamPos, std::ios::beg); + ArchiveFile curFile; + for (int i=0; i #include #include +#include #include "Types.h" +#include "FileUtils.h" +#include "StringUtils.h" #include "DebugUtils.h" #include "ArchiveComment.h" #include "ArchiveHeader.h" @@ -24,13 +27,16 @@ class Archive uint64_t readComment(uint64_t streamPos); uint64_t readHeader(uint64_t streamPos); + uint64_t readFileList(uint64_t streamPos); void open(char* szFilePath); + void extractByIndex(uint32_t index); + void extractAll(); void close(); ArchiveComment m_Comment; ArchiveHeader m_Header; - + std::vector m_FileList; protected: diff --git a/Source/ArchiveFile.h b/Source/ArchiveFile.h index 5b1b799..b4460ca 100644 --- a/Source/ArchiveFile.h +++ b/Source/ArchiveFile.h @@ -12,7 +12,7 @@ struct ArchiveFile uint32_t FileId; uint32_t RawSize; uint32_t CompressedSize; - uint32_t Offest; + uint64_t Offest; char CRC32[4]; uint32_t UnknownConstant; }; diff --git a/Source/DebugUtils.cpp b/Source/DebugUtils.cpp index cfa9e2b..75dafd2 100644 --- a/Source/DebugUtils.cpp +++ b/Source/DebugUtils.cpp @@ -1,3 +1,4 @@ +/* DebugUtils.cpp */ #include "DebugUtils.h" namespace DB { @@ -12,34 +13,33 @@ namespace DB { } fflush(stdout); } - void debugLog(char* szDesc, char* szString, char* szComment) + void debugLog(char* szDesc, char* szString, char* szComment, bool isHex) { - #ifdef _DEBUG szDesc = (szDesc==NULL) ? "" : szDesc; szString = (szString==NULL) ? "" : szString; szComment = (szComment==NULL) ? "" : szComment; - std::cout << szDesc << szString << szComment << std::endl; - #endif + if (isHex) + { + // Display in big endian order + std::cout << szDesc << std::hex << std::setfill ('0') << std::setw(8) << *(uint32_t*)szString << std::dec << szComment << std::endl; + } + else + std::cout << szDesc << szString << szComment << std::endl; } void debugLog(char* szDesc, float szFloat, char* szComment) { - #ifdef _DEBUG szDesc = (szDesc==NULL) ? "" : szDesc; szComment = (szComment==NULL) ? "" : szComment; std::cout << szDesc << std::fixed << std::setprecision(2) << szFloat << szComment << std::endl; - #endif } void debugLog(char* szDesc, uint32_t szUint, char* szComment) { - #ifdef _DEBUG szDesc = (szDesc==NULL) ? "" : szDesc; szComment = (szComment==NULL) ? "" : szComment; std::cout << szDesc << szUint << szComment << std::endl; - #endif } void debugLog(char* szDesc, uint64_t szUint, char* szComment) { - #ifdef _DEBUG szDesc = (szDesc==NULL) ? "" : szDesc; szComment = (szComment==NULL) ? "" : szComment; #if (_MSC_VER < 1300) // VC6 doesn't support cout 64bit integer @@ -49,6 +49,5 @@ namespace DB { #else std::cout << szDesc << szUint << szComment << std::endl; #endif - #endif } } \ No newline at end of file diff --git a/Source/DebugUtils.h b/Source/DebugUtils.h index 9e6e96f..7562d94 100644 --- a/Source/DebugUtils.h +++ b/Source/DebugUtils.h @@ -1,12 +1,13 @@ -/* DebugUtils.hpp */ +/* DebugUtils.h */ #pragma once + #include #include #include "Types.h" namespace DB { void printint64(uint64_t i); - void debugLog(char* szDesc, char* szString, char* szComment); + void debugLog(char* szDesc, char* szString, char* szComment, bool isHex=false); void debugLog(char* szDesc, float szFloat, char* szComment); void debugLog(char* szDesc, uint32_t szUint32, char* szComment); void debugLog(char* szDesc, uint64_t szUint64, char* szComment); diff --git a/Source/FileUtils.cpp b/Source/FileUtils.cpp new file mode 100644 index 0000000..aca3f72 --- /dev/null +++ b/Source/FileUtils.cpp @@ -0,0 +1,16 @@ +/* FileUtils.cpp */ +#include "FileUtils.h" + +PathType checkPathType(const char* dirPath) +{ + if (access(dirPath, 0)==0) + { + struct stat status; + stat(dirPath, &status); + if ( status.st_mode & S_IFDIR ) + return TYPE_DIR; + else + return TYPE_FILE; + } + return TYPE_NOT_EXIST; +} \ No newline at end of file diff --git a/Source/FileUtils.h b/Source/FileUtils.h new file mode 100644 index 0000000..a37cfb8 --- /dev/null +++ b/Source/FileUtils.h @@ -0,0 +1,10 @@ +/* FileUtils.h */ +#pragma once + +#include // For access() +#include // For stat() +#include // For stat() +#include "Types.h" + +enum PathType { TYPE_DIR, TYPE_FILE, TYPE_NOT_EXIST }; +PathType checkPathType(const char* dirPath); \ No newline at end of file diff --git a/Source/H2OExtractor.cpp b/Source/H2OExtractor.cpp index 1b05c63..98a88db 100644 --- a/Source/H2OExtractor.cpp +++ b/Source/H2OExtractor.cpp @@ -4,7 +4,9 @@ int main(int argc, char* argv[]) { printf("H2OExtractor\n============================\n"); - Archive h2o("Cursors.H2O"); - return 0; -} + Archive h2o("Input.H2O"); + DB::debugLog("\nExtracting files...", "\n", NULL); + h2o.extractAll(); + return 0; +} \ No newline at end of file diff --git a/Source/StringUtils.cpp b/Source/StringUtils.cpp new file mode 100644 index 0000000..97a3438 --- /dev/null +++ b/Source/StringUtils.cpp @@ -0,0 +1,20 @@ +/* StringUtils.cpp */ +#include "StringUtils.h" + +// TODO: Use native char array + +void getFileName(uint32_t index, const char* postfix, char* outputBuffer) +{ + memset(outputBuffer, 0, 16); + char szIndex[8]; + itoa (index, szIndex, 10); + strcpy(outputBuffer, szIndex); + strcat(outputBuffer, postfix); +} + +void getFullPath(const char* directoryPath, char* fileName, char* outputBuffer) +{ + memset(outputBuffer, 0, 64); + strcpy(outputBuffer, directoryPath); + strcat(outputBuffer, fileName); +} \ No newline at end of file diff --git a/Source/StringUtils.h b/Source/StringUtils.h new file mode 100644 index 0000000..6318f6d --- /dev/null +++ b/Source/StringUtils.h @@ -0,0 +1,9 @@ +/* StringUtils.h */ +#pragma once + +#include +#include +#include "Types.h" + +void getFileName(uint32_t index, const char* postfix, char* outputBuffer); +void getFullPath(const char* directoryPath, char* fileName, char* outputBuffer);