9.04 beta

This commit is contained in:
Igor Pavlov
2009-06-02 00:00:00 +00:00
committed by Kornel Lesiński
parent 8874e4fbc9
commit 829409452d
440 changed files with 19803 additions and 9941 deletions
+127
View File
@@ -0,0 +1,127 @@
// CWrappers.h
#include "StdAfx.h"
#include "CWrappers.h"
#include "StreamUtils.h"
#define PROGRESS_UNKNOWN_VALUE ((UInt64)(Int64)-1)
#define CONVERT_PR_VAL(x) (x == PROGRESS_UNKNOWN_VALUE ? NULL : &x)
static SRes CompressProgress(void *pp, UInt64 inSize, UInt64 outSize)
{
CCompressProgressWrap *p = (CCompressProgressWrap *)pp;
p->Res = p->Progress->SetRatioInfo(CONVERT_PR_VAL(inSize), CONVERT_PR_VAL(outSize));
return (SRes)p->Res;
}
CCompressProgressWrap::CCompressProgressWrap(ICompressProgressInfo *progress)
{
p.Progress = CompressProgress;
Progress = progress;
Res = SZ_OK;
}
static const UInt32 kStreamStepSize = (UInt32)1 << 31;
SRes HRESULT_To_SRes(HRESULT res, SRes defaultRes)
{
switch(res)
{
case S_OK: return SZ_OK;
case E_OUTOFMEMORY: return SZ_ERROR_MEM;
case E_INVALIDARG: return SZ_ERROR_PARAM;
case E_ABORT: return SZ_ERROR_PROGRESS;
case S_FALSE: return SZ_ERROR_DATA;
}
return defaultRes;
}
static SRes MyRead(void *object, void *data, size_t *size)
{
CSeqInStreamWrap *p = (CSeqInStreamWrap *)object;
UInt32 curSize = ((*size < kStreamStepSize) ? (UInt32)*size : kStreamStepSize);
p->Res = (p->Stream->Read(data, curSize, &curSize));
*size = curSize;
if (p->Res == S_OK)
return SZ_OK;
return HRESULT_To_SRes(p->Res, SZ_ERROR_READ);
}
static size_t MyWrite(void *object, const void *data, size_t size)
{
CSeqOutStreamWrap *p = (CSeqOutStreamWrap *)object;
if (p->Stream)
{
p->Res = WriteStream(p->Stream, data, size);
if (p->Res != 0)
return 0;
}
else
p->Res = S_OK;
p->Processed += size;
return size;
}
CSeqInStreamWrap::CSeqInStreamWrap(ISequentialInStream *stream)
{
p.Read = MyRead;
Stream = stream;
}
CSeqOutStreamWrap::CSeqOutStreamWrap(ISequentialOutStream *stream)
{
p.Write = MyWrite;
Stream = stream;
Res = SZ_OK;
Processed = 0;
}
HRESULT SResToHRESULT(SRes res)
{
switch(res)
{
case SZ_OK: return S_OK;
case SZ_ERROR_MEM: return E_OUTOFMEMORY;
case SZ_ERROR_PARAM: return E_INVALIDARG;
case SZ_ERROR_PROGRESS: return E_ABORT;
case SZ_ERROR_DATA: return S_FALSE;
}
return E_FAIL;
}
static SRes InStreamWrap_Read(void *pp, void *data, size_t *size)
{
CSeekInStreamWrap *p = (CSeekInStreamWrap *)pp;
UInt32 curSize = ((*size < kStreamStepSize) ? (UInt32)*size : kStreamStepSize);
p->Res = p->Stream->Read(data, curSize, &curSize);
*size = curSize;
return (p->Res == S_OK) ? SZ_OK : SZ_ERROR_READ;
}
static SRes InStreamWrap_Seek(void *pp, Int64 *offset, ESzSeek origin)
{
CSeekInStreamWrap *p = (CSeekInStreamWrap *)pp;
UInt32 moveMethod;
switch(origin)
{
case SZ_SEEK_SET: moveMethod = STREAM_SEEK_SET; break;
case SZ_SEEK_CUR: moveMethod = STREAM_SEEK_CUR; break;
case SZ_SEEK_END: moveMethod = STREAM_SEEK_END; break;
default: return SZ_ERROR_PARAM;
}
UInt64 newPosition;
p->Res = p->Stream->Seek(*offset, moveMethod, &newPosition);
*offset = (Int64)newPosition;
return (p->Res == S_OK) ? SZ_OK : SZ_ERROR_READ;
}
CSeekInStreamWrap::CSeekInStreamWrap(IInStream *stream)
{
Stream = stream;
p.Read = InStreamWrap_Read;
p.Seek = InStreamWrap_Seek;
Res = S_OK;
}
+46
View File
@@ -0,0 +1,46 @@
// CWrappers.h
#ifndef __C_WRAPPERS_H
#define __C_WRAPPERS_H
#include "../../../C/Types.h"
#include "../ICoder.h"
#include "../../Common/MyCom.h"
struct CCompressProgressWrap
{
ICompressProgress p;
ICompressProgressInfo *Progress;
HRESULT Res;
CCompressProgressWrap(ICompressProgressInfo *progress);
};
struct CSeqInStreamWrap
{
ISeqInStream p;
ISequentialInStream *Stream;
HRESULT Res;
CSeqInStreamWrap(ISequentialInStream *stream);
};
struct CSeekInStreamWrap
{
ISeekInStream p;
IInStream *Stream;
HRESULT Res;
CSeekInStreamWrap(IInStream *stream);
};
struct CSeqOutStreamWrap
{
ISeqOutStream p;
ISequentialOutStream *Stream;
HRESULT Res;
UInt64 Processed;
CSeqOutStreamWrap(ISequentialOutStream *stream);
};
HRESULT SResToHRESULT(SRes res);
#endif
+14 -16
View File
@@ -1,25 +1,25 @@
// FilePathAutoRename.cpp
#include "StdAfx.h"
#include "FilePathAutoRename.h"
#include "Common/Defs.h"
#include "Common/IntToString.h"
#include "Windows/FileName.h"
#include "Windows/FileFind.h"
#include "FilePathAutoRename.h"
using namespace NWindows;
static bool MakeAutoName(const UString &name,
const UString &extension, int value, UString &path)
const UString &extension, unsigned value, UString &path)
{
wchar_t number[32];
ConvertUInt64ToString(value, number);
wchar_t number[16];
ConvertUInt32ToString(value, number);
path = name;
path += number;
path += extension;
return NFile::NFind::DoesFileExist(path);
return NFile::NFind::DoesFileOrDirExist(path);
}
bool AutoRenamePath(UString &fullProcessedPath)
@@ -34,7 +34,7 @@ bool AutoRenamePath(UString &fullProcessedPath)
#endif
UString name, extension;
if (dotPos > slashPos && dotPos > 0)
if (dotPos > slashPos && dotPos > 0)
{
name = fullProcessedPath.Left(dotPos);
extension = fullProcessedPath.Mid(dotPos);
@@ -42,16 +42,14 @@ bool AutoRenamePath(UString &fullProcessedPath)
else
name = fullProcessedPath;
name += L'_';
int indexLeft = 1, indexRight = (1 << 30);
while (indexLeft != indexRight)
unsigned left = 1, right = (1 << 30);
while (left != right)
{
int indexMid = (indexLeft + indexRight) / 2;
if (MakeAutoName(name, extension, indexMid, path))
indexLeft = indexMid + 1;
unsigned mid = (left + right) / 2;
if (MakeAutoName(name, extension, mid, path))
left = mid + 1;
else
indexRight = indexMid;
right = mid;
}
if (MakeAutoName(name, extension, indexRight, fullProcessedPath))
return false;
return true;
return !MakeAutoName(name, extension, right, fullProcessedPath);
}
+167 -22
View File
@@ -8,6 +8,11 @@
#include <errno.h>
#endif
#ifdef SUPPORT_DEVICE_FILE
#include "../../../C/Alloc.h"
#include "../../Common/Defs.h"
#endif
#include "FileStreams.h"
static inline HRESULT ConvertBoolToHRESULT(bool result)
@@ -52,24 +57,138 @@ bool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite)
#endif
#endif
#ifdef SUPPORT_DEVICE_FILE
static const UInt32 kClusterSize = 1 << 18;
CInFileStream::CInFileStream():
VirtPos(0),
PhyPos(0),
Buffer(0),
BufferSize(0)
{
}
#endif
CInFileStream::~CInFileStream()
{
#ifdef SUPPORT_DEVICE_FILE
MidFree(Buffer);
#endif
}
STDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
#ifdef USE_WIN_FILE
#ifdef SUPPORT_DEVICE_FILE
if (processedSize != NULL)
*processedSize = 0;
if (size == 0)
return S_OK;
if (File.IsDeviceFile)
{
if (File.LengthDefined)
{
if (VirtPos >= File.Length)
return VirtPos == File.Length ? S_OK : E_FAIL;
UInt64 rem = File.Length - VirtPos;
if (size > rem)
size = (UInt32)rem;
}
for (;;)
{
const UInt32 mask = kClusterSize - 1;
UInt64 mask2 = ~(UInt64)mask;
UInt64 alignedPos = VirtPos & mask2;
if (BufferSize > 0 && BufferStartPos == alignedPos)
{
UInt32 pos = (UInt32)VirtPos & mask;
if (pos >= BufferSize)
return S_OK;
UInt32 rem = MyMin(BufferSize - pos, size);
memcpy(data, Buffer + pos, rem);
VirtPos += rem;
if (processedSize != NULL)
*processedSize += rem;
return S_OK;
}
bool useBuffer = false;
if ((VirtPos & mask) != 0 || ((ptrdiff_t)data & mask) != 0 )
useBuffer = true;
else
{
UInt64 end = VirtPos + size;
if ((end & mask) != 0)
{
end &= mask2;
if (end <= VirtPos)
useBuffer = true;
else
size = (UInt32)(end - VirtPos);
}
}
if (!useBuffer)
break;
if (alignedPos != PhyPos)
{
UInt64 realNewPosition;
bool result = File.Seek(alignedPos, FILE_BEGIN, realNewPosition);
if (!result)
return ConvertBoolToHRESULT(result);
PhyPos = realNewPosition;
}
BufferStartPos = alignedPos;
UInt32 readSize = kClusterSize;
if (File.LengthDefined)
readSize = (UInt32)MyMin(File.Length - PhyPos, (UInt64)kClusterSize);
if (Buffer == 0)
{
Buffer = (Byte *)MidAlloc(kClusterSize);
if (Buffer == 0)
return E_OUTOFMEMORY;
}
bool result = File.Read1(Buffer, readSize, BufferSize);
if (!result)
return ConvertBoolToHRESULT(result);
if (BufferSize == 0)
return S_OK;
PhyPos += BufferSize;
}
if (VirtPos != PhyPos)
{
UInt64 realNewPosition;
bool result = File.Seek(VirtPos, FILE_BEGIN, realNewPosition);
if (!result)
return ConvertBoolToHRESULT(result);
PhyPos = VirtPos = realNewPosition;
}
}
#endif
UInt32 realProcessedSize;
bool result = File.ReadPart(data, size, realProcessedSize);
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = realProcessedSize;
#ifdef SUPPORT_DEVICE_FILE
VirtPos += realProcessedSize;
PhyPos += realProcessedSize;
#endif
return ConvertBoolToHRESULT(result);
#else
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = 0;
ssize_t res = File.Read(data, (size_t)size);
if (res == -1)
return E_FAIL;
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = (UInt32)res;
return S_OK;
@@ -80,10 +199,13 @@ STDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)
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)
DWORD realProcessedSize;
UInt32 sizeTemp = (1 << 20);
if (sizeTemp > size)
sizeTemp = size;
BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), data, sizeTemp, &realProcessedSize, NULL);
if (processedSize != NULL)
*processedSize = realProcessedSize;
if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)
return S_OK;
@@ -91,7 +213,7 @@ STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSi
#else
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = 0;
ssize_t res;
do
@@ -101,7 +223,7 @@ STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSi
while (res < 0 && (errno == EINTR));
if (res == -1)
return E_FAIL;
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = (UInt32)res;
return S_OK;
@@ -113,14 +235,37 @@ STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSi
STDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,
UInt64 *newPosition)
{
if(seekOrigin >= 3)
if (seekOrigin >= 3)
return STG_E_INVALIDFUNCTION;
#ifdef USE_WIN_FILE
#ifdef SUPPORT_DEVICE_FILE
if (File.IsDeviceFile)
{
UInt64 newVirtPos = offset;
switch(seekOrigin)
{
case STREAM_SEEK_SET: break;
case STREAM_SEEK_CUR: newVirtPos += VirtPos; break;
case STREAM_SEEK_END: newVirtPos += File.Length; break;
default: return STG_E_INVALIDFUNCTION;
}
VirtPos = newVirtPos;
if (newPosition)
*newPosition = newVirtPos;
return S_OK;
}
#endif
UInt64 realNewPosition;
bool result = File.Seek(offset, seekOrigin, realNewPosition);
if(newPosition != NULL)
#ifdef SUPPORT_DEVICE_FILE
PhyPos = VirtPos = realNewPosition;
#endif
if (newPosition != NULL)
*newPosition = realNewPosition;
return ConvertBoolToHRESULT(result);
@@ -129,7 +274,7 @@ STDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,
off_t res = File.Seek(offset, seekOrigin);
if (res == -1)
return E_FAIL;
if(newPosition != NULL)
if (newPosition != NULL)
*newPosition = (UInt64)res;
return S_OK;
@@ -157,18 +302,18 @@ STDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *proces
UInt32 realProcessedSize;
bool result = File.WritePart(data, size, realProcessedSize);
ProcessedSize += realProcessedSize;
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = realProcessedSize;
return ConvertBoolToHRESULT(result);
#else
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = 0;
ssize_t res = File.Write(data, (size_t)size);
if (res == -1)
return E_FAIL;
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = (UInt32)res;
ProcessedSize += res;
return S_OK;
@@ -178,13 +323,13 @@ STDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *proces
STDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
{
if(seekOrigin >= 3)
if (seekOrigin >= 3)
return STG_E_INVALIDFUNCTION;
#ifdef USE_WIN_FILE
UInt64 realNewPosition;
bool result = File.Seek(offset, seekOrigin, realNewPosition);
if(newPosition != NULL)
if (newPosition != NULL)
*newPosition = realNewPosition;
return ConvertBoolToHRESULT(result);
@@ -193,7 +338,7 @@ STDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPo
off_t res = File.Seek(offset, seekOrigin);
if (res == -1)
return E_FAIL;
if(newPosition != NULL)
if (newPosition != NULL)
*newPosition = (UInt64)res;
return S_OK;
@@ -204,7 +349,7 @@ STDMETHODIMP COutFileStream::SetSize(Int64 newSize)
{
#ifdef USE_WIN_FILE
UInt64 currentPos;
if(!File.Seek(0, FILE_CURRENT, currentPos))
if (!File.Seek(0, FILE_CURRENT, currentPos))
return E_FAIL;
bool result = File.SetLength(newSize);
UInt64 currentPos2;
@@ -218,7 +363,7 @@ STDMETHODIMP COutFileStream::SetSize(Int64 newSize)
#ifndef _WIN32_WCE
STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = 0;
#ifdef _WIN32
@@ -235,7 +380,7 @@ STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *pro
data, sizeTemp, (DWORD *)&realProcessedSize, NULL);
size -= realProcessedSize;
data = (const void *)((const Byte *)data + realProcessedSize);
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize += realProcessedSize;
}
return ConvertBoolToHRESULT(res != FALSE);
@@ -250,7 +395,7 @@ STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *pro
while (res < 0 && (errno == EINTR));
if (res == -1)
return E_FAIL;
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = (UInt32)res;
return S_OK;
+14 -6
View File
@@ -13,9 +13,10 @@
#include "../../Common/C_FileIO.h"
#endif
#include "../IStream.h"
#include "../../Common/MyCom.h"
#include "../IStream.h"
class CInFileStream:
public IInStream,
public IStreamGetSize,
@@ -24,12 +25,22 @@ class CInFileStream:
public:
#ifdef USE_WIN_FILE
NWindows::NFile::NIO::CInFile File;
#ifdef SUPPORT_DEVICE_FILE
UInt64 VirtPos;
UInt64 PhyPos;
UInt64 BufferStartPos;
Byte *Buffer;
UInt32 BufferSize;
#endif
#else
NC::NFile::NIO::CInFile File;
#endif
CInFileStream() {}
virtual ~CInFileStream() {}
virtual ~CInFileStream();
#ifdef SUPPORT_DEVICE_FILE
CInFileStream();
#endif
bool Open(LPCTSTR fileName);
#ifdef USE_WIN_FILE
#ifndef _UNICODE
@@ -58,9 +69,6 @@ class CStdInFileStream:
public CMyUnknownImp
{
public:
// HANDLE File;
// CStdInFileStream() File(INVALID_HANDLE_VALUE): {}
// void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };
MY_UNKNOWN_IMP
virtual ~CStdInFileStream() {}
+3 -4
View File
@@ -2,12 +2,11 @@
#include "StdAfx.h"
#include "FilterCoder.h"
extern "C"
{
#include "../../../C/Alloc.h"
}
#include "../../Common/Defs.h"
#include "FilterCoder.h"
#include "StreamUtils.h"
static const UInt32 kBufferSize = 1 << 17;
+2 -5
View File
@@ -2,12 +2,9 @@
#include "StdAfx.h"
#include "InBuffer.h"
#include "../../../C/Alloc.h"
extern "C"
{
#include "../../../C/Alloc.h"
}
#include "InBuffer.h"
CInBuffer::CInBuffer():
_buffer(0),
+5 -2
View File
@@ -1,11 +1,14 @@
// InMemStream.h
#ifndef __INMEMSTREAM_H
#define __INMEMSTREAM_H
#ifndef __IN_MEM_STREAM_H
#define __IN_MEM_STREAM_H
#include <stdio.h>
#include "../../../C/Alloc.h"
#include "../../Common/MyCom.h"
#include "MemBlocks.h"
class CIntListCheck
+113 -4
View File
@@ -17,11 +17,116 @@ STDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *p
if (realProcessedSize == 0)
_wasFinished = true;
}
if(processedSize != NULL)
if (processedSize != NULL)
*processedSize = realProcessedSize;
return result;
}
STDMETHODIMP CLimitedInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
if (processedSize != NULL)
*processedSize = 0;
if (_virtPos >= _size)
return (_virtPos == _size) ? S_OK: E_FAIL;
UInt64 rem = _size - _virtPos;
if (rem < size)
size = (UInt32)rem;
UInt64 newPos = _startOffset + _virtPos;
if (newPos != _physPos)
{
_physPos = newPos;
RINOK(SeekToPhys());
}
HRESULT res = _stream->Read(data, size, &size);
if (processedSize != NULL)
*processedSize = size;
_physPos += size;
_virtPos += size;
return res;
}
STDMETHODIMP CLimitedInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
{
switch(seekOrigin)
{
case STREAM_SEEK_SET: _virtPos = offset; break;
case STREAM_SEEK_CUR: _virtPos += offset; break;
case STREAM_SEEK_END: _virtPos = _size + offset; break;
default: return STG_E_INVALIDFUNCTION;
}
if (newPosition)
*newPosition = _virtPos;
return S_OK;
}
STDMETHODIMP CClusterInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
if (processedSize != NULL)
*processedSize = 0;
if (_virtPos >= Size)
return (_virtPos == Size) ? S_OK: E_FAIL;
if (_curRem == 0)
{
UInt32 blockSize = (UInt32)1 << BlockSizeLog;
UInt32 virtBlock = (UInt32)(_virtPos >> BlockSizeLog);
UInt32 offsetInBlock = (UInt32)_virtPos & (blockSize - 1);
UInt32 phyBlock = Vector[virtBlock];
UInt64 newPos = StartOffset + ((UInt64)phyBlock << BlockSizeLog) + offsetInBlock;
if (newPos != _physPos)
{
_physPos = newPos;
RINOK(SeekToPhys());
}
_curRem = blockSize - offsetInBlock;
for (int i = 1; i < 64 && (virtBlock + i) < (UInt32)Vector.Size() && phyBlock + i == Vector[virtBlock + i]; i++)
_curRem += (UInt32)1 << BlockSizeLog;
UInt64 rem = Size - _virtPos;
if (_curRem > rem)
_curRem = (UInt32)rem;
}
if (size > _curRem)
size = _curRem;
HRESULT res = Stream->Read(data, size, &size);
if (processedSize != NULL)
*processedSize = size;
_physPos += size;
_virtPos += size;
_curRem -= size;
return res;
}
STDMETHODIMP CClusterInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
{
UInt64 newVirtPos = offset;
switch(seekOrigin)
{
case STREAM_SEEK_SET: break;
case STREAM_SEEK_CUR: newVirtPos += _virtPos; break;
case STREAM_SEEK_END: newVirtPos += Size; break;
default: return STG_E_INVALIDFUNCTION;
}
if (_virtPos != newVirtPos)
_curRem = 0;
_virtPos = newVirtPos;
if (newPosition)
*newPosition = newVirtPos;
return S_OK;
}
HRESULT CreateLimitedInStream(IInStream *inStream, UInt64 pos, UInt64 size, ISequentialInStream **resStream)
{
*resStream = 0;
CLimitedInStream *streamSpec = new CLimitedInStream;
CMyComPtr<ISequentialInStream> streamTemp = streamSpec;
streamSpec->SetStream(inStream);
RINOK(streamSpec->InitAndSeek(pos, size));
streamSpec->SeekToStart();
*resStream = streamTemp.Detach();
return S_OK;
}
STDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
HRESULT result = S_OK;
@@ -29,12 +134,16 @@ STDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, U
*processedSize = 0;
if (size > _size)
{
size = (UInt32)_size;
if (size == 0)
if (_size == 0)
{
_overflow = true;
return E_FAIL;
if (!_overflowIsAllowed)
return E_FAIL;
if (processedSize != NULL)
*processedSize = size;
return S_OK;
}
size = (UInt32)_size;
}
if (_stream)
result = _stream->Write(data, size, &size);
+73 -3
View File
@@ -1,9 +1,10 @@
// LimitedStreams.h
#ifndef __LIMITEDSTREAMS_H
#define __LIMITEDSTREAMS_H
#ifndef __LIMITED_STREAMS_H
#define __LIMITED_STREAMS_H
#include "../../Common/MyCom.h"
#include "../../Common/MyVector.h"
#include "../IStream.h"
class CLimitedSequentialInStream:
@@ -30,6 +31,73 @@ public:
bool WasFinished() const { return _wasFinished; }
};
class CLimitedInStream:
public IInStream,
public CMyUnknownImp
{
CMyComPtr<IInStream> _stream;
UInt64 _virtPos;
UInt64 _physPos;
UInt64 _size;
UInt64 _startOffset;
HRESULT SeekToPhys() { return _stream->Seek(_physPos, STREAM_SEEK_SET, NULL); }
public:
void SetStream(IInStream *stream) { _stream = stream; }
HRESULT InitAndSeek(UInt64 startOffset, UInt64 size)
{
_startOffset = startOffset;
_physPos = startOffset;
_virtPos = 0;
_size = size;
return SeekToPhys();
}
MY_UNKNOWN_IMP1(IInStream)
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
HRESULT SeekToStart() { return Seek(0, STREAM_SEEK_SET, NULL); }
};
class CClusterInStream:
public IInStream,
public CMyUnknownImp
{
UInt64 _virtPos;
UInt64 _physPos;
UInt32 _curRem;
public:
CMyComPtr<IInStream> Stream;
UInt64 StartOffset;
UInt64 Size;
int BlockSizeLog;
CRecordVector<UInt32> Vector;
HRESULT SeekToPhys() { return Stream->Seek(_physPos, STREAM_SEEK_SET, NULL); }
HRESULT InitAndSeek()
{
_curRem = 0;
_virtPos = 0;
_physPos = StartOffset;
if (Vector.Size() > 0)
{
_physPos = StartOffset + (Vector[0] << BlockSizeLog);
return SeekToPhys();
}
return S_OK;
}
MY_UNKNOWN_IMP1(IInStream)
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
};
HRESULT CreateLimitedInStream(IInStream *inStream, UInt64 pos, UInt64 size, ISequentialInStream **resStream);
class CLimitedSequentialOutStream:
public ISequentialOutStream,
public CMyUnknownImp
@@ -37,15 +105,17 @@ class CLimitedSequentialOutStream:
CMyComPtr<ISequentialOutStream> _stream;
UInt64 _size;
bool _overflow;
bool _overflowIsAllowed;
public:
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
void ReleaseStream() { _stream.Release(); }
void Init(UInt64 size)
void Init(UInt64 size, bool overflowIsAllowed = false)
{
_size = size;
_overflow = false;
_overflowIsAllowed = overflowIsAllowed;
}
bool IsFinishedOK() const { return (_size == 0 && !_overflow); }
UInt64 GetRem() const { return _size; }
+2 -2
View File
@@ -2,10 +2,10 @@
#include "StdAfx.h"
#include "Common/MyCom.h"
#include "../../../C/Alloc.h"
#include "StreamUtils.h"
#include "MemBlocks.h"
#include "StreamUtils.h"
bool CMemBlockManager::AllocateSpace(size_t numBlocks)
{
+2 -8
View File
@@ -1,14 +1,8 @@
// MemBlocks.h
#ifndef __MEMBLOCKS_H
#define __MEMBLOCKS_H
#ifndef __MEM_BLOCKS_H
#define __MEM_BLOCKS_H
extern "C"
{
#include "../../../C/Alloc.h"
}
#include "Common/Types.h"
#include "Common/MyVector.h"
#include "Windows/Synchronization.h"
+3 -3
View File
@@ -8,14 +8,14 @@
#include "MethodProps.h"
static UInt64 k_LZMA = 0x030101;
// static UInt64 k_LZMA2 = 0x030102;
static const UInt64 k_LZMA = 0x030101;
static const UInt64 k_LZMA2 = 0x21;
HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)
{
bool tryReduce = false;
UInt32 reducedDictionarySize = 1 << 10;
if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))
if (inSizeForReduce != 0 && (method.Id == k_LZMA || method.Id == k_LZMA2))
{
for (;;)
{
+3 -6
View File
@@ -1,13 +1,10 @@
// OutByte.cpp
// OutBuffer.cpp
#include "StdAfx.h"
#include "OutBuffer.h"
#include "../../../C/Alloc.h"
extern "C"
{
#include "../../../C/Alloc.h"
}
#include "OutBuffer.h"
bool COutBuffer::Create(UInt32 bufferSize)
{
+2 -1
View File
@@ -40,6 +40,7 @@ CVirtThread::~CVirtThread()
ExitEvent = true;
if (StartEvent.IsCreated())
StartEvent.Set();
Thread.Wait();
if (Thread.IsCreated())
Thread.Wait();
}