mirror of
https://github.com/Xevion/easy7zip.git
synced 2026-02-01 00:24:14 -06:00
Update to 7-Zip Version 21.02
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../C/7zCrc.h"
|
||||
|
||||
#include "../../Common/Defs.h"
|
||||
|
||||
#include "InOutTempBuffer.h"
|
||||
#include "StreamUtils.h"
|
||||
|
||||
#ifdef USE_InOutTempBuffer_FILE
|
||||
|
||||
#include "../../../C/7zCrc.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NFile;
|
||||
using namespace NDir;
|
||||
@@ -16,50 +16,58 @@ using namespace NDir;
|
||||
static const size_t kTempBufSize = (1 << 20);
|
||||
|
||||
#define kTempFilePrefixString FTEXT("7zt")
|
||||
|
||||
CInOutTempBuffer::CInOutTempBuffer(): _buf(NULL) { }
|
||||
|
||||
void CInOutTempBuffer::Create()
|
||||
{
|
||||
if (!_buf)
|
||||
_buf = new Byte[kTempBufSize];
|
||||
}
|
||||
|
||||
CInOutTempBuffer::~CInOutTempBuffer()
|
||||
{
|
||||
delete []_buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
CInOutTempBuffer::CInOutTempBuffer()
|
||||
#ifdef USE_InOutTempBuffer_FILE
|
||||
: _buf(NULL)
|
||||
#endif
|
||||
{ }
|
||||
|
||||
void CInOutTempBuffer::Create()
|
||||
{
|
||||
#ifdef USE_InOutTempBuffer_FILE
|
||||
if (!_buf)
|
||||
_buf = new Byte[kTempBufSize];
|
||||
#endif
|
||||
}
|
||||
|
||||
void CInOutTempBuffer::InitWriting()
|
||||
{
|
||||
#ifdef USE_InOutTempBuffer_FILE
|
||||
_bufPos = 0;
|
||||
_tempFileCreated = false;
|
||||
_size = 0;
|
||||
_crc = CRC_INIT_VAL;
|
||||
_tempFileCreated = false;
|
||||
#endif
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
bool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)
|
||||
|
||||
#ifdef USE_InOutTempBuffer_FILE
|
||||
|
||||
static inline HRESULT Get_HRESULT_LastError()
|
||||
{
|
||||
if (size == 0)
|
||||
return true;
|
||||
if (!_tempFileCreated)
|
||||
{
|
||||
if (!_tempFile.CreateRandomInTempFolder(kTempFilePrefixString, &_outFile))
|
||||
return false;
|
||||
_tempFileCreated = true;
|
||||
}
|
||||
UInt32 processed;
|
||||
if (!_outFile.Write(data, size, processed))
|
||||
return false;
|
||||
_crc = CrcUpdate(_crc, data, processed);
|
||||
_size += processed;
|
||||
return (processed == size);
|
||||
#ifdef _WIN32
|
||||
DWORD lastError = ::GetLastError();
|
||||
if (lastError != 0)
|
||||
return HRESULT_FROM_WIN32(lastError);
|
||||
#endif
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
bool CInOutTempBuffer::Write(const void *data, UInt32 size)
|
||||
#endif
|
||||
|
||||
|
||||
HRESULT CInOutTempBuffer::Write_HRESULT(const void *data, UInt32 size)
|
||||
{
|
||||
#ifdef USE_InOutTempBuffer_FILE
|
||||
|
||||
if (size == 0)
|
||||
return true;
|
||||
return S_OK;
|
||||
size_t cur = kTempBufSize - _bufPos;
|
||||
if (cur != 0)
|
||||
{
|
||||
@@ -72,11 +80,42 @@ bool CInOutTempBuffer::Write(const void *data, UInt32 size)
|
||||
size -= (UInt32)cur;
|
||||
data = ((const Byte *)data) + cur;
|
||||
}
|
||||
return WriteToFile(data, size);
|
||||
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
|
||||
if (!_tempFileCreated)
|
||||
{
|
||||
if (!_tempFile.CreateRandomInTempFolder(kTempFilePrefixString, &_outFile))
|
||||
return Get_HRESULT_LastError();
|
||||
_tempFileCreated = true;
|
||||
}
|
||||
UInt32 processed;
|
||||
if (!_outFile.Write(data, size, processed))
|
||||
return Get_HRESULT_LastError();
|
||||
_crc = CrcUpdate(_crc, data, processed);
|
||||
_size += processed;
|
||||
return (processed == size) ? S_OK : E_FAIL;
|
||||
|
||||
#else
|
||||
|
||||
const size_t newSize = _size + size;
|
||||
if (newSize < _size)
|
||||
return E_OUTOFMEMORY;
|
||||
if (!_dynBuffer.EnsureCapacity(newSize))
|
||||
return E_OUTOFMEMORY;
|
||||
memcpy(((Byte *)_dynBuffer) + _size, data, size);
|
||||
_size = newSize;
|
||||
return S_OK;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
|
||||
{
|
||||
#ifdef USE_InOutTempBuffer_FILE
|
||||
|
||||
if (!_outFile.Close())
|
||||
return E_FAIL;
|
||||
|
||||
@@ -107,8 +146,13 @@ HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
|
||||
size += processed;
|
||||
}
|
||||
}
|
||||
|
||||
return (_crc == crc && size == _size) ? S_OK : E_FAIL;
|
||||
|
||||
#else
|
||||
|
||||
return WriteStream(stream, (const Byte *)_dynBuffer, _size);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user