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:
kichik 2004-01-06 00:53:12 +00:00
parent e9919e7f89
commit dd8a4388ac
6 changed files with 42 additions and 14 deletions

View file

@ -140,14 +140,14 @@ int __stdcall lzmaDecompress(CLZMAStateP lzmaState)
EnterCriticalSection(&lzmaState->cs);
lzmaState->it_locked = TRUE;
while (lzmaState->dt_locked)
Sleep(0);
if (lzmaState->finished)
{
LeaveCriticalSection(&lzmaState->cs);
return lzmaState->res;
}
while (lzmaState->dt_locked)
Sleep(0);
return 0;
}

View file

@ -729,7 +729,7 @@ int CEXEBuild::add_db_data(IMMap *map) // returns offset
int st = db->getlen();
#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
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();
}
while (compressor->GetNextOut() - out > 0);
while (compressor->GetNextOut() - out > 0 && avail_out > 0);
compressor->End();
@ -818,6 +818,8 @@ int CEXEBuild::add_db_data(IMMap *map) // returns offset
else st = nst;
}
}
else
compressor->End();
}
#endif // NSIS_CONFIG_COMPRESSION_SUPPORT

View file

@ -420,7 +420,7 @@ extern void BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
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);
#endif//EXEHEAD

View file

@ -21,7 +21,7 @@ class CBzip2 : public ICompressor {
int Compress(BOOL finish) {
// 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;
last_ret = BZ2_bzCompress(stream, finish?BZ_FINISH:0);
return last_ret;

View file

@ -45,6 +45,7 @@ public:
hCompressionThread = NULL;
compressor_finished = FALSE;
finish = FALSE;
ct_locked = TRUE;
End();
InitializeCriticalSection(&cs);
}
@ -102,6 +103,22 @@ public:
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)
{
CloseHandle(hCompressionThread);
@ -167,17 +184,18 @@ public:
return -1;
}
finish = flush;
if (!hCompressionThread)
{
DWORD dwThreadId;
finish = flush;
hCompressionThread = CreateThread(0, 0, lzmaCompressThread, (LPVOID) this, 0, &dwThreadId);
if (!hCompressionThread)
return -2;
}
else
{
finish = flush;
LeaveCriticalSection(&cs);
}
@ -189,15 +207,15 @@ public:
EnterCriticalSection(&cs);
nt_locked = TRUE;
while (ct_locked)
Sleep(0);
if (compressor_finished)
{
LeaveCriticalSection(&cs);
return res;
}
while (ct_locked)
Sleep(0);
return C_OK;
}

View file

@ -244,7 +244,7 @@ const char * NSISCALL loadHeaders(int cl_flags)
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);
{
@ -336,7 +336,8 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, char *outbuf, int outbuflen)
int l=min(input_len,IBUFSIZE);
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.avail_in = l;
@ -345,6 +346,13 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, char *outbuf, int outbuflen)
for (;;)
{
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.avail_out = (unsigned int)outbuffer_len;