From 4e48722b63c6a57b388d01c0adaf64ea59e0d1fc Mon Sep 17 00:00:00 2001 From: wizou Date: Mon, 16 Nov 2009 14:10:29 +0000 Subject: [PATCH 1/2] creating working branch for wizou git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/branches/wizou@6000 212acab6-be3b-0410-9dea-997c60f758d6 From 752d7d239a2d80be92685219a0a330426dad908d Mon Sep 17 00:00:00 2001 From: wizou Date: Wed, 24 Mar 2010 17:22:56 +0000 Subject: [PATCH 2/2] Jim Park's Unicode NSIS merging - Step 1 : switch to TCHARs where relevant. Compiler output is identical before & after this step git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/branches/wizou@6036 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/AdvSplash/advsplash.c | 21 +- Contrib/Banner/Banner.c | 12 +- Contrib/BgImage/BgImage.cpp | 44 +- Contrib/Dialer/dialer.c | 27 +- Contrib/ExDLL/SConscript | 3 +- Contrib/ExDLL/exdll.c | 9 +- Contrib/ExDLL/nsis_tchar.h | 214 ++ Contrib/ExDLL/pluginapi.c | 62 +- Contrib/ExDLL/pluginapi.h | 27 +- Contrib/InstallOptions/InstallerOptions.cpp | 434 ++-- Contrib/LangDLL/LangDLL.c | 42 +- Contrib/Library/LibraryLocal/LibraryLocal.cpp | 46 +- Contrib/Library/RegTool/RegTool.c | 103 +- Contrib/Library/TypeLib/TypeLib.cpp | 21 +- Contrib/MakeLangId/MakeLangId.cpp | 21 +- Contrib/Makensisw/afxres.h | 2 + Contrib/Makensisw/jnetlib/asyncdns.cpp | 7 +- Contrib/Makensisw/jnetlib/asyncdns.h | 3 + Contrib/Makensisw/jnetlib/connection.cpp | 2 + Contrib/Makensisw/jnetlib/connection.h | 2 + Contrib/Makensisw/jnetlib/httpget.cpp | 12 +- Contrib/Makensisw/jnetlib/httpget.h | 6 + Contrib/Makensisw/jnetlib/netinc.h | 14 +- Contrib/Makensisw/jnetlib/util.cpp | 6 + Contrib/Makensisw/jnetlib/util.h | 5 + Contrib/Makensisw/makensisw.cpp | 187 +- Contrib/Makensisw/makensisw.h | 118 +- Contrib/Makensisw/toolbar.cpp | 21 +- Contrib/Makensisw/toolbar.h | 1 + Contrib/Makensisw/update.cpp | 53 +- Contrib/Makensisw/update.h | 2 + Contrib/Makensisw/utils.cpp | 244 +- Contrib/Makensisw/utils.h | 18 +- Contrib/Makensisw/version.cpp | 8 +- Contrib/Math/Source/Math.c | 334 +-- Contrib/Math/Source/Math.h | 4 +- Contrib/Math/Source/MyMath.c | 86 +- Contrib/Math/Source/MyMath.h | 26 +- Contrib/Math/Source/plugin.c | 10 +- Contrib/NSIS Menu/SConscript | 126 +- Contrib/NSIS Menu/nsismenu/nsismenu.cpp | 9 +- Contrib/NSIS Menu/nsismenu/nslinks.cpp | 9 +- Contrib/NSIS Menu/wx/setup.h | 3 + Contrib/NSIS Menu/wx/wxbuild.bat | 34 +- Contrib/NSISdl/asyncdns.cpp | 168 +- Contrib/NSISdl/asyncdns.h | 82 +- Contrib/NSISdl/connection.cpp | 892 +++---- Contrib/NSISdl/connection.h | 273 +- Contrib/NSISdl/httpget.cpp | 1000 ++++---- Contrib/NSISdl/httpget.h | 222 +- Contrib/NSISdl/netinc.h | 88 +- Contrib/NSISdl/nsisdl.cpp | 1196 ++++----- Contrib/NSISdl/util.cpp | 173 +- Contrib/NSISdl/util.h | 74 +- Contrib/Splash/splash.c | 24 +- Contrib/StartMenu/StartMenu.c | 60 +- Contrib/System/Source/Buffers.c | 30 +- Contrib/System/Source/Plugin.c | 60 +- Contrib/System/Source/Plugin.h | 22 +- Contrib/System/Source/System.c | 258 +- Contrib/System/Source/System.h | 4 +- Contrib/System/System.nsh | 1 + Contrib/UIs/default.rc | 6 +- Contrib/UIs/modern.rc | 6 +- Contrib/UIs/resource.h | 1 + Contrib/UIs/sdbarker_tiny.rc | 6 +- Contrib/UIs/ui.c | 22 +- Contrib/UserInfo/UserInfo.c | 46 +- Contrib/VPatch/Source/GenPat/Checksums.cpp | 5 +- Contrib/VPatch/Source/GenPat/Checksums.h | 5 +- Contrib/VPatch/Source/GenPat/ChunkedFile.cpp | 13 +- Contrib/VPatch/Source/GenPat/ChunkedFile.h | 2 + Contrib/VPatch/Source/GenPat/FileFormat1.cpp | 6 +- Contrib/VPatch/Source/GenPat/FileFormat1.h | 2 + Contrib/VPatch/Source/GenPat/GlobalTypes.cpp | 2 + Contrib/VPatch/Source/GenPat/GlobalTypes.h | 2 + Contrib/VPatch/Source/GenPat/POSIXUtil.cpp | 32 +- Contrib/VPatch/Source/GenPat/POSIXUtil.h | 9 +- .../VPatch/Source/GenPat/PatchGenerator.cpp | 17 +- Contrib/VPatch/Source/GenPat/PatchGenerator.h | 2 + Contrib/VPatch/Source/GenPat/adler32.cpp | 2 + Contrib/VPatch/Source/GenPat/adler32.h | 2 + Contrib/VPatch/Source/GenPat/main.cpp | 132 +- Contrib/VPatch/Source/GenPat/md5.c | 3 +- Contrib/VPatch/Source/GenPat/md5.h | 3 +- Contrib/VPatch/Source/GenPat/tchar.h | 28 + Contrib/VPatch/Source/Plugin/apply_patch.c | 2 + Contrib/VPatch/Source/Plugin/apply_patch.h | 2 + Contrib/VPatch/Source/Plugin/checksum.c | 2 + Contrib/VPatch/Source/Plugin/checksum.h | 4 + Contrib/VPatch/Source/Plugin/md5.c | 3 +- Contrib/VPatch/Source/Plugin/md5.h | 4 +- Contrib/VPatch/Source/Plugin/vpatchdll.c | 46 +- Contrib/nsDialogs/browse.c | 51 +- Contrib/nsDialogs/defs.h | 6 +- Contrib/nsDialogs/input.c | 12 +- Contrib/nsDialogs/input.h | 2 + Contrib/nsDialogs/nsDialogs.c | 90 +- Contrib/nsDialogs/rtl.c | 2 +- Contrib/nsExec/nsexec.c | 165 +- Contrib/zip2exe/main.cpp | 306 +-- Contrib/zip2exe/zlib/adler32.c | 2 +- Contrib/zip2exe/zlib/ioapi.c | 15 +- Contrib/zip2exe/zlib/ioapi.h | 6 +- Contrib/zip2exe/zlib/unzip.c | 7 +- Contrib/zip2exe/zlib/unzip.h | 8 +- Docs/src/credits.but | 6 + Include/FileFunc.nsh | 16 +- Include/LogicLib.nsh | 2 +- Include/StrFunc.nsh | 6 +- Include/WinVer.nsh | 17 +- Menu/index.html | 2 +- SCons/Config/ms | 92 +- SCons/Tools/mstoolkit.py | 2 +- SCons/config.py | 2 +- SConstruct | 49 +- Source/7zip/7zGuids.cpp | 2 + Source/7zip/Common/Alloc.cpp | 17 +- Source/7zip/Common/Alloc.h | 2 + Source/7zip/Common/CRC.cpp | 2 + Source/7zip/Common/CRC.h | 2 + Source/7zip/LZMADecode.c | 2 + Source/7zip/LZMADecode.h | 2 + Source/DialogTemplate.cpp | 14 +- Source/DialogTemplate.h | 12 +- Source/Platform.h | 39 +- Source/Plugins.cpp | 30 +- Source/Plugins.h | 26 +- Source/ResourceEditor.cpp | 6 +- Source/ResourceEditor.h | 5 +- Source/ResourceVersionInfo.cpp | 35 +- Source/ResourceVersionInfo.h | 83 +- Source/ShConstants.cpp | 10 +- Source/ShConstants.h | 8 +- Source/Tests/SConscript | 6 +- Source/Tests/memcpy.c | 2 + Source/Tests/mmap.cpp | 4 +- Source/Tests/specmatch.cpp | 42 +- Source/Tests/winchar.cpp | 1 + Source/build.cpp | 912 +++---- Source/build.h | 910 +++---- Source/bzip2/blocksort.c | 12 +- Source/bzip2/bzlib.c | 2 + Source/bzip2/bzlib.h | 2 + Source/bzip2/compress.c | 6 +- Source/bzip2/decompress.c | 2 + Source/bzip2/huffman.c | 2 + Source/cbzip2.h | 18 +- Source/clzma.cpp | 22 +- Source/clzma.h | 6 +- Source/compressor.h | 8 +- Source/crc32.c | 2 + Source/crc32.h | 2 + Source/czlib.h | 20 +- Source/dirreader.cpp | 65 +- Source/dirreader.h | 32 +- Source/exehead/Main.c | 56 +- Source/exehead/Ui.c | 97 +- Source/exehead/api.h | 2 +- Source/exehead/bgbg.c | 2 + Source/exehead/components.c | 2 + Source/exehead/components.h | 3 + Source/exehead/config.h | 2 + Source/exehead/exec.c | 337 +-- Source/exehead/exec.h | 2 + Source/exehead/fileform.c | 25 +- Source/exehead/fileform.h | 24 +- Source/exehead/lang.h | 27 +- Source/exehead/state.h | 4 +- Source/exehead/ui.h | 4 +- Source/exehead/util.c | 275 +- Source/exehead/util.h | 95 +- Source/fileform.cpp | 3 + Source/fileform.h | 2 + Source/growbuf.cpp | 28 +- Source/growbuf.h | 74 +- Source/icon.cpp | 13 +- Source/icon.h | 4 +- Source/lang.cpp | 459 ++-- Source/lang.h | 165 +- Source/lineparse.cpp | 81 +- Source/lineparse.h | 14 +- Source/makenssi.cpp | 277 +- Source/manifest.cpp | 5 + Source/manifest.h | 4 +- Source/mmap.cpp | 12 +- Source/mmap.h | 99 + Source/script.cpp | 2232 ++++++++--------- Source/strlist.cpp | 38 +- Source/strlist.h | 347 ++- Source/tchar.h | 210 ++ Source/tokens.cpp | 504 ++-- Source/tokens.h | 548 ++-- Source/tstring.h | 91 + Source/uservars.h | 34 +- Source/util.cpp | 190 +- Source/util.h | 48 +- Source/winchar.cpp | 2 + Source/winchar.h | 2 + Source/writer.cpp | 4 + Source/writer.h | 7 +- Source/zlib/DEFLATE.H | 2 + Source/zlib/INFBLOCK.C | 26 +- Source/zlib/ZCONF.H | 4 +- Source/zlib/ZLIB.H | 12 +- Source/zlib/ZUTIL.H | 8 +- Source/zlib/deflate.c | 50 +- Source/zlib/trees.c | 68 +- TODO.txt | 9 +- 209 files changed, 9698 insertions(+), 7658 deletions(-) create mode 100644 Contrib/ExDLL/nsis_tchar.h create mode 100644 Contrib/VPatch/Source/GenPat/tchar.h create mode 100644 Source/tchar.h create mode 100644 Source/tstring.h diff --git a/Contrib/AdvSplash/advsplash.c b/Contrib/AdvSplash/advsplash.c index bdf8acfc..c441f200 100644 --- a/Contrib/AdvSplash/advsplash.c +++ b/Contrib/AdvSplash/advsplash.c @@ -1,3 +1,4 @@ +// Unicode support by Jim Park -- 08/22/2007 // For layered windows #define _WIN32_WINNT 0x0500 @@ -15,7 +16,7 @@ int g_rv; int resolution; int sleep_val, fadein_val, fadeout_val, state, timeleft, keycolor, nt50, alphaparam; -const char classname[4] = "_sp"; +const TCHAR classname[4] = _T("_sp"); typedef BOOL(_stdcall * _tSetLayeredWindowAttributesProc) (HWND hwnd, // handle to the layered window COLORREF crKey, // specifies the color key @@ -170,11 +171,11 @@ void CALLBACK TimeProc(UINT uID, } void __declspec(dllexport) show(HWND hwndParent, int string_size, - char *variables, stack_t ** stacktop) + TCHAR *variables, stack_t ** stacktop) { DEVMODE dm; - char fn[MAX_PATH]; - char temp[64]; + TCHAR fn[MAX_PATH]; + TCHAR temp[64]; g_rv = -1; resolution = RESOLUTION; @@ -223,10 +224,10 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = classname; if (RegisterClass(&wc)) { - char fn2[MAX_PATH]; + TCHAR fn2[MAX_PATH]; lstrcpy(fn2, fn); - lstrcat(fn, ".bmp"); - lstrcat(fn2, ".wav"); + lstrcat(fn, _T(".bmp")); + lstrcat(fn2, _T(".wav")); g_hbm = LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE); @@ -235,7 +236,7 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, UINT timerEvent; // Get Bitmap Information - GetObject(g_hbm, sizeof(bm), (LPSTR) & bm); + GetObject(g_hbm, sizeof(bm), & bm); myWnd = CreateWindowEx(WS_EX_TOOLWINDOW | @@ -246,7 +247,7 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, // Set transparency / key color if (nt50) { // Get blending proc address - HANDLE user32 = GetModuleHandle("user32"); + HANDLE user32 = GetModuleHandle(_T("user32")); SetLayeredWindowAttributesProc = (_tSetLayeredWindowAttributesProc) GetProcAddress(user32, "SetLayeredWindowAttributes"); @@ -283,6 +284,6 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, UnregisterClass(wc.lpszClassName, g_hInstance); } } - wsprintf(temp, "%d", g_rv); + wsprintf(temp, _T("%d"), g_rv); pushstring(temp); } diff --git a/Contrib/Banner/Banner.c b/Contrib/Banner/Banner.c index 018cd447..f4b42cd3 100644 --- a/Contrib/Banner/Banner.c +++ b/Contrib/Banner/Banner.c @@ -2,6 +2,8 @@ #include // nsis plugin #include "../../Source/exehead/resource.h" +// Unicode support added by Jim Park -- 08/02/2007 + // Turn a pair of chars into a word // Turn four chars into a dword #ifdef __BIG_ENDIAN__ // Not very likely, but, still... @@ -17,7 +19,7 @@ HWND hwBanner; HANDLE hThread; BOOL bFailed; -char buf[1024]; +TCHAR buf[1024]; BOOL CALLBACK BannerProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -116,7 +118,7 @@ static UINT_PTR PluginCallback(enum NSPIM msg) return 0; } -void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { EXDLL_INIT(); @@ -155,13 +157,13 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variable } } -void __declspec(dllexport) getWindow(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +void __declspec(dllexport) getWindow(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { - wsprintf(buf, "%u", hwBanner); + wsprintf(buf, _T("%u"), hwBanner); pushstring(buf); } -void __declspec(dllexport) destroy(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +void __declspec(dllexport) destroy(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { if (!hwBanner) return; diff --git a/Contrib/BgImage/BgImage.cpp b/Contrib/BgImage/BgImage.cpp index 4a3fc7d0..6a6a9763 100644 --- a/Contrib/BgImage/BgImage.cpp +++ b/Contrib/BgImage/BgImage.cpp @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 08/22/2007 + #include #include #include // nsis plugin @@ -8,9 +10,9 @@ g_stringsize=string_size; \ g_stacktop=stacktop; } -#define NSISFunc(name) extern "C" void __declspec(dllexport) name(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +#define NSISFunc(name) extern "C" void __declspec(dllexport) name(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) -char szTemp[2048]; +TCHAR szTemp[2048]; HWND hWndImage, hWndParent; HINSTANCE g_hInstance; @@ -37,7 +39,7 @@ struct myImageList { BYTE iType; union { HBITMAP hBitmap; - char *szText; + TCHAR *szText; COLORREF cGradientFrom; }; RECT rPos; @@ -80,14 +82,14 @@ NSISFunc(SetReturn) { extra->RegisterPluginCallback(g_hInstance, PluginCallback); popstring(szTemp); - bReturn = !lstrcmpi(szTemp, "on"); + bReturn = !lstrcmpi(szTemp, _T("on")); } -static void __stdcall my_pushstring(char *str) +static void __stdcall my_pushstring(TCHAR *str) { stack_t *th; if (!g_stacktop || !bReturn) return; - th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize); + th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+(g_stringsize*sizeof(TCHAR))); lstrcpyn(th->text,str,g_stringsize); th->next=*g_stacktop; *g_stacktop=th; @@ -104,7 +106,7 @@ NSISFunc(SetBg) { hWndParent = hwndParent; if (!hwndParent) { - my_pushstring("can't find parent window"); + my_pushstring(_T("can't find parent window")); LCS(); return; } @@ -120,18 +122,18 @@ NSISFunc(SetBg) { LoadCursor(0, IDC_ARROW), 0, 0, - "NSISBGImage", + _T("NSISBGImage"), 0 }; ATOM atomClass = RegisterClassEx(&wc); if (!atomClass) { - my_pushstring("can't create window"); + my_pushstring(_T("can't create window")); return; } hWndImage = CreateWindowEx( WS_EX_TOOLWINDOW, - (LPSTR)(DWORD)atomClass, + (LPTSTR)(DWORD)atomClass, 0, WS_CLIPSIBLINGS|WS_POPUP, 0, @@ -144,7 +146,7 @@ NSISFunc(SetBg) { 0 ); if (!hWndImage) { - my_pushstring("can't create window"); + my_pushstring(_T("can't create window")); LCS(); return; } @@ -225,7 +227,7 @@ done: ); } - my_pushstring("success"); + my_pushstring(_T("success")); } NSISFunc(AddImage) { @@ -233,7 +235,7 @@ NSISFunc(AddImage) { myImageList *newImg = (myImageList *)GlobalAlloc(GPTR, sizeof(myImageList)); if (!newImg) { - my_pushstring("memory allocation error"); + my_pushstring(_T("memory allocation error")); LCS(); return; } @@ -242,7 +244,7 @@ NSISFunc(AddImage) { newImg->cTransparent = (COLORREF)-1; popstring(szTemp); - if (!lstrcmpi(szTemp, "/TRANSPARENT")) { + if (!lstrcmpi(szTemp, _T("/TRANSPARENT"))) { newImg->iType = MIL_TRANSPARENT_BITMAP; newImg->cTransparent = GetColor(); popstring(szTemp); @@ -265,7 +267,7 @@ NSISFunc(AddImage) { while (img->next) img = img->next; img->next = newImg; - my_pushstring("success"); + my_pushstring(_T("success")); LCS(); } @@ -275,7 +277,7 @@ NSISFunc(AddText) { myImageList *newImg = (myImageList *)GlobalAlloc(GPTR, sizeof(myImageList)); if (!newImg) { - my_pushstring("memory allocation error"); + my_pushstring(_T("memory allocation error")); LCS(); return; } @@ -283,9 +285,9 @@ NSISFunc(AddText) { newImg->iType = MIL_TEXT; popstring(szTemp); - newImg->szText = (char *)GlobalAlloc(GPTR, lstrlen(szTemp)+1); + newImg->szText = (TCHAR *)GlobalAlloc(GPTR, (lstrlen(szTemp)+1)*sizeof(TCHAR)); if (!newImg->szText) { - my_pushstring("memory allocation error"); + my_pushstring(_T("memory allocation error")); GlobalFree(newImg); LCS(); return; @@ -303,7 +305,7 @@ NSISFunc(AddText) { while (img->next) img = img->next; img->next = newImg; - my_pushstring("success"); + my_pushstring(_T("success")); LCS(); } @@ -351,7 +353,7 @@ NSISFunc(Destroy) { hWndImage = 0; oldProc = NULL; Clear(0, 0, 0, 0, 0); - UnregisterClass("NSISBGImage", g_hInstance); + UnregisterClass(_T("NSISBGImage"), g_hInstance); } NSISFunc(Sound) { @@ -576,7 +578,7 @@ HBITMAP __stdcall LoadBitmapFile(long right, long bottom, BITMAP *bBitmap) { HBITMAP hBitmap = (HBITMAP)LoadImage(0, szTemp, IMAGE_BITMAP, right, bottom, LR_LOADFROMFILE); if (!hBitmap || !GetObject(hBitmap, sizeof(BITMAP), (void *)bBitmap)) { - my_pushstring("can't load bitmap"); + my_pushstring(_T("can't load bitmap")); if (hBitmap) DeleteObject(hBitmap); LCS(); diff --git a/Contrib/Dialer/dialer.c b/Contrib/Dialer/dialer.c index c78ac4b5..ed8414d8 100644 --- a/Contrib/Dialer/dialer.c +++ b/Contrib/Dialer/dialer.c @@ -1,10 +1,12 @@ +// Unicode support by Jim Park -- 08/22/2007 + #define WIN32_LEAN_AND_MEAN #include #include #include // nsis plugin -#define NSISFunction(funcname) void __declspec(dllexport) funcname(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +#define NSISFunction(funcname) void __declspec(dllexport) funcname(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { return TRUE; @@ -16,8 +18,9 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { HMODULE hWinInet = NULL; +// GetProcAddress only takes ANSI. FARPROC GetWinInetFunc(char *func) { - hWinInet = LoadLibrary("wininet.dll"); + hWinInet = LoadLibrary(_T("wininet.dll")); if (hWinInet) return GetProcAddress(hWinInet, func); return NULL; @@ -44,9 +47,9 @@ NSISFunction(AutodialOnline) { EXDLL_INIT(); if (pInternetAutodial(INTERNET_AUTODIAL_FORCE_ONLINE, 0)) - pushstring("online"); + pushstring(_T("online")); else - pushstring("offline"); + pushstring(_T("offline")); FreeWinInet(); } @@ -62,9 +65,9 @@ NSISFunction(AutodialUnattended) { EXDLL_INIT(); if (pInternetAutodial(INTERNET_AUTODIAL_FORCE_UNATTENDED , 0)) - pushstring("online"); + pushstring(_T("online")); else - pushstring("offline"); + pushstring(_T("offline")); FreeWinInet(); } @@ -80,9 +83,9 @@ NSISFunction(AttemptConnect) { EXDLL_INIT(); if (pInternetAttemptConnect(0) == ERROR_SUCCESS) - pushstring("online"); + pushstring(_T("online")); else - pushstring("offline"); + pushstring(_T("offline")); FreeWinInet(); } @@ -100,9 +103,9 @@ NSISFunction(GetConnectedState) { EXDLL_INIT(); if (pInternetGetConnectedState(&dwState, 0)) - pushstring("online"); + pushstring(_T("online")); else - pushstring("offline"); + pushstring(_T("offline")); FreeWinInet(); } @@ -118,9 +121,9 @@ NSISFunction(AutodialHangup) { EXDLL_INIT(); if (pInternetAutodialHangup(0)) - pushstring("success"); + pushstring(_T("success")); else - pushstring("failure"); + pushstring(_T("failure")); FreeWinInet(); } diff --git a/Contrib/ExDLL/SConscript b/Contrib/ExDLL/SConscript index 3d2beaf4..55380302 100644 --- a/Contrib/ExDLL/SConscript +++ b/Contrib/ExDLL/SConscript @@ -8,6 +8,7 @@ lib_files = Split(""" api_files = Split(""" pluginapi.h + nsis_tchar.h #Source/exehead/api.h """) @@ -18,7 +19,7 @@ example = Split(""" exdll.dsw exdll_with_unit.dpr exdll-vs2008.sln - exdll-vs2008.vcproj + exdll-vs2008.vcproj nsis.pas extdll.inc """) diff --git a/Contrib/ExDLL/exdll.c b/Contrib/ExDLL/exdll.c index 6e5c1ac7..8d3a51bc 100644 --- a/Contrib/ExDLL/exdll.c +++ b/Contrib/ExDLL/exdll.c @@ -5,8 +5,11 @@ HINSTANCE g_hInstance; HWND g_hwndParent; +// To work with Unicode version of NSIS, please use TCHAR-type +// functions for accessing the variables and the stack. + void __declspec(dllexport) myFunction(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop, + TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { g_hwndParent=hwndParent; @@ -23,8 +26,8 @@ void __declspec(dllexport) myFunction(HWND hwndParent, int string_size, // do your stuff here { - char buf[1024]; - wsprintf(buf,"$0=%s\n",getuservariable(INST_0)); + TCHAR buf[1024]; + wsprintf(buf,_T("$0=%s\n"),getuservariable(INST_0)); MessageBox(g_hwndParent,buf,0,MB_OK); } } diff --git a/Contrib/ExDLL/nsis_tchar.h b/Contrib/ExDLL/nsis_tchar.h new file mode 100644 index 00000000..9532d4e4 --- /dev/null +++ b/Contrib/ExDLL/nsis_tchar.h @@ -0,0 +1,214 @@ +/* + * nsis_tchar.h + * + * This file is a part of NSIS. + * + * Copyright (C) 1999-2007 Nullsoft and Contributors + * + * This software is provided 'as-is', without any express or implied + * warranty. + * + * For Unicode support by Jim Park -- 08/30/2007 + */ + +// Jim Park: Only those we use are listed here. + +#pragma once + +#ifdef _UNICODE + +#ifndef _T +#define __T(x) L ## x +#define _T(x) __T(x) +#define _TEXT(x) __T(x) +#endif +typedef wchar_t TCHAR; +typedef wchar_t _TUCHAR; + +// program +#define _tmain wmain +#define _tWinMain wWinMain +#define _tenviron _wenviron +#define __targv __wargv + +// printfs +#define _ftprintf fwprintf +#define _sntprintf _snwprintf +#define _stprintf _swprintf +#define _tprintf wprintf +#define _vftprintf vfwprintf +#define _vsntprintf _vsnwprintf +#define _vstprintf _vswprintf + +// scanfs +#define _tscanf wscanf +#define _stscanf swscanf + +// string manipulations +#define _tcscat wcscat +#define _tcschr wcschr +#define _tcsclen wcslen +#define _tcscpy wcscpy +#define _tcsdup _wcsdup +#define _tcslen wcslen +#define _tcsnccpy wcsncpy +#define _tcsncpy wcsncpy +#define _tcsrchr wcsrchr +#define _tcsstr wcsstr +#define _tcstok wcstok + +// string comparisons +#define _tcscmp wcscmp +#define _tcsicmp _wcsicmp +#define _tcsncicmp _wcsnicmp +#define _tcsncmp wcsncmp +#define _tcsnicmp _wcsnicmp + +// upper / lower +#define _tcslwr _wcslwr +#define _tcsupr _wcsupr +#define _totlower towlower +#define _totupper towupper + +// conversions to numbers +#define _tcstoi64 _wcstoi64 +#define _tcstol wcstol +#define _tcstoul wcstoul +#define _tstof _wtof +#define _tstoi _wtoi +#define _tstoi64 _wtoi64 +#define _ttoi _wtoi +#define _ttoi64 _wtoi64 +#define _ttol _wtol + +// conversion from numbers to strings +#define _itot _itow +#define _ltot _ltow +#define _i64tot _i64tow +#define _ui64tot _ui64tow + +// file manipulations +#define _tfopen _wfopen +#define _topen _wopen +#define _tremove _wremove +#define _tunlink _wunlink + +// reading and writing to i/o +#define _fgettc fgetwc +#define _fgetts fgetws +#define _fputts fputws +#define _gettchar getwchar + +// directory +#define _tchdir _wchdir + +// environment +#define _tgetenv _wgetenv +#define _tsystem _wsystem + +// time +#define _tcsftime wcsftime + +#else // ANSI + +#ifndef _T +#define _T(x) x +#define _TEXT(x) x +#endif +typedef char TCHAR; +typedef unsigned char _TUCHAR; + +// program +#define _tmain main +#define _tWinMain WinMain +#define _tenviron environ +#define __targv __argv + +// printfs +#define _ftprintf fprintf +#define _sntprintf _snprintf +#define _stprintf sprintf +#define _tprintf printf +#define _vftprintf vfprintf +#define _vsntprintf _vsnprintf +#define _vstprintf vsprintf + +// scanfs +#define _tscanf scanf +#define _stscanf sscanf + +// string manipulations +#define _tcscat strcat +#define _tcschr strchr +#define _tcsclen strlen +#define _tcscnlen strnlen +#define _tcscpy strcpy +#define _tcsdup _strdup +#define _tcslen strlen +#define _tcsnccpy strncpy +#define _tcsrchr strrchr +#define _tcsstr strstr +#define _tcstok strtok + +// string comparisons +#define _tcscmp strcmp +#define _tcsicmp _stricmp +#define _tcsncmp strncmp +#define _tcsncicmp _strnicmp +#define _tcsnicmp _strnicmp + +// upper / lower +#define _tcslwr _strlwr +#define _tcsupr _strupr + +#define _totupper toupper +#define _totlower tolower + +// conversions to numbers +#define _tcstol strtol +#define _tcstoul strtoul +#define _tstof atof +#define _tstoi atoi +#define _tstoi64 _atoi64 +#define _tstoi64 _atoi64 +#define _ttoi atoi +#define _ttoi64 _atoi64 +#define _ttol atol + +// conversion from numbers to strings +#define _i64tot _i64toa +#define _itot _itoa +#define _ltot _ltoa +#define _ui64tot _ui64toa + +// file manipulations +#define _tfopen fopen +#define _topen _open +#define _tremove remove +#define _tunlink _unlink + +// reading and writing to i/o +#define _fgettc fgetc +#define _fgetts fgets +#define _fputts fputs +#define _gettchar getchar + +// directory +#define _tchdir _chdir + +// environment +#define _tgetenv getenv +#define _tsystem system + +// time +#define _tcsftime strftime + +#endif + +// is functions (the same in Unicode / ANSI) +#define _istgraph isgraph +#define _istascii __isascii + +#define __TFILE__ _T(__FILE__) +#define __TDATE__ _T(__DATE__) +#define __TTIME__ _T(__TIME__) diff --git a/Contrib/ExDLL/pluginapi.c b/Contrib/ExDLL/pluginapi.c index 906f16a0..5aeba504 100644 --- a/Contrib/ExDLL/pluginapi.c +++ b/Contrib/ExDLL/pluginapi.c @@ -4,11 +4,11 @@ unsigned int g_stringsize; stack_t **g_stacktop; -char *g_variables; +TCHAR *g_variables; // utility functions (not required but often useful) -int NSISCALL popstring(char *str) +int NSISCALL popstring(TCHAR *str) { stack_t *th; if (!g_stacktop || !*g_stacktop) return 1; @@ -19,7 +19,7 @@ int NSISCALL popstring(char *str) return 0; } -int NSISCALL popstringn(char *str, int maxlen) +int NSISCALL popstringn(TCHAR *str, int maxlen) { stack_t *th; if (!g_stacktop || !*g_stacktop) return 1; @@ -30,7 +30,7 @@ int NSISCALL popstringn(char *str, int maxlen) return 0; } -void NSISCALL pushstring(const char *str) +void NSISCALL pushstring(const TCHAR *str) { stack_t *th; if (!g_stacktop) return; @@ -40,13 +40,13 @@ void NSISCALL pushstring(const char *str) *g_stacktop=th; } -char * NSISCALL getuservariable(const int varnum) +TCHAR * NSISCALL getuservariable(const int varnum) { if (varnum < 0 || varnum >= __INST_LAST) return NULL; return g_variables+varnum*g_stringsize; } -void NSISCALL setuservariable(const int varnum, const char *var) +void NSISCALL setuservariable(const int varnum, const TCHAR *var) { if (var != NULL && varnum >= 0 && varnum < __INST_LAST) lstrcpyA(g_variables + varnum*g_stringsize, var); @@ -54,29 +54,29 @@ void NSISCALL setuservariable(const int varnum, const char *var) // playing with integers -int NSISCALL myatoi(const char *s) +int NSISCALL myatoi(const TCHAR *s) { int v=0; - if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) + if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X'))) { s++; for (;;) { int c=*(++s); - if (c >= '0' && c <= '9') c-='0'; - else if (c >= 'a' && c <= 'f') c-='a'-10; - else if (c >= 'A' && c <= 'F') c-='A'-10; + if (c >= _T('0') && c <= _T('9')) c-=_T('0'); + else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10; + else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10; else break; v<<=4; v+=c; } } - else if (*s == '0' && s[1] <= '7' && s[1] >= '0') + else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0')) { for (;;) { int c=*(++s); - if (c >= '0' && c <= '7') c-='0'; + if (c >= _T('0') && c <= _T('7')) c-=_T('0'); else break; v<<=3; v+=c; @@ -85,10 +85,10 @@ int NSISCALL myatoi(const char *s) else { int sign=0; - if (*s == '-') sign++; else s--; + if (*s == _T('-')) sign++; else s--; for (;;) { - int c=*(++s) - '0'; + int c=*(++s) - _T('0'); if (c < 0 || c > 9) break; v*=10; v+=c; @@ -99,14 +99,14 @@ int NSISCALL myatoi(const char *s) return v; } -unsigned NSISCALL myatou(const char *s) +unsigned NSISCALL myatou(const TCHAR *s) { unsigned int v=0; for (;;) { unsigned int c=*s++; - if (c >= '0' && c <= '9') c-='0'; + if (c >= _T('0') && c <= _T('9')) c-=_T('0'); else break; v*=10; v+=c; @@ -114,29 +114,29 @@ unsigned NSISCALL myatou(const char *s) return v; } -int NSISCALL myatoi_or(const char *s) +int NSISCALL myatoi_or(const TCHAR *s) { int v=0; - if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) + if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X'))) { s++; for (;;) { int c=*(++s); - if (c >= '0' && c <= '9') c-='0'; - else if (c >= 'a' && c <= 'f') c-='a'-10; - else if (c >= 'A' && c <= 'F') c-='A'-10; + if (c >= _T('0') && c <= _T('9')) c-=_T('0'); + else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10; + else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10; else break; v<<=4; v+=c; } } - else if (*s == '0' && s[1] <= '7' && s[1] >= '0') + else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0')) { for (;;) { int c=*(++s); - if (c >= '0' && c <= '7') c-='0'; + if (c >= _T('0') && c <= _T('7')) c-=_T('0'); else break; v<<=3; v+=c; @@ -145,10 +145,10 @@ int NSISCALL myatoi_or(const char *s) else { int sign=0; - if (*s == '-') sign++; else s--; + if (*s == _T('-')) sign++; else s--; for (;;) { - int c=*(++s) - '0'; + int c=*(++s) - _T('0'); if (c < 0 || c > 9) break; v*=10; v+=c; @@ -157,7 +157,7 @@ int NSISCALL myatoi_or(const char *s) } // Support for simple ORed expressions - if (*s == '|') + if (*s == _T('|')) { v |= myatoi_or(s+1); } @@ -167,7 +167,7 @@ int NSISCALL myatoi_or(const char *s) int NSISCALL popint() { - char buf[128]; + TCHAR buf[128]; if (popstringn(buf,sizeof(buf))) return 0; @@ -176,7 +176,7 @@ int NSISCALL popint() int NSISCALL popint_or() { - char buf[128]; + TCHAR buf[128]; if (popstringn(buf,sizeof(buf))) return 0; @@ -185,7 +185,7 @@ int NSISCALL popint_or() void NSISCALL pushint(int value) { - char buffer[1024]; - wsprintf(buffer, "%d", value); + TCHAR buffer[1024]; + wsprintf(buffer, _T("%d"), value); pushstring(buffer); } diff --git a/Contrib/ExDLL/pluginapi.h b/Contrib/ExDLL/pluginapi.h index 63b8b846..522bcab0 100644 --- a/Contrib/ExDLL/pluginapi.h +++ b/Contrib/ExDLL/pluginapi.h @@ -6,6 +6,7 @@ extern "C" { #endif #include "api.h" +#include "nsis_tchar.h" #ifndef NSISCALL # define NSISCALL __stdcall @@ -18,7 +19,7 @@ extern "C" { typedef struct _stack_t { struct _stack_t *next; - char text[1]; // this should be the length of string_size + TCHAR text[1]; // this should be the length of string_size } stack_t; enum @@ -53,19 +54,25 @@ __INST_LAST extern unsigned int g_stringsize; extern stack_t **g_stacktop; -extern char *g_variables; +extern TCHAR *g_variables; -int NSISCALL popstring(char *str); // 0 on success, 1 on empty stack -int NSISCALL popstringn(char *str, int maxlen); // with length limit, pass 0 for g_stringsize +int NSISCALL popstring(TCHAR *str); // 0 on success, 1 on empty stack +int NSISCALL popstringn(TCHAR *str, int maxlen); // with length limit, pass 0 for g_stringsize int NSISCALL popint(); // pops an integer int NSISCALL popint_or(); // with support for or'ing (2|4|8) -int NSISCALL myatoi(const char *s); // converts a string to an integer -unsigned NSISCALL myatou(const char *s); // converts a string to an unsigned integer, decimal only -int NSISCALL myatoi_or(const char *s); // with support for or'ing (2|4|8) -void NSISCALL pushstring(const char *str); +int NSISCALL myatoi(const TCHAR *s); // converts a string to an integer +unsigned NSISCALL myatou(const TCHAR *s); // converts a string to an unsigned integer, decimal only +int NSISCALL myatoi_or(const TCHAR *s); // with support for or'ing (2|4|8) +void NSISCALL pushstring(const TCHAR *str); void NSISCALL pushint(int value); -char * NSISCALL getuservariable(const int varnum); -void NSISCALL setuservariable(const int varnum, const char *var); +TCHAR * NSISCALL getuservariable(const int varnum); +void NSISCALL setuservariable(const int varnum, const TCHAR *var); + +// ANSI defs + +#define PopStringA(x) popstring(x) +#define PushStringA(x) pushstring(x) +#define SetUserVariableA(x,y) setuservariable(x,y) #ifdef __cplusplus } diff --git a/Contrib/InstallOptions/InstallerOptions.cpp b/Contrib/InstallOptions/InstallerOptions.cpp index d8303b06..247fe07e 100644 --- a/Contrib/InstallOptions/InstallerOptions.cpp +++ b/Contrib/InstallOptions/InstallerOptions.cpp @@ -4,6 +4,8 @@ * * See Readme.html for documentation and license * + * Unicode support by Jim Park -- 08/01/2007 + * *********************************************************/ #include @@ -34,9 +36,9 @@ void WINAPI FREE(void *d) { if (d) GlobalFree((HGLOBAL)d); } #define stricmp(x,y) lstrcmpi(x,y) //#define abs(x) ((x) < 0 ? -(x) : (x)) -char *WINAPI STRDUP(const char *c) +TCHAR *WINAPI STRDUP(const TCHAR *c) { - char *t=(char*)MALLOC(lstrlen(c)+1); + TCHAR *t=(TCHAR*)MALLOC((lstrlen(c)+1)*sizeof(TCHAR)); return lstrcpy(t,c); } @@ -111,27 +113,27 @@ char *WINAPI STRDUP(const char *c) #define FLAG_FOCUS 0x10000000 // Controls that can receive focus struct TableEntry { - char *pszName; + TCHAR *pszName; int nValue; }; -int WINAPI LookupToken(TableEntry*, char*); -int WINAPI LookupTokens(TableEntry*, char*); +int WINAPI LookupToken(TableEntry*, TCHAR*); +int WINAPI LookupTokens(TableEntry*, TCHAR*); -void WINAPI ConvertNewLines(char *str); +void WINAPI ConvertNewLines(TCHAR *str); // all allocated buffers must be first in the struct // when adding more allocated buffers to FieldType, don't forget to change this define #define FIELD_BUFFERS 6 struct FieldType { - char *pszText; - char *pszState; - char *pszRoot; + TCHAR *pszText; + TCHAR *pszState; + TCHAR *pszRoot; - char *pszListItems; - char *pszFilter; + TCHAR *pszListItems; + TCHAR *pszFilter; - char *pszValidateText; + TCHAR *pszValidateText; int nMinLength; int nMaxLength; @@ -147,7 +149,7 @@ struct FieldType { HANDLE hImage; // this is used by image/icon field to save the handle to the image int nField; // field number in INI file - char *pszHwndEntry; // "HWND" or "HWND2" + TCHAR *pszHwndEntry; // "HWND" or "HWND2" long wndProc; }; @@ -156,7 +158,7 @@ struct FieldType { // use a value larger than MAX_PATH to prevent need for excessive growing. #define BUFFER_SIZE 8192 // 8kb of mem is max char count in multiedit -char szBrowseButtonCaption[] = "..."; +TCHAR szBrowseButtonCaption[] = _T("..."); HWND hConfigWindow = NULL; HWND hMainWindow = NULL; @@ -168,11 +170,11 @@ HINSTANCE m_hInstance = NULL; struct _stack_t *pFilenameStackEntry = NULL; -char *pszFilename = NULL; -char *pszTitle = NULL; -char *pszCancelButtonText = NULL; -char *pszNextButtonText = NULL; -char *pszBackButtonText = NULL; +TCHAR *pszFilename = NULL; +TCHAR *pszTitle = NULL; +TCHAR *pszCancelButtonText = NULL; +TCHAR *pszNextButtonText = NULL; +TCHAR *pszBackButtonText = NULL; int bBackEnabled = FALSE; int bCancelEnabled = FALSE; // by ORTIM: 13-August-2002 @@ -237,8 +239,8 @@ bool INLINE ValidateFields() { if (((pField->nMaxLength > 0) && (nLength > pField->nMaxLength)) || ((pField->nMinLength > 0) && (nLength < pField->nMinLength))) { if (pField->pszValidateText) { - char szTitle[1024]; - GetWindowText(hMainWindow, szTitle, sizeof(szTitle)); + TCHAR szTitle[1024]; + GetWindowText(hMainWindow, szTitle, _countof(szTitle)); MessageBox(hConfigWindow, pField->pszValidateText, szTitle, MB_OK|MB_ICONWARNING); } mySetFocus(pField->hwnd); @@ -251,9 +253,9 @@ bool INLINE ValidateFields() { } bool WINAPI SaveSettings(void) { - static char szField[25]; + static TCHAR szField[25]; int nBufLen = BUFFER_SIZE; - char *pszBuffer = (char*)MALLOC(nBufLen); + TCHAR *pszBuffer = (TCHAR*)MALLOC(nBufLen*sizeof(TCHAR)); if (!pszBuffer) return false; int nIdx; @@ -271,7 +273,7 @@ bool WINAPI SaveSettings(void) { case FIELD_CHECKBOX: case FIELD_RADIOBUTTON: - wsprintf(pszBuffer, "%d", !!mySendMessage(hwnd, BM_GETCHECK, 0, 0)); + wsprintf(pszBuffer, _T("%d"), !!mySendMessage(hwnd, BM_GETCHECK, 0, 0)); break; case FIELD_LISTBOX: @@ -285,17 +287,17 @@ bool WINAPI SaveSettings(void) { if (nLength > nBufLen) { FREE(pszBuffer); nBufLen = nLength; - pszBuffer = (char*)MALLOC(nBufLen); + pszBuffer = (TCHAR*)MALLOC(nBufLen*sizeof(TCHAR)); if (!pszBuffer) return false; } - char *pszItem = (char*)MALLOC(nBufLen); + TCHAR *pszItem = (TCHAR*)MALLOC(nBufLen*sizeof(TCHAR)); if (!pszItem) return false; - *pszBuffer = '\0'; + *pszBuffer = _T('\0'); int nNumItems = mySendMessage(hwnd, LB_GETCOUNT, 0, 0); for (int nIdx2 = 0; nIdx2 < nNumItems; nIdx2++) { if (mySendMessage(hwnd, LB_GETSEL, nIdx2, 0) > 0) { - if (*pszBuffer) lstrcat(pszBuffer, "|"); + if (*pszBuffer) lstrcat(pszBuffer, _T("|")); mySendMessage(hwnd, LB_GETTEXT, (WPARAM)nIdx2, (LPARAM)pszItem); lstrcat(pszBuffer, pszItem); } @@ -315,35 +317,38 @@ bool WINAPI SaveSettings(void) { FREE(pszBuffer); // add a bit extra so we do this less often nBufLen = nLength + 20; - pszBuffer = (char*)MALLOC(nBufLen); + pszBuffer = (TCHAR*)MALLOC(nBufLen*sizeof(TCHAR)); if (!pszBuffer) return false; } - *pszBuffer='"'; + *pszBuffer=_T('"'); GetWindowText(hwnd, pszBuffer+1, nBufLen-1); - pszBuffer[nLength+1]='"'; - pszBuffer[nLength+2]='\0'; + pszBuffer[nLength+1]=_T('"'); + pszBuffer[nLength+2]=_T('\0'); if (pField->nType == FIELD_TEXT && (pField->nFlags & FLAG_MULTILINE)) { - char *pszBuf2 = (char*)MALLOC(nBufLen*2); // double the size, consider the worst case, all chars are \r\n - char *p1, *p2; + TCHAR *pszBuf2 = (TCHAR*)MALLOC(nBufLen*2*sizeof(TCHAR)); // double the size, consider the worst case, all chars are \r\n + TCHAR *p1, *p2; for (p1 = pszBuffer, p2 = pszBuf2; *p1; p1 = CharNext(p1), p2 = CharNext(p2)) { switch (*p1) { - case '\t': + case _T('\t'): *(LPWORD)p2 = CHAR2_TO_WORD('\\', 't'); p2++; break; - case '\n': + case _T('\n'): *(LPWORD)p2 = CHAR2_TO_WORD('\\', 'n'); p2++; break; - case '\r': + case _T('\r'): *(LPWORD)p2 = CHAR2_TO_WORD('\\', 'r'); p2++; break; - case '\\': + case _T('\\'): *p2++ = '\\'; + // Jim Park: used to be p2++ but that's a bug that works because + // CharNext()'s behavior at terminating null char. But still + // definitely, unsafe. default: lstrcpyn(p2, p1, CharNext(p1) - p1 + 1); break; @@ -357,13 +362,13 @@ bool WINAPI SaveSettings(void) { break; } } - wsprintf(szField, "Field %d", CurrField); - WritePrivateProfileString(szField, "State", pszBuffer, pszFilename); + wsprintf(szField, _T("Field %d"), CurrField); + WritePrivateProfileString(szField, _T("State"), pszBuffer, pszFilename); } // Tell NSIS which control was activated, if any - wsprintf(pszBuffer, "%d", g_NotifyField); - WritePrivateProfileString("Settings", "State", pszBuffer, pszFilename); + wsprintf(pszBuffer, _T("%d"), g_NotifyField); + WritePrivateProfileString(_T("Settings"), _T("State"), pszBuffer, pszFilename); FREE(pszBuffer); @@ -372,20 +377,20 @@ bool WINAPI SaveSettings(void) { #define BROWSE_WIDTH 15 -static char szResult[BUFFER_SIZE]; -char *pszAppName; +static TCHAR szResult[BUFFER_SIZE]; +TCHAR *pszAppName; DWORD WINAPI myGetProfileString(LPCTSTR lpKeyName) { - *szResult = '\0'; - return GetPrivateProfileString(pszAppName, lpKeyName, "", szResult, BUFFER_SIZE, pszFilename); + *szResult = _T('\0'); + return GetPrivateProfileString(pszAppName, lpKeyName, _T(""), szResult, BUFFER_SIZE, pszFilename); } -char * WINAPI myGetProfileStringDup(LPCTSTR lpKeyName) +TCHAR * WINAPI myGetProfileStringDup(LPCTSTR lpKeyName) { int nSize = myGetProfileString(lpKeyName); if (nSize) - return strdup(szResult); + return strdup(szResult); // uses STRDUP else return NULL; } @@ -396,25 +401,25 @@ UINT WINAPI myGetProfileInt(LPCTSTR lpKeyName, INT nDefault) } int WINAPI ReadSettings(void) { - static char szField[25]; + static TCHAR szField[25]; int nIdx, nCtrlIdx; - pszAppName = "Settings"; - pszTitle = myGetProfileStringDup("Title"); - pszCancelButtonText = myGetProfileStringDup("CancelButtonText"); - pszNextButtonText = myGetProfileStringDup("NextButtonText"); - pszBackButtonText = myGetProfileStringDup("BackButtonText"); + pszAppName = _T("Settings"); + pszTitle = myGetProfileStringDup(_T("Title")); + pszCancelButtonText = myGetProfileStringDup(_T("CancelButtonText")); + pszNextButtonText = myGetProfileStringDup(_T("NextButtonText")); + pszBackButtonText = myGetProfileStringDup(_T("BackButtonText")); - nNumFields = myGetProfileInt("NumFields", 0); + nNumFields = myGetProfileInt(_T("NumFields"), 0); - nRectId = myGetProfileInt("Rect", DEFAULT_RECT); + nRectId = myGetProfileInt(_T("Rect"), DEFAULT_RECT); - bBackEnabled = myGetProfileInt("BackEnabled", -1); + bBackEnabled = myGetProfileInt(_T("BackEnabled"), -1); // by ORTIM: 13-August-2002 - bCancelEnabled = myGetProfileInt("CancelEnabled", -1); - bCancelShow = myGetProfileInt("CancelShow", -1); + bCancelEnabled = myGetProfileInt(_T("CancelEnabled"), -1); + bCancelShow = myGetProfileInt(_T("CancelShow"), -1); - bRTL = myGetProfileInt("RTL", 0); + bRTL = myGetProfileInt(_T("RTL"), 0); if (nNumFields > 0) { // make this twice as large for the worst case that every control is a browse button. @@ -426,117 +431,117 @@ int WINAPI ReadSettings(void) { for (nIdx = 0, nCtrlIdx = 0; nCtrlIdx < nNumFields; nCtrlIdx++, nIdx++) { // Control types static TableEntry TypeTable[] = { - { "LABEL", FIELD_LABEL }, - { "TEXT", FIELD_TEXT }, - { "PASSWORD", FIELD_TEXT }, - { "LISTBOX", FIELD_LISTBOX }, - { "COMBOBOX", FIELD_COMBOBOX }, - { "DROPLIST", FIELD_COMBOBOX }, - { "FILEREQUEST", FIELD_FILEREQUEST }, - { "DIRREQUEST", FIELD_DIRREQUEST }, - { "CHECKBOX", FIELD_CHECKBOX }, - { "RADIOBUTTON", FIELD_RADIOBUTTON }, - { "ICON", FIELD_ICON }, - { "BITMAP", FIELD_BITMAP }, - { "GROUPBOX", FIELD_GROUPBOX }, + { _T("LABEL"), FIELD_LABEL }, + { _T("TEXT"), FIELD_TEXT }, + { _T("PASSWORD"), FIELD_TEXT }, + { _T("LISTBOX"), FIELD_LISTBOX }, + { _T("COMBOBOX"), FIELD_COMBOBOX }, + { _T("DROPLIST"), FIELD_COMBOBOX }, + { _T("FILEREQUEST"), FIELD_FILEREQUEST }, + { _T("DIRREQUEST"), FIELD_DIRREQUEST }, + { _T("CHECKBOX"), FIELD_CHECKBOX }, + { _T("RADIOBUTTON"), FIELD_RADIOBUTTON }, + { _T("ICON"), FIELD_ICON }, + { _T("BITMAP"), FIELD_BITMAP }, + { _T("GROUPBOX"), FIELD_GROUPBOX }, #ifdef IO_ENABLE_LINK - { "LINK", FIELD_LINK }, + { _T("LINK"), FIELD_LINK }, #else - { "LINK", FIELD_LABEL }, + { _T("LINK"), FIELD_LABEL }, #endif - { "BUTTON", FIELD_BUTTON }, - { "HLINE", FIELD_HLINE }, - { "VLINE", FIELD_VLINE }, - { NULL, 0 } + { _T("BUTTON"), FIELD_BUTTON }, + { _T("HLINE"), FIELD_HLINE }, + { _T("VLINE"), FIELD_VLINE }, + { NULL, 0 } }; // Control flags static TableEntry FlagTable[] = { - { "NOTIFY", LBS_NOTIFY }, - { "WARN_IF_EXIST", OFN_OVERWRITEPROMPT }, - { "FILE_HIDEREADONLY", OFN_HIDEREADONLY }, - { "MULTISELECT", LBS_MULTIPLESEL }, - { "READONLY", FLAG_READONLY }, - { "RIGHT", BS_LEFTTEXT }, - { "PASSWORD", FLAG_PASSWORD }, - { "ONLY_NUMBERS", FLAG_ONLYNUMBERS }, - { "MULTILINE", FLAG_MULTILINE }, - { "NOWORDWRAP", FLAG_NOWORDWRAP }, - { "WANTRETURN", FLAG_WANTRETURN }, - { "EXTENDEDSELCT", LBS_EXTENDEDSEL }, - { "PATH_MUST_EXIST", OFN_PATHMUSTEXIST }, - { "FILE_MUST_EXIST", OFN_FILEMUSTEXIST }, - { "PROMPT_CREATE", OFN_CREATEPROMPT }, - { "DROPLIST", FLAG_DROPLIST }, - { "RESIZETOFIT", FLAG_RESIZETOFIT }, - { "NOTABSTOP", WS_TABSTOP }, - { "GROUP", WS_GROUP }, - { "REQ_SAVE", FLAG_SAVEAS }, - { "FILE_EXPLORER", OFN_EXPLORER }, - { "HSCROLL", WS_HSCROLL }, - { "VSCROLL", WS_VSCROLL }, - { "DISABLED", WS_DISABLED }, - { "TRANSPARENT", TRANSPARENT_BMP }, - { "FOCUS", FLAG_FOCUS }, - { NULL, 0 } + { _T("NOTIFY"), LBS_NOTIFY }, + { _T("WARN_IF_EXIST"), OFN_OVERWRITEPROMPT }, + { _T("FILE_HIDEREADONLY"), OFN_HIDEREADONLY }, + { _T("MULTISELECT"), LBS_MULTIPLESEL }, + { _T("READONLY"), FLAG_READONLY }, + { _T("RIGHT"), BS_LEFTTEXT }, + { _T("PASSWORD"), FLAG_PASSWORD }, + { _T("ONLY_NUMBERS"), FLAG_ONLYNUMBERS }, + { _T("MULTILINE"), FLAG_MULTILINE }, + { _T("NOWORDWRAP"), FLAG_NOWORDWRAP }, + { _T("WANTRETURN"), FLAG_WANTRETURN }, + { _T("EXTENDEDSELCT"), LBS_EXTENDEDSEL }, + { _T("PATH_MUST_EXIST"), OFN_PATHMUSTEXIST }, + { _T("FILE_MUST_EXIST"), OFN_FILEMUSTEXIST }, + { _T("PROMPT_CREATE"), OFN_CREATEPROMPT }, + { _T("DROPLIST"), FLAG_DROPLIST }, + { _T("RESIZETOFIT"), FLAG_RESIZETOFIT }, + { _T("NOTABSTOP"), WS_TABSTOP }, + { _T("GROUP"), WS_GROUP }, + { _T("REQ_SAVE"), FLAG_SAVEAS }, + { _T("FILE_EXPLORER"), OFN_EXPLORER }, + { _T("HSCROLL"), WS_HSCROLL }, + { _T("VSCROLL"), WS_VSCROLL }, + { _T("DISABLED"), WS_DISABLED }, + { _T("TRANSPARENT"), TRANSPARENT_BMP }, + { _T("FOCUS"), FLAG_FOCUS }, + { NULL, 0 } }; FieldType *pField = pFields + nIdx; pField->nField = nCtrlIdx + 1; - pField->pszHwndEntry = "HWND"; + pField->pszHwndEntry = _T("HWND"); - wsprintf(szField, "Field %d", nCtrlIdx + 1); + wsprintf(szField, _T("Field %d"), nCtrlIdx + 1); pszAppName = szField; // Get the control type - myGetProfileString("TYPE"); + myGetProfileString(_T("TYPE")); pField->nType = LookupToken(TypeTable, szResult); if (pField->nType == FIELD_INVALID) continue; // Lookup flags associated with the control type pField->nFlags = LookupToken(FlagTable, szResult); - myGetProfileString("Flags"); + myGetProfileString(_T("Flags")); pField->nFlags |= LookupTokens(FlagTable, szResult); // pszState must not be NULL! - myGetProfileString("State"); - pField->pszState = strdup(szResult); + myGetProfileString(_T("State")); + pField->pszState = strdup(szResult); // uses STRDUP // ListBox items list { - int nResult = myGetProfileString("ListItems"); + int nResult = myGetProfileString(_T("ListItems")); if (nResult) { // add an extra | character to the end to simplify the loop where we add the items. - pField->pszListItems = (char*)MALLOC(nResult + 2); - strcpy(pField->pszListItems, szResult); - pField->pszListItems[nResult] = '|'; - pField->pszListItems[nResult + 1] = '\0'; + pField->pszListItems = (TCHAR*)MALLOC((nResult + 2)*sizeof(TCHAR)); + lstrcpy(pField->pszListItems, szResult); + pField->pszListItems[nResult] = _T('|'); + pField->pszListItems[nResult + 1] = _T('\0'); } } // Label Text - convert newline - pField->pszText = myGetProfileStringDup("TEXT"); + pField->pszText = myGetProfileStringDup(_T("TEXT")); if (pField->nType == FIELD_LABEL || pField->nType == FIELD_LINK) ConvertNewLines(pField->pszText); // Dir request - root folder - pField->pszRoot = myGetProfileStringDup("ROOT"); + pField->pszRoot = myGetProfileStringDup(_T("ROOT")); // ValidateText - convert newline - pField->pszValidateText = myGetProfileStringDup("ValidateText"); + pField->pszValidateText = myGetProfileStringDup(_T("ValidateText")); ConvertNewLines(pField->pszValidateText); { - int nResult = GetPrivateProfileString(szField, "Filter", "All Files|*.*", szResult, sizeof(szResult), pszFilename); + int nResult = GetPrivateProfileString(szField, _T("Filter"), _T("All Files|*.*"), szResult, _countof(szResult), pszFilename); if (nResult) { // Convert the filter to the format required by Windows: NULL after each // item followed by a terminating NULL - pField->pszFilter = (char*)MALLOC(nResult + 2); - strcpy(pField->pszFilter, szResult); - char *pszPos = pField->pszFilter; + pField->pszFilter = (TCHAR*)MALLOC((nResult + 2)*sizeof(TCHAR)); + lstrcpy(pField->pszFilter, szResult); + TCHAR *pszPos = pField->pszFilter; while (*pszPos) { - if (*pszPos == '|') + if (*pszPos == _T('|')) *pszPos++ = 0; else pszPos = CharNext(pszPos); @@ -544,15 +549,15 @@ int WINAPI ReadSettings(void) { } } - pField->rect.left = myGetProfileInt("LEFT", 0); - pField->rect.top = myGetProfileInt("TOP", 0); - pField->rect.right = myGetProfileInt("RIGHT", 0); - pField->rect.bottom = myGetProfileInt("BOTTOM", 0); - pField->nMinLength = myGetProfileInt("MinLen", 0); - pField->nMaxLength = myGetProfileInt("MaxLen", 0); + pField->rect.left = myGetProfileInt(_T("LEFT"), 0); + pField->rect.top = myGetProfileInt(_T("TOP"), 0); + pField->rect.right = myGetProfileInt(_T("RIGHT"), 0); + pField->rect.bottom = myGetProfileInt(_T("BOTTOM"), 0); + pField->nMinLength = myGetProfileInt(_T("MinLen"), 0); + pField->nMaxLength = myGetProfileInt(_T("MaxLen"), 0); // Text color for LINK control, default is pure blue - pField->hImage = (HANDLE)myGetProfileInt("TxtColor", RGB(0,0,255)); + pField->hImage = (HANDLE)myGetProfileInt(_T("TxtColor"), RGB(0,0,255)); pField->nControlID = 1200 + nIdx; if (pField->nType == FIELD_FILEREQUEST || pField->nType == FIELD_DIRREQUEST) @@ -568,7 +573,7 @@ int WINAPI ReadSettings(void) { pNewField->rect.top = pField->rect.top; pField->rect.right = pNewField->rect.left - 3; pNewField->nField = nCtrlIdx + 1; - pNewField->pszHwndEntry = "HWND2"; + pNewField->pszHwndEntry = _T("HWND2"); nNumFields++; nIdx++; } @@ -605,7 +610,7 @@ LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify) FieldType *pField = pFields + nIdx; - char szBrowsePath[MAX_PATH]; + TCHAR szBrowsePath[MAX_PATH]; switch (pField->nType) { case FIELD_FILEREQUEST: { @@ -615,10 +620,10 @@ LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify) ofn.hwndOwner = hConfigWindow; ofn.lpstrFilter = pField->pszFilter; ofn.lpstrFile = szBrowsePath; - ofn.nMaxFile = sizeof(szBrowsePath); + ofn.nMaxFile = _countof(szBrowsePath); ofn.Flags = pField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER); - GetWindowText(pField->hwnd, szBrowsePath, sizeof(szBrowsePath)); + GetWindowText(pField->hwnd, szBrowsePath, _countof(szBrowsePath)); tryagain: GetCurrentDirectory(BUFFER_SIZE, szResult); // save working dir @@ -629,7 +634,7 @@ LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify) break; } else if (szBrowsePath[0] && CommDlgExtendedError() == FNERR_INVALIDFILENAME) { - szBrowsePath[0] = '\0'; + szBrowsePath[0] = _T('\0'); goto tryagain; } @@ -880,17 +885,17 @@ int WINAPI NumbersOnlyPasteWndProc(HWND hWin, UINT uMsg, WPARAM wParam, LPARAM l if (hData) { - char *lpData = (char *) GlobalLock(hData); + TCHAR *lpData = (TCHAR *) GlobalLock(hData); if (lpData) { int iLen = lstrlen(lpData); - char *lpFilteredData = (char *) MALLOC(iLen + 1); + TCHAR *lpFilteredData = (TCHAR *) MALLOC((iLen + 1)*sizeof(TCHAR)); if (lpFilteredData) { for (int i = 0, j = 0; i < iLen; i++) { - if (lpData[i] >= '0' && lpData[i] <= '9') + if (lpData[i] >= _T('0') && lpData[i] <= _T('9')) { lpFilteredData[j] = lpData[i]; j++; @@ -926,14 +931,14 @@ int WINAPI createCfgDlg() if (!mainwnd) { popstring(NULL); - pushstring("error finding mainwnd"); + pushstring(_T("error finding mainwnd")); return 1; // cannot be used in silent mode unfortunately. } if (!g_stacktop || !*g_stacktop || !(pszFilename = (*g_stacktop)->text) || !pszFilename[0] || !ReadSettings()) { popstring(NULL); - pushstring("error finding config"); + pushstring(_T("error finding config")); return 1; } @@ -941,7 +946,7 @@ int WINAPI createCfgDlg() if (!childwnd) { popstring(NULL); - pushstring("error finding childwnd"); + pushstring(_T("error finding childwnd")); return 1; } @@ -993,7 +998,7 @@ int WINAPI createCfgDlg() else { popstring(NULL); - pushstring("error creating dialog"); + pushstring(_T("error creating dialog")); return 1; } @@ -1005,88 +1010,88 @@ int WINAPI createCfgDlg() for (int nIdx = 0; nIdx < nNumFields; nIdx++) { static struct { - char* pszClass; + TCHAR* pszClass; DWORD dwStyle; DWORD dwRTLStyle; DWORD dwExStyle; DWORD dwRTLExStyle; } ClassTable[] = { - { "STATIC", // FIELD_HLINE + { _T("STATIC"), // FIELD_HLINE DEFAULT_STYLES | SS_ETCHEDHORZ | SS_SUNKEN, DEFAULT_STYLES | SS_ETCHEDHORZ | SS_SUNKEN, WS_EX_TRANSPARENT, WS_EX_TRANSPARENT | RTL_EX_STYLES }, - { "STATIC", // FIELD_VLINE + { _T("STATIC"), // FIELD_VLINE DEFAULT_STYLES | SS_ETCHEDVERT | SS_SUNKEN, DEFAULT_STYLES | SS_ETCHEDVERT | SS_SUNKEN, WS_EX_TRANSPARENT, WS_EX_TRANSPARENT | RTL_EX_STYLES }, - { "STATIC", // FIELD_LABEL + { _T("STATIC"), // FIELD_LABEL DEFAULT_STYLES, DEFAULT_STYLES | SS_RIGHT, WS_EX_TRANSPARENT, WS_EX_TRANSPARENT | RTL_EX_STYLES }, - { "STATIC", // FIELD_ICON + { _T("STATIC"), // FIELD_ICON DEFAULT_STYLES | SS_ICON, DEFAULT_STYLES | SS_ICON, 0, RTL_EX_STYLES }, - { "STATIC", // FIELD_BITMAP + { _T("STATIC"), // FIELD_BITMAP DEFAULT_STYLES | SS_BITMAP, DEFAULT_STYLES | SS_BITMAP, 0, RTL_EX_STYLES }, - { "BUTTON", // FIELD_BROWSEBUTTON + { _T("BUTTON"), // FIELD_BROWSEBUTTON DEFAULT_STYLES | WS_TABSTOP, DEFAULT_STYLES | WS_TABSTOP, 0, RTL_EX_STYLES }, - { "BUTTON", // FIELD_LINK + { _T("BUTTON"), // FIELD_LINK DEFAULT_STYLES | WS_TABSTOP | BS_OWNERDRAW, DEFAULT_STYLES | WS_TABSTOP | BS_OWNERDRAW | BS_RIGHT, 0, RTL_EX_STYLES }, - { "BUTTON", // FIELD_BUTTON + { _T("BUTTON"), // FIELD_BUTTON DEFAULT_STYLES | WS_TABSTOP, DEFAULT_STYLES | WS_TABSTOP, 0, RTL_EX_STYLES }, - { "BUTTON", // FIELD_GROUPBOX + { _T("BUTTON"), // FIELD_GROUPBOX DEFAULT_STYLES | BS_GROUPBOX, DEFAULT_STYLES | BS_GROUPBOX | BS_RIGHT, WS_EX_TRANSPARENT, WS_EX_TRANSPARENT | RTL_EX_STYLES }, - { "BUTTON", // FIELD_CHECKBOX + { _T("BUTTON"), // FIELD_CHECKBOX DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTOCHECKBOX | BS_MULTILINE, DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTOCHECKBOX | BS_MULTILINE | BS_RIGHT | BS_LEFTTEXT, 0, RTL_EX_STYLES }, - { "BUTTON", // FIELD_RADIOBUTTON + { _T("BUTTON"), // FIELD_RADIOBUTTON DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTORADIOBUTTON | BS_MULTILINE, DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTORADIOBUTTON | BS_MULTILINE | BS_RIGHT | BS_LEFTTEXT, 0, RTL_EX_STYLES }, - { "EDIT", // FIELD_TEXT + { _T("EDIT"), // FIELD_TEXT DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL, DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL | ES_RIGHT, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | RTL_EX_STYLES }, - { "EDIT", // FIELD_FILEREQUEST + { _T("EDIT"), // FIELD_FILEREQUEST DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL, DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL | ES_RIGHT, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | RTL_EX_STYLES }, - { "EDIT", // FIELD_DIRREQUEST + { _T("EDIT"), // FIELD_DIRREQUEST DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL, DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL | ES_RIGHT, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | RTL_EX_STYLES }, - { "COMBOBOX", // FIELD_COMBOBOX + { _T("COMBOBOX"), // FIELD_COMBOBOX DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | WS_CLIPCHILDREN | CBS_AUTOHSCROLL | CBS_HASSTRINGS, DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | WS_CLIPCHILDREN | CBS_AUTOHSCROLL | CBS_HASSTRINGS, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_RIGHT | RTL_EX_STYLES }, - { "LISTBOX", // FIELD_LISTBOX + { _T("LISTBOX"), // FIELD_LISTBOX DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT, DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, @@ -1133,7 +1138,7 @@ int WINAPI createCfgDlg() rect.left = mainWndWidth - right; } - char *title = pField->pszText; + TCHAR *title = pField->pszText; switch (pField->nType) { case FIELD_ICON: case FIELD_BITMAP: @@ -1198,10 +1203,10 @@ int WINAPI createCfgDlg() ); { - char szField[64]; - char szHwnd[64]; - wsprintf(szField, "Field %d", pField->nField); - wsprintf(szHwnd, "%d", hwCtrl); + TCHAR szField[64]; + TCHAR szHwnd[64]; + wsprintf(szField, _T("Field %d"), pField->nField); + wsprintf(szHwnd, _T("%d"), hwCtrl); WritePrivateProfileString(szField, pField->pszHwndEntry, szHwnd, pszFilename); } @@ -1223,7 +1228,7 @@ int WINAPI createCfgDlg() case FIELD_CHECKBOX: case FIELD_RADIOBUTTON: - if (pField->pszState[0] == '1') + if (pField->pszState[0] == _T('1')) mySendMessage(hwCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0); break; @@ -1242,12 +1247,12 @@ int WINAPI createCfgDlg() nFindMsg = LB_FINDSTRINGEXACT; nSetSelMsg = LB_SETCURSEL; } - char *pszStart, *pszEnd, *pszList; + TCHAR *pszStart, *pszEnd, *pszList; pszStart = pszEnd = pszList = STRDUP(pField->pszListItems); // pszListItems has a trailing pipe while (*pszEnd) { - if (*pszEnd == '|') { - *pszEnd = '\0'; + if (*pszEnd == _T('|')) { + *pszEnd = _T('\0'); if (*pszStart) mySendMessage(hwCtrl, nAddMsg, 0, (LPARAM) pszStart); pszStart = ++pszEnd; @@ -1261,9 +1266,9 @@ int WINAPI createCfgDlg() mySendMessage(hwCtrl, LB_SETSEL, FALSE, (LPARAM)-1); pszStart = pszEnd = pField->pszState; for (;;) { - char c = *pszEnd; - if (c == '|' || c == '\0') { - *pszEnd = '\0'; + TCHAR c = *pszEnd; + if (c == _T('|') || c == _T('\0')) { + *pszEnd = _T('\0'); if (*pszStart) { int nItem = mySendMessage(hwCtrl, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)pszStart); @@ -1429,8 +1434,8 @@ int WINAPI createCfgDlg() mySetWindowText(mainwnd,pszTitle); pFilenameStackEntry = *g_stacktop; *g_stacktop = (*g_stacktop)->next; - static char tmp[32]; - wsprintf(tmp,"%d",hConfigWindow); + static TCHAR tmp[32]; + wsprintf(tmp,_T("%d"),hConfigWindow); pushstring(tmp); return 0; } @@ -1477,7 +1482,7 @@ void WINAPI showCfgDlg() int j = FIELD_BUFFERS; while (j--) - FREE(((char **) pField)[j]); + FREE(((TCHAR **) pField)[j]); if (pField->nType == FIELD_BITMAP) { DeleteObject(pField->hImage); @@ -1488,18 +1493,18 @@ void WINAPI showCfgDlg() } FREE(pFields); - pushstring(g_is_cancel?"cancel":g_is_back?"back":"success"); + pushstring(g_is_cancel?_T("cancel"):g_is_back?_T("back"):_T("success")); } int initCalled; extern "C" void __declspec(dllexport) dialog(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop) + TCHAR *variables, stack_t **stacktop) { hMainWindow=hwndParent; EXDLL_INIT(); if (initCalled) { - pushstring("error"); + pushstring(_T("error")); return; } if (createCfgDlg()) @@ -1514,14 +1519,16 @@ static UINT_PTR PluginCallback(enum NSPIM msg) } extern "C" void __declspec(dllexport) initDialog(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop, + TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { hMainWindow=hwndParent; EXDLL_INIT(); + extra->RegisterPluginCallback(m_hInstance, PluginCallback); + if (initCalled) { - pushstring("error"); + pushstring(_T("error")); return; } if (createCfgDlg()) @@ -1530,11 +1537,11 @@ extern "C" void __declspec(dllexport) initDialog(HWND hwndParent, int string_siz } extern "C" void __declspec(dllexport) show(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop) + TCHAR *variables, stack_t **stacktop) { EXDLL_INIT(); if (!initCalled) { - pushstring("error"); + pushstring(_T("error")); return; } initCalled--; @@ -1548,23 +1555,41 @@ extern "C" BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lp } -int WINAPI LookupToken(TableEntry* psTable_, char* pszToken_) +/** + * Looks up a single token in the psTable_ and returns its mapped numerical value. + * + * @param psTable_ The lookup table. + * @param pszToken_ The token to lookup. + * @return The integer value related to the token, otherwise 0. + */ +int WINAPI LookupToken(TableEntry* psTable_, TCHAR* pszToken_) { for (int i = 0; psTable_[i].pszName; i++) - if (!stricmp(pszToken_, psTable_[i].pszName)) + if (!lstrcmpi(pszToken_, psTable_[i].pszName)) return psTable_[i].nValue; return 0; } -int WINAPI LookupTokens(TableEntry* psTable_, char* pszTokens_) +/** + * In a string of tokens separated by vertical bars '|', look them up in the + * Lookup Table psTable and return their logical OR of their subsequent + * integer values. + * + * @param psTable_ The lookup table to search in. + * @param pszToken String of tokens separated by '|' whose values are to be + * ORed together. + * @return The ORed value of the token values. If no tokens were found, it + * will return 0. + */ +int WINAPI LookupTokens(TableEntry* psTable_, TCHAR* pszTokens_) { int n = 0; - char *pszStart = pszTokens_; - char *pszEnd = pszTokens_; + TCHAR *pszStart = pszTokens_; + TCHAR *pszEnd = pszTokens_; for (;;) { - char c = *pszEnd; - if (c == '|' || c == '\0') { - *pszEnd = '\0'; + TCHAR c = *pszEnd; + if (c == _T('|') || c == _T('\0')) { + *pszEnd = _T('\0'); n |= LookupToken(psTable_, pszStart); *pszEnd = c; if (!c) @@ -1577,8 +1602,15 @@ int WINAPI LookupTokens(TableEntry* psTable_, char* pszTokens_) return n; } -void WINAPI ConvertNewLines(char *str) { - char *p1, *p2, *p3; +/** + * ConvertNewLines takes a string and turns escape sequences written + * as separate chars e.g. "\\t" into the special char they represent + * '\t'. The transformation is done in place. + * + * @param str [in/out] The string to convert. + */ +void WINAPI ConvertNewLines(TCHAR *str) { + TCHAR *p1, *p2, *p3; if (!str) return; @@ -1589,23 +1621,23 @@ void WINAPI ConvertNewLines(char *str) { { switch (*(LPWORD)p1) { - case CHAR2_TO_WORD('\\', 't'): - *p2 = '\t'; + case CHAR2_TO_WORD(_T('\\'), _T('t')): + *p2 = _T('\t'); p1 += 2; p2++; break; - case CHAR2_TO_WORD('\\', 'n'): - *p2 = '\n'; + case CHAR2_TO_WORD(_T('\\'), _T('n')): + *p2 = _T('\n'); p1 += 2; p2++; break; - case CHAR2_TO_WORD('\\', 'r'): - *p2 = '\r'; + case CHAR2_TO_WORD(_T('\\'), _T('r')): + *p2 = _T('\r'); p1 += 2; p2++; break; - case CHAR2_TO_WORD('\\', '\\'): - *p2 = '\\'; + case CHAR2_TO_WORD(_T('\\'), _T('\\')): + *p2 = _T('\\'); p1 += 2; p2++; break; diff --git a/Contrib/LangDLL/LangDLL.c b/Contrib/LangDLL/LangDLL.c index 537e3ad2..99f0db7d 100644 --- a/Contrib/LangDLL/LangDLL.c +++ b/Contrib/LangDLL/LangDLL.c @@ -1,5 +1,6 @@ #include #include "resource.h" +#include // JF> updated usage // call like this: @@ -8,6 +9,8 @@ // LangDLL:LangDialog "Language Selection" "Choose a language" 2 French 1036 English 1033 // or (the F after the 2 means we're supplying font information) // LangDLL:LangDialog "Language Selection" "Choose a language" 2F French 1036 English 1033 12 Garamond +// +// Unicode support added by Jim Park -- 07/27/2007 #include // nsis plugin @@ -15,8 +18,8 @@ HINSTANCE g_hInstance; HWND g_hwndParent; -char temp[1024]; -char g_wndtitle[1024], g_wndtext[1024]; +TCHAR temp[1024]; +TCHAR g_wndtitle[1024], g_wndtext[1024]; int dofont; int docp; @@ -24,15 +27,15 @@ int langs_num; int visible_langs_num; struct lang { - char *name; - char *id; + TCHAR *name; + TCHAR *id; UINT cp; } *langs; BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { int i, size; - char *selected_language = NULL; + TCHAR *selected_language = NULL; static HFONT font; switch (uMsg) { case WM_INITDIALOG: @@ -62,7 +65,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) size = myatou(temp); if (!popstring(temp)) { LOGFONT f = {0,}; - if (lstrcmp(temp, "MS Shell Dlg")) { + if (lstrcmp(temp, _T("MS Shell Dlg"))) { f.lfHeight = -MulDiv(size, GetDeviceCaps(GetDC(hwndDlg), LOGPIXELSY), 72); lstrcpy(f.lfFaceName, temp); font = CreateFontIndirect(&f); @@ -84,17 +87,17 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) i = SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_GETCURSEL, 0, 0); i = SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_GETITEMDATA, i, 0); if (i != CB_ERR && i) { - pushstring((char *) i); + pushstring((TCHAR *) i); } else { // ?! - pushstring("cancel"); + pushstring(_T("cancel")); } // end dialog EndDialog(hwndDlg, 0); break; case IDCANCEL: // push "cancel" on the stack - pushstring("cancel"); + pushstring(_T("cancel")); // end dialog EndDialog(hwndDlg, 0); break; @@ -111,7 +114,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) } void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop) + TCHAR *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); @@ -130,12 +133,12 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, // parse flags { - char *p=temp; + TCHAR *p=temp; while (*p) { - if (*p == 'A') doauto=1; // parse auto count flag - if (*p == 'F') dofont=1; // parse font flag - if (*p == 'C') docp=1; // parse codepage flag + if (*p == _T('A')) doauto=1; // parse auto count flag + if (*p == _T('F')) dofont=1; // parse font flag + if (*p == _T('C')) docp=1; // parse codepage flag p++; } } @@ -173,12 +176,12 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, // fill language struct for (i = 0; i < langs_num; i++) { if (popstring(temp)) { visible_langs_num = 0; break; } - langs[visible_langs_num].name = GlobalAlloc(GPTR, lstrlen(temp)+1); + langs[visible_langs_num].name = (TCHAR*) GlobalAlloc(GPTR, (lstrlen(temp)+1)*sizeof(TCHAR)); if (!langs[visible_langs_num].name) { visible_langs_num = 0; break; } lstrcpy(langs[visible_langs_num].name, temp); if (popstring(temp)) { visible_langs_num = 0; break; } - langs[visible_langs_num].id = GlobalAlloc(GPTR, lstrlen(temp)+1); + langs[visible_langs_num].id = (TCHAR*) GlobalAlloc(GPTR, (lstrlen(temp)+1)*sizeof(TCHAR)); if (!langs[visible_langs_num].id) { visible_langs_num = 0; break; } lstrcpy(langs[visible_langs_num].id, temp); @@ -188,6 +191,10 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, langs[visible_langs_num].cp = myatou(temp); } + // If Unicode, show everything. +#ifdef _UNICODE + visible_langs_num++; +#else if (!docp || langs[visible_langs_num].cp == GetACP() || langs[visible_langs_num].cp == 0) { visible_langs_num++; @@ -197,6 +204,7 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, GlobalFree(langs[visible_langs_num].name); GlobalFree(langs[visible_langs_num].id); } +#endif } // pop the empty string to keep the stack clean @@ -213,7 +221,7 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, } else if (visible_langs_num == 0) { - pushstring(""); + pushstring(_T("")); } else { diff --git a/Contrib/Library/LibraryLocal/LibraryLocal.cpp b/Contrib/Library/LibraryLocal/LibraryLocal.cpp index 9ec104c3..67b98466 100644 --- a/Contrib/Library/LibraryLocal/LibraryLocal.cpp +++ b/Contrib/Library/LibraryLocal/LibraryLocal.cpp @@ -3,10 +3,12 @@ LibraryLocal - used by the Library.nsh macros Get the version of local DLL and TLB files Written by Joost Verburg + Unicode support by Jim Park -- 07/27/2007 */ #include "../../../Source/Platform.h" +#include "../../../Source/tstring.h" #include #include @@ -21,23 +23,27 @@ int g_noconfig=0; int g_display_errors=1; FILE *g_output=stdout; -int GetTLBVersion(string& filepath, DWORD& high, DWORD & low) +int GetTLBVersion(tstring& filepath, DWORD& high, DWORD & low) { #ifdef _WIN32 int found = 0; - char fullpath[1024]; - char *p; - if (!GetFullPathName(filepath.c_str(), sizeof(fullpath), fullpath, &p)) + TCHAR fullpath[1024]; + TCHAR *p; + if (!GetFullPathName(filepath.c_str(), _countof(fullpath), fullpath, &p)) return 0; - WCHAR *ole_filename = winchar_fromansi(fullpath); - ITypeLib* typeLib; HRESULT hr; - + +#ifdef _UNICODE + hr = LoadTypeLib(fullpath, &typeLib); +#else + // If built without UNICODE, we still need to convert this string to a Unicode string. + WCHAR *ole_filename = winchar_fromansi(fullpath); hr = LoadTypeLib(ole_filename, &typeLib); +#endif if (SUCCEEDED(hr)) { @@ -67,16 +73,16 @@ int GetTLBVersion(string& filepath, DWORD& high, DWORD & low) #endif } -int main(int argc, char* argv[]) +int _tmain(int argc, TCHAR* argv[]) { // Parse the command line - string cmdline; + tstring cmdline; - string mode; - string filename; - string filepath; + tstring mode; + tstring filename; + tstring filepath; int filefound = 0; @@ -90,7 +96,7 @@ int main(int argc, char* argv[]) // Validate filename - ifstream fs(filename.c_str()); + tifstream fs(filename.c_str()); if (fs.is_open()) { @@ -110,7 +116,7 @@ int main(int argc, char* argv[]) // DLL / EXE - if (mode.compare("D") == 0) + if (mode.compare(_T("D")) == 0) { versionfound = GetDLLVersion(filename, high, low); @@ -119,7 +125,7 @@ int main(int argc, char* argv[]) // TLB - if (mode.compare("T") == 0) + if (mode.compare(_T("T")) == 0) { versionfound = GetTLBVersion(filename, high, low); @@ -130,23 +136,23 @@ int main(int argc, char* argv[]) // Write the version to an NSIS header file - ofstream header(argv[3], ofstream::out); + tofstream header(argv[3], tofstream::out); if (header) { if (!filefound) { - header << "!define LIBRARY_VERSION_FILENOTFOUND" << endl; + header << _T("!define LIBRARY_VERSION_FILENOTFOUND") << endl; } else if (!versionfound) { - header << "!define LIBRARY_VERSION_NONE" << endl; + header << _T("!define LIBRARY_VERSION_NONE") << endl; } else { - header << "!define LIBRARY_VERSION_HIGH " << high << endl; - header << "!define LIBRARY_VERSION_LOW " << low << endl; + header << _T("!define LIBRARY_VERSION_HIGH ") << high << endl; + header << _T("!define LIBRARY_VERSION_LOW ") << low << endl; } header.close(); diff --git a/Contrib/Library/RegTool/RegTool.c b/Contrib/Library/RegTool/RegTool.c index b835d716..72cb983e 100644 --- a/Contrib/Library/RegTool/RegTool.c +++ b/Contrib/Library/RegTool/RegTool.c @@ -1,40 +1,41 @@ #include +#include "../../ExDll/nsis_tchar.h" #define STR_SIZE 1024 -void RegFile(char cmd, char *file, int x64); -void RegDll(char *file); -void RegTypeLib(char *file); -void DeleteFileOnReboot(char *pszFile); +void RegFile(TCHAR cmd, TCHAR *file, int x64); +void RegDll(TCHAR *file); +void RegTypeLib(TCHAR *file); +void DeleteFileOnReboot(TCHAR *pszFile); -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { - char *cmdline; - char seekchar = ' '; + TCHAR *cmdline; + TCHAR seekchar = _T(' '); cmdline = GetCommandLine(); - if (*cmdline == '\"') + if (*cmdline == _T('\"')) seekchar = *cmdline++; while (*cmdline && *cmdline != seekchar) cmdline = CharNext(cmdline); cmdline = CharNext(cmdline); - while (*cmdline == ' ') + while (*cmdline == _T(' ')) cmdline++; - if (*cmdline++ != '/') + if (*cmdline++ != _T('/')) { ExitProcess(1); return 0; } - if (*cmdline == 'S') + if (*cmdline == _T('S')) { HKEY rootkey; - if (SUCCEEDED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\NSIS.Library.RegTool.v3", 0, KEY_READ, &rootkey))) + if (SUCCEEDED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\NSIS.Library.RegTool.v3"), 0, KEY_READ, &rootkey))) { - char keyname[STR_SIZE]; + TCHAR keyname[STR_SIZE]; while (RegEnumKey(rootkey, 0, keyname, STR_SIZE) == ERROR_SUCCESS) { @@ -44,24 +45,24 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine { DWORD t, count, l = sizeof(DWORD); - if (SUCCEEDED(RegQueryValueEx(key, "count", NULL, &t, (LPBYTE) &count, &l)) && t == REG_DWORD) + if (SUCCEEDED(RegQueryValueEx(key, _T("count"), NULL, &t, (LPBYTE) &count, &l)) && t == REG_DWORD) { DWORD j; - char valname[128], mode[3], file[STR_SIZE]; + TCHAR valname[128], mode[3], file[STR_SIZE]; for (j = 1; j <= count; j++) { - wsprintf(valname, "%u.mode", j); + wsprintf(valname, _T("%u.mode"), j); l = sizeof(mode); if (FAILED(RegQueryValueEx(key, valname, NULL, &t, (LPBYTE) mode, &l)) || t != REG_SZ) continue; - wsprintf(valname, "%u.file", j); + wsprintf(valname, _T("%u.file"), j); l = STR_SIZE; if (FAILED(RegQueryValueEx(key, valname, NULL, &t, (LPBYTE) file, &l)) || t != REG_SZ) continue; - RegFile(mode[0], file, mode[1] == 'X'); + RegFile(mode[0], file, mode[1] == _T('X')); } } @@ -71,11 +72,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine } RegCloseKey(rootkey); - RegDeleteKey(HKEY_LOCAL_MACHINE, "Software\\NSIS.Library.RegTool.v3"); + RegDeleteKey(HKEY_LOCAL_MACHINE, _T("Software\\NSIS.Library.RegTool.v3")); } { - char file[STR_SIZE]; + TCHAR file[STR_SIZE]; if (GetModuleFileName(GetModuleHandle(NULL), file, STR_SIZE)) { DeleteFileOnReboot(file); @@ -87,11 +88,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); OleInitialize(NULL); - if (*cmdline == 'D') + if (*cmdline == _T('D')) { RegDll(cmdline + 1); } - else if (*cmdline == 'T') + else if (*cmdline == _T('T')) { RegTypeLib(cmdline + 1); } @@ -106,7 +107,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine void SafeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection) { - HMODULE kernel = GetModuleHandle("kernel32"); + HMODULE kernel = GetModuleHandle(_T("kernel32")); if (kernel) { FARPROC proc = GetProcAddress(kernel, "Wow64EnableWow64FsRedirection"); @@ -121,26 +122,26 @@ void SafeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection) } } -void RegFile(char cmd, char *file, int x64) +void RegFile(TCHAR cmd, TCHAR *file, int x64) { - char self[STR_SIZE]; - char cmdline[STR_SIZE]; + TCHAR self[STR_SIZE]; + TCHAR cmdline[STR_SIZE]; int ready = 0; - if (!*file || (cmd != 'D' && cmd != 'T' && cmd != 'E')) + if (!*file || (cmd != _T('D') && cmd != _T('T') && cmd != _T('E'))) return; - if (cmd == 'E') + if (cmd == _T('E')) { - wsprintf(cmdline, "\"%s\" /regserver", file); + wsprintf(cmdline, _T("\"%s\" /regserver"), file); ready++; } else if (!x64) { if (GetModuleFileName(GetModuleHandle(NULL), self, STR_SIZE)) { - wsprintf(cmdline, "\"%s\" /%c%s", self, cmd, file); + wsprintf(cmdline, _T("\"%s\" /%c%s"), self, cmd, file); ready++; } } @@ -148,7 +149,7 @@ void RegFile(char cmd, char *file, int x64) { if (GetSystemDirectory(self, STR_SIZE)) { - wsprintf(cmdline, "\"%s\\regsvr32.exe\" /s \"%s\"", self, file); + wsprintf(cmdline, _T("\"%s\\regsvr32.exe\" /s \"%s\""), self, file); ready++; SafeWow64EnableWow64FsRedirection(FALSE); @@ -176,7 +177,7 @@ void RegFile(char cmd, char *file, int x64) } } -void RegDll(char *file) +void RegDll(TCHAR *file) { HMODULE mod = LoadLibraryEx(file, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (mod) @@ -188,7 +189,7 @@ void RegDll(char *file) } } -void RegTypeLib(char *file) +void RegTypeLib(TCHAR *file) { WCHAR wfile[STR_SIZE]; @@ -202,12 +203,12 @@ void RegTypeLib(char *file) } } -char *mystrstri(char *a, char *b) +TCHAR *mystrstri(TCHAR *a, TCHAR *b) { int l = lstrlen(b); while (lstrlen(a) >= l) { - char c = a[l]; + TCHAR c = a[l]; a[l] = 0; if (!lstrcmpi(a, b)) { @@ -222,23 +223,23 @@ char *mystrstri(char *a, char *b) void mini_memcpy(void *out, const void *in, int len) { - char *c_out=(char*)out; - char *c_in=(char *)in; + TCHAR *c_out=(TCHAR*)out; + TCHAR *c_in=(TCHAR *)in; while (len-- > 0) { *c_out++=*c_in++; } } -void DeleteFileOnReboot(char *pszFile) +void DeleteFileOnReboot(TCHAR *pszFile) { BOOL fOk = 0; - HMODULE hLib=GetModuleHandle("KERNEL32.dll"); + HMODULE hLib=GetModuleHandle(_T("KERNEL32.dll")); if (hLib) { - typedef BOOL (WINAPI *mfea_t)(LPCSTR lpExistingFileName,LPCSTR lpNewFileName,DWORD dwFlags); + typedef BOOL (WINAPI *mfea_t)(LPCTSTR lpExistingFileName,LPCTSTR lpNewFileName,DWORD dwFlags); mfea_t mfea; - mfea=(mfea_t) GetProcAddress(hLib,"MoveFileExA"); + mfea=(mfea_t) GetProcAddress(hLib,_CRT_STRINGIZE(MoveFileEx)); if (mfea) { fOk=mfea(pszFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT); @@ -247,10 +248,10 @@ void DeleteFileOnReboot(char *pszFile) if (!fOk) { - static char szRenameLine[1024]; - static char wininit[1024]; + static TCHAR szRenameLine[1024]; + static TCHAR wininit[1024]; int cchRenameLine; - char *szRenameSec = "[Rename]\r\n"; + TCHAR *szRenameSec = _T("[Rename]\r\n"); HANDLE hfile, hfilemap; DWORD dwFileSize, dwRenameLinePos; @@ -260,10 +261,10 @@ void DeleteFileOnReboot(char *pszFile) spn = GetShortPathName(pszFile,wininit,1024); if (!spn || spn > 1024) return; - cchRenameLine = wsprintf(szRenameLine,"NUL=%s\r\n",wininit); + cchRenameLine = wsprintf(szRenameLine,_T("NUL=%s\r\n"),wininit); GetWindowsDirectory(wininit, 1024-16); - lstrcat(wininit, "\\wininit.ini"); + lstrcat(wininit, _T("\\wininit.ini")); hfile = CreateFile(wininit, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); @@ -275,11 +276,11 @@ void DeleteFileOnReboot(char *pszFile) if (hfilemap != NULL) { - LPSTR pszWinInit = (LPSTR) MapViewOfFile(hfilemap, FILE_MAP_WRITE, 0, 0, 0); + LPTSTR pszWinInit = (LPTSTR) MapViewOfFile(hfilemap, FILE_MAP_WRITE, 0, 0, 0); if (pszWinInit != NULL) { - LPSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec); + LPTSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec); if (pszRenameSecInFile == NULL) { lstrcpy(pszWinInit+dwFileSize, szRenameSec); @@ -288,11 +289,11 @@ void DeleteFileOnReboot(char *pszFile) } else { - char *pszFirstRenameLine = pszRenameSecInFile+10; - char *pszNextSec = mystrstri(pszFirstRenameLine,"\n["); + TCHAR *pszFirstRenameLine = pszRenameSecInFile+10; + TCHAR *pszNextSec = mystrstri(pszFirstRenameLine,_T("\n[")); if (pszNextSec) { - char *p = ++pszNextSec; + TCHAR *p = ++pszNextSec; while (p < pszWinInit + dwFileSize) { p[cchRenameLine] = *p; p++; diff --git a/Contrib/Library/TypeLib/TypeLib.cpp b/Contrib/Library/TypeLib/TypeLib.cpp index 97379e70..24de9592 100644 --- a/Contrib/Library/TypeLib/TypeLib.cpp +++ b/Contrib/Library/TypeLib/TypeLib.cpp @@ -3,19 +3,20 @@ NSIS plug-in for Type Library Registration/UnRegistration Written by Joost Verburg + Unicode support by Jim Park -- 08/23/2007 + */ #include #include // nsis plugin +#include -#define NSISFunction(funcname) extern "C" void __declspec(dllexport) funcname(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +#define NSISFunction(funcname) extern "C" void __declspec(dllexport) funcname(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) extern "C" BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { return TRUE; } -// Functions - NSISFunction(Register) { EXDLL_INIT(); @@ -107,11 +108,11 @@ NSISFunction(GetLibVersion) { if (SUCCEEDED(hr)) { - char buf[33]; + TCHAR buf[33]; - wsprintf(buf, "%d", typelibAttr->wMajorVerNum); + wsprintf(buf, _T("%d"), typelibAttr->wMajorVerNum); pushstring(buf); - wsprintf(buf, "%d", typelibAttr->wMinorVerNum); + wsprintf(buf, _T("%d"), typelibAttr->wMinorVerNum); pushstring(buf); typeLib->ReleaseTLibAttr(typelibAttr); @@ -119,8 +120,8 @@ NSISFunction(GetLibVersion) { } else { - pushstring("0"); - pushstring("0"); + pushstring(_T("0")); + pushstring(_T("0")); } typeLib->Release(); @@ -128,8 +129,8 @@ NSISFunction(GetLibVersion) { } else { - pushstring("0"); - pushstring("0"); + pushstring(_T("0")); + pushstring(_T("0")); } } diff --git a/Contrib/MakeLangId/MakeLangId.cpp b/Contrib/MakeLangId/MakeLangId.cpp index 02df7d94..4c9a1a97 100644 --- a/Contrib/MakeLangId/MakeLangId.cpp +++ b/Contrib/MakeLangId/MakeLangId.cpp @@ -1,12 +1,15 @@ +// Unicode support by Jim Park -- 08/23/2007 + #include #include +#include "../ExDLL/nsis_tchar.h" #include "resource.h" -#define CBL(x) {x,#x} +#define CBL(x) {x,_T(#x)} struct line { unsigned short id; - char *name; + TCHAR *name; }; line primary[] = { @@ -201,17 +204,17 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) { } else if (HIWORD(wParam) == CBN_SELCHANGE) { if (SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0) != CB_ERR && SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0) != CB_ERR) { - char lang[512]; - wsprintf(lang, "Language ID: %d", MAKELANGID(primary[SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0)].id, sub[SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0)].id)); + TCHAR lang[512]; + wsprintf(lang, _T("Language ID: %d"), MAKELANGID(primary[SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0)].id, sub[SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0)].id)); SetDlgItemText(hwndDlg, IDC_RESULT, lang); } } else if (LOWORD(wParam) == IDOK) { if (SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0) != CB_ERR && SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0) != CB_ERR) { - HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, 16); + HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, 16*sizeof(TCHAR)); if (!hMem) return 0; - char *lang_id = (char *)GlobalLock(hMem); - wsprintf(lang_id, "%u", MAKELANGID(primary[SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0)].id, sub[SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0)].id)); + TCHAR *lang_id = (TCHAR *)GlobalLock(hMem); + wsprintf(lang_id, _T("%u"), MAKELANGID(primary[SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0)].id, sub[SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0)].id)); GlobalUnlock(hMem); if (!OpenClipboard(hwndDlg)) return 0; EmptyClipboard(); @@ -224,9 +227,9 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) { return 0; } -int APIENTRY WinMain(HINSTANCE hInstance, +int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPSTR lpCmdLine, + LPTSTR lpCmdLine, int nCmdShow) { InitCommonControls(); diff --git a/Contrib/Makensisw/afxres.h b/Contrib/Makensisw/afxres.h index d4c5e1fe..cc81d957 100644 --- a/Contrib/Makensisw/afxres.h +++ b/Contrib/Makensisw/afxres.h @@ -1,3 +1,5 @@ +// Reviewed for Unicode support by Jim Park -- 08/17/2007 + #define _WIN32_IE 0x0400 #include diff --git a/Contrib/Makensisw/jnetlib/asyncdns.cpp b/Contrib/Makensisw/jnetlib/asyncdns.cpp index 4789bdac..2904bfa5 100644 --- a/Contrib/Makensisw/jnetlib/asyncdns.cpp +++ b/Contrib/Makensisw/jnetlib/asyncdns.cpp @@ -6,6 +6,9 @@ ** License: see jnetlib.h */ +// Reviewed for Unicode support by Jim Park -- 08/16/2007 +// Note: For Unicode Support, all string functions must explicitly use +// ANSI versions if UNICODE is defined. #include "netinc.h" #include "util.h" @@ -57,14 +60,14 @@ int JNL_AsyncDNS::resolve(char *hostname, unsigned long *addr) return 0; } - if (lstrcmpi(m_hostname,hostname)) m_addr=0; + if (lstrcmpiA(m_hostname,hostname)) m_addr=0; else if (m_addr == INADDR_NONE) return -1; else if (m_addr) { *addr=m_addr; return 0; } - lstrcpy(m_hostname,hostname); + lstrcpyA(m_hostname,hostname); if (m_thread_kill) { diff --git a/Contrib/Makensisw/jnetlib/asyncdns.h b/Contrib/Makensisw/jnetlib/asyncdns.h index a8bbb466..4f6dc69d 100644 --- a/Contrib/Makensisw/jnetlib/asyncdns.h +++ b/Contrib/Makensisw/jnetlib/asyncdns.h @@ -14,6 +14,9 @@ ** 4. enjoy. */ +// Reviewed for Unicode support by Jim Park -- 08/16/2007 +// Note: Inet host name is strictly ANSI, no UNICODE for now. + #ifndef _ASYNCDNS_H_ #define _ASYNCDNS_H_ diff --git a/Contrib/Makensisw/jnetlib/connection.cpp b/Contrib/Makensisw/jnetlib/connection.cpp index 38d5f293..935715b8 100644 --- a/Contrib/Makensisw/jnetlib/connection.cpp +++ b/Contrib/Makensisw/jnetlib/connection.cpp @@ -4,6 +4,8 @@ ** Author: Justin Frankel ** File: connection.cpp - JNL TCP connection implementation ** License: see jnetlib.h +** +** Reviewed for Unicode support by Jim Park -- 08/17/2007 */ #include "netinc.h" diff --git a/Contrib/Makensisw/jnetlib/connection.h b/Contrib/Makensisw/jnetlib/connection.h index d77e856c..eb5a8ee6 100644 --- a/Contrib/Makensisw/jnetlib/connection.h +++ b/Contrib/Makensisw/jnetlib/connection.h @@ -50,6 +50,8 @@ ** make the socket close after sending all the data sent. ** ** 8. delete ye' ol' object. +** +** Reviewed for Unicode Support by Jim Park -- 08/17/2007 */ #ifndef _CONNECTION_H_ diff --git a/Contrib/Makensisw/jnetlib/httpget.cpp b/Contrib/Makensisw/jnetlib/httpget.cpp index a23202ce..9e38c1dd 100644 --- a/Contrib/Makensisw/jnetlib/httpget.cpp +++ b/Contrib/Makensisw/jnetlib/httpget.cpp @@ -4,6 +4,12 @@ ** Author: Justin Frankel ** File: httpget.cpp - JNL HTTP GET implementation ** License: see jnetlib.h +** +** Reviewed for Unicode Support by Jim Park -- 08/17/2007 +** Note: The functions that work on char's should be explicitely set to use the +** ANSI versions. Some of the functions like wprintf() are #defined to be +** the wide-char versions when _UNICODE is defined. So these must be explictly +** set to use the ANSI versions. */ #include "netinc.h" @@ -181,14 +187,14 @@ void JNL_HTTPGet::connect(char *url) if (!m_http_proxyhost || !m_http_proxyhost[0]) { - wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_request); + wsprintfA(str,"GET %s HTTP/1.0\r\n",m_http_request); } else { - wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_url); + wsprintfA(str,"GET %s HTTP/1.0\r\n",m_http_url); } - wsprintf(str+strlen(str),"Host: %s\r\n",m_http_host); + wsprintfA(str+strlen(str),"Host: %s\r\n",m_http_host); if (m_http_lpinfo&&m_http_lpinfo[0]) { diff --git a/Contrib/Makensisw/jnetlib/httpget.h b/Contrib/Makensisw/jnetlib/httpget.h index ba0790f1..98cb39b2 100644 --- a/Contrib/Makensisw/jnetlib/httpget.h +++ b/Contrib/Makensisw/jnetlib/httpget.h @@ -37,6 +37,12 @@ ** note that user, pass, port, and /requestwhatever are all optional :) ** note that also, http:// is really not important. if you do poo:// ** or even leave out the http:// altogether, it will still work. +** +** Reviewed for Unicode Support by Jim Park -- 08/17/2007 +** Note: The functions that work on char's should be explicitely set to use the +** ANSI versions. Some of the functions like wprintf() are #defined to be +** the wide-char versions when _UNICODE is defined. So these must be explictly +** set to use the ANSI versions. */ #ifndef _HTTPGET_H_ diff --git a/Contrib/Makensisw/jnetlib/netinc.h b/Contrib/Makensisw/jnetlib/netinc.h index b4d96fda..ae1895f2 100644 --- a/Contrib/Makensisw/jnetlib/netinc.h +++ b/Contrib/Makensisw/jnetlib/netinc.h @@ -4,6 +4,12 @@ ** Author: Justin Frankel ** File: netinc.h - network includes and portability defines (used internally) ** License: see jnetlib.h +** +** Reviewed for Unicode Support by Jim Park -- 08/17/2007 +** Note: The functions that work on char's should be explicitely set to use the +** ANSI versions. Some of the functions like lstrcpy() are #defined to be +** the wide-char versions when _UNICODE is defined. So these must be explictly +** set to use the ANSI versions. */ #ifndef _NETINC_H_ @@ -72,10 +78,10 @@ extern void mini_memset(void *,char,int); extern void mini_memcpy(void *,void*,int); #define memset mini_memset #define memcpy mini_memcpy -#define strcpy lstrcpy -#define strncpy lstrcpyn -#define strcat lstrcat -#define strlen lstrlen +#define strcpy lstrcpyA +#define strncpy lstrcpynA +#define strcat lstrcatA +#define strlen lstrlenA #define malloc(x) GlobalAlloc(GPTR,(x)) #define free(x) { if (x) GlobalFree(x); } diff --git a/Contrib/Makensisw/jnetlib/util.cpp b/Contrib/Makensisw/jnetlib/util.cpp index 350bb161..759f8e58 100644 --- a/Contrib/Makensisw/jnetlib/util.cpp +++ b/Contrib/Makensisw/jnetlib/util.cpp @@ -4,6 +4,12 @@ ** Author: Justin Frankel ** File: util.cpp - JNL implementation of basic network utilities ** License: see jnetlib.h +** +** Reviewed for Unicode Support by Jim Park -- 08/17/2007 +** Note: The functions that work on char's should be explicitely set to use the +** ANSI versions. Some of the functions like wprintf() are #defined to be +** the wide-char versions when _UNICODE is defined. So these must be explictly +** set to use the ANSI versions. */ #include "netinc.h" diff --git a/Contrib/Makensisw/jnetlib/util.h b/Contrib/Makensisw/jnetlib/util.h index d271fd6c..59d75bff 100644 --- a/Contrib/Makensisw/jnetlib/util.h +++ b/Contrib/Makensisw/jnetlib/util.h @@ -22,6 +22,11 @@ ** JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen); ** gives you the dotted decimal notation of an integer ip address. ** +** Reviewed for Unicode Support by Jim Park -- 08/17/2007 +** Note: The functions that work on char's should be explicitely set to use the +** ANSI versions. Some of the functions like wprintf() are #defined to be +** the wide-char versions when _UNICODE is defined. So these must be explictly +** set to use the ANSI versions. */ #ifndef _UTIL_H_ diff --git a/Contrib/Makensisw/makensisw.cpp b/Contrib/Makensisw/makensisw.cpp index a75758b7..d95d8327 100644 --- a/Contrib/Makensisw/makensisw.cpp +++ b/Contrib/Makensisw/makensisw.cpp @@ -17,6 +17,8 @@ 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. + + Unicode support by Jim Park -- 08/18/2007 */ #define MAKENSISW_CPP @@ -34,7 +36,7 @@ NFINDREPLACE g_find; extern NTOOLBAR g_toolbar; int g_symbol_set_mode; -int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow) { +int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, TCHAR *cmdParam, int cmdShow) { MSG msg; int status; HACCEL haccel; @@ -44,19 +46,19 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmd my_memset(&g_find,0,sizeof(NFINDREPLACE)); g_sdata.hInstance=GetModuleHandle(0); g_sdata.symbols = NULL; - g_sdata.sigint_event = CreateEvent(NULL, FALSE, FALSE, "makensis win32 signint event"); + g_sdata.sigint_event = CreateEvent(NULL, FALSE, FALSE, _T("makensis win32 signint event")); RestoreSymbols(); - HINSTANCE hRichEditDLL = LoadLibrary("RichEd32.dll"); + HINSTANCE hRichEditDLL = LoadLibrary(_T("RichEd32.dll")); if (!InitBranding()) { - MessageBox(0,NSISERROR,"Error",MB_ICONEXCLAMATION|MB_OK); + MessageBox(0,NSISERROR,_T("Error"),MB_ICONEXCLAMATION|MB_OK); return 1; } ResetObjects(); HWND hDialog = CreateDialog(g_sdata.hInstance,MAKEINTRESOURCE(DLG_MAIN),0,DialogProc); if (!hDialog) { - MessageBox(0,DLGERROR,"Error",MB_ICONEXCLAMATION|MB_OK); + MessageBox(0,DLGERROR,_T("Error"),MB_ICONEXCLAMATION|MB_OK); return 1; } haccel = LoadAccelerators(g_sdata.hInstance, MAKEINTRESOURCE(IDK_ACCEL)); @@ -80,7 +82,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmd return msg.wParam; } -void SetScript(const char *script, bool clearArgs /*= true*/) +void SetScript(const TCHAR *script, bool clearArgs /*= true*/) { if (g_sdata.script) { @@ -94,24 +96,25 @@ void SetScript(const char *script, bool clearArgs /*= true*/) GlobalFree(g_sdata.script_cmd_args); } - g_sdata.script_cmd_args = GlobalAlloc(GHND, 1); + // Pointing to a single char. Maybe _T('\0') + g_sdata.script_cmd_args = GlobalAlloc(GHND, sizeof(TCHAR)); } - g_sdata.script = (char *) GlobalAlloc(GPTR, lstrlen(script) + 1); + g_sdata.script = (TCHAR *) GlobalAlloc(GPTR, (lstrlen(script) + 1)*sizeof(TCHAR)); lstrcpy(g_sdata.script, script); } -void AddScriptCmdArgs(const char *arg) +void AddScriptCmdArgs(const TCHAR *arg) { g_sdata.script_cmd_args = GlobalReAlloc(g_sdata.script_cmd_args, - GlobalSize(g_sdata.script_cmd_args) + lstrlen(arg) + 2 /* quotes */ + 1 /* space */, + GlobalSize(g_sdata.script_cmd_args) + (lstrlen(arg) + 2/* quotes */ + 1 /* space */)*sizeof(TCHAR), 0); - char *args = (char *) GlobalLock(g_sdata.script_cmd_args); + TCHAR *args = (TCHAR *) GlobalLock(g_sdata.script_cmd_args); - lstrcat(args, " \""); + lstrcat(args, _T(" \"")); lstrcat(args, arg); - lstrcat(args, "\""); + lstrcat(args, _T("\"")); GlobalUnlock(g_sdata.script_cmd_args); } @@ -119,23 +122,23 @@ void AddScriptCmdArgs(const char *arg) void ProcessCommandLine() { int argc; - char **argv; + TCHAR **argv; int i, j; int argSpaceSize; - argSpaceSize = SetArgv((char *)GetCommandLine(), &argc, &argv); + argSpaceSize = SetArgv((TCHAR *)GetCommandLine(), &argc, &argv); if (argc > 1) { for (i = 1; i < argc; i++) { - if (!lstrncmpi(argv[i], "/XSetCompressor ", lstrlen("/XSetCompressor "))) + if (!lstrncmpi(argv[i], _T("/XSetCompressor "), lstrlen(_T("/XSetCompressor ")))) { - char *p = argv[i] + lstrlen("/XSetCompressor "); - if(!lstrncmpi(p,"/FINAL ", lstrlen("/FINAL "))) + TCHAR *p = argv[i] + lstrlen(_T("/XSetCompressor ")); + if(!lstrncmpi(p,_T("/FINAL "), lstrlen(_T("/FINAL ")))) { - p += lstrlen("/FINAL "); + p += lstrlen(_T("/FINAL ")); } - while (*p == ' ') p++; + while (*p == _T(' ')) p++; for (j = (int) COMPRESSOR_SCRIPT + 1; j < (int) COMPRESSOR_BEST; j++) { @@ -145,11 +148,11 @@ void ProcessCommandLine() } } } - else if (!lstrcmpi(argv[i], "/ChooseCompressor")) + else if (!lstrcmpi(argv[i], _T("/ChooseCompressor"))) { g_sdata.userSelectCompressor = TRUE; } - else if (argv[i][0] == '-' || argv[i][0] == '/') + else if (argv[i][0] == _T('-') || argv[i][0] == _T('/')) { AddScriptCmdArgs(argv[i]); } @@ -185,11 +188,11 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { CreateToolBar(); InitTooltips(g_sdata.hwnd); SetBranding(g_sdata.hwnd); - HFONT hFont = CreateFont(14,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,"Courier New"); + HFONT hFont = CreateFont(14,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,_T("Courier New")); SendDlgItemMessage(hwndDlg,IDC_LOGWIN,WM_SETFONT,(WPARAM)hFont,0); RestoreWindowPos(g_sdata.hwnd); RestoreCompressor(); - SetScript(""); + SetScript(_T("")); g_sdata.compressor = COMPRESSOR_NONE_SELECTED; g_sdata.userSelectCompressor = FALSE; @@ -243,7 +246,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { } case WM_DROPFILES: { int num; - char szTmp[MAX_PATH]; + TCHAR szTmp[MAX_PATH]; num = DragQueryFile((HDROP)wParam,(UINT)-1,NULL,0); if (num==1) { DragQueryFile((HDROP)wParam,0,szTmp,MAX_PATH); @@ -254,7 +257,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { CompileNSISScript(); } } else { - MessageBox(hwndDlg,MULTIDROPERROR,"Error",MB_OK|MB_ICONSTOP); + MessageBox(hwndDlg,MULTIDROPERROR,_T("Error"),MB_OK|MB_ICONSTOP); } DragFinish((HDROP)wParam); break; @@ -267,7 +270,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { case WM_ENTERSIZEMOVE: { GetClientRect(g_sdata.hwnd, &g_resize.resizeRect); - return TRUE; + return TRUE; } case WM_SIZE: { @@ -299,8 +302,8 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { } if(g_sdata.compressor == COMPRESSOR_BEST) { if (g_sdata.retcode==0 && FileExists(g_sdata.output_exe)) { - char temp_file_name[1024]; - wsprintf(temp_file_name,"%s_makensisw_temp",g_sdata.output_exe); + TCHAR temp_file_name[1024]; + wsprintf(temp_file_name,_T("%s_makensisw_temp"),g_sdata.output_exe); if(!lstrcmpi(g_sdata.compressor_name,compressor_names[(int)COMPRESSOR_SCRIPT+1])) { SetCompressorStats(); CopyFile(g_sdata.output_exe,temp_file_name,false); @@ -354,7 +357,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { } if(this_compressor == ((int)COMPRESSOR_BEST - 1)) { - char buf[1024]; + TCHAR buf[1024]; g_sdata.compressor_name = compressor_names[(int)COMPRESSOR_SCRIPT+1]; @@ -369,7 +372,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { LogMessage(g_sdata.hwnd, g_sdata.compressor_stats); } DeleteFile(temp_file_name); - lstrcpy(g_sdata.compressor_stats,""); + lstrcpy(g_sdata.compressor_stats,_T("")); } else { g_sdata.compressor_name = compressor_names[this_compressor+1]; @@ -385,16 +388,16 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { if (!g_sdata.retcode) { MessageBeep(MB_ICONASTERISK); if (g_sdata.warnings) - SetTitle(g_sdata.hwnd,"Finished with Warnings"); + SetTitle(g_sdata.hwnd,_T("Finished with Warnings")); else - SetTitle(g_sdata.hwnd,"Finished Sucessfully"); + SetTitle(g_sdata.hwnd,_T("Finished Sucessfully")); // Added by Darren Owen (DrO) on 1/10/2003 if(g_sdata.recompile_test) PostMessage(g_sdata.hwnd, WM_COMMAND, LOWORD(IDC_TEST), 0); } else { MessageBeep(MB_ICONEXCLAMATION); - SetTitle(g_sdata.hwnd,"Compile Error: See Log for Details"); + SetTitle(g_sdata.hwnd,_T("Compile Error: See Log for Details")); } // Added by Darren Owen (DrO) on 1/10/2003 @@ -455,8 +458,8 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (cds->dwData) { case MAKENSIS_NOTIFY_SCRIPT: if (g_sdata.input_script) GlobalFree(g_sdata.input_script); - g_sdata.input_script = (char *)GlobalAlloc(GPTR, cds->cbData); - lstrcpy(g_sdata.input_script, (char *)cds->lpData); + g_sdata.input_script = (TCHAR *)GlobalAlloc(GPTR, cds->cbData * sizeof(TCHAR)); + lstrcpy(g_sdata.input_script, (TCHAR *)cds->lpData); break; case MAKENSIS_NOTIFY_WARNING: g_sdata.warnings++; @@ -465,8 +468,8 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { break; case MAKENSIS_NOTIFY_OUTPUT: if (g_sdata.output_exe) GlobalFree(g_sdata.output_exe); - g_sdata.output_exe = (char *)GlobalAlloc(GPTR, cds->cbData); - lstrcpy(g_sdata.output_exe, (char *)cds->lpData); + g_sdata.output_exe = (TCHAR *)GlobalAlloc(GPTR, cds->cbData * sizeof(TCHAR)); + lstrcpy(g_sdata.output_exe, (TCHAR *)cds->lpData); break; } return TRUE; @@ -476,11 +479,11 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (LOWORD(wParam)) { case IDM_BROWSESCR: { if (g_sdata.input_script) { - char str[MAX_PATH],*str2; + TCHAR str[MAX_PATH],*str2; lstrcpy(str,g_sdata.input_script); - str2=my_strrchr(str,'\\'); + str2=my_strrchr(str,_T('\\')); if(str2!=NULL) *(str2+1)=0; - ShellExecute(g_sdata.hwnd,"open",str,NULL,NULL,SW_SHOWNORMAL); + ShellExecute(g_sdata.hwnd,_T("open"),str,NULL,NULL,SW_SHOWNORMAL); } return TRUE; } @@ -491,12 +494,12 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { } case IDM_NSISHOME: { - ShellExecute(g_sdata.hwnd,"open",NSIS_URL,NULL,NULL,SW_SHOWNORMAL); + ShellExecuteA(g_sdata.hwnd,"open",NSIS_URL,NULL,NULL,SW_SHOWNORMAL); return TRUE; } case IDM_FORUM: { - ShellExecute(g_sdata.hwnd,"open",NSIS_FOR,NULL,NULL,SW_SHOWNORMAL); + ShellExecuteA(g_sdata.hwnd,"open",NSIS_FOR,NULL,NULL,SW_SHOWNORMAL); return TRUE; } case IDM_NSISUPDATE: @@ -518,17 +521,17 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { { if (!g_sdata.thread) { OPENFILENAME l={sizeof(l),}; - char buf[MAX_PATH]; + TCHAR buf[MAX_PATH]; l.hwndOwner = hwndDlg; - l.lpstrFilter = "NSIS Script (*.nsi)\0*.nsi\0All Files (*.*)\0*.*\0"; + l.lpstrFilter = _T("NSIS Script (*.nsi)\0*.nsi\0All Files (*.*)\0*.*\0"); l.lpstrFile = buf; l.nMaxFile = MAX_STRING-1; - l.lpstrTitle = "Load Script"; - l.lpstrDefExt = "log"; + l.lpstrTitle = _T("Load Script"); + l.lpstrDefExt = _T("log"); l.lpstrFileTitle = NULL; l.lpstrInitialDir = NULL; l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST; - lstrcpy(buf,""); + lstrcpy(buf,_T("")); if (GetOpenFileName(&l)) { SetScript(buf); PushMRUFile(g_sdata.script); @@ -582,18 +585,18 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { case IDC_TEST: { if (g_sdata.output_exe) { - ShellExecute(g_sdata.hwnd,"open",g_sdata.output_exe,NULL,NULL,SW_SHOWNORMAL); + ShellExecute(g_sdata.hwnd,_T("open"),g_sdata.output_exe,NULL,NULL,SW_SHOWNORMAL); } return TRUE; } case IDM_EDITSCRIPT: { if (g_sdata.input_script) { - if ((int)ShellExecute(g_sdata.hwnd,"open",g_sdata.input_script,NULL,NULL,SW_SHOWNORMAL)<=32) { - char path[MAX_PATH]; + if ((int)ShellExecute(g_sdata.hwnd,_T("open"),g_sdata.input_script,NULL,NULL,SW_SHOWNORMAL)<=32) { + TCHAR path[MAX_PATH]; if (GetWindowsDirectory(path,sizeof(path))) { - lstrcat(path,"\\notepad.exe"); - ShellExecute(g_sdata.hwnd,"open",path,g_sdata.input_script,NULL,SW_SHOWNORMAL); + lstrcat(path,_T("\\notepad.exe")); + ShellExecute(g_sdata.hwnd,_T("open"),path,g_sdata.input_script,NULL,SW_SHOWNORMAL); } } } @@ -625,21 +628,21 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { case IDM_SAVE: { OPENFILENAME l={sizeof(l),}; - char buf[MAX_STRING]; + TCHAR buf[MAX_STRING]; l.hwndOwner = hwndDlg; - l.lpstrFilter = "Log Files (*.log)\0*.log\0Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; + l.lpstrFilter = _T("Log Files (*.log)\0*.log\0Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"); l.lpstrFile = buf; l.nMaxFile = MAX_STRING-1; - l.lpstrTitle = "Save Output"; - l.lpstrDefExt = "log"; + l.lpstrTitle = _T("Save Output"); + l.lpstrDefExt = _T("log"); l.lpstrInitialDir = NULL; l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST; - lstrcpy(buf,"output"); + lstrcpy(buf,_T("output")); if (GetSaveFileName(&l)) { HANDLE hFile = CreateFile(buf,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0); if (hFile) { int len=SendDlgItemMessage(g_sdata.hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0); - char *existing_text=(char*)GlobalAlloc(GPTR,len); + TCHAR *existing_text=(TCHAR*)GlobalAlloc(GPTR,len * sizeof(TCHAR)); existing_text[0]=0; GetDlgItemText(g_sdata.hwnd, IDC_LOGWIN, existing_text, len); DWORD dwWritten = 0; @@ -657,7 +660,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { g_find.fr.lStructSize = sizeof(FINDREPLACE); g_find.fr.hwndOwner = hwndDlg; g_find.fr.Flags = FR_NOUPDOWN; - g_find.fr.lpstrFindWhat = (char *)GlobalAlloc(GPTR, 128); + g_find.fr.lpstrFindWhat = (TCHAR *)GlobalAlloc(GPTR, 128 * sizeof(TCHAR)); if (!g_find.fr.lpstrFindWhat) return TRUE; g_find.fr.wFindWhatLen = 128; g_find.hwndFind = FindText(&g_find.fr); @@ -716,12 +719,12 @@ DWORD WINAPI MakeNSISProc(LPVOID p) { else sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = true; if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) { - ErrorMessage(g_sdata.hwnd,"There was an error creating the output pipe."); + ErrorMessage(g_sdata.hwnd,_T("There was an error creating the output pipe.")); PostMessage(g_sdata.hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0); return 1; } if (!CreatePipe(&read_stdin,&newstdin,&sa,0)) { - ErrorMessage(g_sdata.hwnd,"There was an error creating the input pipe."); + ErrorMessage(g_sdata.hwnd,_T("There was an error creating the input pipe.")); PostMessage(g_sdata.hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0); return 1; } @@ -732,8 +735,8 @@ DWORD WINAPI MakeNSISProc(LPVOID p) { si.hStdError = newstdout; si.hStdInput = newstdin; if (!CreateProcess(NULL,g_sdata.compile_command,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) { - char buf[MAX_STRING]; - wsprintf(buf,"Could not execute:\r\n %s.",g_sdata.compile_command); + TCHAR buf[MAX_STRING]; + wsprintf(buf,_T("Could not execute:\r\n %s."),g_sdata.compile_command); ErrorMessage(g_sdata.hwnd,buf); CloseHandle(newstdout); CloseHandle(read_stdout); @@ -746,7 +749,7 @@ DWORD WINAPI MakeNSISProc(LPVOID p) { while (dwExit == STILL_ACTIVE || dwRead) { PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL); if (dwRead) { - ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL); + ReadFile(read_stdout, szBuf, sizeof(szBuf)-sizeof(TCHAR), &dwRead, NULL); szBuf[dwRead] = 0; LogMessage(g_sdata.hwnd, szBuf); } @@ -804,16 +807,16 @@ BOOL CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { { HFONT bfont = CreateFont(13,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FIXED_PITCH|FF_DONTCARE, "Tahoma"); + FIXED_PITCH|FF_DONTCARE, _T("Tahoma")); HFONT bfontb = CreateFont(13,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FIXED_PITCH|FF_DONTCARE, "Tahoma"); + FIXED_PITCH|FF_DONTCARE, _T("Tahoma")); HFONT rfont = CreateFont(12,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FIXED_PITCH|FF_DONTCARE, "MS Shell Dlg"); + FIXED_PITCH|FF_DONTCARE, _T("MS Shell Dlg")); HFONT rfontb = CreateFont(12,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FIXED_PITCH|FF_DONTCARE, "MS Shell Dlg"); + FIXED_PITCH|FF_DONTCARE, _T("MS Shell Dlg")); if (bfont&&bfontb) { SendDlgItemMessage(hwndDlg, IDC_ABOUTVERSION, WM_SETFONT, (WPARAM)bfontb, FALSE); SendDlgItemMessage(hwndDlg, IDC_ABOUTCOPY, WM_SETFONT, (WPARAM)bfont, FALSE); @@ -876,7 +879,7 @@ void EnableSymbolEditButtons(HWND hwndDlg) } } -void SetSymbols(HWND hwndDlg, char **symbols) +void SetSymbols(HWND hwndDlg, TCHAR **symbols) { int i = 0; SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_RESETCONTENT , 0, 0); @@ -892,16 +895,16 @@ void SetSymbols(HWND hwndDlg, char **symbols) EnableWindow(GetDlgItem(hwndDlg, IDDEL), FALSE); } -char **GetSymbols(HWND hwndDlg) +TCHAR **GetSymbols(HWND hwndDlg) { int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETCOUNT, 0, 0); - char **symbols = NULL; + TCHAR **symbols = NULL; if(n > 0) { - HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (n+1)*sizeof(char *)); - symbols = (char **)GlobalLock(hMem); + HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (n+1)*sizeof(TCHAR *)); + symbols = (TCHAR **)GlobalLock(hMem); for (int i = 0; i < n; i++) { int len = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXTLEN, (WPARAM)i, 0); - symbols[i] = (char *)GlobalAlloc(GPTR, (len+1)*sizeof(char)); + symbols[i] = (TCHAR *)GlobalAlloc(GPTR, (len+1)*sizeof(TCHAR)); SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)i, (LPARAM)symbols[i]); } symbols[n] = NULL; @@ -928,8 +931,8 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) } case WM_MAKENSIS_LOADSYMBOLSET: { - char *name = (char *)wParam; - char **symbols = LoadSymbolSet(name); + TCHAR *name = (TCHAR *)wParam; + TCHAR **symbols = LoadSymbolSet(name); HGLOBAL hMem; SetSymbols(hwndDlg, symbols); @@ -942,8 +945,8 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) } case WM_MAKENSIS_SAVESYMBOLSET: { - char *name = (char *)wParam; - char **symbols = GetSymbols(hwndDlg); + TCHAR *name = (TCHAR *)wParam; + TCHAR **symbols = GetSymbols(hwndDlg); HGLOBAL hMem; if(symbols) { @@ -981,20 +984,20 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0); if(n > 0) { - char *buf = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char)); + TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR)); SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXT, n+1, (LPARAM)buf); - if(my_strstr(buf," ") || my_strstr(buf,"\t")) { - MessageBox(hwndDlg,SYMBOLSERROR,"Error",MB_OK|MB_ICONSTOP); + if(my_strstr(buf,_T(" ")) || my_strstr(buf,_T("\t"))) { + MessageBox(hwndDlg,SYMBOLSERROR,_T("Error"),MB_OK|MB_ICONSTOP); GlobalFree(buf); break; } n = SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXTLENGTH, 0, 0); if(n > 0) { - char *buf2 = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char)); + TCHAR *buf2 = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR)); SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXT, n+1, (LPARAM)buf2); - char *buf3 = (char *)GlobalAlloc(GPTR, (lstrlen(buf)+lstrlen(buf2)+2)*sizeof(char)); - wsprintf(buf3,"%s=%s",buf,buf2); + TCHAR *buf3 = (TCHAR *)GlobalAlloc(GPTR, (lstrlen(buf)+lstrlen(buf2)+2)*sizeof(TCHAR)); + wsprintf(buf3,_T("%s=%s"),buf,buf2); GlobalFree(buf); buf = buf3; GlobalFree(buf2); @@ -1023,9 +1026,9 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) if(num == 1) { int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXTLEN, (WPARAM)index, 0); if(n > 0) { - char *buf = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char)); + TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR)); SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)index, (LPARAM)buf); - char *p = my_strstr(buf,"="); + TCHAR *p = my_strstr(buf,_T("=")); if(p) { SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, (LPARAM)(p+1)); *p=0; @@ -1157,7 +1160,7 @@ BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam HKEY hSubKey; if (RegOpenKeyEx(hKey,REGSYMSUBKEY,0,KEY_READ,&hSubKey) == ERROR_SUCCESS) { - char subkey[1024]; + TCHAR subkey[1024]; int i=0; while (RegEnumKey(hSubKey,i,subkey,sizeof(subkey)) == ERROR_SUCCESS) { @@ -1189,7 +1192,7 @@ BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam case IDOK: { HWND hwndEdit; - char name[SYMBOL_SET_NAME_MAXLEN+1]; + TCHAR name[SYMBOL_SET_NAME_MAXLEN+1]; hwndEdit = FindWindowEx(GetDlgItem(hwndDlg, IDC_NAMES), 0, 0, 0); // Handle of list hwndEdit = FindWindowEx(GetDlgItem(hwndDlg, IDC_NAMES), hwndEdit, 0, 0); //Handle of edit box @@ -1224,7 +1227,7 @@ BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam int n = SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETCURSEL, 0, 0); if(n != CB_ERR) { long len = SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETLBTEXTLEN, (WPARAM)n, 0); - char *buf = (char *)GlobalAlloc(GPTR, (len+1)*sizeof(char)); + TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (len+1)*sizeof(TCHAR)); if(SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETLBTEXT, (WPARAM)n, (LPARAM)buf) != CB_ERR) { SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_DELETESTRING, n, 0); DeleteSymbolSet(buf); @@ -1269,7 +1272,7 @@ void SetCompressor(NCOMPRESSOR compressor) if(g_sdata.compressor != compressor) { WORD command; - char *compressor_name; + TCHAR *compressor_name; if(compressor > COMPRESSOR_SCRIPT && compressor < COMPRESSOR_BEST) { command = compressor_commands[(int)compressor]; @@ -1282,7 +1285,7 @@ void SetCompressor(NCOMPRESSOR compressor) else { compressor = COMPRESSOR_SCRIPT; command = IDM_COMPRESSOR_SCRIPT; - compressor_name = ""; + compressor_name = _T(""); } g_sdata.compressor = compressor; g_sdata.compressor_name = compressor_name; diff --git a/Contrib/Makensisw/makensisw.h b/Contrib/Makensisw/makensisw.h index beadc3fc..eca24156 100644 --- a/Contrib/Makensisw/makensisw.h +++ b/Contrib/Makensisw/makensisw.h @@ -18,6 +18,7 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. + Unicode support by Jim Park -- 08/10/2007 */ #ifndef MAKENSIS_H #define MAKENSIS_H @@ -25,6 +26,7 @@ #define _WIN32_IE 0x0400 #include #include +#include "../ExDLL/nsis_tchar.h" #include "utils.h" #define _RICHEDIT_VER 0x0200 #include @@ -35,39 +37,39 @@ #define NSIS_FOR "http://forums.winamp.com/forumdisplay.php?forumid=65" #define NSIS_UPDATE "http://nsis.sourceforge.net/update.php?version=" #define NSIS_DL_URL "http://nsis.sourceforge.net/download/" -#define USAGE "Usage:\r\n\r\n - File | Load Script...\r\n - Drag the .nsi file into this window\r\n - Right click the .nsi file and choose \"Compile NSIS Script\"" -#define COPYRIGHT "Copyright © 2002 Robert Rainwater" -#define CONTRIB "Fritz Elfert, Justin Frankel, Amir Szekely, Sunil Kamath, Joost Verburg" +#define USAGE _T("Usage:\r\n\r\n - File | Load Script...\r\n - Drag the .nsi file into this window\r\n - Right click the .nsi file and choose \"Compile NSIS Script\"") +#define COPYRIGHT _T("Copyright © 2002 Robert Rainwater") +#define CONTRIB _T("Fritz Elfert, Justin Frankel, Amir Szekely, Sunil Kamath, Joost Verburg") #define DOCPATH "http://nsis.sourceforge.net/Docs/" -#define LOCALDOCS "\\NSIS.chm" -#define NSISERROR "Unable to intialize MakeNSIS. Please verify that makensis.exe is in the same directory as makensisw.exe." -#define DLGERROR "Unable to intialize MakeNSISW." -#define SYMBOLSERROR "Symbol cannot contain whitespace characters" -#define MULTIDROPERROR "Dropping more than one script at a time is not supported" -#define NSISUPDATEPROMPT "Running NSIS Update will close MakeNSISW.\nContinue?" +#define LOCALDOCS _T("\\NSIS.chm") +#define NSISERROR _T("Unable to intialize MakeNSIS. Please verify that makensis.exe is in the same directory as makensisw.exe.") +#define DLGERROR _T("Unable to intialize MakeNSISW.") +#define SYMBOLSERROR _T("Symbol cannot contain whitespace characters") +#define MULTIDROPERROR _T("Dropping more than one script at a time is not supported") +#define NSISUPDATEPROMPT _T("Running NSIS Update will close MakeNSISW.\nContinue?") #define REGSEC HKEY_CURRENT_USER #define REGSECDEF HKEY_LOCAL_MACHINE -#define REGKEY "Software\\NSIS" -#define REGLOC "MakeNSISWPlacement" -#define REGCOMPRESSOR "MakeNSISWCompressor" -#define REGSYMSUBKEY "Symbols" -#define REGMRUSUBKEY "MRU" -#define EXENAME "makensis.exe" +#define REGKEY _T("Software\\NSIS") +#define REGLOC _T("MakeNSISWPlacement") +#define REGCOMPRESSOR _T("MakeNSISWCompressor") +#define REGSYMSUBKEY _T("Symbols") +#define REGMRUSUBKEY _T("MRU") +#define EXENAME _T("makensis.exe") #define MAX_STRING 256 #define TIMEOUT 100 #define MINWIDTH 350 #define MINHEIGHT 180 -#define COMPRESSOR_MESSAGE "\n\nThe %s compressor created the smallest installer (%d bytes)." -#define RESTORED_COMPRESSOR_MESSAGE "\n\nThe %s compressor created the smallest installer (%d bytes)." -#define EXE_HEADER_COMPRESSOR_STAT "EXE header size:" -#define TOTAL_SIZE_COMPRESSOR_STAT "Total size:" +#define COMPRESSOR_MESSAGE _T("\n\nThe %s compressor created the smallest installer (%d bytes).") +#define RESTORED_COMPRESSOR_MESSAGE _T("\n\nThe %s compressor created the smallest installer (%d bytes).") +#define EXE_HEADER_COMPRESSOR_STAT _T("EXE header size:") +#define TOTAL_SIZE_COMPRESSOR_STAT _T("Total size:") #define SYMBOL_SET_NAME_MAXLEN 40 -#define LOAD_SYMBOL_SET_DLG_NAME "Load Symbol Definitions Set" -#define SAVE_SYMBOL_SET_DLG_NAME "Save Symbol Definitions Set" -#define LOAD_BUTTON_TEXT "Load" -#define SAVE_BUTTON_TEXT "Save" -#define LOAD_SYMBOL_SET_MESSAGE "Please select a name for the Symbol Definitions Set to load." -#define SAVE_SYMBOL_SET_MESSAGE "Please enter or select a name for the Symbol Definitions Set to save." +#define LOAD_SYMBOL_SET_DLG_NAME _T("Load Symbol Definitions Set") +#define SAVE_SYMBOL_SET_DLG_NAME _T("Save Symbol Definitions Set") +#define LOAD_BUTTON_TEXT _T("Load") +#define SAVE_BUTTON_TEXT _T("Save") +#define LOAD_SYMBOL_SET_MESSAGE _T("Please select a name for the Symbol Definitions Set to load.") +#define SAVE_SYMBOL_SET_MESSAGE _T("Please enter or select a name for the Symbol Definitions Set to save.") #define WM_MAKENSIS_PROCESSCOMPLETE (WM_USER+1001) #define WM_MAKENSIS_LOADSYMBOLSET (WM_USER+1002) @@ -93,22 +95,22 @@ typedef enum { } NCOMPRESSOR; #ifdef MAKENSISW_CPP -char *compressor_names[] = {"", - "zlib", - "/SOLID zlib", - "bzip2", - "/SOLID bzip2", - "lzma", - "/SOLID lzma", - "Best"}; -char *compressor_display_names[] = {"Defined in Script/Compiler Default", - "ZLIB", - "ZLIB (solid)", - "BZIP2", - "BZIP2 (solid)", - "LZMA", - "LZMA (solid)", - "Best Compressor"}; +TCHAR *compressor_names[] = {_T(""), + _T("zlib"), + _T("/SOLID zlib"), + _T("bzip2"), + _T("/SOLID bzip2"), + _T("lzma"), + _T("/SOLID lzma"), + _T("Best")}; +TCHAR *compressor_display_names[] = {_T("Defined in Script/Compiler Default"), + _T("ZLIB"), + _T("ZLIB (solid)"), + _T("BZIP2"), + _T("BZIP2 (solid)"), + _T("LZMA"), + _T("LZMA (solid)"), + _T("Best Compressor")}; WORD compressor_commands[] = {IDM_COMPRESSOR_SCRIPT, IDM_ZLIB, IDM_ZLIB_SOLID, @@ -140,9 +142,9 @@ int compressor_strings[] = {IDS_SCRIPT, // Extern Variables -extern const char* NSISW_VERSION; +extern const TCHAR* NSISW_VERSION; -int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow); +int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, TCHAR *cmdParam, int cmdShow); BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); DWORD WINAPI MakeNSISProc(LPVOID p); BOOL CALLBACK DialogResize(HWND hWnd, LPARAM /* unused*/); @@ -151,27 +153,27 @@ BOOL CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK CompressorProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -void SetScript(const char *script, bool clearArgs = true); +void SetScript(const TCHAR *script, bool clearArgs = true); void CompileNSISScript(); -char* BuildSymbols(); +TCHAR* BuildSymbols(); void SetCompressor(NCOMPRESSOR); void RestoreSymbols(); void SaveSymbols(); -void DeleteSymbolSet(char *); -char** LoadSymbolSet(char *); -void SaveSymbolSet(char *, char **); +void DeleteSymbolSet(TCHAR *); +TCHAR** LoadSymbolSet(TCHAR *); +void SaveSymbolSet(TCHAR *, TCHAR **); void RestoreMRUList(); void SaveMRUList(); typedef struct NSISScriptData { - char *script; + TCHAR *script; HGLOBAL script_cmd_args; - char *compile_command; - char *output_exe; - char *input_script; - char *branding; - char *brandingv; - char **symbols; + TCHAR *compile_command; + TCHAR *output_exe; + TCHAR *input_script; + TCHAR *branding; + TCHAR *brandingv; + TCHAR **symbols; int retcode; BOOL userSelectCompressor; DWORD logLength; @@ -188,9 +190,9 @@ typedef struct NSISScriptData { CHARRANGE textrange; NCOMPRESSOR default_compressor; NCOMPRESSOR compressor; - char *compressor_name; - char compressor_stats[512]; - char *best_compressor_name; + TCHAR *compressor_name; + TCHAR compressor_stats[512]; + TCHAR *best_compressor_name; // Added by Darren Owen (DrO) on 1/10/2003 int recompile_test; } NSCRIPTDATA; diff --git a/Contrib/Makensisw/toolbar.cpp b/Contrib/Makensisw/toolbar.cpp index 55edbf7a..850330fc 100644 --- a/Contrib/Makensisw/toolbar.cpp +++ b/Contrib/Makensisw/toolbar.cpp @@ -18,6 +18,8 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. + Unicode support by Jim Park -- 08/20/2007 + */ #define TOOLBAR_CPP @@ -25,6 +27,7 @@ #include "resource.h" #include "noclib.h" #include "toolbar.h" +#include "../ExDLL/nsis_tchar.h" NTOOLBAR g_toolbar; extern NSCRIPTDATA g_sdata; @@ -65,7 +68,7 @@ void CreateToolBar() g_toolbar.hwnd = CreateWindowEx ( 0L, TOOLBARCLASSNAME, - "", + _T(""), WS_CHILD | WS_VISIBLE | TBSTYLE_TRANSPARENT | TBSTYLE_FLAT, 0, 0, 0, 30, g_sdata.hwnd, @@ -77,7 +80,7 @@ void CreateToolBar() SendMessage(g_toolbar.hwnd, TB_ADDBUTTONS, BUTTONCOUNT, (LONG) &tbButton); // For Comctl32.dll version detection - HMODULE hMod = GetModuleHandle("comctl32.dll"); + HMODULE hMod = GetModuleHandle(_T("comctl32.dll")); if (GetProcAddress(hMod, "InitCommonControlsEx")) { // Version 4.70 // Modern toolbar, 24-bit bitmaps @@ -120,8 +123,8 @@ void UpdateToolBarCompressorButton() { int iBitmap; int iString; - char szBuffer[64]; - char temp[32]; + TCHAR szBuffer[64]; + TCHAR temp[32]; TOOLINFO ti; my_memset(&ti, 0, sizeof(TOOLINFO)); @@ -139,13 +142,13 @@ void UpdateToolBarCompressorButton() sizeof(temp)); my_memset(szBuffer, 0, sizeof(szBuffer)); lstrcat(szBuffer,temp); - lstrcat(szBuffer," ["); + lstrcat(szBuffer,_T(" [")); LoadString(g_sdata.hInstance, iString, temp, sizeof(temp)); lstrcat(szBuffer,temp); - lstrcat(szBuffer,"]"); + lstrcat(szBuffer,_T("]")); SendMessage(g_toolbar.hwnd, TB_CHANGEBITMAP, (WPARAM) IDM_COMPRESSOR, (LPARAM) MAKELPARAM(iBitmap, 0)); @@ -155,14 +158,14 @@ void UpdateToolBarCompressorButton() ti.hwnd = g_toolbar.hwnd; ti.uId = (UINT)TBB_COMPRESSOR; SendMessage(g_tip.tip, TTM_GETTOOLINFO, 0, (LPARAM) (LPTOOLINFO) &ti); - ti.lpszText = (LPSTR)szBuffer; + ti.lpszText = (LPTSTR)szBuffer; SendMessage(g_tip.tip, TTM_SETTOOLINFO, 0, (LPARAM) (LPTOOLINFO) &ti); } void AddToolBarButtonTooltip(int id, int iString) { TOOLINFO ti; - char szBuffer[64]; + TCHAR szBuffer[64]; RECT rect; my_memset(&ti, 0, sizeof(TOOLINFO)); @@ -179,7 +182,7 @@ void AddToolBarButtonTooltip(int id, int iString) iString, szBuffer, sizeof(szBuffer)); - ti.lpszText = (LPSTR) szBuffer; + ti.lpszText = (LPTSTR) szBuffer; ti.rect.left =rect.left; ti.rect.top = rect.top; ti.rect.right = rect.right; diff --git a/Contrib/Makensisw/toolbar.h b/Contrib/Makensisw/toolbar.h index 568118a6..989fef61 100644 --- a/Contrib/Makensisw/toolbar.h +++ b/Contrib/Makensisw/toolbar.h @@ -18,6 +18,7 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. + Reviewed for Unicode support by Jim Park -- 08/20/2007 */ #ifndef TOOLBAR_H #define TOOLBAR_H diff --git a/Contrib/Makensisw/update.cpp b/Contrib/Makensisw/update.cpp index 9dcbc17a..f509d3b2 100644 --- a/Contrib/Makensisw/update.cpp +++ b/Contrib/Makensisw/update.cpp @@ -1,8 +1,11 @@ +// Unicode support by Jim Park -- 08/20/2007 + #include "makensisw.h" #include "update.h" #include "noclib.h" #include "jnetlib/httpget.h" +#include "../ExDLL/nsis_tchar.h" static BOOL update_initialized = FALSE; @@ -28,12 +31,12 @@ void FinalizeUpdate() { int getProxyInfo(char *out) { DWORD v=0; HKEY hKey; - if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS) { + if (RegOpenKeyExA(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS) { DWORD l = 4; DWORD t; - if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD) { + if (RegQueryValueExA(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD) { l=8192; - if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)out,&l ) != ERROR_SUCCESS || t != REG_SZ) { + if (RegQueryValueExA(hKey,"ProxyServer",NULL,&t,(unsigned char *)out,&l ) != ERROR_SUCCESS || t != REG_SZ) { v=0; *out=0; } @@ -53,6 +56,7 @@ DWORD CALLBACK UpdateThread(LPVOID v) { char url[300]; BOOL error = FALSE; static char pbuf[8192]; + static char ansiBuf[1024]; char *p=NULL; *response = 0; @@ -72,9 +76,16 @@ DWORD CALLBACK UpdateThread(LPVOID v) { InitializeUpdate(); JNL_HTTPGet *get = new JNL_HTTPGet(g_dns,8192,(p&&p[0])?p:NULL);; - lstrcpy(url,NSIS_UPDATE); - lstrcat(url,g_sdata.brandingv); - lstrcpy(response,""); + lstrcpyA(url,NSIS_UPDATE); + +#ifdef _UNICODE + WideCharToMultiByte(CP_ACP, 0, g_sdata.brandingv, -1, ansiBuf, sizeof(ansiBuf), NULL, NULL); + lstrcatA(url,ansiBuf); +#else + lstrcatA(url,g_sdata.brandingv); +#endif + + lstrcpyA(response,""); get->addheader("User-Agent: MakeNSISw (jnetlib)"); get->addheader("Accept:*/*"); get->connect(url); @@ -85,10 +96,10 @@ DWORD CALLBACK UpdateThread(LPVOID v) { while(len=get->bytes_available()) { char b[RSZ]; if (len>RSZ) len=RSZ; - if (lstrlen(response)+len>RSZ) break; + if (lstrlenA(response)+len>RSZ) break; len=get->get_bytes(b,len); b[len]=0; - lstrcat(response,b); + lstrcatA(response,b); } } if (st==1) break; //closed @@ -100,26 +111,26 @@ DWORD CALLBACK UpdateThread(LPVOID v) { } if (error) { char buf[1000]; - wsprintf(buf,"There was a problem checking for an update. Please try again later.\n\nError: %s",get->geterrorstr()); - MessageBox(g_sdata.hwnd,buf,"NSIS Update",MB_OK|MB_ICONINFORMATION); + wsprintfA(buf, "There was a problem checking for an update. Please try again later.\n\nError: %s",get->geterrorstr()); + MessageBoxA(g_sdata.hwnd,buf,"NSIS Update",MB_OK|MB_ICONINFORMATION); } - else if (*response=='1'&&lstrlen(response)>2) { + else if (*response=='1'&&lstrlenA(response)>2) { char buf[200]; response+=2; - wsprintf(buf,"NSIS %s is now available. Would you like to download it now?",response); - if (MessageBox(g_sdata.hwnd,buf,"NSIS Update",MB_YESNO|MB_ICONINFORMATION)==IDYES) { - ShellExecute(g_sdata.hwnd,"open",NSIS_DL_URL,NULL,NULL,SW_SHOWNORMAL); + wsprintfA(buf, "NSIS %s is now available. Would you like to download it now?",response); + if (MessageBoxA(g_sdata.hwnd,buf,"NSIS Update",MB_YESNO|MB_ICONINFORMATION)==IDYES) { + ShellExecuteA(g_sdata.hwnd,"open",NSIS_DL_URL,NULL,NULL,SW_SHOWNORMAL); } } - else if (*response=='2'&&lstrlen(response)>2) { + else if (*response=='2'&&lstrlenA(response)>2) { char buf[200]; response+=2; - wsprintf(buf,"NSIS %s is now available. Would you like to download this preview release now?",response); - if (MessageBox(g_sdata.hwnd,buf,"NSIS Update",MB_YESNO|MB_ICONINFORMATION)==IDYES) { - ShellExecute(g_sdata.hwnd,"open",NSIS_DL_URL,NULL,NULL,SW_SHOWNORMAL); + wsprintfA(buf,"NSIS %s is now available. Would you like to download this preview release now?",response); + if (MessageBoxA(g_sdata.hwnd,buf,"NSIS Update",MB_YESNO|MB_ICONINFORMATION)==IDYES) { + ShellExecuteA(g_sdata.hwnd,"open",NSIS_DL_URL,NULL,NULL,SW_SHOWNORMAL); } } - else MessageBox(g_sdata.hwnd,"There is no update available for NSIS at this time.","NSIS Update",MB_OK|MB_ICONINFORMATION); + else MessageBoxA(g_sdata.hwnd,"There is no update available for NSIS at this time.","NSIS Update",MB_OK|MB_ICONINFORMATION); GlobalFree(response); delete get; EnableMenuItem(g_sdata.menu,IDM_NSISUPDATE,MF_ENABLED); @@ -129,9 +140,9 @@ DWORD CALLBACK UpdateThread(LPVOID v) { void Update() { DWORD dwThreadId; - if (my_strstr(g_sdata.brandingv,"cvs")) + if (my_strstr(g_sdata.brandingv,_T("cvs"))) { - MessageBox(g_sdata.hwnd,"Cannot check for new version of nightly builds. To update, download a new nightly build.","NSIS Update",MB_OK|MB_ICONSTOP); + MessageBox(g_sdata.hwnd,_T("Cannot check for new version of nightly builds. To update, download a new nightly build."),_T("NSIS Update"),MB_OK|MB_ICONSTOP); return; } diff --git a/Contrib/Makensisw/update.h b/Contrib/Makensisw/update.h index fa9c2bb3..942c7dbc 100644 --- a/Contrib/Makensisw/update.h +++ b/Contrib/Makensisw/update.h @@ -1,3 +1,5 @@ +/* Reviewed for Unicode support by Jim Park -- 08/18/2007 + /* Initialize update objects. */ void InitializeUpdate(); diff --git a/Contrib/Makensisw/utils.cpp b/Contrib/Makensisw/utils.cpp index 430f0e90..9a76d977 100644 --- a/Contrib/Makensisw/utils.cpp +++ b/Contrib/Makensisw/utils.cpp @@ -18,6 +18,8 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. + Unicode support by Jim Park -- 08/20/2007 + */ #include "makensisw.h" @@ -28,46 +30,46 @@ NTOOLTIP g_tip; LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam); -char g_mru_list[MRU_LIST_SIZE][MAX_PATH] = { "", "", "", "", "" }; +TCHAR g_mru_list[MRU_LIST_SIZE][MAX_PATH] = { _T(""), _T(""), _T(""), _T(""), _T("") }; extern NSCRIPTDATA g_sdata; -extern char *compressor_names[]; +extern TCHAR *compressor_names[]; -int SetArgv(const char *cmdLine, int *argc, char ***argv) +int SetArgv(const TCHAR *cmdLine, int *argc, TCHAR ***argv) { - const char *p; - char *arg, *argSpace; + const TCHAR *p; + TCHAR *arg, *argSpace; int size, argSpaceSize, inquote, copy, slashes; size = 2; - for (p = cmdLine; *p != '\0'; p++) { - if ((*p == ' ') || (*p == '\t')) { + for (p = cmdLine; *p != _T('\0'); p++) { + if ((*p == _T(' ')) || (*p == _T('\t'))) { size++; - while ((*p == ' ') || (*p == '\t')) { + while ((*p == _T(' ')) || (*p == _T('\t'))) { p++; } - if (*p == '\0') { + if (*p == _T('\0')) { break; } } } - argSpaceSize = size * sizeof(char *) + lstrlen(cmdLine) + 1; - argSpace = (char *) GlobalAlloc(GMEM_FIXED, argSpaceSize); + argSpaceSize = size * sizeof(TCHAR *) + lstrlen(cmdLine) + 1; + argSpace = (TCHAR *) GlobalAlloc(GMEM_FIXED, argSpaceSize); if (!argSpace) return 0; - *argv = (char **) argSpace; - argSpace += size * sizeof(char *); + *argv = (TCHAR **) argSpace; + argSpace += size * sizeof(TCHAR *); size--; p = cmdLine; for (*argc = 0; *argc < size; (*argc)++) { (*argv)[*argc] = arg = argSpace; - while ((*p == ' ') || (*p == '\t')) { + while ((*p == _T(' ')) || (*p == _T('\t'))) { p++; } - if (*p == '\0') { + if (*p == _T('\0')) { break; } @@ -75,14 +77,14 @@ int SetArgv(const char *cmdLine, int *argc, char ***argv) slashes = 0; while (1) { copy = 1; - while (*p == '\\') { + while (*p == _T('\\')) { slashes++; p++; } - if (*p == '"') { + if (*p == _T('"')) { if ((slashes & 1) == 0) { copy = 0; - if ((inquote) && (p[1] == '"')) { + if ((inquote) && (p[1] == _T('"'))) { p++; copy = 1; } @@ -94,12 +96,12 @@ int SetArgv(const char *cmdLine, int *argc, char ***argv) } while (slashes) { - *arg = '\\'; + *arg = _T('\\'); arg++; slashes--; } - if ((*p == '\0') || (!inquote && ((*p == ' ') || (*p == '\t')))) { + if ((*p == _T('\0')) || (!inquote && ((*p == _T(' ')) || (*p == _T('\t'))))) { break; } if (copy != 0) { @@ -108,7 +110,7 @@ int SetArgv(const char *cmdLine, int *argc, char ***argv) } p++; } - *arg = '\0'; + *arg = _T('\0'); argSpace = arg + 1; } (*argv)[*argc] = NULL; @@ -116,10 +118,10 @@ int SetArgv(const char *cmdLine, int *argc, char ***argv) return argSpaceSize; } -void SetTitle(HWND hwnd,char *substr) { - char title[64]; - if (substr==NULL) wsprintf(title,"MakeNSISW"); - else wsprintf(title,"MakeNSISW - %s",substr); +void SetTitle(HWND hwnd,TCHAR *substr) { + TCHAR title[64]; + if (substr==NULL) wsprintf(title,_T("MakeNSISW")); + else wsprintf(title,_T("MakeNSISW - %s"),substr); SetWindowText(hwnd,title); } @@ -130,9 +132,9 @@ void SetBranding(HWND hwnd) { void CopyToClipboard(HWND hwnd) { if (!hwnd||!OpenClipboard(hwnd)) return; int len=SendDlgItemMessage(hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0); - HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE,len+1); + HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE,(len+1)*sizeof(TCHAR)); if (!mem) { CloseClipboard(); return; } - char *existing_text = (char *)GlobalLock(mem); + TCHAR *existing_text = (TCHAR *)GlobalLock(mem); if (!existing_text) { CloseClipboard(); return; } EmptyClipboard(); existing_text[0]=0; @@ -143,20 +145,20 @@ void CopyToClipboard(HWND hwnd) { } void ClearLog(HWND hwnd) { - SetDlgItemText(hwnd, IDC_LOGWIN, ""); + SetDlgItemText(hwnd, IDC_LOGWIN, _T("")); } -void LogMessage(HWND hwnd,const char *str) { +void LogMessage(HWND hwnd,const TCHAR *str) { SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_SETSEL, g_sdata.logLength, g_sdata.logLength); g_sdata.logLength += lstrlen(str); - SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_REPLACESEL, 0, (WPARAM)str); + SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_REPLACESEL, 0, (LPARAM)str); SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_SCROLLCARET, 0, 0); } -void ErrorMessage(HWND hwnd,const char *str) { +void ErrorMessage(HWND hwnd,const TCHAR *str) { if (!str) return; - char buf[1028]; - wsprintf(buf,"[Error] %s\r\n",str); + TCHAR buf[1028]; + wsprintf(buf,_T("[Error] %s\r\n"),str); LogMessage(hwnd,buf); } @@ -218,7 +220,7 @@ void Items(HWND hwnd, int on){ void SetCompressorStats() { DWORD line_count, i; - char buf[1024]; + TCHAR buf[1024]; bool found = false; line_count = SendDlgItemMessage(g_sdata.hwnd, IDC_LOGWIN, EM_GETLINECOUNT, 0, 0); @@ -237,7 +239,7 @@ void SetCompressorStats() DWORD len = lstrlen(EXE_HEADER_COMPRESSOR_STAT); if(!lstrncmp(buf,EXE_HEADER_COMPRESSOR_STAT,len)) { found = true; - lstrcpy(g_sdata.compressor_stats,"\n\n"); + lstrcpy(g_sdata.compressor_stats,_T("\n\n")); lstrcat(g_sdata.compressor_stats,buf); } } @@ -245,7 +247,7 @@ void SetCompressorStats() } void CompileNSISScript() { - static char *s; + static TCHAR *s; DragAcceptFiles(g_sdata.hwnd,FALSE); ClearLog(g_sdata.hwnd); SetTitle(g_sdata.hwnd,NULL); @@ -270,31 +272,31 @@ void CompileNSISScript() { } if (!g_sdata.compile_command) { if (s) GlobalFree(s); - char *symbols = BuildSymbols(); + TCHAR *symbols = BuildSymbols(); - char compressor[40]; + TCHAR compressor[40]; if(lstrlen(g_sdata.compressor_name)) { - wsprintf(compressor,"/X\"SetCompressor /FINAL %s\"",g_sdata.compressor_name); + wsprintf(compressor,_T("/X\"SetCompressor /FINAL %s\""),g_sdata.compressor_name); } else { - lstrcpy(compressor,""); + lstrcpy(compressor,_T("")); } - char *args = (char *) GlobalLock(g_sdata.script_cmd_args); + TCHAR *args = (TCHAR *) GlobalLock(g_sdata.script_cmd_args); g_sdata.compile_command = (char *) GlobalAlloc( GPTR, - /* makensis.exe */ sizeof(EXENAME) + /* space */ 1 + + /* makensis.exe */ _countof(EXENAME) + /* space */ 1 + /* script path */ lstrlen(g_sdata.script) + /* space */ 1 + /* script cmd args */ lstrlen(args) + /* space */ 1 + /* defines /Dblah=... */ lstrlen(symbols) + /* space */ 1 + /* /XSetCompressor... */ lstrlen(compressor) + /* space */ 1 + - /* /NOTTIFYHWND + HWND */ sizeof("/NOTIFYHWND -4294967295") + /* space */ 1 - ); + /* /NOTTIFYHWND + HWND */ _countof(_T("/NOTIFYHWND -4294967295")) + /* space */ 1 + ); wsprintf( g_sdata.compile_command, - "%s %s %s /NOTIFYHWND %d %s -- \"%s\"", + _T("%s %s %s /NOTIFYHWND %d %s -- \"%s\""), EXENAME, compressor, symbols, @@ -343,7 +345,7 @@ void RestoreWindowPos(HWND hwnd) { if (OpenRegSettingsKey(hKey)) { DWORD l = sizeof(p); DWORD t; - if ((RegQueryValueEx(hKey,REGLOC,NULL,&t,(unsigned char*)&p,&l)==ERROR_SUCCESS)&&(t == REG_BINARY)&&(l==sizeof(p))) { + if ((RegQueryValueEx(hKey,REGLOC,NULL,&t,(LPBYTE)&p,&l)==ERROR_SUCCESS)&&(t == REG_BINARY)&&(l==sizeof(p))) { int width, height; int windowWidth, windowHeight; @@ -391,7 +393,7 @@ void SaveWindowPos(HWND hwnd) { p.length = sizeof(p); GetWindowPlacement(hwnd, &p); if (OpenRegSettingsKey(hKey, true)) { - RegSetValueEx(hKey,REGLOC,0,REG_BINARY,(unsigned char*)&p,sizeof(p)); + RegSetValueEx(hKey,REGLOC,0,REG_BINARY,(LPBYTE)&p,sizeof(p)); RegCloseKey(hKey); } } @@ -406,34 +408,34 @@ void SaveSymbols() SaveSymbolSet(NULL, g_sdata.symbols); } -void DeleteSymbolSet(char *name) +void DeleteSymbolSet(TCHAR *name) { if(name) { HKEY hKey; if (OpenRegSettingsKey(hKey)) { - char subkey[1024]; - wsprintf(subkey,"%s\\%s",REGSYMSUBKEY,name); + TCHAR subkey[1024]; + wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name); RegDeleteKey(hKey,subkey); RegCloseKey(hKey); } } } -char** LoadSymbolSet(char *name) +TCHAR** LoadSymbolSet(TCHAR *name) { HKEY hKey; HKEY hSubKey; - char **symbols = NULL; + TCHAR **symbols = NULL; if (OpenRegSettingsKey(hKey)) { - char subkey[1024]; + TCHAR subkey[1024]; if(name) { - wsprintf(subkey,"%s\\%s",REGSYMSUBKEY,name); + wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name); } else { lstrcpy(subkey,REGSYMSUBKEY); } if (RegCreateKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) { - char buf[8]; + TCHAR buf[8]; DWORD l; DWORD t; DWORD bufSize; @@ -446,16 +448,16 @@ char** LoadSymbolSet(char *name) if ((RegEnumValue(hSubKey,i, buf, &bufSize,NULL,&t,NULL,&l)==ERROR_SUCCESS)&&(t == REG_SZ)) { if(symbols) { GlobalUnlock(hMem); - hMem = GlobalReAlloc(hMem, (i+2)*sizeof(char *), GMEM_MOVEABLE|GMEM_ZEROINIT); - symbols = (char **)GlobalLock(hMem); + hMem = GlobalReAlloc(hMem, (i+2)*sizeof(TCHAR *), GMEM_MOVEABLE|GMEM_ZEROINIT); + symbols = (TCHAR **)GlobalLock(hMem); } else { - hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (i+2)*sizeof(char *)); - symbols = (char **)GlobalLock(hMem); + hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (i+2)*sizeof(TCHAR *)); + symbols = (TCHAR **)GlobalLock(hMem); } if(symbols) { l++; - symbols[i] = (char *)GlobalAlloc(GPTR, l*sizeof(char)); + symbols[i] = (TCHAR *)GlobalAlloc(GPTR, l*sizeof(TCHAR)); if (symbols[i]) { RegQueryValueEx(hSubKey,buf,NULL,&t,(unsigned char*)symbols[i],&l); } @@ -481,22 +483,22 @@ char** LoadSymbolSet(char *name) return symbols; } -void SaveSymbolSet(char *name, char **symbols) +void SaveSymbolSet(TCHAR *name, TCHAR **symbols) { HKEY hKey; HKEY hSubKey; int n = 0; if (OpenRegSettingsKey(hKey, true)) { - char subkey[1024]; + TCHAR subkey[1024]; if(name) { - wsprintf(subkey,"%s\\%s",REGSYMSUBKEY,name); + wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name); } else { lstrcpy(subkey,REGSYMSUBKEY); } if (RegOpenKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) { - char buf[8]; + TCHAR buf[8]; DWORD l; while(TRUE) { l = sizeof(buf); @@ -511,11 +513,11 @@ void SaveSymbolSet(char *name, char **symbols) } if(symbols) { if (RegCreateKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) { - char buf[8]; + TCHAR buf[8]; n = 0; while(symbols[n]) { - wsprintf(buf,"%d",n); - RegSetValueEx(hSubKey,buf,0,REG_SZ,(CONST BYTE *)symbols[n],lstrlen(symbols[n])+1); + wsprintf(buf,_T("%d"),n); + RegSetValueEx(hSubKey,buf,0,REG_SZ,(CONST BYTE *)symbols[n],(lstrlen(symbols[n])+1)*sizeof(TCHAR)); n++; } RegCloseKey(hSubKey); @@ -551,9 +553,9 @@ void ResetSymbols() { } int InitBranding() { - char *s; - s = (char *)GlobalAlloc(GPTR,lstrlen(EXENAME)+10); - wsprintf(s,"%s /version",EXENAME); + TCHAR *s; + s = (TCHAR *)GlobalAlloc(GPTR,lstrlen(EXENAME)+10); + wsprintf(s,_T("%s /version"),EXENAME); { STARTUPINFO si={sizeof(si),}; SECURITY_ATTRIBUTES sa={sizeof(sa),}; @@ -583,7 +585,7 @@ int InitBranding() { CloseHandle(read_stdout); return 0; } - char szBuf[1024]; + TCHAR szBuf[1024]; DWORD dwRead = 1; if (WaitForSingleObject(pi.hProcess,10000)!=WAIT_OBJECT_0) { return 0; @@ -591,9 +593,9 @@ int InitBranding() { ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL); szBuf[dwRead] = 0; if (lstrlen(szBuf)==0) return 0; - g_sdata.branding = (char *)GlobalAlloc(GPTR,lstrlen(szBuf)+6); - wsprintf(g_sdata.branding,"NSIS %s",szBuf); - g_sdata.brandingv = (char *)GlobalAlloc(GPTR,lstrlen(szBuf)+1); + g_sdata.branding = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(szBuf)+6)*sizeof(TCHAR)); + wsprintf(g_sdata.branding,_T("NSIS %s"),szBuf); + g_sdata.brandingv = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(szBuf)+1)*sizeof(TCHAR)); lstrcpy(g_sdata.brandingv,szBuf); GlobalFree(s); } @@ -613,8 +615,8 @@ void InitTooltips(HWND h) { g_tip.tip = CreateWindowEx(dwExStyle,TOOLTIPS_CLASS,NULL,dwStyle,0,0,0,0,h,NULL,GetModuleHandle(NULL),NULL); if (!g_tip.tip) return; g_tip.hook = SetWindowsHookEx(WH_GETMESSAGE,TipHookProc,NULL, GetCurrentThreadId()); - AddTip(GetDlgItem(h,IDCANCEL),TEXT("Close MakeNSISW")); - AddTip(GetDlgItem(h,IDC_TEST),TEXT("Test the installer generated by MakeNSISW")); + AddTip(GetDlgItem(h,IDCANCEL),_T("Close MakeNSISW")); + AddTip(GetDlgItem(h,IDC_TEST),_T("Test the installer generated by MakeNSISW")); AddToolBarTooltips(); } @@ -622,7 +624,7 @@ void DestroyTooltips() { UnhookWindowsHookEx(g_tip.hook); } -void AddTip(HWND hWnd,LPSTR lpszToolTip) { +void AddTip(HWND hWnd,LPTSTR lpszToolTip) { TOOLINFO ti; ti.cbSize = sizeof(TOOLINFO); ti.uFlags = TTF_IDISHWND; @@ -646,44 +648,44 @@ LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam) { } void ShowDocs() { - char pathf[MAX_PATH],*path; + TCHAR pathf[MAX_PATH],*path; GetModuleFileName(NULL,pathf,sizeof(pathf)); - path=my_strrchr(pathf,'\\'); + path=my_strrchr(pathf,_T('\\')); if(path!=NULL) *path=0; lstrcat(pathf,LOCALDOCS); - if ((int)ShellExecute(g_sdata.hwnd,"open",pathf,NULL,NULL,SW_SHOWNORMAL)<=32) - ShellExecute(g_sdata.hwnd,"open",DOCPATH,NULL,NULL,SW_SHOWNORMAL); + if ((int)ShellExecute(g_sdata.hwnd,_T("open"),pathf,NULL,NULL,SW_SHOWNORMAL)<=32) + ShellExecuteA(g_sdata.hwnd,"open",DOCPATH,NULL,NULL,SW_SHOWNORMAL); } -char* BuildSymbols() +TCHAR* BuildSymbols() { - char *buf = NULL; + TCHAR *buf = NULL; if(g_sdata.symbols) { int i=0; while(g_sdata.symbols[i]) { if(buf) { - char *buf3 = (char *)GlobalAlloc(GPTR,(lstrlen(buf)+lstrlen(g_sdata.symbols[i])+6)*sizeof(char)); - wsprintf(buf3,"%s \"/D%s\"",buf,g_sdata.symbols[i]); + TCHAR *buf3 = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(buf)+lstrlen(g_sdata.symbols[i])+6)*sizeof(TCHAR)); + wsprintf(buf3,_T("%s \"/D%s\""),buf,g_sdata.symbols[i]); GlobalFree(buf); buf = buf3; } else { - buf = (char *)GlobalAlloc(GPTR,(lstrlen(g_sdata.symbols[i])+5)*sizeof(char)); - wsprintf(buf,"\"/D%s\"",g_sdata.symbols[i]); + buf = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(g_sdata.symbols[i])+5)*sizeof(TCHAR)); + wsprintf(buf,_T("\"/D%s\""),g_sdata.symbols[i]); } i++; } } else { - buf = (char *)GlobalAlloc(GPTR, sizeof(char)); - buf[0] = '\0'; + buf = (TCHAR *)GlobalAlloc(GPTR, sizeof(TCHAR)); + buf[0] = _T('\0'); } return buf; } -BOOL PopMRUFile(char* fname) +BOOL PopMRUFile(TCHAR* fname) { int i; @@ -698,7 +700,7 @@ BOOL PopMRUFile(char* fname) for(j = i; j < MRU_LIST_SIZE-1; j++) { lstrcpy(g_mru_list[j],g_mru_list[j+1]); } - g_mru_list[MRU_LIST_SIZE-1][0]='\0'; + g_mru_list[MRU_LIST_SIZE-1][0]=_T('\0'); return TRUE; } else { @@ -706,7 +708,7 @@ BOOL PopMRUFile(char* fname) } } -BOOL IsValidFile(char *fname) +BOOL IsValidFile(TCHAR *fname) { WIN32_FIND_DATA wfd; HANDLE h; @@ -719,19 +721,19 @@ BOOL IsValidFile(char *fname) return false; } -void PushMRUFile(char* fname) +void PushMRUFile(TCHAR* fname) { int i; DWORD rv; - char* file_part; - char full_file_name[MAX_PATH+1]; + TCHAR* file_part; + TCHAR full_file_name[MAX_PATH+1]; - if(!fname || fname[0] == '\0' || fname[0] == '/' || fname[0] == '-') { + if(!fname || fname[0] == _T('\0') || fname[0] == _T('/') || fname[0] == _T('-')) { return; } my_memset(full_file_name,0,sizeof(full_file_name)); - rv = GetFullPathName(fname,sizeof(full_file_name),full_file_name,&file_part); + rv = GetFullPathName(fname,_countof(full_file_name),full_file_name,&file_part); if (rv == 0) { return; } @@ -751,9 +753,9 @@ void BuildMRUMenus() HMENU hMenu = g_sdata.fileSubmenu; int i; MENUITEMINFO mii; - char buf[MRU_DISPLAY_LENGTH + 5/*number*/ + 1/*null*/]; - char buf2[MRU_DISPLAY_LENGTH - 6]; - char buf3[MRU_DISPLAY_LENGTH + 1]; + TCHAR buf[MRU_DISPLAY_LENGTH + 5/*number*/ + 1/*null*/]; + TCHAR buf2[MRU_DISPLAY_LENGTH - 6]; + TCHAR buf3[MRU_DISPLAY_LENGTH + 1]; int n; for(i = 0; i < MRU_LIST_SIZE; i++) { @@ -770,32 +772,32 @@ void BuildMRUMenus() mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE; mii.wID = IDM_MRU_FILE+i; mii.fType = MFT_STRING; - wsprintf(buf, "&%d ", i + 1); + wsprintf(buf, _T("&%d "), i + 1); if(lstrlen(g_mru_list[i]) > MRU_DISPLAY_LENGTH) { - char *p = my_strrchr(g_mru_list[i],'\\'); + TCHAR *p = my_strrchr(g_mru_list[i],_T('\\')); if(p) { p++; if(lstrlen(p) > MRU_DISPLAY_LENGTH - 7) { my_memset(buf2,0,sizeof(buf2)); lstrcpyn(buf2,p,MRU_DISPLAY_LENGTH - 9); - lstrcat(buf2,"..."); + lstrcat(buf2,_T("...")); lstrcpyn(buf3,g_mru_list[i],4); lstrcat(buf,buf3); - lstrcat(buf,"...\\"); + lstrcat(buf,_T("...\\")); lstrcat(buf,buf2); } else { lstrcpyn(buf3,g_mru_list[i],(MRU_DISPLAY_LENGTH - lstrlen(p) - 3)); lstrcat(buf,buf3); - lstrcat(buf,"...\\"); + lstrcat(buf,_T("...\\")); lstrcat(buf,p); } } else { lstrcpyn(buf3,g_mru_list[i],(MRU_DISPLAY_LENGTH-2)); lstrcat(buf,buf3); - lstrcat(buf,"..."); + lstrcat(buf,_T("...")); } } else { @@ -852,13 +854,13 @@ void RestoreMRUList() int i; if (OpenRegSettingsKey(hKey)) { if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) { - char buf[8]; + TCHAR buf[8]; DWORD l; for(int i=0; i #include // nsis plugin #include "MyMath.h" @@ -15,12 +17,12 @@ int UserVarsCount, UserFuncsCount; UserVar UserVars[MAX_USER_VARS]; UserFunc UserFuncs[MAX_USER_FUNCS]; -void PrintTree(ExpressionItem *root, char *str); -void ParseString(char *&sp, ExpressionItem* &itemplace); +void PrintTree(ExpressionItem *root, TCHAR *str); +void ParseString(TCHAR *&sp, ExpressionItem* &itemplace); void CleanupItems(ExpressionItem* &itemplace); -void PlaceVariable(char *&vb, ParseInfo *pi); +void PlaceVariable(TCHAR *&vb, ParseInfo *pi); -void PlaceNewItem(char *&vb, ParseInfo *pi, int precedence) +void PlaceNewItem(TCHAR *&vb, ParseInfo *pi, int precedence) { ExpressionItem *newroot; PlaceVariable(vb, pi); @@ -56,12 +58,12 @@ void PlaceNewItem(char *&vb, ParseInfo *pi, int precedence) #define NSIS_VARS_STACK 25 #define NSIS_VARS_NSTACK 26 -typedef char smallstr[2]; -const smallstr NSISVariablesNames[NSIS_VARS_COUNT] = {{'r','0'}, {'r','1'}, {'r','2'}, {'r','3'}, {'r','4'}, {'r','5'}, {'r','6'}, {'r','7'}, {'r','8'}, {'r','9'}, -{'R','0'}, {'R','1'}, {'R','2'}, {'R','3'}, {'R','4'}, {'R','5'}, {'R','6'}, {'R','7'}, {'R','8'}, {'R','9'}, -{'C','L'}, {'I','D'}, {'O','D'}, {'E','D'}, {'L','G'}, {'S',0}, {'N','S'}}; +typedef TCHAR smallstr[2]; +const smallstr NSISVariablesNames[NSIS_VARS_COUNT] = {{_T('r'),_T('0')}, {_T('r'),_T('1')}, {_T('r'),_T('2')}, {_T('r'),_T('3')}, {_T('r'),_T('4')}, {_T('r'),_T('5')}, {_T('r'),_T('6')}, {_T('r'),_T('7')}, {_T('r'),_T('8')}, {_T('r'),_T('9')}, +{_T('R'),_T('0')}, {_T('R'),_T('1')}, {_T('R'),_T('2')}, {_T('R'),_T('3')}, {_T('R'),_T('4')}, {_T('R'),_T('5')}, {_T('R'),_T('6')}, {_T('R'),_T('7')}, {_T('R'),_T('8')}, {_T('R'),_T('9')}, +{_T('C'),_T('L')}, {_T('I'),_T('D')}, {_T('O'),_T('D')}, {_T('E'),_T('D')}, {_T('L'),_T('G')}, {_T('S'),0}, {_T('N'),_T('S')}}; -ExpressionItem *FindVariable(char *varname) +ExpressionItem *FindVariable(TCHAR *varname) { int i; @@ -98,7 +100,7 @@ ExpressionItem *FindVariable(char *varname) return item; } -void PlaceVariable(char *&vb, ParseInfo *pi) +void PlaceVariable(TCHAR *&vb, ParseInfo *pi) { if (vb <= pi->valbuf) return; *vb = 0; @@ -112,43 +114,43 @@ typedef double (*math_di)(double, int*); #define MATHFUNCNUM 29 const MathFunction MathFunctions[MATHFUNCNUM] = { - {{'s','i','n'}, ITF_MATH1 >> 8, sin}, - {{'s','n','h'}, ITF_MATH1 >> 8, sinh}, - {{'a','s','n'}, ITF_MATH1 >> 8, asin}, - {{'c','o','s'}, ITF_MATH1 >> 8, cos}, - {{'c','s','h'}, ITF_MATH1 >> 8, cosh}, - {{'a','c','s'}, ITF_MATH1 >> 8, acos}, - {{'t','a','n'}, ITF_MATH1 >> 8, tan}, - {{'t','n','h'}, ITF_MATH1 >> 8, tanh}, - {{'a','t','n'}, ITF_MATH1 >> 8, atan}, - {{'a','b','s'}, ITF_MATH1 >> 8, fabs}, - {{'l','n',0}, ITF_MATH1 >> 8, log}, - {{'l','o','g'}, ITF_MATH1 >> 8, log10}, - {{'e','x','p'}, ITF_MATH1 >> 8, exp}, - {{'s','q','t'}, ITF_MATH1 >> 8, sqrt}, - {{'c','e','l'}, ITF_MATH1 >> 8, ceil}, - {{'f','l','r'}, ITF_MATH1 >> 8, floor}, + {{_T('s'),_T('i'),_T('n')}, ITF_MATH1 >> 8, sin}, + {{_T('s'),_T('n'),_T('h')}, ITF_MATH1 >> 8, sinh}, + {{_T('a'),_T('s'),_T('n')}, ITF_MATH1 >> 8, asin}, + {{_T('c'),_T('o'),_T('s')}, ITF_MATH1 >> 8, cos}, + {{_T('c'),_T('s'),_T('h')}, ITF_MATH1 >> 8, cosh}, + {{_T('a'),_T('c'),_T('s')}, ITF_MATH1 >> 8, acos}, + {{_T('t'),_T('a'),_T('n')}, ITF_MATH1 >> 8, tan}, + {{_T('t'),_T('n'),_T('h')}, ITF_MATH1 >> 8, tanh}, + {{_T('a'),_T('t'),_T('n')}, ITF_MATH1 >> 8, atan}, + {{_T('a'),_T('b'),_T('s')}, ITF_MATH1 >> 8, fabs}, + {{_T('l'),_T('n'),0}, ITF_MATH1 >> 8, log}, + {{_T('l'),_T('o'),_T('g')}, ITF_MATH1 >> 8, log10}, + {{_T('e'),_T('x'),_T('p')}, ITF_MATH1 >> 8, exp}, + {{_T('s'),_T('q'),_T('t')}, ITF_MATH1 >> 8, sqrt}, + {{_T('c'),_T('e'),_T('l')}, ITF_MATH1 >> 8, ceil}, + {{_T('f'),_T('l'),_T('r')}, ITF_MATH1 >> 8, floor}, - {{'a','t','2'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)atan2}, - {{'p','o','w'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)pow}, - {{'f','m','d'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)fmod}, + {{_T('a'),_T('t'),_T('2')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)atan2}, + {{_T('p'),_T('o'),_T('w')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)pow}, + {{_T('f'),_T('m'),_T('d')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)fmod}, // type conversions - {{'i',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_INT}, - {{'s',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_STRING}, - {{'f',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_FLOAT}, - {{'a',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY}, + {{_T('i'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_INT}, + {{_T('s'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_STRING}, + {{_T('f'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_FLOAT}, + {{_T('a'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY}, #define ITFT_CARRAY_ID 23 - {{'c','a',0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY}, - {{'f','f',0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_FLOATF}, - {{'l',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_LEN}, - {{'c',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_CHAR}, + {{_T('c'),_T('a'),0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY}, + {{_T('f'),_T('f'),0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_FLOATF}, + {{_T('l'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_LEN}, + {{_T('c'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_CHAR}, - {{'f','e','x'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_di)frexp}, - {{'m','d','f'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_ddp)modf}, + {{_T('f'),_T('e'),_T('x')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_di)frexp}, + {{_T('m'),_T('d'),_T('f')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_ddp)modf}, }; -void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) +void PlaceFunction(TCHAR *&vb, TCHAR *&sp, ParseInfo *pi, int redefine) { int i; ExpressionItem *item = pi->item = AllocItem(); @@ -163,7 +165,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) // get first argument sp++; ParseString(sp, *((ExpressionItem **)(&item->param1))); - if (*sp == ',') + if (*sp == _T(',')) { // get second argument sp++; @@ -185,7 +187,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) item->type = IT_FUNCTION | ITF_USER | i; // get arguments list ExpressionItem **newplace = ((ExpressionItem **)(&pi->item->param1)); - while (*sp != ')') + while (*sp != _T(')')) { *newplace = AllocItem(); (*newplace)->type = IT_EXPRESSION; @@ -203,7 +205,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) // it's user function define int flags = 0; - char buffer[128], *buf = buffer; + TCHAR buffer[128], *buf = buffer; // workaround for redefine flag - if the function already present, // it will be cleared and redefined @@ -219,10 +221,10 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) sp++; switch (*sp) { - case ' ': + case _T(' '): break; - case ',': - case ')': + case _T(','): + case _T(')'): if (buf > buffer) { *buf = 0; @@ -234,7 +236,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) flags <<= 1; } break; - case '&': + case _T('&'): flags |= 1; break; default: @@ -242,7 +244,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) break; } } - while (*sp != ')'); + while (*sp != _T(')')); // prepare flag for fast analisys for (i = 0; i < f->varsnum; i++) @@ -253,7 +255,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) } // find nearest round bracket - function body - while (*sp != '(' && *sp) sp++; + while (*sp != _T('(') && *sp) sp++; if (!*sp) return; sp++; @@ -265,17 +267,17 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) #ifdef _DEBUG // dump function (in debug mode) - char place[1024]; - wsprintf(place, "function %s(", f->name); + TCHAR place[1024]; + wsprintf(place, _T("function %s("), f->name); flags = f->varflags; for (i = 0; i < f->varsnum; i++) { - if (flags&1) lstrcat(place, "&"); + if (flags&1) lstrcat(place, _T("&")); lstrcat(place, UserVars[f->vars[i]].name); - if (i < f->varsnum-1) lstrcat(place, ", "); + if (i < f->varsnum-1) lstrcat(place, _T(", ")); flags >>= 1; } - lstrcat(place, ")"); + lstrcat(place, _T(")")); PrintTree(f->root, place); #endif } @@ -290,7 +292,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine) #define PO_USESPRE 0x40 // operator will use pre operand #define PO_USESPOST 0x80 // operator will use post operan -void PlaceOp(char *&vb, int type, int precedence, ParseInfo *pi) +void PlaceOp(TCHAR *&vb, int type, int precedence, ParseInfo *pi) { PlaceVariable(vb, pi); if ((type & PO_UNARYPRE) && (!pi->item)) @@ -332,54 +334,54 @@ void PlaceOp(char *&vb, int type, int precedence, ParseInfo *pi) const OpStruct Operators[OPSNUM] = { // three byte ops -{{'>','>','='}, 14, ITO_SHR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, -{{'<','<','='}, 14, ITO_SHL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{{_T('>'),_T('>'),_T('=')}, 14, ITO_SHR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{{_T('<'),_T('<'),_T('=')}, 14, ITO_SHL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, // two byte ops // !!! don't forget to change Set Operator Precedence !!! -{"-=", 14, ITO_MINUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, -{"+=", 14, ITO_PLUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, -{"/=", 14, ITO_DIV | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, -{"*=", 14, ITO_MUL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, -{"|=", 14, ITO_OR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, -{"&=", 14, ITO_AND | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, -{"^=", 14, ITO_XOR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, -{"%=", 14, ITO_MOD | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, -{"--", 2, ITO_DEC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST}, -{"++", 2, ITO_INC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST}, -{">>", 6, ITO_SHR | PO_USESPRE | PO_USESPOST}, -{"<<", 6, ITO_SHL | PO_USESPRE | PO_USESPOST}, +{_T("-="), 14, ITO_MINUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T("+="), 14, ITO_PLUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T("/="), 14, ITO_DIV | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T("*="), 14, ITO_MUL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T("|="), 14, ITO_OR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T("&="), 14, ITO_AND | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T("^="), 14, ITO_XOR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T("%="), 14, ITO_MOD | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T("--"), 2, ITO_DEC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T("++"), 2, ITO_INC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST}, +{_T(">>"), 6, ITO_SHR | PO_USESPRE | PO_USESPOST}, +{_T("<<"), 6, ITO_SHL | PO_USESPRE | PO_USESPOST}, // logical -{"&&", 12, ITO_LAND | PO_USESPRE | PO_USESPOST}, -{"||", 13, ITO_LOR | PO_USESPRE | PO_USESPOST}, +{_T("&&"), 12, ITO_LAND | PO_USESPRE | PO_USESPOST}, +{_T("||"), 13, ITO_LOR | PO_USESPRE | PO_USESPOST}, // comparisons -{"<=", 7, ITO_LE | PO_USESPRE | PO_USESPOST}, -{"=<", 7, ITO_LE | PO_USESPRE | PO_USESPOST}, -{">=", 7, ITO_GE | PO_USESPRE | PO_USESPOST}, -{"=>", 7, ITO_GE | PO_USESPRE | PO_USESPOST}, -{"!=", 8, ITO_NE | PO_USESPRE | PO_USESPOST}, -{"==", 8, ITO_EQ | PO_USESPRE | PO_USESPOST}, +{_T("<="), 7, ITO_LE | PO_USESPRE | PO_USESPOST}, +{_T("=<"), 7, ITO_LE | PO_USESPRE | PO_USESPOST}, +{_T(">="), 7, ITO_GE | PO_USESPRE | PO_USESPOST}, +{_T("=>"), 7, ITO_GE | PO_USESPRE | PO_USESPOST}, +{_T("!="), 8, ITO_NE | PO_USESPRE | PO_USESPOST}, +{_T("=="), 8, ITO_EQ | PO_USESPRE | PO_USESPOST}, // single byte ops // !!! don't forget to change Set Operator Precedence !!! -{"=", 14, ITO_SET | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPOST}, -{"+", 5, ITO_PLUS | PO_USESPRE | PO_USESPOST}, -{"-", 5, ITO_MINUS | PO_USESPRE | PO_USESPOST | PO_UNARYPRE}, -{"*", 4, ITO_MUL | PO_USESPRE | PO_USESPOST | PO_UNARYPRE}, -{"/", 4, ITO_DIV | PO_USESPRE | PO_USESPOST}, -{"%", 4, ITO_MOD | PO_USESPRE | PO_USESPOST}, -{"<", 7, ITO_LS | PO_USESPRE | PO_USESPOST}, -{">", 7, ITO_GR | PO_USESPRE | PO_USESPOST}, -{"&", 9, ITO_AND | PO_USESPRE | PO_USESPOST | PO_UNARYPRE}, -{"|", 11, ITO_OR | PO_USESPRE | PO_USESPOST}, -{"^", 10, ITO_XOR | PO_USESPRE | PO_USESPOST}, -{"~", 3, ITO_NOT | PO_USESPOST | PO_UNARYPRE}, -{"!", 3, ITO_LNOT |PO_USESPOST | PO_UNARYPRE} +{_T("="), 14, ITO_SET | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPOST}, +{_T("+"), 5, ITO_PLUS | PO_USESPRE | PO_USESPOST}, +{_T("-"), 5, ITO_MINUS | PO_USESPRE | PO_USESPOST | PO_UNARYPRE}, +{_T("*"), 4, ITO_MUL | PO_USESPRE | PO_USESPOST | PO_UNARYPRE}, +{_T("/"), 4, ITO_DIV | PO_USESPRE | PO_USESPOST}, +{_T("%"), 4, ITO_MOD | PO_USESPRE | PO_USESPOST}, +{_T("<"), 7, ITO_LS | PO_USESPRE | PO_USESPOST}, +{_T(">"), 7, ITO_GR | PO_USESPRE | PO_USESPOST}, +{_T("&"), 9, ITO_AND | PO_USESPRE | PO_USESPOST | PO_UNARYPRE}, +{_T("|"), 11, ITO_OR | PO_USESPRE | PO_USESPOST}, +{_T("^"), 10, ITO_XOR | PO_USESPRE | PO_USESPOST}, +{_T("~"), 3, ITO_NOT | PO_USESPOST | PO_UNARYPRE}, +{_T("!"), 3, ITO_LNOT |PO_USESPOST | PO_UNARYPRE} }; -void CheckForOperator(char *&sp, char *&vb, ParseInfo *pi) +void CheckForOperator(TCHAR *&sp, TCHAR *&vb, ParseInfo *pi) { for (int op = 0; op < OPSNUM; op++) { @@ -397,44 +399,44 @@ void CheckForOperator(char *&sp, char *&vb, ParseInfo *pi) } } -void ParseString(char *&sp, ExpressionItem* &itemplace) +void ParseString(TCHAR *&sp, ExpressionItem* &itemplace) { ParseInfo pi = {0, NULL, NULL, &itemplace, &itemplace}; int redefine = 0; - char *vb = pi.valbuf; + TCHAR *vb = pi.valbuf; // cycle until current expression end - while ((*sp != 0) && (*sp != ')') && (*sp != '}') && - (*sp != ']') && (*sp != ',')) + while ((*sp != 0) && (*sp != _T(')')) && (*sp != _T('}')) && + (*sp != _T(']')) && (*sp != _T(','))) { int processed = 1; switch (*sp) { - case ' ': - case '\t': + case _T(' '): + case _T('\t'): sp++; break; - case ';': + case _T(';'): // expression delimeter PlaceNewItem(vb, &pi, 255); if (*pi.root) pi.SetupNewRoot = 1; sp++; break; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'): + case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'): // variable & function names could contain numbers as non first chars if (vb > pi.valbuf) { processed = FALSE; break; } - case '\'': case '\"': case '`': + case _T('\''): case _T('\"'): case _T('`'): // constant meet pi.item = AllocItem(); StringToItem(sp, pi.item, STI_STRING | STI_FLOAT | STI_INT); break; - case '(': // start of function or expression + case _T('('): // start of function or expression if (vb > pi.valbuf) { // thats function @@ -444,14 +446,14 @@ void ParseString(char *&sp, ExpressionItem* &itemplace) // expression sp++; ParseString(sp, pi.item); - if (*sp == ')') sp++; + if (*sp == _T(')')) sp++; } redefine = 0; break; - case '#': // start of one of logical expresions + case _T('#'): // start of one of logical expresions sp++; - if ((*sp != '[') && (*sp != '{')) + if ((*sp != _T('[')) && (*sp != _T('{'))) { // function redefine flag redefine = 1; @@ -460,14 +462,14 @@ void ParseString(char *&sp, ExpressionItem* &itemplace) { pi.item = AllocItem(); // IF or WHILE - pi.item->type = ((*sp == '[')?(IT_LOGIC | ITL_IF):(IT_LOGIC | ITL_WHILE)); + pi.item->type = ((*sp == _T('['))?(IT_LOGIC | ITL_IF):(IT_LOGIC | ITL_WHILE)); // first expr - logic statement sp++; ParseString(sp, *((ExpressionItem **)(&pi.item->param1))); // ok, second expr - then, third - else statement.. others??? ExpressionItem **newplace = ((ExpressionItem **)(&pi.item->param2)); - while (*sp == ',') + while (*sp == _T(',')) { *newplace = AllocItem(); (*newplace)->type = IT_EXPRESSION; @@ -479,14 +481,14 @@ void ParseString(char *&sp, ExpressionItem* &itemplace) sp++; break; - case '[': + case _T('['): { // thats array access PlaceOp(vb, IT_ARRAY | ITA_ACCESS | PO_UNARYPOST, 1, &pi); sp++; // item index ParseString(sp, *(ExpressionItem **)&(pi.item->param2)); - if (*sp == ',') + if (*sp == _T(',')) { // two indexes - string access ExpressionItem *it = AllocItem(); @@ -502,7 +504,7 @@ void ParseString(char *&sp, ExpressionItem* &itemplace) } break; - case '{': // start of array define + case _T('{'): // start of array define { // array define - constists of array copy operator and array define itself @@ -516,7 +518,7 @@ void ParseString(char *&sp, ExpressionItem* &itemplace) ArrayDesc *ad = *((ArrayDesc**)&(ai->param1)); // parse array initializers - while (*sp != '}') + while (*sp != _T('}')) { sp++; ParseString(sp, ad->array[ad->count]); @@ -527,9 +529,9 @@ void ParseString(char *&sp, ExpressionItem* &itemplace) sp++; } break; - case '-': case '+': case '<': case '=': case '>': - case '/': case '*': case '~': case '^': case '!': - case '&': case '|': case '%': + case _T('-'): case _T('+'): case _T('<'): case _T('='): case _T('>'): + case _T('/'): case _T('*'): case _T('~'): case _T('^'): case _T('!'): + case _T('&'): case _T('|'): case _T('%'): CheckForOperator(sp, vb, &pi); break; @@ -594,8 +596,8 @@ void CleanupItems(ExpressionItem* &itemplace) #ifdef _DEBUG HANDLE myfile; -char *opsnames[] = {"", "-", "+", "<<", ">>", "*", "/", "=", "&&", "||", "++", "--", -"=<", ">=", "!=", "==", "<", ">", "&", "%", "|", "^", "~", "!"}; +TCHAR *opsnames[] = {_T(""), _T("-"), _T("+"), _T("<<"), _T(">>"), _T("*"), _T("/"), _T("="), _T("&&"), _T("||"), _T("++"), _T("--"), +_T("=<"), _T(">="), _T("!="), _T("=="), _T("<"), _T(">"), _T("&"), _T("%"), _T("|"), _T("^"), _T("~"), _T("!")}; void PrintNode(int index, int spaces, ExpressionItem* itemplace) { @@ -605,7 +607,7 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace) do { DWORD wrote; - char buffer[1024], *place = buffer; + TCHAR buffer[1024], *place = buffer; for (int k = 0; k < spaces; k++) *(place++) = 32; *place = 0; @@ -613,100 +615,100 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace) switch (item->type & ITEMTYPE) { case IT_EXPRESSION: - wsprintf(place, "Expression Place-Holder "); + wsprintf(place, _T("Expression Place-Holder ")); break; case IT_CONST: switch (item->type & ITEMSUBTYPE) { case ITC_STRING: - wsprintf(place, "String: \"%s\"", (char *) item->param1); + wsprintf(place, _T("String: \"%s\""), (TCHAR *) item->param1); break; case ITC_INT: - wsprintf(place, "Int: "); + wsprintf(place, _T("Int: ")); itoa64(*((__int64*)&(item->param1)), place+5); break; case ITC_FLOAT: - wsprintf(place, "Float: "); + wsprintf(place, _T("Float: ")); FloatFormat(place+7, *((double*)&(item->param1)), 6); break; case ITC_ARRAY: ArrayDesc *ad = (ArrayDesc*) item->param1; - wsprintf(place, "Array, ptr %08X, size %d, count %d, references %d", + wsprintf(place, _T("Array, ptr %08X, size %d, count %d, references %d"), ad->array, ad->size, ad->count, ad->references); break; } - strcat(place, " "); + _tcscat(place, _T(" ")); break; case IT_OPERATOR: - wsprintf(place, "Op: %s%s ", opsnames[(item->type & ITEMSUBTYPE) >> 8], (item->type & PO_SET)?("(=)"):("")); + wsprintf(place, _T("Op: %s%s "), opsnames[(item->type & ITEMSUBTYPE) >> 8], (item->type & PO_SET)?(_T("(=)")):(_T(""))); break; case IT_VARIABLE: switch (item->type & ITEMSUBTYPE) { case ITV_NSIS: { - char buffer[128]; + TCHAR buffer[128]; buffer[0] = NSISVariablesNames[item->type & ITEMOPTIONS][0]; buffer[1] = NSISVariablesNames[item->type & ITEMOPTIONS][1]; buffer[2] = 0; - wsprintf(place, "Var: %s (%d) ", + wsprintf(place, _T("Var: %s (%d) "), buffer, item->type & ITEMOPTIONS); } break; case ITV_USER: - wsprintf(place, "Var: %s (%d) ", UserVars[item->type & ITEMOPTIONS].name, item->type & ITEMOPTIONS); + wsprintf(place, _T("Var: %s (%d) "), UserVars[item->type & ITEMOPTIONS].name, item->type & ITEMOPTIONS); break; case ITV_STACK: - wsprintf(place, "Plugin Stack "); + wsprintf(place, _T("Plugin Stack ")); break; case ITV_NSTACK: - wsprintf(place, "NSIS Stack "); + wsprintf(place, _T("NSIS Stack ")); break; } break; case IT_LOGIC: if ((item->type & ITEMSUBTYPE) == ITL_IF) - wsprintf(place, "IF "); + wsprintf(place, _T("IF ")); else - wsprintf(place, "WHILE "); + wsprintf(place, _T("WHILE ")); break; case IT_FUNCTION: if (((item->type & ITEMSUBTYPE) == ITF_MATH1) || ((item->type & ITEMSUBTYPE) == ITF_MATH2) || ((item->type & ITEMSUBTYPE) == ITF_TYPE)) { - char buffer[128]; + TCHAR buffer[128]; buffer[0] = (MathFunctions[item->type &ITEMOPTIONS].name)[0]; buffer[1] = (MathFunctions[item->type &ITEMOPTIONS].name)[1]; buffer[2] = (MathFunctions[item->type &ITEMOPTIONS].name)[2]; buffer[3] = 0; - wsprintf(place, "Built-In Function %s() [%d] ", + wsprintf(place, _T("Built-In Function %s() [%d] "), buffer, item->type &ITEMOPTIONS); } else { UserFunc *f = &(UserFuncs[item->type & ITEMOPTIONS]); - wsprintf(place, "User Function: %s(", f->name); + wsprintf(place, _T("User Function: %s("), f->name); int flags = f->varflags; for (int i = 0; i < f->varsnum; i++) { - if (flags&1) lstrcat(place, "&"); + if (flags&1) lstrcat(place, _T("&")); lstrcat(place, UserVars[f->vars[i]].name); - if (i < f->varsnum-1) lstrcat(place, ", "); + if (i < f->varsnum-1) lstrcat(place, _T(", ")); flags >>= 1; } - lstrcat(place, ") "); + lstrcat(place, _T(") ")); } break; case IT_ARRAY: - wsprintf(place, "Array access [] "); + wsprintf(place, _T("Array access [] ")); break; } place += lstrlen(place); - wsprintf(place, "Addr: %08X Type: %08X Next: %08X Param1: %08X Param2: %08X", item, item->type, item->next, item->param1, item->param2); - lstrcat(place, "\n"); + wsprintf(place, _T("Addr: %08X Type: %08X Next: %08X Param1: %08X Param2: %08X"), item, item->type, item->next, item->param1, item->param2); + lstrcat(place, _T("\n")); WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL); if (((item->type & ITEMTYPE) != IT_CONST) && ((item->type & (ITEMTYPE|ITEMSUBTYPE)) != (IT_VARIABLE|ITV_ARRITEM))) { @@ -719,13 +721,13 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace) show = 1; if (show) { - wsprintf(place, "Sub1:\n"); + wsprintf(place, _T("Sub1:\n")); WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL); } PrintNode(1, spaces + 4, *((ExpressionItem**) &item->param1)); if (show) { - wsprintf(place, "Sub2:\n"); + wsprintf(place, _T("Sub2:\n")); WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL); } PrintNode(2, spaces + 4, *((ExpressionItem**) &item->param2)); @@ -743,12 +745,12 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace) } while (item != NULL); } -void PrintTree(ExpressionItem *root, char *str) +void PrintTree(ExpressionItem *root, TCHAR *str) { - myfile = CreateFile("d:\\math.debug", GENERIC_ALL, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, 0); + myfile = CreateFile(_T("d:\\math.debug"), GENERIC_ALL, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, 0); SetFilePointer(myfile, 0, NULL, FILE_END); - char buffer[1024]; DWORD wrote; - wsprintf(buffer, "New tree for \'%s\'\n", str); + TCHAR buffer[1024]; DWORD wrote; + wsprintf(buffer, _T("New tree for \'%s\'\n"), str); WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL); PrintNode(0, 4, root); @@ -776,7 +778,7 @@ void CopyArray(ExpressionItem *&item) void ItemToType(ExpressionItem* &item, int type) { - char *buffer, *bp; + TCHAR *buffer, *bp; if (item == NULL) return; int itemt = item->type & ITEMTYPE, oldtype = item->type & ITEMSUBTYPE; @@ -796,7 +798,7 @@ void ItemToType(ExpressionItem* &item, int type) *((double *)&(item->param1)) = (double) *((__int64 *)&(item->param1)); else { - bp = buffer = (char*) item->param1; + bp = buffer = (TCHAR*) item->param1; StringToItem(buffer, item, STI_FLOAT); dbgGlobalFree(bp); } @@ -806,7 +808,7 @@ void ItemToType(ExpressionItem* &item, int type) *((__int64 *)&(item->param1)) = (__int64) *((double *)&(item->param1)); else { - bp = buffer = (char*) item->param1; + bp = buffer = (TCHAR*) item->param1; StringToItem(buffer, item, STI_INT); dbgGlobalFree(bp); } @@ -814,7 +816,7 @@ void ItemToType(ExpressionItem* &item, int type) case ITC_ARRAY: if (oldtype == ITC_STRING) { - char *buf = (char*) item->param1; + TCHAR *buf = (TCHAR*) item->param1; int len = lstrlen(buf)+1; ExpressionItem *ni = AllocArray(lstrlen(buf)+1); ArrayDesc *ad = (ArrayDesc*) ni->param1; @@ -843,7 +845,7 @@ void SaveResult(ExpressionItem *var, ExpressionItem *result) case ITV_NSIS: { // store string result direct to NSIS variable - char *ptr = g_variables + varindex*g_stringsize; + TCHAR *ptr = g_variables + varindex*g_stringsize; ItemToString(ptr, result); } break; @@ -869,7 +871,7 @@ void SaveResult(ExpressionItem *var, ExpressionItem *result) break; case ITV_NSTACK: { - char *buf = AllocString(); + TCHAR *buf = AllocString(); ItemToString(buf, result); pushstring(buf); dbgGlobalFree(buf); @@ -912,7 +914,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) { // nsis result = AllocItem(); - char *variable = getuservariable(ioptions); + TCHAR *variable = getuservariable(ioptions); StringToItem(variable, result, options); } break; @@ -947,7 +949,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) case ITV_NSTACK: { // NSIS stack - char buffer[1024], *buf = buffer; + TCHAR buffer[1024], *buf = buffer; result = AllocItem(); popstring(buffer); StringToItem(buf, result, options); @@ -1111,8 +1113,8 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) case ITC_STRING: { int ir = -666; - char *i1 = (item1)?((char*)item1->param1):(NULL); - char *i2 = (item2)?((char*)item2->param1):(NULL); + TCHAR *i1 = (item1)?((TCHAR*)item1->param1):(NULL); + TCHAR *i2 = (item2)?((TCHAR*)item2->param1):(NULL); int sc = (i1 && i2)?(lstrcmp(i1, i2)):((i1)?(1):((i2)?(-1):(0))); switch (subtype) @@ -1277,7 +1279,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) result = AllocItem(); result->type = IT_CONST | ITC_STRING; result->param1 = (EIPARAM) AllocString(); - FloatFormat((char*) result->param1, value, format); + FloatFormat((TCHAR*) result->param1, value, format); CleanupItems(arg1); CleanupItems(arg2); } else if (newtype == FTT_LEN) { @@ -1297,7 +1299,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) if ((result->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST|ITC_STRING)) { // ok, that's string - int len = lstrlen((char*)result->param1); + int len = lstrlen((TCHAR*)result->param1); dbgGlobalFree((HGLOBAL) result->param1); *((__int64*)&(result->param1)) = (__int64) len; result->type = IT_CONST | ITC_INT; @@ -1309,7 +1311,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) if ((result->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST|ITC_STRING)) { // ok, that's string - convert first char to int - int chr = (*((char*)result->param1)) & 0xFF; + int chr = (*((TCHAR*)result->param1)) & 0xFF; dbgGlobalFree((HGLOBAL) result->param1); *((__int64*)&(result->param1)) = (__int64) chr; result->type = IT_CONST | ITC_INT; @@ -1320,8 +1322,8 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) // ok, that's int - convert to new string (char+0) int chr = (int) (*((__int64*)&(result->param1))) & 0xFF; result->param1 = (EIPARAM) AllocString(); - *((char*)result->param1) = (char) chr; - *((char*)(result->param1+1)) = (char) 0; + *((TCHAR*)result->param1) = (TCHAR) chr; + *((TCHAR*)(result->param1+1)) = (TCHAR) 0; result->type = IT_CONST | ITC_STRING; break; } else CleanupItems(result); @@ -1380,7 +1382,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) if ((aritem->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST | ITC_STRING)) { // argument is string - char *str = (char*)(aritem->param1); + TCHAR *str = (TCHAR*)(aritem->param1); int len = lstrlen(str); // have we two indexes or one? if ((*((ExpressionItem **) &(item->param2)))->type != IT_EXPRESSION) @@ -1428,7 +1430,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) if (pos2 >= len) pos2 = len-1; // copy string part - char* lpos = str + (pos2-pos1); + TCHAR* lpos = str + (pos2-pos1); while (str <= lpos) { *str = *(str + pos1); @@ -1490,11 +1492,11 @@ HINSTANCE g_hInstance; extern "C" void __declspec(dllexport) Script(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop, + TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { EXDLL_INIT(); - char *buffer = AllocString(), *buf = buffer; + TCHAR *buffer = AllocString(), *buf = buffer; ExpressionItem *root = NULL; // root of current tree // keep loaded to save user defined variables @@ -1552,7 +1554,7 @@ void CleanAll(int init) } } -extern "C" BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { g_hInstance = hInst; CleanAll(ul_reason_for_call == DLL_PROCESS_ATTACH); diff --git a/Contrib/Math/Source/Math.h b/Contrib/Math/Source/Math.h index 1dad1801..60c4049c 100644 --- a/Contrib/Math/Source/Math.h +++ b/Contrib/Math/Source/Math.h @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 08/22/2007 + #pragma once #include // nsis plugin @@ -23,7 +25,7 @@ HGLOBAL watchGlobalAlloc(UINT Flags, UINT size); #endif -char *AllocString(); +TCHAR *AllocString(); ExpressionItem *AllocItem(); ExpressionItem *AllocArray(int size); ExpressionItem *CopyItem(ExpressionItem *item, int NeedConst = 0); diff --git a/Contrib/Math/Source/MyMath.c b/Contrib/Math/Source/MyMath.c index eed587c5..3f8a843f 100644 --- a/Contrib/Math/Source/MyMath.c +++ b/Contrib/Math/Source/MyMath.c @@ -1,10 +1,12 @@ +// Unicode support by Jim Park -- 08/22/2007 + #include #include #include "MyMath.h" #include "Math.h" // Converts String to Int (Dec, Hex) or Float value -void StringToItem(char *&s, ExpressionItem *item, int options) +void StringToItem(TCHAR *&s, ExpressionItem *item, int options) { item->type = IT_CONST | ITC_INT; __int64 &v=*((__int64*)&(item->param1)); @@ -14,19 +16,19 @@ void StringToItem(char *&s, ExpressionItem *item, int options) if (!s) return; // String-value - if ((((options & (STI_FLOAT | STI_INT)) == 0) || *s == '\'' || *s == '\"' || *s == '`' || - ((*s != '+') && (*s != '-') && ((*s < '0') || (*s > '9')))) + if ((((options & (STI_FLOAT | STI_INT)) == 0) || *s == _T('\'') || *s == _T('\"') || *s == _T('`') || + ((*s != _T('+')) && (*s != _T('-')) && ((*s < _T('0')) || (*s > _T('9'))))) && (options & STI_STRING)) { // end of string char - char eol = 0; - if (*s == '\'' || *s == '\"' || *s == '`') eol = *s; + TCHAR eol = 0; + if (*s == _T('\'') || *s == _T('\"') || *s == _T('`')) eol = *s; else s--; item->type = IT_CONST | ITC_STRING; // allocate memory buffer for string - char *sp; - sp = *((char**)&(item->param1)) = AllocString(); + TCHAR *sp; + sp = *((TCHAR**)&(item->param1)) = AllocString(); while (*(++s) && (*s != eol)) { *(sp++) = *s; @@ -36,18 +38,18 @@ void StringToItem(char *&s, ExpressionItem *item, int options) } else { // strip leading spaces and tabs - while ((*s == ' ') || (*s == '\t')) s++; + while ((*s == _T(' ')) || (*s == _T('\t'))) s++; // Hex-value - if ((options & STI_INT) && *s == '0' && (s[1] == 'x' || s[1] == 'X')) + if ((options & STI_INT) && *s == _T('0') && (s[1] == _T('x') || s[1] == _T('X'))) { s++; - while (*(s+1) == '0') *s++; + while (*(s+1) == _T('0')) *s++; for (;;) { int c=*(++s); - if (c >= '0' && c <= '9') c-='0'; - else if (c >= 'a' && c <= 'f') c-='a'-10; - else if (c >= 'A' && c <= 'F') c-='A'-10; + if (c >= _T('0') && c <= _T('9')) c-=_T('0'); + else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10; + else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10; else break; v<<=4; v+=c; @@ -57,13 +59,13 @@ void StringToItem(char *&s, ExpressionItem *item, int options) else { int sign=0, numsignif = 0; - if (*s == '-') sign++; else s--; - while (*(s+1) == '0') *s++; + if (*s == _T('-')) sign++; else s--; + while (*(s+1) == _T('0')) *s++; for (;;) { - int c=*(++s) - '0'; numsignif++; + int c=*(++s) - _T('0'); numsignif++; if ((options & STI_FLOAT) && - ((c == ('e'-'0')) || (c==('E'-'0')) || (c==('.'-'0')) + ((c == (_T('e')-_T('0'))) || (c==(_T('E')-_T('0'))) || (c==(_T('.')-_T('0'))) || (numsignif > 18))) { // Switch to floating point conversion rountine @@ -74,16 +76,16 @@ void StringToItem(char *&s, ExpressionItem *item, int options) while ((c >= 0) && (c <= 9)) { d = d*10.0 + (double) c; - c=*(++s) - '0'; + c=*(++s) - _T('0'); } // sub-decimal part - if (c == ('.'-'0')) + if (c == (_T('.')-_T('0'))) { double pwr = 1.0, dec = 0.0; for (;;) { - c=*(++s) - '0'; + c=*(++s) - _T('0'); if ((c < 0) || (c > 9)) break; dec = dec*10.0 + (double) c; pwr *= 10.0; @@ -91,19 +93,19 @@ void StringToItem(char *&s, ExpressionItem *item, int options) d += dec/pwr; } // exponental part - if ((c == ('E'-'0')) || (c == ('e'-'0'))) + if ((c == (_T('E')-_T('0'))) || (c == (_T('e')-_T('0')))) { int expc = 0, esign = 0; s++; // detect exponential sign - if ((*s == '+') || (*s == '-')) - esign = (*s == '-'); + if ((*s == _T('+')) || (*s == _T('-'))) + esign = (*s == _T('-')); else s--; // detect exp value for (;;) { - c=*(++s) - '0'; + c=*(++s) - _T('0'); if ((c < 0) || (c > 9)) break; expc = expc*10 + c; } @@ -139,7 +141,7 @@ void StringToItem(char *&s, ExpressionItem *item, int options) } } -void ItemToString(char *sbuf, ExpressionItem *item) +void ItemToString(TCHAR *sbuf, ExpressionItem *item) { if ((item == NULL) || ((item->type & ITEMTYPE) != IT_CONST)) { @@ -151,7 +153,7 @@ void ItemToString(char *sbuf, ExpressionItem *item) { case ITC_STRING: { - char *ptr = *((char**)&(item->param1)); + TCHAR *ptr = *((TCHAR**)&(item->param1)); while (*(sbuf++) = *(ptr++)); } break; @@ -161,7 +163,7 @@ void ItemToString(char *sbuf, ExpressionItem *item) for (int index = 0; index < ad->count; index++) if ((ad->array[index]) && ((ad->array[index]->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST | ITC_INT))) - if ((*(sbuf++) = (char) *((__int64*)&(ad->array[index]->param1))) == 0) + if ((*(sbuf++) = (TCHAR) *((__int64*)&(ad->array[index]->param1))) == 0) break; } break; @@ -174,21 +176,21 @@ void ItemToString(char *sbuf, ExpressionItem *item) } } -void itoa64(__int64 i, char *buffer) +void itoa64(__int64 i, TCHAR *buffer) { - char buf[128], *b = buf; + TCHAR buf[128], *b = buf; if (i < 0) { - *(buffer++) = '-'; + *(buffer++) = _T('-'); i = -i; } - if (i == 0) *(buffer++) = '0'; + if (i == 0) *(buffer++) = _T('0'); else { while (i > 0) { - *(b++) = '0' + ((char) (i%10)); + *(b++) = _T('0') + ((TCHAR) (i%10)); i /= 10; } while (b > buf) *(buffer++) = *(--b); @@ -196,12 +198,12 @@ void itoa64(__int64 i, char *buffer) *buffer = 0; } -#define POS_INFINITY "#INF" -#define NEG_INFINITY "-#INF" +#define POS_INFINITY _T("#INF") +#define NEG_INFINITY _T("-#INF") -void FloatFormat(char *s, double value, int options) +void FloatFormat(TCHAR *s, double value, int options) { - char format[128]; + TCHAR format[128]; int prec = options & 0xF; *s = 0; @@ -217,25 +219,25 @@ void FloatFormat(char *s, double value, int options) if (options & FF_NOEXP) { - sprintf(format, "%%.%df", prec); + _stprintf(format, _T("%%.%df"), prec); } else if (options & FF_EXP) { - sprintf(format, "%%.%de", prec); + _stprintf(format, _T("%%.%de"), prec); } else if (options & FF_LEXP) { - sprintf(format, "%%.%dE", prec); + _stprintf(format, _T("%%.%dE"), prec); } else { - sprintf(format, "%%.%dg", prec); + _stprintf(format, _T("%%.%dg"), prec); } - sprintf(s, format, value); + _stprintf(s, format, value); } -int lstrcmpn(char *s1, const char *s2, int chars) +int lstrcmpn(TCHAR *s1, const TCHAR *s2, int chars) { while ((chars > 0) && (*s1) && (*s2) && (*(s1) == *(s2))) chars--, s1++, s2++; if ((chars == 0) || (*s1 == *s2)) return 0; diff --git a/Contrib/Math/Source/MyMath.h b/Contrib/Math/Source/MyMath.h index 5ed44aa8..74936d0c 100644 --- a/Contrib/Math/Source/MyMath.h +++ b/Contrib/Math/Source/MyMath.h @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 08/22/2007 + #pragma once #include @@ -97,13 +99,13 @@ typedef struct __ParseInfo ExpressionItem *OpsStack; ExpressionItem **place; ExpressionItem **root; - char valbuf[108]; + TCHAR valbuf[108]; } ParseInfo; #define OPERATOR_SET_PRECEDENCE 14 typedef struct __OpStruct { - char name[3]; + TCHAR name[3]; unsigned char precedence; unsigned short int type; } OpStruct; @@ -111,16 +113,16 @@ typedef struct __OpStruct #define MAX_USER_VARS 256 typedef struct __UserVar { - char name[28]; + TCHAR name[28]; ExpressionItem *item; } UserVar; #define MAX_USER_FUNCS 256 typedef struct __UserFunc { - char name[20]; - unsigned char vars[31]; - unsigned char varsnum; + TCHAR name[20]; + unsigned char vars[31]; // only used for indexing + unsigned char varsnum; // number of vars < 256 unsigned int varflags; ExpressionItem *root; } UserFunc; @@ -140,7 +142,7 @@ typedef double (*Math2dFuncPtr)(double arg, double *arg2); typedef struct __MathFunction { - char name[3]; + TCHAR name[3]; unsigned char type; Math1FuncPtr fptr; } MathFunction; @@ -159,8 +161,8 @@ typedef struct __MathFunction #define RTO_PREFFEREDTYPE 0xFF00 void RunTree(ExpressionItem *from, ExpressionItem* &result, int type); -void StringToItem(char *&sbuf, ExpressionItem *item, int options); -void ItemToString(char *sbuf, ExpressionItem *item); -void FloatFormat(char *sbuf, double value, int options); -void itoa64(__int64 i, char *buffer); -int lstrcmpn(char *s1, const char *s2, int chars); +void StringToItem(TCHAR *&sbuf, ExpressionItem *item, int options); +void ItemToString(TCHAR *sbuf, ExpressionItem *item); +void FloatFormat(TCHAR *sbuf, double value, int options); +void itoa64(__int64 i, TCHAR *buffer); +int lstrcmpn(TCHAR *s1, const TCHAR *s2, int chars); diff --git a/Contrib/Math/Source/plugin.c b/Contrib/Math/Source/plugin.c index 11a44568..57ac7dc1 100644 --- a/Contrib/Math/Source/plugin.c +++ b/Contrib/Math/Source/plugin.c @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 08/22/2007 + #include #include "MyMath.h" #include "Math.h" @@ -28,15 +30,15 @@ void watchGlobal() for (int i = 0; i < blocksnum; i++) if (blocks[i] != NULL) { - _RPT2(_CRT_WARN, "Memory leak %d at %8X\n", i, blocks[i]); + _RPT2(_CRT_WARN, _T("Memory leak %d at %8X\n"), i, blocks[i]); } } #endif -char *AllocString() +TCHAR *AllocString() { - return (char*) dbgGlobalAlloc(GPTR,g_stringsize); + return (TCHAR*) dbgGlobalAlloc(GPTR,g_stringsize*sizeof(TCHAR)); } ExpressionItem *AllocItem() @@ -82,7 +84,7 @@ ExpressionItem *CopyItem(ExpressionItem *citem, int NeedConst) if ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_STRING)) { item->param1 = (EIPARAM) AllocString(); - lstrcpy((LPSTR) item->param1, (LPSTR) citem->param1); + lstrcpy((LPTSTR) item->param1, (LPTSTR) citem->param1); } else if (((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_ARRAY)) || ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_VARIABLE | ITV_ARRITEM))) diff --git a/Contrib/NSIS Menu/SConscript b/Contrib/NSIS Menu/SConscript index 73f03c28..19f92bf4 100644 --- a/Contrib/NSIS Menu/SConscript +++ b/Contrib/NSIS Menu/SConscript @@ -1,38 +1,44 @@ target = "NSIS" +Import('BuildUtil env') files = Split(""" - nsismenu/nsismenu.cpp - nsismenu/nslinks.cpp + nsismenu/nsismenu.cpp + nsismenu/nslinks.cpp """) resources = Split(""" - nsismenu/nsisicon.ico + nsismenu/nsisicon.ico """) rc = 'nsismenu/nsismenu.rc' libs = Split(""" - advapi32 - comctl32 - gdi32 - shell32 - user32 - wxbase28 - wxmsw28_core - wxmsw28_html + advapi32 + comctl32 + gdi32 + shell32 + user32 """) +if env['UNICODE']: + libs.append(["wxbase28u", "wxmsw28u_core", "wxmsw28u_html"]) +else: + libs.append(["wxbase28", "wxmsw28_core", "wxmsw28_html"]) + html = Split(""" - #Menu/index.html + #Menu/index.html """) images = Split(""" - #Menu/images/header.gif - #Menu/images/line.gif - #Menu/images/site.gif + #Menu/images/line.gif + #Menu/images/site.gif """) -Import('BuildUtil env') + +if env['UNICODE']: + images.append("#Menu/images/Unicode/header.gif") +else: + images.append("#Menu/images/header.gif") import os from os.path import join @@ -40,56 +46,60 @@ from os.path import join if env['PLATFORM'] != 'win32' and WhereIs('wx-config') or \ env['PLATFORM'] == 'win32' and os.environ.has_key('WXWIN'): - # build + # build - if env['PLATFORM'] != 'win32': - rc = libs = [] + if env['PLATFORM'] != 'win32': + rc = libs = [] - nsis_menu = BuildUtil( - target, - files, - libs, - res = rc, - resources = resources, - flags = ['$MSVCRT_FLAG', '$EXCEPTION_FLAG'], - root_util = True, - cross_platform = True - ) + nsis_menu = BuildUtil( + target, + files, + libs, + res = rc, + resources = resources, + flags = ['$MSVCRT_FLAG', '$EXCEPTION_FLAG'], + root_util = True, + cross_platform = True + ) - # manifest + # manifest - if env.has_key('MSVS_VERSION'): - if float(env['MSVS_VERSION'].replace('Exp','')) >= 8.0: - manifest = env.SideEffect('%s.exe.manifest' % target, nsis_menu) - env.DistributeBin(manifest, alias='install-utils') + if env.has_key('MSVS_VERSION'): + if float(env['MSVS_VERSION'].replace('Exp','')) >= 8.0: + manifest = env.SideEffect('%s.exe.manifest' % target, nsis_menu) + env.DistributeBin(manifest, alias='install-utils') - # set directories + # set directories - if nsis_menu[0].env['PLATFORM'] == 'win32': - wxlib = [join(os.environ['WXWIN'], 'lib', 'vc_libnsis')] - wxinc = [ - join(os.environ['WXWIN'], 'include'), - join(os.environ['WXWIN'], 'lib', 'vc_libnsis', 'msw') - ] - nsis_menu[0].env.Append(LIBPATH = wxlib) - nsis_menu[0].env.Append(CPPPATH = wxinc) - else: - nsis_menu[0].env.ParseConfig('wx-config --cxxflags --libs') + if nsis_menu[0].env['PLATFORM'] == 'win32': + wxinc = [join(os.environ['WXWIN'], 'include')] - # install menu files + if env['UNICODE']: + wxlib = [join(os.environ['WXWIN'], 'lib', 'vc_libunsis')] + wxinc.append(join(os.environ['WXWIN'], 'lib', 'vc_libunsis', 'mswu')) + else: + wxlib = [join(os.environ['WXWIN'], 'lib', 'vc_libnsis')] + wxinc.append(join(os.environ['WXWIN'], 'lib', 'vc_libnsis', 'msw')) - env.DistributeMenu(html, alias='install-utils') - env.DistributeMenu(images, path='images', alias='install-utils') + nsis_menu[0].env.Append(LIBPATH = wxlib) + nsis_menu[0].env.Append(CPPPATH = wxinc) + else: + nsis_menu[0].env.ParseConfig('wx-config --cxxflags --libs') + + # install menu files + + env.DistributeMenu(html, alias='install-utils') + env.DistributeMenu(images, path='images', alias='install-utils') else: - - # no wxWidgets - def err(target, source, env): - if env['PLATFORM'] == 'win32': - print '*** error: WXWIN must be set to build NSIS Menu!' - else: - print '*** error: wx-config must be in the PATH to build NSIS Menu!' - return 1 + + # no wxWidgets + def err(target, source, env): + if env['PLATFORM'] == 'win32': + print '*** error: WXWIN must be set to build NSIS Menu!' + else: + print '*** error: wx-config must be in the PATH to build NSIS Menu!' + return 1 - cmd = env.Command(target, files, Action(err, '')) - env.Alias('NSIS Menu', cmd) + cmd = env.Command(target, files, Action(err, '')) + env.Alias('NSIS Menu', cmd) diff --git a/Contrib/NSIS Menu/nsismenu/nsismenu.cpp b/Contrib/NSIS Menu/nsismenu/nsismenu.cpp index d6b84ff2..9a5420ec 100644 --- a/Contrib/NSIS Menu/nsismenu/nsismenu.cpp +++ b/Contrib/NSIS Menu/nsismenu/nsismenu.cpp @@ -1,5 +1,8 @@ ///////////////////////////////////////////////////////////////////////////// // NSIS MENU +// +// Reviewed for Unicode support by Jim Park -- 08/23/2007 +// Basically, compiling wxWidgets as Unicode should do it. ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx/wx.h". @@ -100,7 +103,7 @@ private: // Create the main application window MyFrame *frame = new MyFrame(_("NSIS Menu"), - wxPoint(50, 50), wxSize(600 + wxSystemSettings::GetMetric(wxSYS_FRAMESIZE_X), 355 + wxSystemSettings::GetMetric(wxSYS_FRAMESIZE_X))); + wxPoint(50, 50), wxSize(600 + wxSystemSettings::GetMetric(wxSYS_FRAMESIZE_X), 365 + wxSystemSettings::GetMetric(wxSYS_FRAMESIZE_X))); // Show it and tell the application that it's our main window @@ -154,10 +157,10 @@ void MyFrame::OnLink(wxHtmlLinkEvent& event) if (e == NULL || e->LeftUp()) { const wxString href = event.GetLinkInfo().GetHref(); - if (href.Left(3).IsSameAs((const wxChar*)"EX:", false)) + if (href.Left(3).IsSameAs((const wxChar*) wxT("EX:"), false)) { wxString url = href.Mid(3); - if (url.Left(7).IsSameAs((const wxChar*)"http://", false) || url.Left(6).IsSameAs((const wxChar*)"irc://", false)) + if (url.Left(7).IsSameAs((const wxChar*) wxT("http://"), false) || url.Left(6).IsSameAs((const wxChar*) wxT("irc://"), false)) { ::wxLaunchDefaultBrowser(url); } diff --git a/Contrib/NSIS Menu/nsismenu/nslinks.cpp b/Contrib/NSIS Menu/nsismenu/nslinks.cpp index e5d3a067..3f17a0dc 100644 --- a/Contrib/NSIS Menu/nsismenu/nslinks.cpp +++ b/Contrib/NSIS Menu/nsismenu/nslinks.cpp @@ -2,9 +2,12 @@ // Name: src/html/m_links.cpp // Purpose: wxHtml module for links & anchors // Author: Vaclav Slavik -// RCS-ID: $Id: nslinks.cpp,v 1.1 2007/02/24 18:57:09 kichik Exp $ +// RCS-ID: $Id: nslinks.cpp,v 1.2 2007/03/08 01:47:14 pabs3 Exp $ // Copyright: (c) 1999 Vaclav Slavik // Licence: wxWindows licence +// +// Reviewed for Unicode support by Jim Park -- 08/23/2007 +// Basically, compiling wxWidgets as Unicode should do it. ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" @@ -60,10 +63,10 @@ TAG_HANDLER_BEGIN(A, "A") wxColour colour = m_WParser->GetLinkColor(); wxHtmlLinkInfo linkInfo(name, target); - if (name.Left(3).IsSameAs((const wxChar*)"EX:", false)) + if (name.Left(3).IsSameAs((const wxChar*) wxT("EX:"), false)) { wxString url = name.Mid(3); - if (!url.Left(7).IsSameAs((const wxChar*)"http://", false) && !url.Left(6).IsSameAs((const wxChar*)"irc://", false)) + if (!url.Left(7).IsSameAs((const wxChar*) wxT("http://"), false) && !url.Left(6).IsSameAs((const wxChar*) wxT("irc://"), false)) { wxString exePath = wxStandardPaths::Get().GetExecutablePath(); wxString path = ::wxPathOnly(exePath); diff --git a/Contrib/NSIS Menu/wx/setup.h b/Contrib/NSIS Menu/wx/setup.h index aa7f14de..af281272 100644 --- a/Contrib/NSIS Menu/wx/setup.h +++ b/Contrib/NSIS Menu/wx/setup.h @@ -7,6 +7,9 @@ // RCS-ID: $Id: setup0.h,v 1.246 2006/11/09 00:54:51 VZ Exp $ // Copyright: (c) Julian Smart // Licence: wxWindows licence +// +// Reviewed for Unicode support by Jim Park -- 08/01/2007 +// (This one is the ANSI version.) ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_SETUP_H_ diff --git a/Contrib/NSIS Menu/wx/wxbuild.bat b/Contrib/NSIS Menu/wx/wxbuild.bat index 0c29e84f..7651b041 100644 --- a/Contrib/NSIS Menu/wx/wxbuild.bat +++ b/Contrib/NSIS Menu/wx/wxbuild.bat @@ -1,12 +1,42 @@ +@echo off if not exist setup.h goto setup_error if not exist "%WXWIN%\build\msw\makefile.vc" goto error set OLDCD=%CD% cd /D "%WXWIN%\build\msw" +rem Save the old setup.h as old_setup.h in the starting dir. copy /y "%WXWIN%\include\wx\msw\setup.h" "%OLDCD%\old_setup.h" -copy /y "%OLDCD%\setup.h" "%WXWIN%\include\wx\msw\setup.h" + +if "%1" == "unicode" goto unicode +if "%1" == "ansi" goto ansi +:ansi +rem Ask if we want to delete this dir. +echo Deleting... rd /S ..\..\lib\vc_libnsis + +echo ### building ANSI version ### +rem Copy the ANSI version of setup.h to WXWIN setup. +copy /y "%OLDCD%\setup.h" "%WXWIN%\include\wx\msw\setup.h" +echo Deleting... rd /S vc_mswnsis -nmake -f makefile.vc CFG=nsis BUILD=release RUNTIME_LIBS=dynamic SHARED=0 UNICODE=0 WXUNIV=0 USE_OPENGL=0 USE_ODBC=0 USE_HTML=1 USE_XRC=0 +nmake -f makefile.vc CFG=nsis BUILD=release RUNTIME_LIBS=static SHARED=0 UNICODE=0 WXUNIV=0 USE_OPENGL=0 USE_ODBC=0 USE_HTML=1 USE_XRC=0 +if "%1" == "" goto unicode +if "%1" == "all" goto unicode +goto finish + +:unicode +rem Ask if we want to delete this dir. +echo Deleting... +rd /S ..\..\lib\vc_libunsis + +echo ### building UNICODE version ### +rem Copy the UNICODE version of setup.h to WXWIN setup. +copy /y "%OLDCD%\setup_unicode.h" "%WXWIN%\include\wx\msw\setup.h" +echo Deleting... +rd /S vc_mswunsis +nmake -f makefile.vc CFG=unsis BUILD=release RUNTIME_LIBS=static SHARED=0 UNICODE=1 WXUNIV=0 USE_OPENGL=0 USE_ODBC=0 USE_HTML=1 USE_XRC=0 + +:finish +rem Restore the setup.h copy /y "%OLDCD%\old_setup.h" "%WXWIN%\include\wx\msw\setup.h" cd /D "%OLDCD%" goto done diff --git a/Contrib/NSISdl/asyncdns.cpp b/Contrib/NSISdl/asyncdns.cpp index da3e4d3c..caa555bf 100644 --- a/Contrib/NSISdl/asyncdns.cpp +++ b/Contrib/NSISdl/asyncdns.cpp @@ -1,82 +1,86 @@ -/* -** JNetLib -** Copyright (C) 2000-2001 Nullsoft, Inc. -** Author: Justin Frankel -** File: asyncdns.cpp - JNL portable asynchronous DNS implementation -** License: see jnetlib.h -*/ - - -#include "netinc.h" -#include "util.h" -#include "asyncdns.h" - -JNL_AsyncDNS::JNL_AsyncDNS() -{ - m_thread=0; - m_addr=0; - m_hostname[0]=0; -} - -JNL_AsyncDNS::~JNL_AsyncDNS() -{ - wait_for_thread_death(); -} - -unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d) -{ - JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d; - struct hostent *hostentry; - hostentry=::gethostbyname(_this->m_hostname); - if (hostentry) - { - _this->m_addr=*((int*)hostentry->h_addr); - } - else - _this->m_addr=INADDR_NONE; - return 0; -} - -int JNL_AsyncDNS::resolve(char *hostname, unsigned long *addr) -{ - // return 0 on success, 1 on wait, -1 on unresolvable - unsigned long ip=inet_addr(hostname); - if (ip != INADDR_NONE) - { - *addr=ip; - return 0; - } - - if (lstrcmpi(m_hostname,hostname)) m_addr=0; - else if (m_addr == INADDR_NONE) - { - wait_for_thread_death(); - return -1; - } - else if (m_addr) - { - *addr=m_addr; - wait_for_thread_death(); - return 0; - } - lstrcpy(m_hostname,hostname); - - if (!m_thread) - { - DWORD id; - m_thread=CreateThread(NULL,0,_threadfunc,(LPVOID)this,0,&id); - if (!m_thread) return -1; - } - return 1; -} - -void JNL_AsyncDNS::wait_for_thread_death() -{ - if (m_thread) - { - WaitForSingleObject(m_thread,INFINITE); - CloseHandle(m_thread); - } - - m_thread=0; -} +/* +** JNetLib +** Copyright (C) 2000-2001 Nullsoft, Inc. +** Author: Justin Frankel +** File: asyncdns.cpp - JNL portable asynchronous DNS implementation +** License: see jnetlib.h +** +** Unicode support by Jim Park -- 08/24/2007 +*/ + +// Jim Park: For Unicode Support, all string functions must explicitly use +// ANSI versions if UNICODE is defined. + +#include "netinc.h" +#include "util.h" +#include "asyncdns.h" + +JNL_AsyncDNS::JNL_AsyncDNS() +{ + m_thread=0; + m_addr=0; + m_hostname[0]=0; +} + +JNL_AsyncDNS::~JNL_AsyncDNS() +{ + wait_for_thread_death(); +} + +unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d) +{ + JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d; + struct hostent *hostentry; + hostentry=::gethostbyname(_this->m_hostname); + if (hostentry) + { + _this->m_addr=*((int*)hostentry->h_addr); + } + else + _this->m_addr=INADDR_NONE; + return 0; +} + +int JNL_AsyncDNS::resolve(char *hostname, unsigned long *addr) +{ + // return 0 on success, 1 on wait, -1 on unresolvable + unsigned long ip=inet_addr(hostname); + if (ip != INADDR_NONE) + { + *addr=ip; + return 0; + } + + if (lstrcmpiA(m_hostname,hostname)) m_addr=0; + else if (m_addr == INADDR_NONE) + { + wait_for_thread_death(); + return -1; + } + else if (m_addr) + { + *addr=m_addr; + wait_for_thread_death(); + return 0; + } + lstrcpyA(m_hostname,hostname); + + if (!m_thread) + { + DWORD id; + m_thread=CreateThread(NULL,0,_threadfunc,(LPVOID)this,0,&id); + if (!m_thread) return -1; + } + return 1; +} + +void JNL_AsyncDNS::wait_for_thread_death() +{ + if (m_thread) + { + WaitForSingleObject(m_thread,INFINITE); + CloseHandle(m_thread); + } + + m_thread=0; +} diff --git a/Contrib/NSISdl/asyncdns.h b/Contrib/NSISdl/asyncdns.h index f99d3ef7..832b1ca4 100644 --- a/Contrib/NSISdl/asyncdns.h +++ b/Contrib/NSISdl/asyncdns.h @@ -1,39 +1,43 @@ -/* -** JNetLib -** Copyright (C) 2000-2001 Nullsoft, Inc. -** Author: Justin Frankel -** File: asyncdns.h - JNL portable asynchronous DNS interface -** License: see jnetlib.h -** -** Usage: -** 1. Create JNL_AsyncDNS object, optionally with the number of cache entries. -** 2. call resolve() to resolve a hostname into an address. The return value of -** resolve is 0 on success (host successfully resolved), 1 on wait (meaning -** try calling resolve() with the same hostname in a few hundred milliseconds -** or so), or -1 on error (i.e. the host can't resolve). -** 4. enjoy. -*/ - -#ifndef _ASYNCDNS_H_ -#define _ASYNCDNS_H_ - -class JNL_AsyncDNS -{ -public: - JNL_AsyncDNS(); - ~JNL_AsyncDNS(); - - int resolve(char *hostname, unsigned long *addr); // return 0 on success, 1 on wait, -1 on unresolvable - -private: - void wait_for_thread_death(); - - char m_hostname[256]; - unsigned long m_addr; - - HANDLE m_thread; - static unsigned long WINAPI _threadfunc(LPVOID _d); - -}; - -#endif //_ASYNCDNS_H_ +/* +** JNetLib +** Copyright (C) 2000-2001 Nullsoft, Inc. +** Author: Justin Frankel +** File: asyncdns.h - JNL portable asynchronous DNS interface +** License: see jnetlib.h +** +** Usage: +** 1. Create JNL_AsyncDNS object, optionally with the number of cache entries. +** 2. call resolve() to resolve a hostname into an address. The return value of +** resolve is 0 on success (host successfully resolved), 1 on wait (meaning +** try calling resolve() with the same hostname in a few hundred milliseconds +** or so), or -1 on error (i.e. the host can't resolve). +** 4. enjoy. +** +** Unicode support by Jim Park -- 08/24/2007 +*/ + +// Jim Park: Inet host name is strictly ANSI, no UNICODE for now. + +#ifndef _ASYNCDNS_H_ +#define _ASYNCDNS_H_ + +class JNL_AsyncDNS +{ +public: + JNL_AsyncDNS(); + ~JNL_AsyncDNS(); + + int resolve(char *hostname, unsigned long *addr); // return 0 on success, 1 on wait, -1 on unresolvable + +private: + void wait_for_thread_death(); + + char m_hostname[256]; + unsigned long m_addr; + + HANDLE m_thread; + static unsigned long WINAPI _threadfunc(LPVOID _d); + +}; + +#endif //_ASYNCDNS_H_ diff --git a/Contrib/NSISdl/connection.cpp b/Contrib/NSISdl/connection.cpp index b5426544..14c35dc8 100644 --- a/Contrib/NSISdl/connection.cpp +++ b/Contrib/NSISdl/connection.cpp @@ -1,445 +1,447 @@ -/* -** JNetLib -** Copyright (C) 2000-2001 Nullsoft, Inc. -** Author: Justin Frankel -** File: connection.cpp - JNL TCP connection implementation -** License: see jnetlib.h -*/ - -#include "netinc.h" -#include "util.h" -#include "connection.h" - - -JNL_Connection::JNL_Connection(JNL_AsyncDNS *dns, int sendbufsize, int recvbufsize) -{ - m_errorstr=""; - if (dns == JNL_CONNECTION_AUTODNS) - { - m_dns=new JNL_AsyncDNS(); - m_dns_owned=1; - } - else - { - m_dns=dns; - m_dns_owned=0; - } - m_recv_buffer_len=recvbufsize; - m_send_buffer_len=sendbufsize; - m_recv_buffer=(char*)malloc(m_recv_buffer_len); - m_send_buffer=(char*)malloc(m_send_buffer_len); - m_socket=-1; - m_remote_port=0; - m_state=STATE_NOCONNECTION; - m_recv_len=m_recv_pos=0; - m_send_len=m_send_pos=0; - m_host[0]=0; - memset(&m_saddr,0,sizeof(m_saddr)); -} - -void JNL_Connection::connect(int s, struct sockaddr_in *loc) -{ - close(1); - m_socket=s; - m_remote_port=0; - m_dns=NULL; - if (loc) m_saddr=*loc; - else memset(&m_saddr,0,sizeof(m_saddr)); - if (m_socket != -1) - { - SET_SOCK_BLOCK(m_socket,0); - m_state=STATE_CONNECTED; - } - else - { - m_errorstr="invalid socket passed to connect"; - m_state=STATE_ERROR; - } -} - -void JNL_Connection::connect(char *hostname, int port) -{ - close(1); - m_remote_port=(short)port; - m_socket=::socket(AF_INET,SOCK_STREAM,0); - if (m_socket==-1) - { - m_errorstr="creating socket"; - m_state=STATE_ERROR; - } - else - { - SET_SOCK_BLOCK(m_socket,0); - strncpy(m_host,hostname,sizeof(m_host)-1); - m_host[sizeof(m_host)-1]=0; - memset(&m_saddr,0,sizeof(m_saddr)); - if (!m_host[0]) - { - m_errorstr="empty hostname"; - m_state=STATE_ERROR; - } - else - { - m_state=STATE_RESOLVING; - m_saddr.sin_family=AF_INET; - m_saddr.sin_port=htons((unsigned short)port); - m_saddr.sin_addr.s_addr=inet_addr(hostname); - } - } -} - -JNL_Connection::~JNL_Connection() -{ - if (m_socket >= 0) - { - ::shutdown(m_socket, SHUT_RDWR); - ::closesocket(m_socket); - m_socket=-1; - } - free(m_recv_buffer); - free(m_send_buffer); - if (m_dns_owned) - { - delete m_dns; - } -} - -void JNL_Connection::run(int max_send_bytes, int max_recv_bytes, int *bytes_sent, int *bytes_rcvd) -{ - int bytes_allowed_to_send=(max_send_bytes<0)?m_send_buffer_len:max_send_bytes; - int bytes_allowed_to_recv=(max_recv_bytes<0)?m_recv_buffer_len:max_recv_bytes; - - if (bytes_sent) *bytes_sent=0; - if (bytes_rcvd) *bytes_rcvd=0; - - switch (m_state) - { - case STATE_RESOLVING: - if (m_saddr.sin_addr.s_addr == INADDR_NONE) - { - int a=m_dns?m_dns->resolve(m_host,(unsigned long int *)&m_saddr.sin_addr.s_addr):-1; - if (!a) { m_state=STATE_CONNECTING; } - else if (a == 1) - { - m_state=STATE_RESOLVING; - break; - } - else - { - m_errorstr="resolving hostname"; - m_state=STATE_ERROR; - return; - } - } - if (!::connect(m_socket,(struct sockaddr *)&m_saddr,16)) - { - m_state=STATE_CONNECTED; - } - else if (ERRNO!=EINPROGRESS) - { - m_errorstr="connecting to host"; - m_state=STATE_ERROR; - } - else { m_state=STATE_CONNECTING; } - break; - case STATE_CONNECTING: - { - fd_set f[3]; - FD_ZERO(&f[0]); - FD_ZERO(&f[1]); - FD_ZERO(&f[2]); - FD_SET(m_socket,&f[0]); - FD_SET(m_socket,&f[1]); - FD_SET(m_socket,&f[2]); - struct timeval tv; - memset(&tv,0,sizeof(tv)); - if (select(m_socket+1,&f[0],&f[1],&f[2],&tv)==-1) - { - m_errorstr="connecting to host (calling select())"; - m_state=STATE_ERROR; - } - else if (FD_ISSET(m_socket,&f[1])) - { - m_state=STATE_CONNECTED; - } - else if (FD_ISSET(m_socket,&f[2])) - { - m_errorstr="connecting to host"; - m_state=STATE_ERROR; - } - } - break; - case STATE_CONNECTED: - case STATE_CLOSING: - if (m_send_len>0 && bytes_allowed_to_send>0) - { - int len=m_send_buffer_len-m_send_pos; - if (len > m_send_len) len=m_send_len; - if (len > bytes_allowed_to_send) len=bytes_allowed_to_send; - if (len > 0) - { - int res=::send(m_socket,m_send_buffer+m_send_pos,len,0); - if (res==-1 && ERRNO != EWOULDBLOCK) - { -// m_state=STATE_CLOSED; -// return; - } - if (res>0) - { - bytes_allowed_to_send-=res; - if (bytes_sent) *bytes_sent+=res; - m_send_pos+=res; - m_send_len-=res; - } - } - if (m_send_pos>=m_send_buffer_len) - { - m_send_pos=0; - if (m_send_len>0) - { - len=m_send_buffer_len-m_send_pos; - if (len > m_send_len) len=m_send_len; - if (len > bytes_allowed_to_send) len=bytes_allowed_to_send; - int res=::send(m_socket,m_send_buffer+m_send_pos,len,0); - if (res==-1 && ERRNO != EWOULDBLOCK) - { -// m_state=STATE_CLOSED; - } - if (res>0) - { - bytes_allowed_to_send-=res; - if (bytes_sent) *bytes_sent+=res; - m_send_pos+=res; - m_send_len-=res; - } - } - } - } - if (m_recv_len m_recv_buffer_len-m_recv_len) len=m_recv_buffer_len-m_recv_len; - if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv; - if (len>0) - { - int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0); - if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK)) - { - m_state=STATE_CLOSED; - break; - } - if (res > 0) - { - bytes_allowed_to_recv-=res; - if (bytes_rcvd) *bytes_rcvd+=res; - m_recv_pos+=res; - m_recv_len+=res; - } - } - if (m_recv_pos >= m_recv_buffer_len) - { - m_recv_pos=0; - if (m_recv_len < m_recv_buffer_len) - { - len=m_recv_buffer_len-m_recv_len; - if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv; - if (len > 0) - { - int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0); - if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK)) - { - m_state=STATE_CLOSED; - break; - } - if (res > 0) - { - bytes_allowed_to_recv-=res; - if (bytes_rcvd) *bytes_rcvd+=res; - m_recv_pos+=res; - m_recv_len+=res; - } - } - } - } - } - if (m_state == STATE_CLOSING) - { - if (m_send_len < 1) m_state = STATE_CLOSED; - } - break; - default: break; - } -} - -void JNL_Connection::close(int quick) -{ - if (quick || m_state == STATE_RESOLVING || m_state == STATE_CONNECTING) - { - m_state=STATE_CLOSED; - if (m_socket >= 0) - { - ::shutdown(m_socket, SHUT_RDWR); - ::closesocket(m_socket); - } - m_socket=-1; - memset(m_recv_buffer,0,m_recv_buffer_len); - memset(m_send_buffer,0,m_send_buffer_len); - m_remote_port=0; - m_recv_len=m_recv_pos=0; - m_send_len=m_send_pos=0; - m_host[0]=0; - memset(&m_saddr,0,sizeof(m_saddr)); - } - else - { - if (m_state == STATE_CONNECTED) m_state=STATE_CLOSING; - } -} - -int JNL_Connection::send_bytes_in_queue(void) -{ - return m_send_len; -} - -int JNL_Connection::send_bytes_available(void) -{ - return m_send_buffer_len-m_send_len; -} - -int JNL_Connection::send(char *data, int length) -{ - if (length > send_bytes_available()) - { - return -1; - } - - int write_pos=m_send_pos+m_send_len; - if (write_pos >= m_send_buffer_len) - { - write_pos-=m_send_buffer_len; - } - - int len=m_send_buffer_len-write_pos; - if (len > length) - { - len=length; - } - - memcpy(m_send_buffer+write_pos,data,len); - if (length > len) - { - memcpy(m_send_buffer,data+len,length-len); - } - m_send_len+=length; - return 0; -} - -int JNL_Connection::send_string(char *line) -{ - return send(line,strlen(line)); -} - -int JNL_Connection::recv_bytes_available(void) -{ - return m_recv_len; -} - -int JNL_Connection::peek_bytes(char *data, int maxlength) -{ - if (maxlength > m_recv_len) - { - maxlength=m_recv_len; - } - int read_pos=m_recv_pos-m_recv_len; - if (read_pos < 0) - { - read_pos += m_recv_buffer_len; - } - int len=m_recv_buffer_len-read_pos; - if (len > maxlength) - { - len=maxlength; - } - memcpy(data,m_recv_buffer+read_pos,len); - if (len < maxlength) - { - memcpy(data+len,m_recv_buffer,maxlength-len); - } - - return maxlength; -} - -int JNL_Connection::recv_bytes(char *data, int maxlength) -{ - - int ml=peek_bytes(data,maxlength); - m_recv_len-=ml; - return ml; -} - -int JNL_Connection::getbfromrecv(int pos, int remove) -{ - int read_pos=m_recv_pos-m_recv_len + pos; - if (pos < 0 || pos > m_recv_len) return -1; - if (read_pos < 0) - { - read_pos += m_recv_buffer_len; - } - if (read_pos >= m_recv_buffer_len) - { - read_pos-=m_recv_buffer_len; - } - if (remove) m_recv_len--; - return m_recv_buffer[read_pos]; -} - -int JNL_Connection::recv_lines_available(void) -{ - int l=recv_bytes_available(); - int lcount=0; - int lastch=0; - int pos; - for (pos=0; pos < l; pos ++) - { - int t=getbfromrecv(pos,0); - if (t == -1) return lcount; - if ((t=='\r' || t=='\n') &&( - (lastch != '\r' && lastch != '\n') || lastch==t - )) lcount++; - lastch=t; - } - return lcount; -} - -int JNL_Connection::recv_line(char *line, int maxlength) -{ - if (maxlength > m_recv_len) maxlength=m_recv_len; - while (maxlength--) - { - int t=getbfromrecv(0,1); - if (t == -1) - { - *line=0; - return 0; - } - if (t == '\r' || t == '\n') - { - int r=getbfromrecv(0,0); - if ((r == '\r' || r == '\n') && r != t) getbfromrecv(0,1); - *line=0; - return 0; - } - *line++=(char)t; - } - return 1; -} - -unsigned long JNL_Connection::get_interface(void) -{ - if (m_socket==-1) return 0; - struct sockaddr_in sin; - memset(&sin,0,sizeof(sin)); - socklen_t len=16; - if (::getsockname(m_socket,(struct sockaddr *)&sin,&len)) return 0; - return (unsigned long) sin.sin_addr.s_addr; -} +/* +** JNetLib +** Copyright (C) 2000-2001 Nullsoft, Inc. +** Author: Justin Frankel +** File: connection.cpp - JNL TCP connection implementation +** License: see jnetlib.h +** +** Unicode support by Jim Park -- 08/24/2007 +*/ + +#include "netinc.h" +#include "util.h" +#include "connection.h" + + +JNL_Connection::JNL_Connection(JNL_AsyncDNS *dns, int sendbufsize, int recvbufsize) +{ + m_errorstr=""; + if (dns == JNL_CONNECTION_AUTODNS) + { + m_dns=new JNL_AsyncDNS(); + m_dns_owned=1; + } + else + { + m_dns=dns; + m_dns_owned=0; + } + m_recv_buffer_len=recvbufsize; + m_send_buffer_len=sendbufsize; + m_recv_buffer=(char*)malloc(m_recv_buffer_len); + m_send_buffer=(char*)malloc(m_send_buffer_len); + m_socket=-1; + m_remote_port=0; + m_state=STATE_NOCONNECTION; + m_recv_len=m_recv_pos=0; + m_send_len=m_send_pos=0; + m_host[0]=0; + memset(&m_saddr,0,sizeof(m_saddr)); +} + +void JNL_Connection::connect(int s, struct sockaddr_in *loc) +{ + close(1); + m_socket=s; + m_remote_port=0; + m_dns=NULL; + if (loc) m_saddr=*loc; + else memset(&m_saddr,0,sizeof(m_saddr)); + if (m_socket != -1) + { + SET_SOCK_BLOCK(m_socket,0); + m_state=STATE_CONNECTED; + } + else + { + m_errorstr="invalid socket passed to connect"; + m_state=STATE_ERROR; + } +} + +void JNL_Connection::connect(char *hostname, int port) +{ + close(1); + m_remote_port=(short)port; + m_socket=::socket(AF_INET,SOCK_STREAM,0); + if (m_socket==-1) + { + m_errorstr="creating socket"; + m_state=STATE_ERROR; + } + else + { + SET_SOCK_BLOCK(m_socket,0); + strncpy(m_host,hostname,sizeof(m_host)-1); + m_host[sizeof(m_host)-1]=0; + memset(&m_saddr,0,sizeof(m_saddr)); + if (!m_host[0]) + { + m_errorstr="empty hostname"; + m_state=STATE_ERROR; + } + else + { + m_state=STATE_RESOLVING; + m_saddr.sin_family=AF_INET; + m_saddr.sin_port=htons((unsigned short)port); + m_saddr.sin_addr.s_addr=inet_addr(hostname); + } + } +} + +JNL_Connection::~JNL_Connection() +{ + if (m_socket >= 0) + { + ::shutdown(m_socket, SHUT_RDWR); + ::closesocket(m_socket); + m_socket=-1; + } + free(m_recv_buffer); + free(m_send_buffer); + if (m_dns_owned) + { + delete m_dns; + } +} + +void JNL_Connection::run(int max_send_bytes, int max_recv_bytes, int *bytes_sent, int *bytes_rcvd) +{ + int bytes_allowed_to_send=(max_send_bytes<0)?m_send_buffer_len:max_send_bytes; + int bytes_allowed_to_recv=(max_recv_bytes<0)?m_recv_buffer_len:max_recv_bytes; + + if (bytes_sent) *bytes_sent=0; + if (bytes_rcvd) *bytes_rcvd=0; + + switch (m_state) + { + case STATE_RESOLVING: + if (m_saddr.sin_addr.s_addr == INADDR_NONE) + { + int a=m_dns?m_dns->resolve(m_host,(unsigned long int *)&m_saddr.sin_addr.s_addr):-1; + if (!a) { m_state=STATE_CONNECTING; } + else if (a == 1) + { + m_state=STATE_RESOLVING; + break; + } + else + { + m_errorstr="resolving hostname"; + m_state=STATE_ERROR; + return; + } + } + if (!::connect(m_socket,(struct sockaddr *)&m_saddr,16)) + { + m_state=STATE_CONNECTED; + } + else if (ERRNO!=EINPROGRESS) + { + m_errorstr="connecting to host"; + m_state=STATE_ERROR; + } + else { m_state=STATE_CONNECTING; } + break; + case STATE_CONNECTING: + { + fd_set f[3]; + FD_ZERO(&f[0]); + FD_ZERO(&f[1]); + FD_ZERO(&f[2]); + FD_SET(m_socket,&f[0]); + FD_SET(m_socket,&f[1]); + FD_SET(m_socket,&f[2]); + struct timeval tv; + memset(&tv,0,sizeof(tv)); + if (select(m_socket+1,&f[0],&f[1],&f[2],&tv)==-1) + { + m_errorstr="connecting to host (calling select())"; + m_state=STATE_ERROR; + } + else if (FD_ISSET(m_socket,&f[1])) + { + m_state=STATE_CONNECTED; + } + else if (FD_ISSET(m_socket,&f[2])) + { + m_errorstr="connecting to host"; + m_state=STATE_ERROR; + } + } + break; + case STATE_CONNECTED: + case STATE_CLOSING: + if (m_send_len>0 && bytes_allowed_to_send>0) + { + int len=m_send_buffer_len-m_send_pos; + if (len > m_send_len) len=m_send_len; + if (len > bytes_allowed_to_send) len=bytes_allowed_to_send; + if (len > 0) + { + int res=::send(m_socket,m_send_buffer+m_send_pos,len,0); + if (res==-1 && ERRNO != EWOULDBLOCK) + { +// m_state=STATE_CLOSED; +// return; + } + if (res>0) + { + bytes_allowed_to_send-=res; + if (bytes_sent) *bytes_sent+=res; + m_send_pos+=res; + m_send_len-=res; + } + } + if (m_send_pos>=m_send_buffer_len) + { + m_send_pos=0; + if (m_send_len>0) + { + len=m_send_buffer_len-m_send_pos; + if (len > m_send_len) len=m_send_len; + if (len > bytes_allowed_to_send) len=bytes_allowed_to_send; + int res=::send(m_socket,m_send_buffer+m_send_pos,len,0); + if (res==-1 && ERRNO != EWOULDBLOCK) + { +// m_state=STATE_CLOSED; + } + if (res>0) + { + bytes_allowed_to_send-=res; + if (bytes_sent) *bytes_sent+=res; + m_send_pos+=res; + m_send_len-=res; + } + } + } + } + if (m_recv_len m_recv_buffer_len-m_recv_len) len=m_recv_buffer_len-m_recv_len; + if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv; + if (len>0) + { + int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0); + if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK)) + { + m_state=STATE_CLOSED; + break; + } + if (res > 0) + { + bytes_allowed_to_recv-=res; + if (bytes_rcvd) *bytes_rcvd+=res; + m_recv_pos+=res; + m_recv_len+=res; + } + } + if (m_recv_pos >= m_recv_buffer_len) + { + m_recv_pos=0; + if (m_recv_len < m_recv_buffer_len) + { + len=m_recv_buffer_len-m_recv_len; + if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv; + if (len > 0) + { + int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0); + if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK)) + { + m_state=STATE_CLOSED; + break; + } + if (res > 0) + { + bytes_allowed_to_recv-=res; + if (bytes_rcvd) *bytes_rcvd+=res; + m_recv_pos+=res; + m_recv_len+=res; + } + } + } + } + } + if (m_state == STATE_CLOSING) + { + if (m_send_len < 1) m_state = STATE_CLOSED; + } + break; + default: break; + } +} + +void JNL_Connection::close(int quick) +{ + if (quick || m_state == STATE_RESOLVING || m_state == STATE_CONNECTING) + { + m_state=STATE_CLOSED; + if (m_socket >= 0) + { + ::shutdown(m_socket, SHUT_RDWR); + ::closesocket(m_socket); + } + m_socket=-1; + memset(m_recv_buffer,0,m_recv_buffer_len); + memset(m_send_buffer,0,m_send_buffer_len); + m_remote_port=0; + m_recv_len=m_recv_pos=0; + m_send_len=m_send_pos=0; + m_host[0]=0; + memset(&m_saddr,0,sizeof(m_saddr)); + } + else + { + if (m_state == STATE_CONNECTED) m_state=STATE_CLOSING; + } +} + +int JNL_Connection::send_bytes_in_queue(void) +{ + return m_send_len; +} + +int JNL_Connection::send_bytes_available(void) +{ + return m_send_buffer_len-m_send_len; +} + +int JNL_Connection::send(char *data, int length) +{ + if (length > send_bytes_available()) + { + return -1; + } + + int write_pos=m_send_pos+m_send_len; + if (write_pos >= m_send_buffer_len) + { + write_pos-=m_send_buffer_len; + } + + int len=m_send_buffer_len-write_pos; + if (len > length) + { + len=length; + } + + memcpy(m_send_buffer+write_pos,data,len); + if (length > len) + { + memcpy(m_send_buffer,data+len,length-len); + } + m_send_len+=length; + return 0; +} + +int JNL_Connection::send_string(char *line) +{ + return send(line,strlen(line)); +} + +int JNL_Connection::recv_bytes_available(void) +{ + return m_recv_len; +} + +int JNL_Connection::peek_bytes(char *data, int maxlength) +{ + if (maxlength > m_recv_len) + { + maxlength=m_recv_len; + } + int read_pos=m_recv_pos-m_recv_len; + if (read_pos < 0) + { + read_pos += m_recv_buffer_len; + } + int len=m_recv_buffer_len-read_pos; + if (len > maxlength) + { + len=maxlength; + } + memcpy(data,m_recv_buffer+read_pos,len); + if (len < maxlength) + { + memcpy(data+len,m_recv_buffer,maxlength-len); + } + + return maxlength; +} + +int JNL_Connection::recv_bytes(char *data, int maxlength) +{ + + int ml=peek_bytes(data,maxlength); + m_recv_len-=ml; + return ml; +} + +int JNL_Connection::getbfromrecv(int pos, int remove) +{ + int read_pos=m_recv_pos-m_recv_len + pos; + if (pos < 0 || pos > m_recv_len) return -1; + if (read_pos < 0) + { + read_pos += m_recv_buffer_len; + } + if (read_pos >= m_recv_buffer_len) + { + read_pos-=m_recv_buffer_len; + } + if (remove) m_recv_len--; + return m_recv_buffer[read_pos]; +} + +int JNL_Connection::recv_lines_available(void) +{ + int l=recv_bytes_available(); + int lcount=0; + int lastch=0; + int pos; + for (pos=0; pos < l; pos ++) + { + int t=getbfromrecv(pos,0); + if (t == -1) return lcount; + if ((t=='\r' || t=='\n') &&( + (lastch != '\r' && lastch != '\n') || lastch==t + )) lcount++; + lastch=t; + } + return lcount; +} + +int JNL_Connection::recv_line(char *line, int maxlength) +{ + if (maxlength > m_recv_len) maxlength=m_recv_len; + while (maxlength--) + { + int t=getbfromrecv(0,1); + if (t == -1) + { + *line=0; + return 0; + } + if (t == '\r' || t == '\n') + { + int r=getbfromrecv(0,0); + if ((r == '\r' || r == '\n') && r != t) getbfromrecv(0,1); + *line=0; + return 0; + } + *line++=(char)t; + } + return 1; +} + +unsigned long JNL_Connection::get_interface(void) +{ + if (m_socket==-1) return 0; + struct sockaddr_in sin; + memset(&sin,0,sizeof(sin)); + socklen_t len=16; + if (::getsockname(m_socket,(struct sockaddr *)&sin,&len)) return 0; + return (unsigned long) sin.sin_addr.s_addr; +} diff --git a/Contrib/NSISdl/connection.h b/Contrib/NSISdl/connection.h index d77e856c..caad53a3 100644 --- a/Contrib/NSISdl/connection.h +++ b/Contrib/NSISdl/connection.h @@ -1,135 +1,138 @@ -/* -** JNetLib -** Copyright (C) 2000-2001 Nullsoft, Inc. -** Author: Justin Frankel -** File: connection.h - JNL TCP connection interface -** License: see jnetlib.h -** -** Usage: -** 1. Create a JNL_Connection object, optionally specifying a JNL_AsyncDNS -** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto), -** and the send and receive buffer sizes. -** 2. Call connect() to have it connect to a host/port (the hostname will be -** resolved if possible). -** 3. call run() with the maximum send/recv amounts, and optionally parameters -** so you can tell how much has been send/received. You want to do this a lot, while: -** 4. check get_state() to check the state of the connection. The states are: -** JNL_Connection::STATE_ERROR -** - an error has occurred on the connection. the connection has closed, -** and you can no longer write to the socket (there still might be -** data in the receive buffer - use recv_bytes_available()). -** JNL_Connection::STATE_NOCONNECTION -** - no connection has been made yet. call connect() already! :) -** JNL_Connection::STATE_RESOLVING -** - the connection is still waiting for a JNL_AsycnDNS to resolve the -** host. -** JNL_Connection::STATE_CONNECTING -** - the asynchronous call to connect() is still running. -** JNL_Connection::STATE_CONNECTED -** - the connection has connected, all is well. -** JNL_Connection::STATE_CLOSING -** - the connection is closing. This happens after a call to close, -** without the quick parameter set. This means that the connection -** will close once the data in the send buffer is sent (data could -** still be being received when it would be closed). After it is -** closed, the state will transition to: -** JNL_Connection::STATE_CLOSED -** - the connection has closed, generally without error. There still -** might be data in the receieve buffer, use recv_bytes_available(). -** 5. Use send() and send_string() to send data. You can use -** send_bytes_in_queue() to see how much has yet to go out, or -** send_bytes_available() to see how much you can write. If you use send() -** or send_string() and not enough room is available, both functions will -** return error ( < 0) -** 6. Use recv() and recv_line() to get data. If you want to see how much data -** there is, use recv_bytes_available() and recv_lines_available(). If you -** call recv() and not enough data is available, recv() will return how much -** data was actually read. See comments at the function defs. -** -** 7. To close, call close(1) for a quick close, or close() for a close that will -** make the socket close after sending all the data sent. -** -** 8. delete ye' ol' object. -*/ - -#ifndef _CONNECTION_H_ -#define _CONNECTION_H_ - -#include "asyncdns.h" - -#define JNL_CONNECTION_AUTODNS ((JNL_AsyncDNS*)-1) - -class JNL_Connection -{ - public: - typedef enum - { - STATE_ERROR, - STATE_NOCONNECTION, - STATE_RESOLVING, - STATE_CONNECTING, - STATE_CONNECTED, - STATE_CLOSING, - STATE_CLOSED - } state; - - JNL_Connection(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int sendbufsize=8192, int recvbufsize=8192); - ~JNL_Connection(); - - void connect(char *hostname, int port); - void connect(int sock, struct sockaddr_in *loc=NULL); // used by the listen object, usually not needed by users. - - void run(int max_send_bytes=-1, int max_recv_bytes=-1, int *bytes_sent=NULL, int *bytes_rcvd=NULL); - int get_state() { return m_state; } - char *get_errstr() { return m_errorstr; } - - void close(int quick=0); - void flush_send(void) { m_send_len=m_send_pos=0; } - - int send_bytes_in_queue(void); - int send_bytes_available(void); - int send(char *data, int length); // returns -1 if not enough room - int send_string(char *line); // returns -1 if not enough room - - - int recv_bytes_available(void); - int recv_bytes(char *data, int maxlength); // returns actual bytes read - unsigned int recv_int(void); - int recv_lines_available(void); - int recv_line(char *line, int maxlength); // returns 0 if the line was terminated with a \r or \n, 1 if not. - // (i.e. if you specify maxlength=10, and the line is 12 bytes long - // it will return 1. or if there is no \r or \n and that's all the data - // the connection has.) - int peek_bytes(char *data, int maxlength); // returns bytes peeked - - unsigned long get_interface(void); // this returns the interface the connection is on - unsigned long get_remote(void) { return m_saddr.sin_addr.s_addr; } // remote host ip. - short get_remote_port(void) { return m_remote_port; } // this returns the remote port of connection - - protected: - int m_socket; - short m_remote_port; - char *m_recv_buffer; - char *m_send_buffer; - int m_recv_buffer_len; - int m_send_buffer_len; - - int m_recv_pos; - int m_recv_len; - int m_send_pos; - int m_send_len; - - struct sockaddr_in m_saddr; - char m_host[256]; - - JNL_AsyncDNS *m_dns; - int m_dns_owned; - - state m_state; - char *m_errorstr; - - int getbfromrecv(int pos, int remove); // used by recv_line* - -}; - -#endif // _Connection_H_ +/* +** JNetLib +** Copyright (C) 2000-2001 Nullsoft, Inc. +** Author: Justin Frankel +** File: connection.h - JNL TCP connection interface +** License: see jnetlib.h +** +** Usage: +** 1. Create a JNL_Connection object, optionally specifying a JNL_AsyncDNS +** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto), +** and the send and receive buffer sizes. +** 2. Call connect() to have it connect to a host/port (the hostname will be +** resolved if possible). +** 3. call run() with the maximum send/recv amounts, and optionally parameters +** so you can tell how much has been send/received. You want to do this a lot, while: +** 4. check get_state() to check the state of the connection. The states are: +** JNL_Connection::STATE_ERROR +** - an error has occurred on the connection. the connection has closed, +** and you can no longer write to the socket (there still might be +** data in the receive buffer - use recv_bytes_available()). +** JNL_Connection::STATE_NOCONNECTION +** - no connection has been made yet. call connect() already! :) +** JNL_Connection::STATE_RESOLVING +** - the connection is still waiting for a JNL_AsycnDNS to resolve the +** host. +** JNL_Connection::STATE_CONNECTING +** - the asynchronous call to connect() is still running. +** JNL_Connection::STATE_CONNECTED +** - the connection has connected, all is well. +** JNL_Connection::STATE_CLOSING +** - the connection is closing. This happens after a call to close, +** without the quick parameter set. This means that the connection +** will close once the data in the send buffer is sent (data could +** still be being received when it would be closed). After it is +** closed, the state will transition to: +** JNL_Connection::STATE_CLOSED +** - the connection has closed, generally without error. There still +** might be data in the receieve buffer, use recv_bytes_available(). +** 5. Use send() and send_string() to send data. You can use +** send_bytes_in_queue() to see how much has yet to go out, or +** send_bytes_available() to see how much you can write. If you use send() +** or send_string() and not enough room is available, both functions will +** return error ( < 0) +** 6. Use recv() and recv_line() to get data. If you want to see how much data +** there is, use recv_bytes_available() and recv_lines_available(). If you +** call recv() and not enough data is available, recv() will return how much +** data was actually read. See comments at the function defs. +** +** 7. To close, call close(1) for a quick close, or close() for a close that will +** make the socket close after sending all the data sent. +** +** 8. delete ye' ol' object. +** +** Unicode support by Jim Park -- 08/24/2007 +** Keep all the stuff here strictly ANSI. +*/ + +#ifndef _CONNECTION_H_ +#define _CONNECTION_H_ + +#include "asyncdns.h" + +#define JNL_CONNECTION_AUTODNS ((JNL_AsyncDNS*)-1) + +class JNL_Connection +{ + public: + typedef enum + { + STATE_ERROR, + STATE_NOCONNECTION, + STATE_RESOLVING, + STATE_CONNECTING, + STATE_CONNECTED, + STATE_CLOSING, + STATE_CLOSED + } state; + + JNL_Connection(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int sendbufsize=8192, int recvbufsize=8192); + ~JNL_Connection(); + + void connect(char *hostname, int port); + void connect(int sock, struct sockaddr_in *loc=NULL); // used by the listen object, usually not needed by users. + + void run(int max_send_bytes=-1, int max_recv_bytes=-1, int *bytes_sent=NULL, int *bytes_rcvd=NULL); + int get_state() { return m_state; } + char *get_errstr() { return m_errorstr; } + + void close(int quick=0); + void flush_send(void) { m_send_len=m_send_pos=0; } + + int send_bytes_in_queue(void); + int send_bytes_available(void); + int send(char *data, int length); // returns -1 if not enough room + int send_string(char *line); // returns -1 if not enough room + + + int recv_bytes_available(void); + int recv_bytes(char *data, int maxlength); // returns actual bytes read + unsigned int recv_int(void); + int recv_lines_available(void); + int recv_line(char *line, int maxlength); // returns 0 if the line was terminated with a \r or \n, 1 if not. + // (i.e. if you specify maxlength=10, and the line is 12 bytes long + // it will return 1. or if there is no \r or \n and that's all the data + // the connection has.) + int peek_bytes(char *data, int maxlength); // returns bytes peeked + + unsigned long get_interface(void); // this returns the interface the connection is on + unsigned long get_remote(void) { return m_saddr.sin_addr.s_addr; } // remote host ip. + short get_remote_port(void) { return m_remote_port; } // this returns the remote port of connection + + protected: + int m_socket; + short m_remote_port; + char *m_recv_buffer; + char *m_send_buffer; + int m_recv_buffer_len; + int m_send_buffer_len; + + int m_recv_pos; + int m_recv_len; + int m_send_pos; + int m_send_len; + + struct sockaddr_in m_saddr; + char m_host[256]; + + JNL_AsyncDNS *m_dns; + int m_dns_owned; + + state m_state; + char *m_errorstr; + + int getbfromrecv(int pos, int remove); // used by recv_line* + +}; + +#endif // _Connection_H_ diff --git a/Contrib/NSISdl/httpget.cpp b/Contrib/NSISdl/httpget.cpp index 8761e80f..837d9930 100644 --- a/Contrib/NSISdl/httpget.cpp +++ b/Contrib/NSISdl/httpget.cpp @@ -1,499 +1,501 @@ -/* -** JNetLib -** Copyright (C) 2000-2001 Nullsoft, Inc. -** Author: Justin Frankel -** File: httpget.cpp - JNL HTTP GET implementation -** License: see jnetlib.h -*/ - -#include "netinc.h" -#include "util.h" -#include "httpget.h" - - -JNL_HTTPGet::JNL_HTTPGet(JNL_AsyncDNS *dns, int recvbufsize, char *proxy) -{ - m_recvbufsize=recvbufsize; - m_dns=dns; - m_con=NULL; - m_http_proxylpinfo=0; - m_http_proxyhost=0; - m_http_proxyport=0; - if (proxy && *proxy) - { - char *p=(char*)malloc(strlen(proxy)+1); - if (p) - { - char *r=NULL; - strcpy(p,proxy); - do_parse_url(p,&m_http_proxyhost,&m_http_proxyport,&r,&m_http_proxylpinfo); - free(r); - free(p); - } - } - m_sendheaders=NULL; - reinit(); -} - -void JNL_HTTPGet::reinit() -{ - m_errstr=0; - m_recvheaders=NULL; - m_recvheaders_size=0; - m_http_state=0; - m_http_port=0; - m_http_url=0; - m_reply=0; - m_http_host=m_http_lpinfo=m_http_request=NULL; -} - -void JNL_HTTPGet::deinit() -{ - delete m_con; - free(m_recvheaders); - - free(m_http_url); - free(m_http_host); - free(m_http_lpinfo); - free(m_http_request); - free(m_errstr); - free(m_reply); - reinit(); -} - -JNL_HTTPGet::~JNL_HTTPGet() -{ - deinit(); - free(m_sendheaders); - free(m_http_proxylpinfo); - free(m_http_proxyhost); - -} - - -void JNL_HTTPGet::addheader(char *header) -{ - //if (strstr(header,"\r") || strstr(header,"\n")) return; - if (!m_sendheaders) - { - m_sendheaders=(char*)malloc(strlen(header)+3); - if (m_sendheaders) - { - strcpy(m_sendheaders,header); - strcat(m_sendheaders,"\r\n"); - } - } - else - { - char *t=(char*)malloc(strlen(header)+strlen(m_sendheaders)+1+2); - if (t) - { - strcpy(t,m_sendheaders); - strcat(t,header); - strcat(t,"\r\n"); - free(m_sendheaders); - m_sendheaders=t; - } - } -} - -void JNL_HTTPGet::do_encode_mimestr(char *in, char *out) -{ - char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - int shift = 0; - int accum = 0; - - while (*in) - { - if (*in) - { - accum <<= 8; - shift += 8; - accum |= *in++; - } - while ( shift >= 6 ) - { - shift -= 6; - *out++ = alphabet[(accum >> shift) & 0x3F]; - } - } - if (shift == 4) - { - *out++ = alphabet[(accum & 0xF)<<2]; - *out++='='; - } - else if (shift == 2) - { - *out++ = alphabet[(accum & 0x3)<<4]; - *out++='='; - *out++='='; - } - - *out++=0; -} - - -void JNL_HTTPGet::connect(char *url) -{ - deinit(); - m_http_url=(char*)malloc(strlen(url)+1); - strcpy(m_http_url,url); - do_parse_url(m_http_url,&m_http_host,&m_http_port,&m_http_request, &m_http_lpinfo); - strcpy(m_http_url,url); - if (!m_http_host || !m_http_host[0] || !m_http_port) - { - m_http_state=-1; - seterrstr("invalid URL"); - return; - } - - int sendbufferlen=0; - - if (!m_http_proxyhost || !m_http_proxyhost[0]) - { - sendbufferlen += 4 /* GET */ + strlen(m_http_request) + 9 /* HTTP/1.0 */ + 2; - } - else - { - sendbufferlen += 4 /* GET */ + strlen(m_http_url) + 9 /* HTTP/1.0 */ + 2; - if (m_http_proxylpinfo&&m_http_proxylpinfo[0]) - { - sendbufferlen+=58+strlen(m_http_proxylpinfo)*2; // being safe here - } - } - sendbufferlen += 5 /* Host: */ + strlen(m_http_host) + 2; - - if (m_http_lpinfo&&m_http_lpinfo[0]) - { - sendbufferlen+=46+strlen(m_http_lpinfo)*2; // being safe here - } - - if (m_sendheaders) sendbufferlen+=strlen(m_sendheaders); - - char *str=(char*)malloc(sendbufferlen+1024); - if (!str) - { - seterrstr("error allocating memory"); - m_http_state=-1; - } - - if (!m_http_proxyhost || !m_http_proxyhost[0]) - { - wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_request); - } - else - { - wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_url); - } - - wsprintf(str+strlen(str),"Host: %s\r\n",m_http_host); - - if (m_http_lpinfo&&m_http_lpinfo[0]) - { - strcat(str,"Authorization: Basic "); - do_encode_mimestr(m_http_lpinfo,str+strlen(str)); - strcat(str,"\r\n"); - } - if (m_http_proxylpinfo&&m_http_proxylpinfo[0]) - { - strcat(str,"Proxy-Authorization: Basic "); - do_encode_mimestr(m_http_proxylpinfo,str+strlen(str)); - strcat(str,"\r\n"); - } - - if (m_sendheaders) strcat(str,m_sendheaders); - strcat(str,"\r\n"); - - int a=m_recvbufsize; - if (a < 4096) a=4096; - m_con=new JNL_Connection(m_dns,strlen(str)+4,a); - if (m_con) - { - if (!m_http_proxyhost || !m_http_proxyhost[0]) - { - m_con->connect(m_http_host,m_http_port); - } - else - { - m_con->connect(m_http_proxyhost,m_http_proxyport); - } - m_con->send_string(str); - } - else - { - m_http_state=-1; - seterrstr("could not create connection object"); - } - free(str); - -} - -static int my_strnicmp(char *b1, char *b2, int l) -{ - while (l-- && *b1 && *b2) - { - char bb1=*b1++; - char bb2=*b2++; - if (bb1>='a' && bb1 <= 'z') bb1+='A'-'a'; - if (bb2>='a' && bb2 <= 'z') bb2+='A'-'a'; - if (bb1 != bb2) return bb1-bb2; - } - return 0; -} - -char *_strstr(char *i, char *s) -{ - if (strlen(i)>=strlen(s)) while (i[strlen(s)-1]) - { - int l=strlen(s)+1; - char *ii=i; - char *is=s; - while (--l>0) - { - if (*ii != *is) break; - ii++; - is++; - } - if (l==0) return i; - i++; - } - return NULL; -} - -#define strstr _strstr - -void JNL_HTTPGet::do_parse_url(char *url, char **host, int *port, char **req, char **lp) -{ - char *p,*np; - free(*host); *host=0; - free(*req); *req=0; - free(*lp); *lp=0; - - if (strstr(url,"://")) np=p=strstr(url,"://")+3; - else np=p=url; - while (*np != '/' && *np) np++; - if (*np) - { - *req=(char*)malloc(strlen(np)+1); - if (*req) strcpy(*req,np); - *np++=0; - } - else - { - *req=(char*)malloc(2); - if (*req) strcpy(*req,"/"); - } - - np=p; - while (*np != '@' && *np) np++; - if (*np) - { - *np++=0; - *lp=(char*)malloc(strlen(p)+1); - if (*lp) strcpy(*lp,p); - p=np; - } - else - { - *lp=(char*)malloc(1); - if (*lp) strcpy(*lp,""); - } - np=p; - while (*np != ':' && *np) np++; - if (*np) - { - *np++=0; - *port=my_atoi(np); - } else *port=80; - *host=(char*)malloc(strlen(p)+1); - if (*host) strcpy(*host,p); -} - - -char *JNL_HTTPGet::getallheaders() -{ // double null terminated, null delimited list - if (m_recvheaders) return m_recvheaders; - else return "\0\0"; -} - -char *JNL_HTTPGet::getheader(char *headername) -{ - char *ret=NULL; - if (strlen(headername)<1||!m_recvheaders) return NULL; - char *p=m_recvheaders; - while (*p) - { - if (!my_strnicmp(headername,p,strlen(headername))) - { - ret=p+strlen(headername); - while (*ret == ' ') ret++; - break; - } - p+=strlen(p)+1; - } - return ret; -} - -int JNL_HTTPGet::run() -{ - int cnt=0; - if (m_http_state==-1||!m_con) return -1; // error - - -run_again: - static char main_buf[4096]; - char *buf = main_buf; - m_con->run(); - - if (m_con->get_state()==JNL_Connection::STATE_ERROR) - { - seterrstr(m_con->get_errstr()); - return -1; - } - if (m_con->get_state()==JNL_Connection::STATE_CLOSED) return 1; - - if (m_http_state==0) // connected, waiting for reply - { - if (m_con->recv_lines_available()>0) - { - m_con->recv_line(buf,4095); - buf[4095]=0; - m_reply=(char*)malloc(strlen(buf)+1); - strcpy(m_reply,buf); - - if (strstr(buf,"200")) m_http_state=2; // proceed to read headers normally - else if (strstr(buf,"301") || strstr(buf,"302")) - { - m_http_state=1; // redirect city - } - else - { - seterrstr(buf); - m_http_state=-1; - return -1; - } - cnt=0; - } - else if (!cnt++) goto run_again; - } - if (m_http_state == 1) // redirect - { - while (m_con->recv_lines_available() > 0) - { - m_con->recv_line(buf,4096); - if (!buf[0]) - { - m_http_state=-1; - return -1; - } - if (!my_strnicmp(buf,"Location:",9)) - { - char *p=buf+9; while (*p== ' ') p++; - if (*p) - { - connect(p); - return 0; - } - } - } - } - if (m_http_state==2) - { - if (!cnt++ && m_con->recv_lines_available() < 1) goto run_again; - while (m_con->recv_lines_available() > 0) - { - m_con->recv_line(buf,4096); - if (!buf[0]) { m_http_state=3; break; } - - char *h = buf; - - // workaround for bug #1445735 - // - // some proxies, like WinProxy, prefix headers with tabs - // or spaces. to make sure headers are detected properly, - // this removes up to 128 useless white spaces. - - while ((h - buf < 128) && (*h == ' ' || *h == '\t')) h++; - - if (!m_recvheaders) - { - m_recvheaders_size=strlen(h)+1; - m_recvheaders=(char*)malloc(m_recvheaders_size+1); - if (m_recvheaders) - { - strcpy(m_recvheaders,h); - m_recvheaders[m_recvheaders_size]=0; - } - } - else - { - int oldsize=m_recvheaders_size; - m_recvheaders_size+=strlen(h)+1; - char *n=(char*)malloc(m_recvheaders_size+1); - if (n) - { - memcpy(n,m_recvheaders,oldsize); - strcpy(n+oldsize,h); - n[m_recvheaders_size]=0; - free(m_recvheaders); - m_recvheaders=n; - } - } - } - } - if (m_http_state==3) - { - } - return 0; -} - -int JNL_HTTPGet::get_status() // returns 0 if connecting, 1 if reading headers, - // 2 if reading content, -1 if error. -{ - if (m_http_state < 0) return -1; - if (m_http_state < 2) return 0; - if (m_http_state == 2) return 1; - if (m_http_state == 3) return 2; - return -1; -} - -int JNL_HTTPGet::getreplycode()// returns 0 if none yet, otherwise returns http reply code. -{ - if (!m_reply) return 0; - char *p=m_reply; - while (*p && *p != ' ') p++; // skip over HTTP/x.x - if (!*p) return 0; - return my_atoi(++p); -} - -int JNL_HTTPGet::bytes_available() -{ - if (m_con && m_http_state==3) return m_con->recv_bytes_available(); - return 0; -} -int JNL_HTTPGet::get_bytes(char *buf, int len) -{ - if (m_con && m_http_state==3) return m_con->recv_bytes(buf,len); - return 0; -} -int JNL_HTTPGet::peek_bytes(char *buf, int len) -{ - if (m_con && m_http_state==3) return m_con->peek_bytes(buf,len); - return 0; -} - -__int64 JNL_HTTPGet::content_length() -{ - char *p=getheader("content-length:"); - if (!p) return 0; - __int64 cl = myatoi64(p); - if (cl > 0) return cl; - - // workaround for bug #1744091 - // some buggy apache servers return negative values for sizes - // over 2gb - fix it for them - if (cl < 0) - return (__int64)((unsigned int)(cl)); - - return 0; -} +/* +** JNetLib +** Copyright (C) 2000-2001 Nullsoft, Inc. +** Author: Justin Frankel +** File: httpget.cpp - JNL HTTP GET implementation +** License: see jnetlib.h +** +** Unicode support by Jim Park -- 08/24/2007 +*/ + +#include "netinc.h" +#include "util.h" +#include "httpget.h" + + +JNL_HTTPGet::JNL_HTTPGet(JNL_AsyncDNS *dns, int recvbufsize, char *proxy) +{ + m_recvbufsize=recvbufsize; + m_dns=dns; + m_con=NULL; + m_http_proxylpinfo=0; + m_http_proxyhost=0; + m_http_proxyport=0; + if (proxy && *proxy) + { + char *p=(char*)malloc(strlen(proxy)+1); + if (p) + { + char *r=NULL; + strcpy(p,proxy); + do_parse_url(p,&m_http_proxyhost,&m_http_proxyport,&r,&m_http_proxylpinfo); + free(r); + free(p); + } + } + m_sendheaders=NULL; + reinit(); +} + +void JNL_HTTPGet::reinit() +{ + m_errstr=0; + m_recvheaders=NULL; + m_recvheaders_size=0; + m_http_state=0; + m_http_port=0; + m_http_url=0; + m_reply=0; + m_http_host=m_http_lpinfo=m_http_request=NULL; +} + +void JNL_HTTPGet::deinit() +{ + delete m_con; + free(m_recvheaders); + + free(m_http_url); + free(m_http_host); + free(m_http_lpinfo); + free(m_http_request); + free(m_errstr); + free(m_reply); + reinit(); +} + +JNL_HTTPGet::~JNL_HTTPGet() +{ + deinit(); + free(m_sendheaders); + free(m_http_proxylpinfo); + free(m_http_proxyhost); + +} + + +void JNL_HTTPGet::addheader(char *header) +{ + //if (strstr(header,"\r") || strstr(header,"\n")) return; + if (!m_sendheaders) + { + m_sendheaders=(char*)malloc(strlen(header)+3); + if (m_sendheaders) + { + strcpy(m_sendheaders,header); + strcat(m_sendheaders,"\r\n"); + } + } + else + { + char *t=(char*)malloc(strlen(header)+strlen(m_sendheaders)+1+2); + if (t) + { + strcpy(t,m_sendheaders); + strcat(t,header); + strcat(t,"\r\n"); + free(m_sendheaders); + m_sendheaders=t; + } + } +} + +void JNL_HTTPGet::do_encode_mimestr(char *in, char *out) +{ + char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + int shift = 0; + int accum = 0; + + while (*in) + { + if (*in) + { + accum <<= 8; + shift += 8; + accum |= *in++; + } + while ( shift >= 6 ) + { + shift -= 6; + *out++ = alphabet[(accum >> shift) & 0x3F]; + } + } + if (shift == 4) + { + *out++ = alphabet[(accum & 0xF)<<2]; + *out++='='; + } + else if (shift == 2) + { + *out++ = alphabet[(accum & 0x3)<<4]; + *out++='='; + *out++='='; + } + + *out++=0; +} + + +void JNL_HTTPGet::connect(char *url) +{ + deinit(); + m_http_url=(char*)malloc(strlen(url)+1); + strcpy(m_http_url,url); + do_parse_url(m_http_url,&m_http_host,&m_http_port,&m_http_request, &m_http_lpinfo); + strcpy(m_http_url,url); + if (!m_http_host || !m_http_host[0] || !m_http_port) + { + m_http_state=-1; + seterrstr("invalid URL"); + return; + } + + int sendbufferlen=0; + + if (!m_http_proxyhost || !m_http_proxyhost[0]) + { + sendbufferlen += 4 /* GET */ + strlen(m_http_request) + 9 /* HTTP/1.0 */ + 2; + } + else + { + sendbufferlen += 4 /* GET */ + strlen(m_http_url) + 9 /* HTTP/1.0 */ + 2; + if (m_http_proxylpinfo&&m_http_proxylpinfo[0]) + { + sendbufferlen+=58+strlen(m_http_proxylpinfo)*2; // being safe here + } + } + sendbufferlen += 5 /* Host: */ + strlen(m_http_host) + 2; + + if (m_http_lpinfo&&m_http_lpinfo[0]) + { + sendbufferlen+=46+strlen(m_http_lpinfo)*2; // being safe here + } + + if (m_sendheaders) sendbufferlen+=strlen(m_sendheaders); + + char *str=(char*)malloc(sendbufferlen+1024); + if (!str) + { + seterrstr("error allocating memory"); + m_http_state=-1; + } + + if (!m_http_proxyhost || !m_http_proxyhost[0]) + { + wsprintfA(str,"GET %s HTTP/1.0\r\n",m_http_request); + } + else + { + wsprintfA(str,"GET %s HTTP/1.0\r\n",m_http_url); + } + + wsprintfA(str+strlen(str),"Host: %s\r\n",m_http_host); + + if (m_http_lpinfo&&m_http_lpinfo[0]) + { + strcat(str,"Authorization: Basic "); + do_encode_mimestr(m_http_lpinfo,str+strlen(str)); + strcat(str,"\r\n"); + } + if (m_http_proxylpinfo&&m_http_proxylpinfo[0]) + { + strcat(str,"Proxy-Authorization: Basic "); + do_encode_mimestr(m_http_proxylpinfo,str+strlen(str)); + strcat(str,"\r\n"); + } + + if (m_sendheaders) strcat(str,m_sendheaders); + strcat(str,"\r\n"); + + int a=m_recvbufsize; + if (a < 4096) a=4096; + m_con=new JNL_Connection(m_dns,strlen(str)+4,a); + if (m_con) + { + if (!m_http_proxyhost || !m_http_proxyhost[0]) + { + m_con->connect(m_http_host,m_http_port); + } + else + { + m_con->connect(m_http_proxyhost,m_http_proxyport); + } + m_con->send_string(str); + } + else + { + m_http_state=-1; + seterrstr("could not create connection object"); + } + free(str); + +} + +static int my_strnicmp(char *b1, char *b2, int l) +{ + while (l-- && *b1 && *b2) + { + char bb1=*b1++; + char bb2=*b2++; + if (bb1>='a' && bb1 <= 'z') bb1+='A'-'a'; + if (bb2>='a' && bb2 <= 'z') bb2+='A'-'a'; + if (bb1 != bb2) return bb1-bb2; + } + return 0; +} + +char *_strstr(char *i, char *s) +{ + if (strlen(i)>=strlen(s)) while (i[strlen(s)-1]) + { + int l=strlen(s)+1; + char *ii=i; + char *is=s; + while (--l>0) + { + if (*ii != *is) break; + ii++; + is++; + } + if (l==0) return i; + i++; + } + return NULL; +} + +#define strstr _strstr + +void JNL_HTTPGet::do_parse_url(char *url, char **host, int *port, char **req, char **lp) +{ + char *p,*np; + free(*host); *host=0; + free(*req); *req=0; + free(*lp); *lp=0; + + if (strstr(url,"://")) np=p=strstr(url,"://")+3; + else np=p=url; + while (*np != '/' && *np) np++; + if (*np) + { + *req=(char*)malloc(strlen(np)+1); + if (*req) strcpy(*req,np); + *np++=0; + } + else + { + *req=(char*)malloc(2); + if (*req) strcpy(*req,"/"); + } + + np=p; + while (*np != '@' && *np) np++; + if (*np) + { + *np++=0; + *lp=(char*)malloc(strlen(p)+1); + if (*lp) strcpy(*lp,p); + p=np; + } + else + { + *lp=(char*)malloc(1); + if (*lp) strcpy(*lp,""); + } + np=p; + while (*np != ':' && *np) np++; + if (*np) + { + *np++=0; + *port=my_atoi(np); + } else *port=80; + *host=(char*)malloc(strlen(p)+1); + if (*host) strcpy(*host,p); +} + + +char *JNL_HTTPGet::getallheaders() +{ // double null terminated, null delimited list + if (m_recvheaders) return m_recvheaders; + else return "\0\0"; +} + +char *JNL_HTTPGet::getheader(char *headername) +{ + char *ret=NULL; + if (strlen(headername)<1||!m_recvheaders) return NULL; + char *p=m_recvheaders; + while (*p) + { + if (!my_strnicmp(headername,p,strlen(headername))) + { + ret=p+strlen(headername); + while (*ret == ' ') ret++; + break; + } + p+=strlen(p)+1; + } + return ret; +} + +int JNL_HTTPGet::run() +{ + int cnt=0; + if (m_http_state==-1||!m_con) return -1; // error + + +run_again: + static char main_buf[4096]; + char *buf = main_buf; + m_con->run(); + + if (m_con->get_state()==JNL_Connection::STATE_ERROR) + { + seterrstr(m_con->get_errstr()); + return -1; + } + if (m_con->get_state()==JNL_Connection::STATE_CLOSED) return 1; + + if (m_http_state==0) // connected, waiting for reply + { + if (m_con->recv_lines_available()>0) + { + m_con->recv_line(buf,4095); + buf[4095]=0; + m_reply=(char*)malloc(strlen(buf)+1); + strcpy(m_reply,buf); + + if (strstr(buf,"200")) m_http_state=2; // proceed to read headers normally + else if (strstr(buf,"301") || strstr(buf,"302")) + { + m_http_state=1; // redirect city + } + else + { + seterrstr(buf); + m_http_state=-1; + return -1; + } + cnt=0; + } + else if (!cnt++) goto run_again; + } + if (m_http_state == 1) // redirect + { + while (m_con->recv_lines_available() > 0) + { + m_con->recv_line(buf,4096); + if (!buf[0]) + { + m_http_state=-1; + return -1; + } + if (!my_strnicmp(buf,"Location:",9)) + { + char *p=buf+9; while (*p== ' ') p++; + if (*p) + { + connect(p); + return 0; + } + } + } + } + if (m_http_state==2) + { + if (!cnt++ && m_con->recv_lines_available() < 1) goto run_again; + while (m_con->recv_lines_available() > 0) + { + m_con->recv_line(buf,4096); + if (!buf[0]) { m_http_state=3; break; } + + char *h = buf; + + // workaround for bug #1445735 + // + // some proxies, like WinProxy, prefix headers with tabs + // or spaces. to make sure headers are detected properly, + // this removes up to 128 useless white spaces. + + while ((h - buf < 128) && (*h == ' ' || *h == '\t')) h++; + + if (!m_recvheaders) + { + m_recvheaders_size=strlen(h)+1; + m_recvheaders=(char*)malloc(m_recvheaders_size+1); + if (m_recvheaders) + { + strcpy(m_recvheaders,h); + m_recvheaders[m_recvheaders_size]=0; + } + } + else + { + int oldsize=m_recvheaders_size; + m_recvheaders_size+=strlen(h)+1; + char *n=(char*)malloc(m_recvheaders_size+1); + if (n) + { + memcpy(n,m_recvheaders,oldsize); + strcpy(n+oldsize,h); + n[m_recvheaders_size]=0; + free(m_recvheaders); + m_recvheaders=n; + } + } + } + } + if (m_http_state==3) + { + } + return 0; +} + +int JNL_HTTPGet::get_status() // returns 0 if connecting, 1 if reading headers, + // 2 if reading content, -1 if error. +{ + if (m_http_state < 0) return -1; + if (m_http_state < 2) return 0; + if (m_http_state == 2) return 1; + if (m_http_state == 3) return 2; + return -1; +} + +int JNL_HTTPGet::getreplycode()// returns 0 if none yet, otherwise returns http reply code. +{ + if (!m_reply) return 0; + char *p=m_reply; + while (*p && *p != ' ') p++; // skip over HTTP/x.x + if (!*p) return 0; + return my_atoi(++p); +} + +int JNL_HTTPGet::bytes_available() +{ + if (m_con && m_http_state==3) return m_con->recv_bytes_available(); + return 0; +} +int JNL_HTTPGet::get_bytes(char *buf, int len) +{ + if (m_con && m_http_state==3) return m_con->recv_bytes(buf,len); + return 0; +} +int JNL_HTTPGet::peek_bytes(char *buf, int len) +{ + if (m_con && m_http_state==3) return m_con->peek_bytes(buf,len); + return 0; +} + +__int64 JNL_HTTPGet::content_length() +{ + char *p=getheader("content-length:"); + if (!p) return 0; + __int64 cl = myatoi64(p); + if (cl > 0) return cl; + + // workaround for bug #1744091 + // some buggy apache servers return negative values for sizes + // over 2gb - fix it for them + if (cl < 0) + return (__int64)((unsigned int)(cl)); + + return 0; +} diff --git a/Contrib/NSISdl/httpget.h b/Contrib/NSISdl/httpget.h index c87e1811..266a822e 100644 --- a/Contrib/NSISdl/httpget.h +++ b/Contrib/NSISdl/httpget.h @@ -1,109 +1,113 @@ -/* -** JNetLib -** Copyright (C) 2000-2001 Nullsoft, Inc. -** Author: Justin Frankel -** File: httpget.h - JNL interface for doing HTTP GETs. -** License: see jnetlib.h -** -** Usage: -** 1. Create a JNL_HTTPGet object, optionally specifying a JNL_AsyncDNS -** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto), -** and the receive buffer size, and a string specifying proxy (or NULL -** for none). See note on proxy string below. -** 2. call addheader() to add whatever headers you want. It is recommended to -** add at least the following two: -** addheader("User-Agent:MyApp (Mozilla)"); -*/// addheader("Accept:*/*"); -/* ( the comment weirdness is there so I Can do the star-slash :) -** 3. Call connect() with the URL you wish to GET (see URL string note below) -** 4. Call run() once in a while, checking to see if it returns -1 -** (if it does return -1, call geterrorstr() to see what the error is). -** (if it returns 1, no big deal, the connection has closed). -** 5. While you're at it, you can call bytes_available() to see if any data -** from the http stream is available, or getheader() to see if any headers -** are available, or getreply() to see the HTTP reply, or getallheaders() -** to get a double null terminated, null delimited list of headers returned. -** 6. If you want to read from the stream, call get_bytes (which returns how much -** was actually read). -** 7. content_length() is a helper function that uses getheader() to check the -** content-length header. -** 8. Delete ye' ol' object when done. -** -** Proxy String: -** should be in the format of host:port, or user@host:port, or -** user:password@host:port. if port is not specified, 80 is assumed. -** URL String: -** should be in the format of http://user:pass@host:port/requestwhatever -** note that user, pass, port, and /requestwhatever are all optional :) -** note that also, http:// is really not important. if you do poo:// -** or even leave out the http:// altogether, it will still work. -*/ - -#ifndef _HTTPGET_H_ -#define _HTTPGET_H_ - -#include "connection.h" - -class JNL_HTTPGet -{ - public: - JNL_HTTPGet(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int recvbufsize=16384, char *proxy=NULL); - ~JNL_HTTPGet(); - - void addheader(char *header); - - void connect(char *url); - - int run(); // returns: 0 if all is OK. -1 if error (call geterrorstr()). 1 if connection closed. - - int get_status(); // returns 0 if connecting, 1 if reading headers, - // 2 if reading content, -1 if error. - - char *getallheaders(); // double null terminated, null delimited list - char *getheader(char *headername); - char *getreply() { return m_reply; } - int getreplycode(); // returns 0 if none yet, otherwise returns http reply code. - - char *geterrorstr() { return m_errstr;} - - int bytes_available(); - int get_bytes(char *buf, int len); - int peek_bytes(char *buf, int len); - - __int64 content_length(); - - JNL_Connection *get_con() { return m_con; } - - public: - void reinit(); - void deinit(); - void seterrstr(char *str) { if (m_errstr) free(m_errstr); m_errstr=(char*)malloc(strlen(str)+1); strcpy(m_errstr,str); } - - void do_parse_url(char *url, char **host, int *port, char **req, char **lp); - void do_encode_mimestr(char *in, char *out); - - JNL_AsyncDNS *m_dns; - JNL_Connection *m_con; - int m_recvbufsize; - - int m_http_state; - - int m_http_port; - char *m_http_url; - char *m_http_host; - char *m_http_lpinfo; - char *m_http_request; - - char *m_http_proxylpinfo; - char *m_http_proxyhost; - int m_http_proxyport; - - char *m_sendheaders; - char *m_recvheaders; - int m_recvheaders_size; - char *m_reply; - - char *m_errstr; -}; - -#endif // _HTTPGET_H_ +/* +** JNetLib +** Copyright (C) 2000-2001 Nullsoft, Inc. +** Author: Justin Frankel +** File: httpget.h - JNL interface for doing HTTP GETs. +** License: see jnetlib.h +** +** Usage: +** 1. Create a JNL_HTTPGet object, optionally specifying a JNL_AsyncDNS +** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto), +** and the receive buffer size, and a string specifying proxy (or NULL +** for none). See note on proxy string below. +** 2. call addheader() to add whatever headers you want. It is recommended to +** add at least the following two: +** addheader("User-Agent:MyApp (Mozilla)"); +*/// addheader("Accept:*/*"); +/* ( the comment weirdness is there so I Can do the star-slash :) +** 3. Call connect() with the URL you wish to GET (see URL string note below) +** 4. Call run() once in a while, checking to see if it returns -1 +** (if it does return -1, call geterrorstr() to see what the error is). +** (if it returns 1, no big deal, the connection has closed). +** 5. While you're at it, you can call bytes_available() to see if any data +** from the http stream is available, or getheader() to see if any headers +** are available, or getreply() to see the HTTP reply, or getallheaders() +** to get a double null terminated, null delimited list of headers returned. +** 6. If you want to read from the stream, call get_bytes (which returns how much +** was actually read). +** 7. content_length() is a helper function that uses getheader() to check the +** content-length header. +** 8. Delete ye' ol' object when done. +** +** Proxy String: +** should be in the format of host:port, or user@host:port, or +** user:password@host:port. if port is not specified, 80 is assumed. +** URL String: +** should be in the format of http://user:pass@host:port/requestwhatever +** note that user, pass, port, and /requestwhatever are all optional :) +** note that also, http:// is really not important. if you do poo:// +** or even leave out the http:// altogether, it will still work. +** +** Reviewed for Unicode support by Jim Park -- 08/24/2004 +** Everything remains ANSI. Made sure all TCHAR style functions were +** changed to strictly ANSI. +*/ + +#ifndef _HTTPGET_H_ +#define _HTTPGET_H_ + +#include "connection.h" + +class JNL_HTTPGet +{ + public: + JNL_HTTPGet(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int recvbufsize=16384, char *proxy=NULL); + ~JNL_HTTPGet(); + + void addheader(char *header); + + void connect(char *url); + + int run(); // returns: 0 if all is OK. -1 if error (call geterrorstr()). 1 if connection closed. + + int get_status(); // returns 0 if connecting, 1 if reading headers, + // 2 if reading content, -1 if error. + + char *getallheaders(); // double null terminated, null delimited list + char *getheader(char *headername); + char *getreply() { return m_reply; } + int getreplycode(); // returns 0 if none yet, otherwise returns http reply code. + + char *geterrorstr() { return m_errstr;} + + int bytes_available(); + int get_bytes(char *buf, int len); + int peek_bytes(char *buf, int len); + + __int64 content_length(); + + JNL_Connection *get_con() { return m_con; } + + public: + void reinit(); + void deinit(); + void seterrstr(char *str) { if (m_errstr) free(m_errstr); m_errstr=(char*)malloc(strlen(str)+1); strcpy(m_errstr,str); } + + void do_parse_url(char *url, char **host, int *port, char **req, char **lp); + void do_encode_mimestr(char *in, char *out); + + JNL_AsyncDNS *m_dns; + JNL_Connection *m_con; + int m_recvbufsize; + + int m_http_state; + + int m_http_port; + char *m_http_url; + char *m_http_host; + char *m_http_lpinfo; + char *m_http_request; + + char *m_http_proxylpinfo; + char *m_http_proxyhost; + int m_http_proxyport; + + char *m_sendheaders; + char *m_recvheaders; + int m_recvheaders_size; + char *m_reply; + + char *m_errstr; +}; + +#endif // _HTTPGET_H_ diff --git a/Contrib/NSISdl/netinc.h b/Contrib/NSISdl/netinc.h index ed8bd002..a62a7e22 100644 --- a/Contrib/NSISdl/netinc.h +++ b/Contrib/NSISdl/netinc.h @@ -1,42 +1,46 @@ -/* -** JNetLib -** Copyright (C) 2000-2001 Nullsoft, Inc. -** Author: Justin Frankel -** File: netinc.h - network includes and portability defines (used internally) -** License: see jnetlib.h -*/ - -#ifndef _NETINC_H_ -#define _NETINC_H_ - -#include -#include "util.h" - -#define strcasecmp(x,y) stricmp(x,y) -#define ERRNO (WSAGetLastError()) -#define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); } -#define EWOULDBLOCK WSAEWOULDBLOCK -#define EINPROGRESS WSAEWOULDBLOCK -#define memset mini_memset -#define memcpy mini_memcpy -#define strcpy lstrcpy -#define strncpy lstrcpyn -#define strcat lstrcat -#define strlen lstrlen -#define malloc(x) (new char[x]) -#define free(x) {delete [] x;} -typedef int socklen_t; - -#ifndef INADDR_NONE -#define INADDR_NONE 0xffffffff -#endif - -#ifndef INADDR_ANY -#define INADDR_ANY 0 -#endif - -#ifndef SHUT_RDWR -#define SHUT_RDWR 2 -#endif - -#endif //_NETINC_H_ +/* +** JNetLib +** Copyright (C) 2000-2001 Nullsoft, Inc. +** Author: Justin Frankel +** File: netinc.h - network includes and portability defines (used internally) +** License: see jnetlib.h +** +** Unicode support by Jim Park -- 08/24/2007 +*/ + +#ifndef _NETINC_H_ +#define _NETINC_H_ + +#include +#include "util.h" + +#define strcasecmp(x,y) stricmp(x,y) +#define ERRNO (WSAGetLastError()) +#define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); } +#define EWOULDBLOCK WSAEWOULDBLOCK +#define EINPROGRESS WSAEWOULDBLOCK +#define memset mini_memset +#define memcpy mini_memcpy +// Jim Park: For Unicode support, we need to distinguish whether we are working on +// Unicode or ANSI. +#define strcpy lstrcpyA +#define strncpy lstrcpynA +#define strcat lstrcatA +#define strlen lstrlenA +#define malloc(x) (new char[x]) +#define free(x) {delete [] x;} +typedef int socklen_t; + +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff +#endif + +#ifndef INADDR_ANY +#define INADDR_ANY 0 +#endif + +#ifndef SHUT_RDWR +#define SHUT_RDWR 2 +#endif + +#endif //_NETINC_H_ diff --git a/Contrib/NSISdl/nsisdl.cpp b/Contrib/NSISdl/nsisdl.cpp index 7eaa246a..ba4112d3 100644 --- a/Contrib/NSISdl/nsisdl.cpp +++ b/Contrib/NSISdl/nsisdl.cpp @@ -1,597 +1,599 @@ -/* - NSIS-DL 1.3 - http downloading DLL for NSIS - Copyright (C) 2001-2002 Yaroslav Faybishenko & Justin Frankel - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include -#include -#include - -#include "netinc.h" -#include "util.h" -#include "httpget.h" - -#include // nsis plugin - -void *operator new( unsigned int num_bytes ) -{ - return GlobalAlloc(GPTR,num_bytes); -} -void operator delete( void *p ) { if (p) GlobalFree(p); } - - -HMODULE hModule; -HWND g_hwndProgressBar; -HWND g_hwndStatic; -static int g_cancelled; -static void *lpWndProcOld; - -static UINT uMsgCreate; - -HWND childwnd; -HWND hwndL; -HWND hwndB; - -static LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - if (uMsgCreate && message == uMsgCreate) - { - static HWND hwndPrevFocus; - static BOOL fCancelDisabled; - - if (wParam) - { - childwnd = FindWindowEx((HWND) lParam, NULL, "#32770", NULL); - hwndL = GetDlgItem(childwnd, 1016); - hwndB = GetDlgItem(childwnd, 1027); - HWND hwndP = GetDlgItem(childwnd, 1004); - HWND hwndS = GetDlgItem(childwnd, 1006); - if (childwnd && hwndP && hwndS) - { - // Where to restore focus to before we disable the cancel button - hwndPrevFocus = GetFocus(); - if (!hwndPrevFocus) - hwndPrevFocus = hwndP; - - if (IsWindowVisible(hwndL)) - ShowWindow(hwndL, SW_HIDE); - else - hwndL = NULL; - if (IsWindowVisible(hwndB)) - ShowWindow(hwndB, SW_HIDE); - else - hwndB = NULL; - - RECT wndRect, ctlRect; - - GetClientRect(childwnd, &wndRect); - - GetWindowRect(hwndS, &ctlRect); - - HWND s = g_hwndStatic = CreateWindow( - "STATIC", - "", - WS_CHILD | WS_CLIPSIBLINGS | SS_CENTER, - 0, - wndRect.bottom / 2 - (ctlRect.bottom - ctlRect.top) / 2, - wndRect.right, - ctlRect.bottom - ctlRect.top, - childwnd, - NULL, - hModule, - NULL - ); - - DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS; - dwStyle |= GetWindowLong(hwndP, GWL_STYLE) & PBS_SMOOTH; - - GetWindowRect(hwndP, &ctlRect); - - HWND pb = g_hwndProgressBar = CreateWindow( - "msctls_progress32", - "", - dwStyle, - 0, - wndRect.bottom / 2 + (ctlRect.bottom - ctlRect.top) / 2, - wndRect.right, - ctlRect.bottom - ctlRect.top, - childwnd, - NULL, - hModule, - NULL - ); - - long c; - - c = SendMessage(hwndP, PBM_SETBARCOLOR, 0, 0); - SendMessage(hwndP, PBM_SETBARCOLOR, 0, c); - SendMessage(pb, PBM_SETBARCOLOR, 0, c); - - c = SendMessage(hwndP, PBM_SETBKCOLOR, 0, 0); - SendMessage(hwndP, PBM_SETBKCOLOR, 0, c); - SendMessage(pb, PBM_SETBKCOLOR, 0, c); - - // set font - long hFont = SendMessage((HWND) lParam, WM_GETFONT, 0, 0); - SendMessage(pb, WM_SETFONT, hFont, 0); - SendMessage(s, WM_SETFONT, hFont, 0); - - ShowWindow(pb, SW_SHOWNA); - ShowWindow(s, SW_SHOWNA); - - fCancelDisabled = EnableWindow(GetDlgItem(hwnd, IDCANCEL), TRUE); - SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDCANCEL), TRUE); - } - else - childwnd = NULL; - } - else if (childwnd) - { - if (hwndB) - { - ShowWindow(hwndB, SW_SHOWNA); - hwndB = NULL; - } - if (hwndL) - { - ShowWindow(hwndL, SW_SHOWNA); - hwndL = NULL; - } - - // Prevent wierd stuff happening if the cancel button happens to be - // pressed at the moment we are finishing and restore the previous focus - // and cancel button states - SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)hwndPrevFocus, TRUE); - SendMessage(GetDlgItem(hwnd, IDCANCEL), BM_SETSTATE, FALSE, 0); - if (fCancelDisabled) - EnableWindow(GetDlgItem(hwnd, IDCANCEL), FALSE); - - if (g_hwndStatic) - { - DestroyWindow(g_hwndStatic); - g_hwndStatic = NULL; - } - if (g_hwndProgressBar) - { - DestroyWindow(g_hwndProgressBar); - g_hwndProgressBar = NULL; - } - childwnd = NULL; - } - } - else if (message == WM_COMMAND && LOWORD(wParam) == IDCANCEL) - { - g_cancelled = 1; - } - else - { - return CallWindowProc( - (WNDPROC) lpWndProcOld, - hwnd, - message, - wParam, - lParam - ); - } - return 0; -} - -extern "C" BOOL APIENTRY DllMain(HINSTANCE _hModule, DWORD ul_reason_for_call, LPVOID lpReserved) -{ - hModule = _hModule; - return TRUE; -} - -#define INT32_MAX 0x7fffffff - -int MulDiv64(int nNumber, __int64 nNumerator, __int64 nDenominator) -{ - // ok, a complete implementation would handle negatives too, - // but this method is probably not generally useful. - while (nNumerator > INT32_MAX || nDenominator > INT32_MAX) - { - nNumerator = Int64ShraMod32(nNumerator, 1); - nDenominator = Int64ShraMod32(nDenominator, 1); - } - return MulDiv(nNumber, (int)nNumerator, (int)nDenominator); -} - - -static __int64 g_file_size; -static DWORD g_dwLastTick = 0; -void progress_callback(char *msg, __int64 read_bytes) -{ - // flicker reduction by A. Schiffler - DWORD dwLastTick = g_dwLastTick; - DWORD dwThisTick = GetTickCount(); - if (childwnd) - { - if (dwThisTick - dwLastTick > 500) - { - SetWindowText(g_hwndStatic, msg); - dwLastTick = dwThisTick; - } - if (g_file_size) - SendMessage(g_hwndProgressBar, PBM_SETPOS, (WPARAM) MulDiv64(30000, read_bytes, g_file_size), 0); - g_dwLastTick = dwLastTick; - } -} - -extern char *_strstr(char *i, char *s); -#define strstr _strstr - -extern "C" -{ - -__declspec(dllexport) void download (HWND parent, - int string_size, - char *variables, - stack_t **stacktop) -{ - char buf[1024]; - char url[1024]; - char filename[1024]; - static char proxy[1024]; - BOOL bSuccess=FALSE; - int timeout_ms=30000; - int getieproxy=1; - int manualproxy=0; - int translation_version; - - char *error=NULL; - - // translation version 2 & 1 - static char szDownloading[1024]; // "Downloading %s" - static char szConnecting[1024]; // "Connecting ..." - static char szSecond[1024]; // " (1 second remaining)" for v2 - // "second" for v1 - static char szMinute[1024]; // " (1 minute remaining)" for v2 - // "minute" for v1 - static char szHour[1024]; // " (1 hour remaining)" for v2 - // "hour" for v1 - static char szProgress[1024]; // "%skB (%d%%) of %skB at %u.%01ukB/s" for v2 - // "%dkB (%d%%) of %dkB at %d.%01dkB/s" for v1 - - // translation version 2 only - static char szSeconds[1024]; // " (%u seconds remaining)" - static char szMinutes[1024]; // " (%u minutes remaining)" - static char szHours[1024]; // " (%u hours remaining)" - - // translation version 1 only - static char szPlural[1024]; // "s"; - static char szRemaining[1024]; // " (%d %s%s remaining)"; - - EXDLL_INIT(); - - popstring(url); - if (!lstrcmpi(url, "/TRANSLATE2")) { - popstring(szDownloading); - popstring(szConnecting); - popstring(szSecond); - popstring(szMinute); - popstring(szHour); - popstring(szSeconds); - popstring(szMinutes); - popstring(szHours); - popstring(szProgress); - popstring(url); - translation_version=2; - } else if (!lstrcmpi(url, "/TRANSLATE")) { - popstring(szDownloading); - popstring(szConnecting); - popstring(szSecond); - popstring(szMinute); - popstring(szHour); - popstring(szPlural); - popstring(szProgress); - popstring(szRemaining); - popstring(url); - translation_version=1; - } else { - lstrcpy(szDownloading, "Downloading %s"); - lstrcpy(szConnecting, "Connecting ..."); - lstrcpy(szSecond, " (1 second remaining)"); - lstrcpy(szMinute, " (1 minute remaining)"); - lstrcpy(szHour, " (1 hour remaining)"); - lstrcpy(szSeconds, " (%u seconds remaining)"); - lstrcpy(szMinutes, " (%u minutes remaining)"); - lstrcpy(szHours, " (%u hours remaining)"); - lstrcpy(szProgress, "%skB (%d%%) of %skB at %u.%01ukB/s"); - translation_version=2; - } - lstrcpyn(buf, url, 10); - if (!lstrcmpi(buf, "/TIMEOUT=")) { - timeout_ms=my_atoi(url+9); - popstring(url); - } - if (!lstrcmpi(url, "/PROXY")) { - getieproxy=0; - manualproxy=1; - popstring(proxy); - popstring(url); - } - if (!lstrcmpi(url, "/NOIEPROXY")) { - getieproxy=0; - popstring(url); - } - popstring(filename); - - HANDLE hFile = CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - wsprintf(buf, "Unable to open %s", filename); - error = buf; - } - else - { - if (parent) - { - uMsgCreate = RegisterWindowMessage("nsisdl create"); - - lpWndProcOld = (void *)SetWindowLong(parent,GWL_WNDPROC,(long)ParentWndProc); - - SendMessage(parent, uMsgCreate, TRUE, (LPARAM) parent); - - // set initial text - char *p = filename; - while (*p) p++; - while (*p != '\\' && p != filename) p = CharPrev(filename, p); - wsprintf(buf, szDownloading, p != filename ? p + 1 : p); - SetDlgItemText(childwnd, 1006, buf); - SetWindowText(g_hwndStatic, szConnecting); - } - { - WSADATA wsaData; - WSAStartup(MAKEWORD(1, 1), &wsaData); - - JNL_HTTPGet *get = 0; - - static char main_buf[8192]; - char *buf=main_buf; - char *p=NULL; - - HKEY hKey; - if (getieproxy && RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS) - { - DWORD l = 4; - DWORD t; - DWORD v; - if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD && v) - { - l=8192; - if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)buf,&l ) == ERROR_SUCCESS && t == REG_SZ) - { - p=strstr(buf,"http="); - if (!p) p=buf; - else { - p+=5; - } - char *tp=strstr(p,";"); - if (tp) *tp=0; - char *p2=strstr(p,"="); - if (p2) p=0; // we found the wrong proxy - } - } - buf[8192-1]=0; - RegCloseKey(hKey); - } - if (manualproxy == 1) { - p = proxy; - } - - DWORD start_time=GetTickCount(); - get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL); - int st; - int has_printed_headers = 0; - __int64 cl = 0; - int len; - __int64 sofar = 0; - DWORD last_recv_time=start_time; - - get->addheader ("User-Agent: NSISDL/1.2 (Mozilla)"); - get->addheader ("Accept: */*"); - - get->connect (url); - - while (1) { - if (g_cancelled) - error = "cancel"; - - if (error) - { - if (parent) - { - SendMessage(parent, uMsgCreate, FALSE, (LPARAM) parent); - SetWindowLong(parent, GWL_WNDPROC, (long)lpWndProcOld); - } - break; - } - - st = get->run (); - - if (st == -1) { - lstrcpyn(url, get->geterrorstr(), sizeof(url)); - error = url; - } else if (st == 1) { - if (sofar < cl || get->get_status () != 2) - error="download incomplete"; - else - { - bSuccess=TRUE; - error = "success"; - } - } else { - - if (get->get_status () == 0) { - // progressFunc ("Connecting ...", 0); - if (last_recv_time+timeout_ms < GetTickCount()) - error = "Timed out on connecting."; - else - Sleep(10); // don't busy-loop while connecting - - } else if (get->get_status () == 1) { - - progress_callback("Reading headers", 0); - if (last_recv_time+timeout_ms < GetTickCount()) - error = "Timed out on getting headers."; - else - Sleep(10); // don't busy-loop while reading headers - - } else if (get->get_status () == 2) { - - if (! has_printed_headers) { - has_printed_headers = 1; - last_recv_time=GetTickCount(); - - cl = get->content_length (); - if (cl == 0) - error = "Server did not specify content length."; - else if (g_hwndProgressBar) { - SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 30000)); - g_file_size = cl; - } - } - - int data_downloaded = 0; - while ((len = get->bytes_available ()) > 0) { - data_downloaded++; - if (len > 8192) - len = 8192; - len = get->get_bytes (buf, len); - if (len > 0) { - last_recv_time=GetTickCount(); - DWORD dw; - WriteFile(hFile,buf,len,&dw,NULL); - sofar += len; - int time_sofar=(GetTickCount()-start_time)/1000; - int bps = (int)(sofar/(time_sofar?time_sofar:1)); - int remain = MulDiv64(time_sofar, cl, sofar) - time_sofar; - - if (translation_version == 2) { - char *rtext=remain==1?szSecond:szSeconds;; - if (remain >= 60) - { - remain/=60; - rtext=remain==1?szMinute:szMinutes; - if (remain >= 60) - { - remain/=60; - rtext=remain==1?szHour:szHours; - } - } - - char sofar_str[128]; - char cl_str[128]; - myitoa64(sofar/1024, sofar_str); - myitoa64(cl/1024, cl_str); - - wsprintf (buf, - szProgress, //%skB (%d%%) of %skB @ %u.%01ukB/s - sofar_str, - MulDiv64(100, sofar, cl), - cl_str, - bps/1024,((bps*10)/1024)%10 - ); - if (remain) wsprintf(buf+lstrlen(buf),rtext, - remain - ); - } else if (translation_version == 1) { - char *rtext=szSecond; - if (remain >= 60) - { - remain/=60; - rtext=szMinute; - if (remain >= 60) - { - remain/=60; - rtext=szHour; - } - } - - wsprintf (buf, - szProgress, //%dkB (%d%%) of %dkB @ %d.%01dkB/s - int(sofar/1024), - MulDiv64(100, sofar, cl), - int(cl/1024), - bps/1024,((bps*10)/1024)%10 - ); - if (remain) wsprintf(buf+lstrlen(buf),szRemaining, - remain, - rtext, - remain==1?"":szPlural - ); - } - progress_callback(buf, sofar); - } else { - if (sofar < cl) - error = "Server aborted."; - } - } - if (GetTickCount() > last_recv_time+timeout_ms) - { - if (sofar != cl) - { - error = "Downloading timed out."; - } - else - { - // workaround for bug #1713562 - // buggy servers that wait for the client to close the connection. - // another solution would be manually stopping when cl == sofar, - // but then buggy servers that return wrong content-length will fail. - bSuccess = TRUE; - error = "success"; - } - } - else if (!data_downloaded) - Sleep(10); - - } else { - error = "Bad response status."; - } - } - - } - - // Clean up the connection then release winsock - if (get) delete get; - WSACleanup(); - } - - CloseHandle(hFile); - } - - if (g_cancelled || !bSuccess) { - DeleteFile(filename); - } - - pushstring(error); -} - - -__declspec(dllexport) void download_quiet(HWND parent, - int stringsize, - char *variables, - stack_t **stacktop) -{ - g_hwndProgressBar=0; - download(NULL,stringsize,variables,stacktop); -} - -} //extern "C" +/* + NSIS-DL 1.3 - http downloading DLL for NSIS + Copyright (C) 2001-2002 Yaroslav Faybishenko & Justin Frankel + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Unicode support by Jim Park -- 08/24/2007 +*/ +#include +#include +#include + +#include "netinc.h" +#include "util.h" +#include "httpget.h" + +#include // nsis plugin + +void *operator new( unsigned int num_bytes ) +{ + return GlobalAlloc(GPTR,num_bytes); +} +void operator delete( void *p ) { if (p) GlobalFree(p); } + + +HMODULE hModule; +HWND g_hwndProgressBar; +HWND g_hwndStatic; +static int g_cancelled; +static void *lpWndProcOld; + +static UINT uMsgCreate; + +HWND childwnd; +HWND hwndL; +HWND hwndB; + +static LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + if (uMsgCreate && message == uMsgCreate) + { + static HWND hwndPrevFocus; + static BOOL fCancelDisabled; + + if (wParam) + { + childwnd = FindWindowEx((HWND) lParam, NULL, _T("#32770"), NULL); + hwndL = GetDlgItem(childwnd, 1016); + hwndB = GetDlgItem(childwnd, 1027); + HWND hwndP = GetDlgItem(childwnd, 1004); + HWND hwndS = GetDlgItem(childwnd, 1006); + if (childwnd && hwndP && hwndS) + { + // Where to restore focus to before we disable the cancel button + hwndPrevFocus = GetFocus(); + if (!hwndPrevFocus) + hwndPrevFocus = hwndP; + + if (IsWindowVisible(hwndL)) + ShowWindow(hwndL, SW_HIDE); + else + hwndL = NULL; + if (IsWindowVisible(hwndB)) + ShowWindow(hwndB, SW_HIDE); + else + hwndB = NULL; + + RECT wndRect, ctlRect; + + GetClientRect(childwnd, &wndRect); + + GetWindowRect(hwndS, &ctlRect); + + HWND s = g_hwndStatic = CreateWindow( + _T("STATIC"), + _T(""), + WS_CHILD | WS_CLIPSIBLINGS | SS_CENTER, + 0, + wndRect.bottom / 2 - (ctlRect.bottom - ctlRect.top) / 2, + wndRect.right, + ctlRect.bottom - ctlRect.top, + childwnd, + NULL, + hModule, + NULL + ); + + DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS; + dwStyle |= GetWindowLong(hwndP, GWL_STYLE) & PBS_SMOOTH; + + GetWindowRect(hwndP, &ctlRect); + + HWND pb = g_hwndProgressBar = CreateWindow( + _T("msctls_progress32"), + _T(""), + dwStyle, + 0, + wndRect.bottom / 2 + (ctlRect.bottom - ctlRect.top) / 2, + wndRect.right, + ctlRect.bottom - ctlRect.top, + childwnd, + NULL, + hModule, + NULL + ); + + long c; + + c = SendMessage(hwndP, PBM_SETBARCOLOR, 0, 0); + SendMessage(hwndP, PBM_SETBARCOLOR, 0, c); + SendMessage(pb, PBM_SETBARCOLOR, 0, c); + + c = SendMessage(hwndP, PBM_SETBKCOLOR, 0, 0); + SendMessage(hwndP, PBM_SETBKCOLOR, 0, c); + SendMessage(pb, PBM_SETBKCOLOR, 0, c); + + // set font + long hFont = SendMessage((HWND) lParam, WM_GETFONT, 0, 0); + SendMessage(pb, WM_SETFONT, hFont, 0); + SendMessage(s, WM_SETFONT, hFont, 0); + + ShowWindow(pb, SW_SHOWNA); + ShowWindow(s, SW_SHOWNA); + + fCancelDisabled = EnableWindow(GetDlgItem(hwnd, IDCANCEL), TRUE); + SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDCANCEL), TRUE); + } + else + childwnd = NULL; + } + else if (childwnd) + { + if (hwndB) + { + ShowWindow(hwndB, SW_SHOWNA); + hwndB = NULL; + } + if (hwndL) + { + ShowWindow(hwndL, SW_SHOWNA); + hwndL = NULL; + } + + // Prevent wierd stuff happening if the cancel button happens to be + // pressed at the moment we are finishing and restore the previous focus + // and cancel button states + SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)hwndPrevFocus, TRUE); + SendMessage(GetDlgItem(hwnd, IDCANCEL), BM_SETSTATE, FALSE, 0); + if (fCancelDisabled) + EnableWindow(GetDlgItem(hwnd, IDCANCEL), FALSE); + + if (g_hwndStatic) + { + DestroyWindow(g_hwndStatic); + g_hwndStatic = NULL; + } + if (g_hwndProgressBar) + { + DestroyWindow(g_hwndProgressBar); + g_hwndProgressBar = NULL; + } + childwnd = NULL; + } + } + else if (message == WM_COMMAND && LOWORD(wParam) == IDCANCEL) + { + g_cancelled = 1; + } + else + { + return CallWindowProc( + (WNDPROC) lpWndProcOld, + hwnd, + message, + wParam, + lParam + ); + } + return 0; +} + +extern "C" BOOL APIENTRY DllMain(HINSTANCE _hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + hModule = _hModule; + return TRUE; +} + +#define INT32_MAX 0x7fffffff + +int MulDiv64(int nNumber, __int64 nNumerator, __int64 nDenominator) +{ + // ok, a complete implementation would handle negatives too, + // but this method is probably not generally useful. + while (nNumerator > INT32_MAX || nDenominator > INT32_MAX) + { + nNumerator = Int64ShraMod32(nNumerator, 1); + nDenominator = Int64ShraMod32(nDenominator, 1); + } + return MulDiv(nNumber, (int)nNumerator, (int)nDenominator); +} + + +static __int64 g_file_size; +static DWORD g_dwLastTick = 0; +void progress_callback(char *msg, __int64 read_bytes) +{ + // flicker reduction by A. Schiffler + DWORD dwLastTick = g_dwLastTick; + DWORD dwThisTick = GetTickCount(); + if (childwnd) + { + if (dwThisTick - dwLastTick > 500) + { + SetWindowTextA(g_hwndStatic, msg); + dwLastTick = dwThisTick; + } + if (g_file_size) + SendMessage(g_hwndProgressBar, PBM_SETPOS, (WPARAM) MulDiv64(30000, read_bytes, g_file_size), 0); + g_dwLastTick = dwLastTick; + } +} + +extern char *_strstr(char *i, char *s); +#define strstr _strstr + +extern "C" +{ + +__declspec(dllexport) void download (HWND parent, + int string_size, + TCHAR *variables, + stack_t **stacktop) +{ + char buf[1024]; + char url[1024]; + char filename[1024]; + static char proxy[1024]; + BOOL bSuccess=FALSE; + int timeout_ms=30000; + int getieproxy=1; + int manualproxy=0; + int translation_version; + + char *error=NULL; + + // translation version 2 & 1 + static char szDownloading[1024]; // "Downloading %s" + static char szConnecting[1024]; // "Connecting ..." + static char szSecond[1024]; // " (1 second remaining)" for v2 + // "second" for v1 + static char szMinute[1024]; // " (1 minute remaining)" for v2 + // "minute" for v1 + static char szHour[1024]; // " (1 hour remaining)" for v2 + // "hour" for v1 + static char szProgress[1024]; // "%skB (%d%%) of %skB at %u.%01ukB/s" for v2 + // "%dkB (%d%%) of %dkB at %d.%01dkB/s" for v1 + + // translation version 2 only + static char szSeconds[1024]; // " (%u seconds remaining)" + static char szMinutes[1024]; // " (%u minutes remaining)" + static char szHours[1024]; // " (%u hours remaining)" + + // translation version 1 only + static char szPlural[1024]; // "s"; + static char szRemaining[1024]; // " (%d %s%s remaining)"; + + EXDLL_INIT(); + + PopStringA(url); + if (!lstrcmpiA(url, "/TRANSLATE2")) { + PopStringA(szDownloading); + PopStringA(szConnecting); + PopStringA(szSecond); + PopStringA(szMinute); + PopStringA(szHour); + PopStringA(szSeconds); + PopStringA(szMinutes); + PopStringA(szHours); + PopStringA(szProgress); + PopStringA(url); + translation_version=2; + } else if (!lstrcmpiA(url, "/TRANSLATE")) { + PopStringA(szDownloading); + PopStringA(szConnecting); + PopStringA(szSecond); + PopStringA(szMinute); + PopStringA(szHour); + PopStringA(szPlural); + PopStringA(szProgress); + PopStringA(szRemaining); + PopStringA(url); + translation_version=1; + } else { + lstrcpyA(szDownloading, "Downloading %s"); + lstrcpyA(szConnecting, "Connecting ..."); + lstrcpyA(szSecond, " (1 second remaining)"); + lstrcpyA(szMinute, " (1 minute remaining)"); + lstrcpyA(szHour, " (1 hour remaining)"); + lstrcpyA(szSeconds, " (%u seconds remaining)"); + lstrcpyA(szMinutes, " (%u minutes remaining)"); + lstrcpyA(szHours, " (%u hours remaining)"); + lstrcpyA(szProgress, "%skB (%d%%) of %skB at %u.%01ukB/s"); + translation_version=2; + } + lstrcpynA(buf, url, 10); + if (!lstrcmpiA(buf, "/TIMEOUT=")) { + timeout_ms=my_atoi(url+9); + PopStringA(url); + } + if (!lstrcmpiA(url, "/PROXY")) { + getieproxy=0; + manualproxy=1; + PopStringA(proxy); + PopStringA(url); + } + if (!lstrcmpiA(url, "/NOIEPROXY")) { + getieproxy=0; + PopStringA(url); + } + PopStringA(filename); + + HANDLE hFile = CreateFileA(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + wsprintfA(buf, "Unable to open %s", filename); + error = buf; + } + else + { + if (parent) + { + uMsgCreate = RegisterWindowMessage(_T("nsisdl create")); + + lpWndProcOld = (void *)SetWindowLong(parent,GWL_WNDPROC,(long)ParentWndProc); + + SendMessage(parent, uMsgCreate, TRUE, (LPARAM) parent); + + // set initial text + char *p = filename; + while (*p) p++; + while (*p !='\\' && p != filename) p = CharPrevA(filename, p); + wsprintfA(buf, szDownloading, p != filename ? p + 1 : p); + SetDlgItemTextA(childwnd, 1006, buf); + SetWindowTextA(g_hwndStatic, szConnecting); + } + { + WSADATA wsaData; + WSAStartup(MAKEWORD(1, 1), &wsaData); + + JNL_HTTPGet *get = 0; + + static char main_buf[8192]; + char *buf=main_buf; + char *p=NULL; + + HKEY hKey; + if (getieproxy && RegOpenKeyExA(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS) + { + DWORD l = 4; + DWORD t; + DWORD v; + if (RegQueryValueExA(hKey,"ProxyEnable",NULL,&t,(unsigned char*)&v,&l) == ERROR_SUCCESS && t == REG_DWORD && v) + { + l=8192; + if (RegQueryValueExA(hKey,"ProxyServer",NULL,&t,(unsigned char *)buf,&l ) == ERROR_SUCCESS && t == REG_SZ) + { + p=strstr(buf,"http="); + if (!p) p=buf; + else { + p+=5; + } + char *tp=strstr(p,";"); + if (tp) *tp=0; + char *p2=strstr(p,"="); + if (p2) p=0; // we found the wrong proxy + } + } + buf[8192-1]=0; + RegCloseKey(hKey); + } + if (manualproxy == 1) { + p = proxy; + } + + DWORD start_time=GetTickCount(); + get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL); + int st; + int has_printed_headers = 0; + __int64 cl = 0; + int len; + __int64 sofar = 0; + DWORD last_recv_time=start_time; + + get->addheader ("User-Agent: NSISDL/1.2 (Mozilla)"); + get->addheader ("Accept: */*"); + + get->connect (url); + + while (1) { + if (g_cancelled) + error = "cancel"; + + if (error) + { + if (parent) + { + SendMessage(parent, uMsgCreate, FALSE, (LPARAM) parent); + SetWindowLong(parent, GWL_WNDPROC, (long)lpWndProcOld); + } + break; + } + + st = get->run (); + + if (st == -1) { + lstrcpynA(url, get->geterrorstr(), sizeof(url)); + error = url; + } else if (st == 1) { + if (sofar < cl || get->get_status () != 2) + error="download incomplete"; + else + { + bSuccess=TRUE; + error = "success"; + } + } else { + + if (get->get_status () == 0) { + // progressFunc ("Connecting ...", 0); + if (last_recv_time+timeout_ms < GetTickCount()) + error = "Timed out on connecting."; + else + Sleep(10); // don't busy-loop while connecting + + } else if (get->get_status () == 1) { + + progress_callback("Reading headers", 0); + if (last_recv_time+timeout_ms < GetTickCount()) + error = "Timed out on getting headers."; + else + Sleep(10); // don't busy-loop while reading headers + + } else if (get->get_status () == 2) { + + if (! has_printed_headers) { + has_printed_headers = 1; + last_recv_time=GetTickCount(); + + cl = get->content_length (); + if (cl == 0) + error = "Server did not specify content length."; + else if (g_hwndProgressBar) { + SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 30000)); + g_file_size = cl; + } + } + + int data_downloaded = 0; + while ((len = get->bytes_available ()) > 0) { + data_downloaded++; + if (len > 8192) + len = 8192; + len = get->get_bytes (buf, len); + if (len > 0) { + last_recv_time=GetTickCount(); + DWORD dw; + WriteFile(hFile,buf,len,&dw,NULL); + sofar += len; + int time_sofar=(GetTickCount()-start_time)/1000; + int bps = (int)(sofar/(time_sofar?time_sofar:1)); + int remain = MulDiv64(time_sofar, cl, sofar) - time_sofar; + + if (translation_version == 2) { + char *rtext=remain==1?szSecond:szSeconds;; + if (remain >= 60) + { + remain/=60; + rtext=remain==1?szMinute:szMinutes; + if (remain >= 60) + { + remain/=60; + rtext=remain==1?szHour:szHours; + } + } + + char sofar_str[128]; + char cl_str[128]; + myitoa64(sofar/1024, sofar_str); + myitoa64(cl/1024, cl_str); + + wsprintfA (buf, + szProgress, //%skB (%d%%) of %skB @ %u.%01ukB/s + sofar_str, + MulDiv64(100, sofar, cl), + cl_str, + bps/1024,((bps*10)/1024)%10 + ); + if (remain) wsprintfA(buf+lstrlenA(buf),rtext, + remain + ); + } else if (translation_version == 1) { + char *rtext=szSecond; + if (remain >= 60) + { + remain/=60; + rtext=szMinute; + if (remain >= 60) + { + remain/=60; + rtext=szHour; + } + } + + wsprintfA (buf, + szProgress, //%dkB (%d%%) of %dkB @ %d.%01dkB/s + int(sofar/1024), + MulDiv64(100, sofar, cl), + int(cl/1024), + bps/1024,((bps*10)/1024)%10 + ); + if (remain) wsprintfA(buf+lstrlenA(buf),szRemaining, + remain, + rtext, + remain==1?"":szPlural + ); + } + progress_callback(buf, sofar); + } else { + if (sofar < cl) + error = "Server aborted."; + } + } + if (GetTickCount() > last_recv_time+timeout_ms) + { + if (sofar != cl) + { + error = "Downloading timed out."; + } + else + { + // workaround for bug #1713562 + // buggy servers that wait for the client to close the connection. + // another solution would be manually stopping when cl == sofar, + // but then buggy servers that return wrong content-length will fail. + bSuccess = TRUE; + error = "success"; + } + } + else if (!data_downloaded) + Sleep(10); + + } else { + error = "Bad response status."; + } + } + + } + + // Clean up the connection then release winsock + if (get) delete get; + WSACleanup(); + } + + CloseHandle(hFile); + } + + if (g_cancelled || !bSuccess) { + DeleteFileA(filename); + } + + PushStringA(error); +} + + +__declspec(dllexport) void download_quiet(HWND parent, + int stringsize, + TCHAR *variables, + stack_t **stacktop) +{ + g_hwndProgressBar=0; + download(NULL,stringsize,variables,stacktop); +} + +} //extern "C" diff --git a/Contrib/NSISdl/util.cpp b/Contrib/NSISdl/util.cpp index e81b6496..c7d1c877 100644 --- a/Contrib/NSISdl/util.cpp +++ b/Contrib/NSISdl/util.cpp @@ -1,85 +1,88 @@ -/* -** JNetLib -** Copyright (C) 2000-2001 Nullsoft, Inc. -** Author: Justin Frankel -** File: util.cpp - JNL implementation of basic network utilities -** License: see jnetlib.h -*/ - -#include "netinc.h" - -#include "util.h" - -int my_atoi(char *s) -{ - int sign=0; - int v=0; - if (*s == '-') { s++; sign++; } - for (;;) - { - int c=*s++ - '0'; - if (c < 0 || c > 9) break; - v*=10; - v+=c; - } - if (sign) return -(int) v; - return (int)v; -} - -__int64 myatoi64(char *s) -{ - __int64 v=0; - int sign=0; - - if (*s == '-') - sign++; - else - s--; - - for (;;) - { - int c=*(++s) - '0'; - if (c < 0 || c > 9) break; - v*=10; - v+=c; - } - - if (sign) - v = -v; - - return v; -} - -void myitoa64(__int64 i, char *buffer) -{ - char buf[128], *b = buf; - - if (i < 0) - { - *(buffer++) = '-'; - i = -i; - } - if (i == 0) *(buffer++) = '0'; - else - { - while (i > 0) - { - *(b++) = '0' + ((char) (i%10)); - i /= 10; - } - while (b > buf) *(buffer++) = *(--b); - } - *buffer = 0; -} - -void mini_memset(void *o,char i,int l) -{ - char *oo=(char*)o; - while (l-- > 0) *oo++=i; -} -void mini_memcpy(void *o,void*i,int l) -{ - char *oo=(char*)o; - char *ii=(char*)i; - while (l-- > 0) *oo++=*ii++; -} +/* +** JNetLib +** Copyright (C) 2000-2001 Nullsoft, Inc. +** Author: Justin Frankel +** File: util.cpp - JNL implementation of basic network utilities +** License: see jnetlib.h +** +** Unicode support by Jim Park -- 08/24/2007 +** Keep everything here strictly ANSI. No TCHAR style stuff. +*/ + +#include "netinc.h" + +#include "util.h" + +int my_atoi(char *s) +{ + int sign=0; + int v=0; + if (*s == '-') { s++; sign++; } + for (;;) + { + int c=*s++ - '0'; + if (c < 0 || c > 9) break; + v*=10; + v+=c; + } + if (sign) return -(int) v; + return (int)v; +} + +__int64 myatoi64(char *s) +{ + __int64 v=0; + int sign=0; + + if (*s == '-') + sign++; + else + s--; + + for (;;) + { + int c=*(++s) - '0'; + if (c < 0 || c > 9) break; + v*=10; + v+=c; + } + + if (sign) + v = -v; + + return v; +} + +void myitoa64(__int64 i, char *buffer) +{ + char buf[128], *b = buf; + + if (i < 0) + { + *(buffer++) = '-'; + i = -i; + } + if (i == 0) *(buffer++) = '0'; + else + { + while (i > 0) + { + *(b++) = '0' + ((char) (i%10)); + i /= 10; + } + while (b > buf) *(buffer++) = *(--b); + } + *buffer = 0; +} + +void mini_memset(void *o,char i,int l) +{ + char *oo=(char*)o; + while (l-- > 0) *oo++=i; +} +void mini_memcpy(void *o,void*i,int l) +{ + char *oo=(char*)o; + char *ii=(char*)i; + while (l-- > 0) *oo++=*ii++; +} diff --git a/Contrib/NSISdl/util.h b/Contrib/NSISdl/util.h index 6be0704c..c612d15c 100644 --- a/Contrib/NSISdl/util.h +++ b/Contrib/NSISdl/util.h @@ -1,36 +1,38 @@ -/* -** JNetLib -** Copyright (C) 2000-2001 Nullsoft, Inc. -** Author: Justin Frankel -** File: util.h - JNL interface for basic network utilities -** License: see jnetlib.h -** -** routines you may be interested in: -** JNL::open_socketlib(); -** opens the socket library. Call this once before using any network -** code. If you create a new thread, call this again. Only really an -** issue for Win32 support, but use it anyway for portability/ -** -** JNL::close_Socketlib(); -** closes the socketlib. Call this when you're done with the network, -** after all your JNetLib objects have been destroyed. -** -** unsigned long JNL::ipstr_to_addr(const char *cp); -** gives you the integer representation of a ip address in dotted -** decimal form. -** -** JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen); -** gives you the dotted decimal notation of an integer ip address. -** -*/ - -#ifndef _UTIL_H_ -#define _UTIL_H_ - -int my_atoi(char *p); -__int64 myatoi64(char *s); -void myitoa64(__int64 i, char *buffer); -void mini_memset(void *,char,int); -void mini_memcpy(void *,void*,int); - -#endif //_UTIL_H_ +/* +** JNetLib +** Copyright (C) 2000-2001 Nullsoft, Inc. +** Author: Justin Frankel +** File: util.h - JNL interface for basic network utilities +** License: see jnetlib.h +** +** routines you may be interested in: +** JNL::open_socketlib(); +** opens the socket library. Call this once before using any network +** code. If you create a new thread, call this again. Only really an +** issue for Win32 support, but use it anyway for portability/ +** +** JNL::close_Socketlib(); +** closes the socketlib. Call this when you're done with the network, +** after all your JNetLib objects have been destroyed. +** +** unsigned long JNL::ipstr_to_addr(const char *cp); +** gives you the integer representation of a ip address in dotted +** decimal form. +** +** JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen); +** gives you the dotted decimal notation of an integer ip address. +** +** Reviewed for Unicode support by Jim Park -- 08/24/2007 +** Keep the functions here strictly ANSI. +*/ + +#ifndef _UTIL_H_ +#define _UTIL_H_ + +int my_atoi(char *p); +__int64 myatoi64(char *s); +void myitoa64(__int64 i, char *buffer); +void mini_memset(void *,char,int); +void mini_memcpy(void *,void*,int); + +#endif //_UTIL_H_ diff --git a/Contrib/Splash/splash.c b/Contrib/Splash/splash.c index efc36fc9..8c175e71 100644 --- a/Contrib/Splash/splash.c +++ b/Contrib/Splash/splash.c @@ -13,7 +13,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar { BITMAP bm; RECT vp; - GetObject(g_hbm, sizeof(bm), (LPSTR)&bm); + GetObject(g_hbm, sizeof(bm), (LPTSTR)&bm); SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0); SetWindowLong(hwnd,GWL_STYLE,0); SetWindowPos(hwnd,NULL, @@ -55,11 +55,11 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) return TRUE; } -void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +void __declspec(dllexport) show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { - char fn[MAX_PATH]; - char temp[64]; - char *sleep=temp; + TCHAR fn[MAX_PATH]; + TCHAR temp[64]; + TCHAR *sleep=temp; EXDLL_INIT(); @@ -68,16 +68,16 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variable popstring(fn); sleep_val=0; - while (*sleep >= '0' && *sleep <= '9') + while (*sleep >= _T('0') && *sleep <= _T('9')) { sleep_val*=10; - sleep_val+=*sleep++-'0'; + sleep_val+=*sleep++-_T('0'); } if (fn[0] && sleep_val>0) { MSG msg; - char classname[4]="_sp"; + TCHAR classname[4]=_T("_sp"); static WNDCLASS wc; wc.lpfnWndProc = WndProc; wc.hInstance = g_hInstance; @@ -85,10 +85,10 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variable wc.lpszClassName = classname; if (RegisterClass(&wc)) { - char fn2[MAX_PATH]; + TCHAR fn2[MAX_PATH]; lstrcpy(fn2,fn); - lstrcat(fn,".bmp"); - lstrcat(fn2,".wav"); + lstrcat(fn,_T(".bmp")); + lstrcat(fn2,_T(".wav")); g_hbm=LoadImage(NULL,fn,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE); if (g_hbm) { @@ -114,6 +114,6 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variable } } } - wsprintf(temp,"%d",g_rv); + wsprintf(temp,_T("%d"),g_rv); pushstring(temp); } diff --git a/Contrib/StartMenu/StartMenu.c b/Contrib/StartMenu/StartMenu.c index d3f916b8..a87aaefd 100644 --- a/Contrib/StartMenu/StartMenu.c +++ b/Contrib/StartMenu/StartMenu.c @@ -10,11 +10,11 @@ HWND hwChild; HWND g_hwStartMenuSelect; HWND g_hwDirList; -char buf[1024]; -char text[1024]; -char progname[1024]; -char lastused[1024]; -char checkbox[1024]; +TCHAR buf[1024]; +TCHAR text[1024]; +TCHAR progname[1024]; +TCHAR lastused[1024]; +TCHAR checkbox[1024]; int autoadd; int g_done; @@ -23,7 +23,7 @@ int rtl; void *lpWndProcOld; -void (__stdcall *validate_filename)(char *); +void (__stdcall *validate_filename)(TCHAR *); BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); static BOOL CALLBACK ParentWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -34,7 +34,7 @@ static UINT_PTR PluginCallback(enum NSPIM msg) return 0; } -void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) Init(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { HWND hwStartMenuSelect; @@ -62,35 +62,35 @@ void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variable hwChild = GetDlgItem(hwndParent, 1018); if (!hwChild) { - pushstring("error finding childwnd"); + pushstring(_T("error finding childwnd")); return; } popstring(buf); - while (buf[0] == '/') + while (buf[0] == _T('/')) { - if (!lstrcmpi(buf+1, "noicon")) + if (!lstrcmpi(buf+1, _T("noicon"))) { noicon = 1; } - else if (!lstrcmpi(buf+1, "rtl")) + else if (!lstrcmpi(buf+1, _T("rtl"))) { rtl = 1; } - else if (!lstrcmpi(buf+1, "text")) + else if (!lstrcmpi(buf+1, _T("text"))) { popstring(text); } - else if (!lstrcmpi(buf+1, "autoadd")) + else if (!lstrcmpi(buf+1, _T("autoadd"))) { autoadd = 1; } - else if (!lstrcmpi(buf+1, "lastused")) + else if (!lstrcmpi(buf+1, _T("lastused"))) { popstring(lastused); } - else if (!lstrcmpi(buf+1, "checknoshortcuts")) + else if (!lstrcmpi(buf+1, _T("checknoshortcuts"))) { popstring(checkbox); } @@ -107,7 +107,7 @@ void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variable } else { - pushstring("error reading parameters"); + pushstring(_T("error reading parameters")); return; } @@ -115,19 +115,19 @@ void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variable g_hwStartMenuSelect = hwStartMenuSelect; if (!hwStartMenuSelect) { - pushstring("error creating dialog"); + pushstring(_T("error creating dialog")); return; } else { lpWndProcOld = (void *) SetWindowLong(hwndParent, DWL_DLGPROC, (long) ParentWndProc); - wsprintf(buf, "%u", hwStartMenuSelect); + wsprintf(buf, _T("%u"), hwStartMenuSelect); pushstring(buf); } } } -void __declspec(dllexport) Show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +void __declspec(dllexport) Show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { HWND hwStartMenuSelect = g_hwStartMenuSelect; @@ -148,7 +148,7 @@ void __declspec(dllexport) Show(HWND hwndParent, int string_size, char *variable SetWindowLong(hwndParent, DWL_DLGPROC, (long) lpWndProcOld); } -void __declspec(dllexport) Select(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) Select(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { Init(hwndParent, string_size, variables, stacktop, extra); if (g_hwStartMenuSelect) @@ -312,7 +312,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) ); } - SetWindowText(hwText, *text ? text : "Select the Start Menu folder in which you would like to create the program's shortcuts:"); + SetWindowText(hwText, *text ? text : _T("Select the Start Menu folder in which you would like to create the program's shortcuts:")); ProgressiveSetWindowPos( hwLocation, @@ -321,7 +321,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) MulDiv(12, baseUnitY, 8) ); - if (*lastused == '>') + if (*lastused == _T('>')) { CheckDlgButton(hwndDlg, IDC_CHECK, BST_CHECKED); lstrcpy(lastused, lstrcpy(buf, lastused) + 1); @@ -370,7 +370,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { SendMessage(hwDirList, LB_GETTEXT, SendMessage(hwDirList, LB_GETCURSEL, 0, 0), (WPARAM)buf); if (autoadd) - lstrcat(lstrcat(buf, "\\"), progname); + lstrcat(lstrcat(buf, _T("\\")), progname); SetWindowText(hwLocation, buf); } else if (LOWORD(wParam) == IDC_CHECK && HIWORD(wParam) == BN_CLICKED) @@ -383,27 +383,27 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { GetWindowText(hwLocation, buf, MAX_PATH); validate_filename(buf); - EnableWindow(GetDlgItem(hwParent, IDOK), *buf != '\0'); + EnableWindow(GetDlgItem(hwParent, IDOK), *buf != _T('\0')); } break; case WM_USER+666: g_done = 1; if (wParam == NOTIFY_BYE_BYE) - pushstring("cancel"); + pushstring(_T("cancel")); else { GetWindowText(hwLocation, buf + 1, MAX_PATH); validate_filename(buf); if (IsDlgButtonChecked(hwndDlg, IDC_CHECK) == BST_CHECKED) { - buf[0] = '>'; + buf[0] = _T('>'); pushstring(buf); } else { pushstring(buf + 1); } - pushstring("success"); + pushstring(_T("success")); } case WM_CTLCOLORSTATIC: case WM_CTLCOLOREDIT: @@ -440,7 +440,7 @@ void AddFolderFromReg(int nFolder) if (!buf[0]) return; - lstrcat(buf, "\\*.*"); + lstrcat(buf, _T("\\*.*")); hSearch = FindFirstFile(buf, &FileData); if (hSearch != INVALID_HANDLE_VALUE) { @@ -448,9 +448,9 @@ void AddFolderFromReg(int nFolder) { if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - if (*(WORD*)FileData.cFileName != *(WORD*)".") + if (*(WORD*)FileData.cFileName != *(WORD*)_T(".")) { - if (*(WORD*)FileData.cFileName != *(WORD*)".." || FileData.cFileName[2]) + if (*(WORD*)FileData.cFileName != *(WORD*)_T("..") || FileData.cFileName[2]) { if (SendMessage(g_hwDirList, LB_FINDSTRINGEXACT, (WPARAM) -1, (LPARAM)FileData.cFileName) == LB_ERR) SendMessage(g_hwDirList, LB_ADDSTRING, 0, (LPARAM)FileData.cFileName); diff --git a/Contrib/System/Source/Buffers.c b/Contrib/System/Source/Buffers.c index 00e055d6..d4274b69 100644 --- a/Contrib/System/Source/Buffers.c +++ b/Contrib/System/Source/Buffers.c @@ -7,7 +7,7 @@ typedef struct tagTempStack TempStack; struct tagTempStack { TempStack *Next; - char Data[0]; + TCHAR Data[0]; }; TempStack *tempstack = NULL; @@ -27,12 +27,12 @@ PLUGINFUNCTIONSHORT(Copy) { int size = 0; HANDLE source, dest; - char *str; + TCHAR *str; // Get the string if ((str = system_popstring()) == NULL) return; // Check for size option - if (str[0] == '/') + if (str[0] == _T('/')) { size = (int) myatoi64(str+1); dest = (HANDLE) popint64(); @@ -65,15 +65,15 @@ PLUGINFUNCTIONEND PLUGINFUNCTION(Store) { TempStack *tmp; - int size = ((INST_R9+1)*g_stringsize); + int size = ((INST_R9+1)*g_stringsize*sizeof(TCHAR)); - char *command, *cmd = command = system_popstring(); + TCHAR *command, *cmd = command = system_popstring(); while (*cmd != 0) { switch (*(cmd++)) { - case 's': - case 'S': + case _T('s'): + case _T('S'): // Store the whole variables range tmp = (TempStack*) GlobalAlloc(GPTR, sizeof(TempStack)+size); tmp->Next = tempstack; @@ -82,8 +82,8 @@ PLUGINFUNCTION(Store) // Fill with data copymem(tempstack->Data, g_variables, size); break; - case 'l': - case 'L': + case _T('l'): + case _T('L'): if (tempstack == NULL) break; // Fill with data @@ -94,15 +94,15 @@ PLUGINFUNCTION(Store) GlobalFree((HANDLE) tempstack); tempstack = tmp; break; - case 'P': + case _T('P'): *cmd += 10; - case 'p': - GlobalFree((HANDLE) system_pushstring(system_getuservariable(*(cmd++)-'0'))); + case _T('p'): + GlobalFree((HANDLE) system_pushstring(system_getuservariable(*(cmd++)-_T('0')))); break; - case 'R': + case _T('R'): *cmd += 10; - case 'r': - GlobalFree((HANDLE) system_setuservariable(*(cmd++)-'0', system_popstring())); + case _T('r'): + GlobalFree((HANDLE) system_setuservariable(*(cmd++)-_T('0'), system_popstring())); break; } } diff --git a/Contrib/System/Source/Plugin.c b/Contrib/System/Source/Plugin.c index 84913e04..e46992bf 100644 --- a/Contrib/System/Source/Plugin.c +++ b/Contrib/System/Source/Plugin.c @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 08/23/2007 + #include "stdafx.h" #include "Plugin.h" #include "Buffers.h" @@ -5,19 +7,19 @@ HWND g_hwndParent; -char *AllocString() +TCHAR *AllocString() { - return (char*) GlobalAlloc(GPTR,g_stringsize); + return (TCHAR*) GlobalAlloc(GPTR,g_stringsize*sizeof(TCHAR)); } -char *AllocStr(char *str) +TCHAR *AllocStr(TCHAR *str) { return lstrcpy(AllocString(), str); } -char* system_popstring() +TCHAR* system_popstring() { - char *str; + TCHAR *str; stack_t *th; if (!g_stacktop || !*g_stacktop) return NULL; @@ -31,24 +33,24 @@ char* system_popstring() return str; } -char *system_pushstring(char *str) +TCHAR *system_pushstring(TCHAR *str) { stack_t *th; if (!g_stacktop) return str; - th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize); + th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+(g_stringsize*sizeof(TCHAR))); lstrcpyn(th->text,str,g_stringsize); th->next=*g_stacktop; *g_stacktop=th; return str; } -char *system_getuservariable(int varnum) +TCHAR *system_getuservariable(int varnum) { if (varnum < 0 || varnum >= __INST_LAST) return AllocString(); return AllocStr(g_variables+varnum*g_stringsize); } -char *system_setuservariable(int varnum, char *var) +TCHAR *system_setuservariable(int varnum, TCHAR *var) { if (var != NULL && varnum >= 0 && varnum < __INST_LAST) { lstrcpy (g_variables + varnum*g_stringsize, var); @@ -57,31 +59,31 @@ char *system_setuservariable(int varnum, char *var) } // Updated for int64 and simple bitwise operations -__int64 myatoi64(char *s) +__int64 myatoi64(TCHAR *s) { __int64 v=0; // Check for right input if (!s) return 0; - if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) + if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X'))) { s++; for (;;) { int c=*(++s); - if (c >= '0' && c <= '9') c-='0'; - else if (c >= 'a' && c <= 'f') c-='a'-10; - else if (c >= 'A' && c <= 'F') c-='A'-10; + if (c >= _T('0') && c <= _T('9')) c-=_T('0'); + else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10; + else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10; else break; v<<=4; v+=c; } } - else if (*s == '0' && s[1] <= '7' && s[1] >= '0') + else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0')) { for (;;) { int c=*(++s); - if (c >= '0' && c <= '7') c-='0'; + if (c >= _T('0') && c <= _T('7')) c-=_T('0'); else break; v<<=3; v+=c; @@ -90,10 +92,10 @@ __int64 myatoi64(char *s) else { int sign=0; - if (*s == '-') sign++; else s--; + if (*s == _T('-')) sign++; else s--; for (;;) { - int c=*(++s) - '0'; + int c=*(++s) - _T('0'); if (c < 0 || c > 9) break; v*=10; v+=c; @@ -102,7 +104,7 @@ __int64 myatoi64(char *s) } // Support for simple ORed expressions - if (*s == '|') + if (*s == _T('|')) { v |= myatoi64(s+1); } @@ -110,21 +112,21 @@ __int64 myatoi64(char *s) return v; } -void myitoa64(__int64 i, char *buffer) +void myitoa64(__int64 i, TCHAR *buffer) { - char buf[128], *b = buf; + TCHAR buf[128], *b = buf; if (i < 0) { - *(buffer++) = '-'; + *(buffer++) = _T('-'); i = -i; } - if (i == 0) *(buffer++) = '0'; + if (i == 0) *(buffer++) = _T('0'); else { while (i > 0) { - *(b++) = '0' + ((char) (i%10)); + *(b++) = _T('0') + ((TCHAR) (i%10)); i /= 10; } while (b > buf) *(buffer++) = *(--b); @@ -135,7 +137,7 @@ void myitoa64(__int64 i, char *buffer) int popint64() { int value; - char *str; + TCHAR *str; if ((str = system_popstring()) == NULL) return -1; value = (int) myatoi64(str); GlobalFree(str); @@ -144,14 +146,14 @@ int popint64() void system_pushint(int value) { - char buffer[1024]; - wsprintf(buffer, "%d", value); + TCHAR buffer[1024]; + wsprintf(buffer, _T("%d"), value); system_pushstring(buffer); } -char *copymem(char *output, char *input, int size) +TCHAR *copymem(TCHAR *output, TCHAR *input, int size) { - char *out = output; + TCHAR *out = output; if ((input != NULL) && (output != NULL)) while (size-- > 0) *(out++) = *(input++); return output; diff --git a/Contrib/System/Source/Plugin.h b/Contrib/System/Source/Plugin.h index a448ab89..6400f469 100644 --- a/Contrib/System/Source/Plugin.h +++ b/Contrib/System/Source/Plugin.h @@ -5,29 +5,29 @@ #define PLUGINFUNCTION(name) \ void __declspec(dllexport) name( \ - HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) { \ + HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { \ /*g_hwndParent=hwndParent;*/ \ EXDLL_INIT(); \ extra->RegisterPluginCallback(g_hInstance, NSISCallback); #define PLUGINFUNCTIONEND } -#define PLUGINFUNCTIONSHORT(name) void __declspec(dllexport) name(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { \ +#define PLUGINFUNCTIONSHORT(name) void __declspec(dllexport) name(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { \ g_stringsize=string_size; \ g_stacktop=stacktop; -extern char *AllocStr(char *str); -extern void myitoa64(__int64 i, char *buffer); -extern char *AllocString(); -extern char *system_getuservariable(int varnum); -extern char *system_setuservariable(int varnum, char *var); -extern char* system_popstring(); // NULL - stack empty -extern char* system_pushstring(char *str); -extern __int64 myatoi64(char *s); +extern TCHAR *AllocStr(TCHAR *str); +extern void myitoa64(__int64 i, TCHAR *buffer); +extern TCHAR *AllocString(); +extern TCHAR *system_getuservariable(int varnum); +extern TCHAR *system_setuservariable(int varnum, TCHAR *var); +extern TCHAR* system_popstring(); // NULL - stack empty +extern TCHAR* system_pushstring(TCHAR *str); +extern __int64 myatoi64(TCHAR *s); extern int popint64(); // -1 -> stack empty extern void system_pushint(int value); extern HANDLE GlobalCopy(HANDLE Old); -extern char *copymem(char *output, char *input, int size); +extern TCHAR *copymem(TCHAR *output, TCHAR *input, int size); extern UINT_PTR NSISCallback(enum NSPIM); diff --git a/Contrib/System/Source/System.c b/Contrib/System/Source/System.c index 4f93e3ff..a5744165 100644 --- a/Contrib/System/Source/System.c +++ b/Contrib/System/Source/System.c @@ -45,15 +45,15 @@ int CallbackIndex; HINSTANCE g_hInstance; // Return to callback caller with stack restore -char retexpr[4]; +TCHAR retexpr[4]; HANDLE retaddr; -char *GetResultStr(SystemProc *proc) +TCHAR *GetResultStr(SystemProc *proc) { - char *buf = AllocString(); - if (proc->ProcResult == PR_OK) lstrcpy(buf, "ok"); - else if (proc->ProcResult == PR_ERROR) lstrcpy(buf, "error"); - else if (proc->ProcResult == PR_CALLBACK) wsprintf(buf, "callback%d", proc->CallbackIndex); + TCHAR *buf = AllocString(); + if (proc->ProcResult == PR_OK) lstrcpy(buf, _T("ok")); + else if (proc->ProcResult == PR_ERROR) lstrcpy(buf, _T("error")); + else if (proc->ProcResult == PR_CALLBACK) wsprintf(buf, _T("callback%d"), proc->CallbackIndex); return buf; } @@ -61,16 +61,16 @@ char *GetResultStr(SystemProc *proc) // System log debugging turned on #define SYSTEM_LOG_ADD(a) { register int _len = lstrlen(syslogbuf); lstrcpyn(syslogbuf + _len, a, sizeof(syslogbuf) - _len); } -#define SYSTEM_LOG_POST { SYSTEM_LOG_ADD("\n"); WriteToLog(syslogbuf); *syslogbuf = 0; } +#define SYSTEM_LOG_POST { SYSTEM_LOG_ADD(_T("\n")); WriteToLog(syslogbuf); *syslogbuf = 0; } HANDLE logfile = NULL; -char syslogbuf[4096] = ""; +TCHAR syslogbuf[4096] = _T(""); int logop = 0; -void WriteToLog(char *buffer) +void WriteToLog(TCHAR *buffer) { DWORD written; - char timebuffer[128]; + TCHAR timebuffer[128]; GetTickCount(); @@ -78,7 +78,7 @@ void WriteToLog(char *buffer) SetFilePointer(logfile, 0, 0, FILE_END); - wsprintf(timebuffer, "%04d %04d.%03d ", (++logop)%10000, (GetTickCount() / 1000) % 10000, + wsprintf(timebuffer, _T("%04d %04d.%03d "), (++logop)%10000, (GetTickCount() / 1000) % 10000, GetTickCount() % 1000); _RPT0(_CRT_WARN, timebuffer); @@ -91,14 +91,14 @@ void WriteToLog(char *buffer) PLUGINFUNCTION(Debug) { - char *o1; + TCHAR *o1; o1 = system_popstring(); if (logfile == NULL) if (lstrlen(o1) > 0) { SYSTEMTIME t; - char buffer[1024], buftime[1024], bufdate[1024]; + TCHAR buffer[1024], buftime[1024], bufdate[1024]; // Init debugging logfile = CreateFile(o1, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, @@ -110,7 +110,7 @@ PLUGINFUNCTION(Debug) GetLocalTime(&t); GetTimeFormat(LOCALE_SYSTEM_DEFAULT, LOCALE_NOUSEROVERRIDE, &t, NULL, buftime, 1024); GetDateFormat(LOCALE_SYSTEM_DEFAULT, LOCALE_NOUSEROVERRIDE, &t, NULL, bufdate, 1024); - wsprintf(buffer, "System, %s %s [build "__TIME__" "__DATE__"]\n", buftime, bufdate); + wsprintf(buffer, _T("System, %s %s [build "__TIME__" ")__DATE___T("]\n"), buftime, bufdate); WriteToLog(buffer); } else ; else @@ -121,7 +121,7 @@ PLUGINFUNCTION(Debug) } else { // Stop debugging - WriteToLog("Debug stopped.\n\n\n"); + WriteToLog(_T("Debug stopped.\n\n\n")); CloseHandle(logfile); logfile = NULL; } @@ -141,15 +141,15 @@ PLUGINFUNCTION(Get) SystemProc *proc = PrepareProc(FALSE); if (proc == NULL) { - system_pushstring("error"); + system_pushstring(_T("error")); return; } - SYSTEM_LOG_ADD("Get "); + SYSTEM_LOG_ADD(_T("Get ")); SYSTEM_LOG_ADD(proc->DllName); - SYSTEM_LOG_ADD("::"); + SYSTEM_LOG_ADD(_T("::")); SYSTEM_LOG_ADD(proc->ProcName); - SYSTEM_LOG_ADD("\n"); + SYSTEM_LOG_ADD(_T("\n")); SYSTEM_LOG_POST; if ((proc->Options & POPT_ALWRETURN) != 0) { @@ -178,11 +178,11 @@ PLUGINFUNCTION(Call) if (proc == NULL) return; - SYSTEM_LOG_ADD("Call "); + SYSTEM_LOG_ADD(_T("Call ")); SYSTEM_LOG_ADD(proc->DllName); - SYSTEM_LOG_ADD("::"); + SYSTEM_LOG_ADD(_T("::")); SYSTEM_LOG_ADD(proc->ProcName); - SYSTEM_LOG_ADD("\n"); + SYSTEM_LOG_ADD(_T("\n")); if (proc->ProcResult != PR_CALLBACK) ParamAllocate(proc); ParamsIn(proc); @@ -253,13 +253,13 @@ PLUGINFUNCTION(Call) PLUGINFUNCTIONSHORT(Int64Op) { __int64 i1, i2 = 0, i3, i4; - char *op, *o1, *o2; - char buf[128]; + TCHAR *op, *o1, *o2; + TCHAR buf[128]; // Get strings o1 = system_popstring(); op = system_popstring(); i1 = myatoi64(o1); // convert first arg to int64 - if ((*op != '~') && (*op != '!')) + if ((*op != _T('~')) && (*op != _T('!'))) { // get second arg, convert it, free it o2 = system_popstring(); @@ -270,25 +270,25 @@ PLUGINFUNCTIONSHORT(Int64Op) // operation switch (*op) { - case '+': i1 += i2; break; - case '-': i1 -= i2; break; - case '*': i1 *= i2; break; - case '/': - case '%': + case _T('+'): i1 += i2; break; + case _T('-'): i1 -= i2; break; + case _T('*'): i1 *= i2; break; + case _T('/'): + case _T('%'): // It's unclear, but in this case compiler will use DivMod rountine // instead of two separate Div and Mod rountines. if (i2 == 0) { i3 = 0; i4 = i1; } else {i3 = i1 / i2; i4 = i1 % i2; } - if (*op == '/') i1 = i3; else i1 = i4; + if (*op == _T('/')) i1 = i3; else i1 = i4; break; - case '|': if (op[1] == '|') i1 = i1 || i2; else i1 |= i2; break; - case '&': if (op[1] == '&') i1 = i1 && i2; else i1 &= i2; break; - case '^': i1 ^= i2; break; - case '~': i1 = ~i1; break; - case '!': i1 = !i1; break; - case '<': if (op[1] == '<') i1 = i1 << i2; else i1 = i1 < i2; break; - case '>': if (op[1] == '>') i1 = i1 >> i2; else i1 = i1 > i2; break; - case '=': i1 = (i1 == i2); break; + case _T('|'): if (op[1] == _T('|')) i1 = i1 || i2; else i1 |= i2; break; + case _T('&'): if (op[1] == _T('&')) i1 = i1 && i2; else i1 &= i2; break; + case _T('^'): i1 ^= i2; break; + case _T('~'): i1 = ~i1; break; + case _T('!'): i1 = !i1; break; + case _T('<'): if (op[1] == _T('<')) i1 = i1 << i2; else i1 = i1 < i2; break; + case _T('>'): if (op[1] == _T('>')) i1 = i1 >> i2; else i1 = i1 > i2; break; + case _T('='): i1 = (i1 == i2); break; } // Output and freedom @@ -297,11 +297,11 @@ PLUGINFUNCTIONSHORT(Int64Op) GlobalFree(o1); GlobalFree(op); } PLUGINFUNCTIONEND -__int64 GetIntFromString(char **p) +__int64 GetIntFromString(TCHAR **p) { - char buffer[128], *b = buffer; + TCHAR buffer[128], *b = buffer; (*p)++; // First character should be skipped - while (((**p >= 'a') && (**p <= 'f')) || ((**p >= 'A') && (**p <= 'F')) || ((**p >= '0') && (**p <= '9')) || (**p == 'X') || (**p == '-') || (**p == 'x') || (**p == '|')) *(b++) = *((*p)++); + while (((**p >= _T('a')) && (**p <= _T('f'))) || ((**p >= _T('A')) && (**p <= _T('F'))) || ((**p >= _T('0')) && (**p <= _T('9'))) || (**p == _T('X')) || (**p == _T('-')) || (**p == _T('x')) || (**p == _T('|'))) *(b++) = *((*p)++); *b = 0; (*p)--; // We should point at last digit return myatoi64(buffer); @@ -316,7 +316,7 @@ SystemProc *PrepareProc(BOOL NeedForCall) temp = 0, temp2, temp3, temp4; BOOL param_defined = FALSE; SystemProc *proc = NULL; - char *ibuf, *ib, *sbuf, *cbuf, *cb; + TCHAR *ibuf, *ib, *sbuf, *cbuf, *cb; // Retrieve proc specs cb = (cbuf = AllocString()); // Current String buffer @@ -339,16 +339,16 @@ SystemProc *PrepareProc(BOOL NeedForCall) switch (*ib) { case 0x0: SectionType = -1; break; - case '#': SectionType = PST_PROC; ProcType = PT_NOTHING; break; - case '(': + case _T('#'): SectionType = PST_PROC; ProcType = PT_NOTHING; break; + case _T('('): SectionType = PST_PARAMS; // fake-real parameter: for COM interfaces first param is Interface Pointer ParamIndex = ((ProcType == PT_VTABLEPROC)?(2):(1)); temp3 = temp = 0; param_defined = FALSE; break; - case ')': SectionType = PST_RETURN; temp3 = temp = 0; break; - case '?': SectionType = PST_OPTIONS; temp = 1; break; + case _T(')'): SectionType = PST_RETURN; temp3 = temp = 0; break; + case _T('?'): SectionType = PST_OPTIONS; temp = 1; break; default: changed = FALSE; } @@ -437,18 +437,18 @@ SystemProc *PrepareProc(BOOL NeedForCall) case PST_PROC: switch (*ib) { - case ':': - case '-': + case _T(':'): + case _T('-'): // Is it '::' - if ((*(ib) == '-') && (*(ib+1) == '>')) + if ((*(ib) == _T('-')) && (*(ib+1) == _T('>'))) { ProcType = PT_VTABLEPROC; } else { - if ((*(ib+1) != ':') || (*(ib) == '-')) break; + if ((*(ib+1) != _T(':')) || (*(ib) == _T('-'))) break; ProcType = PT_PROC; } - ib++; // Skip next ':' + ib++; // Skip next _T(':') if (cb > cbuf) { @@ -459,7 +459,7 @@ SystemProc *PrepareProc(BOOL NeedForCall) // Ok ChangesDone = PCD_DONE; break; - case '*': + case _T('*'): // Structure defenition ProcType = PT_STRUCT; ChangesDone = PCD_DONE; @@ -474,9 +474,9 @@ SystemProc *PrepareProc(BOOL NeedForCall) temp2 = -1; temp4 = 0; // Our type placeholder switch (*ib) { - case ' ': + case _T(' '): break; - case '_': // No param cutting specifier + case _T('_'): // No param cutting specifier if (proc->ParamCount > ParamIndex) ParamIndex = proc->ParamCount; temp3 = temp = 0; // Clear parameter options if (proc->ParamCount != ((ProcType == PT_VTABLEPROC) ? 1 : 0)) @@ -488,59 +488,59 @@ SystemProc *PrepareProc(BOOL NeedForCall) param_defined = TRUE; } break; - case ',': // Next param + case _T(','): // Next param temp3 = temp = 0; // Clear parameter options ParamIndex++; param_defined = TRUE; break; - case '&': + case _T('&'): temp = 1; break; // Special parameter option - case '*': + case _T('*'): temp = -1; break; // Pointer parameter option // Types - case 'v': - case 'V': temp2 = PAT_VOID; break; - case 'i': - case 'I': temp2 = PAT_INT; break; - case 'l': - case 'L': temp2 = PAT_LONG; break; - case 'm': - case 'M': - case 't': - case 'T': temp2 = PAT_STRING; break; - case 'g': - case 'G': temp2 = PAT_GUID; break; - case 'w': - case 'W': temp2 = PAT_WSTRING; break; - case 'k': - case 'K': temp2 = PAT_CALLBACK; break; + case _T('v'): + case _T('V'): temp2 = PAT_VOID; break; + case _T('i'): + case _T('I'): temp2 = PAT_INT; break; + case _T('l'): + case _T('L'): temp2 = PAT_LONG; break; + case _T('m'): + case _T('M'): + case _T('t'): + case _T('T'): temp2 = PAT_STRING; break; + case _T('g'): + case _T('G'): temp2 = PAT_GUID; break; + case _T('w'): + case _T('W'): temp2 = PAT_WSTRING; break; + case _T('k'): + case _T('K'): temp2 = PAT_CALLBACK; break; // Input output specifiers - case '.': temp3++; break; // skip specifier + case _T('.'): temp3++; break; // skip specifier - case 'R': + case _T('R'): temp4 = ((int) GetIntFromString(&ib))+1; if (temp4 < 11) temp4 += 10; break; - case 'r': temp4 = ((int) GetIntFromString(&ib))+1; break; // Register + case _T('r'): temp4 = ((int) GetIntFromString(&ib))+1; break; // Register - case '-': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case _T('-'): + case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'): + case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'): // Numeric inline if (temp3 == 0) { ib--; // It's stupid, I know, but I'm too laze to do another thing - myitoa64(GetIntFromString(&(ib)),(char *)(temp4 = (int) AllocString())); + myitoa64(GetIntFromString(&(ib)),(TCHAR *)(temp4 = (int) AllocString())); } break; - case '\"': case '\'': case '`': + case _T('\"'): case _T('\''): case _T('`'): // Character inline { - char start = *ib; + TCHAR start = *ib; cb = cbuf; // copy inline while (!((*(++ib) == start) && (*(ib+1) != start)) && (*ib)) @@ -554,18 +554,18 @@ SystemProc *PrepareProc(BOOL NeedForCall) } break; - case 's': - case 'S': temp4 = -1; break; // Stack - case 'c': - case 'C': temp4 = INST_CMDLINE+1; break; - case 'd': - case 'D': temp4 = INST_INSTDIR+1; break; - case 'o': - case 'O': temp4 = INST_OUTDIR+1; break; - case 'e': - case 'E': temp4 = INST_EXEDIR+1; break; - case 'a': - case 'A': temp4 = INST_LANG+1; break; + case _T('s'): + case _T('S'): temp4 = -1; break; // Stack + case _T('c'): + case _T('C'): temp4 = INST_CMDLINE+1; break; + case _T('d'): + case _T('D'): temp4 = INST_INSTDIR+1; break; + case _T('o'): + case _T('O'): temp4 = INST_OUTDIR+1; break; + case _T('e'): + case _T('E'): temp4 = INST_EXEDIR+1; break; + case _T('a'): + case _T('A'): temp4 = INST_LANG+1; break; } // Param type changed? @@ -608,25 +608,25 @@ SystemProc *PrepareProc(BOOL NeedForCall) temp2 = 0; switch (*ib) { - case ' ': + case _T(' '): break; - case '!': temp = -temp; break; - case 'c': + case _T('!'): temp = -temp; break; + case _T('c'): temp2 = POPT_CDECL; break; - case 'r': + case _T('r'): temp2 = POPT_ALWRETURN; break; - case 'n': + case _T('n'): temp2 = POPT_NEVERREDEF; break; - case 's': + case _T('s'): temp2 = POPT_GENSTACK; break; - case 'e': + case _T('e'): temp2 = POPT_ERROR; break; - case 'u': + case _T('u'): temp2 = POPT_UNLOAD; break; } @@ -713,7 +713,7 @@ SystemProc *PrepareProc(BOOL NeedForCall) if ((proc->Proc = GetProcAddress(proc->Dll, proc->ProcName)) == NULL) { // automatic A discover - lstrcat(proc->ProcName, "A"); + lstrcat(proc->ProcName, _T("A")); if ((proc->Proc = GetProcAddress(proc->Dll, proc->ProcName)) == NULL) proc->ProcResult = PR_ERROR; } @@ -742,7 +742,7 @@ void ParamAllocate(SystemProc *proc) void ParamsIn(SystemProc *proc) { int i, *place; - char *realbuf; + TCHAR *realbuf; LPWSTR wstr; i = (proc->ParamCount > 0)?(1):(0); @@ -751,14 +751,14 @@ void ParamsIn(SystemProc *proc) ProcParameter *par = &proc->Params[i]; // Step 1: retrive value if ((par->Input == IOT_NONE) || (par->Input == IOT_INLINE)) - realbuf = AllocStr(""); + realbuf = AllocStr(_T("")); else if (par->Input == IOT_STACK) realbuf = system_popstring(); else if ((par->Input > 0) && (par->Input <= __INST_LAST)) realbuf = system_getuservariable(par->Input - 1); else { // Inline input, will be freed as realbuf - realbuf = (char*) par->Input; + realbuf = (TCHAR*) par->Input; par->Input = IOT_INLINE; } @@ -809,8 +809,8 @@ void ParamsIn(SystemProc *proc) #ifdef SYSTEM_LOG_DEBUG { - char buf[1024]; - wsprintf(buf, "\t\t\tParam In %d: type %d value 0x%08X value2 0x%08X\n", i, + TCHAR buf[1024]; + wsprintf(buf, _T("\t\t\tParam In %d: type %d value 0x%08X value2 0x%08X\n"), i, par->Type, par->Value, par->_value); SYSTEM_LOG_ADD(buf); } @@ -837,7 +837,7 @@ void ParamsDeAllocate(SystemProc *proc) void ParamsOut(SystemProc *proc) { int i, *place; - char *realbuf; + TCHAR *realbuf; LPWSTR wstr; i = proc->ParamCount; @@ -853,19 +853,19 @@ void ParamsOut(SystemProc *proc) switch (proc->Params[i].Type) { case PAT_VOID: - lstrcpy(realbuf,""); + lstrcpy(realbuf,_T("")); break; case PAT_INT: - wsprintf(realbuf, "%d", *((int*) place)); + wsprintf(realbuf, _T("%d"), *((int*) place)); break; case PAT_LONG: myitoa64(*((__int64*) place), realbuf); break; case PAT_STRING: { - unsigned num = lstrlen(*((char**) place)); + unsigned num = lstrlen(*((TCHAR**) place)); if (num >= g_stringsize) num = g_stringsize-1; - lstrcpyn(realbuf,*((char**) place), num+1); + lstrcpyn(realbuf,*((TCHAR**) place), num+1); realbuf[num] = 0; } break; @@ -880,7 +880,7 @@ void ParamsOut(SystemProc *proc) WideCharToMultiByte(CP_ACP, 0, wstr, g_stringsize, realbuf, g_stringsize, NULL, NULL); break; case PAT_CALLBACK: - wsprintf(realbuf, "%d", proc->Params[i].Value); + wsprintf(realbuf, _T("%d"), proc->Params[i].Value); break; } @@ -903,7 +903,7 @@ void ParamsOut(SystemProc *proc) HANDLE CreateCallback(SystemProc *cbproc) { - char *mem; + TCHAR *mem; if (cbproc->Proc == NULL) { @@ -911,11 +911,11 @@ HANDLE CreateCallback(SystemProc *cbproc) cbproc->CallbackIndex = ++(CallbackIndex); cbproc->Options |= POPT_PERMANENT; - mem = (char *) (cbproc->Proc = VirtualAlloc(NULL, 10, MEM_COMMIT, PAGE_EXECUTE_READWRITE)); - *(mem++) = (char) 0xB8; // Mov eax, const + mem = (TCHAR *) (cbproc->Proc = VirtualAlloc(NULL, 10, MEM_COMMIT, PAGE_EXECUTE_READWRITE)); + *(mem++) = (TCHAR) 0xB8; // Mov eax, const *((int *)mem) = (int) cbproc; mem += sizeof(int); - *(mem++) = (char) 0xe9; // Jmp relative + *(mem++) = (TCHAR) 0xe9; // Jmp relative *((int *)mem) = (int) RealCallBack; *((int *)mem) -= ((int) mem) + 4; } @@ -928,9 +928,9 @@ void CallStruct(SystemProc *proc) { BOOL ssflag; int i, structsize = 0, size = 0; - char *st, *ptr; + TCHAR *st, *ptr; - SYSTEM_LOG_ADD("\t\tStruct..."); + SYSTEM_LOG_ADD(_T("\t\tStruct...")); // Calculate the structure size for (i = 1; i <= proc->ParamCount; i++) @@ -947,7 +947,7 @@ void CallStruct(SystemProc *proc) if (structsize == 0) structsize = (int) GlobalSize((HANDLE) proc->Proc); // Pointer to current data - st = (char*) proc->Proc; + st = (TCHAR*) proc->Proc; for (i = 1; i <= proc->ParamCount; i++) { @@ -958,7 +958,7 @@ void CallStruct(SystemProc *proc) { // Normal size = proc->Params[i].Size*4; - ptr = (char*) &(proc->Params[i].Value); + ptr = (TCHAR*) &(proc->Params[i].Value); } else { @@ -979,13 +979,13 @@ void CallStruct(SystemProc *proc) // clear unused value bits proc->Params[i].Value &= intmask[((size >= 0) && (size < 4))?(size):(0)]; // pointer - ptr = (char*) &(proc->Params[i].Value); + ptr = (TCHAR*) &(proc->Params[i].Value); break; case PAT_STRING: case PAT_GUID: case PAT_WSTRING: - ptr = (char*) proc->Params[i].Value; break; + ptr = (TCHAR*) proc->Params[i].Value; break; } } @@ -1037,7 +1037,7 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) LastError = 0; LastProc = NULL; CallbackIndex = 0; - retexpr[0] = (char) 0xC2; + retexpr[0] = (TCHAR) 0xC2; retexpr[2] = 0x00; } @@ -1158,7 +1158,7 @@ unsigned int Get_valueOffsetParam(void) } /* -Sets "CLONE" option +Sets _T("CLONE") option */ void SetCloneOption(SystemProc *proc) { @@ -1166,7 +1166,7 @@ void SetCloneOption(SystemProc *proc) } /* -Sets Result of procedure call to be "OK" +Sets Result of procedure call to be _T("OK") */ void SetProcResultOk(SystemProc *proc) { @@ -1174,7 +1174,7 @@ void SetProcResultOk(SystemProc *proc) } /* -Sets Result of procedure call to be "CALLBACK" +Sets Result of procedure call to be _T("CALLBACK") */ void SetProcResultCallback(SystemProc *proc) { diff --git a/Contrib/System/Source/System.h b/Contrib/System/Source/System.h index d4a23750..b4b01922 100644 --- a/Contrib/System/Source/System.h +++ b/Contrib/System/Source/System.h @@ -73,8 +73,8 @@ struct tag_SystemProc { int ProcType; int ProcResult; - char DllName[1024]; - char ProcName[1024]; + TCHAR DllName[1024]; + TCHAR ProcName[1024]; HANDLE Dll; HANDLE Proc; int Options; diff --git a/Contrib/System/System.nsh b/Contrib/System/System.nsh index b550d19f..2fb789c1 100644 --- a/Contrib/System/System.nsh +++ b/Contrib/System/System.nsh @@ -109,6 +109,7 @@ ; UINT_PTR SetTimer(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc); !define sysSetTimer "user32::SetTimer(i, i, i, k) i" +; DWORD GetLogicalDriveStrings(DWORD nBufferLength, LPTSTR LpBuffer); !define sysGetLogicalDriveStrings 'kernel32::GetLogicalDriveStringsA(i, i) i' !define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l) i' diff --git a/Contrib/UIs/default.rc b/Contrib/UIs/default.rc index 37cf5a25..234f04b4 100644 --- a/Contrib/UIs/default.rc +++ b/Contrib/UIs/default.rc @@ -8,7 +8,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN ICON IDI_ICON2,IDC_ULICON,0,0,22,20 LTEXT "",IDC_INTROTEXT,25,0,241,23 - CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL | + CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x804,0,24,266,105 END @@ -18,7 +18,7 @@ FONT 8, "MS Shell Dlg" BEGIN ICON IDI_ICON2,IDC_ULICON,0,0,22,20 LTEXT "",IDC_INTROTEXT,25,0,241,23 - CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL | + CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x804,0,24,266,85 CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,0,110,266,9 @@ -32,7 +32,7 @@ FONT 8, "MS Shell Dlg" BEGIN ICON IDI_ICON2,IDC_ULICON,0,0,22,20 LTEXT "",IDC_INTROTEXT,25,0,241,23 - CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL | + CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x804,0,24,266,95 CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,0,120,266,9 diff --git a/Contrib/UIs/modern.rc b/Contrib/UIs/modern.rc index 0c760d09..e1258ad4 100644 --- a/Contrib/UIs/modern.rc +++ b/Contrib/UIs/modern.rc @@ -7,7 +7,7 @@ STYLE DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CAPTION FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN LTEXT "",1040,0,0,300,15,NOT WS_GROUP - CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL | + CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x804,0,15,300,93 LTEXT "",IDC_INTROTEXT,0,113,300,26,NOT WS_GROUP END @@ -98,7 +98,7 @@ STYLE DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CAPTION FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN LTEXT "",1040,0,0,300,15,NOT WS_GROUP - CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL | + CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x804,0,15,300,73 LTEXT "",IDC_INTROTEXT,0,93,300,26,NOT WS_GROUP CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTORADIOBUTTON | @@ -112,7 +112,7 @@ STYLE DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CAPTION FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN LTEXT "",1040,0,0,300,15,NOT WS_GROUP - CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL | + CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x804,0,15,300,83 LTEXT "",IDC_INTROTEXT,0,103,300,26,NOT WS_GROUP CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTOCHECKBOX | diff --git a/Contrib/UIs/resource.h b/Contrib/UIs/resource.h index baeee936..46fb1672 100644 --- a/Contrib/UIs/resource.h +++ b/Contrib/UIs/resource.h @@ -1,4 +1,5 @@ #include +#include #ifndef IDC_STATIC #define IDC_STATIC (-1) diff --git a/Contrib/UIs/sdbarker_tiny.rc b/Contrib/UIs/sdbarker_tiny.rc index 9952e716..893f2ae7 100644 --- a/Contrib/UIs/sdbarker_tiny.rc +++ b/Contrib/UIs/sdbarker_tiny.rc @@ -8,7 +8,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN ICON 103,IDC_ULICON,0,0,20,20 LTEXT "",IDC_INTROTEXT,25,0,241,23,NOT WS_GROUP - CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL | + CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x804,0,24,266,47 END @@ -91,7 +91,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN ICON 103,IDC_ULICON,0,0,20,20 LTEXT "",IDC_INTROTEXT,25,0,241,23,NOT WS_GROUP - CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL | + CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x804,0,24,266,27 CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,0,50,266,9 @@ -105,7 +105,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN ICON 103,IDC_ULICON,0,0,20,20 LTEXT "",IDC_INTROTEXT,25,0,241,23,NOT WS_GROUP - CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL | + CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x804,0,24,266,37 CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,0,60,266,9 diff --git a/Contrib/UIs/ui.c b/Contrib/UIs/ui.c index 91a7c7ba..4efaf9e0 100644 --- a/Contrib/UIs/ui.c +++ b/Contrib/UIs/ui.c @@ -1,14 +1,16 @@ // ui.cpp : Defines the entry point for the application. // +// Unicode support by Jim Park -- 08/10/2007 #include #include +#include "../ExDLL/nsis_tchar.h" #include "resource.h" HINSTANCE g_hInstance; HWND m_curwnd; -char* windows[] = { +TCHAR* windows[] = { MAKEINTRESOURCE(IDD_LICENSE), MAKEINTRESOURCE(IDD_SELCOM), MAKEINTRESOURCE(IDD_DIR), @@ -34,11 +36,11 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) { static int i = -1; switch (uMsg) { case WM_INITDIALOG: - SetWindowText(hwndDlg, "NSIS User Interface - Testing"); - SetWindowText(GetDlgItem(hwndDlg, IDC_VERSTR), "NSIS version"); - SetWindowText(GetDlgItem(hwndDlg, IDC_BACK), "< Back"); - SetWindowText(GetDlgItem(hwndDlg, IDOK), "Next >"); - SetWindowText(GetDlgItem(hwndDlg, IDCANCEL), "Cancel"); + SetWindowText(hwndDlg, _T("NSIS User Interface - Testing")); + SetWindowText(GetDlgItem(hwndDlg, IDC_VERSTR), _T("NSIS version")); + SetWindowText(GetDlgItem(hwndDlg, IDC_BACK), _T("< Back")); + SetWindowText(GetDlgItem(hwndDlg, IDOK), _T("Next >")); + SetWindowText(GetDlgItem(hwndDlg, IDCANCEL), _T("Cancel")); ShowWindow(GetDlgItem(hwndDlg, IDC_BACK), SW_SHOW); ShowWindow(GetDlgItem(hwndDlg, IDC_CHILDRECT), SW_SHOW); SendMessage(hwndDlg, WM_COMMAND, MAKEWORD(IDOK, 0), 0); @@ -53,7 +55,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) { i++; break; } - if (i >= (int)sizeof(windows)/sizeof(char*)) { + if (i >= (int)sizeof(windows)/sizeof(TCHAR*)) { i--; break; } @@ -78,14 +80,14 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) { return 0; } -int APIENTRY WinMain(HINSTANCE hInstance, +int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPSTR lpCmdLine, + LPTSTR lpCmdLine, int nCmdShow) { InitCommonControls(); - LoadLibrary("RichEd32.dll"); + LoadLibrary(_T("RichEd32.dll")); g_hInstance = GetModuleHandle(0); diff --git a/Contrib/UserInfo/UserInfo.c b/Contrib/UserInfo/UserInfo.c index 1706d766..f5d4b65d 100644 --- a/Contrib/UserInfo/UserInfo.c +++ b/Contrib/UserInfo/UserInfo.c @@ -1,10 +1,12 @@ +// Unicode support by Jim Park -- 08/23/2007 + #include #include // nsis plugin typedef BOOL (WINAPI*CHECKTOKENMEMBERSHIP)(HANDLE TokenHandle,PSID SidToCheck,PBOOL IsMember); CHECKTOKENMEMBERSHIP _CheckTokenMembership=NULL; void __declspec(dllexport) GetName(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop) + TCHAR *variables, stack_t **stacktop) { EXDLL_INIT(); @@ -12,35 +14,35 @@ void __declspec(dllexport) GetName(HWND hwndParent, int string_size, DWORD dwStringSize = g_stringsize; stack_t *th; if (!g_stacktop) return; - th = (stack_t*) GlobalAlloc(GPTR, sizeof(stack_t) + g_stringsize); + th = (stack_t*) GlobalAlloc(GPTR, sizeof(stack_t) + g_stringsize*sizeof(TCHAR)); GetUserName(th->text, &dwStringSize); th->next = *g_stacktop; *g_stacktop = th; } } -char* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny) +TCHAR* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny) { - char *group = NULL; + TCHAR *group = NULL; HANDLE hToken = NULL; - struct group - { - DWORD auth_id; - char *name; - }; +struct group +{ + DWORD auth_id; + TCHAR *name; +}; - struct group groups[] = - { - {DOMAIN_ALIAS_RID_USERS, "User"}, - // every user belongs to the users group, hence users come before guests - {DOMAIN_ALIAS_RID_GUESTS, "Guest"}, - {DOMAIN_ALIAS_RID_POWER_USERS, "Power"}, - {DOMAIN_ALIAS_RID_ADMINS, "Admin"} - }; +struct group groups[] = +{ + {DOMAIN_ALIAS_RID_USERS, _T("User")}, + // every user belongs to the users group, hence users come before guests + {DOMAIN_ALIAS_RID_GUESTS, _T("Guest")}, + {DOMAIN_ALIAS_RID_POWER_USERS, _T("Power")}, + {DOMAIN_ALIAS_RID_ADMINS, _T("Admin")} +}; if (GetVersion() & 0x80000000) // Not NT { - return "Admin"; + return _T("Admin"); } // First we must open a handle to the access token for this thread. @@ -58,7 +60,7 @@ char* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny) // GetUserName is in advapi32.dll so we can avoid Load/Freelibrary _CheckTokenMembership= (CHECKTOKENMEMBERSHIP) GetProcAddress( - GetModuleHandle("ADVAPI32"), "CheckTokenMembership"); + GetModuleHandle(_T("ADVAPI32")), "CheckTokenMembership"); // Use "old school" membership check? if (!CheckTokenForGroupDeny || _CheckTokenMembership == NULL) @@ -121,18 +123,18 @@ char* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny) return group; } - return ""; + return _T(""); } void __declspec(dllexport) GetAccountType(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop) + TCHAR *variables, stack_t **stacktop) { EXDLL_INIT(); pushstring(GetAccountTypeHelper(TRUE)); } void __declspec(dllexport) GetOriginalAccountType(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop) + TCHAR *variables, stack_t **stacktop) { EXDLL_INIT(); pushstring(GetAccountTypeHelper(FALSE)); diff --git a/Contrib/VPatch/Source/GenPat/Checksums.cpp b/Contrib/VPatch/Source/GenPat/Checksums.cpp index 387e4b9e..b3b2e513 100644 --- a/Contrib/VPatch/Source/GenPat/Checksums.cpp +++ b/Contrib/VPatch/Source/GenPat/Checksums.cpp @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Unicode support by Jim Park -- 08/29/2007 #include "Checksums.h" @@ -82,7 +84,8 @@ void streamMD5(bistream& data, md5_byte_t digest[16]) { md5_finish(&state, digest); } -TChecksum::TChecksum(std::string& fileName) : mode(MD5) { +// Jim Park: string -> tstring. +TChecksum::TChecksum(tstring& fileName) : mode(MD5) { bifstream data; data.open(fileName.c_str(), ios::binary | ios::in); data.seekg(0, ios::beg); diff --git a/Contrib/VPatch/Source/GenPat/Checksums.h b/Contrib/VPatch/Source/GenPat/Checksums.h index d0196398..7d404049 100644 --- a/Contrib/VPatch/Source/GenPat/Checksums.h +++ b/Contrib/VPatch/Source/GenPat/Checksums.h @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Unicode support by Jim Park -- 08/29/2007 #if !defined(Checksums_H) #define Checksums_H @@ -29,6 +31,7 @@ #include "md5.h" #include #include "GlobalTypes.h" + #include "tchar.h" typedef uint32_t crc32_t; @@ -39,7 +42,7 @@ enum { CRC32, MD5 } mode; TChecksum() : mode(MD5) { } - TChecksum(std::string& fileName); + TChecksum(tstring& fileName); void loadMD5(md5_byte_t newdigest[16]); void loadCRC32(crc32_t newcrc); diff --git a/Contrib/VPatch/Source/GenPat/ChunkedFile.cpp b/Contrib/VPatch/Source/GenPat/ChunkedFile.cpp index 29f99168..9717802a 100644 --- a/Contrib/VPatch/Source/GenPat/ChunkedFile.cpp +++ b/Contrib/VPatch/Source/GenPat/ChunkedFile.cpp @@ -22,9 +22,12 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Unicode support by Jim Park -- 08/29/2007 #include "ChunkedFile.h" +#include "tchar.h" using namespace std; @@ -32,15 +35,15 @@ using namespace std; chunks(NULL) { chunkCount = fSize / chunkSize; - cout << "[ChunkedFile] Filesize of " << static_cast(fSize) << " gives " << static_cast(chunkCount) << " chunks.\n"; + tout << _T("[ChunkedFile] Filesize of ") << static_cast(fSize) << _T(" gives ") << static_cast(chunkCount) << _T(" chunks.\n"); - cout << "[ChunkedFile] Memory to be used by those chunks: " << sizeof(FileChunk) * chunkCount << " bytes..."; + tout << _T("[ChunkedFile] Memory to be used by those chunks: ") << sizeof(FileChunk) * chunkCount << _T(" bytes..."); if(chunkCount == 0) { chunks = NULL; return; } chunks = new FileChunk[chunkCount]; - cout << " allocated.\n"; + tout << _T(" allocated.\n"); unsigned char* data = new unsigned char[chunkSize]; for(TFileOffset i = 0; i < chunkCount; i++) { @@ -50,9 +53,9 @@ using namespace std; } delete[] data; - cout << "[ChunkedFile] Sorting chunks... "; + tout << _T("[ChunkedFile] Sorting chunks... "); std::sort(chunks,chunks + chunkCount); - cout << "done.\n"; + tout << _T("done.\n"); } diff --git a/Contrib/VPatch/Source/GenPat/ChunkedFile.h b/Contrib/VPatch/Source/GenPat/ChunkedFile.h index 4c617fcf..2a7045f0 100644 --- a/Contrib/VPatch/Source/GenPat/ChunkedFile.h +++ b/Contrib/VPatch/Source/GenPat/ChunkedFile.h @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #if !defined(ChunkedFile_H) #define ChunkedFile_H diff --git a/Contrib/VPatch/Source/GenPat/FileFormat1.cpp b/Contrib/VPatch/Source/GenPat/FileFormat1.cpp index 8e85b7bd..6e715d9e 100644 --- a/Contrib/VPatch/Source/GenPat/FileFormat1.cpp +++ b/Contrib/VPatch/Source/GenPat/FileFormat1.cpp @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #include "FileFormat1.h" #include "GlobalTypes.h" @@ -126,7 +128,7 @@ namespace FileFormat1 { TFileOffset endOffset = in.tellg(); if(sourceChecksum == *removeCRC) { if(existanceIsError) { - throw "Source file with the exact same contents already exists in patch!\nUse /R option (replace) to replace it with this patch!"; + throw _T("Source file with the exact same contents already exists in patch!\nUse /R option (replace) to replace it with this patch!"); } fileCount--; } else { @@ -192,7 +194,7 @@ namespace FileFormat1 { // calculate area inbetween this block and the next TFileOffset notFoundStart = current->targetOffset+current->size; if(notFoundStart > next->targetOffset) { - throw "makeBinaryPatch input problem: there was overlap"; + throw _T("makeBinaryPatch input problem: there was overlap"); } TFileOffset notFoundSize = next->targetOffset - notFoundStart; if(notFoundSize > 0) { diff --git a/Contrib/VPatch/Source/GenPat/FileFormat1.h b/Contrib/VPatch/Source/GenPat/FileFormat1.h index b8d791f9..42cf66b8 100644 --- a/Contrib/VPatch/Source/GenPat/FileFormat1.h +++ b/Contrib/VPatch/Source/GenPat/FileFormat1.h @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #if !defined(FileFormat1_H) #define FileFormat1_H diff --git a/Contrib/VPatch/Source/GenPat/GlobalTypes.cpp b/Contrib/VPatch/Source/GenPat/GlobalTypes.cpp index 99e1b771..7ab7d537 100644 --- a/Contrib/VPatch/Source/GenPat/GlobalTypes.cpp +++ b/Contrib/VPatch/Source/GenPat/GlobalTypes.cpp @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #include "GlobalTypes.h" diff --git a/Contrib/VPatch/Source/GenPat/GlobalTypes.h b/Contrib/VPatch/Source/GenPat/GlobalTypes.h index aafb1c55..034b45ff 100644 --- a/Contrib/VPatch/Source/GenPat/GlobalTypes.h +++ b/Contrib/VPatch/Source/GenPat/GlobalTypes.h @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #if !defined(GlobalTypes_H) #define GlobalTypes_H diff --git a/Contrib/VPatch/Source/GenPat/POSIXUtil.cpp b/Contrib/VPatch/Source/GenPat/POSIXUtil.cpp index 111a87e1..5746aa75 100644 --- a/Contrib/VPatch/Source/GenPat/POSIXUtil.cpp +++ b/Contrib/VPatch/Source/GenPat/POSIXUtil.cpp @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Unicode support by Jim Park -- 08/29/2007 #include "POSIXUtil.h" @@ -54,13 +56,13 @@ namespace POSIX { #ifdef __WIN32__ /* do it the old way on Win32, because POSIX does not get timezone stuff right */ - ALT_FILETIME getFileTime(const char* sFileName) { + ALT_FILETIME getFileTime(const TCHAR* sFileName) { FILETIME temp; GetSystemTimeAsFileTime(&temp); HANDLE h = CreateFile(sFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (h == INVALID_HANDLE_VALUE) { - cerr << "Cannot read file time of " << sFileName << "\n"; + terr << _T("Cannot read file time of ") << sFileName << _T("\n"); } else { GetFileTime(h, NULL, NULL, &temp); CloseHandle(h); @@ -77,7 +79,7 @@ namespace POSIX { time_t currentTime = time(NULL); if(stat(sFileName, &buf)) { - cerr << "Cannot read file time of " << sFileName << "\n"; + terr << _T("Cannot read file time of ") << sFileName << _T("\n"); } else { /* get the time from the file */ currentTime = buf.st_mtime; @@ -88,11 +90,11 @@ namespace POSIX { } #endif - uint32_t getFileSize(const char* sFileName) { + uint32_t getFileSize(const TCHAR* sFileName) { std::ifstream f; f.open(sFileName, std::ios_base::binary | std::ios_base::in); if (!f.good() || f.eof() || !f.is_open()) { - throw "File could not be read (getFileSize)"; + throw _T("File could not be read (getFileSize)"); } f.seekg(0, std::ios_base::beg); std::ifstream::pos_type begin_pos = f.tellg(); @@ -101,29 +103,29 @@ namespace POSIX { } #ifdef __WIN32__ - string getTempFile() { - char buffer[MAX_PATH]; - if(GetTempFileName(".","vpatch",0,buffer) == 0) { - cerr << "Cannot create temporary filename"; + tstring getTempFile() { + TCHAR buffer[MAX_PATH]; + if(GetTempFileName(_T("."),_T("vpatch"),0,buffer) == 0) { + terr << _T("Cannot create temporary filename"); } - return string(buffer); + return tstring(buffer); } #else - string getTempFile() { - char t[] = "/tmp/genpatXXXXXX"; + tstring getTempFile() { + TCHAR t[] = _T("/tmp/genpatXXXXXX"); mode_t old_umask = umask(0077); int fd = mkstemp(t); if (fd == -1) { - cerr << "Cannot create temporary filename"; - return ""; + terr << _T("Cannot create temporary filename"); + return _T(""); } close(fd); umask(old_umask); - return string(t); + return tstring(t); } #endif diff --git a/Contrib/VPatch/Source/GenPat/POSIXUtil.h b/Contrib/VPatch/Source/GenPat/POSIXUtil.h index 20529f10..e14361d3 100644 --- a/Contrib/VPatch/Source/GenPat/POSIXUtil.h +++ b/Contrib/VPatch/Source/GenPat/POSIXUtil.h @@ -22,11 +22,14 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Unicode support by Jim Park -- 08/29/2007 #if !defined(POSIXUtil_H) #define POSIXUtil_H #include "GlobalTypes.h" #include + #include "tchar.h" using namespace std; @@ -36,9 +39,9 @@ uint32_t dwHighDateTime; } ALT_FILETIME; - ALT_FILETIME getFileTime(const char* sFileName); - uint32_t getFileSize(const char* sFileName); - string getTempFile(); + ALT_FILETIME getFileTime(const TCHAR* sFileName); + uint32_t getFileSize(const TCHAR* sFileName); + tstring getTempFile(); } #endif // POSIXUtil_H diff --git a/Contrib/VPatch/Source/GenPat/PatchGenerator.cpp b/Contrib/VPatch/Source/GenPat/PatchGenerator.cpp index 445f2e5b..172c96e8 100644 --- a/Contrib/VPatch/Source/GenPat/PatchGenerator.cpp +++ b/Contrib/VPatch/Source/GenPat/PatchGenerator.cpp @@ -22,7 +22,10 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Unicode support by Jim Park -- 08/29/2007 +#include "tchar.h" #include "PatchGenerator.h" #include @@ -85,12 +88,12 @@ void PatchGenerator::execute(vector& sameBlocks) { } // we need to update the memory cache of target - cout << "[CacheReload] File position = " << static_cast(targetCDataBaseOffset) << "\n"; + tout << _T("[CacheReload] File position = ") << static_cast(targetCDataBaseOffset) << _T("\n"); target.seekg(targetCDataBaseOffset,ios::beg); target.read(reinterpret_cast(targetCData),targetCDataSize); } - //cout << currentOffset << " "; + //tout << currentOffset << _T(" "); SameBlock* currentSameBlock = findBlock(sourceTree,currentOffset); @@ -108,9 +111,9 @@ void PatchGenerator::execute(vector& sameBlocks) { // debug info if(beVerbose) { - cout << "Block found: " << static_cast(currentSameBlock->targetOffset) - << " " << static_cast(currentSameBlock->size) - << " (source offset=" << static_cast(currentSameBlock->sourceOffset) << ")\n"; + tout << _T("Block found: ") << static_cast(currentSameBlock->targetOffset) + << _T(" ") << static_cast(currentSameBlock->size) + << _T(" (source offset=") << static_cast(currentSameBlock->sourceOffset) << _T(")\n"); } currentOffset = currentSameBlock->targetOffset + currentSameBlock->size; @@ -172,8 +175,8 @@ SameBlock* PatchGenerator::findBlock(ChunkedFile* sourceTree, if(beVerbose) { if(maxMatches != 0) { if(matchCount == maxMatches) { - cout << "[FindBlock] Abort due to >" << static_cast(maxMatches) - << " matches; file position = " << static_cast(targetFileStartOffset) << "\n"; + tout << _T("[FindBlock] Abort due to >") << static_cast(maxMatches) + << _T(" matches; file position = ") << static_cast(targetFileStartOffset) << _T("\n"); } } } diff --git a/Contrib/VPatch/Source/GenPat/PatchGenerator.h b/Contrib/VPatch/Source/GenPat/PatchGenerator.h index 03df9f4c..919d0e0d 100644 --- a/Contrib/VPatch/Source/GenPat/PatchGenerator.h +++ b/Contrib/VPatch/Source/GenPat/PatchGenerator.h @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #if !defined(PatchGenerator_H) #define PatchGenerator_H diff --git a/Contrib/VPatch/Source/GenPat/adler32.cpp b/Contrib/VPatch/Source/GenPat/adler32.cpp index 150929a1..06ffc184 100644 --- a/Contrib/VPatch/Source/GenPat/adler32.cpp +++ b/Contrib/VPatch/Source/GenPat/adler32.cpp @@ -21,6 +21,8 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. + Reviewed for Unicode support by Jim Park -- 08/29/2007 + (nothing changed.) */ #include "adler32.h" diff --git a/Contrib/VPatch/Source/GenPat/adler32.h b/Contrib/VPatch/Source/GenPat/adler32.h index d5c25074..4f6e4729 100644 --- a/Contrib/VPatch/Source/GenPat/adler32.h +++ b/Contrib/VPatch/Source/GenPat/adler32.h @@ -1,6 +1,8 @@ //--------------------------------------------------------------------------- // Adler32 //--------------------------------------------------------------------------- +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #if !defined(Adler32_H) #define Adler32_H diff --git a/Contrib/VPatch/Source/GenPat/main.cpp b/Contrib/VPatch/Source/GenPat/main.cpp index a62ccf04..1eea88e9 100644 --- a/Contrib/VPatch/Source/GenPat/main.cpp +++ b/Contrib/VPatch/Source/GenPat/main.cpp @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Unicode support by Jim Park -- 08/29/2007 #ifdef __BORLANDC__ #pragma argsused @@ -31,10 +33,12 @@ #include #endif +#include "tchar.h" + #ifdef __WIN32__ - #define OPT_CHAR '/' + #define OPT_CHAR _T('/') #else - #define OPT_CHAR '-' + #define OPT_CHAR _T('-') #endif #include "GlobalTypes.h" @@ -46,14 +50,14 @@ #include #include -int main( int argc, char * argv[] ) { - cout << "GenPat v3.1\n"; - cout << "===========\n\n(c) 2001-2005 Van de Sande Productions\n"; - cout << "Website: http://www.tibed.net/vpatch\n\n"; +int _tmain( int argc, TCHAR * argv[] ) { + tout << _T("GenPat v3.1\n"); + tout << _T("===========\n\n(c) 2001-2005 Van de Sande Productions\n"); + tout << _T("Website: http://www.tibed.net/vpatch\n\n"); - string sourceFileName; - string targetFileName; - string patchFileName; + tstring sourceFileName; + tstring targetFileName; + tstring patchFileName; bool showHelp = true; @@ -65,30 +69,30 @@ int main( int argc, char * argv[] ) { int fileNameArgument = 0; if(argc > 1) { for(int i = 1; i < argc; i++) { - string s(argv[i]); + tstring s(argv[i]); if(s.size() > 0) { if(s[0] == OPT_CHAR) { if(s.size() > 1) { - if((s[1] == 'v') || (s[1] == 'V')) { + if((s[1] == _T('v')) || (s[1] == _T('V'))) { beVerbose = true; } - if((s[1] == 'o') || (s[1] == 'O')) { + if((s[1] == _T('o')) || (s[1] == _T('O'))) { beOptimal = true; } - if((s[1] == 'r') || (s[1] == 'R')) { + if((s[1] == _T('r')) || (s[1] == _T('R'))) { existanceIsError = false; } } if(s.size() > 2) { - if((s[1] == 'b') || (s[1] == 'B')) { - if(s[2] == '=') { - istringstream ss(s.substr(3)); + if((s[1] == _T('b')) || (s[1] == _T('B'))) { + if(s[2] == _T('=')) { + tistringstream ss(s.substr(3)); ss >> blockSize; } } - if((s[1] == 'a') || (s[1] == 'A')) { - if(s[2] == '=') { - istringstream ss(s.substr(3)); + if((s[1] == _T('a')) || (s[1] == _T('A'))) { + if(s[2] == _T('=')) { + tistringstream ss(s.substr(3)); ss >> maxMatches; } } @@ -106,7 +110,7 @@ int main( int argc, char * argv[] ) { showHelp = false; break; default: - cerr << "WARNING: extra filename argument not used: " << s << "\n"; + terr << _T("WARNING: extra filename argument not used: ") << s << _T("\n"); } fileNameArgument++; } @@ -117,45 +121,45 @@ int main( int argc, char * argv[] ) { maxMatches = 0; } if(showHelp) { - cout << "This program will take (sourcefile) as input and create a (patchfile).\n"; - cout << "With this patchfile, you can convert a (sourcefile) into (targetfile).\n\n"; - cout << "Command line info:\n"; - cout << " GENPAT (sourcefile) (targetfile) (patchfile)\n\n"; + tout << _T("This program will take (sourcefile) as input and create a (patchfile).\n"); + tout << _T("With this patchfile, you can convert a (sourcefile) into (targetfile).\n\n"); + tout << _T("Command line info:\n"); + tout << _T(" GENPAT (sourcefile) (targetfile) (patchfile)\n\n"); - cout << "Command line option (optional):\n"; - cout << OPT_CHAR << "R Replace a patch with same contents as source silently if it\n already exists.\n"; - cout << OPT_CHAR << "B=64 Set blocksize (default=64), multiple of 2 is required.\n"; - cout << OPT_CHAR << "V More verbose information during patch creation.\n"; - cout << OPT_CHAR << "O Deactivate match limit of the " << OPT_CHAR << "A switch (sometimes smaller patches).\n"; - cout << OPT_CHAR << "A=500 Maximum number of block matches per block (improves performance).\n"; - cout << " Default is 500, larger is slower. Use " << OPT_CHAR << "V to see the cut-off aborts.\n\n"; - cout << "Note: filenames should never start with " << OPT_CHAR << " character!\n\n"; - cout << "Possible exit codes:\n"; - cout << " 0 Success\n"; - cout << " 1 Arguments missing\n"; - cout << " 2 Other error\n"; - cout << " 3 Source file already has a patch in specified patch file (=error)\n"; + tout << _T("Command line option (optional):\n"); + tout << OPT_CHAR << _T("R Replace a patch with same contents as source silently if it\n already exists.\n"); + tout << OPT_CHAR << _T("B=64 Set blocksize (default=64), multiple of 2 is required.\n"); + tout << OPT_CHAR << _T("V More verbose information during patch creation.\n"); + tout << OPT_CHAR << _T("O Deactivate match limit of the ") << OPT_CHAR << _T("A switch (sometimes smaller patches).\n"); + tout << OPT_CHAR << _T("A=500 Maximum number of block matches per block (improves performance).\n"); + tout << _T(" Default is 500, larger is slower. Use ") << OPT_CHAR << _T("V to see the cut-off aborts.\n\n"); + tout << _T("Note: filenames should never start with ") << OPT_CHAR << _T(" character!\n\n"); + tout << _T("Possible exit codes:\n"); + tout << _T(" 0 Success\n"); + tout << _T(" 1 Arguments missing\n"); + tout << _T(" 2 Other error\n"); + tout << _T(" 3 Source file already has a patch in specified patch file (=error)\n"); return 1; } - cout << "[Source] " << sourceFileName.c_str() << "\n"; - cout << "[Target] " << targetFileName.c_str() << "\n[PatchFile] " << patchFileName.c_str() << "\n"; + tout << _T("[Source] ") << sourceFileName.c_str() << _T("\n"); + tout << _T("[Target] ") << targetFileName.c_str() << _T("\n[PatchFile] ") << patchFileName.c_str() << _T("\n"); // get the file sizes TFileOffset sourceSize = 0; try { sourceSize = POSIX::getFileSize(sourceFileName.c_str()); } - catch(char* s) { - cerr << "Source file size reading failed: " << s << "\n"; + catch(TCHAR* s) { + terr << _T("Source file size reading failed: ") << s << _T("\n"); return 2; } TFileOffset targetSize; try { targetSize = POSIX::getFileSize(targetFileName.c_str()); } - catch(const char* s) { - cerr << "Target file size reading failed: " << s << "\n"; + catch(const TCHAR* s) { + terr << _T("Target file size reading failed: ") << s << _T("\n"); return 2; } @@ -165,8 +169,8 @@ int main( int argc, char * argv[] ) { TChecksum* targetCRC = new TChecksum(targetFileName); targetCRC->mode = TChecksum::MD5; // default - string tempFileName = POSIX::getTempFile(); - if (tempFileName == "") + tstring tempFileName = POSIX::getTempFile(); + if (tempFileName == _T("")) return 2; // open the files @@ -183,8 +187,8 @@ int main( int argc, char * argv[] ) { TFileOffset previousPatchSize = 0; try { previousPatchSize = POSIX::getFileSize(patchFileName.c_str()); - } catch(const char* s) { - cout << "Patch file does not yet exist: " << s << ", it will be created.\n"; + } catch(const TCHAR* s) { + tout << _T("Patch file does not yet exist: ") << s << _T(", it will be created.\n"); std::ofstream newfile; newfile.open(patchFileName.c_str(), std::ios_base::binary | std::ios_base::out); newfile.close(); @@ -195,8 +199,8 @@ int main( int argc, char * argv[] ) { try { // this will copy the contents of previousPatch to patch, but without sourceCRC fileCount = FileFormat1::removeExistingPatch(previousPatch,previousPatchSize,patch,sourceCRC,existanceIsError); - } catch(const char* s) { - cerr << "ERROR: " << s << "\n"; + } catch(const TCHAR* s) { + terr << _T("ERROR: ") << s << _T("\n"); patch.close(); unlink(tempFileName.c_str()); return 3; @@ -204,9 +208,9 @@ int main( int argc, char * argv[] ) { // set them to the same checksum mode targetCRC->mode = sourceCRC->mode; - cout << "[Checksum] Kind of checksums used: "; - if(targetCRC->mode == TChecksum::MD5) cout << "MD5\n"; - if(targetCRC->mode == TChecksum::CRC32) cout << "CRC32\n"; + tout << _T("[Checksum] Kind of checksums used: "); + if(targetCRC->mode == TChecksum::MD5) tout << _T("MD5\n"); + if(targetCRC->mode == TChecksum::CRC32) tout << _T("CRC32\n"); break; } @@ -227,26 +231,26 @@ int main( int argc, char * argv[] ) { } if((blockSize >> 1) == orgBlockSize) blockSize = orgBlockSize; if(blockSize != orgBlockSize) { - cout << "[BlockSizeFix] Your blocksize had to be fixed since it is not a multiple of 2\n"; + tout << _T("[BlockSizeFix] Your blocksize had to be fixed since it is not a multiple of 2\n"); } if(blockSize < 16) { blockSize = 16; - cout << "[BlockSizeFix] Your blocksize had to be fixed since it is smaller than 16\n"; + tout << _T("[BlockSizeFix] Your blocksize had to be fixed since it is smaller than 16\n"); } gen->blockSize = blockSize; - cout << "[BlockSize] " << static_cast(gen->blockSize) << " bytes\n"; + tout << _T("[BlockSize] ") << static_cast(gen->blockSize) << _T(" bytes\n"); gen->maxMatches = maxMatches; if(gen->maxMatches == 0) { - cout << "[FindBlockMatchLimit] Unlimited matches\n"; + tout << _T("[FindBlockMatchLimit] Unlimited matches\n"); } else { - cout << "[FindBlockMatchLimit] " << gen->maxMatches << " matches\n"; + tout << _T("[FindBlockMatchLimit] ") << gen->maxMatches << _T(" matches\n"); } gen->beVerbose = beVerbose; if(beVerbose) { - cout << "[Debug] Verbose output during patch generation activated.\n"; + tout << _T("[Debug] Verbose output during patch generation activated.\n"); } // create sameBlock storage @@ -279,20 +283,20 @@ int main( int argc, char * argv[] ) { std::ofstream clearF; clearF.open(tempFileName.c_str(), std::ios_base::binary | std::ios_base::out); } - catch(string s) { - cerr << "Error thrown: " << s.c_str(); + catch(tstring s) { + terr << _T("Error thrown: ") << s.c_str(); return 2; } - catch(const char* s) { - cerr << "Error thrown: " << s; + catch(const TCHAR* s) { + terr << _T("Error thrown: ") << s; return 2; } } else { - cerr << "There was a problem opening the files.\n"; + terr << _T("There was a problem opening the files.\n"); return 2; } if(*sourceCRC == *targetCRC) - cerr << "WARNING: source and target file have equal CRCs!"; + terr << _T("WARNING: source and target file have equal CRCs!"); delete sourceCRC; delete targetCRC; unlink(tempFileName.c_str()); diff --git a/Contrib/VPatch/Source/GenPat/md5.c b/Contrib/VPatch/Source/GenPat/md5.c index 0ededbf3..8f21e7cf 100644 --- a/Contrib/VPatch/Source/GenPat/md5.c +++ b/Contrib/VPatch/Source/GenPat/md5.c @@ -20,8 +20,9 @@ L. Peter Deutsch ghost@aladdin.com + Reviewed for Unicode support by Jim Park -- 08/29/2007 */ -/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ +/* $Id: md5.c,v 1.1 2005/09/17 09:25:44 kichik Exp $ */ /* Independent implementation of MD5 (RFC 1321). diff --git a/Contrib/VPatch/Source/GenPat/md5.h b/Contrib/VPatch/Source/GenPat/md5.h index 698c995d..487652cc 100644 --- a/Contrib/VPatch/Source/GenPat/md5.h +++ b/Contrib/VPatch/Source/GenPat/md5.h @@ -20,8 +20,9 @@ L. Peter Deutsch ghost@aladdin.com + Reviewed for Unicode support by Jim Park -- 08/29/2007 */ -/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ +/* $Id: md5.h,v 1.1 2005/09/17 09:25:44 kichik Exp $ */ /* Independent implementation of MD5 (RFC 1321). diff --git a/Contrib/VPatch/Source/GenPat/tchar.h b/Contrib/VPatch/Source/GenPat/tchar.h new file mode 100644 index 00000000..24e16bd2 --- /dev/null +++ b/Contrib/VPatch/Source/GenPat/tchar.h @@ -0,0 +1,28 @@ +// Added for Unicode support by Jim Park -- 08/29/2007 +#pragma once +#include +#include + +#ifdef _UNICODE +# define tout wcout +# define terr wcerr +# define __T(x) L ## x +# define _T(x) __T(x) +# define _tmain wmain +# define _tunlink _wunlink + + typedef std::wstring tstring; + typedef std::wistringstream tistringstream; + + typedef wchar_t TCHAR; +#else +# define tout cout +# define terr cerr +# define _T(x) x +# define _tmain main +# define _tunlink _unlink + + typedef std::string tstring; + typedef std::istringstream tistringstream; + typedef char TCHAR; +#endif diff --git a/Contrib/VPatch/Source/Plugin/apply_patch.c b/Contrib/VPatch/Source/Plugin/apply_patch.c index 1384dcdd..d0e00258 100644 --- a/Contrib/VPatch/Source/Plugin/apply_patch.c +++ b/Contrib/VPatch/Source/Plugin/apply_patch.c @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #include "apply_patch.h" #include "checksum.h" diff --git a/Contrib/VPatch/Source/Plugin/apply_patch.h b/Contrib/VPatch/Source/Plugin/apply_patch.h index 7716175b..76853aba 100644 --- a/Contrib/VPatch/Source/Plugin/apply_patch.h +++ b/Contrib/VPatch/Source/Plugin/apply_patch.h @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #ifndef apply_patch_INCLUDED #define apply_patch_INCLUDED diff --git a/Contrib/VPatch/Source/Plugin/checksum.c b/Contrib/VPatch/Source/Plugin/checksum.c index 81b1d27e..e16ec666 100644 --- a/Contrib/VPatch/Source/Plugin/checksum.c +++ b/Contrib/VPatch/Source/Plugin/checksum.c @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 #include "checksum.h" diff --git a/Contrib/VPatch/Source/Plugin/checksum.h b/Contrib/VPatch/Source/Plugin/checksum.h index 4817f5f6..d1fe1abc 100644 --- a/Contrib/VPatch/Source/Plugin/checksum.h +++ b/Contrib/VPatch/Source/Plugin/checksum.h @@ -22,6 +22,10 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Reviewed for Unicode support by Jim Park -- 08/29/2007 +// The functions return ANSI strings so we use PushStringA to push it on +// to the return stack correctly. #ifndef checksum_INCLUDED #define checksum_INCLUDED diff --git a/Contrib/VPatch/Source/Plugin/md5.c b/Contrib/VPatch/Source/Plugin/md5.c index 0c9f7ce1..447c3b2a 100644 --- a/Contrib/VPatch/Source/Plugin/md5.c +++ b/Contrib/VPatch/Source/Plugin/md5.c @@ -20,8 +20,9 @@ L. Peter Deutsch ghost@aladdin.com + Reviewed for Unicode support by Jim Park -- 08/29/2007 */ -/* $Id: md5.c,v 1.1 2005/09/17 09:25:44 kichik Exp $ */ +/* $Id: md5.c,v 1.2 2005/09/20 17:42:28 kichik Exp $ */ /* Independent implementation of MD5 (RFC 1321). diff --git a/Contrib/VPatch/Source/Plugin/md5.h b/Contrib/VPatch/Source/Plugin/md5.h index 698c995d..935f7bdf 100644 --- a/Contrib/VPatch/Source/Plugin/md5.h +++ b/Contrib/VPatch/Source/Plugin/md5.h @@ -20,8 +20,10 @@ L. Peter Deutsch ghost@aladdin.com + Reviewed for Unicode support by Jim Park -- 08/29/2007 + */ -/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ +/* $Id: md5.h,v 1.1 2005/09/17 09:25:44 kichik Exp $ */ /* Independent implementation of MD5 (RFC 1321). diff --git a/Contrib/VPatch/Source/Plugin/vpatchdll.c b/Contrib/VPatch/Source/Plugin/vpatchdll.c index df6ca613..ec0e25c1 100644 --- a/Contrib/VPatch/Source/Plugin/vpatchdll.c +++ b/Contrib/VPatch/Source/Plugin/vpatchdll.c @@ -22,6 +22,8 @@ // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +// +// Unicode support by Jim Park -- 08/29/2007 #define WIN32_LEAN_AND_MEAN #include @@ -36,15 +38,15 @@ HINSTANCE g_hInstance; HWND g_hwndParent; void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop) { + TCHAR *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); { - char source[MAX_PATH]; - char dest[MAX_PATH]; - char exename[MAX_PATH]; + TCHAR source[MAX_PATH]; + TCHAR dest[MAX_PATH]; + TCHAR exename[MAX_PATH]; HANDLE hPatch, hSource, hDest; int result; @@ -55,7 +57,7 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size, hPatch = CreateFile(exename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hPatch == INVALID_HANDLE_VALUE) { - pushstring("Unable to open patch file"); + pushstring(_T("Unable to open patch file")); return; } @@ -63,7 +65,7 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hSource == INVALID_HANDLE_VALUE) { CloseHandle(hPatch); - pushstring("Unable to open source file"); + pushstring(_T("Unable to open source file")); return; } @@ -72,7 +74,7 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size, if (hDest == INVALID_HANDLE_VALUE) { CloseHandle(hPatch); CloseHandle(hSource); - pushstring("Unable to open output file"); + pushstring(_T("Unable to open output file")); return; } @@ -84,16 +86,16 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size, if ((result != PATCH_SUCCESS)) { if (result == PATCH_ERROR) - pushstring("An error occured while patching"); + pushstring(_T("An error occured while patching")); else if (result == PATCH_CORRUPT) - pushstring("Patch data is invalid or corrupt"); + pushstring(_T("Patch data is invalid or corrupt")); else if (result == PATCH_NOMATCH) - pushstring("No suitable patches were found"); + pushstring(_T("No suitable patches were found")); else if (result == PATCH_UPTODATE) - pushstring("OK, new version already installed"); + pushstring(_T("OK, new version already installed")); DeleteFile(dest); } else { - pushstring("OK"); + pushstring(_T("OK")); } return; @@ -102,13 +104,13 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size, #ifdef DLL_CHECKSUMS void __declspec(dllexport) GetFileCRC32(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop) { + TCHAR *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); { - char filename[MAX_PATH]; + TCHAR filename[MAX_PATH]; char crc_string[9]; HANDLE hFile; unsigned long crc; @@ -119,17 +121,17 @@ void __declspec(dllexport) GetFileCRC32(HWND hwndParent, int string_size, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) { //pushstring("ERROR: Unable to open file for CRC32 calculation"); - pushstring(""); + pushstring(_T("")); return; } if (!FileCRC(hFile, &crc)) { //pushstring("ERROR: Unable to calculate CRC32"); - pushstring(""); + pushstring(_T("")); } else { crc_string[8] = '\0'; CRC32ToString(crc_string,crc); - pushstring(crc_string); + PushStringA(crc_string); } CloseHandle(hFile); @@ -137,13 +139,13 @@ void __declspec(dllexport) GetFileCRC32(HWND hwndParent, int string_size, } void __declspec(dllexport) GetFileMD5(HWND hwndParent, int string_size, - char *variables, stack_t **stacktop) { + TCHAR *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); { - char filename[MAX_PATH]; + TCHAR filename[MAX_PATH]; char md5_string[33]; HANDLE hFile; md5_byte_t digest[16]; @@ -154,17 +156,17 @@ void __declspec(dllexport) GetFileMD5(HWND hwndParent, int string_size, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) { //pushstring("ERROR: Unable to open file for MD5 calculation"); - pushstring(""); + pushstring(_T("")); return; } if (!FileMD5(hFile, digest)) { //pushstring("ERROR: Unable to calculate MD5"); - pushstring(""); + pushstring(_T("")); } else { md5_string[32] = '\0'; MD5ToString(md5_string,digest); - pushstring(md5_string); + PushStringA(md5_string); } CloseHandle(hFile); diff --git a/Contrib/nsDialogs/browse.c b/Contrib/nsDialogs/browse.c index 9a7d637b..6c823491 100644 --- a/Contrib/nsDialogs/browse.c +++ b/Contrib/nsDialogs/browse.c @@ -1,7 +1,10 @@ +// Unicode support by Jim Park -- 08/10/2007 + #include #include #include // nsis plugin +#include #include "defs.h" @@ -12,26 +15,26 @@ int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) { return 0; } -void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { BROWSEINFO bi; - char result[MAX_PATH]; - char initial[MAX_PATH]; - char title[1024]; + TCHAR result[MAX_PATH]; + TCHAR initial[MAX_PATH]; + TCHAR title[1024]; LPITEMIDLIST resultPIDL; EXDLL_INIT(); - if (popstringn(title, sizeof(initial))) + if (popstringn(title, _countof(initial))) { - pushstring("error"); + pushstring(_T("error")); return; } - if (popstringn(initial, sizeof(title))) + if (popstringn(initial, _countof(title))) { - pushstring("error"); + pushstring(_T("error")); return; } @@ -64,7 +67,7 @@ void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size, resultPIDL = SHBrowseForFolder(&bi); if (!resultPIDL) { - pushstring("error"); + pushstring(_T("error")); return; } @@ -74,21 +77,21 @@ void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size, } else { - pushstring("error"); + pushstring(_T("error")); } CoTaskMemFree(resultPIDL); } -void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { OPENFILENAME ofn={0,}; // XXX WTF int save; - char type[5]; - static char path[1024]; - static char filter[1024]; - static char currentDirectory[1024]; - static char initialDir[1024]; + TCHAR type[5]; + static TCHAR path[1024]; + static TCHAR filter[1024]; + static TCHAR currentDirectory[1024]; + static TCHAR initialDir[1024]; DWORD gfa; EXDLL_INIT(); @@ -105,7 +108,7 @@ void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, ch popstringn(path, sizeof(path)); popstringn(filter, sizeof(filter)); - save = !lstrcmpi(type, "save"); + save = !lstrcmpi(type, _T("save")); // Check if the path given is a folder. If it is we initialize the // ofn.lpstrInitialDir parameter @@ -114,21 +117,21 @@ void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, ch { lstrcpy(initialDir, path); ofn.lpstrInitialDir = initialDir; - path[0] = '\0'; // disable initial file selection as path is actually a directory + path[0] = _T('\0'); // disable initial file selection as path is actually a directory } if (!filter[0]) { - lstrcpy(filter, "All Files|*.*"); + lstrcpy(filter, _T("All Files|*.*")); } { // Convert the filter to the format required by Windows: NULL after each // item followed by a terminating NULL - char *p = filter; + TCHAR *p = filter; while (*p) // XXX take care for 1024 { - if (*p == '|') + if (*p == _T('|')) { *p++ = 0; } @@ -149,19 +152,19 @@ void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, ch } else if (CommDlgExtendedError() == FNERR_INVALIDFILENAME) { - *path = '\0'; + *path = _T('\0'); if ((save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn))) { pushstring(path); } else { - pushstring(""); + pushstring(_T("")); } } else { - pushstring(""); + pushstring(_T("")); } // restore working dir diff --git a/Contrib/nsDialogs/defs.h b/Contrib/nsDialogs/defs.h index 4de614c0..b765f22d 100644 --- a/Contrib/nsDialogs/defs.h +++ b/Contrib/nsDialogs/defs.h @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 08/24/2007 + #ifndef __NS_DIALOGS__DEFS_H__ #define __NS_DIALOGS__DEFS_H__ @@ -43,7 +45,7 @@ struct nsControl { HWND window; enum nsControlType type; - char userData[USERDATA_SIZE]; + TCHAR userData[USERDATA_SIZE]; struct nsControlCallbacks callbacks; WNDPROC oldWndProc; }; @@ -64,6 +66,6 @@ struct nsDialog struct nsControl* controls; }; -#define NSCONTROL_ID_PROP "NSIS: nsControl pointer property" +#define NSCONTROL_ID_PROP _T("NSIS: nsControl pointer property") #endif//__NS_DIALOGS__DEFS_H__ diff --git a/Contrib/nsDialogs/input.c b/Contrib/nsDialogs/input.c index cf869f82..ead2a455 100644 --- a/Contrib/nsDialogs/input.c +++ b/Contrib/nsDialogs/input.c @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 08/24/2007 + #include #include // nsis plugin @@ -8,12 +10,12 @@ extern struct nsDialog g_dialog; -static int NSDFUNC ConvertPlacement(char *str, int total, int height) +static int NSDFUNC ConvertPlacement(TCHAR *str, int total, int height) { - char unit = *CharPrev(str, str + lstrlen(str)); + TCHAR unit = *CharPrev(str, str + lstrlen(str)); int x = myatoi(str); - if (unit == '%') + if (unit == _T('%')) { if (x < 0) { @@ -22,7 +24,7 @@ static int NSDFUNC ConvertPlacement(char *str, int total, int height) return MulDiv(total, x, 100); } - else if (unit == 'u') + else if (unit == _T('u')) { RECT r; @@ -50,7 +52,7 @@ int NSDFUNC PopPlacement(int *x, int *y, int *width, int *height) RECT dialogRect; int dialogWidth; int dialogHeight; - char buf[1024]; + TCHAR buf[1024]; GetClientRect(g_dialog.hwDialog, &dialogRect); dialogWidth = dialogRect.right; diff --git a/Contrib/nsDialogs/input.h b/Contrib/nsDialogs/input.h index d37d8097..f0434bd3 100644 --- a/Contrib/nsDialogs/input.h +++ b/Contrib/nsDialogs/input.h @@ -1,3 +1,5 @@ +// Reviewed for Unicode support by Jim Park -- 08/24/2007 + #ifndef __NS_DIALOGS__INPUT_H__ #define __NS_DIALOGS__INPUT_H__ diff --git a/Contrib/nsDialogs/nsDialogs.c b/Contrib/nsDialogs/nsDialogs.c index 850a8e51..dd799292 100644 --- a/Contrib/nsDialogs/nsDialogs.c +++ b/Contrib/nsDialogs/nsDialogs.c @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 08/10/2007 + #include #include // nsis plugin @@ -99,34 +101,34 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (ctl->callbacks.onChange) { - pushint((int) hwCtl); - g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0); - } + pushint((int) hwCtl); + g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0); + } } else if (HIWORD(wParam) == LBN_SELCHANGE && ctl->type == NSCTL_LISTBOX) { if (ctl->callbacks.onChange) { - pushint((int) hwCtl); - g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0); - } + pushint((int) hwCtl); + g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0); + } } else if ((HIWORD(wParam) == CBN_EDITUPDATE || HIWORD(wParam) == CBN_SELCHANGE) && ctl->type == NSCTL_COMBOBOX) { if (ctl->callbacks.onChange) { - pushint((int) hwCtl); - g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0); - } + pushint((int) hwCtl); + g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0); + } } else if (HIWORD(wParam) == STN_CLICKED && ctl->type == NSCTL_STATIC) { if (ctl->callbacks.onClick) { - pushint((int) hwCtl); - g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onClick - 1, 0); - } + pushint((int) hwCtl); + g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onClick - 1, 0); + } } break; @@ -154,7 +156,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam; RECT rc; - char text[1024]; + TCHAR text[1024]; // http://blogs.msdn.com/oldnewthing/archive/2005/05/03/414317.aspx#414357 // says we should call SystemParametersInfo(SPI_GETKEYBOARDCUES,...) to make @@ -171,7 +173,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) rc = lpdis->rcItem; // Get button's text - text[0] = '\0'; + text[0] = _T('\0'); GetWindowText(lpdis->hwndItem, text, 1024); // Calculate needed size of the control @@ -242,7 +244,7 @@ static UINT_PTR PluginCallback(enum NSPIM msg) return 0; } -void __declspec(dllexport) Create(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) Create(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { HWND hwPlacementRect; RECT rcPlacement; @@ -262,7 +264,7 @@ void __declspec(dllexport) Create(HWND hwndParent, int string_size, char *variab if (g_dialog.hwDialog == NULL) { - pushstring("error"); + pushstring(_T("error")); return; } @@ -288,10 +290,10 @@ void __declspec(dllexport) Create(HWND hwndParent, int string_size, char *variab pushint((int) g_dialog.hwDialog); } -void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { - char *className; - char *text; + TCHAR *className; + TCHAR *text; HWND hwItem; int x, y, width, height; @@ -300,18 +302,18 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char // get info from stack - className = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, g_stringsize * 2); + className = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (g_stringsize * 2)*sizeof(TCHAR)); text = &className[g_stringsize]; if (!className) { - pushstring("error"); + pushstring(_T("error")); return; } if (popstringn(className, 0)) { - pushstring("error"); + pushstring(_T("error")); HeapFree(GetProcessHeap(), 0, className); return; } @@ -323,7 +325,7 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char if (popstringn(text, 0)) { - pushstring("error"); + pushstring(_T("error")); HeapFree(GetProcessHeap(), 0, className); return; } @@ -338,21 +340,21 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char g_dialog.controls, g_dialog.controlCount * sizeof(struct nsControl)); - if (!lstrcmpi(className, "BUTTON")) + if (!lstrcmpi(className, _T("BUTTON"))) g_dialog.controls[id].type = NSCTL_BUTTON; - else if (!lstrcmpi(className, "EDIT")) + else if (!lstrcmpi(className, _T("EDIT"))) g_dialog.controls[id].type = NSCTL_EDIT; - else if (!lstrcmpi(className, "COMBOBOX")) + else if (!lstrcmpi(className, _T("COMBOBOX"))) g_dialog.controls[id].type = NSCTL_COMBOBOX; - else if (!lstrcmpi(className, "LISTBOX")) + else if (!lstrcmpi(className, _T("LISTBOX"))) g_dialog.controls[id].type = NSCTL_LISTBOX; - else if (!lstrcmpi(className, "RichEdit")) + else if (!lstrcmpi(className, _T("RichEdit"))) g_dialog.controls[id].type = NSCTL_RICHEDIT; - else if (!lstrcmpi(className, "RICHEDIT_CLASS")) + else if (!lstrcmpi(className, _T("RICHEDIT_CLASS"))) g_dialog.controls[id].type = NSCTL_RICHEDIT2; - else if (!lstrcmpi(className, "STATIC")) + else if (!lstrcmpi(className, _T("STATIC"))) g_dialog.controls[id].type = NSCTL_STATIC; - else if (!lstrcmpi(className, "LINK")) + else if (!lstrcmpi(className, _T("LINK"))) g_dialog.controls[id].type = NSCTL_LINK; else g_dialog.controls[id].type = NSCTL_UNKNOWN; @@ -365,7 +367,7 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char hwItem = CreateWindowEx( exStyle, - lstrcmpi(className, "LINK") ? className : "BUTTON", + lstrcmpi(className, _T("LINK")) ? className : _T("BUTTON"), text, style, x, y, width, height, @@ -399,12 +401,12 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char } // for backward compatibility (2.29 had CreateItem) -void __declspec(dllexport) CreateItem(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) CreateItem(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { CreateControl(hwndParent, string_size, variables, stacktop, extra); } -void __declspec(dllexport) SetUserData(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) SetUserData(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { HWND hwCtl; struct nsControl* ctl; @@ -431,7 +433,7 @@ void __declspec(dllexport) SetUserData(HWND hwndParent, int string_size, char *v popstringn(ctl->userData, USERDATA_SIZE); } -void __declspec(dllexport) GetUserData(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) GetUserData(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { HWND hwCtl; struct nsControl* ctl; @@ -442,7 +444,7 @@ void __declspec(dllexport) GetUserData(HWND hwndParent, int string_size, char *v if (!IsWindow(hwCtl)) { - pushstring(""); + pushstring(_T("")); return; } @@ -452,7 +454,7 @@ void __declspec(dllexport) GetUserData(HWND hwndParent, int string_size, char *v if (ctl == NULL) { - pushstring(""); + pushstring(_T("")); return; } @@ -467,7 +469,7 @@ void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) g_pluginParms->ExecuteCodeSegment(idEvent - 1, 0); } -void __declspec(dllexport) CreateTimer(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) CreateTimer(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { UINT callback; UINT interval; @@ -489,7 +491,7 @@ void __declspec(dllexport) CreateTimer(HWND hwndParent, int string_size, char *v TimerProc); } -void nsdKillTimer(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void nsdKillTimer(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { UINT id; @@ -546,27 +548,27 @@ void NSDFUNC SetDialogCallback(size_t callbackIdx) } -void __declspec(dllexport) OnClick(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) OnClick(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { SetControlCallback(CTL_CALLBACK_IDX(onClick)); } -void __declspec(dllexport) OnChange(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) OnChange(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { SetControlCallback(CTL_CALLBACK_IDX(onChange)); } -void __declspec(dllexport) OnNotify(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) OnNotify(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { SetControlCallback(CTL_CALLBACK_IDX(onNotify)); } -void __declspec(dllexport) OnBack(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) OnBack(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { SetDialogCallback(DLG_CALLBACK_IDX(onBack)); } -void __declspec(dllexport) Show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) Show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { // tell NSIS to remove old inner dialog and pass handle of the new inner dialog diff --git a/Contrib/nsDialogs/rtl.c b/Contrib/nsDialogs/rtl.c index 72f9a07d..2de27c67 100644 --- a/Contrib/nsDialogs/rtl.c +++ b/Contrib/nsDialogs/rtl.c @@ -23,7 +23,7 @@ extern struct nsDialog g_dialog; -void __declspec(dllexport) SetRTL(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) +void __declspec(dllexport) SetRTL(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { g_dialog.rtl = (BOOL) popint(); } diff --git a/Contrib/nsExec/nsexec.c b/Contrib/nsExec/nsexec.c index a3d784fe..837ae25d 100644 --- a/Contrib/nsExec/nsexec.c +++ b/Contrib/nsExec/nsexec.c @@ -17,6 +17,8 @@ freely, subject to the following restrictions: misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. +Unicode support by Jim Park -- 08/24/2007 + */ #include #include @@ -35,11 +37,12 @@ HWND g_hwndParent; HWND g_hwndList; void ExecScript(BOOL log); -void LogMessage(const char *pStr, BOOL bOEM); -char *my_strstr(char *a, char *b); -unsigned int my_atoi(char *s); +void LogMessage(const TCHAR *pStr, BOOL bOEM); +TCHAR *my_strstr(TCHAR *a, TCHAR *b); +unsigned int my_atoi(TCHAR *s); +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow); -void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { +void __declspec(dllexport) Exec(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); { @@ -47,7 +50,7 @@ void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variable } } -void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { +void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); { @@ -55,7 +58,7 @@ void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *var } } -void __declspec(dllexport) ExecToStack(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { +void __declspec(dllexport) ExecToStack(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); { @@ -69,7 +72,7 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { return TRUE; } -#define TAB_REPLACE " " +#define TAB_REPLACE _T(" ") #define TAB_REPLACE_SIZE (sizeof(TAB_REPLACE)-1) // Turn a pair of chars into a word @@ -88,7 +91,7 @@ BOOL IsWOW64() { LPFN_ISWOW64PROCESS fnIsWow64Process; fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( - GetModuleHandle("kernel32"), "IsWow64Process"); + GetModuleHandle(_T("kernel32")), "IsWow64Process"); if (fnIsWow64Process != NULL) { if (fnIsWow64Process(GetCurrentProcess(), &wow64)) { @@ -100,27 +103,28 @@ BOOL IsWOW64() { } void ExecScript(int log) { - char szRet[128] = ""; - char meDLLPath[MAX_PATH]; - char *executor; - char *g_exec; - char *pExec; + TCHAR szRet[128] = _T(""); + TCHAR meDLLPath[MAX_PATH]; + TCHAR *executor; + TCHAR *g_exec; + TCHAR *pExec; unsigned int g_to; BOOL bOEM; if (!IsWOW64()) { - char *p; + TCHAR* p; int nComSpecSize; nComSpecSize = GetModuleFileName(g_hInst, meDLLPath, MAX_PATH) + 2; // 2 chars for quotes - g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+nComSpecSize+2); // 1 for space, 1 for null + g_exec = (TCHAR *)GlobalAlloc(GPTR, sizeof(TCHAR)*(g_stringsize+nComSpecSize+2)); // 1 for space, 1 for null p = meDLLPath + nComSpecSize - 2; // point p at null char of meDLLPath - *g_exec = '"'; + *g_exec = _T('"'); executor = g_exec + 1; + // Look for the last '\' in path. do { - if (*p == '\\') + if (*p == _T('\\')) break; p = CharPrev(meDLLPath, p); } @@ -128,15 +132,15 @@ void ExecScript(int log) { if (p == meDLLPath) { // bad path - pushstring("error"); + pushstring(_T("error")); GlobalFree(g_exec); return; } *p = 0; - GetTempFileName(meDLLPath, "ns", 0, executor); - *p = '\\'; - if (CopyFile(meDLLPath, executor, FALSE)) + GetTempFileName(meDLLPath, _T("ns"), 0, executor); // executor = new temp file name in module path. + *p = _T('\\'); + if (CopyFile(meDLLPath, executor, FALSE)) // copy current DLL to temp file in module path. { HANDLE hFile, hMapping; LPBYTE pMapView; @@ -147,25 +151,27 @@ void ExecScript(int log) { if (pMapView) { pNTHeaders = (PIMAGE_NT_HEADERS)(pMapView + ((PIMAGE_DOS_HEADER)pMapView)->e_lfanew); + // Turning the copied DLL into a stripped down executable. pNTHeaders->FileHeader.Characteristics = IMAGE_FILE_32BIT_MACHINE | IMAGE_FILE_LOCAL_SYMS_STRIPPED | IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE; + // Windows character-mode user interface (CUI) subsystem. pNTHeaders->OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI; - pNTHeaders->OptionalHeader.AddressOfEntryPoint = (DWORD)WinMain - (DWORD)g_hInst; + pNTHeaders->OptionalHeader.AddressOfEntryPoint = (DWORD)_tWinMain - (DWORD)g_hInst; UnmapViewOfFile(pMapView); } CloseHandle(hMapping); CloseHandle(hFile); } - lstrcat(g_exec, "\""); + lstrcat(g_exec, _T("\"")); // add space pExec = g_exec + lstrlen(g_exec); - *pExec = ' '; + *pExec = _T(' '); pExec++; } else { executor = NULL; - g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1); // 1 for null + g_exec = (TCHAR *)GlobalAlloc(GPTR, sizeof(TCHAR)*(g_stringsize+1)); // 1 for NULL pExec = g_exec; } @@ -173,18 +179,24 @@ void ExecScript(int log) { bOEM = FALSE; // default is no OEM->ANSI conversion g_hwndList = NULL; - if (g_hwndParent) - g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,"#32770",NULL),NULL,"SysListView32",NULL); + + // g_hwndParent = the caller, usually NSIS installer. + if (g_hwndParent) // The window class name for dialog boxes is "#32770" + g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,_T("#32770"),NULL),NULL,_T("SysListView32"),NULL); + + // g_exec is the complete command to run: It has the copy of this DLL turned + // into an executable right now. params: + // Get the command I need to run from the NSIS stack. popstring(pExec); - if (my_strstr(pExec, "/TIMEOUT=") == pExec) { - char *szTimeout = pExec + 9; + if (my_strstr(pExec, _T("/TIMEOUT=")) == pExec) { + TCHAR *szTimeout = pExec + 9; g_to = my_atoi(szTimeout); *pExec = 0; goto params; } - if (!lstrcmpi(pExec, "/OEM")) { + if (!lstrcmpi(pExec, _T("/OEM"))) { bOEM = TRUE; *pExec = 0; goto params; @@ -192,12 +204,14 @@ params: if (!pExec[0]) { - pushstring("error"); - *(pExec-2) = '\0'; // skip space and quote + pushstring(_T("error")); + *(pExec-2) = _T('\0'); // skip space and quote if (executor) DeleteFile(executor); GlobalFree(g_exec); return; } + + // Got all the params off the stack. { STARTUPINFO si={sizeof(si),}; @@ -211,20 +225,20 @@ params: DWORD dwExit = 0; DWORD dwWait = WAIT_TIMEOUT; DWORD dwLastOutput; - static char szBuf[1024]; + static TCHAR szBuf[1024]; HGLOBAL hUnusedBuf = NULL; - char *szUnusedBuf = 0; + TCHAR *szUnusedBuf = 0; if (log) { - hUnusedBuf = GlobalAlloc(GHND, log & 2 ? g_stringsize : sizeof(szBuf)*4); + hUnusedBuf = GlobalAlloc(GHND, log & 2 ? (g_stringsize*sizeof(TCHAR)) : sizeof(szBuf)*4); if (!hUnusedBuf) { - lstrcpy(szRet, "error"); + lstrcpy(szRet, _T("error")); goto done; } - szUnusedBuf = (char *)GlobalLock(hUnusedBuf); + szUnusedBuf = (TCHAR *)GlobalLock(hUnusedBuf); } - GetVersionEx(&osv); + GetVersionEx(&osv); // Get OS info if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) { InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(&sd,true,NULL,false); @@ -234,11 +248,11 @@ params: sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = true; if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) { - lstrcpy(szRet, "error"); + lstrcpy(szRet, _T("error")); goto done; } if (!CreatePipe(&read_stdin,&newstdin,&sa,0)) { - lstrcpy(szRet, "error"); + lstrcpy(szRet, _T("error")); goto done; } @@ -249,12 +263,13 @@ params: si.hStdOutput = newstdout; si.hStdError = newstdout; if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) { - lstrcpy(szRet, "error"); + lstrcpy(szRet, _T("error")); goto done; } dwLastOutput = GetTickCount(); + // Now I'm talking with an executable copy of myself. while (dwWait != WAIT_OBJECT_0 || dwRead) { PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL); if (dwRead) { @@ -262,16 +277,16 @@ params: ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL); szBuf[dwRead] = 0; if (log) { - char *p, *p2; + TCHAR *p, *p2; SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf); if (GlobalSize(hUnusedBuf) < iReqLen && (iReqLen < g_stringsize || !(log & 2))) { GlobalUnlock(hUnusedBuf); hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND); if (!hUnusedBuf) { - lstrcpy(szRet, "error"); + lstrcpy(szRet, _T("error")); break; } - szUnusedBuf = (char *)GlobalLock(hUnusedBuf); + szUnusedBuf = (TCHAR *)GlobalLock(hUnusedBuf); } p = szUnusedBuf; // get the old left overs if (iReqLen < g_stringsize || !(log & 2)) lstrcat(p, szBuf); @@ -280,33 +295,33 @@ params: } if (!(log & 2)) { - while ((p = my_strstr(p, "\t"))) { + while ((p = my_strstr(p, _T("\t")))) { if ((int)(p - szUnusedBuf) > (int)(GlobalSize(hUnusedBuf) - TAB_REPLACE_SIZE - 1)) { - *p++ = ' '; + *p++ = _T(' '); } else { int len = lstrlen(p); - char *c_out=(char*)p+TAB_REPLACE_SIZE+len; - char *c_in=(char *)p+len; + TCHAR *c_out=(TCHAR*)p+TAB_REPLACE_SIZE+len; + TCHAR *c_in=(TCHAR *)p+len; while (len-- > 0) { *c_out--=*c_in--; } lstrcpy(p, TAB_REPLACE); p += TAB_REPLACE_SIZE; - *p = ' '; + *p = _T(' '); } } p = szUnusedBuf; // get the old left overs for (p2 = p; *p2;) { - if (*p2 == '\r') { + if (*p2 == _T('\r')) { *p2++ = 0; continue; } - if (*p2 == '\n') { + if (*p2 == _T('\n')) { *p2 = 0; while (!*p && p != p2) p++; LogMessage(p, bOEM); @@ -318,7 +333,7 @@ params: // If data was taken out from the unused buffer, move p contents to the start of szUnusedBuf if (p != szUnusedBuf) { - char *p2 = szUnusedBuf; + TCHAR *p2 = szUnusedBuf; while (*p) *p2++ = *p++; *p2 = 0; } @@ -328,7 +343,7 @@ params: else { if (g_to && GetTickCount() > dwLastOutput+g_to) { TerminateProcess(pi.hProcess, -1); - lstrcpy(szRet, "timeout"); + lstrcpy(szRet, _T("timeout")); } else Sleep(LOOPTIMEOUT); } @@ -341,8 +356,8 @@ done: if (log & 2) pushstring(szUnusedBuf); if (log & 1 && *szUnusedBuf) LogMessage(szUnusedBuf, bOEM); if ( dwExit == STATUS_ILLEGAL_INSTRUCTION ) - lstrcpy(szRet, "error"); - if (!szRet[0]) wsprintf(szRet,"%d",dwExit); + lstrcpy(szRet, _T("error")); + if (!szRet[0]) wsprintf(szRet,_T("%d"),dwExit); pushstring(szRet); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); @@ -350,7 +365,7 @@ done: CloseHandle(read_stdout); CloseHandle(newstdin); CloseHandle(read_stdin); - *(pExec-2) = '\0'; // skip space and quote + *(pExec-2) = _T('\0'); // skip space and quote if (executor) DeleteFile(executor); GlobalFree(g_exec); if (log) { @@ -361,27 +376,27 @@ done: } // Tim Kosse's LogMessage -void LogMessage(const char *pStr, BOOL bOEM) { +void LogMessage(const TCHAR *pStr, BOOL bOEM) { LVITEM item={0}; int nItemCount; if (!g_hwndList) return; //if (!lstrlen(pStr)) return; - if (bOEM == TRUE) OemToCharBuff(pStr, (char *)pStr, lstrlen(pStr)); + if (bOEM == TRUE) OemToCharBuff(pStr, (TCHAR *)pStr, lstrlen(pStr)); nItemCount=SendMessage(g_hwndList, LVM_GETITEMCOUNT, 0, 0); item.mask=LVIF_TEXT; - item.pszText=(char *)pStr; + item.pszText=(TCHAR *)pStr; item.cchTextMax=0; item.iItem=nItemCount; ListView_InsertItem(g_hwndList, &item); ListView_EnsureVisible(g_hwndList, item.iItem, 0); } -char *my_strstr(char *a, char *b) +TCHAR *my_strstr(TCHAR *a, TCHAR *b) { int l = lstrlen(b); while (lstrlen(a) >= l) { - char c = a[l]; + TCHAR c = a[l]; a[l] = 0; if (!lstrcmpi(a, b)) { @@ -394,25 +409,25 @@ char *my_strstr(char *a, char *b) return NULL; } -unsigned int my_atoi(char *s) { +unsigned int my_atoi(TCHAR *s) { unsigned int v=0; - if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) { + if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X'))) { s+=2; for (;;) { int c=*s++; - if (c >= '0' && c <= '9') c-='0'; - else if (c >= 'a' && c <= 'f') c-='a'-10; - else if (c >= 'A' && c <= 'F') c-='A'-10; + if (c >= _T('0') && c <= _T('9')) c-=_T('0'); + else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10; + else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10; else break; v<<=4; v+=c; } } - else if (*s == '0' && s[1] <= '7' && s[1] >= '0') { + else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0')) { s++; for (;;) { int c=*s++; - if (c >= '0' && c <= '7') c-='0'; + if (c >= _T('0') && c <= _T('7')) c-=_T('0'); else break; v<<=3; v+=c; @@ -420,7 +435,7 @@ unsigned int my_atoi(char *s) { } else { for (;;) { - int c=*s++ - '0'; + int c=*s++ - _T('0'); if (c < 0 || c > 9) break; v*=10; v+=c; @@ -429,14 +444,14 @@ unsigned int my_atoi(char *s) { return (int)v; } -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { DWORD Ret; STARTUPINFO si = {0}; PROCESS_INFORMATION pi = {0}; - char command_line[1024]; - char seekchar=' '; - char *cmdline; + TCHAR command_line[1024]; + TCHAR seekchar=_T(' '); + TCHAR *cmdline; si.cb = sizeof(si); // Make child process use this app's standard files. Not needed because the handles @@ -448,12 +463,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine lstrcpyn(command_line, GetCommandLine(), 1024); cmdline = command_line; - if (*cmdline == '\"') seekchar = *cmdline++; + if (*cmdline == _T('\"')) seekchar = *cmdline++; while (*cmdline && *cmdline != seekchar) cmdline=CharNext(cmdline); cmdline=CharNext(cmdline); // skip any spaces before the arguments - while (*cmdline && *cmdline == ' ') cmdline++; + while (*cmdline && *cmdline == _T(' ')) cmdline++; Ret = CreateProcess (NULL, cmdline, NULL, NULL, diff --git a/Contrib/zip2exe/main.cpp b/Contrib/zip2exe/main.cpp index eb0ad140..c85e8a7b 100644 --- a/Contrib/zip2exe/main.cpp +++ b/Contrib/zip2exe/main.cpp @@ -2,8 +2,14 @@ #include #include #include +#include "..\ExDLL\nsis_tchar.h" /* +version 0.36 +* Unicode support by Jim Park -- 08/27/2007 +* This support allow Unicode *ZIP file* names but does NOT allow the archive +* to store Unicode files inside it. That's a ZLIB limitation that I can't +* do much about. version 0.35 * drag & drop support @@ -38,50 +44,50 @@ extern "C" }; #include "resource.h" -const char *g_errcaption="Zip2Exe Error"; +const TCHAR *g_errcaption=_T("Zip2Exe Error"); HINSTANCE g_hInstance; HWND g_hwnd; HANDLE g_hThread; -char g_cmdline[1024]; +TCHAR g_cmdline[1024]; int g_extracting; int g_compressor; int g_compressor_solid; int g_mui; int g_zipfile_size; -char *g_options="";//"/V3"; +TCHAR *g_options=_T("");//_T("/V3"); static BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, - LPSTR lpszCmdParam, int nCmdShow) +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, + LPTSTR lpszCmdParam, int nCmdShow) { g_hInstance=hInstance; InitCommonControls(); return DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),GetDesktopWindow(),DlgProc); } -char tempzip_path[1024]; +TCHAR tempzip_path[1024]; int made; -static void doRMDir(char *buf) +static void doRMDir(TCHAR *buf) { HANDLE h; WIN32_FIND_DATA fd; - char *p=buf; + TCHAR *p=buf; while (*p) p++; - lstrcpy(p,"\\*.*"); + lstrcpy(p,_T("\\*.*")); h = FindFirstFile(buf,&fd); if (h != INVALID_HANDLE_VALUE) { do { - if (fd.cFileName[0] != '.' || - (fd.cFileName[1] != '.' && fd.cFileName[1])) + if (fd.cFileName[0] != _T('.') || + (fd.cFileName[1] != _T('.') && fd.cFileName[1])) { lstrcpy(p+1,fd.cFileName); if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) @@ -99,22 +105,22 @@ static void doRMDir(char *buf) RemoveDirectory(buf); } -static void doMKDir(char *directory) +static void doMKDir(TCHAR *directory) { - char *p, *p2; - char buf[MAX_PATH]; + TCHAR *p, *p2; + TCHAR buf[MAX_PATH]; if (!*directory) return; lstrcpy(buf,directory); p=buf; while (*p) p++; - while (p >= buf && *p != '\\') p--; + while (p >= buf && *p != _T('\\')) p--; p2 = buf; - if (p2[1] == ':') p2+=4; - else if (p2[0] == '\\' && p2[1] == '\\') + if (p2[1] == _T(':')) p2+=4; + else if (p2[0] == _T('\\') && p2[1] == _T('\\')) { p2+=2; - while (*p2 && *p2 != '\\') p2++; + while (*p2 && *p2 != _T('\\')) p2++; if (*p2) p2++; - while (*p2 && *p2 != '\\') p2++; + while (*p2 && *p2 != _T('\\')) p2++; if (*p2) p2++; } if (p >= p2) @@ -135,29 +141,29 @@ void tempzip_cleanup(HWND hwndDlg, int err) { SendDlgItemMessage(hwndDlg,IDC_ZIPINFO_FILES,LB_RESETCONTENT,0,0); EnableWindow(GetDlgItem(hwndDlg,IDOK),0); - SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,""); - SetDlgItemText(hwndDlg,IDC_ZIPFILE,""); - SetDlgItemText(hwndDlg,IDC_OUTFILE,""); + SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,_T("")); + SetDlgItemText(hwndDlg,IDC_ZIPFILE,_T("")); + SetDlgItemText(hwndDlg,IDC_OUTFILE,_T("")); } } -int tempzip_make(HWND hwndDlg, char *fn) +int tempzip_make(HWND hwndDlg, TCHAR *fn) { - char buf[MAX_PATH]; + TCHAR buf[MAX_PATH]; GetTempPath(MAX_PATH,buf); - GetTempFileName(buf,"z2e",GetTickCount(),tempzip_path); + GetTempFileName(buf,_T("z2e"),GetTickCount(),tempzip_path); if (!CreateDirectory(tempzip_path,NULL)) { GetTempPath(MAX_PATH,tempzip_path); - strcat(tempzip_path,"\\nsi"); + _tcscat(tempzip_path,_T("\\nsi")); if (!CreateDirectory(tempzip_path,NULL)) { tempzip_path[0]=0; - MessageBox(hwndDlg,"Error creating temporary directory",g_errcaption,MB_OK|MB_ICONSTOP); + MessageBox(hwndDlg,_T("Error creating temporary directory"),g_errcaption,MB_OK|MB_ICONSTOP); return 1; } } - FILE *fp=fopen(fn,"rb"); + FILE *fp=_tfopen(fn,_T("rb")); if (fp) { fseek(fp,0,SEEK_END); @@ -170,14 +176,14 @@ int tempzip_make(HWND hwndDlg, char *fn) if (!f || unzGoToFirstFile(f) != UNZ_OK) { if (f) unzClose(f); - MessageBox(hwndDlg,"Error opening ZIP file",g_errcaption,MB_OK|MB_ICONSTOP); + MessageBox(hwndDlg,_T("Error opening ZIP file"),g_errcaption,MB_OK|MB_ICONSTOP); return 1; } int nf=0, nkb=0; g_extracting=1; do { - char filename[MAX_PATH]; + TCHAR filename[MAX_PATH]; unz_file_info info; unzGetCurrentFileInfo(f,&info,filename,sizeof(filename),NULL,0,NULL,0); @@ -189,29 +195,29 @@ int tempzip_make(HWND hwndDlg, char *fn) } if (filename[0] && - filename[strlen(filename)-1] != '\\' && - filename[strlen(filename)-1] != '/') + filename[_tcsclen(filename)-1] != _T('\\') && + filename[_tcsclen(filename)-1] != _T('/')) { - char *pfn=filename; + TCHAR *pfn=filename; while (*pfn) { - if (*pfn == '/') *pfn='\\'; + if (*pfn == _T('/')) *pfn=_T('\\'); pfn++; } pfn=filename; - if (pfn[1] == ':' && pfn[2] == '\\') pfn+=3; - while (*pfn == '\\') pfn++; + if (pfn[1] == _T(':') && pfn[2] == _T('\\')) pfn+=3; + while (*pfn == _T('\\')) pfn++; - char out_filename[1024]; + TCHAR out_filename[1024]; lstrcpy(out_filename,tempzip_path); - lstrcat(out_filename,"\\"); + lstrcat(out_filename,_T("\\")); lstrcat(out_filename,pfn); - if (strstr(pfn,"\\")) + if (_tcsstr(pfn,_T("\\"))) { - char buf[1024]; + TCHAR buf[1024]; lstrcpy(buf,out_filename); - char *p=buf+strlen(buf); - while (p > buf && *p != '\\') p--; + TCHAR *p=buf+_tcsclen(buf); + while (p > buf && *p != _T('\\')) p--; *p=0; if (buf[0]) doMKDir(buf); } @@ -221,11 +227,12 @@ int tempzip_make(HWND hwndDlg, char *fn) SendDlgItemMessage(hwndDlg,IDC_ZIPINFO_FILES,LB_ADDSTRING,0,(LPARAM)pfn); FILE *fp; int l; - fp = fopen(out_filename,"wb"); + fp = _tfopen(out_filename,_T("wb")); if (fp) { do { + // Jim Park: Local buf, no need to TCHAR char buf[1024]; l=unzReadCurrentFile(f,buf,sizeof(buf)); if (l > 0) @@ -234,7 +241,7 @@ int tempzip_make(HWND hwndDlg, char *fn) { unzClose(f); fclose(fp); - MessageBox(hwndDlg,"Error writing output file(s)",g_errcaption,MB_OK|MB_ICONSTOP); + MessageBox(hwndDlg,_T("Error writing output file(s)"),g_errcaption,MB_OK|MB_ICONSTOP); g_extracting=0; return 1; } @@ -260,12 +267,12 @@ int tempzip_make(HWND hwndDlg, char *fn) else { unzClose(f); - MessageBox(hwndDlg,"Error opening output file(s)",g_errcaption,MB_OK|MB_ICONSTOP); + MessageBox(hwndDlg,_T("Error opening output file(s)"),g_errcaption,MB_OK|MB_ICONSTOP); g_extracting=0; return 1; } nf++; - wsprintf(buf,"Extracting: %d files, %dKB",nf,nkb); + wsprintf(buf,_T("Extracting: %d files, %dKB"),nf,nkb); SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,buf); MSG msg; int quit=0; @@ -285,7 +292,7 @@ int tempzip_make(HWND hwndDlg, char *fn) else { unzClose(f); - MessageBox(hwndDlg,"Error extracting from ZIP file",g_errcaption,MB_OK|MB_ICONSTOP); + MessageBox(hwndDlg,_T("Error extracting from ZIP file"),g_errcaption,MB_OK|MB_ICONSTOP); g_extracting=0; return 1; } @@ -293,45 +300,45 @@ int tempzip_make(HWND hwndDlg, char *fn) } while (unzGoToNextFile(f) == UNZ_OK); g_extracting=0; - wsprintf(buf,"Extracted: %d files, %dKB",nf,nkb); + wsprintf(buf,_T("Extracted: %d files, %dKB"),nf,nkb); SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,buf); unzClose(f); return 0; } -char *gp_winamp = "(WINAMP DIRECTORY)"; -char *gp_winamp_plugins = "(WINAMP PLUG-INS DIRECTORY)"; -char *gp_winamp_vis = "(WINAMP VIS PLUG-INS DIRECTORY)"; -char *gp_winamp_dsp = "(WINAMP DSP PLUG-INS DIRECTORY)"; -char *gp_winamp_skins = "(WINAMP SKINS DIRECTORY)"; -char *gp_poi = "(PATH OF INSTALLER)"; +TCHAR *gp_winamp = _T("(WINAMP DIRECTORY)"); +TCHAR *gp_winamp_plugins = _T("(WINAMP PLUG-INS DIRECTORY)"); +TCHAR *gp_winamp_vis = _T("(WINAMP VIS PLUG-INS DIRECTORY)"); +TCHAR *gp_winamp_dsp = _T("(WINAMP DSP PLUG-INS DIRECTORY)"); +TCHAR *gp_winamp_skins = _T("(WINAMP SKINS DIRECTORY)"); +TCHAR *gp_poi = _T("(PATH OF INSTALLER)"); -void wnd_printf(const char *str) +void wnd_printf(const TCHAR *str) { if (!*str) return; - char existing_text[32000]; + TCHAR existing_text[32000]; existing_text[0]=0; UINT l=GetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, existing_text, 32000); - l+=strlen(str); + l+=_tcsclen(str); - char *p=existing_text; + TCHAR *p=existing_text; existing_text[31000]=0; while (l > 31000 && *p) { - while (*p != '\r' && *p != '\n' && *p) + while (*p != _T('\r') && *p != _T('\n') && *p) { p++; l--; } - while (*p == '\r' || *p == '\n') + while (*p == _T('\r') || *p == _T('\n')) { p++; l--; } } - char buf[31000]; + TCHAR buf[31000]; lstrcpy(buf,p); lstrcpy(existing_text,buf); lstrcat(existing_text,str); @@ -341,7 +348,7 @@ void wnd_printf(const char *str) } -void ErrorMessage(char *str) //display detailed error info +void ErrorMessage(TCHAR *str) //display detailed error info { LPVOID msg; FormatMessage( @@ -354,14 +361,14 @@ void ErrorMessage(char *str) //display detailed error info NULL ); wnd_printf(str); - wnd_printf(": "); - wnd_printf((char*)msg); + wnd_printf(_T(": ")); + wnd_printf((TCHAR*)msg); LocalFree(msg); } -DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor wwwinamp +DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor makensis { - char buf[1024]; //i/o buffer + TCHAR buf[1024]; //i/o buffer STARTUPINFO si={sizeof(si),}; SECURITY_ATTRIBUTES sa={sizeof(sa),}; SECURITY_DESCRIPTOR sd={0,}; //security information for pipes @@ -381,7 +388,7 @@ DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor wwwinamp if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) //create stdout pipe { - ErrorMessage("CreatePipe"); + ErrorMessage(_T("CreatePipe")); PostMessage(g_hwnd,WM_USER+1203,0,1); return 1; } @@ -404,8 +411,8 @@ DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor wwwinamp if (!CreateProcess(NULL,g_cmdline,NULL,NULL,TRUE,CREATE_NEW_CONSOLE, NULL,tempzip_path,&si,&pi)) { - ErrorMessage("CreateProcess"); - wnd_printf("\r\nPlease make sure the path to makensis.exe is correct."); + ErrorMessage(_T("CreateProcess")); + wnd_printf(_T("\r\nPlease make sure the path to makensis.exe is correct.")); CloseHandle(newstdout); CloseHandle(read_stdout); PostMessage(g_hwnd,WM_USER+1203,0,1); @@ -416,26 +423,30 @@ DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor wwwinamp DWORD bread; //bytes read DWORD avail; //bytes available + // Number of bytes available in the buffer. + const int bufBytesAvail = sizeof(buf)-sizeof(TCHAR); + memset(buf,0,sizeof(buf)); while (1) //main program loop { - PeekNamedPipe(read_stdout,buf,1023,&bread,&avail,NULL); + PeekNamedPipe(read_stdout,buf,bufBytesAvail,&bread,&avail,NULL); + //check to see if there is any data to read from stdout if (bread != 0) { memset(buf,0,sizeof(buf)); - if (avail > 1023) + if (avail > bufBytesAvail) { - while (bread >= 1023) + while (bread >= bufBytesAvail) { - ReadFile(read_stdout,buf,1023,&bread,NULL); //read the stdout pipe + ReadFile(read_stdout,buf,bufBytesAvail,&bread,NULL); //read the stdout pipe wnd_printf(buf); memset(buf,0,sizeof(buf)); } } else { - ReadFile(read_stdout,buf,1023,&bread,NULL); + ReadFile(read_stdout,buf,bufBytesAvail,&bread,NULL); wnd_printf(buf); } } @@ -452,7 +463,7 @@ DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor wwwinamp CloseHandle(read_stdout); - wsprintf(buf,"(source ZIP size was %d bytes)\r\n",g_zipfile_size); + wsprintf(buf,_T("(source ZIP size was %d bytes)\r\n"),g_zipfile_size); wnd_printf(buf); PostMessage(g_hwnd,WM_USER+1203,0,0); @@ -460,107 +471,107 @@ DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor wwwinamp } -char nsifilename[MAX_PATH]; +TCHAR nsifilename[MAX_PATH]; void makeEXE(HWND hwndDlg) { - char buf[2048]; + TCHAR buf[2048]; GetTempPath(MAX_PATH,buf); - GetTempFileName(buf,"zne",0,nsifilename); - FILE *fp=fopen(nsifilename,"w"); + GetTempFileName(buf,_T("zne"),0,nsifilename); + FILE *fp=fopen(nsifilename,_T("w")); if (!fp) { - MessageBox(hwndDlg,"Error writing .NSI file",g_errcaption,MB_OK|MB_ICONSTOP); + MessageBox(hwndDlg,_T("Error writing .NSI file"),g_errcaption,MB_OK|MB_ICONSTOP); PostMessage(g_hwnd,WM_USER+1203,0,0); return; } GetDlgItemText(hwndDlg,IDC_INSTNAME,buf,sizeof(buf)); - fprintf(fp,"!define ZIP2EXE_NAME `%s`\n",buf); + _ftprintf(fp,_T("!define ZIP2EXE_NAME `%s`\n"),buf); GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf)); - fprintf(fp,"!define ZIP2EXE_OUTFILE `%s`\n",buf); + _ftprintf(fp,_T("!define ZIP2EXE_OUTFILE `%s`\n"),buf); if (g_compressor == 1) - fprintf(fp,"!define ZIP2EXE_COMPRESSOR_ZLIB\n"); + _ftprintf(fp,_T("!define ZIP2EXE_COMPRESSOR_ZLIB\n")); if (g_compressor == 2) - fprintf(fp,"!define ZIP2EXE_COMPRESSOR_BZIP2\n"); + _ftprintf(fp,_T("!define ZIP2EXE_COMPRESSOR_BZIP2\n")); if (g_compressor == 3) - fprintf(fp,"!define ZIP2EXE_COMPRESSOR_LZMA\n"); + _ftprintf(fp,_T("!define ZIP2EXE_COMPRESSOR_LZMA\n")); if (g_compressor_solid == 1) - fprintf(fp,"!define ZIP2EXE_COMPRESSOR_SOLID\n"); + _ftprintf(fp,_T("!define ZIP2EXE_COMPRESSOR_SOLID\n")); GetDlgItemText(hwndDlg,IDC_INSTPATH,buf,sizeof(buf)); int iswinamp=0; - char *iswinampmode=NULL; - if (!strcmp(buf,gp_poi)) lstrcpy(buf,"$EXEDIR"); + TCHAR *iswinampmode=NULL; + if (!_tcscmp(buf,gp_poi)) lstrcpy(buf,_T("$EXEDIR")); - if (!strcmp(buf,gp_winamp)) + if (!_tcscmp(buf,gp_winamp)) { iswinamp=1; } - if (!strcmp(buf,gp_winamp_plugins)) + if (!_tcscmp(buf,gp_winamp_plugins)) { iswinamp=1; - fprintf(fp,"!define ZIP2EXE_INSTALLDIR_PLUGINS\n"); + _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR_PLUGINS\n")); } - if (!strcmp(buf,gp_winamp_vis)) + if (!_tcscmp(buf,gp_winamp_vis)) { iswinamp=1; - iswinampmode="VisDir"; + iswinampmode=_T("VisDir"); } - if (!strcmp(buf,gp_winamp_dsp)) + if (!_tcscmp(buf,gp_winamp_dsp)) { iswinamp=1; - iswinampmode="DSPDir"; + iswinampmode=_T("DSPDir"); } - if (!strcmp(buf,gp_winamp_skins)) + if (!_tcscmp(buf,gp_winamp_skins)) { iswinamp=1; - iswinampmode="SkinDir"; - fprintf(fp,"!define ZIP2EXE_INSTALLDIR_SKINS\n"); + iswinampmode=_T("SkinDir"); + _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR_SKINS\n")); } if (iswinamp) { - fprintf(fp,"!define ZIP2EXE_INSTALLDIR_WINAMP\n"); + _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR_WINAMP\n")); if (iswinampmode) { - fprintf(fp,"!define ZIP2EXE_INSTALLDIR_WINAMPMODE `%s`\n",iswinampmode); + _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR_WINAMPMODE `%s`\n"),iswinampmode); } } else // set out path to $INSTDIR { - fprintf(fp,"!define ZIP2EXE_INSTALLDIR `%s`\n",buf); + _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR `%s`\n"),buf); } - fprintf(fp,"!include `${NSISDIR}\\Contrib\\zip2exe\\Base.nsh`\n"); - fprintf(fp,"!include `${NSISDIR}\\Contrib\\zip2exe\\%s.nsh`\n",g_mui?"Modern":"Classic"); + _ftprintf(fp,_T("!include `${NSISDIR}\\Contrib\\zip2exe\\Base.nsh`\n")); + _ftprintf(fp,_T("!include `${NSISDIR}\\Contrib\\zip2exe\\%s.nsh`\n"),g_mui?_T("Modern"):_T("Classic")); - fprintf(fp,"!insertmacro SECTION_BEGIN\n"); - fprintf(fp,"File /r `%s\\*.*`\n",tempzip_path); - fprintf(fp,"!insertmacro SECTION_END\n"); + _ftprintf(fp,_T("!insertmacro SECTION_BEGIN\n")); + _ftprintf(fp,_T("File /r `%s\\*.*`\n"),tempzip_path); + _ftprintf(fp,_T("!insertmacro SECTION_END\n")); fclose(fp); - char g_makensis_path[MAX_PATH]; - char *p=g_makensis_path; + TCHAR g_makensis_path[MAX_PATH]; + TCHAR *p=g_makensis_path; GetModuleFileName(g_hInstance,g_makensis_path,sizeof(g_makensis_path)); while (*p) p++; - while (p >= g_makensis_path && *p != '\\') p--; - strcpy(p+1,"makensis.exe"); + while (p >= g_makensis_path && *p != _T('\\')) p--; + _tcscpy(p+1,_T("makensis.exe")); WIN32_FIND_DATA fd; HANDLE h=FindFirstFile(g_makensis_path,&fd); if (h==INVALID_HANDLE_VALUE) { - if ((p-g_makensis_path>4)&&(tolower(*(p-1))=='n')&&(tolower(*(p-2))=='i')&&(tolower(*(p-3))=='b')&&(*(p-4)=='\\')) + if ((p-g_makensis_path>4)&&(_totlower(*(p-1))==_T('n'))&&(_totlower(*(p-2))==_T('i'))&&(_totlower(*(p-3))==_T('b'))&&(*(p-4)==_T('\\'))) { p -= 4; - strcpy(p+1,"makensis.exe"); + _tcscpy(p+1,_T("makensis.exe")); h=FindFirstFile(g_makensis_path,&fd); if (h==INVALID_HANDLE_VALUE) { - MessageBox(hwndDlg,"Error finding makensis.exe.",g_errcaption,MB_OK|MB_ICONSTOP); + MessageBox(hwndDlg,_T("Error finding makensis.exe."),g_errcaption,MB_OK|MB_ICONSTOP); PostMessage(g_hwnd,WM_USER+1203,0,0); return; } @@ -570,29 +581,28 @@ void makeEXE(HWND hwndDlg) - wsprintf(g_cmdline,"\"%s\" %s \"%s\"",g_makensis_path,g_options,nsifilename); - + wsprintf(g_cmdline,_T("\"%s\" %s \"%s\""),g_makensis_path,g_options,nsifilename); DWORD id; g_hThread=CreateThread(NULL,0,ThreadProc,0,0,&id); } -void SetZip(HWND hwndDlg, char *path) +void SetZip(HWND hwndDlg, TCHAR *path) { - char buf2[1024]; + TCHAR buf2[1024]; lstrcpy(buf2,path); tempzip_cleanup(hwndDlg,1); SetDlgItemText(hwndDlg,IDC_ZIPFILE,path); - char *t=path+lstrlen(path); - while (t > path && *t != '\\' && *t != '.') t--; + TCHAR *t=path+lstrlen(path); + while (t > path && *t != _T('\\') && *t != _T('.')) t--; { - char *p=t; - while (p >= path && *p != '\\') p--; + TCHAR *p=t; + while (p >= path && *p != _T('\\')) p--; p++; *t=0; - SetDlgItemText(hwndDlg,IDC_INSTNAME,p[0]?p:"Stuff"); + SetDlgItemText(hwndDlg,IDC_INSTNAME,p[0]?p:_T("Stuff")); } - strcpy(t,".exe"); + _tcscpy(t,_T(".exe")); SetDlgItemText(hwndDlg,IDC_OUTFILE,path); if (tempzip_make(hwndDlg,buf2)) tempzip_cleanup(hwndDlg,1); else @@ -615,14 +625,14 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) CheckDlgButton(hwndDlg,IDC_LZMA,BST_CHECKED); CheckDlgButton(hwndDlg,IDC_MODERNUI,BST_CHECKED); SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_poi); - SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$TEMP"); - SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$SYSDIR"); - SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$WINDIR"); - SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$DESKTOP"); - SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$DESKTOP\\YourNameHere"); - SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$PROGRAMFILES\\YourNameHere"); - SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$STARTMENU"); - SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$SMPROGRAMS"); + SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$TEMP")); + SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$SYSDIR")); + SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$WINDIR")); + SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$DESKTOP")); + SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$DESKTOP\\YourNameHere")); + SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$PROGRAMFILES\\YourNameHere")); + SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$STARTMENU")); + SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$SMPROGRAMS")); SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp); SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_plugins); @@ -638,7 +648,7 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) hFont=CreateFont(15,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,"Courier New"); + DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,_T("Courier New")); SendDlgItemMessage(hwndDlg,IDC_OUTPUTTEXT,WM_SETFONT,(WPARAM)hFont,0); DragAcceptFiles(hwndDlg,TRUE); @@ -666,7 +676,7 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) break; case WM_DROPFILES: { - char dropped_file[MAX_PATH]=""; + TCHAR dropped_file[MAX_PATH]=_T(""); if (DragQueryFile((HDROP)wParam,(UINT)-1,NULL,0)==1) { DragQueryFile((HDROP)wParam,0,dropped_file,MAX_PATH); @@ -677,7 +687,7 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) } else { - MessageBox(hwndDlg,"Dropping more than one zip file at a time is not supported",g_errcaption,MB_OK|MB_ICONSTOP); + MessageBox(hwndDlg,_T("Dropping more than one zip file at a time is not supported"),g_errcaption,MB_OK|MB_ICONSTOP); } DragFinish((HDROP)wParam); return TRUE; @@ -688,13 +698,13 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) case IDC_BROWSE: if (!g_extracting) { OPENFILENAME l={sizeof(l),}; - char buf[1024]; + TCHAR buf[1024]; l.hwndOwner = hwndDlg; - l.lpstrFilter = "ZIP Files\0*.zip\0All Files\0*.*\0"; + l.lpstrFilter = _T("ZIP Files\0*.zip\0All Files\0*.*\0"); l.lpstrFile = buf; l.nMaxFile = 1023; - l.lpstrTitle = "Open ZIP File"; - l.lpstrDefExt = "zip"; + l.lpstrTitle = _T("Open ZIP File"); + l.lpstrDefExt = _T("zip"); l.lpstrInitialDir = NULL; l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST; buf[0]=0; @@ -707,13 +717,13 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) case IDC_BROWSE2: { OPENFILENAME l={sizeof(l),}; - char buf[1024]; + TCHAR buf[1024]; l.hwndOwner = hwndDlg; - l.lpstrFilter = "Executables\0*.exe\0All Files\0*.*\0"; + l.lpstrFilter = _T("Executables\0*.exe\0All Files\0*.*\0"); l.lpstrFile = buf; l.nMaxFile = 1023; - l.lpstrTitle = "Select Output EXE File"; - l.lpstrDefExt = "exe"; + l.lpstrTitle = _T("Select Output EXE File"); + l.lpstrDefExt = _T("exe"); l.lpstrInitialDir = NULL; l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER; GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf)); @@ -733,16 +743,16 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { for (size_t x = 0; x < sizeof(ids)/sizeof(ids[0]); x ++) ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_SHOWNA); - SetDlgItemText(hwndDlg,IDOK,"&Generate"); + SetDlgItemText(hwndDlg,IDOK,_T("&Generate")); EnableWindow(GetDlgItem(hwndDlg,IDOK),1); } } break; case IDC_TEST: if (!g_hThread) { - char buf[1024]; - GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf)); - ShellExecute(hwndDlg,"open",buf,"","",SW_SHOW); + TCHAR buf[1024]; + GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,_countof(buf)); + ShellExecute(hwndDlg,_T("open"),buf,_T(""),_T(""),SW_SHOW); } break; case IDOK: @@ -761,11 +771,11 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) else g_compressor_solid = 0; g_mui=!IsDlgButtonChecked(hwndDlg,IDC_CLASSICUI); - SetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, ""); + SetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, _T("")); for (size_t x = 0; x < sizeof(ids)/sizeof(ids[0]); x ++) ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_HIDE); ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_SHOWNA); - SetDlgItemText(hwndDlg,IDOK,"&Close"); + SetDlgItemText(hwndDlg,IDOK,_T("&Close")); EnableWindow(GetDlgItem(hwndDlg,IDOK),0); makeEXE(hwndDlg); diff --git a/Contrib/zip2exe/zlib/adler32.c b/Contrib/zip2exe/zlib/adler32.c index 007ba262..6d5cd7ca 100644 --- a/Contrib/zip2exe/zlib/adler32.c +++ b/Contrib/zip2exe/zlib/adler32.c @@ -3,7 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* @(#) $Id$ */ +/* @(#) $Id: adler32.c,v 1.2 2005/07/22 17:42:47 kichik Exp $ */ #define ZLIB_INTERNAL #include "zlib.h" diff --git a/Contrib/zip2exe/zlib/ioapi.c b/Contrib/zip2exe/zlib/ioapi.c index f1bee23e..3c002269 100644 --- a/Contrib/zip2exe/zlib/ioapi.c +++ b/Contrib/zip2exe/zlib/ioapi.c @@ -4,6 +4,7 @@ Version 1.01e, February 12th, 2005 Copyright (C) 1998-2005 Gilles Vollant + Unicode support by Jim Park -- 08/28/2007 */ #include @@ -31,7 +32,7 @@ voidpf ZCALLBACK fopen_file_func OF(( voidpf opaque, - const char* filename, + const TCHAR* filename, int mode)); uLong ZCALLBACK fread_file_func OF(( @@ -67,22 +68,22 @@ int ZCALLBACK ferror_file_func OF(( voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) voidpf opaque; - const char* filename; + const TCHAR* filename; int mode; { FILE* file = NULL; - const char* mode_fopen = NULL; + const TCHAR* mode_fopen = NULL; if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; + mode_fopen = _T("rb"); else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; + mode_fopen = _T("r+b"); else if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; + mode_fopen = _T("wb"); if ((filename!=NULL) && (mode_fopen != NULL)) - file = fopen(filename, mode_fopen); + file = _tfopen(filename, mode_fopen); return file; } diff --git a/Contrib/zip2exe/zlib/ioapi.h b/Contrib/zip2exe/zlib/ioapi.h index 7d457baa..351d230e 100644 --- a/Contrib/zip2exe/zlib/ioapi.h +++ b/Contrib/zip2exe/zlib/ioapi.h @@ -4,11 +4,15 @@ Version 1.01e, February 12th, 2005 Copyright (C) 1998-2005 Gilles Vollant + + Unicode support by Jim Park -- 08/28/2007 */ #ifndef _ZLIBIOAPI_H #define _ZLIBIOAPI_H +#include "../../ExDLL/nsis_tchar.h" + #define ZLIB_FILEFUNC_SEEK_CUR (1) #define ZLIB_FILEFUNC_SEEK_END (2) @@ -35,7 +39,7 @@ extern "C" { #endif -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const TCHAR* filename, int mode)); typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); diff --git a/Contrib/zip2exe/zlib/unzip.c b/Contrib/zip2exe/zlib/unzip.c index 9ad4766d..a4f41da2 100644 --- a/Contrib/zip2exe/zlib/unzip.c +++ b/Contrib/zip2exe/zlib/unzip.c @@ -4,6 +4,9 @@ Copyright (C) 1998-2005 Gilles Vollant Read unzip.h for more info + + Unicode support by Jim Park -- 08/28/2007 + (Unicode ZIP file name, but not the files in the archive itself.) */ /* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of @@ -395,7 +398,7 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) of this unzip package. */ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) - const char *path; + const TCHAR *path; zlib_filefunc_def* pzlib_filefunc_def; { unz_s us; @@ -498,7 +501,7 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) extern unzFile ZEXPORT unzOpen (path) - const char *path; + const TCHAR *path; { return unzOpen2(path, NULL); } diff --git a/Contrib/zip2exe/zlib/unzip.h b/Contrib/zip2exe/zlib/unzip.h index b247937c..7e7c2ed4 100644 --- a/Contrib/zip2exe/zlib/unzip.h +++ b/Contrib/zip2exe/zlib/unzip.h @@ -32,6 +32,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. + Unicode support by Jim Park -- 08/28/2007 + (Support of the archive file name being Unicode but not the files in + the archive itself. That requires modifying the ZLIB lib not just + here but the user's zlib-based tool.) */ @@ -132,7 +136,7 @@ extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, */ -extern unzFile ZEXPORT unzOpen OF((const char *path)); +extern unzFile ZEXPORT unzOpen OF((const TCHAR *path)); /* Open a Zip file. path contain the full pathname (by example, on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer @@ -143,7 +147,7 @@ extern unzFile ZEXPORT unzOpen OF((const char *path)); of this unzip package. */ -extern unzFile ZEXPORT unzOpen2 OF((const char *path, +extern unzFile ZEXPORT unzOpen2 OF((const TCHAR *path, zlib_filefunc_def* pzlib_filefunc_def)); /* Open a Zip file, like unzOpen, but provide a set of file low level API diff --git a/Docs/src/credits.but b/Docs/src/credits.but index 2a0ea89c..df84ae4d 100644 --- a/Docs/src/credits.but +++ b/Docs/src/credits.but @@ -66,6 +66,12 @@ \b InstallOptions improvements +\e{Jim Park} + +\b Unicode support + +\e{Olivier Marcoux} + \e{nnop@newmail.ru} \e{Ryan Geiss} diff --git a/Include/FileFunc.nsh b/Include/FileFunc.nsh index 87195b8c..8bd86433 100644 --- a/Include/FileFunc.nsh +++ b/Include/FileFunc.nsh @@ -910,7 +910,7 @@ RefreshShellIcons StrCpy $6 1073741824 FileFunc_DriveSpace_getspace: - System::Call 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l)i(r0,.r2,.r3,.)' + System::Call 'kernel32::GetDiskFreeSpaceEx(t, *l, *l, *l)i(r0,.r2,.r3,.)' StrCmp $5 T 0 +3 StrCpy $0 $3 @@ -970,7 +970,7 @@ RefreshShellIcons System::Alloc 1024 Pop $2 - System::Call 'kernel32::GetLogicalDriveStringsA(i,i) i(1024, r2)' + System::Call 'kernel32::GetLogicalDriveStrings(i,i) i(1024, r2)' StrCmp $0 ALL FileFunc_GetDrives_drivestring StrCmp $0 '' 0 FileFunc_GetDrives_typeset @@ -1007,10 +1007,10 @@ RefreshShellIcons StrCpy $3 $2 FileFunc_GetDrives_enumok: - System::Call 'kernel32::lstrlenA(t) i(i r3) .r4' + System::Call 'kernel32::lstrlen(t) i(i r3) .r4' StrCmp $4$0 '0ALL' FileFunc_GetDrives_enumex StrCmp $4 0 FileFunc_GetDrives_typeset - System::Call 'kernel32::GetDriveTypeA(t) i(i r3) .r5' + System::Call 'kernel32::GetDriveType(t) i(i r3) .r5' StrCmp $0 ALL +2 StrCmp $5 $6 FileFunc_GetDrives_letter FileFunc_GetDrives_enumnext @@ -1111,7 +1111,7 @@ RefreshShellIcons FileFunc_GetTime_getfile: IfFileExists $0 0 FileFunc_GetTime_error System::Call '*(i,l,l,l,i,i,i,i,&t260,&t14) i .r6' - System::Call 'kernel32::FindFirstFileA(t,i)i(r0,r6) .r2' + System::Call 'kernel32::FindFirstFile(t,i)i(r0,r6) .r2' System::Call 'kernel32::FindClose(i)i(r2)' FileFunc_GetTime_gettime: @@ -1401,8 +1401,8 @@ RefreshShellIcons Push $0 Push $1 Push $2 - System::Call 'kernel32::GetModuleFileNameA(i 0, t .r0, i 1024)' - System::Call 'kernel32::GetLongPathNameA(t r0, t .r1, i 1024)i .r2' + System::Call 'kernel32::GetModuleFileName(i 0, t .r0, i 1024)' + System::Call 'kernel32::GetLongPathName(t r0, t .r1, i 1024)i .r2' StrCmp $2 error +2 StrCpy $0 $1 Pop $2 @@ -1429,7 +1429,7 @@ RefreshShellIcons Push $1 Push $2 StrCpy $0 $EXEDIR - System::Call 'kernel32::GetLongPathNameA(t r0, t .r1, i 1024)i .r2' + System::Call 'kernel32::GetLongPathName(t r0, t .r1, i 1024)i .r2' StrCmp $2 error +2 StrCpy $0 $1 Pop $2 diff --git a/Include/LogicLib.nsh b/Include/LogicLib.nsh index 326417a2..ba0b5277 100644 --- a/Include/LogicLib.nsh +++ b/Include/LogicLib.nsh @@ -155,7 +155,7 @@ ; Extra string tests (cannot do these case-sensitively - I tried and lstrcmp still ignored the case) !macro _StrCmpI _a _b _e _l _m !insertmacro _LOGICLIB_TEMP - System::Call `kernel32::lstrcmpiA(ts, ts) i.s` `${_a}` `${_b}` + System::Call `kernel32::lstrcmpi(ts, ts) i.s` `${_a}` `${_b}` Pop $_LOGICLIB_TEMP IntCmp $_LOGICLIB_TEMP 0 `${_e}` `${_l}` `${_m}` !macroend diff --git a/Include/StrFunc.nsh b/Include/StrFunc.nsh index f6c4b3e4..1b0cb18c 100644 --- a/Include/StrFunc.nsh +++ b/Include/StrFunc.nsh @@ -411,7 +411,7 @@ o-----------------------------------------------------------------------------o System::Call 'kernel32::GlobalLock(i r2) i.r3' ;Step 4: Copy the text to locked clipboard buffer - System::Call 'kernel32::lstrcpyA(i r3, t r0)' + System::Call 'kernel32::lstrcpy(i r3, t r0)' ;Step 5: Unlock the handle again System::Call 'kernel32::GlobalUnlock(i r2)' @@ -455,7 +455,7 @@ o-----------------------------------------------------------------------------o System::Call 'kernel32::GlobalLock(i r2) i.r3' ;Step 7: Copy the text to locked clipboard buffer - System::Call 'kernel32::lstrcpyA(i r3, t r0)' + System::Call 'kernel32::lstrcpy(i r3, t r0)' ;Step 8: Unlock the handle again System::Call 'kernel32::GlobalUnlock(i r2)' @@ -1192,7 +1192,7 @@ o-----------------------------------------------------------------------------o ; variable because it won't be used anymore ${If} $6 == 1 - System::Call `kernel32::lstrcmpA(ts, ts) i.s` `$R3` `$1` + System::Call `kernel32::lstrcmp(ts, ts) i.s` `$R3` `$1` Pop $R3 ${If} $R3 = 0 StrCpy $R3 1 ; Continue diff --git a/Include/WinVer.nsh b/Include/WinVer.nsh index cc860c1e..7c562575 100644 --- a/Include/WinVer.nsh +++ b/Include/WinVer.nsh @@ -151,8 +151,13 @@ # some definitions from header files -!define OSVERSIONINFOA_SIZE 148 -!define OSVERSIONINFOEXA_SIZE 156 +!ifdef NSIS_UNICODE +!define OSVERSIONINFO_SIZE 276 ; OSVERSIONINFOW +!define OSVERSIONINFOEX_SIZE 284 ; OSVERSIONINFOEXW +!else +!define OSVERSIONINFO_SIZE 148 ; OSVERSIONINFOA +!define OSVERSIONINFOEX_SIZE 156 ; OSVERSIONINFOEXA +!endif !define VER_PLATFORM_WIN32_NT 2 !define VER_NT_WORKSTATION 1 @@ -206,15 +211,15 @@ Push $R0 ;temp # allocate memory - System::Alloc ${OSVERSIONINFOEXA_SIZE} + System::Alloc ${OSVERSIONINFOEX_SIZE} Pop $0 # use OSVERSIONINFOEX - !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOEXA_SIZE} + !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOEX_SIZE} IntCmp $3 0 "" _winver_ex _winver_ex # OSVERSIONINFOEX not allowed (Win9x or NT4 w/SP < 6), use OSVERSIONINFO - !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOA_SIZE} + !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFO_SIZE} _winver_ex: # get results from struct @@ -266,7 +271,7 @@ _winver_nt: # nt - IntCmp $R0 ${OSVERSIONINFOEXA_SIZE} "" _winver_sp_noex _winver_sp_noex + IntCmp $R0 ${OSVERSIONINFOEX_SIZE} "" _winver_sp_noex _winver_sp_noex # discard szCSDVersion Pop $0 diff --git a/Menu/index.html b/Menu/index.html index 10539482..ed58ed7b 100644 --- a/Menu/index.html +++ b/Menu/index.html @@ -17,7 +17,7 @@

Developer Center
- Many more examples, tutorials, plug-ins and NSIS-releted software are available + Many more examples, tutorials, plug-ins and NSIS-related software are available at the on-line Developer Center.

diff --git a/SCons/Config/ms b/SCons/Config/ms index 3386b17c..87b24aa5 100644 --- a/SCons/Config/ms +++ b/SCons/Config/ms @@ -17,7 +17,7 @@ defenv['STDCALL'] = '__stdcall' if float(defenv['MSVS_VERSION'].replace('Exp','')) >= 8.0: defenv['EXCEPTION_FLAG'] = '/EHsc' defenv.Append(CCFLAGS = ['/GS-']) - defenv.Append(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS', '_CRT_NONSTDC_NO_WARNINGS']) + defenv.Append(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS', '_CRT_NONSTDC_NO_WARNINGS', '_CRT_SECURE_NO_DEPRECATE', '_CRT_NON_CONFORMING_SWPRINTFS']) else: defenv['EXCEPTION_FLAG'] = '/GX' @@ -36,6 +36,10 @@ if defenv['DEBUG']: defenv.Append(CCFLAGS = ['/Fd${TARGET.dir}\\${TARGET.dir.file}.pdb']) defenv.Append(LINKFLAGS = ['/debug']) +### unicode +if defenv['UNICODE']: + defenv.Append(CPPDEFINES = ['_UNICODE', 'UNICODE']) + ### workarounds # Some Platform SDK version includes a bad version of libcp.lib. @@ -45,38 +49,42 @@ if defenv['DEBUG']: confenv = defenv.Clone() conf = confenv.Configure() -libcptest = """ -#include -int main() { - // %s - std::ofstream header("test", std::ofstream::out); - return 0; -} -""" +# For VS 2005 and up, the single threaded version of C runtime +# need not be explicitly linked. +if float(defenv['MSVS_VERSION'].replace('Exp','')) < 8.0: + libcptest = """ + #include + int main() { + // %s + std::ofstream header("test", std::ofstream::out); + return 0; + } + """ -conf.env.PrependENVPath('LIB', Dir('#/.sconf_temp').abspath) -conf.env.Append(CCFLAGS = ['$EXCEPTION_FLAG']) + conf.env.PrependENVPath('LIB', Dir('#/.sconf_temp').abspath) + conf.env.Append(CCFLAGS = ['$EXCEPTION_FLAG']) -if not conf.TryLink(libcptest % 'no change', '.cpp'): - import os, shutil + if not conf.TryLink(libcptest % 'no change', '.cpp'): + import os, shutil - libdirs = defenv['ENV']['LIB'].split(os.pathsep) + libdirs = defenv['ENV']['LIB'].split(os.pathsep) - for libdir in libdirs: - try: - libcp = r'%s\libcp.lib' % libdir - shutil.copy(libcp, Dir('#/.sconf_temp').abspath) - if conf.TryLink(libcptest % (r'using %s' % libcp), '.cpp'): - defenv.PrependENVPath('LIB', Dir('#/.sconf_temp').abspath) - break - except IOError: - continue - else: - print "*** Couldn't find a good version of libcp.lib" - Exit(2) + for libdir in libdirs: + try: + libcp = r'%s\libcp.lib' % libdir + shutil.copy(libcp, Dir('#/.sconf_temp').abspath) + if conf.TryLink(libcptest % (r'using %s' % libcp), '.cpp'): + defenv.PrependENVPath('LIB', Dir('#/.sconf_temp').abspath) + break + except IOError: + continue + else: + print "*** Couldn't find a good version of libcp.lib" + Exit(2) conf.Finish() + ### stub environment stub_env = defenv.Clone() @@ -88,7 +96,12 @@ if not defenv['DEBUG']: stub_env.Append(CCFLAGS = ['/W3']) # level 3 warnings stub_env.Append(LINKFLAGS = ['/opt:nowin98']) # 512 bytes align -stub_env.Append(LINKFLAGS = ['/entry:WinMain']) # entry point + +if defenv['UNICODE']: + stub_env.Append(LINKFLAGS = ['/entry:wWinMain']) # Unicode entry point +else: + stub_env.Append(LINKFLAGS = ['/entry:WinMain']) # ANSI entry point + stub_env.Append(LINKFLAGS = ['$NODEFLIBS_FLAG']) # no default libraries stub_env.Append(LINKFLAGS = ['$MAP_FLAG']) # generate map file stub_env.Append(CCFLAGS = ['/FAcs']) # full listing files @@ -104,6 +117,8 @@ if not defenv['DEBUG']: makensis_env.Append(CCFLAGS = ['/O2']) # optimize for speed makensis_env.Append(CCFLAGS = ['$EXCEPTION_FLAG']) # enable exceptions makensis_env.Append(CCFLAGS = ['/W3']) # level 3 warnings +makensis_env.Append(CCFLAGS = ['/FAcs']) # full listing files +makensis_env.Append(CCFLAGS = ['/Fa${TARGET}.lst']) # listing file name makensis_env.Append(LINKFLAGS = ['/opt:nowin98']) # 512 bytes align makensis_env.Append(LINKFLAGS = ['$MAP_FLAG']) # generate map file @@ -200,13 +215,22 @@ def add_file(file): conf = stub_env.Configure() -int64test = """ -#include -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow) { - ULARGE_INTEGER *i = 0; - return (int)(i->QuadPart >> 10); -} -""" +if defenv['UNICODE']: + int64test = """ + #include + int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPTSTR lpszCmdParam, int nCmdShow) { + ULARGE_INTEGER *i = 0; + return (int)(i->QuadPart >> 10); + } + """ +else: + int64test = """ + #include + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow) { + ULARGE_INTEGER *i = 0; + return (int)(i->QuadPart >> 10); + } + """ if not conf.TryLink(int64test, '.c'): stub_env.Append(CPPDEFINES = ['_NSIS_NO_INT64_SHR']) diff --git a/SCons/Tools/mstoolkit.py b/SCons/Tools/mstoolkit.py index c2c92766..1b7eaa5f 100644 --- a/SCons/Tools/mstoolkit.py +++ b/SCons/Tools/mstoolkit.py @@ -338,7 +338,7 @@ def generate(env): env['REGSVRFLAGS'] = '/s ' env['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS $TARGET' - env['MSVS_VERSION'] = '7.1' + env['MSVS_VERSION'] = '8.0' def exists(env): diff --git a/SCons/config.py b/SCons/config.py index a344456e..8dc7b333 100644 --- a/SCons/config.py +++ b/SCons/config.py @@ -7,7 +7,7 @@ cfg = Variables() cfg.Add( ( 'NSIS_MAX_STRLEN', - 'defines the maximum string length for internal variables and stack entries. 1024 should be plenty, but if you are doing crazy registry shit, you might want to bump it up. Generally it adds about 16-32x the memory, so setting this to 4096 from 1024 will add around 64k of memory usage (not really a big deal, but not usually needed).', + 'defines the maximum string length for internal variables and stack entries. 1024 should be plenty, but if you are doing crazy registry stuff, you might want to bump it up. Generally it adds about 16-32x the memory, so setting this to 4096 from 1024 will add around 64k of memory usage (not really a big deal, but not usually needed).', 1024 ) ) diff --git a/SConstruct b/SConstruct index 75622bce..7c8e6f0d 100644 --- a/SConstruct +++ b/SConstruct @@ -156,6 +156,7 @@ opts.Add(PathVariable('APPEND_LIBPATH', 'Additional paths to search for librarie opts.Add(('APPEND_CCFLAGS', 'Additional C/C++ compiler flags')) opts.Add(('APPEND_LINKFLAGS', 'Additional linker flags')) # build options +opts.Add(BoolVariable('UNICODE', 'Build the Unicode version of the executable', 'no')) opts.Add(BoolVariable('DEBUG', 'Build executables with debugging information', 'no')) opts.Add(PathVariable('CODESIGNER', 'A program used to sign executables', None)) opts.Add(BoolVariable('STRIP', 'Strips executables of any unrequired data such as symbols', 'yes')) @@ -179,10 +180,17 @@ if 'NSIS_CONFIG_CONST_DATA_PATH' in defenv['NSIS_CPPDEFINES']: defenv.Append(NSIS_CPPDEFINES = [('PREFIX_DATA', '"%s"' % defenv.subst('$PREFIX_DATA'))]) # Need this early for the config header files to be placed in -if defenv['DEBUG']: - defenv.Replace(BUILD_PREFIX = 'build/debug') + +if defenv['UNICODE']: + if defenv['DEBUG']: + defenv.Replace(BUILD_PREFIX = 'build/udebug') + else: + defenv.Replace(BUILD_PREFIX = 'build/urelease') else: - defenv.Replace(BUILD_PREFIX = 'build/release') + if defenv['DEBUG']: + defenv.Replace(BUILD_PREFIX = 'build/debug') + else: + defenv.Replace(BUILD_PREFIX = 'build/release') defenv.Replace(BUILD_CONFIG = defenv.subst('$BUILD_PREFIX/config')) @@ -200,19 +208,32 @@ for i in defenv['NSIS_CPPDEFINES']: if type(i) is not str: sconf_h.write('#define %s %s\n' % (i[0], i[1])) if str(i[1])[0] != '"': - defines_h.write('definedlist.add("%s", "%s");\n' % (i[0], i[1])) + defines_h.write('definedlist.add(_T("%s"), _T("%s"));\n' % (i[0], i[1])) else: - defines_h.write('definedlist.add("%s", %s);\n' % (i[0], i[1])) + defines_h.write('definedlist.add(_T("%s"), _T(%s));\n' % (i[0], i[1])) else: sconf_h.write('#define %s\n' % (i)) - defines_h.write('definedlist.add("%s");\n' % (i)) + defines_h.write('definedlist.add(_T("%s"));\n' % (i)) sconf_h.close() defines_h.close() # write version into version.h f = open(defenv.File('#$BUILD_CONFIG/nsis-version.h').abspath, 'w') f.write('// This file is automatically generated by SCons\n// DO NOT EDIT THIS FILE\n') -f.write('#define NSIS_VERSION "v%s"\n' % defenv['VERSION']) +f.write('#include "tchar.h"\n') + +if defenv.has_key('VER_MAJOR'): + defenv['VERSION'] = defenv['VER_MAJOR'] + if defenv.has_key('VER_MINOR'): + defenv['VERSION'] += '.' + defenv['VER_MINOR'] + if defenv.has_key('VER_REVISION'): + defenv['VERSION'] += '.' + defenv['VER_REVISION'] + +if defenv['UNICODE']: + defenv['VERSION'] += "-Unicode" + +f.write('#define NSIS_VERSION _T("v%s")\n' % defenv['VERSION']) + f.close() ###################################################################### @@ -401,7 +422,9 @@ defenv.Depends(installer_target, '$INSTDISTDIR') defenv.Sign(installer_target) defenv.Alias('dist-installer', installer_target) -AlwaysBuild(defenv.AddPostAction(installer_target, Delete('$INSTDISTDIR'))) +# Comment out the following if you want to see the installation directory +# after the build is finished. +#AlwaysBuild(defenv.AddPostAction(installer_target, Delete('$INSTDISTDIR'))) defenv.Alias('dist', ['dist-zip', 'dist-installer']) @@ -412,9 +435,15 @@ defenv.Alias('dist', ['dist-zip', 'dist-installer']) for d in doc: if d in defenv['SKIPDOC']: continue - defenv.DistributeDoc(d) + if defenv['UNICODE']: + defenv.DistributeDoc('Unicode/' + d) + else: + defenv.DistributeDoc(d) -defenv.DistributeConf('nsisconf.nsh') +if defenv['UNICODE']: + defenv.DistributeConf('Unicode/nsisconf.nsh') +else: + defenv.DistributeConf('nsisconf.nsh') ###################################################################### ####### Stubs ### diff --git a/Source/7zip/7zGuids.cpp b/Source/7zip/7zGuids.cpp index 1ca1ac12..08276c91 100644 --- a/Source/7zip/7zGuids.cpp +++ b/Source/7zip/7zGuids.cpp @@ -13,6 +13,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/24/2007 */ // DLLExports.cpp diff --git a/Source/7zip/Common/Alloc.cpp b/Source/7zip/Common/Alloc.cpp index 9ac1946b..2dd73bb1 100644 --- a/Source/7zip/Common/Alloc.cpp +++ b/Source/7zip/Common/Alloc.cpp @@ -13,6 +13,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/28/2007 */ #include "StdAfx.h" @@ -21,6 +23,7 @@ #include "MyWindows.h" #else #include +#include "../../tchar.h" #endif #include "Alloc.h" @@ -39,7 +42,7 @@ void *MyAlloc(size_t size) throw() if (size == 0) return 0; #ifdef _SZ_ALLOC_DEBUG - fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount++); + _ftprintf(stderr, _T("\nAlloc %10d bytes; count = %10d"), size, g_allocCount++); #endif return ::malloc(size); } @@ -48,7 +51,7 @@ void MyFree(void *address) throw() { #ifdef _SZ_ALLOC_DEBUG if (address != 0) - fprintf(stderr, "\nFree; count = %10d", --g_allocCount); + _ftprintf(stderr, _T("\nFree; count = %10d"), --g_allocCount); #endif ::free(address); @@ -61,7 +64,7 @@ void *MidAlloc(size_t size) throw() if (size == 0) return 0; #ifdef _SZ_ALLOC_DEBUG - fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++); + _ftprintf(stderr, _T("\nAlloc_Mid %10d bytes; count = %10d"), size, g_allocCountMid++); #endif return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); } @@ -70,7 +73,7 @@ void MidFree(void *address) throw() { #ifdef _SZ_ALLOC_DEBUG if (address != 0) - fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid); + _ftprintf(stderr, _T("\nFree_Mid; count = %10d"), --g_allocCountMid); #endif if (address == 0) return; @@ -89,7 +92,7 @@ typedef SIZE_T (WINAPI *GetLargePageMinimumP)(); bool SetLargePageSize() { GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP) - ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum"); + ::GetProcAddress(::GetModuleHandle(_T("kernel32.dll")), "GetLargePageMinimum"); if (largePageMinimum == 0) return false; SIZE_T size = largePageMinimum(); @@ -105,7 +108,7 @@ void *BigAlloc(size_t size) throw() if (size == 0) return 0; #ifdef _SZ_ALLOC_DEBUG - fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++); + _ftprintf(stderr, _T("\nAlloc_Big %10d bytes; count = %10d"), size, g_allocCountBig++); #endif if (size >= (1 << 18)) @@ -122,7 +125,7 @@ void BigFree(void *address) throw() { #ifdef _SZ_ALLOC_DEBUG if (address != 0) - fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig); + _ftprintf(stderr, _T("\nFree_Big; count = %10d"), --g_allocCountBig); #endif if (address == 0) diff --git a/Source/7zip/Common/Alloc.h b/Source/7zip/Common/Alloc.h index 5916ef06..aaa2749e 100644 --- a/Source/7zip/Common/Alloc.h +++ b/Source/7zip/Common/Alloc.h @@ -13,6 +13,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/28/2007 */ #ifndef __COMMON_ALLOC_H diff --git a/Source/7zip/Common/CRC.cpp b/Source/7zip/Common/CRC.cpp index dad64326..4a2d1a2f 100644 --- a/Source/7zip/Common/CRC.cpp +++ b/Source/7zip/Common/CRC.cpp @@ -13,6 +13,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/28/2007 */ #include "StdAfx.h" diff --git a/Source/7zip/Common/CRC.h b/Source/7zip/Common/CRC.h index 72cb518f..b1fc6b87 100644 --- a/Source/7zip/Common/CRC.h +++ b/Source/7zip/Common/CRC.h @@ -13,6 +13,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/28/2007 */ #ifndef __COMMON_CRC_H diff --git a/Source/7zip/LZMADecode.c b/Source/7zip/LZMADecode.c index 0635b013..0522bfef 100644 --- a/Source/7zip/LZMADecode.c +++ b/Source/7zip/LZMADecode.c @@ -13,6 +13,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/24/2007 */ #include diff --git a/Source/7zip/LZMADecode.h b/Source/7zip/LZMADecode.h index 68c78655..e6aec0c1 100644 --- a/Source/7zip/LZMADecode.h +++ b/Source/7zip/LZMADecode.h @@ -13,6 +13,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/24/2007 */ #ifndef __LZMADECODE_H diff --git a/Source/DialogTemplate.cpp b/Source/DialogTemplate.cpp index 109a1d79..e0d336fc 100644 --- a/Source/DialogTemplate.cpp +++ b/Source/DialogTemplate.cpp @@ -280,8 +280,8 @@ int CDialogTemplate::RemoveItem(WORD wId) { } // Sets the font of the dialog -void CDialogTemplate::SetFont(char* szFaceName, WORD wFontSize) { - if (strcmp(szFaceName, "MS Shell Dlg")) { +void CDialogTemplate::SetFont(TCHAR* szFaceName, WORD wFontSize) { + if (_tcscmp(szFaceName, _T("MS Shell Dlg"))) { // not MS Shell Dlg m_dwStyle &= ~DS_SHELLFONT; } @@ -364,7 +364,7 @@ void CDialogTemplate::DlgUnitsToPixels(short& x, short& y) { } // Returns the size of a string in the dialog (in dialog units) -SIZE CDialogTemplate::GetStringSize(WORD id, char *str) { +SIZE CDialogTemplate::GetStringSize(WORD id, TCHAR *str) { HWND hDlg = CreateDummyDialog(); LOGFONT f; @@ -375,7 +375,7 @@ SIZE CDialogTemplate::GetStringSize(WORD id, char *str) { SelectObject(memDC, font); SIZE size; - GetTextExtentPoint32(memDC, str, strlen(str), &size); + GetTextExtentPoint32(memDC, str, _tcsclen(str), &size); DestroyWindow(hDlg); DeleteObject(font); @@ -387,7 +387,7 @@ SIZE CDialogTemplate::GetStringSize(WORD id, char *str) { } // Trims the right margins of a control to fit a given text string size. -void CDialogTemplate::RTrimToString(WORD id, char *str, int margins) { +void CDialogTemplate::RTrimToString(WORD id, TCHAR *str, int margins) { DialogItemTemplate* item = GetItem(id); if (!item) return; @@ -401,7 +401,7 @@ void CDialogTemplate::RTrimToString(WORD id, char *str, int margins) { } // Trims the left margins of a control to fit a given text string size. -void CDialogTemplate::LTrimToString(WORD id, char *str, int margins) { +void CDialogTemplate::LTrimToString(WORD id, TCHAR *str, int margins) { DialogItemTemplate* item = GetItem(id); if (!item) return; @@ -416,7 +416,7 @@ void CDialogTemplate::LTrimToString(WORD id, char *str, int margins) { } // Trims the left and right margins of a control to fit a given text string size. -void CDialogTemplate::CTrimToString(WORD id, char *str, int margins) { +void CDialogTemplate::CTrimToString(WORD id, TCHAR *str, int margins) { DialogItemTemplate* item = GetItem(id); if (!item) return; diff --git a/Source/DialogTemplate.h b/Source/DialogTemplate.h index 918ca23c..00c072ea 100644 --- a/Source/DialogTemplate.h +++ b/Source/DialogTemplate.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/21/2007 */ #if !defined(AFX_DIALOGTEMPLATE_H__C5A973AF_0F56_4BEC_814A_79318E2EB4AC__INCLUDED_) @@ -113,7 +115,7 @@ public: DialogItemTemplate* GetItem(WORD wId); DialogItemTemplate* GetItemByIdx(DWORD i); int RemoveItem(WORD wId); - void SetFont(char* szFaceName, WORD wFontSize); + void SetFont(TCHAR* szFaceName, WORD wFontSize); void AddItem(DialogItemTemplate item); #ifdef _WIN32 HWND CreateDummyDialog(); @@ -123,10 +125,10 @@ public: #ifdef _WIN32 void PixelsToDlgUnits(short& x, short& y); void DlgUnitsToPixels(short& x, short& y); - SIZE GetStringSize(WORD id, char *str); - void RTrimToString(WORD id, char *str, int margins); - void LTrimToString(WORD id, char *str, int margins); - void CTrimToString(WORD id, char *str, int margins); + SIZE GetStringSize(WORD id, TCHAR *str); + void RTrimToString(WORD id, TCHAR *str, int margins); + void LTrimToString(WORD id, TCHAR *str, int margins); + void CTrimToString(WORD id, TCHAR *str, int margins); #endif void ConvertToRTL(); BYTE* Save(DWORD& dwSize); diff --git a/Source/Platform.h b/Source/Platform.h index 52eb9bcb..b4aaf2cb 100644 --- a/Source/Platform.h +++ b/Source/Platform.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ #ifndef ___PLATFORM__H___ @@ -22,9 +24,10 @@ // includes #ifdef _WIN32 -# include -# include -# include +#include +#include +#include +#include "tchar.h" #else # ifndef EXEHEAD # include @@ -109,22 +112,22 @@ typedef DWORDLONG ULONGLONG,*PULONGLONG; // script path separator -# define PATH_SEPARATOR_STR "\\" -# define PATH_SEPARATOR_C '\\' +# define PATH_SEPARATOR_STR _T("\\") +# define PATH_SEPARATOR_C _T('\\') // system specific characters #ifdef _WIN32 -# define PLATFORM_PATH_SEPARATOR_STR "\\" -# define PLATFORM_PATH_SEPARATOR_C '\\' -# define OPT_STR "/" -# define OPT_C '/' -# define IS_OPT(a) (a[0]==OPT_C||a[0]=='-') +# define PLATFORM_PATH_SEPARATOR_STR _T("\\") +# define PLATFORM_PATH_SEPARATOR_C _T('\\') +# define OPT_STR _T("/") +# define OPT_C _T('/') +# define IS_OPT(a) (a[0]==OPT_C||a[0]==_T('-')) #else -# define PLATFORM_PATH_SEPARATOR_STR "/" -# define PLATFORM_PATH_SEPARATOR_C '/' -# define OPT_STR "-" -# define OPT_C '-' +# define PLATFORM_PATH_SEPARATOR_STR _T("/") +# define PLATFORM_PATH_SEPARATOR_C _T('/') +# define OPT_STR _T("-") +# define OPT_C _T('-') # define IS_OPT(a) (a[0]==OPT_C) #endif @@ -183,6 +186,8 @@ typedef DWORDLONG ULONGLONG,*PULONGLONG; // functions +// Jim Park: These str functions will probably never be encountered with all my +// Unicode changes. And if they were used, these would probably be wrong. #ifndef _WIN32 # define stricmp strcasecmp # define strcmpi strcasecmp @@ -227,10 +232,10 @@ typedef DWORDLONG ULONGLONG,*PULONGLONG; #ifndef EXEHEAD # ifndef SF_TEXT -# define SF_TEXT 1 +# define SF_TEXT 0x0001 # endif # ifndef SF_RTF -# define SF_RTF 2 +# define SF_RTF 0x0002 # endif #endif @@ -683,7 +688,7 @@ typedef struct _LOGFONT { BYTE lfClipPrecision; BYTE lfQuality; BYTE lfPitchAndFamily; - CHAR lfFaceName[LF_FACESIZE]; + TCHAR lfFaceName[LF_FACESIZE]; } LOGFONT; # pragma pack(2) typedef struct _IMAGE_DOS_HEADER { diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index 6872b281..2fdc5239 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -18,7 +18,7 @@ #ifdef NSIS_CONFIG_PLUGIN_SUPPORT #include -#include +#include "tstring.h" #include #include "Plugins.h" @@ -40,7 +40,7 @@ using namespace std; extern FILE *g_output; -void Plugins::FindCommands(const string &path, bool displayInfo) +void Plugins::FindCommands(const tstring &path, bool displayInfo) { boost::scoped_ptr dr( new_dir_reader() ); dr->read(path); @@ -49,10 +49,10 @@ void Plugins::FindCommands(const string &path, bool displayInfo) files_itr != dr->files().end(); files_itr++) { - if (!dir_reader::matches(*files_itr, "*.dll")) + if (!dir_reader::matches(*files_itr, _T("*.dll"))) continue; - const string plugin = path + PLATFORM_PATH_SEPARATOR_C + *files_itr; + const tstring plugin = path + PLATFORM_PATH_SEPARATOR_C + *files_itr; GetExports(plugin, displayInfo); } } @@ -89,7 +89,7 @@ vector read_file(const string& filename) { vector result; result.resize(filesize); - file.read(reinterpret_cast(&result[0]), filesize); + file.read(reinterpret_cast(&result[0]), filesize); if (size_t(file.tellg()) != filesize) { // ifstream::eof doesn't return true here throw NSISException("Couldn't read entire file '" + filename + "'"); @@ -99,7 +99,7 @@ vector read_file(const string& filename) { } } -void Plugins::GetExports(const string &pathToDll, bool displayInfo) +void Plugins::GetExports(const tstring &pathToDll, bool displayInfo) { vector dlldata; PIMAGE_NT_HEADERS NTHeaders; @@ -110,7 +110,7 @@ void Plugins::GetExports(const string &pathToDll, bool displayInfo) return; } - const string dllName = remove_file_extension(get_file_name(pathToDll)); + const tstring dllName = remove_file_extension(get_file_name(pathToDll)); FIX_ENDIAN_INT16_INPLACE(NTHeaders->FileHeader.Characteristics); if (NTHeaders->FileHeader.Characteristics & IMAGE_FILE_DLL) @@ -140,12 +140,12 @@ void Plugins::GetExports(const string &pathToDll, bool displayInfo) for (unsigned long j = 0; j < FIX_ENDIAN_INT32(exports->NumberOfNames); j++) { const string name = string((char*)exports + FIX_ENDIAN_INT32(names[j]) - ExportDirVA); - const string signature = dllName + "::" + name; - const string lcsig = lowercase(signature); + const tstring signature = dllName + _T("::") + name; + const tstring lcsig = lowercase(signature); m_command_to_path[lcsig] = pathToDll; m_command_lowercase_to_command[lcsig] = signature; if (displayInfo) - fprintf(g_output, " - %s\n", signature.c_str()); + _ftprintf(g_output, _T(" - %s\n"), signature.c_str()); } break; } @@ -153,7 +153,7 @@ void Plugins::GetExports(const string &pathToDll, bool displayInfo) } } -bool Plugins::IsPluginCommand(const string& token) const { +bool Plugins::IsPluginCommand(const tstring& token) const { return m_command_to_path.find(lowercase(token)) != m_command_to_path.end(); } @@ -177,11 +177,11 @@ Value get_value(const map& the_map, } } -string Plugins::NormalizedCommand(const string& command) const { +tstring Plugins::NormalizedCommand(const tstring& command) const { return get_value(m_command_lowercase_to_command, lowercase(command)); } -int Plugins::GetPluginHandle(bool uninst, const string& command) const { +int Plugins::GetPluginHandle(bool uninst, const tstring& command) const { if (uninst) { return get_value(m_command_to_uninstall_data_handle, command, -1); } @@ -190,11 +190,11 @@ int Plugins::GetPluginHandle(bool uninst, const string& command) const { } } -string Plugins::GetPluginPath(const string& command) const { +tstring Plugins::GetPluginPath(const tstring& command) const { return get_value(m_command_to_path, lowercase(command)); } -void Plugins::SetDllDataHandle(bool uninst, const string& command, int dataHandle) +void Plugins::SetDllDataHandle(bool uninst, const tstring& command, int dataHandle) { if (uninst) { m_command_to_uninstall_data_handle[command] = dataHandle; diff --git a/Source/Plugins.h b/Source/Plugins.h index d15d7cf6..ba623e1d 100644 --- a/Source/Plugins.h +++ b/Source/Plugins.h @@ -12,32 +12,34 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/21/2007 */ #ifndef __X18_PLUGINS_H #define __X18_PLUGINS_H #include -#include +#include "tstring.h" class Plugins { public: - void FindCommands(const std::string& path, bool displayInfo); - bool IsPluginCommand(const std::string& command) const; - std::string NormalizedCommand(const std::string& command) const; - int GetPluginHandle(bool uninst, const std::string& command) const; - std::string GetPluginPath(const std::string& command) const; - void SetDllDataHandle(bool uninst, const std::string& command, int dataHandle); + void FindCommands(const tstring& path, bool displayInfo); + bool IsPluginCommand(const tstring& command) const; + tstring NormalizedCommand(const tstring& command) const; + int GetPluginHandle(bool uninst, const tstring& command) const; + tstring GetPluginPath(const tstring& command) const; + void SetDllDataHandle(bool uninst, const tstring& command, int dataHandle); private: // methods - void GetExports(const std::string &pathToDll, bool displayInfo); + void GetExports(const tstring &pathToDll, bool displayInfo); private: // data members - std::map m_command_lowercase_to_command; - std::map m_command_to_path; - std::map m_command_to_data_handle; - std::map m_command_to_uninstall_data_handle; + std::map m_command_lowercase_to_command; + std::map m_command_to_path; + std::map m_command_to_data_handle; + std::map m_command_to_uninstall_data_handle; }; #endif diff --git a/Source/ResourceEditor.cpp b/Source/ResourceEditor.cpp index 85094142..f4bf691a 100644 --- a/Source/ResourceEditor.cpp +++ b/Source/ResourceEditor.cpp @@ -12,12 +12,15 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/21/2007 */ #include "ResourceEditor.h" #include "util.h" #include "winchar.h" #include +#include "tchar.h" using namespace std; ////////////////////////////////////////////////////////////////////// @@ -541,6 +544,7 @@ DWORD CResourceEditor::Save(BYTE* pbBuf, DWORD &dwSize) { // This function scans exe sections and after find a match with given name // increments it's virtual size (auto fixes image size based on section alignment, etc) +// Jim Park: The section name must be ASCII code. Do not TCHAR this stuff. bool CResourceEditor::AddExtraVirtualSize2PESection(const char* pszSectionName, int addsize) { PIMAGE_SECTION_HEADER sectionHeadersArray = IMAGE_FIRST_SECTION(m_ntHeaders); @@ -889,7 +893,7 @@ int CResourceDirectory::Find(WCHAR* szName) { if (IS_INTRESOURCE(szName)) return Find((WORD) (DWORD) szName); else - if (szName[0] == '#') + if (szName[0] == L'#') return Find(WORD(winchar_stoi(szName + 1))); for (unsigned int i = 0; i < m_vEntries.size(); i++) { diff --git a/Source/ResourceEditor.h b/Source/ResourceEditor.h index 59def2eb..a50ea519 100644 --- a/Source/ResourceEditor.h +++ b/Source/ResourceEditor.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/21/2007 */ #if !defined(AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_) @@ -27,7 +29,7 @@ #include "Platform.h" #ifdef _WIN32 -# include +#include #else // all definitions for non Win32 platforms were taken from MinGW's free Win32 library # define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 @@ -127,6 +129,7 @@ public: DWORD GetResourceOffsetA(char* szType, char* szName, LANGID wLanguage); void FreeResource(BYTE* pbResource); + // The section name must be in ASCII. bool AddExtraVirtualSize2PESection(const char* pszSectionName, int addsize); DWORD Save(BYTE* pbBuf, DWORD &dwSize); diff --git a/Source/ResourceVersionInfo.cpp b/Source/ResourceVersionInfo.cpp index 71df19ef..73d290ba 100644 --- a/Source/ResourceVersionInfo.cpp +++ b/Source/ResourceVersionInfo.cpp @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Modified for Unicode support by Jim Park -- 08/21/2007 */ #include "ResourceVersionInfo.h" @@ -54,8 +56,8 @@ CVersionStrigList::~CVersionStrigList() int CVersionStrigList::add(LANGID langid, int codepage) { - char Buff[10]; - sprintf(Buff, "%04x", langid); + TCHAR Buff[10]; + sprintf(Buff, _T("%04x"), langid); int pos = SortedStringListND::add(Buff); if (pos == -1) return false; ((struct version_string_list*)gr.get())[pos].pChildStrings = new DefineList; @@ -84,8 +86,8 @@ DefineList* CVersionStrigList::get_strings(int idx) int CVersionStrigList::find(LANGID lang_id, int codepage) { - char Buff[10]; - sprintf(Buff, "%04x", lang_id); + TCHAR Buff[10]; + sprintf(Buff, _T("%04x"), lang_id); return SortedStringListND::find(Buff); } @@ -132,6 +134,7 @@ void CResourceVersionInfo::SetProductVersion(int HighPart, int LowPart) m_FixedInfo.dwProductVersionMS = HighPart; } +// Jim Park: Not sure where this is used. int GetVersionHeader (LPSTR &p, WORD &wLength, WORD &wValueLength, WORD &wType) { WCHAR *szKey; @@ -159,6 +162,14 @@ void PadStream (GrowBuf &strm) strm.add (&ZEROS, 4 - (strm.getlen() % 4)); } +// Helper function only used by CResourceVersionInfo::ExportToStream +// Cannot handle anything longer than 65K objects. +// +// @param wLength Size in bytes of the entire object we are storing. +// @param wValueLength The value length in bytes. +// @param wType If type is 1, it's a wchar_t string, so save value length appropriately. +// @param key The string key +// @param value The value mapped to string key. void SaveVersionHeader (GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wType, const WCHAR *key, void *value) { WORD valueLen; @@ -190,7 +201,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) WCHAR *KeyName, *KeyValue; strm.resize(0); - KeyName = winchar_fromansi("VS_VERSION_INFO"); + KeyName = winchar_fromansi(_T("VS_VERSION_INFO")); SaveVersionHeader (strm, 0, sizeof (VS_FIXEDFILEINFO), 0, KeyName, &m_FixedInfo); delete [] KeyName; @@ -200,8 +211,8 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) GrowBuf stringInfoStream; int codepage = m_ChildStringLists.get_codepage(Index); LANGID langid = m_ChildStringLists.get_lang(Index); - char Buff[16]; - sprintf(Buff, "%04x%04x", langid, codepage); + TCHAR Buff[16]; + sprintf(Buff, _T("%04x%04x"), langid, codepage); KeyName = winchar_fromansi(Buff, CP_ACP); SaveVersionHeader (stringInfoStream, 0, 0, 0, KeyName, &ZEROS); delete [] KeyName; @@ -226,7 +237,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) PadStream (strm); p = strm.getlen(); - KeyName = winchar_fromansi("StringFileInfo", CP_ACP); + KeyName = winchar_fromansi(_T("StringFileInfo"), CP_ACP); SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS); delete [] KeyName; strm.add (stringInfoStream.get(), stringInfoStream.getlen()); @@ -240,13 +251,13 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) { PadStream (strm); p = strm.getlen(); - KeyName = winchar_fromansi("VarFileInfo", CP_ACP); + KeyName = winchar_fromansi(_T("VarFileInfo"), CP_ACP); SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS); delete [] KeyName; PadStream (strm); p1 = strm.getlen(); - KeyName = winchar_fromansi("Translation", CP_ACP); + KeyName = winchar_fromansi(_T("Translation"), CP_ACP); SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS); delete [] KeyName; @@ -278,7 +289,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) } // Returns 0 if success, 1 if already defined -int CResourceVersionInfo::SetKeyValue(LANGID lang_id, int codepage, char* AKeyName, char* AValue) +int CResourceVersionInfo::SetKeyValue(LANGID lang_id, int codepage, TCHAR* AKeyName, TCHAR* AValue) { int pos = m_ChildStringLists.find(lang_id, codepage); if ( pos == -1 ) @@ -304,7 +315,7 @@ int CResourceVersionInfo::GetCodePage(int Index) return m_ChildStringLists.get_codepage(Index); } -char *CResourceVersionInfo::FindKey(LANGID LangID, int codepage, const char *pKeyName) +TCHAR *CResourceVersionInfo::FindKey(LANGID LangID, int codepage, const TCHAR *pKeyName) { int pos = m_ChildStringLists.find(LangID, codepage); if ( pos == -1 ) diff --git a/Source/ResourceVersionInfo.h b/Source/ResourceVersionInfo.h index 5d799393..6937ec7a 100644 --- a/Source/ResourceVersionInfo.h +++ b/Source/ResourceVersionInfo.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support and Doxygen comments by Jim Park -- 07/26/2007 */ #if !defined(AFX_RESOURCEVERSIONINFO_H__80439ADA_49DA_4623_8DA9_1663FF356E76__INCLUDED_) @@ -33,12 +35,46 @@ class CVersionStrigList : public SortedStringListND { public: ~CVersionStrigList(); + + /** + * Add a version_string_list struct referred to by langid. Then add the + * codepage value to the structure. + * + * @param langid The language ID (LANGID) + * @param codepage The code page value to set. + * @return The position to the inserted structure, false (0) if failed. + */ int add(LANGID langid, int codepage); + + /** + * Get the language ID given the positional index idx. + */ LANGID get_lang(int idx); + + /** + * Get the codepage value given the positional index idx. + */ int get_codepage(int idx); + + /** + * Get the string pair mappings given the positional index idx. + */ DefineList* get_strings(int idx); + + /** + * Given a language ID return the positional index that holds the + * version_string_list struct. Actually, the codepage value is ignored. + */ int find(LANGID lang_id, int codepage); + + /** + * Get the length of the buffer of strings in count of TCHARs. + */ int getlen(); + + /** + * Get the number of version_string_list objects stored in this list. + */ int getnum(); }; @@ -51,15 +87,58 @@ class CResourceVersionInfo public: CResourceVersionInfo(); virtual ~CResourceVersionInfo(); - int SetKeyValue(LANGID lang_id, int codepage, char* AKeyName, char* AValue); + int SetKeyValue(LANGID lang_id, int codepage, TCHAR* AKeyName, TCHAR* AValue); + + /** + * Sets the file flags into the VS_FIXEDFILEINFO structure for this object. + * Only what's set as valid in the dwFileFlagsMask is allowed to be set. + * Currently, this API is never used and unless dwFileFlagsMask is set, + * should never be used. + */ void SetFileFlags(int Value); + + /** + * Set the file version. + */ void SetFileVersion(int HighPart, int LowPart); + + /** + * Set the product version. + */ void SetProductVersion(int HighPart, int LowPart); + + /** + * Write the data out to the flat buffer 'strm'. Not sure where and how + * it gets read back in though. + */ void ExportToStream(GrowBuf &strm, int Index); + + /** + * How many string tables are we storing in the m_ChildStringLists? + */ int GetStringTablesCount(); + + /** + * Given a positional index, get the Language ID associated with it. + */ LANGID GetLangID(int Index); + + /** + * Given a positional index, get the CodePage associated with it. + */ int GetCodePage(int Index); - char *FindKey(LANGID LangID, int codepage, const char *pKeyName); + + /** + * Given the language ID, codepage, and the 'keyname', return the + * TCHAR* pointer to the value portion of the key-value pair. + * + * @param LangID The language ID. + * @param codepage The codepage. (Not used.) + * @param pKeyName The key name in the key-value pair of strings. + * @return The value string associated with the key string. NULL + * if not found. + */ + TCHAR *FindKey(LANGID LangID, int codepage, const TCHAR *pKeyName); }; #endif diff --git a/Source/ShConstants.cpp b/Source/ShConstants.cpp index a1a79979..edb78fe5 100644 --- a/Source/ShConstants.cpp +++ b/Source/ShConstants.cpp @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/24/2007 */ #include "ShConstants.h" @@ -21,7 +23,7 @@ ConstantsStringList::ConstantsStringList() index = 0; } -int ConstantsStringList::add(const char *name, int value1, int value2) +int ConstantsStringList::add(const TCHAR *name, int value1, int value2) { int pos=SortedStringListND::add(name); if (pos == -1) return -1; @@ -37,7 +39,7 @@ int ConstantsStringList::add(const char *name, int value1, int value2) return temp; } -int ConstantsStringList::get(char *name, int n_chars /*= -1*/) +int ConstantsStringList::get(TCHAR *name, int n_chars /*= -1*/) { int v=SortedStringListND::find(name, n_chars); if (v==-1) return -1; @@ -63,12 +65,12 @@ int ConstantsStringList::get_value2(int idx) return (((struct constantstring*)gr.get())[pos].value2); } -char* ConstantsStringList::idx2name(int idx) +TCHAR* ConstantsStringList::idx2name(int idx) { int pos=get_internal_idx(idx); if (pos==-1) return NULL; struct constantstring *data=(struct constantstring *)gr.get(); - return ((char*)strings.get() + data[pos].name); + return ((TCHAR*)strings.get() + data[pos].name); } int ConstantsStringList::get_internal_idx(int idx) diff --git a/Source/ShConstants.h b/Source/ShConstants.h index 2b2f2f38..f1c93549 100644 --- a/Source/ShConstants.h +++ b/Source/ShConstants.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/24/2007 */ #ifndef ___CONSTANTS___H_____ @@ -32,12 +34,12 @@ class ConstantsStringList : public SortedStringListND public: ConstantsStringList(); - int add(const char *name, int value1, int value2); - int get(char *name, int n_chars = -1); + int add(const TCHAR *name, int value1, int value2); + int get(TCHAR *name, int n_chars = -1); int getnum(); int get_value1(int idx); int get_value2(int idx); - char *idx2name(int idx); + TCHAR *idx2name(int idx); private: int index; diff --git a/Source/Tests/SConscript b/Source/Tests/SConscript index 724787a2..3bd5e8a5 100644 --- a/Source/Tests/SConscript +++ b/Source/Tests/SConscript @@ -84,11 +84,15 @@ scripts = Split(""" icon1.nsi icon2.nsi preprocessor.nsi - winver.nsi """) Import('env AddAvailableLibs') +if env['UNICODE']: + scripts.append('Unicode/winver.nsi') +else: + scripts.append('ANSI/winver.nsi') + # Test scripts env.TestScript(scripts) diff --git a/Source/Tests/memcpy.c b/Source/Tests/memcpy.c index 0c590e8a..69012137 100644 --- a/Source/Tests/memcpy.c +++ b/Source/Tests/memcpy.c @@ -1,3 +1,5 @@ +// Reviewed for Unicode support by Jim Park -- 08/24/2007 + #include "../Platform.h" void NSISCALL mini_memcpy(void *out, const void *in, int len) diff --git a/Source/Tests/mmap.cpp b/Source/Tests/mmap.cpp index c2d267b4..8e04b5e2 100644 --- a/Source/Tests/mmap.cpp +++ b/Source/Tests/mmap.cpp @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 08/13/2007 +// #include #include "../mmap.h" @@ -11,7 +13,7 @@ int g_display_errors = 1; FILE *g_output = stderr; void quit() { - fprintf(g_output, "MMap quit\n"); + _ftprintf(g_output, _T("MMap quit\n")); } class MMapTest : public CppUnit::TestFixture { diff --git a/Source/Tests/specmatch.cpp b/Source/Tests/specmatch.cpp index 56a79c7e..facdc2ac 100644 --- a/Source/Tests/specmatch.cpp +++ b/Source/Tests/specmatch.cpp @@ -1,7 +1,7 @@ #include #include "../dirreader.h" -#include +#include "tstring.h" using namespace std; @@ -13,30 +13,30 @@ class SpecTest : public CppUnit::TestFixture { public: void testMatches() { - testMatch("test.exe", "test.exe", true); - testMatch("test", "test", true); - testMatch("test.exe", "test.*", true); - testMatch("test", "test.*", true); - testMatch("test", "????", true); - testMatch("test", "???", false); - testMatch("test", "*.exe", false); - testMatch("test.exe.bat", "*.exe", false); - testMatch("test.exe.bat", "*.bat", true); - testMatch("test.exe.bat", "*t", true); - testMatch("test.exe.bat", "*", true); - testMatch("test.exe.bat", "*x*", true); - testMatch("test.exe.exe", "*.*", true); - testMatch("test.exe.bat", "*.b*", true); - testMatch("test.exe.bat", "tes?.*.bat", true); - testMatch("test.exe.bat", "tes?.*bat", true); - testMatch("test.exe.bat", "tes?.*bat***.", true); - testMatch("test.exe", "????.*", true); - testMatch("testing.exe", "????.*", false); + testMatch(TEXT("test.exe"), TEXT("test.exe"), true); + testMatch(TEXT("test"), TEXT("test"), true); + testMatch(TEXT("test.exe"), TEXT("test.*"), true); + testMatch(TEXT("test"), TEXT("test.*"), true); + testMatch(TEXT("test"), TEXT("????"), true); + testMatch(TEXT("test"), TEXT("???"), false); + testMatch(TEXT("test"), TEXT("*.exe"), false); + testMatch(TEXT("test.exe.bat"), TEXT("*.exe"), false); + testMatch(TEXT("test.exe.bat"), TEXT("*.bat"), true); + testMatch(TEXT("test.exe.bat"), TEXT("*t"), true); + testMatch(TEXT("test.exe.bat"), TEXT("*"), true); + testMatch(TEXT("test.exe.bat"), TEXT("*x*"), true); + testMatch(TEXT("test.exe.exe"), TEXT("*.*"), true); + testMatch(TEXT("test.exe.bat"), TEXT("*.b*"), true); + testMatch(TEXT("test.exe.bat"), TEXT("tes?.*.bat"), true); + testMatch(TEXT("test.exe.bat"), TEXT("tes?.*bat"), true); + testMatch(TEXT("test.exe.bat"), TEXT("tes?.*bat***."), true); + testMatch(TEXT("test.exe"), TEXT("????.*"), true); + testMatch(TEXT("testing.exe"), TEXT("????.*"), false); } private: - void testMatch(string name, string spec, bool result) { + void testMatch(tstring name, tstring spec, bool result) { CPPUNIT_ASSERT_EQUAL( dir_reader::matches(name, spec), result ); } diff --git a/Source/Tests/winchar.cpp b/Source/Tests/winchar.cpp index a7df1e49..1ba44c70 100644 --- a/Source/Tests/winchar.cpp +++ b/Source/Tests/winchar.cpp @@ -1,3 +1,4 @@ +// Reviewed for Unicode support by Jim Park -- 08/13/2007 #include #include "../winchar.h" diff --git a/Source/build.cpp b/Source/build.cpp index a91c4cb0..15e33249 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -3,7 +3,7 @@ * * This file is a part of NSIS. * - * Copyright (C) 1999-2008 Nullsoft and Contributors + * Copyright (C) 1999-2009 Nullsoft and Contributors * * Licensed under the zlib/libpng license (the "License"); * you may not use this file except in compliance with the License. @@ -12,8 +12,11 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support added by Jim Park -- 08/07/2007 */ +#include "tchar.h" #include "Platform.h" #include #include "exehead/config.h" @@ -36,6 +39,7 @@ #include "ResourceEditor.h" #include "DialogTemplate.h" #include "ResourceVersionInfo.h" +#include "tstring.h" #ifndef _WIN32 # include @@ -57,14 +61,14 @@ using namespace std; namespace { // begin anonymous namespace -bool isSimpleChar(char ch) +bool isSimpleChar(TCHAR ch) { - return (ch == '.' ) || (ch == '_' ) || (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); + return (ch == _T('.') ) || (ch == _T('_') ) || (ch >= _T('0') && ch <= _T('9')) || (ch >= _T('A') && ch <= _T('Z')) || (ch >= _T('a') && ch <= _T('z')); } } // end of anonymous namespace -void CEXEBuild::define(const char *p, const char *v) +void CEXEBuild::define(const TCHAR *p, const TCHAR *v) { definedlist.add(p,v); } @@ -106,21 +110,21 @@ CEXEBuild::CEXEBuild() : has_called_write_output=false; - ns_func.add("",0); // make sure offset 0 is special on these (i.e. never used by a label) - ns_label.add("",0); + ns_func.add(_T(""),0); // make sure offset 0 is special on these (i.e. never used by a label) + ns_label.add(_T(""),0); - definedlist.add("NSIS_VERSION", NSIS_VERSION); + definedlist.add(_T("NSIS_VERSION"), NSIS_VERSION); // automatically generated header file containing all defines #include // no longer optional - definedlist.add("NSIS_SUPPORT_STANDARD_PREDEFINES"); - definedlist.add("NSIS_SUPPORT_NAMED_USERVARS"); - definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS"); + definedlist.add(_T("NSIS_SUPPORT_STANDARD_PREDEFINES")); + definedlist.add(_T("NSIS_SUPPORT_NAMED_USERVARS")); + definedlist.add(_T("NSIS_SUPPORT_LANG_IN_STRINGS")); #ifdef _WIN32 - definedlist.add("NSIS_WIN32_MAKENSIS"); + definedlist.add(_T("NSIS_WIN32_MAKENSIS")); #endif db_opt_save=db_comp_save=db_full_size=db_opt_save_u=db_comp_save_u=db_full_size_u=0; @@ -218,8 +222,8 @@ CEXEBuild::CEXEBuild() : uninstaller_writes_used=0; - build_strlist.add("",0); - ubuild_strlist.add("",0); + build_strlist.add(_T(""),0); + ubuild_strlist.add(_T(""),0); build_langstring_num=0; ubuild_langstring_num=0; @@ -268,7 +272,7 @@ CEXEBuild::CEXEBuild() : bg_default_font.lfClipPrecision=CLIP_DEFAULT_PRECIS; bg_default_font.lfQuality=DEFAULT_QUALITY; bg_default_font.lfPitchAndFamily=DEFAULT_PITCH; - strncpy(bg_default_font.lfFaceName,"Times New Roman",LF_FACESIZE); + _tcsnccpy(bg_default_font.lfFaceName,_T("Times New Roman"),LF_FACESIZE); memcpy(&bg_font,&bg_default_font,sizeof(LOGFONT)); #endif @@ -279,117 +283,117 @@ CEXEBuild::CEXEBuild() : // Register static user variables $0, $1 and so on // with ONE of reference count, to avoid warning on this vars - char Aux[3]; + TCHAR Aux[3]; int i; for (i = 0; i < 10; i++) // 0 - 9 { - sprintf(Aux, "%d", i); + sprintf(Aux, _T("%d"), i); m_UserVarNames.add(Aux,1); } for (i = 0; i < 10; i++) // 10 - 19 { - sprintf(Aux, "R%d", i); + sprintf(Aux, _T("R%d"), i); m_UserVarNames.add(Aux,1); } - m_UserVarNames.add("CMDLINE",1); // 20 everything before here doesn't have trailing slash removal - m_UserVarNames.add("INSTDIR",1); // 21 - m_UserVarNames.add("OUTDIR",1); // 22 - m_UserVarNames.add("EXEDIR",1); // 23 - m_UserVarNames.add("LANGUAGE",1); // 24 - m_UserVarNames.add("TEMP",-1); // 25 - m_UserVarNames.add("PLUGINSDIR",-1); // 26 - m_UserVarNames.add("EXEPATH",-1); // 27 - m_UserVarNames.add("EXEFILE",-1); // 28 - m_UserVarNames.add("HWNDPARENT",-1); // 29 - m_UserVarNames.add("_CLICK",-1); // 30 - m_UserVarNames.add("_OUTDIR",1); // 31 + m_UserVarNames.add(_T("CMDLINE"),1); // 20 everything before here doesn't have trailing slash removal + m_UserVarNames.add(_T("INSTDIR"),1); // 21 + m_UserVarNames.add(_T("OUTDIR"),1); // 22 + m_UserVarNames.add(_T("EXEDIR"),1); // 23 + m_UserVarNames.add(_T("LANGUAGE"),1); // 24 + m_UserVarNames.add(_T("TEMP"),-1); // 25 + m_UserVarNames.add(_T("PLUGINSDIR"),-1); // 26 + m_UserVarNames.add(_T("EXEPATH"),-1); // 27 + m_UserVarNames.add(_T("EXEFILE"),-1); // 28 + m_UserVarNames.add(_T("HWNDPARENT"),-1); // 29 + m_UserVarNames.add(_T("_CLICK"),-1); // 30 + m_UserVarNames.add(_T("_OUTDIR"),1); // 31 m_iBaseVarsNum = m_UserVarNames.getnum(); - m_ShellConstants.add("WINDIR",CSIDL_WINDOWS,CSIDL_WINDOWS); - m_ShellConstants.add("SYSDIR",CSIDL_SYSTEM,CSIDL_SYSTEM); - m_ShellConstants.add("SMPROGRAMS",CSIDL_PROGRAMS, CSIDL_COMMON_PROGRAMS); - m_ShellConstants.add("SMSTARTUP",CSIDL_STARTUP, CSIDL_COMMON_STARTUP); - m_ShellConstants.add("DESKTOP",CSIDL_DESKTOPDIRECTORY, CSIDL_COMMON_DESKTOPDIRECTORY); - m_ShellConstants.add("STARTMENU",CSIDL_STARTMENU, CSIDL_COMMON_STARTMENU); - m_ShellConstants.add("QUICKLAUNCH", CSIDL_APPDATA, CSIDL_APPDATA); - m_ShellConstants.add("DOCUMENTS",CSIDL_PERSONAL, CSIDL_COMMON_DOCUMENTS); - m_ShellConstants.add("SENDTO",CSIDL_SENDTO, CSIDL_SENDTO); - m_ShellConstants.add("RECENT",CSIDL_RECENT, CSIDL_RECENT); - m_ShellConstants.add("FAVORITES",CSIDL_FAVORITES, CSIDL_COMMON_FAVORITES); - m_ShellConstants.add("MUSIC",CSIDL_MYMUSIC, CSIDL_COMMON_MUSIC); - m_ShellConstants.add("PICTURES",CSIDL_MYPICTURES, CSIDL_COMMON_PICTURES); - m_ShellConstants.add("VIDEOS",CSIDL_MYVIDEO, CSIDL_COMMON_VIDEO); - m_ShellConstants.add("NETHOOD", CSIDL_NETHOOD, CSIDL_NETHOOD); - m_ShellConstants.add("FONTS", CSIDL_FONTS, CSIDL_FONTS); - m_ShellConstants.add("TEMPLATES", CSIDL_TEMPLATES, CSIDL_COMMON_TEMPLATES); - m_ShellConstants.add("APPDATA", CSIDL_APPDATA, CSIDL_COMMON_APPDATA); - m_ShellConstants.add("LOCALAPPDATA", CSIDL_LOCAL_APPDATA, CSIDL_LOCAL_APPDATA); - m_ShellConstants.add("PRINTHOOD", CSIDL_PRINTHOOD, CSIDL_PRINTHOOD); - //m_ShellConstants.add("ALTSTARTUP", CSIDL_ALTSTARTUP, CSIDL_COMMON_ALTSTARTUP); - m_ShellConstants.add("INTERNET_CACHE", CSIDL_INTERNET_CACHE, CSIDL_INTERNET_CACHE); - m_ShellConstants.add("COOKIES", CSIDL_COOKIES, CSIDL_COOKIES); - m_ShellConstants.add("HISTORY", CSIDL_HISTORY, CSIDL_HISTORY); - m_ShellConstants.add("PROFILE", CSIDL_PROFILE, CSIDL_PROFILE); - m_ShellConstants.add("ADMINTOOLS", CSIDL_ADMINTOOLS, CSIDL_COMMON_ADMINTOOLS); - m_ShellConstants.add("RESOURCES", CSIDL_RESOURCES, CSIDL_RESOURCES); - m_ShellConstants.add("RESOURCES_LOCALIZED", CSIDL_RESOURCES_LOCALIZED, CSIDL_RESOURCES_LOCALIZED); - m_ShellConstants.add("CDBURN_AREA", CSIDL_CDBURN_AREA, CSIDL_CDBURN_AREA); + m_ShellConstants.add(_T("WINDIR"),CSIDL_WINDOWS,CSIDL_WINDOWS); + m_ShellConstants.add(_T("SYSDIR"),CSIDL_SYSTEM,CSIDL_SYSTEM); + m_ShellConstants.add(_T("SMPROGRAMS"),CSIDL_PROGRAMS, CSIDL_COMMON_PROGRAMS); + m_ShellConstants.add(_T("SMSTARTUP"),CSIDL_STARTUP, CSIDL_COMMON_STARTUP); + m_ShellConstants.add(_T("DESKTOP"),CSIDL_DESKTOPDIRECTORY, CSIDL_COMMON_DESKTOPDIRECTORY); + m_ShellConstants.add(_T("STARTMENU"),CSIDL_STARTMENU, CSIDL_COMMON_STARTMENU); + m_ShellConstants.add(_T("QUICKLAUNCH"), CSIDL_APPDATA, CSIDL_APPDATA); + m_ShellConstants.add(_T("DOCUMENTS"),CSIDL_PERSONAL, CSIDL_COMMON_DOCUMENTS); + m_ShellConstants.add(_T("SENDTO"),CSIDL_SENDTO, CSIDL_SENDTO); + m_ShellConstants.add(_T("RECENT"),CSIDL_RECENT, CSIDL_RECENT); + m_ShellConstants.add(_T("FAVORITES"),CSIDL_FAVORITES, CSIDL_COMMON_FAVORITES); + m_ShellConstants.add(_T("MUSIC"),CSIDL_MYMUSIC, CSIDL_COMMON_MUSIC); + m_ShellConstants.add(_T("PICTURES"),CSIDL_MYPICTURES, CSIDL_COMMON_PICTURES); + m_ShellConstants.add(_T("VIDEOS"),CSIDL_MYVIDEO, CSIDL_COMMON_VIDEO); + m_ShellConstants.add(_T("NETHOOD"), CSIDL_NETHOOD, CSIDL_NETHOOD); + m_ShellConstants.add(_T("FONTS"), CSIDL_FONTS, CSIDL_FONTS); + m_ShellConstants.add(_T("TEMPLATES"), CSIDL_TEMPLATES, CSIDL_COMMON_TEMPLATES); + m_ShellConstants.add(_T("APPDATA"), CSIDL_APPDATA, CSIDL_COMMON_APPDATA); + m_ShellConstants.add(_T("LOCALAPPDATA"), CSIDL_LOCAL_APPDATA, CSIDL_LOCAL_APPDATA); + m_ShellConstants.add(_T("PRINTHOOD"), CSIDL_PRINTHOOD, CSIDL_PRINTHOOD); + //m_ShellConstants.add(_T("ALTSTARTUP"), CSIDL_ALTSTARTUP, CSIDL_COMMON_ALTSTARTUP); + m_ShellConstants.add(_T("INTERNET_CACHE"), CSIDL_INTERNET_CACHE, CSIDL_INTERNET_CACHE); + m_ShellConstants.add(_T("COOKIES"), CSIDL_COOKIES, CSIDL_COOKIES); + m_ShellConstants.add(_T("HISTORY"), CSIDL_HISTORY, CSIDL_HISTORY); + m_ShellConstants.add(_T("PROFILE"), CSIDL_PROFILE, CSIDL_PROFILE); + m_ShellConstants.add(_T("ADMINTOOLS"), CSIDL_ADMINTOOLS, CSIDL_COMMON_ADMINTOOLS); + m_ShellConstants.add(_T("RESOURCES"), CSIDL_RESOURCES, CSIDL_RESOURCES); + m_ShellConstants.add(_T("RESOURCES_LOCALIZED"), CSIDL_RESOURCES_LOCALIZED, CSIDL_RESOURCES_LOCALIZED); + m_ShellConstants.add(_T("CDBURN_AREA"), CSIDL_CDBURN_AREA, CSIDL_CDBURN_AREA); - unsigned int program_files = add_string("ProgramFilesDir", 0); - unsigned int program_files_def = add_string("C:\\Program Files"); + unsigned int program_files = add_string(_T("ProgramFilesDir"), 0); + unsigned int program_files_def = add_string(_T("C:\\Program Files")); if ((program_files >= 0x40) || (program_files_def >= 0xFF)) { // see Source\exehead\util.c for implementation details // basically, it knows it needs to get folders from the registry when the 0x80 is on - ERROR_MSG("Internal compiler error: too many strings added to strings block before adding shell constants!\n"); + ERROR_MSG(_T("Internal compiler error: too many strings added to strings block before adding shell constants!\n")); throw out_of_range("Internal compiler error: too many strings added to strings block before adding shell constants!"); } - m_ShellConstants.add("PROGRAMFILES", 0x80 | program_files, program_files_def); + m_ShellConstants.add(_T("PROGRAMFILES"), 0x80 | program_files, program_files_def); - unsigned int program_files64_def = add_string("$PROGRAMFILES"); + unsigned int program_files64_def = add_string(_T("$PROGRAMFILES")); if (program_files64_def > 0xFF) { - ERROR_MSG("Internal compiler error: too many strings added to strings block before adding shell constants!\n"); + ERROR_MSG(_T("Internal compiler error: too many strings added to strings block before adding shell constants!\n")); throw out_of_range("Internal compiler error: too many strings added to strings block before adding shell constants!"); } - m_ShellConstants.add("PROGRAMFILES32", 0x80 | program_files, program_files_def); - m_ShellConstants.add("PROGRAMFILES64", 0xC0 | program_files, program_files64_def); + m_ShellConstants.add(_T("PROGRAMFILES32"), 0x80 | program_files, program_files_def); + m_ShellConstants.add(_T("PROGRAMFILES64"), 0xC0 | program_files, program_files64_def); - unsigned int common_files = add_string("CommonFilesDir", 0); - unsigned int common_files_def = add_string("$PROGRAMFILES\\Common Files"); + unsigned int common_files = add_string(_T("CommonFilesDir"), 0); + unsigned int common_files_def = add_string(_T("$PROGRAMFILES\\Common Files")); if ((common_files > 0x40) || (common_files_def > 0xFF)) { - ERROR_MSG("Internal compiler error: too many strings added to strings block before adding shell constants!\n"); + ERROR_MSG(_T("Internal compiler error: too many strings added to strings block before adding shell constants!\n")); throw out_of_range("Internal compiler error: too many strings added to strings block before adding shell constants!"); } - m_ShellConstants.add("COMMONFILES", 0x80 | common_files, common_files_def); + m_ShellConstants.add(_T("COMMONFILES"), 0x80 | common_files, common_files_def); - unsigned int common_files64_def = add_string("$COMMONFILES"); + unsigned int common_files64_def = add_string(_T("$COMMONFILES")); if (common_files64_def > 0xFF) { - ERROR_MSG("Internal compiler error: too many strings added to strings block before adding shell constants!\n"); + ERROR_MSG(_T("Internal compiler error: too many strings added to strings block before adding shell constants!\n")); throw out_of_range("Internal compiler error: too many strings added to strings block before adding shell constants!"); } - m_ShellConstants.add("COMMONFILES32", 0x80 | common_files, common_files_def); - m_ShellConstants.add("COMMONFILES64", 0xC0 | common_files, common_files64_def); + m_ShellConstants.add(_T("COMMONFILES32"), 0x80 | common_files, common_files_def); + m_ShellConstants.add(_T("COMMONFILES64"), 0xC0 | common_files, common_files64_def); set_uninstall_mode(1); - unsigned int uprogram_files = add_string("ProgramFilesDir", 0); - unsigned int uprogram_files_def = add_string("C:\\Program Files"); - unsigned int uprogram_files64_def = add_string("$PROGRAMFILES"); - unsigned int ucommon_files = add_string("CommonFilesDir", 0); - unsigned int ucommon_files_def = add_string("$PROGRAMFILES\\Common Files"); - unsigned int ucommon_files64_def = add_string("$COMMONFILES"); + unsigned int uprogram_files = add_string(_T("ProgramFilesDir"), 0); + unsigned int uprogram_files_def = add_string(_T("C:\\Program Files")); + unsigned int uprogram_files64_def = add_string(_T("$PROGRAMFILES")); + unsigned int ucommon_files = add_string(_T("CommonFilesDir"), 0); + unsigned int ucommon_files_def = add_string(_T("$PROGRAMFILES\\Common Files")); + unsigned int ucommon_files64_def = add_string(_T("$COMMONFILES")); if (uprogram_files != program_files || uprogram_files_def != program_files_def @@ -398,7 +402,7 @@ CEXEBuild::CEXEBuild() : || ucommon_files_def != common_files_def || ucommon_files64_def != common_files64_def) { - ERROR_MSG("Internal compiler error: installer's shell constants are different than uninstallers!\n"); + ERROR_MSG(_T("Internal compiler error: installer's shell constants are different than uninstallers!\n")); throw out_of_range("Internal compiler error: installer's shell constants are different than uninstallers!"); } @@ -407,10 +411,10 @@ CEXEBuild::CEXEBuild() : set_code_type_predefines(); } -void CEXEBuild::initialize(const char *makensis_path) +void CEXEBuild::initialize(const TCHAR *makensis_path) { - string nsis_dir; - const char *dir = getenv("NSISDIR"); + tstring nsis_dir; + const TCHAR *dir = _tgetenv(_T("NSISDIR")); if (dir) nsis_dir = dir; else { #ifndef NSIS_CONFIG_CONST_DATA_PATH @@ -419,21 +423,21 @@ void CEXEBuild::initialize(const char *makensis_path) nsis_dir = PREFIX_DATA; #endif } - definedlist.add("NSISDIR", nsis_dir.c_str()); + definedlist.add(_T("NSISDIR"), nsis_dir.c_str()); - string includes_dir = nsis_dir; - includes_dir += PLATFORM_PATH_SEPARATOR_STR"Include"; + tstring includes_dir = nsis_dir; + includes_dir += PLATFORM_PATH_SEPARATOR_STR _T("Include"); include_dirs.add(includes_dir.c_str(),0); stubs_dir = nsis_dir; - stubs_dir += PLATFORM_PATH_SEPARATOR_STR"Stubs"; + stubs_dir += PLATFORM_PATH_SEPARATOR_STR _T("Stubs"); - if (set_compressor("zlib", false) != PS_OK) + if (set_compressor(_T("zlib"), false) != PS_OK) { throw runtime_error("error setting default stub"); } - string uninst = stubs_dir + PLATFORM_PATH_SEPARATOR_STR + "uninst"; + tstring uninst = stubs_dir + PLATFORM_PATH_SEPARATOR_STR + _T("uninst"); uninstaller_icon = load_icon_file(uninst.c_str()); } @@ -441,15 +445,15 @@ void CEXEBuild::initialize(const char *makensis_path) int CEXEBuild::getcurdbsize() { return cur_datablock->getlen(); } // returns offset in stringblock -int CEXEBuild::add_string(const char *string, int process/*=1*/, WORD codepage/*=CP_ACP*/) +int CEXEBuild::add_string(const TCHAR *string, int process/*=1*/, WORD codepage/*=CP_ACP*/) { if (!string || !*string) return 0; - if (*string == '$' && *(string+1) == '(') { + if (*string == _T('$') && *(string+1) == _T('(')) { int idx = 0; - char *cp = strdup(string+2); - char *p = strchr(cp, ')'); - if (p && p[1] == '\0' ) { // if string is only a language str identifier + TCHAR *cp = strdup(string+2); + TCHAR *p = _tcschr(cp, _T(')')); + if (p && p[1] == _T('\0') ) { // if string is only a language str identifier *p = 0; idx = DefineLangString(cp, process); } @@ -459,67 +463,78 @@ int CEXEBuild::add_string(const char *string, int process/*=1*/, WORD codepage/* if (!process) return cur_strlist->add(string,2); - char buf[NSIS_MAX_STRLEN*4]; + TCHAR buf[NSIS_MAX_STRLEN*4]; preprocess_string(buf,string,codepage); return cur_strlist->add(buf,2); } int CEXEBuild::add_intstring(const int i) // returns offset in stringblock { - char i_str[1024]; - wsprintf(i_str, "%d", i); + TCHAR i_str[1024]; + wsprintf(i_str, _T("%d"), i); return add_string(i_str); } // based on Dave Laundon's code -int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_ACP*/) +int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP_ACP*/) { - const char *p=in; + const TCHAR *p=in; while (*p) { - const char *np = CharNextExA(codepage, p, 0); - if (np - p > 1) // multibyte char + const TCHAR *np = CharNextExA(codepage, p, 0); + if (np - p > 1) // multibyte TCHAR { int l = np - p; while (l--) { - unsigned char i = (unsigned char)*p++; + _TUCHAR i = (_TUCHAR)*p++; if (i >= NS_CODES_START) { - *out++ = (char)NS_SKIP_CODE; + *out++ = (TCHAR)NS_SKIP_CODE; } - *out++=(char)i; + *out++=(TCHAR)i; } continue; } - unsigned char i = (unsigned char)*p; + _TUCHAR i = (_TUCHAR)*p; - p=np; + p=np; // increment p. // Test for characters extending into the variable codes if (i >= NS_CODES_START) { - *out++ = (char)NS_SKIP_CODE; + *out++ = (TCHAR)NS_SKIP_CODE; + // out does get the NS_CODE as well because of + // "*out++=(TCHAR)i" at the end. } - else if (i == '$') + else if (i == _T('$')) { - if (*p == '$') + if (*p == _T('$')) p++; // Can simply convert $$ to $ now else { - { + // starts with a $ but not $$. + { // block - why do we need this extra {? bool bProceced=false; if ( *p ) { - const char *pUserVarName = p; + const TCHAR *pUserVarName = p; while (isSimpleChar(*pUserVarName)) pUserVarName++; while (pUserVarName > p) { - if (m_ShellConstants.get((char*)p, pUserVarName-p) >= 0) - break; // Upps it's a shell constant + if (m_ShellConstants.get((TCHAR*)p, pUserVarName-p) >= 0) + break; // Woops it's a shell constant - int idxUserVar = m_UserVarNames.get((char*)p, pUserVarName-p); + // Jim Park: The following line could be a source of bugs for + // variables where one variable name is a prefix of another + // variable name. For example, if you are searching for + // variable 'UserVar', you can get 'UserVariable' instead. + // Suggest that we do: + // TCHAR varname[NSIS_MAX_STRLEN]; + // _tcsncpy(varname, p, pUserVarName-p); + // int idxUserVar = m_UserVarNames.get(varname); + int idxUserVar = m_UserVarNames.get((TCHAR*)p, pUserVarName-p); if (idxUserVar >= 0) { // Well, using variables inside string formating doens't mean @@ -527,102 +542,111 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A // which is also memory wasting // So the line below must be commented !?? //m_UserVarNames.inc_reference(idxUserVar); - *out++ = (char) NS_VAR_CODE; // Named user variable; + *out++ = (TCHAR) NS_VAR_CODE; // Named user variable; WORD w = FIX_ENDIAN_INT16(CODE_SHORT(idxUserVar)); memcpy(out, &w, sizeof(WORD)); - out += sizeof(WORD); - p += pUserVarName-p; + out += sizeof(WORD)/sizeof(TCHAR); + p += pUserVarName-p; // zip past the user var string. bProceced = true; break; } pUserVarName--; } - } + }// if ( *p ) if (!bProceced && *p) { - const char *pShellConstName = p; + const TCHAR *pShellConstName = p; while (isSimpleChar(*pShellConstName)) pShellConstName++; while (pShellConstName > p) { - int idxConst = m_ShellConstants.get((char*)p, pShellConstName - p); + // Look for the identifier in the shell constants list of strings. + int idxConst = m_ShellConstants.get((TCHAR*)p, pShellConstName - p); + + // If found... if (idxConst >= 0) { int CSIDL_Value_current = m_ShellConstants.get_value1(idxConst); int CSIDL_Value_all = m_ShellConstants.get_value2(idxConst); - *out++=(char)NS_SHELL_CODE; // Constant code identifier - *out++=(char)CSIDL_Value_current; - *out++=(char)CSIDL_Value_all; - p = pShellConstName; + *out++=(TCHAR)NS_SHELL_CODE; // Constant code identifier + *out++=(TCHAR)CSIDL_Value_current; + *out++=(TCHAR)CSIDL_Value_all; + p = pShellConstName; // zip past the shell constant string. bProceced = true; break; } + + // We are looking from the longest identifier first and work + // smaller. pShellConstName--; } } - if ( !bProceced && *p == '(' ) + if ( !bProceced && *p == _T('(') ) { int idx = -1; - char *cp = strdup(p+1); - char *pos = strchr(cp, ')'); + TCHAR *cp = strdup(p+1); // JP: Bad... should avoid memory alloc. + TCHAR *pos = _tcschr(cp, _T(')')); if (pos) { *pos = 0; idx = DefineLangString(cp); if (idx < 0) { - *out++ = (char)NS_LANG_CODE; // Next word is lang-string Identifier + *out++ = (TCHAR)NS_LANG_CODE; // Next word is lang-string Identifier WORD w = FIX_ENDIAN_INT16(CODE_SHORT(-idx-1)); memcpy(out, &w, sizeof(WORD)); - out += sizeof(WORD); - p += strlen(cp) + 2; + out += sizeof(WORD)/sizeof(TCHAR); + p += _tcsclen(cp) + 2; bProceced = true; } } free(cp); } if ( bProceced ) - continue; + continue; // outermost while else { - char tbuf[64]; - char cBracket = '\0'; + TCHAR tbuf[64]; + TCHAR cBracket = _T('\0'); bool bDoWarning = true; - if ( *p == '[' ) - cBracket = ']'; - else if ( *p == '(' ) - cBracket = ')'; - else if ( *p == '{' ) - cBracket = '}'; + if ( *p == _T('[') ) + cBracket = _T(']'); + else if ( *p == _T('(') ) + cBracket = _T(')'); + else if ( *p == _T('{') ) + cBracket = _T('}'); - strncpy(tbuf,p,63); + _tcsnccpy(tbuf,p,63); tbuf[63]=0; if ( cBracket != 0 ) { - if (strchr(tbuf,cBracket)) (strchr(tbuf,cBracket)+1)[0]=0; - if ( tbuf[0] == '{' && tbuf[strlen(tbuf)-1] == '}' ) + if (_tcschr(tbuf,cBracket)) (_tcschr(tbuf,cBracket)+1)[0]=0; + if ( tbuf[0] == _T('{') && tbuf[_tcsclen(tbuf)-1] == _T('}') ) { - char *tstIfDefine = strdup(tbuf+1); - tstIfDefine[strlen(tstIfDefine)-1] = '\0'; + TCHAR *tstIfDefine = strdup(tbuf+1); + tstIfDefine[_tcsclen(tstIfDefine)-1] = _T('\0'); bDoWarning = definedlist.find(tstIfDefine) == NULL; + // If it's a defined identifier, then don't warn. } } else { - if (strstr(tbuf," ")) strstr(tbuf," ")[0]=0; + if (_tcsstr(tbuf,_T(" "))) _tcsstr(tbuf,_T(" "))[0]=0; } if ( bDoWarning ) - warning_fl("unknown variable/constant \"%s\" detected, ignoring",tbuf); - i = '$'; + warning_fl(_T("unknown variable/constant \"%s\" detected, ignoring"),tbuf); + i = _T('$'); // redundant since i is already '$' and has + // not changed. } - } - } - } - *out++=(char)i; - } + } // block + } // else + } // else if (i == _T('$')) + + *out++=(TCHAR)i; + } // outside while *out=0; return 0; } @@ -637,16 +661,16 @@ int CEXEBuild::datablock_optimize(int start_offset, int first_int) int this_len = cur_datablock->getlen() - start_offset; cached_db_size this_size = {first_int, start_offset}; - cur_datablock_cache->add(&this_size, sizeof(cached_db_size)); + this->cur_datablock_cache->add(&this_size, sizeof(cached_db_size)); - if (!build_optimize_datablock || this_len < (int) sizeof(int)) + if (!this->build_optimize_datablock || this_len < (int) sizeof(int)) return start_offset; MMapBuf *db = (MMapBuf *) cur_datablock; db->setro(TRUE); - cached_db_size *db_sizes = (cached_db_size *) cur_datablock_cache->get(); - int db_sizes_num = cur_datablock_cache->getlen() / sizeof(cached_db_size); + cached_db_size *db_sizes = (cached_db_size *) this->cur_datablock_cache->get(); + int db_sizes_num = this->cur_datablock_cache->getlen() / sizeof(cached_db_size); db_sizes_num--; // don't compare with the one we just added for (int i = 0; i < db_sizes_num; i++) @@ -679,7 +703,7 @@ int CEXEBuild::datablock_optimize(int start_offset, int first_int) db_opt_save += this_len; db->resize(max(start_offset, pos + this_len)); db->setro(FALSE); - cur_datablock_cache->resize(cur_datablock_cache->getlen() - sizeof(cached_db_size)); + this->cur_datablock_cache->resize(cur_datablock_cache->getlen() - sizeof(cached_db_size)); return pos; } } @@ -698,7 +722,7 @@ int CEXEBuild::add_db_data(IMMap *mmap) // returns offset if (!mmap) { - ERROR_MSG("Error: add_db_data() called with invalid mapped file\n"); + ERROR_MSG(_T("Error: add_db_data() called with invalid mapped file\n")); return -1; } @@ -706,11 +730,13 @@ int CEXEBuild::add_db_data(IMMap *mmap) // returns offset if (length < 0) { - ERROR_MSG("Error: add_db_data() called with length=%d\n", length); + ERROR_MSG(_T("Error: add_db_data() called with length=%d\n"), length); return -1; } - MMapBuf *db = (MMapBuf *) cur_datablock; + // Jim Park: This kind of stuff looks scary and it is. cur_datablock is + // most likely to point to a MMapBuf type right now so it works. + MMapBuf *db = (MMapBuf *) this->cur_datablock; int st = db->getlen(); @@ -727,7 +753,7 @@ int CEXEBuild::add_db_data(IMMap *mmap) // returns offset int n = compressor->Init(build_compress_level, build_compress_dict_size); if (n != C_OK) { - ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%s [%d]).\n", compressor->GetErrStr(n), n); + ERROR_MSG(_T("Internal compiler error #12345: deflateInit() failed(%s [%d]).\n"), compressor->GetErrStr(n), n); extern void quit(); quit(); } @@ -736,14 +762,14 @@ int CEXEBuild::add_db_data(IMMap *mmap) // returns offset int ret; while (avail_in > 0) { - int in_len = min(build_filebuflen, avail_in); - int out_len = min(build_filebuflen, avail_out); + int in_len = min(this->build_filebuflen, avail_in); + int out_len = min(this->build_filebuflen, avail_out); - compressor->SetNextIn((char *) mmap->get(length - avail_in, in_len), in_len); - compressor->SetNextOut((char *) db->get(st + sizeof(int) + bufferlen - avail_out, out_len), out_len); + compressor->SetNextIn((char*) mmap->get(length - avail_in, in_len), in_len); + compressor->SetNextOut((char*) db->get(st + sizeof(int) + bufferlen - avail_out, out_len), out_len); if ((ret = compressor->Compress(0)) < 0) { - ERROR_MSG("Error: add_db_data() - compress() failed(%s [%d])\n", compressor->GetErrStr(ret), ret); + ERROR_MSG(_T("Error: add_db_data() - compress() failed(%s [%d])\n"), compressor->GetErrStr(ret), ret); return -1; } mmap->release(); @@ -774,7 +800,7 @@ int CEXEBuild::add_db_data(IMMap *mmap) // returns offset compressor->SetNextOut(out, out_len); if ((ret = compressor->Compress(C_FINISH)) < 0) { - ERROR_MSG("Error: add_db_data() - compress() failed(%s [%d])\n", compressor->GetErrStr(ret), ret); + ERROR_MSG(_T("Error: add_db_data() - compress() failed(%s [%d])\n"), compressor->GetErrStr(ret), ret); return -1; } @@ -850,7 +876,7 @@ int CEXEBuild::add_data(const char *data, int length, IGrowBuf *dblock) // retur if (length < 0) { - ERROR_MSG("Error: add_data() called with length=%d\n",length); + ERROR_MSG(_T("Error: add_data() called with length=%d\n"),length); return -1; } @@ -866,7 +892,7 @@ int CEXEBuild::add_data(const char *data, int length, IGrowBuf *dblock) // retur int n = compressor->Init(build_compress_level, build_compress_dict_size); if (n != C_OK) { - ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%s [%d]).\n", compressor->GetErrStr(n), n); + ERROR_MSG(_T("Internal compiler error #12345: deflateInit() failed(%s [%d]).\n"), compressor->GetErrStr(n), n); extern void quit(); quit(); } @@ -900,43 +926,46 @@ int CEXEBuild::add_data(const char *data, int length, IGrowBuf *dblock) // retur return st; } -int CEXEBuild::add_label(const char *name) +int CEXEBuild::add_label(const TCHAR *name) { if (!build_cursection) { - ERROR_MSG("Error: Label declaration not valid outside of function/section\n"); + ERROR_MSG(_T("Error: Label declaration not valid outside of function/section\n")); return PS_ERROR; } - if ((name[0] >= '0' && name[0] <= '9') || name[0] == '-' || name[0] == ' ' || name[0] == ':') + if ((name[0] >= _T('0') && name[0] <= _T('9')) || name[0] == _T('-') || name[0] == _T(' ') || name[0] == _T(':')) { - ERROR_MSG("Error: labels must not begin with 0-9, -, :, or a space.\n"); + ERROR_MSG(_T("Error: labels must not begin with 0-9, -, :, or a space.\n")); return PS_ERROR; } int cs=build_cursection->code; int ce=cs+build_cursection->code_size; - char *p=strdup(name); - if (p[strlen(p)-1] == ':') p[strlen(p)-1]=0; + TCHAR *p=strdup(name); + if (p[_tcsclen(p)-1] == _T(':')) p[_tcsclen(p)-1]=0; int offs=ns_label.add(p,0); free(p); int n=cur_labels->getlen()/sizeof(section); + + // Check to see if the label already exists. if (n) { section *t=(section*)cur_labels->get(); while (n--) { - if ((*name == '.' || (t->code >= cs && t->code <= ce)) && + // Labels beginning with '.' are global and can be jumped to from any function or section. + if ((*name == _T('.') || (t->code >= cs && t->code <= ce)) && t->name_ptr==offs) { - if (*name == '.') ERROR_MSG("Error: global label \"%s\" already declared\n",name); + if (*name == _T('.')) ERROR_MSG(_T("Error: global label \"%s\" already declared\n"),name); else { - const char *t = "section"; + const TCHAR *t = _T("section"); if (build_cursection_isfunc) - t = "function"; - ERROR_MSG("Error: label \"%s\" already declared in %s\n",name,t); + t = _T("function"); + ERROR_MSG(_T("Error: label \"%s\" already declared in %s\n"),name,t); } return PS_ERROR; } @@ -952,31 +981,32 @@ int CEXEBuild::add_label(const char *name) return PS_OK; } -int CEXEBuild::add_function(const char *funname) +int CEXEBuild::add_function(const TCHAR *funname) { if (build_cursection_isfunc) { - ERROR_MSG("Error: Function open when creating function (use FunctionEnd first)\n"); + ERROR_MSG(_T("Error: Function open when creating function (use FunctionEnd first)\n")); return PS_ERROR; } if (build_cursection) { - ERROR_MSG("Error: Section open when creating function (use SectionEnd first)\n"); + ERROR_MSG(_T("Error: Section open when creating function (use SectionEnd first)\n")); return PS_ERROR; } if (cur_page) { - ERROR_MSG("Error: PageEx open when creating function (use PageExEnd first)\n"); + ERROR_MSG(_T("Error: PageEx open when creating function (use PageExEnd first)\n")); return PS_ERROR; } if (!funname[0]) { - ERROR_MSG("Error: Function must have a name\n"); + ERROR_MSG(_T("Error: Function must have a name\n")); return PS_ERROR; } - set_uninstall_mode(!strnicmp(funname,"un.",3)); + set_uninstall_mode(!strnicmp(funname,_T("un."),3)); + // ns_func contains all the function names defined. int addr=ns_func.add(funname,0); int x; int n=cur_functions->getlen()/sizeof(section); @@ -985,7 +1015,7 @@ int CEXEBuild::add_function(const char *funname) { if (tmp[x].name_ptr == addr) { - ERROR_MSG("Error: Function named \"%s\" already exists.\n",funname); + ERROR_MSG(_T("Error: Function named \"%s\" already exists.\n"),funname); return PS_ERROR; } } @@ -1013,7 +1043,7 @@ int CEXEBuild::function_end() { if (!build_cursection_isfunc) { - ERROR_MSG("Error: No function open, FunctionEnd called\n"); + ERROR_MSG(_T("Error: No function open, FunctionEnd called\n")); return PS_ERROR; } // add ret. @@ -1033,7 +1063,7 @@ int CEXEBuild::section_add_flags(int flags) { if (!build_cursection || build_cursection_isfunc) { - ERROR_MSG("Error: can't modify flags when no section is open\n"); + ERROR_MSG(_T("Error: can't modify flags when no section is open\n")); return PS_ERROR; } build_cursection->flags |= flags; @@ -1044,7 +1074,7 @@ int CEXEBuild::section_add_install_type(int inst_type) { if (!build_cursection || build_cursection_isfunc) { - ERROR_MSG("Error: can't modify flags when no section is open\n"); + ERROR_MSG(_T("Error: can't modify flags when no section is open\n")); return PS_ERROR; } if (build_cursection->install_types == ~0) @@ -1065,12 +1095,12 @@ int CEXEBuild::section_end() { if (build_cursection_isfunc) { - ERROR_MSG("Error: SectionEnd specified in function (not section)\n"); + ERROR_MSG(_T("Error: SectionEnd specified in function (not section)\n")); return PS_ERROR; } if (!build_cursection) { - ERROR_MSG("Error: SectionEnd specified and no sections open\n"); + ERROR_MSG(_T("Error: SectionEnd specified and no sections open\n")); return PS_ERROR; } add_entry_direct(EW_RET); @@ -1083,20 +1113,20 @@ int CEXEBuild::section_end() return PS_OK; } -int CEXEBuild::add_section(const char *secname, const char *defname, int expand/*=0*/) +int CEXEBuild::add_section(const TCHAR *secname, const TCHAR *defname, int expand/*=0*/) { if (build_cursection_isfunc) { - ERROR_MSG("Error: Section can't create section (already in function, use FunctionEnd first)\n"); + ERROR_MSG(_T("Error: Section can't create section (already in function, use FunctionEnd first)\n")); return PS_ERROR; } if (cur_page) { - ERROR_MSG("Error: PageEx already open, call PageExEnd first\n"); + ERROR_MSG(_T("Error: PageEx already open, call PageExEnd first\n")); return PS_ERROR; } if (build_cursection) { - ERROR_MSG("Error: Section already open, call SectionEnd first\n"); + ERROR_MSG(_T("Error: Section already open, call SectionEnd first\n")); return PS_ERROR; } @@ -1106,9 +1136,10 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/ new_section.code_size = 0; new_section.size_kb = 0; - char *name = (char*)secname; + TCHAR *name = (TCHAR*)secname; - if (secname[0] == '-') + // Is it a hidden section? + if (secname[0] == _T('-')) { if (secname[1]) { @@ -1119,7 +1150,7 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/ new_section.flags |= SF_SECGRPEND; } - if (name[0] == '!') + if (name[0] == _T('!')) { name++; new_section.flags |= SF_BOLD; @@ -1129,13 +1160,13 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/ set_uninstall_mode(0); - if (!strnicmp(name, "un.", 3)) + if (!strnicmp(name, _T("un."), 3)) { set_uninstall_mode(1); name += 3; } - if (!stricmp(name, "uninstall")) + if (!stricmp(name, _T("uninstall"))) { set_uninstall_mode(1); } @@ -1149,7 +1180,7 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/ { if (uninstall_mode != old_uninstall_mode) { - ERROR_MSG("Error: Can't create %s section in %s section group (use SectionGroupEnd first)\n", uninstall_mode ? "uninstaller" : "installer", old_uninstall_mode ? "uninstaller" : "installer"); + ERROR_MSG(_T("Error: Can't create %s section in %s section group (use SectionGroupEnd first)\n"), uninstall_mode ? _T("uninstaller") : _T("installer"), old_uninstall_mode ? _T("uninstaller") : _T("installer")); return PS_ERROR; } } @@ -1165,11 +1196,11 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/ if (defname[0]) { - char buf[1024]; - wsprintf(buf, "%d", cur_header->blocks[NB_SECTIONS].num); + TCHAR buf[1024]; + wsprintf(buf, _T("%d"), cur_header->blocks[NB_SECTIONS].num); if (definedlist.add(defname, buf)) { - ERROR_MSG("Error: \"%s\" already defined, can't assign section index!\n", defname); + ERROR_MSG(_T("Error: \"%s\" already defined, can't assign section index!\n"), defname); return PS_ERROR; } } @@ -1188,7 +1219,7 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/ sectiongroup_open_cnt--; if (sectiongroup_open_cnt < 0) { - ERROR_MSG("SectionGroupEnd: no SectionGroups are open\n"); + ERROR_MSG(_T("SectionGroupEnd: no SectionGroups are open\n")); return PS_ERROR; } if (!sectiongroup_open_cnt) @@ -1209,7 +1240,7 @@ int CEXEBuild::add_entry(const entry *ent) { if (!build_cursection && !uninstall_mode) { - ERROR_MSG("Error: Can't add entry, no section or function is open!\n"); + ERROR_MSG(_T("Error: Can't add entry, no section or function is open!\n")); return PS_ERROR; } @@ -1236,14 +1267,14 @@ int CEXEBuild::add_entry_direct(int which, int o0, int o1, int o2, int o3, int o return add_entry(&ent); } -int CEXEBuild::resolve_jump_int(const char *fn, int *a, int offs, int start, int end) +int CEXEBuild::resolve_jump_int(const TCHAR *fn, int *a, int offs, int start, int end) { if (*a > 0) { - char *lname=(char*)ns_label.get()+*a; - if (lname[0] == '-' || lname[0]=='+') + TCHAR *lname=(TCHAR*)ns_label.get()+*a; + if (lname[0] == _T('-') || lname[0]==_T('+')) { - int jump = atoi(lname); + int jump = _ttoi(lname); int *skip_map = (int *) cur_instruction_entry_map->get(); int maxoffs = cur_instruction_entry_map->getlen() / (int) sizeof(int); @@ -1271,11 +1302,11 @@ int CEXEBuild::resolve_jump_int(const char *fn, int *a, int offs, int start, int int n=cur_labels->getlen()/sizeof(section); while (n-->0) { - if ((*lname == '.' || (s->code >= start && s->code <= end)) && s->name_ptr == *a) + if ((*lname == _T('.') || (s->code >= start && s->code <= end)) && s->name_ptr == *a) { *a = s->code+1; // jumps are to the absolute position, +1 (to differentiate between no jump, and jumping to offset 0) s->flags++; - if (*lname == '.') + if (*lname == _T('.')) { // bug #2593369 - mark functions with used global labels as used // XXX this puts another hole in function reference counting @@ -1299,7 +1330,7 @@ int CEXEBuild::resolve_jump_int(const char *fn, int *a, int offs, int start, int s++; } - ERROR_MSG("Error: could not resolve label \"%s\" in %s\n",lname,fn); + ERROR_MSG(_T("Error: could not resolve label \"%s\" in %s\n"),lname,fn); return 1; } } @@ -1310,7 +1341,7 @@ int CEXEBuild::resolve_jump_int(const char *fn, int *a, int offs, int start, int return 0; } -int CEXEBuild::resolve_call_int(const char *fn, const char *str, int fptr, int *ofs) +int CEXEBuild::resolve_call_int(const TCHAR *fn, const TCHAR *str, int fptr, int *ofs) { if (fptr < 0) return 0; int nf=cur_functions->getlen()/sizeof(section); @@ -1325,12 +1356,12 @@ int CEXEBuild::resolve_call_int(const char *fn, const char *str, int fptr, int * } sec++; } - ERROR_MSG("Error: resolving %s function \"%s\" in %s\n",str,(char*)ns_func.get()+fptr,fn); - ERROR_MSG("Note: uninstall functions must begin with \"un.\", and install functions must not\n"); + ERROR_MSG(_T("Error: resolving %s function \"%s\" in %s\n"),str,(TCHAR*)ns_func.get()+fptr,fn); + ERROR_MSG(_T("Note: uninstall functions must begin with \"un.\", and install functions must not\n")); return 1; } -int CEXEBuild::resolve_instruction(const char *fn, const char *str, entry *w, int offs, int start, int end) +int CEXEBuild::resolve_instruction(const TCHAR *fn, const TCHAR *str, entry *w, int offs, int start, int end) { if (w->which == EW_NOP) { @@ -1396,7 +1427,7 @@ int CEXEBuild::resolve_instruction(const char *fn, const char *str, entry *w, in { if (w->offsets[1] < 0) { - ERROR_MSG("Error: GetFunctionAddress requires a real function to get address of.\n"); + ERROR_MSG(_T("Error: GetFunctionAddress requires a real function to get address of.\n")); return 1; } @@ -1415,7 +1446,7 @@ int CEXEBuild::resolve_instruction(const char *fn, const char *str, entry *w, in return 0; } -int CEXEBuild::resolve_coderefs(const char *str) +int CEXEBuild::resolve_coderefs(const TCHAR *str) { // resolve jumps&calls { @@ -1427,8 +1458,8 @@ int CEXEBuild::resolve_coderefs(const char *str) int x; for (x = sec->code; x < sec->code+sec->code_size; x ++) { - char fname[1024]; - wsprintf(fname,"function \"%s\"",ns_func.get()+sec->name_ptr); + TCHAR fname[1024]; + wsprintf(fname,_T("function \"%s\""),ns_func.get()+sec->name_ptr); if (resolve_instruction(fname,str,w+x,x,sec->code,sec->code+sec->code_size)) return 1; } sec++; @@ -1440,20 +1471,20 @@ int CEXEBuild::resolve_coderefs(const char *str) while (l-- > 0) { int x=sec->name_ptr; - char fname[1024]; - const char *section_name; + TCHAR fname[1024]; + const TCHAR *section_name; if (x < 0) { // lang string - section_name = "$(lang string)"; + section_name = _T("$(lang string)"); } else { // normal string section_name = cur_strlist->get() + x; } - if (x) wsprintf(fname,"%s section \"%s\" (%d)",str,section_name,cnt); - else wsprintf(fname,"unnamed %s section (%d)",str,cnt); + if (x) wsprintf(fname,_T("%s section \"%s\" (%d)"),str,section_name,cnt); + else wsprintf(fname,_T("unnamed %s section (%d)"),str,cnt); for (x = sec->code; x < sec->code+sec->code_size; x ++) { if (resolve_instruction(fname,str,w+x,x,sec->code,sec->code+sec->code_size)) @@ -1468,11 +1499,11 @@ int CEXEBuild::resolve_coderefs(const char *str) page *p=(page *)cur_pages->get(); int i = 0; while (i < cur_header->blocks[NB_PAGES].num) { - char pagestr[1024]; - wsprintf(pagestr, "%s pages", str); - if (resolve_call_int(pagestr,p->dlg_id?"pre-page":"create-page",p->prefunc,&p->prefunc)) return 1; - if (resolve_call_int(pagestr,"show-page",p->showfunc,&p->showfunc)) return 1; - if (resolve_call_int(pagestr,"leave-page",p->leavefunc,&p->leavefunc)) return 1; + TCHAR pagestr[1024]; + wsprintf(pagestr, _T("%s pages"), str); + if (resolve_call_int(pagestr,p->dlg_id?_T("pre-page"):_T("create-page"),p->prefunc,&p->prefunc)) return 1; + if (resolve_call_int(pagestr,_T("show-page"),p->showfunc,&p->showfunc)) return 1; + if (resolve_call_int(pagestr,_T("leave-page"),p->leavefunc,&p->leavefunc)) return 1; p++; i++; } @@ -1485,36 +1516,36 @@ int CEXEBuild::resolve_coderefs(const char *str) // resolve callbacks { struct { - const char *name; + const TCHAR *name; int *p; } callbacks[] = { - {"%s.onInit", &cur_header->code_onInit}, - {"%s.on%sInstSuccess", &cur_header->code_onInstSuccess}, - {"%s.on%sInstFailed", &cur_header->code_onInstFailed}, - {"%s.onUserAbort", &cur_header->code_onUserAbort}, - {"%s.onVerifyInstDir", &cur_header->code_onVerifyInstDir}, + {_T("%s.onInit"), &cur_header->code_onInit}, + {_T("%s.on%sInstSuccess"), &cur_header->code_onInstSuccess}, + {_T("%s.on%sInstFailed"), &cur_header->code_onInstFailed}, + {_T("%s.onUserAbort"), &cur_header->code_onUserAbort}, + {_T("%s.onVerifyInstDir"), &cur_header->code_onVerifyInstDir}, #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT - {"%s.onGUIInit", &cur_header->code_onGUIInit}, - {"%s.onGUIEnd", &cur_header->code_onGUIEnd}, - {"%s.onMouseOverSection", &cur_header->code_onMouseOverSection}, + {_T("%s.onGUIInit"), &cur_header->code_onGUIInit}, + {_T("%s.onGUIEnd"), &cur_header->code_onGUIEnd}, + {_T("%s.onMouseOverSection"), &cur_header->code_onMouseOverSection}, #endif//NSIS_CONFIG_ENHANCEDUI_SUPPORT #ifdef NSIS_CONFIG_COMPONENTPAGE - {"%s.onSelChange", &cur_header->code_onSelChange}, + {_T("%s.onSelChange"), &cur_header->code_onSelChange}, #endif//NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_SUPPORT_REBOOT - {"%s.onRebootFailed", &cur_header->code_onRebootFailed}, + {_T("%s.onRebootFailed"), &cur_header->code_onRebootFailed}, #endif//NSIS_SUPPORT_REBOOT {0, 0} }; for (int i = 0; callbacks[i].name; i++) { - const char *un = uninstall_mode ? "un" : ""; - char fname[1024]; + const TCHAR *un = uninstall_mode ? _T("un") : _T(""); + TCHAR fname[1024]; wsprintf(fname, callbacks[i].name, un, un); - char cbstr[1024]; - wsprintf(cbstr, "%s callback", str); - char cbstr2[1024]; - wsprintf(cbstr2, "%s.callbacks", un); + TCHAR cbstr[1024]; + wsprintf(cbstr, _T("%s callback"), str); + TCHAR cbstr2[1024]; + wsprintf(cbstr2, _T("%s.callbacks"), un); if (resolve_call_int(cbstr,cbstr2,ns_func.find(fname,0),callbacks[i].p)) return PS_ERROR; @@ -1535,7 +1566,7 @@ int CEXEBuild::resolve_coderefs(const char *str) { if (sec->code_size>0) { - warning("%s function \"%s\" not referenced - zeroing code (%d-%d) out\n",str, + warning(_T("%s function \"%s\" not referenced - zeroing code (%d-%d) out\n"),str, ns_func.get()+sec->name_ptr, sec->code,sec->code+sec->code_size); memset(w+sec->code,0,sec->code_size*sizeof(entry)); @@ -1554,9 +1585,9 @@ int CEXEBuild::resolve_coderefs(const char *str) { if (!t->flags) { - char *n=(char*)ns_label.get()+t->name_ptr; - if (*n == '.') warning("global label \"%s\" not used",n); - else warning("label \"%s\" not used",n); + TCHAR *n=(TCHAR*)ns_label.get()+t->name_ptr; + if (*n == _T('.')) warning(_T("global label \"%s\" not used"),n); + else warning(_T("label \"%s\" not used"),n); } t++; } @@ -1582,21 +1613,21 @@ int CEXEBuild::add_page(int type) #ifndef NSIS_CONFIG_LICENSEPAGE if (type == PAGE_LICENSE) { - ERROR_MSG("Error: can't add license page, NSIS_CONFIG_LICENSEPAGE not defined.\n"); + ERROR_MSG(_T("Error: can't add license page, NSIS_CONFIG_LICENSEPAGE not defined.\n")); return PS_ERROR; } #endif #ifndef NSIS_CONFIG_COMPONENTPAGE if (type == PAGE_COMPONENTS) { - ERROR_MSG("Error: can't add components page, NSIS_CONFIG_COMPONENTPAGE not defined.\n"); + ERROR_MSG(_T("Error: can't add components page, NSIS_CONFIG_COMPONENTPAGE not defined.\n")); return PS_ERROR; } #endif #ifndef NSIS_CONFIG_UNINSTALL_SUPPORT if (type == PAGE_COMPONENTS) { - ERROR_MSG("Error: can't add uninstConfirm page, NSIS_CONFIG_UNINSTALL_SUPPORT not defined.\n"); + ERROR_MSG(_T("Error: can't add uninstConfirm page, NSIS_CONFIG_UNINSTALL_SUPPORT not defined.\n")); return PS_ERROR; } #endif @@ -1604,25 +1635,25 @@ int CEXEBuild::add_page(int type) struct { int wndproc_id; int dlg_id; - const char *name; + const TCHAR *name; } ids[] = { - {PWP_CUSTOM, 0, "custom"}, // custom + {PWP_CUSTOM, 0, _T("custom")}, // custom #ifdef NSIS_CONFIG_LICENSEPAGE - {PWP_LICENSE, IDD_LICENSE, "license"}, // license + {PWP_LICENSE, IDD_LICENSE, _T("license")}, // license #else - {0, IDD_LICENSE, "license"}, // license + {0, IDD_LICENSE, _T("license")}, // license #endif #ifdef NSIS_CONFIG_COMPONENTPAGE - {PWP_SELCOM, IDD_SELCOM, "components"}, // components + {PWP_SELCOM, IDD_SELCOM, _T("components")}, // components #else - {0, IDD_SELCOM, "components"}, // components + {0, IDD_SELCOM, _T("components")}, // components #endif - {PWP_DIR, IDD_DIR, "directory"}, // directory - {PWP_INSTFILES, IDD_INSTFILES, "instfiles"}, // instfiles + {PWP_DIR, IDD_DIR, _T("directory")}, // directory + {PWP_INSTFILES, IDD_INSTFILES, _T("instfiles")}, // instfiles #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT - {PWP_UNINST, IDD_UNINST, "uninstConfirm"}, // uninstConfirm + {PWP_UNINST, IDD_UNINST, _T("uninstConfirm")}, // uninstConfirm #else - {0, IDD_UNINST, "uninstConfirm"}, // uninstConfirm + {0, IDD_UNINST, _T("uninstConfirm")}, // uninstConfirm #endif {PWP_COMPLETED, -1, NULL} // completed }; @@ -1658,15 +1689,15 @@ int CEXEBuild::AddVersionInfo() { if ( !version_product_v[0] ) { - ERROR_MSG("Error: VIProductVersion is required when other version information functions are used.\n"); + ERROR_MSG(_T("Error: VIProductVersion is required when other version information functions are used.\n")); return PS_ERROR; } else { int imm, iml, ilm, ill; - if ( sscanf(version_product_v, "%d.%d.%d.%d", &imm, &iml, &ilm, &ill) != 4 ) + if ( _stscanf(version_product_v, _T("%d.%d.%d.%d"), &imm, &iml, &ilm, &ill) != 4 ) { - ERROR_MSG("Error: invalid VIProductVersion format, should be X.X.X.X\n"); + ERROR_MSG(_T("Error: invalid VIProductVersion format, should be X.X.X.X\n")); return PS_ERROR; } rVersionInfo.SetFileVersion(MAKELONG(iml, imm),MAKELONG(ill, ilm)); @@ -1680,21 +1711,21 @@ int CEXEBuild::AddVersionInfo() LANGID lang_id = rVersionInfo.GetLangID(i); int code_page = rVersionInfo.GetCodePage(i); - const char *lang_name = GetLangNameAndCP(lang_id); + const TCHAR *lang_name = GetLangNameAndCP(lang_id); - if ( !rVersionInfo.FindKey(lang_id, code_page, "FileVersion") ) - warning("Generating version information for language \"%04d-%s\" without standard key \"FileVersion\"", lang_id, lang_name); - if ( !rVersionInfo.FindKey(lang_id, code_page, "FileDescription") ) - warning("Generating version information for language \"%04d-%s\" without standard key \"FileDescription\"", lang_id, lang_name); - if ( !rVersionInfo.FindKey(lang_id, code_page, "LegalCopyright") ) - warning("Generating version information for language \"%04d-%s\" without standard key \"LegalCopyright\"", lang_id, lang_name); + if ( !rVersionInfo.FindKey(lang_id, code_page, _T("FileVersion")) ) + warning(_T("Generating version information for language \"%04d-%s\" without standard key \"FileVersion\""), lang_id, lang_name); + if ( !rVersionInfo.FindKey(lang_id, code_page, _T("FileDescription")) ) + warning(_T("Generating version information for language \"%04d-%s\" without standard key \"FileDescription\""), lang_id, lang_name); + if ( !rVersionInfo.FindKey(lang_id, code_page, _T("LegalCopyright")) ) + warning(_T("Generating version information for language \"%04d-%s\" without standard key \"LegalCopyright\""), lang_id, lang_name); rVersionInfo.ExportToStream(VerInfoStream, i); res_editor->UpdateResourceA(RT_VERSION, 1, lang_id, (BYTE*)VerInfoStream.get(), VerInfoStream.getlen()); } } catch (exception& err) { - ERROR_MSG("Error adding version information: %s\n", err.what()); + ERROR_MSG(_T("Error adding version information: %s\n"), err.what()); return PS_ERROR; } } @@ -1707,7 +1738,7 @@ int CEXEBuild::AddVersionInfo() #ifdef NSIS_CONFIG_VISIBLE_SUPPORT int CEXEBuild::ProcessPages() { - SCRIPT_MSG("Processing pages... "); + SCRIPT_MSG(_T("Processing pages... ")); int license_normal=0; int license_fsrb=0; @@ -1942,7 +1973,7 @@ again: if (!p->parms[3]) p->parms[3] = DefineInnerLangString(LS(NLF_DIR_BROWSETEXT, NLF_UDIR_BROWSETEXT)); if (!p->parms[4]) - p->parms[4] = m_UserVarNames.get("INSTDIR"); + p->parms[4] = m_UserVarNames.get(_T("INSTDIR")); else p->parms[4]--; @@ -1979,7 +2010,7 @@ again: if (!p->parms[1]) p->parms[1] = DefineInnerLangString(NLF_UNINST_SUBTEXT); if (!p->parms[4]) - p->parms[4] = m_UserVarNames.get("INSTDIR"); + p->parms[4] = m_UserVarNames.get(_T("INSTDIR")); else p->parms[4]--; @@ -2011,7 +2042,7 @@ again: } if (!instlog_used) { - warning("%sage instfiles not used, no sections will be executed!", uninstall_mode ? "Uninstall p" : "P"); + warning(_T("%sage instfiles not used, no sections will be executed!"), uninstall_mode ? _T("Uninstall p") : _T("P")); } } } @@ -2026,7 +2057,7 @@ again: #endif//NSIS_CONFIG_UNINSTALL_SUPPORT - SCRIPT_MSG("Done!\n"); + SCRIPT_MSG(_T("Done!\n")); #define REMOVE_ICON(id) if (disable_window_icon) { \ BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \ @@ -2054,7 +2085,7 @@ again: } try { - SCRIPT_MSG("Removing unused resources... "); + SCRIPT_MSG(_T("Removing unused resources... ")); init_res_editor(); #ifdef NSIS_CONFIG_LICENSEPAGE if (!license_normal) { @@ -2097,10 +2128,10 @@ again: res_editor->UpdateResourceA(RT_DIALOG, IDD_VERIFY, NSIS_DEFAULT_LANG, 0, 0); } - SCRIPT_MSG("Done!\n"); + SCRIPT_MSG(_T("Done!\n")); } catch (exception& err) { - ERROR_MSG("\nError: %s\n", err.what()); + ERROR_MSG(_T("\nError: %s\n"), err.what()); return PS_ERROR; } @@ -2149,12 +2180,12 @@ void CEXEBuild::AddStandardStrings() #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT if (uninstall_mode) { - cur_header->str_uninstchild = add_string("$TEMP\\$1u_.exe"); - cur_header->str_uninstcmd = add_string("\"$TEMP\\$1u_.exe\" $0 _?=$INSTDIR\\"); + cur_header->str_uninstchild = add_string(_T("$TEMP\\$1u_.exe")); + cur_header->str_uninstcmd = add_string(_T("\"$TEMP\\$1u_.exe\" $0 _?=$INSTDIR\\")); } #endif//NSIS_CONFIG_UNINSTALL_SUPPORT #ifdef NSIS_SUPPORT_MOVEONREBOOT - cur_header->str_wininit = add_string("$WINDIR\\wininit.ini"); + cur_header->str_wininit = add_string(_T("$WINDIR\\wininit.ini")); #endif//NSIS_SUPPORT_MOVEONREBOOT } @@ -2212,12 +2243,12 @@ int CEXEBuild::SetVarsSection() // -1 because the default size is 1 if (!res_editor->AddExtraVirtualSize2PESection(NSIS_VARS_SECTION, (MaxUserVars - 1) * sizeof(NSIS_STRING))) { - ERROR_MSG("Internal compiler error #12346: invalid exehead cannot find section \"%s\"!\n", NSIS_VARS_SECTION); + ERROR_MSG(_T("Internal compiler error #12346: invalid exehead cannot find section \"%s\"!\n"), _T(NSIS_VARS_SECTION)); return PS_ERROR; } } catch (exception& err) { - ERROR_MSG("\nError: %s\n", err.what()); + ERROR_MSG(_T("\nError: %s\n"), err.what()); return PS_ERROR; } @@ -2228,7 +2259,7 @@ int CEXEBuild::SetManifest() { try { init_res_editor(); - + // This should stay ANSI string manifest = manifest::generate(manifest_comctl, manifest_exec_level); if (manifest == "") @@ -2237,7 +2268,7 @@ int CEXEBuild::SetManifest() res_editor->UpdateResourceA(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), NSIS_DEFAULT_LANG, (LPBYTE) manifest.c_str(), manifest.length()); } catch (exception& err) { - ERROR_MSG("Error setting manifest: %s\n", err.what()); + ERROR_MSG(_T("Error setting manifest: %s\n"), err.what()); return PS_ERROR; } @@ -2254,7 +2285,7 @@ int CEXEBuild::UpdatePEHeader() // terminal services aware headers->OptionalHeader.DllCharacteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE; } catch (std::runtime_error& err) { - ERROR_MSG("Error updating PE headers: %s\n", err.what()); + ERROR_MSG(_T("Error updating PE headers: %s\n"), err.what()); return PS_ERROR; } @@ -2265,50 +2296,50 @@ int CEXEBuild::check_write_output_errors() const { if (has_called_write_output) { - ERROR_MSG("Error (write_output): write_output already called, can't continue\n"); + ERROR_MSG(_T("Error (write_output): write_output already called, can't continue\n")); return PS_ERROR; } if (!build_output_filename[0]) { - ERROR_MSG("Error: invalid script: never had OutFile command\n"); + ERROR_MSG(_T("Error: invalid script: never had OutFile command\n")); return PS_ERROR; } if (!build_sections.getlen()) { - ERROR_MSG("Error: invalid script: no sections specified\n"); + ERROR_MSG(_T("Error: invalid script: no sections specified\n")); return PS_ERROR; } if (!build_entries.getlen()) { - ERROR_MSG("Error: invalid script: no entries specified\n"); + ERROR_MSG(_T("Error: invalid script: no entries specified\n")); return PS_ERROR; } if (build_cursection) { - ERROR_MSG("Error: Section left open at EOF\n"); + ERROR_MSG(_T("Error: Section left open at EOF\n")); return PS_ERROR; } if (sectiongroup_open_cnt) { - ERROR_MSG("Error: SectionGroup left open at EOF\n"); + ERROR_MSG(_T("Error: SectionGroup left open at EOF\n")); return PS_ERROR; } if (cur_page) { - ERROR_MSG("Error: PageEx left open at EOF\n"); + ERROR_MSG(_T("Error: PageEx left open at EOF\n")); return PS_ERROR; } // deal with functions, for both install and uninstall modes. if (build_cursection_isfunc) { - ERROR_MSG("Error: Function left open at EOF\n"); + ERROR_MSG(_T("Error: Function left open at EOF\n")); return PS_ERROR; } @@ -2321,7 +2352,7 @@ int CEXEBuild::prepare_uninstaller() { { if (!uninstaller_writes_used) { - warning("Uninstaller script code found but WriteUninstaller never used - no uninstaller will be created."); + warning(_T("Uninstaller script code found but WriteUninstaller never used - no uninstaller will be created.")); return PS_OK; } @@ -2331,7 +2362,7 @@ int CEXEBuild::prepare_uninstaller() { DefineInnerLangString(NLF_UCAPTION); - if (resolve_coderefs("uninstall")) + if (resolve_coderefs(_T("uninstall"))) return PS_ERROR; #ifdef NSIS_CONFIG_COMPONENTPAGE @@ -2346,7 +2377,7 @@ int CEXEBuild::prepare_uninstaller() { } else if (uninstaller_writes_used) { - ERROR_MSG("Error: no Uninstall section specified, but WriteUninstaller used %d time(s)\n",uninstaller_writes_used); + ERROR_MSG(_T("Error: no Uninstall section specified, but WriteUninstaller used %d time(s)\n"),uninstaller_writes_used); return PS_ERROR; } #endif//NSIS_CONFIG_UNINSTALL_SUPPORT @@ -2362,27 +2393,27 @@ int CEXEBuild::pack_exe_header() // write out exe header, pack, read back in, and // update the header info - FILE *tmpfile=FOPEN(build_packname,"wb"); + FILE *tmpfile=FOPEN(build_packname,_T("wb")); if (!tmpfile) { - ERROR_MSG("Error: writing temporary file \"%s\" for pack\n",build_packname); + ERROR_MSG(_T("Error: writing temporary file \"%s\" for pack\n"),build_packname); return PS_ERROR; } fwrite(m_exehead,1,m_exehead_size,tmpfile); fclose(tmpfile); if (sane_system(build_packcmd) == -1) { - remove(build_packname); - ERROR_MSG("Error: calling packer on \"%s\"\n",build_packname); + _tremove(build_packname); + ERROR_MSG(_T("Error: calling packer on \"%s\"\n"),build_packname); return PS_ERROR; } int result = update_exehead(build_packname); - remove(build_packname); + _tremove(build_packname); if (result != PS_OK) { - ERROR_MSG("Error: reading temporary file \"%s\" after pack\n",build_packname); + ERROR_MSG(_T("Error: reading temporary file \"%s\" after pack\n"),build_packname); return result; } @@ -2410,7 +2441,7 @@ int CEXEBuild::write_output(void) RET_UNLESS_OK( prepare_uninstaller() ); DefineInnerLangString(NLF_CAPTION); - if (resolve_coderefs("install")) + if (resolve_coderefs(_T("install"))) return PS_ERROR; #ifdef NSIS_CONFIG_COMPONENTPAGE @@ -2449,7 +2480,7 @@ int CEXEBuild::write_output(void) close_res_editor(); } catch (exception& err) { - ERROR_MSG("\nError: %s\n", err.what()); + ERROR_MSG(_T("\nError: %s\n"), err.what()); return PS_ERROR; } @@ -2468,21 +2499,21 @@ int CEXEBuild::write_output(void) crc32_t crc=0; { - string full_path = get_full_path(build_output_filename); + tstring full_path = get_full_path(build_output_filename); notify(MAKENSIS_NOTIFY_OUTPUT, full_path.c_str()); - INFO_MSG("\nOutput: \"%s\"\n", full_path.c_str()); + INFO_MSG(_T("\nOutput: \"%s\"\n"), full_path.c_str()); } - FILE *fp = FOPEN(build_output_filename,"w+b"); + FILE *fp = FOPEN(build_output_filename,_T("w+b")); if (!fp) { - ERROR_MSG("Can't open output file\n"); + ERROR_MSG(_T("Can't open output file\n")); return PS_ERROR; } if (fwrite(m_exehead,1,m_exehead_size,fp) != m_exehead_size) { - ERROR_MSG("Error: can't write %d bytes to output\n",m_exehead_size); + ERROR_MSG(_T("Error: can't write %d bytes to output\n"),m_exehead_size); fclose(fp); return PS_ERROR; } @@ -2519,7 +2550,7 @@ int CEXEBuild::write_output(void) int n = compressor->Init(build_compress_level, build_compress_dict_size); if (n != C_OK) { - ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%s [%d]).\n", compressor->GetErrStr(n), n); + ERROR_MSG(_T("Internal compiler error #12345: deflateInit() failed(%s [%d]).\n"), compressor->GetErrStr(n), n); return PS_ERROR; } } @@ -2552,7 +2583,7 @@ int CEXEBuild::write_output(void) } catch (...) { - ERROR_MSG("Error: can't write %d bytes to output\n",sizeof(fh)); + ERROR_MSG(_T("Error: can't write %d bytes to output\n"),sizeof(fh)); fclose(fp); return PS_ERROR; } @@ -2570,7 +2601,7 @@ int CEXEBuild::write_output(void) { if (fwrite(ihd.get(),1,ihd.getlen(),fp) != (unsigned int)ihd.getlen()) { - ERROR_MSG("Error: can't write %d bytes to output\n",ihd.getlen()); + ERROR_MSG(_T("Error: can't write %d bytes to output\n"),ihd.getlen()); fclose(fp); return PS_ERROR; } @@ -2584,10 +2615,10 @@ int CEXEBuild::write_output(void) } } - INFO_MSG("Install: "); + INFO_MSG(_T("Install: ")); #ifdef NSIS_CONFIG_VISIBLE_SUPPORT int np=build_header.blocks[NB_PAGES].num; - INFO_MSG("%d page%s (%d bytes), ",np,np==1?"":"s",np*sizeof(page)); + INFO_MSG(_T("%d page%s (%d bytes), "),np,np==1?_T(""):_T("s"),np*sizeof(page)); #endif { int ns=build_sections.getlen()/sizeof(section); @@ -2598,25 +2629,25 @@ int CEXEBuild::write_output(void) { if (!s[x].name_ptr || s[x].flags & SF_RO) req++; } - INFO_MSG("%d section%s",ns,ns==1?"":"s"); + INFO_MSG(_T("%d section%s"),ns,ns==1?_T(""):_T("s")); if (req) { - INFO_MSG(" (%d required)",req); + INFO_MSG(_T(" (%d required)"),req); } - INFO_MSG(" (%d bytes), ", build_sections.getlen()); + INFO_MSG(_T(" (%d bytes), "), build_sections.getlen()); } int ne=build_header.blocks[NB_ENTRIES].num; - INFO_MSG("%d instruction%s (%d bytes), ",ne,ne==1?"":"s",ne*sizeof(entry)); + INFO_MSG(_T("%d instruction%s (%d bytes), "),ne,ne==1?_T(""):_T("s"),ne*sizeof(entry)); int ns=build_strlist.getnum(); - INFO_MSG("%d string%s (%d bytes), ",ns,ns==1?"":"s",build_strlist.getlen()); + INFO_MSG(_T("%d string%s (%d bytes), "),ns,ns==1?_T(""):_T("s"),build_strlist.getlen()); int nlt=build_header.blocks[NB_LANGTABLES].num; - INFO_MSG("%d language table%s (%d bytes).\n",nlt,nlt==1?"":"s",build_langtables.getlen()); + INFO_MSG(_T("%d language table%s (%d bytes).\n"),nlt,nlt==1?_T(""):_T("s"),build_langtables.getlen()); if (ubuild_entries.getlen()) { - INFO_MSG("Uninstall: "); + INFO_MSG(_T("Uninstall: ")); #ifdef NSIS_CONFIG_VISIBLE_SUPPORT np=build_uninst.blocks[NB_PAGES].num; - INFO_MSG("%d page%s (%d bytes), \n",np,np==1?"":"s",ubuild_pages.getlen()); + INFO_MSG(_T("%d page%s (%d bytes), \n"),np,np==1?_T(""):_T("s"),ubuild_pages.getlen()); #endif { int ns=ubuild_sections.getlen()/sizeof(section); @@ -2627,19 +2658,19 @@ int CEXEBuild::write_output(void) { if (!s[x].name_ptr || s[x].flags & SF_RO) req++; } - INFO_MSG("%d section%s",ns,ns==1?"":"s"); + INFO_MSG(_T("%d section%s"),ns,ns==1?_T(""):_T("s")); if (req) { - INFO_MSG(" (%d required)",req); + INFO_MSG(_T(" (%d required)"),req); } - INFO_MSG(" (%d bytes), ", ubuild_sections.getlen()); + INFO_MSG(_T(" (%d bytes), "), ubuild_sections.getlen()); } ne=build_uninst.blocks[NB_ENTRIES].num; - INFO_MSG("%d instruction%s (%d bytes), ",ne,ne==1?"":"s",ubuild_entries.getlen()); + INFO_MSG(_T("%d instruction%s (%d bytes), "),ne,ne==1?_T(""):_T("s"),ubuild_entries.getlen()); ns=ubuild_strlist.getnum(); - INFO_MSG("%d string%s (%d bytes), ",ns,ns==1?"":"s",ubuild_strlist.getlen()); + INFO_MSG(_T("%d string%s (%d bytes), "),ns,ns==1?_T(""):_T("s"),ubuild_strlist.getlen()); nlt=build_uninst.blocks[NB_LANGTABLES].num; - INFO_MSG("%d language table%s (%d bytes).\n",nlt,nlt==1?"":"s",ubuild_langtables.getlen()); + INFO_MSG(_T("%d language table%s (%d bytes).\n"),nlt,nlt==1?_T(""):_T("s"),ubuild_langtables.getlen()); } @@ -2648,24 +2679,24 @@ int CEXEBuild::write_output(void) int total_out_size_estimate= m_exehead_size+sizeof(fh)+build_datablock.getlen()+(build_crcchk?sizeof(crc32_t):0); int pc=(int)(((INT64)db_opt_save*1000)/(db_opt_save+total_out_size_estimate)); - INFO_MSG("Datablock optimizer saved %d bytes (~%d.%d%%).\n",db_opt_save, + INFO_MSG(_T("Datablock optimizer saved %d bytes (~%d.%d%%).\n"),db_opt_save, pc/10,pc%10); } #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT - INFO_MSG("\nUsing %s%s compression.\n\n", compressor->GetName(), build_compress_whole?" (compress whole)":""); + INFO_MSG(_T("\nUsing %s%s compression.\n\n"), compressor->GetName(), build_compress_whole?_T(" (compress whole)"):_T("")); #endif unsigned int total_usize=m_exehead_original_size; - INFO_MSG("EXE header size: %10d / %d bytes\n",m_exehead_size,m_exehead_original_size); + INFO_MSG(_T("EXE header size: %10d / %d bytes\n"),m_exehead_size,m_exehead_original_size); if (build_compress_whole) { - INFO_MSG("Install code: (%d bytes)\n", + INFO_MSG(_T("Install code: (%d bytes)\n"), sizeof(fh)+fh.length_of_header); } else { - INFO_MSG("Install code: %10d / %d bytes\n", + INFO_MSG(_T("Install code: %10d / %d bytes\n"), sizeof(fh)+installinfo_compressed, sizeof(fh)+fh.length_of_header); } @@ -2679,11 +2710,11 @@ int CEXEBuild::write_output(void) if (build_compress_whole) { dbsizeu=dbsize; - INFO_MSG("Install data: (%d bytes)\n",dbsizeu); + INFO_MSG(_T("Install data: (%d bytes)\n"),dbsizeu); } else { dbsizeu = db_full_size - uninstall_size_full; - INFO_MSG("Install data: %10d / %d bytes\n",dbsize,dbsizeu); + INFO_MSG(_T("Install data: %10d / %d bytes\n"),dbsize,dbsizeu); } total_usize+=dbsizeu; } @@ -2691,14 +2722,14 @@ int CEXEBuild::write_output(void) if (uninstall_size>=0) { if (build_compress_whole) - INFO_MSG("Uninstall code+data: (%d bytes)\n",uninstall_size_full); + INFO_MSG(_T("Uninstall code+data: (%d bytes)\n"),uninstall_size_full); else - INFO_MSG("Uninstall code+data: %6d / %d bytes\n",uninstall_size,uninstall_size_full); + INFO_MSG(_T("Uninstall code+data: %6d / %d bytes\n"),uninstall_size,uninstall_size_full); total_usize+=uninstall_size_full; } if (build_compress_whole) { - INFO_MSG("Compressed data: "); + INFO_MSG(_T("Compressed data: ")); } if (build_datablock.getlen()) @@ -2727,7 +2758,7 @@ int CEXEBuild::write_output(void) #endif if ((int)fwrite(dbptr,1,l,fp) != l) { - ERROR_MSG("Error: can't write %d bytes to output\n",l); + ERROR_MSG(_T("Error: can't write %d bytes to output\n"),l); fclose(fp); return PS_ERROR; } @@ -2753,7 +2784,7 @@ int CEXEBuild::write_output(void) fh.length_of_all_following_data=ftell(fp)-fd_start+(build_crcchk?sizeof(crc32_t):0); INFO_MSG( - "%10d / %d bytes\n", + _T("%10d / %d bytes\n"), ftell(fp) - fd_start, data_block_size_before_uninst + fh.length_of_header + sizeof(firstheader) + uninstall_size_full ); @@ -2768,7 +2799,7 @@ int CEXEBuild::write_output(void) } catch (...) { - ERROR_MSG("Error: can't write %d bytes to output\n",sizeof(fh)); + ERROR_MSG(_T("Error: can't write %d bytes to output\n"),sizeof(fh)); fclose(fp); return PS_ERROR; } @@ -2797,16 +2828,16 @@ int CEXEBuild::write_output(void) int rcrc = FIX_ENDIAN_INT32(crc); if (fwrite(&rcrc,1,sizeof(crc32_t),fp) != sizeof(crc32_t)) { - ERROR_MSG("Error: can't write %d bytes to output\n",sizeof(crc32_t)); + ERROR_MSG(_T("Error: can't write %d bytes to output\n"),sizeof(crc32_t)); fclose(fp); return PS_ERROR; } - INFO_MSG("CRC (0x%08X): 4 / 4 bytes\n",crc); + INFO_MSG(_T("CRC (0x%08X): 4 / 4 bytes\n"),crc); } - INFO_MSG("\n"); + INFO_MSG(_T("\n")); { UINT pc=(UINT)(((UINT64)ftell(fp)*1000)/(total_usize)); - INFO_MSG("Total size: %10u / %u bytes (%u.%u%%)\n", + INFO_MSG(_T("Total size: %10u / %u bytes (%u.%u%%)\n"), ftell(fp),total_usize,pc/10,pc%10); } fclose(fp); @@ -2834,7 +2865,7 @@ int CEXEBuild::deflateToFile(FILE *fp, char *buf, int len) // len==0 to flush int ret=compressor->Compress(flush); if (ret<0 && (ret!=-1 || !flush)) { - ERROR_MSG("Error: deflateToFile: deflate() failed(%s [%d])\n", compressor->GetErrStr(ret), ret); + ERROR_MSG(_T("Error: deflateToFile: deflate() failed(%s [%d])\n"), compressor->GetErrStr(ret), ret); return 1; } int l=compressor->GetNextOut()-obuf; @@ -2842,7 +2873,7 @@ int CEXEBuild::deflateToFile(FILE *fp, char *buf, int len) // len==0 to flush { if (fwrite(obuf,1,l,fp) != (unsigned)l) { - ERROR_MSG("Error: deflateToFile fwrite(%d) failed\n",l); + ERROR_MSG(_T("Error: deflateToFile fwrite(%d) failed\n"),l); return 1; } fflush(fp); @@ -2858,7 +2889,7 @@ int CEXEBuild::uninstall_generate() #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT if (ubuild_entries.getlen() && uninstaller_writes_used) { - SCRIPT_MSG("Generating uninstaller... "); + SCRIPT_MSG(_T("Generating uninstaller... ")); firstheader fh={0,}; @@ -2979,7 +3010,7 @@ int CEXEBuild::uninstall_generate() int n = compressor->Init(build_compress_level, build_compress_dict_size); if (n != C_OK) { - ERROR_MSG("Internal compiler error #12345: deflateInit() failed(%s [%d]).\n", compressor->GetErrStr(n), n); + ERROR_MSG(_T("Internal compiler error #12345: deflateInit() failed(%s [%d]).\n"), compressor->GetErrStr(n), n); extern void quit(); quit(); } @@ -3087,7 +3118,7 @@ int CEXEBuild::uninstall_generate() // compressed size uninstall_size=build_datablock.getlen()-uninstdata_offset; - SCRIPT_MSG("Done!\n"); + SCRIPT_MSG(_T("Done!\n")); } #endif return PS_OK; @@ -3115,7 +3146,7 @@ void CEXEBuild::set_uninstall_mode(int un) cur_langtables=&ubuild_langtables; cur_ctlcolors=&ubuild_ctlcolors; - definedlist.add("__UNINSTALL__"); + definedlist.add(_T("__UNINSTALL__")); } else { @@ -3132,7 +3163,7 @@ void CEXEBuild::set_uninstall_mode(int un) cur_langtables=&build_langtables; cur_ctlcolors=&build_ctlcolors; - definedlist.del("__UNINSTALL__"); + definedlist.del(_T("__UNINSTALL__")); } SWAP(db_opt_save_u,db_opt_save,int); @@ -3143,88 +3174,97 @@ void CEXEBuild::set_uninstall_mode(int un) extern FILE *g_output; -void CEXEBuild::warning(const char *s, ...) +/* Useful for debugging. +bool IsStringASCII(const TCHAR* s) { - char buf[NSIS_MAX_STRLEN*10]; + while (*s) { if (!_istascii(*s++)) return false; } + return true; +} +*/ + +void CEXEBuild::warning(const TCHAR *s, ...) +{ + TCHAR buf[NSIS_MAX_STRLEN*10]; va_list val; va_start(val,s); #ifdef _WIN32 - vsprintf(buf,s,val); + _vstprintf(buf,s,val); #else - vsnprintf(buf,NSIS_MAX_STRLEN*10,s,val); + _vsntprintf(buf,NSIS_MAX_STRLEN*10,s,val); #endif va_end(val); m_warnings.add(buf,0); notify(MAKENSIS_NOTIFY_WARNING,buf); if (display_warnings) { - fprintf(g_output,"warning: %s\n",buf); + _ftprintf(g_output,_T("warning: %s\n"),buf); fflush(g_output); } } -void CEXEBuild::warning_fl(const char *s, ...) +void CEXEBuild::warning_fl(const TCHAR *s, ...) { - char buf[NSIS_MAX_STRLEN*10]; + TCHAR buf[NSIS_MAX_STRLEN*10]; va_list val; va_start(val,s); #ifdef _WIN32 - vsprintf(buf,s,val); + _vstprintf(buf,s,val); #else - vsnprintf(buf,NSIS_MAX_STRLEN*10,s,val); + _vsntprintf(buf,NSIS_MAX_STRLEN*10,s,val); #endif va_end(val); - sprintf(buf+strlen(buf)," (%s:%d)",curfilename,linecnt); + _stprintf(buf+_tcsclen(buf),_T(" (%s:%d)"),curfilename,linecnt); + m_warnings.add(buf,0); notify(MAKENSIS_NOTIFY_WARNING,buf); if (display_warnings) { - fprintf(g_output,"warning: %s\n",buf); + _ftprintf(g_output,_T("warning: %s\n"),buf); fflush(g_output); } } -void CEXEBuild::ERROR_MSG(const char *s, ...) const +void CEXEBuild::ERROR_MSG(const TCHAR *s, ...) const { if (display_errors || notify_hwnd) { - char buf[NSIS_MAX_STRLEN*10]; + TCHAR buf[NSIS_MAX_STRLEN*10]; va_list val; va_start(val,s); #ifdef _WIN32 - vsprintf(buf,s,val); + _vstprintf(buf,s,val); #else - vsnprintf(buf,NSIS_MAX_STRLEN*10,s,val); + _vsntprintf(buf,NSIS_MAX_STRLEN*10,s,val); #endif va_end(val); notify(MAKENSIS_NOTIFY_ERROR,buf); if (display_errors) { - fprintf(g_output,"%s",buf); + _ftprintf(g_output,_T("%s"),buf); fflush(g_output); } } } -void CEXEBuild::SCRIPT_MSG(const char *s, ...) const +void CEXEBuild::SCRIPT_MSG(const TCHAR *s, ...) const { if (display_script) { va_list val; va_start(val,s); - vfprintf(g_output,s,val); + _vftprintf(g_output,s,val); va_end(val); fflush(g_output); } } -void CEXEBuild::INFO_MSG(const char *s, ...) const +void CEXEBuild::INFO_MSG(const TCHAR *s, ...) const { if (display_info) { va_list val; va_start(val,s); - vfprintf(g_output,s,val); + _vftprintf(g_output,s,val); va_end(val); fflush(g_output); } @@ -3234,23 +3274,23 @@ void CEXEBuild::print_warnings() { int nw=0,x=m_warnings.getlen(); if (!x || !display_warnings) return; - char *p=m_warnings.get(); + TCHAR *p=m_warnings.get(); while (x>0) if (!p[--x]) nw++; - fprintf(g_output,"\n%d warning%s:\n",nw,nw==1?"":"s"); + _ftprintf(g_output,_T("\n%d warning%s:\n"),nw,nw==1?_T(""):_T("s")); for (x = 0; x < nw; x ++) { - fprintf(g_output," %s\n",p); - p+=strlen(p)+1; + _ftprintf(g_output,_T(" %s\n"),p); + p+=_tcsclen(p)+1; } fflush(g_output); } -void CEXEBuild::notify(notify_e code, const char *data) const +void CEXEBuild::notify(notify_e code, const TCHAR *data) const { #ifdef _WIN32 if (notify_hwnd) { - COPYDATASTRUCT cds = {(DWORD)code, strlen(data)+1, (void *) data}; + COPYDATASTRUCT cds = {(DWORD)code, (_tcsclen(data)+1)*sizeof(TCHAR), (void *) data}; SendMessage(notify_hwnd, WM_COPYDATA, 0, (LPARAM)&cds); } #endif @@ -3266,11 +3306,11 @@ void CEXEBuild::build_plugin_table(void) plugin_used = false; uninst_plugin_used = false; - string searchPath = definedlist.find("NSISDIR"); - searchPath += PLATFORM_PATH_SEPARATOR_STR"Plugins"; - INFO_MSG("Processing plugin dlls: \"%s" PLATFORM_PATH_SEPARATOR_STR "*.dll\"\n",searchPath.c_str()); + tstring searchPath = definedlist.find(_T("NSISDIR")); + searchPath += PLATFORM_PATH_SEPARATOR_STR _T("Plugins"); + INFO_MSG(_T("Processing plugin dlls: \"%s") PLATFORM_PATH_SEPARATOR_STR _T("*.dll\"\n"),searchPath.c_str()); m_plugins.FindCommands(searchPath, display_info?true:false); - INFO_MSG("\n"); + INFO_MSG(_T("\n")); } #define FLAG_OFFSET(flag) (FIELD_OFFSET(exec_flags_t, flag)/sizeof(int)) @@ -3279,7 +3319,7 @@ int CEXEBuild::add_plugins_dir_initializer(void) { if (!plugin_used && !uninst_plugin_used) return PS_OK; - SCRIPT_MSG("Adding plug-ins initializing function... "); + SCRIPT_MSG(_T("Adding plug-ins initializing function... ")); bool uninstall = !plugin_used; @@ -3287,22 +3327,22 @@ int CEXEBuild::add_plugins_dir_initializer(void) int zero_offset; int var_zero; - var_zero=m_UserVarNames.get("0"); + var_zero=m_UserVarNames.get(_T("0")); again: // Function [un.]Initialize_____Plugins - ret=add_function(uninstall?"un.Initialize_____Plugins":"Initialize_____Plugins"); + ret=add_function(uninstall?_T("un.Initialize_____Plugins"):_T("Initialize_____Plugins")); if (ret != PS_OK) return ret; // don't move this, depends on [un.] - zero_offset=add_string("$0"); + zero_offset=add_string(_T("$0")); // SetDetailsPrint none ret=add_entry_direct(EW_SETFLAG, FLAG_OFFSET(status_update), add_intstring(6)); if (ret != PS_OK) return ret; // StrCmp $PLUGINSDIR "" - ret=add_entry_direct(EW_STRCMP, add_string("$PLUGINSDIR"), 0, 0, ns_label.add("Initialize_____Plugins_done",0)); + ret=add_entry_direct(EW_STRCMP, add_string(_T("$PLUGINSDIR")), 0, 0, ns_label.add(_T("Initialize_____Plugins_done"),0)); if (ret != PS_OK) return ret; // Push $0 ret=add_entry_direct(EW_PUSHPOP, zero_offset); @@ -3311,7 +3351,7 @@ again: ret=add_entry_direct(EW_SETFLAG, FLAG_OFFSET(exec_error)); if (ret != PS_OK) return ret; // GetTempFileName $0 - ret=add_entry_direct(EW_GETTEMPFILENAME, var_zero, add_string("$TEMP")); + ret=add_entry_direct(EW_GETTEMPFILENAME, var_zero, add_string(_T("$TEMP"))); if (ret != PS_OK) return ret; // Delete $0 [simple, nothing that could clash with special temp permissions] ret=add_entry_direct(EW_DELETEFILE, zero_offset, DEL_SIMPLE); @@ -3320,25 +3360,25 @@ again: ret=add_entry_direct(EW_CREATEDIR, zero_offset); if (ret != PS_OK) return ret; // IfErrors Initialize_____Plugins_error - detect errors - ret=add_entry_direct(EW_IFFLAG, ns_label.add("Initialize_____Plugins_error",0), 0, FLAG_OFFSET(exec_error)); + ret=add_entry_direct(EW_IFFLAG, ns_label.add(_T("Initialize_____Plugins_error"),0), 0, FLAG_OFFSET(exec_error)); if (ret != PS_OK) return ret; // Copy $0 to $PLUGINSDIR - ret=add_entry_direct(EW_ASSIGNVAR, m_UserVarNames.get("PLUGINSDIR"), zero_offset); + ret=add_entry_direct(EW_ASSIGNVAR, m_UserVarNames.get(_T("PLUGINSDIR")), zero_offset); if (ret != PS_OK) return ret; // Pop $0 ret=add_entry_direct(EW_PUSHPOP, var_zero, 1); if (ret != PS_OK) return ret; // done - if (add_label("Initialize_____Plugins_done")) return PS_ERROR; + if (add_label(_T("Initialize_____Plugins_done"))) return PS_ERROR; // Return ret=add_entry_direct(EW_RET); if (ret != PS_OK) return ret; // error - if (add_label("Initialize_____Plugins_error")) return PS_ERROR; + if (add_label(_T("Initialize_____Plugins_error"))) return PS_ERROR; // error message box - ret=add_entry_direct(EW_MESSAGEBOX, MB_OK|MB_ICONSTOP|(IDOK<<21), add_string("Error! Can't initialize plug-ins directory. Please try again later.")); + ret=add_entry_direct(EW_MESSAGEBOX, MB_OK|MB_ICONSTOP|(IDOK<<21), add_string(_T("Error! Can't initialize plug-ins directory. Please try again later."))); if (ret != PS_OK) return ret; // Quit ret=add_entry_direct(EW_QUIT); @@ -3353,7 +3393,7 @@ again: goto again; } - SCRIPT_MSG("Done!\n"); + SCRIPT_MSG(_T("Done!\n")); return PS_OK; } @@ -3388,31 +3428,31 @@ void CEXEBuild::close_res_editor() res_editor=0; } -int CEXEBuild::DeclaredUserVar(const char *szVarName) +int CEXEBuild::DeclaredUserVar(const TCHAR *szVarName) { - if (m_ShellConstants.get((char*)szVarName) >= 0) + if (m_ShellConstants.get((TCHAR*)szVarName) >= 0) { - ERROR_MSG("Error: name \"%s\" in use by constant\n", szVarName); + ERROR_MSG(_T("Error: name \"%s\" in use by constant\n"), szVarName); return PS_ERROR; } - int idxUserVar = m_UserVarNames.get((char*)szVarName); + int idxUserVar = m_UserVarNames.get((TCHAR*)szVarName); if (idxUserVar >= 0) { - ERROR_MSG("Error: variable \"%s\" already declared\n", szVarName); + ERROR_MSG(_T("Error: variable \"%s\" already declared\n"), szVarName); return PS_ERROR; } - const char *pVarName = szVarName; - int iVarLen = strlen(szVarName); + const TCHAR *pVarName = szVarName; + int iVarLen = _tcsclen(szVarName); if (iVarLen > 60) { - ERROR_MSG("Error: variable name too long!\n"); + ERROR_MSG(_T("Error: variable name too long!\n")); return PS_ERROR; } else if (!iVarLen) { - ERROR_MSG("Error: variable with empty name!\n"); + ERROR_MSG(_T("Error: variable with empty name!\n")); return PS_ERROR; } else @@ -3421,7 +3461,7 @@ int CEXEBuild::DeclaredUserVar(const char *szVarName) { if (!isSimpleChar(*pVarName)) { - ERROR_MSG("Error: invalid characters in variable name \"%s\", use only characters [a-z][A-Z][0-9] and '_'\n", szVarName); + ERROR_MSG(_T("Error: invalid characters in variable name \"%s\", use only characters [a-z][A-Z][0-9] and '_'\n"), szVarName); return PS_ERROR; } pVarName++; @@ -3431,7 +3471,7 @@ int CEXEBuild::DeclaredUserVar(const char *szVarName) m_UserVarNames.add(szVarName); if (m_UserVarNames.getnum() > MAX_CODED) { - ERROR_MSG("Error: too many user variables declared. Maximum allowed is %u.\n", MAX_CODED - m_iBaseVarsNum); + ERROR_MSG(_T("Error: too many user variables declared. Maximum allowed is %u.\n"), MAX_CODED - m_iBaseVarsNum); return PS_ERROR; } return PS_OK; @@ -3440,10 +3480,10 @@ int CEXEBuild::DeclaredUserVar(const char *szVarName) int CEXEBuild::GetUserVarIndex(LineParser &line, int token) { - char *p = line.gettoken_str(token); - if ( *p == '$' && *(p+1) ) + TCHAR *p = line.gettoken_str(token); + if ( *p == _T('$') && *(p+1) ) { - int idxUserVar = m_UserVarNames.get((char *)p+1); + int idxUserVar = m_UserVarNames.get((TCHAR *)p+1); if (idxUserVar >= 0 && m_UserVarNames.get_reference(idxUserVar) >= 0) { m_UserVarNames.inc_reference(idxUserVar); @@ -3451,10 +3491,10 @@ int CEXEBuild::GetUserVarIndex(LineParser &line, int token) } else { - int idxConst = m_ShellConstants.get((char *)p+1); + int idxConst = m_ShellConstants.get((TCHAR *)p+1); if (idxConst >= 0) { - ERROR_MSG("Error: cannot change constants : %s\n", p); + ERROR_MSG(_T("Error: cannot change constants : %s\n"), p); } } } @@ -3467,24 +3507,24 @@ void CEXEBuild::VerifyDeclaredUserVarRefs(UserVarsStringList *pVarsStringList) { if (!pVarsStringList->get_reference(i)) { - warning("Variable \"%s\" not referenced or never set, wasting memory!", pVarsStringList->idx2name(i)); + warning(_T("Variable \"%s\" not referenced or never set, wasting memory!"), pVarsStringList->idx2name(i)); } } } -int CEXEBuild::set_compressor(const string& compressor, const bool solid) { - string stub = stubs_dir + PLATFORM_PATH_SEPARATOR_STR + compressor; +int CEXEBuild::set_compressor(const tstring& compressor, const bool solid) { + tstring stub = stubs_dir + PLATFORM_PATH_SEPARATOR_STR + compressor; if (solid) - stub += "_solid"; + stub += _T("_solid"); return update_exehead(stub, &m_exehead_original_size); } -int CEXEBuild::update_exehead(const string& file, size_t *size/*=NULL*/) { - FILE *tmpfile = fopen(file.c_str(), "rb"); +int CEXEBuild::update_exehead(const tstring& file, size_t *size/*=NULL*/) { + FILE *tmpfile = _tfopen(file.c_str(), _T("rb")); if (!tmpfile) { - ERROR_MSG("Error: opening stub \"%s\"\n", file.c_str()); + ERROR_MSG(_T("Error: opening stub \"%s\"\n"), file.c_str()); return PS_ERROR; } @@ -3495,7 +3535,7 @@ int CEXEBuild::update_exehead(const string& file, size_t *size/*=NULL*/) { fseek(tmpfile, 0, SEEK_SET); if (fread(exehead, 1, exehead_size, tmpfile) != exehead_size) { - ERROR_MSG("Error: reading stub \"%s\"\n", file.c_str()); + ERROR_MSG(_T("Error: reading stub \"%s\"\n"), file.c_str()); fclose(tmpfile); delete [] exehead; return PS_ERROR; @@ -3528,26 +3568,26 @@ void CEXEBuild::update_exehead(const unsigned char *new_exehead, size_t new_size memset(m_exehead + new_size, 0, m_exehead_size - new_size); } -void CEXEBuild::set_code_type_predefines(const char *value) +void CEXEBuild::set_code_type_predefines(const TCHAR *value) { - definedlist.del("__SECTION__"); - definedlist.del("__FUNCTION__"); - definedlist.del("__PAGEEX__"); - definedlist.del("__GLOBAL__"); + definedlist.del(_T("__SECTION__")); + definedlist.del(_T("__FUNCTION__")); + definedlist.del(_T("__PAGEEX__")); + definedlist.del(_T("__GLOBAL__")); switch (GetCurrentTokenPlace()) { case TP_SEC: - definedlist.add("__SECTION__", value==NULL?"":value); + definedlist.add(_T("__SECTION__"), value==NULL?_T(""):value); break; case TP_FUNC: - definedlist.add("__FUNCTION__", value==NULL?"":value); + definedlist.add(_T("__FUNCTION__"), value==NULL?_T(""):value); break; case TP_PAGEEX: - definedlist.add("__PAGEEX__", value==NULL?"":value); + definedlist.add(_T("__PAGEEX__"), value==NULL?_T(""):value); break; default: - definedlist.add("__GLOBAL__"); + definedlist.add(_T("__GLOBAL__")); } } diff --git a/Source/build.h b/Source/build.h index 0dc0d2ea..26c109e0 100644 --- a/Source/build.h +++ b/Source/build.h @@ -1,421 +1,491 @@ -/* - * build.h - * - * This file is a part of NSIS. - * - * Copyright (C) 1999-2008 Nullsoft and Contributors - * - * Licensed under the zlib/libpng license (the "License"); - * you may not use this file except in compliance with the License. - * - * Licence details can be found in the file COPYING. - * - * This software is provided 'as-is', without any express or implied - * warranty. - */ - -#ifndef _BUILD_H_ -#define _BUILD_H_ - -#include "strlist.h" -#include "lineparse.h" -#include "lang.h" -#include "ResourceEditor.h" -#include "ResourceVersionInfo.h" -#include "uservars.h" -#include "ShConstants.h" -#include "mmap.h" -#include "manifest.h" -#include "icon.h" - -#include "exehead/fileform.h" -#include "exehead/config.h" - -#include -#include - -#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES -// Added by Sunil Kamath 11 June 2003 -# include -# include -#endif - -#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT -// Changed by Amir Szekely 31st July 2002 -#include "compressor.h" -#include "czlib.h" -#include "cbzip2.h" -#include "clzma.h" - -#endif//NSIS_CONFIG_COMPRESSION_SUPPORT - -#ifdef NSIS_CONFIG_PLUGIN_SUPPORT -# include "Plugins.h" -#endif //NSIS_CONFIG_PLUGIN_SUPPORT - -#define PS_OK 0 -#define PS_EOF 1 -#define PS_ERROR 50 -#define PS_WARNING 100 - -// token placement -#define TP_SEC 1 -#define TP_FUNC 2 -#define TP_CODE (TP_SEC | TP_FUNC) -#define TP_GLOBAL 4 -#define TP_PAGEEX 8 -#define TP_PG (TP_GLOBAL | TP_PAGEEX) -#define TP_ALL (TP_CODE | TP_PG) - -enum notify_e { - MAKENSIS_NOTIFY_SCRIPT, - MAKENSIS_NOTIFY_WARNING, - MAKENSIS_NOTIFY_ERROR, - MAKENSIS_NOTIFY_OUTPUT -}; - -#define PAGE_CUSTOM 0 -#define PAGE_LICENSE 1 -#define PAGE_COMPONENTS 2 -#define PAGE_DIRECTORY 3 -#define PAGE_INSTFILES 4 -#define PAGE_UNINSTCONFIRM 5 -#define PAGE_COMPLETED 6 - -class CEXEBuild { - public: - CEXEBuild(); - void initialize(const char *makensis_path); - ~CEXEBuild(); - - // to add a warning to the compiler's warning list. - void warning(const char *s, ...); - // warning with file name and line count - void warning_fl(const char *s, ...); - - // to add a defined thing. - void define(const char *p, const char *v=""); - -#ifdef NSIS_CONFIG_PLUGIN_SUPPORT - // Added by Ximon Eighteen 5th August 2002 - void build_plugin_table(void); - int plugins_processed; -#endif //NSIS_CONFIG_PLUGIN_SUPPORT - - - // process a script (you can process as many scripts as you want, - // it is as if they are concatenated) - int process_script(FILE *fp, const char *curfilename); - int process_oneline(char *line, const char *curfilename, int lineptr); - - // you only get to call write_output once, so use it wisely. - int write_output(void); - - void print_help(char *commandname=NULL); - - DefineList definedlist; - - int display_errors; - int display_script; - int display_warnings; - int display_info; - - int linecnt; - const char *curfilename; - FILE *fp; - - HWND notify_hwnd; - void notify(notify_e code, const char *data) const; - - private: - int check_write_output_errors() const; - int prepare_uninstaller(); - int pack_exe_header(); - - int set_compressor(const std::string& compressor, const bool solid); - int update_exehead(const std::string& file, size_t *size=NULL); - void update_exehead(const unsigned char *new_exehead, size_t new_size); - - // tokens.cpp - bool is_valid_token(char *s); - int get_commandtoken(char *s, int *np, int *op, int *pos); - int GetCurrentTokenPlace(); - int IsTokenPlacedRight(int pos, char *tok); - - // script.cpp -#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES - // Added by Sunil Kamath 11 June 2003 - char* set_file_predefine(const char *); - void restore_file_predefine(char *); - char* set_timestamp_predefine(const char *); - void restore_timestamp_predefine(char *); - char* set_line_predefine(int, BOOL); - void restore_line_predefine(char *); - void set_date_time_predefines(); - void del_date_time_predefines(); -#endif - int parseScript(); - int includeScript(char *f); - int MacroExists(const char *macroname); -#ifdef NSIS_FIX_DEFINES_IN_STRINGS - void ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist, bool bIgnoreDefines = false); -#else - void ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist); -#endif - int doParse(const char *str); - int doCommand(int which_token, LineParser &line); - - int do_add_file(const char *lgss, int attrib, int recurse, int *total_files, const char - *name_override=0, int generatecode=1, int *data_handle=0, - const std::set& excluded=std::set(), - const std::string& basedir=std::string(""), bool dir_created=false); - int add_file(const std::string& dir, const std::string& file, int attrib, const char - *name_override, int generatecode, int *data_handle); - int do_add_file_create_dir(const std::string& local_dir, const std::string& dir, int attrib=0); - - GrowBuf m_linebuild; // used for concatenating lines - - // used by doParse to do preprocessing - struct ifblock - { - int hasexeced; - int elseused; - int ignore; - int inherited_ignore; - } *cur_ifblock; - - TinyGrowBuf build_preprocessor_data; - - void start_ifblock(); - void end_ifblock(); - int num_ifblock(); - - int last_line_had_slash; - bool inside_comment; - int multiple_entries_instruction; - - void ERROR_MSG(const char *s, ...) const; - void SCRIPT_MSG(const char *s, ...) const; - void INFO_MSG(const char *s, ...) const; +/* + * build.h + * + * This file is a part of NSIS. + * + * Copyright (C) 1999-2009 Nullsoft and Contributors + * + * Licensed under the zlib/libpng license (the "License"); + * you may not use this file except in compliance with the License. + * + * Licence details can be found in the file COPYING. + * + * This software is provided 'as-is', without any express or implied + * warranty. + * + * Unicode support by Jim Park -- 08/10/2007 + */ - DefineList *searchParseString(const char *source_string, LineParser *line, int parmOffs, bool ignCase, bool noErrors); - -#ifdef NSIS_CONFIG_PLUGIN_SUPPORT - int add_plugins_dir_initializer(void); -#endif //NSIS_CONFIG_PLUGIN_SUPPORT - - // build.cpp functions used mostly by script.cpp - void set_code_type_predefines(const char *value = NULL); - int getcurdbsize(); - int add_section(const char *secname, const char *defname, int expand=0); - int section_end(); - int add_function(const char *funname); - int function_end(); - void section_add_size_kb(int kb); - int section_add_flags(int flags); - int section_add_install_type(int inst_type); - int add_page(int type); - int page_end(); - int add_label(const char *name); - int add_entry(const entry *ent); - int add_entry_direct(int which, int o0=0, int o1=0, int o2=0, int o3=0, int o4=0, int o5=0); - int add_db_data(IMMap *map); // returns offset - int add_db_data(const char *data, int length); // returns offset - int add_data(const char *data, int length, IGrowBuf *dblock); // returns offset - int add_string(const char *string, int process=1, WORD codepage=CP_ACP); // returns offset (in string table) - int add_intstring(const int i); // returns offset in stringblock - - int preprocess_string(char *out, const char *in, WORD codepage=CP_ACP); - -#ifdef NSIS_CONFIG_PLUGIN_SUPPORT - // Added by Ximon Eighteen 5th August 2002 - Plugins m_plugins; - bool plugin_used; - bool uninst_plugin_used; - int build_plugin_unload; -#endif //NSIS_CONFIG_PLUGIN_SUPPORT - - // build.cpp functions used mostly within build.cpp - int datablock_optimize(int start_offset, int first_int); - void printline(int l); - int process_jump(LineParser &line, int wt, int *offs); - - int AddVersionInfo(); - int ProcessPages(); - void PrepareInstTypes(); - void AddStandardStrings(); - void PrepareHeaders(IGrowBuf *hdrbuf); - int SetVarsSection(); - int SetManifest(); - int UpdatePEHeader(); - - int resolve_jump_int(const char *fn, int *a, int offs, int start, int end); - int resolve_call_int(const char *fn, const char *str, int fptr, int *ofs); - int resolve_instruction(const char *fn, const char *str, entry *w, int offs, int start, int end); - - int resolve_coderefs(const char *str); - void print_warnings(); - int uninstall_generate(); - void set_uninstall_mode(int un); - - // lang.cpp functions and variables - void InitLangTables(); - LanguageTable *GetLangTable(LANGID &lang, bool create = true); - const char *GetLangNameAndCP(LANGID lang, unsigned int *codepage = NULL); - int DefineLangString(const char *name, int process=-1); - int DefineInnerLangString(int id, int process=-1); - int SetLangString(char *name, LANGID lang, char *string); - int SetInnerString(int id, char *string); - int GenerateLangTable(LanguageTable *lt, int num_lang_tables); - int GenerateLangTables(); - void FillLanguageTable(LanguageTable *table); - int HasUserDefined(int id) { - const char *us = UserInnerStrings.get(id); - return us && *us; - }; - - LanguageTable *LoadLangFile(char *filename); - void DeleteLangTable(LanguageTable *table); - - NLFRef NLFRefs[NLF_STRINGS]; - bool keep_ref; - StringsArray UserInnerStrings; - bool defcodepage_set; - GrowBuf lang_tables; - LANGID last_used_lang; - LangStringList build_langstrings; - int build_langstring_num, ubuild_langstring_num; - char build_font[1024]; - int build_font_size; - - unsigned int uDefCodePage; - - // pages stuff - int license_res_id; - page *cur_page; - int cur_page_type; - int enable_last_page_cancel, uenable_last_page_cancel; - - int disable_window_icon; - - // User variables stuff - int GetUserVarIndex(LineParser &line, int token); - // Added by ramon 3 jun 2003 - UserVarsStringList m_UserVarNames; - int m_iBaseVarsNum; - int DeclaredUserVar(const char *VarName); - void VerifyDeclaredUserVarRefs(UserVarsStringList *pVarsStringList); - - ConstantsStringList m_ShellConstants; - - // a whole bunch O data. - - std::string stubs_dir; - -#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT - ICompressor *compressor; - CZlib zlib_compressor; - CBzip2 bzip2_compressor; - CLZMA lzma_compressor; -#endif - bool build_compressor_set; - bool build_compressor_final; - bool build_compress_whole; - int build_compress; - int build_compress_level; - int build_compress_dict_size; - - bool no_space_texts; - - bool has_called_write_output; - - char build_packname[1024], build_packcmd[1024]; - int build_overwrite, build_last_overwrite, build_crcchk, - build_datesave, build_optimize_datablock, - build_allowskipfiles; // Added by ramon 23 May 2003 - - header build_header, build_uninst, *cur_header; - int uninstall_mode; - int uninstall_size,uninstall_size_full; - int uninstaller_writes_used; - - char build_output_filename[1024]; - - int build_include_depth; - - // Added by ramon 6 jun 2003 -#ifdef NSIS_SUPPORT_VERSION_INFO - CResourceVersionInfo rVersionInfo; - char version_product_v[1024]; -#endif - - int sectiongroup_open_cnt; - FastStringList m_warnings; - GrowBuf m_macros; - - StringList m_macro_entry; - - int db_opt_save, db_comp_save, db_full_size, db_opt_save_u, - db_comp_save_u, db_full_size_u; - - FastStringList include_dirs; - - StringList ns_func; // function namespace - StringList ns_label; // label namespace - - int build_cursection_isfunc; - section *build_cursection; - TinyGrowBuf build_sections, ubuild_sections, *cur_sections; - GrowBuf build_entries,ubuild_entries, *cur_entries; - GrowBuf build_instruction_entry_map,ubuild_instruction_entry_map, *cur_instruction_entry_map; - TinyGrowBuf build_functions, ubuild_functions, *cur_functions; - TinyGrowBuf build_labels, ubuild_labels, *cur_labels; - StringList build_strlist, ubuild_strlist, *cur_strlist; - GrowBuf build_langtables, ubuild_langtables, *cur_langtables; - TinyGrowBuf build_pages, ubuild_pages, *cur_pages; - TinyGrowBuf build_ctlcolors, ubuild_ctlcolors, *cur_ctlcolors; - - // don't forget to update the cache after updating the datablock - // see datablock_optimize for an example - MMapBuf build_datablock, ubuild_datablock; - TinyGrowBuf build_datablock_cache, ubuild_datablock_cache; - IGrowBuf *cur_datablock, *cur_datablock_cache; - struct cached_db_size - { - int first_int; // size | (compressed ? 0x80000000 : 0) - int start_offset; - }; - - int build_filebuflen; - - TinyGrowBuf verbose_stack; - - unsigned char *m_exehead; - size_t m_exehead_size; - size_t m_exehead_original_size; - - bool branding_image_found; - WORD branding_image_id; - - IconGroup installer_icon; - IconGroup uninstaller_icon; - size_t m_unicon_size; - -#ifdef NSIS_SUPPORT_BGBG - LOGFONT bg_font; - LOGFONT bg_default_font; -#endif - -#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT - int deflateToFile(FILE *fp, char *buf, int len); // len==0 to flush -#endif - - manifest::comctl manifest_comctl; - manifest::exec_level manifest_exec_level; - - CResourceEditor *res_editor; - void init_res_editor(); - void close_res_editor(); -}; - -#endif //_BUILD_H_ +#ifndef _BUILD_H_ +#define _BUILD_H_ + +#include "strlist.h" +#include "lineparse.h" +#include "lang.h" +#include "ResourceEditor.h" +#include "ResourceVersionInfo.h" +#include "uservars.h" +#include "ShConstants.h" +#include "mmap.h" +#include "manifest.h" +#include "icon.h" + +#include "exehead/fileform.h" +#include "exehead/config.h" + +#include "tstring.h" +#include + +#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES +// Added by Sunil Kamath 11 June 2003 +# include +# include +#endif + +#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT +// Changed by Amir Szekely 31st July 2002 +#include "compressor.h" +#include "czlib.h" +#include "cbzip2.h" +#include "clzma.h" + +#endif//NSIS_CONFIG_COMPRESSION_SUPPORT + +#ifdef NSIS_CONFIG_PLUGIN_SUPPORT +# include "Plugins.h" +#endif //NSIS_CONFIG_PLUGIN_SUPPORT + +#define PS_OK 0 +#define PS_EOF 1 +#define PS_ERROR 50 +#define PS_WARNING 100 + +// token placement +#define TP_SEC 1 +#define TP_FUNC 2 +#define TP_CODE (TP_SEC | TP_FUNC) +#define TP_GLOBAL 4 +#define TP_PAGEEX 8 +#define TP_PG (TP_GLOBAL | TP_PAGEEX) +#define TP_ALL (TP_CODE | TP_PG) + +enum notify_e { + MAKENSIS_NOTIFY_SCRIPT, + MAKENSIS_NOTIFY_WARNING, + MAKENSIS_NOTIFY_ERROR, + MAKENSIS_NOTIFY_OUTPUT +}; + +#define PAGE_CUSTOM 0 +#define PAGE_LICENSE 1 +#define PAGE_COMPONENTS 2 +#define PAGE_DIRECTORY 3 +#define PAGE_INSTFILES 4 +#define PAGE_UNINSTCONFIRM 5 +#define PAGE_COMPLETED 6 + +class CEXEBuild { + public: + CEXEBuild(); + void initialize(const TCHAR *makensis_path); + ~CEXEBuild(); + + // to add a warning to the compiler's warning list. + void warning(const TCHAR *s, ...); + // warning with file name and line count + void warning_fl(const TCHAR *s, ...); + + // to add a defined thing. + void define(const TCHAR *p, const TCHAR *v=TEXT("")); + +#ifdef NSIS_CONFIG_PLUGIN_SUPPORT + // Added by Ximon Eighteen 5th August 2002 + void build_plugin_table(void); + int plugins_processed; +#endif //NSIS_CONFIG_PLUGIN_SUPPORT + + + // process a script (you can process as many scripts as you want, + // it is as if they are concatenated) + int process_script(FILE *fp, const TCHAR *curfilename); + int process_oneline(TCHAR *line, const TCHAR *curfilename, int lineptr); + + // you only get to call write_output once, so use it wisely. + int write_output(void); + + void print_help(TCHAR *commandname=NULL); + + DefineList definedlist; // List of identifiers marked as "defined" like + // C++ macro definitions such as _UNICODE. + + int display_errors; + int display_script; + int display_warnings; + int display_info; + + int linecnt; + const TCHAR *curfilename; + FILE *fp; + + HWND notify_hwnd; + void notify(notify_e code, const TCHAR *data) const; + + private: + int check_write_output_errors() const; + int prepare_uninstaller(); + int pack_exe_header(); + + int set_compressor(const tstring& compressor, const bool solid); + int update_exehead(const tstring& file, size_t *size=NULL); + void update_exehead(const unsigned char *new_exehead, size_t new_size); + + // tokens.cpp + bool is_valid_token(TCHAR *s); + int get_commandtoken(TCHAR *s, int *np, int *op, int *pos); + + /** + * Returns the current "state" by looking at whether it is in a + * section/function/pagex or global. + * @return TP_FUNC, TP_SEC, TP_PAGEEX, TP_GLOBAL. + */ + int GetCurrentTokenPlace(); + int IsTokenPlacedRight(int pos, TCHAR *tok); + + // script.cpp +#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES + // Added by Sunil Kamath 11 June 2003 + TCHAR* set_file_predefine(const TCHAR *); + void restore_file_predefine(TCHAR *); + TCHAR* set_timestamp_predefine(const TCHAR *); + void restore_timestamp_predefine(TCHAR *); + TCHAR* set_line_predefine(int, BOOL); + void restore_line_predefine(TCHAR *); + void set_date_time_predefines(); + void del_date_time_predefines(); +#endif + int parseScript(); + int includeScript(TCHAR *f); + int MacroExists(const TCHAR *macroname); +#ifdef NSIS_FIX_DEFINES_IN_STRINGS + void ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hist, bool bIgnoreDefines = false); +#else + void ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hist); +#endif + int doParse(const TCHAR *str); + int doCommand(int which_token, LineParser &line); + + int do_add_file(const TCHAR *lgss, int attrib, int recurse, int *total_files, const TCHAR + *name_override=0, int generatecode=1, int *data_handle=0, + const std::set& excluded=std::set(), + const tstring& basedir=tstring(_T("")), bool dir_created=false); + int add_file(const tstring& dir, const tstring& file, int attrib, const TCHAR + *name_override, int generatecode, int *data_handle); + int do_add_file_create_dir(const tstring& local_dir, const tstring& dir, int attrib=0); + + GrowBuf m_linebuild; // used for concatenating lines + + // used by doParse to do preprocessing + struct ifblock + { + int hasexeced; + int elseused; + int ignore; + int inherited_ignore; + } *cur_ifblock; + + TinyGrowBuf build_preprocessor_data; + + void start_ifblock(); + void end_ifblock(); + int num_ifblock(); + + int last_line_had_slash; + bool inside_comment; + int multiple_entries_instruction; // 1 (true) or 0 (false) + + void ERROR_MSG(const TCHAR *s, ...) const; + void SCRIPT_MSG(const TCHAR *s, ...) const; + void INFO_MSG(const TCHAR *s, ...) const; + + DefineList *searchParseString(const TCHAR *source_string, LineParser *line, int parmOffs, bool ignCase, bool noErrors); + +#ifdef NSIS_CONFIG_PLUGIN_SUPPORT + int add_plugins_dir_initializer(void); +#endif //NSIS_CONFIG_PLUGIN_SUPPORT + + // build.cpp functions used mostly by script.cpp + void set_code_type_predefines(const TCHAR *value = NULL); + int getcurdbsize(); + int add_section(const TCHAR *secname, const TCHAR *defname, int expand=0); + int section_end(); + int add_function(const TCHAR *funname); + int function_end(); + void section_add_size_kb(int kb); + int section_add_flags(int flags); + int section_add_install_type(int inst_type); + int add_page(int type); + int page_end(); + int add_label(const TCHAR *name); + int add_entry(const entry *ent); + int add_entry_direct(int which, int o0=0, int o1=0, int o2=0, int o3=0, int o4=0, int o5=0); + int add_db_data(IMMap *map); // returns offset + int add_db_data(const char *data, int length); // returns offset + int add_data(const char *data, int length, IGrowBuf *dblock); // returns offset + int add_string(const TCHAR *string, int process=1, WORD codepage=CP_ACP); // returns offset (in string table) + int add_intstring(const int i); // returns offset in stringblock + + int preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage=CP_ACP); + +#ifdef NSIS_CONFIG_PLUGIN_SUPPORT + // Added by Ximon Eighteen 5th August 2002 + Plugins m_plugins; + bool plugin_used; + bool uninst_plugin_used; + int build_plugin_unload; +#endif //NSIS_CONFIG_PLUGIN_SUPPORT + + // build.cpp functions used mostly within build.cpp + int datablock_optimize(int start_offset, int first_int); + void printline(int l); + int process_jump(LineParser &line, int wt, int *offs); + + int AddVersionInfo(); + int ProcessPages(); + void PrepareInstTypes(); + void AddStandardStrings(); + void PrepareHeaders(IGrowBuf *hdrbuf); + int SetVarsSection(); + int SetManifest(); + int UpdatePEHeader(); + + int resolve_jump_int(const TCHAR *fn, int *a, int offs, int start, int end); + int resolve_call_int(const TCHAR *fn, const TCHAR *str, int fptr, int *ofs); + int resolve_instruction(const TCHAR *fn, const TCHAR *str, entry *w, int offs, int start, int end); + + int resolve_coderefs(const TCHAR *str); + void print_warnings(); + int uninstall_generate(); + + /** Are we defining an uninstall version of the code? + * @param un Use like a boolean to define whether in uninstall mode. + */ + void set_uninstall_mode(int un); + + // lang.cpp functions and variables + void InitLangTables(); + + /** + * This function gets a LanguageTable structure for the specified language + * via LANGID. If create == true, it will create a new LanguageTable if + * the appropriate one cannot be found. If lang is LANG_NEUTRAL (0), then + * it will get the LanguageTable of the last used language or more + * correctly, the last Language ID that generated a valid return value + * (not NULL). + * + * @param lang [in/out] Language ID reference. If LANG_NEUTRAL, it gets + * set to thelast used language ID. + * @param create Create a new LanguageTable? Default = true. + * @return Appropriate LanguagTable* if exists, otherwise NULL. + */ + LanguageTable *GetLangTable(LANGID &lang, bool create = true); + + /** + * Get the language name as a TCHAR* and the code page value via an + * out parameter. It will look for a LanguageTable to get the values. + * If not found, then it will set the codepage to English for ANSI + * or Unicode for Unicode version of NSIS. The language name is looked + * up via the LanguageTable if it exists, otherwise, it calls + * GetLocaleInfo() with the LANGID to get the string. + * + * This function is not thread-safe! For a thread-safe version, the + * parameter must include the buffer to write to. + * + * @param lang The language ID + * @param codepage [out] The code page referred to by the language ID. + * @return The language string in English. + */ + const TCHAR *GetLangNameAndCP(LANGID lang, unsigned int *codepage = NULL); + + int DefineLangString(const TCHAR *name, int process=-1); + int DefineInnerLangString(int id, int process=-1); + + /** + * A LangString is a string variable that varies in value depending on what + * language is being used. This function sets the string value for the + * variable 'name' for a given language ID. + * + * @return If the language id, the variable name or string is invalid, it will + * return aPS_ERROR. If this function call is overwriting a set user string, + * this will return a PS_WARNING. + */ + int SetLangString(TCHAR *name, LANGID lang, TCHAR *str); + + /** + * Sets the user string to the specific NLF_STRINGS id. + * + * @return If the id is invalid or the string is not valid, it will return + * aPS_ERROR. If this function call is overwriting a set user string, + * this will return a PS_WARNING. + */ + int SetInnerString(int id, TCHAR *str); + + int GenerateLangTable(LanguageTable *lt, int num_lang_tables); + int GenerateLangTables(); + void FillLanguageTable(LanguageTable *table); + int HasUserDefined(int id) { + const TCHAR *us = UserInnerStrings.get(id); + return us && *us; + }; + + LanguageTable *LoadLangFile(TCHAR *filename); + void DeleteLangTable(LanguageTable *table); + + NLFRef NLFRefs[NLF_STRINGS]; + bool keep_ref; + StringsArray UserInnerStrings; + bool defcodepage_set; + GrowBuf lang_tables; + LANGID last_used_lang; + LangStringList build_langstrings; + + int build_langstring_num, ubuild_langstring_num; + TCHAR build_font[1024]; + int build_font_size; + + unsigned int uDefCodePage; + + // pages stuff + int license_res_id; + page *cur_page; // Current page we are defining, NULL if not. + int cur_page_type; + int enable_last_page_cancel, uenable_last_page_cancel; + + int disable_window_icon; + + // User variables stuff + int GetUserVarIndex(LineParser &line, int token); + // Added by ramon 3 jun 2003 + UserVarsStringList m_UserVarNames; + int m_iBaseVarsNum; + int DeclaredUserVar(const TCHAR *VarName); + void VerifyDeclaredUserVarRefs(UserVarsStringList *pVarsStringList); + + ConstantsStringList m_ShellConstants; + + // a whole bunch O data. + + tstring stubs_dir; + +#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT + ICompressor *compressor; + CZlib zlib_compressor; + CBzip2 bzip2_compressor; + CLZMA lzma_compressor; +#endif + bool build_compressor_set; + bool build_compressor_final; + bool build_compress_whole; + int build_compress; + int build_compress_level; + int build_compress_dict_size; + + bool no_space_texts; + + bool has_called_write_output; + + TCHAR build_packname[1024], build_packcmd[1024]; + int build_overwrite, build_last_overwrite, build_crcchk, + build_datesave, build_optimize_datablock, + build_allowskipfiles; // Added by ramon 23 May 2003 + + header build_header, build_uninst, *cur_header; + int uninstall_mode; // Are we in uinstall mode? Acts like a bool. + int uninstall_size,uninstall_size_full; + int uninstaller_writes_used; + + TCHAR build_output_filename[1024]; + + int build_include_depth; + + // Added by ramon 6 jun 2003 +#ifdef NSIS_SUPPORT_VERSION_INFO + CResourceVersionInfo rVersionInfo; + TCHAR version_product_v[1024]; +#endif + + int sectiongroup_open_cnt; + FastStringList m_warnings; + GrowBuf m_macros; + + StringList m_macro_entry; + + int db_opt_save, db_comp_save, db_full_size, db_opt_save_u, + db_comp_save_u, db_full_size_u; + + FastStringList include_dirs; + + StringList ns_func; // function namespace + StringList ns_label; // label namespace + + int build_cursection_isfunc; // Are we in the middle of func definition? + section *build_cursection; // The section we are defining, NULL if not in section. + // This could be a function or a section. + + // The ubuild prefixed objects / variables are for the uinstall versions + // of the code. The cur prefix objects are what the current objects that + // need to be referenced should be. What is pointed to by the cur* objects + // are determined by whether or not we are in uninstall mode or not. + TinyGrowBuf build_sections, ubuild_sections, *cur_sections; + GrowBuf build_entries,ubuild_entries, *cur_entries; + GrowBuf build_instruction_entry_map,ubuild_instruction_entry_map, *cur_instruction_entry_map; + TinyGrowBuf build_functions, ubuild_functions, *cur_functions; + TinyGrowBuf build_labels, ubuild_labels, *cur_labels; + StringList build_strlist, ubuild_strlist, *cur_strlist; + GrowBuf build_langtables, ubuild_langtables, *cur_langtables; + TinyGrowBuf build_pages, ubuild_pages, *cur_pages; + TinyGrowBuf build_ctlcolors, ubuild_ctlcolors, *cur_ctlcolors; + + // don't forget to update the cache after updating the datablock + // see datablock_optimize for an example + MMapBuf build_datablock, ubuild_datablock; + TinyGrowBuf build_datablock_cache, ubuild_datablock_cache; + IGrowBuf *cur_datablock, *cur_datablock_cache; + struct cached_db_size + { + int first_int; // size | (compressed ? 0x80000000 : 0) + int start_offset; + }; + + int build_filebuflen; + + TinyGrowBuf verbose_stack; + + unsigned char *m_exehead; + size_t m_exehead_size; + size_t m_exehead_original_size; + + bool branding_image_found; + WORD branding_image_id; + + IconGroup installer_icon; + IconGroup uninstaller_icon; + size_t m_unicon_size; + +#ifdef NSIS_SUPPORT_BGBG + LOGFONT bg_font; + LOGFONT bg_default_font; +#endif + +#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT + int deflateToFile(FILE *fp, char *buf, int len); // len==0 to flush +#endif + + manifest::comctl manifest_comctl; + manifest::exec_level manifest_exec_level; + + CResourceEditor *res_editor; + void init_res_editor(); + void close_res_editor(); +}; + +#endif //_BUILD_H_ diff --git a/Source/bzip2/blocksort.c b/Source/bzip2/blocksort.c index 09489dc3..63e6a4d8 100644 --- a/Source/bzip2/blocksort.c +++ b/Source/bzip2/blocksort.c @@ -11,6 +11,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/27/2007 */ #include "bzlib.h" @@ -217,7 +219,7 @@ void fallbackQSort3 ( UInt32* fmap, fswap(fmap[unLo], fmap[unHi]); unLo++; unHi--; } - AssertD ( unHi == unLo-1, "fallbackQSort3(2)" ); + AssertD ( unHi == unLo-1, _T("fallbackQSort3(2)") ); if (gtHi < ltLo) continue; @@ -400,7 +402,7 @@ static Bool mainGtU ( UInt32 i1, UChar c1, c2; UInt16 s1, s2; - AssertD ( i1 != i2, "mainGtU" ); + AssertD ( i1 != i2, _T("mainGtU") ); /* 1 */ c1 = block[i1]; c2 = block[i2]; if (c1 != c2) return (c1 > c2); @@ -730,7 +732,7 @@ void mainQSort3 ( UInt32* ptr, mswap(ptr[unLo], ptr[unHi]); unLo++; unHi--; } - AssertD ( unHi == unLo-1, "mainQSort3(2)" ); + AssertD ( unHi == unLo-1, _T("mainQSort3(2)") ); if (gtHi < ltLo) { mpush(lo, hi, d+1 ); @@ -751,8 +753,8 @@ void mainQSort3 ( UInt32* ptr, if (mnextsize(1) < mnextsize(2)) mnextswap(1,2); if (mnextsize(0) < mnextsize(1)) mnextswap(0,1); - AssertD (mnextsize(0) >= mnextsize(1), "mainQSort3(8)" ); - AssertD (mnextsize(1) >= mnextsize(2), "mainQSort3(9)" ); + AssertD (mnextsize(0) >= mnextsize(1), _T("mainQSort3(8)") ); + AssertD (mnextsize(1) >= mnextsize(2), _T("mainQSort3(9)") ); mpush (nextLo[0], nextHi[0], nextD[0]); mpush (nextLo[1], nextHi[1], nextD[1]); diff --git a/Source/bzip2/bzlib.c b/Source/bzip2/bzlib.c index 3f605d70..b6e999a1 100644 --- a/Source/bzip2/bzlib.c +++ b/Source/bzip2/bzlib.c @@ -11,6 +11,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/23/2007 */ #include "bzlib.h" diff --git a/Source/bzip2/bzlib.h b/Source/bzip2/bzlib.h index d4ee6619..b004ae0a 100644 --- a/Source/bzip2/bzlib.h +++ b/Source/bzip2/bzlib.h @@ -11,6 +11,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/27/2007 */ /*-------------------------------------------------------------*/ diff --git a/Source/bzip2/compress.c b/Source/bzip2/compress.c index f70acf00..35e91da9 100644 --- a/Source/bzip2/compress.c +++ b/Source/bzip2/compress.c @@ -11,6 +11,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/27/2007 */ /*-------------------------------------------------------------*/ @@ -218,10 +220,10 @@ void generateMTFValues ( EState* s ) for (i = 0; i < s->nblock; i++) { UChar ll_i; - AssertD ( wr <= i, "generateMTFValues(1)" ); + AssertD ( wr <= i, _T("generateMTFValues(1)") ); j = ptr[i]-1; if (j < 0) j += s->nblock; ll_i = s->unseqToSeq[block[j]]; - AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" ); + AssertD ( ll_i < s->nInUse, _T("generateMTFValues(2a)") ); if (yy[0] == ll_i) { zPend++; diff --git a/Source/bzip2/decompress.c b/Source/bzip2/decompress.c index cb559f4f..8fca1cac 100644 --- a/Source/bzip2/decompress.c +++ b/Source/bzip2/decompress.c @@ -11,6 +11,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/27/2007 */ #include "bzlib.h" diff --git a/Source/bzip2/huffman.c b/Source/bzip2/huffman.c index ea13ea5b..385f1823 100644 --- a/Source/bzip2/huffman.c +++ b/Source/bzip2/huffman.c @@ -11,6 +11,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/27/2007 */ #include "bzlib.h" diff --git a/Source/cbzip2.h b/Source/cbzip2.h index 21079c0f..23ab436c 100644 --- a/Source/cbzip2.h +++ b/Source/cbzip2.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/24/2007 */ #ifndef __CBZIP2_H__ @@ -71,23 +73,23 @@ class CBzip2 : public ICompressor { return stream->avail_out; } - const char* GetName() { - return "bzip2"; + const TCHAR* GetName() { + return _T("bzip2"); } - const char* GetErrStr(int err) { + const TCHAR* GetErrStr(int err) { switch (err) { case BZ_SEQUENCE_ERROR: - return "sequence error - bad call"; + return _T("sequence error - bad call"); case BZ_PARAM_ERROR: - return "parameter error - bad call"; + return _T("parameter error - bad call"); case BZ_MEM_ERROR: - return "not enough memory"; + return _T("not enough memory"); case BZ_CONFIG_ERROR: - return "config error"; + return _T("config error"); default: - return "unknown error"; + return _T("unknown error"); } } diff --git a/Source/clzma.cpp b/Source/clzma.cpp index 7088648c..552006b7 100644 --- a/Source/clzma.cpp +++ b/Source/clzma.cpp @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/24/2007 */ #include // for std::min @@ -27,7 +29,7 @@ struct evnet_t bool signaled; }; -HANDLE CreateEvent(void *, BOOL, BOOL, char *) +HANDLE CreateEvent(void *, BOOL, BOOL, TCHAR *) { evnet_t *event = (evnet_t *) malloc(sizeof(evnet_t)); if (!event) @@ -439,26 +441,26 @@ unsigned int CLZMA::GetAvailOut() return avail_out; } -const char* CLZMA::GetName() +const TCHAR* CLZMA::GetName() { - return "lzma"; + return _T("lzma"); } -const char* CLZMA::GetErrStr(int err) +const TCHAR* CLZMA::GetErrStr(int err) { switch (err) { case LZMA_BAD_CALL: - return "bad call"; + return _T("bad call"); case LZMA_INIT_ERROR: - return "initialization failed"; + return _T("initialization failed"); case LZMA_THREAD_ERROR: - return "thread synchronization error"; + return _T("thread synchronization error"); case LZMA_IO_ERROR: - return "input/output error"; + return _T("input/output error"); case LZMA_MEM_ERROR: - return "not enough memory"; + return _T("not enough memory"); default: - return "unknown error"; + return _T("unknown error"); } } diff --git a/Source/clzma.h b/Source/clzma.h index 74cacdf8..1c8f4afb 100644 --- a/Source/clzma.h +++ b/Source/clzma.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/24/2007 */ #ifndef __CLZMA_H__ @@ -95,9 +97,9 @@ public: virtual char *GetNextOut(); virtual unsigned int GetAvailIn(); virtual unsigned int GetAvailOut(); - virtual const char *GetName(); + virtual const TCHAR *GetName(); - virtual const char* GetErrStr(int err); + virtual const TCHAR* GetErrStr(int err); }; #endif diff --git a/Source/compressor.h b/Source/compressor.h index 7913a1d9..7991434b 100644 --- a/Source/compressor.h +++ b/Source/compressor.h @@ -12,11 +12,15 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/24/2007 */ #ifndef __COMPRESSOR_H__ #define __COMPRESSOR_H__ +#include "tchar.h" + #define C_OK 0 #define C_FINISHED 1 @@ -38,9 +42,9 @@ class ICompressor { virtual unsigned int GetAvailIn() = 0; virtual unsigned int GetAvailOut() = 0; - virtual const char* GetName() = 0; + virtual const TCHAR* GetName() = 0; - virtual const char* GetErrStr(int err) = 0; + virtual const TCHAR* GetErrStr(int err) = 0; }; #endif diff --git a/Source/crc32.c b/Source/crc32.c index f41d423b..93049aa7 100644 --- a/Source/crc32.c +++ b/Source/crc32.c @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/24/2007 */ #include "Platform.h" diff --git a/Source/crc32.h b/Source/crc32.h index c75c9191..f98cebc4 100644 --- a/Source/crc32.h +++ b/Source/crc32.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/24/2007 */ #include "Platform.h" diff --git a/Source/czlib.h b/Source/czlib.h index 654ae10b..aeb2372e 100644 --- a/Source/czlib.h +++ b/Source/czlib.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/24/2007 */ #ifndef __CZLIB_H__ @@ -62,25 +64,25 @@ class CZlib : public ICompressor { return stream->avail_out; } - const char* GetName() { - return "zlib"; + const TCHAR* GetName() { + return _T("zlib"); } - const char* GetErrStr(int err) { + const TCHAR* GetErrStr(int err) { switch (err) { case Z_STREAM_ERROR: - return "invalid stream - bad call"; + return _T("invalid stream - bad call"); case Z_DATA_ERROR: - return "data error"; + return _T("data error"); case Z_MEM_ERROR: - return "not enough memory"; + return _T("not enough memory"); case Z_BUF_ERROR: - return "buffer error - bad call"; + return _T("buffer error - bad call"); case Z_VERSION_ERROR: - return "version error"; + return _T("version error"); default: - return "unknown error"; + return _T("unknown error"); } } diff --git a/Source/dirreader.cpp b/Source/dirreader.cpp index 48548510..e5bc5d9f 100644 --- a/Source/dirreader.cpp +++ b/Source/dirreader.cpp @@ -12,11 +12,13 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/23/2007 */ #include "Platform.h" #include "dirreader.h" -#include +#include "tstring.h" #include #include // for stricmp() @@ -25,27 +27,27 @@ using namespace std; dir_reader::dir_reader() { - exclude("."); - exclude(".."); + exclude(_T(".")); + exclude(_T("..")); } -const set& dir_reader::files() { +const set& dir_reader::files() { return m_files; } -const set& dir_reader::dirs() { +const set& dir_reader::dirs() { return m_dirs; } -void dir_reader::exclude(const string& spec) { - if (spec.find_first_of("?*") != string::npos) { +void dir_reader::exclude(const tstring& spec) { + if (spec.find_first_of(_T("?*")) != tstring::npos) { m_wildcard_excluded.insert(spec); } else { m_excluded.insert(spec); } } -void dir_reader::exclude(const set& specs) { +void dir_reader::exclude(const set& specs) { iterator i = specs.begin(); iterator e = specs.end(); @@ -54,27 +56,27 @@ void dir_reader::exclude(const set& specs) { } } -bool dir_reader::matches(const string& name, const string& spec) { - string::const_iterator name_itr = name.begin(); - string::const_iterator name_end = name.end(); +bool dir_reader::matches(const tstring& name, const tstring& spec) { + tstring::const_iterator name_itr = name.begin(); + tstring::const_iterator name_end = name.end(); - string::const_iterator spec_itr = spec.begin(); - string::const_iterator spec_end = spec.end(); + tstring::const_iterator spec_itr = spec.begin(); + tstring::const_iterator spec_end = spec.end(); - string::const_iterator last_good_spec = spec_end; - string::const_iterator last_good_name = name_end; + tstring::const_iterator last_good_spec = spec_end; + tstring::const_iterator last_good_name = name_end; while (name_itr != name_end && spec_itr != spec_end) { switch (*spec_itr) { - case '?': + case _T('?'): // question mark mathes one char name_itr++; spec_itr++; break; - case '*': + case _T('*'): // double asterisk is the same as a single asterisk - while (*spec_itr == '*') { + while (*spec_itr == _T('*')) { spec_itr++; // asterisk at the end of the spec matches the end of the name if (spec_itr == spec_end) @@ -88,6 +90,7 @@ bool dir_reader::matches(const string& name, const string& spec) { break; default: + // Jim Park: This should work since tolower is templated with Chartype. if (::tolower(*name_itr) != ::tolower(*spec_itr)) { if (last_good_spec != spec_end) { // matched wrong part of the name, try again @@ -115,7 +118,7 @@ bool dir_reader::matches(const string& name, const string& spec) { // skip any redundant asterisks and periods at the end of the name while (spec_itr != spec_end) { - if (*spec_itr != '.' && *spec_itr != '*') { + if (*spec_itr != _T('.') && *spec_itr != _T('*')) { break; } spec_itr++; @@ -125,19 +128,19 @@ bool dir_reader::matches(const string& name, const string& spec) { return name_itr == name_end && spec_itr == spec_end; } -void dir_reader::add_file(const string& file) { +void dir_reader::add_file(const tstring& file) { if (!is_excluded(file)) { m_files.insert(file); } } -void dir_reader::add_dir(const string& dir) { +void dir_reader::add_dir(const tstring& dir) { if (!is_excluded(dir)) { m_dirs.insert(dir); } } -bool dir_reader::is_excluded(const string& name) const { +bool dir_reader::is_excluded(const tstring& name) const { iterator i = m_excluded.begin(); iterator e = m_excluded.end(); @@ -164,10 +167,10 @@ bool dir_reader::is_excluded(const string& name) const { class win32_dir_reader : public dir_reader { public: - virtual void read(const string& dir) { + virtual void read(const tstring& dir) { WIN32_FIND_DATA fd; - string spec = dir + PLATFORM_PATH_SEPARATOR_STR + "*.*"; + tstring spec = dir + PLATFORM_PATH_SEPARATOR_STR + _T("*.*"); HANDLE h = ::FindFirstFile(spec.c_str(), &fd); if (h != INVALID_HANDLE_VALUE) { @@ -193,7 +196,7 @@ public: class posix_dir_reader : public dir_reader { public: - virtual void read(const string& dir) { + virtual void read(const tstring& dir) { //convert(dir); DIR *dip = ::opendir(dir.c_str()); @@ -218,16 +221,16 @@ public: private: void convert(string& path) { - string::size_type pos = path.find('\\'); + string::size_type pos = path.find(_T('\\')); while (pos != string::npos) { - path[pos] = '/'; - pos = path.find('\\'); + path[pos] = _T('/'); + pos = path.find(_T('\\')); } /* Replace drive letter X: by /x */ - if (path[1] == ':') { - path[1] = ::tolower(path[0]); - path[0] = '/'; + if (path[1] == _T(':')) { + path[1] = ::_totlower(path[0]); + path[0] = _T('/'); } } diff --git a/Source/dirreader.h b/Source/dirreader.h index b79a74e2..52cebe8f 100644 --- a/Source/dirreader.h +++ b/Source/dirreader.h @@ -12,44 +12,46 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/23/2007 */ #include "Platform.h" -#include +#include "tstring.h" #include class dir_reader { public: - typedef std::set::const_iterator iterator; + typedef std::set::const_iterator iterator; dir_reader(); virtual ~dir_reader() {} - virtual void read(const std::string& dir) = 0; + virtual void read(const tstring& dir) = 0; - virtual const std::set& files(); - virtual const std::set& dirs(); + virtual const std::set& files(); + virtual const std::set& dirs(); - virtual void exclude(const std::string& spec); - virtual void exclude(const std::set& specs); + virtual void exclude(const tstring& spec); + virtual void exclude(const std::set& specs); - static bool matches(const std::string& name, const std::string& spec); + static bool matches(const tstring& name, const tstring& spec); protected: - virtual void add_file(const std::string& file); - virtual void add_dir(const std::string& dir); + virtual void add_file(const tstring& file); + virtual void add_dir(const tstring& dir); - virtual bool is_excluded(const std::string& name) const; + virtual bool is_excluded(const tstring& name) const; private: - std::set m_excluded; - std::set m_wildcard_excluded; + std::set m_excluded; + std::set m_wildcard_excluded; - std::set m_files; - std::set m_dirs; + std::set m_files; + std::set m_dirs; }; diff --git a/Source/exehead/Main.c b/Source/exehead/Main.c index c8e6de86..ab7e6a17 100644 --- a/Source/exehead/Main.c +++ b/Source/exehead/Main.c @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/22/2007 */ #include "../Platform.h" @@ -34,7 +36,7 @@ extern HANDLE dbd_hFile; #endif -char g_caption[NSIS_MAX_STRLEN*2]; +TCHAR g_caption[NSIS_MAX_STRLEN*2]; #ifdef NSIS_CONFIG_VISIBLE_SUPPORT HWND g_hwnd; HANDLE g_hInstance; @@ -42,7 +44,7 @@ HANDLE g_hInstance; void NSISCALL CleanUp(); -char *ValidateTempDir() +TCHAR *ValidateTempDir() { validate_filename(state_temp_dir); if (!validpathspec(state_temp_dir)) @@ -55,16 +57,16 @@ char *ValidateTempDir() void *g_SHGetFolderPath; -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow) +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPTSTR lpszCmdParam, int nCmdShow) { int ret = 0; - const char *m_Err = _LANG_ERRORWRITINGTEMP; + const TCHAR *m_Err = _LANG_ERRORWRITINGTEMP; int cl_flags = 0; - char *realcmds; - char seekchar=' '; - char *cmdline; + TCHAR *realcmds; + TCHAR seekchar=_T(' '); + TCHAR *cmdline; InitCommonControls(); @@ -88,7 +90,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, // Delete $PROGRAMFILES\shfolder.dll # can't be deleted, as the // # new shfolder.dll is used // # to find its own path. - g_SHGetFolderPath = myGetProcAddress(MGA_SHGetFolderPathA); + g_SHGetFolderPath = myGetProcAddress(MGA_SHGetFolderPath); { // workaround for bug #1008632 @@ -108,7 +110,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, // of special folders (CSIDL_*). SHFILEINFO shfi; - SHGetFileInfo("", 0, &shfi, sizeof(SHFILEINFO), 0); + SHGetFileInfo(_T(""), 0, &shfi, sizeof(SHFILEINFO), 0); } mystrcpy(g_caption,_LANG_GENERIC_ERROR); @@ -120,7 +122,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, #endif//NSIS_CONFIG_VISIBLE_SUPPORT cmdline = state_command_line; - if (*cmdline == '\"') seekchar = *cmdline++; + if (*cmdline == _T('\"')) seekchar = *cmdline++; cmdline=findchar(cmdline, seekchar); cmdline=CharNext(cmdline); @@ -129,34 +131,34 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, while (*cmdline) { // skip over any spaces - while (*cmdline == ' ') cmdline++; + while (*cmdline == _T(' ')) cmdline++; // get char we should look for to get the next parm - seekchar = ' '; - if (cmdline[0] == '\"') + seekchar = _T(' '); + if (cmdline[0] == _T('\"')) { cmdline++; - seekchar = '\"'; + seekchar = _T('\"'); } // is it a switch? - if (cmdline[0] == '/') + if (cmdline[0] == _T('/')) { cmdline++; // this only works with spaces because they have just one bit on -#define END_OF_ARG(c) (((c)|' ')==' ') +#define END_OF_ARG(c) (((c)|_T(' '))==_T(' ')) #if defined(NSIS_CONFIG_VISIBLE_SUPPORT) && defined(NSIS_CONFIG_SILENT_SUPPORT) - if (cmdline[0] == 'S' && END_OF_ARG(cmdline[1])) + if (cmdline[0] == _T('S') && END_OF_ARG(cmdline[1])) cl_flags |= FH_FLAGS_SILENT; #endif//NSIS_CONFIG_SILENT_SUPPORT && NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_CRC_SUPPORT - if (*(LPDWORD)cmdline == CHAR4_TO_DWORD('N','C','R','C') && END_OF_ARG(cmdline[4])) + if (*(LPDWORD)cmdline == CHAR4_TO_DWORD(_T('N'),_T('C'),_T('R'),_T('C')) && END_OF_ARG(cmdline[4])) cl_flags |= FH_FLAGS_NO_CRC; #endif//NSIS_CONFIG_CRC_SUPPORT - if (*(LPDWORD)(cmdline-2) == CHAR4_TO_DWORD(' ', '/', 'D','=')) + if (*(LPDWORD)(cmdline-2) == CHAR4_TO_DWORD(_T(' '), _T('/'), _T('D'),_T('='))) { *(LPDWORD)(cmdline-2)=0; // keep this from being passed to uninstaller if necessary mystrcpy(state_install_directory,cmdline+2); @@ -167,7 +169,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, // skip over our parm cmdline = findchar(cmdline, seekchar); // skip the quote - if (*cmdline == '\"') + if (*cmdline == _T('\"')) cmdline++; } @@ -175,7 +177,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, if (!ValidateTempDir()) { GetWindowsDirectory(state_temp_dir, NSIS_MAX_STRLEN - 5); // leave space for \Temp - mystrcat(state_temp_dir, "\\Temp"); + mystrcat(state_temp_dir, _T("\\Temp")); if (!ValidateTempDir()) { goto end; @@ -189,11 +191,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT if (g_is_uninstaller) { - char *p = findchar(state_command_line, 0); + TCHAR *p = findchar(state_command_line, 0); // state_command_line has state_install_directory right after it in memory, so reading // a bit over state_command_line won't do any harm - while (p >= state_command_line && *(LPDWORD)p != CHAR4_TO_DWORD(' ', '_', '?', '=')) p--; + while (p >= state_command_line && *(LPDWORD)p != CHAR4_TO_DWORD(_T(' '), _T('_'), _T('?'), _T('='))) p--; m_Err = _LANG_UNINSTINITERROR; @@ -216,7 +218,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, { int x; - mystrcat(state_temp_dir,"~nsu.tmp"); + mystrcat(state_temp_dir,_T("~nsu.tmp")); // check if already running from uninstaller temp dir // this prevents recursive uninstaller calls @@ -230,11 +232,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, mystrcpy(state_install_directory,state_exe_directory); mystrcpy(g_usrvars[0], realcmds); - *(LPWORD)g_usrvars[1] = CHAR2_TO_WORD('A',0); + *(LPWORD)g_usrvars[1] = CHAR2_TO_WORD(_T('A'),0); for (x = 0; x < 26; x ++) { - static char buf2[NSIS_MAX_STRLEN]; + static TCHAR buf2[NSIS_MAX_STRLEN]; GetNSISString(buf2,g_header->str_uninstchild); // $TEMP\$1u_.exe @@ -301,7 +303,7 @@ end: BOOL (WINAPI *LPV)(LPCTSTR,LPCTSTR,PLUID); BOOL (WINAPI *ATP)(HANDLE,BOOL,PTOKEN_PRIVILEGES,DWORD,PTOKEN_PRIVILEGES,PDWORD); OPT=myGetProcAddress(MGA_OpenProcessToken); - LPV=myGetProcAddress(MGA_LookupPrivilegeValueA); + LPV=myGetProcAddress(MGA_LookupPrivilegeValue); ATP=myGetProcAddress(MGA_AdjustTokenPrivileges); if (OPT && LPV && ATP) { diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index 7fe32ac8..4f0c6ed6 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/10/2007 */ #include @@ -48,9 +50,9 @@ int g_quit_flag; // set when Quit has been called (meaning bail out ASAP) int progress_bar_pos, progress_bar_len; #if NSIS_MAX_STRLEN < 1024 -static char g_tmp[4096]; +static TCHAR g_tmp[4096]; #else -static char g_tmp[NSIS_MAX_STRLEN * 4]; +static TCHAR g_tmp[NSIS_MAX_STRLEN * 4]; #endif static int m_page=-1,m_retcode,m_delta; @@ -162,7 +164,7 @@ static BOOL NSISCALL _HandleStaticBkColor(UINT uMsg, WPARAM wParam, LPARAM lPara #if !defined(NSIS_CONFIG_LOG_ODS) && !defined(NSIS_CONFIG_LOG_STDOUT) void NSISCALL build_g_logfile() { - mystrcat(addtrailingslash(mystrcpy(g_log_file,state_install_directory)),"install.log"); + mystrcat(addtrailingslash(mystrcpy(g_log_file,state_install_directory)),_T("install.log")); } #endif #endif @@ -177,6 +179,8 @@ static void NSISCALL set_language() int lang_num; int *selected_langtable=0; + // Jim Park: We are doing byte offsets to get to various data structures so + // no TCHARs here. lang_again: lang_num=g_blocks[NB_LANGTABLES].num; while (lang_num--) { @@ -200,7 +204,7 @@ lang_again: myitoa(state_language, *(LANGID*)language_table); { - char *caption = GetNSISString(g_caption,LANG_CAPTION); + TCHAR *caption = GetNSISString(g_caption,LANG_CAPTION); #ifdef NSIS_SUPPORT_BGBG my_SetWindowText(m_bgwnd, caption); #endif @@ -241,11 +245,11 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) } else { - static const char reg_9x_locale[] = "Control Panel\\Desktop\\ResourceLocale"; - static const char reg_nt_locale_key[] = ".DEFAULT\\Control Panel\\International"; - const char *reg_nt_locale_val = ®_9x_locale[30]; // = "Locale" with opt + static const TCHAR reg_9x_locale[] = _T("Control Panel\\Desktop\\ResourceLocale"); + static const TCHAR reg_nt_locale_key[] = _T(".DEFAULT\\Control Panel\\International"); + const TCHAR *reg_nt_locale_val = ®_9x_locale[30]; // = _T("Locale") with opt - *(DWORD*)state_language = CHAR4_TO_DWORD('0', 'x', 0, 0); + *(DWORD*)state_language = CHAR4_TO_DWORD(_T('0'), _T('x'), 0, 0); { // Windows 9x @@ -287,13 +291,13 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) ); if (ps_tmpbuf[0]) { - char *p=ps_tmpbuf; - char *e; - if (p[0]=='\"') + TCHAR *p=ps_tmpbuf; + TCHAR *e; + if (p[0]==_T('\"')) { - char *p2; + TCHAR *p2; p++; - p2 = findchar(p, '"'); + p2 = findchar(p, _T('"')); *p2 = 0; } // p is the path now, check for .exe extension @@ -302,7 +306,7 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) if (e > p) { // if filename ends in .exe, and is not a directory, remove the filename - if (!lstrcmpi(e, ".exe")) // check extension + if (!lstrcmpi(e, _T(".exe"))) // check extension { DWORD d; d=GetFileAttributes(p); @@ -339,20 +343,20 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) #ifdef NSIS_SUPPORT_BGBG if (header->bg_color1 != -1) { - DWORD cn = CHAR4_TO_DWORD('_', 'N', 'b', 0); + DWORD cn = CHAR4_TO_DWORD(_T('_'), _T('N'), _T('b'), 0); RECT vp; extern LRESULT CALLBACK BG_WndProc(HWND, UINT, WPARAM, LPARAM); wc.lpfnWndProc = BG_WndProc; wc.hInstance = g_hInstance; wc.hIcon = g_hIcon; //wc.hCursor = LoadCursor(NULL,IDC_ARROW); - wc.lpszClassName = (LPCSTR)&cn; + wc.lpszClassName = (LPCTSTR)&cn; if (!RegisterClass(&wc)) return 0; SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0); - m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,(LPCSTR)&cn,0,WS_POPUP, + m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,(LPCTSTR)&cn,0,WS_POPUP, vp.left,vp.top,vp.right-vp.left,vp.bottom-vp.top,0,NULL,g_hInstance,NULL); } @@ -378,10 +382,10 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) #ifdef NSIS_CONFIG_LICENSEPAGE { // load richedit DLL - static const char riched20[]="RichEd20"; - static const char riched32[]="RichEd32"; - static const char richedit20a[]="RichEdit20A"; - static const char richedit[]="RichEdit"; + static const TCHAR riched20[]=_T("RichEd20"); + static const TCHAR riched32[]=_T("RichEd32"); + static const TCHAR richedit20a[]=_T("RichEdit20A"); + static const TCHAR richedit[]=_T("RichEdit"); if (!LoadLibrary(riched20)) { LoadLibrary(riched32); @@ -434,9 +438,10 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) #ifdef NSIS_CONFIG_VISIBLE_SUPPORT static int CALLBACK WINAPI BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { + // lpData has the TCHAR* to 'dir'. if (uMsg==BFFM_INITIALIZED) { - my_GetDialogItemText(IDC_DIR,(char*)lpData); + my_GetDialogItemText(IDC_DIR,(TCHAR*)lpData); SendMessage(hwnd,BFFM_SETSELECTION,(WPARAM)1,lpData); } if (uMsg==BFFM_SELCHANGED) @@ -445,7 +450,7 @@ static int CALLBACK WINAPI BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lPara hwnd, BFFM_ENABLEOK, 0, - SHGetPathFromIDList((LPITEMIDLIST)lParam,(char*)lpData) + SHGetPathFromIDList((LPITEMIDLIST)lParam,(TCHAR*)lpData) #ifdef NSIS_SUPPORT_CODECALLBACKS && !ExecuteCallbackFunction(CB_ONVERIFYINSTDIR) #endif @@ -710,7 +715,7 @@ skipPage: static DWORD dwRead; DWORD CALLBACK StreamLicense(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { - lstrcpyn(pbBuff,(char*)dwCookie+dwRead,cb); + lstrcpyn(pbBuff,(TCHAR*)dwCookie+dwRead,cb); *pcb=mystrlen(pbBuff); dwRead+=*pcb; return 0; @@ -724,7 +729,7 @@ static BOOL CALLBACK LicenseProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM if (uMsg == WM_INITDIALOG) { - char *l = (char *)GetNSISStringNP(GetNSISTab(this_page->parms[1])); + TCHAR *l = (TCHAR *)GetNSISStringNP(GetNSISTab(this_page->parms[1])); int lt = *l; EDITSTREAM es = { (DWORD)(++l), @@ -778,7 +783,7 @@ static BOOL CALLBACK LicenseProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM if (tr.chrg.cpMax-tr.chrg.cpMin < sizeof(ps_tmpbuf)) { SendMessage(hwLicense,EM_GETTEXTRANGE,0,(LPARAM)&tr); SetCursor(LoadCursor(0, IDC_WAIT)); - ShellExecute(hwndDlg,"open",tr.lpstrText,NULL,NULL,SW_SHOWNORMAL); + ShellExecute(hwndDlg,_T("open"),tr.lpstrText,NULL,NULL,SW_SHOWNORMAL); SetCursor(LoadCursor(0, IDC_ARROW)); } } @@ -835,7 +840,7 @@ static BOOL CALLBACK UninstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l static void NSISCALL SetSizeText(int dlgItem, int prefix, unsigned kb) { - char scalestr[32], byte[32]; + TCHAR scalestr[32], byte[32]; unsigned sh = 20; int scale = LANG_GIGA; @@ -853,7 +858,7 @@ static void NSISCALL SetSizeText(int dlgItem, int prefix, unsigned kb) wsprintf( g_tmp + mystrlen(g_tmp), #endif - "%u.%u%s%s", + _T("%u.%u%s%s"), kb >> sh, (((kb & 0x00FFFFFF) * 10) >> sh) % 10, // 0x00FFFFFF mask is used to // prevent overflow that causes @@ -887,7 +892,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar { static int dontsetdefstyle; page *thispage = g_this_page; - char *dir = g_usrvars[thispage->parms[4]]; + TCHAR *dir = g_usrvars[thispage->parms[4]]; int browse_text = thispage->parms[3]; if (uMsg == WM_NOTIFY_INIGO_MONTOYA) { @@ -955,7 +960,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar } if (id == IDC_BROWSE) { - static char bt[NSIS_MAX_STRLEN]; + static TCHAR bt[NSIS_MAX_STRLEN]; BROWSEINFO bi = {0,}; ITEMIDLIST *idlist; bi.hwndOwner = hwndDlg; @@ -975,7 +980,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (g_header->install_directory_auto_append && dir == state_install_directory) // only append to $INSTDIR (bug #1174184) { - const char *post_str = ps_tmpbuf; + const TCHAR *post_str = ps_tmpbuf; GetNSISStringTT(g_header->install_directory_auto_append); // display name gives just the folder name if (lstrcmpi(post_str, g_tmp)) @@ -995,7 +1000,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar } if (uMsg == WM_IN_UPDATEMSG || uMsg == WM_NOTIFY_START) { - static char s[NSIS_MAX_STRLEN]; + static TCHAR s[NSIS_MAX_STRLEN]; int error = 0; int available_set = 0; unsigned total, available; @@ -1026,15 +1031,15 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar // Test for and use the GetDiskFreeSpaceEx API { - BOOL (WINAPI *GDFSE)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER) = - myGetProcAddress(MGA_GetDiskFreeSpaceExA); + BOOL (WINAPI *GDFSE)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER) = + myGetProcAddress(MGA_GetDiskFreeSpaceEx); if (GDFSE) { ULARGE_INTEGER available64; ULARGE_INTEGER a, b; - char *p; + TCHAR *p; WORD *pw = NULL; - while ((char *) pw != s) // trimslashtoend() cut the entire string + while ((TCHAR *) pw != s) // trimslashtoend() cut the entire string { if (GDFSE(s, &available64, &a, &b)) { @@ -1053,7 +1058,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar p = trimslashtoend(s); // trim last backslash pw = (LPWORD) (p - 1); - *pw = CHAR2_TO_WORD('\\', 0); // bring it back, but make the next char null + *pw = CHAR2_TO_WORD(_T('\\'), 0); // bring it back, but make the next TCHAR null } } } @@ -1061,7 +1066,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (!available_set) { DWORD spc, bps, fc, tc; - char *root; + TCHAR *root; // GetDiskFreeSpaceEx accepts any path, but GetDiskFreeSpace accepts only the root mystrcpy(s,dir); @@ -1087,7 +1092,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (available_set) SetSizeText(IDC_SPACEAVAILABLE,LANG_SPACE_AVAIL,available); else - SetUITextNT(IDC_SPACEAVAILABLE,""); + SetUITextNT(IDC_SPACEAVAILABLE,_T("")); } g_exec_flags.instdir_error = error; @@ -1500,8 +1505,8 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar #endif//NSIS_CONFIG_VISIBLE_SUPPORT -void NSISCALL update_status_text(int strtab, const char *text) { - static char tmp[NSIS_MAX_STRLEN*2]; +void NSISCALL update_status_text(int strtab, const TCHAR *text) { + static TCHAR tmp[NSIS_MAX_STRLEN*2]; LVITEM new_item; HWND linsthwnd = insthwnd; if (linsthwnd) @@ -1567,7 +1572,7 @@ static DWORD WINAPI install_thread(LPVOID p) if (s->flags&SF_SELECTED) #endif { - log_printf2("Section: \"%s\"",s->name); + log_printf2(_T("Section: \"%s\""),s->name); if (ExecuteCodeSegment(s->code,progresswnd)) { g_exec_flags.abort++; @@ -1577,7 +1582,7 @@ static DWORD WINAPI install_thread(LPVOID p) #ifdef NSIS_CONFIG_COMPONENTPAGE else { - log_printf2("Skipping section: \"%s\"",s->name); + log_printf2(_T("Skipping section: \"%s\""),s->name); } #endif s++; @@ -1611,7 +1616,7 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa progress_bar_len=sumsecsfield(code_size); progress_bar_pos=0; - log_printf3("New install of \"%s\" to \"%s\"",GetNSISStringTT(LANG_NAME),state_install_directory); + log_printf3(_T("New install of \"%s\" to \"%s\""),GetNSISStringTT(LANG_NAME),state_install_directory); GetClientRect(linsthwnd, &r); lvc.cx = r.right - GetSystemMetrics(SM_CXHSCROLL); @@ -1718,14 +1723,14 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa // Clipboard MSDN docs say mem must be GMEM_MOVEABLE OpenClipboard(0); EmptyClipboard(); - memory = GlobalAlloc(GHND,total); + memory = GlobalAlloc(GHND,total*sizeof(TCHAR)); ptr = GlobalLock(memory); //endPtr = ptr+total-2; // -2 to allow for CR/LF i = 0; do { item.pszText = ptr; ptr += SendMessage(linsthwnd,LVM_GETITEMTEXT,i,(LPARAM)&item); - *(WORD*)ptr = CHAR2_TO_WORD('\r','\n'); + *(WORD*)ptr = CHAR2_TO_WORD(_T('\r'),_T('\n')); ptr+=2; } while (++i < count); // memory is auto zeroed when allocated with GHND - *ptr = 0; diff --git a/Source/exehead/api.h b/Source/exehead/api.h index 7418b873..bab95222 100644 --- a/Source/exehead/api.h +++ b/Source/exehead/api.h @@ -64,7 +64,7 @@ typedef struct typedef struct { exec_flags_t *exec_flags; int (NSISCALL *ExecuteCodeSegment)(int, HWND); - void (NSISCALL *validate_filename)(char *); + void (NSISCALL *validate_filename)(TCHAR *); int (NSISCALL *RegisterPluginCallback)(HMODULE, NSISPLUGINCALLBACK); // returns 0 on success, 1 if already registered and < 0 on errors } extra_parameters; diff --git a/Source/exehead/bgbg.c b/Source/exehead/bgbg.c index 9285aaec..67eaca89 100644 --- a/Source/exehead/bgbg.c +++ b/Source/exehead/bgbg.c @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/22/2007 */ #include "../Platform.h" diff --git a/Source/exehead/components.c b/Source/exehead/components.c index 87087a33..6b6bd54d 100644 --- a/Source/exehead/components.c +++ b/Source/exehead/components.c @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/22/2007 */ #include "../Platform.h" diff --git a/Source/exehead/components.h b/Source/exehead/components.h index 7a9af481..27896c7b 100644 --- a/Source/exehead/components.h +++ b/Source/exehead/components.h @@ -12,6 +12,9 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * + * Reviewed for Unicode support by Jim Park -- 08/22/2007 */ #ifndef ___COMPONENTS_H___ diff --git a/Source/exehead/config.h b/Source/exehead/config.h index 2c86cf85..4218781e 100644 --- a/Source/exehead/config.h +++ b/Source/exehead/config.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/22/2007 */ #ifndef NSIS_CONFIG_H diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index bf76f865..14fca41f 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ #include "../Platform.h" @@ -27,6 +29,7 @@ #include "lang.h" #include "resource.h" #include "api.h" +#include "../tchar.h" #define EXEC_ERROR 0x7FFFFFFF @@ -37,7 +40,7 @@ HWND g_SectionHack; #ifdef NSIS_SUPPORT_STACK typedef struct _stack_t { struct _stack_t *next; - char text[NSIS_MAX_STRLEN]; + TCHAR text[NSIS_MAX_STRLEN]; } stack_t; static stack_t *g_st; @@ -59,6 +62,11 @@ HRESULT g_hres; static int NSISCALL ExecuteEntry(entry *entry_); +/** + * If v is negative, then the address to resolve is actually + * stored in the global user variables. Convert the value + * to integer and return. + */ int NSISCALL resolveaddr(int v) { if (v < 0) @@ -107,7 +115,7 @@ int NSISCALL ExecuteCallbackFunction(int num) #endif -static char bufs[5][NSIS_MAX_STRLEN]; +static TCHAR bufs[5][NSIS_MAX_STRLEN]; static int *parms; void NSISCALL update_status_text_buf1(int strtab) @@ -123,10 +131,14 @@ static int NSISCALL GetIntFromParm(int id_) // NB - USE CAUTION when rearranging code to make use of the new return value of // this function - be sure the parm being accessed is not modified before the call. // Use a negative number to get the string validated as a file name -static char * NSISCALL GetStringFromParm(int id_) +// Note: Calling GetNSISString has the side effect that the buffer holding +// the string to expand gets modified. +// When calling this function with numbers like 0x13, it means create the string +// from the string ID found in entry.offset[3] and put it into bufs[0]. +static TCHAR * NSISCALL GetStringFromParm(int id_) { int id = id_ < 0 ? -id_ : id_; - char *result = GetNSISString(bufs[id >> 4], parms[id & 0xF]); + TCHAR *result = GetNSISString(bufs[id >> 4], parms[id & 0xF]); if (id_ < 0) validate_filename(result); return result; } @@ -145,7 +157,7 @@ static LONG NSISCALL myRegDeleteKeyEx(HKEY thiskey, LPCTSTR lpSubKey, int onlyif if (retval==ERROR_SUCCESS) { // NB - don't change this to static (recursive function) - char buffer[MAX_PATH+1]; + TCHAR buffer[MAX_PATH+1]; while (RegEnumKey(key,0,buffer,MAX_PATH+1)==ERROR_SUCCESS) { if (onlyifempty) @@ -157,9 +169,9 @@ static LONG NSISCALL myRegDeleteKeyEx(HKEY thiskey, LPCTSTR lpSubKey, int onlyif } RegCloseKey(key); { - typedef LONG (WINAPI * RegDeleteKeyExAPtr)(HKEY, LPCTSTR, REGSAM, DWORD); - RegDeleteKeyExAPtr RDKE = (RegDeleteKeyExAPtr) - myGetProcAddress(MGA_RegDeleteKeyExA); + typedef LONG (WINAPI * RegDeleteKeyExPtr)(HKEY, LPCTSTR, REGSAM, DWORD); + RegDeleteKeyExPtr RDKE = (RegDeleteKeyExPtr) + myGetProcAddress(MGA_RegDeleteKeyEx); if (RDKE) retval=RDKE(thiskey,lpSubKey,AlterRegistrySAM(0),0); @@ -195,14 +207,14 @@ static HKEY NSISCALL myRegOpenKey(REGSAM samDesired) // otherwise, returns new_position+1 static int NSISCALL ExecuteEntry(entry *entry_) { - char *buf0 = bufs[0]; - char *buf1 = bufs[1]; - char *buf2 = bufs[2]; - char *buf3 = bufs[3]; + TCHAR *buf0 = bufs[0]; + TCHAR *buf1 = bufs[1]; + TCHAR *buf2 = bufs[2]; + TCHAR *buf3 = bufs[3]; //char *buf4 = bufs[4]; - char *var0; - char *var1; + TCHAR *var0; + TCHAR *var1; //char *var2; //char *var3; //char *var4; @@ -239,11 +251,11 @@ static int NSISCALL ExecuteEntry(entry *entry_) switch (which) { case EW_NOP: - log_printf2("Jump: %d",parm0); + log_printf2(_T("Jump: %d"),parm0); return parm0; case EW_ABORT: { - log_printf2("Aborting: \"%s\"",GetStringFromParm(0x00)); + log_printf2(_T("Aborting: \"%s\""),GetStringFromParm(0x00)); update_status_text(parm0,0); } return EXEC_ERROR; @@ -254,23 +266,23 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_CALL: { int v=resolveaddr(parm0)-1; // address is -1, since we encode it as +1 - log_printf2("Call: %d",v); + log_printf2(_T("Call: %d"),v); return ExecuteCodeSegment(v,NULL); } case EW_UPDATETEXT: - log_printf2("detailprint: %s",GetStringFromParm(0x00)); + log_printf2(_T("detailprint: %s"),GetStringFromParm(0x00)); update_status_text(parm0,0); break; case EW_SLEEP: { int x=GetIntFromParm(0); - log_printf2("Sleep(%d)",x); + log_printf2(_T("Sleep(%d)"),x); Sleep(max(x,1)); } break; #ifdef NSIS_CONFIG_VISIBLE_SUPPORT case EW_BRINGTOFRONT: - log_printf("BringToFront"); + log_printf(_T("BringToFront")); SetForegroundWindow(g_hwnd); break; #endif//NSIS_CONFIG_VISIBLE_SUPPORT @@ -302,44 +314,44 @@ static int NSISCALL ExecuteEntry(entry *entry_) #endif//NSIS_CONFIG_VISIBLE_SUPPORT case EW_SETFILEATTRIBUTES: { - char *buf1=GetStringFromParm(-0x10); - log_printf3("SetFileAttributes: \"%s\":%08X",buf1,parm1); + TCHAR *buf1=GetStringFromParm(-0x10); + log_printf3(_T("SetFileAttributes: \"%s\":%08X"),buf1,parm1); if (!SetFileAttributes(buf1,parm1)) { exec_error++; - log_printf("SetFileAttributes failed."); + log_printf(_T("SetFileAttributes failed.")); } } break; case EW_CREATEDIR: { - char *buf1=GetStringFromParm(-0x10); - log_printf3("CreateDirectory: \"%s\" (%d)",buf1,parm1); + TCHAR *buf1=GetStringFromParm(-0x10); + log_printf3(_T("CreateDirectory: \"%s\" (%d)"),buf1,parm1); { - char *p = skip_root(buf1); - char c = 'c'; + TCHAR *p = skip_root(buf1); + TCHAR c = _T('c'); if (p) { while (c) { - p = findchar(p, '\\'); + p = findchar(p, _T('\\')); c = *p; *p = 0; if (!CreateDirectory(buf1, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) - { - log_printf3("CreateDirectory: can't create \"%s\" (err=%d)",buf1,GetLastError()); + { + log_printf3(_T("CreateDirectory: can't create \"%s\" (err=%d)"),buf1,GetLastError()); exec_error++; } else if ((GetFileAttributes(buf1) & FILE_ATTRIBUTE_DIRECTORY) == 0) { - log_printf2("CreateDirectory: can't create \"%s\" - a file already exists",buf1); + log_printf2(_T("CreateDirectory: can't create \"%s\" - a file already exists"),buf1); exec_error++; } } else { - log_printf2("CreateDirectory: \"%s\" created",buf1); + log_printf2(_T("CreateDirectory: \"%s\" created"),buf1); } *p++ = c; } @@ -356,22 +368,22 @@ static int NSISCALL ExecuteEntry(entry *entry_) break; case EW_IFFILEEXISTS: { - char *buf0=GetStringFromParm(0x00); + TCHAR *buf0=GetStringFromParm(0x00); if (file_exists(buf0)) { - log_printf3("IfFileExists: file \"%s\" exists, jumping %d",buf0,parm1); + log_printf3(_T("IfFileExists: file \"%s\" exists, jumping %d"),buf0,parm1); return parm1; } - log_printf3("IfFileExists: file \"%s\" does not exist, jumping %d",buf0,parm2); + log_printf3(_T("IfFileExists: file \"%s\" does not exist, jumping %d"),buf0,parm2); } return parm2; #ifdef NSIS_SUPPORT_RENAME case EW_RENAME: { - char *buf3=GetStringFromParm(-0x30); - char *buf2=GetStringFromParm(-0x21); - char *buf1=GetStringFromParm(0x13); - log_printf2("Rename: %s",buf1); + TCHAR *buf3=GetStringFromParm(-0x30); + TCHAR *buf2=GetStringFromParm(-0x21); + TCHAR *buf1=GetStringFromParm(0x13); + log_printf2(_T("Rename: %s"),buf1); if (MoveFile(buf3,buf2)) { update_status_text_buf1(LANG_RENAME); @@ -383,13 +395,13 @@ static int NSISCALL ExecuteEntry(entry *entry_) { MoveFileOnReboot(buf3,buf2); update_status_text_buf1(LANG_RENAMEONREBOOT); - log_printf2("Rename on reboot: %s",buf1); + log_printf2(_T("Rename on reboot: %s"),buf1); } else #endif { exec_error++; - log_printf2("Rename failed: %s",buf1); + log_printf2(_T("Rename failed: %s"),buf1); } } } @@ -398,9 +410,9 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_FNUTIL case EW_GETFULLPATHNAME: { - char *fp; - char *p=var1; - char *buf0=GetStringFromParm(0x00); + TCHAR *fp; + TCHAR *p=var1; + TCHAR *buf0=GetStringFromParm(0x00); if (!GetFullPathName(buf0,NSIS_MAX_STRLEN,p,&fp)) { exec_error++; @@ -424,9 +436,9 @@ static int NSISCALL ExecuteEntry(entry *entry_) break; case EW_SEARCHPATH: { - char *fp; - char *p=var0; - char *buf0=GetStringFromParm(-0x01); + TCHAR *fp; + TCHAR *p=var0; + TCHAR *buf0=GetStringFromParm(-0x01); if (!SearchPath(NULL,buf0,NULL,NSIS_MAX_STRLEN,p,&fp)) { exec_error++; @@ -436,7 +448,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) break; case EW_GETTEMPFILENAME: { - char *textout=var0; + TCHAR *textout=var0; if (!my_GetTempFileName(textout, GetStringFromParm(-0x11))) exec_error++; } @@ -447,10 +459,10 @@ static int NSISCALL ExecuteEntry(entry *entry_) { HANDLE hOut; int ret; - char *buf3 = GetStringFromParm(0x31); + TCHAR *buf3 = GetStringFromParm(0x31); int overwriteflag = parm0 & 7; - log_printf4("File: overwriteflag=%d, allowskipfilesflag=%d, name=\"%s\"",overwriteflag,(parm0>>3)&MB_ABORTRETRYIGNORE,buf3); + log_printf4(_T("File: overwriteflag=%d, allowskipfilesflag=%d, name=\"%s\""),overwriteflag,(parm0>>3)&MB_ABORTRETRYIGNORE,buf3); if (validpathspec(buf3)) { mystrcpy(buf0,buf3); @@ -481,10 +493,10 @@ static int NSISCALL ExecuteEntry(entry *entry_) { update_status_text(LANG_SKIPPED,buf3); if (overwriteflag==2) exec_error++; - log_printf3("File: skipped: \"%s\" (overwriteflag=%d)",buf0,overwriteflag); + log_printf3(_T("File: skipped: \"%s\" (overwriteflag=%d)"),buf0,overwriteflag); break; } - log_printf2("File: error creating \"%s\"",buf0); + log_printf2(_T("File: error creating \"%s\""),buf0); mystrcpy(buf2,g_usrvars[0]); // save $0 mystrcpy(g_usrvars[0],buf0); // copy file name to $0 @@ -495,14 +507,14 @@ static int NSISCALL ExecuteEntry(entry *entry_) switch (my_MessageBox(buf1, parm0>>3)) { case IDRETRY: - log_printf("File: error, user retry"); + log_printf(_T("File: error, user retry")); goto _tryagain; case IDIGNORE: - log_printf("File: error, user cancel"); + log_printf(_T("File: error, user cancel")); g_exec_flags.exec_error++; return 0; default: - log_printf("File: error, user abort"); + log_printf(_T("File: error, user abort")); update_status_text(LANG_CANTWRITE,buf0); return EXEC_ERROR; } @@ -515,7 +527,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) g_exec_flags.status_update--; } - log_printf3("File: wrote %d to \"%s\"",ret,buf0); + log_printf3(_T("File: wrote %d to \"%s\""),ret,buf0); if (parm3 != 0xffffffff || parm4 != 0xffffffff) SetFileTime(hOut,(FILETIME*)(lent.offsets+3),NULL,(FILETIME*)(lent.offsets+3)); @@ -533,7 +545,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) { GetNSISString(buf0,LANG_ERRORDECOMPRESSING); } - log_printf2("%s",buf0); + log_printf2(_T("%s"),buf0); my_MessageBox(buf0,MB_OK|MB_ICONSTOP|(IDOK<<21)); return EXEC_ERROR; } @@ -543,8 +555,8 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_DELETE case EW_DELETEFILE: { - char *buf0=GetStringFromParm(0x00); - log_printf2("Delete: \"%s\"",buf0); + TCHAR *buf0=GetStringFromParm(0x00); + log_printf2(_T("Delete: \"%s\""),buf0); myDelete(buf0,parm1); } break; @@ -553,8 +565,8 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_MESSAGEBOX: // MessageBox { int v; - char *buf3=GetStringFromParm(0x31); - log_printf3("MessageBox: %d,\"%s\"",parm0,buf3); + TCHAR *buf3=GetStringFromParm(0x31); + log_printf3(_T("MessageBox: %d,\"%s\""),parm0,buf3); v=my_MessageBox(buf3,parm0); if (v) { @@ -574,8 +586,8 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_RMDIR case EW_RMDIR: { - char *buf1=GetStringFromParm(-0x10); - log_printf2("RMDir: \"%s\"",buf1); + TCHAR *buf1=GetStringFromParm(-0x10); + log_printf2(_T("RMDir: \"%s\""),buf1); myDelete(buf1,parm1); } @@ -584,7 +596,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_STROPTS case EW_STRLEN: { - char *buf0=GetStringFromParm(0x01); + TCHAR *buf0=GetStringFromParm(0x01); myitoa(var0,mystrlen(buf0)); } break; @@ -593,8 +605,8 @@ static int NSISCALL ExecuteEntry(entry *entry_) int newlen=GetIntFromParm(2); int start=GetIntFromParm(3); int l; - char *p=var0; - char *buf0=GetStringFromParm(0x01); + TCHAR *p=var0; + TCHAR *buf0=GetStringFromParm(0x01); *p=0; if (!parm2 || newlen) { @@ -617,8 +629,8 @@ static int NSISCALL ExecuteEntry(entry *entry_) break; case EW_STRCMP: { - char *buf2=GetStringFromParm(0x20); - char *buf3=GetStringFromParm(0x31); + TCHAR *buf2=GetStringFromParm(0x20); + TCHAR *buf3=GetStringFromParm(0x31); if (!parm4) { // case insensitive if (!lstrcmpi(buf2,buf3)) return parm2; @@ -633,8 +645,8 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_ENVIRONMENT case EW_READENVSTR: { - char *p=var0; - char *buf0=GetStringFromParm(0x01); + TCHAR *p=var0; + TCHAR *buf0=GetStringFromParm(0x01); if (!ExpandEnvironmentStrings(buf0,p,NSIS_MAX_STRLEN) || (parm2 && !lstrcmp(buf0, p))) { @@ -666,7 +678,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_INTOP: { int v,v2; - char *p=var0; + TCHAR *p=var0; v=GetIntFromParm(1); v2=GetIntFromParm(2); switch (parm3) @@ -689,7 +701,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) } break; case EW_INTFMT: { - char *buf0=GetStringFromParm(0x01); + TCHAR *buf0=GetStringFromParm(0x01); wsprintf(var0, buf0, GetIntFromParm(2)); @@ -706,7 +718,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) while (cnt--&&s) s=s->next; if (!s) { - log_printf2("Exch: stack < %d elements",parm2); + log_printf2(_T("Exch: stack < %d elements"),parm2); my_MessageBox(GetNSISStringTT(LANG_INSTCORRUPTED),MB_OK|MB_ICONSTOP|(IDOK<<21)); return EXEC_ERROR; } @@ -718,7 +730,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) { if (!s) { - log_printf("Pop: stack empty"); + log_printf(_T("Pop: stack empty")); exec_error++; break; } @@ -752,12 +764,15 @@ static int NSISCALL ExecuteEntry(entry *entry_) int msg=GetIntFromParm(2); if (parm5>>2) exec_error += !SendMessageTimeout(hwnd,msg,b3,b4,SMTO_NORMAL,parm5>>2,(LPDWORD)&v); + // Jim Park: This sends script messages. Some messages require + // settings for Unicode. This means the user's script may need + // to change for Unicode NSIS. else v=SendMessage(hwnd,msg,b3,b4); } else { - char *buf0=GetStringFromParm(0x01); - char *buf1=GetStringFromParm(0x12); + TCHAR *buf0=GetStringFromParm(0x01); + TCHAR *buf1=GetStringFromParm(0x12); v=(int)FindWindowEx((HWND)b3,(HWND)b4,buf0[0]?buf0:NULL,buf1[0]?buf1:NULL); } @@ -825,7 +840,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) { HWND hw=(HWND)GetIntFromParm(0); int a=GetIntFromParm(1); - if (parm2) log_printf("HideWindow"); + if (parm2) log_printf(_T("HideWindow")); if (!parm3) ShowWindow(hw,a); else @@ -838,20 +853,20 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_SHELLEXEC: // this uses improvements of Andras Varga { int x; - char *buf0=GetStringFromParm(0x00); - char *buf3=GetStringFromParm(0x31); - char *buf2=GetStringFromParm(0x22); - char *buf1=GetStringFromParm(0x15); + TCHAR *buf0=GetStringFromParm(0x00); + TCHAR *buf3=GetStringFromParm(0x31); + TCHAR *buf2=GetStringFromParm(0x22); + TCHAR *buf1=GetStringFromParm(0x15); update_status_text_buf1(LANG_EXECSHELL); x=(int)ShellExecute(g_hwnd,buf0[0]?buf0:NULL,buf3,buf2[0]?buf2:NULL,state_output_directory,parm3); if (x < 33) { - log_printf5("ExecShell: warning: error (\"%s\": file:\"%s\" params:\"%s\")=%d",buf0,buf3,buf2,x); + log_printf5(_T("ExecShell: warning: error (\"%s\": file:\"%s\" params:\"%s\")=%d"),buf0,buf3,buf2,x); exec_error++; } else { - log_printf4("ExecShell: success (\"%s\": file:\"%s\" params:\"%s\")",buf0,buf3,buf2); + log_printf4(_T("ExecShell: success (\"%s\": file:\"%s\" params:\"%s\")"),buf0,buf3,buf2); } } break; @@ -860,15 +875,15 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_EXECUTE: { HANDLE hProc; - char *buf0=GetStringFromParm(0x00); - log_printf2("Exec: command=\"%s\"",buf0); + TCHAR *buf0=GetStringFromParm(0x00); + log_printf2(_T("Exec: command=\"%s\""),buf0); update_status_text(LANG_EXECUTE,buf0); hProc=myCreateProcess(buf0); if (hProc) { - log_printf2("Exec: success (\"%s\")",buf0); + log_printf2(_T("Exec: success (\"%s\")"),buf0); if (parm2) { DWORD lExitCode; @@ -886,7 +901,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) else { exec_error++; - log_printf2("Exec: failed createprocess (\"%s\")",buf0); + log_printf2(_T("Exec: failed createprocess (\"%s\")"),buf0); } } break; @@ -898,9 +913,9 @@ static int NSISCALL ExecuteEntry(entry *entry_) // also allows GetFileTime to be passed a wildcard. { WIN32_FIND_DATA *ffd; - char *highout=var0; - char *lowout=var1; - char *buf0=GetStringFromParm(0x02); + TCHAR *highout=var0; + TCHAR *lowout=var1; + TCHAR *buf0=GetStringFromParm(0x02); ffd=file_exists(buf0); if (ffd) @@ -919,12 +934,12 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_GETDLLVERSION case EW_GETDLLVERSION: { - char *highout=var0; - char *lowout=var1; + TCHAR *highout=var0; + TCHAR *lowout=var1; DWORD s1; VS_FIXEDFILEINFO *pvsf1; DWORD d; - char *buf1=GetStringFromParm(-0x12); + TCHAR *buf1=GetStringFromParm(-0x12); s1=GetFileVersionInfoSize(buf1,&d); *lowout=*highout=0; exec_error++; @@ -935,7 +950,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) if (b1) { UINT uLen; - if (GetFileVersionInfo(buf1,0,s1,b1) && VerQueryValue(b1,"\\",(void*)&pvsf1,&uLen)) + if (GetFileVersionInfo(buf1,0,s1,b1) && VerQueryValue(b1,_T("\\"),(void*)&pvsf1,&uLen)) { myitoa(highout,pvsf1->dwFileVersionMS); myitoa(lowout,pvsf1->dwFileVersionLS); @@ -955,8 +970,8 @@ static int NSISCALL ExecuteEntry(entry *entry_) if (SUCCEEDED(g_hres)) { HANDLE h=NULL; - char *buf1=GetStringFromParm(-0x10); - char *buf0=GetStringFromParm(0x01); + TCHAR *buf1=GetStringFromParm(-0x10); + TCHAR *buf0=GetStringFromParm(0x01); if (parm4) h=GetModuleHandle(buf1); @@ -975,12 +990,12 @@ static int NSISCALL ExecuteEntry(entry *entry_) } else { - void (*func)(HWND,int,char*,void*,void*); + void (*func)(HWND,int,TCHAR*,void*,void*); func=(void*)funke; func( g_hwnd, NSIS_MAX_STRLEN, - (char*)g_usrvars, + (TCHAR*)g_usrvars, #ifdef NSIS_SUPPORT_STACK (void*)&g_st, #else @@ -993,20 +1008,20 @@ static int NSISCALL ExecuteEntry(entry *entry_) else { update_status_text(LANG_CANNOTFINDSYMBOL,buf0); - log_printf3("Error registering DLL: %s not found in %s",buf0,buf1); + log_printf3(_T("Error registering DLL: %s not found in %s"),buf0,buf1); } if (!parm3 && Plugins_CanUnload(h)) FreeLibrary(h); } else { update_status_text_buf1(LANG_COULDNOTLOAD); - log_printf2("Error registering DLL: Could not load %s",buf1); + log_printf2(_T("Error registering DLL: Could not load %s"),buf1); } } else { update_status_text_buf1(LANG_NOOLE); - log_printf("Error registering DLL: Could not initialize OLE"); + log_printf(_T("Error registering DLL: Could not initialize OLE")); } } break; @@ -1014,11 +1029,11 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_CREATESHORTCUT case EW_CREATESHORTCUT: { - char *buf1=GetStringFromParm(-0x10); - char *buf2=GetStringFromParm(-0x21); - char *buf0=GetStringFromParm(0x02); - char *buf3=GetStringFromParm(-0x33); - char *buf4=GetStringFromParm(0x45); + TCHAR *buf1=GetStringFromParm(-0x10); + TCHAR *buf2=GetStringFromParm(-0x21); + TCHAR *buf0=GetStringFromParm(0x02); + TCHAR *buf3=GetStringFromParm(-0x33); + TCHAR *buf4=GetStringFromParm(0x45); HRESULT hres; IShellLink* psl; @@ -1026,7 +1041,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) if (!validpathspec(buf2)) GetStringFromParm(0x21); - log_printf8("CreateShortCut: out: \"%s\", in: \"%s %s\", icon: %s,%d, sw=%d, hk=%d", + log_printf8(_T("CreateShortCut: out: \"%s\", in: \"%s %s\", icon: %s,%d, sw=%d, hk=%d"), buf1,buf2,buf0,buf3,parm4&0xff,(parm4&0xff00)>>8,parm4>>16); hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, @@ -1075,10 +1090,10 @@ static int NSISCALL ExecuteEntry(entry *entry_) { int res; SHFILEOPSTRUCT op; - char *buf0=GetStringFromParm(0x00); - char *buf1=GetStringFromParm(0x11); - char *buf2=GetStringFromParm(0x23); // LANG_COPYTO + buf1 - log_printf3("CopyFiles \"%s\"->\"%s\"",buf0,buf1); + TCHAR *buf0=GetStringFromParm(0x00); + TCHAR *buf1=GetStringFromParm(0x11); + TCHAR *buf2=GetStringFromParm(0x23); // LANG_COPYTO + buf1 + log_printf3(_T("CopyFiles \"%s\"->\"%s\""),buf0,buf1); if (!file_exists(buf0)) { @@ -1127,9 +1142,9 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_INIFILES case EW_WRITEINI: { - char *sec=0, *key=0, *str=0; + TCHAR *sec=0, *key=0, *str=0; #ifdef NSIS_CONFIG_LOG - mystrcpy(buf1,""); + mystrcpy(buf1,_T("")); mystrcpy(buf2,buf1); #endif if (parm0) @@ -1145,18 +1160,18 @@ static int NSISCALL ExecuteEntry(entry *entry_) str=GetStringFromParm(0x22); } buf3=GetStringFromParm(-0x33); - log_printf5("WriteINIStr: wrote [%s] %s=%s in %s",buf0,buf1,buf2,buf3); + log_printf5(_T("WriteINIStr: wrote [%s] %s=%s in %s"),buf0,buf1,buf2,buf3); if (!WritePrivateProfileString(sec,key,str,buf3)) exec_error++; } break; case EW_READINISTR: { - DWORD errstr = CHAR4_TO_DWORD('!', 'N', '~', 0); - char *p=var0; - char *buf0=GetStringFromParm(0x01); - char *buf1=GetStringFromParm(0x12); - char *buf2=GetStringFromParm(-0x23); - GetPrivateProfileString(buf0,buf1,(LPCSTR)&errstr,p,NSIS_MAX_STRLEN-1,buf2); + DWORD errstr = CHAR4_TO_DWORD(_T('!'), _T('N'), _T('~'), 0); + TCHAR *p=var0; + TCHAR *buf0=GetStringFromParm(0x01); + TCHAR *buf1=GetStringFromParm(0x12); + TCHAR *buf2=GetStringFromParm(-0x23); + GetPrivateProfileString(buf0,buf1,(LPCTSTR)&errstr,p,NSIS_MAX_STRLEN-1,buf2); if (*(DWORD*)p == errstr) { exec_error++; @@ -1169,22 +1184,22 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_DELREG: { long res=!ERROR_SUCCESS; - const char *rkn UNUSED=RegKeyHandleToName((HKEY)parm1); + const TCHAR *rkn UNUSED=RegKeyHandleToName((HKEY)parm1); if (!parm4) { HKEY hKey=myRegOpenKey(KEY_SET_VALUE); if (hKey) { - char *buf3=GetStringFromParm(0x33); + TCHAR *buf3=GetStringFromParm(0x33); res = RegDeleteValue(hKey,buf3); - log_printf4("DeleteRegValue: \"%s\\%s\" \"%s\"",rkn,buf2,buf3); + log_printf4(_T("DeleteRegValue: \"%s\\%s\" \"%s\""),rkn,buf2,buf3); RegCloseKey(hKey); } } else { - char *buf2=GetStringFromParm(0x22); - log_printf3("DeleteRegKey: \"%s\\%s\"",rkn,buf2); + TCHAR *buf2=GetStringFromParm(0x22); + log_printf3(_T("DeleteRegKey: \"%s\\%s\""),rkn,buf2); res = myRegDeleteKeyEx(GetRegRootKey(parm1),buf2,parm4&2); } if (res != ERROR_SUCCESS) @@ -1197,9 +1212,9 @@ static int NSISCALL ExecuteEntry(entry *entry_) HKEY rootkey=GetRegRootKey(parm0); int type=parm4; int rtype=parm5; - char *buf0=GetStringFromParm(0x02); - char *buf1=GetStringFromParm(0x11); - const char *rkn UNUSED=RegKeyHandleToName(rootkey); + TCHAR *buf0=GetStringFromParm(0x02); + TCHAR *buf1=GetStringFromParm(0x11); + const TCHAR *rkn UNUSED=RegKeyHandleToName(rootkey); exec_error++; if (RegCreateKeyEx(rootkey,buf1,0,0,0,AlterRegistrySAM(KEY_SET_VALUE),0,&hKey,0) == ERROR_SUCCESS) @@ -1209,31 +1224,31 @@ static int NSISCALL ExecuteEntry(entry *entry_) if (type == REG_SZ) { GetStringFromParm(0x23); - size = mystrlen((char *) data) + 1; + size = (mystrlen((TCHAR *) data) + 1)*sizeof(TCHAR); if (rtype == REG_SZ) { - log_printf5("WriteRegStr: \"%s\\%s\" \"%s\"=\"%s\"",rkn,buf1,buf0,data); + log_printf5(_T("WriteRegStr: \"%s\\%s\" \"%s\"=\"%s\""),rkn,buf1,buf0,data); } else { - log_printf5("WriteRegExpandStr: \"%s\\%s\" \"%s\"=\"%s\"",rkn,buf1,buf0,data); + log_printf5(_T("WriteRegExpandStr: \"%s\\%s\" \"%s\"=\"%s\""),rkn,buf1,buf0,data); } } if (type == REG_DWORD) { *(LPDWORD) data = GetIntFromParm(3); size = sizeof(DWORD); - log_printf5("WriteRegDWORD: \"%s\\%s\" \"%s\"=\"0x%08x\"",rkn,buf1,buf0,*(LPDWORD) data); + log_printf5(_T("WriteRegDWORD: \"%s\\%s\" \"%s\"=\"0x%08x\""),rkn,buf1,buf0,*(LPDWORD) data); } if (type == REG_BINARY) { #ifdef NSIS_CONFIG_LOG - char binbuf[128]; + TCHAR binbuf[128]; #endif // use buf2, buf3 and buf4 - size = GetCompressedDataFromDataBlockToMemory(parm3, data, 3 * NSIS_MAX_STRLEN); + size = GetCompressedDataFromDataBlockToMemory(parm3, data, (3 * NSIS_MAX_STRLEN)*sizeof(TCHAR)); LogData2Hex(binbuf, sizeof(binbuf), data, size); - log_printf5("WriteRegBin: \"%s\\%s\" \"%s\"=\"%s\"",rkn,buf1,buf0,binbuf); + log_printf5(_T("WriteRegBin: \"%s\\%s\" \"%s\"=\"%s\""),rkn,buf1,buf0,binbuf); } if (size >= 0 && RegSetValueEx(hKey,buf0,0,rtype,data,size) == ERROR_SUCCESS) @@ -1242,19 +1257,19 @@ static int NSISCALL ExecuteEntry(entry *entry_) } else { - log_printf4("WriteReg: error writing into \"%s\\%s\" \"%s\"",rkn,buf1,buf0); + log_printf4(_T("WriteReg: error writing into \"%s\\%s\" \"%s\""),rkn,buf1,buf0); } RegCloseKey(hKey); } - else { log_printf3("WriteReg: error creating key \"%s\\%s\"",rkn,buf1); } + else { log_printf3(_T("WriteReg: error creating key \"%s\\%s\""),rkn,buf1); } } break; case EW_READREGSTR: // read registry string { HKEY hKey=myRegOpenKey(KEY_READ); - char *p=var0; - char *buf3=GetStringFromParm(0x33); // buf3 == key name + TCHAR *p=var0; + TCHAR *buf3=GetStringFromParm(0x33); // buf3 == key name p[0]=0; if (hKey) { @@ -1288,7 +1303,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_REGENUM: { HKEY key=myRegOpenKey(KEY_READ); - char *p=var0; + TCHAR *p=var0; int b=GetIntFromParm(3); p[0]=0; if (key) @@ -1311,15 +1326,15 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_FILEFUNCTIONS case EW_FCLOSE: { - char *t=var0; + TCHAR *t=var0; if (*t) CloseHandle((HANDLE)myatoi(t)); } break; case EW_FOPEN: { HANDLE h; - char *handleout=var0; - char *buf1=GetStringFromParm(-0x13); + TCHAR *handleout=var0; + TCHAR *buf1=GetStringFromParm(-0x13); h=myOpenFile(buf1,parm1,parm2); if (h == INVALID_HANDLE_VALUE) { @@ -1336,8 +1351,8 @@ static int NSISCALL ExecuteEntry(entry *entry_) { DWORD dw; int l; - char *t=var0; - if (parm2) + TCHAR *t=var0; + if (parm2) // WriteByte { ((unsigned char *)buf1)[0]=GetIntFromParm(1)&0xff; l=1; @@ -1368,7 +1383,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) while (rpos 200 || !input_len)) { - wsprintf(progress, "... %d%%", MulDiv(input_len_total - input_len, 100, input_len_total)); + wsprintf(progress, _T("... %d%%"), MulDiv(input_len_total - input_len, 100, input_len_total)); update_status_text(0, progress); ltc = tc; } diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h index 0e927021..549edc02 100644 --- a/Source/exehead/fileform.h +++ b/Source/exehead/fileform.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ #include "config.h" @@ -271,7 +273,7 @@ enum { // nsis strings -typedef char NSIS_STRING[NSIS_MAX_STRLEN]; +typedef TCHAR NSIS_STRING[NSIS_MAX_STRLEN]; // Settings common to both installers and uninstallers typedef struct @@ -333,7 +335,7 @@ typedef struct int str_uninstcmd; #endif//NSIS_CONFIG_UNINSTALL_SUPPORT #ifdef NSIS_SUPPORT_MOVEONREBOOT - int str_wininit; + int str_wininit; // Points to the path of wininit.ini #endif//NSIS_SUPPORT_MOVEONREBOOT } header; @@ -376,18 +378,22 @@ typedef struct int name_ptr; // initial name pointer int install_types; // bits set for each of the different install_types, if any. int flags; // SF_* - defined above - int code; - int code_size; + // for labels, it looks like it's only used to track how often it is used. + int code; // The "address" of the start of the code in count of struct entries. + int code_size; // The size of the code in num of entries? int size_kb; - char name[NSIS_MAX_STRLEN]; // '' for invisible sections + TCHAR name[NSIS_MAX_STRLEN]; // '' for invisible sections } section; #define SECTION_OFFSET(field) (FIELD_OFFSET(section, field)/sizeof(int)) typedef struct { - int which; + int which; // EW_* enum. Look at the enum values to see what offsets mean. int offsets[MAX_ENTRY_OFFSETS]; // count and meaning of offsets depend on 'which' + // sometimes they are just straight int values or bool + // values and sometimes they are indices into string + // tables. } entry; // page window proc @@ -478,8 +484,10 @@ typedef struct { #define NS_LANG_CODE 255 #define NS_CODES_START NS_SKIP_CODE +// We are doing this to store an integer value into a char string and we +// don't want false end of string values so we shift then OR with 0x8080 #define CODE_SHORT(x) (WORD)((((WORD)(x) & 0x7F) | (((WORD)(x) & 0x3F80) << 1) | 0x8080)) -#define MAX_CODED 16383 +#define MAX_CODED 16383 // 0x3FFF #define NSIS_INSTDIR_INVALID 1 #define NSIS_INSTDIR_NOT_ENOUGH_SPACE 2 @@ -496,7 +504,7 @@ int NSISCALL isheader(firstheader *h); // returns 0 on not header, length_of_dat // returns 0 on success // on success, m_header will be set to a pointer that should eventually be GlobalFree()'d. // (or m_uninstheader) -const char * NSISCALL loadHeaders(int cl_flags); +const TCHAR * NSISCALL loadHeaders(int cl_flags); int NSISCALL _dodecomp(int offset, HANDLE hFileOut, char *outbuf, int outbuflen); diff --git a/Source/exehead/lang.h b/Source/exehead/lang.h index 824cde99..f1b20618 100644 --- a/Source/exehead/lang.h +++ b/Source/exehead/lang.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ #ifndef _NSIS_LANG_H_ @@ -19,24 +21,27 @@ // generic startup strings (these will never be overridable) -#define _LANG_INVALIDCRC "Installer integrity check has failed. Common causes include\n" \ - "incomplete download and damaged media. Contact the\n" \ - "installer's author to obtain a new copy.\n\n" \ - "More information at:\n" \ - "http://nsis.sf.net/NSIS_Error" +#define _LANG_INVALIDCRC _T("Installer integrity check has failed. Common causes include\n") \ + _T("incomplete download and damaged media. Contact the\n") \ + _T("installer's author to obtain a new copy.\n\n") \ + _T("More information at:\n") \ + _T("http://nsis.sf.net/NSIS_Error") -#define _LANG_ERRORWRITINGTEMP "Error writing temporary file. Make sure your temp folder is valid." +#define _LANG_ERRORWRITINGTEMP _T("Error writing temporary file. Make sure your temp folder is valid.") -#define _LANG_UNINSTINITERROR "Error launching installer" +#define _LANG_UNINSTINITERROR _T("Error launching installer") -#define _LANG_VERIFYINGINST "verifying installer: %d%%" +#define _LANG_VERIFYINGINST _T("verifying installer: %d%%") -#define _LANG_UNPACKING "unpacking data: %d%%" +#define _LANG_UNPACKING _T("unpacking data: %d%%") -#define _LANG_CANTOPENSELF "Error launching installer" // same as uninstiniterror for size +#define _LANG_CANTOPENSELF _T("Error launching installer") // same as uninstiniterror for size -#define _LANG_GENERIC_ERROR "NSIS Error" +#define _LANG_GENERIC_ERROR _T("NSIS Error") +// We store index to the current language table as a negative +// index value - 1. So this macro, undoes that into a valid +// index. #define LANG_STR_TAB(x) cur_langtable[-((int)x+1)] #define LANG_BRANDING -1 diff --git a/Source/exehead/state.h b/Source/exehead/state.h index 94d04f6a..39740b45 100644 --- a/Source/exehead/state.h +++ b/Source/exehead/state.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/22/2007 */ #include "fileform.h" @@ -31,7 +33,7 @@ extern NSIS_STRING g_usrvars[1]; #define state_exe_file g_usrvars[28] #define state_click_next g_usrvars[30] -extern char g_caption[NSIS_MAX_STRLEN*2]; +extern TCHAR g_caption[NSIS_MAX_STRLEN*2]; #ifdef NSIS_CONFIG_VISIBLE_SUPPORT extern HWND g_hwnd; extern HANDLE g_hInstance; diff --git a/Source/exehead/ui.h b/Source/exehead/ui.h index 33da6bf0..232f9d78 100644 --- a/Source/exehead/ui.h +++ b/Source/exehead/ui.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ @@ -21,7 +23,7 @@ extern int *cur_langtable; extern int NSISCALL ui_doinstall(void); -void NSISCALL update_status_text(int strtab, const char *text2); +void NSISCALL update_status_text(int strtab, const TCHAR *text2); extern int ui_dlg_visible; extern HWND m_curwnd; diff --git a/Source/exehead/util.c b/Source/exehead/util.c index ac424dc4..4550725c 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/11/2007 */ #include "../Platform.h" @@ -24,10 +26,11 @@ #include "exec.h" #include "ui.h" #include "resource.h" +#include "../tchar.h" #ifdef NSIS_CONFIG_LOG #if !defined(NSIS_CONFIG_LOG_ODS) && !defined(NSIS_CONFIG_LOG_STDOUT) -char g_log_file[1024]; +TCHAR g_log_file[1024]; #endif #endif @@ -50,7 +53,7 @@ NSIS_STRING g_usrvars[1] __attribute__((section (NSIS_VARS_SECTION))); # endif #endif -HANDLE NSISCALL myCreateProcess(char *cmd) +HANDLE NSISCALL myCreateProcess(TCHAR *cmd) { PROCESS_INFORMATION ProcInfo; static STARTUPINFO StartUp; @@ -61,25 +64,25 @@ HANDLE NSISCALL myCreateProcess(char *cmd) return ProcInfo.hProcess; } -/*BOOL NSISCALL my_SetWindowText(HWND hWnd, const char *val) +/*BOOL NSISCALL my_SetWindowText(HWND hWnd, const TCHAR *val) { return SendMessage(hWnd,WM_SETTEXT,0,(LPARAM)val); }*/ -BOOL NSISCALL my_SetDialogItemText(HWND dlg, UINT idx, const char *val) +BOOL NSISCALL my_SetDialogItemText(HWND dlg, UINT idx, const TCHAR *val) { return SetDlgItemText(dlg,idx,val); // return my_SetWindowText(GetDlgItem(dlg, idx), val); } -int NSISCALL my_GetDialogItemText(UINT idx, char *val) +int NSISCALL my_GetDialogItemText(UINT idx, TCHAR *val) { extern HWND m_curwnd; return GetDlgItemText(m_curwnd, idx, val, NSIS_MAX_STRLEN); // return my_GetWindowText(GetDlgItem(m_curwnd, idx), val, NSIS_MAX_STRLEN); } -int NSISCALL my_MessageBox(const char *text, UINT type) { +int NSISCALL my_MessageBox(const TCHAR *text, UINT type) { int _type = type & 0x001FFFFF; static MSGBOXPARAMS mbp = { sizeof(MSGBOXPARAMS), @@ -112,13 +115,13 @@ int NSISCALL my_MessageBox(const char *text, UINT type) { return MessageBoxIndirect(&mbp); } -void NSISCALL myDelete(char *buf, int flags) +void NSISCALL myDelete(TCHAR *buf, int flags) { - static char lbuf[NSIS_MAX_STRLEN]; + static TCHAR lbuf[NSIS_MAX_STRLEN]; HANDLE h; WIN32_FIND_DATA fd; - char *fn; + TCHAR *fn; int valid_dir=is_valid_instpath(buf); if ((flags & DEL_SIMPLE)) @@ -134,14 +137,14 @@ void NSISCALL myDelete(char *buf, int flags) mystrcpy(lbuf,buf); #ifdef NSIS_SUPPORT_RMDIR if (flags & DEL_DIR) - mystrcat(lbuf,"\\*.*"); + mystrcat(lbuf,_T("\\*.*")); else #endif//NSIS_SUPPORT_RMDIR trimslashtoend(buf); // only append backslash if the path isn't relative to the working directory [bug #1851273] - if (*buf || *lbuf == '\\') - mystrcat(buf,"\\"); + if (*buf || *lbuf == _T('\\')) + mystrcat(buf,_T("\\")); fn=buf+mystrlen(buf); @@ -150,14 +153,14 @@ void NSISCALL myDelete(char *buf, int flags) { do { - char *fdfn = fd.cFileName; - if (*findchar(fdfn, '?') && *fd.cAlternateFileName) + TCHAR *fdfn = fd.cFileName; + if (*findchar(fdfn, _T('?')) && *fd.cAlternateFileName) // name contains unicode, use short name fdfn = fd.cAlternateFileName; #ifdef NSIS_SUPPORT_RMDIR - if (fdfn[0] == '.' && !fdfn[1]) continue; - if (fdfn[0] == '.' && fdfn[1] == '.' && !fdfn[2]) continue; + if (fdfn[0] == _T('.') && !fdfn[1]) continue; + if (fdfn[0] == _T('.') && fdfn[1] == _T('.') && !fdfn[2]) continue; #endif//NSIS_SUPPORT_RMDIR { mystrcpy(fn,fdfn); @@ -172,21 +175,21 @@ void NSISCALL myDelete(char *buf, int flags) } else { - log_printf2("Delete: DeleteFile(\"%s\")",buf); + log_printf2(_T("Delete: DeleteFile(\"%s\")"),buf); remove_ro_attr(buf); if (!DeleteFile(buf)) { #ifdef NSIS_SUPPORT_MOVEONREBOOT if (flags & DEL_REBOOT) { - log_printf2("Delete: DeleteFile on Reboot(\"%s\")",buf); + log_printf2(_T("Delete: DeleteFile on Reboot(\"%s\")"),buf); update_status_text(LANG_DELETEONREBOOT,buf); MoveFileOnReboot(buf,NULL); } else #endif//NSIS_SUPPORT_MOVEONREBOOT { - log_printf2("Delete: DeleteFile failed(\"%s\")",buf); + log_printf2(_T("Delete: DeleteFile failed(\"%s\")"),buf); g_exec_flags.exec_error++; } } @@ -209,27 +212,27 @@ void NSISCALL myDelete(char *buf, int flags) { if (!valid_dir) { - log_printf2("RMDir: RemoveDirectory invalid input(\"%s\")",buf); + log_printf2(_T("RMDir: RemoveDirectory invalid input(\"%s\")"),buf); g_exec_flags.exec_error++; } else if (file_exists(buf)) { addtrailingslash(buf); - log_printf2("RMDir: RemoveDirectory(\"%s\")",buf); + log_printf2(_T("RMDir: RemoveDirectory(\"%s\")"),buf); remove_ro_attr(buf); if (!RemoveDirectory(buf)) { #ifdef NSIS_SUPPORT_MOVEONREBOOT if (flags & DEL_REBOOT) { - log_printf2("RMDir: RemoveDirectory on Reboot(\"%s\")",buf); + log_printf2(_T("RMDir: RemoveDirectory on Reboot(\"%s\")"),buf); update_status_text(LANG_DELETEONREBOOT,buf); MoveFileOnReboot(buf,NULL); } else #endif//NSIS_SUPPORT_MOVEONREBOOT { - log_printf2("RMDir: RemoveDirectory failed(\"%s\")",buf); + log_printf2(_T("RMDir: RemoveDirectory failed(\"%s\")"),buf); g_exec_flags.exec_error++; } } @@ -242,9 +245,9 @@ void NSISCALL myDelete(char *buf, int flags) #endif//NSIS_SUPPORT_RMDIR } -char *NSISCALL addtrailingslash(char *str) +TCHAR *NSISCALL addtrailingslash(TCHAR *str) { - if (lastchar(str)!='\\') mystrcat(str,"\\"); + if (lastchar(str)!=_T('\\')) mystrcat(str,_T("\\")); return str; } @@ -253,7 +256,7 @@ char *NSISCALL addtrailingslash(char *str) return *CharPrev(str,str+mystrlen(str)); }*/ -char * NSISCALL findchar(char *str, char c) +TCHAR * NSISCALL findchar(TCHAR *str, TCHAR c) { while (*str && *str != c) { @@ -262,12 +265,14 @@ char * NSISCALL findchar(char *str, char c) return str; } -char * NSISCALL trimslashtoend(char *buf) +// Separates a full path to the directory portion and file name portion +// and returns the pointer to the filename portion. +TCHAR * NSISCALL trimslashtoend(TCHAR *buf) { - char *p = buf + mystrlen(buf); + TCHAR *p = buf + mystrlen(buf); do { - if (*p == '\\') + if (*p == _T('\\')) break; p = CharPrev(buf, p); } while (p > buf); @@ -277,28 +282,28 @@ char * NSISCALL trimslashtoend(char *buf) return p + 1; } -int NSISCALL validpathspec(char *ubuf) +int NSISCALL validpathspec(TCHAR *ubuf) { - char dl = ubuf[0] | 0x20; // convert alleged drive letter to lower case - return ((*(WORD*)ubuf==CHAR2_TO_WORD('\\','\\')) || (dl >= 'a' && dl <= 'z' && ubuf[1]==':')); + TCHAR dl = ubuf[0] | 0x20; // convert alleged drive letter to lower case + return ((*(WORD*)ubuf==CHAR2_TO_WORD(_T('\\'),_T('\\'))) || (dl >= _T('a') && dl <= _T('z') && ubuf[1]==_T(':'))); } -char * NSISCALL skip_root(char *path) +TCHAR * NSISCALL skip_root(TCHAR *path) { - char *p = CharNext(path); - char *p2 = CharNext(p); + TCHAR *p = CharNext(path); + TCHAR *p2 = CharNext(p); - if (*path && *(WORD*)p == CHAR2_TO_WORD(':', '\\')) + if (*path && *(WORD*)p == CHAR2_TO_WORD(_T(':'), _T('\\'))) { return CharNext(p2); } - else if (*(WORD*)path == CHAR2_TO_WORD('\\','\\')) + else if (*(WORD*)path == CHAR2_TO_WORD(_T('\\'),_T('\\'))) { // skip host and share name int x = 2; while (x--) { - p2 = findchar(p2, '\\'); + p2 = findchar(p2, _T('\\')); if (!*p2) return NULL; p2++; // skip backslash @@ -310,10 +315,10 @@ char * NSISCALL skip_root(char *path) return NULL; } -int NSISCALL is_valid_instpath(char *s) +int NSISCALL is_valid_instpath(TCHAR *s) { - static char tmp[NSIS_MAX_STRLEN]; - char *root; + static TCHAR tmp[NSIS_MAX_STRLEN]; + TCHAR *root; mystrcpy(tmp, s); @@ -330,7 +335,7 @@ int NSISCALL is_valid_instpath(char *s) // not pass as a valid non-root directory. validate_filename(root); - if ((g_flags & CH_FLAGS_NO_ROOT_DIR) && (!*root || *root == '\\')) + if ((g_flags & CH_FLAGS_NO_ROOT_DIR) && (!*root || *root == _T('\\'))) return 0; while (mystrlen(tmp) > root - tmp) @@ -352,12 +357,12 @@ int NSISCALL is_valid_instpath(char *s) return 1; } -char * NSISCALL mystrstri(char *a, const char *b) +TCHAR * NSISCALL mystrstri(TCHAR *a, const TCHAR *b) { int l = mystrlen(b); while (mystrlen(a) >= l) { - char c = a[l]; + TCHAR c = a[l]; a[l] = 0; if (!lstrcmpi(a, b)) { @@ -370,6 +375,8 @@ char * NSISCALL mystrstri(char *a, const char *b) return NULL; } + +// mini_memcpy takes the number of bytes to copy. void NSISCALL mini_memcpy(void *out, const void *in, int len) { char *c_out=(char*)out; @@ -380,14 +387,14 @@ void NSISCALL mini_memcpy(void *out, const void *in, int len) } } -void NSISCALL remove_ro_attr(char *file) +void NSISCALL remove_ro_attr(TCHAR *file) { int attr = GetFileAttributes(file); if (attr != INVALID_FILE_ATTRIBUTES) SetFileAttributes(file,attr&(~FILE_ATTRIBUTE_READONLY)); } -HANDLE NSISCALL myOpenFile(const char *fn, DWORD da, DWORD cd) +HANDLE NSISCALL myOpenFile(const TCHAR *fn, DWORD da, DWORD cd) { int attr = GetFileAttributes(fn); return CreateFile( @@ -401,14 +408,14 @@ HANDLE NSISCALL myOpenFile(const char *fn, DWORD da, DWORD cd) ); } -char * NSISCALL my_GetTempFileName(char *buf, const char *dir) +TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir) { int n = 100; while (n--) { - char prefix[4]; - *(LPDWORD)prefix = CHAR4_TO_DWORD('n', 's', 'a', 0); - prefix[2] += (char)(GetTickCount() % 26); + TCHAR prefix[4]; + *(LPDWORD)prefix = CHAR4_TO_DWORD(_T('n'), _T('s'), _T('a'), 0); + prefix[2] += (TCHAR)(GetTickCount() % 26); if (GetTempFileName(dir, prefix, 0, buf)) return buf; } @@ -420,9 +427,9 @@ char * NSISCALL my_GetTempFileName(char *buf, const char *dir) void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) { BOOL fOk = 0; - typedef BOOL (WINAPI *mfea_t)(LPCSTR lpExistingFileName,LPCSTR lpNewFileName,DWORD dwFlags); + typedef BOOL (WINAPI *mfea_t)(LPCTSTR lpExistingFileName,LPCTSTR lpNewFileName,DWORD dwFlags); mfea_t mfea; - mfea=(mfea_t) myGetProcAddress(MGA_MoveFileExA); + mfea=(mfea_t) myGetProcAddress(MGA_MoveFileEx); if (mfea) { fOk=mfea(pszExisting, pszNew, MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING); @@ -430,20 +437,20 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) if (!fOk) { - static char szRenameLine[1024]; - static char wininit[1024]; - static char tmpbuf[1024]; + static TCHAR szRenameLine[1024]; + static TCHAR wininit[1024]; + static TCHAR tmpbuf[1024]; int cchRenameLine; - static const char szRenameSec[] = "[Rename]\r\n"; + static const TCHAR szRenameSec[] = _T("[Rename]\r\n"); HANDLE hfile; DWORD dwFileSize; DWORD dwBytes; DWORD dwRenameLinePos; - char *pszWinInit; + TCHAR *pszWinInit; int spn; - *(DWORD*)tmpbuf = CHAR4_TO_DWORD('N', 'U', 'L', 0); + *(DWORD*)tmpbuf = CHAR4_TO_DWORD(_T('N'), _T('U'), _T('L'), 0); if (pszNew) { // create the file if it's not already there to prevent GetShortPathName from failing @@ -456,7 +463,7 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) spn = GetShortPathName(pszExisting,wininit,1024); if (!spn || spn > 1024) return; - cchRenameLine = wsprintf(szRenameLine,"%s=%s\r\n",tmpbuf,wininit); + cchRenameLine = wsprintf(szRenameLine,_T("%s=%s\r\n"),tmpbuf,wininit); GetNSISString(wininit, g_header->str_wininit); hfile = myOpenFile(wininit, GENERIC_READ | GENERIC_WRITE, OPEN_ALWAYS); @@ -470,7 +477,7 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) { if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes) { - LPSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec); + LPTSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec); if (pszRenameSecInFile == NULL) { mystrcpy(pszWinInit+dwFileSize, szRenameSec); @@ -479,11 +486,11 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) } else { - char *pszFirstRenameLine = pszRenameSecInFile+10; - char *pszNextSec = mystrstri(pszFirstRenameLine,"\n["); + TCHAR *pszFirstRenameLine = pszRenameSecInFile+10; + TCHAR *pszNextSec = mystrstri(pszFirstRenameLine,_T("\n[")); if (pszNextSec) { - char *p = ++pszNextSec; + TCHAR *p = ++pszNextSec; while (p < pszWinInit + dwFileSize) { p[cchRenameLine] = *p; p++; @@ -515,48 +522,52 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) } #endif -void NSISCALL myRegGetStr(HKEY root, const char *sub, const char *name, char *out, int x64) +// The value of registry->sub->name is stored in out. If failure, then out becomes +// an empty string "". +void NSISCALL myRegGetStr(HKEY root, const TCHAR *sub, const TCHAR *name, TCHAR *out, int x64) { HKEY hKey; *out=0; if (RegOpenKeyEx(root,sub,0,KEY_READ|(x64?KEY_WOW64_64KEY:0),&hKey) == ERROR_SUCCESS) { - DWORD l = NSIS_MAX_STRLEN; + DWORD l = NSIS_MAX_STRLEN*sizeof(TCHAR); DWORD t; - if (RegQueryValueEx(hKey,name,NULL,&t,out,&l ) != ERROR_SUCCESS || (t != REG_SZ && t != REG_EXPAND_SZ)) *out=0; + // Note that RegQueryValueEx returns Unicode strings if _UNICODE is defined for the + // REG_SZ type. + if (RegQueryValueEx(hKey,name,NULL,&t,(LPBYTE)out,&l ) != ERROR_SUCCESS || (t != REG_SZ && t != REG_EXPAND_SZ)) *out=0; out[NSIS_MAX_STRLEN-1]=0; RegCloseKey(hKey); } } -void NSISCALL myitoa(char *s, int d) +void NSISCALL myitoa(TCHAR *s, int d) { - static const char c[] = "%d"; + static const TCHAR c[] = _T("%d"); wsprintf(s,c,d); } -int NSISCALL myatoi(char *s) +int NSISCALL myatoi(TCHAR *s) { unsigned int v=0; int sign=1; // sign of positive - char m=10; // base of 10 - char t='9'; // cap top of numbers at 9 + TCHAR m=10; // base of 10 + TCHAR t=_T('9'); // cap top of numbers at 9 - if (*s == '-') + if (*s == _T('-')) { s++; //skip over - sign=-1; // sign flip } - if (*s == '0') + if (*s == _T('0')) { s++; // skip over 0 - if (s[0] >= '0' && s[0] <= '7') + if (s[0] >= _T('0') && s[0] <= _T('7')) { m=8; // base of 8 - t='7'; // cap top at 7 + t=_T('7'); // cap top at 7 } - if ((s[0] & ~0x20) == 'X') + if ((s[0] & ~0x20) == _T('X')) { m=16; // base of 16 s++; // advance over 'x' @@ -566,8 +577,9 @@ int NSISCALL myatoi(char *s) for (;;) { int c=*s++; - if (c >= '0' && c <= t) c-='0'; - else if (m==16 && (c & ~0x20) >= 'A' && (c & ~0x20) <= 'F') c = (c & 7) + 9; + if (c >= _T('0') && c <= t) c-=_T('0'); + // clever little trick to do both upper and lowercase A-F. + else if (m==16 && (c & ~0x20) >= _T('A') && (c & ~0x20) <= _T('F')) c = (c & 7) + 9; else break; v*=m; v+=c; @@ -578,34 +590,38 @@ int NSISCALL myatoi(char *s) // Straight copies of selected shell functions. Calling local functions // requires less code than DLL functions. For the savings to outweigh the cost // of a new function there should be about a couple of dozen or so calls. -char * NSISCALL mystrcpy(char *out, const char *in) +TCHAR * NSISCALL mystrcpy(TCHAR *out, const TCHAR *in) { return lstrcpyn(out, in, NSIS_MAX_STRLEN); } -int NSISCALL mystrlen(const char *in) +int NSISCALL mystrlen(const TCHAR *in) { return lstrlen(in); } -char * NSISCALL mystrcat(char *out, const char *concat) +TCHAR * NSISCALL mystrcat(TCHAR *out, const TCHAR *concat) { return lstrcat(out, concat); } -char ps_tmpbuf[NSIS_MAX_STRLEN*2]; +TCHAR ps_tmpbuf[NSIS_MAX_STRLEN*2]; -const char SYSREGKEY[] = "Software\\Microsoft\\Windows\\CurrentVersion"; -const char QUICKLAUNCH[] = "\\Microsoft\\Internet Explorer\\Quick Launch"; +const TCHAR SYSREGKEY[] = _T("Software\\Microsoft\\Windows\\CurrentVersion"); +const TCHAR QUICKLAUNCH[] = _T("\\Microsoft\\Internet Explorer\\Quick Launch"); -typedef HRESULT (__stdcall * PFNSHGETFOLDERPATHA)(HWND, int, HANDLE, DWORD, LPSTR); +typedef HRESULT (__stdcall * PFNSHGETFOLDERPATH)(HWND, int, HANDLE, DWORD, LPTSTR); extern void *g_SHGetFolderPath; // Based on Dave Laundon's simplified process_string -char * NSISCALL GetNSISString(char *outbuf, int strtab) +// The string actually has a lot of different data encoded into it. This +// function extracts the special data out and puts it into outbuf. +TCHAR * NSISCALL GetNSISString(TCHAR *outbuf, int strtab) { - char *in = (char*)GetNSISStringNP(GetNSISTab(strtab)); - char *out = ps_tmpbuf; + // This looks at the g_block (copied from header->blocks) and + // indexes into the language + TCHAR *in = (TCHAR*)GetNSISStringNP(GetNSISTab(strtab)); + TCHAR *out = ps_tmpbuf; if ((unsigned int) (outbuf - ps_tmpbuf) < sizeof(ps_tmpbuf)) { out = outbuf; @@ -613,7 +629,7 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab) } while (*in && out - ps_tmpbuf < NSIS_MAX_STRLEN) { - unsigned char nVarIdx = (unsigned char)*in++; + _TUCHAR nVarIdx = (_TUCHAR)*in++; int nData; int fldrs[4]; if (nVarIdx > NS_CODES_START) @@ -623,7 +639,7 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab) fldrs[1] = in[0]; fldrs[2] = in[1] | CSIDL_FLAG_CREATE; // all users fldrs[3] = in[1]; - in += 2; + in += sizeof(SHORT)/sizeof(TCHAR); if (nVarIdx == NS_SHELL_CODE) { @@ -689,7 +705,7 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab) { if (g_SHGetFolderPath && use_shfolder) { - PFNSHGETFOLDERPATHA SHGetFolderPathFunc = (PFNSHGETFOLDERPATHA) g_SHGetFolderPath; + PFNSHGETFOLDERPATH SHGetFolderPathFunc = (PFNSHGETFOLDERPATH) g_SHGetFolderPath; if (!SHGetFolderPathFunc(g_hwnd, fldrs[x], NULL, SHGFP_TYPE_CURRENT, out)) { break; @@ -751,15 +767,15 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab) return ps_tmpbuf; } -void NSISCALL validate_filename(char *in) { - char *nono = "*?|<>/\":"; - char *out; - char *out_save; +void NSISCALL validate_filename(TCHAR *in) { + TCHAR *nono = _T("*?|<>/\":"); + TCHAR *out; + TCHAR *out_save; - // ignoring spaces is wrong, " C:\blah" is invalid - //while (*in == ' ') in = CharNext(in); + // ignoring spaces is wrong, _T(" C:\blah") is invalid + //while (*in == _T(' ')) in = CharNext(in); - if (in[0] == '\\' && in[1] == '\\' && in[2] == '?' && in[3] == '\\') + if (in[0] == _T('\\') && in[1] == _T('\\') && in[2] == _T('?') && in[3] == _T('\\')) { // at least four bytes in += 4; @@ -772,7 +788,7 @@ void NSISCALL validate_filename(char *in) { out = out_save = in; while (*in) { - if ((unsigned char)*in > 31 && !*findchar(nono, *in)) + if ((_TUCHAR)*in > 31 && !*findchar(nono, *in)) { mini_memcpy(out, in, CharNext(in) - in); out = CharNext(out); @@ -783,7 +799,7 @@ void NSISCALL validate_filename(char *in) { do { out = CharPrev(out_save, out); - if (*out == ' ' || *out == '\\') + if (*out == _T(' ') || *out == _T('\\')) *out = 0; else break; @@ -792,7 +808,7 @@ void NSISCALL validate_filename(char *in) { #ifdef NSIS_CONFIG_LOG int log_dolog; -char log_text[2048]; // 1024 for each wsprintf +TCHAR log_text[2048]; // 1024 for each wsprintf #if !defined(NSIS_CONFIG_LOG_ODS) && !defined(NSIS_CONFIG_LOG_STDOUT) void NSISCALL log_write(int close) @@ -818,36 +834,36 @@ void NSISCALL log_write(int close) if (fp!=INVALID_HANDLE_VALUE) { DWORD d; - mystrcat(log_text,"\r\n"); - WriteFile(fp,log_text,mystrlen(log_text),&d,NULL); + mystrcat(log_text,_T("\r\n")); + WriteFile(fp,log_text,mystrlen(log_text)*sizeof(TCHAR),&d,NULL); } } } #endif//!NSIS_CONFIG_LOG_ODS && !NSIS_CONFIG_LOG_STDOUT -const char * _RegKeyHandleToName(HKEY hKey) +const TCHAR * _RegKeyHandleToName(HKEY hKey) { if (hKey == HKEY_CLASSES_ROOT) - return "HKEY_CLASSES_ROOT"; + return _T("HKEY_CLASSES_ROOT"); else if (hKey == HKEY_CURRENT_USER) - return "HKEY_CURRENT_USER"; + return _T("HKEY_CURRENT_USER"); else if (hKey == HKEY_LOCAL_MACHINE) - return "HKEY_LOCAL_MACHINE"; + return _T("HKEY_LOCAL_MACHINE"); else if (hKey == HKEY_USERS) - return "HKEY_USERS"; + return _T("HKEY_USERS"); else if (hKey == HKEY_PERFORMANCE_DATA) - return "HKEY_PERFORMANCE_DATA"; + return _T("HKEY_PERFORMANCE_DATA"); else if (hKey == HKEY_CURRENT_CONFIG) - return "HKEY_CURRENT_CONFIG"; + return _T("HKEY_CURRENT_CONFIG"); else if (hKey == HKEY_DYN_DATA) - return "HKEY_DYN_DATA"; + return _T("HKEY_DYN_DATA"); else - return "invalid registry key"; + return _T("invalid registry key"); } -void _LogData2Hex(char *buf, size_t buflen, unsigned char *data, size_t datalen) +void _LogData2Hex(TCHAR *buf, size_t buflen, BYTE *data, size_t datalen) { - char *p = buf; + TCHAR *p = buf; size_t i; @@ -864,31 +880,31 @@ void _LogData2Hex(char *buf, size_t buflen, unsigned char *data, size_t datalen) for (i = 0; i < bufbytes; i++) { - wsprintf(p, "%02x%c", data[i], (i == bufbytes - 1) ? '\0' : ' '); + wsprintf(p, _T("%02x%c"), data[i], (i == bufbytes - 1) ? _T('\0') : _T(' ')); p += 3; } if (dots) - mystrcat(buf, "..."); + mystrcat(buf, _T("...")); } #ifdef NSIS_CONFIG_LOG_TIMESTAMP -void log_timestamp(char *buf) +void log_timestamp(TCHAR *buf) { SYSTEMTIME st; GetLocalTime(&st); - wsprintf(buf,"[%04hu/%02hu/%02hu %02hu:%02hu:%02hu] ", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); + wsprintf(buf,_T("[%04hu/%02hu/%02hu %02hu:%02hu:%02hu] "), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); } #else # define log_timestamp(x) #endif//NSIS_CONFIG_LOG_TIMESTAMP -void log_printf(char *format, ...) +void log_printf(TCHAR *format, ...) { va_list val; va_start(val,format); - log_text[0] = '\0'; + log_text[0] = _T('\0'); log_timestamp(log_text); wvsprintf(log_text+mystrlen(log_text),format,val); @@ -902,7 +918,7 @@ void log_printf(char *format, ...) { DWORD dwBytes; WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), log_text, lstrlen(log_text), &dwBytes, NULL); - WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), "\n", 1, &dwBytes, NULL); + WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), _T("\n"), 1, &dwBytes, NULL); } #endif #if !defined(NSIS_CONFIG_LOG_ODS) && !defined(NSIS_CONFIG_LOG_STDOUT) @@ -911,7 +927,8 @@ void log_printf(char *format, ...) } #endif//NSIS_CONFIG_LOG -WIN32_FIND_DATA * NSISCALL file_exists(char *buf) +// Jim Park: This function is non-reentrant because of the static. +WIN32_FIND_DATA * NSISCALL file_exists(TCHAR *buf) { HANDLE h; static WIN32_FIND_DATA fd; @@ -924,6 +941,8 @@ WIN32_FIND_DATA * NSISCALL file_exists(char *buf) return NULL; } +// Jim Park: Keep these as chars since there's only ANSI version of +// GetProcAddress. struct MGA_FUNC { const char *dll; @@ -942,12 +961,20 @@ struct MGA_FUNC MGA_FUNCS[] = { {"SHFOLDER", "SHGetFolderPathA"} }; +/** + * Given a function enum, it will load the appropriate DLL and get the + * process address of the function and return the pointer. It's up to + * the caller to know how to call that function, however. + * + * @param func Enum value that indexes the MGA_FUNCS array. + * @return Pointer to the function identified by the enum value. + */ void * NSISCALL myGetProcAddress(const enum myGetProcAddressFunctions func) { const char *dll = MGA_FUNCS[func].dll; - HMODULE hModule = GetModuleHandle(dll); + HMODULE hModule = GetModuleHandleA(dll); if (!hModule) - hModule = LoadLibrary(dll); + hModule = LoadLibraryA(dll); if (!hModule) return NULL; diff --git a/Source/exehead/util.h b/Source/exehead/util.h index ab8dd1be..6563e67d 100644 --- a/Source/exehead/util.h +++ b/Source/exehead/util.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 07/23/2007 */ #ifndef ___NSIS_UTIL_H___ @@ -21,36 +23,40 @@ #include "config.h" #include -extern char ps_tmpbuf[NSIS_MAX_STRLEN*2]; -char * NSISCALL GetNSISString(char *outbuf, int strtab); +extern TCHAR ps_tmpbuf[NSIS_MAX_STRLEN*2]; +TCHAR * NSISCALL GetNSISString(TCHAR *outbuf, int strtab); #define GetNSISStringTT(strtab) GetNSISString(0, (strtab)) -#define GetNSISStringNP(strtab) ((const char *)g_blocks[NB_STRINGS].offset+(strtab)) -#define GetNSISTab(strtab) (strtab < 0 ? LANG_STR_TAB(strtab) : strtab) -void NSISCALL myRegGetStr(HKEY root, const char *sub, const char *name, char *out, int x64); -int NSISCALL myatoi(char *s); -void NSISCALL myitoa(char *s, int d); -char * NSISCALL mystrcpy(char *out, const char *in); -int NSISCALL mystrlen(const char *in); -char * NSISCALL mystrcat(char *out, const char *concat); -char * NSISCALL mystrstr(char *a, char *b); -WIN32_FIND_DATA * NSISCALL file_exists(char *buf); -char * NSISCALL my_GetTempFileName(char *buf, const char *dir); +#define GetNSISStringNP(strtab) ((const TCHAR *)g_blocks[NB_STRINGS].offset+(strtab)) -//BOOL NSISCALL my_SetWindowText(HWND hWnd, const char *val); +// A negative string table index means it's a language string table, so we +// use the LANG_STR_TAB() macro to decode it. +#define GetNSISTab(strtab) (strtab < 0 ? LANG_STR_TAB(strtab) : strtab) + +void NSISCALL myRegGetStr(HKEY root, const TCHAR *sub, const TCHAR *name, TCHAR *out, int x64); +int NSISCALL myatoi(TCHAR *s); +void NSISCALL myitoa(TCHAR *s, int d); +TCHAR * NSISCALL mystrcpy(TCHAR *out, const TCHAR *in); +int NSISCALL mystrlen(const TCHAR *in); +TCHAR * NSISCALL mystrcat(TCHAR *out, const TCHAR *concat); +TCHAR * NSISCALL mystrstr(TCHAR *a, TCHAR *b); +WIN32_FIND_DATA * NSISCALL file_exists(TCHAR *buf); +TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir); + +//BOOL NSISCALL my_SetWindowText(HWND hWnd, const TCHAR *val); #define my_SetWindowText SetWindowText -BOOL NSISCALL my_SetDialogItemText(HWND dlg, UINT idx, const char *val); +BOOL NSISCALL my_SetDialogItemText(HWND dlg, UINT idx, const TCHAR *val); //#define my_SetDialogItemText SetDlgItemText -//int NSISCALL my_GetWindowText(HWND hWnd, char *val, int size); +//int NSISCALL my_GetWindowText(HWND hWnd, TCHAR *val, int size); #define my_GetWindowText GetWindowText -int NSISCALL my_GetDialogItemText(UINT idx, char *val); +int NSISCALL my_GetDialogItemText(UINT idx, TCHAR *val); //#define my_GetDialogItemText GetDlgItemText #ifdef NSIS_CONFIG_LOG -extern char log_text[2048]; +extern TCHAR log_text[2048]; void NSISCALL log_write(int close); -const char * _RegKeyHandleToName(HKEY hKey); -void _LogData2Hex(char *buf, size_t buflen, unsigned char *data, size_t datalen); -void log_printf(char *format, ...); +const TCHAR * _RegKeyHandleToName(HKEY hKey); +void _LogData2Hex(TCHAR *buf, size_t buflen, BYTE *data, size_t datalen); +void log_printf(TCHAR *format, ...); #define log_printf2(x1,x2) log_printf(x1,x2); #define log_printf3(x1,x2,x3) log_printf(x1,x2,x3); #define log_printf4(x1,x2,x3,x4) log_printf(x1,x2,x3,x4); @@ -61,7 +67,7 @@ void log_printf(char *format, ...); #define RegKeyHandleToName(x1) _RegKeyHandleToName(x1); #define LogData2Hex(x1,x2,x3,x4) _LogData2Hex(x1,x2,x3,x4); extern int log_dolog; -extern char g_log_file[1024]; +extern TCHAR g_log_file[1024]; #else #define log_printf(x1) #define log_printf2(x1,x2) @@ -75,35 +81,44 @@ extern char g_log_file[1024]; #define LogData2Hex(x1,x2,x3,x4) #endif -HANDLE NSISCALL myCreateProcess(char *cmd); -int NSISCALL my_MessageBox(const char *text, UINT type); +HANDLE NSISCALL myCreateProcess(TCHAR *cmd); +int NSISCALL my_MessageBox(const TCHAR *text, UINT type); -void NSISCALL myDelete(char *buf, int flags); +void NSISCALL myDelete(TCHAR *buf, int flags); -HANDLE NSISCALL myOpenFile(const char *fn, DWORD da, DWORD cd); -int NSISCALL validpathspec(char *ubuf); -char * NSISCALL addtrailingslash(char *str); -//char NSISCALL lastchar(const char *str); +HANDLE NSISCALL myOpenFile(const TCHAR *fn, DWORD da, DWORD cd); +int NSISCALL validpathspec(TCHAR *ubuf); +TCHAR * NSISCALL addtrailingslash(TCHAR *str); +//TCHAR NSISCALL lastchar(const TCHAR *str); #define lastchar(str) *CharPrev(str,str+mystrlen(str)) -char * NSISCALL findchar(char *str, char c); -char * NSISCALL trimslashtoend(char *buf); -char * NSISCALL skip_root(char *path); -int NSISCALL is_valid_instpath(char *s); -void NSISCALL validate_filename(char *fn); +TCHAR * NSISCALL findchar(TCHAR *str, TCHAR c); +TCHAR * NSISCALL trimslashtoend(TCHAR *buf); +TCHAR * NSISCALL skip_root(TCHAR *path); +int NSISCALL is_valid_instpath(TCHAR *s); +void NSISCALL validate_filename(TCHAR *fn); + +/** + * MoveFileOnReboot tries to move a file by the name of pszExisting to the + * name pszNew. + * + * @param pszExisting The old name of the file. + * @param pszNew The new name of the file. + */ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew); + void NSISCALL mini_memcpy(void *out, const void *in, int len); -void NSISCALL remove_ro_attr(char *file); +void NSISCALL remove_ro_attr(TCHAR *file); enum myGetProcAddressFunctions { - MGA_GetDiskFreeSpaceExA, - MGA_MoveFileExA, - MGA_RegDeleteKeyExA, + MGA_GetDiskFreeSpaceEx, + MGA_MoveFileEx, + MGA_RegDeleteKeyEx, MGA_OpenProcessToken, - MGA_LookupPrivilegeValueA, + MGA_LookupPrivilegeValue, MGA_AdjustTokenPrivileges, MGA_GetUserDefaultUILanguage, MGA_SHAutoComplete, - MGA_SHGetFolderPathA + MGA_SHGetFolderPath }; void * NSISCALL myGetProcAddress(const enum myGetProcAddressFunctions func); diff --git a/Source/fileform.cpp b/Source/fileform.cpp index 72296bab..e2cc79a7 100644 --- a/Source/fileform.cpp +++ b/Source/fileform.cpp @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ #include "fileform.h" @@ -184,6 +186,7 @@ void lang_table_writer::write(const unsigned char *data) void lang_table_writer::write_block(IGrowBuf *buf, writer_sink *sink, const size_t table_size) { unsigned char *tables = (unsigned char *) buf->get(); + // langtable has LANGID(WORD) + dlgoffset(int) + right-to-left(int) + string pointers. size_t lang_strings = ( table_size - 2 * sizeof(int) - sizeof(LANGID) ) / sizeof(int); size_t l = buf->getlen() / table_size; lang_table_writer writer(sink, lang_strings); diff --git a/Source/fileform.h b/Source/fileform.h index a92b6985..30661527 100644 --- a/Source/fileform.h +++ b/Source/fileform.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ #ifndef ___MAKENSIS_FILEFORM_H___ diff --git a/Source/growbuf.cpp b/Source/growbuf.cpp index 6ad76973..f0a7169a 100644 --- a/Source/growbuf.cpp +++ b/Source/growbuf.cpp @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support and Doxygen comments by Jim Park -- 07/31/2007 */ #include "growbuf.h" @@ -20,12 +22,16 @@ #include // for memcpy #include // for f* #include // for std::min +#include "tchar.h" #include "Platform.h" using namespace std; +// Default constructor GrowBuf::GrowBuf() { m_alloc=m_used=m_zero=0; m_s=NULL; m_bs=32768; } + +// Destructor GrowBuf::~GrowBuf() { free(m_s); } void GrowBuf::set_zeroing(int zero) { m_zero=zero; } @@ -34,18 +40,22 @@ int GrowBuf::add(const void *data, int len) { if (len<=0) return 0; resize(m_used+len); - memcpy((char*)m_s+m_used-len,data,len); + memcpy((BYTE*)m_s+m_used-len,data,len); return m_used-len; } void GrowBuf::resize(int newlen) { - int os=m_alloc; - int ou=m_used; + int os=m_alloc; // old size + int ou=m_used; // old used m_used=newlen; if (newlen > m_alloc) { void *n; + + // Jim Park: Not sure why we don't just add m_bs. Multiplying by 2 + // makes m_bs meaningless after a few resizes. So TinyGrowBuf + // isn't very tiny. m_alloc = newlen*2 + m_bs; n = realloc(m_s, m_alloc); if (!n) @@ -54,7 +64,7 @@ void GrowBuf::resize(int newlen) extern int g_display_errors; if (g_display_errors) { - fprintf(g_output,"\nack! realloc(%d) failed, trying malloc(%d)!\n",m_alloc,newlen); + _ftprintf(g_output,_T("\nack! realloc(%d) failed, trying malloc(%d)!\n"),m_alloc,newlen); fflush(g_output); } m_alloc=newlen; // try to malloc the minimum needed @@ -64,7 +74,7 @@ void GrowBuf::resize(int newlen) extern void quit(); if (g_display_errors) { - fprintf(g_output,"\nInternal compiler error #12345: GrowBuf realloc/malloc(%d) failed.\n",m_alloc); + _ftprintf(g_output,_T("\nInternal compiler error #12345: GrowBuf realloc/malloc(%d) failed.\n"),m_alloc); fflush(g_output); } quit(); @@ -74,9 +84,13 @@ void GrowBuf::resize(int newlen) } m_s=n; } + + // Zero out the new buffer area if (m_zero && m_used > ou) - memset((char*)m_s + ou, 0, m_used - ou); - if (!m_used && m_alloc > 2*m_bs) // only free if you resize to 0 and we're > 64k + memset((BYTE*)m_s + ou, 0, m_used - ou); + + if (!m_used && m_alloc > 2*m_bs) // only free if you resize to 0 and we're > 64k or + // 2K in the case of TinyGrowBuf { m_alloc=0; free(m_s); diff --git a/Source/growbuf.h b/Source/growbuf.h index dcbbae23..1b7fb7b3 100644 --- a/Source/growbuf.h +++ b/Source/growbuf.h @@ -12,21 +12,52 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/22/2007 */ #ifndef __GROWBUF_H_ #define __GROWBUF_H_ +/** + * IGrowBuf is the interface to a buffer that grows as you + * add to the buffer. + */ class IGrowBuf { public: virtual ~IGrowBuf() {} + + /** + * Add data to the buffer. + * @param data Pointer to the data to be stored. + * @param len Size of the data in bytes. + * @return the previous logical size in bytes before the addition. + */ virtual int add(const void *data, int len)=0; + + /** + * Resizes the buffer to hold the number of bytes specified. + * @param newlen the desired logical size of the buffer. + */ virtual void resize(int newlen)=0; + + /** + * Get the length of the logical buffer in bytes. + * @return the length in bytes + */ virtual int getlen() const=0; + + /** + * Get the buffer itself. + * @return Void pointer to the buffer. + */ virtual void *get() const=0; }; +/** + * GrowBuf implements IGrowBuf and grows in 32K chunks. + */ class GrowBuf : public IGrowBuf { private: // don't copy instances @@ -37,22 +68,55 @@ class GrowBuf : public IGrowBuf GrowBuf(); virtual ~GrowBuf(); + /** + * Set whether to zero out buffer + * @param zero A boolean value. + */ void set_zeroing(int zero); + + /** + * Add data to the buffer. + * @param data Pointer to the data to be stored. + * @param len Size of the data in bytes. + * @return the previous logical size in bytes before the addition. + */ int add(const void *data, int len); + + /** + * Resizes the buffer to hold the number of bytes specified. + * @param newlen the desired logical size of the buffer. + */ void resize(int newlen); + + /** + * Get the length of the logical buffer in bytes. + * Setting the newlen to 0 will cause the buffer to be at most + * 2*m_bs bytes long. (It will free the buffer if > 2*m_bs.) + * + * @return the length in bytes + */ int getlen() const; + + /** + * Get the buffer itself. + * @return Void pointer to the buffer. + */ void *get() const; private: - void *m_s; - int m_alloc; - int m_used; - int m_zero; + void *m_s; /* the storage buffer */ + int m_alloc; /* allocated bytes */ + int m_used; /* how many bytes of the buffer is used? */ + int m_zero; /* should storage be zeroed out? */ protected: - int m_bs; + int m_bs; // byte-size to grow by }; +/** + * TinyGrowBuf is a derived class that grows the buffer + * in tiny increments. + */ class TinyGrowBuf : public GrowBuf { public: TinyGrowBuf() : GrowBuf() { m_bs=1024; } diff --git a/Source/icon.cpp b/Source/icon.cpp index 1de25ad4..bbf06e2d 100644 --- a/Source/icon.cpp +++ b/Source/icon.cpp @@ -1,3 +1,5 @@ +// Unicode support by Jim Park -- 11/16/2007 + #include "Platform.h" #include "icon.h" #include "util.h" @@ -15,9 +17,9 @@ extern FILE *g_output; #define SIZEOF_RSRC_ICON_GROUP_ENTRY 14 -static FILE * open_icon(const char* filename, IconGroupHeader& igh) +static FILE * open_icon(const TCHAR* filename, IconGroupHeader& igh) { - FILE* f = FOPEN(filename, "rb"); + FILE* f = FOPEN(filename, _T("rb")); if (!f) throw runtime_error("can't open file"); @@ -81,7 +83,7 @@ IconGroup load_icon_res(CResourceEditor* re, WORD id) return result; } -IconGroup load_icon_file(const char* filename) +IconGroup load_icon_file(const TCHAR* filename) { IconGroupHeader iconHeader; IconGroup result; @@ -150,6 +152,7 @@ typedef struct unsigned size_index; } IconPair; + typedef vector IconPairs; static bool compare_icon(Icon a, Icon b) @@ -389,7 +392,7 @@ int generate_unicons_offsets(LPBYTE exeHeader, size_t exeHeaderSize, LPBYTE unin if (offset > exeHeaderSize) { - throw runtime_error("invalid icon offset (possibly compressed icon)"); + throw runtime_error(_T("invalid icon offset (possibly compressed icon)")); } DWORD real_size = re.GetResourceSizeA(RT_ICON, MAKEINTRESOURCE(icon_index), NSIS_DEFAULT_LANG); @@ -413,7 +416,7 @@ int generate_unicons_offsets(LPBYTE exeHeader, size_t exeHeaderSize, LPBYTE unin catch (const exception& e) { if (g_display_errors) - fprintf(g_output, "\nError generating uninstaller icon: %s -- failing!\n", e.what()); + fprintf(g_output, _T("\nError generating uninstaller icon: %s -- failing!\n"), e.what()); return 0; } diff --git a/Source/icon.h b/Source/icon.h index 38aeef91..21cf4a65 100644 --- a/Source/icon.h +++ b/Source/icon.h @@ -14,6 +14,8 @@ * warranty. */ +/* Unicode support by Jim Park -- 11/16/2007 */ + #ifndef _ICON_H_ #define _ICON_H_ @@ -60,7 +62,7 @@ typedef struct typedef std::vector IconGroup; -IconGroup load_icon_file(const char* filename); +IconGroup load_icon_file(const TCHAR* filename); IconGroup load_icon_res(CResourceEditor* re, WORD id); void free_loaded_icon(IconGroup icon); diff --git a/Source/lang.cpp b/Source/lang.cpp index e806a6fe..cb55dccb 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -12,16 +12,20 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support and Doxygen comments by Jim Park -- 07/25/2007 */ #include "Platform.h" #include #include +#include "tchar.h" #include "build.h" #include "util.h" #include "DialogTemplate.h" #include "exehead/resource.h" #include +#include "tstring.h" using namespace std; @@ -37,107 +41,107 @@ typedef enum { } STATICID; struct NLFString { - const char *szLangStringName; - const char *szDefault; + const TCHAR *szLangStringName; + const TCHAR *szDefault; STATICID eStaticID; }; NLFString NLFStrings[NLF_STRINGS] = { - {"^Branding", "Nullsoft Install System %s", BOTH_STATIC}, - {"^SetupCaption", "$(^Name) Setup", INSTALL_STATIC}, - {"^UninstallCaption", "$(^Name) Uninstall", UNINSTALL_STATIC}, - {"^LicenseSubCaption", ": License Agreement", NONE_STATIC}, - {"^ComponentsSubCaption", ": Installation Options", NONE_STATIC}, - {"^DirSubCaption", ": Installation Folder", NONE_STATIC}, - {"^InstallingSubCaption", ": Installing", NONE_STATIC}, - {"^CompletedSubCaption", ": Completed", NONE_STATIC}, - {"^UnComponentsSubCaption", ": Uninstallation Options", NONE_STATIC}, - {"^UnDirSubCaption", ": Uninstallation Folder", NONE_STATIC}, - {"^ConfirmSubCaption", ": Confirmation", NONE_STATIC}, - {"^UninstallingSubCaption", ": Uninstalling", NONE_STATIC}, - {"^UnCompletedSubCaption", ": Completed", NONE_STATIC}, - {"^BackBtn", "< &Back", NONE_STATIC}, - {"^NextBtn", "&Next >", NONE_STATIC}, - {"^AgreeBtn", "I &Agree", NONE_STATIC}, - {"^AcceptBtn", "I &accept the terms of the License Agreement", NONE_STATIC}, - {"^DontAcceptBtn", "I &do not accept the terms of the License Agreement", NONE_STATIC}, - {"^InstallBtn", "&Install", NONE_STATIC}, - {"^UninstallBtn", "&Uninstall", NONE_STATIC}, - {"^CancelBtn", "Cancel", NONE_STATIC}, - {"^CloseBtn", "&Close", NONE_STATIC}, - {"^BrowseBtn", "B&rowse...", NONE_STATIC}, - {"^ShowDetailsBtn", "Show &details", NONE_STATIC}, - {"^ClickNext", "Click Next to continue.", NONE_STATIC}, - {"^ClickInstall", "Click Install to start the installation.", NONE_STATIC}, - {"^ClickUninstall", "Click Uninstall to start the uninstallation.", NONE_STATIC}, - {"^Name", "Name", BOTH_STATIC}, - {"^NameDA", 0, NONE_STATIC}, // virtual - {"^Completed", "Completed", NONE_STATIC}, - {"^LicenseText", "Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, click I Agree.", NONE_STATIC}, - {"^LicenseTextCB", "Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, click the check box below. $_CLICK", NONE_STATIC}, - {"^LicenseTextRB", "Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, select the first option below. $_CLICK", NONE_STATIC}, - {"^UnLicenseText", "Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, click I Agree.", NONE_STATIC}, - {"^UnLicenseTextCB", "Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, click the check box below. $_CLICK", NONE_STATIC}, - {"^UnLicenseTextRB", "Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, select the first option below. $_CLICK", NONE_STATIC}, - {"^LicenseData", 0, NONE_STATIC}, // virtual - not processed - {"^Custom", "Custom", NONE_STATIC}, - {"^ComponentsText", "Check the components you want to install and uncheck the components you don't want to install. $_CLICK", NONE_STATIC}, - {"^ComponentsSubText1", "Select the type of install:", NONE_STATIC}, - {"^ComponentsSubText2_NoInstTypes", "Select components to install:", NONE_STATIC}, - {"^ComponentsSubText2", "Or, select the optional components you wish to install:", NONE_STATIC}, - {"^UnComponentsText", "Check the components you want to uninstall and uncheck the components you don't want to uninstall. $_CLICK", NONE_STATIC}, - {"^UnComponentsSubText1", "Select the type of uninstall:", NONE_STATIC}, - {"^UnComponentsSubText2_NoInstTypes", "Select components to uninstall:", NONE_STATIC}, - {"^UnComponentsSubText2", "Or, select the optional components you wish to uninstall:", NONE_STATIC}, - {"^DirText", "Setup will install $(^NameDA) in the following folder. To install in a different folder, click Browse and select another folder. $_CLICK", NONE_STATIC}, - {"^DirSubText", "Destination Folder", NONE_STATIC}, - {"^DirBrowseText", "Select the folder to install $(^NameDA) in:", NONE_STATIC}, - {"^UnDirText", "Setup will uninstall $(^NameDA) from the following folder. To uninstall from a different folder, click Browse and select another folder. $_CLICK", NONE_STATIC}, - {"^UnDirSubText", "", NONE_STATIC}, - {"^UnDirBrowseText", "Select the folder to uninstall $(^NameDA) from:", NONE_STATIC}, - {"^SpaceAvailable", "Space available: ", BOTH_STATIC}, - {"^SpaceRequired", "Space required: ", BOTH_STATIC}, - {"^UninstallingText", "This wizard will uninstall $(^NameDA) from your computer. $_CLICK", NONE_STATIC}, - {"^UninstallingSubText", "Uninstalling from:", NONE_STATIC}, - {"^FileError", "Error opening file for writing: \r\n\r\n$0\r\n\r\nClick Abort to stop the installation,\r\nRetry to try again, or\r\nIgnore to skip this file.", NONE_STATIC}, - {"^FileError_NoIgnore", "Error opening file for writing: \r\n\r\n$0\r\n\r\nClick Retry to try again, or\r\nCancel to stop the installation.", NONE_STATIC}, - {"^CantWrite", "Can't write: ", BOTH_STATIC}, - {"^CopyFailed", "Copy failed", BOTH_STATIC}, - {"^CopyTo", "Copy to ", BOTH_STATIC}, - {"^Registering", "Registering: ", NONE_STATIC}, - {"^Unregistering", "Unregistering: ", NONE_STATIC}, - {"^SymbolNotFound", "Could not find symbol: ", BOTH_STATIC}, - {"^CouldNotLoad", "Could not load: ", BOTH_STATIC}, - {"^CreateFolder", "Create folder: ", BOTH_STATIC}, - {"^CreateShortcut", "Create shortcut: ", BOTH_STATIC}, - {"^CreatedUninstaller", "Created uninstaller: ", BOTH_STATIC}, - {"^Delete", "Delete file: ", BOTH_STATIC}, - {"^DeleteOnReboot", "Delete on reboot: ", BOTH_STATIC}, - {"^ErrorCreatingShortcut", "Error creating shortcut: ", BOTH_STATIC}, - {"^ErrorCreating", "Error creating: ", BOTH_STATIC}, - {"^ErrorDecompressing", "Error decompressing data! Corrupted installer?", BOTH_STATIC}, - {"^ErrorRegistering", "Error registering DLL", BOTH_STATIC}, - {"^ExecShell", "ExecShell: ", BOTH_STATIC}, - {"^Exec", "Execute: ", BOTH_STATIC}, - {"^Extract", "Extract: ", BOTH_STATIC}, - {"^ErrorWriting", "Extract: error writing to file ", BOTH_STATIC}, - {"^InvalidOpcode", "Installer corrupted: invalid opcode", BOTH_STATIC}, - {"^NoOLE", "No OLE for: ", BOTH_STATIC}, - {"^OutputFolder", "Output folder: ", BOTH_STATIC}, - {"^RemoveFolder", "Remove folder: ", BOTH_STATIC}, - {"^RenameOnReboot", "Rename on reboot: ", BOTH_STATIC}, - {"^Rename", "Rename: ", BOTH_STATIC}, - {"^Skipped", "Skipped: ", BOTH_STATIC}, - {"^CopyDetails", "Copy Details To Clipboard", BOTH_STATIC}, - {"^LogInstall", "Log install process", BOTH_STATIC}, - {"^Byte", "B", BOTH_STATIC}, - {"^Kilo", "K", BOTH_STATIC}, - {"^Mega", "M", BOTH_STATIC}, - {"^Giga", "G", BOTH_STATIC}, - {"^Font", "MS Shell Dlg", NONE_STATIC}, - {"^FontSize", "8", NONE_STATIC}, - {"^RTL", "0", NONE_STATIC}, - {"^Language", "English", NONE_STATIC} + {_T("^Branding"), _T("Nullsoft Install System %s"), BOTH_STATIC}, + {_T("^SetupCaption"), _T("$(^Name) Setup"), INSTALL_STATIC}, + {_T("^UninstallCaption"), _T("$(^Name) Uninstall"), UNINSTALL_STATIC}, + {_T("^LicenseSubCaption"), _T(": License Agreement"), NONE_STATIC}, + {_T("^ComponentsSubCaption"), _T(": Installation Options"), NONE_STATIC}, + {_T("^DirSubCaption"), _T(": Installation Folder"), NONE_STATIC}, + {_T("^InstallingSubCaption"), _T(": Installing"), NONE_STATIC}, + {_T("^CompletedSubCaption"), _T(": Completed"), NONE_STATIC}, + {_T("^UnComponentsSubCaption"), _T(": Uninstallation Options"), NONE_STATIC}, + {_T("^UnDirSubCaption"), _T(": Uninstallation Folder"), NONE_STATIC}, + {_T("^ConfirmSubCaption"), _T(": Confirmation"), NONE_STATIC}, + {_T("^UninstallingSubCaption"), _T(": Uninstalling"), NONE_STATIC}, + {_T("^UnCompletedSubCaption"), _T(": Completed"), NONE_STATIC}, + {_T("^BackBtn"), _T("< &Back"), NONE_STATIC}, + {_T("^NextBtn"), _T("&Next >"), NONE_STATIC}, + {_T("^AgreeBtn"), _T("I &Agree"), NONE_STATIC}, + {_T("^AcceptBtn"), _T("I &accept the terms of the License Agreement"), NONE_STATIC}, + {_T("^DontAcceptBtn"), _T("I &do not accept the terms of the License Agreement"), NONE_STATIC}, + {_T("^InstallBtn"), _T("&Install"), NONE_STATIC}, + {_T("^UninstallBtn"), _T("&Uninstall"), NONE_STATIC}, + {_T("^CancelBtn"), _T("Cancel"), NONE_STATIC}, + {_T("^CloseBtn"), _T("&Close"), NONE_STATIC}, + {_T("^BrowseBtn"), _T("B&rowse..."), NONE_STATIC}, + {_T("^ShowDetailsBtn"), _T("Show &details"), NONE_STATIC}, + {_T("^ClickNext"), _T("Click Next to continue."), NONE_STATIC}, + {_T("^ClickInstall"), _T("Click Install to start the installation."), NONE_STATIC}, + {_T("^ClickUninstall"), _T("Click Uninstall to start the uninstallation."), NONE_STATIC}, + {_T("^Name"), _T("Name"), BOTH_STATIC}, + {_T("^NameDA"), 0, NONE_STATIC}, // virtual + {_T("^Completed"), _T("Completed"), NONE_STATIC}, + {_T("^LicenseText"), _T("Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, click I Agree."), NONE_STATIC}, + {_T("^LicenseTextCB"), _T("Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, click the check box below. $_CLICK"), NONE_STATIC}, + {_T("^LicenseTextRB"), _T("Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, select the first option below. $_CLICK"), NONE_STATIC}, + {_T("^UnLicenseText"), _T("Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, click I Agree."), NONE_STATIC}, + {_T("^UnLicenseTextCB"), _T("Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, click the check box below. $_CLICK"), NONE_STATIC}, + {_T("^UnLicenseTextRB"), _T("Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, select the first option below. $_CLICK"), NONE_STATIC}, + {_T("^LicenseData"), 0, NONE_STATIC}, // virtual - not processed + {_T("^Custom"), _T("Custom"), NONE_STATIC}, + {_T("^ComponentsText"), _T("Check the components you want to install and uncheck the components you don't want to install. $_CLICK"), NONE_STATIC}, + {_T("^ComponentsSubText1"), _T("Select the type of install:"), NONE_STATIC}, + {_T("^ComponentsSubText2_NoInstTypes"), _T("Select components to install:"), NONE_STATIC}, + {_T("^ComponentsSubText2"), _T("Or, select the optional components you wish to install:"), NONE_STATIC}, + {_T("^UnComponentsText"), _T("Check the components you want to uninstall and uncheck the components you don't want to uninstall. $_CLICK"), NONE_STATIC}, + {_T("^UnComponentsSubText1"), _T("Select the type of uninstall:"), NONE_STATIC}, + {_T("^UnComponentsSubText2_NoInstTypes"), _T("Select components to uninstall:"), NONE_STATIC}, + {_T("^UnComponentsSubText2"), _T("Or, select the optional components you wish to uninstall:"), NONE_STATIC}, + {_T("^DirText"), _T("Setup will install $(^NameDA) in the following folder. To install in a different folder, click Browse and select another folder. $_CLICK"), NONE_STATIC}, + {_T("^DirSubText"), _T("Destination Folder"), NONE_STATIC}, + {_T("^DirBrowseText"), _T("Select the folder to install $(^NameDA) in:"), NONE_STATIC}, + {_T("^UnDirText"), _T("Setup will uninstall $(^NameDA) from the following folder. To uninstall from a different folder, click Browse and select another folder. $_CLICK"), NONE_STATIC}, + {_T("^UnDirSubText"), _T(""), NONE_STATIC}, + {_T("^UnDirBrowseText"), _T("Select the folder to uninstall $(^NameDA) from:"), NONE_STATIC}, + {_T("^SpaceAvailable"), _T("Space available: "), BOTH_STATIC}, + {_T("^SpaceRequired"), _T("Space required: "), BOTH_STATIC}, + {_T("^UninstallingText"), _T("This wizard will uninstall $(^NameDA) from your computer. $_CLICK"), NONE_STATIC}, + {_T("^UninstallingSubText"), _T("Uninstalling from:"), NONE_STATIC}, + {_T("^FileError"), _T("Error opening file for writing: \r\n\r\n$0\r\n\r\nClick Abort to stop the installation,\r\nRetry to try again, or\r\nIgnore to skip this file."), NONE_STATIC}, + {_T("^FileError_NoIgnore"), _T("Error opening file for writing: \r\n\r\n$0\r\n\r\nClick Retry to try again, or\r\nCancel to stop the installation."), NONE_STATIC}, + {_T("^CantWrite"), _T("Can't write: "), BOTH_STATIC}, + {_T("^CopyFailed"), _T("Copy failed"), BOTH_STATIC}, + {_T("^CopyTo"), _T("Copy to "), BOTH_STATIC}, + {_T("^Registering"), _T("Registering: "), NONE_STATIC}, + {_T("^Unregistering"), _T("Unregistering: "), NONE_STATIC}, + {_T("^SymbolNotFound"), _T("Could not find symbol: "), BOTH_STATIC}, + {_T("^CouldNotLoad"), _T("Could not load: "), BOTH_STATIC}, + {_T("^CreateFolder"), _T("Create folder: "), BOTH_STATIC}, + {_T("^CreateShortcut"), _T("Create shortcut: "), BOTH_STATIC}, + {_T("^CreatedUninstaller"), _T("Created uninstaller: "), BOTH_STATIC}, + {_T("^Delete"), _T("Delete file: "), BOTH_STATIC}, + {_T("^DeleteOnReboot"), _T("Delete on reboot: "), BOTH_STATIC}, + {_T("^ErrorCreatingShortcut"), _T("Error creating shortcut: "), BOTH_STATIC}, + {_T("^ErrorCreating"), _T("Error creating: "), BOTH_STATIC}, + {_T("^ErrorDecompressing"), _T("Error decompressing data! Corrupted installer?"), BOTH_STATIC}, + {_T("^ErrorRegistering"), _T("Error registering DLL"), BOTH_STATIC}, + {_T("^ExecShell"), _T("ExecShell: "), BOTH_STATIC}, + {_T("^Exec"), _T("Execute: "), BOTH_STATIC}, + {_T("^Extract"), _T("Extract: "), BOTH_STATIC}, + {_T("^ErrorWriting"), _T("Extract: error writing to file "), BOTH_STATIC}, + {_T("^InvalidOpcode"), _T("Installer corrupted: invalid opcode"), BOTH_STATIC}, + {_T("^NoOLE"), _T("No OLE for: "), BOTH_STATIC}, + {_T("^OutputFolder"), _T("Output folder: "), BOTH_STATIC}, + {_T("^RemoveFolder"), _T("Remove folder: "), BOTH_STATIC}, + {_T("^RenameOnReboot"), _T("Rename on reboot: "), BOTH_STATIC}, + {_T("^Rename"), _T("Rename: "), BOTH_STATIC}, + {_T("^Skipped"), _T("Skipped: "), BOTH_STATIC}, + {_T("^CopyDetails"), _T("Copy Details To Clipboard"), BOTH_STATIC}, + {_T("^LogInstall"), _T("Log install process"), BOTH_STATIC}, + {_T("^Byte"), _T("B"), BOTH_STATIC}, + {_T("^Kilo"), _T("K"), BOTH_STATIC}, + {_T("^Mega"), _T("M"), BOTH_STATIC}, + {_T("^Giga"), _T("G"), BOTH_STATIC}, + {_T("^Font"), _T("MS Shell Dlg"), NONE_STATIC}, + {_T("^FontSize"), _T("8"), NONE_STATIC}, + {_T("^RTL"), _T("0"), NONE_STATIC}, + {_T("^Language"), _T("English"), NONE_STATIC} }; // ============== @@ -148,7 +152,7 @@ LangStringList::LangStringList() { count = 0; } -int LangStringList::add(const char *name, int *sn/*=0*/) +int LangStringList::add(const TCHAR *name, int *sn/*=0*/) { int pos = SortedStringListND::add(name); if (pos == -1) return -1; @@ -163,9 +167,9 @@ int LangStringList::add(const char *name, int *sn/*=0*/) return pos; } -int LangStringList::get(const char *name, int *sn/*=0*/, int *index/*=0*/, int *uindex/*=0*/, int *process/*=0*/) +int LangStringList::get(const TCHAR *name, int *sn/*=0*/, int *index/*=0*/, int *uindex/*=0*/, int *process/*=0*/) { - if (index) *index = -1; + if (index) *index = -1; if (uindex) *uindex = -1; if (sn) *sn = -1; int v=find(name); @@ -192,27 +196,27 @@ void LangStringList::set(int pos, int index/*=-1*/, int uindex/*=-1*/, int proce data[pos].process = process; } -void LangStringList::set(const char *name, int index, int uindex/*=-1*/, int process/*=-1*/) +void LangStringList::set(const TCHAR *name, int index, int uindex/*=-1*/, int process/*=-1*/) { set(get(name), index, uindex, process); } -const char* LangStringList::pos2name(int pos) +const TCHAR* LangStringList::pos2name(int pos) { struct langstring *data=(struct langstring *)gr.get(); if ((unsigned int)pos > (gr.getlen() / sizeof(struct langstring))) return 0; - return ((const char*)strings.get() + data[pos].name); + return ((const TCHAR*)strings.get() + data[pos].name); } -const char* LangStringList::offset2name(int name) +const TCHAR* LangStringList::offset2name(int name) { if ((unsigned int)name > (unsigned int)strings.getlen()) return 0; - return (const char*)strings.get() + name; + return (const TCHAR*)strings.get() + name; } int LangStringList::getnum() @@ -264,7 +268,7 @@ StringsArray::StringsArray() { offsets.set_zeroing(1); - strings.add("", sizeof("")); + strings.add(_T(""), sizeof(_T(""))); } void StringsArray::resize(int num) @@ -272,7 +276,7 @@ void StringsArray::resize(int num) offsets.resize(num * sizeof(int)); } -int StringsArray::set(int idx, const char *str) +int StringsArray::set(int idx, const TCHAR *str) { if (idx < 0) return 0; @@ -287,12 +291,12 @@ int StringsArray::set(int idx, const char *str) return old; } -const char* StringsArray::get(int idx) +const TCHAR* StringsArray::get(int idx) { if ((unsigned int)idx >= (offsets.getlen() / sizeof(int))) return 0; - return (const char *)strings.get() + ((int*)offsets.get())[idx]; + return (const TCHAR *)strings.get() + ((int*)offsets.get())[idx]; } // ========= @@ -331,6 +335,12 @@ void CEXEBuild::InitLangTables() { keep_ref = true; } +////////////////////////////////////////////////////////////////////////////// +// class CEXEBuild +// +// Note: The functions below refer to the methods related to Languages. +////////////////////////////////////////////////////////////////////////////// + LanguageTable* CEXEBuild::GetLangTable(LANGID &lang, bool create/*=true*/) { int nlt = lang_tables.getlen() / sizeof(LanguageTable); LanguageTable *nla = (LanguageTable*)lang_tables.get(); @@ -363,7 +373,7 @@ LanguageTable* CEXEBuild::GetLangTable(LANGID &lang, bool create/*=true*/) { return table; } -const char *CEXEBuild::GetLangNameAndCP(LANGID lang, unsigned int *codepage/*=NULL*/) { +const TCHAR *CEXEBuild::GetLangNameAndCP(LANGID lang, unsigned int *codepage/*=NULL*/) { LanguageTable *table = GetLangTable(lang, false); if (table && table->nlf.m_bLoaded) { @@ -377,48 +387,54 @@ const char *CEXEBuild::GetLangNameAndCP(LANGID lang, unsigned int *codepage/*=NU *codepage = 1252; // English US if (lang == 1033) - return "English"; + return _T("English"); else - return "???"; + return _T("???"); } } -int CEXEBuild::DefineLangString(const char *name, int process/*=-1*/) { +int CEXEBuild::DefineLangString(const TCHAR *name, int process/*=-1*/) { int index, uindex, pos, ret, sn; + + /* If not exist, index and uindex will get -1. */ pos = build_langstrings.get(name, &sn, &index, &uindex); if (pos < 0) { pos = build_langstrings.add(name); } #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT - if (!uninstall_mode) { + if (!this->uninstall_mode) { #endif if (index < 0) { - index = build_langstring_num++; + // Did not exist. Increment. + index = this->build_langstring_num++; } ret = -index - 1; #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT } else { if (uindex < 0) { - uindex = ubuild_langstring_num++; + // Did not exist. Increment. + uindex = this->ubuild_langstring_num++; } ret = -uindex - 1; } #endif + // Now set the new index and uindex values with the + // passed in proces value. build_langstrings.set(pos, index, uindex, process); // set reference count for NLF strings - if (keep_ref && name[0] == '^') { + if (this->keep_ref && name[0] == _T('^')) { for (int i = 0; i < NLF_STRINGS; i++) { - if (!strcmp(name, NLFStrings[i].szLangStringName)) { + if (!_tcscmp(name, NLFStrings[i].szLangStringName)) { #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT - if (uninstall_mode) - NLFRefs[i].iUnRef++; + if (this->uninstall_mode) + this->NLFRefs[i].iUnRef++; else #endif - NLFRefs[i].iRef++; + this->NLFRefs[i].iRef++; break; } @@ -450,8 +466,15 @@ int CEXEBuild::DefineInnerLangString(int id, int process/*=-1*/) { return ret; } -int CEXEBuild::SetLangString(char *name, LANGID lang, char *string) { - if (!string || !name) return PS_ERROR; +// A LangString is a string variable that varies in value depending on what +// language is being used. This function sets the string value for the +// variable 'name' for a given language ID. +// +// @return If the language id, the variable name or string is invalid, it will +// return a PS_ERROR. If this function call is overwriting a set user string, +// this will return a PS_WARNING. +int CEXEBuild::SetLangString(TCHAR *name, LANGID lang, TCHAR *str) { + if (!str || !name) return PS_ERROR; LanguageTable *table = GetLangTable(lang); if (!table) return PS_ERROR; @@ -462,22 +485,27 @@ int CEXEBuild::SetLangString(char *name, LANGID lang, char *string) { if (pos < 0) pos = build_langstrings.add(name, &sn); - if (table->lang_strings->set(sn, string)) + if (table->lang_strings->set(sn, str)) return PS_WARNING; return PS_OK; } -int CEXEBuild::SetInnerString(int id, char *string) { - if ((unsigned int)id >= NLF_STRINGS || !string) return PS_ERROR; +// Sets the user string to the specific NLF_STRINGS id. +// +// @return If the id is invalid or the string is not valid, it will return a +// PS_ERROR. If this function call is overwriting a set user string, this +// will return a PS_WARNING. +int CEXEBuild::SetInnerString(int id, TCHAR *str) { + if ((unsigned int)id >= NLF_STRINGS || !str) return PS_ERROR; int ret = PS_OK; - const char *ps = UserInnerStrings.get(id); + const TCHAR *ps = UserInnerStrings.get(id); if (ps && *ps) ret = PS_WARNING; - UserInnerStrings.set(id, string); + UserInnerStrings.set(id, str); return ret; } @@ -531,24 +559,25 @@ int CEXEBuild::GenerateLangTable(LanguageTable *lt, int num_lang_tables) { if (!*ptr) { // Get the language string and its name - const char *str = lt[i].lang_strings->get(lang_strings[j].sn); - const char *lsn = build_langstrings.offset2name(lang_strings[j].name); + const TCHAR *str = lt[i].lang_strings->get(lang_strings[j].sn); + const TCHAR *lsn = build_langstrings.offset2name(lang_strings[j].name); + // lsn = variable name, str = value if (!str || !*str) { // No string is defined; give a warning (for user strings only) - if (lsn[0] != '^') + if (lsn[0] != _T('^')) { if (lt[i].nlf.m_bLoaded) - warning("LangString \"%s\" is not set in language table of language %s", lsn, lt[i].nlf.m_szName); + warning(_T("LangString \"%s\" is not set in language table of language %s"), lsn, lt[i].nlf.m_szName); else - warning("LangString \"%s\" is not set in language table of language %d", lsn, lt[i].lang_id); + warning(_T("LangString \"%s\" is not set in language table of language %d"), lsn, lt[i].lang_id); } } else { // Add the language string to the string data block - char fn[1024]; - sprintf(fn, "LangString %s", lsn); + TCHAR fn[1024]; + _stprintf(fn, _T("LangString %s"), lsn); curfilename = fn; linecnt = lt[i].lang_id; *ptr = add_string(str, lang_strings[j].process, (WORD) lt[i].nlf.m_uCodePage); @@ -586,7 +615,7 @@ int CEXEBuild::GenerateLangTable(LanguageTable *lt, int num_lang_tables) { if (((int*)rec.get())[l] == lst[j]) { // We have the index of a recursive language string; now find the name - const char *name = "(unnamed)"; + const TCHAR *name = _T("(unnamed)"); for (l = 0; l < langstring_num; l++) { int index; @@ -601,7 +630,7 @@ int CEXEBuild::GenerateLangTable(LanguageTable *lt, int num_lang_tables) { name = build_langstrings.offset2name(lang_strings[l].name); } } - ERROR_MSG("Error: LangString %s is recursive!\n", name); + ERROR_MSG(_T("Error: LangString %s is recursive!\n"), name); delete [] string_ptrs; return PS_ERROR; } @@ -638,7 +667,7 @@ int CEXEBuild::GenerateLangTables() { int i; LanguageTable *lt = (LanguageTable*)lang_tables.get(); - SCRIPT_MSG("Generating language tables... "); + SCRIPT_MSG(_T("Generating language tables... ")); if ( #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT @@ -647,7 +676,7 @@ int CEXEBuild::GenerateLangTables() { build_langstring_num > MAX_CODED ) { - ERROR_MSG("\nError: too many LangStrings. Maximum allowed is %u.\n", MAX_CODED); + ERROR_MSG(_T("\nError: too many LangStrings. Maximum allowed is %u.\n"), MAX_CODED); return PS_ERROR; } @@ -699,7 +728,7 @@ int CEXEBuild::GenerateLangTables() { #undef ADD_FONT } catch (exception& err) { - ERROR_MSG("\nError while applying font: %s\n", err.what()); + ERROR_MSG(_T("\nError while applying font: %s\n"), err.what()); return PS_ERROR; } } @@ -715,7 +744,7 @@ int CEXEBuild::GenerateLangTables() { { lt[i].dlg_offset = cur_offset; - char *font = lt[i].nlf.m_szFont; + TCHAR *font = lt[i].nlf.m_szFont; if (*build_font) font = 0; try { @@ -762,7 +791,7 @@ int CEXEBuild::GenerateLangTables() { #undef ADD_FONT } catch (exception& err) { - ERROR_MSG("\nError while applying NLF font/RTL: %s\n", err.what()); + ERROR_MSG(_T("\nError while applying NLF font/RTL: %s\n"), err.what()); return PS_ERROR; } @@ -784,7 +813,7 @@ int CEXEBuild::GenerateLangTables() { set_uninstall_mode(orig_uninstall_mode); - SCRIPT_MSG("Done!\n"); + SCRIPT_MSG(_T("Done!\n")); return PS_OK; } @@ -810,30 +839,30 @@ void CEXEBuild::FillLanguageTable(LanguageTable *table) { int sn, index; int pos = build_langstrings.get(NLFStrings[i].szLangStringName, &sn, &index); if (pos >= 0) { - const char *str = table->lang_strings->get(sn); + const TCHAR *str = table->lang_strings->get(sn); if (!str || !*str) { - const char *us = UserInnerStrings.get(i); + const TCHAR *us = UserInnerStrings.get(i); if (i == NLF_NAME_DA && (!us || !*us)) { // if the user didn't set NLF_NAME_DA we set it to $(^Name) - table->lang_strings->set(sn, "$(^Name)"); + table->lang_strings->set(sn, _T("$(^Name)")); } if (us && *us) { - table->lang_strings->set(sn, (char *) us); + table->lang_strings->set(sn, (TCHAR *) us); } else { - const char *dstr = table->nlf.m_szStrings[i] ? table->nlf.m_szStrings[i] : NLFStrings[i].szDefault; + const TCHAR *dstr = table->nlf.m_szStrings[i] ? table->nlf.m_szStrings[i] : NLFStrings[i].szDefault; if (!dstr) continue; if (i == NLF_BRANDING) { - char temp[NSIS_MAX_STRLEN + sizeof(NSIS_VERSION)]; - sprintf(temp, dstr, NSIS_VERSION); + TCHAR temp[NSIS_MAX_STRLEN + sizeof(NSIS_VERSION)]; + _stprintf(temp, dstr, NSIS_VERSION); table->lang_strings->set(sn, temp); continue; } else if (i == NLF_FONT) { - char *font = *build_font ? build_font : table->nlf.m_szFont; + TCHAR *font = *build_font ? build_font : table->nlf.m_szFont; if (font) table->lang_strings->set(sn, font); else @@ -845,8 +874,8 @@ void CEXEBuild::FillLanguageTable(LanguageTable *table) { WORD font_size = *build_font ? (WORD) build_font_size : (WORD) table->nlf.m_iFontSize; if (font_size) { - char temp[64]; - sprintf(temp, "%d", font_size); + TCHAR temp[64]; + _stprintf(temp, _T("%d"), font_size); table->lang_strings->set(sn, temp); } else @@ -860,51 +889,51 @@ void CEXEBuild::FillLanguageTable(LanguageTable *table) { } } -char SkipComments(FILE *f) { +TCHAR SkipComments(FILE *f) { int c; - while ((c = fgetc(f))) { - while (c == '\n' || c == '\r') { - c = fgetc(f); // Skip empty lines + while ((c = _fgettc(f))) { + while (c == _T('\n') || c == _T('\r')) { + c = _fgettc(f); // Skip empty lines } - if (c == '#' || c == ';') { - while ((c = fgetc(f))) { - if (c == '\n') break; + if (c == _T('#') || c == _T(';')) { + while ((c = _fgettc(f))) { + if (c == _T('\n')) break; } } else break; } - return (char) c; + return (TCHAR) c; } // NSIS Language File parser -LanguageTable * CEXEBuild::LoadLangFile(char *filename) { - FILE *f = FOPEN(filename, "r"); +LanguageTable * CEXEBuild::LoadLangFile(TCHAR *filename) { + FILE *f = FOPEN(filename, _T("r")); if (!f) { - ERROR_MSG("Error: Can't open language file - \"%s\"!\n",filename); + ERROR_MSG(_T("Error: Can't open language file - \"%s\"!\n"),filename); return 0; } // Check header - char buf[NSIS_MAX_STRLEN]; + TCHAR buf[NSIS_MAX_STRLEN]; buf[0] = SkipComments(f); - fgets(buf+1, NSIS_MAX_STRLEN, f); + _fgetts(buf+1, NSIS_MAX_STRLEN, f); - if (strncmp(buf, "NLF v", 5)) { - ERROR_MSG("Error: Invalid language file.\n"); + if (_tcsncmp(buf, _T("NLF v"), 5)) { + ERROR_MSG(_T("Error: Invalid language file.\n")); return 0; } - int nlf_version = atoi(buf+5); + int nlf_version = _ttoi(buf+5); if (nlf_version != NLF_VERSION) { if (nlf_version != 2 && nlf_version != 3 && nlf_version != 4 && nlf_version != 5) { - ERROR_MSG("Error: Language file version doesn't match NSIS version.\n"); + ERROR_MSG(_T("Error: Language file version doesn't match NSIS version.\n")); return 0; } } // Get language ID buf[0] = SkipComments(f); - fgets(buf+1, NSIS_MAX_STRLEN, f); - LANGID lang_id = atoi(buf); + _fgetts(buf+1, NSIS_MAX_STRLEN, f); + LANGID lang_id = _ttoi(buf); // Get appropriate table LanguageTable *table = GetLangTable(lang_id); @@ -914,32 +943,32 @@ LanguageTable * CEXEBuild::LoadLangFile(char *filename) { NLF *nlf = &table->nlf; if (nlf->m_bLoaded) { - ERROR_MSG("Error: can't load same language file twice.\n"); + ERROR_MSG(_T("Error: can't load same language file twice.\n")); return 0; } // Generate language name - char *p, *p2, t = 0; + TCHAR *p, *p2, t = 0; - p = strrchr(filename, '.'); + p = _tcsrchr(filename, _T('.')); if (p) { t = *p; *p = 0; } - p2 = strrchr(filename, '\\'); + p2 = _tcsrchr(filename, _T('\\')); if (p2) { p2++; - nlf->m_szName = (char*)malloc(strlen(p2)+1); - strcpy(nlf->m_szName, p2); + nlf->m_szName = (TCHAR*)malloc((_tcsclen(p2)+1)*sizeof(TCHAR)); + _tcscpy(nlf->m_szName, p2); } else { - nlf->m_szName = (char*)malloc(strlen(filename)+1); - strcpy(nlf->m_szName, filename); + nlf->m_szName = (TCHAR*)malloc((_tcsclen(filename)+1)*sizeof(TCHAR)); + _tcscpy(nlf->m_szName, filename); } if (p) *p = t; if (nlf_version != NLF_VERSION) { - warning_fl("%s language file version doesn't match. Using default English texts for missing strings.", nlf->m_szName); + warning_fl(_T("%s language file version doesn't match. Using default English texts for missing strings."), nlf->m_szName); } // set ^Language @@ -949,48 +978,48 @@ LanguageTable * CEXEBuild::LoadLangFile(char *filename) { // Get font buf[0] = SkipComments(f); - fgets(buf+1, NSIS_MAX_STRLEN, f); + _fgetts(buf+1, NSIS_MAX_STRLEN, f); if (!nlf->m_szFont) { - temp=strlen(buf); - while (buf[temp-1] == '\n' || buf[temp-1] == '\r') { + temp=_tcsclen(buf); + while (buf[temp-1] == _T('\n') || buf[temp-1] == _T('\r')) { buf[temp-1] = 0; temp--; } - if (buf[0] != '-' || buf[1] != 0) { - nlf->m_szFont = (char*)malloc(strlen(buf)+1); - strcpy(nlf->m_szFont, buf); + if (buf[0] != _T('-') || buf[1] != 0) { + nlf->m_szFont = (TCHAR*)malloc((_tcsclen(buf)+1)*sizeof(TCHAR)); + _tcscpy(nlf->m_szFont, buf); } } buf[0] = SkipComments(f); - fgets(buf+1, NSIS_MAX_STRLEN, f); + _fgetts(buf+1, NSIS_MAX_STRLEN, f); if (!nlf->m_iFontSize) { - if (buf[0] != '-' || buf[1] != 0) { - nlf->m_iFontSize = atoi(buf); + if (buf[0] != _T('-') || buf[1] != 0) { + nlf->m_iFontSize = _ttoi(buf); } } // Get code page nlf->m_uCodePage = CP_ACP; buf[0] = SkipComments(f); - fgets(buf+1, NSIS_MAX_STRLEN, f); - if (buf[0] != '-' || buf[1] != 0) { - nlf->m_uCodePage = atoi(buf); + _fgetts(buf+1, NSIS_MAX_STRLEN, f); + if (buf[0] != _T('-') || buf[1] != 0) { + nlf->m_uCodePage = _ttoi(buf); if (!IsValidCodePage(nlf->m_uCodePage)) nlf->m_uCodePage = CP_ACP; } // Get RTL setting - nlf->m_szStrings[NLF_RTL] = (char *)malloc(2); + nlf->m_szStrings[NLF_RTL] = (TCHAR *)malloc(2*sizeof(TCHAR)); nlf->m_bRTL = false; buf[0] = SkipComments(f); - fgets(buf+1, NSIS_MAX_STRLEN, f); - if (buf[0] == 'R' && buf[1] == 'T' && buf[2] == 'L' && (!buf[3] || buf[3] == '\r' || buf[3] == '\n')) { + _fgetts(buf+1, NSIS_MAX_STRLEN, f); + if (buf[0] == _T('R') && buf[1] == _T('T') && buf[2] == _T('L') && (!buf[3] || buf[3] == _T('\r') || buf[3] == _T('\n'))) { nlf->m_bRTL = true; - strcpy(nlf->m_szStrings[NLF_RTL], "1"); + _tcscpy(nlf->m_szStrings[NLF_RTL], _T("1")); } else { - strcpy(nlf->m_szStrings[NLF_RTL], "0"); + _tcscpy(nlf->m_szStrings[NLF_RTL], _T("0")); } // Read strings @@ -1045,42 +1074,42 @@ LanguageTable * CEXEBuild::LoadLangFile(char *filename) { buf[0] = SkipComments(f); - fgets(buf+1, NSIS_MAX_STRLEN, f); - if (strlen(buf) == NSIS_MAX_STRLEN-1) { - ERROR_MSG("Error: String too long (string #%d - \"%s\")", i, NLFStrings[i].szLangStringName); + _fgetts(buf+1, NSIS_MAX_STRLEN, f); + if (_tcsclen(buf) == NSIS_MAX_STRLEN-1) { + ERROR_MSG(_T("Error: String too long (string #%d - \"%s\")"), i, NLFStrings[i].szLangStringName); return 0; } - temp=strlen(buf); + temp=_tcsclen(buf); - while (buf[temp-1] == '\n' || buf[temp-1] == '\r') { + while (buf[temp-1] == _T('\n') || buf[temp-1] == _T('\r')) { buf[--temp] = 0; } - char *in = buf; + TCHAR *in = buf; // trim quotes - if (buf[0] == '"' && buf[temp-1] == '"') { + if (buf[0] == _T('"') && buf[temp-1] == _T('"')) { in++; buf[--temp] = 0; } - nlf->m_szStrings[i] = (char*)malloc(temp+1); - char *out; + nlf->m_szStrings[i] = (TCHAR*)malloc((temp+1)*sizeof(TCHAR)); + TCHAR *out; for (out = nlf->m_szStrings[i]; *in; in++, out++) { - if (*in == '\\') { + if (*in == _T('\\')) { in++; switch (*in) { - case 'n': - *out = '\n'; + case _T('n'): + *out = _T('\n'); break; - case 'r': - *out = '\r'; + case _T('r'): + *out = _T('\r'); break; - case 't': - *out = '\t'; + case _T('t'): + *out = _T('\t'); break; default: - *out++ = '\\'; + *out++ = _T('\\'); *out = *in; } } diff --git a/Source/lang.h b/Source/lang.h index 71dc26ca..53efed86 100644 --- a/Source/lang.h +++ b/Source/lang.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support and Doxygen comments by Jim Park -- 07/30/2007 */ #ifndef ___NLF___H_____ @@ -37,18 +39,116 @@ struct langstring { class LangStringList : public SortedStringListND { public: + /* Default constructor */ LangStringList(); - int add(const char *name, int *sn=0); - int get(const char *name, int *sn=0, int *index=0, int *uindex=0, int *process=0); + /** + * Adds a langstring struct with the string name of 'name' into this + * structure. + * + * @param name The string to use as key. + * @param sn [out] The string number. + * @return Returns the position where T was stored. + */ + int add(const TCHAR *name, int *sn=0); + + /** + * Gets the values in the langstring struct that is mapped to the string + * 'name'. Sets sn, index, and uindex to -1 before looking for the + * 'name'. If not found, -1 is returned. If found, then the values + * associated with 'name' are set to the sn, index, uindex, process + * variables. + * + * TODO: Need better documentation here. + * @param sn [out] Set to string ID number. + * @param index [out] Set to index value in langstring. + * @param uindex [out] Set to uindex value in langstring. + * @param process [out] Set to process value in langstring. + * @return The index into langstring array. -1 if not found. + */ + int get(const TCHAR *name, int *sn=0, int *index=0, int *uindex=0, int *process=0); + + /** + * Sets the values in the langstring struct that is in the position 'pos'. + * + * @param pos The langstring index into m_gr. + * @param index Value to set langstring[pos].index. + * @param uindex Value to set langstring[pos].uindex. + * @param process Value to set langstring[pos].process. + */ void set(int pos, int index=-1, int uindex=-1, int process=-1); - void set(const char *name, int index, int uindex=-1, int process=-1); - const char *pos2name(int pos); - const char *offset2name(int name); + + /** + * Sets the values in the langstring struct that is mapped to the string + * 'name'. + * + * @param name The string key to lookup langstring. + * @param index Value to set langstring[pos].index. + * @param uindex Value to set langstring[pos].uindex. + * @param process Value to set langstring[pos].process. + */ + void set(const TCHAR *name, int index, int uindex=-1, int process=-1); + + /** + * From the position index, get the pointer to the key string. + * Basically, get the string referenced by langstring[pos].name. + * + * @param pos The position index. + * @return The TCHAR* to the string referenced by pos. + */ + const TCHAR *pos2name(int pos); + + /** + * From the index into the strings, get the pointer to the + * key string. Note: the positional index into the storage of + * key strings probably should not be exposed to the outside. + * + * @param name Index into the m_strings array. + * @return The TCHAR* to the string referenced by name. + */ + const TCHAR *offset2name(int name); + + /** + * Get the number of entries. + * + * @return The number of langstring entries. + */ int getnum(); + + /** + * Compare two langstring structs pointed by item1 and item2 by looking at + * their .index values via their difference (item1->index - item2->index). + * + * @return 0 if equal, negative value if item1 is smaller, positive value + * if item1 is bigger. + */ static int compare_index(const void *item1, const void *item2); + + /** + * Sorts the langstrings by their index. Then return the sorted array + * via m_sortbuf. Warning: This function is not thread-safe! + * + * @param num [out] Set to the size of langstring items in the array. + * @return The sorted langstring array via m_sortbuf. + */ langstring *sort_index(int *num); + + /** + * Compare two langstring structs pointed by item1 and item2 by looking at + * their .uindex values via their difference (item1->uindex - item2->uindex). + * + * @return 0 if equal, negative value if item1 is smaller, positive value + * if item1 is bigger. + */ static int compare_uindex(const void *item1, const void *item2); + + /** + * Sorts the langstrings by their index. Then return the sorted array + * via m_sortbuf. Warning: This function is not thread-safe! + * + * @param num [out] Set to the size of langstring items in the array. + * @return The sorted langstring array via m_sortbuf. + */ langstring *sort_uindex(int *num); private: @@ -56,14 +156,43 @@ class LangStringList : public SortedStringListND TinyGrowBuf sortbuf; }; +/** + * This class implements an array of C-style strings in a flat buffer. + * + * Implementation: Resetting the string at a particular index does not delete + * the old string. Instead a new string is added to the end of m_strings and + * the old string can no longer be looked up. + */ class StringsArray { public: StringsArray(); + /** + * Resizes the m_offsets so that the index num is valid. + * + * @param num New size. + */ void resize(int num); - int set(int idx, const char *str); - const char *get(int idx); + + /** + * Set the string 'str' at index idx. This class cannot really delete + * strings. It can "overwrite" them in the sense that the string is no + * longer referenceable via the index but they are never gone. + * + * @param idx The index position to set the string to. + * @param str The string value to set. + * @return If overwriting, the position in m_strings of the old string. + */ + int set(int idx, const TCHAR *str); + + /** + * Get the string at index 'idx'. + * + * @param idx The logical index to the string. + * @return Returns the TCHAR* to the string. + */ + const TCHAR *get(int idx); private: TinyGrowBuf offsets; @@ -176,18 +305,26 @@ enum { }; struct NLF { - bool m_bLoaded; - char *m_szName; - char *m_szFont; + bool m_bLoaded; /* Is the table loaded? */ + TCHAR *m_szName; /* The language name */ + TCHAR *m_szFont; int m_iFontSize; - unsigned int m_uCodePage; - bool m_bRTL; + unsigned int m_uCodePage; /* Code page associated with language. When + * using Unicode, this value will be 1200. + */ + + bool m_bRTL; /* Is this a right-to-left language like + Hebrew? */ - char *m_szStrings[NLF_STRINGS]; + TCHAR *m_szStrings[NLF_STRINGS]; }; +/** + * LanguageTable stores within the lang_strings, all the user strings and + * variables for that specific language. + */ struct LanguageTable { - LANGID lang_id; + LANGID lang_id; /* Windows Language ID identifier */ int dlg_offset; diff --git a/Source/lineparse.cpp b/Source/lineparse.cpp index ec0324fb..863596c3 100644 --- a/Source/lineparse.cpp +++ b/Source/lineparse.cpp @@ -12,13 +12,16 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/09/2007 */ #include "lineparse.h" #include "Platform.h" - +#include "tchar.h" #include #include +//#include "tstring.h" LineParser::LineParser(bool bCommentBlock) { @@ -43,7 +46,7 @@ bool LineParser::inCommentBlock() return m_incommentblock; } -int LineParser::parse(char *line, int ignore_escaping/*=0*/) // returns -1 on error +int LineParser::parse(TCHAR *line, int ignore_escaping/*=0*/) // returns -1 on error { freetokens(); bool bPrevCB=m_incommentblock; @@ -52,7 +55,7 @@ int LineParser::parse(char *line, int ignore_escaping/*=0*/) // returns -1 on er if (m_nt) { m_incommentblock=bPrevCB; - m_tokens=(char**)malloc(sizeof(char*)*m_nt); + m_tokens=(TCHAR**)malloc(sizeof(TCHAR*)*m_nt); n=doline(line, ignore_escaping); if (n) { @@ -83,15 +86,15 @@ double LineParser::gettoken_float(int token, int *success/*=0*/) } if (success) { - char *t=m_tokens[token]; + TCHAR *t=m_tokens[token]; *success=*t?1:0; while (*t) { - if ((*t < '0' || *t > '9')&&*t != '.') *success=0; + if ((*t < _T('0') || *t > _T('9'))&&*t != _T('.')) *success=0; t++; } } - return atof(m_tokens[token]); + return _tstof(m_tokens[token]); } int LineParser::gettoken_int(int token, int *success/*=0*/) @@ -102,29 +105,29 @@ int LineParser::gettoken_int(int token, int *success/*=0*/) if (success) *success=0; return 0; } - char *tmp; + TCHAR *tmp; int l; - if (m_tokens[token][0] == '-') l=strtol(m_tokens[token],&tmp,0); - else l=(int)strtoul(m_tokens[token],&tmp,0); + if (m_tokens[token][0] == _T('-')) l=_tcstol(m_tokens[token],&tmp,0); + else l=(int)_tcstoul(m_tokens[token],&tmp,0); if (success) *success=! (int)(*tmp); return l; } -char* LineParser::gettoken_str(int token) +TCHAR* LineParser::gettoken_str(int token) { token+=m_eat; - if (token < 0 || token >= m_nt) return (char*)""; + if (token < 0 || token >= m_nt) return (TCHAR*)_T(""); return m_tokens[token]; } -int LineParser::gettoken_enum(int token, const char *strlist) // null seperated list +int LineParser::gettoken_enum(int token, const TCHAR *strlist) // null seperated list { int x=0; - char *tt=gettoken_str(token); + TCHAR *tt=gettoken_str(token); if (tt && *tt) while (*strlist) { if (!stricmp(tt,strlist)) return x; - strlist+=strlen(strlist)+1; + strlist+=_tcsclen(strlist)+1; x++; } return -1; @@ -143,22 +146,22 @@ void LineParser::freetokens() m_nt=0; } -int LineParser::doline(char *line, int ignore_escaping/*=0*/) +int LineParser::doline(TCHAR *line, int ignore_escaping/*=0*/) { m_nt=0; m_incomment = false; - while (*line == ' ' || *line == '\t') line++; + while (*line == _T(' ') || *line == _T('\t')) line++; while (*line) { if ( m_incommentblock ) { while ( *line ) { - if ( *line == '*' && *(line+1) == '/' ) + if ( *line == _T('*') && *(line+1) == _T('/') ) { m_incommentblock=false; // Found end of comment block line+=2; - while (*line == ' ' || *line == '\t') line++; + while (*line == _T(' ') || *line == _T('\t')) line++; break; } else line++; @@ -166,41 +169,41 @@ int LineParser::doline(char *line, int ignore_escaping/*=0*/) } else { int lstate=0; // 1=", 2=`, 4=' - if (*line == ';' || *line == '#') + if (*line == _T(';') || *line == _T('#')) { m_incomment = true; break; } - if (*line == '/' && *(line+1) == '*') + if (*line == _T('/') && *(line+1) == _T('*')) { m_incommentblock = true; line+=2; } else { - if (*line == '\"') lstate=1; - else if (*line == '\'') lstate=2; - else if (*line == '`') lstate=4; + if (*line == _T('\"')) lstate=1; + else if (*line == _T('\'')) lstate=2; + else if (*line == _T('`')) lstate=4; if (lstate) line++; int nc=0; - char *p = line; + TCHAR *p = line; while (*line) { - if (line[0] == '$' && line[1] == '\\') { + if (line[0] == _T('$') && line[1] == _T('\\')) { switch (line[2]) { - case '"': - case '\'': - case '`': + case _T('"'): + case _T('\''): + case _T('`'): nc += ignore_escaping ? 3 : 1; line += 3; continue; } } - if (lstate==1 && *line =='\"') break; - if (lstate==2 && *line =='\'') break; - if (lstate==4 && *line =='`') break; - if (!lstate && (*line == ' ' || *line == '\t')) break; + if (lstate==1 && *line ==_T('\"')) break; + if (lstate==2 && *line ==_T('\'')) break; + if (lstate==4 && *line ==_T('`')) break; + if (!lstate && (*line == _T(' ') || *line == _T('\t'))) break; #ifdef NSIS_FIX_COMMENT_HANDLING - if (!lstate && (*line == ';' || *line == '#' || (*line == '/' && *(line+1) == '*'))) break; + if (!lstate && (*line == _T(';') || *line == _T('#') || (*line == _T('/') && *(line+1) == _T('*')))) break; #endif line++; nc++; @@ -208,13 +211,13 @@ int LineParser::doline(char *line, int ignore_escaping/*=0*/) if (m_tokens) { int i; - m_tokens[m_nt]=(char*)malloc(nc+1); + m_tokens[m_nt]=(TCHAR*)malloc((nc+1)*sizeof(TCHAR)); for (i = 0; p < line; i++, p++) { - if (!ignore_escaping && p[0] == '$' && p[1] == '\\') { + if (!ignore_escaping && p[0] == _T('$') && p[1] == _T('\\')) { switch (p[2]) { - case '"': - case '\'': - case '`': + case _T('"'): + case _T('\''): + case _T('`'): p += 2; } } @@ -228,7 +231,7 @@ int LineParser::doline(char *line, int ignore_escaping/*=0*/) if (*line) line++; else return -2; } - while (*line == ' ' || *line == '\t') line++; + while (*line == _T(' ') || *line == _T('\t')) line++; } } } diff --git a/Source/lineparse.h b/Source/lineparse.h index 744071e1..76954021 100644 --- a/Source/lineparse.h +++ b/Source/lineparse.h @@ -12,11 +12,15 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/09/2007 */ #ifndef _LINEPARSE_H_ #define _LINEPARSE_H_ +#include "tchar.h" + class LineParser { public: @@ -25,23 +29,23 @@ class LineParser { bool inComment(); bool inCommentBlock(); - int parse(char *line, int ignore_escaping=0); // returns -1 on error + int parse(TCHAR *line, int ignore_escaping=0); // returns -1 on error int getnumtokens(); void eattoken(); double gettoken_float(int token, int *success=0); int gettoken_int(int token, int *success=0); - char *gettoken_str(int token); - int gettoken_enum(int token, const char *strlist); // null seperated list + TCHAR *gettoken_str(int token); + int gettoken_enum(int token, const TCHAR *strlist); // null seperated list private: void freetokens(); - int doline(char *line, int ignore_escaping=0); + int doline(TCHAR *line, int ignore_escaping=0); int m_eat; int m_nt; bool m_incommentblock; bool m_incomment; - char **m_tokens; + TCHAR **m_tokens; }; #endif//_LINEPARSE_H_ diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp index 63410269..91f07ec4 100644 --- a/Source/makenssi.cpp +++ b/Source/makenssi.cpp @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/09/2007 */ #include "Platform.h" @@ -22,7 +24,7 @@ #else # include #endif -#include +#include "tstring.h" #include "build.h" #include "util.h" @@ -39,8 +41,8 @@ void quit() { if (g_display_errors) { - fprintf(g_output,"\nNote: you may have one or two (large) stale temporary file(s)\n" - "left in your temporary directory (Generally this only happens on Windows 9x).\n"); + _ftprintf(g_output,_T("\nNote: you may have one or two (large) stale temporary file(s)\n") + _T("left in your temporary directory (Generally this only happens on Windows 9x).\n")); fflush(g_output); } exit(1); @@ -56,7 +58,7 @@ static void sigint(int sig) { if (g_display_errors) { - fprintf(g_output,"\n\nAborting on Ctrl+C...\n"); + _ftprintf(g_output,_T("\n\nAborting on Ctrl+C...\n")); fflush(g_output); } quit(); @@ -65,7 +67,7 @@ static void sigint(int sig) #ifdef _WIN32 static DWORD WINAPI sigint_event_msg_handler(LPVOID) { - HANDLE hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, "makensis win32 signint event"); + HANDLE hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("makensis win32 signint event")); if (hEvent) { @@ -92,59 +94,59 @@ static void init_signals() static void print_logo() { - fprintf(g_output,"MakeNSIS %s - Copyright 1995-2009 Contributors\n" - "See the file COPYING for license details.\n" - "Credits can be found in the Users Manual.\n\n", NSIS_VERSION); + _ftprintf(g_output,_T("MakeNSIS %s - Copyright 1995-2009 Contributors\n") + _T("See the file COPYING for license details.\n") + _T("Credits can be found in the Users Manual.\n\n"), NSIS_VERSION); fflush(g_output); } static void print_license() { - fprintf(g_output,"Copyright (C) 1999-2009 Nullsoft and Contributors\n\n" - "This license applies to everything in the NSIS package, except where otherwise\n" - "noted.\n\n" - "This software is provided 'as-is', without any express or implied warranty.\n" - "In no event will the authors be held liable for any damages arising from the\n" - "use of this software.\n\n" - "Permission is granted to anyone to use this software for any purpose, including\n" - "commercial applications, and to alter it and redistribute it freely, subject to\n" - "the following restrictions:\n" - " 1. The origin of this software must not be misrepresented; you must not claim\n" - " that you wrote the original software. If you use this software in a\n" - " product, an acknowledgment in the product documentation would be\n" - " appreciated but is not required.\n" - " 2. Altered source versions must be plainly marked as such, and must not be\n" - " misrepresented as being the original software.\n" - " 3. This notice may not be removed or altered from any source distribution.\n\n" - "In addition to this license, different licenses apply to the included\n" - "compression modules. See the file COPYING for details.\n"); + _ftprintf(g_output,_T("Copyright (C) 1999-2009 Nullsoft and Contributors\n\n") + _T("This license applies to everything in the NSIS package, except where otherwise\n") + _T("noted.\n\n") + _T("This software is provided 'as-is', without any express or implied warranty.\n") + _T("In no event will the authors be held liable for any damages arising from the\n") + _T("use of this software.\n\n") + _T("Permission is granted to anyone to use this software for any purpose, including\n") + _T("commercial applications, and to alter it and redistribute it freely, subject to\n") + _T("the following restrictions:\n") + _T(" 1. The origin of this software must not be misrepresented; you must not claim\n") + _T(" that you wrote the original software. If you use this software in a\n") + _T(" product, an acknowledgment in the product documentation would be\n") + _T(" appreciated but is not required.\n") + _T(" 2. Altered source versions must be plainly marked as such, and must not be\n") + _T(" misrepresented as being the original software.\n") + _T(" 3. This notice may not be removed or altered from any source distribution.\n\n") + _T("In addition to this license, different licenses apply to the included\n") + _T("compression modules. See the file COPYING for details.\n")); fflush(g_output); } static void print_usage() { - fprintf(g_output,"Usage:\n" - " makensis [option | script.nsi | - [...]]\n" - " options are:\n" - " " OPT_STR "CMDHELP item prints out help for 'item', or lists all commands\n" - " " OPT_STR "HDRINFO prints information about what options makensis was compiled with\n" - " " OPT_STR "LICENSE prints the makensis software license\n" - " " OPT_STR "VERSION prints the makensis version and exits\n" - " " OPT_STR "Px sets the compiler process priority, where x is 5=realtime,4=high,\n" - " " " 3=above normal,2=normal,1=below normal,0=idle\n" - " " OPT_STR "Vx verbosity where x is 4=all,3=no script,2=no info,1=no warnings,0=none\n" - " " OPT_STR "Ofile specifies a text file to log compiler output (default is stdout)\n" - " " OPT_STR "PAUSE pauses after execution\n" - " " OPT_STR "NOCONFIG disables inclusion of " PLATFORM_PATH_SEPARATOR_STR "nsisconf.nsh\n" - " " OPT_STR "NOCD disabled the current directory change to that of the .nsi file\n" - " " OPT_STR "Ddefine[=value] defines the symbol \"define\" for the script [to value]\n" - " " OPT_STR "Xscriptcmd executes scriptcmd in script (i.e. \"" OPT_STR "XOutFile poop.exe\")\n" - " parameters are processed by order (" OPT_STR "Ddef ins.nsi != ins.nsi " OPT_STR "Ddef)\n" - " for script file name, you can use - to read from the standard input\n" + _ftprintf(g_output,_T("Usage:\n") + _T(" makensis [option | script.nsi | - [...]]\n") + _T(" options are:\n") + _T(" ") OPT_STR _T("CMDHELP item prints out help for 'item', or lists all commands\n") + _T(" ") OPT_STR _T("HDRINFO prints information about what options makensis was compiled with\n") + _T(" ") OPT_STR _T("LICENSE prints the makensis software license\n") + _T(" ") OPT_STR _T("VERSION prints the makensis version and exits\n") + _T(" ") OPT_STR _T("Px sets the compiler process priority, where x is 5=realtime,4=high,\n") + _T(" ") _T(" 3=above normal,2=normal,1=below normal,0=idle\n") + _T(" ") OPT_STR _T("Vx verbosity where x is 4=all,3=no script,2=no info,1=no warnings,0=none\n") + _T(" ") OPT_STR _T("Ofile specifies a text file to log compiler output (default is stdout)\n") + _T(" ") OPT_STR _T("PAUSE pauses after execution\n") + _T(" ") OPT_STR _T("NOCONFIG disables inclusion of ") PLATFORM_PATH_SEPARATOR_STR _T("nsisconf.nsh\n") + _T(" ") OPT_STR _T("NOCD disabled the current directory change to that of the .nsi file\n") + _T(" ") OPT_STR _T("Ddefine[=value] defines the symbol \"define\" for the script [to value]\n") + _T(" ") OPT_STR _T("Xscriptcmd executes scriptcmd in script (i.e. \"") OPT_STR _T("XOutFile poop.exe\")\n") + _T(" parameters are processed by order (") OPT_STR _T("Ddef ins.nsi != ins.nsi ") OPT_STR _T("Ddef)\n") + _T(" for script file name, you can use - to read from the standard input\n") #ifdef _WIN32 - " you can also use - as an option character: -PAUSE as well as /PAUSE\n" + _T(" you can also use - as an option character: -PAUSE as well as /PAUSE\n") #endif - " you can use a double-dash to end options processing: makensis -- -ins.nsi\n"); + _T(" you can use a double-dash to end options processing: makensis -- -ins.nsi\n")); fflush(g_output); } @@ -152,91 +154,91 @@ static void print_stub_info(CEXEBuild& build) { if (build.display_info) { - fprintf(g_output,"Size of first header is %lu bytes.\n",(unsigned long)sizeof(firstheader)); - fprintf(g_output,"Size of main header is %lu bytes.\n",(unsigned long)sizeof(header)); - fprintf(g_output,"Size of each section is %lu bytes.\n",(unsigned long)sizeof(section)); - fprintf(g_output,"Size of each page is %lu bytes.\n",(unsigned long)sizeof(page)); - fprintf(g_output,"Size of each instruction is %lu bytes.\n",(unsigned long)sizeof(entry)); + _ftprintf(g_output,_T("Size of first header is %lu bytes.\n"),(unsigned long)sizeof(firstheader)); + _ftprintf(g_output,_T("Size of main header is %lu bytes.\n"),(unsigned long)sizeof(header)); + _ftprintf(g_output,_T("Size of each section is %lu bytes.\n"),(unsigned long)sizeof(section)); + _ftprintf(g_output,_T("Size of each page is %lu bytes.\n"),(unsigned long)sizeof(page)); + _ftprintf(g_output,_T("Size of each instruction is %lu bytes.\n"),(unsigned long)sizeof(entry)); int x=build.definedlist.getnum(); - fprintf(g_output,"\nDefined symbols: "); + _ftprintf(g_output,_T("\nDefined symbols: ")); for (int i=0; i 1 && IS_OPT(argv[1]) && !stricmp(&argv[1][1],"VERSION")) + if (argc > 1 && IS_OPT(argv[1]) && !stricmp(&argv[1][1],_T("VERSION"))) { fprintf(g_output,NSIS_VERSION); fflush(g_output); return 0; } - if (argc > 1 && IS_OPT(argv[1]) && (argv[1][1]=='v' || argv[1][1]=='V')) + if (argc > 1 && IS_OPT(argv[1]) && (argv[1][1]==_T('v') || argv[1][1]==_T('V'))) { tmpargpos++; - if (argv[1][2] <= '2' && argv[1][2] >= '0') + if (argv[1][2] <= _T('2') && argv[1][2] >= _T('0')) { no_logo=1; } @@ -293,12 +296,12 @@ int main(int argc, char **argv) if (!no_logo) { - if (argc > tmpargpos && IS_OPT(argv[tmpargpos]) && (argv[tmpargpos][1]=='o' || argv[tmpargpos][1]=='O') && argv[tmpargpos][2]) + if (argc > tmpargpos && IS_OPT(argv[tmpargpos]) && (argv[tmpargpos][1]==_T('o') || argv[tmpargpos][1]==_T('O')) && argv[tmpargpos][2]) { - g_output=fopen(argv[tmpargpos]+2,"w"); + g_output=fopen(argv[tmpargpos]+2,_T("w")); if (!g_output) { - printf("Error opening output log for writing. Using stdout.\n"); + printf(_T("Error opening output log for writing. Using stdout.\n")); g_output=stdout; } outputtried=1; @@ -311,59 +314,59 @@ int main(int argc, char **argv) if (!g_output) g_output=stdout; while (argpos < argc) { - if (!strcmp(argv[argpos], "--")) + if (!_tcscmp(argv[argpos], _T("--"))) in_files=1; - else if (IS_OPT(argv[argpos]) && strcmp(argv[argpos], "-") && !in_files) + else if (IS_OPT(argv[argpos]) && _tcscmp(argv[argpos], _T("-")) && !in_files) { - if ((argv[argpos][1]=='D' || argv[argpos][1]=='d') && argv[argpos][2]) + if ((argv[argpos][1]==_T('D') || argv[argpos][1]==_T('d')) && argv[argpos][2]) { - char *p=argv[argpos]+2; - char *s=strdup(p),*v; + TCHAR *p=argv[argpos]+2; + TCHAR *s=strdup(p),*v; if (build.display_script) { - fprintf(g_output,"Command line defined: \"%s\"\n",p); + _ftprintf(g_output,_T("Command line defined: \"%s\"\n"),p); fflush(g_output); } - v=strstr(s,"="); + v=_tcsstr(s,_T("=")); if (v) *v++=0; - build.define(s,v?v:""); + build.define(s,v?v:_T("")); free(s); } - else if ((argv[argpos][1]=='X' || argv[argpos][1]=='x') && argv[argpos][2]) + else if ((argv[argpos][1]==_T('X') || argv[argpos][1]==_T('x')) && argv[argpos][2]) { - if (build.process_oneline(argv[argpos]+2,"command line",argpos+1) != PS_OK) + if (build.process_oneline(argv[argpos]+2,_T("command line"),argpos+1) != PS_OK) { return 1; } cmds_processed++; } - else if ((argv[argpos][1]=='O' || argv[argpos][1]=='o') && argv[argpos][2]) + else if ((argv[argpos][1]==_T('O') || argv[argpos][1]==_T('o')) && argv[argpos][2]) { if (!outputtried) { - g_output=fopen(argv[argpos]+2,"w"); + g_output=fopen(argv[argpos]+2,_T("w")); if (!g_output) { - if (build.display_errors) printf("Error opening output log for writing. Using stdout.\n"); + if (build.display_errors) _tprintf(_T("Error opening output log for writing. Using stdout.\n")); g_output=stdout; } outputtried=1; } } - else if (!stricmp(&argv[argpos][1],"NOCD")) do_cd=0; - else if ((argv[argpos][1] == 'V' || argv[argpos][1] == 'v') && - argv[argpos][2] >= '0' && argv[argpos][2] <= '4' && !argv[argpos][3]) + else if (!stricmp(&argv[argpos][1],_T("NOCD"))) do_cd=0; + else if ((argv[argpos][1] == _T('V') || argv[argpos][1] == _T('v')) && + argv[argpos][2] >= _T('0') && argv[argpos][2] <= _T('4') && !argv[argpos][3]) { - int v=argv[argpos][2]-'0'; + int v=argv[argpos][2]-_T('0'); build.display_script=v>3; build.display_info=v>2; build.display_warnings=v>1; build.display_errors=v>0; g_display_errors=build.display_errors; } - else if (!stricmp(&argv[argpos][1],"NOCONFIG")) g_noconfig=1; - else if (!stricmp(&argv[argpos][1],"PAUSE")) g_dopause=1; - else if (!stricmp(&argv[argpos][1],"LICENSE")) + else if (!stricmp(&argv[argpos][1],_T("NOCONFIG"))) g_noconfig=1; + else if (!stricmp(&argv[argpos][1],_T("PAUSE"))) g_dopause=1; + else if (!stricmp(&argv[argpos][1],_T("LICENSE"))) { if (build.display_info) { @@ -371,7 +374,7 @@ int main(int argc, char **argv) } nousage++; } - else if (!stricmp(&argv[argpos][1],"CMDHELP")) + else if (!stricmp(&argv[argpos][1],_T("CMDHELP"))) { if (argpos < argc-1) build.print_help(argv[++argpos]); @@ -379,28 +382,28 @@ int main(int argc, char **argv) build.print_help(NULL); nousage++; } - else if (!stricmp(&argv[argpos][1],"NOTIFYHWND")) + else if (!stricmp(&argv[argpos][1],_T("NOTIFYHWND"))) { #ifdef _WIN32 - build.notify_hwnd=(HWND)atol(argv[++argpos]); + build.notify_hwnd=(HWND)_ttol(argv[++argpos]); if (!IsWindow(build.notify_hwnd)) build.notify_hwnd=0; #else argpos++; - build.warning(OPT_STR "NOTIFYHWND is disabled for non Win32 platforms."); + build.warning(OPT_STR _T("NOTIFYHWND is disabled for non Win32 platforms.")); #endif } - else if (!stricmp(&argv[argpos][1],"HDRINFO")) + else if (!stricmp(&argv[argpos][1],_T("HDRINFO"))) { print_stub_info(build); nousage++; } - else if ((argv[argpos][1]=='P' || argv[argpos][1]=='p') && - argv[argpos][2] >= '0' && argv[argpos][2] <= '5' && !argv[argpos][3]) + else if ((argv[argpos][1]==_T('P') || argv[argpos][1]==_T('p')) && + argv[argpos][2] >= _T('0') && argv[argpos][2] <= _T('5') && !argv[argpos][3]) { #ifdef _WIN32 // priority setting added 01-2007 by Comm@nder21 - int p=argv[argpos][2]-'0'; + int p=argv[argpos][2]-_T('0'); HANDLE hProc = GetCurrentProcess(); struct @@ -422,10 +425,10 @@ int main(int argc, char **argv) } if (p == 5) - build.warning("makensis is running in REALTIME priority mode!"); + build.warning(_T("makensis is running in REALTIME priority mode!")); #else - build.warning(OPT_STR "Px is disabled for non Win32 platforms."); + build.warning(OPT_STR _T("Px is disabled for non Win32 platforms.")); #endif } else break; @@ -433,13 +436,13 @@ int main(int argc, char **argv) else { files_processed++; - if (!strcmp(argv[argpos],"-") && !in_files) + if (!_tcscmp(argv[argpos],_T("-")) && !in_files) g_dopause=0; if (!g_noconfig) { g_noconfig=1; - string main_conf; - char* env_var = getenv("NSISCONFDIR"); + tstring main_conf; + TCHAR* env_var = _tgetenv(_T("NSISCONFDIR")); if(env_var == NULL) #ifndef NSIS_CONFIG_CONST_DATA_PATH main_conf = get_executable_dir(argv[0]); @@ -448,18 +451,18 @@ int main(int argc, char **argv) #endif else main_conf = env_var; main_conf += PLATFORM_PATH_SEPARATOR_STR; - main_conf += "nsisconf.nsh"; + main_conf += _T("nsisconf.nsh"); if (process_config(build, main_conf)) return 1; - string home_conf = get_home(); - if (home_conf != "") + tstring home_conf = get_home(); + if (home_conf != _T("")) { home_conf += PLATFORM_PATH_SEPARATOR_STR; #ifdef _WIN32 - home_conf += "nsisconf.nsh"; + home_conf += _T("nsisconf.nsh"); #else - home_conf += ".nsisconf.nsh"; + home_conf += _T(".nsisconf.nsh"); #endif if (process_config(build, home_conf)) return 1; @@ -467,26 +470,26 @@ int main(int argc, char **argv) } { - char sfile[1024]; - if (!strcmp(argv[argpos],"-") && !in_files) + TCHAR sfile[1024]; + if (!_tcscmp(argv[argpos],_T("-")) && !in_files) { fp=stdin; - strcpy(sfile,"stdin"); + _tcscpy(sfile,_T("stdin")); } else { - strcpy(sfile,argv[argpos]); - fp=fopen(sfile,"rt"); + _tcscpy(sfile,argv[argpos]); + fp=fopen(sfile,_T("rt")); if (!fp) { - sprintf(sfile,"%s.nsi",argv[argpos]); - fp=fopen(sfile,"rt"); + _stprintf(sfile,_T("%s.nsi"),argv[argpos]); + fp=fopen(sfile,_T("rt")); if (!fp) { if (build.display_errors) { - sfile[strlen(sfile)-4]=0; - fprintf(g_output,"Can't open script \"%s\"\n",sfile); + sfile[_tcsclen(sfile)-4]=0; + _ftprintf(g_output,_T("Can't open script \"%s\"\n"),sfile); fflush(g_output); } return 1; @@ -494,7 +497,7 @@ int main(int argc, char **argv) } if (do_cd) { - string script_file = string(sfile); + tstring script_file = tstring(sfile); if (change_to_script_dir(build, script_file)) return 1; } @@ -503,7 +506,7 @@ int main(int argc, char **argv) if (build.display_script) { build.notify(MAKENSIS_NOTIFY_SCRIPT,sfile); - fprintf(g_output,"Processing script file: \"%s\"\n",sfile); + _ftprintf(g_output,_T("Processing script file: \"%s\"\n"),sfile); fflush(g_output); } int ret=build.process_script(fp,sfile); @@ -513,7 +516,7 @@ int main(int argc, char **argv) { if (build.display_errors) { - fprintf(g_output,"Error in script \"%s\" on line %d -- aborting creation process\n",sfile,build.linecnt); + _ftprintf(g_output,_T("Error in script \"%s\" on line %d -- aborting creation process\n"),sfile,build.linecnt); fflush(g_output); } return 1; @@ -534,10 +537,10 @@ int main(int argc, char **argv) if (build.display_info) { - fprintf(g_output,"\nProcessed "); - if (files_processed) fprintf(g_output,"%d file%s, ",files_processed,files_processed==1?"":"s"); - if (cmds_processed) fprintf(g_output,"%d command line command%s, ",cmds_processed,cmds_processed==1?"":"s"); - fprintf(g_output,"writing output:\n"); + _ftprintf(g_output,_T("\nProcessed ")); + if (files_processed) _ftprintf(g_output,_T("%d file%s, "),files_processed,files_processed==1?_T(""):_T("s")); + if (cmds_processed) _ftprintf(g_output,_T("%d command line command%s, "),cmds_processed,cmds_processed==1?_T(""):_T("s")); + _ftprintf(g_output,_T("writing output:\n")); fflush(g_output); } @@ -545,7 +548,7 @@ int main(int argc, char **argv) { if (build.display_errors) { - fprintf(g_output,"Error - aborting creation process\n"); + _ftprintf(g_output,_T("Error - aborting creation process\n")); fflush(g_output); } return 1; diff --git a/Source/manifest.cpp b/Source/manifest.cpp index c5fbd105..d36890dc 100644 --- a/Source/manifest.cpp +++ b/Source/manifest.cpp @@ -12,11 +12,16 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/22/2007 */ #include "Platform.h" #include "manifest.h" #include +#include "tstring.h" + +// Jim Park: The manifest must stay UTF-8. Do not convert. namespace manifest { diff --git a/Source/manifest.h b/Source/manifest.h index b8975cb0..e018e895 100644 --- a/Source/manifest.h +++ b/Source/manifest.h @@ -12,12 +12,14 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/22/2007 */ #ifndef ___MANIFEST_H___ #define ___MANIFEST_H___ -#include +#include "tstring.h" namespace manifest { diff --git a/Source/mmap.cpp b/Source/mmap.cpp index 1e0be7a0..3d0246fb 100644 --- a/Source/mmap.cpp +++ b/Source/mmap.cpp @@ -15,9 +15,9 @@ */ #include "mmap.h" - #include // for f* #include // for assert +#include "tchar.h" #ifndef _WIN32 # include // for freebsd # include @@ -146,10 +146,10 @@ void MMapFile::resize(int newsize) #ifdef _WIN32 if (m_hFile == INVALID_HANDLE_VALUE) { - char buf[MAX_PATH], buf2[MAX_PATH]; + TCHAR buf[MAX_PATH], buf2[MAX_PATH]; GetTempPath(MAX_PATH, buf); - GetTempFileName(buf, "nsd", 0, buf2); + GetTempFileName(buf, _T("nsd"), 0, buf2); m_hFile = CreateFile( buf2, @@ -219,7 +219,7 @@ void MMapFile::resize(int newsize) extern void quit(); extern int g_display_errors; if (g_display_errors) { - fprintf(g_output,"\nInternal compiler error #12345: error creating mmap the size of %d.\n", m_iSize); + _ftprintf(g_output,_T("\nInternal compiler error #12345: error creating mmap the size of %d.\n"), m_iSize); fflush(g_output); } quit(); @@ -252,7 +252,7 @@ void *MMapFile::get(int offset, int *sizep) const extern void quit(); extern int g_display_errors; if (g_display_errors) { - fprintf(g_output,"\nInternal compiler error #12345: error mmapping file (%d, %d) is out of range.\n", offset, size); + _ftprintf(g_output,_T("\nInternal compiler error #12345: error mmapping file (%d, %d) is out of range.\n"), offset, size); fflush(g_output); } quit(); @@ -279,7 +279,7 @@ void *MMapFile::get(int offset, int *sizep) const extern void quit(); extern int g_display_errors; if (g_display_errors) { - fprintf(g_output,"\nInternal compiler error #12345: error mmapping datablock to %d.\n", size); + _ftprintf(g_output,_T("\nInternal compiler error #12345: error mmapping datablock to %d.\n"), size); fflush(g_output); } quit(); diff --git a/Source/mmap.h b/Source/mmap.h index e05a87af..07c22c08 100644 --- a/Source/mmap.h +++ b/Source/mmap.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ #ifndef __MMAP_H_ @@ -51,20 +53,108 @@ class MMapFile : public IMMap MMapFile(); virtual ~MMapFile(); + /** + * Closes the memory map and the file handle. + */ void clear(); + + /** + * Set read-only. + * @param bRO Boolean value to set read-only. + */ void setro(BOOL bRO); + + /** + * Creates the memory mapping object of the file with a mapping size. + * + * @param hFile The handle to the opened file. + * @param dwSize The size of the memory mapped object. You cannot set + * this value to zero like with CreateFileMapping() because it will + * immediately return. Most likely, you want to set it to the size + * of the file unless you want to only map a part of the file on + * purpose. + * @return Returns 1 on success, 0 on failure. + */ #ifdef _WIN32 int setfile(HANDLE hFile, DWORD dwSize); #else int setfile(int hFile, DWORD dwSize); #endif + + /** + * Resize the memory mapping of the file. Used when the filesize has + * changed. When setfile has not been called previously, then it will + * create a temporary file and use it to create a memory map. This is + * what's used by MMapBuf to create a Memory Mapped Buffer. + * + * @param newsize The new size of the file. Limited to 32-bits. + */ void resize(int newsize); + + /** + * Size of the memory map object. + */ int getsize() const; + + /** + * Set the memory map to a particular offset in the file and return the + * memory mapped pointer to it. Internally it may have to align to a + * certain page size. + * + * @param offset The offset from the beginning of the file. + * @param size The size of the memory map window. + */ void *get(int offset, int size) const; + + /** + * Set the memory map to a particular offset in the file and return the + * memory mapped pointer to it. Internally it may have to align to a + * certain page size. + * + * @param offset The offset from the beginning of the file. + * @param sizep [in/out] The size of the memory map window. (In non-Win32 + * systems, the new size is written back out.) + */ void *get(int offset, int *sizep) const; + + /** + * This function sets memory map and just hands you the pointer and + * it expects you to manage it. So you need to call release(pView, size) + * yourself or you will leak memory. + * + * Warning: This breaks encapsulation. The user should probably just + * create a new map. + * + * @param offset The offset from the beginning of the file. + * @param size The size of the memory map window. + */ void *getmore(int offset, int size) const; + + /** + * Releases the memory map currently being used. Calls UnMapViewOfFile(). + */ void release(); + + /** + * Releases the memory map pointed to by pView. In Win32 systems + * eventually calls UnmapViewOfFile(). Interestingly, the function + * tries to align the pointer value back to the beginning of the + * paged memory which is necessary because of the way get() works. + * + * This looks like it should only be used in conjunction with + * getmore(). Otherwise, just call release(). + * + * @param pView The pointer to somewhere in a MemMapped object. + * @param size The size of the object. Used only in non-Win32 systems. + */ void release(void *pView, int size); + + /** + * Flushes the contents of the current memory map to disk. Set size to 0 + * if you want to flush everything. + * + * @param num The number of bytes to flush. 0 for everything. + */ void flush(int num); private: @@ -109,6 +199,15 @@ class MMapFake : public IMMap int m_iSize; }; +/** + * A data structure that can be used to create a scratch file to do + * work in. When it's smaller than 16mb, it's all in memory using the + * GrowBuf class. But when it gets biggered than 16mb, then it uses + * the MMapFile class to create a memory map to a temporary file and + * then uses it. This reduces memory overhead of the installer. + * + * This is sort of our virtual memory manager. + */ class MMapBuf : public IGrowBuf, public IMMap { private: // don't copy instances diff --git a/Source/script.cpp b/Source/script.cpp index a492051a..bbcb895a 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -31,7 +31,7 @@ #include "exehead/resource.h" #include // for assert(3) #include -#include +#include "tstring.h" #include #include "boost/scoped_ptr.hpp" @@ -52,47 +52,47 @@ using namespace std; #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 -char *CEXEBuild::set_file_predefine(const char *filename) +TCHAR *CEXEBuild::set_file_predefine(const TCHAR *filename) { - char *oldfilename = definedlist.find("__FILE__"); + TCHAR *oldfilename = definedlist.find(_T("__FILE__")); if(oldfilename) { oldfilename = strdup(oldfilename); - definedlist.del("__FILE__"); + definedlist.del(_T("__FILE__")); } - const char *p = strrchr(filename,'\\'); + const TCHAR *p = _tcsrchr(filename,_T('\\')); if(p) { p++; } else { p = curfilename; } - definedlist.add("__FILE__",p); + definedlist.add(_T("__FILE__"),p); return oldfilename; } -void CEXEBuild::restore_file_predefine(char *oldfilename) +void CEXEBuild::restore_file_predefine(TCHAR *oldfilename) { - definedlist.del("__FILE__"); + definedlist.del(_T("__FILE__")); if(oldfilename) { - definedlist.add("__FILE__",oldfilename); + definedlist.add(_T("__FILE__"),oldfilename); free(oldfilename); } } -char *CEXEBuild::set_timestamp_predefine(const char *filename) +TCHAR *CEXEBuild::set_timestamp_predefine(const TCHAR *filename) { - char *oldtimestamp = definedlist.find("__TIMESTAMP__"); + TCHAR *oldtimestamp = definedlist.find(_T("__TIMESTAMP__")); if(oldtimestamp) { oldtimestamp = strdup(oldtimestamp); - definedlist.del("__TIMESTAMP__"); + definedlist.del(_T("__TIMESTAMP__")); } #ifdef _WIN32 - char timestampbuf[256] = ""; - char datebuf[128] = ""; - char timebuf[128] = ""; + TCHAR timestampbuf[256] = _T(""); + TCHAR datebuf[128] = _T(""); + TCHAR timebuf[128] = _T(""); WIN32_FIND_DATA fd; FILETIME floctime; SYSTEMTIME stime; @@ -105,60 +105,60 @@ char *CEXEBuild::set_timestamp_predefine(const char *filename) FileTimeToLocalFileTime(&fd.ftLastWriteTime, &floctime); FileTimeToSystemTime(&floctime, &stime); - GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &stime, NULL, datebuf, sizeof(datebuf)); - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, sizeof(timebuf)); - wsprintf(timestampbuf,"%s %s",datebuf,timebuf); + GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &stime, NULL, datebuf, sizeof(datebuf)/sizeof(datebuf[0])); + GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, sizeof(timebuf)/sizeof(timebuf[0])); + wsprintf(timestampbuf,_T("%s %s"),datebuf,timebuf); - definedlist.add("__TIMESTAMP__",timestampbuf); + definedlist.add(_T("__TIMESTAMP__"),timestampbuf); } #else struct stat st; if (!stat(filename, &st)) - definedlist.add("__TIMESTAMP__",ctime(&st.st_mtime)); + definedlist.add(_T("__TIMESTAMP__"),_tctime(&st.st_mtime)); #endif return oldtimestamp; } -void CEXEBuild::restore_timestamp_predefine(char *oldtimestamp) +void CEXEBuild::restore_timestamp_predefine(TCHAR *oldtimestamp) { - definedlist.del("__TIMESTAMP__"); + definedlist.del(_T("__TIMESTAMP__")); if(oldtimestamp) { - definedlist.add("__TIMESTAMP__",oldtimestamp); + definedlist.add(_T("__TIMESTAMP__"),oldtimestamp); free(oldtimestamp); } } -char *CEXEBuild::set_line_predefine(int linecnt, BOOL is_macro) +TCHAR *CEXEBuild::set_line_predefine(int linecnt, BOOL is_macro) { - char* linebuf = NULL; + TCHAR* linebuf = NULL; MANAGE_WITH(linebuf, free); - char temp[128] = ""; - sprintf(temp,"%d",linecnt); + TCHAR temp[128] = _T(""); + _stprintf(temp,_T("%d"),linecnt); - char *oldline = definedlist.find("__LINE__"); + TCHAR *oldline = definedlist.find(_T("__LINE__")); if(oldline) { oldline = strdup(oldline); - definedlist.del("__LINE__"); + definedlist.del(_T("__LINE__")); } if(is_macro && oldline) { - linebuf = (char *)malloc(strlen(oldline)+strlen(temp)+2); - sprintf(linebuf,"%s.%s",oldline,temp); + linebuf = (TCHAR *)malloc((_tcsclen(oldline)+_tcsclen(temp)+2)*sizeof(TCHAR)); + _stprintf(linebuf,_T("%s.%s"),oldline,temp); } else { linebuf = strdup(temp); } - definedlist.add("__LINE__",linebuf); + definedlist.add(_T("__LINE__"),linebuf); return oldline; } -void CEXEBuild::restore_line_predefine(char *oldline) +void CEXEBuild::restore_line_predefine(TCHAR *oldline) { - definedlist.del("__LINE__"); + definedlist.del(_T("__LINE__")); if(oldline) { - definedlist.add("__LINE__",oldline); + definedlist.add(_T("__LINE__"),oldline); free(oldline); } } @@ -167,8 +167,8 @@ void CEXEBuild::set_date_time_predefines() { time_t etime; struct tm * ltime; - char datebuf[128]; - char timebuf[128]; + TCHAR datebuf[128]; + TCHAR timebuf[128]; time(&etime); ltime = localtime(&etime); @@ -182,25 +182,25 @@ void CEXEBuild::set_date_time_predefines() stime.wSecond= ltime->tm_sec; stime.wMilliseconds= 0; GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stime, NULL, datebuf, sizeof(datebuf)); - definedlist.add("__DATE__",(char *)datebuf); + definedlist.add(_T("__DATE__"),(TCHAR *)datebuf); GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, sizeof(timebuf)); - definedlist.add("__TIME__",(char *)timebuf); + definedlist.add(_T("__TIME__"),(TCHAR *)timebuf); #else - my_strftime(datebuf, sizeof(datebuf), "%x", ltime); - definedlist.add("__DATE__",(char *)datebuf); - my_strftime(timebuf, sizeof(timebuf), "%X", ltime); - definedlist.add("__TIME__",(char *)timebuf); + my_strftime(datebuf, sizeof(datebuf), _T("%x"), ltime); + definedlist.add(_T("__DATE__"),(TCHAR *)datebuf); + my_strftime(timebuf, sizeof(timebuf), _T("%X"), ltime); + definedlist.add(_T("__TIME__"),(TCHAR *)timebuf); #endif } void CEXEBuild::del_date_time_predefines() { - definedlist.del("__DATE__"); - definedlist.del("__TIME__"); + definedlist.del(_T("__DATE__")); + definedlist.del(_T("__TIME__")); } #endif -int CEXEBuild::process_script(FILE *filepointer, const char *filename) +int CEXEBuild::process_script(FILE *filepointer, const TCHAR *filename) { linecnt = 0; fp = filepointer; @@ -208,15 +208,15 @@ int CEXEBuild::process_script(FILE *filepointer, const char *filename) if (has_called_write_output) { - ERROR_MSG("Error (process_script): write_output already called, can't continue\n"); + ERROR_MSG(_T("Error (process_script): write_output already called, can't continue\n")); return PS_ERROR; } #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 set_date_time_predefines(); - char *oldfilename = set_file_predefine(curfilename); - char *oldtimestamp = set_timestamp_predefine(curfilename); + TCHAR *oldfilename = set_file_predefine(curfilename); + TCHAR *oldtimestamp = set_timestamp_predefine(curfilename); #endif int ret=parseScript(); @@ -233,13 +233,13 @@ int CEXEBuild::process_script(FILE *filepointer, const char *filename) if (m_linebuild.getlen()) { - ERROR_MSG("Error: invalid script: last line ended with \\\n"); + ERROR_MSG(_T("Error: invalid script: last line ended with \\\n")); return PS_ERROR; } if (ret == PS_EOF && num_ifblock()) { - ERROR_MSG("!if[macro][n]def: open at EOF - need !endif\n"); + ERROR_MSG(_T("!if[macro][n]def: open at EOF - need !endif\n")); return PS_ERROR; } @@ -275,36 +275,36 @@ int CEXEBuild::num_ifblock() } // Func size: just under 200 lines (orip) -int CEXEBuild::doParse(const char *str) +int CEXEBuild::doParse(const TCHAR *str) { LineParser line(inside_comment); int res; - while (*str == ' ' || *str == '\t') str++; + while (*str == _T(' ') || *str == _T('\t')) str++; // remove trailing slash and null, if there's a previous line if (m_linebuild.getlen()>1) - m_linebuild.resize(m_linebuild.getlen()-2); + m_linebuild.resize(m_linebuild.getlen()-(2*sizeof(TCHAR))); // warn of comment with line-continuation if (m_linebuild.getlen()) { LineParser prevline(inside_comment); - prevline.parse((char*)m_linebuild.get()); + prevline.parse((TCHAR*)m_linebuild.get()); LineParser thisline(inside_comment); - thisline.parse((char*)str); + thisline.parse((TCHAR*)str); if (prevline.inComment() && !thisline.inComment()) { - warning_fl("comment contains line-continuation character, following line will be ignored"); + warning_fl(_T("comment contains line-continuation character, following line will be ignored")); } } // add new line to line buffer - m_linebuild.add(str,strlen(str)+1); + m_linebuild.add(str,(_tcsclen(str)+1)*sizeof(TCHAR)); // keep waiting for more lines, if this line ends with a backslash - if (str[0] && CharPrev(str,str+strlen(str))[0] == '\\') + if (str[0] && CharPrev(str,str+_tcsclen(str))[0] == _T('\\')) { return PS_OK; } @@ -313,16 +313,16 @@ int CEXEBuild::doParse(const char *str) // escaped quotes should be ignored for compile time commands that set defines // because defines can be inserted in commands at a later stage - bool ignore_escaping = (!strnicmp((char*)m_linebuild.get(),"!define",7) || !strnicmp((char*)m_linebuild.get(),"!insertmacro",12)); - res=line.parse((char*)m_linebuild.get(), ignore_escaping); + bool ignore_escaping = (!strnicmp((TCHAR*)m_linebuild.get(),_T("!define"),7) || !strnicmp((TCHAR*)m_linebuild.get(),_T("!insertmacro"),12)); + res=line.parse((TCHAR*)m_linebuild.get(), ignore_escaping); inside_comment = line.inCommentBlock(); // if ignoring, ignore all lines that don't begin with an exclamation mark { bool ignore_line = cur_ifblock && (cur_ifblock->ignore || cur_ifblock->inherited_ignore); - char first_char = *(char *) m_linebuild.get(); - if (ignore_line && (first_char!='!' || !is_valid_token(line.gettoken_str(0)))) + TCHAR first_char = *(TCHAR *) m_linebuild.get(); + if (ignore_line && (first_char!=_T('!') || !is_valid_token(line.gettoken_str(0)))) { m_linebuild.resize(0); return PS_OK; @@ -333,8 +333,8 @@ int CEXEBuild::doParse(const char *str) if (res) { - if (res==-2) ERROR_MSG("Error: unterminated string parsing line at %s:%d\n",curfilename,linecnt); - else ERROR_MSG("Error: error parsing line (%s:%d)\n",curfilename,linecnt); + if (res==-2) ERROR_MSG(_T("Error: unterminated string parsing line at %s:%d\n"),curfilename,linecnt); + else ERROR_MSG(_T("Error: error parsing line (%s:%d)\n"),curfilename,linecnt); return PS_ERROR; } @@ -345,12 +345,12 @@ parse_again: int tkid=get_commandtoken(line.gettoken_str(0),&np,&op,&pos); if (tkid == -1) { - char *p=line.gettoken_str(0); - if (p[0] && p[strlen(p)-1]==':') + TCHAR *p=line.gettoken_str(0); + if (p[0] && p[_tcsclen(p)-1]==_T(':')) { - if (p[0] == '!' || (p[0] >= '0' && p[0] <= '9') || p[0] == '$' || p[0] == '-' || p[0] == '+') + if (p[0] == _T('!') || (p[0] >= _T('0') && p[0] <= _T('9')) || p[0] == _T('$') || p[0] == _T('-') || p[0] == _T('+')) { - ERROR_MSG("Invalid label: %s (labels cannot begin with !, $, -, +, or 0-9)\n",line.gettoken_str(0)); + ERROR_MSG(_T("Invalid label: %s (labels cannot begin with !, $, -, +, or 0-9)\n"),line.gettoken_str(0)); return PS_ERROR; } if (add_label(line.gettoken_str(0))) return PS_ERROR; @@ -372,7 +372,7 @@ parse_again: else #endif { - ERROR_MSG("Invalid command: %s\n",line.gettoken_str(0)); + ERROR_MSG(_T("Invalid command: %s\n"),line.gettoken_str(0)); return PS_ERROR; } } @@ -383,10 +383,10 @@ parse_again: int v=line.getnumtokens()-(np+1); if (v < 0 || (op >= 0 && v > op)) // opt_parms is -1 for unlimited { - ERROR_MSG("%s expects %d",line.gettoken_str(0),np); - if (op < 0) ERROR_MSG("+"); - if (op > 0) ERROR_MSG("-%d",op+np); - ERROR_MSG(" parameters, got %d.\n",line.getnumtokens()-1); + ERROR_MSG(_T("%s expects %d"),line.gettoken_str(0),np); + if (op < 0) ERROR_MSG(_T("+")); + if (op > 0) ERROR_MSG(_T("-%d"),op+np); + ERROR_MSG(_T(" parameters, got %d.\n"),line.getnumtokens()-1); PRINTHELP() } @@ -399,13 +399,13 @@ parse_again: if (!num_ifblock()) { - ERROR_MSG("!else: no if block open (!if[macro][n][def])\n"); + ERROR_MSG(_T("!else: no if block open (!if[macro][n][def])\n")); return PS_ERROR; } if (cur_ifblock->elseused) { - ERROR_MSG("!else: else already used in current if block\n"); + ERROR_MSG(_T("!else: else already used in current if block\n")); return PS_ERROR; } @@ -426,7 +426,7 @@ parse_again: line.eattoken(); - int v=line.gettoken_enum(0,"if\0ifdef\0ifndef\0ifmacrodef\0ifmacrondef\0"); + int v=line.gettoken_enum(0,_T("if\0ifdef\0ifndef\0ifmacrodef\0ifmacrondef\0")); if (v < 0) PRINTHELP() if (line.getnumtokens() == 1) PRINTHELP() int cmds[] = {TOK_P_IF, TOK_P_IFDEF, TOK_P_IFNDEF, TOK_P_IFMACRODEF, TOK_P_IFMACRONDEF}; @@ -453,7 +453,7 @@ parse_again: int p=0; if (tkid == TOK_P_IF) { - if(!strcmp(line.gettoken_str(1),"!")) { + if(!_tcscmp(line.gettoken_str(1),_T("!"))) { p = 1; line.eattoken(); } @@ -462,7 +462,7 @@ parse_again: istrue = line.gettoken_int(1); else if (line.getnumtokens() == 4) { - mod = line.gettoken_enum(2,"=\0==\0!=\0<=\0<\0>\0>=\0&\0&&\0|\0||\0"); + mod = line.gettoken_enum(2,_T("=\0==\0!=\0<=\0<\0>\0>=\0&\0&&\0|\0||\0")); switch(mod) { case 0: @@ -513,7 +513,7 @@ parse_again: } else { - mod=line.gettoken_enum(p,"|\0&\0||\0&&\0"); + mod=line.gettoken_enum(p,_T("|\0&\0||\0&&\0")); if (mod == -1) PRINTHELP() mod &= 1; } @@ -533,7 +533,7 @@ parse_again: if (tkid == TOK_P_ENDIF) { if (!num_ifblock()) { - ERROR_MSG("!endif: no if block open (!if[macro][n][def])\n"); + ERROR_MSG(_T("!endif: no if block open (!if[macro][n][def])\n")); return PS_ERROR; } end_ifblock(); @@ -549,60 +549,60 @@ parse_again: // Func size: about 140 lines (orip) #ifdef NSIS_FIX_DEFINES_IN_STRINGS -void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist, bool bIgnoreDefines /*= false*/) +void CEXEBuild::ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hist, bool bIgnoreDefines /*= false*/) #else -void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist) +void CEXEBuild::ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hist) #endif { // convert $\r, $\n to their literals // preprocessor replace ${VAR} and $%VAR% with whatever value // note that if VAR does not exist, ${VAR} or $%VAR% will go through unmodified - const char *in=str; + const TCHAR *in=str; while (*in) { int add=1; - char *t; - char c=*in; + TCHAR *t; + TCHAR c=*in; t=CharNext(in); if (t-in > 1) // handle multibyte chars (no escape) { - linedata.add((void*)in,t-in); + linedata.add((void*)in,(t-in)*sizeof(TCHAR)); in=t; continue; } in=t; - if (c == '$') + if (c == _T('$')) { - if (in[0] == '\\') + if (in[0] == _T('\\')) { - if (in[1] == 'r') + if (in[1] == _T('r')) { in+=2; - c='\r'; + c=_T('\r'); } - else if (in[1] == 'n') + else if (in[1] == _T('n')) { in+=2; - c='\n'; + c=_T('\n'); } - else if (in[1] == 't') + else if (in[1] == _T('t')) { in+=2; - c='\t'; + c=_T('\t'); } } - else if (in[0] == '{') + else if (in[0] == _T('{')) { - char *s=strdup(in+1); + TCHAR *s=strdup(in+1); MANAGE_WITH(s, free); - char *t=s; + TCHAR *t=s; unsigned int bn = 0; while (*t) { - if (*t == '{') bn++; - if (*t == '}' && bn-- == 0) break; + if (*t == _T('{')) bn++; + if (*t == _T('}') && bn-- == 0) break; t=CharNext(t); } if (*t && t!=s @@ -615,30 +615,30 @@ void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &his // check for defines inside the define name - ${bla${blo}} GrowBuf defname; ps_addtoline(s,defname,hist); - defname.add("",1); - t=definedlist.find((char*)defname.get()); - if (t && hist.find((char*)defname.get(),0)<0) + defname.add(_T(""),sizeof(_T(""))); + t=definedlist.find((TCHAR*)defname.get()); + if (t && hist.find((TCHAR*)defname.get(),0)<0) { - in+=strlen(s)+2; + in+=_tcsclen(s)+2; add=0; - hist.add((char*)defname.get(),0); + hist.add((TCHAR*)defname.get(),0); #ifdef NSIS_FIX_DEFINES_IN_STRINGS ps_addtoline(t,linedata,hist,true); #else ps_addtoline(t,linedata,hist); #endif - hist.delbypos(hist.find((char*)defname.get(),0)); + hist.delbypos(hist.find((TCHAR*)defname.get(),0)); } } } - else if (in[0] == '%') + else if (in[0] == _T('%')) { - char *s=strdup(in+1); + TCHAR *s=strdup(in+1); MANAGE_WITH(s, free); - char *t=s; + TCHAR *t=s; while (*t) { - if (*t == '%') break; + if (*t == _T('%')) break; t=CharNext(t); } if (*t && t!=s) @@ -647,35 +647,35 @@ void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &his // check for defines inside the define name - ${bla${blo}} GrowBuf defname; ps_addtoline(s,defname,hist); - defname.add("",1); - t=getenv((char*)defname.get()); - if (t && hist.find((char*)defname.get(),0)<0) + defname.add(_T(""),sizeof(_T(""))); + t=_tgetenv((TCHAR*)defname.get()); + if (t && hist.find((TCHAR*)defname.get(),0)<0) { - in+=strlen(s)+2; + in+=_tcsclen(s)+2; add=0; - hist.add((char*)defname.get(),0); + hist.add((TCHAR*)defname.get(),0); #ifdef NSIS_FIX_DEFINES_IN_STRINGS ps_addtoline(t,linedata,hist,true); #else ps_addtoline(t,linedata,hist); #endif - hist.delbypos(hist.find((char*)defname.get(),0)); + hist.delbypos(hist.find((TCHAR*)defname.get(),0)); } } } #ifdef NSIS_FIX_DEFINES_IN_STRINGS - else if (in[0] == '$') + else if (in[0] == _T('$')) { - if (in[1] == '{') // Found $$ before - Don't replace this define + if (in[1] == _T('{')) // Found $$ before - Don't replace this define { - char *s=strdup(in+2); + TCHAR *s=strdup(in+2); MANAGE_WITH(s, free); - char *t=s; + TCHAR *t=s; unsigned int bn = 0; while (*t) { - if (*t == '{') bn++; - if (*t == '}' && bn-- == 0) break; + if (*t == _T('{')) bn++; + if (*t == _T('}') && bn-- == 0) break; t=CharNext(t); } if (*t && t!=s) @@ -689,32 +689,32 @@ void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &his } else { - linedata.add((void*)&c,1); + linedata.add((void*)&c,1*sizeof(TCHAR)); in++; } } #endif } - if (add) linedata.add((void*)&c,1); + if (add) linedata.add((void*)&c,1*sizeof(TCHAR)); } } int CEXEBuild::parseScript() { - char str[MAX_LINELENGTH]; + TCHAR str[MAX_LINELENGTH]; for (;;) { - char *p=str; + TCHAR *p=str; *p=0; - fgets(str,MAX_LINELENGTH,fp); + _fgetts(str,MAX_LINELENGTH,fp); linecnt++; if (feof(fp)&&!str[0]) break; // remove trailing whitespace while (*p) p++; if (p > str) p--; - while (p >= str && (*p == '\r' || *p == '\n' || *p == ' ' || *p == '\t')) p--; + while (p >= str && (*p == _T('\r') || *p == _T('\n') || *p == _T(' ') || *p == _T('\t'))) p--; *++p=0; StringList hist; @@ -722,12 +722,12 @@ int CEXEBuild::parseScript() #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 - char *oldline = set_line_predefine(linecnt, FALSE); + TCHAR *oldline = set_line_predefine(linecnt, FALSE); #endif ps_addtoline(str,linedata,hist); - linedata.add((void*)"",1); - int ret=doParse((char*)linedata.get()); + linedata.add(_T(""),sizeof(_T(""))); + int ret=doParse((TCHAR*)linedata.get()); #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 @@ -740,13 +740,13 @@ int CEXEBuild::parseScript() return PS_EOF; } -int CEXEBuild::includeScript(char *f) +int CEXEBuild::includeScript(TCHAR *f) { - SCRIPT_MSG("!include: \"%s\"\n",f); - FILE *incfp=FOPEN(f,"rt"); + SCRIPT_MSG(_T("!include: \"%s\"\n"),f); + FILE *incfp=FOPEN(f,_T("rt")); if (!incfp) { - ERROR_MSG("!include: could not open file: \"%s\"\n",f); + ERROR_MSG(_T("!include: could not open file: \"%s\"\n"),f); return PS_ERROR; } @@ -755,22 +755,22 @@ int CEXEBuild::includeScript(char *f) if (build_include_depth >= MAX_INCLUDEDEPTH) { - ERROR_MSG("parseScript: too many levels of includes (%d max).\n",MAX_INCLUDEDEPTH); + ERROR_MSG(_T("parseScript: too many levels of includes (%d max).\n"),MAX_INCLUDEDEPTH); return PS_ERROR; } build_include_depth++; int last_linecnt=linecnt; linecnt=0; - const char *last_filename=curfilename; + const TCHAR *last_filename=curfilename; curfilename=f; FILE *last_fp=fp; fp=incfp; #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 - char *oldfilename = set_file_predefine(curfilename); - char *oldtimestamp = set_timestamp_predefine(curfilename); + TCHAR *oldfilename = set_file_predefine(curfilename); + TCHAR *oldtimestamp = set_timestamp_predefine(curfilename); #endif int r=parseScript(); @@ -790,17 +790,17 @@ int CEXEBuild::includeScript(char *f) build_include_depth--; if (r != PS_EOF && r != PS_OK) { - ERROR_MSG("!include: error in script: \"%s\" on line %d\n",f,errlinecnt); + ERROR_MSG(_T("!include: error in script: \"%s\" on line %d\n"),f,errlinecnt); return PS_ERROR; } - SCRIPT_MSG("!include: closed: \"%s\"\n",f); + SCRIPT_MSG(_T("!include: closed: \"%s\"\n"),f); return PS_OK; } // !ifmacro[n]def based on Anders Kjersem's code -int CEXEBuild::MacroExists(const char *macroname) +int CEXEBuild::MacroExists(const TCHAR *macroname) { - char *m = (char *) m_macros.get(); + TCHAR *m = (TCHAR *) m_macros.get(); while (m && *m) { @@ -809,23 +809,23 @@ int CEXEBuild::MacroExists(const char *macroname) return 1; // skip macro name - m += strlen(m) + 1; + m += _tcsclen(m) + 1; // skip params - while (*m) m += strlen(m) + 1; + while (*m) m += _tcsclen(m) + 1; m++; // skip data - while (*m) m += strlen(m) + 1; - if (m - (char *) m_macros.get() >= m_macros.getlen() - 1) break; + while (*m) m += _tcsclen(m) + 1; + if (m - (TCHAR *) m_macros.get() >= m_macros.getlen() - 1) break; m++; } return 0; } -int CEXEBuild::process_oneline(char *line, const char *filename, int linenum) +int CEXEBuild::process_oneline(TCHAR *line, const TCHAR *filename, int linenum) { - const char *last_filename=curfilename; + const TCHAR *last_filename=curfilename; curfilename=filename; int last_linecnt=linecnt; linecnt=linenum; @@ -835,11 +835,11 @@ int CEXEBuild::process_oneline(char *line, const char *filename, int linenum) #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 - char *oldfilename = NULL; - char *oldtimestamp = NULL; - char *oldline = NULL; - BOOL is_commandline = !strcmp(filename,"command line"); - BOOL is_macro = !strncmp(filename,"macro:",strlen("macro:")); + TCHAR *oldfilename = NULL; + TCHAR *oldtimestamp = NULL; + TCHAR *oldline = NULL; + BOOL is_commandline = !_tcscmp(filename,_T("command line")); + BOOL is_macro = !_tcsncmp(filename,_T("macro:"),_tcsclen(_T("macro:"))); if(!is_commandline) { // Don't set the predefines for command line /X option if(!is_macro) { @@ -851,8 +851,8 @@ int CEXEBuild::process_oneline(char *line, const char *filename, int linenum) #endif ps_addtoline(line,linedata,hist); - linedata.add((void*)"",1); - int ret=doParse((char*)linedata.get()); + linedata.add(_T(""),sizeof(_T(""))); + int ret=doParse((TCHAR*)linedata.get()); #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 @@ -873,24 +873,24 @@ int CEXEBuild::process_oneline(char *line, const char *filename, int linenum) int CEXEBuild::process_jump(LineParser &line, int wt, int *offs) { - const char *s=line.gettoken_str(wt); + const TCHAR *s=line.gettoken_str(wt); int v; - if (!stricmp(s,"0") || !stricmp(s,"")) *offs=0; + if (!stricmp(s,_T("0")) || !stricmp(s,_T(""))) *offs=0; else if ((v=GetUserVarIndex(line, wt))>=0) { *offs=-v-1; // to jump to a user variable target, -variable_index-1 is stored. } else { - if ((s[0] == '-' || s[0] == '+') && !atoi(s+1)) + if ((s[0] == _T('-') || s[0] == _T('+')) && !_ttoi(s+1)) { - ERROR_MSG("Error: Goto targets beginning with '+' or '-' must be followed by nonzero integer (relative jump)\n"); + ERROR_MSG(_T("Error: Goto targets beginning with '+' or '-' must be followed by nonzero integer (relative jump)\n")); return 1; } - if ((s[0] >= '0' && s[0] <= '9') || s[0] == '$' || s[0] == '!') + if ((s[0] >= _T('0') && s[0] <= _T('9')) || s[0] == _T('$') || s[0] == _T('!')) { - ERROR_MSG("Error: Goto targets cannot begin with 0-9, $, !\n"); + ERROR_MSG(_T("Error: Goto targets cannot begin with 0-9, $, !\n")); return 1; } *offs=ns_label.add(s,0); @@ -905,9 +905,9 @@ int CEXEBuild::process_jump(LineParser &line, int wt, int *offs) // Func size: about 5000 lines (orip) int CEXEBuild::doCommand(int which_token, LineParser &line) { - static const char *rootkeys[2] = { - "HKCR\0HKLM\0HKCU\0HKU\0HKCC\0HKDD\0HKPD\0SHCTX\0", - "HKEY_CLASSES_ROOT\0HKEY_LOCAL_MACHINE\0HKEY_CURRENT_USER\0HKEY_USERS\0HKEY_CURRENT_CONFIG\0HKEY_DYN_DATA\0HKEY_PERFORMANCE_DATA\0SHELL_CONTEXT\0" + static const TCHAR *rootkeys[2] = { + _T("HKCR\0HKLM\0HKCU\0HKU\0HKCC\0HKDD\0HKPD\0SHCTX\0"), + _T("HKEY_CLASSES_ROOT\0HKEY_LOCAL_MACHINE\0HKEY_CURRENT_USER\0HKEY_USERS\0HKEY_CURRENT_CONFIG\0HKEY_DYN_DATA\0HKEY_PERFORMANCE_DATA\0SHELL_CONTEXT\0") }; static HKEY rootkey_tab[] = { HKEY_CLASSES_ROOT,HKEY_LOCAL_MACHINE,HKEY_CURRENT_USER,HKEY_USERS,HKEY_CURRENT_CONFIG,HKEY_DYN_DATA,HKEY_PERFORMANCE_DATA,0 @@ -922,40 +922,40 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) entry ent={0,}; switch (which_token) { - // macro shit + // macro stuff /////////////////////////////////////////////////////////////////////////////// case TOK_P_MACRO: { if (!line.gettoken_str(1)[0]) PRINTHELP() - char *t=(char *)m_macros.get(); + TCHAR *t=(TCHAR *)m_macros.get(); while (t && *t) { if (!stricmp(t,line.gettoken_str(1))) break; - t+=strlen(t)+1; + t+=_tcsclen(t)+1; // advance over parameters - while (*t) t+=strlen(t)+1; + while (*t) t+=_tcsclen(t)+1; t++; // advance over data - while (*t) t+=strlen(t)+1; - if (t-(char *)m_macros.get() >= m_macros.getlen()-1) + while (*t) t+=_tcsclen(t)+1; + if (t-(TCHAR *)m_macros.get() >= m_macros.getlen()-1) break; t++; } if (t && *t) { - ERROR_MSG("!macro: macro named \"%s\" already found!\n",line.gettoken_str(1)); + ERROR_MSG(_T("!macro: macro named \"%s\" already found!\n"),line.gettoken_str(1)); return PS_ERROR; } - m_macros.add(line.gettoken_str(1),strlen(line.gettoken_str(1))+1); + m_macros.add(line.gettoken_str(1),(_tcsclen(line.gettoken_str(1))+1)*sizeof(TCHAR)); int pc; for (pc=2; pc < line.getnumtokens(); pc ++) { if (!line.gettoken_str(pc)[0]) { - ERROR_MSG("!macro: macro parameter %d is empty, not valid!\n",pc-1); + ERROR_MSG(_T("!macro: macro parameter %d is empty, not valid!\n"),pc-1); return PS_ERROR; } int a; @@ -963,83 +963,83 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!stricmp(line.gettoken_str(pc),line.gettoken_str(a))) { - ERROR_MSG("!macro: macro parameter named %s is used multiple times!\n", + ERROR_MSG(_T("!macro: macro parameter named %s is used multiple times!\n"), line.gettoken_str(pc)); return PS_ERROR; } } - m_macros.add(line.gettoken_str(pc),strlen(line.gettoken_str(pc))+1); + m_macros.add(line.gettoken_str(pc),(_tcsclen(line.gettoken_str(pc))+1)*sizeof(TCHAR)); } - m_macros.add("",1); + m_macros.add(_T(""),sizeof(_T(""))); for (;;) { - char str[MAX_LINELENGTH]; - char *p=str; + TCHAR str[MAX_LINELENGTH]; + TCHAR *p=str; str[0]=0; - fgets(str,MAX_LINELENGTH,fp); - //SCRIPT_MSG("%s%s", str, str[strlen(str)-1]=='\n'?"":"\n"); + _fgetts(str,MAX_LINELENGTH,fp); + //SCRIPT_MSG(_T("%s%s"), str, str[_tcsclen(str)-1]==_T('\n')?_T(""):_T("\n")); if (feof(fp) && !str[0]) { - ERROR_MSG("!macro \"%s\": unterminated (no !macroend found in file)!\n",line.gettoken_str(1)); + ERROR_MSG(_T("!macro \"%s\": unterminated (no !macroend found in file)!\n"),line.gettoken_str(1)); return PS_ERROR; } // remove trailing whitespace while (*p) p++; if (p > str) p--; - while (p >= str && (*p == '\r' || *p == '\n' || *p == ' ' || *p == '\t')) p--; + while (p >= str && (*p == _T('\r') || *p == _T('\n') || *p == _T(' ') || *p == _T('\t'))) p--; *++p=0; LineParser l2(false); if (!l2.parse(str)) { - if (!stricmp(l2.gettoken_str(0),"!macroend")) + if (!stricmp(l2.gettoken_str(0),_T("!macroend"))) { linecnt++; break; } - if (!stricmp(l2.gettoken_str(0),"!macro")) + if (!stricmp(l2.gettoken_str(0),_T("!macro"))) { - ERROR_MSG("Error: can't define a macro inside a macro!\n"); + ERROR_MSG(_T("Error: can't define a macro inside a macro!\n")); return PS_ERROR; } } - if (str[0]) m_macros.add(str,strlen(str)+1); - else m_macros.add(" ",2); + if (str[0]) m_macros.add(str,(_tcsclen(str)+1)*sizeof(TCHAR)); + else m_macros.add(_T(" "),sizeof(_T(" "))); linecnt++; } - m_macros.add("",1); + m_macros.add(_T(""),sizeof(_T(""))); } return PS_OK; case TOK_P_MACROEND: - ERROR_MSG("!macroend: no macro currently open.\n"); + ERROR_MSG(_T("!macroend: no macro currently open.\n")); return PS_ERROR; case TOK_P_INSERTMACRO: { if (!line.gettoken_str(1)[0]) PRINTHELP() - char *t=(char *)m_macros.get(); - char *m=t; + TCHAR *t=(TCHAR *)m_macros.get(); + TCHAR *m=t; while (t && *t) { if (!stricmp(t,line.gettoken_str(1))) break; - t+=strlen(t)+1; + t+=_tcsclen(t)+1; // advance over parms - while (*t) t+=strlen(t)+1; + while (*t) t+=_tcsclen(t)+1; t++; // advance over data - while (*t) t+=strlen(t)+1; - if (t-(char *)m_macros.get() >= m_macros.getlen()-1) + while (*t) t+=_tcsclen(t)+1; + if (t-(TCHAR *)m_macros.get() >= m_macros.getlen()-1) break; t++; } - SCRIPT_MSG("!insertmacro: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("!insertmacro: %s\n"),line.gettoken_str(1)); if (!t || !*t) { - ERROR_MSG("!insertmacro: macro named \"%s\" not found!\n",line.gettoken_str(1)); + ERROR_MSG(_T("!insertmacro: macro named \"%s\" not found!\n"),line.gettoken_str(1)); return PS_ERROR; } - t+=strlen(t)+1; + t+=_tcsclen(t)+1; GrowBuf l_define_names; @@ -1048,72 +1048,72 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) // advance over parms while (*t) { - char *v=definedlist.find(t); + TCHAR *v=definedlist.find(t); if (v) { l_define_saves.add(t,v); definedlist.del(t); } - l_define_names.add(t,strlen(t)+1); + l_define_names.add(t,(_tcsclen(t)+1)*sizeof(TCHAR)); definedlist.add(t,line.gettoken_str(npr+2)); npr++; - t+=strlen(t)+1; + t+=_tcsclen(t)+1; } - l_define_names.add("",1); + l_define_names.add(_T(""),sizeof(_T(""))); t++; if (npr != line.getnumtokens()-2) { - ERROR_MSG("!insertmacro: macro \"%s\" requires %d parameter(s), passed %d!\n", + ERROR_MSG(_T("!insertmacro: macro \"%s\" requires %d parameter(s), passed %d!\n"), line.gettoken_str(1),npr,line.getnumtokens()-2); return PS_ERROR; } int lp=0; - char str[1024]; + TCHAR str[1024]; if (m_macro_entry.find(line.gettoken_str(1),0)>=0) { - ERROR_MSG("!insertmacro: macro \"%s\" already being inserted!\n",line.gettoken_str(1)); + ERROR_MSG(_T("!insertmacro: macro \"%s\" already being inserted!\n"),line.gettoken_str(1)); return PS_ERROR; } int npos=m_macro_entry.add(line.gettoken_str(1),0); - wsprintf(str,"macro:%s",line.gettoken_str(1)); + wsprintf(str,_T("macro:%s"),line.gettoken_str(1)); while (*t) { lp++; - if (strcmp(t," ")) + if (_tcscmp(t,_T(" "))) { int ret=process_oneline(t,str,lp); if (ret != PS_OK) { - ERROR_MSG("Error in macro %s on macroline %d\n",line.gettoken_str(1),lp); + ERROR_MSG(_T("Error in macro %s on macroline %d\n"),line.gettoken_str(1),lp); return ret; } } { // fix t if process_oneline changed m_macros - char *nm=(char *)m_macros.get(); + TCHAR *nm=(TCHAR *)m_macros.get(); if (nm != m) { t += nm - m; m = nm; } } - t+=strlen(t)+1; + t+=_tcsclen(t)+1; } m_macro_entry.delbypos(npos); { - char *p=(char*)l_define_names.get(); + TCHAR *p=(TCHAR*)l_define_names.get(); while (*p) { definedlist.del(p); - char *v; + TCHAR *v; if ((v=l_define_saves.find(p))) definedlist.add(p,v); - p+=strlen(p)+1; + p+=_tcsclen(p)+1; } } - SCRIPT_MSG("!insertmacro: end of %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("!insertmacro: end of %s\n"),line.gettoken_str(1)); } return PS_OK; @@ -1122,28 +1122,28 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_P_TEMPFILE: { - char *symbol = line.gettoken_str(1); - char *fpath; + TCHAR *symbol = line.gettoken_str(1); + TCHAR *fpath; #ifdef _WIN32 - char buf[MAX_PATH], buf2[MAX_PATH]; + TCHAR buf[MAX_PATH], buf2[MAX_PATH]; GetTempPath(MAX_PATH, buf); - if (!GetTempFileName(buf, "nst", 0, buf2)) + if (!GetTempFileName(buf, _T("nst"), 0, buf2)) { - ERROR_MSG("!tempfile: unable to create temporary file.\n"); + ERROR_MSG(_T("!tempfile: unable to create temporary file.\n")); return PS_ERROR; } fpath = buf2; #else - char t[] = "/tmp/makensisXXXXXX"; + TCHAR t[] = _T("/tmp/makensisXXXXXX"); mode_t old_umask = umask(0077); int fd = mkstemp(t); if (fd == -1) { - ERROR_MSG("!tempfile: unable to create temporary file.\n"); + ERROR_MSG(_T("!tempfile: unable to create temporary file.\n")); return PS_ERROR; } close(fd); @@ -1155,11 +1155,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (definedlist.add(symbol, fpath)) { - ERROR_MSG("!tempfile: \"%s\" already defined!\n", symbol); + ERROR_MSG(_T("!tempfile: \"%s\" already defined!\n"), symbol); return PS_ERROR; } - SCRIPT_MSG("!tempfile: \"%s\"=\"%s\"\n", symbol, fpath); + SCRIPT_MSG(_T("!tempfile: \"%s\"=\"%s\"\n"), symbol, fpath); } return PS_OK; @@ -1167,10 +1167,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int fatal = 1; int a = 1; - char *fc = line.gettoken_str(a); + TCHAR *fc = line.gettoken_str(a); if (line.getnumtokens()==3) { - if(!stricmp(fc,"/nonfatal")) + if(!stricmp(fc,_T("/nonfatal"))) { fatal = 0; fc = line.gettoken_str(++a); @@ -1178,15 +1178,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else PRINTHELP(); } - SCRIPT_MSG("!delfile: \"%s\"\n", line.gettoken_str(a)); + SCRIPT_MSG(_T("!delfile: \"%s\"\n"), line.gettoken_str(a)); - string dir = get_dir_name(fc); - string spec = get_file_name(fc); - string basedir = dir + PLATFORM_PATH_SEPARATOR_STR; + tstring dir = get_dir_name(fc); + tstring spec = get_file_name(fc); + tstring basedir = dir + PLATFORM_PATH_SEPARATOR_STR; if (dir == spec) { // no path, just file name - dir = "."; - basedir = ""; + dir = _T("."); + basedir = _T(""); } boost::scoped_ptr dr( new_dir_reader() ); @@ -1199,11 +1199,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!dir_reader::matches(*files_itr, spec)) continue; - string file = basedir + *files_itr; + tstring file = basedir + *files_itr; int result = unlink(file.c_str()); if (result == -1) { - ERROR_MSG("!delfile: \"%s\" couldn't be deleted.\n", file.c_str()); + ERROR_MSG(_T("!delfile: \"%s\" couldn't be deleted.\n"), file.c_str()); if (fatal) { return PS_ERROR; @@ -1211,7 +1211,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } else { - SCRIPT_MSG("!delfile: deleted \"%s\"\n", file.c_str()); + SCRIPT_MSG(_T("!delfile: deleted \"%s\"\n"), file.c_str()); } } } @@ -1219,29 +1219,29 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_P_APPENDFILE: { - char *file = line.gettoken_str(1); - char *text = line.gettoken_str(2); + TCHAR *file = line.gettoken_str(1); + TCHAR *text = line.gettoken_str(2); - FILE *fp = FOPEN(file, "a"); + FILE *fp = FOPEN(file, _T("a")); if (!fp) { - ERROR_MSG("!appendfile: \"%s\" couldn't be opened.\n", file); + ERROR_MSG(_T("!appendfile: \"%s\" couldn't be opened.\n"), file); return PS_ERROR; } - if (fputs(text, fp) < 0) + if (_fputts(text, fp) < 0) { - ERROR_MSG("!appendfile: error writing to \"%s\".\n", file); + ERROR_MSG(_T("!appendfile: error writing to \"%s\".\n"), file); return PS_ERROR; } fclose(fp); - SCRIPT_MSG("!appendfile: \"%s\" \"%s\"\n", file, text); + SCRIPT_MSG(_T("!appendfile: \"%s\" \"%s\"\n"), file, text); } return PS_OK; - // page ordering shit + // page ordering stuff /////////////////////////////////////////////////////////////////////////////// #ifdef NSIS_CONFIG_VISIBLE_SUPPORT case TOK_UNINSTPAGE: @@ -1250,16 +1250,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!uninstall_mode) { enable_last_page_cancel = 0; - if (!stricmp(line.gettoken_str(line.getnumtokens()-1),"/ENABLECANCEL")) + if (!stricmp(line.gettoken_str(line.getnumtokens()-1),_T("/ENABLECANCEL"))) enable_last_page_cancel = 1; } else { uenable_last_page_cancel = 0; - if (!stricmp(line.gettoken_str(line.getnumtokens()-1),"/ENABLECANCEL")) + if (!stricmp(line.gettoken_str(line.getnumtokens()-1),_T("/ENABLECANCEL"))) uenable_last_page_cancel = 1; } - int k = line.gettoken_enum(1,"custom\0license\0components\0directory\0instfiles\0uninstConfirm\0"); + int k = line.gettoken_enum(1,_T("custom\0license\0components\0directory\0instfiles\0uninstConfirm\0")); if (k < 0) PRINTHELP(); @@ -1268,7 +1268,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) #ifndef NSIS_SUPPORT_CODECALLBACKS if (!k) { - ERROR_MSG("Error: custom page specified, NSIS_SUPPORT_CODECALLBACKS not defined.\n"); + ERROR_MSG(_T("Error: custom page specified, NSIS_SUPPORT_CODECALLBACKS not defined.\n")); return PS_ERROR; } #endif//!NSIS_SUPPORT_CODECALLBACKS @@ -1307,25 +1307,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) cur_page->prefunc = ns_func.add(line.gettoken_str(2),0); break; case 2: - ERROR_MSG("Error: custom page must have a creator function!\n"); + ERROR_MSG(_T("Error: custom page must have a creator function!\n")); PRINTHELP(); } } #endif//NSIS_SUPPORT_CODECALLBACKS - SCRIPT_MSG("%sPage: %s", uninstall_mode?"Uninst":"", line.gettoken_str(1)); + SCRIPT_MSG(_T("%sPage: %s"), uninstall_mode?_T("Uninst"):_T(""), line.gettoken_str(1)); #ifdef NSIS_SUPPORT_CODECALLBACKS if (cur_page->prefunc>=0) - SCRIPT_MSG(" (%s:%s)", k?"pre":"creator", line.gettoken_str(2)); + SCRIPT_MSG(_T(" (%s:%s)"), k?_T("pre"):_T("creator"), line.gettoken_str(2)); if (cur_page->showfunc>=0 && k) - SCRIPT_MSG(" (show:%s)", line.gettoken_str(3)); + SCRIPT_MSG(_T(" (show:%s)"), line.gettoken_str(3)); if (cur_page->leavefunc>=0) - SCRIPT_MSG(" (leave:%s)", line.gettoken_str(4-!k)); + SCRIPT_MSG(_T(" (leave:%s)"), line.gettoken_str(4-!k)); else if (cur_page->caption && !k) - SCRIPT_MSG(" (caption:%s)", line.gettoken_str(3)); + SCRIPT_MSG(_T(" (caption:%s)"), line.gettoken_str(3)); #endif - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); page_end(); @@ -1341,14 +1341,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) // extended page setting case TOK_PAGEEX: { - int k = line.gettoken_enum(1,"custom\0license\0components\0directory\0instfiles\0uninstConfirm\0"); + int k = line.gettoken_enum(1,_T("custom\0license\0components\0directory\0instfiles\0uninstConfirm\0")); if (k < 0) { - k = line.gettoken_enum(1,"un.custom\0un.license\0un.components\0un.directory\0un.instfiles\0un.uninstConfirm\0"); + k = line.gettoken_enum(1,_T("un.custom\0un.license\0un.components\0un.directory\0un.instfiles\0un.uninstConfirm\0")); if (k < 0) PRINTHELP(); set_uninstall_mode(1); } - SCRIPT_MSG("PageEx: %s\n", line.gettoken_str(1)); + SCRIPT_MSG(_T("PageEx: %s\n"), line.gettoken_str(1)); if (add_page(k) != PS_OK) return PS_ERROR; @@ -1359,11 +1359,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_PAGEEXEND: { - SCRIPT_MSG("PageExEnd\n"); + SCRIPT_MSG(_T("PageExEnd\n")); #ifdef NSIS_SUPPORT_CODECALLBACKS if (cur_page_type == PAGE_CUSTOM && !cur_page->prefunc) { - ERROR_MSG("Error: custom pages must have a creator function.\n"); + ERROR_MSG(_T("Error: custom pages must have a creator function.\n")); return PS_ERROR; } #endif @@ -1381,7 +1381,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_PAGECALLBACKS: #ifdef NSIS_SUPPORT_CODECALLBACKS { - SCRIPT_MSG("PageCallbacks:"); + SCRIPT_MSG(_T("PageCallbacks:")); if (cur_page_type == PAGE_CUSTOM) { @@ -1395,11 +1395,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(2)) { - if (strnicmp(line.gettoken_str(2), "un.", 3)) + if (strnicmp(line.gettoken_str(2), _T("un."), 3)) { if (uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1407,7 +1407,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1418,11 +1418,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(1)) { - if (strnicmp(line.gettoken_str(1), "un.", 3)) + if (strnicmp(line.gettoken_str(1), _T("un."), 3)) { if (uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1430,7 +1430,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1447,11 +1447,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(3)) { - if (strnicmp(line.gettoken_str(3), "un.", 3)) + if (strnicmp(line.gettoken_str(3), _T("un."), 3)) { if (uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1459,7 +1459,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1470,11 +1470,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(2)) { - if (strnicmp(line.gettoken_str(2), "un.", 3)) + if (strnicmp(line.gettoken_str(2), _T("un."), 3)) { if (uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1482,7 +1482,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1493,11 +1493,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(1)) { - if (strnicmp(line.gettoken_str(1), "un.", 3)) + if (strnicmp(line.gettoken_str(1), _T("un."), 3)) { if (uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1505,7 +1505,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!uninstall_mode) { - ERROR_MSG("\nError: function names must start with \"un.\" in an uninstall page.\n"); + ERROR_MSG(_T("\nError: function names must start with \"un.\" in an uninstall page.\n")); return PS_ERROR; } } @@ -1518,17 +1518,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int custom = cur_page_type == PAGE_CUSTOM ? 1 : 0; if (cur_page->prefunc>=0) - SCRIPT_MSG(" %s:%s", !custom?"pre":"creator", line.gettoken_str(1)); + SCRIPT_MSG(_T(" %s:%s"), !custom?_T("pre"):_T("creator"), line.gettoken_str(1)); if (cur_page->showfunc>=0 && !custom) - SCRIPT_MSG(" show:%s", line.gettoken_str(2)); + SCRIPT_MSG(_T(" show:%s"), line.gettoken_str(2)); if (cur_page->leavefunc>=0) - SCRIPT_MSG(" leave:%s", line.gettoken_str(3-custom)); + SCRIPT_MSG(_T(" leave:%s"), line.gettoken_str(3-custom)); - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); } return PS_OK; #else - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_CODECALLBACKS not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_CODECALLBACKS not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//NSIS_SUPPORT_CODECALLBACKS #else @@ -1537,47 +1537,47 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_PAGEEX: case TOK_PAGEEXEND: case TOK_PAGECALLBACKS: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//NSIS_CONFIG_VISIBLE_SUPPORT // header flags /////////////////////////////////////////////////////////////////////////////// case TOK_LANGSTRING: { - char *name = line.gettoken_str(1); + TCHAR *name = line.gettoken_str(1); LANGID lang = line.gettoken_int(2); - char *str = line.gettoken_str(3); + TCHAR *str = line.gettoken_str(3); int ret = SetLangString(name, lang, str); if (ret == PS_WARNING) - warning_fl("LangString \"%s\" set multiple times for %d, wasting space", name, lang); + warning_fl(_T("LangString \"%s\" set multiple times for %d, wasting space"), name, lang); else if (ret == PS_ERROR) { - ERROR_MSG("Error: can't set LangString \"%s\"!\n", name); + ERROR_MSG(_T("Error: can't set LangString \"%s\"!\n"), name); return PS_ERROR; } - SCRIPT_MSG("LangString: \"%s\" %d \"%s\"\n", name, lang, str); + SCRIPT_MSG(_T("LangString: \"%s\" %d \"%s\"\n"), name, lang, str); } return PS_OK; case TOK_LANGSTRINGUP: - SCRIPT_MSG("Error: LangStringUP is obsolete, there are no more unprocessed strings. Use LangString.\n"); + SCRIPT_MSG(_T("Error: LangStringUP is obsolete, there are no more unprocessed strings. Use LangString.\n")); return PS_ERROR; case TOK_LICENSELANGSTRING: { #ifdef NSIS_CONFIG_SILENT_SUPPORT if (build_header.flags&(CH_FLAGS_SILENT|CH_FLAGS_SILENT_LOG)) { - warning_fl("LicenseLangString: SilentInstall enabled, wasting space"); + warning_fl(_T("LicenseLangString: SilentInstall enabled, wasting space")); } #endif - char *name = line.gettoken_str(1); + TCHAR *name = line.gettoken_str(1); LANGID lang = line.gettoken_int(2); - char *file = line.gettoken_str(3); + TCHAR *file = line.gettoken_str(3); FILE *fp; unsigned int datalen; - fp=FOPEN(file,"rb"); + fp=FOPEN(file,_T("rb")); if (!fp) { - ERROR_MSG("LicenseLangString: open failed \"%s\"\n",file); + ERROR_MSG(_T("LicenseLangString: open failed \"%s\"\n"),file); PRINTHELP() } MANAGE_WITH(fp, fclose); @@ -1585,50 +1585,50 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) datalen=ftell(fp); if (!datalen) { - ERROR_MSG("LicenseLangString: empty license file \"%s\"\n",file); + ERROR_MSG(_T("LicenseLangString: empty license file \"%s\"\n"),file); return PS_ERROR; } rewind(fp); - char *data=(char*)malloc(datalen+2); + TCHAR *data=(TCHAR*)malloc(datalen+2*sizeof(TCHAR)); if (!data) { - ERROR_MSG("Internal compiler error #12345: LicenseData malloc(%d) failed.\n", datalen+2); + ERROR_MSG(_T("Internal compiler error #12345: LicenseData malloc(%d) failed.\n"), datalen+2); return PS_ERROR; } MANAGE_WITH(data, free); - char *ldata=data+1; - if (fread(ldata,1,datalen,fp) != datalen) + TCHAR *ldata=data+1; + if (fread((void*)ldata,1,datalen,fp) != datalen) { - ERROR_MSG("LicenseLangString: can't read file.\n"); + ERROR_MSG(_T("LicenseLangString: can't read file.\n")); return PS_ERROR; } - ldata[datalen]=0; - if (!strncmp(ldata,"{\\rtf",sizeof("{\\rtf")-1)) + ldata[datalen/sizeof(TCHAR)]=0; + if (!strncmp((char*)ldata,"{\\rtf",sizeof("{\\rtf")-1)) *data = SF_RTF; else *data = SF_TEXT; int ret = SetLangString(name, lang, data); if (ret == PS_WARNING) - warning_fl("LicenseLangString \"%s\" set multiple times for %d, wasting space", name, lang); + warning_fl(_T("LicenseLangString \"%s\" set multiple times for %d, wasting space"), name, lang); else if (ret == PS_ERROR) { - ERROR_MSG("Error: can't set LicenseLangString \"%s\"!\n", name); + ERROR_MSG(_T("Error: can't set LicenseLangString \"%s\"!\n"), name); return PS_ERROR; } - SCRIPT_MSG("LicenseLangString: \"%s\" %d \"%s\"\n", name, lang, file); + SCRIPT_MSG(_T("LicenseLangString: \"%s\" %d \"%s\"\n"), name, lang, file); } return PS_OK; case TOK_NAME: { if (SetInnerString(NLF_NAME,line.gettoken_str(1)) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); SetInnerString(NLF_NAME_DA,line.gettoken_str(2)); - SCRIPT_MSG("Name: \"%s\"",line.gettoken_str(1)); + SCRIPT_MSG(_T("Name: \"%s\""),line.gettoken_str(1)); if (*line.gettoken_str(2)) - SCRIPT_MSG(" \"%s\"",line.gettoken_str(2)); - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T(" \"%s\""),line.gettoken_str(2)); + SCRIPT_MSG(_T("\n")); } return PS_OK; case TOK_CAPTION: @@ -1636,58 +1636,58 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!cur_page) { if (SetInnerString(NLF_CAPTION,line.gettoken_str(1)) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); } else { cur_page->caption = add_string(line.gettoken_str(1)); } - SCRIPT_MSG("Caption: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Caption: \"%s\"\n"),line.gettoken_str(1)); } return PS_OK; case TOK_ICON: - SCRIPT_MSG("Icon: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Icon: \"%s\"\n"),line.gettoken_str(1)); try { free_loaded_icon(installer_icon); installer_icon = load_icon_file(line.gettoken_str(1)); } catch (exception& err) { - ERROR_MSG("Error while loading icon from \"%s\": %s\n", line.gettoken_str(1), err.what()); + ERROR_MSG(_T("Error while loading icon from \"%s\": %s\n"), line.gettoken_str(1), err.what()); return PS_ERROR; } return PS_OK; #ifdef NSIS_CONFIG_COMPONENTPAGE case TOK_CHECKBITMAP: - SCRIPT_MSG("CheckBitmap: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("CheckBitmap: \"%s\"\n"),line.gettoken_str(1)); try { init_res_editor(); int err = update_bitmap(res_editor, IDB_BITMAP1, line.gettoken_str(1), 96, 16, 8); if (err) { switch (err) { case -1: - ERROR_MSG("Error: can't find bitmap\n"); + ERROR_MSG(_T("Error: can't find bitmap\n")); break; case -2: - ERROR_MSG("Error: invalid bitmap file - corrupted or not a bitmap\n"); + ERROR_MSG(_T("Error: invalid bitmap file - corrupted or not a bitmap\n")); break; case -3: - ERROR_MSG("Error: bitmap isn't 96x16 in size\n"); + ERROR_MSG(_T("Error: bitmap isn't 96x16 in size\n")); break; case -4: - ERROR_MSG("Error: bitmap has more than 8bpp\n"); + ERROR_MSG(_T("Error: bitmap has more than 8bpp\n")); break; } return PS_ERROR; } } catch (exception& err) { - ERROR_MSG("Error while replacing bitmap: %s\n", err.what()); + ERROR_MSG(_T("Error while replacing bitmap: %s\n"), err.what()); return PS_ERROR; } return PS_OK; #else//NSIS_CONFIG_COMPONENTPAGE case TOK_CHECKBITMAP: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_COMPONENTPAGE not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_COMPONENTPAGE not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_CONFIG_COMPONENTPAGE case TOK_DIRTEXT: @@ -1695,7 +1695,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!cur_page) { if (SetInnerString(NLF_DIR_TEXT, line.gettoken_str(1)) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); if (line.getnumtokens() > 2) SetInnerString(NLF_DIR_SUBTEXT, line.gettoken_str(2)); if (line.getnumtokens() > 3) @@ -1705,7 +1705,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } else { if (cur_page_type != PAGE_DIRECTORY) { - ERROR_MSG("Error: DirText can only be used inside PageEx directory.\n"); + ERROR_MSG(_T("Error: DirText can only be used inside PageEx directory.\n")); return PS_ERROR; } cur_page->parms[0] = add_string(line.gettoken_str(1)); @@ -1716,37 +1716,37 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (line.getnumtokens() > 4) cur_page->parms[3] = add_string(line.gettoken_str(4)); } - SCRIPT_MSG("DirText: \"%s\" \"%s\" \"%s\" \"%s\"\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); + SCRIPT_MSG(_T("DirText: \"%s\" \"%s\" \"%s\" \"%s\"\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); } return PS_OK; #else//NSIS_CONFIG_VISIBLE_SUPPORT - ERROR_MSG("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_CONFIG_VISIBLE_SUPPORT case TOK_DIRVAR: { if (cur_page_type != PAGE_DIRECTORY && cur_page_type != PAGE_UNINSTCONFIRM) { - ERROR_MSG("Error: can't use DirVar outside of PageEx directory|uninstConfirm.\n"); + ERROR_MSG(_T("Error: can't use DirVar outside of PageEx directory|uninstConfirm.\n")); return PS_ERROR; } cur_page->parms[4] = GetUserVarIndex(line, 1) + 1; if (cur_page->parms[4] <= 0) PRINTHELP(); - SCRIPT_MSG("DirVar: %s\n", line.gettoken_str(1)); + SCRIPT_MSG(_T("DirVar: %s\n"), line.gettoken_str(1)); } return PS_OK; case TOK_DIRVERIFY: { if (cur_page_type != PAGE_DIRECTORY) { - ERROR_MSG("Error: can't use DirVerify outside of PageEx directory.\n"); + ERROR_MSG(_T("Error: can't use DirVerify outside of PageEx directory.\n")); return PS_ERROR; } cur_page->flags &= ~PF_DIR_NO_BTN_DISABLE; - int k = line.gettoken_enum(1,"auto\0leave\0"); + int k = line.gettoken_enum(1,_T("auto\0leave\0")); if (k == -1) PRINTHELP(); if (k) cur_page->flags |= PF_DIR_NO_BTN_DISABLE; - SCRIPT_MSG("DirVerify: %s\n", line.gettoken_str(1)); + SCRIPT_MSG(_T("DirVerify: %s\n"), line.gettoken_str(1)); } return PS_OK; case TOK_GETINSTDIRERROR: @@ -1759,7 +1759,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!cur_page) { if (SetInnerString(NLF_COMP_TEXT, line.gettoken_str(1)) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); if (line.getnumtokens() > 2) SetInnerString(NLF_COMP_SUBTEXT1, line.gettoken_str(2)); if (line.getnumtokens() > 3) @@ -1767,7 +1767,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } else { if (cur_page_type != PAGE_COMPONENTS) { - ERROR_MSG("Error: ComponentText can only be used inside PageEx components.\n"); + ERROR_MSG(_T("Error: ComponentText can only be used inside PageEx components.\n")); return PS_ERROR; } cur_page->parms[0] = add_string(line.gettoken_str(1)); @@ -1776,38 +1776,38 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) cur_page->parms[3] = cur_page->parms[1]; cur_page->parms[4] = cur_page->parms[2]; } - SCRIPT_MSG("ComponentText: \"%s\" \"%s\" \"%s\"\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); + SCRIPT_MSG(_T("ComponentText: \"%s\" \"%s\" \"%s\"\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); } return PS_OK; case TOK_INSTTYPE: { int x; - if (!stricmp(line.gettoken_str(1),"/NOCUSTOM")) + if (!stricmp(line.gettoken_str(1),_T("/NOCUSTOM"))) { build_header.flags|=CH_FLAGS_NO_CUSTOM; - SCRIPT_MSG("InstType: disabling custom install type\n"); + SCRIPT_MSG(_T("InstType: disabling custom install type\n")); } - else if (!stricmp(line.gettoken_str(1),"/COMPONENTSONLYONCUSTOM")) + else if (!stricmp(line.gettoken_str(1),_T("/COMPONENTSONLYONCUSTOM"))) { build_header.flags|=CH_FLAGS_COMP_ONLY_ON_CUSTOM; - SCRIPT_MSG("InstType: making components viewable only on custom install type\n"); + SCRIPT_MSG(_T("InstType: making components viewable only on custom install type\n")); } - else if (!strnicmp(line.gettoken_str(1),"/CUSTOMSTRING=",14)) + else if (!strnicmp(line.gettoken_str(1),_T("/CUSTOMSTRING="),14)) { - SCRIPT_MSG("InstType: setting custom text to: \"%s\"\n",line.gettoken_str(1)+14); + SCRIPT_MSG(_T("InstType: setting custom text to: \"%s\"\n"),line.gettoken_str(1)+14); if (SetInnerString(NLF_COMP_CUSTOM,line.gettoken_str(1)+14) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space","InstType /CUSTOMSTRING"); + warning_fl(_T("%s: specified multiple times, wasting space"),_T("InstType /CUSTOMSTRING")); } - else if (line.gettoken_str(1)[0]=='/') + else if (line.gettoken_str(1)[0]==_T('/')) { PRINTHELP() } else { - char *itname = line.gettoken_str(1); + TCHAR *itname = line.gettoken_str(1); - if (!strnicmp(itname, "un.", 3)) { + if (!strnicmp(itname, _T("un."), 3)) { set_uninstall_mode(1); itname += 3; } @@ -1815,13 +1815,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) for (x = 0; x < NSIS_MAX_INST_TYPES && cur_header->install_types[x]; x ++); if (x == NSIS_MAX_INST_TYPES) { - ERROR_MSG("InstType: no more than %d install types allowed. %d specified\n", NSIS_MAX_INST_TYPES, NSIS_MAX_INST_TYPES + 1); + ERROR_MSG(_T("InstType: no more than %d install types allowed. %d specified\n"), NSIS_MAX_INST_TYPES, NSIS_MAX_INST_TYPES + 1); return PS_ERROR; } else { cur_header->install_types[x] = add_string(itname); - SCRIPT_MSG("InstType: %s%d=\"%s\"\n", uninstall_mode ? "(uninstall) " : "", x+1, itname); + SCRIPT_MSG(_T("InstType: %s%d=\"%s\"\n"), uninstall_mode ? _T("(uninstall) ") : _T(""), x+1, itname); } set_uninstall_mode(0); @@ -1831,7 +1831,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) #else//NSIS_CONFIG_COMPONENTPAGE case TOK_COMPTEXT: case TOK_INSTTYPE: - ERROR_MSG("Error: %s specified but NSIS_CONFIG_COMPONENTPAGE not defined\n",line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified but NSIS_CONFIG_COMPONENTPAGE not defined\n"),line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_LICENSEPAGE @@ -1839,7 +1839,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!cur_page) { if (SetInnerString(NLF_LICENSE_TEXT, line.gettoken_str(1)) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); SetInnerString(NLF_LICENSE_TEXT_FSRB, line.gettoken_str(1)); SetInnerString(NLF_LICENSE_TEXT_FSCB, line.gettoken_str(1)); if (line.getnumtokens() > 2) @@ -1847,26 +1847,26 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } else { if (cur_page_type != PAGE_LICENSE) { - ERROR_MSG("Error: LicenseText can only be used inside PageEx license.\n"); + ERROR_MSG(_T("Error: LicenseText can only be used inside PageEx license.\n")); return PS_ERROR; } cur_page->parms[0] = add_string(line.gettoken_str(1)); cur_page->next = add_string(line.gettoken_str(2)); } - SCRIPT_MSG("LicenseText: \"%s\" \"%s\"\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("LicenseText: \"%s\" \"%s\"\n"),line.gettoken_str(1),line.gettoken_str(2)); } return PS_OK; case TOK_LICENSEDATA: { int idx = 0; - char *file = line.gettoken_str(1); - char *data = NULL; + TCHAR *file = line.gettoken_str(1); + TCHAR *data = NULL; - if (file[0] == '$' && file[1] == '(') + if (file[0] == _T('$') && file[1] == _T('(')) { - char *cp = strdup(file+2); + TCHAR *cp = strdup(file+2); MANAGE_WITH(cp, free); - char *p = strchr(cp, ')'); + TCHAR *p = _tcschr(cp, _T(')')); if (p && p[1] == 0) { // if string is only a language str identifier *p = 0; idx = DefineLangString(cp, 0); @@ -1877,10 +1877,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!idx) { unsigned int datalen; - FILE *fp=FOPEN(file,"rb"); + FILE *fp=FOPEN(file,_T("rb")); if (!fp) { - ERROR_MSG("LicenseData: open failed \"%s\"\n",file); + ERROR_MSG(_T("LicenseData: open failed \"%s\"\n"),file); PRINTHELP() } MANAGE_WITH(fp, fclose); @@ -1888,25 +1888,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) datalen=ftell(fp); if (!datalen) { - ERROR_MSG("LicenseData: empty license file \"%s\"\n",file); + ERROR_MSG(_T("LicenseData: empty license file \"%s\"\n"),file); return PS_ERROR; } rewind(fp); - data=(char*)malloc(datalen+2); + data=(TCHAR*)malloc(datalen+2*sizeof(TCHAR)); if (!data) { - ERROR_MSG("Internal compiler error #12345: LicenseData malloc(%d) failed.\n", datalen+2); + ERROR_MSG(_T("Internal compiler error #12345: LicenseData malloc(%d) failed.\n"), (datalen+2)*sizeof(TCHAR)); return PS_ERROR; } //MANAGE_WITH(data, free); - char *ldata=data+1; - if (fread(ldata,1,datalen,fp) != datalen) { - ERROR_MSG("LicenseData: can't read file.\n"); + TCHAR* ldata=(TCHAR*)data+1; + if (fread((void*)ldata,1,datalen,fp) != datalen) { + ERROR_MSG(_T("LicenseData: can't read file.\n")); free(data); // TODO: fix later (orip) return PS_ERROR; } - ldata[datalen]=0; - if (!strncmp(ldata,"{\\rtf",sizeof("{\\rtf")-1)) + ldata[datalen/sizeof(TCHAR)]=0; + if (!strncmp((char*)ldata,"{\\rtf",sizeof("{\\rtf")-1)) *data = SF_RTF; else *data = SF_TEXT; @@ -1914,11 +1914,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!cur_page) { if (SetInnerString(NLF_LICENSE_DATA,data) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); } else { if (cur_page_type != PAGE_LICENSE) { - ERROR_MSG("Error: LicenseData can only be used inside PageEx license.\n"); + ERROR_MSG(_T("Error: LicenseData can only be used inside PageEx license.\n")); return PS_ERROR; } @@ -1927,12 +1927,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!idx) free(data); // TODO: fix later (orip) - SCRIPT_MSG("LicenseData: \"%s\"\n",file); + SCRIPT_MSG(_T("LicenseData: \"%s\"\n"),file); } return PS_OK; case TOK_LICENSEFORCESELECTION: { - int k=line.gettoken_enum(1,"off\0checkbox\0radiobuttons\0"); + int k=line.gettoken_enum(1,_T("off\0checkbox\0radiobuttons\0")); if (k == -1) PRINTHELP() if (k < line.getnumtokens() - 2) PRINTHELP() @@ -1959,7 +1959,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } else { if (cur_page_type != PAGE_LICENSE) { - ERROR_MSG("Error: LicenseForceSelection can only be used inside PageEx license.\n"); + ERROR_MSG(_T("Error: LicenseForceSelection can only be used inside PageEx license.\n")); return PS_ERROR; } switch (line.getnumtokens()) { @@ -1988,28 +1988,28 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } } - SCRIPT_MSG("LicenseForceSelection: %s \"%s\" \"%s\"\n", line.gettoken_str(1), line.gettoken_str(2), line.gettoken_str(3)); + SCRIPT_MSG(_T("LicenseForceSelection: %s \"%s\" \"%s\"\n"), line.gettoken_str(1), line.gettoken_str(2), line.gettoken_str(3)); } return PS_OK; case TOK_LICENSEBKCOLOR: { - char *p = line.gettoken_str(1); - if (!strcmpi(p,"/windows")) + TCHAR *p = line.gettoken_str(1); + if (!strcmpi(p,_T("/windows"))) { build_header.license_bg=-COLOR_WINDOW; - SCRIPT_MSG("LicenseBkColor: /windows\n"); + SCRIPT_MSG(_T("LicenseBkColor: /windows\n")); } - else if (!strcmpi(p,"/grey") || !strcmpi(p,"/gray")) + else if (!strcmpi(p,_T("/grey")) || !strcmpi(p,_T("/gray"))) { build_header.license_bg=-COLOR_BTNFACE; - SCRIPT_MSG("LicenseBkColor: /grey\n"); + SCRIPT_MSG(_T("LicenseBkColor: /grey\n")); } else { - int v=strtoul(p,&p,16); + int v=_tcstoul(p,&p,16); build_header.license_bg=((v&0xff)<<16)|(v&0xff00)|((v&0xff0000)>>16); build_uninst.license_bg=build_header.license_bg; - SCRIPT_MSG("LicenseBkColor: %06X\n",v); + SCRIPT_MSG(_T("LicenseBkColor: %06X\n"),v); } } return PS_OK; @@ -2017,26 +2017,26 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_LICENSETEXT: case TOK_LICENSEDATA: case TOK_LICENSEBKCOLOR: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_LICENSEPAGE not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_LICENSEPAGE not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_CONFIG_LICENSEPAGE #ifdef NSIS_CONFIG_SILENT_SUPPORT case TOK_SILENTINST: { - int k=line.gettoken_enum(1,"normal\0silent\0silentlog\0"); + int k=line.gettoken_enum(1,_T("normal\0silent\0silentlog\0")); if (k<0) PRINTHELP() #ifndef NSIS_CONFIG_LOG if (k == 2) { - ERROR_MSG("SilentInstall: silentlog specified, no log support compiled in (use NSIS_CONFIG_LOG)\n"); + ERROR_MSG(_T("SilentInstall: silentlog specified, no log support compiled in (use NSIS_CONFIG_LOG)\n")); return PS_ERROR; } #endif//NSIS_CONFIG_LOG - SCRIPT_MSG("SilentInstall: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SilentInstall: %s\n"),line.gettoken_str(1)); #ifdef NSIS_CONFIG_LICENSEPAGE if (k && HasUserDefined(NLF_LICENSE_DATA)) { - warning_fl("SilentInstall: LicenseData already specified. wasting space"); + warning_fl(_T("SilentInstall: LicenseData already specified. wasting space")); } if (k) { build_header.flags|=CH_FLAGS_SILENT; @@ -2053,17 +2053,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_SILENTUNINST: #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT { - int k=line.gettoken_enum(1,"normal\0silent\0"); + int k=line.gettoken_enum(1,_T("normal\0silent\0")); if (k<0) PRINTHELP() if (k) build_uninst.flags|=CH_FLAGS_SILENT; else build_uninst.flags&=~CH_FLAGS_SILENT; - SCRIPT_MSG("SilentUnInstall: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SilentUnInstall: %s\n"),line.gettoken_str(1)); } return PS_OK; #else - ERROR_MSG("Error: %s specified, NSIS_CONFIG_UNINSTALL_SUPPORT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_UNINSTALL_SUPPORT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif case TOK_IFSILENT: @@ -2072,16 +2072,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) process_jump(line,2,&ent.offsets[1])) PRINTHELP() ent.offsets[2]=FLAG_OFFSET(silent); ent.offsets[3]=~0;//new value mask - keep flag - SCRIPT_MSG("IfSilent ?%s:%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("IfSilent ?%s:%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SETSILENT: { ent.which=EW_SETFLAG; ent.offsets[0]=FLAG_OFFSET(silent); - int k=line.gettoken_enum(1,"normal\0silent\0"); + int k=line.gettoken_enum(1,_T("normal\0silent\0")); if (k<0) PRINTHELP() ent.offsets[1]=add_intstring(k); - SCRIPT_MSG("SetSilent: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetSilent: %s\n"),line.gettoken_str(1)); } return add_entry(&ent); #else//!NSIS_CONFIG_SILENT_SUPPORT @@ -2089,42 +2089,42 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_SILENTUNINST: case TOK_IFSILENT: case TOK_SETSILENT: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_SILENT_SUPPORT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_SILENT_SUPPORT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//NSIS_CONFIG_SILENT_SUPPORT case TOK_OUTFILE: - strncpy(build_output_filename,line.gettoken_str(1),1024-1); - SCRIPT_MSG("OutFile: \"%s\"\n",build_output_filename); + _tcsnccpy(build_output_filename,line.gettoken_str(1),1024-1); + SCRIPT_MSG(_T("OutFile: \"%s\"\n"),build_output_filename); return PS_OK; case TOK_INSTDIR: { - char *p = line.gettoken_str(1); + TCHAR *p = line.gettoken_str(1); if (build_header.install_directory_ptr) { - warning_fl("%s: specified multiple times. wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times. wasting space"),line.gettoken_str(0)); } build_header.install_directory_ptr = add_string(p); build_header.install_directory_auto_append = 0; - char *p2 = p + strlen(p); - if (*p && *CharPrev(p, p2) != '\\') + TCHAR *p2 = p + _tcsclen(p); + if (*p && *CharPrev(p, p2) != _T('\\')) { // we risk hitting $\r or something like $(bla\ad) or ${bla\ad} here, but it's better // than hitting backslashes in processed strings - while (p2 > p && *p2 != '\\') + while (p2 > p && *p2 != _T('\\')) p2 = CharPrev(p, p2); - if (*p2 == '\\') + if (*p2 == _T('\\')) { build_header.install_directory_auto_append = add_string(p2 + 1); } } - SCRIPT_MSG("InstallDir: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("InstallDir: \"%s\"\n"),line.gettoken_str(1)); } return PS_OK; case TOK_INSTALLDIRREGKEY: // InstallDirRegKey { if (build_header.install_reg_key_ptr) { - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); } int k=line.gettoken_enum(1,rootkeys[0]); if (k == -1) k=line.gettoken_enum(1,rootkeys[1]); @@ -2132,16 +2132,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) build_header.install_reg_rootkey=(int)rootkey_tab[k]; if (!build_header.install_reg_rootkey) PRINTHELP() // SHCTX is invalid here build_header.install_reg_key_ptr = add_string(line.gettoken_str(2),0); - if (line.gettoken_str(2)[0] == '\\') - warning_fl("%s: registry path name begins with \'\\\', may cause problems",line.gettoken_str(0)); + if (line.gettoken_str(2)[0] == _T('\\')) + warning_fl(_T("%s: registry path name begins with \'\\\', may cause problems"),line.gettoken_str(0)); build_header.install_reg_value_ptr = add_string(line.gettoken_str(3),0); - SCRIPT_MSG("InstallRegKey: \"%s\\%s\\%s\"\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); + SCRIPT_MSG(_T("InstallRegKey: \"%s\\%s\\%s\"\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); } return PS_OK; case TOK_CRCCHECK: - build_crcchk=line.gettoken_enum(1,"off\0on\0force\0"); + build_crcchk=line.gettoken_enum(1,_T("off\0on\0force\0")); if (build_crcchk==-1) PRINTHELP() - SCRIPT_MSG("CRCCheck: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("CRCCheck: %s\n"),line.gettoken_str(1)); return PS_OK; case TOK_INSTPROGRESSFLAGS: { @@ -2150,8 +2150,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) build_header.flags&=~CH_FLAGS_PROGRESS_COLORED; for (x = 1; x < line.getnumtokens(); x ++) { - if (!stricmp(line.gettoken_str(x),"smooth")) smooth=1; - else if (!stricmp(line.gettoken_str(x),"colored")) build_header.flags|=CH_FLAGS_PROGRESS_COLORED; + if (!stricmp(line.gettoken_str(x),_T("smooth"))) smooth=1; + else if (!stricmp(line.gettoken_str(x),_T("colored"))) build_header.flags|=CH_FLAGS_PROGRESS_COLORED; else PRINTHELP() } try { @@ -2177,42 +2177,42 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) delete [] dlg; } catch (exception& err) { - ERROR_MSG("Error setting smooth progress bar: %s\n", err.what()); + ERROR_MSG(_T("Error setting smooth progress bar: %s\n"), err.what()); return PS_ERROR; } - SCRIPT_MSG("InstProgressFlags: smooth=%d, colored=%d\n",smooth, + SCRIPT_MSG(_T("InstProgressFlags: smooth=%d, colored=%d\n"),smooth, !!(build_header.flags&CH_FLAGS_PROGRESS_COLORED)); } return PS_OK; case TOK_AUTOCLOSE: { - int k=line.gettoken_enum(1,"false\0true\0"); + int k=line.gettoken_enum(1,_T("false\0true\0")); if (k == -1) PRINTHELP(); if (k) build_header.flags|=CH_FLAGS_AUTO_CLOSE; else build_header.flags&=~CH_FLAGS_AUTO_CLOSE; - SCRIPT_MSG("AutoCloseWindow: %s\n",k?"true":"false"); + SCRIPT_MSG(_T("AutoCloseWindow: %s\n"),k?_T("true"):_T("false")); } return PS_OK; case TOK_WINDOWICON: #ifdef NSIS_CONFIG_VISIBLE_SUPPORT - disable_window_icon=line.gettoken_enum(1,"on\0off\0"); + disable_window_icon=line.gettoken_enum(1,_T("on\0off\0")); if (disable_window_icon == -1) PRINTHELP(); - SCRIPT_MSG("WindowIcon: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("WindowIcon: %s\n"),line.gettoken_str(1)); return PS_OK; #else - ERROR_MSG("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n",line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n"),line.gettoken_str(0)); return PS_ERROR; #endif // NSIS_CONFIG_VISIBLE_SUPPORT case TOK_SHOWDETAILSUNINST: #ifndef NSIS_CONFIG_UNINSTALL_SUPPORT - ERROR_MSG("Error: ShowUninstDetails specified but NSIS_CONFIG_UNINSTALL_SUPPORT not defined\n"); + ERROR_MSG(_T("Error: ShowUninstDetails specified but NSIS_CONFIG_UNINSTALL_SUPPORT not defined\n")); return PS_ERROR; #endif case TOK_SHOWDETAILS: { - int k=line.gettoken_enum(1,"hide\0show\0nevershow\0"); + int k=line.gettoken_enum(1,_T("hide\0show\0nevershow\0")); if (k == -1) PRINTHELP() #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT if (which_token == TOK_SHOWDETAILSUNINST) @@ -2232,41 +2232,41 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else if (k==2) build_header.flags|=CH_FLAGS_DETAILS_NEVERSHOW; } - SCRIPT_MSG("%s: %s\n",line.gettoken_str(0),line.gettoken_str(1)); + SCRIPT_MSG(_T("%s: %s\n"),line.gettoken_str(0),line.gettoken_str(1)); } return PS_OK; case TOK_DIRSHOW: /*{ - int k=line.gettoken_enum(1,"show\0hide\0"); + int k=line.gettoken_enum(1,_T("show\0hide\0")); if (k == -1) PRINTHELP(); if (k) build_header.flags|=CH_FLAGS_DIR_NO_SHOW; else build_header.flags&=~CH_FLAGS_DIR_NO_SHOW; - SCRIPT_MSG("DirShow: %s\n",k?"hide":"show"); + SCRIPT_MSG(_T("DirShow: %s\n"),k?_T("hide"):_T("show")); }*/ - ERROR_MSG("Error: DirShow doesn't currently work\n"); + ERROR_MSG(_T("Error: DirShow doesn't currently work\n")); return PS_ERROR; case TOK_ROOTDIRINST: { - int k=line.gettoken_enum(1,"true\0false\0"); + int k=line.gettoken_enum(1,_T("true\0false\0")); if (k == -1) PRINTHELP(); if (k) build_header.flags|=CH_FLAGS_NO_ROOT_DIR; else build_header.flags&=~CH_FLAGS_NO_ROOT_DIR; - SCRIPT_MSG("AllowRootDirInstall: %s\n",k?"false":"true"); + SCRIPT_MSG(_T("AllowRootDirInstall: %s\n"),k?_T("false"):_T("true")); } return PS_OK; case TOK_BGFONT: #ifndef NSIS_SUPPORT_BGBG - ERROR_MSG("Error: BGFont specified but NSIS_SUPPORT_BGBG not defined\n"); + ERROR_MSG(_T("Error: BGFont specified but NSIS_SUPPORT_BGBG not defined\n")); return PS_ERROR; #else//NSIS_SUPPORT_BGBG if (line.getnumtokens()==1) { memcpy(&bg_font,&bg_default_font,sizeof(LOGFONT)); - SCRIPT_MSG("BGFont: default font\n"); + SCRIPT_MSG(_T("BGFont: default font\n")); return PS_OK; } @@ -2285,93 +2285,93 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) newfont.lfQuality=DEFAULT_QUALITY; newfont.lfPitchAndFamily=DEFAULT_PITCH; - strncpy(newfont.lfFaceName,line.gettoken_str(1),LF_FACESIZE); + _tcsnccpy(newfont.lfFaceName,line.gettoken_str(1),LF_FACESIZE); - SCRIPT_MSG("BGFont: \"%s\"",line.gettoken_str(1)); + SCRIPT_MSG(_T("BGFont: \"%s\""),line.gettoken_str(1)); { bool height=false; bool weight=false; for (int i = 2; i < line.getnumtokens(); i++) { - char *tok=line.gettoken_str(i); - if (tok[0]=='/') { - if (!strcmpi(tok,"/ITALIC")) { - SCRIPT_MSG(" /ITALIC"); + TCHAR *tok=line.gettoken_str(i); + if (tok[0]==_T('/')) { + if (!strcmpi(tok,_T("/ITALIC"))) { + SCRIPT_MSG(_T(" /ITALIC")); newfont.lfItalic=TRUE; } - else if (!strcmpi(tok,"/UNDERLINE")) { - SCRIPT_MSG(" /UNDERLINE"); + else if (!strcmpi(tok,_T("/UNDERLINE"))) { + SCRIPT_MSG(_T(" /UNDERLINE")); newfont.lfUnderline=TRUE; } - else if (!strcmpi(tok,"/STRIKE")) { - SCRIPT_MSG(" /STRIKE"); + else if (!strcmpi(tok,_T("/STRIKE"))) { + SCRIPT_MSG(_T(" /STRIKE")); newfont.lfStrikeOut=TRUE; } else { - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); PRINTHELP(); } } else { if (!height) { - SCRIPT_MSG(" height=%s",tok); + SCRIPT_MSG(_T(" height=%s"),tok); newfont.lfHeight=line.gettoken_int(i); height=true; } else if (!weight) { - SCRIPT_MSG(" weight=%s",tok); + SCRIPT_MSG(_T(" weight=%s"),tok); newfont.lfWeight=line.gettoken_int(i); weight=true; } else { - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); PRINTHELP(); } } } } - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); memcpy(&bg_font, &newfont, sizeof(LOGFONT)); return PS_OK; #endif//NSIS_SUPPORT_BGBG case TOK_BGGRADIENT: #ifndef NSIS_SUPPORT_BGBG - ERROR_MSG("Error: BGGradient specified but NSIS_SUPPORT_BGBG not defined\n"); + ERROR_MSG(_T("Error: BGGradient specified but NSIS_SUPPORT_BGBG not defined\n")); return PS_ERROR; #else//NSIS_SUPPORT_BGBG if (line.getnumtokens()==1) { - SCRIPT_MSG("BGGradient: default colors\n"); + SCRIPT_MSG(_T("BGGradient: default colors\n")); build_header.bg_color1=0; build_header.bg_color2=RGB(0,0,255); } - else if (!stricmp(line.gettoken_str(1),"off")) + else if (!stricmp(line.gettoken_str(1),_T("off"))) { build_header.bg_color1=build_header.bg_color2=build_header.bg_textcolor=-1; - SCRIPT_MSG("BGGradient: off\n"); + SCRIPT_MSG(_T("BGGradient: off\n")); if (line.getnumtokens()>2) PRINTHELP() } else { - char *p = line.gettoken_str(1); + TCHAR *p = line.gettoken_str(1); int v1,v2,v3=-1; - v1=strtoul(p,&p,16); + v1=_tcstoul(p,&p,16); build_header.bg_color1=((v1&0xff)<<16)|(v1&0xff00)|((v1&0xff0000)>>16); p=line.gettoken_str(2); - v2=strtoul(p,&p,16); + v2=_tcstoul(p,&p,16); build_header.bg_color2=((v2&0xff)<<16)|(v2&0xff00)|((v2&0xff0000)>>16); p=line.gettoken_str(3); if (*p) { - if (!stricmp(p,"notext")) build_header.bg_textcolor=-1; + if (!stricmp(p,_T("notext"))) build_header.bg_textcolor=-1; else { - v3=strtoul(p,&p,16); + v3=_tcstoul(p,&p,16); build_header.bg_textcolor=((v3&0xff)<<16)|(v3&0xff00)|((v3&0xff0000)>>16); } } - SCRIPT_MSG("BGGradient: 0x%06X->0x%06X (text=0x%06X)\n",v1,v2,v3); + SCRIPT_MSG(_T("BGGradient: 0x%06X->0x%06X (text=0x%06X)\n"),v1,v2,v3); } #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT @@ -2384,23 +2384,23 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) #ifdef NSIS_CONFIG_VISIBLE_SUPPORT case TOK_INSTCOLORS: { - char *p = line.gettoken_str(1); - if (p[0]=='/') + TCHAR *p = line.gettoken_str(1); + if (p[0]==_T('/')) { - if (stricmp(p,"/windows") || line.getnumtokens()!=2) PRINTHELP() + if (stricmp(p,_T("/windows")) || line.getnumtokens()!=2) PRINTHELP() build_header.lb_fg=build_header.lb_bg=-1; - SCRIPT_MSG("InstallColors: windows default colors\n"); + SCRIPT_MSG(_T("InstallColors: windows default colors\n")); } else { int v1,v2; if (line.getnumtokens()!=3) PRINTHELP() - v1=strtoul(p,&p,16); + v1=_tcstoul(p,&p,16); build_header.lb_fg=((v1&0xff)<<16)|(v1&0xff00)|((v1&0xff0000)>>16); p=line.gettoken_str(2); - v2=strtoul(p,&p,16); + v2=_tcstoul(p,&p,16); build_header.lb_bg=((v2&0xff)<<16)|(v2&0xff00)|((v2&0xff0000)>>16); - SCRIPT_MSG("InstallColors: fg=%06X bg=%06X\n",v1,v2); + SCRIPT_MSG(_T("InstallColors: fg=%06X bg=%06X\n"),v1,v2); } #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT @@ -2411,9 +2411,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; case TOK_XPSTYLE: { - int k=line.gettoken_enum(1,"on\0off\0"); + int k=line.gettoken_enum(1,_T("on\0off\0")); if (k == -1) PRINTHELP() - SCRIPT_MSG("XPStyle: %s\n", line.gettoken_str(1)); + SCRIPT_MSG(_T("XPStyle: %s\n"), line.gettoken_str(1)); if (!k) manifest_comctl = manifest::comctl_xp; else @@ -2423,12 +2423,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_CHANGEUI: try { DWORD dwSize; - 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, _T("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(); - FILE *fui = FOPEN(line.gettoken_str(2), "rb"); + FILE *fui = FOPEN(line.gettoken_str(2), _T("rb")); if (!fui) { - ERROR_MSG("Error: Can't open \"%s\"!\n", line.gettoken_str(2)); + ERROR_MSG(_T("Error: Can't open \"%s\"!\n"), line.gettoken_str(2)); return PS_ERROR; } MANAGE_WITH(fui, fclose); @@ -2438,12 +2438,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) fseek(fui, 0, SEEK_SET); LPBYTE ui = (LPBYTE) malloc(len); if (!ui) { - ERROR_MSG("Internal compiler error #12345: malloc(%d) failed\n", len); + ERROR_MSG(_T("Internal compiler error #12345: malloc(%d) failed\n"), len); extern void quit(); quit(); } MANAGE_WITH(ui, free); if (fread(ui, 1, len, fui) != len) { - ERROR_MSG("Error: Can't read \"%s\"!\n", line.gettoken_str(2)); + ERROR_MSG(_T("Error: Can't read \"%s\"!\n"), line.gettoken_str(2)); return PS_ERROR; } @@ -2500,8 +2500,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) check = true; } } else { - char *szClass = winchar_toansi(dlgItem->szClass); - check = stricmp(szClass, "Static") == 0; + TCHAR *szClass = winchar_toansi(dlgItem->szClass); + check = stricmp(szClass, _T("Static")) == 0; delete [] szClass; } @@ -2554,17 +2554,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) delete uire; - SCRIPT_MSG("ChangeUI: %s %s%s\n", line.gettoken_str(1), line.gettoken_str(2), branding_image_found?" (branding image holder found)":""); + SCRIPT_MSG(_T("ChangeUI: %s %s%s\n"), line.gettoken_str(1), line.gettoken_str(2), branding_image_found?_T(" (branding image holder found)"):_T("")); } catch (exception& err) { - ERROR_MSG("Error while changing UI: %s\n", err.what()); + ERROR_MSG(_T("Error while changing UI: %s\n"), err.what()); return PS_ERROR; } return PS_OK; case TOK_ADDBRANDINGIMAGE: #ifdef _WIN32 try { - int k=line.gettoken_enum(1,"top\0left\0bottom\0right\0"); + int k=line.gettoken_enum(1,_T("top\0left\0bottom\0right\0")); int wh=line.gettoken_int(2); if (k == -1) PRINTHELP(); int padding = 2; @@ -2625,38 +2625,38 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) delete [] dlg; dt.DlgUnitsToPixels(brandingCtl.sWidth, brandingCtl.sHeight); - SCRIPT_MSG("AddBrandingImage: %s %ux%u\n", line.gettoken_str(1), brandingCtl.sWidth, brandingCtl.sHeight); + SCRIPT_MSG(_T("AddBrandingImage: %s %ux%u\n"), line.gettoken_str(1), brandingCtl.sWidth, brandingCtl.sHeight); branding_image_found = true; branding_image_id = IDC_BRANDIMAGE; } catch (exception& err) { - ERROR_MSG("Error while adding image branding support: %s\n", err.what()); + ERROR_MSG(_T("Error while adding image branding support: %s\n"), err.what()); return PS_ERROR; } return PS_OK; #else - ERROR_MSG("Error: AddBrandingImage is disabled for non Win32 platforms.\n"); + ERROR_MSG(_T("Error: AddBrandingImage is disabled for non Win32 platforms.\n")); return PS_ERROR; #endif case TOK_SETFONT: { - if (!strnicmp(line.gettoken_str(1), "/LANG=", 6)) + if (!strnicmp(line.gettoken_str(1), _T("/LANG="), 6)) { - LANGID lang_id = atoi(line.gettoken_str(1) + 6); + LANGID lang_id = _ttoi(line.gettoken_str(1) + 6); LanguageTable *table = GetLangTable(lang_id); - table->nlf.m_szFont = (char*)malloc(strlen(line.gettoken_str(2))+1); - strcpy(table->nlf.m_szFont, line.gettoken_str(2)); + table->nlf.m_szFont = (TCHAR*)malloc((_tcsclen(line.gettoken_str(2))+1)*sizeof(TCHAR)); + _tcscpy(table->nlf.m_szFont, line.gettoken_str(2)); table->nlf.m_iFontSize = line.gettoken_int(3); - SCRIPT_MSG("SetFont: lang=%d \"%s\" %s\n", lang_id, line.gettoken_str(2), line.gettoken_str(3)); + SCRIPT_MSG(_T("SetFont: lang=%d \"%s\" %s\n"), lang_id, line.gettoken_str(2), line.gettoken_str(3)); } else { - strncpy(build_font, line.gettoken_str(1), sizeof(build_font)); + _tcsnccpy(build_font, line.gettoken_str(1), sizeof(build_font)/sizeof(TCHAR)); build_font_size = line.gettoken_int(2); - SCRIPT_MSG("SetFont: \"%s\" %s\n", line.gettoken_str(1), line.gettoken_str(2)); + SCRIPT_MSG(_T("SetFont: \"%s\" %s\n"), line.gettoken_str(1), line.gettoken_str(2)); } } return PS_OK; @@ -2666,13 +2666,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_CHANGEUI: case TOK_ADDBRANDINGIMAGE: case TOK_SETFONT: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n",line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n"),line.gettoken_str(0)); return PS_ERROR; #endif// NSIS_CONFIG_VISIBLE_SUPPORT case TOK_REQEXECLEVEL: { - int k=line.gettoken_enum(1,"none\0user\0highest\0admin\0"); + int k=line.gettoken_enum(1,_T("none\0user\0highest\0admin\0")); switch (k) { case 0: @@ -2698,13 +2698,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT { if (build_compressor_set) { - ERROR_MSG("Error: can't change compressor after data already got compressed or header already changed!\n"); + ERROR_MSG(_T("Error: can't change compressor after data already got compressed or header already changed!\n")); return PS_ERROR; } if (build_compressor_final) { - warning_fl("SetCompressor ignored due to previous call with the /FINAL switch"); + warning_fl(_T("SetCompressor ignored due to previous call with the /FINAL switch")); return PS_OK; } @@ -2712,14 +2712,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) build_compress_whole = false; - while (line.gettoken_str(a)[0] == '/') + while (line.gettoken_str(a)[0] == _T('/')) { - if (!strcmpi(line.gettoken_str(a),"/FINAL")) + if (!strcmpi(line.gettoken_str(a),_T("/FINAL"))) { build_compressor_final = true; a++; } - else if (!strcmpi(line.gettoken_str(a),"/SOLID")) + else if (!strcmpi(line.gettoken_str(a),_T("/SOLID"))) { build_compress_whole = true; a++; @@ -2729,11 +2729,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (a != line.getnumtokens() - 1) { - ERROR_MSG("%s expects %d parameters, got %d.\n", line.gettoken_str(0), a + 1, line.getnumtokens()); + ERROR_MSG(_T("%s expects %d parameters, got %d.\n"), line.gettoken_str(0), a + 1, line.getnumtokens()); PRINTHELP(); } - int k=line.gettoken_enum(a, "zlib\0bzip2\0lzma\0"); + int k=line.gettoken_enum(a, _T("zlib\0bzip2\0lzma\0")); switch (k) { case 0: compressor = &zlib_compressor; @@ -2751,25 +2751,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) PRINTHELP(); } - string compressor_name = line.gettoken_str(a); + tstring compressor_name = line.gettoken_str(a); compressor_name = lowercase(compressor_name); if (set_compressor(compressor_name, build_compress_whole) != PS_OK) { - SCRIPT_MSG("SetCompressor: error loading stub for \"%s\" compressor.\n", compressor_name.c_str()); + SCRIPT_MSG(_T("SetCompressor: error loading stub for \"%s\" compressor.\n"), compressor_name.c_str()); return PS_ERROR; } - SCRIPT_MSG("SetCompressor: %s%s%s\n", build_compressor_final ? "/FINAL " : "", build_compress_whole ? "/SOLID " : "", line.gettoken_str(a)); + SCRIPT_MSG(_T("SetCompressor: %s%s%s\n"), build_compressor_final ? _T("/FINAL ") : _T(""), build_compress_whole ? _T("/SOLID ") : _T(""), line.gettoken_str(a)); } return PS_OK; #else//NSIS_CONFIG_COMPRESSION_SUPPORT - ERROR_MSG("Error: %s specified, NSIS_CONFIG_COMPRESSION_SUPPORT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_COMPRESSION_SUPPORT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//NSIS_CONFIG_COMPRESSION_SUPPORT case TOK_LOADNLF: { - SCRIPT_MSG("LoadLanguageFile: %s\n", line.gettoken_str(1)); + SCRIPT_MSG(_T("LoadLanguageFile: %s\n"), line.gettoken_str(1)); LanguageTable *table = LoadLangFile(line.gettoken_str(1)); @@ -2785,14 +2785,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) last_used_lang = table->lang_id; // define LANG_LangName as "####" (lang id) // for example ${LANG_ENGLISH} = 1033 - char lang_id[16]; - char lang_cp[16]; - char lang_name[1024]; - wsprintf(lang_name, "LANG_%s", table->nlf.m_szName); - wsprintf(lang_id, "%u", table->lang_id); - wsprintf(lang_cp, "%u", table->nlf.m_uCodePage); + TCHAR lang_id[16]; + TCHAR lang_cp[16]; + TCHAR lang_name[1024]; + wsprintf(lang_name, _T("LANG_%s"), table->nlf.m_szName); + wsprintf(lang_id, _T("%u"), table->lang_id); + wsprintf(lang_cp, _T("%u"), table->nlf.m_uCodePage); definedlist.add(lang_name, lang_id); - wsprintf(lang_name, "LANG_%s_CP", table->nlf.m_szName); + wsprintf(lang_name, _T("LANG_%s_CP"), table->nlf.m_szName); definedlist.add(lang_name, lang_cp); } return PS_OK; @@ -2801,16 +2801,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) /////////////////////////////////////////////////////////////////////////////// case TOK_P_DEFINE: { - char *define=line.gettoken_str(1); - char *value; + TCHAR *define=line.gettoken_str(1); + TCHAR *value; GrowBuf file_buf; - char datebuf[256]; - char mathbuf[256]; + TCHAR datebuf[256]; + TCHAR mathbuf[256]; - if (!stricmp(define,"/date") || !stricmp(define,"/utcdate")) { + if (!stricmp(define,_T("/date")) || !stricmp(define,_T("/utcdate"))) { if (line.getnumtokens()!=4) PRINTHELP() - char *date_type = define; + TCHAR *date_type = define; define=line.gettoken_str(2); value=line.gettoken_str(3); @@ -2818,7 +2818,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) time_t rawtime; time(&rawtime); - if (!stricmp(date_type,"/utcdate")) + if (!stricmp(date_type,_T("/utcdate"))) rawtime = mktime(gmtime(&rawtime)); datebuf[0]=0; @@ -2830,23 +2830,23 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) datebuf[max(s,sizeof(datebuf)-1)]=0; value=datebuf; - } else if (!stricmp(define,"/file") || !stricmp(define,"/file_noerr")) { + } else if (!stricmp(define,_T("/file")) || !stricmp(define,_T("/file_noerr"))) { if (line.getnumtokens()!=4) PRINTHELP() define=line.gettoken_str(2); - const char *filename=line.gettoken_str(3); - FILE *fp=fopen(filename,"r"); + const TCHAR *filename=line.gettoken_str(3); + FILE *fp=fopen(filename,_T("r")); - if (!fp && stricmp(define,"/file_noerr")) { - ERROR_MSG("!define /file: file not found (\"%s\")\n",filename); + if (!fp && stricmp(define,_T("/file_noerr"))) { + ERROR_MSG(_T("!define /file: file not found (\"%s\")\n"),filename); return PS_ERROR; } if (fp) { - char str[MAX_LINELENGTH]; + TCHAR str[MAX_LINELENGTH]; for (;;) { - char *p=str; + TCHAR *p=str; *p=0; fgets(str,MAX_LINELENGTH,fp); linecnt++; @@ -2854,21 +2854,21 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) while (*p) p++; if (p > str) p--; - while (p >= str && (*p == '\r' || *p == '\n')) p--; + while (p >= str && (*p == _T('\r') || *p == _T('\n'))) p--; *++p=0; - if (file_buf.getlen()) file_buf.add("\n",1); + if (file_buf.getlen()) file_buf.add(_T("\n"),1); file_buf.add(str,strlen(str)); } fclose(fp); } - file_buf.add("\0",1); - value = (char *)file_buf.get(); + file_buf.add(_T("\0"),1); + value = (TCHAR *)file_buf.get(); - } else if (!stricmp(define,"/math")) { + } else if (!stricmp(define,_T("/math"))) { int value1; int value2; - char *mathop; + TCHAR *mathop; if (line.getnumtokens()!=6) PRINTHELP() @@ -2878,30 +2878,30 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) value2 = line.gettoken_int(5); value = mathbuf; - if (!strcmp(mathop,"+")) { - sprintf(value,"%d",value1+value2); - } else if (!strcmp(mathop,"-")) { - sprintf(value,"%d",value1-value2); - } else if (!strcmp(mathop,"*")) { - sprintf(value,"%d",value1*value2); - } else if (!strcmp(mathop,"&")) { - sprintf(value,"%d",value1&value2); - } else if (!strcmp(mathop,"|")) { - sprintf(value,"%d",value1|value2); - } else if (!strcmp(mathop,"^")) { - sprintf(value,"%d",value1^value2); - } else if (!strcmp(mathop,"/")) { + if (!_tcscmp(mathop,_T("+"))) { + _stprintf(value,_T("%d"),value1+value2); + } else if (!_tcscmp(mathop,_T("-"))) { + _stprintf(value,_T("%d"),value1-value2); + } else if (!_tcscmp(mathop,_T("*"))) { + _stprintf(value,_T("%d"),value1*value2); + } else if (!_tcscmp(mathop,_T("&"))) { + _stprintf(value,_T("%d"),value1&value2); + } else if (!_tcscmp(mathop,_T("|"))) { + _stprintf(value,_T("%d"),value1|value2); + } else if (!_tcscmp(mathop,_T("^"))) { + _stprintf(value,_T("%d"),value1^value2); + } else if (!_tcscmp(mathop,_T("/"))) { if (value2==0) { - ERROR_MSG("!define /math: division by zero! (\"%i / %i\")\n",value1,value2); + ERROR_MSG(_T("!define /math: division by zero! (\"%i / %i\")\n"),value1,value2); return PS_ERROR; } - sprintf(value,"%d",value1/value2); - } else if (!strcmp(mathop,"%")) { + _stprintf(value,_T("%d"),value1/value2); + } else if (!_tcscmp(mathop,_T("%"))) { if (value2==0) { - ERROR_MSG("!define /math: division by zero! (\"%i %% %i\")\n",value1,value2); + ERROR_MSG(_T("!define /math: division by zero! (\"%i %% %i\")\n"),value1,value2); return PS_ERROR; } - sprintf(value,"%d",value1%value2); + _stprintf(value,_T("%d"),value1%value2); } else PRINTHELP() } else { @@ -2912,37 +2912,37 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (definedlist.add(define,value)) { - ERROR_MSG("!define: \"%s\" already defined!\n",define); + ERROR_MSG(_T("!define: \"%s\" already defined!\n"),define); return PS_ERROR; } - SCRIPT_MSG("!define: \"%s\"=\"%s\"\n",define,value); + SCRIPT_MSG(_T("!define: \"%s\"=\"%s\"\n"),define,value); } return PS_OK; case TOK_P_UNDEF: if (definedlist.del(line.gettoken_str(1))) { - ERROR_MSG("!undef: \"%s\" not defined!\n",line.gettoken_str(1)); + ERROR_MSG(_T("!undef: \"%s\" not defined!\n"),line.gettoken_str(1)); return PS_ERROR; } - SCRIPT_MSG("!undef: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("!undef: \"%s\"\n"),line.gettoken_str(1)); return PS_OK; case TOK_P_PACKEXEHEADER: - strncpy(build_packname,line.gettoken_str(1),sizeof(build_packname)-1); - strncpy(build_packcmd,line.gettoken_str(2),sizeof(build_packcmd)-1); - SCRIPT_MSG("!packhdr: filename=\"%s\", command=\"%s\"\n", + _tcsnccpy(build_packname,line.gettoken_str(1),sizeof(build_packname)/sizeof(TCHAR)-1); + _tcsnccpy(build_packcmd,line.gettoken_str(2),sizeof(build_packcmd)/sizeof(TCHAR)-1); + SCRIPT_MSG(_T("!packhdr: filename=\"%s\", command=\"%s\"\n"), build_packname, build_packcmd); return PS_OK; case TOK_P_SYSTEMEXEC: { - char *exec=line.gettoken_str(1); - int comp=line.gettoken_enum(2,"<\0>\0<>\0=\0ignore\0"); + TCHAR *exec=line.gettoken_str(1); + int comp=line.gettoken_enum(2,_T("<\0>\0<>\0=\0ignore\0")); if (line.getnumtokens() == 2) comp = 4; if (comp == -1 && line.getnumtokens() == 3) comp=4; if (comp == -1) PRINTHELP() int success=0; int cmpv=line.gettoken_int(3,&success); if (!success && comp != 4) PRINTHELP() - SCRIPT_MSG("!system: \"%s\"\n",exec); + SCRIPT_MSG(_T("!system: \"%s\"\n"),exec); #ifdef _WIN32 int ret=sane_system(exec); #else @@ -2956,15 +2956,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else if (comp == 4); else { - ERROR_MSG("!system: returned %d, aborting\n",ret); + ERROR_MSG(_T("!system: returned %d, aborting\n"),ret); return PS_ERROR; } - SCRIPT_MSG("!system: returned %d\n",ret); + SCRIPT_MSG(_T("!system: returned %d\n"),ret); } return PS_OK; case TOK_P_EXECUTE: { - char *exec=line.gettoken_str(1); + TCHAR *exec=line.gettoken_str(1); #ifdef _WIN32 PROCESS_INFORMATION pi; STARTUPINFO si={sizeof(STARTUPINFO),}; @@ -2975,15 +2975,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) CloseHandle(pi.hProcess); } #else - char *execfixed = my_convert(exec); + TCHAR *execfixed = my_convert(exec); system(execfixed); my_convert_free(execfixed); #endif - SCRIPT_MSG("!execute: \"%s\"\n",exec); + SCRIPT_MSG(_T("!execute: \"%s\"\n"),exec); } case TOK_P_ADDINCLUDEDIR: { - char *f = line.gettoken_str(1); + TCHAR *f = line.gettoken_str(1); PATH_CONVERT(f); include_dirs.add(f,0); } @@ -2992,9 +2992,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { bool required = true; - char *f = line.gettoken_str(1); + TCHAR *f = line.gettoken_str(1); - if(!stricmp(f,"/nonfatal")) { + if(!stricmp(f,_T("/nonfatal"))) { if (line.getnumtokens()!=3) PRINTHELP(); @@ -3004,16 +3004,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) PRINTHELP(); } - char *fc = my_convert(f); + TCHAR *fc = my_convert(f); int included = 0; - string dir = get_dir_name(fc); - string spec = get_file_name(fc); - string basedir = dir + PLATFORM_PATH_SEPARATOR_STR; + tstring dir = get_dir_name(fc); + tstring spec = get_file_name(fc); + tstring basedir = dir + PLATFORM_PATH_SEPARATOR_STR; if (dir == spec) { // no path, just file name - dir = "."; - basedir = ""; + dir = _T("."); + basedir = _T(""); } my_convert_free(fc); @@ -3029,9 +3029,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!dir_reader::matches(*files_itr, spec)) continue; - string incfile = basedir + *files_itr; + tstring incfile = basedir + *files_itr; - if (includeScript((char *) incfile.c_str()) != PS_OK) { + if (includeScript((TCHAR *) incfile.c_str()) != PS_OK) { return PS_ERROR; } @@ -3042,11 +3042,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; // search include dirs - char *incdir = include_dirs.get(); + TCHAR *incdir = include_dirs.get(); int incdirs = include_dirs.getnum(); - for (int i = 0; i < incdirs; i++, incdir += strlen(incdir) + 1) { - string curincdir = string(incdir) + PLATFORM_PATH_SEPARATOR_STR + dir; + for (int i = 0; i < incdirs; i++, incdir += _tcsclen(incdir) + 1) { + tstring curincdir = tstring(incdir) + PLATFORM_PATH_SEPARATOR_STR + dir; boost::scoped_ptr dr( new_dir_reader() ); dr->read(curincdir); @@ -3058,9 +3058,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!dir_reader::matches(*incdir_itr, spec)) continue; - string incfile = string(incdir) + PLATFORM_PATH_SEPARATOR_STR + basedir + *incdir_itr; + tstring incfile = tstring(incdir) + PLATFORM_PATH_SEPARATOR_STR + basedir + *incdir_itr; - if (includeScript((char *) incfile.c_str()) != PS_OK) { + if (includeScript((TCHAR *) incfile.c_str()) != PS_OK) { return PS_ERROR; } @@ -3076,10 +3076,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!included) { if(required) { - ERROR_MSG("!include: could not find: \"%s\"\n",f); + ERROR_MSG(_T("!include: could not find: \"%s\"\n"),f); return PS_ERROR; } else { - warning_fl("!include: could not find: \"%s\"",f); + warning_fl(_T("!include: could not find: \"%s\""),f); } } } @@ -3087,18 +3087,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_P_CD: if (!line.gettoken_str(1)[0] || chdir(line.gettoken_str(1))) { - ERROR_MSG("!cd: error changing to: \"%s\"\n",line.gettoken_str(1)); + ERROR_MSG(_T("!cd: error changing to: \"%s\"\n"),line.gettoken_str(1)); return PS_ERROR; } return PS_OK; case TOK_P_ERROR: - ERROR_MSG("!error: %s\n",line.gettoken_str(1)); + ERROR_MSG(_T("!error: %s\n"),line.gettoken_str(1)); return PS_ERROR; case TOK_P_WARNING: - warning_fl("!warning: %s",line.gettoken_str(1)); + warning_fl(_T("!warning: %s"),line.gettoken_str(1)); return PS_OK; case TOK_P_ECHO: - SCRIPT_MSG("%s (%s:%d)\n", line.gettoken_str(1),curfilename,linecnt); + SCRIPT_MSG(_T("%s (%s:%d)\n"), line.gettoken_str(1),curfilename,linecnt); return PS_OK; case TOK_P_SEARCHPARSESTRING: { @@ -3108,33 +3108,33 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int parmOffs=1; while (parmOffs < line.getnumtokens()) { - if (!stricmp(line.gettoken_str(parmOffs),"/ignorecase")) { ignCase=true; parmOffs++; } - else if (!stricmp(line.gettoken_str(parmOffs),"/noerrors")) { noErrors=true; parmOffs++; } - else if (!stricmp(line.gettoken_str(parmOffs),"/file")) { isFile=true; parmOffs++; } + if (!stricmp(line.gettoken_str(parmOffs),_T("/ignorecase"))) { ignCase=true; parmOffs++; } + else if (!stricmp(line.gettoken_str(parmOffs),_T("/noerrors"))) { noErrors=true; parmOffs++; } + else if (!stricmp(line.gettoken_str(parmOffs),_T("/file"))) { isFile=true; parmOffs++; } else break; } if (parmOffs+3 > line.getnumtokens()) { - ERROR_MSG("!searchparse: not enough parameters\n"); + ERROR_MSG(_T("!searchparse: not enough parameters\n")); return PS_ERROR; } - const char *source_string = line.gettoken_str(parmOffs++); + const TCHAR *source_string = line.gettoken_str(parmOffs++); DefineList *list=NULL; if (isFile) { - FILE *fp=fopen(source_string,"r"); + FILE *fp=fopen(source_string,_T("r")); if (!fp) { - ERROR_MSG("!searchparse /file: error opening \"%s\"\n",source_string); + ERROR_MSG(_T("!searchparse /file: error opening \"%s\"\n"),source_string); return PS_ERROR; } int req_parm = (line.getnumtokens() - parmOffs)/2; GrowBuf tmpstr; - char str[MAX_LINELENGTH]; + TCHAR str[MAX_LINELENGTH]; for (;;) { tmpstr.resize(0); @@ -3144,13 +3144,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) fgets(str,sizeof(str),fp); if (!str[0]) break; // eof - char *p=str; + TCHAR *p=str; while (*p) p++; if (p > str) p--; - while (p >= str && (*p == '\r' || *p == '\n')) p--; + while (p >= str && (*p == _T('\r') || *p == _T('\n'))) p--; *++p=0; - bool endSlash = (str[0] && str[strlen(str)-1] == '\\'); + bool endSlash = (str[0] && str[strlen(str)-1] == _T('\\')); if (tmpstr.getlen() || endSlash) tmpstr.add(str,strlen(str)); // if we have valid contents and not ending on slash, then done @@ -3159,11 +3159,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!str[0] && !tmpstr.getlen()) break; // reached eof - char *thisline=str; + TCHAR *thisline=str; if (tmpstr.getlen()) { - tmpstr.add("\0",1); - thisline=(char *)tmpstr.get(); + tmpstr.add(_T("\0"),1); + thisline=(TCHAR *)tmpstr.get(); } DefineList *tlist = searchParseString(thisline,&line,parmOffs,ignCase,true); @@ -3184,13 +3184,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!list) { - ERROR_MSG("!searchparse: starting string \"%s\" not found in file!\n",line.gettoken_str(parmOffs)); + ERROR_MSG(_T("!searchparse: starting string \"%s\" not found in file!\n"),line.gettoken_str(parmOffs)); return PS_ERROR; } else if (list->getnum() < req_parm) { - char *p=line.gettoken_str(parmOffs + list->getnum()*2); - ERROR_MSG("!searchparse: failed search at string \"%s\" not found in file!\n",p?p:"(null)"); + TCHAR *p=line.gettoken_str(parmOffs + list->getnum()*2); + ERROR_MSG(_T("!searchparse: failed search at string \"%s\" not found in file!\n"),p?p:_T("(null)")); return PS_ERROR; } } @@ -3206,8 +3206,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int i; for (i=0;igetnum(); i ++) { - char *def=list->getname(i); - char *val=list->getvalue(i); + TCHAR *def=list->getname(i); + TCHAR *val=list->getvalue(i); if (def && val) { if (definedlist.find(def)) definedlist.del(def); @@ -3220,18 +3220,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; case TOK_P_SEARCHREPLACESTRING: { - int ignoreCase=!stricmp(line.gettoken_str(1),"/ignorecase"); + int ignoreCase=!stricmp(line.gettoken_str(1),_T("/ignorecase")); if (line.getnumtokens()!=5+ignoreCase) PRINTHELP() - char *define=line.gettoken_str(1+ignoreCase); - char *src = line.gettoken_str(2+ignoreCase); - char *search = line.gettoken_str(3+ignoreCase); - char *replace = line.gettoken_str(4+ignoreCase); - int searchlen=strlen(search); - int replacelen=strlen(replace); + TCHAR *define=line.gettoken_str(1+ignoreCase); + TCHAR *src = line.gettoken_str(2+ignoreCase); + TCHAR *search = line.gettoken_str(3+ignoreCase); + TCHAR *replace = line.gettoken_str(4+ignoreCase); + int searchlen=_tcsclen(search); + int replacelen=_tcsclen(replace); if (!searchlen) { - ERROR_MSG("!searchreplace: search string must not be empty for search/replace!\n"); + ERROR_MSG(_T("!searchreplace: search string must not be empty for search/replace!\n")); return PS_ERROR; } @@ -3239,7 +3239,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) while (*src) { - if (ignoreCase ? strnicmp(src,search,searchlen) : strncmp(src,search,searchlen)) + if (ignoreCase ? strnicmp(src,search,searchlen) : _tcsncmp(src,search,searchlen)) valout.add(src++,1); else { @@ -3248,16 +3248,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } } - valout.add("",1); + valout.add(_T(""),1); definedlist.del(define); // allow changing variables since we'll often use this in series - if (definedlist.add(define,(char*)valout.get())) + if (definedlist.add(define,(TCHAR*)valout.get())) { - ERROR_MSG("!searchreplace: error defining \"%s\"!\n",define); + ERROR_MSG(_T("!searchreplace: error defining \"%s\"!\n"),define); return PS_ERROR; } - SCRIPT_MSG("!searchreplace: \"%s\"=\"%s\"\n",define,(char*)valout.get()); + SCRIPT_MSG(_T("!searchreplace: \"%s\"=\"%s\"\n"),define,(TCHAR*)valout.get()); } return PS_OK; @@ -3265,7 +3265,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_P_VERBOSE: { extern int g_display_errors; - int k=line.gettoken_enum(1,"push\0pop\0"); + int k=line.gettoken_enum(1,_T("push\0pop\0")); int v; if (k < 0) // just set @@ -3323,18 +3323,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_UNINSTCAPTION: { if (SetInnerString(NLF_UCAPTION,line.gettoken_str(1)) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); - SCRIPT_MSG("UninstCaption: \"%s\"\n",line.gettoken_str(1)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); + SCRIPT_MSG(_T("UninstCaption: \"%s\"\n"),line.gettoken_str(1)); } return PS_OK; case TOK_UNINSTICON: - SCRIPT_MSG("UninstallIcon: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("UninstallIcon: \"%s\"\n"),line.gettoken_str(1)); try { free_loaded_icon(uninstaller_icon); uninstaller_icon = load_icon_file(line.gettoken_str(1)); } catch (exception& err) { - ERROR_MSG("Error while loading icon from \"%s\": %s\n", line.gettoken_str(1), err.what()); + ERROR_MSG(_T("Error while loading icon from \"%s\": %s\n"), line.gettoken_str(1), err.what()); return PS_ERROR; } return PS_OK; @@ -3342,18 +3342,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!cur_page) { if (SetInnerString(NLF_UNINST_TEXT, line.gettoken_str(1)) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); SetInnerString(NLF_UNINST_SUBTEXT, line.gettoken_str(2)); } else { if (cur_page_type != PAGE_UNINSTCONFIRM) { - ERROR_MSG("Error: UninstallText can only be used inside PageEx uninstConfirm.\n"); + ERROR_MSG(_T("Error: UninstallText can only be used inside PageEx uninstConfirm.\n")); return PS_ERROR; } cur_page->parms[0] = add_string(line.gettoken_str(1)); cur_page->parms[1] = add_string(line.gettoken_str(2)); } - SCRIPT_MSG("UninstallText: \"%s\" \"%s\"\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("UninstallText: \"%s\" \"%s\"\n"),line.gettoken_str(1),line.gettoken_str(2)); } return PS_OK; case TOK_UNINSTSUBCAPTION: @@ -3362,24 +3362,24 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int w=line.gettoken_int(1,&s); if (!s || w < 0 || w > 2) PRINTHELP() SetInnerString(NLF_USUBCAPTION_CONFIRM+w,line.gettoken_str(2)); - SCRIPT_MSG("UninstSubCaption: page:%d, text=%s\n",w,line.gettoken_str(2)); + SCRIPT_MSG(_T("UninstSubCaption: page:%d, text=%s\n"),w,line.gettoken_str(2)); } return PS_OK; case TOK_WRITEUNINSTALLER: { if (uninstall_mode) { - ERROR_MSG("WriteUninstaller only valid from install, not from uninstall.\n"); + ERROR_MSG(_T("WriteUninstaller only valid from install, not from uninstall.\n")); PRINTHELP() } uninstaller_writes_used++; ent.which=EW_WRITEUNINSTALLER; ent.offsets[0]=add_string(line.gettoken_str(1)); - string full = string("$INSTDIR\\") + string(line.gettoken_str(1)); + tstring full = tstring(_T("$INSTDIR\\")) + tstring(line.gettoken_str(1)); ent.offsets[3]=add_string(full.c_str()); // ent.offsets[1] and ent.offsets[2] are set in CEXEBuild::uninstall_generate() if (!ent.offsets[0]) PRINTHELP() - SCRIPT_MSG("WriteUninstaller: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("WriteUninstaller: \"%s\"\n"),line.gettoken_str(1)); DefineInnerLangString(NLF_ERR_CREATING); DefineInnerLangString(NLF_CREATED_UNINST); @@ -3391,44 +3391,44 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_UNINSTICON: case TOK_UNINSTTEXT: case TOK_UNINSTSUBCAPTION: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_UNINSTALL_SUPPORT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_UNINSTALL_SUPPORT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif - // section/function shit + // section/function stuff /////////////////////////////////////////////////////////////////////////////// case TOK_SECTION: { int a=1,unselected = 0; - if (!strcmpi(line.gettoken_str(1),"/o")) + if (!strcmpi(line.gettoken_str(1),_T("/o"))) { unselected = 1; a++; } else if (line.getnumtokens() > 3) PRINTHELP(); - SCRIPT_MSG("Section: \"%s\"",line.gettoken_str(a)); - if (line.gettoken_str(a+1)[0]) SCRIPT_MSG(" ->(%s)",line.gettoken_str(a+1)); - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("Section: \"%s\""),line.gettoken_str(a)); + if (line.gettoken_str(a+1)[0]) SCRIPT_MSG(_T(" ->(%s)"),line.gettoken_str(a+1)); + SCRIPT_MSG(_T("\n")); #ifndef NSIS_CONFIG_UNINSTALL_SUPPORT - if (!stricmp(line.gettoken_str(a),"uninstall")) + if (!stricmp(line.gettoken_str(a),_T("uninstall"))) { - ERROR_MSG("Error: Uninstall section declared, no NSIS_CONFIG_UNINSTALL_SUPPORT\n"); + ERROR_MSG(_T("Error: Uninstall section declared, no NSIS_CONFIG_UNINSTALL_SUPPORT\n")); return PS_ERROR; } #endif int ret; - if (line.gettoken_str(a)[0]=='-') + if (line.gettoken_str(a)[0]==_T('-')) { - if (!strnicmp(line.gettoken_str(a)+1,"un.",3)) - ret=add_section("un.",line.gettoken_str(a+1)); + if (!strnicmp(line.gettoken_str(a)+1,_T("un."),3)) + ret=add_section(_T("un."),line.gettoken_str(a+1)); else - ret=add_section("",line.gettoken_str(a+1)); + ret=add_section(_T(""),line.gettoken_str(a+1)); } else ret=add_section(line.gettoken_str(a),line.gettoken_str(a+1)); if (ret != PS_OK) return ret; @@ -3439,27 +3439,27 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; } case TOK_SECTIONEND: - SCRIPT_MSG("SectionEnd\n"); + SCRIPT_MSG(_T("SectionEnd\n")); return section_end(); case TOK_SECTIONIN: { - SCRIPT_MSG("SectionIn: "); + SCRIPT_MSG(_T("SectionIn: ")); int wt; for (wt = 1; wt < line.getnumtokens(); wt ++) { - char *p=line.gettoken_str(wt); - if (!stricmp(p, "RO")) + TCHAR *p=line.gettoken_str(wt); + if (!stricmp(p, _T("RO"))) { if (section_add_flags(SF_RO) != PS_OK) return PS_ERROR; - SCRIPT_MSG("[RO] "); + SCRIPT_MSG(_T("[RO] ")); } else { - int x=atoi(p)-1; + int x=_ttoi(p)-1; if (x >= 0 && x < NSIS_MAX_INST_TYPES) { if (section_add_install_type(1<(%s)",line.gettoken_str(a+1)); - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("%s %s"),line.gettoken_str(0),line.gettoken_str(a)); + if (line.gettoken_str(a+1)[0]) SCRIPT_MSG(_T(" ->(%s)"),line.gettoken_str(a+1)); + SCRIPT_MSG(_T("\n")); return add_section(buf,line.gettoken_str(a+1),ex); } case TOK_FUNCTION: if (!line.gettoken_str(1)[0]) PRINTHELP() - if (line.gettoken_str(1)[0]==':' || line.gettoken_str(1)[0]=='/') + if (line.gettoken_str(1)[0]==_T(':') || line.gettoken_str(1)[0]==_T('/')) { - ERROR_MSG("Function: function name cannot begin with : or /.\n"); + ERROR_MSG(_T("Function: function name cannot begin with : or /.\n")); PRINTHELP() } - SCRIPT_MSG("Function: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Function: \"%s\"\n"),line.gettoken_str(1)); #ifndef NSIS_CONFIG_UNINSTALL_SUPPORT - if (!strnicmp(line.gettoken_str(1),"un.",3)) + if (!strnicmp(line.gettoken_str(1),_T("un."),3)) { - ERROR_MSG("Error: Uninstall function declared, no NSIS_CONFIG_UNINSTALL_SUPPORT\n"); + ERROR_MSG(_T("Error: Uninstall function declared, no NSIS_CONFIG_UNINSTALL_SUPPORT\n")); return PS_ERROR; } #endif return add_function(line.gettoken_str(1)); case TOK_FUNCTIONEND: - SCRIPT_MSG("FunctionEnd\n"); + SCRIPT_MSG(_T("FunctionEnd\n")); return function_end(); // flag setters @@ -3526,19 +3526,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) // BEGIN - Added by ramon 23 May 2003 case TOK_ALLOWSKIPFILES: - build_allowskipfiles=line.gettoken_enum(1,"off\0on\0"); + build_allowskipfiles=line.gettoken_enum(1,_T("off\0on\0")); if (build_allowskipfiles==-1) PRINTHELP() - SCRIPT_MSG("AllowSkipFiles: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("AllowSkipFiles: %s\n"),line.gettoken_str(1)); return PS_OK; // END - Added by ramon 23 May 2003 case TOK_SETDATESAVE: - build_datesave=line.gettoken_enum(1,"off\0on\0"); + build_datesave=line.gettoken_enum(1,_T("off\0on\0")); if (build_datesave==-1) PRINTHELP() - SCRIPT_MSG("SetDateSave: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetDateSave: %s\n"),line.gettoken_str(1)); return PS_OK; case TOK_SETOVERWRITE: { - int k=line.gettoken_enum(1,"on\0off\0try\0ifnewer\0ifdiff\0lastused\0"); + int k=line.gettoken_enum(1,_T("on\0off\0try\0ifnewer\0ifdiff\0lastused\0")); if (k==-1) PRINTHELP() if (k==5) { @@ -3551,72 +3551,72 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) build_last_overwrite=build_overwrite; build_overwrite=k; } - SCRIPT_MSG("SetOverwrite: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetOverwrite: %s\n"),line.gettoken_str(1)); } return PS_OK; #ifdef NSIS_CONFIG_PLUGIN_SUPPORT case TOK_SETPLUGINUNLOAD: - build_plugin_unload=line.gettoken_enum(1,"manual\0alwaysoff\0"); + build_plugin_unload=line.gettoken_enum(1,_T("manual\0alwaysoff\0")); if (build_plugin_unload==-1) PRINTHELP() - SCRIPT_MSG("SetPluginUnload: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetPluginUnload: %s\n"),line.gettoken_str(1)); return PS_OK; #endif //NSIS_CONFIG_PLUGIN_SUPPORT case TOK_SETCOMPRESS: - build_compress=line.gettoken_enum(1,"off\0auto\0force\0"); + build_compress=line.gettoken_enum(1,_T("off\0auto\0force\0")); if (build_compress==-1) PRINTHELP() if (build_compress==0 && build_compress_whole) { - warning_fl("'SetCompress off' encountered, and in whole compression mode. Effectively ignored."); + warning_fl(_T("'SetCompress off' encountered, and in whole compression mode. Effectively ignored.")); } - SCRIPT_MSG("SetCompress: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetCompress: %s\n"),line.gettoken_str(1)); return PS_OK; case TOK_DBOPTIMIZE: - build_optimize_datablock=line.gettoken_enum(1,"off\0on\0"); + build_optimize_datablock=line.gettoken_enum(1,_T("off\0on\0")); if (build_optimize_datablock==-1) PRINTHELP() - SCRIPT_MSG("SetDatablockOptimize: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetDatablockOptimize: %s\n"),line.gettoken_str(1)); return PS_OK; case TOK_FILEBUFSIZE: build_filebuflen=line.gettoken_int(1); build_filebuflen<<=20; if (build_filebuflen<=0) { - ERROR_MSG("Error: FileBufSize: invalid buffer size -- %d\n",build_filebuflen); + ERROR_MSG(_T("Error: FileBufSize: invalid buffer size -- %d\n"),build_filebuflen); return PS_ERROR; } - SCRIPT_MSG("FileBufSize: %smb (%d bytes)\n",line.gettoken_str(1),build_filebuflen); + SCRIPT_MSG(_T("FileBufSize: %smb (%d bytes)\n"),line.gettoken_str(1),build_filebuflen); return PS_OK; #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT case TOK_SETCOMPRESSIONLEVEL: { if (compressor == &lzma_compressor) - warning_fl("SetCompressionLevel: compressor is set to LZMA. Effectively ignored."); + warning_fl(_T("SetCompressionLevel: compressor is set to LZMA. Effectively ignored.")); if (build_compressor_set && build_compress_whole) - warning_fl("SetCompressionLevel: data already compressed in compress whole mode. Effectively ignored."); + warning_fl(_T("SetCompressionLevel: data already compressed in compress whole mode. Effectively ignored.")); int s; build_compress_level=line.gettoken_int(1,&s); if (!s || build_compress_level < 0 || build_compress_level > 9) PRINTHELP(); - SCRIPT_MSG("SetCompressionLevel: %u\n", build_compress_level); + SCRIPT_MSG(_T("SetCompressionLevel: %u\n"), build_compress_level); } return PS_OK; case TOK_SETCOMPRESSORDICTSIZE: { if (compressor != &lzma_compressor) - warning_fl("SetCompressorDictSize: compressor is not set to LZMA. Effectively ignored."); + warning_fl(_T("SetCompressorDictSize: compressor is not set to LZMA. Effectively ignored.")); if (build_compressor_set && build_compress_whole) - warning_fl("SetCompressorDictSize: data already compressed in compress whole mode. Effectively ignored."); + warning_fl(_T("SetCompressorDictSize: data already compressed in compress whole mode. Effectively ignored.")); int s; build_compress_dict_size=line.gettoken_int(1,&s); if (!s) PRINTHELP(); - SCRIPT_MSG("SetCompressorDictSize: %u mb\n", build_compress_dict_size); + SCRIPT_MSG(_T("SetCompressorDictSize: %u mb\n"), build_compress_dict_size); build_compress_dict_size <<= 20; } return PS_OK; #else case TOK_SETCOMPRESSIONLEVEL: case TOK_SETCOMPRESSORDICTSIZE: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_COMPRESSION_SUPPORT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_COMPRESSION_SUPPORT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//NSIS_CONFIG_COMPRESSION_SUPPORT case TOK_ADDSIZE: @@ -3624,7 +3624,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int s; int size_kb=line.gettoken_int(1,&s); if (!s) PRINTHELP() - SCRIPT_MSG("AddSize: %d kb\n",size_kb); + SCRIPT_MSG(_T("AddSize: %d kb\n"),size_kb); section_add_size_kb(size_kb); } return PS_OK; @@ -3634,7 +3634,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int w=line.gettoken_int(1,&s); if (!s || w < 0 || w > 4) PRINTHELP() SetInnerString(NLF_SUBCAPTION_LICENSE+w,line.gettoken_str(2)); - SCRIPT_MSG("SubCaption: page:%d, text=%s\n",w,line.gettoken_str(2)); + SCRIPT_MSG(_T("SubCaption: page:%d, text=%s\n"),w,line.gettoken_str(2)); } return PS_OK; case TOK_FILEERRORTEXT: @@ -3642,22 +3642,22 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { SetInnerString(NLF_FILE_ERROR,line.gettoken_str(1)); SetInnerString(NLF_FILE_ERROR_NOIGNORE,line.gettoken_str(2)); - SCRIPT_MSG("FileErrorText: \"%s\" \"%s\"\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("FileErrorText: \"%s\" \"%s\"\n"),line.gettoken_str(1),line.gettoken_str(2)); } return PS_OK; #else - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_FILE not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_FILE not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif case TOK_BRANDINGTEXT: { int a = 1; int trim = 0; - while (line.gettoken_str(a)[0] == '/') { - if (!strnicmp(line.gettoken_str(a),"/TRIM",5)) { - if (!stricmp(line.gettoken_str(a)+5,"LEFT")) trim = 1; - else if (!stricmp(line.gettoken_str(a)+5,"RIGHT")) trim = 2; - else if (!stricmp(line.gettoken_str(a)+5,"CENTER")) trim = 3; + while (line.gettoken_str(a)[0] == _T('/')) { + if (!strnicmp(line.gettoken_str(a),_T("/TRIM"),5)) { + if (!stricmp(line.gettoken_str(a)+5,_T("LEFT"))) trim = 1; + else if (!stricmp(line.gettoken_str(a)+5,_T("RIGHT"))) trim = 2; + else if (!stricmp(line.gettoken_str(a)+5,_T("CENTER"))) trim = 3; else PRINTHELP(); a++; } @@ -3675,11 +3675,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) free(dlg); if (trim) { - char str[512]; + TCHAR str[512]; if (line.getnumtokens()==a+1 && line.gettoken_str(a)[0]) strcpy(str, line.gettoken_str(a)); else - wsprintf(str, "Nullsoft Install System %s", NSIS_VERSION); + wsprintf(str, _T("Nullsoft Install System %s"), NSIS_VERSION); short old_width = td.GetItem(IDC_VERSTR)->sWidth; @@ -3691,7 +3691,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (td.GetItem(IDC_VERSTR)->sWidth > old_width) { - warning_fl("BrandingText: \"%s\" is too long, trimming has expanded the label", str); + warning_fl(_T("BrandingText: \"%s\" is too long, trimming has expanded the label"), str); } } @@ -3701,17 +3701,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) res_editor->FreeResource(dlg); } catch (exception& err) { - ERROR_MSG("Error while triming branding text control: %s\n", err.what()); + ERROR_MSG(_T("Error while triming branding text control: %s\n"), err.what()); return PS_ERROR; } #else if (trim) { - ERROR_MSG("Error: BrandingText /TRIM* is disabled for non Win32 platforms.\n"); + ERROR_MSG(_T("Error: BrandingText /TRIM* is disabled for non Win32 platforms.\n")); return PS_ERROR; } #endif - SCRIPT_MSG("BrandingText: \"%s\"\n",line.gettoken_str(a)); + SCRIPT_MSG(_T("BrandingText: \"%s\"\n"),line.gettoken_str(a)); } return PS_OK; case TOK_MISCBUTTONTEXT: @@ -3720,90 +3720,90 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) SetInnerString(NLF_BTN_NEXT,line.gettoken_str(2)); SetInnerString(NLF_BTN_CANCEL,line.gettoken_str(3)); SetInnerString(NLF_BTN_CLOSE,line.gettoken_str(4)); - SCRIPT_MSG("MiscButtonText: back=\"%s\" next=\"%s\" cancel=\"%s\" close=\"%s\"\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); + SCRIPT_MSG(_T("MiscButtonText: back=\"%s\" next=\"%s\" cancel=\"%s\" close=\"%s\"\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); } return PS_OK; case TOK_SPACETEXTS: { - if (!strcmpi(line.gettoken_str(1), "none")) { + if (!strcmpi(line.gettoken_str(1), _T("none"))) { no_space_texts=true; - SCRIPT_MSG("SpaceTexts: none\n"); + SCRIPT_MSG(_T("SpaceTexts: none\n")); } else { no_space_texts=false; SetInnerString(NLF_SPACE_REQ,line.gettoken_str(1)); SetInnerString(NLF_SPACE_AVAIL,line.gettoken_str(2)); - SCRIPT_MSG("SpaceTexts: required=\"%s\" available=\"%s\"\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SpaceTexts: required=\"%s\" available=\"%s\"\n"),line.gettoken_str(1),line.gettoken_str(2)); } } return PS_OK; case TOK_INSTBUTTONTEXT: { SetInnerString(NLF_BTN_INSTALL,line.gettoken_str(1)); - SCRIPT_MSG("InstallButtonText: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("InstallButtonText: \"%s\"\n"),line.gettoken_str(1)); } return PS_OK; case TOK_DETAILSBUTTONTEXT: { if (!cur_page) { if (SetInnerString(NLF_BTN_DETAILS,line.gettoken_str(1)) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); } else { if (cur_page_type != PAGE_INSTFILES) { - ERROR_MSG("Error: DetailsButtonText can only be used inside PageEx instfiles.\n"); + ERROR_MSG(_T("Error: DetailsButtonText can only be used inside PageEx instfiles.\n")); return PS_ERROR; } cur_page->parms[1] = add_string(line.gettoken_str(1)); } - SCRIPT_MSG("DetailsButtonText: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("DetailsButtonText: \"%s\"\n"),line.gettoken_str(1)); } return PS_OK; case TOK_COMPLETEDTEXT: { if (!cur_page) { if (SetInnerString(NLF_COMPLETED,line.gettoken_str(1)) == PS_WARNING) - warning_fl("%s: specified multiple times, wasting space",line.gettoken_str(0)); + warning_fl(_T("%s: specified multiple times, wasting space"),line.gettoken_str(0)); } else { if (cur_page_type != PAGE_INSTFILES) { - ERROR_MSG("Error: CompletedText can only be used inside PageEx instfiles.\n"); + ERROR_MSG(_T("Error: CompletedText can only be used inside PageEx instfiles.\n")); return PS_ERROR; } cur_page->parms[2] = add_string(line.gettoken_str(1)); } - SCRIPT_MSG("CompletedText: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("CompletedText: \"%s\"\n"),line.gettoken_str(1)); } return PS_OK; case TOK_UNINSTBUTTONTEXT: #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT { SetInnerString(NLF_BTN_UNINSTALL,line.gettoken_str(1)); - SCRIPT_MSG("UninstButtonText: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("UninstButtonText: \"%s\"\n"),line.gettoken_str(1)); } return PS_OK; #else - ERROR_MSG("Error: %s specified, NSIS_CONFIG_UNINSTALL_SUPPORT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_UNINSTALL_SUPPORT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif // instructions /////////////////////////////////////////////////////////////////////////////// case TOK_NOP: - SCRIPT_MSG("Nop\n"); + SCRIPT_MSG(_T("Nop\n")); ent.which=EW_NOP; return add_entry(&ent); case TOK_GOTO: ent.which=EW_NOP; if (process_jump(line,1,&ent.offsets[0])) PRINTHELP() - SCRIPT_MSG("Goto: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Goto: %s\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_SETREGVIEW: { ent.which=EW_SETFLAG; ent.offsets[0]=FLAG_OFFSET(alter_reg_view); // "64" results in setting the flag to 1 which alters the view - int k=line.gettoken_enum(1,"32\0" "64\0lastused\0"); + int k=line.gettoken_enum(1,_T("32\0") _T("64\0lastused\0")); if (k<0) PRINTHELP() if (k == 0) // 32 ent.offsets[1]=add_intstring(0); @@ -3811,35 +3811,35 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=add_intstring(KEY_WOW64_64KEY); else if (k == 2) // last used ent.offsets[2]=1; - SCRIPT_MSG("SetRegView: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetRegView: %s\n"),line.gettoken_str(1)); } return add_entry(&ent); case TOK_SETSHELLVARCONTEXT: { ent.which=EW_SETFLAG; ent.offsets[0]=FLAG_OFFSET(all_user_var); - int k=line.gettoken_enum(1,"current\0all\0"); + int k=line.gettoken_enum(1,_T("current\0all\0")); if (k<0) PRINTHELP() ent.offsets[1]=add_intstring(k); - SCRIPT_MSG("SetShellVarContext: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetShellVarContext: %s\n"),line.gettoken_str(1)); } return add_entry(&ent); case TOK_RET: - SCRIPT_MSG("Return\n"); + SCRIPT_MSG(_T("Return\n")); ent.which=EW_RET; return add_entry(&ent); case TOK_CALL: - if (!line.gettoken_str(1)[0] || (line.gettoken_str(1)[0]==':' && !line.gettoken_str(1)[1] )) PRINTHELP() + if (!line.gettoken_str(1)[0] || (line.gettoken_str(1)[0]==_T(':') && !line.gettoken_str(1)[1] )) PRINTHELP() #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT - if (uninstall_mode && strnicmp(line.gettoken_str(1),"un.",3) - && (GetUserVarIndex(line,1) < 0) && line.gettoken_str(1)[0]!=':') + if (uninstall_mode && strnicmp(line.gettoken_str(1),_T("un."),3) + && (GetUserVarIndex(line,1) < 0) && line.gettoken_str(1)[0]!=_T(':')) { - ERROR_MSG("Call must be used with function names starting with \"un.\" in the uninstall section.\n"); + ERROR_MSG(_T("Call must be used with function names starting with \"un.\" in the uninstall section.\n")); PRINTHELP() } - if (!uninstall_mode && !strnicmp(line.gettoken_str(1),"un.",3)) + if (!uninstall_mode && !strnicmp(line.gettoken_str(1),_T("un."),3)) { - ERROR_MSG("Call must not be used with functions starting with \"un.\" in the non-uninstall sections.\n"); + ERROR_MSG(_T("Call must not be used with functions starting with \"un.\" in the non-uninstall sections.\n")); PRINTHELP() } #endif @@ -3853,7 +3853,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } else { - if (line.gettoken_str(1)[0] == ':') + if (line.gettoken_str(1)[0] == _T(':')) { ent.offsets[1]=1; ent.offsets[0]=ns_label.add(line.gettoken_str(1)+1,0); @@ -3861,16 +3861,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else ent.offsets[0]=ns_func.add(line.gettoken_str(1),0); } } - SCRIPT_MSG("Call \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Call \"%s\"\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_SETOUTPATH: { - const char *op=line.gettoken_str(1); - if (!strcmp(op,"-")) + const TCHAR *op=line.gettoken_str(1); + if (!_tcscmp(op,_T("-"))) { - op="$INSTDIR"; + op=_T("$INSTDIR"); } - SCRIPT_MSG("SetOutPath: \"%s\"\n",op); + SCRIPT_MSG(_T("SetOutPath: \"%s\"\n"),op); ent.which=EW_CREATEDIR; ent.offsets[0]=add_string(op); ent.offsets[1]=1; @@ -3880,18 +3880,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return add_entry(&ent); case TOK_CREATEDIR: { - char out_path[1024]; - char *p=line.gettoken_str(1); - if (*p == '-') out_path[0]=0; + TCHAR out_path[1024]; + TCHAR *p=line.gettoken_str(1); + if (*p == _T('-')) out_path[0]=0; else { - if (p[0] == '\\' && p[1] != '\\') p++; + if (p[0] == _T('\\') && p[1] != _T('\\')) p++; strncpy(out_path,p,1024-1); - if (*CharPrev(out_path,out_path+strlen(out_path))=='\\') + if (*CharPrev(out_path,out_path+strlen(out_path))==_T('\\')) *CharPrev(out_path,out_path+strlen(out_path))=0; // remove trailing slash } if (!*out_path) PRINTHELP() - SCRIPT_MSG("CreateDirectory: \"%s\"\n",out_path); + SCRIPT_MSG(_T("CreateDirectory: \"%s\"\n"),out_path); ent.which=EW_CREATEDIR; ent.offsets[0]=add_string(out_path); @@ -3910,12 +3910,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=GetUserVarIndex(line, 2); if (line.gettoken_str(2)[0] && ent.offsets[1]<0) PRINTHELP() } - SCRIPT_MSG("%s: \"%s\" (->%s)\n",ent.offsets[2]?"ExecWait":"Exec",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("%s: \"%s\" (->%s)\n"),ent.offsets[2]?_T("ExecWait"):_T("Exec"),line.gettoken_str(1),line.gettoken_str(2)); DefineInnerLangString(NLF_EXEC); return add_entry(&ent); #else//!NSIS_SUPPORT_EXECUTE - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_EXECUTE not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_EXECUTE not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_EXECUTE case TOK_EXECSHELL: // this uses improvements of Andras Varga @@ -3929,40 +3929,40 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (line.getnumtokens() > 4) { int tab[5]={SW_SHOWDEFAULT,SW_SHOWNORMAL,SW_SHOWMAXIMIZED,SW_SHOWMINIMIZED,SW_HIDE}; - int a=line.gettoken_enum(4,"SW_SHOWDEFAULT\0SW_SHOWNORMAL\0SW_SHOWMAXIMIZED\0SW_SHOWMINIMIZED\0SW_HIDE\0"); + int a=line.gettoken_enum(4,_T("SW_SHOWDEFAULT\0SW_SHOWNORMAL\0SW_SHOWMAXIMIZED\0SW_SHOWMINIMIZED\0SW_HIDE\0")); if (a < 0) PRINTHELP() ent.offsets[3]=tab[a]; } - string detail=string(line.gettoken_str(1))+" "+string(line.gettoken_str(2)); + tstring detail=tstring(line.gettoken_str(1))+_T(" ")+tstring(line.gettoken_str(2)); ent.offsets[5]=add_string(detail.c_str()); - SCRIPT_MSG("ExecShell: %s: \"%s\" \"%s\" %s\n",line.gettoken_str(1),line.gettoken_str(2), + SCRIPT_MSG(_T("ExecShell: %s: \"%s\" \"%s\" %s\n"),line.gettoken_str(1),line.gettoken_str(2), line.gettoken_str(3),line.gettoken_str(4)); DefineInnerLangString(NLF_EXEC_SHELL); } return add_entry(&ent); #else//!NSIS_SUPPORT_SHELLEXECUTE - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_SHELLEXECUTE not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_SHELLEXECUTE not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_SHELLEXECUTE case TOK_CALLINSTDLL: case TOK_REGDLL: case TOK_UNREGDLL: #ifndef NSIS_SUPPORT_ACTIVEXREG - ERROR_MSG("%s: support not compiled in (NSIS_SUPPORT_ACTIVEXREG)\n",line.gettoken_str(0)); + ERROR_MSG(_T("%s: support not compiled in (NSIS_SUPPORT_ACTIVEXREG)\n"),line.gettoken_str(0)); return PS_ERROR; #else//NSIS_SUPPORT_ACTIVEXREG ent.which=EW_REGISTERDLL; ent.offsets[0]=add_string(line.gettoken_str(1)); if (which_token == TOK_UNREGDLL) { - ent.offsets[1]=add_string("DllUnregisterServer"); + ent.offsets[1]=add_string(_T("DllUnregisterServer")); ent.offsets[2]=DefineInnerLangString(NLF_UNREGISTERING); } else if (which_token == TOK_CALLINSTDLL) { int a = 2; - if (!stricmp(line.gettoken_str(a), "/NOUNLOAD")) { + if (!stricmp(line.gettoken_str(a), _T("/NOUNLOAD"))) { ent.offsets[3]=1; a++; } @@ -3974,11 +3974,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else // register { ent.offsets[1] = add_string(line.gettoken_str(2)); - if (!ent.offsets[1]) ent.offsets[1]=add_string("DllRegisterServer"); + if (!ent.offsets[1]) ent.offsets[1]=add_string(_T("DllRegisterServer")); ent.offsets[2]=DefineInnerLangString(NLF_REGISTERING); } - SCRIPT_MSG("%s: \"%s\" %s\n",line.gettoken_str(0),line.gettoken_str(1), line.gettoken_str(ent.offsets[3]?3:2)); + SCRIPT_MSG(_T("%s: \"%s\" %s\n"),line.gettoken_str(0),line.gettoken_str(1), line.gettoken_str(ent.offsets[3]?3:2)); DefineInnerLangString(NLF_SYMBOL_NOT_FOUND); DefineInnerLangString(NLF_COULD_NOT_LOAD); @@ -3991,25 +3991,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int a=1; ent.which=EW_RENAME; - if (!stricmp(line.gettoken_str(1),"/REBOOTOK")) + if (!stricmp(line.gettoken_str(1),_T("/REBOOTOK"))) { ent.offsets[2]=1; a++; #ifndef NSIS_SUPPORT_MOVEONREBOOT - ERROR_MSG("Error: /REBOOTOK specified, NSIS_SUPPORT_MOVEONREBOOT not defined\n"); + ERROR_MSG(_T("Error: /REBOOTOK specified, NSIS_SUPPORT_MOVEONREBOOT not defined\n")); PRINTHELP() #endif } - else if (line.gettoken_str(1)[0]=='/') + else if (line.gettoken_str(1)[0]==_T('/')) { a=line.getnumtokens(); // cause usage to go here: } if (line.getnumtokens()!=a+2) PRINTHELP() ent.offsets[0]=add_string(line.gettoken_str(a)); ent.offsets[1]=add_string(line.gettoken_str(a+1)); - string print = string(line.gettoken_str(a)) + "->" + string(line.gettoken_str(a+1)); + tstring print = tstring(line.gettoken_str(a)) + _T("->") + tstring(line.gettoken_str(a+1)); ent.offsets[3]=add_string(print.c_str()); - SCRIPT_MSG("Rename: %s%s->%s\n",ent.offsets[2]?"/REBOOTOK ":"",line.gettoken_str(a),line.gettoken_str(a+1)); + SCRIPT_MSG(_T("Rename: %s%s->%s\n"),ent.offsets[2]?_T("/REBOOTOK "):_T(""),line.gettoken_str(a),line.gettoken_str(a+1)); DefineInnerLangString(NLF_RENAME); #ifdef NSIS_SUPPORT_MOVEONREBOOT @@ -4018,17 +4018,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } return add_entry(&ent); #else//!NSIS_SUPPORT_RENAME - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_RENAME not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_RENAME not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_RENAME case TOK_MESSAGEBOX: #ifdef NSIS_SUPPORT_MESSAGEBOX { - #define MBD(x) {x,#x}, + #define MBD(x) {x,_T(#x)}, struct { int id; - const char *str; + const TCHAR *str; } list[]= { MBD(MB_ABORTRETRYIGNORE) @@ -4054,12 +4054,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) #undef MBD int r=0; int x; - char *p=line.gettoken_str(1); + TCHAR *p=line.gettoken_str(1); while (*p) { - char *np=p; - while (*np && *np != '|') np++; + TCHAR *np=p; + while (*np && *np != _T('|')) np++; if (*np) *np++=0; for (x = 0 ; (unsigned) x < sizeof(list) / sizeof(list[0]) && strcmpi(list[x].str, p); x++); if ((unsigned) x < sizeof(list) / sizeof(list[0])) @@ -4076,11 +4076,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { 0,IDABORT,IDCANCEL,IDIGNORE,IDNO,IDOK,IDRETRY,IDYES }; - const char *retstr="0\0IDABORT\0IDCANCEL\0IDIGNORE\0IDNO\0IDOK\0IDRETRY\0IDYES\0"; + const TCHAR *retstr=_T("0\0IDABORT\0IDCANCEL\0IDIGNORE\0IDNO\0IDOK\0IDRETRY\0IDYES\0"); int a=3; if (line.getnumtokens() > 3) { - if (!strcmpi(line.gettoken_str(3),"/SD")) + if (!strcmpi(line.gettoken_str(3),_T("/SD"))) { int k=line.gettoken_enum(4,retstr); if (k <= 0) PRINTHELP(); @@ -4109,13 +4109,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } } } - SCRIPT_MSG("MessageBox: %d: \"%s\"",r,line.gettoken_str(2)); - if (line.getnumtokens()>a+1) SCRIPT_MSG(" (on %s goto %s)",line.gettoken_str(a),line.gettoken_str(a+1)); - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("MessageBox: %d: \"%s\""),r,line.gettoken_str(2)); + if (line.getnumtokens()>a+1) SCRIPT_MSG(_T(" (on %s goto %s)"),line.gettoken_str(a),line.gettoken_str(a+1)); + SCRIPT_MSG(_T("\n")); } return add_entry(&ent); #else//!NSIS_SUPPORT_MESSAGEBOX - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_MESSAGEBOX not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_MESSAGEBOX not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_MESSAGEBOX case TOK_CREATESHORTCUT: @@ -4132,7 +4132,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (line.getnumtokens() > 5 && *line.gettoken_str(5)) { - ERROR_MSG("CreateShortCut: cannot interpret icon index\n"); + ERROR_MSG(_T("CreateShortCut: cannot interpret icon index\n")); PRINTHELP() } ent.offsets[4]=0; @@ -4140,19 +4140,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (line.getnumtokens() > 6 && *line.gettoken_str(6)) { int tab[3]={SW_SHOWNORMAL,SW_SHOWMAXIMIZED,SW_SHOWMINNOACTIVE/*SW_SHOWMINIMIZED doesn't work*/}; - int a=line.gettoken_enum(6,"SW_SHOWNORMAL\0SW_SHOWMAXIMIZED\0SW_SHOWMINIMIZED\0"); + int a=line.gettoken_enum(6,_T("SW_SHOWNORMAL\0SW_SHOWMAXIMIZED\0SW_SHOWMINIMIZED\0")); if (a < 0) { - ERROR_MSG("CreateShortCut: unknown show mode \"%s\"\n",line.gettoken_str(6)); + ERROR_MSG(_T("CreateShortCut: unknown show mode \"%s\"\n"),line.gettoken_str(6)); PRINTHELP() } ent.offsets[4]|=tab[a]<<8; } if (line.getnumtokens() > 7) { - char *s=(line.gettoken_str(7)); + TCHAR *s=(line.gettoken_str(7)); - char b[255]; + TCHAR b[255]; for (unsigned int spos=0; (spos <= strlen(s)) && (spos <= 255); spos++) b[spos]=toupper(*(s+spos)); strcpy(s,b); @@ -4160,33 +4160,33 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (*s) { int c=0; - if (strstr(s,"ALT|")) ent.offsets[4]|=HOTKEYF_ALT << 24; - if (strstr(s,"CONTROL|")) ent.offsets[4]|=HOTKEYF_CONTROL << 24; - if (strstr(s,"EXT|")) ent.offsets[4]|=HOTKEYF_EXT << 24; - if (strstr(s,"SHIFT|")) ent.offsets[4]|=HOTKEYF_SHIFT << 24; - while (strstr(s,"|")) + if (_tcsstr(s,_T("ALT|"))) ent.offsets[4]|=HOTKEYF_ALT << 24; + if (_tcsstr(s,_T("CONTROL|"))) ent.offsets[4]|=HOTKEYF_CONTROL << 24; + if (_tcsstr(s,_T("EXT|"))) ent.offsets[4]|=HOTKEYF_EXT << 24; + if (_tcsstr(s,_T("SHIFT|"))) ent.offsets[4]|=HOTKEYF_SHIFT << 24; + while (_tcsstr(s,_T("|"))) { - s=strstr(s,"|")+1; + s=_tcsstr(s,_T("|"))+1; } - if ((s[0] == 'F') && (s[1] >= '1' && s[1] <= '9')) + if ((s[0] == _T('F')) && (s[1] >= _T('1') && s[1] <= _T('9'))) { - c=VK_F1-1+atoi(s+1); - if (atoi(s+1) < 1 || atoi(s+1) > 24) + c=VK_F1-1+_ttoi(s+1); + if (_ttoi(s+1) < 1 || _ttoi(s+1) > 24) { - warning_fl("CreateShortCut: F-key \"%s\" out of range",s); + warning_fl(_T("CreateShortCut: F-key \"%s\" out of range"),s); } } - else if (((s[0] >= 'A' && s[0] <= 'Z') || (s[0] >= '0' && s[0] <= '9')) && !s[1]) + else if (((s[0] >= _T('A') && s[0] <= _T('Z')) || (s[0] >= _T('0') && s[0] <= _T('9'))) && !s[1]) c=s[0]; else { c=s[0]; - warning_fl("CreateShortCut: unrecognized hotkey \"%s\"",s); + warning_fl(_T("CreateShortCut: unrecognized hotkey \"%s\""),s); } ent.offsets[4] |= (c) << 16; } } - SCRIPT_MSG("CreateShortCut: \"%s\"->\"%s\" %s icon:%s,%d, showmode=0x%X, hotkey=0x%X, comment=%s\n", + SCRIPT_MSG(_T("CreateShortCut: \"%s\"->\"%s\" %s icon:%s,%d, showmode=0x%X, hotkey=0x%X, comment=%s\n"), line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3), line.gettoken_str(4),ent.offsets[4]&0xff,(ent.offsets[4]>>8)&0xff,ent.offsets[4]>>16,line.gettoken_str(8)); @@ -4194,7 +4194,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) DefineInnerLangString(NLF_ERR_CREATING_SHORTCUT); return add_entry(&ent); #else//!NSIS_SUPPORT_CREATESHORTCUT - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_CREATESHORTCUT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_CREATESHORTCUT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//NSIS_SUPPORT_CREATESHORTCUT #ifdef NSIS_SUPPORT_HWNDS @@ -4206,32 +4206,32 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[2]=add_string(line.gettoken_str(3)); ent.offsets[3]=add_string(line.gettoken_str(4)); ent.offsets[4]=add_string(line.gettoken_str(5)); - SCRIPT_MSG("FindWindow: output=%s, class=\"%s\", text=\"%s\" hwndparent=\"%s\" hwndafter=\"%s\"\n", + SCRIPT_MSG(_T("FindWindow: output=%s, class=\"%s\", text=\"%s\" hwndparent=\"%s\" hwndafter=\"%s\"\n"), line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4),line.gettoken_str(5)); return add_entry(&ent); case TOK_SENDMESSAGE: ent.which=EW_SENDMESSAGE; - if (line.gettoken_str(1)[0] == '/' || line.gettoken_str(2)[0] == '/' || - line.gettoken_str(3)[0] == '/' || line.gettoken_str(4)[0] == '/') + if (line.gettoken_str(1)[0] == _T('/') || line.gettoken_str(2)[0] == _T('/') || + line.gettoken_str(3)[0] == _T('/') || line.gettoken_str(4)[0] == _T('/')) { PRINTHELP() } - SCRIPT_MSG("SendMessage:"); + SCRIPT_MSG(_T("SendMessage:")); { int a=5; ent.offsets[0]=GetUserVarIndex(line, 5); if (ent.offsets[0]>=0) { - SCRIPT_MSG("(->%s)",line.gettoken_str(5)); + SCRIPT_MSG(_T("(->%s)"),line.gettoken_str(5)); a++; } - if (!strncmp(line.gettoken_str(a),"/TIMEOUT=",9)) + if (!_tcsncmp(line.gettoken_str(a),_T("/TIMEOUT="),9)) { - ent.offsets[5]|=atoi(line.gettoken_str(a)+9)<<2; - SCRIPT_MSG(" (timeout=%d)",ent.offsets[5]>>2); + ent.offsets[5]|=_ttoi(line.gettoken_str(a)+9)<<2; + SCRIPT_MSG(_T(" (timeout=%d)"),ent.offsets[5]>>2); a++; } @@ -4241,13 +4241,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } } - if (!strncmp(line.gettoken_str(3),"STR:",4)) + if (!_tcsncmp(line.gettoken_str(3),_T("STR:"),4)) { ent.offsets[5]|=1; ent.offsets[3]=add_string(line.gettoken_str(3)+4); } else ent.offsets[3]=add_string(line.gettoken_str(3)); - if (!strncmp(line.gettoken_str(4),"STR:",4)) + if (!_tcsncmp(line.gettoken_str(4),_T("STR:"),4)) { ent.offsets[5]|=2; ent.offsets[4]=add_string(line.gettoken_str(4)+4); @@ -4257,14 +4257,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=add_string(line.gettoken_str(1)); ent.offsets[2]=add_string(line.gettoken_str(2)); - SCRIPT_MSG("(%s,%s,%s,%s)\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); + SCRIPT_MSG(_T("(%s,%s,%s,%s)\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); return add_entry(&ent); case TOK_ISWINDOW: ent.which=EW_ISWINDOW; ent.offsets[0]=add_string(line.gettoken_str(1)); if (process_jump(line,2,&ent.offsets[1])|| process_jump(line,3,&ent.offsets[2])) PRINTHELP() - SCRIPT_MSG("IsWindow(%s): %s:%s\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); + SCRIPT_MSG(_T("IsWindow(%s): %s:%s\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); return add_entry(&ent); #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT case TOK_GETDLGITEM: @@ -4273,7 +4273,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (ent.offsets[0]<0) PRINTHELP(); ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[2]=add_string(line.gettoken_str(3)); - SCRIPT_MSG("GetDlgItem: output=%s dialog=%s item=%s\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); + SCRIPT_MSG(_T("GetDlgItem: output=%s dialog=%s item=%s\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); return add_entry(&ent); case TOK_SETCTLCOLORS: { @@ -4284,18 +4284,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int a = 2; - if (!strcmpi(line.gettoken_str(2),"/BRANDING")) + if (!strcmpi(line.gettoken_str(2),_T("/BRANDING"))) a++; { - char *p; + TCHAR *p; if (a == 2 && line.getnumtokens() == 5) { - ERROR_MSG("Error: SetCtlColors expected 3 parameters, got 4\n"); + ERROR_MSG(_T("Error: SetCtlColors expected 3 parameters, got 4\n")); return PS_ERROR; } - if (!strcmpi(line.gettoken_str(a+1),"transparent")) { + if (!strcmpi(line.gettoken_str(a+1),_T("transparent"))) { c.flags|=CC_BKB; c.lbStyle=BS_NULL; c.bkmode=TRANSPARENT; @@ -4303,7 +4303,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else { p=line.gettoken_str(a+1); if (*p) { - int v=strtoul(p,&p,16); + int v=_tcstoul(p,&p,16); c.bkc=((v&0xff)<<16)|(v&0xff00)|((v&0xff0000)>>16); c.flags|=CC_BK|CC_BKB; } @@ -4314,7 +4314,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) p=line.gettoken_str(a); if (*p) { - int v=strtoul(p,&p,16); + int v=_tcstoul(p,&p,16); c.text=((v&0xff)<<16)|(v&0xff00)|((v&0xff0000)>>16); c.flags|=CC_TEXT; } @@ -4350,7 +4350,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=cur_ctlcolors->add(&c,sizeof(ctlcolors)); } - SCRIPT_MSG("SetCtlColors: hwnd=%s %stext=%s background=%s\n",line.gettoken_str(1),a==2?"":"/BRANDING ",line.gettoken_str(a),line.gettoken_str(a+1)); + SCRIPT_MSG(_T("SetCtlColors: hwnd=%s %stext=%s background=%s\n"),line.gettoken_str(1),a==2?_T(""):_T("/BRANDING "),line.gettoken_str(a),line.gettoken_str(a+1)); } return add_entry(&ent); case TOK_CREATEFONT: @@ -4358,42 +4358,42 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[0]=GetUserVarIndex(line, 1); if (ent.offsets[0] < 0) PRINTHELP() ent.offsets[1]=add_string(line.gettoken_str(2)); - SCRIPT_MSG("CreateFont: output=%s \"%s\"",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("CreateFont: output=%s \"%s\""),line.gettoken_str(1),line.gettoken_str(2)); { int height=0; int weight=0; int flags=0; for (int i = 3; i < line.getnumtokens(); i++) { - char *tok=line.gettoken_str(i); + TCHAR *tok=line.gettoken_str(i); if (tok[0]=='/') { - if (!strcmpi(tok,"/ITALIC")) { - SCRIPT_MSG(" /ITALIC"); + if (!strcmpi(tok,_T("/ITALIC"))) { + SCRIPT_MSG(_T(" /ITALIC")); flags|=1; } - else if (!strcmpi(tok,"/UNDERLINE")) { - SCRIPT_MSG(" /UNDERLINE"); + else if (!strcmpi(tok,_T("/UNDERLINE"))) { + SCRIPT_MSG(_T(" /UNDERLINE")); flags|=2; } - else if (!strcmpi(tok,"/STRIKE")) { - SCRIPT_MSG(" /STRIKE"); + else if (!strcmpi(tok,_T("/STRIKE"))) { + SCRIPT_MSG(_T(" /STRIKE")); flags|=4; } else { - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); PRINTHELP(); } } else { if (!height) { - SCRIPT_MSG(" height=%s",tok); + SCRIPT_MSG(_T(" height=%s"),tok); height=add_string(tok); } else if (!weight) { - SCRIPT_MSG(" weight=%s",tok); + SCRIPT_MSG(_T(" weight=%s"),tok); weight=add_string(tok); } else { - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); PRINTHELP(); } } @@ -4402,40 +4402,40 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[3]=weight; ent.offsets[4]=flags; } - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); return add_entry(&ent); case TOK_ENABLEWINDOW: ent.which=EW_SHOWWINDOW; ent.offsets[0]=add_string(line.gettoken_str(1)); ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[3]=1; - SCRIPT_MSG("EnableWindow: handle=%s enable=%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("EnableWindow: handle=%s enable=%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SHOWWINDOW: ent.which=EW_SHOWWINDOW; ent.offsets[0]=add_string(line.gettoken_str(1)); ent.offsets[1]=add_string(line.gettoken_str(2)); - SCRIPT_MSG("ShowWindow: handle=%s show state=%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("ShowWindow: handle=%s show state=%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_HIDEWINDOW: ent.which=EW_SHOWWINDOW; - ent.offsets[0]=add_string("$HWNDPARENT"); - ent.offsets[1]=add_string("0"/*SW_HIDE*/); + ent.offsets[0]=add_string(_T("$HWNDPARENT")); + ent.offsets[1]=add_string(_T("0")/*SW_HIDE*/); ent.offsets[2]=1; - SCRIPT_MSG("HideWindow\n"); + SCRIPT_MSG(_T("HideWindow\n")); return add_entry(&ent); case TOK_BRINGTOFRONT: { int ret; ent.which=EW_SHOWWINDOW; - ent.offsets[0]=add_string("$HWNDPARENT"); - ent.offsets[1]=add_string("5"/*SW_SHOW*/); + ent.offsets[0]=add_string(_T("$HWNDPARENT")); + ent.offsets[1]=add_string(_T("5")/*SW_SHOW*/); ret = add_entry(&ent); if (ret != PS_OK) return ret; ent.which=EW_BRINGTOFRONT; ent.offsets[0]=0; ent.offsets[1]=0; - SCRIPT_MSG("BringToFront\n"); + SCRIPT_MSG(_T("BringToFront\n")); } return add_entry(&ent); #else//NSIS_CONFIG_ENHANCEDUI_SUPPORT @@ -4446,7 +4446,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_CREATEFONT: case TOK_HIDEWINDOW: case TOK_ENABLEWINDOW: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_ENHANCEDUI_SUPPORT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_ENHANCEDUI_SUPPORT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//NSIS_CONFIG_ENHANCEDUI_SUPPORT #else//!NSIS_SUPPORT_HWNDS @@ -4460,7 +4460,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_CREATEFONT: case TOK_HIDEWINDOW: case TOK_BRINGTOFRONT: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_HWNDS not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_HWNDS not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_HWNDS case TOK_DELETE: @@ -4468,22 +4468,22 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int a=1; ent.which=EW_DELETEFILE; - if (!stricmp(line.gettoken_str(a),"/REBOOTOK")) + if (!stricmp(line.gettoken_str(a),_T("/REBOOTOK"))) { a++; ent.offsets[1]=DEL_REBOOT; #ifndef NSIS_SUPPORT_MOVEONREBOOT - ERROR_MSG("Error: /REBOOTOK specified, NSIS_SUPPORT_MOVEONREBOOT not defined\n"); + ERROR_MSG(_T("Error: /REBOOTOK specified, NSIS_SUPPORT_MOVEONREBOOT not defined\n")); PRINTHELP() #endif } - else if (line.gettoken_str(1)[0]=='/') + else if (line.gettoken_str(1)[0]==_T('/')) { a=line.getnumtokens(); } if (line.getnumtokens() != a+1) PRINTHELP() ent.offsets[0]=add_string(line.gettoken_str(a)); - SCRIPT_MSG("Delete: %s\"%s\"\n",ent.offsets[1]?"/REBOOTOK ":"",line.gettoken_str(a)); + SCRIPT_MSG(_T("Delete: %s\"%s\"\n"),ent.offsets[1]?_T("/REBOOTOK "):_T(""),line.gettoken_str(a)); DefineInnerLangString(NLF_DEL_FILE); #ifdef NSIS_SUPPORT_MOVEONREBOOT @@ -4492,7 +4492,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } return add_entry(&ent); #else//!NSIS_SUPPORT_DELETE - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_DELETE not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_DELETE not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_DELETE case TOK_RMDIR: @@ -4501,15 +4501,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int a=1; ent.which=EW_RMDIR; ent.offsets[1]=DEL_DIR; - while (line.gettoken_str(a)[0]=='/') + while (line.gettoken_str(a)[0]==_T('/')) { - if (!stricmp(line.gettoken_str(a),"/r")) + if (!stricmp(line.gettoken_str(a),_T("/r"))) { if (a == 3) PRINTHELP(); a++; ent.offsets[1]|=DEL_RECURSE; } - else if (!stricmp(line.gettoken_str(a),"/REBOOTOK")) + else if (!stricmp(line.gettoken_str(a),_T("/REBOOTOK"))) { if (a == 3) PRINTHELP(); a++; @@ -4519,12 +4519,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } if (a < line.getnumtokens() - 1) PRINTHELP(); ent.offsets[0]=add_string(line.gettoken_str(a)); - SCRIPT_MSG("RMDir: "); + SCRIPT_MSG(_T("RMDir: ")); if (a>1) - SCRIPT_MSG("%s ",line.gettoken_str(1)); + SCRIPT_MSG(_T("%s "),line.gettoken_str(1)); if (a>2) - SCRIPT_MSG("%s ",line.gettoken_str(2)); - SCRIPT_MSG("\"%s\"\n",line.gettoken_str(a)); + SCRIPT_MSG(_T("%s "),line.gettoken_str(2)); + SCRIPT_MSG(_T("\"%s\"\n"),line.gettoken_str(a)); DefineInnerLangString(NLF_REMOVE_DIR); DefineInnerLangString(NLF_DEL_FILE); @@ -4534,47 +4534,47 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } return add_entry(&ent); #else//!NSIS_SUPPORT_RMDIR - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_RMDIR not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_RMDIR not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_RMDIR case TOK_RESERVEFILE: case TOK_FILE: #ifdef NSIS_SUPPORT_FILE { - set excluded; + set excluded; int a=1,attrib=0,rec=0,fatal=1; - if (!stricmp(line.gettoken_str(a),"/nonfatal")) { + if (!stricmp(line.gettoken_str(a),_T("/nonfatal"))) { fatal=0; a++; } - if (which_token == TOK_FILE && !stricmp(line.gettoken_str(a),"/a")) + if (which_token == TOK_FILE && !stricmp(line.gettoken_str(a),_T("/a"))) { #ifdef _WIN32 attrib=1; #else - warning_fl("%sFile /a is disabled for non Win32 platforms.",(which_token == TOK_FILE)?"":"Reserve"); + warning_fl(_T("%sFile /a is disabled for non Win32 platforms."),(which_token == TOK_FILE)?_T(""):_T("Reserve")); #endif a++; } - if (!stricmp(line.gettoken_str(a),"/r")) + if (!stricmp(line.gettoken_str(a),_T("/r"))) { rec=1; a++; } - else if (which_token == TOK_FILE && !strnicmp(line.gettoken_str(a),"/oname=",7)) + else if (which_token == TOK_FILE && !strnicmp(line.gettoken_str(a),_T("/oname="),7)) { - char *on=line.gettoken_str(a)+7; + TCHAR *on=line.gettoken_str(a)+7; a++; - if (!*on||line.getnumtokens()!=a+1||strstr(on,"*") || strstr(on,"?")) PRINTHELP() + if (!*on||line.getnumtokens()!=a+1||_tcsstr(on,_T("*")) || _tcsstr(on,_T("?"))) PRINTHELP() - if (on[0]=='"') + if (on[0]==_T('"')) { - ERROR_MSG("%sFile: output name must not begin with a quote, use \"/oname=name with spaces\".\n",(which_token == TOK_FILE)?"":"Reserve",line.gettoken_str(a)); + ERROR_MSG(_T("%sFile: output name must not begin with a quote, use \"/oname=name with spaces\".\n"),(which_token == TOK_FILE)?_T(""):_T("Reserve"),line.gettoken_str(a)); PRINTHELP(); } int tf=0; - char *fn = line.gettoken_str(a); + TCHAR *fn = line.gettoken_str(a); PATH_CONVERT(fn); int v=do_add_file(fn, attrib, 0, &tf, on); if (v != PS_OK) return v; @@ -4583,12 +4583,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (fatal) { - ERROR_MSG("%sFile: \"%s\" -> no files found.\n",(which_token == TOK_FILE)?"":"Reserve",line.gettoken_str(a)); + ERROR_MSG(_T("%sFile: \"%s\" -> no files found.\n"),(which_token == TOK_FILE)?_T(""):_T("Reserve"),line.gettoken_str(a)); PRINTHELP() } else { - warning_fl("%sFile: \"%s\" -> no files found",(which_token == TOK_FILE)?"":"Reserve",line.gettoken_str(a)); + warning_fl(_T("%sFile: \"%s\" -> no files found"),(which_token == TOK_FILE)?_T(""):_T("Reserve"),line.gettoken_str(a)); // workaround for bug #1299100 // add a nop opcode so relative jumps will work as expected @@ -4598,9 +4598,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; } - if (!strnicmp(line.gettoken_str(a),"/x",2)) + if (!strnicmp(line.gettoken_str(a),_T("/x"),2)) { - while (!strnicmp(line.gettoken_str(a),"/x",2)) + while (!strnicmp(line.gettoken_str(a),_T("/x"),2)) { a++; @@ -4611,24 +4611,24 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } } #ifdef _WIN32 - if (line.gettoken_str(a)[0] == '/') PRINTHELP() + if (line.gettoken_str(a)[0] == _T('/')) PRINTHELP() #endif if (line.getnumtokens() no files found.\n",(which_token == TOK_FILE)?"":"Reserve",t); + ERROR_MSG(_T("%sFile: \"%s\" -> no files found.\n"),(which_token == TOK_FILE)?_T(""):_T("Reserve"),t); PRINTHELP(); } else { - warning_fl("%sFile: \"%s\" -> no files found.",(which_token == TOK_FILE)?"":"Reserve",t); + warning_fl(_T("%sFile: \"%s\" -> no files found."),(which_token == TOK_FILE)?_T(""):_T("Reserve"),t); } } } } return PS_OK; #else//!NSIS_SUPPORT_FILE - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_FILE not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_FILE not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_FILE #ifdef NSIS_SUPPORT_COPYFILES @@ -4661,30 +4661,30 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int x; for (x = 0; x < 2; x ++) { - if (!stricmp(line.gettoken_str(a),"/SILENT")) + if (!stricmp(line.gettoken_str(a),_T("/SILENT"))) { a++; ent.offsets[2]&=~FOF_SIMPLEPROGRESS; ent.offsets[2]|=FOF_SILENT; } - else if (!stricmp(line.gettoken_str(a),"/FILESONLY")) + else if (!stricmp(line.gettoken_str(a),_T("/FILESONLY"))) { a++; ent.offsets[2]|=FOF_FILESONLY; } - else if (line.gettoken_str(a)[0]=='/') PRINTHELP() + else if (line.gettoken_str(a)[0]==_T('/')) PRINTHELP() else break; } if (line.getnumtokens() < a+2) PRINTHELP() ent.offsets[0]=add_string(line.gettoken_str(a)); ent.offsets[1]=add_string(line.gettoken_str(a+1)); - string copy_to = string("$(^CopyTo)") + line.gettoken_str(a+1); + tstring copy_to = tstring(_T("$(^CopyTo)")) + line.gettoken_str(a+1); ent.offsets[3]=add_string(copy_to.c_str()); int s; int size_kb=line.gettoken_int(a+2,&s); if (!s && line.gettoken_str(a+2)[0]) PRINTHELP() section_add_size_kb(size_kb); - SCRIPT_MSG("CopyFiles: %s\"%s\" -> \"%s\", size=%iKB\n",ent.offsets[2]&FOF_SILENT?"(silent) ":"", line.gettoken_str(a),line.gettoken_str(a+1),size_kb); + SCRIPT_MSG(_T("CopyFiles: %s\"%s\" -> \"%s\", size=%iKB\n"),ent.offsets[2]&FOF_SILENT?_T("(silent) "):_T(""), line.gettoken_str(a),line.gettoken_str(a+1),size_kb); DefineInnerLangString(NLF_COPY_FAILED); DefineInnerLangString(NLF_COPY_TO); @@ -4692,17 +4692,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return add_entry(&ent); #else//!NSIS_SUPPORT_COPYFILES case TOK_COPYFILES: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_COPYFILES not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_COPYFILES not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_COPYFILES case TOK_SETFILEATTRIBUTES: { - #define MBD(x) {x,#x}, + #define MBD(x) {x,_T(#x)}, struct { int id; - const char *str; + const TCHAR *str; } list[]= { MBD(FILE_ATTRIBUTE_NORMAL) @@ -4712,24 +4712,24 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) MBD(FILE_ATTRIBUTE_READONLY) MBD(FILE_ATTRIBUTE_SYSTEM) MBD(FILE_ATTRIBUTE_TEMPORARY) - {FILE_ATTRIBUTE_NORMAL,"NORMAL"}, - {FILE_ATTRIBUTE_ARCHIVE,"ARCHIVE"}, - {FILE_ATTRIBUTE_HIDDEN,"HIDDEN"}, - {FILE_ATTRIBUTE_OFFLINE,"OFFLINE"}, - {FILE_ATTRIBUTE_READONLY,"READONLY"}, - {FILE_ATTRIBUTE_SYSTEM,"SYSTEM"}, - {FILE_ATTRIBUTE_TEMPORARY,"TEMPORARY"}, - {FILE_ATTRIBUTE_NORMAL,"0"}, + {FILE_ATTRIBUTE_NORMAL,_T("NORMAL")}, + {FILE_ATTRIBUTE_ARCHIVE,_T("ARCHIVE")}, + {FILE_ATTRIBUTE_HIDDEN,_T("HIDDEN")}, + {FILE_ATTRIBUTE_OFFLINE,_T("OFFLINE")}, + {FILE_ATTRIBUTE_READONLY,_T("READONLY")}, + {FILE_ATTRIBUTE_SYSTEM,_T("SYSTEM")}, + {FILE_ATTRIBUTE_TEMPORARY,_T("TEMPORARY")}, + {FILE_ATTRIBUTE_NORMAL,_T("0")}, }; #undef MBD int r=0; int x; - char *p=line.gettoken_str(2); + TCHAR *p=line.gettoken_str(2); while (*p) { - char *np=p; - while (*np && *np != '|') np++; + TCHAR *np=p; + while (*np && *np != _T('|')) np++; if (*np) *np++=0; for (x = 0 ; (unsigned) x < sizeof(list)/sizeof(list[0]) && stricmp(list[x].str,p); x ++); @@ -4749,7 +4749,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { ent.which=EW_SLEEP; ent.offsets[0]=add_string(line.gettoken_str(1)); - SCRIPT_MSG("Sleep: %s ms\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Sleep: %s ms\n"),line.gettoken_str(1)); } return add_entry(&ent); case TOK_IFFILEEXISTS: @@ -4757,32 +4757,32 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[0] = add_string(line.gettoken_str(1)); if (process_jump(line,2,&ent.offsets[1]) || process_jump(line,3,&ent.offsets[2])) PRINTHELP() - SCRIPT_MSG("IfFileExists: \"%s\" ? %s : %s\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); + SCRIPT_MSG(_T("IfFileExists: \"%s\" ? %s : %s\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); return add_entry(&ent); case TOK_QUIT: ent.which=EW_QUIT; - SCRIPT_MSG("Quit\n"); + SCRIPT_MSG(_T("Quit\n")); return add_entry(&ent); case TOK_ABORT: ent.which=EW_ABORT; ent.offsets[0] = add_string(line.gettoken_str(1)); - SCRIPT_MSG("Abort: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Abort: \"%s\"\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_SETDETAILSVIEW: { - int v=line.gettoken_enum(1,"hide\0show\0"); + int v=line.gettoken_enum(1,_T("hide\0show\0")); ent.which=EW_CHDETAILSVIEW; if (v < 0) PRINTHELP() ent.offsets[0] = v?SW_SHOWNA:SW_HIDE; ent.offsets[1] = v?SW_HIDE:SW_SHOWNA; - SCRIPT_MSG("SetDetailsView: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetDetailsView: %s\n"),line.gettoken_str(1)); } return add_entry(&ent); case TOK_SETDETAILSPRINT: { ent.which=EW_SETFLAG; ent.offsets[0]=FLAG_OFFSET(status_update); - int k=line.gettoken_enum(1,"both\0textonly\0listonly\0none\0lastused\0"); + int k=line.gettoken_enum(1,_T("both\0textonly\0listonly\0none\0lastused\0")); if (k<0) PRINTHELP() if (k == 4) { @@ -4796,17 +4796,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) // none 6 ent.offsets[1]=add_intstring(k*2); } - SCRIPT_MSG("SetDetailsPrint: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetDetailsPrint: %s\n"),line.gettoken_str(1)); } return add_entry(&ent); case TOK_SETAUTOCLOSE: { ent.which=EW_SETFLAG; ent.offsets[0]=FLAG_OFFSET(autoclose); - int k=line.gettoken_enum(1,"false\0true\0"); + int k=line.gettoken_enum(1,_T("false\0true\0")); if (k < 0) PRINTHELP() ent.offsets[1]=add_intstring(k); - SCRIPT_MSG("SetAutoClose: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetAutoClose: %s\n"),line.gettoken_str(1)); } return add_entry(&ent); case TOK_IFERRORS: @@ -4815,7 +4815,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) process_jump(line,2,&ent.offsets[1])) PRINTHELP() ent.offsets[2]=FLAG_OFFSET(exec_error); ent.offsets[3]=0;//new value mask - clean error - SCRIPT_MSG("IfErrors ?%s:%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("IfErrors ?%s:%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_IFABORT: ent.which=EW_IFFLAG; @@ -4823,32 +4823,32 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) process_jump(line,2,&ent.offsets[1])) PRINTHELP() ent.offsets[2]=FLAG_OFFSET(abort); ent.offsets[3]=~0;//new value mask - keep flag - SCRIPT_MSG("IfAbort ?%s:%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("IfAbort ?%s:%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_CLEARERRORS: ent.which=EW_SETFLAG; ent.offsets[0]=FLAG_OFFSET(exec_error); ent.offsets[1]=add_intstring(0); - SCRIPT_MSG("ClearErrors\n"); + SCRIPT_MSG(_T("ClearErrors\n")); return add_entry(&ent); case TOK_SETERRORS: ent.which=EW_SETFLAG; ent.offsets[0]=FLAG_OFFSET(exec_error); ent.offsets[1]=add_intstring(1); - SCRIPT_MSG("SetErrors\n"); + SCRIPT_MSG(_T("SetErrors\n")); return add_entry(&ent); case TOK_SETERRORLEVEL: ent.which=EW_SETFLAG; ent.offsets[0]=FLAG_OFFSET(errlvl); ent.offsets[1]=add_string(line.gettoken_str(1)); - SCRIPT_MSG("SetErrorLevel: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetErrorLevel: %s\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_GETERRORLEVEL: ent.which=EW_GETFLAG; ent.offsets[0]=GetUserVarIndex(line, 1); ent.offsets[1]=FLAG_OFFSET(errlvl); if (line.gettoken_str(1)[0] && ent.offsets[0]<0) PRINTHELP() - SCRIPT_MSG("GetErrorLevel: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("GetErrorLevel: %s\n"),line.gettoken_str(1)); return add_entry(&ent); #ifdef NSIS_SUPPORT_STROPTS case TOK_STRLEN: @@ -4856,7 +4856,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[0]=GetUserVarIndex(line, 1); ent.offsets[1]=add_string(line.gettoken_str(2)); if (ent.offsets[0] < 0) PRINTHELP() - SCRIPT_MSG("StrLen %s \"%s\"\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("StrLen %s \"%s\"\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_STRCPY: ent.which=EW_ASSIGNVAR; @@ -4866,7 +4866,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[3]=add_string(line.gettoken_str(4)); if (ent.offsets[0] < 0) PRINTHELP() - SCRIPT_MSG("StrCpy %s \"%s\" (%s) (%s)\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); + SCRIPT_MSG(_T("StrCpy %s \"%s\" (%s) (%s)\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); return add_entry(&ent); case TOK_GETFUNCTIONADDR: ent.which=EW_GETFUNCTIONADDR; @@ -4875,7 +4875,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[2]=0; ent.offsets[3]=0; if (ent.offsets[0] < 0) PRINTHELP() - SCRIPT_MSG("GetFunctionAddress: %s %s",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("GetFunctionAddress: %s %s"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_GETLABELADDR: ent.which=EW_GETLABELADDR; @@ -4883,20 +4883,20 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (ent.offsets[0] < 0 || process_jump(line,2,&ent.offsets[1])) PRINTHELP() ent.offsets[2]=0; ent.offsets[3]=0; - SCRIPT_MSG("GetLabelAddress: %s %s",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("GetLabelAddress: %s %s"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_GETCURRENTADDR: ent.which=EW_ASSIGNVAR; ent.offsets[0]=GetUserVarIndex(line, 1); { - char buf[32]; - wsprintf(buf,"%d",1+(cur_header->blocks[NB_ENTRIES].num)); + TCHAR buf[32]; + wsprintf(buf,_T("%d"),1+(cur_header->blocks[NB_ENTRIES].num)); ent.offsets[1]=add_string(buf); } if (ent.offsets[0] < 0) PRINTHELP() ent.offsets[2]=0; ent.offsets[3]=0; - SCRIPT_MSG("GetCurrentAddress: %s",line.gettoken_str(1)); + SCRIPT_MSG(_T("GetCurrentAddress: %s"),line.gettoken_str(1)); return add_entry(&ent); case TOK_STRCMP: case TOK_STRCMPS: @@ -4906,14 +4906,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[4]=which_token == TOK_STRCMPS; if (process_jump(line,3,&ent.offsets[2]) || process_jump(line,4,&ent.offsets[3])) PRINTHELP() - SCRIPT_MSG("%s \"%s\" \"%s\" equal=%s, nonequal=%s\n",line.gettoken_str(0),line.gettoken_str(1),line.gettoken_str(2), line.gettoken_str(3),line.gettoken_str(4)); + SCRIPT_MSG(_T("%s \"%s\" \"%s\" equal=%s, nonequal=%s\n"),line.gettoken_str(0),line.gettoken_str(1),line.gettoken_str(2), line.gettoken_str(3),line.gettoken_str(4)); return add_entry(&ent); case TOK_GETDLLVERSIONLOCAL: { DWORD low, high; if (!GetDLLVersion(line.gettoken_str(1),high,low)) { - ERROR_MSG("GetDLLVersionLocal: error reading version info from \"%s\"\n",line.gettoken_str(1)); + ERROR_MSG(_T("GetDLLVersionLocal: error reading version info from \"%s\"\n"),line.gettoken_str(1)); return PS_ERROR; } ent.which=EW_ASSIGNVAR; @@ -4929,13 +4929,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[2]=0; ent.offsets[3]=0; if (ent.offsets[0]<0) PRINTHELP() - SCRIPT_MSG("GetDLLVersionLocal: %s (%u,%u)->(%s,%s)\n", + SCRIPT_MSG(_T("GetDLLVersionLocal: %s (%u,%u)->(%s,%s)\n"), line.gettoken_str(1),high,low,line.gettoken_str(2),line.gettoken_str(3)); } return add_entry(&ent); case TOK_GETFILETIMELOCAL: { - char buf[129]; + TCHAR buf[129]; DWORD high=0,low=0; #ifdef _WIN32 int flag=0; @@ -4953,7 +4953,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } if (!flag) { - ERROR_MSG("GetFileTimeLocal: error reading date from \"%s\"\n",line.gettoken_str(1)); + ERROR_MSG(_T("GetFileTimeLocal: error reading date from \"%s\"\n"),line.gettoken_str(1)); return PS_ERROR; } #else @@ -4966,14 +4966,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } else { - ERROR_MSG("GetFileTimeLocal: error reading date from \"%s\"\n",line.gettoken_str(1)); + ERROR_MSG(_T("GetFileTimeLocal: error reading date from \"%s\"\n"),line.gettoken_str(1)); return PS_ERROR; } #endif ent.which=EW_ASSIGNVAR; ent.offsets[0]=GetUserVarIndex(line, 2); - wsprintf(buf,"%u",high); + wsprintf(buf,_T("%u"),high); ent.offsets[1]=add_string(buf); ent.offsets[2]=0; ent.offsets[3]=0; @@ -4981,12 +4981,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) add_entry(&ent); ent.offsets[0]=GetUserVarIndex(line, 3); - wsprintf(buf,"%u",low); + wsprintf(buf,_T("%u"),low); ent.offsets[1]=add_string(buf); ent.offsets[2]=0; ent.offsets[3]=0; if (ent.offsets[0]<0) PRINTHELP() - SCRIPT_MSG("GetFileTimeLocal: %s (%u,%u)->(%s,%s)\n", + SCRIPT_MSG(_T("GetFileTimeLocal: %s (%u,%u)->(%s,%s)\n"), line.gettoken_str(1),high,low,line.gettoken_str(2),line.gettoken_str(3)); } return add_entry(&ent); @@ -5001,34 +5001,34 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_STRCPY: case TOK_STRCMP: case TOK_STRCMPS: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_STROPTS not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_STROPTS not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_STROPTS #ifdef NSIS_SUPPORT_INIFILES case TOK_DELETEINISEC: case TOK_DELETEINISTR: { - const char *vname=""; - const char *space=""; + const TCHAR *vname=_T(""); + const TCHAR *space=_T(""); ent.which=EW_WRITEINI; ent.offsets[0]=add_string(line.gettoken_str(2)); // section name if (line.getnumtokens() > 3) { vname=line.gettoken_str(3); ent.offsets[1]=add_string(vname); // value name - space=" "; + space=_T(" "); } else ent.offsets[1]=0; ent.offsets[2]=0; ent.offsets[3]=add_string(line.gettoken_str(1)); - SCRIPT_MSG("DeleteINI%s: [%s] %s%sin %s\n",*vname?"Str":"Sec", + SCRIPT_MSG(_T("DeleteINI%s: [%s] %s%sin %s\n"),*vname?_T("Str"):_T("Sec"), line.gettoken_str(2),vname,space,line.gettoken_str(1)); } return add_entry(&ent); case TOK_FLUSHINI: ent.which=EW_WRITEINI; ent.offsets[3]=add_string(line.gettoken_str(1)); - SCRIPT_MSG("FlushINI: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("FlushINI: %s\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_WRITEINISTR: ent.which=EW_WRITEINI; @@ -5037,7 +5037,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[2]=add_string(line.gettoken_str(4)); ent.offsets[3]=add_string(line.gettoken_str(1)); ent.offsets[4]=1; // write - SCRIPT_MSG("WriteINIStr: [%s] %s=%s in %s\n", + SCRIPT_MSG(_T("WriteINIStr: [%s] %s=%s in %s\n"), line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4),line.gettoken_str(1)); return add_entry(&ent); case TOK_READINISTR: @@ -5047,7 +5047,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=add_string(line.gettoken_str(3)); ent.offsets[2]=add_string(line.gettoken_str(4)); ent.offsets[3]=add_string(line.gettoken_str(2)); - SCRIPT_MSG("ReadINIStr %s [%s]:%s from %s\n",line.gettoken_str(1),line.gettoken_str(3),line.gettoken_str(4),line.gettoken_str(2)); + SCRIPT_MSG(_T("ReadINIStr %s [%s]:%s from %s\n"),line.gettoken_str(1),line.gettoken_str(3),line.gettoken_str(4),line.gettoken_str(2)); return add_entry(&ent); #else//!NSIS_SUPPORT_INIFILES case TOK_DELETEINISEC: @@ -5055,14 +5055,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_FLUSHINI: case TOK_WRITEINISTR: case TOK_READINISTR: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_INIFILES not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_INIFILES not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_INIFILES case TOK_DETAILPRINT: ent.which=EW_UPDATETEXT; ent.offsets[0]=add_string(line.gettoken_str(1)); ent.offsets[1]=0; - SCRIPT_MSG("DetailPrint: \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("DetailPrint: \"%s\"\n"),line.gettoken_str(1)); return add_entry(&ent); #ifdef NSIS_SUPPORT_FNUTIL case TOK_GETTEMPFILENAME: @@ -5071,22 +5071,22 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (line.getnumtokens() == 3) ent.offsets[1]=add_string(line.gettoken_str(2)); else - ent.offsets[1]=add_string("$TEMP"); + ent.offsets[1]=add_string(_T("$TEMP")); if (ent.offsets[0]<0) PRINTHELP() - SCRIPT_MSG("GetTempFileName -> %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("GetTempFileName -> %s\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_GETFULLPATHNAME: { int a=0; ent.which=EW_GETFULLPATHNAME; - if (line.getnumtokens()==4 && !stricmp(line.gettoken_str(1),"/SHORT")) a++; - else if (line.getnumtokens()==4 || *line.gettoken_str(1)=='/') PRINTHELP() + if (line.getnumtokens()==4 && !stricmp(line.gettoken_str(1),_T("/SHORT"))) a++; + else if (line.getnumtokens()==4 || *line.gettoken_str(1)==_T('/')) PRINTHELP() ent.offsets[0]=add_string(line.gettoken_str(2+a)); ent.offsets[1]=GetUserVarIndex(line, 1+a); ent.offsets[2]=!a; if (ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("GetFullPathName: %s->%s (%d)\n", - line.gettoken_str(2+a),line.gettoken_str(1+a),a?"sfn":"lfn"); + SCRIPT_MSG(_T("GetFullPathName: %s->%s (%d)\n"), + line.gettoken_str(2+a),line.gettoken_str(1+a),a?_T("sfn"):_T("lfn")); } return add_entry(&ent); case TOK_SEARCHPATH: @@ -5094,13 +5094,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[0]=GetUserVarIndex(line, 1); if (ent.offsets[0] < 0) PRINTHELP() ent.offsets[1]=add_string(line.gettoken_str(2)); - SCRIPT_MSG("SearchPath %s %s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SearchPath %s %s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); #else case TOK_SEARCHPATH: case TOK_GETTEMPFILENAME: case TOK_GETFULLPATHNAME: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_FNUTIL not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_FNUTIL not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif case TOK_GETDLLVERSION: @@ -5110,11 +5110,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=GetUserVarIndex(line, 3); ent.offsets[2]=add_string(line.gettoken_str(1)); if (ent.offsets[0]<0 || ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("GetDLLVersion: %s->%s,%s\n", + SCRIPT_MSG(_T("GetDLLVersion: %s->%s,%s\n"), line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); return add_entry(&ent); #else//!NSIS_SUPPORT_GETDLLVERSION - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_GETDLLVERSION not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_GETDLLVERSION not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_GETDLLVERSION case TOK_GETFILETIME: @@ -5124,18 +5124,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=GetUserVarIndex(line, 3); ent.offsets[2]=add_string(line.gettoken_str(1)); if (ent.offsets[0]<0 || ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("GetFileTime: %s->%s,%s\n", + SCRIPT_MSG(_T("GetFileTime: %s->%s,%s\n"), line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); return add_entry(&ent); #else//!NSIS_SUPPORT_GETFILETIME - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_GETFILETIME not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_GETFILETIME not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_GETFILETIME #ifdef NSIS_SUPPORT_INTOPTS case TOK_INTOP: ent.which=EW_INTOP; ent.offsets[0]=GetUserVarIndex(line, 1); - ent.offsets[3]=line.gettoken_enum(3,"+\0-\0*\0/\0|\0&\0^\0!\0||\0&&\0%\0<<\0>>\0~\0"); + ent.offsets[3]=line.gettoken_enum(3,_T("+\0-\0*\0/\0|\0&\0^\0!\0||\0&&\0%\0<<\0>>\0~\0")); if (ent.offsets[0] < 0 || ent.offsets[3] < 0 || ((ent.offsets[3] == 7 || ent.offsets[3] == 13) && line.getnumtokens() > 4)) PRINTHELP() @@ -5143,9 +5143,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (ent.offsets[3] != 7 && ent.offsets[3] != 13) ent.offsets[2]=add_string(line.gettoken_str(4)); if (ent.offsets[3] == 13) { ent.offsets[3]=6; - ent.offsets[2]=add_string("0xFFFFFFFF"); + ent.offsets[2]=add_string(_T("0xFFFFFFFF")); } - SCRIPT_MSG("IntOp: %s=%s%s%s\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); + SCRIPT_MSG(_T("IntOp: %s=%s%s%s\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); return add_entry(&ent); case TOK_INTFMT: ent.which=EW_INTFMT; @@ -5153,7 +5153,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (ent.offsets[0]<0) PRINTHELP() ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[2]=add_string(line.gettoken_str(3)); - SCRIPT_MSG("IntFmt: %s->%s (fmt:%s)\n",line.gettoken_str(3),line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("IntFmt: %s->%s (fmt:%s)\n"),line.gettoken_str(3),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_INTCMP: case TOK_INTCMPU: @@ -5164,7 +5164,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (process_jump(line,3,&ent.offsets[2]) || process_jump(line,4,&ent.offsets[3]) || process_jump(line,5,&ent.offsets[4])) PRINTHELP() - SCRIPT_MSG("%s %s:%s equal=%s, < %s, > %s\n",line.gettoken_str(0), + SCRIPT_MSG(_T("%s %s:%s equal=%s, < %s, > %s\n"),line.gettoken_str(0), line.gettoken_str(1),line.gettoken_str(2), line.gettoken_str(3),line.gettoken_str(4),line.gettoken_str(5)); return add_entry(&ent); #else//!NSIS_SUPPORT_INTOPTS @@ -5172,7 +5172,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_INTCMP: case TOK_INTFMT: case TOK_INTCMPU: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_INTOPTS not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_INTOPTS not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_INTOPTS #ifdef NSIS_SUPPORT_REGISTRYFUNCTIONS @@ -5189,10 +5189,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[3]=add_string(line.gettoken_str(4)); if (which_token == TOK_READREGDWORD) ent.offsets[4]=1; else ent.offsets[4]=0; - if (line.gettoken_str(3)[0] == '\\') - warning_fl("%s: registry path name begins with \'\\\', may cause problems",line.gettoken_str(0)); + if (line.gettoken_str(3)[0] == _T('\\')) + warning_fl(_T("%s: registry path name begins with \'\\\', may cause problems"),line.gettoken_str(0)); - SCRIPT_MSG("%s %s %s\\%s\\%s\n",line.gettoken_str(0), + SCRIPT_MSG(_T("%s %s %s\\%s\\%s\n"),line.gettoken_str(0), line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); } return add_entry(&ent); @@ -5203,10 +5203,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (which_token==TOK_DELETEREGKEY) { ent.offsets[4]=1; - char *s=line.gettoken_str(a); - if (s[0] == '/') + TCHAR *s=line.gettoken_str(a); + if (s[0] == _T('/')) { - if (stricmp(s,"/ifempty")) PRINTHELP() + if (stricmp(s,_T("/ifempty"))) PRINTHELP() a++; ent.offsets[4]=3; } @@ -5219,12 +5219,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=(int)rootkey_tab[k]; ent.offsets[2]=add_string(line.gettoken_str(a+1)); ent.offsets[3]=(which_token==TOK_DELETEREGKEY)?0:add_string(line.gettoken_str(a+2)); - if (line.gettoken_str(a+1)[0] == '\\') - warning_fl("%s: registry path name begins with \'\\\', may cause problems",line.gettoken_str(0)); + if (line.gettoken_str(a+1)[0] == _T('\\')) + warning_fl(_T("%s: registry path name begins with \'\\\', may cause problems"),line.gettoken_str(0)); if (which_token==TOK_DELETEREGKEY) - SCRIPT_MSG("DeleteRegKey: %s\\%s\n",line.gettoken_str(a),line.gettoken_str(a+1)); + SCRIPT_MSG(_T("DeleteRegKey: %s\\%s\n"),line.gettoken_str(a),line.gettoken_str(a+1)); else - SCRIPT_MSG("DeleteRegValue: %s\\%s\\%s\n",line.gettoken_str(a),line.gettoken_str(a+1),line.gettoken_str(a+2)); + SCRIPT_MSG(_T("DeleteRegValue: %s\\%s\\%s\n"),line.gettoken_str(a),line.gettoken_str(a+1),line.gettoken_str(a+2)); } return add_entry(&ent); case TOK_WRITEREGSTR: @@ -5238,12 +5238,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.which=EW_WRITEREG; ent.offsets[0]=(int)rootkey_tab[k]; ent.offsets[1]=add_string(line.gettoken_str(2)); - if (line.gettoken_str(2)[0] == '\\') - warning_fl("%s: registry path name begins with \'\\\', may cause problems",line.gettoken_str(0)); + if (line.gettoken_str(2)[0] == _T('\\')) + warning_fl(_T("%s: registry path name begins with \'\\\', may cause problems"),line.gettoken_str(0)); ent.offsets[2]=add_string(line.gettoken_str(3)); if (which_token == TOK_WRITEREGSTR || which_token == TOK_WRITEREGEXPANDSTR) { - SCRIPT_MSG("%s: %s\\%s\\%s=%s\n", + SCRIPT_MSG(_T("%s: %s\\%s\\%s=%s\n"), line.gettoken_str(0),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); ent.offsets[3]=add_string(line.gettoken_str(4)); ent.offsets[4]=ent.offsets[5]=REG_SZ; @@ -5255,33 +5255,33 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (which_token == TOK_WRITEREGBIN) { char data[3*NSIS_MAX_STRLEN]; - char *p=line.gettoken_str(4); + TCHAR *p=line.gettoken_str(4); int data_len=0; while (*p) { int c; int a,b; a=*p; - if (a >= '0' && a <= '9') a-='0'; - else if (a >= 'a' && a <= 'f') a-='a'-10; - else if (a >= 'A' && a <= 'F') a-='A'-10; + if (a >= _T('0') && a <= _T('9')) a-=_T('0'); + else if (a >= _T('a') && a <= _T('f')) a-=_T('a')-10; + else if (a >= _T('A') && a <= _T('F')) a-=_T('A')-10; else break; b=*++p; - if (b >= '0' && b <= '9') b-='0'; - else if (b >= 'a' && b <= 'f') b-='a'-10; - else if (b >= 'A' && b <= 'F') b-='A'-10; + if (b >= _T('0') && b <= _T('9')) b-=_T('0'); + else if (b >= _T('a') && b <= _T('f')) b-=_T('a')-10; + else if (b >= _T('A') && b <= _T('F')) b-=_T('A')-10; else break; p++; c=(a<<4)|b; if (data_len >= 3*NSIS_MAX_STRLEN) { - ERROR_MSG("WriteRegBin: %d bytes of data exceeded\n",3*NSIS_MAX_STRLEN); + ERROR_MSG(_T("WriteRegBin: %d bytes of data exceeded\n"),3*NSIS_MAX_STRLEN); return PS_ERROR; } data[data_len++]=c; } if (*p) PRINTHELP() - SCRIPT_MSG("WriteRegBin: %s\\%s\\%s=%s\n", + SCRIPT_MSG(_T("WriteRegBin: %s\\%s\\%s=%s\n"), line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); ent.offsets[3]=add_db_data(data,data_len); if (ent.offsets[3] < 0) return PS_ERROR; @@ -5292,7 +5292,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[3]=add_string(line.gettoken_str(4)); ent.offsets[4]=ent.offsets[5]=REG_DWORD; - SCRIPT_MSG("WriteRegDWORD: %s\\%s\\%s=%s\n", + SCRIPT_MSG(_T("WriteRegDWORD: %s\\%s\\%s=%s\n"), line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); } } @@ -5309,8 +5309,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[2]=add_string(line.gettoken_str(3)); ent.offsets[3]=add_string(line.gettoken_str(4)); ent.offsets[4]=which_token == TOK_ENUMREGKEY; - if (line.gettoken_str(3)[0] == '\\') warning_fl("%s: registry path name begins with \'\\\', may cause problems",line.gettoken_str(0)); - SCRIPT_MSG("%s %s %s\\%s\\%s\n",which_token == TOK_ENUMREGKEY ? "EnumRegKey" : "EnumRegValue", + if (line.gettoken_str(3)[0] == _T('\\')) warning_fl(_T("%s: registry path name begins with \'\\\', may cause problems"),line.gettoken_str(0)); + SCRIPT_MSG(_T("%s %s %s\\%s\\%s\n"),which_token == TOK_ENUMREGKEY ? _T("EnumRegKey") : _T("EnumRegValue"), line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); } return add_entry(&ent); @@ -5325,7 +5325,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_WRITEREGDWORD: case TOK_ENUMREGKEY: case TOK_ENUMREGVAL: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_REGISTRYFUNCTIONS not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_REGISTRYFUNCTIONS not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_REGISTRYFUNCTIONS #ifdef NSIS_SUPPORT_STACK @@ -5342,13 +5342,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } if (save>=0) { - SCRIPT_MSG("Exch(%s,0)\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Exch(%s,0)\n"),line.gettoken_str(1)); ent.offsets[0]=add_string(line.gettoken_str(1)); ent.offsets[1]=0; ent.offsets[2]=0; add_entry(&ent); } - else SCRIPT_MSG("Exch(st(%d),0)\n",swapitem); + else SCRIPT_MSG(_T("Exch(st(%d),0)\n"),swapitem); ent.offsets[0]=0; ent.offsets[1]=0; @@ -5369,20 +5369,20 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.which=EW_PUSHPOP; ent.offsets[0]=add_string(line.gettoken_str(1)); ent.offsets[1]=0; - SCRIPT_MSG("Push: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Push: %s\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_POP: ent.which=EW_PUSHPOP; ent.offsets[0]=GetUserVarIndex(line, 1); ent.offsets[1]=1; if (ent.offsets[0] < 0) PRINTHELP() - SCRIPT_MSG("Pop: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("Pop: %s\n"),line.gettoken_str(1)); return add_entry(&ent); #else//!NSIS_SUPPORT_STACK case TOK_POP: case TOK_PUSH: case TOK_EXCH: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_STACK not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_STACK not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_STACK #ifdef NSIS_SUPPORT_ENVIRONMENT @@ -5390,15 +5390,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.which=EW_READENVSTR; ent.offsets[0]=GetUserVarIndex(line, 1); { - char str[NSIS_MAX_STRLEN]; - strcpy(str, "%"); + TCHAR str[NSIS_MAX_STRLEN]; + strcpy(str, _T("%")); strcat(str, line.gettoken_str(2)); - strcat(str, "%"); + strcat(str, _T("%")); ent.offsets[1]=add_string(str); - if (ent.offsets[0] < 0 || strlen(line.gettoken_str(2))<1) PRINTHELP() + if (ent.offsets[0] < 0 || _tcsclen(line.gettoken_str(2))<1) PRINTHELP() } ent.offsets[2]=1; - SCRIPT_MSG("ReadEnvStr: %s->%s\n",line.gettoken_str(2),line.gettoken_str(1)); + SCRIPT_MSG(_T("ReadEnvStr: %s->%s\n"),line.gettoken_str(2),line.gettoken_str(1)); return add_entry(&ent); case TOK_EXPANDENVSTRS: ent.which=EW_READENVSTR; @@ -5406,12 +5406,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[2]=0; if (ent.offsets[0] < 0) PRINTHELP() - SCRIPT_MSG("ExpandEnvStrings: %s->%s\n",line.gettoken_str(2),line.gettoken_str(1)); + SCRIPT_MSG(_T("ExpandEnvStrings: %s->%s\n"),line.gettoken_str(2),line.gettoken_str(1)); return add_entry(&ent); #else//!NSIS_SUPPORT_ENVIRONMENT case TOK_EXPANDENVSTRS: case TOK_READENVSTR: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_ENVIRONMENT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_ENVIRONMENT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_ENVIRONMENT #ifdef NSIS_SUPPORT_FINDFIRST @@ -5421,26 +5421,26 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=GetUserVarIndex(line, 1); // handleout ent.offsets[2]=add_string(line.gettoken_str(3)); // filespec if (ent.offsets[0] < 0 || ent.offsets[1] < 0) PRINTHELP() - SCRIPT_MSG("FindFirst: spec=\"%s\" handle=%s output=%s\n",line.gettoken_str(3),line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("FindFirst: spec=\"%s\" handle=%s output=%s\n"),line.gettoken_str(3),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_FINDNEXT: ent.which=EW_FINDNEXT; ent.offsets[0]=GetUserVarIndex(line, 2); ent.offsets[1]=GetUserVarIndex(line, 1); if (ent.offsets[0] < 0 || ent.offsets[1] < 0) PRINTHELP() - SCRIPT_MSG("FindNext: handle=%s output=%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("FindNext: handle=%s output=%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_FINDCLOSE: ent.which=EW_FINDCLOSE; ent.offsets[0]=GetUserVarIndex(line, 1); if (ent.offsets[0] < 0) PRINTHELP() - SCRIPT_MSG("FindClose: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("FindClose: %s\n"),line.gettoken_str(1)); return add_entry(&ent); #else//!NSIS_SUPPORT_FINDFIRST case TOK_FINDCLOSE: case TOK_FINDNEXT: case TOK_FINDFIRST: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_FINDFIRST not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_FINDFIRST not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_FINDFIRST @@ -5453,17 +5453,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[0]=GetUserVarIndex(line, 1); // file handle ent.offsets[3]=add_string(line.gettoken_str(2)); ent.offsets[1]=0; //openmode - if (!stricmp(line.gettoken_str(3),"r")) + if (!stricmp(line.gettoken_str(3),_T("r"))) { ent.offsets[1]=GENERIC_READ; ent.offsets[2]=OPEN_EXISTING; } - else if (!stricmp(line.gettoken_str(3),"w")) + else if (!stricmp(line.gettoken_str(3),_T("w"))) { ent.offsets[1]=GENERIC_WRITE; ent.offsets[2]=CREATE_ALWAYS; } - else if (!stricmp(line.gettoken_str(3),"a")) + else if (!stricmp(line.gettoken_str(3),_T("a"))) { ent.offsets[1]=GENERIC_WRITE|GENERIC_READ; ent.offsets[2]=OPEN_ALWAYS; @@ -5471,13 +5471,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (ent.offsets[0] < 0 || !ent.offsets[1]) PRINTHELP() } - SCRIPT_MSG("FileOpen: %s as %s -> %s\n",line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(1)); + SCRIPT_MSG(_T("FileOpen: %s as %s -> %s\n"),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(1)); return add_entry(&ent); case TOK_FILECLOSE: ent.which=EW_FCLOSE; ent.offsets[0]=GetUserVarIndex(line, 1); // file handle if (ent.offsets[0] < 0) PRINTHELP() - SCRIPT_MSG("FileClose: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("FileClose: %s\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_FILEREAD: ent.which=EW_FGETS; @@ -5488,23 +5488,23 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else ent.offsets[2]=add_intstring(NSIS_MAX_STRLEN-1); if (ent.offsets[0]<0 || ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("FileRead: %s->%s (max:%s)\n",line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); + SCRIPT_MSG(_T("FileRead: %s->%s (max:%s)\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3)); return add_entry(&ent); case TOK_FILEWRITE: ent.which=EW_FPUTS; ent.offsets[0]=GetUserVarIndex(line, 1); // file handle ent.offsets[1]=add_string(line.gettoken_str(2)); if (ent.offsets[0]<0) PRINTHELP() - SCRIPT_MSG("FileWrite: %s->%s\n",line.gettoken_str(2),line.gettoken_str(1)); + SCRIPT_MSG(_T("FileWrite: %s->%s\n"),line.gettoken_str(2),line.gettoken_str(1)); return add_entry(&ent); case TOK_FILEREADBYTE: ent.which=EW_FGETS; ent.offsets[0]=GetUserVarIndex(line, 1); // file handle ent.offsets[1]=GetUserVarIndex(line, 2); // output string - ent.offsets[2]=add_string("1"); + ent.offsets[2]=add_string(_T("1")); ent.offsets[3]=1; if (ent.offsets[0]<0 || ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("FileReadByte: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("FileReadByte: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_FILEWRITEBYTE: ent.which=EW_FPUTS; @@ -5512,13 +5512,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[2]=1; if (ent.offsets[0]<0) PRINTHELP() - SCRIPT_MSG("FileWriteByte: %s->%s\n",line.gettoken_str(2),line.gettoken_str(1)); + SCRIPT_MSG(_T("FileWriteByte: %s->%s\n"),line.gettoken_str(2),line.gettoken_str(1)); return add_entry(&ent); case TOK_FILESEEK: { - const char *modestr; + const TCHAR *modestr; int tab[3]={FILE_BEGIN,FILE_CURRENT,FILE_END}; - int mode=line.gettoken_enum(3,"SET\0CUR\0END\0"); + int mode=line.gettoken_enum(3,_T("SET\0CUR\0END\0")); ent.which=EW_FSEEK; ent.offsets[0]=GetUserVarIndex(line, 1); ent.offsets[1]=GetUserVarIndex(line, 4); @@ -5527,13 +5527,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (mode<0 && !line.gettoken_str(3)[0]) { mode=0; - modestr="SET"; + modestr=_T("SET"); } else modestr=line.gettoken_str(3); if (mode<0 || ent.offsets[0] < 0 || (ent.offsets[1]<0 && line.gettoken_str(4)[0])) PRINTHELP() ent.offsets[3]=tab[mode]; - SCRIPT_MSG("FileSeek: fp=%s, ofs=%s, mode=%s, output=%s\n", + SCRIPT_MSG(_T("FileSeek: fp=%s, ofs=%s, mode=%s, output=%s\n"), line.gettoken_str(1), line.gettoken_str(2), modestr, @@ -5549,7 +5549,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_FILEWRITE: case TOK_FILEREADBYTE: case TOK_FILEWRITEBYTE: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_FILEFUNCTIONS not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_FILEFUNCTIONS not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_FILEFUNCTIONS @@ -5562,7 +5562,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ret = add_entry_direct(EW_QUIT); if (ret != PS_OK) return ret; - SCRIPT_MSG("Reboot! (WOW)\n"); + SCRIPT_MSG(_T("Reboot! (WOW)\n")); DefineInnerLangString(NLF_INST_CORRUPTED); } @@ -5573,13 +5573,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) process_jump(line,2,&ent.offsets[1])) PRINTHELP() ent.offsets[2]=FLAG_OFFSET(exec_reboot); ent.offsets[3]=~0;//new value mask - keep flag - SCRIPT_MSG("IfRebootFlag ?%s:%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("IfRebootFlag ?%s:%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SETREBOOTFLAG: { ent.which=EW_SETFLAG; ent.offsets[0]=FLAG_OFFSET(exec_reboot); - int k=line.gettoken_enum(1,"false\0true\0"); + int k=line.gettoken_enum(1,_T("false\0true\0")); if (k < 0) PRINTHELP() ent.offsets[1]=add_intstring(k); } @@ -5588,29 +5588,29 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_REBOOT: case TOK_IFREBOOTFLAG: case TOK_SETREBOOTFLAG: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_REBOOT not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_REBOOT not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_REBOOT #ifdef NSIS_CONFIG_LOG case TOK_LOGSET: ent.which=EW_LOG; ent.offsets[0]=1; - ent.offsets[1]=line.gettoken_enum(1,"off\0on\0"); + ent.offsets[1]=line.gettoken_enum(1,_T("off\0on\0")); if (ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("LogSet: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("LogSet: %s\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_LOGTEXT: ent.which=EW_LOG; ent.offsets[0]=0; ent.offsets[1]=add_string(line.gettoken_str(1)); - SCRIPT_MSG("LogText \"%s\"\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("LogText \"%s\"\n"),line.gettoken_str(1)); return add_entry(&ent); #else//!NSIS_CONFIG_LOG case TOK_LOGSET: case TOK_LOGTEXT: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_LOG not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_LOG not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_CONFIG_LOG #ifdef NSIS_CONFIG_COMPONENTPAGE @@ -5619,7 +5619,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[0]=add_string(line.gettoken_str(1)); ent.offsets[2]=SECTION_FIELD_SET(name_ptr); ent.offsets[4]=add_string(line.gettoken_str(2)); - SCRIPT_MSG("SectionSetText: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SectionSetText: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SECTIONGETTEXT: ent.which=EW_SECTIONSET; @@ -5627,7 +5627,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=GetUserVarIndex(line, 2); ent.offsets[2]=SECTION_FIELD_GET(name_ptr); if (line.gettoken_str(2)[0] && ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("SectionGetText: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SectionGetText: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SECTIONSETFLAGS: ent.which=EW_SECTIONSET; @@ -5635,7 +5635,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[2]=SECTION_FIELD_SET(flags); ent.offsets[3]=1; - SCRIPT_MSG("SectionSetFlags: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SectionSetFlags: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SECTIONGETFLAGS: ent.which=EW_SECTIONSET; @@ -5643,14 +5643,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=GetUserVarIndex(line, 2); ent.offsets[2]=SECTION_FIELD_GET(flags); if (line.gettoken_str(2)[0] && ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("SectionGetFlags: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SectionGetFlags: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_INSTTYPESETTEXT: ent.which=EW_INSTTYPESET; ent.offsets[0]=add_string(line.gettoken_str(1)); ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[2]=1; - SCRIPT_MSG("InstTypeSetText: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("InstTypeSetText: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_INSTTYPEGETTEXT: ent.which=EW_INSTTYPESET; @@ -5658,14 +5658,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=GetUserVarIndex(line, 2); ent.offsets[2]=0; if (line.gettoken_str(1)[0] && ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("InstTypeGetText: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("InstTypeGetText: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SECTIONSETINSTTYPES: ent.which=EW_SECTIONSET; ent.offsets[0]=add_string(line.gettoken_str(1)); ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[2]=SECTION_FIELD_SET(install_types); - SCRIPT_MSG("SectionSetInstTypes: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SectionSetInstTypes: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SECTIONGETINSTTYPES: ent.which=EW_SECTIONSET; @@ -5673,14 +5673,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=GetUserVarIndex(line, 2); ent.offsets[2]=SECTION_FIELD_GET(install_types); if (line.gettoken_str(2)[0] && ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("SectionGetInstTypes: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SectionGetInstTypes: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SECTIONSETSIZE: ent.which=EW_SECTIONSET; ent.offsets[0]=add_string(line.gettoken_str(1)); ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[2]=SECTION_FIELD_SET(size_kb); - SCRIPT_MSG("SectionSetSize: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SectionSetSize: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SECTIONGETSIZE: ent.which=EW_SECTIONSET; @@ -5688,7 +5688,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=GetUserVarIndex(line, 2); ent.offsets[2]=SECTION_FIELD_GET(size_kb); if (line.gettoken_str(2)[0] && ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("SectionGetSize: %s->%s\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG(_T("SectionGetSize: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_SETCURINSTTYPE: ent.which=EW_INSTTYPESET; @@ -5696,7 +5696,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=0; ent.offsets[2]=1; ent.offsets[3]=1; - SCRIPT_MSG("SetCurInstType: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("SetCurInstType: %s\n"),line.gettoken_str(1)); return add_entry(&ent); case TOK_GETCURINSTTYPE: ent.which=EW_INSTTYPESET; @@ -5705,7 +5705,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[2]=0; ent.offsets[3]=1; if (line.gettoken_str(1)[0] && ent.offsets[1]<0) PRINTHELP() - SCRIPT_MSG("GetCurInstType: %s\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("GetCurInstType: %s\n"),line.gettoken_str(1)); return add_entry(&ent); #else//!NSIS_CONFIG_COMPONENTPAGE case TOK_SECTIONSETTEXT: @@ -5718,44 +5718,44 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_SECTIONGETINSTTYPES: case TOK_SETCURINSTTYPE: case TOK_GETCURINSTTYPE: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_COMPONENTPAGE not defined.\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_COMPONENTPAGE not defined.\n"), line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT case TOK_SETBRANDINGIMAGE: { - SCRIPT_MSG("SetBrandingImage: "); + SCRIPT_MSG(_T("SetBrandingImage: ")); if (!branding_image_found) { - ERROR_MSG("\nError: no branding image found in chosen UI!\n"); + ERROR_MSG(_T("\nError: no branding image found in chosen UI!\n")); return PS_ERROR; } ent.which=EW_SETBRANDINGIMAGE; for (int i = 1; i < line.getnumtokens(); i++) - if (!strnicmp(line.gettoken_str(i),"/IMGID=",7)) { - ent.offsets[1]=atoi(line.gettoken_str(i)+7); - SCRIPT_MSG("/IMGID=%d ",ent.offsets[1]); + if (!strnicmp(line.gettoken_str(i),_T("/IMGID="),7)) { + ent.offsets[1]=_ttoi(line.gettoken_str(i)+7); + SCRIPT_MSG(_T("/IMGID=%d "),ent.offsets[1]); } - else if (!stricmp(line.gettoken_str(i),"/RESIZETOFIT")) { + else if (!stricmp(line.gettoken_str(i),_T("/RESIZETOFIT"))) { ent.offsets[2]=1; // must be 1 or 0 - SCRIPT_MSG("/RESIZETOFIT "); + SCRIPT_MSG(_T("/RESIZETOFIT ")); } else if (!ent.offsets[0]) { ent.offsets[0]=add_string(line.gettoken_str(i)); - SCRIPT_MSG("\"%s\" ", line.gettoken_str(i)); + SCRIPT_MSG(_T("\"%s\" "), line.gettoken_str(i)); } else { - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); PRINTHELP(); } if (!ent.offsets[1]) ent.offsets[1]=branding_image_id; - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); } return add_entry(&ent); #else//NSIS_CONFIG_ENHANCEDUI_SUPPORT case TOK_SETBRANDINGIMAGE: - ERROR_MSG("Error: %s specified, NSIS_CONFIG_ENHANCEDUI_SUPPORT not defined.\n",line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_ENHANCEDUI_SUPPORT not defined.\n"),line.gettoken_str(0)); return PS_ERROR; #endif//!NSIS_SUPPORT_CREATEFONT @@ -5764,7 +5764,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int a=1; - if (!strcmpi(line.gettoken_str(1),"/GLOBAL")) + if (!strcmpi(line.gettoken_str(1),_T("/GLOBAL"))) { a++; } @@ -5777,12 +5777,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (a==1) { - ERROR_MSG("Var: currently, only global variables can be defined.\n"); + ERROR_MSG(_T("Var: currently, only global variables can be defined.\n")); PRINTHELP(); } } - SCRIPT_MSG("Var: \"%s\"\n",line.gettoken_str(a)); + SCRIPT_MSG(_T("Var: \"%s\"\n"),line.gettoken_str(a)); int res = DeclaredUserVar(line.gettoken_str(a)); if (res != PS_OK) @@ -5797,29 +5797,29 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { LANGID LangID=0; int a = 1; - if (!strnicmp(line.gettoken_str(a),"/LANG=",6)) - LangID=atoi(line.gettoken_str(a++)+6); + if (!strnicmp(line.gettoken_str(a),_T("/LANG="),6)) + LangID=_ttoi(line.gettoken_str(a++)+6); if (line.getnumtokens()!=a+2) PRINTHELP(); - char *pKey = line.gettoken_str(a); - char *pValue = line.gettoken_str(a+1); + TCHAR *pKey = line.gettoken_str(a); + TCHAR *pValue = line.gettoken_str(a+1); if ( !(*pKey) ) { - ERROR_MSG("Error: empty name for version info key!\n"); + ERROR_MSG(_T("Error: empty name for version info key!\n")); return PS_ERROR; } else { - SCRIPT_MSG("%s: \"%s\" \"%s\"\n", line.gettoken_str(0), line.gettoken_str(a), line.gettoken_str(a+1)); + SCRIPT_MSG(_T("%s: \"%s\" \"%s\"\n"), line.gettoken_str(0), line.gettoken_str(a), line.gettoken_str(a+1)); LANGID lReaded = LangID; if ( a > 1 && lReaded == 0 ) - warning_fl("%s: %s language not loaded, using default \"1033-English\"", line.gettoken_str(0), line.gettoken_str(1)); + warning_fl(_T("%s: %s language not loaded, using default \"1033-English\""), line.gettoken_str(0), line.gettoken_str(1)); unsigned int codepage; - const char *lang_name = GetLangNameAndCP(LangID, &codepage); + const TCHAR *lang_name = GetLangNameAndCP(LangID, &codepage); if ( rVersionInfo.SetKeyValue(LangID, codepage, pKey, pValue) ) { - ERROR_MSG("%s: \"%s\" \"%04d-%s\" already defined!\n",line.gettoken_str(0), line.gettoken_str(2), LangID, lang_name); + ERROR_MSG(_T("%s: \"%s\" \"%04d-%s\" already defined!\n"),line.gettoken_str(0), line.gettoken_str(2), LangID, lang_name); return PS_ERROR; } @@ -5829,16 +5829,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_VI_SETPRODUCTVERSION: if ( version_product_v[0] ) { - ERROR_MSG("Error: %s already defined!\n", line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s already defined!\n"), line.gettoken_str(0)); return PS_ERROR; } - strcpy(version_product_v, line.gettoken_str(1)); + _tcscpy(version_product_v, line.gettoken_str(1)); return PS_OK; #else case TOK_VI_ADDKEY: case TOK_VI_SETPRODUCTVERSION: - ERROR_MSG("Error: %s specified, NSIS_SUPPORT_VERSION_INFO not defined.\n",line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_VERSION_INFO not defined.\n"),line.gettoken_str(0)); return PS_ERROR; #endif @@ -5851,8 +5851,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (line.getnumtokens() == 2) { - SCRIPT_MSG("PluginDir: \"%s\"\n",line.gettoken_str(1)); - char *path = line.gettoken_str(1); + SCRIPT_MSG(_T("PluginDir: \"%s\"\n"),line.gettoken_str(1)); + TCHAR *path = line.gettoken_str(1); PATH_CONVERT(path); m_plugins.FindCommands(path, display_info?true:false); return PS_OK; @@ -5863,8 +5863,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int ret; - const string command = m_plugins.NormalizedCommand(line.gettoken_str(0)); - const string dllPath = m_plugins.GetPluginPath(command); + const tstring command = m_plugins.NormalizedCommand(line.gettoken_str(0)); + const tstring dllPath = m_plugins.GetPluginPath(command); int data_handle = m_plugins.GetPluginHandle(uninstall_mode?true:false, command); if (uninstall_mode) uninst_plugin_used = true; @@ -5872,16 +5872,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) // Initialize $PLUGINSDIR ent.which=EW_CALL; - ent.offsets[0]=ns_func.add(uninstall_mode?"un.Initialize_____Plugins":"Initialize_____Plugins",0); + ent.offsets[0]=ns_func.add(uninstall_mode?_T("un.Initialize_____Plugins"):_T("Initialize_____Plugins"),0); ret=add_entry(&ent); if (ret != PS_OK) { return ret; } // DLL name on the user machine - char tempDLL[NSIS_MAX_STRLEN]; - string dllName = get_file_name(dllPath); - wsprintf(tempDLL, "$PLUGINSDIR\\%s", dllName.c_str()); + TCHAR tempDLL[NSIS_MAX_STRLEN]; + tstring dllName = get_file_name(dllPath); + wsprintf(tempDLL, _T("$PLUGINSDIR\\%s"), dllName.c_str()); // Add the DLL to the installer if (data_handle == -1) @@ -5933,12 +5933,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } // Call the DLL - string funcname = get_string_suffix(command, "::"); - SCRIPT_MSG("Plugin Command: %s",funcname.c_str()); + tstring funcname = get_string_suffix(command, _T("::")); + SCRIPT_MSG(_T("Plugin Command: %s"),funcname.c_str()); int i = 1; int nounload = 0; - if (!strcmpi(line.gettoken_str(i), "/NOUNLOAD")) { + if (!strcmpi(line.gettoken_str(i), _T("/NOUNLOAD"))) { i++; nounload++; } @@ -5951,18 +5951,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int w=parmst + (line.getnumtokens()-i - 1); ent.which=EW_PUSHPOP; ent.offsets[0]=add_string(line.gettoken_str(w)); - if (!strcmpi(line.gettoken_str(w), "/NOUNLOAD")) nounloadmisused=1; + if (!strcmpi(line.gettoken_str(w), _T("/NOUNLOAD"))) nounloadmisused=1; ent.offsets[1]=0; ent.offsets[2]=0; ret=add_entry(&ent); if (ret != PS_OK) { return ret; } - SCRIPT_MSG(" %s",line.gettoken_str(i)); + SCRIPT_MSG(_T(" %s"),line.gettoken_str(i)); } - SCRIPT_MSG("\n"); + SCRIPT_MSG(_T("\n")); if (nounloadmisused) - warning_fl("/NOUNLOAD must come first before any plugin parameter. Unless the plugin you are trying to use has a parameter /NOUNLOAD, you are doing something wrong"); + warning_fl(_T("/NOUNLOAD must come first before any plugin parameter. Unless the plugin you are trying to use has a parameter /NOUNLOAD, you are doing something wrong")); // next, call it ent.which=EW_REGISTERDLL; @@ -5986,12 +5986,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_INITPLUGINSDIR: { int ret; - SCRIPT_MSG("%s\n",line.gettoken_str(0)); + SCRIPT_MSG(_T("%s\n"),line.gettoken_str(0)); if (uninstall_mode) uninst_plugin_used = true; else plugin_used = true; // Call [un.]Initialize_____Plugins ent.which=EW_CALL; - ent.offsets[0]=ns_func.add(uninstall_mode?"un.Initialize_____Plugins":"Initialize_____Plugins",0); + ent.offsets[0]=ns_func.add(uninstall_mode?_T("un.Initialize_____Plugins"):_T("Initialize_____Plugins"),0); ret=add_entry(&ent); if (ret != PS_OK) return ret; // SetDetailsPrint lastused @@ -6004,23 +6004,23 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK__PLUGINCOMMAND: case TOK_INITPLUGINSDIR: { - ERROR_MSG("Error: %s specified, NSIS_CONFIG_PLUGIN_SUPPORT not defined.\n",line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_CONFIG_PLUGIN_SUPPORT not defined.\n"),line.gettoken_str(0)); } return PS_ERROR; #endif// NSIS_CONFIG_PLUGIN_SUPPORT #ifdef NSIS_LOCKWINDOW_SUPPORT case TOK_LOCKWINDOW: - SCRIPT_MSG("LockWindow: lock state=%d\n",line.gettoken_str(1)); + SCRIPT_MSG(_T("LockWindow: lock state=%d\n"),line.gettoken_str(1)); ent.which=EW_LOCKWINDOW; - ent.offsets[0]=line.gettoken_enum(1,"on\0off\0"); + ent.offsets[0]=line.gettoken_enum(1,_T("on\0off\0")); if (ent.offsets[0] == -1) PRINTHELP(); return add_entry(&ent); #else case TOK_LOCKWINDOW: { - ERROR_MSG("Error: %s specified, NSIS_LOCKWINDOW_SUPPORT not defined.\n",line.gettoken_str(0)); + ERROR_MSG(_T("Error: %s specified, NSIS_LOCKWINDOW_SUPPORT not defined.\n"),line.gettoken_str(0)); } return PS_ERROR; #endif // NSIS_LOCKWINDOW_SUPPORT @@ -6028,35 +6028,35 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) default: break; } - ERROR_MSG("Error: doCommand: Invalid token \"%s\".\n",line.gettoken_str(0)); + ERROR_MSG(_T("Error: doCommand: Invalid token \"%s\".\n"),line.gettoken_str(0)); return PS_ERROR; } #ifdef NSIS_SUPPORT_FILE -int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total_files, const char *name_override, int generatecode, int *data_handle, const set& excluded, const string& basedir, bool dir_created) +int CEXEBuild::do_add_file(const TCHAR *lgss, int attrib, int recurse, int *total_files, const TCHAR *name_override, int generatecode, int *data_handle, const set& excluded, const tstring& basedir, bool dir_created) { assert(!name_override || !recurse); - string dir = get_dir_name(lgss); - string spec; + tstring dir = get_dir_name(lgss); + tstring spec; if (dir == lgss) { - dir = "."; + dir = _T("."); spec = lgss; } else { - spec = string(lgss).substr(dir.length() + 1, string::npos); + spec = tstring(lgss).substr(dir.length() + 1, tstring::npos); } - if (spec == "") { - spec = "*"; + if (spec == _T("")) { + spec = _T("*"); } - if (basedir == "") { + if (basedir == _T("")) { dir_created = true; if (recurse) { // save $OUTDIR into $_OUTDIR [StrCpy $_OUTDIR $OUTDIR] - if (add_entry_direct(EW_ASSIGNVAR, m_UserVarNames.get("_OUTDIR"), add_string("$OUTDIR")) != PS_OK) { + if (add_entry_direct(EW_ASSIGNVAR, m_UserVarNames.get(_T("_OUTDIR")), add_string(_T("$OUTDIR"))) != PS_OK) { return PS_ERROR; } } @@ -6075,7 +6075,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total continue; if (!dir_created && generatecode) { - SCRIPT_MSG("%sFile: Descending to: \"%s\"\n", generatecode ? "" : "Reserve", dir.c_str()); + SCRIPT_MSG(_T("%sFile: Descending to: \"%s\"\n"), generatecode ? _T("") : _T("Reserve"), dir.c_str()); if (do_add_file_create_dir(dir, basedir, attrib) != PS_OK) { return PS_ERROR; @@ -6100,32 +6100,32 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total dirs_itr != dr->dirs().end(); dirs_itr++) { - string new_dir; + tstring new_dir; bool created = false; - if (basedir == "") { + if (basedir == _T("")) { new_dir = *dirs_itr; } else { - new_dir = basedir + '\\' + *dirs_itr; + new_dir = basedir + _T('\\') + *dirs_itr; } - string new_spec = dir + PLATFORM_PATH_SEPARATOR_STR + *dirs_itr + PLATFORM_PATH_SEPARATOR_STR; + tstring new_spec = dir + PLATFORM_PATH_SEPARATOR_STR + *dirs_itr + PLATFORM_PATH_SEPARATOR_STR; if (!dir_reader::matches(*dirs_itr, spec)) { new_spec += spec; } else if (generatecode) { // always create directories that match - SCRIPT_MSG("%sFile: Descending to: \"%s\"\n", generatecode ? "" : "Reserve", new_spec.c_str()); + SCRIPT_MSG(_T("%sFile: Descending to: \"%s\"\n"), generatecode ? _T("") : _T("Reserve"), new_spec.c_str()); - if (do_add_file_create_dir(dir + '\\' + *dirs_itr, new_dir, attrib) != PS_OK) { + if (do_add_file_create_dir(dir + _T('\\') + *dirs_itr, new_dir, attrib) != PS_OK) { return PS_ERROR; } created = true; } - const char *new_spec_c = new_spec.c_str(); + const TCHAR *new_spec_c = new_spec.c_str(); int res = do_add_file(new_spec_c, attrib, 1, total_files, NULL, generatecode, NULL, excluded, new_dir, created); if (res != PS_OK) { @@ -6133,11 +6133,11 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total } } - if (basedir == "") { - SCRIPT_MSG("%sFile: Returning to: \"%s\"\n", generatecode ? "" : "Reserve", dir.c_str()); + if (basedir == _T("")) { + SCRIPT_MSG(_T("%sFile: Returning to: \"%s\"\n"), generatecode ? _T("") : _T("Reserve"), dir.c_str()); // restore $OUTDIR from $_OUTDIR [SetOutPath $_OUTDIR] - if (add_entry_direct(EW_CREATEDIR, add_string("$_OUTDIR"), 1) != PS_OK) { + if (add_entry_direct(EW_CREATEDIR, add_string(_T("$_OUTDIR")), 1) != PS_OK) { return PS_ERROR; } } @@ -6145,10 +6145,10 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total return PS_OK; } -int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const char *name_override, int generatecode, int *data_handle) { - string newfn_s = dir + PLATFORM_PATH_SEPARATOR_C + file; - const char *newfn = newfn_s.c_str(); - const char *filename = file.c_str(); +int CEXEBuild::add_file(const tstring& dir, const tstring& file, int attrib, const TCHAR *name_override, int generatecode, int *data_handle) { + tstring newfn_s = dir + PLATFORM_PATH_SEPARATOR_C + file; + const TCHAR *newfn = newfn_s.c_str(); + const TCHAR *filename = file.c_str(); MMapFile mmap; DWORD len; @@ -6165,7 +6165,7 @@ int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const ); if (hFile == INVALID_HANDLE_VALUE) { - ERROR_MSG("%sFile: failed opening file \"%s\"\n",generatecode?"":"Reserve",newfn); + ERROR_MSG(_T("%sFile: failed opening file \"%s\"\n"),generatecode?_T(""):_T("Reserve"),newfn); return PS_ERROR; } @@ -6175,13 +6175,13 @@ int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const len = GetFileSize(hFile, NULL); if (len && !mmap.setfile(hFile, len)) { - ERROR_MSG("%sFile: failed creating mmap of \"%s\"\n",generatecode?"":"Reserve",newfn); + ERROR_MSG(_T("%sFile: failed creating mmap of \"%s\"\n"),generatecode?_T(""):_T("Reserve"),newfn); return PS_ERROR; } #else struct stat s; if (stat(newfn, &s)) { - ERROR_MSG("%sFile: failed stating file \"%s\"\n",generatecode?"":"Reserve",newfn); + ERROR_MSG(_T("%sFile: failed stating file \"%s\"\n"),generatecode?_T(""):_T("Reserve"),newfn); return PS_ERROR; } @@ -6190,7 +6190,7 @@ int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const int fd = OPEN(newfn, O_RDONLY); if (fd == -1) { - ERROR_MSG("%sFile: failed opening file \"%s\"\n",generatecode?"":"Reserve",newfn); + ERROR_MSG(_T("%sFile: failed opening file \"%s\"\n"),generatecode?_T(""):_T("Reserve"),newfn); return PS_ERROR; } @@ -6199,19 +6199,19 @@ int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const if (len && !mmap.setfile(fd, len)) { - ERROR_MSG("%sFile: failed creating mmap of \"%s\"\n",generatecode?"":"Reserve",newfn); + ERROR_MSG(_T("%sFile: failed creating mmap of \"%s\"\n"),generatecode?_T(""):_T("Reserve"),newfn); return PS_ERROR; } #endif if (generatecode&1) section_add_size_kb((len+1023)/1024); - if (name_override) SCRIPT_MSG("%sFile: \"%s\"->\"%s\"",generatecode?"":"Reserve",filename,name_override); - else SCRIPT_MSG("%sFile: \"%s\"",generatecode?"":"Reserve",filename); + if (name_override) SCRIPT_MSG(_T("%sFile: \"%s\"->\"%s\""),generatecode?_T(""):_T("Reserve"),filename,name_override); + else SCRIPT_MSG(_T("%sFile: \"%s\""),generatecode?_T(""):_T("Reserve"),filename); if (!build_compress_whole) - if (build_compress) SCRIPT_MSG(" [compress]"); + if (build_compress) SCRIPT_MSG(_T(" [compress]")); fflush(stdout); - char buf[1024]; + TCHAR buf[1024]; int last_build_datablock_used=getcurdbsize(); entry ent={0,}; if (generatecode) @@ -6231,13 +6231,13 @@ int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const } else { - const char *i=filename; - char *o=buf; + const TCHAR *i=filename; + TCHAR *o=buf; while (*i) { - const char c=*i++; + const TCHAR c=*i++; *o++=c; - if (c == '$') *o++='$'; + if (c == _T('$')) *o++=_T('$'); } *o=0; ent.offsets[1]=add_string(buf); @@ -6260,8 +6260,8 @@ int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const { DWORD s=getcurdbsize()-last_build_datablock_used; if (s) s-=4; - if (s != len) SCRIPT_MSG(" %d/%d bytes\n",s,len); - else SCRIPT_MSG(" %d bytes\n",len); + if (s != len) SCRIPT_MSG(_T(" %d/%d bytes\n"),s,len); + else SCRIPT_MSG(_T(" %d bytes\n"),len); } if (generatecode) @@ -6294,7 +6294,7 @@ int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const #endif else { - ERROR_MSG("%sFile: failed getting file date from \"%s\"\n",generatecode?"":"Reserve",newfn); + ERROR_MSG(_T("%sFile: failed getting file date from \"%s\"\n"),generatecode?_T(""):_T("Reserve"),newfn); return PS_ERROR; } } @@ -6357,14 +6357,14 @@ int CEXEBuild::add_file(const string& dir, const string& file, int attrib, const return PS_OK; } -int CEXEBuild::do_add_file_create_dir(const string& local_dir, const string& dir, int attrib) { - string outdir_s = "$_OUTDIR\\" + dir; +int CEXEBuild::do_add_file_create_dir(const tstring& local_dir, const tstring& dir, int attrib) { + tstring outdir_s = _T("$_OUTDIR\\") + dir; - string::size_type pos = 1; - pos = outdir_s.find('$', pos); - while (pos != string::npos) { - outdir_s = outdir_s.insert(pos, "$"); - pos = outdir_s.find('$', pos + 2); + tstring::size_type pos = 1; + pos = outdir_s.find(_T('$'), pos); + while (pos != tstring::npos) { + outdir_s = outdir_s.insert(pos, _T("$")); + pos = outdir_s.find(_T('$'), pos + 2); } int outdir = add_string(outdir_s.c_str()); @@ -6375,7 +6375,7 @@ int CEXEBuild::do_add_file_create_dir(const string& local_dir, const string& dir #ifdef _WIN32 if (attrib) { - int ndc = add_string("."); + int ndc = add_string(_T(".")); DWORD attr = GetFileAttributes(local_dir.c_str()); @@ -6395,17 +6395,17 @@ int CEXEBuild::do_add_file_create_dir(const string& local_dir, const string& dir -DefineList *CEXEBuild::searchParseString(const char *source_string, LineParser *line, int parmOffs, bool ignCase, bool noErrors) +DefineList *CEXEBuild::searchParseString(const TCHAR *source_string, LineParser *line, int parmOffs, bool ignCase, bool noErrors) { - const char *tok = line->gettoken_str(parmOffs++); + const TCHAR *tok = line->gettoken_str(parmOffs++); if (tok && *tok) { - int toklen = strlen(tok); - while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):strncmp(source_string,tok,toklen))) source_string++; + int toklen = _tcsclen(tok); + while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):_tcsncmp(source_string,tok,toklen))) source_string++; if (!*source_string) { - if (!noErrors) ERROR_MSG("!searchparse: starting string \"%s\" not found, aborted search!\n",tok); + if (!noErrors) ERROR_MSG(_T("!searchparse: starting string \"%s\" not found, aborted search!\n"),tok); return NULL; } if (*source_string) source_string+=toklen; @@ -6415,24 +6415,24 @@ DefineList *CEXEBuild::searchParseString(const char *source_string, LineParser * while (parmOffs < line->getnumtokens()) { - const char *defout = line->gettoken_str(parmOffs++); + const TCHAR *defout = line->gettoken_str(parmOffs++); if (parmOffs < line->getnumtokens()) tok=line->gettoken_str(parmOffs++); else tok=NULL; int maxlen=-1; - const char *src_start = source_string; + const TCHAR *src_start = source_string; if (tok && *tok) { - int toklen = strlen(tok); - while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):strncmp(source_string,tok,toklen))) source_string++; + int toklen = _tcsclen(tok); + while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):_tcsncmp(source_string,tok,toklen))) source_string++; maxlen = source_string - src_start; if (*source_string) source_string += toklen; else if (!noErrors) { - ERROR_MSG("!searchparse: string \"%s\" not found, aborted search!\n",tok); + ERROR_MSG(_T("!searchparse: string \"%s\" not found, aborted search!\n"),tok); delete ret; return NULL; } @@ -6446,7 +6446,7 @@ DefineList *CEXEBuild::searchParseString(const char *source_string, LineParser * if (maxlen < 0) ret->add(defout,src_start); else { - char *p=strdup(src_start); + TCHAR *p=strdup(src_start); if (p) { p[maxlen]=0; diff --git a/Source/strlist.cpp b/Source/strlist.cpp index b9c09d9d..ffda8e56 100644 --- a/Source/strlist.cpp +++ b/Source/strlist.cpp @@ -16,7 +16,7 @@ #include "strlist.h" -int StringList::add(const char *str, int case_sensitive) +int StringList::add(const TCHAR *str, int case_sensitive) { int a=find(str,case_sensitive); if (a >= 0 && case_sensitive!=-1) return a; @@ -24,9 +24,9 @@ int StringList::add(const char *str, int case_sensitive) } // use 2 for case sensitive end-of-string matches too -int StringList::find(const char *str, int case_sensitive, int *idx/*=NULL*/) const // returns -1 if not found +int StringList::find(const TCHAR *str, int case_sensitive, int *idx/*=NULL*/) const // returns -1 if not found { - const char *s=get(); + const TCHAR *s=get(); int ml=getlen(); int offs=0; if (idx) *idx=0; @@ -51,7 +51,7 @@ int StringList::find(const char *str, int case_sensitive, int *idx/*=NULL*/) con void StringList::delbypos(int pos) { - char *s=(char*)gr.get(); + TCHAR *s=(TCHAR*)gr.get(); int len=strlen(s+pos)+1; if (pos+len < gr.getlen()) memcpy(s+pos,s+pos+len,gr.getlen()-(pos+len)); gr.resize(gr.getlen()-len); @@ -59,7 +59,7 @@ void StringList::delbypos(int pos) int StringList::idx2pos(int idx) const { - char *s=(char*)gr.get(); + TCHAR *s=(TCHAR*)gr.get(); int offs=0; int cnt=0; if (idx>=0) while (offs < gr.getlen()) @@ -72,7 +72,7 @@ int StringList::idx2pos(int idx) const int StringList::getnum() const { - char *s=(char*)gr.get(); + TCHAR *s=(TCHAR*)gr.get(); int ml=gr.getlen(); int offs=0; int idx=0; @@ -84,9 +84,9 @@ int StringList::getnum() const return idx; } -const char *StringList::get() const +const TCHAR *StringList::get() const { - return (const char*)gr.get(); + return (const TCHAR*)gr.get(); } int StringList::getlen() const @@ -108,7 +108,7 @@ DefineList::~DefineList() } } -int DefineList::add(const char *name, const char *value/*=""*/) +int DefineList::add(const TCHAR *name, const TCHAR *value/*=_T("")*/) { int pos=SortedStringList::add(name); if (pos == -1) @@ -116,8 +116,8 @@ int DefineList::add(const char *name, const char *value/*=""*/) return 1; } - char **newvalue=&(((struct define*)gr.get())[pos].value); - *newvalue=(char*)malloc(strlen(value)+1); + TCHAR **newvalue=&(((struct define*)gr.get())[pos].value); + *newvalue=(TCHAR*)malloc(strlen(value)+1); if (!(*newvalue)) { extern FILE *g_output; @@ -125,7 +125,7 @@ int DefineList::add(const char *name, const char *value/*=""*/) extern void quit(); if (g_display_errors) { - fprintf(g_output,"\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n",(unsigned long)strlen(value)+1); + fprintf(g_output,_T("\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n"),(unsigned long)strlen(value)+1); fflush(g_output); } quit(); @@ -134,7 +134,7 @@ int DefineList::add(const char *name, const char *value/*=""*/) return 0; } -char *DefineList::find(const char *name) +TCHAR *DefineList::find(const TCHAR *name) { int v=SortedStringList::find(name); if (v==-1) @@ -145,7 +145,7 @@ char *DefineList::find(const char *name) } // returns 0 on success, 1 otherwise -int DefineList::del(const char *str) +int DefineList::del(const TCHAR *str) { int pos=SortedStringList::find(str); if (pos==-1) return 1; @@ -162,14 +162,14 @@ int DefineList::getnum() return gr.getlen()/sizeof(define); } -char *DefineList::getname(int num) +TCHAR *DefineList::getname(int num) { if ((unsigned int)getnum() <= (unsigned int)num) return 0; return ((struct define*)gr.get())[num].name; } -char *DefineList::getvalue(int num) +TCHAR *DefineList::getvalue(int num) { if ((unsigned int)getnum() <= (unsigned int)num) return 0; @@ -180,16 +180,16 @@ char *DefineList::getvalue(int num) // FastStringList // ============== -int FastStringList::add(const char *name, int case_sensitive/*=0*/) +int FastStringList::add(const TCHAR *name, int case_sensitive/*=0*/) { int pos = SortedStringListND::add(name, case_sensitive); if (pos == -1) return -1; return ((struct string_t*)gr.get())[pos].name; } -char *FastStringList::get() const +TCHAR *FastStringList::get() const { - return (char*)strings.get(); + return (TCHAR*)strings.get(); } int FastStringList::getlen() const diff --git a/Source/strlist.h b/Source/strlist.h index 48a1b495..2e9f53d5 100644 --- a/Source/strlist.h +++ b/Source/strlist.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support and Doxygen comments by Jim Park -- 07/27/2007 */ #ifndef _STRLIST_H_ @@ -20,8 +22,14 @@ #include "Platform.h" #include #include +#include "tchar.h" #include "growbuf.h" +/** + * Implements a list of strings mapped into a straight buffer. It is + * virtually always O(n) to do any basic operations on this thing. Very + * memory efficient but very slow performance. + */ class StringList { private: // don't copy instances @@ -32,23 +40,99 @@ public: StringList() {} ~StringList() {} - int add(const char *str, int case_sensitive); - // use 2 for case sensitive end-of-string matches too - int find(const char *str, int case_sensitive, int *idx=NULL) const; // returns -1 if not found + /** + * Adds a string to the StringList. If the string already exists in the + * list, then it just returns the index of the found string. + * + * @param str String to add. + * + * @param case_sensitive If 0, search for whole string case insensitively. + * If 1, then search for whole string case sensitively. If 2, then search + * for just the end of the string match case sensitively. Basically it's + * like searching for regexp('str$') in the list of string. If -1, then it + * adds the string regardless of whether there is a match or not! + * + * @return the index to the string in TCHARs. + */ + int add(const TCHAR *str, int case_sensitive); + + /** + * Search the StrinList for a string. If the string already exists in the + * list then it returns the index of the found string. Returns -1 on + * failure. + * + * @param str String to search for. + * + * @param case_sensitive If 0, search for whole string case insensitively.If + * 1, then search for whole string case sensitively. If 2, then + * search for just the end of the string match, case sensitively. + * Basically it's like searching for regexp('str$') in the list of string. + * + * @param idx If not NULL, the *idx is set to the cardinal number of the + * string. In other words, it tells you which nth string it is in the + * list. + * + * @return the TCHAR index to the string (not necessarily the byte positional + * offset). -1 if not found. + */ + int find(const TCHAR *str, int case_sensitive, int *idx=NULL) const; // returns -1 if not found + + /** + * Delete the string at the positional index. + * + * @param pos The number of TCHARS to count from the beginning of the buffer + * before the start of the string. + */ void delbypos(int pos); + + /** + * Converts the string index to the positional TCHAR index. For example, + * it gives the answer to which TCHAR position is the beginning of the + * nth string in the list? + * + * @param idx The string index. + */ int idx2pos(int idx) const; + + /** + * Get the count of the number of strings in the list. + * @return the number of string in the list. + */ int getnum() const; - const char *get() const; + + /** + * Get the buffer straight as a const TCHAR pointer. Very unwise to use. + * @return gr.m_s cast as a TCHAR*. + */ + const TCHAR *get() const; + + /** + * Get the buffer size in bytes. + * @return The buffer size in bytes. + */ int getlen() const; private: GrowBuf gr; }; +/** + * This class maintains a list of T types in a GrowBuf sorted by T.name which + * is assumed to be a string (TCHAR*). So it's really sort of a + * map where X is whatever else is defined in T. But T must define + * a TCHAR* name. + * + * The T struct should have the 'name' as the first element in its list of + * members. Otherwise, all kinds of bad things will happen. + */ template class SortedStringList { public: + /** + * Jim Park: Note that SortedStringList actually owns T.name. + * Yes, this violates all kinds of encapsulation ideas. + */ virtual ~SortedStringList() { T *s=(T*)gr.get(); @@ -59,13 +143,22 @@ class SortedStringList } } - // returns -1 when name already exists and pos if added - int add(const char *name, int case_sensitive=0) + /** + * This function adds a new T struct with a copy of TCHAR *name into + * T.name. But adds it into a sorted position. All calls to + * add must be done with the same value for case_sensitive or you + * can get random behavior. + * + * @param name The name which is the "key" to finding the instance of T. + * @param case_sensitive 1 means case sensitive, 0 insensitive. + * @return Returns -1 when name already exists and pos if added. + */ + int add(const TCHAR *name, int case_sensitive=0) { T newstruct={0,}; int pos=find(name,case_sensitive,1); if (pos==-1) return -1; - newstruct.name=(char*)malloc(strlen(name)+1); + newstruct.name=(TCHAR*)malloc((_tcsclen(name)+1)*sizeof(TCHAR)); if (!newstruct.name) { extern FILE *g_output; @@ -73,12 +166,12 @@ class SortedStringList extern void quit(); if (g_display_errors) { - fprintf(g_output,"\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n",(unsigned long)strlen(name)+1); + _ftprintf(g_output,_T("\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n"),(unsigned long)((_tcsclen(name)+1)*sizeof(TCHAR))); fflush(g_output); } quit(); } - strcpy(newstruct.name,name); + _tcscpy(newstruct.name,name); gr.add(&newstruct,sizeof(T)); T *s=(T*)gr.get(); @@ -88,9 +181,23 @@ class SortedStringList return pos; } - // returns -1 if not found, position if found - // if returnbestpos=1 returns -1 if found, best pos to insert if not found - int find(const char *str, int case_sensitive=0, int returnbestpos=0) + /** + * This function does a binary search for the T in the buffer that + * contains str as its T.name. It then returns the position of the found + * T, not in its byte position, but its T position (valid offset to T*). + * + * @param str The string to search for in T.name. + * + * @param case_sensitive If 1, do a case sensitive search, otherwise, case insensitive. + * + * @param returnbestpos If 1, then the function changes behavior. Instead + * of looking for the string str in the Ts, it tries to find the best + * sorted position to insert str into the buffer. + * + * @return Returns -1 if not found, position if found. If returnbestpos=1 + * returns -1 if found, best pos to insert if not found + */ + int find(const TCHAR *str, int case_sensitive=0, int returnbestpos=0) { T *data=(T *)gr.get(); int ul=gr.getlen()/sizeof(T); @@ -101,7 +208,7 @@ class SortedStringList { int res; if (case_sensitive) - res=strcmp(str, data[nextpos].name); + res=_tcscmp(str, data[nextpos].name); else res=stricmp(str, data[nextpos].name); if (res==0) return returnbestpos ? -1 : nextpos; @@ -113,8 +220,13 @@ class SortedStringList return returnbestpos ? nextpos : -1; } - // returns 0 on success, 1 otherwise - int del(const char *str, int case_sensitive=0) + /** + * This function looks for str in T.name and deletes the T in the + * buffer. + * + * @return Returns 0 on success, 1 on failure. + */ + int del(const TCHAR *str, int case_sensitive=0) { int pos=find(str, case_sensitive); if (pos==-1) return 1; @@ -124,6 +236,12 @@ class SortedStringList return 0; } + /** + * Given a T position, it deletes it from the buffer. It will + * move the rest of the Ts to fill its position. + * + * @param pos The position of the target for deletion in T* offsets. + */ void delbypos(int pos) { T *db=(T *)gr.get(); @@ -138,6 +256,21 @@ class SortedStringList #define mymin(x, y) ((x < y) ? x : y) +/** + * This class maintains a list of T types in a GrowBuf sorted by T.name which + * is assumed to be an index into m_strings. So it's really sort of a + * map where X is whatever else is defined in T. But T must define + * a int name. + * + * The T struct should have the 'name' as the first element in its list of + * members. Otherwise, all kinds of bad things will happen. + * + * This version does not have a delete function, hence the ND designation. + * Also, because nothing is malloc'ed and free'd, this structure can be + * placed in a single flat buffer. (Of course, T itself can be holding + * pointers to things on the heap, which this structure does not + * disallow explicitly.) + */ template class SortedStringListND // no delete - can be placed in GrowBuf { @@ -145,12 +278,27 @@ class SortedStringListND // no delete - can be placed in GrowBuf SortedStringListND() { } virtual ~SortedStringListND() { } - // returns -1 when name already exists and pos if added - int add(const char *name, int case_sensitive=0, int alwaysreturnpos=0) + /** + * Adds name into the list of sorted strings. + * + * @param name String to store. + * @param case_sensitive Look for string case sensitively. Default is 0. + * @param alwaysreturnpos Always return the position regardless of whether + * name was inserted into the list or not. The default is 0. + * + * @return Returns -1 when name already exists, otherwise the T offset + * into which the struct was stored in m_gr. If alwaysreturnpos + * is true, then it will return the byte offset regardless of whether + * the string was found. + */ + int add(const TCHAR *name, int case_sensitive=0, int alwaysreturnpos=0) { int where=0; T newstruct={0,}; + + // Find the best position to insert. int pos=find(name,-1,case_sensitive,1,&where); + if (pos==-1) return alwaysreturnpos ? where : -1; newstruct.name=strings.add(name,strlen(name)+1); @@ -162,10 +310,47 @@ class SortedStringListND // no delete - can be placed in GrowBuf return pos; } - // returns -1 if not found, position if found - // if returnbestpos=1 returns -1 if found, best pos to insert if not found - // if n_chars equal to -1 all string is tested - int find(const char *str, int n_chars=-1, int case_sensitive=0, int returnbestpos=0, int *where=0) + /** + * This function looks for the string str, in T.name in the buffer m_gr. + * If it finds it, it returns the position found. Otherwise, it returns + * -1. + * + * This behavior changes when returnbestpos == 1. In this case, + * it will do the reverse. It will return -1 when it is found, noting + * that there is no good place to put this duplicate string. If it + * is not found, it returns the position where it ought to be + * placed. + * + * When case_sensitive == -1 and returnbestpos == 1, then when the string + * is found, it returns + * the position of the string so that one can overwrite it. Very strange + * special case behavior that I'm not sure if anyone actually uses. + * + * @param str The key string to search for. + * + * @param n_chars The number of characters to compare. Use -1 to match + * the entire string. + * + * @param case_sensitive 1 = case sensitive, 0 = case insensitive, + * -1 is a special case where it is case sensitive and overrides the + * returnbestpos behavior when the string is found. + * + * @param returnbestpos If 1, then look for the best position to add the + * string. If found in the list, return -1. + * + * @param where When str is found, returns the position of the string. + * + * @return The position of T where T.name == str. If returnbestpos != 0 + * then return the best position to add T if not found, otherwise, -1. + */ + int find + ( + const TCHAR* str, /* key to search for */ + int n_chars=-1, /* if -1, test the entire string, otherwise just n characters */ + int case_sensitive=0, + int returnbestpos=0, /* if not found, return best pos */ + int* where=0 /* */ + ) { T *data=(T *)gr.get(); int ul=gr.getlen()/sizeof(T); @@ -175,11 +360,11 @@ class SortedStringListND // no delete - can be placed in GrowBuf while (ul > ll) { int res; - const char *pCurr = (char*)strings.get() + data[nextpos].name; + const TCHAR *pCurr = (TCHAR*)strings.get() + data[nextpos].name; if (n_chars < 0) { if (case_sensitive) - res = strcmp(str, pCurr); + res = _tcscmp(str, pCurr); else res = stricmp(str, pCurr); } @@ -211,11 +396,18 @@ class SortedStringListND // no delete - can be placed in GrowBuf GrowBuf strings; }; +/** + * Structure stored by DefineList. + */ struct define { - char *name; - char *value; + TCHAR *name; // key + TCHAR *value; // value stored }; +/** + * DefineList is a specialized version of a SortedStringList + * which is like a string to string mapping class. + */ class DefineList : public SortedStringList { private: // don't copy instances @@ -223,23 +415,78 @@ class DefineList : public SortedStringList void operator=(const DefineList&); public: + /* Empty default constructor */ DefineList() {} // VC6 complains otherwise virtual ~DefineList(); - int add(const char *name, const char *value=""); - char *find(const char *name); + /** + * Add a name-value pair, case insensitively. + * + * @param name The name of the variable or key to search by. In a + * std::map, it would be the .first of the pair. + * + * @param value The value to store. In a std::map, it would be the.second + * of the pair. + * + * @return Returns 0 if successful, 1 if already exists. Errors cause + * general program exit with error logging. + */ + int add(const TCHAR *name, const TCHAR *value=_T("")); - // returns 0 on success, 1 otherwise - int del(const char *str); + /** + * This function returns the pointer to the .value TCHAR* that corresponds + * to the name key. + * + * @param name The key to search with. + * + * @return The TCHAR* to the value portion of the define struct. If not + * found, returns NULL. + */ + TCHAR *find(const TCHAR *name); + + /** + * This function deletes the define struct corresponding to the key 'str'. + * + * @return Returns 0 on success, 1 otherwise + */ + int del(const TCHAR *str); + + /** + * This function returns the number of define structs in the sorted array. + */ int getnum(); - char *getname(int num); - char *getvalue(int num); + + /** + * Get the .name string of the (num)th define struct in the sorted array. + * + * @return Returns 0 if not found, otherwise the pointer to the .name. + */ + TCHAR *getname(int num); + + /** + * Get the .value string of the (num)th define struct in the sorted array. + * + * @return Returns 0 if not found, otherwise the pointer to the .value. + */ + TCHAR *getvalue(int num); }; +/** + * Storage unit for FastStringList. Contains the byte offset into m_strings. + */ struct string_t { int name; }; +/** + * This class uses SortedStringListND to implement a "faster" storage of + * strings. It sort of implements a std::set that allows you + * to add to the set and check for existence of the set. + * + * It's only faster in the sense that memory moves now only need to occur + * on the array of string_t structs (or pointers) rather than entire + * strings. A truly faster implementation would be using a hash table. + */ class FastStringList : public SortedStringListND { private: // don't copy instances @@ -247,12 +494,46 @@ class FastStringList : public SortedStringListND void operator=(const FastStringList&); public: + /* Empty constructor */ FastStringList() {} // VC6 complains otherwise + + /* Empty virtual destructor */ virtual ~FastStringList() {} - int add(const char *name, int case_sensitive=0); - char *get() const; + /** + * Adds name to sorted array and returns the TCHAR* offset of m_strings + * where it is stored. + * + * @param name The string to store. + * + * @param case_sensitive Should we store this case sensitively or not? + * Setting case_sensitive to -1 will cause it to be case sensitive and + * always overwrite. (Weird bad behavior). + * + * @return The TCHAR* offset of name in m_string as an int. + */ + int add(const TCHAR *name, int case_sensitive=0); + + /** + * Get the buffer that contains the list of the strings in the order + * in which they were added. + * + * @return The pointer to m_strings as a TCHAR*. + */ + TCHAR *get() const; + + /** + * The size of the collection of m_strings as bytes. + * + * @return The size of m_strings in bytes. + */ int getlen() const; + + /** + * The number of strings stored in the sorted array. + * + * @return The number of strings stored. + */ int getnum() const; }; diff --git a/Source/tchar.h b/Source/tchar.h new file mode 100644 index 00000000..7f2e998d --- /dev/null +++ b/Source/tchar.h @@ -0,0 +1,210 @@ +/* + * tchar.h + * + * This file is a part of NSIS. + * + * Copyright (C) 1999-2009 Nullsoft and Contributors + * + * This software is provided 'as-is', without any express or implied + * warranty. + * + * For Unicode support by Jim Park -- 08/30/2007 + */ + +// Jim Park: Only those we use are listed here. + +#pragma once + +#ifdef _UNICODE + +#ifndef _T +#define __T(x) L ## x +#define _T(x) __T(x) +#define _TEXT(x) __T(x) +#endif +typedef wchar_t TCHAR; +typedef wchar_t _TUCHAR; + +// program +#define _tmain wmain +#define _tWinMain wWinMain +#define _tenviron _wenviron +#define __targv __wargv + +// printfs +#define _ftprintf fwprintf +#define _sntprintf _snwprintf +#define _stprintf _swprintf +#define _tprintf wprintf +#define _vftprintf vfwprintf +#define _vsntprintf _vsnwprintf +#define _vstprintf _vswprintf + +// scanfs +#define _tscanf wscanf +#define _stscanf swscanf + +// string manipulations +#define _tcscat wcscat +#define _tcschr wcschr +#define _tcsclen wcslen +#define _tcscpy wcscpy +#define _tcsdup _wcsdup +#define _tcslen wcslen +#define _tcsnccpy wcsncpy +#define _tcsncpy wcsncpy +#define _tcsrchr wcsrchr +#define _tcsstr wcsstr +#define _tcstok wcstok + +// string comparisons +#define _tcscmp wcscmp +#define _tcsicmp _wcsicmp +#define _tcsncicmp _wcsnicmp +#define _tcsncmp wcsncmp +#define _tcsnicmp _wcsnicmp + +// upper / lower +#define _tcslwr _wcslwr +#define _tcsupr _wcsupr +#define _totlower towlower +#define _totupper towupper + +// conversions to numbers +#define _tcstoi64 _wcstoi64 +#define _tcstol wcstol +#define _tcstoul wcstoul +#define _tstof _wtof +#define _tstoi _wtoi +#define _tstoi64 _wtoi64 +#define _ttoi _wtoi +#define _ttoi64 _wtoi64 +#define _ttol _wtol + +// conversion from numbers to strings +#define _itot _itow +#define _ltot _ltow +#define _i64tot _i64tow +#define _ui64tot _ui64tow + +// file manipulations +#define _tfopen _wfopen +#define _topen _wopen +#define _tremove _wremove +#define _tunlink _wunlink + +// reading and writing to i/o +#define _fgettc fgetwc +#define _fgetts fgetws +#define _fputts fputws +#define _gettchar getwchar + +// directory +#define _tchdir _wchdir + +// environment +#define _tgetenv _wgetenv +#define _tsystem _wsystem + +// time +#define _tcsftime wcsftime + +#else // ANSI + +#ifndef _T +#define _T(x) x +#define _TEXT(x) x +#endif +typedef char TCHAR; +typedef unsigned char _TUCHAR; + +// program +#define _tmain main +#define _tWinMain WinMain +#define _tenviron environ +#define __targv __argv + +// printfs +#define _ftprintf fprintf +#define _sntprintf _snprintf +#define _stprintf sprintf +#define _tprintf printf +#define _vftprintf vfprintf +#define _vsntprintf _vsnprintf +#define _vstprintf vsprintf + +// scanfs +#define _tscanf scanf +#define _stscanf sscanf + +// string manipulations +#define _tcscat strcat +#define _tcschr strchr +#define _tcsclen strlen +#define _tcscnlen strnlen +#define _tcscpy strcpy +#define _tcsdup _strdup +#define _tcslen strlen +#define _tcsnccpy strncpy +#define _tcsrchr strrchr +#define _tcsstr strstr +#define _tcstok strtok + +// string comparisons +#define _tcscmp strcmp +#define _tcsicmp _stricmp +#define _tcsncmp strncmp +#define _tcsncicmp _strnicmp +#define _tcsnicmp _strnicmp + +// upper / lower +#define _tcslwr _strlwr +#define _tcsupr _strupr + +#define _totupper toupper +#define _totlower tolower + +// conversions to numbers +#define _tcstol strtol +#define _tcstoul strtoul +#define _tstof atof +#define _tstoi atoi +#define _tstoi64 _atoi64 +#define _tstoi64 _atoi64 +#define _ttoi atoi +#define _ttoi64 _atoi64 +#define _ttol atol + +// conversion from numbers to strings +#define _i64tot _i64toa +#define _itot _itoa +#define _ltot _ltoa +#define _ui64tot _ui64toa + +// file manipulations +#define _tfopen fopen +#define _topen _open +#define _tremove remove +#define _tunlink _unlink + +// reading and writing to i/o +#define _fgettc fgetc +#define _fgetts fgets +#define _fputts fputs +#define _gettchar getchar + +// directory +#define _tchdir _chdir + +// environment +#define _tgetenv getenv +#define _tsystem system + +// time +#define _tcsftime strftime + +#endif + +// is functions (the same in Unicode / ANSI) +#define _istgraph isgraph +#define _istascii __isascii diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 9341bd46..93b93cec 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/10/2007 */ #include "Platform.h" @@ -24,284 +26,284 @@ typedef struct { int id; - const char *name; + const TCHAR *name; int num_parms; // minimum number of parameters int opt_parms; // optional parmaters, usually 0, can be -1 for unlimited. - const char *usage_str; + const TCHAR *usage_str; int placement; // where the token can be placed } tokenType; static tokenType tokenlist[TOK__LAST] = { -{TOK_ABORT,"Abort",0,1,"[message]",TP_CODE}, -{TOK_ADDBRANDINGIMAGE,"AddBrandingImage",2,1,"(top|left|bottom|right) (height|width) [padding]",TP_GLOBAL}, -{TOK_ADDSIZE,"AddSize",1,0,"size_to_add_to_section_in_kb",TP_SEC}, -{TOK_AUTOCLOSE,"AutoCloseWindow",1,0,"(false|true)",TP_GLOBAL}, -{TOK_BGFONT,"BGFont",0,6,"[font_face [height [wieght] [/ITALIC] [/UNDERLINE] [/STRIKE]]]",TP_GLOBAL}, -{TOK_BGGRADIENT,"BGGradient",0,3,"(off | [top_color [bottom_color [text_color]]])",TP_GLOBAL}, -{TOK_BRANDINGTEXT,"BrandingText",1,1,"[/TRIM(LEFT|RIGHT|CENTER)] installer_text",TP_GLOBAL}, -{TOK_BRINGTOFRONT,"BringToFront",0,0,"",TP_CODE}, -{TOK_CALL,"Call",1,0,"function_name | [:label_name]",TP_CODE}, -{TOK_CALLINSTDLL,"CallInstDLL",2,1,"dll_path_on_target.dll function",TP_CODE}, -{TOK_CAPTION,"Caption",1,0,"installer_caption",TP_GLOBAL|TP_PAGEEX}, -{TOK_CHANGEUI,"ChangeUI",2,0,"(all|dlg_id) ui_file.exe",TP_GLOBAL}, -{TOK_CLEARERRORS,"ClearErrors",0,0,"",TP_CODE}, -{TOK_COMPTEXT,"ComponentText",0,3,"[component_page_description] [component_subtext1] [component_subtext2]",TP_PG}, -{TOK_GETDLLVERSION,"GetDLLVersion",3,0,"filename $(user_var: high output) $(user_var: low output)",TP_CODE}, -{TOK_GETDLLVERSIONLOCAL,"GetDLLVersionLocal",3,0,"localfilename $(user_var: high output) $(user_var: low output)",TP_CODE}, -{TOK_GETFILETIME,"GetFileTime",3,0,"file $(user_var: high output) $(user_var: low output)",TP_CODE}, -{TOK_GETFILETIMELOCAL,"GetFileTimeLocal",3,0,"localfile $(user_var: high output) $(user_var: low output)",TP_CODE}, -{TOK_COPYFILES,"CopyFiles",2,3,"[/SILENT] [/FILESONLY] source_path destination_path [total_size_in_kb]",TP_CODE}, -{TOK_CRCCHECK,"CRCCheck",1,0,"(on|force|off)",TP_GLOBAL}, -{TOK_CREATEDIR,"CreateDirectory",1,0,"directory_name",TP_CODE}, -{TOK_CREATEFONT,"CreateFont",2,5,"$(user_var: handle output) face_name [height wieght /ITALIC /UNDERLINE /STRIKE]",TP_CODE}, -{TOK_CREATESHORTCUT,"CreateShortCut",2,6,"shortcut_name.lnk shortcut_target [parameters [icon_file [icon index [showmode [hotkey [comment]]]]]]\n showmode=(SW_SHOWNORMAL|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED)\n hotkey=(ALT|CONTROL|EXT|SHIFT)|(F1-F24|A-Z)",TP_CODE}, -{TOK_DBOPTIMIZE,"SetDatablockOptimize",1,0,"(off|on)",TP_ALL}, -{TOK_DELETEINISEC,"DeleteINISec",2,0,"ini_file section_name",TP_CODE}, -{TOK_DELETEINISTR,"DeleteINIStr",3,0,"ini_file section_name entry_name",TP_CODE}, -{TOK_DELETEREGKEY,"DeleteRegKey",2,1,"[/ifempty] root_key subkey\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_DELETEREGVALUE,"DeleteRegValue",3,0,"root_key subkey entry_name\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_DELETE,"Delete",1,1,"[/REBOOTOK] filespec",TP_CODE}, -{TOK_DETAILPRINT,"DetailPrint",1,0,"message",TP_CODE}, -{TOK_DIRTEXT,"DirText",0,4,"[directory_page_description] [directory_page_subtext] [browse_button_text] [browse_dlg_text]",TP_PG}, -//{TOK_DIRSHOW,"DirShow",1,0,"(show|hide)",TP_PG}, -{TOK_DIRSHOW,"DirShow",0,0,"doesn't currently work",TP_ALL}, -{TOK_DIRVAR,"DirVar",1,0,"$(user_var: dir in/out))",TP_PAGEEX}, -{TOK_DIRVERIFY,"DirVerify",1,0,"auto|leave",TP_PAGEEX}, -{TOK_GETINSTDIRERROR,"GetInstDirError",1,0,"$(user_var: error output)",TP_CODE}, -{TOK_ROOTDIRINST,"AllowRootDirInstall",1,0,"(true|false)",TP_GLOBAL}, -{TOK_CHECKBITMAP,"CheckBitmap",1,0,"local_bitmap.bmp",TP_GLOBAL}, -{TOK_ENABLEWINDOW,"EnableWindow",2,0,"hwnd (1|0)",TP_CODE}, -{TOK_ENUMREGKEY,"EnumRegKey",4,0,"$(user_var: output) rootkey subkey index\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_ENUMREGVAL,"EnumRegValue",4,0,"$(user_var: output) rootkey subkey index\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_EXCH,"Exch",0,1,"[$(user_var)] | [stack_item_index]",TP_CODE}, -{TOK_EXEC,"Exec",1,0,"command_line",TP_CODE}, -{TOK_EXECWAIT,"ExecWait",1,1,"command_line [$(user_var: return value)]",TP_CODE}, -{TOK_EXECSHELL,"ExecShell",2,2,"(open|print|etc) command_line [parameters [showmode]]\n showmode=(SW_SHOWNORMAL|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED|SW_HIDE)",TP_CODE}, -{TOK_EXPANDENVSTRS,"ExpandEnvStrings",2,0,"$(user_var: output) string",TP_CODE}, -{TOK_FINDWINDOW,"FindWindow",2,3,"$(user_var: handle output) WindowClass [WindowTitle] [Window_Parent] [Child_After]",TP_CODE}, -{TOK_FINDCLOSE,"FindClose",1,0,"$(user_var: handle input)",TP_CODE}, -{TOK_FINDFIRST,"FindFirst",3,0,"$(user_var: handle output) $(user_var: filename output) filespec",TP_CODE}, -{TOK_FINDNEXT,"FindNext",2,0,"$(user_var: handle input) $(user_var: filename output)",TP_CODE}, -{TOK_FILE,"File",1,-1,"[/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |\n /oname=outfile one_file_only)",TP_CODE}, -{TOK_FILEBUFSIZE,"FileBufSize",1,0,"buf_size_mb",TP_ALL}, -{TOK_FLUSHINI,"FlushINI",1,0,"ini_file",TP_CODE}, -{TOK_RESERVEFILE,"ReserveFile",1,-1,"[/nonfatal] [/r] [/x filespec [...]] file [file...]",TP_ALL}, -{TOK_FILECLOSE,"FileClose",1,0,"$(user_var: handle input)",TP_CODE}, -{TOK_FILEERRORTEXT,"FileErrorText",0,2,"[text (can contain $0)] [text without ignore (can contain $0)]",TP_GLOBAL}, -{TOK_FILEOPEN,"FileOpen",3,0,"$(user_var: handle output) filename openmode\n openmode=r|w|a",TP_CODE}, -{TOK_FILEREAD,"FileRead",2,1,"$(user_var: handle input) $(user_var: text output) [maxlen]",TP_CODE}, -{TOK_FILEWRITE,"FileWrite",2,0,"$(user_var: handle input) text",TP_CODE}, -{TOK_FILEREADBYTE,"FileReadByte",2,0,"$(user_var: handle input) $(user_var: bytevalue output)",TP_CODE}, -{TOK_FILEWRITEBYTE,"FileWriteByte",2,0,"$(user_var: handle input) bytevalue",TP_CODE}, -{TOK_FILESEEK,"FileSeek",2,2,"$(user_var: handle input) offset [mode] [$(user_var: new position output)]\n mode=SET|CUR|END",TP_CODE}, -{TOK_FUNCTION,"Function",1,0,"function_name",TP_GLOBAL}, -{TOK_FUNCTIONEND,"FunctionEnd",0,0,"",TP_FUNC}, -{TOK_GETDLGITEM,"GetDlgItem",3,0,"$(user_var: handle output) dialog item_id",TP_CODE}, -{TOK_GETFULLPATHNAME,"GetFullPathName",2,1,"[/SHORT] $(user_var: result) path_or_file",TP_CODE}, -{TOK_GETTEMPFILENAME,"GetTempFileName",1,1,"$(user_var: name output) [base_dir]",TP_CODE}, -{TOK_HIDEWINDOW,"HideWindow",0,0,"",TP_CODE}, -{TOK_ICON,"Icon",1,0,"local_icon.ico",TP_GLOBAL}, -{TOK_IFABORT,"IfAbort",1,1,"label_to_goto_if_abort [label_to_goto_if_no_abort]",TP_CODE}, -{TOK_IFERRORS,"IfErrors",1,1,"label_to_goto_if_errors [label_to_goto_if_no_errors]",TP_CODE}, -{TOK_IFFILEEXISTS,"IfFileExists",2,1,"filename label_to_goto_if_file_exists [label_to_goto_otherwise]",TP_CODE}, -{TOK_IFREBOOTFLAG,"IfRebootFlag",1,1,"jump_if_set [jump_if_not_set]",TP_CODE}, -{TOK_IFSILENT,"IfSilent",1,1,"jump_if_silent [jump_if_not_silent]",TP_CODE}, -{TOK_INSTALLDIRREGKEY,"InstallDirRegKey",3,0,"root_key subkey entry_name\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_GLOBAL}, -{TOK_INSTCOLORS,"InstallColors",1,1,"(/windows | (foreground_color background_color))",TP_GLOBAL}, -{TOK_INSTDIR,"InstallDir",1,0,"default_install_directory",TP_GLOBAL}, -{TOK_INSTPROGRESSFLAGS,"InstProgressFlags",0,-1,"[flag [...]]\n flag={smooth|colored}",TP_GLOBAL}, -{TOK_INSTTYPE,"InstType",1,0,"[un.]install_type_name | /NOCUSTOM | /CUSTOMSTRING=str | /COMPONENTSONLYONCUSTOM",TP_GLOBAL}, -{TOK_INTOP,"IntOp",3,1,"$(user_var: result) val1 OP [val2]\n OP=(+ - * / % | & ^ ~ ! || && << >>)",TP_CODE}, -{TOK_INTCMP,"IntCmp",3,2,"val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]",TP_CODE}, -{TOK_INTCMPU,"IntCmpU",3,2,"val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]",TP_CODE}, -{TOK_INTFMT,"IntFmt",3,0,"$(user_var: output) format_string input",TP_CODE}, -{TOK_ISWINDOW,"IsWindow",2,1,"hwnd jump_if_window [jump_if_not_window]",TP_CODE}, -{TOK_GOTO,"Goto",1,0,"label",TP_CODE}, -{TOK_LANGSTRING,"LangString",3,0,"[un.]name lang_id string",TP_GLOBAL}, -{TOK_LANGSTRINGUP,"LangStringUP",0,0,"obsolete, use LangString.",TP_ALL}, -{TOK_LICENSEDATA,"LicenseData",1,0,"local_file_that_has_license_text | license_lang_string",TP_PG}, -{TOK_LICENSEFORCESELECTION,"LicenseForceSelection",1,2,"(checkbox [accept_text] | radiobuttons [accept_text] [decline_text] | off)",TP_PG}, -{TOK_LICENSELANGSTRING,"LicenseLangString",3,0,"name lang_id license_path",TP_GLOBAL}, -{TOK_LICENSETEXT,"LicenseText",1,1,"license_page_description [license_button_text]",TP_PG}, -{TOK_LICENSEBKCOLOR,"LicenseBkColor",1,0,"background_color",TP_GLOBAL}, -{TOK_LOADNLF,"LoadLanguageFile",1,0,"language.nlf",TP_GLOBAL}, -{TOK_LOGSET,"LogSet",1,0,"on|off",TP_CODE}, -{TOK_LOGTEXT,"LogText",1,0,"text",TP_CODE}, -{TOK_MESSAGEBOX,"MessageBox",2,6,"mode messagebox_text [/SD return] [return_check label_to_goto_if_equal [return_check2 label2]]\n mode=modeflag[|modeflag[|modeflag[...]]]\n " - "modeflag=(MB_ABORTRETRYIGNORE|MB_OK|MB_OKCANCEL|MB_RETRYCANCEL|MB_YESNO|MB_YESNOCANCEL|MB_ICONEXCLAMATION|MB_ICONINFORMATION|MB_ICONQUESTION|MB_ICONSTOP|MB_USERICON|MB_TOPMOST|MB_SETFOREGROUND|MB_RIGHT",TP_CODE}, -{TOK_NOP,"Nop",0,0,"",TP_CODE}, -{TOK_NAME,"Name",1,1,"installer_name installer_name_doubled_ampersands",TP_GLOBAL}, -{TOK_OUTFILE,"OutFile",1,0,"install_output.exe",TP_GLOBAL}, +{TOK_ABORT,_T("Abort"),0,1,_T("[message]"),TP_CODE}, +{TOK_ADDBRANDINGIMAGE,_T("AddBrandingImage"),2,1,_T("(top|left|bottom|right) (height|width) [padding]"),TP_GLOBAL}, +{TOK_ADDSIZE,_T("AddSize"),1,0,_T("size_to_add_to_section_in_kb"),TP_SEC}, +{TOK_AUTOCLOSE,_T("AutoCloseWindow"),1,0,_T("(false|true)"),TP_GLOBAL}, +{TOK_BGFONT,_T("BGFont"),0,6,_T("[font_face [height [wieght] [/ITALIC] [/UNDERLINE] [/STRIKE]]]"),TP_GLOBAL}, +{TOK_BGGRADIENT,_T("BGGradient"),0,3,_T("(off | [top_color [bottom_color [text_color]]])"),TP_GLOBAL}, +{TOK_BRANDINGTEXT,_T("BrandingText"),1,1,_T("[/TRIM(LEFT|RIGHT|CENTER)] installer_text"),TP_GLOBAL}, +{TOK_BRINGTOFRONT,_T("BringToFront"),0,0,_T(""),TP_CODE}, +{TOK_CALL,_T("Call"),1,0,_T("function_name | [:label_name]"),TP_CODE}, +{TOK_CALLINSTDLL,_T("CallInstDLL"),2,1,_T("dll_path_on_target.dll function"),TP_CODE}, +{TOK_CAPTION,_T("Caption"),1,0,_T("installer_caption"),TP_GLOBAL|TP_PAGEEX}, +{TOK_CHANGEUI,_T("ChangeUI"),2,0,_T("(all|dlg_id) ui_file.exe"),TP_GLOBAL}, +{TOK_CLEARERRORS,_T("ClearErrors"),0,0,_T(""),TP_CODE}, +{TOK_COMPTEXT,_T("ComponentText"),0,3,_T("[component_page_description] [component_subtext1] [component_subtext2]"),TP_PG}, +{TOK_GETDLLVERSION,_T("GetDLLVersion"),3,0,_T("filename $(user_var: high output) $(user_var: low output)"),TP_CODE}, +{TOK_GETDLLVERSIONLOCAL,_T("GetDLLVersionLocal"),3,0,_T("localfilename $(user_var: high output) $(user_var: low output)"),TP_CODE}, +{TOK_GETFILETIME,_T("GetFileTime"),3,0,_T("file $(user_var: high output) $(user_var: low output)"),TP_CODE}, +{TOK_GETFILETIMELOCAL,_T("GetFileTimeLocal"),3,0,_T("localfile $(user_var: high output) $(user_var: low output)"),TP_CODE}, +{TOK_COPYFILES,_T("CopyFiles"),2,3,_T("[/SILENT] [/FILESONLY] source_path destination_path [total_size_in_kb]"),TP_CODE}, +{TOK_CRCCHECK,_T("CRCCheck"),1,0,_T("(on|force|off)"),TP_GLOBAL}, +{TOK_CREATEDIR,_T("CreateDirectory"),1,0,_T("directory_name"),TP_CODE}, +{TOK_CREATEFONT,_T("CreateFont"),2,5,_T("$(user_var: handle output) face_name [height wieght /ITALIC /UNDERLINE /STRIKE]"),TP_CODE}, +{TOK_CREATESHORTCUT,_T("CreateShortCut"),2,6,_T("shortcut_name.lnk shortcut_target [parameters [icon_file [icon index [showmode [hotkey [comment]]]]]]\n showmode=(SW_SHOWNORMAL|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED)\n hotkey=(ALT|CONTROL|EXT|SHIFT)|(F1-F24|A-Z)"),TP_CODE}, +{TOK_DBOPTIMIZE,_T("SetDatablockOptimize"),1,0,_T("(off|on)"),TP_ALL}, +{TOK_DELETEINISEC,_T("DeleteINISec"),2,0,_T("ini_file section_name"),TP_CODE}, +{TOK_DELETEINISTR,_T("DeleteINIStr"),3,0,_T("ini_file section_name entry_name"),TP_CODE}, +{TOK_DELETEREGKEY,_T("DeleteRegKey"),2,1,_T("[/ifempty] root_key subkey\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_DELETEREGVALUE,_T("DeleteRegValue"),3,0,_T("root_key subkey entry_name\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_DELETE,_T("Delete"),1,1,_T("[/REBOOTOK] filespec"),TP_CODE}, +{TOK_DETAILPRINT,_T("DetailPrint"),1,0,_T("message"),TP_CODE}, +{TOK_DIRTEXT,_T("DirText"),0,4,_T("[directory_page_description] [directory_page_subtext] [browse_button_text] [browse_dlg_text]"),TP_PG}, +//{TOK_DIRSHOW,_T("DirShow"),1,0,_T("(show|hide)"),TP_PG}, +{TOK_DIRSHOW,_T("DirShow"),0,0,_T("doesn't currently work"),TP_ALL}, +{TOK_DIRVAR,_T("DirVar"),1,0,_T("$(user_var: dir in/out))"),TP_PAGEEX}, +{TOK_DIRVERIFY,_T("DirVerify"),1,0,_T("auto|leave"),TP_PAGEEX}, +{TOK_GETINSTDIRERROR,_T("GetInstDirError"),1,0,_T("$(user_var: error output)"),TP_CODE}, +{TOK_ROOTDIRINST,_T("AllowRootDirInstall"),1,0,_T("(true|false)"),TP_GLOBAL}, +{TOK_CHECKBITMAP,_T("CheckBitmap"),1,0,_T("local_bitmap.bmp"),TP_GLOBAL}, +{TOK_ENABLEWINDOW,_T("EnableWindow"),2,0,_T("hwnd (1|0)"),TP_CODE}, +{TOK_ENUMREGKEY,_T("EnumRegKey"),4,0,_T("$(user_var: output) rootkey subkey index\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_ENUMREGVAL,_T("EnumRegValue"),4,0,_T("$(user_var: output) rootkey subkey index\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_EXCH,_T("Exch"),0,1,_T("[$(user_var)] | [stack_item_index]"),TP_CODE}, +{TOK_EXEC,_T("Exec"),1,0,_T("command_line"),TP_CODE}, +{TOK_EXECWAIT,_T("ExecWait"),1,1,_T("command_line [$(user_var: return value)]"),TP_CODE}, +{TOK_EXECSHELL,_T("ExecShell"),2,2,_T("(open|print|etc) command_line [parameters [showmode]]\n showmode=(SW_SHOWNORMAL|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED|SW_HIDE)"),TP_CODE}, +{TOK_EXPANDENVSTRS,_T("ExpandEnvStrings"),2,0,_T("$(user_var: output) string"),TP_CODE}, +{TOK_FINDWINDOW,_T("FindWindow"),2,3,_T("$(user_var: handle output) WindowClass [WindowTitle] [Window_Parent] [Child_After]"),TP_CODE}, +{TOK_FINDCLOSE,_T("FindClose"),1,0,_T("$(user_var: handle input)"),TP_CODE}, +{TOK_FINDFIRST,_T("FindFirst"),3,0,_T("$(user_var: handle output) $(user_var: filename output) filespec"),TP_CODE}, +{TOK_FINDNEXT,_T("FindNext"),2,0,_T("$(user_var: handle input) $(user_var: filename output)"),TP_CODE}, +{TOK_FILE,_T("File"),1,-1,_T("[/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |\n /oname=outfile one_file_only)"),TP_CODE}, +{TOK_FILEBUFSIZE,_T("FileBufSize"),1,0,_T("buf_size_mb"),TP_ALL}, +{TOK_FLUSHINI,_T("FlushINI"),1,0,_T("ini_file"),TP_CODE}, +{TOK_RESERVEFILE,_T("ReserveFile"),1,-1,_T("[/nonfatal] [/r] [/x filespec [...]] file [file...]"),TP_ALL}, +{TOK_FILECLOSE,_T("FileClose"),1,0,_T("$(user_var: handle input)"),TP_CODE}, +{TOK_FILEERRORTEXT,_T("FileErrorText"),0,2,_T("[text (can contain $0)] [text without ignore (can contain $0)]"),TP_GLOBAL}, +{TOK_FILEOPEN,_T("FileOpen"),3,0,_T("$(user_var: handle output) filename openmode\n openmode=r|w|a"),TP_CODE}, +{TOK_FILEREAD,_T("FileRead"),2,1,_T("$(user_var: handle input) $(user_var: text output) [maxlen]"),TP_CODE}, +{TOK_FILEWRITE,_T("FileWrite"),2,0,_T("$(user_var: handle input) text"),TP_CODE}, +{TOK_FILEREADBYTE,_T("FileReadByte"),2,0,_T("$(user_var: handle input) $(user_var: bytevalue output)"),TP_CODE}, +{TOK_FILEWRITEBYTE,_T("FileWriteByte"),2,0,_T("$(user_var: handle input) bytevalue"),TP_CODE}, +{TOK_FILESEEK,_T("FileSeek"),2,2,_T("$(user_var: handle input) offset [mode] [$(user_var: new position output)]\n mode=SET|CUR|END"),TP_CODE}, +{TOK_FUNCTION,_T("Function"),1,0,_T("function_name"),TP_GLOBAL}, +{TOK_FUNCTIONEND,_T("FunctionEnd"),0,0,_T(""),TP_FUNC}, +{TOK_GETDLGITEM,_T("GetDlgItem"),3,0,_T("$(user_var: handle output) dialog item_id"),TP_CODE}, +{TOK_GETFULLPATHNAME,_T("GetFullPathName"),2,1,_T("[/SHORT] $(user_var: result) path_or_file"),TP_CODE}, +{TOK_GETTEMPFILENAME,_T("GetTempFileName"),1,1,_T("$(user_var: name output) [base_dir]"),TP_CODE}, +{TOK_HIDEWINDOW,_T("HideWindow"),0,0,_T(""),TP_CODE}, +{TOK_ICON,_T("Icon"),1,0,_T("local_icon.ico"),TP_GLOBAL}, +{TOK_IFABORT,_T("IfAbort"),1,1,_T("label_to_goto_if_abort [label_to_goto_if_no_abort]"),TP_CODE}, +{TOK_IFERRORS,_T("IfErrors"),1,1,_T("label_to_goto_if_errors [label_to_goto_if_no_errors]"),TP_CODE}, +{TOK_IFFILEEXISTS,_T("IfFileExists"),2,1,_T("filename label_to_goto_if_file_exists [label_to_goto_otherwise]"),TP_CODE}, +{TOK_IFREBOOTFLAG,_T("IfRebootFlag"),1,1,_T("jump_if_set [jump_if_not_set]"),TP_CODE}, +{TOK_IFSILENT,_T("IfSilent"),1,1,_T("jump_if_silent [jump_if_not_silent]"),TP_CODE}, +{TOK_INSTALLDIRREGKEY,_T("InstallDirRegKey"),3,0,_T("root_key subkey entry_name\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)"),TP_GLOBAL}, +{TOK_INSTCOLORS,_T("InstallColors"),1,1,_T("(/windows | (foreground_color background_color))"),TP_GLOBAL}, +{TOK_INSTDIR,_T("InstallDir"),1,0,_T("default_install_directory"),TP_GLOBAL}, +{TOK_INSTPROGRESSFLAGS,_T("InstProgressFlags"),0,-1,_T("[flag [...]]\n flag={smooth|colored}"),TP_GLOBAL}, +{TOK_INSTTYPE,_T("InstType"),1,0,_T("[un.]install_type_name | /NOCUSTOM | /CUSTOMSTRING=str | /COMPONENTSONLYONCUSTOM"),TP_GLOBAL}, +{TOK_INTOP,_T("IntOp"),3,1,_T("$(user_var: result) val1 OP [val2]\n OP=(+ - * / % | & ^ ~ ! || && << >>)"),TP_CODE}, +{TOK_INTCMP,_T("IntCmp"),3,2,_T("val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]"),TP_CODE}, +{TOK_INTCMPU,_T("IntCmpU"),3,2,_T("val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]"),TP_CODE}, +{TOK_INTFMT,_T("IntFmt"),3,0,_T("$(user_var: output) format_string input"),TP_CODE}, +{TOK_ISWINDOW,_T("IsWindow"),2,1,_T("hwnd jump_if_window [jump_if_not_window]"),TP_CODE}, +{TOK_GOTO,_T("Goto"),1,0,_T("label"),TP_CODE}, +{TOK_LANGSTRING,_T("LangString"),3,0,_T("[un.]name lang_id string"),TP_GLOBAL}, +{TOK_LANGSTRINGUP,_T("LangStringUP"),0,0,_T("obsolete, use LangString."),TP_ALL}, +{TOK_LICENSEDATA,_T("LicenseData"),1,0,_T("local_file_that_has_license_text | license_lang_string"),TP_PG}, +{TOK_LICENSEFORCESELECTION,_T("LicenseForceSelection"),1,2,_T("(checkbox [accept_text] | radiobuttons [accept_text] [decline_text] | off)"),TP_PG}, +{TOK_LICENSELANGSTRING,_T("LicenseLangString"),3,0,_T("name lang_id license_path"),TP_GLOBAL}, +{TOK_LICENSETEXT,_T("LicenseText"),1,1,_T("license_page_description [license_button_text]"),TP_PG}, +{TOK_LICENSEBKCOLOR,_T("LicenseBkColor"),1,0,_T("background_color"),TP_GLOBAL}, +{TOK_LOADNLF,_T("LoadLanguageFile"),1,0,_T("language.nlf"),TP_GLOBAL}, +{TOK_LOGSET,_T("LogSet"),1,0,_T("on|off"),TP_CODE}, +{TOK_LOGTEXT,_T("LogText"),1,0,_T("text"),TP_CODE}, +{TOK_MESSAGEBOX,_T("MessageBox"),2,6,_T("mode messagebox_text [/SD return] [return_check label_to_goto_if_equal [return_check2 label2]]\n mode=modeflag[|modeflag[|modeflag[...]]]\n ") + _T("modeflag=(MB_ABORTRETRYIGNORE|MB_OK|MB_OKCANCEL|MB_RETRYCANCEL|MB_YESNO|MB_YESNOCANCEL|MB_ICONEXCLAMATION|MB_ICONINFORMATION|MB_ICONQUESTION|MB_ICONSTOP|MB_USERICON|MB_TOPMOST|MB_SETFOREGROUND|MB_RIGHT"),TP_CODE}, +{TOK_NOP,_T("Nop"),0,0,_T(""),TP_CODE}, +{TOK_NAME,_T("Name"),1,1,_T("installer_name installer_name_doubled_ampersands"),TP_GLOBAL}, +{TOK_OUTFILE,_T("OutFile"),1,0,_T("install_output.exe"),TP_GLOBAL}, #ifdef NSIS_SUPPORT_CODECALLBACKS -{TOK_PAGE,"Page",1,4,"((custom [creator_function] [leave_function] [caption]) | ((license|components|directory|instfiles|uninstConfirm) [pre_function] [show_function] [leave_function])) [/ENABLECANCEL]",TP_GLOBAL}, +{TOK_PAGE,_T("Page"),1,4,_T("((custom [creator_function] [leave_function] [caption]) | ((license|components|directory|instfiles|uninstConfirm) [pre_function] [show_function] [leave_function])) [/ENABLECANCEL]"),TP_GLOBAL}, #else -{TOK_PAGE,"Page",1,1,"license|components|directory|instfiles|uninstConfirm [/ENABLECANCEL]",TP_GLOBAL}, +{TOK_PAGE,_T("Page"),1,1,_T("license|components|directory|instfiles|uninstConfirm [/ENABLECANCEL]"),TP_GLOBAL}, #endif -{TOK_PAGECALLBACKS,"PageCallbacks",0,3,"([creator_function] [leave_function]) | ([pre_function] [show_function] [leave_function])",TP_PAGEEX}, -{TOK_PAGEEX,"PageEx",1,0,"[un.](custom|uninstConfirm|license|components|directory|instfiles)",TP_GLOBAL}, -{TOK_PAGEEXEND,"PageExEnd",0,0,"",TP_PAGEEX}, -{TOK_POP,"Pop",1,0,"$(user_var: output)",TP_CODE}, -{TOK_PUSH,"Push",1,0,"string",TP_CODE}, -{TOK_QUIT,"Quit",0,0,"",TP_CODE}, -{TOK_READINISTR,"ReadINIStr",4,0,"$(user_var: output) ini_file section entry_name",TP_CODE}, -{TOK_READREGDWORD,"ReadRegDWORD",4,0,"$(user_var: output) rootkey subkey entry\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_READREGSTR,"ReadRegStr",4,0,"$(user_var: output) rootkey subkey entry\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_READENVSTR,"ReadEnvStr",2,0,"$(user_var: output) name",TP_CODE}, -{TOK_REBOOT,"Reboot",0,0,"",TP_CODE}, -{TOK_REGDLL,"RegDLL",1,1,"dll_path_on_target.dll [entrypoint_symbol]",TP_CODE}, -{TOK_RENAME,"Rename",2,1,"[/REBOOTOK] source_file destination_file",TP_CODE}, -{TOK_RET,"Return",0,0,"",TP_CODE}, -{TOK_RMDIR,"RMDir",1,2,"[/r] [/REBOOTOK] directory_name",TP_CODE}, -{TOK_SECTION,"Section",0,3,"[/o] [-][un.][section_name] [section index output]",TP_GLOBAL}, -{TOK_SECTIONEND,"SectionEnd",0,0,"",TP_SEC}, -{TOK_SECTIONIN,"SectionIn",1,-1,"InstTypeIdx [InstTypeIdx [...]]",TP_SEC}, -{TOK_SUBSECTION,"SubSection",1,2,"deprecated - use SectionGroup",TP_GLOBAL}, -{TOK_SECTIONGROUP,"SectionGroup",1,2,"[/e] [un.]section_group_name [section index output]",TP_GLOBAL}, -{TOK_SUBSECTIONEND,"SubSectionEnd",0,0,"deprecated - use SectionGroupEnd",TP_GLOBAL}, -{TOK_SECTIONGROUPEND,"SectionGroupEnd",0,0,"",TP_GLOBAL}, -{TOK_SEARCHPATH,"SearchPath",2,0,"$(user_var: result) filename",TP_CODE}, -{TOK_SECTIONSETFLAGS,"SectionSetFlags",2,0,"section_index flags",TP_CODE}, -{TOK_SECTIONGETFLAGS,"SectionGetFlags",2,0,"section_index $(user_var: output flags)",TP_CODE}, -{TOK_SECTIONSETINSTTYPES,"SectionSetInstTypes",2,0,"section_index inst_types",TP_CODE}, -{TOK_SECTIONGETINSTTYPES,"SectionGetInstTypes",2,0,"section_index $(user_var: output inst_types)",TP_CODE}, -{TOK_SECTIONGETTEXT,"SectionGetText",2,0,"section_index $(user_var: output text)",TP_CODE}, -{TOK_SECTIONSETTEXT,"SectionSetText",2,0,"section_index text_string",TP_CODE}, -{TOK_SECTIONGETSIZE,"SectionGetSize",2,0,"section_index $(user_var: output size)",TP_CODE}, -{TOK_SECTIONSETSIZE,"SectionSetSize",2,0,"section_index new_size",TP_CODE}, -{TOK_GETCURINSTTYPE,"GetCurInstType",1,0,"$(user_var: output inst_type_idx)",TP_CODE}, -{TOK_SETCURINSTTYPE,"SetCurInstType",1,0,"inst_type_idx",TP_CODE}, -{TOK_INSTTYPESETTEXT,"InstTypeSetText",2,0,"insttype_index flags",TP_CODE}, -{TOK_INSTTYPEGETTEXT,"InstTypeGetText",2,0,"insttype_index $(user_var: output flags)",TP_CODE}, -{TOK_SENDMESSAGE,"SendMessage",4,2,"hwnd message [wparam|STR:wParam] [lparam|STR:lParam] [$(user_var: return value)] [/TIMEOUT=X]",TP_CODE}, -{TOK_SETAUTOCLOSE,"SetAutoClose",1,0,"(false|true)",TP_CODE}, -{TOK_SETCTLCOLORS,"SetCtlColors",2,2,"hwnd [/BRANDING] [text_color] [transparent|bg_color]",TP_CODE}, -{TOK_SETBRANDINGIMAGE,"SetBrandingImage",1,2,"[/IMGID=image_item_id_in_dialog] [/RESIZETOFIT] bitmap.bmp",TP_CODE}, -{TOK_SETCOMPRESS,"SetCompress",1,0,"(off|auto|force)",TP_ALL}, -{TOK_SETCOMPRESSOR,"SetCompressor",1,2,"[/FINAL] [/SOLID] (zlib|bzip2|lzma)",TP_GLOBAL}, -{TOK_SETCOMPRESSORDICTSIZE,"SetCompressorDictSize",1,0,"dict_size_mb",TP_ALL}, -{TOK_SETCOMPRESSIONLEVEL,"SetCompressionLevel",1,0,"level_0-9",TP_ALL}, -{TOK_SETDATESAVE,"SetDateSave",1,0,"(off|on)",TP_ALL}, -{TOK_SETDETAILSVIEW,"SetDetailsView",1,0,"(hide|show)",TP_CODE}, -{TOK_SETDETAILSPRINT,"SetDetailsPrint",1,0,"(none|listonly|textonly|both)",TP_CODE}, -{TOK_SETERRORS,"SetErrors",0,0,"",TP_CODE}, -{TOK_SETERRORLEVEL,"SetErrorLevel",1,0,"error_level",TP_CODE}, -{TOK_GETERRORLEVEL,"GetErrorLevel",1,0,"$(user_var: output)",TP_CODE}, -{TOK_SETFILEATTRIBUTES,"SetFileAttributes",2,0,"file attribute[|attribute[...]]\n attribute=(NORMAL|ARCHIVE|HIDDEN|OFFLINE|READONLY|SYSTEM|TEMPORARY|0)",TP_CODE}, -{TOK_SETFONT,"SetFont",2,1,"[/LANG=lang_id] font_face_name font_size",TP_GLOBAL}, -{TOK_SETOUTPATH,"SetOutPath",1,0,"output_path",TP_CODE}, -{TOK_SETOVERWRITE,"SetOverwrite",1,0,"on|off|try|ifnewer|ifdiff",TP_ALL}, -{TOK_SETPLUGINUNLOAD,"SetPluginUnload",1,0,"deprecated - plug-ins should handle this on their own",TP_ALL}, -{TOK_SETREBOOTFLAG,"SetRebootFlag",1,0,"true|false",TP_CODE}, -{TOK_SETREGVIEW,"SetRegView",1,0,"32|64|lastused",TP_CODE}, -{TOK_SETSHELLVARCONTEXT,"SetShellVarContext",1,0,"all|current",TP_CODE}, -{TOK_SETSILENT,"SetSilent",1,0,"silent|normal",TP_CODE}, -{TOK_SHOWDETAILS,"ShowInstDetails",1,0,"(hide|show|nevershow)",TP_GLOBAL}, -{TOK_SHOWDETAILSUNINST,"ShowUninstDetails",1,0,"(hide|show|nevershow)",TP_GLOBAL}, -{TOK_SHOWWINDOW,"ShowWindow",2,0,"hwnd show_state",TP_CODE}, -{TOK_SILENTINST,"SilentInstall",1,0,"(normal|silent|silentlog)",TP_GLOBAL}, -{TOK_SILENTUNINST,"SilentUnInstall",1,0,"(normal|silent)",TP_GLOBAL}, -{TOK_SLEEP,"Sleep",1,0,"sleep_time_in_ms",TP_CODE}, -{TOK_STRCMP,"StrCmp",3,1,"str1 str2 label_to_goto_if_equal [label_to_goto_if_not]",TP_CODE}, -{TOK_STRCMPS,"StrCmpS",3,1,"str1 str2 label_to_goto_if_equal [label_to_goto_if_not]",TP_CODE}, -{TOK_STRCPY,"StrCpy",2,2,"$(user_var: output) str [maxlen] [startoffset]",TP_CODE}, -{TOK_STRLEN,"StrLen",2,0,"$(user_var: length output) str",TP_CODE}, -{TOK_SUBCAPTION,"SubCaption",2,0,"page_number(0-4) new_subcaption",TP_GLOBAL}, -{TOK_UNINSTALLEXENAME,"UninstallExeName",0,0,"no longer supported, use WriteUninstaller from section.",TP_ALL}, -{TOK_UNINSTCAPTION,"UninstallCaption",1,0,"uninstaller_caption",TP_GLOBAL}, -{TOK_UNINSTICON,"UninstallIcon",1,0,"icon_on_local_system.ico",TP_GLOBAL}, +{TOK_PAGECALLBACKS,_T("PageCallbacks"),0,3,_T("([creator_function] [leave_function]) | ([pre_function] [show_function] [leave_function])"),TP_PAGEEX}, +{TOK_PAGEEX,_T("PageEx"),1,0,_T("[un.](custom|uninstConfirm|license|components|directory|instfiles)"),TP_GLOBAL}, +{TOK_PAGEEXEND,_T("PageExEnd"),0,0,_T(""),TP_PAGEEX}, +{TOK_POP,_T("Pop"),1,0,_T("$(user_var: output)"),TP_CODE}, +{TOK_PUSH,_T("Push"),1,0,_T("string"),TP_CODE}, +{TOK_QUIT,_T("Quit"),0,0,_T(""),TP_CODE}, +{TOK_READINISTR,_T("ReadINIStr"),4,0,_T("$(user_var: output) ini_file section entry_name"),TP_CODE}, +{TOK_READREGDWORD,_T("ReadRegDWORD"),4,0,_T("$(user_var: output) rootkey subkey entry\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_READREGSTR,_T("ReadRegStr"),4,0,_T("$(user_var: output) rootkey subkey entry\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_READENVSTR,_T("ReadEnvStr"),2,0,_T("$(user_var: output) name"),TP_CODE}, +{TOK_REBOOT,_T("Reboot"),0,0,_T(""),TP_CODE}, +{TOK_REGDLL,_T("RegDLL"),1,1,_T("dll_path_on_target.dll [entrypoint_symbol]"),TP_CODE}, +{TOK_RENAME,_T("Rename"),2,1,_T("[/REBOOTOK] source_file destination_file"),TP_CODE}, +{TOK_RET,_T("Return"),0,0,_T(""),TP_CODE}, +{TOK_RMDIR,_T("RMDir"),1,2,_T("[/r] [/REBOOTOK] directory_name"),TP_CODE}, +{TOK_SECTION,_T("Section"),0,3,_T("[/o] [-][un.][section_name] [section index output]"),TP_GLOBAL}, +{TOK_SECTIONEND,_T("SectionEnd"),0,0,_T(""),TP_SEC}, +{TOK_SECTIONIN,_T("SectionIn"),1,-1,_T("InstTypeIdx [InstTypeIdx [...]]"),TP_SEC}, +{TOK_SUBSECTION,_T("SubSection"),1,2,_T("deprecated - use SectionGroup"),TP_GLOBAL}, +{TOK_SECTIONGROUP,_T("SectionGroup"),1,2,_T("[/e] [un.]section_group_name [section index output]"),TP_GLOBAL}, +{TOK_SUBSECTIONEND,_T("SubSectionEnd"),0,0,_T("deprecated - use SectionGroupEnd"),TP_GLOBAL}, +{TOK_SECTIONGROUPEND,_T("SectionGroupEnd"),0,0,_T(""),TP_GLOBAL}, +{TOK_SEARCHPATH,_T("SearchPath"),2,0,_T("$(user_var: result) filename"),TP_CODE}, +{TOK_SECTIONSETFLAGS,_T("SectionSetFlags"),2,0,_T("section_index flags"),TP_CODE}, +{TOK_SECTIONGETFLAGS,_T("SectionGetFlags"),2,0,_T("section_index $(user_var: output flags)"),TP_CODE}, +{TOK_SECTIONSETINSTTYPES,_T("SectionSetInstTypes"),2,0,_T("section_index inst_types"),TP_CODE}, +{TOK_SECTIONGETINSTTYPES,_T("SectionGetInstTypes"),2,0,_T("section_index $(user_var: output inst_types)"),TP_CODE}, +{TOK_SECTIONGETTEXT,_T("SectionGetText"),2,0,_T("section_index $(user_var: output text)"),TP_CODE}, +{TOK_SECTIONSETTEXT,_T("SectionSetText"),2,0,_T("section_index text_string"),TP_CODE}, +{TOK_SECTIONGETSIZE,_T("SectionGetSize"),2,0,_T("section_index $(user_var: output size)"),TP_CODE}, +{TOK_SECTIONSETSIZE,_T("SectionSetSize"),2,0,_T("section_index new_size"),TP_CODE}, +{TOK_GETCURINSTTYPE,_T("GetCurInstType"),1,0,_T("$(user_var: output inst_type_idx)"),TP_CODE}, +{TOK_SETCURINSTTYPE,_T("SetCurInstType"),1,0,_T("inst_type_idx"),TP_CODE}, +{TOK_INSTTYPESETTEXT,_T("InstTypeSetText"),2,0,_T("insttype_index flags"),TP_CODE}, +{TOK_INSTTYPEGETTEXT,_T("InstTypeGetText"),2,0,_T("insttype_index $(user_var: output flags)"),TP_CODE}, +{TOK_SENDMESSAGE,_T("SendMessage"),4,2,_T("hwnd message [wparam|STR:wParam] [lparam|STR:lParam] [$(user_var: return value)] [/TIMEOUT=X]"),TP_CODE}, +{TOK_SETAUTOCLOSE,_T("SetAutoClose"),1,0,_T("(false|true)"),TP_CODE}, +{TOK_SETCTLCOLORS,_T("SetCtlColors"),2,2,_T("hwnd [/BRANDING] [text_color] [transparent|bg_color]"),TP_CODE}, +{TOK_SETBRANDINGIMAGE,_T("SetBrandingImage"),1,2,_T("[/IMGID=image_item_id_in_dialog] [/RESIZETOFIT] bitmap.bmp"),TP_CODE}, +{TOK_SETCOMPRESS,_T("SetCompress"),1,0,_T("(off|auto|force)"),TP_ALL}, +{TOK_SETCOMPRESSOR,_T("SetCompressor"),1,2,_T("[/FINAL] [/SOLID] (zlib|bzip2|lzma)"),TP_GLOBAL}, +{TOK_SETCOMPRESSORDICTSIZE,_T("SetCompressorDictSize"),1,0,_T("dict_size_mb"),TP_ALL}, +{TOK_SETCOMPRESSIONLEVEL,_T("SetCompressionLevel"),1,0,_T("level_0-9"),TP_ALL}, +{TOK_SETDATESAVE,_T("SetDateSave"),1,0,_T("(off|on)"),TP_ALL}, +{TOK_SETDETAILSVIEW,_T("SetDetailsView"),1,0,_T("(hide|show)"),TP_CODE}, +{TOK_SETDETAILSPRINT,_T("SetDetailsPrint"),1,0,_T("(none|listonly|textonly|both)"),TP_CODE}, +{TOK_SETERRORS,_T("SetErrors"),0,0,_T(""),TP_CODE}, +{TOK_SETERRORLEVEL,_T("SetErrorLevel"),1,0,_T("error_level"),TP_CODE}, +{TOK_GETERRORLEVEL,_T("GetErrorLevel"),1,0,_T("$(user_var: output)"),TP_CODE}, +{TOK_SETFILEATTRIBUTES,_T("SetFileAttributes"),2,0,_T("file attribute[|attribute[...]]\n attribute=(NORMAL|ARCHIVE|HIDDEN|OFFLINE|READONLY|SYSTEM|TEMPORARY|0)"),TP_CODE}, +{TOK_SETFONT,_T("SetFont"),2,1,_T("[/LANG=lang_id] font_face_name font_size"),TP_GLOBAL}, +{TOK_SETOUTPATH,_T("SetOutPath"),1,0,_T("output_path"),TP_CODE}, +{TOK_SETOVERWRITE,_T("SetOverwrite"),1,0,_T("on|off|try|ifnewer|ifdiff"),TP_ALL}, +{TOK_SETPLUGINUNLOAD,_T("SetPluginUnload"),1,0,_T("deprecated - plug-ins should handle this on their own"),TP_ALL}, +{TOK_SETREBOOTFLAG,_T("SetRebootFlag"),1,0,_T("true|false"),TP_CODE}, +{TOK_SETREGVIEW,_T("SetRegView"),1,0,_T("32|64|lastused"),TP_CODE}, +{TOK_SETSHELLVARCONTEXT,_T("SetShellVarContext"),1,0,_T("all|current"),TP_CODE}, +{TOK_SETSILENT,_T("SetSilent"),1,0,_T("silent|normal"),TP_CODE}, +{TOK_SHOWDETAILS,_T("ShowInstDetails"),1,0,_T("(hide|show|nevershow)"),TP_GLOBAL}, +{TOK_SHOWDETAILSUNINST,_T("ShowUninstDetails"),1,0,_T("(hide|show|nevershow)"),TP_GLOBAL}, +{TOK_SHOWWINDOW,_T("ShowWindow"),2,0,_T("hwnd show_state"),TP_CODE}, +{TOK_SILENTINST,_T("SilentInstall"),1,0,_T("(normal|silent|silentlog)"),TP_GLOBAL}, +{TOK_SILENTUNINST,_T("SilentUnInstall"),1,0,_T("(normal|silent)"),TP_GLOBAL}, +{TOK_SLEEP,_T("Sleep"),1,0,_T("sleep_time_in_ms"),TP_CODE}, +{TOK_STRCMP,_T("StrCmp"),3,1,_T("str1 str2 label_to_goto_if_equal [label_to_goto_if_not]"),TP_CODE}, +{TOK_STRCMPS,_T("StrCmpS"),3,1,_T("str1 str2 label_to_goto_if_equal [label_to_goto_if_not]"),TP_CODE}, +{TOK_STRCPY,_T("StrCpy"),2,2,_T("$(user_var: output) str [maxlen] [startoffset]"),TP_CODE}, +{TOK_STRLEN,_T("StrLen"),2,0,_T("$(user_var: length output) str"),TP_CODE}, +{TOK_SUBCAPTION,_T("SubCaption"),2,0,_T("page_number(0-4) new_subcaption"),TP_GLOBAL}, +{TOK_UNINSTALLEXENAME,_T("UninstallExeName"),0,0,_T("no longer supported, use WriteUninstaller from section."),TP_ALL}, +{TOK_UNINSTCAPTION,_T("UninstallCaption"),1,0,_T("uninstaller_caption"),TP_GLOBAL}, +{TOK_UNINSTICON,_T("UninstallIcon"),1,0,_T("icon_on_local_system.ico"),TP_GLOBAL}, #ifdef NSIS_SUPPORT_CODECALLBACKS -{TOK_UNINSTPAGE,"UninstPage",1,4,"((custom [creator_function] [leave_function] [caption]) | ((license|components|directory|instfiles|uninstConfirm) [pre_function] [show_function] [leave_function])) [/ENABLECANCEL]",TP_GLOBAL}, +{TOK_UNINSTPAGE,_T("UninstPage"),1,4,_T("((custom [creator_function] [leave_function] [caption]) | ((license|components|directory|instfiles|uninstConfirm) [pre_function] [show_function] [leave_function])) [/ENABLECANCEL]"),TP_GLOBAL}, #else -{TOK_UNINSTPAGE,"UninstPage",1,1,"license|components|directory|instfiles|uninstConfirm [/ENABLECANCEL]",TP_GLOBAL}, +{TOK_UNINSTPAGE,_T("UninstPage"),1,1,_T("license|components|directory|instfiles|uninstConfirm [/ENABLECANCEL]"),TP_GLOBAL}, #endif -{TOK_UNINSTTEXT,"UninstallText",1,1,"Text_to_go_on_uninstall_page [subtext]",TP_PG}, -{TOK_UNINSTSUBCAPTION,"UninstallSubCaption",2,0,"page_number(0-2) new_subcaption",TP_GLOBAL}, -{TOK_UNREGDLL,"UnRegDLL",1,0,"dll_path_on_target.dll",TP_CODE}, -{TOK_WINDOWICON,"WindowIcon",1,0,"on|off",TP_GLOBAL}, -{TOK_WRITEINISTR,"WriteINIStr",4,0,"ini_file section_name entry_name new_value",TP_CODE}, -{TOK_WRITEREGBIN,"WriteRegBin",4,0,"rootkey subkey entry_name hex_string_like_12848412AB\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_WRITEREGDWORD,"WriteRegDWORD",4,0,"rootkey subkey entry_name new_value_dword\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_WRITEREGSTR,"WriteRegStr",4,0,"rootkey subkey entry_name new_value_string\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_WRITEREGEXPANDSTR,"WriteRegExpandStr",4,0,"rootkey subkey entry_name new_value_string\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE}, -{TOK_WRITEUNINSTALLER,"WriteUninstaller",1,0,"uninstall_exe_name",TP_CODE}, -{TOK_XPSTYLE, "XPStyle",1,0,"(on|off)",TP_GLOBAL}, -{TOK_REQEXECLEVEL, "RequestExecutionLevel",1,0,"none|user|highest|admin",TP_GLOBAL}, -{TOK_P_PACKEXEHEADER,"!packhdr",2,0,"temp_file_name command_line_to_compress_that_temp_file",TP_ALL}, -{TOK_P_SYSTEMEXEC,"!system",1,2,"command [<|>|<>|=) retval]",TP_ALL}, -{TOK_P_EXECUTE,"!execute",1,0,"command",TP_ALL}, -{TOK_P_ADDINCLUDEDIR,"!AddIncludeDir",1,0,"dir",TP_ALL}, -{TOK_P_INCLUDE,"!include",1,1,"[/NONFATAL] filename.nsh",TP_ALL}, -{TOK_P_CD,"!cd",1,0,"absolute_or_relative_new_directory",TP_ALL}, -{TOK_P_IF,"!if",1,3,"[!] value [(==,!=,<=,<,>,>=,&&,||) value2] [...]",TP_ALL}, -{TOK_P_IFDEF,"!ifdef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL}, -{TOK_P_IFNDEF,"!ifndef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL}, -{TOK_P_ENDIF,"!endif",0,0,"",TP_ALL}, -{TOK_P_DEFINE,"!define",1,4,"([/date|/utcdate] symbol [value]) | (/file symbol filename) | (/math symbol val1 OP val2)\n OP=(+ - * / % & | ^)",TP_ALL}, -{TOK_P_UNDEF,"!undef",1,1,"symbol [value]",TP_ALL}, -{TOK_P_ELSE,"!else",0,-1,"[if[macro][n][def] ...]",TP_ALL}, -{TOK_P_ECHO,"!echo",1,0,"message",TP_ALL}, -{TOK_P_WARNING,"!warning",0,1,"[warning_message]",TP_ALL}, -{TOK_P_ERROR,"!error",0,1,"[error_message]",TP_ALL}, +{TOK_UNINSTTEXT,_T("UninstallText"),1,1,_T("Text_to_go_on_uninstall_page [subtext]"),TP_PG}, +{TOK_UNINSTSUBCAPTION,_T("UninstallSubCaption"),2,0,_T("page_number(0-2) new_subcaption"),TP_GLOBAL}, +{TOK_UNREGDLL,_T("UnRegDLL"),1,0,_T("dll_path_on_target.dll"),TP_CODE}, +{TOK_WINDOWICON,_T("WindowIcon"),1,0,_T("on|off"),TP_GLOBAL}, +{TOK_WRITEINISTR,_T("WriteINIStr"),4,0,_T("ini_file section_name entry_name new_value"),TP_CODE}, +{TOK_WRITEREGBIN,_T("WriteRegBin"),4,0,_T("rootkey subkey entry_name hex_string_like_12848412AB\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_WRITEREGDWORD,_T("WriteRegDWORD"),4,0,_T("rootkey subkey entry_name new_value_dword\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_WRITEREGSTR,_T("WriteRegStr"),4,0,_T("rootkey subkey entry_name new_value_string\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_WRITEREGEXPANDSTR,_T("WriteRegExpandStr"),4,0,_T("rootkey subkey entry_name new_value_string\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)"),TP_CODE}, +{TOK_WRITEUNINSTALLER,_T("WriteUninstaller"),1,0,_T("uninstall_exe_name"),TP_CODE}, +{TOK_XPSTYLE, _T("XPStyle"),1,0,_T("(on|off)"),TP_GLOBAL}, +{TOK_REQEXECLEVEL, _T("RequestExecutionLevel"),1,0,_T("none|user|highest|admin"),TP_GLOBAL}, +{TOK_P_PACKEXEHEADER,_T("!packhdr"),2,0,_T("temp_file_name command_line_to_compress_that_temp_file"),TP_ALL}, +{TOK_P_SYSTEMEXEC,_T("!system"),1,2,_T("command [<|>|<>|=) retval]"),TP_ALL}, +{TOK_P_EXECUTE,_T("!execute"),1,0,_T("command"),TP_ALL}, +{TOK_P_ADDINCLUDEDIR,_T("!AddIncludeDir"),1,0,_T("dir"),TP_ALL}, +{TOK_P_INCLUDE,_T("!include"),1,1,_T("[/NONFATAL] filename.nsh"),TP_ALL}, +{TOK_P_CD,_T("!cd"),1,0,_T("absolute_or_relative_new_directory"),TP_ALL}, +{TOK_P_IF,_T("!if"),1,3,_T("[!] value [(==,!=,<=,<,>,>=,&&,||) value2] [...]"),TP_ALL}, +{TOK_P_IFDEF,_T("!ifdef"),1,-1,_T("symbol [| symbol2 [& symbol3 [...]]]"),TP_ALL}, +{TOK_P_IFNDEF,_T("!ifndef"),1,-1,_T("symbol [| symbol2 [& symbol3 [...]]]"),TP_ALL}, +{TOK_P_ENDIF,_T("!endif"),0,0,_T(""),TP_ALL}, +{TOK_P_DEFINE,_T("!define"),1,4,_T("([/date|/utcdate] symbol [value]) | (/file symbol filename) | (/math symbol val1 OP val2)\n OP=(+ - * / % & | ^)"),TP_ALL}, +{TOK_P_UNDEF,_T("!undef"),1,1,_T("symbol [value]"),TP_ALL}, +{TOK_P_ELSE,_T("!else"),0,-1,_T("[if[macro][n][def] ...]"),TP_ALL}, +{TOK_P_ECHO,_T("!echo"),1,0,_T("message"),TP_ALL}, +{TOK_P_WARNING,_T("!warning"),0,1,_T("[warning_message]"),TP_ALL}, +{TOK_P_ERROR,_T("!error"),0,1,_T("[error_message]"),TP_ALL}, -{TOK_P_VERBOSE,"!verbose",1,0,"verbose_level | push | pop",TP_ALL}, +{TOK_P_VERBOSE,_T("!verbose"),1,0,_T("verbose_level | push | pop"),TP_ALL}, -{TOK_P_MACRO,"!macro",1,-1,"macroname [parms ...]",TP_ALL}, -{TOK_P_MACROEND,"!macroend",0,0,"",TP_ALL}, -{TOK_P_INSERTMACRO,"!insertmacro",1,-1,"macroname [parms ...]",TP_ALL}, -{TOK_P_IFMACRODEF,"!ifmacrodef",1,-1,"macro [| macro2 [& macro3 [...]]]",TP_ALL}, -{TOK_P_IFMACRONDEF,"!ifmacrondef",1,-1,"macro [| macro2 [& macro3 [...]]]",TP_ALL}, +{TOK_P_MACRO,_T("!macro"),1,-1,_T("macroname [parms ...]"),TP_ALL}, +{TOK_P_MACROEND,_T("!macroend"),0,0,_T(""),TP_ALL}, +{TOK_P_INSERTMACRO,_T("!insertmacro"),1,-1,_T("macroname [parms ...]"),TP_ALL}, +{TOK_P_IFMACRODEF,_T("!ifmacrodef"),1,-1,_T("macro [| macro2 [& macro3 [...]]]"),TP_ALL}, +{TOK_P_IFMACRONDEF,_T("!ifmacrondef"),1,-1,_T("macro [| macro2 [& macro3 [...]]]"),TP_ALL}, -{TOK_P_TEMPFILE,"!tempfile",1,0,"symbol",TP_ALL}, -{TOK_P_DELFILE,"!delfile",1,1,"[/nonfatal] file",TP_ALL}, -{TOK_P_APPENDFILE,"!appendfile",2,0,"file appended_line",TP_ALL}, +{TOK_P_TEMPFILE,_T("!tempfile"),1,0,_T("symbol"),TP_ALL}, +{TOK_P_DELFILE,_T("!delfile"),1,1,_T("[/nonfatal] file"),TP_ALL}, +{TOK_P_APPENDFILE,_T("!appendfile"),2,0,_T("file appended_line"),TP_ALL}, -{TOK_P_SEARCHPARSESTRING,"!searchparse",3,-1,"[/ignorecase] [/noerrors] [/file] source_string substring OUTPUTSYM1 [substring [OUTPUTSYM2 [substring ...]]]",TP_ALL}, -{TOK_P_SEARCHREPLACESTRING,"!searchreplace",4,1,"[/ignorecase] output_name source_string substring replacestring", TP_ALL}, +{TOK_P_SEARCHPARSESTRING,_T("!searchparse"),3,-1,_T("[/ignorecase] [/noerrors] [/file] source_string substring OUTPUTSYM1 [substring [OUTPUTSYM2 [substring ...]]]"),TP_ALL}, +{TOK_P_SEARCHREPLACESTRING,_T("!searchreplace"),4,1,_T("[/ignorecase] output_name source_string substring replacestring"), TP_ALL}, -{TOK_MISCBUTTONTEXT,"MiscButtonText",0,4,"[back button text] [next button text] [cancel button text] [close button text]",TP_GLOBAL}, -{TOK_DETAILSBUTTONTEXT,"DetailsButtonText",0,1,"[details button text]",TP_PG}, -{TOK_UNINSTBUTTONTEXT,"UninstallButtonText",0,1,"[uninstall button text]",TP_GLOBAL}, -{TOK_INSTBUTTONTEXT,"InstallButtonText",0,1,"[install button text]",TP_GLOBAL}, -{TOK_SPACETEXTS,"SpaceTexts",0,2,"none | ([space required text] [space available text])",TP_GLOBAL}, -{TOK_COMPLETEDTEXT,"CompletedText",0,1,"[completed text]",TP_PG}, +{TOK_MISCBUTTONTEXT,_T("MiscButtonText"),0,4,_T("[back button text] [next button text] [cancel button text] [close button text]"),TP_GLOBAL}, +{TOK_DETAILSBUTTONTEXT,_T("DetailsButtonText"),0,1,_T("[details button text]"),TP_PG}, +{TOK_UNINSTBUTTONTEXT,_T("UninstallButtonText"),0,1,_T("[uninstall button text]"),TP_GLOBAL}, +{TOK_INSTBUTTONTEXT,_T("InstallButtonText"),0,1,_T("[install button text]"),TP_GLOBAL}, +{TOK_SPACETEXTS,_T("SpaceTexts"),0,2,_T("none | ([space required text] [space available text])"),TP_GLOBAL}, +{TOK_COMPLETEDTEXT,_T("CompletedText"),0,1,_T("[completed text]"),TP_PG}, -{TOK_GETFUNCTIONADDR,"GetFunctionAddress",2,0,"output function",TP_CODE}, -{TOK_GETLABELADDR,"GetLabelAddress",2,0,"output label",TP_CODE}, -{TOK_GETCURRENTADDR,"GetCurrentAddress",1,0,"output",TP_CODE}, +{TOK_GETFUNCTIONADDR,_T("GetFunctionAddress"),2,0,_T("output function"),TP_CODE}, +{TOK_GETLABELADDR,_T("GetLabelAddress"),2,0,_T("output label"),TP_CODE}, +{TOK_GETCURRENTADDR,_T("GetCurrentAddress"),1,0,_T("output"),TP_CODE}, -{TOK_PLUGINDIR,"!AddPluginDir",1,0,"new_plugin_directory",TP_ALL}, -{TOK_INITPLUGINSDIR,"InitPluginsDir",0,0,"",TP_CODE}, +{TOK_PLUGINDIR,_T("!AddPluginDir"),1,0,_T("new_plugin_directory"),TP_ALL}, +{TOK_INITPLUGINSDIR,_T("InitPluginsDir"),0,0,_T(""),TP_CODE}, // Added by ramon 23 May 2003 -{TOK_ALLOWSKIPFILES,"AllowSkipFiles",1,0,"(off|on)",TP_ALL}, +{TOK_ALLOWSKIPFILES,_T("AllowSkipFiles"),1,0,_T("(off|on)"),TP_ALL}, // Added by ramon 3 jun 2003 -{TOK_DEFVAR,"Var",1,1,"[/GLOBAL] var_name",TP_ALL}, +{TOK_DEFVAR,_T("Var"),1,1,_T("[/GLOBAL] var_name"),TP_ALL}, // Added by ramon 6 jun 2003 -{TOK_VI_ADDKEY,"VIAddVersionKey",2,1,"/LANG=lang_id keyname value",TP_GLOBAL}, -{TOK_VI_SETPRODUCTVERSION,"VIProductVersion",1,0,"[version_string_X.X.X.X]",TP_GLOBAL}, -{TOK_LOCKWINDOW,"LockWindow",1,0,"(on|off)",TP_CODE}, +{TOK_VI_ADDKEY,_T("VIAddVersionKey"),2,1,_T("/LANG=lang_id keyname value"),TP_GLOBAL}, +{TOK_VI_SETPRODUCTVERSION,_T("VIProductVersion"),1,0,_T("[version_string_X.X.X.X]"),TP_GLOBAL}, +{TOK_LOCKWINDOW,_T("LockWindow"),1,0,_T("(on|off)"),TP_CODE}, }; -void CEXEBuild::print_help(char *commandname) +void CEXEBuild::print_help(TCHAR *commandname) { int x; for (x = 0; x < TOK__LAST; x ++) { if (!commandname || !stricmp(tokenlist[x].name,commandname)) { - ERROR_MSG("%s%s %s\n",commandname?"Usage: ":"",tokenlist[x].name,tokenlist[x].usage_str); + ERROR_MSG(_T("%s%s %s\n"),commandname?_T("Usage: "):_T(""),tokenlist[x].name,tokenlist[x].usage_str); if (commandname) break; } } if (x == TOK__LAST && commandname) { - ERROR_MSG("Invalid command \"%s\"\n",commandname); + ERROR_MSG(_T("Invalid command \"%s\"\n"),commandname); } } -bool CEXEBuild::is_valid_token(char *s) +bool CEXEBuild::is_valid_token(TCHAR *s) { for (int x = 0; x < TOK__LAST; x ++) if (!stricmp(tokenlist[x].name,s)) @@ -309,7 +311,7 @@ bool CEXEBuild::is_valid_token(char *s) return false; } -int CEXEBuild::get_commandtoken(char *s, int *np, int *op, int *pos) +int CEXEBuild::get_commandtoken(TCHAR *s, int *np, int *op, int *pos) { int x; for (x = 0; x < TOK__LAST; x ++) @@ -343,7 +345,7 @@ int CEXEBuild::GetCurrentTokenPlace() return TP_GLOBAL; } -int CEXEBuild::IsTokenPlacedRight(int pos, char *tok) +int CEXEBuild::IsTokenPlacedRight(int pos, TCHAR *tok) { if ((unsigned int) pos > (sizeof(tokenlist) / sizeof(tokenType))) return PS_OK; @@ -354,45 +356,45 @@ int CEXEBuild::IsTokenPlacedRight(int pos, char *tok) return PS_OK; } else { - char err[1024]; + TCHAR err[1024]; if (cp == TP_SEC) { - strcpy(err, "Error: command %s not valid in Section\n"); + _tcscpy(err, _T("Error: command %s not valid in Section\n")); } else if (cp == TP_FUNC) { - strcpy(err, "Error: command %s not valid in Function\n"); + _tcscpy(err, _T("Error: command %s not valid in Function\n")); } else if (cp == TP_PAGEEX) { - strcpy(err, "Error: command %s not valid in PageEx\n"); + _tcscpy(err, _T("Error: command %s not valid in PageEx\n")); } else { - strcpy(err, "Error: command %s not valid outside "); + _tcscpy(err, _T("Error: command %s not valid outside ")); if (tp & TP_SEC) - strcat(err, "Section"); + _tcscat(err, _T("Section")); if (tp & TP_FUNC) { if (tp & TP_SEC) { if (tp & TP_PAGEEX) { - strcat(err, ", "); + _tcscat(err, _T(", ")); } else { - strcat(err, " or "); + _tcscat(err, _T(" or ")); } } - strcat(err, "Function"); + _tcscat(err, _T("Function")); } if (tp & TP_PAGEEX) { if (tp & TP_CODE) { - strcat(err, " or "); + _tcscat(err, _T(" or ")); } - strcat(err, "PageEx"); + _tcscat(err, _T("PageEx")); } - strcat(err, "\n"); + _tcscat(err, _T("\n")); } ERROR_MSG(err, tok); return PS_ERROR; diff --git a/Source/tokens.h b/Source/tokens.h index e0f91f2a..bae2fa3c 100644 --- a/Source/tokens.h +++ b/Source/tokens.h @@ -1,277 +1,277 @@ -/* - * tokens.h - * - * This file is a part of NSIS. - * - * Copyright (C) 1999-2009 Nullsoft and Contributors - * - * Licensed under the zlib/libpng license (the "License"); - * you may not use this file except in compliance with the License. - * - * Licence details can be found in the file COPYING. - * - * This software is provided 'as-is', without any express or implied - * warranty. - */ - -#ifndef _TOKENS_H_ -#define _TOKENS_H_ - -// the order of these two lists no longer needs to match. -J -enum -{ - // header setting tokens - TOK_NAME, - TOK_CAPTION, - TOK_UNINSTCAPTION, - TOK_ICON, - TOK_UNINSTICON, - TOK_CHECKBITMAP, - TOK_WINDOWICON, - TOK_DIRTEXT, - TOK_COMPTEXT, - TOK_LICENSEBKCOLOR, - TOK_LICENSEDATA, - TOK_LICENSEFORCESELECTION, - TOK_LICENSELANGSTRING, - TOK_LICENSETEXT, - TOK_UNINSTTEXT, - TOK_SILENTINST, - TOK_SILENTUNINST, - TOK_INSTTYPE, - TOK_OUTFILE, - TOK_INSTDIR, - TOK_INSTALLDIRREGKEY, - TOK_UNINSTALLEXENAME, - TOK_CRCCHECK, - TOK_AUTOCLOSE, - TOK_SHOWDETAILS, - TOK_SHOWDETAILSUNINST, - TOK_DIRSHOW, - TOK_ROOTDIRINST, - TOK_BGFONT, - TOK_BGGRADIENT, - TOK_INSTCOLORS, - TOK_SUBCAPTION, - TOK_UNINSTSUBCAPTION, - TOK_BRANDINGTEXT, - TOK_FILEERRORTEXT, - TOK_INSTPROGRESSFLAGS, - TOK_XPSTYLE, - TOK_REQEXECLEVEL, - TOK_CHANGEUI, - TOK_ADDBRANDINGIMAGE, - TOK_SETFONT, - TOK_LOADNLF, - TOK_RESERVEFILE, - TOK_ALLOWSKIPFILES, - TOK_DEFVAR, - TOK_VI_ADDKEY, - TOK_VI_SETPRODUCTVERSION, - - TOK_MISCBUTTONTEXT, - TOK_DETAILSBUTTONTEXT, - TOK_UNINSTBUTTONTEXT, - TOK_INSTBUTTONTEXT, - TOK_SPACETEXTS, - TOK_COMPLETEDTEXT, - - TOK_LANGSTRING, - TOK_LANGSTRINGUP, - - // compression stuff - TOK_SETCOMPRESS, - TOK_DBOPTIMIZE, - TOK_SETCOMPRESSOR, - TOK_SETCOMPRESSORDICTSIZE, - TOK_SETCOMPRESSIONLEVEL, - TOK_FILEBUFSIZE, - - // system "preprocessor"ish tokens - TOK_P_IF, - TOK_P_IFDEF, - TOK_P_IFNDEF, - TOK_P_ELSE, - TOK_P_ENDIF, - TOK_P_DEFINE, - TOK_P_UNDEF, - TOK_P_PACKEXEHEADER, - TOK_P_SYSTEMEXEC, - TOK_P_EXECUTE, - TOK_P_ADDINCLUDEDIR, - TOK_P_INCLUDE, - TOK_P_CD, - TOK_P_ECHO, - TOK_P_WARNING, - TOK_P_ERROR, - - TOK_P_VERBOSE, - - TOK_P_MACRO, - TOK_P_MACROEND, - TOK_P_INSERTMACRO, - TOK_P_IFMACRODEF, - TOK_P_IFMACRONDEF, - - TOK_P_TEMPFILE, - TOK_P_DELFILE, - TOK_P_APPENDFILE, +/* + * tokens.h + * + * This file is a part of NSIS. + * + * Copyright (C) 1999-2009 Nullsoft and Contributors + * + * Licensed under the zlib/libpng license (the "License"); + * you may not use this file except in compliance with the License. + * + * Licence details can be found in the file COPYING. + * + * This software is provided 'as-is', without any express or implied + * warranty. + */ + +#ifndef _TOKENS_H_ +#define _TOKENS_H_ + +// the order of these two lists no longer needs to match. -J +enum +{ + // header setting tokens + TOK_NAME, + TOK_CAPTION, + TOK_UNINSTCAPTION, + TOK_ICON, + TOK_UNINSTICON, + TOK_CHECKBITMAP, + TOK_WINDOWICON, + TOK_DIRTEXT, + TOK_COMPTEXT, + TOK_LICENSEBKCOLOR, + TOK_LICENSEDATA, + TOK_LICENSEFORCESELECTION, + TOK_LICENSELANGSTRING, + TOK_LICENSETEXT, + TOK_UNINSTTEXT, + TOK_SILENTINST, + TOK_SILENTUNINST, + TOK_INSTTYPE, + TOK_OUTFILE, + TOK_INSTDIR, + TOK_INSTALLDIRREGKEY, + TOK_UNINSTALLEXENAME, + TOK_CRCCHECK, + TOK_AUTOCLOSE, + TOK_SHOWDETAILS, + TOK_SHOWDETAILSUNINST, + TOK_DIRSHOW, + TOK_ROOTDIRINST, + TOK_BGFONT, + TOK_BGGRADIENT, + TOK_INSTCOLORS, + TOK_SUBCAPTION, + TOK_UNINSTSUBCAPTION, + TOK_BRANDINGTEXT, + TOK_FILEERRORTEXT, + TOK_INSTPROGRESSFLAGS, + TOK_XPSTYLE, + TOK_REQEXECLEVEL, + TOK_CHANGEUI, + TOK_ADDBRANDINGIMAGE, + TOK_SETFONT, + TOK_LOADNLF, + TOK_RESERVEFILE, + TOK_ALLOWSKIPFILES, + TOK_DEFVAR, + TOK_VI_ADDKEY, + TOK_VI_SETPRODUCTVERSION, + + TOK_MISCBUTTONTEXT, + TOK_DETAILSBUTTONTEXT, + TOK_UNINSTBUTTONTEXT, + TOK_INSTBUTTONTEXT, + TOK_SPACETEXTS, + TOK_COMPLETEDTEXT, + + TOK_LANGSTRING, + TOK_LANGSTRINGUP, + + // compression stuff + TOK_SETCOMPRESS, + TOK_DBOPTIMIZE, + TOK_SETCOMPRESSOR, + TOK_SETCOMPRESSORDICTSIZE, + TOK_SETCOMPRESSIONLEVEL, + TOK_FILEBUFSIZE, + + // system "preprocessor"ish tokens + TOK_P_IF, + TOK_P_IFDEF, + TOK_P_IFNDEF, + TOK_P_ELSE, + TOK_P_ENDIF, + TOK_P_DEFINE, + TOK_P_UNDEF, + TOK_P_PACKEXEHEADER, + TOK_P_SYSTEMEXEC, + TOK_P_EXECUTE, + TOK_P_ADDINCLUDEDIR, + TOK_P_INCLUDE, + TOK_P_CD, + TOK_P_ECHO, + TOK_P_WARNING, + TOK_P_ERROR, + + TOK_P_VERBOSE, + + TOK_P_MACRO, + TOK_P_MACROEND, + TOK_P_INSERTMACRO, + TOK_P_IFMACRODEF, + TOK_P_IFMACRONDEF, + + TOK_P_TEMPFILE, + TOK_P_DELFILE, + TOK_P_APPENDFILE, TOK_P_SEARCHPARSESTRING, TOK_P_SEARCHREPLACESTRING, - - // section/function shit - TOK_SECTION, - TOK_SECTIONEND, - TOK_SECTIONIN, - TOK_SECTIONGROUP, - TOK_SECTIONGROUPEND, - TOK_SUBSECTION, - TOK_SUBSECTIONEND, - TOK_FUNCTION, - TOK_FUNCTIONEND, - TOK_ADDSIZE, - - // page ordering - TOK_PAGE, - TOK_UNINSTPAGE, - - // PageEx stuff - TOK_PAGEEX, - TOK_PAGEEXEND, - TOK_DIRVAR, - TOK_DIRVERIFY, - TOK_PAGECALLBACKS, - - TOK_GETINSTDIRERROR, - - // flag setters - TOK_SETDATESAVE, - TOK_SETOVERWRITE, - TOK_SETPLUGINUNLOAD, - - // instructions - TOK_NOP, - TOK_GOTO, - TOK_RET, - TOK_CALL, - TOK_SETOUTPATH, - TOK_CREATEDIR, - TOK_EXEC, - TOK_EXECWAIT, - TOK_EXECSHELL, - TOK_CALLINSTDLL, - TOK_REGDLL, - TOK_UNREGDLL, - TOK_RENAME, - TOK_MESSAGEBOX, - TOK_DELETEREGVALUE, - TOK_DELETEREGKEY, - TOK_WRITEREGSTR, - TOK_WRITEREGEXPANDSTR, - TOK_WRITEREGBIN, - TOK_WRITEREGDWORD, - TOK_DELETEINISEC, - TOK_DELETEINISTR, - TOK_FLUSHINI, - TOK_WRITEINISTR, - TOK_CREATESHORTCUT, - TOK_FINDWINDOW, - TOK_DELETE, - TOK_RMDIR, - TOK_FILE, - TOK_COPYFILES, - TOK_SETFILEATTRIBUTES, - TOK_SLEEP, - TOK_BRINGTOFRONT, - TOK_HIDEWINDOW, - TOK_IFFILEEXISTS, - TOK_ABORT, - TOK_QUIT, - TOK_SETDETAILSVIEW, - TOK_SETDETAILSPRINT, - TOK_SETAUTOCLOSE, - TOK_IFERRORS, - TOK_CLEARERRORS, - TOK_SETERRORS, - TOK_IFABORT, - TOK_STRCPY, - TOK_STRCMP, - TOK_STRCMPS, - TOK_GETTEMPFILENAME, - TOK_GETFUNCTIONADDR, - TOK_GETLABELADDR, - TOK_GETCURRENTADDR, - TOK_READINISTR, - TOK_READREGSTR, - TOK_READREGDWORD, - TOK_READENVSTR, - TOK_EXPANDENVSTRS, - TOK_DETAILPRINT, - TOK_SEARCHPATH, - TOK_GETDLLVERSION, - TOK_GETDLLVERSIONLOCAL, - TOK_GETFILETIME, - TOK_GETFILETIMELOCAL, - TOK_STRLEN, - TOK_INTOP, - TOK_INTCMP, - TOK_INTCMPU, - TOK_INTFMT, - TOK_ENUMREGKEY, - TOK_ENUMREGVAL, - TOK_PUSH, - TOK_POP, - TOK_EXCH, - TOK_SENDMESSAGE, - TOK_ISWINDOW, - TOK_GETDLGITEM, - TOK_SETCTLCOLORS, - TOK_FINDFIRST, - TOK_FINDNEXT, - TOK_FINDCLOSE, - TOK_FILEOPEN, - TOK_FILECLOSE, - TOK_FILEREAD, - TOK_FILEWRITE, - TOK_FILEREADBYTE, - TOK_FILEWRITEBYTE, - TOK_FILESEEK, - TOK_GETFULLPATHNAME, - TOK_REBOOT, - TOK_IFREBOOTFLAG, - TOK_SETREBOOTFLAG, - TOK_WRITEUNINSTALLER, - TOK_LOGSET, - TOK_LOGTEXT, - TOK_SETBRANDINGIMAGE, - TOK_SECTIONSETTEXT, - TOK_SECTIONGETTEXT, - TOK_SECTIONSETFLAGS, - TOK_SECTIONGETFLAGS, - TOK_SECTIONSETINSTTYPES, - TOK_SECTIONGETINSTTYPES, - TOK_SECTIONSETSIZE, - TOK_SECTIONGETSIZE, - TOK_INSTTYPESETTEXT, - TOK_INSTTYPEGETTEXT, - TOK_GETCURINSTTYPE, - TOK_SETCURINSTTYPE, - TOK_SETREGVIEW, - TOK_SETSHELLVARCONTEXT, - TOK_PLUGINDIR, - TOK_INITPLUGINSDIR, - TOK_CREATEFONT, - TOK_SHOWWINDOW, - TOK_ENABLEWINDOW, - TOK_SETSILENT, - TOK_IFSILENT, - TOK_SETERRORLEVEL, - TOK_GETERRORLEVEL, - TOK_LOCKWINDOW, - - TOK__LAST, - TOK__PLUGINCOMMAND -}; - -#endif//_TOKENS_H_ + + // section/function stuff + TOK_SECTION, + TOK_SECTIONEND, + TOK_SECTIONIN, + TOK_SECTIONGROUP, + TOK_SECTIONGROUPEND, + TOK_SUBSECTION, + TOK_SUBSECTIONEND, + TOK_FUNCTION, + TOK_FUNCTIONEND, + TOK_ADDSIZE, + + // page ordering + TOK_PAGE, + TOK_UNINSTPAGE, + + // PageEx stuff + TOK_PAGEEX, + TOK_PAGEEXEND, + TOK_DIRVAR, + TOK_DIRVERIFY, + TOK_PAGECALLBACKS, + + TOK_GETINSTDIRERROR, + + // flag setters + TOK_SETDATESAVE, + TOK_SETOVERWRITE, + TOK_SETPLUGINUNLOAD, + + // instructions + TOK_NOP, + TOK_GOTO, + TOK_RET, + TOK_CALL, + TOK_SETOUTPATH, + TOK_CREATEDIR, + TOK_EXEC, + TOK_EXECWAIT, + TOK_EXECSHELL, + TOK_CALLINSTDLL, + TOK_REGDLL, + TOK_UNREGDLL, + TOK_RENAME, + TOK_MESSAGEBOX, + TOK_DELETEREGVALUE, + TOK_DELETEREGKEY, + TOK_WRITEREGSTR, + TOK_WRITEREGEXPANDSTR, + TOK_WRITEREGBIN, + TOK_WRITEREGDWORD, + TOK_DELETEINISEC, + TOK_DELETEINISTR, + TOK_FLUSHINI, + TOK_WRITEINISTR, + TOK_CREATESHORTCUT, + TOK_FINDWINDOW, + TOK_DELETE, + TOK_RMDIR, + TOK_FILE, + TOK_COPYFILES, + TOK_SETFILEATTRIBUTES, + TOK_SLEEP, + TOK_BRINGTOFRONT, + TOK_HIDEWINDOW, + TOK_IFFILEEXISTS, + TOK_ABORT, + TOK_QUIT, + TOK_SETDETAILSVIEW, + TOK_SETDETAILSPRINT, + TOK_SETAUTOCLOSE, + TOK_IFERRORS, + TOK_CLEARERRORS, + TOK_SETERRORS, + TOK_IFABORT, + TOK_STRCPY, + TOK_STRCMP, + TOK_STRCMPS, + TOK_GETTEMPFILENAME, + TOK_GETFUNCTIONADDR, + TOK_GETLABELADDR, + TOK_GETCURRENTADDR, + TOK_READINISTR, + TOK_READREGSTR, + TOK_READREGDWORD, + TOK_READENVSTR, + TOK_EXPANDENVSTRS, + TOK_DETAILPRINT, + TOK_SEARCHPATH, + TOK_GETDLLVERSION, + TOK_GETDLLVERSIONLOCAL, + TOK_GETFILETIME, + TOK_GETFILETIMELOCAL, + TOK_STRLEN, + TOK_INTOP, + TOK_INTCMP, + TOK_INTCMPU, + TOK_INTFMT, + TOK_ENUMREGKEY, + TOK_ENUMREGVAL, + TOK_PUSH, + TOK_POP, + TOK_EXCH, + TOK_SENDMESSAGE, + TOK_ISWINDOW, + TOK_GETDLGITEM, + TOK_SETCTLCOLORS, + TOK_FINDFIRST, + TOK_FINDNEXT, + TOK_FINDCLOSE, + TOK_FILEOPEN, + TOK_FILECLOSE, + TOK_FILEREAD, + TOK_FILEWRITE, + TOK_FILEREADBYTE, + TOK_FILEWRITEBYTE, + TOK_FILESEEK, + TOK_GETFULLPATHNAME, + TOK_REBOOT, + TOK_IFREBOOTFLAG, + TOK_SETREBOOTFLAG, + TOK_WRITEUNINSTALLER, + TOK_LOGSET, + TOK_LOGTEXT, + TOK_SETBRANDINGIMAGE, + TOK_SECTIONSETTEXT, + TOK_SECTIONGETTEXT, + TOK_SECTIONSETFLAGS, + TOK_SECTIONGETFLAGS, + TOK_SECTIONSETINSTTYPES, + TOK_SECTIONGETINSTTYPES, + TOK_SECTIONSETSIZE, + TOK_SECTIONGETSIZE, + TOK_INSTTYPESETTEXT, + TOK_INSTTYPEGETTEXT, + TOK_GETCURINSTTYPE, + TOK_SETCURINSTTYPE, + TOK_SETREGVIEW, + TOK_SETSHELLVARCONTEXT, + TOK_PLUGINDIR, + TOK_INITPLUGINSDIR, + TOK_CREATEFONT, + TOK_SHOWWINDOW, + TOK_ENABLEWINDOW, + TOK_SETSILENT, + TOK_IFSILENT, + TOK_SETERRORLEVEL, + TOK_GETERRORLEVEL, + TOK_LOCKWINDOW, + + TOK__LAST, + TOK__PLUGINCOMMAND +}; + +#endif//_TOKENS_H_ diff --git a/Source/tstring.h b/Source/tstring.h new file mode 100644 index 00000000..9159397d --- /dev/null +++ b/Source/tstring.h @@ -0,0 +1,91 @@ +// tstring.h +// +// This file is a part of Unicode NSIS. +// +// Copyright (C) 2007-2009 Jim Park +// +// Licensed under the zlib/libpng license (the "License"); +// you may not use this file except in compliance with the License. +// +// This software is provided 'as-is', without any expressed or implied +// warranty. +// +// Provides TSTRING support. + +/* + Unicode support by Jim Park -- 07/23/2007 +*/ + +#ifndef _TSTRING_ +#define _TSTRING_ + +#include "tchar.h" +#include +//#include +//#include + +/* Abstract string type as well. */ +#ifdef _UNICODE +typedef std::wstring tstring; +typedef std::wofstream tofstream; +typedef std::wifstream tifstream; +// Use the following macros to open text files. +// #define FOPENTEXT(file, mode) _wfopen(file, mode ## L", ccs=Unicode") +FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode); +#define FOPENTEXT(file, mode) FileOpenUnicodeText(file, mode) +#else +typedef std::string tstring; +typedef std::ofstream tofstream; +typedef std::ifstream tifstream; +// Use the following macros to open text files. +#define FOPENTEXT(file, mode) fopen(file, mode) +#endif + +#ifndef _UNICODE +#define CtoTString(str) (str) +#define TtoCString(str) (str) +#else + +// This is a helpful little function for converting exceptions or +// other system type things that come back ANSI and must be +// utilized as either ANSI or WCHAR depending on _UNICODE. +class CtoTString +{ +public: + CtoTString(const char* str) + { + int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); + m_wStr = (wchar_t*) GlobalAlloc(GPTR, len*sizeof(wchar_t)); + MultiByteToWideChar(CP_ACP, 0, str, -1, m_wStr, len); + } + + ~CtoTString() { GlobalFree(m_wStr); m_wStr = 0; } + + operator const wchar_t* tstr() { return m_wStr; } + +private: + wchar_t* m_wStr; +}; + +// There may be system things that require C strings but we +// may actually have Unicode strings. +class TtoCString +{ +public: + TtoCString(const wchar_t* wStr) + { + int len = WideCharToMultiByte(CP_ACP, 0, wStr, -1, NULL, 0, 0, 0); + m_cStr = (char*) GlobalAlloc(GPTR, len); + WideCharToMultiByte(CP_ACP, 0, wStr, -1, m_cStr, len, 0, 0); + } + + ~TtoCString() { GlobalFree(m_cStr); m_cStr = 0; } + + operator const char*() { return m_cStr; } + +private: + char* m_cStr; +}; +#endif // _UNICODE + +#endif diff --git a/Source/uservars.h b/Source/uservars.h index c855bbfc..f652b66f 100644 --- a/Source/uservars.h +++ b/Source/uservars.h @@ -35,7 +35,7 @@ class UserVarsStringList : public SortedStringListND } ~UserVarsStringList() { } - int add(const char *name, int ref_count = 0 ) + int add(const TCHAR *name, int ref_count = 0 ) { int pos=SortedStringListND::add(name); if (pos == -1) return -1; @@ -50,18 +50,38 @@ class UserVarsStringList : public SortedStringListND return temp; } - int get(const char *name, int n_chars = -1) + /** + * Get the index of the string that matches 'name.' + * + * @param name The name of the string to search for. + * @param n_chars If -1, match entire string, otherwise compare only + * n_chars worth of characters. + * @return The index position of the structure where structure.name == + * name. + */ + int get(const TCHAR *name, int n_chars = -1) { int v=SortedStringListND::find(name, n_chars); if (v==-1) return -1; return (((struct uservarstring*)gr.get())[v].index); } + /** + * Get count of strings. + * + * @return The count of strings. + */ int getnum() { return index; } + /** + * Given the index of the structure, return the reference count. + * + * @return The reference count of the nth uservarstring structure. + * If not found, returns -1. + */ int get_reference(int idx) { int pos=get_internal_idx(idx); @@ -69,6 +89,12 @@ class UserVarsStringList : public SortedStringListND return (((struct uservarstring*)gr.get())[pos].reference); } + /** + * Given the index of the structure, increment the reference count. + * + * @return The previous reference count (before the increment). + * If not found, returns -1. + */ int inc_reference(int idx) { int pos=get_internal_idx(idx); @@ -76,12 +102,12 @@ class UserVarsStringList : public SortedStringListND return (((struct uservarstring*)gr.get())[pos].reference)-1; } - char *idx2name(int idx) + TCHAR *idx2name(int idx) { int pos=get_internal_idx(idx); if (pos==-1) return NULL; struct uservarstring *data=(struct uservarstring *)gr.get(); - return ((char*)strings.get() + data[pos].name); + return ((TCHAR*)strings.get() + data[pos].name); } private: diff --git a/Source/util.cpp b/Source/util.cpp index 2c0b07f0..df5d3c4a 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -13,17 +13,17 @@ * This software is provided 'as-is', without any express or implied * warranty. */ - +/* Unicode support by Jim Park -- 07/23/2007 */ #include "Platform.h" #include #include #include #include +#include "tchar.h" #include "exehead/fileform.h" #include "util.h" #include "strlist.h" #include "winchar.h" - #ifndef _WIN32 # include # include // for close(2) @@ -55,10 +55,10 @@ void dopause(void) { if (g_dopause) { - if (g_display_errors) fprintf(g_output,"MakeNSIS done - hit enter to close..."); + if (g_display_errors) _ftprintf(g_output,_T("MakeNSIS done - hit enter to close...")); fflush(stdout); int a; - while ((a=getchar()) != '\r' && a != '\n' && a != 27/*esc*/); + while ((a=_gettchar()) != _T('\r') && a != _T('\n') && a != 27/*esc*/); } } @@ -67,8 +67,8 @@ void dopause(void) // Returns -2 if the file is an invalid bitmap // Returns -3 if the size doesn't match // Returns -4 if the bpp doesn't match -int update_bitmap(CResourceEditor* re, WORD id, const char* filename, int width/*=0*/, int height/*=0*/, int maxbpp/*=0*/) { - FILE *f = FOPEN(filename, "rb"); +int update_bitmap(CResourceEditor* re, WORD id, const TCHAR* filename, int width/*=0*/, int height/*=0*/, int maxbpp/*=0*/) { + FILE *f = FOPEN(filename, _T("rb")); if (!f) return -1; if (fgetc(f) != 'B' || fgetc(f) != 'M') { @@ -134,23 +134,23 @@ int update_bitmap(CResourceEditor* re, WORD id, const char* filename, int width/ } #ifndef _WIN32 -char *CharPrev(const char *s, const char *p) { +TCHAR *CharPrev(const TCHAR *s, const TCHAR *p) { if (!s || !p || p < s) return NULL; while (*s) { - char *n = CharNext(s); + TCHAR *n = CharNext(s); if (n >= p) break; s = n; } - return (char *) s; + return (TCHAR *) s; } -char *CharNext(const char *s) { +TCHAR *CharNext(const TCHAR *s) { int l = 0; if (s && *s) l = max(1, mblen(s, MB_CUR_MAX)); - return (char *) s + l; + return (TCHAR *) s + l; } char *CharNextExA(WORD codepage, const char *s, int flags) { @@ -170,10 +170,10 @@ char *CharNextExA(WORD codepage, const char *s, int flags) { return (char *) np; } -int wsprintf(char *s, const char *format, ...) { +int wsprintf(TCHAR *s, const TCHAR *format, ...) { va_list val; va_start(val, format); - int res = vsnprintf(s, 1024, format, val); + int res = _vsntprintf(s, 1024, format, val); va_end(val); return res; } @@ -181,18 +181,18 @@ int wsprintf(char *s, const char *format, ...) { // iconv const inconsistency workaround by Alexandre Oliva template inline size_t nsis_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) + (size_t (*iconv_func)(iconv_t, T, size_t *, TCHAR**,size_t*), + iconv_t cd, TCHAR **inbuf, size_t *inbytesleft, + TCHAR **outbuf, size_t *outbytesleft) { return iconv_func (cd, (T)inbuf, inbytesleft, outbuf, outbytesleft); } -void static create_code_page_string(char *buf, size_t len, UINT code_page) { +void static create_code_page_string(TCHAR *buf, size_t len, UINT code_page) { if (code_page == CP_ACP) code_page = 1252; - snprintf(buf, len, "CP%d", code_page); + _sntprintf(buf, len, _T("CP%d"), code_page); } int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, @@ -270,10 +270,10 @@ int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, BOOL IsValidCodePage(UINT CodePage) { - char cp[128]; + TCHAR cp[128]; create_code_page_string(cp, sizeof(cp), CodePage); - iconv_t cd = iconv_open("UCS-2LE", cp); + iconv_t cd = iconv_open(_T("UCS-2LE"), cp); if (cd == (iconv_t) -1) return FALSE; @@ -282,37 +282,37 @@ BOOL IsValidCodePage(UINT CodePage) return TRUE; } -#define MY_ERROR_MSG(x) {if (g_display_errors) {fprintf(g_output,"%s", x);}} +#define MY_ERROR_MSG(x) {if (g_display_errors) {_ftprintf(g_output,_T("%s"), x);}} -char *my_convert(const char *path) +TCHAR *my_convert(const TCHAR *path) { // TODO: (orip) ref. this func. to use std::string? - char *converted_path = strdup(path); - size_t len = strlen(path); + TCHAR *converted_path = _tcsdup(path); + size_t len = _tcsclen(path); if(!converted_path) { - MY_ERROR_MSG("Error: could not allocate memory in my_convert()\n"); - return (char*) path; /* dirty */ + MY_ERROR_MSG(_T("Error: could not allocate memory in my_convert()\n")); + return (TCHAR*) path; /* dirty */ } /* Replace drive letter X: by /X */ if(len >= 2) { - if (path[1] == ':') + if (path[1] == _T(':')) { - converted_path[0] = '/'; - converted_path[1] = (char) tolower((int) path[0]); + converted_path[0] = _T('/'); + converted_path[1] = (TCHAR) tolower((int) path[0]); } } - char *p = converted_path; + TCHAR *p = converted_path; do { - if (*p == '\\') + if (*p == _T('\\')) { - *p = '/'; + *p = _T('/'); } p = CharNext(p); } @@ -321,25 +321,25 @@ char *my_convert(const char *path) return converted_path; } -void my_convert_free(char *converted_path) +void my_convert_free(TCHAR *converted_path) { free(converted_path); } -int my_open(const char *pathname, int flags) +int my_open(const TCHAR *pathname, int flags) { - char *converted_pathname = my_convert(pathname); + TCHAR *converted_pathname = my_convert(pathname); int result = open(converted_pathname, flags); my_convert_free(converted_pathname); return result; } -FILE *my_fopen(const char *path, const char *mode) +FILE *my_fopen(const TCHAR *path, const TCHAR *mode) { - char *converted_path = my_convert(path); + TCHAR *converted_path = my_convert(path); - FILE *result = fopen(converted_path, mode); + FILE *result = _tfopen(converted_path, mode); my_convert_free(converted_path); return result; } @@ -360,32 +360,32 @@ void operator delete [](void *p) throw() { if (p) free(p); } -size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) { - return strftime(s, max, fmt, tm); +size_t my_strftime(TCHAR *s, size_t max, const TCHAR *fmt, const struct tm *tm) { + return _tcsftime(s, max, fmt, tm); } -string get_full_path(const string &path) { +tstring get_full_path(const tstring &path) { #ifdef _WIN32 - char *throwaway; - char real_path[1024]; + TCHAR *throwaway; + TCHAR real_path[1024]; int rc = GetFullPathName(path.c_str(),1024,real_path,&throwaway); assert(rc <= 1024); // path size is limited by MAX_PATH (260) assert(rc != 0); // rc==0 in case of error - return string(real_path); + return tstring(real_path); #else//_WIN32 #ifdef PATH_MAX - static char buffer[PATH_MAX]; + static TCHAR buffer[PATH_MAX]; #else//PATH_MAX int path_max = pathconf(path.c_str(), _PC_PATH_MAX); if (path_max <= 0) path_max = 4096; - char *buffer = (char *) malloc(path_max); + TCHAR *buffer = (TCHAR *) malloc(path_max*sizeof(TCHAR)); if (!buffer) - return string(path); + return tstring(path); #endif//PATH_MAX if (!realpath(path.c_str(), buffer)) - strcpy(buffer, path.c_str()); - string result(buffer); + _tcscpy(buffer, path.c_str()); + tstring result(buffer); #ifndef PATH_MAX free(buffer); #endif//!PATH_MAX @@ -393,63 +393,63 @@ string get_full_path(const string &path) { #endif//_WIN32 } -string get_string_prefix(const string& str, const string& separator) { - const string::size_type last_separator_pos = str.rfind(separator); +tstring get_string_prefix(const tstring& str, const tstring& separator) { + const tstring::size_type last_separator_pos = str.rfind(separator); if (last_separator_pos == string::npos) return str; return str.substr(0, last_separator_pos); } -string get_string_suffix(const string& str, const string& separator) { - const string::size_type last_separator_pos = str.rfind(separator); - if (last_separator_pos == string::npos) +tstring get_string_suffix(const tstring& str, const tstring& separator) { + const tstring::size_type last_separator_pos = str.rfind(separator); + if (last_separator_pos == tstring::npos) return str; - return str.substr(last_separator_pos + separator.size(), string::npos); + return str.substr(last_separator_pos + separator.size(), tstring::npos); } -string get_dir_name(const string& path) { +tstring get_dir_name(const tstring& path) { return get_string_prefix(path, PLATFORM_PATH_SEPARATOR_STR); } -string get_file_name(const string& path) { +tstring get_file_name(const tstring& path) { return get_string_suffix(path, PLATFORM_PATH_SEPARATOR_STR); } -string get_executable_path(const char* argv0) { +tstring get_executable_path(const TCHAR* argv0) { #ifdef _WIN32 - char temp_buf[MAX_PATH+1]; - temp_buf[0] = '\0'; + TCHAR temp_buf[MAX_PATH+1]; + temp_buf[0] = _T('\0'); int rc = GetModuleFileName(NULL,temp_buf,MAX_PATH); assert(rc != 0); - return string(temp_buf); + return tstring(temp_buf); #elif __APPLE__ - char temp_buf[MAXPATHLEN+1]; + TCHAR temp_buf[MAXPATHLEN+1]; unsigned int buf_len = MAXPATHLEN; int rc = Apple::_NSGetExecutablePath(temp_buf, &buf_len); assert(rc == 0); - return string(temp_buf); + return tstring(temp_buf); #else /* Linux/BSD/POSIX/etc */ - const char *envpath = getenv("_"); + const TCHAR *envpath = _tgetenv(_T("_")); if( envpath != NULL ) return get_full_path( envpath ); else { - char* pathtmp; - char* path = NULL; + TCHAR* pathtmp; + TCHAR* path = NULL; size_t len = 100; int nchars; while(1){ - pathtmp = (char*)realloc(path,len+1); + pathtmp = (TCHAR*)realloc(path,len+1); if( pathtmp == NULL ){ free(path); return get_full_path(argv0); } path = pathtmp; - nchars = readlink("/proc/self/exe", path, len); + nchars = readlink(_T("/proc/self/exe"), path, len); if( nchars == -1 ){ free(path); return get_full_path(argv0); } if( nchars < (int) len ){ - path[nchars] = '\0'; + path[nchars] = _T('\0'); string result(path); free(path); return result; @@ -460,26 +460,26 @@ string get_executable_path(const char* argv0) { #endif } -string get_executable_dir(const char *argv0) { +tstring get_executable_dir(const TCHAR *argv0) { return get_dir_name(get_executable_path(argv0)); } -string remove_file_extension(const string& path) { - return get_string_prefix(path, "."); +tstring remove_file_extension(const tstring& path) { + return get_string_prefix(path, _T(".")); } struct ToLower { - char operator() (char c) const { return tolower(c); } + TCHAR operator() (TCHAR c) const { return _totlower(c); } }; -string lowercase(const string &str) { - string result = str; +tstring lowercase(const tstring &str) { + tstring result = str; transform(str.begin(), str.end(), result.begin(), ToLower()); return result; } -int sane_system(const char *command) { +int sane_system(const TCHAR *command) { #ifdef _WIN32 // workaround for bug #1509909 @@ -494,23 +494,21 @@ int sane_system(const char *command) { // // to avoid the stripping, a harmless string is prefixed // to the command line. - - string command_s = "IF 1==1 "; + tstring command_s = _T("IF 1==1 "); command_s += command; - return system(command_s.c_str()); + return _tsystem(command_s.c_str()); #else - - return system(command); - + return _tsystem(command); #endif } -static bool GetDLLVersionUsingRE(const string& filepath, DWORD& high, DWORD & low) + +static bool GetDLLVersionUsingRE(const tstring& filepath, DWORD& high, DWORD & low) { bool found = false; - FILE *fdll = FOPEN(filepath.c_str(), "rb"); + FILE *fdll = FOPEN(filepath.c_str(), _T("rb")); if (!fdll) return 0; @@ -567,13 +565,13 @@ static bool GetDLLVersionUsingRE(const string& filepath, DWORD& high, DWORD & lo return found; } -static bool GetDLLVersionUsingAPI(const string& filepath, DWORD& high, DWORD& low) +static bool GetDLLVersionUsingAPI(const tstring& filepath, DWORD& high, DWORD& low) { bool found = false; #ifdef _WIN32 - char path[1024]; - char *name; + TCHAR path[1024]; + TCHAR *name; path[0] = 0; GetFullPathName(filepath.c_str(), 1024, path, &name); @@ -587,7 +585,7 @@ static bool GetDLLVersionUsingAPI(const string& filepath, DWORD& high, DWORD& lo { UINT uLen; VS_FIXEDFILEINFO *pvsf; - if (GetFileVersionInfo(path, 0, verSize, buf) && VerQueryValue(buf, "\\", (void**) &pvsf, &uLen)) + if (GetFileVersionInfo(path, 0, verSize, buf) && VerQueryValue(buf, _T("\\"), (void**) &pvsf, &uLen)) { low = pvsf->dwFileVersionLS; high = pvsf->dwFileVersionMS; @@ -606,9 +604,9 @@ static bool GetDLLVersionUsingAPI(const string& filepath, DWORD& high, DWORD& lo // the following structure must be byte-aligned. #pragma pack( push, pre_vxd_ver, 1 ) typedef struct _VXD_VERSION_RESOURCE { - char cType; + char cType; // Should not be converted to TCHAR (JP) WORD wID; - char cName; + char cName; // Should not be converted to TCHAR (JP) WORD wOrdinal; WORD wFlags; DWORD dwResSize; @@ -616,7 +614,7 @@ typedef struct _VXD_VERSION_RESOURCE { } VXD_VERSION_RESOURCE, *PVXD_VERSION_RESOURCE; #pragma pack( pop, pre_vxd_ver ) -static BOOL GetVxdVersion( LPCSTR szFile, LPDWORD lpdwLen, LPVOID lpData ) +static BOOL GetVxdVersion( LPCTSTR szFile, LPDWORD lpdwLen, LPVOID lpData ) { HANDLE hFile = NULL; @@ -769,7 +767,7 @@ static BOOL GetVxdVersion( LPCSTR szFile, LPDWORD lpdwLen, LPVOID lpData ) return TRUE; } -static DWORD GetVxdVersionInfoSize( LPCSTR szFile ) +static DWORD GetVxdVersionInfoSize( LPCTSTR szFile ) { DWORD dwResult = 0; @@ -791,14 +789,14 @@ static DWORD GetVxdVersionInfoSize( LPCSTR szFile ) return 0; } -static BOOL GetVxdVersionInfo( LPCSTR szFile, DWORD dwLen, LPVOID lpData ) +static BOOL GetVxdVersionInfo( LPCTSTR szFile, DWORD dwLen, LPVOID lpData ) { return GetVxdVersion( szFile, &dwLen, lpData ); } #endif //_WIN32 -static bool GetDLLVersionFromVXD(const string& filepath, DWORD& high, DWORD& low) +static bool GetDLLVersionFromVXD(const tstring& filepath, DWORD& high, DWORD& low) { bool found = false; @@ -811,7 +809,7 @@ static bool GetDLLVersionFromVXD(const string& filepath, DWORD& high, DWORD& low { UINT uLen; VS_FIXEDFILEINFO *pvsf; - if (GetVxdVersionInfo(filepath.c_str(), verSize, buf) && VerQueryValue(buf, "\\", (void**) &pvsf, &uLen)) + if (GetVxdVersionInfo(filepath.c_str(), verSize, buf) && VerQueryValue(buf, _T("\\"), (void**) &pvsf, &uLen)) { low = pvsf->dwFileVersionLS; high = pvsf->dwFileVersionMS; @@ -825,7 +823,7 @@ static bool GetDLLVersionFromVXD(const string& filepath, DWORD& high, DWORD& low return found; } -bool GetDLLVersion(const string& filepath, DWORD& high, DWORD& low) +bool GetDLLVersion(const tstring& filepath, DWORD& high, DWORD& low) { if (GetDLLVersionUsingAPI(filepath, high, low)) return true; diff --git a/Source/util.h b/Source/util.h index 4259a6ac..49bf1bdf 100644 --- a/Source/util.h +++ b/Source/util.h @@ -12,12 +12,14 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/10/2007 */ #ifndef _UTIL_H_ #define _UTIL_H_ -#include // for std::string +#include "tstring.h" // for std::string #include "boost/scoped_ptr.hpp" // for boost::scoped_ptr #include "ResourceEditor.h" @@ -28,35 +30,35 @@ #endif -// these are the standard pause-before-quit shit. +// these are the standard pause-before-quit stuff. extern int g_dopause; extern void dopause(void); // Adds the bitmap in filename using resource editor re as id id. // If width or height are specified it will also make sure the bitmap is in that size -int update_bitmap(CResourceEditor* re, WORD id, const char* filename, int width=0, int height=0, int maxbpp=0); +int update_bitmap(CResourceEditor* re, WORD id, const TCHAR* filename, int width=0, int height=0, int maxbpp=0); -size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm); +size_t my_strftime(TCHAR *s, size_t max, const TCHAR *fmt, const struct tm *tm); -bool GetDLLVersion(const std::string& filepath, DWORD& high, DWORD& low); +bool GetDLLVersion(const tstring& filepath, DWORD& high, DWORD& low); -std::string get_full_path(const std::string& path); -std::string get_dir_name(const std::string& path); -std::string get_file_name(const std::string& path); -std::string get_executable_dir(const char *argv0); -std::string remove_file_extension(const std::string& path); -std::string lowercase(const std::string&); +tstring get_full_path(const tstring& path); +tstring get_dir_name(const tstring& path); +tstring get_file_name(const tstring& path); +tstring get_executable_dir(const TCHAR *argv0); +tstring remove_file_extension(const tstring& path); +tstring lowercase(const tstring&); -std::string get_string_prefix(const std::string& str, const std::string& separator); -std::string get_string_suffix(const std::string& str, const std::string& separator); +tstring get_string_prefix(const tstring& str, const tstring& separator); +tstring get_string_suffix(const tstring& str, const tstring& separator); -int sane_system(const char *command); +int sane_system(const TCHAR *command); #ifndef _WIN32 -char *CharPrev(const char *s, const char *p); -char *CharNext(const char *s); +TCHAR *CharPrev(const TCHAR *s, const TCHAR *p); +TCHAR *CharNext(const TCHAR *s); char *CharNextExA(WORD codepage, const char *s, int flags); -int wsprintf(char *s, const char *format, ...); +int wsprintf(TCHAR *s, const TCHAR *format, ...); int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar); @@ -64,10 +66,10 @@ int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar); BOOL IsValidCodePage(UINT CodePage); -char *my_convert(const char *path); -void my_convert_free(char *converted_path); -int my_open(const char *pathname, int flags); -FILE *my_fopen(const char *path, const char *mode); +TCHAR *my_convert(const TCHAR *path); +void my_convert_free(TCHAR *converted_path); +int my_open(const TCHAR *pathname, int flags); +FILE *my_fopen(const TCHAR *path, const TCHAR *mode); #define FOPEN(a, b) my_fopen(a, b) #define OPEN(a, b) my_open(a, b) @@ -77,8 +79,8 @@ FILE *my_fopen(const char *path, const char *mode); #define my_convert(x) (x) #define my_convert_free(x) -#define FOPEN(a, b) fopen(a, b) -#define OPEN(a, b) open(a, b) +#define FOPEN(a, b) _tfopen(a, b) +#define OPEN(a, b) _topen(a, b) #endif diff --git a/Source/winchar.cpp b/Source/winchar.cpp index 7c236304..a8e54711 100644 --- a/Source/winchar.cpp +++ b/Source/winchar.cpp @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/13/2007 */ #include "Platform.h" diff --git a/Source/winchar.h b/Source/winchar.h index d04ff0ed..3c400235 100644 --- a/Source/winchar.h +++ b/Source/winchar.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 07/31/2007 */ #include "Platform.h" diff --git a/Source/writer.cpp b/Source/writer.cpp index 2c3c95a2..b81c9a6c 100644 --- a/Source/writer.cpp +++ b/Source/writer.cpp @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ #include "exehead/config.h" @@ -21,6 +23,7 @@ #include #include #include +#include "tchar.h" void writer_sink::write_byte(const unsigned char b) { @@ -52,6 +55,7 @@ void writer_sink::write_string(const char *s) write_data(s, strlen(s) + 1); } +// size in this case is the length of the string to write. void writer_sink::write_string(const char *s, const size_t size) { char *wb = new char[size]; diff --git a/Source/writer.h b/Source/writer.h index ca84c5d1..294cc4fa 100644 --- a/Source/writer.h +++ b/Source/writer.h @@ -12,6 +12,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/13/2007 */ #ifndef ___WRITER__H___ @@ -21,6 +23,7 @@ #include "growbuf.h" #include "crc32.h" #include +#include "tchar.h" class writer_sink { public: @@ -31,8 +34,8 @@ public: virtual void write_short(const short s); virtual void write_int(const int i); virtual void write_int_array(const int i[], const size_t len); - virtual void write_string(const char *s); - virtual void write_string(const char *s, const size_t size); + virtual void write_string(const TCHAR *s); + virtual void write_string(const TCHAR *s, const size_t size); virtual void write_growbuf(const IGrowBuf *b); virtual void write_data(const void *data, const size_t size) = 0; diff --git a/Source/zlib/DEFLATE.H b/Source/zlib/DEFLATE.H index fab3dce8..91156e5d 100644 --- a/Source/zlib/DEFLATE.H +++ b/Source/zlib/DEFLATE.H @@ -9,6 +9,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/27/2007 */ /* deflate.h -- internal compression state diff --git a/Source/zlib/INFBLOCK.C b/Source/zlib/INFBLOCK.C index 6fd0333d..c1f4616d 100644 --- a/Source/zlib/INFBLOCK.C +++ b/Source/zlib/INFBLOCK.C @@ -9,6 +9,10 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/27/2007 + * All messages and true strings turned into TCHARs for when we + * create viewable messages. */ #include "../Platform.h" @@ -367,14 +371,14 @@ int ZEXPORT inflate(z_streamp z) switch (t >> 1) { case 0: /* stored */ - Tracev((stderr, "inflate: stored block%s\n", - LAST ? " (last)" : "")); + Tracev((stderr, _T("inflate: stored block%s\n"), + LAST ? _T(" (last)") : _T(""))); DUMPBITS(k&7) s->mode = LENS; /* get length of stored block */ break; case 1: /* fixed */ - Tracev((stderr, "inflate: fixed codes block%s\n", - LAST ? " (last)" : "")); + Tracev((stderr, _T("inflate: fixed codes block%s\n"), + LAST ? _T(" (last)") : _T(""))); { if (!fixed_built) { @@ -414,8 +418,8 @@ int ZEXPORT inflate(z_streamp z) s->mode = CODES_START; break; case 2: /* dynamic */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - LAST ? " (last)" : "")); + Tracev((stderr, _T("inflate: dynamic codes block%s\n"), + LAST ? _T(" (last)") : _T(""))); s->mode = TABLE; break; case 3: /* illegal */ @@ -427,7 +431,7 @@ int ZEXPORT inflate(z_streamp z) NEEDBITS(16) s->sub.left = (uInt)b & 0xffff; b = k = 0; /* dump bits */ - Tracev((stderr, "inflate: stored length %u\n", s->sub.left)); + Tracev((stderr, _T("inflate: stored length %u\n"), s->sub.left)); s->mode = s->sub.left ? STORED : s->last; break; case STORED: @@ -457,7 +461,7 @@ int ZEXPORT inflate(z_streamp z) //t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f); DUMPBITS(14) s->sub.trees.index = 0; - Tracev((stderr, "inflate: table sizes ok\n")); + Tracev((stderr, _T("inflate: table sizes ok\n"))); s->mode = BTREE; case BTREE: while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10)) @@ -483,7 +487,7 @@ int ZEXPORT inflate(z_streamp z) } s->sub.trees.index = 0; - Tracev((stderr, "inflate: bits tree ok\n")); + Tracev((stderr, _T("inflate: bits tree ok\n"))); s->mode = DTREE; case DTREE: while (t = s->sub.trees.table, @@ -558,7 +562,7 @@ int ZEXPORT inflate(z_streamp z) s->mode = BAD; LEAVE(Z_DATA_ERROR); } - Tracev((stderr, "inflate: trees ok\n")); + Tracev((stderr, _T("inflate: trees ok\n"))); //s->sub.decode.t_codes.mode = CODES_START; s->sub.decode.t_codes.lbits = (Byte)bl; @@ -682,7 +686,7 @@ int ZEXPORT inflate(z_streamp z) LEAVE(Z_OK) if (s->mode == CODES_WASH) { - Tracev((stderr, "inflate: codes end, %lu total out\n", + Tracev((stderr, _T("inflate: codes end, %lu total out\n"), z->total_out + (q >= s->read ? q - s->read : (s->end - s->read) + (q - s->window)))); } diff --git a/Source/zlib/ZCONF.H b/Source/zlib/ZCONF.H index 633c62d8..3df2cdeb 100644 --- a/Source/zlib/ZCONF.H +++ b/Source/zlib/ZCONF.H @@ -9,6 +9,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/27/2007 */ /* zconf.h -- configuration of the zlib compression library @@ -16,7 +18,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* @(#) $Id: ZCONF.H,v 1.2 2006/10/28 19:45:02 joostverburg Exp $ */ +/* @(#) $Id: ZCONF.H,v 1.3 2007/01/13 17:28:23 kichik Exp $ */ #ifndef _ZCONF_H #define _ZCONF_H diff --git a/Source/zlib/ZLIB.H b/Source/zlib/ZLIB.H index 904efc6a..68e57f0a 100644 --- a/Source/zlib/ZLIB.H +++ b/Source/zlib/ZLIB.H @@ -9,6 +9,8 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/27/2007 */ /* zlib.h -- interface of the 'zlib' general purpose compression library @@ -175,7 +177,7 @@ typedef struct z_stream_s { uLong total_out; /* total nb of bytes output so far */ #endif -// char *msg; /* last error message, NULL if no error */ +// TCHAR *msg; /* last error message, NULL if no error */ //struct internal_state FAR *state; /* not visible by applications */ #ifdef EXEHEAD struct inflate_blocks_state blocks; /* current inflate_blocks state */ @@ -278,16 +280,16 @@ ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); * and the compiler's view of z_stream: */ ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); + const TCHAR *version, int stream_size)); //ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - // const char *version, int stream_size)); + // const TCHAR *version, int stream_size)); ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, int windowBits, int memLevel, - int strategy, const char *version, + int strategy, const TCHAR *version, int stream_size)); #define deflateInit(strm, level) \ - deflateInit_((strm), (level), "", sizeof(z_stream)) + deflateInit_((strm), (level), _T(""), sizeof(z_stream)) #ifdef __cplusplus diff --git a/Source/zlib/ZUTIL.H b/Source/zlib/ZUTIL.H index c2d61ea9..86904528 100644 --- a/Source/zlib/ZUTIL.H +++ b/Source/zlib/ZUTIL.H @@ -9,6 +9,11 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Reviewed for Unicode support by Jim Park -- 08/27/2007 + * The messages generated here are mostly #def'ed out, but are used + * when debugging. So in order for the messages to be viewable in + * Unicode version, using TCHAR macros. */ /* zutil.h -- internal interface and configuration of the compression library @@ -21,13 +26,14 @@ subject to change. Applications should only use zlib.h. */ -/* @(#) $Id: ZUTIL.H,v 1.5 2007/01/13 17:28:23 kichik Exp $ */ +/* @(#) $Id: ZUTIL.H,v 1.6 2007/01/25 18:07:40 kichik Exp $ */ #ifndef _Z_UTIL_H #define _Z_UTIL_H #include "../Platform.h" #include "ZLIB.H" +#include "../tchar.h" #ifndef local # define local static diff --git a/Source/zlib/deflate.c b/Source/zlib/deflate.c index 9be307c7..e4ac1505 100644 --- a/Source/zlib/deflate.c +++ b/Source/zlib/deflate.c @@ -9,6 +9,10 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/27/2007 + * All messages and true strings turned into TCHARs for when we + * create viewable messages. */ /* deflate.c -- compress data using the deflation algorithm @@ -19,8 +23,8 @@ #include "DEFLATE.H" -const char deflate_copyright[] = - " deflate 1.1.3 Copyright 1995-1998 Jean-loup Gailly "; +const TCHAR deflate_copyright[] = + _T(" deflate 1.1.3 Copyright 1995-1998 Jean-loup Gailly "); /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -113,7 +117,7 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ int ZEXPORT deflateInit_(strm, level, version, stream_size) z_streamp strm; int level; - const char *version; + const TCHAR *version; int stream_size; { return deflateInit2_(strm, level, Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, @@ -130,7 +134,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, int windowBits; int memLevel; int strategy; - const char *version; + const TCHAR *version; int stream_size; { deflate_state *s; @@ -185,7 +189,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { -// strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); +// strm->msg = (TCHAR*)ERR_MSG(Z_MEM_ERROR); deflateEnd (strm); return Z_MEM_ERROR; } @@ -420,7 +424,7 @@ int ZEXPORT deflate (strm, flush) } } } - Assert(strm->avail_out > 0, "bug2"); + Assert(strm->avail_out > 0, _T("bug2")); if (flush != Z_FINISH) return Z_OK; if (s->noheader) return Z_STREAM_END; @@ -546,7 +550,7 @@ local uInt longest_match(s, cur_match) /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. * It is easy to get rid of this optimization if necessary. */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, _T("Code too clever")); /* Do not waste too much time if we already have a good match: */ if (s->prev_length >= s->good_match) { @@ -557,10 +561,10 @@ local uInt longest_match(s, cur_match) */ if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, _T("need lookahead")); do { - Assert(cur_match < s->strstart, "no future"); + Assert(cur_match < s->strstart, _T("no future")); match = s->window + cur_match; /* Skip to next match if the match length cannot increase @@ -573,7 +577,7 @@ local uInt longest_match(s, cur_match) if (*(ushf*)(match+best_len-1) != scan_end || *(ushf*)match != scan_start) continue; - Assert(scan[2] == match[2], "scan[2]?"); + Assert(scan[2] == match[2], _T("scan[2]?")); scan++, match++; do { } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && @@ -584,7 +588,7 @@ local uInt longest_match(s, cur_match) /* The funny "do {}" generates better code on most compilers */ /* Here, scan <= window+strstart+257 */ - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + Assert(scan <= s->window+(unsigned)(s->window_size-1), _T("wild scan")); if (*scan == *match) scan++; len = (MAX_MATCH - 1) - (int)(strend-scan); @@ -598,7 +602,7 @@ local uInt longest_match(s, cur_match) *++match != scan[1]) continue; scan += 2, match++; - Assert(*scan == *match, "match[2]?"); + Assert(*scan == *match, _T("match[2]?")); do { } while (*++scan == *++match && *++scan == *++match && *++scan == *++match && *++scan == *++match && @@ -606,7 +610,7 @@ local uInt longest_match(s, cur_match) *++scan == *++match && *++scan == *++match && scan < strend); - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + Assert(scan <= s->window+(unsigned)(s->window_size-1), _T("wild scan")); len = MAX_MATCH - (int)(strend - scan); scan = strend - MAX_MATCH; @@ -644,11 +648,11 @@ local uInt longest_match(s, cur_match) register int len; /* length of current match */ register Bytef *strend = s->window + s->strstart + MAX_MATCH; - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, _T("Code too clever")); - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, _T("need lookahead")); - Assert(cur_match < s->strstart, "no future"); + Assert(cur_match < s->strstart, _T("no future")); match = s->window + cur_match; @@ -656,7 +660,7 @@ local uInt longest_match(s, cur_match) */ if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; scan += 2, match += 2; - Assert(*scan == *match, "match[2]?"); + Assert(*scan == *match, _T("match[2]?")); do { } while (*++scan == *++match && *++scan == *++match && @@ -665,7 +669,7 @@ local uInt longest_match(s, cur_match) *++scan == *++match && *++scan == *++match && scan < strend); - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + Assert(scan <= s->window+(unsigned)(s->window_size-1), _T("wild scan")); len = MAX_MATCH - (int)(strend - scan); @@ -731,7 +735,7 @@ local void fill_window(s) more += wsize; } if (s->strm->avail_in == 0) return; - Assert(more >= 2, "more < 2"); + Assert(more >= 2, _T("more < 2")); n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); s->lookahead += n; @@ -756,7 +760,7 @@ local void fill_window(s) (eof)); \ s->block_start = s->strstart; \ flush_pending(s->strm); \ - Tracev((stderr,"[FLUSH]")); \ + Tracev((stderr,_T("[FLUSH]"))); \ } /* Same but force premature exit if necessary. */ @@ -829,7 +833,7 @@ local block_state deflate_slow(s, flush) if (bflush) FLUSH_BLOCK(s, 0); } else if (s->match_available) { - Tracevv((stderr,"%c", s->window[s->strstart-1])); + Tracevv((stderr,_T("%c"), s->window[s->strstart-1])); _tr_tally_lit(s, s->window[s->strstart-1], bflush); if (bflush) { FLUSH_BLOCK_ONLY(s, 0); @@ -846,9 +850,9 @@ local block_state deflate_slow(s, flush) s->lookahead--; } } - Assert (flush != Z_NO_FLUSH, "no flush?"); + Assert (flush != Z_NO_FLUSH, _T("no flush?")); if (s->match_available) { - Tracevv((stderr,"%c", s->window[s->strstart-1])); + Tracevv((stderr,_T("%c"), s->window[s->strstart-1])); _tr_tally_lit(s, s->window[s->strstart-1], bflush); s->match_available = 0; } diff --git a/Source/zlib/trees.c b/Source/zlib/trees.c index 745e5c6d..3f4c1437 100644 --- a/Source/zlib/trees.c +++ b/Source/zlib/trees.c @@ -9,6 +9,10 @@ * * This software is provided 'as-is', without any express or implied * warranty. + * + * Unicode support by Jim Park -- 08/27/2007 + * All messages and true strings turned into TCHARs for when we + * create viewable messages. */ /* trees.c -- output deflated data using Huffman coding @@ -126,7 +130,7 @@ local void gen_trees_header OF((void)); #else /* DEBUG */ # define send_code(s, c, tree) \ - { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ + { if (z_verbose>2) _ftprintf(stderr,_T("\ncd %3d "),(c)); \ send_bits(s, tree[c].Code, tree[c].Len); } #endif @@ -151,8 +155,8 @@ local void send_bits(s, value, length) int value; /* value to send */ int length; /* number of bits */ { - Tracevv((stderr," l %2d v %4x ", length, value)); - Assert(length > 0 && length <= 15, "invalid length"); + Tracevv((stderr,_T(" l %2d v %4x "), length, value)); + Assert(length > 0 && length <= 15, _T("invalid length")); s->bits_sent += (ulg)length; if (s->bi_valid > (int)Buf_size - length) { @@ -217,7 +221,7 @@ local void tr_static_init() _length_code[length++] = (uch)code; } } - Assert (length == 256, "tr_static_init: length != 256"); + Assert (length == 256, _T("tr_static_init: length != 256")); _length_code[length-1] = (uch)code; /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ @@ -228,7 +232,7 @@ local void tr_static_init() _dist_code[dist++] = (uch)code; } } - Assert (dist == 256, "tr_static_init: dist != 256"); + Assert (dist == 256, _T("tr_static_init: dist != 256")); dist >>= 7; /* from now on, all distances are divided by 128 */ for ( ; code < D_CODES; code++) { base_dist[code] = dist << 7; @@ -236,7 +240,7 @@ local void tr_static_init() _dist_code[256 + dist++] = (uch)code; } } - Assert (dist == 256, "tr_static_init: 256+dist != 512"); + Assert (dist == 256, _T("tr_static_init: 256+dist != 512")); /* Construct the codes of the static literal tree */ for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; @@ -373,7 +377,7 @@ local void gen_bitlen(s, desc) } if (overflow == 0) return; - Trace((stderr,"\nbit length overflow\n")); + Trace((stderr,_T("\nbit length overflow\n"))); do { bits = max_length-1; while (s->bl_count[bits] == 0) bits--; @@ -389,7 +393,7 @@ local void gen_bitlen(s, desc) m = s->heap[--h]; if (m > max_code) continue; if (tree[m].Len != (unsigned) bits) { - Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); + Trace((stderr,_T("code %d bits %d->%d\n"), m, tree[m].Len, bits)); s->opt_len += ((long)bits - (long)tree[m].Len) *(long)tree[m].Freq; tree[m].Len = (ush)bits; @@ -413,8 +417,8 @@ local void gen_codes (tree, max_code, bl_count) next_code[bits] = code = (code + bl_count[bits-1]) << 1; } Assert (code + bl_count[MAX_BITS]-1 == (1<bl_tree) { - fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", + _ftprintf(stderr,_T("\nnode %d(%d), sons %d(%d) %d(%d)"), node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); } #endif @@ -559,7 +563,7 @@ local void send_tree (s, tree, max_code) if (curlen != prevlen) { send_code(s, curlen, s->bl_tree); count--; } - Assert(count >= 3 && count <= 6, " 3_6?"); + Assert(count >= 3 && count <= 6, _T(" 3_6?")); send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); } else if (count <= 10) { @@ -595,7 +599,7 @@ local int build_bl_tree(s) } /* Update opt_len to include the bit length tree and counts */ s->opt_len += 3*(max_blindex+1) + 5+5+4; - Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", + Tracev((stderr, _T("\ndyn trees: dyn %ld, stat %ld"), s->opt_len, s->static_len)); return max_blindex; @@ -607,24 +611,24 @@ local void send_all_trees(s, lcodes, dcodes, blcodes) { int rank; /* index in bl_order */ - Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, _T("not enough codes")); Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, - "too many codes"); - Tracev((stderr, "\nbl counts: ")); + _T("too many codes")); + Tracev((stderr, _T("\nbl counts: "))); send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ send_bits(s, dcodes-1, 5); send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ for (rank = 0; rank < blcodes; rank++) { - Tracev((stderr, "\nbl code %2d ", bl_order[rank])); + Tracev((stderr, _T("\nbl code %2d "), bl_order[rank])); send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); } - Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); + Tracev((stderr, _T("\nbl tree: sent %ld"), s->bits_sent)); send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ - Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); + Tracev((stderr, _T("\nlit tree: sent %ld"), s->bits_sent)); send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ - Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); + Tracev((stderr, _T("\ndist tree: sent %ld"), s->bits_sent)); } void _tr_stored_block(s, buf, stored_len, eof) @@ -675,11 +679,11 @@ void _tr_flush_block(s, buf, stored_len, eof) /* Construct the literal and distance trees */ build_tree(s, (tree_desc *)(&(s->l_desc))); - Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, + Tracev((stderr, _T("\nlit data: dyn %ld, stat %ld"), s->opt_len, s->static_len)); build_tree(s, (tree_desc *)(&(s->d_desc))); - Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, + Tracev((stderr, _T("\ndist data: dyn %ld, stat %ld"), s->opt_len, s->static_len)); max_blindex = build_bl_tree(s); @@ -687,14 +691,14 @@ void _tr_flush_block(s, buf, stored_len, eof) opt_lenb = (s->opt_len+3+7)>>3; static_lenb = (s->static_len+3+7)>>3; - Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", + Tracev((stderr, _T("\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u "), opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, s->last_lit)); if (static_lenb <= opt_lenb) opt_lenb = static_lenb; } else { - Assert(buf != (char*)0, "lost buf"); + Assert(buf != (char*)0, _T("lost buf")); opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ } @@ -725,7 +729,7 @@ void _tr_flush_block(s, buf, stored_len, eof) s->compressed_len += 3 + s->opt_len; #endif } - Assert (s->compressed_len == s->bits_sent, "bad compressed size"); + Assert (s->compressed_len == s->bits_sent, _T("bad compressed size")); init_block(s); @@ -735,7 +739,7 @@ void _tr_flush_block(s, buf, stored_len, eof) s->compressed_len += 7; /* align on byte boundary */ #endif } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, + Tracev((stderr,_T("\ncomprlen %lu(%lu) "), s->compressed_len>>3, s->compressed_len-7*eof)); } @@ -755,7 +759,7 @@ int _tr_tally (s, dist, lc) dist--; /* dist = match distance - 1 */ Assert((ush)dist < (ush)MAX_DIST(s) && (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && - (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); + (ush)d_code(dist) < (ush)D_CODES, _T("_tr_tally: bad match")); s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; s->dyn_dtree[d_code(dist)].Freq++; @@ -773,7 +777,7 @@ int _tr_tally (s, dist, lc) (5L+extra_dbits[dcode]); } out_length >>= 3; - Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", + Tracev((stderr,_T("\nlast_lit %u, in %ld, out ~%ld(%ld%%) "), s->last_lit, in_length, out_length, 100L - out_length*100L/in_length)); if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; @@ -798,7 +802,7 @@ local void compress_block(s, ltree, dtree) lc = s->l_buf[lx++]; if (dist == 0) { send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + Tracecv(isgraph(lc), (stderr,_T(" '%c' "), lc)); } else { /* Here, lc is the match length - MIN_MATCH */ code = _length_code[lc]; @@ -810,7 +814,7 @@ local void compress_block(s, ltree, dtree) } dist--; /* dist is now the match distance - 1 */ code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); + Assert (code < D_CODES, _T("bad d_code")); send_code(s, code, dtree); /* send the distance code */ extra = extra_dbits[code]; @@ -821,7 +825,7 @@ local void compress_block(s, ltree, dtree) } /* literal or match pair ? */ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow"); + Assert(s->pending < s->lit_bufsize + 2*lx, _T("pendingBuf overflow")); } while (lx < s->last_lit); diff --git a/TODO.txt b/TODO.txt index c12605c3..0a713b6a 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,6 +3,8 @@ TODO NSIS +* Make Unicode version compile on other compilers / platforms. + * Compiler plug-ins * Empty subsections should not show @@ -11,11 +13,12 @@ NSIS EXAMPLES -* Write an advanced paging example showing multiple components page with multiple - instfiles pages +* Write an advanced paging example showing multiple components page with + multiple instfiles pages PLUG-INS -* InstallOptions - custom class names so you can include whatever control you want +* InstallOptions - custom class names so you can include whatever control + you want * nsExec - live outputs \ No newline at end of file