mirror of
https://github.com/Xevion/easy7zip.git
synced 2026-01-31 08:24:11 -06:00
4.59 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
3901bf0ab8
commit
173c07e166
@@ -11,11 +11,11 @@
|
||||
|
||||
static const unsigned int kNumCodecsMax = 64;
|
||||
unsigned int g_NumCodecs = 0;
|
||||
const CCodecInfo *g_Codecs[kNumCodecsMax];
|
||||
void RegisterCodec(const CCodecInfo *codecInfo)
|
||||
{
|
||||
const CCodecInfo *g_Codecs[kNumCodecsMax];
|
||||
void RegisterCodec(const CCodecInfo *codecInfo)
|
||||
{
|
||||
if (g_NumCodecs < kNumCodecsMax)
|
||||
g_Codecs[g_NumCodecs++] = codecInfo;
|
||||
g_Codecs[g_NumCodecs++] = codecInfo;
|
||||
}
|
||||
|
||||
#ifdef EXTERNAL_CODECS
|
||||
@@ -59,7 +59,7 @@ HRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodec
|
||||
// memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);
|
||||
if (prop.vt != VT_UI8)
|
||||
{
|
||||
continue; // old Interface
|
||||
continue; // old Interface
|
||||
// return E_INVALIDARG;
|
||||
}
|
||||
info.Id = prop.uhVal.QuadPart;
|
||||
@@ -93,7 +93,7 @@ bool FindMethod(
|
||||
UInt32 i;
|
||||
for (i = 0; i < g_NumCodecs; i++)
|
||||
{
|
||||
const CCodecInfo &codec = *g_Codecs[i];
|
||||
const CCodecInfo &codec = *g_Codecs[i];
|
||||
if (name.CompareNoCase(codec.Name) == 0)
|
||||
{
|
||||
methodId = codec.Id;
|
||||
@@ -106,7 +106,7 @@ bool FindMethod(
|
||||
if (externalCodecs)
|
||||
for (i = 0; i < (UInt32)externalCodecs->Size(); i++)
|
||||
{
|
||||
const CCodecInfoEx &codec = (*externalCodecs)[i];
|
||||
const CCodecInfoEx &codec = (*externalCodecs)[i];
|
||||
if (codec.Name.CompareNoCase(name) == 0)
|
||||
{
|
||||
methodId = codec.Id;
|
||||
@@ -128,7 +128,7 @@ bool FindMethod(
|
||||
UInt32 i;
|
||||
for (i = 0; i < g_NumCodecs; i++)
|
||||
{
|
||||
const CCodecInfo &codec = *g_Codecs[i];
|
||||
const CCodecInfo &codec = *g_Codecs[i];
|
||||
if (methodId == codec.Id)
|
||||
{
|
||||
name = codec.Name;
|
||||
@@ -139,7 +139,7 @@ bool FindMethod(
|
||||
if (externalCodecs)
|
||||
for (i = 0; i < (UInt32)externalCodecs->Size(); i++)
|
||||
{
|
||||
const CCodecInfoEx &codec = (*externalCodecs)[i];
|
||||
const CCodecInfoEx &codec = (*externalCodecs)[i];
|
||||
if (methodId == codec.Id)
|
||||
{
|
||||
name = codec.Name;
|
||||
@@ -162,7 +162,7 @@ HRESULT CreateCoder(
|
||||
UInt32 i;
|
||||
for (i = 0; i < g_NumCodecs; i++)
|
||||
{
|
||||
const CCodecInfo &codec = *g_Codecs[i];
|
||||
const CCodecInfo &codec = *g_Codecs[i];
|
||||
if (codec.Id == methodId)
|
||||
{
|
||||
if (encode)
|
||||
@@ -194,7 +194,7 @@ HRESULT CreateCoder(
|
||||
if (!created && externalCodecs)
|
||||
for (i = 0; i < (UInt32)externalCodecs->Size(); i++)
|
||||
{
|
||||
const CCodecInfoEx &codec = (*externalCodecs)[i];
|
||||
const CCodecInfoEx &codec = (*externalCodecs)[i];
|
||||
if (codec.Id == methodId)
|
||||
{
|
||||
if (encode)
|
||||
@@ -204,7 +204,7 @@ HRESULT CreateCoder(
|
||||
if (codec.IsSimpleCodec())
|
||||
{
|
||||
HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);
|
||||
if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)
|
||||
if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)
|
||||
return result;
|
||||
if (!coder)
|
||||
{
|
||||
@@ -224,7 +224,7 @@ HRESULT CreateCoder(
|
||||
if (codec.IsSimpleCodec())
|
||||
{
|
||||
HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);
|
||||
if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)
|
||||
if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)
|
||||
return result;
|
||||
if (!coder)
|
||||
{
|
||||
@@ -253,7 +253,7 @@ HRESULT CreateCoder(
|
||||
HRESULT CreateCoder(
|
||||
DECL_EXTERNAL_CODECS_LOC_VARS
|
||||
CMethodId methodId,
|
||||
CMyComPtr<ICompressCoder> &coder,
|
||||
CMyComPtr<ICompressCoder> &coder,
|
||||
CMyComPtr<ICompressCoder2> &coder2,
|
||||
bool encode)
|
||||
{
|
||||
|
||||
@@ -86,7 +86,7 @@ HRESULT CreateCoder(
|
||||
|
||||
HRESULT CreateCoder(
|
||||
DECL_EXTERNAL_CODECS_LOC_VARS
|
||||
CMethodId methodId,
|
||||
CMethodId methodId,
|
||||
CMyComPtr<ICompressCoder> &coder, bool encode);
|
||||
|
||||
HRESULT CreateFilter(
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
static bool MakeAutoName(const UString &name,
|
||||
static bool MakeAutoName(const UString &name,
|
||||
const UString &extension, int value, UString &path)
|
||||
{
|
||||
wchar_t number[32];
|
||||
|
||||
@@ -81,7 +81,7 @@ STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSi
|
||||
{
|
||||
#ifdef _WIN32
|
||||
UInt32 realProcessedSize;
|
||||
BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE),
|
||||
BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE),
|
||||
data, size, (DWORD *)&realProcessedSize, NULL);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
@@ -94,10 +94,10 @@ STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSi
|
||||
if(processedSize != NULL)
|
||||
*processedSize = 0;
|
||||
ssize_t res;
|
||||
do
|
||||
do
|
||||
{
|
||||
res = read(0, data, (size_t)size);
|
||||
}
|
||||
}
|
||||
while (res < 0 && (errno == EINTR));
|
||||
if (res == -1)
|
||||
return E_FAIL;
|
||||
@@ -110,7 +110,7 @@ STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSi
|
||||
|
||||
#endif
|
||||
|
||||
STDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,
|
||||
STDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,
|
||||
UInt64 *newPosition)
|
||||
{
|
||||
if(seekOrigin >= 3)
|
||||
@@ -228,10 +228,10 @@ STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *pro
|
||||
{
|
||||
// Seems that Windows doesn't like big amounts writing to stdout.
|
||||
// So we limit portions by 32KB.
|
||||
UInt32 sizeTemp = (1 << 15);
|
||||
UInt32 sizeTemp = (1 << 15);
|
||||
if (sizeTemp > size)
|
||||
sizeTemp = size;
|
||||
res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),
|
||||
res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),
|
||||
data, sizeTemp, (DWORD *)&realProcessedSize, NULL);
|
||||
size -= realProcessedSize;
|
||||
data = (const void *)((const Byte *)data + realProcessedSize);
|
||||
@@ -243,10 +243,10 @@ STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *pro
|
||||
#else
|
||||
|
||||
ssize_t res;
|
||||
do
|
||||
do
|
||||
{
|
||||
res = write(1, data, (size_t)size);
|
||||
}
|
||||
}
|
||||
while (res < 0 && (errno == EINTR));
|
||||
if (res == -1)
|
||||
return E_FAIL;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "../IStream.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
|
||||
class CInFileStream:
|
||||
class CInFileStream:
|
||||
public IInStream,
|
||||
public IStreamGetSize,
|
||||
public CMyUnknownImp
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
};
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
class CStdInFileStream:
|
||||
class CStdInFileStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
};
|
||||
#endif
|
||||
|
||||
class COutFileStream:
|
||||
class COutFileStream:
|
||||
public IOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -109,14 +109,11 @@ public:
|
||||
UInt64 ProcessedSize;
|
||||
|
||||
#ifdef USE_WIN_FILE
|
||||
bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)
|
||||
bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)
|
||||
{
|
||||
return File.SetTime(creationTime, lastAccessTime, lastWriteTime);
|
||||
}
|
||||
bool SetLastWriteTime(const FILETIME *lastWriteTime)
|
||||
{
|
||||
return File.SetLastWriteTime(lastWriteTime);
|
||||
return File.SetTime(cTime, aTime, mTime);
|
||||
}
|
||||
bool SetMTime(const FILETIME *mTime) { return File.SetMTime(mTime); }
|
||||
#endif
|
||||
|
||||
|
||||
@@ -128,7 +125,7 @@ public:
|
||||
};
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
class CStdOutFileStream:
|
||||
class CStdOutFileStream:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "FilterCoder.h"
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../C/Alloc.h"
|
||||
}
|
||||
#include "../../Common/Defs.h"
|
||||
@@ -13,13 +13,13 @@ extern "C"
|
||||
static const UInt32 kBufferSize = 1 << 17;
|
||||
|
||||
CFilterCoder::CFilterCoder()
|
||||
{
|
||||
_buffer = (Byte *)::MidAlloc(kBufferSize);
|
||||
{
|
||||
_buffer = (Byte *)::MidAlloc(kBufferSize);
|
||||
}
|
||||
|
||||
CFilterCoder::~CFilterCoder()
|
||||
{
|
||||
::MidFree(_buffer);
|
||||
CFilterCoder::~CFilterCoder()
|
||||
{
|
||||
::MidFree(_buffer);
|
||||
}
|
||||
|
||||
HRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)
|
||||
@@ -226,7 +226,7 @@ STDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)
|
||||
#endif
|
||||
|
||||
#ifndef EXTRACT_ONLY
|
||||
STDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs,
|
||||
STDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties)
|
||||
{
|
||||
return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \
|
||||
{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \
|
||||
*outObject = (void *)(i *)this; AddRef(); return S_OK; }
|
||||
*outObject = (void *)(i *)this; AddRef(); return S_OK; }
|
||||
|
||||
class CFilterCoder:
|
||||
public ICompressCoder,
|
||||
@@ -46,11 +46,11 @@ protected:
|
||||
UInt64 _outSize;
|
||||
UInt64 _nowPos64;
|
||||
|
||||
HRESULT Init()
|
||||
{
|
||||
HRESULT Init()
|
||||
{
|
||||
_nowPos64 = 0;
|
||||
_outSizeIsDefined = false;
|
||||
return Filter->Init();
|
||||
return Filter->Init();
|
||||
}
|
||||
|
||||
CMyComPtr<ICryptoSetPassword> _setPassword;
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
CFilterCoder();
|
||||
~CFilterCoder();
|
||||
HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);
|
||||
bool NeedMore() const
|
||||
bool NeedMore() const
|
||||
{ return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }
|
||||
|
||||
public:
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
|
||||
#endif
|
||||
#ifndef EXTRACT_ONLY
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties);
|
||||
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
|
||||
// STDMETHOD(ResetSalt)();
|
||||
|
||||
@@ -9,10 +9,10 @@ extern "C"
|
||||
#include "../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
CInBuffer::CInBuffer():
|
||||
_buffer(0),
|
||||
_bufferLimit(0),
|
||||
_bufferBase(0),
|
||||
CInBuffer::CInBuffer():
|
||||
_buffer(0),
|
||||
_bufferLimit(0),
|
||||
_bufferBase(0),
|
||||
_stream(0),
|
||||
_bufferSize(0)
|
||||
{}
|
||||
|
||||
+21
-15
@@ -8,9 +8,9 @@
|
||||
#include "../../Common/MyException.h"
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
struct CInBufferException: public CSystemException
|
||||
struct CInBufferException: public CSystemException
|
||||
{
|
||||
CInBufferException(HRESULT errorCode): CSystemException(errorCode) {}
|
||||
CInBufferException(HRESULT errorCode): CSystemException(errorCode) {}
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -44,29 +44,35 @@ public:
|
||||
|
||||
bool ReadByte(Byte &b)
|
||||
{
|
||||
if(_buffer >= _bufferLimit)
|
||||
if(!ReadBlock())
|
||||
if (_buffer >= _bufferLimit)
|
||||
if (!ReadBlock())
|
||||
return false;
|
||||
b = *_buffer++;
|
||||
return true;
|
||||
}
|
||||
Byte ReadByte()
|
||||
{
|
||||
if(_buffer >= _bufferLimit)
|
||||
if (_buffer >= _bufferLimit)
|
||||
return ReadBlock2();
|
||||
return *_buffer++;
|
||||
}
|
||||
void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
|
||||
UInt32 ReadBytes(Byte *buf, UInt32 size)
|
||||
{
|
||||
for(processedSize = 0; processedSize < size; processedSize++)
|
||||
if (!ReadByte(((Byte *)data)[processedSize]))
|
||||
return;
|
||||
}
|
||||
bool ReadBytes(void *data, UInt32 size)
|
||||
{
|
||||
UInt32 processedSize;
|
||||
ReadBytes(data, size, processedSize);
|
||||
return (processedSize == size);
|
||||
if ((UInt32)(_bufferLimit - _buffer) >= size)
|
||||
{
|
||||
for (UInt32 i = 0; i < size; i++)
|
||||
buf[i] = _buffer[i];
|
||||
_buffer += size;
|
||||
return size;
|
||||
}
|
||||
for (UInt32 i = 0; i < size; i++)
|
||||
{
|
||||
if (_buffer >= _bufferLimit)
|
||||
if (!ReadBlock())
|
||||
return i;
|
||||
buf[i] = *_buffer++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
|
||||
bool WasFinished() const { return _wasFinished; }
|
||||
|
||||
@@ -191,8 +191,8 @@ HRESULT CInMemStreamMt::ReadSubStream(int subStreamIndex, void *data, UInt32 siz
|
||||
if (curPos == Callback->GetBlockSize())
|
||||
needFree = true;
|
||||
blocks.Cs->Enter();
|
||||
if (blocks.CurBlockIndex == blocks.LastBlockIndex &&
|
||||
blocks.CurBlockPos == blocks.LastBlockPos &&
|
||||
if (blocks.CurBlockIndex == blocks.LastBlockIndex &&
|
||||
blocks.CurBlockPos == blocks.LastBlockPos &&
|
||||
blocks.StreamWasFinished)
|
||||
needFree = true;
|
||||
blocks.Cs->Leave();
|
||||
|
||||
@@ -162,7 +162,7 @@ struct IInMemStreamMtCallback
|
||||
// must be same for all calls
|
||||
virtual size_t GetBlockSize() = 0;
|
||||
|
||||
// Out:
|
||||
// Out:
|
||||
// result != S_OK stops Reading
|
||||
// if *p = 0, result must be != S_OK;
|
||||
// Locking is allowed
|
||||
@@ -249,7 +249,7 @@ public:
|
||||
~CInMemStreamMt() { Free(); }
|
||||
void SetStream(ISequentialInStream *stream) { _stream = stream; }
|
||||
|
||||
// to stop reading you must implement
|
||||
// to stop reading you must implement
|
||||
// returning Error in IInMemStreamMtCallback::AllocateBlock
|
||||
// and then you must free at least one substream
|
||||
HRes StartReadThread();
|
||||
@@ -260,7 +260,7 @@ public:
|
||||
// void StopReading() { _stopReading = true; }
|
||||
};
|
||||
|
||||
class CInMemStream:
|
||||
class CInMemStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -269,8 +269,8 @@ class CInMemStream:
|
||||
public:
|
||||
int Index;
|
||||
CInMemStreamMt *mtStream;
|
||||
void Init(bool keepData = false)
|
||||
{
|
||||
void Init(bool keepData = false)
|
||||
{
|
||||
_size = 0; _keepData = keepData ;
|
||||
}
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
HRESULT WriteToStream(ISequentialOutStream *stream);
|
||||
};
|
||||
|
||||
class CSequentialOutTempBufferImp:
|
||||
class CSequentialOutTempBufferImp:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
|
||||
@@ -33,13 +33,13 @@ public:
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = kNumBigValueBits;
|
||||
m_BitPos = kNumBigValueBits;
|
||||
m_Value = 0;
|
||||
NumExtraBytes = 0;
|
||||
}
|
||||
UInt64 GetProcessedSize() const
|
||||
UInt64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
|
||||
UInt64 GetProcessedBitsSize() const
|
||||
UInt64 GetProcessedBitsSize() const
|
||||
{ return (m_Stream.GetProcessedSize() << 3) - (kNumBigValueBits - m_BitPos); }
|
||||
int GetBitPosition() const { return (m_BitPos & 7); }
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = 8;
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
HRESULT Flush()
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
{
|
||||
if(m_BitPos < 8)
|
||||
m_Stream.WriteByte(m_CurByte);
|
||||
m_BitPos = 8;
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
}
|
||||
}
|
||||
UInt32 GetBitPosition() const { return (8 - m_BitPos); }
|
||||
UInt64 GetProcessedSize() const {
|
||||
UInt64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
|
||||
void WriteByte(Byte b) { m_Stream.WriteByte(b);}
|
||||
};
|
||||
|
||||
@@ -22,3 +22,24 @@ STDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *p
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
HRESULT result = S_OK;
|
||||
if (processedSize != NULL)
|
||||
*processedSize = 0;
|
||||
if (size > _size)
|
||||
{
|
||||
size = (UInt32)_size;
|
||||
if (size == 0)
|
||||
{
|
||||
_overflow = true;
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
if (_stream)
|
||||
result = _stream->Write(data, size, &size);
|
||||
_size -= size;
|
||||
if (processedSize != NULL)
|
||||
*processedSize = size;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../../Common/MyCom.h"
|
||||
#include "../IStream.h"
|
||||
|
||||
class CLimitedSequentialInStream:
|
||||
class CLimitedSequentialInStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -16,11 +16,11 @@ class CLimitedSequentialInStream:
|
||||
bool _wasFinished;
|
||||
public:
|
||||
void SetStream(ISequentialInStream *stream) { _stream = stream; }
|
||||
void Init(UInt64 streamSize)
|
||||
{
|
||||
_size = streamSize;
|
||||
_pos = 0;
|
||||
_wasFinished = false;
|
||||
void Init(UInt64 streamSize)
|
||||
{
|
||||
_size = streamSize;
|
||||
_pos = 0;
|
||||
_wasFinished = false;
|
||||
}
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
@@ -30,4 +30,25 @@ public:
|
||||
bool WasFinished() const { return _wasFinished; }
|
||||
};
|
||||
|
||||
class CLimitedSequentialOutStream:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UInt64 _size;
|
||||
bool _overflow;
|
||||
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(UInt64 size)
|
||||
{
|
||||
_size = size;
|
||||
_overflow = false;
|
||||
}
|
||||
bool IsFinishedOK() const { return (_size == 0 && !_overflow); }
|
||||
UInt64 GetRem() const { return _size; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "LockedStream.h"
|
||||
|
||||
HRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size,
|
||||
HRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size,
|
||||
UInt32 *processedSize)
|
||||
{
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
class CLockedSequentialInStreamImp:
|
||||
class CLockedSequentialInStreamImp:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
|
||||
@@ -30,11 +30,11 @@ public:
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = kNumBigValueBits;
|
||||
m_BitPos = kNumBigValueBits;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
UInt64 GetProcessedSize() const
|
||||
UInt64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
|
||||
UInt32 GetBitPosition() const { return (m_BitPos & 7); }
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = 8;
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
HRESULT Flush()
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
m_CurByte = 0;
|
||||
}
|
||||
}
|
||||
UInt64 GetProcessedSize() const {
|
||||
UInt64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) / 8; }
|
||||
};
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ bool CMemBlockManager::AllocateSpace(size_t numBlocks)
|
||||
if (_blockSize < sizeof(void *) || numBlocks < 1)
|
||||
return false;
|
||||
size_t totalSize = numBlocks * _blockSize;
|
||||
if (totalSize / _blockSize != numBlocks)
|
||||
if (totalSize / _blockSize != numBlocks)
|
||||
return false;
|
||||
_data = ::MidAlloc(totalSize);
|
||||
if (_data == 0)
|
||||
@@ -36,7 +36,7 @@ void CMemBlockManager::FreeSpace()
|
||||
void *CMemBlockManager::AllocateBlock()
|
||||
{
|
||||
if (_headFree == 0)
|
||||
return 0;
|
||||
return 0;
|
||||
void *p = _headFree;
|
||||
_headFree = *(void **)_headFree;
|
||||
return p;
|
||||
@@ -114,7 +114,7 @@ void CMemBlocks::Free(CMemBlockManagerMt *manager)
|
||||
void CMemBlocks::FreeOpt(CMemBlockManagerMt *manager)
|
||||
{
|
||||
Free(manager);
|
||||
Blocks.Free(); // to reduce memory usage
|
||||
Blocks.ClearAndFree();
|
||||
}
|
||||
|
||||
HRESULT CMemBlocks::WriteToStream(size_t blockSize, ISequentialOutStream *outStream) const
|
||||
@@ -150,8 +150,8 @@ void CMemLockBlocks::Free(CMemBlockManagerMt *memManager)
|
||||
TotalSize = 0;
|
||||
}
|
||||
|
||||
HRes CMemLockBlocks::SwitchToNoLockMode(CMemBlockManagerMt *memManager)
|
||||
{
|
||||
HRes CMemLockBlocks::SwitchToNoLockMode(CMemBlockManagerMt *memManager)
|
||||
{
|
||||
if (LockMode)
|
||||
{
|
||||
if (Blocks.Size() > 0)
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#ifndef __MEMBLOCKS_H
|
||||
#define __MEMBLOCKS_H
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
void FreeSpace();
|
||||
void *AllocateBlock();
|
||||
void FreeBlock(void *p, bool lockMode = true);
|
||||
HRes ReleaseLockedBlocks(int number) { return Semaphore.Release(number); }
|
||||
HRes ReleaseLockedBlocks(int number) { return Semaphore.Release(number); }
|
||||
};
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ struct CMemLockBlocks: public CMemBlocks
|
||||
CMemLockBlocks(): LockMode(true) {};
|
||||
void Free(CMemBlockManagerMt *memManager);
|
||||
void FreeBlock(int index, CMemBlockManagerMt *memManager);
|
||||
HRes SwitchToNoLockMode(CMemBlockManagerMt *memManager);
|
||||
HRes SwitchToNoLockMode(CMemBlockManagerMt *memManager);
|
||||
void Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager);
|
||||
};
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ struct CMethodsMode
|
||||
|
||||
CMethodsMode()
|
||||
#ifdef COMPRESS_MT
|
||||
: NumThreads(1)
|
||||
: NumThreads(1)
|
||||
#endif
|
||||
{}
|
||||
bool IsEmpty() const { return Methods.IsEmpty() ; }
|
||||
|
||||
@@ -17,7 +17,7 @@ STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *proc
|
||||
return _stream->Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,
|
||||
STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,
|
||||
UInt64 *newPosition)
|
||||
{
|
||||
UInt64 absoluteNewPosition;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "Common/MyCom.h"
|
||||
#include "../IStream.h"
|
||||
|
||||
class COffsetOutStream:
|
||||
class COffsetOutStream:
|
||||
public IOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
|
||||
@@ -46,9 +46,9 @@ void COutBuffer::Init()
|
||||
}
|
||||
|
||||
UInt64 COutBuffer::GetProcessedSize() const
|
||||
{
|
||||
{
|
||||
UInt64 res = _processedSize + _pos - _streamPos;
|
||||
if (_streamPos > _pos)
|
||||
if (_streamPos > _pos)
|
||||
res += _bufferSize;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#include "../../Common/MyException.h"
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
struct COutBufferException: public CSystemException
|
||||
{
|
||||
COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}
|
||||
struct COutBufferException: public CSystemException
|
||||
{
|
||||
COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
HRESULT SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize);
|
||||
};
|
||||
|
||||
class CMtCompressProgress:
|
||||
class CMtCompressProgress:
|
||||
public ICompressProgressInfo,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "../ICoder.h"
|
||||
#include "../IProgress.h"
|
||||
|
||||
class CLocalProgress:
|
||||
class CLocalProgress:
|
||||
public ICompressProgressInfo,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ struct CArcInfo
|
||||
|
||||
void RegisterArc(const CArcInfo *arcInfo);
|
||||
|
||||
#define REGISTER_ARC_NAME(x) CRegister ## x
|
||||
#define REGISTER_ARC_NAME(x) CRegister ## x
|
||||
|
||||
#define REGISTER_ARC_DEC_SIG(x) struct REGISTER_ARC_NAME(x) { \
|
||||
REGISTER_ARC_NAME(x)() { g_ArcInfo.Signature[0]--; RegisterArc(&g_ArcInfo); }}; \
|
||||
|
||||
@@ -18,13 +18,13 @@ struct CCodecInfo
|
||||
|
||||
void RegisterCodec(const CCodecInfo *codecInfo);
|
||||
|
||||
#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x
|
||||
#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x
|
||||
|
||||
#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \
|
||||
REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \
|
||||
static REGISTER_CODEC_NAME(x) g_RegisterCodec;
|
||||
|
||||
#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x
|
||||
#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x
|
||||
#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \
|
||||
REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \
|
||||
RegisterCodec(&g_CodecsInfo[i]); }}; \
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
#include "../../Common/MyWindows.h"
|
||||
#include "../../Common/NewHandler.h"
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
using namespace NWindows;
|
||||
using namespace NSynchronization;
|
||||
|
||||
class CSequentialInStreamForBinder:
|
||||
class CSequentialInStreamForBinder:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
STDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{ return m_StreamBinder->Read(data, size, processedSize); }
|
||||
|
||||
class CSequentialOutStreamForBinder:
|
||||
class CSequentialOutStreamForBinder:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -67,16 +67,16 @@ void CStreamBinder::ReInit()
|
||||
|
||||
|
||||
|
||||
void CStreamBinder::CreateStreams(ISequentialInStream **inStream,
|
||||
void CStreamBinder::CreateStreams(ISequentialInStream **inStream,
|
||||
ISequentialOutStream **outStream)
|
||||
{
|
||||
CSequentialInStreamForBinder *inStreamSpec = new
|
||||
CSequentialInStreamForBinder *inStreamSpec = new
|
||||
CSequentialInStreamForBinder;
|
||||
CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);
|
||||
inStreamSpec->SetBinder(this);
|
||||
*inStream = inStreamLoc.Detach();
|
||||
|
||||
CSequentialOutStreamForBinder *outStreamSpec = new
|
||||
CSequentialOutStreamForBinder *outStreamSpec = new
|
||||
CSequentialOutStreamForBinder;
|
||||
CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);
|
||||
outStreamSpec->SetBinder(this);
|
||||
@@ -96,7 +96,7 @@ HRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
sizeToRead = MyMin(_bufferSize, size);
|
||||
if (_bufferSize > 0)
|
||||
{
|
||||
MoveMemory(data, _buffer, sizeToRead);
|
||||
memcpy(data, _buffer, sizeToRead);
|
||||
_buffer = ((const Byte *)_buffer) + sizeToRead;
|
||||
_bufferSize -= sizeToRead;
|
||||
if (_bufferSize == 0)
|
||||
@@ -126,9 +126,9 @@ HRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSiz
|
||||
_allBytesAreWritenEvent.Reset();
|
||||
_thereAreBytesToReadEvent.Set();
|
||||
|
||||
HANDLE events[2];
|
||||
HANDLE events[2];
|
||||
events[0] = _allBytesAreWritenEvent;
|
||||
events[1] = _readStreamIsClosedEvent;
|
||||
events[1] = _readStreamIsClosedEvent;
|
||||
DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);
|
||||
if (waitResult != WAIT_OBJECT_0 + 0)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
CStreamBinder() {}
|
||||
HRes CreateEvents();
|
||||
|
||||
void CreateStreams(ISequentialInStream **inStream,
|
||||
void CreateStreams(ISequentialInStream **inStream,
|
||||
ISequentialOutStream **outStream);
|
||||
HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);
|
||||
void CloseRead();
|
||||
|
||||
@@ -32,7 +32,7 @@ STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt3
|
||||
_writeBuffer.Write(data, (size_t)size);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
@@ -54,7 +54,7 @@ STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
*processedSize = realProcessedSize;
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
@@ -64,5 +64,5 @@ STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size,
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
*processedSize = realProcessedSize;
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "../../Common/MyCom.h"
|
||||
#include "../IStream.h"
|
||||
|
||||
class CSequentialInStreamImp:
|
||||
class CSequentialInStreamImp:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
const CByteDynamicBuffer& GetBuffer() const { return _buffer; }
|
||||
};
|
||||
|
||||
class CSequentialOutStreamImp:
|
||||
class CSequentialOutStreamImp:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
class CSequentialOutStreamImp2:
|
||||
class CSequentialOutStreamImp2:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -65,11 +65,11 @@ class CSequentialOutStreamImp2:
|
||||
size_t _pos;
|
||||
public:
|
||||
|
||||
void Init(Byte *buffer, size_t size)
|
||||
{
|
||||
void Init(Byte *buffer, size_t size)
|
||||
{
|
||||
_buffer = buffer;
|
||||
_pos = 0;
|
||||
_size = size;
|
||||
_size = size;
|
||||
}
|
||||
|
||||
size_t GetPos() const { return _pos; }
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
class CSequentialInStreamSizeCount:
|
||||
class CSequentialInStreamSizeCount:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
class CSequentialOutStreamSizeCount:
|
||||
class CSequentialOutStreamSizeCount:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSiz
|
||||
while (size != 0)
|
||||
{
|
||||
UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;
|
||||
UInt32 processedSizeLoc;
|
||||
UInt32 processedSizeLoc;
|
||||
HRESULT res = stream->Read(data, curSize, &processedSizeLoc);
|
||||
*processedSize += processedSizeLoc;
|
||||
data = (void *)((Byte *)data + processedSizeLoc);
|
||||
@@ -27,14 +27,14 @@ HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSiz
|
||||
|
||||
HRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size)
|
||||
{
|
||||
size_t processedSize = size;
|
||||
size_t processedSize = size;
|
||||
RINOK(ReadStream(stream, data, &processedSize));
|
||||
return (size == processedSize) ? S_OK : S_FALSE;
|
||||
}
|
||||
|
||||
HRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size)
|
||||
{
|
||||
size_t processedSize = size;
|
||||
size_t processedSize = size;
|
||||
RINOK(ReadStream(stream, data, &processedSize));
|
||||
return (size == processedSize) ? S_OK : E_FAIL;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ HRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size)
|
||||
while (size != 0)
|
||||
{
|
||||
UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;
|
||||
UInt32 processedSizeLoc;
|
||||
UInt32 processedSizeLoc;
|
||||
HRESULT res = stream->Write(data, curSize, &processedSizeLoc);
|
||||
data = (const void *)((const Byte *)data + processedSizeLoc);
|
||||
size -= processedSizeLoc;
|
||||
|
||||
@@ -16,7 +16,7 @@ struct CVirtThread
|
||||
~CVirtThread();
|
||||
WRes Create();
|
||||
void Start();
|
||||
void WaitFinish() { FinishedEvent.Lock(); }
|
||||
void WaitFinish() { FinishedEvent.Lock(); }
|
||||
virtual void Execute() = 0;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user