| 1 |
#include "decompress.h" |
| 2 |
|
| 3 |
#include <string.h> // for memset |
| 4 |
|
| 5 |
#if _MSC_VER > 1200 // Hack to avoid extern "C" causing trouble with templates |
| 6 |
#include <new> |
| 7 |
#include <algorithm> |
| 8 |
#include <iterator> |
| 9 |
#include <memory> |
| 10 |
#endif |
| 11 |
|
| 12 |
#define EXEHEAD |
| 13 |
#define NSIS_CONFIG_COMPRESSION_SUPPORT |
| 14 |
|
| 15 |
#include "../Platform.h" |
| 16 |
|
| 17 |
extern "C" { |
| 18 |
#define NSIS_COMPRESS_USE_BZIP2 |
| 19 |
#include "../bzip2/bzlib.h" |
| 20 |
#undef NSIS_COMPRESS_USE_BZIP2 |
| 21 |
|
| 22 |
#define NSIS_COMPRESS_USE_LZMA |
| 23 |
#include "../7zip/LZMADecode.h" |
| 24 |
#undef NSIS_COMPRESS_USE_LZMA |
| 25 |
|
| 26 |
#define NSIS_COMPRESS_USE_ZLIB |
| 27 |
#include "../zlib/ZLIB.H" |
| 28 |
#undef NSIS_COMPRESS_USE_ZLIB |
| 29 |
} |
| 30 |
|
| 31 |
#define DECOMPRESSOR(name, type, initf, dec, u) \ |
| 32 |
name::name() { \ |
| 33 |
vs = new type; \ |
| 34 |
memset(vs, 0, sizeof(type)); \ |
| 35 |
} \ |
| 36 |
\ |
| 37 |
name::~name() { \ |
| 38 |
delete (type *) vs; \ |
| 39 |
vs = 0; \ |
| 40 |
} \ |
| 41 |
\ |
| 42 |
void name::setNextIn(void *buffer, int size) { \ |
| 43 |
type *s = (type *) vs; \ |
| 44 |
s->next_in = (u *) buffer; \ |
| 45 |
s->avail_in = size; \ |
| 46 |
} \ |
| 47 |
\ |
| 48 |
void name::setNextOut(void *buffer, int size) { \ |
| 49 |
type *s = (type *) vs; \ |
| 50 |
s->next_out = (u *) buffer; \ |
| 51 |
s->avail_out = size; \ |
| 52 |
} \ |
| 53 |
\ |
| 54 |
int name::getAvailOut() { \ |
| 55 |
type *s = (type *) vs; \ |
| 56 |
return s->avail_out; \ |
| 57 |
} \ |
| 58 |
\ |
| 59 |
void name::init() { \ |
| 60 |
type *s = (type *) vs; \ |
| 61 |
initf(s); \ |
| 62 |
} \ |
| 63 |
\ |
| 64 |
int name::decompress() { \ |
| 65 |
type *s = (type *) vs; \ |
| 66 |
return dec(s); \ |
| 67 |
} |
| 68 |
|
| 69 |
DECOMPRESSOR(lzmaDecompressor, lzma_stream, lzmaInit, lzmaDecode, unsigned char); |
| 70 |
DECOMPRESSOR(bzip2Decompressor, DState, BZ2_bzDecompressInit, BZ2_bzDecompress, unsigned char); |
| 71 |
DECOMPRESSOR(zlibDecompressor, z_stream, inflateReset, inflate, unsigned char); |