Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Archive/Common')
-rw-r--r--CPP/7zip/Archive/Common/CoderMixer.cpp19
-rw-r--r--CPP/7zip/Archive/Common/CoderMixer.h32
-rw-r--r--CPP/7zip/Archive/Common/CoderMixer2MT.cpp254
-rw-r--r--CPP/7zip/Archive/Common/CoderMixer2MT.h77
-rw-r--r--CPP/7zip/Archive/Common/CoderMixer2ST.cpp562
-rw-r--r--CPP/7zip/Archive/Common/CoderMixer2ST.h129
-rw-r--r--CPP/7zip/Archive/Common/CoderMixerMT.cpp99
-rw-r--r--CPP/7zip/Archive/Common/CoderMixerMT.h70
-rw-r--r--CPP/7zip/Archive/Common/FindSignature.cpp2
-rw-r--r--CPP/7zip/Archive/Common/FindSignature.h4
10 files changed, 4 insertions, 1244 deletions
diff --git a/CPP/7zip/Archive/Common/CoderMixer.cpp b/CPP/7zip/Archive/Common/CoderMixer.cpp
deleted file mode 100644
index a19f0457..00000000
--- a/CPP/7zip/Archive/Common/CoderMixer.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// CoderMixer.cpp
-
-#include "StdAfx.h"
-
-#include "CoderMixer.h"
-
-namespace NCoderMixer {
-
-void CCoderInfo::SetCoderInfo(const UInt64 *inSize, const UInt64 *outSize)
-{
- InSizeAssigned = (inSize != 0);
- if (InSizeAssigned)
- InSizeValue = *inSize;
- OutSizeAssigned = (outSize != 0);
- if (OutSizeAssigned)
- OutSizeValue = *outSize;
-}
-
-}
diff --git a/CPP/7zip/Archive/Common/CoderMixer.h b/CPP/7zip/Archive/Common/CoderMixer.h
deleted file mode 100644
index 6379dd80..00000000
--- a/CPP/7zip/Archive/Common/CoderMixer.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// CoderMixer.h
-
-#ifndef __CODER_MIXER_H
-#define __CODER_MIXER_H
-
-#include "../../../Common/MyCom.h"
-#include "../../ICoder.h"
-
-namespace NCoderMixer {
-
-struct CCoderInfo
-{
- CMyComPtr<ICompressCoder> Coder;
- CMyComPtr<ISequentialInStream> InStream;
- CMyComPtr<ISequentialOutStream> OutStream;
- CMyComPtr<ICompressProgressInfo> Progress;
-
- UInt64 InSizeValue;
- UInt64 OutSizeValue;
- bool InSizeAssigned;
- bool OutSizeAssigned;
-
- void ReInit()
- {
- InSizeAssigned = OutSizeAssigned = false;
- }
-
- void SetCoderInfo(const UInt64 *inSize, const UInt64 *outSize);
-};
-
-}
-#endif
diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
deleted file mode 100644
index c0139862..00000000
--- a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
+++ /dev/null
@@ -1,254 +0,0 @@
-// CoderMixer2MT.cpp
-
-#include "StdAfx.h"
-
-#include "CoderMixer2MT.h"
-
-namespace NCoderMixer2 {
-
-void CCoderMT::Execute() { Code(NULL); }
-
-void CCoderMT::Code(ICompressProgressInfo *progress)
-{
- unsigned numInStreams = EncodeMode ? 1 : NumStreams;
- unsigned numOutStreams = EncodeMode ? NumStreams : 1;
-
- InStreamPointers.ClearAndReserve(numInStreams);
- OutStreamPointers.ClearAndReserve(numOutStreams);
-
- unsigned i;
-
- for (i = 0; i < numInStreams; i++)
- InStreamPointers.AddInReserved((ISequentialInStream *)InStreams[i]);
-
- for (i = 0; i < numOutStreams; i++)
- OutStreamPointers.AddInReserved((ISequentialOutStream *)OutStreams[i]);
-
- // we suppose that UnpackSizePointer and PackSizePointers contain correct pointers.
- /*
- if (UnpackSizePointer)
- UnpackSizePointer = &UnpackSize;
- for (i = 0; i < NumStreams; i++)
- if (PackSizePointers[i])
- PackSizePointers[i] = &PackSizes[i];
- */
-
- if (Coder)
- Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],
- EncodeMode ? UnpackSizePointer : PackSizePointers[0],
- EncodeMode ? PackSizePointers[0] : UnpackSizePointer,
- progress);
- else
- Result = Coder2->Code(
- &InStreamPointers.Front(), EncodeMode ? &UnpackSizePointer : &PackSizePointers.Front(), numInStreams,
- &OutStreamPointers.Front(), EncodeMode ? &PackSizePointers.Front(): &UnpackSizePointer, numOutStreams,
- progress);
-
- InStreamPointers.Clear();
- OutStreamPointers.Clear();
-
- for (i = 0; i < InStreams.Size(); i++)
- InStreams[i].Release();
- for (i = 0; i < OutStreams.Size(); i++)
- OutStreams[i].Release();
-}
-
-HRESULT CMixerMT::SetBindInfo(const CBindInfo &bindInfo)
-{
- CMixer::SetBindInfo(bindInfo);
-
- _streamBinders.Clear();
- FOR_VECTOR (i, _bi.Bonds)
- {
- RINOK(_streamBinders.AddNew().CreateEvents());
- }
- return S_OK;
-}
-
-void CMixerMT::AddCoder(ICompressCoder *coder, ICompressCoder2 *coder2, bool isFilter)
-{
- const CCoderStreamsInfo &c = _bi.Coders[_coders.Size()];
- CCoderMT &c2 = _coders.AddNew();
- c2.NumStreams = c.NumStreams;
- c2.EncodeMode = EncodeMode;
- c2.Coder = coder;
- c2.Coder2 = coder2;
- IsFilter_Vector.Add(isFilter);
-}
-
-CCoder &CMixerMT::GetCoder(unsigned index)
-{
- return _coders[index];
-}
-
-void CMixerMT::ReInit()
-{
- FOR_VECTOR (i, _streamBinders)
- _streamBinders[i].ReInit();
-}
-
-void CMixerMT::SelectMainCoder(bool useFirst)
-{
- unsigned ci = _bi.UnpackCoder;
-
- if (!useFirst)
- for (;;)
- {
- if (_coders[ci].NumStreams != 1)
- break;
- if (!IsFilter_Vector[ci])
- break;
-
- UInt32 st = _bi.Coder_to_Stream[ci];
- if (_bi.IsStream_in_PackStreams(st))
- break;
- int bond = _bi.FindBond_for_PackStream(st);
- if (bond < 0)
- throw 20150213;
- ci = _bi.Bonds[bond].UnpackIndex;
- }
-
- MainCoderIndex = ci;
-}
-
-HRESULT CMixerMT::Init(ISequentialInStream * const *inStreams, ISequentialOutStream * const *outStreams)
-{
- unsigned i;
-
- for (i = 0; i < _coders.Size(); i++)
- {
- CCoderMT &coderInfo = _coders[i];
- const CCoderStreamsInfo &csi = _bi.Coders[i];
-
- UInt32 j;
-
- unsigned numInStreams = EncodeMode ? 1 : csi.NumStreams;
- unsigned numOutStreams = EncodeMode ? csi.NumStreams : 1;
-
- coderInfo.InStreams.Clear();
- for (j = 0; j < numInStreams; j++)
- coderInfo.InStreams.AddNew();
-
- coderInfo.OutStreams.Clear();
- for (j = 0; j < numOutStreams; j++)
- coderInfo.OutStreams.AddNew();
- }
-
- for (i = 0; i < _bi.Bonds.Size(); i++)
- {
- const CBond &bond = _bi.Bonds[i];
-
- UInt32 inCoderIndex, inCoderStreamIndex;
- UInt32 outCoderIndex, outCoderStreamIndex;
-
- {
- UInt32 coderIndex, coderStreamIndex;
- _bi.GetCoder_for_Stream(bond.PackIndex, coderIndex, coderStreamIndex);
-
- inCoderIndex = EncodeMode ? bond.UnpackIndex : coderIndex;
- outCoderIndex = EncodeMode ? coderIndex : bond.UnpackIndex;
-
- inCoderStreamIndex = EncodeMode ? 0 : coderStreamIndex;
- outCoderStreamIndex = EncodeMode ? coderStreamIndex : 0;
- }
-
- _streamBinders[i].CreateStreams(
- &_coders[inCoderIndex].InStreams[inCoderStreamIndex],
- &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);
-
- CMyComPtr<ICompressSetBufSize> inSetSize, outSetSize;
- _coders[inCoderIndex].QueryInterface(IID_ICompressSetBufSize, (void **)&inSetSize);
- _coders[outCoderIndex].QueryInterface(IID_ICompressSetBufSize, (void **)&outSetSize);
- if (inSetSize && outSetSize)
- {
- const UInt32 kBufSize = 1 << 19;
- inSetSize->SetInBufSize(inCoderStreamIndex, kBufSize);
- outSetSize->SetOutBufSize(outCoderStreamIndex, kBufSize);
- }
- }
-
- {
- CCoderMT &cod = _coders[_bi.UnpackCoder];
- if (EncodeMode)
- cod.InStreams[0] = inStreams[0];
- else
- cod.OutStreams[0] = outStreams[0];
- }
-
- for (i = 0; i < _bi.PackStreams.Size(); i++)
- {
- UInt32 coderIndex, coderStreamIndex;
- _bi.GetCoder_for_Stream(_bi.PackStreams[i], coderIndex, coderStreamIndex);
- CCoderMT &cod = _coders[coderIndex];
- if (EncodeMode)
- cod.OutStreams[coderStreamIndex] = outStreams[i];
- else
- cod.InStreams[coderStreamIndex] = inStreams[i];
- }
-
- return S_OK;
-}
-
-HRESULT CMixerMT::ReturnIfError(HRESULT code)
-{
- FOR_VECTOR (i, _coders)
- if (_coders[i].Result == code)
- return code;
- return S_OK;
-}
-
-HRESULT CMixerMT::Code(
- ISequentialInStream * const *inStreams,
- ISequentialOutStream * const *outStreams,
- ICompressProgressInfo *progress)
-{
- Init(inStreams, outStreams);
-
- unsigned i;
- for (i = 0; i < _coders.Size(); i++)
- if (i != MainCoderIndex)
- {
- RINOK(_coders[i].Create());
- }
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != MainCoderIndex)
- _coders[i].Start();
-
- _coders[MainCoderIndex].Code(progress);
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != MainCoderIndex)
- _coders[i].WaitExecuteFinish();
-
- RINOK(ReturnIfError(E_ABORT));
- RINOK(ReturnIfError(E_OUTOFMEMORY));
-
- for (i = 0; i < _coders.Size(); i++)
- {
- HRESULT result = _coders[i].Result;
- if (result != S_OK
- && result != k_My_HRESULT_WritingWasCut
- && result != S_FALSE
- && result != E_FAIL)
- return result;
- }
-
- RINOK(ReturnIfError(S_FALSE));
-
- for (i = 0; i < _coders.Size(); i++)
- {
- HRESULT result = _coders[i].Result;
- if (result != S_OK && result != k_My_HRESULT_WritingWasCut)
- return result;
- }
-
- return S_OK;
-}
-
-UInt64 CMixerMT::GetBondStreamSize(unsigned bondIndex) const
-{
- return _streamBinders[bondIndex].ProcessedSize;
-}
-
-}
diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.h b/CPP/7zip/Archive/Common/CoderMixer2MT.h
deleted file mode 100644
index 41bb3e1c..00000000
--- a/CPP/7zip/Archive/Common/CoderMixer2MT.h
+++ /dev/null
@@ -1,77 +0,0 @@
-// CoderMixer2MT.h
-
-#ifndef __CODER_MIXER2_MT_H
-#define __CODER_MIXER2_MT_H
-
-#include "../../../Common/MyCom.h"
-
-#include "../../Common/StreamBinder.h"
-#include "../../Common/VirtThread.h"
-
-#include "CoderMixer2.h"
-
-namespace NCoderMixer2 {
-
-class CCoderMT: public CCoder, public CVirtThread
-{
- CLASS_NO_COPY(CCoderMT)
- CRecordVector<ISequentialInStream*> InStreamPointers;
- CRecordVector<ISequentialOutStream*> OutStreamPointers;
-
-private:
- void Execute();
-public:
- bool EncodeMode;
- HRESULT Result;
- CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;
- CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;
-
- CCoderMT(): EncodeMode(false) {}
- ~CCoderMT() { CVirtThread::WaitThreadFinish(); }
-
- void Code(ICompressProgressInfo *progress);
-};
-
-
-
-class CMixerMT:
- public IUnknown,
- public CMixer,
- public CMyUnknownImp
-{
- CObjectVector<CStreamBinder> _streamBinders;
-
- HRESULT Init(ISequentialInStream * const *inStreams, ISequentialOutStream * const *outStreams);
- HRESULT ReturnIfError(HRESULT code);
-
-public:
- CObjectVector<CCoderMT> _coders;
-
- MY_UNKNOWN_IMP
-
- virtual HRESULT SetBindInfo(const CBindInfo &bindInfo);
-
- virtual void AddCoder(ICompressCoder *coder, ICompressCoder2 *coder2, bool isFilter);
-
- virtual CCoder &GetCoder(unsigned index);
-
- virtual void SelectMainCoder(bool useFirst);
-
- virtual void ReInit();
-
- virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes)
- { _coders[coderIndex].SetCoderInfo(unpackSize, packSizes); }
-
- virtual HRESULT Code(
- ISequentialInStream * const *inStreams,
- ISequentialOutStream * const *outStreams,
- ICompressProgressInfo *progress);
-
- virtual UInt64 GetBondStreamSize(unsigned bondIndex) const;
-
- CMixerMT(bool encodeMode): CMixer(encodeMode) {}
-};
-
-}
-
-#endif
diff --git a/CPP/7zip/Archive/Common/CoderMixer2ST.cpp b/CPP/7zip/Archive/Common/CoderMixer2ST.cpp
deleted file mode 100644
index 127c1ed4..00000000
--- a/CPP/7zip/Archive/Common/CoderMixer2ST.cpp
+++ /dev/null
@@ -1,562 +0,0 @@
-// CoderMixer2ST.cpp
-
-#include "StdAfx.h"
-
-#include "CoderMixer2ST.h"
-
-STDMETHODIMP CSequentialInStreamCalcSize::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessed = 0;
- HRESULT result = S_OK;
- if (_stream)
- result = _stream->Read(data, size, &realProcessed);
- _size += realProcessed;
- if (size != 0 && realProcessed == 0)
- _wasFinished = true;
- if (processedSize)
- *processedSize = realProcessed;
- return result;
-}
-
-
-
-STDMETHODIMP COutStreamCalcSize::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- HRESULT result = S_OK;
- if (_stream)
- result = _stream->Write(data, size, &size);
- _size += size;
- if (processedSize)
- *processedSize = size;
- return result;
-}
-
-STDMETHODIMP COutStreamCalcSize::Flush()
-{
- HRESULT result = S_OK;
- if (_stream)
- {
- CMyComPtr<IOutStreamFlush> outStreamFlush;
- _stream.QueryInterface(IID_IOutStreamFlush, &outStreamFlush);
- if (outStreamFlush)
- result = outStreamFlush->Flush();;
- }
- return result;
-}
-
-
-
-namespace NCoderMixer2 {
-
-CMixerST::CMixerST(bool encodeMode):
- CMixer(encodeMode)
- {}
-
-CMixerST::~CMixerST() {}
-
-void CMixerST::AddCoder(ICompressCoder *coder, ICompressCoder2 *coder2, bool isFilter)
-{
- IsFilter_Vector.Add(isFilter);
- const CCoderStreamsInfo &c = _bi.Coders[_coders.Size()];
- CCoderST &c2 = _coders.AddNew();
- c2.NumStreams = c.NumStreams;
- c2.Coder = coder;
- c2.Coder2 = coder2;
-
- /*
- if (isFilter)
- {
- c2.CanRead = true;
- c2.CanWrite = true;
- }
- else
- */
- {
- IUnknown *unk = (coder ? (IUnknown *)coder : (IUnknown *)coder2);
- {
- CMyComPtr<ISequentialInStream> s;
- unk->QueryInterface(IID_ISequentialInStream, (void**)&s);
- c2.CanRead = (s != NULL);
- }
- {
- CMyComPtr<ISequentialOutStream> s;
- unk->QueryInterface(IID_ISequentialOutStream, (void**)&s);
- c2.CanWrite = (s != NULL);
- }
- }
-}
-
-CCoder &CMixerST::GetCoder(unsigned index)
-{
- return _coders[index];
-}
-
-void CMixerST::ReInit() {}
-
-HRESULT CMixerST::GetInStream2(
- ISequentialInStream * const *inStreams, /* const UInt64 * const *inSizes, */
- UInt32 outStreamIndex, ISequentialInStream **inStreamRes)
-{
- UInt32 coderIndex = outStreamIndex, coderStreamIndex = 0;
-
- if (EncodeMode)
- {
- _bi.GetCoder_for_Stream(outStreamIndex, coderIndex, coderStreamIndex);
- if (coderStreamIndex != 0)
- return E_NOTIMPL;
- }
-
- const CCoder &coder = _coders[coderIndex];
-
- CMyComPtr<ISequentialInStream> seqInStream;
- coder.QueryInterface(IID_ISequentialInStream, (void **)&seqInStream);
- if (!seqInStream)
- return E_NOTIMPL;
-
- UInt32 numInStreams = EncodeMode ? 1 : coder.NumStreams;
- UInt32 startIndex = EncodeMode ? coderIndex : _bi.Coder_to_Stream[coderIndex];
-
- bool isSet = false;
-
- if (numInStreams == 1)
- {
- CMyComPtr<ICompressSetInStream> setStream;
- coder.QueryInterface(IID_ICompressSetInStream, (void **)&setStream);
- if (setStream)
- {
- CMyComPtr<ISequentialInStream> seqInStream2;
- RINOK(GetInStream(inStreams, /* inSizes, */ startIndex + 0, &seqInStream2));
- RINOK(setStream->SetInStream(seqInStream2));
- isSet = true;
- }
- }
-
- if (!isSet && numInStreams != 0)
- {
- CMyComPtr<ICompressSetInStream2> setStream2;
- coder.QueryInterface(IID_ICompressSetInStream2, (void **)&setStream2);
- if (!setStream2)
- return E_NOTIMPL;
-
- for (UInt32 i = 0; i < numInStreams; i++)
- {
- CMyComPtr<ISequentialInStream> seqInStream2;
- RINOK(GetInStream(inStreams, /* inSizes, */ startIndex + i, &seqInStream2));
- RINOK(setStream2->SetInStream2(i, seqInStream2));
- }
- }
-
- *inStreamRes = seqInStream.Detach();
- return S_OK;
-}
-
-
-HRESULT CMixerST::GetInStream(
- ISequentialInStream * const *inStreams, /* const UInt64 * const *inSizes, */
- UInt32 inStreamIndex, ISequentialInStream **inStreamRes)
-{
- CMyComPtr<ISequentialInStream> seqInStream;
-
- {
- int index = -1;
- if (EncodeMode)
- {
- if (_bi.UnpackCoder == inStreamIndex)
- index = 0;
- }
- else
- index = _bi.FindStream_in_PackStreams(inStreamIndex);
-
- if (index >= 0)
- {
- seqInStream = inStreams[index];
- *inStreamRes = seqInStream.Detach();
- return S_OK;
- }
- }
-
- int bond = FindBond_for_Stream(
- true, // forInputStream
- inStreamIndex);
- if (bond < 0)
- return E_INVALIDARG;
-
- RINOK(GetInStream2(inStreams, /* inSizes, */
- _bi.Bonds[bond].Get_OutIndex(EncodeMode), &seqInStream));
-
- while (_binderStreams.Size() <= (unsigned)bond)
- _binderStreams.AddNew();
- CStBinderStream &bs = _binderStreams[bond];
-
- if (bs.StreamRef || bs.InStreamSpec)
- return E_NOTIMPL;
-
- CSequentialInStreamCalcSize *spec = new CSequentialInStreamCalcSize;
- bs.StreamRef = spec;
- bs.InStreamSpec = spec;
-
- spec->SetStream(seqInStream);
- spec->Init();
-
- seqInStream = bs.InStreamSpec;
-
- *inStreamRes = seqInStream.Detach();
- return S_OK;
-}
-
-
-HRESULT CMixerST::GetOutStream(
- ISequentialOutStream * const *outStreams, /* const UInt64 * const *outSizes, */
- UInt32 outStreamIndex, ISequentialOutStream **outStreamRes)
-{
- CMyComPtr<ISequentialOutStream> seqOutStream;
-
- {
- int index = -1;
- if (!EncodeMode)
- {
- if (_bi.UnpackCoder == outStreamIndex)
- index = 0;
- }
- else
- index = _bi.FindStream_in_PackStreams(outStreamIndex);
-
- if (index >= 0)
- {
- seqOutStream = outStreams[index];
- *outStreamRes = seqOutStream.Detach();
- return S_OK;
- }
- }
-
- int bond = FindBond_for_Stream(
- false, // forInputStream
- outStreamIndex);
- if (bond < 0)
- return E_INVALIDARG;
-
- UInt32 inStreamIndex = _bi.Bonds[bond].Get_InIndex(EncodeMode);
-
- UInt32 coderIndex = inStreamIndex;
- UInt32 coderStreamIndex = 0;
-
- if (!EncodeMode)
- _bi.GetCoder_for_Stream(inStreamIndex, coderIndex, coderStreamIndex);
-
- CCoder &coder = _coders[coderIndex];
-
- /*
- if (!coder.Coder)
- return E_NOTIMPL;
- */
-
- coder.QueryInterface(IID_ISequentialOutStream, (void **)&seqOutStream);
- if (!seqOutStream)
- return E_NOTIMPL;
-
- UInt32 numOutStreams = EncodeMode ? coder.NumStreams : 1;
- UInt32 startIndex = EncodeMode ? _bi.Coder_to_Stream[coderIndex]: coderIndex;
-
- bool isSet = false;
-
- if (numOutStreams == 1)
- {
- CMyComPtr<ICompressSetOutStream> setOutStream;
- coder.Coder.QueryInterface(IID_ICompressSetOutStream, &setOutStream);
- if (setOutStream)
- {
- CMyComPtr<ISequentialOutStream> seqOutStream2;
- RINOK(GetOutStream(outStreams, /* outSizes, */ startIndex + 0, &seqOutStream2));
- RINOK(setOutStream->SetOutStream(seqOutStream2));
- isSet = true;
- }
- }
-
- if (!isSet && numOutStreams != 0)
- {
- // return E_NOTIMPL;
- // /*
- CMyComPtr<ICompressSetOutStream2> setStream2;
- coder.QueryInterface(IID_ICompressSetOutStream2, (void **)&setStream2);
- if (!setStream2)
- return E_NOTIMPL;
- for (UInt32 i = 0; i < numOutStreams; i++)
- {
- CMyComPtr<ISequentialOutStream> seqOutStream2;
- RINOK(GetOutStream(outStreams, startIndex + i, &seqOutStream2));
- RINOK(setStream2->SetOutStream2(i, seqOutStream2));
- }
- // */
- }
-
- while (_binderStreams.Size() <= (unsigned)bond)
- _binderStreams.AddNew();
- CStBinderStream &bs = _binderStreams[bond];
-
- if (bs.StreamRef || bs.OutStreamSpec)
- return E_NOTIMPL;
-
- COutStreamCalcSize *spec = new COutStreamCalcSize;
- bs.StreamRef = (ISequentialOutStream *)spec;
- bs.OutStreamSpec = spec;
-
- spec->SetStream(seqOutStream);
- spec->Init();
-
- seqOutStream = bs.OutStreamSpec;
-
- *outStreamRes = seqOutStream.Detach();
- return S_OK;
-}
-
-
-static HRESULT GetError(HRESULT res, HRESULT res2)
-{
- if (res == res2)
- return res;
- if (res == S_OK)
- return res2;
- if (res == k_My_HRESULT_WritingWasCut)
- {
- if (res2 != S_OK)
- return res2;
- }
- return res;
-}
-
-
-HRESULT CMixerST::FlushStream(UInt32 streamIndex)
-{
- {
- int index = -1;
- if (!EncodeMode)
- {
- if (_bi.UnpackCoder == streamIndex)
- index = 0;
- }
- else
- index = _bi.FindStream_in_PackStreams(streamIndex);
-
- if (index >= 0)
- return S_OK;
- }
-
- int bond = FindBond_for_Stream(
- false, // forInputStream
- streamIndex);
- if (bond < 0)
- return E_INVALIDARG;
-
- UInt32 inStreamIndex = _bi.Bonds[bond].Get_InIndex(EncodeMode);
-
- UInt32 coderIndex = inStreamIndex;
- UInt32 coderStreamIndex = 0;
- if (!EncodeMode)
- _bi.GetCoder_for_Stream(inStreamIndex, coderIndex, coderStreamIndex);
-
- CCoder &coder = _coders[coderIndex];
- CMyComPtr<IOutStreamFlush> flush;
- coder.QueryInterface(IID_IOutStreamFlush, (void **)&flush);
- HRESULT res = S_OK;
- if (flush)
- {
- res = flush->Flush();
- }
- return GetError(res, FlushCoder(coderIndex));
-}
-
-
-HRESULT CMixerST::FlushCoder(UInt32 coderIndex)
-{
- CCoder &coder = _coders[coderIndex];
-
- UInt32 numOutStreams = EncodeMode ? coder.NumStreams : 1;
- UInt32 startIndex = EncodeMode ? _bi.Coder_to_Stream[coderIndex]: coderIndex;
-
- HRESULT res = S_OK;
- for (unsigned i = 0; i < numOutStreams; i++)
- res = GetError(res, FlushStream(startIndex + i));
- return res;
-}
-
-
-void CMixerST::SelectMainCoder(bool useFirst)
-{
- unsigned ci = _bi.UnpackCoder;
-
- int firstNonFilter = -1;
- int firstAllowed = ci;
-
- for (;;)
- {
- const CCoderST &coder = _coders[ci];
- // break;
-
- if (ci != _bi.UnpackCoder)
- if (EncodeMode ? !coder.CanWrite : !coder.CanRead)
- {
- firstAllowed = ci;
- firstNonFilter = -2;
- }
-
- if (coder.NumStreams != 1)
- break;
-
- UInt32 st = _bi.Coder_to_Stream[ci];
- if (_bi.IsStream_in_PackStreams(st))
- break;
- int bond = _bi.FindBond_for_PackStream(st);
- if (bond < 0)
- throw 20150213;
-
- if (EncodeMode ? !coder.CanRead : !coder.CanWrite)
- break;
-
- if (firstNonFilter == -1 && !IsFilter_Vector[ci])
- firstNonFilter = ci;
-
- ci = _bi.Bonds[bond].UnpackIndex;
- }
-
- ci = firstNonFilter;
- if (firstNonFilter < 0 || useFirst)
- ci = firstAllowed;
- MainCoderIndex = ci;
-}
-
-
-HRESULT CMixerST::Code(
- ISequentialInStream * const *inStreams,
- ISequentialOutStream * const *outStreams,
- ICompressProgressInfo *progress)
-{
- _binderStreams.Clear();
- unsigned ci = MainCoderIndex;
-
- const CCoder &mainCoder = _coders[MainCoderIndex];
-
- CObjectVector< CMyComPtr<ISequentialInStream> > seqInStreams;
- CObjectVector< CMyComPtr<ISequentialOutStream> > seqOutStreams;
-
- UInt32 numInStreams = EncodeMode ? 1 : mainCoder.NumStreams;
- UInt32 numOutStreams = !EncodeMode ? 1 : mainCoder.NumStreams;
-
- UInt32 startInIndex = EncodeMode ? ci : _bi.Coder_to_Stream[ci];
- UInt32 startOutIndex = !EncodeMode ? ci : _bi.Coder_to_Stream[ci];
-
- UInt32 i;
-
- for (i = 0; i < numInStreams; i++)
- {
- CMyComPtr<ISequentialInStream> seqInStream;
- RINOK(GetInStream(inStreams, /* inSizes, */ startInIndex + i, &seqInStream));
- seqInStreams.Add(seqInStream);
- }
-
- for (i = 0; i < numOutStreams; i++)
- {
- CMyComPtr<ISequentialOutStream> seqOutStream;
- RINOK(GetOutStream(outStreams, /* outSizes, */ startOutIndex + i, &seqOutStream));
- seqOutStreams.Add(seqOutStream);
- }
-
- CRecordVector< ISequentialInStream * > seqInStreamsSpec;
- CRecordVector< ISequentialOutStream * > seqOutStreamsSpec;
-
- for (i = 0; i < numInStreams; i++)
- seqInStreamsSpec.Add(seqInStreams[i]);
- for (i = 0; i < numOutStreams; i++)
- seqOutStreamsSpec.Add(seqOutStreams[i]);
-
- for (i = 0; i < _coders.Size(); i++)
- {
- if (i == ci)
- continue;
-
- CCoder &coder = _coders[i];
-
- CMyComPtr<ICompressSetOutStreamSize> setOutStreamSize;
- coder.QueryInterface(IID_ICompressSetOutStreamSize, (void **)&setOutStreamSize);
- if (setOutStreamSize)
- {
- RINOK(setOutStreamSize->SetOutStreamSize(
- EncodeMode ? coder.PackSizePointers[0] : coder.UnpackSizePointer));
- }
- }
-
- const UInt64 * const *isSizes2 = EncodeMode ? &mainCoder.UnpackSizePointer : &mainCoder.PackSizePointers.Front();
- const UInt64 * const *outSizes2 = EncodeMode ? &mainCoder.PackSizePointers.Front() : &mainCoder.UnpackSizePointer;
-
- HRESULT res;
- if (mainCoder.Coder)
- {
- res = mainCoder.Coder->Code(
- seqInStreamsSpec[0], seqOutStreamsSpec[0],
- isSizes2[0], outSizes2[0],
- progress);
- }
- else
- {
- res = mainCoder.Coder2->Code(
- &seqInStreamsSpec.Front(), isSizes2, numInStreams,
- &seqOutStreamsSpec.Front(), outSizes2, numOutStreams,
- progress);
- }
-
- if (res == k_My_HRESULT_WritingWasCut)
- res = S_OK;
-
- if (res == S_OK || res == S_FALSE)
- {
- res = GetError(res, FlushCoder(ci));
- }
-
- for (i = 0; i < _binderStreams.Size(); i++)
- {
- const CStBinderStream &bs = _binderStreams[i];
- if (bs.InStreamSpec)
- bs.InStreamSpec->ReleaseStream();
- else
- bs.OutStreamSpec->ReleaseStream();
- }
-
- if (res == k_My_HRESULT_WritingWasCut)
- res = S_OK;
- return res;
-}
-
-
-HRESULT CMixerST::GetMainUnpackStream(
- ISequentialInStream * const *inStreams,
- ISequentialInStream **inStreamRes)
-{
- CMyComPtr<ISequentialInStream> seqInStream;
-
- RINOK(GetInStream2(inStreams, /* inSizes, */
- _bi.UnpackCoder, &seqInStream))
-
- FOR_VECTOR (i, _coders)
- {
- CCoder &coder = _coders[i];
- CMyComPtr<ICompressSetOutStreamSize> setOutStreamSize;
- coder.QueryInterface(IID_ICompressSetOutStreamSize, (void **)&setOutStreamSize);
- if (setOutStreamSize)
- {
- RINOK(setOutStreamSize->SetOutStreamSize(coder.UnpackSizePointer));
- }
- }
-
- *inStreamRes = seqInStream.Detach();
- return S_OK;
-}
-
-
-UInt64 CMixerST::GetBondStreamSize(unsigned bondIndex) const
-{
- const CStBinderStream &bs = _binderStreams[bondIndex];
- if (bs.InStreamSpec)
- return bs.InStreamSpec->GetSize();
- return bs.OutStreamSpec->GetSize();
-}
-
-}
diff --git a/CPP/7zip/Archive/Common/CoderMixer2ST.h b/CPP/7zip/Archive/Common/CoderMixer2ST.h
deleted file mode 100644
index f2f7c4cb..00000000
--- a/CPP/7zip/Archive/Common/CoderMixer2ST.h
+++ /dev/null
@@ -1,129 +0,0 @@
-// CoderMixer2ST.h
-
-#ifndef __CODER_MIXER2_ST_H
-#define __CODER_MIXER2_ST_H
-
-#include "../../../Common/MyCom.h"
-
-#include "../../ICoder.h"
-
-#include "CoderMixer2.h"
-
-class CSequentialInStreamCalcSize:
- public ISequentialInStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP1(ISequentialInStream)
-
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
-private:
- CMyComPtr<ISequentialInStream> _stream;
- UInt64 _size;
- bool _wasFinished;
-public:
- void SetStream(ISequentialInStream *stream) { _stream = stream; }
- void Init()
- {
- _size = 0;
- _wasFinished = false;
- }
- void ReleaseStream() { _stream.Release(); }
- UInt64 GetSize() const { return _size; }
- bool WasFinished() const { return _wasFinished; }
-};
-
-
-class COutStreamCalcSize:
- public ISequentialOutStream,
- public IOutStreamFlush,
- public CMyUnknownImp
-{
- CMyComPtr<ISequentialOutStream> _stream;
- UInt64 _size;
-public:
- MY_UNKNOWN_IMP2(ISequentialOutStream, IOutStreamFlush)
-
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
- STDMETHOD(Flush)();
-
- void SetStream(ISequentialOutStream *stream) { _stream = stream; }
- void ReleaseStream() { _stream.Release(); }
- void Init() { _size = 0; }
- UInt64 GetSize() const { return _size; }
-};
-
-
-
-namespace NCoderMixer2 {
-
-struct CCoderST: public CCoder
-{
- bool CanRead;
- bool CanWrite;
-
- CCoderST(): CanRead(false), CanWrite(false) {}
-};
-
-
-struct CStBinderStream
-{
- CSequentialInStreamCalcSize *InStreamSpec;
- COutStreamCalcSize *OutStreamSpec;
- CMyComPtr<IUnknown> StreamRef;
-
- CStBinderStream(): InStreamSpec(NULL), OutStreamSpec(NULL) {}
-};
-
-
-class CMixerST:
- public IUnknown,
- public CMixer,
- public CMyUnknownImp
-{
- HRESULT GetInStream2(ISequentialInStream * const *inStreams, /* const UInt64 * const *inSizes, */
- UInt32 outStreamIndex, ISequentialInStream **inStreamRes);
- HRESULT GetInStream(ISequentialInStream * const *inStreams, /* const UInt64 * const *inSizes, */
- UInt32 inStreamIndex, ISequentialInStream **inStreamRes);
- HRESULT GetOutStream(ISequentialOutStream * const *outStreams, /* const UInt64 * const *outSizes, */
- UInt32 outStreamIndex, ISequentialOutStream **outStreamRes);
-
- HRESULT FlushStream(UInt32 streamIndex);
- HRESULT FlushCoder(UInt32 coderIndex);
-
-public:
- CObjectVector<CCoderST> _coders;
-
- CObjectVector<CStBinderStream> _binderStreams;
-
- MY_UNKNOWN_IMP
-
- CMixerST(bool encodeMode);
- ~CMixerST();
-
- virtual void AddCoder(ICompressCoder *coder, ICompressCoder2 *coder2, bool isFilter);
-
- virtual CCoder &GetCoder(unsigned index);
-
- virtual void SelectMainCoder(bool useFirst);
-
- virtual void ReInit();
-
- virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes)
- { _coders[coderIndex].SetCoderInfo(unpackSize, packSizes); }
-
- virtual HRESULT Code(
- ISequentialInStream * const *inStreams,
- ISequentialOutStream * const *outStreams,
- ICompressProgressInfo *progress);
-
- virtual UInt64 GetBondStreamSize(unsigned bondIndex) const;
-
- HRESULT GetMainUnpackStream(
- ISequentialInStream * const *inStreams,
- ISequentialInStream **inStreamRes);
-};
-
-}
-
-#endif
diff --git a/CPP/7zip/Archive/Common/CoderMixerMT.cpp b/CPP/7zip/Archive/Common/CoderMixerMT.cpp
deleted file mode 100644
index 96ea76a3..00000000
--- a/CPP/7zip/Archive/Common/CoderMixerMT.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-// CoderMixerMT.cpp
-
-#include "StdAfx.h"
-
-#include "CoderMixerMT.h"
-
-namespace NCoderMixer {
-
-void CCoder::Execute() { Code(NULL); }
-
-void CCoder::Code(ICompressProgressInfo *progress)
-{
- Result = Coder->Code(InStream, OutStream,
- InSizeAssigned ? &InSizeValue : NULL,
- OutSizeAssigned ? &OutSizeValue : NULL,
- progress);
- InStream.Release();
- OutStream.Release();
-}
-
-void CCoderMixerMT::AddCoder(ICompressCoder *coder)
-{
- _coders.Add(CCoder());
- _coders.Back().Coder = coder;
-}
-
-void CCoderMixerMT::ReInit()
-{
- for(int i = 0; i < _coders.Size(); i++)
- _coders[i].ReInit();
-}
-
-HRESULT CCoderMixerMT::ReturnIfError(HRESULT code)
-{
- for (int i = 0; i < _coders.Size(); i++)
- if (_coders[i].Result == code)
- return code;
- return S_OK;
-}
-
-STDMETHODIMP CCoderMixerMT::Code(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
- const UInt64 * /* inSize */, const UInt64 * /* outSize */,
- ICompressProgressInfo *progress)
-{
- _coders.Front().InStream = inStream;
- int i;
- _coders.Back().OutStream = outStream;
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != _progressCoderIndex)
- {
- RINOK(_coders[i].Create());
- }
-
- _streamBinders.Clear();
- for (i = 0; i + 1 < _coders.Size(); i++)
- {
- _streamBinders.Add(CStreamBinder());
- CStreamBinder &sb = _streamBinders[i];
- RINOK(sb.CreateEvents());
- sb.CreateStreams(&_coders[i + 1].InStream, &_coders[i].OutStream);
- }
-
- for(i = 0; i < _streamBinders.Size(); i++)
- _streamBinders[i].ReInit();
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != _progressCoderIndex)
- _coders[i].Start();
-
- _coders[_progressCoderIndex].Code(progress);
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != _progressCoderIndex)
- _coders[i].WaitExecuteFinish();
-
- RINOK(ReturnIfError(E_ABORT));
- RINOK(ReturnIfError(E_OUTOFMEMORY));
-
- for (i = 0; i < _coders.Size(); i++)
- {
- HRESULT result = _coders[i].Result;
- if (result != S_OK && result != E_FAIL && result != S_FALSE)
- return result;
- }
-
- RINOK(ReturnIfError(S_FALSE));
-
- for (i = 0; i < _coders.Size(); i++)
- {
- HRESULT result = _coders[i].Result;
- if (result != S_OK)
- return result;
- }
- return S_OK;
-}
-
-}
diff --git a/CPP/7zip/Archive/Common/CoderMixerMT.h b/CPP/7zip/Archive/Common/CoderMixerMT.h
deleted file mode 100644
index d2891b26..00000000
--- a/CPP/7zip/Archive/Common/CoderMixerMT.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// CoderMixerMT.h
-
-#ifndef __CODER_MIXER_MT_H
-#define __CODER_MIXER_MT_H
-
-#include "../../../Common/MyVector.h"
-#include "../../../Common/MyCom.h"
-#include "../../ICoder.h"
-#include "../../Common/StreamBinder.h"
-#include "../../Common/VirtThread.h"
-#include "CoderMixer.h"
-
-namespace NCoderMixer {
-
-struct CCoder: public CCoderInfo, public CVirtThread
-{
- HRESULT Result;
-
- virtual void Execute();
- void Code(ICompressProgressInfo *progress);
- virtual ~CCoder() { CVirtThread::WaitThreadFinish(); }
-};
-
-/*
- for each coder
- AddCoder()
- SetProgressIndex(UInt32 coderIndex);
-
- for each file
- {
- ReInit()
- for each coder
- SetCoderInfo
- Code
- }
-*/
-
-
-class CCoderMixerMT:
- public ICompressCoder,
- public CMyUnknownImp
-{
- CObjectVector<CStreamBinder> _streamBinders;
- int _progressCoderIndex;
-
- HRESULT ReturnIfError(HRESULT code);
-public:
- CObjectVector<CCoder> _coders;
- MY_UNKNOWN_IMP
-
- STDMETHOD(Code)(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
- const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress);
-
- void AddCoder(ICompressCoder *coder);
- void SetProgressCoderIndex(int coderIndex) { _progressCoderIndex = coderIndex; }
-
- void ReInit();
- void SetCoderInfo(UInt32 coderIndex, const UInt64 *inSize, const UInt64 *outSize)
- { _coders[coderIndex].SetCoderInfo(inSize, outSize); }
-
- /*
- UInt64 GetWriteProcessedSize(UInt32 binderIndex) const
- { return _streamBinders[binderIndex].ProcessedSize; }
- */
-};
-
-}
-#endif
diff --git a/CPP/7zip/Archive/Common/FindSignature.cpp b/CPP/7zip/Archive/Common/FindSignature.cpp
index e9a0f032..fc952fa8 100644
--- a/CPP/7zip/Archive/Common/FindSignature.cpp
+++ b/CPP/7zip/Archive/Common/FindSignature.cpp
@@ -2,6 +2,8 @@
#include "StdAfx.h"
+#include <string.h>
+
#include "../../../Common/MyBuffer.h"
#include "../../Common/StreamUtils.h"
diff --git a/CPP/7zip/Archive/Common/FindSignature.h b/CPP/7zip/Archive/Common/FindSignature.h
index e15af573..c359b9ed 100644
--- a/CPP/7zip/Archive/Common/FindSignature.h
+++ b/CPP/7zip/Archive/Common/FindSignature.h
@@ -1,7 +1,7 @@
// FindSignature.h
-#ifndef __FINDSIGNATURE_H
-#define __FINDSIGNATURE_H
+#ifndef __FIND_SIGNATURE_H
+#define __FIND_SIGNATURE_H
#include "../../IStream.h"