This commit is contained in:
Igor Pavlov
2021-07-22 23:00:14 +01:00
committed by Kornel
parent 4a960640a3
commit 585698650f
619 changed files with 34904 additions and 10859 deletions

View File

@@ -88,14 +88,18 @@ STDMETHODIMP CLzmaEncoder::Code(ISequentialInStream *inStream, ISequentialOutStr
}
CAddCommon::CAddCommon(const CCompressionMethodMode &options):
_options(options),
CAddCommon::CAddCommon():
_copyCoderSpec(NULL),
_isLzmaEos(false),
_cryptoStreamSpec(NULL),
_buf(NULL),
_isLzmaEos(false)
_buf(NULL)
{}
void CAddCommon::SetOptions(const CCompressionMethodMode &options)
{
_options = options;
}
CAddCommon::~CAddCommon()
{
MidFree(_buf);
@@ -230,6 +234,11 @@ HRESULT CAddCommon::Compress(
unsigned numTestMethods = _options.MethodSequence.Size();
bool descriptorMode = outSeqMode;
// ZipCrypto without descriptor requires additional reading pass for
// inStream to calculate CRC for password check field.
// The descriptor allows to use ZipCrypto check field without CRC (InfoZip's modification).
if (!outSeqMode)
if (inSeqMode && _options.PasswordIsDefined && !_options.IsAesMode)
descriptorMode = true;
@@ -262,6 +271,15 @@ HRESULT CAddCommon::Compress(
RINOK(outStream->SetSize(0));
RINOK(outStream->Seek(0, STREAM_SEEK_SET, NULL));
}
method = _options.MethodSequence[i];
if (method == NCompressionMethod::kStore && descriptorMode)
{
// we still can create descriptor_mode archives with "Store" method, but they are not good for 100%
return E_NOTIMPL;
}
bool needCode = true;
if (_options.PasswordIsDefined)
{
@@ -314,23 +332,25 @@ HRESULT CAddCommon::Compress(
RINOK(_filterSpec->WriteHeader_Check16(outStream, (UInt16)check));
}
RINOK(_cryptoStreamSpec->SetOutStream(outStream));
RINOK(_cryptoStreamSpec->InitEncoder());
outStreamReleaser.FilterCoder = _cryptoStreamSpec;
if (method == NCompressionMethod::kStore)
{
needCode = false;
RINOK(_cryptoStreamSpec->Code(inCrcStream, outStream, NULL, NULL, progress));
}
else
{
RINOK(_cryptoStreamSpec->SetOutStream(outStream));
RINOK(_cryptoStreamSpec->InitEncoder());
outStreamReleaser.FilterCoder = _cryptoStreamSpec;
}
}
method = _options.MethodSequence[i];
switch (method)
if (needCode)
{
switch (method)
{
case NCompressionMethod::kStore:
{
if (descriptorMode)
{
// we still can create descriptor_mode archives with "Store" method, but they are not good for 100%
return E_NOTIMPL;
}
if (!_copyCoderSpec)
{
_copyCoderSpec = new NCompress::CCopyCoder;
@@ -438,15 +458,21 @@ HRESULT CAddCommon::Compress(
}
}
try {
RINOK(_compressEncoder->Code(inCrcStream, outStreamNew, NULL, NULL, progress));
} catch (...) { return E_FAIL; }
break;
}
} // switch end
if (_options.PasswordIsDefined)
{
RINOK(_cryptoStreamSpec->OutStreamFinish());
}
}
if (_options.PasswordIsDefined)
{
RINOK(_cryptoStreamSpec->OutStreamFinish());
if (_options.IsAesMode)
{
RINOK(_filterAesSpec->WriteFooter(outStream));