mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-12 03:09:57 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -11,6 +11,7 @@
|
||||
#include "../../Common/LimitedStreams.h"
|
||||
#include "../../Common/InOutTempBuffer.h"
|
||||
#include "../../Common/StreamObjects.h"
|
||||
#include "../Common/FilterCoder.h"
|
||||
|
||||
#ifdef COMPRESS_COPY
|
||||
static NArchive::N7z::CMethodID k_Copy = { { 0x0 }, 1 };
|
||||
@@ -38,11 +39,23 @@ static NArchive::N7z::CMethodID k_BCJ2 = { { 0x3, 0x3, 0x1, 0x1B }, 4 };
|
||||
#endif
|
||||
|
||||
#ifdef COMPRESS_DEFLATE
|
||||
#ifndef COMPRESS_DEFLATE_ENCODER
|
||||
#define COMPRESS_DEFLATE_ENCODER
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef COMPRESS_DEFLATE_ENCODER
|
||||
#include "../../Compress/Deflate/DeflateEncoder.h"
|
||||
static NArchive::N7z::CMethodID k_Deflate = { { 0x4, 0x1, 0x8 }, 3 };
|
||||
#endif
|
||||
|
||||
#ifdef COMPRESS_BZIP2
|
||||
#ifndef COMPRESS_BZIP2_ENCODER
|
||||
#define COMPRESS_BZIP2_ENCODER
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef COMPRESS_BZIP2_ENCODER
|
||||
#include "../../Compress/BZip2/BZip2Encoder.h"
|
||||
static NArchive::N7z::CMethodID k_BZip2 = { { 0x4, 0x2, 0x2 }, 3 };
|
||||
#endif
|
||||
@@ -98,16 +111,12 @@ static void ConvertBindInfoToFolderItemInfo(const NCoderMixer2::CBindInfo &bindI
|
||||
folder.Coders.Add(coderInfo);
|
||||
}
|
||||
for (i = 0; i < bindInfo.InStreams.Size(); i++)
|
||||
{
|
||||
CPackStreamInfo packStreamInfo;
|
||||
packStreamInfo.Index = bindInfo.InStreams[i];
|
||||
folder.PackStreams.Add(packStreamInfo);
|
||||
}
|
||||
folder.PackStreams.Add(bindInfo.InStreams[i]);
|
||||
}
|
||||
|
||||
HRESULT CEncoder::CreateMixerCoder()
|
||||
{
|
||||
_mixerCoderSpec = new NCoderMixer2::CCoderMixer2;
|
||||
_mixerCoderSpec = new NCoderMixer2::CCoderMixer2MT;
|
||||
_mixerCoder = _mixerCoderSpec;
|
||||
_mixerCoderSpec->SetBindInfo(_bindInfo);
|
||||
for (int i = 0; i < _options.Methods.Size(); i++)
|
||||
@@ -116,6 +125,7 @@ HRESULT CEncoder::CreateMixerCoder()
|
||||
_codersInfo.Add(CCoderInfo());
|
||||
CCoderInfo &encodingInfo = _codersInfo.Back();
|
||||
CMyComPtr<ICompressCoder> encoder;
|
||||
CMyComPtr<ICompressFilter> filter;
|
||||
CMyComPtr<ICompressCoder2> encoder2;
|
||||
|
||||
if (methodFull.IsSimpleCoder())
|
||||
@@ -132,7 +142,7 @@ HRESULT CEncoder::CreateMixerCoder()
|
||||
|
||||
#ifdef COMPRESS_BCJ_X86
|
||||
if (methodFull.MethodID == k_BCJ_X86)
|
||||
encoder = new CBCJ_x86_Encoder;
|
||||
filter = new CBCJ_x86_Encoder;
|
||||
#endif
|
||||
|
||||
#ifdef COMPRESS_COPY
|
||||
@@ -140,25 +150,32 @@ HRESULT CEncoder::CreateMixerCoder()
|
||||
encoder = new NCompress::CCopyCoder;
|
||||
#endif
|
||||
|
||||
#ifdef COMPRESS_BZIP2
|
||||
#ifdef COMPRESS_BZIP2_ENCODER
|
||||
if (methodFull.MethodID == k_BZip2)
|
||||
encoder = new NCompress::NBZip2::CEncoder;
|
||||
#endif
|
||||
|
||||
#ifdef COMPRESS_DEFLATE
|
||||
#ifdef COMPRESS_DEFLATE_ENCODER
|
||||
if (methodFull.MethodID == k_Deflate)
|
||||
encoder = new NCompress::NDeflate::NEncoder::CCOMCoder;
|
||||
#endif
|
||||
|
||||
#ifdef CRYPTO_7ZAES
|
||||
if (methodFull.MethodID == k_AES)
|
||||
encoder = new NCrypto::NSevenZ::CEncoder;
|
||||
filter = new NCrypto::NSevenZ::CEncoder;
|
||||
#endif
|
||||
|
||||
if (filter)
|
||||
{
|
||||
CFilterCoder *coderSpec = new CFilterCoder;
|
||||
encoder = coderSpec;
|
||||
coderSpec->Filter = filter;
|
||||
}
|
||||
|
||||
#ifndef EXCLUDE_COM
|
||||
if (encoder == 0)
|
||||
{
|
||||
RINOK(_libraries.CreateCoder(methodFull.FilePath,
|
||||
RINOK(_libraries.CreateCoderSpec(methodFull.FilePath,
|
||||
methodFull.EncoderClassID, &encoder));
|
||||
}
|
||||
#endif
|
||||
@@ -189,29 +206,36 @@ HRESULT CEncoder::CreateMixerCoder()
|
||||
|
||||
if (methodFull.CoderProperties.Size() > 0)
|
||||
{
|
||||
std::vector<NWindows::NCOM::CPropVariant> properties;
|
||||
std::vector<PROPID> propIDs;
|
||||
INT32 numProperties = methodFull.CoderProperties.Size();
|
||||
for (int i = 0; i < numProperties; i++)
|
||||
CRecordVector<PROPID> propIDs;
|
||||
int numProperties = methodFull.CoderProperties.Size();
|
||||
NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties];
|
||||
try
|
||||
{
|
||||
const CProperty &property = methodFull.CoderProperties[i];
|
||||
propIDs.push_back(property.PropID);
|
||||
properties.push_back(property.Value);
|
||||
}
|
||||
CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
|
||||
if (methodFull.IsSimpleCoder())
|
||||
{
|
||||
RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties,
|
||||
for (int i = 0; i < numProperties; i++)
|
||||
{
|
||||
const CProperty &property = methodFull.CoderProperties[i];
|
||||
propIDs.Add(property.PropID);
|
||||
values[i] = property.Value;
|
||||
}
|
||||
CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
|
||||
if (methodFull.IsSimpleCoder())
|
||||
{
|
||||
RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties,
|
||||
&setCoderProperties));
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOK(encoder2.QueryInterface(IID_ICompressSetCoderProperties,
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOK(encoder2.QueryInterface(IID_ICompressSetCoderProperties,
|
||||
&setCoderProperties));
|
||||
}
|
||||
RINOK(setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties));
|
||||
}
|
||||
|
||||
RINOK(setCoderProperties->SetCoderProperties(&propIDs.front(),
|
||||
&properties.front(), numProperties));
|
||||
catch(...)
|
||||
{
|
||||
delete []values;
|
||||
throw;
|
||||
}
|
||||
delete []values;
|
||||
}
|
||||
|
||||
CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
|
||||
@@ -234,7 +258,7 @@ HRESULT CEncoder::CreateMixerCoder()
|
||||
outStreamSpec->Init();
|
||||
writeCoderProperties->WriteCoderProperties(outStream);
|
||||
|
||||
UINT32 size = outStreamSpec->GetSize();
|
||||
UInt32 size = outStreamSpec->GetSize();
|
||||
|
||||
// encodingInfo.Properties.SetCapacity(size);
|
||||
if (encodingInfo.AltCoders.Size() == 0)
|
||||
@@ -257,9 +281,17 @@ HRESULT CEncoder::CreateMixerCoder()
|
||||
|
||||
if (cryptoSetPassword)
|
||||
{
|
||||
CByteBuffer buffer;
|
||||
const UInt32 sizeInBytes = _options.Password.Length() * 2;
|
||||
buffer.SetCapacity(sizeInBytes);
|
||||
for (int i = 0; i < _options.Password.Length(); i++)
|
||||
{
|
||||
wchar_t c = _options.Password[i];
|
||||
((Byte *)buffer)[i * 2] = (Byte)c;
|
||||
((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
|
||||
}
|
||||
RINOK(cryptoSetPassword->CryptoSetPassword(
|
||||
(const BYTE *)(const wchar_t *)_options.Password,
|
||||
_options.Password.Length() * sizeof(wchar_t)));
|
||||
(const Byte *)buffer, sizeInBytes));
|
||||
}
|
||||
|
||||
// public ICompressWriteCoderProperties,
|
||||
@@ -276,10 +308,10 @@ HRESULT CEncoder::CreateMixerCoder()
|
||||
}
|
||||
|
||||
HRESULT CEncoder::Encode(ISequentialInStream *inStream,
|
||||
const UINT64 *inStreamSize,
|
||||
const UInt64 *inStreamSize,
|
||||
CFolder &folderItem,
|
||||
ISequentialOutStream *outStream,
|
||||
CRecordVector<UINT64> &packSizes,
|
||||
CRecordVector<UInt64> &packSizes,
|
||||
ICompressProgressInfo *compressProgress)
|
||||
{
|
||||
if (_mixerCoderSpec == NULL)
|
||||
@@ -315,13 +347,13 @@ HRESULT CEncoder::Encode(ISequentialInStream *inStream,
|
||||
|
||||
if (_bindInfo.InStreams.IsEmpty())
|
||||
return E_FAIL;
|
||||
UINT32 mainCoderIndex, mainStreamIndex;
|
||||
UInt32 mainCoderIndex, mainStreamIndex;
|
||||
_bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);
|
||||
_mixerCoderSpec->SetProgressCoderIndex(mainCoderIndex);
|
||||
if (inStreamSize != NULL)
|
||||
{
|
||||
CRecordVector<const UINT64 *> sizePointers;
|
||||
for (int i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)
|
||||
CRecordVector<const UInt64 *> sizePointers;
|
||||
for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)
|
||||
if (i == mainStreamIndex)
|
||||
sizePointers.Add(inStreamSize);
|
||||
else
|
||||
@@ -330,7 +362,7 @@ HRESULT CEncoder::Encode(ISequentialInStream *inStream,
|
||||
}
|
||||
|
||||
|
||||
// UINT64 outStreamStartPos;
|
||||
// UInt64 outStreamStartPos;
|
||||
// RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));
|
||||
|
||||
CSequentialInStreamSizeCount2 *inStreamSizeCountSpec =
|
||||
@@ -367,11 +399,11 @@ HRESULT CEncoder::Encode(ISequentialInStream *inStream,
|
||||
packSizes.Add(inOutTempBuffer.GetDataSize());
|
||||
}
|
||||
|
||||
for (i = 0; i < _bindReverseConverter->NumSrcInStreams; i++)
|
||||
for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)
|
||||
{
|
||||
int binder = _bindInfo.FindBinderForInStream(
|
||||
_bindReverseConverter->DestOutToSrcInMap[i]);
|
||||
UINT64 streamSize;
|
||||
UInt64 streamSize;
|
||||
if (binder < 0)
|
||||
streamSize = inStreamSizeCountSpec->GetSize();
|
||||
else
|
||||
@@ -433,7 +465,7 @@ CEncoder::CEncoder(const CCompressionMethodMode &options):
|
||||
else
|
||||
{
|
||||
|
||||
UINT32 numInStreams = 0, numOutStreams = 0;
|
||||
UInt32 numInStreams = 0, numOutStreams = 0;
|
||||
int i;
|
||||
for (i = 0; i < options.Methods.Size(); i++)
|
||||
{
|
||||
@@ -452,7 +484,7 @@ CEncoder::CEncoder(const CCompressionMethodMode &options):
|
||||
}
|
||||
else
|
||||
_bindInfo.OutStreams.Insert(0, numOutStreams);
|
||||
for (UINT32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)
|
||||
for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)
|
||||
_bindInfo.OutStreams.Add(numOutStreams + j);
|
||||
}
|
||||
|
||||
@@ -464,7 +496,7 @@ CEncoder::CEncoder(const CCompressionMethodMode &options):
|
||||
|
||||
if (!options.Binds.IsEmpty())
|
||||
{
|
||||
for (int i = 0; i < options.Binds.Size(); i++)
|
||||
for (i = 0; i < options.Binds.Size(); i++)
|
||||
{
|
||||
NCoderMixer2::CBindPair bindPair;
|
||||
const CBind &bind = options.Binds[i];
|
||||
@@ -472,12 +504,12 @@ CEncoder::CEncoder(const CCompressionMethodMode &options):
|
||||
bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;
|
||||
_bindInfo.BindPairs.Add(bindPair);
|
||||
}
|
||||
for (i = 0; i < numOutStreams; i++)
|
||||
for (i = 0; i < (int)numOutStreams; i++)
|
||||
if (_bindInfo.FindBinderForOutStream(i) == -1)
|
||||
_bindInfo.OutStreams.Add(i);
|
||||
}
|
||||
|
||||
for (i = 0; i < numInStreams; i++)
|
||||
for (i = 0; i < (int)numInStreams; i++)
|
||||
if (_bindInfo.FindBinderForInStream(i) == -1)
|
||||
_bindInfo.InStreams.Add(i);
|
||||
|
||||
@@ -488,9 +520,9 @@ CEncoder::CEncoder(const CCompressionMethodMode &options):
|
||||
int inIndex = _bindInfo.InStreams[0];
|
||||
while (true)
|
||||
{
|
||||
UINT32 coderIndex, coderStreamIndex;
|
||||
UInt32 coderIndex, coderStreamIndex;
|
||||
_bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);
|
||||
UINT32 outIndex = _bindInfo.GetCoderStartOutStream(coderIndex);
|
||||
UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);
|
||||
int binder = _bindInfo.FindBinderForOutStream(outIndex);
|
||||
if (binder >= 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user