9.06 beta

This commit is contained in:
Igor Pavlov
2009-08-17 00:00:00 +00:00
committed by Kornel Lesiński
parent 829409452d
commit c99f3ebdd6
445 changed files with 15246 additions and 8133 deletions
+18 -3
View File
@@ -195,7 +195,15 @@ STDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)
#endif
}
#ifndef _WIN32_WCE
#ifdef UNDER_CE
STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
size_t s2 = fread(data, 1, size, stdout);
if (processedSize != 0)
*processedSize = s2;
return (s2 = size) ? S_OK : E_FAIL;
}
#else
STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
#ifdef _WIN32
@@ -360,7 +368,15 @@ STDMETHODIMP COutFileStream::SetSize(Int64 newSize)
#endif
}
#ifndef _WIN32_WCE
#ifdef UNDER_CE
STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
size_t s2 = fwrite(data, 1, size, stdout);
if (processedSize != 0)
*processedSize = s2;
return (s2 = size) ? S_OK : E_FAIL;
}
#else
STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
if (processedSize != NULL)
@@ -402,5 +418,4 @@ STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *pro
return S_OK;
#endif
}
#endif
-4
View File
@@ -63,7 +63,6 @@ public:
STDMETHOD(GetSize)(UInt64 *size);
};
#ifndef _WIN32_WCE
class CStdInFileStream:
public ISequentialInStream,
public CMyUnknownImp
@@ -74,7 +73,6 @@ public:
virtual ~CStdInFileStream() {}
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
};
#endif
class COutFileStream:
public IOutStream,
@@ -132,7 +130,6 @@ public:
STDMETHOD(SetSize)(Int64 newSize);
};
#ifndef _WIN32_WCE
class CStdOutFileStream:
public ISequentialOutStream,
public CMyUnknownImp
@@ -143,6 +140,5 @@ public:
virtual ~CStdOutFileStream() {}
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
};
#endif
#endif
+4 -1
View File
@@ -74,7 +74,10 @@ bool CInBuffer::ReadBlock()
Byte CInBuffer::ReadBlock2()
{
if(!ReadBlock())
if (!ReadBlock())
{
_processedSize++;
return 0xFF;
}
return *_buffer++;
}
+62 -62
View File
@@ -2,121 +2,121 @@
#include "StdAfx.h"
#include "InOutTempBuffer.h"
#include "../../Common/Defs.h"
// #include "Windows/Defs.h"
#include "../../../C/7zCrc.h"
#include "InOutTempBuffer.h"
#include "StreamUtils.h"
using namespace NWindows;
using namespace NFile;
using namespace NDirectory;
static UInt32 kTmpBufferMemorySize = (1 << 20);
static const UInt32 kTempBufSize = (1 << 20);
static LPCTSTR kTempFilePrefixString = TEXT("iot");
static LPCTSTR kTempFilePrefixString = TEXT("7zt");
CInOutTempBuffer::CInOutTempBuffer():
_buffer(NULL)
{
}
CInOutTempBuffer::CInOutTempBuffer(): _buf(NULL) { }
void CInOutTempBuffer::Create()
{
_buffer = new Byte[kTmpBufferMemorySize];
if (!_buf)
_buf = new Byte[kTempBufSize];
}
CInOutTempBuffer::~CInOutTempBuffer()
{
delete []_buffer;
delete []_buf;
}
void CInOutTempBuffer::InitWriting()
{
_bufferPosition = 0;
_tmpFileCreated = false;
_fileSize = 0;
_bufPos = 0;
_tempFileCreated = false;
_size = 0;
_crc = CRC_INIT_VAL;
}
bool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)
{
if (size == 0)
return true;
if(!_tmpFileCreated)
if (!_tempFileCreated)
{
CSysString tempDirPath;
if(!MyGetTempPath(tempDirPath))
if (!MyGetTempPath(tempDirPath))
return false;
if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)
if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tempFileName) == 0)
return false;
// _outFile.SetOpenCreationDispositionCreateAlways();
if(!_outFile.Create(_tmpFileName, true))
if (!_outFile.Create(_tempFileName, true))
return false;
_tmpFileCreated = true;
_tempFileCreated = true;
}
UInt32 processedSize;
if(!_outFile.Write(data, size, processedSize))
UInt32 processed;
if (!_outFile.Write(data, size, processed))
return false;
_fileSize += processedSize;
return (processedSize == size);
}
bool CInOutTempBuffer::FlushWrite()
{
return _outFile.Close();
_crc = CrcUpdate(_crc, data, processed);
_size += processed;
return (processed == size);
}
bool CInOutTempBuffer::Write(const void *data, UInt32 size)
{
if(_bufferPosition < kTmpBufferMemorySize)
if (_bufPos < kTempBufSize)
{
UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);
memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);
_bufferPosition += curSize;
size -= curSize;
data = ((const Byte *)data) + curSize;
_fileSize += curSize;
UInt32 cur = MyMin(kTempBufSize - _bufPos, size);
memcpy(_buf + _bufPos, data, cur);
_crc = CrcUpdate(_crc, data, cur);
_bufPos += cur;
size -= cur;
data = ((const Byte *)data) + cur;
_size += cur;
}
return WriteToFile(data, size);
}
bool CInOutTempBuffer::InitReading()
{
_currentPositionInBuffer = 0;
if(_tmpFileCreated)
return _inFile.Open(_tmpFileName);
return true;
}
HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
{
if (_currentPositionInBuffer < _bufferPosition)
if (!_outFile.Close())
return E_FAIL;
UInt64 size = 0;
UInt32 crc = CRC_INIT_VAL;
if (_bufPos > 0)
{
UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;
RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite));
_currentPositionInBuffer += sizeToWrite;
RINOK(WriteStream(stream, _buf, _bufPos));
crc = CrcUpdate(crc, _buf, _bufPos);
size += _bufPos;
}
if (!_tmpFileCreated)
return true;
for (;;)
if (_tempFileCreated)
{
UInt32 localProcessedSize;
if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))
NIO::CInFile inFile;
if (!inFile.Open(_tempFileName))
return E_FAIL;
if (localProcessedSize == 0)
return S_OK;
RINOK(WriteStream(stream, _buffer, localProcessedSize));
while (size < _size)
{
UInt32 processed;
if (!inFile.ReadPart(_buf, kTempBufSize, processed))
return E_FAIL;
if (processed == 0)
break;
RINOK(WriteStream(stream, _buf, processed));
crc = CrcUpdate(crc, _buf, processed);
size += processed;
}
}
return (_crc == crc && size == _size) ? S_OK : E_FAIL;
}
STDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
STDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processed)
{
if (!_buffer->Write(data, size))
if (!_buf->Write(data, size))
{
if (processedSize != NULL)
*processedSize = 0;
if (processed != NULL)
*processed = 0;
return E_FAIL;
}
if (processedSize != NULL)
*processedSize = size;
if (processed != NULL)
*processed = size;
return S_OK;
}
+13 -20
View File
@@ -1,11 +1,11 @@
// Util/InOutTempBuffer.h
// InOutTempBuffer.h
#ifndef __IN_OUT_TEMP_BUFFER_H
#define __IN_OUT_TEMP_BUFFER_H
#include "../../Windows/FileIO.h"
#include "../../Windows/FileDir.h"
#include "../../Common/MyCom.h"
#include "../../Windows/FileDir.h"
#include "../../Windows/FileIO.h"
#include "../IStream.h"
@@ -13,14 +13,12 @@ class CInOutTempBuffer
{
NWindows::NFile::NDirectory::CTempFile _tempFile;
NWindows::NFile::NIO::COutFile _outFile;
NWindows::NFile::NIO::CInFile _inFile;
Byte *_buffer;
UInt32 _bufferPosition;
UInt32 _currentPositionInBuffer;
CSysString _tmpFileName;
bool _tmpFileCreated;
UInt64 _fileSize;
Byte *_buf;
UInt32 _bufPos;
CSysString _tempFileName;
bool _tempFileCreated;
UInt64 _size;
UInt32 _crc;
bool WriteToFile(const void *data, UInt32 size);
public:
@@ -30,23 +28,18 @@ public:
void InitWriting();
bool Write(const void *data, UInt32 size);
UInt64 GetDataSize() const { return _fileSize; }
bool FlushWrite();
bool InitReading();
HRESULT WriteToStream(ISequentialOutStream *stream);
UInt64 GetDataSize() const { return _size; }
};
class CSequentialOutTempBufferImp:
public ISequentialOutStream,
public CMyUnknownImp
{
CInOutTempBuffer *_buffer;
CInOutTempBuffer *_buf;
public:
// CSequentialOutStreamImp(): _size(0) {}
// UInt32 _size;
void Init(CInOutTempBuffer *buffer) { _buffer = buffer; }
// UInt32 GetSize() const { return _size; }
void Init(CInOutTempBuffer *buffer) { _buf = buffer; }
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+21 -5
View File
@@ -3,21 +3,37 @@
#include "StdAfx.h"
#include "StreamObjects.h"
#include "../../Common/Defs.h"
STDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
STDMETHODIMP CBufInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
size_t rem = _size - _pos;
if (processedSize != NULL)
*processedSize = 0;
if (_pos > _size)
return E_FAIL;
size_t rem = _size - (size_t)_pos;
if (size < rem)
rem = (size_t)size;
memcpy(data, _dataPointer + _pos, rem);
memcpy(data, _data + (size_t)_pos, rem);
_pos += rem;
if (processedSize != NULL)
*processedSize = (UInt32)rem;
return S_OK;
}
STDMETHODIMP CBufInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
{
switch(seekOrigin)
{
case STREAM_SEEK_SET: _pos = offset; break;
case STREAM_SEEK_CUR: _pos += offset; break;
case STREAM_SEEK_END: _pos = _size + offset; break;
default: return STG_E_INVALIDFUNCTION;
}
if (newPosition)
*newPosition = _pos;
return S_OK;
}
void CWriteBuffer::Write(const void *data, size_t size)
{
+28 -18
View File
@@ -1,33 +1,43 @@
// StreamObjects.h
#ifndef __STREAMOBJECTS_H
#define __STREAMOBJECTS_H
#ifndef __STREAM_OBJECTS_H
#define __STREAM_OBJECTS_H
#include "../../Common/DynamicBuffer.h"
#include "../../Common/MyCom.h"
#include "../IStream.h"
class CSequentialInStreamImp:
public ISequentialInStream,
struct CReferenceBuf:
public IUnknown,
public CMyUnknownImp
{
const Byte *_dataPointer;
size_t _size;
size_t _pos;
public:
void Init(const Byte *dataPointer, size_t size)
{
_dataPointer = dataPointer;
_size = size;
_pos = 0;
}
CByteBuffer Buf;
MY_UNKNOWN_IMP
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
};
class CBufInStream:
public IInStream,
public CMyUnknownImp
{
const Byte *_data;
UInt64 _pos;
size_t _size;
CMyComPtr<IUnknown> _ref;
public:
void Init(const Byte *data, size_t size, IUnknown *ref = 0)
{
_data = data;
_size = size;
_pos = 0;
_ref = ref;
}
void Init(CReferenceBuf *ref) { Init(ref->Buf, ref->Buf.GetCapacity(), ref); }
MY_UNKNOWN_IMP1(IInStream)
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
};
class CWriteBuffer
{