This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -2,51 +2,52 @@
#include "StdAfx.h"
#include "../../../Common/Alloc.h"
#include "LZOutWindow.h"
void CLZOutWindow::Create(UINT32 windowSize)
bool CLZOutWindow::Create(UInt32 windowSize)
{
const UInt32 kMinBlockSize = 1;
if (windowSize < kMinBlockSize)
windowSize = kMinBlockSize;
if (_buffer != 0 && _windowSize == windowSize)
return true;
// It's here to allow Solid decoding / and calling Create for RAR
_pos = 0;
_streamPos = 0;
UINT32 newBlockSize = windowSize;
const UINT32 kMinBlockSize = 1;
if (newBlockSize < kMinBlockSize)
newBlockSize = kMinBlockSize;
if (_buffer != 0 && _windowSize == newBlockSize)
return;
delete []_buffer;
_buffer = 0;
_windowSize = newBlockSize;
_buffer = new BYTE[_windowSize];
}
CLZOutWindow::~CLZOutWindow()
{
// ReleaseStream();
delete []_buffer;
}
/*
void CLZOutWindow::SetWindowSize(UINT32 windowSize)
{
Free();
_windowSize = windowSize;
_buffer = (Byte *)::BigAlloc(windowSize);
return (_buffer != 0);
}
*/
void CLZOutWindow::Init(ISequentialOutStream *stream, bool solid)
void CLZOutWindow::Free()
{
// ReleaseStream();
_stream = stream;
// _stream->AddRef();
::BigFree(_buffer);
_buffer = 0;
}
void CLZOutWindow::SetStream(ISequentialOutStream *stream)
{
ReleaseStream();
_stream = stream;
_stream->AddRef();
}
void CLZOutWindow::Init(bool solid)
{
if(!solid)
{
_streamPos = 0;
_pos = 0;
}
#ifdef _NO_EXCEPTIONS
ErrorCode = S_OK;
#endif
}
/*
void CLZOutWindow::ReleaseStream()
{
if(_stream != 0)
@@ -56,26 +57,37 @@ void CLZOutWindow::ReleaseStream()
_stream = 0;
}
}
*/
void CLZOutWindow::FlushWithCheck()
{
HRESULT result = Flush();
#ifdef _NO_EXCEPTIONS
ErrorCode = result;
#else
if (result != S_OK)
throw CLZOutWindowException(result);
#endif
}
HRESULT CLZOutWindow::Flush()
{
UINT32 size = _pos - _streamPos;
UInt32 size = _pos - _streamPos;
if(size == 0)
return S_OK;
UINT32 processedSize;
HRESULT result = _stream->Write(_buffer + _streamPos, size, &processedSize);
if (result != S_OK)
return result;
if (size != processedSize)
return E_FAIL;
#ifdef _NO_EXCEPTIONS
if (ErrorCode != S_OK)
return ErrorCode;
#endif
if(_stream != 0)
{
UInt32 processedSize;
HRESULT result = _stream->Write(_buffer + _streamPos, size, &processedSize);
if (result != S_OK)
return result;
if (size != processedSize)
return E_FAIL;
}
if (_pos >= _windowSize)
_pos = 0;
_streamPos = _pos;