1 diff -BurN lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.cpp lzma/SRC/7zip/Compress/LZMA/LZMADecoder.cpp
2 --- lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.cpp 2004-08-25 01:40:48.000000000 +0400
3 +++ lzma/SRC/7zip/Compress/LZMA/LZMADecoder.cpp 2005-01-20 14:47:45.789801629 +0300
5 Byte remainder = (Byte)(properties[0] / 9);
\r
6 int lp = remainder % 5;
\r
7 int pb = remainder / 5;
\r
8 - if (pb > NLength::kNumPosStatesBitsMax)
\r
9 - return E_INVALIDARG;
\r
10 - _posStateMask = (1 << pb) - 1;
\r
11 UInt32 dictionarySize = 0;
\r
12 for (int i = 0; i < 4; i++)
\r
13 dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);
\r
14 + return SetDecoderPropertiesRaw(lc, lp, pb, dictionarySize);
\r
17 +STDMETHODIMP CDecoder::SetDecoderPropertiesRaw(int lc, int lp, int pb, UInt32 dictionarySize)
\r
19 + if (pb > NLength::kNumPosStatesBitsMax)
\r
20 + return E_INVALIDARG;
\r
21 + _posStateMask = (1 << pb) - 1;
\r
22 _dictionarySizeCheck = MyMax(dictionarySize, UInt32(1));
\r
23 UInt32 blockSize = MyMax(_dictionarySizeCheck, UInt32(1 << 12));
\r
24 if (!_outWindowStream.Create(blockSize))
\r
25 diff -BurN lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.h lzma/SRC/7zip/Compress/LZMA/LZMADecoder.h
26 --- lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.h 2004-08-25 01:40:08.000000000 +0400
27 +++ lzma/SRC/7zip/Compress/LZMA/LZMADecoder.h 2005-01-20 13:06:59.081297916 +0300
29 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
\r
30 STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);
\r
32 + STDMETHOD(SetDecoderPropertiesRaw)(int lc, int lp, int pb, UInt32 dictionarySize);
\r
34 virtual ~CDecoder() {}
\r
37 diff -BurN lzma406/SRC/7zip/Compress/LZMA_Lib/makefile lzma/SRC/7zip/Compress/LZMA_Lib/makefile
38 --- lzma406/SRC/7zip/Compress/LZMA_Lib/makefile 1970-01-01 03:00:00.000000000 +0300
39 +++ lzma/SRC/7zip/Compress/LZMA_Lib/makefile 2005-01-19 13:49:20.000000000 +0300
42 +CXX = g++ -O3 -Wall
\r
59 + CommandLineParser.o \
\r
70 + $(AR) r $(PROG) $(OBJS)
\r
73 + $(CXX) $(CFLAGS) ZLib.cpp
\r
75 +LZMADecoder.o: ../LZMA/LZMADecoder.cpp
\r
76 + $(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp
\r
78 +LZMAEncoder.o: ../LZMA/LZMAEncoder.cpp
\r
79 + $(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp
\r
81 +LZInWindow.o: ../LZ/LZInWindow.cpp
\r
82 + $(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp
\r
84 +LZOutWindow.o: ../LZ/LZOutWindow.cpp
\r
85 + $(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp
\r
87 +RangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp
\r
88 + $(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp
\r
90 +InBuffer.o: ../../Common/InBuffer.cpp
\r
91 + $(CXX) $(CFLAGS) ../../Common/InBuffer.cpp
\r
93 +OutBuffer.o: ../../Common/OutBuffer.cpp
\r
94 + $(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp
\r
96 +FileStreams.o: ../../Common/FileStreams.cpp
\r
97 + $(CXX) $(CFLAGS) ../../Common/FileStreams.cpp
\r
99 +Alloc.o: ../../../Common/Alloc.cpp
\r
100 + $(CXX) $(CFLAGS) ../../../Common/Alloc.cpp
\r
102 +C_FileIO.o: ../../../Common/C_FileIO.cpp
\r
103 + $(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp
\r
105 +CommandLineParser.o: ../../../Common/CommandLineParser.cpp
\r
106 + $(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp
\r
108 +CRC.o: ../../../Common/CRC.cpp
\r
109 + $(CXX) $(CFLAGS) ../../../Common/CRC.cpp
\r
111 +MyWindows.o: ../../../Common/MyWindows.cpp
\r
112 + $(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp
\r
114 +String.o: ../../../Common/String.cpp
\r
115 + $(CXX) $(CFLAGS) ../../../Common/String.cpp
\r
117 +StringConvert.o: ../../../Common/StringConvert.cpp
\r
118 + $(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp
\r
120 +StringToInt.o: ../../../Common/StringToInt.cpp
\r
121 + $(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp
\r
123 +Vector.o: ../../../Common/Vector.cpp
\r
124 + $(CXX) $(CFLAGS) ../../../Common/Vector.cpp
\r
127 + -$(RM) $(PROG) $(OBJS)
\r
129 diff -BurN lzma406/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp lzma/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp
130 --- lzma406/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp 1970-01-01 03:00:00.000000000 +0300
131 +++ lzma/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp 2005-01-20 15:01:18.439221129 +0300
134 + * lzma zlib simplified wrapper
\r
136 + * Copyright (c) 2005 Oleg I. Vdovikin <oleg@cs.msu.su>
\r
138 + * This library is free software; you can redistribute
\r
139 + * it and/or modify it under the terms of the GNU Lesser
\r
140 + * General Public License as published by the Free Software
\r
141 + * Foundation; either version 2.1 of the License, or
\r
142 + * (at your option) any later version.
\r
144 + * This library is distributed in the hope that it will be
\r
145 + * useful, but WITHOUT ANY WARRANTY; without even the implied
\r
146 + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
147 + * PURPOSE. See the GNU Lesser General Public License
\r
148 + * for more details.
\r
150 + * You should have received a copy of the GNU Lesser General
\r
151 + * Public License along with this library; if not, write to
\r
152 + * the Free Software Foundation, Inc., 59 Temple Place,
\r
153 + * Suite 330, Boston, MA 02111-1307 USA
\r
157 + * default values for encoder/decoder used by wrapper
\r
167 +#include <initguid.h>
\r
172 +#include "../../../Common/MyWindows.h"
\r
173 +#include "../LZMA/LZMADecoder.h"
\r
174 +#include "../LZMA/LZMAEncoder.h"
\r
176 +#define STG_E_SEEKERROR ((HRESULT)0x80030019L)
\r
177 +#define STG_E_MEDIUMFULL ((HRESULT)0x80030070L)
\r
179 +class CInMemoryStream:
\r
180 + public IInStream,
\r
181 + public IStreamGetSize,
\r
182 + public CMyUnknownImp
\r
185 + CInMemoryStream(const Bytef *data, UInt64 size) :
\r
186 + m_data(data), m_size(size), m_offset(0) {}
\r
188 + virtual ~CInMemoryStream() {}
\r
190 + MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)
\r
192 + STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)
\r
194 + if (size > m_size - m_offset)
\r
195 + size = m_size - m_offset;
\r
198 + memcpy(data, m_data + m_offset, size);
\r
201 + m_offset += size;
\r
203 + if (processedSize)
\r
204 + *processedSize = size;
\r
209 + STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)
\r
211 + return Read(data, size, processedSize);
\r
214 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
\r
218 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
\r
219 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
\r
220 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
\r
221 + else return STG_E_INVALIDFUNCTION;
\r
223 + if (_offset < 0 || _offset > m_size)
\r
224 + return STG_E_SEEKERROR;
\r
226 + m_offset = _offset;
\r
229 + *newPosition = m_offset;
\r
234 + STDMETHOD(GetSize)(UInt64 *size)
\r
240 + const Bytef *m_data;
\r
245 +class COutMemoryStream:
\r
246 + public IOutStream,
\r
247 + public CMyUnknownImp
\r
250 + COutMemoryStream(Bytef *data, UInt64 maxsize) :
\r
251 + m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}
\r
252 + virtual ~COutMemoryStream() {}
\r
254 + MY_UNKNOWN_IMP1(IOutStream)
\r
256 + STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)
\r
258 + if (size > m_maxsize - m_offset)
\r
259 + size = m_maxsize - m_offset;
\r
262 + memcpy(m_data + m_offset, data, size);
\r
265 + m_offset += size;
\r
267 + if (m_offset > m_size)
\r
268 + m_size = m_offset;
\r
270 + if (processedSize)
\r
271 + *processedSize = size;
\r
276 + STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)
\r
278 + return Write(data, size, processedSize);
\r
281 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
\r
285 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
\r
286 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
\r
287 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
\r
288 + else return STG_E_INVALIDFUNCTION;
\r
290 + if (_offset < 0 || _offset > m_maxsize)
\r
291 + return STG_E_SEEKERROR;
\r
293 + m_offset = _offset;
\r
296 + *newPosition = m_offset;
\r
301 + STDMETHOD(SetSize)(Int64 newSize)
\r
303 + if ((UInt64)newSize > m_maxsize)
\r
304 + return STG_E_MEDIUMFULL;
\r
311 + UInt64 m_maxsize;
\r
315 +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
\r
316 + const Bytef *source, uLong sourceLen,
\r
319 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
\r
320 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
\r
322 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
\r
323 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
\r
325 + NCompress::NLZMA::CEncoder *encoderSpec =
\r
326 + new NCompress::NLZMA::CEncoder;
\r
327 + CMyComPtr<ICompressCoder> encoder = encoderSpec;
\r
329 + PROPID propIDs[] =
\r
331 + NCoderPropID::kDictionarySize,
\r
332 + NCoderPropID::kPosStateBits,
\r
333 + NCoderPropID::kLitContextBits,
\r
334 + NCoderPropID::kLitPosBits,
\r
335 + NCoderPropID::kAlgorithm,
\r
336 + NCoderPropID::kNumFastBytes,
\r
337 + NCoderPropID::kMatchFinder,
\r
338 + NCoderPropID::kEndMarker
\r
340 + const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
\r
342 + PROPVARIANT properties[kNumProps];
\r
343 + for (int p = 0; p < 6; p++)
\r
344 + properties[p].vt = VT_UI4;
\r
345 + properties[0].ulVal = UInt32(1 << (level + 14));
\r
346 + properties[1].ulVal = UInt32(ZLIB_PB);
\r
347 + properties[2].ulVal = UInt32(ZLIB_LC); // for normal files
\r
348 + properties[3].ulVal = UInt32(ZLIB_LP); // for normal files
\r
349 + properties[4].ulVal = UInt32(2);
\r
350 + properties[5].ulVal = UInt32(128);
\r
352 + properties[6].vt = VT_BSTR;
\r
353 + properties[6].bstrVal = (BSTR)(const wchar_t *)L"BT4";
\r
355 + properties[7].vt = VT_BOOL;
\r
356 + properties[7].boolVal = VARIANT_TRUE;
\r
358 + if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
\r
359 + return Z_MEM_ERROR; // should not happen
\r
361 + HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);
\r
362 + if (result == E_OUTOFMEMORY)
\r
364 + return Z_MEM_ERROR;
\r
366 + else if (result != S_OK)
\r
368 + return Z_BUF_ERROR; // should not happen
\r
372 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
\r
373 + *destLen = fileSize;
\r
378 +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
\r
379 + const Bytef *source, uLong sourceLen))
\r
381 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
\r
382 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
\r
384 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
\r
385 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
\r
387 + NCompress::NLZMA::CDecoder *decoderSpec =
\r
388 + new NCompress::NLZMA::CDecoder;
\r
389 + CMyComPtr<ICompressCoder> decoder = decoderSpec;
\r
391 + if (decoderSpec->SetDecoderPropertiesRaw(ZLIB_LC,
\r
392 + ZLIB_LP, ZLIB_PB, (1 << 23)) != S_OK) return Z_DATA_ERROR;
\r
394 + UInt64 fileSize = *destLen;
\r
396 + if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)
\r
398 + return Z_DATA_ERROR;
\r
401 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
\r
402 + *destLen = fileSize;
\r