mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 05:15:01 -06:00
Initialer Commit
This commit is contained in:
1044
CPP/7zip/Archive/Common/CoderMixer2.cpp
Normal file
1044
CPP/7zip/Archive/Common/CoderMixer2.cpp
Normal file
File diff suppressed because it is too large
Load Diff
437
CPP/7zip/Archive/Common/CoderMixer2.h
Normal file
437
CPP/7zip/Archive/Common/CoderMixer2.h
Normal file
@@ -0,0 +1,437 @@
|
||||
// CoderMixer2.h
|
||||
|
||||
#ifndef __CODER_MIXER2_H
|
||||
#define __CODER_MIXER2_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../../Common/MyVector.h"
|
||||
|
||||
#include "../../ICoder.h"
|
||||
|
||||
#include "../../Common/CreateCoder.h"
|
||||
|
||||
#ifdef _7ZIP_ST
|
||||
#define USE_MIXER_ST
|
||||
#else
|
||||
#define USE_MIXER_MT
|
||||
#ifndef _SFX
|
||||
#define USE_MIXER_ST
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_MIXER_MT
|
||||
#include "../../Common/StreamBinder.h"
|
||||
#include "../../Common/VirtThread.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef USE_MIXER_ST
|
||||
|
||||
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 IOutStreamFinish,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UInt64 _size;
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(ISequentialOutStream, IOutStreamFinish)
|
||||
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(OutStreamFinish)();
|
||||
|
||||
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
void Init() { _size = 0; }
|
||||
UInt64 GetSize() const { return _size; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace NCoderMixer2 {
|
||||
|
||||
struct CBond
|
||||
{
|
||||
UInt32 PackIndex;
|
||||
UInt32 UnpackIndex;
|
||||
|
||||
UInt32 Get_InIndex(bool encodeMode) const { return encodeMode ? UnpackIndex : PackIndex; }
|
||||
UInt32 Get_OutIndex(bool encodeMode) const { return encodeMode ? PackIndex : UnpackIndex; }
|
||||
};
|
||||
|
||||
|
||||
struct CCoderStreamsInfo
|
||||
{
|
||||
UInt32 NumStreams;
|
||||
};
|
||||
|
||||
|
||||
struct CBindInfo
|
||||
{
|
||||
CRecordVector<CCoderStreamsInfo> Coders;
|
||||
CRecordVector<CBond> Bonds;
|
||||
CRecordVector<UInt32> PackStreams;
|
||||
unsigned UnpackCoder;
|
||||
|
||||
unsigned GetNum_Bonds_and_PackStreams() const { return Bonds.Size() + PackStreams.Size(); }
|
||||
|
||||
int FindBond_for_PackStream(UInt32 packStream) const
|
||||
{
|
||||
FOR_VECTOR (i, Bonds)
|
||||
if (Bonds[i].PackIndex == packStream)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int FindBond_for_UnpackStream(UInt32 unpackStream) const
|
||||
{
|
||||
FOR_VECTOR (i, Bonds)
|
||||
if (Bonds[i].UnpackIndex == unpackStream)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool SetUnpackCoder()
|
||||
{
|
||||
bool isOk = false;
|
||||
FOR_VECTOR(i, Coders)
|
||||
{
|
||||
if (FindBond_for_UnpackStream(i) < 0)
|
||||
{
|
||||
if (isOk)
|
||||
return false;
|
||||
UnpackCoder = i;
|
||||
isOk = true;
|
||||
}
|
||||
}
|
||||
return isOk;
|
||||
}
|
||||
|
||||
bool IsStream_in_PackStreams(UInt32 streamIndex) const
|
||||
{
|
||||
return FindStream_in_PackStreams(streamIndex) >= 0;
|
||||
}
|
||||
|
||||
int FindStream_in_PackStreams(UInt32 streamIndex) const
|
||||
{
|
||||
FOR_VECTOR(i, PackStreams)
|
||||
if (PackStreams[i] == streamIndex)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// that function is used before Maps is calculated
|
||||
|
||||
UInt32 GetStream_for_Coder(UInt32 coderIndex) const
|
||||
{
|
||||
UInt32 streamIndex = 0;
|
||||
for (UInt32 i = 0; i < coderIndex; i++)
|
||||
streamIndex += Coders[i].NumStreams;
|
||||
return streamIndex;
|
||||
}
|
||||
|
||||
// ---------- Maps Section ----------
|
||||
|
||||
CRecordVector<UInt32> Coder_to_Stream;
|
||||
CRecordVector<UInt32> Stream_to_Coder;
|
||||
|
||||
void ClearMaps();
|
||||
bool CalcMapsAndCheck();
|
||||
|
||||
// ---------- End of Maps Section ----------
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Coders.Clear();
|
||||
Bonds.Clear();
|
||||
PackStreams.Clear();
|
||||
|
||||
ClearMaps();
|
||||
}
|
||||
|
||||
void GetCoder_for_Stream(UInt32 streamIndex, UInt32 &coderIndex, UInt32 &coderStreamIndex) const
|
||||
{
|
||||
coderIndex = Stream_to_Coder[streamIndex];
|
||||
coderStreamIndex = streamIndex - Coder_to_Stream[coderIndex];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CCoder
|
||||
{
|
||||
CLASS_NO_COPY(CCoder);
|
||||
public:
|
||||
CMyComPtr<ICompressCoder> Coder;
|
||||
CMyComPtr<ICompressCoder2> Coder2;
|
||||
UInt32 NumStreams;
|
||||
|
||||
UInt64 UnpackSize;
|
||||
const UInt64 *UnpackSizePointer;
|
||||
|
||||
CRecordVector<UInt64> PackSizes;
|
||||
CRecordVector<const UInt64 *> PackSizePointers;
|
||||
|
||||
CCoder() {}
|
||||
|
||||
void SetCoderInfo(const UInt64 *unpackSize, const UInt64 * const *packSizes);
|
||||
|
||||
IUnknown *GetUnknown() const
|
||||
{
|
||||
return Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;
|
||||
}
|
||||
|
||||
HRESULT QueryInterface(REFGUID iid, void** pp) const
|
||||
{
|
||||
return GetUnknown()->QueryInterface(iid, pp);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CMixer
|
||||
{
|
||||
bool Is_PackSize_Correct_for_Stream(UInt32 streamIndex);
|
||||
|
||||
protected:
|
||||
CBindInfo _bi;
|
||||
|
||||
int FindBond_for_Stream(bool forInputStream, UInt32 streamIndex) const
|
||||
{
|
||||
if (EncodeMode == forInputStream)
|
||||
return _bi.FindBond_for_UnpackStream(streamIndex);
|
||||
else
|
||||
return _bi.FindBond_for_PackStream(streamIndex);
|
||||
}
|
||||
|
||||
CBoolVector IsFilter_Vector;
|
||||
CBoolVector IsExternal_Vector;
|
||||
bool EncodeMode;
|
||||
public:
|
||||
unsigned MainCoderIndex;
|
||||
|
||||
CMixer(bool encodeMode):
|
||||
EncodeMode(encodeMode),
|
||||
MainCoderIndex(0)
|
||||
{}
|
||||
|
||||
/*
|
||||
Sequence of calling:
|
||||
|
||||
SetBindInfo();
|
||||
for each coder
|
||||
AddCoder();
|
||||
SelectMainCoder();
|
||||
|
||||
for each file
|
||||
{
|
||||
ReInit()
|
||||
for each coder
|
||||
SetCoderInfo();
|
||||
Code();
|
||||
}
|
||||
*/
|
||||
|
||||
virtual HRESULT SetBindInfo(const CBindInfo &bindInfo)
|
||||
{
|
||||
_bi = bindInfo;
|
||||
IsFilter_Vector.Clear();
|
||||
MainCoderIndex = 0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
virtual void AddCoder(const CCreatedCoder &cod) = 0;
|
||||
virtual CCoder &GetCoder(unsigned index) = 0;
|
||||
virtual void SelectMainCoder(bool useFirst) = 0;
|
||||
virtual void ReInit() = 0;
|
||||
virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes) = 0;
|
||||
virtual HRESULT Code(
|
||||
ISequentialInStream * const *inStreams,
|
||||
ISequentialOutStream * const *outStreams,
|
||||
ICompressProgressInfo *progress) = 0;
|
||||
virtual UInt64 GetBondStreamSize(unsigned bondIndex) const = 0;
|
||||
|
||||
bool Is_UnpackSize_Correct_for_Coder(UInt32 coderIndex);
|
||||
bool Is_PackSize_Correct_for_Coder(UInt32 coderIndex);
|
||||
bool IsThere_ExternalCoder_in_PackTree(UInt32 coderIndex);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef USE_MIXER_ST
|
||||
|
||||
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 FinishStream(UInt32 streamIndex);
|
||||
HRESULT FinishCoder(UInt32 coderIndex);
|
||||
|
||||
public:
|
||||
CObjectVector<CCoderST> _coders;
|
||||
|
||||
CObjectVector<CStBinderStream> _binderStreams;
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
CMixerST(bool encodeMode);
|
||||
~CMixerST();
|
||||
|
||||
virtual void AddCoder(const CCreatedCoder &cod);
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef USE_MIXER_MT
|
||||
|
||||
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;
|
||||
|
||||
void Release()
|
||||
{
|
||||
InStreamPointers.Clear();
|
||||
OutStreamPointers.Clear();
|
||||
unsigned i;
|
||||
for (i = 0; i < InStreams.Size(); i++)
|
||||
InStreams[i].Release();
|
||||
for (i = 0; i < OutStreams.Size(); i++)
|
||||
OutStreams[i].Release();
|
||||
}
|
||||
|
||||
class CReleaser
|
||||
{
|
||||
CLASS_NO_COPY(CReleaser)
|
||||
CCoderMT &_c;
|
||||
public:
|
||||
CReleaser(CCoderMT &c): _c(c) {}
|
||||
~CReleaser() { _c.Release(); }
|
||||
};
|
||||
|
||||
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(const CCreatedCoder &cod);
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
17
CPP/7zip/Archive/Common/DummyOutStream.cpp
Normal file
17
CPP/7zip/Archive/Common/DummyOutStream.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// DummyOutStream.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "DummyOutStream.h"
|
||||
|
||||
STDMETHODIMP CDummyOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UInt32 realProcessedSize = size;
|
||||
HRESULT res = S_OK;
|
||||
if (_stream)
|
||||
res = _stream->Write(data, size, &realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
if (processedSize)
|
||||
*processedSize = realProcessedSize;
|
||||
return res;
|
||||
}
|
||||
25
CPP/7zip/Archive/Common/DummyOutStream.h
Normal file
25
CPP/7zip/Archive/Common/DummyOutStream.h
Normal file
@@ -0,0 +1,25 @@
|
||||
// DummyOutStream.h
|
||||
|
||||
#ifndef __DUMMY_OUT_STREAM_H
|
||||
#define __DUMMY_OUT_STREAM_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
class CDummyOutStream:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UInt64 _size;
|
||||
public:
|
||||
void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
void Init() { _size = 0; }
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
UInt64 GetSize() const { return _size; }
|
||||
};
|
||||
|
||||
#endif
|
||||
62
CPP/7zip/Archive/Common/FindSignature.cpp
Normal file
62
CPP/7zip/Archive/Common/FindSignature.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
// FindSignature.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "../../../Common/MyBuffer.h"
|
||||
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
#include "FindSignature.h"
|
||||
|
||||
HRESULT FindSignatureInStream(ISequentialInStream *stream,
|
||||
const Byte *signature, unsigned signatureSize,
|
||||
const UInt64 *limit, UInt64 &resPos)
|
||||
{
|
||||
resPos = 0;
|
||||
CByteBuffer byteBuffer2(signatureSize);
|
||||
RINOK(ReadStream_FALSE(stream, byteBuffer2, signatureSize));
|
||||
|
||||
if (memcmp(byteBuffer2, signature, signatureSize) == 0)
|
||||
return S_OK;
|
||||
|
||||
const UInt32 kBufferSize = (1 << 16);
|
||||
CByteBuffer byteBuffer(kBufferSize);
|
||||
Byte *buffer = byteBuffer;
|
||||
UInt32 numPrevBytes = signatureSize - 1;
|
||||
memcpy(buffer, (const Byte *)byteBuffer2 + 1, numPrevBytes);
|
||||
resPos = 1;
|
||||
for (;;)
|
||||
{
|
||||
if (limit != NULL)
|
||||
if (resPos > *limit)
|
||||
return S_FALSE;
|
||||
do
|
||||
{
|
||||
UInt32 numReadBytes = kBufferSize - numPrevBytes;
|
||||
UInt32 processedSize;
|
||||
RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
|
||||
numPrevBytes += processedSize;
|
||||
if (processedSize == 0)
|
||||
return S_FALSE;
|
||||
}
|
||||
while (numPrevBytes < signatureSize);
|
||||
UInt32 numTests = numPrevBytes - signatureSize + 1;
|
||||
for (UInt32 pos = 0; pos < numTests; pos++)
|
||||
{
|
||||
Byte b = signature[0];
|
||||
for (; buffer[pos] != b && pos < numTests; pos++);
|
||||
if (pos == numTests)
|
||||
break;
|
||||
if (memcmp(buffer + pos, signature, signatureSize) == 0)
|
||||
{
|
||||
resPos += pos;
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
resPos += numTests;
|
||||
numPrevBytes -= numTests;
|
||||
memmove(buffer, buffer + numTests, numPrevBytes);
|
||||
}
|
||||
}
|
||||
12
CPP/7zip/Archive/Common/FindSignature.h
Normal file
12
CPP/7zip/Archive/Common/FindSignature.h
Normal file
@@ -0,0 +1,12 @@
|
||||
// FindSignature.h
|
||||
|
||||
#ifndef __FIND_SIGNATURE_H
|
||||
#define __FIND_SIGNATURE_H
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
HRESULT FindSignatureInStream(ISequentialInStream *stream,
|
||||
const Byte *signature, unsigned signatureSize,
|
||||
const UInt64 *limit, UInt64 &resPos);
|
||||
|
||||
#endif
|
||||
157
CPP/7zip/Archive/Common/HandlerOut.cpp
Normal file
157
CPP/7zip/Archive/Common/HandlerOut.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
// HandlerOut.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifndef _7ZIP_ST
|
||||
#include "../../../Windows/System.h"
|
||||
#endif
|
||||
|
||||
#include "../Common/ParseProperties.h"
|
||||
|
||||
#include "HandlerOut.h"
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
namespace NArchive {
|
||||
|
||||
static void SetMethodProp32(COneMethodInfo &m, PROPID propID, UInt32 value)
|
||||
{
|
||||
if (m.FindProp(propID) < 0)
|
||||
m.AddProp32(propID, value);
|
||||
}
|
||||
|
||||
void CMultiMethodProps::SetGlobalLevelAndThreads(COneMethodInfo &oneMethodInfo
|
||||
#ifndef _7ZIP_ST
|
||||
, UInt32 numThreads
|
||||
#endif
|
||||
)
|
||||
{
|
||||
UInt32 level = _level;
|
||||
if (level != (UInt32)(Int32)-1)
|
||||
SetMethodProp32(oneMethodInfo, NCoderPropID::kLevel, (UInt32)level);
|
||||
|
||||
#ifndef _7ZIP_ST
|
||||
SetMethodProp32(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CMultiMethodProps::Init()
|
||||
{
|
||||
#ifndef _7ZIP_ST
|
||||
_numProcessors = _numThreads = NSystem::GetNumberOfProcessors();
|
||||
#endif
|
||||
|
||||
_level = (UInt32)(Int32)-1;
|
||||
_analysisLevel = -1;
|
||||
|
||||
_autoFilter = true;
|
||||
_crcSize = 4;
|
||||
_filterMethod.Clear();
|
||||
_methods.Clear();
|
||||
}
|
||||
|
||||
HRESULT CMultiMethodProps::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)
|
||||
{
|
||||
UString name = nameSpec;
|
||||
name.MakeLower_Ascii();
|
||||
if (name.IsEmpty())
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (name[0] == 'x')
|
||||
{
|
||||
name.Delete(0);
|
||||
_level = 9;
|
||||
return ParsePropToUInt32(name, value, _level);
|
||||
}
|
||||
|
||||
if (name.IsPrefixedBy_Ascii_NoCase("yx"))
|
||||
{
|
||||
name.Delete(0, 2);
|
||||
UInt32 v = 9;
|
||||
RINOK(ParsePropToUInt32(name, value, v));
|
||||
_analysisLevel = (int)v;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if (name.IsEqualTo("crc"))
|
||||
{
|
||||
name.Delete(0, 3);
|
||||
_crcSize = 4;
|
||||
return ParsePropToUInt32(name, value, _crcSize);
|
||||
}
|
||||
|
||||
UInt32 number;
|
||||
unsigned index = ParseStringToUInt32(name, number);
|
||||
UString realName = name.Ptr(index);
|
||||
if (index == 0)
|
||||
{
|
||||
if (name.IsPrefixedBy_Ascii_NoCase("mt"))
|
||||
{
|
||||
#ifndef _7ZIP_ST
|
||||
RINOK(ParseMtProp(name.Ptr(2), value, _numProcessors, _numThreads));
|
||||
#endif
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
if (name.IsEqualTo("f"))
|
||||
{
|
||||
HRESULT res = PROPVARIANT_to_bool(value, _autoFilter);
|
||||
if (res == S_OK)
|
||||
return res;
|
||||
if (value.vt != VT_BSTR)
|
||||
return E_INVALIDARG;
|
||||
return _filterMethod.ParseMethodFromPROPVARIANT(UString(), value);
|
||||
}
|
||||
number = 0;
|
||||
}
|
||||
if (number > 64)
|
||||
return E_FAIL;
|
||||
for (int j = _methods.Size(); j <= (int)number; j++)
|
||||
_methods.Add(COneMethodInfo());
|
||||
return _methods[number].ParseMethodFromPROPVARIANT(realName, value);
|
||||
}
|
||||
|
||||
void CSingleMethodProps::Init()
|
||||
{
|
||||
Clear();
|
||||
_level = (UInt32)(Int32)-1;
|
||||
|
||||
#ifndef _7ZIP_ST
|
||||
_numProcessors = _numThreads = NWindows::NSystem::GetNumberOfProcessors();
|
||||
AddProp_NumThreads(_numThreads);
|
||||
#endif
|
||||
}
|
||||
|
||||
HRESULT CSingleMethodProps::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps)
|
||||
{
|
||||
Init();
|
||||
for (UInt32 i = 0; i < numProps; i++)
|
||||
{
|
||||
UString name = names[i];
|
||||
name.MakeLower_Ascii();
|
||||
if (name.IsEmpty())
|
||||
return E_INVALIDARG;
|
||||
const PROPVARIANT &value = values[i];
|
||||
if (name[0] == L'x')
|
||||
{
|
||||
UInt32 a = 9;
|
||||
RINOK(ParsePropToUInt32(name.Ptr(1), value, a));
|
||||
_level = a;
|
||||
AddProp_Level(a);
|
||||
}
|
||||
else if (name.IsPrefixedBy_Ascii_NoCase("mt"))
|
||||
{
|
||||
#ifndef _7ZIP_ST
|
||||
RINOK(ParseMtProp(name.Ptr(2), value, _numProcessors, _numThreads));
|
||||
AddProp_NumThreads(_numThreads);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOK(ParseMethodFromPROPVARIANT(names[i], value));
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}
|
||||
67
CPP/7zip/Archive/Common/HandlerOut.h
Normal file
67
CPP/7zip/Archive/Common/HandlerOut.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// HandlerOut.h
|
||||
|
||||
#ifndef __HANDLER_OUT_H
|
||||
#define __HANDLER_OUT_H
|
||||
|
||||
#include "../../Common/MethodProps.h"
|
||||
|
||||
namespace NArchive {
|
||||
|
||||
class CMultiMethodProps
|
||||
{
|
||||
UInt32 _level;
|
||||
int _analysisLevel;
|
||||
public:
|
||||
#ifndef _7ZIP_ST
|
||||
UInt32 _numThreads;
|
||||
UInt32 _numProcessors;
|
||||
#endif
|
||||
|
||||
UInt32 _crcSize;
|
||||
CObjectVector<COneMethodInfo> _methods;
|
||||
COneMethodInfo _filterMethod;
|
||||
bool _autoFilter;
|
||||
|
||||
void SetGlobalLevelAndThreads(COneMethodInfo &oneMethodInfo
|
||||
#ifndef _7ZIP_ST
|
||||
, UInt32 numThreads
|
||||
#endif
|
||||
);
|
||||
|
||||
unsigned GetNumEmptyMethods() const
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < _methods.Size(); i++)
|
||||
if (!_methods[i].IsEmpty())
|
||||
break;
|
||||
return i;
|
||||
}
|
||||
|
||||
int GetLevel() const { return _level == (UInt32)(Int32)-1 ? 5 : (int)_level; }
|
||||
int GetAnalysisLevel() const { return _analysisLevel; }
|
||||
|
||||
void Init();
|
||||
|
||||
CMultiMethodProps() { Init(); }
|
||||
HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);
|
||||
};
|
||||
|
||||
class CSingleMethodProps: public COneMethodInfo
|
||||
{
|
||||
UInt32 _level;
|
||||
|
||||
public:
|
||||
#ifndef _7ZIP_ST
|
||||
UInt32 _numThreads;
|
||||
UInt32 _numProcessors;
|
||||
#endif
|
||||
|
||||
void Init();
|
||||
CSingleMethodProps() { Init(); }
|
||||
int GetLevel() const { return _level == (UInt32)(Int32)-1 ? 5 : (int)_level; }
|
||||
HRESULT SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
46
CPP/7zip/Archive/Common/InStreamWithCRC.cpp
Normal file
46
CPP/7zip/Archive/Common/InStreamWithCRC.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// InStreamWithCRC.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "InStreamWithCRC.h"
|
||||
|
||||
STDMETHODIMP CSequentialInStreamWithCRC::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;
|
||||
_crc = CrcUpdate(_crc, data, realProcessed);
|
||||
if (processedSize)
|
||||
*processedSize = realProcessed;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CInStreamWithCRC::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;
|
||||
*/
|
||||
_crc = CrcUpdate(_crc, data, realProcessed);
|
||||
if (processedSize)
|
||||
*processedSize = realProcessed;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
|
||||
{
|
||||
if (seekOrigin != STREAM_SEEK_SET || offset != 0)
|
||||
return E_FAIL;
|
||||
_size = 0;
|
||||
_crc = CRC_INIT_VAL;
|
||||
return _stream->Seek(offset, seekOrigin, newPosition);
|
||||
}
|
||||
67
CPP/7zip/Archive/Common/InStreamWithCRC.h
Normal file
67
CPP/7zip/Archive/Common/InStreamWithCRC.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// InStreamWithCRC.h
|
||||
|
||||
#ifndef __IN_STREAM_WITH_CRC_H
|
||||
#define __IN_STREAM_WITH_CRC_H
|
||||
|
||||
#include "../../../../C/7zCrc.h"
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
class CSequentialInStreamWithCRC:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
private:
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
UInt64 _size;
|
||||
UInt32 _crc;
|
||||
bool _wasFinished;
|
||||
public:
|
||||
void SetStream(ISequentialInStream *stream) { _stream = stream; }
|
||||
void Init()
|
||||
{
|
||||
_size = 0;
|
||||
_wasFinished = false;
|
||||
_crc = CRC_INIT_VAL;
|
||||
}
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
|
||||
UInt64 GetSize() const { return _size; }
|
||||
bool WasFinished() const { return _wasFinished; }
|
||||
};
|
||||
|
||||
class CInStreamWithCRC:
|
||||
public IInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(IInStream)
|
||||
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
|
||||
private:
|
||||
CMyComPtr<IInStream> _stream;
|
||||
UInt64 _size;
|
||||
UInt32 _crc;
|
||||
// bool _wasFinished;
|
||||
public:
|
||||
void SetStream(IInStream *stream) { _stream = stream; }
|
||||
void Init()
|
||||
{
|
||||
_size = 0;
|
||||
// _wasFinished = false;
|
||||
_crc = CRC_INIT_VAL;
|
||||
}
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
|
||||
UInt64 GetSize() const { return _size; }
|
||||
// bool WasFinished() const { return _wasFinished; }
|
||||
};
|
||||
|
||||
#endif
|
||||
88
CPP/7zip/Archive/Common/ItemNameUtils.cpp
Normal file
88
CPP/7zip/Archive/Common/ItemNameUtils.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// Archive/Common/ItemNameUtils.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ItemNameUtils.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NItemName {
|
||||
|
||||
static const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;
|
||||
static const wchar_t kDirDelimiter = L'/';
|
||||
|
||||
void ReplaceToOsPathSeparator(wchar_t *s)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
for (;;)
|
||||
{
|
||||
wchar_t c = *s;
|
||||
if (c == 0)
|
||||
break;
|
||||
if (c == kDirDelimiter)
|
||||
*s = kOSDirDelimiter;
|
||||
s++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
UString MakeLegalName(const UString &name)
|
||||
{
|
||||
UString zipName = name;
|
||||
zipName.Replace(kOSDirDelimiter, kDirDelimiter);
|
||||
return zipName;
|
||||
}
|
||||
|
||||
UString GetOSName(const UString &name)
|
||||
{
|
||||
UString newName = name;
|
||||
newName.Replace(kDirDelimiter, kOSDirDelimiter);
|
||||
return newName;
|
||||
}
|
||||
|
||||
UString GetOSName2(const UString &name)
|
||||
{
|
||||
if (name.IsEmpty())
|
||||
return UString();
|
||||
UString newName = GetOSName(name);
|
||||
if (newName.Back() == kOSDirDelimiter)
|
||||
newName.DeleteBack();
|
||||
return newName;
|
||||
}
|
||||
|
||||
void ConvertToOSName2(UString &name)
|
||||
{
|
||||
if (!name.IsEmpty())
|
||||
{
|
||||
name.Replace(kDirDelimiter, kOSDirDelimiter);
|
||||
if (name.Back() == kOSDirDelimiter)
|
||||
name.DeleteBack();
|
||||
}
|
||||
}
|
||||
|
||||
bool HasTailSlash(const AString &name, UINT
|
||||
#if defined(_WIN32) && !defined(UNDER_CE)
|
||||
codePage
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if (name.IsEmpty())
|
||||
return false;
|
||||
LPCSTR prev =
|
||||
#if defined(_WIN32) && !defined(UNDER_CE)
|
||||
CharPrevExA((WORD)codePage, name, &name[name.Len()], 0);
|
||||
#else
|
||||
(LPCSTR)(name) + (name.Len() - 1);
|
||||
#endif
|
||||
return (*prev == '/');
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
UString WinNameToOSName(const UString &name)
|
||||
{
|
||||
UString newName = name;
|
||||
newName.Replace(L'\\', kOSDirDelimiter);
|
||||
return newName;
|
||||
}
|
||||
#endif
|
||||
|
||||
}}
|
||||
27
CPP/7zip/Archive/Common/ItemNameUtils.h
Normal file
27
CPP/7zip/Archive/Common/ItemNameUtils.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// Archive/Common/ItemNameUtils.h
|
||||
|
||||
#ifndef __ARCHIVE_ITEM_NAME_UTILS_H
|
||||
#define __ARCHIVE_ITEM_NAME_UTILS_H
|
||||
|
||||
#include "../../../Common/MyString.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NItemName {
|
||||
|
||||
void ReplaceToOsPathSeparator(wchar_t *s);
|
||||
|
||||
UString MakeLegalName(const UString &name);
|
||||
UString GetOSName(const UString &name);
|
||||
UString GetOSName2(const UString &name);
|
||||
void ConvertToOSName2(UString &name);
|
||||
bool HasTailSlash(const AString &name, UINT codePage);
|
||||
|
||||
#ifdef _WIN32
|
||||
inline UString WinNameToOSName(const UString &name) { return name; }
|
||||
#else
|
||||
UString WinNameToOSName(const UString &name);
|
||||
#endif
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
191
CPP/7zip/Archive/Common/MultiStream.cpp
Normal file
191
CPP/7zip/Archive/Common/MultiStream.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
// MultiStream.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "MultiStream.h"
|
||||
|
||||
STDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if (processedSize)
|
||||
*processedSize = 0;
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
if (_pos >= _totalLength)
|
||||
return S_OK;
|
||||
|
||||
{
|
||||
unsigned left = 0, mid = _streamIndex, right = Streams.Size();
|
||||
for (;;)
|
||||
{
|
||||
CSubStreamInfo &m = Streams[mid];
|
||||
if (_pos < m.GlobalOffset)
|
||||
right = mid;
|
||||
else if (_pos >= m.GlobalOffset + m.Size)
|
||||
left = mid + 1;
|
||||
else
|
||||
{
|
||||
_streamIndex = mid;
|
||||
break;
|
||||
}
|
||||
mid = (left + right) / 2;
|
||||
}
|
||||
_streamIndex = mid;
|
||||
}
|
||||
|
||||
CSubStreamInfo &s = Streams[_streamIndex];
|
||||
UInt64 localPos = _pos - s.GlobalOffset;
|
||||
if (localPos != s.LocalPos)
|
||||
{
|
||||
RINOK(s.Stream->Seek(localPos, STREAM_SEEK_SET, &s.LocalPos));
|
||||
}
|
||||
UInt64 rem = s.Size - localPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
HRESULT result = s.Stream->Read(data, size, &size);
|
||||
_pos += size;
|
||||
s.LocalPos += size;
|
||||
if (processedSize)
|
||||
*processedSize = size;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
|
||||
{
|
||||
switch (seekOrigin)
|
||||
{
|
||||
case STREAM_SEEK_SET: break;
|
||||
case STREAM_SEEK_CUR: offset += _pos; break;
|
||||
case STREAM_SEEK_END: offset += _totalLength; break;
|
||||
default: return STG_E_INVALIDFUNCTION;
|
||||
}
|
||||
if (offset < 0)
|
||||
return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
|
||||
_pos = offset;
|
||||
if (newPosition)
|
||||
*newPosition = offset;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
class COutVolumeStream:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
unsigned _volIndex;
|
||||
UInt64 _volSize;
|
||||
UInt64 _curPos;
|
||||
CMyComPtr<ISequentialOutStream> _volumeStream;
|
||||
COutArchive _archive;
|
||||
CCRC _crc;
|
||||
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
CFileItem _file;
|
||||
CUpdateOptions _options;
|
||||
CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
|
||||
void Init(IArchiveUpdateCallback2 *volumeCallback,
|
||||
const UString &name)
|
||||
{
|
||||
_file.Name = name;
|
||||
_file.IsStartPosDefined = true;
|
||||
_file.StartPos = 0;
|
||||
|
||||
VolumeCallback = volumeCallback;
|
||||
_volIndex = 0;
|
||||
_volSize = 0;
|
||||
}
|
||||
|
||||
HRESULT Flush();
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
HRESULT COutVolumeStream::Flush()
|
||||
{
|
||||
if (_volumeStream)
|
||||
{
|
||||
_file.UnPackSize = _curPos;
|
||||
_file.FileCRC = _crc.GetDigest();
|
||||
RINOK(WriteVolumeHeader(_archive, _file, _options));
|
||||
_archive.Close();
|
||||
_volumeStream.Release();
|
||||
_file.StartPos += _file.UnPackSize;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
STDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if (processedSize)
|
||||
*processedSize = 0;
|
||||
while (size > 0)
|
||||
{
|
||||
if (_streamIndex >= Streams.Size())
|
||||
{
|
||||
CSubStreamInfo subStream;
|
||||
RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));
|
||||
RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));
|
||||
subStream.Pos = 0;
|
||||
Streams.Add(subStream);
|
||||
continue;
|
||||
}
|
||||
CSubStreamInfo &subStream = Streams[_streamIndex];
|
||||
if (_offsetPos >= subStream.Size)
|
||||
{
|
||||
_offsetPos -= subStream.Size;
|
||||
_streamIndex++;
|
||||
continue;
|
||||
}
|
||||
if (_offsetPos != subStream.Pos)
|
||||
{
|
||||
CMyComPtr<IOutStream> outStream;
|
||||
RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));
|
||||
RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));
|
||||
subStream.Pos = _offsetPos;
|
||||
}
|
||||
|
||||
UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);
|
||||
UInt32 realProcessed;
|
||||
RINOK(subStream.Stream->Write(data, curSize, &realProcessed));
|
||||
data = (void *)((Byte *)data + realProcessed);
|
||||
size -= realProcessed;
|
||||
subStream.Pos += realProcessed;
|
||||
_offsetPos += realProcessed;
|
||||
_absPos += realProcessed;
|
||||
if (_absPos > _length)
|
||||
_length = _absPos;
|
||||
if (processedSize)
|
||||
*processedSize += realProcessed;
|
||||
if (subStream.Pos == subStream.Size)
|
||||
{
|
||||
_streamIndex++;
|
||||
_offsetPos = 0;
|
||||
}
|
||||
if (realProcessed != curSize && realProcessed == 0)
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
|
||||
{
|
||||
switch (seekOrigin)
|
||||
{
|
||||
case STREAM_SEEK_SET: break;
|
||||
case STREAM_SEEK_CUR: offset += _absPos; break;
|
||||
case STREAM_SEEK_END: offset += _length; break;
|
||||
default: return STG_E_INVALIDFUNCTION;
|
||||
}
|
||||
if (offset < 0)
|
||||
return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
|
||||
_absPos = offset;
|
||||
_offsetPos = _absPos;
|
||||
_streamIndex = 0;
|
||||
if (newPosition)
|
||||
*newPosition = offset;
|
||||
return S_OK;
|
||||
}
|
||||
*/
|
||||
89
CPP/7zip/Archive/Common/MultiStream.h
Normal file
89
CPP/7zip/Archive/Common/MultiStream.h
Normal file
@@ -0,0 +1,89 @@
|
||||
// MultiStream.h
|
||||
|
||||
#ifndef __MULTI_STREAM_H
|
||||
#define __MULTI_STREAM_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../../Common/MyVector.h"
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
class CMultiStream:
|
||||
public IInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
UInt64 _pos;
|
||||
UInt64 _totalLength;
|
||||
unsigned _streamIndex;
|
||||
|
||||
public:
|
||||
|
||||
struct CSubStreamInfo
|
||||
{
|
||||
CMyComPtr<IInStream> Stream;
|
||||
UInt64 Size;
|
||||
UInt64 GlobalOffset;
|
||||
UInt64 LocalPos;
|
||||
|
||||
CSubStreamInfo(): Size(0), GlobalOffset(0), LocalPos(0) {}
|
||||
};
|
||||
|
||||
CObjectVector<CSubStreamInfo> Streams;
|
||||
|
||||
HRESULT Init()
|
||||
{
|
||||
UInt64 total = 0;
|
||||
FOR_VECTOR (i, Streams)
|
||||
{
|
||||
CSubStreamInfo &s = Streams[i];
|
||||
s.GlobalOffset = total;
|
||||
total += Streams[i].Size;
|
||||
RINOK(s.Stream->Seek(0, STREAM_SEEK_CUR, &s.LocalPos));
|
||||
}
|
||||
_totalLength = total;
|
||||
_pos = 0;
|
||||
_streamIndex = 0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
MY_UNKNOWN_IMP1(IInStream)
|
||||
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
|
||||
};
|
||||
|
||||
/*
|
||||
class COutMultiStream:
|
||||
public IOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
unsigned _streamIndex; // required stream
|
||||
UInt64 _offsetPos; // offset from start of _streamIndex index
|
||||
UInt64 _absPos;
|
||||
UInt64 _length;
|
||||
|
||||
struct CSubStreamInfo
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> Stream;
|
||||
UInt64 Size;
|
||||
UInt64 Pos;
|
||||
};
|
||||
CObjectVector<CSubStreamInfo> Streams;
|
||||
public:
|
||||
CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
|
||||
void Init()
|
||||
{
|
||||
_streamIndex = 0;
|
||||
_offsetPos = 0;
|
||||
_absPos = 0;
|
||||
_length = 0;
|
||||
}
|
||||
|
||||
MY_UNKNOWN_IMP1(IOutStream)
|
||||
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
|
||||
};
|
||||
*/
|
||||
|
||||
#endif
|
||||
18
CPP/7zip/Archive/Common/OutStreamWithCRC.cpp
Normal file
18
CPP/7zip/Archive/Common/OutStreamWithCRC.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// OutStreamWithCRC.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "OutStreamWithCRC.h"
|
||||
|
||||
STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
HRESULT result = S_OK;
|
||||
if (_stream)
|
||||
result = _stream->Write(data, size, &size);
|
||||
if (_calculate)
|
||||
_crc = CrcUpdate(_crc, data, size);
|
||||
_size += size;
|
||||
if (processedSize != NULL)
|
||||
*processedSize = size;
|
||||
return result;
|
||||
}
|
||||
37
CPP/7zip/Archive/Common/OutStreamWithCRC.h
Normal file
37
CPP/7zip/Archive/Common/OutStreamWithCRC.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// OutStreamWithCRC.h
|
||||
|
||||
#ifndef __OUT_STREAM_WITH_CRC_H
|
||||
#define __OUT_STREAM_WITH_CRC_H
|
||||
|
||||
#include "../../../../C/7zCrc.h"
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
class COutStreamWithCRC:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UInt64 _size;
|
||||
UInt32 _crc;
|
||||
bool _calculate;
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
void Init(bool calculate = true)
|
||||
{
|
||||
_size = 0;
|
||||
_calculate = calculate;
|
||||
_crc = CRC_INIT_VAL;
|
||||
}
|
||||
void EnableCalc(bool calculate) { _calculate = calculate; }
|
||||
void InitCRC() { _crc = CRC_INIT_VAL; }
|
||||
UInt64 GetSize() const { return _size; }
|
||||
UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
|
||||
};
|
||||
|
||||
#endif
|
||||
18
CPP/7zip/Archive/Common/OutStreamWithSha1.cpp
Normal file
18
CPP/7zip/Archive/Common/OutStreamWithSha1.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// OutStreamWithSha1.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "OutStreamWithSha1.h"
|
||||
|
||||
STDMETHODIMP COutStreamWithSha1::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
HRESULT result = S_OK;
|
||||
if (_stream)
|
||||
result = _stream->Write(data, size, &size);
|
||||
if (_calculate)
|
||||
Sha1_Update(&_sha, (const Byte *)data, size);
|
||||
_size += size;
|
||||
if (processedSize)
|
||||
*processedSize = size;
|
||||
return result;
|
||||
}
|
||||
36
CPP/7zip/Archive/Common/OutStreamWithSha1.h
Normal file
36
CPP/7zip/Archive/Common/OutStreamWithSha1.h
Normal file
@@ -0,0 +1,36 @@
|
||||
// OutStreamWithSha1.h
|
||||
|
||||
#ifndef __OUT_STREAM_WITH_SHA1_H
|
||||
#define __OUT_STREAM_WITH_SHA1_H
|
||||
|
||||
#include "../../../../C/Sha1.h"
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
class COutStreamWithSha1:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UInt64 _size;
|
||||
CSha1 _sha;
|
||||
bool _calculate;
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
void Init(bool calculate = true)
|
||||
{
|
||||
_size = 0;
|
||||
_calculate = calculate;
|
||||
Sha1_Init(&_sha);
|
||||
}
|
||||
void InitSha1() { Sha1_Init(&_sha); }
|
||||
UInt64 GetSize() const { return _size; }
|
||||
void Final(Byte *digest) { Sha1_Final(&_sha, digest); }
|
||||
};
|
||||
|
||||
#endif
|
||||
3
CPP/7zip/Archive/Common/ParseProperties.cpp
Normal file
3
CPP/7zip/Archive/Common/ParseProperties.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
// ParseProperties.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
6
CPP/7zip/Archive/Common/ParseProperties.h
Normal file
6
CPP/7zip/Archive/Common/ParseProperties.h
Normal file
@@ -0,0 +1,6 @@
|
||||
// ParseProperties.h
|
||||
|
||||
#ifndef __PARSE_PROPERTIES_H
|
||||
#define __PARSE_PROPERTIES_H
|
||||
|
||||
#endif
|
||||
8
CPP/7zip/Archive/Common/StdAfx.h
Normal file
8
CPP/7zip/Archive/Common/StdAfx.h
Normal file
@@ -0,0 +1,8 @@
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include "../../../Common/Common.h"
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user