mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-12 22:11:35 -06:00
add E_ABORT detection
- lz4 and lz5 are not finished...
This commit is contained in:
@@ -48,6 +48,7 @@ typedef enum {
|
|||||||
ZSTDMT_error_frame_decompress,
|
ZSTDMT_error_frame_decompress,
|
||||||
ZSTDMT_error_compressionParameter_unsupported,
|
ZSTDMT_error_compressionParameter_unsupported,
|
||||||
ZSTDMT_error_compression_library,
|
ZSTDMT_error_compression_library,
|
||||||
|
ZSTDMT_error_canceled,
|
||||||
ZSTDMT_error_maxCode
|
ZSTDMT_error_maxCode
|
||||||
} ZSTDMT_ErrorCode;
|
} ZSTDMT_ErrorCode;
|
||||||
|
|
||||||
@@ -73,6 +74,12 @@ typedef struct {
|
|||||||
* - you can use stdio functions or plain read/write
|
* - you can use stdio functions or plain read/write
|
||||||
* - just write some wrapper on your own
|
* - just write some wrapper on your own
|
||||||
* - a sample is given in 7-Zip ZS
|
* - a sample is given in 7-Zip ZS
|
||||||
|
*
|
||||||
|
* error definitions:
|
||||||
|
* 0 = success
|
||||||
|
* -1 = generic read/write error
|
||||||
|
* -2 = user abort
|
||||||
|
* -3 = memory
|
||||||
*/
|
*/
|
||||||
typedef int (fn_read) (void *args, ZSTDMT_Buffer * in);
|
typedef int (fn_read) (void *args, ZSTDMT_Buffer * in);
|
||||||
typedef int (fn_write) (void *args, ZSTDMT_Buffer * out);
|
typedef int (fn_write) (void *args, ZSTDMT_Buffer * out);
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define ZSTD_STATIC_LINKING_ONLY
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
//#define DEBUGME
|
|
||||||
#include "zstd.h"
|
#include "zstd.h"
|
||||||
|
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
@@ -115,7 +114,7 @@ ZSTDMT_CCtx *ZSTDMT_createCCtx(int threads, int level, int inputsize)
|
|||||||
if (inputsize)
|
if (inputsize)
|
||||||
ctx->inputsize = inputsize;
|
ctx->inputsize = inputsize;
|
||||||
else {
|
else {
|
||||||
#ifndef DEBUGME
|
#if 1
|
||||||
const int windowLog[] = {
|
const int windowLog[] = {
|
||||||
0, 19, 19, 20, 20, 20, 21, 21,
|
0, 19, 19, 20, 20, 20, 21, 21,
|
||||||
21, 21, 21, 22, 22, 22, 22, 22,
|
21, 21, 21, 22, 22, 22, 22, 22,
|
||||||
@@ -123,7 +122,8 @@ ZSTDMT_CCtx *ZSTDMT_createCCtx(int threads, int level, int inputsize)
|
|||||||
};
|
};
|
||||||
ctx->inputsize = 1 << (windowLog[level] + 1);
|
ctx->inputsize = 1 << (windowLog[level] + 1);
|
||||||
#else
|
#else
|
||||||
const int mb[] = { 0, 1, 1, 1, 2, 2, 2,
|
const int mb[] = {
|
||||||
|
0, 1, 1, 1, 2, 2, 2,
|
||||||
3, 3, 3, 4, 4, 4, 5,
|
3, 3, 3, 4, 4, 4, 5,
|
||||||
5, 5, 5, 5, 5, 5, 5
|
5, 5, 5, 5, 5, 5, 5
|
||||||
};
|
};
|
||||||
@@ -180,6 +180,8 @@ static size_t pt_write(ZSTDMT_CCtx * ctx, struct writelist *wl)
|
|||||||
rv = ctx->fn_write(ctx->arg_write, &b);
|
rv = ctx->fn_write(ctx->arg_write, &b);
|
||||||
if (rv == -1)
|
if (rv == -1)
|
||||||
return ZSTDMT_ERROR(write_fail);
|
return ZSTDMT_ERROR(write_fail);
|
||||||
|
if (rv == -2)
|
||||||
|
return ZSTDMT_ERROR(canceled);
|
||||||
if (b.size != 9)
|
if (b.size != 9)
|
||||||
return ZSTDMT_ERROR(write_fail);
|
return ZSTDMT_ERROR(write_fail);
|
||||||
ctx->outsize += 9;
|
ctx->outsize += 9;
|
||||||
@@ -197,6 +199,8 @@ static size_t pt_write(ZSTDMT_CCtx * ctx, struct writelist *wl)
|
|||||||
rv = ctx->fn_write(ctx->arg_write, &wl->out);
|
rv = ctx->fn_write(ctx->arg_write, &wl->out);
|
||||||
if (rv == -1)
|
if (rv == -1)
|
||||||
return ZSTDMT_ERROR(write_fail);
|
return ZSTDMT_ERROR(write_fail);
|
||||||
|
if (rv == -2)
|
||||||
|
return ZSTDMT_ERROR(canceled);
|
||||||
ctx->outsize += wl->out.size;
|
ctx->outsize += wl->out.size;
|
||||||
ctx->curframe++;
|
ctx->curframe++;
|
||||||
list_move(entry, &ctx->writelist_free);
|
list_move(entry, &ctx->writelist_free);
|
||||||
@@ -264,6 +268,10 @@ static void *pt_compress(void *arg)
|
|||||||
pthread_mutex_unlock(&ctx->read_mutex);
|
pthread_mutex_unlock(&ctx->read_mutex);
|
||||||
result = ZSTDMT_ERROR(read_fail);
|
result = ZSTDMT_ERROR(read_fail);
|
||||||
goto error;
|
goto error;
|
||||||
|
} else if (rv == -2) {
|
||||||
|
pthread_mutex_unlock(&ctx->read_mutex);
|
||||||
|
result = ZSTDMT_ERROR(canceled);
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eof */
|
/* eof */
|
||||||
@@ -305,6 +313,7 @@ static void *pt_compress(void *arg)
|
|||||||
/* write result */
|
/* write result */
|
||||||
pthread_mutex_lock(&ctx->write_mutex);
|
pthread_mutex_lock(&ctx->write_mutex);
|
||||||
result = pt_write(ctx, wl);
|
result = pt_write(ctx, wl);
|
||||||
|
printf("pt_write() = %d\n", result);
|
||||||
pthread_mutex_unlock(&ctx->write_mutex);
|
pthread_mutex_unlock(&ctx->write_mutex);
|
||||||
if (ZSTDMT_isError(result))
|
if (ZSTDMT_isError(result))
|
||||||
goto error;
|
goto error;
|
||||||
|
|||||||
@@ -175,6 +175,8 @@ static size_t pt_write(ZSTDMT_DCtx * ctx, struct writelist *wl)
|
|||||||
int rv = ctx->fn_write(ctx->arg_write, &wl->out);
|
int rv = ctx->fn_write(ctx->arg_write, &wl->out);
|
||||||
if (rv == -1)
|
if (rv == -1)
|
||||||
return ZSTDMT_ERROR(write_fail);
|
return ZSTDMT_ERROR(write_fail);
|
||||||
|
if (rv == -2)
|
||||||
|
return ZSTDMT_ERROR(canceled);
|
||||||
ctx->outsize += wl->out.size;
|
ctx->outsize += wl->out.size;
|
||||||
ctx->curframe++;
|
ctx->curframe++;
|
||||||
list_move(entry, &ctx->writelist_free);
|
list_move(entry, &ctx->writelist_free);
|
||||||
@@ -217,6 +219,8 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame)
|
|||||||
rv = ctx->fn_read(ctx->arg_read, &hdr);
|
rv = ctx->fn_read(ctx->arg_read, &hdr);
|
||||||
if (rv == -1)
|
if (rv == -1)
|
||||||
goto error_read;
|
goto error_read;
|
||||||
|
if (rv == -2)
|
||||||
|
goto error_read;
|
||||||
if (hdr.size != 5)
|
if (hdr.size != 5)
|
||||||
goto error_data;
|
goto error_data;
|
||||||
hdr.buf = hdrbuf;
|
hdr.buf = hdrbuf;
|
||||||
@@ -284,6 +288,8 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame)
|
|||||||
rv = ctx->fn_read(ctx->arg_read, &hdr);
|
rv = ctx->fn_read(ctx->arg_read, &hdr);
|
||||||
if (rv == -1)
|
if (rv == -1)
|
||||||
goto error_read;
|
goto error_read;
|
||||||
|
if (rv == -2)
|
||||||
|
goto error_canceled;
|
||||||
|
|
||||||
/* eof reached ? */
|
/* eof reached ? */
|
||||||
if (unlikely(hdr.size == 0)) {
|
if (unlikely(hdr.size == 0)) {
|
||||||
@@ -318,6 +324,8 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame)
|
|||||||
/* generic read failure! */
|
/* generic read failure! */
|
||||||
if (rv == -1)
|
if (rv == -1)
|
||||||
goto error_read;
|
goto error_read;
|
||||||
|
if (rv == -2)
|
||||||
|
goto error_canceled;
|
||||||
/* needed more bytes! */
|
/* needed more bytes! */
|
||||||
if (in->size != toRead)
|
if (in->size != toRead)
|
||||||
goto error_data;
|
goto error_data;
|
||||||
@@ -330,6 +338,9 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame)
|
|||||||
/* done, no error */
|
/* done, no error */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error_canceled:
|
||||||
|
pthread_mutex_unlock(&ctx->read_mutex);
|
||||||
|
return ZSTDMT_ERROR(canceled);
|
||||||
error_data:
|
error_data:
|
||||||
pthread_mutex_unlock(&ctx->read_mutex);
|
pthread_mutex_unlock(&ctx->read_mutex);
|
||||||
return ZSTDMT_ERROR(data_error);
|
return ZSTDMT_ERROR(data_error);
|
||||||
@@ -602,6 +613,14 @@ static size_t st_decompress(void *arg)
|
|||||||
w.size = zOut.pos;
|
w.size = zOut.pos;
|
||||||
w.buf = zOut.dst;
|
w.buf = zOut.dst;
|
||||||
rv = ctx->fn_write(ctx->arg_write, &w);
|
rv = ctx->fn_write(ctx->arg_write, &w);
|
||||||
|
if (rv == -1) {
|
||||||
|
return ZSTDMT_ERROR(write_fail);
|
||||||
|
goto error_clib;
|
||||||
|
}
|
||||||
|
if (rv == -2) {
|
||||||
|
return ZSTDMT_ERROR(canceled);
|
||||||
|
goto error_clib;
|
||||||
|
}
|
||||||
ctx->outsize += zOut.pos;
|
ctx->outsize += zOut.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,16 @@ int Lz4Read(void *arg, LZ4MT_Buffer * in)
|
|||||||
size_t size = in->size;
|
size_t size = in->size;
|
||||||
|
|
||||||
HRESULT res = ReadStream(x->inStream, in->buf, &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)
|
if (res != S_OK)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -28,17 +38,29 @@ int Lz4Write(void *arg, LZ4MT_Buffer * out)
|
|||||||
{
|
{
|
||||||
UInt32 block;
|
UInt32 block;
|
||||||
HRESULT res = x->outStream->Write((char*)out->buf + done, todo, &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;
|
done += block;
|
||||||
if (res == k_My_HRESULT_WritingWasCut)
|
if (res == k_My_HRESULT_WritingWasCut)
|
||||||
break;
|
break;
|
||||||
|
/* some other error -> write_fail */
|
||||||
if (res != S_OK)
|
if (res != S_OK)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (block == 0)
|
if (block == 0)
|
||||||
return E_FAIL;
|
return -1;
|
||||||
todo -= block;
|
todo -= block;
|
||||||
}
|
}
|
||||||
|
|
||||||
*x->processedOut += done;
|
*x->processedOut += done;
|
||||||
|
/* we need no lock here, cause only one thread can write... */
|
||||||
if (x->progress)
|
if (x->progress)
|
||||||
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
||||||
|
|
||||||
@@ -130,17 +152,18 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
|
|||||||
rdwr.arg_read = (void *)&Rd;
|
rdwr.arg_read = (void *)&Rd;
|
||||||
rdwr.arg_write = (void *)&Wr;
|
rdwr.arg_write = (void *)&Wr;
|
||||||
|
|
||||||
/* 2) create compression context */
|
/* 2) create decompression context */
|
||||||
LZ4MT_DCtx *ctx = LZ4MT_createDCtx(_numThreads, _inputSize);
|
LZ4MT_DCtx *ctx = LZ4MT_createDCtx(_numThreads, _inputSize);
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
/* 3) compress */
|
/* 3) decompress */
|
||||||
result = LZ4MT_DecompressDCtx(ctx, &rdwr);
|
result = LZ4MT_decompressDCtx(ctx, &rdwr);
|
||||||
if (result == (size_t)-LZ4MT_error_read_fail)
|
if (LZ4MT_isError(result)) {
|
||||||
res = E_ABORT;
|
if (result == (size_t)-LZ4MT_error_canceled)
|
||||||
else if (LZ4MT_isError(result))
|
return E_ABORT;
|
||||||
return ErrorOut(result);
|
return ErrorOut(result);
|
||||||
|
}
|
||||||
|
|
||||||
/* 4) free resources */
|
/* 4) free resources */
|
||||||
LZ4MT_freeDCtx(ctx);
|
LZ4MT_freeDCtx(ctx);
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
// (C) 2016 Tino Reichardt
|
// (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
|
#define LZ4_STATIC_LINKING_ONLY
|
||||||
#include "../../../C/Alloc.h"
|
#include "../../../C/Alloc.h"
|
||||||
#include "../../../C/Threads.h"
|
#include "../../../C/Threads.h"
|
||||||
|
|||||||
@@ -24,6 +24,18 @@ CEncoder::~CEncoder()
|
|||||||
LZ4MT_freeCCtx(_ctx);
|
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)
|
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARIANT * coderProps, UInt32 numProps)
|
||||||
{
|
{
|
||||||
_props.clear();
|
_props.clear();
|
||||||
@@ -40,10 +52,11 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARI
|
|||||||
if (prop.vt != VT_UI4)
|
if (prop.vt != VT_UI4)
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
|
|
||||||
|
/* level 1..22 */
|
||||||
_props._level = static_cast < Byte > (prop.ulVal);
|
_props._level = static_cast < Byte > (prop.ulVal);
|
||||||
Byte lz4_level = static_cast < Byte > (LZ4MT_LEVEL_MAX);
|
Byte mylevel = static_cast < Byte > (LZ4MT_LEVEL_MAX);
|
||||||
if (_props._level > lz4_level)
|
if (_props._level > mylevel)
|
||||||
_props._level = lz4_level;
|
_props._level = mylevel;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -104,12 +117,12 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
|||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
/* 3) compress */
|
/* 3) compress */
|
||||||
result = LZ4MT_CompressCCtx(_ctx, &rdwr);
|
result = LZ4MT_compressCCtx(_ctx, &rdwr);
|
||||||
if (result == (size_t)-LZ4MT_error_read_fail)
|
if (LZ4MT_isError(result)) {
|
||||||
res = E_ABORT;
|
if (result == (size_t)-LZ4MT_error_canceled)
|
||||||
else if (LZ4MT_isError(result))
|
return E_ABORT;
|
||||||
if (result != LZ4MT_error_read_fail)
|
return ErrorOut(result);
|
||||||
return ErrorOut(result);
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -123,17 +136,5 @@ STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads)
|
|||||||
return S_OK;
|
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
|
#endif
|
||||||
|
|||||||
@@ -9,6 +9,16 @@ int Lz5Read(void *arg, LZ5MT_Buffer * in)
|
|||||||
size_t size = in->size;
|
size_t size = in->size;
|
||||||
|
|
||||||
HRESULT res = ReadStream(x->inStream, in->buf, &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)
|
if (res != S_OK)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -28,17 +38,29 @@ int Lz5Write(void *arg, LZ5MT_Buffer * out)
|
|||||||
{
|
{
|
||||||
UInt32 block;
|
UInt32 block;
|
||||||
HRESULT res = x->outStream->Write((char*)out->buf + done, todo, &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;
|
done += block;
|
||||||
if (res == k_My_HRESULT_WritingWasCut)
|
if (res == k_My_HRESULT_WritingWasCut)
|
||||||
break;
|
break;
|
||||||
|
/* some other error -> write_fail */
|
||||||
if (res != S_OK)
|
if (res != S_OK)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (block == 0)
|
if (block == 0)
|
||||||
return E_FAIL;
|
return -1;
|
||||||
todo -= block;
|
todo -= block;
|
||||||
}
|
}
|
||||||
|
|
||||||
*x->processedOut += done;
|
*x->processedOut += done;
|
||||||
|
/* we need no lock here, cause only one thread can write... */
|
||||||
if (x->progress)
|
if (x->progress)
|
||||||
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
||||||
|
|
||||||
@@ -130,18 +152,18 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
|
|||||||
rdwr.arg_read = (void *)&Rd;
|
rdwr.arg_read = (void *)&Rd;
|
||||||
rdwr.arg_write = (void *)&Wr;
|
rdwr.arg_write = (void *)&Wr;
|
||||||
|
|
||||||
/* 2) create compression context */
|
/* 2) create decompression context */
|
||||||
LZ5MT_DCtx *ctx = LZ5MT_createDCtx(_numThreads, _inputSize);
|
LZ5MT_DCtx *ctx = LZ5MT_createDCtx(_numThreads, _inputSize);
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
/* 3) compress */
|
/* 3) decompress */
|
||||||
result = LZ5MT_DecompressDCtx(ctx, &rdwr);
|
result = LZ5MT_decompressDCtx(ctx, &rdwr);
|
||||||
if (result == (size_t)-LZ5MT_error_read_fail)
|
if (LZ5MT_isError(result)) {
|
||||||
res = E_ABORT;
|
if (result == (size_t)-LZ5MT_error_canceled)
|
||||||
else if (LZ5MT_isError(result))
|
return E_ABORT;
|
||||||
if (result != LZ5MT_error_read_fail)
|
return ErrorOut(result);
|
||||||
return ErrorOut(result);
|
}
|
||||||
|
|
||||||
/* 4) free resources */
|
/* 4) free resources */
|
||||||
LZ5MT_freeDCtx(ctx);
|
LZ5MT_freeDCtx(ctx);
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
// (C) 2016 Tino Reichardt
|
// (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
|
#define LZ5_STATIC_LINKING_ONLY
|
||||||
#include "../../../C/Alloc.h"
|
#include "../../../C/Alloc.h"
|
||||||
#include "../../../C/Threads.h"
|
#include "../../../C/Threads.h"
|
||||||
|
|||||||
@@ -24,6 +24,18 @@ CEncoder::~CEncoder()
|
|||||||
LZ5MT_freeCCtx(_ctx);
|
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)
|
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARIANT * coderProps, UInt32 numProps)
|
||||||
{
|
{
|
||||||
_props.clear();
|
_props.clear();
|
||||||
@@ -40,10 +52,11 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARI
|
|||||||
if (prop.vt != VT_UI4)
|
if (prop.vt != VT_UI4)
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
|
|
||||||
|
/* level 1..22 */
|
||||||
_props._level = static_cast < Byte > (prop.ulVal);
|
_props._level = static_cast < Byte > (prop.ulVal);
|
||||||
Byte lz5_level = static_cast < Byte > (LZ5MT_LEVEL_MAX);
|
Byte mylevel = static_cast < Byte > (LZ5MT_LEVEL_MAX);
|
||||||
if (_props._level > lz5_level)
|
if (_props._level > mylevel)
|
||||||
_props._level = lz5_level;
|
_props._level = mylevel;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -104,11 +117,12 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
|||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
/* 3) compress */
|
/* 3) compress */
|
||||||
result = LZ5MT_CompressCCtx(_ctx, &rdwr);
|
result = LZ5MT_compressCCtx(_ctx, &rdwr);
|
||||||
if (result == (size_t)-LZ5MT_error_read_fail)
|
if (LZ5MT_isError(result)) {
|
||||||
res = E_ABORT;
|
if (result == (size_t)-LZ5MT_error_canceled)
|
||||||
if (LZ5MT_isError(result))
|
return E_ABORT;
|
||||||
return ErrorOut(result);
|
return ErrorOut(result);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -122,17 +136,5 @@ STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads)
|
|||||||
return S_OK;
|
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
|
#endif
|
||||||
|
|||||||
@@ -9,6 +9,16 @@ int ZstdRead(void *arg, ZSTDMT_Buffer * in)
|
|||||||
size_t size = in->size;
|
size_t size = in->size;
|
||||||
|
|
||||||
HRESULT res = ReadStream(x->inStream, in->buf, &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)
|
if (res != S_OK)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -28,17 +38,29 @@ int ZstdWrite(void *arg, ZSTDMT_Buffer * out)
|
|||||||
{
|
{
|
||||||
UInt32 block;
|
UInt32 block;
|
||||||
HRESULT res = x->outStream->Write((char*)out->buf + done, todo, &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;
|
done += block;
|
||||||
if (res == k_My_HRESULT_WritingWasCut)
|
if (res == k_My_HRESULT_WritingWasCut)
|
||||||
break;
|
break;
|
||||||
|
/* some other error -> write_fail */
|
||||||
if (res != S_OK)
|
if (res != S_OK)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (block == 0)
|
if (block == 0)
|
||||||
return E_FAIL;
|
return -1;
|
||||||
todo -= block;
|
todo -= block;
|
||||||
}
|
}
|
||||||
|
|
||||||
*x->processedOut += done;
|
*x->processedOut += done;
|
||||||
|
/* we need no lock here, cause only one thread can write... */
|
||||||
if (x->progress)
|
if (x->progress)
|
||||||
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
||||||
|
|
||||||
@@ -137,11 +159,11 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
|
|||||||
|
|
||||||
/* 3) decompress */
|
/* 3) decompress */
|
||||||
result = ZSTDMT_decompressDCtx(ctx, &rdwr);
|
result = ZSTDMT_decompressDCtx(ctx, &rdwr);
|
||||||
//printf("decompress = %d / %d\n", result, ZSTDMT_error_read_fail);
|
if (ZSTDMT_isError(result)) {
|
||||||
if (result == (size_t)-ZSTDMT_error_read_fail)
|
if (result == (size_t)-ZSTDMT_error_canceled)
|
||||||
res = E_ABORT;
|
return E_ABORT;
|
||||||
else if (ZSTDMT_isError(result))
|
|
||||||
return ErrorOut(result);
|
return ErrorOut(result);
|
||||||
|
}
|
||||||
|
|
||||||
/* 4) free resources */
|
/* 4) free resources */
|
||||||
ZSTDMT_freeDCtx(ctx);
|
ZSTDMT_freeDCtx(ctx);
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
// (C) 2016 Tino Reichardt
|
// (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
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
#include "../../../C/Alloc.h"
|
#include "../../../C/Alloc.h"
|
||||||
#include "../../../C/Threads.h"
|
#include "../../../C/Threads.h"
|
||||||
|
|||||||
@@ -24,6 +24,18 @@ CEncoder::~CEncoder()
|
|||||||
ZSTDMT_freeCCtx(_ctx);
|
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)
|
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARIANT * coderProps, UInt32 numProps)
|
||||||
{
|
{
|
||||||
_props.clear();
|
_props.clear();
|
||||||
@@ -42,9 +54,9 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARI
|
|||||||
|
|
||||||
/* level 1..22 */
|
/* level 1..22 */
|
||||||
_props._level = static_cast < Byte > (prop.ulVal);
|
_props._level = static_cast < Byte > (prop.ulVal);
|
||||||
Byte zstd_level = static_cast < Byte > (ZSTD_maxCLevel());
|
Byte mylevel = static_cast < Byte > (ZSTDMT_LEVEL_MAX);
|
||||||
if (_props._level > zstd_level)
|
if (_props._level > mylevel)
|
||||||
_props._level = zstd_level;
|
_props._level = mylevel;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -106,10 +118,11 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
|||||||
|
|
||||||
/* 3) compress */
|
/* 3) compress */
|
||||||
result = ZSTDMT_compressCCtx(_ctx, &rdwr);
|
result = ZSTDMT_compressCCtx(_ctx, &rdwr);
|
||||||
if (result == (size_t)-ZSTDMT_error_read_fail)
|
if (ZSTDMT_isError(result)) {
|
||||||
res = E_ABORT;
|
if (result == (size_t)-ZSTDMT_error_canceled)
|
||||||
else if (ZSTDMT_isError(result))
|
return E_ABORT;
|
||||||
return ErrorOut(result);
|
return ErrorOut(result);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -123,17 +136,5 @@ STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads)
|
|||||||
return S_OK;
|
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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user