more simple TCHARs fixes

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6047 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-04-12 16:00:17 +00:00
parent a92fad7347
commit 64a0f32e52
38 changed files with 1831 additions and 1961 deletions

View file

@ -47,7 +47,7 @@ int GetTLBVersion(tstring& filepath, DWORD& high, DWORD & low)
hr = LoadTypeLib(fullpath, &typeLib); hr = LoadTypeLib(fullpath, &typeLib);
#else #else
// If built without UNICODE, we still need to convert this string to a Unicode string. // If built without UNICODE, we still need to convert this string to a Unicode string.
WCHAR *ole_filename = winchar_fromansi(fullpath); WCHAR *ole_filename = winchar_fromTchar(fullpath);
hr = LoadTypeLib(ole_filename, &typeLib); hr = LoadTypeLib(ole_filename, &typeLib);
#endif #endif

View file

@ -37,11 +37,12 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL
if (*cmdline == _T('S')) if (*cmdline == _T('S'))
{ {
HKEY rootkey; HKEY rootkey;
TCHAR *keyname, *file; // These are turned into heap memory to avoid _chkstk
keyname = (TCHAR*) GlobalAlloc(GPTR, STR_SIZE*sizeof(TCHAR));
file = (TCHAR*) GlobalAlloc(GPTR, STR_SIZE*sizeof(TCHAR));
if (SUCCEEDED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("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)))
{ {
TCHAR keyname[STR_SIZE];
while (RegEnumKey(rootkey, 0, keyname, STR_SIZE) == ERROR_SUCCESS) while (RegEnumKey(rootkey, 0, keyname, STR_SIZE) == ERROR_SUCCESS)
{ {
HKEY key; HKEY key;
@ -53,7 +54,7 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL
if (SUCCEEDED(RegQueryValueEx(key, _T("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; DWORD j;
TCHAR valname[128], mode[3], file[STR_SIZE]; TCHAR valname[128], mode[3];
for (j = 1; j <= count; j++) for (j = 1; j <= count; j++)
{ {
@ -83,12 +84,13 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL
} }
{ {
TCHAR file[STR_SIZE];
if (GetModuleFileName(GetModuleHandle(NULL), file, STR_SIZE)) if (GetModuleFileName(GetModuleHandle(NULL), file, STR_SIZE))
{ {
DeleteFileOnReboot(file); DeleteFileOnReboot(file);
} }
} }
GlobalFree(keyname);
GlobalFree(file);
} }
else else
{ {
@ -131,14 +133,17 @@ void SafeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection)
void RegFile(TCHAR cmd, TCHAR *file, int x64) void RegFile(TCHAR cmd, TCHAR *file, int x64)
{ {
TCHAR self[STR_SIZE]; TCHAR* self; // These are turned into heap memory to avoid _chkstk
TCHAR cmdline[STR_SIZE]; TCHAR* cmdline;
int ready = 0; int ready = 0;
if (!*file || (cmd != _T('D') && cmd != _T('T') && cmd != _T('E'))) if (!*file || (cmd != _T('D') && cmd != _T('T') && cmd != _T('E')))
return; return;
self = (TCHAR*) GlobalAlloc(GPTR, sizeof(TCHAR)*STR_SIZE);
cmdline = (TCHAR*) GlobalAlloc(GPTR, sizeof(TCHAR)*STR_SIZE);
if (cmd == _T('E')) if (cmd == _T('E'))
{ {
wsprintf(cmdline, _T("\"%s\" /regserver"), file); wsprintf(cmdline, _T("\"%s\" /regserver"), file);
@ -182,6 +187,9 @@ void RegFile(TCHAR cmd, TCHAR *file, int x64)
SafeWow64EnableWow64FsRedirection(TRUE); SafeWow64EnableWow64FsRedirection(TRUE);
} }
} }
GlobalFree(self);
GlobalFree(cmdline);
} }
void RegDll(TCHAR *file) void RegDll(TCHAR *file)
@ -198,9 +206,13 @@ void RegDll(TCHAR *file)
void RegTypeLib(TCHAR *file) void RegTypeLib(TCHAR *file)
{ {
#ifdef _UNICODE
WCHAR* wfile = file;
#else
WCHAR wfile[STR_SIZE]; WCHAR wfile[STR_SIZE];
if (MultiByteToWideChar(CP_ACP, 0, file, -1, wfile, STR_SIZE) == 0)
if (MultiByteToWideChar(CP_ACP, 0, file, -1, wfile, STR_SIZE) != 0) return;
#endif
{ {
ITypeLib* tlib; ITypeLib* tlib;
if (SUCCEEDED(LoadTypeLib(wfile, &tlib))) { if (SUCCEEDED(LoadTypeLib(wfile, &tlib))) {
@ -320,7 +332,7 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName)
char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n["); char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n[");
if (pszNextSec) if (pszNextSec)
{ {
TCHAR *p = ++pszNextSec; char *p = ++pszNextSec;
while (p < pszWinInit + dwFileSize) { while (p < pszWinInit + dwFileSize) {
p[cchRenameLine] = *p; p[cchRenameLine] = *p;
p++; p++;

View file

@ -13,5 +13,6 @@ libs = Split("""
""") """)
Import('BuildUtil') Import('BuildUtil')
Import('_tWinMain')
BuildUtil(target, files, libs, entry = 'WinMain', nodeflib = True, file_name = 'RegTool.bin') BuildUtil(target, files, libs, entry = _tWinMain, nodeflib = True, file_name = 'RegTool.bin')

View file

@ -19,6 +19,7 @@ libs = Split("""
""") """)
Import('BuildUtil') Import('BuildUtil')
Import('_tWinMain')
BuildUtil(target, files, libs, res = res, resources = resources, entry = 'WinMain') BuildUtil(target, files, libs, res = res, resources = resources, entry = _tWinMain)

View file

@ -2,7 +2,6 @@ target = 'makensisw'
files = Split(""" files = Split("""
makensisw.cpp makensisw.cpp
noclib.cpp
toolbar.cpp toolbar.cpp
utils.cpp utils.cpp
version.cpp version.cpp
@ -34,6 +33,7 @@ libs = Split("""
user32 user32
gdi32 gdi32
shell32 shell32
shlwapi
comdlg32 comdlg32
comctl32 comctl32
wsock32 wsock32
@ -45,6 +45,7 @@ docs = Split("""
""") """)
Import('BuildUtil') Import('BuildUtil')
Import('_tWinMain')
BuildUtil( BuildUtil(
target, target,
@ -52,7 +53,7 @@ BuildUtil(
libs, libs,
res = res, res = res,
resources = resources, resources = resources,
entry = 'WinMain', entry = _tWinMain,
defines = ['RELEASE=2.3'], defines = ['RELEASE=2.3'],
docs = docs, docs = docs,
root_util = True root_util = True

View file

@ -24,9 +24,9 @@
#include "makensisw.h" #include "makensisw.h"
#include <windowsx.h> #include <windowsx.h>
#include <shlwapi.h>
#include <stdio.h> #include <stdio.h>
#include "resource.h" #include "resource.h"
#include "noclib.h"
#include "toolbar.h" #include "toolbar.h"
#include "update.h" #include "update.h"
@ -41,9 +41,9 @@ int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, TCHAR *cmdParam, int
int status; int status;
HACCEL haccel; HACCEL haccel;
my_memset(&g_sdata,0,sizeof(NSCRIPTDATA)); memset(&g_sdata,0,sizeof(NSCRIPTDATA));
my_memset(&g_resize,0,sizeof(NRESIZEDATA)); memset(&g_resize,0,sizeof(NRESIZEDATA));
my_memset(&g_find,0,sizeof(NFINDREPLACE)); memset(&g_find,0,sizeof(NFINDREPLACE));
g_sdata.hInstance=GetModuleHandle(0); g_sdata.hInstance=GetModuleHandle(0);
g_sdata.symbols = NULL; g_sdata.symbols = NULL;
g_sdata.sigint_event = CreateEvent(NULL, FALSE, FALSE, _T("makensis win32 signint event")); g_sdata.sigint_event = CreateEvent(NULL, FALSE, FALSE, _T("makensis win32 signint event"));
@ -130,10 +130,10 @@ void ProcessCommandLine()
if (argc > 1) { if (argc > 1) {
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if (!lstrncmpi(argv[i], _T("/XSetCompressor "), lstrlen(_T("/XSetCompressor ")))) if (!StrCmpNI(argv[i], _T("/XSetCompressor "), lstrlen(_T("/XSetCompressor "))))
{ {
TCHAR *p = argv[i] + lstrlen(_T("/XSetCompressor ")); TCHAR *p = argv[i] + lstrlen(_T("/XSetCompressor "));
if(!lstrncmpi(p,_T("/FINAL "), lstrlen(_T("/FINAL ")))) if(!StrCmpNI(p,_T("/FINAL "), lstrlen(_T("/FINAL "))))
{ {
p += lstrlen(_T("/FINAL ")); p += lstrlen(_T("/FINAL "));
} }
@ -481,7 +481,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
if (g_sdata.input_script) { if (g_sdata.input_script) {
TCHAR str[MAX_PATH],*str2; TCHAR str[MAX_PATH],*str2;
lstrcpy(str,g_sdata.input_script); lstrcpy(str,g_sdata.input_script);
str2=my_strrchr(str,_T('\\')); str2=_tcsrchr(str,_T('\\'));
if(str2!=NULL) *(str2+1)=0; if(str2!=NULL) *(str2+1)=0;
ShellExecute(g_sdata.hwnd,_T("open"),str,NULL,NULL,SW_SHOWNORMAL); ShellExecute(g_sdata.hwnd,_T("open"),str,NULL,NULL,SW_SHOWNORMAL);
} }
@ -656,7 +656,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
case IDM_FIND: case IDM_FIND:
{ {
if (!g_find.uFindReplaceMsg) g_find.uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING); if (!g_find.uFindReplaceMsg) g_find.uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
my_memset(&g_find.fr, 0, sizeof(FINDREPLACE)); memset(&g_find.fr, 0, sizeof(FINDREPLACE));
g_find.fr.lStructSize = sizeof(FINDREPLACE); g_find.fr.lStructSize = sizeof(FINDREPLACE);
g_find.fr.hwndOwner = hwndDlg; g_find.fr.hwndOwner = hwndDlg;
g_find.fr.Flags = FR_NOUPDOWN; g_find.fr.Flags = FR_NOUPDOWN;
@ -743,7 +743,7 @@ DWORD WINAPI MakeNSISProc(LPVOID p) {
PostMessage(g_sdata.hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0); PostMessage(g_sdata.hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
return 1; return 1;
} }
char szBuf[1024]; TCHAR szBuf[1024];
DWORD dwRead = 1; DWORD dwRead = 1;
DWORD dwExit = !STILL_ACTIVE; DWORD dwExit = !STILL_ACTIVE;
while (dwExit == STILL_ACTIVE || dwRead) { while (dwExit == STILL_ACTIVE || dwRead) {
@ -986,7 +986,7 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
if(n > 0) { if(n > 0) {
TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR)); TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR));
SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXT, n+1, (LPARAM)buf); SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXT, n+1, (LPARAM)buf);
if(my_strstr(buf,_T(" ")) || my_strstr(buf,_T("\t"))) { if(_tcsstr(buf,_T(" ")) || _tcsstr(buf,_T("\t"))) {
MessageBox(hwndDlg,SYMBOLSERROR,_T("Error"),MB_OK|MB_ICONSTOP); MessageBox(hwndDlg,SYMBOLSERROR,_T("Error"),MB_OK|MB_ICONSTOP);
GlobalFree(buf); GlobalFree(buf);
break; break;
@ -1028,7 +1028,7 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
if(n > 0) { if(n > 0) {
TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR)); TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR));
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)index, (LPARAM)buf); SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)index, (LPARAM)buf);
TCHAR *p = my_strstr(buf,_T("=")); TCHAR *p = _tcsstr(buf,_T("="));
if(p) { if(p) {
SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, (LPARAM)(p+1)); SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, (LPARAM)(p+1));
*p=0; *p=0;

View file

@ -1,72 +0,0 @@
/*
Copyright (c) 2002 Robert Rainwater
Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely
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 <windows.h>
#include "noclib.h"
// kickik's clib methods
char *my_strrchr(const char *string, int c) {
for (int i=lstrlen(string); i>=0; i--)
if (string[i]==c) return (char*)&string[i];
return 0;
}
char *my_strstr(char *i, char *s) {
if (lstrlen(i)>=lstrlen(s)) while (i[lstrlen(s)-1]) {
int l=lstrlen(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;
}
void *my_memset(void *dest, int c, size_t count) {
for (size_t i=0; i<count;i++) ((char*)dest)[i]=c;
return dest;
}
// iceman_k's clib methods
int lstrncmp(char *s1, const char *s2, int chars)
{
while ((chars > 0) && (*s1) && (*s2) && (*(s1) == *(s2))) chars--, s1++, s2++;
if ((chars == 0) || (*s1 == *s2)) return 0;
return (*s1 - *s2);
}
int lstrncmpi(char *s1, const char *s2, int chars)
{
while (chars-- && *s1 && *s2)
{
char ss1=*s1++;
char ss2=*s2++;
if (ss1>='a' && ss1 <= 'z') ss1+='A'-'a';
if (ss2>='a' && ss2 <= 'z') ss2+='A'-'a';
if (ss1 != ss2) return ss1-ss2;
}
return 0;
}

View file

@ -1,33 +0,0 @@
/*
Copyright (c) 2002 Robert Rainwater
Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely
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.
*/
#ifndef NOCLIB_H
#define NOCLIB_H
// kickik's clib methods
char *my_strstr(char *i, char *s);
char *my_strrchr(const char *string, int c);
void *my_memset(void *dest, int c, size_t count);
// iceman_k's clib methods
int lstrncmp(char *s1, const char *s2, int chars);
int lstrncmpi(char *s1, const char *s2, int chars);
#endif

View file

@ -25,7 +25,6 @@
#include "makensisw.h" #include "makensisw.h"
#include "resource.h" #include "resource.h"
#include "noclib.h"
#include "toolbar.h" #include "toolbar.h"
#include "../ExDLL/nsis_tchar.h" #include "../ExDLL/nsis_tchar.h"
@ -133,7 +132,7 @@ void UpdateToolBarCompressorButton()
TCHAR temp[64]; // increased to 64. Hit limit 08/20/2007 -- Jim Park. TCHAR temp[64]; // increased to 64. Hit limit 08/20/2007 -- Jim Park.
TOOLINFO ti; TOOLINFO ti;
my_memset(&ti, 0, sizeof(TOOLINFO)); memset(&ti, 0, sizeof(TOOLINFO));
if(g_sdata.compressor >= COMPRESSOR_SCRIPT && g_sdata.compressor <= COMPRESSOR_BEST) { if(g_sdata.compressor >= COMPRESSOR_SCRIPT && g_sdata.compressor <= COMPRESSOR_BEST) {
iBitmap = compressor_bitmaps[(int)g_sdata.compressor]; iBitmap = compressor_bitmaps[(int)g_sdata.compressor];
@ -146,7 +145,7 @@ void UpdateToolBarCompressorButton()
IDS_COMPRESSOR, IDS_COMPRESSOR,
temp, temp,
COUNTOF(temp)); COUNTOF(temp));
my_memset(szBuffer, 0, sizeof(szBuffer)); memset(szBuffer, 0, sizeof(szBuffer));
lstrcat(szBuffer,temp); lstrcat(szBuffer,temp);
lstrcat(szBuffer,_T(" [")); lstrcat(szBuffer,_T(" ["));
LoadString(g_sdata.hInstance, LoadString(g_sdata.hInstance,
@ -174,7 +173,7 @@ void AddToolBarButtonTooltip(int id, int iString)
TCHAR szBuffer[64]; TCHAR szBuffer[64];
RECT rect; RECT rect;
my_memset(&ti, 0, sizeof(TOOLINFO)); memset(&ti, 0, sizeof(TOOLINFO));
SendMessage(g_toolbar.hwnd, TB_GETITEMRECT, id, (LPARAM) (LPRECT) &rect); SendMessage(g_toolbar.hwnd, TB_GETITEMRECT, id, (LPARAM) (LPRECT) &rect);

View file

@ -2,7 +2,6 @@
#include "makensisw.h" #include "makensisw.h"
#include "update.h" #include "update.h"
#include "noclib.h"
#include "jnetlib/httpget.h" #include "jnetlib/httpget.h"
#include "../ExDLL/nsis_tchar.h" #include "../ExDLL/nsis_tchar.h"
@ -62,14 +61,14 @@ DWORD CALLBACK UpdateThread(LPVOID v) {
if (getProxyInfo(pbuf)) if (getProxyInfo(pbuf))
{ {
p=my_strstr(pbuf,"http="); p=strstr(pbuf,"http=");
if (!p) p=pbuf; if (!p) p=pbuf;
else { else {
p+=5; p+=5;
} }
char *tp=my_strstr(p,";"); char *tp=strstr(p,";");
if (tp) *tp=0; if (tp) *tp=0;
char *p2=my_strstr(p,"="); char *p2=strstr(p,"=");
if (p2) p=0; // we found the wrong proxy if (p2) p=0; // we found the wrong proxy
} }
@ -140,7 +139,7 @@ DWORD CALLBACK UpdateThread(LPVOID v) {
void Update() { void Update() {
DWORD dwThreadId; DWORD dwThreadId;
if (my_strstr(g_sdata.brandingv,_T("cvs"))) if (_tcsstr(g_sdata.brandingv,_T("cvs")))
{ {
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); 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; return;

View file

@ -25,7 +25,7 @@
#include "makensisw.h" #include "makensisw.h"
#include "resource.h" #include "resource.h"
#include "toolbar.h" #include "toolbar.h"
#include "noclib.h" #include <shlwapi.h>
#ifdef _countof #ifdef _countof
#define COUNTOF _countof #define COUNTOF _countof
@ -60,13 +60,13 @@ int SetArgv(const TCHAR *cmdLine, int *argc, TCHAR ***argv)
} }
} }
argSpaceSize = size * sizeof(TCHAR *) + lstrlen(cmdLine) + 1; argSpaceSize = size * sizeof(TCHAR *) + (lstrlen(cmdLine) + 1) * sizeof(TCHAR);
argSpace = (TCHAR *) GlobalAlloc(GMEM_FIXED, argSpaceSize); argSpace = (TCHAR *) GlobalAlloc(GMEM_FIXED, argSpaceSize);
if (!argSpace) if (!argSpace)
return 0; return 0;
*argv = (TCHAR **) argSpace; *argv = (TCHAR **) argSpace;
argSpace += size * sizeof(TCHAR *); argSpace = (TCHAR *) ((*argv)+size);
size--; size--;
p = cmdLine; p = cmdLine;
@ -241,13 +241,13 @@ void SetCompressorStats()
DWORD len = lstrlen(TOTAL_SIZE_COMPRESSOR_STAT); DWORD len = lstrlen(TOTAL_SIZE_COMPRESSOR_STAT);
lstrcat(g_sdata.compressor_stats,buf); lstrcat(g_sdata.compressor_stats,buf);
if(!lstrncmp(buf,TOTAL_SIZE_COMPRESSOR_STAT,len)) { if(!StrCmpN(buf,TOTAL_SIZE_COMPRESSOR_STAT,len)) {
break; break;
} }
} }
else { else {
DWORD len = lstrlen(EXE_HEADER_COMPRESSOR_STAT); DWORD len = lstrlen(EXE_HEADER_COMPRESSOR_STAT);
if(!lstrncmp(buf,EXE_HEADER_COMPRESSOR_STAT,len)) { if(!StrCmpN(buf,EXE_HEADER_COMPRESSOR_STAT,len)) {
found = true; found = true;
lstrcpy(g_sdata.compressor_stats,_T("\n\n")); lstrcpy(g_sdata.compressor_stats,_T("\n\n"));
lstrcat(g_sdata.compressor_stats,buf); lstrcat(g_sdata.compressor_stats,buf);
@ -622,7 +622,7 @@ int InitBranding() {
void InitTooltips(HWND h) { void InitTooltips(HWND h) {
if (h == NULL) return; if (h == NULL) return;
my_memset(&g_tip,0,sizeof(NTOOLTIP)); memset(&g_tip,0,sizeof(NTOOLTIP));
g_tip.tip_p = h; g_tip.tip_p = h;
INITCOMMONCONTROLSEX icx; INITCOMMONCONTROLSEX icx;
icx.dwSize = sizeof(icx); icx.dwSize = sizeof(icx);
@ -668,7 +668,7 @@ LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
void ShowDocs() { void ShowDocs() {
TCHAR pathf[MAX_PATH],*path; TCHAR pathf[MAX_PATH],*path;
GetModuleFileName(NULL,pathf,sizeof(pathf)); GetModuleFileName(NULL,pathf,sizeof(pathf));
path=my_strrchr(pathf,_T('\\')); path=_tcsrchr(pathf,_T('\\'));
if(path!=NULL) *path=0; if(path!=NULL) *path=0;
lstrcat(pathf,LOCALDOCS); lstrcat(pathf,LOCALDOCS);
if ((int)ShellExecute(g_sdata.hwnd,_T("open"),pathf,NULL,NULL,SW_SHOWNORMAL)<=32) if ((int)ShellExecute(g_sdata.hwnd,_T("open"),pathf,NULL,NULL,SW_SHOWNORMAL)<=32)
@ -749,7 +749,7 @@ void PushMRUFile(TCHAR* fname)
return; return;
} }
my_memset(full_file_name,0,sizeof(full_file_name)); memset(full_file_name,0,sizeof(full_file_name));
rv = GetFullPathName(fname,COUNTOF(full_file_name),full_file_name,NULL); rv = GetFullPathName(fname,COUNTOF(full_file_name),full_file_name,NULL);
if (rv == 0) { if (rv == 0) {
return; return;
@ -783,19 +783,19 @@ void BuildMRUMenus()
for(i = 0; i < MRU_LIST_SIZE; i++) { for(i = 0; i < MRU_LIST_SIZE; i++) {
if(g_mru_list[i][0]) { if(g_mru_list[i][0]) {
my_memset(buf,0,sizeof(buf)); memset(buf,0,sizeof(buf));
my_memset(&mii, 0, sizeof(mii)); memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(mii); mii.cbSize = sizeof(mii);
mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE; mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
mii.wID = IDM_MRU_FILE+i; mii.wID = IDM_MRU_FILE+i;
mii.fType = MFT_STRING; mii.fType = MFT_STRING;
wsprintf(buf, _T("&%d "), i + 1); wsprintf(buf, _T("&%d "), i + 1);
if(lstrlen(g_mru_list[i]) > MRU_DISPLAY_LENGTH) { if(lstrlen(g_mru_list[i]) > MRU_DISPLAY_LENGTH) {
TCHAR *p = my_strrchr(g_mru_list[i],_T('\\')); TCHAR *p = _tcsrchr(g_mru_list[i],_T('\\'));
if(p) { if(p) {
p++; p++;
if(lstrlen(p) > MRU_DISPLAY_LENGTH - 7) { if(lstrlen(p) > MRU_DISPLAY_LENGTH - 7) {
my_memset(buf2,0,sizeof(buf2)); memset(buf2,0,sizeof(buf2));
lstrcpyn(buf2,p,MRU_DISPLAY_LENGTH - 9); lstrcpyn(buf2,p,MRU_DISPLAY_LENGTH - 9);
lstrcat(buf2,_T("...")); lstrcat(buf2,_T("..."));
@ -833,7 +833,7 @@ void BuildMRUMenus()
} }
hMenu = g_sdata.toolsSubmenu; hMenu = g_sdata.toolsSubmenu;
my_memset(&mii, 0, sizeof(mii)); memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(mii); mii.cbSize = sizeof(mii);
mii.fMask = MIIM_STATE; mii.fMask = MIIM_STATE;

View file

@ -21,11 +21,12 @@
Unicode support by Jim Park -- 08/17/2007 Unicode support by Jim Park -- 08/17/2007
*/ */
#include "makensisw.h"
#define REALSTR(x) #x #define REALSTR(x) #x
#define STR(x) REALSTR(x) #define STR(x) REALSTR(x)
#ifdef RELEASE #ifdef RELEASE
const char *NSISW_VERSION = "MakeNSISW " STR(RELEASE) " (NSIS Compiler Interface)"; const TCHAR *NSISW_VERSION = _T("MakeNSISW ") _T(STR(RELEASE)) _T(" (NSIS Compiler Interface)");
#else #else
const char *NSISW_VERSION = "MakeNSISW " __DATE__; const TCHAR *NSISW_VERSION = _T("MakeNSISW ") __TDATE__;
#endif #endif

View file

@ -18,9 +18,10 @@ libs = Split("""
""") """)
Import('BuildUtil env') Import('BuildUtil env')
Import('_tWinMain')
code = env.Object(code) code = env.Object(code)
for ui in uis: for ui in uis:
ui = BuildUtil(ui, [code], libs, entry = 'WinMain', res = ui + '.rc', contrib = True, path = 'UIs') ui = BuildUtil(ui, [code], libs, entry = _tWinMain, res = ui + '.rc', contrib = True, path = 'UIs')
env.Alias('UIs', ui) env.Alias('UIs', ui)

View file

@ -188,17 +188,30 @@ int tempzip_make(HWND hwndDlg, TCHAR *fn)
int nf=0, nkb=0; int nf=0, nkb=0;
g_extracting=1; g_extracting=1;
do { do {
TCHAR filename[MAX_PATH]; char filenameA[MAX_PATH];
unz_file_info info; unz_file_info info;
unzGetCurrentFileInfo(f,&info,filename,sizeof(filename),NULL,0,NULL,0); // ZREAD uses byte size, not TCHAR length.
unzGetCurrentFileInfo(f,&info,filenameA,sizeof(filenameA),NULL,0,NULL,0);
// was zip created on MS-DOS/Windows? // was zip created on MS-DOS/Windows?
if ((info.version & 0xFF00) == 0) if ((info.version & 0xFF00) == 0)
{ {
OemToCharBuff(filename, filename, strlen(filename)); OemToCharBuffA(filenameA, filenameA, strlen(filenameA));
} }
#ifdef _UNICODE
TCHAR filename[MAX_PATH];
if (MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filename, MAX_PATH) == 0)
{
if (f) unzClose(f);
MessageBox(hwndDlg,_T("Error converting filename to Unicode"), g_errcaption, MB_OK|MB_ICONSTOP);
return 1;
}
#else
char* filename = filenameA;
#endif
if (filename[0] && if (filename[0] &&
filename[_tcsclen(filename)-1] != _T('\\') && filename[_tcsclen(filename)-1] != _T('\\') &&
filename[_tcsclen(filename)-1] != _T('/')) filename[_tcsclen(filename)-1] != _T('/'))
@ -485,7 +498,11 @@ void makeEXE(HWND hwndDlg)
TCHAR buf[2048]; TCHAR buf[2048];
GetTempPath(MAX_PATH,buf); GetTempPath(MAX_PATH,buf);
GetTempFileName(buf,_T("zne"),0,nsifilename); GetTempFileName(buf,_T("zne"),0,nsifilename);
FILE *fp=fopen(nsifilename,_T("w")); #ifdef _UNICODE
FILE *fp=_tfopen(nsifilename,_T("w, ccs=UNICODE")); // generate a Unicode .NSI file
#else
FILE *fp=_tfopen(nsifilename,_T("w"));
#endif
if (!fp) if (!fp)
{ {
MessageBox(hwndDlg,_T("Error writing .NSI file"),g_errcaption,MB_OK|MB_ICONSTOP); MessageBox(hwndDlg,_T("Error writing .NSI file"),g_errcaption,MB_OK|MB_ICONSTOP);

View file

@ -11,7 +11,7 @@
#ifndef _ZLIBIOAPI_H #ifndef _ZLIBIOAPI_H
#define _ZLIBIOAPI_H #define _ZLIBIOAPI_H
#include "../../ExDLL/nsis_tchar.h" #include <tchar.h>
#define ZLIB_FILEFUNC_SEEK_CUR (1) #define ZLIB_FILEFUNC_SEEK_CUR (1)

View file

@ -94,7 +94,7 @@ To compile the documentation as a CHM file, hhc.exe must be in the PATH. It is a
To build NSIS Menu, install \W{http://www.wxwidgets.org/}{wxWidgets 2.8}, create an environment variable named \c{WXWIN} containing the path to the installation directory of wxWidgets, run \c{Contrib\\NSIS Menu\\wx\\wxbuild.bat} and build NSIS as usual. To build NSIS Menu, install \W{http://www.wxwidgets.org/}{wxWidgets 2.8}, create an environment variable named \c{WXWIN} containing the path to the installation directory of wxWidgets, run \c{Contrib\\NSIS Menu\\wx\\wxbuild.bat} and build NSIS as usual.
\\<b\\>Important notes for Microsoft Visual C++ 6.0 users:\\</b\\> The latest \W{http://www.microsoft.com/msdownload/platformsdk/sdkupdate/}{Platform SDK} must be installed before building. Because of flaws in the libraries distributed with Microsoft Visual C++ 6.0, not installing the Platform SDK will result in crashes when using the \R{copyfiles}{CopyFiles} command. See \W{http://forums.winamp.com/showthread.php?s=&threadid=131964}{this forum topic} for more information. Installing the \W{http://msdn.microsoft.com/vstudio/aa718349.aspx}{Processor Pack} is highly recommended xto decrease the size of the installer overhead. \\<b\\>Important notes for Microsoft Visual C++ 6.0 users:\\</b\\> The latest \W{http://www.microsoft.com/msdownload/platformsdk/sdkupdate/}{Platform SDK} must be installed before building. Because of flaws in the libraries distributed with Microsoft Visual C++ 6.0, not installing the Platform SDK will result in crashes when using the \R{copyfiles}{CopyFiles} command. See \W{http://forums.winamp.com/showthread.php?s=&threadid=131964}{this forum topic} for more information. Installing the \W{http://msdn.microsoft.com/vstudio/aa718349.aspx}{Processor Pack} is highly recommended to decrease the size of the installer overhead.
\H{build_posix} Building on POSIX \H{build_posix} Building on POSIX

View file

@ -338,7 +338,7 @@ def generate(env):
env['REGSVRFLAGS'] = '/s ' env['REGSVRFLAGS'] = '/s '
env['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS $TARGET' env['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS $TARGET'
env['MSVS_VERSION'] = '8.0' env['MSVS_VERSION'] = '7.1'
def exists(env): def exists(env):

View file

@ -185,11 +185,13 @@ if 'NSIS_CONFIG_CONST_DATA_PATH' in defenv['NSIS_CPPDEFINES']:
# Need this early for the config header files to be placed in # Need this early for the config header files to be placed in
if defenv['UNICODE']: if defenv['UNICODE']:
_tWinMain = 'wWinMain'
if defenv['DEBUG']: if defenv['DEBUG']:
defenv.Replace(BUILD_PREFIX = 'build/udebug') defenv.Replace(BUILD_PREFIX = 'build/udebug')
else: else:
defenv.Replace(BUILD_PREFIX = 'build/urelease') defenv.Replace(BUILD_PREFIX = 'build/urelease')
else: else:
_tWinMain = 'WinMain'
if defenv['DEBUG']: if defenv['DEBUG']:
defenv.Replace(BUILD_PREFIX = 'build/debug') defenv.Replace(BUILD_PREFIX = 'build/debug')
else: else:
@ -454,7 +456,7 @@ def build_installer(target, source, env):
AlwaysBuild(cmd) AlwaysBuild(cmd)
# Comment out the following if you want to see the installation directory # Comment out the following if you want to see the installation directory
# after the build is finished. # after the build is finished.
AlwaysBuild(env.AddPostAction(cmd, Delete('$INSTDISTDIR'))) #AlwaysBuild(env.AddPostAction(cmd, Delete('$INSTDISTDIR')))
env.Alias('dist-installer', cmd) env.Alias('dist-installer', cmd)
installer_target = defenv.Command('nsis-${VERSION}-setup${DISTSUFFIX}.exe', installer_target = defenv.Command('nsis-${VERSION}-setup${DISTSUFFIX}.exe',
@ -474,15 +476,9 @@ defenv.Alias('dist', ['dist-zip', 'dist-installer'])
for d in doc: for d in doc:
if d in defenv['SKIPDOC']: if d in defenv['SKIPDOC']:
continue continue
if defenv['UNICODE']: defenv.DistributeDoc(d)
defenv.DistributeDoc('Unicode/' + d)
else:
defenv.DistributeDoc(d)
if defenv['UNICODE']: defenv.DistributeConf('nsisconf.nsh')
defenv.DistributeConf('Unicode/nsisconf.nsh')
else:
defenv.DistributeConf('nsisconf.nsh')
###################################################################### ######################################################################
####### Stubs ### ####### Stubs ###
@ -678,7 +674,7 @@ for util in utils:
path = 'Contrib/' + util path = 'Contrib/' + util
build_dir = '$BUILD_PREFIX/' + util build_dir = '$BUILD_PREFIX/' + util
exports = {'BuildUtil' : BuildUtil, 'BuildUtilEnv' : BuildUtilEnv, 'env' : util_env} exports = {'BuildUtil' : BuildUtil, 'BuildUtilEnv' : BuildUtilEnv, 'env' : util_env, '_tWinMain' : _tWinMain}
defenv.SConscript(dirs = path, build_dir = build_dir, duplicate = False, exports = exports) defenv.SConscript(dirs = path, build_dir = build_dir, duplicate = False, exports = exports)

View file

@ -292,7 +292,7 @@ void CDialogTemplate::SetFont(TCHAR* szFaceName, WORD wFontSize) {
m_bCharset = DEFAULT_CHARSET; m_bCharset = DEFAULT_CHARSET;
m_dwStyle |= DS_SETFONT; m_dwStyle |= DS_SETFONT;
if (m_szFont) delete [] m_szFont; if (m_szFont) delete [] m_szFont;
m_szFont = winchar_fromansi(szFaceName, m_uCodePage); m_szFont = winchar_fromTchar(szFaceName, m_uCodePage);
m_sFontSize = wFontSize; m_sFontSize = wFontSize;
} }

View file

@ -59,7 +59,7 @@ void Plugins::FindCommands(const tstring &path, bool displayInfo)
struct NSISException : public std::runtime_error struct NSISException : public std::runtime_error
{ {
NSISException(const string& msg) : std::runtime_error(msg) {} NSISException(const tstring& msg) : std::runtime_error(string(TtoCString(msg))) {}
}; };
namespace { namespace {
@ -82,7 +82,7 @@ void read_file(const tstring& filename, vector<unsigned char>& data) {
ifstream file(filename.c_str(), ios::binary); ifstream file(filename.c_str(), ios::binary);
if (!file) { if (!file) {
throw NSISException("Can't open file '" + filename + "'"); throw NSISException(_T("Can't open file '") + filename + _T("'"));
} }
// get the file size // get the file size
@ -93,7 +93,7 @@ void read_file(const tstring& filename, vector<unsigned char>& data) {
file.read(reinterpret_cast<char*>(&data[0]), filesize); file.read(reinterpret_cast<char*>(&data[0]), filesize);
if (size_t(file.tellg()) != filesize) { // ifstream::eof doesn't return true here if (size_t(file.tellg()) != filesize) { // ifstream::eof doesn't return true here
throw NSISException("Couldn't read entire file '" + filename + "'"); throw NSISException(_T("Couldn't read entire file '") + filename + _T("'"));
} }
} }
} }
@ -139,7 +139,7 @@ void Plugins::GetExports(const tstring &pathToDll, bool displayInfo)
for (DWORD j = 0; j < FIX_ENDIAN_INT32(exports->NumberOfNames); j++) for (DWORD j = 0; j < FIX_ENDIAN_INT32(exports->NumberOfNames); j++)
{ {
const string name = string((char*)exports + FIX_ENDIAN_INT32(names[j]) - ExportDirVA); const string name = string((char*)exports + FIX_ENDIAN_INT32(names[j]) - ExportDirVA);
const tstring signature = dllName + _T("::") + name; const tstring signature = dllName + _T("::") + tstring(CtoTString(name));
const tstring lcsig = lowercase(signature); const tstring lcsig = lowercase(signature);
m_command_to_path[lcsig] = pathToDll; m_command_to_path[lcsig] = pathToDll;
m_command_lowercase_to_command[lcsig] = signature; m_command_lowercase_to_command[lcsig] = signature;

View file

@ -217,48 +217,30 @@ bool CResourceEditor::UpdateResourceW(WCHAR* szType, WCHAR* szName, LANGID wLang
return true; return true;
} }
#ifndef _UNICODE
static WCHAR* ResStringToUnicode(const char *szString) { static WCHAR* ResStringToUnicode(const char *szString) {
if (IS_INTRESOURCE(szString)) if (IS_INTRESOURCE(szString))
return MAKEINTRESOURCEW((ULONG_PTR)szString); return MAKEINTRESOURCEW((ULONG_PTR)szString);
else else
return winchar_fromansi(szString); return winchar_fromTchar(szString);
} }
#endif
static void FreeUnicodeResString(WCHAR* szwString) { static void FreeUnicodeResString(WCHAR* szwString) {
if (!IS_INTRESOURCE(szwString)) if (!IS_INTRESOURCE(szwString))
delete [] szwString; delete [] szwString;
} }
bool CResourceEditor::UpdateResourceW(WORD szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
return UpdateResourceW(MAKEINTRESOURCEW(szType), szName, wLanguage, lpData, dwSize);
}
bool CResourceEditor::UpdateResourceW(WCHAR* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) { bool CResourceEditor::UpdateResource(TCHAR* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
#ifdef _UNICODE
return UpdateResourceW(szType, MAKEINTRESOURCEW(szName), wLanguage, lpData, dwSize); return UpdateResourceW(szType, MAKEINTRESOURCEW(szName), wLanguage, lpData, dwSize);
} #else
bool CResourceEditor::UpdateResourceA(char* szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
WCHAR* szwType = ResStringToUnicode(szType); WCHAR* szwType = ResStringToUnicode(szType);
WCHAR* szwName = ResStringToUnicode(szName); bool result = UpdateResourceW(szwType, MAKEINTRESOURCEW(szName), wLanguage, lpData, dwSize);
bool result = UpdateResourceW(szwType, szwName, wLanguage, lpData, dwSize);
FreeUnicodeResString(szwType); FreeUnicodeResString(szwType);
FreeUnicodeResString(szwName);
return result; return result;
} #endif
bool CResourceEditor::UpdateResourceA(WORD szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
return UpdateResourceA(MAKEINTRESOURCE(szType), szName, wLanguage, lpData, dwSize);
}
bool CResourceEditor::UpdateResourceA(char* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
return UpdateResourceA(szType, MAKEINTRESOURCE(szName), wLanguage, lpData, dwSize);
}
bool CResourceEditor::UpdateResource(WORD szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize) {
return UpdateResourceW(MAKEINTRESOURCEW(szType), MAKEINTRESOURCEW(szName), wLanguage, lpData, dwSize);
} }
// Returns a copy of the requested resource // Returns a copy of the requested resource
@ -295,16 +277,15 @@ BYTE* CResourceEditor::GetResourceW(WCHAR* szType, WCHAR* szName, LANGID wLangua
return NULL; return NULL;
} }
BYTE* CResourceEditor::GetResourceA(char* szType, char* szName, LANGID wLanguage) { BYTE* CResourceEditor::GetResource(TCHAR* szType, WORD szName, LANGID wLanguage) {
#ifdef _UNICODE
return GetResourceW(szType, MAKEINTRESOURCEW(szName), wLanguage);
#else
WCHAR* szwType = ResStringToUnicode(szType); WCHAR* szwType = ResStringToUnicode(szType);
WCHAR* szwName = ResStringToUnicode(szName); BYTE* result = GetResourceW(szwType, MAKEINTRESOURCEW(szName), wLanguage);
BYTE* result = GetResourceW(szwType, szwName, wLanguage);
FreeUnicodeResString(szwType); FreeUnicodeResString(szwType);
FreeUnicodeResString(szwName);
return result; return result;
#endif
} }
// Returns the size of the requested resource // Returns the size of the requested resource
@ -335,16 +316,15 @@ int CResourceEditor::GetResourceSizeW(WCHAR* szType, WCHAR* szName, LANGID wLang
return -1; return -1;
} }
int CResourceEditor::GetResourceSizeA(char* szType, char* szName, LANGID wLanguage) { int CResourceEditor::GetResourceSize(TCHAR* szType, WORD szName, LANGID wLanguage) {
#ifdef _UNICODE
return GetResourceSizeW(szType, MAKEINTRESOURCEW(szName), wLanguage);
#else
WCHAR* szwType = ResStringToUnicode(szType); WCHAR* szwType = ResStringToUnicode(szType);
WCHAR* szwName = ResStringToUnicode(szName); int result = GetResourceSizeW(szwType, MAKEINTRESOURCEW(szName), wLanguage);
int result = GetResourceSizeW(szwType, szwName, wLanguage);
FreeUnicodeResString(szwType); FreeUnicodeResString(szwType);
FreeUnicodeResString(szwName);
return result; return result;
#endif
} }
// Returns the offset of the requested resource in the original PE // Returns the offset of the requested resource in the original PE
@ -375,16 +355,15 @@ DWORD CResourceEditor::GetResourceOffsetW(WCHAR* szType, WCHAR* szName, LANGID w
return DWORD(-1); return DWORD(-1);
} }
DWORD CResourceEditor::GetResourceOffsetA(char* szType, char* szName, LANGID wLanguage) { DWORD CResourceEditor::GetResourceOffset(TCHAR* szType, WORD szName, LANGID wLanguage) {
#ifdef _UNICODE
return GetResourceOffsetW(szType, MAKEINTRESOURCEW(szName), wLanguage);
#else
WCHAR* szwType = ResStringToUnicode(szType); WCHAR* szwType = ResStringToUnicode(szType);
WCHAR* szwName = ResStringToUnicode(szName); DWORD result = GetResourceOffsetW(szwType, MAKEINTRESOURCEW(szName), wLanguage);
DWORD result = GetResourceOffsetW(szwType, szwName, wLanguage);
FreeUnicodeResString(szwType); FreeUnicodeResString(szwType);
FreeUnicodeResString(szwName);
return result; return result;
#endif
} }
void CResourceEditor::FreeResource(BYTE* pbResource) void CResourceEditor::FreeResource(BYTE* pbResource)
@ -884,7 +863,7 @@ int CResourceDirectory::Find(WCHAR* szName) {
return Find((WORD) (ULONG_PTR) szName); return Find((WORD) (ULONG_PTR) szName);
else else
if (szName[0] == L'#') if (szName[0] == L'#')
return Find(WORD(winchar_stoi(szName + 1))); return Find(WORD(_wtoi(szName + 1)));
for (unsigned int i = 0; i < m_vEntries.size(); i++) { for (unsigned int i = 0; i < m_vEntries.size(); i++) {
if (!m_vEntries[i]->HasName()) if (!m_vEntries[i]->HasName())

View file

@ -114,19 +114,10 @@ public:
CResourceEditor(BYTE* pbPE, int iSize, bool bKeepData = true); CResourceEditor(BYTE* pbPE, int iSize, bool bKeepData = true);
virtual ~CResourceEditor(); virtual ~CResourceEditor();
bool UpdateResource(WORD szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize); bool UpdateResource (TCHAR* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
bool UpdateResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize); BYTE* GetResource (TCHAR* szType, WORD szName, LANGID wLanguage);
bool UpdateResourceW(WORD szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize); int GetResourceSize (TCHAR* szType, WORD szName, LANGID wLanguage);
bool UpdateResourceW(WCHAR* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize); DWORD GetResourceOffset(TCHAR* szType, WORD szName, LANGID wLanguage);
bool UpdateResourceA(char* szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
bool UpdateResourceA(WORD szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
bool UpdateResourceA(char* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
BYTE* GetResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
BYTE* GetResourceA(char* szType, char* szName, LANGID wLanguage);
int GetResourceSizeW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
int GetResourceSizeA(char* szType, char* szName, LANGID wLanguage);
DWORD GetResourceOffsetW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
DWORD GetResourceOffsetA(char* szType, char* szName, LANGID wLanguage);
void FreeResource(BYTE* pbResource); void FreeResource(BYTE* pbResource);
// The section name must be in ASCII. // The section name must be in ASCII.
@ -143,6 +134,11 @@ public:
DWORD *pdwResSecVA = NULL, DWORD *pdwResSecVA = NULL,
DWORD *pdwSectionIndex = NULL DWORD *pdwSectionIndex = NULL
); );
private:
bool UpdateResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
BYTE* GetResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
int GetResourceSizeW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
DWORD GetResourceOffsetW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
private: private:
BYTE* m_pbPE; BYTE* m_pbPE;

View file

@ -57,7 +57,7 @@ CVersionStrigList::~CVersionStrigList()
int CVersionStrigList::add(LANGID langid, int codepage) int CVersionStrigList::add(LANGID langid, int codepage)
{ {
TCHAR Buff[10]; TCHAR Buff[10];
sprintf(Buff, _T("%04x"), langid); _stprintf(Buff, _T("%04x"), langid);
int pos = SortedStringListND<struct version_string_list>::add(Buff); int pos = SortedStringListND<struct version_string_list>::add(Buff);
if (pos == -1) return false; if (pos == -1) return false;
((struct version_string_list*)gr.get())[pos].pChildStrings = new DefineList; ((struct version_string_list*)gr.get())[pos].pChildStrings = new DefineList;
@ -87,7 +87,7 @@ DefineList* CVersionStrigList::get_strings(int idx)
int CVersionStrigList::find(LANGID lang_id, int codepage) int CVersionStrigList::find(LANGID lang_id, int codepage)
{ {
TCHAR Buff[10]; TCHAR Buff[10];
sprintf(Buff, _T("%04x"), lang_id); _stprintf(Buff, _T("%04x"), lang_id);
return SortedStringListND<struct version_string_list>::find(Buff); return SortedStringListND<struct version_string_list>::find(Buff);
} }
@ -218,8 +218,8 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
PadStream (stringInfoStream); PadStream (stringInfoStream);
p = stringInfoStream.getlen(); p = stringInfoStream.getlen();
KeyName = winchar_fromansi(pChildStrings->getname(i), codepage); KeyName = winchar_fromTchar(pChildStrings->getname(i), codepage);
KeyValue = winchar_fromansi(pChildStrings->getvalue(i), codepage); KeyValue = winchar_fromTchar(pChildStrings->getvalue(i), codepage);
SaveVersionHeader (stringInfoStream, 0, WORD(winchar_strlen(KeyValue) + 1), 1, KeyName, (void*)KeyValue); SaveVersionHeader (stringInfoStream, 0, WORD(winchar_strlen(KeyValue) + 1), 1, KeyName, (void*)KeyValue);
delete [] KeyName; delete [] KeyName;
delete [] KeyValue; delete [] KeyValue;

View file

@ -11,35 +11,24 @@
class WinCharTest : public CppUnit::TestFixture { class WinCharTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( WinCharTest ); CPPUNIT_TEST_SUITE( WinCharTest );
CPPUNIT_TEST( testFromAnsi ); CPPUNIT_TEST( testFromTchar );
CPPUNIT_TEST( testToAnsi );
CPPUNIT_TEST( testStrCpy ); CPPUNIT_TEST( testStrCpy );
CPPUNIT_TEST( testStrNCpy ); CPPUNIT_TEST( testStrNCpy );
CPPUNIT_TEST( testStrLen ); CPPUNIT_TEST( testStrLen );
CPPUNIT_TEST( testStrCmp ); CPPUNIT_TEST( testStrCmp );
CPPUNIT_TEST( testStrDup ); CPPUNIT_TEST( testStrDup );
CPPUNIT_TEST( testStoi );
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
public: public:
void testFromAnsi() { void testFromTchar() {
WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR *dyn = winchar_fromansi("test"); WCHAR *dyn = winchar_fromTchar("test");
CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) );
delete [] dyn; delete [] dyn;
} }
void testToAnsi() {
WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
char *dyn = winchar_toansi(test);
CPPUNIT_ASSERT_EQUAL( 0, strcmp("test", dyn) );
delete [] dyn;
}
void testStrCpy() { void testStrCpy() {
WCHAR a[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; WCHAR a[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR b[5]; WCHAR b[5];
@ -111,20 +100,6 @@ public:
delete [] b; delete [] b;
} }
void testStoi() {
srand(time(0));
for (int i = 0; i < 1000; i++)
{
int r = rand();
char s[128];
sprintf(s, "%d", r);
WCHAR *ws = winchar_fromansi(s);
CPPUNIT_ASSERT_EQUAL( r, winchar_stoi(ws) );
delete [] ws;
}
}
}; };
CPPUNIT_TEST_SUITE_REGISTRATION( WinCharTest ); CPPUNIT_TEST_SUITE_REGISTRATION( WinCharTest );

View file

@ -1733,7 +1733,7 @@ int CEXEBuild::AddVersionInfo()
warning(_T("Generating version information for language \"%04d-%s\" without standard key \"LegalCopyright\""), lang_id, lang_name); warning(_T("Generating version information for language \"%04d-%s\" without standard key \"LegalCopyright\""), lang_id, lang_name);
rVersionInfo.ExportToStream(VerInfoStream, i); rVersionInfo.ExportToStream(VerInfoStream, i);
res_editor->UpdateResourceA(RT_VERSION, 1, lang_id, (BYTE*)VerInfoStream.get(), VerInfoStream.getlen()); res_editor->UpdateResource(RT_VERSION, 1, lang_id, (BYTE*)VerInfoStream.get(), VerInfoStream.getlen());
} }
} }
catch (exception& err) { catch (exception& err) {
@ -2073,7 +2073,7 @@ again:
SCRIPT_MSG(_T("Done!\n")); SCRIPT_MSG(_T("Done!\n"));
#define REMOVE_ICON(id) if (disable_window_icon) { \ #define REMOVE_ICON(id) if (disable_window_icon) { \
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \ BYTE* dlg = res_editor->GetResource(RT_DIALOG, id, NSIS_DEFAULT_LANG); \
if (dlg) { \ if (dlg) { \
CDialogTemplate dt(dlg,uDefCodePage); \ CDialogTemplate dt(dlg,uDefCodePage); \
res_editor->FreeResource(dlg); \ res_editor->FreeResource(dlg); \
@ -2091,7 +2091,7 @@ again:
\ \
DWORD dwSize; \ DWORD dwSize; \
dlg = dt.Save(dwSize); \ dlg = dt.Save(dwSize); \
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \ res_editor->UpdateResource(RT_DIALOG, id, NSIS_DEFAULT_LANG, dlg, dwSize); \
delete [] dlg; \ delete [] dlg; \
} \ } \
} \ } \
@ -2102,43 +2102,43 @@ again:
init_res_editor(); init_res_editor();
#ifdef NSIS_CONFIG_LICENSEPAGE #ifdef NSIS_CONFIG_LICENSEPAGE
if (!license_normal) { if (!license_normal) {
res_editor->UpdateResourceA(RT_DIALOG, IDD_LICENSE, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE, NSIS_DEFAULT_LANG, 0, 0);
} }
else REMOVE_ICON(IDD_LICENSE); else REMOVE_ICON(IDD_LICENSE);
if (!license_fsrb) { if (!license_fsrb) {
res_editor->UpdateResourceA(RT_DIALOG, IDD_LICENSE_FSRB, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE_FSRB, NSIS_DEFAULT_LANG, 0, 0);
} }
else REMOVE_ICON(IDD_LICENSE_FSRB); else REMOVE_ICON(IDD_LICENSE_FSRB);
if (!license_fscb) { if (!license_fscb) {
res_editor->UpdateResourceA(RT_DIALOG, IDD_LICENSE_FSCB, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE_FSCB, NSIS_DEFAULT_LANG, 0, 0);
} }
else REMOVE_ICON(IDD_LICENSE_FSCB); else REMOVE_ICON(IDD_LICENSE_FSCB);
#endif // NSIS_CONFIG_LICENSEPAGE #endif // NSIS_CONFIG_LICENSEPAGE
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
if (!selcom) { if (!selcom) {
res_editor->UpdateResourceA(RT_DIALOG, IDD_SELCOM, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_DIALOG, IDD_SELCOM, NSIS_DEFAULT_LANG, 0, 0);
res_editor->UpdateResourceA(RT_BITMAP, IDB_BITMAP1, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_BITMAP, IDB_BITMAP1, NSIS_DEFAULT_LANG, 0, 0);
} }
else REMOVE_ICON(IDD_SELCOM); else REMOVE_ICON(IDD_SELCOM);
#endif // NSIS_CONFIG_COMPONENTPAGE #endif // NSIS_CONFIG_COMPONENTPAGE
if (!dir) { if (!dir) {
res_editor->UpdateResourceA(RT_DIALOG, IDD_DIR, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_DIALOG, IDD_DIR, NSIS_DEFAULT_LANG, 0, 0);
} }
else REMOVE_ICON(IDD_DIR); else REMOVE_ICON(IDD_DIR);
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
if (!uninstconfirm) { if (!uninstconfirm) {
res_editor->UpdateResourceA(RT_DIALOG, IDD_UNINST, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_DIALOG, IDD_UNINST, NSIS_DEFAULT_LANG, 0, 0);
} }
else REMOVE_ICON(IDD_UNINST); else REMOVE_ICON(IDD_UNINST);
#endif // NSIS_CONFIG_UNINSTALL_SUPPORT #endif // NSIS_CONFIG_UNINSTALL_SUPPORT
if (!instlog) { if (!instlog) {
res_editor->UpdateResourceA(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, 0, 0);
} }
else REMOVE_ICON(IDD_INSTFILES); else REMOVE_ICON(IDD_INSTFILES);
if (!main) { if (!main) {
res_editor->UpdateResourceA(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, 0, 0);
if (!build_compress_whole && !build_crcchk) if (!build_compress_whole && !build_crcchk)
res_editor->UpdateResourceA(RT_DIALOG, IDD_VERIFY, NSIS_DEFAULT_LANG, 0, 0); res_editor->UpdateResource(RT_DIALOG, IDD_VERIFY, NSIS_DEFAULT_LANG, 0, 0);
} }
SCRIPT_MSG(_T("Done!\n")); SCRIPT_MSG(_T("Done!\n"));
@ -2279,7 +2279,7 @@ int CEXEBuild::SetManifest()
return PS_OK; return PS_OK;
// Saved directly as binary into the exe. // Saved directly as binary into the exe.
res_editor->UpdateResourceA(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), NSIS_DEFAULT_LANG, (LPBYTE) manifest.c_str(), manifest.length()); res_editor->UpdateResource(MAKEINTRESOURCE(24), 1, NSIS_DEFAULT_LANG, (LPBYTE) manifest.c_str(), manifest.length());
} }
catch (exception& err) { catch (exception& err) {
ERROR_MSG(_T("Error setting manifest: %s\n"), CtoTString(err.what())); ERROR_MSG(_T("Error setting manifest: %s\n"), CtoTString(err.what()));

View file

@ -1174,13 +1174,13 @@ static int NSISCALL ExecuteEntry(entry *entry_)
break; break;
case EW_READINISTR: case EW_READINISTR:
{ {
DWORD errstr = CHAR4_TO_DWORD(_T('!'), _T('N'), _T('~'), 0); TCHAR errstr[] = _T("!N~");
TCHAR *p=var0; TCHAR *p=var0;
TCHAR *buf0=GetStringFromParm(0x01); TCHAR *buf0=GetStringFromParm(0x01);
TCHAR *buf1=GetStringFromParm(0x12); TCHAR *buf1=GetStringFromParm(0x12);
TCHAR *buf2=GetStringFromParm(-0x23); TCHAR *buf2=GetStringFromParm(-0x23);
GetPrivateProfileString(buf0,buf1,(LPCTSTR)&errstr,p,NSIS_MAX_STRLEN-1,buf2); GetPrivateProfileString(buf0,buf1,errstr,p,NSIS_MAX_STRLEN-1,buf2);
if (*(DWORD*)p == errstr) if (lstrcmp(p, errstr) == 0)
{ {
exec_error++; exec_error++;
p[0]=0; p[0]=0;

View file

@ -272,7 +272,6 @@ enum {
}; };
// nsis strings // nsis strings
typedef TCHAR NSIS_STRING[NSIS_MAX_STRLEN]; typedef TCHAR NSIS_STRING[NSIS_MAX_STRLEN];
// Settings common to both installers and uninstallers // Settings common to both installers and uninstallers

View file

@ -49,8 +49,8 @@ IconGroup load_icon_res(CResourceEditor* re, WORD id)
IconGroupHeader* header; IconGroupHeader* header;
IconGroup result; IconGroup result;
LPBYTE group = re->GetResourceA( LPBYTE group = re->GetResource(
RT_GROUP_ICON, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); RT_GROUP_ICON, id, NSIS_DEFAULT_LANG);
if (!group) if (!group)
throw runtime_error("can't find icon group"); throw runtime_error("can't find icon group");
@ -69,7 +69,7 @@ IconGroup load_icon_res(CResourceEditor* re, WORD id)
WORD rsrc_id = FIX_ENDIAN_INT16(entry->wRsrcId); WORD rsrc_id = FIX_ENDIAN_INT16(entry->wRsrcId);
icon.data = re->GetResourceA(RT_ICON, MAKEINTRESOURCE(rsrc_id), NSIS_DEFAULT_LANG); icon.data = re->GetResource(RT_ICON, rsrc_id, NSIS_DEFAULT_LANG);
if (!icon.data) if (!icon.data)
{ {
@ -276,17 +276,17 @@ void set_icon(CResourceEditor* re, WORD wIconId, IconGroup icon1, IconGroup icon
size_t group_size = sizeof(IconGroupHeader) // header size_t group_size = sizeof(IconGroupHeader) // header
+ order.size() * SIZEOF_RSRC_ICON_GROUP_ENTRY; // entries + order.size() * SIZEOF_RSRC_ICON_GROUP_ENTRY; // entries
re->UpdateResourceA(RT_GROUP_ICON, MAKEINTRESOURCE(wIconId), NSIS_DEFAULT_LANG, group1, group_size); re->UpdateResource(RT_GROUP_ICON, wIconId, NSIS_DEFAULT_LANG, group1, group_size);
// delete old icons // delete old icons
unsigned i = 1; unsigned i = 1;
while (re->UpdateResourceA(RT_ICON, MAKEINTRESOURCE(i++), NSIS_DEFAULT_LANG, 0, 0)); while (re->UpdateResource(RT_ICON, i++, NSIS_DEFAULT_LANG, 0, 0));
// set new icons // set new icons
IconGroup::size_type order_index; IconGroup::size_type order_index;
for (order_index = 0; order_index < order.size(); order_index++) for (order_index = 0; order_index < order.size(); order_index++)
{ {
DWORD size_index = order[order_index].size_index; WORD size_index = order[order_index].size_index;
DWORD size = order[order_index].size; DWORD size = order[order_index].size;
LPBYTE data = new BYTE[size]; LPBYTE data = new BYTE[size];
memset(data, 0, size); memset(data, 0, size);
@ -297,7 +297,7 @@ void set_icon(CResourceEditor* re, WORD wIconId, IconGroup icon1, IconGroup icon
memcpy(data, icon->data, FIX_ENDIAN_INT32(icon->meta.dwRawSize)); memcpy(data, icon->data, FIX_ENDIAN_INT32(icon->meta.dwRawSize));
} }
re->UpdateResourceA(RT_ICON, MAKEINTRESOURCE(size_index + 1), NSIS_DEFAULT_LANG, data, size); re->UpdateResource(RT_ICON, size_index + 1, NSIS_DEFAULT_LANG, data, size);
delete [] data; delete [] data;
} }
@ -375,7 +375,7 @@ int generate_unicons_offsets(LPBYTE exeHeader, size_t exeHeaderSize, LPBYTE unin
LPBYTE seeker = uninstIconData; LPBYTE seeker = uninstIconData;
offset = re.GetResourceOffsetA(RT_GROUP_ICON, MAKEINTRESOURCE(wIconId), NSIS_DEFAULT_LANG); offset = re.GetResourceOffset(RT_GROUP_ICON, wIconId, NSIS_DEFAULT_LANG);
size = FIX_ENDIAN_INT32(*(LPDWORD)seeker); size = FIX_ENDIAN_INT32(*(LPDWORD)seeker);
seeker += sizeof(DWORD); seeker += sizeof(DWORD);
@ -388,14 +388,14 @@ int generate_unicons_offsets(LPBYTE exeHeader, size_t exeHeaderSize, LPBYTE unin
while (*(LPDWORD)seeker) while (*(LPDWORD)seeker)
{ {
offset = re.GetResourceOffsetA(RT_ICON, MAKEINTRESOURCE(icon_index), NSIS_DEFAULT_LANG); offset = re.GetResourceOffset(RT_ICON, icon_index, NSIS_DEFAULT_LANG);
if (offset > exeHeaderSize) if (offset > exeHeaderSize)
{ {
throw runtime_error(_T("invalid icon offset (possibly compressed icon)")); throw runtime_error("invalid icon offset (possibly compressed icon)");
} }
DWORD real_size = re.GetResourceSizeA(RT_ICON, MAKEINTRESOURCE(icon_index), NSIS_DEFAULT_LANG); DWORD real_size = re.GetResourceSize(RT_ICON, icon_index, NSIS_DEFAULT_LANG);
size = FIX_ENDIAN_INT32(*(LPDWORD)seeker); size = FIX_ENDIAN_INT32(*(LPDWORD)seeker);
seeker += sizeof(DWORD); seeker += sizeof(DWORD);

View file

@ -286,7 +286,7 @@ int StringsArray::set(int idx, const TCHAR *str)
int old = ((int*)offsets.get())[idx]; int old = ((int*)offsets.get())[idx];
((int*)offsets.get())[idx] = strings.add(str, strlen(str) + 1); ((int*)offsets.get())[idx] = strings.add(str, (_tcsclen(str)+1)*sizeof(TCHAR))/sizeof(TCHAR);
return old; return old;
} }
@ -696,14 +696,14 @@ int CEXEBuild::GenerateLangTables() {
init_res_editor(); init_res_editor();
#define ADD_FONT(id) { \ #define ADD_FONT(id) { \
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \ BYTE* dlg = res_editor->GetResource(RT_DIALOG, id, NSIS_DEFAULT_LANG); \
if (dlg) { \ if (dlg) { \
CDialogTemplate td(dlg); \ CDialogTemplate td(dlg); \
res_editor->FreeResource(dlg); \ res_editor->FreeResource(dlg); \
td.SetFont(build_font, (WORD) build_font_size); \ td.SetFont(build_font, (WORD) build_font_size); \
DWORD dwSize; \ DWORD dwSize; \
dlg = td.Save(dwSize); \ dlg = td.Save(dwSize); \
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \ res_editor->UpdateResource(RT_DIALOG, id, NSIS_DEFAULT_LANG, dlg, dwSize); \
delete [] dlg; \ delete [] dlg; \
} \ } \
} }
@ -751,7 +751,7 @@ int CEXEBuild::GenerateLangTables() {
init_res_editor(); init_res_editor();
#define ADD_FONT(id) { \ #define ADD_FONT(id) { \
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \ BYTE* dlg = res_editor->GetResource(RT_DIALOG, id, NSIS_DEFAULT_LANG); \
if (dlg) { \ if (dlg) { \
CDialogTemplate td(dlg,lt[i].nlf.m_uCodePage); \ CDialogTemplate td(dlg,lt[i].nlf.m_uCodePage); \
res_editor->FreeResource(dlg); \ res_editor->FreeResource(dlg); \
@ -766,7 +766,7 @@ int CEXEBuild::GenerateLangTables() {
} \ } \
DWORD dwSize; \ DWORD dwSize; \
dlg = td.Save(dwSize); \ dlg = td.Save(dwSize); \
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(id+cur_offset), NSIS_DEFAULT_LANG, dlg, dwSize); \ res_editor->UpdateResource(RT_DIALOG, id+cur_offset, NSIS_DEFAULT_LANG, dlg, dwSize); \
delete [] dlg; \ delete [] dlg; \
} \ } \
} }

View file

@ -2157,7 +2157,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
try { try {
init_res_editor(); init_res_editor();
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG); BYTE* dlg = res_editor->GetResource(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG);
if (!dlg) throw runtime_error("IDD_INSTFILES doesn't exist!"); if (!dlg) throw runtime_error("IDD_INSTFILES doesn't exist!");
CDialogTemplate dt(dlg,uDefCodePage); CDialogTemplate dt(dlg,uDefCodePage);
free(dlg); free(dlg);
@ -2173,7 +2173,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DWORD dwSize; DWORD dwSize;
dlg = dt.Save(dwSize); dlg = dt.Save(dwSize);
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG, dlg, dwSize); res_editor->UpdateResource(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, dlg, dwSize);
delete [] dlg; delete [] dlg;
} }
catch (exception& err) { catch (exception& err) {
@ -2452,9 +2452,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
init_res_editor(); init_res_editor();
// Search for required items // Search for required items
#define GET(x) dlg = uire->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(x), 0); if (!dlg) return PS_ERROR; CDialogTemplate UIDlg(dlg, uDefCodePage); #define GET(x) dlg = uire->GetResource(RT_DIALOG, x, 0); if (!dlg) return PS_ERROR; CDialogTemplate UIDlg(dlg, uDefCodePage);
#define SEARCH(x) if (!UIDlg.GetItem(x)) {ERROR_MSG("Error: Can't find %s (%u) in the custom UI!\n", #x, x);delete [] dlg;delete uire;return PS_ERROR;} #define SEARCH(x) if (!UIDlg.GetItem(x)) {ERROR_MSG(_T("Error: Can't find %s (%u) in the custom UI!\n"), _T(#x), x);delete [] dlg;delete uire;return PS_ERROR;}
#define SAVE(x) dwSize = UIDlg.GetSize(); res_editor->UpdateResourceA(RT_DIALOG, x, NSIS_DEFAULT_LANG, dlg, dwSize); delete [] dlg; #define SAVE(x) dwSize = UIDlg.GetSize(); res_editor->UpdateResource(RT_DIALOG, x, NSIS_DEFAULT_LANG, dlg, dwSize); delete [] dlg;
LPBYTE dlg = NULL; LPBYTE dlg = NULL;
@ -2570,7 +2570,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
padding = line.gettoken_int(3); padding = line.gettoken_int(3);
init_res_editor(); init_res_editor();
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG); BYTE* dlg = res_editor->GetResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG);
CDialogTemplate dt(dlg, uDefCodePage); CDialogTemplate dt(dlg, uDefCodePage);
@ -2618,7 +2618,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DWORD dwDlgSize; DWORD dwDlgSize;
dlg = dt.Save(dwDlgSize); dlg = dt.Save(dwDlgSize);
res_editor->UpdateResourceA(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize); res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize);
delete [] dlg; delete [] dlg;
@ -2846,7 +2846,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
for (;;) { for (;;) {
TCHAR *p=str; TCHAR *p=str;
*p=0; *p=0;
fgets(str,MAX_LINELENGTH,fp); _fgetts(str,MAX_LINELENGTH,fp);
linecnt++; linecnt++;
if (feof(fp)&&!str[0]) break; if (feof(fp)&&!str[0]) break;
@ -3668,7 +3668,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (trim) try { if (trim) try {
init_res_editor(); init_res_editor();
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG); BYTE* dlg = res_editor->GetResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG);
CDialogTemplate td(dlg,uDefCodePage); CDialogTemplate td(dlg,uDefCodePage);
free(dlg); free(dlg);
@ -3695,7 +3695,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
DWORD dwSize; DWORD dwSize;
dlg = td.Save(dwSize); dlg = td.Save(dwSize);
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG, dlg, dwSize); res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwSize);
res_editor->FreeResource(dlg); res_editor->FreeResource(dlg);
} }
catch (exception& err) { catch (exception& err) {

View file

@ -20,7 +20,7 @@ int StringList::add(const TCHAR *str, int case_sensitive)
{ {
int a=find(str,case_sensitive); int a=find(str,case_sensitive);
if (a >= 0 && case_sensitive!=-1) return a; if (a >= 0 && case_sensitive!=-1) return a;
return gr.add(str,strlen(str)+1); return gr.add(str,(_tcsclen(str)+1)*sizeof(TCHAR))/sizeof(TCHAR);
} }
// use 2 for case sensitive end-of-string matches too // use 2 for case sensitive end-of-string matches too
@ -32,18 +32,18 @@ int StringList::find(const TCHAR *str, int case_sensitive, int *idx/*=NULL*/) co
if (idx) *idx=0; if (idx) *idx=0;
while (offs < ml) while (offs < ml)
{ {
if ((case_sensitive && !strcmp(s+offs,str)) || if ((case_sensitive && !_tcscmp(s+offs,str)) ||
(!case_sensitive && !stricmp(s+offs,str))) (!case_sensitive && !_tcsicmp(s+offs,str)))
{ {
return offs; return offs;
} }
if (case_sensitive==2 && if (case_sensitive==2 &&
strlen(str) < strlen(s+offs) && // check for end of string _tcslen(str) < _tcslen(s+offs) && // check for end of string
!strcmp(s+offs+strlen(s+offs)-strlen(str),str)) !_tcscmp(s+offs+_tcslen(s+offs)-_tcslen(str),str))
{ {
return offs+strlen(s+offs)-strlen(str); return offs+_tcslen(s+offs)-_tcslen(str);
} }
offs+=strlen(s+offs)+1; offs+=_tcslen(s+offs)+1;
if (idx) (*idx)++; if (idx) (*idx)++;
} }
return -1; return -1;
@ -52,7 +52,7 @@ int StringList::find(const TCHAR *str, int case_sensitive, int *idx/*=NULL*/) co
void StringList::delbypos(int pos) void StringList::delbypos(int pos)
{ {
TCHAR *s=(TCHAR*)gr.get(); TCHAR *s=(TCHAR*)gr.get();
int len=strlen(s+pos)+1; int len=_tcslen(s+pos)+1;
if (pos+len < gr.getlen()) memcpy(s+pos,s+pos+len,gr.getlen()-(pos+len)); if (pos+len < gr.getlen()) memcpy(s+pos,s+pos+len,gr.getlen()-(pos+len));
gr.resize(gr.getlen()-len); gr.resize(gr.getlen()-len);
} }
@ -65,7 +65,7 @@ int StringList::idx2pos(int idx) const
if (idx>=0) while (offs < gr.getlen()) if (idx>=0) while (offs < gr.getlen())
{ {
if (cnt++ == idx) return offs; if (cnt++ == idx) return offs;
offs+=strlen(s+offs)+1; offs+=_tcslen(s+offs)+1;
} }
return -1; return -1;
} }
@ -78,7 +78,7 @@ int StringList::getnum() const
int idx=0; int idx=0;
while (offs < ml) while (offs < ml)
{ {
offs+=strlen(s+offs)+1; offs+=_tcslen(s+offs)+1;
idx++; idx++;
} }
return idx; return idx;
@ -117,7 +117,8 @@ int DefineList::add(const TCHAR *name, const TCHAR *value/*=_T("")*/)
} }
TCHAR **newvalue=&(((struct define*)gr.get())[pos].value); TCHAR **newvalue=&(((struct define*)gr.get())[pos].value);
*newvalue=(TCHAR*)malloc(strlen(value)+1); size_t size_in_bytes = (_tcslen(value) + 1) * sizeof(TCHAR);
*newvalue=(TCHAR*)malloc(size_in_bytes);
if (!(*newvalue)) if (!(*newvalue))
{ {
extern FILE *g_output; extern FILE *g_output;
@ -125,12 +126,12 @@ int DefineList::add(const TCHAR *name, const TCHAR *value/*=_T("")*/)
extern void quit(); extern void quit();
if (g_display_errors) if (g_display_errors)
{ {
fprintf(g_output,_T("\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n"),(unsigned long)strlen(value)+1); _ftprintf(g_output,_T("\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n"), (unsigned long) size_in_bytes);
fflush(g_output); fflush(g_output);
} }
quit(); quit();
} }
strcpy(*newvalue,value); _tcscpy(*newvalue,value);
return 0; return 0;
} }

View file

@ -210,7 +210,7 @@ class SortedStringList
if (case_sensitive) if (case_sensitive)
res=_tcscmp(str, data[nextpos].name); res=_tcscmp(str, data[nextpos].name);
else else
res=stricmp(str, data[nextpos].name); res=_tcsicmp(str, data[nextpos].name);
if (res==0) return returnbestpos ? -1 : nextpos; if (res==0) return returnbestpos ? -1 : nextpos;
if (res<0) ul=nextpos; if (res<0) ul=nextpos;
else ll=nextpos+1; else ll=nextpos+1;
@ -302,7 +302,7 @@ class SortedStringListND // no delete - can be placed in GrowBuf
if (pos==-1) return alwaysreturnpos ? where : -1; if (pos==-1) return alwaysreturnpos ? where : -1;
// Note that .name is set with the TCHAR* offset into m_strings. // Note that .name is set with the TCHAR* offset into m_strings.
newstruct.name=strings.add(name,strlen(name)+1); newstruct.name=strings.add(name,(_tcsclen(name)+1)*sizeof(TCHAR))/sizeof(TCHAR);
gr.add(&newstruct,sizeof(T)); gr.add(&newstruct,sizeof(T));
T *s=(T*)gr.get(); T *s=(T*)gr.get();

View file

@ -19,6 +19,7 @@
#ifndef _TSTRING_ #ifndef _TSTRING_
#define _TSTRING_ #define _TSTRING_
#include "Platform.h"
#include "tchar.h" #include "tchar.h"
#include <string> #include <string>
@ -28,9 +29,7 @@ typedef std::wstring tstring;
typedef std::wofstream tofstream; typedef std::wofstream tofstream;
typedef std::wifstream tifstream; typedef std::wifstream tifstream;
// Use the following macros to open text files. // Use the following macros to open text files.
// #define FOPENTEXT(file, mode) _wfopen(file, mode ## L", ccs=Unicode") #define FOPENTEXT(file, mode) _wfopen(file, mode)
FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode);
#define FOPENTEXT(file, mode) FileOpenUnicodeText(file, mode)
#else #else
typedef std::string tstring; typedef std::string tstring;
typedef std::ofstream tofstream; typedef std::ofstream tofstream;
@ -56,10 +55,16 @@ public:
m_wStr = (wchar_t*) GlobalAlloc(GPTR, len*sizeof(wchar_t)); m_wStr = (wchar_t*) GlobalAlloc(GPTR, len*sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, str, -1, m_wStr, len); MultiByteToWideChar(CP_ACP, 0, str, -1, m_wStr, len);
} }
CtoTString(const std::string& str)
{
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, NULL, 0);
m_wStr = (wchar_t*) GlobalAlloc(GPTR, len*sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, m_wStr, len);
}
~CtoTString() { GlobalFree(m_wStr); m_wStr = 0; } ~CtoTString() { GlobalFree(m_wStr); m_wStr = 0; }
operator const wchar_t* tstr() { return m_wStr; } operator const wchar_t*() { return m_wStr; }
private: private:
wchar_t* m_wStr; wchar_t* m_wStr;
@ -76,6 +81,12 @@ public:
m_cStr = (char*) GlobalAlloc(GPTR, len); m_cStr = (char*) GlobalAlloc(GPTR, len);
WideCharToMultiByte(CP_ACP, 0, wStr, -1, m_cStr, len, 0, 0); WideCharToMultiByte(CP_ACP, 0, wStr, -1, m_cStr, len, 0, 0);
} }
TtoCString(const tstring& wStr)
{
int len = WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, NULL, 0, 0, 0);
m_cStr = (char*) GlobalAlloc(GPTR, len);
WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, m_cStr, len, 0, 0);
}
~TtoCString() { GlobalFree(m_cStr); m_cStr = 0; } ~TtoCString() { GlobalFree(m_cStr); m_cStr = 0; }

View file

@ -129,7 +129,7 @@ int update_bitmap(CResourceEditor* re, WORD id, const TCHAR* filename, int width
} }
fclose(f); fclose(f);
re->UpdateResourceA(RT_BITMAP, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, bitmap, dwSize); re->UpdateResource(RT_BITMAP, id, NSIS_DEFAULT_LANG, bitmap, dwSize);
free(bitmap); free(bitmap);
@ -537,8 +537,8 @@ static bool GetDLLVersionUsingRE(const tstring& filepath, DWORD& high, DWORD & l
try try
{ {
CResourceEditor *dllre = new CResourceEditor(dll, len); CResourceEditor *dllre = new CResourceEditor(dll, len);
LPBYTE ver = dllre->GetResourceA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0); LPBYTE ver = dllre->GetResource(VS_FILE_INFO, VS_VERSION_INFO, 0);
int versize = dllre->GetResourceSizeA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0); int versize = dllre->GetResourceSize(VS_FILE_INFO, VS_VERSION_INFO, 0);
if (ver) if (ver)
{ {

View file

@ -24,8 +24,11 @@
using std::runtime_error; using std::runtime_error;
WCHAR *winchar_fromansi(const char* s, unsigned int codepage/*=CP_ACP*/) WCHAR *winchar_fromTchar(const TCHAR* s, unsigned int codepage/*=CP_ACP*/)
{ {
#ifdef _UNICODE
return _wcsdup(s); // codepage is not used in this mode
#else
int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0); int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0);
if (l == 0) if (l == 0)
throw runtime_error("Unicode conversion failed"); throw runtime_error("Unicode conversion failed");
@ -36,20 +39,7 @@ WCHAR *winchar_fromansi(const char* s, unsigned int codepage/*=CP_ACP*/)
throw runtime_error("Unicode conversion failed"); throw runtime_error("Unicode conversion failed");
return ws; return ws;
} #endif
char *winchar_toansi(const WCHAR* ws, unsigned int codepage/*=CP_ACP*/)
{
int l = WideCharToMultiByte(codepage, 0, ws, -1, 0, 0, 0, 0);
if (l == 0)
throw runtime_error("Unicode conversion failed");
char *s = new char[l + 1];
if (WideCharToMultiByte(codepage, 0, ws, -1, s, l + 1, 0, 0) == 0)
throw runtime_error("Unicode conversion failed");
return s;
} }
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2) WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2)
@ -115,14 +105,3 @@ int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2)
return diff; return diff;
} }
int winchar_stoi(const WCHAR *ws)
{
char *s = winchar_toansi(ws);
int ret = atoi(s);
delete [] s;
return ret;
}

View file

@ -18,11 +18,9 @@
#include "Platform.h" #include "Platform.h"
WCHAR *winchar_fromansi(const char* s, unsigned int codepage = CP_ACP); WCHAR *winchar_fromTchar(const TCHAR* s, unsigned int codepage = CP_ACP);
char *winchar_toansi(const WCHAR* ws, unsigned int codepage = CP_ACP);
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2); WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2);
WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n); WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n);
size_t winchar_strlen(const WCHAR *ws); size_t winchar_strlen(const WCHAR *ws);
WCHAR *winchar_strdup(const WCHAR *ws); WCHAR *winchar_strdup(const WCHAR *ws);
int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2); int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2);
int winchar_stoi(const WCHAR *ws);

View file

@ -50,19 +50,29 @@ void writer_sink::write_int_array(const int i[], const size_t len)
} }
} }
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. // size in this case is the length of the string to write.
void writer_sink::write_string(const char *s, const size_t size) void writer_sink::write_string(const TCHAR *s, size_t size)
{ {
#ifdef _UNICODE
bool strEnd = false;
TCHAR ch;
for (; size ; size--)
{
if (!strEnd)
{
ch = *s++;
if (ch == _T('\0'))
strEnd = true;
}
write_short(ch);
}
#else
char *wb = new char[size]; char *wb = new char[size];
memset(wb, 0, size); memset(wb, 0, size);
strncpy(wb, s, size); strncpy(wb, s, size);
write_data(wb, size); write_data(wb, size);
delete [] wb; delete [] wb;
#endif
} }
void writer_sink::write_growbuf(const IGrowBuf *b) void writer_sink::write_growbuf(const IGrowBuf *b)

View file

@ -34,8 +34,7 @@ public:
virtual void write_short(const short s); virtual void write_short(const short s);
virtual void write_int(const int i); virtual void write_int(const int i);
virtual void write_int_array(const int i[], const size_t len); virtual void write_int_array(const int i[], const size_t len);
virtual void write_string(const TCHAR *s); virtual void write_string(const TCHAR *s, size_t size);
virtual void write_string(const TCHAR *s, const size_t size);
virtual void write_growbuf(const IGrowBuf *b); virtual void write_growbuf(const IGrowBuf *b);
virtual void write_data(const void *data, const size_t size) = 0; virtual void write_data(const void *data, const size_t size) = 0;