-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for setting archive properties
- Loading branch information
1 parent
a867cd9
commit 12fe17f
Showing
4 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "ArchiveProperties.h" | ||
|
||
#include <algorithm> | ||
#include <7zip/Archive/IArchive.h> | ||
|
||
void Archive7zProperties::applyProperties(IUnknown* Archive) | ||
{ | ||
CMyComPtr<ISetProperties> SetProperties = [&] | ||
{ | ||
void* Interface{}; | ||
Archive->QueryInterface(IID_ISetProperties, &Interface); | ||
return static_cast<ISetProperties*>(Interface); | ||
}(); | ||
|
||
std::vector<const wchar_t*> PropKeys(Properties.size()); | ||
std::ranges::transform(Properties, PropKeys.begin(), &std::wstring::c_str); | ||
|
||
SetProperties->SetProperties(PropKeys.data(), Values.data(), PropKeys.size()); | ||
} | ||
|
||
Archive7zProperties& Archive7zProperties::set(CompressHeaders Value) | ||
{ | ||
return set(L"hc", Value.Value); | ||
} | ||
|
||
Archive7zProperties& Archive7zProperties::set(CompressHeadersFull Value) | ||
{ | ||
return set(L"hcf", Value.Value); | ||
} | ||
|
||
Archive7zProperties& Archive7zProperties::set(EncryptHeaders Value) | ||
{ | ||
return set(L"he", Value.Value); | ||
} | ||
|
||
Archive7zProperties& Archive7zProperties::set(Level Value) | ||
{ | ||
return set(L"x", Value.Value); | ||
} | ||
|
||
Archive7zProperties& Archive7zProperties::set(NumberOfThreads Value) | ||
{ | ||
return set(L"mt", Value.Value); | ||
} | ||
|
||
Archive7zProperties& Archive7zProperties::set(HashSize Value) | ||
{ | ||
return set(L"crc", Value.Value); | ||
} | ||
|
||
Archive7zProperties& Archive7zProperties::set(const wchar_t* Name, bool Value) | ||
{ | ||
Properties.emplace_back(Name); | ||
auto& PropValue = Values.emplace_back(); | ||
PropVariantClear(&PropValue); | ||
PropValue.vt = VT_BOOL; | ||
PropValue.boolVal = Value ? VARIANT_TRUE : VARIANT_FALSE; | ||
return *this; | ||
} | ||
|
||
Archive7zProperties& Archive7zProperties::set(const wchar_t* Name, std::uint32_t Value) | ||
{ | ||
Properties.emplace_back(Name); | ||
auto& PropValue = Values.emplace_back(); | ||
PropVariantClear(&PropValue); | ||
PropValue.vt = VT_UI4; | ||
PropValue.ulVal = Value; | ||
return *this; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
#include <Common/MyCom.h> | ||
|
||
|
||
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;}; | ||
|
||
template<typename... PropertyTypes> | ||
static void set(IUnknown* Archive, PropertyTypes... Values) | ||
{ | ||
Archive7zProperties Props; | ||
(Props.set(Values), ...); | ||
Props.applyProperties(Archive); | ||
} | ||
|
||
private: | ||
void applyProperties(IUnknown* Archive); | ||
Archive7zProperties& set(CompressHeaders Value); | ||
Archive7zProperties& set(CompressHeadersFull Value); | ||
Archive7zProperties& set(EncryptHeaders Value); | ||
Archive7zProperties& set(Level Value); | ||
Archive7zProperties& set(NumberOfThreads Value); | ||
Archive7zProperties& set(HashSize Value); | ||
|
||
Archive7zProperties& set(const wchar_t* Name, bool Value); | ||
Archive7zProperties& set(const wchar_t* Name, std::uint32_t Value); | ||
|
||
std::vector<std::wstring> Properties; | ||
std::vector<PROPVARIANT> Values; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters