2007-01-23 16:05:03 +00:00
|
|
|
#include "decompress.h"
|
|
|
|
|
2007-02-24 12:16:32 +00:00
|
|
|
#include <string.h> // for memset
|
|
|
|
|
2014-01-22 09:54:21 +00:00
|
|
|
#if _MSC_VER > 1200 // Hack to avoid extern "C" causing trouble with templates
|
|
|
|
#include <new>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
|
|
|
#include <memory>
|
|
|
|
#endif
|
|
|
|
|
2007-01-23 16:05:03 +00:00
|
|
|
#define EXEHEAD
|
|
|
|
#define NSIS_CONFIG_COMPRESSION_SUPPORT
|
|
|
|
|
2014-10-05 21:52:03 +00:00
|
|
|
#include "../Platform.h"
|
|
|
|
|
2007-01-23 16:05:03 +00:00
|
|
|
extern "C" {
|
|
|
|
#define NSIS_COMPRESS_USE_BZIP2
|
|
|
|
#include "../bzip2/bzlib.h"
|
|
|
|
#undef NSIS_COMPRESS_USE_BZIP2
|
|
|
|
|
|
|
|
#define NSIS_COMPRESS_USE_LZMA
|
|
|
|
#include "../7zip/LZMADecode.h"
|
|
|
|
#undef NSIS_COMPRESS_USE_LZMA
|
|
|
|
|
|
|
|
#define NSIS_COMPRESS_USE_ZLIB
|
|
|
|
#include "../zlib/ZLIB.H"
|
|
|
|
#undef NSIS_COMPRESS_USE_ZLIB
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DECOMPRESSOR(name, type, initf, dec, u) \
|
|
|
|
name::name() { \
|
|
|
|
vs = new type; \
|
2007-02-23 12:34:51 +00:00
|
|
|
memset(vs, 0, sizeof(type)); \
|
2007-01-23 16:05:03 +00:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
name::~name() { \
|
2007-01-25 17:49:10 +00:00
|
|
|
delete (type *) vs; \
|
|
|
|
vs = 0; \
|
2007-01-23 16:05:03 +00:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
void name::setNextIn(void *buffer, int size) { \
|
|
|
|
type *s = (type *) vs; \
|
|
|
|
s->next_in = (u *) buffer; \
|
|
|
|
s->avail_in = size; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void name::setNextOut(void *buffer, int size) { \
|
|
|
|
type *s = (type *) vs; \
|
|
|
|
s->next_out = (u *) buffer; \
|
|
|
|
s->avail_out = size; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
int name::getAvailOut() { \
|
|
|
|
type *s = (type *) vs; \
|
|
|
|
return s->avail_out; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void name::init() { \
|
|
|
|
type *s = (type *) vs; \
|
|
|
|
initf(s); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
int name::decompress() { \
|
|
|
|
type *s = (type *) vs; \
|
|
|
|
return dec(s); \
|
|
|
|
}
|
|
|
|
|
|
|
|
DECOMPRESSOR(lzmaDecompressor, lzma_stream, lzmaInit, lzmaDecode, unsigned char);
|
2014-01-22 09:54:21 +00:00
|
|
|
DECOMPRESSOR(bzip2Decompressor, DState, BZ2_bzDecompressInit, BZ2_bzDecompress, unsigned char);
|
2007-01-23 16:05:03 +00:00
|
|
|
DECOMPRESSOR(zlibDecompressor, z_stream, inflateReset, inflate, unsigned char);
|