diff --git a/Source/7zip/7zGuids.cpp b/Source/7zip/7zGuids.cpp index af770534..56caa945 100644 --- a/Source/7zip/7zGuids.cpp +++ b/Source/7zip/7zGuids.cpp @@ -2,11 +2,13 @@ // #include "StdAfx.h" -#ifndef INITGUID -#define INITGUID +#ifdef WIN32 +# include +# include #endif -#include -#include + #include "../Platform.h" + +#define INITGUID #include "7zip/ICoder.h" #include "7zip/Compress/LZ/IMatchFinder.h" diff --git a/Source/7zip/7zip/Common/StdAfx.h b/Source/7zip/7zip/Common/StdAfx.h index a32fbed6..7a63aeaf 100644 --- a/Source/7zip/7zip/Common/StdAfx.h +++ b/Source/7zip/7zip/Common/StdAfx.h @@ -3,6 +3,10 @@ #ifndef __STDAFX_H #define __STDAFX_H -#include +#ifdef _WIN32 +# include +#else +# include "../../../Platform.h" +#endif #endif diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree.h index 9096fe70..67acb025 100644 --- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTree.h +++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTree.h @@ -15,7 +15,8 @@ namespace BT_NAMESPACE { #ifdef __USE_3_BYTES -#pragma pack(push, PragmaBinTree, 1) +//#pragma pack(push, PragmaBinTree, 1) +#pragma pack(1) struct CIndex { @@ -31,7 +32,8 @@ struct CIndex }; const UINT32 kMaxValForNormalize = CIndex(-1); -#pragma pack(pop, PragmaBinTree) +//#pragma pack(pop, PragmaBinTree) +#pragma pack() #else @@ -54,7 +56,8 @@ const UINT32 kMaxValForNormalize = (UINT32(1) << 31) - 1; // #endif -#pragma pack(push, PragmaBinTreePair, 1) +//#pragma pack(push, PragmaBinTreePair, 1) +#pragma pack(1) // #pragma pack(push, 1) struct CPair @@ -64,7 +67,8 @@ struct CPair }; // #pragma pack(pop) -#pragma pack(pop, PragmaBinTreePair) +//#pragma pack(pop, PragmaBinTreePair) +#pragma pack() class CInTree: public CLZInWindow { diff --git a/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h b/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h index 6657d07d..fc568bc7 100644 --- a/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h +++ b/Source/7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h @@ -40,13 +40,13 @@ namespace BT_NAMESPACE { CInTree::CInTree(): + _hash(0), #ifdef HASH_ARRAY_2 _hash2(0), #ifdef HASH_ARRAY_3 _hash3(0), #endif #endif - _hash(0), _son(0), _cutValue(0xFF) { @@ -134,7 +134,7 @@ static const UINT32 kEmptyHashValue = 0; HRESULT CInTree::Init(ISequentialInStream *stream) { RINOK(CLZInWindow::Init(stream)); - int i; + unsigned int i; for(i = 0; i < kHashSize; i++) _hash[i] = kEmptyHashValue; diff --git a/Source/7zip/7zip/Compress/LZ/StdAfx.h b/Source/7zip/7zip/Compress/LZ/StdAfx.h index a32fbed6..e93447e6 100644 --- a/Source/7zip/7zip/Compress/LZ/StdAfx.h +++ b/Source/7zip/7zip/Compress/LZ/StdAfx.h @@ -3,6 +3,10 @@ #ifndef __STDAFX_H #define __STDAFX_H -#include +#ifdef _WIN32 +# include +#else +# include "../../../../Platform.h" +#endif #endif diff --git a/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.h b/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.h index 64076a01..9580d740 100644 --- a/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.h +++ b/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.h @@ -254,10 +254,11 @@ public: HRESULT Create(); - MY_UNKNOWN_IMP2( + /*MY_UNKNOWN_IMP2( ICompressSetCoderProperties, ICompressWriteCoderProperties - ) + )*/ + MY_UNKNOWN_IMP STDMETHOD(Init)( ISequentialOutStream *outStream); diff --git a/Source/7zip/7zip/Compress/LZMA/StdAfx.h b/Source/7zip/7zip/Compress/LZMA/StdAfx.h index a32fbed6..e93447e6 100644 --- a/Source/7zip/7zip/Compress/LZMA/StdAfx.h +++ b/Source/7zip/7zip/Compress/LZMA/StdAfx.h @@ -3,6 +3,10 @@ #ifndef __STDAFX_H #define __STDAFX_H -#include +#ifdef _WIN32 +# include +#else +# include "../../../../Platform.h" +#endif #endif diff --git a/Source/7zip/7zip/Compress/RangeCoder/StdAfx.h b/Source/7zip/7zip/Compress/RangeCoder/StdAfx.h index a32fbed6..e93447e6 100644 --- a/Source/7zip/7zip/Compress/RangeCoder/StdAfx.h +++ b/Source/7zip/7zip/Compress/RangeCoder/StdAfx.h @@ -3,6 +3,10 @@ #ifndef __STDAFX_H #define __STDAFX_H -#include +#ifdef _WIN32 +# include +#else +# include "../../../../Platform.h" +#endif #endif diff --git a/Source/7zip/7zip/IMyUnknown.h b/Source/7zip/7zip/IMyUnknown.h index d614d99a..7e4b2014 100644 --- a/Source/7zip/7zip/IMyUnknown.h +++ b/Source/7zip/7zip/IMyUnknown.h @@ -5,20 +5,52 @@ #ifndef __MYUNKNOWN_H #define __MYUNKNOWN_H -#ifdef WIN32 +#ifdef _WIN32 // #include #include -#else +#else + +#include "../../Platform.h" + +#include #define HRESULT LONG -#define STDMETHODCALLTYPE __stdcall + +#if ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)) +# define STDMETHODCALLTYPE __stdcall +#else +# if defined(__GNUC__) && defined(__i386__) +# define STDMETHODCALLTYPE __attribute__((__stdcall__)) +# else +# define STDMETHODCALLTYPE +# endif +#endif + +#define PROPID ULONG #define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f #define STDMETHOD(f) STDMETHOD_(HRESULT, f) #define STDMETHODIMP_(type) type STDMETHODCALLTYPE #define STDMETHODIMP STDMETHODIMP_(HRESULT) +#define VT_UI4 1 +#define VT_BSTR 2 + +typedef struct _PROPVARIANT +{ + WORD vt; + ULONG ulVal; + wchar_t *bstrVal; +} PROPVARIANT; + +#define S_OK 0 +#define E_NOINTERFACE 0x80000001 +#define E_ABORT 0x80000002 +#define E_INVALIDARG 0x80070057 +#define E_FAIL 0x80004005 +#define E_OUTOFMEMORY 0x8007000E + #define PURE = 0; typedef struct { @@ -35,33 +67,34 @@ typedef struct { #endif #ifdef INITGUID - #define MY_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + #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 MY_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + #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 & +typedef const GUID & REFGUID; #else #define REFGUID const GUID * __MIDL_CONST #endif -#define MIDL_INTERFACE(x) struct +#define MIDL_INTERFACE(x) struct + inline int operator==(REFGUID g1, REFGUID g2) { - for (int i = 0; i < sizeof(g1); i++) + for (unsigned int i = 0; i < sizeof(g1); i++) if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i]) return false; return true; } -inline int operator!=(REFGUID &g1, REFGUID &g2) +inline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); } struct IUnknown { - STDMETHOD(QueryInterface) (const GUID *iid, void **outObject) PURE; + STDMETHOD(QueryInterface) (REFGUID iid, void **outObject) PURE; STDMETHOD_(ULONG, AddRef)() PURE; STDMETHOD_(ULONG, Release)() PURE; }; diff --git a/Source/7zip/Common/MyCom.h b/Source/7zip/Common/MyCom.h index 40e4ce29..54eb7cf2 100644 --- a/Source/7zip/Common/MyCom.h +++ b/Source/7zip/Common/MyCom.h @@ -50,10 +50,10 @@ public: _p = NULL; return pt; } - HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) + /*HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) { return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p); - } + }*/ /* HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) { @@ -65,16 +65,16 @@ public: return hr; } */ - template + /*template HRESULT QueryInterface(REFGUID iid, Q** pp) const { return _p->QueryInterface(iid, (void**)pp); - } + }*/ }; ////////////////////////////////////////////////////////// -class CMyComBSTR +/*class CMyComBSTR { public: BSTR m_str; @@ -83,7 +83,7 @@ public: // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); } // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize); } CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); } - /* + / * CMyComBSTR(REFGUID src) { LPOLESTR szGuid; @@ -91,7 +91,7 @@ public: m_str = ::SysAllocString(szGuid); CoTaskMemFree(szGuid); } - */ + * / ~CMyComBSTR() { ::SysFreeString(m_str); } CMyComBSTR& operator=(const CMyComBSTR& src) { @@ -132,7 +132,7 @@ public: m_str = NULL; } bool operator!() const { return (m_str == NULL); } -}; +};*/ ////////////////////////////////////////////////////////// diff --git a/Source/7zip/Common/StdAfx.h b/Source/7zip/Common/StdAfx.h index a32fbed6..074cf317 100644 --- a/Source/7zip/Common/StdAfx.h +++ b/Source/7zip/Common/StdAfx.h @@ -3,6 +3,10 @@ #ifndef __STDAFX_H #define __STDAFX_H -#include +#ifdef _WIN32 +# include +#else +# include "../../Platform.h" +#endif #endif diff --git a/Source/7zip/Common/Types.h b/Source/7zip/Common/Types.h index 02853e0d..6e769de9 100644 --- a/Source/7zip/Common/Types.h +++ b/Source/7zip/Common/Types.h @@ -5,7 +5,11 @@ #ifndef __COMMON_TYPES_H #define __COMMON_TYPES_H -#include +#ifdef _WIN32 +# include +#else +# include "../../Platform.h" +#endif typedef unsigned char UINT8; typedef unsigned short UINT16; diff --git a/Source/DialogTemplate.cpp b/Source/DialogTemplate.cpp index b9bb8eab..83b598c0 100644 --- a/Source/DialogTemplate.cpp +++ b/Source/DialogTemplate.cpp @@ -21,6 +21,12 @@ */ #include "DialogTemplate.h" +#include "util.h" +#ifndef _WIN32 +# include +# include +# include +#endif ////////////////////////////////////////////////////////////////////// // Utilities @@ -28,13 +34,6 @@ #define ALIGN(dwToAlign, dwAlignOn) dwToAlign = (dwToAlign%dwAlignOn == 0) ? dwToAlign : dwToAlign - (dwToAlign%dwAlignOn) + dwAlignOn -// returns the number of WCHARs in str including null charcter -inline DWORD WCStrLen(WCHAR* szwStr) { - int i; - for (i = 0; szwStr[i]; i++); - return i+1; -} - // Reads a variany length array from seeker into readInto and advances seeker void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) { WORD* arr = (WORD*)seeker; @@ -49,16 +48,49 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) { break; default: { - int iStrLen = WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, 0, 0, 0, 0); - readInto = new char[iStrLen]; - WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, readInto, iStrLen, 0, 0); - seeker += WCStrLen((WCHAR*)arr)*sizeof(WCHAR); + int iStrLen = 1; +#ifdef _WIN32 + iStrLen = WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, 0, 0, 0, 0); + if (iStrLen) + { + readInto = new char[iStrLen]; + WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, readInto, iStrLen, 0, 0); + } + else + { + *arr = 0; + seeker += sizeof(WCHAR); + } +#else + char cp[128] = ""; + if (uCodePage != CP_ACP) + snprintf(cp, 128, "CP%d", uCodePage); + iconv_t cd = iconv_open(cp, "UCS-2"); + if (cd != (iconv_t) -1) + { + iStrLen = WCStrLen((WCHAR *) arr); + char *in = (char *) arr; + char *out = readInto = new char[iStrLen + 1]; + size_t insize = (iStrLen * sizeof(WCHAR)) + 1; + size_t outsize = iStrLen + 1; + if (__iconv_adaptor(iconv, cd, &in, &insize, &out, &outsize) == (size_t) -1) + { + *arr = 0; + iStrLen = 1; + } + iconv_close(cd); + } + else + *arr = 0; +#endif + seeker += iStrLen*sizeof(WCHAR); } break; } } // A macro that writes a given string (that can be a number too) into the buffer +#ifdef _WIN32 #define WriteStringOrId(x) \ if (x) \ if (IS_INTRESOURCE(x)) { \ @@ -73,9 +105,46 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) { } \ else \ seeker += sizeof(WORD); +#else +#define WriteStringOrId(x) \ + if (x) \ + if (IS_INTRESOURCE(x)) { \ + *(WORD*)seeker = 0xFFFF; \ + seeker += sizeof(WORD); \ + *(WORD*)seeker = WORD(DWORD(x)); \ + seeker += sizeof(WORD); \ + } \ + else { \ + char cp[128] = ""; \ + if (m_uCodePage != CP_ACP) \ + snprintf(cp, 128, "CP%d", m_uCodePage); \ + iconv_t cd = iconv_open("UCS-2", cp); \ + if (cd != (iconv_t) -1) \ + { \ + char *in = (char *) x; \ + char *out = (char *) seeker; \ + size_t insize = strlen(in) + 1; \ + size_t outsize = insize * 2; \ + if (__iconv_adaptor(iconv, cd, &in, &insize, &out, &outsize) == (size_t) -1) \ + { \ + *seeker = 0; \ + seeker += sizeof(WCHAR); \ + } \ + seeker = (BYTE *) out; \ + iconv_close(cd); \ + } \ + else \ + { \ + *seeker = 0; \ + seeker += sizeof(WCHAR); \ + } \ + } \ + else \ + seeker += sizeof(WORD); +#endif // 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) : (lstrlen(x)+1)*sizeof(WCHAR)) : sizeof(WORD) +#define AddStringOrIdSize(x) dwSize += x ? (IS_INTRESOURCE(x) ? sizeof(DWORD) : (strlen(x)+1)*sizeof(WCHAR)) : sizeof(WORD) ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -264,7 +333,7 @@ int CDialogTemplate::RemoveItem(WORD wId) { // Sets the font of the dialog void CDialogTemplate::SetFont(char* szFaceName, WORD wFontSize) { - if (lstrcmp(szFaceName, "MS Shell Dlg")) { + if (strcmp(szFaceName, "MS Shell Dlg")) { // not MS Shell Dlg m_dwStyle &= ~DS_SHELLFONT; m_bExtended = false; @@ -276,8 +345,8 @@ void CDialogTemplate::SetFont(char* szFaceName, WORD wFontSize) { } m_dwStyle |= DS_SETFONT; if (m_szFont) delete [] m_szFont; - m_szFont = new char[lstrlen(szFaceName)+1]; - lstrcpy(m_szFont, szFaceName); + m_szFont = new char[strlen(szFaceName)+1]; + strcpy(m_szFont, szFaceName); m_sFontSize = wFontSize; } @@ -287,12 +356,12 @@ void CDialogTemplate::AddItem(DialogItemTemplate item) { CopyMemory(newItem, &item, sizeof(DialogItemTemplate)); if (item.szClass && !IS_INTRESOURCE(item.szClass)) { - newItem->szClass = new char[lstrlen(item.szClass)+1]; - lstrcpy(newItem->szClass, item.szClass); + newItem->szClass = new char[strlen(item.szClass)+1]; + strcpy(newItem->szClass, item.szClass); } if (item.szTitle && !IS_INTRESOURCE(item.szTitle)) { - newItem->szTitle = new char[lstrlen(item.szTitle)+1]; - lstrcpy(newItem->szTitle, item.szTitle); + newItem->szTitle = new char[strlen(item.szTitle)+1]; + strcpy(newItem->szTitle, item.szTitle); } if (item.wCreateDataSize) { newItem->szCreationData = new char[item.wCreateDataSize]; @@ -315,6 +384,7 @@ void CDialogTemplate::Resize(short x, short y) { m_sHeight += y; } +#ifdef _WIN32 // Creates a dummy dialog that is used for converting units HWND CDialogTemplate::CreateDummyDialog() { DWORD dwTemp; @@ -361,7 +431,7 @@ SIZE CDialogTemplate::GetStringSize(WORD id, char *str) { SelectObject(memDC, font); SIZE size; - GetTextExtentPoint32(memDC, str, lstrlen(str), &size); + GetTextExtentPoint32(memDC, str, strlen(str), &size); DestroyWindow(hDlg); DeleteObject(font); @@ -415,6 +485,7 @@ void CDialogTemplate::CTrimToString(WORD id, char *str, int margins) { item->sWidth = short(size.cx); item->sHeight = short(size.cy); } +#endif // Moves every item right and gives it the WS_EX_RIGHT extended style void CDialogTemplate::ConvertToRTL() { @@ -452,12 +523,12 @@ void CDialogTemplate::ConvertToRTL() { m_vItems[i]->dwStyle |= SS_CENTERIMAGE; } } - else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !strcmpi(m_vItems[i]->szClass, "RichEdit20A")) { + else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !stricmp(m_vItems[i]->szClass, "RichEdit20A")) { if ((m_vItems[i]->dwStyle & ES_CENTER) == 0) { m_vItems[i]->dwStyle ^= ES_RIGHT; } } - else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !strcmpi(m_vItems[i]->szClass, "SysTreeView32")) { + else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !stricmp(m_vItems[i]->szClass, "SysTreeView32")) { m_vItems[i]->dwStyle |= TVS_RTLREADING; addExStyle = true; } diff --git a/Source/DialogTemplate.h b/Source/DialogTemplate.h index ed5e91d2..6e117315 100644 --- a/Source/DialogTemplate.h +++ b/Source/DialogTemplate.h @@ -28,9 +28,9 @@ #endif // _MSC_VER > 1000 #include "Platform.h" -#include +#include -#include +#include using namespace std; struct DialogItemTemplate { @@ -51,7 +51,19 @@ struct DialogItemTemplate { WORD wCreateDataSize; }; -#pragma pack(push, 1) +#pragma pack(1) + +#ifndef _WIN32 +typedef struct { + DWORD style; + DWORD dwExtendedStyle; + WORD cdit; + short x; + short y; + short cx; + short cy; +} DLGTEMPLATE; +#endif typedef struct { WORD dlgVer; @@ -66,6 +78,18 @@ typedef struct { short cy; } DLGTEMPLATEEX; +#ifndef _WIN32 +typedef struct { + DWORD style; + DWORD dwExtendedStyle; + short x; + short y; + short cx; + short cy; + WORD id; +} DLGITEMTEMPLATE; +#endif + typedef struct { DWORD helpID; DWORD exStyle; @@ -78,7 +102,7 @@ typedef struct { WORD _miscrosoft_docs_are_wrong; } DLGITEMTEMPLATEEX; -#pragma pack(pop) +#pragma pack() class CDialogTemplate { public: @@ -92,15 +116,19 @@ public: int RemoveItem(WORD wId); void SetFont(char* szFaceName, WORD wFontSize); void AddItem(DialogItemTemplate item); +#ifdef _WIN32 HWND CreateDummyDialog(); +#endif void MoveAll(short x, short y); void Resize(short x, short y); +#ifdef _WIN32 void PixelsToDlgUnits(short& x, short& y); void DlgUnitsToPixels(short& x, short& y); SIZE GetStringSize(WORD id, char *str); void RTrimToString(WORD id, char *str, int margins); void LTrimToString(WORD id, char *str, int margins); void CTrimToString(WORD id, char *str, int margins); +#endif void ConvertToRTL(); BYTE* Save(DWORD& dwSize); DWORD GetSize(); diff --git a/Source/Makefile b/Source/Makefile index 3690cad1..1b2928eb 100644 --- a/Source/Makefile +++ b/Source/Makefile @@ -5,79 +5,52 @@ # -- Objects and source files -- SRCS = zlib/deflate.c zlib/trees.c bzip2/blocksort.c bzip2/bzlib.c bzip2/compress.c bzip2/huffman.c 7zip/7zGuids.cpp 7zip/Common/CRC.cpp 7zip/7zip/Compress/LZ/LZInWindow.cpp 7zip/7zip/Compress/LZMA/LZMAEncoder.cpp 7zip/7zip/Compress/LZMA/LZMALen.cpp 7zip/7zip/Compress/LZMA/LZMALiteral.cpp 7zip/7zip/Common/OutBuffer.cpp 7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp build.cpp crc32.c DialogTemplate.cpp exedata.cpp lang.cpp makenssi.cpp Plugins.cpp ResourceEditor.cpp ResourceVersionInfo.cpp script.cpp tokens.cpp util.cpp OBJS = 7zGuids.o blocksort.o build.o bzlib.o compress.o CRC.o crc32.o deflate.o DialogTemplate.o exedata.o huffman.o lang.o LZInWindow.o LZMAEncoder.o LZMALen.o LZMALiteral.o makenssi.o OutBuffer.o Plugins.o RangeCoderBit.o ResourceEditor.o ResourceVersionInfo.o script.o tokens.o trees.o util.o +ifeq "$(strip $(findstring i386pe,$(shell ld -V)))" "" +LIBS = -lstdc++ -lpthread +else LIBS = -lgdi32 -lversion -lstdc++ - -# -- Required .h files -- -BASEINC = Platform.h exehead/config.h +endif # -- Programs -- MAKE = make CC = gcc -RC = windres RM = rm # -- Compilers and linker flags -- -DEFINES = -DWIN32 -D_WINDOWS_ -CFLAGS = -Wall -O2 $(DEFINES) -CPPFLAGS = -Wall -O2 $(DEFINES) -LFLAGS = -s -RCFLAGS = --input-format rc --output-format coff +DEFINES = -DCOMPRESS_MF_BT +CFLAGS = -Wall -O3 +CXXFLAGS = -Wall -O3 +CPPFLAGS = $(DEFINES) +LDFLAGS = -s -Wl,-Map,$(subst .exe,.map,$@) -all : exehead_zlib exehead_bzip2 exehead_lzma exehead_resources makensis +all : makensis -exehead_zlib exehead_bzip2 exehead_lzma exehead_resources : - $(MAKE) -C exehead $@ +cs = zlib bzip2 lzma +rs = bitmap1.h icon.h unicon.h +deps = $(foreach c,$(cs),exehead/Release-$(c)/exehead_$(c).h) $(foreach r,$(rs),exehead/Release-zlib/$(r)) +exehead : $(deps) +$(deps) : + $(MAKE) -C exehead $(foreach d,$^,$(subst exehead/,,$(d))) -makensis : $(OBJS) - $(CC) $(CFLAGS) $(CPPFLAGS) $(LFLAGS) -o ../makensis.exe $(OBJS) $(LIBS) +makensis : ../makensis.exe -# -- Dependencies -- -build.o : build.cpp ./zlib/zlib.h $(BASEINC) ./exehead/fileform.h ./exehead/resource.h exedata.h build.h util.h strlist.h lineparse.h ResourceEditor.h Makefile -exedata.o : exedata.cpp exedata.h ./exehead/Release-zlib/bitmap1.h ./exehead/Release-zlib/icon.h ./exehead/Release-zlib/unicon.h ./exehead/Release-zlib/exehead_zlib.h Makefile -makenssi.o : makenssi.cpp build.h util.h exedata.h strlist.h lineparse.h ./exehead/fileform.h $(BASEINC) Makefile -script.o : script.cpp tokens.h build.h util.h exedata.h strlist.h lineparse.h ResourceEditor.h DialogTemplate.h ./exehead/resource.h ./exehead/fileform.h $(BASEINC) Makefile -tokens.o : tokens.cpp build.h tokens.h Makefile -util.o : util.cpp ./exehead/fileform.h util.h strlist.h ResourceEditor.h Makefile -crc32.o : crc32.c $(BASEINC) Makefile -ResourceEditor.o : ResourceEditor.cpp -DialogTemplate.o : DialogTemplate.cpp +../makensis.exe : $(SRCS) $(OBJS) $(deps) + $(CC) -Wall $(LDFLAGS) -o ../makensis.exe $(OBJS) $(LIBS) -# -- Special command lines for zlib -- -deflate.o : zlib/deflate.c - $(CC) $(CFLAGS) -c $< -o $@ -trees.o : zlib/trees.c - $(CC) $(CFLAGS) -c $< -o $@ +VPATH=zlib:bzip2:7zip:7zip/Common:7zip/7zip:7zip/7zip/Compress/LZ:7zip/7zip/Compress/LZMA:7zip/7zip/Common:7zip/7zip/Compress/RangeCoder -# -- Special command lines for bzip2 -- -blocksort.o : bzip2/blocksort.c - $(CC) $(CFLAGS) -c $< -o $@ -bzlib.o : bzip2/bzlib.c - $(CC) $(CFLAGS) -c $< -o $@ -compress.o : bzip2/compress.c - $(CC) $(CFLAGS) -c $< -o $@ -huffman.o : bzip2/huffman.c - $(CC) $(CFLAGS) -c $< -o $@ - -# -- Special command lines for lzma -- -7zGuids.o : 7zip/7zGuids.cpp - $(CC) $(CFLAGS) -c $< -o $@ -CRC.o : 7zip/Common/CRC.cpp - $(CC) $(CFLAGS) -c $< -o $@ -LZInWindow.o : 7zip/7zip/Compress/LZ/LZInWindow.cpp - $(CC) $(CFLAGS) -c $< -o $@ -LZMAEncoder.o : 7zip/7zip/Compress/LZMA/LZMAEncoder.cpp - $(CC) $(CFLAGS) -c $< -o $@ -LZMALen.o : 7zip/7zip/Compress/LZMA/LZMALen.cpp - $(CC) $(CFLAGS) -c $< -o $@ -LZMALiteral.o : 7zip/7zip/Compress/LZMA/LZMALiteral.cpp - $(CC) $(CFLAGS) -c $< -o $@ -OutBuffer.o : 7zip/7zip/Common/OutBuffer.cpp - $(CC) $(CFLAGS) -c $< -o $@ -RangeCoderBit.o : 7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp - $(CC) $(CFLAGS) -c $< -o $@ +# -- Some dependencies -- +$(OBJS) : Platform.h exehead/config.h +build.o : czlib.h cbzip2.h clzma.h exehead/fileform.h +script.o : exehead/fileform.h tokens.h # -- Clean script -- -clean :: +clean : clean_makensis $(MAKE) -C exehead clean - $(RM) *.o - $(RM) ../makensis.exe + +clean_makensis : + $(RM) -f *.o + $(RM) -f ../makensis.exe + +# -- Phony targets -- +.PHONY : exehead makensis clean clean_makensis \ No newline at end of file diff --git a/Source/Platform.h b/Source/Platform.h index 8384cbfd..236743ac 100644 --- a/Source/Platform.h +++ b/Source/Platform.h @@ -1,6 +1,8 @@ #ifndef ___PLATFORM__H___ #define ___PLATFORM__H___ +// some definitions for non Win32 platforms were taken from MinGW's free Win32 library + // includes #ifdef _WIN32 @@ -10,8 +12,51 @@ # include # include #else -# define WORD unsigned short -# define DWORD unsigned long +# ifndef EXEHEAD +# include +# include +# endif +// basic types +typedef unsigned char BYTE, *PBYTE, *LPBYTE; +typedef unsigned short WORD, *LPWORD; +typedef unsigned long DWORD, *LPDWORD; +typedef unsigned int UINT; +typedef unsigned int UINT32; +typedef int INT; +typedef int INT32; +typedef long LONG; +typedef unsigned long ULONG; +typedef long long INT64; +typedef unsigned long long UINT64; +typedef int BOOL; +typedef void VOID; +typedef void *LPVOID; +typedef char CHAR, *PCHAR, *LPCH, *PCH, *NPSTR, *LPSTR, *PSTR; +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 int UINT_PTR; +// basic stuff +typedef unsigned long HANDLE; +typedef unsigned long HKEY; +// some gdi +typedef unsigned long COLORREF; +typedef unsigned long HBRUSH; +// bool +# define FALSE 0 +# define TRUE 1 +// more +typedef WORD LANGID; +#endif + +// system specific + +#ifdef _WIN32 +# define PATH_SEPARATOR_STR "\\" +# define PATH_SEPARATOR_C '\\' +#else +# define PATH_SEPARATOR_STR "/" +# define PATH_SEPARATOR_C '/' #endif // attributes @@ -42,7 +87,7 @@ # define NSISCALL __stdcall // Ordinary functions # define NSISCALLV __cdecl // Variable-argument-list functions #else -# ifdef __GNUC__ +# if defined(__GNUC__) && defined(__i386__) # define NSISCALL __attribute__((__stdcall__)) // Ordinary functions # define NSISCALLV __attribute__((__cdecl__)) // Variable-argument-list functions # else @@ -51,141 +96,559 @@ # endif #endif +// macros + +#ifndef _WIN32 +# ifndef min +# define min(x,y) ((xy)?x:y) +# endif +# ifndef FIELD_OFFSET +# define FIELD_OFFSET(t,f) ((LONG)&(((t*)0)->f)) +# endif +# ifndef MAKEINTRESOURCE +# define MAKEINTRESOURCE(i) (LPSTR)((DWORD)((WORD)(i))) +# endif +# ifndef IMAGE_FIRST_SECTION +# define IMAGE_FIRST_SECTION(h) ((PIMAGE_SECTION_HEADER) ((DWORD)h+FIELD_OFFSET(IMAGE_NT_HEADERS,OptionalHeader)+((PIMAGE_NT_HEADERS)(h))->FileHeader.SizeOfOptionalHeader)) +# endif +# ifndef RGB +# define RGB(r,g,b) ((DWORD)(((BYTE)(r)|((WORD)(g)<<8))|(((DWORD)(BYTE)(b))<<16))) +# endif +# ifndef MAKELONG +# define MAKELONG(a,b) ((LONG)(((WORD)(a))|(((DWORD)((WORD)(b)))<<16))) +# endif +#endif +#ifndef IS_INTRESOURCE +# define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0) +#endif + +// functions + +#ifndef _WIN32 +# define stricmp strcasecmp +# define strcmpi strcasecmp +# define strnicmp strncasecmp +# define CopyMemory memcpy +# define ZeroMemory(x, y) memset(x, 0, y) +#endif + // defines #ifndef FOF_NOERRORUI -#define FOF_NOERRORUI 0x0400 -#endif - -#ifndef DS_SHELLFONT -#define DS_SHELLFONT (DS_SETFONT | DS_FIXEDSYS) +# define FOF_NOERRORUI 0x0400 #endif #ifndef ULONG_PTR -#define ULONG_PTR DWORD -#endif - -#ifndef IS_INTRESOURCE -#define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0) +# define ULONG_PTR DWORD #endif #ifndef IDC_HAND -#define IDC_HAND MAKEINTRESOURCE(32649) +# define IDC_HAND MAKEINTRESOURCE(32649) #endif #ifndef BIF_NEWDIALOGSTYLE -#define BIF_NEWDIALOGSTYLE 0x0040 +# define BIF_NEWDIALOGSTYLE 0x0040 #endif #ifndef TVITEM -#define TVITEM TV_ITEM +# define TVITEM TV_ITEM #endif #ifndef TVM_SETITEMHEIGHT -#define TVM_SETITEMHEIGHT (TV_FIRST + 27) +# define TVM_SETITEMHEIGHT (TV_FIRST + 27) #endif #ifndef TVM_GETITEMHEIGHT -#define TVM_GETITEMHEIGHT (TV_FIRST + 28) +# define TVM_GETITEMHEIGHT (TV_FIRST + 28) #endif #ifndef LVS_EX_LABELTIP -#define LVS_EX_LABELTIP 0x00004000 +# define LVS_EX_LABELTIP 0x00004000 #endif -#ifdef __GNUC__ // ((DWORD)-1) may cause parsing errors with MinGW -# ifdef INVALID_FILE_ATTRIBUTES // updated win32api may also set as (DWORD)-1 -# undef INVALID_FILE_ATTRIBUTES +#ifndef EXEHEAD +# ifndef SF_TEXT +# define SF_TEXT 1 # endif -# define INVALID_FILE_ATTRIBUTES ((unsigned long)-1) -#else -# ifndef INVALID_FILE_ATTRIBUTES -# define INVALID_FILE_ATTRIBUTES ((DWORD)-1) +# ifndef SF_RTF +# define SF_RTF 2 # endif #endif +#ifdef __GNUC__ +# undef INVALID_FILE_ATTRIBUTES +#endif +#ifndef INVALID_FILE_ATTRIBUTES +# define INVALID_FILE_ATTRIBUTES ((unsigned long) -1) +#endif + +// shell folders + +#ifdef _WIN32 +# include +#endif + #ifndef CSIDL_FLAG_CREATE -#define CSIDL_FLAG_CREATE 0x8000 +# define CSIDL_FLAG_CREATE 0x8000 #endif -#ifndef CSIDL_WINDOWS -#define CSIDL_WINDOWS 0x0024 +#ifndef CSIDL_PROGRAMS +# define CSIDL_PROGRAMS 0x2 #endif - -#ifndef CSIDL_SYSTEM -#define CSIDL_SYSTEM 0x0025 +#ifndef CSIDL_COMMON_PROGRAMS +# define CSIDL_COMMON_PROGRAMS 0x17 #endif - -#ifndef CSIDL_PROGRAM_FILES -#define CSIDL_PROGRAM_FILES 0x0026 +#ifndef CSIDL_PRINTERS +# define CSIDL_PRINTERS 0x4 #endif - -#ifndef CSIDL_PROGRAM_FILES_COMMON -#define CSIDL_PROGRAM_FILES_COMMON 0x002b +#ifndef CSIDL_PERSONAL +# define CSIDL_PERSONAL 0x5 #endif - #ifndef CSIDL_COMMON_DOCUMENTS -#define CSIDL_COMMON_DOCUMENTS 0x002e +# define CSIDL_COMMON_DOCUMENTS 0x2E #endif - -#ifndef CSIDL_RESOURCES -#define CSIDL_RESOURCES 0x0038 +#ifndef CSIDL_FAVORITES +# define CSIDL_FAVORITES 0x6 #endif - -#ifndef CSIDL_RESOURCES_LOCALIZED -#define CSIDL_RESOURCES_LOCALIZED 0x0039 +#ifndef CSIDL_COMMON_FAVORITES +# define CSIDL_COMMON_FAVORITES 0x1F #endif - -#ifndef CSIDL_COMMON_ADMINTOOLS -#define CSIDL_COMMON_ADMINTOOLS 0x002f +#ifndef CSIDL_STARTUP +# define CSIDL_STARTUP 0x7 #endif - -#ifndef CSIDL_ADMINTOOLS -#define CSIDL_ADMINTOOLS 0x0030 +#ifndef CSIDL_COMMON_STARTUP +# define CSIDL_COMMON_STARTUP 0x18 #endif - -#ifndef CSIDL_MYPICTURES -#define CSIDL_MYPICTURES 0x0027 +#ifndef CSIDL_RECENT +# define CSIDL_RECENT 0x8 #endif - -#ifndef CSIDL_COMMON_PICTURES -#define CSIDL_COMMON_PICTURES 0x0036 +#ifndef CSIDL_SENDTO +# define CSIDL_SENDTO 0x9 #endif - -#ifndef CSIDL_MYMUSIC -#define CSIDL_MYMUSIC 0x000d +#ifndef CSIDL_STARTMENU +# define CSIDL_STARTMENU 0xB #endif - -#ifndef CSIDL_COMMON_MUSIC -#define CSIDL_COMMON_MUSIC 0x0035 +#ifndef CSIDL_COMMON_STARTMENU +# define CSIDL_COMMON_STARTMENU 0x16 #endif - -#ifndef CSIDL_MYVIDEO -#define CSIDL_MYVIDEO 0x000e +#ifndef CSIDL_DESKTOPDIRECTORY +# define CSIDL_DESKTOPDIRECTORY 0x10 #endif - -#ifndef CSIDL_COMMON_VIDEO -#define CSIDL_COMMON_VIDEO 0x0037 +#ifndef CSIDL_COMMON_DESKTOPDIRECTORY +# define CSIDL_COMMON_DESKTOPDIRECTORY 0x19 #endif - -#ifndef CSIDL_CDBURN_AREA -#define CSIDL_CDBURN_AREA 0x003b +#ifndef CSIDL_NETHOOD +# define CSIDL_NETHOOD 0x13 +#endif +#ifndef CSIDL_FONTS +# define CSIDL_FONTS 0x14 #endif - #ifndef CSIDL_TEMPLATES -#define CSIDL_TEMPLATES 0x0015 +# define CSIDL_TEMPLATES 0x15 #endif - #ifndef CSIDL_COMMON_TEMPLATES -#define CSIDL_COMMON_TEMPLATES 0x002d +# define CSIDL_COMMON_TEMPLATES 0x2D #endif - -#ifndef CSIDL_PROFILE -#define CSIDL_PROFILE 0x0028 +#ifndef CSIDL_APPDATA +# define CSIDL_APPDATA 0x1A #endif - #ifndef CSIDL_COMMON_APPDATA -#define CSIDL_COMMON_APPDATA 0x0023 +# define CSIDL_COMMON_APPDATA 0x23 +#endif +#ifndef CSIDL_PRINTHOOD +# define CSIDL_PRINTHOOD 0x1B +#endif +#ifndef CSIDL_ALTSTARTUP +# define CSIDL_ALTSTARTUP 0x1D +#endif +#ifndef CSIDL_COMMON_ALTSTARTUP +# define CSIDL_COMMON_ALTSTARTUP 0x1E +#endif +#ifndef CSIDL_INTERNET_CACHE +# define CSIDL_INTERNET_CACHE 0x20 +#endif +#ifndef CSIDL_COOKIES +# define CSIDL_COOKIES 0x21 +#endif +#ifndef CSIDL_HISTORY +# define CSIDL_HISTORY 0x22 +#endif +#ifndef CSIDL_WINDOWS +# define CSIDL_WINDOWS 0x24 +#endif +#ifndef CSIDL_SYSTEM +# define CSIDL_SYSTEM 0x25 +#endif +#ifndef CSIDL_PROGRAM_FILES +# define CSIDL_PROGRAM_FILES 0x26 +#endif +#ifndef CSIDL_PROGRAM_FILES_COMMON +# define CSIDL_PROGRAM_FILES_COMMON 0x2B +#endif +#ifndef CSIDL_MYPICTURES +# define CSIDL_MYPICTURES 0x27 +#endif +#ifndef CSIDL_COMMON_PICTURES +# define CSIDL_COMMON_PICTURES 0x36 +#endif +#ifndef CSIDL_PROFILE +# define CSIDL_PROFILE 0x28 +#endif +#ifndef CSIDL_ADMINTOOLS +# define CSIDL_ADMINTOOLS 0x30 +#endif +#ifndef CSIDL_COMMON_ADMINTOOLS +# define CSIDL_COMMON_ADMINTOOLS 0x2F +#endif +#ifndef CSIDL_MYMUSIC +# define CSIDL_MYMUSIC 0xD +#endif +#ifndef CSIDL_COMMON_MUSIC +# define CSIDL_COMMON_MUSIC 0x35 +#endif +#ifndef CSIDL_MYVIDEO +# define CSIDL_MYVIDEO 0xE +#endif +#ifndef CSIDL_COMMON_VIDEO +# define CSIDL_COMMON_VIDEO 0x37 +#endif +#ifndef CSIDL_RESOURCES +# define CSIDL_RESOURCES 0x38 +#endif +#ifndef CSIDL_RESOURCES_LOCALIZED +# define CSIDL_RESOURCES_LOCALIZED 0x39 +#endif +#ifndef CSIDL_CDBURN_AREA +# define CSIDL_CDBURN_AREA 0x3B +#endif + +#ifndef CP_ACP +# define CP_ACP 0 +#endif + +#ifndef COLOR_BTNFACE +# define COLOR_BTNFACE 15 +#endif +#ifndef COLOR_WINDOW +# define COLOR_WINDOW 5 +#endif + +#ifndef RT_BITMAP +# define RT_BITMAP MAKEINTRESOURCE(2) +#endif +#ifndef RT_ICON +# define RT_ICON MAKEINTRESOURCE(3) +#endif +#ifndef RT_DIALOG +# define RT_DIALOG MAKEINTRESOURCE(5) +#endif +#ifndef RT_GROUP_ICON +# define RT_GROUP_ICON MAKEINTRESOURCE(14) +#endif +#ifndef RT_VERSION +# define RT_VERSION MAKEINTRESOURCE(16) +#endif + +// message box + +#ifndef MB_OK +# define MB_OK 0 +# define MB_OKCANCEL 1 +# define MB_ABORTRETRYIGNORE 2 +# define MB_YESNOCANCEL 3 +# define MB_YESNO 4 +# define MB_RETRYCANCEL 5 +# define MB_DEFBUTTON1 0 +# define MB_DEFBUTTON2 256 +# define MB_DEFBUTTON3 512 +# define MB_DEFBUTTON4 768 +# define MB_ICONSTOP 16 +# define MB_ICONQUESTION 32 +# define MB_ICONEXCLAMATION 48 +# define MB_ICONINFORMATION 64 +# define MB_SETFOREGROUND 0x10000 +# define MB_TOPMOST 0x40000 +# define MB_RIGHT 0x80000 +#endif + +#ifndef IDOK +# define IDOK 1 +# define IDCANCEL 2 +# define IDABORT 3 +# define IDRETRY 4 +# define IDIGNORE 5 +# define IDYES 6 +# define IDNO 7 +#endif + +// window styles + +#ifndef _WIN32 +# define WS_CHILD 0x40000000 +# define WS_VISIBLE 0x10000000 + +# define BS_CHECKBOX 2 +# define BS_LEFT 256 +# define BS_LEFTTEXT 32 +# define BS_RADIOBUTTON 4 +# define BS_RIGHT 512 +# define BS_USERBUTTON 8 + +# define ES_LEFT 0 +# define ES_CENTER 1 +# define ES_RIGHT 2 + +# define SS_BITMAP 14 +# define SS_CENTER 1 +# define SS_CENTERIMAGE 512 +# define SS_ICON 3 +# define SS_LEFT 0 +# define SS_LEFTNOWORDWRAP 0xc +# define SS_RIGHT 2 +# define SS_RIGHTJUST 0x400 +# define SS_USERITEM 10 +# define SS_TYPEMASK 0x0000001FL + +# define DS_FIXEDSYS 8 +# define DS_SETFONT 64 +# define DS_SHELLFONT (DS_SETFONT | DS_FIXEDSYS) + +# define WS_EX_RIGHT 0x1000 +# define WS_EX_RIGHTSCROLLBAR 0 +# define WS_EX_RTLREADING 0x2000 + +# define TVS_RTLREADING 64 + +# define PBS_SMOOTH 1 +#endif + +// brush styles + +#ifndef BS_SOLID +# define BS_SOLID 0 +#endif +#ifndef BS_NULL +# define BS_NULL 1 +#endif + +// reg +#ifndef HKEY_CLASSES_ROOT +# define HKEY_CLASSES_ROOT ((HKEY)0x80000000) +# define HKEY_CURRENT_USER ((HKEY)0x80000001) +# define HKEY_LOCAL_MACHINE ((HKEY)0x80000002) +# define HKEY_USERS ((HKEY)0x80000003) +# define HKEY_PERFORMANCE_DATA ((HKEY)0x80000004) +# define HKEY_CURRENT_CONFIG ((HKEY)0x80000005) +# define HKEY_DYN_DATA ((HKEY)0x80000006) +#endif + +// show modes + +#ifndef SW_SHOWNORMAL +# define SW_HIDE 0 +# define SW_SHOWNORMAL 1 +# define SW_SHOWMINIMIZED 2 +# define SW_SHOWMAXIMIZED 3 +# define SW_SHOWNOACTIVATE 4 +# define SW_SHOWMINNOACTIVE 7 +# define SW_SHOWNA 8 +#endif + +// hotkeys + +#ifndef HOTKEYF_SHIFT +# define HOTKEYF_SHIFT 1 +# define HOTKEYF_CONTROL 2 +# define HOTKEYF_ALT 4 +# define HOTKEYF_EXT 8 +#endif + +// vk +#ifndef VK_F1 +# define VK_F1 0x70 +#endif + +// gdi + +#ifndef OPAQUE +# define OPAQUE 2 +#endif +#ifndef TRANSPARENT +# define TRANSPARENT 1 +#endif + +// file ops + +#ifndef FOF_SILENT +# define FOF_SILENT 4 +# define FOF_NOCONFIRMATION 16 +# define FOF_FILESONLY 128 +# define FOF_SIMPLEPROGRESS 256 +# define FOF_NOCONFIRMMKDIR 512 +#endif + +// file attribs + +#ifndef FILE_ATTRIBUTE_READONLY +# define FILE_ATTRIBUTE_READONLY 0x00000001 +# define FILE_ATTRIBUTE_HIDDEN 0x00000002 +# define FILE_ATTRIBUTE_SYSTEM 0x00000004 +# define FILE_ATTRIBUTE_ARCHIVE 0x00000020 +# define FILE_ATTRIBUTE_NORMAL 0x00000080 +# define FILE_ATTRIBUTE_TEMPORARY 0x00000100 +# define FILE_ATTRIBUTE_OFFLINE 0x00001000 +#endif + +// registry + +#ifndef REG_SZ +# define REG_SZ 1 +# define REG_EXPAND_SZ 2 +# define REG_BINARY 3 +# define REG_DWORD 4 +#endif + +// fopen +#ifndef GENERIC_READ +# define GENERIC_READ 0x80000000 +# define GENERIC_WRITE 0x40000000 +#endif + +#ifndef CREATE_NEW +# define CREATE_NEW 1 +# define CREATE_ALWAYS 2 +# define OPEN_EXISTING 3 +# define OPEN_ALWAYS 4 +#endif + +// fseek + +#ifndef FILE_BEGIN +# define FILE_BEGIN 0 +# define FILE_CURRENT 1 +# define FILE_END 2 +#endif + +// PE + +#ifndef _WIN32 +# define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16 +# define IMAGE_DOS_SIGNATURE 0x5A4D +# define IMAGE_NT_SIGNATURE 0x00004550 +# define IMAGE_FILE_DLL 8192 +# define IMAGE_DIRECTORY_ENTRY_EXPORT 0 +# define IMAGE_SIZEOF_SHORT_NAME 8 +#endif + +// structures + +#ifndef _WIN32 +# pragma pack(2) +typedef struct _IMAGE_DOS_HEADER { + WORD e_magic; + WORD e_cblp; + WORD e_cp; + WORD e_crlc; + WORD e_cparhdr; + WORD e_minalloc; + WORD e_maxalloc; + WORD e_ss; + WORD e_sp; + WORD e_csum; + WORD e_ip; + WORD e_cs; + WORD e_lfarlc; + WORD e_ovno; + WORD e_res[4]; + WORD e_oemid; + WORD e_oeminfo; + WORD e_res2[10]; + LONG e_lfanew; +} IMAGE_DOS_HEADER,*PIMAGE_DOS_HEADER; +# pragma pack(4) +typedef struct _IMAGE_FILE_HEADER { + WORD Machine; + WORD NumberOfSections; + DWORD TimeDateStamp; + DWORD PointerToSymbolTable; + DWORD NumberOfSymbols; + WORD SizeOfOptionalHeader; + WORD Characteristics; +} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER; +typedef struct _IMAGE_DATA_DIRECTORY { + DWORD VirtualAddress; + DWORD Size; +} IMAGE_DATA_DIRECTORY,*PIMAGE_DATA_DIRECTORY; +typedef struct _IMAGE_OPTIONAL_HEADER { + WORD Magic; + BYTE MajorLinkerVersion; + BYTE MinorLinkerVersion; + DWORD SizeOfCode; + DWORD SizeOfInitializedData; + DWORD SizeOfUninitializedData; + DWORD AddressOfEntryPoint; + DWORD BaseOfCode; + DWORD BaseOfData; + DWORD ImageBase; + DWORD SectionAlignment; + DWORD FileAlignment; + WORD MajorOperatingSystemVersion; + WORD MinorOperatingSystemVersion; + WORD MajorImageVersion; + WORD MinorImageVersion; + WORD MajorSubsystemVersion; + WORD MinorSubsystemVersion; + DWORD Reserved1; + DWORD SizeOfImage; + DWORD SizeOfHeaders; + DWORD CheckSum; + WORD Subsystem; + WORD DllCharacteristics; + DWORD SizeOfStackReserve; + DWORD SizeOfStackCommit; + DWORD SizeOfHeapReserve; + DWORD SizeOfHeapCommit; + DWORD LoaderFlags; + DWORD NumberOfRvaAndSizes; + IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; +} IMAGE_OPTIONAL_HEADER,*PIMAGE_OPTIONAL_HEADER; +typedef struct _IMAGE_NT_HEADERS { + DWORD Signature; + IMAGE_FILE_HEADER FileHeader; + IMAGE_OPTIONAL_HEADER OptionalHeader; +} IMAGE_NT_HEADERS,*PIMAGE_NT_HEADERS; +typedef struct _IMAGE_SECTION_HEADER { + BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; + union { + DWORD PhysicalAddress; + DWORD VirtualSize; + } Misc; + DWORD VirtualAddress; + DWORD SizeOfRawData; + DWORD PointerToRawData; + DWORD PointerToRelocations; + DWORD PointerToLinenumbers; + WORD NumberOfRelocations; + WORD NumberOfLinenumbers; + DWORD Characteristics; +} IMAGE_SECTION_HEADER,*PIMAGE_SECTION_HEADER; +typedef struct _IMAGE_EXPORT_DIRECTORY { + DWORD Characteristics; + DWORD TimeDateStamp; + WORD MajorVersion; + WORD MinorVersion; + DWORD Name; + DWORD Base; + DWORD NumberOfFunctions; + DWORD NumberOfNames; + DWORD AddressOfFunctions; + DWORD AddressOfNames; + DWORD AddressOfNameOrdinals; +} IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY; +# pragma pack() #endif #endif diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index edc4e7c2..a5df537a 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -3,12 +3,18 @@ #include "Plugins.h" #include "Platform.h" -#include +#include "util.h" +#ifdef _WIN32 +# include +#else +# include +# include +#endif extern FILE *g_output; -void Plugins::FindCommands(char* path,bool displayInfo) +void Plugins::FindCommands(char* path, bool displayInfo) { if (path) { @@ -16,11 +22,8 @@ void Plugins::FindCommands(char* path,bool displayInfo) if (length > 0) { - WIN32_FIND_DATA data; - HANDLE handle; - - if (path[length-1] == '\\' || - path[length-1] == '/') + char *lc = CharPrev(path, path + strlen(path)); + if (*lc == '\\' || *lc == '/') { length--; } @@ -31,21 +34,49 @@ void Plugins::FindCommands(char* path,bool displayInfo) char* pathAndWildcard = new char [length+7]; strcpy(pathAndWildcard,basePath); - strcat(pathAndWildcard,"\\*.dll"); + strcat(pathAndWildcard,PATH_SEPARATOR_STR "*.dll"); + +#ifdef _WIN32 + WIN32_FIND_DATA data; + HANDLE handle; handle = FindFirstFile(pathAndWildcard,&data); if (handle != INVALID_HANDLE_VALUE) { do +#else + glob_t globbuf; + globbuf.gl_offs = 0; + globbuf.gl_pathc = 0; + if (!glob(pathAndWildcard, 0, NULL, &globbuf)) + { + struct stat s; + for (unsigned int i = 0; i < globbuf.gl_pathc; i++) + { + if (stat(globbuf.gl_pathv[i], &s) || !S_ISREG(s.st_mode)) + continue; +#endif +#ifdef _WIN32 { char* dllPath = new char [length+strlen(data.cFileName)+2]; - wsprintf(dllPath,"%s\\%s",basePath,data.cFileName); + wsprintf(dllPath,"%s" PATH_SEPARATOR_STR "%s",basePath,data.cFileName); +#else + char *dllPath = new char [strlen(globbuf.gl_pathv[i])+1]; + strcpy(dllPath,globbuf.gl_pathv[i]); +#endif GetExports(dllPath,displayInfo); delete[] dllPath; - } while (FindNextFile(handle,&data)); + } +#ifdef _WIN32 + while (FindNextFile(handle,&data)); +#else + globfree(&globbuf); +#endif } +#ifdef _WIN32 delete[] pathAndWildcard; +#endif delete[] basePath; } } @@ -58,24 +89,19 @@ void Plugins::GetExports(char* pathToDll, bool displayInfo) unsigned char* dlldata = 0; long dlldatalen = 0; bool loaded = false; - char dllName[100]; - char signature[256]; + char dllName[1024]; + char signature[1024]; dllName[0] = 0; - char* ptr = strrchr(pathToDll,'\\'); + char* ptr = strrchr(pathToDll,PATH_SEPARATOR_C); if (ptr && *ptr && *(ptr+1)) strcpy(dllName,ptr+1); // find .dll - char *dllName2 = strdup(dllName); - for (ptr = dllName2; *ptr; ptr = CharNext(ptr)) + int len = strlen(dllName); + if (len > 4 && !stricmp(dllName + len - 4, ".dll")) { - if (!strcmpi(ptr, ".dll")) - { - *(dllName + (ptr - dllName2)) = 0; - break; - } + dllName[len - 4] = 0; } - free(dllName2); FILE* dll = fopen(pathToDll,"rb"); if (dll) diff --git a/Source/ResourceEditor.cpp b/Source/ResourceEditor.cpp index aa91cab5..6d11b0ce 100644 --- a/Source/ResourceEditor.cpp +++ b/Source/ResourceEditor.cpp @@ -20,8 +20,14 @@ 3. This notice may not be removed or altered from any source distribution. */ -#define RESOURCE_EDITOR_NOT_API #include "ResourceEditor.h" +#include "util.h" +#include +#include + +#ifndef _WIN32 +# include +#endif ////////////////////////////////////////////////////////////////////// // Utilities @@ -195,7 +201,9 @@ BYTE* CResourceEditor::GetResource(char* szType, char* szName, LANGID wLanguage) i = nameDir->Find(szName); if (i > -1) { langDir = nameDir->GetEntry(i)->GetSubDirectory(); - i = langDir->Find(wLanguage); + i = 0; + if (wLanguage) + i = langDir->Find(wLanguage); if (i > -1) { data = langDir->GetEntry(i)->GetDataEntry(); } @@ -208,7 +216,7 @@ BYTE* CResourceEditor::GetResource(char* szType, char* szName, LANGID wLanguage) return toReturn; } else - return 0; + return NULL; } void CResourceEditor::FreeResource(BYTE* pbResource) @@ -381,29 +389,47 @@ CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, P // Go through all entries of this resource directory for (int i = 0; i < rdToScan->Header.NumberOfNamedEntries + rdToScan->Header.NumberOfIdEntries; i++) { // If this entry points to data entry get a pointer to it - if (!rdToScan->Entries[i].DataIsDirectory) + if (!rdToScan->Entries[i].DirectoryOffset.DataIsDirectory) rde = PIMAGE_RESOURCE_DATA_ENTRY(rdToScan->Entries[i].OffsetToData + (BYTE*)rdRoot); // If this entry has a name, translate it from Unicode - if (rdToScan->Entries[i].NameIsString) { - PIMAGE_RESOURCE_DIR_STRING_U rds = PIMAGE_RESOURCE_DIR_STRING_U(rdToScan->Entries[i].NameOffset + (char*)rdRoot); + if (rdToScan->Entries[i].NameString.NameIsString) { + PIMAGE_RESOURCE_DIR_STRING_U rds = PIMAGE_RESOURCE_DIR_STRING_U(rdToScan->Entries[i].NameString.NameOffset + (char*)rdRoot); +#ifdef _WIN32 int mbsSize = WideCharToMultiByte(CP_ACP, 0, rds->NameString, rds->Length, 0, 0, 0, 0); szName = new char[mbsSize+1]; WideCharToMultiByte(CP_ACP, 0, rds->NameString, rds->Length, szName, mbsSize, 0, 0); szName[mbsSize] = 0; +#else + { + iconv_t cd = iconv_open("", "UCS-2"); + if (cd != (iconv_t) -1) + { + char *in = (char *) rds->NameString; + char *out = szName = new char[rds->Length * 2 + 1]; + size_t insize = rds->Length; + size_t outsize = rds->Length * 2 + 1; + if (__iconv_adaptor(iconv, cd, &in, &insize, &out, &outsize) == (size_t) -1) + throw runtime_error("Unicode conversion failed"); + iconv_close(cd); + } + else + throw runtime_error("Unicode conversion failed"); + } +#endif } // Else, set the name to this entry's id else szName = MAKEINTRESOURCE(rdToScan->Entries[i].Id); - if (rdToScan->Entries[i].DataIsDirectory) + if (rdToScan->Entries[i].DirectoryOffset.DataIsDirectory) rdc->AddEntry( new CResourceDirectoryEntry( szName, ScanDirectory( rdRoot, - PRESOURCE_DIRECTORY(rdToScan->Entries[i].OffsetToDirectory + (BYTE*)rdRoot) + PRESOURCE_DIRECTORY(rdToScan->Entries[i].DirectoryOffset.OffsetToDirectory + (BYTE*)rdRoot) ) ) ); @@ -457,14 +483,15 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) { qDataEntries2.push(crd->GetEntry(i)->GetDataEntry()); } - IMAGE_RESOURCE_DIRECTORY_ENTRY rDirE = {{0}}; - rDirE.DataIsDirectory = crd->GetEntry(i)->IsDataDirectory(); + MY_IMAGE_RESOURCE_DIRECTORY_ENTRY rDirE; + ZeroMemory(&rDirE, sizeof(rDirE)); + rDirE.DirectoryOffset.DataIsDirectory = crd->GetEntry(i)->IsDataDirectory(); rDirE.Id = (crd->GetEntry(i)->HasName()) ? 0 : crd->GetEntry(i)->GetId(); - rDirE.NameIsString = (crd->GetEntry(i)->HasName()) ? 1 : 0; + rDirE.NameString.NameIsString = (crd->GetEntry(i)->HasName()) ? 1 : 0; - CopyMemory(seeker, &rDirE, sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)); + CopyMemory(seeker, &rDirE, sizeof(MY_IMAGE_RESOURCE_DIRECTORY_ENTRY)); crd->GetEntry(i)->m_dwWrittenAt = DWORD(seeker); - seeker += sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); + seeker += sizeof(MY_IMAGE_RESOURCE_DIRECTORY_ENTRY); } qDirs.pop(); } @@ -491,13 +518,36 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) { while (!qStrings.empty()) { CResourceDirectoryEntry* cRDirE = qStrings.front(); - PIMAGE_RESOURCE_DIRECTORY_ENTRY(cRDirE->m_dwWrittenAt)->NameOffset = DWORD(seeker) - DWORD(pbRsrcSec); + PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(cRDirE->m_dwWrittenAt)->NameString.NameOffset = DWORD(seeker) - DWORD(pbRsrcSec); char* szName = cRDirE->GetName(); - WORD iLen = lstrlen(szName); - WCHAR* szwName = new WCHAR[iLen+1]; + WORD iLen = strlen(szName); + WCHAR *szwName = new WCHAR[iLen + 1]; +#ifdef _WIN32 // MultiByteToWideChar return value includes the null char, so -1 iLen = MultiByteToWideChar(CP_ACP, 0, szName, iLen, szwName, iLen) - 1; +#else + { + iconv_t cd = iconv_open("UCS-2", ""); + if (cd != (iconv_t) -1) + { + char *in = szName; + char *out = (char *) szwName; + size_t insize = iLen + 1; + size_t outsize = (iLen + 1) * sizeof(unsigned short); + if (__iconv_adaptor(iconv, cd, &in, &insize, &out, &outsize) == (size_t) -1) + iLen = (WORD) -1; + else + iLen = (WORD) ((int) out - (int) szwName - 1); + iconv_close(cd); + } + else + iLen = (WORD) -1; + } +#endif + if (iLen == (WORD) -1) + throw runtime_error("Unicode conversion failed"); + *(WORD*)seeker = iLen; seeker += sizeof(WORD); CopyMemory(seeker, szwName, iLen*sizeof(WCHAR)); @@ -536,12 +586,12 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) { void CResourceEditor::SetOffsets(CResourceDirectory* resDir, DWORD newResDirAt) { for (int i = 0; i < resDir->CountEntries(); i++) { if (resDir->GetEntry(i)->IsDataDirectory()) { - PIMAGE_RESOURCE_DIRECTORY_ENTRY(resDir->GetEntry(i)->m_dwWrittenAt)->DataIsDirectory = 1; - PIMAGE_RESOURCE_DIRECTORY_ENTRY(resDir->GetEntry(i)->m_dwWrittenAt)->OffsetToDirectory = resDir->GetEntry(i)->GetSubDirectory()->m_dwWrittenAt - newResDirAt; + PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(resDir->GetEntry(i)->m_dwWrittenAt)->DirectoryOffset.DataIsDirectory = 1; + PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(resDir->GetEntry(i)->m_dwWrittenAt)->DirectoryOffset.OffsetToDirectory = resDir->GetEntry(i)->GetSubDirectory()->m_dwWrittenAt - newResDirAt; SetOffsets(resDir->GetEntry(i)->GetSubDirectory(), newResDirAt); } else { - PIMAGE_RESOURCE_DIRECTORY_ENTRY(resDir->GetEntry(i)->m_dwWrittenAt)->OffsetToData = resDir->GetEntry(i)->GetDataEntry()->m_dwWrittenAt - newResDirAt; + PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(resDir->GetEntry(i)->m_dwWrittenAt)->OffsetToData = resDir->GetEntry(i)->GetDataEntry()->m_dwWrittenAt - newResDirAt; } } } @@ -587,7 +637,7 @@ void CResourceDirectory::AddEntry(CResourceDirectoryEntry* entry) { char* szEntName = entry->GetName(); for (i = 0; i < m_rdDir.NumberOfIdEntries; i++) { char* szName = m_vEntries[i]->GetName(); - int cmp = lstrcmp(szName, szEntName); + int cmp = strcmp(szName, szEntName); delete [] szName; if (cmp == 0) { delete [] szEntName; @@ -639,7 +689,7 @@ int CResourceDirectory::Find(char* szName) { continue; char* szEntName = m_vEntries[i]->GetName(); - int cmp = lstrcmp(szName, szEntName); + int cmp = strcmp(szName, szEntName); delete [] szEntName; if (!cmp) @@ -667,7 +717,7 @@ int CResourceDirectory::Find(WORD wId) { DWORD CResourceDirectory::GetSize() { DWORD dwSize = sizeof(IMAGE_RESOURCE_DIRECTORY); for (unsigned int i = 0; i < m_vEntries.size(); i++) { - dwSize += sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); + dwSize += sizeof(MY_IMAGE_RESOURCE_DIRECTORY_ENTRY); if (m_vEntries[i]->HasName()) dwSize += sizeof(IMAGE_RESOURCE_DIR_STRING_U) + (m_vEntries[i]->GetNameLength()+1)*sizeof(WCHAR); if (m_vEntries[i]->IsDataDirectory()) @@ -711,8 +761,8 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(char* szName, CResourceDirector } else { m_bHasName = true; - m_szName = new char[lstrlen(szName)+1]; - lstrcpy(m_szName, szName); + m_szName = new char[strlen(szName)+1]; + strcpy(m_szName, szName); } m_bIsDataDirectory = true; m_rdSubDir = rdSubDir; @@ -726,8 +776,8 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(char* szName, CResourceDataEntr } else { m_bHasName = true; - m_szName = new char[lstrlen(szName)+1]; - lstrcpy(m_szName, szName); + m_szName = new char[strlen(szName)+1]; + strcpy(m_szName, szName); } m_bIsDataDirectory = false; m_rdeData = rdeData; @@ -751,13 +801,13 @@ char* CResourceDirectoryEntry::GetName() { if (!m_bHasName) return 0; char* szName = 0; - szName = new char[lstrlen(m_szName)+1]; - lstrcpy(szName, m_szName); + szName = new char[strlen(m_szName)+1]; + strcpy(szName, m_szName); return szName; } int CResourceDirectoryEntry::GetNameLength() { - return lstrlen(m_szName); + return strlen(m_szName); } WORD CResourceDirectoryEntry::GetId() { diff --git a/Source/ResourceEditor.h b/Source/ResourceEditor.h index 65d02b11..a2ccc30f 100644 --- a/Source/ResourceEditor.h +++ b/Source/ResourceEditor.h @@ -27,17 +27,61 @@ #pragma once #endif // _MSC_VER > 1000 -#ifdef RESOURCE_EDITOR_NOT_API - #include "Platform.h" -#include -#include -#include -#include +#include +#ifdef _WIN32 +# include +#else +// all definitions for non Win32 platforms were taken from MinGW's free Win32 library +# define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 +# define IMAGE_SCN_MEM_DISCARDABLE 0x2000000 +# pragma pack(4) +typedef struct _IMAGE_RESOURCE_DIRECTORY { + DWORD Characteristics; + DWORD TimeDateStamp; + WORD MajorVersion; + WORD MinorVersion; + WORD NumberOfNamedEntries; + WORD NumberOfIdEntries; +} IMAGE_RESOURCE_DIRECTORY,*PIMAGE_RESOURCE_DIRECTORY; +typedef struct _IMAGE_RESOURCE_DATA_ENTRY { + DWORD OffsetToData; + DWORD Size; + DWORD CodePage; + DWORD Reserved; +} IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY; +typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING { + WORD Length; + CHAR NameString[1]; +} IMAGE_RESOURCE_DIRECTORY_STRING,*PIMAGE_RESOURCE_DIRECTORY_STRING; +typedef struct _IMAGE_RESOURCE_DIR_STRING_U { + WORD Length; + WCHAR NameString[1]; +} IMAGE_RESOURCE_DIR_STRING_U,*PIMAGE_RESOURCE_DIR_STRING_U; +#endif -#endif // #ifdef RESOURCE_EDITOR_NOT_API +#pragma pack(4) +typedef struct _MY_IMAGE_RESOURCE_DIRECTORY_ENTRY { + union { + struct { + DWORD NameOffset:31; + DWORD NameIsString:1; + } NameString; + DWORD Name; + WORD Id; + }; + union { + DWORD OffsetToData; + struct { + DWORD OffsetToDirectory:31; + DWORD DataIsDirectory:1; + } DirectoryOffset; + }; +} MY_IMAGE_RESOURCE_DIRECTORY_ENTRY,*PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY; -#include +#pragma pack() + +#include using namespace std; class CResourceDirectory; @@ -47,7 +91,7 @@ class CResourceDataEntry; // Resource directory with entries typedef struct RESOURCE_DIRECTORY { IMAGE_RESOURCE_DIRECTORY Header; - IMAGE_RESOURCE_DIRECTORY_ENTRY Entries[1]; + MY_IMAGE_RESOURCE_DIRECTORY_ENTRY Entries[1]; } *PRESOURCE_DIRECTORY; class CResourceEditor { @@ -83,8 +127,6 @@ private: void SetOffsets(CResourceDirectory* resDir, DWORD newResDirAt); }; -#ifdef RESOURCE_EDITOR_NOT_API - class CResourceDirectory { public: CResourceDirectory(PIMAGE_RESOURCE_DIRECTORY prd); @@ -164,6 +206,4 @@ private: DWORD m_dwCodePage; }; -#endif // #ifdef RESOURCE_EDITOR_NOT_API - #endif // !defined(AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_) diff --git a/Source/ResourceVersionInfo.cpp b/Source/ResourceVersionInfo.cpp index 4a79e3b5..ea10ed47 100644 --- a/Source/ResourceVersionInfo.cpp +++ b/Source/ResourceVersionInfo.cpp @@ -2,11 +2,24 @@ // ////////////////////////////////////////////////////////////////////// -#include "Platform.h" -#include "build.h" - #include "ResourceVersionInfo.h" + +#include "Platform.h" +#include "util.h" + #ifdef NSIS_SUPPORT_VERSION_INFO + +#ifndef VOS__WINDOWS32 +# define VOS__WINDOWS32 4 +#endif +#ifndef VFT_APP +# define VFT_APP 1 +#endif + +#ifndef _WIN32 +# include +#endif + /* int ValidCodePages[] = { 437, 708, 709, 710, 720, 737, 775, 850, 852, 855, 85, 86, 86, 86, 86, 864, @@ -74,10 +87,33 @@ void CResourceVersionInfo::SetProductVersion(int HighPart, int LowPart) // Util function - must be freeded WCHAR* StrToWstrAlloc(const char* istr, int codepage) { +#ifdef _WIN32 int strSize = MultiByteToWideChar(codepage, 0, istr, -1, 0, 0); WCHAR* wstr = new WCHAR[strSize]; MultiByteToWideChar(codepage, 0, istr, -1, wstr, strSize); return wstr; +#else + WCHAR *wstr = NULL; + char cp[128] = ""; + if (codepage != CP_ACP) + snprintf(cp, 128, "CP%d", codepage); + iconv_t cd = iconv_open("UCS-2", cp); + if (cd != (iconv_t) -1) + { + int len = strlen(istr); + char *in = (char *) istr; + char *out = (char *) wstr = new WCHAR[len + 1]; + size_t insize = len + 1; + size_t outsize = (len + 1) * sizeof(WCHAR); + if (__iconv_adaptor(iconv, cd, &in, &insize, &out, &outsize) == (size_t) -1) + { + delete [] wstr; + wstr = NULL; + } + iconv_close(cd); + } + return wstr; +#endif } int GetVersionHeader (LPSTR &p, WORD &wLength, WORD &wValueLength, WORD &wType) @@ -93,7 +129,7 @@ int GetVersionHeader (LPSTR &p, WORD &wLength, WORD &wValueLength, WORD &wType) wType = *(WORD*)p; p += sizeof(WORD); szKey = (WCHAR*)p; - p += (wcslen(szKey) + 1) * sizeof (WCHAR); + p += (WCStrLen(szKey)) * sizeof (WCHAR); while ( ((long)p % 4) != 0 ) p++; return p - baseP; @@ -116,7 +152,7 @@ void SaveVersionHeader (GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wTy strm.add (&wValueLength, sizeof (wValueLength)); strm.add (&wType, sizeof (wType)); - keyLen = (wcslen(key) + 1) * sizeof (WCHAR); + keyLen = (WCStrLen(key)) * sizeof (WCHAR); strm.add ((void*)key, keyLen); PadStream(strm); @@ -138,7 +174,9 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) WCHAR *KeyName, *KeyValue; strm.resize(0); - SaveVersionHeader (strm, 0, sizeof (VS_FIXEDFILEINFO), 0, L"VS_VERSION_INFO", &m_FixedInfo); + KeyName = StrToWstrAlloc("VS_VERSION_INFO", CP_ACP); + SaveVersionHeader (strm, 0, sizeof (VS_FIXEDFILEINFO), 0, KeyName, &m_FixedInfo); + delete [] KeyName; DefineList *pChildStrings = m_ChildStringLists.get_strings(Index); if ( pChildStrings->getnum() > 0 ) @@ -159,7 +197,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) p = stringInfoStream.getlen(); KeyName = StrToWstrAlloc(pChildStrings->getname(i), codepage); KeyValue = StrToWstrAlloc(pChildStrings->getvalue(i), codepage); - SaveVersionHeader (stringInfoStream, 0, wcslen(KeyValue) + 1, 1, KeyName, (void*)KeyValue); + SaveVersionHeader (stringInfoStream, 0, WCStrLen(KeyValue), 1, KeyName, (void*)KeyValue); delete [] KeyName; delete [] KeyValue; wSize = stringInfoStream.getlen() - p; @@ -172,7 +210,9 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) PadStream (strm); p = strm.getlen(); - SaveVersionHeader (strm, 0, 0, 0, L"StringFileInfo", &ZEROS); + KeyName = StrToWstrAlloc("StringFileInfo", CP_ACP); + SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS); + delete [] KeyName; strm.add (stringInfoStream.get(), stringInfoStream.getlen()); wSize = strm.getlen() - p; @@ -184,11 +224,15 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) { PadStream (strm); p = strm.getlen(); - SaveVersionHeader (strm, 0, 0, 0, L"VarFileInfo", &ZEROS); + KeyName = StrToWstrAlloc("VarFileInfo", CP_ACP); + SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS); + delete [] KeyName; PadStream (strm); p1 = strm.getlen(); - SaveVersionHeader (strm, 0, 0, 0, L"Translation", &ZEROS); + KeyName = StrToWstrAlloc("Translation", CP_ACP); + SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS); + delete [] KeyName; // First add selected code language translation v = MAKELONG(m_ChildStringLists.get_lang(Index), m_ChildStringLists.get_codepage(Index)); diff --git a/Source/ResourceVersionInfo.h b/Source/ResourceVersionInfo.h index f0cc4775..ff86c757 100644 --- a/Source/ResourceVersionInfo.h +++ b/Source/ResourceVersionInfo.h @@ -9,10 +9,29 @@ #pragma once #endif // _MSC_VER > 1000 +#include "exehead/config.h" #ifdef NSIS_SUPPORT_VERSION_INFO -#include -using namespace std; +#include "Platform.h" +#include "strlist.h" +#ifndef _WIN32 +// all definitions for non Win32 platforms were taken from MinGW's free Win32 library +typedef struct tagVS_FIXEDFILEINFO { + DWORD dwSignature; + DWORD dwStrucVersion; + DWORD dwFileVersionMS; + DWORD dwFileVersionLS; + DWORD dwProductVersionMS; + DWORD dwProductVersionLS; + DWORD dwFileFlagsMask; + DWORD dwFileFlags; + DWORD dwFileOS; + DWORD dwFileType; + DWORD dwFileSubtype; + DWORD dwFileDateMS; + DWORD dwFileDateLS; +} VS_FIXEDFILEINFO; +#endif struct version_string_list { int codepage; diff --git a/Source/ShConstants.h b/Source/ShConstants.h index 419ddea9..928123e9 100644 --- a/Source/ShConstants.h +++ b/Source/ShConstants.h @@ -3,7 +3,7 @@ #ifndef ___CONSTANTS___H_____ #define ___CONSTANTS___H_____ -#include "Lang.h" +#include "lang.h" struct constantstring { int name; diff --git a/Source/build.cpp b/Source/build.cpp index 65be44ad..6e3811c5 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -12,18 +12,29 @@ #include "ResourceEditor.h" #include "DialogTemplate.h" #include "ResourceVersionInfo.h" -#include + +#ifndef _WIN32 +# include +# include +# include +# include +#endif int MMapFile::m_iAllocationGranularity = 0; #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT +#ifdef _WIN32 DWORD WINAPI lzmaCompressThread(LPVOID lpParameter) +#else +void *lzmaCompressThread(void *lpParameter) +#endif { CLZMA *Compressor = (CLZMA *) lpParameter; if (!Compressor) return 0; - return Compressor->CompressReal(); + Compressor->CompressReal(); + return 0; } #endif @@ -226,19 +237,6 @@ CEXEBuild::CEXEBuild() #ifdef NSIS_ZLIB_COMPRESS_WHOLE definedlist.add("NSIS_ZLIB_COMPRESS_WHOLE"); #endif - - // Added by Amir Szekely 11th July 2002 - // Coded by Robert Rainwater - { - char szNSISDir[NSIS_MAX_STRLEN],*fn2; - GetModuleFileName(NULL,szNSISDir,sizeof(szNSISDir)-sizeof("\\Include")); - fn2=strrchr(szNSISDir,'\\'); - if(fn2!=NULL) *fn2=0; - definedlist.add("NSISDIR",(char*)szNSISDir); - lstrcat(szNSISDir, "\\Include"); - include_dirs.add(szNSISDir,0); - } - #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 definedlist.add("NSIS_SUPPORT_STANDARD_PREDEFINES"); @@ -380,7 +378,7 @@ definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS"); plugins_processed=0; #endif - last_used_lang=MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); + last_used_lang=NSIS_DEFAULT_LANG; res_editor=0; @@ -391,7 +389,9 @@ definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS"); disable_window_icon=0; +#ifdef _WIN32 notify_hwnd=0; +#endif defcodepage_set=false; uDefCodePage=CP_ACP; @@ -456,6 +456,60 @@ definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS"); m_ShellConstants.add("CDBURN_AREA", CSIDL_CDBURN_AREA, CSIDL_CDBURN_AREA); } +void CEXEBuild::setdirs(char *argv0) +{ + char szNSISDir[NSIS_MAX_STRLEN],*fn2; +#ifdef _WIN32 + GetModuleFileName(NULL,szNSISDir,sizeof(szNSISDir)-sizeof(PATH_SEPARATOR_STR "Include")); +#else + if (argv0[0] == '.' || argv0[0] == PATH_SEPARATOR_C) + { + getcwd(szNSISDir,sizeof(szNSISDir)-strlen(argv0)-2); + if (szNSISDir[strlen(szNSISDir)-1]!=PATH_SEPARATOR_C) + strcat(szNSISDir,PATH_SEPARATOR_STR); + strcat(szNSISDir,argv0); + } + else + { + char *path = getenv("PATH"); + if (path) + { + char *p = path; + char *l = path; + char *e = path + strlen(path); + while (p <= e) + { + if (*p == ':' || !*p) + { + *p = 0; + strncpy(szNSISDir,l,sizeof(szNSISDir)-strlen(argv0)-2); + if (szNSISDir[strlen(szNSISDir)-1]!=PATH_SEPARATOR_C) + strcat(szNSISDir,PATH_SEPARATOR_STR); + strcat(szNSISDir,argv0); + struct stat st; + if (!stat(szNSISDir,&st)) + break; + szNSISDir[0]=0; + l = ++p; + } + p = CharNext(p); + } + } + } +#if defined(MAX_PATH) && (NSIS_MAX_STRLEN >= MAX_PATH) + const char buf[NSIS_MAX_STRLEN]; + strcpy(buf, szNSISDir); + realpath(buf, szNSISDir); +#endif +#endif + fn2=strrchr(szNSISDir,PATH_SEPARATOR_C); + if(fn2!=NULL) *fn2=0; + definedlist.add("NSISDIR",(char*)szNSISDir); + strcat(szNSISDir, PATH_SEPARATOR_STR "Include"); + include_dirs.add(szNSISDir,0); +} + + int CEXEBuild::getcurdbsize() { return cur_datablock->getlen(); } // returns offset in stringblock @@ -484,8 +538,12 @@ int CEXEBuild::add_string(const char *string, int process/*=1*/, WORD codepage/* int CEXEBuild::add_intstring(const int i) // returns offset in stringblock { - char i_str[64]; + char i_str[128]; +#ifdef _WIN32 wsprintf(i_str, "%d", i); +#else + snprintf(i_str, 128, "%d", i); +#endif return add_string(i_str); } @@ -495,11 +553,25 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A const char *p=in; while (*p) { - const char *np=CharNextExA(codepage, p, 0); - - if (np-p > 1) // multibyte char + const char *np; +#ifdef _WIN32 + np = CharNextExA(codepage, p, 0); +#else { - int l=np-p; + char buf[1024]; + snprintf(buf, 1024, "CP%d", codepage); + setlocale(LC_CTYPE, buf); + int len = mblen(p, strlen(p)); + if (len > 0) + np = p + len; + else + np = p + 1; + setlocale(LC_CTYPE, ""); + } +#endif + if (np - p > 1) // multibyte char + { + int l = np - p; while (l--) { int i = (unsigned char)*p++; @@ -510,9 +582,9 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A } continue; } - + int i = (unsigned char)*p; - + p=np; // Test for characters extending into the variable codes @@ -674,12 +746,13 @@ int CEXEBuild::datablock_optimize(int start_offset) 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, l); + void *oldstuff = db->getmore(pos + this_len - left, &la); int res = memcmp(newstuff, oldstuff, l); - db->release(oldstuff); + db->release(oldstuff, la); db->release(); if (res) @@ -1168,8 +1241,12 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/ if (defname[0]) { - char buf[32]; + char buf[128]; +#ifdef _WIN32 wsprintf(buf, "%d", cur_header->blocks[NB_SECTIONS].num); +#else + snprintf(buf, 128, "%d", cur_header->blocks[NB_SECTIONS].num); +#endif if (definedlist.add(defname, buf)) { ERROR_MSG("Error: \"%s\" already defined, can't assign section index!\n", defname); @@ -1353,7 +1430,6 @@ int CEXEBuild::resolve_instruction(const char *fn, const char *str, entry *w, in #ifdef NSIS_SUPPORT_STROPTS else if (w->which == EW_GETFUNCTIONADDR) { - char buf[32]; if (w->offsets[1] < 0) { ERROR_MSG("Error: GetFunctionAddress requires a real function to get address of.\n"); @@ -1363,16 +1439,13 @@ int CEXEBuild::resolve_instruction(const char *fn, const char *str, entry *w, in if (resolve_call_int(fn,str,w->offsets[1],&w->offsets[1])) return 1; w->which=EW_ASSIGNVAR; - wsprintf(buf,"%d",w->offsets[1]+1); // +1 here to make 1-based. - w->offsets[1]=add_string(buf); + w->offsets[1]=add_intstring(w->offsets[1]+1); // +1 here to make 1-based. } else if (w->which == EW_GETLABELADDR) { - char buf[32]; if (resolve_jump_int(fn,&w->offsets[1],offs,start,end)) return 1; w->which=EW_ASSIGNVAR; - wsprintf(buf,"%d",w->offsets[1]); - w->offsets[1]=add_string(buf); + w->offsets[1]=add_intstring(w->offsets[1]); } #endif return 0; @@ -1978,7 +2051,7 @@ again: SCRIPT_MSG("Done!\n"); #define REMOVE_ICON(id) if (disable_window_icon) { \ - BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); \ + BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \ if (dlg) { \ CDialogTemplate dt(dlg,uDefCodePage); \ free(dlg); \ @@ -1996,7 +2069,7 @@ again: \ DWORD dwSize; \ dlg = dt.Save(dwSize); \ - res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); \ + res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \ } \ res_editor->FreeResource(dlg); \ } \ @@ -2007,43 +2080,43 @@ again: init_res_editor(); #ifdef NSIS_CONFIG_LICENSEPAGE if (!license_normal) { - res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); + res_editor->UpdateResource(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, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); + res_editor->UpdateResource(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, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); + res_editor->UpdateResource(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, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); - res_editor->UpdateResource(RT_BITMAP, IDB_BITMAP1, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); + res_editor->UpdateResource(RT_DIALOG, IDD_SELCOM, NSIS_DEFAULT_LANG, 0, 0); + res_editor->UpdateResource(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, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); + res_editor->UpdateResource(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, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); + res_editor->UpdateResource(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, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); + res_editor->UpdateResource(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, 0, 0); } else REMOVE_ICON(IDD_INSTFILES); if (!main) { - res_editor->UpdateResource(RT_DIALOG, IDD_INST, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); + res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, 0, 0); if (!build_compress_whole && !build_crcchk) - res_editor->UpdateResource(RT_DIALOG, IDD_VERIFY, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); + res_editor->UpdateResource(RT_DIALOG, IDD_VERIFY, NSIS_DEFAULT_LANG, 0, 0); } SCRIPT_MSG("Done!\n"); @@ -2310,10 +2383,29 @@ int CEXEBuild::write_output(void) int crc=0; { - char buffer[1024],*p; +#ifdef _WIN32 + char buffer[1024]; + char *p; GetFullPathName(build_output_filename,1024,buffer,&p); +#else +# ifdef PATH_MAX + char buffer[PATH_MAX]; +# else + int path_max = pathconf(build_output_filename, _PC_PATH_MAX); + if (path_max <= 0) + path_max = 4096; + char *buffer = (char *) malloc(path_max); + if (!buffer) + buffer = build_output_filename; +# endif + realpath(build_output_filename, buffer); +#endif notify(MAKENSIS_NOTIFY_OUTPUT, buffer); - INFO_MSG("\nOutput: \"%s\"\n",buffer); + INFO_MSG("\nOutput: \"%s\"\n", buffer); +#if !defined(_WIN32) && defined(PATH_MAX) + if (buffer != build_output_filename) + free(buffer); +#endif } FILE *fp = fopen(build_output_filename,"w+b"); if (!fp) @@ -2503,7 +2595,11 @@ int CEXEBuild::write_output(void) { int total_out_size_estimate= exeheader_size_new+sizeof(fh)+build_datablock.getlen()+(build_crcchk?sizeof(int):0); +#ifdef _WIN32 int pc=MulDiv(db_opt_save,1000,db_opt_save+total_out_size_estimate); +#else + int pc=(int)(((long long)db_opt_save*1000)/(db_opt_save+total_out_size_estimate)); +#endif INFO_MSG("Datablock optimizer saved %d bytes (~%d.%d%%).\n",db_opt_save, pc/10,pc%10); } @@ -2648,7 +2744,11 @@ int CEXEBuild::write_output(void) } INFO_MSG("\n"); { +#ifdef _WIN32 int pc=MulDiv(ftell(fp),1000,total_usize); +#else + int pc=(int)(((long long)ftell(fp)*1000)/(total_usize)); +#endif INFO_MSG("Total size: %10d / %d bytes (%d.%d%%)\n", ftell(fp),total_usize,pc/10,pc%10); } @@ -2996,7 +3096,11 @@ void CEXEBuild::warning_fl(const char *s, ...) void CEXEBuild::ERROR_MSG(const char *s, ...) { +#ifdef _WIN32 if (display_errors || notify_hwnd) +#else + if (display_errors) +#endif { char buf[NSIS_MAX_STRLEN*4]; va_list val; @@ -3055,7 +3159,8 @@ void CEXEBuild::print_warnings() fflush(g_output); } -void CEXEBuild::notify(int code, char *data) +#ifdef _WIN32 +void CEXEBuild::notify(notify_e code, char *data) { if (notify_hwnd) { @@ -3063,6 +3168,7 @@ void CEXEBuild::notify(int code, char *data) SendMessage(notify_hwnd, WM_COPYDATA, 0, (LPARAM)&cds); } } +#endif // Added by Ximon Eighteen 5th August 2002 #ifdef NSIS_CONFIG_PLUGIN_SUPPORT @@ -3080,8 +3186,8 @@ void CEXEBuild::build_plugin_table(void) char* searchPath = new char [strlen(nsisdir)+9]; if (searchPath) { - wsprintf(searchPath,"%s\\plugins",nsisdir); - INFO_MSG("Processing plugin dlls: \"%s\\*.dll\"\n",searchPath); + sprintf(searchPath,"%s" PATH_SEPARATOR_STR "Plugins",nsisdir); + INFO_MSG("Processing plugin dlls: \"%s" PATH_SEPARATOR_STR "*.dll\"\n",searchPath); m_plugins.FindCommands(searchPath,display_info?true:false); INFO_MSG("\n"); delete[] searchPath; diff --git a/Source/build.h b/Source/build.h index 97bbb938..11db2662 100644 --- a/Source/build.h +++ b/Source/build.h @@ -1,7 +1,7 @@ #ifndef _BUILD_H_ #define _BUILD_H_ -#include +#include using namespace std; @@ -18,9 +18,8 @@ using namespace std; #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 -#include -#include -#include +# include +# include #endif #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT @@ -33,7 +32,7 @@ using namespace std; #endif//NSIS_CONFIG_COMPRESSION_SUPPORT #ifdef NSIS_CONFIG_PLUGIN_SUPPORT -#include "Plugins.h" +# include "Plugins.h" #endif //NSIS_CONFIG_PLUGIN_SUPPORT #ifdef NSIS_CONFIG_CRC_SUPPORT @@ -48,7 +47,7 @@ extern "C" #define PS_ERROR 50 #define PS_WARNING 100 -enum { +enum notify_e { MAKENSIS_NOTIFY_SCRIPT, MAKENSIS_NOTIFY_WARNING, MAKENSIS_NOTIFY_ERROR, @@ -66,6 +65,7 @@ enum { class CEXEBuild { public: CEXEBuild(); + void CEXEBuild::setdirs(char *argv0); ~CEXEBuild(); // to add a warning to the compiler's warning list. @@ -104,8 +104,12 @@ class CEXEBuild { char *curfilename; FILE *fp; +#ifdef _WIN32 HWND notify_hwnd; - void notify(int code, char *data); + void notify(notify_e code, char *data); +#else + void notify(notify_e code, char *data) { } +#endif private: // tokens.cpp diff --git a/Source/bzip2/bzlib.h b/Source/bzip2/bzlib.h index de8f497f..13236e91 100644 --- a/Source/bzip2/bzlib.h +++ b/Source/bzip2/bzlib.h @@ -71,7 +71,7 @@ extern "C" { #endif #include "../exehead/config.h" -#include +#include "../Platform.h" #define BZ_RUN 0 #define BZ_FLUSH 1 @@ -129,8 +129,8 @@ typedef unsigned short UInt16; #ifndef EXEHEAD -#define BZALLOC(items) GlobalAlloc(GPTR,items) -#define BZFREE(addr) { if (addr) GlobalFree(addr); } +#define BZALLOC(items) malloc(items) +#define BZFREE(addr) { if (addr) free(addr); } #define mini_memcpy memcpy typedef struct { diff --git a/Source/clzma.h b/Source/clzma.h index c9c5812f..65daa418 100644 --- a/Source/clzma.h +++ b/Source/clzma.h @@ -6,8 +6,16 @@ #include "7zip/7zip/Compress/LZMA/LZMAEncoder.h" #include "7zip/Common/MyCom.h" +#ifndef _WIN32 +# include +#endif + // implemented in build.cpp - simply calls CompressReal +#ifdef _WIN32 DWORD WINAPI lzmaCompressThread(LPVOID lpParameter); +#else +void *lzmaCompressThread(void *arg); +#endif class CLZMA: public ICompressor, @@ -18,7 +26,11 @@ class CLZMA: private: NCompress::NLZMA::CEncoder *_encoder; +#ifdef _WIN32 HANDLE hCompressionThread; +#else + pthread_t hCompressionThread; +#endif BYTE *next_in; /* next input byte */ UINT avail_in; /* number of bytes available at next_in */ @@ -30,11 +42,38 @@ private: BOOL finish; - CRITICAL_SECTION cs; - BOOL nt_locked; /* nsis thread locked */ - BOOL ct_locked; /* compression thread locked */ + long sync_state; BOOL compressor_finished; +#ifndef _WIN32 +# define Sleep(x) sched_yield() + + pthread_mutex_t mutex; + + // these two lock every targer passed to them, but that's ok becuase + // we use only one target anyway... + long InterlockedExchange(long volatile* target, long value) + { + long oldvalue; + pthread_mutex_lock(&mutex); + oldvalue = *target; + *target = value; + pthread_mutex_unlock(&mutex); + return oldvalue; + } + + long InterlockedCompareExchange(long volatile* destination, long exchange, long comperand) + { + long oldvalue; + pthread_mutex_lock(&mutex); + oldvalue = *destination; + if (oldvalue == comperand) + *destination = exchange; + pthread_mutex_unlock(&mutex); + return oldvalue; + } +#endif + public: MY_UNKNOWN_IMP @@ -42,18 +81,27 @@ public: { _encoder = new NCompress::NLZMA::CEncoder(); _encoder->SetWriteEndMarkerMode(true); +#ifdef _WIN32 hCompressionThread = NULL; +#else + hCompressionThread = 0; +#endif compressor_finished = FALSE; finish = FALSE; - ct_locked = TRUE; +#ifndef _WIN32 + pthread_mutex_init(&mutex, 0); +#endif + compressor_finished = 1; + sync_state = 0; End(); - InitializeCriticalSection(&cs); } virtual ~CLZMA() { +#ifndef _WIN32 + pthread_mutex_destroy(&mutex); +#endif End(); - DeleteCriticalSection(&cs); if (_encoder) { delete _encoder; @@ -65,8 +113,7 @@ public: { End(); - nt_locked = TRUE; - ct_locked = FALSE; + sync_state = 1; compressor_finished = FALSE; finish = FALSE; @@ -103,27 +150,26 @@ public: int End() { - if (!compressor_finished && !ct_locked) + // is compressor not finished and waiting for input/output? + if (hCompressionThread && !compressor_finished && sync_state == 0) { // kill compression thread avail_in = 0; avail_out = 0; - finish = TRUE; - LeaveCriticalSection(&cs); - while (!ct_locked) - Sleep(0); - nt_locked = FALSE; - EnterCriticalSection(&cs); - while (ct_locked) - Sleep(0); - nt_locked = TRUE; - LeaveCriticalSection(&cs); + + InterlockedExchange(&sync_state, 1); + while (InterlockedCompareExchange(&sync_state, 2, 0) != 0) + Sleep(1); } +#ifdef _WIN32 if (hCompressionThread) { CloseHandle(hCompressionThread); hCompressionThread = NULL; } +#else + hCompressionThread = 0; +#endif SetNextOut(NULL, 0); SetNextIn(NULL, 0); return C_OK; @@ -131,12 +177,6 @@ public: int CompressReal() { - EnterCriticalSection(&cs); - ct_locked = TRUE; - - while (nt_locked) - Sleep(0); - try { if (_encoder->WriteCoderProperties(this) == S_OK) @@ -168,8 +208,7 @@ public: } compressor_finished = TRUE; - LeaveCriticalSection(&cs); - ct_locked = FALSE; + InterlockedExchange(&sync_state, 0); return C_OK; } @@ -188,31 +227,26 @@ public: if (!hCompressionThread) { +#ifdef _WIN32 DWORD dwThreadId; hCompressionThread = CreateThread(0, 0, lzmaCompressThread, (LPVOID) this, 0, &dwThreadId); if (!hCompressionThread) +#else + if (pthread_create(&hCompressionThread, NULL, lzmaCompressThread, (LPVOID) this)) +#endif return -2; } else { - LeaveCriticalSection(&cs); + InterlockedExchange(&sync_state, 1); } - while (!ct_locked) - Sleep(0); - - nt_locked = FALSE; - - EnterCriticalSection(&cs); - nt_locked = TRUE; - - while (ct_locked) - Sleep(0); + while (InterlockedCompareExchange(&sync_state, 2, 0) != 0) + Sleep(1); if (compressor_finished) { - LeaveCriticalSection(&cs); return res; } @@ -221,17 +255,9 @@ public: void GetMoreIO() { - LeaveCriticalSection(&cs); - while (!nt_locked) - Sleep(0); - - ct_locked = FALSE; - - EnterCriticalSection(&cs); - ct_locked = TRUE; - - while (nt_locked) - Sleep(0); + InterlockedExchange(&sync_state, 0); + while (InterlockedCompareExchange(&sync_state, 2, 1) != 1) + Sleep(1); } STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize) diff --git a/Source/exehead/Main.c b/Source/exehead/Main.c index b145a357..966ea2fc 100644 --- a/Source/exehead/Main.c +++ b/Source/exehead/Main.c @@ -69,7 +69,7 @@ char *ValidateTempDir() int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow) { - int ret = 2; + static int ret; const char *m_Err = _LANG_ERRORWRITINGTEMP; int cl_flags = 0; diff --git a/Source/exehead/Makefile b/Source/exehead/Makefile index bff081d7..dfe4be79 100644 --- a/Source/exehead/Makefile +++ b/Source/exehead/Makefile @@ -10,6 +10,8 @@ BZIP2_OBJS = Release-bzip2/bgbg.o Release-bzip2/exec.o Release-bzip2/fileform.o LZMA_SRCS = bgbg.c exec.c fileform.c main.c ui.c util.c ../crc32.c resource.rc ../7zip/LZMADecode.c LZMA_OBJS = Release-lzma/bgbg.o Release-lzma/exec.o Release-lzma/fileform.o Release-lzma/main.o Release-lzma/ui.o Release-lzma/util.o Release-lzma/crc32.o Release-lzma/resource.res Release-lzma/LZMADecode.o +SRCS = $(ZLIB_SRCS) $(BZIP2_SRCS) $(LZMA_SRCS) + LIBS = -lole32 -lgdi32 -lversion -luuid -lcomctl32 -lkernel32 -luser32 -lshell32 -ladvapi32 # -- Programs -- @@ -17,13 +19,18 @@ CC = gcc RC = windres RM = rm MKDIR = mkdir +BIN2H = ./bin2h # -- Compilers and linker flags -- -DEFINES = -DWIN32 -D_WINDOWS_ -DEXEHEAD -DWIN32_LEAN_AND_MEAN -DZEXPORT=__stdcall -DLZMACALL=__stdcall -CFLAGS = -Wall -Os -fno-common -fomit-frame-pointer -fno-inline $(DEFINES) -LFLAGS = -s -mwindows -nostdlib -nostartfiles --enable-stdcall-fixup -Wl,-Bdynamic -Wl,--file-alignment,512 -Wl,--exclude-libs,msvcrt.a -Wl,-e,_WinMain@16 -Wl,sections_script.ld +CPPFLAGS = -DEXEHEAD -DWIN32_LEAN_AND_MEAN -DZEXPORT=__stdcall -DLZMACALL=__fastcall +CFLAGS = -Wall -Os +LDFLAGS = -s -mwindows -nostdlib -nostartfiles --enable-stdcall-fixup -Wl,-Bdynamic -Wl,--file-alignment,512 -Wl,--exclude-libs,msvcrt.a -Wl,-e,_WinMain@16 -Wl,sections_script -Wl,-Map,$(subst .exe,.map,$@) RCFLAGS = --input-format rc --output-format coff +vpath %.c .:..:../zlib:../bzip2:../7zip + +%c : config.h fileform.h + all : exehead_zlib exehead_bzip2 exehead_lzma exehead_resources missing_dirs = $(filter-out $(wildcard Release-*),Release-zlib Release-bzip2 Release-lzma) @@ -34,75 +41,99 @@ else mkdirline = endif -dirs: +dirs : $(mkdirline) -exehead_zlib : dirs $(ZLIB_SRCS) $(ZLIB_OBJS) sections_script - $(CC) $(CFLAGS) $(LFLAGS) -o Release-zlib/exehead_zlib.exe $(ZLIB_OBJS) $(LIBS) - bin2h Release-zlib/exehead_zlib.exe Release-zlib/exehead_zlib.h zlib_header_data +%.o : dirs -exehead_bzip2 : dirs $(BZIP2_SRCS) $(BZIP2_OBJS) sections_script - $(CC) $(CFLAGS) $(LFLAGS) -o Release-bzip2/exehead_bzip2.exe $(BZIP2_OBJS) $(LIBS) - bin2h Release-bzip2/exehead_bzip2.exe Release-bzip2/exehead_bzip2.h bzip2_header_data +exehead_zlib : Release-zlib/exehead_zlib.exe Release-zlib/exehead_zlib.h -exehead_lzma : dirs $(LZMA_SRCS) $(LZMA_OBJS) sections_script - $(CC) $(CFLAGS) $(LFLAGS) -o Release-lzma/exehead_lzma.exe $(LZMA_OBJS) $(LIBS) - bin2h Release-lzma/exehead_lzma.exe Release-lzma/exehead_lzma.h lzma_header_data +Release-zlib/exehead_zlib.exe : $(ZLIB_OBJS) sections_script + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(ZLIB_OBJS) $(LIBS) -exehead_resources : exehead_zlib - bin2h bitmap1.bmp Release-zlib/bitmap1.h bitmap1_data - bin2h nsis.ico Release-zlib/icon.h icon_data - bin2h uninst.ico Release-zlib/unicon.h unicon_data +Release-zlib/exehead_zlib.h : Release-zlib/exehead_zlib.exe + $(BIN2H) $< $@ zlib_header_data -sections_script: - echo SECTIONS > sections_script.ld - echo { >> sections_script.ld - echo .text : { *(.text) } >> sections_script.ld - echo .data : { *(.data) } >> sections_script.ld - echo .rdata : { *(.rdata) } >> sections_script.ld - echo .bss : { *(.bss) } >> sections_script.ld - echo .idata : { *(.idata) } >> sections_script.ld - echo .ndata BLOCK(__section_alignment__) : { [ .ndata ] } >> sections_script.ld - echo .rsrc : { *(.rsrc) } >> sections_script.ld - echo } >> sections_script.ld +Release-zlib/%.o : %.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + +Release-zlib/resource.res : resource.rc resource.h config.h + $(RC) $(RCFLAGS) -o $@ -i $< + +exehead_bzip2 : Release-bzip2/exehead_bzip2.exe Release-bzip2/exehead_bzip2.h + +Release-bzip2/exehead_bzip2.exe : $(BZIP2_OBJS) sections_script + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(BZIP2_OBJS) $(LIBS) + +Release-bzip2/exehead_bzip2.h : Release-bzip2/exehead_bzip2.exe + $(BIN2H) $< $@ bzip2_header_data + +Release-bzip2/%.o : %.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + +Release-bzip2/resource.res : resource.rc resource.h config.h + $(RC) $(RCFLAGS) -o $@ -i $< + +exehead_lzma : Release-lzma/exehead_lzma.exe Release-lzma/exehead_lzma.h + +Release-lzma/exehead_lzma.exe : $(LZMA_OBJS) sections_script + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LZMA_OBJS) $(LIBS) + +Release-lzma/exehead_lzma.h : Release-lzma/exehead_lzma.exe + $(BIN2H) $< $@ lzma_header_data + +Release-lzma/%.o : %.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + +Release-lzma/resource.res : resource.rc resource.h config.h + $(RC) $(RCFLAGS) -o $@ -i $< + +exehead_resources : Release-zlib/bitmap1.h Release-zlib/icon.h Release-zlib/unicon.h + +Release-zlib/bitmap1.h : bitmap1.bmp + $(BIN2H) bitmap1.bmp Release-zlib/bitmap1.h bitmap1_data + +Release-zlib/icon.h : nsis.ico + $(BIN2H) nsis.ico Release-zlib/icon.h icon_data + +Release-zlib/unicon.h : uninst.ico + $(BIN2H) uninst.ico Release-zlib/unicon.h unicon_data + +sections_script: + echo "SECTIONS" > sections_script + echo "{" >> sections_script + echo " .text : { *(.text) }" >> sections_script + echo " .data : { *(.data) }" >> sections_script + echo " .rdata : { *(.rdata) }" >> sections_script + echo " .bss : { *(.bss) }" >> sections_script + echo " .idata : { *(.idata) }" >> sections_script + echo " .ndata BLOCK(__section_alignment__) : { [ .ndata ] }" >> sections_script + echo " .rsrc : { *(.rsrc) }" >> sections_script + echo "}" >> sections_script Release-zlib/ = -DNSIS_COMPRESS_USE_ZLIB Release-bzip2/ = -DNSIS_COMPRESS_USE_BZIP2 Release-lzma/ = -DNSIS_COMPRESS_USE_LZMA getdefine = $($(dir $@)) -Release-zlib/%.o Release-bzip2/%.o Release-lzma/%.o : %.c $(DEPENDS) - $(CC) $(CFLAGS) $(getdefine) -c $< -o $@ - -Release-zlib/%.o Release-bzip2/%.o Release-lzma/%.o : ../%.c $(DEPENDS) - $(CC) $(CFLAGS) $(getdefine) -c $< -o $@ - -Release-zlib/%.o Release-bzip2/%.o Release-lzma/%.o : ../zlib/%.c $(DEPENDS) - $(CC) $(CFLAGS) $(getdefine) -c $< -o $@ - -Release-zlib/%.o Release-bzip2/%.o Release-lzma/%.o : ../bzip2/%.c $(DEPENDS) - $(CC) $(CFLAGS) $(getdefine) -c $< -o $@ - -Release-zlib/%.o Release-bzip2/%.o Release-lzma/%.o : ../7zip/%.c $(DEPENDS) - $(CC) $(CFLAGS) $(getdefine) -c $< -o $@ - -%/resource.res : resource.rc resource.h config.h Makefile - $(RC) $(RCFLAGS) -o $*/resource.res -i resource.rc +CFLAGS =: $(CFLAGS) $(getdefine) clean :: - $(RM) sections_script.ld - $(RM) Release-zlib/*.o - $(RM) Release-zlib/resource.res - $(RM) Release-zlib/exehead_zlib.exe - $(RM) Release-zlib/exehead_zlib.h - $(RM) Release-zlib/bitmap1.h - $(RM) Release-zlib/icon.h - $(RM) Release-zlib/unicon.h - $(RM) Release-bzip2/*.o - $(RM) Release-bzip2/resource.res - $(RM) Release-bzip2/exehead_bzip2.exe - $(RM) Release-bzip2/exehead_bzip2.h - $(RM) Release-lzma/*.o - $(RM) Release-lzma/resource.res - $(RM) Release-lzma/exehead_lzma.exe - $(RM) Release-lzma/exehead_lzma.h + $(RM) -f sections_script + $(RM) -f Release-zlib/*.o + $(RM) -f Release-zlib/resource.res + $(RM) -f Release-zlib/exehead_zlib.exe + $(RM) -f Release-zlib/exehead_zlib.h + $(RM) -f Release-zlib/bitmap1.h + $(RM) -f Release-zlib/icon.h + $(RM) -f Release-zlib/unicon.h + $(RM) -f Release-bzip2/*.o + $(RM) -f Release-bzip2/resource.res + $(RM) -f Release-bzip2/exehead_bzip2.exe + $(RM) -f Release-bzip2/exehead_bzip2.h + $(RM) -f Release-lzma/*.o + $(RM) -f Release-lzma/resource.res + $(RM) -f Release-lzma/exehead_lzma.exe + $(RM) -f Release-lzma/exehead_lzma.h + +.PHONY : exehead_zlib exehead_bzip2 exehead_lzma exehead_resources dirs clean \ No newline at end of file diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index f72899cd..63121d8d 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -794,7 +794,7 @@ static int NSISCALL _sumsecsfield(int idx) #ifdef NSIS_CONFIG_COMPONENTPAGE if (sections[x].flags & SF_SELECTED) #endif - total += sections[x].fields[idx]; + total += ((int *)§ions[x])[idx]; } return total; } diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index 659fb862..74359146 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -24,7 +24,7 @@ typedef struct _stack_t { static stack_t *g_st; #endif -union exec_flags g_exec_flags; +exec_flags g_exec_flags; #if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT) HRESULT g_hres; @@ -212,16 +212,16 @@ static int NSISCALL ExecuteEntry(entry *entry_) break; #endif//NSIS_CONFIG_VISIBLE_SUPPORT case EW_SETFLAG: - g_exec_flags.flags[parm0]=GetIntFromParm(1); + FIELDN(g_exec_flags,parm0)=GetIntFromParm(1); break; case EW_IFFLAG: { - int f=lent.offsets[!g_exec_flags.flags[parm2]]; - g_exec_flags.flags[parm2]&=parm3; + int f=lent.offsets[!FIELDN(g_exec_flags,parm2)]; + FIELDN(g_exec_flags,parm2)&=parm3; return f; } case EW_GETFLAG: - myitoa(var0,g_exec_flags.flags[parm1]); + myitoa(var0,FIELDN(g_exec_flags,parm1)); break; #ifdef NSIS_CONFIG_VISIBLE_SUPPORT case EW_CHDETAILSVIEW: diff --git a/Source/exehead/exec.h b/Source/exehead/exec.h index 1a0ba1bd..ce7c7032 100644 --- a/Source/exehead/exec.h +++ b/Source/exehead/exec.h @@ -1,7 +1,7 @@ #ifndef _EXEC_H_ #define _EXEC_H_ -extern union exec_flags g_exec_flags; +extern exec_flags g_exec_flags; int NSISCALL ExecuteCodeSegment(int pos, HWND hwndProgress); // returns 0 on success diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h index a37f6d41..b699176e 100644 --- a/Source/exehead/fileform.h +++ b/Source/exehead/fileform.h @@ -315,18 +315,14 @@ typedef struct #define SF_EXPAND 32 #define SF_PSELECTED 64 -typedef union +typedef struct { - struct - { - int name_ptr; // '' for non-optional components - int install_types; // bits set for each of the different install_types, if any. - int flags; // SF_* - defined above - int code; - int code_size; - int size_kb; - }; - int fields[1]; + int name_ptr; // '' for non-optional components + int install_types; // bits set for each of the different install_types, if any. + int flags; // SF_* - defined above + int code; + int code_size; + int size_kb; } section; #define SECTION_OFFSET(field) (FIELD_OFFSET(section, field)/sizeof(int)) @@ -395,6 +391,7 @@ typedef struct int parms[5]; } page; +// text/bg color #define CC_TEXT 1 #define CC_TEXT_SYS 2 #define CC_BK 4 @@ -410,6 +407,42 @@ typedef struct { int flags; } ctlcolors; +// $0..$9, $INSTDIR, etc are encoded as ASCII bytes starting from this value. +// Added by ramon 3 jun 2003 +#define NS_SKIP_CODE 252 +#define NS_VAR_CODE 253 +#define NS_SHELL_CODE 254 +#define NS_LANG_CODE 255 +#define NS_CODES_START NS_SKIP_CODE + +#define CODE_SHORT(x) (WORD)((((WORD)x & 0x7F) | (((WORD)x & 0x3F80) << 1) | 0x8080)) +#define MAX_CODED 16383 + +#define NSIS_INSTDIR_INVALID 1 +#define NSIS_INSTDIR_NOT_ENOUGH_SPACE 2 + +typedef struct +{ + int autoclose; + int all_user_var; + int exec_error; + int abort; +#ifdef NSIS_SUPPORT_REBOOT + int exec_reboot; +#endif + int cur_insttype; + int insttype_changed; +#ifdef NSIS_CONFIG_SILENT_SUPPORT + int silent; +#endif + int instdir_error; + int rtl; +} exec_flags; + +#define FIELDN(x, y) (((int *)&x)[y]) + +#ifdef EXEHEAD + // the following are only used/implemented in exehead, not makensis. int NSISCALL isheader(firstheader *h); // returns 0 on not header, length_of_datablock on success @@ -431,41 +464,6 @@ extern int g_quit_flag; BOOL NSISCALL ReadSelfFile(LPVOID lpBuffer, DWORD nNumberOfBytesToRead); DWORD NSISCALL SetSelfFilePointer(LONG lDistanceToMove); -// $0..$9, $INSTDIR, etc are encoded as ASCII bytes starting from this value. -// Added by ramon 3 jun 2003 -#define NS_SKIP_CODE 252 -#define NS_VAR_CODE 253 -#define NS_SHELL_CODE 254 -#define NS_LANG_CODE 255 -#define NS_CODES_START NS_SKIP_CODE - -#define CODE_SHORT(x) (WORD)((((WORD)x & 0x7F) | (((WORD)x & 0x3F80) << 1) | 0x8080)) -#define MAX_CODED 16383 - -#define NSIS_INSTDIR_INVALID 1 -#define NSIS_INSTDIR_NOT_ENOUGH_SPACE 2 - -union exec_flags { - struct { - int autoclose; - int all_user_var; - int exec_error; - int abort; -#ifdef NSIS_SUPPORT_REBOOT - int exec_reboot; -#endif - int cur_insttype; - int insttype_changed; -#ifdef NSIS_CONFIG_SILENT_SUPPORT - int silent; -#endif - int instdir_error; - int rtl; - }; - int flags[1]; -}; - -#ifdef EXEHEAD extern struct block_header g_blocks[BLOCKS_NUM]; extern header *g_header; extern int g_flags; diff --git a/Source/exehead/util.c b/Source/exehead/util.c index 024d3828..be81a79f 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -4,9 +4,8 @@ #include "state.h" #include "config.h" #include "lang.h" -#include "exec.h" - #include "fileform.h" +#include "exec.h" #include "ui.h" #ifdef NSIS_CONFIG_LOG diff --git a/Source/lang.cpp b/Source/lang.cpp index 08e53f45..2c87910b 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -3,7 +3,7 @@ #include #include "build.h" #include "DialogTemplate.h" -#include "exehead\resource.h" +#include "exehead/resource.h" extern const char *NSIS_VERSION; @@ -313,14 +313,14 @@ int CEXEBuild::GenerateLangTables() { init_res_editor(); #define ADD_FONT(id) { \ - BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); \ + BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \ if (dlg) { \ CDialogTemplate td(dlg); \ free(dlg); \ td.SetFont(build_font, build_font_size); \ DWORD dwSize; \ dlg = td.Save(dwSize); \ - res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); \ + res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \ res_editor->FreeResource(dlg); \ } \ } @@ -368,7 +368,7 @@ int CEXEBuild::GenerateLangTables() { init_res_editor(); #define ADD_FONT(id) { \ - BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); \ + BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \ if (dlg) { \ CDialogTemplate td(dlg,lt[i].nlf.m_uCodePage); \ free(dlg); \ @@ -376,7 +376,7 @@ int CEXEBuild::GenerateLangTables() { if (lt[i].nlf.m_bRTL) td.ConvertToRTL(); \ DWORD dwSize; \ dlg = td.Save(dwSize); \ - res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id+cur_offset), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); \ + res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id+cur_offset), NSIS_DEFAULT_LANG, dlg, dwSize); \ res_editor->FreeResource(dlg); \ } \ } @@ -720,6 +720,14 @@ char SkipComments(FILE *f) { return c; } +#ifndef _WIN32 +BOOL IsValidCodePage(UINT CodePage) +{ + // FIXME make a real check + return TRUE; +} +#endif + // NSIS Language File parser LanguageTable * CEXEBuild::LoadLangFile(char *filename) { FILE *f = fopen(filename, "r"); diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp index 44063528..e7c5ddc7 100644 --- a/Source/makenssi.cpp +++ b/Source/makenssi.cpp @@ -36,6 +36,9 @@ const char *NSIS_VERSION="v2.0"; #include "Platform.h" #include #include +#ifdef _WIN32 +# include +#endif #include "build.h" #include "util.h" @@ -86,6 +89,8 @@ int main(int argc, char **argv) int tmpargpos=1; int no_logo=0; + build.setdirs(argv[0]); + if (argc > 1 && !stricmp(argv[1], "/VERSION")) { fprintf(g_output,NSIS_VERSION); @@ -217,9 +222,14 @@ int main(int argc, char **argv) } else if (!stricmp(argv[argpos],"/NOTIFYHWND")) { +#ifdef _WIN32 build.notify_hwnd=(HWND)atol(argv[++argpos]); if (!IsWindow(build.notify_hwnd)) build.notify_hwnd=0; +#else + argpos++; + build.warning("/NOTIFYHWND is disabled for non Win32 platforms."); +#endif } else if (!stricmp(argv[argpos],"/HDRINFO")) { @@ -257,12 +267,11 @@ int main(int argc, char **argv) { g_noconfig=1; char exepath[1024]; - GetModuleFileName(NULL,exepath,sizeof(exepath)-1); - //strncpy(exepath,argv[0],1023); + strncpy(exepath,argv[0],sizeof(exepath)-1); exepath[1023]=0; char *p=exepath; while (*p) p++; - while (p > exepath && *p != '\\') p=CharPrev(exepath,p); + while (p > exepath && *p != PATH_SEPARATOR_C) p=CharPrev(exepath,p); if (p>exepath) p++; strcpy(p,"nsisconf.nsh"); FILE *cfg=fopen(exepath,"rt"); @@ -320,11 +329,19 @@ int main(int argc, char **argv) } if (do_cd) { - char dirbuf[1024],*p; + char dirbuf[1024]=""; + char *p; +#ifdef _WIN32 GetFullPathName(sfile,sizeof(dirbuf),dirbuf,&p); - p=dirbuf; - while (*p) p++; - while (p > dirbuf && *p != '\\') p=CharPrev(dirbuf,p); + p=CharPrev(dirbuf,p); +#else + getcwd(dirbuf,sizeof(dirbuf)-strlen(sfile)-2); + if (dirbuf[strlen(dirbuf)-1]!=PATH_SEPARATOR_C) + strcat(dirbuf,PATH_SEPARATOR_STR); + strcat(dirbuf,sfile); + p=strrchr(dirbuf,PATH_SEPARATOR_C); +#endif + if (!p) p=dirbuf; *p=0; if (dirbuf[0]) { @@ -333,7 +350,7 @@ int main(int argc, char **argv) fprintf(g_output,"Changing directory to: \"%s\"\n",dirbuf); fflush(g_output); } - if (!SetCurrentDirectory(dirbuf)) + if (chdir(dirbuf)) { if (build.display_errors) { diff --git a/Source/script.cpp b/Source/script.cpp index 07cfe94a..8b421bf6 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -1,9 +1,6 @@ #include "Platform.h" #include -#include -#define _RICHEDIT_VER 0x0200 -#include -#undef _RICHEDIT_VER +#include #include "tokens.h" #include "build.h" #include "util.h" @@ -13,6 +10,12 @@ #include "lang.h" #include "exehead/resource.h" +#ifndef _WIN32 +# include +# include +# include +#endif + #define MAX_INCLUDEDEPTH 10 #define MAX_LINELENGTH 4096 @@ -56,6 +59,7 @@ char *CEXEBuild::set_timestamp_predefine(char *filename) } char timestampbuf[256] = ""; +#ifdef _WIN32 char datebuf[128] = ""; char timebuf[128] = ""; WIN32_FIND_DATA fd; @@ -76,6 +80,17 @@ char *CEXEBuild::set_timestamp_predefine(char *filename) definedlist.add("__TIMESTAMP__",timestampbuf); } +#else + struct stat st; + if (!stat(filename, &st)) + { + ctime_r(&st.st_mtime, timestampbuf); + char *p = timestampbuf + strlen(timestampbuf); + while (!*p || *p == '\n') + *p-- = 0; + definedlist.add("__TIMESTAMP__",timestampbuf); + } +#endif return oldtimestamp; } @@ -92,8 +107,8 @@ void CEXEBuild::restore_timestamp_predefine(char *oldtimestamp) char *CEXEBuild::set_line_predefine(int linecnt, BOOL is_macro) { char* linebuf = NULL; - char temp[8] = ""; - wsprintf(temp,"%d",linecnt); + char temp[128] = ""; + sprintf(temp,"%d",linecnt); char *oldline = definedlist.find("__LINE__"); if(oldline) { @@ -102,7 +117,7 @@ char *CEXEBuild::set_line_predefine(int linecnt, BOOL is_macro) } if(is_macro && oldline) { linebuf = (char *)malloc(strlen(oldline)+strlen(temp)+2); - wsprintf(linebuf,"%s.%s",oldline,temp); + sprintf(linebuf,"%s.%s",oldline,temp); } else { linebuf = strdup(temp); @@ -126,23 +141,30 @@ void CEXEBuild::set_date_time_predefines() { time_t etime; struct tm * ltime; - SYSTEMTIME stime; - char datebuf[32]; - char timebuf[32]; + char datebuf[128]; + char timebuf[128]; time(&etime); ltime = localtime(&etime); +#ifdef _WIN32 + SYSTEMTIME stime; stime.wYear = ltime->tm_year+1900; stime.wMonth = ltime->tm_mon + 1; stime.wDay = ltime->tm_mday; - stime.wHour= ltime->tm_hour; - stime.wMinute= ltime->tm_min; - stime.wSecond= ltime->tm_sec; - stime.wMilliseconds= 0; - GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stime, NULL, datebuf, sizeof(datebuf)); + stime.wHour= ltime->tm_hour; + stime.wMinute= ltime->tm_min; + stime.wSecond= ltime->tm_sec; + stime.wMilliseconds= 0; + GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stime, NULL, datebuf, sizeof(datebuf)); definedlist.add("__DATE__",(char *)datebuf); - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, sizeof(timebuf)); + GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, sizeof(timebuf)); definedlist.add("__TIME__",(char *)timebuf); +#else + strftime(datebuf, sizeof(datebuf), "%x", ltime); + definedlist.add("__DATE__",(char *)datebuf); + strftime(timebuf, sizeof(timebuf), "%X", ltime); + definedlist.add("__TIME__",(char *)timebuf); +#endif } void CEXEBuild::del_date_time_predefines() @@ -841,7 +863,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) char *p=str; str[0]=0; fgets(str,MAX_LINELENGTH,fp); - //SCRIPT_MSG("%s%s", str, str[lstrlen(str)-1]=='\n'?"":"\n"); + //SCRIPT_MSG("%s%s", str, str[strlen(str)-1]=='\n'?"":"\n"); if (feof(fp) && !str[0]) { ERROR_MSG("!macro \"%s\": unterminated (no !macroend found in file)!\n",line.gettoken_str(1)); @@ -1892,7 +1914,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) try { init_res_editor(); - BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); + BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG); if (!dlg) throw runtime_error("IDD_INSTFILES doesn't exist!"); CDialogTemplate dt(dlg,uDefCodePage); free(dlg); @@ -1908,7 +1930,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) DWORD dwSize; dlg = dt.Save(dwSize); - res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); + res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG, dlg, dwSize); res_editor->FreeResource(dlg); } catch (exception& err) { @@ -2076,7 +2098,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) SCRIPT_MSG("XPStyle: %s\n", line.gettoken_str(1)); init_res_editor(); const char *szXPManifest = k ? 0 : "Nullsoft Install System v2.0"; - res_editor->UpdateResource(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (unsigned char*)szXPManifest, k ? 0 : lstrlen(szXPManifest)); + 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()); @@ -2089,32 +2111,47 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int k=line.gettoken_enum(1, "all\0IDD_LICENSE\0IDD_DIR\0IDD_SELCOM\0IDD_INST\0IDD_INSTFILES\0IDD_UNINST\0IDD_VERIFY\0IDD_LICENSE_FSRB\0IDD_LICENSE_FSCB\0"); if (k<0) PRINTHELP(); - HINSTANCE hUIFile = LoadLibraryEx(line.gettoken_str(2), 0, LOAD_LIBRARY_AS_DATAFILE); - if (!hUIFile) { - ERROR_MSG("Error: Can't find \"%s\" in \"%s\"!\n", line.gettoken_str(1), line.gettoken_str(2)); + FILE *fui = fopen(line.gettoken_str(2), "rb"); + if (!fui) { + ERROR_MSG("Error: Can't open \"%s\"!\n", line.gettoken_str(2)); return PS_ERROR; } + fseek(fui, 0, SEEK_END); + unsigned int len = ftell(fui); + fseek(fui, 0, SEEK_SET); + LPBYTE ui = (LPBYTE) malloc(len); + if (!ui) { + ERROR_MSG("Internal compiler error #12345: malloc(%d) failed\n", len); + extern void quit(); quit(); + } + if (fread(ui, 1, len, fui) != len) { + fclose(fui); + free(ui); + ERROR_MSG("Error: Can't read \"%s\"!\n", line.gettoken_str(2)); + return PS_ERROR; + } + fclose(fui); + + CResourceEditor *uire = new CResourceEditor(ui, len); + init_res_editor(); // Search for required items - #define SEARCH(x) if (!UIDlg.GetItem(x)) {ERROR_MSG("Error: Can't find %s (%u) in the custom UI!\n", #x, x);return PS_ERROR;} - #define SAVE(x) dwSize = UIDlg.GetSize(); res_editor->UpdateResource(RT_DIALOG, x, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); + #define GET(x) dlg = uire->GetResource(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;free(ui);delete uire;return PS_ERROR;} + #define SAVE(x) dwSize = UIDlg.GetSize(); res_editor->UpdateResource(RT_DIALOG, x, NSIS_DEFAULT_LANG, dlg, dwSize); delete [] dlg; - BYTE* dlg = 0; + LPBYTE dlg = NULL; if (k == 0 || k == 1) { - dlg = get_dlg(hUIFile, IDD_LICENSE, line.gettoken_str(2)); - if (!dlg) return PS_ERROR; - CDialogTemplate UIDlg(dlg,uDefCodePage); + GET(IDD_LICENSE); SEARCH(IDC_EDIT1); SAVE(IDD_LICENSE); } if (k == 0 || k == 2) { - dlg = get_dlg(hUIFile, IDD_DIR, line.gettoken_str(2)); - if (!dlg) return PS_ERROR; - CDialogTemplate UIDlg(dlg,uDefCodePage); + GET(IDD_DIR); SEARCH(IDC_DIR); SEARCH(IDC_BROWSE); #ifdef NSIS_CONFIG_LOG @@ -2124,18 +2161,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } if (k == 0 || k == 3) { - dlg = get_dlg(hUIFile, IDD_SELCOM, line.gettoken_str(2)); - if (!dlg) return PS_ERROR; - CDialogTemplate UIDlg(dlg,uDefCodePage); + GET(IDD_SELCOM); SEARCH(IDC_TREE1); SEARCH(IDC_COMBO1); SAVE(IDD_SELCOM); } if (k == 0 || k == 4) { - dlg = get_dlg(hUIFile, IDD_INST, line.gettoken_str(2)); - if (!dlg) return PS_ERROR; - CDialogTemplate UIDlg(dlg,uDefCodePage); + GET(IDD_INST); SEARCH(IDC_BACK); SEARCH(IDC_CHILDRECT); SEARCH(IDC_VERSTR); @@ -2161,9 +2194,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } if (k == 0 || k == 5) { - dlg = get_dlg(hUIFile, IDD_INSTFILES, line.gettoken_str(2)); - if (!dlg) return PS_ERROR; - CDialogTemplate UIDlg(dlg,uDefCodePage); + GET(IDD_INSTFILES); SEARCH(IDC_LIST1); SEARCH(IDC_PROGRESS); SEARCH(IDC_SHOWDETAILS); @@ -2171,27 +2202,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } if (k == 0 || k == 6) { - dlg = get_dlg(hUIFile, IDD_UNINST, line.gettoken_str(2)); - if (!dlg) return PS_ERROR; - CDialogTemplate UIDlg(dlg,uDefCodePage); + GET(IDD_UNINST); SEARCH(IDC_EDIT1); SAVE(IDD_UNINST); } if (k == 0 || k == 7) { - dlg = get_dlg(hUIFile, IDD_VERIFY, line.gettoken_str(2)); - if (!dlg) return PS_ERROR; - CDialogTemplate UIDlg(dlg,uDefCodePage); + GET(IDD_VERIFY); SEARCH(IDC_STR); - // No RTL here, pure English goes here. - //SAVE(IDD_VERIFY); - res_editor->UpdateResource(RT_DIALOG, IDD_VERIFY, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, UIDlg.GetSize()); + SAVE(IDD_VERIFY); } if (k == 0 || k == 8) { - dlg = get_dlg(hUIFile, IDD_LICENSE_FSRB, line.gettoken_str(2)); - if (!dlg) return PS_ERROR; - CDialogTemplate UIDlg(dlg,uDefCodePage); + GET(IDD_LICENSE_FSRB); SEARCH(IDC_EDIT1); SEARCH(IDC_LICENSEAGREE); SEARCH(IDC_LICENSEDISAGREE); @@ -2199,17 +2222,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } if (k == 0 || k == 9) { - dlg = get_dlg(hUIFile, IDD_LICENSE_FSCB, line.gettoken_str(2)); - if (!dlg) return PS_ERROR; - CDialogTemplate UIDlg(dlg,uDefCodePage); + GET(IDD_LICENSE_FSCB); SEARCH(IDC_EDIT1); SEARCH(IDC_LICENSEAGREE); SAVE(IDD_LICENSE_FSCB); } - if (!FreeLibrary(hUIFile)) { - ERROR_MSG("can't free library!\n"); - } + delete uire; + free(ui); SCRIPT_MSG("ChangeUI: %s %s%s\n", line.gettoken_str(1), line.gettoken_str(2), branding_image_found?" (branding image holder found)":""); } @@ -2219,6 +2239,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } return PS_OK; case TOK_ADDBRANDINGIMAGE: +#ifdef _WIN32 try { int k=line.gettoken_enum(1,"top\0left\0bottom\0right\0"); int wh=line.gettoken_int(2); @@ -2228,7 +2249,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), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); + BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG); CDialogTemplate dt(dlg,uDefCodePage); delete [] dlg; @@ -2275,7 +2296,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) DWORD dwDlgSize; dlg = dt.Save(dwDlgSize); - res_editor->UpdateResource(RT_DIALOG, IDD_INST, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwDlgSize); + res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize); res_editor->FreeResource(dlg); @@ -2290,6 +2311,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_ERROR; } return PS_OK; +#else + ERROR_MSG("Error: AddBrandingImage is disabled for non Win32 platforms.\n"); + return PS_ERROR; +#endif case TOK_SETFONT: { if (!strnicmp(line.gettoken_str(1), "/LANG=", 6)) @@ -2498,15 +2523,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; case TOK_P_INCLUDE: { - WIN32_FIND_DATA fd; char *f = line.gettoken_str(1); + int included = 0; +#ifdef _WIN32 + WIN32_FIND_DATA fd; unsigned int malloced = sizeof(fd.cFileName) + strlen(f) + 1; + char *incfile = (char *) malloc(malloced); - int included = 0; - strcpy(incfile, f); - char *slash = strrchr(incfile, '\\'); + char *slash = strrchr(incfile, PATH_SEPARATOR_C); HANDLE search = FindFirstFile(f, &fd); if (search != INVALID_HANDLE_VALUE) @@ -2519,11 +2545,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) incfile[0] = 0; strcat(incfile, fd.cFileName); if (includeScript(incfile) != PS_OK) +#else + unsigned int malloced = strlen(f) + 100; + char *incfile = (char *) malloc(malloced); + glob_t globbuf; + if (!glob(incfile, GLOB_NOSORT, NULL, &globbuf)) + { + for (unsigned int i = 0; i < globbuf.gl_pathc; i++) + { + if (includeScript(globbuf.gl_pathv[i]) != PS_OK) +#endif return PS_ERROR; included++; } +#ifdef _WIN32 while (FindNextFile(search, &fd)); FindClose(search); +#else + globfree(&globbuf); +#endif } else { @@ -2538,11 +2578,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) incfile = (char *) malloc(malloced); } strcpy(incfile, dir); - if (*f != '\\') - strcat(incfile, "\\"); + if (*f != PATH_SEPARATOR_C) + strcat(incfile, PATH_SEPARATOR_STR); strcat(incfile, f); - slash = strrchr(incfile, '\\'); - +#ifdef _WIN32 + slash = strrchr(incfile, PATH_SEPARATOR_C); + search = FindFirstFile(incfile, &fd); if (search != INVALID_HANDLE_VALUE) { @@ -2553,12 +2594,24 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else incfile[0] = 0; strcat(incfile, fd.cFileName); + if (includeScript(incfile) != PS_OK) +#else + if (!glob(incfile, GLOB_NOSORT, NULL, &globbuf)) + { + for (unsigned int i = 0; i < globbuf.gl_pathc; i++) + { + if (includeScript(globbuf.gl_pathv[i]) != PS_OK) +#endif return PS_ERROR; included++; } +#ifdef _WIN32 while (FindNextFile(search, &fd)); FindClose(search); +#else + globfree(&globbuf); +#endif break; } else @@ -2578,7 +2631,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } return PS_OK; case TOK_P_CD: +#ifdef _WIN32 if (!line.gettoken_str(1)[0] || !SetCurrentDirectory(line.gettoken_str(1))) +#else + if (!line.gettoken_str(1)[0] || chdir(line.gettoken_str(1))) +#endif { ERROR_MSG("!cd: error changing to: \"%s\"\n",line.gettoken_str(1)); return PS_ERROR; @@ -2996,10 +3053,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (line.getnumtokens()!=a+1 && !trim) PRINTHELP(); if (line.getnumtokens()==a+1) SetInnerString(NLF_BRANDING,line.gettoken_str(a)); +#ifdef _WIN32 if (trim) try { init_res_editor(); - BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); + BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG); CDialogTemplate td(dlg,uDefCodePage); free(dlg); @@ -3007,7 +3065,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) char str[512]; extern const char *NSIS_VERSION; if (line.getnumtokens()==a+1 && line.gettoken_str(a)[0]) - lstrcpy(str, line.gettoken_str(a)); + strcpy(str, line.gettoken_str(a)); else wsprintf(str, "Nullsoft Install System %s", NSIS_VERSION); @@ -3020,13 +3078,20 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) DWORD dwSize; dlg = td.Save(dwSize); - res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); + res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG, dlg, dwSize); res_editor->FreeResource(dlg); } catch (exception& err) { ERROR_MSG("Error while triming branding text control: %s\n", err.what()); return PS_ERROR; } +#else + if (trim) + { + ERROR_MSG("Error: BrandingText /TRIM* disabled for non Win32 platforms.\n"); + return PS_ERROR; + } +#endif SCRIPT_MSG("BrandingText: \"%s\"\n",line.gettoken_str(a)); } return PS_OK; @@ -3041,7 +3106,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; case TOK_SPACETEXTS: { - if (!lstrcmpi(line.gettoken_str(1), "none")) { + if (!strcmpi(line.gettoken_str(1), "none")) { no_space_texts=true; SCRIPT_MSG("SpaceTexts: none\n"); } @@ -3221,8 +3286,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[3]=SW_SHOWNORMAL; if (line.getnumtokens() > 4) { - int tab[3]={SW_SHOWNORMAL,SW_SHOWMAXIMIZED,SW_SHOWMINIMIZED}; - int a=line.gettoken_enum(4,"SW_SHOWNORMAL\0SW_SHOWMAXIMIZED\0SW_SHOWMINIMIZED\0"); + int tab[4]={SW_SHOWNORMAL,SW_SHOWMAXIMIZED,SW_SHOWMINIMIZED,SW_HIDE}; + int a=line.gettoken_enum(4,"SW_SHOWNORMAL\0SW_SHOWMAXIMIZED\0SW_SHOWMINIMIZED\0SW_HIDE\0"); if (a < 0) PRINTHELP() ent.offsets[3]=tab[a]; } @@ -3651,15 +3716,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) for (int i = 3; i < line.getnumtokens(); i++) { char *tok=line.gettoken_str(i); if (tok[0]=='/') { - if (!lstrcmpi(tok,"/ITALIC")) { + if (!strcmpi(tok,"/ITALIC")) { SCRIPT_MSG(" /ITALIC"); flags|=1; } - else if (!lstrcmpi(tok,"/UNDERLINE")) { + else if (!strcmpi(tok,"/UNDERLINE")) { SCRIPT_MSG(" /UNDERLINE"); flags|=2; } - else if (!lstrcmpi(tok,"/STRIKE")) { + else if (!strcmpi(tok,"/STRIKE")) { SCRIPT_MSG(" /STRIKE"); flags|=4; } @@ -4120,6 +4185,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return add_entry(&ent); case TOK_GETDLLVERSIONLOCAL: { +#ifdef _WIN32 char buf[128]; DWORD low=0, high=0; DWORD s,d; @@ -4127,7 +4193,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int alloced=0; char *path=line.gettoken_str(1); if (!((*path == '\\' && path[1] == '\\') || (*path && path[1] == ':'))) { - size_t pathlen=lstrlen(path)+GetCurrentDirectory(0, buf)+2; + size_t pathlen=strlen(path)+GetCurrentDirectory(0, buf)+2; char *nrpath=(char *)malloc(pathlen); alloced=1; GetCurrentDirectory(pathlen, nrpath); @@ -4193,12 +4259,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (ent.offsets[0]<0) PRINTHELP() SCRIPT_MSG("GetDLLVersionLocal: %s (%u,%u)->(%s,%s)\n", line.gettoken_str(1),high,low,line.gettoken_str(2),line.gettoken_str(3)); +#else + ERROR_MSG("Error: GetDLLVersionLocal is disabled for non Win32 platforms.\n"); + return PS_ERROR; +#endif } return add_entry(&ent); case TOK_GETFILETIMELOCAL: { char buf[129]; DWORD high=0,low=0; +#ifdef _WIN32 int flag=0; HANDLE hFile=CreateFile(line.gettoken_str(1),0,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (hFile != INVALID_HANDLE_VALUE) @@ -4217,6 +4288,29 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ERROR_MSG("GetFileTimeLocal: error reading date from \"%s\"\n",line.gettoken_str(1)); return PS_ERROR; } +#else + struct stat st; + if (!stat(line.gettoken_str(1), &st)) + { + union + { + struct + { + long l; + long h; + } words; + long long ll; + }; + ll = (st.st_mtime * 10000000) + 116444736000000000LL; + high = words.h; + low = words.l; + } + else + { + ERROR_MSG("GetFileTimeLocal: error reading date from \"%s\"\n",line.gettoken_str(1)); + return PS_ERROR; + } +#endif ent.which=EW_ASSIGNVAR; ent.offsets[0]=GetUserVarIndex(line, 2); @@ -5153,7 +5247,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int i = 1; int nounload = 0; - if (!lstrcmpi(line.gettoken_str(i), "/NOUNLOAD")) { + if (!strcmpi(line.gettoken_str(i), "/NOUNLOAD")) { i++; nounload++; } @@ -5166,7 +5260,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int w=parmst + (line.getnumtokens()-i - 1); ent.which=EW_PUSHPOP; ent.offsets[0]=add_string(line.gettoken_str(w)); - if (!lstrcmpi(line.gettoken_str(w), "/NOUNLOAD")) nounloadmisused=1; + if (!strcmpi(line.gettoken_str(w), "/NOUNLOAD")) nounloadmisused=1; ent.offsets[1]=0; ret=add_entry(&ent); if (ret != PS_OK) { @@ -5257,15 +5351,25 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn { char dir[1024]; char newfn[1024]; +#ifdef _WIN32 HANDLE h; WIN32_FIND_DATA d; +#else + glob_t globbuf; +#endif strcpy(dir,lgss); { char *s=dir+strlen(dir); - while (s > dir && *s != '\\') s=CharPrev(dir,s); + while (s > dir && *s != PATH_SEPARATOR_C) s=CharPrev(dir,s); *s=0; + if (!*dir) + { + dir[0] = '.'; + dir[1] = 0; + } } +#ifdef _WIN32 h = FindFirstFile(lgss,&d); if (h != INVALID_HANDLE_VALUE) { @@ -5273,12 +5377,29 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn { if ((d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { +#else + glob(lgss, GLOB_NOSORT, NULL, &globbuf); + { + for (unsigned int i = 0; i < globbuf.gl_pathc; i++) + { + struct stat s; + if (!stat(globbuf.gl_pathv[i], &s) && S_ISREG(s.st_mode)) + { + char *filename = strrchr(globbuf.gl_pathv[i], PATH_SEPARATOR_C); + if (filename) + filename++; + else + filename = globbuf.gl_pathv[i]; +#endif MMapFile mmap; - HANDLE hFile; DWORD len; (*total_files)++; - sprintf(newfn,"%s%s%s",dir,dir[0]?"\\":"",d.cFileName); - hFile=CreateFile( + +#ifdef _WIN32 + HANDLE hFile; + + sprintf(newfn,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",d.cFileName); + hFile = CreateFile( newfn, GENERIC_READ, FILE_SHARE_READ, @@ -5289,21 +5410,49 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn ); if (hFile == INVALID_HANDLE_VALUE) { + FindClose(h); ERROR_MSG("%sFile: failed opening file \"%s\"\n",generatecode?"":"Reserve",newfn); return PS_ERROR; } len = GetFileSize(hFile, NULL); if (len && !mmap.setfile(hFile, len)) { + FindClose(h); CloseHandle(hFile); ERROR_MSG("%sFile: failed creating mmap of \"%s\"\n",generatecode?"":"Reserve",newfn); return PS_ERROR; } +#else + int fd; + + sprintf(newfn,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",filename); + len = (DWORD) s.st_size; + + fd = open(newfn, O_RDONLY); + if (fd == -1) + { + globfree(&globbuf); + ERROR_MSG("%sFile: failed opening file \"%s\"\n",generatecode?"":"Reserve",newfn); + return PS_ERROR; + } + if (len && !mmap.setfile(fd, len)) + { + globfree(&globbuf); + close(fd); + ERROR_MSG("%sFile: failed creating mmap of \"%s\"\n",generatecode?"":"Reserve",newfn); + return PS_ERROR; + } +#endif if (generatecode&1) section_add_size_kb((len+1023)/1024); +#ifdef _WIN32 if (name_override) SCRIPT_MSG("%sFile: \"%s\"->\"%s\"",generatecode?"":"Reserve",d.cFileName,name_override); else SCRIPT_MSG("%sFile: \"%s\"",generatecode?"":"Reserve",d.cFileName); +#else + if (name_override) SCRIPT_MSG("%sFile: \"%s\"->\"%s\"",generatecode?"":"Reserve",filename,name_override); + else SCRIPT_MSG("%sFile: \"%s\"",generatecode?"":"Reserve",filename); +#endif if (!build_compress_whole) if (build_compress) SCRIPT_MSG(" [compress]"); fflush(stdout); @@ -5327,7 +5476,11 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn } else { +#ifdef _WIN32 char *i=d.cFileName,*o=buf; +#else + char *i=filename,*o=buf; +#endif while (*i) { char c=*i++; @@ -5344,7 +5497,13 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn if (ent.offsets[2] < 0) { +#ifdef _WIN32 CloseHandle(hFile); + FindClose(h); +#else + close(fd); + globfree(&globbuf); +#endif return PS_ERROR; } @@ -5364,6 +5523,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn { if (build_datesave || build_overwrite>=0x3 /*ifnewer or ifdiff*/) { +#ifdef _WIN32 FILETIME ft; if (GetFileTime(hFile,NULL,NULL,&ft)) { @@ -5373,6 +5533,29 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn else { CloseHandle(hFile); + FindClose(h); +#else + struct stat st; + if (!fstat(fd, &st)) + { + union + { + struct + { + long l; + long h; + } words; + long long ll; + }; + ll = (st.st_mtime * 10000000) + 116444736000000000LL; + ent.offsets[3] = words.l; + ent.offsets[4] = words.h; + } + else + { + close(fd); + globfree(&globbuf); +#endif ERROR_MSG("%sFile: failed getting file date from \"%s\"\n",generatecode?"":"Reserve",newfn); return PS_ERROR; } @@ -5402,18 +5585,27 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn ent.offsets[5] = DefineInnerLangString(build_allowskipfiles ? NLF_FILE_ERROR : NLF_FILE_ERROR_NOIGNORE); } +#ifdef _WIN32 CloseHandle(hFile); +#else + close(fd); +#endif if (generatecode) { int a=add_entry(&ent); if (a != PS_OK) { +#ifdef _WIN32 FindClose(h); +#else + globfree(&globbuf); +#endif return a; } if (attrib) { +#ifdef _WIN32 ent.which=EW_SETFILEATTRIBUTES; // $OUTDIR is the working directory ent.offsets[0]=add_string(name_override?name_override:buf); @@ -5429,32 +5621,65 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn FindClose(h); return a; } +#else + warning_fl("File /a is disabled for non Win32 platforms."); +#endif } } } - } while (FindNextFile(h,&d)); + } +#ifdef _WIN32 + while (FindNextFile(h,&d)); FindClose(h); +#else + globfree(&globbuf); +#endif } if (recurse) { #ifdef NSIS_SUPPORT_STACK +#ifdef _WIN32 WIN32_FIND_DATA temp; +#endif - DWORD a=GetFileAttributes(lgss); +#ifdef _WIN32 const char *fspec=lgss+strlen(dir)+!!dir[0]; +#else + const char *fspec; + if (!strcmp(dir,".") && strncmp(lgss,".",1)) + fspec=lgss; + else + fspec=lgss+strlen(dir)+!!dir[0]; +#endif strcpy(newfn,lgss); +#ifdef _WIN32 + DWORD a=GetFileAttributes(lgss); if (a==INVALID_FILE_ATTRIBUTES) { a=GetFileAttributes(dir); - sprintf(newfn,"%s%s*.*",dir,dir[0]?"\\":""); + sprintf(newfn,"%s%s*.*",dir,dir[0]?PATH_SEPARATOR_STR:""); } +#else + int a; + struct stat st; + if (stat(lgss, &st)) + { + stat(dir, &st); + sprintf(newfn,"%s%s*",dir,dir[0]?PATH_SEPARATOR_STR:""); + } +#endif else { // we don't want to include a whole directory if it's not the first call if (rec_depth) return PS_OK; +#ifdef _WIN32 fspec="*.*"; +#else + fspec="*"; +#endif } +#ifdef _WIN32 if (a&FILE_ATTRIBUTE_DIRECTORY) { h=FindFirstFile(newfn,&d); @@ -5466,10 +5691,33 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn { if (strcmp(d.cFileName,"..") && strcmp(d.cFileName,".")) { +#else + if (S_ISDIR(st.st_mode)) + { + if (!glob(newfn, GLOB_NOSORT, NULL, &globbuf)) + { + for (unsigned int i = 0; i < globbuf.gl_pathc; i++) + { + struct stat s; + if (!stat(globbuf.gl_pathv[i], &s) && S_ISDIR(s.st_mode)) + { + char *dirname = strrchr(globbuf.gl_pathv[i], PATH_SEPARATOR_C); + if (dirname) + dirname++; + else + dirname = globbuf.gl_pathv[i]; + if (strcmp(dirname, "..") && strcmp(dirname, ".")) + { +#endif char out_path[1024] = "$OUTDIR\\"; { - char *i = d.cFileName, *o=out_path+strlen(out_path); +#ifdef _WIN32 + char *i = d.cFileName; +#else + char *i = dirname; +#endif + char *o=out_path+strlen(out_path); while (*i) { @@ -5493,35 +5741,58 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn } char spec[1024]; - sprintf(spec,"%s%s%s",dir,dir[0]?"\\":"",d.cFileName); +#ifdef _WIN32 + wsprintf(spec,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",d.cFileName); +#else + wsprintf(spec,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",dirname); +#endif SCRIPT_MSG("%sFile: Descending to: \"%s\"\n",generatecode?"":"Reserve",spec); - strcat(spec,"\\"); + strcat(spec,PATH_SEPARATOR_STR); strcat(spec,fspec); if (generatecode) { a=add_entry_direct(EW_PUSHPOP, add_string("$OUTDIR")); if (a != PS_OK) { +#ifdef _WIN32 FindClose(h); +#else + globfree(&globbuf); +#endif return a; } a=add_entry_direct(EW_ASSIGNVAR, m_UserVarNames.get("OUTDIR"), add_string(out_path)); if (a != PS_OK) { +#ifdef _WIN32 FindClose(h); +#else + globfree(&globbuf); +#endif return a; } +#ifdef _WIN32 HANDLE htemp = FindFirstFile(spec,&temp); if (htemp != INVALID_HANDLE_VALUE) { FindClose(htemp); +#else + glob_t globbuf2; + glob(spec, GLOB_NOSORT, NULL, &globbuf2); + if (globbuf2.gl_pathc) + { +#endif a=add_entry_direct(EW_CREATEDIR, add_string("$OUTDIR"), 1); if (a != PS_OK) { +#ifdef _WIN32 FindClose(h); +#else + globfree(&globbuf2); +#endif return a; } } @@ -5529,7 +5800,11 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn a=do_add_file(spec,attrib,recurse,linecnt,total_files,NULL,generatecode,data_handle,rec_depth+1); if (a != PS_OK) { +#ifdef _WIN32 FindClose(h); +#else + globfree(&globbuf); +#endif return a; } @@ -5538,25 +5813,38 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn a=add_entry_direct(EW_PUSHPOP, m_UserVarNames.get("OUTDIR"), 1); if (a != PS_OK) { +#ifdef _WIN32 FindClose(h); +#else + globfree(&globbuf); +#endif return a; } if (attrib) { +#ifdef _WIN32 a=add_entry_direct(EW_SETFILEATTRIBUTES, add_string(out_path), d.dwFileAttributes); if (a != PS_OK) { FindClose(h); return a; } +#else + warning_fl("File /a is disabled for non Win32 platforms."); +#endif } } SCRIPT_MSG("%sFile: Returning to: \"%s\"\n",generatecode?"":"Reserve",dir); } } - } while (FindNextFile(h,&d)); + } +#ifdef _WIN32 + while (FindNextFile(h,&d)); FindClose(h); +#else + globfree(&globbuf); +#endif if (!rec_depth) { @@ -5564,7 +5852,6 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn a=add_entry_direct(EW_CREATEDIR, add_string("$OUTDIR"), 1); if (a != PS_OK) { - FindClose(h); return a; } } diff --git a/Source/strlist.h b/Source/strlist.h index 049a1c2b..692df17b 100644 --- a/Source/strlist.h +++ b/Source/strlist.h @@ -4,6 +4,12 @@ #include "Platform.h" #include #include // for gcc +#ifndef _WIN32 +# include +# include +# include +# include +#endif class IGrowBuf { @@ -20,9 +26,10 @@ class IMMap virtual void resize(int newlen)=0; virtual int getsize()=0; virtual void *get(int offset, int size)=0; - virtual void *getmore(int offset, int size)=0; + virtual void *get(int offset, int *size)=0; + virtual void *getmore(int offset, int *size)=0; virtual void release()=0; - virtual void release(void *view)=0; + virtual void release(void *view, int size)=0; virtual void clear()=0; virtual void setro(BOOL bRO)=0; virtual void flush(int num)=0; @@ -485,8 +492,13 @@ class MMapFile : public IMMap public: MMapFile() { +#ifdef _WIN32 m_hFile = INVALID_HANDLE_VALUE; m_hFileMap = NULL; +#else + m_hFile = -1; +#endif + m_pView = NULL; m_iSize = 0; m_bReadOnly = FALSE; @@ -494,9 +506,13 @@ class MMapFile : public IMMap if (!m_iAllocationGranularity) { +#ifdef _WIN32 SYSTEM_INFO si; GetSystemInfo(&si); m_iAllocationGranularity = (int) si.dwAllocationGranularity; +#else + m_iAllocationGranularity = getpagesize(); +#endif } } @@ -509,12 +525,17 @@ class MMapFile : public IMMap { release(); +#ifdef _WIN32 if (m_hFileMap) CloseHandle(m_hFileMap); if (m_bTempHandle && m_hFile) CloseHandle(m_hFile); m_hFileMap = 0; +#else + if (m_bTempHandle && m_hFile) + close(m_hFile); +#endif } void setro(BOOL bRO) @@ -522,21 +543,22 @@ class MMapFile : public IMMap m_bReadOnly = bRO; } +#ifdef _WIN32 int setfile(HANDLE hFile, DWORD dwSize) +#else + int setfile(int hFile, DWORD dwSize) +#endif { - release(); - - if (m_hFileMap) - CloseHandle(m_hFileMap); - if (m_bTempHandle && m_hFile) - CloseHandle(m_hFile); - - m_hFileMap = 0; + clear(); m_hFile = hFile; m_bTempHandle = FALSE; +#ifdef _WIN32 if (m_hFile == INVALID_HANDLE_VALUE) +#else + if (m_hFile == -1) +#endif return 0; m_iSize = (int) dwSize; @@ -544,10 +566,12 @@ class MMapFile : public IMMap if (m_iSize <= 0) return 0; +#ifdef _WIN32 m_hFileMap = CreateFileMapping(m_hFile, NULL, PAGE_READONLY, 0, m_iSize, NULL); if (!m_hFileMap) return 0; +#endif m_bReadOnly = TRUE; @@ -560,13 +584,16 @@ class MMapFile : public IMMap if (newsize > m_iSize) { +#ifdef _WIN32 if (m_hFileMap) CloseHandle(m_hFileMap); m_hFileMap = 0; +#endif m_iSize = newsize; +#ifdef _WIN32 if (m_hFile == INVALID_HANDLE_VALUE) { char buf[MAX_PATH], buf2[MAX_PATH]; @@ -610,6 +637,14 @@ class MMapFile : public IMMap } quit(); } +#else + if (m_hFile == -1) + { + char tmp[] = "/tmp/makensisXXXXXX"; + m_hFile = mkstemp(tmp); + m_bTempHandle = TRUE; + } +#endif } } @@ -620,9 +655,19 @@ class MMapFile : public IMMap void *get(int offset, int size) { + return get(offset, &size); + } + + void *get(int offset, int *sizep) + { + if (!sizep) + return NULL; + if (m_pView) release(); + int size = *sizep; + if (!m_iSize || offset + size > m_iSize) { extern FILE *g_output; @@ -639,9 +684,18 @@ class MMapFile : public IMMap int alignedoffset = offset - (offset % m_iAllocationGranularity); size += offset - alignedoffset; +#ifdef _WIN32 m_pView = MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, alignedoffset, size); +#else + m_pView = mmap(0, size, m_bReadOnly ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, m_hFile, alignedoffset); + m_iMappedSize = *sizep = size; +#endif +#ifdef _WIN32 if (!m_pView) +#else + if (m_pView == MAP_FAILED) +#endif { extern FILE *g_output; extern void quit(); extern int g_display_errors; @@ -656,13 +710,19 @@ class MMapFile : public IMMap return (void *)((char *)m_pView + offset - alignedoffset); } - void *getmore(int offset, int size) + void *getmore(int offset, int *size) { void *pView; void *pViewBackup = m_pView; +#ifndef _WIN32 + int iMappedSizeBackup = m_iMappedSize; +#endif m_pView = 0; pView = get(offset, size); m_pView = pViewBackup; +#ifndef _WIN32 + m_iMappedSize = iMappedSizeBackup; +#endif return pView; } @@ -671,26 +731,43 @@ class MMapFile : public IMMap if (!m_pView) return; +#ifdef _WIN32 UnmapViewOfFile(m_pView); +#else + munmap(m_pView, m_iMappedSize); +#endif m_pView = NULL; } - void release(void *pView) + void release(void *pView, int size) { if (!pView) return; +#ifdef _WIN32 UnmapViewOfFile(pView); +#else + munmap(pView, size); +#endif } void flush(int num) { if (m_pView) +#ifdef _WIN32 FlushViewOfFile(m_pView, num); +#else + msync(m_pView, num, MS_SYNC); +#endif } private: +#ifdef _WIN32 HANDLE m_hFile, m_hFileMap; +#else + int m_hFile; + int m_iMappedSize; +#endif void *m_pView; int m_iSize; BOOL m_bReadOnly; @@ -721,19 +798,24 @@ class MMapFake : public IMMap void *get(int offset, int size) { - if (offset + size > m_iSize) + return get(offset, &size); + } + + void *get(int offset, int *size) + { + if (!size || (offset + *size > m_iSize)) return NULL; return (void *)(m_pMem + offset); } - void *getmore(int offset, int size) + void *getmore(int offset, int *size) { return get(offset, size); } void resize(int n) {} void release() {} - void release(void *p) {} + void release(void *p, int size) {} void clear() {} void setro(BOOL b) {} void flush(BOOL b) {} @@ -817,6 +899,14 @@ class MMapBuf : public IGrowBuf, public IMMap return get(0, m_alloc); } + void *get(int offset, int *sizep) + { + if (!sizep) + return NULL; + int size = *sizep; + return get(offset, size); + } + void *get(int offset, int size) { if (m_gb_u) @@ -824,7 +914,7 @@ class MMapBuf : public IGrowBuf, public IMMap return (void *) ((char *) m_gb.get() + offset); } - void *getmore(int offset, int size) + void *getmore(int offset, int *size) { if (m_gb_u) return m_fm.getmore(offset, size); @@ -837,10 +927,10 @@ class MMapBuf : public IGrowBuf, public IMMap m_fm.release(); } - void release(void *pView) + void release(void *pView, int size) { if (m_gb_u) - m_fm.release(pView); + m_fm.release(pView, size); } void clear() diff --git a/Source/uservars.h b/Source/uservars.h index bdc094fe..39252a2c 100644 --- a/Source/uservars.h +++ b/Source/uservars.h @@ -3,7 +3,7 @@ #ifndef ___USERVARS___H_____ #define ___USERVARS___H_____ -#include "Lang.h" +#include "lang.h" struct uservarstring { int name; diff --git a/Source/util.cpp b/Source/util.cpp index 57e4cc84..b7171468 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -1,7 +1,6 @@ #include "Platform.h" #include #include -#include #include "exedata.h" #include "exehead/fileform.h" #include "util.h" @@ -18,7 +17,7 @@ void dopause(void) if (g_display_errors) fprintf(g_output,"MakeNSIS done - hit enter to close..."); fflush(stdout); int a; - while ((a=_getch()) != '\r' && a != 27/*esc*/); + while ((a=getchar()) != '\r' && a != '\n' && a != 27/*esc*/); } } @@ -82,7 +81,7 @@ int update_bitmap(CResourceEditor* re, WORD id, char* filename, int width/*=0*/, } fclose(f); - re->UpdateResource(RT_BITMAP, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), bitmap, dwSize); + re->UpdateResource(RT_BITMAP, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, bitmap, dwSize); free(bitmap); @@ -146,7 +145,7 @@ int replace_icon(CResourceEditor* re, WORD wIconId, char* filename) int i = 1; // Delete old icons - while (re->UpdateResource(RT_ICON, MAKEINTRESOURCE(i++), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0)); + while (re->UpdateResource(RT_ICON, MAKEINTRESOURCE(i++), NSIS_DEFAULT_LANG, 0, 0)); int iNewIconSize = 0; @@ -170,7 +169,7 @@ int replace_icon(CResourceEditor* re, WORD wIconId, char* filename) throw bad_alloc(); } fread(iconData, sizeof(BYTE), ige->dwRawSize, f); - re->UpdateResource(RT_ICON, MAKEINTRESOURCE(i+1), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), iconData, ige->dwRawSize); + re->UpdateResource(RT_ICON, MAKEINTRESOURCE(i+1), NSIS_DEFAULT_LANG, iconData, ige->dwRawSize); free(iconData); fsetpos(f, &pos); @@ -185,7 +184,7 @@ int replace_icon(CResourceEditor* re, WORD wIconId, char* filename) fclose(f); - re->UpdateResource(RT_GROUP_ICON, MAKEINTRESOURCE(wIconId), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), rsrcIconGroup, sizeof(IconGroupHeader) + igh.wCount*SIZEOF_RSRC_ICON_GROUP_ENTRY); + re->UpdateResource(RT_GROUP_ICON, MAKEINTRESOURCE(wIconId), NSIS_DEFAULT_LANG, rsrcIconGroup, sizeof(IconGroupHeader) + igh.wCount*SIZEOF_RSRC_ICON_GROUP_ENTRY); free(rsrcIconGroup); @@ -300,20 +299,20 @@ int generate_unicons_offsets(unsigned char* exeHeader, unsigned char* uninstIcon int idx = find_in_dir(rdRoot, (WORD) (int) RT_ICON); MY_ASSERT(idx == -1, "no icons?!"); - MY_ASSERT(!rdRoot->Entries[idx].DataIsDirectory, "bad resource directory"); + MY_ASSERT(!rdRoot->Entries[idx].DirectoryOffset.DataIsDirectory, "bad resource directory"); - PRESOURCE_DIRECTORY rdIcons = PRESOURCE_DIRECTORY(rdRoot->Entries[idx].OffsetToDirectory + DWORD(rdRoot)); + PRESOURCE_DIRECTORY rdIcons = PRESOURCE_DIRECTORY(rdRoot->Entries[idx].DirectoryOffset.OffsetToDirectory + DWORD(rdRoot)); MY_ASSERT((int)rdIcons - (int)exeHeader > iNextSection, "corrupted EXE - invalid pointer"); MY_ASSERT(rdIcons->Header.NumberOfIdEntries == 0, "no icons found"); for (i = 0; i < rdIcons->Header.NumberOfIdEntries; i++) { // Icons dir can't have named entries - MY_ASSERT(!rdIcons->Entries[i].DataIsDirectory, "bad resource directory"); - PRESOURCE_DIRECTORY rd = PRESOURCE_DIRECTORY(rdIcons->Entries[i].OffsetToDirectory + DWORD(rdRoot)); + MY_ASSERT(!rdIcons->Entries[i].DirectoryOffset.DataIsDirectory, "bad resource directory"); + PRESOURCE_DIRECTORY rd = PRESOURCE_DIRECTORY(rdIcons->Entries[i].DirectoryOffset.OffsetToDirectory + DWORD(rdRoot)); MY_ASSERT((int)rd - (int)exeHeader > iNextSection, "corrupted EXE - invalid pointer"); - MY_ASSERT(rd->Entries[0].DataIsDirectory, "bad resource directory"); + MY_ASSERT(rd->Entries[0].DirectoryOffset.DataIsDirectory, "bad resource directory"); PIMAGE_RESOURCE_DATA_ENTRY rde = PIMAGE_RESOURCE_DATA_ENTRY(rd->Entries[0].OffsetToData + DWORD(rdRoot)); @@ -352,30 +351,45 @@ int generate_unicons_offsets(unsigned char* exeHeader, unsigned char* uninstIcon seeker += dwSize; } - return PIMAGE_RESOURCE_DATA_ENTRY(PRESOURCE_DIRECTORY(rdIcons->Entries[0].OffsetToDirectory + DWORD(rdRoot))->Entries[0].OffsetToData + DWORD(rdRoot))->OffsetToData + DWORD(rdRoot) - dwResourceSectionVA - DWORD(exeHeader); + return PIMAGE_RESOURCE_DATA_ENTRY(PRESOURCE_DIRECTORY(rdIcons->Entries[0].DirectoryOffset.OffsetToDirectory + DWORD(rdRoot))->Entries[0].OffsetToData + DWORD(rdRoot))->OffsetToData + DWORD(rdRoot) - dwResourceSectionVA - DWORD(exeHeader); } #endif // NSIS_CONFIG_UNINSTALL_SUPPORT -#ifdef NSIS_CONFIG_VISIBLE_SUPPORT -BYTE* get_dlg(HINSTANCE hUIFile, WORD dlgId, char* filename) { - HRSRC hUIRes = FindResource(hUIFile, MAKEINTRESOURCE(dlgId), RT_DIALOG); - if (!hUIRes) { - if (g_display_errors) fprintf(g_output, "Error: \"%s\" doesn't contain a dialog with the ID %u!\n", filename, dlgId); - return 0; - } - HGLOBAL hUIMem = LoadResource(hUIFile, hUIRes); - if (!hUIMem) { - if (g_display_errors) fprintf(g_output, "Error: Can't load a dialog from \"%s\"!\n", filename); - return 0; - } - BYTE* pbUIData = (BYTE*)LockResource(hUIMem); - if (!pbUIData) { - if (g_display_errors) fprintf(g_output, "Error: Can't lock resource from \"%s\"!\n", filename); - return 0; - } - return pbUIData; +// returns the number of WCHARs in str including null charcter +int WCStrLen(const WCHAR* szwStr) { + int i; + for (i = 0; szwStr[i]; i++); + return i+1; } -#endif //NSIS_CONFIG_VISIBLE_SUPPORT + +#ifndef _WIN32 +char *CharPrev(const char *s, const char *p) { + if (!s || !p || p < s) + return NULL; + while (*s) { + char *n = CharNext(s); + if (n >= p) + break; + s = n; + } + return (char *) s; +} + +char *CharNext(const char *s) { + int l = 0; + if (s && *s) + l = min(1, mblen(s, strlen(s))); + return (char *) s + l; +} + +int wsprintf(char *s, const char *format, ...) { + va_list val; + va_start(val, format); + int res = vsnprintf(s, 1024, format, val); + va_end(val); + return res; +} +#endif void *operator new(size_t size) { void *p = malloc(size); diff --git a/Source/util.h b/Source/util.h index 2ca0a71d..43f498b0 100644 --- a/Source/util.h +++ b/Source/util.h @@ -1,6 +1,9 @@ #ifndef _UTIL_H_ #define _UTIL_H_ +#ifndef _WIN32 +# include +#endif #include "ResourceEditor.h" // these are the standard pause-before-quit shit. @@ -21,9 +24,22 @@ unsigned char* generate_uninstall_icon_data(char* filename); int generate_unicons_offsets(unsigned char* exeHeader, unsigned char* uninstIconData); #endif//NSIS_CONFIG_UNINSTALL_SUPPORT -#ifdef NSIS_CONFIG_VISIBLE_SUPPORT -// Returns dialog's raw data from a given loaded module -BYTE* get_dlg(HINSTANCE hUIFile, WORD dlgId, char* filename); +// returns the number of WCHARs in str including null charcter +int WCStrLen(const WCHAR* szwStr); + +#ifndef _WIN32 +char *CharPrev(const char *s, const char *p); +char *CharNext(const char *s); +int wsprintf(char *s, const char *format, ...); +// iconv const inconsistency workaround by Alexandre Oliva +template +inline size_t __iconv_adaptor + (size_t (*iconv_func)(iconv_t, T, size_t *, char**,size_t*), + iconv_t cd, char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + return iconv_func (cd, (T)inbuf, inbytesleft, outbuf, outbytesleft); +} #endif #endif //_UTIL_H_ diff --git a/Source/zlib/DEFLATE.H b/Source/zlib/DEFLATE.H index e4a48948..0323cf78 100644 --- a/Source/zlib/DEFLATE.H +++ b/Source/zlib/DEFLATE.H @@ -7,7 +7,7 @@ #ifndef _DEFLATE_H #define _DEFLATE_H -#include "zutil.h" +#include "ZUTIL.H" /* =========================================================================== * Internal compression state. diff --git a/Source/zlib/INFBLOCK.C b/Source/zlib/INFBLOCK.C index e7cdd9cb..91be4db3 100644 --- a/Source/zlib/INFBLOCK.C +++ b/Source/zlib/INFBLOCK.C @@ -76,7 +76,7 @@ local inflate_huft *fixed_tl; local inflate_huft *fixed_td; /* copy as much as possible from the sliding window to the output area */ -local void inflate_flush(z) +local void ZEXPORT inflate_flush(z) z_streamp z; { inflate_blocks_statef *s = &z->blocks; @@ -118,7 +118,7 @@ again: #define BMAX 15 /* maximum bit length of any code */ -local int huft_build( +local int ZEXPORT huft_build( uIntf *b, /* code lengths in bits (all assumed <= BMAX) */ uInt n, /* number of codes (assumed <= 288) */ uInt s, /* number of simple-valued codes (0..s-1) */ @@ -306,7 +306,7 @@ uInt *hn) /* working area: values in order of bit length */ return (y != 0 && g != 1) ? Z_BUF_ERROR : Z_OK; } -int inflate(z_streamp z) +int ZEXPORT inflate(z_streamp z) { inflate_blocks_statef *s = &z->blocks; inflate_codes_statef *c = &s->sub.decode.t_codes; /* codes state */ diff --git a/Source/zlib/ZLIB.H b/Source/zlib/ZLIB.H index ee967d6f..58ef510d 100644 --- a/Source/zlib/ZLIB.H +++ b/Source/zlib/ZLIB.H @@ -42,8 +42,8 @@ #ifndef _ZLIB_H #define _ZLIB_H -#include "zconf.h" -#include "zutil.h" +#include "ZCONF.H" +#include "ZUTIL.H" #ifdef __cplusplus extern "C" { diff --git a/Source/zlib/ZUTIL.H b/Source/zlib/ZUTIL.H index 944e0db3..0ccb70e1 100644 --- a/Source/zlib/ZUTIL.H +++ b/Source/zlib/ZUTIL.H @@ -8,13 +8,13 @@ subject to change. Applications should only use zlib.h. */ -/* @(#) $Id: ZUTIL.H,v 1.1.1.1 2002/08/02 10:01:35 kichik Exp $ */ +/* @(#) $Id: ZUTIL.H,v 1.2 2002/09/22 20:02:03 eccles Exp $ */ #ifndef _Z_UTIL_H #define _Z_UTIL_H -#include -#include "zlib.h" +#include "../Platform.h" +#include "ZLIB.H" #ifndef local # define local static @@ -63,10 +63,11 @@ typedef unsigned long ulg; #ifdef EXEHEAD #include "../exehead/util.h" #define ZALLOC(strm, items, size) my_GlobalAlloc((items)*(size)) -#else // def EXEHEAD -#define ZALLOC(strm, items, size) GlobalAlloc(GPTR,(items)*(size)) -#endif // def EXEHEAD #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 d5777bf3..9a5464ca 100644 --- a/Source/zlib/deflate.c +++ b/Source/zlib/deflate.c @@ -4,7 +4,7 @@ */ -#include "deflate.h" +#include "DEFLATE.H" const char deflate_copyright[] = " deflate 1.1.3 Copyright 1995-1998 Jean-loup Gailly "; @@ -728,7 +728,7 @@ local void fill_window(s) s->ins_h = s->window[s->strstart]; UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); #if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times +# error Call UPDATE_HASH() MIN_MATCH-3 more times #endif } diff --git a/Source/zlib/trees.c b/Source/zlib/trees.c index b5907433..22d2734e 100644 --- a/Source/zlib/trees.c +++ b/Source/zlib/trees.c @@ -4,7 +4,7 @@ */ -#include "deflate.h" +#include "DEFLATE.H" #ifdef DEBUG # include