Skip to content

Commit

Permalink
Add options for "solid"
Browse files Browse the repository at this point in the history
  • Loading branch information
thebrandre committed Feb 18, 2024
1 parent 12fe17f commit b07abcb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 15 deletions.
35 changes: 30 additions & 5 deletions ArchiveProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <algorithm>
#include <7zip/Archive/IArchive.h>

#include "boost/nowide/convert.hpp"

void Archive7zProperties::applyProperties(IUnknown* Archive)
{
CMyComPtr<ISetProperties> SetProperties = [&]
Expand Down Expand Up @@ -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<UINT>(Value.size()));
return *this;
}
27 changes: 19 additions & 8 deletions ArchiveProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename... PropertyTypes>
static void set(IUnknown* Archive, PropertyTypes... Values)
Expand All @@ -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<std::wstring> Properties;
std::vector<PROPVARIANT> Values;
Expand Down
9 changes: 7 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ void compressStuff(ArchiveFactory& Factory)
{
const unsigned ArchiveFormatId = 0x07;
CMyComPtr<IOutArchive> 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";
Expand Down

0 comments on commit b07abcb

Please sign in to comment.