show meaningful error strings and not just numbers for compression errors
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3545 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
499fa0e764
commit
43cfa19a94
7 changed files with 97 additions and 16 deletions
|
@ -102,10 +102,10 @@ HRESULT CInTree::Create(UINT32 sizeHistory, UINT32 keepAddBufferBefore,
|
|||
#ifdef WIN32
|
||||
_son = (CPair *)::VirtualAlloc(0, (_cyclicBufferSize + 1) * sizeof(CPair), MEM_COMMIT, PAGE_READWRITE);
|
||||
if (_son == 0)
|
||||
throw 1; // CNewException();
|
||||
throw CMemoryException();
|
||||
_hash = (CIndex *)::VirtualAlloc(0, (size + 1) * sizeof(CIndex), MEM_COMMIT, PAGE_READWRITE);
|
||||
if (_hash == 0)
|
||||
throw 1; // CNewException();
|
||||
throw CMemoryException();
|
||||
#else
|
||||
_son = new CPair[_cyclicBufferSize + 1];
|
||||
_hash = new CIndex[size + 1];
|
||||
|
|
|
@ -19,4 +19,10 @@ inline int BoolToInt(bool value)
|
|||
inline bool IntToBool(int value)
|
||||
{ return (value != 0); }
|
||||
|
||||
class CMemoryException
|
||||
{
|
||||
public:
|
||||
CMemoryException() {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -785,7 +785,7 @@ int CEXEBuild::add_db_data(IMMap *map) // returns offset
|
|||
n = compressor->Init(build_compress_level);
|
||||
if (n != C_OK)
|
||||
{
|
||||
ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%d).\n", n);
|
||||
ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%d - %s).\n", n, compressor->GetErrStr(n));
|
||||
extern void quit(); quit();
|
||||
}
|
||||
|
||||
|
@ -801,7 +801,7 @@ int CEXEBuild::add_db_data(IMMap *map) // returns offset
|
|||
compressor->SetNextOut((char *) db->get(st + sizeof(int) + bufferlen - avail_out, out_len), out_len);
|
||||
if ((ret = compressor->Compress(0)) < 0)
|
||||
{
|
||||
ERROR_MSG("Error: add_db_data() - compress() failed - %d\n", ret);
|
||||
ERROR_MSG("Error: add_db_data() - compress() failed(%d - %s)\n", ret, compressor->GetErrStr(ret));
|
||||
return -1;
|
||||
}
|
||||
map->release();
|
||||
|
@ -832,7 +832,7 @@ int CEXEBuild::add_db_data(IMMap *map) // returns offset
|
|||
compressor->SetNextOut(out, out_len);
|
||||
if ((ret = compressor->Compress(C_FINISH)) < 0)
|
||||
{
|
||||
ERROR_MSG("Error: add_db_data() - compress() failed - %d\n", ret);
|
||||
ERROR_MSG("Error: add_db_data() - compress() failed(%d - %s)\n", ret, compressor->GetErrStr(ret));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -928,7 +928,7 @@ int CEXEBuild::add_data(const char *data, int length, IGrowBuf *dblock) // retur
|
|||
n = compressor->Init(build_compress_level);
|
||||
if (n != C_OK)
|
||||
{
|
||||
ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%d).\n",n);
|
||||
ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%d - %s).\n", n, compressor->GetErrStr(n));
|
||||
extern void quit(); quit();
|
||||
}
|
||||
|
||||
|
@ -2432,7 +2432,7 @@ int CEXEBuild::write_output(void)
|
|||
n = compressor->Init(build_compress_level);
|
||||
if (n != C_OK)
|
||||
{
|
||||
ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%d).\n", n);
|
||||
ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%d - %s).\n", n, compressor->GetErrStr(n));
|
||||
return PS_ERROR;
|
||||
}
|
||||
}
|
||||
|
@ -2733,7 +2733,7 @@ int CEXEBuild::deflateToFile(FILE *fp, char *buf, int len) // len==0 to flush
|
|||
int ret=compressor->Compress(flush);
|
||||
if (ret<0 && (ret!=-1 || !flush))
|
||||
{
|
||||
ERROR_MSG("Error: deflateToFile: deflate()=%d\n",ret);
|
||||
ERROR_MSG("Error: deflateToFile: deflate() failed(%d - %s)\n", ret, compressor->GetErrStr(ret));
|
||||
return 1;
|
||||
}
|
||||
int l=compressor->GetNextOut()-obuf;
|
||||
|
@ -2863,7 +2863,7 @@ int CEXEBuild::uninstall_generate()
|
|||
n = compressor->Init(build_compress_level);
|
||||
if (n != C_OK)
|
||||
{
|
||||
ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%d).\n", n);
|
||||
ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%d - %s).\n", n, compressor->GetErrStr(n));
|
||||
extern void quit(); quit();
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,22 @@ class CBzip2 : public ICompressor {
|
|||
return "bzip2";
|
||||
}
|
||||
|
||||
const char* GetErrStr(int err) {
|
||||
switch (err)
|
||||
{
|
||||
case BZ_SEQUENCE_ERROR:
|
||||
return "sequence error - bad call";
|
||||
case BZ_PARAM_ERROR:
|
||||
return "parameter error - bad call";
|
||||
case BZ_MEM_ERROR:
|
||||
return "not enough memory";
|
||||
case BZ_CONFIG_ERROR:
|
||||
return "config error";
|
||||
default:
|
||||
return "unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bz_stream *stream;
|
||||
int last_ret;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "7zip/7zip/IStream.h"
|
||||
#include "7zip/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
#include "7zip/Common/MyCom.h"
|
||||
#include "7zip/Common/Defs.h"
|
||||
|
||||
// implemented in build.cpp - simply calls CompressReal
|
||||
#ifdef _WIN32
|
||||
|
@ -13,6 +14,12 @@ DWORD WINAPI lzmaCompressThread(LPVOID lpParameter);
|
|||
void *lzmaCompressThread(void *arg);
|
||||
#endif
|
||||
|
||||
#define LZMA_BAD_CALL -1
|
||||
#define LZMA_INIT_ERROR -2
|
||||
#define LZMA_THREAD_ERROR -3
|
||||
#define LZMA_IO_ERROR -4
|
||||
#define LZMA_MEM_ERROR -5
|
||||
|
||||
class CLZMA:
|
||||
public ICompressor,
|
||||
public ISequentialInStream,
|
||||
|
@ -169,6 +176,12 @@ public:
|
|||
|
||||
compressor_finished = FALSE;
|
||||
finish = FALSE;
|
||||
res = C_OK;
|
||||
|
||||
if (!hNeedIOEvent || !hIOReadyEvent)
|
||||
{
|
||||
return LZMA_INIT_ERROR;
|
||||
}
|
||||
|
||||
ResetEvent(hNeedIOEvent);
|
||||
ResetEvent(hIOReadyEvent);
|
||||
|
@ -193,7 +206,7 @@ public:
|
|||
props[2].vt = VT_UI4;
|
||||
props[2].ulVal = 64;
|
||||
if (_encoder->SetCoderProperties(propdIDs, props, kNumProps) != 0)
|
||||
return -1;
|
||||
return LZMA_INIT_ERROR;
|
||||
return _encoder->SetStreams(this, this, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -246,7 +259,8 @@ public:
|
|||
INT32 finished;
|
||||
if (_encoder->CodeOneBlock(&inSize, &outSize, &finished))
|
||||
{
|
||||
res = -2;
|
||||
if (res != C_OK)
|
||||
res = LZMA_IO_ERROR;
|
||||
break;
|
||||
}
|
||||
if (finished)
|
||||
|
@ -258,12 +272,16 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
res = -2;
|
||||
res = LZMA_IO_ERROR;
|
||||
}
|
||||
}
|
||||
catch (CMemoryException)
|
||||
{
|
||||
res = LZMA_MEM_ERROR;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
res = -3;
|
||||
res = LZMA_IO_ERROR;
|
||||
}
|
||||
|
||||
compressor_finished = TRUE;
|
||||
|
@ -279,7 +297,7 @@ public:
|
|||
if (flush)
|
||||
return C_OK;
|
||||
else
|
||||
return -1;
|
||||
return LZMA_BAD_CALL;
|
||||
}
|
||||
|
||||
finish = flush;
|
||||
|
@ -294,7 +312,7 @@ public:
|
|||
#else
|
||||
if (pthread_create(&hCompressionThread, NULL, lzmaCompressThread, (LPVOID) this))
|
||||
#endif
|
||||
return -2;
|
||||
return LZMA_INIT_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -307,7 +325,7 @@ public:
|
|||
// thread ended or WaitForMultipleObjects failed
|
||||
compressor_finished = TRUE;
|
||||
SetEvent(hIOReadyEvent);
|
||||
return -4;
|
||||
return LZMA_THREAD_ERROR;
|
||||
}
|
||||
|
||||
if (compressor_finished)
|
||||
|
@ -322,7 +340,10 @@ public:
|
|||
{
|
||||
SetEvent(hNeedIOEvent);
|
||||
if (WaitForSingleObject(hIOReadyEvent, INFINITE) != WAIT_OBJECT_0)
|
||||
{
|
||||
compressor_finished = TRUE;
|
||||
res = LZMA_THREAD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize)
|
||||
|
@ -411,6 +432,24 @@ public:
|
|||
virtual unsigned int GetAvailIn() { return avail_in; }
|
||||
virtual unsigned int GetAvailOut() { return avail_out; }
|
||||
const char *GetName() { return "lzma"; }
|
||||
|
||||
const char* GetErrStr(int err) {
|
||||
switch (err)
|
||||
{
|
||||
case LZMA_BAD_CALL:
|
||||
return "bad call";
|
||||
case LZMA_INIT_ERROR:
|
||||
return "initialization failed";
|
||||
case LZMA_THREAD_ERROR:
|
||||
return "thread synchronization error";
|
||||
case LZMA_IO_ERROR:
|
||||
return "input/output error";
|
||||
case LZMA_MEM_ERROR:
|
||||
return "not enough memory";
|
||||
default:
|
||||
return "unknown error";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,6 +19,8 @@ class ICompressor {
|
|||
virtual unsigned int GetAvailOut() = 0;
|
||||
|
||||
virtual const char* GetName() = 0;
|
||||
|
||||
virtual const char* GetErrStr(int err) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -48,6 +48,24 @@ class CZlib : public ICompressor {
|
|||
return "zlib";
|
||||
}
|
||||
|
||||
const char* GetErrStr(int err) {
|
||||
switch (err)
|
||||
{
|
||||
case Z_STREAM_ERROR:
|
||||
return "invalid stream - bad call";
|
||||
case Z_DATA_ERROR:
|
||||
return "data error";
|
||||
case Z_MEM_ERROR:
|
||||
return "not enough memory";
|
||||
case Z_BUF_ERROR:
|
||||
return "buffer error - bad call";
|
||||
case Z_VERSION_ERROR:
|
||||
return "version error";
|
||||
default:
|
||||
return "unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
z_stream *stream;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue