From 0e0cb087465908b86bd00f0ed63e35a1bbd217ba Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Sat, 1 Oct 2011 22:43:05 +0200 Subject: [PATCH] Parse file entries. --- CMakeLists.txt | 43 ++-- src/BlockReader.hpp | 17 -- src/InnoExtract.cpp | 106 ++++++++- src/{ => loader}/ExeFormat.hpp | 7 +- src/{ => loader}/ExeReader.cpp | 10 +- src/{ => loader}/ExeReader.hpp | 6 +- src/{ => loader}/SetupLoader.cpp | 10 +- src/{ => loader}/SetupLoader.hpp | 8 +- src/{ => loader}/SetupLoaderFormat.hpp | 7 +- src/{ => setup}/CustomMessageEntry.cpp | 4 +- src/{ => setup}/CustomMessageEntry.hpp | 9 +- src/setup/DirectoryEntry.cpp | 82 +++++++ src/setup/DirectoryEntry.hpp | 47 ++++ src/setup/FileEntry.cpp | 222 ++++++++++++++++++ src/setup/FileEntry.hpp | 91 +++++++ src/{ => setup}/LanguageEntry.cpp | 7 +- src/{ => setup}/LanguageEntry.hpp | 10 +- src/{ => setup}/PermissionEntry.cpp | 4 +- src/{ => setup}/PermissionEntry.hpp | 9 +- src/{ => setup}/SetupComponentEntry.cpp | 6 +- src/{ => setup}/SetupComponentEntry.hpp | 16 +- src/{ => setup}/SetupHeader.cpp | 9 +- src/{ => setup}/SetupHeader.hpp | 77 ++---- src/{ => setup}/SetupHeaderFormat.hpp | 9 +- src/{ => setup}/SetupTaskEntry.cpp | 6 +- src/{ => setup}/SetupTaskEntry.hpp | 15 +- src/{ => setup}/SetupTypeEntry.cpp | 6 +- src/{ => setup}/SetupTypeEntry.hpp | 15 +- src/{ => setup}/Version.cpp | 4 +- src/{ => setup}/Version.hpp | 8 +- src/{ => setup}/WindowsVersion.cpp | 45 ++-- src/{ => setup}/WindowsVersion.hpp | 11 +- src/{ => stream}/BlockReader.cpp | 14 +- src/stream/BlockReader.hpp | 17 ++ src/{ => stream}/ChunkFilter.cpp | 2 +- src/{ => stream}/ChunkFilter.hpp | 10 +- .../Lzma1Filter.cpp} | 12 +- .../Lzma1Filter.hpp} | 26 +- src/{ => util}/Enum.hpp | 34 +-- src/{ => util}/Flags.hpp | 31 ++- src/{ => util}/LoadingUtils.cpp | 6 +- src/{ => util}/LoadingUtils.hpp | 6 +- src/{ => util}/Output.cpp | 2 +- src/{ => util}/Output.hpp | 6 +- src/{ => util}/StoredEnum.hpp | 17 +- src/{ => util}/Types.hpp | 6 +- src/{ => util}/Utils.cpp | 2 +- src/{ => util}/Utils.hpp | 8 +- 48 files changed, 831 insertions(+), 294 deletions(-) delete mode 100644 src/BlockReader.hpp rename src/{ => loader}/ExeFormat.hpp (92%) rename src/{ => loader}/ExeReader.cpp (97%) rename src/{ => loader}/ExeReader.hpp (89%) rename src/{ => loader}/SetupLoader.cpp (97%) rename src/{ => loader}/SetupLoader.hpp (88%) rename src/{ => loader}/SetupLoaderFormat.hpp (94%) rename src/{ => setup}/CustomMessageEntry.cpp (73%) rename src/{ => setup}/CustomMessageEntry.hpp (65%) create mode 100644 src/setup/DirectoryEntry.cpp create mode 100644 src/setup/DirectoryEntry.hpp create mode 100644 src/setup/FileEntry.cpp create mode 100644 src/setup/FileEntry.hpp rename src/{ => setup}/LanguageEntry.cpp (94%) rename src/{ => setup}/LanguageEntry.hpp (75%) rename src/{ => setup}/PermissionEntry.cpp (71%) rename src/{ => setup}/PermissionEntry.hpp (51%) rename src/{ => setup}/SetupComponentEntry.cpp (94%) rename src/{ => setup}/SetupComponentEntry.hpp (68%) rename src/{ => setup}/SetupHeader.cpp (99%) rename src/{ => setup}/SetupHeader.hpp (80%) rename src/{ => setup}/SetupHeaderFormat.hpp (91%) rename src/{ => setup}/SetupTaskEntry.cpp (92%) rename src/{ => setup}/SetupTaskEntry.hpp (68%) rename src/{ => setup}/SetupTypeEntry.cpp (92%) rename src/{ => setup}/SetupTypeEntry.hpp (68%) rename src/{ => setup}/Version.cpp (99%) rename src/{ => setup}/Version.hpp (95%) rename src/{ => setup}/WindowsVersion.cpp (72%) rename src/{ => setup}/WindowsVersion.hpp (87%) rename src/{ => stream}/BlockReader.cpp (88%) create mode 100644 src/stream/BlockReader.hpp rename src/{ => stream}/ChunkFilter.cpp (89%) rename src/{ => stream}/ChunkFilter.hpp (90%) rename src/{LzmaFilter.cpp => stream/Lzma1Filter.cpp} (85%) rename src/{LzmaFilter.hpp => stream/Lzma1Filter.hpp} (62%) rename src/{ => util}/Enum.hpp (58%) rename src/{ => util}/Flags.hpp (85%) rename src/{ => util}/LoadingUtils.cpp (94%) rename src/{ => util}/LoadingUtils.hpp (96%) rename src/{ => util}/Output.cpp (69%) rename src/{ => util}/Output.hpp (93%) rename src/{ => util}/StoredEnum.hpp (93%) rename src/{ => util}/Types.hpp (70%) rename src/{ => util}/Utils.cpp (87%) rename src/{ => util}/Utils.hpp (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc47965..ad0579b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,25 +27,34 @@ list(APPEND LIBRARIES -llzma) list(APPEND CMAKE_CXX_FLAGS "-ggdb -O3 -march=native -Wl,--as-needed") set(INNOEXTRACT_SOURCES - src/BlockReader.cpp - src/ChunkFilter.cpp - src/CustomMessageEntry.cpp - src/ExeReader.cpp + + src/loader/ExeReader.cpp + src/loader/SetupLoader.cpp + + src/setup/CustomMessageEntry.cpp + src/setup/DirectoryEntry.cpp + src/setup/FileEntry.cpp + src/setup/LanguageEntry.cpp + src/setup/PermissionEntry.cpp + src/setup/SetupComponentEntry.cpp + src/setup/SetupHeader.cpp + src/setup/SetupTaskEntry.cpp + src/setup/SetupTypeEntry.cpp + src/setup/Version.cpp + src/setup/WindowsVersion.cpp + + src/stream/BlockReader.cpp + src/stream/ChunkFilter.cpp + src/stream/Lzma1Filter.cpp + + src/util/LoadingUtils.cpp + src/util/Output.cpp + src/util/Utils.cpp + src/InnoExtract.cpp - src/LanguageEntry.cpp - src/LoadingUtils.cpp - src/LzmaFilter.cpp - src/Output.cpp - src/PermissionEntry.cpp - src/SetupComponentEntry.cpp - src/SetupHeader.cpp - src/SetupLoader.cpp - src/SetupTaskEntry.cpp - src/SetupTypeEntry.cpp - src/Utils.cpp - src/Version.cpp - src/WindowsVersion.cpp ) +include_directories(src) + add_executable(innoextract ${INNOEXTRACT_SOURCES}) target_link_libraries(innoextract ${LIBRARIES}) diff --git a/src/BlockReader.hpp b/src/BlockReader.hpp deleted file mode 100644 index 8555634..0000000 --- a/src/BlockReader.hpp +++ /dev/null @@ -1,17 +0,0 @@ - -#ifndef INNOEXTRACT_BLOCKREADER_HPP -#define INNOEXTRACT_BLOCKREADER_HPP - -#include - -#include "Version.hpp" - -class BlockReader { - -public: - - static std::istream * get(std::istream & base, const InnoVersion & version); - -}; - -#endif // INNOEXTRACT_BLOCKREADER_HPP diff --git a/src/InnoExtract.cpp b/src/InnoExtract.cpp index b59c091..4d531ef 100644 --- a/src/InnoExtract.cpp +++ b/src/InnoExtract.cpp @@ -11,18 +11,24 @@ #include -#include "SetupHeader.hpp" -#include "SetupLoader.hpp" -#include "Utils.hpp" -#include "Output.hpp" -#include "BlockReader.hpp" -#include "LanguageEntry.hpp" -#include "CustomMessageEntry.hpp" -#include "LoadingUtils.hpp" -#include "PermissionEntry.hpp" -#include "SetupTypeEntry.hpp" -#include "SetupComponentEntry.hpp" -#include "SetupTaskEntry.hpp" +#include "loader/SetupLoader.hpp" + +#include "setup/CustomMessageEntry.hpp" +#include "setup/DirectoryEntry.hpp" +#include "setup/FileEntry.hpp" +#include "setup/LanguageEntry.hpp" +#include "setup/PermissionEntry.hpp" +#include "setup/SetupComponentEntry.hpp" +#include "setup/SetupHeader.hpp" +#include "setup/SetupTaskEntry.hpp" +#include "setup/SetupTypeEntry.hpp" +#include "setup/Version.hpp" + +#include "stream/BlockReader.hpp" + +#include "util/LoadingUtils.hpp" +#include "util/Output.hpp" +#include "util/Utils.hpp" using std::cout; using std::string; @@ -167,7 +173,7 @@ int main(int argc, char * argv[]) { cout << IfNotZero("Type entries", header.numTypeEntries); cout << IfNotZero("Component entries", header.numComponentEntries); cout << IfNotZero("Task entries", header.numTaskEntries); - cout << IfNotZero("Dir entries", header.numDirEntries); + cout << IfNotZero("Dir entries", header.numDirectoryEntries); cout << IfNotZero("File entries", header.numFileEntries); cout << IfNotZero("File location entries", header.numFileLocationEntries); cout << IfNotZero("Icon entries", header.numIconEntries); @@ -424,5 +430,79 @@ int main(int argc, char * argv[]) { }; + if(header.numDirectoryEntries) { + cout << endl << "Directory entries:" << endl; + } + for(size_t i = 0; i < header.numDirectoryEntries; i++) { + + DirectoryEntry entry; + entry.load(is, version); + if(is.fail()) { + error << "error reading directory entry #" << i; + } + + cout << " - " << Quoted(entry.name) << ':' << endl; + cout << IfNotEmpty(" Components", entry.components); + cout << IfNotEmpty(" Tasks", entry.tasks); + cout << IfNotEmpty(" Languages", entry.languages); + cout << IfNotEmpty(" Check", entry.check); + if(!entry.permissions.empty()) { + cout << " Permissions: " << entry.permissions.length() << " bytes"; + } + cout << IfNotEmpty(" After install", entry.afterInstall); + cout << IfNotEmpty(" Before install", entry.beforeInstall); + + cout << IfNotZero(" Attributes", entry.attributes); + + cout << IfNot(" Min version", entry.minVersion, header.minVersion); + cout << IfNot(" Only below version", entry.onlyBelowVersion, header.onlyBelowVersion); + + cout << IfNot(" Permission entry", entry.permission, -1); + + cout << IfNotZero(" Options", entry.options); + + }; + + if(header.numFileEntries) { + cout << endl << "File entries:" << endl; + } + for(size_t i = 0; i < header.numFileEntries; i++) { + + FileEntry entry; + entry.load(is, version); + if(is.fail()) { + error << "error reading file entry #" << i; + } + + if(entry.destination.empty()) { + cout << " - File #" << i << ':' << endl; + } else { + cout << " - " << Quoted(entry.destination) << ':' << endl; + } + cout << IfNotEmpty(" Source", entry.source); + cout << IfNotEmpty(" Install font name", entry.installFontName); + cout << IfNotEmpty(" Strong assembly name", entry.strongAssemblyName); + cout << IfNotEmpty(" Components", entry.components); + cout << IfNotEmpty(" Tasks", entry.tasks); + cout << IfNotEmpty(" Languages", entry.languages); + cout << IfNotEmpty(" Check", entry.check); + cout << IfNotEmpty(" After install", entry.afterInstall); + cout << IfNotEmpty(" Before install", entry.beforeInstall); + + cout << IfNot(" Min version", entry.minVersion, header.minVersion); + cout << IfNot(" Only below version", entry.onlyBelowVersion, header.onlyBelowVersion); + + cout << IfNot(" Location entry", entry.location, -1); + cout << IfNotZero(" Attributes", entry.attributes); + cout << IfNotZero(" Size", entry.externalSize); + + cout << IfNot(" Permission entry", entry.permission, -1); + + cout << IfNotZero(" Options", entry.options); + + cout << IfNot(" Type", entry.type, FileEntry::UserFile); + + }; + return 0; } diff --git a/src/ExeFormat.hpp b/src/loader/ExeFormat.hpp similarity index 92% rename from src/ExeFormat.hpp rename to src/loader/ExeFormat.hpp index 88679cb..07852a0 100644 --- a/src/ExeFormat.hpp +++ b/src/loader/ExeFormat.hpp @@ -1,5 +1,8 @@ -#include "Types.hpp" +#ifndef INNOEXTRACT_LOADER_EXEFORMAT_HPP +#define INNOEXTRACT_LOADER_EXEFORMAT_HPP + +#include "util/Types.hpp" # pragma pack(push, 1) @@ -93,3 +96,5 @@ struct CoffSection { }; #pragma pack(pop) + +#endif // INNOEXTRACT_LOADER_EXEFORMAT_HPP diff --git a/src/ExeReader.cpp b/src/loader/ExeReader.cpp similarity index 97% rename from src/ExeReader.cpp rename to src/loader/ExeReader.cpp index ba8d548..759daee 100644 --- a/src/ExeReader.cpp +++ b/src/loader/ExeReader.cpp @@ -1,15 +1,15 @@ -#include "ExeReader.hpp" +#include #include #include #include #include -#include "Types.hpp" -#include "ExeFormat.hpp" -#include "Utils.hpp" -#include "Output.hpp" +#include "loader/ExeFormat.hpp" +#include "util/Output.hpp" +#include "util/Types.hpp" +#include "util/Utils.hpp" using std::cout; using std::string; diff --git a/src/ExeReader.hpp b/src/loader/ExeReader.hpp similarity index 89% rename from src/ExeReader.hpp rename to src/loader/ExeReader.hpp index 9111988..9a5ba6b 100644 --- a/src/ExeReader.hpp +++ b/src/loader/ExeReader.hpp @@ -1,6 +1,6 @@ -#ifndef INNOEXTRACT_EXEREADER_HPP -#define INNOEXTRACT_EXEREADER_HPP +#ifndef INNOEXTRACT_LOADER_EXEREADER_HPP +#define INNOEXTRACT_LOADER_EXEREADER_HPP #include #include @@ -48,4 +48,4 @@ private: }; -#endif // INNOEXTRACT_EXEREADER_HPP +#endif // INNOEXTRACT_LOADER_EXEREADER_HPP diff --git a/src/SetupLoader.cpp b/src/loader/SetupLoader.cpp similarity index 97% rename from src/SetupLoader.cpp rename to src/loader/SetupLoader.cpp index e15b648..266d4a0 100644 --- a/src/SetupLoader.cpp +++ b/src/loader/SetupLoader.cpp @@ -1,14 +1,14 @@ -#include "SetupLoader.hpp" +#include #include #include -#include "ExeReader.hpp" -#include "SetupLoaderFormat.hpp" -#include "Utils.hpp" -#include "Output.hpp" +#include "loader/ExeReader.hpp" +#include "loader/SetupLoaderFormat.hpp" +#include "util/Output.hpp" +#include "util/Utils.hpp" using std::cout; using std::string; diff --git a/src/SetupLoader.hpp b/src/loader/SetupLoader.hpp similarity index 88% rename from src/SetupLoader.hpp rename to src/loader/SetupLoader.hpp index cdd6212..6a2ef8c 100644 --- a/src/SetupLoader.hpp +++ b/src/loader/SetupLoader.hpp @@ -1,11 +1,11 @@ -#ifndef INNOEXTRACT_SETUPLOADER_HPP -#define INNOEXTRACT_SETUPLOADER_HPP +#ifndef INNOEXTRACT_LOADER_SETUPLOADER_HPP +#define INNOEXTRACT_LOADER_SETUPLOADER_HPP #include #include -#include "Types.hpp" +#include "util/Types.hpp" enum ChecksumMode { ChecksumAdler32, @@ -49,4 +49,4 @@ private: }; -#endif // INNOEXTRACT_SETUPLOADER_HPP +#endif // INNOEXTRACT_LOADER_SETUPLOADER_HPP diff --git a/src/SetupLoaderFormat.hpp b/src/loader/SetupLoaderFormat.hpp similarity index 94% rename from src/SetupLoaderFormat.hpp rename to src/loader/SetupLoaderFormat.hpp index 54d0ad6..371980a 100644 --- a/src/SetupLoaderFormat.hpp +++ b/src/loader/SetupLoaderFormat.hpp @@ -1,5 +1,8 @@ -#include "Types.hpp" +#ifndef INNOEXTRACT_LOADER_SETUPLOADERFORMAT_HPP +#define INNOEXTRACT_LOADER_SETUPLOADERFORMAT_HPP + +#include "util/Types.hpp" #pragma pack(push,1) @@ -110,3 +113,5 @@ struct SetupLoaderHeader { }; #pragma pack(pop) + +#endif // INNOEXTRACT_LOADER_SETUPLOADERFORMAT_HPP diff --git a/src/CustomMessageEntry.cpp b/src/setup/CustomMessageEntry.cpp similarity index 73% rename from src/CustomMessageEntry.cpp rename to src/setup/CustomMessageEntry.cpp index b74a5eb..1ae9084 100644 --- a/src/CustomMessageEntry.cpp +++ b/src/setup/CustomMessageEntry.cpp @@ -1,7 +1,7 @@ -#include "CustomMessageEntry.hpp" +#include "setup/CustomMessageEntry.hpp" -#include "LoadingUtils.hpp" +#include "util/LoadingUtils.hpp" void CustomMessageEntry::load(std::istream & is, const InnoVersion & version) { diff --git a/src/CustomMessageEntry.hpp b/src/setup/CustomMessageEntry.hpp similarity index 65% rename from src/CustomMessageEntry.hpp rename to src/setup/CustomMessageEntry.hpp index 2f5a16a..68adc4f 100644 --- a/src/CustomMessageEntry.hpp +++ b/src/setup/CustomMessageEntry.hpp @@ -1,9 +1,10 @@ -#ifndef INNOEXTRACT_CUSTOMMESSAGEENTRY_HPP -#define INNOEXTRACT_CUSTOMMESSAGEENTRY_HPP +#ifndef INNOEXTRACT_SETUP_CUSTOMMESSAGEENTRY_HPP +#define INNOEXTRACT_SETUP_CUSTOMMESSAGEENTRY_HPP #include -#include "Version.hpp" + +#include "setup/Version.hpp" struct CustomMessageEntry { @@ -22,4 +23,4 @@ struct CustomMessageEntry { }; -#endif // INNOEXTRACT_CUSTOMMESSAGEENTRY_HPP +#endif // INNOEXTRACT_SETUP_CUSTOMMESSAGEENTRY_HPP diff --git a/src/setup/DirectoryEntry.cpp b/src/setup/DirectoryEntry.cpp new file mode 100644 index 0000000..3aa848d --- /dev/null +++ b/src/setup/DirectoryEntry.cpp @@ -0,0 +1,82 @@ + +#include "setup/DirectoryEntry.hpp" + +#include "util/LoadingUtils.hpp" +#include "util/StoredEnum.hpp" + +STORED_FLAGS_MAP(StoredInnoDirectoryOptions0, + doUninsNeverUninstall, + doDeleteAfterInstall, + doUninsAlwaysUninstall, +); + +// starting with version 5.2.0 +STORED_FLAGS_MAP(StoredInnoDirectoryOptions1, + doUninsNeverUninstall, + doDeleteAfterInstall, + doUninsAlwaysUninstall, + doSetNTFSCompression, + doUnsetNTFSCompression, +); + +void DirectoryEntry::load(std::istream & is, const InnoVersion & version) { + + is >> EncodedString(name, version.codepage()); + if(version > INNO_VERSION(1, 3, 26)) { + is >> EncodedString(components, version.codepage()); + is >> EncodedString(tasks, version.codepage()); + } else { + components.clear(), tasks.clear(); + } + if(version >= INNO_VERSION(4, 0, 1)) { + is >> EncodedString(languages, version.codepage()); + } else { + languages.clear(); + } + if(version >= INNO_VERSION(3, 0, 8)) { + is >> EncodedString(check, version.codepage()); + } else { + check.clear(); + } + if(version >= INNO_VERSION(4, 0, 11) && version < INNO_VERSION(4, 1, 0)) { + is >> EncodedString(permissions, version.codepage()); + } else { + permissions.clear(); + } + if(version >= INNO_VERSION(4, 1, 0)) { + is >> EncodedString(afterInstall, version.codepage()); + is >> EncodedString(beforeInstall, version.codepage()); + } else { + afterInstall.clear(), beforeInstall.clear(); + } + + if(version >= INNO_VERSION(2, 0, 11)) { + attributes = loadNumber(is); + } else { + attributes = 0; + } + + minVersion.load(is, version); + onlyBelowVersion.load(is, version); + + if(version >= INNO_VERSION(4, 1, 0)) { + permission = loadNumber(is); + } else { + permission = -1; + } + + if(version >= INNO_VERSION(5, 2, 0)) { + options = StoredFlags(is).get(); + } else { + options = StoredFlags(is).get(); + } + +} + +ENUM_NAMES(InnoDirectoryOptions::Enum, "Directory Option", + "never uninstall", + "delete after install", + "always uninstall", + "set NTFS compression", + "unset NTFS compression", +) diff --git a/src/setup/DirectoryEntry.hpp b/src/setup/DirectoryEntry.hpp new file mode 100644 index 0000000..d67bd22 --- /dev/null +++ b/src/setup/DirectoryEntry.hpp @@ -0,0 +1,47 @@ + +#ifndef INNOEXTRACT_SETUP_DIRECTORYENTRY_HPP +#define INNOEXTRACT_SETUP_DIRECTORYENTRY_HPP + +#include + +#include "setup/Version.hpp" +#include "setup/WindowsVersion.hpp" +#include "util/Enum.hpp" +#include "util/Flags.hpp" +#include "util/Types.hpp" + +FLAGS(InnoDirectoryOptions, + doUninsNeverUninstall, + doDeleteAfterInstall, + doUninsAlwaysUninstall, + doSetNTFSCompression, + doUnsetNTFSCompression, +) + +NAMED_ENUM(InnoDirectoryOptions::Enum) + +struct DirectoryEntry { + + std::string name; + std::string components; + std::string tasks; + std::string languages; + std::string check; + std::string permissions; + std::string afterInstall; + std::string beforeInstall; + + u32 attributes; + + WindowsVersion minVersion; + WindowsVersion onlyBelowVersion; + + int permission; //!< index into the permission entry list + + InnoDirectoryOptions options; + + void load(std::istream & is, const InnoVersion & version); + +}; + +#endif // INNOEXTRACT_SETUP_DIRECTORYENTRY_HPP diff --git a/src/setup/FileEntry.cpp b/src/setup/FileEntry.cpp new file mode 100644 index 0000000..6e15316 --- /dev/null +++ b/src/setup/FileEntry.cpp @@ -0,0 +1,222 @@ + +#include "setup/FileEntry.hpp" + +#include "util/LoadingUtils.hpp" +#include "util/StoredEnum.hpp" + +namespace { + +enum FileCopyMode { + cmNormal, + cmIfDoesntExist, + cmAlwaysOverwrite, + cmAlwaysSkipIfSameOrOlder, +}; + +STORED_ENUM_MAP(StoredFileCopyMode, cmNormal, + cmNormal, + cmIfDoesntExist, + cmAlwaysOverwrite, + cmAlwaysSkipIfSameOrOlder, +); + +STORED_ENUM_MAP(StoredFileType0, FileEntry::UserFile, + FileEntry::UserFile, + FileEntry::UninstExe, +); + +// win32, before 5.0.0 +STORED_ENUM_MAP(StoredFileType1, FileEntry::UserFile, + FileEntry::UserFile, + FileEntry::UninstExe, + FileEntry::RegSvrExe, +); + +} + +NAMED_ENUM(FileCopyMode) + +ENUM_NAMES(FileCopyMode, "File Copy Mode", + "normal", + "if doesn't exist", + "always overwrite", + "always skip if same or older", +) + +void FileEntry::load(std::istream & is, const InnoVersion & version) { + + options = 0; + + is >> EncodedString(source, version.codepage()); + is >> EncodedString(destination, version.codepage()); + is >> EncodedString(installFontName, version.codepage()); + if(version >= INNO_VERSION(5, 2, 5)) { + is >> EncodedString(strongAssemblyName, version.codepage()); + } else { + strongAssemblyName.clear(); + } + if(version > INNO_VERSION(1, 3, 26)) { + is >> EncodedString(components, version.codepage()); + is >> EncodedString(tasks, version.codepage()); + } else { + components.clear(), tasks.clear(); + } + if(version >= INNO_VERSION(4, 0, 1)) { + is >> EncodedString(languages, version.codepage()); + } else { + languages.clear(); + } + if(version >= INNO_VERSION(3, 0, 8)) { + is >> EncodedString(check, version.codepage()); + } else { + check.clear(); + } + if(version >= INNO_VERSION(4, 1, 0)) { + is >> EncodedString(afterInstall, version.codepage()); + is >> EncodedString(beforeInstall, version.codepage()); + } else { + afterInstall.clear(), beforeInstall.clear(); + } + + minVersion.load(is, version); + onlyBelowVersion.load(is, version); + + location = loadNumber(is); + attributes = loadNumber(is); + externalSize = (version >= INNO_VERSION(4, 0, 0)) ? loadNumber(is) : loadNumber(is); + + if(version < INNO_VERSION(3, 0, 5)) { + FileCopyMode copyMode = StoredEnum(is).get(); + // TODO this might be wrong + switch(copyMode) { + case cmNormal: options |= foPromptIfOlder; break; + case cmIfDoesntExist: options |= foOnlyIfDoesntExist | foPromptIfOlder; break; + case cmAlwaysOverwrite: options |= foIgnoreVersion | foPromptIfOlder; break; + case cmAlwaysSkipIfSameOrOlder: break; + } + } + + if(version >= INNO_VERSION(4, 1, 0)) { + permission = loadNumber(is); + } else { + permission = -1; + } + + StoredFlagReader flags; + + flags.add(foConfirmOverwrite); + flags.add(foUninsNeverUninstall); + flags.add(foRestartReplace); + flags.add(foDeleteAfterInstall); + if(version.bits != 16) { + flags.add(foRegisterServer); + flags.add(foRegisterTypeLib); + flags.add(foSharedFile); + if(version < INNO_VERSION(1, 3, 26)) { + flags.add(foIsReadmeFile); + } + } + flags.add(foCompareTimeStamp); + flags.add(foFontIsntTrueType); + flags.add(foSkipIfSourceDoesntExist); + flags.add(foOverwriteReadOnly); + if(version > INNO_VERSION(1, 2, 26)) { + flags.add(foOverwriteSameVersion); + flags.add(foCustomDestName); + flags.add(foOnlyIfDestFileExists); + } + if(version > INNO_VERSION(1, 3, 26)) { + flags.add(foNoRegError); + } + if(version >= INNO_VERSION(3, 0, 1)) { + flags.add(foUninsRestartDelete); + } + if(version >= INNO_VERSION(3, 0, 5)) { + flags.add(foOnlyIfDoesntExist); + flags.add(foIgnoreVersion); + flags.add(foPromptIfOlder); + } + if(version >= INNO_VERSION(3, 0, 8)) { + flags.add(foDontCopy); + } + if(version >= INNO_VERSION(4, 0, 5)) { + flags.add(foUninsRemoveReadOnly); + } + if(version >= INNO_VERSION(4, 1, 8)) { + flags.add(foRecurseSubDirsExternal); + } + if(version >= INNO_VERSION(4, 2, 1)) { + flags.add(foReplaceSameVersionIfContentsDiffer); + } + if(version >= INNO_VERSION(4, 2, 5)) { + flags.add(foDontVerifyChecksum); + } + if(version >= INNO_VERSION(5, 0, 3)) { + flags.add(foUninsNoSharedFilePrompt); + } + if(version >= INNO_VERSION(5, 1, 0)) { + flags.add(foCreateAllSubDirs); + } + if(version >= INNO_VERSION(5, 1, 2)) { + flags.add(fo32Bit); + flags.add(fo64Bit); + } + if(version >= INNO_VERSION(5, 2, 0)) { + flags.add(foExternalSizePreset); + flags.add(foSetNTFSCompression); + flags.add(foUnsetNTFSCompression); + } + if(version >= INNO_VERSION(5, 2, 5)) { + flags.add(foGacInstall); + } + + options = flags.get(is); + + if(version.bits == 16 || version >= INNO_VERSION(5, 0, 0)) { + type = StoredEnum(is).get(); + } else { + type = StoredEnum(is).get(); + } +} + +ENUM_NAMES(FileOptions::Enum, "File Option", + "confirm overwrite", + "never uninstall", + "restart replace", + "delete after install", + "register server", + "register type lib", + "shared file", + "compare timestamp", + "font isn't truetype", + "skip if source doesn't exist", + "overwrite readonly", + "overwrite same version", + "custom destination name", + "only if destination exists", + "no reg error", + "uninstall restart delete", + "only if doesn't exist", + "ignore version", + "prompt if older", + "don't copy", + "uninstall remove readonly", + "recurse subdirectories external", + "replace same version if contents differ", + "don't verify checksum", + "uninstall no shared file prompt", + "create all sub dirs", + "32 bit", + "64 bit", + "external size preset", + "set ntfs compression", + "unset ntfs compression", + "gac install", + "readme", +) + +ENUM_NAMES(FileEntry::Type, "File Entry Type", + "user file", + "uninstaller exe", + "reg server exe", +) diff --git a/src/setup/FileEntry.hpp b/src/setup/FileEntry.hpp new file mode 100644 index 0000000..bd4ec3a --- /dev/null +++ b/src/setup/FileEntry.hpp @@ -0,0 +1,91 @@ + +#ifndef INNOEXTRACT_SETUP_FILEENTRY_HPP +#define INNOEXTRACT_SETUP_FILEENTRY_HPP + +#include + +#include "setup/Version.hpp" +#include "setup/WindowsVersion.hpp" +#include "util/Enum.hpp" +#include "util/Flags.hpp" +#include "util/Types.hpp" + +FLAGS(FileOptions, + foConfirmOverwrite, + foUninsNeverUninstall, + foRestartReplace, + foDeleteAfterInstall, + foRegisterServer, + foRegisterTypeLib, + foSharedFile, + foCompareTimeStamp, + foFontIsntTrueType, + foSkipIfSourceDoesntExist, + foOverwriteReadOnly, + foOverwriteSameVersion, + foCustomDestName, + foOnlyIfDestFileExists, + foNoRegError, + foUninsRestartDelete, + foOnlyIfDoesntExist, + foIgnoreVersion, + foPromptIfOlder, + foDontCopy, + foUninsRemoveReadOnly, + foRecurseSubDirsExternal, + foReplaceSameVersionIfContentsDiffer, + foDontVerifyChecksum, + foUninsNoSharedFilePrompt, + foCreateAllSubDirs, + fo32Bit, + fo64Bit, + foExternalSizePreset, + foSetNTFSCompression, + foUnsetNTFSCompression, + foGacInstall, + + // obsolete options: + foIsReadmeFile, +) + +NAMED_ENUM(FileOptions::Enum) + +struct FileEntry { + + enum Type { + UserFile, + UninstExe, + RegSvrExe, + }; + + std::string source; + std::string destination; + std::string installFontName; + std::string strongAssemblyName; + std::string components; + std::string tasks; + std::string languages; + std::string check; + std::string afterInstall; + std::string beforeInstall; + + WindowsVersion minVersion; + WindowsVersion onlyBelowVersion; + + int location; //!< index into the file location entry list + u32 attributes; + u64 externalSize; + + int permission; //!< index into the permission entry list + + FileOptions options; + + Type type; + + void load(std::istream & is, const InnoVersion & version); + +}; + +NAMED_ENUM(FileEntry::Type) + +#endif // INNOEXTRACT_SETUP_FILEENTRY_HPP diff --git a/src/LanguageEntry.cpp b/src/setup/LanguageEntry.cpp similarity index 94% rename from src/LanguageEntry.cpp rename to src/setup/LanguageEntry.cpp index 61cf3b5..e9050f6 100644 --- a/src/LanguageEntry.cpp +++ b/src/setup/LanguageEntry.cpp @@ -1,10 +1,11 @@ -#include "LanguageEntry.hpp" +#include "setup/LanguageEntry.hpp" #include #include -#include "LoadingUtils.hpp" -#include "Output.hpp" + +#include "util/LoadingUtils.hpp" +#include "util/Output.hpp" void convert(iconv_t converter, const std::string & from, std::string & to); diff --git a/src/LanguageEntry.hpp b/src/setup/LanguageEntry.hpp similarity index 75% rename from src/LanguageEntry.hpp rename to src/setup/LanguageEntry.hpp index 8012a9f..00948b7 100644 --- a/src/LanguageEntry.hpp +++ b/src/setup/LanguageEntry.hpp @@ -1,9 +1,11 @@ -#ifndef INNOEXTRACT_LANGUAGEENTRY_HPP -#define INNOEXTRACT_LANGUAGEENTRY_HPP +#ifndef INNOEXTRACT_SETUP_LANGUAGEENTRY_HPP +#define INNOEXTRACT_SETUP_LANGUAGEENTRY_HPP #include -#include "Version.hpp" + +#include "setup/Version.hpp" +#include "util/Types.hpp" struct LanguageEntry { @@ -34,4 +36,4 @@ struct LanguageEntry { }; -#endif // INNOEXTRACT_LANGUAGEENTRY_HPP +#endif // INNOEXTRACT_SETUP_LANGUAGEENTRY_HPP diff --git a/src/PermissionEntry.cpp b/src/setup/PermissionEntry.cpp similarity index 71% rename from src/PermissionEntry.cpp rename to src/setup/PermissionEntry.cpp index cbac5d0..c4fc342 100644 --- a/src/PermissionEntry.cpp +++ b/src/setup/PermissionEntry.cpp @@ -1,7 +1,7 @@ -#include "PermissionEntry.hpp" +#include "setup/PermissionEntry.hpp" -#include "LoadingUtils.hpp" +#include "util/LoadingUtils.hpp" void PermissionEntry::load(std::istream & is, const InnoVersion & version) { diff --git a/src/PermissionEntry.hpp b/src/setup/PermissionEntry.hpp similarity index 51% rename from src/PermissionEntry.hpp rename to src/setup/PermissionEntry.hpp index aaa3be4..8ff2ca1 100644 --- a/src/PermissionEntry.hpp +++ b/src/setup/PermissionEntry.hpp @@ -1,9 +1,10 @@ -#ifndef INNOEXTRACT_PERMISSIONENTRY_HPP -#define INNOEXTRACT_PERMISSIONENTRY_HPP +#ifndef INNOEXTRACT_SETUP_PERMISSIONENTRY_HPP +#define INNOEXTRACT_SETUP_PERMISSIONENTRY_HPP #include -#include "Version.hpp" + +#include "setup/Version.hpp" struct PermissionEntry { @@ -15,4 +16,4 @@ struct PermissionEntry { }; -#endif // INNOEXTRACT_PERMISSIONENTRY_HPP +#endif // INNOEXTRACT_SETUP_PERMISSIONENTRY_HPP diff --git a/src/SetupComponentEntry.cpp b/src/setup/SetupComponentEntry.cpp similarity index 94% rename from src/SetupComponentEntry.cpp rename to src/setup/SetupComponentEntry.cpp index 7582198..9c7f55a 100644 --- a/src/SetupComponentEntry.cpp +++ b/src/setup/SetupComponentEntry.cpp @@ -1,8 +1,8 @@ -#include "SetupComponentEntry.hpp" +#include "setup/SetupComponentEntry.hpp" -#include "StoredEnum.hpp" -#include "LoadingUtils.hpp" +#include "util/LoadingUtils.hpp" +#include "util/StoredEnum.hpp" STORED_FLAGS_MAP(StoredSetupComponentOptions0, coFixed, diff --git a/src/SetupComponentEntry.hpp b/src/setup/SetupComponentEntry.hpp similarity index 68% rename from src/SetupComponentEntry.hpp rename to src/setup/SetupComponentEntry.hpp index 4ac1e0e..0221470 100644 --- a/src/SetupComponentEntry.hpp +++ b/src/setup/SetupComponentEntry.hpp @@ -1,12 +1,14 @@ -#ifndef INNOEXTRACT_SETUPCOMPONENTENTRY_HPP -#define INNOEXTRACT_SETUPCOMPONENTENTRY_HPP +#ifndef INNOEXTRACT_SETUP_SETUPCOMPONENTENTRY_HPP +#define INNOEXTRACT_SETUP_SETUPCOMPONENTENTRY_HPP #include -#include "Version.hpp" -#include "WindowsVersion.hpp" -#include "Flags.hpp" -#include "Enum.hpp" + +#include "setup/Version.hpp" +#include "setup/WindowsVersion.hpp" + +#include "util/Enum.hpp" +#include "util/Flags.hpp" FLAGS(SetupComponentOptions, coFixed, @@ -44,4 +46,4 @@ struct SetupComponentEntry { }; -#endif // INNOEXTRACT_SETUPCOMPONENTENTRY_HPP +#endif // INNOEXTRACT_SETUP_SETUPCOMPONENTENTRY_HPP diff --git a/src/SetupHeader.cpp b/src/setup/SetupHeader.cpp similarity index 99% rename from src/SetupHeader.cpp rename to src/setup/SetupHeader.cpp index 38b4158..6cd89d9 100644 --- a/src/SetupHeader.cpp +++ b/src/setup/SetupHeader.cpp @@ -3,11 +3,12 @@ #include #include + #include -#include "LoadingUtils.hpp" -#include "SetupHeaderFormat.hpp" -#include "Utils.hpp" +#include "setup/SetupHeaderFormat.hpp" +#include "util/LoadingUtils.hpp" +#include "util/Utils.hpp" void SetupHeader::load(std::istream & is, const InnoVersion & version) { @@ -143,7 +144,7 @@ void SetupHeader::load(std::istream & is, const InnoVersion & version) { numTypeEntries = 0, numComponentEntries = 0, numTaskEntries = 0; } - numDirEntries = loadNumber(is, version.bits); + numDirectoryEntries = loadNumber(is, version.bits); numFileEntries = loadNumber(is, version.bits); numFileLocationEntries = loadNumber(is, version.bits); numIconEntries = loadNumber(is, version.bits); diff --git a/src/SetupHeader.hpp b/src/setup/SetupHeader.hpp similarity index 80% rename from src/SetupHeader.hpp rename to src/setup/SetupHeader.hpp index 666bb9f..90a6132 100644 --- a/src/SetupHeader.hpp +++ b/src/setup/SetupHeader.hpp @@ -1,27 +1,28 @@ -#ifndef INNOEXTRACT_SETUPHEADER_HPP -#define INNOEXTRACT_SETUPHEADER_HPP +#ifndef INNOEXTRACT_SETUP_SETUPHEADER_HPP +#define INNOEXTRACT_SETUP_SETUPHEADER_HPP #include #include #include #include -#include "Types.hpp" -#include "Flags.hpp" -#include "Enum.hpp" -#include "Version.hpp" -#include "WindowsVersion.hpp" + +#include "setup/Version.hpp" +#include "setup/WindowsVersion.hpp" +#include "util/Enum.hpp" +#include "util/Flags.hpp" +#include "util/Types.hpp" typedef char MD5Digest[16]; typedef char SHA1Digest[20]; typedef char SetupSalt[8]; FLAGS(SetupHeaderOptions, - + shDisableStartupPrompt, shCreateAppDir, shAllowNoIcons, - shAlwaysRestart, // TODO missing in [3.0.0, 3.0.3) + shAlwaysRestart, shAlwaysUsePersonalGroup, shWindowVisible, shWindowShowCaption, @@ -45,67 +46,35 @@ FLAGS(SetupHeaderOptions, shDisableReadyPage, shAlwaysShowDirOnReadyPage, shAlwaysShowGroupOnReadyPage, - - // new in 2.0.18 shAllowUNCPath, - - // new in 3.0.0 shUserInfoPage, shUsePreviousUserInfo, - - // new in 3.0.1 shUninstallRestartComputer, - - // new in 3.0.3 shRestartIfNeededByRun, - - // new in 3.0.8 shShowTasksTreeLines, - - // new in 4.0.9 shAllowCancelDuringInstall, - - // new in 4.1.3 shWizardImageStretch, - - // new in 4.1.8 shAppendDefaultDirName, shAppendDefaultGroupName, - - // new in 4.2.2 shEncryptionUsed, - - // new in 5.0.4 shChangesEnvironment, - - // new in 5.1.7 - shShowUndisplayableLanguages, // TODO 5.2.5+: only if not unicode - - // new in 5.1.13 + shShowUndisplayableLanguages, shSetupLogging, - - // new in 5.2.1 shSignedUninstaller, - - // new in 5.3.8 shUsePreviousLanguage, - - // new in 5.3.9 shDisableWelcomePage, // Obsolete flags - shUninstallable, // TODO removed in 5.3.10 - shDisableDirPage, // TODO removed in 5.3.3 - shDisableProgramGroupPage, // TODO removed in 5.3.3 - shDisableAppendDir, // TODO removed in 4.1.2 - shAdminPrivilegesRequired, // TODO removed in 3.0.4 - shAlwaysCreateUninstallIcon, // TODO removed in 3.0.0 - shCreateUninstallRegKey, // TODO removed in 5.3.8 - shBzipUsed, // only in [2.0.17, 4.1.5) - shShowLanguageDialog, // only in [4.0.0, 4.0.10) - shDetectLanguageUsingLocale, // only in [4.0.1, 4.0.10) - - // only in very old versions: + shUninstallable, + shDisableDirPage, + shDisableProgramGroupPage, + shDisableAppendDir, + shAdminPrivilegesRequired, + shAlwaysCreateUninstallIcon, + shCreateUninstallRegKey, + shBzipUsed, + shShowLanguageDialog, + shDetectLanguageUsingLocale, shDisableDirExistsWarning, shBackSolid, shOverwriteUninstRegEntries, @@ -167,7 +136,7 @@ struct SetupHeader { size_t numTypeEntries; size_t numComponentEntries; size_t numTaskEntries; - size_t numDirEntries; + size_t numDirectoryEntries; size_t numFileEntries; size_t numFileLocationEntries; size_t numIconEntries; @@ -294,4 +263,4 @@ NAMED_ENUM(SetupHeader::LanguageDetection) NAMED_ENUM(SetupHeader::CompressionMethod) -#endif // INNOEXTRACT_SETUPHEADER_HPP +#endif // INNOEXTRACT_SETUP_SETUPHEADER_HPP diff --git a/src/SetupHeaderFormat.hpp b/src/setup/SetupHeaderFormat.hpp similarity index 91% rename from src/SetupHeaderFormat.hpp rename to src/setup/SetupHeaderFormat.hpp index 431d6bc..f2c1df1 100644 --- a/src/SetupHeaderFormat.hpp +++ b/src/setup/SetupHeaderFormat.hpp @@ -1,6 +1,9 @@ -#include "SetupHeader.hpp" -#include "StoredEnum.hpp" +#ifndef INNOEXTRACT_SETUP_SETUPHEADERFORMAT_HPP +#define INNOEXTRACT_SETUP_SETUPHEADERFORMAT_HPP + +#include "setup/SetupHeader.hpp" +#include "util/StoredEnum.hpp" STORED_ENUM_MAP(StoredInstallMode, SetupHeader::NormalInstallMode, SetupHeader::NormalInstallMode, @@ -101,3 +104,5 @@ STORED_ENUM_MAP(StoredDisablePage, SetupHeader::Auto, SetupHeader::No, SetupHeader::Yes ); + +#endif // INNOEXTRACT_SETUP_SETUPHEADERFORMAT_HPP diff --git a/src/SetupTaskEntry.cpp b/src/setup/SetupTaskEntry.cpp similarity index 92% rename from src/SetupTaskEntry.cpp rename to src/setup/SetupTaskEntry.cpp index 4ea726f..c47344d 100644 --- a/src/SetupTaskEntry.cpp +++ b/src/setup/SetupTaskEntry.cpp @@ -1,8 +1,8 @@ -#include "SetupTaskEntry.hpp" +#include "setup/SetupTaskEntry.hpp" -#include "LoadingUtils.hpp" -#include "StoredEnum.hpp" +#include "util/LoadingUtils.hpp" +#include "util/StoredEnum.hpp" STORED_FLAGS_MAP(StoredSetupTaskOptions0, toExclusive, diff --git a/src/SetupTaskEntry.hpp b/src/setup/SetupTaskEntry.hpp similarity index 68% rename from src/SetupTaskEntry.hpp rename to src/setup/SetupTaskEntry.hpp index b00fbe4..e89e439 100644 --- a/src/SetupTaskEntry.hpp +++ b/src/setup/SetupTaskEntry.hpp @@ -1,12 +1,13 @@ -#ifndef INNOEXTRACT_SETUPTASKENTRY_HPP -#define INNOEXTRACT_SETUPTASKENTRY_HPP +#ifndef INNOEXTRACT_SETUP_SETUPTASKENTRY_HPP +#define INNOEXTRACT_SETUP_SETUPTASKENTRY_HPP #include -#include "Version.hpp" -#include "WindowsVersion.hpp" -#include "Flags.hpp" -#include "Enum.hpp" + +#include "setup/Version.hpp" +#include "setup/WindowsVersion.hpp" +#include "util/Enum.hpp" +#include "util/Flags.hpp" FLAGS(SetupTaskOptions, toExclusive, @@ -41,4 +42,4 @@ struct SetupTaskEntry { }; -#endif // INNOEXTRACT_SETUPTASKENTRY_HPP +#endif // INNOEXTRACT_SETUP_SETUPTASKENTRY_HPP diff --git a/src/SetupTypeEntry.cpp b/src/setup/SetupTypeEntry.cpp similarity index 92% rename from src/SetupTypeEntry.cpp rename to src/setup/SetupTypeEntry.cpp index c6510f6..9643095 100644 --- a/src/SetupTypeEntry.cpp +++ b/src/setup/SetupTypeEntry.cpp @@ -1,8 +1,8 @@ -#include "SetupTypeEntry.hpp" +#include "setup/SetupTypeEntry.hpp" -#include "StoredEnum.hpp" -#include "LoadingUtils.hpp" +#include "util/LoadingUtils.hpp" +#include "util/StoredEnum.hpp" STORED_FLAGS_MAP(StoredSetupTypeOptions, CustomSetupType, diff --git a/src/SetupTypeEntry.hpp b/src/setup/SetupTypeEntry.hpp similarity index 68% rename from src/SetupTypeEntry.hpp rename to src/setup/SetupTypeEntry.hpp index 703f926..ec5ab1a 100644 --- a/src/SetupTypeEntry.hpp +++ b/src/setup/SetupTypeEntry.hpp @@ -1,12 +1,13 @@ -#ifndef INNOEXTRACT_SETUPTYPEENTRY_HPP -#define INNOEXTRACT_SETUPTYPEENTRY_HPP +#ifndef INNOEXTRACT_SETUP_SETUPTYPEENTRY_HPP +#define INNOEXTRACT_SETUP_SETUPTYPEENTRY_HPP #include -#include "Version.hpp" -#include "WindowsVersion.hpp" -#include "Flags.hpp" -#include "Enum.hpp" + +#include "setup/Version.hpp" +#include "setup/WindowsVersion.hpp" +#include "util/Enum.hpp" +#include "util/Flags.hpp" FLAGS(SetupTypeOptions, CustomSetupType, @@ -45,4 +46,4 @@ struct SetupTypeEntry { NAMED_ENUM(SetupTypeEntry::Type) -#endif // INNOEXTRACT_SETUPTYPEENTRY_HPP +#endif // INNOEXTRACT_SETUP_SETUPTYPEENTRY_HPP diff --git a/src/Version.cpp b/src/setup/Version.cpp similarity index 99% rename from src/Version.cpp rename to src/setup/Version.cpp index 994767a..a40478c 100644 --- a/src/Version.cpp +++ b/src/setup/Version.cpp @@ -1,11 +1,11 @@ -#include "Version.hpp" +#include "setup/Version.hpp" #include #include -#include "Utils.hpp" +#include typedef char StoredLegacySetupDataVersion[12]; diff --git a/src/Version.hpp b/src/setup/Version.hpp similarity index 95% rename from src/Version.hpp rename to src/setup/Version.hpp index 030351f..bdcc712 100644 --- a/src/Version.hpp +++ b/src/setup/Version.hpp @@ -1,11 +1,11 @@ -#ifndef INNOEXTRACT_VERSION_HPP -#define INNOEXTRACT_VERSION_HPP +#ifndef INNOEXTRACT_SETUP_VERSION_HPP +#define INNOEXTRACT_SETUP_VERSION_HPP #include #include -#include "Types.hpp" +#include "util/Types.hpp" typedef u32 InnoVersionConstant; #define INNO_VERSION_EXT(a, b, c, d) ((u32(a) << 24) | (u32(b) << 16) | (u32(c) << 8) | u32(d)) @@ -68,4 +68,4 @@ inline bool operator>=(InnoVersionConstant a, const InnoVersion & b) { return !o std::ostream & operator<<(std::ostream & os, const InnoVersion & version); -#endif // INNOEXTRACT_VERSION_HPP +#endif // INNOEXTRACT_SETUP_VERSION_HPP diff --git a/src/WindowsVersion.cpp b/src/setup/WindowsVersion.cpp similarity index 72% rename from src/WindowsVersion.cpp rename to src/setup/WindowsVersion.cpp index 6dff7cc..e3a5c31 100644 --- a/src/WindowsVersion.cpp +++ b/src/setup/WindowsVersion.cpp @@ -1,8 +1,8 @@ -#include "WindowsVersion.hpp" +#include "setup/WindowsVersion.hpp" -#include "LoadingUtils.hpp" -#include "Utils.hpp" +#include "util/LoadingUtils.hpp" +#include "util/Utils.hpp" const WindowsVersion WindowsVersion::none = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0 } }; @@ -41,39 +41,46 @@ struct WindowsVersionName { WindowsVersion::Version version; - bool nt; - }; WindowsVersionName windowsVersionNames[] = { { "Windows 1.0", { 1, 4, 0 } }, { "Windows 2.0", { 2, 11, 0 } }, { "Windows 3.0", { 3, 0, 0 } }, - { "Windows NT Workstation 3.5", { 3, 5, 807 }, true }, - { "Windows NT 3.1", { 3, 10, 528 }, true }, { "Windows for Workgroups 3.11", { 3, 11, 0 } }, - { "Windows NT Workstation 3.51", { 3, 51, 1057 }, true }, { "Windows 95", { 4, 0, 950 } }, - { "Windows NT Workstation 4.0", { 4, 0, 1381 }, true }, { "Windows 98", { 4, 1, 1998 } }, { "Windows 98 Second Edition", { 4, 1, 2222 } }, { "Windows ME", { 4, 90, 3000 } }, - { "Windows 2000", { 5, 0, 2195 }, true }, - { "Windows XP", { 5, 1, 2600 }, true }, - { "Windows XP x64", { 5, 2, 3790 }, true }, - { "Windows Vista", { 6, 0, 6000 }, true }, - { "Windows 7", { 6, 1, 7600 }, true } +}; + +WindowsVersionName windowsNtVersionNames[] = { + { "Windows NT Workstation 3.5", { 3, 5, 807 } }, + { "Windows NT 3.1", { 3, 10, 528 } }, + { "Windows NT Workstation 3.51", { 3, 51, 1057 } }, + { "Windows NT Workstation 4.0", { 4, 0, 1381 } }, + { "Windows 2000", { 5, 0, 2195 } }, + { "Windows XP", { 5, 1, 2600 } }, + { "Windows XP x64", { 5, 2, 3790 } }, + { "Windows Vista", { 6, 0, 6000 } }, + { "Windows 7", { 6, 1, 7600 } } }; const char * getVersionName(const WindowsVersion::Version & version, bool nt = false) { - for(size_t i = 0; i < ARRAY_SIZE(windowsVersionNames); i++) { - const WindowsVersionName & v = windowsVersionNames[i]; + + WindowsVersionName * names; + size_t count; + if(nt) { + names = windowsNtVersionNames, count = ARRAY_SIZE(windowsNtVersionNames); + } else { + names = windowsVersionNames, count = ARRAY_SIZE(windowsVersionNames); + } + + for(size_t i = 0; i < count; i++) { + const WindowsVersionName & v = names[i]; if(v.version.major != version.major || v.version.minor < version.minor) { continue; } - if(nt != v.nt) { - continue; - } return v.name; }; return NULL; diff --git a/src/WindowsVersion.hpp b/src/setup/WindowsVersion.hpp similarity index 87% rename from src/WindowsVersion.hpp rename to src/setup/WindowsVersion.hpp index b26169d..a0684bd 100644 --- a/src/WindowsVersion.hpp +++ b/src/setup/WindowsVersion.hpp @@ -1,10 +1,11 @@ -#ifndef INNOEXTRACT_SETUPVERSIONDATA_HPP -#define INNOEXTRACT_SETUPVERSIONDATA_HPP +#ifndef INNOEXTRACT_SETUP_WINDOWSVERSION_HPP +#define INNOEXTRACT_SETUP_WINDOWSVERSION_HPP #include -#include "Types.hpp" -#include "Version.hpp" + +#include "setup/Version.hpp" +#include "util/Types.hpp" struct WindowsVersion { @@ -65,4 +66,4 @@ struct WindowsVersion { std::ostream & operator<<(std::ostream & os, const WindowsVersion::Version & svd); std::ostream & operator<<(std::ostream & os, const WindowsVersion & svd); -#endif // INNOEXTRACT_SETUPVERSIONDATA_HPP +#endif // INNOEXTRACT_SETUP_WINDOWSVERSION_HPP diff --git a/src/BlockReader.cpp b/src/stream/BlockReader.cpp similarity index 88% rename from src/BlockReader.cpp rename to src/stream/BlockReader.cpp index 1c26e50..5612e81 100644 --- a/src/BlockReader.cpp +++ b/src/stream/BlockReader.cpp @@ -1,5 +1,5 @@ -#include "BlockReader.hpp" +#include "stream/BlockReader.hpp" #include @@ -8,11 +8,11 @@ #include #include -#include "Utils.hpp" -#include "ChunkFilter.hpp" -#include "LzmaFilter.hpp" -#include "LoadingUtils.hpp" -#include "Enum.hpp" +#include "stream/ChunkFilter.hpp" +#include "stream/Lzma1Filter.hpp" +#include "util/Enum.hpp" +#include "util/LoadingUtils.hpp" +#include "util/Utils.hpp" using std::cout; using std::endl; @@ -79,7 +79,7 @@ std::istream * BlockReader::get(std::istream & base, const InnoVersion & version switch(compression) { case Stored: break; case Zlib: fis->push(io::zlib_decompressor(), 8192); break; - case LZMA1: fis->push(inno_lzma_decompressor(), 8192); break; + case LZMA1: fis->push(inno_lzma1_decompressor(), 8192); break; } fis->push(inno_chunk_filter(), 4096); diff --git a/src/stream/BlockReader.hpp b/src/stream/BlockReader.hpp new file mode 100644 index 0000000..c2d1540 --- /dev/null +++ b/src/stream/BlockReader.hpp @@ -0,0 +1,17 @@ + +#ifndef INNOEXTRACT_STREAM_BLOCKREADER_HPP +#define INNOEXTRACT_STREAM_BLOCKREADER_HPP + +#include + +#include "setup/Version.hpp" + +class BlockReader { + +public: + + static std::istream * get(std::istream & base, const InnoVersion & version); + +}; + +#endif // INNOEXTRACT_STREAM_BLOCKREADER_HPP diff --git a/src/ChunkFilter.cpp b/src/stream/ChunkFilter.cpp similarity index 89% rename from src/ChunkFilter.cpp rename to src/stream/ChunkFilter.cpp index 3ebffcb..9fbed4f 100644 --- a/src/ChunkFilter.cpp +++ b/src/stream/ChunkFilter.cpp @@ -1,5 +1,5 @@ -#include "ChunkFilter.hpp" +#include "stream/ChunkFilter.hpp" #include diff --git a/src/ChunkFilter.hpp b/src/stream/ChunkFilter.hpp similarity index 90% rename from src/ChunkFilter.hpp rename to src/stream/ChunkFilter.hpp index ce884fd..6b1a46d 100644 --- a/src/ChunkFilter.hpp +++ b/src/stream/ChunkFilter.hpp @@ -1,6 +1,6 @@ -#ifndef INNOEXTRACT_CHUNKFILTER_HPP -#define INNOEXTRACT_CHUNKFILTER_HPP +#ifndef INNOEXTRACT_STREAM_CHUNKFILTER_HPP +#define INNOEXTRACT_STREAM_CHUNKFILTER_HPP #include #include @@ -9,8 +9,8 @@ #include #include -#include "Types.hpp" -#include "Output.hpp" +#include "util/Output.hpp" +#include "util/Types.hpp" class inno_chunk_filter : public boost::iostreams::multichar_input_filter { @@ -85,4 +85,4 @@ private: }; -#endif // INNOEXTRACT_CHUNKFILTER_HPP +#endif // INNOEXTRACT_STREAM_CHUNKFILTER_HPP diff --git a/src/LzmaFilter.cpp b/src/stream/Lzma1Filter.cpp similarity index 85% rename from src/LzmaFilter.cpp rename to src/stream/Lzma1Filter.cpp index d52c4ea..3029753 100644 --- a/src/LzmaFilter.cpp +++ b/src/stream/Lzma1Filter.cpp @@ -1,20 +1,20 @@ -#include "LzmaFilter.hpp" +#include "stream/Lzma1Filter.hpp" #include #include -#include "Types.hpp" +#include "util/Types.hpp" using std::cout; using std::endl; -inno_lzma_decompressor_impl::inno_lzma_decompressor_impl() : nread(0), stream(NULL), eof(false) { } +inno_lzma1_decompressor_impl::inno_lzma1_decompressor_impl() : nread(0), stream(NULL), eof(false) { } -inno_lzma_decompressor_impl::~inno_lzma_decompressor_impl() { close(); } +inno_lzma1_decompressor_impl::~inno_lzma1_decompressor_impl() { close(); } -bool inno_lzma_decompressor_impl::filter(const char * & begin_in, const char * end_in, char * & begin_out, char * end_out, bool flush) { +bool inno_lzma1_decompressor_impl::filter(const char * & begin_in, const char * end_in, char * & begin_out, char * end_out, bool flush) { (void)flush; size_t bufsize_in = (end_in - begin_in), bufsize_out = (end_out - begin_out); @@ -99,7 +99,7 @@ bool inno_lzma_decompressor_impl::filter(const char * & begin_in, const char * e return true; } -void inno_lzma_decompressor_impl::close() { +void inno_lzma1_decompressor_impl::close() { if(stream) { diff --git a/src/LzmaFilter.hpp b/src/stream/Lzma1Filter.hpp similarity index 62% rename from src/LzmaFilter.hpp rename to src/stream/Lzma1Filter.hpp index 7483948..c7cbbaa 100644 --- a/src/LzmaFilter.hpp +++ b/src/stream/Lzma1Filter.hpp @@ -1,6 +1,6 @@ -#ifndef INNOEXTRACT_LZMAFILTER_HPP -#define INNOEXTRACT_LZMAFILTER_HPP +#ifndef INNOEXTRACT_STREAM_LZMAFILTER_HPP +#define INNOEXTRACT_STREAM_LZMAFILTER_HPP #include @@ -14,15 +14,15 @@ public: }; -class inno_lzma_decompressor_impl { +class inno_lzma1_decompressor_impl { public: typedef char char_type; - inno_lzma_decompressor_impl(); + inno_lzma1_decompressor_impl(); - ~inno_lzma_decompressor_impl(); + ~inno_lzma1_decompressor_impl(); bool filter(const char * & begin_in, const char * end_in, char * & begin_out, char * end_out, bool flush); @@ -31,7 +31,7 @@ public: private: - void operator=(inno_lzma_decompressor_impl); + void operator=(inno_lzma1_decompressor_impl); size_t nread; char buf[5]; @@ -49,12 +49,12 @@ private: * is missing the uncompressed size field. The fiels that are present are encoded identically. */ template > -struct basic_inno_lzma_decompressor - : public boost::iostreams::symmetric_filter { +struct basic_inno_lzma1_decompressor + : public boost::iostreams::symmetric_filter { private: - typedef inno_lzma_decompressor_impl impl_type; + typedef inno_lzma1_decompressor_impl impl_type; typedef boost::iostreams::symmetric_filter base_type; public: @@ -62,17 +62,17 @@ public: typedef typename base_type::char_type char_type; typedef typename base_type::category category; - basic_inno_lzma_decompressor(int buffer_size = boost::iostreams::default_device_buffer_size); + basic_inno_lzma1_decompressor(int buffer_size = boost::iostreams::default_device_buffer_size); }; -typedef basic_inno_lzma_decompressor<> inno_lzma_decompressor; +typedef basic_inno_lzma1_decompressor<> inno_lzma1_decompressor; // Implementation template -basic_inno_lzma_decompressor::basic_inno_lzma_decompressor(int buffer_size) +basic_inno_lzma1_decompressor::basic_inno_lzma1_decompressor(int buffer_size) : base_type(buffer_size) { } -#endif // INNOEXTRACT_LZMAFILTER_HPP +#endif // INNOEXTRACT_STREAM_LZMAFILTER_HPP diff --git a/src/Enum.hpp b/src/util/Enum.hpp similarity index 58% rename from src/Enum.hpp rename to src/util/Enum.hpp index 9175d52..f21e426 100644 --- a/src/Enum.hpp +++ b/src/util/Enum.hpp @@ -1,12 +1,13 @@ -#ifndef INNOEXTRACT_ENUM_HPP -#define INNOEXTRACT_ENUM_HPP +#ifndef INNOEXTRACT_UTIL_ENUM_HPP +#define INNOEXTRACT_UTIL_ENUM_HPP #include #include -#include "Utils.hpp" -#include "Flags.hpp" -#include "Output.hpp" + +#include "util/Flags.hpp" +#include "util/Output.hpp" +#include "util/Utils.hpp" template struct EnumNames { @@ -39,25 +40,4 @@ struct EnumNames { } \ } -template -std::ostream & operator<<(std::ostream & os, Flags flags) { - color::shell_command prev = color::current; - if(flags) { - bool first = true; - for(size_t i = 0; i < Flags::bits; i++) { - if(flags & Enum(i)) { - if(first) { - first = false; - } else { - os << color::dim_white << ", " << prev; - } - os << Enum(i); - } - } - return os; - } else { - return os << color::dim_white << "(none)" << prev; - } -} - -#endif // INNOEXTRACT_ENUM_HPP +#endif // INNOEXTRACT_UTIL_ENUM_HPP diff --git a/src/Flags.hpp b/src/util/Flags.hpp similarity index 85% rename from src/Flags.hpp rename to src/util/Flags.hpp index b92295a..4cfface 100644 --- a/src/Flags.hpp +++ b/src/util/Flags.hpp @@ -1,8 +1,11 @@ -#ifndef INNOEXTRACT_FLAGS_HPP -#define INNOEXTRACT_FLAGS_HPP +#ifndef INNOEXTRACT_UTIL_FLAGS_HPP +#define INNOEXTRACT_UTIL_FLAGS_HPP #include +#include + +#include "util/Output.hpp" // loosely based on QFlags from Qt @@ -168,4 +171,26 @@ public: DECLARE_FLAGS_SIZE(FLAGS_ENUM(Flagname), Flagname, FLAGS_ENUM_END(Flagname)) \ DECLARE_FLAGS_OPERATORS(Flagname) -#endif // INNOEXTRACT_FLAGS_HPP + +template +std::ostream & operator<<(std::ostream & os, Flags flags) { + color::shell_command prev = color::current; + if(flags) { + bool first = true; + for(size_t i = 0; i < Flags::bits; i++) { + if(flags & Enum(i)) { + if(first) { + first = false; + } else { + os << color::dim_white << ", " << prev; + } + os << Enum(i); + } + } + return os; + } else { + return os << color::dim_white << "(none)" << prev; + } +} + +#endif // INNOEXTRACT_UTIL_FLAGS_HPP diff --git a/src/LoadingUtils.cpp b/src/util/LoadingUtils.cpp similarity index 94% rename from src/LoadingUtils.cpp rename to src/util/LoadingUtils.cpp index 0de8972..d1568df 100644 --- a/src/LoadingUtils.cpp +++ b/src/util/LoadingUtils.cpp @@ -1,5 +1,5 @@ -#include "LoadingUtils.hpp" +#include "util/LoadingUtils.hpp" #include #include @@ -8,8 +8,8 @@ #include #include -#include "Output.hpp" -#include "Utils.hpp" +#include "util/Output.hpp" +#include "util/Utils.hpp" namespace { diff --git a/src/LoadingUtils.hpp b/src/util/LoadingUtils.hpp similarity index 96% rename from src/LoadingUtils.hpp rename to src/util/LoadingUtils.hpp index b6c8b25..df43b5e 100644 --- a/src/LoadingUtils.hpp +++ b/src/util/LoadingUtils.hpp @@ -1,6 +1,6 @@ -#ifndef INNOEXTRACT_LOADINGUTILS_HPP -#define INNOEXTRACT_LOADINGUTILS_HPP +#ifndef INNOEXTRACT_UTIL_LOADINGUTILS_HPP +#define INNOEXTRACT_UTIL_LOADINGUTILS_HPP #include #include @@ -109,4 +109,4 @@ T loadNumber(std::istream & is, size_t bits) { } } -#endif // INNOEXTRACT_LOADINGUTILS_HPP +#endif // INNOEXTRACT_UTIL_LOADINGUTILS_HPP diff --git a/src/Output.cpp b/src/util/Output.cpp similarity index 69% rename from src/Output.cpp rename to src/util/Output.cpp index 799d677..a36e646 100644 --- a/src/Output.cpp +++ b/src/util/Output.cpp @@ -1,5 +1,5 @@ -#include "Output.hpp" +#include "util/Output.hpp" namespace color { diff --git a/src/Output.hpp b/src/util/Output.hpp similarity index 93% rename from src/Output.hpp rename to src/util/Output.hpp index 77ebd94..a4495c5 100644 --- a/src/Output.hpp +++ b/src/util/Output.hpp @@ -1,6 +1,6 @@ -#ifndef INNOEXTRACT_COLOROUT_HPP -#define INNOEXTRACT_COLOROUT_HPP +#ifndef INNOEXTRACT_UTIL_OUTPUT_HPP +#define INNOEXTRACT_UTIL_OUTPUT_HPP #include #include @@ -63,4 +63,4 @@ struct error_base { #define error (error_base(color::red), std::cerr) #define warning (error_base(color::yellow), std::cerr) -#endif // INNOEXTRACT_COLOROUT_HPP +#endif // INNOEXTRACT_UTIL_OUTPUT_HPP diff --git a/src/StoredEnum.hpp b/src/util/StoredEnum.hpp similarity index 93% rename from src/StoredEnum.hpp rename to src/util/StoredEnum.hpp index 33a850a..ac5de5d 100644 --- a/src/StoredEnum.hpp +++ b/src/util/StoredEnum.hpp @@ -1,15 +1,16 @@ -#ifndef INNOEXTRACT_STOREDENUM_HPP -#define INNOEXTRACT_STOREDENUM_HPP +#ifndef INNOEXTRACT_UTIL_STOREDENUM_HPP +#define INNOEXTRACT_UTIL_STOREDENUM_HPP #include + #include #include -#include "Types.hpp" -#include "LoadingUtils.hpp" -#include "Enum.hpp" -#include "Output.hpp" +#include "util/Enum.hpp" +#include "util/LoadingUtils.hpp" +#include "util/Output.hpp" +#include "util/Types.hpp" template struct EnumValueMap { @@ -168,8 +169,6 @@ public: bits |= u64(load(is)) << (i * stored_bits); } - std::cout << "read " << mappings.size() << " flags: " << std::hex << bits << std::dec << std::endl; - flag_type result = 0; for(size_t i = 0; i < mappings.size(); i++) { @@ -193,4 +192,4 @@ class StoredFlagReader > : public StoredFlagReader { }; typedef StoredBitfield<256> CharSet; -#endif // INNOEXTRACT_STOREDENUM_HPP +#endif // INNOEXTRACT_UTIL_STOREDENUM_HPP diff --git a/src/Types.hpp b/src/util/Types.hpp similarity index 70% rename from src/Types.hpp rename to src/util/Types.hpp index 2b690b3..85de303 100644 --- a/src/Types.hpp +++ b/src/util/Types.hpp @@ -1,6 +1,6 @@ -#ifndef INNOEXTRACT_TYPES_HPP -#define INNOEXTRACT_TYPES_HPP +#ifndef INNOEXTRACT_UTIL_TYPES_HPP +#define INNOEXTRACT_UTIL_TYPES_HPP #include #include @@ -18,4 +18,4 @@ typedef u32 Color; typedef std::ios_base strm; -#endif // INNOEXTRACT_TYPES_HPP +#endif // INNOEXTRACT_UTIL_TYPES_HPP diff --git a/src/Utils.cpp b/src/util/Utils.cpp similarity index 87% rename from src/Utils.cpp rename to src/util/Utils.cpp index 6272328..553fa38 100644 --- a/src/Utils.cpp +++ b/src/util/Utils.cpp @@ -1,5 +1,5 @@ -#include "Utils.hpp" +#include "util/Utils.hpp" #include diff --git a/src/Utils.hpp b/src/util/Utils.hpp similarity index 95% rename from src/Utils.hpp rename to src/util/Utils.hpp index def58ae..e456457 100644 --- a/src/Utils.hpp +++ b/src/util/Utils.hpp @@ -1,11 +1,11 @@ -#ifndef INNOEXTRACT_UTILS_HPP -#define INNOEXTRACT_UTILS_HPP +#ifndef INNOEXTRACT_UTIL_UTILS_HPP +#define INNOEXTRACT_UTIL_UTILS_HPP #include #include -#include "Output.hpp" +#include "util/Output.hpp" template inline std::istream & read(std::istream & ifs, T & data) { @@ -98,4 +98,4 @@ inline A ceildiv(A num, B denom) { return A((num + (denom - 1)) / denom); } -#endif // INNOEXTRACT_UTILS_HPP +#endif // INNOEXTRACT_UTIL_UTILS_HPP