mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-13 18:11:37 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -15,7 +15,7 @@ static bool MakeAutoName(const UString &name,
|
||||
const UString &extension, int value, UString &path)
|
||||
{
|
||||
wchar_t number[32];
|
||||
ConvertUINT64ToString(value, number);
|
||||
ConvertUInt64ToString(value, number);
|
||||
path = name;
|
||||
path += number;
|
||||
path += extension;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Util/FilePathAutoRename.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __FILEPATHAUTORENAME_H
|
||||
#define __FILEPATHAUTORENAME_H
|
||||
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
// FileStreams.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "FileStreams.h"
|
||||
|
||||
static inline HRESULT ConvertBoolToHRESULT(bool result)
|
||||
{
|
||||
// return result ? S_OK: E_FAIL;
|
||||
#ifdef _WIN32
|
||||
return result ? S_OK: (::GetLastError());
|
||||
#else
|
||||
return result ? S_OK: E_FAIL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CInFileStream::Open(LPCTSTR fileName)
|
||||
@@ -14,41 +24,104 @@ bool CInFileStream::Open(LPCTSTR fileName)
|
||||
return File.Open(fileName);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef _UNICODE
|
||||
bool CInFileStream::Open(LPCWSTR fileName)
|
||||
{
|
||||
return File.Open(fileName);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
STDMETHODIMP CInFileStream::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
#ifdef _WIN32
|
||||
|
||||
UInt32 realProcessedSize;
|
||||
bool result = File.Read(data, size, realProcessedSize);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
return ConvertBoolToHRESULT(result);
|
||||
|
||||
#else
|
||||
|
||||
if(processedSize != NULL)
|
||||
*processedSize = 0;
|
||||
ssize_t res = File.Read(data, (size_t)size);
|
||||
if (res == -1)
|
||||
return E_FAIL;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = (UInt32)res;
|
||||
return S_OK;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
STDMETHODIMP CInFileStream::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CInFileStream::ReadPart(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Read(data, size, processedSize);
|
||||
}
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
UInt32 realProcessedSize;
|
||||
BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE),
|
||||
data, size, (DWORD *)&realProcessedSize, NULL);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)
|
||||
return S_OK;
|
||||
return ConvertBoolToHRESULT(res != FALSE);
|
||||
|
||||
#else
|
||||
|
||||
STDMETHODIMP CInFileStream::Seek(INT64 offset, UINT32 seekOrigin,
|
||||
UINT64 *newPosition)
|
||||
if(processedSize != NULL)
|
||||
*processedSize = 0;
|
||||
ssize_t res = read(0, data, (size_t)size);
|
||||
if (res == -1)
|
||||
return E_FAIL;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = (UInt32)res;
|
||||
return S_OK;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
STDMETHODIMP CStdInFileStream::ReadPart(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Read(data, size, processedSize);
|
||||
}
|
||||
#endif
|
||||
|
||||
STDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,
|
||||
UInt64 *newPosition)
|
||||
{
|
||||
if(seekOrigin >= 3)
|
||||
return STG_E_INVALIDFUNCTION;
|
||||
UINT64 realNewPosition;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
UInt64 realNewPosition;
|
||||
bool result = File.Seek(offset, seekOrigin, realNewPosition);
|
||||
if(newPosition != NULL)
|
||||
*newPosition = realNewPosition;
|
||||
return ConvertBoolToHRESULT(result);
|
||||
|
||||
#else
|
||||
|
||||
off_t res = File.Seek(offset, seekOrigin);
|
||||
if (res == -1)
|
||||
return E_FAIL;
|
||||
if(newPosition != NULL)
|
||||
*newPosition = (UInt64)res;
|
||||
return S_OK;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
STDMETHODIMP CInFileStream::GetSize(UINT64 *size)
|
||||
STDMETHODIMP CInFileStream::GetSize(UInt64 *size)
|
||||
{
|
||||
return ConvertBoolToHRESULT(File.GetLength(*size));
|
||||
}
|
||||
@@ -57,54 +130,132 @@ STDMETHODIMP CInFileStream::GetSize(UINT64 *size)
|
||||
//////////////////////////
|
||||
// COutFileStream
|
||||
|
||||
bool COutFileStream::Open(LPCTSTR fileName)
|
||||
bool COutFileStream::Create(LPCTSTR fileName, bool createAlways)
|
||||
{
|
||||
File.SetOpenCreationDispositionCreateAlways();
|
||||
return File.Open(fileName);
|
||||
return File.Create(fileName, createAlways);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef _UNICODE
|
||||
bool COutFileStream::Open(LPCWSTR fileName)
|
||||
bool COutFileStream::Create(LPCWSTR fileName, bool createAlways)
|
||||
{
|
||||
File.SetOpenCreationDispositionCreateAlways();
|
||||
return File.Open(fileName);
|
||||
return File.Create(fileName, createAlways);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
STDMETHODIMP COutFileStream::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
#ifdef _WIN32
|
||||
|
||||
UInt32 realProcessedSize;
|
||||
bool result = File.Write(data, size, realProcessedSize);
|
||||
if(processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
return ConvertBoolToHRESULT(result);
|
||||
|
||||
#else
|
||||
|
||||
if(processedSize != NULL)
|
||||
*processedSize = 0;
|
||||
ssize_t res = File.Write(data, (size_t)size);
|
||||
if (res == -1)
|
||||
return E_FAIL;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = (UInt32)res;
|
||||
return S_OK;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
STDMETHODIMP COutFileStream::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP COutFileStream::WritePart(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP COutFileStream::Seek(INT64 offset, UINT32 seekOrigin,
|
||||
UINT64 *newPosition)
|
||||
STDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin,
|
||||
UInt64 *newPosition)
|
||||
{
|
||||
if(seekOrigin >= 3)
|
||||
return STG_E_INVALIDFUNCTION;
|
||||
UINT64 realNewPosition;
|
||||
#ifdef _WIN32
|
||||
|
||||
UInt64 realNewPosition;
|
||||
bool result = File.Seek(offset, seekOrigin, realNewPosition);
|
||||
if(newPosition != NULL)
|
||||
*newPosition = realNewPosition;
|
||||
return ConvertBoolToHRESULT(result);
|
||||
|
||||
#else
|
||||
|
||||
off_t res = File.Seek(offset, seekOrigin);
|
||||
if (res == -1)
|
||||
return E_FAIL;
|
||||
if(newPosition != NULL)
|
||||
*newPosition = (UInt64)res;
|
||||
return S_OK;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
STDMETHODIMP COutFileStream::SetSize(INT64 newSize)
|
||||
STDMETHODIMP COutFileStream::SetSize(Int64 newSize)
|
||||
{
|
||||
UINT64 currentPos;
|
||||
#ifdef _WIN32
|
||||
UInt64 currentPos;
|
||||
if(!File.Seek(0, FILE_CURRENT, currentPos))
|
||||
return E_FAIL;
|
||||
bool result = File.SetLength(newSize);
|
||||
UINT64 currentPos2;
|
||||
UInt64 currentPos2;
|
||||
result = result && File.Seek(currentPos, currentPos2);
|
||||
return result ? S_OK : E_FAIL;
|
||||
#else
|
||||
return E_FAIL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if(processedSize != NULL)
|
||||
*processedSize = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
UInt32 realProcessedSize;
|
||||
BOOL res = TRUE;
|
||||
while (size > 0)
|
||||
{
|
||||
// Seems that Windows doesn't like big amounts writing to stdout.
|
||||
// So we limit portions by 32KB.
|
||||
UInt32 sizeTemp = (1 << 15);
|
||||
if (sizeTemp > size)
|
||||
sizeTemp = size;
|
||||
res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),
|
||||
data, sizeTemp, (DWORD *)&realProcessedSize, NULL);
|
||||
if (realProcessedSize == 0)
|
||||
break;
|
||||
size -= realProcessedSize;
|
||||
data = (const void *)((const Byte *)data + realProcessedSize);
|
||||
if(processedSize != NULL)
|
||||
*processedSize += realProcessedSize;
|
||||
}
|
||||
return ConvertBoolToHRESULT(res != FALSE);
|
||||
|
||||
#else
|
||||
|
||||
ssize_t res = write(1, data, (size_t)size);
|
||||
if (res == -1)
|
||||
return E_FAIL;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = (UInt32)res;
|
||||
return S_OK;
|
||||
|
||||
return S_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
STDMETHODIMP CStdOutFileStream::WritePart(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
// FileStreams.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __FILESTREAMS_H
|
||||
#define __FILESTREAMS_H
|
||||
|
||||
#include "Windows/FileIO.h"
|
||||
#ifdef _WIN32
|
||||
#include "../../Windows/FileIO.h"
|
||||
#else
|
||||
#include "../../Common/C_FileIO.h"
|
||||
#endif
|
||||
|
||||
#include "../IStream.h"
|
||||
#include "Common/MyCom.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
|
||||
class CInFileStream:
|
||||
public IInStream,
|
||||
@@ -16,40 +18,85 @@ class CInFileStream:
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
#ifdef _WIN32
|
||||
NWindows::NFile::NIO::CInFile File;
|
||||
#else
|
||||
NC::NFile::NIO::CInFile File;
|
||||
#endif
|
||||
CInFileStream() {}
|
||||
virtual ~CInFileStream() {}
|
||||
|
||||
bool Open(LPCTSTR fileName);
|
||||
#ifdef _WIN32
|
||||
#ifndef _UNICODE
|
||||
bool Open(LPCWSTR fileName);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
MY_UNKNOWN_IMP1(IStreamGetSize)
|
||||
MY_UNKNOWN_IMP2(IInStream, 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(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);
|
||||
STDMETHOD(GetSize)(UInt64 *size);
|
||||
};
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
class CStdInFileStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
// HANDLE File;
|
||||
// CStdInFileStream() File(INVALID_HANDLE_VALUE): {}
|
||||
// void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
virtual ~CStdInFileStream() {}
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
#endif
|
||||
|
||||
class COutFileStream:
|
||||
public IOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
#ifdef _WIN32
|
||||
NWindows::NFile::NIO::COutFile File;
|
||||
COutFileStream() {}
|
||||
bool Open(LPCTSTR fileName);
|
||||
#else
|
||||
NC::NFile::NIO::COutFile File;
|
||||
#endif
|
||||
virtual ~COutFileStream() {}
|
||||
bool Create(LPCTSTR fileName, bool createAlways);
|
||||
#ifdef _WIN32
|
||||
#ifndef _UNICODE
|
||||
bool Open(LPCWSTR fileName);
|
||||
bool Create(LPCWSTR fileName, bool createAlways);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
MY_UNKNOWN_IMP1(IOutStream)
|
||||
|
||||
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);
|
||||
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);
|
||||
};
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
class CStdOutFileStream:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
virtual ~CStdOutFileStream() {}
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,41 +1,73 @@
|
||||
// InBuffer.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "InBuffer.h"
|
||||
|
||||
CInBuffer::CInBuffer(UINT32 bufferSize):
|
||||
_bufferSize(bufferSize),
|
||||
_bufferBase(0)
|
||||
#include "../../Common/Alloc.h"
|
||||
|
||||
CInBuffer::CInBuffer():
|
||||
_bufferBase(0),
|
||||
_bufferSize(0),
|
||||
_buffer(0),
|
||||
_bufferLimit(0),
|
||||
_stream(0)
|
||||
{}
|
||||
|
||||
bool CInBuffer::Create(UInt32 bufferSize)
|
||||
{
|
||||
_bufferBase = new BYTE[_bufferSize];
|
||||
const UInt32 kMinBlockSize = 1;
|
||||
if (bufferSize < kMinBlockSize)
|
||||
bufferSize = kMinBlockSize;
|
||||
if (_bufferBase != 0 && _bufferSize == bufferSize)
|
||||
return true;
|
||||
Free();
|
||||
_bufferSize = bufferSize;
|
||||
_bufferBase = (Byte *)::BigAlloc(bufferSize);
|
||||
return (_bufferBase != 0);
|
||||
}
|
||||
|
||||
CInBuffer::~CInBuffer()
|
||||
void CInBuffer::Free()
|
||||
{
|
||||
delete []_bufferBase;
|
||||
BigFree(_bufferBase);
|
||||
_bufferBase = 0;
|
||||
}
|
||||
|
||||
void CInBuffer::Init(ISequentialInStream *stream)
|
||||
void CInBuffer::SetStream(ISequentialInStream *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
}
|
||||
|
||||
void CInBuffer::Init()
|
||||
{
|
||||
_processedSize = 0;
|
||||
_buffer = _bufferBase;
|
||||
_bufferLimit = _buffer;
|
||||
_streamWasExhausted = false;
|
||||
_wasFinished = false;
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
ErrorCode = S_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CInBuffer::ReadBlock()
|
||||
{
|
||||
if (_streamWasExhausted)
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
if (ErrorCode != S_OK)
|
||||
return false;
|
||||
#endif
|
||||
if (_wasFinished)
|
||||
return false;
|
||||
_processedSize += (_buffer - _bufferBase);
|
||||
UINT32 numProcessedBytes;
|
||||
UInt32 numProcessedBytes;
|
||||
HRESULT result = _stream->ReadPart(_bufferBase, _bufferSize, &numProcessedBytes);
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
ErrorCode = result;
|
||||
#else
|
||||
if (result != S_OK)
|
||||
throw CInBufferException(result);
|
||||
#endif
|
||||
_buffer = _bufferBase;
|
||||
_bufferLimit = _buffer + numProcessedBytes;
|
||||
_streamWasExhausted = (numProcessedBytes == 0);
|
||||
return (!_streamWasExhausted);
|
||||
_wasFinished = (numProcessedBytes == 0);
|
||||
return (!_wasFinished);
|
||||
}
|
||||
|
||||
@@ -1,39 +1,48 @@
|
||||
// InBuffer.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __INBUFFER_H
|
||||
#define __INBUFFER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
class CInBufferException
|
||||
{
|
||||
public:
|
||||
HRESULT ErrorCode;
|
||||
CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
||||
};
|
||||
#endif
|
||||
|
||||
class CInBuffer
|
||||
{
|
||||
UINT64 _processedSize;
|
||||
BYTE *_bufferBase;
|
||||
UINT32 _bufferSize;
|
||||
BYTE *_buffer;
|
||||
BYTE *_bufferLimit;
|
||||
ISequentialInStream *_stream;
|
||||
bool _streamWasExhausted;
|
||||
UInt64 _processedSize;
|
||||
Byte *_bufferBase;
|
||||
UInt32 _bufferSize;
|
||||
Byte *_buffer;
|
||||
Byte *_bufferLimit;
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
bool _wasFinished;
|
||||
|
||||
bool ReadBlock();
|
||||
|
||||
public:
|
||||
CInBuffer(UINT32 bufferSize = 0x100000);
|
||||
~CInBuffer();
|
||||
|
||||
void Init(ISequentialInStream *stream);
|
||||
// void ReleaseStream() { _stream.Release(); }
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
HRESULT ErrorCode;
|
||||
#endif
|
||||
|
||||
bool ReadByte(BYTE &b)
|
||||
CInBuffer();
|
||||
~CInBuffer() { Free(); }
|
||||
|
||||
bool Create(UInt32 bufferSize);
|
||||
void Free();
|
||||
|
||||
void SetStream(ISequentialInStream *stream);
|
||||
void Init();
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
|
||||
bool ReadByte(Byte &b)
|
||||
{
|
||||
if(_buffer >= _bufferLimit)
|
||||
if(!ReadBlock())
|
||||
@@ -41,26 +50,27 @@ public:
|
||||
b = *_buffer++;
|
||||
return true;
|
||||
}
|
||||
BYTE ReadByte()
|
||||
Byte ReadByte()
|
||||
{
|
||||
if(_buffer >= _bufferLimit)
|
||||
if(!ReadBlock())
|
||||
return 0x0;
|
||||
return 0xFF;
|
||||
return *_buffer++;
|
||||
}
|
||||
void ReadBytes(void *data, UINT32 size, UINT32 &processedSize)
|
||||
void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
|
||||
{
|
||||
for(processedSize = 0; processedSize < size; processedSize++)
|
||||
if (!ReadByte(((BYTE *)data)[processedSize]))
|
||||
if (!ReadByte(((Byte *)data)[processedSize]))
|
||||
return;
|
||||
}
|
||||
bool ReadBytes(void *data, UINT32 size)
|
||||
bool ReadBytes(void *data, UInt32 size)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UInt32 processedSize;
|
||||
ReadBytes(data, size, processedSize);
|
||||
return (processedSize == size);
|
||||
}
|
||||
UINT64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
|
||||
UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
|
||||
bool WasFinished() const { return _wasFinished; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,7 @@ using namespace NWindows;
|
||||
using namespace NFile;
|
||||
using namespace NDirectory;
|
||||
|
||||
static UINT32 kTmpBufferMemorySize = (1 << 20);
|
||||
static UInt32 kTmpBufferMemorySize = (1 << 20);
|
||||
|
||||
static LPCTSTR kTempFilePrefixString = TEXT("iot");
|
||||
|
||||
@@ -21,7 +21,7 @@ CInOutTempBuffer::CInOutTempBuffer():
|
||||
|
||||
void CInOutTempBuffer::Create()
|
||||
{
|
||||
_buffer = new BYTE[kTmpBufferMemorySize];
|
||||
_buffer = new Byte[kTmpBufferMemorySize];
|
||||
}
|
||||
|
||||
CInOutTempBuffer::~CInOutTempBuffer()
|
||||
@@ -35,7 +35,7 @@ void CInOutTempBuffer::InitWriting()
|
||||
_fileSize = 0;
|
||||
}
|
||||
|
||||
bool CInOutTempBuffer::WriteToFile(const void *data, UINT32 size)
|
||||
bool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)
|
||||
{
|
||||
if (size == 0)
|
||||
return true;
|
||||
@@ -46,12 +46,12 @@ bool CInOutTempBuffer::WriteToFile(const void *data, UINT32 size)
|
||||
return false;
|
||||
if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)
|
||||
return false;
|
||||
_outFile.SetOpenCreationDispositionCreateAlways();
|
||||
if(!_outFile.Open(_tmpFileName))
|
||||
// _outFile.SetOpenCreationDispositionCreateAlways();
|
||||
if(!_outFile.Create(_tmpFileName, true))
|
||||
return false;
|
||||
_tmpFileCreated = true;
|
||||
}
|
||||
UINT32 processedSize;
|
||||
UInt32 processedSize;
|
||||
if(!_outFile.Write(data, size, processedSize))
|
||||
return false;
|
||||
_fileSize += processedSize;
|
||||
@@ -63,16 +63,16 @@ bool CInOutTempBuffer::FlushWrite()
|
||||
return _outFile.Close();
|
||||
}
|
||||
|
||||
bool CInOutTempBuffer::Write(const void *data, UINT32 size)
|
||||
bool CInOutTempBuffer::Write(const void *data, UInt32 size)
|
||||
{
|
||||
UINT32 numBytes = 0;
|
||||
UInt32 numBytes = 0;
|
||||
if(_bufferPosition < kTmpBufferMemorySize)
|
||||
{
|
||||
UINT32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);
|
||||
memmove(_buffer + _bufferPosition, (const BYTE *)data, curSize);
|
||||
UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);
|
||||
memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);
|
||||
_bufferPosition += curSize;
|
||||
size -= curSize;
|
||||
data = ((const BYTE *)data) + curSize;
|
||||
data = ((const Byte *)data) + curSize;
|
||||
_fileSize += curSize;
|
||||
}
|
||||
return WriteToFile(data, size);
|
||||
@@ -87,21 +87,21 @@ bool CInOutTempBuffer::InitReading()
|
||||
}
|
||||
|
||||
/*
|
||||
bool CInOutTempBuffer::Read(void *data, UINT32 maxSize, UINT32 &processedSize)
|
||||
bool CInOutTempBuffer::Read(void *data, UInt32 maxSize, UInt32 &processedSize)
|
||||
{
|
||||
processedSize = 0;
|
||||
if (_currentPositionInBuffer < _bufferPosition)
|
||||
{
|
||||
UINT32 sizeToRead = MyMin(_bufferPosition - _currentPositionInBuffer, maxSize);
|
||||
UInt32 sizeToRead = MyMin(_bufferPosition - _currentPositionInBuffer, maxSize);
|
||||
memmove(data, _buffer + _currentPositionInBuffer, sizeToRead);
|
||||
data = ((BYTE *)data) + sizeToRead;
|
||||
data = ((Byte *)data) + sizeToRead;
|
||||
_currentPositionInBuffer += sizeToRead;
|
||||
processedSize += sizeToRead;
|
||||
maxSize -= sizeToRead;
|
||||
}
|
||||
if (maxSize == 0 || !_tmpFileCreated)
|
||||
return true;
|
||||
UINT32 localProcessedSize;
|
||||
UInt32 localProcessedSize;
|
||||
bool result = _inFile.Read(data, maxSize, localProcessedSize);
|
||||
processedSize += localProcessedSize;
|
||||
return result;
|
||||
@@ -112,7 +112,7 @@ HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
|
||||
{
|
||||
if (_currentPositionInBuffer < _bufferPosition)
|
||||
{
|
||||
UINT32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;
|
||||
UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;
|
||||
RINOK(stream->Write(_buffer + _currentPositionInBuffer, sizeToWrite, NULL));
|
||||
_currentPositionInBuffer += sizeToWrite;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
|
||||
return true;
|
||||
while(true)
|
||||
{
|
||||
UINT32 localProcessedSize;
|
||||
UInt32 localProcessedSize;
|
||||
if (!_inFile.Read(_buffer, kTmpBufferMemorySize, localProcessedSize))
|
||||
return E_FAIL;
|
||||
if (localProcessedSize == 0)
|
||||
@@ -129,7 +129,7 @@ HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if (!_buffer->Write(data, size))
|
||||
{
|
||||
@@ -142,7 +142,7 @@ STDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UINT32 size, U
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutTempBufferImp::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialOutTempBufferImp::WritePart(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Util/InOutTempBuffer.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __INOUTTEMPBUFFER_H
|
||||
#define __INOUTTEMPBUFFER_H
|
||||
#ifndef __IN_OUT_TEMP_BUFFER_H
|
||||
#define __IN_OUT_TEMP_BUFFER_H
|
||||
|
||||
#include "../../Windows/FileIO.h"
|
||||
#include "../../Windows/FileDir.h"
|
||||
@@ -16,26 +14,26 @@ class CInOutTempBuffer
|
||||
NWindows::NFile::NDirectory::CTempFile _tempFile;
|
||||
NWindows::NFile::NIO::COutFile _outFile;
|
||||
NWindows::NFile::NIO::CInFile _inFile;
|
||||
BYTE *_buffer;
|
||||
UINT32 _bufferPosition;
|
||||
UINT32 _currentPositionInBuffer;
|
||||
Byte *_buffer;
|
||||
UInt32 _bufferPosition;
|
||||
UInt32 _currentPositionInBuffer;
|
||||
CSysString _tmpFileName;
|
||||
bool _tmpFileCreated;
|
||||
|
||||
UINT64 _fileSize;
|
||||
UInt64 _fileSize;
|
||||
|
||||
bool WriteToFile(const void *data, UINT32 size);
|
||||
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 Write(const void *data, UInt32 size);
|
||||
UInt64 GetDataSize() const { return _fileSize; }
|
||||
bool FlushWrite();
|
||||
bool InitReading();
|
||||
// bool Read(void *data, UINT32 maxSize, UINT32 &processedSize);
|
||||
// bool Read(void *data, UInt32 maxSize, UInt32 &processedSize);
|
||||
HRESULT WriteToStream(ISequentialOutStream *stream);
|
||||
};
|
||||
|
||||
@@ -46,14 +44,14 @@ class CSequentialOutTempBufferImp:
|
||||
CInOutTempBuffer *_buffer;
|
||||
public:
|
||||
// CSequentialOutStreamImp(): _size(0) {}
|
||||
// UINT32 _size;
|
||||
// UInt32 _size;
|
||||
void Init(CInOutTempBuffer *buffer) { _buffer = buffer; }
|
||||
// UINT32 GetSize() const { return _size; }
|
||||
// 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);
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
BYTE kInvertTable[256];
|
||||
Byte kInvertTable[256];
|
||||
|
||||
class CInverterTableInitializer
|
||||
{
|
||||
@@ -16,8 +16,8 @@ public:
|
||||
{
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
BYTE b = BYTE(i);
|
||||
BYTE bInvert = 0;
|
||||
Byte b = Byte(i);
|
||||
Byte bInvert = 0;
|
||||
for(int j = 0; j < 8; j++)
|
||||
{
|
||||
bInvert <<= 1;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// Stream/LSBFDecoder.h
|
||||
|
||||
#pragma once
|
||||
// LSBFDecoder.h
|
||||
|
||||
#ifndef __STREAM_LSBFDECODER_H
|
||||
#define __STREAM_LSBFDECODER_H
|
||||
@@ -15,80 +13,113 @@ const int kNumBigValueBits = 8 * 4;
|
||||
const int kNumValueBytes = 3;
|
||||
const int kNumValueBits = 8 * kNumValueBytes;
|
||||
|
||||
const UINT32 kMask = (1 << kNumValueBits) - 1;
|
||||
const UInt32 kMask = (1 << kNumValueBits) - 1;
|
||||
|
||||
extern BYTE kInvertTable[256];
|
||||
extern Byte kInvertTable[256];
|
||||
// the Least Significant Bit of byte is First
|
||||
|
||||
template<class TInByte>
|
||||
class CDecoder
|
||||
class CBaseDecoder
|
||||
{
|
||||
UINT32 m_BitPos;
|
||||
UINT32 m_Value;
|
||||
UINT32 m_NormalValue;
|
||||
protected:
|
||||
UInt32 m_BitPos;
|
||||
UInt32 m_Value;
|
||||
TInByte m_Stream;
|
||||
public:
|
||||
UINT32 NumExtraBytes;
|
||||
void Init(ISequentialInStream *inStream)
|
||||
{
|
||||
m_Stream.Init(inStream);
|
||||
Init();
|
||||
}
|
||||
UInt32 NumExtraBytes;
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream); }
|
||||
void ReleaseStream() { m_Stream.ReleaseStream(); }
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = kNumBigValueBits;
|
||||
m_NormalValue = 0;
|
||||
m_Value = 0;
|
||||
NumExtraBytes = 0;
|
||||
}
|
||||
/*
|
||||
void ReleaseStream()
|
||||
{
|
||||
m_Stream.ReleaseStream();
|
||||
}
|
||||
*/
|
||||
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); }
|
||||
UInt32 GetBitPosition() const { return (m_BitPos & 7); }
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
for (;m_BitPos >= 8; m_BitPos -= 8)
|
||||
{
|
||||
BYTE b;
|
||||
Byte b;
|
||||
if (!m_Stream.ReadByte(b))
|
||||
{
|
||||
b = 0xFF; // check it
|
||||
NumExtraBytes++;
|
||||
m_NormalValue = (b << (kNumBigValueBits - m_BitPos)) | m_NormalValue;
|
||||
m_Value = (m_Value << 8) | kInvertTable[b];
|
||||
}
|
||||
m_Value = (b << (kNumBigValueBits - m_BitPos)) | m_Value;
|
||||
}
|
||||
}
|
||||
|
||||
UINT32 GetValue(UINT32 numBits)
|
||||
UInt32 ReadBits(UInt32 numBits)
|
||||
{
|
||||
Normalize();
|
||||
return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits);
|
||||
}
|
||||
|
||||
void MovePos(UINT32 numBits)
|
||||
{
|
||||
UInt32 res = m_Value & ((1 << numBits) - 1);
|
||||
m_BitPos += numBits;
|
||||
m_NormalValue >>= numBits;
|
||||
}
|
||||
|
||||
UINT32 ReadBits(UINT32 numBits)
|
||||
{
|
||||
Normalize();
|
||||
UINT32 res = m_NormalValue & ( (1 << numBits) - 1);
|
||||
MovePos(numBits);
|
||||
m_Value >>= numBits;
|
||||
return res;
|
||||
}
|
||||
|
||||
UINT32 GetBitPosition() const
|
||||
bool ExtraBitsWereRead() const
|
||||
{
|
||||
return (m_BitPos & 7);
|
||||
if (NumExtraBytes == 0)
|
||||
return false;
|
||||
return ((kNumBigValueBits - m_BitPos) < (NumExtraBytes << 3));
|
||||
}
|
||||
};
|
||||
|
||||
template<class TInByte>
|
||||
class CDecoder: public CBaseDecoder<TInByte>
|
||||
{
|
||||
UInt32 m_NormalValue;
|
||||
|
||||
public:
|
||||
void Init()
|
||||
{
|
||||
CBaseDecoder<TInByte>::Init();
|
||||
m_NormalValue = 0;
|
||||
}
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
for (;this->m_BitPos >= 8; this->m_BitPos -= 8)
|
||||
{
|
||||
Byte b;
|
||||
if (!this->m_Stream.ReadByte(b))
|
||||
{
|
||||
b = 0xFF; // check it
|
||||
this->NumExtraBytes++;
|
||||
}
|
||||
m_NormalValue = (b << (kNumBigValueBits - this->m_BitPos)) | m_NormalValue;
|
||||
this->m_Value = (this->m_Value << 8) | kInvertTable[b];
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 GetValue(UInt32 numBits)
|
||||
{
|
||||
Normalize();
|
||||
return ((this->m_Value >> (8 - this->m_BitPos)) & kMask) >> (kNumValueBits - numBits);
|
||||
}
|
||||
|
||||
void MovePos(UInt32 numBits)
|
||||
{
|
||||
this->m_BitPos += numBits;
|
||||
m_NormalValue >>= numBits;
|
||||
}
|
||||
|
||||
UInt32 ReadBits(UInt32 numBits)
|
||||
{
|
||||
Normalize();
|
||||
UInt32 res = m_NormalValue & ( (1 << numBits) - 1);
|
||||
MovePos(numBits);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -8,18 +8,18 @@
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
void CEncoder::WriteBits(UINT32 aValue, UINT32 aNumBits)
|
||||
void CEncoder::WriteBits(UInt32 value, UInt32 numBits)
|
||||
{
|
||||
while(aNumBits > 0)
|
||||
while(numBits > 0)
|
||||
{
|
||||
UINT32 aNumNewBits = MyMin(aNumBits, m_BitPos);
|
||||
aNumBits -= aNumNewBits;
|
||||
UInt32 numNewBits = MyMin(numBits, m_BitPos);
|
||||
numBits -= numNewBits;
|
||||
|
||||
UINT32 aMask = (1 << aNumNewBits) - 1;
|
||||
m_CurByte |= (aValue & aMask) << (8 - m_BitPos);
|
||||
aValue >>= aNumNewBits;
|
||||
UInt32 mask = (1 << numNewBits) - 1;
|
||||
m_CurByte |= (value & mask) << (8 - m_BitPos);
|
||||
value >>= numNewBits;
|
||||
|
||||
m_BitPos -= aNumNewBits;
|
||||
m_BitPos -= numNewBits;
|
||||
|
||||
if (m_BitPos == 0)
|
||||
{
|
||||
@@ -31,16 +31,16 @@ void CEncoder::WriteBits(UINT32 aValue, UINT32 aNumBits)
|
||||
}
|
||||
|
||||
|
||||
void CReverseEncoder::WriteBits(UINT32 aValue, UINT32 aNumBits)
|
||||
void CReverseEncoder::WriteBits(UInt32 value, UInt32 numBits)
|
||||
{
|
||||
UINT32 aReverseValue = 0;
|
||||
for(UINT32 i = 0; i < aNumBits; i++)
|
||||
UInt32 reverseValue = 0;
|
||||
for(UInt32 i = 0; i < numBits; i++)
|
||||
{
|
||||
aReverseValue <<= 1;
|
||||
aReverseValue |= aValue & 1;
|
||||
aValue >>= 1;
|
||||
reverseValue <<= 1;
|
||||
reverseValue |= value & 1;
|
||||
value >>= 1;
|
||||
}
|
||||
m_Encoder->WriteBits(aReverseValue, aNumBits);
|
||||
m_Encoder->WriteBits(reverseValue, numBits);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Stream/LSBFEncoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAM_LSBFENCODER_H
|
||||
#define __STREAM_LSBFENCODER_H
|
||||
|
||||
@@ -14,12 +12,15 @@ namespace NLSBF {
|
||||
class CEncoder
|
||||
{
|
||||
COutBuffer m_Stream;
|
||||
UINT32 m_BitPos;
|
||||
BYTE m_CurByte;
|
||||
UInt32 m_BitPos;
|
||||
Byte m_CurByte;
|
||||
public:
|
||||
void Init(ISequentialOutStream *aStream)
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream); }
|
||||
void ReleaseStream() { m_Stream.ReleaseStream(); }
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init(aStream);
|
||||
m_Stream.Init();
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
@@ -29,19 +30,9 @@ public:
|
||||
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 {
|
||||
void WriteBits(UInt32 value, UInt32 numBits);
|
||||
UInt32 GetBitPosition() const { return (8 - m_BitPos); }
|
||||
UInt64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
|
||||
};
|
||||
|
||||
@@ -49,9 +40,8 @@ class CReverseEncoder
|
||||
{
|
||||
CEncoder *m_Encoder;
|
||||
public:
|
||||
void Init(CEncoder *anEncoder)
|
||||
{ m_Encoder = anEncoder; }
|
||||
void WriteBits(UINT32 aValue, UINT32 aNumBits);
|
||||
void Init(CEncoder *encoder) { m_Encoder = encoder; }
|
||||
void WriteBits(UInt32 value, UInt32 numBits);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
#include "LimitedStreams.h"
|
||||
#include "../../Common/Defs.h"
|
||||
|
||||
void CLimitedSequentialInStream::Init(ISequentialInStream *stream, UINT64 streamSize)
|
||||
void CLimitedSequentialInStream::Init(ISequentialInStream *stream, UInt64 streamSize)
|
||||
{
|
||||
_stream = stream;
|
||||
_size = streamSize;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLimitedSequentialInStream::Read(void *data,
|
||||
UINT32 size, UINT32 *processedSize)
|
||||
UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 processedSizeReal;
|
||||
UINT32 sizeToRead = UINT32(MyMin(_size, UINT64(size)));
|
||||
UInt32 processedSizeReal;
|
||||
UInt32 sizeToRead = UInt32(MyMin(_size, UInt64(size)));
|
||||
HRESULT result = _stream->Read(data, sizeToRead, &processedSizeReal);
|
||||
_size -= processedSizeReal;
|
||||
if(processedSize != NULL)
|
||||
@@ -23,10 +23,10 @@ STDMETHODIMP CLimitedSequentialInStream::Read(void *data,
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLimitedSequentialInStream::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CLimitedSequentialInStream::ReadPart(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 processedSizeReal;
|
||||
UINT32 sizeToRead = UINT32(MyMin(_size, UINT64(size)));
|
||||
UInt32 processedSizeReal;
|
||||
UInt32 sizeToRead = UInt32(MyMin(_size, UInt64(size)));
|
||||
HRESULT result = _stream->ReadPart(data, sizeToRead, &processedSizeReal);
|
||||
_size -= processedSizeReal;
|
||||
if(processedSize != NULL)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// LimitedStreams.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __LIMITEDSTREAMS_H
|
||||
#define __LIMITEDSTREAMS_H
|
||||
|
||||
@@ -12,15 +10,15 @@ class CLimitedSequentialInStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
UINT64 _size;
|
||||
UInt64 _size;
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
public:
|
||||
void Init(ISequentialInStream *stream, UINT64 streamSize);
|
||||
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);
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
// MultiStream.cpp
|
||||
// LockedStream.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "MultiStream.h"
|
||||
#include "LockedStream.h"
|
||||
|
||||
HRESULT CLockedInStream::Read(UINT64 startPos, void *data, UINT32 size,
|
||||
UINT32 *processedSize)
|
||||
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)
|
||||
HRESULT CLockedInStream::ReadPart(UInt64 startPos, void *data, UInt32 size,
|
||||
UInt32 *processedSize)
|
||||
{
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
|
||||
RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));
|
||||
@@ -21,9 +21,9 @@ HRESULT CLockedInStream::ReadPart(UINT64 startPos, void *data, UINT32 size,
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize = 0;
|
||||
UInt32 realProcessedSize = 0;
|
||||
HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);
|
||||
_pos += realProcessedSize;
|
||||
if (processedSize != NULL)
|
||||
@@ -31,9 +31,9 @@ STDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UINT32 size, UINT32
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLockedSequentialInStreamImp::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CLockedSequentialInStreamImp::ReadPart(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize = 0;
|
||||
UInt32 realProcessedSize = 0;
|
||||
HRESULT result = _lockedInStream->ReadPart(_pos, data, size, &realProcessedSize);
|
||||
_pos += realProcessedSize;
|
||||
if (processedSize != NULL)
|
||||
@@ -1,9 +1,7 @@
|
||||
// MultiStream.h
|
||||
// LockedStream.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MULTISTREAM_H
|
||||
#define __MULTISTREAM_H
|
||||
#ifndef __LOCKEDSTREAM_H
|
||||
#define __LOCKEDSTREAM_H
|
||||
|
||||
#include "../../Windows/Synchronization.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
@@ -16,8 +14,8 @@ class CLockedInStream
|
||||
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);
|
||||
HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);
|
||||
HRESULT ReadPart(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
class CLockedSequentialInStreamImp:
|
||||
@@ -25,9 +23,9 @@ class CLockedSequentialInStreamImp:
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLockedInStream *_lockedInStream;
|
||||
UINT64 _pos;
|
||||
UInt64 _pos;
|
||||
public:
|
||||
void Init(CLockedInStream *lockedInStream, UINT64 startPos)
|
||||
void Init(CLockedInStream *lockedInStream, UInt64 startPos)
|
||||
{
|
||||
_lockedInStream = lockedInStream;
|
||||
_pos = startPos;
|
||||
@@ -35,8 +33,8 @@ public:
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,6 @@
|
||||
// Stream/MSBFDecoder.h
|
||||
// MSBFDecoder.h
|
||||
// the Most Significant Bit of byte is First
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAM_MSBFDECODER_H
|
||||
#define __STREAM_MSBFDECODER_H
|
||||
|
||||
@@ -10,37 +8,32 @@ namespace NStream {
|
||||
namespace NMSBF {
|
||||
|
||||
const int kNumBigValueBits = 8 * 4;
|
||||
|
||||
const int kNumValueBytes = 3;
|
||||
const int kNumValueBits = 8 * kNumValueBytes;
|
||||
|
||||
const UINT32 kMask = (1 << kNumValueBits) - 1;
|
||||
const UInt32 kMask = (1 << kNumValueBits) - 1;
|
||||
|
||||
template<class TInByte>
|
||||
class CDecoder
|
||||
{
|
||||
TInByte m_Stream;
|
||||
UINT32 m_BitPos;
|
||||
UINT32 m_Value;
|
||||
|
||||
UInt32 m_BitPos;
|
||||
UInt32 m_Value;
|
||||
public:
|
||||
|
||||
void Init(ISequentialInStream *aStream)
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);}
|
||||
void ReleaseStream() { m_Stream.ReleaseStream();}
|
||||
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init(aStream);
|
||||
m_Stream.Init();
|
||||
m_BitPos = kNumBigValueBits;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
/*
|
||||
void ReleaseStream()
|
||||
{
|
||||
m_Stream.ReleaseStream();
|
||||
}
|
||||
*/
|
||||
|
||||
UINT64 GetProcessedSize() const
|
||||
UInt64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
|
||||
UInt32 GetBitPosition() const { return (m_BitPos & 7); }
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
@@ -48,23 +41,23 @@ public:
|
||||
m_Value = (m_Value << 8) | m_Stream.ReadByte();
|
||||
}
|
||||
|
||||
UINT32 GetValue(UINT32 aNumBits) const
|
||||
UInt32 GetValue(UInt32 numBits) const
|
||||
{
|
||||
// return (m_Value << m_BitPos) >> (kNumBigValueBits - aNumBits);
|
||||
return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - aNumBits);
|
||||
// return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits);
|
||||
return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits);
|
||||
}
|
||||
|
||||
void MovePos(UINT32 aNumBits)
|
||||
void MovePos(UInt32 numBits)
|
||||
{
|
||||
m_BitPos += aNumBits;
|
||||
m_BitPos += numBits;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
UINT32 ReadBits(UINT32 aNumBits)
|
||||
UInt32 ReadBits(UInt32 numBits)
|
||||
{
|
||||
UINT32 aRes = GetValue(aNumBits);
|
||||
MovePos(aNumBits);
|
||||
return aRes;
|
||||
UInt32 res = GetValue(numBits);
|
||||
MovePos(numBits);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// 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"
|
||||
#include "../IStream.h"
|
||||
#include "OutBuffer.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NMSBF {
|
||||
@@ -16,12 +14,15 @@ template<class TOutByte>
|
||||
class CEncoder
|
||||
{
|
||||
TOutByte m_Stream;
|
||||
UINT32 m_BitPos;
|
||||
BYTE m_CurByte;
|
||||
int m_BitPos;
|
||||
Byte m_CurByte;
|
||||
public:
|
||||
void Init(ISequentialOutStream *aStream)
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream);}
|
||||
void ReleaseStream() { m_Stream.ReleaseStream(); }
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init(aStream);
|
||||
m_Stream.Init();
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
@@ -32,26 +33,19 @@ public:
|
||||
return m_Stream.Flush();
|
||||
}
|
||||
|
||||
void ReleaseStream()
|
||||
void WriteBits(UInt32 value, int numBits)
|
||||
{
|
||||
m_Stream.ReleaseStream();
|
||||
}
|
||||
|
||||
void WriteBits(UINT32 aValue, UINT32 aNumBits)
|
||||
{
|
||||
while(aNumBits > 0)
|
||||
while(numBits > 0)
|
||||
{
|
||||
UINT32 aNumNewBits = MyMin(aNumBits, m_BitPos);
|
||||
aNumBits -= aNumNewBits;
|
||||
int numNewBits = MyMin(numBits, m_BitPos);
|
||||
numBits -= numNewBits;
|
||||
|
||||
m_CurByte <<= numNewBits;
|
||||
UInt32 newBits = value >> numBits;
|
||||
m_CurByte |= Byte(newBits);
|
||||
value -= (newBits << numBits);
|
||||
|
||||
m_CurByte <<= aNumNewBits;
|
||||
UINT32 aNewBits = aValue >> aNumBits;
|
||||
m_CurByte |= BYTE(aNewBits);
|
||||
aValue -= (aNewBits << aNumBits);
|
||||
|
||||
|
||||
m_BitPos -= aNumNewBits;
|
||||
m_BitPos -= numNewBits;
|
||||
|
||||
if (m_BitPos == 0)
|
||||
{
|
||||
@@ -60,11 +54,10 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
UINT64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
|
||||
UInt64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) / 8; }
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -5,28 +5,28 @@
|
||||
#include "Common/Defs.h"
|
||||
#include "OffsetStream.h"
|
||||
|
||||
HRESULT COffsetOutStream::Init(IOutStream *stream, UINT64 offset)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,
|
||||
UInt64 *newPosition)
|
||||
{
|
||||
UINT64 absoluteNewPosition;
|
||||
UInt64 absoluteNewPosition;
|
||||
if (seekOrigin == STREAM_SEEK_SET)
|
||||
offset += _offset;
|
||||
HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);
|
||||
@@ -35,7 +35,7 @@ STDMETHODIMP COffsetOutStream::Seek(INT64 offset, UINT32 seekOrigin,
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP COffsetOutStream::SetSize(INT64 newSize)
|
||||
STDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)
|
||||
{
|
||||
return _stream->SetSize(_offset + newSize);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// OffsetStream.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __OFFSETSTREAM_H
|
||||
#define __OFFSETSTREAM_H
|
||||
|
||||
@@ -12,17 +10,17 @@ class COffsetOutStream:
|
||||
public IOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
UINT64 _offset;
|
||||
UInt64 _offset;
|
||||
CMyComPtr<IOutStream> _stream;
|
||||
public:
|
||||
HRESULT Init(IOutStream *stream, UINT64 offset);
|
||||
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);
|
||||
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
|
||||
|
||||
@@ -1,40 +1,49 @@
|
||||
// Stream/OutByte.cpp
|
||||
// OutByte.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "OutBuffer.h"
|
||||
|
||||
COutBuffer::COutBuffer(UINT32 bufferSize):
|
||||
_bufferSize(bufferSize)
|
||||
#include "../../Common/Alloc.h"
|
||||
|
||||
bool COutBuffer::Create(UInt32 bufferSize)
|
||||
{
|
||||
_buffer = new BYTE[_bufferSize];
|
||||
const UInt32 kMinBlockSize = 1;
|
||||
if (bufferSize < kMinBlockSize)
|
||||
bufferSize = kMinBlockSize;
|
||||
if (_buffer != 0 && _bufferSize == bufferSize)
|
||||
return true;
|
||||
Free();
|
||||
_bufferSize = bufferSize;
|
||||
_buffer = (Byte *)::BigAlloc(bufferSize);
|
||||
return (_buffer != 0);
|
||||
}
|
||||
|
||||
COutBuffer::~COutBuffer()
|
||||
void COutBuffer::Free()
|
||||
{
|
||||
delete []_buffer;
|
||||
BigFree(_buffer);
|
||||
_buffer = 0;
|
||||
}
|
||||
|
||||
void COutBuffer::Init(ISequentialOutStream *stream)
|
||||
void COutBuffer::SetStream(ISequentialOutStream *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
}
|
||||
|
||||
void COutBuffer::Init()
|
||||
{
|
||||
_processedSize = 0;
|
||||
_pos = 0;
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
ErrorCode = S_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
void COutBuffer::ReleaseStream()
|
||||
{
|
||||
_stream.Release();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
HRESULT COutBuffer::Flush()
|
||||
{
|
||||
if (_pos == 0)
|
||||
return S_OK;
|
||||
UINT32 processedSize;
|
||||
UInt32 processedSize;
|
||||
HRESULT result = _stream->Write(_buffer, _pos, &processedSize);
|
||||
if (result != S_OK)
|
||||
return result;
|
||||
@@ -47,7 +56,15 @@ HRESULT COutBuffer::Flush()
|
||||
|
||||
void COutBuffer::WriteBlock()
|
||||
{
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
if (ErrorCode != S_OK)
|
||||
return;
|
||||
#endif
|
||||
HRESULT result = Flush();
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
ErrorCode = result;
|
||||
#else
|
||||
if (result != S_OK)
|
||||
throw COutBufferException(result);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,62 +1,71 @@
|
||||
// OutBuffer.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __OUTBUFFER_H
|
||||
#define __OUTBUFFER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
|
||||
class COutBufferException
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
struct COutBufferException
|
||||
{
|
||||
public:
|
||||
HRESULT ErrorCode;
|
||||
COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
||||
};
|
||||
#endif
|
||||
|
||||
class COutBuffer
|
||||
{
|
||||
BYTE *_buffer;
|
||||
UINT32 _pos;
|
||||
UINT32 _bufferSize;
|
||||
ISequentialOutStream *_stream;
|
||||
UINT64 _processedSize;
|
||||
Byte *_buffer;
|
||||
UInt32 _pos;
|
||||
UInt32 _bufferSize;
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UInt64 _processedSize;
|
||||
|
||||
void WriteBlock();
|
||||
public:
|
||||
COutBuffer(UINT32 bufferSize = (1 << 20));
|
||||
~COutBuffer();
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
HRESULT ErrorCode;
|
||||
#endif
|
||||
|
||||
void Init(ISequentialOutStream *stream);
|
||||
COutBuffer(): _buffer(0), _pos(0), _stream(0) {}
|
||||
~COutBuffer() { Free(); }
|
||||
|
||||
bool Create(UInt32 bufferSize);
|
||||
void Free();
|
||||
|
||||
void SetStream(ISequentialOutStream *stream);
|
||||
void Init();
|
||||
HRESULT Flush();
|
||||
// void ReleaseStream();
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
|
||||
void *GetBuffer(UINT32 &sizeAvail)
|
||||
/*
|
||||
void *GetBuffer(UInt32 &sizeAvail)
|
||||
{
|
||||
sizeAvail = _bufferSize - _pos;
|
||||
return _buffer + _pos;
|
||||
}
|
||||
void MovePos(UINT32 num)
|
||||
void MovePos(UInt32 num)
|
||||
{
|
||||
_pos += num;
|
||||
if(_pos >= _bufferSize)
|
||||
WriteBlock();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void WriteByte(BYTE b)
|
||||
void WriteByte(Byte b)
|
||||
{
|
||||
_buffer[_pos++] = b;
|
||||
if(_pos >= _bufferSize)
|
||||
WriteBlock();
|
||||
}
|
||||
void WriteBytes(const void *data, UINT32 size)
|
||||
void WriteBytes(const void *data, UInt32 size)
|
||||
{
|
||||
for (UINT32 i = 0; i < size; i++)
|
||||
WriteByte(((const BYTE *)data)[i]);
|
||||
for (UInt32 i = 0; i < size; i++)
|
||||
WriteByte(((const Byte *)data)[i]);
|
||||
}
|
||||
|
||||
UINT64 GetProcessedSize() const { return _processedSize + _pos; }
|
||||
UInt64 GetProcessedSize() const { return _processedSize + _pos; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "ProgressUtils.h"
|
||||
|
||||
void CLocalCompressProgressInfo::Init(ICompressProgressInfo *progress,
|
||||
const UINT64 *inStartValue, const UINT64 *outStartValue)
|
||||
const UInt64 *inStartValue, const UInt64 *outStartValue)
|
||||
{
|
||||
_progress = progress;
|
||||
_inStartValueIsAssigned = (inStartValue != NULL);
|
||||
@@ -17,11 +17,11 @@ void CLocalCompressProgressInfo::Init(ICompressProgressInfo *progress,
|
||||
}
|
||||
|
||||
STDMETHODIMP CLocalCompressProgressInfo::SetRatioInfo(
|
||||
const UINT64 *inSize, const UINT64 *outSize)
|
||||
const UInt64 *inSize, const UInt64 *outSize)
|
||||
{
|
||||
UINT64 inSizeNew, outSizeNew;
|
||||
const UINT64 *inSizeNewPointer;
|
||||
const UINT64 *outSizeNewPointer;
|
||||
UInt64 inSizeNew, outSizeNew;
|
||||
const UInt64 *inSizeNewPointer;
|
||||
const UInt64 *outSizeNewPointer;
|
||||
if (_inStartValueIsAssigned && inSize != NULL)
|
||||
{
|
||||
inSizeNew = _inStartValue + (*inSize);
|
||||
@@ -51,7 +51,7 @@ void CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)
|
||||
}
|
||||
|
||||
STDMETHODIMP CLocalProgress::SetRatioInfo(
|
||||
const UINT64 *inSize, const UINT64 *outSize)
|
||||
const UInt64 *inSize, const UInt64 *outSize)
|
||||
{
|
||||
return _progress->SetCompleted(_inSizeIsMain ? inSize : outSize);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// ProgressUtils.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __PROGRESSUTILS_H
|
||||
#define __PROGRESSUTILS_H
|
||||
|
||||
@@ -17,21 +15,17 @@ class CLocalCompressProgressInfo:
|
||||
CMyComPtr<ICompressProgressInfo> _progress;
|
||||
bool _inStartValueIsAssigned;
|
||||
bool _outStartValueIsAssigned;
|
||||
UINT64 _inStartValue;
|
||||
UINT64 _outStartValue;
|
||||
UInt64 _inStartValue;
|
||||
UInt64 _outStartValue;
|
||||
public:
|
||||
void Init(ICompressProgressInfo *progress,
|
||||
const UINT64 *inStartValue, const UINT64 *outStartValue);
|
||||
const UInt64 *inStartValue, const UInt64 *outStartValue);
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(SetRatioInfo)(const UINT64 *inSize, const UINT64 *outSize);
|
||||
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////
|
||||
// CLocalProgress
|
||||
|
||||
class CLocalProgress:
|
||||
public ICompressProgressInfo,
|
||||
public CMyUnknownImp
|
||||
@@ -43,8 +37,7 @@ public:
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(SetRatioInfo)(const UINT64 *inSize, const UINT64 *outSize);
|
||||
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// stdafx.h
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
#include "../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,8 +16,8 @@ class CSequentialInStreamForBinder:
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
private:
|
||||
CStreamBinder *m_StreamBinder;
|
||||
public:
|
||||
@@ -25,10 +25,10 @@ public:
|
||||
void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }
|
||||
};
|
||||
|
||||
STDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
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)
|
||||
STDMETHODIMP CSequentialInStreamForBinder::ReadPart(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{ return m_StreamBinder->ReadPart(data, size, processedSize); }
|
||||
|
||||
class CSequentialOutStreamForBinder:
|
||||
@@ -38,8 +38,8 @@ class CSequentialOutStreamForBinder:
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
|
||||
private:
|
||||
CStreamBinder *m_StreamBinder;
|
||||
@@ -48,10 +48,10 @@ public:
|
||||
void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }
|
||||
};
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
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)
|
||||
STDMETHODIMP CSequentialOutStreamForBinder::WritePart(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{ return m_StreamBinder->WritePart(data, size, processedSize); }
|
||||
|
||||
|
||||
@@ -106,9 +106,9 @@ void CStreamBinder::CreateStreams(ISequentialInStream **inStream,
|
||||
ProcessedSize = 0;
|
||||
}
|
||||
|
||||
STDMETHODIMP CStreamBinder::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CStreamBinder::ReadPart(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 sizeToRead = size;
|
||||
UInt32 sizeToRead = size;
|
||||
if (size > 0)
|
||||
{
|
||||
if(!_thereAreBytesToReadEvent->Lock())
|
||||
@@ -117,7 +117,7 @@ STDMETHODIMP CStreamBinder::ReadPart(void *data, UINT32 size, UINT32 *processedS
|
||||
if (_bufferSize > 0)
|
||||
{
|
||||
MoveMemory(data, _buffer, sizeToRead);
|
||||
_buffer = ((const BYTE *)_buffer) + sizeToRead;
|
||||
_buffer = ((const Byte *)_buffer) + sizeToRead;
|
||||
_bufferSize -= sizeToRead;
|
||||
if (_bufferSize == 0)
|
||||
{
|
||||
@@ -132,16 +132,16 @@ STDMETHODIMP CStreamBinder::ReadPart(void *data, UINT32 size, UINT32 *processedS
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CStreamBinder::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 fullProcessedSize = 0;
|
||||
UINT32 realProcessedSize;
|
||||
UInt32 fullProcessedSize = 0;
|
||||
UInt32 realProcessedSize;
|
||||
HRESULT result = S_OK;
|
||||
while(size > 0)
|
||||
{
|
||||
result = ReadPart(data, size, &realProcessedSize);
|
||||
size -= realProcessedSize;
|
||||
data = (void *)((BYTE *)data + realProcessedSize);
|
||||
data = (void *)((Byte *)data + realProcessedSize);
|
||||
fullProcessedSize += realProcessedSize;
|
||||
if (result != S_OK)
|
||||
break;
|
||||
@@ -158,7 +158,7 @@ void CStreamBinder::CloseRead()
|
||||
_readStreamIsClosedEvent->Set();
|
||||
}
|
||||
|
||||
STDMETHODIMP CStreamBinder::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if (size > 0)
|
||||
{
|
||||
@@ -184,7 +184,7 @@ STDMETHODIMP CStreamBinder::Write(const void *data, UINT32 size, UINT32 *process
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CStreamBinder::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CStreamBinder::WritePart(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
@@ -194,4 +194,3 @@ void CStreamBinder::CloseWrite()
|
||||
// _bufferSize must be = 0
|
||||
_thereAreBytesToReadEvent->Set();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// StreamBinder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAMBINDER_H
|
||||
#define __STREAMBINDER_H
|
||||
|
||||
@@ -13,11 +11,11 @@ class CStreamBinder
|
||||
NWindows::NSynchronization::CManualResetEvent *_allBytesAreWritenEvent;
|
||||
NWindows::NSynchronization::CManualResetEvent *_thereAreBytesToReadEvent;
|
||||
NWindows::NSynchronization::CManualResetEvent *_readStreamIsClosedEvent;
|
||||
UINT32 _bufferSize;
|
||||
UInt32 _bufferSize;
|
||||
const void *_buffer;
|
||||
public:
|
||||
// bool ReadingWasClosed;
|
||||
UINT64 ProcessedSize;
|
||||
UInt64 ProcessedSize;
|
||||
CStreamBinder():
|
||||
_allBytesAreWritenEvent(NULL),
|
||||
_thereAreBytesToReadEvent(NULL),
|
||||
@@ -28,15 +26,14 @@ public:
|
||||
|
||||
void CreateStreams(ISequentialInStream **inStream,
|
||||
ISequentialOutStream **outStream);
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
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);
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
void CloseWrite();
|
||||
void ReInit();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "StreamObjects.h"
|
||||
#include "../../Common/Defs.h"
|
||||
|
||||
/*
|
||||
STDMETHODIMP COutStreamImp::Read(void *data, ULONG size, ULONG *processedSize)
|
||||
{ return E_NOTIMPL; }
|
||||
|
||||
@@ -19,7 +20,7 @@ STDMETHODIMP COutStreamImp::Write(void const *data, ULONG size, ULONG *processed
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CInStreamImp::Init(BYTE *dataPointer, UINT32 size)
|
||||
void CInStreamImp::Init(Byte *dataPointer, size_t size)
|
||||
{
|
||||
_dataPointer = dataPointer;
|
||||
_size = size;
|
||||
@@ -28,7 +29,7 @@ void CInStreamImp::Init(BYTE *dataPointer, UINT32 size)
|
||||
|
||||
STDMETHODIMP CInStreamImp::Read(void *data, ULONG size, ULONG *processedSize)
|
||||
{
|
||||
UINT32 numBytesToRead = MyMin(_pos + (UINT32)size, _size) - _pos;
|
||||
UInt32 numBytesToRead = MyMin(_pos + (UInt32)size, _size) - _pos;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = numBytesToRead;
|
||||
memmove(data, _dataPointer + _pos, numBytesToRead);
|
||||
@@ -41,12 +42,12 @@ STDMETHODIMP CInStreamImp::Read(void *data, ULONG size, ULONG *processedSize)
|
||||
|
||||
STDMETHODIMP CInStreamImp::Write(void const *data, ULONG size, ULONG *processedSize)
|
||||
{ return E_NOTIMPL; }
|
||||
*/
|
||||
|
||||
|
||||
|
||||
STDMETHODIMP CSequentialInStreamImp::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 numBytesToRead = MyMin(_pos + size, _size) - _pos;
|
||||
UInt32 numBytesToRead = (UInt32)(MyMin(_pos + size, _size) - _pos);
|
||||
memmove(data, _dataPointer + _pos, numBytesToRead);
|
||||
_pos += numBytesToRead;
|
||||
if(processedSize != NULL)
|
||||
@@ -54,7 +55,7 @@ STDMETHODIMP CSequentialInStreamImp::Read(void *data, UINT32 size, UINT32 *proce
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialInStreamImp::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialInStreamImp::ReadPart(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Read(data, size, processedSize);
|
||||
}
|
||||
@@ -62,7 +63,7 @@ STDMETHODIMP CSequentialInStreamImp::ReadPart(void *data, UINT32 size, UINT32 *p
|
||||
////////////////////
|
||||
|
||||
|
||||
void CWriteBuffer::Write(const void *data, UINT32 size)
|
||||
void CWriteBuffer::Write(const void *data, size_t size)
|
||||
{
|
||||
size_t newCapacity = _size + size;
|
||||
_buffer.EnsureCapacity(newCapacity);
|
||||
@@ -70,7 +71,7 @@ void CWriteBuffer::Write(const void *data, UINT32 size)
|
||||
_size += size;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
_writeBuffer.Write(data, size);
|
||||
if(processedSize != NULL)
|
||||
@@ -78,14 +79,14 @@ STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UINT32 size, UINT3
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamImp::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
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)
|
||||
STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 newSize = size;
|
||||
UInt32 newSize = size;
|
||||
if (_pos + size > _size)
|
||||
newSize = _size - _pos;
|
||||
memmove(_buffer + _pos, data, newSize);
|
||||
@@ -97,16 +98,16 @@ STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UINT32 size, UINT
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamImp2::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialOutStreamImp2::WritePart(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
UInt32 realProcessedSize;
|
||||
HRESULT result = _stream->Read(data, size, &realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
@@ -114,9 +115,9 @@ STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UINT32 size, UINT32
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialInStreamSizeCount::ReadPart(void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialInStreamSizeCount::ReadPart(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
UInt32 realProcessedSize;
|
||||
HRESULT result = _stream->ReadPart(data, size, &realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
@@ -124,10 +125,63 @@ STDMETHODIMP CSequentialInStreamSizeCount::ReadPart(void *data, UINT32 size, UIN
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialInStreamRollback::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
HRESULT result = S_OK;
|
||||
UInt32 realProcessedSizeTotal = 0;
|
||||
while (size > 0)
|
||||
{
|
||||
UInt32 realProcessedSize = 0;
|
||||
result = ReadPart(data, size, &realProcessedSize);
|
||||
size -= realProcessedSize;
|
||||
data = ((Byte *)data + realProcessedSize);
|
||||
realProcessedSizeTotal += realProcessedSize;
|
||||
if (realProcessedSize == 0 || result != S_OK)
|
||||
break;
|
||||
}
|
||||
if (processedSize != 0)
|
||||
*processedSize = realProcessedSizeTotal;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialInStreamRollback::ReadPart(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if (_currentPos != _currentSize)
|
||||
{
|
||||
UInt32 curSize = _currentSize - _currentPos;
|
||||
if (size > curSize)
|
||||
size = curSize;
|
||||
memmove(data, _buffer + _currentPos, size);
|
||||
_currentPos += size;
|
||||
if (processedSize != 0)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
UInt32 realProcessedSize;
|
||||
if (size > _bufferSize)
|
||||
size = _bufferSize;
|
||||
HRESULT result = _stream->ReadPart(_buffer, size, &realProcessedSize);
|
||||
memmove(data, _buffer, realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
_currentSize = realProcessedSize;
|
||||
_currentPos = realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
*processedSize = realProcessedSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT CSequentialInStreamRollback::Rollback(size_t rollbackSize)
|
||||
{
|
||||
if (rollbackSize > _currentPos)
|
||||
return E_INVALIDARG;
|
||||
_currentPos -= rollbackSize;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UInt32 realProcessedSize;
|
||||
HRESULT result = _stream->Write(data, size, &realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
@@ -135,9 +189,9 @@ STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UINT32 size,
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSequentialOutStreamSizeCount::WritePart(const void *data, UINT32 size, UINT32 *processedSize)
|
||||
STDMETHODIMP CSequentialOutStreamSizeCount::WritePart(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
UInt32 realProcessedSize;
|
||||
HRESULT result = _stream->WritePart(data, size, &realProcessedSize);
|
||||
_size += realProcessedSize;
|
||||
if (processedSize != 0)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// StreamObjects.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAMOBJECTS_H
|
||||
#define __STREAMOBJECTS_H
|
||||
|
||||
@@ -9,16 +7,17 @@
|
||||
#include "../../Common/MyCom.h"
|
||||
#include "../IStream.h"
|
||||
|
||||
/*
|
||||
class COutStreamImp:
|
||||
public ISequentialStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CByteDynamicBuffer _buffer;
|
||||
UINT32 _size;
|
||||
size_t _size;
|
||||
public:
|
||||
COutStreamImp(): _size(0) {}
|
||||
void Init(){ _size = 0; }
|
||||
UINT32 GetSize() const { return _size; }
|
||||
size_t GetSize() const { return _size; }
|
||||
const CByteDynamicBuffer& GetBuffer() const { return _buffer; }
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
@@ -31,30 +30,31 @@ class CInStreamImp:
|
||||
public ISequentialStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
BYTE *_dataPointer;
|
||||
UINT32 _size;
|
||||
UINT32 _pos;
|
||||
Byte *_dataPointer;
|
||||
size_t _size;
|
||||
size_t _pos;
|
||||
|
||||
public:
|
||||
CInStreamImp(): _size(0xFFFFFFFF), _pos(0), _dataPointer(NULL) {}
|
||||
void Init(BYTE *dataPointer, UINT32 size);
|
||||
void Init(Byte *dataPointer, size_t 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;
|
||||
const Byte *_dataPointer;
|
||||
size_t _size;
|
||||
size_t _pos;
|
||||
|
||||
public:
|
||||
void Init(const BYTE *dataPointer, UINT32 size)
|
||||
void Init(const Byte *dataPointer, size_t size)
|
||||
{
|
||||
_dataPointer = dataPointer;
|
||||
_size = size;
|
||||
@@ -63,18 +63,18 @@ public:
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
|
||||
class CWriteBuffer
|
||||
{
|
||||
CByteDynamicBuffer _buffer;
|
||||
UINT32 _size;
|
||||
size_t _size;
|
||||
public:
|
||||
CWriteBuffer(): _size(0) {}
|
||||
// void Init(UINT32 size = 0)
|
||||
// void Init(size_t size = 0)
|
||||
void Init()
|
||||
{
|
||||
/*
|
||||
@@ -83,8 +83,8 @@ public:
|
||||
*/
|
||||
_size = 0;
|
||||
}
|
||||
void Write(const void *data, UINT32 size);
|
||||
UINT32 GetSize() const { return _size; }
|
||||
void Write(const void *data, size_t size);
|
||||
size_t GetSize() const { return _size; }
|
||||
const CByteDynamicBuffer& GetBuffer() const { return _buffer; }
|
||||
};
|
||||
|
||||
@@ -100,30 +100,30 @@ public:
|
||||
}
|
||||
|
||||
/*
|
||||
void Init(UINT32 size = 0)
|
||||
void Init(size_t size = 0)
|
||||
{
|
||||
_writeBuffer.Init(size);
|
||||
}
|
||||
*/
|
||||
UINT32 GetSize() const { return _writeBuffer.GetSize(); }
|
||||
size_t 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);
|
||||
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;
|
||||
Byte *_buffer;
|
||||
public:
|
||||
UINT32 _size;
|
||||
UINT32 _pos;
|
||||
size_t _size;
|
||||
size_t _pos;
|
||||
|
||||
void Init(BYTE *buffer, UINT32 size)
|
||||
void Init(Byte *buffer, size_t size)
|
||||
{
|
||||
_buffer = buffer;
|
||||
_pos = 0;
|
||||
@@ -132,8 +132,8 @@ public:
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
class CSequentialInStreamSizeCount:
|
||||
@@ -141,19 +141,58 @@ class CSequentialInStreamSizeCount:
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
UINT64 _size;
|
||||
UInt64 _size;
|
||||
public:
|
||||
void Init(ISequentialInStream *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
_size = 0;
|
||||
}
|
||||
UINT64 GetSize() const { return _size; }
|
||||
UInt64 GetSize() const { return _size; }
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UINT32 size, UINT32 *processedSize);
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
class CSequentialInStreamRollback:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
Byte *_buffer;
|
||||
size_t _bufferSize;
|
||||
UInt64 _size;
|
||||
|
||||
size_t _currentSize;
|
||||
size_t _currentPos;
|
||||
public:
|
||||
CSequentialInStreamRollback(size_t bufferSize):
|
||||
_bufferSize(bufferSize),
|
||||
_buffer(0)
|
||||
{
|
||||
_buffer = new Byte[bufferSize];
|
||||
}
|
||||
~CSequentialInStreamRollback()
|
||||
{
|
||||
delete _buffer;
|
||||
}
|
||||
|
||||
void Init(ISequentialInStream *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
_size = 0;
|
||||
_currentSize = 0;
|
||||
_currentPos = 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);
|
||||
HRESULT Rollback(size_t rollbackSize);
|
||||
};
|
||||
|
||||
class CSequentialOutStreamSizeCount:
|
||||
@@ -161,19 +200,19 @@ class CSequentialOutStreamSizeCount:
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UINT64 _size;
|
||||
UInt64 _size;
|
||||
public:
|
||||
void Init(ISequentialOutStream *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
_size = 0;
|
||||
}
|
||||
UINT64 GetSize() const { return _size; }
|
||||
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);
|
||||
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