fixed a bunch of bugs that caused lzma and bzip2 not to function without solid compression
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3362 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
e9919e7f89
commit
dd8a4388ac
6 changed files with 42 additions and 14 deletions
|
@ -140,14 +140,14 @@ int __stdcall lzmaDecompress(CLZMAStateP lzmaState)
|
||||||
EnterCriticalSection(&lzmaState->cs);
|
EnterCriticalSection(&lzmaState->cs);
|
||||||
lzmaState->it_locked = TRUE;
|
lzmaState->it_locked = TRUE;
|
||||||
|
|
||||||
|
while (lzmaState->dt_locked)
|
||||||
|
Sleep(0);
|
||||||
|
|
||||||
if (lzmaState->finished)
|
if (lzmaState->finished)
|
||||||
{
|
{
|
||||||
LeaveCriticalSection(&lzmaState->cs);
|
LeaveCriticalSection(&lzmaState->cs);
|
||||||
return lzmaState->res;
|
return lzmaState->res;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (lzmaState->dt_locked)
|
|
||||||
Sleep(0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -729,7 +729,7 @@ int CEXEBuild::add_db_data(IMMap *map) // returns offset
|
||||||
int st = db->getlen();
|
int st = db->getlen();
|
||||||
|
|
||||||
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
|
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
|
||||||
if (!build_compress_whole && build_compress)
|
if (length && !build_compress_whole && build_compress)
|
||||||
{
|
{
|
||||||
// grow datablock so that there is room to compress into
|
// grow datablock so that there is room to compress into
|
||||||
int bufferlen = length + 1024 + length / 4; // give a nice 25% extra space
|
int bufferlen = length + 1024 + length / 4; // give a nice 25% extra space
|
||||||
|
@ -798,7 +798,7 @@ int CEXEBuild::add_db_data(IMMap *map) // returns offset
|
||||||
|
|
||||||
avail_out -= out_len - compressor->GetAvailOut();
|
avail_out -= out_len - compressor->GetAvailOut();
|
||||||
}
|
}
|
||||||
while (compressor->GetNextOut() - out > 0);
|
while (compressor->GetNextOut() - out > 0 && avail_out > 0);
|
||||||
|
|
||||||
compressor->End();
|
compressor->End();
|
||||||
|
|
||||||
|
@ -818,6 +818,8 @@ int CEXEBuild::add_db_data(IMMap *map) // returns offset
|
||||||
else st = nst;
|
else st = nst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
compressor->End();
|
||||||
}
|
}
|
||||||
#endif // NSIS_CONFIG_COMPRESSION_SUPPORT
|
#endif // NSIS_CONFIG_COMPRESSION_SUPPORT
|
||||||
|
|
||||||
|
|
|
@ -420,7 +420,7 @@ extern void BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
|
||||||
Int32, Int32, Int32 );
|
Int32, Int32, Int32 );
|
||||||
|
|
||||||
|
|
||||||
#define BZ2_bzDecompressInit(s) { (s)->state = BZ_X_BLKHDR_1; }
|
#define BZ2_bzDecompressInit(s) { (s)->state = BZ_X_BLKHDR_1; (s)->bsLive = 0; }
|
||||||
int NSISCALL BZ2_bzDecompress(DState *s);
|
int NSISCALL BZ2_bzDecompress(DState *s);
|
||||||
|
|
||||||
#endif//EXEHEAD
|
#endif//EXEHEAD
|
||||||
|
|
|
@ -21,7 +21,7 @@ class CBzip2 : public ICompressor {
|
||||||
|
|
||||||
int Compress(BOOL finish) {
|
int Compress(BOOL finish) {
|
||||||
// act like zlib when it comes to stream ending
|
// act like zlib when it comes to stream ending
|
||||||
if (last_ret == BZ_STREAM_END)
|
if (last_ret == BZ_STREAM_END && finish)
|
||||||
return BZ_STREAM_END;
|
return BZ_STREAM_END;
|
||||||
last_ret = BZ2_bzCompress(stream, finish?BZ_FINISH:0);
|
last_ret = BZ2_bzCompress(stream, finish?BZ_FINISH:0);
|
||||||
return last_ret;
|
return last_ret;
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
hCompressionThread = NULL;
|
hCompressionThread = NULL;
|
||||||
compressor_finished = FALSE;
|
compressor_finished = FALSE;
|
||||||
finish = FALSE;
|
finish = FALSE;
|
||||||
|
ct_locked = TRUE;
|
||||||
End();
|
End();
|
||||||
InitializeCriticalSection(&cs);
|
InitializeCriticalSection(&cs);
|
||||||
}
|
}
|
||||||
|
@ -102,6 +103,22 @@ public:
|
||||||
|
|
||||||
int End()
|
int End()
|
||||||
{
|
{
|
||||||
|
if (!compressor_finished && !ct_locked)
|
||||||
|
{
|
||||||
|
// kill compression thread
|
||||||
|
avail_in = 0;
|
||||||
|
avail_out = 0;
|
||||||
|
finish = TRUE;
|
||||||
|
LeaveCriticalSection(&cs);
|
||||||
|
while (!ct_locked)
|
||||||
|
Sleep(0);
|
||||||
|
nt_locked = FALSE;
|
||||||
|
EnterCriticalSection(&cs);
|
||||||
|
while (ct_locked)
|
||||||
|
Sleep(0);
|
||||||
|
nt_locked = TRUE;
|
||||||
|
LeaveCriticalSection(&cs);
|
||||||
|
}
|
||||||
if (hCompressionThread)
|
if (hCompressionThread)
|
||||||
{
|
{
|
||||||
CloseHandle(hCompressionThread);
|
CloseHandle(hCompressionThread);
|
||||||
|
@ -167,17 +184,18 @@ public:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finish = flush;
|
||||||
|
|
||||||
if (!hCompressionThread)
|
if (!hCompressionThread)
|
||||||
{
|
{
|
||||||
DWORD dwThreadId;
|
DWORD dwThreadId;
|
||||||
finish = flush;
|
|
||||||
hCompressionThread = CreateThread(0, 0, lzmaCompressThread, (LPVOID) this, 0, &dwThreadId);
|
hCompressionThread = CreateThread(0, 0, lzmaCompressThread, (LPVOID) this, 0, &dwThreadId);
|
||||||
if (!hCompressionThread)
|
if (!hCompressionThread)
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
finish = flush;
|
|
||||||
LeaveCriticalSection(&cs);
|
LeaveCriticalSection(&cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,15 +207,15 @@ public:
|
||||||
EnterCriticalSection(&cs);
|
EnterCriticalSection(&cs);
|
||||||
nt_locked = TRUE;
|
nt_locked = TRUE;
|
||||||
|
|
||||||
|
while (ct_locked)
|
||||||
|
Sleep(0);
|
||||||
|
|
||||||
if (compressor_finished)
|
if (compressor_finished)
|
||||||
{
|
{
|
||||||
LeaveCriticalSection(&cs);
|
LeaveCriticalSection(&cs);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ct_locked)
|
|
||||||
Sleep(0);
|
|
||||||
|
|
||||||
return C_OK;
|
return C_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,7 @@ const char * NSISCALL loadHeaders(int cl_flags)
|
||||||
|
|
||||||
data = (void *)my_GlobalAlloc(h.length_of_header);
|
data = (void *)my_GlobalAlloc(h.length_of_header);
|
||||||
|
|
||||||
#if defined(NSIS_CONFIG_COMPRESSION_SUPPORT) && defined(NSIS_COMPRESS_WHOLE)
|
#ifdef NSIS_COMPRESS_WHOLE
|
||||||
inflateReset(&g_inflate_stream);
|
inflateReset(&g_inflate_stream);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -336,7 +336,8 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, char *outbuf, int outbuflen)
|
||||||
int l=min(input_len,IBUFSIZE);
|
int l=min(input_len,IBUFSIZE);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!ReadSelfFile((LPVOID)inbuffer,l)) return -3;
|
if (!ReadSelfFile((LPVOID)inbuffer,l))
|
||||||
|
return -3;
|
||||||
|
|
||||||
g_inflate_stream.next_in = inbuffer;
|
g_inflate_stream.next_in = inbuffer;
|
||||||
g_inflate_stream.avail_in = l;
|
g_inflate_stream.avail_in = l;
|
||||||
|
@ -345,6 +346,13 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, char *outbuf, int outbuflen)
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
int u;
|
int u;
|
||||||
|
|
||||||
|
#ifdef NSIS_COMPRESS_USE_LZMA
|
||||||
|
// lzma decompressor doesn't like to stay dry
|
||||||
|
if (!g_inflate_stream.avail_in && input_len)
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
g_inflate_stream.next_out = outbuffer;
|
g_inflate_stream.next_out = outbuffer;
|
||||||
g_inflate_stream.avail_out = (unsigned int)outbuffer_len;
|
g_inflate_stream.avail_out = (unsigned int)outbuffer_len;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue