summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2018-03-31 20:38:15 +0200
committerDidier Raboud <odyx@debian.org>2018-03-31 20:38:15 +0200
commit79c4eae72cbe0760878e0100fc7d6a73904c6d12 (patch)
tree4766bd8c6d691ff1ea50ed1b6bc94dd794a3ab5d /Source
parentac50ae59d3d1fed68f8d1bee90507f85e009fb57 (diff)
Import Upstream version 2.25
Diffstat (limited to 'Source')
-rwxr-xr-xSource/7zip/7zGuids.cpp17
-rwxr-xr-xSource/7zip/7zip/Common/InBuffer.cpp42
-rwxr-xr-xSource/7zip/7zip/Common/InBuffer.h35
-rwxr-xr-xSource/7zip/7zip/Common/OutBuffer.cpp105
-rwxr-xr-xSource/7zip/7zip/Common/OutBuffer.h60
-rwxr-xr-xSource/7zip/7zip/Common/StdAfx.h2
-rwxr-xr-xSource/7zip/7zip/Common/StreamUtils.cpp59
-rwxr-xr-xSource/7zip/7zip/Common/StreamUtils.h26
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTree.h119
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTree2.h31
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTree3.h33
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTree3Z.h28
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTree3ZMain.h17
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTree4.h33
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTree4b.h17
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTreeMF.h17
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTreeMFMain.h17
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h735
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/IMatchFinder.h68
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/LZInWindow.cpp43
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/LZInWindow.h42
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/LZOutWindow.cpp92
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/LZOutWindow.h72
-rwxr-xr-xSource/7zip/7zip/Compress/LZ/StdAfx.h2
-rwxr-xr-xSource/7zip/7zip/Compress/LZMA/LZMA.h18
-rwxr-xr-xSource/7zip/7zip/Compress/LZMA/LZMAEncoder.cpp1030
-rwxr-xr-xSource/7zip/7zip/Compress/LZMA/LZMAEncoder.h153
-rwxr-xr-xSource/7zip/7zip/Compress/LZMA/StdAfx.h4
-rwxr-xr-xSource/7zip/7zip/Compress/RangeCoder/RangeCoder.h106
-rwxr-xr-xSource/7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp17
-rwxr-xr-xSource/7zip/7zip/Compress/RangeCoder/RangeCoderBit.h25
-rwxr-xr-xSource/7zip/7zip/Compress/RangeCoder/RangeCoderBitTree.h51
-rwxr-xr-xSource/7zip/7zip/Compress/RangeCoder/RangeCoderOpt.h17
-rwxr-xr-xSource/7zip/7zip/Compress/RangeCoder/StdAfx.h4
-rwxr-xr-xSource/7zip/7zip/ICoder.h144
-rwxr-xr-xSource/7zip/7zip/IStream.h108
-rwxr-xr-xSource/7zip/Common/Alloc.cpp125
-rwxr-xr-xSource/7zip/Common/Alloc.h42
-rwxr-xr-xSource/7zip/Common/CRC.cpp35
-rwxr-xr-xSource/7zip/Common/CRC.h31
-rwxr-xr-xSource/7zip/Common/Defs.h17
-rwxr-xr-xSource/7zip/Common/MyCom.h27
-rwxr-xr-xSource/7zip/Common/MyGuidDef.h69
-rwxr-xr-xSource/7zip/Common/MyUnknown.h20
-rwxr-xr-xSource/7zip/Common/MyWindows.h137
-rwxr-xr-xSource/7zip/Common/StdAfx.h19
-rwxr-xr-xSource/7zip/Common/Types.h55
-rwxr-xr-xSource/7zip/LZMADecode.c21
-rwxr-xr-xSource/7zip/LZMADecode.h30
-rwxr-xr-xSource/7zip/copying.txt504
-rwxr-xr-xSource/7zip/readme.txt32
-rwxr-xr-xSource/7zip/sdk.diff167
-rwxr-xr-xSource/DialogTemplate.cpp94
-rwxr-xr-xSource/DialogTemplate.h46
-rwxr-xr-xSource/Platform.h92
-rwxr-xr-xSource/Plugins.cpp16
-rwxr-xr-xSource/Plugins.h16
-rwxr-xr-xSource/ResourceEditor.cpp231
-rwxr-xr-xSource/ResourceEditor.h68
-rwxr-xr-xSource/ResourceVersionInfo.cpp46
-rwxr-xr-xSource/ResourceVersionInfo.h18
-rwxr-xr-xSource/SConscript9
-rwxr-xr-xSource/ShConstants.cpp16
-rwxr-xr-xSource/ShConstants.h16
-rwxr-xr-xSource/Tests/SConscript73
-rwxr-xr-xSource/Tests/compression.cpp154
-rwxr-xr-xSource/Tests/decompress.cpp62
-rwxr-xr-xSource/Tests/decompress.h66
-rwxr-xr-xSource/Tests/endian.cpp2
-rwxr-xr-xSource/Tests/memcpy.c11
-rwxr-xr-xSource/Tests/mmap.cpp5
-rwxr-xr-xSource/Tests/preprocessor.nsi87
-rwxr-xr-xSource/Tests/textrunner.cpp2
-rwxr-xr-xSource/Tests/winchar.cpp126
-rwxr-xr-xSource/afxres.h16
-rwxr-xr-xSource/build.cpp221
-rwxr-xr-xSource/build.h38
-rwxr-xr-xSource/bzip2/Readme.txt4
-rwxr-xr-xSource/bzip2/blocksort.c18
-rwxr-xr-xSource/bzip2/bzlib.c18
-rwxr-xr-xSource/bzip2/bzlib.h20
-rwxr-xr-xSource/bzip2/compress.c15
-rwxr-xr-xSource/bzip2/decompress.c18
-rwxr-xr-xSource/bzip2/huffman.c17
-rwxr-xr-xSource/cbzip2.h24
-rwxr-xr-xSource/clzma.cpp18
-rwxr-xr-xSource/clzma.h16
-rwxr-xr-xSource/compressor.h18
-rwxr-xr-xSource/crc32.c16
-rwxr-xr-xSource/crc32.h16
-rwxr-xr-xSource/czlib.h16
-rwxr-xr-xSource/dirreader.cpp16
-rwxr-xr-xSource/dirreader.h16
-rwxr-xr-xSource/exehead/Main.c115
-rwxr-xr-xSource/exehead/Ui.c65
-rwxr-xr-xSource/exehead/afxres.h16
-rwxr-xr-xSource/exehead/bgbg.c16
-rwxr-xr-xSource/exehead/components.c16
-rwxr-xr-xSource/exehead/components.h16
-rwxr-xr-xSource/exehead/config.h16
-rwxr-xr-xSource/exehead/exec.c52
-rwxr-xr-xSource/exehead/exec.h16
-rwxr-xr-xSource/exehead/fileform.c38
-rwxr-xr-xSource/exehead/fileform.h24
-rwxr-xr-xSource/exehead/lang.h16
-rwxr-xr-xSource/exehead/state.h16
-rwxr-xr-xSource/exehead/ui.h17
-rwxr-xr-xSource/exehead/util.c118
-rwxr-xr-xSource/exehead/util.h18
-rwxr-xr-xSource/fileform.cpp24
-rwxr-xr-xSource/fileform.h16
-rwxr-xr-xSource/growbuf.cpp16
-rwxr-xr-xSource/growbuf.h16
-rwxr-xr-xSource/lang.cpp60
-rwxr-xr-xSource/lang.h16
-rwxr-xr-xSource/lineparse.cpp45
-rwxr-xr-xSource/lineparse.h22
-rwxr-xr-xSource/makenssi.cpp129
-rwxr-xr-xSource/manifest.cpp67
-rwxr-xr-xSource/manifest.h41
-rwxr-xr-xSource/mmap.cpp25
-rwxr-xr-xSource/mmap.h24
-rwxr-xr-xSource/script.cpp285
-rwxr-xr-xSource/strlist.cpp20
-rwxr-xr-xSource/strlist.h16
-rwxr-xr-xSource/tokens.cpp136
-rwxr-xr-xSource/tokens.h17
-rwxr-xr-xSource/uservars.h16
-rwxr-xr-xSource/util.cpp24
-rwxr-xr-xSource/util.h16
-rwxr-xr-xSource/winchar.cpp126
-rwxr-xr-xSource/winchar.h26
-rwxr-xr-xSource/writer.cpp16
-rwxr-xr-xSource/writer.h16
-rwxr-xr-xSource/zlib/DEFLATE.H13
-rwxr-xr-xSource/zlib/INFBLOCK.C21
-rwxr-xr-xSource/zlib/ZCONF.H15
-rwxr-xr-xSource/zlib/ZLIB.H23
-rwxr-xr-xSource/zlib/ZUTIL.H45
-rwxr-xr-xSource/zlib/deflate.c13
-rwxr-xr-xSource/zlib/trees.c13
141 files changed, 5506 insertions, 2944 deletions
diff --git a/Source/7zip/7zGuids.cpp b/Source/7zip/7zGuids.cpp
index 5fa5a87..f076b0f 100755
--- a/Source/7zip/7zGuids.cpp
+++ b/Source/7zip/7zGuids.cpp
@@ -1,3 +1,20 @@
+/*
+ * 7zGuids.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
// DLLExports.cpp
// #include "StdAfx.h"
diff --git a/Source/7zip/7zip/Common/InBuffer.cpp b/Source/7zip/7zip/Common/InBuffer.cpp
index 7484643..4d99f5c 100755
--- a/Source/7zip/7zip/Common/InBuffer.cpp
+++ b/Source/7zip/7zip/Common/InBuffer.cpp
@@ -1,4 +1,19 @@
-// InBuffer.cpp
+/*
+ * InBuffer.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "StdAfx.h"
@@ -7,11 +22,11 @@
#include "../../Common/Alloc.h"
CInBuffer::CInBuffer():
- _bufferBase(0),
- _bufferSize(0),
_buffer(0),
_bufferLimit(0),
- _stream(0)
+ _bufferBase(0),
+ _stream(0),
+ _bufferSize(0)
{}
bool CInBuffer::Create(UInt32 bufferSize)
@@ -23,19 +38,23 @@ bool CInBuffer::Create(UInt32 bufferSize)
return true;
Free();
_bufferSize = bufferSize;
- _bufferBase = (Byte *)::BigAlloc(bufferSize);
+ _bufferBase = (Byte *)::MidAlloc(bufferSize);
return (_bufferBase != 0);
}
void CInBuffer::Free()
{
- BigFree(_bufferBase);
+ ::MidFree(_bufferBase);
_bufferBase = 0;
}
-void CInBuffer::Init(ISequentialInStream *stream)
+void CInBuffer::SetStream(ISequentialInStream *stream)
{
_stream = stream;
+}
+
+void CInBuffer::Init()
+{
_processedSize = 0;
_buffer = _bufferBase;
_bufferLimit = _buffer;
@@ -55,7 +74,7 @@ bool CInBuffer::ReadBlock()
return false;
_processedSize += (_buffer - _bufferBase);
UInt32 numProcessedBytes;
- HRESULT result = _stream->ReadPart(_bufferBase, _bufferSize, &numProcessedBytes);
+ HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);
#ifdef _NO_EXCEPTIONS
ErrorCode = result;
#else
@@ -67,3 +86,10 @@ bool CInBuffer::ReadBlock()
_wasFinished = (numProcessedBytes == 0);
return (!_wasFinished);
}
+
+Byte CInBuffer::ReadBlock2()
+{
+ if(!ReadBlock())
+ return 0xFF;
+ return *_buffer++;
+}
diff --git a/Source/7zip/7zip/Common/InBuffer.h b/Source/7zip/7zip/Common/InBuffer.h
index 57ea349..797875f 100755
--- a/Source/7zip/7zip/Common/InBuffer.h
+++ b/Source/7zip/7zip/Common/InBuffer.h
@@ -1,9 +1,25 @@
-// InBuffer.h
+/*
+ * InBuffer.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __INBUFFER_H
#define __INBUFFER_H
#include "../IStream.h"
+#include "../../Common/MyCom.h"
#ifndef _NO_EXCEPTIONS
class CInBufferException
@@ -16,15 +32,16 @@ public:
class CInBuffer
{
- UInt64 _processedSize;
- Byte *_bufferBase;
- UInt32 _bufferSize;
Byte *_buffer;
Byte *_bufferLimit;
- ISequentialInStream *_stream;
+ Byte *_bufferBase;
+ CMyComPtr<ISequentialInStream> _stream;
+ UInt64 _processedSize;
+ UInt32 _bufferSize;
bool _wasFinished;
bool ReadBlock();
+ Byte ReadBlock2();
public:
#ifdef _NO_EXCEPTIONS
@@ -37,8 +54,9 @@ public:
bool Create(UInt32 bufferSize);
void Free();
- void Init(ISequentialInStream *stream);
- // void ReleaseStream() { _stream.Release(); }
+ void SetStream(ISequentialInStream *stream);
+ void Init();
+ void ReleaseStream() { _stream.Release(); }
bool ReadByte(Byte &b)
{
@@ -51,8 +69,7 @@ public:
Byte ReadByte()
{
if(_buffer >= _bufferLimit)
- if(!ReadBlock())
- return 0xFF;
+ return ReadBlock2();
return *_buffer++;
}
void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
diff --git a/Source/7zip/7zip/Common/OutBuffer.cpp b/Source/7zip/7zip/Common/OutBuffer.cpp
index d557956..09bed1b 100755
--- a/Source/7zip/7zip/Common/OutBuffer.cpp
+++ b/Source/7zip/7zip/Common/OutBuffer.cpp
@@ -1,4 +1,19 @@
-// OutByte.cpp
+/*
+ * OutBuffer.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "StdAfx.h"
@@ -15,48 +30,98 @@ bool COutBuffer::Create(UInt32 bufferSize)
return true;
Free();
_bufferSize = bufferSize;
- _buffer = (Byte *)::BigAlloc(bufferSize);
+ _buffer = (Byte *)::MidAlloc(bufferSize);
return (_buffer != 0);
}
void COutBuffer::Free()
{
- BigFree(_buffer);
+ ::MidFree(_buffer);
_buffer = 0;
}
-void COutBuffer::Init(ISequentialOutStream *stream)
+void COutBuffer::SetStream(ISequentialOutStream *stream)
{
_stream = stream;
- _processedSize = 0;
+}
+
+void COutBuffer::Init()
+{
+ _streamPos = 0;
+ _limitPos = _bufferSize;
_pos = 0;
+ _processedSize = 0;
+ _overDict = false;
#ifdef _NO_EXCEPTIONS
ErrorCode = S_OK;
#endif
}
-HRESULT COutBuffer::Flush()
+UInt64 COutBuffer::GetProcessedSize() const
+{
+ UInt64 res = _processedSize + _pos - _streamPos;
+ if (_streamPos > _pos)
+ res += _bufferSize;
+ return res;
+}
+
+
+HRESULT COutBuffer::FlushPart()
{
- if (_pos == 0)
- return S_OK;
- UInt32 processedSize;
- HRESULT result = _stream->Write(_buffer, _pos, &processedSize);
- if (result != S_OK)
- return result;
- if (_pos != processedSize)
- return E_FAIL;
- _processedSize += processedSize;
- _pos = 0;
- return S_OK;
+ // _streamPos < _bufferSize
+ UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);
+ HRESULT result = S_OK;
+ #ifdef _NO_EXCEPTIONS
+ result = ErrorCode;
+ #endif
+ if (_buffer2 != 0)
+ {
+ memmove(_buffer2, _buffer + _streamPos, size);
+ _buffer2 += size;
+ }
+
+ if (_stream != 0
+ #ifdef _NO_EXCEPTIONS
+ && (ErrorCode == S_OK)
+ #endif
+ )
+ {
+ UInt32 processedSize = 0;
+ result = _stream->Write(_buffer + _streamPos, size, &processedSize);
+ size = processedSize;
+ }
+ _streamPos += size;
+ if (_streamPos == _bufferSize)
+ _streamPos = 0;
+ if (_pos == _bufferSize)
+ {
+ _overDict = true;
+ _pos = 0;
+ }
+ _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;
+ _processedSize += size;
+ return result;
}
-void COutBuffer::WriteBlock()
+HRESULT COutBuffer::Flush()
{
#ifdef _NO_EXCEPTIONS
if (ErrorCode != S_OK)
- return;
+ return ErrorCode;
#endif
- HRESULT result = Flush();
+
+ while(_streamPos != _pos)
+ {
+ HRESULT result = FlushPart();
+ if (result != S_OK)
+ return result;
+ }
+ return S_OK;
+}
+
+void COutBuffer::FlushWithCheck()
+{
+ HRESULT result = FlushPart();
#ifdef _NO_EXCEPTIONS
ErrorCode = result;
#else
diff --git a/Source/7zip/7zip/Common/OutBuffer.h b/Source/7zip/7zip/Common/OutBuffer.h
index c775eba..34915b7 100755
--- a/Source/7zip/7zip/Common/OutBuffer.h
+++ b/Source/7zip/7zip/Common/OutBuffer.h
@@ -1,9 +1,25 @@
-// OutBuffer.h
+/*
+ * OutBuffer.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __OUTBUFFER_H
#define __OUTBUFFER_H
#include "../IStream.h"
+#include "../../Common/MyCom.h"
#ifndef _NO_EXCEPTIONS
struct COutBufferException
@@ -15,55 +31,49 @@ struct COutBufferException
class COutBuffer
{
+protected:
Byte *_buffer;
UInt32 _pos;
+ UInt32 _limitPos;
+ UInt32 _streamPos;
UInt32 _bufferSize;
- ISequentialOutStream *_stream;
+ CMyComPtr<ISequentialOutStream> _stream;
UInt64 _processedSize;
+ Byte *_buffer2;
+ bool _overDict;
- void WriteBlock();
+ HRESULT FlushPart();
+ void FlushWithCheck();
public:
#ifdef _NO_EXCEPTIONS
HRESULT ErrorCode;
#endif
- COutBuffer(): _buffer(0), _pos(0), _stream(0) {}
+ COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
~COutBuffer() { Free(); }
bool Create(UInt32 bufferSize);
void Free();
- void Init(ISequentialOutStream *stream);
+ void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
+ void SetStream(ISequentialOutStream *stream);
+ void Init();
HRESULT Flush();
- // void ReleaseStream(); { _stream.Release(); }
-
- /*
- void *GetBuffer(UInt32 &sizeAvail)
- {
- sizeAvail = _bufferSize - _pos;
- return _buffer + _pos;
- }
- void MovePos(UInt32 num)
- {
- _pos += num;
- if(_pos >= _bufferSize)
- WriteBlock();
- }
- */
+ void ReleaseStream() { _stream.Release(); }
void WriteByte(Byte b)
{
_buffer[_pos++] = b;
- if(_pos >= _bufferSize)
- WriteBlock();
+ if(_pos == _limitPos)
+ FlushWithCheck();
}
- void WriteBytes(const void *data, UInt32 size)
+ void WriteBytes(const void *data, size_t size)
{
- for (UInt32 i = 0; i < size; i++)
+ for (size_t i = 0; i < size; i++)
WriteByte(((const Byte *)data)[i]);
}
- UInt64 GetProcessedSize() const { return _processedSize + _pos; }
+ UInt64 GetProcessedSize() const;
};
#endif
diff --git a/Source/7zip/7zip/Common/StdAfx.h b/Source/7zip/7zip/Common/StdAfx.h
index 783d444..8e1b1ea 100755
--- a/Source/7zip/7zip/Common/StdAfx.h
+++ b/Source/7zip/7zip/Common/StdAfx.h
@@ -3,6 +3,6 @@
#ifndef __STDAFX_H
#define __STDAFX_H
-#include "../../../Platform.h"
+#include "../../Common/MyWindows.h"
#endif
diff --git a/Source/7zip/7zip/Common/StreamUtils.cpp b/Source/7zip/7zip/Common/StreamUtils.cpp
new file mode 100755
index 0000000..ad77344
--- /dev/null
+++ b/Source/7zip/7zip/Common/StreamUtils.cpp
@@ -0,0 +1,59 @@
+/*
+ * StreamUtils.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#include "StdAfx.h"
+
+#include "../../Common/MyCom.h"
+#include "StreamUtils.h"
+
+HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)
+{
+ if (processedSize != 0)
+ *processedSize = 0;
+ while(size != 0)
+ {
+ UInt32 processedSizeLoc;
+ HRESULT res = stream->Read(data, size, &processedSizeLoc);
+ if (processedSize != 0)
+ *processedSize += processedSizeLoc;
+ data = (Byte *)((Byte *)data + processedSizeLoc);
+ size -= processedSizeLoc;
+ RINOK(res);
+ if (processedSizeLoc == 0)
+ return S_OK;
+ }
+ return S_OK;
+}
+
+HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)
+{
+ if (processedSize != 0)
+ *processedSize = 0;
+ while(size != 0)
+ {
+ UInt32 processedSizeLoc;
+ HRESULT res = stream->Write(data, size, &processedSizeLoc);
+ if (processedSize != 0)
+ *processedSize += processedSizeLoc;
+ data = (const void *)((const Byte *)data + processedSizeLoc);
+ size -= processedSizeLoc;
+ RINOK(res);
+ if (processedSizeLoc == 0)
+ break;
+ }
+ return S_OK;
+}
diff --git a/Source/7zip/7zip/Common/StreamUtils.h b/Source/7zip/7zip/Common/StreamUtils.h
new file mode 100755
index 0000000..58b8141
--- /dev/null
+++ b/Source/7zip/7zip/Common/StreamUtils.h
@@ -0,0 +1,26 @@
+/*
+ * StreamUtils.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#ifndef __STREAMUTILS_H
+#define __STREAMUTILS_H
+
+#include "../IStream.h"
+
+HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);
+HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);
+
+#endif
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree.h
index 50a7058..186adab 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree.h
@@ -1,92 +1,69 @@
-// BinTree.h
-
-// #ifndef __BINTREE_H
-// #define __BINTREE_H
+/*
+ * BinTree.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "../LZInWindow.h"
+#include "../IMatchFinder.h"
namespace BT_NAMESPACE {
typedef UInt32 CIndex;
const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;
-// #define HASH_ARRAY_2
-
-// #ifdef HASH_ARRAY_2
-
-// #define HASH_ARRAY_3
-
-// #else
-
-// #define HASH_ZIP
-
-// #endif
-
-struct CPair
-{
- CIndex Left;
- CIndex Right;
-};
-
-/*
-const int kNumBundleBits = 2;
-const UInt32 kNumPairsInBundle = 1 << kNumBundleBits;
-const UInt32 kBundleMask = kNumPairsInBundle - 1;
-const UInt32 kNumBundleBytes = kNumPairsInBundle * sizeof(CPair);
-
-struct CBundle
-{
- CPair Pairs[kNumPairsInBundle];
- Byte Bytes[kNumBundleBytes];
-};
-*/
-
-class CInTree: public CLZInWindow
+class CMatchFinder:
+ public IMatchFinder,
+ public CLZInWindow,
+ public CMyUnknownImp,
+ public IMatchFinderSetNumPasses
{
UInt32 _cyclicBufferPos;
- UInt32 _cyclicBufferSize;
- UInt32 _historySize;
+ UInt32 _cyclicBufferSize; // it must be historySize + 1
UInt32 _matchMaxLen;
-
CIndex *_hash;
-
- #ifdef HASH_ARRAY_2
- CIndex *_hash2;
- #ifdef HASH_ARRAY_3
- CIndex *_hash3;
- #endif
- #endif
-
- // CBundle *_son;
- CPair *_son;
-
+ CIndex *_son;
+ UInt32 _hashMask;
UInt32 _cutValue;
+ UInt32 _hashSizeSum;
- void NormalizeLinks(CIndex *items, UInt32 numItems, UInt32 subValue);
void Normalize();
+ void FreeThisClassMemory();
void FreeMemory();
+ MY_UNKNOWN_IMP
+
+ STDMETHOD(SetStream)(ISequentialInStream *inStream);
+ STDMETHOD_(void, ReleaseStream)();
+ STDMETHOD(Init)();
+ HRESULT MovePos();
+ STDMETHOD_(Byte, GetIndexByte)(Int32 index);
+ STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
+ STDMETHOD_(UInt32, GetNumAvailableBytes)();
+ STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
+ STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes);
+ STDMETHOD_(void, ChangeBufferPos)();
+
+ STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
+ UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
+ STDMETHOD(GetMatches)(UInt32 *distances);
+ STDMETHOD(Skip)(UInt32 num);
+
public:
- CInTree();
- ~CInTree();
- HRESULT Create(UInt32 sizeHistory, UInt32 keepAddBufferBefore, UInt32 matchMaxLen,
- UInt32 keepAddBufferAfter, UInt32 sizeReserv = (1<<17));
- HRESULT Init(ISequentialInStream *stream);
- void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }
- UInt32 GetLongestMatch(UInt32 *distances);
- void DummyLongestMatch();
- HRESULT MovePos()
- {
- _cyclicBufferPos++;
- if (_cyclicBufferPos >= _cyclicBufferSize)
- _cyclicBufferPos = 0;
- RINOK(CLZInWindow::MovePos());
- if (_pos == kMaxValForNormalize)
- Normalize();
- return S_OK;
- }
+ CMatchFinder();
+ virtual ~CMatchFinder();
+ virtual void SetNumPasses(UInt32 numPasses) { _cutValue = numPasses; }
};
}
-
-// #endif
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree2.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree2.h
index ee11916..2e2996a 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree2.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree2.h
@@ -1,16 +1,27 @@
-// BinTree2.h
+/*
+ * BinTree2.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
-#ifndef __BINTREE2__H
-#define __BINTREE2__H
+#ifndef __BINTREE2_H
+#define __BINTREE2_H
-#undef BT_CLSID
-#define BT_CLSID CLSID_CMatchFinderBT2
-
-#undef BT_NAMESPACE
#define BT_NAMESPACE NBT2
-#include "BinTreeMF.h"
-#include "BinTreeMFMain.h"
+#include "BinTreeMain.h"
-#endif
+#undef BT_NAMESPACE
+#endif
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3.h
index 9cd1ede..6b5b116 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3.h
@@ -1,20 +1,31 @@
-// BinTree3.h
+/*
+ * BinTree3.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#ifndef __BINTREE3_H
+#define __BINTREE3_H
-#ifndef __BINTREE3__H
-#define __BINTREE3__H
-
-#undef BT_CLSID
-#define BT_CLSID CLSID_CMatchFinderBT3
-
-#undef BT_NAMESPACE
#define BT_NAMESPACE NBT3
#define HASH_ARRAY_2
-#include "BinTreeMF.h"
-#include "BinTreeMFMain.h"
+#include "BinTreeMain.h"
#undef HASH_ARRAY_2
-#endif
+#undef BT_NAMESPACE
+#endif
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3Z.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3Z.h
index 6d56a3b..f21cdbd 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3Z.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3Z.h
@@ -1,17 +1,31 @@
-// BinTree3Z.h
+/*
+ * BinTree3Z.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
-#ifndef __BINTREE3Z__H
-#define __BINTREE3Z__H
+#ifndef __BINTREE3Z_H
+#define __BINTREE3Z_H
-#undef BT_NAMESPACE
#define BT_NAMESPACE NBT3Z
#define HASH_ZIP
-#include "BinTree.h"
-// #include "BinTreeMain.h"
+#include "BinTreeMain.h"
#undef HASH_ZIP
-#endif
+#undef BT_NAMESPACE
+#endif
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3ZMain.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3ZMain.h
index b15b96c..15a786c 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3ZMain.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree3ZMain.h
@@ -1,4 +1,19 @@
-// BinTree3ZMain.h
+/*
+ * BinTree3ZMain.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __BINTREE3ZMAIN__H
#define __BINTREE3ZMAIN__H
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree4.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree4.h
index 37ba84f..1b215a3 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree4.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree4.h
@@ -1,22 +1,33 @@
-// BinTree4.h
+/*
+ * BinTree4.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#ifndef __BINTREE4_H
+#define __BINTREE4_H
-#ifndef __BINTREE4__H
-#define __BINTREE4__H
-
-#undef BT_CLSID
-#define BT_CLSID CLSID_CMatchFinderBT4
-
-#undef BT_NAMESPACE
#define BT_NAMESPACE NBT4
#define HASH_ARRAY_2
#define HASH_ARRAY_3
-#include "BinTreeMF.h"
-#include "BinTreeMFMain.h"
+#include "BinTreeMain.h"
#undef HASH_ARRAY_2
#undef HASH_ARRAY_3
-#endif
+#undef BT_NAMESPACE
+#endif
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree4b.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree4b.h
index 16435cf..e7c23ca 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree4b.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree4b.h
@@ -1,4 +1,19 @@
-// BinTree4b.h
+/*
+ * BinTreeb.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __BINTREE4B__H
#define __BINTREE4B__H
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMF.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMF.h
index 21d0006..12b70f3 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMF.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMF.h
@@ -1,4 +1,19 @@
-// BinTreeMF.h
+/*
+ * BinTreeMF.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
// #ifndef __BINTREEMF_H
// #define __BINTREEMF_H
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMFMain.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMFMain.h
index 9eac74a..f72a89e 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMFMain.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMFMain.h
@@ -1,4 +1,19 @@
-// BinTreeMFMain.h
+/*
+ * BinTreeMFMain.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
// #include "StdAfx.h"
diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h
index f3e90d1..ed161c3 100755
--- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h
+++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h
@@ -1,166 +1,205 @@
-// BinTreeMain.h
+/*
+ * BinTreeMain.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "../../../../Common/Defs.h"
#include "../../../../Common/CRC.h"
#include "../../../../Common/Alloc.h"
+#include "BinTree.h"
+
+// #include <xmmintrin.h>
+// It's for prefetch
+// But prefetch doesn't give big gain in K8.
+
namespace BT_NAMESPACE {
#ifdef HASH_ARRAY_2
static const UInt32 kHash2Size = 1 << 10;
+ #define kNumHashDirectBytes 0
#ifdef HASH_ARRAY_3
- static const UInt32 kNumHashDirectBytes = 0;
static const UInt32 kNumHashBytes = 4;
- static const UInt32 kHash3Size = 1 << 18;
- #ifdef HASH_BIG
- static const UInt32 kHashSize = 1 << 23;
- #else
- static const UInt32 kHashSize = 1 << 20;
- #endif
+ static const UInt32 kHash3Size = 1 << 16;
#else
- static const UInt32 kNumHashDirectBytes = 3;
static const UInt32 kNumHashBytes = 3;
- static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
#endif
+ static const UInt32 kHashSize = 0;
+ static const UInt32 kMinMatchCheck = kNumHashBytes;
+ static const UInt32 kStartMaxLen = 1;
#else
#ifdef HASH_ZIP
- static const UInt32 kNumHashDirectBytes = 0;
+ #define kNumHashDirectBytes 0
static const UInt32 kNumHashBytes = 3;
static const UInt32 kHashSize = 1 << 16;
+ static const UInt32 kMinMatchCheck = kNumHashBytes;
+ static const UInt32 kStartMaxLen = 1;
#else
- static const UInt32 kNumHashDirectBytes = 2;
+ #define kNumHashDirectBytes 2
static const UInt32 kNumHashBytes = 2;
static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
+ static const UInt32 kMinMatchCheck = kNumHashBytes + 1;
+ static const UInt32 kStartMaxLen = 1;
#endif
#endif
+#ifdef HASH_ARRAY_2
+#ifdef HASH_ARRAY_3
+static const UInt32 kHash3Offset = kHash2Size;
+#endif
+#endif
-CInTree::CInTree():
- _hash(0),
- #ifdef HASH_ARRAY_2
- _hash2(0),
- #ifdef HASH_ARRAY_3
- _hash3(0),
- #endif
- #endif
- _son(0),
- _cutValue(0xFF)
+static const UInt32 kFixHashSize = 0
+ #ifdef HASH_ARRAY_2
+ + kHash2Size
+ #ifdef HASH_ARRAY_3
+ + kHash3Size
+ #endif
+ #endif
+ ;
+
+CMatchFinder::CMatchFinder():
+ _hash(0)
{
}
-void CInTree::FreeMemory()
+void CMatchFinder::FreeThisClassMemory()
{
- BigFree(_son);
- _son = 0;
BigFree(_hash);
_hash = 0;
+}
+
+void CMatchFinder::FreeMemory()
+{
+ FreeThisClassMemory();
CLZInWindow::Free();
}
-CInTree::~CInTree()
+CMatchFinder::~CMatchFinder()
{
FreeMemory();
}
-HRESULT CInTree::Create(UInt32 sizeHistory, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter, UInt32 sizeReserv)
+STDMETHODIMP CMatchFinder::Create(UInt32 historySize, UInt32 keepAddBufferBefore,
+ UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
{
- FreeMemory();
- if (!CLZInWindow::Create(sizeHistory + keepAddBufferBefore,
- matchMaxLen + keepAddBufferAfter, sizeReserv))
- return E_OUTOFMEMORY;
-
- if (_blockSize + 256 > kMaxValForNormalize)
- return E_INVALIDARG;
-
- _historySize = sizeHistory;
- _matchMaxLen = matchMaxLen;
-
- _cyclicBufferSize = sizeHistory + 1;
-
-
- UInt32 size = kHashSize;
- #ifdef HASH_ARRAY_2
- size += kHash2Size;
- #ifdef HASH_ARRAY_3
- size += kHash3Size;
- #endif
- #endif
-
- _son = (CPair *)BigAlloc((_cyclicBufferSize + 1) * sizeof(CPair));
- if (_son == 0)
+ if (historySize > kMaxValForNormalize - 256)
{
FreeMemory();
- return E_OUTOFMEMORY;
+ return E_INVALIDARG;
}
-
- // UInt32 numBundles = (_cyclicBufferSize + kNumPairsInBundle) >> kNumBundleBits;
- // _son = (CBundle *)::VirtualAlloc(0, numBundles * sizeof(CBundle), MEM_COMMIT, PAGE_READWRITE);
- _hash = (CIndex *)BigAlloc((size + 1) * sizeof(CIndex));
- if (_hash == 0)
+ _cutValue =
+ #ifdef _HASH_CHAIN
+ 8 + (matchMaxLen >> 2);
+ #else
+ 16 + (matchMaxLen >> 1);
+ #endif
+ UInt32 sizeReserv = (historySize + keepAddBufferBefore +
+ matchMaxLen + keepAddBufferAfter) / 2 + 256;
+ if (CLZInWindow::Create(historySize + keepAddBufferBefore,
+ matchMaxLen + keepAddBufferAfter, sizeReserv))
{
- FreeMemory();
- return E_OUTOFMEMORY;
+ _matchMaxLen = matchMaxLen;
+ UInt32 newCyclicBufferSize = historySize + 1;
+ if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)
+ return S_OK;
+ FreeThisClassMemory();
+ _cyclicBufferSize = newCyclicBufferSize; // don't change it
+
+ UInt32 hs = kHashSize;
+
+ #ifdef HASH_ARRAY_2
+ hs = historySize - 1;
+ hs |= (hs >> 1);
+ hs |= (hs >> 2);
+ hs |= (hs >> 4);
+ hs |= (hs >> 8);
+ hs >>= 1;
+ hs |= 0xFFFF;
+ if (hs > (1 << 24))
+ {
+ #ifdef HASH_ARRAY_3
+ hs >>= 1;
+ #else
+ hs = (1 << 24) - 1;
+ #endif
+ }
+ _hashMask = hs;
+ hs++;
+ #endif
+ _hashSizeSum = hs + kFixHashSize;
+ UInt32 numItems = _hashSizeSum + _cyclicBufferSize
+ #ifndef _HASH_CHAIN
+ * 2
+ #endif
+ ;
+ size_t sizeInBytes = (size_t)numItems * sizeof(CIndex);
+ if (sizeInBytes / sizeof(CIndex) != numItems)
+ return E_OUTOFMEMORY;
+ _hash = (CIndex *)BigAlloc(sizeInBytes);
+ _son = _hash + _hashSizeSum;
+ if (_hash != 0)
+ return S_OK;
}
-
- // _hash = &m_RightBase[_blockSize];
- #ifdef HASH_ARRAY_2
- _hash2 = &_hash[kHashSize];
- #ifdef HASH_ARRAY_3
- _hash3 = &_hash2[kHash2Size];
- #endif
- #endif
- return S_OK;
+ FreeMemory();
+ return E_OUTOFMEMORY;
}
static const UInt32 kEmptyHashValue = 0;
-HRESULT CInTree::Init(ISequentialInStream *stream)
+STDMETHODIMP CMatchFinder::SetStream(ISequentialInStream *stream)
{
- RINOK(CLZInWindow::Init(stream));
- UInt32 i;
- for(i = 0; i < kHashSize; i++)
- _hash[i] = kEmptyHashValue;
-
- #ifdef HASH_ARRAY_2
- for(i = 0; i < kHash2Size; i++)
- _hash2[i] = kEmptyHashValue;
- #ifdef HASH_ARRAY_3
- for(i = 0; i < kHash3Size; i++)
- _hash3[i] = kEmptyHashValue;
- #endif
- #endif
+ CLZInWindow::SetStream(stream);
+ return S_OK;
+}
+STDMETHODIMP CMatchFinder::Init()
+{
+ RINOK(CLZInWindow::Init());
+ for(UInt32 i = 0; i < _hashSizeSum; i++)
+ _hash[i] = kEmptyHashValue;
_cyclicBufferPos = 0;
-
ReduceOffsets(-1);
return S_OK;
}
+STDMETHODIMP_(void) CMatchFinder::ReleaseStream()
+{
+ // ReleaseStream();
+}
#ifdef HASH_ARRAY_2
#ifdef HASH_ARRAY_3
-inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)
-{
- UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];
- hash2Value = temp & (kHash2Size - 1);
- hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);
- return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) &
- (kHashSize - 1);
-}
+
+#define HASH_CALC { \
+ UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \
+ hash2Value = temp & (kHash2Size - 1); \
+ hash3Value = (temp ^ (UInt32(cur[2]) << 8)) & (kHash3Size - 1); \
+ hashValue = (temp ^ (UInt32(cur[2]) << 8) ^ (CCRC::Table[cur[3]] << 5)) & _hashMask; }
+
#else // no HASH_ARRAY_3
-inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)
-{
- hash2Value = (CCRC::Table[pointer[0]] ^ pointer[1]) & (kHash2Size - 1);
- return ((UInt32(pointer[0]) << 16)) | ((UInt32(pointer[1]) << 8)) | pointer[2];
-}
+#define HASH_CALC { \
+ UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \
+ hash2Value = temp & (kHash2Size - 1); \
+ hashValue = (temp ^ (UInt32(cur[2]) << 8)) & _hashMask; }
#endif // HASH_ARRAY_3
#else // no HASH_ARRAY_2
#ifdef HASH_ZIP
inline UInt32 Hash(const Byte *pointer)
{
- return ((UInt32(pointer[0]) << 8) ^
- CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);
+ return ((UInt32(pointer[0]) << 8) ^ CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);
}
#else // no HASH_ZIP
inline UInt32 Hash(const Byte *pointer)
@@ -170,7 +209,7 @@ inline UInt32 Hash(const Byte *pointer)
#endif // HASH_ZIP
#endif // HASH_ARRAY_2
-UInt32 CInTree::GetLongestMatch(UInt32 *distances)
+STDMETHODIMP CMatchFinder::GetMatches(UInt32 *distances)
{
UInt32 lenLimit;
if (_pos + _matchMaxLen <= _streamPos)
@@ -178,346 +217,288 @@ UInt32 CInTree::GetLongestMatch(UInt32 *distances)
else
{
lenLimit = _streamPos - _pos;
- if(lenLimit < kNumHashBytes)
- return 0;
+ if(lenLimit < kMinMatchCheck)
+ {
+ distances[0] = 0;
+ return MovePos();
+ }
}
- UInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;
- Byte *cur = _buffer + _pos;
+ int offset = 1;
- /*
- if ((_cyclicBufferPos & kBundleMask) == 0)
- {
- Byte *bytes = _son[_cyclicBufferPos >> kNumBundleBits].Bytes;
- UInt32 bundleLimit = kNumBundleBytes;
- if (bundleLimit > lenLimit)
- bundleLimit = lenLimit;
- for (UInt32 i = 0; i < bundleLimit; i++)
- bytes[i] = cur[i];
- }
- */
-
- UInt32 matchHashLenMax = 0;
+ UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
+ const Byte *cur = _buffer + _pos;
+
+ UInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;
#ifdef HASH_ARRAY_2
UInt32 hash2Value;
#ifdef HASH_ARRAY_3
UInt32 hash3Value;
- UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
- #else
- UInt32 hashValue = Hash(cur, hash2Value);
#endif
+ UInt32 hashValue;
+ HASH_CALC;
#else
UInt32 hashValue = Hash(cur);
#endif
- UInt32 curMatch = _hash[hashValue];
+ UInt32 curMatch = _hash[kFixHashSize + hashValue];
#ifdef HASH_ARRAY_2
- UInt32 curMatch2 = _hash2[hash2Value];
+ UInt32 curMatch2 = _hash[hash2Value];
#ifdef HASH_ARRAY_3
- UInt32 curMatch3 = _hash3[hash3Value];
+ UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];
#endif
- _hash2[hash2Value] = _pos;
- bool matchLen2Exist = false;
- UInt32 len2Distance = 0;
- if(curMatch2 >= matchMinPos)
- {
+ _hash[hash2Value] = _pos;
+ if(curMatch2 > matchMinPos)
if (_buffer[curMatch2] == cur[0])
{
- len2Distance = _pos - curMatch2 - 1;
- matchHashLenMax = 2;
- matchLen2Exist = true;
+ distances[offset++] = maxLen = 2;
+ distances[offset++] = _pos - curMatch2 - 1;
}
- }
#ifdef HASH_ARRAY_3
- _hash3[hash3Value] = _pos;
- UInt32 matchLen3Exist = false;
- UInt32 len3Distance = 0;
- if(curMatch3 >= matchMinPos)
- {
+ _hash[kHash3Offset + hash3Value] = _pos;
+ if(curMatch3 > matchMinPos)
if (_buffer[curMatch3] == cur[0])
{
- len3Distance = _pos - curMatch3 - 1;
- matchHashLenMax = 3;
- matchLen3Exist = true;
- if (matchLen2Exist)
- {
- if (len3Distance < len2Distance)
- len2Distance = len3Distance;
- }
- else
- {
- len2Distance = len3Distance;
- matchLen2Exist = true;
- }
+ if (curMatch3 == curMatch2)
+ offset -= 2;
+ distances[offset++] = maxLen = 3;
+ distances[offset++] = _pos - curMatch3 - 1;
+ curMatch2 = curMatch3;
}
- }
- #endif
#endif
-
- _hash[hashValue] = _pos;
-
- // UInt32 bi = _cyclicBufferPos >> kNumBundleBits;
- // UInt32 bo = _cyclicBufferPos & kBundleMask;
- // CPair &pair = _son[bi].Pairs[bo];
- CPair &pair = _son[_cyclicBufferPos];
- if(curMatch < matchMinPos)
+ if (offset != 1 && curMatch2 == curMatch)
{
- pair.Left = kEmptyHashValue;
- pair.Right = kEmptyHashValue;
+ offset -= 2;
+ maxLen = kStartMaxLen;
+ }
+ #endif
- #ifdef HASH_ARRAY_2
- distances[2] = len2Distance;
- #ifdef HASH_ARRAY_3
- distances[3] = len3Distance;
- #endif
- #endif
+ _hash[kFixHashSize + hashValue] = _pos;
- return matchHashLenMax;
- }
- CIndex *ptrLeft = &pair.Right;
- CIndex *ptrRight = &pair.Left;
+ CIndex *son = _son;
- UInt32 maxLen, minLeft, minRight;
- maxLen = minLeft = minRight = kNumHashDirectBytes;
+ #ifdef _HASH_CHAIN
+ son[_cyclicBufferPos] = curMatch;
+ #else
+ CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
+ CIndex *ptr1 = son + (_cyclicBufferPos << 1);
- #ifdef HASH_ARRAY_2
- #ifndef HASH_ARRAY_3
- if (matchLen2Exist)
- distances[2] = len2Distance;
- else
- if (kNumHashDirectBytes >= 2)
- distances[2] = _pos - curMatch - 1;
- #endif
+ UInt32 len0, len1;
+ len0 = len1 = kNumHashDirectBytes;
#endif
- distances[maxLen] = _pos - curMatch - 1;
-
- for(UInt32 count = _cutValue; count > 0; count--)
+ #if kNumHashDirectBytes != 0
+ if(curMatch > matchMinPos)
{
- /*
- UInt32 delta = _pos - curMatch;
- UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
- (_cyclicBufferPos - delta):
- (_cyclicBufferPos - delta + _cyclicBufferSize);
-
- CBundle &bundle = _son[cyclicPos >> kNumBundleBits];
- UInt32 bo = cyclicPos & kBundleMask;
- CPair &pair = bundle.Pairs[bo];
-
- Byte *pby1 = bundle.Bytes + bo;
- UInt32 bundleLimit = kNumBundleBytes - bo;
- UInt32 currentLen = minSame;
- if (bundleLimit > lenLimit)
- bundleLimit = lenLimit;
- for(; currentLen < bundleLimit; currentLen++)
- if (pby1[currentLen] != cur[currentLen])
- break;
- if (currentLen >= bundleLimit)
+ if (_buffer[curMatch + kNumHashDirectBytes] != cur[kNumHashDirectBytes])
{
- pby1 = _buffer + curMatch;
- for(; currentLen < lenLimit; currentLen++)
- if (pby1[currentLen] != cur[currentLen])
- break;
+ distances[offset++] = maxLen = kNumHashDirectBytes;
+ distances[offset++] = _pos - curMatch - 1;
+ }
+ }
+ #endif
+ UInt32 count = _cutValue;
+ while(true)
+ {
+ if(curMatch <= matchMinPos || count-- == 0)
+ {
+ #ifndef _HASH_CHAIN
+ *ptr0 = *ptr1 = kEmptyHashValue;
+ #endif
+ break;
}
- */
- Byte *pby1 = _buffer + curMatch;
- // CIndex left = pair.Left; // it's prefetch
- UInt32 currentLen = MyMin(minLeft, minRight);
- for(; currentLen < lenLimit; currentLen++)
- if (pby1[currentLen] != cur[currentLen])
- break;
UInt32 delta = _pos - curMatch;
- while (currentLen > maxLen)
- distances[++maxLen] = delta - 1;
-
UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
(_cyclicBufferPos - delta):
(_cyclicBufferPos - delta + _cyclicBufferSize);
- CPair &pair = _son[cyclicPos];
+ CIndex *pair = son +
+ #ifdef _HASH_CHAIN
+ cyclicPos;
+ #else
+ (cyclicPos << 1);
+ #endif
- if (currentLen != lenLimit)
- {
- if (pby1[currentLen] < cur[currentLen])
- {
- *ptrRight = curMatch;
- ptrRight = &pair.Right;
- curMatch = pair.Right;
- if(currentLen > minLeft)
- minLeft = currentLen;
- }
- else
- {
- *ptrLeft = curMatch;
- ptrLeft = &pair.Left;
- curMatch = pair.Left;
- if(currentLen > minRight)
- minRight = currentLen;
- }
- }
- else
+ // _mm_prefetch((const char *)pair, _MM_HINT_T0);
+
+ const Byte *pb = _buffer + curMatch;
+ UInt32 len =
+ #ifdef _HASH_CHAIN
+ kNumHashDirectBytes;
+ if (pb[maxLen] == cur[maxLen])
+ #else
+ MyMin(len0, len1);
+ #endif
+ if (pb[len] == cur[len])
{
- if(currentLen < _matchMaxLen)
- {
- *ptrLeft = curMatch;
- ptrLeft = &pair.Left;
- curMatch = pair.Left;
- if(currentLen > minRight)
- minRight = currentLen;
- }
- else
+ while(++len != lenLimit)
+ if (pb[len] != cur[len])
+ break;
+ if (maxLen < len)
{
- *ptrLeft = pair.Right;
- *ptrRight = pair.Left;
-
- #ifdef HASH_ARRAY_2
- if (matchLen2Exist && len2Distance < distances[2])
- distances[2] = len2Distance;
- #ifdef HASH_ARRAY_3
- if (matchLen3Exist && len3Distance < distances[3])
- distances[3] = len3Distance;
- #endif
- #endif
-
- return maxLen;
+ distances[offset++] = maxLen = len;
+ distances[offset++] = delta - 1;
+ if (len == lenLimit)
+ {
+ #ifndef _HASH_CHAIN
+ *ptr1 = pair[0];
+ *ptr0 = pair[1];
+ #endif
+ break;
+ }
}
}
- if(curMatch < matchMinPos)
- break;
- }
- *ptrLeft = kEmptyHashValue;
- *ptrRight = kEmptyHashValue;
- #ifdef HASH_ARRAY_2
- if (matchLen2Exist)
- {
- if (maxLen < 2)
+ #ifdef _HASH_CHAIN
+ curMatch = *pair;
+ #else
+ if (pb[len] < cur[len])
{
- distances[2] = len2Distance;
- maxLen = 2;
+ *ptr1 = curMatch;
+ ptr1 = pair + 1;
+ curMatch = *ptr1;
+ len1 = len;
}
- else if (len2Distance < distances[2])
- distances[2] = len2Distance;
- }
- #ifdef HASH_ARRAY_3
- if (matchLen3Exist)
- {
- if (maxLen < 3)
+ else
{
- distances[3] = len3Distance;
- maxLen = 3;
+ *ptr0 = curMatch;
+ ptr0 = pair;
+ curMatch = *ptr0;
+ len0 = len;
}
- else if (len3Distance < distances[3])
- distances[3] = len3Distance;
+ #endif
}
- #endif
- #endif
- return maxLen;
+ distances[0] = offset - 1;
+ if (++_cyclicBufferPos == _cyclicBufferSize)
+ _cyclicBufferPos = 0;
+ RINOK(CLZInWindow::MovePos());
+ if (_pos == kMaxValForNormalize)
+ Normalize();
+ return S_OK;
}
-void CInTree::DummyLongestMatch()
+STDMETHODIMP CMatchFinder::Skip(UInt32 num)
{
+ do
+ {
+ #ifdef _HASH_CHAIN
+ if (_streamPos - _pos < kNumHashBytes)
+ {
+ RINOK(MovePos());
+ continue;
+ }
+ #else
UInt32 lenLimit;
if (_pos + _matchMaxLen <= _streamPos)
lenLimit = _matchMaxLen;
else
{
lenLimit = _streamPos - _pos;
- if(lenLimit < kNumHashBytes)
- return;
+ if(lenLimit < kMinMatchCheck)
+ {
+ RINOK(MovePos());
+ continue;
+ }
}
- UInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;
- Byte *cur = _buffer + _pos;
+ UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
+ #endif
+ const Byte *cur = _buffer + _pos;
#ifdef HASH_ARRAY_2
UInt32 hash2Value;
#ifdef HASH_ARRAY_3
UInt32 hash3Value;
- UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
- _hash3[hash3Value] = _pos;
+ UInt32 hashValue;
+ HASH_CALC;
+ _hash[kHash3Offset + hash3Value] = _pos;
#else
- UInt32 hashValue = Hash(cur, hash2Value);
+ UInt32 hashValue;
+ HASH_CALC;
#endif
- _hash2[hash2Value] = _pos;
+ _hash[hash2Value] = _pos;
#else
UInt32 hashValue = Hash(cur);
#endif
- UInt32 curMatch = _hash[hashValue];
- _hash[hashValue] = _pos;
-
- CPair &pair = _son[_cyclicBufferPos];
-
- if(curMatch < matchMinPos)
- {
- pair.Left = kEmptyHashValue;
- pair.Right = kEmptyHashValue;
- return;
- }
- CIndex *ptrLeft = &pair.Right;
- CIndex *ptrRight = &pair.Left;
+ UInt32 curMatch = _hash[kFixHashSize + hashValue];
+ _hash[kFixHashSize + hashValue] = _pos;
- UInt32 maxLen, minLeft, minRight;
- maxLen = minLeft = minRight = kNumHashDirectBytes;
- for(UInt32 count = _cutValue; count > 0; count--)
+ #ifdef _HASH_CHAIN
+ _son[_cyclicBufferPos] = curMatch;
+ #else
+ CIndex *son = _son;
+ CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
+ CIndex *ptr1 = son + (_cyclicBufferPos << 1);
+
+ UInt32 len0, len1;
+ len0 = len1 = kNumHashDirectBytes;
+ UInt32 count = _cutValue;
+ while(true)
{
- Byte *pby1 = _buffer + curMatch;
- UInt32 currentLen = MyMin(minLeft, minRight);
- for(; currentLen < lenLimit; currentLen++)
- if (pby1[currentLen] != cur[currentLen])
- break;
-
+ if(curMatch <= matchMinPos || count-- == 0)
+ {
+ *ptr0 = *ptr1 = kEmptyHashValue;
+ break;
+ }
+
UInt32 delta = _pos - curMatch;
UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
- (_cyclicBufferPos - delta):
- (_cyclicBufferPos - delta + _cyclicBufferSize);
- CPair &pair = _son[cyclicPos];
-
- if (currentLen != lenLimit)
+ (_cyclicBufferPos - delta):
+ (_cyclicBufferPos - delta + _cyclicBufferSize);
+ CIndex *pair = son + (cyclicPos << 1);
+
+ // _mm_prefetch((const char *)pair, _MM_HINT_T0);
+
+ const Byte *pb = _buffer + curMatch;
+ UInt32 len = MyMin(len0, len1);
+
+ if (pb[len] == cur[len])
{
- if (pby1[currentLen] < cur[currentLen])
- {
- *ptrRight = curMatch;
- ptrRight = &pair.Right;
- curMatch = pair.Right;
- if(currentLen > minLeft)
- minLeft = currentLen;
- }
- else
+ while(++len != lenLimit)
+ if (pb[len] != cur[len])
+ break;
+ if (len == lenLimit)
{
- *ptrLeft = curMatch;
- ptrLeft = &pair.Left;
- curMatch = pair.Left;
- if(currentLen > minRight)
- minRight = currentLen;
+ *ptr1 = pair[0];
+ *ptr0 = pair[1];
+ break;
}
}
+ if (pb[len] < cur[len])
+ {
+ *ptr1 = curMatch;
+ ptr1 = pair + 1;
+ curMatch = *ptr1;
+ len1 = len;
+ }
else
{
- if(currentLen < _matchMaxLen)
- {
- *ptrLeft = curMatch;
- ptrLeft = &pair.Left;
- curMatch = pair.Left;
- if(currentLen > minRight)
- minRight = currentLen;
- }
- else
- {
- *ptrLeft = pair.Right;
- *ptrRight = pair.Left;
- return;
- }
+ *ptr0 = curMatch;
+ ptr0 = pair;
+ curMatch = *ptr0;
+ len0 = len;
}
- if(curMatch < matchMinPos)
- break;
}
- *ptrLeft = kEmptyHashValue;
- *ptrRight = kEmptyHashValue;
+ #endif
+ if (++_cyclicBufferPos == _cyclicBufferSize)
+ _cyclicBufferPos = 0;
+ RINOK(CLZInWindow::MovePos());
+ if (_pos == kMaxValForNormalize)
+ Normalize();
+ }
+ while(--num != 0);
+ return S_OK;
}
-void CInTree::NormalizeLinks(CIndex *items, UInt32 numItems, UInt32 subValue)
+void CMatchFinder::Normalize()
{
+ UInt32 subValue = _pos - _cyclicBufferSize;
+ CIndex *items = _hash;
+ UInt32 numItems = (_hashSizeSum + _cyclicBufferSize
+ #ifndef _HASH_CHAIN
+ * 2
+ #endif
+ );
for (UInt32 i = 0; i < numItems; i++)
{
UInt32 value = items[i];
@@ -527,25 +508,39 @@ void CInTree::NormalizeLinks(CIndex *items, UInt32 numItems, UInt32 subValue)
value -= subValue;
items[i] = value;
}
+ ReduceOffsets(subValue);
}
-void CInTree::Normalize()
+HRESULT CMatchFinder::MovePos()
{
- UInt32 startItem = _pos - _historySize;
- UInt32 subValue = startItem - 1;
- // NormalizeLinks((CIndex *)(_son + startItem), _historySize * 2, subValue);
- NormalizeLinks((CIndex *)_son, _cyclicBufferSize * 2, subValue);
-
- NormalizeLinks(_hash, kHashSize, subValue);
+ if (++_cyclicBufferPos == _cyclicBufferSize)
+ _cyclicBufferPos = 0;
+ RINOK(CLZInWindow::MovePos());
+ if (_pos == kMaxValForNormalize)
+ Normalize();
+ return S_OK;
+}
- #ifdef HASH_ARRAY_2
- NormalizeLinks(_hash2, kHash2Size, subValue);
- #ifdef HASH_ARRAY_3
- NormalizeLinks(_hash3, kHash3Size, subValue);
- #endif
- #endif
+STDMETHODIMP_(Byte) CMatchFinder::GetIndexByte(Int32 index)
+ { return CLZInWindow::GetIndexByte(index); }
- ReduceOffsets(subValue);
-}
+STDMETHODIMP_(UInt32) CMatchFinder::GetMatchLen(Int32 index,
+ UInt32 back, UInt32 limit)
+ { return CLZInWindow::GetMatchLen(index, back, limit); }
+
+STDMETHODIMP_(UInt32) CMatchFinder::GetNumAvailableBytes()
+ { return CLZInWindow::GetNumAvailableBytes(); }
+
+STDMETHODIMP_(const Byte *) CMatchFinder::GetPointerToCurrentPos()
+ { return CLZInWindow::GetPointerToCurrentPos(); }
+
+STDMETHODIMP_(Int32) CMatchFinder::NeedChangeBufferPos(UInt32 numCheckBytes)
+ { return CLZInWindow::NeedMove(numCheckBytes) ? 1: 0; }
+
+STDMETHODIMP_(void) CMatchFinder::ChangeBufferPos()
+ { CLZInWindow::MoveBlock();}
+
+#undef HASH_CALC
+#undef kNumHashDirectBytes
}
diff --git a/Source/7zip/7zip/Compress/LZ/IMatchFinder.h b/Source/7zip/7zip/Compress/LZ/IMatchFinder.h
index 1d9c88f..2979eaa 100755
--- a/Source/7zip/7zip/Compress/LZ/IMatchFinder.h
+++ b/Source/7zip/7zip/Compress/LZ/IMatchFinder.h
@@ -1,63 +1,47 @@
-// MatchFinders/IMatchFinder.h
+/*
+ * IMatchFinder.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __IMATCHFINDER_H
#define __IMATCHFINDER_H
-// {23170F69-40C1-278A-0000-000200010000}
-DEFINE_GUID(IID_IInWindowStream,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200010000")
-IInWindowStream: public IUnknown
+struct IInWindowStream: public IUnknown
{
- STDMETHOD(Init)(ISequentialInStream *inStream) PURE;
+ STDMETHOD(SetStream)(ISequentialInStream *inStream) PURE;
STDMETHOD_(void, ReleaseStream)() PURE;
- STDMETHOD(MovePos)() PURE;
+ STDMETHOD(Init)() PURE;
STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;
STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;
STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;
+ STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes) PURE;
+ STDMETHOD_(void, ChangeBufferPos)() PURE;
};
-// {23170F69-40C1-278A-0000-000200020000}
-DEFINE_GUID(IID_IMatchFinder,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020000")
-IMatchFinder: public IInWindowStream
+struct IMatchFinder: public IInWindowStream
{
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;
- STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances) PURE;
- STDMETHOD_(void, DummyLongestMatch)() PURE;
-};
-
-// {23170F69-40C1-278A-0000-000200020100}
-DEFINE_GUID(IID_IMatchFinderCallback,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020100")
-IMatchFinderCallback: public IUnknown
-{
- STDMETHOD(BeforeChangingBufferPos)() PURE;
- STDMETHOD(AfterChangingBufferPos)() PURE;
+ STDMETHOD(GetMatches)(UInt32 *distances) PURE;
+ STDMETHOD(Skip)(UInt32 num) PURE;
};
-// {23170F69-40C1-278A-0000-000200020200}
-DEFINE_GUID(IID_IMatchFinderSetCallback,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020200")
-IMatchFinderSetCallback: public IUnknown
-{
- STDMETHOD(SetCallback)(IMatchFinderCallback *callback) PURE;
-};
-
-/*
-// {23170F69-40C1-278A-0000-000200030000}
-DEFINE_GUID(IID_IInitMatchFinder,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200030000")
-IMatchFinderInit: public IUnknown
+struct IMatchFinderSetNumPasses
{
- STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder) PURE;
+ virtual void SetNumPasses(UInt32 numPasses) PURE;
};
-*/
#endif
diff --git a/Source/7zip/7zip/Compress/LZ/LZInWindow.cpp b/Source/7zip/7zip/Compress/LZ/LZInWindow.cpp
index 43c709d..c5e1720 100755
--- a/Source/7zip/7zip/Compress/LZ/LZInWindow.cpp
+++ b/Source/7zip/7zip/Compress/LZ/LZInWindow.cpp
@@ -1,4 +1,19 @@
-// LZInWindow.cpp
+/*
+ * LZInWindow.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "StdAfx.h"
@@ -16,22 +31,27 @@ bool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 kee
{
_keepSizeBefore = keepSizeBefore;
_keepSizeAfter = keepSizeAfter;
- _keepSizeReserv = keepSizeReserv;
UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
if (_bufferBase == 0 || _blockSize != blockSize)
{
Free();
_blockSize = blockSize;
- _bufferBase = (Byte *)::BigAlloc(_blockSize);
+ if (_blockSize != 0)
+ _bufferBase = (Byte *)::BigAlloc(_blockSize);
}
_pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;
+ if (_blockSize == 0)
+ return true;
return (_bufferBase != 0);
}
-
-HRESULT CLZInWindow::Init(ISequentialInStream *stream)
+void CLZInWindow::SetStream(ISequentialInStream *stream)
{
_stream = stream;
+}
+
+HRESULT CLZInWindow::Init()
+{
_buffer = _bufferBase;
_pos = 0;
_streamPos = 0;
@@ -65,11 +85,11 @@ HRESULT CLZInWindow::ReadBlock()
return S_OK;
while(true)
{
- UInt32 size = UInt32(_bufferBase - _buffer) + _blockSize - _streamPos;
+ UInt32 size = (UInt32)(_bufferBase - _buffer) + _blockSize - _streamPos;
if(size == 0)
return S_OK;
UInt32 numReadBytes;
- RINOK(_stream->ReadPart(_buffer + _streamPos, size, &numReadBytes));
+ RINOK(_stream->Read(_buffer + _streamPos, size, &numReadBytes));
if(numReadBytes == 0)
{
_posLimit = _streamPos;
@@ -90,10 +110,11 @@ HRESULT CLZInWindow::ReadBlock()
void CLZInWindow::MoveBlock()
{
- BeforeMoveBlock();
- UInt32 offset = UInt32(_buffer - _bufferBase) + _pos - _keepSizeBefore;
- UInt32 numBytes = UInt32(_buffer - _bufferBase) + _streamPos - offset;
+ UInt32 offset = (UInt32)(_buffer - _bufferBase) + _pos - _keepSizeBefore;
+ // we need one additional byte, since MovePos moves on 1 byte.
+ if (offset > 0)
+ offset--;
+ UInt32 numBytes = (UInt32)(_buffer - _bufferBase) + _streamPos - offset;
memmove(_bufferBase, _bufferBase + offset, numBytes);
_buffer -= offset;
- AfterMoveBlock();
}
diff --git a/Source/7zip/7zip/Compress/LZ/LZInWindow.h b/Source/7zip/7zip/Compress/LZ/LZInWindow.h
index 7dc194f..1bafd1a 100755
--- a/Source/7zip/7zip/Compress/LZ/LZInWindow.h
+++ b/Source/7zip/7zip/Compress/LZ/LZInWindow.h
@@ -1,4 +1,19 @@
-// LZInWindow.h
+/*
+ * LZInWindow.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __LZ_IN_WINDOW_H
#define __LZ_IN_WINDOW_H
@@ -9,7 +24,7 @@ class CLZInWindow
{
Byte *_bufferBase; // pointer to buffer with data
ISequentialInStream *_stream;
- UInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done
+ UInt32 _posLimit; // offset (from _buffer) when new block reading must be done
bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
const Byte *_pointerToLastSafePosition;
protected:
@@ -18,22 +33,20 @@ protected:
UInt32 _pos; // offset (from _buffer) of curent byte
UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos
UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos
- UInt32 _keepSizeReserv; // how many BYTEs must be kept as reserv
UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream
- virtual void BeforeMoveBlock() {};
- virtual void AfterMoveBlock() {};
void MoveBlock();
- virtual HRESULT ReadBlock();
+ HRESULT ReadBlock();
void Free();
public:
CLZInWindow(): _bufferBase(0) {}
virtual ~CLZInWindow() { Free(); }
- bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter,
- UInt32 keepSizeReserv = (1<<17));
+ // keepSizeBefore + keepSizeAfter + keepSizeReserv < 4G)
+ bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv = (1<<17));
- HRESULT Init(ISequentialInStream *stream);
+ void SetStream(ISequentialInStream *stream);
+ HRESULT Init();
// void ReleaseStream();
Byte *GetBuffer() const { return _buffer; }
@@ -53,17 +66,17 @@ public:
else
return S_OK;
}
- Byte GetIndexByte(Int32 index)const
- { return _buffer[(size_t)_pos + index]; }
+ Byte GetIndexByte(Int32 index) const { return _buffer[(size_t)_pos + index]; }
// index + limit have not to exceed _keepSizeAfter;
+ // -2G <= index < 2G
UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const
{
if(_streamEndWasReached)
if ((_pos + index) + limit > _streamPos)
limit = _streamPos - (_pos + index);
distance++;
- Byte *pby = _buffer + (size_t)_pos + index;
+ const Byte *pby = _buffer + (size_t)_pos + index;
UInt32 i;
for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
return i;
@@ -79,6 +92,11 @@ public:
_streamPos -= subValue;
}
+ bool NeedMove(UInt32 numCheckBytes)
+ {
+ UInt32 reserv = _pointerToLastSafePosition - (_buffer + _pos);
+ return (reserv <= numCheckBytes);
+ }
};
#endif
diff --git a/Source/7zip/7zip/Compress/LZ/LZOutWindow.cpp b/Source/7zip/7zip/Compress/LZ/LZOutWindow.cpp
index 53d4430..5370eff 100755
--- a/Source/7zip/7zip/Compress/LZ/LZOutWindow.cpp
+++ b/Source/7zip/7zip/Compress/LZ/LZOutWindow.cpp
@@ -1,88 +1,32 @@
-// LZOutWindow.cpp
+/*
+ * LZOutWindow.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "StdAfx.h"
#include "../../../Common/Alloc.h"
#include "LZOutWindow.h"
-bool CLZOutWindow::Create(UInt32 windowSize)
-{
- _pos = 0;
- _streamPos = 0;
- const UInt32 kMinBlockSize = 1;
- if (windowSize < kMinBlockSize)
- windowSize = kMinBlockSize;
- if (_buffer != 0 && _windowSize == windowSize)
- return true;
- Free();
- _windowSize = windowSize;
- _buffer = (Byte *)::BigAlloc(windowSize);
- return (_buffer != 0);
-}
-
-void CLZOutWindow::Free()
+void CLZOutWindow::Init(bool solid)
{
- ::BigFree(_buffer);
- _buffer = 0;
-}
-
-void CLZOutWindow::Init(ISequentialOutStream *stream, bool solid)
-{
- // ReleaseStream();
- _stream = stream;
- // _stream->AddRef();
-
if(!solid)
- {
- _streamPos = 0;
- _pos = 0;
- }
+ COutBuffer::Init();
#ifdef _NO_EXCEPTIONS
ErrorCode = S_OK;
#endif
}
-/*
-void CLZOutWindow::ReleaseStream()
-{
- if(_stream != 0)
- {
- // Flush(); // Test it
- _stream->Release();
- _stream = 0;
- }
-}
-*/
-void CLZOutWindow::FlushWithCheck()
-{
- HRESULT result = Flush();
- #ifdef _NO_EXCEPTIONS
- ErrorCode = result;
- #else
- if (result != S_OK)
- throw CLZOutWindowException(result);
- #endif
-}
-
-HRESULT CLZOutWindow::Flush()
-{
- UInt32 size = _pos - _streamPos;
- if(size == 0)
- return S_OK;
- #ifdef _NO_EXCEPTIONS
- if (ErrorCode != S_OK)
- return ErrorCode;
- #endif
-
- UInt32 processedSize;
- HRESULT result = _stream->Write(_buffer + _streamPos, size, &processedSize);
- if (result != S_OK)
- return result;
- if (size != processedSize)
- return E_FAIL;
- if (_pos >= _windowSize)
- _pos = 0;
- _streamPos = _pos;
- return S_OK;
-}
diff --git a/Source/7zip/7zip/Compress/LZ/LZOutWindow.h b/Source/7zip/7zip/Compress/LZ/LZOutWindow.h
index e15132a..e0ee36e 100755
--- a/Source/7zip/7zip/Compress/LZ/LZOutWindow.h
+++ b/Source/7zip/7zip/Compress/LZ/LZOutWindow.h
@@ -1,69 +1,69 @@
-// LZOutWindow.h
+/*
+ * LZOutWindow.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __LZ_OUT_WINDOW_H
#define __LZ_OUT_WINDOW_H
#include "../../IStream.h"
+#include "../../Common/OutBuffer.h"
#ifndef _NO_EXCEPTIONS
-class CLZOutWindowException
-{
-public:
- HRESULT ErrorCode;
- CLZOutWindowException(HRESULT errorCode): ErrorCode(errorCode) {}
-};
+typedef COutBufferException CLZOutWindowException;
#endif
-class CLZOutWindow
+class CLZOutWindow: public COutBuffer
{
- Byte *_buffer;
- UInt32 _pos;
- UInt32 _windowSize;
- UInt32 _streamPos;
- ISequentialOutStream *_stream;
- void FlushWithCheck();
public:
- #ifdef _NO_EXCEPTIONS
- HRESULT ErrorCode;
- #endif
-
- void Free();
- CLZOutWindow(): _buffer(0), _stream(0) {}
- ~CLZOutWindow() { Free(); /* ReleaseStream(); */ }
- bool Create(UInt32 windowSize);
+ void Init(bool solid = false);
- void Init(ISequentialOutStream *stream, bool solid = false);
- HRESULT Flush();
- // void ReleaseStream();
-
- void CopyBlock(UInt32 distance, UInt32 len)
+ // distance >= 0, len > 0,
+ bool CopyBlock(UInt32 distance, UInt32 len)
{
UInt32 pos = _pos - distance - 1;
- if (pos >= _windowSize)
- pos += _windowSize;
- for(; len > 0; len--)
+ if (distance >= _pos)
+ {
+ if (!_overDict || distance >= _bufferSize)
+ return false;
+ pos += _bufferSize;
+ }
+ do
{
- if (pos >= _windowSize)
+ if (pos == _bufferSize)
pos = 0;
_buffer[_pos++] = _buffer[pos++];
- if (_pos >= _windowSize)
+ if (_pos == _limitPos)
FlushWithCheck();
- // PutOneByte(GetOneByte(distance));
}
+ while(--len != 0);
+ return true;
}
void PutByte(Byte b)
{
_buffer[_pos++] = b;
- if (_pos >= _windowSize)
+ if (_pos == _limitPos)
FlushWithCheck();
}
Byte GetByte(UInt32 distance) const
{
UInt32 pos = _pos - distance - 1;
- if (pos >= _windowSize)
- pos += _windowSize;
+ if (pos >= _bufferSize)
+ pos += _bufferSize;
return _buffer[pos];
}
};
diff --git a/Source/7zip/7zip/Compress/LZ/StdAfx.h b/Source/7zip/7zip/Compress/LZ/StdAfx.h
index 59eb30a..3de038a 100755
--- a/Source/7zip/7zip/Compress/LZ/StdAfx.h
+++ b/Source/7zip/7zip/Compress/LZ/StdAfx.h
@@ -3,6 +3,4 @@
#ifndef __STDAFX_H
#define __STDAFX_H
-#include "../../../../Platform.h"
-
#endif
diff --git a/Source/7zip/7zip/Compress/LZMA/LZMA.h b/Source/7zip/7zip/Compress/LZMA/LZMA.h
index 7999c35..13e94e0 100755
--- a/Source/7zip/7zip/Compress/LZMA/LZMA.h
+++ b/Source/7zip/7zip/Compress/LZMA/LZMA.h
@@ -1,4 +1,19 @@
-// LZMA.h
+/*
+ * LZMA.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __LZMA_H
#define __LZMA_H
@@ -24,6 +39,7 @@ public:
void UpdateMatch() { Index = kMatchNextStates[Index]; }
void UpdateRep() { Index = kRepNextStates[Index]; }
void UpdateShortRep() { Index = kShortRepNextStates[Index]; }
+ bool IsCharState() const { return Index < 7; }
};
const int kNumPosSlotBits = 6;
diff --git a/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.cpp b/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.cpp
index df44dc0..5eae213 100755
--- a/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.cpp
+++ b/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.cpp
@@ -1,8 +1,24 @@
-// LZMA/Encoder.cpp
+/*
+ * LZMAEncoder.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "StdAfx.h"
#include "../../../Common/Defs.h"
+#include "../../Common/StreamUtils.h"
#include "LZMAEncoder.h"
@@ -10,18 +26,16 @@
// #define COMPRESS_MF_BT
// #define COMPRESS_MF_BT4
-#if !defined(COMPRESS_MF_BT) && !defined(COMPRESS_MF_PAT) && !defined(COMPRESS_MF_HC)
+#if !defined(COMPRESS_MF_BT) && !defined(COMPRESS_MF_HC)
#define COMPRESS_MF_BT
-#define COMPRESS_MF_PAT
#define COMPRESS_MF_HC
#endif
#ifdef COMPRESS_MF_BT
-#if !defined(COMPRESS_MF_BT2) && !defined(COMPRESS_MF_BT3) && !defined(COMPRESS_MF_BT4) && !defined(COMPRESS_MF_BT4B)
+#if !defined(COMPRESS_MF_BT2) && !defined(COMPRESS_MF_BT3) && !defined(COMPRESS_MF_BT4)
#define COMPRESS_MF_BT2
#define COMPRESS_MF_BT3
#define COMPRESS_MF_BT4
-#define COMPRESS_MF_BT4B
#endif
#ifdef COMPRESS_MF_BT2
#include "../LZ/BinTree/BinTree2.h"
@@ -32,21 +46,9 @@
#ifdef COMPRESS_MF_BT4
#include "../LZ/BinTree/BinTree4.h"
#endif
-#ifdef COMPRESS_MF_BT4B
-#include "../LZ/BinTree/BinTree4b.h"
-#endif
-#endif
-
-#ifdef COMPRESS_MF_PAT
-#include "../LZ/Patricia/Pat2.h"
-#include "../LZ/Patricia/Pat2H.h"
-#include "../LZ/Patricia/Pat3H.h"
-#include "../LZ/Patricia/Pat4H.h"
-#include "../LZ/Patricia/Pat2R.h"
#endif
#ifdef COMPRESS_MF_HC
-#include "../LZ/HashChain/HC3.h"
#include "../LZ/HashChain/HC4.h"
#endif
@@ -57,7 +59,7 @@
namespace NCompress {
namespace NLZMA {
-const int kDefaultDictionaryLogSize = 20;
+const int kDefaultDictionaryLogSize = 22;
const UInt32 kNumFastBytesDefault = 0x20;
enum
@@ -65,32 +67,18 @@ enum
kBT2,
kBT3,
kBT4,
- kBT4B,
- kPat2,
- kPat2H,
- kPat3H,
- kPat4H,
- kPat2R,
- kHC3,
kHC4
};
-static const wchar_t *kMatchFinderIDs[] =
+/*static const wchar_t *kMatchFinderIDs[] =
{
L"BT2",
L"BT3",
L"BT4",
- L"BT4B",
- L"PAT2",
- L"PAT2H",
- L"PAT3H",
- L"PAT4H",
- L"PAT2R",
- L"HC3",
L"HC4"
-};
+};*/
-Byte g_FastPos[1024];
+Byte g_FastPos[1 << 11];
class CFastPosInit
{
@@ -98,7 +86,7 @@ public:
CFastPosInit() { Init(); }
void Init()
{
- const Byte kFastSlots = 20;
+ const Byte kFastSlots = 22;
int c = 2;
g_FastPos[0] = 0;
g_FastPos[1] = 1;
@@ -116,57 +104,66 @@ public:
void CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)
{
UInt32 context = 1;
- for (int i = 7; i >= 0; i--)
+ int i = 8;
+ do
{
+ i--;
UInt32 bit = (symbol >> i) & 1;
- UInt32 state = context;
- _encoders[state].Encode(rangeEncoder, bit);
+ _encoders[context].Encode(rangeEncoder, bit);
context = (context << 1) | bit;
}
+ while(i != 0);
}
void CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder,
Byte matchByte, Byte symbol)
{
UInt32 context = 1;
- bool same = true;
- for (int i = 7; i >= 0; i--)
+ int i = 8;
+ do
{
+ i--;
UInt32 bit = (symbol >> i) & 1;
- UInt32 state = context;
- if (same)
+ UInt32 matchBit = (matchByte >> i) & 1;
+ _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit);
+ context = (context << 1) | bit;
+ if (matchBit != bit)
{
- UInt32 matchBit = (matchByte >> i) & 1;
- state += (1 + matchBit) << 8;
- same = (matchBit == bit);
+ while(i != 0)
+ {
+ i--;
+ UInt32 bit = (symbol >> i) & 1;
+ _encoders[context].Encode(rangeEncoder, bit);
+ context = (context << 1) | bit;
+ }
+ break;
}
- _encoders[state].Encode(rangeEncoder, bit);
- context = (context << 1) | bit;
}
+ while(i != 0);
}
UInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const
{
UInt32 price = 0;
UInt32 context = 1;
- int i = 7;
+ int i = 8;
if (matchMode)
{
- for (; i >= 0; i--)
+ do
{
+ i--;
UInt32 matchBit = (matchByte >> i) & 1;
UInt32 bit = (symbol >> i) & 1;
- price += _encoders[((1 + matchBit) << 8) + context].GetPrice(bit);
+ price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit);
context = (context << 1) | bit;
if (matchBit != bit)
- {
- i--;
break;
- }
}
+ while (i != 0);
}
- for (; i >= 0; i--)
+ while(i != 0)
{
+ i--;
UInt32 bit = (symbol >> i) & 1;
price += _encoders[context].GetPrice(bit);
context = (context << 1) | bit;
@@ -180,12 +177,12 @@ namespace NLength {
void CEncoder::Init(UInt32 numPosStates)
{
_choice.Init();
+ _choice2.Init();
for (UInt32 posState = 0; posState < numPosStates; posState++)
{
_lowCoder[posState].Init();
_midCoder[posState].Init();
}
- _choice2.Init();
_highCoder.Init();
}
@@ -198,45 +195,41 @@ void CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32
}
else
{
- symbol -= kNumLowSymbols;
_choice.Encode(rangeEncoder, 1);
- if(symbol < kNumMidSymbols)
+ if(symbol < kNumLowSymbols + kNumMidSymbols)
{
_choice2.Encode(rangeEncoder, 0);
- _midCoder[posState].Encode(rangeEncoder, symbol);
+ _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols);
}
else
{
_choice2.Encode(rangeEncoder, 1);
- _highCoder.Encode(rangeEncoder, symbol - kNumMidSymbols);
+ _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols);
}
}
}
-UInt32 CEncoder::GetPrice(UInt32 symbol, UInt32 posState) const
+void CEncoder::SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const
{
- UInt32 price = 0;
- if(symbol < kNumLowSymbols)
+ UInt32 a0 = _choice.GetPrice0();
+ UInt32 a1 = _choice.GetPrice1();
+ UInt32 b0 = a1 + _choice2.GetPrice0();
+ UInt32 b1 = a1 + _choice2.GetPrice1();
+ UInt32 i = 0;
+ for (i = 0; i < kNumLowSymbols; i++)
{
- price += _choice.GetPrice(0);
- price += _lowCoder[posState].GetPrice(symbol);
+ if (i >= numSymbols)
+ return;
+ prices[i] = a0 + _lowCoder[posState].GetPrice(i);
}
- else
+ for (; i < kNumLowSymbols + kNumMidSymbols; i++)
{
- symbol -= kNumLowSymbols;
- price += _choice.GetPrice(1);
- if(symbol < kNumMidSymbols)
- {
- price += _choice2.GetPrice(0);
- price += _midCoder[posState].GetPrice(symbol);
- }
- else
- {
- price += _choice2.GetPrice(1);
- price += _highCoder.GetPrice(symbol - kNumMidSymbols);
- }
+ if (i >= numSymbols)
+ return;
+ prices[i] = b0 + _midCoder[posState].GetPrice(i - kNumLowSymbols);
}
- return price;
+ for (; i < numSymbols; i++)
+ prices[i] = b1 + _highCoder.GetPrice(i - kNumLowSymbols - kNumMidSymbols);
}
}
@@ -250,13 +243,15 @@ CEncoder::CEncoder():
_dictionarySize(1 << kDefaultDictionaryLogSize),
_dictionarySizePrev(UInt32(-1)),
_numFastBytesPrev(UInt32(-1)),
+ _matchFinderCycles(0),
_matchFinderIndex(kBT4),
#ifdef COMPRESS_MF_MT
_multiThread(false),
#endif
- _writeEndMark(false)
+ _writeEndMark(false),
+ setMfPasses(0)
{
- _maxMode = false;
+ // _maxMode = false;
_fastMode = false;
}
@@ -271,57 +266,52 @@ HRESULT CEncoder::Create()
#ifdef COMPRESS_MF_BT
#ifdef COMPRESS_MF_BT2
case kBT2:
- _matchFinder = new NBT2::CMatchFinderBinTree;
+ {
+ NBT2::CMatchFinder *mfSpec = new NBT2::CMatchFinder;
+ setMfPasses = mfSpec;
+ _matchFinder = mfSpec;
break;
+ }
#endif
#ifdef COMPRESS_MF_BT3
case kBT3:
- _matchFinder = new NBT3::CMatchFinderBinTree;
+ {
+ NBT3::CMatchFinder *mfSpec = new NBT3::CMatchFinder;
+ setMfPasses = mfSpec;
+ _matchFinder = mfSpec;
break;
+ }
#endif
#ifdef COMPRESS_MF_BT4
case kBT4:
- _matchFinder = new NBT4::CMatchFinderBinTree;
- break;
- #endif
- #ifdef COMPRESS_MF_BT4B
- case kBT4B:
- _matchFinder = new NBT4B::CMatchFinderBinTree;
+ {
+ NBT4::CMatchFinder *mfSpec = new NBT4::CMatchFinder;
+ setMfPasses = mfSpec;
+ _matchFinder = mfSpec;
break;
+ }
#endif
#endif
- #ifdef COMPRESS_MF_PAT
- case kPat2:
- _matchFinder = new NPat2::CPatricia;
- break;
- case kPat2H:
- _matchFinder = new NPat2H::CPatricia;
- break;
- case kPat3H:
- _matchFinder = new NPat3H::CPatricia;
- break;
- case kPat4H:
- _matchFinder = new NPat4H::CPatricia;
- break;
- case kPat2R:
- _matchFinder = new NPat2R::CPatricia;
- break;
- #endif
-
#ifdef COMPRESS_MF_HC
- case kHC3:
- _matchFinder = new NHC3::CMatchFinderHC;
- break;
case kHC4:
- _matchFinder = new NHC4::CMatchFinderHC;
+ {
+ NHC4::CMatchFinder *mfSpec = new NHC4::CMatchFinder;
+ setMfPasses = mfSpec;
+ _matchFinder = mfSpec;
break;
+ }
#endif
}
+ if (_matchFinder == 0)
+ return E_OUTOFMEMORY;
+
#ifdef COMPRESS_MF_MT
- if (_multiThread)
+ if (_multiThread && !(_fastMode && (_matchFinderIndex == kHC4)))
{
CMatchFinderMT *mfSpec = new CMatchFinderMT;
+ if (mfSpec == 0)
+ return E_OUTOFMEMORY;
CMyComPtr<IMatchFinder> mf = mfSpec;
RINOK(mfSpec->SetMatchFinder(_matchFinder));
_matchFinder.Release();
@@ -335,14 +325,15 @@ HRESULT CEncoder::Create()
if (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)
return S_OK;
- RINOK(_matchFinder->Create(_dictionarySize, kNumOpts, _numFastBytes,
- kMatchMaxLen - _numFastBytes));
+ RINOK(_matchFinder->Create(_dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen + 1)); // actually it's + _numFastBytes - _numFastBytes
+ if (_matchFinderCycles != 0 && setMfPasses != 0)
+ setMfPasses->SetNumPasses(_matchFinderCycles);
_dictionarySizePrev = _dictionarySize;
_numFastBytesPrev = _numFastBytes;
return S_OK;
}
-static bool AreStringsEqual(const wchar_t *base, const wchar_t *testString)
+/*static bool AreStringsEqual(const wchar_t *base, const wchar_t *testString)
{
while (true)
{
@@ -364,7 +355,7 @@ static int FindMatchFinder(const wchar_t *s)
if (AreStringsEqual(kMatchFinderIDs[m], s))
return m;
return -1;
-}
+}*/
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
const PROPVARIANT *properties, UInt32 numProperties)
@@ -379,35 +370,43 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
if (prop.vt != VT_UI4)
return E_INVALIDARG;
UInt32 numFastBytes = prop.ulVal;
- if(numFastBytes < 2 || numFastBytes > kMatchMaxLen)
+ if(numFastBytes < 5 || numFastBytes > kMatchMaxLen)
return E_INVALIDARG;
_numFastBytes = numFastBytes;
break;
}
+ case NCoderPropID::kMatchFinderCycles:
+ {
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ _matchFinderCycles = prop.ulVal;
+ break;
+ }
case NCoderPropID::kAlgorithm:
{
if (prop.vt != VT_UI4)
return E_INVALIDARG;
UInt32 maximize = prop.ulVal;
_fastMode = (maximize == 0);
- _maxMode = (maximize >= 2);
+ // _maxMode = (maximize >= 2);
break;
}
case NCoderPropID::kMatchFinder:
{
- if (prop.vt != VT_BSTR)
+ return E_NOTIMPL;
+ /*if (prop.vt != VT_BSTR)
return E_INVALIDARG;
int matchFinderIndexPrev = _matchFinderIndex;
int m = FindMatchFinder(prop.bstrVal);
if (m < 0)
return E_INVALIDARG;
_matchFinderIndex = m;
- if (!_matchFinder && matchFinderIndexPrev != _matchFinderIndex)
+ if (_matchFinder && matchFinderIndexPrev != _matchFinderIndex)
{
- _dictionarySizePrev = UInt32(-1);
- _matchFinder.Release();
+ _dictionarySizePrev = (UInt32)-1;
+ ReleaseMatchFinder();
}
- break;
+ break;*/
}
#ifdef COMPRESS_MF_MT
case NCoderPropID::kMultiThread:
@@ -417,16 +416,29 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
bool newMultiThread = (prop.boolVal == VARIANT_TRUE);
if (newMultiThread != _multiThread)
{
- _dictionarySizePrev = UInt32(-1);
- _matchFinder.Release();
+ _dictionarySizePrev = (UInt32)-1;
+ ReleaseMatchFinder();
+ _multiThread = newMultiThread;
+ }
+ break;
+ }
+ case NCoderPropID::kNumThreads:
+ {
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ bool newMultiThread = (prop.ulVal > 1);
+ if (newMultiThread != _multiThread)
+ {
+ _dictionarySizePrev = (UInt32)-1;
+ ReleaseMatchFinder();
+ _multiThread = newMultiThread;
}
- _multiThread = newMultiThread;
break;
}
#endif
case NCoderPropID::kDictionarySize:
{
- const int kDicLogSizeMaxCompress = 28;
+ const int kDicLogSizeMaxCompress = 30;
if (prop.vt != VT_UI4)
return E_INVALIDARG;
UInt32 dictionarySize = prop.ulVal;
@@ -488,23 +500,32 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
{
- Byte firstByte = (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits;
- RINOK(outStream->Write(&firstByte, sizeof(firstByte), NULL));
+ const UInt32 kPropSize = 5;
+ Byte properties[kPropSize];
+ properties[0] = (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits;
for (int i = 0; i < 4; i++)
- {
- Byte b = Byte(_dictionarySize >> (8 * i));
- RINOK(outStream->Write(&b, sizeof(b), NULL));
- }
+ properties[1 + i] = Byte(_dictionarySize >> (8 * i));
+ return WriteStream(outStream, properties, kPropSize, NULL);
+}
+
+STDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)
+{
+ _rangeEncoder.SetStream(outStream);
+ return S_OK;
+}
+
+STDMETHODIMP CEncoder::ReleaseOutStream()
+{
+ _rangeEncoder.ReleaseStream();
return S_OK;
}
-STDMETHODIMP CEncoder::Init(
- ISequentialOutStream *outStream)
+HRESULT CEncoder::Init()
{
CBaseState::Init();
// RINOK(_matchFinder->Init(inStream));
- _rangeEncoder.Init(outStream);
+ _rangeEncoder.Init();
for(int i = 0; i < kNumStates; i++)
{
@@ -521,8 +542,6 @@ STDMETHODIMP CEncoder::Init(
_literalEncoder.Init();
- // _repMatchLenEncoder.Init();
-
{
for(UInt32 i = 0; i < kNumLenToPosStates; i++)
_posSlotEncoder[i].Init();
@@ -547,13 +566,10 @@ STDMETHODIMP CEncoder::Init(
HRESULT CEncoder::MovePos(UInt32 num)
{
- for (;num > 0; num--)
- {
- _matchFinder->DummyLongestMatch();
- RINOK(_matchFinder->MovePos());
- _additionalOffset++;
- }
- return S_OK;
+ if (num == 0)
+ return S_OK;
+ _additionalOffset += num;
+ return _matchFinder->Skip(num);
}
UInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)
@@ -584,44 +600,51 @@ UInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)
_optimum[posPrev].PosPrev = cur;
cur = posPrev;
}
- while(cur > 0);
+ while(cur != 0);
backRes = _optimum[0].BackPrev;
_optimumCurrentIndex = _optimum[0].PosPrev;
return _optimumCurrentIndex;
}
/*
-inline UInt32 GetMatchLen(const Byte *data, UInt32 back, UInt32 limit)
-{
- back++;
- for(UInt32 i = 0; i < limit && data[i] == data[i - back]; i++);
- return i;
-}
+Out:
+ (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal
*/
HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
{
if(_optimumEndIndex != _optimumCurrentIndex)
{
- lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;
- backRes = _optimum[_optimumCurrentIndex].BackPrev;
- _optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;
+ const COptimal &optimum = _optimum[_optimumCurrentIndex];
+ lenRes = optimum.PosPrev - _optimumCurrentIndex;
+ backRes = optimum.BackPrev;
+ _optimumCurrentIndex = optimum.PosPrev;
return S_OK;
}
- _optimumCurrentIndex = 0;
- _optimumEndIndex = 0; // test it;
+ _optimumCurrentIndex = _optimumEndIndex = 0;
- UInt32 lenMain;
+ UInt32 lenMain, numDistancePairs;
if (!_longestMatchWasFound)
{
- RINOK(ReadMatchDistances(lenMain));
+ RINOK(ReadMatchDistances(lenMain, numDistancePairs));
}
else
{
lenMain = _longestMatchLength;
+ numDistancePairs = _numDistancePairs;
_longestMatchWasFound = false;
}
+ const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;
+ UInt32 numAvailableBytes = _matchFinder->GetNumAvailableBytes() + 1;
+ if (numAvailableBytes < 2)
+ {
+ backRes = (UInt32)(-1);
+ lenRes = 1;
+ return S_OK;
+ }
+ if (numAvailableBytes > kMatchMaxLen)
+ numAvailableBytes = kMatchMaxLen;
UInt32 reps[kNumRepDistances];
UInt32 repLens[kNumRepDistances];
@@ -630,48 +653,53 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
for(i = 0; i < kNumRepDistances; i++)
{
reps[i] = _repDistances[i];
- repLens[i] = _matchFinder->GetMatchLen(0 - 1, reps[i], kMatchMaxLen);
- if (i == 0 || repLens[i] > repLens[repMaxIndex])
+ UInt32 backOffset = reps[i] + 1;
+ if (data[0] != data[(size_t)0 - backOffset] || data[1] != data[(size_t)1 - backOffset])
+ {
+ repLens[i] = 0;
+ continue;
+ }
+ UInt32 lenTest;
+ for (lenTest = 2; lenTest < numAvailableBytes &&
+ data[lenTest] == data[(size_t)lenTest - backOffset]; lenTest++);
+ repLens[i] = lenTest;
+ if (lenTest > repLens[repMaxIndex])
repMaxIndex = i;
}
- if(repLens[repMaxIndex] > _numFastBytes)
+ if(repLens[repMaxIndex] >= _numFastBytes)
{
backRes = repMaxIndex;
lenRes = repLens[repMaxIndex];
- MovePos(lenRes - 1);
- return S_OK;
+ return MovePos(lenRes - 1);
}
- if(lenMain > _numFastBytes)
+ UInt32 *matchDistances = _matchDistances + 1;
+ if(lenMain >= _numFastBytes)
{
- UInt32 backMain = (lenMain < _numFastBytes) ? _matchDistances[lenMain] :
- _matchDistances[_numFastBytes];
- backRes = backMain + kNumRepDistances;
- MovePos(lenMain - 1);
+ backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances;
lenRes = lenMain;
+ return MovePos(lenMain - 1);
+ }
+ Byte currentByte = *data;
+ Byte matchByte = data[(size_t)0 - reps[0] - 1];
+
+ if(lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)
+ {
+ backRes = (UInt32)-1;
+ lenRes = 1;
return S_OK;
}
- Byte currentByte = _matchFinder->GetIndexByte(0 - 1);
_optimum[0].State = _state;
- Byte matchByte;
-
- matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - 1);
-
UInt32 posState = (position & _posStateMask);
- _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice(0) +
- _literalEncoder.GetPrice(position, _previousByte, _peviousIsMatch, matchByte, currentByte);
+ _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() +
+ _literalEncoder.GetSubCoder(position, _previousByte)->GetPrice(!_state.IsCharState(), matchByte, currentByte);
_optimum[1].MakeAsChar();
- _optimum[1].PosPrev = 0;
-
- for (i = 0; i < kNumRepDistances; i++)
- _optimum[0].Backs[i] = reps[i];
-
- UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice(1);
- UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice(1);
+ UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1();
+ UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();
if(matchByte == currentByte)
{
@@ -682,55 +710,75 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
_optimum[1].MakeAsShortRep();
}
}
- if(lenMain < 2)
+ UInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);
+
+ if(lenEnd < 2)
{
backRes = _optimum[1].BackPrev;
lenRes = 1;
return S_OK;
}
-
- UInt32 normalMatchPrice = matchPrice +
- _isRep[_state.Index].GetPrice(0);
+ _optimum[1].PosPrev = 0;
+ for (i = 0; i < kNumRepDistances; i++)
+ _optimum[0].Backs[i] = reps[i];
- if (lenMain <= repLens[repMaxIndex])
- lenMain = 0;
+ UInt32 len = lenEnd;
+ do
+ _optimum[len--].Price = kIfinityPrice;
+ while (len >= 2);
- UInt32 len;
- for(len = 2; len <= lenMain; len++)
+ for(i = 0; i < kNumRepDistances; i++)
{
- _optimum[len].PosPrev = 0;
- _optimum[len].BackPrev = _matchDistances[len] + kNumRepDistances;
- _optimum[len].Price = normalMatchPrice +
- GetPosLenPrice(_matchDistances[len], len, posState);
- _optimum[len].Prev1IsChar = false;
+ UInt32 repLen = repLens[i];
+ if (repLen < 2)
+ continue;
+ UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);
+ do
+ {
+ UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);
+ COptimal &optimum = _optimum[repLen];
+ if (curAndLenPrice < optimum.Price)
+ {
+ optimum.Price = curAndLenPrice;
+ optimum.PosPrev = 0;
+ optimum.BackPrev = i;
+ optimum.Prev1IsChar = false;
+ }
+ }
+ while(--repLen >= 2);
}
- if (lenMain < repLens[repMaxIndex])
- lenMain = repLens[repMaxIndex];
+ UInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();
- for (; len <= lenMain; len++)
- _optimum[len].Price = kIfinityPrice;
-
- for(i = 0; i < kNumRepDistances; i++)
+ len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
+ if (len <= lenMain)
{
- UInt32 repLen = repLens[i];
- for(UInt32 lenTest = 2; lenTest <= repLen; lenTest++)
+ UInt32 offs = 0;
+ while (len > matchDistances[offs])
+ offs += 2;
+ for(; ; len++)
{
- UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);
- COptimal &optimum = _optimum[lenTest];
+ UInt32 distance = matchDistances[offs + 1];
+ UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);
+ COptimal &optimum = _optimum[len];
if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
optimum.PosPrev = 0;
- optimum.BackPrev = i;
+ optimum.BackPrev = distance + kNumRepDistances;
optimum.Prev1IsChar = false;
}
+ if (len == matchDistances[offs])
+ {
+ offs += 2;
+ if (offs == numDistancePairs)
+ break;
+ }
}
}
UInt32 cur = 0;
- UInt32 lenEnd = lenMain;
while(true)
{
@@ -740,16 +788,27 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
lenRes = Backward(backRes, cur);
return S_OK;
}
+ UInt32 newLen, numDistancePairs;
+ RINOK(ReadMatchDistances(newLen, numDistancePairs));
+ if(newLen >= _numFastBytes)
+ {
+ _numDistancePairs = numDistancePairs;
+ _longestMatchLength = newLen;
+ _longestMatchWasFound = true;
+ lenRes = Backward(backRes, cur);
+ return S_OK;
+ }
position++;
- UInt32 posPrev = _optimum[cur].PosPrev;
+ COptimal &curOptimum = _optimum[cur];
+ UInt32 posPrev = curOptimum.PosPrev;
CState state;
- if (_optimum[cur].Prev1IsChar)
+ if (curOptimum.Prev1IsChar)
{
posPrev--;
- if (_optimum[cur].Prev2)
+ if (curOptimum.Prev2)
{
- state = _optimum[_optimum[cur].PosPrev2].State;
- if (_optimum[cur].BackPrev2 < kNumRepDistances)
+ state = _optimum[curOptimum.PosPrev2].State;
+ if (curOptimum.BackPrev2 < kNumRepDistances)
state.UpdateRep();
else
state.UpdateMatch();
@@ -760,83 +819,60 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
}
else
state = _optimum[posPrev].State;
- bool prevWasMatch;
if (posPrev == cur - 1)
{
- if (_optimum[cur].IsShortRep())
- {
- prevWasMatch = true;
+ if (curOptimum.IsShortRep())
state.UpdateShortRep();
- }
else
- {
- prevWasMatch = false;
state.UpdateChar();
- }
- /*
- if (_optimum[cur].Prev1IsChar)
- for(int i = 0; i < kNumRepDistances; i++)
- reps[i] = _optimum[posPrev].Backs[i];
- */
}
else
{
- prevWasMatch = true;
UInt32 pos;
- if (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)
+ if (curOptimum.Prev1IsChar && curOptimum.Prev2)
{
- posPrev = _optimum[cur].PosPrev2;
- pos = _optimum[cur].BackPrev2;
+ posPrev = curOptimum.PosPrev2;
+ pos = curOptimum.BackPrev2;
state.UpdateRep();
}
else
{
- pos = _optimum[cur].BackPrev;
+ pos = curOptimum.BackPrev;
if (pos < kNumRepDistances)
state.UpdateRep();
else
state.UpdateMatch();
}
+ const COptimal &prevOptimum = _optimum[posPrev];
if (pos < kNumRepDistances)
{
- reps[0] = _optimum[posPrev].Backs[pos];
+ reps[0] = prevOptimum.Backs[pos];
UInt32 i;
for(i = 1; i <= pos; i++)
- reps[i] = _optimum[posPrev].Backs[i - 1];
+ reps[i] = prevOptimum.Backs[i - 1];
for(; i < kNumRepDistances; i++)
- reps[i] = _optimum[posPrev].Backs[i];
+ reps[i] = prevOptimum.Backs[i];
}
else
{
reps[0] = (pos - kNumRepDistances);
for(UInt32 i = 1; i < kNumRepDistances; i++)
- reps[i] = _optimum[posPrev].Backs[i - 1];
+ reps[i] = prevOptimum.Backs[i - 1];
}
}
- _optimum[cur].State = state;
+ curOptimum.State = state;
for(UInt32 i = 0; i < kNumRepDistances; i++)
- _optimum[cur].Backs[i] = reps[i];
- UInt32 newLen;
- RINOK(ReadMatchDistances(newLen));
- if(newLen > _numFastBytes)
- {
- _longestMatchLength = newLen;
- _longestMatchWasFound = true;
- lenRes = Backward(backRes, cur);
- return S_OK;
- }
- UInt32 curPrice = _optimum[cur].Price;
- // Byte currentByte = _matchFinder->GetIndexByte(0 - 1);
- // Byte matchByte = _matchFinder->GetIndexByte(0 - reps[0] - 1 - 1);
+ curOptimum.Backs[i] = reps[i];
+ UInt32 curPrice = curOptimum.Price;
const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;
- Byte currentByte = *data;
- Byte matchByte = data[(size_t)0 - reps[0] - 1];
+ const Byte currentByte = *data;
+ const Byte matchByte = data[(size_t)0 - reps[0] - 1];
UInt32 posState = (position & _posStateMask);
UInt32 curAnd1Price = curPrice +
- _isMatch[state.Index][posState].GetPrice(0) +
- _literalEncoder.GetPrice(position, data[(size_t)0 - 1], prevWasMatch, matchByte, currentByte);
+ _isMatch[state.Index][posState].GetPrice0() +
+ _literalEncoder.GetSubCoder(position, data[(size_t)0 - 1])->GetPrice(!state.IsCharState(), matchByte, currentByte);
COptimal &nextOptimum = _optimum[cur + 1];
@@ -849,8 +885,8 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
nextIsChar = true;
}
- UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice(1);
- UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice(1);
+ UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();
+ UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();
if(matchByte == currentByte &&
!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))
@@ -861,28 +897,30 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
nextOptimum.Price = shortRepPrice;
nextOptimum.PosPrev = cur;
nextOptimum.MakeAsShortRep();
- // nextIsChar = false;
+ nextIsChar = true;
}
}
/*
- if(newLen == 2 && _matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?
+ if(newLen == 2 && matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?
continue;
*/
- UInt32 numAvailableBytes = _matchFinder->GetNumAvailableBytes() + 1;
- numAvailableBytes = MyMin(kNumOpts - 1 - cur, numAvailableBytes);
+ UInt32 numAvailableBytesFull = _matchFinder->GetNumAvailableBytes() + 1;
+ numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull);
+ UInt32 numAvailableBytes = numAvailableBytesFull;
if (numAvailableBytes < 2)
continue;
if (numAvailableBytes > _numFastBytes)
numAvailableBytes = _numFastBytes;
- if (numAvailableBytes >= 3 && !nextIsChar)
+ if (!nextIsChar && matchByte != currentByte) // speed optimization
{
+ // try Literal + rep0
UInt32 backOffset = reps[0] + 1;
+ UInt32 limit = MyMin(numAvailableBytesFull, _numFastBytes + 1);
UInt32 temp;
- for (temp = 1; temp < numAvailableBytes; temp++)
- if (data[temp] != data[(size_t)temp - backOffset])
- break;
+ for (temp = 1; temp < limit &&
+ data[temp] == data[(size_t)temp - backOffset]; temp++);
UInt32 lenTest2 = temp - 1;
if (lenTest2 >= 2)
{
@@ -890,15 +928,16 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
state2.UpdateChar();
UInt32 posStateNext = (position + 1) & _posStateMask;
UInt32 nextRepMatchPrice = curAnd1Price +
- _isMatch[state2.Index][posStateNext].GetPrice(1) +
- _isRep[state2.Index].GetPrice(1);
+ _isMatch[state2.Index][posStateNext].GetPrice1() +
+ _isRep[state2.Index].GetPrice1();
// for (; lenTest2 >= 2; lenTest2--)
{
- while(lenEnd < cur + 1 + lenTest2)
+ UInt32 offset = cur + 1 + lenTest2;
+ while(lenEnd < offset)
_optimum[++lenEnd].Price = kIfinityPrice;
UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(
0, lenTest2, state2, posStateNext);
- COptimal &optimum = _optimum[cur + 1 + lenTest2];
+ COptimal &optimum = _optimum[offset];
if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
@@ -910,19 +949,25 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
}
}
}
+
+ UInt32 startLen = 2; // speed optimization
for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)
{
// UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;
UInt32 backOffset = reps[repIndex] + 1;
+ if (data[0] != data[(size_t)0 - backOffset] ||
+ data[1] != data[(size_t)1 - backOffset])
+ continue;
UInt32 lenTest;
- for (lenTest = 0; lenTest < numAvailableBytes; lenTest++)
- if (data[lenTest] != data[(size_t)lenTest - backOffset])
- break;
- for(; lenTest >= 2; lenTest--)
+ for (lenTest = 2; lenTest < numAvailableBytes &&
+ data[lenTest] == data[(size_t)lenTest - backOffset]; lenTest++);
+ while(lenEnd < cur + lenTest)
+ _optimum[++lenEnd].Price = kIfinityPrice;
+ UInt32 lenTestTemp = lenTest;
+ UInt32 price = repMatchPrice + GetPureRepPrice(repIndex, state, posState);
+ do
{
- while(lenEnd < cur + lenTest)
- _optimum[++lenEnd].Price = kIfinityPrice;
- UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);
+ UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState);
COptimal &optimum = _optimum[cur + lenTest];
if (curAndLenPrice < optimum.Price)
{
@@ -931,37 +976,44 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
optimum.BackPrev = repIndex;
optimum.Prev1IsChar = false;
}
-
- /*
- if (_maxMode)
+ }
+ while(--lenTest >= 2);
+ lenTest = lenTestTemp;
+
+ if (repIndex == 0)
+ startLen = lenTest + 1;
+
+ // if (_maxMode)
{
- UInt32 temp;
- for (temp = lenTest + 1; temp < numAvailableBytes; temp++)
- if (data[temp] != data[(size_t)temp - backOffset])
- break;
- UInt32 lenTest2 = temp - (lenTest + 1);
+ UInt32 lenTest2 = lenTest + 1;
+ UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);
+ for (; lenTest2 < limit &&
+ data[lenTest2] == data[(size_t)lenTest2 - backOffset]; lenTest2++);
+ lenTest2 -= lenTest + 1;
if (lenTest2 >= 2)
{
CState state2 = state;
state2.UpdateRep();
UInt32 posStateNext = (position + lenTest) & _posStateMask;
- UInt32 curAndLenCharPrice = curAndLenPrice +
- _isMatch[state2.Index][posStateNext].GetPrice(0) +
- _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1],
+ UInt32 curAndLenCharPrice =
+ price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState) +
+ _isMatch[state2.Index][posStateNext].GetPrice0() +
+ _literalEncoder.GetSubCoder(position + lenTest, data[(size_t)lenTest - 1])->GetPrice(
true, data[(size_t)lenTest - backOffset], data[lenTest]);
state2.UpdateChar();
posStateNext = (position + lenTest + 1) & _posStateMask;
- UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice(1);
- UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice(1);
+ UInt32 nextRepMatchPrice = curAndLenCharPrice +
+ _isMatch[state2.Index][posStateNext].GetPrice1() +
+ _isRep[state2.Index].GetPrice1();
// for(; lenTest2 >= 2; lenTest2--)
{
- UInt32 offset = lenTest + 1 + lenTest2;
- while(lenEnd < cur + offset)
+ UInt32 offset = cur + lenTest + 1 + lenTest2;
+ while(lenEnd < offset)
_optimum[++lenEnd].Price = kIfinityPrice;
UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(
0, lenTest2, state2, posStateNext);
- COptimal &optimum = _optimum[cur + offset];
+ COptimal &optimum = _optimum[offset];
if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
@@ -975,26 +1027,38 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
}
}
}
- */
}
- }
// for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)
if (newLen > numAvailableBytes)
+ {
newLen = numAvailableBytes;
- if (newLen >= 2)
+ for (numDistancePairs = 0; newLen > matchDistances[numDistancePairs]; numDistancePairs += 2);
+ matchDistances[numDistancePairs] = newLen;
+ numDistancePairs += 2;
+ }
+ if (newLen >= startLen)
{
- if (newLen == 2 && _matchDistances[2] >= 0x80)
- continue;
- UInt32 normalMatchPrice = matchPrice +
- _isRep[state.Index].GetPrice(0);
+ UInt32 normalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();
while(lenEnd < cur + newLen)
_optimum[++lenEnd].Price = kIfinityPrice;
- for(UInt32 lenTest = newLen; lenTest >= 2; lenTest--)
+ UInt32 offs = 0;
+ while(startLen > matchDistances[offs])
+ offs += 2;
+ UInt32 curBack = matchDistances[offs + 1];
+ UInt32 posSlot = GetPosSlot2(curBack);
+ for(UInt32 lenTest = /*2*/ startLen; ; lenTest++)
{
- UInt32 curBack = _matchDistances[lenTest];
- UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);
+ UInt32 curAndLenPrice = normalMatchPrice;
+ UInt32 lenToPosState = GetLenToPosState(lenTest);
+ if (curBack < kNumFullDistances)
+ curAndLenPrice += _distancesPrices[lenToPosState][curBack];
+ else
+ curAndLenPrice += _posSlotPrices[lenToPosState][posSlot] + _alignPrices[curBack & kAlignMask];
+
+ curAndLenPrice += _lenEncoder.GetPrice(lenTest - kMatchMinLen, posState);
+
COptimal &optimum = _optimum[cur + lenTest];
if (curAndLenPrice < optimum.Price)
{
@@ -1004,36 +1068,37 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
optimum.Prev1IsChar = false;
}
- if (_maxMode)
+ if (/*_maxMode && */lenTest == matchDistances[offs])
{
+ // Try Match + Literal + Rep0
UInt32 backOffset = curBack + 1;
- UInt32 temp;
- for (temp = lenTest + 1; temp < numAvailableBytes; temp++)
- if (data[temp] != data[(size_t)temp - backOffset])
- break;
- UInt32 lenTest2 = temp - (lenTest + 1);
+ UInt32 lenTest2 = lenTest + 1;
+ UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);
+ for (; lenTest2 < limit &&
+ data[lenTest2] == data[(size_t)lenTest2 - backOffset]; lenTest2++);
+ lenTest2 -= lenTest + 1;
if (lenTest2 >= 2)
{
CState state2 = state;
state2.UpdateMatch();
UInt32 posStateNext = (position + lenTest) & _posStateMask;
UInt32 curAndLenCharPrice = curAndLenPrice +
- _isMatch[state2.Index][posStateNext].GetPrice(0) +
- _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1],
+ _isMatch[state2.Index][posStateNext].GetPrice0() +
+ _literalEncoder.GetSubCoder(position + lenTest, data[(size_t)lenTest - 1])->GetPrice(
true, data[(size_t)lenTest - backOffset], data[lenTest]);
state2.UpdateChar();
- posStateNext = (position + lenTest + 1) & _posStateMask;
- UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice(1);
- UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice(1);
+ posStateNext = (posStateNext + 1) & _posStateMask;
+ UInt32 nextRepMatchPrice = curAndLenCharPrice +
+ _isMatch[state2.Index][posStateNext].GetPrice1() +
+ _isRep[state2.Index].GetPrice1();
// for(; lenTest2 >= 2; lenTest2--)
{
- UInt32 offset = lenTest + 1 + lenTest2;
- while(lenEnd < cur + offset)
+ UInt32 offset = cur + lenTest + 1 + lenTest2;
+ while(lenEnd < offset)
_optimum[++lenEnd].Price = kIfinityPrice;
- UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(
- 0, lenTest2, state2, posStateNext);
- COptimal &optimum = _optimum[cur + offset];
+ UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);
+ COptimal &optimum = _optimum[offset];
if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
@@ -1046,6 +1111,12 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
}
}
}
+ offs += 2;
+ if (offs == numDistancePairs)
+ break;
+ curBack = matchDistances[offs + 1];
+ if (curBack >= kNumFullDistances)
+ posSlot = GetPosSlot2(curBack);
}
}
}
@@ -1054,102 +1125,140 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
static inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)
{
- const int kDif = 7;
- return (smallDist < (UInt32(1) << (32-kDif)) && bigDist >= (smallDist << kDif));
+ return ((bigDist >> 7) > smallDist);
}
-HRESULT CEncoder::ReadMatchDistances(UInt32 &lenRes)
+HRESULT CEncoder::ReadMatchDistances(UInt32 &lenRes, UInt32 &numDistancePairs)
{
- lenRes = _matchFinder->GetLongestMatch(_matchDistances);
- if (lenRes == _numFastBytes)
- lenRes += _matchFinder->GetMatchLen(lenRes, _matchDistances[lenRes],
- kMatchMaxLen - lenRes);
+ lenRes = 0;
+ RINOK(_matchFinder->GetMatches(_matchDistances));
+ numDistancePairs = _matchDistances[0];
+ if (numDistancePairs > 0)
+ {
+ lenRes = _matchDistances[1 + numDistancePairs - 2];
+ if (lenRes == _numFastBytes)
+ lenRes += _matchFinder->GetMatchLen(lenRes - 1, _matchDistances[1 + numDistancePairs - 1],
+ kMatchMaxLen - lenRes);
+ }
_additionalOffset++;
- return _matchFinder->MovePos();
+ return S_OK;
}
HRESULT CEncoder::GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes)
{
- UInt32 lenMain;
+ UInt32 lenMain, numDistancePairs;
if (!_longestMatchWasFound)
{
- RINOK(ReadMatchDistances(lenMain));
+ RINOK(ReadMatchDistances(lenMain, numDistancePairs));
}
else
{
lenMain = _longestMatchLength;
+ numDistancePairs = _numDistancePairs;
_longestMatchWasFound = false;
}
+
+ const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;
+ UInt32 numAvailableBytes = _matchFinder->GetNumAvailableBytes() + 1;
+ if (numAvailableBytes > kMatchMaxLen)
+ numAvailableBytes = kMatchMaxLen;
+ if (numAvailableBytes < 2)
+ {
+ backRes = (UInt32)(-1);
+ lenRes = 1;
+ return S_OK;
+ }
+
UInt32 repLens[kNumRepDistances];
UInt32 repMaxIndex = 0;
+
for(UInt32 i = 0; i < kNumRepDistances; i++)
{
- repLens[i] = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);
- if (i == 0 || repLens[i] > repLens[repMaxIndex])
+ UInt32 backOffset = _repDistances[i] + 1;
+ if (data[0] != data[(size_t)0 - backOffset] || data[1] != data[(size_t)1 - backOffset])
+ {
+ repLens[i] = 0;
+ continue;
+ }
+ UInt32 len;
+ for (len = 2; len < numAvailableBytes && data[len] == data[(size_t)len - backOffset]; len++);
+ if(len >= _numFastBytes)
+ {
+ backRes = i;
+ lenRes = len;
+ return MovePos(lenRes - 1);
+ }
+ repLens[i] = len;
+ if (len > repLens[repMaxIndex])
repMaxIndex = i;
}
- if(repLens[repMaxIndex] >= _numFastBytes)
- {
- backRes = repMaxIndex;
- lenRes = repLens[repMaxIndex];
- MovePos(lenRes - 1);
- return S_OK;
- }
+ UInt32 *matchDistances = _matchDistances + 1;
if(lenMain >= _numFastBytes)
{
- backRes = _matchDistances[_numFastBytes] + kNumRepDistances;
- MovePos(lenMain - 1);
+ backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances;
lenRes = lenMain;
- return S_OK;
+ return MovePos(lenMain - 1);
}
- while (lenMain > 2)
+
+ UInt32 backMain = 0; // for GCC
+ if (lenMain >= 2)
{
- if (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))
- break;
- lenMain--;
+ backMain = matchDistances[numDistancePairs - 1];
+ while (numDistancePairs > 2 && lenMain == matchDistances[numDistancePairs - 4] + 1)
+ {
+ if (!ChangePair(matchDistances[numDistancePairs - 3], backMain))
+ break;
+ numDistancePairs -= 2;
+ lenMain = matchDistances[numDistancePairs - 2];
+ backMain = matchDistances[numDistancePairs - 1];
+ }
+ if (lenMain == 2 && backMain >= 0x80)
+ lenMain = 1;
}
- if (lenMain == 2 && _matchDistances[2] >= 0x80)
- lenMain = 1;
- UInt32 backMain = _matchDistances[lenMain];
if (repLens[repMaxIndex] >= 2)
{
if (repLens[repMaxIndex] + 1 >= lenMain ||
- repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1<<12)))
+ repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9)) ||
+ repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15)))
{
backRes = repMaxIndex;
lenRes = repLens[repMaxIndex];
- MovePos(lenRes - 1);
- return S_OK;
+ return MovePos(lenRes - 1);
}
}
-
- if (lenMain >= 2)
+ if (lenMain >= 2 && numAvailableBytes > 2)
{
- RINOK(ReadMatchDistances(_longestMatchLength));
- if (_longestMatchLength >= 2 &&
- (
- (_longestMatchLength >= lenMain &&
- _matchDistances[lenMain] < backMain) ||
- _longestMatchLength == lenMain + 1 &&
- !ChangePair(backMain, _matchDistances[_longestMatchLength]) ||
- _longestMatchLength > lenMain + 1 ||
- _longestMatchLength + 1 >= lenMain &&
- ChangePair(_matchDistances[lenMain - 1], backMain)
- )
- )
+ RINOK(ReadMatchDistances(_longestMatchLength, _numDistancePairs));
+ if (_longestMatchLength >= 2)
{
- _longestMatchWasFound = true;
- backRes = UInt32(-1);
- lenRes = 1;
- return S_OK;
+ UInt32 newDistance = matchDistances[_numDistancePairs - 1];
+ if (_longestMatchLength >= lenMain && newDistance < backMain ||
+ _longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance) ||
+ _longestMatchLength > lenMain + 1 ||
+ _longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain))
+ {
+ _longestMatchWasFound = true;
+ backRes = UInt32(-1);
+ lenRes = 1;
+ return S_OK;
+ }
}
+ data++;
+ numAvailableBytes--;
for(UInt32 i = 0; i < kNumRepDistances; i++)
{
- UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);
- if (repLen >= 2 && repLen + 1 >= lenMain)
+ UInt32 backOffset = _repDistances[i] + 1;
+ if (data[1] != data[(size_t)1 - backOffset] || data[2] != data[(size_t)2 - backOffset])
+ {
+ repLens[i] = 0;
+ continue;
+ }
+ UInt32 len;
+ for (len = 2; len < numAvailableBytes && data[len] == data[(size_t)len - backOffset]; len++);
+ if (len + 1 >= lenMain)
{
_longestMatchWasFound = true;
backRes = UInt32(-1);
@@ -1158,23 +1267,18 @@ HRESULT CEncoder::GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRe
}
}
backRes = backMain + kNumRepDistances;
- MovePos(lenMain - 2);
lenRes = lenMain;
- return S_OK;
+ return MovePos(lenMain - 2);
}
backRes = UInt32(-1);
lenRes = 1;
return S_OK;
}
-STDMETHODIMP CEncoder::InitMatchFinder(IMatchFinder *matchFinder)
-{
- _matchFinder = matchFinder;
- return S_OK;
-}
-
-HRESULT CEncoder::Flush()
+HRESULT CEncoder::Flush(UInt32 nowPos)
{
+ ReleaseMFStream();
+ WriteEndMarker(nowPos & _posStateMask);
_rangeEncoder.FlushData();
return _rangeEncoder.FlushStream();
}
@@ -1190,7 +1294,7 @@ void CEncoder::WriteEndMarker(UInt32 posState)
_isRep[_state.Index].Encode(&_rangeEncoder, 0);
_state.UpdateMatch();
UInt32 len = kMatchMinLen; // kMatchMaxLen;
- _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);
+ _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);
UInt32 posSlot = (1 << kNumPosSlotBits) - 1;
UInt32 lenToPosState = GetLenToPosState(len);
_posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);
@@ -1230,7 +1334,8 @@ HRESULT CEncoder::SetStreams(ISequentialInStream *inStream,
_inStream = inStream;
_finished = false;
RINOK(Create());
- RINOK(Init(outStream));
+ RINOK(SetOutStream(outStream));
+ RINOK(Init());
// CCoderReleaser releaser(this);
@@ -1241,17 +1346,15 @@ HRESULT CEncoder::SetStreams(ISequentialInStream *inStream,
if (!_fastMode)
{
- FillPosSlotPrices();
FillDistancesPrices();
FillAlignPrices();
}
- _lenEncoder.SetTableSize(_numFastBytes);
+ _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);
_lenEncoder.UpdateTables(1 << _posStateBits);
- _repMatchLenEncoder.SetTableSize(_numFastBytes);
+ _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);
_repMatchLenEncoder.UpdateTables(1 << _posStateBits);
- lastPosSlotFillingPos = 0;
nowPos64 = 0;
return S_OK;
}
@@ -1260,7 +1363,8 @@ HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)
{
if (_inStream != 0)
{
- RINOK(_matchFinder->Init(_inStream));
+ RINOK(_matchFinder->SetStream(_inStream));
+ RINOK(_matchFinder->Init());
_needReleaseMFStream = true;
_inStream = 0;
}
@@ -1271,18 +1375,12 @@ HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)
return S_OK;
_finished = true;
-
- UInt64 progressPosValuePrev = nowPos64;
if (nowPos64 == 0)
{
if (_matchFinder->GetNumAvailableBytes() == 0)
- {
- ReleaseStreams();
- WriteEndMarker(UInt32(nowPos64) & _posStateMask);
- return Flush();
- }
- UInt32 len; // it's not used
- RINOK(ReadMatchDistances(len));
+ return Flush(UInt32(nowPos64));
+ UInt32 len, numDistancePairs;
+ RINOK(ReadMatchDistances(len, numDistancePairs));
UInt32 posState = UInt32(nowPos64) & _posStateMask;
_isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);
_state.UpdateChar();
@@ -1292,48 +1390,45 @@ HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)
_additionalOffset--;
nowPos64++;
}
+
+ UInt32 nowPos32 = (UInt32)nowPos64;
+ UInt32 progressPosValuePrev = nowPos32;
+
if (_matchFinder->GetNumAvailableBytes() == 0)
- {
- ReleaseStreams();
- WriteEndMarker(UInt32(nowPos64) & _posStateMask);
- return Flush();
- }
+ return Flush(nowPos32);
+
while(true)
{
#ifdef _NO_EXCEPTIONS
if (_rangeEncoder.Stream.ErrorCode != S_OK)
return _rangeEncoder.Stream.ErrorCode;
#endif
- UInt32 pos;
- UInt32 posState = UInt32(nowPos64) & _posStateMask;
-
- UInt32 len;
+ UInt32 pos, len;
HRESULT result;
if (_fastMode)
- result = GetOptimumFast(UInt32(nowPos64), pos, len);
+ result = GetOptimumFast(nowPos32, pos, len);
else
- result = GetOptimum(UInt32(nowPos64), pos, len);
+ result = GetOptimum(nowPos32, pos, len);
RINOK(result);
+ UInt32 posState = nowPos32 & _posStateMask;
if(len == 1 && pos == 0xFFFFFFFF)
{
_isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);
- _state.UpdateChar();
Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);
- CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte);
- if(_peviousIsMatch)
+ CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(nowPos32, _previousByte);
+ if(_state.IsCharState())
+ subCoder->Encode(&_rangeEncoder, curByte);
+ else
{
Byte matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - _additionalOffset);
subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);
}
- else
- subCoder->Encode(&_rangeEncoder, curByte);
+ _state.UpdateChar();
_previousByte = curByte;
- _peviousIsMatch = false;
}
else
{
- _peviousIsMatch = true;
_isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);
if(pos < kNumRepDistances)
{
@@ -1341,13 +1436,11 @@ HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)
if(pos == 0)
{
_isRepG0[_state.Index].Encode(&_rangeEncoder, 0);
- if(len == 1)
- _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 0);
- else
- _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 1);
+ _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, ((len == 1) ? 0 : 1));
}
else
{
+ UInt32 distance = _repDistances[pos];
_isRepG0[_state.Index].Encode(&_rangeEncoder, 1);
if (pos == 1)
_isRepG1[_state.Index].Encode(&_rangeEncoder, 0);
@@ -1355,34 +1448,29 @@ HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)
{
_isRepG1[_state.Index].Encode(&_rangeEncoder, 1);
_isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);
+ if (pos == 3)
+ _repDistances[3] = _repDistances[2];
+ _repDistances[2] = _repDistances[1];
}
+ _repDistances[1] = _repDistances[0];
+ _repDistances[0] = distance;
}
if (len == 1)
_state.UpdateShortRep();
else
{
- _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);
+ _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);
_state.UpdateRep();
}
-
-
- UInt32 distance = _repDistances[pos];
- if (pos != 0)
- {
- for(UInt32 i = pos; i >= 1; i--)
- _repDistances[i] = _repDistances[i - 1];
- _repDistances[0] = distance;
- }
}
else
{
_isRep[_state.Index].Encode(&_rangeEncoder, 0);
_state.UpdateMatch();
- _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);
+ _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);
pos -= kNumRepDistances;
UInt32 posSlot = GetPosSlot(pos);
- UInt32 lenToPosState = GetLenToPosState(len);
- _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);
+ _posSlotEncoder[GetLenToPosState(len)].Encode(&_rangeEncoder, posSlot);
if (posSlot >= kStartPosModelIndex)
{
@@ -1397,39 +1485,35 @@ HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)
{
_rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
_posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);
- if (!_fastMode)
- if (--_alignPriceCount == 0)
- FillAlignPrices();
+ _alignPriceCount++;
}
}
- UInt32 distance = pos;
- for(UInt32 i = kNumRepDistances - 1; i >= 1; i--)
- _repDistances[i] = _repDistances[i - 1];
- _repDistances[0] = distance;
+ _repDistances[3] = _repDistances[2];
+ _repDistances[2] = _repDistances[1];
+ _repDistances[1] = _repDistances[0];
+ _repDistances[0] = pos;
+ _matchPriceCount++;
}
_previousByte = _matchFinder->GetIndexByte(len - 1 - _additionalOffset);
}
_additionalOffset -= len;
- nowPos64 += len;
- if (!_fastMode)
- if (nowPos64 - lastPosSlotFillingPos >= (1 << 9))
- {
- FillPosSlotPrices();
- FillDistancesPrices();
- lastPosSlotFillingPos = nowPos64;
- }
+ nowPos32 += len;
if (_additionalOffset == 0)
{
- *inSize = nowPos64;
- *outSize = _rangeEncoder.GetProcessedSize();
- if (_matchFinder->GetNumAvailableBytes() == 0)
+ if (!_fastMode)
{
- ReleaseStreams();
- WriteEndMarker(UInt32(nowPos64) & _posStateMask);
- return Flush();
+ if (_matchPriceCount >= (1 << 7))
+ FillDistancesPrices();
+ if (_alignPriceCount >= kAlignTableSize)
+ FillAlignPrices();
}
- if (nowPos64 - progressPosValuePrev >= (1 << 12))
+ if (_matchFinder->GetNumAvailableBytes() == 0)
+ return Flush(nowPos32);
+ if (nowPos32 - progressPosValuePrev >= (1 << 14))
{
+ nowPos64 += nowPos32 - progressPosValuePrev;
+ *inSize = nowPos64;
+ *outSize = _rangeEncoder.GetProcessedSize();
_finished = false;
*finished = 0;
return S_OK;
@@ -1454,45 +1538,43 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
#endif
}
-void CEncoder::FillPosSlotPrices()
+void CEncoder::FillDistancesPrices()
{
- for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)
- {
- UInt32 posSlot;
- for (posSlot = 0; posSlot < kEndPosModelIndex && posSlot < _distTableSize; posSlot++)
- _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);
- for (; posSlot < _distTableSize; posSlot++)
- _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) +
- ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);
+ UInt32 tempPrices[kNumFullDistances];
+ for (UInt32 i = kStartPosModelIndex; i < kNumFullDistances; i++)
+ {
+ UInt32 posSlot = GetPosSlot(i);
+ UInt32 footerBits = ((posSlot >> 1) - 1);
+ UInt32 base = ((2 | (posSlot & 1)) << footerBits);
+ tempPrices[i] = NRangeCoder::ReverseBitTreeGetPrice(_posEncoders +
+ base - posSlot - 1, footerBits, i - base);
}
-}
-void CEncoder::FillDistancesPrices()
-{
for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)
{
+ UInt32 posSlot;
+ NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> &encoder = _posSlotEncoder[lenToPosState];
+ UInt32 *posSlotPrices = _posSlotPrices[lenToPosState];
+ for (posSlot = 0; posSlot < _distTableSize; posSlot++)
+ posSlotPrices[posSlot] = encoder.GetPrice(posSlot);
+ for (posSlot = kEndPosModelIndex; posSlot < _distTableSize; posSlot++)
+ posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);
+
+ UInt32 *distancesPrices = _distancesPrices[lenToPosState];
UInt32 i;
for (i = 0; i < kStartPosModelIndex; i++)
- _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][i];
+ distancesPrices[i] = posSlotPrices[i];
for (; i < kNumFullDistances; i++)
- {
- UInt32 posSlot = GetPosSlot(i);
- UInt32 footerBits = ((posSlot >> 1) - 1);
- UInt32 base = ((2 | (posSlot & 1)) << footerBits);
-
- _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][posSlot] +
- NRangeCoder::ReverseBitTreeGetPrice(_posEncoders +
- base - posSlot - 1, footerBits, i - base);
-
- }
+ distancesPrices[i] = posSlotPrices[GetPosSlot(i)] + tempPrices[i];
}
+ _matchPriceCount = 0;
}
void CEncoder::FillAlignPrices()
{
for (UInt32 i = 0; i < kAlignTableSize; i++)
_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);
- _alignPriceCount = kAlignTableSize;
+ _alignPriceCount = 0;
}
}}
diff --git a/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.h b/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.h
index de722c9..5fe8d4c 100755
--- a/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.h
+++ b/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.h
@@ -1,4 +1,19 @@
-// LZMA/Encoder.h
+/*
+ * LZMAEncoder.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __LZMA_ENCODER_H
#define __LZMA_ENCODER_H
@@ -21,13 +36,11 @@ class CBaseState
protected:
CState _state;
Byte _previousByte;
- bool _peviousIsMatch;
UInt32 _repDistances[kNumRepDistances];
void Init()
{
_state.Init();
_previousByte = 0;
- _peviousIsMatch = false;
for(UInt32 i = 0 ; i < kNumRepDistances; i++)
_repDistances[i] = 0;
}
@@ -53,23 +66,23 @@ struct COptimal
};
-extern Byte g_FastPos[1024];
+extern Byte g_FastPos[1 << 11];
inline UInt32 GetPosSlot(UInt32 pos)
{
- if (pos < (1 << 10))
+ if (pos < (1 << 11))
return g_FastPos[pos];
- if (pos < (1 << 19))
- return g_FastPos[pos >> 9] + 18;
- return g_FastPos[pos >> 18] + 36;
+ if (pos < (1 << 21))
+ return g_FastPos[pos >> 10] + 20;
+ return g_FastPos[pos >> 20] + 40;
}
inline UInt32 GetPosSlot2(UInt32 pos)
{
- if (pos < (1 << 16))
+ if (pos < (1 << 17))
return g_FastPos[pos >> 6] + 12;
- if (pos < (1 << 25))
- return g_FastPos[pos >> 15] + 30;
- return g_FastPos[pos >> 24] + 48;
+ if (pos < (1 << 27))
+ return g_FastPos[pos >> 16] + 32;
+ return g_FastPos[pos >> 26] + 52;
}
const UInt32 kIfinityPrice = 0xFFFFFFF;
@@ -107,8 +120,7 @@ public:
}
bool Create(int numPosBits, int numPrevBits)
{
- if (_coders == 0 || (numPosBits + numPrevBits) !=
- (_numPrevBits + _numPosBits) )
+ if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))
{
Free();
UInt32 numStates = 1 << (numPosBits + numPrevBits);
@@ -125,21 +137,8 @@ public:
for (UInt32 i = 0; i < numStates; i++)
_coders[i].Init();
}
- UInt32 GetState(UInt32 pos, Byte prevByte) const
- { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }
CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)
- { return &_coders[GetState(pos, prevByte)]; }
- /*
- void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte,
- Byte symbol)
- { _coders[GetState(pos, prevByte)].Encode(rangeEncoder, symbol); }
- void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte,
- Byte matchByte, Byte symbol)
- { _coders[GetState(pos, prevByte)].Encode(rangeEncoder,
- matchByte, symbol); }
- */
- UInt32 GetPrice(UInt32 pos, Byte prevByte, bool matchMode, Byte matchByte, Byte symbol) const
- { return _coders[GetState(pos, prevByte)].GetPrice(matchMode, matchByte, symbol); }
+ { return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }
};
namespace NLength {
@@ -147,31 +146,29 @@ namespace NLength {
class CEncoder
{
CMyBitEncoder _choice;
- NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];
- CMyBitEncoder _choice2;
- NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];
- NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;
+ CMyBitEncoder _choice2;
+ NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];
+ NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];
+ NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;
public:
void Init(UInt32 numPosStates);
void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);
- UInt32 GetPrice(UInt32 symbol, UInt32 posState) const;
+ void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;
};
const UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;
class CPriceTableEncoder: public CEncoder
{
- UInt32 _prices[kNumSymbolsTotal][kNumPosStatesEncodingMax];
+ UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];
UInt32 _tableSize;
UInt32 _counters[kNumPosStatesEncodingMax];
public:
void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }
- UInt32 GetPrice(UInt32 symbol, UInt32 posState) const
- { return _prices[symbol][posState]; }
+ UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }
void UpdateTable(UInt32 posState)
{
- for (UInt32 len = 0; len < _tableSize; len++)
- _prices[len][posState] = CEncoder::GetPrice(len, posState);
+ SetPrices(posState, _tableSize, _prices[posState]);
_counters[posState] = _tableSize;
}
void UpdateTables(UInt32 numPosStates)
@@ -179,20 +176,20 @@ public:
for (UInt32 posState = 0; posState < numPosStates; posState++)
UpdateTable(posState);
}
- void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)
+ void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)
{
CEncoder::Encode(rangeEncoder, symbol, posState);
- if (--_counters[posState] == 0)
- UpdateTable(posState);
+ if (updatePrice)
+ if (--_counters[posState] == 0)
+ UpdateTable(posState);
}
};
}
-
class CEncoder :
public ICompressCoder,
- // public IInitMatchFinder,
+ public ICompressSetOutStream,
public ICompressSetCoderProperties,
public ICompressWriteCoderProperties,
public CBaseState,
@@ -201,8 +198,6 @@ class CEncoder :
COptimal _optimum[kNumOpts];
CMyComPtr<IMatchFinder> _matchFinder; // test it
NRangeCoder::CEncoder _rangeEncoder;
-public:
-private:
CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];
CMyBitEncoder _isRep[kNumStates];
@@ -221,12 +216,13 @@ private:
CLiteralEncoder _literalEncoder;
- UInt32 _matchDistances[kMatchMaxLen + 1];
+ UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];
bool _fastMode;
- bool _maxMode;
+ // bool _maxMode;
UInt32 _numFastBytes;
UInt32 _longestMatchLength;
+ UInt32 _numDistancePairs;
UInt32 _additionalOffset;
@@ -254,11 +250,12 @@ private:
UInt32 _dictionarySizePrev;
UInt32 _numFastBytesPrev;
- UInt64 lastPosSlotFillingPos;
+ UInt32 _matchPriceCount;
UInt64 nowPos64;
bool _finished;
ISequentialInStream *_inStream;
+ UInt32 _matchFinderCycles;
int _matchFinderIndex;
#ifdef COMPRESS_MF_MT
bool _multiThread;
@@ -267,36 +264,50 @@ private:
bool _writeEndMark;
bool _needReleaseMFStream;
+
+ IMatchFinderSetNumPasses *setMfPasses;
+
+ void ReleaseMatchFinder()
+ {
+ setMfPasses = 0;
+ _matchFinder.Release();
+ }
- HRESULT ReadMatchDistances(UInt32 &len);
+ HRESULT ReadMatchDistances(UInt32 &len, UInt32 &numDistancePairs);
HRESULT MovePos(UInt32 num);
UInt32 GetRepLen1Price(CState state, UInt32 posState) const
{
- return _isRepG0[state.Index].GetPrice(0) +
- _isRep0Long[state.Index][posState].GetPrice(0);
+ return _isRepG0[state.Index].GetPrice0() +
+ _isRep0Long[state.Index][posState].GetPrice0();
}
- UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const
+
+ UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const
{
- UInt32 price = _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState);
+ UInt32 price;
if(repIndex == 0)
{
- price += _isRepG0[state.Index].GetPrice(0);
- price += _isRep0Long[state.Index][posState].GetPrice(1);
+ price = _isRepG0[state.Index].GetPrice0();
+ price += _isRep0Long[state.Index][posState].GetPrice1();
}
else
{
- price += _isRepG0[state.Index].GetPrice(1);
+ price = _isRepG0[state.Index].GetPrice1();
if (repIndex == 1)
- price += _isRepG1[state.Index].GetPrice(0);
+ price += _isRepG1[state.Index].GetPrice0();
else
{
- price += _isRepG1[state.Index].GetPrice(1);
+ price += _isRepG1[state.Index].GetPrice1();
price += _isRepG2[state.Index].GetPrice(repIndex - 2);
}
}
return price;
}
+ UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const
+ {
+ return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +
+ GetPureRepPrice(repIndex, state, posState);
+ }
/*
UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const
{
@@ -318,8 +329,6 @@ private:
*/
UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const
{
- if (len == 2 && pos >= 0x80)
- return kIfinityPrice;
UInt32 price;
UInt32 lenToPosState = GetLenToPosState(len);
if (pos < kNumFullDistances)
@@ -334,21 +343,25 @@ private:
HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);
HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);
- void FillPosSlotPrices();
void FillDistancesPrices();
void FillAlignPrices();
- void ReleaseStreams()
+ void ReleaseMFStream()
{
if (_matchFinder && _needReleaseMFStream)
{
_matchFinder->ReleaseStream();
_needReleaseMFStream = false;
}
- // _rangeEncoder.ReleaseStream();
}
- HRESULT Flush();
+ void ReleaseStreams()
+ {
+ ReleaseMFStream();
+ ReleaseOutStream();
+ }
+
+ HRESULT Flush(UInt32 nowPos);
class CCoderReleaser
{
CEncoder *_coder;
@@ -370,13 +383,13 @@ public:
HRESULT Create();
- MY_UNKNOWN_IMP2(
+ MY_UNKNOWN_IMP3(
+ ICompressSetOutStream,
ICompressSetCoderProperties,
ICompressWriteCoderProperties
)
- STDMETHOD(Init)(
- ISequentialOutStream *outStream);
+ HRESULT Init();
// ICompressCoder interface
HRESULT SetStreams(ISequentialInStream *inStream,
@@ -395,9 +408,6 @@ public:
const UInt64 *inSize, const UInt64 *outSize,
ICompressProgressInfo *progress);
- // IInitMatchFinder interface
- STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder);
-
// ICompressSetCoderProperties2
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
const PROPVARIANT *properties, UInt32 numProperties);
@@ -405,6 +415,9 @@ public:
// ICompressWriteCoderProperties
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
+ STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);
+ STDMETHOD(ReleaseOutStream)();
+
virtual ~CEncoder() {}
};
diff --git a/Source/7zip/7zip/Compress/LZMA/StdAfx.h b/Source/7zip/7zip/Compress/LZMA/StdAfx.h
index 59eb30a..83fdd22 100755
--- a/Source/7zip/7zip/Compress/LZMA/StdAfx.h
+++ b/Source/7zip/7zip/Compress/LZMA/StdAfx.h
@@ -3,6 +3,6 @@
#ifndef __STDAFX_H
#define __STDAFX_H
-#include "../../../../Platform.h"
+#include "../../../Common/MyWindows.h"
-#endif
+#endif
diff --git a/Source/7zip/7zip/Compress/RangeCoder/RangeCoder.h b/Source/7zip/7zip/Compress/RangeCoder/RangeCoder.h
index ac68829..cbf5524 100755
--- a/Source/7zip/7zip/Compress/RangeCoder/RangeCoder.h
+++ b/Source/7zip/7zip/Compress/RangeCoder/RangeCoder.h
@@ -1,4 +1,19 @@
-// Compress/RangeCoder/RangeCoder.h
+/*
+ * RangeCoder.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __COMPRESS_RANGECODER_H
#define __COMPRESS_RANGECODER_H
@@ -14,20 +29,21 @@ const UInt32 kTopValue = (1 << kNumTopBits);
class CEncoder
{
- UInt64 Low;
- UInt32 Range;
- UInt32 _ffNum;
+ UInt32 _cacheSize;
Byte _cache;
public:
+ UInt64 Low;
+ UInt32 Range;
COutBuffer Stream;
bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
- void Init(ISequentialOutStream *stream)
+ void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }
+ void Init()
{
- Stream.Init(stream);
+ Stream.Init();
Low = 0;
Range = 0xFFFFFFFF;
- _ffNum = 0;
+ _cacheSize = 1;
_cache = 0;
}
@@ -40,10 +56,7 @@ public:
HRESULT FlushStream() { return Stream.Flush(); }
- /*
- void ReleaseStream()
- { Stream.ReleaseStream(); }
- */
+ void ReleaseStream() { Stream.ReleaseStream(); }
void Encode(UInt32 start, UInt32 size, UInt32 total)
{
@@ -56,36 +69,21 @@ public:
}
}
- /*
- void EncodeDirectBitsDiv(UInt32 value, UInt32 numTotalBits)
- {
- Low += value * (Range >>= numTotalBits);
- Normalize();
- }
-
- void EncodeDirectBitsDiv2(UInt32 value, UInt32 numTotalBits)
- {
- if (numTotalBits <= kNumBottomBits)
- EncodeDirectBitsDiv(value, numTotalBits);
- else
- {
- EncodeDirectBitsDiv(value >> kNumBottomBits, (numTotalBits - kNumBottomBits));
- EncodeDirectBitsDiv(value & ((1 << kBottomValueBits) - 1), kNumBottomBits);
- }
- }
- */
void ShiftLow()
{
- if (Low < (UInt32)0xFF000000 || UInt32(Low >> 32) == 1)
+ if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)
{
- Stream.WriteByte(Byte(_cache + Byte(Low >> 32)));
- for (;_ffNum != 0; _ffNum--)
- Stream.WriteByte(Byte(0xFF + Byte(Low >> 32)));
- _cache = Byte(UInt32(Low) >> 24);
+ Byte temp = _cache;
+ do
+ {
+ Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));
+ temp = 0xFF;
+ }
+ while(--_cacheSize != 0);
+ _cache = (Byte)((UInt32)Low >> 24);
}
- else
- _ffNum++;
- Low = UInt32(Low) << 8;
+ _cacheSize++;
+ Low = (UInt32)Low << 8;
}
void EncodeDirectBits(UInt32 value, int numTotalBits)
@@ -120,7 +118,7 @@ public:
}
}
- UInt64 GetProcessedSize() { return Stream.GetProcessedSize() + _ffNum; }
+ UInt64 GetProcessedSize() { return Stream.GetProcessedSize() + _cacheSize + 4; }
};
class CDecoder
@@ -140,16 +138,17 @@ public:
}
}
- void Init(ISequentialInStream *stream)
+ void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }
+ void Init()
{
- Stream.Init(stream);
+ Stream.Init();
Code = 0;
Range = 0xFFFFFFFF;
for(int i = 0; i < 5; i++)
Code = (Code << 8) | Stream.ReadByte();
}
- // void ReleaseStream() { Stream.ReleaseStream(); }
+ void ReleaseStream() { Stream.ReleaseStream(); }
UInt32 GetThreshold(UInt32 total)
{
@@ -163,32 +162,12 @@ public:
Normalize();
}
- /*
- UInt32 DecodeDirectBitsDiv(UInt32 numTotalBits)
- {
- Range >>= numTotalBits;
- UInt32 threshold = Code / Range;
- Code -= threshold * Range;
-
- Normalize();
- return threshold;
- }
-
- UInt32 DecodeDirectBitsDiv2(UInt32 numTotalBits)
- {
- if (numTotalBits <= kNumBottomBits)
- return DecodeDirectBitsDiv(numTotalBits);
- UInt32 result = DecodeDirectBitsDiv(numTotalBits - kNumBottomBits) << kNumBottomBits;
- return (result | DecodeDirectBitsDiv(kNumBottomBits));
- }
- */
-
- UInt32 DecodeDirectBits(UInt32 numTotalBits)
+ UInt32 DecodeDirectBits(int numTotalBits)
{
UInt32 range = Range;
UInt32 code = Code;
UInt32 result = 0;
- for (UInt32 i = numTotalBits; i > 0; i--)
+ for (int i = numTotalBits; i != 0; i--)
{
range >>= 1;
/*
@@ -201,7 +180,6 @@ public:
*/
UInt32 t = (code - range) >> 31;
code -= range & (t - 1);
- // range = rangeTmp + ((range & 1) & (1 - t));
result = (result << 1) | (1 - t);
if (range < kTopValue)
diff --git a/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp b/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp
index 8d273c8..235797a 100755
--- a/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp
+++ b/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp
@@ -1,4 +1,19 @@
-// Compress/RangeCoder/RangeCoderBit.cpp
+/*
+ * RangeCoderBit.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "StdAfx.h"
diff --git a/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBit.h b/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBit.h
index c8f6b93..e2e7902 100755
--- a/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBit.h
+++ b/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBit.h
@@ -1,4 +1,19 @@
-// Compress/RangeCoder/RangeCoderBit.h
+/*
+ * RangeCoderBit.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __COMPRESS_RANGECODER_BIT_H
#define __COMPRESS_RANGECODER_BIT_H
@@ -50,9 +65,10 @@ class CBitEncoder: public CBitModel<numMoveBits>
public:
void Encode(CEncoder *encoder, UInt32 symbol)
{
+ /*
encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);
this->UpdateModel(symbol);
- /*
+ */
UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;
if (symbol == 0)
{
@@ -65,18 +81,19 @@ public:
encoder->Range -= newBound;
this->Prob -= (this->Prob) >> numMoveBits;
}
- while (encoder->Range < kTopValue)
+ if (encoder->Range < kTopValue)
{
encoder->Range <<= 8;
encoder->ShiftLow();
}
- */
}
UInt32 GetPrice(UInt32 symbol) const
{
return CPriceTables::ProbPrices[
(((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
}
+ UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }
+ UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }
};
diff --git a/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBitTree.h b/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBitTree.h
index 9ad0151..cd8ae5a 100755
--- a/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBitTree.h
+++ b/Source/7zip/7zip/Compress/RangeCoder/RangeCoderBitTree.h
@@ -1,4 +1,19 @@
-// Compress/RangeCoder/RangeCoderBitTree.h
+/*
+ * RangeCoderBitTree.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __COMPRESS_RANGECODER_BIT_TREE_H
#define __COMPRESS_RANGECODER_BIT_TREE_H
@@ -9,7 +24,7 @@
namespace NCompress {
namespace NRangeCoder {
-template <int numMoveBits, UInt32 NumBitLevels>
+template <int numMoveBits, int NumBitLevels>
class CBitTreeEncoder
{
CBitEncoder<numMoveBits> Models[1 << NumBitLevels];
@@ -22,7 +37,7 @@ public:
void Encode(CEncoder *rangeEncoder, UInt32 symbol)
{
UInt32 modelIndex = 1;
- for (UInt32 bitIndex = NumBitLevels; bitIndex > 0 ;)
+ for (int bitIndex = NumBitLevels; bitIndex != 0 ;)
{
bitIndex--;
UInt32 bit = (symbol >> bitIndex) & 1;
@@ -33,7 +48,7 @@ public:
void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)
{
UInt32 modelIndex = 1;
- for (UInt32 i = 0; i < NumBitLevels; i++)
+ for (int i = 0; i < NumBitLevels; i++)
{
UInt32 bit = symbol & 1;
Models[modelIndex].Encode(rangeEncoder, bit);
@@ -43,14 +58,12 @@ public:
}
UInt32 GetPrice(UInt32 symbol) const
{
+ symbol |= (1 << NumBitLevels);
UInt32 price = 0;
- UInt32 modelIndex = 1;
- for (UInt32 bitIndex = NumBitLevels; bitIndex > 0 ;)
+ while (symbol != 1)
{
- bitIndex--;
- UInt32 bit = (symbol >> bitIndex) & 1;
- price += Models[modelIndex].GetPrice(bit);
- modelIndex = (modelIndex << 1) + bit;
+ price += Models[symbol >> 1].GetPrice(symbol & 1);
+ symbol >>= 1;
}
return price;
}
@@ -58,7 +71,7 @@ public:
{
UInt32 price = 0;
UInt32 modelIndex = 1;
- for (UInt32 i = NumBitLevels; i > 0; i--)
+ for (int i = NumBitLevels; i != 0; i--)
{
UInt32 bit = symbol & 1;
symbol >>= 1;
@@ -69,7 +82,7 @@ public:
}
};
-template <int numMoveBits, UInt32 NumBitLevels>
+template <int numMoveBits, int NumBitLevels>
class CBitTreeDecoder
{
CBitDecoder<numMoveBits> Models[1 << NumBitLevels];
@@ -83,7 +96,7 @@ public:
{
UInt32 modelIndex = 1;
RC_INIT_VAR
- for(UInt32 bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)
+ for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)
{
// modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);
RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)
@@ -96,7 +109,7 @@ public:
UInt32 modelIndex = 1;
UInt32 symbol = 0;
RC_INIT_VAR
- for(UInt32 bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
+ for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
{
// UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
// modelIndex <<= 1;
@@ -111,10 +124,10 @@ public:
template <int numMoveBits>
void ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models,
- CEncoder *rangeEncoder, UInt32 NumBitLevels, UInt32 symbol)
+ CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)
{
UInt32 modelIndex = 1;
- for (UInt32 i = 0; i < NumBitLevels; i++)
+ for (int i = 0; i < NumBitLevels; i++)
{
UInt32 bit = symbol & 1;
Models[modelIndex].Encode(rangeEncoder, bit);
@@ -129,7 +142,7 @@ UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models,
{
UInt32 price = 0;
UInt32 modelIndex = 1;
- for (UInt32 i = NumBitLevels; i > 0; i--)
+ for (int i = NumBitLevels; i != 0; i--)
{
UInt32 bit = symbol & 1;
symbol >>= 1;
@@ -141,12 +154,12 @@ UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models,
template <int numMoveBits>
UInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models,
- CDecoder *rangeDecoder, UInt32 NumBitLevels)
+ CDecoder *rangeDecoder, int NumBitLevels)
{
UInt32 modelIndex = 1;
UInt32 symbol = 0;
RC_INIT_VAR
- for(UInt32 bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
+ for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
{
// UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
// modelIndex <<= 1;
diff --git a/Source/7zip/7zip/Compress/RangeCoder/RangeCoderOpt.h b/Source/7zip/7zip/Compress/RangeCoder/RangeCoderOpt.h
index 829fc83..4b59e82 100755
--- a/Source/7zip/7zip/Compress/RangeCoder/RangeCoderOpt.h
+++ b/Source/7zip/7zip/Compress/RangeCoder/RangeCoderOpt.h
@@ -1,4 +1,19 @@
-// Compress/RangeCoder/RangeCoderOpt.h
+/*
+ * RangeCoderOpt.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __COMPRESS_RANGECODER_OPT_H
#define __COMPRESS_RANGECODER_OPT_H
diff --git a/Source/7zip/7zip/Compress/RangeCoder/StdAfx.h b/Source/7zip/7zip/Compress/RangeCoder/StdAfx.h
index 59eb30a..21c2fd7 100755
--- a/Source/7zip/7zip/Compress/RangeCoder/StdAfx.h
+++ b/Source/7zip/7zip/Compress/RangeCoder/StdAfx.h
@@ -3,6 +3,4 @@
#ifndef __STDAFX_H
#define __STDAFX_H
-#include "../../../../Platform.h"
-
-#endif
+#endif
diff --git a/Source/7zip/7zip/ICoder.h b/Source/7zip/7zip/ICoder.h
index 4811454..a0e93e4 100755
--- a/Source/7zip/7zip/ICoder.h
+++ b/Source/7zip/7zip/ICoder.h
@@ -1,37 +1,46 @@
-// ICoder.h
+/*
+ * ICoder.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __ICODER_H
#define __ICODER_H
#include "IStream.h"
-// {23170F69-40C1-278A-0000-000200040000}
-DEFINE_GUID(IID_ICompressProgressInfo,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200040000")
-ICompressProgressInfo: public IUnknown
+// "23170F69-40C1-278A-0000-000400xx0000"
+#define CODER_INTERFACE(i, x) \
+DEFINE_GUID(IID_ ## i, \
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \
+struct i: public IUnknown
+
+CODER_INTERFACE(ICompressProgressInfo, 0x04)
{
- STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) = 0;
+ STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;
};
-// {23170F69-40C1-278A-0000-000200050000}
-DEFINE_GUID(IID_ICompressCoder,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200050000")
-ICompressCoder: public IUnknown
+CODER_INTERFACE(ICompressCoder, 0x05)
{
STDMETHOD(Code)(ISequentialInStream *inStream,
ISequentialOutStream *outStream,
const UInt64 *inSize,
const UInt64 *outSize,
- ICompressProgressInfo *progress) = 0;
+ ICompressProgressInfo *progress) PURE;
};
-// {23170F69-40C1-278A-0000-000200180000}
-DEFINE_GUID(IID_ICompressCoder2,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x18, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200180000")
-ICompressCoder2: public IUnknown
+CODER_INTERFACE(ICompressCoder2, 0x18)
{
STDMETHOD(Code)(ISequentialInStream **inStreams,
const UInt64 **inSizes,
@@ -54,75 +63,100 @@ namespace NCoderPropID
kLitPosBits,
kNumFastBytes = 0x450,
kMatchFinder,
+ kMatchFinderCycles,
kNumPasses = 0x460,
kAlgorithm = 0x470,
kMultiThread = 0x480,
+ kNumThreads,
kEndMarker = 0x490
};
}
-// {23170F69-40C1-278A-0000-000200200000}
-DEFINE_GUID(IID_ICompressSetCoderProperties,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x20, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200200000")
-ICompressSetCoderProperties: public IUnknown
+CODER_INTERFACE(ICompressSetCoderProperties, 0x20)
{
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
const PROPVARIANT *properties, UInt32 numProperties) PURE;
};
-// {23170F69-40C1-278A-0000-000200210000}
-DEFINE_GUID(IID_ICompressSetDecoderProperties,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x21, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200210000")
-ICompressSetDecoderProperties: public IUnknown
+/*
+CODER_INTERFACE(ICompressSetCoderProperties, 0x21)
{
STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;
};
+*/
-// {23170F69-40C1-278A-0000-000200230000}
-DEFINE_GUID(IID_ICompressWriteCoderProperties,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x23, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200230000")
-ICompressWriteCoderProperties: public IUnknown
+CODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)
+{
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;
+};
+
+CODER_INTERFACE(ICompressWriteCoderProperties, 0x23)
{
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;
};
-// {23170F69-40C1-278A-0000-000200240000}
-DEFINE_GUID(IID_ICompressGetInStreamProcessedSize,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x24, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200240000")
-ICompressGetInStreamProcessedSize: public IUnknown
+CODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)
{
STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;
};
-// {23170F69-40C1-278A-0000-000200250000}
-DEFINE_GUID(IID_ICompressGetSubStreamSize,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x25, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200250000")
-ICompressGetSubStreamSize: public IUnknown
+CODER_INTERFACE(ICompressSetCoderMt, 0x25)
+{
+ STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;
+};
+
+CODER_INTERFACE(ICompressGetSubStreamSize, 0x30)
{
STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;
};
-// {23170F69-40C1-278A-0000-000200260000}
-DEFINE_GUID(IID_ICompressSetInStream,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x26, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200260000")
-ICompressSetInStream: public IUnknown
+CODER_INTERFACE(ICompressSetInStream, 0x31)
+{
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;
+ STDMETHOD(ReleaseInStream)() PURE;
+};
+
+CODER_INTERFACE(ICompressSetOutStream, 0x32)
+{
+ STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;
+ STDMETHOD(ReleaseOutStream)() PURE;
+};
+
+CODER_INTERFACE(ICompressSetInStreamSize, 0x33)
+{
+ STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;
+};
+
+CODER_INTERFACE(ICompressSetOutStreamSize, 0x34)
+{
+ STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;
+};
+
+CODER_INTERFACE(ICompressFilter, 0x40)
+{
+ STDMETHOD(Init)() PURE;
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;
+ // Filter return outSize (UInt32)
+ // if (outSize <= size): Filter have converted outSize bytes
+ // if (outSize > size): Filter have not converted anything.
+ // and it needs at least outSize bytes to convert one block
+ // (it's for crypto block algorithms).
+};
+
+CODER_INTERFACE(ICryptoProperties, 0x80)
+{
+ STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;
+ STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;
+};
+
+CODER_INTERFACE(ICryptoSetPassword, 0x90)
{
- STDMETHOD(SetInStream)(ISequentialInStream *inStream, const UInt64 *inSize) PURE;
+ STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;
};
-// {23170F69-40C1-278A-0000-000200270000}
-DEFINE_GUID(IID_ICompressSetOutStream,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x27, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200270000")
-ICompressSetOutStream: public IUnknown
+CODER_INTERFACE(ICryptoSetCRC, 0xA0)
{
- STDMETHOD(SetOutStream)(ISequentialOutStream *outStream, const UInt64 *outSize) PURE;
+ STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;
};
//////////////////////
diff --git a/Source/7zip/7zip/IStream.h b/Source/7zip/7zip/IStream.h
index c1b83ca..62f6060 100755
--- a/Source/7zip/7zip/IStream.h
+++ b/Source/7zip/7zip/IStream.h
@@ -1,79 +1,77 @@
-// IStream.h
+/*
+ * IStream.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
-#ifndef __ISTREAMS_H
-#define __ISTREAMS_H
+#ifndef __ISTREAM_H
+#define __ISTREAM_H
#include "../Common/MyUnknown.h"
#include "../Common/Types.h"
-// {23170F69-40C1-278A-0000-000000010000}
-DEFINE_GUID(IID_ISequentialInStream,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000000010000")
-ISequentialInStream : public IUnknown
+// "23170F69-40C1-278A-0000-000300xx0000"
+
+#define STREAM_INTERFACE_SUB(i, b, x) \
+DEFINE_GUID(IID_ ## i, \
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \
+struct i: public b
+
+#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)
+
+STREAM_INTERFACE(ISequentialInStream, 0x01)
{
-public:
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) = 0;
- STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize) = 0;
-
- // For both function Out: if (processedSize == 0) then there are
- // no more bytes in stream.
- // Read function always tries to read "size" bytes from stream. It
- // can read less only if it reaches end of stream.
- // ReadPart function can read X bytes: (0<=X<="size") and X can
- // be less than number of remaining bytes in stream.
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;
+ /*
+ Out: if size != 0, return_value = S_OK and (*processedSize == 0),
+ then there are no more bytes in stream.
+ if (size > 0) && there are bytes in stream,
+ this function must read at least 1 byte.
+ This function is allowed to read less than number of remaining bytes in stream.
+ You must call Read function in loop, if you need exact amount of data
+ */
};
-// {23170F69-40C1-278A-0000-000000020000}
-DEFINE_GUID(IID_ISequentialOutStream,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000000020000")
-ISequentialOutStream : public IUnknown
+STREAM_INTERFACE(ISequentialOutStream, 0x02)
{
-public:
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) = 0;
- STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize) = 0;
+ STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;
+ /*
+ if (size > 0) this function must write at least 1 byte.
+ This function is allowed to write less than "size".
+ You must call Write function in loop, if you need to write exact amount of data
+ */
};
-// {23170F69-40C1-278A-0000-000000030000}
-DEFINE_GUID(IID_IInStream,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000000030000")
-IInStream : public ISequentialInStream
+STREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)
{
-public:
- STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) = 0;
+ STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
};
-// {23170F69-40C1-278A-0000-000000040000}
-DEFINE_GUID(IID_IOutStream,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000000040000")
-IOutStream : public ISequentialOutStream
+STREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)
{
-public:
- STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) = 0;
- STDMETHOD(SetSize)(Int64 newSize) = 0;
+ STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
+ STDMETHOD(SetSize)(Int64 newSize) PURE;
};
-// {23170F69-40C1-278A-0000-000000060000}
-DEFINE_GUID(IID_IStreamGetSize,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000000060000")
-IStreamGetSize : public IUnknown
+STREAM_INTERFACE(IStreamGetSize, 0x06)
{
-public:
- STDMETHOD(GetSize)(UInt64 *size) = 0;
+ STDMETHOD(GetSize)(UInt64 *size) PURE;
};
-// {23170F69-40C1-278A-0000-000000070000}
-DEFINE_GUID(IID_IOutStreamFlush,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000000070000")
-IOutStreamFlush : public IUnknown
+STREAM_INTERFACE(IOutStreamFlush, 0x07)
{
-public:
- STDMETHOD(Flush)() = 0;
+ STDMETHOD(Flush)() PURE;
};
#endif
diff --git a/Source/7zip/Common/Alloc.cpp b/Source/7zip/Common/Alloc.cpp
index 63bcdd4..2898c6d 100755
--- a/Source/7zip/Common/Alloc.cpp
+++ b/Source/7zip/Common/Alloc.cpp
@@ -1,52 +1,133 @@
-// Common/Alloc.cpp
+/*
+ * Alloc.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "StdAfx.h"
-#ifndef WIN32
+#ifdef _WIN32
+#include "MyWindows.h"
+#else
#include <stdlib.h>
#endif
#include "Alloc.h"
-// #include "NewHandler.h"
-void *MyAlloc(size_t size)
+/* #define _SZ_ALLOC_DEBUG */
+/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
+#ifdef _SZ_ALLOC_DEBUG
+#include <stdio.h>
+int g_allocCount = 0;
+int g_allocCountMid = 0;
+int g_allocCountBig = 0;
+#endif
+
+void *MyAlloc(size_t size) throw()
{
+ if (size == 0)
+ return 0;
+ #ifdef _SZ_ALLOC_DEBUG
+ fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount++);
+ #endif
return ::malloc(size);
}
-void MyFree(void *address)
+void MyFree(void *address) throw()
{
+ #ifdef _SZ_ALLOC_DEBUG
+ if (address != 0)
+ fprintf(stderr, "\nFree; count = %10d", --g_allocCount);
+ #endif
+
::free(address);
}
-void *BigAlloc(size_t size)
+#ifdef _WIN32
+
+void *MidAlloc(size_t size) throw()
{
- #ifdef WIN32
- return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
- #else
- return ::malloc(size);
+ if (size == 0)
+ return 0;
+ #ifdef _SZ_ALLOC_DEBUG
+ fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++);
#endif
+ return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
}
-void BigFree(void *address)
+void MidFree(void *address) throw()
{
+ #ifdef _SZ_ALLOC_DEBUG
+ if (address != 0)
+ fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
+ #endif
if (address == 0)
return;
- #ifdef WIN32
::VirtualFree(address, 0, MEM_RELEASE);
- #else
- ::free(address);
+}
+
+static SIZE_T g_LargePageSize =
+ #ifdef _WIN64
+ (1 << 21);
+ #else
+ (1 << 22);
+ #endif
+
+typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
+
+bool SetLargePageSize()
+{
+ GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
+ ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
+ if (largePageMinimum == 0)
+ return false;
+ SIZE_T size = largePageMinimum();
+ if (size == 0 || (size & (size - 1)) != 0)
+ return false;
+ g_LargePageSize = size;
+ return true;
+}
+
+
+void *BigAlloc(size_t size) throw()
+{
+ if (size == 0)
+ return 0;
+ #ifdef _SZ_ALLOC_DEBUG
+ fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
#endif
+
+ if (size >= (1 << 18))
+ {
+ void *res = ::VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
+ MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
+ if (res != 0)
+ return res;
+ }
+ return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
}
-/*
-void *BigAllocE(size_t size)
+void BigFree(void *address) throw()
{
- void *res = BigAlloc(size);
- #ifndef _NO_EXCEPTIONS
- if (res == 0)
- throw CNewException();
+ #ifdef _SZ_ALLOC_DEBUG
+ if (address != 0)
+ fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
#endif
- return res;
+
+ if (address == 0)
+ return;
+ ::VirtualFree(address, 0, MEM_RELEASE);
}
-*/
+
+#endif
diff --git a/Source/7zip/Common/Alloc.h b/Source/7zip/Common/Alloc.h
index b4d4918..93705a1 100755
--- a/Source/7zip/Common/Alloc.h
+++ b/Source/7zip/Common/Alloc.h
@@ -1,14 +1,44 @@
-// Common/Alloc.h
+/*
+ * Alloc.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __COMMON_ALLOC_H
#define __COMMON_ALLOC_H
#include <stddef.h>
-void *MyAlloc(size_t size);
-void MyFree(void *address);
-void *BigAlloc(size_t size);
-void BigFree(void *address);
-// void *BigAllocE(size_t size);
+void *MyAlloc(size_t size) throw();
+void MyFree(void *address) throw();
+
+#ifdef _WIN32
+
+bool SetLargePageSize();
+
+void *MidAlloc(size_t size) throw();
+void MidFree(void *address) throw();
+void *BigAlloc(size_t size) throw();
+void BigFree(void *address) throw();
+
+#else
+
+#define MidAlloc(size) MyAlloc(size)
+#define MidFree(address) MyFree(address)
+#define BigAlloc(size) MyAlloc(size)
+#define BigFree(address) MyFree(address)
+
+#endif
#endif
diff --git a/Source/7zip/Common/CRC.cpp b/Source/7zip/Common/CRC.cpp
index 213c828..998a579 100755
--- a/Source/7zip/Common/CRC.cpp
+++ b/Source/7zip/Common/CRC.cpp
@@ -1,4 +1,19 @@
-// Common/CRC.cpp
+/*
+ * CRC.cpp
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "StdAfx.h"
@@ -28,24 +43,30 @@ public:
CCRCTableInit() { CCRC::InitTable(); }
} g_CRCTableInit;
-void CCRC::Update(Byte b)
+void CCRC::UpdateByte(Byte b)
{
_value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);
}
-void CCRC::Update(UInt32 v)
+void CCRC::UpdateUInt16(UInt16 v)
+{
+ UpdateByte(Byte(v));
+ UpdateByte(Byte(v >> 8));
+}
+
+void CCRC::UpdateUInt32(UInt32 v)
{
for (int i = 0; i < 4; i++)
- Update((Byte)(v >> (8 * i)));
+ UpdateByte((Byte)(v >> (8 * i)));
}
-void CCRC::Update(const UInt64 &v)
+void CCRC::UpdateUInt64(UInt64 v)
{
for (int i = 0; i < 8; i++)
- Update((Byte)(v >> (8 * i)));
+ UpdateByte((Byte)(v >> (8 * i)));
}
-void CCRC::Update(const void *data, UInt32 size)
+void CCRC::Update(const void *data, size_t size)
{
UInt32 v = _value;
const Byte *p = (const Byte *)data;
diff --git a/Source/7zip/Common/CRC.h b/Source/7zip/Common/CRC.h
index 364a252..e01c72f 100755
--- a/Source/7zip/Common/CRC.h
+++ b/Source/7zip/Common/CRC.h
@@ -1,8 +1,24 @@
-// Common/CRC.h
+/*
+ * CRC.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __COMMON_CRC_H
#define __COMMON_CRC_H
+#include <stddef.h>
#include "Types.h"
class CCRC
@@ -14,18 +30,19 @@ public:
CCRC(): _value(0xFFFFFFFF){};
void Init() { _value = 0xFFFFFFFF; }
- void Update(Byte v);
- void Update(UInt32 v);
- void Update(const UInt64 &v);
- void Update(const void *data, UInt32 size);
+ void UpdateByte(Byte v);
+ void UpdateUInt16(UInt16 v);
+ void UpdateUInt32(UInt32 v);
+ void UpdateUInt64(UInt64 v);
+ void Update(const void *data, size_t size);
UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
- static UInt32 CalculateDigest(const void *data, UInt32 size)
+ static UInt32 CalculateDigest(const void *data, size_t size)
{
CCRC crc;
crc.Update(data, size);
return crc.GetDigest();
}
- static bool VerifyDigest(UInt32 digest, const void *data, UInt32 size)
+ static bool VerifyDigest(UInt32 digest, const void *data, size_t size)
{
return (CalculateDigest(data, size) == digest);
}
diff --git a/Source/7zip/Common/Defs.h b/Source/7zip/Common/Defs.h
index 69b8ece..f1746a8 100755
--- a/Source/7zip/Common/Defs.h
+++ b/Source/7zip/Common/Defs.h
@@ -1,4 +1,19 @@
-// Common/Defs.h
+/*
+ * Defs.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __COMMON_DEFS_H
#define __COMMON_DEFS_H
diff --git a/Source/7zip/Common/MyCom.h b/Source/7zip/Common/MyCom.h
index 1b97dfd..119aaff 100755
--- a/Source/7zip/Common/MyCom.h
+++ b/Source/7zip/Common/MyCom.h
@@ -1,4 +1,19 @@
-// MyCom.h
+/*
+ * MyCom.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __MYCOM_H
#define __MYCOM_H
@@ -50,7 +65,7 @@ public:
_p = NULL;
return pt;
}
- #ifdef WIN32
+ #ifdef _WIN32
HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
{
return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);
@@ -148,8 +163,10 @@ public:
#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \
(REFGUID iid, void **outObject) {
+
#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \
{ *outObject = (void *)(i *)this; AddRef(); return S_OK; }
+
#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }
#define MY_ADDREF_RELEASE \
@@ -164,7 +181,9 @@ STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \
MY_ADDREF_RELEASE
-#define MY_UNKNOWN_IMP MY_UNKNOWN_IMP_SPEC(;)
+#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \
+ MY_QUERYINTERFACE_END \
+ MY_ADDREF_RELEASE
#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \
MY_QUERYINTERFACE_ENTRY(i) \
@@ -174,11 +193,13 @@ STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \
MY_QUERYINTERFACE_ENTRY(i1) \
MY_QUERYINTERFACE_ENTRY(i2) \
)
+
#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \
MY_QUERYINTERFACE_ENTRY(i1) \
MY_QUERYINTERFACE_ENTRY(i2) \
MY_QUERYINTERFACE_ENTRY(i3) \
)
+
#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \
MY_QUERYINTERFACE_ENTRY(i1) \
MY_QUERYINTERFACE_ENTRY(i2) \
diff --git a/Source/7zip/Common/MyGuidDef.h b/Source/7zip/Common/MyGuidDef.h
new file mode 100755
index 0000000..5e2cf4a
--- /dev/null
+++ b/Source/7zip/Common/MyGuidDef.h
@@ -0,0 +1,69 @@
+/*
+ * MyGuidDef.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#ifndef GUID_DEFINED
+#define GUID_DEFINED
+
+#include "Types.h"
+
+typedef struct {
+ UInt32 Data1;
+ UInt16 Data2;
+ UInt16 Data3;
+ unsigned char Data4[8];
+} GUID;
+
+#ifdef __cplusplus
+#define REFGUID const GUID &
+#else
+#define REFGUID const GUID *
+#endif
+
+#define REFCLSID REFGUID
+#define REFIID REFGUID
+
+#ifdef __cplusplus
+inline bool operator==(REFGUID g1, REFGUID g2)
+{
+ for (int i = 0; i < (int)sizeof(g1); i++)
+ if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])
+ return false;
+ return true;
+}
+inline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }
+#endif
+
+#ifdef __cplusplus
+ #define MY_EXTERN_C extern "C"
+#else
+ #define MY_EXTERN_C extern
+#endif
+
+#endif // GUID_DEFINED
+
+
+#ifdef DEFINE_GUID
+#undef DEFINE_GUID
+#endif
+
+#ifdef INITGUID
+ #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
+ MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
+#else
+ #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
+ MY_EXTERN_C const GUID name
+#endif
diff --git a/Source/7zip/Common/MyUnknown.h b/Source/7zip/Common/MyUnknown.h
index fa61c66..7508b60 100755
--- a/Source/7zip/Common/MyUnknown.h
+++ b/Source/7zip/Common/MyUnknown.h
@@ -1,11 +1,25 @@
-// MyUnknown.h
+/*
+ * MyUnknown.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __MYUNKNOWN_H
#define __MYUNKNOWN_H
-#ifdef WIN32
+#ifdef _WIN32
-// #include <guiddef.h>
#ifdef _WIN32_WCE
#if (_WIN32_WCE > 300)
#include <basetyps.h>
diff --git a/Source/7zip/Common/MyWindows.h b/Source/7zip/Common/MyWindows.h
index 9ac7051..02f8710 100755
--- a/Source/7zip/Common/MyWindows.h
+++ b/Source/7zip/Common/MyWindows.h
@@ -1,23 +1,88 @@
-// MyWindows.h
+/*
+ * MyWindows.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __MYWINDOWS_H
#define __MYWINDOWS_H
-#ifndef WIN32
+#include "../../Platform.h"
+
+#ifdef _WIN32
+
+#include <windows.h>
+
+/*
+#define CHAR_PATH_SEPARATOR '\\'
+#define WCHAR_PATH_SEPARATOR L'\\'
+#define STRING_PATH_SEPARATOR "\\"
+#define WSTRING_PATH_SEPARATOR L"\\"
+*/
+
+#else
+/*
+#define CHAR_PATH_SEPARATOR '/'
+#define WCHAR_PATH_SEPARATOR L'/'
+#define STRING_PATH_SEPARATOR "/"
+#define WSTRING_PATH_SEPARATOR L"/"
+
+#include <stddef.h> // for wchar_t
#include <string.h>
+*/
+#include "MyGuidDef.h"
+/*
+typedef char CHAR;
+typedef unsigned char UCHAR;
-#include "../../Platform.h"
+#undef BYTE
+typedef unsigned char BYTE;
-#include "Types.h"
+typedef short SHORT;
+typedef unsigned short USHORT;
+#undef WORD
+typedef unsigned short WORD;
typedef short VARIANT_BOOL;
-typedef wchar_t OLECHAR;
+typedef int INT;
+typedef Int32 INT32;
+typedef unsigned int UINT;
+typedef UInt32 UINT32;
+typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit
+typedef UINT32 ULONG;
+
+#undef DWORD
+typedef UINT32 DWORD;
+
+typedef Int64 LONGLONG;
+typedef UInt64 ULONGLONG;
+
+typedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;
+typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;
+
+typedef const CHAR *LPCSTR;
+typedef CHAR TCHAR;
+typedef const TCHAR *LPCTSTR;
+typedef wchar_t WCHAR;
+typedef WCHAR OLECHAR;
+typedef const WCHAR *LPCWSTR;
typedef OLECHAR *BSTR;
typedef const OLECHAR *LPCOLESTR;
typedef OLECHAR *LPOLESTR;
-
+*/
typedef struct _FILETIME
{
DWORD dwLowDateTime;
@@ -31,6 +96,7 @@ typedef LONG SCODE;
#define S_OK ((HRESULT)0x00000000L)
#define S_FALSE ((HRESULT)0x00000001L)
+#define E_NOTIMPL ((HRESULT)0x80004001L)
#define E_NOINTERFACE ((HRESULT)0x80004002L)
#define E_ABORT ((HRESULT)0x80004004L)
#define E_FAIL ((HRESULT)0x80004005L)
@@ -51,46 +117,7 @@ typedef LONG SCODE;
#define PURE = 0
-typedef struct {
- unsigned long Data1;
- unsigned short Data2;
- unsigned short Data3;
- unsigned char Data4[8];
-} GUID;
-
-#ifdef __cplusplus
- #define MY_EXTERN_C extern "C"
-#else
- #define MY_EXTERN_C extern
-#endif
-
-#ifdef INITGUID
- #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
- MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
-#else
- #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
- MY_EXTERN_C const GUID name
-#endif
-
-#ifdef __cplusplus
-#define REFGUID const GUID &
-#else
-#define REFGUID const GUID * __MIDL_CONST
-#endif
-
-#define REFCLSID REFGUID
-#define REFIID REFGUID
-
#define MIDL_INTERFACE(x) struct
-inline bool operator==(REFGUID g1, REFGUID g2)
-{
- for (size_t i = 0; i < sizeof(g1); i++)
- if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])
- return false;
- return true;
-}
-inline bool operator!=(REFGUID g1, REFGUID g2)
- { return !(g1 == g2); }
struct IUnknown
{
@@ -164,20 +191,20 @@ typedef struct tagPROPVARIANT
};
} PROPVARIANT;
-typedef tagPROPVARIANT tagVARIANT;
+typedef PROPVARIANT tagVARIANT;
typedef tagVARIANT VARIANT;
typedef VARIANT VARIANTARG;
-BSTR SysAllocStringByteLen(LPCSTR psz, unsigned int len);
-BSTR SysAllocString(const OLECHAR *sz);
-void SysFreeString(BSTR bstr);
-UINT SysStringByteLen(BSTR bstr);
-UINT SysStringLen(BSTR bstr);
+MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);
+MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);
+MY_EXTERN_C void SysFreeString(BSTR bstr);
+MY_EXTERN_C UINT SysStringByteLen(BSTR bstr);
+MY_EXTERN_C UINT SysStringLen(BSTR bstr);
-DWORD GetLastError();
-HRESULT VariantClear(VARIANTARG *prop);
-HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);
-LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);
+MY_EXTERN_C DWORD GetLastError();
+MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);
+MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);
+MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);
#define CP_ACP 0
#define CP_OEMCP 1
diff --git a/Source/7zip/Common/StdAfx.h b/Source/7zip/Common/StdAfx.h
index ad99cbb..af02b27 100755
--- a/Source/7zip/Common/StdAfx.h
+++ b/Source/7zip/Common/StdAfx.h
@@ -1,8 +1,23 @@
-// StdAfx.h
+/*
+ * StdAfx.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __STDAFX_H
#define __STDAFX_H
-#include "../../Platform.h"
+// #include "MyWindows.h"
#endif
diff --git a/Source/7zip/Common/Types.h b/Source/7zip/Common/Types.h
index 52d0708..10791e4 100755
--- a/Source/7zip/Common/Types.h
+++ b/Source/7zip/Common/Types.h
@@ -1,19 +1,72 @@
-// Common/Types.h
+/*
+ * Types.h
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2006 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __COMMON_TYPES_H
#define __COMMON_TYPES_H
+#ifndef _7ZIP_BYTE_DEFINED
+#define _7ZIP_BYTE_DEFINED
typedef unsigned char Byte;
+#endif
+
+#ifndef _7ZIP_INT16_DEFINED
+#define _7ZIP_INT16_DEFINED
typedef short Int16;
+#endif
+
+#ifndef _7ZIP_UINT16_DEFINED
+#define _7ZIP_UINT16_DEFINED
typedef unsigned short UInt16;
+#endif
+
+#ifndef _7ZIP_INT32_DEFINED
+#define _7ZIP_INT32_DEFINED
typedef int Int32;
+#endif
+
+#ifndef _7ZIP_UINT32_DEFINED
+#define _7ZIP_UINT32_DEFINED
typedef unsigned int UInt32;
+#endif
+
#ifdef _MSC_VER
+
+#ifndef _7ZIP_INT64_DEFINED
+#define _7ZIP_INT64_DEFINED
typedef __int64 Int64;
+#endif
+
+#ifndef _7ZIP_UINT64_DEFINED
+#define _7ZIP_UINT64_DEFINED
typedef unsigned __int64 UInt64;
+#endif
+
#else
+
+#ifndef _7ZIP_INT64_DEFINED
+#define _7ZIP_INT64_DEFINED
typedef long long int Int64;
+#endif
+
+#ifndef _7ZIP_UINT64_DEFINED
+#define _7ZIP_UINT64_DEFINED
typedef unsigned long long int UInt64;
+#endif
+
#endif
#endif
diff --git a/Source/7zip/LZMADecode.c b/Source/7zip/LZMADecode.c
index d212fa3..e16d4c0 100755
--- a/Source/7zip/LZMADecode.c
+++ b/Source/7zip/LZMADecode.c
@@ -1,10 +1,19 @@
/*
-LzmaDecode.c
-LZMA Decoder
-LZMA SDK 4.01 Copyright (c) 1999-2004 Igor Pavlov (2004-02-15)
-
-Converted to a state machine by Amir Szekely
-*/
+ * LZMADecode.c
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2007 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include <stdlib.h>
#include "LZMADecode.h"
diff --git a/Source/7zip/LZMADecode.h b/Source/7zip/LZMADecode.h
index a5c65b3..dddf709 100755
--- a/Source/7zip/LZMADecode.h
+++ b/Source/7zip/LZMADecode.h
@@ -1,10 +1,19 @@
-/*
-LzmaDecode.h
-LZMA Decoder interface
-LZMA SDK 4.01 Copyright (c) 1999-2004 Igor Pavlov (2004-02-15)
-
-Converted to a state machine by Amir Szekely
-*/
+/*
+ * LZMADecode.c
+ *
+ * This file is a part of LZMA compression module for NSIS.
+ *
+ * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
+ * Modifications Copyright (C) 2003-2007 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the Common Public License version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef __LZMADECODE_H
#define __LZMADECODE_H
@@ -14,14 +23,15 @@ Converted to a state machine by Amir Szekely
***********************/
#include "../Platform.h"
-#include "../exehead/util.h"
/* #define _LZMA_PROB32 */
/* It can increase speed on some 32-bit CPUs,
but memory usage will be doubled in that case */
-#define lzmaalloc(bytes) GlobalAlloc(GPTR,bytes)
-#define lzmafree GlobalFree
+#ifdef _WIN32
+# define lzmaalloc(bytes) GlobalAlloc(GPTR,bytes)
+# define lzmafree GlobalFree
+#endif
/***********************
* Configuration End *
diff --git a/Source/7zip/copying.txt b/Source/7zip/copying.txt
deleted file mode 100755
index f3926a6..0000000
--- a/Source/7zip/copying.txt
+++ /dev/null
@@ -1,504 +0,0 @@
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 2.1, February 1999
-
- Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-[This is the first released version of the Lesser GPL. It also counts
- as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-Licenses are intended to guarantee your freedom to share and change
-free software--to make sure the software is free for all its users.
-
- This license, the Lesser General Public License, applies to some
-specially designated software packages--typically libraries--of the
-Free Software Foundation and other authors who decide to use it. You
-can use it too, but we suggest you first think carefully about whether
-this license or the ordinary General Public License is the better
-strategy to use in any particular case, based on the explanations below.
-
- When we speak of free software, we are referring to freedom of use,
-not price. Our General Public Licenses are designed to make sure that
-you have the freedom to distribute copies of free software (and charge
-for this service if you wish); that you receive source code or can get
-it if you want it; that you can change the software and use pieces of
-it in new free programs; and that you are informed that you can do
-these things.
-
- To protect your rights, we need to make restrictions that forbid
-distributors to deny you these rights or to ask you to surrender these
-rights. These restrictions translate to certain responsibilities for
-you if you distribute copies of the library or if you modify it.
-
- For example, if you distribute copies of the library, whether gratis
-or for a fee, you must give the recipients all the rights that we gave
-you. You must make sure that they, too, receive or can get the source
-code. If you link other code with the library, you must provide
-complete object files to the recipients, so that they can relink them
-with the library after making changes to the library and recompiling
-it. And you must show them these terms so they know their rights.
-
- We protect your rights with a two-step method: (1) we copyright the
-library, and (2) we offer you this license, which gives you legal
-permission to copy, distribute and/or modify the library.
-
- To protect each distributor, we want to make it very clear that
-there is no warranty for the free library. Also, if the library is
-modified by someone else and passed on, the recipients should know
-that what they have is not the original version, so that the original
-author's reputation will not be affected by problems that might be
-introduced by others.
-
- Finally, software patents pose a constant threat to the existence of
-any free program. We wish to make sure that a company cannot
-effectively restrict the users of a free program by obtaining a
-restrictive license from a patent holder. Therefore, we insist that
-any patent license obtained for a version of the library must be
-consistent with the full freedom of use specified in this license.
-
- Most GNU software, including some libraries, is covered by the
-ordinary GNU General Public License. This license, the GNU Lesser
-General Public License, applies to certain designated libraries, and
-is quite different from the ordinary General Public License. We use
-this license for certain libraries in order to permit linking those
-libraries into non-free programs.
-
- When a program is linked with a library, whether statically or using
-a shared library, the combination of the two is legally speaking a
-combined work, a derivative of the original library. The ordinary
-General Public License therefore permits such linking only if the
-entire combination fits its criteria of freedom. The Lesser General
-Public License permits more lax criteria for linking other code with
-the library.
-
- We call this license the "Lesser" General Public License because it
-does Less to protect the user's freedom than the ordinary General
-Public License. It also provides other free software developers Less
-of an advantage over competing non-free programs. These disadvantages
-are the reason we use the ordinary General Public License for many
-libraries. However, the Lesser license provides advantages in certain
-special circumstances.
-
- For example, on rare occasions, there may be a special need to
-encourage the widest possible use of a certain library, so that it becomes
-a de-facto standard. To achieve this, non-free programs must be
-allowed to use the library. A more frequent case is that a free
-library does the same job as widely used non-free libraries. In this
-case, there is little to gain by limiting the free library to free
-software only, so we use the Lesser General Public License.
-
- In other cases, permission to use a particular library in non-free
-programs enables a greater number of people to use a large body of
-free software. For example, permission to use the GNU C Library in
-non-free programs enables many more people to use the whole GNU
-operating system, as well as its variant, the GNU/Linux operating
-system.
-
- Although the Lesser General Public License is Less protective of the
-users' freedom, it does ensure that the user of a program that is
-linked with the Library has the freedom and the wherewithal to run
-that program using a modified version of the Library.
-
- The precise terms and conditions for copying, distribution and
-modification follow. Pay close attention to the difference between a
-"work based on the library" and a "work that uses the library". The
-former contains code derived from the library, whereas the latter must
-be combined with the library in order to run.
-
- GNU LESSER GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any software library or other
-program which contains a notice placed by the copyright holder or
-other authorized party saying it may be distributed under the terms of
-this Lesser General Public License (also called "this License").
-Each licensee is addressed as "you".
-
- A "library" means a collection of software functions and/or data
-prepared so as to be conveniently linked with application programs
-(which use some of those functions and data) to form executables.
-
- The "Library", below, refers to any such software library or work
-which has been distributed under these terms. A "work based on the
-Library" means either the Library or any derivative work under
-copyright law: that is to say, a work containing the Library or a
-portion of it, either verbatim or with modifications and/or translated
-straightforwardly into another language. (Hereinafter, translation is
-included without limitation in the term "modification".)
-
- "Source code" for a work means the preferred form of the work for
-making modifications to it. For a library, complete source code means
-all the source code for all modules it contains, plus any associated
-interface definition files, plus the scripts used to control compilation
-and installation of the library.
-
- Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running a program using the Library is not restricted, and output from
-such a program is covered only if its contents constitute a work based
-on the Library (independent of the use of the Library in a tool for
-writing it). Whether that is true depends on what the Library does
-and what the program that uses the Library does.
-
- 1. You may copy and distribute verbatim copies of the Library's
-complete source code as you receive it, in any medium, provided that
-you conspicuously and appropriately publish on each copy an
-appropriate copyright notice and disclaimer of warranty; keep intact
-all the notices that refer to this License and to the absence of any
-warranty; and distribute a copy of this License along with the
-Library.
-
- You may charge a fee for the physical act of transferring a copy,
-and you may at your option offer warranty protection in exchange for a
-fee.
-
- 2. You may modify your copy or copies of the Library or any portion
-of it, thus forming a work based on the Library, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) The modified work must itself be a software library.
-
- b) You must cause the files modified to carry prominent notices
- stating that you changed the files and the date of any change.
-
- c) You must cause the whole of the work to be licensed at no
- charge to all third parties under the terms of this License.
-
- d) If a facility in the modified Library refers to a function or a
- table of data to be supplied by an application program that uses
- the facility, other than as an argument passed when the facility
- is invoked, then you must make a good faith effort to ensure that,
- in the event an application does not supply such function or
- table, the facility still operates, and performs whatever part of
- its purpose remains meaningful.
-
- (For example, a function in a library to compute square roots has
- a purpose that is entirely well-defined independent of the
- application. Therefore, Subsection 2d requires that any
- application-supplied function or table used by this function must
- be optional: if the application does not supply it, the square
- root function must still compute square roots.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Library,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Library, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote
-it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Library.
-
-In addition, mere aggregation of another work not based on the Library
-with the Library (or with a work based on the Library) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may opt to apply the terms of the ordinary GNU General Public
-License instead of this License to a given copy of the Library. To do
-this, you must alter all the notices that refer to this License, so
-that they refer to the ordinary GNU General Public License, version 2,
-instead of to this License. (If a newer version than version 2 of the
-ordinary GNU General Public License has appeared, then you can specify
-that version instead if you wish.) Do not make any other change in
-these notices.
-
- Once this change is made in a given copy, it is irreversible for
-that copy, so the ordinary GNU General Public License applies to all
-subsequent copies and derivative works made from that copy.
-
- This option is useful when you wish to copy part of the code of
-the Library into a program that is not a library.
-
- 4. You may copy and distribute the Library (or a portion or
-derivative of it, under Section 2) in object code or executable form
-under the terms of Sections 1 and 2 above provided that you accompany
-it with the complete corresponding machine-readable source code, which
-must be distributed under the terms of Sections 1 and 2 above on a
-medium customarily used for software interchange.
-
- If distribution of object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the
-source code from the same place satisfies the requirement to
-distribute the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 5. A program that contains no derivative of any portion of the
-Library, but is designed to work with the Library by being compiled or
-linked with it, is called a "work that uses the Library". Such a
-work, in isolation, is not a derivative work of the Library, and
-therefore falls outside the scope of this License.
-
- However, linking a "work that uses the Library" with the Library
-creates an executable that is a derivative of the Library (because it
-contains portions of the Library), rather than a "work that uses the
-library". The executable is therefore covered by this License.
-Section 6 states terms for distribution of such executables.
-
- When a "work that uses the Library" uses material from a header file
-that is part of the Library, the object code for the work may be a
-derivative work of the Library even though the source code is not.
-Whether this is true is especially significant if the work can be
-linked without the Library, or if the work is itself a library. The
-threshold for this to be true is not precisely defined by law.
-
- If such an object file uses only numerical parameters, data
-structure layouts and accessors, and small macros and small inline
-functions (ten lines or less in length), then the use of the object
-file is unrestricted, regardless of whether it is legally a derivative
-work. (Executables containing this object code plus portions of the
-Library will still fall under Section 6.)
-
- Otherwise, if the work is a derivative of the Library, you may
-distribute the object code for the work under the terms of Section 6.
-Any executables containing that work also fall under Section 6,
-whether or not they are linked directly with the Library itself.
-
- 6. As an exception to the Sections above, you may also combine or
-link a "work that uses the Library" with the Library to produce a
-work containing portions of the Library, and distribute that work
-under terms of your choice, provided that the terms permit
-modification of the work for the customer's own use and reverse
-engineering for debugging such modifications.
-
- You must give prominent notice with each copy of the work that the
-Library is used in it and that the Library and its use are covered by
-this License. You must supply a copy of this License. If the work
-during execution displays copyright notices, you must include the
-copyright notice for the Library among them, as well as a reference
-directing the user to the copy of this License. Also, you must do one
-of these things:
-
- a) Accompany the work with the complete corresponding
- machine-readable source code for the Library including whatever
- changes were used in the work (which must be distributed under
- Sections 1 and 2 above); and, if the work is an executable linked
- with the Library, with the complete machine-readable "work that
- uses the Library", as object code and/or source code, so that the
- user can modify the Library and then relink to produce a modified
- executable containing the modified Library. (It is understood
- that the user who changes the contents of definitions files in the
- Library will not necessarily be able to recompile the application
- to use the modified definitions.)
-
- b) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (1) uses at run time a
- copy of the library already present on the user's computer system,
- rather than copying library functions into the executable, and (2)
- will operate properly with a modified version of the library, if
- the user installs one, as long as the modified version is
- interface-compatible with the version that the work was made with.
-
- c) Accompany the work with a written offer, valid for at
- least three years, to give the same user the materials
- specified in Subsection 6a, above, for a charge no more
- than the cost of performing this distribution.
-
- d) If distribution of the work is made by offering access to copy
- from a designated place, offer equivalent access to copy the above
- specified materials from the same place.
-
- e) Verify that the user has already received a copy of these
- materials or that you have already sent this user a copy.
-
- For an executable, the required form of the "work that uses the
-Library" must include any data and utility programs needed for
-reproducing the executable from it. However, as a special exception,
-the materials to be distributed need not include anything that is
-normally distributed (in either source or binary form) with the major
-components (compiler, kernel, and so on) of the operating system on
-which the executable runs, unless that component itself accompanies
-the executable.
-
- It may happen that this requirement contradicts the license
-restrictions of other proprietary libraries that do not normally
-accompany the operating system. Such a contradiction means you cannot
-use both them and the Library together in an executable that you
-distribute.
-
- 7. You may place library facilities that are a work based on the
-Library side-by-side in a single library together with other library
-facilities not covered by this License, and distribute such a combined
-library, provided that the separate distribution of the work based on
-the Library and of the other library facilities is otherwise
-permitted, and provided that you do these two things:
-
- a) Accompany the combined library with a copy of the same work
- based on the Library, uncombined with any other library
- facilities. This must be distributed under the terms of the
- Sections above.
-
- b) Give prominent notice with the combined library of the fact
- that part of it is a work based on the Library, and explaining
- where to find the accompanying uncombined form of the same work.
-
- 8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License. Any
-attempt otherwise to copy, modify, sublicense, link with, or
-distribute the Library is void, and will automatically terminate your
-rights under this License. However, parties who have received copies,
-or rights, from you under this License will not have their licenses
-terminated so long as such parties remain in full compliance.
-
- 9. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Library or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Library (or any work based on the
-Library), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Library or works based on it.
-
- 10. Each time you redistribute the Library (or any work based on the
-Library), the recipient automatically receives a license from the
-original licensor to copy, distribute, link with or modify the Library
-subject to these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties with
-this License.
-
- 11. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Library at all. For example, if a patent
-license would not permit royalty-free redistribution of the Library by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Library.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply,
-and the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 12. If the distribution and/or use of the Library is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Library under this License may add
-an explicit geographical distribution limitation excluding those countries,
-so that distribution is permitted only in or among countries not thus
-excluded. In such case, this License incorporates the limitation as if
-written in the body of this License.
-
- 13. The Free Software Foundation may publish revised and/or new
-versions of the Lesser General Public License from time to time.
-Such new versions will be similar in spirit to the present version,
-but may differ in detail to address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Library
-specifies a version number of this License which applies to it and
-"any later version", you have the option of following the terms and
-conditions either of that version or of any later version published by
-the Free Software Foundation. If the Library does not specify a
-license version number, you may choose any version ever published by
-the Free Software Foundation.
-
- 14. If you wish to incorporate parts of the Library into other free
-programs whose distribution conditions are incompatible with these,
-write to the author to ask for permission. For software which is
-copyrighted by the Free Software Foundation, write to the Free
-Software Foundation; we sometimes make exceptions for this. Our
-decision will be guided by the two goals of preserving the free status
-of all derivatives of our free software and of promoting the sharing
-and reuse of software generally.
-
- NO WARRANTY
-
- 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
-KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
-LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Libraries
-
- If you develop a new library, and you want it to be of the greatest
-possible use to the public, we recommend making it free software that
-everyone can redistribute and change. You can do so by permitting
-redistribution under these terms (or, alternatively, under the terms of the
-ordinary General Public License).
-
- To apply these terms, attach the following notices to the library. It is
-safest to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least the
-"copyright" line and a pointer to where the full notice is found.
-
- <one line to give the library's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-Also add information on how to contact you by electronic and paper mail.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the library, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the
- library `Frob' (a library for tweaking knobs) written by James Random Hacker.
-
- <signature of Ty Coon>, 1 April 1990
- Ty Coon, President of Vice
-
-That's all there is to it!
-
-
diff --git a/Source/7zip/readme.txt b/Source/7zip/readme.txt
deleted file mode 100755
index 828b795..0000000
--- a/Source/7zip/readme.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-Modified LZMA library for NSIS
-------------------------------
-
- Copyright (c) 1999-2003 Igor Pavlov
-
- All files in this folder and it's subfolders are
- licensed under GNU LGPL.
- Most of these files were copied from source code
- of 7-Zip compression program:
-
- http://www.7-zip.org
-
- Some of the files were modified and are not an
- exact replica of the original files.
-
- LZMA is default and general compression method of 7z format in 7-Zip.
- The main features of LZMA method:
- - High compression ratio
- - High decompressing speed: about 10-20 MB/s on 2 GHz CPU
- - Small memory requirements for decompressing
- - Small code size for decompressing: about 5 KB
-
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
diff --git a/Source/7zip/sdk.diff b/Source/7zip/sdk.diff
new file mode 100755
index 0000000..3390ad0
--- /dev/null
+++ b/Source/7zip/sdk.diff
@@ -0,0 +1,167 @@
+Only in 7zip: 7zGuids.cpp
+Only in 7zip-orig/7zip: Archive
+Only in 7zip/7zip: CVS
+Only in 7zip/7zip/Common: CVS
+Only in 7zip-orig/7zip/Common: FileStreams.cpp
+Only in 7zip-orig/7zip/Common: FileStreams.h
+diff -ru 7zip-orig/7zip/Common/StdAfx.h 7zip/7zip/Common/StdAfx.h
+--- 7zip-orig/7zip/Common/StdAfx.h Mon Jul 11 15:14:54 2005
++++ 7zip/7zip/Common/StdAfx.h Mon Oct 16 10:39:10 2006
+@@ -4,6 +4,5 @@
+ #define __STDAFX_H
+
+ #include "../../Common/MyWindows.h"
+-#include "../../Common/NewHandler.h"
+
+ #endif
+Only in 7zip-orig/7zip/Compress: Branch
+Only in 7zip/7zip/Compress: CVS
+Only in 7zip/7zip/Compress/LZ/BinTree: BinTree3ZMain.h
+Only in 7zip/7zip/Compress/LZ/BinTree: BinTree4b.h
+Only in 7zip/7zip/Compress/LZ/BinTree: BinTreeMF.h
+Only in 7zip/7zip/Compress/LZ/BinTree: BinTreeMFMain.h
+Only in 7zip/7zip/Compress/LZ/BinTree: CVS
+Only in 7zip/7zip/Compress/LZ: CVS
+Only in 7zip-orig/7zip/Compress/LZ: HashChain
+Only in 7zip/7zip/Compress/LZMA: CVS
+Only in 7zip-orig/7zip/Compress/LZMA: LZMADecoder.cpp
+Only in 7zip-orig/7zip/Compress/LZMA: LZMADecoder.h
+diff -ru 7zip-orig/7zip/Compress/LZMA/LZMAEncoder.cpp 7zip/7zip/Compress/LZMA/LZMAEncoder.cpp
+--- 7zip-orig/7zip/Compress/LZMA/LZMAEncoder.cpp Sat May 20 08:23:48 2006
++++ 7zip/7zip/Compress/LZMA/LZMAEncoder.cpp Mon Oct 16 10:26:43 2006
+@@ -55,13 +55,13 @@
+ kHC4
+ };
+
+-static const wchar_t *kMatchFinderIDs[] =
++/*static const wchar_t *kMatchFinderIDs[] =
+ {
+ L"BT2",
+ L"BT3",
+ L"BT4",
+ L"HC4"
+-};
++};*/
+
+ Byte g_FastPos[1 << 11];
+
+@@ -318,7 +318,7 @@
+ return S_OK;
+ }
+
+-static bool AreStringsEqual(const wchar_t *base, const wchar_t *testString)
++/*static bool AreStringsEqual(const wchar_t *base, const wchar_t *testString)
+ {
+ while (true)
+ {
+@@ -340,7 +340,7 @@
+ if (AreStringsEqual(kMatchFinderIDs[m], s))
+ return m;
+ return -1;
+-}
++}*/
+
+ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
+ const PROPVARIANT *properties, UInt32 numProperties)
+@@ -378,7 +378,8 @@
+ }
+ case NCoderPropID::kMatchFinder:
+ {
+- if (prop.vt != VT_BSTR)
++ return E_NOTIMPL;
++ /*if (prop.vt != VT_BSTR)
+ return E_INVALIDARG;
+ int matchFinderIndexPrev = _matchFinderIndex;
+ int m = FindMatchFinder(prop.bstrVal);
+@@ -390,7 +391,7 @@
+ _dictionarySizePrev = (UInt32)-1;
+ ReleaseMatchFinder();
+ }
+- break;
++ break;*/
+ }
+ #ifdef COMPRESS_MF_MT
+ case NCoderPropID::kMultiThread:
+Only in 7zip-orig/7zip/Compress: LZMA_Alone
+Only in 7zip-orig/7zip/Compress: LZMA_C
+Only in 7zip/7zip/Compress/RangeCoder: CVS
+Only in 7zip: CVS
+Only in 7zip/Common: CVS
+Only in 7zip-orig/Common: C_FileIO.cpp
+Only in 7zip-orig/Common: C_FileIO.h
+Only in 7zip-orig/Common: ComTry.h
+Only in 7zip-orig/Common: CommandLineParser.cpp
+Only in 7zip-orig/Common: CommandLineParser.h
+Only in 7zip-orig/Common: MyInitGuid.h
+diff -ru 7zip-orig/Common/MyWindows.h 7zip/Common/MyWindows.h
+--- 7zip-orig/Common/MyWindows.h Sun Apr 16 16:53:43 2006
++++ 7zip/Common/MyWindows.h Mon Oct 16 10:20:04 2006
+@@ -3,17 +3,22 @@
+ #ifndef __MYWINDOWS_H
+ #define __MYWINDOWS_H
+
++#include "../../Platform.h"
++
+ #ifdef _WIN32
+
+ #include <windows.h>
+
++/*
+ #define CHAR_PATH_SEPARATOR '\\'
+ #define WCHAR_PATH_SEPARATOR L'\\'
+ #define STRING_PATH_SEPARATOR "\\"
+ #define WSTRING_PATH_SEPARATOR L"\\"
++*/
+
+ #else
+
++/*
+ #define CHAR_PATH_SEPARATOR '/'
+ #define WCHAR_PATH_SEPARATOR L'/'
+ #define STRING_PATH_SEPARATOR "/"
+@@ -21,9 +26,9 @@
+
+ #include <stddef.h> // for wchar_t
+ #include <string.h>
+-
++*/
+ #include "MyGuidDef.h"
+-
++/*
+ typedef char CHAR;
+ typedef unsigned char UCHAR;
+
+@@ -62,7 +67,7 @@
+ typedef OLECHAR *BSTR;
+ typedef const OLECHAR *LPCOLESTR;
+ typedef OLECHAR *LPOLESTR;
+-
++*/
+ typedef struct _FILETIME
+ {
+ DWORD dwLowDateTime;
+Only in 7zip-orig/Common: NewHandler.cpp
+Only in 7zip-orig/Common: NewHandler.h
+diff -ru 7zip-orig/Common/StdAfx.h 7zip/Common/StdAfx.h
+--- 7zip-orig/Common/StdAfx.h Mon Jul 11 15:16:00 2005
++++ 7zip/Common/StdAfx.h Mon Oct 16 10:39:16 2006
+@@ -4,6 +4,5 @@
+ #define __STDAFX_H
+
+ // #include "MyWindows.h"
+-#include "NewHandler.h"
+
+ #endif
+Only in 7zip-orig/Common: String.cpp
+Only in 7zip-orig/Common: String.h
+Only in 7zip-orig/Common: StringConvert.cpp
+Only in 7zip-orig/Common: StringConvert.h
+Only in 7zip-orig/Common: StringToInt.cpp
+Only in 7zip-orig/Common: StringToInt.h
+Only in 7zip-orig/Common: Vector.cpp
+Only in 7zip-orig/Common: Vector.h
+Only in 7zip: LZMADecode.c
+Only in 7zip: LZMADecode.h
+Only in 7zip-orig: Windows
+Only in 7zip: copying.txt
+Only in 7zip: readme.txt
diff --git a/Source/DialogTemplate.cpp b/Source/DialogTemplate.cpp
index 8f26187..d974cc0 100755
--- a/Source/DialogTemplate.cpp
+++ b/Source/DialogTemplate.cpp
@@ -1,26 +1,21 @@
/*
- Copyright (C) 2002 Amir Szekely <kichik@netvision.net.il>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
-
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
-
- 3. This notice may not be removed or altered from any source distribution.
-*/
+ * DialogTemplate.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 2002 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "DialogTemplate.h"
+#include "winchar.h"
#include <cassert> // for assert(3)
#ifndef _WIN32
# include "util.h" // for Unicode conversion functions
@@ -50,8 +45,8 @@ static inline short ConvertEndianness(short s) {
#define ALIGN(dwToAlign, dwAlignOn) dwToAlign = (dwToAlign%dwAlignOn == 0) ? dwToAlign : dwToAlign - (dwToAlign%dwAlignOn) + dwAlignOn
-// Reads a variany length array from seeker into readInto and advances seeker
-void ReadVarLenArr(LPBYTE &seeker, char* &readInto, unsigned int uCodePage) {
+// Reads a variant length array from seeker into readInto and advances seeker
+void ReadVarLenArr(LPBYTE &seeker, WCHAR* &readInto, unsigned int uCodePage) {
WORD* arr = (WORD*)seeker;
switch (ConvertEndianness(arr[0])) {
case 0x0000:
@@ -59,26 +54,12 @@ void ReadVarLenArr(LPBYTE &seeker, char* &readInto, unsigned int uCodePage) {
seeker += sizeof(WORD);
break;
case 0xFFFF:
- readInto = MAKEINTRESOURCE(ConvertEndianness(arr[1]));
+ readInto = MAKEINTRESOURCEW(ConvertEndianness(arr[1]));
seeker += 2*sizeof(WORD);
break;
default:
{
- int iStrLen = WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, 0, 0, 0, 0);
- if (iStrLen)
- {
- readInto = new char[iStrLen];
- if (!WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, readInto, iStrLen, 0, 0))
- {
- delete [] readInto;
- throw runtime_error("ReadVarLenArr - Unicode conversion failed.");
- }
- }
- else
- {
- throw runtime_error("ReadVarLenArr - Unicode conversion failed.");
- }
-
+ readInto = winchar_strdup((WCHAR *) arr);
PWCHAR wseeker = PWCHAR(seeker);
while (*wseeker++);
seeker = LPBYTE(wseeker);
@@ -97,17 +78,14 @@ void ReadVarLenArr(LPBYTE &seeker, char* &readInto, unsigned int uCodePage) {
seeker += sizeof(WORD); \
} \
else { \
- int us = MultiByteToWideChar(m_uCodePage, 0, x, -1, (WCHAR*)seeker, dwSize - DWORD(seeker - pbDlg)); \
- if (!us) { \
- throw runtime_error("WriteStringOrId - Unicode conversion failed."); \
- } \
- seeker += us*sizeof(WCHAR); \
+ winchar_strcpy((WCHAR *) seeker, x); \
+ seeker += winchar_strlen((WCHAR *) seeker) * sizeof(WCHAR) + sizeof(WCHAR); \
} \
else \
seeker += sizeof(WORD);
// A macro that adds the size of x (which can be a string a number, or nothing) to dwSize
-#define AddStringOrIdSize(x) dwSize += x ? (IS_INTRESOURCE(x) ? sizeof(DWORD) : MultiByteToWideChar(m_uCodePage, 0, x, -1, 0, 0) * sizeof(WCHAR)) : sizeof(WORD)
+#define AddStringOrIdSize(x) dwSize += x ? (IS_INTRESOURCE(x) ? sizeof(DWORD) : (winchar_strlen(x) + 1) * sizeof(WCHAR)) : sizeof(WORD)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
@@ -183,7 +161,7 @@ CDialogTemplate::CDialogTemplate(BYTE* pbData, unsigned int uCodePage) {
// Read items
for (int i = 0; i < wItems; i++) {
- // DLGITEMTEMPLATE[EX]s must be aligned on DWORD boundry
+ // DLGITEMTEMPLATE[EX]s must be aligned on DWORD boundary
if (DWORD(seeker - pbData) % sizeof(DWORD))
seeker += sizeof(WORD);
@@ -314,8 +292,7 @@ void CDialogTemplate::SetFont(char* szFaceName, WORD wFontSize) {
m_bCharset = DEFAULT_CHARSET;
m_dwStyle |= DS_SETFONT;
if (m_szFont) delete [] m_szFont;
- m_szFont = new char[strlen(szFaceName)+1];
- strcpy(m_szFont, szFaceName);
+ m_szFont = winchar_fromansi(szFaceName);
m_sFontSize = wFontSize;
}
@@ -325,12 +302,10 @@ void CDialogTemplate::AddItem(DialogItemTemplate item) {
CopyMemory(newItem, &item, sizeof(DialogItemTemplate));
if (item.szClass && !IS_INTRESOURCE(item.szClass)) {
- newItem->szClass = new char[strlen(item.szClass)+1];
- strcpy(newItem->szClass, item.szClass);
+ newItem->szClass = winchar_strdup(item.szClass);
}
if (item.szTitle && !IS_INTRESOURCE(item.szTitle)) {
- newItem->szTitle = new char[strlen(item.szTitle)+1];
- strcpy(newItem->szTitle, item.szTitle);
+ newItem->szTitle = winchar_strdup(item.szTitle);
}
if (item.wCreateDataSize) {
newItem->szCreationData = new char[item.wCreateDataSize];
@@ -460,6 +435,12 @@ void CDialogTemplate::CTrimToString(WORD id, char *str, int margins) {
void CDialogTemplate::ConvertToRTL() {
for (unsigned int i = 0; i < m_vItems.size(); i++) {
bool addExStyle = false;
+ char *szClass;
+
+ if (IS_INTRESOURCE(m_vItems[i]->szClass))
+ szClass = (char *) m_vItems[i]->szClass;
+ else
+ szClass = winchar_toansi(m_vItems[i]->szClass);
// Button
if (long(m_vItems[i]->szClass) == 0x80) {
@@ -492,12 +473,12 @@ void CDialogTemplate::ConvertToRTL() {
m_vItems[i]->dwStyle |= SS_CENTERIMAGE;
}
}
- else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !stricmp(m_vItems[i]->szClass, "RichEdit20A")) {
+ else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !stricmp(szClass, "RichEdit20A")) {
if ((m_vItems[i]->dwStyle & ES_CENTER) == 0) {
m_vItems[i]->dwStyle ^= ES_RIGHT;
}
}
- else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !stricmp(m_vItems[i]->szClass, "SysTreeView32")) {
+ else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !stricmp(szClass, "SysTreeView32")) {
m_vItems[i]->dwStyle |= TVS_RTLREADING;
addExStyle = true;
}
@@ -509,6 +490,9 @@ void CDialogTemplate::ConvertToRTL() {
m_vItems[i]->dwExtStyle |= WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR;
m_vItems[i]->sX = m_sWidth - m_vItems[i]->sWidth - m_vItems[i]->sX;
+
+ if (!IS_INTRESOURCE(m_vItems[i]->szClass))
+ delete [] szClass;
}
m_dwExtStyle |= WS_EX_RIGHT | WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR;
}
@@ -577,7 +561,7 @@ BYTE* CDialogTemplate::Save(DWORD& dwSize) {
// Write all of the items
for (unsigned int i = 0; i < m_vItems.size(); i++) {
- // DLGITEMTEMPLATE[EX]s must be aligned on DWORD boundry
+ // DLGITEMTEMPLATE[EX]s must be aligned on DWORD boundary
if (DWORD(seeker - pbDlg) % sizeof(DWORD))
seeker += sizeof(WORD);
@@ -653,7 +637,7 @@ DWORD CDialogTemplate::GetSize() {
}
for (unsigned int i = 0; i < m_vItems.size(); i++) {
- // DLGITEMTEMPLATE[EX]s must be aligned on DWORD boundry
+ // DLGITEMTEMPLATE[EX]s must be aligned on DWORD boundary
ALIGN(dwSize, sizeof(DWORD));
dwSize += m_bExtended ? sizeof(DLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE);
diff --git a/Source/DialogTemplate.h b/Source/DialogTemplate.h
index 0e15f8e..c6bc58e 100755
--- a/Source/DialogTemplate.h
+++ b/Source/DialogTemplate.h
@@ -1,24 +1,18 @@
/*
- Copyright (C) 2002 Amir Szekely <kichik@netvision.net.il>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
-
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
-
- 3. This notice may not be removed or altered from any source distribution.
-*/
+ * DialogTemplate.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 2002 Amir Szekely <kichik@netvision.net.il>
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#if !defined(AFX_DIALOGTEMPLATE_H__C5A973AF_0F56_4BEC_814A_79318E2EB4AC__INCLUDED_)
#define AFX_DIALOGTEMPLATE_H__C5A973AF_0F56_4BEC_814A_79318E2EB4AC__INCLUDED_
@@ -49,8 +43,8 @@ struct DialogItemTemplate {
DWORD dwStyle;
WORD wId;
- char *szClass;
- char *szTitle;
+ WCHAR *szClass;
+ WCHAR *szTitle;
char *szCreationData;
WORD wCreateDataSize;
@@ -150,16 +144,16 @@ private:
DWORD m_dwExtStyle;
DWORD m_dwStyle;
- char* m_szMenu;
- char* m_szClass;
- char* m_szTitle;
+ WCHAR *m_szMenu;
+ WCHAR *m_szClass;
+ WCHAR *m_szTitle;
// Only if DS_FONT style is set
short m_sFontSize;
short m_sFontWeight; // Extended only
BYTE m_bItalic; // Extended only
BYTE m_bCharset; // Extended only
- char* m_szFont;
+ WCHAR *m_szFont;
// For (en/de)coding Unicode
unsigned int m_uCodePage;
diff --git a/Source/Platform.h b/Source/Platform.h
index e77d9f7..f72a9c6 100755
--- a/Source/Platform.h
+++ b/Source/Platform.h
@@ -1,3 +1,19 @@
+/*
+ * Platform.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef ___PLATFORM__H___
#define ___PLATFORM__H___
@@ -28,13 +44,14 @@ typedef unsigned long ULONG;
typedef long long INT64, LARGE_INTEGER;
typedef unsigned long long UINT64, ULARGE_INTEGER;
typedef int BOOL, *LPBOOL;
+typedef short VARIANT_BOOL;
typedef void VOID;
typedef void *LPVOID;
typedef char CHAR, *PCHAR, *LPCH, *PCH, *NPSTR, *LPSTR, *PSTR;
typedef unsigned char UCHAR;
typedef const char *LPCCH, *PCSTR, *LPCSTR;
-typedef unsigned short WCHAR, *PWCHAR, *LPWCH, *PWCH, *NWPSTR, *LPWSTR, *PWSTR;
-typedef const unsigned short *LPCWCH, *PCWCH, *LPCWSTR, *PCWSTR;
+typedef unsigned short WCHAR, OLECHAR, *PWCHAR, *LPWCH, *PWCH, *NWPSTR, *LPWSTR, *PWSTR, *BSTR;
+typedef const unsigned short *LPCWCH, *PCWCH, *LPCWSTR, *PCWSTR, *LPCOLESTR;
typedef unsigned int UINT_PTR;
// basic stuff
typedef void * HANDLE;
@@ -47,6 +64,24 @@ typedef unsigned long HBRUSH;
# define TRUE 1
// more
typedef WORD LANGID;
+// ULONGLONG
+#ifdef __GNUC__
+#define _HAVE_INT64
+#define _INTEGRAL_MAX_BITS 64
+#undef __int64
+#define __int64 long long
+#elif defined(__WATCOMC__) && (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64 )
+#define _HAVE_INT64
+#endif /* __GNUC__/__WATCOMC */
+#if defined(_HAVE_INT64) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64)
+typedef __int64 LONGLONG;
+typedef unsigned __int64 DWORDLONG;
+#else
+typedef double LONGLONG,DWORDLONG;
+#endif
+typedef LONGLONG *PLONGLONG;
+typedef DWORDLONG *PDWORDLONG;
+typedef DWORDLONG ULONGLONG,*PULONGLONG;
#endif
#ifndef __BIG_ENDIAN__
@@ -81,11 +116,13 @@ typedef WORD LANGID;
# define PLATFORM_PATH_SEPARATOR_C '\\'
# define OPT_STR "/"
# define OPT_C '/'
+# define IS_OPT(a) (a[0]==OPT_C||a[0]=='-')
#else
# define PLATFORM_PATH_SEPARATOR_STR "/"
# define PLATFORM_PATH_SEPARATOR_C '/'
# define OPT_STR "-"
# define OPT_C '-'
+# define IS_OPT(a) (a[0]==OPT_C)
#endif
// attributes
@@ -131,8 +168,14 @@ typedef WORD LANGID;
# ifndef FIELD_OFFSET
# define FIELD_OFFSET(t,f) ((LONG)&(((t*)0)->f))
# endif
+# ifndef MAKEINTRESOURCEA
+# define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
+# endif
+# ifndef MAKEINTRESOURCEW
+# define MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i))))
+# endif
# ifndef MAKEINTRESOURCE
-# define MAKEINTRESOURCE(i) (LPSTR)((DWORD)((WORD)(i)))
+# define MAKEINTRESOURCE MAKEINTRESOURCEA
# endif
# ifndef IMAGE_FIRST_SECTION
# define IMAGE_FIRST_SECTION(h) ( PIMAGE_SECTION_HEADER( (DWORD) h + \
@@ -715,7 +758,48 @@ typedef struct _IMAGE_OPTIONAL_HEADER {
DWORD LoaderFlags;
DWORD NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
-} IMAGE_OPTIONAL_HEADER,*PIMAGE_OPTIONAL_HEADER;
+} IMAGE_OPTIONAL_HEADER32,*PIMAGE_OPTIONAL_HEADER32;
+typedef struct _IMAGE_OPTIONAL_HEADER64 {
+ WORD Magic;
+ BYTE MajorLinkerVersion;
+ BYTE MinorLinkerVersion;
+ DWORD SizeOfCode;
+ DWORD SizeOfInitializedData;
+ DWORD SizeOfUninitializedData;
+ DWORD AddressOfEntryPoint;
+ DWORD BaseOfCode;
+ ULONGLONG ImageBase;
+ DWORD SectionAlignment;
+ DWORD FileAlignment;
+ WORD MajorOperatingSystemVersion;
+ WORD MinorOperatingSystemVersion;
+ WORD MajorImageVersion;
+ WORD MinorImageVersion;
+ WORD MajorSubsystemVersion;
+ WORD MinorSubsystemVersion;
+ DWORD Win32VersionValue;
+ DWORD SizeOfImage;
+ DWORD SizeOfHeaders;
+ DWORD CheckSum;
+ WORD Subsystem;
+ WORD DllCharacteristics;
+ ULONGLONG SizeOfStackReserve;
+ ULONGLONG SizeOfStackCommit;
+ ULONGLONG SizeOfHeapReserve;
+ ULONGLONG SizeOfHeapCommit;
+ DWORD LoaderFlags;
+ DWORD NumberOfRvaAndSizes;
+ IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
+} IMAGE_OPTIONAL_HEADER64,*PIMAGE_OPTIONAL_HEADER64;
+#ifdef _WIN64
+typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
+typedef PIMAGE_OPTIONAL_HEADER64 PIMAGE_OPTIONAL_HEADER;
+#else
+typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
+typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER;
+#endif
+#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
+#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
typedef struct _IMAGE_NT_HEADERS {
DWORD Signature;
IMAGE_FILE_HEADER FileHeader;
diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp
index 17d46fc..ff9f696 100755
--- a/Source/Plugins.cpp
+++ b/Source/Plugins.cpp
@@ -1,3 +1,19 @@
+/*
+ * Plugins.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "exehead/config.h"
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
diff --git a/Source/Plugins.h b/Source/Plugins.h
index f2c19c6..932cf1d 100755
--- a/Source/Plugins.h
+++ b/Source/Plugins.h
@@ -1,3 +1,19 @@
+/*
+ * Plugins.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef __X18_PLUGINS_H
#define __X18_PLUGINS_H
diff --git a/Source/ResourceEditor.cpp b/Source/ResourceEditor.cpp
index 74c31dc..5373af4 100755
--- a/Source/ResourceEditor.cpp
+++ b/Source/ResourceEditor.cpp
@@ -1,28 +1,22 @@
/*
- Copyright (C) 2002-2006 Amir Szekely <kichik@users.sourceforge.net>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
-
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
-
- 3. This notice may not be removed or altered from any source distribution.
-*/
+ * ResourceEditor.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 2002-2007 Amir Szekely <kichik@users.sourceforge.net>
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "ResourceEditor.h"
#include "util.h"
-#include <time.h>
+#include "winchar.h"
#include <queue>
using namespace std;
@@ -56,6 +50,11 @@ PIMAGE_NT_HEADERS CResourceEditor::GetNTHeaders(BYTE* pbPE) {
if (ntHeaders->Signature != IMAGE_NT_SIGNATURE)
throw runtime_error("PE file missing NT signature");
+ // Make sure this is a supported PE format
+ if (ntHeaders->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC &&
+ ntHeaders->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)
+ throw runtime_error("Unsupported PE format");
+
return ntHeaders;
}
@@ -66,10 +65,13 @@ PRESOURCE_DIRECTORY CResourceEditor::GetResourceDirectory(
DWORD *pdwResSecVA /*=NULL*/,
DWORD *pdwSectionIndex /*=NULL*/
) {
- if (ConvertEndianness(ntHeaders->OptionalHeader.NumberOfRvaAndSizes) <= IMAGE_DIRECTORY_ENTRY_RESOURCE)
+ PIMAGE_DATA_DIRECTORY dataDirectory = *GetMemberFromOptionalHeader(ntHeaders->OptionalHeader, DataDirectory);
+ DWORD dwNumberOfRvaAndSizes = *GetMemberFromOptionalHeader(ntHeaders->OptionalHeader, NumberOfRvaAndSizes);
+
+ if (ConvertEndianness(dwNumberOfRvaAndSizes) <= IMAGE_DIRECTORY_ENTRY_RESOURCE)
throw runtime_error("No resource section found");
// Get resource section virtual address
- DWORD dwResSecVA = ConvertEndianness(ntHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress);
+ DWORD dwResSecVA = ConvertEndianness(dataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress);
// Pointer to the sections headers array
PIMAGE_SECTION_HEADER sectionHeadersArray = IMAGE_FIRST_SECTION(ntHeaders);
@@ -126,10 +128,11 @@ CResourceEditor::CResourceEditor(BYTE* pbPE, int iSize) {
m_ntHeaders = GetNTHeaders(m_pbPE);
// No check sum support yet...
- if (m_ntHeaders->OptionalHeader.CheckSum)
+ DWORD* pdwCheckSum = GetMemberFromOptionalHeader(m_ntHeaders->OptionalHeader, CheckSum);
+ if (*pdwCheckSum)
{
// clear checksum (should be [re]calculated after all changes done)
- m_ntHeaders->OptionalHeader.CheckSum = 0;
+ pdwCheckSum = 0;
//throw runtime_error("CResourceEditor doesn't yet support check sum");
}
@@ -153,7 +156,7 @@ CResourceEditor::~CResourceEditor() {
// Adds/Replaces/Removes a resource.
// If lpData is 0 UpdateResource removes the resource.
-bool CResourceEditor::UpdateResource(char* szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
+bool CResourceEditor::UpdateResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
CResourceDirectory* nameDir = 0;
CResourceDirectory* langDir = 0;
CResourceDataEntry* data = 0;
@@ -193,7 +196,7 @@ bool CResourceEditor::UpdateResource(char* szType, char* szName, LANGID wLanguag
if (!data) {
// Language doesn't yet exist, hence data nither
data = new CResourceDataEntry(lpData, dwSize);
- langDir->AddEntry(new CResourceDirectoryEntry(MAKEINTRESOURCE(wLanguage), data));
+ langDir->AddEntry(new CResourceDirectoryEntry(MAKEINTRESOURCEW(wLanguage), data));
}
}
else if (data) {
@@ -214,21 +217,53 @@ bool CResourceEditor::UpdateResource(char* szType, char* szName, LANGID wLanguag
return true;
}
-bool CResourceEditor::UpdateResource(WORD szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
- return UpdateResource(MAKEINTRESOURCE(szType), szName, wLanguage, lpData, dwSize);
+static WCHAR* ResStringToUnicode(const char *szString) {
+ if (IS_INTRESOURCE(szString))
+ return MAKEINTRESOURCEW((ULONG_PTR)szString);
+ else
+ return winchar_fromansi(szString);
+}
+
+static void FreeUnicodeResString(WCHAR* szwString) {
+ if (!IS_INTRESOURCE(szwString))
+ delete [] szwString;
+}
+
+bool CResourceEditor::UpdateResourceW(WORD szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
+ return UpdateResourceW(MAKEINTRESOURCEW(szType), szName, wLanguage, lpData, dwSize);
+}
+
+bool CResourceEditor::UpdateResourceW(WCHAR* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
+ return UpdateResourceW(szType, MAKEINTRESOURCEW(szName), wLanguage, lpData, dwSize);
+}
+
+bool CResourceEditor::UpdateResourceA(char* szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
+ WCHAR* szwType = ResStringToUnicode(szType);
+ WCHAR* szwName = ResStringToUnicode(szName);
+
+ bool result = UpdateResourceW(szwType, szwName, wLanguage, lpData, dwSize);
+
+ FreeUnicodeResString(szwType);
+ FreeUnicodeResString(szwName);
+
+ return result;
+}
+
+bool CResourceEditor::UpdateResourceA(WORD szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
+ return UpdateResourceA(MAKEINTRESOURCE(szType), szName, wLanguage, lpData, dwSize);
}
-bool CResourceEditor::UpdateResource(char* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
- return UpdateResource(szType, MAKEINTRESOURCE(szName), wLanguage, lpData, dwSize);
+bool CResourceEditor::UpdateResourceA(char* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
+ return UpdateResourceA(szType, MAKEINTRESOURCE(szName), wLanguage, lpData, dwSize);
}
bool CResourceEditor::UpdateResource(WORD szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
- return UpdateResource(MAKEINTRESOURCE(szType), MAKEINTRESOURCE(szName), wLanguage, lpData, dwSize);
+ return UpdateResourceW(MAKEINTRESOURCEW(szType), MAKEINTRESOURCEW(szName), wLanguage, lpData, dwSize);
}
// Returns a copy of the requested resource
// Returns 0 if the requested resource can't be found
-BYTE* CResourceEditor::GetResource(char* szType, char* szName, LANGID wLanguage) {
+BYTE* CResourceEditor::GetResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage) {
CResourceDirectory* nameDir = 0;
CResourceDirectory* langDir = 0;
CResourceDataEntry* data = 0;
@@ -257,9 +292,21 @@ BYTE* CResourceEditor::GetResource(char* szType, char* szName, LANGID wLanguage)
return NULL;
}
+BYTE* CResourceEditor::GetResourceA(char* szType, char* szName, LANGID wLanguage) {
+ WCHAR* szwType = ResStringToUnicode(szType);
+ WCHAR* szwName = ResStringToUnicode(szName);
+
+ BYTE* result = GetResourceW(szwType, szwName, wLanguage);
+
+ FreeUnicodeResString(szwType);
+ FreeUnicodeResString(szwName);
+
+ return result;
+}
+
// Returns the size of the requested resource
// Returns -1 if the requested resource can't be found
-int CResourceEditor::GetResourceSize(char* szType, char* szName, LANGID wLanguage) {
+int CResourceEditor::GetResourceSizeW(WCHAR* szType, WCHAR* szName, LANGID wLanguage) {
CResourceDirectory* nameDir = 0;
CResourceDirectory* langDir = 0;
CResourceDataEntry* data = 0;
@@ -285,6 +332,18 @@ int CResourceEditor::GetResourceSize(char* szType, char* szName, LANGID wLanguag
return -1;
}
+int CResourceEditor::GetResourceSizeA(char* szType, char* szName, LANGID wLanguage) {
+ WCHAR* szwType = ResStringToUnicode(szType);
+ WCHAR* szwName = ResStringToUnicode(szName);
+
+ int result = GetResourceSizeW(szwType, szwName, wLanguage);
+
+ FreeUnicodeResString(szwType);
+ FreeUnicodeResString(szwName);
+
+ return result;
+}
+
void CResourceEditor::FreeResource(BYTE* pbResource)
{
if (pbResource)
@@ -350,28 +409,36 @@ DWORD CResourceEditor::Save(BYTE* pbBuf, DWORD &dwSize) {
sectionHeadersArray[m_dwResourceSectionIndex].SizeOfRawData = ConvertEndianness(dwRsrcSizeAligned);
// Set the virtual size as well (in memory)
sectionHeadersArray[m_dwResourceSectionIndex].Misc.VirtualSize = ConvertEndianness(dwRsrcSize);
- ntHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = ConvertEndianness(dwRsrcSize);
+ (*GetMemberFromOptionalHeader(ntHeaders->OptionalHeader, DataDirectory))[IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = ConvertEndianness(dwRsrcSize);
// Set the new virtual size of the image
- ntHeaders->OptionalHeader.SizeOfImage = AlignVA(ntHeaders->OptionalHeader.SizeOfHeaders);
+ DWORD* pdwSizeOfImage = GetMemberFromOptionalHeader(ntHeaders->OptionalHeader, SizeOfImage);
+ *pdwSizeOfImage = AlignVA(*GetMemberFromOptionalHeader(ntHeaders->OptionalHeader, SizeOfHeaders));
for (i = 0; i < wNumberOfSections; i++) {
DWORD dwSecSize = ConvertEndianness(sectionHeadersArray[i].Misc.VirtualSize);
- ntHeaders->OptionalHeader.SizeOfImage = AlignVA(AdjustVA(ntHeaders->OptionalHeader.SizeOfImage, dwSecSize));
+ *pdwSizeOfImage = AlignVA(AdjustVA(*pdwSizeOfImage, dwSecSize));
}
// Set the new AddressOfEntryPoint if needed
- if (ConvertEndianness(ntHeaders->OptionalHeader.AddressOfEntryPoint) > m_dwResourceSectionVA)
- ntHeaders->OptionalHeader.AddressOfEntryPoint = AdjustVA(ntHeaders->OptionalHeader.AddressOfEntryPoint, dwVAAdjustment);
+ DWORD* pdwAddressOfEntryPoint = GetMemberFromOptionalHeader(ntHeaders->OptionalHeader, AddressOfEntryPoint);
+ if (ConvertEndianness(*pdwAddressOfEntryPoint) > m_dwResourceSectionVA)
+ *pdwAddressOfEntryPoint = AdjustVA(*pdwAddressOfEntryPoint, dwVAAdjustment);
// Set the new BaseOfCode if needed
- if (ConvertEndianness(ntHeaders->OptionalHeader.BaseOfCode) > m_dwResourceSectionVA)
- ntHeaders->OptionalHeader.BaseOfCode = AdjustVA(ntHeaders->OptionalHeader.BaseOfCode, dwVAAdjustment);
+ DWORD* pdwBaseOfCode = GetMemberFromOptionalHeader(ntHeaders->OptionalHeader, BaseOfCode);
+ if (ConvertEndianness(*pdwBaseOfCode) > m_dwResourceSectionVA)
+ *pdwBaseOfCode = AdjustVA(*pdwBaseOfCode, dwVAAdjustment);
// Set the new BaseOfData if needed
- if (ConvertEndianness(ntHeaders->OptionalHeader.BaseOfData) > m_dwResourceSectionVA)
- ntHeaders->OptionalHeader.BaseOfData = AdjustVA(ntHeaders->OptionalHeader.BaseOfData, dwVAAdjustment);
+ if (ntHeaders->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+ DWORD* pdwBaseOfData = &((PIMAGE_OPTIONAL_HEADER32)&ntHeaders->OptionalHeader)->BaseOfData;
+ if (*pdwBaseOfData > m_dwResourceSectionVA)
+ *pdwBaseOfData = AdjustVA(*pdwBaseOfData, dwVAAdjustment);
+ }
// Refresh the headers of the sections that come after the resource section, and the data directory
+ DWORD dwNumberOfRvaAndSizes = *GetMemberFromOptionalHeader(ntHeaders->OptionalHeader, NumberOfRvaAndSizes);
+ PIMAGE_DATA_DIRECTORY pDataDirectory = *GetMemberFromOptionalHeader(ntHeaders->OptionalHeader, DataDirectory);
for (i = m_dwResourceSectionIndex + 1; i < wNumberOfSections; i++) {
if (sectionHeadersArray[i].PointerToRawData) {
AdjustVA(sectionHeadersArray[i].PointerToRawData, dwRsrcSizeAligned - dwOldRsrcSize);
@@ -379,15 +446,15 @@ DWORD CResourceEditor::Save(BYTE* pbBuf, DWORD &dwSize) {
// We must find the right data directory entry before we change the virtual address
unsigned int uDataDirIdx = 0;
- for (unsigned int j = 0; j < ConvertEndianness(ntHeaders->OptionalHeader.NumberOfRvaAndSizes); j++)
- if (ntHeaders->OptionalHeader.DataDirectory[j].VirtualAddress == sectionHeadersArray[i].VirtualAddress)
+ for (unsigned int j = 0; j < ConvertEndianness(dwNumberOfRvaAndSizes); j++)
+ if (pDataDirectory[j].VirtualAddress == sectionHeadersArray[i].VirtualAddress)
uDataDirIdx = j;
sectionHeadersArray[i].VirtualAddress = AdjustVA(sectionHeadersArray[i].VirtualAddress, dwVAAdjustment);
// Change the virtual address in the data directory too
if (uDataDirIdx)
- ntHeaders->OptionalHeader.DataDirectory[uDataDirIdx].VirtualAddress = sectionHeadersArray[i].VirtualAddress;
+ pDataDirectory[uDataDirIdx].VirtualAddress = sectionHeadersArray[i].VirtualAddress;
}
// Write the resource section
@@ -443,7 +510,8 @@ bool CResourceEditor::AddExtraVirtualSize2PESection(const char* pszSectionName,
if (m_dwResourceSectionIndex == (DWORD) k)
{
// fix the resources virtual address if it changed
- m_ntHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = dwSecVA;
+ PIMAGE_DATA_DIRECTORY pDataDirectory = *GetMemberFromOptionalHeader(m_ntHeaders->OptionalHeader, DataDirectory);
+ pDataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = dwSecVA;
m_dwResourceSectionVA = ConvertEndianness(dwSecVA);
}
}
@@ -464,7 +532,7 @@ bool CResourceEditor::AddExtraVirtualSize2PESection(const char* pszSectionName,
CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, PRESOURCE_DIRECTORY rdToScan) {
// Create CResourceDirectory from rdToScan
CResourceDirectory* rdc = new CResourceDirectory(PIMAGE_RESOURCE_DIRECTORY(rdToScan));
- char* szName;
+ WCHAR* szName;
PIMAGE_RESOURCE_DATA_ENTRY rde = NULL;
// Go through all entries of this resource directory
@@ -484,16 +552,14 @@ CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, P
if (rd.NameString.NameIsString) {
PIMAGE_RESOURCE_DIR_STRING_U rds = PIMAGE_RESOURCE_DIR_STRING_U(rd.NameString.NameOffset + (char*)rdRoot);
- int mbsSize = WideCharToMultiByte(CP_ACP, 0, rds->NameString, ConvertEndianness(rds->Length), 0, 0, 0, 0);
- szName = new char[mbsSize+1];
- if (!WideCharToMultiByte(CP_ACP, 0, rds->NameString, ConvertEndianness(rds->Length), szName, mbsSize, 0, 0)) {
- throw runtime_error("Unicode conversion failed");
- }
- szName[mbsSize] = 0;
+ size_t nameSize = ConvertEndianness(rds->Length);
+ szName = new WCHAR[nameSize+1];
+ winchar_strncpy(szName, rds->NameString, nameSize);
+ szName[nameSize] = 0;
}
// Else, set the name to this entry's id
else
- szName = MAKEINTRESOURCE(ConvertEndianness(rdToScan->Entries[i].Id));
+ szName = MAKEINTRESOURCEW(ConvertEndianness(rdToScan->Entries[i].Id));
if (rd.DirectoryOffset.DataIsDirectory)
rdc->AddEntry(
@@ -596,26 +662,15 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) {
PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(cRDirE->m_dwWrittenAt)->NameString.NameOffset = ConvertEndianness(DWORD(seeker) - DWORD(pbRsrcSec));
- char* szName = cRDirE->GetName();
- WORD iLen = strlen(szName) + 1;
- WCHAR *szwName = new WCHAR[iLen];
-
- // MultiByteToWideChar return value includes the null char, so -1
- iLen = MultiByteToWideChar(CP_ACP, 0, szName, iLen, szwName, iLen) - 1;
- if (iLen == (WORD) -1)
- throw runtime_error("Unicode conversion failed");
+ WCHAR* szName = cRDirE->GetName();
+ WORD iLen = winchar_strlen(szName) + 1;
*(WORD*)seeker = ConvertEndianness(iLen);
- seeker += sizeof(WORD);
- CopyMemory(seeker, szwName, iLen*sizeof(WCHAR));
- seeker += iLen*sizeof(WCHAR);
+ CopyMemory(seeker + sizeof(WORD), szName, iLen*sizeof(WCHAR));
- // Even though the number of chars is predefined a null termination is required
- *(WORD*)seeker = 0;
- seeker += sizeof(WORD);
+ seeker += RALIGN(iLen * sizeof(WCHAR) + sizeof(WORD), 4);
delete [] szName;
- delete [] szwName;
qStrings.pop();
}
@@ -666,7 +721,8 @@ DWORD CResourceEditor::AdjustVA(DWORD dwVirtualAddress, DWORD dwAdjustment) {
// Aligns a virtual address to the section alignment
DWORD CResourceEditor::AlignVA(DWORD dwVirtualAddress) {
- DWORD dwAlignment = ConvertEndianness(m_ntHeaders->OptionalHeader.SectionAlignment);
+ DWORD dwSectionAlignment = *GetMemberFromOptionalHeader(m_ntHeaders->OptionalHeader, SectionAlignment);
+ DWORD dwAlignment = ConvertEndianness(dwSectionAlignment);
dwVirtualAddress = ConvertEndianness(dwVirtualAddress);
dwVirtualAddress = RALIGN(dwVirtualAddress, dwAlignment);
@@ -713,10 +769,10 @@ CResourceDirectoryEntry* CResourceDirectory::GetEntry(unsigned int i) {
void CResourceDirectory::AddEntry(CResourceDirectoryEntry* entry) {
int i = 0;
if (entry->HasName()) {
- char* szEntName = entry->GetName();
+ WCHAR* szEntName = entry->GetName();
for (i = 0; i < m_rdDir.NumberOfNamedEntries; i++) {
- char* szName = m_vEntries[i]->GetName();
- int cmp = strcmp(szName, szEntName);
+ WCHAR* szName = m_vEntries[i]->GetName();
+ int cmp = winchar_strcmp(szName, szEntName);
delete [] szName;
if (cmp == 0) {
delete [] szEntName;
@@ -756,19 +812,19 @@ int CResourceDirectory::CountEntries() {
// Returns the index of a directory entry with the specified name
// Name can be a string or an id
// Returns -1 if can not be found
-int CResourceDirectory::Find(char* szName) {
+int CResourceDirectory::Find(WCHAR* szName) {
if (IS_INTRESOURCE(szName))
return Find((WORD) (DWORD) szName);
else
if (szName[0] == '#')
- return Find(WORD(atoi(szName + 1)));
+ return Find(WORD(winchar_stoi(szName + 1)));
for (unsigned int i = 0; i < m_vEntries.size(); i++) {
if (!m_vEntries[i]->HasName())
continue;
- char* szEntName = m_vEntries[i]->GetName();
- int cmp = strcmp(szName, szEntName);
+ WCHAR* szEntName = m_vEntries[i]->GetName();
+ int cmp = winchar_strcmp(szName, szEntName);
delete [] szEntName;
if (!cmp)
@@ -832,7 +888,7 @@ void CResourceDirectory::Destroy() {
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-CResourceDirectoryEntry::CResourceDirectoryEntry(char* szName, CResourceDirectory* rdSubDir) {
+CResourceDirectoryEntry::CResourceDirectoryEntry(WCHAR* szName, CResourceDirectory* rdSubDir) {
if (IS_INTRESOURCE(szName)) {
m_bHasName = false;
m_szName = 0;
@@ -840,14 +896,13 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(char* szName, CResourceDirector
}
else {
m_bHasName = true;
- m_szName = new char[strlen(szName)+1];
- strcpy(m_szName, szName);
+ m_szName = winchar_strdup(szName);
}
m_bIsDataDirectory = true;
m_rdSubDir = rdSubDir;
}
-CResourceDirectoryEntry::CResourceDirectoryEntry(char* szName, CResourceDataEntry* rdeData) {
+CResourceDirectoryEntry::CResourceDirectoryEntry(WCHAR* szName, CResourceDataEntry* rdeData) {
if (IS_INTRESOURCE(szName)) {
m_bHasName = false;
m_szName = 0;
@@ -855,8 +910,7 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(char* szName, CResourceDataEntr
}
else {
m_bHasName = true;
- m_szName = new char[strlen(szName)+1];
- strcpy(m_szName, szName);
+ m_szName = winchar_strdup(szName);
}
m_bIsDataDirectory = false;
m_rdeData = rdeData;
@@ -876,17 +930,14 @@ bool CResourceDirectoryEntry::HasName() {
}
// Don't forget to free the memory used by the string after usage!
-char* CResourceDirectoryEntry::GetName() {
+WCHAR* CResourceDirectoryEntry::GetName() {
if (!m_bHasName)
return 0;
- char* szName = 0;
- szName = new char[strlen(m_szName)+1];
- strcpy(szName, m_szName);
- return szName;
+ return winchar_strdup(m_szName);
}
int CResourceDirectoryEntry::GetNameLength() {
- return strlen(m_szName);
+ return winchar_strlen(m_szName);
}
WORD CResourceDirectoryEntry::GetId() {
diff --git a/Source/ResourceEditor.h b/Source/ResourceEditor.h
index 5c27dfb..d03ba07 100755
--- a/Source/ResourceEditor.h
+++ b/Source/ResourceEditor.h
@@ -1,24 +1,18 @@
/*
- Copyright (C) 2002-2006 Amir Szekely <kichik@users.sourceforge.net>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
-
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
-
- 3. This notice may not be removed or altered from any source distribution.
-*/
+ * ResourceEditor.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 2002-2007 Amir Szekely <kichik@users.sourceforge.net>
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#if !defined(AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_)
#define AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_
@@ -108,17 +102,27 @@ typedef struct RESOURCE_DIRECTORY {
MY_IMAGE_RESOURCE_DIRECTORY_ENTRY Entries[1];
} *PRESOURCE_DIRECTORY;
+#define GetMemberFromOptionalHeader(optionalHeader, member) \
+ ( (optionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) ? \
+ &((PIMAGE_OPTIONAL_HEADER32)&optionalHeader)->member : \
+ &((PIMAGE_OPTIONAL_HEADER64)&optionalHeader)->member \
+ )
class CResourceEditor {
public:
CResourceEditor(BYTE* pbPE, int iSize);
virtual ~CResourceEditor();
- bool UpdateResource(char* szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
- bool UpdateResource(WORD szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
- bool UpdateResource(char* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
bool UpdateResource(WORD szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
- BYTE* GetResource(char* szType, char* szName, LANGID wLanguage);
- int GetResourceSize(char* szType, char* szName, LANGID wLanguage);
+ bool UpdateResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
+ bool UpdateResourceW(WORD szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
+ bool UpdateResourceW(WCHAR* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
+ bool UpdateResourceA(char* szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
+ bool UpdateResourceA(WORD szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
+ bool UpdateResourceA(char* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
+ BYTE* GetResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
+ BYTE* GetResourceA(char* szType, char* szName, LANGID wLanguage);
+ int GetResourceSizeW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
+ int GetResourceSizeA(char* szType, char* szName, LANGID wLanguage);
void FreeResource(BYTE* pbResource);
bool AddExtraVirtualSize2PESection(const char* pszSectionName, int addsize);
@@ -166,7 +170,7 @@ public:
void AddEntry(CResourceDirectoryEntry* entry);
void RemoveEntry(int i);
int CountEntries();
- int Find(char* szName);
+ int Find(WCHAR* szName);
int Find(WORD wId);
DWORD GetSize();
@@ -182,12 +186,12 @@ private:
class CResourceDirectoryEntry {
public:
- CResourceDirectoryEntry(char* szName, CResourceDirectory* rdSubDir);
- CResourceDirectoryEntry(char* szName, CResourceDataEntry* rdeData);
+ CResourceDirectoryEntry(WCHAR* szName, CResourceDirectory* rdSubDir);
+ CResourceDirectoryEntry(WCHAR* szName, CResourceDataEntry* rdeData);
virtual ~CResourceDirectoryEntry();
bool HasName();
- char* GetName();
+ WCHAR* GetName();
int GetNameLength();
WORD GetId();
@@ -201,10 +205,8 @@ public:
private:
bool m_bHasName;
- union {
- char* m_szName;
- WORD m_wId;
- };
+ WCHAR* m_szName;
+ WORD m_wId;
bool m_bIsDataDirectory;
union {
diff --git a/Source/ResourceVersionInfo.cpp b/Source/ResourceVersionInfo.cpp
index 083c53d..ddb4aaa 100755
--- a/Source/ResourceVersionInfo.cpp
+++ b/Source/ResourceVersionInfo.cpp
@@ -1,11 +1,24 @@
-// ResourceVersionInfo.cpp: implementation of the CResourceVersionInfo class.
-//
-//////////////////////////////////////////////////////////////////////
+/*
+ * ResourceVersionInfo.cpp: implementation of the CResourceVersionInfo class.
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "ResourceVersionInfo.h"
#include "Platform.h"
#include "util.h"
+#include "winchar.h"
#ifdef NSIS_SUPPORT_VERSION_INFO
@@ -119,19 +132,6 @@ void CResourceVersionInfo::SetProductVersion(int HighPart, int LowPart)
m_FixedInfo.dwProductVersionMS = HighPart;
}
-// Util function - must be freeded
-WCHAR* StrToWstrAlloc(const char* istr, int codepage)
-{
- int strSize = MultiByteToWideChar(codepage, 0, istr, -1, 0, 0);
- WCHAR* wstr = new WCHAR[strSize];
- if (!MultiByteToWideChar(codepage, 0, istr, -1, wstr, strSize))
- {
- delete [] wstr;
- wstr = NULL;
- }
- return wstr;
-}
-
int GetVersionHeader (LPSTR &p, WORD &wLength, WORD &wValueLength, WORD &wType)
{
WCHAR *szKey;
@@ -190,7 +190,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
WCHAR *KeyName, *KeyValue;
strm.resize(0);
- KeyName = StrToWstrAlloc("VS_VERSION_INFO", CP_ACP);
+ KeyName = winchar_fromansi("VS_VERSION_INFO");
SaveVersionHeader (strm, 0, sizeof (VS_FIXEDFILEINFO), 0, KeyName, &m_FixedInfo);
delete [] KeyName;
@@ -202,7 +202,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
LANGID langid = m_ChildStringLists.get_lang(Index);
char Buff[16];
sprintf(Buff, "%04x%04x", langid, codepage);
- KeyName = StrToWstrAlloc(Buff, CP_ACP);
+ KeyName = winchar_fromansi(Buff, CP_ACP);
SaveVersionHeader (stringInfoStream, 0, 0, 0, KeyName, &ZEROS);
delete [] KeyName;
@@ -211,8 +211,8 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
PadStream (stringInfoStream);
p = stringInfoStream.getlen();
- KeyName = StrToWstrAlloc(pChildStrings->getname(i), codepage);
- KeyValue = StrToWstrAlloc(pChildStrings->getvalue(i), codepage);
+ KeyName = winchar_fromansi(pChildStrings->getname(i), codepage);
+ KeyValue = winchar_fromansi(pChildStrings->getvalue(i), codepage);
SaveVersionHeader (stringInfoStream, 0, WCStrLen(KeyValue), 1, KeyName, (void*)KeyValue);
delete [] KeyName;
delete [] KeyValue;
@@ -226,7 +226,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
PadStream (strm);
p = strm.getlen();
- KeyName = StrToWstrAlloc("StringFileInfo", CP_ACP);
+ KeyName = winchar_fromansi("StringFileInfo", CP_ACP);
SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS);
delete [] KeyName;
strm.add (stringInfoStream.get(), stringInfoStream.getlen());
@@ -240,13 +240,13 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
{
PadStream (strm);
p = strm.getlen();
- KeyName = StrToWstrAlloc("VarFileInfo", CP_ACP);
+ KeyName = winchar_fromansi("VarFileInfo", CP_ACP);
SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS);
delete [] KeyName;
PadStream (strm);
p1 = strm.getlen();
- KeyName = StrToWstrAlloc("Translation", CP_ACP);
+ KeyName = winchar_fromansi("Translation", CP_ACP);
SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS);
delete [] KeyName;
diff --git a/Source/ResourceVersionInfo.h b/Source/ResourceVersionInfo.h
index b5525dd..b77cd88 100755
--- a/Source/ResourceVersionInfo.h
+++ b/Source/ResourceVersionInfo.h
@@ -1,6 +1,18 @@
-// ResourceVersionInfo.h: interface for the CResourceVersionInfo class.
-//
-//////////////////////////////////////////////////////////////////////
+/*
+ * ResourceVersionInfo.h: interface for the CResourceVersionInfo class.
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#if !defined(AFX_RESOURCEVERSIONINFO_H__80439ADA_49DA_4623_8DA9_1663FF356E76__INCLUDED_)
#define AFX_RESOURCEVERSIONINFO_H__80439ADA_49DA_4623_8DA9_1663FF356E76__INCLUDED_
diff --git a/Source/SConscript b/Source/SConscript
index c157830..3759f4d 100755
--- a/Source/SConscript
+++ b/Source/SConscript
@@ -13,6 +13,7 @@ makensis_files = Split("""
lang.cpp
lineparse.cpp
makenssi.cpp
+ manifest.cpp
mmap.cpp
Plugins.cpp
ResourceEditor.cpp
@@ -22,6 +23,7 @@ makensis_files = Split("""
strlist.cpp
tokens.cpp
util.cpp
+ winchar.cpp
writer.cpp
""")
@@ -34,12 +36,13 @@ bzip2_files = Split("""
lzma_files = Split("""
7zip/7zGuids.cpp
- 7zip/Common/CRC.cpp
+ 7zip/7zip/Common/OutBuffer.cpp
+ 7zip/7zip/Common/StreamUtils.cpp
7zip/7zip/Compress/LZ/LZInWindow.cpp
7zip/7zip/Compress/LZMA/LZMAEncoder.cpp
- 7zip/7zip/Common/OutBuffer.cpp
7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp
7zip/Common/Alloc.cpp
+ 7zip/Common/CRC.cpp
""")
zlib_files = Split("""
@@ -78,7 +81,7 @@ env.Append(CPPDEFINES = ['_WIN32_IE=0x0500'])
##### LZMA specific defines
-lzma_env = env.Copy()
+lzma_env = env.Clone()
lzma_env.Append(CPPDEFINES = ['COMPRESS_MF_BT'])
lzma_files = lzma_env.Object(lzma_files)
diff --git a/Source/ShConstants.cpp b/Source/ShConstants.cpp
index 01269d5..66f2a27 100755
--- a/Source/ShConstants.cpp
+++ b/Source/ShConstants.cpp
@@ -1,3 +1,19 @@
+/*
+ * ShConstants.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "ShConstants.h"
ConstantsStringList::ConstantsStringList()
diff --git a/Source/ShConstants.h b/Source/ShConstants.h
index bb82506..9875b51 100755
--- a/Source/ShConstants.h
+++ b/Source/ShConstants.h
@@ -1,4 +1,18 @@
-// constants.h by Ramon 18 Nov 2003
+/*
+ * ShConstants.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 2003 Ramon
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef ___CONSTANTS___H_____
#define ___CONSTANTS___H_____
diff --git a/Source/Tests/SConscript b/Source/Tests/SConscript
index 11e85da..63617bb 100755
--- a/Source/Tests/SConscript
+++ b/Source/Tests/SConscript
@@ -1,12 +1,15 @@
target = 'test'
tests = Split("""
+ compression.cpp
+ decompress.cpp
DialogTemplate.cpp
endian.cpp
mmap.cpp
ResourceEditor.cpp
specmatch.cpp
textrunner.cpp
+ winchar.cpp
""")
required = Split("""
@@ -16,8 +19,55 @@ required = Split("""
mmap.cpp
ResourceEditor.cpp
util.cpp
+ winchar.cpp
""")
+required_exehead = Split("""
+ Tests/memcpy.c
+""")
+
+lzma_files = Split("""
+ clzma.cpp
+ 7zip/7zGuids.cpp
+ 7zip/7zip/Common/OutBuffer.cpp
+ 7zip/7zip/Common/StreamUtils.cpp
+ 7zip/7zip/Compress/LZ/LZInWindow.cpp
+ 7zip/7zip/Compress/LZMA/LZMAEncoder.cpp
+ 7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp
+ 7zip/Common/Alloc.cpp
+ 7zip/Common/CRC.cpp
+ 7zip/LZMADecode.c
+""")
+
+required += lzma_files
+
+bzip2_files = Split("""
+ bzip2/blocksort.c
+ bzip2/bzlib.c
+ bzip2/compress.c
+ bzip2/huffman.c
+""")
+
+bzip2_exehead_files = Split("""
+ bzip2/bzlib.c
+ bzip2/decompress.c
+""")
+
+required += bzip2_files
+required_exehead += bzip2_exehead_files
+
+zlib_files = Split("""
+ zlib/deflate.c
+ zlib/trees.c
+""")
+
+zlib_exehead_files = Split("""
+ zlib/INFBLOCK.C
+""")
+
+required += zlib_files
+required_exehead += zlib_exehead_files
+
cppunitlibs = Split("""
cppunit
""")
@@ -26,6 +76,7 @@ extralibs = Split("""
dl
gdi32
iconv
+ pthread
user32
""")
@@ -48,6 +99,9 @@ if 'msvc' in env['TOOLS'] or 'mstoolkit' in env['TOOLS']:
# uses exceptions
env.Append(CCFLAGS = ['$EXCEPTION_FLAG'])
+# for lzma
+env.Append(CPPDEFINES = ['COMPRESS_MF_BT'])
+
# test for CppUnit
conf = env.Configure()
cppunit = conf.CheckLibWithHeader(cppunitlibs, 'cppunit/extensions/HelperMacros.h', 'C++')
@@ -59,12 +113,29 @@ if cppunit:
required_obj = []
for i in required:
- b = 'required/%s' % i[:-4]
+ b = 'required/%s' % i.split('.')[0]
s = '#Source/%s' % i
o = env.Object(b, s)
required_obj.append(o)
+ # exehead files special treatment
+ exehead_env = env.Clone()
+ exehead_env.Append(CCFLAGS = ['$C_FLAG'])
+ exehead_env.Append(
+ CPPDEFINES = [
+ 'EXEHEAD',
+ 'NSIS_COMPRESS_USE_ZLIB' # just so config.h won't complain
+ ]
+ )
+
+ for i in required_exehead:
+ b = 'required/exehead/%s' % i.split('.')[0]
+ s = '#Source/%s' % i
+ o = exehead_env.Object(b, s)
+
+ required_obj.append(o)
+
# build test program
tests = env.Program(target, tests + required_obj)
diff --git a/Source/Tests/compression.cpp b/Source/Tests/compression.cpp
new file mode 100755
index 0000000..e9a1241
--- /dev/null
+++ b/Source/Tests/compression.cpp
@@ -0,0 +1,154 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include "../Platform.h"
+#include "../growbuf.h"
+
+#include <stdlib.h>
+#include <time.h>
+
+#include "decompress.h"
+
+#include "../cbzip2.h"
+#include "../clzma.h"
+#include "../czlib.h"
+
+class CompressionTest : public CppUnit::TestFixture {
+
+public:
+ void randData(IGrowBuf &buf, int kb) {
+ srand(time(0));
+
+ for (int i = 0; i < kb; i++) {
+ int r = rand();
+ for (int j = 0; j < 1024/sizeof(int); j++) {
+ buf.add(&r, sizeof(int));
+ }
+ }
+ }
+
+ // compressor must be initialized!
+ void compress(ICompressor &compressor, IGrowBuf& in, IGrowBuf& out) {
+ compressor.SetNextIn((char *) in.get(), in.getlen());
+
+ int ret;
+
+ do {
+ char outbuf[1024];
+ compressor.SetNextOut(outbuf, sizeof(outbuf));
+
+ ret = compressor.Compress(C_FINISH);
+
+ CPPUNIT_ASSERT_MESSAGE( compressor.GetErrStr(ret) , ret >= 0 );
+
+ out.add(outbuf, sizeof(outbuf) - compressor.GetAvailOut());
+ } while (ret == 0);
+ }
+
+ typedef void (*decompressInitPtr)(void *);
+ typedef int (*decompressWorkPtr)(void *);
+
+ void decompress(IDecompressor& decompressor, IGrowBuf& in, IGrowBuf& out) {
+ decompressor.init();
+ decompressor.setNextIn(in.get(), in.getlen());
+
+ int ret;
+
+ do {
+ char outbuf[1024];
+ decompressor.setNextOut(outbuf, sizeof(outbuf));
+
+ ret = decompressor.decompress();
+
+ CPPUNIT_ASSERT( ret >= 0 );
+
+ out.add(outbuf, sizeof(outbuf) - decompressor.getAvailOut());
+
+ } while (ret == 0);
+
+ }
+
+ // compressor must be initialized!
+ void testCompressDecompress(int size_kb, ICompressor &compressor, IDecompressor& decompressor) {
+ GrowBuf data;
+ GrowBuf compressed;
+ GrowBuf decompressed;
+
+ randData(data, size_kb);
+
+ compress(compressor, data, compressed);
+ decompress(decompressor, compressed, decompressed);
+
+ CPPUNIT_ASSERT_MESSAGE( "decompressed data is smaller", data.getlen() <= decompressed.getlen() );
+ CPPUNIT_ASSERT_MESSAGE( "decompressed data is larger", data.getlen() >= decompressed.getlen() );
+ CPPUNIT_ASSERT_MESSAGE( "decompressed data is different", !memcmp(data.get(), decompressed.get(), data.getlen()) );
+ }
+
+ void testCompressDecompress(ICompressor &compressor, IDecompressor& decompressor) {
+ CPPUNIT_ASSERT( compressor.Init(9, 1 << 23) == C_OK );
+ testCompressDecompress(1, compressor, decompressor);
+
+ CPPUNIT_ASSERT( compressor.Init(9, 1 << 23) == C_OK );
+ testCompressDecompress(1024, compressor, decompressor);
+
+ CPPUNIT_ASSERT( compressor.Init(9, 1 << 23) == C_OK );
+ testCompressDecompress(8*1024, compressor, decompressor);
+
+ CPPUNIT_ASSERT( compressor.Init(9, 1 << 23) == C_OK );
+ testCompressDecompress(32*1024, compressor, decompressor);
+ }
+
+};
+
+class bzip2CompressionTest : public CompressionTest {
+
+ CPPUNIT_TEST_SUITE( bzip2CompressionTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+ void test() {
+ CBzip2 compressor;
+ bzip2Decompressor decompressor;
+
+ testCompressDecompress(compressor, decompressor);
+ }
+
+};
+
+class lzmaCompressionTest : public CompressionTest {
+
+ CPPUNIT_TEST_SUITE( lzmaCompressionTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+ void test() {
+ CLZMA compressor;
+ lzmaDecompressor decompressor;
+
+ testCompressDecompress(compressor, decompressor);
+ }
+
+};
+
+class zlibCompressionTest : public CompressionTest {
+
+ CPPUNIT_TEST_SUITE( zlibCompressionTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+ void test() {
+ CZlib compressor;
+ zlibDecompressor decompressor;
+
+ testCompressDecompress(compressor, decompressor);
+ }
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION( bzip2CompressionTest );
+CPPUNIT_TEST_SUITE_REGISTRATION( lzmaCompressionTest );
+CPPUNIT_TEST_SUITE_REGISTRATION( zlibCompressionTest );
diff --git a/Source/Tests/decompress.cpp b/Source/Tests/decompress.cpp
new file mode 100755
index 0000000..8f27f7b
--- /dev/null
+++ b/Source/Tests/decompress.cpp
@@ -0,0 +1,62 @@
+#include "decompress.h"
+
+#include <string.h> // for memset
+
+#define EXEHEAD
+#define NSIS_CONFIG_COMPRESSION_SUPPORT
+
+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; \
+ memset(vs, 0, sizeof(type)); \
+ } \
+ \
+ name::~name() { \
+ delete (type *) vs; \
+ vs = 0; \
+ } \
+ \
+ 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);
+DECOMPRESSOR(bzip2Decompressor, DState, BZ2_bzDecompressInit, BZ2_bzDecompress, char);
+DECOMPRESSOR(zlibDecompressor, z_stream, inflateReset, inflate, unsigned char);
diff --git a/Source/Tests/decompress.h b/Source/Tests/decompress.h
new file mode 100755
index 0000000..4f0e492
--- /dev/null
+++ b/Source/Tests/decompress.h
@@ -0,0 +1,66 @@
+class IDecompressor {
+public:
+
+ virtual ~IDecompressor() {};
+
+ virtual void init() = 0;
+ virtual void setNextIn(void *buffer, int size) = 0;
+ virtual void setNextOut(void *buffer, int size) = 0;
+ virtual int getAvailOut() = 0;
+ virtual int decompress() = 0;
+
+};
+
+class lzmaDecompressor : public IDecompressor {
+public:
+
+ lzmaDecompressor();
+ virtual ~lzmaDecompressor();
+
+ virtual void init();
+ virtual void setNextIn(void *buffer, int size);
+ virtual void setNextOut(void *buffer, int size);
+ virtual int getAvailOut();
+ virtual int decompress();
+
+private:
+
+ void *vs;
+
+};
+
+class bzip2Decompressor : public IDecompressor {
+public:
+
+ bzip2Decompressor();
+ virtual ~bzip2Decompressor();
+
+ virtual void init();
+ virtual void setNextIn(void *buffer, int size);
+ virtual void setNextOut(void *buffer, int size);
+ virtual int getAvailOut();
+ virtual int decompress();
+
+private:
+
+ void *vs;
+
+};
+
+class zlibDecompressor : public IDecompressor {
+public:
+
+ zlibDecompressor();
+ virtual ~zlibDecompressor();
+
+ virtual void init();
+ virtual void setNextIn(void *buffer, int size);
+ virtual void setNextOut(void *buffer, int size);
+ virtual int getAvailOut();
+ virtual int decompress();
+
+private:
+
+ void *vs;
+
+};
diff --git a/Source/Tests/endian.cpp b/Source/Tests/endian.cpp
index 85e4967..ed9b2e2 100755
--- a/Source/Tests/endian.cpp
+++ b/Source/Tests/endian.cpp
@@ -53,4 +53,4 @@ public:
};
-CPPUNIT_TEST_SUITE_REGISTRATION( EndianTest ); \ No newline at end of file
+CPPUNIT_TEST_SUITE_REGISTRATION( EndianTest );
diff --git a/Source/Tests/memcpy.c b/Source/Tests/memcpy.c
new file mode 100755
index 0000000..f2828e8
--- /dev/null
+++ b/Source/Tests/memcpy.c
@@ -0,0 +1,11 @@
+#include "../Platform.h"
+
+void NSISCALL mini_memcpy(void *out, const void *in, int len)
+{
+ char *c_out=(char*)out;
+ char *c_in=(char *)in;
+ while (len-- > 0)
+ {
+ *c_out++=*c_in++;
+ }
+}
diff --git a/Source/Tests/mmap.cpp b/Source/Tests/mmap.cpp
index 4c8b324..cdc8790 100755
--- a/Source/Tests/mmap.cpp
+++ b/Source/Tests/mmap.cpp
@@ -41,8 +41,7 @@ public:
int offset2 = rand() % BUF_SIZE;
int size2 = rand() % (BUF_SIZE - offset2);
- int size2forrelease = size2;
- char *p2 = (char *) mmap.getmore(offset2, &size2forrelease);
+ char *p2 = (char *) mmap.getmore(offset2, size2);
int minsize = min(size1, size2);
for (size_t j = 0; j < minsize; j++) {
@@ -50,7 +49,7 @@ public:
}
mmap.release();
- mmap.release(p2, size2forrelease);
+ mmap.release(p2, size2);
}
}
diff --git a/Source/Tests/preprocessor.nsi b/Source/Tests/preprocessor.nsi
index b8722cf..751fdce 100755
--- a/Source/Tests/preprocessor.nsi
+++ b/Source/Tests/preprocessor.nsi
@@ -10,6 +10,8 @@ this should not be executed, so no error should be raised
code inside comments should not be executed
!ifdef
*/
+# invalid preprocessor should be ignored
+!hello
!endif
!ifdef d1
@@ -51,6 +53,13 @@ d\
i\
f
+!if 0
+/*
+this shouldn't be compiled
+!endif
+*/
+!endif
+
# tests for !if statement
!if 'test' == 'test'
!if 1 <= 2
@@ -129,9 +138,87 @@ ${increase} number3
!include preprocessor.nsi
Section
+Return
+WriteUninstaller uninst.exe # avoid warning
+SectionEnd
+
+# test scopes
+
+!macro TEST_SCOPE scope def should_exist
+
+ !if ${should_exist} == y
+ !ifndef ${def}
+ !error "${def} not defined in ${scope} scope"
+ !endif
+ !else
+ !ifdef ${def}
+ !error "${def} defined in ${scope} scope"
+ !endif
+ !endif
+
+!macroend
+
+!macro TEST_SCOPES scope global section function pageex uninstall
+
+ !insertmacro TEST_SCOPE "${scope}" __GLOBAL__ ${global}
+ !insertmacro TEST_SCOPE "${scope}" __SECTION__ ${section}
+ !insertmacro TEST_SCOPE "${scope}" __FUNCTION__ ${function}
+ !insertmacro TEST_SCOPE "${scope}" __PAGEEX__ ${pageex}
+ !insertmacro TEST_SCOPE "${scope}" __UNINSTALL__ ${uninstall}
+
+!macroend
+
+!insertmacro TEST_SCOPES "global" y n n n n
+
+Section test
+!insertmacro TEST_SCOPES "section" n y n n n
+!if ${__SECTION__} != test
+ !error "invalid __SECTION__ value"
+!endif
SectionEnd
+Section un.test
+!insertmacro TEST_SCOPES "uninstall section" n y n n y
+!if ${__SECTION__} != test
+ !error "invalid __SECTION__ value"
+!endif
+SectionEnd
+
+Function test
+Call test # avoid warning
+!insertmacro TEST_SCOPES "function" n n y n n
+!if ${__FUNCTION__} != test
+ !error "invalid __FUNCTION__ value"
+!endif
+FunctionEnd
+
+Function un.test
+Call un.test # avoid warning
+!insertmacro TEST_SCOPES "uninstall function" n n y n y
+!if ${__FUNCTION__} != test
+ !error "invalid __FUNCTION__ value"
+!endif
+FunctionEnd
+
+PageEx instfiles
+!insertmacro TEST_SCOPES "pageex" n n n y n
+!if ${__PAGEEX__} != instfiles
+ !error "invalid __PAGEEX__ value"
+!endif
+PageExEnd
+
+PageEx un.instfiles
+!insertmacro TEST_SCOPES "uninstall pageex" n n n y y
+!if ${__PAGEEX__} != instfiles
+ !error "invalid __PAGEEX__ value"
+!endif
+PageExEnd
+
+!insertmacro TEST_SCOPES "global" y n n n n
+
!else
+
# this should just give a warning, not an error
!include /NONFATAL another_file_that_doesnt_exist.nsh
+
!endif
diff --git a/Source/Tests/textrunner.cpp b/Source/Tests/textrunner.cpp
index faa3657..4c5179f 100755
--- a/Source/Tests/textrunner.cpp
+++ b/Source/Tests/textrunner.cpp
@@ -19,4 +19,4 @@ int main(int argc, char* argv[])
// Return error code 1 if the one of test failed.
return wasSucessful ? 0 : 1;
-} \ No newline at end of file
+}
diff --git a/Source/Tests/winchar.cpp b/Source/Tests/winchar.cpp
new file mode 100755
index 0000000..d25ebb2
--- /dev/null
+++ b/Source/Tests/winchar.cpp
@@ -0,0 +1,126 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include "../winchar.h"
+
+#include <time.h>
+#include <stdlib.h>
+
+class WinCharTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( WinCharTest );
+ CPPUNIT_TEST( testFromAnsi );
+ CPPUNIT_TEST( testToAnsi );
+ CPPUNIT_TEST( testStrCpy );
+ CPPUNIT_TEST( testStrNCpy );
+ CPPUNIT_TEST( testStrLen );
+ CPPUNIT_TEST( testStrCmp );
+ CPPUNIT_TEST( testStrDup );
+ CPPUNIT_TEST( testStoi );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void testFromAnsi() {
+ WCHAR test[] = { 't', 'e', 's', 't', 0 };
+ WCHAR *dyn = winchar_fromansi("test");
+
+ CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) );
+
+ delete [] dyn;
+ }
+
+ void testToAnsi() {
+ WCHAR test[] = { 't', 'e', 's', 't', 0 };
+ char *dyn = winchar_toansi(test);
+
+ CPPUNIT_ASSERT_EQUAL( 0, strcmp("test", dyn) );
+
+ delete [] dyn;
+ }
+
+ void testStrCpy() {
+ WCHAR a[] = { 't', 'e', 's', 't', 0 };
+ WCHAR b[5];
+
+ CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strcpy(b, a) );
+ CPPUNIT_ASSERT_EQUAL( 0, memcmp(a, b, 5) );
+ }
+
+ void testStrNCpy() {
+ WCHAR a1[] = { 't', 'e', 's', 't', 0 };
+ WCHAR b[5];
+
+ CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strncpy(b, a1, 5) );
+ CPPUNIT_ASSERT_EQUAL( 0, memcmp(a1, b, 5 * sizeof(WCHAR)) );
+
+ WCHAR a2[] = { 't', 'e', 0, 0, 0 };
+
+ CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strncpy(b, a2, 5) );
+ CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WCHAR)) );
+
+ CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strncpy(b, a1, 2) );
+ CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WCHAR)) );
+ }
+
+ void testStrLen() {
+ WCHAR test[] = { 't', 'e', 's', 't', 0 };
+
+ CPPUNIT_ASSERT_EQUAL( (size_t) 4, winchar_strlen(test) );
+ }
+
+ static int simplifyNumber(int n) {
+ if (n < 0)
+ return -1;
+ if (n > 0)
+ return 1;
+ return 0;
+ }
+
+ void testStrCmp() {
+ char a[] = "a";
+ WCHAR wa[] = { 'a', 0 };
+ char b[] = "b";
+ WCHAR wb[] = { 'b', 0 };
+ char empty[] = "";
+ WCHAR wempty[] = { 0 };
+
+ #define TEST_STR_CMP(x, y) \
+ CPPUNIT_ASSERT_EQUAL(\
+ simplifyNumber(strcmp(x, y)), \
+ simplifyNumber(winchar_strcmp(w##x, w##y)) \
+ )
+
+ TEST_STR_CMP(a, b);
+ TEST_STR_CMP(b, a);
+ TEST_STR_CMP(a, a);
+ TEST_STR_CMP(b, b);
+ TEST_STR_CMP(a, empty);
+ TEST_STR_CMP(empty, b);
+ TEST_STR_CMP(empty, empty);
+ }
+
+ void testStrDup() {
+ WCHAR a[] = { 'a', 'b', 'c', 0 };
+
+ WCHAR *b = winchar_strdup(a);
+
+ CPPUNIT_ASSERT_EQUAL( 0, winchar_strcmp(a, b) );
+
+ delete [] b;
+ }
+
+ void testStoi() {
+ srand(time(0));
+
+ for (int i = 0; i < 1000; i++)
+ {
+ int r = rand();
+ char s[128];
+ sprintf(s, "%d", r);
+ WCHAR *ws = winchar_fromansi(s);
+ CPPUNIT_ASSERT_EQUAL( r, winchar_stoi(ws) );
+ delete [] ws;
+ }
+ }
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION( WinCharTest );
diff --git a/Source/afxres.h b/Source/afxres.h
index ee9c4d6..b9e682f 100755
--- a/Source/afxres.h
+++ b/Source/afxres.h
@@ -1,3 +1,19 @@
+/*
+ * afxres.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#ifndef IDC_STATIC
diff --git a/Source/build.cpp b/Source/build.cpp
index 56eeeba..f72c85a 100755
--- a/Source/build.cpp
+++ b/Source/build.cpp
@@ -1,3 +1,19 @@
+/*
+ * build.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#include <stdio.h>
#include "exehead/config.h"
@@ -9,6 +25,7 @@
#include "fileform.h"
#include "writer.h"
#include "crc32.h"
+#include "manifest.h"
#include <stdexcept>
@@ -226,6 +243,9 @@ CEXEBuild::CEXEBuild() :
res_editor=0;
+ manifest_comctl = manifest::comctl_old;
+ manifest_exec_level = manifest::exec_level_none;
+
enable_last_page_cancel=0;
uenable_last_page_cancel=0;
@@ -294,7 +314,7 @@ CEXEBuild::CEXEBuild() :
m_ShellConstants.add("SMSTARTUP",CSIDL_STARTUP, CSIDL_COMMON_STARTUP);
m_ShellConstants.add("DESKTOP",CSIDL_DESKTOPDIRECTORY, CSIDL_COMMON_DESKTOPDIRECTORY);
m_ShellConstants.add("STARTMENU",CSIDL_STARTMENU, CSIDL_COMMON_STARTMENU);
- m_ShellConstants.add("QUICKLAUNCH", CSIDL_APPDATA, CSIDL_PRINTERS);
+ m_ShellConstants.add("QUICKLAUNCH", CSIDL_APPDATA, CSIDL_APPDATA);
m_ShellConstants.add("COMMONFILES",CSIDL_PROGRAM_FILES_COMMON, CSIDL_PROGRAM_FILES_COMMON);
m_ShellConstants.add("DOCUMENTS",CSIDL_PERSONAL, CSIDL_COMMON_DOCUMENTS);
m_ShellConstants.add("SENDTO",CSIDL_SENDTO, CSIDL_SENDTO);
@@ -318,6 +338,8 @@ CEXEBuild::CEXEBuild() :
m_ShellConstants.add("RESOURCES", CSIDL_RESOURCES, CSIDL_RESOURCES);
m_ShellConstants.add("RESOURCES_LOCALIZED", CSIDL_RESOURCES_LOCALIZED, CSIDL_RESOURCES_LOCALIZED);
m_ShellConstants.add("CDBURN_AREA", CSIDL_CDBURN_AREA, CSIDL_CDBURN_AREA);
+
+ set_code_type_predefines();
}
void CEXEBuild::initialize(const char *makensis_path)
@@ -594,13 +616,12 @@ int CEXEBuild::datablock_optimize(int start_offset, int first_int)
while (left > 0)
{
int l = min(left, build_filebuflen);
- int la = l;
void *newstuff = db->get(start_offset + this_len - left, l);
- void *oldstuff = db->getmore(pos + this_len - left, &la);
+ void *oldstuff = db->getmore(pos + this_len - left, l);
int res = memcmp(newstuff, oldstuff, l);
- db->release(oldstuff, la);
+ db->release(oldstuff, l);
db->release();
if (res)
@@ -918,10 +939,10 @@ int CEXEBuild::add_function(const char *funname)
for (x = 0; x < n; x ++)
{
if (tmp[x].name_ptr == addr)
- {
- ERROR_MSG("Error: Function named \"%s\" already exists.\n",funname);
- return PS_ERROR;
- }
+ {
+ ERROR_MSG("Error: Function named \"%s\" already exists.\n",funname);
+ return PS_ERROR;
+ }
}
cur_functions->resize((n+1)*sizeof(section));
@@ -934,6 +955,12 @@ int CEXEBuild::add_function(const char *funname)
build_cursection->flags=0;
build_cursection->size_kb=0;
memset(build_cursection->name,0,sizeof(build_cursection->name));
+
+ if (uninstall_mode)
+ set_code_type_predefines(funname+3);
+ else
+ set_code_type_predefines(funname);
+
return PS_OK;
}
@@ -951,6 +978,8 @@ int CEXEBuild::function_end()
build_cursection=NULL;
set_uninstall_mode(0);
+
+ set_code_type_predefines();
return PS_OK;
}
@@ -1004,6 +1033,8 @@ int CEXEBuild::section_end()
build_cursection=NULL;
if (!sectiongroup_open_cnt)
set_uninstall_mode(0);
+
+ set_code_type_predefines();
return PS_OK;
}
@@ -1127,7 +1158,9 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/
else
sectiongroup_open_cnt++;
}
-
+
+ set_code_type_predefines(name);
+
return PS_OK;
}
@@ -1511,26 +1544,27 @@ int CEXEBuild::add_page(int type)
struct {
int wndproc_id;
int dlg_id;
+ char *name;
} ids[] = {
- {PWP_CUSTOM, 0}, // custom
+ {PWP_CUSTOM, 0, "custom"}, // custom
#ifdef NSIS_CONFIG_LICENSEPAGE
- {PWP_LICENSE, IDD_LICENSE}, // license
+ {PWP_LICENSE, IDD_LICENSE, "license"}, // license
#else
- {0, IDD_LICENSE}, // license
+ {0, IDD_LICENSE, "license"}, // license
#endif
#ifdef NSIS_CONFIG_COMPONENTPAGE
- {PWP_SELCOM, IDD_SELCOM}, // components
+ {PWP_SELCOM, IDD_SELCOM, "components"}, // components
#else
- {0, IDD_SELCOM}, // components
+ {0, IDD_SELCOM, "components"}, // components
#endif
- {PWP_DIR, IDD_DIR}, // directory
- {PWP_INSTFILES, IDD_INSTFILES}, // instfiles
+ {PWP_DIR, IDD_DIR, "directory"}, // directory
+ {PWP_INSTFILES, IDD_INSTFILES, "instfiles"}, // instfiles
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
- {PWP_UNINST, IDD_UNINST}, // uninstConfirm
+ {PWP_UNINST, IDD_UNINST, "uninstConfirm"}, // uninstConfirm
#else
- {0, IDD_UNINST}, // uninstConfirm
+ {0, IDD_UNINST, "uninstConfirm"}, // uninstConfirm
#endif
- {PWP_COMPLETED, -1} // completed
+ {PWP_COMPLETED, -1, NULL} // completed
};
pg.wndproc_id = ids[type].wndproc_id;
@@ -1541,7 +1575,8 @@ int CEXEBuild::add_page(int type)
cur_page = (page *)cur_pages->get() + cur_header->blocks[NB_PAGES].num++;
cur_page_type = type;
-
+
+ set_code_type_predefines(ids[type].name);
return PS_OK;
}
@@ -1549,6 +1584,7 @@ int CEXEBuild::page_end()
{
cur_page = 0;
+ set_code_type_predefines();
return PS_OK;
}
#endif
@@ -1583,17 +1619,18 @@ int CEXEBuild::AddVersionInfo()
{
LANGID lang_id = rVersionInfo.GetLangID(i);
int code_page = rVersionInfo.GetCodePage(i);
- LanguageTable *Table = GetLangTable(lang_id);
+
+ char *lang_name = GetLangNameAndCP(lang_id);
if ( !rVersionInfo.FindKey(lang_id, code_page, "FileVersion") )
- warning("Generating version information for language \"%04d-%s\" without standard key \"FileVersion\"", lang_id, Table->nlf.m_bLoaded ? Table->nlf.m_szName : lang_id == 1033 ? "English" : "???");
+ warning("Generating version information for language \"%04d-%s\" without standard key \"FileVersion\"", lang_id, lang_name);
if ( !rVersionInfo.FindKey(lang_id, code_page, "FileDescription") )
- warning("Generating version information for language \"%04d-%s\" without standard key \"FileDescription\"", lang_id, Table->nlf.m_bLoaded ? Table->nlf.m_szName : lang_id == 1033 ? "English" : "???");
+ warning("Generating version information for language \"%04d-%s\" without standard key \"FileDescription\"", lang_id, lang_name);
if ( !rVersionInfo.FindKey(lang_id, code_page, "LegalCopyright") )
- warning("Generating version information for language \"%04d-%s\" without standard key \"LegalCopyright\"", lang_id, Table->nlf.m_bLoaded ? Table->nlf.m_szName : lang_id == 1033 ? "English" : "???");
+ warning("Generating version information for language \"%04d-%s\" without standard key \"LegalCopyright\"", lang_id, lang_name);
rVersionInfo.ExportToStream(VerInfoStream, i);
- res_editor->UpdateResource(RT_VERSION, 1, lang_id, (BYTE*)VerInfoStream.get(), VerInfoStream.getlen());
+ res_editor->UpdateResourceA(RT_VERSION, 1, lang_id, (BYTE*)VerInfoStream.get(), VerInfoStream.getlen());
}
}
catch (exception& err) {
@@ -1932,7 +1969,7 @@ again:
SCRIPT_MSG("Done!\n");
#define REMOVE_ICON(id) if (disable_window_icon) { \
- BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \
+ BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \
if (dlg) { \
CDialogTemplate dt(dlg,uDefCodePage); \
res_editor->FreeResource(dlg); \
@@ -1950,7 +1987,7 @@ again:
\
DWORD dwSize; \
dlg = dt.Save(dwSize); \
- res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \
+ res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \
delete [] dlg; \
} \
} \
@@ -1961,43 +1998,43 @@ again:
init_res_editor();
#ifdef NSIS_CONFIG_LICENSEPAGE
if (!license_normal) {
- res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_LICENSE, NSIS_DEFAULT_LANG, 0, 0);
}
else REMOVE_ICON(IDD_LICENSE);
if (!license_fsrb) {
- res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE_FSRB, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_LICENSE_FSRB, NSIS_DEFAULT_LANG, 0, 0);
}
else REMOVE_ICON(IDD_LICENSE_FSRB);
if (!license_fscb) {
- res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE_FSCB, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_LICENSE_FSCB, NSIS_DEFAULT_LANG, 0, 0);
}
else REMOVE_ICON(IDD_LICENSE_FSCB);
#endif // NSIS_CONFIG_LICENSEPAGE
#ifdef NSIS_CONFIG_COMPONENTPAGE
if (!selcom) {
- res_editor->UpdateResource(RT_DIALOG, IDD_SELCOM, NSIS_DEFAULT_LANG, 0, 0);
- res_editor->UpdateResource(RT_BITMAP, IDB_BITMAP1, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_SELCOM, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_BITMAP, IDB_BITMAP1, NSIS_DEFAULT_LANG, 0, 0);
}
else REMOVE_ICON(IDD_SELCOM);
#endif // NSIS_CONFIG_COMPONENTPAGE
if (!dir) {
- res_editor->UpdateResource(RT_DIALOG, IDD_DIR, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_DIR, NSIS_DEFAULT_LANG, 0, 0);
}
else REMOVE_ICON(IDD_DIR);
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
if (!uninstconfirm) {
- res_editor->UpdateResource(RT_DIALOG, IDD_UNINST, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_UNINST, NSIS_DEFAULT_LANG, 0, 0);
}
else REMOVE_ICON(IDD_UNINST);
#endif // NSIS_CONFIG_UNINSTALL_SUPPORT
if (!instlog) {
- res_editor->UpdateResource(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, 0, 0);
}
else REMOVE_ICON(IDD_INSTFILES);
if (!main) {
- res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, 0, 0);
if (!build_compress_whole && !build_crcchk)
- res_editor->UpdateResource(RT_DIALOG, IDD_VERIFY, NSIS_DEFAULT_LANG, 0, 0);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_VERIFY, NSIS_DEFAULT_LANG, 0, 0);
}
SCRIPT_MSG("Done!\n");
@@ -2047,6 +2084,20 @@ void CEXEBuild::PrepareInstTypes()
}
#endif
+void CEXEBuild::AddStandardStrings()
+{
+#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
+ if (uninstall_mode)
+ {
+ cur_header->str_uninstchild = add_string("$TEMP\\$1");
+ cur_header->str_uninstcmd = add_string("\"$TEMP\\$1\" $0 _?=$INSTDIR\\");
+ }
+#endif//NSIS_CONFIG_UNINSTALL_SUPPORT
+#ifdef NSIS_SUPPORT_MOVEONREBOOT
+ cur_header->str_wininit = add_string("$WINDIR\\wininit.ini");
+#endif//NSIS_SUPPORT_MOVEONREBOOT
+}
+
void CEXEBuild::PrepareHeaders(IGrowBuf *hdrbuf)
{
GrowBuf blocks_buf;
@@ -2091,6 +2142,48 @@ void CEXEBuild::PrepareHeaders(IGrowBuf *hdrbuf)
sink2.write_growbuf(&blocks_buf);
}
+int CEXEBuild::SetVarsSection()
+{
+ try {
+ init_res_editor();
+
+ VerifyDeclaredUserVarRefs(&m_UserVarNames);
+ int MaxUserVars = m_UserVarNames.getnum();
+ // -1 because the default size is 1
+ if (!res_editor->AddExtraVirtualSize2PESection(NSIS_VARS_SECTION, (MaxUserVars - 1) * sizeof(NSIS_STRING)))
+ {
+ ERROR_MSG("Internal compiler error #12346: invalid exehead cannot find section \"%s\"!\n", NSIS_VARS_SECTION);
+ return PS_ERROR;
+ }
+ }
+ catch (exception& err) {
+ ERROR_MSG("\nError: %s\n", err.what());
+ return PS_ERROR;
+ }
+
+ return PS_OK;
+}
+
+int CEXEBuild::SetManifest()
+{
+ try {
+ init_res_editor();
+
+ string manifest = manifest::generate(manifest_comctl, manifest_exec_level);
+
+ if (manifest == "")
+ return PS_OK;
+
+ res_editor->UpdateResourceA(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), NSIS_DEFAULT_LANG, (LPBYTE) manifest.c_str(), manifest.length());
+ }
+ catch (exception& err) {
+ ERROR_MSG("Error while setting manifest: %s\n", err.what());
+ return PS_ERROR;
+ }
+
+ return PS_OK;
+}
+
int CEXEBuild::check_write_output_errors() const
{
if (has_called_write_output)
@@ -2151,20 +2244,27 @@ int CEXEBuild::prepare_uninstaller() {
{
if (!uninstaller_writes_used)
{
- warning("Uninstall section found but WriteUninstaller never used - no uninstaller will be created.");
+ warning("Uninstaller script code found but WriteUninstaller never used - no uninstaller will be created.");
return PS_OK;
}
build_uninst.flags|=build_header.flags&(CH_FLAGS_PROGRESS_COLORED|CH_FLAGS_NO_ROOT_DIR);
set_uninstall_mode(1);
+
DefineInnerLangString(NLF_UCAPTION);
+
if (resolve_coderefs("uninstall"))
return PS_ERROR;
+
#ifdef NSIS_CONFIG_COMPONENTPAGE
// set sections to the first insttype
PrepareInstTypes();
#endif
+
+ // Add standard strings to string table
+ AddStandardStrings();
+
set_uninstall_mode(0);
}
else if (uninstaller_writes_used)
@@ -2248,18 +2348,16 @@ int CEXEBuild::write_output(void)
// Generate language tables
RET_UNLESS_OK( GenerateLangTables() );
- try {
- init_res_editor();
+ // Setup user variables PE section
+ RET_UNLESS_OK( SetVarsSection() );
- VerifyDeclaredUserVarRefs(&m_UserVarNames);
- int MaxUserVars = m_UserVarNames.getnum();
- // -1 because the default size is 1
- if (!res_editor->AddExtraVirtualSize2PESection(NSIS_VARS_SECTION, (MaxUserVars - 1) * sizeof(NSIS_STRING)))
- {
- ERROR_MSG("Internal compiler error #12346: invalid exehead cannot find section \"%s\"!\n", NSIS_VARS_SECTION);
- return PS_ERROR;
- }
+ // Set XML manifest
+ RET_UNLESS_OK( SetManifest() );
+
+ // Add standard strings to string table
+ AddStandardStrings();
+ try {
// Save all changes to the exe header
close_res_editor();
}
@@ -2917,6 +3015,8 @@ void CEXEBuild::set_uninstall_mode(int un)
cur_strlist=&ubuild_strlist;
cur_langtables=&ubuild_langtables;
cur_ctlcolors=&ubuild_ctlcolors;
+
+ definedlist.add("__UNINSTALL__");
}
else
{
@@ -2932,6 +3032,8 @@ void CEXEBuild::set_uninstall_mode(int un)
cur_strlist=&build_strlist;
cur_langtables=&build_langtables;
cur_ctlcolors=&build_ctlcolors;
+
+ definedlist.del("__UNINSTALL__");
}
SWAP(db_opt_save_u,db_opt_save,int);
@@ -3331,3 +3433,26 @@ void CEXEBuild::update_exehead(const unsigned char *new_exehead, size_t new_size
memset(m_exehead + new_size, 0, m_exehead_size - new_size);
}
+void CEXEBuild::set_code_type_predefines(const char *value)
+{
+ definedlist.del("__SECTION__");
+ definedlist.del("__FUNCTION__");
+ definedlist.del("__PAGEEX__");
+ definedlist.del("__GLOBAL__");
+
+ switch (GetCurrentTokenPlace())
+ {
+ case TP_SEC:
+ definedlist.add("__SECTION__", value==NULL?"":value);
+ break;
+ case TP_FUNC:
+ definedlist.add("__FUNCTION__", value==NULL?"":value);
+ break;
+ case TP_PAGEEX:
+ definedlist.add("__PAGEEX__", value==NULL?"":value);
+ break;
+ default:
+ definedlist.add("__GLOBAL__");
+ }
+}
+
diff --git a/Source/build.h b/Source/build.h
index 564b9ba..82595a6 100755
--- a/Source/build.h
+++ b/Source/build.h
@@ -1,3 +1,19 @@
+/*
+ * build.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef _BUILD_H_
#define _BUILD_H_
@@ -9,6 +25,7 @@
#include "uservars.h"
#include "ShConstants.h"
#include "mmap.h"
+#include "manifest.h"
#include "exehead/fileform.h"
#include "exehead/config.h"
@@ -40,6 +57,15 @@
#define PS_ERROR 50
#define PS_WARNING 100
+// token placement
+#define TP_SEC 1
+#define TP_FUNC 2
+#define TP_CODE (TP_SEC | TP_FUNC)
+#define TP_GLOBAL 4
+#define TP_PAGEEX 8
+#define TP_PG (TP_GLOBAL | TP_PAGEEX)
+#define TP_ALL (TP_CODE | TP_PG)
+
enum notify_e {
MAKENSIS_NOTIFY_SCRIPT,
MAKENSIS_NOTIFY_WARNING,
@@ -114,7 +140,9 @@ class CEXEBuild {
void update_exehead(const unsigned char *new_exehead, size_t new_size);
// tokens.cpp
+ bool is_valid_token(char *s);
int get_commandtoken(char *s, int *np, int *op, int *pos);
+ int GetCurrentTokenPlace();
int IsTokenPlacedRight(int pos, char *tok);
// script.cpp
@@ -178,6 +206,7 @@ class CEXEBuild {
#endif //NSIS_CONFIG_PLUGIN_SUPPORT
// build.cpp functions used mostly by script.cpp
+ void set_code_type_predefines(const char *value = NULL);
int getcurdbsize();
int add_section(const char *secname, const char *defname, int expand=0);
int section_end();
@@ -215,7 +244,10 @@ class CEXEBuild {
int AddVersionInfo();
int ProcessPages();
void PrepareInstTypes();
+ void AddStandardStrings();
void PrepareHeaders(IGrowBuf *hdrbuf);
+ int SetVarsSection();
+ int SetManifest();
int resolve_jump_int(const char *fn, int *a, int offs, int start, int end);
int resolve_call_int(const char *fn, const char *str, int fptr, int *ofs);
@@ -228,7 +260,8 @@ class CEXEBuild {
// lang.cpp functions and variables
void InitLangTables();
- LanguageTable *GetLangTable(LANGID &lang);
+ LanguageTable *GetLangTable(LANGID &lang, bool create = true);
+ char *GetLangNameAndCP(LANGID lang, unsigned int *codepage = NULL);
int DefineLangString(char *name, int process=-1);
int DefineInnerLangString(int id, int process=-1);
int SetLangString(char *name, LANGID lang, char *string);
@@ -374,6 +407,9 @@ class CEXEBuild {
int deflateToFile(FILE *fp, char *buf, int len); // len==0 to flush
#endif
+ manifest::comctl manifest_comctl;
+ manifest::exec_level manifest_exec_level;
+
CResourceEditor *res_editor;
void init_res_editor();
void close_res_editor();
diff --git a/Source/bzip2/Readme.txt b/Source/bzip2/Readme.txt
deleted file mode 100755
index 4f82a82..0000000
--- a/Source/bzip2/Readme.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-These files are bzip2 files, modified for NSIS. The files are under
-a BSD-like license.
-
-bzip2 is copyright (C) 1996-2002 Julian R Seward. All rights reserved. \ No newline at end of file
diff --git a/Source/bzip2/blocksort.c b/Source/bzip2/blocksort.c
index 26c8cd9..6c2fa34 100755
--- a/Source/bzip2/blocksort.c
+++ b/Source/bzip2/blocksort.c
@@ -1,6 +1,20 @@
+/*
+ * This file is a part of the bzip2 compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.bzip.org/
+ *
+ * This modification is not compatible with the original bzip2.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "bzlib.h"
-#if (defined(NSIS_COMPRESS_USE_BZIP2) && defined(NSIS_CONFIG_COMPRESSION_SUPPORT)) || !defined(EXEHEAD)
/*-------------------------------------------------------------*/
/*--- Block sorting machinery ---*/
/*--- blocksort.c ---*/
@@ -1093,5 +1107,3 @@ void BZ2_blockSort ( EState* s )
/*-------------------------------------------------------------*/
/*--- end blocksort.c ---*/
/*-------------------------------------------------------------*/
-
-#endif
diff --git a/Source/bzip2/bzlib.c b/Source/bzip2/bzlib.c
index ad98d42..4aec93a 100755
--- a/Source/bzip2/bzlib.c
+++ b/Source/bzip2/bzlib.c
@@ -1,6 +1,20 @@
+/*
+ * This file is a part of the bzip2 compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.bzip.org/
+ *
+ * This modification is not compatible with the original bzip2.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "bzlib.h"
-#if (defined(NSIS_COMPRESS_USE_BZIP2) && defined(NSIS_CONFIG_COMPRESSION_SUPPORT)) || !defined(EXEHEAD)
/*-------------------------------------------------------------*/
/*--- Library top-level functions. ---*/
/*--- bzlib.c ---*/
@@ -605,5 +619,3 @@ int NSISCALL BZ2_bzDecompress( DState *s )
#endif
-
-#endif
diff --git a/Source/bzip2/bzlib.h b/Source/bzip2/bzlib.h
index b60dcdb..2554364 100755
--- a/Source/bzip2/bzlib.h
+++ b/Source/bzip2/bzlib.h
@@ -1,13 +1,23 @@
+/*
+ * This file is a part of the bzip2 compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.bzip.org/
+ *
+ * This modification is not compatible with the original bzip2.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
/*-------------------------------------------------------------*/
/*--- Public header file for the library. ---*/
/*--- bzlib.h ---*/
/*-------------------------------------------------------------*/
-// (this has been hacked to pieces by dave laundon and justin frankel,
-// and others, to make it small for nsis. it is not compatible with
-// bzip2 any longer. yay. )
-
/*--
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
@@ -247,8 +257,6 @@ extern void BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
#else//EXEHEAD
-#include "../exehead/util.h"
-
/*-- states for decompression. --*/
#define BZ_X_IDLE 1
diff --git a/Source/bzip2/compress.c b/Source/bzip2/compress.c
index 7ac8bc8..67485f4 100755
--- a/Source/bzip2/compress.c
+++ b/Source/bzip2/compress.c
@@ -1,3 +1,18 @@
+/*
+ * This file is a part of the bzip2 compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.bzip.org/
+ *
+ * This modification is not compatible with the original bzip2.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
/*-------------------------------------------------------------*/
/*--- Compression machinery (not incl block sorting) ---*/
/*--- compress.c ---*/
diff --git a/Source/bzip2/decompress.c b/Source/bzip2/decompress.c
index b1b68db..675c186 100755
--- a/Source/bzip2/decompress.c
+++ b/Source/bzip2/decompress.c
@@ -1,6 +1,19 @@
-#include "bzlib.h"
+/*
+ * This file is a part of the bzip2 compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.bzip.org/
+ *
+ * This modification is not compatible with the original bzip2.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
-#if defined(NSIS_COMPRESS_USE_BZIP2) && defined(NSIS_CONFIG_COMPRESSION_SUPPORT)
+#include "bzlib.h"
/*-------------------------------------------------------------*/
/*--- Decompression machinery ---*/
@@ -519,4 +532,3 @@ Int32 NSISCALL BZ2_decompress ( DState* s )
/*-------------------------------------------------------------*/
/*--- end decompress.c ---*/
/*-------------------------------------------------------------*/
-#endif
diff --git a/Source/bzip2/huffman.c b/Source/bzip2/huffman.c
index eb1a703..d36ccb0 100755
--- a/Source/bzip2/huffman.c
+++ b/Source/bzip2/huffman.c
@@ -1,6 +1,20 @@
+/*
+ * This file is a part of the bzip2 compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.bzip.org/
+ *
+ * This modification is not compatible with the original bzip2.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "bzlib.h"
-#if (defined(NSIS_COMPRESS_USE_BZIP2) && defined(NSIS_CONFIG_COMPRESSION_SUPPORT)) || !defined(EXEHEAD)
/*-------------------------------------------------------------*/
/*--- Huffman coding low-level stuff ---*/
/*--- huffman.c ---*/
@@ -228,4 +242,3 @@ BZ2_hbCreateDecodeTables ( Int32 *limit,
/*-------------------------------------------------------------*/
/*--- end huffman.c ---*/
/*-------------------------------------------------------------*/
-#endif
diff --git a/Source/cbzip2.h b/Source/cbzip2.h
index 9f67ff9..840af93 100755
--- a/Source/cbzip2.h
+++ b/Source/cbzip2.h
@@ -1,3 +1,19 @@
+/*
+ * cbzip2.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef __CBZIP2_H__
#define __CBZIP2_H__
@@ -24,9 +40,13 @@ class CBzip2 : public ICompressor {
int Compress(bool finish) {
// act like zlib when it comes to stream ending
if (last_ret == BZ_STREAM_END && finish)
- return BZ_STREAM_END;
+ return C_FINISHED;
last_ret = BZ2_bzCompress(stream, finish?BZ_FINISH:0);
- return last_ret;
+
+ if (last_ret < 0)
+ return last_ret;
+
+ return C_OK;
}
void SetNextIn(char *in, unsigned int size) {
diff --git a/Source/clzma.cpp b/Source/clzma.cpp
index 9d2c690..366b179 100755
--- a/Source/clzma.cpp
+++ b/Source/clzma.cpp
@@ -1,3 +1,19 @@
+/*
+ * clzma.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include <algorithm> // for std::min
#include "clzma.h"
@@ -247,7 +263,7 @@ int CLZMA::CompressReal()
break;
if (finished)
{
- res = C_OK;
+ res = C_FINISHED;
break;
}
}
diff --git a/Source/clzma.h b/Source/clzma.h
index bc33e6d..677cf78 100755
--- a/Source/clzma.h
+++ b/Source/clzma.h
@@ -1,3 +1,19 @@
+/*
+ * clzma.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef __CLZMA_H__
#define __CLZMA_H__
diff --git a/Source/compressor.h b/Source/compressor.h
index 099de4b..aae7569 100755
--- a/Source/compressor.h
+++ b/Source/compressor.h
@@ -1,7 +1,25 @@
+/*
+ * compressor.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef __COMPRESSOR_H__
#define __COMPRESSOR_H__
#define C_OK 0
+#define C_FINISHED 1
+
#define C_FINISH true
class ICompressor {
diff --git a/Source/crc32.c b/Source/crc32.c
index 0589adf..eb3a988 100755
--- a/Source/crc32.c
+++ b/Source/crc32.c
@@ -1,3 +1,19 @@
+/*
+ * crc32.c
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#include "crc32.h"
#include "exehead/config.h"
diff --git a/Source/crc32.h b/Source/crc32.h
index c55ed37..8245b6f 100755
--- a/Source/crc32.h
+++ b/Source/crc32.h
@@ -1,3 +1,19 @@
+/*
+ * crc32.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#ifndef ___CRC32__H___
diff --git a/Source/czlib.h b/Source/czlib.h
index c45051c..7d1b3e9 100755
--- a/Source/czlib.h
+++ b/Source/czlib.h
@@ -1,3 +1,19 @@
+/*
+ * czlib.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef __CZLIB_H__
#define __CZLIB_H__
diff --git a/Source/dirreader.cpp b/Source/dirreader.cpp
index a81b0d1..f6b9052 100755
--- a/Source/dirreader.cpp
+++ b/Source/dirreader.cpp
@@ -1,3 +1,19 @@
+/*
+ * dirreader.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#include "dirreader.h"
#include <string>
diff --git a/Source/dirreader.h b/Source/dirreader.h
index 2175dd8..c0bcbb4 100755
--- a/Source/dirreader.h
+++ b/Source/dirreader.h
@@ -1,3 +1,19 @@
+/*
+ * dirreader.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#include <string>
#include <set>
diff --git a/Source/exehead/Main.c b/Source/exehead/Main.c
index fa61105..3630a18 100755
--- a/Source/exehead/Main.c
+++ b/Source/exehead/Main.c
@@ -1,35 +1,18 @@
-/*
-
- Nullsoft Scriptable Install System (NSIS)
- main.c - executable header main code
-
- Copyright (C) 1999-2006 Nullsoft, Inc.
-
- This license applies to everything in the NSIS package, except where otherwise noted.
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- This is the zlib/libpng license, which is approved by opensource.org.
-
- Portions Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler (zlib).
- Portions Copyright (C) 1996-2002 Julian R Seward (bzip2).
- Portions Copyright (C) 1999-2003 Igor Pavlov (lzma).
-
-*/
+/*
+ * main.c: executable header main code
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "../Platform.h"
#include <shlobj.h>
@@ -65,8 +48,8 @@ char *ValidateTempDir()
return NULL;
addtrailingslash(state_temp_dir);
CreateDirectory(state_temp_dir, NULL);
- // state_command_line is used as a temp var here
- return my_GetTempFileName(state_command_line, state_temp_dir);
+ // state_language is used as a temp var here
+ return my_GetTempFileName(state_language, state_temp_dir);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow)
@@ -112,18 +95,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
mystrcpy(g_caption,_LANG_GENERIC_ERROR);
- GetTempPath(NSIS_MAX_STRLEN, state_temp_dir);
- if (!ValidateTempDir())
- {
- GetWindowsDirectory(state_temp_dir, NSIS_MAX_STRLEN - 5); // leave space for \Temp
- mystrcat(state_temp_dir, "\\Temp");
- if (!ValidateTempDir())
- {
- goto end;
- }
- }
- DeleteFile(state_command_line);
-
mystrcpy(state_command_line, GetCommandLine());
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT
@@ -169,7 +140,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
if (*(LPDWORD)(cmdline-2) == CHAR4_TO_DWORD(' ', '/', 'D','='))
{
- cmdline[-2]=0; // keep this from being passed to uninstaller if necessary
+ *(LPDWORD)(cmdline-2)=0; // keep this from being passed to uninstaller if necessary
mystrcpy(state_install_directory,cmdline+2);
break; // /D= must always be last
}
@@ -182,6 +153,18 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
cmdline++;
}
+ GetTempPath(NSIS_MAX_STRLEN, state_temp_dir);
+ if (!ValidateTempDir())
+ {
+ GetWindowsDirectory(state_temp_dir, NSIS_MAX_STRLEN - 5); // leave space for \Temp
+ mystrcat(state_temp_dir, "\\Temp");
+ if (!ValidateTempDir())
+ {
+ goto end;
+ }
+ }
+ DeleteFile(state_language);
+
m_Err = loadHeaders(cl_flags);
if (m_Err) goto end;
@@ -214,44 +197,42 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
else
{
int x;
+ char s[] = "Au_.exe";
- mystrcat(state_temp_dir,"~nsu.tmp\\");
+ mystrcat(state_temp_dir,"~nsu.tmp");
CreateDirectory(state_temp_dir,NULL);
+ if (!state_install_directory[0])
+ mystrcpy(state_install_directory,state_exe_directory);
+
+ mystrcpy(g_usrvars[0], realcmds);
+ mystrcpy(g_usrvars[1], s);
+
for (x = 0; x < 26; x ++)
{
- static char s[]="Au_.exe";
- static char buf2[NSIS_MAX_STRLEN*2];
+ static char buf2[NSIS_MAX_STRLEN];
static char ibuf[NSIS_MAX_STRLEN];
- *(LPWORD)buf2=CHAR2_TO_WORD('\"',0);
- mystrcat(buf2,state_temp_dir);
- mystrcat(buf2,s);
+ GetNSISString(buf2,g_header->str_uninstchild); // $TEMP\$1
- DeleteFile(buf2+1); // clean up after all the other ones if they are there
+ DeleteFile(buf2); // clean up after all the other ones if they are there
if (m_Err) // not done yet
{
// get current name
- int l=GetModuleFileName(g_hInstance,ibuf,sizeof(ibuf));
- // check if it is ?Au_.exe - if so, fuck it
+ int l=GetModuleFileName(NULL,ibuf,sizeof(ibuf));
+ // check if it is ?u_.exe - if so, fuck it
if (!lstrcmpi(ibuf+l-(sizeof(s)-2),s+1)) break;
// copy file
- if (CopyFile(ibuf,buf2+1,FALSE))
+ if (CopyFile(ibuf,buf2,TRUE))
{
HANDLE hProc;
#ifdef NSIS_SUPPORT_MOVEONREBOOT
- MoveFileOnReboot(buf2+1,NULL);
+ MoveFileOnReboot(buf2,NULL);
+ MoveFileOnReboot(state_temp_dir,NULL);
#endif
- if (state_install_directory[0]) mystrcpy(ibuf,state_install_directory);
- else trimslashtoend(ibuf);
- mystrcat(buf2,"\" ");
- mystrcat(buf2,realcmds);
- mystrcat(buf2," _?=");
- mystrcat(buf2,ibuf);
- // add a trailing backslash to make sure is_valid_instpath will not fail when it shouldn't
- addtrailingslash(buf2);
+ GetNSISString(buf2,g_header->str_uninstcmd); // '"$TEMP\$1" $0 _?=$INSTDIR\'
hProc=myCreateProcess(buf2,state_temp_dir);
if (hProc)
{
@@ -261,7 +242,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
}
}
}
- s[0]++;
+ g_usrvars[1][0]++;
}
goto end;
}
diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c
index 4fdde15..9ead396 100755
--- a/Source/exehead/Ui.c
+++ b/Source/exehead/Ui.c
@@ -1,24 +1,18 @@
/*
-* Copyright (C) 1999-2006 Nullsoft, Inc.
-* Portions Copyright (C) 2002 Jeff Doozan
-*
-* This software is provided 'as-is', without any express or implied warranty.
-* In no event will the authors be held liable for any damages arising from the
-* use of this software.
-*
-* Permission is granted to anyone to use this software for any purpose, including
-* commercial applications, and to alter it and redistribute it freely, subject to
-* the following restrictions:
-*
-* 1. The origin of this software must not be misrepresented; you must not claim that
-* you wrote the original software. If you use this software in a product, an
-* acknowledgment in the product documentation would be appreciated but is not required.
-*
-* 2. Altered source versions must be plainly marked as such, and must not be
-* misrepresented as being the original software.
-*
-* 3. This notice may not be removed or altered from any source distribution.
-*/
+ * Ui.c
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft, Jeff Doozan and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include <windowsx.h>
#include <shlobj.h>
@@ -248,12 +242,14 @@ FORCE_INLINE int NSISCALL ui_doinstall(void)
}
else
{
+ static const char reg_9x_locale[] = "Control Panel\\Desktop\\ResourceLocale";
+ static const char reg_nt_locale_key[] = ".DEFAULT\\Control Panel\\International";
+ const char *reg_nt_locale_val = &reg_9x_locale[30]; // = "Locale" with opt
+
*(DWORD*)state_language = CHAR4_TO_DWORD('0', 'x', 0, 0);
{
// Windows 9x
- static const char reg_9x_locale[] = "Control Panel\\Desktop\\ResourceLocale";
-
myRegGetStr(HKEY_CURRENT_USER, reg_9x_locale, NULL, g_tmp);
}
@@ -261,9 +257,6 @@ FORCE_INLINE int NSISCALL ui_doinstall(void)
{
// Windows NT
// This key exists on 9x as well, so it's only read if ResourceLocale wasn't found
- static const char reg_nt_locale_key[] = ".DEFAULT\\Control Panel\\International";
- static const char reg_nt_locale_val[] = "Locale";
-
myRegGetStr(HKEY_USERS, reg_nt_locale_key, reg_nt_locale_val, g_tmp);
}
@@ -654,7 +647,7 @@ skipPage:
if (uMsg == WM_COMMAND)
{
int id = LOWORD(wParam);
- HWND hCtl = GetDlgItem(hwndDlg, id);
+ HWND hCtl = GetDlgItem(hwndDlg, id); // lParam might be NULL
if (hCtl)
{
SendMessage(hCtl, BM_SETSTATE, FALSE, 0);
@@ -958,11 +951,12 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
if (idlist)
{
// free idlist
- FreePIDL(idlist);
+ CoTaskMemFree(idlist);
addtrailingslash(dir);
- if (g_header->install_directory_auto_append)
+ if (g_header->install_directory_auto_append &&
+ dir == state_install_directory) // only append to $INSTDIR (bug #1174184)
{
const char *post_str = ps_tmpbuf;
GetNSISStringTT(g_header->install_directory_auto_append);
@@ -1159,17 +1153,14 @@ int NSISCALL TreeGetSelectedSection(HWND tree, BOOL mouse)
}
static LONG oldTreeWndProc;
+static LPARAM last_selected_tree_item;
static DWORD WINAPI newTreeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- static LPARAM last_item=-1;
if (uMsg == WM_CHAR && wParam == VK_SPACE) {
NotifyCurWnd(WM_TREEVIEW_KEYHACK);
return 0;
}
#if defined(NSIS_SUPPORT_CODECALLBACKS) && defined(NSIS_CONFIG_ENHANCEDUI_SUPPORT)
- if (uMsg == WM_DESTROY) {
- last_item=-1;
- }
#ifndef NSIS_CONFIG_COMPONENTPAGE_ALTERNATIVE
if (uMsg == WM_MOUSEMOVE) {
if (IsWindowVisible(hwnd)) {
@@ -1179,9 +1170,9 @@ static DWORD WINAPI newTreeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
}
#endif
if (uMsg == WM_NOTIFY_SELCHANGE) {
- if (last_item != lParam)
+ if (last_selected_tree_item != lParam)
{
- last_item = lParam;
+ last_selected_tree_item = lParam;
mystrcpy(g_tmp, g_usrvars[0]);
@@ -1218,6 +1209,7 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
hBMcheck1=LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_BITMAP1));
+ last_selected_tree_item=-1;
oldTreeWndProc=SetWindowLong(hwndTree1,GWL_WNDPROC,(long)newTreeWndProc);
hImageList = ImageList_Create(16,16, ILC_COLOR32|ILC_MASK, 6, 0);
@@ -1654,7 +1646,7 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
TPM_NONOTIFY|TPM_RETURNCMD,
pt.x,
pt.y,
- 0,linsthwnd,0))
+ 0,hwndDlg,0))
{
int i,total = 1; // 1 for the null char
LVITEM item;
@@ -1680,8 +1672,7 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
i = 0;
do {
item.pszText = ptr;
- SendMessage(linsthwnd,LVM_GETITEMTEXT,i,(LPARAM)&item);
- ptr += mystrlen(ptr);
+ ptr += SendMessage(linsthwnd,LVM_GETITEMTEXT,i,(LPARAM)&item);
*(WORD*)ptr = CHAR2_TO_WORD('\r','\n');
ptr+=2;
} while (++i < count);
diff --git a/Source/exehead/afxres.h b/Source/exehead/afxres.h
index 766cfa2..7a74b25 100755
--- a/Source/exehead/afxres.h
+++ b/Source/exehead/afxres.h
@@ -1,3 +1,19 @@
+/*
+ * afxres.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "../Platform.h"
#ifndef IDC_STATIC
diff --git a/Source/exehead/bgbg.c b/Source/exehead/bgbg.c
index c8c593d..9851f2b 100755
--- a/Source/exehead/bgbg.c
+++ b/Source/exehead/bgbg.c
@@ -1,3 +1,19 @@
+/*
+ * bgbg.c
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "../Platform.h"
#include "resource.h"
#include "config.h"
diff --git a/Source/exehead/components.c b/Source/exehead/components.c
index 068b309..8b494c4 100755
--- a/Source/exehead/components.c
+++ b/Source/exehead/components.c
@@ -1,3 +1,19 @@
+/*
+ * components.c
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "../Platform.h"
#include "config.h"
#include "ui.h"
diff --git a/Source/exehead/components.h b/Source/exehead/components.h
index d1773b0..35b78c6 100755
--- a/Source/exehead/components.h
+++ b/Source/exehead/components.h
@@ -1,3 +1,19 @@
+/*
+ * components.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef ___COMPONENTS_H___
#define ___COMPONENTS_H___
diff --git a/Source/exehead/config.h b/Source/exehead/config.h
index afb2967..03a2afd 100755
--- a/Source/exehead/config.h
+++ b/Source/exehead/config.h
@@ -1,3 +1,19 @@
+/*
+ * config.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef NSIS_CONFIG_H
#define NSIS_CONFIG_H
diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c
index 503c618..00e7aa3 100755
--- a/Source/exehead/exec.c
+++ b/Source/exehead/exec.c
@@ -1,3 +1,19 @@
+/*
+ * exec.c
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "../Platform.h"
#include <shlobj.h>
#include <shellapi.h>
@@ -285,7 +301,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
{
char *p = skip_root(buf1);
char c = 'c';
- if (*buf1 && p)
+ if (p)
{
while (c)
{
@@ -439,8 +455,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
// remove read only flag if overwrite mode is on
if (!overwriteflag)
{
- int attr=GetFileAttributes(buf0);
- SetFileAttributes(buf0,attr&(~FILE_ATTRIBUTE_READONLY));
+ remove_ro_attr(buf0);
}
hOut=myOpenFile(buf0,GENERIC_WRITE,(overwriteflag==1)?CREATE_NEW:CREATE_ALWAYS);
if (hOut == INVALID_HANDLE_VALUE)
@@ -603,21 +618,11 @@ static int NSISCALL ExecuteEntry(entry *entry_)
{
char *p=var0;
char *buf0=GetStringFromParm(0x01);
- if (parm2)
+ if (!ExpandEnvironmentStrings(buf0,p,NSIS_MAX_STRLEN)
+ || (parm2 && !lstrcmp(buf0, p)))
{
- if (!GetEnvironmentVariable(buf0,p,NSIS_MAX_STRLEN))
- {
- exec_error++;
- *p=0;
- }
- }
- else
- {
- if (!ExpandEnvironmentStrings(buf0,p,NSIS_MAX_STRLEN))
- {
- exec_error++;
- *p=0;
- }
+ exec_error++;
+ *p=0;
}
p[NSIS_MAX_STRLEN-1]=0;
}
@@ -941,7 +946,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
if (parm4)
h=GetModuleHandle(buf1);
if (!h)
- h=LoadLibrary(buf1);
+ h=LoadLibraryEx(buf1, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (h)
{
FARPROC funke = GetProcAddress(h,buf0);
@@ -1205,11 +1210,19 @@ static int NSISCALL ExecuteEntry(entry *entry_)
LogData2Hex(binbuf, sizeof(binbuf), data, size);
log_printf5("WriteRegBin: \"%s\\%s\" \"%s\"=\"%s\"",rkn,buf1,buf0,binbuf);
}
+
if (size >= 0 && RegSetValueEx(hKey,buf0,0,rtype,data,size) == ERROR_SUCCESS)
+ {
exec_error--;
+ }
+ else
+ {
+ log_printf4("WriteReg: error writing into \"%s\\%s\" \"%s\"",rkn,buf1,buf0);
+ }
+
RegCloseKey(hKey);
}
- else { log_printf3("WriteReg: error creating key \"%s\\%s\"",buf3,buf1); }
+ else { log_printf3("WriteReg: error creating key \"%s\\%s\"",rkn,buf1); }
}
break;
case EW_READREGSTR: // read registry string
@@ -1429,6 +1442,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
}
validate_filename(buf1);
+ remove_ro_attr(buf1);
hFile=myOpenFile(buf1,GENERIC_WRITE,CREATE_ALWAYS);
if (hFile != INVALID_HANDLE_VALUE)
{
diff --git a/Source/exehead/exec.h b/Source/exehead/exec.h
index b6f2d10..dd9368b 100755
--- a/Source/exehead/exec.h
+++ b/Source/exehead/exec.h
@@ -1,3 +1,19 @@
+/*
+ * exec.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef _EXEC_H_
#define _EXEC_H_
diff --git a/Source/exehead/fileform.c b/Source/exehead/fileform.c
index 7967ab5..b0a03d0 100755
--- a/Source/exehead/fileform.c
+++ b/Source/exehead/fileform.c
@@ -1,3 +1,19 @@
+/*
+ * fileform.c
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "../Platform.h"
#include "fileform.h"
#include "util.h"
@@ -114,7 +130,7 @@ const char * NSISCALL loadHeaders(int cl_flags)
HANDLE db_hFile;
- GetModuleFileName(g_hInstance, state_exe_directory, NSIS_MAX_STRLEN);
+ GetModuleFileName(NULL, state_exe_directory, NSIS_MAX_STRLEN);
g_db_hFile = db_hFile = myOpenFile(state_exe_directory, GENERIC_READ, OPEN_EXISTING);
if (db_hFile == INVALID_HANDLE_VALUE)
@@ -150,15 +166,19 @@ const char * NSISCALL loadHeaders(int cl_flags)
h.nsinst[0] == FH_INT1
)
{
- if (h.length_of_all_following_data > left)
- return _LANG_INVALIDCRC;
-
g_filehdrsize = m_pos;
-#if defined(NSIS_CONFIG_CRC_SUPPORT) || (defined(NSIS_CONFIG_SILENT_SUPPORT) && defined(NSIS_CONFIG_VISIBLE_SUPPORT))
+#if defined(NSIS_CONFIG_CRC_SUPPORT) || defined(NSIS_CONFIG_SILENT_SUPPORT)
cl_flags |= h.flags;
#endif
+#ifdef NSIS_CONFIG_SILENT_SUPPORT
+ g_exec_flags.silent |= cl_flags & FH_FLAGS_SILENT;
+#endif
+
+ if (h.length_of_all_following_data > left)
+ return _LANG_INVALIDCRC;
+
#ifdef NSIS_CONFIG_CRC_SUPPORT
if ((cl_flags & FH_FLAGS_FORCE_CRC) == 0)
{
@@ -260,19 +280,11 @@ const char * NSISCALL loadHeaders(int cl_flags)
if (GetCompressedDataFromDataBlockToMemory(-1, data, h.length_of_header) != h.length_of_header)
{
- GlobalFree((HGLOBAL)data);
return _LANG_INVALIDCRC;
}
header = g_header = data;
-#ifdef NSIS_CONFIG_SILENT_SUPPORT
- if (cl_flags & FH_FLAGS_SILENT)
- header->flags |= CH_FLAGS_SILENT;
-
- g_exec_flags.silent = header->flags & (CH_FLAGS_SILENT | CH_FLAGS_SILENT_LOG);
-#endif
-
g_flags = header->flags;
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h
index 0025303..6b82285 100755
--- a/Source/exehead/fileform.h
+++ b/Source/exehead/fileform.h
@@ -1,3 +1,19 @@
+/*
+ * fileform.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "config.h"
#include "../Platform.h"
@@ -313,6 +329,14 @@ typedef struct
int install_directory_ptr; // default install dir.
int install_directory_auto_append; // auto append part
+
+#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
+ int str_uninstchild;
+ int str_uninstcmd;
+#endif//NSIS_CONFIG_UNINSTALL_SUPPORT
+#ifdef NSIS_SUPPORT_MOVEONREBOOT
+ int str_wininit;
+#endif//NSIS_SUPPORT_MOVEONREBOOT
} header;
#ifdef NSIS_SUPPORT_CODECALLBACKS
diff --git a/Source/exehead/lang.h b/Source/exehead/lang.h
index 44b7839..db5b26b 100755
--- a/Source/exehead/lang.h
+++ b/Source/exehead/lang.h
@@ -1,3 +1,19 @@
+/*
+ * lang.c
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef _NSIS_LANG_H_
#define _NSIS_LANG_H_
diff --git a/Source/exehead/state.h b/Source/exehead/state.h
index db295b1..27657c1 100755
--- a/Source/exehead/state.h
+++ b/Source/exehead/state.h
@@ -1,3 +1,19 @@
+/*
+ * fileform.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "fileform.h"
extern NSIS_STRING g_usrvars[1];
diff --git a/Source/exehead/ui.h b/Source/exehead/ui.h
index 656959b..d863ee1 100755
--- a/Source/exehead/ui.h
+++ b/Source/exehead/ui.h
@@ -1,3 +1,20 @@
+/*
+ * ui.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+
#ifndef _UI_H_
#define _UI_H_
diff --git a/Source/exehead/util.c b/Source/exehead/util.c
index 45c1281..212746c 100755
--- a/Source/exehead/util.c
+++ b/Source/exehead/util.c
@@ -1,3 +1,19 @@
+/*
+ * util.c
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "../Platform.h"
#include <shellapi.h>
#include "util.h"
@@ -33,17 +49,6 @@ NSIS_STRING g_usrvars[1] __attribute__((section (NSIS_VARS_SECTION)));
# endif
#endif
-void NSISCALL FreePIDL(LPITEMIDLIST idl)
-{
- IMalloc *m;
- SHGetMalloc(&m);
- if (m)
- {
- m->lpVtbl->Free(m, idl);
- m->lpVtbl->Release(m);
- }
-}
-
HANDLE NSISCALL myCreateProcess(char *cmd, char *dir)
{
DWORD d;
@@ -149,7 +154,7 @@ void NSISCALL myDelete(char *buf, int flags)
else
{
log_printf2("Delete: DeleteFile(\"%s\")",buf);
- SetFileAttributes(buf,fd.dwFileAttributes&(~FILE_ATTRIBUTE_READONLY));
+ remove_ro_attr(buf);
if (!DeleteFile(buf))
{
#ifdef NSIS_SUPPORT_MOVEONREBOOT
@@ -192,7 +197,7 @@ void NSISCALL myDelete(char *buf, int flags)
{
addtrailingslash(buf);
log_printf2("RMDir: RemoveDirectory(\"%s\")",buf);
- SetFileAttributes(buf,FILE_ATTRIBUTE_NORMAL);
+ remove_ro_attr(buf);
if (!RemoveDirectory(buf))
{
#ifdef NSIS_SUPPORT_MOVEONREBOOT
@@ -354,6 +359,13 @@ void NSISCALL mini_memcpy(void *out, const void *in, int len)
}
}
+void NSISCALL remove_ro_attr(char *file)
+{
+ int attr = GetFileAttributes(file);
+ if (attr != INVALID_FILE_ATTRIBUTES)
+ SetFileAttributes(file,attr&(~FILE_ATTRIBUTE_READONLY));
+}
+
HANDLE NSISCALL myOpenFile(const char *fn, DWORD da, DWORD cd)
{
int attr = GetFileAttributes(fn);
@@ -425,11 +437,8 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
return;
cchRenameLine = wsprintf(szRenameLine,"%s=%s\r\n",tmpbuf,wininit);
- GetWindowsDirectory(wininit, 1024-16);
- mystrcat(wininit, "\\wininit.ini");
- hfile = CreateFile(wininit,
- GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
+ GetNSISString(wininit, g_header->str_wininit);
+ hfile = myOpenFile(wininit, GENERIC_READ | GENERIC_WRITE, OPEN_ALWAYS);
if (hfile != INVALID_HANDLE_VALUE)
{
@@ -593,45 +602,13 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab)
if (nVarIdx == NS_SHELL_CODE)
{
- // NOTE 1: the code CSIDL_PRINTERS, is used for QUICKLAUNCH
- // NOTE 2: the code CSIDL_BITBUCKET is used for COMMONFILES
- // NOTE 3: the code CSIDL_CONTROLS is used for PROGRAMFILES
LPITEMIDLIST idl;
- char *append = 0;
-
- int x = 0;
- *out = 0;
+ int x = 2;
- if (fldrs[2] == CSIDL_PRINTERS) // QUICKLAUNCH
- {
- append = "\\Microsoft\\Internet Explorer\\Quick Launch";
- x = 2;
- }
- else if (fldrs[0] == CSIDL_PROGRAM_FILES_COMMON)
- {
- myRegGetStr(HKEY_LOCAL_MACHINE, SYSREGKEY, "CommonFilesDir", out);
- }
- else if (fldrs[0] == CSIDL_PROGRAM_FILES)
- {
- myRegGetStr(HKEY_LOCAL_MACHINE, SYSREGKEY, "ProgramFilesDir", out);
- if (!*out)
- mystrcpy(out, "C:\\Program Files");
- }
- else if (fldrs[0] == CSIDL_SYSTEM)
- {
- GetSystemDirectory(out, NSIS_MAX_STRLEN);
- }
- else if (fldrs[0] == CSIDL_WINDOWS)
- {
- GetWindowsDirectory(out, NSIS_MAX_STRLEN);
- }
-
- if (!*out)
+ if (g_exec_flags.all_user_var)
{
x = 4;
- if (!g_exec_flags.all_user_var)
- x = 2;
}
while (x--)
@@ -639,19 +616,46 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab)
if (!SHGetSpecialFolderLocation(g_hwnd, fldrs[x], &idl))
{
BOOL res = SHGetPathFromIDList(idl, out);
- FreePIDL(idl);
+ CoTaskMemFree(idl);
if (res)
{
break;
}
}
- else
- *out=0;
+ *out=0;
+ }
+
+ // resort to old registry methods, only when CSIDL failed
+ if (!*out)
+ {
+ if (fldrs[0] == CSIDL_PROGRAM_FILES_COMMON)
+ {
+ myRegGetStr(HKEY_LOCAL_MACHINE, SYSREGKEY, "CommonFilesDir", out);
+ }
+ else if (fldrs[0] == CSIDL_PROGRAM_FILES)
+ {
+ myRegGetStr(HKEY_LOCAL_MACHINE, SYSREGKEY, "ProgramFilesDir", out);
+ if (!*out)
+ mystrcpy(out, "C:\\Program Files");
+ }
+ else if (fldrs[0] == CSIDL_SYSTEM)
+ {
+ GetSystemDirectory(out, NSIS_MAX_STRLEN);
+ }
+ else if (fldrs[0] == CSIDL_WINDOWS)
+ {
+ GetWindowsDirectory(out, NSIS_MAX_STRLEN);
+ }
}
- if (*out && append)
+ if (*out)
{
- mystrcat(out, append);
+ // all users' version is CSIDL_APPDATA only for $QUICKLAUNCH
+ // for normal $APPDATA, it'd be CSIDL_APPDATA_COMMON
+ if (fldrs[2] == CSIDL_APPDATA)
+ {
+ mystrcat(out, "\\Microsoft\\Internet Explorer\\Quick Launch");
+ }
}
validate_filename(out);
diff --git a/Source/exehead/util.h b/Source/exehead/util.h
index 14c5af9..640c1d7 100755
--- a/Source/exehead/util.h
+++ b/Source/exehead/util.h
@@ -1,3 +1,19 @@
+/*
+ * util.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "../Platform.h"
#include "config.h"
#include <shlobj.h>
@@ -16,7 +32,6 @@ char * NSISCALL mystrcat(char *out, const char *concat);
char * NSISCALL mystrstr(char *a, char *b);
WIN32_FIND_DATA * NSISCALL file_exists(char *buf);
char * NSISCALL my_GetTempFileName(char *buf, const char *dir);
-void NSISCALL FreePIDL(LPITEMIDLIST idl);
//BOOL NSISCALL my_SetWindowText(HWND hWnd, const char *val);
#define my_SetWindowText SetWindowText
@@ -74,6 +89,7 @@ int NSISCALL is_valid_instpath(char *s);
void NSISCALL validate_filename(char *fn);
void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew);
void NSISCALL mini_memcpy(void *out, const void *in, int len);
+void NSISCALL remove_ro_attr(char *file);
void * NSISCALL myGetProcAddress(char *dll, char *func);
void NSISCALL MessageLoop(UINT uCheckedMsg);
diff --git a/Source/fileform.cpp b/Source/fileform.cpp
index ec9ceb7..c2bdb67 100755
--- a/Source/fileform.cpp
+++ b/Source/fileform.cpp
@@ -1,3 +1,19 @@
+/*
+ * fileform.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "fileform.h"
#include "exehead/config.h"
#include "Platform.h"
@@ -79,6 +95,14 @@ void header_writer::write(const header *data)
m_sink->write_int(data->install_directory_ptr);
m_sink->write_int(data->install_directory_auto_append);
+
+#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
+ m_sink->write_int(data->str_uninstchild);
+ m_sink->write_int(data->str_uninstcmd);
+#endif//NSIS_CONFIG_UNINSTALL_SUPPORT
+#ifdef NSIS_SUPPORT_MOVEONREBOOT
+ m_sink->write_int(data->str_wininit);
+#endif//NSIS_SUPPORT_MOVEONREBOOT
}
void section_writer::write(const section *data)
diff --git a/Source/fileform.h b/Source/fileform.h
index c52b88f..1244d18 100755
--- a/Source/fileform.h
+++ b/Source/fileform.h
@@ -1,3 +1,19 @@
+/*
+ * fileform.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef ___MAKENSIS_FILEFORM_H___
#define ___MAKENSIS_FILEFORM_H___
diff --git a/Source/growbuf.cpp b/Source/growbuf.cpp
index edfa28b..8a13b63 100755
--- a/Source/growbuf.cpp
+++ b/Source/growbuf.cpp
@@ -1,3 +1,19 @@
+/*
+ * growbuf.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "growbuf.h"
#include <cstdlib> // for malloc/free
diff --git a/Source/growbuf.h b/Source/growbuf.h
index 6c6c905..42edef1 100755
--- a/Source/growbuf.h
+++ b/Source/growbuf.h
@@ -1,3 +1,19 @@
+/*
+ * growbuf.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef __GROWBUF_H_
#define __GROWBUF_H_
diff --git a/Source/lang.cpp b/Source/lang.cpp
index f9b4615..dda8cfb 100755
--- a/Source/lang.cpp
+++ b/Source/lang.cpp
@@ -1,3 +1,19 @@
+/*
+ * lang.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#include <stdio.h>
#include <stdlib.h>
@@ -20,11 +36,13 @@ typedef enum {
BOTH_STATIC = 3
} STATICID;
-struct {
+struct NLFString {
char *szLangStringName;
char *szDefault;
STATICID eStaticID;
-} NLFStrings[NLF_STRINGS] = {
+};
+
+NLFString NLFStrings[NLF_STRINGS] = {
{"^Branding", "Nullsoft Install System %s", BOTH_STATIC},
{"^SetupCaption", "$(^Name) Setup", INSTALL_STATIC},
{"^UninstallCaption", "$(^Name) Uninstall", UNINSTALL_STATIC},
@@ -312,13 +330,12 @@ void CEXEBuild::InitLangTables() {
keep_ref = true;
}
-LanguageTable* CEXEBuild::GetLangTable(LANGID &lang) {
+LanguageTable* CEXEBuild::GetLangTable(LANGID &lang, bool create/*=true*/) {
int nlt = lang_tables.getlen() / sizeof(LanguageTable);
LanguageTable *nla = (LanguageTable*)lang_tables.get();
lang = lang ? lang : last_used_lang;
- last_used_lang = lang;
- LanguageTable *table = 0;
+ LanguageTable *table = NULL;
for (int i = 0; i < nlt; i++) {
if (lang == nla[i].lang_id) {
@@ -326,7 +343,7 @@ LanguageTable* CEXEBuild::GetLangTable(LANGID &lang) {
break;
}
}
- if (!table) {
+ if (!table && create) {
LanguageTable newtable;
newtable.lang_id = lang;
@@ -339,9 +356,32 @@ LanguageTable* CEXEBuild::GetLangTable(LANGID &lang) {
table = (LanguageTable*)lang_tables.get() + nlt;
}
+ if (table) // update last used language if a table was loaded
+ last_used_lang = lang;
+
return table;
}
+char *CEXEBuild::GetLangNameAndCP(LANGID lang, unsigned int *codepage/*=NULL*/) {
+ LanguageTable *table = GetLangTable(lang, false);
+
+ if (table && table->nlf.m_bLoaded) {
+ if (codepage)
+ *codepage = table->nlf.m_uCodePage;
+
+ return table->nlf.m_szName;
+ }
+ else {
+ if (codepage)
+ *codepage = 1252; // English US
+
+ if (lang == 1033)
+ return "English";
+ else
+ return "???";
+ }
+}
+
int CEXEBuild::DefineLangString(char *name, int process/*=-1*/) {
int index, uindex, pos, ret, sn;
pos = build_langstrings.get(name, &sn, &index, &uindex);
@@ -474,14 +514,14 @@ int CEXEBuild::GenerateLangTables() {
init_res_editor();
#define ADD_FONT(id) { \
- BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \
+ BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \
if (dlg) { \
CDialogTemplate td(dlg); \
res_editor->FreeResource(dlg); \
td.SetFont(build_font, build_font_size); \
DWORD dwSize; \
dlg = td.Save(dwSize); \
- res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \
+ res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \
delete [] dlg; \
} \
}
@@ -529,7 +569,7 @@ int CEXEBuild::GenerateLangTables() {
init_res_editor();
#define ADD_FONT(id) { \
- BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \
+ BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \
if (dlg) { \
CDialogTemplate td(dlg,lt[i].nlf.m_uCodePage); \
res_editor->FreeResource(dlg); \
@@ -544,7 +584,7 @@ int CEXEBuild::GenerateLangTables() {
} \
DWORD dwSize; \
dlg = td.Save(dwSize); \
- res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id+cur_offset), NSIS_DEFAULT_LANG, dlg, dwSize); \
+ res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(id+cur_offset), NSIS_DEFAULT_LANG, dlg, dwSize); \
delete [] dlg; \
} \
}
diff --git a/Source/lang.h b/Source/lang.h
index 6354c7e..94e751d 100755
--- a/Source/lang.h
+++ b/Source/lang.h
@@ -1,3 +1,19 @@
+/*
+ * lang.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef ___NLF___H_____
#define ___NLF___H_____
diff --git a/Source/lineparse.cpp b/Source/lineparse.cpp
index b7e32f7..2d42ae6 100755
--- a/Source/lineparse.cpp
+++ b/Source/lineparse.cpp
@@ -1,3 +1,19 @@
+/*
+ * lineparse.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "lineparse.h"
#include "Platform.h"
@@ -6,7 +22,8 @@
LineParser::LineParser(bool bCommentBlock)
{
- m_bCommentBlock=bCommentBlock;
+ m_incommentblock=bCommentBlock;
+ m_incomment=false;
m_nt=m_eat=0;
m_tokens=0;
}
@@ -16,20 +33,25 @@ LineParser::~LineParser()
freetokens();
}
-bool LineParser::InCommentBlock()
+bool LineParser::inComment()
+{
+ return m_incomment;
+}
+
+bool LineParser::inCommentBlock()
{
- return m_bCommentBlock;
+ return m_incommentblock;
}
int LineParser::parse(char *line, int ignore_escaping/*=0*/) // returns -1 on error
{
freetokens();
- bool bPrevCB=m_bCommentBlock;
+ bool bPrevCB=m_incommentblock;
int n=doline(line, ignore_escaping);
if (n) return n;
if (m_nt)
{
- m_bCommentBlock=bPrevCB;
+ m_incommentblock=bPrevCB;
m_tokens=(char**)malloc(sizeof(char*)*m_nt);
n=doline(line, ignore_escaping);
if (n)
@@ -124,16 +146,17 @@ void LineParser::freetokens()
int LineParser::doline(char *line, int ignore_escaping/*=0*/)
{
m_nt=0;
+ m_incomment = false;
while (*line == ' ' || *line == '\t') line++;
while (*line)
{
- if ( m_bCommentBlock )
+ if ( m_incommentblock )
{
while ( *line )
{
if ( *line == '*' && *(line+1) == '/' )
{
- m_bCommentBlock=false; // Found end of comment block
+ m_incommentblock=false; // Found end of comment block
line+=2;
while (*line == ' ' || *line == '\t') line++;
break;
@@ -143,10 +166,14 @@ int LineParser::doline(char *line, int ignore_escaping/*=0*/)
}
else {
int lstate=0; // 1=", 2=`, 4='
- if (*line == ';' || *line == '#') break;
+ if (*line == ';' || *line == '#')
+ {
+ m_incomment = true;
+ break;
+ }
if (*line == '/' && *(line+1) == '*')
{
- m_bCommentBlock = true;
+ m_incommentblock = true;
line+=2;
}
else {
diff --git a/Source/lineparse.h b/Source/lineparse.h
index e091621..2ab67f1 100755
--- a/Source/lineparse.h
+++ b/Source/lineparse.h
@@ -1,3 +1,19 @@
+/*
+ * lineparse.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef _LINEPARSE_H_
#define _LINEPARSE_H_
@@ -7,7 +23,8 @@ class LineParser {
LineParser(bool bCommentBlock);
virtual ~LineParser();
- bool InCommentBlock();
+ bool inComment();
+ bool inCommentBlock();
int parse(char *line, int ignore_escaping=0); // returns -1 on error
int getnumtokens();
void eattoken();
@@ -23,7 +40,8 @@ class LineParser {
int m_eat;
int m_nt;
- bool m_bCommentBlock;
+ bool m_incommentblock;
+ bool m_incomment;
char **m_tokens;
};
#endif//_LINEPARSE_H_
diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp
index 56113eb..d4e9811 100755
--- a/Source/makenssi.cpp
+++ b/Source/makenssi.cpp
@@ -1,35 +1,18 @@
-/*
-
- Nullsoft Scriptable Install System (NSIS)
- makensis.cpp - installer compiler code
-
- Copyright (C) 1999-2006 Nullsoft, Inc.
-
- This license applies to everything in the NSIS package, except where otherwise noted.
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- This is the zlib/libpng license, which is approved by opensource.org.
-
- Portions Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler (zlib).
- Portions Copyright (C) 1996-2002 Julian R Seward (bzip2).
- Portions Copyright (C) 1999-2003 Igor Pavlov (lzma).
-
-*/
+/*
+ * makenssi.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#include "Platform.h"
#include <stdio.h>
@@ -109,20 +92,17 @@ static void init_signals()
static void print_logo()
{
- fprintf(g_output,"MakeNSIS %s - Copyright 1999-2006 Nullsoft, Inc.\n"
- "\n"
- "Portions Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler (zlib).\n"
- "Portions Copyright (C) 1996-2002 Julian R Seward (bzip2).\n"
- "Portions Copyright (C) 1999-2003 Igor Pavlov (lzma).\n"
- "\n"
- "Contributors: nnop@newmail.ru, Ryan Geiss, Andras Varga, Drew Davidson, Peter Windridge, Dave Laundon, Robert Rainwater, Yaroslav Faybishenko, Jeff Doozan, Amir Szekely, Ximon Eighteen, et al.\n\n",NSIS_VERSION);
+ fprintf(g_output,"MakeNSIS %s - Copyright 1995-2007 Contributors\n"
+ "See the file COPYING for license details.\n"
+ "Credits can be found in the Users Manual.\n\n", NSIS_VERSION);
fflush(g_output);
}
static void print_license()
{
- fprintf(g_output,"Copyright (C) 1999-2006 Nullsoft, Inc.\n\n"
- "This license applies to everything in the NSIS package, except where otherwise\nnoted.\n\n"
+ fprintf(g_output,"Copyright (C) 1999-2007 Nullsoft and Contributors\n\n"
+ "This license applies to everything in the NSIS package, except where otherwise\n"
+ "noted.\n\n"
"This software is provided 'as-is', without any express or implied warranty.\n"
"In no event will the authors be held liable for any damages arising from the\n"
"use of this software.\n\n"
@@ -135,7 +115,9 @@ static void print_license()
" appreciated but is not required.\n"
" 2. Altered source versions must be plainly marked as such, and must not be\n"
" misrepresented as being the original software.\n"
- " 3. This notice may not be removed or altered from any source distribution.\n\n");
+ " 3. This notice may not be removed or altered from any source distribution.\n\n"
+ "In addition to this license, different licenses apply to the included\n"
+ "compression modules. See the file COPYING for details.\n");
fflush(g_output);
}
@@ -148,6 +130,8 @@ static void print_usage()
" " OPT_STR "HDRINFO prints information about what options makensis was compiled with\n"
" " OPT_STR "LICENSE prints the makensis software license\n"
" " OPT_STR "VERSION prints the makensis version and exits\n"
+ " " OPT_STR "Px sets the compiler process priority, where x is 5=realtime,4=high,\n"
+ " " " 3=above normal,2=normal,1=below normal,0=idle\n"
" " OPT_STR "Vx verbosity where x is 4=all,3=no script,2=no info,1=no warnings,0=none\n"
" " OPT_STR "Ofile specifies a text file to log compiler output (default is stdout)\n"
" " OPT_STR "PAUSE pauses after execution\n"
@@ -156,7 +140,11 @@ static void print_usage()
" " OPT_STR "Ddefine[=value] defines the symbol \"define\" for the script [to value]\n"
" " OPT_STR "Xscriptcmd executes scriptcmd in script (i.e. \"" OPT_STR "XOutFile poop.exe\")\n"
" parameters are processed by order (" OPT_STR "Ddef ins.nsi != ins.nsi " OPT_STR "Ddef)\n"
- " for script file name, you can use - to read from the standard input\n");
+ " for script file name, you can use - to read from the standard input\n"
+#ifdef _WIN32
+ " you can also use - as an option character: -PAUSE as well as /PAUSE\n"
+#endif
+ " you can use a double-dash to end options processing: makensis -- -ins.nsi\n");
fflush(g_output);
}
@@ -267,9 +255,7 @@ int main(int argc, char **argv)
FILE *fp;
int tmpargpos=1;
int no_logo=0;
-#ifndef _WIN32
int in_files=0;
-#endif
try
{
@@ -282,13 +268,13 @@ int main(int argc, char **argv)
return 1;
}
- if (argc > 1 && !stricmp(argv[1], OPT_STR "VERSION"))
+ if (argc > 1 && IS_OPT(argv[1]) && !stricmp(&argv[1][1],"VERSION"))
{
fprintf(g_output,NSIS_VERSION);
fflush(g_output);
return 0;
}
- if (argc > 1 && argv[1][0]==OPT_C && (argv[1][1]=='v' || argv[1][1]=='V'))
+ if (argc > 1 && IS_OPT(argv[1]) && (argv[1][1]=='v' || argv[1][1]=='V'))
{
tmpargpos++;
if (argv[1][2] <= '2' && argv[1][2] >= '0')
@@ -299,7 +285,7 @@ int main(int argc, char **argv)
if (!no_logo)
{
- if (argc > tmpargpos && argv[tmpargpos][0]==OPT_C && (argv[tmpargpos][1]=='o' || argv[tmpargpos][1]=='O') && argv[tmpargpos][2])
+ if (argc > tmpargpos && IS_OPT(argv[tmpargpos]) && (argv[tmpargpos][1]=='o' || argv[tmpargpos][1]=='O') && argv[tmpargpos][2])
{
g_output=fopen(argv[tmpargpos]+2,"w");
if (!g_output)
@@ -317,13 +303,9 @@ int main(int argc, char **argv)
if (!g_output) g_output=stdout;
while (argpos < argc)
{
-#ifndef _WIN32
if (!strcmp(argv[argpos], "--"))
in_files=1;
- else if (argv[argpos][0] == OPT_C && strcmp(argv[argpos], "-") && !in_files)
-#else
- if (argv[argpos][0] == OPT_C && strcmp(argv[argpos], "-"))
-#endif
+ else if (IS_OPT(argv[argpos]) && strcmp(argv[argpos], "-") && !in_files)
{
if ((argv[argpos][1]=='D' || argv[argpos][1]=='d') && argv[argpos][2])
{
@@ -405,16 +387,45 @@ int main(int argc, char **argv)
print_stub_info(build);
nousage++;
}
+ else if ((argv[argpos][1]=='P' || argv[argpos][1]=='p') &&
+ argv[argpos][2] >= '0' && argv[argpos][2] <= '5' && !argv[argpos][3])
+ {
+#ifdef _WIN32
+ // priority setting added 01-2007 by Comm@nder21
+ int p=argv[argpos][2]-'0';
+ HANDLE hProc = GetCurrentProcess();
+
+ struct
+ {
+ DWORD priority;
+ DWORD fallback;
+ } classes[] = {
+ {IDLE_PRIORITY_CLASS, IDLE_PRIORITY_CLASS},
+ {BELOW_NORMAL_PRIORITY_CLASS, IDLE_PRIORITY_CLASS},
+ {NORMAL_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS},
+ {ABOVE_NORMAL_PRIORITY_CLASS, HIGH_PRIORITY_CLASS},
+ {HIGH_PRIORITY_CLASS, HIGH_PRIORITY_CLASS},
+ {REALTIME_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS}
+ };
+
+ if (SetPriorityClass(hProc, classes[p].priority) == FALSE)
+ {
+ SetPriorityClass(hProc, classes[p].fallback);
+ }
+
+ if (p == 5)
+ build.warning("makensis is running in REALTIME priority mode!");
+
+#else
+ build.warning(OPT_STR "Px is disabled for non Win32 platforms.");
+#endif
+ }
else break;
}
else
{
files_processed++;
-#ifndef _WIN32
if (!strcmp(argv[argpos],"-") && !in_files)
-#else
- if (!strcmp(argv[argpos],"-"))
-#endif
g_dopause=0;
if (!g_noconfig)
{
@@ -449,11 +460,7 @@ int main(int argc, char **argv)
{
char sfile[1024];
-#ifndef _WIN32
if (!strcmp(argv[argpos],"-") && !in_files)
-#else
- if (!strcmp(argv[argpos],"-"))
-#endif
{
fp=stdin;
strcpy(sfile,"stdin");
diff --git a/Source/manifest.cpp b/Source/manifest.cpp
new file mode 100755
index 0000000..3d6d005
--- /dev/null
+++ b/Source/manifest.cpp
@@ -0,0 +1,67 @@
+/*
+ * manifest.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#include "Platform.h"
+#include "manifest.h"
+#include "version.h"
+
+namespace manifest
+{
+
+using namespace std;
+
+string generate(comctl comctl_selection, exec_level exec_level_selection)
+{
+ if (comctl_selection == comctl_old && exec_level_selection == exec_level_none)
+ return "";
+
+ string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"><assemblyIdentity version=\"1.0.0.0\" processorArchitecture=\"X86\" name=\"Nullsoft.NSIS.exehead\" type=\"win32\"/><description>Nullsoft Install System " NSIS_VERSION "</description>";
+
+ if (comctl_selection == comctl_xp)
+ {
+ xml += "<dependency><dependentAssembly><assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" version=\"6.0.0.0\" processorArchitecture=\"X86\" publicKeyToken=\"6595b64144ccf1df\" language=\"*\" /></dependentAssembly></dependency>";
+ }
+
+ if (exec_level_selection != exec_level_none)
+ {
+ string level = "";
+
+ switch (exec_level_selection)
+ {
+ case exec_level_none:
+ break;
+ case exec_level_user:
+ level = "asInvoker";
+ break;
+ case exec_level_highest:
+ level = "highestAvailable";
+ break;
+ case exec_level_admin:
+ level = "requireAdministrator";
+ break;
+ }
+
+ xml += "<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v3\"><security><requestedPrivileges><requestedExecutionLevel level=\"";
+ xml += level;
+ xml += "\" uiAccess=\"false\"/></requestedPrivileges></security></trustInfo>";
+ }
+
+ xml += "</assembly>";
+
+ return xml;
+}
+
+};
diff --git a/Source/manifest.h b/Source/manifest.h
new file mode 100755
index 0000000..7533ee8
--- /dev/null
+++ b/Source/manifest.h
@@ -0,0 +1,41 @@
+/*
+ * manifest.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#ifndef ___MANIFEST_H___
+#define ___MANIFEST_H___
+
+#include <string>
+
+namespace manifest
+{
+ enum comctl
+ {
+ comctl_old,
+ comctl_xp
+ };
+
+ enum exec_level
+ {
+ exec_level_none,
+ exec_level_user,
+ exec_level_highest,
+ exec_level_admin
+ };
+
+ std::string generate(comctl, exec_level);
+};
+
+#endif//!___MANIFEST_H___
diff --git a/Source/mmap.cpp b/Source/mmap.cpp
index fe674a0..aecdba2 100755
--- a/Source/mmap.cpp
+++ b/Source/mmap.cpp
@@ -1,3 +1,19 @@
+/*
+ * mmap.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "mmap.h"
#include <cstdio> // for f*
@@ -274,7 +290,7 @@ void *MMapFile::get(int offset, int *sizep) const
return (void *)((char *)m_pView + offset - alignedoffset);
}
-void *MMapFile::getmore(int offset, int *size) const
+void *MMapFile::getmore(int offset, int size) const
{
void *pView;
void *pViewBackup = m_pView;
@@ -308,6 +324,9 @@ void MMapFile::release(void *pView, int size)
if (!pView)
return;
+ unsigned int alignment = ((unsigned int)pView) % m_iAllocationGranularity;
+ pView = (char *)pView - alignment;
+ size += alignment;
#ifdef _WIN32
UnmapViewOfFile(pView);
#else
@@ -358,7 +377,7 @@ void *MMapFake::get(int offset, int *size) const
return (void *)(m_pMem + offset);
}
-void *MMapFake::getmore(int offset, int *size) const
+void *MMapFake::getmore(int offset, int size) const
{
return get(offset, size);
}
@@ -461,7 +480,7 @@ void *MMapBuf::get(int offset, int size) const
return (void *) ((char *) m_gb.get() + offset);
}
-void *MMapBuf::getmore(int offset, int *size) const
+void *MMapBuf::getmore(int offset, int size) const
{
if (m_gb_u)
return m_fm.getmore(offset, size);
diff --git a/Source/mmap.h b/Source/mmap.h
index b621515..80e6124 100755
--- a/Source/mmap.h
+++ b/Source/mmap.h
@@ -1,3 +1,19 @@
+/*
+ * mmap.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef __MMAP_H_
#define __MMAP_H_
@@ -15,7 +31,7 @@ class IMMap
virtual int getsize() const=0;
virtual void *get(int offset, int size) const=0;
virtual void *get(int offset, int *size) const=0;
- virtual void *getmore(int offset, int *size) const=0;
+ virtual void *getmore(int offset, int size) const=0;
virtual void release()=0;
virtual void release(void *view, int size)=0;
virtual void clear()=0;
@@ -45,7 +61,7 @@ class MMapFile : public IMMap
int getsize() const;
void *get(int offset, int size) const;
void *get(int offset, int *sizep) const;
- void *getmore(int offset, int *size) const;
+ void *getmore(int offset, int size) const;
void release();
void release(void *pView, int size);
void flush(int num);
@@ -78,7 +94,7 @@ class MMapFake : public IMMap
int getsize() const;
void *get(int offset, int size) const;
void *get(int offset, int *size) const;
- void *getmore(int offset, int *size) const;
+ void *getmore(int offset, int size) const;
void resize(int n);
void release();
@@ -110,7 +126,7 @@ class MMapBuf : public IGrowBuf, public IMMap
void *get() const;
void *get(int offset, int *sizep) const;
void *get(int offset, int size) const;
- void *getmore(int offset, int *size) const;
+ void *getmore(int offset, int size) const;
void release();
void release(void *pView, int size);
void clear();
diff --git a/Source/script.cpp b/Source/script.cpp
index d0315e3..75f9434 100755
--- a/Source/script.cpp
+++ b/Source/script.cpp
@@ -1,9 +1,26 @@
+/*
+ * script.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#include <stdio.h>
#include <ctype.h>
#include "tokens.h"
#include "build.h"
#include "util.h"
+#include "winchar.h"
#include "ResourceEditor.h"
#include "DialogTemplate.h"
#include "lang.h"
@@ -263,31 +280,41 @@ int CEXEBuild::doParse(const char *str)
while (*str == ' ' || *str == '\t') str++;
- if (m_linebuild.getlen()>1) m_linebuild.resize(m_linebuild.getlen()-2);
+ // remove trailing slash and null, if there's a previous line
+ if (m_linebuild.getlen()>1)
+ m_linebuild.resize(m_linebuild.getlen()-2);
m_linebuild.add(str,strlen(str)+1);
- // remove trailing slash and null
- if (str[0] && CharPrev(str,str+strlen(str))[0] == '\\') {
- last_line_had_slash = 1;
+ // keep waiting for more lines, if this line ends with a backslash
+ if (str[0] && CharPrev(str,str+strlen(str))[0] == '\\')
+ {
+ line.parse((char*)m_linebuild.get());
+ if (line.inComment())
+ {
+ warning_fl("comment contains line-continuation character, following line will be ignored");
+ }
return PS_OK;
}
- else last_line_had_slash = 0;
+ // parse before checking if the line should be ignored, so block comments won't be missed
res=line.parse((char*)m_linebuild.get(),!strnicmp((char*)m_linebuild.get(),"!define",7));
- inside_comment = line.InCommentBlock();
-
- m_linebuild.resize(0);
+ inside_comment = line.inCommentBlock();
// if ignoring, ignore all lines that don't begin with an exclamation mark
{
bool ignore_line = cur_ifblock && (cur_ifblock->ignore || cur_ifblock->inherited_ignore);
char first_char = *(char *) m_linebuild.get();
- if (ignore_line && first_char!='!' && !last_line_had_slash)
+ if (ignore_line && (first_char!='!' || !is_valid_token(line.gettoken_str(0))))
+ {
+ m_linebuild.resize(0);
return PS_OK;
+ }
}
+ m_linebuild.resize(0);
+
if (res)
{
if (res==-2) ERROR_MSG("Error: unterminated string parsing line at %s:%d\n",curfilename,linecnt);
@@ -2079,7 +2106,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
try {
init_res_editor();
- BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG);
+ BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG);
if (!dlg) throw runtime_error("IDD_INSTFILES doesn't exist!");
CDialogTemplate dt(dlg,uDefCodePage);
free(dlg);
@@ -2095,7 +2122,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DWORD dwSize;
dlg = dt.Save(dwSize);
- res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG, dlg, dwSize);
+ res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG, dlg, dwSize);
delete [] dlg;
}
catch (exception& err) {
@@ -2332,17 +2359,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
}
return PS_OK;
case TOK_XPSTYLE:
- try {
+ {
int k=line.gettoken_enum(1,"on\0off\0");
if (k == -1) PRINTHELP()
SCRIPT_MSG("XPStyle: %s\n", line.gettoken_str(1));
- init_res_editor();
- const char *szXPManifest = k ? 0 : "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"><assemblyIdentity version=\"1.0.0.0\" processorArchitecture=\"X86\" name=\"Nullsoft.NSIS.exehead\" type=\"win32\"/><description>Nullsoft Install System " NSIS_VERSION "</description><dependency><dependentAssembly><assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" version=\"6.0.0.0\" processorArchitecture=\"X86\" publicKeyToken=\"6595b64144ccf1df\" language=\"*\" /></dependentAssembly></dependency></assembly>";
- res_editor->UpdateResource(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), NSIS_DEFAULT_LANG, (unsigned char*)szXPManifest, k ? 0 : strlen(szXPManifest));
- }
- catch (exception& err) {
- ERROR_MSG("Error while adding XP style: %s\n", err.what());
- return PS_ERROR;
+ if (!k)
+ manifest_comctl = manifest::comctl_xp;
+ else
+ manifest_comctl = manifest::comctl_old;
}
return PS_OK;
case TOK_CHANGEUI:
@@ -2377,9 +2401,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
init_res_editor();
// Search for required items
- #define GET(x) dlg = uire->GetResource(RT_DIALOG, MAKEINTRESOURCE(x), 0); if (!dlg) return PS_ERROR; CDialogTemplate UIDlg(dlg, uDefCodePage);
+ #define GET(x) dlg = uire->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(x), 0); if (!dlg) return PS_ERROR; CDialogTemplate UIDlg(dlg, uDefCodePage);
#define SEARCH(x) if (!UIDlg.GetItem(x)) {ERROR_MSG("Error: Can't find %s (%u) in the custom UI!\n", #x, x);delete [] dlg;delete uire;return PS_ERROR;}
- #define SAVE(x) dwSize = UIDlg.GetSize(); res_editor->UpdateResource(RT_DIALOG, x, NSIS_DEFAULT_LANG, dlg, dwSize); delete [] dlg;
+ #define SAVE(x) dwSize = UIDlg.GetSize(); res_editor->UpdateResourceA(RT_DIALOG, x, NSIS_DEFAULT_LANG, dlg, dwSize); delete [] dlg;
LPBYTE dlg = NULL;
@@ -2418,8 +2442,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
branding_image_found = false;
DialogItemTemplate* dlgItem = 0;
for (int i = 0; (dlgItem = UIDlg.GetItemByIdx(i)); i++) {
- if ((IS_INTRESOURCE(dlgItem->szClass) && dlgItem->szClass == MAKEINTRESOURCE(0x0082))
- || (!IS_INTRESOURCE(dlgItem->szClass) && !strcmp(dlgItem->szClass, "Static"))) {
+ bool check = false;
+
+ if (IS_INTRESOURCE(dlgItem->szClass)) {
+ if (dlgItem->szClass == MAKEINTRESOURCEW(0x0082)) {
+ check = true;
+ }
+ } else {
+ char *szClass = winchar_toansi(dlgItem->szClass);
+ check = strcmp(szClass, "Static") == 0;
+ delete [] szClass;
+ }
+
+ if (check) {
if ((dlgItem->dwStyle & SS_BITMAP) == SS_BITMAP) {
branding_image_found = true;
branding_image_id = dlgItem->wId;
@@ -2486,7 +2521,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
padding = line.gettoken_int(3);
init_res_editor();
- BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG);
+ BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG);
CDialogTemplate dt(dlg, uDefCodePage);
@@ -2497,8 +2532,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
brandingCtl.dwStyle = SS_BITMAP | WS_CHILD | WS_VISIBLE;
brandingCtl.sX = padding;
brandingCtl.sY = padding;
- brandingCtl.szClass = MAKEINTRESOURCE(0x0082);
- brandingCtl.szTitle = "";
+ brandingCtl.szClass = MAKEINTRESOURCEW(0x0082);
+ brandingCtl.szTitle = NULL;
brandingCtl.wId = IDC_BRANDIMAGE;
brandingCtl.sHeight = wh;
@@ -2534,7 +2569,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DWORD dwDlgSize;
dlg = dt.Save(dwDlgSize);
- res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize);
+ res_editor->UpdateResourceA(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize);
delete [] dlg;
@@ -2575,14 +2610,38 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
}
return PS_OK;
#else
- case TOK_INSTCOLORS:
- case TOK_XPSTYLE:
- case TOK_CHANGEUI:
- case TOK_ADDBRANDINGIMAGE:
- case TOK_SETFONT:
- ERROR_MSG("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n",line.gettoken_str(0));
- return PS_ERROR;
+ case TOK_INSTCOLORS:
+ case TOK_XPSTYLE:
+ case TOK_CHANGEUI:
+ case TOK_ADDBRANDINGIMAGE:
+ case TOK_SETFONT:
+ ERROR_MSG("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n",line.gettoken_str(0));
+ return PS_ERROR;
#endif// NSIS_CONFIG_VISIBLE_SUPPORT
+
+ case TOK_REQEXECLEVEL:
+ {
+ int k=line.gettoken_enum(1,"none\0user\0highest\0admin\0");
+ switch (k)
+ {
+ case 0:
+ manifest_exec_level = manifest::exec_level_none;
+ break;
+ case 1:
+ manifest_exec_level = manifest::exec_level_user;
+ break;
+ case 2:
+ manifest_exec_level = manifest::exec_level_highest;
+ break;
+ case 3:
+ manifest_exec_level = manifest::exec_level_admin;
+ break;
+ default:
+ PRINTHELP();
+ }
+ }
+ return PS_OK;
+
// Ability to change compression methods from within the script
case TOK_SETCOMPRESSOR:
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
@@ -2736,6 +2795,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
sprintf(value,"%d",value1-value2);
} else if (!strcmp(mathop,"*")) {
sprintf(value,"%d",value1*value2);
+ } else if (!strcmp(mathop,"&")) {
+ sprintf(value,"%d",value1&value2);
+ } else if (!strcmp(mathop,"|")) {
+ sprintf(value,"%d",value1|value2);
+ } else if (!strcmp(mathop,"^")) {
+ sprintf(value,"%d",value1^value2);
} else if (!strcmp(mathop,"/")) {
if (value2==0) {
ERROR_MSG("!define /math: division by zero! (\"%i / %i\")\n",value1,value2);
@@ -2845,17 +2910,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
bool required = true;
char *f = line.gettoken_str(1);
-
+
if(!stricmp(f,"/nonfatal")) {
if (line.getnumtokens()!=3)
PRINTHELP();
-
+
f = line.gettoken_str(2);
- required = false;
+ required = false;
} else if (line.getnumtokens()!=2) {
PRINTHELP();
}
-
+
#ifdef _WIN32
char *fc = f;
#else
@@ -2877,27 +2942,27 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
#endif
// search working directory
- boost::scoped_ptr<dir_reader> dr( new_dir_reader() );
- dr->read(dir);
+ boost::scoped_ptr<dir_reader> dr( new_dir_reader() );
+ dr->read(dir);
- for (dir_reader::iterator files_itr = dr->files().begin();
- files_itr != dr->files().end();
- files_itr++)
- {
- if (!dir_reader::matches(*files_itr, spec))
- continue;
+ for (dir_reader::iterator files_itr = dr->files().begin();
+ files_itr != dr->files().end();
+ files_itr++)
+ {
+ if (!dir_reader::matches(*files_itr, spec))
+ continue;
- string incfile = basedir + *files_itr;
+ string incfile = basedir + *files_itr;
- if (includeScript((char *) incfile.c_str()) != PS_OK) {
- return PS_ERROR;
- }
+ if (includeScript((char *) incfile.c_str()) != PS_OK) {
+ return PS_ERROR;
+ }
included++;
}
if (included)
- return PS_OK;
+ return PS_OK;
// search include dirs
char *incdir = include_dirs.get();
@@ -2934,13 +2999,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (!included)
{
if(required) {
- ERROR_MSG("!include: could not find: \"%s\"\n",f);
- return PS_ERROR;
- } else {
- warning_fl("!include: could not find: \"%s\"",f);
- }
+ ERROR_MSG("!include: could not find: \"%s\"\n",f);
+ return PS_ERROR;
+ } else {
+ warning_fl("!include: could not find: \"%s\"",f);
}
}
+ }
return PS_OK;
case TOK_P_CD:
if (!line.gettoken_str(1)[0] || chdir(line.gettoken_str(1)))
@@ -3362,7 +3427,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (trim) try {
init_res_editor();
- BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG);
+ BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG);
CDialogTemplate td(dlg,uDefCodePage);
free(dlg);
@@ -3389,7 +3454,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DWORD dwSize;
dlg = td.Save(dwSize);
- res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG, dlg, dwSize);
+ res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG, dlg, dwSize);
res_editor->FreeResource(dlg);
}
catch (exception& err) {
@@ -3655,7 +3720,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DefineInnerLangString(NLF_SYMBOL_NOT_FOUND);
DefineInnerLangString(NLF_COULD_NOT_LOAD);
DefineInnerLangString(NLF_NO_OLE);
- DefineInnerLangString(NLF_ERR_REG_DLL);
+ // not used anywhere - DefineInnerLangString(NLF_ERR_REG_DLL);
return add_entry(&ent);
#endif//NSIS_SUPPORT_ACTIVEXREG
case TOK_RENAME:
@@ -4660,8 +4725,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
try
{
CResourceEditor *dllre = new CResourceEditor(dll, len);
- LPBYTE ver = dllre->GetResource(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
- int versize = dllre->GetResourceSize(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
+ LPBYTE ver = dllre->GetResourceA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
+ int versize = dllre->GetResourceSizeA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
if (ver)
{
@@ -4744,18 +4809,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
struct stat st;
if (!stat(line.gettoken_str(1), &st))
{
- union
- {
- struct
- {
- long l;
- long h;
- } words;
- long long ll;
- };
- ll = (st.st_mtime * 10000000LL) + 116444736000000000LL;
- high = words.h;
- low = words.l;
+ unsigned long long ll = (st.st_mtime * 10000000LL) + 116444736000000000LL;
+ high = (DWORD) (ll >> 32);
+ low = (DWORD) ll;
}
else
{
@@ -5183,7 +5239,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
ent.which=EW_READENVSTR;
ent.offsets[0]=GetUserVarIndex(line, 1);
{
- ent.offsets[1]=add_string(line.gettoken_str(2));
+ char str[NSIS_MAX_STRLEN];
+ strcpy(str, "%");
+ strcat(str, line.gettoken_str(2));
+ strcat(str, "%");
+ ent.offsets[1]=add_string(str);
if (ent.offsets[0] < 0 || strlen(line.gettoken_str(2))<1) PRINTHELP()
}
ent.offsets[2]=1;
@@ -5580,39 +5640,42 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
#ifdef NSIS_SUPPORT_VERSION_INFO
case TOK_VI_ADDKEY:
{
- LANGID LangID=0;
- int a = 1;
- if (!strnicmp(line.gettoken_str(a),"/LANG=",6))
- LangID=atoi(line.gettoken_str(a++)+6);
- if (line.getnumtokens()!=a+2) PRINTHELP();
- char *pKey = line.gettoken_str(a);
- char *pValue = line.gettoken_str(a+1);
- if ( !(*pKey) )
- {
- ERROR_MSG("Error: empty name for version info key!\n");
- return PS_ERROR;
- }
- else
+ LANGID LangID=0;
+ int a = 1;
+ if (!strnicmp(line.gettoken_str(a),"/LANG=",6))
+ LangID=atoi(line.gettoken_str(a++)+6);
+ if (line.getnumtokens()!=a+2) PRINTHELP();
+ char *pKey = line.gettoken_str(a);
+ char *pValue = line.gettoken_str(a+1);
+ if ( !(*pKey) )
+ {
+ ERROR_MSG("Error: empty name for version info key!\n");
+ return PS_ERROR;
+ }
+ else
+ {
+ SCRIPT_MSG("%s: \"%s\" \"%s\"\n", line.gettoken_str(0), line.gettoken_str(a), line.gettoken_str(a+1));
+ LANGID lReaded = LangID;
+ if ( a > 1 && lReaded == 0 )
+ warning_fl("%s: %s language not loaded, using default \"1033-English\"", line.gettoken_str(0), line.gettoken_str(1));
+
+ unsigned int codepage;
+ char *lang_name = GetLangNameAndCP(LangID, &codepage);
+
+ if ( rVersionInfo.SetKeyValue(LangID, codepage, pKey, pValue) )
{
- SCRIPT_MSG("%s: \"%s\" \"%s\"\n", line.gettoken_str(0), line.gettoken_str(a), line.gettoken_str(a+1));
- LANGID lReaded = LangID;
- LanguageTable *table = GetLangTable(LangID);
- if ( a > 1 && lReaded == 0 )
- warning_fl("%s: %s language not loaded, using default \"1033-English\"", line.gettoken_str(0), line.gettoken_str(1));
- if ( rVersionInfo.SetKeyValue(LangID, table->nlf.m_bLoaded ? table->nlf.m_uCodePage : 1252 /*English US*/, pKey, pValue) )
- {
- ERROR_MSG("%s: \"%s\" \"%04d-%s\" already defined!\n",line.gettoken_str(0), line.gettoken_str(2), LangID, table->nlf.m_bLoaded ? table->nlf.m_szName : LangID == 1033 ? "English" : "???");
- return PS_ERROR;
- }
-
- return PS_OK;
+ ERROR_MSG("%s: \"%s\" \"%04d-%s\" already defined!\n",line.gettoken_str(0), line.gettoken_str(2), LangID, lang_name);
+ return PS_ERROR;
}
+
+ return PS_OK;
+ }
}
case TOK_VI_SETPRODUCTVERSION:
if ( version_product_v[0] )
{
- ERROR_MSG("Error: %s already defined!\n", line.gettoken_str(0));
- return PS_ERROR;
+ ERROR_MSG("Error: %s already defined!\n", line.gettoken_str(0));
+ return PS_ERROR;
}
strcpy(version_product_v, line.gettoken_str(1));
return PS_OK;
@@ -5765,6 +5828,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return ret;
}
+ DefineInnerLangString(NLF_SYMBOL_NOT_FOUND);
+ DefineInnerLangString(NLF_COULD_NOT_LOAD);
+ DefineInnerLangString(NLF_NO_OLE);
+ // not used anywhere - DefineInnerLangString(NLF_ERR_REG_DLL);
+
return PS_OK;
}
return PS_ERROR;
@@ -6071,22 +6139,13 @@ int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const
struct stat st;
if (!fstat(fd, &st))
{
- union
- {
- struct
- {
- long l;
- long h;
- } words;
- long long ll;
- };
- ll = (st.st_mtime * 10000000LL) + 116444736000000000LL;
+ unsigned long long ll = (st.st_mtime * 10000000LL) + 116444736000000000LL;
// FAT write time has a resolution of 2 seconds
ll -= ll % 20000000;
- ent.offsets[3] = words.l;
- ent.offsets[4] = words.h;
+ ent.offsets[3] = (int) ll;
+ ent.offsets[4] = (int) (ll >> 32);
}
#endif
else
diff --git a/Source/strlist.cpp b/Source/strlist.cpp
index 232e8e3..e655c6a 100755
--- a/Source/strlist.cpp
+++ b/Source/strlist.cpp
@@ -1,8 +1,20 @@
-#include "strlist.h"
+/*
+ * strlist.cpp: Implementation of the StringList class.
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
-// ==========
-// StringList
-// ==========
+#include "strlist.h"
int StringList::add(const char *str, int case_sensitive)
{
diff --git a/Source/strlist.h b/Source/strlist.h
index 505a6f0..8c151dc 100755
--- a/Source/strlist.h
+++ b/Source/strlist.h
@@ -1,3 +1,19 @@
+/*
+ * strlist.h: Implementation of the StringList class.
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef _STRLIST_H_
#define _STRLIST_H_
diff --git a/Source/tokens.cpp b/Source/tokens.cpp
index c4619db..7df6dc2 100755
--- a/Source/tokens.cpp
+++ b/Source/tokens.cpp
@@ -1,3 +1,19 @@
+/*
+ * tokens.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#include <stdlib.h>
#include <stdio.h>
@@ -5,15 +21,6 @@
#include "build.h"
#include "tokens.h"
-// token placement
-#define TP_SEC 1
-#define TP_FUNC 2
-#define TP_CODE (TP_SEC | TP_FUNC)
-#define TP_GLOBAL 4
-#define TP_PAGEEX 8
-#define TP_PG (TP_GLOBAL | TP_PAGEEX)
-#define TP_ALL (TP_CODE | TP_PG)
-
typedef struct
{
int id;
@@ -147,7 +154,7 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_RENAME,"Rename",2,1,"[/REBOOTOK] source_file destination_file",TP_CODE},
{TOK_RET,"Return",0,0,"",TP_CODE},
{TOK_RMDIR,"RMDir",1,2,"[/r] [/REBOOTOK] directory_name",TP_CODE},
-{TOK_SECTION,"Section",0,3,"[/0] [-][un.][section_name] [section index output]",TP_GLOBAL},
+{TOK_SECTION,"Section",0,3,"[/o] [-][un.][section_name] [section index output]",TP_GLOBAL},
{TOK_SECTIONEND,"SectionEnd",0,0,"",TP_SEC},
{TOK_SECTIONIN,"SectionIn",1,-1,"InstTypeIdx [InstTypeIdx [...]]",TP_SEC},
{TOK_SUBSECTION,"SubSection",1,2,"deprecated - use SectionGroup",TP_GLOBAL},
@@ -219,6 +226,7 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_WRITEREGEXPANDSTR,"WriteRegExpandStr",4,0,"rootkey subkey entry_name new_value_string\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_WRITEUNINSTALLER,"WriteUninstaller",1,0,"uninstall_exe_name",TP_CODE},
{TOK_XPSTYLE, "XPStyle",1,0,"(on|off)",TP_GLOBAL},
+{TOK_REQEXECLEVEL, "RequestExecutionLevel",1,0,"none|user|highest|admin",TP_GLOBAL},
{TOK_P_PACKEXEHEADER,"!packhdr",2,0,"temp_file_name command_line_to_compress_that_temp_file",TP_ALL},
{TOK_P_SYSTEMEXEC,"!system",1,2,"command [<|>|<>|=) retval]",TP_ALL},
{TOK_P_EXECUTE,"!execute",1,0,"command",TP_ALL},
@@ -229,7 +237,7 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_P_IFDEF,"!ifdef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL},
{TOK_P_IFNDEF,"!ifndef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL},
{TOK_P_ENDIF,"!endif",0,0,"",TP_ALL},
-{TOK_P_DEFINE,"!define",1,4,"([/date|/utcdate] symbol [value]) | (/math symbol val1 OP val2)\n OP=(+ - * / %)",TP_ALL},
+{TOK_P_DEFINE,"!define",1,4,"([/date|/utcdate] symbol [value]) | (/math symbol val1 OP val2)\n OP=(+ - * / % & | ^)",TP_ALL},
{TOK_P_UNDEF,"!undef",1,1,"symbol [value]",TP_ALL},
{TOK_P_ELSE,"!else",0,-1,"[if[macro][n][def] ...]",TP_ALL},
{TOK_P_ECHO,"!echo",1,0,"message",TP_ALL},
@@ -289,6 +297,14 @@ void CEXEBuild::print_help(char *commandname)
}
+bool CEXEBuild::is_valid_token(char *s)
+{
+ for (int x = 0; x < TOK__LAST; x ++)
+ if (!stricmp(tokenlist[x].name,s))
+ return true;
+ return false;
+}
+
int CEXEBuild::get_commandtoken(char *s, int *np, int *op, int *pos)
{
int x;
@@ -303,69 +319,77 @@ int CEXEBuild::get_commandtoken(char *s, int *np, int *op, int *pos)
return -1;
}
+int CEXEBuild::GetCurrentTokenPlace()
+{
+ if (build_cursection)
+ {
+ if (build_cursection_isfunc)
+ {
+ return TP_FUNC;
+ }
+ else
+ {
+ return TP_SEC;
+ }
+ }
+
+ if (cur_page)
+ return TP_PAGEEX;
+
+ return TP_GLOBAL;
+}
+
int CEXEBuild::IsTokenPlacedRight(int pos, char *tok)
{
if ((unsigned int) pos > (sizeof(tokenlist) / sizeof(tokenType)))
return PS_OK;
int tp = tokenlist[pos].placement;
- if (build_cursection && !build_cursection_isfunc)
- {
- // section
- if (tp & TP_SEC)
- return PS_OK;
- ERROR_MSG("Error: command %s not valid in section\n", tok);
- return PS_ERROR;
- }
- else if (build_cursection && build_cursection_isfunc)
- {
- // function
- if (tp & TP_FUNC)
- return PS_OK;
- ERROR_MSG("Error: command %s not valid in function\n", tok);
- return PS_ERROR;
- }
- else if (cur_page)
- {
- // pageex
- if (tp & TP_PAGEEX)
- return PS_OK;
- ERROR_MSG("Error: command %s not valid in PageEx\n", tok);
- return PS_ERROR;
+ int cp = GetCurrentTokenPlace();
+ if (tp & cp) {
+ return PS_OK;
}
- else
- {
- // global
- if (tp & TP_GLOBAL)
- return PS_OK;
+ else {
char err[1024];
- strcpy(err, "Error: command %s not valid outside ");
- if (tp & TP_SEC)
- strcat(err, "section");
- if (tp & TP_FUNC)
+ if (cp == TP_SEC) {
+ strcpy(err, "Error: command %s not valid in Section\n");
+ }
+ else if (cp == TP_FUNC) {
+ strcpy(err, "Error: command %s not valid in Function\n");
+ }
+ else if (cp == TP_PAGEEX) {
+ strcpy(err, "Error: command %s not valid in PageEx\n");
+ }
+ else
{
+ strcpy(err, "Error: command %s not valid outside ");
if (tp & TP_SEC)
+ strcat(err, "Section");
+ if (tp & TP_FUNC)
{
- if (tp & TP_PAGEEX)
+ if (tp & TP_SEC)
{
- strcat(err, ", ");
+ if (tp & TP_PAGEEX)
+ {
+ strcat(err, ", ");
+ }
+ else
+ {
+ strcat(err, " or ");
+ }
}
- else
+ strcat(err, "Function");
+ }
+ if (tp & TP_PAGEEX)
+ {
+ if (tp & TP_CODE)
{
strcat(err, " or ");
}
+ strcat(err, "PageEx");
}
- strcat(err, "function");
- }
- if (tp & TP_PAGEEX)
- {
- if (tp & TP_CODE)
- {
- strcat(err, " or ");
- }
- strcat(err, "PageEx");
+ strcat(err, "\n");
}
- strcat(err, "\n");
ERROR_MSG(err, tok);
return PS_ERROR;
}
diff --git a/Source/tokens.h b/Source/tokens.h
index e3debaa..b418a44 100755
--- a/Source/tokens.h
+++ b/Source/tokens.h
@@ -1,3 +1,19 @@
+/*
+ * tokens.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef _TOKENS_H_
#define _TOKENS_H_
@@ -42,6 +58,7 @@ enum
TOK_FILEERRORTEXT,
TOK_INSTPROGRESSFLAGS,
TOK_XPSTYLE,
+ TOK_REQEXECLEVEL,
TOK_CHANGEUI,
TOK_ADDBRANDINGIMAGE,
TOK_SETFONT,
diff --git a/Source/uservars.h b/Source/uservars.h
index ae79b44..d559a4c 100755
--- a/Source/uservars.h
+++ b/Source/uservars.h
@@ -1,4 +1,18 @@
-// uservars.h by Ramon 10 Jun 2003
+/*
+ * uservars.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 2003 Ramon
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
#ifndef ___USERVARS___H_____
#define ___USERVARS___H_____
diff --git a/Source/util.cpp b/Source/util.cpp
index cc90655..923778d 100755
--- a/Source/util.cpp
+++ b/Source/util.cpp
@@ -1,3 +1,19 @@
+/*
+ * util.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "Platform.h"
#include <stdio.h>
#include <stdarg.h>
@@ -106,7 +122,7 @@ int update_bitmap(CResourceEditor* re, WORD id, const char* filename, int width/
}
fclose(f);
- re->UpdateResource(RT_BITMAP, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, bitmap, dwSize);
+ re->UpdateResourceA(RT_BITMAP, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, bitmap, dwSize);
free(bitmap);
@@ -185,7 +201,7 @@ void replace_icon(CResourceEditor* re, WORD wIconId, const char* filename)
int i = 1;
// Delete old icons
- while (re->UpdateResource(RT_ICON, MAKEINTRESOURCE(i++), NSIS_DEFAULT_LANG, 0, 0));
+ while (re->UpdateResourceA(RT_ICON, MAKEINTRESOURCE(i++), NSIS_DEFAULT_LANG, 0, 0));
for (i = 0; i < igh.wCount; i++) {
fread(ige, sizeof(FileIconGroupEntry)-sizeof(DWORD), 1, f);
@@ -212,7 +228,7 @@ void replace_icon(CResourceEditor* re, WORD wIconId, const char* filename)
throw bad_alloc();
}
fread(iconData, sizeof(BYTE), dwRawSize, f);
- re->UpdateResource(RT_ICON, MAKEINTRESOURCE(i+1), NSIS_DEFAULT_LANG, iconData, dwRawSize);
+ re->UpdateResourceA(RT_ICON, MAKEINTRESOURCE(i+1), NSIS_DEFAULT_LANG, iconData, dwRawSize);
free(iconData);
fsetpos(f, &pos);
@@ -224,7 +240,7 @@ void replace_icon(CResourceEditor* re, WORD wIconId, const char* filename)
fclose(f);
- re->UpdateResource(RT_GROUP_ICON, MAKEINTRESOURCE(wIconId), NSIS_DEFAULT_LANG, rsrcIconGroup, sizeof(IconGroupHeader) + igh.wCount*SIZEOF_RSRC_ICON_GROUP_ENTRY);
+ re->UpdateResourceA(RT_GROUP_ICON, MAKEINTRESOURCE(wIconId), NSIS_DEFAULT_LANG, rsrcIconGroup, sizeof(IconGroupHeader) + igh.wCount*SIZEOF_RSRC_ICON_GROUP_ENTRY);
free(rsrcIconGroup);
}
diff --git a/Source/util.h b/Source/util.h
index 6da9b46..943b44f 100755
--- a/Source/util.h
+++ b/Source/util.h
@@ -1,3 +1,19 @@
+/*
+ * util.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef _UTIL_H_
#define _UTIL_H_
diff --git a/Source/winchar.cpp b/Source/winchar.cpp
new file mode 100755
index 0000000..c8cab50
--- /dev/null
+++ b/Source/winchar.cpp
@@ -0,0 +1,126 @@
+/*
+ * winchar.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#include "Platform.h"
+#include "winchar.h"
+#include "util.h"
+
+#include <stdexcept>
+
+using std::runtime_error;
+
+WCHAR *winchar_fromansi(const char* s, unsigned int codepage/*=CP_ACP*/)
+{
+ int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0);
+ if (l == 0)
+ throw runtime_error("Unicode conversion failed");
+
+ WCHAR *ws = new WCHAR[l + 1];
+
+ if (MultiByteToWideChar(codepage, 0, s, -1, ws, l + 1) == 0)
+ throw runtime_error("Unicode conversion failed");
+
+ return ws;
+}
+
+char *winchar_toansi(const WCHAR* ws, unsigned int codepage/*=CP_ACP*/)
+{
+ int l = WideCharToMultiByte(codepage, 0, ws, -1, 0, 0, 0, 0);
+ if (l == 0)
+ throw runtime_error("Unicode conversion failed");
+
+ char *s = new char[l + 1];
+
+ if (WideCharToMultiByte(codepage, 0, ws, -1, s, l + 1, 0, 0) == 0)
+ throw runtime_error("Unicode conversion failed");
+
+ return s;
+}
+
+WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2)
+{
+ WCHAR *ret = ws1;
+
+ while (*ws2)
+ {
+ *ws1++ = *ws2++;
+ }
+
+ *ws1 = 0;
+
+ return ret;
+}
+
+WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n)
+{
+ WCHAR *ret = ws1;
+
+ while (n && *ws2)
+ {
+ *ws1++ = *ws2++;
+ n--;
+ }
+
+ while (n--)
+ {
+ *ws1++ = 0;
+ }
+
+ return ret;
+}
+
+size_t winchar_strlen(WCHAR *ws)
+{
+ size_t len = 0;
+
+ while (*ws++)
+ {
+ len++;
+ }
+
+ return len;
+}
+
+WCHAR *winchar_strdup(WCHAR *ws)
+{
+ WCHAR *dup = new WCHAR[winchar_strlen(ws) + 1];
+ winchar_strcpy(dup, ws);
+ return dup;
+}
+
+int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2)
+{
+ int diff = 0;
+
+ do
+ {
+ diff = static_cast<int>(*ws1) - static_cast<int>(*ws2);
+ }
+ while (*ws1++ && *ws2++ && !diff);
+
+ return diff;
+}
+
+int winchar_stoi(const WCHAR *ws)
+{
+ char *s = winchar_toansi(ws);
+
+ int ret = atoi(s);
+
+ delete [] s;
+
+ return ret;
+}
diff --git a/Source/winchar.h b/Source/winchar.h
new file mode 100755
index 0000000..caad97e
--- /dev/null
+++ b/Source/winchar.h
@@ -0,0 +1,26 @@
+/*
+ * winchar.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#include "Platform.h"
+
+WCHAR *winchar_fromansi(const char* s, unsigned int codepage = CP_ACP);
+char *winchar_toansi(const WCHAR* ws, unsigned int codepage = CP_ACP);
+WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2);
+WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n);
+size_t winchar_strlen(WCHAR *ws);
+WCHAR *winchar_strdup(WCHAR *ws);
+int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2);
+int winchar_stoi(const WCHAR *ws);
diff --git a/Source/writer.cpp b/Source/writer.cpp
index a59c89a..20207fd 100755
--- a/Source/writer.cpp
+++ b/Source/writer.cpp
@@ -1,3 +1,19 @@
+/*
+ * writer.cpp
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#include "exehead/config.h"
#include "writer.h"
#include "growbuf.h"
diff --git a/Source/writer.h b/Source/writer.h
index 399d53d..7f672bb 100755
--- a/Source/writer.h
+++ b/Source/writer.h
@@ -1,3 +1,19 @@
+/*
+ * writer.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * Licensed under the zlib/libpng license (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * Licence details can be found in the file COPYING.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
#ifndef ___WRITER__H___
#define ___WRITER__H___
diff --git a/Source/zlib/DEFLATE.H b/Source/zlib/DEFLATE.H
index f50885d..0af4034 100755
--- a/Source/zlib/DEFLATE.H
+++ b/Source/zlib/DEFLATE.H
@@ -1,3 +1,16 @@
+/*
+ * This file is a part of the zlib compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.zlib.net/
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
/* deflate.h -- internal compression state
* Copyright (C) 1995-1998 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
diff --git a/Source/zlib/INFBLOCK.C b/Source/zlib/INFBLOCK.C
index 959a42c..8e937fb 100755
--- a/Source/zlib/INFBLOCK.C
+++ b/Source/zlib/INFBLOCK.C
@@ -1,8 +1,24 @@
+/*
+ * This file is a part of the zlib compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.zlib.net/
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
+#include "../Platform.h"
#include "../exehead/config.h"
-#ifdef NSIS_COMPRESS_USE_ZLIB
#include "ZUTIL.H"
+#ifndef min
+# define min(x,y) ((x<y)?x:y)
+#endif
/* defines for inflate input/output */
/* update pointers and return */
@@ -692,6 +708,3 @@ int ZEXPORT inflate(z_streamp z)
#undef n
#undef q
#undef m
-
-
-#endif
diff --git a/Source/zlib/ZCONF.H b/Source/zlib/ZCONF.H
index f7114bf..6ca8fb5 100755
--- a/Source/zlib/ZCONF.H
+++ b/Source/zlib/ZCONF.H
@@ -1,9 +1,22 @@
+/*
+ * This file is a part of the zlib compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.zlib.net/
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-1998 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* @(#) $Id: ZCONF.H,v 1.1.1.1 2002/08/02 10:01:35 kichik Exp $ */
+/* @(#) $Id: ZCONF.H,v 1.3 2007/01/13 17:28:23 kichik Exp $ */
#ifndef _ZCONF_H
#define _ZCONF_H
diff --git a/Source/zlib/ZLIB.H b/Source/zlib/ZLIB.H
index 4eab26d..e1ee3a4 100755
--- a/Source/zlib/ZLIB.H
+++ b/Source/zlib/ZLIB.H
@@ -1,16 +1,15 @@
/*
- Note: this version of zlib has been hacked up quite a bit in order to reduce
- the size of the EXE header and to remove what we didn't need.
- For the complete real thing, go to:
-
- http://www.info-zip.org/pub/infozip/zlib/
-
- Peace,
-
- -Justin
-*/
-
-
+ * This file is a part of the zlib compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.zlib.net/
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.1.3, July 9th, 1998
diff --git a/Source/zlib/ZUTIL.H b/Source/zlib/ZUTIL.H
index d2f20a1..67defc5 100755
--- a/Source/zlib/ZUTIL.H
+++ b/Source/zlib/ZUTIL.H
@@ -1,3 +1,16 @@
+/*
+ * This file is a part of the zlib compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.zlib.net/
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
/* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-1998 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
@@ -8,7 +21,7 @@
subject to change. Applications should only use zlib.h.
*/
-/* @(#) $Id: ZUTIL.H,v 1.3 2004/03/29 20:21:00 kichik Exp $ */
+/* @(#) $Id: ZUTIL.H,v 1.6 2007/01/25 18:07:40 kichik Exp $ */
#ifndef _Z_UTIL_H
#define _Z_UTIL_H
@@ -46,28 +59,26 @@ typedef unsigned long ulg;
#ifdef EXEHEAD
-#include "../exehead/util.h"
-#define zmemcpy mini_memcpy
+# ifdef _WIN32
+# include "../exehead/util.h"
+# define zmemcpy mini_memcpy
+# else
+# define zmemcpy memcpy
+# endif
#else
-#define zmemcpy memcpy
-#define zmemzero(a,b) memset(a,0,b)
+# define zmemcpy memcpy
+# define zmemzero(a,b) memset(a,0,b)
#endif
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
+#define Assert(cond,msg)
+#define Trace(x)
+#define Tracev(x)
+#define Tracevv(x)
+#define Tracec(c,x)
+#define Tracecv(c,x)
-#ifdef EXEHEAD
-#include "../exehead/util.h"
-#define ZALLOC(strm, items, size) my_GlobalAlloc((items)*(size))
-#define ZFREE(strm, addr) { if (addr) GlobalFree(addr); }
-#else // def EXEHEAD
#define ZALLOC(strm, items, size) malloc((items)*(size))
#define ZFREE(strm, addr) { if (addr) free(addr); }
-#endif // def EXEHEAD
#define TRY_FREE(s, p) { ZFREE(s, p); }
#define ERR_RETURN(strm,err) return (err)
diff --git a/Source/zlib/deflate.c b/Source/zlib/deflate.c
index 1e92a79..1b74143 100755
--- a/Source/zlib/deflate.c
+++ b/Source/zlib/deflate.c
@@ -1,3 +1,16 @@
+/*
+ * This file is a part of the zlib compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.zlib.net/
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
/* deflate.c -- compress data using the deflation algorithm
* Copyright (C) 1995-1998 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
diff --git a/Source/zlib/trees.c b/Source/zlib/trees.c
index 5bd25ac..eb1a5af 100755
--- a/Source/zlib/trees.c
+++ b/Source/zlib/trees.c
@@ -1,3 +1,16 @@
+/*
+ * This file is a part of the zlib compression module for NSIS.
+ *
+ * Copyright and license information can be found below.
+ * Modifications Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * The original zlib source code is available at
+ * http://www.zlib.net/
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ */
+
/* trees.c -- output deflated data using Huffman coding
* Copyright (C) 1995-1998 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h