From acf9a8c21f41780e27816b2782343ee9fcedc194 Mon Sep 17 00:00:00 2001 From: wizou Date: Mon, 29 Mar 2010 14:24:47 +0000 Subject: [PATCH] Jim Park's Unicode NSIS merging - Step 4 : merging more TCHAR stuff that shouldn't have any impact git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6041 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Banner/Banner.c | 2 +- Contrib/BgImage/BgImage.cpp | 12 +- Contrib/ExDLL/pluginapi.c | 113 ++++++- Contrib/ExDLL/pluginapi.h | 20 ++ Contrib/InstallOptions/InstallerOptions.cpp | 73 ++--- Contrib/Library/RegTool/RegTool.c | 199 ++++++++----- Contrib/Library/TypeLib/TypeLib.cpp | 15 +- Contrib/MakeLangId/MakeLangId.cpp | 4 + Contrib/Makensisw/toolbar.cpp | 10 +- Contrib/Makensisw/utils.cpp | 37 ++- Contrib/Splash/splash.c | 2 +- Contrib/StartMenu/StartMenu.c | 16 +- Contrib/System/Source/Call.S | 161 +++++++--- Contrib/System/Source/Plugin.c | 17 +- Contrib/System/Source/Plugin.h | 2 +- Contrib/System/Source/System.c | 59 ++-- Contrib/System/Source/System.h | 5 +- Contrib/UserInfo/UserInfo.c | 16 +- Contrib/VPatch/Source/GenPat/main.cpp | 4 +- Contrib/nsExec/nsexec.c | 20 +- Contrib/zip2exe/main.cpp | 5 +- .../7zip/7zip/Compress/LZMA/LZMAEncoder.cpp | 2 +- Source/DialogTemplate.cpp | 15 +- Source/Plugins.cpp | 13 +- Source/ResourceVersionInfo.cpp | 24 +- Source/ShConstants.cpp | 2 + Source/build.cpp | 58 ++-- Source/clzma.cpp | 2 +- Source/dirreader.cpp | 2 +- Source/exehead/Main.c | 3 +- Source/exehead/Ui.c | 34 ++- Source/exehead/exec.c | 12 +- Source/exehead/fileform.h | 1 + Source/exehead/util.c | 224 ++++++++------ Source/icon.cpp | 2 +- Source/lineparse.cpp | 4 +- Source/makenssi.cpp | 42 +-- Source/manifest.cpp | 4 +- Source/script.cpp | 278 +++++++++--------- Source/tokens.cpp | 6 +- Source/util.cpp | 3 + 41 files changed, 937 insertions(+), 586 deletions(-) diff --git a/Contrib/Banner/Banner.c b/Contrib/Banner/Banner.c index f4b42cd3..3b704489 100644 --- a/Contrib/Banner/Banner.c +++ b/Contrib/Banner/Banner.c @@ -28,7 +28,7 @@ BOOL CALLBACK BannerProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) int iMainStringSet = 0; popstring(buf); - while (*(int*)buf == CHAR4_TO_DWORD('/','s','e','t') && !buf[4]) + while (lstrcmp(buf, _T("/set")) == 0) { unsigned int id; popstring(buf); diff --git a/Contrib/BgImage/BgImage.cpp b/Contrib/BgImage/BgImage.cpp index 6a6a9763..bcc784a5 100644 --- a/Contrib/BgImage/BgImage.cpp +++ b/Contrib/BgImage/BgImage.cpp @@ -168,9 +168,9 @@ NSISFunc(SetBg) { uWndWidth = uScrWidth; uWndHeight = uScrHeight; - char szGradient[] = {'/', 'G', 'R', 'A', 'D', 'I', 'E', 'N', 'T', 0}; - char szFillScreen[] = {'/', 'F', 'I' ,'L', 'L', 'S', 'C', 'R', 'E', 'E', 'N', 0}; - char szTiled[] = {'/', 'T', 'I', 'L', 'E', 'D', 0}; + LPCTSTR szGradient = _T("/GRADIENT"); + LPCTSTR szFillScreen = _T("/FILLSCREEN"); + LPCTSTR szTiled = _T("/TILED"); popstring(szTemp); if (!lstrcmpi(szTemp, szGradient)) { @@ -357,9 +357,9 @@ NSISFunc(Destroy) { } NSISFunc(Sound) { - char szLoop[] = {'/', 'L', 'O', 'O', 'P', 0}; - char szWait[] = {'/', 'W', 'A', 'I', 'T', 0}; - char szStop[] = {'/', 'S', 'T', 'O', 'P', 0}; + LPCTSTR szLoop = _T("/LOOP"); + LPCTSTR szWait = _T("/WAIT"); + LPCTSTR szStop = _T("/STOP"); DWORD flags = SND_FILENAME | SND_NODEFAULT; diff --git a/Contrib/ExDLL/pluginapi.c b/Contrib/ExDLL/pluginapi.c index 5aeba504..f5a440d3 100644 --- a/Contrib/ExDLL/pluginapi.c +++ b/Contrib/ExDLL/pluginapi.c @@ -13,7 +13,7 @@ int NSISCALL popstring(TCHAR *str) stack_t *th; if (!g_stacktop || !*g_stacktop) return 1; th=(*g_stacktop); - if (str) lstrcpyA(str,th->text); + if (str) lstrcpy(str,th->text); *g_stacktop = th->next; GlobalFree((HGLOBAL)th); return 0; @@ -24,7 +24,7 @@ int NSISCALL popstringn(TCHAR *str, int maxlen) stack_t *th; if (!g_stacktop || !*g_stacktop) return 1; th=(*g_stacktop); - if (str) lstrcpynA(str,th->text,maxlen?maxlen:g_stringsize); + if (str) lstrcpyn(str,th->text,maxlen?maxlen:g_stringsize); *g_stacktop = th->next; GlobalFree((HGLOBAL)th); return 0; @@ -34,8 +34,8 @@ void NSISCALL pushstring(const TCHAR *str) { stack_t *th; if (!g_stacktop) return; - th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize); - lstrcpynA(th->text,str,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; } @@ -49,9 +49,108 @@ TCHAR * NSISCALL getuservariable(const int varnum) void NSISCALL setuservariable(const int varnum, const TCHAR *var) { if (var != NULL && varnum >= 0 && varnum < __INST_LAST) - lstrcpyA(g_variables + varnum*g_stringsize, var); + lstrcpy(g_variables + varnum*g_stringsize, var); } +#ifdef _UNICODE +int NSISCALL PopStringA(char* ansiStr) +{ + wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); + int rval = popstring(wideStr); + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); + GlobalFree((HGLOBAL)wideStr); + return rval; +} + +int NSISCALL PopStringNA(char* ansiStr, int maxlen) +{ + int realLen = maxlen ? maxlen : g_stringsize; + wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, realLen*sizeof(wchar_t)); + int rval = popstringn(wideStr, realLen); + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, realLen, NULL, NULL); + GlobalFree((HGLOBAL)wideStr); + return rval; +} + +void NSISCALL PushStringA(const char* ansiStr) +{ + wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); + pushstring(wideStr); + GlobalFree((HGLOBAL)wideStr); + return; +} + +void NSISCALL GetUserVariableW(const int varnum, wchar_t* wideStr) +{ + lstrcpyW(wideStr, getuservariable(varnum)); +} + +void NSISCALL GetUserVariableA(const int varnum, char* ansiStr) +{ + wchar_t* wideStr = getuservariable(varnum); + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); +} + +void NSISCALL SetUserVariableA(const int varnum, const char* ansiStr) +{ + if (ansiStr != NULL && varnum >= 0 && varnum < __INST_LAST) + { + wchar_t* wideStr = g_variables + varnum * g_stringsize; + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); + } +} + +#else +// ANSI defs +int NSISCALL PopStringW(wchar_t* wideStr) +{ + char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); + int rval = popstring(ansiStr); + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); + GlobalFree((HGLOBAL)ansiStr); + return rval; +} + +int NSISCALL PopStringNW(wchar_t* wideStr, int maxlen) +{ + int realLen = maxlen ? maxlen : g_stringsize; + char* ansiStr = (char*) GlobalAlloc(GPTR, realLen); + int rval = popstringn(ansiStr, realLen); + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, realLen); + GlobalFree((HGLOBAL)ansiStr); + return rval; +} + +void NSISCALL PushStringW(wchar_t* wideStr) +{ + char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); + pushstring(ansiStr); + GlobalFree((HGLOBAL)ansiStr); +} + +void NSISCALL GetUserVariableW(const int varnum, wchar_t* wideStr) +{ + char* ansiStr = getuservariable(varnum); + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); +} + +void NSISCALL GetUserVariableA(const int varnum, char* ansiStr) +{ + lstrcpyA(ansiStr, getuservariable(varnum)); +} + +void NSISCALL SetUserVariableW(const int varnum, const wchar_t* wideStr) +{ + if (wideStr != NULL && varnum >= 0 && varnum < __INST_LAST) + { + char* ansiStr = g_variables + varnum * g_stringsize; + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); + } +} +#endif + // playing with integers int NSISCALL myatoi(const TCHAR *s) @@ -168,7 +267,7 @@ int NSISCALL myatoi_or(const TCHAR *s) int NSISCALL popint() { TCHAR buf[128]; - if (popstringn(buf,sizeof(buf))) + if (popstringn(buf,_countof(buf))) return 0; return myatoi(buf); @@ -177,7 +276,7 @@ int NSISCALL popint() int NSISCALL popint_or() { TCHAR buf[128]; - if (popstringn(buf,sizeof(buf))) + if (popstringn(buf,_countof(buf))) return 0; return myatoi_or(buf); diff --git a/Contrib/ExDLL/pluginapi.h b/Contrib/ExDLL/pluginapi.h index 522bcab0..e762bbfc 100644 --- a/Contrib/ExDLL/pluginapi.h +++ b/Contrib/ExDLL/pluginapi.h @@ -68,12 +68,32 @@ void NSISCALL pushint(int value); TCHAR * NSISCALL getuservariable(const int varnum); void NSISCALL setuservariable(const int varnum, const TCHAR *var); +#ifdef _UNICODE +#define PopStringW(x) popstring(x) +#define PushStringW(x) pushstring(x) +#define SetUserVariableW(x,y) setuservariable(x,y) + +int NSISCALL PopStringA(char* ansiStr); +void NSISCALL PushStringA(const char* ansiStr); +void NSISCALL GetUserVariableW(const int varnum, wchar_t* wideStr); +void NSISCALL GetUserVariableA(const int varnum, char* ansiStr); +void NSISCALL SetUserVariableA(const int varnum, const char* ansiStr); + +#else // ANSI defs #define PopStringA(x) popstring(x) #define PushStringA(x) pushstring(x) #define SetUserVariableA(x,y) setuservariable(x,y) +int NSISCALL PopStringW(wchar_t* wideStr); +void NSISCALL PushStringW(wchar_t* wideStr); +void NSISCALL GetUserVariableW(const int varnum, wchar_t* wideStr); +void NSISCALL GetUserVariableA(const int varnum, char* ansiStr); +void NSISCALL SetUserVariableW(const int varnum, const wchar_t* wideStr); + +#endif + #ifdef __cplusplus } #endif diff --git a/Contrib/InstallOptions/InstallerOptions.cpp b/Contrib/InstallOptions/InstallerOptions.cpp index 200e9c09..4828344d 100644 --- a/Contrib/InstallOptions/InstallerOptions.cpp +++ b/Contrib/InstallOptions/InstallerOptions.cpp @@ -344,19 +344,19 @@ bool WINAPI SaveSettings(void) { { switch (*p1) { case _T('\t'): - *(LPWORD)p2 = CHAR2_TO_WORD('\\', 't'); - p2++; + *p2++ = _T('\\'); + *p2 = _T('t'); break; case _T('\n'): - *(LPWORD)p2 = CHAR2_TO_WORD('\\', 'n'); - p2++; + *p2++ = _T('\\'); + *p2 = _T('n'); break; case _T('\r'): - *(LPWORD)p2 = CHAR2_TO_WORD('\\', 'r'); - p2++; + *p2++ = _T('\\'); + *p2 = _T('n'); break; case _T('\\'): - *p2++ = '\\'; + *p2 = _T('\\'); // 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. @@ -672,13 +672,17 @@ LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify) ULONG eaten; LPITEMIDLIST root; int ccRoot = (lstrlen(pField->pszRoot) * 2) + 2; + SHGetDesktopFolder(&sf); +#ifdef _UNICODE + sf->ParseDisplayName(hConfigWindow, NULL, pField->pszRoot, &eaten, &root, NULL); +#else LPWSTR pwszRoot = (LPWSTR) MALLOC(ccRoot); MultiByteToWideChar(CP_ACP, 0, pField->pszRoot, -1, pwszRoot, ccRoot); - SHGetDesktopFolder(&sf); sf->ParseDisplayName(hConfigWindow, NULL, pwszRoot, &eaten, &root, NULL); + FREE(pwszRoot); +#endif bi.pidlRoot = root; sf->Release(); - FREE(pwszRoot); } //CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); LPITEMIDLIST pResult = SHBrowseForFolder(&bi); @@ -892,7 +896,11 @@ int WINAPI NumbersOnlyPasteWndProc(HWND hWin, UINT uMsg, WPARAM wParam, LPARAM l { if (OpenClipboard(hWin)) { +#ifdef _UNICODE + HGLOBAL hData = GetClipboardData(CF_UNICODETEXT); +#else HGLOBAL hData = GetClipboardData(CF_TEXT); +#endif if (hData) { @@ -1113,7 +1121,7 @@ int WINAPI createCfgDlg() #undef DEFAULT_STYLES - if (pField->nType < 1 || pField->nType > (int)(sizeof(ClassTable) / sizeof(ClassTable[0]))) + if (pField->nType < 1 || pField->nType > (int)(_countof(ClassTable))) continue; DWORD dwStyle, dwExStyle; @@ -1622,41 +1630,38 @@ int WINAPI LookupTokens(TableEntry* psTable_, TCHAR* pszTokens_) */ void WINAPI ConvertNewLines(TCHAR *str) { TCHAR *p1, *p2, *p3; + TCHAR tch0, tch1, nch; if (!str) return; p1 = p2 = str; - while (*p1) + while ((tch0 = *p1) != 0) { - switch (*(LPWORD)p1) + nch = 0; // new translated char + if (tch0 == _T('\\')) { - case CHAR2_TO_WORD(_T('\\'), _T('t')): - *p2 = _T('\t'); - p1 += 2; - p2++; - break; - case CHAR2_TO_WORD(_T('\\'), _T('n')): - *p2 = _T('\n'); - p1 += 2; - p2++; - break; - case CHAR2_TO_WORD(_T('\\'), _T('r')): - *p2 = _T('\r'); - p1 += 2; - p2++; - break; - case CHAR2_TO_WORD(_T('\\'), _T('\\')): - *p2 = _T('\\'); - p1 += 2; - p2++; - break; - default: + tch1 = *(p1+1); + + if (tch1 == _T('t')) nch = _T('\t'); + else if (tch1 == _T('n')) nch = _T('\n'); + else if (tch1 == _T('r')) nch = _T('\r'); + else if (tch1 == _T('\\')) nch = _T('\\'); + } + + // Was it a special char? + if (nch) + { + *p2++ = nch; + p1 += 2; + } + else + { + // For MBCS p3 = CharNext(p1); while (p1 < p3) *p2++ = *p1++; - break; } } diff --git a/Contrib/Library/RegTool/RegTool.c b/Contrib/Library/RegTool/RegTool.c index f8760489..70178120 100644 --- a/Contrib/Library/RegTool/RegTool.c +++ b/Contrib/Library/RegTool/RegTool.c @@ -63,11 +63,13 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL continue; wsprintf(valname, _T("%u.file"), j); - l = STR_SIZE; + l = (lstrlen(file)+1)*sizeof(TCHAR); if (FAILED(RegQueryValueEx(key, valname, NULL, &t, (LPBYTE) file, &l)) || t != REG_SZ) continue; - RegFile(mode[0], file, mode[1] == _T('X')); + // JP: Note, if this mode[1] is used as anything but a boolean later on, + // we'll need to consider the next line carefully. + RegFile(mode[0], file, mode[1] == 'X'); } } @@ -208,34 +210,142 @@ void RegTypeLib(TCHAR *file) } } -TCHAR *mystrstri(TCHAR *a, TCHAR *b) +char *mystrstriA(char *a, const char *b) { - int l = lstrlen(b); - while (lstrlen(a) >= l) + int l = lstrlenA(b); + while (lstrlenA(a) >= l) { - TCHAR c = a[l]; + char c = a[l]; a[l] = 0; - if (!lstrcmpi(a, b)) + if (!lstrcmpiA(a, b)) { a[l] = c; return a; } a[l] = c; - a = CharNext(a); + a = CharNextA(a); } return NULL; } void mini_memcpy(void *out, const void *in, int len) { - TCHAR *c_out=(TCHAR*)out; - TCHAR *c_in=(TCHAR *)in; + char *c_out=(char*)out; + char *c_in=(char *)in; while (len-- > 0) { *c_out++=*c_in++; } } +HANDLE myOpenFile(const TCHAR *fn, DWORD da, DWORD cd) +{ + int attr = GetFileAttributes(fn); + return CreateFile( + fn, + da, + FILE_SHARE_READ, + NULL, + cd, + attr == INVALID_FILE_ATTRIBUTES ? 0 : attr, + NULL + ); +} + +/** Modifies the wininit.ini file to rename / delete a file. + * + * @param prevName The previous / current name of the file. + * @param newName The new name to move the file to. If NULL, the current file + * will be deleted. + */ +void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName) +{ + static char szRenameLine[1024]; + static TCHAR wininit[1024]; + static TCHAR tmpbuf[1024]; + + int cchRenameLine; + LPCSTR szRenameSec = "[Rename]\r\n"; // rename section marker + HANDLE hfile; + DWORD dwFileSize; + DWORD dwBytes; + DWORD dwRenameLinePos; + char *pszWinInit; // Contains the file contents of wininit.ini + + int spn; // length of the short path name in TCHARs. + + lstrcpy(tmpbuf, _T("NUL")); + + if (newName) { + // create the file if it's not already there to prevent GetShortPathName from failing + CloseHandle(myOpenFile(newName,0,CREATE_NEW)); + spn = GetShortPathName(newName,tmpbuf,1024); + if (!spn || spn > 1024) + return; + } + // wininit is used as a temporary here + spn = GetShortPathName(prevName,wininit,1024); + if (!spn || spn > 1024) + return; + cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit); + // Get the path to the wininit.ini file. + GetWindowsDirectory(wininit, 1024-16); + lstrcat(wininit, _T("\\wininit.ini")); + + hfile = myOpenFile(wininit, GENERIC_READ | GENERIC_WRITE, OPEN_ALWAYS); + + if (hfile != INVALID_HANDLE_VALUE) + { + // We are now working on the Windows wininit file + dwFileSize = GetFileSize(hfile, NULL); + pszWinInit = (char*) GlobalAlloc(GPTR, dwFileSize + cchRenameLine + 10); + + if (pszWinInit != NULL) + { + if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes) + { + // Look for the rename section in the current file. + LPSTR pszRenameSecInFile = mystrstriA(pszWinInit, szRenameSec); + if (pszRenameSecInFile == NULL) + { + // No rename section. So we add it to the end of file. + lstrcpyA(pszWinInit+dwFileSize, szRenameSec); + dwFileSize += 10; + dwRenameLinePos = dwFileSize; + } + else + { + // There is a rename section, but is there another section after it? + char *pszFirstRenameLine = pszRenameSecInFile+10; + char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n["); + if (pszNextSec) + { + TCHAR *p = ++pszNextSec; + while (p < pszWinInit + dwFileSize) { + p[cchRenameLine] = *p; + p++; + } + + dwRenameLinePos = pszNextSec - pszWinInit; + } + // rename section is last, stick item at end of file + else dwRenameLinePos = dwFileSize; + } + + mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, cchRenameLine); + dwFileSize += cchRenameLine; + + SetFilePointer(hfile, 0, NULL, FILE_BEGIN); + WriteFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL); + + GlobalFree(pszWinInit); + } + } + + CloseHandle(hfile); + } +} + void DeleteFileOnReboot(TCHAR *pszFile) { BOOL fOk = 0; @@ -253,73 +363,6 @@ void DeleteFileOnReboot(TCHAR *pszFile) if (!fOk) { - static TCHAR szRenameLine[1024]; - static TCHAR wininit[1024]; - int cchRenameLine; - TCHAR *szRenameSec = _T("[Rename]\r\n"); - HANDLE hfile, hfilemap; - DWORD dwFileSize, dwRenameLinePos; - - int spn; - - // wininit is used as a temporary here - spn = GetShortPathName(pszFile,wininit,1024); - if (!spn || spn > 1024) - return; - cchRenameLine = wsprintf(szRenameLine,_T("NUL=%s\r\n"),wininit); - - GetWindowsDirectory(wininit, 1024-16); - lstrcat(wininit, _T("\\wininit.ini")); - hfile = CreateFile(wininit, - GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); - - if (hfile != INVALID_HANDLE_VALUE) - { - dwFileSize = GetFileSize(hfile, NULL); - hfilemap = CreateFileMapping(hfile, NULL, PAGE_READWRITE, 0, dwFileSize + cchRenameLine + 10, NULL); - - if (hfilemap != NULL) - { - LPTSTR pszWinInit = (LPTSTR) MapViewOfFile(hfilemap, FILE_MAP_WRITE, 0, 0, 0); - - if (pszWinInit != NULL) - { - LPTSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec); - if (pszRenameSecInFile == NULL) - { - lstrcpy(pszWinInit+dwFileSize, szRenameSec); - dwFileSize += 10; - dwRenameLinePos = dwFileSize; - } - else - { - TCHAR *pszFirstRenameLine = pszRenameSecInFile+10; - TCHAR *pszNextSec = mystrstri(pszFirstRenameLine,_T("\n[")); - if (pszNextSec) - { - TCHAR *p = ++pszNextSec; - while (p < pszWinInit + dwFileSize) { - p[cchRenameLine] = *p; - p++; - } - - dwRenameLinePos = pszNextSec - pszWinInit; - } - // rename section is last, stick item at end of file - else dwRenameLinePos = dwFileSize; - } - - mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, cchRenameLine); - dwFileSize += cchRenameLine; - - UnmapViewOfFile(pszWinInit); - } - CloseHandle(hfilemap); - } - SetFilePointer(hfile, dwFileSize, NULL, FILE_BEGIN); - SetEndOfFile(hfile); - CloseHandle(hfile); - } + RenameViaWininit(pszFile, NULL); } } diff --git a/Contrib/Library/TypeLib/TypeLib.cpp b/Contrib/Library/TypeLib/TypeLib.cpp index 24de9592..2340bd07 100644 --- a/Contrib/Library/TypeLib/TypeLib.cpp +++ b/Contrib/Library/TypeLib/TypeLib.cpp @@ -21,11 +21,8 @@ NSISFunction(Register) { EXDLL_INIT(); - char filename[1024]; - popstring(filename); - wchar_t ole_filename[1024]; - MultiByteToWideChar(CP_ACP, 0, filename, 1024, ole_filename, 1024); + PopStringW(ole_filename); ITypeLib* typeLib; HRESULT hr; @@ -46,11 +43,8 @@ NSISFunction(UnRegister) { EXDLL_INIT(); - char filename[1024]; - popstring(filename); - wchar_t ole_filename[1024]; - MultiByteToWideChar(CP_ACP, 0, filename, 1024, ole_filename, 1024); + PopStringW(ole_filename); ITypeLib* typeLib; HRESULT hr; @@ -87,11 +81,8 @@ NSISFunction(GetLibVersion) { EXDLL_INIT(); - char filename[1024]; - popstring(filename); - wchar_t ole_filename[1024]; - MultiByteToWideChar(CP_ACP, 0, filename, 1024, ole_filename, 1024); + PopStringW(ole_filename); ITypeLib* typeLib; HRESULT hr; diff --git a/Contrib/MakeLangId/MakeLangId.cpp b/Contrib/MakeLangId/MakeLangId.cpp index 4c9a1a97..76f15098 100644 --- a/Contrib/MakeLangId/MakeLangId.cpp +++ b/Contrib/MakeLangId/MakeLangId.cpp @@ -218,7 +218,11 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) { GlobalUnlock(hMem); if (!OpenClipboard(hwndDlg)) return 0; EmptyClipboard(); +#ifdef _UNICODE + SetClipboardData(CF_UNICODETEXT,hMem); +#else SetClipboardData(CF_TEXT,hMem); +#endif CloseClipboard(); } } diff --git a/Contrib/Makensisw/toolbar.cpp b/Contrib/Makensisw/toolbar.cpp index 850330fc..419581f8 100644 --- a/Contrib/Makensisw/toolbar.cpp +++ b/Contrib/Makensisw/toolbar.cpp @@ -123,8 +123,8 @@ void UpdateToolBarCompressorButton() { int iBitmap; int iString; - TCHAR szBuffer[64]; - TCHAR temp[32]; + TCHAR szBuffer[124]; // increased to 124 for good measure, also. + TCHAR temp[64]; // increased to 64. Hit limit 08/20/2007 -- Jim Park. TOOLINFO ti; my_memset(&ti, 0, sizeof(TOOLINFO)); @@ -139,14 +139,14 @@ void UpdateToolBarCompressorButton() LoadString(g_sdata.hInstance, IDS_COMPRESSOR, temp, - sizeof(temp)); + _countof(temp)); my_memset(szBuffer, 0, sizeof(szBuffer)); lstrcat(szBuffer,temp); lstrcat(szBuffer,_T(" [")); LoadString(g_sdata.hInstance, iString, temp, - sizeof(temp)); + _countof(temp)); lstrcat(szBuffer,temp); lstrcat(szBuffer,_T("]")); @@ -181,7 +181,7 @@ void AddToolBarButtonTooltip(int id, int iString) LoadString(g_sdata.hInstance, iString, szBuffer, - sizeof(szBuffer)); + _countof(szBuffer)); ti.lpszText = (LPTSTR) szBuffer; ti.rect.left =rect.left; ti.rect.top = rect.top; diff --git a/Contrib/Makensisw/utils.cpp b/Contrib/Makensisw/utils.cpp index 2aef1153..f0ad42b9 100644 --- a/Contrib/Makensisw/utils.cpp +++ b/Contrib/Makensisw/utils.cpp @@ -151,7 +151,11 @@ void CopyToClipboard(HWND hwnd) { existing_text[0]=0; GetDlgItemText(hwnd, IDC_LOGWIN, existing_text, len+1); GlobalUnlock(mem); +#ifdef _UNICODE + SetClipboardData(CF_UNICODETEXT,mem); +#else SetClipboardData(CF_TEXT,mem); +#endif CloseClipboard(); } @@ -295,15 +299,16 @@ void CompileNSISScript() { TCHAR *args = (TCHAR *) GlobalLock(g_sdata.script_cmd_args); - g_sdata.compile_command = (char *) GlobalAlloc( - GPTR, - /* makensis.exe */ _countof(EXENAME) + /* space */ 1 + + size_t byteSize = sizeof(TCHAR)*( + /* makensis.exe */ lstrlen(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 */ _countof(_T("/NOTIFYHWND -4294967295")) + /* space */ 1 - ); + +6); /* for -- \"\" and NULL */ + + g_sdata.compile_command = (TCHAR *) GlobalAlloc(GPTR, byteSize); wsprintf( g_sdata.compile_command, @@ -468,9 +473,10 @@ TCHAR** LoadSymbolSet(TCHAR *name) } if(symbols) { l++; - symbols[i] = (TCHAR *)GlobalAlloc(GPTR, l*sizeof(TCHAR)); + DWORD bytes = sizeof(TCHAR) * l; + symbols[i] = (TCHAR *)GlobalAlloc(GPTR, bytes); if (symbols[i]) { - RegQueryValueEx(hSubKey,buf,NULL,&t,(unsigned char*)symbols[i],&l); + RegQueryValueEx(hSubKey,buf,NULL,&t,(unsigned char*)symbols[i],&bytes); } else { break; @@ -540,7 +546,10 @@ void SaveSymbolSet(TCHAR *name, TCHAR **symbols) void ResetObjects() { if (g_sdata.compile_command) + { GlobalFree(g_sdata.compile_command); + g_sdata.compile_command = 0; + } g_sdata.warnings = FALSE; g_sdata.retcode = -1; @@ -565,8 +574,10 @@ void ResetSymbols() { int InitBranding() { TCHAR *s; - s = (TCHAR *)GlobalAlloc(GPTR,lstrlen(EXENAME)+10); - wsprintf(s,_T("%s /version"),EXENAME); + TCHAR opt[] = _T(" /version"); + s = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(EXENAME)+lstrlen(opt)+1)*sizeof(TCHAR)); + lstrcpy(s, EXENAME); + lstrcat(s, opt); { STARTUPINFO si={sizeof(si),}; SECURITY_ATTRIBUTES sa={sizeof(sa),}; @@ -601,8 +612,8 @@ int InitBranding() { if (WaitForSingleObject(pi.hProcess,10000)!=WAIT_OBJECT_0) { return 0; } - ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL); - szBuf[dwRead] = 0; + ReadFile(read_stdout, szBuf, sizeof(szBuf)-sizeof(TCHAR), &dwRead, NULL); + szBuf[dwRead/sizeof(TCHAR)] = 0; if (lstrlen(szBuf)==0) return 0; g_sdata.branding = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(szBuf)+6)*sizeof(TCHAR)); wsprintf(g_sdata.branding,_T("NSIS %s"),szBuf); @@ -613,6 +624,7 @@ int InitBranding() { return 1; } + void InitTooltips(HWND h) { if (h == NULL) return; my_memset(&g_tip,0,sizeof(NTOOLTIP)); @@ -736,7 +748,6 @@ void PushMRUFile(TCHAR* fname) { int i; DWORD rv; - TCHAR* file_part; TCHAR full_file_name[MAX_PATH+1]; if(!fname || fname[0] == _T('\0') || fname[0] == _T('/') || fname[0] == _T('-')) { @@ -744,7 +755,7 @@ void PushMRUFile(TCHAR* fname) } my_memset(full_file_name,0,sizeof(full_file_name)); - rv = GetFullPathName(fname,_countof(full_file_name),full_file_name,&file_part); + rv = GetFullPathName(fname,_countof(full_file_name),full_file_name,NULL); if (rv == 0) { return; } @@ -897,7 +908,7 @@ void SaveMRUList() for(i = 0; i < MRU_LIST_SIZE; i++) { wsprintf(buf,_T("%d"),i); // cbData must include the size of the terminating null character. - RegSetValueEx(hSubKey,buf,0,REG_SZ,(const BYTE*)g_mru_list[i],(lstrlen(g_mru_list[i]))*sizeof(TCHAR)); + RegSetValueEx(hSubKey,buf,0,REG_SZ,(const BYTE*)g_mru_list[i],(lstrlen(g_mru_list[i])+1)*sizeof(TCHAR)); } RegCloseKey(hSubKey); } diff --git a/Contrib/Splash/splash.c b/Contrib/Splash/splash.c index 8c175e71..38e23693 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), (LPTSTR)&bm); + GetObject(g_hbm, sizeof(bm), &bm); SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0); SetWindowLong(hwnd,GWL_STYLE,0); SetWindowPos(hwnd,NULL, diff --git a/Contrib/StartMenu/StartMenu.c b/Contrib/StartMenu/StartMenu.c index 6dc11f78..b72a9e7b 100644 --- a/Contrib/StartMenu/StartMenu.c +++ b/Contrib/StartMenu/StartMenu.c @@ -368,14 +368,10 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_COMMAND: if (LOWORD(wParam) == IDC_DIRLIST && HIWORD(wParam) == LBN_SELCHANGE) { - LRESULT selection = SendMessage(hwDirList, LB_GETCURSEL, 0, 0); - if (selection != LB_ERR) - { - SendMessage(hwDirList, LB_GETTEXT, selection, (WPARAM)buf); - if (autoadd) - lstrcat(lstrcat(buf, _T("\\")), progname); - SetWindowText(hwLocation, buf); - } + SendMessage(hwDirList, LB_GETTEXT, SendMessage(hwDirList, LB_GETCURSEL, 0, 0), (WPARAM)buf); + if (autoadd) + lstrcat(lstrcat(buf, _T("\\")), progname); + SetWindowText(hwLocation, buf); } else if (LOWORD(wParam) == IDC_CHECK && HIWORD(wParam) == BN_CLICKED) { @@ -458,9 +454,9 @@ void AddFolderFromReg(int nFolder) { if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - if (*(WORD*)FileData.cFileName != *(WORD*)_T(".")) + if (lstrcmp(FileData.cFileName, _T(".")) != 0) { - if (*(WORD*)FileData.cFileName != *(WORD*)_T("..") || FileData.cFileName[2]) + if (lstrcmp(FileData.cFileName, _T("..")) != 0) { 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/Call.S b/Contrib/System/Source/Call.S index 93c2e12e..61a8b90b 100644 --- a/Contrib/System/Source/Call.S +++ b/Contrib/System/Source/Call.S @@ -87,6 +87,11 @@ IF 0 .set SYSTEM_LOG_DEBUG,1 #endif +#ifdef _UNICODE +#undef _UNICODE +.set _UNICODE,1 +#endif + #define IFDEF .ifdef #define ELSE .else #define ENDIF .endif @@ -99,6 +104,7 @@ IF 0 #define DATA_SUFFIX : #define BYTE .byte #define DWORD .int +#define WORD .word #define ASCII .ascii #define MACRO_DECL .macro @@ -140,7 +146,12 @@ EXTERN __alloca_probe : PROC EXTERN __imp__GlobalFree@4 : PROC EXTERN __imp__GetLastError@0 : PROC + +IFDEF _UNICODE +EXTERN __imp__wsprintfW : PROC +ELSE EXTERN __imp__wsprintfA : PROC +ENDIF EXTERN _GlobalCopy : PROC @@ -181,54 +192,130 @@ SECTION_DATA IFDEF SYSTEM_LOG_DEBUG - LogStack DATA_SUFFIX ASCII "%s ESP = 0x%08X Stack = 0x%08X Real = 0x%08X" - BYTE 0 + IFDEF _UNICODE + LogStack DATA_SUFFIX + BYTE '%', 0, 's', 0, ' ', 0, ' ', 0, 'E', 0, 'S', 0, 'P', 0, ' ', 0 + BYTE ' ', 0, '0', 0, 'x', 0, '%', 0, '0', 0, '8', 0, 'X', 0, ' ', 0 + BYTE 'S', 0, 't', 0, 'a', 0, 'c', 0, 'k', 0, ' ', 0, '=', 0, ' ', 0 + BYTE 'x', 0, '%', 0, '0', 0, '8', 0, 'X', 0, ' ', 0, ' ', 0, 'R', 0 + BYTE 'a', 0, 'l', 0, ' ', 0, '=', 0, ' ', 0, '0', 0, 'x', 0, '%', 0 + BYTE '8', 0, 'X', 0 + WORD 0 - LogCall DATA_SUFFIX BYTE 9,9 - ASCII "Call:" - BYTE 10,0 + LogCall DATA_SUFFIX WORD 9,9 + BYTE 'C', 0, 'a', 0, 'l', 0, 'l', 0, ':', 0 + WORD 10,0 - LogBeforeCall DATA_SUFFIX BYTE 9,9,9 - ASCII "Before call " - BYTE 0 + LogBeforeCall DATA_SUFFIX WORD 9,9,9 + BYTE 'B', 0, 'e', 0, 'f', 0, 'o', 0, 'r', 0, 'e', 0, ' ', 0, 'c', 0 + BYTE 'l', 0, 'l', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0 + BYTE ' ', 0 + WORD 0 - LogNearCall DATA_SUFFIX BYTE 10,9,9,9 - ASCII "Near call " - BYTE 0 + LogNearCall DATA_SUFFIX WORD 10,9,9,9 + BYTE 'N', 0, 'e', 0, 'a', 0, 'r', 0, ' ', 0, 'c', 0, 'a', 0, 'l', 0 + BYTE ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0 + BYTE ' ', 0 + WORD 0 - LogBackFrom DATA_SUFFIX BYTE 9 - ASCII "Back from " - BYTE 0 + LogBackFrom DATA_SUFFIX WORD 9 + BYTE 'B', 0, 'a', 0, 'c', 0, 'k', 0, ' ', 0, 'f', 0, 'r', 0, 'o', 0 + BYTE ' ', 0 + WORD 0 - LogAfterCall DATA_SUFFIX BYTE 10,9,9,9 - ASCII "After call " - BYTE 0 + LogAfterCall DATA_SUFFIX WORD 10,9,9,9 + BYTE 'A', 0, 'f', 0, 't', 0, 'e', 0, 'r', 0, ' ', 0, 'c', 0, 'a', 0 + BYTE 'l', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0 + BYTE ' ', 0 + WORD 0 - LogReturnAfter DATA_SUFFIX BYTE 10,9,9,9 - ASCII "Return 0x%08X 0x%08X" - BYTE 0 + LogReturnAfter DATA_SUFFIX WORD 10,9,9,9 + BYTE 'R', 0, 'e', 0, 't', 0, 'u', 0, 'r', 0, 'n', 0, ' ', 0, ' ', 0 + BYTE ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0 + BYTE ' ', 0, ' ', 0, ' ', 0, '0', 0, 'x', 0, '%', 0, '0', 0, '8', 0 + BYTE ' ', 0, ' ', 0, ' ', 0, ' ', 0, '0', 0, 'x', 0, '%', 0, '0', 0 + BYTE 'X', 0 + WORD 0 - LogCalled DATA_SUFFIX ASCII "Called callback from " - BYTE 0 + LogCalled DATA_SUFFIX + BYTE 'C', 0, 'a', 0, 'l', 0, 'l', 0, 'e', 0, 'd', 0, ' ', 0, 'c', 0 + BYTE 'l', 0, 'l', 0, 'b', 0, 'a', 0, 'c', 0, 'k', 0, ' ', 0, 'f', 0 + BYTE 'o', 0, 'm', 0, ' ', 0 + WORD 0 - LogShortAfter DATA_SUFFIX BYTE 10,9,9,9 - ASCII "Short-After call " - BYTE 0 + LogShortAfter DATA_SUFFIX WORD 10,9,9,9 + BYTE 'S', 0, 'h', 0, 'o', 0, 'r', 0, 't', 0, '-', 0, 'A', 0, 'f', 0 + BYTE 'e', 0, 'r', 0, ' ', 0, 'c', 0, 'a', 0, 'l', 0, 'l', 0, ' ', 0 + BYTE ' ', 0 + WORD 0 - LogReturn DATA_SUFFIX BYTE 9,9 - ASCII "Return from callback:" - BYTE 10,0 + LogReturn DATA_SUFFIX WORD 9,9 + BYTE 'R', 0, 'e', 0, 't', 0, 'u', 0, 'r', 0, 'n', 0, ' ', 0, 'f', 0 + BYTE 'o', 0, 'm', 0, ' ', 0, 'c', 0, 'a', 0, 'l', 0, 'l', 0, 'b', 0 + BYTE 'c', 0, 'k', 0, ':', 0 + WORD 10,0 - LogBefore DATA_SUFFIX BYTE 9,9,9 - ASCII "Before call-back " - BYTE 0 + LogBefore DATA_SUFFIX WORD 9,9,9 + BYTE 'B', 0, 'e', 0, 'f', 0, 'o', 0, 'r', 0, 'e', 0, ' ', 0, 'c', 0 + BYTE 'l', 0, 'l', 0, '-', 0, 'b', 0, 'a', 0, 'c', 0, 'k', 0, ' ', 0 + BYTE ' ', 0 + WORD 0 - LogShortBefore DATA_SUFFIX BYTE 10,9,9,9 - ASCII "Sh-Before call-back" - BYTE 0 + LogShortBefore DATA_SUFFIX WORD 10,9,9,9 + BYTE 'S', 0, 'h', 0, '-', 0, 'B', 0, 'e', 0, 'f', 0, 'o', 0, 'r', 0 + BYTE ' ', 0, 'c', 0, 'a', 0, 'l', 0, 'l', 0, '-', 0, 'b', 0, 'a', 0 + BYTE 'k', 0 + WORD 0 + LogLF DATA_SUFFIX WORD 10,0 + ELSE + LogStack DATA_SUFFIX ASCII "%s ESP = 0x%08X Stack = 0x%08X Real = 0x%08X" + BYTE 0 - LogLF DATA_SUFFIX BYTE 10,0 + LogCall DATA_SUFFIX BYTE 9,9 + ASCII "Call:" + BYTE 10,0 + LogBeforeCall DATA_SUFFIX BYTE 9,9,9 + ASCII "Before call " + BYTE 0 + + LogNearCall DATA_SUFFIX BYTE 10,9,9,9 + ASCII "Near call " + BYTE 0 + + LogBackFrom DATA_SUFFIX BYTE 9 + ASCII "Back from " + BYTE 0 + + LogAfterCall DATA_SUFFIX BYTE 10,9,9,9 + ASCII "After call " + BYTE 0 + + LogReturnAfter DATA_SUFFIX BYTE 10,9,9,9 + ASCII "Return 0x%08X 0x%08X" + BYTE 0 + + LogCalled DATA_SUFFIX ASCII "Called callback from " + BYTE 0 + + LogShortAfter DATA_SUFFIX BYTE 10,9,9,9 + ASCII "Short-After call " + BYTE 0 + + LogReturn DATA_SUFFIX BYTE 9,9 + ASCII "Return from callback:" + BYTE 10,0 + + LogBefore DATA_SUFFIX BYTE 9,9,9 + ASCII "Before call-back " + BYTE 0 + + LogShortBefore DATA_SUFFIX BYTE 10,9,9,9 + ASCII "Sh-Before call-back" + BYTE 0 + + LogLF DATA_SUFFIX BYTE 10,0 + ENDIF ENDIF SECTION_CODE @@ -263,7 +350,11 @@ ELSE ENDIF ;# Log buffer push edi +IFDEF _UNICODE + call dword ptr [__imp__wsprintfW] +ELSE call dword ptr [__imp__wsprintfA] +ENDIF ;# If wsprintf succeeds then advance edi by number of bytes ;# written to buffer cmp eax,0 diff --git a/Contrib/System/Source/Plugin.c b/Contrib/System/Source/Plugin.c index e46992bf..8b570dd9 100644 --- a/Contrib/System/Source/Plugin.c +++ b/Contrib/System/Source/Plugin.c @@ -151,18 +151,21 @@ void system_pushint(int value) system_pushstring(buffer); } -TCHAR *copymem(TCHAR *output, TCHAR *input, int size) +void *copymem(void *output, void *input, size_t cbSize) { - TCHAR *out = output; - if ((input != NULL) && (output != NULL)) - while (size-- > 0) *(out++) = *(input++); - return output; + BYTE *out = (BYTE*) output; + BYTE *in = (BYTE*) input; + if ((input != NULL) && (output != NULL)) + { + while (cbSize-- > 0) *(out++) = *(in++); + } + return output; } HANDLE GlobalCopy(HANDLE Old) { - SIZE_T size = GlobalSize(Old); - return copymem(GlobalAlloc(GPTR, size), Old, (int) size); + size_t size = GlobalSize(Old); + return copymem(GlobalAlloc(GPTR, size), Old, size); } UINT_PTR NSISCallback(enum NSPIM msg) diff --git a/Contrib/System/Source/Plugin.h b/Contrib/System/Source/Plugin.h index 6400f469..4d9e4d51 100644 --- a/Contrib/System/Source/Plugin.h +++ b/Contrib/System/Source/Plugin.h @@ -27,7 +27,7 @@ extern int popint64(); // -1 -> stack empty extern void system_pushint(int value); extern HANDLE GlobalCopy(HANDLE Old); -extern TCHAR *copymem(TCHAR *output, TCHAR *input, int size); +extern void *copymem(void *output, void *input, size_t cbSize); extern UINT_PTR NSISCallback(enum NSPIM); diff --git a/Contrib/System/Source/System.c b/Contrib/System/Source/System.c index 916b6b5f..2de5003f 100644 --- a/Contrib/System/Source/System.c +++ b/Contrib/System/Source/System.c @@ -46,7 +46,7 @@ CallbackThunk* CallbackThunkListHead; HINSTANCE g_hInstance; // Return to callback caller with stack restore -TCHAR retexpr[4]; +char retexpr[4]; HANDLE retaddr; TCHAR *GetResultStr(SystemProc *proc) @@ -61,7 +61,7 @@ TCHAR *GetResultStr(SystemProc *proc) #ifdef SYSTEM_LOG_DEBUG // 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_ADD(a) { register int _len = lstrlen(syslogbuf); lstrcpyn(syslogbuf + _len, a, _countof(syslogbuf) - _len); } #define SYSTEM_LOG_POST { SYSTEM_LOG_ADD(_T("\n")); WriteToLog(syslogbuf); *syslogbuf = 0; } HANDLE logfile = NULL; @@ -82,11 +82,18 @@ void WriteToLog(TCHAR *buffer) wsprintf(timebuffer, _T("%04d %04d.%03d "), (++logop)%10000, (GetTickCount() / 1000) % 10000, GetTickCount() % 1000); +#ifdef _UNICODE +#ifdef _RPTW0 + _RPTW0(_CRT_WARN, timebuffer); + _RPTW0(_CRT_WARN, buffer); +#endif +#else _RPT0(_CRT_WARN, timebuffer); _RPT0(_CRT_WARN, buffer); +#endif - WriteFile(logfile, timebuffer, lstrlen(timebuffer), &written, NULL); - WriteFile(logfile, buffer, lstrlen(buffer), &written, NULL); + WriteFile(logfile, timebuffer, lstrlen(timebuffer)*sizeof(TCHAR), &written, NULL); + WriteFile(logfile, buffer, lstrlen(buffer)*sizeof(TCHAR), &written, NULL); // FlushFileBuffers(logfile); } @@ -108,10 +115,17 @@ PLUGINFUNCTION(Debug) SetFilePointer(logfile, 0, 0, FILE_END); logop = 0; +#ifdef _UNICODE + { // write Unicode Byte-Order Mark + DWORD written; + unsigned short bom = 0xfeff; + WriteFile(logfile, &bom, 2, &written, NULL); + } +#endif GetLocalTime(&t); GetTimeFormat(LOCALE_SYSTEM_DEFAULT, LOCALE_NOUSEROVERRIDE, &t, NULL, buftime, 1024); GetDateFormat(LOCALE_SYSTEM_DEFAULT, LOCALE_NOUSEROVERRIDE, &t, NULL, bufdate, 1024); - wsprintf(buffer, _T("System, %s %s [build "__TIME__" ")__DATE___T("]\n"), buftime, bufdate); + wsprintf(buffer, _T("System, %s %s [build ") __TTIME__ _T(" ") __TDATE__ _T("]\n"), buftime, bufdate); WriteToLog(buffer); } else ; else @@ -543,9 +557,9 @@ SystemProc *PrepareProc(BOOL NeedForCall) case _T('l'): case _T('L'): temp2 = PAT_LONG; break; case _T('m'): - case _T('M'): + case _T('M'): temp2 = PAT_STRING; break; case _T('t'): - case _T('T'): temp2 = PAT_STRING; break; + case _T('T'): temp2 = PAT_STRING; break; // will be PAT_WSTRING for Unicode NSIS case _T('g'): case _T('G'): temp2 = PAT_GUID; break; case _T('w'): @@ -705,7 +719,7 @@ SystemProc *PrepareProc(BOOL NeedForCall) // Use direct system proc address int addr; - proc->Dll = (HANDLE) INT_TO_POINTER(myatoi64(proc->DllName)); + proc->Dll = (HMODULE) INT_TO_POINTER(myatoi64(proc->DllName)); if (proc->Dll == 0) { @@ -749,8 +763,13 @@ SystemProc *PrepareProc(BOOL NeedForCall) // Get proc address if ((proc->Proc = GetProcAddress(proc->Dll, proc->ProcName)) == NULL) { +#ifdef _UNICODE + // automatic W discover + lstrcat(proc->ProcName, _T("W")); +#else // automatic A discover - lstrcat(proc->ProcName, _T("A")); + lstrcat(proc->ProcName, "A"); +#endif if ((proc->Proc = GetProcAddress(proc->Dll, proc->ProcName)) == NULL) proc->ProcResult = PR_ERROR; } @@ -826,7 +845,7 @@ void ParamsIn(SystemProc *proc) break; case PAT_WSTRING: case PAT_GUID: - wstr = (LPWSTR) (par->allocatedBlock = GlobalAlloc(GPTR, g_stringsize*2)); + wstr = (LPWSTR) (par->allocatedBlock = GlobalAlloc(GPTR, g_stringsize*sizeof(WCHAR))); MultiByteToWideChar(CP_ACP, 0, realbuf, g_stringsize, wstr, g_stringsize); if (par->Type == PAT_GUID) { @@ -900,7 +919,7 @@ void ParamsOut(SystemProc *proc) break; case PAT_STRING: { - unsigned num = lstrlen(*((TCHAR**) place)); + unsigned int num = lstrlen(*((TCHAR**) place)); if (num >= g_stringsize) num = g_stringsize-1; lstrcpyn(realbuf,*((TCHAR**) place), num+1); realbuf[num] = 0; @@ -908,7 +927,7 @@ void ParamsOut(SystemProc *proc) break; case PAT_GUID: wstr = (LPWSTR) GlobalAlloc(GPTR, g_stringsize*2); - StringFromGUID2(*((REFGUID*)place), wstr, g_stringsize*2); + StringFromGUID2(*((REFGUID*)place), wstr, g_stringsize); WideCharToMultiByte(CP_ACP, 0, wstr, g_stringsize, realbuf, g_stringsize, NULL, NULL); GlobalFree((HGLOBAL)wstr); break; @@ -942,7 +961,6 @@ HANDLE CreateCallback(SystemProc *cbproc) { char *mem; - if (cbproc->Proc == NULL) { // Set callback index @@ -975,7 +993,7 @@ void CallStruct(SystemProc *proc) { BOOL ssflag; int i, structsize = 0, size = 0; - TCHAR *st, *ptr; + char *st, *ptr; SYSTEM_LOG_ADD(_T("\t\tStruct...")); @@ -994,7 +1012,7 @@ void CallStruct(SystemProc *proc) if (structsize == 0) structsize = (int) GlobalSize((HANDLE) proc->Proc); // Pointer to current data - st = (TCHAR*) proc->Proc; + st = (char*) proc->Proc; for (i = 1; i <= proc->ParamCount; i++) { @@ -1005,7 +1023,7 @@ void CallStruct(SystemProc *proc) { // Normal size = proc->Params[i].Size*4; - ptr = (TCHAR*) &(proc->Params[i].Value); + ptr = (char*) &(proc->Params[i].Value); } else { @@ -1026,13 +1044,14 @@ void CallStruct(SystemProc *proc) // clear unused value bits proc->Params[i].Value &= intmask[((size >= 0) && (size < 4))?(size):(0)]; // pointer - ptr = (TCHAR*) &(proc->Params[i].Value); + ptr = (char*) &(proc->Params[i].Value); break; case PAT_STRING: case PAT_GUID: case PAT_WSTRING: - ptr = (TCHAR*) proc->Params[i].Value; break; + // Jim Park: Pointer for memcopy, so keep as char* + ptr = (char*) proc->Params[i].Value; break; } } @@ -1071,7 +1090,7 @@ the same means as used for the _RPT0 macro. This leads to an endless recursion. BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { - g_hInstance=hInst; + g_hInstance=(HINSTANCE)hInst; if (ul_reason_for_call == DLL_PROCESS_ATTACH) { @@ -1084,7 +1103,6 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) LastError = 0; LastProc = NULL; CallbackIndex = 0; - retexpr[0] = (char) 0xC2; CallbackThunkListHead = NULL; retexpr[0] = (char) 0xC2; retexpr[2] = 0x00; @@ -1181,7 +1199,6 @@ unsigned int GetSizeOfProcParam(void) return (sizeof(ProcParameter)); } - /* Returns offset for element Size of ProcParameter structure */ diff --git a/Contrib/System/Source/System.h b/Contrib/System/Source/System.h index ac21c72d..99f1e16d 100644 --- a/Contrib/System/Source/System.h +++ b/Contrib/System/Source/System.h @@ -87,11 +87,10 @@ struct tag_SystemProc int ProcResult; TCHAR DllName[1024]; TCHAR ProcName[1024]; - HANDLE Dll; - HANDLE Proc; + HMODULE Dll; + HANDLE Proc; int Options; int ParamCount; - // if you'll change ProcParameter or SystemProc structure - update SYSTEM_ZERO_PARAM_VALUE_OFFSET value ProcParameter Params[100]; // I hope nobody will use more than 100 params // Callback specific diff --git a/Contrib/UserInfo/UserInfo.c b/Contrib/UserInfo/UserInfo.c index f5d4b65d..26cec4d4 100644 --- a/Contrib/UserInfo/UserInfo.c +++ b/Contrib/UserInfo/UserInfo.c @@ -21,16 +21,18 @@ void __declspec(dllexport) GetName(HWND hwndParent, int string_size, } } -TCHAR* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny) -{ - TCHAR *group = NULL; - HANDLE hToken = NULL; struct group { DWORD auth_id; TCHAR *name; }; +// Jim Park: Moved this array from inside the func to the outside. While it +// was probably "safe" for this array to be inside because the strings are in +// the .data section and so the pointer to the string returned is probably +// safe, this is a bad practice to have as that's making an assumption on what +// the compiler will do. Besides which, other types of data returned would +// actually fail as the local vars would be popped off the stack. struct group groups[] = { {DOMAIN_ALIAS_RID_USERS, _T("User")}, @@ -40,6 +42,12 @@ struct group groups[] = {DOMAIN_ALIAS_RID_ADMINS, _T("Admin")} }; +TCHAR* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny) +{ + TCHAR *group = NULL; + HANDLE hToken = NULL; + + if (GetVersion() & 0x80000000) // Not NT { return _T("Admin"); diff --git a/Contrib/VPatch/Source/GenPat/main.cpp b/Contrib/VPatch/Source/GenPat/main.cpp index 1eea88e9..64e3a505 100644 --- a/Contrib/VPatch/Source/GenPat/main.cpp +++ b/Contrib/VPatch/Source/GenPat/main.cpp @@ -202,7 +202,7 @@ int _tmain( int argc, TCHAR * argv[] ) { } catch(const TCHAR* s) { terr << _T("ERROR: ") << s << _T("\n"); patch.close(); - unlink(tempFileName.c_str()); + _tunlink(tempFileName.c_str()); return 3; } @@ -299,6 +299,6 @@ int _tmain( int argc, TCHAR * argv[] ) { terr << _T("WARNING: source and target file have equal CRCs!"); delete sourceCRC; delete targetCRC; - unlink(tempFileName.c_str()); + _tunlink(tempFileName.c_str()); return 0; } diff --git a/Contrib/nsExec/nsexec.c b/Contrib/nsExec/nsexec.c index 837ae25d..19c9a7c1 100644 --- a/Contrib/nsExec/nsexec.c +++ b/Contrib/nsExec/nsexec.c @@ -156,6 +156,10 @@ void ExecScript(int log) { IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE; // Windows character-mode user interface (CUI) subsystem. pNTHeaders->OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI; + // g_hInst is assumed to be the very base of the DLL in memory. + // WinMain will have the address of the WinMain function in memory. + // Getting the difference gets you the relative location of the + // WinMain function. pNTHeaders->OptionalHeader.AddressOfEntryPoint = (DWORD)_tWinMain - (DWORD)g_hInst; UnmapViewOfFile(pMapView); } @@ -278,10 +282,10 @@ params: szBuf[dwRead] = 0; if (log) { TCHAR *p, *p2; - SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf); - if (GlobalSize(hUnusedBuf) < iReqLen && (iReqLen < g_stringsize || !(log & 2))) { + SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf) + 1; + if (GlobalSize(hUnusedBuf) < iReqLen*sizeof(TCHAR) && (iReqLen < g_stringsize || !(log & 2))) { GlobalUnlock(hUnusedBuf); - hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND); + hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen*sizeof(TCHAR)+sizeof(szBuf), GHND); if (!hUnusedBuf) { lstrcpy(szRet, _T("error")); break; @@ -289,14 +293,16 @@ params: szUnusedBuf = (TCHAR *)GlobalLock(hUnusedBuf); } p = szUnusedBuf; // get the old left overs - if (iReqLen < g_stringsize || !(log & 2)) lstrcat(p, szBuf); + if (iReqLen < g_stringsize || !(log & 2)) { + lstrcat(p, szBuf); + } else { lstrcpyn(p + lstrlen(p), szBuf, g_stringsize - lstrlen(p)); } if (!(log & 2)) { while ((p = my_strstr(p, _T("\t")))) { - if ((int)(p - szUnusedBuf) > (int)(GlobalSize(hUnusedBuf) - TAB_REPLACE_SIZE - 1)) + if ((int)(p - szUnusedBuf) > (int)(GlobalSize(hUnusedBuf)/sizeof(TCHAR) - TAB_REPLACE_SIZE - 1)) { *p++ = _T(' '); } @@ -381,7 +387,9 @@ void LogMessage(const TCHAR *pStr, BOOL bOEM) { int nItemCount; if (!g_hwndList) return; //if (!lstrlen(pStr)) return; - if (bOEM == TRUE) OemToCharBuff(pStr, (TCHAR *)pStr, lstrlen(pStr)); +#ifndef _UNICODE + if (bOEM == TRUE) OemToCharBuff(pStr, (char*)pStr, lstrlen(pStr)); +#endif nItemCount=SendMessage(g_hwndList, LVM_GETITEMCOUNT, 0, 0); item.mask=LVIF_TEXT; item.pszText=(TCHAR *)pStr; diff --git a/Contrib/zip2exe/main.cpp b/Contrib/zip2exe/main.cpp index db5123bc..037e315c 100644 --- a/Contrib/zip2exe/main.cpp +++ b/Contrib/zip2exe/main.cpp @@ -71,7 +71,6 @@ TCHAR *g_options=_T("");//_T("/V3"); static BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); - int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpszCmdParam, int nCmdShow) { @@ -752,7 +751,7 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) ShowWindow(GetDlgItem(hwndDlg,IDC_TEST),SW_HIDE); ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_HIDE); { - for (size_t x = 0; x < sizeof(ids)/sizeof(ids[0]); x ++) + for (size_t x = 0; x < _countof(ids); x ++) ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_SHOWNA); SetDlgItemText(hwndDlg,IDOK,_T("&Generate")); EnableWindow(GetDlgItem(hwndDlg,IDOK),1); @@ -783,7 +782,7 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) g_compressor_solid = 0; g_mui=!IsDlgButtonChecked(hwndDlg,IDC_CLASSICUI); SetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, _T("")); - for (size_t x = 0; x < sizeof(ids)/sizeof(ids[0]); x ++) + for (size_t x = 0; x < _countof(ids); x ++) ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_HIDE); ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_SHOWNA); SetDlgItemText(hwndDlg,IDOK,_T("&Close")); diff --git a/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.cpp b/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.cpp index 171ff7fb..4f544c4e 100644 --- a/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.cpp +++ b/Source/7zip/7zip/Compress/LZMA/LZMAEncoder.cpp @@ -351,7 +351,7 @@ HRESULT CEncoder::Create() static int FindMatchFinder(const wchar_t *s) { - for (int m = 0; m < (int)(sizeof(kMatchFinderIDs) / sizeof(kMatchFinderIDs[0])); m++) + for (int m = 0; m < (int)(_countof(kMatchFinderIDs)); m++) if (AreStringsEqual(kMatchFinderIDs[m], s)) return m; return -1; diff --git a/Source/DialogTemplate.cpp b/Source/DialogTemplate.cpp index 56f7c9b2..cbb9a98a 100644 --- a/Source/DialogTemplate.cpp +++ b/Source/DialogTemplate.cpp @@ -436,12 +436,6 @@ void CDialogTemplate::ConvertToRTL() { for (unsigned int i = 0; i < m_vItems.size(); i++) { bool addExStyle = false; bool addExLeftScrollbar = true; - char *szClass; - - if (IS_INTRESOURCE(m_vItems[i]->szClass)) - szClass = (char *) m_vItems[i]->szClass; - else - szClass = winchar_toansi(m_vItems[i]->szClass); // Button if ((ULONG_PTR)(m_vItems[i]->szClass) == 0x80) { @@ -474,18 +468,18 @@ void CDialogTemplate::ConvertToRTL() { m_vItems[i]->dwStyle |= SS_CENTERIMAGE; } } - else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !stricmp(szClass, "RichEdit20A")) { + else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !_wcsicmp(m_vItems[i]->szClass, L"RichEdit20A")) { if ((m_vItems[i]->dwStyle & ES_CENTER) == 0) { m_vItems[i]->dwStyle ^= ES_RIGHT; } } - else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !stricmp(szClass, "SysTreeView32")) { + else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !_wcsicmp(m_vItems[i]->szClass, L"SysTreeView32")) { m_vItems[i]->dwStyle |= TVS_RTLREADING; m_vItems[i]->dwExtStyle |= WS_EX_LAYOUTRTL; addExStyle = true; addExLeftScrollbar = false; } - else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !stricmp(szClass, "SysListView32")) { + else if (!IS_INTRESOURCE(m_vItems[i]->szClass) && !_wcsicmp(m_vItems[i]->szClass, L"SysListView32")) { m_vItems[i]->dwExtStyle |= WS_EX_LAYOUTRTL; addExLeftScrollbar = false; } @@ -499,9 +493,6 @@ void CDialogTemplate::ConvertToRTL() { m_vItems[i]->dwExtStyle |= WS_EX_RTLREADING; m_vItems[i]->sX = m_sWidth - m_vItems[i]->sWidth - m_vItems[i]->sX; - - if (!IS_INTRESOURCE(m_vItems[i]->szClass)) - delete [] szClass; } m_dwExtStyle |= WS_EX_RIGHT | WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR; } diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index 100d20d3..cc0dfb82 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -76,7 +76,9 @@ size_t file_size(ifstream& file) { return (size_t)result; } -vector read_file(const string& filename) { +// This function slurps the whole file into the vector. +// Modified so the huge vector isn't returned by value. +void read_file(const tstring& filename, vector& data) { ifstream file(filename.c_str(), ios::binary); if (!file) { @@ -86,16 +88,13 @@ vector read_file(const string& filename) { // get the file size size_t filesize = file_size(file); - vector result; - result.resize(filesize); + data.resize(filesize); - file.read(reinterpret_cast(&result[0]), filesize); + file.read(reinterpret_cast(&data[0]), filesize); if (size_t(file.tellg()) != filesize) { // ifstream::eof doesn't return true here throw NSISException("Couldn't read entire file '" + filename + "'"); } - - return result; } } @@ -104,7 +103,7 @@ void Plugins::GetExports(const tstring &pathToDll, bool displayInfo) vector dlldata; PIMAGE_NT_HEADERS NTHeaders; try { - dlldata = read_file(pathToDll); + read_file(pathToDll, dlldata); NTHeaders = CResourceEditor::GetNTHeaders(&dlldata[0]); } catch (std::runtime_error&) { return; diff --git a/Source/ResourceVersionInfo.cpp b/Source/ResourceVersionInfo.cpp index fb13b942..3b2f3ad8 100644 --- a/Source/ResourceVersionInfo.cpp +++ b/Source/ResourceVersionInfo.cpp @@ -201,9 +201,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) WCHAR *KeyName, *KeyValue; strm.resize(0); - KeyName = winchar_fromansi(_T("VS_VERSION_INFO")); - SaveVersionHeader (strm, 0, sizeof (VS_FIXEDFILEINFO), 0, KeyName, &m_FixedInfo); - delete [] KeyName; + SaveVersionHeader (strm, 0, sizeof (VS_FIXEDFILEINFO), 0, L"VS_VERSION_INFO", &m_FixedInfo); DefineList *pChildStrings = m_ChildStringLists.get_strings(Index); if ( pChildStrings->getnum() > 0 ) @@ -211,11 +209,9 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) GrowBuf stringInfoStream; int codepage = m_ChildStringLists.get_codepage(Index); LANGID langid = m_ChildStringLists.get_lang(Index); - 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; + WCHAR Buff[16]; + swprintf(Buff, _countof(Buff), L"%04x%04x", langid, codepage); + SaveVersionHeader (stringInfoStream, 0, 0, 0, Buff, &ZEROS); for ( int i = 0; i < pChildStrings->getnum(); i++ ) { @@ -237,9 +233,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) PadStream (strm); p = strm.getlen(); - KeyName = winchar_fromansi(_T("StringFileInfo"), CP_ACP); - SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS); - delete [] KeyName; + SaveVersionHeader (strm, 0, 0, 0, L"StringFileInfo", &ZEROS); strm.add (stringInfoStream.get(), stringInfoStream.getlen()); wSize = WORD(strm.getlen() - p); @@ -251,15 +245,11 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) { PadStream (strm); p = strm.getlen(); - KeyName = winchar_fromansi(_T("VarFileInfo"), CP_ACP); - SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS); - delete [] KeyName; + SaveVersionHeader (strm, 0, 0, 0, L"VarFileInfo", &ZEROS); PadStream (strm); p1 = strm.getlen(); - KeyName = winchar_fromansi(_T("Translation"), CP_ACP); - SaveVersionHeader (strm, 0, 0, 0, KeyName, &ZEROS); - delete [] KeyName; + SaveVersionHeader (strm, 0, 0, 0, L"Translation", &ZEROS); // First add selected code language translation v = MAKELONG(m_ChildStringLists.get_lang(Index), m_ChildStringLists.get_codepage(Index)); diff --git a/Source/ShConstants.cpp b/Source/ShConstants.cpp index edb78fe5..c2624209 100644 --- a/Source/ShConstants.cpp +++ b/Source/ShConstants.cpp @@ -76,6 +76,8 @@ TCHAR* ConstantsStringList::idx2name(int idx) int ConstantsStringList::get_internal_idx(int idx) { struct constantstring *data=(struct constantstring *)gr.get(); + + // We do a linear search because the strings are sorted. for (int i = 0; i < index; i++) { if (data[i].index == idx) diff --git a/Source/build.cpp b/Source/build.cpp index ec3bef63..06cb2b1e 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -16,6 +16,7 @@ * Unicode support added by Jim Park -- 08/07/2007 */ +#include "tchar.h" #include "Platform.h" #include #include "exehead/config.h" @@ -114,6 +115,13 @@ CEXEBuild::CEXEBuild() : definedlist.add(_T("NSIS_VERSION"), NSIS_VERSION); +#ifdef _UNICODE + definedlist.add(_T("NSIS_UNICODE")); + definedlist.add(_T("NSIS_CHAR_SIZE"), _T("2")); +#else + definedlist.add(_T("NSIS_CHAR_SIZE"), _T("1")); +#endif + // automatically generated header file containing all defines #include @@ -286,12 +294,12 @@ CEXEBuild::CEXEBuild() : int i; for (i = 0; i < 10; i++) // 0 - 9 { - sprintf(Aux, _T("%d"), i); + wsprintf(Aux, _T("%d"), i); m_UserVarNames.add(Aux,1); } for (i = 0; i < 10; i++) // 10 - 19 { - sprintf(Aux, _T("R%d"), i); + wsprintf(Aux, _T("R%d"), i); m_UserVarNames.add(Aux,1); } m_UserVarNames.add(_T("CMDLINE"),1); // 20 everything before here doesn't have trailing slash removal @@ -450,7 +458,7 @@ int CEXEBuild::add_string(const TCHAR *string, int process/*=1*/, WORD codepage/ if (*string == _T('$') && *(string+1) == _T('(')) { int idx = 0; - TCHAR *cp = strdup(string+2); + TCHAR *cp = _tcsdup(string+2); TCHAR *p = _tcschr(cp, _T(')')); if (p && p[1] == _T('\0') ) { // if string is only a language str identifier *p = 0; @@ -480,14 +488,19 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP const TCHAR *p=in; while (*p) { - const TCHAR *np = CharNextExA(codepage, p, 0); + const TCHAR *np; +#ifdef _UNICODE + np = CharNext(p); +#else + np = CharNextExA(codepage, p, 0); +#endif if (np - p > 1) // multibyte TCHAR { int l = np - p; while (l--) { _TUCHAR i = (_TUCHAR)*p++; - if (i >= NS_CODES_START) { + if (NS_IS_CODE(i)) { *out++ = (TCHAR)NS_SKIP_CODE; } *out++=(TCHAR)i; @@ -500,7 +513,7 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP p=np; // increment p. // Test for characters extending into the variable codes - if (i >= NS_CODES_START) { + if (NS_IS_CODE(i)) { *out++ = (TCHAR)NS_SKIP_CODE; // out does get the NS_CODE as well because of // "*out++=(TCHAR)i" at the end. @@ -584,7 +597,7 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP if ( !bProceced && *p == _T('(') ) { int idx = -1; - TCHAR *cp = strdup(p+1); // JP: Bad... should avoid memory alloc. + TCHAR *cp = _tcsdup(p+1); // JP: Bad... should avoid memory alloc. TCHAR *pos = _tcschr(cp, _T(')')); if (pos) { @@ -625,7 +638,7 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP if (_tcschr(tbuf,cBracket)) (_tcschr(tbuf,cBracket)+1)[0]=0; if ( tbuf[0] == _T('{') && tbuf[_tcsclen(tbuf)-1] == _T('}') ) { - TCHAR *tstIfDefine = strdup(tbuf+1); + TCHAR *tstIfDefine = _tcsdup(tbuf+1); tstIfDefine[_tcsclen(tstIfDefine)-1] = _T('\0'); bDoWarning = definedlist.find(tstIfDefine) == NULL; // If it's a defined identifier, then don't warn. @@ -941,7 +954,7 @@ int CEXEBuild::add_label(const TCHAR *name) int cs=build_cursection->code; int ce=cs+build_cursection->code_size; - TCHAR *p=strdup(name); + TCHAR *p=_tcsdup(name); if (p[_tcsclen(p)-1] == _T(':')) p[_tcsclen(p)-1]=0; int offs=ns_label.add(p,0); free(p); @@ -961,10 +974,10 @@ int CEXEBuild::add_label(const TCHAR *name) if (*name == _T('.')) ERROR_MSG(_T("Error: global label \"%s\" already declared\n"),name); else { - const TCHAR *t = _T("section"); + const TCHAR *szType = _T("section"); if (build_cursection_isfunc) - t = _T("function"); - ERROR_MSG(_T("Error: label \"%s\" already declared in %s\n"),name,t); + szType = _T("function"); + ERROR_MSG(_T("Error: label \"%s\" already declared in %s\n"),name,szType); } return PS_ERROR; } @@ -1003,7 +1016,7 @@ int CEXEBuild::add_function(const TCHAR *funname) return PS_ERROR; } - set_uninstall_mode(!strnicmp(funname,_T("un."),3)); + set_uninstall_mode(!_tcsncicmp(funname,_T("un."),3)); // ns_func contains all the function names defined. int addr=ns_func.add(funname,0); @@ -1159,13 +1172,13 @@ int CEXEBuild::add_section(const TCHAR *secname, const TCHAR *defname, int expan set_uninstall_mode(0); - if (!strnicmp(name, _T("un."), 3)) + if (!_tcsncicmp(name, _T("un."), 3)) { set_uninstall_mode(1); name += 3; } - if (!stricmp(name, _T("uninstall"))) + if (!_tcsicmp(name, _T("uninstall"))) { set_uninstall_mode(1); } @@ -1724,7 +1737,7 @@ int CEXEBuild::AddVersionInfo() } } catch (exception& err) { - ERROR_MSG(_T("Error adding version information: %s\n"), err.what()); + ERROR_MSG(_T("Error adding version information: %s\n"), CtoTString(err.what())); return PS_ERROR; } } @@ -1735,6 +1748,7 @@ int CEXEBuild::AddVersionInfo() #endif // NSIS_SUPPORT_VERSION_INFO #ifdef NSIS_CONFIG_VISIBLE_SUPPORT + int CEXEBuild::ProcessPages() { SCRIPT_MSG(_T("Processing pages... ")); @@ -2130,7 +2144,7 @@ again: SCRIPT_MSG(_T("Done!\n")); } catch (exception& err) { - ERROR_MSG(_T("\nError: %s\n"), err.what()); + ERROR_MSG(_T("\nError: %s\n"), CtoTString(err.what())); return PS_ERROR; } @@ -2247,7 +2261,7 @@ int CEXEBuild::SetVarsSection() } } catch (exception& err) { - ERROR_MSG(_T("\nError: %s\n"), err.what()); + ERROR_MSG(_T("\nError: %s\n"), CtoTString(err.what())); return PS_ERROR; } @@ -2264,10 +2278,11 @@ int CEXEBuild::SetManifest() if (manifest == "") return PS_OK; + // Saved directly as binary into the exe. res_editor->UpdateResourceA(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), NSIS_DEFAULT_LANG, (LPBYTE) manifest.c_str(), manifest.length()); } catch (exception& err) { - ERROR_MSG(_T("Error setting manifest: %s\n"), err.what()); + ERROR_MSG(_T("Error setting manifest: %s\n"), CtoTString(err.what())); return PS_ERROR; } @@ -2284,7 +2299,7 @@ int CEXEBuild::UpdatePEHeader() // terminal services aware headers->OptionalHeader.DllCharacteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE; } catch (std::runtime_error& err) { - ERROR_MSG(_T("Error updating PE headers: %s\n"), err.what()); + ERROR_MSG(_T("Error updating PE headers: %s\n"), CtoTString(err.what())); return PS_ERROR; } @@ -2479,7 +2494,7 @@ int CEXEBuild::write_output(void) close_res_editor(); } catch (exception& err) { - ERROR_MSG(_T("\nError: %s\n"), err.what()); + ERROR_MSG(_T("\nError: %s\n"), CtoTString(err.what())); return PS_ERROR; } @@ -3192,6 +3207,7 @@ void CEXEBuild::warning(const TCHAR *s, ...) _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) diff --git a/Source/clzma.cpp b/Source/clzma.cpp index 552006b7..e1438797 100644 --- a/Source/clzma.cpp +++ b/Source/clzma.cpp @@ -199,7 +199,7 @@ int CLZMA::Init(int level, unsigned int dicSize) NCoderPropID::kDictionarySize, NCoderPropID::kNumFastBytes }; - const int kNumProps = sizeof(propdIDs) / sizeof(propdIDs[0]); + const int kNumProps = _countof(propdIDs); PROPVARIANT props[kNumProps]; // NCoderPropID::kAlgorithm props[0].vt = VT_UI4; diff --git a/Source/dirreader.cpp b/Source/dirreader.cpp index e5bc5d9f..3b8219f3 100644 --- a/Source/dirreader.cpp +++ b/Source/dirreader.cpp @@ -145,7 +145,7 @@ bool dir_reader::is_excluded(const tstring& name) const { iterator e = m_excluded.end(); for (; i != e; i++) { - if (!::stricmp(name.c_str(), i->c_str())) { + if (!::_tcsicmp(name.c_str(), i->c_str())) { return true; } } diff --git a/Source/exehead/Main.c b/Source/exehead/Main.c index ab7e6a17..7fd3e2cb 100644 --- a/Source/exehead/Main.c +++ b/Source/exehead/Main.c @@ -146,8 +146,7 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPTSTR lpszCmdPara { cmdline++; -// this only works with spaces because they have just one bit on -#define END_OF_ARG(c) (((c)|_T(' '))==_T(' ')) +#define END_OF_ARG(c) (c == _T(' ') || c == _T('\0')) #if defined(NSIS_CONFIG_VISIBLE_SUPPORT) && defined(NSIS_CONFIG_SILENT_SUPPORT) if (cmdline[0] == _T('S') && END_OF_ARG(cmdline[1])) diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index 4f0c6ed6..a7e5e87e 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -249,7 +249,9 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) 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(_T('0'), _T('x'), 0, 0); + state_language[0] = _T('0'); + state_language[1] = _T('x'); + state_language[2] = 0; { // Windows 9x @@ -318,7 +320,6 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) } } } - mystrcpy(state_install_directory,addtrailingslash(p)); } } @@ -343,20 +344,20 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) #ifdef NSIS_SUPPORT_BGBG if (header->bg_color1 != -1) { - DWORD cn = CHAR4_TO_DWORD(_T('_'), _T('N'), _T('b'), 0); + LPCTSTR cn = _T("_Nb"); 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 = (LPCTSTR)&cn; + wc.lpszClassName = cn; if (!RegisterClass(&wc)) return 0; SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0); - m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,(LPCTSTR)&cn,0,WS_POPUP, + m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,cn,0,WS_POPUP, vp.left,vp.top,vp.right-vp.left,vp.bottom-vp.top,0,NULL,g_hInstance,NULL); } @@ -399,6 +400,7 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) RegisterClass(&wc); } } + #endif { @@ -434,7 +436,6 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) #endif//NSIS_CONFIG_SILENT_SUPPORT } - #ifdef NSIS_CONFIG_VISIBLE_SUPPORT static int CALLBACK WINAPI BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { @@ -894,6 +895,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar page *thispage = g_this_page; TCHAR *dir = g_usrvars[thispage->parms[4]]; int browse_text = thispage->parms[3]; + if (uMsg == WM_NOTIFY_INIGO_MONTOYA) { GetUIText(IDC_DIR,dir); @@ -1026,7 +1028,6 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar * 6. `dir' is never modified. * */ - mystrcpy(s,dir); // Test for and use the GetDiskFreeSpaceEx API @@ -1038,8 +1039,8 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar ULARGE_INTEGER available64; ULARGE_INTEGER a, b; TCHAR *p; - WORD *pw = NULL; - while ((TCHAR *) pw != s) // trimslashtoend() cut the entire string + TCHAR *pw = NULL; + while (pw != s) // trimslashtoend() cut the entire string { if (GDFSE(s, &available64, &a, &b)) { @@ -1057,8 +1058,11 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar *pw = 0; p = trimslashtoend(s); // trim last backslash - pw = (LPWORD) (p - 1); - *pw = CHAR2_TO_WORD(_T('\\'), 0); // bring it back, but make the next TCHAR null + // bring it back, but make the next char null + pw = p; + *pw = 0; + --pw; + *pw = _T('\\'); } } } @@ -1730,12 +1734,16 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa do { item.pszText = ptr; ptr += SendMessage(linsthwnd,LVM_GETITEMTEXT,i,(LPARAM)&item); - *(WORD*)ptr = CHAR2_TO_WORD(_T('\r'),_T('\n')); - ptr+=2; + *ptr++ = _T('\r'); + *ptr++ = _T('\n'); } while (++i < count); // memory is auto zeroed when allocated with GHND - *ptr = 0; GlobalUnlock(memory); +#ifdef _UNICODE + SetClipboardData(CF_UNICODETEXT,memory); +#else SetClipboardData(CF_TEXT,memory); +#endif CloseClipboard(); } } diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index 3628220d..380b7e9e 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -1067,10 +1067,14 @@ static int NSISCALL ExecuteEntry(entry *entry_) if (SUCCEEDED(hres)) { - static WCHAR wsz[1024]; - hres=E_FAIL; - if (MultiByteToWideChar(CP_ACP, 0, buf1, -1, wsz, 1024)) - hres=ppf->lpVtbl->Save(ppf,(const WCHAR*)wsz,TRUE); +#ifdef _UNICODE + hres=ppf->lpVtbl->Save(ppf,(const WCHAR*)buf1,TRUE); +#else + static WCHAR wsz[1024]; + hres=E_FAIL; + if (MultiByteToWideChar(CP_ACP, 0, buf1, -1, wsz, 1024)) + hres=ppf->lpVtbl->Save(ppf,(const WCHAR*)wsz,TRUE); +#endif } ppf->lpVtbl->Release(ppf); } diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h index 549edc02..838943da 100644 --- a/Source/exehead/fileform.h +++ b/Source/exehead/fileform.h @@ -483,6 +483,7 @@ typedef struct { #define NS_SHELL_CODE 254 #define NS_LANG_CODE 255 #define NS_CODES_START NS_SKIP_CODE +#define NS_IS_CODE(x) ((x) >= 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 diff --git a/Source/exehead/util.c b/Source/exehead/util.c index 4550725c..c77fda42 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -285,7 +285,8 @@ TCHAR * NSISCALL trimslashtoend(TCHAR *buf) int NSISCALL validpathspec(TCHAR *ubuf) { 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(':'))); + return ((ubuf[0] == _T('\\') && ubuf[1] == _T('\\')) || + (dl >= _T('a') && dl <= _T('z') && ubuf[1] == _T(':'))); } TCHAR * NSISCALL skip_root(TCHAR *path) @@ -293,11 +294,11 @@ TCHAR * NSISCALL skip_root(TCHAR *path) TCHAR *p = CharNext(path); TCHAR *p2 = CharNext(p); - if (*path && *(WORD*)p == CHAR2_TO_WORD(_T(':'), _T('\\'))) + if (*path && p[0] == _T(':') && p[1] == _T('\\')) { return CharNext(p2); } - else if (*(WORD*)path == CHAR2_TO_WORD(_T('\\'),_T('\\'))) + else if (path[0] == _T('\\') && path[1] == _T('\\')) { // skip host and share name int x = 2; @@ -357,20 +358,21 @@ int NSISCALL is_valid_instpath(TCHAR *s) return 1; } -TCHAR * NSISCALL mystrstri(TCHAR *a, const TCHAR *b) +// Used strictly for the wininit.ini file which is an ASCII file. +char * NSISCALL mystrstriA(char *a, const char *b) { - int l = mystrlen(b); - while (mystrlen(a) >= l) + int l = lstrlenA(b); + while (lstrlenA(a) >= l) { - TCHAR c = a[l]; + char c = a[l]; a[l] = 0; - if (!lstrcmpi(a, b)) + if (!lstrcmpiA(a, b)) { a[l] = c; return a; } a[l] = c; - a = CharNext(a); + a = CharNextA(a); } return NULL; } @@ -413,8 +415,7 @@ TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir) int n = 100; while (n--) { - TCHAR prefix[4]; - *(LPDWORD)prefix = CHAR4_TO_DWORD(_T('n'), _T('s'), _T('a'), 0); + TCHAR prefix[4] = _T("nsa"); prefix[2] += (TCHAR)(GetTickCount() % 26); if (GetTempFileName(dir, prefix, 0, buf)) return buf; @@ -424,6 +425,106 @@ TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir) } #ifdef NSIS_SUPPORT_MOVEONREBOOT +/** Modifies the wininit.ini file to rename / delete a file. + * + * @param prevName The previous / current name of the file. + * @param newName The new name to move the file to. If NULL, the current file + * will be deleted. + */ +void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName) +{ + static char szRenameLine[1024]; + static TCHAR wininit[1024]; + static TCHAR tmpbuf[1024]; + + int cchRenameLine; + LPCSTR szRenameSec = "[Rename]\r\n"; // rename section marker + HANDLE hfile; + DWORD dwFileSize; + DWORD dwBytes; + DWORD dwRenameLinePos; + char *pszWinInit; // Contains the file contents of wininit.ini + + int spn; // length of the short path name in TCHARs. + + lstrcpy(tmpbuf, _T("NUL")); + + if (newName) { + // create the file if it's not already there to prevent GetShortPathName from failing + CloseHandle(myOpenFile(newName,0,CREATE_NEW)); + spn = GetShortPathName(newName,tmpbuf,1024); + if (!spn || spn > 1024) + return; + } + // wininit is used as a temporary here + spn = GetShortPathName(prevName,wininit,1024); + if (!spn || spn > 1024) + return; + cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit); + // Get the path to the wininit.ini file. + GetNSISString(wininit, g_header->str_wininit); + + hfile = myOpenFile(wininit, GENERIC_READ | GENERIC_WRITE, OPEN_ALWAYS); + + if (hfile != INVALID_HANDLE_VALUE) + { + // We are now working on the Windows wininit file + dwFileSize = GetFileSize(hfile, NULL); + pszWinInit = (char*) GlobalAlloc(GPTR, dwFileSize + cchRenameLine + 10); + + if (pszWinInit != NULL) + { + if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes) + { + // Look for the rename section in the current file. + LPSTR pszRenameSecInFile = mystrstriA(pszWinInit, szRenameSec); + if (pszRenameSecInFile == NULL) + { + // No rename section. So we add it to the end of file. + lstrcpyA(pszWinInit+dwFileSize, szRenameSec); + dwFileSize += 10; + dwRenameLinePos = dwFileSize; + } + else + { + // There is a rename section, but is there another section after it? + char *pszFirstRenameLine = pszRenameSecInFile+10; + char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n["); + if (pszNextSec) + { + TCHAR *p = ++pszNextSec; + while (p < pszWinInit + dwFileSize) { + p[cchRenameLine] = *p; + p++; + } + + dwRenameLinePos = pszNextSec - pszWinInit; + } + // rename section is last, stick item at end of file + else dwRenameLinePos = dwFileSize; + } + + mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, cchRenameLine); + dwFileSize += cchRenameLine; + + SetFilePointer(hfile, 0, NULL, FILE_BEGIN); + WriteFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL); + + GlobalFree(pszWinInit); + } + } + + CloseHandle(hfile); + } +} + +/** + * 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) { BOOL fOk = 0; @@ -434,86 +535,10 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) { fOk=mfea(pszExisting, pszNew, MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING); } - + if (!fOk) { - static TCHAR szRenameLine[1024]; - static TCHAR wininit[1024]; - static TCHAR tmpbuf[1024]; - int cchRenameLine; - static const TCHAR szRenameSec[] = _T("[Rename]\r\n"); - HANDLE hfile; - DWORD dwFileSize; - DWORD dwBytes; - DWORD dwRenameLinePos; - TCHAR *pszWinInit; - - int spn; - - *(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 - CloseHandle(myOpenFile(pszNew,0,CREATE_NEW)); - spn = GetShortPathName(pszNew,tmpbuf,1024); - if (!spn || spn > 1024) - return; - } - // wininit is used as a temporary here - spn = GetShortPathName(pszExisting,wininit,1024); - if (!spn || spn > 1024) - return; - 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); - - if (hfile != INVALID_HANDLE_VALUE) - { - dwFileSize = GetFileSize(hfile, NULL); - pszWinInit = GlobalAlloc(GPTR, dwFileSize + cchRenameLine + 10); - - if (pszWinInit != NULL) - { - if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes) - { - LPTSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec); - if (pszRenameSecInFile == NULL) - { - mystrcpy(pszWinInit+dwFileSize, szRenameSec); - dwFileSize += 10; - dwRenameLinePos = dwFileSize; - } - else - { - TCHAR *pszFirstRenameLine = pszRenameSecInFile+10; - TCHAR *pszNextSec = mystrstri(pszFirstRenameLine,_T("\n[")); - if (pszNextSec) - { - TCHAR *p = ++pszNextSec; - while (p < pszWinInit + dwFileSize) { - p[cchRenameLine] = *p; - p++; - } - - dwRenameLinePos = pszNextSec - pszWinInit; - } - // rename section is last, stick item at end of file - else dwRenameLinePos = dwFileSize; - } - - mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, cchRenameLine); - dwFileSize += cchRenameLine; - - SetFilePointer(hfile, 0, NULL, FILE_BEGIN); - WriteFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL); - - GlobalFree(pszWinInit); - } - } - - CloseHandle(hfile); - } + RenameViaWininit(pszExisting, pszNew); } #ifdef NSIS_SUPPORT_REBOOT @@ -622,11 +647,16 @@ TCHAR * NSISCALL GetNSISString(TCHAR *outbuf, int strtab) // indexes into the language TCHAR *in = (TCHAR*)GetNSISStringNP(GetNSISTab(strtab)); TCHAR *out = ps_tmpbuf; - if ((unsigned int) (outbuf - ps_tmpbuf) < sizeof(ps_tmpbuf)) + + // Still working within ps_tmpbuf, so set out to the + // current position that is passed in. + if (outbuf >= ps_tmpbuf && + (size_t) (outbuf - ps_tmpbuf) < _countof(ps_tmpbuf)) { out = outbuf; outbuf = 0; } + while (*in && out - ps_tmpbuf < NSIS_MAX_STRLEN) { _TUCHAR nVarIdx = (_TUCHAR)*in++; @@ -949,6 +979,19 @@ struct MGA_FUNC const char *func; }; +#ifdef _UNICODE +struct MGA_FUNC MGA_FUNCS[] = { + {"KERNEL32", "GetDiskFreeSpaceExW"}, + {"KERNEL32", "MoveFileExW"}, + {"ADVAPI32", "RegDeleteKeyExW"}, + {"ADVAPI32", "OpenProcessToken"}, + {"ADVAPI32", "LookupPrivilegeValueW"}, + {"ADVAPI32", "AdjustTokenPrivileges"}, + {"KERNEL32", "GetUserDefaultUILanguage"}, + {"SHLWAPI", "SHAutoComplete"}, + {"SHFOLDER", "SHGetFolderPathW"} +}; +#else struct MGA_FUNC MGA_FUNCS[] = { {"KERNEL32", "GetDiskFreeSpaceExA"}, {"KERNEL32", "MoveFileExA"}, @@ -960,6 +1003,7 @@ struct MGA_FUNC MGA_FUNCS[] = { {"SHLWAPI", "SHAutoComplete"}, {"SHFOLDER", "SHGetFolderPathA"} }; +#endif /** * Given a function enum, it will load the appropriate DLL and get the diff --git a/Source/icon.cpp b/Source/icon.cpp index bbf06e2d..7567c08d 100644 --- a/Source/icon.cpp +++ b/Source/icon.cpp @@ -416,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, _T("\nError generating uninstaller icon: %s -- failing!\n"), e.what()); + _ftprintf(g_output, _T("\nError generating uninstaller icon: %s -- failing!\n"), CtoTString(e.what())); return 0; } diff --git a/Source/lineparse.cpp b/Source/lineparse.cpp index 863596c3..ec2fd014 100644 --- a/Source/lineparse.cpp +++ b/Source/lineparse.cpp @@ -21,7 +21,7 @@ #include "tchar.h" #include #include -//#include "tstring.h" +#include "tstring.h" LineParser::LineParser(bool bCommentBlock) { @@ -126,7 +126,7 @@ int LineParser::gettoken_enum(int token, const TCHAR *strlist) // null seperated TCHAR *tt=gettoken_str(token); if (tt && *tt) while (*strlist) { - if (!stricmp(tt,strlist)) return x; + if (!_tcsicmp(tt,strlist)) return x; strlist+=_tcsclen(strlist)+1; x++; } diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp index 3c5832ef..2f04e625 100644 --- a/Source/makenssi.cpp +++ b/Source/makenssi.cpp @@ -189,7 +189,7 @@ static tstring get_home() static int process_config(CEXEBuild& build, tstring& conf) { - FILE *cfg=fopen(conf.c_str(),_T("rt")); + FILE *cfg=FOPENTEXT(conf.c_str(),_T("rt")); if (cfg) { if (build.display_script) @@ -227,7 +227,7 @@ static int change_to_script_dir(CEXEBuild& build, tstring& script) _ftprintf(g_output,_T("Changing directory to: \"%s\"\n"),dir.c_str()); fflush(g_output); } - if (chdir(dir.c_str())) + if (_tchdir(dir.c_str())) { if (build.display_errors) { @@ -274,34 +274,34 @@ int _tmain(int argc, TCHAR **argv) } catch (exception& err) { - fprintf(g_output, _T("Error initalizing CEXEBuild: %s\n"), err.what()); + _ftprintf(g_output, _T("Error initalizing CEXEBuild: %s\n"), CtoTString(err.what())); fflush(g_output); return 1; } - if (argc > 1 && IS_OPT(argv[1]) && !stricmp(&argv[1][1],_T("VERSION"))) + if (argc > 1 && IS_OPT(argv[tmpargpos]) && !_tcsicmp(&argv[tmpargpos][1],_T("VERSION"))) { - fprintf(g_output,NSIS_VERSION); + _ftprintf(g_output,NSIS_VERSION); fflush(g_output); return 0; } - if (argc > 1 && IS_OPT(argv[1]) && (argv[1][1]==_T('v') || argv[1][1]==_T('V'))) + if (argc > 1 && IS_OPT(argv[tmpargpos]) && (argv[tmpargpos][1]==_T('v') || argv[tmpargpos][1]==_T('V'))) { - tmpargpos++; - if (argv[1][2] <= _T('2') && argv[1][2] >= _T('0')) + if (argv[tmpargpos][2] <= _T('2') && argv[tmpargpos][2] >= _T('0')) { no_logo=1; } + tmpargpos++; } if (!no_logo) { 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,_T("w")); + g_output=FOPENTEXT(argv[tmpargpos]+2,_T("w")); if (!g_output) { - printf(_T("Error opening output log for writing. Using stdout.\n")); + _tprintf(_T("Error opening output log for writing. Using stdout.\n")); g_output=stdout; } outputtried=1; @@ -321,7 +321,7 @@ int _tmain(int argc, TCHAR **argv) if ((argv[argpos][1]==_T('D') || argv[argpos][1]==_T('d')) && argv[argpos][2]) { TCHAR *p=argv[argpos]+2; - TCHAR *s=strdup(p),*v; + TCHAR *s=_tcsdup(p),*v; if (build.display_script) { _ftprintf(g_output,_T("Command line defined: \"%s\"\n"),p); @@ -344,7 +344,7 @@ int _tmain(int argc, TCHAR **argv) { if (!outputtried) { - g_output=fopen(argv[argpos]+2,_T("w")); + g_output=FOPENTEXT(argv[argpos]+2,_T("w")); if (!g_output) { if (build.display_errors) _tprintf(_T("Error opening output log for writing. Using stdout.\n")); @@ -353,7 +353,7 @@ int _tmain(int argc, TCHAR **argv) outputtried=1; } } - else if (!stricmp(&argv[argpos][1],_T("NOCD"))) do_cd=0; + else if (!_tcsicmp(&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]) { @@ -364,9 +364,9 @@ int _tmain(int argc, TCHAR **argv) build.display_errors=v>0; g_display_errors=build.display_errors; } - 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"))) + else if (!_tcsicmp(&argv[argpos][1],_T("NOCONFIG"))) g_noconfig=1; + else if (!_tcsicmp(&argv[argpos][1],_T("PAUSE"))) g_dopause=1; + else if (!_tcsicmp(&argv[argpos][1],_T("LICENSE"))) { if (build.display_info) { @@ -374,7 +374,7 @@ int _tmain(int argc, TCHAR **argv) } nousage++; } - else if (!stricmp(&argv[argpos][1],_T("CMDHELP"))) + else if (!_tcsicmp(&argv[argpos][1],_T("CMDHELP"))) { if (argpos < argc-1) build.print_help(argv[++argpos]); @@ -382,7 +382,7 @@ int _tmain(int argc, TCHAR **argv) build.print_help(NULL); nousage++; } - else if (!stricmp(&argv[argpos][1],_T("NOTIFYHWND"))) + else if (!_tcsicmp(&argv[argpos][1],_T("NOTIFYHWND"))) { #ifdef _WIN32 build.notify_hwnd=(HWND)_ttol(argv[++argpos]); @@ -393,7 +393,7 @@ int _tmain(int argc, TCHAR **argv) build.warning(OPT_STR _T("NOTIFYHWND is disabled for non Win32 platforms.")); #endif } - else if (!stricmp(&argv[argpos][1],_T("HDRINFO"))) + else if (!_tcsicmp(&argv[argpos][1],_T("HDRINFO"))) { print_stub_info(build); nousage++; @@ -479,11 +479,11 @@ int _tmain(int argc, TCHAR **argv) else { _tcscpy(sfile,argv[argpos]); - fp=fopen(sfile,_T("rt")); + fp=FOPENTEXT(sfile,_T("rt")); if (!fp) { _stprintf(sfile,_T("%s.nsi"),argv[argpos]); - fp=fopen(sfile,_T("rt")); + fp=FOPENTEXT(sfile,_T("rt")); if (!fp) { if (build.display_errors) diff --git a/Source/manifest.cpp b/Source/manifest.cpp index d36890dc..da61fbf1 100644 --- a/Source/manifest.cpp +++ b/Source/manifest.cpp @@ -33,7 +33,9 @@ string generate(comctl comctl_selection, exec_level exec_level_selection) if (comctl_selection == comctl_old && exec_level_selection == exec_level_none) return ""; - string xml = "Nullsoft Install System " NSIS_VERSION ""; + string xml = "Nullsoft Install System "; + xml += TtoCString(NSIS_VERSION); + xml += ""; if (comctl_selection == comctl_xp) { diff --git a/Source/script.cpp b/Source/script.cpp index 785c62b8..5d912ea8 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -57,7 +57,7 @@ TCHAR *CEXEBuild::set_file_predefine(const TCHAR *filename) TCHAR *oldfilename = definedlist.find(_T("__FILE__")); if(oldfilename) { - oldfilename = strdup(oldfilename); + oldfilename = _tcsdup(oldfilename); definedlist.del(_T("__FILE__")); } const TCHAR *p = _tcsrchr(filename,_T('\\')); @@ -85,7 +85,7 @@ TCHAR *CEXEBuild::set_timestamp_predefine(const TCHAR *filename) { TCHAR *oldtimestamp = definedlist.find(_T("__TIMESTAMP__")); if(oldtimestamp) { - oldtimestamp = strdup(oldtimestamp); + oldtimestamp = _tcsdup(oldtimestamp); definedlist.del(_T("__TIMESTAMP__")); } @@ -105,8 +105,8 @@ TCHAR *CEXEBuild::set_timestamp_predefine(const TCHAR *filename) FileTimeToLocalFileTime(&fd.ftLastWriteTime, &floctime); FileTimeToSystemTime(&floctime, &stime); - 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])); + GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &stime, NULL, datebuf, _countof(datebuf)); + GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, _countof(timebuf)); wsprintf(timestampbuf,_T("%s %s"),datebuf,timebuf); definedlist.add(_T("__TIMESTAMP__"),timestampbuf); @@ -139,7 +139,7 @@ TCHAR *CEXEBuild::set_line_predefine(int linecnt, BOOL is_macro) TCHAR *oldline = definedlist.find(_T("__LINE__")); if(oldline) { - oldline = strdup(oldline); + oldline = _tcsdup(oldline); definedlist.del(_T("__LINE__")); } if(is_macro && oldline) { @@ -147,7 +147,7 @@ TCHAR *CEXEBuild::set_line_predefine(int linecnt, BOOL is_macro) _stprintf(linebuf,_T("%s.%s"),oldline,temp); } else { - linebuf = strdup(temp); + linebuf = _tcsdup(temp); } definedlist.add(_T("__LINE__"),linebuf); @@ -313,7 +313,7 @@ int CEXEBuild::doParse(const TCHAR *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((TCHAR*)m_linebuild.get(),_T("!define"),7) || !strnicmp((TCHAR*)m_linebuild.get(),_T("!insertmacro"),12)); + bool ignore_escaping = (!_tcsncicmp((TCHAR*)m_linebuild.get(),_T("!define"),7) || !_tcsncicmp((TCHAR*)m_linebuild.get(),_T("!insertmacro"),12)); res=line.parse((TCHAR*)m_linebuild.get(), ignore_escaping); inside_comment = line.inCommentBlock(); @@ -467,9 +467,9 @@ parse_again: switch(mod) { case 0: case 1: - istrue = stricmp(line.gettoken_str(1),line.gettoken_str(3)) == 0; break; + istrue = _tcsicmp(line.gettoken_str(1),line.gettoken_str(3)) == 0; break; case 2: - istrue = stricmp(line.gettoken_str(1),line.gettoken_str(3)) != 0; break; + istrue = _tcsicmp(line.gettoken_str(1),line.gettoken_str(3)) != 0; break; case 3: istrue = line.gettoken_float(1) <= line.gettoken_float(3); break; case 4: @@ -595,7 +595,7 @@ void CEXEBuild::ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hi } else if (in[0] == _T('{')) { - TCHAR *s=strdup(in+1); + TCHAR *s=_tcsdup(in+1); MANAGE_WITH(s, free); TCHAR *t=s; unsigned int bn = 0; @@ -633,7 +633,7 @@ void CEXEBuild::ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hi } else if (in[0] == _T('%')) { - TCHAR *s=strdup(in+1); + TCHAR *s=_tcsdup(in+1); MANAGE_WITH(s, free); TCHAR *t=s; while (*t) @@ -668,7 +668,7 @@ void CEXEBuild::ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hi { if (in[1] == _T('{')) // Found $$ before - Don't replace this define { - TCHAR *s=strdup(in+2); + TCHAR *s=_tcsdup(in+2); MANAGE_WITH(s, free); TCHAR *t=s; unsigned int bn = 0; @@ -743,7 +743,7 @@ int CEXEBuild::parseScript() int CEXEBuild::includeScript(TCHAR *f) { SCRIPT_MSG(_T("!include: \"%s\"\n"),f); - FILE *incfp=FOPEN(f,_T("rt")); + FILE *incfp=FOPENTEXT(f,_T("rt")); if (!incfp) { ERROR_MSG(_T("!include: could not open file: \"%s\"\n"),f); @@ -805,7 +805,7 @@ int CEXEBuild::MacroExists(const TCHAR *macroname) while (m && *m) { // check if macroname matches - if (!stricmp(m, macroname)) + if (!_tcsicmp(m, macroname)) return 1; // skip macro name @@ -876,7 +876,7 @@ int CEXEBuild::process_jump(LineParser &line, int wt, int *offs) const TCHAR *s=line.gettoken_str(wt); int v; - if (!stricmp(s,_T("0")) || !stricmp(s,_T(""))) *offs=0; + if (!_tcsicmp(s,_T("0")) || !_tcsicmp(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. @@ -930,7 +930,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *t=(TCHAR *)m_macros.get(); while (t && *t) { - if (!stricmp(t,line.gettoken_str(1))) break; + if (!_tcsicmp(t,line.gettoken_str(1))) break; t+=_tcsclen(t)+1; // advance over parameters @@ -961,7 +961,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int a; for (a=2; a < pc; a ++) { - if (!stricmp(line.gettoken_str(pc),line.gettoken_str(a))) + if (!_tcsicmp(line.gettoken_str(pc),line.gettoken_str(a))) { ERROR_MSG(_T("!macro: macro parameter named %s is used multiple times!\n"), line.gettoken_str(pc)); @@ -992,12 +992,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) LineParser l2(false); if (!l2.parse(str)) { - if (!stricmp(l2.gettoken_str(0),_T("!macroend"))) + if (!_tcsicmp(l2.gettoken_str(0),_T("!macroend"))) { linecnt++; break; } - if (!stricmp(l2.gettoken_str(0),_T("!macro"))) + if (!_tcsicmp(l2.gettoken_str(0),_T("!macro"))) { ERROR_MSG(_T("Error: can't define a macro inside a macro!\n")); return PS_ERROR; @@ -1020,7 +1020,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *m=t; while (t && *t) { - if (!stricmp(t,line.gettoken_str(1))) break; + if (!_tcsicmp(t,line.gettoken_str(1))) break; t+=_tcsclen(t)+1; // advance over parms @@ -1170,7 +1170,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *fc = line.gettoken_str(a); if (line.getnumtokens()==3) { - if(!stricmp(fc,_T("/nonfatal"))) + if(!_tcsicmp(fc,_T("/nonfatal"))) { fatal = 0; fc = line.gettoken_str(++a); @@ -1201,7 +1201,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) tstring file = basedir + *files_itr; - int result = unlink(file.c_str()); + int result = _tunlink(file.c_str()); if (result == -1) { ERROR_MSG(_T("!delfile: \"%s\" couldn't be deleted.\n"), file.c_str()); if (fatal) @@ -1222,7 +1222,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *file = line.gettoken_str(1); TCHAR *text = line.gettoken_str(2); - FILE *fp = FOPEN(file, _T("a")); + FILE *fp = FOPENTEXT(file, _T("a")); if (!fp) { ERROR_MSG(_T("!appendfile: \"%s\" couldn't be opened.\n"), file); @@ -1250,12 +1250,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!uninstall_mode) { enable_last_page_cancel = 0; - if (!stricmp(line.gettoken_str(line.getnumtokens()-1),_T("/ENABLECANCEL"))) + if (!_tcsicmp(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),_T("/ENABLECANCEL"))) + if (!_tcsicmp(line.gettoken_str(line.getnumtokens()-1),_T("/ENABLECANCEL"))) uenable_last_page_cancel = 1; } @@ -1395,7 +1395,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(2)) { - if (strnicmp(line.gettoken_str(2), _T("un."), 3)) + if (_tcsncicmp(line.gettoken_str(2), _T("un."), 3)) { if (uninstall_mode) { @@ -1418,7 +1418,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(1)) { - if (strnicmp(line.gettoken_str(1), _T("un."), 3)) + if (_tcsncicmp(line.gettoken_str(1), _T("un."), 3)) { if (uninstall_mode) { @@ -1447,7 +1447,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(3)) { - if (strnicmp(line.gettoken_str(3), _T("un."), 3)) + if (_tcsncicmp(line.gettoken_str(3), _T("un."), 3)) { if (uninstall_mode) { @@ -1470,7 +1470,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(2)) { - if (strnicmp(line.gettoken_str(2), _T("un."), 3)) + if (_tcsncicmp(line.gettoken_str(2), _T("un."), 3)) { if (uninstall_mode) { @@ -1493,7 +1493,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (*line.gettoken_str(1)) { - if (strnicmp(line.gettoken_str(1), _T("un."), 3)) + if (_tcsncicmp(line.gettoken_str(1), _T("un."), 3)) { if (uninstall_mode) { @@ -1652,7 +1652,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) installer_icon = load_icon_file(line.gettoken_str(1)); } catch (exception& err) { - ERROR_MSG(_T("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), CtoTString(err.what())); return PS_ERROR; } return PS_OK; @@ -1681,7 +1681,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } } catch (exception& err) { - ERROR_MSG(_T("Error while replacing bitmap: %s\n"), err.what()); + ERROR_MSG(_T("Error while replacing bitmap: %s\n"), CtoTString(err.what())); return PS_ERROR; } return PS_OK; @@ -1783,17 +1783,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int x; - if (!stricmp(line.gettoken_str(1),_T("/NOCUSTOM"))) + if (!_tcsicmp(line.gettoken_str(1),_T("/NOCUSTOM"))) { build_header.flags|=CH_FLAGS_NO_CUSTOM; SCRIPT_MSG(_T("InstType: disabling custom install type\n")); } - else if (!stricmp(line.gettoken_str(1),_T("/COMPONENTSONLYONCUSTOM"))) + else if (!_tcsicmp(line.gettoken_str(1),_T("/COMPONENTSONLYONCUSTOM"))) { build_header.flags|=CH_FLAGS_COMP_ONLY_ON_CUSTOM; SCRIPT_MSG(_T("InstType: making components viewable only on custom install type\n")); } - else if (!strnicmp(line.gettoken_str(1),_T("/CUSTOMSTRING="),14)) + else if (!_tcsncicmp(line.gettoken_str(1),_T("/CUSTOMSTRING="),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) @@ -1807,7 +1807,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { TCHAR *itname = line.gettoken_str(1); - if (!strnicmp(itname, _T("un."), 3)) { + if (!_tcsncicmp(itname, _T("un."), 3)) { set_uninstall_mode(1); itname += 3; } @@ -1864,7 +1864,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (file[0] == _T('$') && file[1] == _T('(')) { - TCHAR *cp = strdup(file+2); + TCHAR *cp = _tcsdup(file+2); MANAGE_WITH(cp, free); TCHAR *p = _tcschr(cp, _T(')')); if (p && p[1] == 0) { // if string is only a language str identifier @@ -1994,12 +1994,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_LICENSEBKCOLOR: { TCHAR *p = line.gettoken_str(1); - if (!strcmpi(p,_T("/windows"))) + if (!_tcsicmp(p,_T("/windows"))) { build_header.license_bg=-COLOR_WINDOW; SCRIPT_MSG(_T("LicenseBkColor: /windows\n")); } - else if (!strcmpi(p,_T("/grey")) || !strcmpi(p,_T("/gray"))) + else if (!_tcsicmp(p,_T("/grey")) || !_tcsicmp(p,_T("/gray"))) { build_header.license_bg=-COLOR_BTNFACE; SCRIPT_MSG(_T("LicenseBkColor: /grey\n")); @@ -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),_T("smooth"))) smooth=1; - else if (!stricmp(line.gettoken_str(x),_T("colored"))) build_header.flags|=CH_FLAGS_PROGRESS_COLORED; + if (!_tcsicmp(line.gettoken_str(x),_T("smooth"))) smooth=1; + else if (!_tcsicmp(line.gettoken_str(x),_T("colored"))) build_header.flags|=CH_FLAGS_PROGRESS_COLORED; else PRINTHELP() } try { @@ -2177,7 +2177,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) delete [] dlg; } catch (exception& err) { - ERROR_MSG(_T("Error setting smooth progress bar: %s\n"), err.what()); + ERROR_MSG(_T("Error setting smooth progress bar: %s\n"), CtoTString(err.what())); return PS_ERROR; } SCRIPT_MSG(_T("InstProgressFlags: smooth=%d, colored=%d\n"),smooth, @@ -2294,15 +2294,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) for (int i = 2; i < line.getnumtokens(); i++) { TCHAR *tok=line.gettoken_str(i); if (tok[0]==_T('/')) { - if (!strcmpi(tok,_T("/ITALIC"))) { + if (!_tcsicmp(tok,_T("/ITALIC"))) { SCRIPT_MSG(_T(" /ITALIC")); newfont.lfItalic=TRUE; } - else if (!strcmpi(tok,_T("/UNDERLINE"))) { + else if (!_tcsicmp(tok,_T("/UNDERLINE"))) { SCRIPT_MSG(_T(" /UNDERLINE")); newfont.lfUnderline=TRUE; } - else if (!strcmpi(tok,_T("/STRIKE"))) { + else if (!_tcsicmp(tok,_T("/STRIKE"))) { SCRIPT_MSG(_T(" /STRIKE")); newfont.lfStrikeOut=TRUE; } @@ -2344,7 +2344,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) build_header.bg_color1=0; build_header.bg_color2=RGB(0,0,255); } - else if (!stricmp(line.gettoken_str(1),_T("off"))) + else if (!_tcsicmp(line.gettoken_str(1),_T("off"))) { build_header.bg_color1=build_header.bg_color2=build_header.bg_textcolor=-1; SCRIPT_MSG(_T("BGGradient: off\n")); @@ -2363,7 +2363,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) p=line.gettoken_str(3); if (*p) { - if (!stricmp(p,_T("notext"))) build_header.bg_textcolor=-1; + if (!_tcsicmp(p,_T("notext"))) build_header.bg_textcolor=-1; else { v3=_tcstoul(p,&p,16); @@ -2387,7 +2387,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *p = line.gettoken_str(1); if (p[0]==_T('/')) { - if (stricmp(p,_T("/windows")) || line.getnumtokens()!=2) PRINTHELP() + if (_tcsicmp(p,_T("/windows")) || line.getnumtokens()!=2) PRINTHELP() build_header.lb_fg=build_header.lb_bg=-1; SCRIPT_MSG(_T("InstallColors: windows default colors\n")); } @@ -2500,9 +2500,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) check = true; } } else { - TCHAR *szClass = winchar_toansi(dlgItem->szClass); - check = stricmp(szClass, _T("Static")) == 0; - delete [] szClass; + check = _wcsicmp(dlgItem->szClass, L"Static") == 0; } if (check) { @@ -2557,7 +2555,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) 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(_T("Error while changing UI: %s\n"), err.what()); + ERROR_MSG(_T("Error while changing UI: %s\n"), CtoTString(err.what())); return PS_ERROR; } return PS_OK; @@ -2631,7 +2629,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) branding_image_id = IDC_BRANDIMAGE; } catch (exception& err) { - ERROR_MSG(_T("Error while adding image branding support: %s\n"), err.what()); + ERROR_MSG(_T("Error while adding image branding support: %s\n"), CtoTString(err.what())); return PS_ERROR; } return PS_OK; @@ -2641,7 +2639,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) #endif case TOK_SETFONT: { - if (!strnicmp(line.gettoken_str(1), _T("/LANG="), 6)) + if (!_tcsncicmp(line.gettoken_str(1), _T("/LANG="), 6)) { LANGID lang_id = _ttoi(line.gettoken_str(1) + 6); LanguageTable *table = GetLangTable(lang_id); @@ -2653,7 +2651,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } else { - _tcsnccpy(build_font, line.gettoken_str(1), sizeof(build_font)/sizeof(TCHAR)); + _tcsnccpy(build_font, line.gettoken_str(1), _countof(build_font)); build_font_size = line.gettoken_int(2); SCRIPT_MSG(_T("SetFont: \"%s\" %s\n"), line.gettoken_str(1), line.gettoken_str(2)); @@ -2714,12 +2712,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) while (line.gettoken_str(a)[0] == _T('/')) { - if (!strcmpi(line.gettoken_str(a),_T("/FINAL"))) + if (!_tcsicmp(line.gettoken_str(a),_T("/FINAL"))) { build_compressor_final = true; a++; } - else if (!strcmpi(line.gettoken_str(a),_T("/SOLID"))) + else if (!_tcsicmp(line.gettoken_str(a),_T("/SOLID"))) { build_compress_whole = true; a++; @@ -2807,7 +2805,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR datebuf[256]; TCHAR mathbuf[256]; - if (!stricmp(define,_T("/date")) || !stricmp(define,_T("/utcdate"))) { + if (!_tcsicmp(define,_T("/date")) || !_tcsicmp(define,_T("/utcdate"))) { if (line.getnumtokens()!=4) PRINTHELP() TCHAR *date_type = define; @@ -2818,11 +2816,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) time_t rawtime; time(&rawtime); - if (!stricmp(date_type,_T("/utcdate"))) + if (!_tcsicmp(date_type,_T("/utcdate"))) rawtime = mktime(gmtime(&rawtime)); datebuf[0]=0; - size_t s=strftime(datebuf,sizeof(datebuf),value,localtime(&rawtime)); + size_t s=_tcsftime(datebuf,_countof(datebuf),value,localtime(&rawtime)); if (s == 0) datebuf[0]=0; @@ -2830,15 +2828,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) datebuf[max(s,sizeof(datebuf)-1)]=0; value=datebuf; - } else if (!stricmp(define,_T("/file")) || !stricmp(define,_T("/file_noerr"))) { + } else if (!_tcsicmp(define,_T("/file")) || !_tcsicmp(define,_T("/file_noerr"))) { if (line.getnumtokens()!=4) PRINTHELP() define=line.gettoken_str(2); const TCHAR *filename=line.gettoken_str(3); - FILE *fp=fopen(filename,_T("r")); + FILE *fp=FOPENTEXT(filename,_T("r")); - if (!fp && stricmp(define,_T("/file_noerr"))) { + if (!fp && _tcsicmp(define,_T("/file_noerr"))) { ERROR_MSG(_T("!define /file: file not found (\"%s\")\n"),filename); return PS_ERROR; } @@ -2857,14 +2855,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) while (p >= str && (*p == _T('\r') || *p == _T('\n'))) p--; *++p=0; if (file_buf.getlen()) file_buf.add(_T("\n"),1); - file_buf.add(str,strlen(str)); + file_buf.add(str,_tcsclen(str)); } fclose(fp); } file_buf.add(_T("\0"),1); value = (TCHAR *)file_buf.get(); - } else if (!stricmp(define,_T("/math"))) { + } else if (!_tcsicmp(define,_T("/math"))) { int value1; int value2; @@ -2927,8 +2925,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) SCRIPT_MSG(_T("!undef: \"%s\"\n"),line.gettoken_str(1)); return PS_OK; case TOK_P_PACKEXEHEADER: - _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); + _tcsnccpy(build_packname,line.gettoken_str(1),_countof(build_packname)-1); + _tcsnccpy(build_packcmd,line.gettoken_str(2),_countof(build_packcmd)-1); SCRIPT_MSG(_T("!packhdr: filename=\"%s\", command=\"%s\"\n"), build_packname, build_packcmd); return PS_OK; @@ -2994,7 +2992,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *f = line.gettoken_str(1); - if(!stricmp(f,_T("/nonfatal"))) { + if(!_tcsicmp(f,_T("/nonfatal"))) { if (line.getnumtokens()!=3) PRINTHELP(); @@ -3085,7 +3083,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } return PS_OK; case TOK_P_CD: - if (!line.gettoken_str(1)[0] || chdir(line.gettoken_str(1))) + if (!line.gettoken_str(1)[0] || _tchdir(line.gettoken_str(1))) { ERROR_MSG(_T("!cd: error changing to: \"%s\"\n"),line.gettoken_str(1)); return PS_ERROR; @@ -3108,9 +3106,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int parmOffs=1; while (parmOffs < line.getnumtokens()) { - 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++; } + if (!_tcsicmp(line.gettoken_str(parmOffs),_T("/ignorecase"))) { ignCase=true; parmOffs++; } + else if (!_tcsicmp(line.gettoken_str(parmOffs),_T("/noerrors"))) { noErrors=true; parmOffs++; } + else if (!_tcsicmp(line.gettoken_str(parmOffs),_T("/file"))) { isFile=true; parmOffs++; } else break; } if (parmOffs+3 > line.getnumtokens()) @@ -3124,7 +3122,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (isFile) { - FILE *fp=fopen(source_string,_T("r")); + FILE *fp=FOPENTEXT(source_string,_T("r")); if (!fp) { ERROR_MSG(_T("!searchparse /file: error opening \"%s\"\n"),source_string); @@ -3150,8 +3148,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) while (p >= str && (*p == _T('\r') || *p == _T('\n'))) p--; *++p=0; - bool endSlash = (str[0] && str[strlen(str)-1] == _T('\\')); - if (tmpstr.getlen() || endSlash) tmpstr.add(str,strlen(str)); + bool endSlash = (str[0] && str[_tcsclen(str)-1] == _T('\\')); + if (tmpstr.getlen() || endSlash) tmpstr.add(str,_tcsclen(str)); // if we have valid contents and not ending on slash, then done if (!endSlash && (str[0] || tmpstr.getlen())) break; @@ -3220,7 +3218,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; case TOK_P_SEARCHREPLACESTRING: { - int ignoreCase=!stricmp(line.gettoken_str(1),_T("/ignorecase")); + int ignoreCase=!_tcsicmp(line.gettoken_str(1),_T("/ignorecase")); if (line.getnumtokens()!=5+ignoreCase) PRINTHELP() TCHAR *define=line.gettoken_str(1+ignoreCase); @@ -3239,7 +3237,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) while (*src) { - if (ignoreCase ? strnicmp(src,search,searchlen) : _tcsncmp(src,search,searchlen)) + if (ignoreCase ? _tcsncicmp(src,search,searchlen) : _tcsncmp(src,search,searchlen)) valout.add(src++,1); else { @@ -3334,7 +3332,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) uninstaller_icon = load_icon_file(line.gettoken_str(1)); } catch (exception& err) { - ERROR_MSG(_T("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), CtoTString(err.what())); return PS_ERROR; } return PS_OK; @@ -3403,7 +3401,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_SECTION: { int a=1,unselected = 0; - if (!strcmpi(line.gettoken_str(1),_T("/o"))) + if (!_tcsicmp(line.gettoken_str(1),_T("/o"))) { unselected = 1; a++; @@ -3414,7 +3412,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) 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),_T("uninstall"))) + if (!_tcsicmp(line.gettoken_str(a),_T("uninstall"))) { ERROR_MSG(_T("Error: Uninstall section declared, no NSIS_CONFIG_UNINSTALL_SUPPORT\n")); return PS_ERROR; @@ -3425,7 +3423,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (line.gettoken_str(a)[0]==_T('-')) { - if (!strnicmp(line.gettoken_str(a)+1,_T("un."),3)) + if (!_tcsncicmp(line.gettoken_str(a)+1,_T("un."),3)) ret=add_section(_T("un."),line.gettoken_str(a+1)); else ret=add_section(_T(""),line.gettoken_str(a+1)); @@ -3448,7 +3446,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) for (wt = 1; wt < line.getnumtokens(); wt ++) { TCHAR *p=line.gettoken_str(wt); - if (!stricmp(p, _T("RO"))) + if (!_tcsicmp(p, _T("RO"))) { if (section_add_flags(SF_RO) != PS_OK) return PS_ERROR; SCRIPT_MSG(_T("[RO] ")); @@ -3483,7 +3481,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { TCHAR buf[1024]; int a=1,ex = 0; - if (!strcmpi(line.gettoken_str(1),_T("/e"))) + if (!_tcsicmp(line.gettoken_str(1),_T("/e"))) { ex = 1; a++; @@ -3492,7 +3490,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (which_token == TOK_SECTIONGROUP || which_token == TOK_SUBSECTION) { TCHAR *s = line.gettoken_str(a); - if (!s[0] || (!strcmpi(s, _T("un.")) && !s[3])) + if (!s[0] || (!_tcsicmp(s, _T("un.")) && !s[3])) PRINTHELP(); } @@ -3510,7 +3508,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } SCRIPT_MSG(_T("Function: \"%s\"\n"),line.gettoken_str(1)); #ifndef NSIS_CONFIG_UNINSTALL_SUPPORT - if (!strnicmp(line.gettoken_str(1),_T("un."),3)) + if (!_tcsncicmp(line.gettoken_str(1),_T("un."),3)) { ERROR_MSG(_T("Error: Uninstall function declared, no NSIS_CONFIG_UNINSTALL_SUPPORT\n")); return PS_ERROR; @@ -3654,10 +3652,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int a = 1; int trim = 0; 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; + if (!_tcsncicmp(line.gettoken_str(a),_T("/TRIM"),5)) { + if (!_tcsicmp(line.gettoken_str(a)+5,_T("LEFT"))) trim = 1; + else if (!_tcsicmp(line.gettoken_str(a)+5,_T("RIGHT"))) trim = 2; + else if (!_tcsicmp(line.gettoken_str(a)+5,_T("CENTER"))) trim = 3; else PRINTHELP(); a++; } @@ -3677,7 +3675,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (trim) { TCHAR str[512]; if (line.getnumtokens()==a+1 && line.gettoken_str(a)[0]) - strcpy(str, line.gettoken_str(a)); + _tcscpy(str, line.gettoken_str(a)); else wsprintf(str, _T("Nullsoft Install System %s"), NSIS_VERSION); @@ -3701,7 +3699,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) res_editor->FreeResource(dlg); } catch (exception& err) { - ERROR_MSG(_T("Error while triming branding text control: %s\n"), err.what()); + ERROR_MSG(_T("Error while triming branding text control: %s\n"), CtoTString(err.what())); return PS_ERROR; } #else @@ -3725,7 +3723,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; case TOK_SPACETEXTS: { - if (!strcmpi(line.gettoken_str(1), _T("none"))) { + if (!_tcsicmp(line.gettoken_str(1), _T("none"))) { no_space_texts=true; SCRIPT_MSG(_T("SpaceTexts: none\n")); } @@ -3831,13 +3829,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_CALL: 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),_T("un."),3) + if (uninstall_mode && _tcsncicmp(line.gettoken_str(1),_T("un."),3) && (GetUserVarIndex(line,1) < 0) && line.gettoken_str(1)[0]!=_T(':')) { 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),_T("un."),3)) + if (!uninstall_mode && !_tcsncicmp(line.gettoken_str(1),_T("un."),3)) { ERROR_MSG(_T("Call must not be used with functions starting with \"un.\" in the non-uninstall sections.\n")); PRINTHELP() @@ -3886,9 +3884,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else { if (p[0] == _T('\\') && p[1] != _T('\\')) p++; - strncpy(out_path,p,1024-1); - if (*CharPrev(out_path,out_path+strlen(out_path))==_T('\\')) - *CharPrev(out_path,out_path+strlen(out_path))=0; // remove trailing slash + _tcsnccpy(out_path,p,1024-1); + if (*CharPrev(out_path,out_path+_tcsclen(out_path))==_T('\\')) + *CharPrev(out_path,out_path+_tcsclen(out_path))=0; // remove trailing slash } if (!*out_path) PRINTHELP() SCRIPT_MSG(_T("CreateDirectory: \"%s\"\n"),out_path); @@ -3962,7 +3960,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) else if (which_token == TOK_CALLINSTDLL) { int a = 2; - if (!stricmp(line.gettoken_str(a), _T("/NOUNLOAD"))) { + if (!_tcsicmp(line.gettoken_str(a), _T("/NOUNLOAD"))) { ent.offsets[3]=1; a++; } @@ -3991,7 +3989,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int a=1; ent.which=EW_RENAME; - if (!stricmp(line.gettoken_str(1),_T("/REBOOTOK"))) + if (!_tcsicmp(line.gettoken_str(1),_T("/REBOOTOK"))) { ent.offsets[2]=1; a++; @@ -4061,8 +4059,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) 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])) + for (x = 0 ; (unsigned) x < _countof(list) && _tcsicmp(list[x].str, p); x++); + if ((unsigned) x < _countof(list)) { r|=list[x].id; } @@ -4080,7 +4078,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int a=3; if (line.getnumtokens() > 3) { - if (!strcmpi(line.gettoken_str(3),_T("/SD"))) + if (!_tcsicmp(line.gettoken_str(3),_T("/SD"))) { int k=line.gettoken_enum(4,retstr); if (k <= 0) PRINTHELP(); @@ -4153,9 +4151,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *s=(line.gettoken_str(7)); TCHAR b[255]; - for (unsigned int spos=0; (spos <= strlen(s)) && (spos <= 255); spos++) - b[spos]=toupper(*(s+spos)); - strcpy(s,b); + for (unsigned int spos=0; (spos <= _tcsclen(s)) && (spos <= 255); spos++) + b[spos]=_totupper(*(s+spos)); + _tcscpy(s,b); if (*s) { @@ -4284,7 +4282,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int a = 2; - if (!strcmpi(line.gettoken_str(2),_T("/BRANDING"))) + if (!_tcsicmp(line.gettoken_str(2),_T("/BRANDING"))) a++; { @@ -4295,7 +4293,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_ERROR; } - if (!strcmpi(line.gettoken_str(a+1),_T("transparent"))) { + if (!_tcsicmp(line.gettoken_str(a+1),_T("transparent"))) { c.flags|=CC_BKB; c.lbStyle=BS_NULL; c.bkmode=TRANSPARENT; @@ -4366,15 +4364,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) for (int i = 3; i < line.getnumtokens(); i++) { TCHAR *tok=line.gettoken_str(i); if (tok[0]=='/') { - if (!strcmpi(tok,_T("/ITALIC"))) { + if (!_tcsicmp(tok,_T("/ITALIC"))) { SCRIPT_MSG(_T(" /ITALIC")); flags|=1; } - else if (!strcmpi(tok,_T("/UNDERLINE"))) { + else if (!_tcsicmp(tok,_T("/UNDERLINE"))) { SCRIPT_MSG(_T(" /UNDERLINE")); flags|=2; } - else if (!strcmpi(tok,_T("/STRIKE"))) { + else if (!_tcsicmp(tok,_T("/STRIKE"))) { SCRIPT_MSG(_T(" /STRIKE")); flags|=4; } @@ -4468,7 +4466,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int a=1; ent.which=EW_DELETEFILE; - if (!stricmp(line.gettoken_str(a),_T("/REBOOTOK"))) + if (!_tcsicmp(line.gettoken_str(a),_T("/REBOOTOK"))) { a++; ent.offsets[1]=DEL_REBOOT; @@ -4503,13 +4501,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=DEL_DIR; while (line.gettoken_str(a)[0]==_T('/')) { - if (!stricmp(line.gettoken_str(a),_T("/r"))) + if (!_tcsicmp(line.gettoken_str(a),_T("/r"))) { if (a == 3) PRINTHELP(); a++; ent.offsets[1]|=DEL_RECURSE; } - else if (!stricmp(line.gettoken_str(a),_T("/REBOOTOK"))) + else if (!_tcsicmp(line.gettoken_str(a),_T("/REBOOTOK"))) { if (a == 3) PRINTHELP(); a++; @@ -4543,11 +4541,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { set excluded; int a=1,attrib=0,rec=0,fatal=1; - if (!stricmp(line.gettoken_str(a),_T("/nonfatal"))) { + if (!_tcsicmp(line.gettoken_str(a),_T("/nonfatal"))) { fatal=0; a++; } - if (which_token == TOK_FILE && !stricmp(line.gettoken_str(a),_T("/a"))) + if (which_token == TOK_FILE && !_tcsicmp(line.gettoken_str(a),_T("/a"))) { #ifdef _WIN32 attrib=1; @@ -4556,12 +4554,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) #endif a++; } - if (!stricmp(line.gettoken_str(a),_T("/r"))) + if (!_tcsicmp(line.gettoken_str(a),_T("/r"))) { rec=1; a++; } - else if (which_token == TOK_FILE && !strnicmp(line.gettoken_str(a),_T("/oname="),7)) + else if (which_token == TOK_FILE && !_tcsncicmp(line.gettoken_str(a),_T("/oname="),7)) { TCHAR *on=line.gettoken_str(a)+7; a++; @@ -4598,9 +4596,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; } - if (!strnicmp(line.gettoken_str(a),_T("/x"),2)) + if (!_tcsncicmp(line.gettoken_str(a),_T("/x"),2)) { - while (!strnicmp(line.gettoken_str(a),_T("/x"),2)) + while (!_tcsncicmp(line.gettoken_str(a),_T("/x"),2)) { a++; @@ -4661,13 +4659,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int x; for (x = 0; x < 2; x ++) { - if (!stricmp(line.gettoken_str(a),_T("/SILENT"))) + if (!_tcsicmp(line.gettoken_str(a),_T("/SILENT"))) { a++; ent.offsets[2]&=~FOF_SIMPLEPROGRESS; ent.offsets[2]|=FOF_SILENT; } - else if (!stricmp(line.gettoken_str(a),_T("/FILESONLY"))) + else if (!_tcsicmp(line.gettoken_str(a),_T("/FILESONLY"))) { a++; ent.offsets[2]|=FOF_FILESONLY; @@ -4731,9 +4729,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) 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 ++); + for (x = 0 ; (unsigned) x < _countof(list) && _tcsicmp(list[x].str,p); x ++); - if ((unsigned) x < sizeof(list)/sizeof(list[0])) + if ((unsigned) x < _countof(list)) { r|=list[x].id; } @@ -5079,7 +5077,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int a=0; ent.which=EW_GETFULLPATHNAME; - if (line.getnumtokens()==4 && !stricmp(line.gettoken_str(1),_T("/SHORT"))) a++; + if (line.getnumtokens()==4 && !_tcsicmp(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); @@ -5206,7 +5204,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *s=line.gettoken_str(a); if (s[0] == _T('/')) { - if (stricmp(s,_T("/ifempty"))) PRINTHELP() + if (_tcsicmp(s,_T("/ifempty"))) PRINTHELP() a++; ent.offsets[4]=3; } @@ -5391,9 +5389,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[0]=GetUserVarIndex(line, 1); { TCHAR str[NSIS_MAX_STRLEN]; - strcpy(str, _T("%")); - strcat(str, line.gettoken_str(2)); - strcat(str, _T("%")); + _tcscpy(str, _T("%")); + _tcscat(str, line.gettoken_str(2)); + _tcscat(str, _T("%")); ent.offsets[1]=add_string(str); if (ent.offsets[0] < 0 || _tcsclen(line.gettoken_str(2))<1) PRINTHELP() } @@ -5453,17 +5451,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),_T("r"))) + if (!_tcsicmp(line.gettoken_str(3),_T("r"))) { ent.offsets[1]=GENERIC_READ; ent.offsets[2]=OPEN_EXISTING; } - else if (!stricmp(line.gettoken_str(3),_T("w"))) + else if (!_tcsicmp(line.gettoken_str(3),_T("w"))) { ent.offsets[1]=GENERIC_WRITE; ent.offsets[2]=CREATE_ALWAYS; } - else if (!stricmp(line.gettoken_str(3),_T("a"))) + else if (!_tcsicmp(line.gettoken_str(3),_T("a"))) { ent.offsets[1]=GENERIC_WRITE|GENERIC_READ; ent.offsets[2]=OPEN_ALWAYS; @@ -5731,11 +5729,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } ent.which=EW_SETBRANDINGIMAGE; for (int i = 1; i < line.getnumtokens(); i++) - if (!strnicmp(line.gettoken_str(i),_T("/IMGID="),7)) { + if (!_tcsncicmp(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),_T("/RESIZETOFIT"))) { + else if (!_tcsicmp(line.gettoken_str(i),_T("/RESIZETOFIT"))) { ent.offsets[2]=1; // must be 1 or 0 SCRIPT_MSG(_T("/RESIZETOFIT ")); } @@ -5764,7 +5762,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { int a=1; - if (!strcmpi(line.gettoken_str(1),_T("/GLOBAL"))) + if (!_tcsicmp(line.gettoken_str(1),_T("/GLOBAL"))) { a++; } @@ -5797,7 +5795,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { LANGID LangID=0; int a = 1; - if (!strnicmp(line.gettoken_str(a),_T("/LANG="),6)) + if (!_tcsncicmp(line.gettoken_str(a),_T("/LANG="),6)) LangID=_ttoi(line.gettoken_str(a++)+6); if (line.getnumtokens()!=a+2) PRINTHELP(); TCHAR *pKey = line.gettoken_str(a); @@ -5938,7 +5936,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int i = 1; int nounload = 0; - if (!strcmpi(line.gettoken_str(i), _T("/NOUNLOAD"))) { + if (!_tcsicmp(line.gettoken_str(i), _T("/NOUNLOAD"))) { i++; nounload++; } @@ -5951,7 +5949,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int w=parmst + (line.getnumtokens()-i - 1); ent.which=EW_PUSHPOP; ent.offsets[0]=add_string(line.gettoken_str(w)); - if (!strcmpi(line.gettoken_str(w), _T("/NOUNLOAD"))) nounloadmisused=1; + if (!_tcsicmp(line.gettoken_str(w), _T("/NOUNLOAD"))) nounloadmisused=1; ent.offsets[1]=0; ent.offsets[2]=0; ret=add_entry(&ent); @@ -6401,7 +6399,7 @@ DefineList *CEXEBuild::searchParseString(const TCHAR *source_string, LineParser if (tok && *tok) { int toklen = _tcsclen(tok); - while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):_tcsncmp(source_string,tok,toklen))) source_string++; + while (*source_string && (ignCase?_tcsncicmp(source_string,tok,toklen):_tcsncmp(source_string,tok,toklen))) source_string++; if (!*source_string) { @@ -6425,7 +6423,7 @@ DefineList *CEXEBuild::searchParseString(const TCHAR *source_string, LineParser if (tok && *tok) { int toklen = _tcsclen(tok); - while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):_tcsncmp(source_string,tok,toklen))) source_string++; + while (*source_string && (ignCase?_tcsncicmp(source_string,tok,toklen):_tcsncmp(source_string,tok,toklen))) source_string++; maxlen = source_string - src_start; @@ -6446,7 +6444,7 @@ DefineList *CEXEBuild::searchParseString(const TCHAR *source_string, LineParser if (maxlen < 0) ret->add(defout,src_start); else { - TCHAR *p=strdup(src_start); + TCHAR *p=_tcsdup(src_start); if (p) { p[maxlen]=0; diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 93b93cec..0cea2f8c 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -290,7 +290,7 @@ void CEXEBuild::print_help(TCHAR *commandname) int x; for (x = 0; x < TOK__LAST; x ++) { - if (!commandname || !stricmp(tokenlist[x].name,commandname)) + if (!commandname || !_tcsicmp(tokenlist[x].name,commandname)) { ERROR_MSG(_T("%s%s %s\n"),commandname?_T("Usage: "):_T(""),tokenlist[x].name,tokenlist[x].usage_str); if (commandname) break; @@ -306,7 +306,7 @@ void CEXEBuild::print_help(TCHAR *commandname) bool CEXEBuild::is_valid_token(TCHAR *s) { for (int x = 0; x < TOK__LAST; x ++) - if (!stricmp(tokenlist[x].name,s)) + if (!_tcsicmp(tokenlist[x].name,s)) return true; return false; } @@ -315,7 +315,7 @@ int CEXEBuild::get_commandtoken(TCHAR *s, int *np, int *op, int *pos) { int x; for (x = 0; x < TOK__LAST; x ++) - if (!stricmp(tokenlist[x].name,s)) + if (!_tcsicmp(tokenlist[x].name,s)) { *np=tokenlist[x].num_parms; *op=tokenlist[x].opt_parms; diff --git a/Source/util.cpp b/Source/util.cpp index 792169e9..18bfce9a 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -13,7 +13,9 @@ * 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 @@ -24,6 +26,7 @@ #include "util.h" #include "strlist.h" #include "winchar.h" + #ifndef _WIN32 # include # include // for close(2)