From b07abcb83136dcb0f66a099a28f04247a67e25fa Mon Sep 17 00:00:00 2001 From: Andre Brand Date: Sun, 18 Feb 2024 13:07:27 +0100 Subject: [PATCH] Add options for "solid" --- ArchiveProperties.cpp | 35 ++++++++++++++++++++++++++++++----- ArchiveProperties.h | 27 +++++++++++++++++++-------- main.cpp | 9 +++++++-- 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/ArchiveProperties.cpp b/ArchiveProperties.cpp index 9e94345..784f14a 100644 --- a/ArchiveProperties.cpp +++ b/ArchiveProperties.cpp @@ -3,6 +3,8 @@ #include #include <7zip/Archive/IArchive.h> +#include "boost/nowide/convert.hpp" + void Archive7zProperties::applyProperties(IUnknown* Archive) { CMyComPtr SetProperties = [&] @@ -48,22 +50,45 @@ Archive7zProperties& Archive7zProperties::set(HashSize Value) return set(L"crc", Value.Value); } -Archive7zProperties& Archive7zProperties::set(const wchar_t* Name, bool Value) +Archive7zProperties& Archive7zProperties::set(Solid Value) +{ + return set(L"s", Value.Value); +} + +Archive7zProperties& Archive7zProperties::set(SolidOptions Value) +{ + set(L"s", boost::nowide::widen(Value.Value)); + return *this; +} + +PROPVARIANT& Archive7zProperties::emplace_back(std::wstring_view Name) { Properties.emplace_back(Name); auto& PropValue = Values.emplace_back(); PropVariantClear(&PropValue); + return PropValue; +} + +Archive7zProperties& Archive7zProperties::set(std::wstring_view Name, bool Value) +{ + auto& PropValue = emplace_back(Name); PropValue.vt = VT_BOOL; PropValue.boolVal = Value ? VARIANT_TRUE : VARIANT_FALSE; return *this; } -Archive7zProperties& Archive7zProperties::set(const wchar_t* Name, std::uint32_t Value) +Archive7zProperties& Archive7zProperties::set(std::wstring_view Name, std::uint32_t Value) { - Properties.emplace_back(Name); - auto& PropValue = Values.emplace_back(); - PropVariantClear(&PropValue); + auto& PropValue = emplace_back(Name); PropValue.vt = VT_UI4; PropValue.ulVal = Value; return *this; } + +Archive7zProperties& Archive7zProperties::set(std::wstring_view Name, std::wstring_view Value) +{ + auto& PropValue = emplace_back(Name); + PropValue.vt = VT_BSTR; + PropValue.bstrVal = ::SysAllocStringLen(Value.data(), static_cast(Value.size())); + return *this; +} diff --git a/ArchiveProperties.h b/ArchiveProperties.h index 5980f64..bc3ff96 100644 --- a/ArchiveProperties.h +++ b/ArchiveProperties.h @@ -7,12 +7,19 @@ class Archive7zProperties { public: - struct CompressHeaders {bool Value;}; - struct CompressHeadersFull {bool Value;}; - struct EncryptHeaders {bool Value;}; - struct Level {std::uint32_t Value;}; - struct NumberOfThreads {std::uint32_t Value;}; - struct HashSize {std::uint32_t Value;}; + struct CompressHeaders { bool Value; }; + struct CompressHeadersFull { bool Value; }; + struct EncryptHeaders { bool Value; }; + struct Level { std::uint32_t Value; }; + struct NumberOfThreads { std::uint32_t Value; }; + struct HashSize { std::uint32_t Value; }; + + // No idea how to use that. It does not seem to have any effect on the archive. + // It resets the solid extension to false, block size, and the number of solid files + struct Solid { bool Value; }; + // format "e2g100f" = extension enabled, 2 GB block size, number of solid files = 100. + // But it is still marked as "not solid" in the command line. + struct SolidOptions { std::u8string_view Value; }; template static void set(IUnknown* Archive, PropertyTypes... Values) @@ -30,9 +37,13 @@ class Archive7zProperties Archive7zProperties& set(Level Value); Archive7zProperties& set(NumberOfThreads Value); Archive7zProperties& set(HashSize Value); + Archive7zProperties& set(Solid Value); + Archive7zProperties& set(SolidOptions Value); - Archive7zProperties& set(const wchar_t* Name, bool Value); - Archive7zProperties& set(const wchar_t* Name, std::uint32_t Value); + PROPVARIANT& emplace_back(std::wstring_view Name); + Archive7zProperties& set(std::wstring_view Name, bool Value); + Archive7zProperties& set(std::wstring_view Name, std::uint32_t Value); + Archive7zProperties& set(std::wstring_view Name, std::wstring_view Value); std::vector Properties; std::vector Values; diff --git a/main.cpp b/main.cpp index d09c2d3..0bfaac5 100644 --- a/main.cpp +++ b/main.cpp @@ -75,8 +75,13 @@ void compressStuff(ArchiveFactory& Factory) { const unsigned ArchiveFormatId = 0x07; CMyComPtr OutArchive = Factory.createOutArchive(ArchiveFormatId); - Archive7zProperties::set(OutArchive, Archive7zProperties::EncryptHeaders{true}, Archive7zProperties::NumberOfThreads{1}); - + Archive7zProperties::set(OutArchive, + //Archive7zProperties::EncryptHeaders{ true }, + Archive7zProperties::NumberOfThreads{ 1 }, + Archive7zProperties::SolidOptions{ u8"e2g" } + //Archive7zProperties::Solid{ true } + ); + InMemoryArchive TempArchive; TempArchive.Password = u8"Password"; unsigned char FileContent[] = "ASCII and stuff";