- makensis should now compile on any POSIX compliment platform (Linux, *BSD, Mac OS X, etc.)

- improved makefiles so nothing is compiled when it's already up-to-date
- Added SW_HIDE to ExecShell's accepted show modes


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3518 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2004-03-29 20:21:00 +00:00
parent 8567625b0e
commit 4c5f8a30eb
46 changed files with 2054 additions and 679 deletions

View file

@ -2,11 +2,13 @@
// #include "StdAfx.h" // #include "StdAfx.h"
#ifndef INITGUID #ifdef WIN32
#define INITGUID # include <objbase.h>
# include <initguid.h>
#endif #endif
#include <objbase.h>
#include <initguid.h>
#include "../Platform.h" #include "../Platform.h"
#define INITGUID
#include "7zip/ICoder.h" #include "7zip/ICoder.h"
#include "7zip/Compress/LZ/IMatchFinder.h" #include "7zip/Compress/LZ/IMatchFinder.h"

View file

@ -3,6 +3,10 @@
#ifndef __STDAFX_H #ifndef __STDAFX_H
#define __STDAFX_H #define __STDAFX_H
#include <windows.h> #ifdef _WIN32
# include <windows.h>
#else
# include "../../../Platform.h"
#endif
#endif #endif

View file

@ -15,7 +15,8 @@ namespace BT_NAMESPACE {
#ifdef __USE_3_BYTES #ifdef __USE_3_BYTES
#pragma pack(push, PragmaBinTree, 1) //#pragma pack(push, PragmaBinTree, 1)
#pragma pack(1)
struct CIndex struct CIndex
{ {
@ -31,7 +32,8 @@ struct CIndex
}; };
const UINT32 kMaxValForNormalize = CIndex(-1); const UINT32 kMaxValForNormalize = CIndex(-1);
#pragma pack(pop, PragmaBinTree) //#pragma pack(pop, PragmaBinTree)
#pragma pack()
#else #else
@ -54,7 +56,8 @@ const UINT32 kMaxValForNormalize = (UINT32(1) << 31) - 1;
// #endif // #endif
#pragma pack(push, PragmaBinTreePair, 1) //#pragma pack(push, PragmaBinTreePair, 1)
#pragma pack(1)
// #pragma pack(push, 1) // #pragma pack(push, 1)
struct CPair struct CPair
@ -64,7 +67,8 @@ struct CPair
}; };
// #pragma pack(pop) // #pragma pack(pop)
#pragma pack(pop, PragmaBinTreePair) //#pragma pack(pop, PragmaBinTreePair)
#pragma pack()
class CInTree: public CLZInWindow class CInTree: public CLZInWindow
{ {

View file

@ -40,13 +40,13 @@ namespace BT_NAMESPACE {
CInTree::CInTree(): CInTree::CInTree():
_hash(0),
#ifdef HASH_ARRAY_2 #ifdef HASH_ARRAY_2
_hash2(0), _hash2(0),
#ifdef HASH_ARRAY_3 #ifdef HASH_ARRAY_3
_hash3(0), _hash3(0),
#endif #endif
#endif #endif
_hash(0),
_son(0), _son(0),
_cutValue(0xFF) _cutValue(0xFF)
{ {
@ -134,7 +134,7 @@ static const UINT32 kEmptyHashValue = 0;
HRESULT CInTree::Init(ISequentialInStream *stream) HRESULT CInTree::Init(ISequentialInStream *stream)
{ {
RINOK(CLZInWindow::Init(stream)); RINOK(CLZInWindow::Init(stream));
int i; unsigned int i;
for(i = 0; i < kHashSize; i++) for(i = 0; i < kHashSize; i++)
_hash[i] = kEmptyHashValue; _hash[i] = kEmptyHashValue;

View file

@ -3,6 +3,10 @@
#ifndef __STDAFX_H #ifndef __STDAFX_H
#define __STDAFX_H #define __STDAFX_H
#include <windows.h> #ifdef _WIN32
# include <windows.h>
#else
# include "../../../../Platform.h"
#endif
#endif #endif

View file

@ -254,10 +254,11 @@ public:
HRESULT Create(); HRESULT Create();
MY_UNKNOWN_IMP2( /*MY_UNKNOWN_IMP2(
ICompressSetCoderProperties, ICompressSetCoderProperties,
ICompressWriteCoderProperties ICompressWriteCoderProperties
) )*/
MY_UNKNOWN_IMP
STDMETHOD(Init)( STDMETHOD(Init)(
ISequentialOutStream *outStream); ISequentialOutStream *outStream);

View file

@ -3,6 +3,10 @@
#ifndef __STDAFX_H #ifndef __STDAFX_H
#define __STDAFX_H #define __STDAFX_H
#include <windows.h> #ifdef _WIN32
# include <windows.h>
#else
# include "../../../../Platform.h"
#endif
#endif #endif

View file

@ -3,6 +3,10 @@
#ifndef __STDAFX_H #ifndef __STDAFX_H
#define __STDAFX_H #define __STDAFX_H
#include <windows.h> #ifdef _WIN32
# include <windows.h>
#else
# include "../../../../Platform.h"
#endif
#endif #endif

View file

@ -5,20 +5,52 @@
#ifndef __MYUNKNOWN_H #ifndef __MYUNKNOWN_H
#define __MYUNKNOWN_H #define __MYUNKNOWN_H
#ifdef WIN32 #ifdef _WIN32
// #include <guiddef.h> // #include <guiddef.h>
#include <basetyps.h> #include <basetyps.h>
#else #else
#include "../../Platform.h"
#include <string>
#define HRESULT LONG #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_(t, f) virtual t STDMETHODCALLTYPE f
#define STDMETHOD(f) STDMETHOD_(HRESULT, f) #define STDMETHOD(f) STDMETHOD_(HRESULT, f)
#define STDMETHODIMP_(type) type STDMETHODCALLTYPE #define STDMETHODIMP_(type) type STDMETHODCALLTYPE
#define STDMETHODIMP STDMETHODIMP_(HRESULT) #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; #define PURE = 0;
typedef struct { typedef struct {
@ -35,33 +67,34 @@ typedef struct {
#endif #endif
#ifdef INITGUID #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 } } MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
#else #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 MY_EXTERN_C const GUID name
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
#define REFGUID const GUID & typedef const GUID & REFGUID;
#else #else
#define REFGUID const GUID * __MIDL_CONST #define REFGUID const GUID * __MIDL_CONST
#endif #endif
#define MIDL_INTERFACE(x) struct #define MIDL_INTERFACE(x) struct
inline int operator==(REFGUID g1, REFGUID g2) 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]) if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])
return false; return false;
return true; return true;
} }
inline int operator!=(REFGUID &g1, REFGUID &g2) inline int operator!=(REFGUID g1, REFGUID g2)
{ return !(g1 == g2); } { return !(g1 == g2); }
struct IUnknown struct IUnknown
{ {
STDMETHOD(QueryInterface) (const GUID *iid, void **outObject) PURE; STDMETHOD(QueryInterface) (REFGUID iid, void **outObject) PURE;
STDMETHOD_(ULONG, AddRef)() PURE; STDMETHOD_(ULONG, AddRef)() PURE;
STDMETHOD_(ULONG, Release)() PURE; STDMETHOD_(ULONG, Release)() PURE;
}; };

View file

@ -50,10 +50,10 @@ public:
_p = NULL; _p = NULL;
return pt; 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); return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);
} }*/
/* /*
HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
{ {
@ -65,16 +65,16 @@ public:
return hr; return hr;
} }
*/ */
template <class Q> /*template <class Q>
HRESULT QueryInterface(REFGUID iid, Q** pp) const HRESULT QueryInterface(REFGUID iid, Q** pp) const
{ {
return _p->QueryInterface(iid, (void**)pp); return _p->QueryInterface(iid, (void**)pp);
} }*/
}; };
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
class CMyComBSTR /*class CMyComBSTR
{ {
public: public:
BSTR m_str; BSTR m_str;
@ -83,7 +83,7 @@ public:
// CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); } // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }
// CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize); } // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize); }
CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); } CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }
/* / *
CMyComBSTR(REFGUID src) CMyComBSTR(REFGUID src)
{ {
LPOLESTR szGuid; LPOLESTR szGuid;
@ -91,7 +91,7 @@ public:
m_str = ::SysAllocString(szGuid); m_str = ::SysAllocString(szGuid);
CoTaskMemFree(szGuid); CoTaskMemFree(szGuid);
} }
*/ * /
~CMyComBSTR() { ::SysFreeString(m_str); } ~CMyComBSTR() { ::SysFreeString(m_str); }
CMyComBSTR& operator=(const CMyComBSTR& src) CMyComBSTR& operator=(const CMyComBSTR& src)
{ {
@ -132,7 +132,7 @@ public:
m_str = NULL; m_str = NULL;
} }
bool operator!() const { return (m_str == NULL); } bool operator!() const { return (m_str == NULL); }
}; };*/
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////

View file

@ -3,6 +3,10 @@
#ifndef __STDAFX_H #ifndef __STDAFX_H
#define __STDAFX_H #define __STDAFX_H
#include <windows.h> #ifdef _WIN32
# include <windows.h>
#else
# include "../../Platform.h"
#endif
#endif #endif

View file

@ -5,7 +5,11 @@
#ifndef __COMMON_TYPES_H #ifndef __COMMON_TYPES_H
#define __COMMON_TYPES_H #define __COMMON_TYPES_H
#include <basetsd.h> #ifdef _WIN32
# include <basetsd.h>
#else
# include "../../Platform.h"
#endif
typedef unsigned char UINT8; typedef unsigned char UINT8;
typedef unsigned short UINT16; typedef unsigned short UINT16;

View file

@ -21,6 +21,12 @@
*/ */
#include "DialogTemplate.h" #include "DialogTemplate.h"
#include "util.h"
#ifndef _WIN32
# include <stdio.h>
# include <stdlib.h>
# include <iconv.h>
#endif
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Utilities // Utilities
@ -28,13 +34,6 @@
#define ALIGN(dwToAlign, dwAlignOn) dwToAlign = (dwToAlign%dwAlignOn == 0) ? dwToAlign : dwToAlign - (dwToAlign%dwAlignOn) + dwAlignOn #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 // Reads a variany length array from seeker into readInto and advances seeker
void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) { void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) {
WORD* arr = (WORD*)seeker; WORD* arr = (WORD*)seeker;
@ -49,16 +48,49 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) {
break; break;
default: default:
{ {
int iStrLen = WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, 0, 0, 0, 0); int iStrLen = 1;
readInto = new char[iStrLen]; #ifdef _WIN32
WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, readInto, iStrLen, 0, 0); iStrLen = WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, 0, 0, 0, 0);
seeker += WCStrLen((WCHAR*)arr)*sizeof(WCHAR); 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; break;
} }
} }
// A macro that writes a given string (that can be a number too) into the buffer // A macro that writes a given string (that can be a number too) into the buffer
#ifdef _WIN32
#define WriteStringOrId(x) \ #define WriteStringOrId(x) \
if (x) \ if (x) \
if (IS_INTRESOURCE(x)) { \ if (IS_INTRESOURCE(x)) { \
@ -73,9 +105,46 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) {
} \ } \
else \ else \
seeker += sizeof(WORD); 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 // 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 // Construction/Destruction
@ -264,7 +333,7 @@ int CDialogTemplate::RemoveItem(WORD wId) {
// Sets the font of the dialog // Sets the font of the dialog
void CDialogTemplate::SetFont(char* szFaceName, WORD wFontSize) { void CDialogTemplate::SetFont(char* szFaceName, WORD wFontSize) {
if (lstrcmp(szFaceName, "MS Shell Dlg")) { if (strcmp(szFaceName, "MS Shell Dlg")) {
// not MS Shell Dlg // not MS Shell Dlg
m_dwStyle &= ~DS_SHELLFONT; m_dwStyle &= ~DS_SHELLFONT;
m_bExtended = false; m_bExtended = false;
@ -276,8 +345,8 @@ void CDialogTemplate::SetFont(char* szFaceName, WORD wFontSize) {
} }
m_dwStyle |= DS_SETFONT; m_dwStyle |= DS_SETFONT;
if (m_szFont) delete [] m_szFont; if (m_szFont) delete [] m_szFont;
m_szFont = new char[lstrlen(szFaceName)+1]; m_szFont = new char[strlen(szFaceName)+1];
lstrcpy(m_szFont, szFaceName); strcpy(m_szFont, szFaceName);
m_sFontSize = wFontSize; m_sFontSize = wFontSize;
} }
@ -287,12 +356,12 @@ void CDialogTemplate::AddItem(DialogItemTemplate item) {
CopyMemory(newItem, &item, sizeof(DialogItemTemplate)); CopyMemory(newItem, &item, sizeof(DialogItemTemplate));
if (item.szClass && !IS_INTRESOURCE(item.szClass)) { if (item.szClass && !IS_INTRESOURCE(item.szClass)) {
newItem->szClass = new char[lstrlen(item.szClass)+1]; newItem->szClass = new char[strlen(item.szClass)+1];
lstrcpy(newItem->szClass, item.szClass); strcpy(newItem->szClass, item.szClass);
} }
if (item.szTitle && !IS_INTRESOURCE(item.szTitle)) { if (item.szTitle && !IS_INTRESOURCE(item.szTitle)) {
newItem->szTitle = new char[lstrlen(item.szTitle)+1]; newItem->szTitle = new char[strlen(item.szTitle)+1];
lstrcpy(newItem->szTitle, item.szTitle); strcpy(newItem->szTitle, item.szTitle);
} }
if (item.wCreateDataSize) { if (item.wCreateDataSize) {
newItem->szCreationData = new char[item.wCreateDataSize]; newItem->szCreationData = new char[item.wCreateDataSize];
@ -315,6 +384,7 @@ void CDialogTemplate::Resize(short x, short y) {
m_sHeight += y; m_sHeight += y;
} }
#ifdef _WIN32
// Creates a dummy dialog that is used for converting units // Creates a dummy dialog that is used for converting units
HWND CDialogTemplate::CreateDummyDialog() { HWND CDialogTemplate::CreateDummyDialog() {
DWORD dwTemp; DWORD dwTemp;
@ -361,7 +431,7 @@ SIZE CDialogTemplate::GetStringSize(WORD id, char *str) {
SelectObject(memDC, font); SelectObject(memDC, font);
SIZE size; SIZE size;
GetTextExtentPoint32(memDC, str, lstrlen(str), &size); GetTextExtentPoint32(memDC, str, strlen(str), &size);
DestroyWindow(hDlg); DestroyWindow(hDlg);
DeleteObject(font); DeleteObject(font);
@ -415,6 +485,7 @@ void CDialogTemplate::CTrimToString(WORD id, char *str, int margins) {
item->sWidth = short(size.cx); item->sWidth = short(size.cx);
item->sHeight = short(size.cy); item->sHeight = short(size.cy);
} }
#endif
// Moves every item right and gives it the WS_EX_RIGHT extended style // Moves every item right and gives it the WS_EX_RIGHT extended style
void CDialogTemplate::ConvertToRTL() { void CDialogTemplate::ConvertToRTL() {
@ -452,12 +523,12 @@ void CDialogTemplate::ConvertToRTL() {
m_vItems[i]->dwStyle |= SS_CENTERIMAGE; 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) { if ((m_vItems[i]->dwStyle & ES_CENTER) == 0) {
m_vItems[i]->dwStyle ^= ES_RIGHT; 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; m_vItems[i]->dwStyle |= TVS_RTLREADING;
addExStyle = true; addExStyle = true;
} }

View file

@ -28,9 +28,9 @@
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include "Platform.h" #include "Platform.h"
#include <Vector> #include <vector>
#include <StdExcept> #include <stdexcept>
using namespace std; using namespace std;
struct DialogItemTemplate { struct DialogItemTemplate {
@ -51,7 +51,19 @@ struct DialogItemTemplate {
WORD wCreateDataSize; 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 { typedef struct {
WORD dlgVer; WORD dlgVer;
@ -66,6 +78,18 @@ typedef struct {
short cy; short cy;
} DLGTEMPLATEEX; } DLGTEMPLATEEX;
#ifndef _WIN32
typedef struct {
DWORD style;
DWORD dwExtendedStyle;
short x;
short y;
short cx;
short cy;
WORD id;
} DLGITEMTEMPLATE;
#endif
typedef struct { typedef struct {
DWORD helpID; DWORD helpID;
DWORD exStyle; DWORD exStyle;
@ -78,7 +102,7 @@ typedef struct {
WORD _miscrosoft_docs_are_wrong; WORD _miscrosoft_docs_are_wrong;
} DLGITEMTEMPLATEEX; } DLGITEMTEMPLATEEX;
#pragma pack(pop) #pragma pack()
class CDialogTemplate { class CDialogTemplate {
public: public:
@ -92,15 +116,19 @@ public:
int RemoveItem(WORD wId); int RemoveItem(WORD wId);
void SetFont(char* szFaceName, WORD wFontSize); void SetFont(char* szFaceName, WORD wFontSize);
void AddItem(DialogItemTemplate item); void AddItem(DialogItemTemplate item);
#ifdef _WIN32
HWND CreateDummyDialog(); HWND CreateDummyDialog();
#endif
void MoveAll(short x, short y); void MoveAll(short x, short y);
void Resize(short x, short y); void Resize(short x, short y);
#ifdef _WIN32
void PixelsToDlgUnits(short& x, short& y); void PixelsToDlgUnits(short& x, short& y);
void DlgUnitsToPixels(short& x, short& y); void DlgUnitsToPixels(short& x, short& y);
SIZE GetStringSize(WORD id, char *str); SIZE GetStringSize(WORD id, char *str);
void RTrimToString(WORD id, char *str, int margins); void RTrimToString(WORD id, char *str, int margins);
void LTrimToString(WORD id, char *str, int margins); void LTrimToString(WORD id, char *str, int margins);
void CTrimToString(WORD id, char *str, int margins); void CTrimToString(WORD id, char *str, int margins);
#endif
void ConvertToRTL(); void ConvertToRTL();
BYTE* Save(DWORD& dwSize); BYTE* Save(DWORD& dwSize);
DWORD GetSize(); DWORD GetSize();

View file

@ -5,79 +5,52 @@
# -- Objects and source files -- # -- 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 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 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++ LIBS = -lgdi32 -lversion -lstdc++
endif
# -- Required .h files --
BASEINC = Platform.h exehead/config.h
# -- Programs -- # -- Programs --
MAKE = make MAKE = make
CC = gcc CC = gcc
RC = windres
RM = rm RM = rm
# -- Compilers and linker flags -- # -- Compilers and linker flags --
DEFINES = -DWIN32 -D_WINDOWS_ DEFINES = -DCOMPRESS_MF_BT
CFLAGS = -Wall -O2 $(DEFINES) CFLAGS = -Wall -O3
CPPFLAGS = -Wall -O2 $(DEFINES) CXXFLAGS = -Wall -O3
LFLAGS = -s CPPFLAGS = $(DEFINES)
RCFLAGS = --input-format rc --output-format coff 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 : cs = zlib bzip2 lzma
$(MAKE) -C exehead $@ 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) makensis : ../makensis.exe
$(CC) $(CFLAGS) $(CPPFLAGS) $(LFLAGS) -o ../makensis.exe $(OBJS) $(LIBS)
# -- Dependencies -- ../makensis.exe : $(SRCS) $(OBJS) $(deps)
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 $(CC) -Wall $(LDFLAGS) -o ../makensis.exe $(OBJS) $(LIBS)
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
# -- Special command lines for zlib -- VPATH=zlib:bzip2:7zip:7zip/Common:7zip/7zip:7zip/7zip/Compress/LZ:7zip/7zip/Compress/LZMA:7zip/7zip/Common:7zip/7zip/Compress/RangeCoder
deflate.o : zlib/deflate.c
$(CC) $(CFLAGS) -c $< -o $@
trees.o : zlib/trees.c
$(CC) $(CFLAGS) -c $< -o $@
# -- Special command lines for bzip2 -- # -- Some dependencies --
blocksort.o : bzip2/blocksort.c $(OBJS) : Platform.h exehead/config.h
$(CC) $(CFLAGS) -c $< -o $@ build.o : czlib.h cbzip2.h clzma.h exehead/fileform.h
bzlib.o : bzip2/bzlib.c script.o : exehead/fileform.h tokens.h
$(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 $@
# -- Clean script -- # -- Clean script --
clean :: clean : clean_makensis
$(MAKE) -C exehead clean $(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

View file

@ -1,6 +1,8 @@
#ifndef ___PLATFORM__H___ #ifndef ___PLATFORM__H___
#define ___PLATFORM__H___ #define ___PLATFORM__H___
// some definitions for non Win32 platforms were taken from MinGW's free Win32 library
// includes // includes
#ifdef _WIN32 #ifdef _WIN32
@ -10,8 +12,51 @@
# include <Windows.h> # include <Windows.h>
# include <commctrl.h> # include <commctrl.h>
#else #else
# define WORD unsigned short # ifndef EXEHEAD
# define DWORD unsigned long # include <string.h>
# include <stdlib.h>
# 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 #endif
// attributes // attributes
@ -42,7 +87,7 @@
# define NSISCALL __stdcall // Ordinary functions # define NSISCALL __stdcall // Ordinary functions
# define NSISCALLV __cdecl // Variable-argument-list functions # define NSISCALLV __cdecl // Variable-argument-list functions
#else #else
# ifdef __GNUC__ # if defined(__GNUC__) && defined(__i386__)
# define NSISCALL __attribute__((__stdcall__)) // Ordinary functions # define NSISCALL __attribute__((__stdcall__)) // Ordinary functions
# define NSISCALLV __attribute__((__cdecl__)) // Variable-argument-list functions # define NSISCALLV __attribute__((__cdecl__)) // Variable-argument-list functions
# else # else
@ -51,141 +96,559 @@
# endif # endif
#endif #endif
// macros
#ifndef _WIN32
# ifndef min
# define min(x,y) ((x<y)?x:y)
# endif
# ifndef max
# define max(x,y) ((x>y)?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 // defines
#ifndef FOF_NOERRORUI #ifndef FOF_NOERRORUI
#define FOF_NOERRORUI 0x0400 # define FOF_NOERRORUI 0x0400
#endif
#ifndef DS_SHELLFONT
#define DS_SHELLFONT (DS_SETFONT | DS_FIXEDSYS)
#endif #endif
#ifndef ULONG_PTR #ifndef ULONG_PTR
#define ULONG_PTR DWORD # define ULONG_PTR DWORD
#endif
#ifndef IS_INTRESOURCE
#define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0)
#endif #endif
#ifndef IDC_HAND #ifndef IDC_HAND
#define IDC_HAND MAKEINTRESOURCE(32649) # define IDC_HAND MAKEINTRESOURCE(32649)
#endif #endif
#ifndef BIF_NEWDIALOGSTYLE #ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 0x0040 # define BIF_NEWDIALOGSTYLE 0x0040
#endif #endif
#ifndef TVITEM #ifndef TVITEM
#define TVITEM TV_ITEM # define TVITEM TV_ITEM
#endif #endif
#ifndef TVM_SETITEMHEIGHT #ifndef TVM_SETITEMHEIGHT
#define TVM_SETITEMHEIGHT (TV_FIRST + 27) # define TVM_SETITEMHEIGHT (TV_FIRST + 27)
#endif #endif
#ifndef TVM_GETITEMHEIGHT #ifndef TVM_GETITEMHEIGHT
#define TVM_GETITEMHEIGHT (TV_FIRST + 28) # define TVM_GETITEMHEIGHT (TV_FIRST + 28)
#endif #endif
#ifndef LVS_EX_LABELTIP #ifndef LVS_EX_LABELTIP
#define LVS_EX_LABELTIP 0x00004000 # define LVS_EX_LABELTIP 0x00004000
#endif #endif
#ifdef __GNUC__ // ((DWORD)-1) may cause parsing errors with MinGW #ifndef EXEHEAD
# ifdef INVALID_FILE_ATTRIBUTES // updated win32api may also set as (DWORD)-1 # ifndef SF_TEXT
# undef INVALID_FILE_ATTRIBUTES # define SF_TEXT 1
# endif # endif
# define INVALID_FILE_ATTRIBUTES ((unsigned long)-1) # ifndef SF_RTF
#else # define SF_RTF 2
# ifndef INVALID_FILE_ATTRIBUTES
# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
# endif # endif
#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 <Shlobj.h>
#endif
#ifndef CSIDL_FLAG_CREATE #ifndef CSIDL_FLAG_CREATE
#define CSIDL_FLAG_CREATE 0x8000 # define CSIDL_FLAG_CREATE 0x8000
#endif #endif
#ifndef CSIDL_WINDOWS #ifndef CSIDL_PROGRAMS
#define CSIDL_WINDOWS 0x0024 # define CSIDL_PROGRAMS 0x2
#endif #endif
#ifndef CSIDL_COMMON_PROGRAMS
#ifndef CSIDL_SYSTEM # define CSIDL_COMMON_PROGRAMS 0x17
#define CSIDL_SYSTEM 0x0025
#endif #endif
#ifndef CSIDL_PRINTERS
#ifndef CSIDL_PROGRAM_FILES # define CSIDL_PRINTERS 0x4
#define CSIDL_PROGRAM_FILES 0x0026
#endif #endif
#ifndef CSIDL_PERSONAL
#ifndef CSIDL_PROGRAM_FILES_COMMON # define CSIDL_PERSONAL 0x5
#define CSIDL_PROGRAM_FILES_COMMON 0x002b
#endif #endif
#ifndef CSIDL_COMMON_DOCUMENTS #ifndef CSIDL_COMMON_DOCUMENTS
#define CSIDL_COMMON_DOCUMENTS 0x002e # define CSIDL_COMMON_DOCUMENTS 0x2E
#endif #endif
#ifndef CSIDL_FAVORITES
#ifndef CSIDL_RESOURCES # define CSIDL_FAVORITES 0x6
#define CSIDL_RESOURCES 0x0038
#endif #endif
#ifndef CSIDL_COMMON_FAVORITES
#ifndef CSIDL_RESOURCES_LOCALIZED # define CSIDL_COMMON_FAVORITES 0x1F
#define CSIDL_RESOURCES_LOCALIZED 0x0039
#endif #endif
#ifndef CSIDL_STARTUP
#ifndef CSIDL_COMMON_ADMINTOOLS # define CSIDL_STARTUP 0x7
#define CSIDL_COMMON_ADMINTOOLS 0x002f
#endif #endif
#ifndef CSIDL_COMMON_STARTUP
#ifndef CSIDL_ADMINTOOLS # define CSIDL_COMMON_STARTUP 0x18
#define CSIDL_ADMINTOOLS 0x0030
#endif #endif
#ifndef CSIDL_RECENT
#ifndef CSIDL_MYPICTURES # define CSIDL_RECENT 0x8
#define CSIDL_MYPICTURES 0x0027
#endif #endif
#ifndef CSIDL_SENDTO
#ifndef CSIDL_COMMON_PICTURES # define CSIDL_SENDTO 0x9
#define CSIDL_COMMON_PICTURES 0x0036
#endif #endif
#ifndef CSIDL_STARTMENU
#ifndef CSIDL_MYMUSIC # define CSIDL_STARTMENU 0xB
#define CSIDL_MYMUSIC 0x000d
#endif #endif
#ifndef CSIDL_COMMON_STARTMENU
#ifndef CSIDL_COMMON_MUSIC # define CSIDL_COMMON_STARTMENU 0x16
#define CSIDL_COMMON_MUSIC 0x0035
#endif #endif
#ifndef CSIDL_DESKTOPDIRECTORY
#ifndef CSIDL_MYVIDEO # define CSIDL_DESKTOPDIRECTORY 0x10
#define CSIDL_MYVIDEO 0x000e
#endif #endif
#ifndef CSIDL_COMMON_DESKTOPDIRECTORY
#ifndef CSIDL_COMMON_VIDEO # define CSIDL_COMMON_DESKTOPDIRECTORY 0x19
#define CSIDL_COMMON_VIDEO 0x0037
#endif #endif
#ifndef CSIDL_NETHOOD
#ifndef CSIDL_CDBURN_AREA # define CSIDL_NETHOOD 0x13
#define CSIDL_CDBURN_AREA 0x003b #endif
#ifndef CSIDL_FONTS
# define CSIDL_FONTS 0x14
#endif #endif
#ifndef CSIDL_TEMPLATES #ifndef CSIDL_TEMPLATES
#define CSIDL_TEMPLATES 0x0015 # define CSIDL_TEMPLATES 0x15
#endif #endif
#ifndef CSIDL_COMMON_TEMPLATES #ifndef CSIDL_COMMON_TEMPLATES
#define CSIDL_COMMON_TEMPLATES 0x002d # define CSIDL_COMMON_TEMPLATES 0x2D
#endif #endif
#ifndef CSIDL_APPDATA
#ifndef CSIDL_PROFILE # define CSIDL_APPDATA 0x1A
#define CSIDL_PROFILE 0x0028
#endif #endif
#ifndef CSIDL_COMMON_APPDATA #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
#endif #endif

View file

@ -3,12 +3,18 @@
#include "Plugins.h" #include "Plugins.h"
#include "Platform.h" #include "Platform.h"
#include <WinNT.h> #include "util.h"
#ifdef _WIN32
# include <WinNT.h>
#else
# include <sys/stat.h>
# include <glob.h>
#endif
extern FILE *g_output; extern FILE *g_output;
void Plugins::FindCommands(char* path,bool displayInfo) void Plugins::FindCommands(char* path, bool displayInfo)
{ {
if (path) if (path)
{ {
@ -16,11 +22,8 @@ void Plugins::FindCommands(char* path,bool displayInfo)
if (length > 0) if (length > 0)
{ {
WIN32_FIND_DATA data; char *lc = CharPrev(path, path + strlen(path));
HANDLE handle; if (*lc == '\\' || *lc == '/')
if (path[length-1] == '\\' ||
path[length-1] == '/')
{ {
length--; length--;
} }
@ -31,21 +34,49 @@ void Plugins::FindCommands(char* path,bool displayInfo)
char* pathAndWildcard = new char [length+7]; char* pathAndWildcard = new char [length+7];
strcpy(pathAndWildcard,basePath); strcpy(pathAndWildcard,basePath);
strcat(pathAndWildcard,"\\*.dll"); strcat(pathAndWildcard,PATH_SEPARATOR_STR "*.dll");
#ifdef _WIN32
WIN32_FIND_DATA data;
HANDLE handle;
handle = FindFirstFile(pathAndWildcard,&data); handle = FindFirstFile(pathAndWildcard,&data);
if (handle != INVALID_HANDLE_VALUE) if (handle != INVALID_HANDLE_VALUE)
{ {
do 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]; 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); GetExports(dllPath,displayInfo);
delete[] dllPath; delete[] dllPath;
} while (FindNextFile(handle,&data)); }
#ifdef _WIN32
while (FindNextFile(handle,&data));
#else
globfree(&globbuf);
#endif
} }
#ifdef _WIN32
delete[] pathAndWildcard; delete[] pathAndWildcard;
#endif
delete[] basePath; delete[] basePath;
} }
} }
@ -58,24 +89,19 @@ void Plugins::GetExports(char* pathToDll, bool displayInfo)
unsigned char* dlldata = 0; unsigned char* dlldata = 0;
long dlldatalen = 0; long dlldatalen = 0;
bool loaded = false; bool loaded = false;
char dllName[100]; char dllName[1024];
char signature[256]; char signature[1024];
dllName[0] = 0; dllName[0] = 0;
char* ptr = strrchr(pathToDll,'\\'); char* ptr = strrchr(pathToDll,PATH_SEPARATOR_C);
if (ptr && *ptr && *(ptr+1)) strcpy(dllName,ptr+1); if (ptr && *ptr && *(ptr+1)) strcpy(dllName,ptr+1);
// find .dll // find .dll
char *dllName2 = strdup(dllName); int len = strlen(dllName);
for (ptr = dllName2; *ptr; ptr = CharNext(ptr)) if (len > 4 && !stricmp(dllName + len - 4, ".dll"))
{ {
if (!strcmpi(ptr, ".dll")) dllName[len - 4] = 0;
{
*(dllName + (ptr - dllName2)) = 0;
break;
}
} }
free(dllName2);
FILE* dll = fopen(pathToDll,"rb"); FILE* dll = fopen(pathToDll,"rb");
if (dll) if (dll)

View file

@ -20,8 +20,14 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#define RESOURCE_EDITOR_NOT_API
#include "ResourceEditor.h" #include "ResourceEditor.h"
#include "util.h"
#include <time.h>
#include <queue>
#ifndef _WIN32
# include <iconv.h>
#endif
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Utilities // Utilities
@ -195,7 +201,9 @@ BYTE* CResourceEditor::GetResource(char* szType, char* szName, LANGID wLanguage)
i = nameDir->Find(szName); i = nameDir->Find(szName);
if (i > -1) { if (i > -1) {
langDir = nameDir->GetEntry(i)->GetSubDirectory(); langDir = nameDir->GetEntry(i)->GetSubDirectory();
i = langDir->Find(wLanguage); i = 0;
if (wLanguage)
i = langDir->Find(wLanguage);
if (i > -1) { if (i > -1) {
data = langDir->GetEntry(i)->GetDataEntry(); data = langDir->GetEntry(i)->GetDataEntry();
} }
@ -208,7 +216,7 @@ BYTE* CResourceEditor::GetResource(char* szType, char* szName, LANGID wLanguage)
return toReturn; return toReturn;
} }
else else
return 0; return NULL;
} }
void CResourceEditor::FreeResource(BYTE* pbResource) void CResourceEditor::FreeResource(BYTE* pbResource)
@ -381,29 +389,47 @@ CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, P
// Go through all entries of this resource directory // Go through all entries of this resource directory
for (int i = 0; i < rdToScan->Header.NumberOfNamedEntries + rdToScan->Header.NumberOfIdEntries; i++) { 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 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); rde = PIMAGE_RESOURCE_DATA_ENTRY(rdToScan->Entries[i].OffsetToData + (BYTE*)rdRoot);
// If this entry has a name, translate it from Unicode // If this entry has a name, translate it from Unicode
if (rdToScan->Entries[i].NameIsString) { if (rdToScan->Entries[i].NameString.NameIsString) {
PIMAGE_RESOURCE_DIR_STRING_U rds = PIMAGE_RESOURCE_DIR_STRING_U(rdToScan->Entries[i].NameOffset + (char*)rdRoot); 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); int mbsSize = WideCharToMultiByte(CP_ACP, 0, rds->NameString, rds->Length, 0, 0, 0, 0);
szName = new char[mbsSize+1]; szName = new char[mbsSize+1];
WideCharToMultiByte(CP_ACP, 0, rds->NameString, rds->Length, szName, mbsSize, 0, 0); WideCharToMultiByte(CP_ACP, 0, rds->NameString, rds->Length, szName, mbsSize, 0, 0);
szName[mbsSize] = 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, set the name to this entry's id
else else
szName = MAKEINTRESOURCE(rdToScan->Entries[i].Id); szName = MAKEINTRESOURCE(rdToScan->Entries[i].Id);
if (rdToScan->Entries[i].DataIsDirectory) if (rdToScan->Entries[i].DirectoryOffset.DataIsDirectory)
rdc->AddEntry( rdc->AddEntry(
new CResourceDirectoryEntry( new CResourceDirectoryEntry(
szName, szName,
ScanDirectory( ScanDirectory(
rdRoot, 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()); qDataEntries2.push(crd->GetEntry(i)->GetDataEntry());
} }
IMAGE_RESOURCE_DIRECTORY_ENTRY rDirE = {{0}}; MY_IMAGE_RESOURCE_DIRECTORY_ENTRY rDirE;
rDirE.DataIsDirectory = crd->GetEntry(i)->IsDataDirectory(); ZeroMemory(&rDirE, sizeof(rDirE));
rDirE.DirectoryOffset.DataIsDirectory = crd->GetEntry(i)->IsDataDirectory();
rDirE.Id = (crd->GetEntry(i)->HasName()) ? 0 : crd->GetEntry(i)->GetId(); 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); crd->GetEntry(i)->m_dwWrittenAt = DWORD(seeker);
seeker += sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); seeker += sizeof(MY_IMAGE_RESOURCE_DIRECTORY_ENTRY);
} }
qDirs.pop(); qDirs.pop();
} }
@ -491,13 +518,36 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) {
while (!qStrings.empty()) { while (!qStrings.empty()) {
CResourceDirectoryEntry* cRDirE = qStrings.front(); 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(); char* szName = cRDirE->GetName();
WORD iLen = lstrlen(szName); WORD iLen = strlen(szName);
WCHAR* szwName = new WCHAR[iLen+1]; WCHAR *szwName = new WCHAR[iLen + 1];
#ifdef _WIN32
// MultiByteToWideChar return value includes the null char, so -1 // MultiByteToWideChar return value includes the null char, so -1
iLen = MultiByteToWideChar(CP_ACP, 0, szName, iLen, szwName, iLen) - 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; *(WORD*)seeker = iLen;
seeker += sizeof(WORD); seeker += sizeof(WORD);
CopyMemory(seeker, szwName, iLen*sizeof(WCHAR)); CopyMemory(seeker, szwName, iLen*sizeof(WCHAR));
@ -536,12 +586,12 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) {
void CResourceEditor::SetOffsets(CResourceDirectory* resDir, DWORD newResDirAt) { void CResourceEditor::SetOffsets(CResourceDirectory* resDir, DWORD newResDirAt) {
for (int i = 0; i < resDir->CountEntries(); i++) { for (int i = 0; i < resDir->CountEntries(); i++) {
if (resDir->GetEntry(i)->IsDataDirectory()) { if (resDir->GetEntry(i)->IsDataDirectory()) {
PIMAGE_RESOURCE_DIRECTORY_ENTRY(resDir->GetEntry(i)->m_dwWrittenAt)->DataIsDirectory = 1; PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(resDir->GetEntry(i)->m_dwWrittenAt)->DirectoryOffset.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.OffsetToDirectory = resDir->GetEntry(i)->GetSubDirectory()->m_dwWrittenAt - newResDirAt;
SetOffsets(resDir->GetEntry(i)->GetSubDirectory(), newResDirAt); SetOffsets(resDir->GetEntry(i)->GetSubDirectory(), newResDirAt);
} }
else { 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(); char* szEntName = entry->GetName();
for (i = 0; i < m_rdDir.NumberOfIdEntries; i++) { for (i = 0; i < m_rdDir.NumberOfIdEntries; i++) {
char* szName = m_vEntries[i]->GetName(); char* szName = m_vEntries[i]->GetName();
int cmp = lstrcmp(szName, szEntName); int cmp = strcmp(szName, szEntName);
delete [] szName; delete [] szName;
if (cmp == 0) { if (cmp == 0) {
delete [] szEntName; delete [] szEntName;
@ -639,7 +689,7 @@ int CResourceDirectory::Find(char* szName) {
continue; continue;
char* szEntName = m_vEntries[i]->GetName(); char* szEntName = m_vEntries[i]->GetName();
int cmp = lstrcmp(szName, szEntName); int cmp = strcmp(szName, szEntName);
delete [] szEntName; delete [] szEntName;
if (!cmp) if (!cmp)
@ -667,7 +717,7 @@ int CResourceDirectory::Find(WORD wId) {
DWORD CResourceDirectory::GetSize() { DWORD CResourceDirectory::GetSize() {
DWORD dwSize = sizeof(IMAGE_RESOURCE_DIRECTORY); DWORD dwSize = sizeof(IMAGE_RESOURCE_DIRECTORY);
for (unsigned int i = 0; i < m_vEntries.size(); i++) { 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()) if (m_vEntries[i]->HasName())
dwSize += sizeof(IMAGE_RESOURCE_DIR_STRING_U) + (m_vEntries[i]->GetNameLength()+1)*sizeof(WCHAR); dwSize += sizeof(IMAGE_RESOURCE_DIR_STRING_U) + (m_vEntries[i]->GetNameLength()+1)*sizeof(WCHAR);
if (m_vEntries[i]->IsDataDirectory()) if (m_vEntries[i]->IsDataDirectory())
@ -711,8 +761,8 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(char* szName, CResourceDirector
} }
else { else {
m_bHasName = true; m_bHasName = true;
m_szName = new char[lstrlen(szName)+1]; m_szName = new char[strlen(szName)+1];
lstrcpy(m_szName, szName); strcpy(m_szName, szName);
} }
m_bIsDataDirectory = true; m_bIsDataDirectory = true;
m_rdSubDir = rdSubDir; m_rdSubDir = rdSubDir;
@ -726,8 +776,8 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(char* szName, CResourceDataEntr
} }
else { else {
m_bHasName = true; m_bHasName = true;
m_szName = new char[lstrlen(szName)+1]; m_szName = new char[strlen(szName)+1];
lstrcpy(m_szName, szName); strcpy(m_szName, szName);
} }
m_bIsDataDirectory = false; m_bIsDataDirectory = false;
m_rdeData = rdeData; m_rdeData = rdeData;
@ -751,13 +801,13 @@ char* CResourceDirectoryEntry::GetName() {
if (!m_bHasName) if (!m_bHasName)
return 0; return 0;
char* szName = 0; char* szName = 0;
szName = new char[lstrlen(m_szName)+1]; szName = new char[strlen(m_szName)+1];
lstrcpy(szName, m_szName); strcpy(szName, m_szName);
return szName; return szName;
} }
int CResourceDirectoryEntry::GetNameLength() { int CResourceDirectoryEntry::GetNameLength() {
return lstrlen(m_szName); return strlen(m_szName);
} }
WORD CResourceDirectoryEntry::GetId() { WORD CResourceDirectoryEntry::GetId() {

View file

@ -27,17 +27,61 @@
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#ifdef RESOURCE_EDITOR_NOT_API
#include "Platform.h" #include "Platform.h"
#include <WinNT.h> #include <vector>
#include <Time.h> #ifdef _WIN32
#include <Vector> # include <WinNT.h>
#include <Queue> #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 <StdExcept> #pragma pack()
#include <stdexcept>
using namespace std; using namespace std;
class CResourceDirectory; class CResourceDirectory;
@ -47,7 +91,7 @@ class CResourceDataEntry;
// Resource directory with entries // Resource directory with entries
typedef struct RESOURCE_DIRECTORY { typedef struct RESOURCE_DIRECTORY {
IMAGE_RESOURCE_DIRECTORY Header; IMAGE_RESOURCE_DIRECTORY Header;
IMAGE_RESOURCE_DIRECTORY_ENTRY Entries[1]; MY_IMAGE_RESOURCE_DIRECTORY_ENTRY Entries[1];
} *PRESOURCE_DIRECTORY; } *PRESOURCE_DIRECTORY;
class CResourceEditor { class CResourceEditor {
@ -83,8 +127,6 @@ private:
void SetOffsets(CResourceDirectory* resDir, DWORD newResDirAt); void SetOffsets(CResourceDirectory* resDir, DWORD newResDirAt);
}; };
#ifdef RESOURCE_EDITOR_NOT_API
class CResourceDirectory { class CResourceDirectory {
public: public:
CResourceDirectory(PIMAGE_RESOURCE_DIRECTORY prd); CResourceDirectory(PIMAGE_RESOURCE_DIRECTORY prd);
@ -164,6 +206,4 @@ private:
DWORD m_dwCodePage; DWORD m_dwCodePage;
}; };
#endif // #ifdef RESOURCE_EDITOR_NOT_API
#endif // !defined(AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_) #endif // !defined(AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_)

View file

@ -2,11 +2,24 @@
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "Platform.h"
#include "build.h"
#include "ResourceVersionInfo.h" #include "ResourceVersionInfo.h"
#include "Platform.h"
#include "util.h"
#ifdef NSIS_SUPPORT_VERSION_INFO #ifdef NSIS_SUPPORT_VERSION_INFO
#ifndef VOS__WINDOWS32
# define VOS__WINDOWS32 4
#endif
#ifndef VFT_APP
# define VFT_APP 1
#endif
#ifndef _WIN32
# include <iconv.h>
#endif
/* /*
int ValidCodePages[] = { int ValidCodePages[] = {
437, 708, 709, 710, 720, 737, 775, 850, 852, 855, 85, 86, 86, 86, 86, 864, 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 // Util function - must be freeded
WCHAR* StrToWstrAlloc(const char* istr, int codepage) WCHAR* StrToWstrAlloc(const char* istr, int codepage)
{ {
#ifdef _WIN32
int strSize = MultiByteToWideChar(codepage, 0, istr, -1, 0, 0); int strSize = MultiByteToWideChar(codepage, 0, istr, -1, 0, 0);
WCHAR* wstr = new WCHAR[strSize]; WCHAR* wstr = new WCHAR[strSize];
MultiByteToWideChar(codepage, 0, istr, -1, wstr, strSize); MultiByteToWideChar(codepage, 0, istr, -1, wstr, strSize);
return wstr; 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) 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; wType = *(WORD*)p;
p += sizeof(WORD); p += sizeof(WORD);
szKey = (WCHAR*)p; szKey = (WCHAR*)p;
p += (wcslen(szKey) + 1) * sizeof (WCHAR); p += (WCStrLen(szKey)) * sizeof (WCHAR);
while ( ((long)p % 4) != 0 ) while ( ((long)p % 4) != 0 )
p++; p++;
return p - baseP; return p - baseP;
@ -116,7 +152,7 @@ void SaveVersionHeader (GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wTy
strm.add (&wValueLength, sizeof (wValueLength)); strm.add (&wValueLength, sizeof (wValueLength));
strm.add (&wType, sizeof (wType)); strm.add (&wType, sizeof (wType));
keyLen = (wcslen(key) + 1) * sizeof (WCHAR); keyLen = (WCStrLen(key)) * sizeof (WCHAR);
strm.add ((void*)key, keyLen); strm.add ((void*)key, keyLen);
PadStream(strm); PadStream(strm);
@ -138,7 +174,9 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
WCHAR *KeyName, *KeyValue; WCHAR *KeyName, *KeyValue;
strm.resize(0); 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); DefineList *pChildStrings = m_ChildStringLists.get_strings(Index);
if ( pChildStrings->getnum() > 0 ) if ( pChildStrings->getnum() > 0 )
@ -159,7 +197,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
p = stringInfoStream.getlen(); p = stringInfoStream.getlen();
KeyName = StrToWstrAlloc(pChildStrings->getname(i), codepage); KeyName = StrToWstrAlloc(pChildStrings->getname(i), codepage);
KeyValue = StrToWstrAlloc(pChildStrings->getvalue(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 [] KeyName;
delete [] KeyValue; delete [] KeyValue;
wSize = stringInfoStream.getlen() - p; wSize = stringInfoStream.getlen() - p;
@ -172,7 +210,9 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
PadStream (strm); PadStream (strm);
p = strm.getlen(); 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()); strm.add (stringInfoStream.get(), stringInfoStream.getlen());
wSize = strm.getlen() - p; wSize = strm.getlen() - p;
@ -184,11 +224,15 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
{ {
PadStream (strm); PadStream (strm);
p = strm.getlen(); 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); PadStream (strm);
p1 = strm.getlen(); 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 // First add selected code language translation
v = MAKELONG(m_ChildStringLists.get_lang(Index), m_ChildStringLists.get_codepage(Index)); v = MAKELONG(m_ChildStringLists.get_lang(Index), m_ChildStringLists.get_codepage(Index));

View file

@ -9,10 +9,29 @@
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include "exehead/config.h"
#ifdef NSIS_SUPPORT_VERSION_INFO #ifdef NSIS_SUPPORT_VERSION_INFO
#include <algorithm> #include "Platform.h"
using namespace std; #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 { struct version_string_list {
int codepage; int codepage;

View file

@ -3,7 +3,7 @@
#ifndef ___CONSTANTS___H_____ #ifndef ___CONSTANTS___H_____
#define ___CONSTANTS___H_____ #define ___CONSTANTS___H_____
#include "Lang.h" #include "lang.h"
struct constantstring { struct constantstring {
int name; int name;

View file

@ -12,18 +12,29 @@
#include "ResourceEditor.h" #include "ResourceEditor.h"
#include "DialogTemplate.h" #include "DialogTemplate.h"
#include "ResourceVersionInfo.h" #include "ResourceVersionInfo.h"
#include <Shlobj.h>
#ifndef _WIN32
# include <locale.h>
# include <unistd.h>
# include <limits.h>
# include <stdlib.h>
#endif
int MMapFile::m_iAllocationGranularity = 0; int MMapFile::m_iAllocationGranularity = 0;
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
#ifdef _WIN32
DWORD WINAPI lzmaCompressThread(LPVOID lpParameter) DWORD WINAPI lzmaCompressThread(LPVOID lpParameter)
#else
void *lzmaCompressThread(void *lpParameter)
#endif
{ {
CLZMA *Compressor = (CLZMA *) lpParameter; CLZMA *Compressor = (CLZMA *) lpParameter;
if (!Compressor) if (!Compressor)
return 0; return 0;
return Compressor->CompressReal(); Compressor->CompressReal();
return 0;
} }
#endif #endif
@ -226,19 +237,6 @@ CEXEBuild::CEXEBuild()
#ifdef NSIS_ZLIB_COMPRESS_WHOLE #ifdef NSIS_ZLIB_COMPRESS_WHOLE
definedlist.add("NSIS_ZLIB_COMPRESS_WHOLE"); definedlist.add("NSIS_ZLIB_COMPRESS_WHOLE");
#endif #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 #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003 // Added by Sunil Kamath 11 June 2003
definedlist.add("NSIS_SUPPORT_STANDARD_PREDEFINES"); definedlist.add("NSIS_SUPPORT_STANDARD_PREDEFINES");
@ -380,7 +378,7 @@ definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS");
plugins_processed=0; plugins_processed=0;
#endif #endif
last_used_lang=MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); last_used_lang=NSIS_DEFAULT_LANG;
res_editor=0; res_editor=0;
@ -391,7 +389,9 @@ definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS");
disable_window_icon=0; disable_window_icon=0;
#ifdef _WIN32
notify_hwnd=0; notify_hwnd=0;
#endif
defcodepage_set=false; defcodepage_set=false;
uDefCodePage=CP_ACP; 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); 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(); } int CEXEBuild::getcurdbsize() { return cur_datablock->getlen(); }
// returns offset in stringblock // 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 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); wsprintf(i_str, "%d", i);
#else
snprintf(i_str, 128, "%d", i);
#endif
return add_string(i_str); 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; const char *p=in;
while (*p) while (*p)
{ {
const char *np=CharNextExA(codepage, p, 0); const char *np;
#ifdef _WIN32
if (np-p > 1) // multibyte char 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--) while (l--)
{ {
int i = (unsigned char)*p++; int i = (unsigned char)*p++;
@ -510,9 +582,9 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
} }
continue; continue;
} }
int i = (unsigned char)*p; int i = (unsigned char)*p;
p=np; p=np;
// Test for characters extending into the variable codes // Test for characters extending into the variable codes
@ -674,12 +746,13 @@ int CEXEBuild::datablock_optimize(int start_offset)
while (left > 0) while (left > 0)
{ {
int l = min(left, build_filebuflen); int l = min(left, build_filebuflen);
int la = l;
void *newstuff = db->get(start_offset + this_len - left, 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); int res = memcmp(newstuff, oldstuff, l);
db->release(oldstuff); db->release(oldstuff, la);
db->release(); db->release();
if (res) if (res)
@ -1168,8 +1241,12 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/
if (defname[0]) if (defname[0])
{ {
char buf[32]; char buf[128];
#ifdef _WIN32
wsprintf(buf, "%d", cur_header->blocks[NB_SECTIONS].num); 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)) if (definedlist.add(defname, buf))
{ {
ERROR_MSG("Error: \"%s\" already defined, can't assign section index!\n", defname); 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 #ifdef NSIS_SUPPORT_STROPTS
else if (w->which == EW_GETFUNCTIONADDR) else if (w->which == EW_GETFUNCTIONADDR)
{ {
char buf[32];
if (w->offsets[1] < 0) if (w->offsets[1] < 0)
{ {
ERROR_MSG("Error: GetFunctionAddress requires a real function to get address of.\n"); 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; if (resolve_call_int(fn,str,w->offsets[1],&w->offsets[1])) return 1;
w->which=EW_ASSIGNVAR; w->which=EW_ASSIGNVAR;
wsprintf(buf,"%d",w->offsets[1]+1); // +1 here to make 1-based. w->offsets[1]=add_intstring(w->offsets[1]+1); // +1 here to make 1-based.
w->offsets[1]=add_string(buf);
} }
else if (w->which == EW_GETLABELADDR) else if (w->which == EW_GETLABELADDR)
{ {
char buf[32];
if (resolve_jump_int(fn,&w->offsets[1],offs,start,end)) return 1; if (resolve_jump_int(fn,&w->offsets[1],offs,start,end)) return 1;
w->which=EW_ASSIGNVAR; w->which=EW_ASSIGNVAR;
wsprintf(buf,"%d",w->offsets[1]); w->offsets[1]=add_intstring(w->offsets[1]);
w->offsets[1]=add_string(buf);
} }
#endif #endif
return 0; return 0;
@ -1978,7 +2051,7 @@ again:
SCRIPT_MSG("Done!\n"); SCRIPT_MSG("Done!\n");
#define REMOVE_ICON(id) if (disable_window_icon) { \ #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) { \ if (dlg) { \
CDialogTemplate dt(dlg,uDefCodePage); \ CDialogTemplate dt(dlg,uDefCodePage); \
free(dlg); \ free(dlg); \
@ -1996,7 +2069,7 @@ again:
\ \
DWORD dwSize; \ DWORD dwSize; \
dlg = dt.Save(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); \ res_editor->FreeResource(dlg); \
} \ } \
@ -2007,43 +2080,43 @@ again:
init_res_editor(); init_res_editor();
#ifdef NSIS_CONFIG_LICENSEPAGE #ifdef NSIS_CONFIG_LICENSEPAGE
if (!license_normal) { 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); else REMOVE_ICON(IDD_LICENSE);
if (!license_fsrb) { 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); else REMOVE_ICON(IDD_LICENSE_FSRB);
if (!license_fscb) { 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); else REMOVE_ICON(IDD_LICENSE_FSCB);
#endif // NSIS_CONFIG_LICENSEPAGE #endif // NSIS_CONFIG_LICENSEPAGE
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
if (!selcom) { if (!selcom) {
res_editor->UpdateResource(RT_DIALOG, IDD_SELCOM, 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, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); res_editor->UpdateResource(RT_BITMAP, IDB_BITMAP1, NSIS_DEFAULT_LANG, 0, 0);
} }
else REMOVE_ICON(IDD_SELCOM); else REMOVE_ICON(IDD_SELCOM);
#endif // NSIS_CONFIG_COMPONENTPAGE #endif // NSIS_CONFIG_COMPONENTPAGE
if (!dir) { 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); else REMOVE_ICON(IDD_DIR);
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
if (!uninstconfirm) { 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); else REMOVE_ICON(IDD_UNINST);
#endif // NSIS_CONFIG_UNINSTALL_SUPPORT #endif // NSIS_CONFIG_UNINSTALL_SUPPORT
if (!instlog) { 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); else REMOVE_ICON(IDD_INSTFILES);
if (!main) { 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) 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"); SCRIPT_MSG("Done!\n");
@ -2310,10 +2383,29 @@ int CEXEBuild::write_output(void)
int crc=0; int crc=0;
{ {
char buffer[1024],*p; #ifdef _WIN32
char buffer[1024];
char *p;
GetFullPathName(build_output_filename,1024,buffer,&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); 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"); FILE *fp = fopen(build_output_filename,"w+b");
if (!fp) if (!fp)
@ -2503,7 +2595,11 @@ int CEXEBuild::write_output(void)
{ {
int total_out_size_estimate= int total_out_size_estimate=
exeheader_size_new+sizeof(fh)+build_datablock.getlen()+(build_crcchk?sizeof(int):0); 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); 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, INFO_MSG("Datablock optimizer saved %d bytes (~%d.%d%%).\n",db_opt_save,
pc/10,pc%10); pc/10,pc%10);
} }
@ -2648,7 +2744,11 @@ int CEXEBuild::write_output(void)
} }
INFO_MSG("\n"); INFO_MSG("\n");
{ {
#ifdef _WIN32
int pc=MulDiv(ftell(fp),1000,total_usize); 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", INFO_MSG("Total size: %10d / %d bytes (%d.%d%%)\n",
ftell(fp),total_usize,pc/10,pc%10); 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, ...) void CEXEBuild::ERROR_MSG(const char *s, ...)
{ {
#ifdef _WIN32
if (display_errors || notify_hwnd) if (display_errors || notify_hwnd)
#else
if (display_errors)
#endif
{ {
char buf[NSIS_MAX_STRLEN*4]; char buf[NSIS_MAX_STRLEN*4];
va_list val; va_list val;
@ -3055,7 +3159,8 @@ void CEXEBuild::print_warnings()
fflush(g_output); fflush(g_output);
} }
void CEXEBuild::notify(int code, char *data) #ifdef _WIN32
void CEXEBuild::notify(notify_e code, char *data)
{ {
if (notify_hwnd) if (notify_hwnd)
{ {
@ -3063,6 +3168,7 @@ void CEXEBuild::notify(int code, char *data)
SendMessage(notify_hwnd, WM_COPYDATA, 0, (LPARAM)&cds); SendMessage(notify_hwnd, WM_COPYDATA, 0, (LPARAM)&cds);
} }
} }
#endif
// Added by Ximon Eighteen 5th August 2002 // Added by Ximon Eighteen 5th August 2002
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
@ -3080,8 +3186,8 @@ void CEXEBuild::build_plugin_table(void)
char* searchPath = new char [strlen(nsisdir)+9]; char* searchPath = new char [strlen(nsisdir)+9];
if (searchPath) if (searchPath)
{ {
wsprintf(searchPath,"%s\\plugins",nsisdir); sprintf(searchPath,"%s" PATH_SEPARATOR_STR "Plugins",nsisdir);
INFO_MSG("Processing plugin dlls: \"%s\\*.dll\"\n",searchPath); INFO_MSG("Processing plugin dlls: \"%s" PATH_SEPARATOR_STR "*.dll\"\n",searchPath);
m_plugins.FindCommands(searchPath,display_info?true:false); m_plugins.FindCommands(searchPath,display_info?true:false);
INFO_MSG("\n"); INFO_MSG("\n");
delete[] searchPath; delete[] searchPath;

View file

@ -1,7 +1,7 @@
#ifndef _BUILD_H_ #ifndef _BUILD_H_
#define _BUILD_H_ #define _BUILD_H_
#include <StdExcept> #include <stdexcept>
using namespace std; using namespace std;
@ -18,9 +18,8 @@ using namespace std;
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003 // Added by Sunil Kamath 11 June 2003
#include <time.h> # include <time.h>
#include <sys/types.h> # include <sys/stat.h>
#include <sys/stat.h>
#endif #endif
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
@ -33,7 +32,7 @@ using namespace std;
#endif//NSIS_CONFIG_COMPRESSION_SUPPORT #endif//NSIS_CONFIG_COMPRESSION_SUPPORT
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
#include "Plugins.h" # include "Plugins.h"
#endif //NSIS_CONFIG_PLUGIN_SUPPORT #endif //NSIS_CONFIG_PLUGIN_SUPPORT
#ifdef NSIS_CONFIG_CRC_SUPPORT #ifdef NSIS_CONFIG_CRC_SUPPORT
@ -48,7 +47,7 @@ extern "C"
#define PS_ERROR 50 #define PS_ERROR 50
#define PS_WARNING 100 #define PS_WARNING 100
enum { enum notify_e {
MAKENSIS_NOTIFY_SCRIPT, MAKENSIS_NOTIFY_SCRIPT,
MAKENSIS_NOTIFY_WARNING, MAKENSIS_NOTIFY_WARNING,
MAKENSIS_NOTIFY_ERROR, MAKENSIS_NOTIFY_ERROR,
@ -66,6 +65,7 @@ enum {
class CEXEBuild { class CEXEBuild {
public: public:
CEXEBuild(); CEXEBuild();
void CEXEBuild::setdirs(char *argv0);
~CEXEBuild(); ~CEXEBuild();
// to add a warning to the compiler's warning list. // to add a warning to the compiler's warning list.
@ -104,8 +104,12 @@ class CEXEBuild {
char *curfilename; char *curfilename;
FILE *fp; FILE *fp;
#ifdef _WIN32
HWND notify_hwnd; 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: private:
// tokens.cpp // tokens.cpp

View file

@ -71,7 +71,7 @@ extern "C" {
#endif #endif
#include "../exehead/config.h" #include "../exehead/config.h"
#include <windows.h> #include "../Platform.h"
#define BZ_RUN 0 #define BZ_RUN 0
#define BZ_FLUSH 1 #define BZ_FLUSH 1
@ -129,8 +129,8 @@ typedef unsigned short UInt16;
#ifndef EXEHEAD #ifndef EXEHEAD
#define BZALLOC(items) GlobalAlloc(GPTR,items) #define BZALLOC(items) malloc(items)
#define BZFREE(addr) { if (addr) GlobalFree(addr); } #define BZFREE(addr) { if (addr) free(addr); }
#define mini_memcpy memcpy #define mini_memcpy memcpy
typedef struct { typedef struct {

View file

@ -6,8 +6,16 @@
#include "7zip/7zip/Compress/LZMA/LZMAEncoder.h" #include "7zip/7zip/Compress/LZMA/LZMAEncoder.h"
#include "7zip/Common/MyCom.h" #include "7zip/Common/MyCom.h"
#ifndef _WIN32
# include <sched.h>
#endif
// implemented in build.cpp - simply calls CompressReal // implemented in build.cpp - simply calls CompressReal
#ifdef _WIN32
DWORD WINAPI lzmaCompressThread(LPVOID lpParameter); DWORD WINAPI lzmaCompressThread(LPVOID lpParameter);
#else
void *lzmaCompressThread(void *arg);
#endif
class CLZMA: class CLZMA:
public ICompressor, public ICompressor,
@ -18,7 +26,11 @@ class CLZMA:
private: private:
NCompress::NLZMA::CEncoder *_encoder; NCompress::NLZMA::CEncoder *_encoder;
#ifdef _WIN32
HANDLE hCompressionThread; HANDLE hCompressionThread;
#else
pthread_t hCompressionThread;
#endif
BYTE *next_in; /* next input byte */ BYTE *next_in; /* next input byte */
UINT avail_in; /* number of bytes available at next_in */ UINT avail_in; /* number of bytes available at next_in */
@ -30,11 +42,38 @@ private:
BOOL finish; BOOL finish;
CRITICAL_SECTION cs; long sync_state;
BOOL nt_locked; /* nsis thread locked */
BOOL ct_locked; /* compression thread locked */
BOOL compressor_finished; 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: public:
MY_UNKNOWN_IMP MY_UNKNOWN_IMP
@ -42,18 +81,27 @@ public:
{ {
_encoder = new NCompress::NLZMA::CEncoder(); _encoder = new NCompress::NLZMA::CEncoder();
_encoder->SetWriteEndMarkerMode(true); _encoder->SetWriteEndMarkerMode(true);
#ifdef _WIN32
hCompressionThread = NULL; hCompressionThread = NULL;
#else
hCompressionThread = 0;
#endif
compressor_finished = FALSE; compressor_finished = FALSE;
finish = FALSE; finish = FALSE;
ct_locked = TRUE; #ifndef _WIN32
pthread_mutex_init(&mutex, 0);
#endif
compressor_finished = 1;
sync_state = 0;
End(); End();
InitializeCriticalSection(&cs);
} }
virtual ~CLZMA() virtual ~CLZMA()
{ {
#ifndef _WIN32
pthread_mutex_destroy(&mutex);
#endif
End(); End();
DeleteCriticalSection(&cs);
if (_encoder) if (_encoder)
{ {
delete _encoder; delete _encoder;
@ -65,8 +113,7 @@ public:
{ {
End(); End();
nt_locked = TRUE; sync_state = 1;
ct_locked = FALSE;
compressor_finished = FALSE; compressor_finished = FALSE;
finish = FALSE; finish = FALSE;
@ -103,27 +150,26 @@ public:
int End() 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 // kill compression thread
avail_in = 0; avail_in = 0;
avail_out = 0; avail_out = 0;
finish = TRUE;
LeaveCriticalSection(&cs); InterlockedExchange(&sync_state, 1);
while (!ct_locked) while (InterlockedCompareExchange(&sync_state, 2, 0) != 0)
Sleep(0); Sleep(1);
nt_locked = FALSE;
EnterCriticalSection(&cs);
while (ct_locked)
Sleep(0);
nt_locked = TRUE;
LeaveCriticalSection(&cs);
} }
#ifdef _WIN32
if (hCompressionThread) if (hCompressionThread)
{ {
CloseHandle(hCompressionThread); CloseHandle(hCompressionThread);
hCompressionThread = NULL; hCompressionThread = NULL;
} }
#else
hCompressionThread = 0;
#endif
SetNextOut(NULL, 0); SetNextOut(NULL, 0);
SetNextIn(NULL, 0); SetNextIn(NULL, 0);
return C_OK; return C_OK;
@ -131,12 +177,6 @@ public:
int CompressReal() int CompressReal()
{ {
EnterCriticalSection(&cs);
ct_locked = TRUE;
while (nt_locked)
Sleep(0);
try try
{ {
if (_encoder->WriteCoderProperties(this) == S_OK) if (_encoder->WriteCoderProperties(this) == S_OK)
@ -168,8 +208,7 @@ public:
} }
compressor_finished = TRUE; compressor_finished = TRUE;
LeaveCriticalSection(&cs); InterlockedExchange(&sync_state, 0);
ct_locked = FALSE;
return C_OK; return C_OK;
} }
@ -188,31 +227,26 @@ public:
if (!hCompressionThread) if (!hCompressionThread)
{ {
#ifdef _WIN32
DWORD dwThreadId; DWORD dwThreadId;
hCompressionThread = CreateThread(0, 0, lzmaCompressThread, (LPVOID) this, 0, &dwThreadId); hCompressionThread = CreateThread(0, 0, lzmaCompressThread, (LPVOID) this, 0, &dwThreadId);
if (!hCompressionThread) if (!hCompressionThread)
#else
if (pthread_create(&hCompressionThread, NULL, lzmaCompressThread, (LPVOID) this))
#endif
return -2; return -2;
} }
else else
{ {
LeaveCriticalSection(&cs); InterlockedExchange(&sync_state, 1);
} }
while (!ct_locked) while (InterlockedCompareExchange(&sync_state, 2, 0) != 0)
Sleep(0); Sleep(1);
nt_locked = FALSE;
EnterCriticalSection(&cs);
nt_locked = TRUE;
while (ct_locked)
Sleep(0);
if (compressor_finished) if (compressor_finished)
{ {
LeaveCriticalSection(&cs);
return res; return res;
} }
@ -221,17 +255,9 @@ public:
void GetMoreIO() void GetMoreIO()
{ {
LeaveCriticalSection(&cs); InterlockedExchange(&sync_state, 0);
while (!nt_locked) while (InterlockedCompareExchange(&sync_state, 2, 1) != 1)
Sleep(0); Sleep(1);
ct_locked = FALSE;
EnterCriticalSection(&cs);
ct_locked = TRUE;
while (nt_locked)
Sleep(0);
} }
STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize) STDMETHOD(Read)(void *data, UINT32 size, UINT32 *processedSize)

View file

@ -69,7 +69,7 @@ char *ValidateTempDir()
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow)
{ {
int ret = 2; static int ret;
const char *m_Err = _LANG_ERRORWRITINGTEMP; const char *m_Err = _LANG_ERRORWRITINGTEMP;
int cl_flags = 0; int cl_flags = 0;

View file

@ -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_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 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 LIBS = -lole32 -lgdi32 -lversion -luuid -lcomctl32 -lkernel32 -luser32 -lshell32 -ladvapi32
# -- Programs -- # -- Programs --
@ -17,13 +19,18 @@ CC = gcc
RC = windres RC = windres
RM = rm RM = rm
MKDIR = mkdir MKDIR = mkdir
BIN2H = ./bin2h
# -- Compilers and linker flags -- # -- Compilers and linker flags --
DEFINES = -DWIN32 -D_WINDOWS_ -DEXEHEAD -DWIN32_LEAN_AND_MEAN -DZEXPORT=__stdcall -DLZMACALL=__stdcall CPPFLAGS = -DEXEHEAD -DWIN32_LEAN_AND_MEAN -DZEXPORT=__stdcall -DLZMACALL=__fastcall
CFLAGS = -Wall -Os -fno-common -fomit-frame-pointer -fno-inline $(DEFINES) CFLAGS = -Wall -Os
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 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 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 all : exehead_zlib exehead_bzip2 exehead_lzma exehead_resources
missing_dirs = $(filter-out $(wildcard Release-*),Release-zlib Release-bzip2 Release-lzma) missing_dirs = $(filter-out $(wildcard Release-*),Release-zlib Release-bzip2 Release-lzma)
@ -34,75 +41,99 @@ else
mkdirline = mkdirline =
endif endif
dirs: dirs :
$(mkdirline) $(mkdirline)
exehead_zlib : dirs $(ZLIB_SRCS) $(ZLIB_OBJS) sections_script %.o : dirs
$(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
exehead_bzip2 : dirs $(BZIP2_SRCS) $(BZIP2_OBJS) sections_script exehead_zlib : Release-zlib/exehead_zlib.exe Release-zlib/exehead_zlib.h
$(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_lzma : dirs $(LZMA_SRCS) $(LZMA_OBJS) sections_script Release-zlib/exehead_zlib.exe : $(ZLIB_OBJS) sections_script
$(CC) $(CFLAGS) $(LFLAGS) -o Release-lzma/exehead_lzma.exe $(LZMA_OBJS) $(LIBS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(ZLIB_OBJS) $(LIBS)
bin2h Release-lzma/exehead_lzma.exe Release-lzma/exehead_lzma.h lzma_header_data
exehead_resources : exehead_zlib Release-zlib/exehead_zlib.h : Release-zlib/exehead_zlib.exe
bin2h bitmap1.bmp Release-zlib/bitmap1.h bitmap1_data $(BIN2H) $< $@ zlib_header_data
bin2h nsis.ico Release-zlib/icon.h icon_data
bin2h uninst.ico Release-zlib/unicon.h unicon_data
sections_script: Release-zlib/%.o : %.c
echo SECTIONS > sections_script.ld $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
echo { >> sections_script.ld
echo .text : { *(.text) } >> sections_script.ld Release-zlib/resource.res : resource.rc resource.h config.h
echo .data : { *(.data) } >> sections_script.ld $(RC) $(RCFLAGS) -o $@ -i $<
echo .rdata : { *(.rdata) } >> sections_script.ld
echo .bss : { *(.bss) } >> sections_script.ld exehead_bzip2 : Release-bzip2/exehead_bzip2.exe Release-bzip2/exehead_bzip2.h
echo .idata : { *(.idata) } >> sections_script.ld
echo .ndata BLOCK(__section_alignment__) : { [ .ndata ] } >> sections_script.ld Release-bzip2/exehead_bzip2.exe : $(BZIP2_OBJS) sections_script
echo .rsrc : { *(.rsrc) } >> sections_script.ld $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(BZIP2_OBJS) $(LIBS)
echo } >> sections_script.ld
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-zlib/ = -DNSIS_COMPRESS_USE_ZLIB
Release-bzip2/ = -DNSIS_COMPRESS_USE_BZIP2 Release-bzip2/ = -DNSIS_COMPRESS_USE_BZIP2
Release-lzma/ = -DNSIS_COMPRESS_USE_LZMA Release-lzma/ = -DNSIS_COMPRESS_USE_LZMA
getdefine = $($(dir $@)) getdefine = $($(dir $@))
Release-zlib/%.o Release-bzip2/%.o Release-lzma/%.o : %.c $(DEPENDS) CFLAGS =: $(CFLAGS) $(getdefine)
$(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
clean :: clean ::
$(RM) sections_script.ld $(RM) -f sections_script
$(RM) Release-zlib/*.o $(RM) -f Release-zlib/*.o
$(RM) Release-zlib/resource.res $(RM) -f Release-zlib/resource.res
$(RM) Release-zlib/exehead_zlib.exe $(RM) -f Release-zlib/exehead_zlib.exe
$(RM) Release-zlib/exehead_zlib.h $(RM) -f Release-zlib/exehead_zlib.h
$(RM) Release-zlib/bitmap1.h $(RM) -f Release-zlib/bitmap1.h
$(RM) Release-zlib/icon.h $(RM) -f Release-zlib/icon.h
$(RM) Release-zlib/unicon.h $(RM) -f Release-zlib/unicon.h
$(RM) Release-bzip2/*.o $(RM) -f Release-bzip2/*.o
$(RM) Release-bzip2/resource.res $(RM) -f Release-bzip2/resource.res
$(RM) Release-bzip2/exehead_bzip2.exe $(RM) -f Release-bzip2/exehead_bzip2.exe
$(RM) Release-bzip2/exehead_bzip2.h $(RM) -f Release-bzip2/exehead_bzip2.h
$(RM) Release-lzma/*.o $(RM) -f Release-lzma/*.o
$(RM) Release-lzma/resource.res $(RM) -f Release-lzma/resource.res
$(RM) Release-lzma/exehead_lzma.exe $(RM) -f Release-lzma/exehead_lzma.exe
$(RM) Release-lzma/exehead_lzma.h $(RM) -f Release-lzma/exehead_lzma.h
.PHONY : exehead_zlib exehead_bzip2 exehead_lzma exehead_resources dirs clean

View file

@ -794,7 +794,7 @@ static int NSISCALL _sumsecsfield(int idx)
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
if (sections[x].flags & SF_SELECTED) if (sections[x].flags & SF_SELECTED)
#endif #endif
total += sections[x].fields[idx]; total += ((int *)&sections[x])[idx];
} }
return total; return total;
} }

View file

@ -24,7 +24,7 @@ typedef struct _stack_t {
static stack_t *g_st; static stack_t *g_st;
#endif #endif
union exec_flags g_exec_flags; exec_flags g_exec_flags;
#if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT) #if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT)
HRESULT g_hres; HRESULT g_hres;
@ -212,16 +212,16 @@ static int NSISCALL ExecuteEntry(entry *entry_)
break; break;
#endif//NSIS_CONFIG_VISIBLE_SUPPORT #endif//NSIS_CONFIG_VISIBLE_SUPPORT
case EW_SETFLAG: case EW_SETFLAG:
g_exec_flags.flags[parm0]=GetIntFromParm(1); FIELDN(g_exec_flags,parm0)=GetIntFromParm(1);
break; break;
case EW_IFFLAG: case EW_IFFLAG:
{ {
int f=lent.offsets[!g_exec_flags.flags[parm2]]; int f=lent.offsets[!FIELDN(g_exec_flags,parm2)];
g_exec_flags.flags[parm2]&=parm3; FIELDN(g_exec_flags,parm2)&=parm3;
return f; return f;
} }
case EW_GETFLAG: case EW_GETFLAG:
myitoa(var0,g_exec_flags.flags[parm1]); myitoa(var0,FIELDN(g_exec_flags,parm1));
break; break;
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_VISIBLE_SUPPORT
case EW_CHDETAILSVIEW: case EW_CHDETAILSVIEW:

View file

@ -1,7 +1,7 @@
#ifndef _EXEC_H_ #ifndef _EXEC_H_
#define _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 int NSISCALL ExecuteCodeSegment(int pos, HWND hwndProgress); // returns 0 on success

View file

@ -315,18 +315,14 @@ typedef struct
#define SF_EXPAND 32 #define SF_EXPAND 32
#define SF_PSELECTED 64 #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 name_ptr; // '' for non-optional components int flags; // SF_* - defined above
int install_types; // bits set for each of the different install_types, if any. int code;
int flags; // SF_* - defined above int code_size;
int code; int size_kb;
int code_size;
int size_kb;
};
int fields[1];
} section; } section;
#define SECTION_OFFSET(field) (FIELD_OFFSET(section, field)/sizeof(int)) #define SECTION_OFFSET(field) (FIELD_OFFSET(section, field)/sizeof(int))
@ -395,6 +391,7 @@ typedef struct
int parms[5]; int parms[5];
} page; } page;
// text/bg color
#define CC_TEXT 1 #define CC_TEXT 1
#define CC_TEXT_SYS 2 #define CC_TEXT_SYS 2
#define CC_BK 4 #define CC_BK 4
@ -410,6 +407,42 @@ typedef struct {
int flags; int flags;
} ctlcolors; } 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. // 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 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); BOOL NSISCALL ReadSelfFile(LPVOID lpBuffer, DWORD nNumberOfBytesToRead);
DWORD NSISCALL SetSelfFilePointer(LONG lDistanceToMove); 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 struct block_header g_blocks[BLOCKS_NUM];
extern header *g_header; extern header *g_header;
extern int g_flags; extern int g_flags;

View file

@ -4,9 +4,8 @@
#include "state.h" #include "state.h"
#include "config.h" #include "config.h"
#include "lang.h" #include "lang.h"
#include "exec.h"
#include "fileform.h" #include "fileform.h"
#include "exec.h"
#include "ui.h" #include "ui.h"
#ifdef NSIS_CONFIG_LOG #ifdef NSIS_CONFIG_LOG

View file

@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "build.h" #include "build.h"
#include "DialogTemplate.h" #include "DialogTemplate.h"
#include "exehead\resource.h" #include "exehead/resource.h"
extern const char *NSIS_VERSION; extern const char *NSIS_VERSION;
@ -313,14 +313,14 @@ int CEXEBuild::GenerateLangTables() {
init_res_editor(); init_res_editor();
#define ADD_FONT(id) { \ #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) { \ if (dlg) { \
CDialogTemplate td(dlg); \ CDialogTemplate td(dlg); \
free(dlg); \ free(dlg); \
td.SetFont(build_font, build_font_size); \ td.SetFont(build_font, build_font_size); \
DWORD dwSize; \ DWORD dwSize; \
dlg = td.Save(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); \ res_editor->FreeResource(dlg); \
} \ } \
} }
@ -368,7 +368,7 @@ int CEXEBuild::GenerateLangTables() {
init_res_editor(); init_res_editor();
#define ADD_FONT(id) { \ #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) { \ if (dlg) { \
CDialogTemplate td(dlg,lt[i].nlf.m_uCodePage); \ CDialogTemplate td(dlg,lt[i].nlf.m_uCodePage); \
free(dlg); \ free(dlg); \
@ -376,7 +376,7 @@ int CEXEBuild::GenerateLangTables() {
if (lt[i].nlf.m_bRTL) td.ConvertToRTL(); \ if (lt[i].nlf.m_bRTL) td.ConvertToRTL(); \
DWORD dwSize; \ DWORD dwSize; \
dlg = td.Save(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); \ res_editor->FreeResource(dlg); \
} \ } \
} }
@ -720,6 +720,14 @@ char SkipComments(FILE *f) {
return c; return c;
} }
#ifndef _WIN32
BOOL IsValidCodePage(UINT CodePage)
{
// FIXME make a real check
return TRUE;
}
#endif
// NSIS Language File parser // NSIS Language File parser
LanguageTable * CEXEBuild::LoadLangFile(char *filename) { LanguageTable * CEXEBuild::LoadLangFile(char *filename) {
FILE *f = fopen(filename, "r"); FILE *f = fopen(filename, "r");

View file

@ -36,6 +36,9 @@ const char *NSIS_VERSION="v2.0";
#include "Platform.h" #include "Platform.h"
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#ifdef _WIN32
# include <direct.h>
#endif
#include "build.h" #include "build.h"
#include "util.h" #include "util.h"
@ -86,6 +89,8 @@ int main(int argc, char **argv)
int tmpargpos=1; int tmpargpos=1;
int no_logo=0; int no_logo=0;
build.setdirs(argv[0]);
if (argc > 1 && !stricmp(argv[1], "/VERSION")) if (argc > 1 && !stricmp(argv[1], "/VERSION"))
{ {
fprintf(g_output,NSIS_VERSION); fprintf(g_output,NSIS_VERSION);
@ -217,9 +222,14 @@ int main(int argc, char **argv)
} }
else if (!stricmp(argv[argpos],"/NOTIFYHWND")) else if (!stricmp(argv[argpos],"/NOTIFYHWND"))
{ {
#ifdef _WIN32
build.notify_hwnd=(HWND)atol(argv[++argpos]); build.notify_hwnd=(HWND)atol(argv[++argpos]);
if (!IsWindow(build.notify_hwnd)) if (!IsWindow(build.notify_hwnd))
build.notify_hwnd=0; build.notify_hwnd=0;
#else
argpos++;
build.warning("/NOTIFYHWND is disabled for non Win32 platforms.");
#endif
} }
else if (!stricmp(argv[argpos],"/HDRINFO")) else if (!stricmp(argv[argpos],"/HDRINFO"))
{ {
@ -257,12 +267,11 @@ int main(int argc, char **argv)
{ {
g_noconfig=1; g_noconfig=1;
char exepath[1024]; char exepath[1024];
GetModuleFileName(NULL,exepath,sizeof(exepath)-1); strncpy(exepath,argv[0],sizeof(exepath)-1);
//strncpy(exepath,argv[0],1023);
exepath[1023]=0; exepath[1023]=0;
char *p=exepath; char *p=exepath;
while (*p) p++; 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++; if (p>exepath) p++;
strcpy(p,"nsisconf.nsh"); strcpy(p,"nsisconf.nsh");
FILE *cfg=fopen(exepath,"rt"); FILE *cfg=fopen(exepath,"rt");
@ -320,11 +329,19 @@ int main(int argc, char **argv)
} }
if (do_cd) if (do_cd)
{ {
char dirbuf[1024],*p; char dirbuf[1024]="";
char *p;
#ifdef _WIN32
GetFullPathName(sfile,sizeof(dirbuf),dirbuf,&p); GetFullPathName(sfile,sizeof(dirbuf),dirbuf,&p);
p=dirbuf; p=CharPrev(dirbuf,p);
while (*p) p++; #else
while (p > dirbuf && *p != '\\') p=CharPrev(dirbuf,p); 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; *p=0;
if (dirbuf[0]) if (dirbuf[0])
{ {
@ -333,7 +350,7 @@ int main(int argc, char **argv)
fprintf(g_output,"Changing directory to: \"%s\"\n",dirbuf); fprintf(g_output,"Changing directory to: \"%s\"\n",dirbuf);
fflush(g_output); fflush(g_output);
} }
if (!SetCurrentDirectory(dirbuf)) if (chdir(dirbuf))
{ {
if (build.display_errors) if (build.display_errors)
{ {

View file

@ -1,9 +1,6 @@
#include "Platform.h" #include "Platform.h"
#include <stdio.h> #include <stdio.h>
#include <shlobj.h> #include <ctype.h>
#define _RICHEDIT_VER 0x0200
#include <RichEdit.h>
#undef _RICHEDIT_VER
#include "tokens.h" #include "tokens.h"
#include "build.h" #include "build.h"
#include "util.h" #include "util.h"
@ -13,6 +10,12 @@
#include "lang.h" #include "lang.h"
#include "exehead/resource.h" #include "exehead/resource.h"
#ifndef _WIN32
# include <sys/stat.h>
# include <time.h>
# include <glob.h>
#endif
#define MAX_INCLUDEDEPTH 10 #define MAX_INCLUDEDEPTH 10
#define MAX_LINELENGTH 4096 #define MAX_LINELENGTH 4096
@ -56,6 +59,7 @@ char *CEXEBuild::set_timestamp_predefine(char *filename)
} }
char timestampbuf[256] = ""; char timestampbuf[256] = "";
#ifdef _WIN32
char datebuf[128] = ""; char datebuf[128] = "";
char timebuf[128] = ""; char timebuf[128] = "";
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
@ -76,6 +80,17 @@ char *CEXEBuild::set_timestamp_predefine(char *filename)
definedlist.add("__TIMESTAMP__",timestampbuf); 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; return oldtimestamp;
} }
@ -92,8 +107,8 @@ void CEXEBuild::restore_timestamp_predefine(char *oldtimestamp)
char *CEXEBuild::set_line_predefine(int linecnt, BOOL is_macro) char *CEXEBuild::set_line_predefine(int linecnt, BOOL is_macro)
{ {
char* linebuf = NULL; char* linebuf = NULL;
char temp[8] = ""; char temp[128] = "";
wsprintf(temp,"%d",linecnt); sprintf(temp,"%d",linecnt);
char *oldline = definedlist.find("__LINE__"); char *oldline = definedlist.find("__LINE__");
if(oldline) { if(oldline) {
@ -102,7 +117,7 @@ char *CEXEBuild::set_line_predefine(int linecnt, BOOL is_macro)
} }
if(is_macro && oldline) { if(is_macro && oldline) {
linebuf = (char *)malloc(strlen(oldline)+strlen(temp)+2); linebuf = (char *)malloc(strlen(oldline)+strlen(temp)+2);
wsprintf(linebuf,"%s.%s",oldline,temp); sprintf(linebuf,"%s.%s",oldline,temp);
} }
else { else {
linebuf = strdup(temp); linebuf = strdup(temp);
@ -126,23 +141,30 @@ void CEXEBuild::set_date_time_predefines()
{ {
time_t etime; time_t etime;
struct tm * ltime; struct tm * ltime;
SYSTEMTIME stime; char datebuf[128];
char datebuf[32]; char timebuf[128];
char timebuf[32];
time(&etime); time(&etime);
ltime = localtime(&etime); ltime = localtime(&etime);
#ifdef _WIN32
SYSTEMTIME stime;
stime.wYear = ltime->tm_year+1900; stime.wYear = ltime->tm_year+1900;
stime.wMonth = ltime->tm_mon + 1; stime.wMonth = ltime->tm_mon + 1;
stime.wDay = ltime->tm_mday; stime.wDay = ltime->tm_mday;
stime.wHour= ltime->tm_hour; stime.wHour= ltime->tm_hour;
stime.wMinute= ltime->tm_min; stime.wMinute= ltime->tm_min;
stime.wSecond= ltime->tm_sec; stime.wSecond= ltime->tm_sec;
stime.wMilliseconds= 0; stime.wMilliseconds= 0;
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stime, NULL, datebuf, sizeof(datebuf)); GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stime, NULL, datebuf, sizeof(datebuf));
definedlist.add("__DATE__",(char *)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); 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() void CEXEBuild::del_date_time_predefines()
@ -841,7 +863,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
char *p=str; char *p=str;
str[0]=0; str[0]=0;
fgets(str,MAX_LINELENGTH,fp); 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]) if (feof(fp) && !str[0])
{ {
ERROR_MSG("!macro \"%s\": unterminated (no !macroend found in file)!\n",line.gettoken_str(1)); 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 { try {
init_res_editor(); 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!"); if (!dlg) throw runtime_error("IDD_INSTFILES doesn't exist!");
CDialogTemplate dt(dlg,uDefCodePage); CDialogTemplate dt(dlg,uDefCodePage);
free(dlg); free(dlg);
@ -1908,7 +1930,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DWORD dwSize; DWORD dwSize;
dlg = dt.Save(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); res_editor->FreeResource(dlg);
} }
catch (exception& err) { catch (exception& err) {
@ -2076,7 +2098,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
SCRIPT_MSG("XPStyle: %s\n", line.gettoken_str(1)); SCRIPT_MSG("XPStyle: %s\n", line.gettoken_str(1));
init_res_editor(); init_res_editor();
const char *szXPManifest = k ? 0 : "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"><assemblyIdentity version=\"1.0.0.0\" processorArchitecture=\"X86\" name=\"Nullsoft.NSIS.exehead\" type=\"win32\"/><description>Nullsoft Install System v2.0</description><dependency><dependentAssembly><assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" version=\"6.0.0.0\" processorArchitecture=\"X86\" publicKeyToken=\"6595b64144ccf1df\" language=\"*\" /></dependentAssembly></dependency></assembly>"; const char *szXPManifest = k ? 0 : "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"><assemblyIdentity version=\"1.0.0.0\" processorArchitecture=\"X86\" name=\"Nullsoft.NSIS.exehead\" type=\"win32\"/><description>Nullsoft Install System v2.0</description><dependency><dependentAssembly><assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" version=\"6.0.0.0\" processorArchitecture=\"X86\" publicKeyToken=\"6595b64144ccf1df\" language=\"*\" /></dependentAssembly></dependency></assembly>";
res_editor->UpdateResource(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), 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) { catch (exception& err) {
ERROR_MSG("Error while adding XP style: %s\n", err.what()); 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"); 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(); if (k<0) PRINTHELP();
HINSTANCE hUIFile = LoadLibraryEx(line.gettoken_str(2), 0, LOAD_LIBRARY_AS_DATAFILE); FILE *fui = fopen(line.gettoken_str(2), "rb");
if (!hUIFile) { if (!fui) {
ERROR_MSG("Error: Can't find \"%s\" in \"%s\"!\n", line.gettoken_str(1), line.gettoken_str(2)); ERROR_MSG("Error: Can't open \"%s\"!\n", line.gettoken_str(2));
return PS_ERROR; 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(); init_res_editor();
// Search for required items // 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 GET(x) dlg = uire->GetResource(RT_DIALOG, MAKEINTRESOURCE(x), 0); if (!dlg) return PS_ERROR; CDialogTemplate UIDlg(dlg, uDefCodePage);
#define SAVE(x) dwSize = UIDlg.GetSize(); res_editor->UpdateResource(RT_DIALOG, x, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); #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) { if (k == 0 || k == 1) {
dlg = get_dlg(hUIFile, IDD_LICENSE, line.gettoken_str(2)); GET(IDD_LICENSE);
if (!dlg) return PS_ERROR;
CDialogTemplate UIDlg(dlg,uDefCodePage);
SEARCH(IDC_EDIT1); SEARCH(IDC_EDIT1);
SAVE(IDD_LICENSE); SAVE(IDD_LICENSE);
} }
if (k == 0 || k == 2) { if (k == 0 || k == 2) {
dlg = get_dlg(hUIFile, IDD_DIR, line.gettoken_str(2)); GET(IDD_DIR);
if (!dlg) return PS_ERROR;
CDialogTemplate UIDlg(dlg,uDefCodePage);
SEARCH(IDC_DIR); SEARCH(IDC_DIR);
SEARCH(IDC_BROWSE); SEARCH(IDC_BROWSE);
#ifdef NSIS_CONFIG_LOG #ifdef NSIS_CONFIG_LOG
@ -2124,18 +2161,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
} }
if (k == 0 || k == 3) { if (k == 0 || k == 3) {
dlg = get_dlg(hUIFile, IDD_SELCOM, line.gettoken_str(2)); GET(IDD_SELCOM);
if (!dlg) return PS_ERROR;
CDialogTemplate UIDlg(dlg,uDefCodePage);
SEARCH(IDC_TREE1); SEARCH(IDC_TREE1);
SEARCH(IDC_COMBO1); SEARCH(IDC_COMBO1);
SAVE(IDD_SELCOM); SAVE(IDD_SELCOM);
} }
if (k == 0 || k == 4) { if (k == 0 || k == 4) {
dlg = get_dlg(hUIFile, IDD_INST, line.gettoken_str(2)); GET(IDD_INST);
if (!dlg) return PS_ERROR;
CDialogTemplate UIDlg(dlg,uDefCodePage);
SEARCH(IDC_BACK); SEARCH(IDC_BACK);
SEARCH(IDC_CHILDRECT); SEARCH(IDC_CHILDRECT);
SEARCH(IDC_VERSTR); SEARCH(IDC_VERSTR);
@ -2161,9 +2194,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
} }
if (k == 0 || k == 5) { if (k == 0 || k == 5) {
dlg = get_dlg(hUIFile, IDD_INSTFILES, line.gettoken_str(2)); GET(IDD_INSTFILES);
if (!dlg) return PS_ERROR;
CDialogTemplate UIDlg(dlg,uDefCodePage);
SEARCH(IDC_LIST1); SEARCH(IDC_LIST1);
SEARCH(IDC_PROGRESS); SEARCH(IDC_PROGRESS);
SEARCH(IDC_SHOWDETAILS); SEARCH(IDC_SHOWDETAILS);
@ -2171,27 +2202,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
} }
if (k == 0 || k == 6) { if (k == 0 || k == 6) {
dlg = get_dlg(hUIFile, IDD_UNINST, line.gettoken_str(2)); GET(IDD_UNINST);
if (!dlg) return PS_ERROR;
CDialogTemplate UIDlg(dlg,uDefCodePage);
SEARCH(IDC_EDIT1); SEARCH(IDC_EDIT1);
SAVE(IDD_UNINST); SAVE(IDD_UNINST);
} }
if (k == 0 || k == 7) { if (k == 0 || k == 7) {
dlg = get_dlg(hUIFile, IDD_VERIFY, line.gettoken_str(2)); GET(IDD_VERIFY);
if (!dlg) return PS_ERROR;
CDialogTemplate UIDlg(dlg,uDefCodePage);
SEARCH(IDC_STR); SEARCH(IDC_STR);
// No RTL here, pure English goes here. SAVE(IDD_VERIFY);
//SAVE(IDD_VERIFY);
res_editor->UpdateResource(RT_DIALOG, IDD_VERIFY, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, UIDlg.GetSize());
} }
if (k == 0 || k == 8) { if (k == 0 || k == 8) {
dlg = get_dlg(hUIFile, IDD_LICENSE_FSRB, line.gettoken_str(2)); GET(IDD_LICENSE_FSRB);
if (!dlg) return PS_ERROR;
CDialogTemplate UIDlg(dlg,uDefCodePage);
SEARCH(IDC_EDIT1); SEARCH(IDC_EDIT1);
SEARCH(IDC_LICENSEAGREE); SEARCH(IDC_LICENSEAGREE);
SEARCH(IDC_LICENSEDISAGREE); SEARCH(IDC_LICENSEDISAGREE);
@ -2199,17 +2222,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
} }
if (k == 0 || k == 9) { if (k == 0 || k == 9) {
dlg = get_dlg(hUIFile, IDD_LICENSE_FSCB, line.gettoken_str(2)); GET(IDD_LICENSE_FSCB);
if (!dlg) return PS_ERROR;
CDialogTemplate UIDlg(dlg,uDefCodePage);
SEARCH(IDC_EDIT1); SEARCH(IDC_EDIT1);
SEARCH(IDC_LICENSEAGREE); SEARCH(IDC_LICENSEAGREE);
SAVE(IDD_LICENSE_FSCB); SAVE(IDD_LICENSE_FSCB);
} }
if (!FreeLibrary(hUIFile)) { delete uire;
ERROR_MSG("can't free library!\n"); free(ui);
}
SCRIPT_MSG("ChangeUI: %s %s%s\n", line.gettoken_str(1), line.gettoken_str(2), branding_image_found?" (branding image holder found)":""); 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; return PS_OK;
case TOK_ADDBRANDINGIMAGE: case TOK_ADDBRANDINGIMAGE:
#ifdef _WIN32
try { try {
int k=line.gettoken_enum(1,"top\0left\0bottom\0right\0"); int k=line.gettoken_enum(1,"top\0left\0bottom\0right\0");
int wh=line.gettoken_int(2); int wh=line.gettoken_int(2);
@ -2228,7 +2249,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
padding = line.gettoken_int(3); padding = line.gettoken_int(3);
init_res_editor(); 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); CDialogTemplate dt(dlg,uDefCodePage);
delete [] dlg; delete [] dlg;
@ -2275,7 +2296,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DWORD dwDlgSize; DWORD dwDlgSize;
dlg = dt.Save(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); res_editor->FreeResource(dlg);
@ -2290,6 +2311,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return PS_ERROR; return PS_ERROR;
} }
return PS_OK; return PS_OK;
#else
ERROR_MSG("Error: AddBrandingImage is disabled for non Win32 platforms.\n");
return PS_ERROR;
#endif
case TOK_SETFONT: case TOK_SETFONT:
{ {
if (!strnicmp(line.gettoken_str(1), "/LANG=", 6)) if (!strnicmp(line.gettoken_str(1), "/LANG=", 6))
@ -2498,15 +2523,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return PS_OK; return PS_OK;
case TOK_P_INCLUDE: case TOK_P_INCLUDE:
{ {
WIN32_FIND_DATA fd;
char *f = line.gettoken_str(1); char *f = line.gettoken_str(1);
int included = 0;
#ifdef _WIN32
WIN32_FIND_DATA fd;
unsigned int malloced = sizeof(fd.cFileName) + strlen(f) + 1; unsigned int malloced = sizeof(fd.cFileName) + strlen(f) + 1;
char *incfile = (char *) malloc(malloced); char *incfile = (char *) malloc(malloced);
int included = 0;
strcpy(incfile, f); strcpy(incfile, f);
char *slash = strrchr(incfile, '\\'); char *slash = strrchr(incfile, PATH_SEPARATOR_C);
HANDLE search = FindFirstFile(f, &fd); HANDLE search = FindFirstFile(f, &fd);
if (search != INVALID_HANDLE_VALUE) if (search != INVALID_HANDLE_VALUE)
@ -2519,11 +2545,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
incfile[0] = 0; incfile[0] = 0;
strcat(incfile, fd.cFileName); strcat(incfile, fd.cFileName);
if (includeScript(incfile) != PS_OK) 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; return PS_ERROR;
included++; included++;
} }
#ifdef _WIN32
while (FindNextFile(search, &fd)); while (FindNextFile(search, &fd));
FindClose(search); FindClose(search);
#else
globfree(&globbuf);
#endif
} }
else else
{ {
@ -2538,11 +2578,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
incfile = (char *) malloc(malloced); incfile = (char *) malloc(malloced);
} }
strcpy(incfile, dir); strcpy(incfile, dir);
if (*f != '\\') if (*f != PATH_SEPARATOR_C)
strcat(incfile, "\\"); strcat(incfile, PATH_SEPARATOR_STR);
strcat(incfile, f); strcat(incfile, f);
slash = strrchr(incfile, '\\'); #ifdef _WIN32
slash = strrchr(incfile, PATH_SEPARATOR_C);
search = FindFirstFile(incfile, &fd); search = FindFirstFile(incfile, &fd);
if (search != INVALID_HANDLE_VALUE) if (search != INVALID_HANDLE_VALUE)
{ {
@ -2553,12 +2594,24 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
else else
incfile[0] = 0; incfile[0] = 0;
strcat(incfile, fd.cFileName); strcat(incfile, fd.cFileName);
if (includeScript(incfile) != PS_OK) 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; return PS_ERROR;
included++; included++;
} }
#ifdef _WIN32
while (FindNextFile(search, &fd)); while (FindNextFile(search, &fd));
FindClose(search); FindClose(search);
#else
globfree(&globbuf);
#endif
break; break;
} }
else else
@ -2578,7 +2631,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
} }
return PS_OK; return PS_OK;
case TOK_P_CD: case TOK_P_CD:
#ifdef _WIN32
if (!line.gettoken_str(1)[0] || !SetCurrentDirectory(line.gettoken_str(1))) 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)); ERROR_MSG("!cd: error changing to: \"%s\"\n",line.gettoken_str(1));
return PS_ERROR; 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 && !trim) PRINTHELP();
if (line.getnumtokens()==a+1) if (line.getnumtokens()==a+1)
SetInnerString(NLF_BRANDING,line.gettoken_str(a)); SetInnerString(NLF_BRANDING,line.gettoken_str(a));
#ifdef _WIN32
if (trim) try { if (trim) try {
init_res_editor(); 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); CDialogTemplate td(dlg,uDefCodePage);
free(dlg); free(dlg);
@ -3007,7 +3065,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
char str[512]; char str[512];
extern const char *NSIS_VERSION; extern const char *NSIS_VERSION;
if (line.getnumtokens()==a+1 && line.gettoken_str(a)[0]) if (line.getnumtokens()==a+1 && line.gettoken_str(a)[0])
lstrcpy(str, line.gettoken_str(a)); strcpy(str, line.gettoken_str(a));
else else
wsprintf(str, "Nullsoft Install System %s", NSIS_VERSION); wsprintf(str, "Nullsoft Install System %s", NSIS_VERSION);
@ -3020,13 +3078,20 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DWORD dwSize; DWORD dwSize;
dlg = td.Save(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); res_editor->FreeResource(dlg);
} }
catch (exception& err) { catch (exception& err) {
ERROR_MSG("Error while triming branding text control: %s\n", err.what()); ERROR_MSG("Error while triming branding text control: %s\n", err.what());
return PS_ERROR; 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)); SCRIPT_MSG("BrandingText: \"%s\"\n",line.gettoken_str(a));
} }
return PS_OK; return PS_OK;
@ -3041,7 +3106,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return PS_OK; return PS_OK;
case TOK_SPACETEXTS: case TOK_SPACETEXTS:
{ {
if (!lstrcmpi(line.gettoken_str(1), "none")) { if (!strcmpi(line.gettoken_str(1), "none")) {
no_space_texts=true; no_space_texts=true;
SCRIPT_MSG("SpaceTexts: none\n"); SCRIPT_MSG("SpaceTexts: none\n");
} }
@ -3221,8 +3286,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
ent.offsets[3]=SW_SHOWNORMAL; ent.offsets[3]=SW_SHOWNORMAL;
if (line.getnumtokens() > 4) if (line.getnumtokens() > 4)
{ {
int tab[3]={SW_SHOWNORMAL,SW_SHOWMAXIMIZED,SW_SHOWMINIMIZED}; int tab[4]={SW_SHOWNORMAL,SW_SHOWMAXIMIZED,SW_SHOWMINIMIZED,SW_HIDE};
int a=line.gettoken_enum(4,"SW_SHOWNORMAL\0SW_SHOWMAXIMIZED\0SW_SHOWMINIMIZED\0"); int a=line.gettoken_enum(4,"SW_SHOWNORMAL\0SW_SHOWMAXIMIZED\0SW_SHOWMINIMIZED\0SW_HIDE\0");
if (a < 0) PRINTHELP() if (a < 0) PRINTHELP()
ent.offsets[3]=tab[a]; 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++) { for (int i = 3; i < line.getnumtokens(); i++) {
char *tok=line.gettoken_str(i); char *tok=line.gettoken_str(i);
if (tok[0]=='/') { if (tok[0]=='/') {
if (!lstrcmpi(tok,"/ITALIC")) { if (!strcmpi(tok,"/ITALIC")) {
SCRIPT_MSG(" /ITALIC"); SCRIPT_MSG(" /ITALIC");
flags|=1; flags|=1;
} }
else if (!lstrcmpi(tok,"/UNDERLINE")) { else if (!strcmpi(tok,"/UNDERLINE")) {
SCRIPT_MSG(" /UNDERLINE"); SCRIPT_MSG(" /UNDERLINE");
flags|=2; flags|=2;
} }
else if (!lstrcmpi(tok,"/STRIKE")) { else if (!strcmpi(tok,"/STRIKE")) {
SCRIPT_MSG(" /STRIKE"); SCRIPT_MSG(" /STRIKE");
flags|=4; flags|=4;
} }
@ -4120,6 +4185,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return add_entry(&ent); return add_entry(&ent);
case TOK_GETDLLVERSIONLOCAL: case TOK_GETDLLVERSIONLOCAL:
{ {
#ifdef _WIN32
char buf[128]; char buf[128];
DWORD low=0, high=0; DWORD low=0, high=0;
DWORD s,d; DWORD s,d;
@ -4127,7 +4193,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
int alloced=0; int alloced=0;
char *path=line.gettoken_str(1); char *path=line.gettoken_str(1);
if (!((*path == '\\' && path[1] == '\\') || (*path && path[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); char *nrpath=(char *)malloc(pathlen);
alloced=1; alloced=1;
GetCurrentDirectory(pathlen, nrpath); GetCurrentDirectory(pathlen, nrpath);
@ -4193,12 +4259,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (ent.offsets[0]<0) PRINTHELP() if (ent.offsets[0]<0) PRINTHELP()
SCRIPT_MSG("GetDLLVersionLocal: %s (%u,%u)->(%s,%s)\n", SCRIPT_MSG("GetDLLVersionLocal: %s (%u,%u)->(%s,%s)\n",
line.gettoken_str(1),high,low,line.gettoken_str(2),line.gettoken_str(3)); 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); return add_entry(&ent);
case TOK_GETFILETIMELOCAL: case TOK_GETFILETIMELOCAL:
{ {
char buf[129]; char buf[129];
DWORD high=0,low=0; DWORD high=0,low=0;
#ifdef _WIN32
int flag=0; int flag=0;
HANDLE hFile=CreateFile(line.gettoken_str(1),0,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); HANDLE hFile=CreateFile(line.gettoken_str(1),0,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (hFile != INVALID_HANDLE_VALUE) 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)); ERROR_MSG("GetFileTimeLocal: error reading date from \"%s\"\n",line.gettoken_str(1));
return PS_ERROR; 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.which=EW_ASSIGNVAR;
ent.offsets[0]=GetUserVarIndex(line, 2); ent.offsets[0]=GetUserVarIndex(line, 2);
@ -5153,7 +5247,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
int i = 1; int i = 1;
int nounload = 0; int nounload = 0;
if (!lstrcmpi(line.gettoken_str(i), "/NOUNLOAD")) { if (!strcmpi(line.gettoken_str(i), "/NOUNLOAD")) {
i++; i++;
nounload++; nounload++;
} }
@ -5166,7 +5260,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
int w=parmst + (line.getnumtokens()-i - 1); int w=parmst + (line.getnumtokens()-i - 1);
ent.which=EW_PUSHPOP; ent.which=EW_PUSHPOP;
ent.offsets[0]=add_string(line.gettoken_str(w)); 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; ent.offsets[1]=0;
ret=add_entry(&ent); ret=add_entry(&ent);
if (ret != PS_OK) { 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 dir[1024];
char newfn[1024]; char newfn[1024];
#ifdef _WIN32
HANDLE h; HANDLE h;
WIN32_FIND_DATA d; WIN32_FIND_DATA d;
#else
glob_t globbuf;
#endif
strcpy(dir,lgss); strcpy(dir,lgss);
{ {
char *s=dir+strlen(dir); 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; *s=0;
if (!*dir)
{
dir[0] = '.';
dir[1] = 0;
}
} }
#ifdef _WIN32
h = FindFirstFile(lgss,&d); h = FindFirstFile(lgss,&d);
if (h != INVALID_HANDLE_VALUE) 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) 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; MMapFile mmap;
HANDLE hFile;
DWORD len; DWORD len;
(*total_files)++; (*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, newfn,
GENERIC_READ, GENERIC_READ,
FILE_SHARE_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) if (hFile == INVALID_HANDLE_VALUE)
{ {
FindClose(h);
ERROR_MSG("%sFile: failed opening file \"%s\"\n",generatecode?"":"Reserve",newfn); ERROR_MSG("%sFile: failed opening file \"%s\"\n",generatecode?"":"Reserve",newfn);
return PS_ERROR; return PS_ERROR;
} }
len = GetFileSize(hFile, NULL); len = GetFileSize(hFile, NULL);
if (len && !mmap.setfile(hFile, len)) if (len && !mmap.setfile(hFile, len))
{ {
FindClose(h);
CloseHandle(hFile); CloseHandle(hFile);
ERROR_MSG("%sFile: failed creating mmap of \"%s\"\n",generatecode?"":"Reserve",newfn); ERROR_MSG("%sFile: failed creating mmap of \"%s\"\n",generatecode?"":"Reserve",newfn);
return PS_ERROR; 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) if (generatecode&1)
section_add_size_kb((len+1023)/1024); section_add_size_kb((len+1023)/1024);
#ifdef _WIN32
if (name_override) SCRIPT_MSG("%sFile: \"%s\"->\"%s\"",generatecode?"":"Reserve",d.cFileName,name_override); if (name_override) SCRIPT_MSG("%sFile: \"%s\"->\"%s\"",generatecode?"":"Reserve",d.cFileName,name_override);
else SCRIPT_MSG("%sFile: \"%s\"",generatecode?"":"Reserve",d.cFileName); 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_whole)
if (build_compress) SCRIPT_MSG(" [compress]"); if (build_compress) SCRIPT_MSG(" [compress]");
fflush(stdout); fflush(stdout);
@ -5327,7 +5476,11 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
} }
else else
{ {
#ifdef _WIN32
char *i=d.cFileName,*o=buf; char *i=d.cFileName,*o=buf;
#else
char *i=filename,*o=buf;
#endif
while (*i) while (*i)
{ {
char c=*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) if (ent.offsets[2] < 0)
{ {
#ifdef _WIN32
CloseHandle(hFile); CloseHandle(hFile);
FindClose(h);
#else
close(fd);
globfree(&globbuf);
#endif
return PS_ERROR; 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*/) if (build_datesave || build_overwrite>=0x3 /*ifnewer or ifdiff*/)
{ {
#ifdef _WIN32
FILETIME ft; FILETIME ft;
if (GetFileTime(hFile,NULL,NULL,&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 else
{ {
CloseHandle(hFile); 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); ERROR_MSG("%sFile: failed getting file date from \"%s\"\n",generatecode?"":"Reserve",newfn);
return PS_ERROR; 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); ent.offsets[5] = DefineInnerLangString(build_allowskipfiles ? NLF_FILE_ERROR : NLF_FILE_ERROR_NOIGNORE);
} }
#ifdef _WIN32
CloseHandle(hFile); CloseHandle(hFile);
#else
close(fd);
#endif
if (generatecode) if (generatecode)
{ {
int a=add_entry(&ent); int a=add_entry(&ent);
if (a != PS_OK) if (a != PS_OK)
{ {
#ifdef _WIN32
FindClose(h); FindClose(h);
#else
globfree(&globbuf);
#endif
return a; return a;
} }
if (attrib) if (attrib)
{ {
#ifdef _WIN32
ent.which=EW_SETFILEATTRIBUTES; ent.which=EW_SETFILEATTRIBUTES;
// $OUTDIR is the working directory // $OUTDIR is the working directory
ent.offsets[0]=add_string(name_override?name_override:buf); 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); FindClose(h);
return a; 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); FindClose(h);
#else
globfree(&globbuf);
#endif
} }
if (recurse) if (recurse)
{ {
#ifdef NSIS_SUPPORT_STACK #ifdef NSIS_SUPPORT_STACK
#ifdef _WIN32
WIN32_FIND_DATA temp; WIN32_FIND_DATA temp;
#endif
DWORD a=GetFileAttributes(lgss); #ifdef _WIN32
const char *fspec=lgss+strlen(dir)+!!dir[0]; 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); strcpy(newfn,lgss);
#ifdef _WIN32
DWORD a=GetFileAttributes(lgss);
if (a==INVALID_FILE_ATTRIBUTES) if (a==INVALID_FILE_ATTRIBUTES)
{ {
a=GetFileAttributes(dir); 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 else
{ {
// we don't want to include a whole directory if it's not the first call // we don't want to include a whole directory if it's not the first call
if (rec_depth) return PS_OK; if (rec_depth) return PS_OK;
#ifdef _WIN32
fspec="*.*"; fspec="*.*";
#else
fspec="*";
#endif
} }
#ifdef _WIN32
if (a&FILE_ATTRIBUTE_DIRECTORY) if (a&FILE_ATTRIBUTE_DIRECTORY)
{ {
h=FindFirstFile(newfn,&d); 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,".")) 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 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) while (*i)
{ {
@ -5493,35 +5741,58 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
} }
char spec[1024]; 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); SCRIPT_MSG("%sFile: Descending to: \"%s\"\n",generatecode?"":"Reserve",spec);
strcat(spec,"\\"); strcat(spec,PATH_SEPARATOR_STR);
strcat(spec,fspec); strcat(spec,fspec);
if (generatecode) if (generatecode)
{ {
a=add_entry_direct(EW_PUSHPOP, add_string("$OUTDIR")); a=add_entry_direct(EW_PUSHPOP, add_string("$OUTDIR"));
if (a != PS_OK) if (a != PS_OK)
{ {
#ifdef _WIN32
FindClose(h); FindClose(h);
#else
globfree(&globbuf);
#endif
return a; return a;
} }
a=add_entry_direct(EW_ASSIGNVAR, m_UserVarNames.get("OUTDIR"), add_string(out_path)); a=add_entry_direct(EW_ASSIGNVAR, m_UserVarNames.get("OUTDIR"), add_string(out_path));
if (a != PS_OK) if (a != PS_OK)
{ {
#ifdef _WIN32
FindClose(h); FindClose(h);
#else
globfree(&globbuf);
#endif
return a; return a;
} }
#ifdef _WIN32
HANDLE htemp = FindFirstFile(spec,&temp); HANDLE htemp = FindFirstFile(spec,&temp);
if (htemp != INVALID_HANDLE_VALUE) if (htemp != INVALID_HANDLE_VALUE)
{ {
FindClose(htemp); 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); a=add_entry_direct(EW_CREATEDIR, add_string("$OUTDIR"), 1);
if (a != PS_OK) if (a != PS_OK)
{ {
#ifdef _WIN32
FindClose(h); FindClose(h);
#else
globfree(&globbuf2);
#endif
return a; 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); a=do_add_file(spec,attrib,recurse,linecnt,total_files,NULL,generatecode,data_handle,rec_depth+1);
if (a != PS_OK) if (a != PS_OK)
{ {
#ifdef _WIN32
FindClose(h); FindClose(h);
#else
globfree(&globbuf);
#endif
return a; 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); a=add_entry_direct(EW_PUSHPOP, m_UserVarNames.get("OUTDIR"), 1);
if (a != PS_OK) if (a != PS_OK)
{ {
#ifdef _WIN32
FindClose(h); FindClose(h);
#else
globfree(&globbuf);
#endif
return a; return a;
} }
if (attrib) if (attrib)
{ {
#ifdef _WIN32
a=add_entry_direct(EW_SETFILEATTRIBUTES, add_string(out_path), d.dwFileAttributes); a=add_entry_direct(EW_SETFILEATTRIBUTES, add_string(out_path), d.dwFileAttributes);
if (a != PS_OK) if (a != PS_OK)
{ {
FindClose(h); FindClose(h);
return a; return a;
} }
#else
warning_fl("File /a is disabled for non Win32 platforms.");
#endif
} }
} }
SCRIPT_MSG("%sFile: Returning to: \"%s\"\n",generatecode?"":"Reserve",dir); SCRIPT_MSG("%sFile: Returning to: \"%s\"\n",generatecode?"":"Reserve",dir);
} }
} }
} while (FindNextFile(h,&d)); }
#ifdef _WIN32
while (FindNextFile(h,&d));
FindClose(h); FindClose(h);
#else
globfree(&globbuf);
#endif
if (!rec_depth) 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); a=add_entry_direct(EW_CREATEDIR, add_string("$OUTDIR"), 1);
if (a != PS_OK) if (a != PS_OK)
{ {
FindClose(h);
return a; return a;
} }
} }

View file

@ -4,6 +4,12 @@
#include "Platform.h" #include "Platform.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> // for gcc #include <stdlib.h> // for gcc
#ifndef _WIN32
# include <sys/mman.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <unistd.h>
#endif
class IGrowBuf class IGrowBuf
{ {
@ -20,9 +26,10 @@ class IMMap
virtual void resize(int newlen)=0; virtual void resize(int newlen)=0;
virtual int getsize()=0; virtual int getsize()=0;
virtual void *get(int offset, int size)=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()=0;
virtual void release(void *view)=0; virtual void release(void *view, int size)=0;
virtual void clear()=0; virtual void clear()=0;
virtual void setro(BOOL bRO)=0; virtual void setro(BOOL bRO)=0;
virtual void flush(int num)=0; virtual void flush(int num)=0;
@ -485,8 +492,13 @@ class MMapFile : public IMMap
public: public:
MMapFile() MMapFile()
{ {
#ifdef _WIN32
m_hFile = INVALID_HANDLE_VALUE; m_hFile = INVALID_HANDLE_VALUE;
m_hFileMap = NULL; m_hFileMap = NULL;
#else
m_hFile = -1;
#endif
m_pView = NULL; m_pView = NULL;
m_iSize = 0; m_iSize = 0;
m_bReadOnly = FALSE; m_bReadOnly = FALSE;
@ -494,9 +506,13 @@ class MMapFile : public IMMap
if (!m_iAllocationGranularity) if (!m_iAllocationGranularity)
{ {
#ifdef _WIN32
SYSTEM_INFO si; SYSTEM_INFO si;
GetSystemInfo(&si); GetSystemInfo(&si);
m_iAllocationGranularity = (int) si.dwAllocationGranularity; m_iAllocationGranularity = (int) si.dwAllocationGranularity;
#else
m_iAllocationGranularity = getpagesize();
#endif
} }
} }
@ -509,12 +525,17 @@ class MMapFile : public IMMap
{ {
release(); release();
#ifdef _WIN32
if (m_hFileMap) if (m_hFileMap)
CloseHandle(m_hFileMap); CloseHandle(m_hFileMap);
if (m_bTempHandle && m_hFile) if (m_bTempHandle && m_hFile)
CloseHandle(m_hFile); CloseHandle(m_hFile);
m_hFileMap = 0; m_hFileMap = 0;
#else
if (m_bTempHandle && m_hFile)
close(m_hFile);
#endif
} }
void setro(BOOL bRO) void setro(BOOL bRO)
@ -522,21 +543,22 @@ class MMapFile : public IMMap
m_bReadOnly = bRO; m_bReadOnly = bRO;
} }
#ifdef _WIN32
int setfile(HANDLE hFile, DWORD dwSize) int setfile(HANDLE hFile, DWORD dwSize)
#else
int setfile(int hFile, DWORD dwSize)
#endif
{ {
release(); clear();
if (m_hFileMap)
CloseHandle(m_hFileMap);
if (m_bTempHandle && m_hFile)
CloseHandle(m_hFile);
m_hFileMap = 0;
m_hFile = hFile; m_hFile = hFile;
m_bTempHandle = FALSE; m_bTempHandle = FALSE;
#ifdef _WIN32
if (m_hFile == INVALID_HANDLE_VALUE) if (m_hFile == INVALID_HANDLE_VALUE)
#else
if (m_hFile == -1)
#endif
return 0; return 0;
m_iSize = (int) dwSize; m_iSize = (int) dwSize;
@ -544,10 +566,12 @@ class MMapFile : public IMMap
if (m_iSize <= 0) if (m_iSize <= 0)
return 0; return 0;
#ifdef _WIN32
m_hFileMap = CreateFileMapping(m_hFile, NULL, PAGE_READONLY, 0, m_iSize, NULL); m_hFileMap = CreateFileMapping(m_hFile, NULL, PAGE_READONLY, 0, m_iSize, NULL);
if (!m_hFileMap) if (!m_hFileMap)
return 0; return 0;
#endif
m_bReadOnly = TRUE; m_bReadOnly = TRUE;
@ -560,13 +584,16 @@ class MMapFile : public IMMap
if (newsize > m_iSize) if (newsize > m_iSize)
{ {
#ifdef _WIN32
if (m_hFileMap) if (m_hFileMap)
CloseHandle(m_hFileMap); CloseHandle(m_hFileMap);
m_hFileMap = 0; m_hFileMap = 0;
#endif
m_iSize = newsize; m_iSize = newsize;
#ifdef _WIN32
if (m_hFile == INVALID_HANDLE_VALUE) if (m_hFile == INVALID_HANDLE_VALUE)
{ {
char buf[MAX_PATH], buf2[MAX_PATH]; char buf[MAX_PATH], buf2[MAX_PATH];
@ -610,6 +637,14 @@ class MMapFile : public IMMap
} }
quit(); 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) void *get(int offset, int size)
{ {
return get(offset, &size);
}
void *get(int offset, int *sizep)
{
if (!sizep)
return NULL;
if (m_pView) if (m_pView)
release(); release();
int size = *sizep;
if (!m_iSize || offset + size > m_iSize) if (!m_iSize || offset + size > m_iSize)
{ {
extern FILE *g_output; extern FILE *g_output;
@ -639,9 +684,18 @@ class MMapFile : public IMMap
int alignedoffset = offset - (offset % m_iAllocationGranularity); int alignedoffset = offset - (offset % m_iAllocationGranularity);
size += offset - alignedoffset; size += offset - alignedoffset;
#ifdef _WIN32
m_pView = MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, alignedoffset, size); 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) if (!m_pView)
#else
if (m_pView == MAP_FAILED)
#endif
{ {
extern FILE *g_output; extern FILE *g_output;
extern void quit(); extern int g_display_errors; extern void quit(); extern int g_display_errors;
@ -656,13 +710,19 @@ class MMapFile : public IMMap
return (void *)((char *)m_pView + offset - alignedoffset); return (void *)((char *)m_pView + offset - alignedoffset);
} }
void *getmore(int offset, int size) void *getmore(int offset, int *size)
{ {
void *pView; void *pView;
void *pViewBackup = m_pView; void *pViewBackup = m_pView;
#ifndef _WIN32
int iMappedSizeBackup = m_iMappedSize;
#endif
m_pView = 0; m_pView = 0;
pView = get(offset, size); pView = get(offset, size);
m_pView = pViewBackup; m_pView = pViewBackup;
#ifndef _WIN32
m_iMappedSize = iMappedSizeBackup;
#endif
return pView; return pView;
} }
@ -671,26 +731,43 @@ class MMapFile : public IMMap
if (!m_pView) if (!m_pView)
return; return;
#ifdef _WIN32
UnmapViewOfFile(m_pView); UnmapViewOfFile(m_pView);
#else
munmap(m_pView, m_iMappedSize);
#endif
m_pView = NULL; m_pView = NULL;
} }
void release(void *pView) void release(void *pView, int size)
{ {
if (!pView) if (!pView)
return; return;
#ifdef _WIN32
UnmapViewOfFile(pView); UnmapViewOfFile(pView);
#else
munmap(pView, size);
#endif
} }
void flush(int num) void flush(int num)
{ {
if (m_pView) if (m_pView)
#ifdef _WIN32
FlushViewOfFile(m_pView, num); FlushViewOfFile(m_pView, num);
#else
msync(m_pView, num, MS_SYNC);
#endif
} }
private: private:
#ifdef _WIN32
HANDLE m_hFile, m_hFileMap; HANDLE m_hFile, m_hFileMap;
#else
int m_hFile;
int m_iMappedSize;
#endif
void *m_pView; void *m_pView;
int m_iSize; int m_iSize;
BOOL m_bReadOnly; BOOL m_bReadOnly;
@ -721,19 +798,24 @@ class MMapFake : public IMMap
void *get(int offset, int size) 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 NULL;
return (void *)(m_pMem + offset); return (void *)(m_pMem + offset);
} }
void *getmore(int offset, int size) void *getmore(int offset, int *size)
{ {
return get(offset, size); return get(offset, size);
} }
void resize(int n) {} void resize(int n) {}
void release() {} void release() {}
void release(void *p) {} void release(void *p, int size) {}
void clear() {} void clear() {}
void setro(BOOL b) {} void setro(BOOL b) {}
void flush(BOOL b) {} void flush(BOOL b) {}
@ -817,6 +899,14 @@ class MMapBuf : public IGrowBuf, public IMMap
return get(0, m_alloc); 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) void *get(int offset, int size)
{ {
if (m_gb_u) if (m_gb_u)
@ -824,7 +914,7 @@ class MMapBuf : public IGrowBuf, public IMMap
return (void *) ((char *) m_gb.get() + offset); return (void *) ((char *) m_gb.get() + offset);
} }
void *getmore(int offset, int size) void *getmore(int offset, int *size)
{ {
if (m_gb_u) if (m_gb_u)
return m_fm.getmore(offset, size); return m_fm.getmore(offset, size);
@ -837,10 +927,10 @@ class MMapBuf : public IGrowBuf, public IMMap
m_fm.release(); m_fm.release();
} }
void release(void *pView) void release(void *pView, int size)
{ {
if (m_gb_u) if (m_gb_u)
m_fm.release(pView); m_fm.release(pView, size);
} }
void clear() void clear()

View file

@ -3,7 +3,7 @@
#ifndef ___USERVARS___H_____ #ifndef ___USERVARS___H_____
#define ___USERVARS___H_____ #define ___USERVARS___H_____
#include "Lang.h" #include "lang.h"
struct uservarstring { struct uservarstring {
int name; int name;

View file

@ -1,7 +1,6 @@
#include "Platform.h" #include "Platform.h"
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <conio.h>
#include "exedata.h" #include "exedata.h"
#include "exehead/fileform.h" #include "exehead/fileform.h"
#include "util.h" #include "util.h"
@ -18,7 +17,7 @@ void dopause(void)
if (g_display_errors) fprintf(g_output,"MakeNSIS done - hit enter to close..."); if (g_display_errors) fprintf(g_output,"MakeNSIS done - hit enter to close...");
fflush(stdout); fflush(stdout);
int a; 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); 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); free(bitmap);
@ -146,7 +145,7 @@ int replace_icon(CResourceEditor* re, WORD wIconId, char* filename)
int i = 1; int i = 1;
// Delete old icons // 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; int iNewIconSize = 0;
@ -170,7 +169,7 @@ int replace_icon(CResourceEditor* re, WORD wIconId, char* filename)
throw bad_alloc(); throw bad_alloc();
} }
fread(iconData, sizeof(BYTE), ige->dwRawSize, f); 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); free(iconData);
fsetpos(f, &pos); fsetpos(f, &pos);
@ -185,7 +184,7 @@ int replace_icon(CResourceEditor* re, WORD wIconId, char* filename)
fclose(f); 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); 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); int idx = find_in_dir(rdRoot, (WORD) (int) RT_ICON);
MY_ASSERT(idx == -1, "no icons?!"); 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((int)rdIcons - (int)exeHeader > iNextSection, "corrupted EXE - invalid pointer");
MY_ASSERT(rdIcons->Header.NumberOfIdEntries == 0, "no icons found"); MY_ASSERT(rdIcons->Header.NumberOfIdEntries == 0, "no icons found");
for (i = 0; i < rdIcons->Header.NumberOfIdEntries; i++) { // Icons dir can't have named entries for (i = 0; i < rdIcons->Header.NumberOfIdEntries; i++) { // Icons dir can't have named entries
MY_ASSERT(!rdIcons->Entries[i].DataIsDirectory, "bad resource directory"); MY_ASSERT(!rdIcons->Entries[i].DirectoryOffset.DataIsDirectory, "bad resource directory");
PRESOURCE_DIRECTORY rd = PRESOURCE_DIRECTORY(rdIcons->Entries[i].OffsetToDirectory + DWORD(rdRoot)); 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((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)); 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; 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 #endif // NSIS_CONFIG_UNINSTALL_SUPPORT
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT // returns the number of WCHARs in str including null charcter
BYTE* get_dlg(HINSTANCE hUIFile, WORD dlgId, char* filename) { int WCStrLen(const WCHAR* szwStr) {
HRSRC hUIRes = FindResource(hUIFile, MAKEINTRESOURCE(dlgId), RT_DIALOG); int i;
if (!hUIRes) { for (i = 0; szwStr[i]; i++);
if (g_display_errors) fprintf(g_output, "Error: \"%s\" doesn't contain a dialog with the ID %u!\n", filename, dlgId); return i+1;
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;
} }
#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 *operator new(size_t size) {
void *p = malloc(size); void *p = malloc(size);

View file

@ -1,6 +1,9 @@
#ifndef _UTIL_H_ #ifndef _UTIL_H_
#define _UTIL_H_ #define _UTIL_H_
#ifndef _WIN32
# include <iconv.h>
#endif
#include "ResourceEditor.h" #include "ResourceEditor.h"
// these are the standard pause-before-quit shit. // 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); int generate_unicons_offsets(unsigned char* exeHeader, unsigned char* uninstIconData);
#endif//NSIS_CONFIG_UNINSTALL_SUPPORT #endif//NSIS_CONFIG_UNINSTALL_SUPPORT
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT // returns the number of WCHARs in str including null charcter
// Returns dialog's raw data from a given loaded module int WCStrLen(const WCHAR* szwStr);
BYTE* get_dlg(HINSTANCE hUIFile, WORD dlgId, char* filename);
#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 <typename T>
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
#endif //_UTIL_H_ #endif //_UTIL_H_

View file

@ -7,7 +7,7 @@
#ifndef _DEFLATE_H #ifndef _DEFLATE_H
#define _DEFLATE_H #define _DEFLATE_H
#include "zutil.h" #include "ZUTIL.H"
/* =========================================================================== /* ===========================================================================
* Internal compression state. * Internal compression state.

View file

@ -76,7 +76,7 @@ local inflate_huft *fixed_tl;
local inflate_huft *fixed_td; local inflate_huft *fixed_td;
/* copy as much as possible from the sliding window to the output area */ /* 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; z_streamp z;
{ {
inflate_blocks_statef *s = &z->blocks; inflate_blocks_statef *s = &z->blocks;
@ -118,7 +118,7 @@ again:
#define BMAX 15 /* maximum bit length of any code */ #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) */ uIntf *b, /* code lengths in bits (all assumed <= BMAX) */
uInt n, /* number of codes (assumed <= 288) */ uInt n, /* number of codes (assumed <= 288) */
uInt s, /* number of simple-valued codes (0..s-1) */ 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; 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_blocks_statef *s = &z->blocks;
inflate_codes_statef *c = &s->sub.decode.t_codes; /* codes state */ inflate_codes_statef *c = &s->sub.decode.t_codes; /* codes state */

View file

@ -42,8 +42,8 @@
#ifndef _ZLIB_H #ifndef _ZLIB_H
#define _ZLIB_H #define _ZLIB_H
#include "zconf.h" #include "ZCONF.H"
#include "zutil.h" #include "ZUTIL.H"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -8,13 +8,13 @@
subject to change. Applications should only use zlib.h. 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 #ifndef _Z_UTIL_H
#define _Z_UTIL_H #define _Z_UTIL_H
#include <windows.h> #include "../Platform.h"
#include "zlib.h" #include "ZLIB.H"
#ifndef local #ifndef local
# define local static # define local static
@ -63,10 +63,11 @@ typedef unsigned long ulg;
#ifdef EXEHEAD #ifdef EXEHEAD
#include "../exehead/util.h" #include "../exehead/util.h"
#define ZALLOC(strm, items, size) my_GlobalAlloc((items)*(size)) #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); } #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 TRY_FREE(s, p) { ZFREE(s, p); }
#define ERR_RETURN(strm,err) return (err) #define ERR_RETURN(strm,err) return (err)

View file

@ -4,7 +4,7 @@
*/ */
#include "deflate.h" #include "DEFLATE.H"
const char deflate_copyright[] = const char deflate_copyright[] =
" deflate 1.1.3 Copyright 1995-1998 Jean-loup Gailly "; " 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]; s->ins_h = s->window[s->strstart];
UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
#if MIN_MATCH != 3 #if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times # error Call UPDATE_HASH() MIN_MATCH-3 more times
#endif #endif
} }

View file

@ -4,7 +4,7 @@
*/ */
#include "deflate.h" #include "DEFLATE.H"
#ifdef DEBUG #ifdef DEBUG
# include <ctype.h> # include <ctype.h>