mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-15 00:11:40 -06:00
3.13
This commit is contained in:
53
7zip/Common/FilePathAutoRename.cpp
Executable file
53
7zip/Common/FilePathAutoRename.cpp
Executable file
@@ -0,0 +1,53 @@
|
||||
// FilePathAutoRename.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "FilePathAutoRename.h"
|
||||
|
||||
#include "Common/Defs.h"
|
||||
#include "Common/IntToString.h"
|
||||
|
||||
#include "Windows/FileName.h"
|
||||
#include "Windows/FileFind.h"
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
static bool MakeAutoName(const UString &name,
|
||||
const UString &extension, int value, UString &path)
|
||||
{
|
||||
wchar_t number[32];
|
||||
ConvertUINT64ToString(value, number);
|
||||
path = name;
|
||||
path += number;
|
||||
path += extension;
|
||||
return NFile::NFind::DoesFileExist(path);
|
||||
}
|
||||
|
||||
bool AutoRenamePath(UString &fullProcessedPath)
|
||||
{
|
||||
UString path;
|
||||
int dotPos = fullProcessedPath.ReverseFind(L'.');
|
||||
int slashDot1 = fullProcessedPath.ReverseFind(L'\\');
|
||||
int slashDot2 = fullProcessedPath.ReverseFind(L'/');
|
||||
int slashDot = MyMin(slashDot1, slashDot2);
|
||||
UString name, extension;
|
||||
if (dotPos > slashDot && dotPos > 0)
|
||||
{
|
||||
name = fullProcessedPath.Left(dotPos);
|
||||
extension = fullProcessedPath.Mid(dotPos);
|
||||
}
|
||||
else
|
||||
name = fullProcessedPath;
|
||||
name += L'_';
|
||||
int indexLeft = 1, indexRight = (1 << 30);
|
||||
while (indexLeft != indexRight)
|
||||
{
|
||||
int indexMid = (indexLeft + indexRight) / 2;
|
||||
if (MakeAutoName(name, extension, indexMid, path))
|
||||
indexLeft = indexMid + 1;
|
||||
else
|
||||
indexRight = indexMid;
|
||||
}
|
||||
if (MakeAutoName(name, extension, indexRight, fullProcessedPath))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
12
7zip/Common/FilePathAutoRename.h
Executable file
12
7zip/Common/FilePathAutoRename.h
Executable file
@@ -0,0 +1,12 @@
|
||||
// Util/FilePathAutoRename.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __FILEPATHAUTORENAME_H
|
||||
#define __FILEPATHAUTORENAME_H
|
||||
|
||||
#include "Common/String.h"
|
||||
|
||||
bool AutoRenamePath(UString &fullProcessedPath);
|
||||
|
||||
#endif
|
||||
110
7zip/Common/FileStreams.cpp
Executable file
110
7zip/Common/FileStreams.cpp
Executable file
@@ -0,0 +1,110 @@
|
||||
// FileStreams.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "FileStreams.h"
|
||||
|
||||
static inline HRESULT ConvertBoolToHRESULT(bool result)
|
||||
{
|
||||
// return result ? S_OK: E_FAIL;
|
||||
return result ? S_OK: (::GetLastError());
|
||||
}
|
||||
|
||||
bool CInFileStream::Open(LPCTSTR fileName)
|
||||
{
|
||||
return File.Open(fileName);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CInFileStream::Open(LPCWSTR fileName)
|
||||
{
|
||||
return File.Open(fileName);
|
||||
}
|
||||
#endif
|
||||
|
||||
STDMETHODIMP CInFileStream::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
bool result = File.Read(data, size, realProcessedSize);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
return ConvertBoolToHRESULT(result);
|
||||
}
|
||||
|
||||
STDMETHODIMP CInFileStream::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
return Read(data, size, processedSize);
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CInFileStream::Seek(INT64 offset, UINT32 seekOrigin,
|
||||
UINT64 *newPosition)
|
||||
{
|
||||
if(seekOrigin >= 3)
|
||||
return STG_E_INVALIDFUNCTION;
|
||||
UINT64 realNewPosition;
|
||||
bool result = File.Seek(offset, seekOrigin, realNewPosition);
|
||||
if(newPosition != NULL)
|
||||
*newPosition = realNewPosition;
|
||||
return ConvertBoolToHRESULT(result);
|
||||
}
|
||||
|
||||
STDMETHODIMP CInFileStream::GetSize(UINT64 *size)
|
||||
{
|
||||
return ConvertBoolToHRESULT(File.GetLength(*size));
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////
|
||||
// COutFileStream
|
||||
|
||||
bool COutFileStream::Open(LPCTSTR fileName)
|
||||
{
|
||||
File.SetOpenCreationDispositionCreateAlways();
|
||||
return File.Open(fileName);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool COutFileStream::Open(LPCWSTR fileName)
|
||||
{
|
||||
File.SetOpenCreationDispositionCreateAlways();
|
||||
return File.Open(fileName);
|
||||
}
|
||||
#endif
|
||||
|
||||
STDMETHODIMP COutFileStream::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
bool result = File.Write(data, size, realProcessedSize);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
return ConvertBoolToHRESULT(result);
|
||||
}
|
||||
|
||||
STDMETHODIMP COutFileStream::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP COutFileStream::Seek(INT64 offset, UINT32 seekOrigin,
|
||||
UINT64 *newPosition)
|
||||
{
|
||||
if(seekOrigin >= 3)
|
||||
return STG_E_INVALIDFUNCTION;
|
||||
UINT64 realNewPosition;
|
||||
bool result = File.Seek(offset, seekOrigin, realNewPosition);
|
||||
if(newPosition != NULL)
|
||||
*newPosition = realNewPosition;
|
||||
return ConvertBoolToHRESULT(result);
|
||||
}
|
||||
|
||||
STDMETHODIMP COutFileStream::SetSize(INT64 newSize)
|
||||
{
|
||||
UINT64 currentPos;
|
||||
if(!File.Seek(0, FILE_CURRENT, currentPos))
|
||||
return E_FAIL;
|
||||
bool result = File.SetLength(newSize);
|
||||
UINT64 currentPos2;
|
||||
result = result && File.Seek(currentPos, currentPos2);
|
||||
return result ? S_OK : E_FAIL;
|
||||
}
|
||||
55
7zip/Common/FileStreams.h
Executable file
55
7zip/Common/FileStreams.h
Executable file
@@ -0,0 +1,55 @@
|
||||
// FileStreams.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __FILESTREAMS_H
|
||||
#define __FILESTREAMS_H
|
||||
|
||||
#include "Windows/FileIO.h"
|
||||
|
||||
#include "../IStream.h"
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
class CInFileStream:
|
||||
public IInStream,
|
||||
public IStreamGetSize,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
NWindows::NFile::NIO::CInFile File;
|
||||
CInFileStream() {}
|
||||
bool Open(LPCTSTR fileName);
|
||||
#ifndef _UNICODE
|
||||
bool Open(LPCWSTR fileName);
|
||||
#endif
|
||||
|
||||
MY_UNKNOWN_IMP1(IStreamGetSize)
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(Seek)(INT64 offset, UINT32 seekOrigin, UINT64 *newPosition);
|
||||
|
||||
STDMETHOD(GetSize)(UINT64 *size);
|
||||
};
|
||||
|
||||
class COutFileStream:
|
||||
public IOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
NWindows::NFile::NIO::COutFile File;
|
||||
COutFileStream() {}
|
||||
bool Open(LPCTSTR fileName);
|
||||
#ifndef _UNICODE
|
||||
bool Open(LPCWSTR fileName);
|
||||
#endif
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(Seek)(INT64 offset, UINT32 seekOrigin, UINT64 *newPosition);
|
||||
STDMETHOD(SetSize)(INT64 newSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
41
7zip/Common/InBuffer.cpp
Executable file
41
7zip/Common/InBuffer.cpp
Executable file
@@ -0,0 +1,41 @@
|
||||
// InBuffer.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "InBuffer.h"
|
||||
|
||||
CInBuffer::CInBuffer(UINT32 bufferSize):
|
||||
_bufferSize(bufferSize),
|
||||
_bufferBase(0)
|
||||
{
|
||||
_bufferBase = new BYTE[_bufferSize];
|
||||
}
|
||||
|
||||
CInBuffer::~CInBuffer()
|
||||
{
|
||||
delete []_bufferBase;
|
||||
}
|
||||
|
||||
void CInBuffer::Init(ISequentialInStream *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
_processedSize = 0;
|
||||
_buffer = _bufferBase;
|
||||
_bufferLimit = _buffer;
|
||||
_streamWasExhausted = false;
|
||||
}
|
||||
|
||||
bool CInBuffer::ReadBlock()
|
||||
{
|
||||
if (_streamWasExhausted)
|
||||
return false;
|
||||
_processedSize += (_buffer - _bufferBase);
|
||||
UINT32 numProcessedBytes;
|
||||
HRESULT result = _stream->ReadPart(_bufferBase, _bufferSize, &numProcessedBytes);
|
||||
if (result != S_OK)
|
||||
throw CInBufferException(result);
|
||||
_buffer = _bufferBase;
|
||||
_bufferLimit = _buffer + numProcessedBytes;
|
||||
_streamWasExhausted = (numProcessedBytes == 0);
|
||||
return (!_streamWasExhausted);
|
||||
}
|
||||
66
7zip/Common/InBuffer.h
Executable file
66
7zip/Common/InBuffer.h
Executable file
@@ -0,0 +1,66 @@
|
||||
// InBuffer.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __INBUFFER_H
|
||||
#define __INBUFFER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
|
||||
class CInBufferException
|
||||
{
|
||||
public:
|
||||
HRESULT ErrorCode;
|
||||
CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
||||
};
|
||||
|
||||
class CInBuffer
|
||||
{
|
||||
UINT64 _processedSize;
|
||||
BYTE *_bufferBase;
|
||||
UINT32 _bufferSize;
|
||||
BYTE *_buffer;
|
||||
BYTE *_bufferLimit;
|
||||
ISequentialInStream *_stream;
|
||||
bool _streamWasExhausted;
|
||||
|
||||
bool ReadBlock();
|
||||
|
||||
public:
|
||||
CInBuffer(UINT32 bufferSize = 0x100000);
|
||||
~CInBuffer();
|
||||
|
||||
void Init(ISequentialInStream *stream);
|
||||
// void ReleaseStream() { _stream.Release(); }
|
||||
|
||||
bool ReadByte(BYTE &b)
|
||||
{
|
||||
if(_buffer >= _bufferLimit)
|
||||
if(!ReadBlock())
|
||||
return false;
|
||||
b = *_buffer++;
|
||||
return true;
|
||||
}
|
||||
BYTE ReadByte()
|
||||
{
|
||||
if(_buffer >= _bufferLimit)
|
||||
if(!ReadBlock())
|
||||
return 0x0;
|
||||
return *_buffer++;
|
||||
}
|
||||
void ReadBytes(void *data, UINT32 size, UINT32 &processedSize)
|
||||
{
|
||||
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);
|
||||
}
|
||||
UINT64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
|
||||
};
|
||||
|
||||
#endif
|
||||
148
7zip/Common/InOutTempBuffer.cpp
Executable file
148
7zip/Common/InOutTempBuffer.cpp
Executable file
@@ -0,0 +1,148 @@
|
||||
// InOutTempBuffer.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "InOutTempBuffer.h"
|
||||
#include "../../Common/Defs.h"
|
||||
// #include "Windows/Defs.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NFile;
|
||||
using namespace NDirectory;
|
||||
|
||||
static UINT32 kTmpBufferMemorySize = (1 << 20);
|
||||
|
||||
static LPCTSTR kTempFilePrefixString = TEXT("iot");
|
||||
|
||||
CInOutTempBuffer::CInOutTempBuffer():
|
||||
_buffer(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void CInOutTempBuffer::Create()
|
||||
{
|
||||
_buffer = new BYTE[kTmpBufferMemorySize];
|
||||
}
|
||||
|
||||
CInOutTempBuffer::~CInOutTempBuffer()
|
||||
{
|
||||
delete []_buffer;
|
||||
}
|
||||
void CInOutTempBuffer::InitWriting()
|
||||
{
|
||||
_bufferPosition = 0;
|
||||
_tmpFileCreated = false;
|
||||
_fileSize = 0;
|
||||
}
|
||||
|
||||
bool CInOutTempBuffer::WriteToFile(const void *data, UINT32 size)
|
||||
{
|
||||
if (size == 0)
|
||||
return true;
|
||||
if(!_tmpFileCreated)
|
||||
{
|
||||
CSysString tempDirPath;
|
||||
if(!MyGetTempPath(tempDirPath))
|
||||
return false;
|
||||
if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)
|
||||
return false;
|
||||
_outFile.SetOpenCreationDispositionCreateAlways();
|
||||
if(!_outFile.Open(_tmpFileName))
|
||||
return false;
|
||||
_tmpFileCreated = true;
|
||||
}
|
||||
UINT32 processedSize;
|
||||
if(!_outFile.Write(data, size, processedSize))
|
||||
return false;
|
||||
_fileSize += processedSize;
|
||||
return (processedSize == size);
|
||||
}
|
||||
|
||||
bool CInOutTempBuffer::FlushWrite()
|
||||
{
|
||||
return _outFile.Close();
|
||||
}
|
||||
|
||||
bool CInOutTempBuffer::Write(const void *data, UINT32 size)
|
||||
{
|
||||
UINT32 numBytes = 0;
|
||||
if(_bufferPosition < kTmpBufferMemorySize)
|
||||
{
|
||||
UINT32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);
|
||||
memmove(_buffer + _bufferPosition, (const BYTE *)data, curSize);
|
||||
_bufferPosition += curSize;
|
||||
size -= curSize;
|
||||
data = ((const BYTE *)data) + curSize;
|
||||
_fileSize += curSize;
|
||||
}
|
||||
return WriteToFile(data, size);
|
||||
}
|
||||
|
||||
bool CInOutTempBuffer::InitReading()
|
||||
{
|
||||
_currentPositionInBuffer = 0;
|
||||
if(_tmpFileCreated)
|
||||
return _inFile.Open(_tmpFileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
bool CInOutTempBuffer::Read(void *data, UINT32 maxSize, UINT32 &processedSize)
|
||||
{
|
||||
processedSize = 0;
|
||||
if (_currentPositionInBuffer < _bufferPosition)
|
||||
{
|
||||
UINT32 sizeToRead = MyMin(_bufferPosition - _currentPositionInBuffer, maxSize);
|
||||
memmove(data, _buffer + _currentPositionInBuffer, sizeToRead);
|
||||
data = ((BYTE *)data) + sizeToRead;
|
||||
_currentPositionInBuffer += sizeToRead;
|
||||
processedSize += sizeToRead;
|
||||
maxSize -= sizeToRead;
|
||||
}
|
||||
if (maxSize == 0 || !_tmpFileCreated)
|
||||
return true;
|
||||
UINT32 localProcessedSize;
|
||||
bool result = _inFile.Read(data, maxSize, localProcessedSize);
|
||||
processedSize += localProcessedSize;
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
|
||||
{
|
||||
if (_currentPositionInBuffer < _bufferPosition)
|
||||
{
|
||||
UINT32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;
|
||||
RINOK(stream->Write(_buffer + _currentPositionInBuffer, sizeToWrite, NULL));
|
||||
_currentPositionInBuffer += sizeToWrite;
|
||||
}
|
||||
if (!_tmpFileCreated)
|
||||
return true;
|
||||
while(true)
|
||||
{
|
||||
UINT32 localProcessedSize;
|
||||
if (!_inFile.Read(_buffer, kTmpBufferMemorySize, localProcessedSize))
|
||||
return E_FAIL;
|
||||
if (localProcessedSize == 0)
|
||||
return S_OK;
|
||||
RINOK(stream->Write(_buffer, localProcessedSize, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
if (!_buffer->Write(data, size))
|
||||
{
|
||||
if (processedSize != NULL)
|
||||
*processedSize = 0;
|
||||
return E_FAIL;
|
||||
}
|
||||
if (processedSize != NULL)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutTempBufferImp::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
59
7zip/Common/InOutTempBuffer.h
Executable file
59
7zip/Common/InOutTempBuffer.h
Executable file
@@ -0,0 +1,59 @@
|
||||
// Util/InOutTempBuffer.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __INOUTTEMPBUFFER_H
|
||||
#define __INOUTTEMPBUFFER_H
|
||||
|
||||
#include "../../Windows/FileIO.h"
|
||||
#include "../../Windows/FileDir.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
|
||||
#include "../IStream.h"
|
||||
|
||||
class CInOutTempBuffer
|
||||
{
|
||||
NWindows::NFile::NDirectory::CTempFile _tempFile;
|
||||
NWindows::NFile::NIO::COutFile _outFile;
|
||||
NWindows::NFile::NIO::CInFile _inFile;
|
||||
BYTE *_buffer;
|
||||
UINT32 _bufferPosition;
|
||||
UINT32 _currentPositionInBuffer;
|
||||
CSysString _tmpFileName;
|
||||
bool _tmpFileCreated;
|
||||
|
||||
UINT64 _fileSize;
|
||||
|
||||
bool WriteToFile(const void *data, UINT32 size);
|
||||
public:
|
||||
CInOutTempBuffer();
|
||||
~CInOutTempBuffer();
|
||||
void Create();
|
||||
|
||||
void InitWriting();
|
||||
bool Write(const void *data, UINT32 size);
|
||||
UINT64 GetDataSize() const { return _fileSize; }
|
||||
bool FlushWrite();
|
||||
bool InitReading();
|
||||
// bool Read(void *data, UINT32 maxSize, UINT32 &processedSize);
|
||||
HRESULT WriteToStream(ISequentialOutStream *stream);
|
||||
};
|
||||
|
||||
class CSequentialOutTempBufferImp:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CInOutTempBuffer *_buffer;
|
||||
public:
|
||||
// CSequentialOutStreamImp(): _size(0) {}
|
||||
// UINT32 _size;
|
||||
void Init(CInOutTempBuffer *buffer) { _buffer = buffer; }
|
||||
// UINT32 GetSize() const { return _size; }
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
34
7zip/Common/LSBFDecoder.cpp
Executable file
34
7zip/Common/LSBFDecoder.cpp
Executable file
@@ -0,0 +1,34 @@
|
||||
// Stream/LSBFDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LSBFDecoder.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
BYTE kInvertTable[256];
|
||||
|
||||
class CInverterTableInitializer
|
||||
{
|
||||
public:
|
||||
CInverterTableInitializer()
|
||||
{
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
BYTE b = BYTE(i);
|
||||
BYTE bInvert = 0;
|
||||
for(int j = 0; j < 8; j++)
|
||||
{
|
||||
bInvert <<= 1;
|
||||
if (b & 1)
|
||||
bInvert |= 1;
|
||||
b >>= 1;
|
||||
}
|
||||
kInvertTable[i] = bInvert;
|
||||
}
|
||||
}
|
||||
} g_InverterTableInitializer;
|
||||
|
||||
|
||||
}}
|
||||
96
7zip/Common/LSBFDecoder.h
Executable file
96
7zip/Common/LSBFDecoder.h
Executable file
@@ -0,0 +1,96 @@
|
||||
// Stream/LSBFDecoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAM_LSBFDECODER_H
|
||||
#define __STREAM_LSBFDECODER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
const int kNumBigValueBits = 8 * 4;
|
||||
|
||||
const int kNumValueBytes = 3;
|
||||
const int kNumValueBits = 8 * kNumValueBytes;
|
||||
|
||||
const UINT32 kMask = (1 << kNumValueBits) - 1;
|
||||
|
||||
extern BYTE kInvertTable[256];
|
||||
// the Least Significant Bit of byte is First
|
||||
|
||||
template<class TInByte>
|
||||
class CDecoder
|
||||
{
|
||||
UINT32 m_BitPos;
|
||||
UINT32 m_Value;
|
||||
UINT32 m_NormalValue;
|
||||
protected:
|
||||
TInByte m_Stream;
|
||||
public:
|
||||
UINT32 NumExtraBytes;
|
||||
void Init(ISequentialInStream *inStream)
|
||||
{
|
||||
m_Stream.Init(inStream);
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
m_BitPos = kNumBigValueBits;
|
||||
m_NormalValue = 0;
|
||||
NumExtraBytes = 0;
|
||||
}
|
||||
/*
|
||||
void ReleaseStream()
|
||||
{
|
||||
m_Stream.ReleaseStream();
|
||||
}
|
||||
*/
|
||||
UINT64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
|
||||
UINT64 GetProcessedBitsSize() const
|
||||
{ return (m_Stream.GetProcessedSize() << 3) - (kNumBigValueBits - m_BitPos); }
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
for (;m_BitPos >= 8; m_BitPos -= 8)
|
||||
{
|
||||
BYTE b;
|
||||
if (!m_Stream.ReadByte(b))
|
||||
NumExtraBytes++;
|
||||
m_NormalValue = (b << (kNumBigValueBits - m_BitPos)) | m_NormalValue;
|
||||
m_Value = (m_Value << 8) | kInvertTable[b];
|
||||
}
|
||||
}
|
||||
|
||||
UINT32 GetValue(UINT32 numBits)
|
||||
{
|
||||
Normalize();
|
||||
return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits);
|
||||
}
|
||||
|
||||
void MovePos(UINT32 numBits)
|
||||
{
|
||||
m_BitPos += numBits;
|
||||
m_NormalValue >>= numBits;
|
||||
}
|
||||
|
||||
UINT32 ReadBits(UINT32 numBits)
|
||||
{
|
||||
Normalize();
|
||||
UINT32 res = m_NormalValue & ( (1 << numBits) - 1);
|
||||
MovePos(numBits);
|
||||
return res;
|
||||
}
|
||||
|
||||
UINT32 GetBitPosition() const
|
||||
{
|
||||
return (m_BitPos & 7);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
46
7zip/Common/LSBFEncoder.cpp
Executable file
46
7zip/Common/LSBFEncoder.cpp
Executable file
@@ -0,0 +1,46 @@
|
||||
// LSBFEncoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LSBFEncoder.h"
|
||||
#include "Common/Defs.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
void CEncoder::WriteBits(UINT32 aValue, UINT32 aNumBits)
|
||||
{
|
||||
while(aNumBits > 0)
|
||||
{
|
||||
UINT32 aNumNewBits = MyMin(aNumBits, m_BitPos);
|
||||
aNumBits -= aNumNewBits;
|
||||
|
||||
UINT32 aMask = (1 << aNumNewBits) - 1;
|
||||
m_CurByte |= (aValue & aMask) << (8 - m_BitPos);
|
||||
aValue >>= aNumNewBits;
|
||||
|
||||
m_BitPos -= aNumNewBits;
|
||||
|
||||
if (m_BitPos == 0)
|
||||
{
|
||||
m_Stream.WriteByte(m_CurByte);
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CReverseEncoder::WriteBits(UINT32 aValue, UINT32 aNumBits)
|
||||
{
|
||||
UINT32 aReverseValue = 0;
|
||||
for(UINT32 i = 0; i < aNumBits; i++)
|
||||
{
|
||||
aReverseValue <<= 1;
|
||||
aReverseValue |= aValue & 1;
|
||||
aValue >>= 1;
|
||||
}
|
||||
m_Encoder->WriteBits(aReverseValue, aNumBits);
|
||||
}
|
||||
|
||||
}}
|
||||
59
7zip/Common/LSBFEncoder.h
Executable file
59
7zip/Common/LSBFEncoder.h
Executable file
@@ -0,0 +1,59 @@
|
||||
// Stream/LSBFEncoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAM_LSBFENCODER_H
|
||||
#define __STREAM_LSBFENCODER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
#include "OutBuffer.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
class CEncoder
|
||||
{
|
||||
COutBuffer m_Stream;
|
||||
UINT32 m_BitPos;
|
||||
BYTE m_CurByte;
|
||||
public:
|
||||
void Init(ISequentialOutStream *aStream)
|
||||
{
|
||||
m_Stream.Init(aStream);
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
HRESULT Flush()
|
||||
{
|
||||
if(m_BitPos < 8)
|
||||
WriteBits(0, m_BitPos);
|
||||
return m_Stream.Flush();
|
||||
}
|
||||
/*
|
||||
void ReleaseStream()
|
||||
{
|
||||
m_Stream.ReleaseStream();
|
||||
}
|
||||
*/
|
||||
|
||||
void WriteBits(UINT32 aValue, UINT32 aNumBits);
|
||||
|
||||
UINT32 GetBitPosition() const
|
||||
{ return (8 - m_BitPos); }
|
||||
|
||||
UINT64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
|
||||
};
|
||||
|
||||
class CReverseEncoder
|
||||
{
|
||||
CEncoder *m_Encoder;
|
||||
public:
|
||||
void Init(CEncoder *anEncoder)
|
||||
{ m_Encoder = anEncoder; }
|
||||
void WriteBits(UINT32 aValue, UINT32 aNumBits);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
36
7zip/Common/LimitedStreams.cpp
Executable file
36
7zip/Common/LimitedStreams.cpp
Executable file
@@ -0,0 +1,36 @@
|
||||
// LimitedStreams.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LimitedStreams.h"
|
||||
#include "../../Common/Defs.h"
|
||||
|
||||
void CLimitedSequentialInStream::Init(ISequentialInStream *stream, UINT64 streamSize)
|
||||
{
|
||||
_stream = stream;
|
||||
_size = streamSize;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLimitedSequentialInStream::Read(void *data,
|
||||
UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 processedSizeReal;
|
||||
UINT32 sizeToRead = UINT32(MyMin(_size, UINT64(size)));
|
||||
HRESULT result = _stream->Read(data, sizeToRead, &processedSizeReal);
|
||||
_size -= processedSizeReal;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = processedSizeReal;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLimitedSequentialInStream::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 processedSizeReal;
|
||||
UINT32 sizeToRead = UINT32(MyMin(_size, UINT64(size)));
|
||||
HRESULT result = _stream->ReadPart(data, sizeToRead, &processedSizeReal);
|
||||
_size -= processedSizeReal;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = processedSizeReal;
|
||||
return result;
|
||||
}
|
||||
|
||||
26
7zip/Common/LimitedStreams.h
Executable file
26
7zip/Common/LimitedStreams.h
Executable file
@@ -0,0 +1,26 @@
|
||||
// LimitedStreams.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __LIMITEDSTREAMS_H
|
||||
#define __LIMITEDSTREAMS_H
|
||||
|
||||
#include "../../Common/MyCom.h"
|
||||
#include "../IStream.h"
|
||||
|
||||
class CLimitedSequentialInStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
UINT64 _size;
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
public:
|
||||
void Init(ISequentialInStream *stream, UINT64 streamSize);
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
73
7zip/Common/MSBFDecoder.h
Executable file
73
7zip/Common/MSBFDecoder.h
Executable file
@@ -0,0 +1,73 @@
|
||||
// Stream/MSBFDecoder.h
|
||||
// the Most Significant Bit of byte is First
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAM_MSBFDECODER_H
|
||||
#define __STREAM_MSBFDECODER_H
|
||||
|
||||
namespace NStream {
|
||||
namespace NMSBF {
|
||||
|
||||
const int kNumBigValueBits = 8 * 4;
|
||||
|
||||
const int kNumValueBytes = 3;
|
||||
const int kNumValueBits = 8 * kNumValueBytes;
|
||||
|
||||
const UINT32 kMask = (1 << kNumValueBits) - 1;
|
||||
|
||||
template<class TInByte>
|
||||
class CDecoder
|
||||
{
|
||||
TInByte m_Stream;
|
||||
UINT32 m_BitPos;
|
||||
UINT32 m_Value;
|
||||
|
||||
public:
|
||||
|
||||
void Init(ISequentialInStream *aStream)
|
||||
{
|
||||
m_Stream.Init(aStream);
|
||||
m_BitPos = kNumBigValueBits;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
/*
|
||||
void ReleaseStream()
|
||||
{
|
||||
m_Stream.ReleaseStream();
|
||||
}
|
||||
*/
|
||||
|
||||
UINT64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
for (;m_BitPos >= 8; m_BitPos -= 8)
|
||||
m_Value = (m_Value << 8) | m_Stream.ReadByte();
|
||||
}
|
||||
|
||||
UINT32 GetValue(UINT32 aNumBits) const
|
||||
{
|
||||
// return (m_Value << m_BitPos) >> (kNumBigValueBits - aNumBits);
|
||||
return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - aNumBits);
|
||||
}
|
||||
|
||||
void MovePos(UINT32 aNumBits)
|
||||
{
|
||||
m_BitPos += aNumBits;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
UINT32 ReadBits(UINT32 aNumBits)
|
||||
{
|
||||
UINT32 aRes = GetValue(aNumBits);
|
||||
MovePos(aNumBits);
|
||||
return aRes;
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
70
7zip/Common/MSBFEncoder.h
Executable file
70
7zip/Common/MSBFEncoder.h
Executable file
@@ -0,0 +1,70 @@
|
||||
// Stream/MSBFEncoder.h
|
||||
// the Most Significant Bit of byte is First
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAM_MSBFENCODER_H
|
||||
#define __STREAM_MSBFENCODER_H
|
||||
|
||||
#include "Common/Defs.h"
|
||||
#include "Interface/IInOutStreams.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NMSBF {
|
||||
|
||||
template<class TOutByte>
|
||||
class CEncoder
|
||||
{
|
||||
TOutByte m_Stream;
|
||||
UINT32 m_BitPos;
|
||||
BYTE m_CurByte;
|
||||
public:
|
||||
void Init(ISequentialOutStream *aStream)
|
||||
{
|
||||
m_Stream.Init(aStream);
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
HRESULT Flush()
|
||||
{
|
||||
if(m_BitPos < 8)
|
||||
WriteBits(0, m_BitPos);
|
||||
return m_Stream.Flush();
|
||||
}
|
||||
|
||||
void ReleaseStream()
|
||||
{
|
||||
m_Stream.ReleaseStream();
|
||||
}
|
||||
|
||||
void WriteBits(UINT32 aValue, UINT32 aNumBits)
|
||||
{
|
||||
while(aNumBits > 0)
|
||||
{
|
||||
UINT32 aNumNewBits = MyMin(aNumBits, m_BitPos);
|
||||
aNumBits -= aNumNewBits;
|
||||
|
||||
|
||||
m_CurByte <<= aNumNewBits;
|
||||
UINT32 aNewBits = aValue >> aNumBits;
|
||||
m_CurByte |= BYTE(aNewBits);
|
||||
aValue -= (aNewBits << aNumBits);
|
||||
|
||||
|
||||
m_BitPos -= aNumNewBits;
|
||||
|
||||
if (m_BitPos == 0)
|
||||
{
|
||||
m_Stream.WriteByte(m_CurByte);
|
||||
m_BitPos = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
UINT64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
42
7zip/Common/MultiStream.cpp
Executable file
42
7zip/Common/MultiStream.cpp
Executable file
@@ -0,0 +1,42 @@
|
||||
// MultiStream.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "MultiStream.h"
|
||||
|
||||
HRESULT CLockedInStream::Read(UINT64 startPos, void *data, UINT32 size,
|
||||
UINT32 *processedSize)
|
||||
{
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
|
||||
RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));
|
||||
return _stream->Read(data, size, processedSize);
|
||||
}
|
||||
|
||||
HRESULT CLockedInStream::ReadPart(UINT64 startPos, void *data, UINT32 size,
|
||||
UINT32 *processedSize)
|
||||
{
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
|
||||
RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));
|
||||
return _stream->ReadPart(data, size, processedSize);
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize = 0;
|
||||
HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);
|
||||
_pos += realProcessedSize;
|
||||
if (processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLockedSequentialInStreamImp::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize = 0;
|
||||
HRESULT result = _lockedInStream->ReadPart(_pos, data, size, &realProcessedSize);
|
||||
_pos += realProcessedSize;
|
||||
if (processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
return result;
|
||||
}
|
||||
42
7zip/Common/MultiStream.h
Executable file
42
7zip/Common/MultiStream.h
Executable file
@@ -0,0 +1,42 @@
|
||||
// MultiStream.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MULTISTREAM_H
|
||||
#define __MULTISTREAM_H
|
||||
|
||||
#include "../../Windows/Synchronization.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
#include "../IStream.h"
|
||||
|
||||
class CLockedInStream
|
||||
{
|
||||
CMyComPtr<IInStream> _stream;
|
||||
NWindows::NSynchronization::CCriticalSection _criticalSection;
|
||||
public:
|
||||
void Init(IInStream *stream)
|
||||
{ _stream = stream; }
|
||||
HRESULT Read(UINT64 startPos, void *data, UINT32 size, UINT32 *processedSize);
|
||||
HRESULT ReadPart(UINT64 startPos, void *data, UINT32 size, UINT32 *processedSize);
|
||||
};
|
||||
|
||||
class CLockedSequentialInStreamImp:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLockedInStream *_lockedInStream;
|
||||
UINT64 _pos;
|
||||
public:
|
||||
void Init(CLockedInStream *lockedInStream, UINT64 startPos)
|
||||
{
|
||||
_lockedInStream = lockedInStream;
|
||||
_pos = startPos;
|
||||
}
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
41
7zip/Common/OffsetStream.cpp
Executable file
41
7zip/Common/OffsetStream.cpp
Executable file
@@ -0,0 +1,41 @@
|
||||
// OffsetStream.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Common/Defs.h"
|
||||
#include "OffsetStream.h"
|
||||
|
||||
HRESULT COffsetOutStream::Init(IOutStream *stream, UINT64 offset)
|
||||
{
|
||||
_offset = offset;
|
||||
_stream = stream;
|
||||
return _stream->Seek(offset, STREAM_SEEK_SET, NULL);
|
||||
}
|
||||
|
||||
STDMETHODIMP COffsetOutStream::Write(const void *data, UINT32 size,
|
||||
UINT32 *processedSize)
|
||||
{
|
||||
return _stream->Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
STDMETHODIMP COffsetOutStream::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
return _stream->WritePart(data, size, processedSize);
|
||||
}
|
||||
|
||||
STDMETHODIMP COffsetOutStream::Seek(INT64 offset, UINT32 seekOrigin,
|
||||
UINT64 *newPosition)
|
||||
{
|
||||
UINT64 absoluteNewPosition;
|
||||
if (seekOrigin == STREAM_SEEK_SET)
|
||||
offset += _offset;
|
||||
HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);
|
||||
if (newPosition != NULL)
|
||||
*newPosition = absoluteNewPosition - _offset;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP COffsetOutStream::SetSize(INT64 newSize)
|
||||
{
|
||||
return _stream->SetSize(_offset + newSize);
|
||||
}
|
||||
28
7zip/Common/OffsetStream.h
Executable file
28
7zip/Common/OffsetStream.h
Executable file
@@ -0,0 +1,28 @@
|
||||
// OffsetStream.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __OFFSETSTREAM_H
|
||||
#define __OFFSETSTREAM_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "../IStream.h"
|
||||
|
||||
class COffsetOutStream:
|
||||
public IOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
UINT64 _offset;
|
||||
CMyComPtr<IOutStream> _stream;
|
||||
public:
|
||||
HRESULT Init(IOutStream *stream, UINT64 offset);
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(Seek)(INT64 offset, UINT32 seekOrigin, UINT64 *newPosition);
|
||||
STDMETHOD(SetSize)(INT64 newSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
53
7zip/Common/OutBuffer.cpp
Executable file
53
7zip/Common/OutBuffer.cpp
Executable file
@@ -0,0 +1,53 @@
|
||||
// Stream/OutByte.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "OutBuffer.h"
|
||||
|
||||
COutBuffer::COutBuffer(UINT32 bufferSize):
|
||||
_bufferSize(bufferSize)
|
||||
{
|
||||
_buffer = new BYTE[_bufferSize];
|
||||
}
|
||||
|
||||
COutBuffer::~COutBuffer()
|
||||
{
|
||||
delete []_buffer;
|
||||
}
|
||||
|
||||
void COutBuffer::Init(ISequentialOutStream *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
_processedSize = 0;
|
||||
_pos = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
void COutBuffer::ReleaseStream()
|
||||
{
|
||||
_stream.Release();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
HRESULT COutBuffer::Flush()
|
||||
{
|
||||
if (_pos == 0)
|
||||
return S_OK;
|
||||
UINT32 processedSize;
|
||||
HRESULT result = _stream->Write(_buffer, _pos, &processedSize);
|
||||
if (result != S_OK)
|
||||
return result;
|
||||
if (_pos != processedSize)
|
||||
return E_FAIL;
|
||||
_processedSize += processedSize;
|
||||
_pos = 0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void COutBuffer::WriteBlock()
|
||||
{
|
||||
HRESULT result = Flush();
|
||||
if (result != S_OK)
|
||||
throw COutBufferException(result);
|
||||
}
|
||||
62
7zip/Common/OutBuffer.h
Executable file
62
7zip/Common/OutBuffer.h
Executable file
@@ -0,0 +1,62 @@
|
||||
// OutBuffer.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __OUTBUFFER_H
|
||||
#define __OUTBUFFER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
|
||||
class COutBufferException
|
||||
{
|
||||
public:
|
||||
HRESULT ErrorCode;
|
||||
COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
||||
};
|
||||
|
||||
class COutBuffer
|
||||
{
|
||||
BYTE *_buffer;
|
||||
UINT32 _pos;
|
||||
UINT32 _bufferSize;
|
||||
ISequentialOutStream *_stream;
|
||||
UINT64 _processedSize;
|
||||
|
||||
void WriteBlock();
|
||||
public:
|
||||
COutBuffer(UINT32 bufferSize = (1 << 20));
|
||||
~COutBuffer();
|
||||
|
||||
void Init(ISequentialOutStream *stream);
|
||||
HRESULT Flush();
|
||||
// void ReleaseStream();
|
||||
|
||||
void *GetBuffer(UINT32 &sizeAvail)
|
||||
{
|
||||
sizeAvail = _bufferSize - _pos;
|
||||
return _buffer + _pos;
|
||||
}
|
||||
void MovePos(UINT32 num)
|
||||
{
|
||||
_pos += num;
|
||||
if(_pos >= _bufferSize)
|
||||
WriteBlock();
|
||||
}
|
||||
|
||||
|
||||
void WriteByte(BYTE b)
|
||||
{
|
||||
_buffer[_pos++] = b;
|
||||
if(_pos >= _bufferSize)
|
||||
WriteBlock();
|
||||
}
|
||||
void WriteBytes(const void *data, UINT32 size)
|
||||
{
|
||||
for (UINT32 i = 0; i < size; i++)
|
||||
WriteByte(((const BYTE *)data)[i]);
|
||||
}
|
||||
|
||||
UINT64 GetProcessedSize() const { return _processedSize + _pos; }
|
||||
};
|
||||
|
||||
#endif
|
||||
58
7zip/Common/ProgressUtils.cpp
Executable file
58
7zip/Common/ProgressUtils.cpp
Executable file
@@ -0,0 +1,58 @@
|
||||
// ProgressUtils.h
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ProgressUtils.h"
|
||||
|
||||
void CLocalCompressProgressInfo::Init(ICompressProgressInfo *progress,
|
||||
const UINT64 *inStartValue, const UINT64 *outStartValue)
|
||||
{
|
||||
_progress = progress;
|
||||
_inStartValueIsAssigned = (inStartValue != NULL);
|
||||
if (_inStartValueIsAssigned)
|
||||
_inStartValue = *inStartValue;
|
||||
_outStartValueIsAssigned = (outStartValue != NULL);
|
||||
if (_outStartValueIsAssigned)
|
||||
_outStartValue = *outStartValue;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLocalCompressProgressInfo::SetRatioInfo(
|
||||
const UINT64 *inSize, const UINT64 *outSize)
|
||||
{
|
||||
UINT64 inSizeNew, outSizeNew;
|
||||
const UINT64 *inSizeNewPointer;
|
||||
const UINT64 *outSizeNewPointer;
|
||||
if (_inStartValueIsAssigned && inSize != NULL)
|
||||
{
|
||||
inSizeNew = _inStartValue + (*inSize);
|
||||
inSizeNewPointer = &inSizeNew;
|
||||
}
|
||||
else
|
||||
inSizeNewPointer = NULL;
|
||||
|
||||
if (_outStartValueIsAssigned && outSize != NULL)
|
||||
{
|
||||
outSizeNew = _outStartValue + (*outSize);
|
||||
outSizeNewPointer = &outSizeNew;
|
||||
}
|
||||
else
|
||||
outSizeNewPointer = NULL;
|
||||
return _progress->SetRatioInfo(inSizeNewPointer, outSizeNewPointer);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
//
|
||||
|
||||
void CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)
|
||||
{
|
||||
_progress = progress;
|
||||
_inSizeIsMain = inSizeIsMain;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLocalProgress::SetRatioInfo(
|
||||
const UINT64 *inSize, const UINT64 *outSize)
|
||||
{
|
||||
return _progress->SetCompleted(_inSizeIsMain ? inSize : outSize);
|
||||
}
|
||||
|
||||
50
7zip/Common/ProgressUtils.h
Executable file
50
7zip/Common/ProgressUtils.h
Executable file
@@ -0,0 +1,50 @@
|
||||
// ProgressUtils.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __PROGRESSUTILS_H
|
||||
#define __PROGRESSUTILS_H
|
||||
|
||||
#include "../../Common/MyCom.h"
|
||||
|
||||
#include "../ICoder.h"
|
||||
#include "../IProgress.h"
|
||||
|
||||
class CLocalCompressProgressInfo:
|
||||
public ICompressProgressInfo,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ICompressProgressInfo> _progress;
|
||||
bool _inStartValueIsAssigned;
|
||||
bool _outStartValueIsAssigned;
|
||||
UINT64 _inStartValue;
|
||||
UINT64 _outStartValue;
|
||||
public:
|
||||
void Init(ICompressProgressInfo *progress,
|
||||
const UINT64 *inStartValue, const UINT64 *outStartValue);
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(SetRatioInfo)(const UINT64 *inSize, const UINT64 *outSize);
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////
|
||||
// CLocalProgress
|
||||
|
||||
class CLocalProgress:
|
||||
public ICompressProgressInfo,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<IProgress> _progress;
|
||||
bool _inSizeIsMain;
|
||||
public:
|
||||
void Init(IProgress *progress, bool inSizeIsMain);
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(SetRatioInfo)(const UINT64 *inSize, const UINT64 *outSize);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
8
7zip/Common/StdAfx.h
Executable file
8
7zip/Common/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
197
7zip/Common/StreamBinder.cpp
Executable file
197
7zip/Common/StreamBinder.cpp
Executable file
@@ -0,0 +1,197 @@
|
||||
// StreamBinder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "StreamBinder.h"
|
||||
#include "../../Common/Defs.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NSynchronization;
|
||||
|
||||
class CSequentialInStreamForBinder:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
private:
|
||||
CStreamBinder *m_StreamBinder;
|
||||
public:
|
||||
~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }
|
||||
void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }
|
||||
};
|
||||
|
||||
STDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{ return m_StreamBinder->Read(data, size, processedSize); }
|
||||
|
||||
STDMETHODIMP CSequentialInStreamForBinder::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{ return m_StreamBinder->ReadPart(data, size, processedSize); }
|
||||
|
||||
class CSequentialOutStreamForBinder:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
|
||||
private:
|
||||
CStreamBinder *m_StreamBinder;
|
||||
public:
|
||||
~CSequentialOutStreamForBinder() { m_StreamBinder->CloseWrite(); }
|
||||
void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }
|
||||
};
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{ return m_StreamBinder->Write(data, size, processedSize); }
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamForBinder::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{ return m_StreamBinder->WritePart(data, size, processedSize); }
|
||||
|
||||
|
||||
//////////////////////////
|
||||
// CStreamBinder
|
||||
// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.
|
||||
|
||||
void CStreamBinder::CreateEvents()
|
||||
{
|
||||
_allBytesAreWritenEvent = new CManualResetEvent(true);
|
||||
_thereAreBytesToReadEvent = new CManualResetEvent(false);
|
||||
_readStreamIsClosedEvent = new CManualResetEvent(false);
|
||||
}
|
||||
|
||||
void CStreamBinder::ReInit()
|
||||
{
|
||||
_thereAreBytesToReadEvent->Reset();
|
||||
_readStreamIsClosedEvent->Reset();
|
||||
ProcessedSize = 0;
|
||||
}
|
||||
|
||||
CStreamBinder::~CStreamBinder()
|
||||
{
|
||||
if (_allBytesAreWritenEvent != NULL)
|
||||
delete _allBytesAreWritenEvent;
|
||||
if (_thereAreBytesToReadEvent != NULL)
|
||||
delete _thereAreBytesToReadEvent;
|
||||
if (_readStreamIsClosedEvent != NULL)
|
||||
delete _readStreamIsClosedEvent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void CStreamBinder::CreateStreams(ISequentialInStream **inStream,
|
||||
ISequentialOutStream **outStream)
|
||||
{
|
||||
CSequentialInStreamForBinder *inStreamSpec = new
|
||||
CSequentialInStreamForBinder;
|
||||
CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);
|
||||
inStreamSpec->SetBinder(this);
|
||||
*inStream = inStreamLoc.Detach();
|
||||
|
||||
CSequentialOutStreamForBinder *outStreamSpec = new
|
||||
CSequentialOutStreamForBinder;
|
||||
CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);
|
||||
outStreamSpec->SetBinder(this);
|
||||
*outStream = outStreamLoc.Detach();
|
||||
|
||||
_buffer = NULL;
|
||||
_bufferSize= 0;
|
||||
ProcessedSize = 0;
|
||||
}
|
||||
|
||||
STDMETHODIMP CStreamBinder::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 sizeToRead = size;
|
||||
if (size > 0)
|
||||
{
|
||||
if(!_thereAreBytesToReadEvent->Lock())
|
||||
return E_FAIL;
|
||||
sizeToRead = MyMin(_bufferSize, size);
|
||||
if (_bufferSize > 0)
|
||||
{
|
||||
MoveMemory(data, _buffer, sizeToRead);
|
||||
_buffer = ((const BYTE *)_buffer) + sizeToRead;
|
||||
_bufferSize -= sizeToRead;
|
||||
if (_bufferSize == 0)
|
||||
{
|
||||
_thereAreBytesToReadEvent->Reset();
|
||||
_allBytesAreWritenEvent->Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (processedSize != NULL)
|
||||
*processedSize = sizeToRead;
|
||||
ProcessedSize += sizeToRead;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CStreamBinder::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 fullProcessedSize = 0;
|
||||
UINT32 realProcessedSize;
|
||||
HRESULT result = S_OK;
|
||||
while(size > 0)
|
||||
{
|
||||
result = ReadPart(data, size, &realProcessedSize);
|
||||
size -= realProcessedSize;
|
||||
data = (void *)((BYTE *)data + realProcessedSize);
|
||||
fullProcessedSize += realProcessedSize;
|
||||
if (result != S_OK)
|
||||
break;
|
||||
if (realProcessedSize == 0)
|
||||
break;
|
||||
}
|
||||
if (processedSize != NULL)
|
||||
*processedSize = fullProcessedSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
void CStreamBinder::CloseRead()
|
||||
{
|
||||
_readStreamIsClosedEvent->Set();
|
||||
}
|
||||
|
||||
STDMETHODIMP CStreamBinder::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
if (size > 0)
|
||||
{
|
||||
_buffer = data;
|
||||
_bufferSize = size;
|
||||
_allBytesAreWritenEvent->Reset();
|
||||
_thereAreBytesToReadEvent->Set();
|
||||
|
||||
HANDLE events[2];
|
||||
events[0] = *_allBytesAreWritenEvent;
|
||||
events[1] = *_readStreamIsClosedEvent;
|
||||
DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);
|
||||
if (waitResult != WAIT_OBJECT_0 + 0)
|
||||
{
|
||||
// ReadingWasClosed = true;
|
||||
return E_FAIL;
|
||||
}
|
||||
// if(!_allBytesAreWritenEvent.Lock())
|
||||
// return E_FAIL;
|
||||
}
|
||||
if (processedSize != NULL)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CStreamBinder::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
void CStreamBinder::CloseWrite()
|
||||
{
|
||||
// _bufferSize must be = 0
|
||||
_thereAreBytesToReadEvent->Set();
|
||||
}
|
||||
|
||||
42
7zip/Common/StreamBinder.h
Executable file
42
7zip/Common/StreamBinder.h
Executable file
@@ -0,0 +1,42 @@
|
||||
// StreamBinder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAMBINDER_H
|
||||
#define __STREAMBINDER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
#include "../../Windows/Synchronization.h"
|
||||
|
||||
class CStreamBinder
|
||||
{
|
||||
NWindows::NSynchronization::CManualResetEvent *_allBytesAreWritenEvent;
|
||||
NWindows::NSynchronization::CManualResetEvent *_thereAreBytesToReadEvent;
|
||||
NWindows::NSynchronization::CManualResetEvent *_readStreamIsClosedEvent;
|
||||
UINT32 _bufferSize;
|
||||
const void *_buffer;
|
||||
public:
|
||||
// bool ReadingWasClosed;
|
||||
UINT64 ProcessedSize;
|
||||
CStreamBinder():
|
||||
_allBytesAreWritenEvent(NULL),
|
||||
_thereAreBytesToReadEvent(NULL),
|
||||
_readStreamIsClosedEvent(NULL)
|
||||
{}
|
||||
~CStreamBinder();
|
||||
void CreateEvents();
|
||||
|
||||
void CreateStreams(ISequentialInStream **inStream,
|
||||
ISequentialOutStream **outStream);
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
void CloseRead();
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
void CloseWrite();
|
||||
void ReInit();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
146
7zip/Common/StreamObjects.cpp
Executable file
146
7zip/Common/StreamObjects.cpp
Executable file
@@ -0,0 +1,146 @@
|
||||
// StreamObjects.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "StreamObjects.h"
|
||||
#include "../../Common/Defs.h"
|
||||
|
||||
STDMETHODIMP COutStreamImp::Read(void *data, ULONG size, ULONG *processedSize)
|
||||
{ return E_NOTIMPL; }
|
||||
|
||||
STDMETHODIMP COutStreamImp::Write(void const *data, ULONG size, ULONG *processedSize)
|
||||
{
|
||||
size_t newCapacity = _size + size;
|
||||
_buffer.EnsureCapacity(newCapacity);
|
||||
memmove(_buffer + _size, data, size);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = size;
|
||||
_size += size;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CInStreamImp::Init(BYTE *dataPointer, UINT32 size)
|
||||
{
|
||||
_dataPointer = dataPointer;
|
||||
_size = size;
|
||||
_pos = 0;
|
||||
}
|
||||
|
||||
STDMETHODIMP CInStreamImp::Read(void *data, ULONG size, ULONG *processedSize)
|
||||
{
|
||||
UINT32 numBytesToRead = MyMin(_pos + (UINT32)size, _size) - _pos;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = numBytesToRead;
|
||||
memmove(data, _dataPointer + _pos, numBytesToRead);
|
||||
_pos += numBytesToRead;
|
||||
if(numBytesToRead == size)
|
||||
return S_OK;
|
||||
else
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
STDMETHODIMP CInStreamImp::Write(void const *data, ULONG size, ULONG *processedSize)
|
||||
{ return E_NOTIMPL; }
|
||||
|
||||
|
||||
|
||||
STDMETHODIMP CSequentialInStreamImp::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 numBytesToRead = MyMin(_pos + size, _size) - _pos;
|
||||
memmove(data, _dataPointer + _pos, numBytesToRead);
|
||||
_pos += numBytesToRead;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = numBytesToRead;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialInStreamImp::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
return Read(data, size, processedSize);
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
void CWriteBuffer::Write(const void *data, UINT32 size)
|
||||
{
|
||||
size_t newCapacity = _size + size;
|
||||
_buffer.EnsureCapacity(newCapacity);
|
||||
memmove(_buffer + _size, data, size);
|
||||
_size += size;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
_writeBuffer.Write(data, size);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamImp::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 newSize = size;
|
||||
if (_pos + size > _size)
|
||||
newSize = _size - _pos;
|
||||
memmove(_buffer + _pos, data, newSize);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = newSize;
|
||||
_pos += newSize;
|
||||
if (newSize != size)
|
||||
return E_FAIL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamImp2::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
HRESULT result = _stream->Read(data, size, &realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
*processedSize = realProcessedSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialInStreamSizeCount::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
HRESULT result = _stream->ReadPart(data, size, &realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
*processedSize = realProcessedSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
HRESULT result = _stream->Write(data, size, &realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
*processedSize = realProcessedSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamSizeCount::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
HRESULT result = _stream->WritePart(data, size, &realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
*processedSize = realProcessedSize;
|
||||
return result;
|
||||
}
|
||||
179
7zip/Common/StreamObjects.h
Executable file
179
7zip/Common/StreamObjects.h
Executable file
@@ -0,0 +1,179 @@
|
||||
// StreamObjects.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAMOBJECTS_H
|
||||
#define __STREAMOBJECTS_H
|
||||
|
||||
#include "../../Common/DynamicBuffer.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
#include "../IStream.h"
|
||||
|
||||
class COutStreamImp:
|
||||
public ISequentialStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CByteDynamicBuffer _buffer;
|
||||
UINT32 _size;
|
||||
public:
|
||||
COutStreamImp(): _size(0) {}
|
||||
void Init(){ _size = 0; }
|
||||
UINT32 GetSize() const { return _size; }
|
||||
const CByteDynamicBuffer& GetBuffer() const { return _buffer; }
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHODIMP Read(void *data, ULONG size, ULONG *processedSize);
|
||||
STDMETHODIMP Write(void const *data, ULONG size, ULONG *processedSize);
|
||||
};
|
||||
|
||||
class CInStreamImp:
|
||||
public ISequentialStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
BYTE *_dataPointer;
|
||||
UINT32 _size;
|
||||
UINT32 _pos;
|
||||
|
||||
public:
|
||||
CInStreamImp(): _size(0xFFFFFFFF), _pos(0), _dataPointer(NULL) {}
|
||||
void Init(BYTE *dataPointer, UINT32 size);
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHODIMP Read(void *data, ULONG size, ULONG *processedSize);
|
||||
STDMETHODIMP Write(void const *data, ULONG size, ULONG *processedSize);
|
||||
};
|
||||
|
||||
class CSequentialInStreamImp:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
const BYTE *_dataPointer;
|
||||
UINT32 _size;
|
||||
UINT32 _pos;
|
||||
|
||||
public:
|
||||
void Init(const BYTE *dataPointer, UINT32 size)
|
||||
{
|
||||
_dataPointer = dataPointer;
|
||||
_size = size;
|
||||
_pos = 0;
|
||||
}
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
};
|
||||
|
||||
|
||||
class CWriteBuffer
|
||||
{
|
||||
CByteDynamicBuffer _buffer;
|
||||
UINT32 _size;
|
||||
public:
|
||||
CWriteBuffer(): _size(0) {}
|
||||
// void Init(UINT32 size = 0)
|
||||
void Init()
|
||||
{
|
||||
/*
|
||||
if (size > 0)
|
||||
_buffer.EnsureCapacity(size);
|
||||
*/
|
||||
_size = 0;
|
||||
}
|
||||
void Write(const void *data, UINT32 size);
|
||||
UINT32 GetSize() const { return _size; }
|
||||
const CByteDynamicBuffer& GetBuffer() const { return _buffer; }
|
||||
};
|
||||
|
||||
class CSequentialOutStreamImp:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CWriteBuffer _writeBuffer;
|
||||
public:
|
||||
void Init()
|
||||
{
|
||||
_writeBuffer.Init();
|
||||
}
|
||||
|
||||
/*
|
||||
void Init(UINT32 size = 0)
|
||||
{
|
||||
_writeBuffer.Init(size);
|
||||
}
|
||||
*/
|
||||
UINT32 GetSize() const { return _writeBuffer.GetSize(); }
|
||||
const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
};
|
||||
|
||||
class CSequentialOutStreamImp2:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
BYTE *_buffer;
|
||||
public:
|
||||
UINT32 _size;
|
||||
UINT32 _pos;
|
||||
|
||||
void Init(BYTE *buffer, UINT32 size)
|
||||
{
|
||||
_buffer = buffer;
|
||||
_pos = 0;
|
||||
_size = size;
|
||||
}
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
};
|
||||
|
||||
class CSequentialInStreamSizeCount:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
UINT64 _size;
|
||||
public:
|
||||
void Init(ISequentialInStream *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
_size = 0;
|
||||
}
|
||||
UINT64 GetSize() const { return _size; }
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
};
|
||||
|
||||
class CSequentialOutStreamSizeCount:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UINT64 _size;
|
||||
public:
|
||||
void Init(ISequentialOutStream *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
_size = 0;
|
||||
}
|
||||
UINT64 GetSize() const { return _size; }
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user