mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-09 04:07:08 -06:00
add E_ABORT detection
- lz4 and lz5 are not finished...
This commit is contained in:
@@ -9,6 +9,16 @@ int Lz4Read(void *arg, LZ4MT_Buffer * in)
|
||||
size_t size = in->size;
|
||||
|
||||
HRESULT res = ReadStream(x->inStream, in->buf, &size);
|
||||
|
||||
/* catch errors */
|
||||
switch (res) {
|
||||
case E_ABORT:
|
||||
return -2;
|
||||
case E_OUTOFMEMORY:
|
||||
return -3;
|
||||
}
|
||||
|
||||
/* some other error -> read_fail */
|
||||
if (res != S_OK)
|
||||
return -1;
|
||||
|
||||
@@ -28,17 +38,29 @@ int Lz4Write(void *arg, LZ4MT_Buffer * out)
|
||||
{
|
||||
UInt32 block;
|
||||
HRESULT res = x->outStream->Write((char*)out->buf + done, todo, &block);
|
||||
|
||||
/* catch errors */
|
||||
switch (res) {
|
||||
case E_ABORT:
|
||||
return -2;
|
||||
case E_OUTOFMEMORY:
|
||||
return -3;
|
||||
}
|
||||
|
||||
done += block;
|
||||
if (res == k_My_HRESULT_WritingWasCut)
|
||||
break;
|
||||
/* some other error -> write_fail */
|
||||
if (res != S_OK)
|
||||
return -1;
|
||||
|
||||
if (block == 0)
|
||||
return E_FAIL;
|
||||
return -1;
|
||||
todo -= block;
|
||||
}
|
||||
|
||||
*x->processedOut += done;
|
||||
/* we need no lock here, cause only one thread can write... */
|
||||
if (x->progress)
|
||||
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
||||
|
||||
@@ -130,17 +152,18 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
|
||||
rdwr.arg_read = (void *)&Rd;
|
||||
rdwr.arg_write = (void *)&Wr;
|
||||
|
||||
/* 2) create compression context */
|
||||
/* 2) create decompression context */
|
||||
LZ4MT_DCtx *ctx = LZ4MT_createDCtx(_numThreads, _inputSize);
|
||||
if (!ctx)
|
||||
return S_FALSE;
|
||||
|
||||
/* 3) compress */
|
||||
result = LZ4MT_DecompressDCtx(ctx, &rdwr);
|
||||
if (result == (size_t)-LZ4MT_error_read_fail)
|
||||
res = E_ABORT;
|
||||
else if (LZ4MT_isError(result))
|
||||
/* 3) decompress */
|
||||
result = LZ4MT_decompressDCtx(ctx, &rdwr);
|
||||
if (LZ4MT_isError(result)) {
|
||||
if (result == (size_t)-LZ4MT_error_canceled)
|
||||
return E_ABORT;
|
||||
return ErrorOut(result);
|
||||
}
|
||||
|
||||
/* 4) free resources */
|
||||
LZ4MT_freeDCtx(ctx);
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
// (C) 2016 Tino Reichardt
|
||||
|
||||
/**
|
||||
* you can define LZ4_LEGACY_SUPPORT to be backwards compatible (0.1 .. 0.7)
|
||||
* /TR 2016-10-01
|
||||
*/
|
||||
|
||||
#define LZ4_STATIC_LINKING_ONLY
|
||||
#include "../../../C/Alloc.h"
|
||||
#include "../../../C/Threads.h"
|
||||
|
||||
@@ -24,6 +24,18 @@ CEncoder::~CEncoder()
|
||||
LZ4MT_freeCCtx(_ctx);
|
||||
}
|
||||
|
||||
HRESULT CEncoder::ErrorOut(size_t code)
|
||||
{
|
||||
const char *strError = LZ4MT_getErrorString(code);
|
||||
wchar_t wstrError[200+5]; /* no malloc here, /TR */
|
||||
|
||||
mbstowcs(wstrError, strError, 200);
|
||||
MessageBoxW(0, wstrError, L"7-Zip ZStandard", MB_ICONERROR | MB_OK);
|
||||
MyFree(wstrError);
|
||||
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARIANT * coderProps, UInt32 numProps)
|
||||
{
|
||||
_props.clear();
|
||||
@@ -40,10 +52,11 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARI
|
||||
if (prop.vt != VT_UI4)
|
||||
return E_INVALIDARG;
|
||||
|
||||
/* level 1..22 */
|
||||
_props._level = static_cast < Byte > (prop.ulVal);
|
||||
Byte lz4_level = static_cast < Byte > (LZ4MT_LEVEL_MAX);
|
||||
if (_props._level > lz4_level)
|
||||
_props._level = lz4_level;
|
||||
Byte mylevel = static_cast < Byte > (LZ4MT_LEVEL_MAX);
|
||||
if (_props._level > mylevel)
|
||||
_props._level = mylevel;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -104,12 +117,12 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
||||
return S_FALSE;
|
||||
|
||||
/* 3) compress */
|
||||
result = LZ4MT_CompressCCtx(_ctx, &rdwr);
|
||||
if (result == (size_t)-LZ4MT_error_read_fail)
|
||||
res = E_ABORT;
|
||||
else if (LZ4MT_isError(result))
|
||||
if (result != LZ4MT_error_read_fail)
|
||||
return ErrorOut(result);
|
||||
result = LZ4MT_compressCCtx(_ctx, &rdwr);
|
||||
if (LZ4MT_isError(result)) {
|
||||
if (result == (size_t)-LZ4MT_error_canceled)
|
||||
return E_ABORT;
|
||||
return ErrorOut(result);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -123,17 +136,5 @@ STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CEncoder::ErrorOut(size_t code)
|
||||
{
|
||||
const char *strError = LZ4MT_getErrorString(code);
|
||||
wchar_t wstrError[200+5]; /* no malloc here, /TR */
|
||||
|
||||
mbstowcs(wstrError, strError, 200);
|
||||
MessageBoxW(0, wstrError, L"7-Zip ZStandard", MB_ICONERROR | MB_OK);
|
||||
MyFree(wstrError);
|
||||
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
}}
|
||||
#endif
|
||||
|
||||
@@ -9,6 +9,16 @@ int Lz5Read(void *arg, LZ5MT_Buffer * in)
|
||||
size_t size = in->size;
|
||||
|
||||
HRESULT res = ReadStream(x->inStream, in->buf, &size);
|
||||
|
||||
/* catch errors */
|
||||
switch (res) {
|
||||
case E_ABORT:
|
||||
return -2;
|
||||
case E_OUTOFMEMORY:
|
||||
return -3;
|
||||
}
|
||||
|
||||
/* some other error -> read_fail */
|
||||
if (res != S_OK)
|
||||
return -1;
|
||||
|
||||
@@ -28,17 +38,29 @@ int Lz5Write(void *arg, LZ5MT_Buffer * out)
|
||||
{
|
||||
UInt32 block;
|
||||
HRESULT res = x->outStream->Write((char*)out->buf + done, todo, &block);
|
||||
|
||||
/* catch errors */
|
||||
switch (res) {
|
||||
case E_ABORT:
|
||||
return -2;
|
||||
case E_OUTOFMEMORY:
|
||||
return -3;
|
||||
}
|
||||
|
||||
done += block;
|
||||
if (res == k_My_HRESULT_WritingWasCut)
|
||||
break;
|
||||
/* some other error -> write_fail */
|
||||
if (res != S_OK)
|
||||
return -1;
|
||||
|
||||
if (block == 0)
|
||||
return E_FAIL;
|
||||
return -1;
|
||||
todo -= block;
|
||||
}
|
||||
|
||||
*x->processedOut += done;
|
||||
/* we need no lock here, cause only one thread can write... */
|
||||
if (x->progress)
|
||||
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
||||
|
||||
@@ -130,18 +152,18 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
|
||||
rdwr.arg_read = (void *)&Rd;
|
||||
rdwr.arg_write = (void *)&Wr;
|
||||
|
||||
/* 2) create compression context */
|
||||
/* 2) create decompression context */
|
||||
LZ5MT_DCtx *ctx = LZ5MT_createDCtx(_numThreads, _inputSize);
|
||||
if (!ctx)
|
||||
return S_FALSE;
|
||||
|
||||
/* 3) compress */
|
||||
result = LZ5MT_DecompressDCtx(ctx, &rdwr);
|
||||
if (result == (size_t)-LZ5MT_error_read_fail)
|
||||
res = E_ABORT;
|
||||
else if (LZ5MT_isError(result))
|
||||
if (result != LZ5MT_error_read_fail)
|
||||
return ErrorOut(result);
|
||||
/* 3) decompress */
|
||||
result = LZ5MT_decompressDCtx(ctx, &rdwr);
|
||||
if (LZ5MT_isError(result)) {
|
||||
if (result == (size_t)-LZ5MT_error_canceled)
|
||||
return E_ABORT;
|
||||
return ErrorOut(result);
|
||||
}
|
||||
|
||||
/* 4) free resources */
|
||||
LZ5MT_freeDCtx(ctx);
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
// (C) 2016 Tino Reichardt
|
||||
|
||||
/**
|
||||
* you can define LZ5_LEGACY_SUPPORT to be backwards compatible (0.1 .. 0.7)
|
||||
* /TR 2016-10-01
|
||||
*/
|
||||
|
||||
#define LZ5_STATIC_LINKING_ONLY
|
||||
#include "../../../C/Alloc.h"
|
||||
#include "../../../C/Threads.h"
|
||||
|
||||
@@ -24,6 +24,18 @@ CEncoder::~CEncoder()
|
||||
LZ5MT_freeCCtx(_ctx);
|
||||
}
|
||||
|
||||
HRESULT CEncoder::ErrorOut(size_t code)
|
||||
{
|
||||
const char *strError = LZ5MT_getErrorString(code);
|
||||
wchar_t wstrError[200+5]; /* no malloc here, /TR */
|
||||
|
||||
mbstowcs(wstrError, strError, 200);
|
||||
MessageBoxW(0, wstrError, L"7-Zip ZStandard", MB_ICONERROR | MB_OK);
|
||||
MyFree(wstrError);
|
||||
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARIANT * coderProps, UInt32 numProps)
|
||||
{
|
||||
_props.clear();
|
||||
@@ -40,10 +52,11 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARI
|
||||
if (prop.vt != VT_UI4)
|
||||
return E_INVALIDARG;
|
||||
|
||||
/* level 1..22 */
|
||||
_props._level = static_cast < Byte > (prop.ulVal);
|
||||
Byte lz5_level = static_cast < Byte > (LZ5MT_LEVEL_MAX);
|
||||
if (_props._level > lz5_level)
|
||||
_props._level = lz5_level;
|
||||
Byte mylevel = static_cast < Byte > (LZ5MT_LEVEL_MAX);
|
||||
if (_props._level > mylevel)
|
||||
_props._level = mylevel;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -104,11 +117,12 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
||||
return S_FALSE;
|
||||
|
||||
/* 3) compress */
|
||||
result = LZ5MT_CompressCCtx(_ctx, &rdwr);
|
||||
if (result == (size_t)-LZ5MT_error_read_fail)
|
||||
res = E_ABORT;
|
||||
if (LZ5MT_isError(result))
|
||||
result = LZ5MT_compressCCtx(_ctx, &rdwr);
|
||||
if (LZ5MT_isError(result)) {
|
||||
if (result == (size_t)-LZ5MT_error_canceled)
|
||||
return E_ABORT;
|
||||
return ErrorOut(result);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -122,17 +136,5 @@ STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CEncoder::ErrorOut(size_t code)
|
||||
{
|
||||
const char *strError = LZ5MT_getErrorString(code);
|
||||
wchar_t wstrError[200+5]; /* no malloc here, /TR */
|
||||
|
||||
mbstowcs(wstrError, strError, 200);
|
||||
MessageBoxW(0, wstrError, L"7-Zip ZStandard", MB_ICONERROR | MB_OK);
|
||||
MyFree(wstrError);
|
||||
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
}}
|
||||
#endif
|
||||
|
||||
@@ -9,6 +9,16 @@ int ZstdRead(void *arg, ZSTDMT_Buffer * in)
|
||||
size_t size = in->size;
|
||||
|
||||
HRESULT res = ReadStream(x->inStream, in->buf, &size);
|
||||
|
||||
/* catch errors */
|
||||
switch (res) {
|
||||
case E_ABORT:
|
||||
return -2;
|
||||
case E_OUTOFMEMORY:
|
||||
return -3;
|
||||
}
|
||||
|
||||
/* some other error -> read_fail */
|
||||
if (res != S_OK)
|
||||
return -1;
|
||||
|
||||
@@ -28,17 +38,29 @@ int ZstdWrite(void *arg, ZSTDMT_Buffer * out)
|
||||
{
|
||||
UInt32 block;
|
||||
HRESULT res = x->outStream->Write((char*)out->buf + done, todo, &block);
|
||||
|
||||
/* catch errors */
|
||||
switch (res) {
|
||||
case E_ABORT:
|
||||
return -2;
|
||||
case E_OUTOFMEMORY:
|
||||
return -3;
|
||||
}
|
||||
|
||||
done += block;
|
||||
if (res == k_My_HRESULT_WritingWasCut)
|
||||
break;
|
||||
/* some other error -> write_fail */
|
||||
if (res != S_OK)
|
||||
return -1;
|
||||
|
||||
if (block == 0)
|
||||
return E_FAIL;
|
||||
return -1;
|
||||
todo -= block;
|
||||
}
|
||||
|
||||
*x->processedOut += done;
|
||||
/* we need no lock here, cause only one thread can write... */
|
||||
if (x->progress)
|
||||
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
||||
|
||||
@@ -137,11 +159,11 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
|
||||
|
||||
/* 3) decompress */
|
||||
result = ZSTDMT_decompressDCtx(ctx, &rdwr);
|
||||
//printf("decompress = %d / %d\n", result, ZSTDMT_error_read_fail);
|
||||
if (result == (size_t)-ZSTDMT_error_read_fail)
|
||||
res = E_ABORT;
|
||||
else if (ZSTDMT_isError(result))
|
||||
if (ZSTDMT_isError(result)) {
|
||||
if (result == (size_t)-ZSTDMT_error_canceled)
|
||||
return E_ABORT;
|
||||
return ErrorOut(result);
|
||||
}
|
||||
|
||||
/* 4) free resources */
|
||||
ZSTDMT_freeDCtx(ctx);
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
// (C) 2016 Tino Reichardt
|
||||
|
||||
/**
|
||||
* you can define ZSTD_LEGACY_SUPPORT to be backwards compatible (0.1 .. 0.7)
|
||||
* /TR 2016-10-01
|
||||
*/
|
||||
|
||||
#define ZSTD_STATIC_LINKING_ONLY
|
||||
#include "../../../C/Alloc.h"
|
||||
#include "../../../C/Threads.h"
|
||||
|
||||
@@ -24,6 +24,18 @@ CEncoder::~CEncoder()
|
||||
ZSTDMT_freeCCtx(_ctx);
|
||||
}
|
||||
|
||||
HRESULT CEncoder::ErrorOut(size_t code)
|
||||
{
|
||||
const char *strError = ZSTDMT_getErrorString(code);
|
||||
wchar_t wstrError[200+5]; /* no malloc here, /TR */
|
||||
|
||||
mbstowcs(wstrError, strError, 200);
|
||||
MessageBoxW(0, wstrError, L"7-Zip ZStandard", MB_ICONERROR | MB_OK);
|
||||
MyFree(wstrError);
|
||||
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARIANT * coderProps, UInt32 numProps)
|
||||
{
|
||||
_props.clear();
|
||||
@@ -42,9 +54,9 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARI
|
||||
|
||||
/* level 1..22 */
|
||||
_props._level = static_cast < Byte > (prop.ulVal);
|
||||
Byte zstd_level = static_cast < Byte > (ZSTD_maxCLevel());
|
||||
if (_props._level > zstd_level)
|
||||
_props._level = zstd_level;
|
||||
Byte mylevel = static_cast < Byte > (ZSTDMT_LEVEL_MAX);
|
||||
if (_props._level > mylevel)
|
||||
_props._level = mylevel;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -106,10 +118,11 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
||||
|
||||
/* 3) compress */
|
||||
result = ZSTDMT_compressCCtx(_ctx, &rdwr);
|
||||
if (result == (size_t)-ZSTDMT_error_read_fail)
|
||||
res = E_ABORT;
|
||||
else if (ZSTDMT_isError(result))
|
||||
if (ZSTDMT_isError(result)) {
|
||||
if (result == (size_t)-ZSTDMT_error_canceled)
|
||||
return E_ABORT;
|
||||
return ErrorOut(result);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -123,17 +136,5 @@ STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CEncoder::ErrorOut(size_t code)
|
||||
{
|
||||
const char *strError = ZSTDMT_getErrorString(code);
|
||||
wchar_t wstrError[200+5]; /* no malloc here, /TR */
|
||||
|
||||
mbstowcs(wstrError, strError, 200);
|
||||
MessageBoxW(0, wstrError, L"7-Zip ZStandard", MB_ICONERROR | MB_OK);
|
||||
MyFree(wstrError);
|
||||
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
}}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user