mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-09 14:07:08 -06:00
4.53 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
33ccab7e72
commit
051769bbc5
@@ -12,9 +12,13 @@
|
||||
|
||||
static inline HRESULT ConvertBoolToHRESULT(bool result)
|
||||
{
|
||||
// return result ? S_OK: E_FAIL;
|
||||
#ifdef _WIN32
|
||||
return result ? S_OK: (::GetLastError());
|
||||
if (result)
|
||||
return S_OK;
|
||||
DWORD lastError = ::GetLastError();
|
||||
if (lastError == 0)
|
||||
return E_FAIL;
|
||||
return lastError;
|
||||
#else
|
||||
return result ? S_OK: E_FAIL;
|
||||
#endif
|
||||
@@ -141,26 +145,13 @@ STDMETHODIMP CInFileStream::GetSize(UInt64 *size)
|
||||
//////////////////////////
|
||||
// COutFileStream
|
||||
|
||||
bool COutFileStream::Create(LPCTSTR fileName, bool createAlways)
|
||||
{
|
||||
return File.Create(fileName, createAlways);
|
||||
}
|
||||
|
||||
#ifdef USE_WIN_FILE
|
||||
#ifndef _UNICODE
|
||||
bool COutFileStream::Create(LPCWSTR fileName, bool createAlways)
|
||||
{
|
||||
return File.Create(fileName, createAlways);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
STDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
#ifdef USE_WIN_FILE
|
||||
|
||||
UInt32 realProcessedSize;
|
||||
bool result = File.WritePart(data, size, realProcessedSize);
|
||||
ProcessedSize += realProcessedSize;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
return ConvertBoolToHRESULT(result);
|
||||
@@ -174,13 +165,13 @@ STDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *proces
|
||||
return E_FAIL;
|
||||
if(processedSize != NULL)
|
||||
*processedSize = (UInt32)res;
|
||||
ProcessedSize += res;
|
||||
return S_OK;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -72,20 +72,52 @@ class COutFileStream:
|
||||
public IOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
#ifdef USE_WIN_FILE
|
||||
NWindows::NFile::NIO::COutFile File;
|
||||
#else
|
||||
NC::NFile::NIO::COutFile File;
|
||||
#endif
|
||||
public:
|
||||
virtual ~COutFileStream() {}
|
||||
bool Create(LPCTSTR fileName, bool createAlways);
|
||||
bool Create(LPCTSTR fileName, bool createAlways)
|
||||
{
|
||||
ProcessedSize = 0;
|
||||
return File.Create(fileName, createAlways);
|
||||
}
|
||||
bool Open(LPCTSTR fileName, DWORD creationDisposition)
|
||||
{
|
||||
ProcessedSize = 0;
|
||||
return File.Open(fileName, creationDisposition);
|
||||
}
|
||||
#ifdef USE_WIN_FILE
|
||||
#ifndef _UNICODE
|
||||
bool Create(LPCWSTR fileName, bool createAlways);
|
||||
bool Create(LPCWSTR fileName, bool createAlways)
|
||||
{
|
||||
ProcessedSize = 0;
|
||||
return File.Create(fileName, createAlways);
|
||||
}
|
||||
bool Open(LPCWSTR fileName, DWORD creationDisposition)
|
||||
{
|
||||
ProcessedSize = 0;
|
||||
return File.Open(fileName, creationDisposition);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
UInt64 ProcessedSize;
|
||||
|
||||
#ifdef USE_WIN_FILE
|
||||
bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)
|
||||
{
|
||||
return File.SetTime(creationTime, lastAccessTime, lastWriteTime);
|
||||
}
|
||||
bool SetLastWriteTime(const FILETIME *lastWriteTime)
|
||||
{
|
||||
return File.SetLastWriteTime(lastWriteTime);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
MY_UNKNOWN_IMP1(IOutStream)
|
||||
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
|
||||
@@ -109,7 +109,7 @@ HRESULT COutBuffer::Flush()
|
||||
|
||||
void COutBuffer::FlushWithCheck()
|
||||
{
|
||||
HRESULT result = FlushPart();
|
||||
HRESULT result = Flush();
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
ErrorCode = result;
|
||||
#else
|
||||
|
||||
@@ -4,52 +4,37 @@
|
||||
|
||||
#include "ProgressUtils.h"
|
||||
|
||||
void CLocalCompressProgressInfo::Init(ICompressProgressInfo *progress,
|
||||
const UInt64 *inStartValue, const UInt64 *outStartValue)
|
||||
CLocalProgress::CLocalProgress()
|
||||
{
|
||||
_progress = progress;
|
||||
_inStartValueIsAssigned = (inStartValue != NULL);
|
||||
if (_inStartValueIsAssigned)
|
||||
_inStartValue = *inStartValue;
|
||||
_outStartValueIsAssigned = (outStartValue != NULL);
|
||||
if (_outStartValueIsAssigned)
|
||||
_outStartValue = *outStartValue;
|
||||
ProgressOffset = InSize = OutSize = 0;
|
||||
SendRatio = true;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLocalCompressProgressInfo::SetRatioInfo(
|
||||
const UInt64 *inSize, const UInt64 *outSize)
|
||||
{
|
||||
UInt64 inSizeNew, outSizeNew;
|
||||
const UInt64 *inSizeNewPointer;
|
||||
const UInt64 *outSizeNewPointer;
|
||||
if (_inStartValueIsAssigned && inSize != NULL)
|
||||
{
|
||||
inSizeNew = _inStartValue + (*inSize);
|
||||
inSizeNewPointer = &inSizeNew;
|
||||
}
|
||||
else
|
||||
inSizeNewPointer = NULL;
|
||||
|
||||
if (_outStartValueIsAssigned && outSize != NULL)
|
||||
{
|
||||
outSizeNew = _outStartValue + (*outSize);
|
||||
outSizeNewPointer = &outSizeNew;
|
||||
}
|
||||
else
|
||||
outSizeNewPointer = NULL;
|
||||
return _progress->SetRatioInfo(inSizeNewPointer, outSizeNewPointer);
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
|
||||
void CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)
|
||||
{
|
||||
_ratioProgress.Release();
|
||||
_progress = progress;
|
||||
_progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);
|
||||
_inSizeIsMain = inSizeIsMain;
|
||||
}
|
||||
|
||||
STDMETHODIMP CLocalProgress::SetRatioInfo(
|
||||
const UInt64 *inSize, const UInt64 *outSize)
|
||||
STDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
|
||||
{
|
||||
return _progress->SetCompleted(_inSizeIsMain ? inSize : outSize);
|
||||
UInt64 inSizeNew = InSize, outSizeNew = OutSize;
|
||||
if (inSize)
|
||||
inSizeNew += (*inSize);
|
||||
if (outSize)
|
||||
outSizeNew += (*outSize);
|
||||
if (SendRatio && _ratioProgress)
|
||||
{
|
||||
RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));
|
||||
}
|
||||
inSizeNew += ProgressOffset;
|
||||
outSizeNew += ProgressOffset;
|
||||
return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);
|
||||
}
|
||||
|
||||
HRESULT CLocalProgress::SetCur()
|
||||
{
|
||||
return SetRatioInfo(NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -8,32 +8,22 @@
|
||||
#include "../ICoder.h"
|
||||
#include "../IProgress.h"
|
||||
|
||||
class CLocalCompressProgressInfo:
|
||||
public ICompressProgressInfo,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ICompressProgressInfo> _progress;
|
||||
bool _inStartValueIsAssigned;
|
||||
bool _outStartValueIsAssigned;
|
||||
UInt64 _inStartValue;
|
||||
UInt64 _outStartValue;
|
||||
public:
|
||||
void Init(ICompressProgressInfo *progress,
|
||||
const UInt64 *inStartValue, const UInt64 *outStartValue);
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
|
||||
};
|
||||
|
||||
class CLocalProgress:
|
||||
public ICompressProgressInfo,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<IProgress> _progress;
|
||||
CMyComPtr<ICompressProgressInfo> _ratioProgress;
|
||||
bool _inSizeIsMain;
|
||||
public:
|
||||
UInt64 ProgressOffset;
|
||||
UInt64 InSize;
|
||||
UInt64 OutSize;
|
||||
bool SendRatio;
|
||||
|
||||
CLocalProgress();
|
||||
void Init(IProgress *progress, bool inSizeIsMain);
|
||||
HRESULT SetCur();
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size,
|
||||
size -= processedSizeLoc;
|
||||
RINOK(res);
|
||||
if (processedSizeLoc == 0)
|
||||
break;
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user