Jim Park's Unicode NSIS merging - Step 1 : switch to TCHARs where relevant.

Compiler output is identical before & after this step

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/branches/wizou@6036 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-03-24 17:22:56 +00:00
parent 4e48722b63
commit 752d7d239a
209 changed files with 9698 additions and 7658 deletions

View file

@ -3,10 +3,12 @@
LibraryLocal - used by the Library.nsh macros
Get the version of local DLL and TLB files
Written by Joost Verburg
Unicode support by Jim Park -- 07/27/2007
*/
#include "../../../Source/Platform.h"
#include "../../../Source/tstring.h"
#include <stdio.h>
#include <iostream>
@ -21,23 +23,27 @@ int g_noconfig=0;
int g_display_errors=1;
FILE *g_output=stdout;
int GetTLBVersion(string& filepath, DWORD& high, DWORD & low)
int GetTLBVersion(tstring& filepath, DWORD& high, DWORD & low)
{
#ifdef _WIN32
int found = 0;
char fullpath[1024];
char *p;
if (!GetFullPathName(filepath.c_str(), sizeof(fullpath), fullpath, &p))
TCHAR fullpath[1024];
TCHAR *p;
if (!GetFullPathName(filepath.c_str(), _countof(fullpath), fullpath, &p))
return 0;
WCHAR *ole_filename = winchar_fromansi(fullpath);
ITypeLib* typeLib;
HRESULT hr;
#ifdef _UNICODE
hr = LoadTypeLib(fullpath, &typeLib);
#else
// If built without UNICODE, we still need to convert this string to a Unicode string.
WCHAR *ole_filename = winchar_fromansi(fullpath);
hr = LoadTypeLib(ole_filename, &typeLib);
#endif
if (SUCCEEDED(hr)) {
@ -67,16 +73,16 @@ int GetTLBVersion(string& filepath, DWORD& high, DWORD & low)
#endif
}
int main(int argc, char* argv[])
int _tmain(int argc, TCHAR* argv[])
{
// Parse the command line
string cmdline;
tstring cmdline;
string mode;
string filename;
string filepath;
tstring mode;
tstring filename;
tstring filepath;
int filefound = 0;
@ -90,7 +96,7 @@ int main(int argc, char* argv[])
// Validate filename
ifstream fs(filename.c_str());
tifstream fs(filename.c_str());
if (fs.is_open())
{
@ -110,7 +116,7 @@ int main(int argc, char* argv[])
// DLL / EXE
if (mode.compare("D") == 0)
if (mode.compare(_T("D")) == 0)
{
versionfound = GetDLLVersion(filename, high, low);
@ -119,7 +125,7 @@ int main(int argc, char* argv[])
// TLB
if (mode.compare("T") == 0)
if (mode.compare(_T("T")) == 0)
{
versionfound = GetTLBVersion(filename, high, low);
@ -130,23 +136,23 @@ int main(int argc, char* argv[])
// Write the version to an NSIS header file
ofstream header(argv[3], ofstream::out);
tofstream header(argv[3], tofstream::out);
if (header)
{
if (!filefound)
{
header << "!define LIBRARY_VERSION_FILENOTFOUND" << endl;
header << _T("!define LIBRARY_VERSION_FILENOTFOUND") << endl;
}
else if (!versionfound)
{
header << "!define LIBRARY_VERSION_NONE" << endl;
header << _T("!define LIBRARY_VERSION_NONE") << endl;
}
else
{
header << "!define LIBRARY_VERSION_HIGH " << high << endl;
header << "!define LIBRARY_VERSION_LOW " << low << endl;
header << _T("!define LIBRARY_VERSION_HIGH ") << high << endl;
header << _T("!define LIBRARY_VERSION_LOW ") << low << endl;
}
header.close();

View file

@ -1,40 +1,41 @@
#include <windows.h>
#include "../../ExDll/nsis_tchar.h"
#define STR_SIZE 1024
void RegFile(char cmd, char *file, int x64);
void RegDll(char *file);
void RegTypeLib(char *file);
void DeleteFileOnReboot(char *pszFile);
void RegFile(TCHAR cmd, TCHAR *file, int x64);
void RegDll(TCHAR *file);
void RegTypeLib(TCHAR *file);
void DeleteFileOnReboot(TCHAR *pszFile);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
char *cmdline;
char seekchar = ' ';
TCHAR *cmdline;
TCHAR seekchar = _T(' ');
cmdline = GetCommandLine();
if (*cmdline == '\"')
if (*cmdline == _T('\"'))
seekchar = *cmdline++;
while (*cmdline && *cmdline != seekchar)
cmdline = CharNext(cmdline);
cmdline = CharNext(cmdline);
while (*cmdline == ' ')
while (*cmdline == _T(' '))
cmdline++;
if (*cmdline++ != '/')
if (*cmdline++ != _T('/'))
{
ExitProcess(1);
return 0;
}
if (*cmdline == 'S')
if (*cmdline == _T('S'))
{
HKEY rootkey;
if (SUCCEEDED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\NSIS.Library.RegTool.v3", 0, KEY_READ, &rootkey)))
if (SUCCEEDED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\NSIS.Library.RegTool.v3"), 0, KEY_READ, &rootkey)))
{
char keyname[STR_SIZE];
TCHAR keyname[STR_SIZE];
while (RegEnumKey(rootkey, 0, keyname, STR_SIZE) == ERROR_SUCCESS)
{
@ -44,24 +45,24 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
{
DWORD t, count, l = sizeof(DWORD);
if (SUCCEEDED(RegQueryValueEx(key, "count", NULL, &t, (LPBYTE) &count, &l)) && t == REG_DWORD)
if (SUCCEEDED(RegQueryValueEx(key, _T("count"), NULL, &t, (LPBYTE) &count, &l)) && t == REG_DWORD)
{
DWORD j;
char valname[128], mode[3], file[STR_SIZE];
TCHAR valname[128], mode[3], file[STR_SIZE];
for (j = 1; j <= count; j++)
{
wsprintf(valname, "%u.mode", j);
wsprintf(valname, _T("%u.mode"), j);
l = sizeof(mode);
if (FAILED(RegQueryValueEx(key, valname, NULL, &t, (LPBYTE) mode, &l)) || t != REG_SZ)
continue;
wsprintf(valname, "%u.file", j);
wsprintf(valname, _T("%u.file"), j);
l = STR_SIZE;
if (FAILED(RegQueryValueEx(key, valname, NULL, &t, (LPBYTE) file, &l)) || t != REG_SZ)
continue;
RegFile(mode[0], file, mode[1] == 'X');
RegFile(mode[0], file, mode[1] == _T('X'));
}
}
@ -71,11 +72,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
RegCloseKey(rootkey);
RegDeleteKey(HKEY_LOCAL_MACHINE, "Software\\NSIS.Library.RegTool.v3");
RegDeleteKey(HKEY_LOCAL_MACHINE, _T("Software\\NSIS.Library.RegTool.v3"));
}
{
char file[STR_SIZE];
TCHAR file[STR_SIZE];
if (GetModuleFileName(GetModuleHandle(NULL), file, STR_SIZE))
{
DeleteFileOnReboot(file);
@ -87,11 +88,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
OleInitialize(NULL);
if (*cmdline == 'D')
if (*cmdline == _T('D'))
{
RegDll(cmdline + 1);
}
else if (*cmdline == 'T')
else if (*cmdline == _T('T'))
{
RegTypeLib(cmdline + 1);
}
@ -106,7 +107,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
void SafeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection)
{
HMODULE kernel = GetModuleHandle("kernel32");
HMODULE kernel = GetModuleHandle(_T("kernel32"));
if (kernel)
{
FARPROC proc = GetProcAddress(kernel, "Wow64EnableWow64FsRedirection");
@ -121,26 +122,26 @@ void SafeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection)
}
}
void RegFile(char cmd, char *file, int x64)
void RegFile(TCHAR cmd, TCHAR *file, int x64)
{
char self[STR_SIZE];
char cmdline[STR_SIZE];
TCHAR self[STR_SIZE];
TCHAR cmdline[STR_SIZE];
int ready = 0;
if (!*file || (cmd != 'D' && cmd != 'T' && cmd != 'E'))
if (!*file || (cmd != _T('D') && cmd != _T('T') && cmd != _T('E')))
return;
if (cmd == 'E')
if (cmd == _T('E'))
{
wsprintf(cmdline, "\"%s\" /regserver", file);
wsprintf(cmdline, _T("\"%s\" /regserver"), file);
ready++;
}
else if (!x64)
{
if (GetModuleFileName(GetModuleHandle(NULL), self, STR_SIZE))
{
wsprintf(cmdline, "\"%s\" /%c%s", self, cmd, file);
wsprintf(cmdline, _T("\"%s\" /%c%s"), self, cmd, file);
ready++;
}
}
@ -148,7 +149,7 @@ void RegFile(char cmd, char *file, int x64)
{
if (GetSystemDirectory(self, STR_SIZE))
{
wsprintf(cmdline, "\"%s\\regsvr32.exe\" /s \"%s\"", self, file);
wsprintf(cmdline, _T("\"%s\\regsvr32.exe\" /s \"%s\""), self, file);
ready++;
SafeWow64EnableWow64FsRedirection(FALSE);
@ -176,7 +177,7 @@ void RegFile(char cmd, char *file, int x64)
}
}
void RegDll(char *file)
void RegDll(TCHAR *file)
{
HMODULE mod = LoadLibraryEx(file, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (mod)
@ -188,7 +189,7 @@ void RegDll(char *file)
}
}
void RegTypeLib(char *file)
void RegTypeLib(TCHAR *file)
{
WCHAR wfile[STR_SIZE];
@ -202,12 +203,12 @@ void RegTypeLib(char *file)
}
}
char *mystrstri(char *a, char *b)
TCHAR *mystrstri(TCHAR *a, TCHAR *b)
{
int l = lstrlen(b);
while (lstrlen(a) >= l)
{
char c = a[l];
TCHAR c = a[l];
a[l] = 0;
if (!lstrcmpi(a, b))
{
@ -222,23 +223,23 @@ char *mystrstri(char *a, char *b)
void mini_memcpy(void *out, const void *in, int len)
{
char *c_out=(char*)out;
char *c_in=(char *)in;
TCHAR *c_out=(TCHAR*)out;
TCHAR *c_in=(TCHAR *)in;
while (len-- > 0)
{
*c_out++=*c_in++;
}
}
void DeleteFileOnReboot(char *pszFile)
void DeleteFileOnReboot(TCHAR *pszFile)
{
BOOL fOk = 0;
HMODULE hLib=GetModuleHandle("KERNEL32.dll");
HMODULE hLib=GetModuleHandle(_T("KERNEL32.dll"));
if (hLib)
{
typedef BOOL (WINAPI *mfea_t)(LPCSTR lpExistingFileName,LPCSTR lpNewFileName,DWORD dwFlags);
typedef BOOL (WINAPI *mfea_t)(LPCTSTR lpExistingFileName,LPCTSTR lpNewFileName,DWORD dwFlags);
mfea_t mfea;
mfea=(mfea_t) GetProcAddress(hLib,"MoveFileExA");
mfea=(mfea_t) GetProcAddress(hLib,_CRT_STRINGIZE(MoveFileEx));
if (mfea)
{
fOk=mfea(pszFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
@ -247,10 +248,10 @@ void DeleteFileOnReboot(char *pszFile)
if (!fOk)
{
static char szRenameLine[1024];
static char wininit[1024];
static TCHAR szRenameLine[1024];
static TCHAR wininit[1024];
int cchRenameLine;
char *szRenameSec = "[Rename]\r\n";
TCHAR *szRenameSec = _T("[Rename]\r\n");
HANDLE hfile, hfilemap;
DWORD dwFileSize, dwRenameLinePos;
@ -260,10 +261,10 @@ void DeleteFileOnReboot(char *pszFile)
spn = GetShortPathName(pszFile,wininit,1024);
if (!spn || spn > 1024)
return;
cchRenameLine = wsprintf(szRenameLine,"NUL=%s\r\n",wininit);
cchRenameLine = wsprintf(szRenameLine,_T("NUL=%s\r\n"),wininit);
GetWindowsDirectory(wininit, 1024-16);
lstrcat(wininit, "\\wininit.ini");
lstrcat(wininit, _T("\\wininit.ini"));
hfile = CreateFile(wininit,
GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
@ -275,11 +276,11 @@ void DeleteFileOnReboot(char *pszFile)
if (hfilemap != NULL)
{
LPSTR pszWinInit = (LPSTR) MapViewOfFile(hfilemap, FILE_MAP_WRITE, 0, 0, 0);
LPTSTR pszWinInit = (LPTSTR) MapViewOfFile(hfilemap, FILE_MAP_WRITE, 0, 0, 0);
if (pszWinInit != NULL)
{
LPSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec);
LPTSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec);
if (pszRenameSecInFile == NULL)
{
lstrcpy(pszWinInit+dwFileSize, szRenameSec);
@ -288,11 +289,11 @@ void DeleteFileOnReboot(char *pszFile)
}
else
{
char *pszFirstRenameLine = pszRenameSecInFile+10;
char *pszNextSec = mystrstri(pszFirstRenameLine,"\n[");
TCHAR *pszFirstRenameLine = pszRenameSecInFile+10;
TCHAR *pszNextSec = mystrstri(pszFirstRenameLine,_T("\n["));
if (pszNextSec)
{
char *p = ++pszNextSec;
TCHAR *p = ++pszNextSec;
while (p < pszWinInit + dwFileSize) {
p[cchRenameLine] = *p;
p++;

View file

@ -3,19 +3,20 @@
NSIS plug-in for Type Library Registration/UnRegistration
Written by Joost Verburg
Unicode support by Jim Park -- 08/23/2007
*/
#include <windows.h>
#include <nsis/pluginapi.h> // nsis plugin
#include <nsis/nsis_tchar.h>
#define NSISFunction(funcname) extern "C" void __declspec(dllexport) funcname(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
#define NSISFunction(funcname) extern "C" void __declspec(dllexport) funcname(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop)
extern "C" BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
return TRUE;
}
// Functions
NSISFunction(Register) {
EXDLL_INIT();
@ -107,11 +108,11 @@ NSISFunction(GetLibVersion) {
if (SUCCEEDED(hr))
{
char buf[33];
TCHAR buf[33];
wsprintf(buf, "%d", typelibAttr->wMajorVerNum);
wsprintf(buf, _T("%d"), typelibAttr->wMajorVerNum);
pushstring(buf);
wsprintf(buf, "%d", typelibAttr->wMinorVerNum);
wsprintf(buf, _T("%d"), typelibAttr->wMinorVerNum);
pushstring(buf);
typeLib->ReleaseTLibAttr(typelibAttr);
@ -119,8 +120,8 @@ NSISFunction(GetLibVersion) {
}
else
{
pushstring("0");
pushstring("0");
pushstring(_T("0"));
pushstring(_T("0"));
}
typeLib->Release();
@ -128,8 +129,8 @@ NSISFunction(GetLibVersion) {
}
else
{
pushstring("0");
pushstring("0");
pushstring(_T("0"));
pushstring(_T("0"));
}
}