MCPcopy Create free account
hub / github.com/DFIR-ORC/dfir-orc / SetCompressionLevel

Method SetCompressionLevel

src/OrcLib/ZipCreate.cpp:162–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162HRESULT ZipCreate::SetCompressionLevel(const CComPtr<IOutArchive>& pArchiver, CompressionLevel level)
163{
164 HRESULT hr = E_FAIL;
165
166 Log::Debug(L"ZipCreate: {}: set compression level to {}", m_ArchiveName, static_cast<size_t>(level));
167
168 if (!pArchiver)
169 {
170 Log::Error("ZipCreate: Failed to update compression level: invalid pointer");
171 return E_POINTER;
172 }
173
174 // The dictionary and thread overrides only apply to the LZMA2-based 7z format. The Zip format
175 // uses Deflate (fixed 32 KiB window) and would not benefit from (and could reject) the 'd' property.
176 const bool is7z = (m_Format == ArchiveFormat::SevenZip);
177 const wchar_t* dictionarySize = is7z ? DictionarySizeForLevel(level) : nullptr;
178 const UInt32 threadCount = is7z ? ThreadCountForLevel(level) : 0;
179
180 const wchar_t* names[3];
181 CPropVariant values[3];
182 UInt32 numProps = 0;
183
184 names[numProps] = L"x";
185 values[numProps] = static_cast<UInt32>(level);
186 ++numProps;
187
188 if (dictionarySize)
189 {
190 names[numProps] = L"d";
191 values[numProps] = dictionarySize;
192 ++numProps;
193 }
194
195 if (threadCount)
196 {
197 names[numProps] = L"mt";
198 values[numProps] = static_cast<UInt32>(threadCount);
199 ++numProps;
200 }
201
202 CComPtr<ISetProperties> setter;
203 if (FAILED(hr = pArchiver->QueryInterface(IID_ISetProperties, reinterpret_cast<void**>(&setter))))
204 {
205 Log::Error("Failed to retrieve IID_ISetProperties [{}]", SystemError(hr));
206 return hr;
207 }
208
209 if (FAILED(hr = setter->SetProperties(names, values, numProps)))
210 {
211 Log::Error("Failed to set properties [{}]", SystemError(hr));
212 return hr;
213 }
214
215 return S_OK;
216}
217
218STDMETHODIMP ZipCreate::InitArchive(const fs::path& path, OrcArchive::ArchiveCallback pCallback)
219{

Callers 2

UpdateResourcesMethod · 0.45
runMethod · 0.45

Calls 7

DictionarySizeForLevelFunction · 0.85
ThreadCountForLevelFunction · 0.85
SystemErrorFunction · 0.85
DebugFunction · 0.50
ErrorFunction · 0.50
QueryInterfaceMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected