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:
parent
4e48722b63
commit
752d7d239a
209 changed files with 9698 additions and 7658 deletions
|
@ -1,3 +1,4 @@
|
|||
// Unicode support by Jim Park -- 08/22/2007
|
||||
// For layered windows
|
||||
#define _WIN32_WINNT 0x0500
|
||||
|
||||
|
@ -15,7 +16,7 @@ int g_rv;
|
|||
int resolution;
|
||||
int sleep_val, fadein_val, fadeout_val, state, timeleft, keycolor, nt50,
|
||||
alphaparam;
|
||||
const char classname[4] = "_sp";
|
||||
const TCHAR classname[4] = _T("_sp");
|
||||
|
||||
typedef BOOL(_stdcall * _tSetLayeredWindowAttributesProc) (HWND hwnd, // handle to the layered window
|
||||
COLORREF crKey, // specifies the color key
|
||||
|
@ -170,11 +171,11 @@ void CALLBACK TimeProc(UINT uID,
|
|||
}
|
||||
|
||||
void __declspec(dllexport) show(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t ** stacktop)
|
||||
TCHAR *variables, stack_t ** stacktop)
|
||||
{
|
||||
DEVMODE dm;
|
||||
char fn[MAX_PATH];
|
||||
char temp[64];
|
||||
TCHAR fn[MAX_PATH];
|
||||
TCHAR temp[64];
|
||||
|
||||
g_rv = -1;
|
||||
resolution = RESOLUTION;
|
||||
|
@ -223,10 +224,10 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
|
|||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.lpszClassName = classname;
|
||||
if (RegisterClass(&wc)) {
|
||||
char fn2[MAX_PATH];
|
||||
TCHAR fn2[MAX_PATH];
|
||||
lstrcpy(fn2, fn);
|
||||
lstrcat(fn, ".bmp");
|
||||
lstrcat(fn2, ".wav");
|
||||
lstrcat(fn, _T(".bmp"));
|
||||
lstrcat(fn2, _T(".wav"));
|
||||
g_hbm =
|
||||
LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0,
|
||||
LR_CREATEDIBSECTION | LR_LOADFROMFILE);
|
||||
|
@ -235,7 +236,7 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
|
|||
UINT timerEvent;
|
||||
|
||||
// Get Bitmap Information
|
||||
GetObject(g_hbm, sizeof(bm), (LPSTR) & bm);
|
||||
GetObject(g_hbm, sizeof(bm), & bm);
|
||||
|
||||
myWnd =
|
||||
CreateWindowEx(WS_EX_TOOLWINDOW |
|
||||
|
@ -246,7 +247,7 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
|
|||
// Set transparency / key color
|
||||
if (nt50) {
|
||||
// Get blending proc address
|
||||
HANDLE user32 = GetModuleHandle("user32");
|
||||
HANDLE user32 = GetModuleHandle(_T("user32"));
|
||||
SetLayeredWindowAttributesProc =
|
||||
(_tSetLayeredWindowAttributesProc) GetProcAddress(user32,
|
||||
"SetLayeredWindowAttributes");
|
||||
|
@ -283,6 +284,6 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
|
|||
UnregisterClass(wc.lpszClassName, g_hInstance);
|
||||
}
|
||||
}
|
||||
wsprintf(temp, "%d", g_rv);
|
||||
wsprintf(temp, _T("%d"), g_rv);
|
||||
pushstring(temp);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
#include "../../Source/exehead/resource.h"
|
||||
|
||||
// Unicode support added by Jim Park -- 08/02/2007
|
||||
|
||||
// Turn a pair of chars into a word
|
||||
// Turn four chars into a dword
|
||||
#ifdef __BIG_ENDIAN__ // Not very likely, but, still...
|
||||
|
@ -17,7 +19,7 @@ HWND hwBanner;
|
|||
HANDLE hThread;
|
||||
BOOL bFailed;
|
||||
|
||||
char buf[1024];
|
||||
TCHAR buf[1024];
|
||||
|
||||
BOOL CALLBACK BannerProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
|
@ -116,7 +118,7 @@ static UINT_PTR PluginCallback(enum NSPIM msg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
EXDLL_INIT();
|
||||
|
||||
|
@ -155,13 +157,13 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variable
|
|||
}
|
||||
}
|
||||
|
||||
void __declspec(dllexport) getWindow(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
|
||||
void __declspec(dllexport) getWindow(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
wsprintf(buf, "%u", hwBanner);
|
||||
wsprintf(buf, _T("%u"), hwBanner);
|
||||
pushstring(buf);
|
||||
}
|
||||
|
||||
void __declspec(dllexport) destroy(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
|
||||
void __declspec(dllexport) destroy(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
if (!hwBanner)
|
||||
return;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Unicode support by Jim Park -- 08/22/2007
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
|
@ -8,9 +10,9 @@
|
|||
g_stringsize=string_size; \
|
||||
g_stacktop=stacktop; }
|
||||
|
||||
#define NSISFunc(name) extern "C" void __declspec(dllexport) name(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
#define NSISFunc(name) extern "C" void __declspec(dllexport) name(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
|
||||
char szTemp[2048];
|
||||
TCHAR szTemp[2048];
|
||||
HWND hWndImage, hWndParent;
|
||||
|
||||
HINSTANCE g_hInstance;
|
||||
|
@ -37,7 +39,7 @@ struct myImageList {
|
|||
BYTE iType;
|
||||
union {
|
||||
HBITMAP hBitmap;
|
||||
char *szText;
|
||||
TCHAR *szText;
|
||||
COLORREF cGradientFrom;
|
||||
};
|
||||
RECT rPos;
|
||||
|
@ -80,14 +82,14 @@ NSISFunc(SetReturn) {
|
|||
extra->RegisterPluginCallback(g_hInstance, PluginCallback);
|
||||
|
||||
popstring(szTemp);
|
||||
bReturn = !lstrcmpi(szTemp, "on");
|
||||
bReturn = !lstrcmpi(szTemp, _T("on"));
|
||||
}
|
||||
|
||||
static void __stdcall my_pushstring(char *str)
|
||||
static void __stdcall my_pushstring(TCHAR *str)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop || !bReturn) return;
|
||||
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
|
||||
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+(g_stringsize*sizeof(TCHAR)));
|
||||
lstrcpyn(th->text,str,g_stringsize);
|
||||
th->next=*g_stacktop;
|
||||
*g_stacktop=th;
|
||||
|
@ -104,7 +106,7 @@ NSISFunc(SetBg) {
|
|||
hWndParent = hwndParent;
|
||||
|
||||
if (!hwndParent) {
|
||||
my_pushstring("can't find parent window");
|
||||
my_pushstring(_T("can't find parent window"));
|
||||
LCS();
|
||||
return;
|
||||
}
|
||||
|
@ -120,18 +122,18 @@ NSISFunc(SetBg) {
|
|||
LoadCursor(0, IDC_ARROW),
|
||||
0,
|
||||
0,
|
||||
"NSISBGImage",
|
||||
_T("NSISBGImage"),
|
||||
0
|
||||
};
|
||||
ATOM atomClass = RegisterClassEx(&wc);
|
||||
if (!atomClass) {
|
||||
my_pushstring("can't create window");
|
||||
my_pushstring(_T("can't create window"));
|
||||
return;
|
||||
}
|
||||
|
||||
hWndImage = CreateWindowEx(
|
||||
WS_EX_TOOLWINDOW,
|
||||
(LPSTR)(DWORD)atomClass,
|
||||
(LPTSTR)(DWORD)atomClass,
|
||||
0,
|
||||
WS_CLIPSIBLINGS|WS_POPUP,
|
||||
0,
|
||||
|
@ -144,7 +146,7 @@ NSISFunc(SetBg) {
|
|||
0
|
||||
);
|
||||
if (!hWndImage) {
|
||||
my_pushstring("can't create window");
|
||||
my_pushstring(_T("can't create window"));
|
||||
LCS();
|
||||
return;
|
||||
}
|
||||
|
@ -225,7 +227,7 @@ done:
|
|||
);
|
||||
}
|
||||
|
||||
my_pushstring("success");
|
||||
my_pushstring(_T("success"));
|
||||
}
|
||||
|
||||
NSISFunc(AddImage) {
|
||||
|
@ -233,7 +235,7 @@ NSISFunc(AddImage) {
|
|||
|
||||
myImageList *newImg = (myImageList *)GlobalAlloc(GPTR, sizeof(myImageList));
|
||||
if (!newImg) {
|
||||
my_pushstring("memory allocation error");
|
||||
my_pushstring(_T("memory allocation error"));
|
||||
LCS();
|
||||
return;
|
||||
}
|
||||
|
@ -242,7 +244,7 @@ NSISFunc(AddImage) {
|
|||
newImg->cTransparent = (COLORREF)-1;
|
||||
|
||||
popstring(szTemp);
|
||||
if (!lstrcmpi(szTemp, "/TRANSPARENT")) {
|
||||
if (!lstrcmpi(szTemp, _T("/TRANSPARENT"))) {
|
||||
newImg->iType = MIL_TRANSPARENT_BITMAP;
|
||||
newImg->cTransparent = GetColor();
|
||||
popstring(szTemp);
|
||||
|
@ -265,7 +267,7 @@ NSISFunc(AddImage) {
|
|||
while (img->next) img = img->next;
|
||||
img->next = newImg;
|
||||
|
||||
my_pushstring("success");
|
||||
my_pushstring(_T("success"));
|
||||
|
||||
LCS();
|
||||
}
|
||||
|
@ -275,7 +277,7 @@ NSISFunc(AddText) {
|
|||
|
||||
myImageList *newImg = (myImageList *)GlobalAlloc(GPTR, sizeof(myImageList));
|
||||
if (!newImg) {
|
||||
my_pushstring("memory allocation error");
|
||||
my_pushstring(_T("memory allocation error"));
|
||||
LCS();
|
||||
return;
|
||||
}
|
||||
|
@ -283,9 +285,9 @@ NSISFunc(AddText) {
|
|||
newImg->iType = MIL_TEXT;
|
||||
|
||||
popstring(szTemp);
|
||||
newImg->szText = (char *)GlobalAlloc(GPTR, lstrlen(szTemp)+1);
|
||||
newImg->szText = (TCHAR *)GlobalAlloc(GPTR, (lstrlen(szTemp)+1)*sizeof(TCHAR));
|
||||
if (!newImg->szText) {
|
||||
my_pushstring("memory allocation error");
|
||||
my_pushstring(_T("memory allocation error"));
|
||||
GlobalFree(newImg);
|
||||
LCS();
|
||||
return;
|
||||
|
@ -303,7 +305,7 @@ NSISFunc(AddText) {
|
|||
while (img->next) img = img->next;
|
||||
img->next = newImg;
|
||||
|
||||
my_pushstring("success");
|
||||
my_pushstring(_T("success"));
|
||||
|
||||
LCS();
|
||||
}
|
||||
|
@ -351,7 +353,7 @@ NSISFunc(Destroy) {
|
|||
hWndImage = 0;
|
||||
oldProc = NULL;
|
||||
Clear(0, 0, 0, 0, 0);
|
||||
UnregisterClass("NSISBGImage", g_hInstance);
|
||||
UnregisterClass(_T("NSISBGImage"), g_hInstance);
|
||||
}
|
||||
|
||||
NSISFunc(Sound) {
|
||||
|
@ -576,7 +578,7 @@ HBITMAP __stdcall LoadBitmapFile(long right, long bottom, BITMAP *bBitmap)
|
|||
{
|
||||
HBITMAP hBitmap = (HBITMAP)LoadImage(0, szTemp, IMAGE_BITMAP, right, bottom, LR_LOADFROMFILE);
|
||||
if (!hBitmap || !GetObject(hBitmap, sizeof(BITMAP), (void *)bBitmap)) {
|
||||
my_pushstring("can't load bitmap");
|
||||
my_pushstring(_T("can't load bitmap"));
|
||||
if (hBitmap)
|
||||
DeleteObject(hBitmap);
|
||||
LCS();
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
// Unicode support by Jim Park -- 08/22/2007
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
|
||||
#define NSISFunction(funcname) void __declspec(dllexport) funcname(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
#define NSISFunction(funcname) void __declspec(dllexport) funcname(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
|
||||
BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
||||
return TRUE;
|
||||
|
@ -16,8 +18,9 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
|||
|
||||
HMODULE hWinInet = NULL;
|
||||
|
||||
// GetProcAddress only takes ANSI.
|
||||
FARPROC GetWinInetFunc(char *func) {
|
||||
hWinInet = LoadLibrary("wininet.dll");
|
||||
hWinInet = LoadLibrary(_T("wininet.dll"));
|
||||
if (hWinInet)
|
||||
return GetProcAddress(hWinInet, func);
|
||||
return NULL;
|
||||
|
@ -44,9 +47,9 @@ NSISFunction(AutodialOnline) {
|
|||
EXDLL_INIT();
|
||||
|
||||
if (pInternetAutodial(INTERNET_AUTODIAL_FORCE_ONLINE, 0))
|
||||
pushstring("online");
|
||||
pushstring(_T("online"));
|
||||
else
|
||||
pushstring("offline");
|
||||
pushstring(_T("offline"));
|
||||
|
||||
FreeWinInet();
|
||||
}
|
||||
|
@ -62,9 +65,9 @@ NSISFunction(AutodialUnattended) {
|
|||
EXDLL_INIT();
|
||||
|
||||
if (pInternetAutodial(INTERNET_AUTODIAL_FORCE_UNATTENDED , 0))
|
||||
pushstring("online");
|
||||
pushstring(_T("online"));
|
||||
else
|
||||
pushstring("offline");
|
||||
pushstring(_T("offline"));
|
||||
|
||||
FreeWinInet();
|
||||
}
|
||||
|
@ -80,9 +83,9 @@ NSISFunction(AttemptConnect) {
|
|||
EXDLL_INIT();
|
||||
|
||||
if (pInternetAttemptConnect(0) == ERROR_SUCCESS)
|
||||
pushstring("online");
|
||||
pushstring(_T("online"));
|
||||
else
|
||||
pushstring("offline");
|
||||
pushstring(_T("offline"));
|
||||
|
||||
FreeWinInet();
|
||||
}
|
||||
|
@ -100,9 +103,9 @@ NSISFunction(GetConnectedState) {
|
|||
EXDLL_INIT();
|
||||
|
||||
if (pInternetGetConnectedState(&dwState, 0))
|
||||
pushstring("online");
|
||||
pushstring(_T("online"));
|
||||
else
|
||||
pushstring("offline");
|
||||
pushstring(_T("offline"));
|
||||
|
||||
FreeWinInet();
|
||||
}
|
||||
|
@ -118,9 +121,9 @@ NSISFunction(AutodialHangup) {
|
|||
EXDLL_INIT();
|
||||
|
||||
if (pInternetAutodialHangup(0))
|
||||
pushstring("success");
|
||||
pushstring(_T("success"));
|
||||
else
|
||||
pushstring("failure");
|
||||
pushstring(_T("failure"));
|
||||
|
||||
FreeWinInet();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ lib_files = Split("""
|
|||
|
||||
api_files = Split("""
|
||||
pluginapi.h
|
||||
nsis_tchar.h
|
||||
#Source/exehead/api.h
|
||||
""")
|
||||
|
||||
|
@ -18,7 +19,7 @@ example = Split("""
|
|||
exdll.dsw
|
||||
exdll_with_unit.dpr
|
||||
exdll-vs2008.sln
|
||||
exdll-vs2008.vcproj
|
||||
exdll-vs2008.vcproj
|
||||
nsis.pas
|
||||
extdll.inc
|
||||
""")
|
||||
|
|
|
@ -5,8 +5,11 @@ HINSTANCE g_hInstance;
|
|||
|
||||
HWND g_hwndParent;
|
||||
|
||||
// To work with Unicode version of NSIS, please use TCHAR-type
|
||||
// functions for accessing the variables and the stack.
|
||||
|
||||
void __declspec(dllexport) myFunction(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop,
|
||||
TCHAR *variables, stack_t **stacktop,
|
||||
extra_parameters *extra)
|
||||
{
|
||||
g_hwndParent=hwndParent;
|
||||
|
@ -23,8 +26,8 @@ void __declspec(dllexport) myFunction(HWND hwndParent, int string_size,
|
|||
|
||||
// do your stuff here
|
||||
{
|
||||
char buf[1024];
|
||||
wsprintf(buf,"$0=%s\n",getuservariable(INST_0));
|
||||
TCHAR buf[1024];
|
||||
wsprintf(buf,_T("$0=%s\n"),getuservariable(INST_0));
|
||||
MessageBox(g_hwndParent,buf,0,MB_OK);
|
||||
}
|
||||
}
|
||||
|
|
214
Contrib/ExDLL/nsis_tchar.h
Normal file
214
Contrib/ExDLL/nsis_tchar.h
Normal file
|
@ -0,0 +1,214 @@
|
|||
/*
|
||||
* nsis_tchar.h
|
||||
*
|
||||
* This file is a part of NSIS.
|
||||
*
|
||||
* Copyright (C) 1999-2007 Nullsoft and Contributors
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty.
|
||||
*
|
||||
* For Unicode support by Jim Park -- 08/30/2007
|
||||
*/
|
||||
|
||||
// Jim Park: Only those we use are listed here.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _UNICODE
|
||||
|
||||
#ifndef _T
|
||||
#define __T(x) L ## x
|
||||
#define _T(x) __T(x)
|
||||
#define _TEXT(x) __T(x)
|
||||
#endif
|
||||
typedef wchar_t TCHAR;
|
||||
typedef wchar_t _TUCHAR;
|
||||
|
||||
// program
|
||||
#define _tmain wmain
|
||||
#define _tWinMain wWinMain
|
||||
#define _tenviron _wenviron
|
||||
#define __targv __wargv
|
||||
|
||||
// printfs
|
||||
#define _ftprintf fwprintf
|
||||
#define _sntprintf _snwprintf
|
||||
#define _stprintf _swprintf
|
||||
#define _tprintf wprintf
|
||||
#define _vftprintf vfwprintf
|
||||
#define _vsntprintf _vsnwprintf
|
||||
#define _vstprintf _vswprintf
|
||||
|
||||
// scanfs
|
||||
#define _tscanf wscanf
|
||||
#define _stscanf swscanf
|
||||
|
||||
// string manipulations
|
||||
#define _tcscat wcscat
|
||||
#define _tcschr wcschr
|
||||
#define _tcsclen wcslen
|
||||
#define _tcscpy wcscpy
|
||||
#define _tcsdup _wcsdup
|
||||
#define _tcslen wcslen
|
||||
#define _tcsnccpy wcsncpy
|
||||
#define _tcsncpy wcsncpy
|
||||
#define _tcsrchr wcsrchr
|
||||
#define _tcsstr wcsstr
|
||||
#define _tcstok wcstok
|
||||
|
||||
// string comparisons
|
||||
#define _tcscmp wcscmp
|
||||
#define _tcsicmp _wcsicmp
|
||||
#define _tcsncicmp _wcsnicmp
|
||||
#define _tcsncmp wcsncmp
|
||||
#define _tcsnicmp _wcsnicmp
|
||||
|
||||
// upper / lower
|
||||
#define _tcslwr _wcslwr
|
||||
#define _tcsupr _wcsupr
|
||||
#define _totlower towlower
|
||||
#define _totupper towupper
|
||||
|
||||
// conversions to numbers
|
||||
#define _tcstoi64 _wcstoi64
|
||||
#define _tcstol wcstol
|
||||
#define _tcstoul wcstoul
|
||||
#define _tstof _wtof
|
||||
#define _tstoi _wtoi
|
||||
#define _tstoi64 _wtoi64
|
||||
#define _ttoi _wtoi
|
||||
#define _ttoi64 _wtoi64
|
||||
#define _ttol _wtol
|
||||
|
||||
// conversion from numbers to strings
|
||||
#define _itot _itow
|
||||
#define _ltot _ltow
|
||||
#define _i64tot _i64tow
|
||||
#define _ui64tot _ui64tow
|
||||
|
||||
// file manipulations
|
||||
#define _tfopen _wfopen
|
||||
#define _topen _wopen
|
||||
#define _tremove _wremove
|
||||
#define _tunlink _wunlink
|
||||
|
||||
// reading and writing to i/o
|
||||
#define _fgettc fgetwc
|
||||
#define _fgetts fgetws
|
||||
#define _fputts fputws
|
||||
#define _gettchar getwchar
|
||||
|
||||
// directory
|
||||
#define _tchdir _wchdir
|
||||
|
||||
// environment
|
||||
#define _tgetenv _wgetenv
|
||||
#define _tsystem _wsystem
|
||||
|
||||
// time
|
||||
#define _tcsftime wcsftime
|
||||
|
||||
#else // ANSI
|
||||
|
||||
#ifndef _T
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
typedef char TCHAR;
|
||||
typedef unsigned char _TUCHAR;
|
||||
|
||||
// program
|
||||
#define _tmain main
|
||||
#define _tWinMain WinMain
|
||||
#define _tenviron environ
|
||||
#define __targv __argv
|
||||
|
||||
// printfs
|
||||
#define _ftprintf fprintf
|
||||
#define _sntprintf _snprintf
|
||||
#define _stprintf sprintf
|
||||
#define _tprintf printf
|
||||
#define _vftprintf vfprintf
|
||||
#define _vsntprintf _vsnprintf
|
||||
#define _vstprintf vsprintf
|
||||
|
||||
// scanfs
|
||||
#define _tscanf scanf
|
||||
#define _stscanf sscanf
|
||||
|
||||
// string manipulations
|
||||
#define _tcscat strcat
|
||||
#define _tcschr strchr
|
||||
#define _tcsclen strlen
|
||||
#define _tcscnlen strnlen
|
||||
#define _tcscpy strcpy
|
||||
#define _tcsdup _strdup
|
||||
#define _tcslen strlen
|
||||
#define _tcsnccpy strncpy
|
||||
#define _tcsrchr strrchr
|
||||
#define _tcsstr strstr
|
||||
#define _tcstok strtok
|
||||
|
||||
// string comparisons
|
||||
#define _tcscmp strcmp
|
||||
#define _tcsicmp _stricmp
|
||||
#define _tcsncmp strncmp
|
||||
#define _tcsncicmp _strnicmp
|
||||
#define _tcsnicmp _strnicmp
|
||||
|
||||
// upper / lower
|
||||
#define _tcslwr _strlwr
|
||||
#define _tcsupr _strupr
|
||||
|
||||
#define _totupper toupper
|
||||
#define _totlower tolower
|
||||
|
||||
// conversions to numbers
|
||||
#define _tcstol strtol
|
||||
#define _tcstoul strtoul
|
||||
#define _tstof atof
|
||||
#define _tstoi atoi
|
||||
#define _tstoi64 _atoi64
|
||||
#define _tstoi64 _atoi64
|
||||
#define _ttoi atoi
|
||||
#define _ttoi64 _atoi64
|
||||
#define _ttol atol
|
||||
|
||||
// conversion from numbers to strings
|
||||
#define _i64tot _i64toa
|
||||
#define _itot _itoa
|
||||
#define _ltot _ltoa
|
||||
#define _ui64tot _ui64toa
|
||||
|
||||
// file manipulations
|
||||
#define _tfopen fopen
|
||||
#define _topen _open
|
||||
#define _tremove remove
|
||||
#define _tunlink _unlink
|
||||
|
||||
// reading and writing to i/o
|
||||
#define _fgettc fgetc
|
||||
#define _fgetts fgets
|
||||
#define _fputts fputs
|
||||
#define _gettchar getchar
|
||||
|
||||
// directory
|
||||
#define _tchdir _chdir
|
||||
|
||||
// environment
|
||||
#define _tgetenv getenv
|
||||
#define _tsystem system
|
||||
|
||||
// time
|
||||
#define _tcsftime strftime
|
||||
|
||||
#endif
|
||||
|
||||
// is functions (the same in Unicode / ANSI)
|
||||
#define _istgraph isgraph
|
||||
#define _istascii __isascii
|
||||
|
||||
#define __TFILE__ _T(__FILE__)
|
||||
#define __TDATE__ _T(__DATE__)
|
||||
#define __TTIME__ _T(__TIME__)
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
unsigned int g_stringsize;
|
||||
stack_t **g_stacktop;
|
||||
char *g_variables;
|
||||
TCHAR *g_variables;
|
||||
|
||||
// utility functions (not required but often useful)
|
||||
|
||||
int NSISCALL popstring(char *str)
|
||||
int NSISCALL popstring(TCHAR *str)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop || !*g_stacktop) return 1;
|
||||
|
@ -19,7 +19,7 @@ int NSISCALL popstring(char *str)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int NSISCALL popstringn(char *str, int maxlen)
|
||||
int NSISCALL popstringn(TCHAR *str, int maxlen)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop || !*g_stacktop) return 1;
|
||||
|
@ -30,7 +30,7 @@ int NSISCALL popstringn(char *str, int maxlen)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void NSISCALL pushstring(const char *str)
|
||||
void NSISCALL pushstring(const TCHAR *str)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop) return;
|
||||
|
@ -40,13 +40,13 @@ void NSISCALL pushstring(const char *str)
|
|||
*g_stacktop=th;
|
||||
}
|
||||
|
||||
char * NSISCALL getuservariable(const int varnum)
|
||||
TCHAR * NSISCALL getuservariable(const int varnum)
|
||||
{
|
||||
if (varnum < 0 || varnum >= __INST_LAST) return NULL;
|
||||
return g_variables+varnum*g_stringsize;
|
||||
}
|
||||
|
||||
void NSISCALL setuservariable(const int varnum, const char *var)
|
||||
void NSISCALL setuservariable(const int varnum, const TCHAR *var)
|
||||
{
|
||||
if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
|
||||
lstrcpyA(g_variables + varnum*g_stringsize, var);
|
||||
|
@ -54,29 +54,29 @@ void NSISCALL setuservariable(const int varnum, const char *var)
|
|||
|
||||
// playing with integers
|
||||
|
||||
int NSISCALL myatoi(const char *s)
|
||||
int NSISCALL myatoi(const TCHAR *s)
|
||||
{
|
||||
int v=0;
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||
if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X')))
|
||||
{
|
||||
s++;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s);
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
else if (c >= 'a' && c <= 'f') c-='a'-10;
|
||||
else if (c >= 'A' && c <= 'F') c-='A'-10;
|
||||
if (c >= _T('0') && c <= _T('9')) c-=_T('0');
|
||||
else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10;
|
||||
else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10;
|
||||
else break;
|
||||
v<<=4;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
|
||||
else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0'))
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s);
|
||||
if (c >= '0' && c <= '7') c-='0';
|
||||
if (c >= _T('0') && c <= _T('7')) c-=_T('0');
|
||||
else break;
|
||||
v<<=3;
|
||||
v+=c;
|
||||
|
@ -85,10 +85,10 @@ int NSISCALL myatoi(const char *s)
|
|||
else
|
||||
{
|
||||
int sign=0;
|
||||
if (*s == '-') sign++; else s--;
|
||||
if (*s == _T('-')) sign++; else s--;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s) - '0';
|
||||
int c=*(++s) - _T('0');
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
|
@ -99,14 +99,14 @@ int NSISCALL myatoi(const char *s)
|
|||
return v;
|
||||
}
|
||||
|
||||
unsigned NSISCALL myatou(const char *s)
|
||||
unsigned NSISCALL myatou(const TCHAR *s)
|
||||
{
|
||||
unsigned int v=0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned int c=*s++;
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
if (c >= _T('0') && c <= _T('9')) c-=_T('0');
|
||||
else break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
|
@ -114,29 +114,29 @@ unsigned NSISCALL myatou(const char *s)
|
|||
return v;
|
||||
}
|
||||
|
||||
int NSISCALL myatoi_or(const char *s)
|
||||
int NSISCALL myatoi_or(const TCHAR *s)
|
||||
{
|
||||
int v=0;
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||
if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X')))
|
||||
{
|
||||
s++;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s);
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
else if (c >= 'a' && c <= 'f') c-='a'-10;
|
||||
else if (c >= 'A' && c <= 'F') c-='A'-10;
|
||||
if (c >= _T('0') && c <= _T('9')) c-=_T('0');
|
||||
else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10;
|
||||
else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10;
|
||||
else break;
|
||||
v<<=4;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
|
||||
else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0'))
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s);
|
||||
if (c >= '0' && c <= '7') c-='0';
|
||||
if (c >= _T('0') && c <= _T('7')) c-=_T('0');
|
||||
else break;
|
||||
v<<=3;
|
||||
v+=c;
|
||||
|
@ -145,10 +145,10 @@ int NSISCALL myatoi_or(const char *s)
|
|||
else
|
||||
{
|
||||
int sign=0;
|
||||
if (*s == '-') sign++; else s--;
|
||||
if (*s == _T('-')) sign++; else s--;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s) - '0';
|
||||
int c=*(++s) - _T('0');
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
|
@ -157,7 +157,7 @@ int NSISCALL myatoi_or(const char *s)
|
|||
}
|
||||
|
||||
// Support for simple ORed expressions
|
||||
if (*s == '|')
|
||||
if (*s == _T('|'))
|
||||
{
|
||||
v |= myatoi_or(s+1);
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ int NSISCALL myatoi_or(const char *s)
|
|||
|
||||
int NSISCALL popint()
|
||||
{
|
||||
char buf[128];
|
||||
TCHAR buf[128];
|
||||
if (popstringn(buf,sizeof(buf)))
|
||||
return 0;
|
||||
|
||||
|
@ -176,7 +176,7 @@ int NSISCALL popint()
|
|||
|
||||
int NSISCALL popint_or()
|
||||
{
|
||||
char buf[128];
|
||||
TCHAR buf[128];
|
||||
if (popstringn(buf,sizeof(buf)))
|
||||
return 0;
|
||||
|
||||
|
@ -185,7 +185,7 @@ int NSISCALL popint_or()
|
|||
|
||||
void NSISCALL pushint(int value)
|
||||
{
|
||||
char buffer[1024];
|
||||
wsprintf(buffer, "%d", value);
|
||||
TCHAR buffer[1024];
|
||||
wsprintf(buffer, _T("%d"), value);
|
||||
pushstring(buffer);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "api.h"
|
||||
#include "nsis_tchar.h"
|
||||
|
||||
#ifndef NSISCALL
|
||||
# define NSISCALL __stdcall
|
||||
|
@ -18,7 +19,7 @@ extern "C" {
|
|||
|
||||
typedef struct _stack_t {
|
||||
struct _stack_t *next;
|
||||
char text[1]; // this should be the length of string_size
|
||||
TCHAR text[1]; // this should be the length of string_size
|
||||
} stack_t;
|
||||
|
||||
enum
|
||||
|
@ -53,19 +54,25 @@ __INST_LAST
|
|||
|
||||
extern unsigned int g_stringsize;
|
||||
extern stack_t **g_stacktop;
|
||||
extern char *g_variables;
|
||||
extern TCHAR *g_variables;
|
||||
|
||||
int NSISCALL popstring(char *str); // 0 on success, 1 on empty stack
|
||||
int NSISCALL popstringn(char *str, int maxlen); // with length limit, pass 0 for g_stringsize
|
||||
int NSISCALL popstring(TCHAR *str); // 0 on success, 1 on empty stack
|
||||
int NSISCALL popstringn(TCHAR *str, int maxlen); // with length limit, pass 0 for g_stringsize
|
||||
int NSISCALL popint(); // pops an integer
|
||||
int NSISCALL popint_or(); // with support for or'ing (2|4|8)
|
||||
int NSISCALL myatoi(const char *s); // converts a string to an integer
|
||||
unsigned NSISCALL myatou(const char *s); // converts a string to an unsigned integer, decimal only
|
||||
int NSISCALL myatoi_or(const char *s); // with support for or'ing (2|4|8)
|
||||
void NSISCALL pushstring(const char *str);
|
||||
int NSISCALL myatoi(const TCHAR *s); // converts a string to an integer
|
||||
unsigned NSISCALL myatou(const TCHAR *s); // converts a string to an unsigned integer, decimal only
|
||||
int NSISCALL myatoi_or(const TCHAR *s); // with support for or'ing (2|4|8)
|
||||
void NSISCALL pushstring(const TCHAR *str);
|
||||
void NSISCALL pushint(int value);
|
||||
char * NSISCALL getuservariable(const int varnum);
|
||||
void NSISCALL setuservariable(const int varnum, const char *var);
|
||||
TCHAR * NSISCALL getuservariable(const int varnum);
|
||||
void NSISCALL setuservariable(const int varnum, const TCHAR *var);
|
||||
|
||||
// ANSI defs
|
||||
|
||||
#define PopStringA(x) popstring(x)
|
||||
#define PushStringA(x) pushstring(x)
|
||||
#define SetUserVariableA(x,y) setuservariable(x,y)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
*
|
||||
* See Readme.html for documentation and license
|
||||
*
|
||||
* Unicode support by Jim Park -- 08/01/2007
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
#include <windows.h>
|
||||
|
@ -34,9 +36,9 @@ void WINAPI FREE(void *d) { if (d) GlobalFree((HGLOBAL)d); }
|
|||
#define stricmp(x,y) lstrcmpi(x,y)
|
||||
//#define abs(x) ((x) < 0 ? -(x) : (x))
|
||||
|
||||
char *WINAPI STRDUP(const char *c)
|
||||
TCHAR *WINAPI STRDUP(const TCHAR *c)
|
||||
{
|
||||
char *t=(char*)MALLOC(lstrlen(c)+1);
|
||||
TCHAR *t=(TCHAR*)MALLOC((lstrlen(c)+1)*sizeof(TCHAR));
|
||||
return lstrcpy(t,c);
|
||||
}
|
||||
|
||||
|
@ -111,27 +113,27 @@ char *WINAPI STRDUP(const char *c)
|
|||
#define FLAG_FOCUS 0x10000000 // Controls that can receive focus
|
||||
|
||||
struct TableEntry {
|
||||
char *pszName;
|
||||
TCHAR *pszName;
|
||||
int nValue;
|
||||
};
|
||||
|
||||
int WINAPI LookupToken(TableEntry*, char*);
|
||||
int WINAPI LookupTokens(TableEntry*, char*);
|
||||
int WINAPI LookupToken(TableEntry*, TCHAR*);
|
||||
int WINAPI LookupTokens(TableEntry*, TCHAR*);
|
||||
|
||||
void WINAPI ConvertNewLines(char *str);
|
||||
void WINAPI ConvertNewLines(TCHAR *str);
|
||||
|
||||
// all allocated buffers must be first in the struct
|
||||
// when adding more allocated buffers to FieldType, don't forget to change this define
|
||||
#define FIELD_BUFFERS 6
|
||||
struct FieldType {
|
||||
char *pszText;
|
||||
char *pszState;
|
||||
char *pszRoot;
|
||||
TCHAR *pszText;
|
||||
TCHAR *pszState;
|
||||
TCHAR *pszRoot;
|
||||
|
||||
char *pszListItems;
|
||||
char *pszFilter;
|
||||
TCHAR *pszListItems;
|
||||
TCHAR *pszFilter;
|
||||
|
||||
char *pszValidateText;
|
||||
TCHAR *pszValidateText;
|
||||
int nMinLength;
|
||||
int nMaxLength;
|
||||
|
||||
|
@ -147,7 +149,7 @@ struct FieldType {
|
|||
HANDLE hImage; // this is used by image/icon field to save the handle to the image
|
||||
|
||||
int nField; // field number in INI file
|
||||
char *pszHwndEntry; // "HWND" or "HWND2"
|
||||
TCHAR *pszHwndEntry; // "HWND" or "HWND2"
|
||||
|
||||
long wndProc;
|
||||
};
|
||||
|
@ -156,7 +158,7 @@ struct FieldType {
|
|||
// use a value larger than MAX_PATH to prevent need for excessive growing.
|
||||
#define BUFFER_SIZE 8192 // 8kb of mem is max char count in multiedit
|
||||
|
||||
char szBrowseButtonCaption[] = "...";
|
||||
TCHAR szBrowseButtonCaption[] = _T("...");
|
||||
|
||||
HWND hConfigWindow = NULL;
|
||||
HWND hMainWindow = NULL;
|
||||
|
@ -168,11 +170,11 @@ HINSTANCE m_hInstance = NULL;
|
|||
|
||||
struct _stack_t *pFilenameStackEntry = NULL;
|
||||
|
||||
char *pszFilename = NULL;
|
||||
char *pszTitle = NULL;
|
||||
char *pszCancelButtonText = NULL;
|
||||
char *pszNextButtonText = NULL;
|
||||
char *pszBackButtonText = NULL;
|
||||
TCHAR *pszFilename = NULL;
|
||||
TCHAR *pszTitle = NULL;
|
||||
TCHAR *pszCancelButtonText = NULL;
|
||||
TCHAR *pszNextButtonText = NULL;
|
||||
TCHAR *pszBackButtonText = NULL;
|
||||
|
||||
int bBackEnabled = FALSE;
|
||||
int bCancelEnabled = FALSE; // by ORTIM: 13-August-2002
|
||||
|
@ -237,8 +239,8 @@ bool INLINE ValidateFields() {
|
|||
if (((pField->nMaxLength > 0) && (nLength > pField->nMaxLength)) ||
|
||||
((pField->nMinLength > 0) && (nLength < pField->nMinLength))) {
|
||||
if (pField->pszValidateText) {
|
||||
char szTitle[1024];
|
||||
GetWindowText(hMainWindow, szTitle, sizeof(szTitle));
|
||||
TCHAR szTitle[1024];
|
||||
GetWindowText(hMainWindow, szTitle, _countof(szTitle));
|
||||
MessageBox(hConfigWindow, pField->pszValidateText, szTitle, MB_OK|MB_ICONWARNING);
|
||||
}
|
||||
mySetFocus(pField->hwnd);
|
||||
|
@ -251,9 +253,9 @@ bool INLINE ValidateFields() {
|
|||
}
|
||||
|
||||
bool WINAPI SaveSettings(void) {
|
||||
static char szField[25];
|
||||
static TCHAR szField[25];
|
||||
int nBufLen = BUFFER_SIZE;
|
||||
char *pszBuffer = (char*)MALLOC(nBufLen);
|
||||
TCHAR *pszBuffer = (TCHAR*)MALLOC(nBufLen*sizeof(TCHAR));
|
||||
if (!pszBuffer) return false;
|
||||
|
||||
int nIdx;
|
||||
|
@ -271,7 +273,7 @@ bool WINAPI SaveSettings(void) {
|
|||
|
||||
case FIELD_CHECKBOX:
|
||||
case FIELD_RADIOBUTTON:
|
||||
wsprintf(pszBuffer, "%d", !!mySendMessage(hwnd, BM_GETCHECK, 0, 0));
|
||||
wsprintf(pszBuffer, _T("%d"), !!mySendMessage(hwnd, BM_GETCHECK, 0, 0));
|
||||
break;
|
||||
|
||||
case FIELD_LISTBOX:
|
||||
|
@ -285,17 +287,17 @@ bool WINAPI SaveSettings(void) {
|
|||
if (nLength > nBufLen) {
|
||||
FREE(pszBuffer);
|
||||
nBufLen = nLength;
|
||||
pszBuffer = (char*)MALLOC(nBufLen);
|
||||
pszBuffer = (TCHAR*)MALLOC(nBufLen*sizeof(TCHAR));
|
||||
if (!pszBuffer) return false;
|
||||
}
|
||||
char *pszItem = (char*)MALLOC(nBufLen);
|
||||
TCHAR *pszItem = (TCHAR*)MALLOC(nBufLen*sizeof(TCHAR));
|
||||
if (!pszItem) return false;
|
||||
|
||||
*pszBuffer = '\0';
|
||||
*pszBuffer = _T('\0');
|
||||
int nNumItems = mySendMessage(hwnd, LB_GETCOUNT, 0, 0);
|
||||
for (int nIdx2 = 0; nIdx2 < nNumItems; nIdx2++) {
|
||||
if (mySendMessage(hwnd, LB_GETSEL, nIdx2, 0) > 0) {
|
||||
if (*pszBuffer) lstrcat(pszBuffer, "|");
|
||||
if (*pszBuffer) lstrcat(pszBuffer, _T("|"));
|
||||
mySendMessage(hwnd, LB_GETTEXT, (WPARAM)nIdx2, (LPARAM)pszItem);
|
||||
lstrcat(pszBuffer, pszItem);
|
||||
}
|
||||
|
@ -315,35 +317,38 @@ bool WINAPI SaveSettings(void) {
|
|||
FREE(pszBuffer);
|
||||
// add a bit extra so we do this less often
|
||||
nBufLen = nLength + 20;
|
||||
pszBuffer = (char*)MALLOC(nBufLen);
|
||||
pszBuffer = (TCHAR*)MALLOC(nBufLen*sizeof(TCHAR));
|
||||
if (!pszBuffer) return false;
|
||||
}
|
||||
*pszBuffer='"';
|
||||
*pszBuffer=_T('"');
|
||||
GetWindowText(hwnd, pszBuffer+1, nBufLen-1);
|
||||
pszBuffer[nLength+1]='"';
|
||||
pszBuffer[nLength+2]='\0';
|
||||
pszBuffer[nLength+1]=_T('"');
|
||||
pszBuffer[nLength+2]=_T('\0');
|
||||
|
||||
if (pField->nType == FIELD_TEXT && (pField->nFlags & FLAG_MULTILINE))
|
||||
{
|
||||
char *pszBuf2 = (char*)MALLOC(nBufLen*2); // double the size, consider the worst case, all chars are \r\n
|
||||
char *p1, *p2;
|
||||
TCHAR *pszBuf2 = (TCHAR*)MALLOC(nBufLen*2*sizeof(TCHAR)); // double the size, consider the worst case, all chars are \r\n
|
||||
TCHAR *p1, *p2;
|
||||
for (p1 = pszBuffer, p2 = pszBuf2; *p1; p1 = CharNext(p1), p2 = CharNext(p2))
|
||||
{
|
||||
switch (*p1) {
|
||||
case '\t':
|
||||
case _T('\t'):
|
||||
*(LPWORD)p2 = CHAR2_TO_WORD('\\', 't');
|
||||
p2++;
|
||||
break;
|
||||
case '\n':
|
||||
case _T('\n'):
|
||||
*(LPWORD)p2 = CHAR2_TO_WORD('\\', 'n');
|
||||
p2++;
|
||||
break;
|
||||
case '\r':
|
||||
case _T('\r'):
|
||||
*(LPWORD)p2 = CHAR2_TO_WORD('\\', 'r');
|
||||
p2++;
|
||||
break;
|
||||
case '\\':
|
||||
case _T('\\'):
|
||||
*p2++ = '\\';
|
||||
// Jim Park: used to be p2++ but that's a bug that works because
|
||||
// CharNext()'s behavior at terminating null char. But still
|
||||
// definitely, unsafe.
|
||||
default:
|
||||
lstrcpyn(p2, p1, CharNext(p1) - p1 + 1);
|
||||
break;
|
||||
|
@ -357,13 +362,13 @@ bool WINAPI SaveSettings(void) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
wsprintf(szField, "Field %d", CurrField);
|
||||
WritePrivateProfileString(szField, "State", pszBuffer, pszFilename);
|
||||
wsprintf(szField, _T("Field %d"), CurrField);
|
||||
WritePrivateProfileString(szField, _T("State"), pszBuffer, pszFilename);
|
||||
}
|
||||
|
||||
// Tell NSIS which control was activated, if any
|
||||
wsprintf(pszBuffer, "%d", g_NotifyField);
|
||||
WritePrivateProfileString("Settings", "State", pszBuffer, pszFilename);
|
||||
wsprintf(pszBuffer, _T("%d"), g_NotifyField);
|
||||
WritePrivateProfileString(_T("Settings"), _T("State"), pszBuffer, pszFilename);
|
||||
|
||||
FREE(pszBuffer);
|
||||
|
||||
|
@ -372,20 +377,20 @@ bool WINAPI SaveSettings(void) {
|
|||
|
||||
#define BROWSE_WIDTH 15
|
||||
|
||||
static char szResult[BUFFER_SIZE];
|
||||
char *pszAppName;
|
||||
static TCHAR szResult[BUFFER_SIZE];
|
||||
TCHAR *pszAppName;
|
||||
|
||||
DWORD WINAPI myGetProfileString(LPCTSTR lpKeyName)
|
||||
{
|
||||
*szResult = '\0';
|
||||
return GetPrivateProfileString(pszAppName, lpKeyName, "", szResult, BUFFER_SIZE, pszFilename);
|
||||
*szResult = _T('\0');
|
||||
return GetPrivateProfileString(pszAppName, lpKeyName, _T(""), szResult, BUFFER_SIZE, pszFilename);
|
||||
}
|
||||
|
||||
char * WINAPI myGetProfileStringDup(LPCTSTR lpKeyName)
|
||||
TCHAR * WINAPI myGetProfileStringDup(LPCTSTR lpKeyName)
|
||||
{
|
||||
int nSize = myGetProfileString(lpKeyName);
|
||||
if (nSize)
|
||||
return strdup(szResult);
|
||||
return strdup(szResult); // uses STRDUP
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
@ -396,25 +401,25 @@ UINT WINAPI myGetProfileInt(LPCTSTR lpKeyName, INT nDefault)
|
|||
}
|
||||
|
||||
int WINAPI ReadSettings(void) {
|
||||
static char szField[25];
|
||||
static TCHAR szField[25];
|
||||
int nIdx, nCtrlIdx;
|
||||
|
||||
pszAppName = "Settings";
|
||||
pszTitle = myGetProfileStringDup("Title");
|
||||
pszCancelButtonText = myGetProfileStringDup("CancelButtonText");
|
||||
pszNextButtonText = myGetProfileStringDup("NextButtonText");
|
||||
pszBackButtonText = myGetProfileStringDup("BackButtonText");
|
||||
pszAppName = _T("Settings");
|
||||
pszTitle = myGetProfileStringDup(_T("Title"));
|
||||
pszCancelButtonText = myGetProfileStringDup(_T("CancelButtonText"));
|
||||
pszNextButtonText = myGetProfileStringDup(_T("NextButtonText"));
|
||||
pszBackButtonText = myGetProfileStringDup(_T("BackButtonText"));
|
||||
|
||||
nNumFields = myGetProfileInt("NumFields", 0);
|
||||
nNumFields = myGetProfileInt(_T("NumFields"), 0);
|
||||
|
||||
nRectId = myGetProfileInt("Rect", DEFAULT_RECT);
|
||||
nRectId = myGetProfileInt(_T("Rect"), DEFAULT_RECT);
|
||||
|
||||
bBackEnabled = myGetProfileInt("BackEnabled", -1);
|
||||
bBackEnabled = myGetProfileInt(_T("BackEnabled"), -1);
|
||||
// by ORTIM: 13-August-2002
|
||||
bCancelEnabled = myGetProfileInt("CancelEnabled", -1);
|
||||
bCancelShow = myGetProfileInt("CancelShow", -1);
|
||||
bCancelEnabled = myGetProfileInt(_T("CancelEnabled"), -1);
|
||||
bCancelShow = myGetProfileInt(_T("CancelShow"), -1);
|
||||
|
||||
bRTL = myGetProfileInt("RTL", 0);
|
||||
bRTL = myGetProfileInt(_T("RTL"), 0);
|
||||
|
||||
if (nNumFields > 0) {
|
||||
// make this twice as large for the worst case that every control is a browse button.
|
||||
|
@ -426,117 +431,117 @@ int WINAPI ReadSettings(void) {
|
|||
for (nIdx = 0, nCtrlIdx = 0; nCtrlIdx < nNumFields; nCtrlIdx++, nIdx++) {
|
||||
// Control types
|
||||
static TableEntry TypeTable[] = {
|
||||
{ "LABEL", FIELD_LABEL },
|
||||
{ "TEXT", FIELD_TEXT },
|
||||
{ "PASSWORD", FIELD_TEXT },
|
||||
{ "LISTBOX", FIELD_LISTBOX },
|
||||
{ "COMBOBOX", FIELD_COMBOBOX },
|
||||
{ "DROPLIST", FIELD_COMBOBOX },
|
||||
{ "FILEREQUEST", FIELD_FILEREQUEST },
|
||||
{ "DIRREQUEST", FIELD_DIRREQUEST },
|
||||
{ "CHECKBOX", FIELD_CHECKBOX },
|
||||
{ "RADIOBUTTON", FIELD_RADIOBUTTON },
|
||||
{ "ICON", FIELD_ICON },
|
||||
{ "BITMAP", FIELD_BITMAP },
|
||||
{ "GROUPBOX", FIELD_GROUPBOX },
|
||||
{ _T("LABEL"), FIELD_LABEL },
|
||||
{ _T("TEXT"), FIELD_TEXT },
|
||||
{ _T("PASSWORD"), FIELD_TEXT },
|
||||
{ _T("LISTBOX"), FIELD_LISTBOX },
|
||||
{ _T("COMBOBOX"), FIELD_COMBOBOX },
|
||||
{ _T("DROPLIST"), FIELD_COMBOBOX },
|
||||
{ _T("FILEREQUEST"), FIELD_FILEREQUEST },
|
||||
{ _T("DIRREQUEST"), FIELD_DIRREQUEST },
|
||||
{ _T("CHECKBOX"), FIELD_CHECKBOX },
|
||||
{ _T("RADIOBUTTON"), FIELD_RADIOBUTTON },
|
||||
{ _T("ICON"), FIELD_ICON },
|
||||
{ _T("BITMAP"), FIELD_BITMAP },
|
||||
{ _T("GROUPBOX"), FIELD_GROUPBOX },
|
||||
#ifdef IO_ENABLE_LINK
|
||||
{ "LINK", FIELD_LINK },
|
||||
{ _T("LINK"), FIELD_LINK },
|
||||
#else
|
||||
{ "LINK", FIELD_LABEL },
|
||||
{ _T("LINK"), FIELD_LABEL },
|
||||
#endif
|
||||
{ "BUTTON", FIELD_BUTTON },
|
||||
{ "HLINE", FIELD_HLINE },
|
||||
{ "VLINE", FIELD_VLINE },
|
||||
{ NULL, 0 }
|
||||
{ _T("BUTTON"), FIELD_BUTTON },
|
||||
{ _T("HLINE"), FIELD_HLINE },
|
||||
{ _T("VLINE"), FIELD_VLINE },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
// Control flags
|
||||
static TableEntry FlagTable[] = {
|
||||
{ "NOTIFY", LBS_NOTIFY },
|
||||
{ "WARN_IF_EXIST", OFN_OVERWRITEPROMPT },
|
||||
{ "FILE_HIDEREADONLY", OFN_HIDEREADONLY },
|
||||
{ "MULTISELECT", LBS_MULTIPLESEL },
|
||||
{ "READONLY", FLAG_READONLY },
|
||||
{ "RIGHT", BS_LEFTTEXT },
|
||||
{ "PASSWORD", FLAG_PASSWORD },
|
||||
{ "ONLY_NUMBERS", FLAG_ONLYNUMBERS },
|
||||
{ "MULTILINE", FLAG_MULTILINE },
|
||||
{ "NOWORDWRAP", FLAG_NOWORDWRAP },
|
||||
{ "WANTRETURN", FLAG_WANTRETURN },
|
||||
{ "EXTENDEDSELCT", LBS_EXTENDEDSEL },
|
||||
{ "PATH_MUST_EXIST", OFN_PATHMUSTEXIST },
|
||||
{ "FILE_MUST_EXIST", OFN_FILEMUSTEXIST },
|
||||
{ "PROMPT_CREATE", OFN_CREATEPROMPT },
|
||||
{ "DROPLIST", FLAG_DROPLIST },
|
||||
{ "RESIZETOFIT", FLAG_RESIZETOFIT },
|
||||
{ "NOTABSTOP", WS_TABSTOP },
|
||||
{ "GROUP", WS_GROUP },
|
||||
{ "REQ_SAVE", FLAG_SAVEAS },
|
||||
{ "FILE_EXPLORER", OFN_EXPLORER },
|
||||
{ "HSCROLL", WS_HSCROLL },
|
||||
{ "VSCROLL", WS_VSCROLL },
|
||||
{ "DISABLED", WS_DISABLED },
|
||||
{ "TRANSPARENT", TRANSPARENT_BMP },
|
||||
{ "FOCUS", FLAG_FOCUS },
|
||||
{ NULL, 0 }
|
||||
{ _T("NOTIFY"), LBS_NOTIFY },
|
||||
{ _T("WARN_IF_EXIST"), OFN_OVERWRITEPROMPT },
|
||||
{ _T("FILE_HIDEREADONLY"), OFN_HIDEREADONLY },
|
||||
{ _T("MULTISELECT"), LBS_MULTIPLESEL },
|
||||
{ _T("READONLY"), FLAG_READONLY },
|
||||
{ _T("RIGHT"), BS_LEFTTEXT },
|
||||
{ _T("PASSWORD"), FLAG_PASSWORD },
|
||||
{ _T("ONLY_NUMBERS"), FLAG_ONLYNUMBERS },
|
||||
{ _T("MULTILINE"), FLAG_MULTILINE },
|
||||
{ _T("NOWORDWRAP"), FLAG_NOWORDWRAP },
|
||||
{ _T("WANTRETURN"), FLAG_WANTRETURN },
|
||||
{ _T("EXTENDEDSELCT"), LBS_EXTENDEDSEL },
|
||||
{ _T("PATH_MUST_EXIST"), OFN_PATHMUSTEXIST },
|
||||
{ _T("FILE_MUST_EXIST"), OFN_FILEMUSTEXIST },
|
||||
{ _T("PROMPT_CREATE"), OFN_CREATEPROMPT },
|
||||
{ _T("DROPLIST"), FLAG_DROPLIST },
|
||||
{ _T("RESIZETOFIT"), FLAG_RESIZETOFIT },
|
||||
{ _T("NOTABSTOP"), WS_TABSTOP },
|
||||
{ _T("GROUP"), WS_GROUP },
|
||||
{ _T("REQ_SAVE"), FLAG_SAVEAS },
|
||||
{ _T("FILE_EXPLORER"), OFN_EXPLORER },
|
||||
{ _T("HSCROLL"), WS_HSCROLL },
|
||||
{ _T("VSCROLL"), WS_VSCROLL },
|
||||
{ _T("DISABLED"), WS_DISABLED },
|
||||
{ _T("TRANSPARENT"), TRANSPARENT_BMP },
|
||||
{ _T("FOCUS"), FLAG_FOCUS },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
FieldType *pField = pFields + nIdx;
|
||||
|
||||
pField->nField = nCtrlIdx + 1;
|
||||
pField->pszHwndEntry = "HWND";
|
||||
pField->pszHwndEntry = _T("HWND");
|
||||
|
||||
wsprintf(szField, "Field %d", nCtrlIdx + 1);
|
||||
wsprintf(szField, _T("Field %d"), nCtrlIdx + 1);
|
||||
pszAppName = szField;
|
||||
|
||||
// Get the control type
|
||||
myGetProfileString("TYPE");
|
||||
myGetProfileString(_T("TYPE"));
|
||||
pField->nType = LookupToken(TypeTable, szResult);
|
||||
if (pField->nType == FIELD_INVALID)
|
||||
continue;
|
||||
|
||||
// Lookup flags associated with the control type
|
||||
pField->nFlags = LookupToken(FlagTable, szResult);
|
||||
myGetProfileString("Flags");
|
||||
myGetProfileString(_T("Flags"));
|
||||
pField->nFlags |= LookupTokens(FlagTable, szResult);
|
||||
|
||||
// pszState must not be NULL!
|
||||
myGetProfileString("State");
|
||||
pField->pszState = strdup(szResult);
|
||||
myGetProfileString(_T("State"));
|
||||
pField->pszState = strdup(szResult); // uses STRDUP
|
||||
|
||||
// ListBox items list
|
||||
{
|
||||
int nResult = myGetProfileString("ListItems");
|
||||
int nResult = myGetProfileString(_T("ListItems"));
|
||||
if (nResult) {
|
||||
// add an extra | character to the end to simplify the loop where we add the items.
|
||||
pField->pszListItems = (char*)MALLOC(nResult + 2);
|
||||
strcpy(pField->pszListItems, szResult);
|
||||
pField->pszListItems[nResult] = '|';
|
||||
pField->pszListItems[nResult + 1] = '\0';
|
||||
pField->pszListItems = (TCHAR*)MALLOC((nResult + 2)*sizeof(TCHAR));
|
||||
lstrcpy(pField->pszListItems, szResult);
|
||||
pField->pszListItems[nResult] = _T('|');
|
||||
pField->pszListItems[nResult + 1] = _T('\0');
|
||||
}
|
||||
}
|
||||
|
||||
// Label Text - convert newline
|
||||
pField->pszText = myGetProfileStringDup("TEXT");
|
||||
pField->pszText = myGetProfileStringDup(_T("TEXT"));
|
||||
if (pField->nType == FIELD_LABEL || pField->nType == FIELD_LINK)
|
||||
ConvertNewLines(pField->pszText);
|
||||
|
||||
// Dir request - root folder
|
||||
pField->pszRoot = myGetProfileStringDup("ROOT");
|
||||
pField->pszRoot = myGetProfileStringDup(_T("ROOT"));
|
||||
|
||||
// ValidateText - convert newline
|
||||
pField->pszValidateText = myGetProfileStringDup("ValidateText");
|
||||
pField->pszValidateText = myGetProfileStringDup(_T("ValidateText"));
|
||||
ConvertNewLines(pField->pszValidateText);
|
||||
|
||||
{
|
||||
int nResult = GetPrivateProfileString(szField, "Filter", "All Files|*.*", szResult, sizeof(szResult), pszFilename);
|
||||
int nResult = GetPrivateProfileString(szField, _T("Filter"), _T("All Files|*.*"), szResult, _countof(szResult), pszFilename);
|
||||
if (nResult) {
|
||||
// Convert the filter to the format required by Windows: NULL after each
|
||||
// item followed by a terminating NULL
|
||||
pField->pszFilter = (char*)MALLOC(nResult + 2);
|
||||
strcpy(pField->pszFilter, szResult);
|
||||
char *pszPos = pField->pszFilter;
|
||||
pField->pszFilter = (TCHAR*)MALLOC((nResult + 2)*sizeof(TCHAR));
|
||||
lstrcpy(pField->pszFilter, szResult);
|
||||
TCHAR *pszPos = pField->pszFilter;
|
||||
while (*pszPos)
|
||||
{
|
||||
if (*pszPos == '|')
|
||||
if (*pszPos == _T('|'))
|
||||
*pszPos++ = 0;
|
||||
else
|
||||
pszPos = CharNext(pszPos);
|
||||
|
@ -544,15 +549,15 @@ int WINAPI ReadSettings(void) {
|
|||
}
|
||||
}
|
||||
|
||||
pField->rect.left = myGetProfileInt("LEFT", 0);
|
||||
pField->rect.top = myGetProfileInt("TOP", 0);
|
||||
pField->rect.right = myGetProfileInt("RIGHT", 0);
|
||||
pField->rect.bottom = myGetProfileInt("BOTTOM", 0);
|
||||
pField->nMinLength = myGetProfileInt("MinLen", 0);
|
||||
pField->nMaxLength = myGetProfileInt("MaxLen", 0);
|
||||
pField->rect.left = myGetProfileInt(_T("LEFT"), 0);
|
||||
pField->rect.top = myGetProfileInt(_T("TOP"), 0);
|
||||
pField->rect.right = myGetProfileInt(_T("RIGHT"), 0);
|
||||
pField->rect.bottom = myGetProfileInt(_T("BOTTOM"), 0);
|
||||
pField->nMinLength = myGetProfileInt(_T("MinLen"), 0);
|
||||
pField->nMaxLength = myGetProfileInt(_T("MaxLen"), 0);
|
||||
|
||||
// Text color for LINK control, default is pure blue
|
||||
pField->hImage = (HANDLE)myGetProfileInt("TxtColor", RGB(0,0,255));
|
||||
pField->hImage = (HANDLE)myGetProfileInt(_T("TxtColor"), RGB(0,0,255));
|
||||
|
||||
pField->nControlID = 1200 + nIdx;
|
||||
if (pField->nType == FIELD_FILEREQUEST || pField->nType == FIELD_DIRREQUEST)
|
||||
|
@ -568,7 +573,7 @@ int WINAPI ReadSettings(void) {
|
|||
pNewField->rect.top = pField->rect.top;
|
||||
pField->rect.right = pNewField->rect.left - 3;
|
||||
pNewField->nField = nCtrlIdx + 1;
|
||||
pNewField->pszHwndEntry = "HWND2";
|
||||
pNewField->pszHwndEntry = _T("HWND2");
|
||||
nNumFields++;
|
||||
nIdx++;
|
||||
}
|
||||
|
@ -605,7 +610,7 @@ LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify)
|
|||
|
||||
FieldType *pField = pFields + nIdx;
|
||||
|
||||
char szBrowsePath[MAX_PATH];
|
||||
TCHAR szBrowsePath[MAX_PATH];
|
||||
|
||||
switch (pField->nType) {
|
||||
case FIELD_FILEREQUEST: {
|
||||
|
@ -615,10 +620,10 @@ LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify)
|
|||
ofn.hwndOwner = hConfigWindow;
|
||||
ofn.lpstrFilter = pField->pszFilter;
|
||||
ofn.lpstrFile = szBrowsePath;
|
||||
ofn.nMaxFile = sizeof(szBrowsePath);
|
||||
ofn.nMaxFile = _countof(szBrowsePath);
|
||||
ofn.Flags = pField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER);
|
||||
|
||||
GetWindowText(pField->hwnd, szBrowsePath, sizeof(szBrowsePath));
|
||||
GetWindowText(pField->hwnd, szBrowsePath, _countof(szBrowsePath));
|
||||
|
||||
tryagain:
|
||||
GetCurrentDirectory(BUFFER_SIZE, szResult); // save working dir
|
||||
|
@ -629,7 +634,7 @@ LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify)
|
|||
break;
|
||||
}
|
||||
else if (szBrowsePath[0] && CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
|
||||
szBrowsePath[0] = '\0';
|
||||
szBrowsePath[0] = _T('\0');
|
||||
goto tryagain;
|
||||
}
|
||||
|
||||
|
@ -880,17 +885,17 @@ int WINAPI NumbersOnlyPasteWndProc(HWND hWin, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
|
||||
if (hData)
|
||||
{
|
||||
char *lpData = (char *) GlobalLock(hData);
|
||||
TCHAR *lpData = (TCHAR *) GlobalLock(hData);
|
||||
if (lpData)
|
||||
{
|
||||
int iLen = lstrlen(lpData);
|
||||
char *lpFilteredData = (char *) MALLOC(iLen + 1);
|
||||
TCHAR *lpFilteredData = (TCHAR *) MALLOC((iLen + 1)*sizeof(TCHAR));
|
||||
|
||||
if (lpFilteredData)
|
||||
{
|
||||
for (int i = 0, j = 0; i < iLen; i++)
|
||||
{
|
||||
if (lpData[i] >= '0' && lpData[i] <= '9')
|
||||
if (lpData[i] >= _T('0') && lpData[i] <= _T('9'))
|
||||
{
|
||||
lpFilteredData[j] = lpData[i];
|
||||
j++;
|
||||
|
@ -926,14 +931,14 @@ int WINAPI createCfgDlg()
|
|||
if (!mainwnd)
|
||||
{
|
||||
popstring(NULL);
|
||||
pushstring("error finding mainwnd");
|
||||
pushstring(_T("error finding mainwnd"));
|
||||
return 1; // cannot be used in silent mode unfortunately.
|
||||
}
|
||||
|
||||
if (!g_stacktop || !*g_stacktop || !(pszFilename = (*g_stacktop)->text) || !pszFilename[0] || !ReadSettings())
|
||||
{
|
||||
popstring(NULL);
|
||||
pushstring("error finding config");
|
||||
pushstring(_T("error finding config"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -941,7 +946,7 @@ int WINAPI createCfgDlg()
|
|||
if (!childwnd)
|
||||
{
|
||||
popstring(NULL);
|
||||
pushstring("error finding childwnd");
|
||||
pushstring(_T("error finding childwnd"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -993,7 +998,7 @@ int WINAPI createCfgDlg()
|
|||
else
|
||||
{
|
||||
popstring(NULL);
|
||||
pushstring("error creating dialog");
|
||||
pushstring(_T("error creating dialog"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1005,88 +1010,88 @@ int WINAPI createCfgDlg()
|
|||
|
||||
for (int nIdx = 0; nIdx < nNumFields; nIdx++) {
|
||||
static struct {
|
||||
char* pszClass;
|
||||
TCHAR* pszClass;
|
||||
DWORD dwStyle;
|
||||
DWORD dwRTLStyle;
|
||||
DWORD dwExStyle;
|
||||
DWORD dwRTLExStyle;
|
||||
} ClassTable[] = {
|
||||
{ "STATIC", // FIELD_HLINE
|
||||
{ _T("STATIC"), // FIELD_HLINE
|
||||
DEFAULT_STYLES | SS_ETCHEDHORZ | SS_SUNKEN,
|
||||
DEFAULT_STYLES | SS_ETCHEDHORZ | SS_SUNKEN,
|
||||
WS_EX_TRANSPARENT,
|
||||
WS_EX_TRANSPARENT | RTL_EX_STYLES },
|
||||
{ "STATIC", // FIELD_VLINE
|
||||
{ _T("STATIC"), // FIELD_VLINE
|
||||
DEFAULT_STYLES | SS_ETCHEDVERT | SS_SUNKEN,
|
||||
DEFAULT_STYLES | SS_ETCHEDVERT | SS_SUNKEN,
|
||||
WS_EX_TRANSPARENT,
|
||||
WS_EX_TRANSPARENT | RTL_EX_STYLES },
|
||||
{ "STATIC", // FIELD_LABEL
|
||||
{ _T("STATIC"), // FIELD_LABEL
|
||||
DEFAULT_STYLES,
|
||||
DEFAULT_STYLES | SS_RIGHT,
|
||||
WS_EX_TRANSPARENT,
|
||||
WS_EX_TRANSPARENT | RTL_EX_STYLES },
|
||||
{ "STATIC", // FIELD_ICON
|
||||
{ _T("STATIC"), // FIELD_ICON
|
||||
DEFAULT_STYLES | SS_ICON,
|
||||
DEFAULT_STYLES | SS_ICON,
|
||||
0,
|
||||
RTL_EX_STYLES },
|
||||
{ "STATIC", // FIELD_BITMAP
|
||||
{ _T("STATIC"), // FIELD_BITMAP
|
||||
DEFAULT_STYLES | SS_BITMAP,
|
||||
DEFAULT_STYLES | SS_BITMAP,
|
||||
0,
|
||||
RTL_EX_STYLES },
|
||||
{ "BUTTON", // FIELD_BROWSEBUTTON
|
||||
{ _T("BUTTON"), // FIELD_BROWSEBUTTON
|
||||
DEFAULT_STYLES | WS_TABSTOP,
|
||||
DEFAULT_STYLES | WS_TABSTOP,
|
||||
0,
|
||||
RTL_EX_STYLES },
|
||||
{ "BUTTON", // FIELD_LINK
|
||||
{ _T("BUTTON"), // FIELD_LINK
|
||||
DEFAULT_STYLES | WS_TABSTOP | BS_OWNERDRAW,
|
||||
DEFAULT_STYLES | WS_TABSTOP | BS_OWNERDRAW | BS_RIGHT,
|
||||
0,
|
||||
RTL_EX_STYLES },
|
||||
{ "BUTTON", // FIELD_BUTTON
|
||||
{ _T("BUTTON"), // FIELD_BUTTON
|
||||
DEFAULT_STYLES | WS_TABSTOP,
|
||||
DEFAULT_STYLES | WS_TABSTOP,
|
||||
0,
|
||||
RTL_EX_STYLES },
|
||||
{ "BUTTON", // FIELD_GROUPBOX
|
||||
{ _T("BUTTON"), // FIELD_GROUPBOX
|
||||
DEFAULT_STYLES | BS_GROUPBOX,
|
||||
DEFAULT_STYLES | BS_GROUPBOX | BS_RIGHT,
|
||||
WS_EX_TRANSPARENT,
|
||||
WS_EX_TRANSPARENT | RTL_EX_STYLES },
|
||||
{ "BUTTON", // FIELD_CHECKBOX
|
||||
{ _T("BUTTON"), // FIELD_CHECKBOX
|
||||
DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTOCHECKBOX | BS_MULTILINE,
|
||||
DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTOCHECKBOX | BS_MULTILINE | BS_RIGHT | BS_LEFTTEXT,
|
||||
0,
|
||||
RTL_EX_STYLES },
|
||||
{ "BUTTON", // FIELD_RADIOBUTTON
|
||||
{ _T("BUTTON"), // FIELD_RADIOBUTTON
|
||||
DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTORADIOBUTTON | BS_MULTILINE,
|
||||
DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTORADIOBUTTON | BS_MULTILINE | BS_RIGHT | BS_LEFTTEXT,
|
||||
0,
|
||||
RTL_EX_STYLES },
|
||||
{ "EDIT", // FIELD_TEXT
|
||||
{ _T("EDIT"), // FIELD_TEXT
|
||||
DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL,
|
||||
DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL | ES_RIGHT,
|
||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
|
||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | RTL_EX_STYLES },
|
||||
{ "EDIT", // FIELD_FILEREQUEST
|
||||
{ _T("EDIT"), // FIELD_FILEREQUEST
|
||||
DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL,
|
||||
DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL | ES_RIGHT,
|
||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
|
||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | RTL_EX_STYLES },
|
||||
{ "EDIT", // FIELD_DIRREQUEST
|
||||
{ _T("EDIT"), // FIELD_DIRREQUEST
|
||||
DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL,
|
||||
DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL | ES_RIGHT,
|
||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
|
||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | RTL_EX_STYLES },
|
||||
{ "COMBOBOX", // FIELD_COMBOBOX
|
||||
{ _T("COMBOBOX"), // FIELD_COMBOBOX
|
||||
DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | WS_CLIPCHILDREN | CBS_AUTOHSCROLL | CBS_HASSTRINGS,
|
||||
DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | WS_CLIPCHILDREN | CBS_AUTOHSCROLL | CBS_HASSTRINGS,
|
||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
|
||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_RIGHT | RTL_EX_STYLES },
|
||||
{ "LISTBOX", // FIELD_LISTBOX
|
||||
{ _T("LISTBOX"), // FIELD_LISTBOX
|
||||
DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT,
|
||||
DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT,
|
||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
|
||||
|
@ -1133,7 +1138,7 @@ int WINAPI createCfgDlg()
|
|||
rect.left = mainWndWidth - right;
|
||||
}
|
||||
|
||||
char *title = pField->pszText;
|
||||
TCHAR *title = pField->pszText;
|
||||
switch (pField->nType) {
|
||||
case FIELD_ICON:
|
||||
case FIELD_BITMAP:
|
||||
|
@ -1198,10 +1203,10 @@ int WINAPI createCfgDlg()
|
|||
);
|
||||
|
||||
{
|
||||
char szField[64];
|
||||
char szHwnd[64];
|
||||
wsprintf(szField, "Field %d", pField->nField);
|
||||
wsprintf(szHwnd, "%d", hwCtrl);
|
||||
TCHAR szField[64];
|
||||
TCHAR szHwnd[64];
|
||||
wsprintf(szField, _T("Field %d"), pField->nField);
|
||||
wsprintf(szHwnd, _T("%d"), hwCtrl);
|
||||
WritePrivateProfileString(szField, pField->pszHwndEntry, szHwnd, pszFilename);
|
||||
}
|
||||
|
||||
|
@ -1223,7 +1228,7 @@ int WINAPI createCfgDlg()
|
|||
|
||||
case FIELD_CHECKBOX:
|
||||
case FIELD_RADIOBUTTON:
|
||||
if (pField->pszState[0] == '1')
|
||||
if (pField->pszState[0] == _T('1'))
|
||||
mySendMessage(hwCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
|
||||
break;
|
||||
|
||||
|
@ -1242,12 +1247,12 @@ int WINAPI createCfgDlg()
|
|||
nFindMsg = LB_FINDSTRINGEXACT;
|
||||
nSetSelMsg = LB_SETCURSEL;
|
||||
}
|
||||
char *pszStart, *pszEnd, *pszList;
|
||||
TCHAR *pszStart, *pszEnd, *pszList;
|
||||
pszStart = pszEnd = pszList = STRDUP(pField->pszListItems);
|
||||
// pszListItems has a trailing pipe
|
||||
while (*pszEnd) {
|
||||
if (*pszEnd == '|') {
|
||||
*pszEnd = '\0';
|
||||
if (*pszEnd == _T('|')) {
|
||||
*pszEnd = _T('\0');
|
||||
if (*pszStart)
|
||||
mySendMessage(hwCtrl, nAddMsg, 0, (LPARAM) pszStart);
|
||||
pszStart = ++pszEnd;
|
||||
|
@ -1261,9 +1266,9 @@ int WINAPI createCfgDlg()
|
|||
mySendMessage(hwCtrl, LB_SETSEL, FALSE, (LPARAM)-1);
|
||||
pszStart = pszEnd = pField->pszState;
|
||||
for (;;) {
|
||||
char c = *pszEnd;
|
||||
if (c == '|' || c == '\0') {
|
||||
*pszEnd = '\0';
|
||||
TCHAR c = *pszEnd;
|
||||
if (c == _T('|') || c == _T('\0')) {
|
||||
*pszEnd = _T('\0');
|
||||
if (*pszStart)
|
||||
{
|
||||
int nItem = mySendMessage(hwCtrl, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)pszStart);
|
||||
|
@ -1429,8 +1434,8 @@ int WINAPI createCfgDlg()
|
|||
mySetWindowText(mainwnd,pszTitle);
|
||||
pFilenameStackEntry = *g_stacktop;
|
||||
*g_stacktop = (*g_stacktop)->next;
|
||||
static char tmp[32];
|
||||
wsprintf(tmp,"%d",hConfigWindow);
|
||||
static TCHAR tmp[32];
|
||||
wsprintf(tmp,_T("%d"),hConfigWindow);
|
||||
pushstring(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1477,7 +1482,7 @@ void WINAPI showCfgDlg()
|
|||
|
||||
int j = FIELD_BUFFERS;
|
||||
while (j--)
|
||||
FREE(((char **) pField)[j]);
|
||||
FREE(((TCHAR **) pField)[j]);
|
||||
|
||||
if (pField->nType == FIELD_BITMAP) {
|
||||
DeleteObject(pField->hImage);
|
||||
|
@ -1488,18 +1493,18 @@ void WINAPI showCfgDlg()
|
|||
}
|
||||
FREE(pFields);
|
||||
|
||||
pushstring(g_is_cancel?"cancel":g_is_back?"back":"success");
|
||||
pushstring(g_is_cancel?_T("cancel"):g_is_back?_T("back"):_T("success"));
|
||||
}
|
||||
|
||||
int initCalled;
|
||||
|
||||
extern "C" void __declspec(dllexport) dialog(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop)
|
||||
TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
hMainWindow=hwndParent;
|
||||
EXDLL_INIT();
|
||||
if (initCalled) {
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
if (createCfgDlg())
|
||||
|
@ -1514,14 +1519,16 @@ static UINT_PTR PluginCallback(enum NSPIM msg)
|
|||
}
|
||||
|
||||
extern "C" void __declspec(dllexport) initDialog(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop,
|
||||
TCHAR *variables, stack_t **stacktop,
|
||||
extra_parameters *extra)
|
||||
{
|
||||
hMainWindow=hwndParent;
|
||||
EXDLL_INIT();
|
||||
|
||||
extra->RegisterPluginCallback(m_hInstance, PluginCallback);
|
||||
|
||||
if (initCalled) {
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
if (createCfgDlg())
|
||||
|
@ -1530,11 +1537,11 @@ extern "C" void __declspec(dllexport) initDialog(HWND hwndParent, int string_siz
|
|||
}
|
||||
|
||||
extern "C" void __declspec(dllexport) show(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop)
|
||||
TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
EXDLL_INIT();
|
||||
if (!initCalled) {
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
initCalled--;
|
||||
|
@ -1548,23 +1555,41 @@ extern "C" BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lp
|
|||
}
|
||||
|
||||
|
||||
int WINAPI LookupToken(TableEntry* psTable_, char* pszToken_)
|
||||
/**
|
||||
* Looks up a single token in the psTable_ and returns its mapped numerical value.
|
||||
*
|
||||
* @param psTable_ The lookup table.
|
||||
* @param pszToken_ The token to lookup.
|
||||
* @return The integer value related to the token, otherwise 0.
|
||||
*/
|
||||
int WINAPI LookupToken(TableEntry* psTable_, TCHAR* pszToken_)
|
||||
{
|
||||
for (int i = 0; psTable_[i].pszName; i++)
|
||||
if (!stricmp(pszToken_, psTable_[i].pszName))
|
||||
if (!lstrcmpi(pszToken_, psTable_[i].pszName))
|
||||
return psTable_[i].nValue;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WINAPI LookupTokens(TableEntry* psTable_, char* pszTokens_)
|
||||
/**
|
||||
* In a string of tokens separated by vertical bars '|', look them up in the
|
||||
* Lookup Table psTable and return their logical OR of their subsequent
|
||||
* integer values.
|
||||
*
|
||||
* @param psTable_ The lookup table to search in.
|
||||
* @param pszToken String of tokens separated by '|' whose values are to be
|
||||
* ORed together.
|
||||
* @return The ORed value of the token values. If no tokens were found, it
|
||||
* will return 0.
|
||||
*/
|
||||
int WINAPI LookupTokens(TableEntry* psTable_, TCHAR* pszTokens_)
|
||||
{
|
||||
int n = 0;
|
||||
char *pszStart = pszTokens_;
|
||||
char *pszEnd = pszTokens_;
|
||||
TCHAR *pszStart = pszTokens_;
|
||||
TCHAR *pszEnd = pszTokens_;
|
||||
for (;;) {
|
||||
char c = *pszEnd;
|
||||
if (c == '|' || c == '\0') {
|
||||
*pszEnd = '\0';
|
||||
TCHAR c = *pszEnd;
|
||||
if (c == _T('|') || c == _T('\0')) {
|
||||
*pszEnd = _T('\0');
|
||||
n |= LookupToken(psTable_, pszStart);
|
||||
*pszEnd = c;
|
||||
if (!c)
|
||||
|
@ -1577,8 +1602,15 @@ int WINAPI LookupTokens(TableEntry* psTable_, char* pszTokens_)
|
|||
return n;
|
||||
}
|
||||
|
||||
void WINAPI ConvertNewLines(char *str) {
|
||||
char *p1, *p2, *p3;
|
||||
/**
|
||||
* ConvertNewLines takes a string and turns escape sequences written
|
||||
* as separate chars e.g. "\\t" into the special char they represent
|
||||
* '\t'. The transformation is done in place.
|
||||
*
|
||||
* @param str [in/out] The string to convert.
|
||||
*/
|
||||
void WINAPI ConvertNewLines(TCHAR *str) {
|
||||
TCHAR *p1, *p2, *p3;
|
||||
|
||||
if (!str)
|
||||
return;
|
||||
|
@ -1589,23 +1621,23 @@ void WINAPI ConvertNewLines(char *str) {
|
|||
{
|
||||
switch (*(LPWORD)p1)
|
||||
{
|
||||
case CHAR2_TO_WORD('\\', 't'):
|
||||
*p2 = '\t';
|
||||
case CHAR2_TO_WORD(_T('\\'), _T('t')):
|
||||
*p2 = _T('\t');
|
||||
p1 += 2;
|
||||
p2++;
|
||||
break;
|
||||
case CHAR2_TO_WORD('\\', 'n'):
|
||||
*p2 = '\n';
|
||||
case CHAR2_TO_WORD(_T('\\'), _T('n')):
|
||||
*p2 = _T('\n');
|
||||
p1 += 2;
|
||||
p2++;
|
||||
break;
|
||||
case CHAR2_TO_WORD('\\', 'r'):
|
||||
*p2 = '\r';
|
||||
case CHAR2_TO_WORD(_T('\\'), _T('r')):
|
||||
*p2 = _T('\r');
|
||||
p1 += 2;
|
||||
p2++;
|
||||
break;
|
||||
case CHAR2_TO_WORD('\\', '\\'):
|
||||
*p2 = '\\';
|
||||
case CHAR2_TO_WORD(_T('\\'), _T('\\')):
|
||||
*p2 = _T('\\');
|
||||
p1 += 2;
|
||||
p2++;
|
||||
break;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <windows.h>
|
||||
#include "resource.h"
|
||||
#include <nsis/nsis_tchar.h>
|
||||
|
||||
// JF> updated usage
|
||||
// call like this:
|
||||
|
@ -8,6 +9,8 @@
|
|||
// LangDLL:LangDialog "Language Selection" "Choose a language" 2 French 1036 English 1033
|
||||
// or (the F after the 2 means we're supplying font information)
|
||||
// LangDLL:LangDialog "Language Selection" "Choose a language" 2F French 1036 English 1033 12 Garamond
|
||||
//
|
||||
// Unicode support added by Jim Park -- 07/27/2007
|
||||
|
||||
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
|
@ -15,8 +18,8 @@
|
|||
HINSTANCE g_hInstance;
|
||||
HWND g_hwndParent;
|
||||
|
||||
char temp[1024];
|
||||
char g_wndtitle[1024], g_wndtext[1024];
|
||||
TCHAR temp[1024];
|
||||
TCHAR g_wndtitle[1024], g_wndtext[1024];
|
||||
int dofont;
|
||||
int docp;
|
||||
|
||||
|
@ -24,15 +27,15 @@ int langs_num;
|
|||
int visible_langs_num;
|
||||
|
||||
struct lang {
|
||||
char *name;
|
||||
char *id;
|
||||
TCHAR *name;
|
||||
TCHAR *id;
|
||||
UINT cp;
|
||||
} *langs;
|
||||
|
||||
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
int i, size;
|
||||
char *selected_language = NULL;
|
||||
TCHAR *selected_language = NULL;
|
||||
static HFONT font;
|
||||
switch (uMsg) {
|
||||
case WM_INITDIALOG:
|
||||
|
@ -62,7 +65,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
size = myatou(temp);
|
||||
if (!popstring(temp)) {
|
||||
LOGFONT f = {0,};
|
||||
if (lstrcmp(temp, "MS Shell Dlg")) {
|
||||
if (lstrcmp(temp, _T("MS Shell Dlg"))) {
|
||||
f.lfHeight = -MulDiv(size, GetDeviceCaps(GetDC(hwndDlg), LOGPIXELSY), 72);
|
||||
lstrcpy(f.lfFaceName, temp);
|
||||
font = CreateFontIndirect(&f);
|
||||
|
@ -84,17 +87,17 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
i = SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_GETCURSEL, 0, 0);
|
||||
i = SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_GETITEMDATA, i, 0);
|
||||
if (i != CB_ERR && i) {
|
||||
pushstring((char *) i);
|
||||
pushstring((TCHAR *) i);
|
||||
} else {
|
||||
// ?!
|
||||
pushstring("cancel");
|
||||
pushstring(_T("cancel"));
|
||||
}
|
||||
// end dialog
|
||||
EndDialog(hwndDlg, 0);
|
||||
break;
|
||||
case IDCANCEL:
|
||||
// push "cancel" on the stack
|
||||
pushstring("cancel");
|
||||
pushstring(_T("cancel"));
|
||||
// end dialog
|
||||
EndDialog(hwndDlg, 0);
|
||||
break;
|
||||
|
@ -111,7 +114,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
}
|
||||
|
||||
void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop)
|
||||
TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
g_hwndParent=hwndParent;
|
||||
EXDLL_INIT();
|
||||
|
@ -130,12 +133,12 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size,
|
|||
|
||||
// parse flags
|
||||
{
|
||||
char *p=temp;
|
||||
TCHAR *p=temp;
|
||||
while (*p)
|
||||
{
|
||||
if (*p == 'A') doauto=1; // parse auto count flag
|
||||
if (*p == 'F') dofont=1; // parse font flag
|
||||
if (*p == 'C') docp=1; // parse codepage flag
|
||||
if (*p == _T('A')) doauto=1; // parse auto count flag
|
||||
if (*p == _T('F')) dofont=1; // parse font flag
|
||||
if (*p == _T('C')) docp=1; // parse codepage flag
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
@ -173,12 +176,12 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size,
|
|||
// fill language struct
|
||||
for (i = 0; i < langs_num; i++) {
|
||||
if (popstring(temp)) { visible_langs_num = 0; break; }
|
||||
langs[visible_langs_num].name = GlobalAlloc(GPTR, lstrlen(temp)+1);
|
||||
langs[visible_langs_num].name = (TCHAR*) GlobalAlloc(GPTR, (lstrlen(temp)+1)*sizeof(TCHAR));
|
||||
if (!langs[visible_langs_num].name) { visible_langs_num = 0; break; }
|
||||
lstrcpy(langs[visible_langs_num].name, temp);
|
||||
|
||||
if (popstring(temp)) { visible_langs_num = 0; break; }
|
||||
langs[visible_langs_num].id = GlobalAlloc(GPTR, lstrlen(temp)+1);
|
||||
langs[visible_langs_num].id = (TCHAR*) GlobalAlloc(GPTR, (lstrlen(temp)+1)*sizeof(TCHAR));
|
||||
if (!langs[visible_langs_num].id) { visible_langs_num = 0; break; }
|
||||
lstrcpy(langs[visible_langs_num].id, temp);
|
||||
|
||||
|
@ -188,6 +191,10 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size,
|
|||
langs[visible_langs_num].cp = myatou(temp);
|
||||
}
|
||||
|
||||
// If Unicode, show everything.
|
||||
#ifdef _UNICODE
|
||||
visible_langs_num++;
|
||||
#else
|
||||
if (!docp || langs[visible_langs_num].cp == GetACP() || langs[visible_langs_num].cp == 0)
|
||||
{
|
||||
visible_langs_num++;
|
||||
|
@ -197,6 +204,7 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size,
|
|||
GlobalFree(langs[visible_langs_num].name);
|
||||
GlobalFree(langs[visible_langs_num].id);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// pop the empty string to keep the stack clean
|
||||
|
@ -213,7 +221,7 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size,
|
|||
}
|
||||
else if (visible_langs_num == 0)
|
||||
{
|
||||
pushstring("");
|
||||
pushstring(_T(""));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
// Unicode support by Jim Park -- 08/23/2007
|
||||
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
#include "../ExDLL/nsis_tchar.h"
|
||||
#include "resource.h"
|
||||
|
||||
#define CBL(x) {x,#x}
|
||||
#define CBL(x) {x,_T(#x)}
|
||||
|
||||
struct line {
|
||||
unsigned short id;
|
||||
char *name;
|
||||
TCHAR *name;
|
||||
};
|
||||
|
||||
line primary[] = {
|
||||
|
@ -201,17 +204,17 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
|
|||
}
|
||||
else if (HIWORD(wParam) == CBN_SELCHANGE) {
|
||||
if (SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0) != CB_ERR && SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0) != CB_ERR) {
|
||||
char lang[512];
|
||||
wsprintf(lang, "Language ID: %d", MAKELANGID(primary[SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0)].id, sub[SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0)].id));
|
||||
TCHAR lang[512];
|
||||
wsprintf(lang, _T("Language ID: %d"), MAKELANGID(primary[SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0)].id, sub[SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0)].id));
|
||||
SetDlgItemText(hwndDlg, IDC_RESULT, lang);
|
||||
}
|
||||
}
|
||||
else if (LOWORD(wParam) == IDOK) {
|
||||
if (SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0) != CB_ERR && SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0) != CB_ERR) {
|
||||
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, 16);
|
||||
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, 16*sizeof(TCHAR));
|
||||
if (!hMem) return 0;
|
||||
char *lang_id = (char *)GlobalLock(hMem);
|
||||
wsprintf(lang_id, "%u", MAKELANGID(primary[SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0)].id, sub[SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0)].id));
|
||||
TCHAR *lang_id = (TCHAR *)GlobalLock(hMem);
|
||||
wsprintf(lang_id, _T("%u"), MAKELANGID(primary[SendDlgItemMessage(hwndDlg, IDC_PRIMARY, CB_GETCURSEL, 0, 0)].id, sub[SendDlgItemMessage(hwndDlg, IDC_SUB, CB_GETCURSEL, 0, 0)].id));
|
||||
GlobalUnlock(hMem);
|
||||
if (!OpenClipboard(hwndDlg)) return 0;
|
||||
EmptyClipboard();
|
||||
|
@ -224,9 +227,9 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInstance,
|
||||
int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
LPTSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
InitCommonControls();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Reviewed for Unicode support by Jim Park -- 08/17/2007
|
||||
|
||||
#define _WIN32_IE 0x0400
|
||||
#include <windows.h>
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
** License: see jnetlib.h
|
||||
*/
|
||||
|
||||
// Reviewed for Unicode support by Jim Park -- 08/16/2007
|
||||
// Note: For Unicode Support, all string functions must explicitly use
|
||||
// ANSI versions if UNICODE is defined.
|
||||
|
||||
#include "netinc.h"
|
||||
#include "util.h"
|
||||
|
@ -57,14 +60,14 @@ int JNL_AsyncDNS::resolve(char *hostname, unsigned long *addr)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (lstrcmpi(m_hostname,hostname)) m_addr=0;
|
||||
if (lstrcmpiA(m_hostname,hostname)) m_addr=0;
|
||||
else if (m_addr == INADDR_NONE) return -1;
|
||||
else if (m_addr)
|
||||
{
|
||||
*addr=m_addr;
|
||||
return 0;
|
||||
}
|
||||
lstrcpy(m_hostname,hostname);
|
||||
lstrcpyA(m_hostname,hostname);
|
||||
|
||||
if (m_thread_kill)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
** 4. enjoy.
|
||||
*/
|
||||
|
||||
// Reviewed for Unicode support by Jim Park -- 08/16/2007
|
||||
// Note: Inet host name is strictly ANSI, no UNICODE for now.
|
||||
|
||||
#ifndef _ASYNCDNS_H_
|
||||
#define _ASYNCDNS_H_
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
** Author: Justin Frankel
|
||||
** File: connection.cpp - JNL TCP connection implementation
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Reviewed for Unicode support by Jim Park -- 08/17/2007
|
||||
*/
|
||||
|
||||
#include "netinc.h"
|
||||
|
|
|
@ -50,6 +50,8 @@
|
|||
** make the socket close after sending all the data sent.
|
||||
**
|
||||
** 8. delete ye' ol' object.
|
||||
**
|
||||
** Reviewed for Unicode Support by Jim Park -- 08/17/2007
|
||||
*/
|
||||
|
||||
#ifndef _CONNECTION_H_
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
** Author: Justin Frankel
|
||||
** File: httpget.cpp - JNL HTTP GET implementation
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Reviewed for Unicode Support by Jim Park -- 08/17/2007
|
||||
** Note: The functions that work on char's should be explicitely set to use the
|
||||
** ANSI versions. Some of the functions like wprintf() are #defined to be
|
||||
** the wide-char versions when _UNICODE is defined. So these must be explictly
|
||||
** set to use the ANSI versions.
|
||||
*/
|
||||
|
||||
#include "netinc.h"
|
||||
|
@ -181,14 +187,14 @@ void JNL_HTTPGet::connect(char *url)
|
|||
|
||||
if (!m_http_proxyhost || !m_http_proxyhost[0])
|
||||
{
|
||||
wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_request);
|
||||
wsprintfA(str,"GET %s HTTP/1.0\r\n",m_http_request);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_url);
|
||||
wsprintfA(str,"GET %s HTTP/1.0\r\n",m_http_url);
|
||||
}
|
||||
|
||||
wsprintf(str+strlen(str),"Host: %s\r\n",m_http_host);
|
||||
wsprintfA(str+strlen(str),"Host: %s\r\n",m_http_host);
|
||||
|
||||
if (m_http_lpinfo&&m_http_lpinfo[0])
|
||||
{
|
||||
|
|
|
@ -37,6 +37,12 @@
|
|||
** note that user, pass, port, and /requestwhatever are all optional :)
|
||||
** note that also, http:// is really not important. if you do poo://
|
||||
** or even leave out the http:// altogether, it will still work.
|
||||
**
|
||||
** Reviewed for Unicode Support by Jim Park -- 08/17/2007
|
||||
** Note: The functions that work on char's should be explicitely set to use the
|
||||
** ANSI versions. Some of the functions like wprintf() are #defined to be
|
||||
** the wide-char versions when _UNICODE is defined. So these must be explictly
|
||||
** set to use the ANSI versions.
|
||||
*/
|
||||
|
||||
#ifndef _HTTPGET_H_
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
** Author: Justin Frankel
|
||||
** File: netinc.h - network includes and portability defines (used internally)
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Reviewed for Unicode Support by Jim Park -- 08/17/2007
|
||||
** Note: The functions that work on char's should be explicitely set to use the
|
||||
** ANSI versions. Some of the functions like lstrcpy() are #defined to be
|
||||
** the wide-char versions when _UNICODE is defined. So these must be explictly
|
||||
** set to use the ANSI versions.
|
||||
*/
|
||||
|
||||
#ifndef _NETINC_H_
|
||||
|
@ -72,10 +78,10 @@ extern void mini_memset(void *,char,int);
|
|||
extern void mini_memcpy(void *,void*,int);
|
||||
#define memset mini_memset
|
||||
#define memcpy mini_memcpy
|
||||
#define strcpy lstrcpy
|
||||
#define strncpy lstrcpyn
|
||||
#define strcat lstrcat
|
||||
#define strlen lstrlen
|
||||
#define strcpy lstrcpyA
|
||||
#define strncpy lstrcpynA
|
||||
#define strcat lstrcatA
|
||||
#define strlen lstrlenA
|
||||
#define malloc(x) GlobalAlloc(GPTR,(x))
|
||||
#define free(x) { if (x) GlobalFree(x); }
|
||||
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
** Author: Justin Frankel
|
||||
** File: util.cpp - JNL implementation of basic network utilities
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Reviewed for Unicode Support by Jim Park -- 08/17/2007
|
||||
** Note: The functions that work on char's should be explicitely set to use the
|
||||
** ANSI versions. Some of the functions like wprintf() are #defined to be
|
||||
** the wide-char versions when _UNICODE is defined. So these must be explictly
|
||||
** set to use the ANSI versions.
|
||||
*/
|
||||
|
||||
#include "netinc.h"
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
** JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen);
|
||||
** gives you the dotted decimal notation of an integer ip address.
|
||||
**
|
||||
** Reviewed for Unicode Support by Jim Park -- 08/17/2007
|
||||
** Note: The functions that work on char's should be explicitely set to use the
|
||||
** ANSI versions. Some of the functions like wprintf() are #defined to be
|
||||
** the wide-char versions when _UNICODE is defined. So these must be explictly
|
||||
** set to use the ANSI versions.
|
||||
*/
|
||||
|
||||
#ifndef _UTIL_H_
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Unicode support by Jim Park -- 08/18/2007
|
||||
*/
|
||||
#define MAKENSISW_CPP
|
||||
|
||||
|
@ -34,7 +36,7 @@ NFINDREPLACE g_find;
|
|||
extern NTOOLBAR g_toolbar;
|
||||
int g_symbol_set_mode;
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow) {
|
||||
int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, TCHAR *cmdParam, int cmdShow) {
|
||||
MSG msg;
|
||||
int status;
|
||||
HACCEL haccel;
|
||||
|
@ -44,19 +46,19 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmd
|
|||
my_memset(&g_find,0,sizeof(NFINDREPLACE));
|
||||
g_sdata.hInstance=GetModuleHandle(0);
|
||||
g_sdata.symbols = NULL;
|
||||
g_sdata.sigint_event = CreateEvent(NULL, FALSE, FALSE, "makensis win32 signint event");
|
||||
g_sdata.sigint_event = CreateEvent(NULL, FALSE, FALSE, _T("makensis win32 signint event"));
|
||||
RestoreSymbols();
|
||||
|
||||
HINSTANCE hRichEditDLL = LoadLibrary("RichEd32.dll");
|
||||
HINSTANCE hRichEditDLL = LoadLibrary(_T("RichEd32.dll"));
|
||||
|
||||
if (!InitBranding()) {
|
||||
MessageBox(0,NSISERROR,"Error",MB_ICONEXCLAMATION|MB_OK);
|
||||
MessageBox(0,NSISERROR,_T("Error"),MB_ICONEXCLAMATION|MB_OK);
|
||||
return 1;
|
||||
}
|
||||
ResetObjects();
|
||||
HWND hDialog = CreateDialog(g_sdata.hInstance,MAKEINTRESOURCE(DLG_MAIN),0,DialogProc);
|
||||
if (!hDialog) {
|
||||
MessageBox(0,DLGERROR,"Error",MB_ICONEXCLAMATION|MB_OK);
|
||||
MessageBox(0,DLGERROR,_T("Error"),MB_ICONEXCLAMATION|MB_OK);
|
||||
return 1;
|
||||
}
|
||||
haccel = LoadAccelerators(g_sdata.hInstance, MAKEINTRESOURCE(IDK_ACCEL));
|
||||
|
@ -80,7 +82,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmd
|
|||
return msg.wParam;
|
||||
}
|
||||
|
||||
void SetScript(const char *script, bool clearArgs /*= true*/)
|
||||
void SetScript(const TCHAR *script, bool clearArgs /*= true*/)
|
||||
{
|
||||
if (g_sdata.script)
|
||||
{
|
||||
|
@ -94,24 +96,25 @@ void SetScript(const char *script, bool clearArgs /*= true*/)
|
|||
GlobalFree(g_sdata.script_cmd_args);
|
||||
}
|
||||
|
||||
g_sdata.script_cmd_args = GlobalAlloc(GHND, 1);
|
||||
// Pointing to a single char. Maybe _T('\0')
|
||||
g_sdata.script_cmd_args = GlobalAlloc(GHND, sizeof(TCHAR));
|
||||
}
|
||||
|
||||
g_sdata.script = (char *) GlobalAlloc(GPTR, lstrlen(script) + 1);
|
||||
g_sdata.script = (TCHAR *) GlobalAlloc(GPTR, (lstrlen(script) + 1)*sizeof(TCHAR));
|
||||
lstrcpy(g_sdata.script, script);
|
||||
}
|
||||
|
||||
void AddScriptCmdArgs(const char *arg)
|
||||
void AddScriptCmdArgs(const TCHAR *arg)
|
||||
{
|
||||
g_sdata.script_cmd_args = GlobalReAlloc(g_sdata.script_cmd_args,
|
||||
GlobalSize(g_sdata.script_cmd_args) + lstrlen(arg) + 2 /* quotes */ + 1 /* space */,
|
||||
GlobalSize(g_sdata.script_cmd_args) + (lstrlen(arg) + 2/* quotes */ + 1 /* space */)*sizeof(TCHAR),
|
||||
0);
|
||||
|
||||
char *args = (char *) GlobalLock(g_sdata.script_cmd_args);
|
||||
TCHAR *args = (TCHAR *) GlobalLock(g_sdata.script_cmd_args);
|
||||
|
||||
lstrcat(args, " \"");
|
||||
lstrcat(args, _T(" \""));
|
||||
lstrcat(args, arg);
|
||||
lstrcat(args, "\"");
|
||||
lstrcat(args, _T("\""));
|
||||
|
||||
GlobalUnlock(g_sdata.script_cmd_args);
|
||||
}
|
||||
|
@ -119,23 +122,23 @@ void AddScriptCmdArgs(const char *arg)
|
|||
void ProcessCommandLine()
|
||||
{
|
||||
int argc;
|
||||
char **argv;
|
||||
TCHAR **argv;
|
||||
int i, j;
|
||||
int argSpaceSize;
|
||||
|
||||
argSpaceSize = SetArgv((char *)GetCommandLine(), &argc, &argv);
|
||||
argSpaceSize = SetArgv((TCHAR *)GetCommandLine(), &argc, &argv);
|
||||
if (argc > 1) {
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (!lstrncmpi(argv[i], "/XSetCompressor ", lstrlen("/XSetCompressor ")))
|
||||
if (!lstrncmpi(argv[i], _T("/XSetCompressor "), lstrlen(_T("/XSetCompressor "))))
|
||||
{
|
||||
char *p = argv[i] + lstrlen("/XSetCompressor ");
|
||||
if(!lstrncmpi(p,"/FINAL ", lstrlen("/FINAL ")))
|
||||
TCHAR *p = argv[i] + lstrlen(_T("/XSetCompressor "));
|
||||
if(!lstrncmpi(p,_T("/FINAL "), lstrlen(_T("/FINAL "))))
|
||||
{
|
||||
p += lstrlen("/FINAL ");
|
||||
p += lstrlen(_T("/FINAL "));
|
||||
}
|
||||
|
||||
while (*p == ' ') p++;
|
||||
while (*p == _T(' ')) p++;
|
||||
|
||||
for (j = (int) COMPRESSOR_SCRIPT + 1; j < (int) COMPRESSOR_BEST; j++)
|
||||
{
|
||||
|
@ -145,11 +148,11 @@ void ProcessCommandLine()
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (!lstrcmpi(argv[i], "/ChooseCompressor"))
|
||||
else if (!lstrcmpi(argv[i], _T("/ChooseCompressor")))
|
||||
{
|
||||
g_sdata.userSelectCompressor = TRUE;
|
||||
}
|
||||
else if (argv[i][0] == '-' || argv[i][0] == '/')
|
||||
else if (argv[i][0] == _T('-') || argv[i][0] == _T('/'))
|
||||
{
|
||||
AddScriptCmdArgs(argv[i]);
|
||||
}
|
||||
|
@ -185,11 +188,11 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
CreateToolBar();
|
||||
InitTooltips(g_sdata.hwnd);
|
||||
SetBranding(g_sdata.hwnd);
|
||||
HFONT hFont = CreateFont(14,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,"Courier New");
|
||||
HFONT hFont = CreateFont(14,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,_T("Courier New"));
|
||||
SendDlgItemMessage(hwndDlg,IDC_LOGWIN,WM_SETFONT,(WPARAM)hFont,0);
|
||||
RestoreWindowPos(g_sdata.hwnd);
|
||||
RestoreCompressor();
|
||||
SetScript("");
|
||||
SetScript(_T(""));
|
||||
g_sdata.compressor = COMPRESSOR_NONE_SELECTED;
|
||||
g_sdata.userSelectCompressor = FALSE;
|
||||
|
||||
|
@ -243,7 +246,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
}
|
||||
case WM_DROPFILES: {
|
||||
int num;
|
||||
char szTmp[MAX_PATH];
|
||||
TCHAR szTmp[MAX_PATH];
|
||||
num = DragQueryFile((HDROP)wParam,(UINT)-1,NULL,0);
|
||||
if (num==1) {
|
||||
DragQueryFile((HDROP)wParam,0,szTmp,MAX_PATH);
|
||||
|
@ -254,7 +257,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
CompileNSISScript();
|
||||
}
|
||||
} else {
|
||||
MessageBox(hwndDlg,MULTIDROPERROR,"Error",MB_OK|MB_ICONSTOP);
|
||||
MessageBox(hwndDlg,MULTIDROPERROR,_T("Error"),MB_OK|MB_ICONSTOP);
|
||||
}
|
||||
DragFinish((HDROP)wParam);
|
||||
break;
|
||||
|
@ -267,7 +270,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
case WM_ENTERSIZEMOVE:
|
||||
{
|
||||
GetClientRect(g_sdata.hwnd, &g_resize.resizeRect);
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
case WM_SIZE:
|
||||
{
|
||||
|
@ -299,8 +302,8 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
}
|
||||
if(g_sdata.compressor == COMPRESSOR_BEST) {
|
||||
if (g_sdata.retcode==0 && FileExists(g_sdata.output_exe)) {
|
||||
char temp_file_name[1024];
|
||||
wsprintf(temp_file_name,"%s_makensisw_temp",g_sdata.output_exe);
|
||||
TCHAR temp_file_name[1024];
|
||||
wsprintf(temp_file_name,_T("%s_makensisw_temp"),g_sdata.output_exe);
|
||||
if(!lstrcmpi(g_sdata.compressor_name,compressor_names[(int)COMPRESSOR_SCRIPT+1])) {
|
||||
SetCompressorStats();
|
||||
CopyFile(g_sdata.output_exe,temp_file_name,false);
|
||||
|
@ -354,7 +357,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
}
|
||||
|
||||
if(this_compressor == ((int)COMPRESSOR_BEST - 1)) {
|
||||
char buf[1024];
|
||||
TCHAR buf[1024];
|
||||
|
||||
g_sdata.compressor_name = compressor_names[(int)COMPRESSOR_SCRIPT+1];
|
||||
|
||||
|
@ -369,7 +372,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
LogMessage(g_sdata.hwnd, g_sdata.compressor_stats);
|
||||
}
|
||||
DeleteFile(temp_file_name);
|
||||
lstrcpy(g_sdata.compressor_stats,"");
|
||||
lstrcpy(g_sdata.compressor_stats,_T(""));
|
||||
}
|
||||
else {
|
||||
g_sdata.compressor_name = compressor_names[this_compressor+1];
|
||||
|
@ -385,16 +388,16 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
if (!g_sdata.retcode) {
|
||||
MessageBeep(MB_ICONASTERISK);
|
||||
if (g_sdata.warnings)
|
||||
SetTitle(g_sdata.hwnd,"Finished with Warnings");
|
||||
SetTitle(g_sdata.hwnd,_T("Finished with Warnings"));
|
||||
else
|
||||
SetTitle(g_sdata.hwnd,"Finished Sucessfully");
|
||||
SetTitle(g_sdata.hwnd,_T("Finished Sucessfully"));
|
||||
// Added by Darren Owen (DrO) on 1/10/2003
|
||||
if(g_sdata.recompile_test)
|
||||
PostMessage(g_sdata.hwnd, WM_COMMAND, LOWORD(IDC_TEST), 0);
|
||||
}
|
||||
else {
|
||||
MessageBeep(MB_ICONEXCLAMATION);
|
||||
SetTitle(g_sdata.hwnd,"Compile Error: See Log for Details");
|
||||
SetTitle(g_sdata.hwnd,_T("Compile Error: See Log for Details"));
|
||||
}
|
||||
|
||||
// Added by Darren Owen (DrO) on 1/10/2003
|
||||
|
@ -455,8 +458,8 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
switch (cds->dwData) {
|
||||
case MAKENSIS_NOTIFY_SCRIPT:
|
||||
if (g_sdata.input_script) GlobalFree(g_sdata.input_script);
|
||||
g_sdata.input_script = (char *)GlobalAlloc(GPTR, cds->cbData);
|
||||
lstrcpy(g_sdata.input_script, (char *)cds->lpData);
|
||||
g_sdata.input_script = (TCHAR *)GlobalAlloc(GPTR, cds->cbData * sizeof(TCHAR));
|
||||
lstrcpy(g_sdata.input_script, (TCHAR *)cds->lpData);
|
||||
break;
|
||||
case MAKENSIS_NOTIFY_WARNING:
|
||||
g_sdata.warnings++;
|
||||
|
@ -465,8 +468,8 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
break;
|
||||
case MAKENSIS_NOTIFY_OUTPUT:
|
||||
if (g_sdata.output_exe) GlobalFree(g_sdata.output_exe);
|
||||
g_sdata.output_exe = (char *)GlobalAlloc(GPTR, cds->cbData);
|
||||
lstrcpy(g_sdata.output_exe, (char *)cds->lpData);
|
||||
g_sdata.output_exe = (TCHAR *)GlobalAlloc(GPTR, cds->cbData * sizeof(TCHAR));
|
||||
lstrcpy(g_sdata.output_exe, (TCHAR *)cds->lpData);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
|
@ -476,11 +479,11 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
switch (LOWORD(wParam)) {
|
||||
case IDM_BROWSESCR: {
|
||||
if (g_sdata.input_script) {
|
||||
char str[MAX_PATH],*str2;
|
||||
TCHAR str[MAX_PATH],*str2;
|
||||
lstrcpy(str,g_sdata.input_script);
|
||||
str2=my_strrchr(str,'\\');
|
||||
str2=my_strrchr(str,_T('\\'));
|
||||
if(str2!=NULL) *(str2+1)=0;
|
||||
ShellExecute(g_sdata.hwnd,"open",str,NULL,NULL,SW_SHOWNORMAL);
|
||||
ShellExecute(g_sdata.hwnd,_T("open"),str,NULL,NULL,SW_SHOWNORMAL);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -491,12 +494,12 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
}
|
||||
case IDM_NSISHOME:
|
||||
{
|
||||
ShellExecute(g_sdata.hwnd,"open",NSIS_URL,NULL,NULL,SW_SHOWNORMAL);
|
||||
ShellExecuteA(g_sdata.hwnd,"open",NSIS_URL,NULL,NULL,SW_SHOWNORMAL);
|
||||
return TRUE;
|
||||
}
|
||||
case IDM_FORUM:
|
||||
{
|
||||
ShellExecute(g_sdata.hwnd,"open",NSIS_FOR,NULL,NULL,SW_SHOWNORMAL);
|
||||
ShellExecuteA(g_sdata.hwnd,"open",NSIS_FOR,NULL,NULL,SW_SHOWNORMAL);
|
||||
return TRUE;
|
||||
}
|
||||
case IDM_NSISUPDATE:
|
||||
|
@ -518,17 +521,17 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
{
|
||||
if (!g_sdata.thread) {
|
||||
OPENFILENAME l={sizeof(l),};
|
||||
char buf[MAX_PATH];
|
||||
TCHAR buf[MAX_PATH];
|
||||
l.hwndOwner = hwndDlg;
|
||||
l.lpstrFilter = "NSIS Script (*.nsi)\0*.nsi\0All Files (*.*)\0*.*\0";
|
||||
l.lpstrFilter = _T("NSIS Script (*.nsi)\0*.nsi\0All Files (*.*)\0*.*\0");
|
||||
l.lpstrFile = buf;
|
||||
l.nMaxFile = MAX_STRING-1;
|
||||
l.lpstrTitle = "Load Script";
|
||||
l.lpstrDefExt = "log";
|
||||
l.lpstrTitle = _T("Load Script");
|
||||
l.lpstrDefExt = _T("log");
|
||||
l.lpstrFileTitle = NULL;
|
||||
l.lpstrInitialDir = NULL;
|
||||
l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST;
|
||||
lstrcpy(buf,"");
|
||||
lstrcpy(buf,_T(""));
|
||||
if (GetOpenFileName(&l)) {
|
||||
SetScript(buf);
|
||||
PushMRUFile(g_sdata.script);
|
||||
|
@ -582,18 +585,18 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
case IDC_TEST:
|
||||
{
|
||||
if (g_sdata.output_exe) {
|
||||
ShellExecute(g_sdata.hwnd,"open",g_sdata.output_exe,NULL,NULL,SW_SHOWNORMAL);
|
||||
ShellExecute(g_sdata.hwnd,_T("open"),g_sdata.output_exe,NULL,NULL,SW_SHOWNORMAL);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
case IDM_EDITSCRIPT:
|
||||
{
|
||||
if (g_sdata.input_script) {
|
||||
if ((int)ShellExecute(g_sdata.hwnd,"open",g_sdata.input_script,NULL,NULL,SW_SHOWNORMAL)<=32) {
|
||||
char path[MAX_PATH];
|
||||
if ((int)ShellExecute(g_sdata.hwnd,_T("open"),g_sdata.input_script,NULL,NULL,SW_SHOWNORMAL)<=32) {
|
||||
TCHAR path[MAX_PATH];
|
||||
if (GetWindowsDirectory(path,sizeof(path))) {
|
||||
lstrcat(path,"\\notepad.exe");
|
||||
ShellExecute(g_sdata.hwnd,"open",path,g_sdata.input_script,NULL,SW_SHOWNORMAL);
|
||||
lstrcat(path,_T("\\notepad.exe"));
|
||||
ShellExecute(g_sdata.hwnd,_T("open"),path,g_sdata.input_script,NULL,SW_SHOWNORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -625,21 +628,21 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
case IDM_SAVE:
|
||||
{
|
||||
OPENFILENAME l={sizeof(l),};
|
||||
char buf[MAX_STRING];
|
||||
TCHAR buf[MAX_STRING];
|
||||
l.hwndOwner = hwndDlg;
|
||||
l.lpstrFilter = "Log Files (*.log)\0*.log\0Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
|
||||
l.lpstrFilter = _T("Log Files (*.log)\0*.log\0Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0");
|
||||
l.lpstrFile = buf;
|
||||
l.nMaxFile = MAX_STRING-1;
|
||||
l.lpstrTitle = "Save Output";
|
||||
l.lpstrDefExt = "log";
|
||||
l.lpstrTitle = _T("Save Output");
|
||||
l.lpstrDefExt = _T("log");
|
||||
l.lpstrInitialDir = NULL;
|
||||
l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST;
|
||||
lstrcpy(buf,"output");
|
||||
lstrcpy(buf,_T("output"));
|
||||
if (GetSaveFileName(&l)) {
|
||||
HANDLE hFile = CreateFile(buf,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0);
|
||||
if (hFile) {
|
||||
int len=SendDlgItemMessage(g_sdata.hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0);
|
||||
char *existing_text=(char*)GlobalAlloc(GPTR,len);
|
||||
TCHAR *existing_text=(TCHAR*)GlobalAlloc(GPTR,len * sizeof(TCHAR));
|
||||
existing_text[0]=0;
|
||||
GetDlgItemText(g_sdata.hwnd, IDC_LOGWIN, existing_text, len);
|
||||
DWORD dwWritten = 0;
|
||||
|
@ -657,7 +660,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
g_find.fr.lStructSize = sizeof(FINDREPLACE);
|
||||
g_find.fr.hwndOwner = hwndDlg;
|
||||
g_find.fr.Flags = FR_NOUPDOWN;
|
||||
g_find.fr.lpstrFindWhat = (char *)GlobalAlloc(GPTR, 128);
|
||||
g_find.fr.lpstrFindWhat = (TCHAR *)GlobalAlloc(GPTR, 128 * sizeof(TCHAR));
|
||||
if (!g_find.fr.lpstrFindWhat) return TRUE;
|
||||
g_find.fr.wFindWhatLen = 128;
|
||||
g_find.hwndFind = FindText(&g_find.fr);
|
||||
|
@ -716,12 +719,12 @@ DWORD WINAPI MakeNSISProc(LPVOID p) {
|
|||
else sa.lpSecurityDescriptor = NULL;
|
||||
sa.bInheritHandle = true;
|
||||
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
|
||||
ErrorMessage(g_sdata.hwnd,"There was an error creating the output pipe.");
|
||||
ErrorMessage(g_sdata.hwnd,_T("There was an error creating the output pipe."));
|
||||
PostMessage(g_sdata.hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
|
||||
return 1;
|
||||
}
|
||||
if (!CreatePipe(&read_stdin,&newstdin,&sa,0)) {
|
||||
ErrorMessage(g_sdata.hwnd,"There was an error creating the input pipe.");
|
||||
ErrorMessage(g_sdata.hwnd,_T("There was an error creating the input pipe."));
|
||||
PostMessage(g_sdata.hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
|
||||
return 1;
|
||||
}
|
||||
|
@ -732,8 +735,8 @@ DWORD WINAPI MakeNSISProc(LPVOID p) {
|
|||
si.hStdError = newstdout;
|
||||
si.hStdInput = newstdin;
|
||||
if (!CreateProcess(NULL,g_sdata.compile_command,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
||||
char buf[MAX_STRING];
|
||||
wsprintf(buf,"Could not execute:\r\n %s.",g_sdata.compile_command);
|
||||
TCHAR buf[MAX_STRING];
|
||||
wsprintf(buf,_T("Could not execute:\r\n %s."),g_sdata.compile_command);
|
||||
ErrorMessage(g_sdata.hwnd,buf);
|
||||
CloseHandle(newstdout);
|
||||
CloseHandle(read_stdout);
|
||||
|
@ -746,7 +749,7 @@ DWORD WINAPI MakeNSISProc(LPVOID p) {
|
|||
while (dwExit == STILL_ACTIVE || dwRead) {
|
||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||
if (dwRead) {
|
||||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-sizeof(TCHAR), &dwRead, NULL);
|
||||
szBuf[dwRead] = 0;
|
||||
LogMessage(g_sdata.hwnd, szBuf);
|
||||
}
|
||||
|
@ -804,16 +807,16 @@ BOOL CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||
{
|
||||
HFONT bfont = CreateFont(13,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
|
||||
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
||||
FIXED_PITCH|FF_DONTCARE, "Tahoma");
|
||||
FIXED_PITCH|FF_DONTCARE, _T("Tahoma"));
|
||||
HFONT bfontb = CreateFont(13,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
|
||||
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
||||
FIXED_PITCH|FF_DONTCARE, "Tahoma");
|
||||
FIXED_PITCH|FF_DONTCARE, _T("Tahoma"));
|
||||
HFONT rfont = CreateFont(12,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
|
||||
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
||||
FIXED_PITCH|FF_DONTCARE, "MS Shell Dlg");
|
||||
FIXED_PITCH|FF_DONTCARE, _T("MS Shell Dlg"));
|
||||
HFONT rfontb = CreateFont(12,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
|
||||
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
||||
FIXED_PITCH|FF_DONTCARE, "MS Shell Dlg");
|
||||
FIXED_PITCH|FF_DONTCARE, _T("MS Shell Dlg"));
|
||||
if (bfont&&bfontb) {
|
||||
SendDlgItemMessage(hwndDlg, IDC_ABOUTVERSION, WM_SETFONT, (WPARAM)bfontb, FALSE);
|
||||
SendDlgItemMessage(hwndDlg, IDC_ABOUTCOPY, WM_SETFONT, (WPARAM)bfont, FALSE);
|
||||
|
@ -876,7 +879,7 @@ void EnableSymbolEditButtons(HWND hwndDlg)
|
|||
}
|
||||
}
|
||||
|
||||
void SetSymbols(HWND hwndDlg, char **symbols)
|
||||
void SetSymbols(HWND hwndDlg, TCHAR **symbols)
|
||||
{
|
||||
int i = 0;
|
||||
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_RESETCONTENT , 0, 0);
|
||||
|
@ -892,16 +895,16 @@ void SetSymbols(HWND hwndDlg, char **symbols)
|
|||
EnableWindow(GetDlgItem(hwndDlg, IDDEL), FALSE);
|
||||
}
|
||||
|
||||
char **GetSymbols(HWND hwndDlg)
|
||||
TCHAR **GetSymbols(HWND hwndDlg)
|
||||
{
|
||||
int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETCOUNT, 0, 0);
|
||||
char **symbols = NULL;
|
||||
TCHAR **symbols = NULL;
|
||||
if(n > 0) {
|
||||
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (n+1)*sizeof(char *));
|
||||
symbols = (char **)GlobalLock(hMem);
|
||||
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (n+1)*sizeof(TCHAR *));
|
||||
symbols = (TCHAR **)GlobalLock(hMem);
|
||||
for (int i = 0; i < n; i++) {
|
||||
int len = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXTLEN, (WPARAM)i, 0);
|
||||
symbols[i] = (char *)GlobalAlloc(GPTR, (len+1)*sizeof(char));
|
||||
symbols[i] = (TCHAR *)GlobalAlloc(GPTR, (len+1)*sizeof(TCHAR));
|
||||
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)i, (LPARAM)symbols[i]);
|
||||
}
|
||||
symbols[n] = NULL;
|
||||
|
@ -928,8 +931,8 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
}
|
||||
case WM_MAKENSIS_LOADSYMBOLSET:
|
||||
{
|
||||
char *name = (char *)wParam;
|
||||
char **symbols = LoadSymbolSet(name);
|
||||
TCHAR *name = (TCHAR *)wParam;
|
||||
TCHAR **symbols = LoadSymbolSet(name);
|
||||
HGLOBAL hMem;
|
||||
|
||||
SetSymbols(hwndDlg, symbols);
|
||||
|
@ -942,8 +945,8 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
}
|
||||
case WM_MAKENSIS_SAVESYMBOLSET:
|
||||
{
|
||||
char *name = (char *)wParam;
|
||||
char **symbols = GetSymbols(hwndDlg);
|
||||
TCHAR *name = (TCHAR *)wParam;
|
||||
TCHAR **symbols = GetSymbols(hwndDlg);
|
||||
HGLOBAL hMem;
|
||||
|
||||
if(symbols) {
|
||||
|
@ -981,20 +984,20 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0);
|
||||
if(n > 0) {
|
||||
char *buf = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char));
|
||||
TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR));
|
||||
SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXT, n+1, (LPARAM)buf);
|
||||
if(my_strstr(buf," ") || my_strstr(buf,"\t")) {
|
||||
MessageBox(hwndDlg,SYMBOLSERROR,"Error",MB_OK|MB_ICONSTOP);
|
||||
if(my_strstr(buf,_T(" ")) || my_strstr(buf,_T("\t"))) {
|
||||
MessageBox(hwndDlg,SYMBOLSERROR,_T("Error"),MB_OK|MB_ICONSTOP);
|
||||
GlobalFree(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
n = SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXTLENGTH, 0, 0);
|
||||
if(n > 0) {
|
||||
char *buf2 = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char));
|
||||
TCHAR *buf2 = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR));
|
||||
SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXT, n+1, (LPARAM)buf2);
|
||||
char *buf3 = (char *)GlobalAlloc(GPTR, (lstrlen(buf)+lstrlen(buf2)+2)*sizeof(char));
|
||||
wsprintf(buf3,"%s=%s",buf,buf2);
|
||||
TCHAR *buf3 = (TCHAR *)GlobalAlloc(GPTR, (lstrlen(buf)+lstrlen(buf2)+2)*sizeof(TCHAR));
|
||||
wsprintf(buf3,_T("%s=%s"),buf,buf2);
|
||||
GlobalFree(buf);
|
||||
buf = buf3;
|
||||
GlobalFree(buf2);
|
||||
|
@ -1023,9 +1026,9 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
if(num == 1) {
|
||||
int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXTLEN, (WPARAM)index, 0);
|
||||
if(n > 0) {
|
||||
char *buf = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char));
|
||||
TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR));
|
||||
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)index, (LPARAM)buf);
|
||||
char *p = my_strstr(buf,"=");
|
||||
TCHAR *p = my_strstr(buf,_T("="));
|
||||
if(p) {
|
||||
SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, (LPARAM)(p+1));
|
||||
*p=0;
|
||||
|
@ -1157,7 +1160,7 @@ BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
|
|||
HKEY hSubKey;
|
||||
|
||||
if (RegOpenKeyEx(hKey,REGSYMSUBKEY,0,KEY_READ,&hSubKey) == ERROR_SUCCESS) {
|
||||
char subkey[1024];
|
||||
TCHAR subkey[1024];
|
||||
int i=0;
|
||||
|
||||
while (RegEnumKey(hSubKey,i,subkey,sizeof(subkey)) == ERROR_SUCCESS) {
|
||||
|
@ -1189,7 +1192,7 @@ BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
|
|||
case IDOK:
|
||||
{
|
||||
HWND hwndEdit;
|
||||
char name[SYMBOL_SET_NAME_MAXLEN+1];
|
||||
TCHAR name[SYMBOL_SET_NAME_MAXLEN+1];
|
||||
|
||||
hwndEdit = FindWindowEx(GetDlgItem(hwndDlg, IDC_NAMES), 0, 0, 0); // Handle of list
|
||||
hwndEdit = FindWindowEx(GetDlgItem(hwndDlg, IDC_NAMES), hwndEdit, 0, 0); //Handle of edit box
|
||||
|
@ -1224,7 +1227,7 @@ BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
|
|||
int n = SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETCURSEL, 0, 0);
|
||||
if(n != CB_ERR) {
|
||||
long len = SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETLBTEXTLEN, (WPARAM)n, 0);
|
||||
char *buf = (char *)GlobalAlloc(GPTR, (len+1)*sizeof(char));
|
||||
TCHAR *buf = (TCHAR *)GlobalAlloc(GPTR, (len+1)*sizeof(TCHAR));
|
||||
if(SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETLBTEXT, (WPARAM)n, (LPARAM)buf) != CB_ERR) {
|
||||
SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_DELETESTRING, n, 0);
|
||||
DeleteSymbolSet(buf);
|
||||
|
@ -1269,7 +1272,7 @@ void SetCompressor(NCOMPRESSOR compressor)
|
|||
|
||||
if(g_sdata.compressor != compressor) {
|
||||
WORD command;
|
||||
char *compressor_name;
|
||||
TCHAR *compressor_name;
|
||||
|
||||
if(compressor > COMPRESSOR_SCRIPT && compressor < COMPRESSOR_BEST) {
|
||||
command = compressor_commands[(int)compressor];
|
||||
|
@ -1282,7 +1285,7 @@ void SetCompressor(NCOMPRESSOR compressor)
|
|||
else {
|
||||
compressor = COMPRESSOR_SCRIPT;
|
||||
command = IDM_COMPRESSOR_SCRIPT;
|
||||
compressor_name = "";
|
||||
compressor_name = _T("");
|
||||
}
|
||||
g_sdata.compressor = compressor;
|
||||
g_sdata.compressor_name = compressor_name;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Unicode support by Jim Park -- 08/10/2007
|
||||
*/
|
||||
#ifndef MAKENSIS_H
|
||||
#define MAKENSIS_H
|
||||
|
@ -25,6 +26,7 @@
|
|||
#define _WIN32_IE 0x0400
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
#include "../ExDLL/nsis_tchar.h"
|
||||
#include "utils.h"
|
||||
#define _RICHEDIT_VER 0x0200
|
||||
#include <richedit.h>
|
||||
|
@ -35,39 +37,39 @@
|
|||
#define NSIS_FOR "http://forums.winamp.com/forumdisplay.php?forumid=65"
|
||||
#define NSIS_UPDATE "http://nsis.sourceforge.net/update.php?version="
|
||||
#define NSIS_DL_URL "http://nsis.sourceforge.net/download/"
|
||||
#define USAGE "Usage:\r\n\r\n - File | Load Script...\r\n - Drag the .nsi file into this window\r\n - Right click the .nsi file and choose \"Compile NSIS Script\""
|
||||
#define COPYRIGHT "Copyright © 2002 Robert Rainwater"
|
||||
#define CONTRIB "Fritz Elfert, Justin Frankel, Amir Szekely, Sunil Kamath, Joost Verburg"
|
||||
#define USAGE _T("Usage:\r\n\r\n - File | Load Script...\r\n - Drag the .nsi file into this window\r\n - Right click the .nsi file and choose \"Compile NSIS Script\"")
|
||||
#define COPYRIGHT _T("Copyright © 2002 Robert Rainwater")
|
||||
#define CONTRIB _T("Fritz Elfert, Justin Frankel, Amir Szekely, Sunil Kamath, Joost Verburg")
|
||||
#define DOCPATH "http://nsis.sourceforge.net/Docs/"
|
||||
#define LOCALDOCS "\\NSIS.chm"
|
||||
#define NSISERROR "Unable to intialize MakeNSIS. Please verify that makensis.exe is in the same directory as makensisw.exe."
|
||||
#define DLGERROR "Unable to intialize MakeNSISW."
|
||||
#define SYMBOLSERROR "Symbol cannot contain whitespace characters"
|
||||
#define MULTIDROPERROR "Dropping more than one script at a time is not supported"
|
||||
#define NSISUPDATEPROMPT "Running NSIS Update will close MakeNSISW.\nContinue?"
|
||||
#define LOCALDOCS _T("\\NSIS.chm")
|
||||
#define NSISERROR _T("Unable to intialize MakeNSIS. Please verify that makensis.exe is in the same directory as makensisw.exe.")
|
||||
#define DLGERROR _T("Unable to intialize MakeNSISW.")
|
||||
#define SYMBOLSERROR _T("Symbol cannot contain whitespace characters")
|
||||
#define MULTIDROPERROR _T("Dropping more than one script at a time is not supported")
|
||||
#define NSISUPDATEPROMPT _T("Running NSIS Update will close MakeNSISW.\nContinue?")
|
||||
#define REGSEC HKEY_CURRENT_USER
|
||||
#define REGSECDEF HKEY_LOCAL_MACHINE
|
||||
#define REGKEY "Software\\NSIS"
|
||||
#define REGLOC "MakeNSISWPlacement"
|
||||
#define REGCOMPRESSOR "MakeNSISWCompressor"
|
||||
#define REGSYMSUBKEY "Symbols"
|
||||
#define REGMRUSUBKEY "MRU"
|
||||
#define EXENAME "makensis.exe"
|
||||
#define REGKEY _T("Software\\NSIS")
|
||||
#define REGLOC _T("MakeNSISWPlacement")
|
||||
#define REGCOMPRESSOR _T("MakeNSISWCompressor")
|
||||
#define REGSYMSUBKEY _T("Symbols")
|
||||
#define REGMRUSUBKEY _T("MRU")
|
||||
#define EXENAME _T("makensis.exe")
|
||||
#define MAX_STRING 256
|
||||
#define TIMEOUT 100
|
||||
#define MINWIDTH 350
|
||||
#define MINHEIGHT 180
|
||||
#define COMPRESSOR_MESSAGE "\n\nThe %s compressor created the smallest installer (%d bytes)."
|
||||
#define RESTORED_COMPRESSOR_MESSAGE "\n\nThe %s compressor created the smallest installer (%d bytes)."
|
||||
#define EXE_HEADER_COMPRESSOR_STAT "EXE header size:"
|
||||
#define TOTAL_SIZE_COMPRESSOR_STAT "Total size:"
|
||||
#define COMPRESSOR_MESSAGE _T("\n\nThe %s compressor created the smallest installer (%d bytes).")
|
||||
#define RESTORED_COMPRESSOR_MESSAGE _T("\n\nThe %s compressor created the smallest installer (%d bytes).")
|
||||
#define EXE_HEADER_COMPRESSOR_STAT _T("EXE header size:")
|
||||
#define TOTAL_SIZE_COMPRESSOR_STAT _T("Total size:")
|
||||
#define SYMBOL_SET_NAME_MAXLEN 40
|
||||
#define LOAD_SYMBOL_SET_DLG_NAME "Load Symbol Definitions Set"
|
||||
#define SAVE_SYMBOL_SET_DLG_NAME "Save Symbol Definitions Set"
|
||||
#define LOAD_BUTTON_TEXT "Load"
|
||||
#define SAVE_BUTTON_TEXT "Save"
|
||||
#define LOAD_SYMBOL_SET_MESSAGE "Please select a name for the Symbol Definitions Set to load."
|
||||
#define SAVE_SYMBOL_SET_MESSAGE "Please enter or select a name for the Symbol Definitions Set to save."
|
||||
#define LOAD_SYMBOL_SET_DLG_NAME _T("Load Symbol Definitions Set")
|
||||
#define SAVE_SYMBOL_SET_DLG_NAME _T("Save Symbol Definitions Set")
|
||||
#define LOAD_BUTTON_TEXT _T("Load")
|
||||
#define SAVE_BUTTON_TEXT _T("Save")
|
||||
#define LOAD_SYMBOL_SET_MESSAGE _T("Please select a name for the Symbol Definitions Set to load.")
|
||||
#define SAVE_SYMBOL_SET_MESSAGE _T("Please enter or select a name for the Symbol Definitions Set to save.")
|
||||
|
||||
#define WM_MAKENSIS_PROCESSCOMPLETE (WM_USER+1001)
|
||||
#define WM_MAKENSIS_LOADSYMBOLSET (WM_USER+1002)
|
||||
|
@ -93,22 +95,22 @@ typedef enum {
|
|||
} NCOMPRESSOR;
|
||||
|
||||
#ifdef MAKENSISW_CPP
|
||||
char *compressor_names[] = {"",
|
||||
"zlib",
|
||||
"/SOLID zlib",
|
||||
"bzip2",
|
||||
"/SOLID bzip2",
|
||||
"lzma",
|
||||
"/SOLID lzma",
|
||||
"Best"};
|
||||
char *compressor_display_names[] = {"Defined in Script/Compiler Default",
|
||||
"ZLIB",
|
||||
"ZLIB (solid)",
|
||||
"BZIP2",
|
||||
"BZIP2 (solid)",
|
||||
"LZMA",
|
||||
"LZMA (solid)",
|
||||
"Best Compressor"};
|
||||
TCHAR *compressor_names[] = {_T(""),
|
||||
_T("zlib"),
|
||||
_T("/SOLID zlib"),
|
||||
_T("bzip2"),
|
||||
_T("/SOLID bzip2"),
|
||||
_T("lzma"),
|
||||
_T("/SOLID lzma"),
|
||||
_T("Best")};
|
||||
TCHAR *compressor_display_names[] = {_T("Defined in Script/Compiler Default"),
|
||||
_T("ZLIB"),
|
||||
_T("ZLIB (solid)"),
|
||||
_T("BZIP2"),
|
||||
_T("BZIP2 (solid)"),
|
||||
_T("LZMA"),
|
||||
_T("LZMA (solid)"),
|
||||
_T("Best Compressor")};
|
||||
WORD compressor_commands[] = {IDM_COMPRESSOR_SCRIPT,
|
||||
IDM_ZLIB,
|
||||
IDM_ZLIB_SOLID,
|
||||
|
@ -140,9 +142,9 @@ int compressor_strings[] = {IDS_SCRIPT,
|
|||
|
||||
// Extern Variables
|
||||
|
||||
extern const char* NSISW_VERSION;
|
||||
extern const TCHAR* NSISW_VERSION;
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow);
|
||||
int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, TCHAR *cmdParam, int cmdShow);
|
||||
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
DWORD WINAPI MakeNSISProc(LPVOID p);
|
||||
BOOL CALLBACK DialogResize(HWND hWnd, LPARAM /* unused*/);
|
||||
|
@ -151,27 +153,27 @@ BOOL CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
|||
BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
BOOL CALLBACK CompressorProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
void SetScript(const char *script, bool clearArgs = true);
|
||||
void SetScript(const TCHAR *script, bool clearArgs = true);
|
||||
void CompileNSISScript();
|
||||
char* BuildSymbols();
|
||||
TCHAR* BuildSymbols();
|
||||
void SetCompressor(NCOMPRESSOR);
|
||||
void RestoreSymbols();
|
||||
void SaveSymbols();
|
||||
void DeleteSymbolSet(char *);
|
||||
char** LoadSymbolSet(char *);
|
||||
void SaveSymbolSet(char *, char **);
|
||||
void DeleteSymbolSet(TCHAR *);
|
||||
TCHAR** LoadSymbolSet(TCHAR *);
|
||||
void SaveSymbolSet(TCHAR *, TCHAR **);
|
||||
void RestoreMRUList();
|
||||
void SaveMRUList();
|
||||
|
||||
typedef struct NSISScriptData {
|
||||
char *script;
|
||||
TCHAR *script;
|
||||
HGLOBAL script_cmd_args;
|
||||
char *compile_command;
|
||||
char *output_exe;
|
||||
char *input_script;
|
||||
char *branding;
|
||||
char *brandingv;
|
||||
char **symbols;
|
||||
TCHAR *compile_command;
|
||||
TCHAR *output_exe;
|
||||
TCHAR *input_script;
|
||||
TCHAR *branding;
|
||||
TCHAR *brandingv;
|
||||
TCHAR **symbols;
|
||||
int retcode;
|
||||
BOOL userSelectCompressor;
|
||||
DWORD logLength;
|
||||
|
@ -188,9 +190,9 @@ typedef struct NSISScriptData {
|
|||
CHARRANGE textrange;
|
||||
NCOMPRESSOR default_compressor;
|
||||
NCOMPRESSOR compressor;
|
||||
char *compressor_name;
|
||||
char compressor_stats[512];
|
||||
char *best_compressor_name;
|
||||
TCHAR *compressor_name;
|
||||
TCHAR compressor_stats[512];
|
||||
TCHAR *best_compressor_name;
|
||||
// Added by Darren Owen (DrO) on 1/10/2003
|
||||
int recompile_test;
|
||||
} NSCRIPTDATA;
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Unicode support by Jim Park -- 08/20/2007
|
||||
|
||||
*/
|
||||
#define TOOLBAR_CPP
|
||||
|
||||
|
@ -25,6 +27,7 @@
|
|||
#include "resource.h"
|
||||
#include "noclib.h"
|
||||
#include "toolbar.h"
|
||||
#include "../ExDLL/nsis_tchar.h"
|
||||
|
||||
NTOOLBAR g_toolbar;
|
||||
extern NSCRIPTDATA g_sdata;
|
||||
|
@ -65,7 +68,7 @@ void CreateToolBar()
|
|||
g_toolbar.hwnd = CreateWindowEx (
|
||||
0L,
|
||||
TOOLBARCLASSNAME,
|
||||
"",
|
||||
_T(""),
|
||||
WS_CHILD | WS_VISIBLE | TBSTYLE_TRANSPARENT | TBSTYLE_FLAT,
|
||||
0, 0, 0, 30,
|
||||
g_sdata.hwnd,
|
||||
|
@ -77,7 +80,7 @@ void CreateToolBar()
|
|||
SendMessage(g_toolbar.hwnd, TB_ADDBUTTONS, BUTTONCOUNT, (LONG) &tbButton);
|
||||
|
||||
// For Comctl32.dll version detection
|
||||
HMODULE hMod = GetModuleHandle("comctl32.dll");
|
||||
HMODULE hMod = GetModuleHandle(_T("comctl32.dll"));
|
||||
|
||||
if (GetProcAddress(hMod, "InitCommonControlsEx")) { // Version 4.70
|
||||
// Modern toolbar, 24-bit bitmaps
|
||||
|
@ -120,8 +123,8 @@ void UpdateToolBarCompressorButton()
|
|||
{
|
||||
int iBitmap;
|
||||
int iString;
|
||||
char szBuffer[64];
|
||||
char temp[32];
|
||||
TCHAR szBuffer[64];
|
||||
TCHAR temp[32];
|
||||
TOOLINFO ti;
|
||||
|
||||
my_memset(&ti, 0, sizeof(TOOLINFO));
|
||||
|
@ -139,13 +142,13 @@ void UpdateToolBarCompressorButton()
|
|||
sizeof(temp));
|
||||
my_memset(szBuffer, 0, sizeof(szBuffer));
|
||||
lstrcat(szBuffer,temp);
|
||||
lstrcat(szBuffer," [");
|
||||
lstrcat(szBuffer,_T(" ["));
|
||||
LoadString(g_sdata.hInstance,
|
||||
iString,
|
||||
temp,
|
||||
sizeof(temp));
|
||||
lstrcat(szBuffer,temp);
|
||||
lstrcat(szBuffer,"]");
|
||||
lstrcat(szBuffer,_T("]"));
|
||||
|
||||
SendMessage(g_toolbar.hwnd, TB_CHANGEBITMAP, (WPARAM) IDM_COMPRESSOR, (LPARAM) MAKELPARAM(iBitmap, 0));
|
||||
|
||||
|
@ -155,14 +158,14 @@ void UpdateToolBarCompressorButton()
|
|||
ti.hwnd = g_toolbar.hwnd;
|
||||
ti.uId = (UINT)TBB_COMPRESSOR;
|
||||
SendMessage(g_tip.tip, TTM_GETTOOLINFO, 0, (LPARAM) (LPTOOLINFO) &ti);
|
||||
ti.lpszText = (LPSTR)szBuffer;
|
||||
ti.lpszText = (LPTSTR)szBuffer;
|
||||
SendMessage(g_tip.tip, TTM_SETTOOLINFO, 0, (LPARAM) (LPTOOLINFO) &ti);
|
||||
}
|
||||
|
||||
void AddToolBarButtonTooltip(int id, int iString)
|
||||
{
|
||||
TOOLINFO ti;
|
||||
char szBuffer[64];
|
||||
TCHAR szBuffer[64];
|
||||
RECT rect;
|
||||
|
||||
my_memset(&ti, 0, sizeof(TOOLINFO));
|
||||
|
@ -179,7 +182,7 @@ void AddToolBarButtonTooltip(int id, int iString)
|
|||
iString,
|
||||
szBuffer,
|
||||
sizeof(szBuffer));
|
||||
ti.lpszText = (LPSTR) szBuffer;
|
||||
ti.lpszText = (LPTSTR) szBuffer;
|
||||
ti.rect.left =rect.left;
|
||||
ti.rect.top = rect.top;
|
||||
ti.rect.right = rect.right;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Reviewed for Unicode support by Jim Park -- 08/20/2007
|
||||
*/
|
||||
#ifndef TOOLBAR_H
|
||||
#define TOOLBAR_H
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
// Unicode support by Jim Park -- 08/20/2007
|
||||
|
||||
#include "makensisw.h"
|
||||
#include "update.h"
|
||||
#include "noclib.h"
|
||||
|
||||
#include "jnetlib/httpget.h"
|
||||
#include "../ExDLL/nsis_tchar.h"
|
||||
|
||||
static BOOL update_initialized = FALSE;
|
||||
|
||||
|
@ -28,12 +31,12 @@ void FinalizeUpdate() {
|
|||
int getProxyInfo(char *out) {
|
||||
DWORD v=0;
|
||||
HKEY hKey;
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS) {
|
||||
if (RegOpenKeyExA(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS) {
|
||||
DWORD l = 4;
|
||||
DWORD t;
|
||||
if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD) {
|
||||
if (RegQueryValueExA(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD) {
|
||||
l=8192;
|
||||
if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)out,&l ) != ERROR_SUCCESS || t != REG_SZ) {
|
||||
if (RegQueryValueExA(hKey,"ProxyServer",NULL,&t,(unsigned char *)out,&l ) != ERROR_SUCCESS || t != REG_SZ) {
|
||||
v=0;
|
||||
*out=0;
|
||||
}
|
||||
|
@ -53,6 +56,7 @@ DWORD CALLBACK UpdateThread(LPVOID v) {
|
|||
char url[300];
|
||||
BOOL error = FALSE;
|
||||
static char pbuf[8192];
|
||||
static char ansiBuf[1024];
|
||||
char *p=NULL;
|
||||
*response = 0;
|
||||
|
||||
|
@ -72,9 +76,16 @@ DWORD CALLBACK UpdateThread(LPVOID v) {
|
|||
InitializeUpdate();
|
||||
|
||||
JNL_HTTPGet *get = new JNL_HTTPGet(g_dns,8192,(p&&p[0])?p:NULL);;
|
||||
lstrcpy(url,NSIS_UPDATE);
|
||||
lstrcat(url,g_sdata.brandingv);
|
||||
lstrcpy(response,"");
|
||||
lstrcpyA(url,NSIS_UPDATE);
|
||||
|
||||
#ifdef _UNICODE
|
||||
WideCharToMultiByte(CP_ACP, 0, g_sdata.brandingv, -1, ansiBuf, sizeof(ansiBuf), NULL, NULL);
|
||||
lstrcatA(url,ansiBuf);
|
||||
#else
|
||||
lstrcatA(url,g_sdata.brandingv);
|
||||
#endif
|
||||
|
||||
lstrcpyA(response,"");
|
||||
get->addheader("User-Agent: MakeNSISw (jnetlib)");
|
||||
get->addheader("Accept:*/*");
|
||||
get->connect(url);
|
||||
|
@ -85,10 +96,10 @@ DWORD CALLBACK UpdateThread(LPVOID v) {
|
|||
while(len=get->bytes_available()) {
|
||||
char b[RSZ];
|
||||
if (len>RSZ) len=RSZ;
|
||||
if (lstrlen(response)+len>RSZ) break;
|
||||
if (lstrlenA(response)+len>RSZ) break;
|
||||
len=get->get_bytes(b,len);
|
||||
b[len]=0;
|
||||
lstrcat(response,b);
|
||||
lstrcatA(response,b);
|
||||
}
|
||||
}
|
||||
if (st==1) break; //closed
|
||||
|
@ -100,26 +111,26 @@ DWORD CALLBACK UpdateThread(LPVOID v) {
|
|||
}
|
||||
if (error) {
|
||||
char buf[1000];
|
||||
wsprintf(buf,"There was a problem checking for an update. Please try again later.\n\nError: %s",get->geterrorstr());
|
||||
MessageBox(g_sdata.hwnd,buf,"NSIS Update",MB_OK|MB_ICONINFORMATION);
|
||||
wsprintfA(buf, "There was a problem checking for an update. Please try again later.\n\nError: %s",get->geterrorstr());
|
||||
MessageBoxA(g_sdata.hwnd,buf,"NSIS Update",MB_OK|MB_ICONINFORMATION);
|
||||
}
|
||||
else if (*response=='1'&&lstrlen(response)>2) {
|
||||
else if (*response=='1'&&lstrlenA(response)>2) {
|
||||
char buf[200];
|
||||
response+=2;
|
||||
wsprintf(buf,"NSIS %s is now available. Would you like to download it now?",response);
|
||||
if (MessageBox(g_sdata.hwnd,buf,"NSIS Update",MB_YESNO|MB_ICONINFORMATION)==IDYES) {
|
||||
ShellExecute(g_sdata.hwnd,"open",NSIS_DL_URL,NULL,NULL,SW_SHOWNORMAL);
|
||||
wsprintfA(buf, "NSIS %s is now available. Would you like to download it now?",response);
|
||||
if (MessageBoxA(g_sdata.hwnd,buf,"NSIS Update",MB_YESNO|MB_ICONINFORMATION)==IDYES) {
|
||||
ShellExecuteA(g_sdata.hwnd,"open",NSIS_DL_URL,NULL,NULL,SW_SHOWNORMAL);
|
||||
}
|
||||
}
|
||||
else if (*response=='2'&&lstrlen(response)>2) {
|
||||
else if (*response=='2'&&lstrlenA(response)>2) {
|
||||
char buf[200];
|
||||
response+=2;
|
||||
wsprintf(buf,"NSIS %s is now available. Would you like to download this preview release now?",response);
|
||||
if (MessageBox(g_sdata.hwnd,buf,"NSIS Update",MB_YESNO|MB_ICONINFORMATION)==IDYES) {
|
||||
ShellExecute(g_sdata.hwnd,"open",NSIS_DL_URL,NULL,NULL,SW_SHOWNORMAL);
|
||||
wsprintfA(buf,"NSIS %s is now available. Would you like to download this preview release now?",response);
|
||||
if (MessageBoxA(g_sdata.hwnd,buf,"NSIS Update",MB_YESNO|MB_ICONINFORMATION)==IDYES) {
|
||||
ShellExecuteA(g_sdata.hwnd,"open",NSIS_DL_URL,NULL,NULL,SW_SHOWNORMAL);
|
||||
}
|
||||
}
|
||||
else MessageBox(g_sdata.hwnd,"There is no update available for NSIS at this time.","NSIS Update",MB_OK|MB_ICONINFORMATION);
|
||||
else MessageBoxA(g_sdata.hwnd,"There is no update available for NSIS at this time.","NSIS Update",MB_OK|MB_ICONINFORMATION);
|
||||
GlobalFree(response);
|
||||
delete get;
|
||||
EnableMenuItem(g_sdata.menu,IDM_NSISUPDATE,MF_ENABLED);
|
||||
|
@ -129,9 +140,9 @@ DWORD CALLBACK UpdateThread(LPVOID v) {
|
|||
void Update() {
|
||||
DWORD dwThreadId;
|
||||
|
||||
if (my_strstr(g_sdata.brandingv,"cvs"))
|
||||
if (my_strstr(g_sdata.brandingv,_T("cvs")))
|
||||
{
|
||||
MessageBox(g_sdata.hwnd,"Cannot check for new version of nightly builds. To update, download a new nightly build.","NSIS Update",MB_OK|MB_ICONSTOP);
|
||||
MessageBox(g_sdata.hwnd,_T("Cannot check for new version of nightly builds. To update, download a new nightly build."),_T("NSIS Update"),MB_OK|MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* Reviewed for Unicode support by Jim Park -- 08/18/2007
|
||||
|
||||
/* Initialize update objects. */
|
||||
void InitializeUpdate();
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Unicode support by Jim Park -- 08/20/2007
|
||||
|
||||
*/
|
||||
|
||||
#include "makensisw.h"
|
||||
|
@ -28,46 +30,46 @@
|
|||
NTOOLTIP g_tip;
|
||||
LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
char g_mru_list[MRU_LIST_SIZE][MAX_PATH] = { "", "", "", "", "" };
|
||||
TCHAR g_mru_list[MRU_LIST_SIZE][MAX_PATH] = { _T(""), _T(""), _T(""), _T(""), _T("") };
|
||||
|
||||
extern NSCRIPTDATA g_sdata;
|
||||
extern char *compressor_names[];
|
||||
extern TCHAR *compressor_names[];
|
||||
|
||||
int SetArgv(const char *cmdLine, int *argc, char ***argv)
|
||||
int SetArgv(const TCHAR *cmdLine, int *argc, TCHAR ***argv)
|
||||
{
|
||||
const char *p;
|
||||
char *arg, *argSpace;
|
||||
const TCHAR *p;
|
||||
TCHAR *arg, *argSpace;
|
||||
int size, argSpaceSize, inquote, copy, slashes;
|
||||
|
||||
size = 2;
|
||||
for (p = cmdLine; *p != '\0'; p++) {
|
||||
if ((*p == ' ') || (*p == '\t')) {
|
||||
for (p = cmdLine; *p != _T('\0'); p++) {
|
||||
if ((*p == _T(' ')) || (*p == _T('\t'))) {
|
||||
size++;
|
||||
while ((*p == ' ') || (*p == '\t')) {
|
||||
while ((*p == _T(' ')) || (*p == _T('\t'))) {
|
||||
p++;
|
||||
}
|
||||
if (*p == '\0') {
|
||||
if (*p == _T('\0')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
argSpaceSize = size * sizeof(char *) + lstrlen(cmdLine) + 1;
|
||||
argSpace = (char *) GlobalAlloc(GMEM_FIXED, argSpaceSize);
|
||||
argSpaceSize = size * sizeof(TCHAR *) + lstrlen(cmdLine) + 1;
|
||||
argSpace = (TCHAR *) GlobalAlloc(GMEM_FIXED, argSpaceSize);
|
||||
if (!argSpace)
|
||||
return 0;
|
||||
|
||||
*argv = (char **) argSpace;
|
||||
argSpace += size * sizeof(char *);
|
||||
*argv = (TCHAR **) argSpace;
|
||||
argSpace += size * sizeof(TCHAR *);
|
||||
size--;
|
||||
|
||||
p = cmdLine;
|
||||
for (*argc = 0; *argc < size; (*argc)++) {
|
||||
(*argv)[*argc] = arg = argSpace;
|
||||
while ((*p == ' ') || (*p == '\t')) {
|
||||
while ((*p == _T(' ')) || (*p == _T('\t'))) {
|
||||
p++;
|
||||
}
|
||||
if (*p == '\0') {
|
||||
if (*p == _T('\0')) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -75,14 +77,14 @@ int SetArgv(const char *cmdLine, int *argc, char ***argv)
|
|||
slashes = 0;
|
||||
while (1) {
|
||||
copy = 1;
|
||||
while (*p == '\\') {
|
||||
while (*p == _T('\\')) {
|
||||
slashes++;
|
||||
p++;
|
||||
}
|
||||
if (*p == '"') {
|
||||
if (*p == _T('"')) {
|
||||
if ((slashes & 1) == 0) {
|
||||
copy = 0;
|
||||
if ((inquote) && (p[1] == '"')) {
|
||||
if ((inquote) && (p[1] == _T('"'))) {
|
||||
p++;
|
||||
copy = 1;
|
||||
}
|
||||
|
@ -94,12 +96,12 @@ int SetArgv(const char *cmdLine, int *argc, char ***argv)
|
|||
}
|
||||
|
||||
while (slashes) {
|
||||
*arg = '\\';
|
||||
*arg = _T('\\');
|
||||
arg++;
|
||||
slashes--;
|
||||
}
|
||||
|
||||
if ((*p == '\0') || (!inquote && ((*p == ' ') || (*p == '\t')))) {
|
||||
if ((*p == _T('\0')) || (!inquote && ((*p == _T(' ')) || (*p == _T('\t'))))) {
|
||||
break;
|
||||
}
|
||||
if (copy != 0) {
|
||||
|
@ -108,7 +110,7 @@ int SetArgv(const char *cmdLine, int *argc, char ***argv)
|
|||
}
|
||||
p++;
|
||||
}
|
||||
*arg = '\0';
|
||||
*arg = _T('\0');
|
||||
argSpace = arg + 1;
|
||||
}
|
||||
(*argv)[*argc] = NULL;
|
||||
|
@ -116,10 +118,10 @@ int SetArgv(const char *cmdLine, int *argc, char ***argv)
|
|||
return argSpaceSize;
|
||||
}
|
||||
|
||||
void SetTitle(HWND hwnd,char *substr) {
|
||||
char title[64];
|
||||
if (substr==NULL) wsprintf(title,"MakeNSISW");
|
||||
else wsprintf(title,"MakeNSISW - %s",substr);
|
||||
void SetTitle(HWND hwnd,TCHAR *substr) {
|
||||
TCHAR title[64];
|
||||
if (substr==NULL) wsprintf(title,_T("MakeNSISW"));
|
||||
else wsprintf(title,_T("MakeNSISW - %s"),substr);
|
||||
SetWindowText(hwnd,title);
|
||||
}
|
||||
|
||||
|
@ -130,9 +132,9 @@ void SetBranding(HWND hwnd) {
|
|||
void CopyToClipboard(HWND hwnd) {
|
||||
if (!hwnd||!OpenClipboard(hwnd)) return;
|
||||
int len=SendDlgItemMessage(hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0);
|
||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE,len+1);
|
||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE,(len+1)*sizeof(TCHAR));
|
||||
if (!mem) { CloseClipboard(); return; }
|
||||
char *existing_text = (char *)GlobalLock(mem);
|
||||
TCHAR *existing_text = (TCHAR *)GlobalLock(mem);
|
||||
if (!existing_text) { CloseClipboard(); return; }
|
||||
EmptyClipboard();
|
||||
existing_text[0]=0;
|
||||
|
@ -143,20 +145,20 @@ void CopyToClipboard(HWND hwnd) {
|
|||
}
|
||||
|
||||
void ClearLog(HWND hwnd) {
|
||||
SetDlgItemText(hwnd, IDC_LOGWIN, "");
|
||||
SetDlgItemText(hwnd, IDC_LOGWIN, _T(""));
|
||||
}
|
||||
|
||||
void LogMessage(HWND hwnd,const char *str) {
|
||||
void LogMessage(HWND hwnd,const TCHAR *str) {
|
||||
SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_SETSEL, g_sdata.logLength, g_sdata.logLength);
|
||||
g_sdata.logLength += lstrlen(str);
|
||||
SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_REPLACESEL, 0, (WPARAM)str);
|
||||
SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_REPLACESEL, 0, (LPARAM)str);
|
||||
SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_SCROLLCARET, 0, 0);
|
||||
}
|
||||
|
||||
void ErrorMessage(HWND hwnd,const char *str) {
|
||||
void ErrorMessage(HWND hwnd,const TCHAR *str) {
|
||||
if (!str) return;
|
||||
char buf[1028];
|
||||
wsprintf(buf,"[Error] %s\r\n",str);
|
||||
TCHAR buf[1028];
|
||||
wsprintf(buf,_T("[Error] %s\r\n"),str);
|
||||
LogMessage(hwnd,buf);
|
||||
}
|
||||
|
||||
|
@ -218,7 +220,7 @@ void Items(HWND hwnd, int on){
|
|||
void SetCompressorStats()
|
||||
{
|
||||
DWORD line_count, i;
|
||||
char buf[1024];
|
||||
TCHAR buf[1024];
|
||||
bool found = false;
|
||||
|
||||
line_count = SendDlgItemMessage(g_sdata.hwnd, IDC_LOGWIN, EM_GETLINECOUNT, 0, 0);
|
||||
|
@ -237,7 +239,7 @@ void SetCompressorStats()
|
|||
DWORD len = lstrlen(EXE_HEADER_COMPRESSOR_STAT);
|
||||
if(!lstrncmp(buf,EXE_HEADER_COMPRESSOR_STAT,len)) {
|
||||
found = true;
|
||||
lstrcpy(g_sdata.compressor_stats,"\n\n");
|
||||
lstrcpy(g_sdata.compressor_stats,_T("\n\n"));
|
||||
lstrcat(g_sdata.compressor_stats,buf);
|
||||
}
|
||||
}
|
||||
|
@ -245,7 +247,7 @@ void SetCompressorStats()
|
|||
}
|
||||
|
||||
void CompileNSISScript() {
|
||||
static char *s;
|
||||
static TCHAR *s;
|
||||
DragAcceptFiles(g_sdata.hwnd,FALSE);
|
||||
ClearLog(g_sdata.hwnd);
|
||||
SetTitle(g_sdata.hwnd,NULL);
|
||||
|
@ -270,31 +272,31 @@ void CompileNSISScript() {
|
|||
}
|
||||
if (!g_sdata.compile_command) {
|
||||
if (s) GlobalFree(s);
|
||||
char *symbols = BuildSymbols();
|
||||
TCHAR *symbols = BuildSymbols();
|
||||
|
||||
char compressor[40];
|
||||
TCHAR compressor[40];
|
||||
if(lstrlen(g_sdata.compressor_name)) {
|
||||
wsprintf(compressor,"/X\"SetCompressor /FINAL %s\"",g_sdata.compressor_name);
|
||||
wsprintf(compressor,_T("/X\"SetCompressor /FINAL %s\""),g_sdata.compressor_name);
|
||||
}
|
||||
else {
|
||||
lstrcpy(compressor,"");
|
||||
lstrcpy(compressor,_T(""));
|
||||
}
|
||||
|
||||
char *args = (char *) GlobalLock(g_sdata.script_cmd_args);
|
||||
TCHAR *args = (TCHAR *) GlobalLock(g_sdata.script_cmd_args);
|
||||
|
||||
g_sdata.compile_command = (char *) GlobalAlloc(
|
||||
GPTR,
|
||||
/* makensis.exe */ sizeof(EXENAME) + /* space */ 1 +
|
||||
/* makensis.exe */ _countof(EXENAME) + /* space */ 1 +
|
||||
/* script path */ lstrlen(g_sdata.script) + /* space */ 1 +
|
||||
/* script cmd args */ lstrlen(args) + /* space */ 1 +
|
||||
/* defines /Dblah=... */ lstrlen(symbols) + /* space */ 1 +
|
||||
/* /XSetCompressor... */ lstrlen(compressor) + /* space */ 1 +
|
||||
/* /NOTTIFYHWND + HWND */ sizeof("/NOTIFYHWND -4294967295") + /* space */ 1
|
||||
);
|
||||
/* /NOTTIFYHWND + HWND */ _countof(_T("/NOTIFYHWND -4294967295")) + /* space */ 1
|
||||
);
|
||||
|
||||
wsprintf(
|
||||
g_sdata.compile_command,
|
||||
"%s %s %s /NOTIFYHWND %d %s -- \"%s\"",
|
||||
_T("%s %s %s /NOTIFYHWND %d %s -- \"%s\""),
|
||||
EXENAME,
|
||||
compressor,
|
||||
symbols,
|
||||
|
@ -343,7 +345,7 @@ void RestoreWindowPos(HWND hwnd) {
|
|||
if (OpenRegSettingsKey(hKey)) {
|
||||
DWORD l = sizeof(p);
|
||||
DWORD t;
|
||||
if ((RegQueryValueEx(hKey,REGLOC,NULL,&t,(unsigned char*)&p,&l)==ERROR_SUCCESS)&&(t == REG_BINARY)&&(l==sizeof(p))) {
|
||||
if ((RegQueryValueEx(hKey,REGLOC,NULL,&t,(LPBYTE)&p,&l)==ERROR_SUCCESS)&&(t == REG_BINARY)&&(l==sizeof(p))) {
|
||||
int width, height;
|
||||
int windowWidth, windowHeight;
|
||||
|
||||
|
@ -391,7 +393,7 @@ void SaveWindowPos(HWND hwnd) {
|
|||
p.length = sizeof(p);
|
||||
GetWindowPlacement(hwnd, &p);
|
||||
if (OpenRegSettingsKey(hKey, true)) {
|
||||
RegSetValueEx(hKey,REGLOC,0,REG_BINARY,(unsigned char*)&p,sizeof(p));
|
||||
RegSetValueEx(hKey,REGLOC,0,REG_BINARY,(LPBYTE)&p,sizeof(p));
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
@ -406,34 +408,34 @@ void SaveSymbols()
|
|||
SaveSymbolSet(NULL, g_sdata.symbols);
|
||||
}
|
||||
|
||||
void DeleteSymbolSet(char *name)
|
||||
void DeleteSymbolSet(TCHAR *name)
|
||||
{
|
||||
if(name) {
|
||||
HKEY hKey;
|
||||
if (OpenRegSettingsKey(hKey)) {
|
||||
char subkey[1024];
|
||||
wsprintf(subkey,"%s\\%s",REGSYMSUBKEY,name);
|
||||
TCHAR subkey[1024];
|
||||
wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name);
|
||||
RegDeleteKey(hKey,subkey);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char** LoadSymbolSet(char *name)
|
||||
TCHAR** LoadSymbolSet(TCHAR *name)
|
||||
{
|
||||
HKEY hKey;
|
||||
HKEY hSubKey;
|
||||
char **symbols = NULL;
|
||||
TCHAR **symbols = NULL;
|
||||
if (OpenRegSettingsKey(hKey)) {
|
||||
char subkey[1024];
|
||||
TCHAR subkey[1024];
|
||||
if(name) {
|
||||
wsprintf(subkey,"%s\\%s",REGSYMSUBKEY,name);
|
||||
wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name);
|
||||
}
|
||||
else {
|
||||
lstrcpy(subkey,REGSYMSUBKEY);
|
||||
}
|
||||
if (RegCreateKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) {
|
||||
char buf[8];
|
||||
TCHAR buf[8];
|
||||
DWORD l;
|
||||
DWORD t;
|
||||
DWORD bufSize;
|
||||
|
@ -446,16 +448,16 @@ char** LoadSymbolSet(char *name)
|
|||
if ((RegEnumValue(hSubKey,i, buf, &bufSize,NULL,&t,NULL,&l)==ERROR_SUCCESS)&&(t == REG_SZ)) {
|
||||
if(symbols) {
|
||||
GlobalUnlock(hMem);
|
||||
hMem = GlobalReAlloc(hMem, (i+2)*sizeof(char *), GMEM_MOVEABLE|GMEM_ZEROINIT);
|
||||
symbols = (char **)GlobalLock(hMem);
|
||||
hMem = GlobalReAlloc(hMem, (i+2)*sizeof(TCHAR *), GMEM_MOVEABLE|GMEM_ZEROINIT);
|
||||
symbols = (TCHAR **)GlobalLock(hMem);
|
||||
}
|
||||
else {
|
||||
hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (i+2)*sizeof(char *));
|
||||
symbols = (char **)GlobalLock(hMem);
|
||||
hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (i+2)*sizeof(TCHAR *));
|
||||
symbols = (TCHAR **)GlobalLock(hMem);
|
||||
}
|
||||
if(symbols) {
|
||||
l++;
|
||||
symbols[i] = (char *)GlobalAlloc(GPTR, l*sizeof(char));
|
||||
symbols[i] = (TCHAR *)GlobalAlloc(GPTR, l*sizeof(TCHAR));
|
||||
if (symbols[i]) {
|
||||
RegQueryValueEx(hSubKey,buf,NULL,&t,(unsigned char*)symbols[i],&l);
|
||||
}
|
||||
|
@ -481,22 +483,22 @@ char** LoadSymbolSet(char *name)
|
|||
return symbols;
|
||||
}
|
||||
|
||||
void SaveSymbolSet(char *name, char **symbols)
|
||||
void SaveSymbolSet(TCHAR *name, TCHAR **symbols)
|
||||
{
|
||||
HKEY hKey;
|
||||
HKEY hSubKey;
|
||||
int n = 0;
|
||||
if (OpenRegSettingsKey(hKey, true)) {
|
||||
char subkey[1024];
|
||||
TCHAR subkey[1024];
|
||||
if(name) {
|
||||
wsprintf(subkey,"%s\\%s",REGSYMSUBKEY,name);
|
||||
wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name);
|
||||
}
|
||||
else {
|
||||
lstrcpy(subkey,REGSYMSUBKEY);
|
||||
}
|
||||
|
||||
if (RegOpenKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) {
|
||||
char buf[8];
|
||||
TCHAR buf[8];
|
||||
DWORD l;
|
||||
while(TRUE) {
|
||||
l = sizeof(buf);
|
||||
|
@ -511,11 +513,11 @@ void SaveSymbolSet(char *name, char **symbols)
|
|||
}
|
||||
if(symbols) {
|
||||
if (RegCreateKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) {
|
||||
char buf[8];
|
||||
TCHAR buf[8];
|
||||
n = 0;
|
||||
while(symbols[n]) {
|
||||
wsprintf(buf,"%d",n);
|
||||
RegSetValueEx(hSubKey,buf,0,REG_SZ,(CONST BYTE *)symbols[n],lstrlen(symbols[n])+1);
|
||||
wsprintf(buf,_T("%d"),n);
|
||||
RegSetValueEx(hSubKey,buf,0,REG_SZ,(CONST BYTE *)symbols[n],(lstrlen(symbols[n])+1)*sizeof(TCHAR));
|
||||
n++;
|
||||
}
|
||||
RegCloseKey(hSubKey);
|
||||
|
@ -551,9 +553,9 @@ void ResetSymbols() {
|
|||
}
|
||||
|
||||
int InitBranding() {
|
||||
char *s;
|
||||
s = (char *)GlobalAlloc(GPTR,lstrlen(EXENAME)+10);
|
||||
wsprintf(s,"%s /version",EXENAME);
|
||||
TCHAR *s;
|
||||
s = (TCHAR *)GlobalAlloc(GPTR,lstrlen(EXENAME)+10);
|
||||
wsprintf(s,_T("%s /version"),EXENAME);
|
||||
{
|
||||
STARTUPINFO si={sizeof(si),};
|
||||
SECURITY_ATTRIBUTES sa={sizeof(sa),};
|
||||
|
@ -583,7 +585,7 @@ int InitBranding() {
|
|||
CloseHandle(read_stdout);
|
||||
return 0;
|
||||
}
|
||||
char szBuf[1024];
|
||||
TCHAR szBuf[1024];
|
||||
DWORD dwRead = 1;
|
||||
if (WaitForSingleObject(pi.hProcess,10000)!=WAIT_OBJECT_0) {
|
||||
return 0;
|
||||
|
@ -591,9 +593,9 @@ int InitBranding() {
|
|||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||
szBuf[dwRead] = 0;
|
||||
if (lstrlen(szBuf)==0) return 0;
|
||||
g_sdata.branding = (char *)GlobalAlloc(GPTR,lstrlen(szBuf)+6);
|
||||
wsprintf(g_sdata.branding,"NSIS %s",szBuf);
|
||||
g_sdata.brandingv = (char *)GlobalAlloc(GPTR,lstrlen(szBuf)+1);
|
||||
g_sdata.branding = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(szBuf)+6)*sizeof(TCHAR));
|
||||
wsprintf(g_sdata.branding,_T("NSIS %s"),szBuf);
|
||||
g_sdata.brandingv = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(szBuf)+1)*sizeof(TCHAR));
|
||||
lstrcpy(g_sdata.brandingv,szBuf);
|
||||
GlobalFree(s);
|
||||
}
|
||||
|
@ -613,8 +615,8 @@ void InitTooltips(HWND h) {
|
|||
g_tip.tip = CreateWindowEx(dwExStyle,TOOLTIPS_CLASS,NULL,dwStyle,0,0,0,0,h,NULL,GetModuleHandle(NULL),NULL);
|
||||
if (!g_tip.tip) return;
|
||||
g_tip.hook = SetWindowsHookEx(WH_GETMESSAGE,TipHookProc,NULL, GetCurrentThreadId());
|
||||
AddTip(GetDlgItem(h,IDCANCEL),TEXT("Close MakeNSISW"));
|
||||
AddTip(GetDlgItem(h,IDC_TEST),TEXT("Test the installer generated by MakeNSISW"));
|
||||
AddTip(GetDlgItem(h,IDCANCEL),_T("Close MakeNSISW"));
|
||||
AddTip(GetDlgItem(h,IDC_TEST),_T("Test the installer generated by MakeNSISW"));
|
||||
AddToolBarTooltips();
|
||||
}
|
||||
|
||||
|
@ -622,7 +624,7 @@ void DestroyTooltips() {
|
|||
UnhookWindowsHookEx(g_tip.hook);
|
||||
}
|
||||
|
||||
void AddTip(HWND hWnd,LPSTR lpszToolTip) {
|
||||
void AddTip(HWND hWnd,LPTSTR lpszToolTip) {
|
||||
TOOLINFO ti;
|
||||
ti.cbSize = sizeof(TOOLINFO);
|
||||
ti.uFlags = TTF_IDISHWND;
|
||||
|
@ -646,44 +648,44 @@ LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
|||
}
|
||||
|
||||
void ShowDocs() {
|
||||
char pathf[MAX_PATH],*path;
|
||||
TCHAR pathf[MAX_PATH],*path;
|
||||
GetModuleFileName(NULL,pathf,sizeof(pathf));
|
||||
path=my_strrchr(pathf,'\\');
|
||||
path=my_strrchr(pathf,_T('\\'));
|
||||
if(path!=NULL) *path=0;
|
||||
lstrcat(pathf,LOCALDOCS);
|
||||
if ((int)ShellExecute(g_sdata.hwnd,"open",pathf,NULL,NULL,SW_SHOWNORMAL)<=32)
|
||||
ShellExecute(g_sdata.hwnd,"open",DOCPATH,NULL,NULL,SW_SHOWNORMAL);
|
||||
if ((int)ShellExecute(g_sdata.hwnd,_T("open"),pathf,NULL,NULL,SW_SHOWNORMAL)<=32)
|
||||
ShellExecuteA(g_sdata.hwnd,"open",DOCPATH,NULL,NULL,SW_SHOWNORMAL);
|
||||
}
|
||||
|
||||
char* BuildSymbols()
|
||||
TCHAR* BuildSymbols()
|
||||
{
|
||||
char *buf = NULL;
|
||||
TCHAR *buf = NULL;
|
||||
|
||||
if(g_sdata.symbols) {
|
||||
int i=0;
|
||||
while(g_sdata.symbols[i]) {
|
||||
if(buf) {
|
||||
char *buf3 = (char *)GlobalAlloc(GPTR,(lstrlen(buf)+lstrlen(g_sdata.symbols[i])+6)*sizeof(char));
|
||||
wsprintf(buf3,"%s \"/D%s\"",buf,g_sdata.symbols[i]);
|
||||
TCHAR *buf3 = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(buf)+lstrlen(g_sdata.symbols[i])+6)*sizeof(TCHAR));
|
||||
wsprintf(buf3,_T("%s \"/D%s\""),buf,g_sdata.symbols[i]);
|
||||
GlobalFree(buf);
|
||||
buf = buf3;
|
||||
}
|
||||
else {
|
||||
buf = (char *)GlobalAlloc(GPTR,(lstrlen(g_sdata.symbols[i])+5)*sizeof(char));
|
||||
wsprintf(buf,"\"/D%s\"",g_sdata.symbols[i]);
|
||||
buf = (TCHAR *)GlobalAlloc(GPTR,(lstrlen(g_sdata.symbols[i])+5)*sizeof(TCHAR));
|
||||
wsprintf(buf,_T("\"/D%s\""),g_sdata.symbols[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
buf = (char *)GlobalAlloc(GPTR, sizeof(char));
|
||||
buf[0] = '\0';
|
||||
buf = (TCHAR *)GlobalAlloc(GPTR, sizeof(TCHAR));
|
||||
buf[0] = _T('\0');
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
BOOL PopMRUFile(char* fname)
|
||||
BOOL PopMRUFile(TCHAR* fname)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -698,7 +700,7 @@ BOOL PopMRUFile(char* fname)
|
|||
for(j = i; j < MRU_LIST_SIZE-1; j++) {
|
||||
lstrcpy(g_mru_list[j],g_mru_list[j+1]);
|
||||
}
|
||||
g_mru_list[MRU_LIST_SIZE-1][0]='\0';
|
||||
g_mru_list[MRU_LIST_SIZE-1][0]=_T('\0');
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
|
@ -706,7 +708,7 @@ BOOL PopMRUFile(char* fname)
|
|||
}
|
||||
}
|
||||
|
||||
BOOL IsValidFile(char *fname)
|
||||
BOOL IsValidFile(TCHAR *fname)
|
||||
{
|
||||
WIN32_FIND_DATA wfd;
|
||||
HANDLE h;
|
||||
|
@ -719,19 +721,19 @@ BOOL IsValidFile(char *fname)
|
|||
return false;
|
||||
}
|
||||
|
||||
void PushMRUFile(char* fname)
|
||||
void PushMRUFile(TCHAR* fname)
|
||||
{
|
||||
int i;
|
||||
DWORD rv;
|
||||
char* file_part;
|
||||
char full_file_name[MAX_PATH+1];
|
||||
TCHAR* file_part;
|
||||
TCHAR full_file_name[MAX_PATH+1];
|
||||
|
||||
if(!fname || fname[0] == '\0' || fname[0] == '/' || fname[0] == '-') {
|
||||
if(!fname || fname[0] == _T('\0') || fname[0] == _T('/') || fname[0] == _T('-')) {
|
||||
return;
|
||||
}
|
||||
|
||||
my_memset(full_file_name,0,sizeof(full_file_name));
|
||||
rv = GetFullPathName(fname,sizeof(full_file_name),full_file_name,&file_part);
|
||||
rv = GetFullPathName(fname,_countof(full_file_name),full_file_name,&file_part);
|
||||
if (rv == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -751,9 +753,9 @@ void BuildMRUMenus()
|
|||
HMENU hMenu = g_sdata.fileSubmenu;
|
||||
int i;
|
||||
MENUITEMINFO mii;
|
||||
char buf[MRU_DISPLAY_LENGTH + 5/*number*/ + 1/*null*/];
|
||||
char buf2[MRU_DISPLAY_LENGTH - 6];
|
||||
char buf3[MRU_DISPLAY_LENGTH + 1];
|
||||
TCHAR buf[MRU_DISPLAY_LENGTH + 5/*number*/ + 1/*null*/];
|
||||
TCHAR buf2[MRU_DISPLAY_LENGTH - 6];
|
||||
TCHAR buf3[MRU_DISPLAY_LENGTH + 1];
|
||||
int n;
|
||||
|
||||
for(i = 0; i < MRU_LIST_SIZE; i++) {
|
||||
|
@ -770,32 +772,32 @@ void BuildMRUMenus()
|
|||
mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
|
||||
mii.wID = IDM_MRU_FILE+i;
|
||||
mii.fType = MFT_STRING;
|
||||
wsprintf(buf, "&%d ", i + 1);
|
||||
wsprintf(buf, _T("&%d "), i + 1);
|
||||
if(lstrlen(g_mru_list[i]) > MRU_DISPLAY_LENGTH) {
|
||||
char *p = my_strrchr(g_mru_list[i],'\\');
|
||||
TCHAR *p = my_strrchr(g_mru_list[i],_T('\\'));
|
||||
if(p) {
|
||||
p++;
|
||||
if(lstrlen(p) > MRU_DISPLAY_LENGTH - 7) {
|
||||
my_memset(buf2,0,sizeof(buf2));
|
||||
lstrcpyn(buf2,p,MRU_DISPLAY_LENGTH - 9);
|
||||
lstrcat(buf2,"...");
|
||||
lstrcat(buf2,_T("..."));
|
||||
|
||||
lstrcpyn(buf3,g_mru_list[i],4);
|
||||
lstrcat(buf,buf3);
|
||||
lstrcat(buf,"...\\");
|
||||
lstrcat(buf,_T("...\\"));
|
||||
lstrcat(buf,buf2);
|
||||
}
|
||||
else {
|
||||
lstrcpyn(buf3,g_mru_list[i],(MRU_DISPLAY_LENGTH - lstrlen(p) - 3));
|
||||
lstrcat(buf,buf3);
|
||||
lstrcat(buf,"...\\");
|
||||
lstrcat(buf,_T("...\\"));
|
||||
lstrcat(buf,p);
|
||||
}
|
||||
}
|
||||
else {
|
||||
lstrcpyn(buf3,g_mru_list[i],(MRU_DISPLAY_LENGTH-2));
|
||||
lstrcat(buf,buf3);
|
||||
lstrcat(buf,"...");
|
||||
lstrcat(buf,_T("..."));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -852,13 +854,13 @@ void RestoreMRUList()
|
|||
int i;
|
||||
if (OpenRegSettingsKey(hKey)) {
|
||||
if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) {
|
||||
char buf[8];
|
||||
TCHAR buf[8];
|
||||
DWORD l;
|
||||
for(int i=0; i<MRU_LIST_SIZE; i++) {
|
||||
wsprintf(buf,"%d",i);
|
||||
wsprintf(buf,_T("%d"),i);
|
||||
l = sizeof(g_mru_list[n]);
|
||||
RegQueryValueEx(hSubKey,buf,NULL,NULL,(unsigned char*)g_mru_list[n],&l);
|
||||
if(g_mru_list[n][0] != '\0') {
|
||||
RegQueryValueEx(hSubKey,buf,NULL,NULL,(LPBYTE)g_mru_list[n],&l);
|
||||
if(g_mru_list[n][0] != _T('\0')) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
@ -867,7 +869,7 @@ void RestoreMRUList()
|
|||
RegCloseKey(hKey);
|
||||
}
|
||||
for(i = n; i < MRU_LIST_SIZE; i++) {
|
||||
g_mru_list[i][0] = '\0';
|
||||
g_mru_list[i][0] = _T('\0');
|
||||
}
|
||||
|
||||
BuildMRUMenus();
|
||||
|
@ -880,10 +882,11 @@ void SaveMRUList()
|
|||
int i = 0;
|
||||
if (OpenRegSettingsKey(hKey, true)) {
|
||||
if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) {
|
||||
char buf[8];
|
||||
TCHAR buf[8];
|
||||
for(i = 0; i < MRU_LIST_SIZE; i++) {
|
||||
wsprintf(buf,"%d",i);
|
||||
RegSetValueEx(hSubKey,buf,0,REG_SZ,(const unsigned char *)g_mru_list[i],lstrlen(g_mru_list[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));
|
||||
}
|
||||
RegCloseKey(hSubKey);
|
||||
}
|
||||
|
@ -895,7 +898,7 @@ void ClearMRUList()
|
|||
{
|
||||
int i;
|
||||
for(i=0; i<MRU_LIST_SIZE; i++) {
|
||||
g_mru_list[i][0] = '\0';
|
||||
g_mru_list[i][0] = _T('\0');
|
||||
}
|
||||
|
||||
BuildMRUMenus();
|
||||
|
@ -906,11 +909,11 @@ void RestoreCompressor()
|
|||
HKEY hKey;
|
||||
NCOMPRESSOR v = COMPRESSOR_SCRIPT;
|
||||
if (OpenRegSettingsKey(hKey)) {
|
||||
char compressor_name[32];
|
||||
TCHAR compressor_name[32];
|
||||
DWORD l = sizeof(compressor_name);
|
||||
DWORD t;
|
||||
|
||||
if (RegQueryValueEx(hKey,REGCOMPRESSOR,NULL,&t,(unsigned char*)compressor_name,&l)==ERROR_SUCCESS) {
|
||||
if (RegQueryValueEx(hKey,REGCOMPRESSOR,NULL,&t,(LPBYTE)compressor_name,&l)==ERROR_SUCCESS) {
|
||||
int i;
|
||||
for(i=(int)COMPRESSOR_SCRIPT; i<= (int)COMPRESSOR_BEST; i++) {
|
||||
if(!lstrcmpi(compressor_names[i],compressor_name)) {
|
||||
|
@ -935,13 +938,14 @@ void SaveCompressor()
|
|||
}
|
||||
|
||||
if (OpenRegSettingsKey(hKey, true)) {
|
||||
RegSetValueEx(hKey,REGCOMPRESSOR,0,REG_SZ,(unsigned char*)compressor_names[n],
|
||||
lstrlen(compressor_names[n]));
|
||||
// compressor_names, even if Unicode is saved as BYTE* data.
|
||||
RegSetValueEx(hKey,REGCOMPRESSOR,0,REG_SZ,(const BYTE*)compressor_names[n],
|
||||
lstrlen(compressor_names[n])*sizeof(TCHAR));
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL FileExists(char *fname)
|
||||
BOOL FileExists(TCHAR *fname)
|
||||
{
|
||||
WIN32_FIND_DATA wfd;
|
||||
HANDLE h;
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Unicode support by Jim Park -- 08/20/2007
|
||||
|
||||
*/
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
@ -28,13 +30,13 @@
|
|||
#define MRU_LIST_SIZE 5
|
||||
#define MRU_DISPLAY_LENGTH 40
|
||||
|
||||
int SetArgv(const char *cmdLine, int *argc, char ***argv);
|
||||
void SetTitle(HWND hwnd,char *substr);
|
||||
int SetArgv(const TCHAR *cmdLine, int *argc, TCHAR ***argv);
|
||||
void SetTitle(HWND hwnd,TCHAR *substr);
|
||||
void SetBranding(HWND hwnd);
|
||||
void CopyToClipboard(HWND hwnd);
|
||||
void ClearLog(HWND hwnd);
|
||||
void LogMessage(HWND hwnd,const char *str);
|
||||
void ErrorMessage(HWND hwnd,const char *str);
|
||||
void LogMessage(HWND hwnd,const TCHAR *str);
|
||||
void ErrorMessage(HWND hwnd,const TCHAR *str);
|
||||
#define DisableItems(hwnd) Items(hwnd, 0)
|
||||
#define EnableItems(hwnd) Items(hwnd, 1)
|
||||
void Items(HWND hwnd, int on);
|
||||
|
@ -48,19 +50,19 @@ void ResetSymbols();
|
|||
int InitBranding();
|
||||
void InitTooltips(HWND h);
|
||||
void DestroyTooltips();
|
||||
void AddTip(HWND hWnd,LPSTR lpszToolTip);
|
||||
void AddTip(HWND hWnd,LPTSTR lpszToolTip);
|
||||
void ShowDocs();
|
||||
void RestoreCompressor();
|
||||
void SaveCompressor();
|
||||
void SetCompressorStats();
|
||||
|
||||
BOOL PopMRUFile(char* fname);
|
||||
void PushMRUFile(char* fname);
|
||||
BOOL PopMRUFile(TCHAR* fname);
|
||||
void PushMRUFile(TCHAR* fname);
|
||||
void BuildMRUMenus();
|
||||
void LoadMRUFile(int position);
|
||||
void ClearMRUList();
|
||||
|
||||
BOOL FileExists(char *fname);
|
||||
BOOL FileExists(TCHAR *fname);
|
||||
|
||||
HMENU FindSubMenu(HMENU hMenu, UINT uId);
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 2002 Robert Rainwater
|
||||
Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely
|
||||
Contributors: Justin Frankel, Fritz Elfert, Amir Szekely and
|
||||
Jim Park (Unicode Support)
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@ -18,12 +19,13 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Unicode support by Jim Park -- 08/17/2007
|
||||
*/
|
||||
#define REALSTR(x) #x
|
||||
#define STR(x) REALSTR(x)
|
||||
|
||||
#ifdef RELEASE
|
||||
const char *NSISW_VERSION = "MakeNSISW " STR(RELEASE) " (NSIS Compiler Interface)";
|
||||
const char *NSISW_VERSION = "MakeNSISW " STR(RELEASE) " (NSIS Compiler Interface)";
|
||||
#else
|
||||
const char *NSISW_VERSION = "MakeNSISW " __DATE__;
|
||||
const char *NSISW_VERSION = "MakeNSISW " __DATE__;
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Unicode support by Jim Park -- 08/22/2007
|
||||
|
||||
#include <windows.h>
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
#include "MyMath.h"
|
||||
|
@ -15,12 +17,12 @@ int UserVarsCount, UserFuncsCount;
|
|||
UserVar UserVars[MAX_USER_VARS];
|
||||
UserFunc UserFuncs[MAX_USER_FUNCS];
|
||||
|
||||
void PrintTree(ExpressionItem *root, char *str);
|
||||
void ParseString(char *&sp, ExpressionItem* &itemplace);
|
||||
void PrintTree(ExpressionItem *root, TCHAR *str);
|
||||
void ParseString(TCHAR *&sp, ExpressionItem* &itemplace);
|
||||
void CleanupItems(ExpressionItem* &itemplace);
|
||||
void PlaceVariable(char *&vb, ParseInfo *pi);
|
||||
void PlaceVariable(TCHAR *&vb, ParseInfo *pi);
|
||||
|
||||
void PlaceNewItem(char *&vb, ParseInfo *pi, int precedence)
|
||||
void PlaceNewItem(TCHAR *&vb, ParseInfo *pi, int precedence)
|
||||
{
|
||||
ExpressionItem *newroot;
|
||||
PlaceVariable(vb, pi);
|
||||
|
@ -56,12 +58,12 @@ void PlaceNewItem(char *&vb, ParseInfo *pi, int precedence)
|
|||
#define NSIS_VARS_STACK 25
|
||||
#define NSIS_VARS_NSTACK 26
|
||||
|
||||
typedef char smallstr[2];
|
||||
const smallstr NSISVariablesNames[NSIS_VARS_COUNT] = {{'r','0'}, {'r','1'}, {'r','2'}, {'r','3'}, {'r','4'}, {'r','5'}, {'r','6'}, {'r','7'}, {'r','8'}, {'r','9'},
|
||||
{'R','0'}, {'R','1'}, {'R','2'}, {'R','3'}, {'R','4'}, {'R','5'}, {'R','6'}, {'R','7'}, {'R','8'}, {'R','9'},
|
||||
{'C','L'}, {'I','D'}, {'O','D'}, {'E','D'}, {'L','G'}, {'S',0}, {'N','S'}};
|
||||
typedef TCHAR smallstr[2];
|
||||
const smallstr NSISVariablesNames[NSIS_VARS_COUNT] = {{_T('r'),_T('0')}, {_T('r'),_T('1')}, {_T('r'),_T('2')}, {_T('r'),_T('3')}, {_T('r'),_T('4')}, {_T('r'),_T('5')}, {_T('r'),_T('6')}, {_T('r'),_T('7')}, {_T('r'),_T('8')}, {_T('r'),_T('9')},
|
||||
{_T('R'),_T('0')}, {_T('R'),_T('1')}, {_T('R'),_T('2')}, {_T('R'),_T('3')}, {_T('R'),_T('4')}, {_T('R'),_T('5')}, {_T('R'),_T('6')}, {_T('R'),_T('7')}, {_T('R'),_T('8')}, {_T('R'),_T('9')},
|
||||
{_T('C'),_T('L')}, {_T('I'),_T('D')}, {_T('O'),_T('D')}, {_T('E'),_T('D')}, {_T('L'),_T('G')}, {_T('S'),0}, {_T('N'),_T('S')}};
|
||||
|
||||
ExpressionItem *FindVariable(char *varname)
|
||||
ExpressionItem *FindVariable(TCHAR *varname)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -98,7 +100,7 @@ ExpressionItem *FindVariable(char *varname)
|
|||
return item;
|
||||
}
|
||||
|
||||
void PlaceVariable(char *&vb, ParseInfo *pi)
|
||||
void PlaceVariable(TCHAR *&vb, ParseInfo *pi)
|
||||
{
|
||||
if (vb <= pi->valbuf) return;
|
||||
*vb = 0;
|
||||
|
@ -112,43 +114,43 @@ typedef double (*math_di)(double, int*);
|
|||
|
||||
#define MATHFUNCNUM 29
|
||||
const MathFunction MathFunctions[MATHFUNCNUM] = {
|
||||
{{'s','i','n'}, ITF_MATH1 >> 8, sin},
|
||||
{{'s','n','h'}, ITF_MATH1 >> 8, sinh},
|
||||
{{'a','s','n'}, ITF_MATH1 >> 8, asin},
|
||||
{{'c','o','s'}, ITF_MATH1 >> 8, cos},
|
||||
{{'c','s','h'}, ITF_MATH1 >> 8, cosh},
|
||||
{{'a','c','s'}, ITF_MATH1 >> 8, acos},
|
||||
{{'t','a','n'}, ITF_MATH1 >> 8, tan},
|
||||
{{'t','n','h'}, ITF_MATH1 >> 8, tanh},
|
||||
{{'a','t','n'}, ITF_MATH1 >> 8, atan},
|
||||
{{'a','b','s'}, ITF_MATH1 >> 8, fabs},
|
||||
{{'l','n',0}, ITF_MATH1 >> 8, log},
|
||||
{{'l','o','g'}, ITF_MATH1 >> 8, log10},
|
||||
{{'e','x','p'}, ITF_MATH1 >> 8, exp},
|
||||
{{'s','q','t'}, ITF_MATH1 >> 8, sqrt},
|
||||
{{'c','e','l'}, ITF_MATH1 >> 8, ceil},
|
||||
{{'f','l','r'}, ITF_MATH1 >> 8, floor},
|
||||
{{_T('s'),_T('i'),_T('n')}, ITF_MATH1 >> 8, sin},
|
||||
{{_T('s'),_T('n'),_T('h')}, ITF_MATH1 >> 8, sinh},
|
||||
{{_T('a'),_T('s'),_T('n')}, ITF_MATH1 >> 8, asin},
|
||||
{{_T('c'),_T('o'),_T('s')}, ITF_MATH1 >> 8, cos},
|
||||
{{_T('c'),_T('s'),_T('h')}, ITF_MATH1 >> 8, cosh},
|
||||
{{_T('a'),_T('c'),_T('s')}, ITF_MATH1 >> 8, acos},
|
||||
{{_T('t'),_T('a'),_T('n')}, ITF_MATH1 >> 8, tan},
|
||||
{{_T('t'),_T('n'),_T('h')}, ITF_MATH1 >> 8, tanh},
|
||||
{{_T('a'),_T('t'),_T('n')}, ITF_MATH1 >> 8, atan},
|
||||
{{_T('a'),_T('b'),_T('s')}, ITF_MATH1 >> 8, fabs},
|
||||
{{_T('l'),_T('n'),0}, ITF_MATH1 >> 8, log},
|
||||
{{_T('l'),_T('o'),_T('g')}, ITF_MATH1 >> 8, log10},
|
||||
{{_T('e'),_T('x'),_T('p')}, ITF_MATH1 >> 8, exp},
|
||||
{{_T('s'),_T('q'),_T('t')}, ITF_MATH1 >> 8, sqrt},
|
||||
{{_T('c'),_T('e'),_T('l')}, ITF_MATH1 >> 8, ceil},
|
||||
{{_T('f'),_T('l'),_T('r')}, ITF_MATH1 >> 8, floor},
|
||||
|
||||
{{'a','t','2'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)atan2},
|
||||
{{'p','o','w'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)pow},
|
||||
{{'f','m','d'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)fmod},
|
||||
{{_T('a'),_T('t'),_T('2')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)atan2},
|
||||
{{_T('p'),_T('o'),_T('w')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)pow},
|
||||
{{_T('f'),_T('m'),_T('d')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_d2)fmod},
|
||||
|
||||
// type conversions
|
||||
{{'i',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_INT},
|
||||
{{'s',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_STRING},
|
||||
{{'f',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_FLOAT},
|
||||
{{'a',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY},
|
||||
{{_T('i'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_INT},
|
||||
{{_T('s'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_STRING},
|
||||
{{_T('f'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_FLOAT},
|
||||
{{_T('a'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY},
|
||||
#define ITFT_CARRAY_ID 23
|
||||
{{'c','a',0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY},
|
||||
{{'f','f',0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_FLOATF},
|
||||
{{'l',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_LEN},
|
||||
{{'c',0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_CHAR},
|
||||
{{_T('c'),_T('a'),0}, ITF_TYPE >> 8, (Math1FuncPtr)ITC_ARRAY},
|
||||
{{_T('f'),_T('f'),0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_FLOATF},
|
||||
{{_T('l'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_LEN},
|
||||
{{_T('c'),0,0}, ITF_TYPE >> 8, (Math1FuncPtr)FTT_CHAR},
|
||||
|
||||
{{'f','e','x'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_di)frexp},
|
||||
{{'m','d','f'}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_ddp)modf},
|
||||
{{_T('f'),_T('e'),_T('x')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_di)frexp},
|
||||
{{_T('m'),_T('d'),_T('f')}, ITF_MATH2 >> 8, (Math1FuncPtr)(math_ddp)modf},
|
||||
};
|
||||
|
||||
void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
||||
void PlaceFunction(TCHAR *&vb, TCHAR *&sp, ParseInfo *pi, int redefine)
|
||||
{
|
||||
int i;
|
||||
ExpressionItem *item = pi->item = AllocItem();
|
||||
|
@ -163,7 +165,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
|||
// get first argument
|
||||
sp++;
|
||||
ParseString(sp, *((ExpressionItem **)(&item->param1)));
|
||||
if (*sp == ',')
|
||||
if (*sp == _T(','))
|
||||
{
|
||||
// get second argument
|
||||
sp++;
|
||||
|
@ -185,7 +187,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
|||
item->type = IT_FUNCTION | ITF_USER | i;
|
||||
// get arguments list
|
||||
ExpressionItem **newplace = ((ExpressionItem **)(&pi->item->param1));
|
||||
while (*sp != ')')
|
||||
while (*sp != _T(')'))
|
||||
{
|
||||
*newplace = AllocItem();
|
||||
(*newplace)->type = IT_EXPRESSION;
|
||||
|
@ -203,7 +205,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
|||
|
||||
// it's user function define
|
||||
int flags = 0;
|
||||
char buffer[128], *buf = buffer;
|
||||
TCHAR buffer[128], *buf = buffer;
|
||||
|
||||
// workaround for redefine flag - if the function already present,
|
||||
// it will be cleared and redefined
|
||||
|
@ -219,10 +221,10 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
|||
sp++;
|
||||
switch (*sp)
|
||||
{
|
||||
case ' ':
|
||||
case _T(' '):
|
||||
break;
|
||||
case ',':
|
||||
case ')':
|
||||
case _T(','):
|
||||
case _T(')'):
|
||||
if (buf > buffer)
|
||||
{
|
||||
*buf = 0;
|
||||
|
@ -234,7 +236,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
|||
flags <<= 1;
|
||||
}
|
||||
break;
|
||||
case '&':
|
||||
case _T('&'):
|
||||
flags |= 1;
|
||||
break;
|
||||
default:
|
||||
|
@ -242,7 +244,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
|||
break;
|
||||
}
|
||||
}
|
||||
while (*sp != ')');
|
||||
while (*sp != _T(')'));
|
||||
|
||||
// prepare flag for fast analisys
|
||||
for (i = 0; i < f->varsnum; i++)
|
||||
|
@ -253,7 +255,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
|||
}
|
||||
|
||||
// find nearest round bracket - function body
|
||||
while (*sp != '(' && *sp) sp++;
|
||||
while (*sp != _T('(') && *sp) sp++;
|
||||
if (!*sp)
|
||||
return;
|
||||
sp++;
|
||||
|
@ -265,17 +267,17 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
|||
|
||||
#ifdef _DEBUG
|
||||
// dump function (in debug mode)
|
||||
char place[1024];
|
||||
wsprintf(place, "function %s(", f->name);
|
||||
TCHAR place[1024];
|
||||
wsprintf(place, _T("function %s("), f->name);
|
||||
flags = f->varflags;
|
||||
for (i = 0; i < f->varsnum; i++)
|
||||
{
|
||||
if (flags&1) lstrcat(place, "&");
|
||||
if (flags&1) lstrcat(place, _T("&"));
|
||||
lstrcat(place, UserVars[f->vars[i]].name);
|
||||
if (i < f->varsnum-1) lstrcat(place, ", ");
|
||||
if (i < f->varsnum-1) lstrcat(place, _T(", "));
|
||||
flags >>= 1;
|
||||
}
|
||||
lstrcat(place, ")");
|
||||
lstrcat(place, _T(")"));
|
||||
PrintTree(f->root, place);
|
||||
#endif
|
||||
}
|
||||
|
@ -290,7 +292,7 @@ void PlaceFunction(char *&vb, char *&sp, ParseInfo *pi, int redefine)
|
|||
#define PO_USESPRE 0x40 // operator will use pre operand
|
||||
#define PO_USESPOST 0x80 // operator will use post operan
|
||||
|
||||
void PlaceOp(char *&vb, int type, int precedence, ParseInfo *pi)
|
||||
void PlaceOp(TCHAR *&vb, int type, int precedence, ParseInfo *pi)
|
||||
{
|
||||
PlaceVariable(vb, pi);
|
||||
if ((type & PO_UNARYPRE) && (!pi->item))
|
||||
|
@ -332,54 +334,54 @@ void PlaceOp(char *&vb, int type, int precedence, ParseInfo *pi)
|
|||
const OpStruct Operators[OPSNUM] =
|
||||
{
|
||||
// three byte ops
|
||||
{{'>','>','='}, 14, ITO_SHR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{{'<','<','='}, 14, ITO_SHL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{{_T('>'),_T('>'),_T('=')}, 14, ITO_SHR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{{_T('<'),_T('<'),_T('=')}, 14, ITO_SHL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
|
||||
// two byte ops
|
||||
// !!! don't forget to change Set Operator Precedence !!!
|
||||
{"-=", 14, ITO_MINUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{"+=", 14, ITO_PLUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{"/=", 14, ITO_DIV | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{"*=", 14, ITO_MUL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{"|=", 14, ITO_OR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{"&=", 14, ITO_AND | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{"^=", 14, ITO_XOR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{"%=", 14, ITO_MOD | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{"--", 2, ITO_DEC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{"++", 2, ITO_INC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{">>", 6, ITO_SHR | PO_USESPRE | PO_USESPOST},
|
||||
{"<<", 6, ITO_SHL | PO_USESPRE | PO_USESPOST},
|
||||
{_T("-="), 14, ITO_MINUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T("+="), 14, ITO_PLUS | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T("/="), 14, ITO_DIV | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T("*="), 14, ITO_MUL | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T("|="), 14, ITO_OR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T("&="), 14, ITO_AND | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T("^="), 14, ITO_XOR | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T("%="), 14, ITO_MOD | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T("--"), 2, ITO_DEC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T("++"), 2, ITO_INC | PO_POSTNONCONST | PO_PRENONCONST | PO_UNARYPRE | PO_UNARYPOST | PO_SET | PO_USESPRE | PO_USESPOST},
|
||||
{_T(">>"), 6, ITO_SHR | PO_USESPRE | PO_USESPOST},
|
||||
{_T("<<"), 6, ITO_SHL | PO_USESPRE | PO_USESPOST},
|
||||
|
||||
// logical
|
||||
{"&&", 12, ITO_LAND | PO_USESPRE | PO_USESPOST},
|
||||
{"||", 13, ITO_LOR | PO_USESPRE | PO_USESPOST},
|
||||
{_T("&&"), 12, ITO_LAND | PO_USESPRE | PO_USESPOST},
|
||||
{_T("||"), 13, ITO_LOR | PO_USESPRE | PO_USESPOST},
|
||||
|
||||
// comparisons
|
||||
{"<=", 7, ITO_LE | PO_USESPRE | PO_USESPOST},
|
||||
{"=<", 7, ITO_LE | PO_USESPRE | PO_USESPOST},
|
||||
{">=", 7, ITO_GE | PO_USESPRE | PO_USESPOST},
|
||||
{"=>", 7, ITO_GE | PO_USESPRE | PO_USESPOST},
|
||||
{"!=", 8, ITO_NE | PO_USESPRE | PO_USESPOST},
|
||||
{"==", 8, ITO_EQ | PO_USESPRE | PO_USESPOST},
|
||||
{_T("<="), 7, ITO_LE | PO_USESPRE | PO_USESPOST},
|
||||
{_T("=<"), 7, ITO_LE | PO_USESPRE | PO_USESPOST},
|
||||
{_T(">="), 7, ITO_GE | PO_USESPRE | PO_USESPOST},
|
||||
{_T("=>"), 7, ITO_GE | PO_USESPRE | PO_USESPOST},
|
||||
{_T("!="), 8, ITO_NE | PO_USESPRE | PO_USESPOST},
|
||||
{_T("=="), 8, ITO_EQ | PO_USESPRE | PO_USESPOST},
|
||||
|
||||
// single byte ops
|
||||
// !!! don't forget to change Set Operator Precedence !!!
|
||||
{"=", 14, ITO_SET | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPOST},
|
||||
{"+", 5, ITO_PLUS | PO_USESPRE | PO_USESPOST},
|
||||
{"-", 5, ITO_MINUS | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
|
||||
{"*", 4, ITO_MUL | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
|
||||
{"/", 4, ITO_DIV | PO_USESPRE | PO_USESPOST},
|
||||
{"%", 4, ITO_MOD | PO_USESPRE | PO_USESPOST},
|
||||
{"<", 7, ITO_LS | PO_USESPRE | PO_USESPOST},
|
||||
{">", 7, ITO_GR | PO_USESPRE | PO_USESPOST},
|
||||
{"&", 9, ITO_AND | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
|
||||
{"|", 11, ITO_OR | PO_USESPRE | PO_USESPOST},
|
||||
{"^", 10, ITO_XOR | PO_USESPRE | PO_USESPOST},
|
||||
{"~", 3, ITO_NOT | PO_USESPOST | PO_UNARYPRE},
|
||||
{"!", 3, ITO_LNOT |PO_USESPOST | PO_UNARYPRE}
|
||||
{_T("="), 14, ITO_SET | PO_PRENONCONST | PO_LASTOP | PO_SET | PO_USESPOST},
|
||||
{_T("+"), 5, ITO_PLUS | PO_USESPRE | PO_USESPOST},
|
||||
{_T("-"), 5, ITO_MINUS | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
|
||||
{_T("*"), 4, ITO_MUL | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
|
||||
{_T("/"), 4, ITO_DIV | PO_USESPRE | PO_USESPOST},
|
||||
{_T("%"), 4, ITO_MOD | PO_USESPRE | PO_USESPOST},
|
||||
{_T("<"), 7, ITO_LS | PO_USESPRE | PO_USESPOST},
|
||||
{_T(">"), 7, ITO_GR | PO_USESPRE | PO_USESPOST},
|
||||
{_T("&"), 9, ITO_AND | PO_USESPRE | PO_USESPOST | PO_UNARYPRE},
|
||||
{_T("|"), 11, ITO_OR | PO_USESPRE | PO_USESPOST},
|
||||
{_T("^"), 10, ITO_XOR | PO_USESPRE | PO_USESPOST},
|
||||
{_T("~"), 3, ITO_NOT | PO_USESPOST | PO_UNARYPRE},
|
||||
{_T("!"), 3, ITO_LNOT |PO_USESPOST | PO_UNARYPRE}
|
||||
};
|
||||
|
||||
void CheckForOperator(char *&sp, char *&vb, ParseInfo *pi)
|
||||
void CheckForOperator(TCHAR *&sp, TCHAR *&vb, ParseInfo *pi)
|
||||
{
|
||||
for (int op = 0; op < OPSNUM; op++)
|
||||
{
|
||||
|
@ -397,44 +399,44 @@ void CheckForOperator(char *&sp, char *&vb, ParseInfo *pi)
|
|||
}
|
||||
}
|
||||
|
||||
void ParseString(char *&sp, ExpressionItem* &itemplace)
|
||||
void ParseString(TCHAR *&sp, ExpressionItem* &itemplace)
|
||||
{
|
||||
ParseInfo pi = {0, NULL, NULL, &itemplace, &itemplace};
|
||||
|
||||
int redefine = 0;
|
||||
char *vb = pi.valbuf;
|
||||
TCHAR *vb = pi.valbuf;
|
||||
// cycle until current expression end
|
||||
while ((*sp != 0) && (*sp != ')') && (*sp != '}') &&
|
||||
(*sp != ']') && (*sp != ','))
|
||||
while ((*sp != 0) && (*sp != _T(')')) && (*sp != _T('}')) &&
|
||||
(*sp != _T(']')) && (*sp != _T(',')))
|
||||
{
|
||||
int processed = 1;
|
||||
switch (*sp)
|
||||
{
|
||||
case ' ':
|
||||
case '\t':
|
||||
case _T(' '):
|
||||
case _T('\t'):
|
||||
sp++;
|
||||
break;
|
||||
case ';':
|
||||
case _T(';'):
|
||||
// expression delimeter
|
||||
PlaceNewItem(vb, &pi, 255);
|
||||
if (*pi.root) pi.SetupNewRoot = 1;
|
||||
sp++;
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'):
|
||||
case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'):
|
||||
// variable & function names could contain numbers as non first chars
|
||||
if (vb > pi.valbuf)
|
||||
{
|
||||
processed = FALSE;
|
||||
break;
|
||||
}
|
||||
case '\'': case '\"': case '`':
|
||||
case _T('\''): case _T('\"'): case _T('`'):
|
||||
// constant meet
|
||||
pi.item = AllocItem();
|
||||
StringToItem(sp, pi.item, STI_STRING | STI_FLOAT | STI_INT);
|
||||
break;
|
||||
|
||||
case '(': // start of function or expression
|
||||
case _T('('): // start of function or expression
|
||||
if (vb > pi.valbuf)
|
||||
{
|
||||
// thats function
|
||||
|
@ -444,14 +446,14 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
|
|||
// expression
|
||||
sp++;
|
||||
ParseString(sp, pi.item);
|
||||
if (*sp == ')') sp++;
|
||||
if (*sp == _T(')')) sp++;
|
||||
}
|
||||
redefine = 0;
|
||||
break;
|
||||
|
||||
case '#': // start of one of logical expresions
|
||||
case _T('#'): // start of one of logical expresions
|
||||
sp++;
|
||||
if ((*sp != '[') && (*sp != '{'))
|
||||
if ((*sp != _T('[')) && (*sp != _T('{')))
|
||||
{
|
||||
// function redefine flag
|
||||
redefine = 1;
|
||||
|
@ -460,14 +462,14 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
|
|||
{
|
||||
pi.item = AllocItem();
|
||||
// IF or WHILE
|
||||
pi.item->type = ((*sp == '[')?(IT_LOGIC | ITL_IF):(IT_LOGIC | ITL_WHILE));
|
||||
pi.item->type = ((*sp == _T('['))?(IT_LOGIC | ITL_IF):(IT_LOGIC | ITL_WHILE));
|
||||
// first expr - logic statement
|
||||
sp++;
|
||||
|
||||
ParseString(sp, *((ExpressionItem **)(&pi.item->param1)));
|
||||
// ok, second expr - then, third - else statement.. others???
|
||||
ExpressionItem **newplace = ((ExpressionItem **)(&pi.item->param2));
|
||||
while (*sp == ',')
|
||||
while (*sp == _T(','))
|
||||
{
|
||||
*newplace = AllocItem();
|
||||
(*newplace)->type = IT_EXPRESSION;
|
||||
|
@ -479,14 +481,14 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
|
|||
sp++;
|
||||
break;
|
||||
|
||||
case '[':
|
||||
case _T('['):
|
||||
{
|
||||
// thats array access
|
||||
PlaceOp(vb, IT_ARRAY | ITA_ACCESS | PO_UNARYPOST, 1, &pi);
|
||||
sp++;
|
||||
// item index
|
||||
ParseString(sp, *(ExpressionItem **)&(pi.item->param2));
|
||||
if (*sp == ',')
|
||||
if (*sp == _T(','))
|
||||
{
|
||||
// two indexes - string access
|
||||
ExpressionItem *it = AllocItem();
|
||||
|
@ -502,7 +504,7 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
|
|||
}
|
||||
break;
|
||||
|
||||
case '{': // start of array define
|
||||
case _T('{'): // start of array define
|
||||
{
|
||||
// array define - constists of array copy operator and array define itself
|
||||
|
||||
|
@ -516,7 +518,7 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
|
|||
ArrayDesc *ad = *((ArrayDesc**)&(ai->param1));
|
||||
|
||||
// parse array initializers
|
||||
while (*sp != '}')
|
||||
while (*sp != _T('}'))
|
||||
{
|
||||
sp++;
|
||||
ParseString(sp, ad->array[ad->count]);
|
||||
|
@ -527,9 +529,9 @@ void ParseString(char *&sp, ExpressionItem* &itemplace)
|
|||
sp++;
|
||||
}
|
||||
break;
|
||||
case '-': case '+': case '<': case '=': case '>':
|
||||
case '/': case '*': case '~': case '^': case '!':
|
||||
case '&': case '|': case '%':
|
||||
case _T('-'): case _T('+'): case _T('<'): case _T('='): case _T('>'):
|
||||
case _T('/'): case _T('*'): case _T('~'): case _T('^'): case _T('!'):
|
||||
case _T('&'): case _T('|'): case _T('%'):
|
||||
CheckForOperator(sp, vb, &pi);
|
||||
break;
|
||||
|
||||
|
@ -594,8 +596,8 @@ void CleanupItems(ExpressionItem* &itemplace)
|
|||
#ifdef _DEBUG
|
||||
HANDLE myfile;
|
||||
|
||||
char *opsnames[] = {"", "-", "+", "<<", ">>", "*", "/", "=", "&&", "||", "++", "--",
|
||||
"=<", ">=", "!=", "==", "<", ">", "&", "%", "|", "^", "~", "!"};
|
||||
TCHAR *opsnames[] = {_T(""), _T("-"), _T("+"), _T("<<"), _T(">>"), _T("*"), _T("/"), _T("="), _T("&&"), _T("||"), _T("++"), _T("--"),
|
||||
_T("=<"), _T(">="), _T("!="), _T("=="), _T("<"), _T(">"), _T("&"), _T("%"), _T("|"), _T("^"), _T("~"), _T("!")};
|
||||
|
||||
void PrintNode(int index, int spaces, ExpressionItem* itemplace)
|
||||
{
|
||||
|
@ -605,7 +607,7 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace)
|
|||
do
|
||||
{
|
||||
DWORD wrote;
|
||||
char buffer[1024], *place = buffer;
|
||||
TCHAR buffer[1024], *place = buffer;
|
||||
for (int k = 0; k < spaces; k++)
|
||||
*(place++) = 32;
|
||||
*place = 0;
|
||||
|
@ -613,100 +615,100 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace)
|
|||
switch (item->type & ITEMTYPE)
|
||||
{
|
||||
case IT_EXPRESSION:
|
||||
wsprintf(place, "Expression Place-Holder ");
|
||||
wsprintf(place, _T("Expression Place-Holder "));
|
||||
break;
|
||||
case IT_CONST:
|
||||
switch (item->type & ITEMSUBTYPE)
|
||||
{
|
||||
case ITC_STRING:
|
||||
wsprintf(place, "String: \"%s\"", (char *) item->param1);
|
||||
wsprintf(place, _T("String: \"%s\""), (TCHAR *) item->param1);
|
||||
break;
|
||||
case ITC_INT:
|
||||
wsprintf(place, "Int: ");
|
||||
wsprintf(place, _T("Int: "));
|
||||
itoa64(*((__int64*)&(item->param1)), place+5);
|
||||
break;
|
||||
case ITC_FLOAT:
|
||||
wsprintf(place, "Float: ");
|
||||
wsprintf(place, _T("Float: "));
|
||||
FloatFormat(place+7, *((double*)&(item->param1)), 6);
|
||||
break;
|
||||
case ITC_ARRAY:
|
||||
ArrayDesc *ad = (ArrayDesc*) item->param1;
|
||||
wsprintf(place, "Array, ptr %08X, size %d, count %d, references %d",
|
||||
wsprintf(place, _T("Array, ptr %08X, size %d, count %d, references %d"),
|
||||
ad->array, ad->size, ad->count, ad->references);
|
||||
break;
|
||||
}
|
||||
strcat(place, " ");
|
||||
_tcscat(place, _T(" "));
|
||||
break;
|
||||
case IT_OPERATOR:
|
||||
wsprintf(place, "Op: %s%s ", opsnames[(item->type & ITEMSUBTYPE) >> 8], (item->type & PO_SET)?("(=)"):(""));
|
||||
wsprintf(place, _T("Op: %s%s "), opsnames[(item->type & ITEMSUBTYPE) >> 8], (item->type & PO_SET)?(_T("(=)")):(_T("")));
|
||||
break;
|
||||
case IT_VARIABLE:
|
||||
switch (item->type & ITEMSUBTYPE)
|
||||
{
|
||||
case ITV_NSIS:
|
||||
{
|
||||
char buffer[128];
|
||||
TCHAR buffer[128];
|
||||
buffer[0] = NSISVariablesNames[item->type & ITEMOPTIONS][0];
|
||||
buffer[1] = NSISVariablesNames[item->type & ITEMOPTIONS][1];
|
||||
buffer[2] = 0;
|
||||
wsprintf(place, "Var: %s (%d) ",
|
||||
wsprintf(place, _T("Var: %s (%d) "),
|
||||
buffer,
|
||||
item->type & ITEMOPTIONS);
|
||||
}
|
||||
break;
|
||||
case ITV_USER:
|
||||
wsprintf(place, "Var: %s (%d) ", UserVars[item->type & ITEMOPTIONS].name, item->type & ITEMOPTIONS);
|
||||
wsprintf(place, _T("Var: %s (%d) "), UserVars[item->type & ITEMOPTIONS].name, item->type & ITEMOPTIONS);
|
||||
break;
|
||||
case ITV_STACK:
|
||||
wsprintf(place, "Plugin Stack ");
|
||||
wsprintf(place, _T("Plugin Stack "));
|
||||
break;
|
||||
case ITV_NSTACK:
|
||||
wsprintf(place, "NSIS Stack ");
|
||||
wsprintf(place, _T("NSIS Stack "));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IT_LOGIC:
|
||||
if ((item->type & ITEMSUBTYPE) == ITL_IF)
|
||||
wsprintf(place, "IF ");
|
||||
wsprintf(place, _T("IF "));
|
||||
else
|
||||
wsprintf(place, "WHILE ");
|
||||
wsprintf(place, _T("WHILE "));
|
||||
break;
|
||||
case IT_FUNCTION:
|
||||
if (((item->type & ITEMSUBTYPE) == ITF_MATH1) ||
|
||||
((item->type & ITEMSUBTYPE) == ITF_MATH2) ||
|
||||
((item->type & ITEMSUBTYPE) == ITF_TYPE))
|
||||
{
|
||||
char buffer[128];
|
||||
TCHAR buffer[128];
|
||||
buffer[0] = (MathFunctions[item->type &ITEMOPTIONS].name)[0];
|
||||
buffer[1] = (MathFunctions[item->type &ITEMOPTIONS].name)[1];
|
||||
buffer[2] = (MathFunctions[item->type &ITEMOPTIONS].name)[2];
|
||||
buffer[3] = 0;
|
||||
wsprintf(place, "Built-In Function %s() [%d] ",
|
||||
wsprintf(place, _T("Built-In Function %s() [%d] "),
|
||||
buffer,
|
||||
item->type &ITEMOPTIONS);
|
||||
}
|
||||
else
|
||||
{
|
||||
UserFunc *f = &(UserFuncs[item->type & ITEMOPTIONS]);
|
||||
wsprintf(place, "User Function: %s(", f->name);
|
||||
wsprintf(place, _T("User Function: %s("), f->name);
|
||||
int flags = f->varflags;
|
||||
for (int i = 0; i < f->varsnum; i++)
|
||||
{
|
||||
if (flags&1) lstrcat(place, "&");
|
||||
if (flags&1) lstrcat(place, _T("&"));
|
||||
lstrcat(place, UserVars[f->vars[i]].name);
|
||||
if (i < f->varsnum-1) lstrcat(place, ", ");
|
||||
if (i < f->varsnum-1) lstrcat(place, _T(", "));
|
||||
flags >>= 1;
|
||||
}
|
||||
lstrcat(place, ") ");
|
||||
lstrcat(place, _T(") "));
|
||||
}
|
||||
break;
|
||||
case IT_ARRAY:
|
||||
wsprintf(place, "Array access [] ");
|
||||
wsprintf(place, _T("Array access [] "));
|
||||
break;
|
||||
}
|
||||
place += lstrlen(place);
|
||||
wsprintf(place, "Addr: %08X Type: %08X Next: %08X Param1: %08X Param2: %08X", item, item->type, item->next, item->param1, item->param2);
|
||||
lstrcat(place, "\n");
|
||||
wsprintf(place, _T("Addr: %08X Type: %08X Next: %08X Param1: %08X Param2: %08X"), item, item->type, item->next, item->param1, item->param2);
|
||||
lstrcat(place, _T("\n"));
|
||||
WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL);
|
||||
if (((item->type & ITEMTYPE) != IT_CONST) && ((item->type & (ITEMTYPE|ITEMSUBTYPE)) != (IT_VARIABLE|ITV_ARRITEM)))
|
||||
{
|
||||
|
@ -719,13 +721,13 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace)
|
|||
show = 1;
|
||||
if (show)
|
||||
{
|
||||
wsprintf(place, "Sub1:\n");
|
||||
wsprintf(place, _T("Sub1:\n"));
|
||||
WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL);
|
||||
}
|
||||
PrintNode(1, spaces + 4, *((ExpressionItem**) &item->param1));
|
||||
if (show)
|
||||
{
|
||||
wsprintf(place, "Sub2:\n");
|
||||
wsprintf(place, _T("Sub2:\n"));
|
||||
WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL);
|
||||
}
|
||||
PrintNode(2, spaces + 4, *((ExpressionItem**) &item->param2));
|
||||
|
@ -743,12 +745,12 @@ void PrintNode(int index, int spaces, ExpressionItem* itemplace)
|
|||
} while (item != NULL);
|
||||
}
|
||||
|
||||
void PrintTree(ExpressionItem *root, char *str)
|
||||
void PrintTree(ExpressionItem *root, TCHAR *str)
|
||||
{
|
||||
myfile = CreateFile("d:\\math.debug", GENERIC_ALL, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, 0);
|
||||
myfile = CreateFile(_T("d:\\math.debug"), GENERIC_ALL, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, 0);
|
||||
SetFilePointer(myfile, 0, NULL, FILE_END);
|
||||
char buffer[1024]; DWORD wrote;
|
||||
wsprintf(buffer, "New tree for \'%s\'\n", str);
|
||||
TCHAR buffer[1024]; DWORD wrote;
|
||||
wsprintf(buffer, _T("New tree for \'%s\'\n"), str);
|
||||
WriteFile(myfile, buffer, lstrlen(buffer), &wrote, NULL);
|
||||
|
||||
PrintNode(0, 4, root);
|
||||
|
@ -776,7 +778,7 @@ void CopyArray(ExpressionItem *&item)
|
|||
|
||||
void ItemToType(ExpressionItem* &item, int type)
|
||||
{
|
||||
char *buffer, *bp;
|
||||
TCHAR *buffer, *bp;
|
||||
if (item == NULL) return;
|
||||
int itemt = item->type & ITEMTYPE, oldtype = item->type & ITEMSUBTYPE;
|
||||
|
||||
|
@ -796,7 +798,7 @@ void ItemToType(ExpressionItem* &item, int type)
|
|||
*((double *)&(item->param1)) = (double) *((__int64 *)&(item->param1));
|
||||
else
|
||||
{
|
||||
bp = buffer = (char*) item->param1;
|
||||
bp = buffer = (TCHAR*) item->param1;
|
||||
StringToItem(buffer, item, STI_FLOAT);
|
||||
dbgGlobalFree(bp);
|
||||
}
|
||||
|
@ -806,7 +808,7 @@ void ItemToType(ExpressionItem* &item, int type)
|
|||
*((__int64 *)&(item->param1)) = (__int64) *((double *)&(item->param1));
|
||||
else
|
||||
{
|
||||
bp = buffer = (char*) item->param1;
|
||||
bp = buffer = (TCHAR*) item->param1;
|
||||
StringToItem(buffer, item, STI_INT);
|
||||
dbgGlobalFree(bp);
|
||||
}
|
||||
|
@ -814,7 +816,7 @@ void ItemToType(ExpressionItem* &item, int type)
|
|||
case ITC_ARRAY:
|
||||
if (oldtype == ITC_STRING)
|
||||
{
|
||||
char *buf = (char*) item->param1;
|
||||
TCHAR *buf = (TCHAR*) item->param1;
|
||||
int len = lstrlen(buf)+1;
|
||||
ExpressionItem *ni = AllocArray(lstrlen(buf)+1);
|
||||
ArrayDesc *ad = (ArrayDesc*) ni->param1;
|
||||
|
@ -843,7 +845,7 @@ void SaveResult(ExpressionItem *var, ExpressionItem *result)
|
|||
case ITV_NSIS:
|
||||
{
|
||||
// store string result direct to NSIS variable
|
||||
char *ptr = g_variables + varindex*g_stringsize;
|
||||
TCHAR *ptr = g_variables + varindex*g_stringsize;
|
||||
ItemToString(ptr, result);
|
||||
}
|
||||
break;
|
||||
|
@ -869,7 +871,7 @@ void SaveResult(ExpressionItem *var, ExpressionItem *result)
|
|||
break;
|
||||
case ITV_NSTACK:
|
||||
{
|
||||
char *buf = AllocString();
|
||||
TCHAR *buf = AllocString();
|
||||
ItemToString(buf, result);
|
||||
pushstring(buf);
|
||||
dbgGlobalFree(buf);
|
||||
|
@ -912,7 +914,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
|
|||
{
|
||||
// nsis
|
||||
result = AllocItem();
|
||||
char *variable = getuservariable(ioptions);
|
||||
TCHAR *variable = getuservariable(ioptions);
|
||||
StringToItem(variable, result, options);
|
||||
}
|
||||
break;
|
||||
|
@ -947,7 +949,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
|
|||
case ITV_NSTACK:
|
||||
{
|
||||
// NSIS stack
|
||||
char buffer[1024], *buf = buffer;
|
||||
TCHAR buffer[1024], *buf = buffer;
|
||||
result = AllocItem();
|
||||
popstring(buffer);
|
||||
StringToItem(buf, result, options);
|
||||
|
@ -1111,8 +1113,8 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
|
|||
case ITC_STRING:
|
||||
{
|
||||
int ir = -666;
|
||||
char *i1 = (item1)?((char*)item1->param1):(NULL);
|
||||
char *i2 = (item2)?((char*)item2->param1):(NULL);
|
||||
TCHAR *i1 = (item1)?((TCHAR*)item1->param1):(NULL);
|
||||
TCHAR *i2 = (item2)?((TCHAR*)item2->param1):(NULL);
|
||||
int sc = (i1 && i2)?(lstrcmp(i1, i2)):((i1)?(1):((i2)?(-1):(0)));
|
||||
|
||||
switch (subtype)
|
||||
|
@ -1277,7 +1279,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
|
|||
result = AllocItem();
|
||||
result->type = IT_CONST | ITC_STRING;
|
||||
result->param1 = (EIPARAM) AllocString();
|
||||
FloatFormat((char*) result->param1, value, format);
|
||||
FloatFormat((TCHAR*) result->param1, value, format);
|
||||
CleanupItems(arg1); CleanupItems(arg2);
|
||||
} else if (newtype == FTT_LEN)
|
||||
{
|
||||
|
@ -1297,7 +1299,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
|
|||
if ((result->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST|ITC_STRING))
|
||||
{
|
||||
// ok, that's string
|
||||
int len = lstrlen((char*)result->param1);
|
||||
int len = lstrlen((TCHAR*)result->param1);
|
||||
dbgGlobalFree((HGLOBAL) result->param1);
|
||||
*((__int64*)&(result->param1)) = (__int64) len;
|
||||
result->type = IT_CONST | ITC_INT;
|
||||
|
@ -1309,7 +1311,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
|
|||
if ((result->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST|ITC_STRING))
|
||||
{
|
||||
// ok, that's string - convert first char to int
|
||||
int chr = (*((char*)result->param1)) & 0xFF;
|
||||
int chr = (*((TCHAR*)result->param1)) & 0xFF;
|
||||
dbgGlobalFree((HGLOBAL) result->param1);
|
||||
*((__int64*)&(result->param1)) = (__int64) chr;
|
||||
result->type = IT_CONST | ITC_INT;
|
||||
|
@ -1320,8 +1322,8 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
|
|||
// ok, that's int - convert to new string (char+0)
|
||||
int chr = (int) (*((__int64*)&(result->param1))) & 0xFF;
|
||||
result->param1 = (EIPARAM) AllocString();
|
||||
*((char*)result->param1) = (char) chr;
|
||||
*((char*)(result->param1+1)) = (char) 0;
|
||||
*((TCHAR*)result->param1) = (TCHAR) chr;
|
||||
*((TCHAR*)(result->param1+1)) = (TCHAR) 0;
|
||||
result->type = IT_CONST | ITC_STRING;
|
||||
break;
|
||||
} else CleanupItems(result);
|
||||
|
@ -1380,7 +1382,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
|
|||
if ((aritem->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST | ITC_STRING))
|
||||
{
|
||||
// argument is string
|
||||
char *str = (char*)(aritem->param1);
|
||||
TCHAR *str = (TCHAR*)(aritem->param1);
|
||||
int len = lstrlen(str);
|
||||
// have we two indexes or one?
|
||||
if ((*((ExpressionItem **) &(item->param2)))->type != IT_EXPRESSION)
|
||||
|
@ -1428,7 +1430,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options)
|
|||
if (pos2 >= len) pos2 = len-1;
|
||||
|
||||
// copy string part
|
||||
char* lpos = str + (pos2-pos1);
|
||||
TCHAR* lpos = str + (pos2-pos1);
|
||||
while (str <= lpos)
|
||||
{
|
||||
*str = *(str + pos1);
|
||||
|
@ -1490,11 +1492,11 @@ HINSTANCE g_hInstance;
|
|||
|
||||
extern "C"
|
||||
void __declspec(dllexport) Script(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop,
|
||||
TCHAR *variables, stack_t **stacktop,
|
||||
extra_parameters *extra)
|
||||
{
|
||||
EXDLL_INIT();
|
||||
char *buffer = AllocString(), *buf = buffer;
|
||||
TCHAR *buffer = AllocString(), *buf = buffer;
|
||||
ExpressionItem *root = NULL; // root of current tree
|
||||
|
||||
// keep loaded to save user defined variables
|
||||
|
@ -1552,7 +1554,7 @@ void CleanAll(int init)
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
||||
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
g_hInstance = hInst;
|
||||
CleanAll(ul_reason_for_call == DLL_PROCESS_ATTACH);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Unicode support by Jim Park -- 08/22/2007
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
|
@ -23,7 +25,7 @@ HGLOBAL watchGlobalAlloc(UINT Flags, UINT size);
|
|||
|
||||
#endif
|
||||
|
||||
char *AllocString();
|
||||
TCHAR *AllocString();
|
||||
ExpressionItem *AllocItem();
|
||||
ExpressionItem *AllocArray(int size);
|
||||
ExpressionItem *CopyItem(ExpressionItem *item, int NeedConst = 0);
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
// Unicode support by Jim Park -- 08/22/2007
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "MyMath.h"
|
||||
#include "Math.h"
|
||||
|
||||
// Converts String to Int (Dec, Hex) or Float value
|
||||
void StringToItem(char *&s, ExpressionItem *item, int options)
|
||||
void StringToItem(TCHAR *&s, ExpressionItem *item, int options)
|
||||
{
|
||||
item->type = IT_CONST | ITC_INT;
|
||||
__int64 &v=*((__int64*)&(item->param1));
|
||||
|
@ -14,19 +16,19 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
|
|||
if (!s) return;
|
||||
|
||||
// String-value
|
||||
if ((((options & (STI_FLOAT | STI_INT)) == 0) || *s == '\'' || *s == '\"' || *s == '`' ||
|
||||
((*s != '+') && (*s != '-') && ((*s < '0') || (*s > '9'))))
|
||||
if ((((options & (STI_FLOAT | STI_INT)) == 0) || *s == _T('\'') || *s == _T('\"') || *s == _T('`') ||
|
||||
((*s != _T('+')) && (*s != _T('-')) && ((*s < _T('0')) || (*s > _T('9')))))
|
||||
&& (options & STI_STRING))
|
||||
{
|
||||
// end of string char
|
||||
char eol = 0;
|
||||
if (*s == '\'' || *s == '\"' || *s == '`') eol = *s;
|
||||
TCHAR eol = 0;
|
||||
if (*s == _T('\'') || *s == _T('\"') || *s == _T('`')) eol = *s;
|
||||
else s--;
|
||||
|
||||
item->type = IT_CONST | ITC_STRING;
|
||||
// allocate memory buffer for string
|
||||
char *sp;
|
||||
sp = *((char**)&(item->param1)) = AllocString();
|
||||
TCHAR *sp;
|
||||
sp = *((TCHAR**)&(item->param1)) = AllocString();
|
||||
while (*(++s) && (*s != eol))
|
||||
{
|
||||
*(sp++) = *s;
|
||||
|
@ -36,18 +38,18 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
|
|||
} else
|
||||
{
|
||||
// strip leading spaces and tabs
|
||||
while ((*s == ' ') || (*s == '\t')) s++;
|
||||
while ((*s == _T(' ')) || (*s == _T('\t'))) s++;
|
||||
// Hex-value
|
||||
if ((options & STI_INT) && *s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||
if ((options & STI_INT) && *s == _T('0') && (s[1] == _T('x') || s[1] == _T('X')))
|
||||
{
|
||||
s++;
|
||||
while (*(s+1) == '0') *s++;
|
||||
while (*(s+1) == _T('0')) *s++;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s);
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
else if (c >= 'a' && c <= 'f') c-='a'-10;
|
||||
else if (c >= 'A' && c <= 'F') c-='A'-10;
|
||||
if (c >= _T('0') && c <= _T('9')) c-=_T('0');
|
||||
else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10;
|
||||
else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10;
|
||||
else break;
|
||||
v<<=4;
|
||||
v+=c;
|
||||
|
@ -57,13 +59,13 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
|
|||
else
|
||||
{
|
||||
int sign=0, numsignif = 0;
|
||||
if (*s == '-') sign++; else s--;
|
||||
while (*(s+1) == '0') *s++;
|
||||
if (*s == _T('-')) sign++; else s--;
|
||||
while (*(s+1) == _T('0')) *s++;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s) - '0'; numsignif++;
|
||||
int c=*(++s) - _T('0'); numsignif++;
|
||||
if ((options & STI_FLOAT) &&
|
||||
((c == ('e'-'0')) || (c==('E'-'0')) || (c==('.'-'0'))
|
||||
((c == (_T('e')-_T('0'))) || (c==(_T('E')-_T('0'))) || (c==(_T('.')-_T('0')))
|
||||
|| (numsignif > 18)))
|
||||
{
|
||||
// Switch to floating point conversion rountine
|
||||
|
@ -74,16 +76,16 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
|
|||
while ((c >= 0) && (c <= 9))
|
||||
{
|
||||
d = d*10.0 + (double) c;
|
||||
c=*(++s) - '0';
|
||||
c=*(++s) - _T('0');
|
||||
}
|
||||
|
||||
// sub-decimal part
|
||||
if (c == ('.'-'0'))
|
||||
if (c == (_T('.')-_T('0')))
|
||||
{
|
||||
double pwr = 1.0, dec = 0.0;
|
||||
for (;;)
|
||||
{
|
||||
c=*(++s) - '0';
|
||||
c=*(++s) - _T('0');
|
||||
if ((c < 0) || (c > 9)) break;
|
||||
dec = dec*10.0 + (double) c;
|
||||
pwr *= 10.0;
|
||||
|
@ -91,19 +93,19 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
|
|||
d += dec/pwr;
|
||||
}
|
||||
// exponental part
|
||||
if ((c == ('E'-'0')) || (c == ('e'-'0')))
|
||||
if ((c == (_T('E')-_T('0'))) || (c == (_T('e')-_T('0'))))
|
||||
{
|
||||
int expc = 0, esign = 0;
|
||||
s++;
|
||||
// detect exponential sign
|
||||
if ((*s == '+') || (*s == '-'))
|
||||
esign = (*s == '-');
|
||||
if ((*s == _T('+')) || (*s == _T('-')))
|
||||
esign = (*s == _T('-'));
|
||||
else s--;
|
||||
|
||||
// detect exp value
|
||||
for (;;)
|
||||
{
|
||||
c=*(++s) - '0';
|
||||
c=*(++s) - _T('0');
|
||||
if ((c < 0) || (c > 9)) break;
|
||||
expc = expc*10 + c;
|
||||
}
|
||||
|
@ -139,7 +141,7 @@ void StringToItem(char *&s, ExpressionItem *item, int options)
|
|||
}
|
||||
}
|
||||
|
||||
void ItemToString(char *sbuf, ExpressionItem *item)
|
||||
void ItemToString(TCHAR *sbuf, ExpressionItem *item)
|
||||
{
|
||||
if ((item == NULL) || ((item->type & ITEMTYPE) != IT_CONST))
|
||||
{
|
||||
|
@ -151,7 +153,7 @@ void ItemToString(char *sbuf, ExpressionItem *item)
|
|||
{
|
||||
case ITC_STRING:
|
||||
{
|
||||
char *ptr = *((char**)&(item->param1));
|
||||
TCHAR *ptr = *((TCHAR**)&(item->param1));
|
||||
while (*(sbuf++) = *(ptr++));
|
||||
}
|
||||
break;
|
||||
|
@ -161,7 +163,7 @@ void ItemToString(char *sbuf, ExpressionItem *item)
|
|||
for (int index = 0; index < ad->count; index++)
|
||||
if ((ad->array[index]) &&
|
||||
((ad->array[index]->type & (ITEMTYPE|ITEMSUBTYPE)) == (IT_CONST | ITC_INT)))
|
||||
if ((*(sbuf++) = (char) *((__int64*)&(ad->array[index]->param1))) == 0)
|
||||
if ((*(sbuf++) = (TCHAR) *((__int64*)&(ad->array[index]->param1))) == 0)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -174,21 +176,21 @@ void ItemToString(char *sbuf, ExpressionItem *item)
|
|||
}
|
||||
}
|
||||
|
||||
void itoa64(__int64 i, char *buffer)
|
||||
void itoa64(__int64 i, TCHAR *buffer)
|
||||
{
|
||||
char buf[128], *b = buf;
|
||||
TCHAR buf[128], *b = buf;
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
*(buffer++) = '-';
|
||||
*(buffer++) = _T('-');
|
||||
i = -i;
|
||||
}
|
||||
if (i == 0) *(buffer++) = '0';
|
||||
if (i == 0) *(buffer++) = _T('0');
|
||||
else
|
||||
{
|
||||
while (i > 0)
|
||||
{
|
||||
*(b++) = '0' + ((char) (i%10));
|
||||
*(b++) = _T('0') + ((TCHAR) (i%10));
|
||||
i /= 10;
|
||||
}
|
||||
while (b > buf) *(buffer++) = *(--b);
|
||||
|
@ -196,12 +198,12 @@ void itoa64(__int64 i, char *buffer)
|
|||
*buffer = 0;
|
||||
}
|
||||
|
||||
#define POS_INFINITY "#INF"
|
||||
#define NEG_INFINITY "-#INF"
|
||||
#define POS_INFINITY _T("#INF")
|
||||
#define NEG_INFINITY _T("-#INF")
|
||||
|
||||
void FloatFormat(char *s, double value, int options)
|
||||
void FloatFormat(TCHAR *s, double value, int options)
|
||||
{
|
||||
char format[128];
|
||||
TCHAR format[128];
|
||||
int prec = options & 0xF;
|
||||
|
||||
*s = 0;
|
||||
|
@ -217,25 +219,25 @@ void FloatFormat(char *s, double value, int options)
|
|||
|
||||
if (options & FF_NOEXP)
|
||||
{
|
||||
sprintf(format, "%%.%df", prec);
|
||||
_stprintf(format, _T("%%.%df"), prec);
|
||||
}
|
||||
else if (options & FF_EXP)
|
||||
{
|
||||
sprintf(format, "%%.%de", prec);
|
||||
_stprintf(format, _T("%%.%de"), prec);
|
||||
}
|
||||
else if (options & FF_LEXP)
|
||||
{
|
||||
sprintf(format, "%%.%dE", prec);
|
||||
_stprintf(format, _T("%%.%dE"), prec);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(format, "%%.%dg", prec);
|
||||
_stprintf(format, _T("%%.%dg"), prec);
|
||||
}
|
||||
|
||||
sprintf(s, format, value);
|
||||
_stprintf(s, format, value);
|
||||
}
|
||||
|
||||
int lstrcmpn(char *s1, const char *s2, int chars)
|
||||
int lstrcmpn(TCHAR *s1, const TCHAR *s2, int chars)
|
||||
{
|
||||
while ((chars > 0) && (*s1) && (*s2) && (*(s1) == *(s2))) chars--, s1++, s2++;
|
||||
if ((chars == 0) || (*s1 == *s2)) return 0;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Unicode support by Jim Park -- 08/22/2007
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
|
@ -97,13 +99,13 @@ typedef struct __ParseInfo
|
|||
ExpressionItem *OpsStack;
|
||||
ExpressionItem **place;
|
||||
ExpressionItem **root;
|
||||
char valbuf[108];
|
||||
TCHAR valbuf[108];
|
||||
} ParseInfo;
|
||||
|
||||
#define OPERATOR_SET_PRECEDENCE 14
|
||||
typedef struct __OpStruct
|
||||
{
|
||||
char name[3];
|
||||
TCHAR name[3];
|
||||
unsigned char precedence;
|
||||
unsigned short int type;
|
||||
} OpStruct;
|
||||
|
@ -111,16 +113,16 @@ typedef struct __OpStruct
|
|||
#define MAX_USER_VARS 256
|
||||
typedef struct __UserVar
|
||||
{
|
||||
char name[28];
|
||||
TCHAR name[28];
|
||||
ExpressionItem *item;
|
||||
} UserVar;
|
||||
|
||||
#define MAX_USER_FUNCS 256
|
||||
typedef struct __UserFunc
|
||||
{
|
||||
char name[20];
|
||||
unsigned char vars[31];
|
||||
unsigned char varsnum;
|
||||
TCHAR name[20];
|
||||
unsigned char vars[31]; // only used for indexing
|
||||
unsigned char varsnum; // number of vars < 256
|
||||
unsigned int varflags;
|
||||
ExpressionItem *root;
|
||||
} UserFunc;
|
||||
|
@ -140,7 +142,7 @@ typedef double (*Math2dFuncPtr)(double arg, double *arg2);
|
|||
|
||||
typedef struct __MathFunction
|
||||
{
|
||||
char name[3];
|
||||
TCHAR name[3];
|
||||
unsigned char type;
|
||||
Math1FuncPtr fptr;
|
||||
} MathFunction;
|
||||
|
@ -159,8 +161,8 @@ typedef struct __MathFunction
|
|||
#define RTO_PREFFEREDTYPE 0xFF00
|
||||
void RunTree(ExpressionItem *from, ExpressionItem* &result, int type);
|
||||
|
||||
void StringToItem(char *&sbuf, ExpressionItem *item, int options);
|
||||
void ItemToString(char *sbuf, ExpressionItem *item);
|
||||
void FloatFormat(char *sbuf, double value, int options);
|
||||
void itoa64(__int64 i, char *buffer);
|
||||
int lstrcmpn(char *s1, const char *s2, int chars);
|
||||
void StringToItem(TCHAR *&sbuf, ExpressionItem *item, int options);
|
||||
void ItemToString(TCHAR *sbuf, ExpressionItem *item);
|
||||
void FloatFormat(TCHAR *sbuf, double value, int options);
|
||||
void itoa64(__int64 i, TCHAR *buffer);
|
||||
int lstrcmpn(TCHAR *s1, const TCHAR *s2, int chars);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Unicode support by Jim Park -- 08/22/2007
|
||||
|
||||
#include <windows.h>
|
||||
#include "MyMath.h"
|
||||
#include "Math.h"
|
||||
|
@ -28,15 +30,15 @@ void watchGlobal()
|
|||
for (int i = 0; i < blocksnum; i++)
|
||||
if (blocks[i] != NULL)
|
||||
{
|
||||
_RPT2(_CRT_WARN, "Memory leak %d at %8X\n", i, blocks[i]);
|
||||
_RPT2(_CRT_WARN, _T("Memory leak %d at %8X\n"), i, blocks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
char *AllocString()
|
||||
TCHAR *AllocString()
|
||||
{
|
||||
return (char*) dbgGlobalAlloc(GPTR,g_stringsize);
|
||||
return (TCHAR*) dbgGlobalAlloc(GPTR,g_stringsize*sizeof(TCHAR));
|
||||
}
|
||||
|
||||
ExpressionItem *AllocItem()
|
||||
|
@ -82,7 +84,7 @@ ExpressionItem *CopyItem(ExpressionItem *citem, int NeedConst)
|
|||
if ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_STRING))
|
||||
{
|
||||
item->param1 = (EIPARAM) AllocString();
|
||||
lstrcpy((LPSTR) item->param1, (LPSTR) citem->param1);
|
||||
lstrcpy((LPTSTR) item->param1, (LPTSTR) citem->param1);
|
||||
} else if (((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_ARRAY))
|
||||
||
|
||||
((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_VARIABLE | ITV_ARRITEM)))
|
||||
|
|
|
@ -1,38 +1,44 @@
|
|||
target = "NSIS"
|
||||
Import('BuildUtil env')
|
||||
|
||||
files = Split("""
|
||||
nsismenu/nsismenu.cpp
|
||||
nsismenu/nslinks.cpp
|
||||
nsismenu/nsismenu.cpp
|
||||
nsismenu/nslinks.cpp
|
||||
""")
|
||||
|
||||
resources = Split("""
|
||||
nsismenu/nsisicon.ico
|
||||
nsismenu/nsisicon.ico
|
||||
""")
|
||||
|
||||
rc = 'nsismenu/nsismenu.rc'
|
||||
|
||||
libs = Split("""
|
||||
advapi32
|
||||
comctl32
|
||||
gdi32
|
||||
shell32
|
||||
user32
|
||||
wxbase28
|
||||
wxmsw28_core
|
||||
wxmsw28_html
|
||||
advapi32
|
||||
comctl32
|
||||
gdi32
|
||||
shell32
|
||||
user32
|
||||
""")
|
||||
|
||||
if env['UNICODE']:
|
||||
libs.append(["wxbase28u", "wxmsw28u_core", "wxmsw28u_html"])
|
||||
else:
|
||||
libs.append(["wxbase28", "wxmsw28_core", "wxmsw28_html"])
|
||||
|
||||
html = Split("""
|
||||
#Menu/index.html
|
||||
#Menu/index.html
|
||||
""")
|
||||
|
||||
images = Split("""
|
||||
#Menu/images/header.gif
|
||||
#Menu/images/line.gif
|
||||
#Menu/images/site.gif
|
||||
#Menu/images/line.gif
|
||||
#Menu/images/site.gif
|
||||
""")
|
||||
|
||||
Import('BuildUtil env')
|
||||
|
||||
if env['UNICODE']:
|
||||
images.append("#Menu/images/Unicode/header.gif")
|
||||
else:
|
||||
images.append("#Menu/images/header.gif")
|
||||
|
||||
import os
|
||||
from os.path import join
|
||||
|
@ -40,56 +46,60 @@ from os.path import join
|
|||
if env['PLATFORM'] != 'win32' and WhereIs('wx-config') or \
|
||||
env['PLATFORM'] == 'win32' and os.environ.has_key('WXWIN'):
|
||||
|
||||
# build
|
||||
# build
|
||||
|
||||
if env['PLATFORM'] != 'win32':
|
||||
rc = libs = []
|
||||
if env['PLATFORM'] != 'win32':
|
||||
rc = libs = []
|
||||
|
||||
nsis_menu = BuildUtil(
|
||||
target,
|
||||
files,
|
||||
libs,
|
||||
res = rc,
|
||||
resources = resources,
|
||||
flags = ['$MSVCRT_FLAG', '$EXCEPTION_FLAG'],
|
||||
root_util = True,
|
||||
cross_platform = True
|
||||
)
|
||||
nsis_menu = BuildUtil(
|
||||
target,
|
||||
files,
|
||||
libs,
|
||||
res = rc,
|
||||
resources = resources,
|
||||
flags = ['$MSVCRT_FLAG', '$EXCEPTION_FLAG'],
|
||||
root_util = True,
|
||||
cross_platform = True
|
||||
)
|
||||
|
||||
# manifest
|
||||
# manifest
|
||||
|
||||
if env.has_key('MSVS_VERSION'):
|
||||
if float(env['MSVS_VERSION'].replace('Exp','')) >= 8.0:
|
||||
manifest = env.SideEffect('%s.exe.manifest' % target, nsis_menu)
|
||||
env.DistributeBin(manifest, alias='install-utils')
|
||||
if env.has_key('MSVS_VERSION'):
|
||||
if float(env['MSVS_VERSION'].replace('Exp','')) >= 8.0:
|
||||
manifest = env.SideEffect('%s.exe.manifest' % target, nsis_menu)
|
||||
env.DistributeBin(manifest, alias='install-utils')
|
||||
|
||||
# set directories
|
||||
# set directories
|
||||
|
||||
if nsis_menu[0].env['PLATFORM'] == 'win32':
|
||||
wxlib = [join(os.environ['WXWIN'], 'lib', 'vc_libnsis')]
|
||||
wxinc = [
|
||||
join(os.environ['WXWIN'], 'include'),
|
||||
join(os.environ['WXWIN'], 'lib', 'vc_libnsis', 'msw')
|
||||
]
|
||||
nsis_menu[0].env.Append(LIBPATH = wxlib)
|
||||
nsis_menu[0].env.Append(CPPPATH = wxinc)
|
||||
else:
|
||||
nsis_menu[0].env.ParseConfig('wx-config --cxxflags --libs')
|
||||
if nsis_menu[0].env['PLATFORM'] == 'win32':
|
||||
wxinc = [join(os.environ['WXWIN'], 'include')]
|
||||
|
||||
# install menu files
|
||||
if env['UNICODE']:
|
||||
wxlib = [join(os.environ['WXWIN'], 'lib', 'vc_libunsis')]
|
||||
wxinc.append(join(os.environ['WXWIN'], 'lib', 'vc_libunsis', 'mswu'))
|
||||
else:
|
||||
wxlib = [join(os.environ['WXWIN'], 'lib', 'vc_libnsis')]
|
||||
wxinc.append(join(os.environ['WXWIN'], 'lib', 'vc_libnsis', 'msw'))
|
||||
|
||||
env.DistributeMenu(html, alias='install-utils')
|
||||
env.DistributeMenu(images, path='images', alias='install-utils')
|
||||
nsis_menu[0].env.Append(LIBPATH = wxlib)
|
||||
nsis_menu[0].env.Append(CPPPATH = wxinc)
|
||||
else:
|
||||
nsis_menu[0].env.ParseConfig('wx-config --cxxflags --libs')
|
||||
|
||||
# install menu files
|
||||
|
||||
env.DistributeMenu(html, alias='install-utils')
|
||||
env.DistributeMenu(images, path='images', alias='install-utils')
|
||||
|
||||
else:
|
||||
|
||||
# no wxWidgets
|
||||
def err(target, source, env):
|
||||
if env['PLATFORM'] == 'win32':
|
||||
print '*** error: WXWIN must be set to build NSIS Menu!'
|
||||
else:
|
||||
print '*** error: wx-config must be in the PATH to build NSIS Menu!'
|
||||
return 1
|
||||
|
||||
# no wxWidgets
|
||||
def err(target, source, env):
|
||||
if env['PLATFORM'] == 'win32':
|
||||
print '*** error: WXWIN must be set to build NSIS Menu!'
|
||||
else:
|
||||
print '*** error: wx-config must be in the PATH to build NSIS Menu!'
|
||||
return 1
|
||||
|
||||
cmd = env.Command(target, files, Action(err, ''))
|
||||
env.Alias('NSIS Menu', cmd)
|
||||
cmd = env.Command(target, files, Action(err, ''))
|
||||
env.Alias('NSIS Menu', cmd)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// NSIS MENU
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/23/2007
|
||||
// Basically, compiling wxWidgets as Unicode should do it.
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h".
|
||||
|
@ -100,7 +103,7 @@ private:
|
|||
|
||||
// Create the main application window
|
||||
MyFrame *frame = new MyFrame(_("NSIS Menu"),
|
||||
wxPoint(50, 50), wxSize(600 + wxSystemSettings::GetMetric(wxSYS_FRAMESIZE_X), 355 + wxSystemSettings::GetMetric(wxSYS_FRAMESIZE_X)));
|
||||
wxPoint(50, 50), wxSize(600 + wxSystemSettings::GetMetric(wxSYS_FRAMESIZE_X), 365 + wxSystemSettings::GetMetric(wxSYS_FRAMESIZE_X)));
|
||||
|
||||
// Show it and tell the application that it's our main window
|
||||
|
||||
|
@ -154,10 +157,10 @@ void MyFrame::OnLink(wxHtmlLinkEvent& event)
|
|||
if (e == NULL || e->LeftUp())
|
||||
{
|
||||
const wxString href = event.GetLinkInfo().GetHref();
|
||||
if (href.Left(3).IsSameAs((const wxChar*)"EX:", false))
|
||||
if (href.Left(3).IsSameAs((const wxChar*) wxT("EX:"), false))
|
||||
{
|
||||
wxString url = href.Mid(3);
|
||||
if (url.Left(7).IsSameAs((const wxChar*)"http://", false) || url.Left(6).IsSameAs((const wxChar*)"irc://", false))
|
||||
if (url.Left(7).IsSameAs((const wxChar*) wxT("http://"), false) || url.Left(6).IsSameAs((const wxChar*) wxT("irc://"), false))
|
||||
{
|
||||
::wxLaunchDefaultBrowser(url);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
// Name: src/html/m_links.cpp
|
||||
// Purpose: wxHtml module for links & anchors
|
||||
// Author: Vaclav Slavik
|
||||
// RCS-ID: $Id: nslinks.cpp,v 1.1 2007/02/24 18:57:09 kichik Exp $
|
||||
// RCS-ID: $Id: nslinks.cpp,v 1.2 2007/03/08 01:47:14 pabs3 Exp $
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/23/2007
|
||||
// Basically, compiling wxWidgets as Unicode should do it.
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
@ -60,10 +63,10 @@ TAG_HANDLER_BEGIN(A, "A")
|
|||
wxColour colour = m_WParser->GetLinkColor();
|
||||
wxHtmlLinkInfo linkInfo(name, target);
|
||||
|
||||
if (name.Left(3).IsSameAs((const wxChar*)"EX:", false))
|
||||
if (name.Left(3).IsSameAs((const wxChar*) wxT("EX:"), false))
|
||||
{
|
||||
wxString url = name.Mid(3);
|
||||
if (!url.Left(7).IsSameAs((const wxChar*)"http://", false) && !url.Left(6).IsSameAs((const wxChar*)"irc://", false))
|
||||
if (!url.Left(7).IsSameAs((const wxChar*) wxT("http://"), false) && !url.Left(6).IsSameAs((const wxChar*) wxT("irc://"), false))
|
||||
{
|
||||
wxString exePath = wxStandardPaths::Get().GetExecutablePath();
|
||||
wxString path = ::wxPathOnly(exePath);
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
// RCS-ID: $Id: setup0.h,v 1.246 2006/11/09 00:54:51 VZ Exp $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/01/2007
|
||||
// (This one is the ANSI version.)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_SETUP_H_
|
||||
|
|
|
@ -1,12 +1,42 @@
|
|||
@echo off
|
||||
if not exist setup.h goto setup_error
|
||||
if not exist "%WXWIN%\build\msw\makefile.vc" goto error
|
||||
set OLDCD=%CD%
|
||||
cd /D "%WXWIN%\build\msw"
|
||||
rem Save the old setup.h as old_setup.h in the starting dir.
|
||||
copy /y "%WXWIN%\include\wx\msw\setup.h" "%OLDCD%\old_setup.h"
|
||||
copy /y "%OLDCD%\setup.h" "%WXWIN%\include\wx\msw\setup.h"
|
||||
|
||||
if "%1" == "unicode" goto unicode
|
||||
if "%1" == "ansi" goto ansi
|
||||
:ansi
|
||||
rem Ask if we want to delete this dir.
|
||||
echo Deleting...
|
||||
rd /S ..\..\lib\vc_libnsis
|
||||
|
||||
echo ### building ANSI version ###
|
||||
rem Copy the ANSI version of setup.h to WXWIN setup.
|
||||
copy /y "%OLDCD%\setup.h" "%WXWIN%\include\wx\msw\setup.h"
|
||||
echo Deleting...
|
||||
rd /S vc_mswnsis
|
||||
nmake -f makefile.vc CFG=nsis BUILD=release RUNTIME_LIBS=dynamic SHARED=0 UNICODE=0 WXUNIV=0 USE_OPENGL=0 USE_ODBC=0 USE_HTML=1 USE_XRC=0
|
||||
nmake -f makefile.vc CFG=nsis BUILD=release RUNTIME_LIBS=static SHARED=0 UNICODE=0 WXUNIV=0 USE_OPENGL=0 USE_ODBC=0 USE_HTML=1 USE_XRC=0
|
||||
if "%1" == "" goto unicode
|
||||
if "%1" == "all" goto unicode
|
||||
goto finish
|
||||
|
||||
:unicode
|
||||
rem Ask if we want to delete this dir.
|
||||
echo Deleting...
|
||||
rd /S ..\..\lib\vc_libunsis
|
||||
|
||||
echo ### building UNICODE version ###
|
||||
rem Copy the UNICODE version of setup.h to WXWIN setup.
|
||||
copy /y "%OLDCD%\setup_unicode.h" "%WXWIN%\include\wx\msw\setup.h"
|
||||
echo Deleting...
|
||||
rd /S vc_mswunsis
|
||||
nmake -f makefile.vc CFG=unsis BUILD=release RUNTIME_LIBS=static SHARED=0 UNICODE=1 WXUNIV=0 USE_OPENGL=0 USE_ODBC=0 USE_HTML=1 USE_XRC=0
|
||||
|
||||
:finish
|
||||
rem Restore the setup.h
|
||||
copy /y "%OLDCD%\old_setup.h" "%WXWIN%\include\wx\msw\setup.h"
|
||||
cd /D "%OLDCD%"
|
||||
goto done
|
||||
|
|
|
@ -1,82 +1,86 @@
|
|||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: asyncdns.cpp - JNL portable asynchronous DNS implementation
|
||||
** License: see jnetlib.h
|
||||
*/
|
||||
|
||||
|
||||
#include "netinc.h"
|
||||
#include "util.h"
|
||||
#include "asyncdns.h"
|
||||
|
||||
JNL_AsyncDNS::JNL_AsyncDNS()
|
||||
{
|
||||
m_thread=0;
|
||||
m_addr=0;
|
||||
m_hostname[0]=0;
|
||||
}
|
||||
|
||||
JNL_AsyncDNS::~JNL_AsyncDNS()
|
||||
{
|
||||
wait_for_thread_death();
|
||||
}
|
||||
|
||||
unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
|
||||
{
|
||||
JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d;
|
||||
struct hostent *hostentry;
|
||||
hostentry=::gethostbyname(_this->m_hostname);
|
||||
if (hostentry)
|
||||
{
|
||||
_this->m_addr=*((int*)hostentry->h_addr);
|
||||
}
|
||||
else
|
||||
_this->m_addr=INADDR_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JNL_AsyncDNS::resolve(char *hostname, unsigned long *addr)
|
||||
{
|
||||
// return 0 on success, 1 on wait, -1 on unresolvable
|
||||
unsigned long ip=inet_addr(hostname);
|
||||
if (ip != INADDR_NONE)
|
||||
{
|
||||
*addr=ip;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lstrcmpi(m_hostname,hostname)) m_addr=0;
|
||||
else if (m_addr == INADDR_NONE)
|
||||
{
|
||||
wait_for_thread_death();
|
||||
return -1;
|
||||
}
|
||||
else if (m_addr)
|
||||
{
|
||||
*addr=m_addr;
|
||||
wait_for_thread_death();
|
||||
return 0;
|
||||
}
|
||||
lstrcpy(m_hostname,hostname);
|
||||
|
||||
if (!m_thread)
|
||||
{
|
||||
DWORD id;
|
||||
m_thread=CreateThread(NULL,0,_threadfunc,(LPVOID)this,0,&id);
|
||||
if (!m_thread) return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void JNL_AsyncDNS::wait_for_thread_death()
|
||||
{
|
||||
if (m_thread)
|
||||
{
|
||||
WaitForSingleObject(m_thread,INFINITE);
|
||||
CloseHandle(m_thread);
|
||||
}
|
||||
|
||||
m_thread=0;
|
||||
}
|
||||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: asyncdns.cpp - JNL portable asynchronous DNS implementation
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Unicode support by Jim Park -- 08/24/2007
|
||||
*/
|
||||
|
||||
// Jim Park: For Unicode Support, all string functions must explicitly use
|
||||
// ANSI versions if UNICODE is defined.
|
||||
|
||||
#include "netinc.h"
|
||||
#include "util.h"
|
||||
#include "asyncdns.h"
|
||||
|
||||
JNL_AsyncDNS::JNL_AsyncDNS()
|
||||
{
|
||||
m_thread=0;
|
||||
m_addr=0;
|
||||
m_hostname[0]=0;
|
||||
}
|
||||
|
||||
JNL_AsyncDNS::~JNL_AsyncDNS()
|
||||
{
|
||||
wait_for_thread_death();
|
||||
}
|
||||
|
||||
unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
|
||||
{
|
||||
JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d;
|
||||
struct hostent *hostentry;
|
||||
hostentry=::gethostbyname(_this->m_hostname);
|
||||
if (hostentry)
|
||||
{
|
||||
_this->m_addr=*((int*)hostentry->h_addr);
|
||||
}
|
||||
else
|
||||
_this->m_addr=INADDR_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JNL_AsyncDNS::resolve(char *hostname, unsigned long *addr)
|
||||
{
|
||||
// return 0 on success, 1 on wait, -1 on unresolvable
|
||||
unsigned long ip=inet_addr(hostname);
|
||||
if (ip != INADDR_NONE)
|
||||
{
|
||||
*addr=ip;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lstrcmpiA(m_hostname,hostname)) m_addr=0;
|
||||
else if (m_addr == INADDR_NONE)
|
||||
{
|
||||
wait_for_thread_death();
|
||||
return -1;
|
||||
}
|
||||
else if (m_addr)
|
||||
{
|
||||
*addr=m_addr;
|
||||
wait_for_thread_death();
|
||||
return 0;
|
||||
}
|
||||
lstrcpyA(m_hostname,hostname);
|
||||
|
||||
if (!m_thread)
|
||||
{
|
||||
DWORD id;
|
||||
m_thread=CreateThread(NULL,0,_threadfunc,(LPVOID)this,0,&id);
|
||||
if (!m_thread) return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void JNL_AsyncDNS::wait_for_thread_death()
|
||||
{
|
||||
if (m_thread)
|
||||
{
|
||||
WaitForSingleObject(m_thread,INFINITE);
|
||||
CloseHandle(m_thread);
|
||||
}
|
||||
|
||||
m_thread=0;
|
||||
}
|
||||
|
|
|
@ -1,39 +1,43 @@
|
|||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: asyncdns.h - JNL portable asynchronous DNS interface
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Usage:
|
||||
** 1. Create JNL_AsyncDNS object, optionally with the number of cache entries.
|
||||
** 2. call resolve() to resolve a hostname into an address. The return value of
|
||||
** resolve is 0 on success (host successfully resolved), 1 on wait (meaning
|
||||
** try calling resolve() with the same hostname in a few hundred milliseconds
|
||||
** or so), or -1 on error (i.e. the host can't resolve).
|
||||
** 4. enjoy.
|
||||
*/
|
||||
|
||||
#ifndef _ASYNCDNS_H_
|
||||
#define _ASYNCDNS_H_
|
||||
|
||||
class JNL_AsyncDNS
|
||||
{
|
||||
public:
|
||||
JNL_AsyncDNS();
|
||||
~JNL_AsyncDNS();
|
||||
|
||||
int resolve(char *hostname, unsigned long *addr); // return 0 on success, 1 on wait, -1 on unresolvable
|
||||
|
||||
private:
|
||||
void wait_for_thread_death();
|
||||
|
||||
char m_hostname[256];
|
||||
unsigned long m_addr;
|
||||
|
||||
HANDLE m_thread;
|
||||
static unsigned long WINAPI _threadfunc(LPVOID _d);
|
||||
|
||||
};
|
||||
|
||||
#endif //_ASYNCDNS_H_
|
||||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: asyncdns.h - JNL portable asynchronous DNS interface
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Usage:
|
||||
** 1. Create JNL_AsyncDNS object, optionally with the number of cache entries.
|
||||
** 2. call resolve() to resolve a hostname into an address. The return value of
|
||||
** resolve is 0 on success (host successfully resolved), 1 on wait (meaning
|
||||
** try calling resolve() with the same hostname in a few hundred milliseconds
|
||||
** or so), or -1 on error (i.e. the host can't resolve).
|
||||
** 4. enjoy.
|
||||
**
|
||||
** Unicode support by Jim Park -- 08/24/2007
|
||||
*/
|
||||
|
||||
// Jim Park: Inet host name is strictly ANSI, no UNICODE for now.
|
||||
|
||||
#ifndef _ASYNCDNS_H_
|
||||
#define _ASYNCDNS_H_
|
||||
|
||||
class JNL_AsyncDNS
|
||||
{
|
||||
public:
|
||||
JNL_AsyncDNS();
|
||||
~JNL_AsyncDNS();
|
||||
|
||||
int resolve(char *hostname, unsigned long *addr); // return 0 on success, 1 on wait, -1 on unresolvable
|
||||
|
||||
private:
|
||||
void wait_for_thread_death();
|
||||
|
||||
char m_hostname[256];
|
||||
unsigned long m_addr;
|
||||
|
||||
HANDLE m_thread;
|
||||
static unsigned long WINAPI _threadfunc(LPVOID _d);
|
||||
|
||||
};
|
||||
|
||||
#endif //_ASYNCDNS_H_
|
||||
|
|
|
@ -1,445 +1,447 @@
|
|||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: connection.cpp - JNL TCP connection implementation
|
||||
** License: see jnetlib.h
|
||||
*/
|
||||
|
||||
#include "netinc.h"
|
||||
#include "util.h"
|
||||
#include "connection.h"
|
||||
|
||||
|
||||
JNL_Connection::JNL_Connection(JNL_AsyncDNS *dns, int sendbufsize, int recvbufsize)
|
||||
{
|
||||
m_errorstr="";
|
||||
if (dns == JNL_CONNECTION_AUTODNS)
|
||||
{
|
||||
m_dns=new JNL_AsyncDNS();
|
||||
m_dns_owned=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dns=dns;
|
||||
m_dns_owned=0;
|
||||
}
|
||||
m_recv_buffer_len=recvbufsize;
|
||||
m_send_buffer_len=sendbufsize;
|
||||
m_recv_buffer=(char*)malloc(m_recv_buffer_len);
|
||||
m_send_buffer=(char*)malloc(m_send_buffer_len);
|
||||
m_socket=-1;
|
||||
m_remote_port=0;
|
||||
m_state=STATE_NOCONNECTION;
|
||||
m_recv_len=m_recv_pos=0;
|
||||
m_send_len=m_send_pos=0;
|
||||
m_host[0]=0;
|
||||
memset(&m_saddr,0,sizeof(m_saddr));
|
||||
}
|
||||
|
||||
void JNL_Connection::connect(int s, struct sockaddr_in *loc)
|
||||
{
|
||||
close(1);
|
||||
m_socket=s;
|
||||
m_remote_port=0;
|
||||
m_dns=NULL;
|
||||
if (loc) m_saddr=*loc;
|
||||
else memset(&m_saddr,0,sizeof(m_saddr));
|
||||
if (m_socket != -1)
|
||||
{
|
||||
SET_SOCK_BLOCK(m_socket,0);
|
||||
m_state=STATE_CONNECTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_errorstr="invalid socket passed to connect";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
void JNL_Connection::connect(char *hostname, int port)
|
||||
{
|
||||
close(1);
|
||||
m_remote_port=(short)port;
|
||||
m_socket=::socket(AF_INET,SOCK_STREAM,0);
|
||||
if (m_socket==-1)
|
||||
{
|
||||
m_errorstr="creating socket";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_SOCK_BLOCK(m_socket,0);
|
||||
strncpy(m_host,hostname,sizeof(m_host)-1);
|
||||
m_host[sizeof(m_host)-1]=0;
|
||||
memset(&m_saddr,0,sizeof(m_saddr));
|
||||
if (!m_host[0])
|
||||
{
|
||||
m_errorstr="empty hostname";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_state=STATE_RESOLVING;
|
||||
m_saddr.sin_family=AF_INET;
|
||||
m_saddr.sin_port=htons((unsigned short)port);
|
||||
m_saddr.sin_addr.s_addr=inet_addr(hostname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNL_Connection::~JNL_Connection()
|
||||
{
|
||||
if (m_socket >= 0)
|
||||
{
|
||||
::shutdown(m_socket, SHUT_RDWR);
|
||||
::closesocket(m_socket);
|
||||
m_socket=-1;
|
||||
}
|
||||
free(m_recv_buffer);
|
||||
free(m_send_buffer);
|
||||
if (m_dns_owned)
|
||||
{
|
||||
delete m_dns;
|
||||
}
|
||||
}
|
||||
|
||||
void JNL_Connection::run(int max_send_bytes, int max_recv_bytes, int *bytes_sent, int *bytes_rcvd)
|
||||
{
|
||||
int bytes_allowed_to_send=(max_send_bytes<0)?m_send_buffer_len:max_send_bytes;
|
||||
int bytes_allowed_to_recv=(max_recv_bytes<0)?m_recv_buffer_len:max_recv_bytes;
|
||||
|
||||
if (bytes_sent) *bytes_sent=0;
|
||||
if (bytes_rcvd) *bytes_rcvd=0;
|
||||
|
||||
switch (m_state)
|
||||
{
|
||||
case STATE_RESOLVING:
|
||||
if (m_saddr.sin_addr.s_addr == INADDR_NONE)
|
||||
{
|
||||
int a=m_dns?m_dns->resolve(m_host,(unsigned long int *)&m_saddr.sin_addr.s_addr):-1;
|
||||
if (!a) { m_state=STATE_CONNECTING; }
|
||||
else if (a == 1)
|
||||
{
|
||||
m_state=STATE_RESOLVING;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_errorstr="resolving hostname";
|
||||
m_state=STATE_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!::connect(m_socket,(struct sockaddr *)&m_saddr,16))
|
||||
{
|
||||
m_state=STATE_CONNECTED;
|
||||
}
|
||||
else if (ERRNO!=EINPROGRESS)
|
||||
{
|
||||
m_errorstr="connecting to host";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
else { m_state=STATE_CONNECTING; }
|
||||
break;
|
||||
case STATE_CONNECTING:
|
||||
{
|
||||
fd_set f[3];
|
||||
FD_ZERO(&f[0]);
|
||||
FD_ZERO(&f[1]);
|
||||
FD_ZERO(&f[2]);
|
||||
FD_SET(m_socket,&f[0]);
|
||||
FD_SET(m_socket,&f[1]);
|
||||
FD_SET(m_socket,&f[2]);
|
||||
struct timeval tv;
|
||||
memset(&tv,0,sizeof(tv));
|
||||
if (select(m_socket+1,&f[0],&f[1],&f[2],&tv)==-1)
|
||||
{
|
||||
m_errorstr="connecting to host (calling select())";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
else if (FD_ISSET(m_socket,&f[1]))
|
||||
{
|
||||
m_state=STATE_CONNECTED;
|
||||
}
|
||||
else if (FD_ISSET(m_socket,&f[2]))
|
||||
{
|
||||
m_errorstr="connecting to host";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_CONNECTED:
|
||||
case STATE_CLOSING:
|
||||
if (m_send_len>0 && bytes_allowed_to_send>0)
|
||||
{
|
||||
int len=m_send_buffer_len-m_send_pos;
|
||||
if (len > m_send_len) len=m_send_len;
|
||||
if (len > bytes_allowed_to_send) len=bytes_allowed_to_send;
|
||||
if (len > 0)
|
||||
{
|
||||
int res=::send(m_socket,m_send_buffer+m_send_pos,len,0);
|
||||
if (res==-1 && ERRNO != EWOULDBLOCK)
|
||||
{
|
||||
// m_state=STATE_CLOSED;
|
||||
// return;
|
||||
}
|
||||
if (res>0)
|
||||
{
|
||||
bytes_allowed_to_send-=res;
|
||||
if (bytes_sent) *bytes_sent+=res;
|
||||
m_send_pos+=res;
|
||||
m_send_len-=res;
|
||||
}
|
||||
}
|
||||
if (m_send_pos>=m_send_buffer_len)
|
||||
{
|
||||
m_send_pos=0;
|
||||
if (m_send_len>0)
|
||||
{
|
||||
len=m_send_buffer_len-m_send_pos;
|
||||
if (len > m_send_len) len=m_send_len;
|
||||
if (len > bytes_allowed_to_send) len=bytes_allowed_to_send;
|
||||
int res=::send(m_socket,m_send_buffer+m_send_pos,len,0);
|
||||
if (res==-1 && ERRNO != EWOULDBLOCK)
|
||||
{
|
||||
// m_state=STATE_CLOSED;
|
||||
}
|
||||
if (res>0)
|
||||
{
|
||||
bytes_allowed_to_send-=res;
|
||||
if (bytes_sent) *bytes_sent+=res;
|
||||
m_send_pos+=res;
|
||||
m_send_len-=res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_recv_len<m_recv_buffer_len)
|
||||
{
|
||||
int len=m_recv_buffer_len-m_recv_pos;
|
||||
if (len > m_recv_buffer_len-m_recv_len) len=m_recv_buffer_len-m_recv_len;
|
||||
if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv;
|
||||
if (len>0)
|
||||
{
|
||||
int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0);
|
||||
if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK))
|
||||
{
|
||||
m_state=STATE_CLOSED;
|
||||
break;
|
||||
}
|
||||
if (res > 0)
|
||||
{
|
||||
bytes_allowed_to_recv-=res;
|
||||
if (bytes_rcvd) *bytes_rcvd+=res;
|
||||
m_recv_pos+=res;
|
||||
m_recv_len+=res;
|
||||
}
|
||||
}
|
||||
if (m_recv_pos >= m_recv_buffer_len)
|
||||
{
|
||||
m_recv_pos=0;
|
||||
if (m_recv_len < m_recv_buffer_len)
|
||||
{
|
||||
len=m_recv_buffer_len-m_recv_len;
|
||||
if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv;
|
||||
if (len > 0)
|
||||
{
|
||||
int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0);
|
||||
if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK))
|
||||
{
|
||||
m_state=STATE_CLOSED;
|
||||
break;
|
||||
}
|
||||
if (res > 0)
|
||||
{
|
||||
bytes_allowed_to_recv-=res;
|
||||
if (bytes_rcvd) *bytes_rcvd+=res;
|
||||
m_recv_pos+=res;
|
||||
m_recv_len+=res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_state == STATE_CLOSING)
|
||||
{
|
||||
if (m_send_len < 1) m_state = STATE_CLOSED;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void JNL_Connection::close(int quick)
|
||||
{
|
||||
if (quick || m_state == STATE_RESOLVING || m_state == STATE_CONNECTING)
|
||||
{
|
||||
m_state=STATE_CLOSED;
|
||||
if (m_socket >= 0)
|
||||
{
|
||||
::shutdown(m_socket, SHUT_RDWR);
|
||||
::closesocket(m_socket);
|
||||
}
|
||||
m_socket=-1;
|
||||
memset(m_recv_buffer,0,m_recv_buffer_len);
|
||||
memset(m_send_buffer,0,m_send_buffer_len);
|
||||
m_remote_port=0;
|
||||
m_recv_len=m_recv_pos=0;
|
||||
m_send_len=m_send_pos=0;
|
||||
m_host[0]=0;
|
||||
memset(&m_saddr,0,sizeof(m_saddr));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_state == STATE_CONNECTED) m_state=STATE_CLOSING;
|
||||
}
|
||||
}
|
||||
|
||||
int JNL_Connection::send_bytes_in_queue(void)
|
||||
{
|
||||
return m_send_len;
|
||||
}
|
||||
|
||||
int JNL_Connection::send_bytes_available(void)
|
||||
{
|
||||
return m_send_buffer_len-m_send_len;
|
||||
}
|
||||
|
||||
int JNL_Connection::send(char *data, int length)
|
||||
{
|
||||
if (length > send_bytes_available())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int write_pos=m_send_pos+m_send_len;
|
||||
if (write_pos >= m_send_buffer_len)
|
||||
{
|
||||
write_pos-=m_send_buffer_len;
|
||||
}
|
||||
|
||||
int len=m_send_buffer_len-write_pos;
|
||||
if (len > length)
|
||||
{
|
||||
len=length;
|
||||
}
|
||||
|
||||
memcpy(m_send_buffer+write_pos,data,len);
|
||||
if (length > len)
|
||||
{
|
||||
memcpy(m_send_buffer,data+len,length-len);
|
||||
}
|
||||
m_send_len+=length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JNL_Connection::send_string(char *line)
|
||||
{
|
||||
return send(line,strlen(line));
|
||||
}
|
||||
|
||||
int JNL_Connection::recv_bytes_available(void)
|
||||
{
|
||||
return m_recv_len;
|
||||
}
|
||||
|
||||
int JNL_Connection::peek_bytes(char *data, int maxlength)
|
||||
{
|
||||
if (maxlength > m_recv_len)
|
||||
{
|
||||
maxlength=m_recv_len;
|
||||
}
|
||||
int read_pos=m_recv_pos-m_recv_len;
|
||||
if (read_pos < 0)
|
||||
{
|
||||
read_pos += m_recv_buffer_len;
|
||||
}
|
||||
int len=m_recv_buffer_len-read_pos;
|
||||
if (len > maxlength)
|
||||
{
|
||||
len=maxlength;
|
||||
}
|
||||
memcpy(data,m_recv_buffer+read_pos,len);
|
||||
if (len < maxlength)
|
||||
{
|
||||
memcpy(data+len,m_recv_buffer,maxlength-len);
|
||||
}
|
||||
|
||||
return maxlength;
|
||||
}
|
||||
|
||||
int JNL_Connection::recv_bytes(char *data, int maxlength)
|
||||
{
|
||||
|
||||
int ml=peek_bytes(data,maxlength);
|
||||
m_recv_len-=ml;
|
||||
return ml;
|
||||
}
|
||||
|
||||
int JNL_Connection::getbfromrecv(int pos, int remove)
|
||||
{
|
||||
int read_pos=m_recv_pos-m_recv_len + pos;
|
||||
if (pos < 0 || pos > m_recv_len) return -1;
|
||||
if (read_pos < 0)
|
||||
{
|
||||
read_pos += m_recv_buffer_len;
|
||||
}
|
||||
if (read_pos >= m_recv_buffer_len)
|
||||
{
|
||||
read_pos-=m_recv_buffer_len;
|
||||
}
|
||||
if (remove) m_recv_len--;
|
||||
return m_recv_buffer[read_pos];
|
||||
}
|
||||
|
||||
int JNL_Connection::recv_lines_available(void)
|
||||
{
|
||||
int l=recv_bytes_available();
|
||||
int lcount=0;
|
||||
int lastch=0;
|
||||
int pos;
|
||||
for (pos=0; pos < l; pos ++)
|
||||
{
|
||||
int t=getbfromrecv(pos,0);
|
||||
if (t == -1) return lcount;
|
||||
if ((t=='\r' || t=='\n') &&(
|
||||
(lastch != '\r' && lastch != '\n') || lastch==t
|
||||
)) lcount++;
|
||||
lastch=t;
|
||||
}
|
||||
return lcount;
|
||||
}
|
||||
|
||||
int JNL_Connection::recv_line(char *line, int maxlength)
|
||||
{
|
||||
if (maxlength > m_recv_len) maxlength=m_recv_len;
|
||||
while (maxlength--)
|
||||
{
|
||||
int t=getbfromrecv(0,1);
|
||||
if (t == -1)
|
||||
{
|
||||
*line=0;
|
||||
return 0;
|
||||
}
|
||||
if (t == '\r' || t == '\n')
|
||||
{
|
||||
int r=getbfromrecv(0,0);
|
||||
if ((r == '\r' || r == '\n') && r != t) getbfromrecv(0,1);
|
||||
*line=0;
|
||||
return 0;
|
||||
}
|
||||
*line++=(char)t;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned long JNL_Connection::get_interface(void)
|
||||
{
|
||||
if (m_socket==-1) return 0;
|
||||
struct sockaddr_in sin;
|
||||
memset(&sin,0,sizeof(sin));
|
||||
socklen_t len=16;
|
||||
if (::getsockname(m_socket,(struct sockaddr *)&sin,&len)) return 0;
|
||||
return (unsigned long) sin.sin_addr.s_addr;
|
||||
}
|
||||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: connection.cpp - JNL TCP connection implementation
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Unicode support by Jim Park -- 08/24/2007
|
||||
*/
|
||||
|
||||
#include "netinc.h"
|
||||
#include "util.h"
|
||||
#include "connection.h"
|
||||
|
||||
|
||||
JNL_Connection::JNL_Connection(JNL_AsyncDNS *dns, int sendbufsize, int recvbufsize)
|
||||
{
|
||||
m_errorstr="";
|
||||
if (dns == JNL_CONNECTION_AUTODNS)
|
||||
{
|
||||
m_dns=new JNL_AsyncDNS();
|
||||
m_dns_owned=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dns=dns;
|
||||
m_dns_owned=0;
|
||||
}
|
||||
m_recv_buffer_len=recvbufsize;
|
||||
m_send_buffer_len=sendbufsize;
|
||||
m_recv_buffer=(char*)malloc(m_recv_buffer_len);
|
||||
m_send_buffer=(char*)malloc(m_send_buffer_len);
|
||||
m_socket=-1;
|
||||
m_remote_port=0;
|
||||
m_state=STATE_NOCONNECTION;
|
||||
m_recv_len=m_recv_pos=0;
|
||||
m_send_len=m_send_pos=0;
|
||||
m_host[0]=0;
|
||||
memset(&m_saddr,0,sizeof(m_saddr));
|
||||
}
|
||||
|
||||
void JNL_Connection::connect(int s, struct sockaddr_in *loc)
|
||||
{
|
||||
close(1);
|
||||
m_socket=s;
|
||||
m_remote_port=0;
|
||||
m_dns=NULL;
|
||||
if (loc) m_saddr=*loc;
|
||||
else memset(&m_saddr,0,sizeof(m_saddr));
|
||||
if (m_socket != -1)
|
||||
{
|
||||
SET_SOCK_BLOCK(m_socket,0);
|
||||
m_state=STATE_CONNECTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_errorstr="invalid socket passed to connect";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
void JNL_Connection::connect(char *hostname, int port)
|
||||
{
|
||||
close(1);
|
||||
m_remote_port=(short)port;
|
||||
m_socket=::socket(AF_INET,SOCK_STREAM,0);
|
||||
if (m_socket==-1)
|
||||
{
|
||||
m_errorstr="creating socket";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_SOCK_BLOCK(m_socket,0);
|
||||
strncpy(m_host,hostname,sizeof(m_host)-1);
|
||||
m_host[sizeof(m_host)-1]=0;
|
||||
memset(&m_saddr,0,sizeof(m_saddr));
|
||||
if (!m_host[0])
|
||||
{
|
||||
m_errorstr="empty hostname";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_state=STATE_RESOLVING;
|
||||
m_saddr.sin_family=AF_INET;
|
||||
m_saddr.sin_port=htons((unsigned short)port);
|
||||
m_saddr.sin_addr.s_addr=inet_addr(hostname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNL_Connection::~JNL_Connection()
|
||||
{
|
||||
if (m_socket >= 0)
|
||||
{
|
||||
::shutdown(m_socket, SHUT_RDWR);
|
||||
::closesocket(m_socket);
|
||||
m_socket=-1;
|
||||
}
|
||||
free(m_recv_buffer);
|
||||
free(m_send_buffer);
|
||||
if (m_dns_owned)
|
||||
{
|
||||
delete m_dns;
|
||||
}
|
||||
}
|
||||
|
||||
void JNL_Connection::run(int max_send_bytes, int max_recv_bytes, int *bytes_sent, int *bytes_rcvd)
|
||||
{
|
||||
int bytes_allowed_to_send=(max_send_bytes<0)?m_send_buffer_len:max_send_bytes;
|
||||
int bytes_allowed_to_recv=(max_recv_bytes<0)?m_recv_buffer_len:max_recv_bytes;
|
||||
|
||||
if (bytes_sent) *bytes_sent=0;
|
||||
if (bytes_rcvd) *bytes_rcvd=0;
|
||||
|
||||
switch (m_state)
|
||||
{
|
||||
case STATE_RESOLVING:
|
||||
if (m_saddr.sin_addr.s_addr == INADDR_NONE)
|
||||
{
|
||||
int a=m_dns?m_dns->resolve(m_host,(unsigned long int *)&m_saddr.sin_addr.s_addr):-1;
|
||||
if (!a) { m_state=STATE_CONNECTING; }
|
||||
else if (a == 1)
|
||||
{
|
||||
m_state=STATE_RESOLVING;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_errorstr="resolving hostname";
|
||||
m_state=STATE_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!::connect(m_socket,(struct sockaddr *)&m_saddr,16))
|
||||
{
|
||||
m_state=STATE_CONNECTED;
|
||||
}
|
||||
else if (ERRNO!=EINPROGRESS)
|
||||
{
|
||||
m_errorstr="connecting to host";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
else { m_state=STATE_CONNECTING; }
|
||||
break;
|
||||
case STATE_CONNECTING:
|
||||
{
|
||||
fd_set f[3];
|
||||
FD_ZERO(&f[0]);
|
||||
FD_ZERO(&f[1]);
|
||||
FD_ZERO(&f[2]);
|
||||
FD_SET(m_socket,&f[0]);
|
||||
FD_SET(m_socket,&f[1]);
|
||||
FD_SET(m_socket,&f[2]);
|
||||
struct timeval tv;
|
||||
memset(&tv,0,sizeof(tv));
|
||||
if (select(m_socket+1,&f[0],&f[1],&f[2],&tv)==-1)
|
||||
{
|
||||
m_errorstr="connecting to host (calling select())";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
else if (FD_ISSET(m_socket,&f[1]))
|
||||
{
|
||||
m_state=STATE_CONNECTED;
|
||||
}
|
||||
else if (FD_ISSET(m_socket,&f[2]))
|
||||
{
|
||||
m_errorstr="connecting to host";
|
||||
m_state=STATE_ERROR;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_CONNECTED:
|
||||
case STATE_CLOSING:
|
||||
if (m_send_len>0 && bytes_allowed_to_send>0)
|
||||
{
|
||||
int len=m_send_buffer_len-m_send_pos;
|
||||
if (len > m_send_len) len=m_send_len;
|
||||
if (len > bytes_allowed_to_send) len=bytes_allowed_to_send;
|
||||
if (len > 0)
|
||||
{
|
||||
int res=::send(m_socket,m_send_buffer+m_send_pos,len,0);
|
||||
if (res==-1 && ERRNO != EWOULDBLOCK)
|
||||
{
|
||||
// m_state=STATE_CLOSED;
|
||||
// return;
|
||||
}
|
||||
if (res>0)
|
||||
{
|
||||
bytes_allowed_to_send-=res;
|
||||
if (bytes_sent) *bytes_sent+=res;
|
||||
m_send_pos+=res;
|
||||
m_send_len-=res;
|
||||
}
|
||||
}
|
||||
if (m_send_pos>=m_send_buffer_len)
|
||||
{
|
||||
m_send_pos=0;
|
||||
if (m_send_len>0)
|
||||
{
|
||||
len=m_send_buffer_len-m_send_pos;
|
||||
if (len > m_send_len) len=m_send_len;
|
||||
if (len > bytes_allowed_to_send) len=bytes_allowed_to_send;
|
||||
int res=::send(m_socket,m_send_buffer+m_send_pos,len,0);
|
||||
if (res==-1 && ERRNO != EWOULDBLOCK)
|
||||
{
|
||||
// m_state=STATE_CLOSED;
|
||||
}
|
||||
if (res>0)
|
||||
{
|
||||
bytes_allowed_to_send-=res;
|
||||
if (bytes_sent) *bytes_sent+=res;
|
||||
m_send_pos+=res;
|
||||
m_send_len-=res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_recv_len<m_recv_buffer_len)
|
||||
{
|
||||
int len=m_recv_buffer_len-m_recv_pos;
|
||||
if (len > m_recv_buffer_len-m_recv_len) len=m_recv_buffer_len-m_recv_len;
|
||||
if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv;
|
||||
if (len>0)
|
||||
{
|
||||
int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0);
|
||||
if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK))
|
||||
{
|
||||
m_state=STATE_CLOSED;
|
||||
break;
|
||||
}
|
||||
if (res > 0)
|
||||
{
|
||||
bytes_allowed_to_recv-=res;
|
||||
if (bytes_rcvd) *bytes_rcvd+=res;
|
||||
m_recv_pos+=res;
|
||||
m_recv_len+=res;
|
||||
}
|
||||
}
|
||||
if (m_recv_pos >= m_recv_buffer_len)
|
||||
{
|
||||
m_recv_pos=0;
|
||||
if (m_recv_len < m_recv_buffer_len)
|
||||
{
|
||||
len=m_recv_buffer_len-m_recv_len;
|
||||
if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv;
|
||||
if (len > 0)
|
||||
{
|
||||
int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0);
|
||||
if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK))
|
||||
{
|
||||
m_state=STATE_CLOSED;
|
||||
break;
|
||||
}
|
||||
if (res > 0)
|
||||
{
|
||||
bytes_allowed_to_recv-=res;
|
||||
if (bytes_rcvd) *bytes_rcvd+=res;
|
||||
m_recv_pos+=res;
|
||||
m_recv_len+=res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_state == STATE_CLOSING)
|
||||
{
|
||||
if (m_send_len < 1) m_state = STATE_CLOSED;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void JNL_Connection::close(int quick)
|
||||
{
|
||||
if (quick || m_state == STATE_RESOLVING || m_state == STATE_CONNECTING)
|
||||
{
|
||||
m_state=STATE_CLOSED;
|
||||
if (m_socket >= 0)
|
||||
{
|
||||
::shutdown(m_socket, SHUT_RDWR);
|
||||
::closesocket(m_socket);
|
||||
}
|
||||
m_socket=-1;
|
||||
memset(m_recv_buffer,0,m_recv_buffer_len);
|
||||
memset(m_send_buffer,0,m_send_buffer_len);
|
||||
m_remote_port=0;
|
||||
m_recv_len=m_recv_pos=0;
|
||||
m_send_len=m_send_pos=0;
|
||||
m_host[0]=0;
|
||||
memset(&m_saddr,0,sizeof(m_saddr));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_state == STATE_CONNECTED) m_state=STATE_CLOSING;
|
||||
}
|
||||
}
|
||||
|
||||
int JNL_Connection::send_bytes_in_queue(void)
|
||||
{
|
||||
return m_send_len;
|
||||
}
|
||||
|
||||
int JNL_Connection::send_bytes_available(void)
|
||||
{
|
||||
return m_send_buffer_len-m_send_len;
|
||||
}
|
||||
|
||||
int JNL_Connection::send(char *data, int length)
|
||||
{
|
||||
if (length > send_bytes_available())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int write_pos=m_send_pos+m_send_len;
|
||||
if (write_pos >= m_send_buffer_len)
|
||||
{
|
||||
write_pos-=m_send_buffer_len;
|
||||
}
|
||||
|
||||
int len=m_send_buffer_len-write_pos;
|
||||
if (len > length)
|
||||
{
|
||||
len=length;
|
||||
}
|
||||
|
||||
memcpy(m_send_buffer+write_pos,data,len);
|
||||
if (length > len)
|
||||
{
|
||||
memcpy(m_send_buffer,data+len,length-len);
|
||||
}
|
||||
m_send_len+=length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JNL_Connection::send_string(char *line)
|
||||
{
|
||||
return send(line,strlen(line));
|
||||
}
|
||||
|
||||
int JNL_Connection::recv_bytes_available(void)
|
||||
{
|
||||
return m_recv_len;
|
||||
}
|
||||
|
||||
int JNL_Connection::peek_bytes(char *data, int maxlength)
|
||||
{
|
||||
if (maxlength > m_recv_len)
|
||||
{
|
||||
maxlength=m_recv_len;
|
||||
}
|
||||
int read_pos=m_recv_pos-m_recv_len;
|
||||
if (read_pos < 0)
|
||||
{
|
||||
read_pos += m_recv_buffer_len;
|
||||
}
|
||||
int len=m_recv_buffer_len-read_pos;
|
||||
if (len > maxlength)
|
||||
{
|
||||
len=maxlength;
|
||||
}
|
||||
memcpy(data,m_recv_buffer+read_pos,len);
|
||||
if (len < maxlength)
|
||||
{
|
||||
memcpy(data+len,m_recv_buffer,maxlength-len);
|
||||
}
|
||||
|
||||
return maxlength;
|
||||
}
|
||||
|
||||
int JNL_Connection::recv_bytes(char *data, int maxlength)
|
||||
{
|
||||
|
||||
int ml=peek_bytes(data,maxlength);
|
||||
m_recv_len-=ml;
|
||||
return ml;
|
||||
}
|
||||
|
||||
int JNL_Connection::getbfromrecv(int pos, int remove)
|
||||
{
|
||||
int read_pos=m_recv_pos-m_recv_len + pos;
|
||||
if (pos < 0 || pos > m_recv_len) return -1;
|
||||
if (read_pos < 0)
|
||||
{
|
||||
read_pos += m_recv_buffer_len;
|
||||
}
|
||||
if (read_pos >= m_recv_buffer_len)
|
||||
{
|
||||
read_pos-=m_recv_buffer_len;
|
||||
}
|
||||
if (remove) m_recv_len--;
|
||||
return m_recv_buffer[read_pos];
|
||||
}
|
||||
|
||||
int JNL_Connection::recv_lines_available(void)
|
||||
{
|
||||
int l=recv_bytes_available();
|
||||
int lcount=0;
|
||||
int lastch=0;
|
||||
int pos;
|
||||
for (pos=0; pos < l; pos ++)
|
||||
{
|
||||
int t=getbfromrecv(pos,0);
|
||||
if (t == -1) return lcount;
|
||||
if ((t=='\r' || t=='\n') &&(
|
||||
(lastch != '\r' && lastch != '\n') || lastch==t
|
||||
)) lcount++;
|
||||
lastch=t;
|
||||
}
|
||||
return lcount;
|
||||
}
|
||||
|
||||
int JNL_Connection::recv_line(char *line, int maxlength)
|
||||
{
|
||||
if (maxlength > m_recv_len) maxlength=m_recv_len;
|
||||
while (maxlength--)
|
||||
{
|
||||
int t=getbfromrecv(0,1);
|
||||
if (t == -1)
|
||||
{
|
||||
*line=0;
|
||||
return 0;
|
||||
}
|
||||
if (t == '\r' || t == '\n')
|
||||
{
|
||||
int r=getbfromrecv(0,0);
|
||||
if ((r == '\r' || r == '\n') && r != t) getbfromrecv(0,1);
|
||||
*line=0;
|
||||
return 0;
|
||||
}
|
||||
*line++=(char)t;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned long JNL_Connection::get_interface(void)
|
||||
{
|
||||
if (m_socket==-1) return 0;
|
||||
struct sockaddr_in sin;
|
||||
memset(&sin,0,sizeof(sin));
|
||||
socklen_t len=16;
|
||||
if (::getsockname(m_socket,(struct sockaddr *)&sin,&len)) return 0;
|
||||
return (unsigned long) sin.sin_addr.s_addr;
|
||||
}
|
||||
|
|
|
@ -1,135 +1,138 @@
|
|||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: connection.h - JNL TCP connection interface
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Usage:
|
||||
** 1. Create a JNL_Connection object, optionally specifying a JNL_AsyncDNS
|
||||
** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
|
||||
** and the send and receive buffer sizes.
|
||||
** 2. Call connect() to have it connect to a host/port (the hostname will be
|
||||
** resolved if possible).
|
||||
** 3. call run() with the maximum send/recv amounts, and optionally parameters
|
||||
** so you can tell how much has been send/received. You want to do this a lot, while:
|
||||
** 4. check get_state() to check the state of the connection. The states are:
|
||||
** JNL_Connection::STATE_ERROR
|
||||
** - an error has occurred on the connection. the connection has closed,
|
||||
** and you can no longer write to the socket (there still might be
|
||||
** data in the receive buffer - use recv_bytes_available()).
|
||||
** JNL_Connection::STATE_NOCONNECTION
|
||||
** - no connection has been made yet. call connect() already! :)
|
||||
** JNL_Connection::STATE_RESOLVING
|
||||
** - the connection is still waiting for a JNL_AsycnDNS to resolve the
|
||||
** host.
|
||||
** JNL_Connection::STATE_CONNECTING
|
||||
** - the asynchronous call to connect() is still running.
|
||||
** JNL_Connection::STATE_CONNECTED
|
||||
** - the connection has connected, all is well.
|
||||
** JNL_Connection::STATE_CLOSING
|
||||
** - the connection is closing. This happens after a call to close,
|
||||
** without the quick parameter set. This means that the connection
|
||||
** will close once the data in the send buffer is sent (data could
|
||||
** still be being received when it would be closed). After it is
|
||||
** closed, the state will transition to:
|
||||
** JNL_Connection::STATE_CLOSED
|
||||
** - the connection has closed, generally without error. There still
|
||||
** might be data in the receieve buffer, use recv_bytes_available().
|
||||
** 5. Use send() and send_string() to send data. You can use
|
||||
** send_bytes_in_queue() to see how much has yet to go out, or
|
||||
** send_bytes_available() to see how much you can write. If you use send()
|
||||
** or send_string() and not enough room is available, both functions will
|
||||
** return error ( < 0)
|
||||
** 6. Use recv() and recv_line() to get data. If you want to see how much data
|
||||
** there is, use recv_bytes_available() and recv_lines_available(). If you
|
||||
** call recv() and not enough data is available, recv() will return how much
|
||||
** data was actually read. See comments at the function defs.
|
||||
**
|
||||
** 7. To close, call close(1) for a quick close, or close() for a close that will
|
||||
** make the socket close after sending all the data sent.
|
||||
**
|
||||
** 8. delete ye' ol' object.
|
||||
*/
|
||||
|
||||
#ifndef _CONNECTION_H_
|
||||
#define _CONNECTION_H_
|
||||
|
||||
#include "asyncdns.h"
|
||||
|
||||
#define JNL_CONNECTION_AUTODNS ((JNL_AsyncDNS*)-1)
|
||||
|
||||
class JNL_Connection
|
||||
{
|
||||
public:
|
||||
typedef enum
|
||||
{
|
||||
STATE_ERROR,
|
||||
STATE_NOCONNECTION,
|
||||
STATE_RESOLVING,
|
||||
STATE_CONNECTING,
|
||||
STATE_CONNECTED,
|
||||
STATE_CLOSING,
|
||||
STATE_CLOSED
|
||||
} state;
|
||||
|
||||
JNL_Connection(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int sendbufsize=8192, int recvbufsize=8192);
|
||||
~JNL_Connection();
|
||||
|
||||
void connect(char *hostname, int port);
|
||||
void connect(int sock, struct sockaddr_in *loc=NULL); // used by the listen object, usually not needed by users.
|
||||
|
||||
void run(int max_send_bytes=-1, int max_recv_bytes=-1, int *bytes_sent=NULL, int *bytes_rcvd=NULL);
|
||||
int get_state() { return m_state; }
|
||||
char *get_errstr() { return m_errorstr; }
|
||||
|
||||
void close(int quick=0);
|
||||
void flush_send(void) { m_send_len=m_send_pos=0; }
|
||||
|
||||
int send_bytes_in_queue(void);
|
||||
int send_bytes_available(void);
|
||||
int send(char *data, int length); // returns -1 if not enough room
|
||||
int send_string(char *line); // returns -1 if not enough room
|
||||
|
||||
|
||||
int recv_bytes_available(void);
|
||||
int recv_bytes(char *data, int maxlength); // returns actual bytes read
|
||||
unsigned int recv_int(void);
|
||||
int recv_lines_available(void);
|
||||
int recv_line(char *line, int maxlength); // returns 0 if the line was terminated with a \r or \n, 1 if not.
|
||||
// (i.e. if you specify maxlength=10, and the line is 12 bytes long
|
||||
// it will return 1. or if there is no \r or \n and that's all the data
|
||||
// the connection has.)
|
||||
int peek_bytes(char *data, int maxlength); // returns bytes peeked
|
||||
|
||||
unsigned long get_interface(void); // this returns the interface the connection is on
|
||||
unsigned long get_remote(void) { return m_saddr.sin_addr.s_addr; } // remote host ip.
|
||||
short get_remote_port(void) { return m_remote_port; } // this returns the remote port of connection
|
||||
|
||||
protected:
|
||||
int m_socket;
|
||||
short m_remote_port;
|
||||
char *m_recv_buffer;
|
||||
char *m_send_buffer;
|
||||
int m_recv_buffer_len;
|
||||
int m_send_buffer_len;
|
||||
|
||||
int m_recv_pos;
|
||||
int m_recv_len;
|
||||
int m_send_pos;
|
||||
int m_send_len;
|
||||
|
||||
struct sockaddr_in m_saddr;
|
||||
char m_host[256];
|
||||
|
||||
JNL_AsyncDNS *m_dns;
|
||||
int m_dns_owned;
|
||||
|
||||
state m_state;
|
||||
char *m_errorstr;
|
||||
|
||||
int getbfromrecv(int pos, int remove); // used by recv_line*
|
||||
|
||||
};
|
||||
|
||||
#endif // _Connection_H_
|
||||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: connection.h - JNL TCP connection interface
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Usage:
|
||||
** 1. Create a JNL_Connection object, optionally specifying a JNL_AsyncDNS
|
||||
** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
|
||||
** and the send and receive buffer sizes.
|
||||
** 2. Call connect() to have it connect to a host/port (the hostname will be
|
||||
** resolved if possible).
|
||||
** 3. call run() with the maximum send/recv amounts, and optionally parameters
|
||||
** so you can tell how much has been send/received. You want to do this a lot, while:
|
||||
** 4. check get_state() to check the state of the connection. The states are:
|
||||
** JNL_Connection::STATE_ERROR
|
||||
** - an error has occurred on the connection. the connection has closed,
|
||||
** and you can no longer write to the socket (there still might be
|
||||
** data in the receive buffer - use recv_bytes_available()).
|
||||
** JNL_Connection::STATE_NOCONNECTION
|
||||
** - no connection has been made yet. call connect() already! :)
|
||||
** JNL_Connection::STATE_RESOLVING
|
||||
** - the connection is still waiting for a JNL_AsycnDNS to resolve the
|
||||
** host.
|
||||
** JNL_Connection::STATE_CONNECTING
|
||||
** - the asynchronous call to connect() is still running.
|
||||
** JNL_Connection::STATE_CONNECTED
|
||||
** - the connection has connected, all is well.
|
||||
** JNL_Connection::STATE_CLOSING
|
||||
** - the connection is closing. This happens after a call to close,
|
||||
** without the quick parameter set. This means that the connection
|
||||
** will close once the data in the send buffer is sent (data could
|
||||
** still be being received when it would be closed). After it is
|
||||
** closed, the state will transition to:
|
||||
** JNL_Connection::STATE_CLOSED
|
||||
** - the connection has closed, generally without error. There still
|
||||
** might be data in the receieve buffer, use recv_bytes_available().
|
||||
** 5. Use send() and send_string() to send data. You can use
|
||||
** send_bytes_in_queue() to see how much has yet to go out, or
|
||||
** send_bytes_available() to see how much you can write. If you use send()
|
||||
** or send_string() and not enough room is available, both functions will
|
||||
** return error ( < 0)
|
||||
** 6. Use recv() and recv_line() to get data. If you want to see how much data
|
||||
** there is, use recv_bytes_available() and recv_lines_available(). If you
|
||||
** call recv() and not enough data is available, recv() will return how much
|
||||
** data was actually read. See comments at the function defs.
|
||||
**
|
||||
** 7. To close, call close(1) for a quick close, or close() for a close that will
|
||||
** make the socket close after sending all the data sent.
|
||||
**
|
||||
** 8. delete ye' ol' object.
|
||||
**
|
||||
** Unicode support by Jim Park -- 08/24/2007
|
||||
** Keep all the stuff here strictly ANSI.
|
||||
*/
|
||||
|
||||
#ifndef _CONNECTION_H_
|
||||
#define _CONNECTION_H_
|
||||
|
||||
#include "asyncdns.h"
|
||||
|
||||
#define JNL_CONNECTION_AUTODNS ((JNL_AsyncDNS*)-1)
|
||||
|
||||
class JNL_Connection
|
||||
{
|
||||
public:
|
||||
typedef enum
|
||||
{
|
||||
STATE_ERROR,
|
||||
STATE_NOCONNECTION,
|
||||
STATE_RESOLVING,
|
||||
STATE_CONNECTING,
|
||||
STATE_CONNECTED,
|
||||
STATE_CLOSING,
|
||||
STATE_CLOSED
|
||||
} state;
|
||||
|
||||
JNL_Connection(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int sendbufsize=8192, int recvbufsize=8192);
|
||||
~JNL_Connection();
|
||||
|
||||
void connect(char *hostname, int port);
|
||||
void connect(int sock, struct sockaddr_in *loc=NULL); // used by the listen object, usually not needed by users.
|
||||
|
||||
void run(int max_send_bytes=-1, int max_recv_bytes=-1, int *bytes_sent=NULL, int *bytes_rcvd=NULL);
|
||||
int get_state() { return m_state; }
|
||||
char *get_errstr() { return m_errorstr; }
|
||||
|
||||
void close(int quick=0);
|
||||
void flush_send(void) { m_send_len=m_send_pos=0; }
|
||||
|
||||
int send_bytes_in_queue(void);
|
||||
int send_bytes_available(void);
|
||||
int send(char *data, int length); // returns -1 if not enough room
|
||||
int send_string(char *line); // returns -1 if not enough room
|
||||
|
||||
|
||||
int recv_bytes_available(void);
|
||||
int recv_bytes(char *data, int maxlength); // returns actual bytes read
|
||||
unsigned int recv_int(void);
|
||||
int recv_lines_available(void);
|
||||
int recv_line(char *line, int maxlength); // returns 0 if the line was terminated with a \r or \n, 1 if not.
|
||||
// (i.e. if you specify maxlength=10, and the line is 12 bytes long
|
||||
// it will return 1. or if there is no \r or \n and that's all the data
|
||||
// the connection has.)
|
||||
int peek_bytes(char *data, int maxlength); // returns bytes peeked
|
||||
|
||||
unsigned long get_interface(void); // this returns the interface the connection is on
|
||||
unsigned long get_remote(void) { return m_saddr.sin_addr.s_addr; } // remote host ip.
|
||||
short get_remote_port(void) { return m_remote_port; } // this returns the remote port of connection
|
||||
|
||||
protected:
|
||||
int m_socket;
|
||||
short m_remote_port;
|
||||
char *m_recv_buffer;
|
||||
char *m_send_buffer;
|
||||
int m_recv_buffer_len;
|
||||
int m_send_buffer_len;
|
||||
|
||||
int m_recv_pos;
|
||||
int m_recv_len;
|
||||
int m_send_pos;
|
||||
int m_send_len;
|
||||
|
||||
struct sockaddr_in m_saddr;
|
||||
char m_host[256];
|
||||
|
||||
JNL_AsyncDNS *m_dns;
|
||||
int m_dns_owned;
|
||||
|
||||
state m_state;
|
||||
char *m_errorstr;
|
||||
|
||||
int getbfromrecv(int pos, int remove); // used by recv_line*
|
||||
|
||||
};
|
||||
|
||||
#endif // _Connection_H_
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,109 +1,113 @@
|
|||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: httpget.h - JNL interface for doing HTTP GETs.
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Usage:
|
||||
** 1. Create a JNL_HTTPGet object, optionally specifying a JNL_AsyncDNS
|
||||
** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
|
||||
** and the receive buffer size, and a string specifying proxy (or NULL
|
||||
** for none). See note on proxy string below.
|
||||
** 2. call addheader() to add whatever headers you want. It is recommended to
|
||||
** add at least the following two:
|
||||
** addheader("User-Agent:MyApp (Mozilla)");
|
||||
*/// addheader("Accept:*/*");
|
||||
/* ( the comment weirdness is there so I Can do the star-slash :)
|
||||
** 3. Call connect() with the URL you wish to GET (see URL string note below)
|
||||
** 4. Call run() once in a while, checking to see if it returns -1
|
||||
** (if it does return -1, call geterrorstr() to see what the error is).
|
||||
** (if it returns 1, no big deal, the connection has closed).
|
||||
** 5. While you're at it, you can call bytes_available() to see if any data
|
||||
** from the http stream is available, or getheader() to see if any headers
|
||||
** are available, or getreply() to see the HTTP reply, or getallheaders()
|
||||
** to get a double null terminated, null delimited list of headers returned.
|
||||
** 6. If you want to read from the stream, call get_bytes (which returns how much
|
||||
** was actually read).
|
||||
** 7. content_length() is a helper function that uses getheader() to check the
|
||||
** content-length header.
|
||||
** 8. Delete ye' ol' object when done.
|
||||
**
|
||||
** Proxy String:
|
||||
** should be in the format of host:port, or user@host:port, or
|
||||
** user:password@host:port. if port is not specified, 80 is assumed.
|
||||
** URL String:
|
||||
** should be in the format of http://user:pass@host:port/requestwhatever
|
||||
** note that user, pass, port, and /requestwhatever are all optional :)
|
||||
** note that also, http:// is really not important. if you do poo://
|
||||
** or even leave out the http:// altogether, it will still work.
|
||||
*/
|
||||
|
||||
#ifndef _HTTPGET_H_
|
||||
#define _HTTPGET_H_
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
class JNL_HTTPGet
|
||||
{
|
||||
public:
|
||||
JNL_HTTPGet(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int recvbufsize=16384, char *proxy=NULL);
|
||||
~JNL_HTTPGet();
|
||||
|
||||
void addheader(char *header);
|
||||
|
||||
void connect(char *url);
|
||||
|
||||
int run(); // returns: 0 if all is OK. -1 if error (call geterrorstr()). 1 if connection closed.
|
||||
|
||||
int get_status(); // returns 0 if connecting, 1 if reading headers,
|
||||
// 2 if reading content, -1 if error.
|
||||
|
||||
char *getallheaders(); // double null terminated, null delimited list
|
||||
char *getheader(char *headername);
|
||||
char *getreply() { return m_reply; }
|
||||
int getreplycode(); // returns 0 if none yet, otherwise returns http reply code.
|
||||
|
||||
char *geterrorstr() { return m_errstr;}
|
||||
|
||||
int bytes_available();
|
||||
int get_bytes(char *buf, int len);
|
||||
int peek_bytes(char *buf, int len);
|
||||
|
||||
__int64 content_length();
|
||||
|
||||
JNL_Connection *get_con() { return m_con; }
|
||||
|
||||
public:
|
||||
void reinit();
|
||||
void deinit();
|
||||
void seterrstr(char *str) { if (m_errstr) free(m_errstr); m_errstr=(char*)malloc(strlen(str)+1); strcpy(m_errstr,str); }
|
||||
|
||||
void do_parse_url(char *url, char **host, int *port, char **req, char **lp);
|
||||
void do_encode_mimestr(char *in, char *out);
|
||||
|
||||
JNL_AsyncDNS *m_dns;
|
||||
JNL_Connection *m_con;
|
||||
int m_recvbufsize;
|
||||
|
||||
int m_http_state;
|
||||
|
||||
int m_http_port;
|
||||
char *m_http_url;
|
||||
char *m_http_host;
|
||||
char *m_http_lpinfo;
|
||||
char *m_http_request;
|
||||
|
||||
char *m_http_proxylpinfo;
|
||||
char *m_http_proxyhost;
|
||||
int m_http_proxyport;
|
||||
|
||||
char *m_sendheaders;
|
||||
char *m_recvheaders;
|
||||
int m_recvheaders_size;
|
||||
char *m_reply;
|
||||
|
||||
char *m_errstr;
|
||||
};
|
||||
|
||||
#endif // _HTTPGET_H_
|
||||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: httpget.h - JNL interface for doing HTTP GETs.
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Usage:
|
||||
** 1. Create a JNL_HTTPGet object, optionally specifying a JNL_AsyncDNS
|
||||
** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
|
||||
** and the receive buffer size, and a string specifying proxy (or NULL
|
||||
** for none). See note on proxy string below.
|
||||
** 2. call addheader() to add whatever headers you want. It is recommended to
|
||||
** add at least the following two:
|
||||
** addheader("User-Agent:MyApp (Mozilla)");
|
||||
*/// addheader("Accept:*/*");
|
||||
/* ( the comment weirdness is there so I Can do the star-slash :)
|
||||
** 3. Call connect() with the URL you wish to GET (see URL string note below)
|
||||
** 4. Call run() once in a while, checking to see if it returns -1
|
||||
** (if it does return -1, call geterrorstr() to see what the error is).
|
||||
** (if it returns 1, no big deal, the connection has closed).
|
||||
** 5. While you're at it, you can call bytes_available() to see if any data
|
||||
** from the http stream is available, or getheader() to see if any headers
|
||||
** are available, or getreply() to see the HTTP reply, or getallheaders()
|
||||
** to get a double null terminated, null delimited list of headers returned.
|
||||
** 6. If you want to read from the stream, call get_bytes (which returns how much
|
||||
** was actually read).
|
||||
** 7. content_length() is a helper function that uses getheader() to check the
|
||||
** content-length header.
|
||||
** 8. Delete ye' ol' object when done.
|
||||
**
|
||||
** Proxy String:
|
||||
** should be in the format of host:port, or user@host:port, or
|
||||
** user:password@host:port. if port is not specified, 80 is assumed.
|
||||
** URL String:
|
||||
** should be in the format of http://user:pass@host:port/requestwhatever
|
||||
** note that user, pass, port, and /requestwhatever are all optional :)
|
||||
** note that also, http:// is really not important. if you do poo://
|
||||
** or even leave out the http:// altogether, it will still work.
|
||||
**
|
||||
** Reviewed for Unicode support by Jim Park -- 08/24/2004
|
||||
** Everything remains ANSI. Made sure all TCHAR style functions were
|
||||
** changed to strictly ANSI.
|
||||
*/
|
||||
|
||||
#ifndef _HTTPGET_H_
|
||||
#define _HTTPGET_H_
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
class JNL_HTTPGet
|
||||
{
|
||||
public:
|
||||
JNL_HTTPGet(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int recvbufsize=16384, char *proxy=NULL);
|
||||
~JNL_HTTPGet();
|
||||
|
||||
void addheader(char *header);
|
||||
|
||||
void connect(char *url);
|
||||
|
||||
int run(); // returns: 0 if all is OK. -1 if error (call geterrorstr()). 1 if connection closed.
|
||||
|
||||
int get_status(); // returns 0 if connecting, 1 if reading headers,
|
||||
// 2 if reading content, -1 if error.
|
||||
|
||||
char *getallheaders(); // double null terminated, null delimited list
|
||||
char *getheader(char *headername);
|
||||
char *getreply() { return m_reply; }
|
||||
int getreplycode(); // returns 0 if none yet, otherwise returns http reply code.
|
||||
|
||||
char *geterrorstr() { return m_errstr;}
|
||||
|
||||
int bytes_available();
|
||||
int get_bytes(char *buf, int len);
|
||||
int peek_bytes(char *buf, int len);
|
||||
|
||||
__int64 content_length();
|
||||
|
||||
JNL_Connection *get_con() { return m_con; }
|
||||
|
||||
public:
|
||||
void reinit();
|
||||
void deinit();
|
||||
void seterrstr(char *str) { if (m_errstr) free(m_errstr); m_errstr=(char*)malloc(strlen(str)+1); strcpy(m_errstr,str); }
|
||||
|
||||
void do_parse_url(char *url, char **host, int *port, char **req, char **lp);
|
||||
void do_encode_mimestr(char *in, char *out);
|
||||
|
||||
JNL_AsyncDNS *m_dns;
|
||||
JNL_Connection *m_con;
|
||||
int m_recvbufsize;
|
||||
|
||||
int m_http_state;
|
||||
|
||||
int m_http_port;
|
||||
char *m_http_url;
|
||||
char *m_http_host;
|
||||
char *m_http_lpinfo;
|
||||
char *m_http_request;
|
||||
|
||||
char *m_http_proxylpinfo;
|
||||
char *m_http_proxyhost;
|
||||
int m_http_proxyport;
|
||||
|
||||
char *m_sendheaders;
|
||||
char *m_recvheaders;
|
||||
int m_recvheaders_size;
|
||||
char *m_reply;
|
||||
|
||||
char *m_errstr;
|
||||
};
|
||||
|
||||
#endif // _HTTPGET_H_
|
||||
|
|
|
@ -1,42 +1,46 @@
|
|||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: netinc.h - network includes and portability defines (used internally)
|
||||
** License: see jnetlib.h
|
||||
*/
|
||||
|
||||
#ifndef _NETINC_H_
|
||||
#define _NETINC_H_
|
||||
|
||||
#include <windows.h>
|
||||
#include "util.h"
|
||||
|
||||
#define strcasecmp(x,y) stricmp(x,y)
|
||||
#define ERRNO (WSAGetLastError())
|
||||
#define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); }
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define EINPROGRESS WSAEWOULDBLOCK
|
||||
#define memset mini_memset
|
||||
#define memcpy mini_memcpy
|
||||
#define strcpy lstrcpy
|
||||
#define strncpy lstrcpyn
|
||||
#define strcat lstrcat
|
||||
#define strlen lstrlen
|
||||
#define malloc(x) (new char[x])
|
||||
#define free(x) {delete [] x;}
|
||||
typedef int socklen_t;
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_ANY
|
||||
#define INADDR_ANY 0
|
||||
#endif
|
||||
|
||||
#ifndef SHUT_RDWR
|
||||
#define SHUT_RDWR 2
|
||||
#endif
|
||||
|
||||
#endif //_NETINC_H_
|
||||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: netinc.h - network includes and portability defines (used internally)
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Unicode support by Jim Park -- 08/24/2007
|
||||
*/
|
||||
|
||||
#ifndef _NETINC_H_
|
||||
#define _NETINC_H_
|
||||
|
||||
#include <windows.h>
|
||||
#include "util.h"
|
||||
|
||||
#define strcasecmp(x,y) stricmp(x,y)
|
||||
#define ERRNO (WSAGetLastError())
|
||||
#define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); }
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define EINPROGRESS WSAEWOULDBLOCK
|
||||
#define memset mini_memset
|
||||
#define memcpy mini_memcpy
|
||||
// Jim Park: For Unicode support, we need to distinguish whether we are working on
|
||||
// Unicode or ANSI.
|
||||
#define strcpy lstrcpyA
|
||||
#define strncpy lstrcpynA
|
||||
#define strcat lstrcatA
|
||||
#define strlen lstrlenA
|
||||
#define malloc(x) (new char[x])
|
||||
#define free(x) {delete [] x;}
|
||||
typedef int socklen_t;
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_ANY
|
||||
#define INADDR_ANY 0
|
||||
#endif
|
||||
|
||||
#ifndef SHUT_RDWR
|
||||
#define SHUT_RDWR 2
|
||||
#endif
|
||||
|
||||
#endif //_NETINC_H_
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,85 +1,88 @@
|
|||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: util.cpp - JNL implementation of basic network utilities
|
||||
** License: see jnetlib.h
|
||||
*/
|
||||
|
||||
#include "netinc.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
int my_atoi(char *s)
|
||||
{
|
||||
int sign=0;
|
||||
int v=0;
|
||||
if (*s == '-') { s++; sign++; }
|
||||
for (;;)
|
||||
{
|
||||
int c=*s++ - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
}
|
||||
if (sign) return -(int) v;
|
||||
return (int)v;
|
||||
}
|
||||
|
||||
__int64 myatoi64(char *s)
|
||||
{
|
||||
__int64 v=0;
|
||||
int sign=0;
|
||||
|
||||
if (*s == '-')
|
||||
sign++;
|
||||
else
|
||||
s--;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s) - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
}
|
||||
|
||||
if (sign)
|
||||
v = -v;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void myitoa64(__int64 i, char *buffer)
|
||||
{
|
||||
char buf[128], *b = buf;
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
*(buffer++) = '-';
|
||||
i = -i;
|
||||
}
|
||||
if (i == 0) *(buffer++) = '0';
|
||||
else
|
||||
{
|
||||
while (i > 0)
|
||||
{
|
||||
*(b++) = '0' + ((char) (i%10));
|
||||
i /= 10;
|
||||
}
|
||||
while (b > buf) *(buffer++) = *(--b);
|
||||
}
|
||||
*buffer = 0;
|
||||
}
|
||||
|
||||
void mini_memset(void *o,char i,int l)
|
||||
{
|
||||
char *oo=(char*)o;
|
||||
while (l-- > 0) *oo++=i;
|
||||
}
|
||||
void mini_memcpy(void *o,void*i,int l)
|
||||
{
|
||||
char *oo=(char*)o;
|
||||
char *ii=(char*)i;
|
||||
while (l-- > 0) *oo++=*ii++;
|
||||
}
|
||||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: util.cpp - JNL implementation of basic network utilities
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** Unicode support by Jim Park -- 08/24/2007
|
||||
** Keep everything here strictly ANSI. No TCHAR style stuff.
|
||||
*/
|
||||
|
||||
#include "netinc.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
int my_atoi(char *s)
|
||||
{
|
||||
int sign=0;
|
||||
int v=0;
|
||||
if (*s == '-') { s++; sign++; }
|
||||
for (;;)
|
||||
{
|
||||
int c=*s++ - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
}
|
||||
if (sign) return -(int) v;
|
||||
return (int)v;
|
||||
}
|
||||
|
||||
__int64 myatoi64(char *s)
|
||||
{
|
||||
__int64 v=0;
|
||||
int sign=0;
|
||||
|
||||
if (*s == '-')
|
||||
sign++;
|
||||
else
|
||||
s--;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s) - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
}
|
||||
|
||||
if (sign)
|
||||
v = -v;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void myitoa64(__int64 i, char *buffer)
|
||||
{
|
||||
char buf[128], *b = buf;
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
*(buffer++) = '-';
|
||||
i = -i;
|
||||
}
|
||||
if (i == 0) *(buffer++) = '0';
|
||||
else
|
||||
{
|
||||
while (i > 0)
|
||||
{
|
||||
*(b++) = '0' + ((char) (i%10));
|
||||
i /= 10;
|
||||
}
|
||||
while (b > buf) *(buffer++) = *(--b);
|
||||
}
|
||||
*buffer = 0;
|
||||
}
|
||||
|
||||
void mini_memset(void *o,char i,int l)
|
||||
{
|
||||
char *oo=(char*)o;
|
||||
while (l-- > 0) *oo++=i;
|
||||
}
|
||||
void mini_memcpy(void *o,void*i,int l)
|
||||
{
|
||||
char *oo=(char*)o;
|
||||
char *ii=(char*)i;
|
||||
while (l-- > 0) *oo++=*ii++;
|
||||
}
|
||||
|
|
|
@ -1,36 +1,38 @@
|
|||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: util.h - JNL interface for basic network utilities
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** routines you may be interested in:
|
||||
** JNL::open_socketlib();
|
||||
** opens the socket library. Call this once before using any network
|
||||
** code. If you create a new thread, call this again. Only really an
|
||||
** issue for Win32 support, but use it anyway for portability/
|
||||
**
|
||||
** JNL::close_Socketlib();
|
||||
** closes the socketlib. Call this when you're done with the network,
|
||||
** after all your JNetLib objects have been destroyed.
|
||||
**
|
||||
** unsigned long JNL::ipstr_to_addr(const char *cp);
|
||||
** gives you the integer representation of a ip address in dotted
|
||||
** decimal form.
|
||||
**
|
||||
** JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen);
|
||||
** gives you the dotted decimal notation of an integer ip address.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
|
||||
int my_atoi(char *p);
|
||||
__int64 myatoi64(char *s);
|
||||
void myitoa64(__int64 i, char *buffer);
|
||||
void mini_memset(void *,char,int);
|
||||
void mini_memcpy(void *,void*,int);
|
||||
|
||||
#endif //_UTIL_H_
|
||||
/*
|
||||
** JNetLib
|
||||
** Copyright (C) 2000-2001 Nullsoft, Inc.
|
||||
** Author: Justin Frankel
|
||||
** File: util.h - JNL interface for basic network utilities
|
||||
** License: see jnetlib.h
|
||||
**
|
||||
** routines you may be interested in:
|
||||
** JNL::open_socketlib();
|
||||
** opens the socket library. Call this once before using any network
|
||||
** code. If you create a new thread, call this again. Only really an
|
||||
** issue for Win32 support, but use it anyway for portability/
|
||||
**
|
||||
** JNL::close_Socketlib();
|
||||
** closes the socketlib. Call this when you're done with the network,
|
||||
** after all your JNetLib objects have been destroyed.
|
||||
**
|
||||
** unsigned long JNL::ipstr_to_addr(const char *cp);
|
||||
** gives you the integer representation of a ip address in dotted
|
||||
** decimal form.
|
||||
**
|
||||
** JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen);
|
||||
** gives you the dotted decimal notation of an integer ip address.
|
||||
**
|
||||
** Reviewed for Unicode support by Jim Park -- 08/24/2007
|
||||
** Keep the functions here strictly ANSI.
|
||||
*/
|
||||
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
|
||||
int my_atoi(char *p);
|
||||
__int64 myatoi64(char *s);
|
||||
void myitoa64(__int64 i, char *buffer);
|
||||
void mini_memset(void *,char,int);
|
||||
void mini_memcpy(void *,void*,int);
|
||||
|
||||
#endif //_UTIL_H_
|
||||
|
|
|
@ -13,7 +13,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
|||
{
|
||||
BITMAP bm;
|
||||
RECT vp;
|
||||
GetObject(g_hbm, sizeof(bm), (LPSTR)&bm);
|
||||
GetObject(g_hbm, sizeof(bm), (LPTSTR)&bm);
|
||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0);
|
||||
SetWindowLong(hwnd,GWL_STYLE,0);
|
||||
SetWindowPos(hwnd,NULL,
|
||||
|
@ -55,11 +55,11 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
|
||||
void __declspec(dllexport) show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
char fn[MAX_PATH];
|
||||
char temp[64];
|
||||
char *sleep=temp;
|
||||
TCHAR fn[MAX_PATH];
|
||||
TCHAR temp[64];
|
||||
TCHAR *sleep=temp;
|
||||
|
||||
|
||||
EXDLL_INIT();
|
||||
|
@ -68,16 +68,16 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variable
|
|||
popstring(fn);
|
||||
|
||||
sleep_val=0;
|
||||
while (*sleep >= '0' && *sleep <= '9')
|
||||
while (*sleep >= _T('0') && *sleep <= _T('9'))
|
||||
{
|
||||
sleep_val*=10;
|
||||
sleep_val+=*sleep++-'0';
|
||||
sleep_val+=*sleep++-_T('0');
|
||||
}
|
||||
|
||||
if (fn[0] && sleep_val>0)
|
||||
{
|
||||
MSG msg;
|
||||
char classname[4]="_sp";
|
||||
TCHAR classname[4]=_T("_sp");
|
||||
static WNDCLASS wc;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = g_hInstance;
|
||||
|
@ -85,10 +85,10 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variable
|
|||
wc.lpszClassName = classname;
|
||||
if (RegisterClass(&wc))
|
||||
{
|
||||
char fn2[MAX_PATH];
|
||||
TCHAR fn2[MAX_PATH];
|
||||
lstrcpy(fn2,fn);
|
||||
lstrcat(fn,".bmp");
|
||||
lstrcat(fn2,".wav");
|
||||
lstrcat(fn,_T(".bmp"));
|
||||
lstrcat(fn2,_T(".wav"));
|
||||
g_hbm=LoadImage(NULL,fn,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
|
||||
if (g_hbm)
|
||||
{
|
||||
|
@ -114,6 +114,6 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variable
|
|||
}
|
||||
}
|
||||
}
|
||||
wsprintf(temp,"%d",g_rv);
|
||||
wsprintf(temp,_T("%d"),g_rv);
|
||||
pushstring(temp);
|
||||
}
|
||||
|
|
|
@ -10,11 +10,11 @@ HWND hwChild;
|
|||
HWND g_hwStartMenuSelect;
|
||||
HWND g_hwDirList;
|
||||
|
||||
char buf[1024];
|
||||
char text[1024];
|
||||
char progname[1024];
|
||||
char lastused[1024];
|
||||
char checkbox[1024];
|
||||
TCHAR buf[1024];
|
||||
TCHAR text[1024];
|
||||
TCHAR progname[1024];
|
||||
TCHAR lastused[1024];
|
||||
TCHAR checkbox[1024];
|
||||
|
||||
int autoadd;
|
||||
int g_done;
|
||||
|
@ -23,7 +23,7 @@ int rtl;
|
|||
|
||||
void *lpWndProcOld;
|
||||
|
||||
void (__stdcall *validate_filename)(char *);
|
||||
void (__stdcall *validate_filename)(TCHAR *);
|
||||
|
||||
BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
static BOOL CALLBACK ParentWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
@ -34,7 +34,7 @@ static UINT_PTR PluginCallback(enum NSPIM msg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) Init(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
HWND hwStartMenuSelect;
|
||||
|
||||
|
@ -62,35 +62,35 @@ void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variable
|
|||
hwChild = GetDlgItem(hwndParent, 1018);
|
||||
if (!hwChild)
|
||||
{
|
||||
pushstring("error finding childwnd");
|
||||
pushstring(_T("error finding childwnd"));
|
||||
return;
|
||||
}
|
||||
|
||||
popstring(buf);
|
||||
|
||||
while (buf[0] == '/')
|
||||
while (buf[0] == _T('/'))
|
||||
{
|
||||
if (!lstrcmpi(buf+1, "noicon"))
|
||||
if (!lstrcmpi(buf+1, _T("noicon")))
|
||||
{
|
||||
noicon = 1;
|
||||
}
|
||||
else if (!lstrcmpi(buf+1, "rtl"))
|
||||
else if (!lstrcmpi(buf+1, _T("rtl")))
|
||||
{
|
||||
rtl = 1;
|
||||
}
|
||||
else if (!lstrcmpi(buf+1, "text"))
|
||||
else if (!lstrcmpi(buf+1, _T("text")))
|
||||
{
|
||||
popstring(text);
|
||||
}
|
||||
else if (!lstrcmpi(buf+1, "autoadd"))
|
||||
else if (!lstrcmpi(buf+1, _T("autoadd")))
|
||||
{
|
||||
autoadd = 1;
|
||||
}
|
||||
else if (!lstrcmpi(buf+1, "lastused"))
|
||||
else if (!lstrcmpi(buf+1, _T("lastused")))
|
||||
{
|
||||
popstring(lastused);
|
||||
}
|
||||
else if (!lstrcmpi(buf+1, "checknoshortcuts"))
|
||||
else if (!lstrcmpi(buf+1, _T("checknoshortcuts")))
|
||||
{
|
||||
popstring(checkbox);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variable
|
|||
}
|
||||
else
|
||||
{
|
||||
pushstring("error reading parameters");
|
||||
pushstring(_T("error reading parameters"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -115,19 +115,19 @@ void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variable
|
|||
g_hwStartMenuSelect = hwStartMenuSelect;
|
||||
if (!hwStartMenuSelect)
|
||||
{
|
||||
pushstring("error creating dialog");
|
||||
pushstring(_T("error creating dialog"));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
lpWndProcOld = (void *) SetWindowLong(hwndParent, DWL_DLGPROC, (long) ParentWndProc);
|
||||
wsprintf(buf, "%u", hwStartMenuSelect);
|
||||
wsprintf(buf, _T("%u"), hwStartMenuSelect);
|
||||
pushstring(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(dllexport) Show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
|
||||
void __declspec(dllexport) Show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
HWND hwStartMenuSelect = g_hwStartMenuSelect;
|
||||
|
||||
|
@ -148,7 +148,7 @@ void __declspec(dllexport) Show(HWND hwndParent, int string_size, char *variable
|
|||
SetWindowLong(hwndParent, DWL_DLGPROC, (long) lpWndProcOld);
|
||||
}
|
||||
|
||||
void __declspec(dllexport) Select(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) Select(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
Init(hwndParent, string_size, variables, stacktop, extra);
|
||||
if (g_hwStartMenuSelect)
|
||||
|
@ -312,7 +312,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
);
|
||||
}
|
||||
|
||||
SetWindowText(hwText, *text ? text : "Select the Start Menu folder in which you would like to create the program's shortcuts:");
|
||||
SetWindowText(hwText, *text ? text : _T("Select the Start Menu folder in which you would like to create the program's shortcuts:"));
|
||||
|
||||
ProgressiveSetWindowPos(
|
||||
hwLocation,
|
||||
|
@ -321,7 +321,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
MulDiv(12, baseUnitY, 8)
|
||||
);
|
||||
|
||||
if (*lastused == '>')
|
||||
if (*lastused == _T('>'))
|
||||
{
|
||||
CheckDlgButton(hwndDlg, IDC_CHECK, BST_CHECKED);
|
||||
lstrcpy(lastused, lstrcpy(buf, lastused) + 1);
|
||||
|
@ -370,7 +370,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
SendMessage(hwDirList, LB_GETTEXT, SendMessage(hwDirList, LB_GETCURSEL, 0, 0), (WPARAM)buf);
|
||||
if (autoadd)
|
||||
lstrcat(lstrcat(buf, "\\"), progname);
|
||||
lstrcat(lstrcat(buf, _T("\\")), progname);
|
||||
SetWindowText(hwLocation, buf);
|
||||
}
|
||||
else if (LOWORD(wParam) == IDC_CHECK && HIWORD(wParam) == BN_CLICKED)
|
||||
|
@ -383,27 +383,27 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
GetWindowText(hwLocation, buf, MAX_PATH);
|
||||
validate_filename(buf);
|
||||
EnableWindow(GetDlgItem(hwParent, IDOK), *buf != '\0');
|
||||
EnableWindow(GetDlgItem(hwParent, IDOK), *buf != _T('\0'));
|
||||
}
|
||||
break;
|
||||
case WM_USER+666:
|
||||
g_done = 1;
|
||||
if (wParam == NOTIFY_BYE_BYE)
|
||||
pushstring("cancel");
|
||||
pushstring(_T("cancel"));
|
||||
else
|
||||
{
|
||||
GetWindowText(hwLocation, buf + 1, MAX_PATH);
|
||||
validate_filename(buf);
|
||||
if (IsDlgButtonChecked(hwndDlg, IDC_CHECK) == BST_CHECKED)
|
||||
{
|
||||
buf[0] = '>';
|
||||
buf[0] = _T('>');
|
||||
pushstring(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
pushstring(buf + 1);
|
||||
}
|
||||
pushstring("success");
|
||||
pushstring(_T("success"));
|
||||
}
|
||||
case WM_CTLCOLORSTATIC:
|
||||
case WM_CTLCOLOREDIT:
|
||||
|
@ -440,7 +440,7 @@ void AddFolderFromReg(int nFolder)
|
|||
if (!buf[0])
|
||||
return;
|
||||
|
||||
lstrcat(buf, "\\*.*");
|
||||
lstrcat(buf, _T("\\*.*"));
|
||||
hSearch = FindFirstFile(buf, &FileData);
|
||||
if (hSearch != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
|
@ -448,9 +448,9 @@ void AddFolderFromReg(int nFolder)
|
|||
{
|
||||
if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
{
|
||||
if (*(WORD*)FileData.cFileName != *(WORD*)".")
|
||||
if (*(WORD*)FileData.cFileName != *(WORD*)_T("."))
|
||||
{
|
||||
if (*(WORD*)FileData.cFileName != *(WORD*)".." || FileData.cFileName[2])
|
||||
if (*(WORD*)FileData.cFileName != *(WORD*)_T("..") || FileData.cFileName[2])
|
||||
{
|
||||
if (SendMessage(g_hwDirList, LB_FINDSTRINGEXACT, (WPARAM) -1, (LPARAM)FileData.cFileName) == LB_ERR)
|
||||
SendMessage(g_hwDirList, LB_ADDSTRING, 0, (LPARAM)FileData.cFileName);
|
||||
|
|
|
@ -7,7 +7,7 @@ typedef struct tagTempStack TempStack;
|
|||
struct tagTempStack
|
||||
{
|
||||
TempStack *Next;
|
||||
char Data[0];
|
||||
TCHAR Data[0];
|
||||
};
|
||||
TempStack *tempstack = NULL;
|
||||
|
||||
|
@ -27,12 +27,12 @@ PLUGINFUNCTIONSHORT(Copy)
|
|||
{
|
||||
int size = 0;
|
||||
HANDLE source, dest;
|
||||
char *str;
|
||||
TCHAR *str;
|
||||
// Get the string
|
||||
if ((str = system_popstring()) == NULL) return;
|
||||
|
||||
// Check for size option
|
||||
if (str[0] == '/')
|
||||
if (str[0] == _T('/'))
|
||||
{
|
||||
size = (int) myatoi64(str+1);
|
||||
dest = (HANDLE) popint64();
|
||||
|
@ -65,15 +65,15 @@ PLUGINFUNCTIONEND
|
|||
PLUGINFUNCTION(Store)
|
||||
{
|
||||
TempStack *tmp;
|
||||
int size = ((INST_R9+1)*g_stringsize);
|
||||
int size = ((INST_R9+1)*g_stringsize*sizeof(TCHAR));
|
||||
|
||||
char *command, *cmd = command = system_popstring();
|
||||
TCHAR *command, *cmd = command = system_popstring();
|
||||
while (*cmd != 0)
|
||||
{
|
||||
switch (*(cmd++))
|
||||
{
|
||||
case 's':
|
||||
case 'S':
|
||||
case _T('s'):
|
||||
case _T('S'):
|
||||
// Store the whole variables range
|
||||
tmp = (TempStack*) GlobalAlloc(GPTR, sizeof(TempStack)+size);
|
||||
tmp->Next = tempstack;
|
||||
|
@ -82,8 +82,8 @@ PLUGINFUNCTION(Store)
|
|||
// Fill with data
|
||||
copymem(tempstack->Data, g_variables, size);
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
case _T('l'):
|
||||
case _T('L'):
|
||||
if (tempstack == NULL) break;
|
||||
|
||||
// Fill with data
|
||||
|
@ -94,15 +94,15 @@ PLUGINFUNCTION(Store)
|
|||
GlobalFree((HANDLE) tempstack);
|
||||
tempstack = tmp;
|
||||
break;
|
||||
case 'P':
|
||||
case _T('P'):
|
||||
*cmd += 10;
|
||||
case 'p':
|
||||
GlobalFree((HANDLE) system_pushstring(system_getuservariable(*(cmd++)-'0')));
|
||||
case _T('p'):
|
||||
GlobalFree((HANDLE) system_pushstring(system_getuservariable(*(cmd++)-_T('0'))));
|
||||
break;
|
||||
case 'R':
|
||||
case _T('R'):
|
||||
*cmd += 10;
|
||||
case 'r':
|
||||
GlobalFree((HANDLE) system_setuservariable(*(cmd++)-'0', system_popstring()));
|
||||
case _T('r'):
|
||||
GlobalFree((HANDLE) system_setuservariable(*(cmd++)-_T('0'), system_popstring()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Unicode support by Jim Park -- 08/23/2007
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Plugin.h"
|
||||
#include "Buffers.h"
|
||||
|
@ -5,19 +7,19 @@
|
|||
|
||||
HWND g_hwndParent;
|
||||
|
||||
char *AllocString()
|
||||
TCHAR *AllocString()
|
||||
{
|
||||
return (char*) GlobalAlloc(GPTR,g_stringsize);
|
||||
return (TCHAR*) GlobalAlloc(GPTR,g_stringsize*sizeof(TCHAR));
|
||||
}
|
||||
|
||||
char *AllocStr(char *str)
|
||||
TCHAR *AllocStr(TCHAR *str)
|
||||
{
|
||||
return lstrcpy(AllocString(), str);
|
||||
}
|
||||
|
||||
char* system_popstring()
|
||||
TCHAR* system_popstring()
|
||||
{
|
||||
char *str;
|
||||
TCHAR *str;
|
||||
stack_t *th;
|
||||
|
||||
if (!g_stacktop || !*g_stacktop) return NULL;
|
||||
|
@ -31,24 +33,24 @@ char* system_popstring()
|
|||
return str;
|
||||
}
|
||||
|
||||
char *system_pushstring(char *str)
|
||||
TCHAR *system_pushstring(TCHAR *str)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop) return str;
|
||||
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
|
||||
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+(g_stringsize*sizeof(TCHAR)));
|
||||
lstrcpyn(th->text,str,g_stringsize);
|
||||
th->next=*g_stacktop;
|
||||
*g_stacktop=th;
|
||||
return str;
|
||||
}
|
||||
|
||||
char *system_getuservariable(int varnum)
|
||||
TCHAR *system_getuservariable(int varnum)
|
||||
{
|
||||
if (varnum < 0 || varnum >= __INST_LAST) return AllocString();
|
||||
return AllocStr(g_variables+varnum*g_stringsize);
|
||||
}
|
||||
|
||||
char *system_setuservariable(int varnum, char *var)
|
||||
TCHAR *system_setuservariable(int varnum, TCHAR *var)
|
||||
{
|
||||
if (var != NULL && varnum >= 0 && varnum < __INST_LAST) {
|
||||
lstrcpy (g_variables + varnum*g_stringsize, var);
|
||||
|
@ -57,31 +59,31 @@ char *system_setuservariable(int varnum, char *var)
|
|||
}
|
||||
|
||||
// Updated for int64 and simple bitwise operations
|
||||
__int64 myatoi64(char *s)
|
||||
__int64 myatoi64(TCHAR *s)
|
||||
{
|
||||
__int64 v=0;
|
||||
// Check for right input
|
||||
if (!s) return 0;
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||
if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X')))
|
||||
{
|
||||
s++;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s);
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
else if (c >= 'a' && c <= 'f') c-='a'-10;
|
||||
else if (c >= 'A' && c <= 'F') c-='A'-10;
|
||||
if (c >= _T('0') && c <= _T('9')) c-=_T('0');
|
||||
else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10;
|
||||
else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10;
|
||||
else break;
|
||||
v<<=4;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
|
||||
else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0'))
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s);
|
||||
if (c >= '0' && c <= '7') c-='0';
|
||||
if (c >= _T('0') && c <= _T('7')) c-=_T('0');
|
||||
else break;
|
||||
v<<=3;
|
||||
v+=c;
|
||||
|
@ -90,10 +92,10 @@ __int64 myatoi64(char *s)
|
|||
else
|
||||
{
|
||||
int sign=0;
|
||||
if (*s == '-') sign++; else s--;
|
||||
if (*s == _T('-')) sign++; else s--;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s) - '0';
|
||||
int c=*(++s) - _T('0');
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
|
@ -102,7 +104,7 @@ __int64 myatoi64(char *s)
|
|||
}
|
||||
|
||||
// Support for simple ORed expressions
|
||||
if (*s == '|')
|
||||
if (*s == _T('|'))
|
||||
{
|
||||
v |= myatoi64(s+1);
|
||||
}
|
||||
|
@ -110,21 +112,21 @@ __int64 myatoi64(char *s)
|
|||
return v;
|
||||
}
|
||||
|
||||
void myitoa64(__int64 i, char *buffer)
|
||||
void myitoa64(__int64 i, TCHAR *buffer)
|
||||
{
|
||||
char buf[128], *b = buf;
|
||||
TCHAR buf[128], *b = buf;
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
*(buffer++) = '-';
|
||||
*(buffer++) = _T('-');
|
||||
i = -i;
|
||||
}
|
||||
if (i == 0) *(buffer++) = '0';
|
||||
if (i == 0) *(buffer++) = _T('0');
|
||||
else
|
||||
{
|
||||
while (i > 0)
|
||||
{
|
||||
*(b++) = '0' + ((char) (i%10));
|
||||
*(b++) = _T('0') + ((TCHAR) (i%10));
|
||||
i /= 10;
|
||||
}
|
||||
while (b > buf) *(buffer++) = *(--b);
|
||||
|
@ -135,7 +137,7 @@ void myitoa64(__int64 i, char *buffer)
|
|||
int popint64()
|
||||
{
|
||||
int value;
|
||||
char *str;
|
||||
TCHAR *str;
|
||||
if ((str = system_popstring()) == NULL) return -1;
|
||||
value = (int) myatoi64(str);
|
||||
GlobalFree(str);
|
||||
|
@ -144,14 +146,14 @@ int popint64()
|
|||
|
||||
void system_pushint(int value)
|
||||
{
|
||||
char buffer[1024];
|
||||
wsprintf(buffer, "%d", value);
|
||||
TCHAR buffer[1024];
|
||||
wsprintf(buffer, _T("%d"), value);
|
||||
system_pushstring(buffer);
|
||||
}
|
||||
|
||||
char *copymem(char *output, char *input, int size)
|
||||
TCHAR *copymem(TCHAR *output, TCHAR *input, int size)
|
||||
{
|
||||
char *out = output;
|
||||
TCHAR *out = output;
|
||||
if ((input != NULL) && (output != NULL))
|
||||
while (size-- > 0) *(out++) = *(input++);
|
||||
return output;
|
||||
|
|
|
@ -5,29 +5,29 @@
|
|||
|
||||
#define PLUGINFUNCTION(name) \
|
||||
void __declspec(dllexport) name( \
|
||||
HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) { \
|
||||
HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { \
|
||||
/*g_hwndParent=hwndParent;*/ \
|
||||
EXDLL_INIT(); \
|
||||
extra->RegisterPluginCallback(g_hInstance, NSISCallback);
|
||||
#define PLUGINFUNCTIONEND }
|
||||
|
||||
#define PLUGINFUNCTIONSHORT(name) void __declspec(dllexport) name(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { \
|
||||
#define PLUGINFUNCTIONSHORT(name) void __declspec(dllexport) name(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { \
|
||||
g_stringsize=string_size; \
|
||||
g_stacktop=stacktop;
|
||||
|
||||
extern char *AllocStr(char *str);
|
||||
extern void myitoa64(__int64 i, char *buffer);
|
||||
extern char *AllocString();
|
||||
extern char *system_getuservariable(int varnum);
|
||||
extern char *system_setuservariable(int varnum, char *var);
|
||||
extern char* system_popstring(); // NULL - stack empty
|
||||
extern char* system_pushstring(char *str);
|
||||
extern __int64 myatoi64(char *s);
|
||||
extern TCHAR *AllocStr(TCHAR *str);
|
||||
extern void myitoa64(__int64 i, TCHAR *buffer);
|
||||
extern TCHAR *AllocString();
|
||||
extern TCHAR *system_getuservariable(int varnum);
|
||||
extern TCHAR *system_setuservariable(int varnum, TCHAR *var);
|
||||
extern TCHAR* system_popstring(); // NULL - stack empty
|
||||
extern TCHAR* system_pushstring(TCHAR *str);
|
||||
extern __int64 myatoi64(TCHAR *s);
|
||||
extern int popint64(); // -1 -> stack empty
|
||||
extern void system_pushint(int value);
|
||||
|
||||
extern HANDLE GlobalCopy(HANDLE Old);
|
||||
extern char *copymem(char *output, char *input, int size);
|
||||
extern TCHAR *copymem(TCHAR *output, TCHAR *input, int size);
|
||||
|
||||
extern UINT_PTR NSISCallback(enum NSPIM);
|
||||
|
||||
|
|
|
@ -45,15 +45,15 @@ int CallbackIndex;
|
|||
HINSTANCE g_hInstance;
|
||||
|
||||
// Return to callback caller with stack restore
|
||||
char retexpr[4];
|
||||
TCHAR retexpr[4];
|
||||
HANDLE retaddr;
|
||||
|
||||
char *GetResultStr(SystemProc *proc)
|
||||
TCHAR *GetResultStr(SystemProc *proc)
|
||||
{
|
||||
char *buf = AllocString();
|
||||
if (proc->ProcResult == PR_OK) lstrcpy(buf, "ok");
|
||||
else if (proc->ProcResult == PR_ERROR) lstrcpy(buf, "error");
|
||||
else if (proc->ProcResult == PR_CALLBACK) wsprintf(buf, "callback%d", proc->CallbackIndex);
|
||||
TCHAR *buf = AllocString();
|
||||
if (proc->ProcResult == PR_OK) lstrcpy(buf, _T("ok"));
|
||||
else if (proc->ProcResult == PR_ERROR) lstrcpy(buf, _T("error"));
|
||||
else if (proc->ProcResult == PR_CALLBACK) wsprintf(buf, _T("callback%d"), proc->CallbackIndex);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -61,16 +61,16 @@ char *GetResultStr(SystemProc *proc)
|
|||
|
||||
// System log debugging turned on
|
||||
#define SYSTEM_LOG_ADD(a) { register int _len = lstrlen(syslogbuf); lstrcpyn(syslogbuf + _len, a, sizeof(syslogbuf) - _len); }
|
||||
#define SYSTEM_LOG_POST { SYSTEM_LOG_ADD("\n"); WriteToLog(syslogbuf); *syslogbuf = 0; }
|
||||
#define SYSTEM_LOG_POST { SYSTEM_LOG_ADD(_T("\n")); WriteToLog(syslogbuf); *syslogbuf = 0; }
|
||||
|
||||
HANDLE logfile = NULL;
|
||||
char syslogbuf[4096] = "";
|
||||
TCHAR syslogbuf[4096] = _T("");
|
||||
int logop = 0;
|
||||
|
||||
void WriteToLog(char *buffer)
|
||||
void WriteToLog(TCHAR *buffer)
|
||||
{
|
||||
DWORD written;
|
||||
char timebuffer[128];
|
||||
TCHAR timebuffer[128];
|
||||
|
||||
GetTickCount();
|
||||
|
||||
|
@ -78,7 +78,7 @@ void WriteToLog(char *buffer)
|
|||
|
||||
SetFilePointer(logfile, 0, 0, FILE_END);
|
||||
|
||||
wsprintf(timebuffer, "%04d %04d.%03d ", (++logop)%10000, (GetTickCount() / 1000) % 10000,
|
||||
wsprintf(timebuffer, _T("%04d %04d.%03d "), (++logop)%10000, (GetTickCount() / 1000) % 10000,
|
||||
GetTickCount() % 1000);
|
||||
|
||||
_RPT0(_CRT_WARN, timebuffer);
|
||||
|
@ -91,14 +91,14 @@ void WriteToLog(char *buffer)
|
|||
|
||||
PLUGINFUNCTION(Debug)
|
||||
{
|
||||
char *o1;
|
||||
TCHAR *o1;
|
||||
o1 = system_popstring();
|
||||
|
||||
if (logfile == NULL)
|
||||
if (lstrlen(o1) > 0)
|
||||
{
|
||||
SYSTEMTIME t;
|
||||
char buffer[1024], buftime[1024], bufdate[1024];
|
||||
TCHAR buffer[1024], buftime[1024], bufdate[1024];
|
||||
|
||||
// Init debugging
|
||||
logfile = CreateFile(o1, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
||||
|
@ -110,7 +110,7 @@ PLUGINFUNCTION(Debug)
|
|||
GetLocalTime(&t);
|
||||
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, LOCALE_NOUSEROVERRIDE, &t, NULL, buftime, 1024);
|
||||
GetDateFormat(LOCALE_SYSTEM_DEFAULT, LOCALE_NOUSEROVERRIDE, &t, NULL, bufdate, 1024);
|
||||
wsprintf(buffer, "System, %s %s [build "__TIME__" "__DATE__"]\n", buftime, bufdate);
|
||||
wsprintf(buffer, _T("System, %s %s [build "__TIME__" ")__DATE___T("]\n"), buftime, bufdate);
|
||||
WriteToLog(buffer);
|
||||
} else ;
|
||||
else
|
||||
|
@ -121,7 +121,7 @@ PLUGINFUNCTION(Debug)
|
|||
} else
|
||||
{
|
||||
// Stop debugging
|
||||
WriteToLog("Debug stopped.\n\n\n");
|
||||
WriteToLog(_T("Debug stopped.\n\n\n"));
|
||||
CloseHandle(logfile);
|
||||
logfile = NULL;
|
||||
}
|
||||
|
@ -141,15 +141,15 @@ PLUGINFUNCTION(Get)
|
|||
SystemProc *proc = PrepareProc(FALSE);
|
||||
if (proc == NULL)
|
||||
{
|
||||
system_pushstring("error");
|
||||
system_pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
|
||||
SYSTEM_LOG_ADD("Get ");
|
||||
SYSTEM_LOG_ADD(_T("Get "));
|
||||
SYSTEM_LOG_ADD(proc->DllName);
|
||||
SYSTEM_LOG_ADD("::");
|
||||
SYSTEM_LOG_ADD(_T("::"));
|
||||
SYSTEM_LOG_ADD(proc->ProcName);
|
||||
SYSTEM_LOG_ADD("\n");
|
||||
SYSTEM_LOG_ADD(_T("\n"));
|
||||
SYSTEM_LOG_POST;
|
||||
if ((proc->Options & POPT_ALWRETURN) != 0)
|
||||
{
|
||||
|
@ -178,11 +178,11 @@ PLUGINFUNCTION(Call)
|
|||
if (proc == NULL)
|
||||
return;
|
||||
|
||||
SYSTEM_LOG_ADD("Call ");
|
||||
SYSTEM_LOG_ADD(_T("Call "));
|
||||
SYSTEM_LOG_ADD(proc->DllName);
|
||||
SYSTEM_LOG_ADD("::");
|
||||
SYSTEM_LOG_ADD(_T("::"));
|
||||
SYSTEM_LOG_ADD(proc->ProcName);
|
||||
SYSTEM_LOG_ADD("\n");
|
||||
SYSTEM_LOG_ADD(_T("\n"));
|
||||
if (proc->ProcResult != PR_CALLBACK)
|
||||
ParamAllocate(proc);
|
||||
ParamsIn(proc);
|
||||
|
@ -253,13 +253,13 @@ PLUGINFUNCTION(Call)
|
|||
PLUGINFUNCTIONSHORT(Int64Op)
|
||||
{
|
||||
__int64 i1, i2 = 0, i3, i4;
|
||||
char *op, *o1, *o2;
|
||||
char buf[128];
|
||||
TCHAR *op, *o1, *o2;
|
||||
TCHAR buf[128];
|
||||
|
||||
// Get strings
|
||||
o1 = system_popstring(); op = system_popstring();
|
||||
i1 = myatoi64(o1); // convert first arg to int64
|
||||
if ((*op != '~') && (*op != '!'))
|
||||
if ((*op != _T('~')) && (*op != _T('!')))
|
||||
{
|
||||
// get second arg, convert it, free it
|
||||
o2 = system_popstring();
|
||||
|
@ -270,25 +270,25 @@ PLUGINFUNCTIONSHORT(Int64Op)
|
|||
// operation
|
||||
switch (*op)
|
||||
{
|
||||
case '+': i1 += i2; break;
|
||||
case '-': i1 -= i2; break;
|
||||
case '*': i1 *= i2; break;
|
||||
case '/':
|
||||
case '%':
|
||||
case _T('+'): i1 += i2; break;
|
||||
case _T('-'): i1 -= i2; break;
|
||||
case _T('*'): i1 *= i2; break;
|
||||
case _T('/'):
|
||||
case _T('%'):
|
||||
// It's unclear, but in this case compiler will use DivMod rountine
|
||||
// instead of two separate Div and Mod rountines.
|
||||
if (i2 == 0) { i3 = 0; i4 = i1; }
|
||||
else {i3 = i1 / i2; i4 = i1 % i2; }
|
||||
if (*op == '/') i1 = i3; else i1 = i4;
|
||||
if (*op == _T('/')) i1 = i3; else i1 = i4;
|
||||
break;
|
||||
case '|': if (op[1] == '|') i1 = i1 || i2; else i1 |= i2; break;
|
||||
case '&': if (op[1] == '&') i1 = i1 && i2; else i1 &= i2; break;
|
||||
case '^': i1 ^= i2; break;
|
||||
case '~': i1 = ~i1; break;
|
||||
case '!': i1 = !i1; break;
|
||||
case '<': if (op[1] == '<') i1 = i1 << i2; else i1 = i1 < i2; break;
|
||||
case '>': if (op[1] == '>') i1 = i1 >> i2; else i1 = i1 > i2; break;
|
||||
case '=': i1 = (i1 == i2); break;
|
||||
case _T('|'): if (op[1] == _T('|')) i1 = i1 || i2; else i1 |= i2; break;
|
||||
case _T('&'): if (op[1] == _T('&')) i1 = i1 && i2; else i1 &= i2; break;
|
||||
case _T('^'): i1 ^= i2; break;
|
||||
case _T('~'): i1 = ~i1; break;
|
||||
case _T('!'): i1 = !i1; break;
|
||||
case _T('<'): if (op[1] == _T('<')) i1 = i1 << i2; else i1 = i1 < i2; break;
|
||||
case _T('>'): if (op[1] == _T('>')) i1 = i1 >> i2; else i1 = i1 > i2; break;
|
||||
case _T('='): i1 = (i1 == i2); break;
|
||||
}
|
||||
|
||||
// Output and freedom
|
||||
|
@ -297,11 +297,11 @@ PLUGINFUNCTIONSHORT(Int64Op)
|
|||
GlobalFree(o1); GlobalFree(op);
|
||||
} PLUGINFUNCTIONEND
|
||||
|
||||
__int64 GetIntFromString(char **p)
|
||||
__int64 GetIntFromString(TCHAR **p)
|
||||
{
|
||||
char buffer[128], *b = buffer;
|
||||
TCHAR buffer[128], *b = buffer;
|
||||
(*p)++; // First character should be skipped
|
||||
while (((**p >= 'a') && (**p <= 'f')) || ((**p >= 'A') && (**p <= 'F')) || ((**p >= '0') && (**p <= '9')) || (**p == 'X') || (**p == '-') || (**p == 'x') || (**p == '|')) *(b++) = *((*p)++);
|
||||
while (((**p >= _T('a')) && (**p <= _T('f'))) || ((**p >= _T('A')) && (**p <= _T('F'))) || ((**p >= _T('0')) && (**p <= _T('9'))) || (**p == _T('X')) || (**p == _T('-')) || (**p == _T('x')) || (**p == _T('|'))) *(b++) = *((*p)++);
|
||||
*b = 0;
|
||||
(*p)--; // We should point at last digit
|
||||
return myatoi64(buffer);
|
||||
|
@ -316,7 +316,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
temp = 0, temp2, temp3, temp4;
|
||||
BOOL param_defined = FALSE;
|
||||
SystemProc *proc = NULL;
|
||||
char *ibuf, *ib, *sbuf, *cbuf, *cb;
|
||||
TCHAR *ibuf, *ib, *sbuf, *cbuf, *cb;
|
||||
|
||||
// Retrieve proc specs
|
||||
cb = (cbuf = AllocString()); // Current String buffer
|
||||
|
@ -339,16 +339,16 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
switch (*ib)
|
||||
{
|
||||
case 0x0: SectionType = -1; break;
|
||||
case '#': SectionType = PST_PROC; ProcType = PT_NOTHING; break;
|
||||
case '(':
|
||||
case _T('#'): SectionType = PST_PROC; ProcType = PT_NOTHING; break;
|
||||
case _T('('):
|
||||
SectionType = PST_PARAMS;
|
||||
// fake-real parameter: for COM interfaces first param is Interface Pointer
|
||||
ParamIndex = ((ProcType == PT_VTABLEPROC)?(2):(1));
|
||||
temp3 = temp = 0;
|
||||
param_defined = FALSE;
|
||||
break;
|
||||
case ')': SectionType = PST_RETURN; temp3 = temp = 0; break;
|
||||
case '?': SectionType = PST_OPTIONS; temp = 1; break;
|
||||
case _T(')'): SectionType = PST_RETURN; temp3 = temp = 0; break;
|
||||
case _T('?'): SectionType = PST_OPTIONS; temp = 1; break;
|
||||
default:
|
||||
changed = FALSE;
|
||||
}
|
||||
|
@ -437,18 +437,18 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
case PST_PROC:
|
||||
switch (*ib)
|
||||
{
|
||||
case ':':
|
||||
case '-':
|
||||
case _T(':'):
|
||||
case _T('-'):
|
||||
// Is it '::'
|
||||
if ((*(ib) == '-') && (*(ib+1) == '>'))
|
||||
if ((*(ib) == _T('-')) && (*(ib+1) == _T('>')))
|
||||
{
|
||||
ProcType = PT_VTABLEPROC;
|
||||
} else
|
||||
{
|
||||
if ((*(ib+1) != ':') || (*(ib) == '-')) break;
|
||||
if ((*(ib+1) != _T(':')) || (*(ib) == _T('-'))) break;
|
||||
ProcType = PT_PROC;
|
||||
}
|
||||
ib++; // Skip next ':'
|
||||
ib++; // Skip next _T(':')
|
||||
|
||||
if (cb > cbuf)
|
||||
{
|
||||
|
@ -459,7 +459,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
// Ok
|
||||
ChangesDone = PCD_DONE;
|
||||
break;
|
||||
case '*':
|
||||
case _T('*'):
|
||||
// Structure defenition
|
||||
ProcType = PT_STRUCT;
|
||||
ChangesDone = PCD_DONE;
|
||||
|
@ -474,9 +474,9 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
temp2 = -1; temp4 = 0; // Our type placeholder
|
||||
switch (*ib)
|
||||
{
|
||||
case ' ':
|
||||
case _T(' '):
|
||||
break;
|
||||
case '_': // No param cutting specifier
|
||||
case _T('_'): // No param cutting specifier
|
||||
if (proc->ParamCount > ParamIndex) ParamIndex = proc->ParamCount;
|
||||
temp3 = temp = 0; // Clear parameter options
|
||||
if (proc->ParamCount != ((ProcType == PT_VTABLEPROC) ? 1 : 0))
|
||||
|
@ -488,59 +488,59 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
param_defined = TRUE;
|
||||
}
|
||||
break;
|
||||
case ',': // Next param
|
||||
case _T(','): // Next param
|
||||
temp3 = temp = 0; // Clear parameter options
|
||||
ParamIndex++;
|
||||
param_defined = TRUE;
|
||||
break;
|
||||
case '&':
|
||||
case _T('&'):
|
||||
temp = 1; break; // Special parameter option
|
||||
case '*':
|
||||
case _T('*'):
|
||||
temp = -1; break; // Pointer parameter option
|
||||
|
||||
// Types
|
||||
case 'v':
|
||||
case 'V': temp2 = PAT_VOID; break;
|
||||
case 'i':
|
||||
case 'I': temp2 = PAT_INT; break;
|
||||
case 'l':
|
||||
case 'L': temp2 = PAT_LONG; break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
case 't':
|
||||
case 'T': temp2 = PAT_STRING; break;
|
||||
case 'g':
|
||||
case 'G': temp2 = PAT_GUID; break;
|
||||
case 'w':
|
||||
case 'W': temp2 = PAT_WSTRING; break;
|
||||
case 'k':
|
||||
case 'K': temp2 = PAT_CALLBACK; break;
|
||||
case _T('v'):
|
||||
case _T('V'): temp2 = PAT_VOID; break;
|
||||
case _T('i'):
|
||||
case _T('I'): temp2 = PAT_INT; break;
|
||||
case _T('l'):
|
||||
case _T('L'): temp2 = PAT_LONG; break;
|
||||
case _T('m'):
|
||||
case _T('M'):
|
||||
case _T('t'):
|
||||
case _T('T'): temp2 = PAT_STRING; break;
|
||||
case _T('g'):
|
||||
case _T('G'): temp2 = PAT_GUID; break;
|
||||
case _T('w'):
|
||||
case _T('W'): temp2 = PAT_WSTRING; break;
|
||||
case _T('k'):
|
||||
case _T('K'): temp2 = PAT_CALLBACK; break;
|
||||
|
||||
// Input output specifiers
|
||||
case '.': temp3++; break; // skip specifier
|
||||
case _T('.'): temp3++; break; // skip specifier
|
||||
|
||||
case 'R':
|
||||
case _T('R'):
|
||||
temp4 = ((int) GetIntFromString(&ib))+1;
|
||||
if (temp4 < 11) temp4 += 10;
|
||||
break;
|
||||
case 'r': temp4 = ((int) GetIntFromString(&ib))+1; break; // Register
|
||||
case _T('r'): temp4 = ((int) GetIntFromString(&ib))+1; break; // Register
|
||||
|
||||
case '-':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
case _T('-'):
|
||||
case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'):
|
||||
case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'):
|
||||
// Numeric inline
|
||||
if (temp3 == 0)
|
||||
{
|
||||
ib--;
|
||||
// It's stupid, I know, but I'm too laze to do another thing
|
||||
myitoa64(GetIntFromString(&(ib)),(char *)(temp4 = (int) AllocString()));
|
||||
myitoa64(GetIntFromString(&(ib)),(TCHAR *)(temp4 = (int) AllocString()));
|
||||
}
|
||||
break;
|
||||
|
||||
case '\"': case '\'': case '`':
|
||||
case _T('\"'): case _T('\''): case _T('`'):
|
||||
// Character inline
|
||||
{
|
||||
char start = *ib;
|
||||
TCHAR start = *ib;
|
||||
cb = cbuf;
|
||||
// copy inline
|
||||
while (!((*(++ib) == start) && (*(ib+1) != start)) && (*ib))
|
||||
|
@ -554,18 +554,18 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
case 'S': temp4 = -1; break; // Stack
|
||||
case 'c':
|
||||
case 'C': temp4 = INST_CMDLINE+1; break;
|
||||
case 'd':
|
||||
case 'D': temp4 = INST_INSTDIR+1; break;
|
||||
case 'o':
|
||||
case 'O': temp4 = INST_OUTDIR+1; break;
|
||||
case 'e':
|
||||
case 'E': temp4 = INST_EXEDIR+1; break;
|
||||
case 'a':
|
||||
case 'A': temp4 = INST_LANG+1; break;
|
||||
case _T('s'):
|
||||
case _T('S'): temp4 = -1; break; // Stack
|
||||
case _T('c'):
|
||||
case _T('C'): temp4 = INST_CMDLINE+1; break;
|
||||
case _T('d'):
|
||||
case _T('D'): temp4 = INST_INSTDIR+1; break;
|
||||
case _T('o'):
|
||||
case _T('O'): temp4 = INST_OUTDIR+1; break;
|
||||
case _T('e'):
|
||||
case _T('E'): temp4 = INST_EXEDIR+1; break;
|
||||
case _T('a'):
|
||||
case _T('A'): temp4 = INST_LANG+1; break;
|
||||
}
|
||||
|
||||
// Param type changed?
|
||||
|
@ -608,25 +608,25 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
temp2 = 0;
|
||||
switch (*ib)
|
||||
{
|
||||
case ' ':
|
||||
case _T(' '):
|
||||
break;
|
||||
case '!': temp = -temp; break;
|
||||
case 'c':
|
||||
case _T('!'): temp = -temp; break;
|
||||
case _T('c'):
|
||||
temp2 = POPT_CDECL;
|
||||
break;
|
||||
case 'r':
|
||||
case _T('r'):
|
||||
temp2 = POPT_ALWRETURN;
|
||||
break;
|
||||
case 'n':
|
||||
case _T('n'):
|
||||
temp2 = POPT_NEVERREDEF;
|
||||
break;
|
||||
case 's':
|
||||
case _T('s'):
|
||||
temp2 = POPT_GENSTACK;
|
||||
break;
|
||||
case 'e':
|
||||
case _T('e'):
|
||||
temp2 = POPT_ERROR;
|
||||
break;
|
||||
case 'u':
|
||||
case _T('u'):
|
||||
temp2 = POPT_UNLOAD;
|
||||
break;
|
||||
}
|
||||
|
@ -713,7 +713,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
if ((proc->Proc = GetProcAddress(proc->Dll, proc->ProcName)) == NULL)
|
||||
{
|
||||
// automatic A discover
|
||||
lstrcat(proc->ProcName, "A");
|
||||
lstrcat(proc->ProcName, _T("A"));
|
||||
if ((proc->Proc = GetProcAddress(proc->Dll, proc->ProcName)) == NULL)
|
||||
proc->ProcResult = PR_ERROR;
|
||||
}
|
||||
|
@ -742,7 +742,7 @@ void ParamAllocate(SystemProc *proc)
|
|||
void ParamsIn(SystemProc *proc)
|
||||
{
|
||||
int i, *place;
|
||||
char *realbuf;
|
||||
TCHAR *realbuf;
|
||||
LPWSTR wstr;
|
||||
|
||||
i = (proc->ParamCount > 0)?(1):(0);
|
||||
|
@ -751,14 +751,14 @@ void ParamsIn(SystemProc *proc)
|
|||
ProcParameter *par = &proc->Params[i];
|
||||
// Step 1: retrive value
|
||||
if ((par->Input == IOT_NONE) || (par->Input == IOT_INLINE))
|
||||
realbuf = AllocStr("");
|
||||
realbuf = AllocStr(_T(""));
|
||||
else if (par->Input == IOT_STACK) realbuf = system_popstring();
|
||||
else if ((par->Input > 0) && (par->Input <= __INST_LAST))
|
||||
realbuf = system_getuservariable(par->Input - 1);
|
||||
else
|
||||
{
|
||||
// Inline input, will be freed as realbuf
|
||||
realbuf = (char*) par->Input;
|
||||
realbuf = (TCHAR*) par->Input;
|
||||
par->Input = IOT_INLINE;
|
||||
}
|
||||
|
||||
|
@ -809,8 +809,8 @@ void ParamsIn(SystemProc *proc)
|
|||
|
||||
#ifdef SYSTEM_LOG_DEBUG
|
||||
{
|
||||
char buf[1024];
|
||||
wsprintf(buf, "\t\t\tParam In %d: type %d value 0x%08X value2 0x%08X\n", i,
|
||||
TCHAR buf[1024];
|
||||
wsprintf(buf, _T("\t\t\tParam In %d: type %d value 0x%08X value2 0x%08X\n"), i,
|
||||
par->Type, par->Value, par->_value);
|
||||
SYSTEM_LOG_ADD(buf);
|
||||
}
|
||||
|
@ -837,7 +837,7 @@ void ParamsDeAllocate(SystemProc *proc)
|
|||
void ParamsOut(SystemProc *proc)
|
||||
{
|
||||
int i, *place;
|
||||
char *realbuf;
|
||||
TCHAR *realbuf;
|
||||
LPWSTR wstr;
|
||||
|
||||
i = proc->ParamCount;
|
||||
|
@ -853,19 +853,19 @@ void ParamsOut(SystemProc *proc)
|
|||
switch (proc->Params[i].Type)
|
||||
{
|
||||
case PAT_VOID:
|
||||
lstrcpy(realbuf,"");
|
||||
lstrcpy(realbuf,_T(""));
|
||||
break;
|
||||
case PAT_INT:
|
||||
wsprintf(realbuf, "%d", *((int*) place));
|
||||
wsprintf(realbuf, _T("%d"), *((int*) place));
|
||||
break;
|
||||
case PAT_LONG:
|
||||
myitoa64(*((__int64*) place), realbuf);
|
||||
break;
|
||||
case PAT_STRING:
|
||||
{
|
||||
unsigned num = lstrlen(*((char**) place));
|
||||
unsigned num = lstrlen(*((TCHAR**) place));
|
||||
if (num >= g_stringsize) num = g_stringsize-1;
|
||||
lstrcpyn(realbuf,*((char**) place), num+1);
|
||||
lstrcpyn(realbuf,*((TCHAR**) place), num+1);
|
||||
realbuf[num] = 0;
|
||||
}
|
||||
break;
|
||||
|
@ -880,7 +880,7 @@ void ParamsOut(SystemProc *proc)
|
|||
WideCharToMultiByte(CP_ACP, 0, wstr, g_stringsize, realbuf, g_stringsize, NULL, NULL);
|
||||
break;
|
||||
case PAT_CALLBACK:
|
||||
wsprintf(realbuf, "%d", proc->Params[i].Value);
|
||||
wsprintf(realbuf, _T("%d"), proc->Params[i].Value);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -903,7 +903,7 @@ void ParamsOut(SystemProc *proc)
|
|||
|
||||
HANDLE CreateCallback(SystemProc *cbproc)
|
||||
{
|
||||
char *mem;
|
||||
TCHAR *mem;
|
||||
|
||||
if (cbproc->Proc == NULL)
|
||||
{
|
||||
|
@ -911,11 +911,11 @@ HANDLE CreateCallback(SystemProc *cbproc)
|
|||
cbproc->CallbackIndex = ++(CallbackIndex);
|
||||
cbproc->Options |= POPT_PERMANENT;
|
||||
|
||||
mem = (char *) (cbproc->Proc = VirtualAlloc(NULL, 10, MEM_COMMIT, PAGE_EXECUTE_READWRITE));
|
||||
*(mem++) = (char) 0xB8; // Mov eax, const
|
||||
mem = (TCHAR *) (cbproc->Proc = VirtualAlloc(NULL, 10, MEM_COMMIT, PAGE_EXECUTE_READWRITE));
|
||||
*(mem++) = (TCHAR) 0xB8; // Mov eax, const
|
||||
*((int *)mem) = (int) cbproc;
|
||||
mem += sizeof(int);
|
||||
*(mem++) = (char) 0xe9; // Jmp relative
|
||||
*(mem++) = (TCHAR) 0xe9; // Jmp relative
|
||||
*((int *)mem) = (int) RealCallBack;
|
||||
*((int *)mem) -= ((int) mem) + 4;
|
||||
}
|
||||
|
@ -928,9 +928,9 @@ void CallStruct(SystemProc *proc)
|
|||
{
|
||||
BOOL ssflag;
|
||||
int i, structsize = 0, size = 0;
|
||||
char *st, *ptr;
|
||||
TCHAR *st, *ptr;
|
||||
|
||||
SYSTEM_LOG_ADD("\t\tStruct...");
|
||||
SYSTEM_LOG_ADD(_T("\t\tStruct..."));
|
||||
|
||||
// Calculate the structure size
|
||||
for (i = 1; i <= proc->ParamCount; i++)
|
||||
|
@ -947,7 +947,7 @@ void CallStruct(SystemProc *proc)
|
|||
if (structsize == 0) structsize = (int) GlobalSize((HANDLE) proc->Proc);
|
||||
|
||||
// Pointer to current data
|
||||
st = (char*) proc->Proc;
|
||||
st = (TCHAR*) proc->Proc;
|
||||
|
||||
for (i = 1; i <= proc->ParamCount; i++)
|
||||
{
|
||||
|
@ -958,7 +958,7 @@ void CallStruct(SystemProc *proc)
|
|||
{
|
||||
// Normal
|
||||
size = proc->Params[i].Size*4;
|
||||
ptr = (char*) &(proc->Params[i].Value);
|
||||
ptr = (TCHAR*) &(proc->Params[i].Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -979,13 +979,13 @@ void CallStruct(SystemProc *proc)
|
|||
// clear unused value bits
|
||||
proc->Params[i].Value &= intmask[((size >= 0) && (size < 4))?(size):(0)];
|
||||
// pointer
|
||||
ptr = (char*) &(proc->Params[i].Value);
|
||||
ptr = (TCHAR*) &(proc->Params[i].Value);
|
||||
break;
|
||||
|
||||
case PAT_STRING:
|
||||
case PAT_GUID:
|
||||
case PAT_WSTRING:
|
||||
ptr = (char*) proc->Params[i].Value; break;
|
||||
ptr = (TCHAR*) proc->Params[i].Value; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1037,7 +1037,7 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
|||
LastError = 0;
|
||||
LastProc = NULL;
|
||||
CallbackIndex = 0;
|
||||
retexpr[0] = (char) 0xC2;
|
||||
retexpr[0] = (TCHAR) 0xC2;
|
||||
retexpr[2] = 0x00;
|
||||
}
|
||||
|
||||
|
@ -1158,7 +1158,7 @@ unsigned int Get_valueOffsetParam(void)
|
|||
}
|
||||
|
||||
/*
|
||||
Sets "CLONE" option
|
||||
Sets _T("CLONE") option
|
||||
*/
|
||||
void SetCloneOption(SystemProc *proc)
|
||||
{
|
||||
|
@ -1166,7 +1166,7 @@ void SetCloneOption(SystemProc *proc)
|
|||
}
|
||||
|
||||
/*
|
||||
Sets Result of procedure call to be "OK"
|
||||
Sets Result of procedure call to be _T("OK")
|
||||
*/
|
||||
void SetProcResultOk(SystemProc *proc)
|
||||
{
|
||||
|
@ -1174,7 +1174,7 @@ void SetProcResultOk(SystemProc *proc)
|
|||
}
|
||||
|
||||
/*
|
||||
Sets Result of procedure call to be "CALLBACK"
|
||||
Sets Result of procedure call to be _T("CALLBACK")
|
||||
*/
|
||||
void SetProcResultCallback(SystemProc *proc)
|
||||
{
|
||||
|
|
|
@ -73,8 +73,8 @@ struct tag_SystemProc
|
|||
{
|
||||
int ProcType;
|
||||
int ProcResult;
|
||||
char DllName[1024];
|
||||
char ProcName[1024];
|
||||
TCHAR DllName[1024];
|
||||
TCHAR ProcName[1024];
|
||||
HANDLE Dll;
|
||||
HANDLE Proc;
|
||||
int Options;
|
||||
|
|
|
@ -109,6 +109,7 @@
|
|||
; UINT_PTR SetTimer(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc);
|
||||
!define sysSetTimer "user32::SetTimer(i, i, i, k) i"
|
||||
|
||||
; DWORD GetLogicalDriveStrings(DWORD nBufferLength, LPTSTR LpBuffer);
|
||||
!define sysGetLogicalDriveStrings 'kernel32::GetLogicalDriveStringsA(i, i) i'
|
||||
|
||||
!define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l) i'
|
||||
|
|
|
@ -8,7 +8,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1
|
|||
BEGIN
|
||||
ICON IDI_ICON2,IDC_ULICON,0,0,22,20
|
||||
LTEXT "",IDC_INTROTEXT,25,0,241,23
|
||||
CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL |
|
||||
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
|
||||
WS_TABSTOP | 0x804,0,24,266,105
|
||||
END
|
||||
|
||||
|
@ -18,7 +18,7 @@ FONT 8, "MS Shell Dlg"
|
|||
BEGIN
|
||||
ICON IDI_ICON2,IDC_ULICON,0,0,22,20
|
||||
LTEXT "",IDC_INTROTEXT,25,0,241,23
|
||||
CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL |
|
||||
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
|
||||
WS_TABSTOP | 0x804,0,24,266,85
|
||||
CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTORADIOBUTTON |
|
||||
WS_TABSTOP,0,110,266,9
|
||||
|
@ -32,7 +32,7 @@ FONT 8, "MS Shell Dlg"
|
|||
BEGIN
|
||||
ICON IDI_ICON2,IDC_ULICON,0,0,22,20
|
||||
LTEXT "",IDC_INTROTEXT,25,0,241,23
|
||||
CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL |
|
||||
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
|
||||
WS_TABSTOP | 0x804,0,24,266,95
|
||||
CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTOCHECKBOX |
|
||||
WS_TABSTOP,0,120,266,9
|
||||
|
|
|
@ -7,7 +7,7 @@ STYLE DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CAPTION
|
|||
FONT 8, "MS Shell Dlg", 0, 0, 0x1
|
||||
BEGIN
|
||||
LTEXT "",1040,0,0,300,15,NOT WS_GROUP
|
||||
CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL |
|
||||
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
|
||||
WS_TABSTOP | 0x804,0,15,300,93
|
||||
LTEXT "",IDC_INTROTEXT,0,113,300,26,NOT WS_GROUP
|
||||
END
|
||||
|
@ -98,7 +98,7 @@ STYLE DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CAPTION
|
|||
FONT 8, "MS Shell Dlg", 0, 0, 0x1
|
||||
BEGIN
|
||||
LTEXT "",1040,0,0,300,15,NOT WS_GROUP
|
||||
CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL |
|
||||
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
|
||||
WS_TABSTOP | 0x804,0,15,300,73
|
||||
LTEXT "",IDC_INTROTEXT,0,93,300,26,NOT WS_GROUP
|
||||
CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTORADIOBUTTON |
|
||||
|
@ -112,7 +112,7 @@ STYLE DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CAPTION
|
|||
FONT 8, "MS Shell Dlg", 0, 0, 0x1
|
||||
BEGIN
|
||||
LTEXT "",1040,0,0,300,15,NOT WS_GROUP
|
||||
CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL |
|
||||
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
|
||||
WS_TABSTOP | 0x804,0,15,300,83
|
||||
LTEXT "",IDC_INTROTEXT,0,103,300,26,NOT WS_GROUP
|
||||
CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTOCHECKBOX |
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <windows.h>
|
||||
#include <richedit.h>
|
||||
|
||||
#ifndef IDC_STATIC
|
||||
#define IDC_STATIC (-1)
|
||||
|
|
|
@ -8,7 +8,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1
|
|||
BEGIN
|
||||
ICON 103,IDC_ULICON,0,0,20,20
|
||||
LTEXT "",IDC_INTROTEXT,25,0,241,23,NOT WS_GROUP
|
||||
CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL |
|
||||
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
|
||||
WS_TABSTOP | 0x804,0,24,266,47
|
||||
END
|
||||
|
||||
|
@ -91,7 +91,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1
|
|||
BEGIN
|
||||
ICON 103,IDC_ULICON,0,0,20,20
|
||||
LTEXT "",IDC_INTROTEXT,25,0,241,23,NOT WS_GROUP
|
||||
CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL |
|
||||
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
|
||||
WS_TABSTOP | 0x804,0,24,266,27
|
||||
CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTORADIOBUTTON |
|
||||
WS_TABSTOP,0,50,266,9
|
||||
|
@ -105,7 +105,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1
|
|||
BEGIN
|
||||
ICON 103,IDC_ULICON,0,0,20,20
|
||||
LTEXT "",IDC_INTROTEXT,25,0,241,23,NOT WS_GROUP
|
||||
CONTROL "",IDC_EDIT1,"RichEdit20A",WS_BORDER | WS_VSCROLL |
|
||||
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
|
||||
WS_TABSTOP | 0x804,0,24,266,37
|
||||
CONTROL "",IDC_LICENSEAGREE,"Button",BS_AUTOCHECKBOX |
|
||||
WS_TABSTOP,0,60,266,9
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
// ui.cpp : Defines the entry point for the application.
|
||||
//
|
||||
// Unicode support by Jim Park -- 08/10/2007
|
||||
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
#include "../ExDLL/nsis_tchar.h"
|
||||
#include "resource.h"
|
||||
|
||||
HINSTANCE g_hInstance;
|
||||
HWND m_curwnd;
|
||||
|
||||
char* windows[] = {
|
||||
TCHAR* windows[] = {
|
||||
MAKEINTRESOURCE(IDD_LICENSE),
|
||||
MAKEINTRESOURCE(IDD_SELCOM),
|
||||
MAKEINTRESOURCE(IDD_DIR),
|
||||
|
@ -34,11 +36,11 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
|
|||
static int i = -1;
|
||||
switch (uMsg) {
|
||||
case WM_INITDIALOG:
|
||||
SetWindowText(hwndDlg, "NSIS User Interface - Testing");
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDC_VERSTR), "NSIS version");
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDC_BACK), "< Back");
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDOK), "Next >");
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDCANCEL), "Cancel");
|
||||
SetWindowText(hwndDlg, _T("NSIS User Interface - Testing"));
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDC_VERSTR), _T("NSIS version"));
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDC_BACK), _T("< Back"));
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDOK), _T("Next >"));
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDCANCEL), _T("Cancel"));
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_BACK), SW_SHOW);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_CHILDRECT), SW_SHOW);
|
||||
SendMessage(hwndDlg, WM_COMMAND, MAKEWORD(IDOK, 0), 0);
|
||||
|
@ -53,7 +55,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
|
|||
i++;
|
||||
break;
|
||||
}
|
||||
if (i >= (int)sizeof(windows)/sizeof(char*)) {
|
||||
if (i >= (int)sizeof(windows)/sizeof(TCHAR*)) {
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
|
@ -78,14 +80,14 @@ BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInstance,
|
||||
int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
LPTSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
InitCommonControls();
|
||||
|
||||
LoadLibrary("RichEd32.dll");
|
||||
LoadLibrary(_T("RichEd32.dll"));
|
||||
|
||||
g_hInstance = GetModuleHandle(0);
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
// Unicode support by Jim Park -- 08/23/2007
|
||||
|
||||
#include <windows.h>
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
typedef BOOL (WINAPI*CHECKTOKENMEMBERSHIP)(HANDLE TokenHandle,PSID SidToCheck,PBOOL IsMember);
|
||||
CHECKTOKENMEMBERSHIP _CheckTokenMembership=NULL;
|
||||
|
||||
void __declspec(dllexport) GetName(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop)
|
||||
TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
EXDLL_INIT();
|
||||
|
||||
|
@ -12,35 +14,35 @@ void __declspec(dllexport) GetName(HWND hwndParent, int string_size,
|
|||
DWORD dwStringSize = g_stringsize;
|
||||
stack_t *th;
|
||||
if (!g_stacktop) return;
|
||||
th = (stack_t*) GlobalAlloc(GPTR, sizeof(stack_t) + g_stringsize);
|
||||
th = (stack_t*) GlobalAlloc(GPTR, sizeof(stack_t) + g_stringsize*sizeof(TCHAR));
|
||||
GetUserName(th->text, &dwStringSize);
|
||||
th->next = *g_stacktop;
|
||||
*g_stacktop = th;
|
||||
}
|
||||
}
|
||||
|
||||
char* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny)
|
||||
TCHAR* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny)
|
||||
{
|
||||
char *group = NULL;
|
||||
TCHAR *group = NULL;
|
||||
HANDLE hToken = NULL;
|
||||
struct group
|
||||
{
|
||||
DWORD auth_id;
|
||||
char *name;
|
||||
};
|
||||
struct group
|
||||
{
|
||||
DWORD auth_id;
|
||||
TCHAR *name;
|
||||
};
|
||||
|
||||
struct group groups[] =
|
||||
{
|
||||
{DOMAIN_ALIAS_RID_USERS, "User"},
|
||||
// every user belongs to the users group, hence users come before guests
|
||||
{DOMAIN_ALIAS_RID_GUESTS, "Guest"},
|
||||
{DOMAIN_ALIAS_RID_POWER_USERS, "Power"},
|
||||
{DOMAIN_ALIAS_RID_ADMINS, "Admin"}
|
||||
};
|
||||
struct group groups[] =
|
||||
{
|
||||
{DOMAIN_ALIAS_RID_USERS, _T("User")},
|
||||
// every user belongs to the users group, hence users come before guests
|
||||
{DOMAIN_ALIAS_RID_GUESTS, _T("Guest")},
|
||||
{DOMAIN_ALIAS_RID_POWER_USERS, _T("Power")},
|
||||
{DOMAIN_ALIAS_RID_ADMINS, _T("Admin")}
|
||||
};
|
||||
|
||||
if (GetVersion() & 0x80000000) // Not NT
|
||||
{
|
||||
return "Admin";
|
||||
return _T("Admin");
|
||||
}
|
||||
|
||||
// First we must open a handle to the access token for this thread.
|
||||
|
@ -58,7 +60,7 @@ char* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny)
|
|||
// GetUserName is in advapi32.dll so we can avoid Load/Freelibrary
|
||||
_CheckTokenMembership=
|
||||
(CHECKTOKENMEMBERSHIP) GetProcAddress(
|
||||
GetModuleHandle("ADVAPI32"), "CheckTokenMembership");
|
||||
GetModuleHandle(_T("ADVAPI32")), "CheckTokenMembership");
|
||||
|
||||
// Use "old school" membership check?
|
||||
if (!CheckTokenForGroupDeny || _CheckTokenMembership == NULL)
|
||||
|
@ -121,18 +123,18 @@ char* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny)
|
|||
return group;
|
||||
}
|
||||
|
||||
return "";
|
||||
return _T("");
|
||||
}
|
||||
|
||||
void __declspec(dllexport) GetAccountType(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop)
|
||||
TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
EXDLL_INIT();
|
||||
pushstring(GetAccountTypeHelper(TRUE));
|
||||
}
|
||||
|
||||
void __declspec(dllexport) GetOriginalAccountType(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop)
|
||||
TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
EXDLL_INIT();
|
||||
pushstring(GetAccountTypeHelper(FALSE));
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#include "Checksums.h"
|
||||
|
||||
|
@ -82,7 +84,8 @@ void streamMD5(bistream& data, md5_byte_t digest[16]) {
|
|||
md5_finish(&state, digest);
|
||||
}
|
||||
|
||||
TChecksum::TChecksum(std::string& fileName) : mode(MD5) {
|
||||
// Jim Park: string -> tstring.
|
||||
TChecksum::TChecksum(tstring& fileName) : mode(MD5) {
|
||||
bifstream data;
|
||||
data.open(fileName.c_str(), ios::binary | ios::in);
|
||||
data.seekg(0, ios::beg);
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#if !defined(Checksums_H)
|
||||
#define Checksums_H
|
||||
|
@ -29,6 +31,7 @@
|
|||
#include "md5.h"
|
||||
#include <string>
|
||||
#include "GlobalTypes.h"
|
||||
#include "tchar.h"
|
||||
|
||||
typedef uint32_t crc32_t;
|
||||
|
||||
|
@ -39,7 +42,7 @@
|
|||
enum { CRC32, MD5 } mode;
|
||||
|
||||
TChecksum() : mode(MD5) { }
|
||||
TChecksum(std::string& fileName);
|
||||
TChecksum(tstring& fileName);
|
||||
|
||||
void loadMD5(md5_byte_t newdigest[16]);
|
||||
void loadCRC32(crc32_t newcrc);
|
||||
|
|
|
@ -22,9 +22,12 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
|
||||
#include "ChunkedFile.h"
|
||||
#include "tchar.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -32,15 +35,15 @@ using namespace std;
|
|||
chunks(NULL) {
|
||||
|
||||
chunkCount = fSize / chunkSize;
|
||||
cout << "[ChunkedFile] Filesize of " << static_cast<unsigned int>(fSize) << " gives " << static_cast<unsigned int>(chunkCount) << " chunks.\n";
|
||||
tout << _T("[ChunkedFile] Filesize of ") << static_cast<unsigned int>(fSize) << _T(" gives ") << static_cast<unsigned int>(chunkCount) << _T(" chunks.\n");
|
||||
|
||||
cout << "[ChunkedFile] Memory to be used by those chunks: " << sizeof(FileChunk) * chunkCount << " bytes...";
|
||||
tout << _T("[ChunkedFile] Memory to be used by those chunks: ") << sizeof(FileChunk) * chunkCount << _T(" bytes...");
|
||||
if(chunkCount == 0) {
|
||||
chunks = NULL;
|
||||
return;
|
||||
}
|
||||
chunks = new FileChunk[chunkCount];
|
||||
cout << " allocated.\n";
|
||||
tout << _T(" allocated.\n");
|
||||
|
||||
unsigned char* data = new unsigned char[chunkSize];
|
||||
for(TFileOffset i = 0; i < chunkCount; i++) {
|
||||
|
@ -50,9 +53,9 @@ using namespace std;
|
|||
}
|
||||
delete[] data;
|
||||
|
||||
cout << "[ChunkedFile] Sorting chunks... ";
|
||||
tout << _T("[ChunkedFile] Sorting chunks... ");
|
||||
std::sort(chunks,chunks + chunkCount);
|
||||
cout << "done.\n";
|
||||
tout << _T("done.\n");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#if !defined(ChunkedFile_H)
|
||||
#define ChunkedFile_H
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#include "FileFormat1.h"
|
||||
#include "GlobalTypes.h"
|
||||
|
@ -126,7 +128,7 @@ namespace FileFormat1 {
|
|||
TFileOffset endOffset = in.tellg();
|
||||
if(sourceChecksum == *removeCRC) {
|
||||
if(existanceIsError) {
|
||||
throw "Source file with the exact same contents already exists in patch!\nUse /R option (replace) to replace it with this patch!";
|
||||
throw _T("Source file with the exact same contents already exists in patch!\nUse /R option (replace) to replace it with this patch!");
|
||||
}
|
||||
fileCount--;
|
||||
} else {
|
||||
|
@ -192,7 +194,7 @@ namespace FileFormat1 {
|
|||
// calculate area inbetween this block and the next
|
||||
TFileOffset notFoundStart = current->targetOffset+current->size;
|
||||
if(notFoundStart > next->targetOffset) {
|
||||
throw "makeBinaryPatch input problem: there was overlap";
|
||||
throw _T("makeBinaryPatch input problem: there was overlap");
|
||||
}
|
||||
TFileOffset notFoundSize = next->targetOffset - notFoundStart;
|
||||
if(notFoundSize > 0) {
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#if !defined(FileFormat1_H)
|
||||
#define FileFormat1_H
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
|
||||
#include "GlobalTypes.h"
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#if !defined(GlobalTypes_H)
|
||||
#define GlobalTypes_H
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
|
||||
#include "POSIXUtil.h"
|
||||
|
@ -54,13 +56,13 @@ namespace POSIX {
|
|||
|
||||
#ifdef __WIN32__
|
||||
/* do it the old way on Win32, because POSIX does not get timezone stuff right */
|
||||
ALT_FILETIME getFileTime(const char* sFileName) {
|
||||
ALT_FILETIME getFileTime(const TCHAR* sFileName) {
|
||||
FILETIME temp;
|
||||
GetSystemTimeAsFileTime(&temp);
|
||||
HANDLE h = CreateFile(sFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (h == INVALID_HANDLE_VALUE) {
|
||||
cerr << "Cannot read file time of " << sFileName << "\n";
|
||||
terr << _T("Cannot read file time of ") << sFileName << _T("\n");
|
||||
} else {
|
||||
GetFileTime(h, NULL, NULL, &temp);
|
||||
CloseHandle(h);
|
||||
|
@ -77,7 +79,7 @@ namespace POSIX {
|
|||
time_t currentTime = time(NULL);
|
||||
|
||||
if(stat(sFileName, &buf)) {
|
||||
cerr << "Cannot read file time of " << sFileName << "\n";
|
||||
terr << _T("Cannot read file time of ") << sFileName << _T("\n");
|
||||
} else {
|
||||
/* get the time from the file */
|
||||
currentTime = buf.st_mtime;
|
||||
|
@ -88,11 +90,11 @@ namespace POSIX {
|
|||
}
|
||||
#endif
|
||||
|
||||
uint32_t getFileSize(const char* sFileName) {
|
||||
uint32_t getFileSize(const TCHAR* sFileName) {
|
||||
std::ifstream f;
|
||||
f.open(sFileName, std::ios_base::binary | std::ios_base::in);
|
||||
if (!f.good() || f.eof() || !f.is_open()) {
|
||||
throw "File could not be read (getFileSize)";
|
||||
throw _T("File could not be read (getFileSize)");
|
||||
}
|
||||
f.seekg(0, std::ios_base::beg);
|
||||
std::ifstream::pos_type begin_pos = f.tellg();
|
||||
|
@ -101,29 +103,29 @@ namespace POSIX {
|
|||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
string getTempFile() {
|
||||
char buffer[MAX_PATH];
|
||||
if(GetTempFileName(".","vpatch",0,buffer) == 0) {
|
||||
cerr << "Cannot create temporary filename";
|
||||
tstring getTempFile() {
|
||||
TCHAR buffer[MAX_PATH];
|
||||
if(GetTempFileName(_T("."),_T("vpatch"),0,buffer) == 0) {
|
||||
terr << _T("Cannot create temporary filename");
|
||||
}
|
||||
return string(buffer);
|
||||
return tstring(buffer);
|
||||
}
|
||||
#else
|
||||
string getTempFile() {
|
||||
char t[] = "/tmp/genpatXXXXXX";
|
||||
tstring getTempFile() {
|
||||
TCHAR t[] = _T("/tmp/genpatXXXXXX");
|
||||
|
||||
mode_t old_umask = umask(0077);
|
||||
|
||||
int fd = mkstemp(t);
|
||||
if (fd == -1) {
|
||||
cerr << "Cannot create temporary filename";
|
||||
return "";
|
||||
terr << _T("Cannot create temporary filename");
|
||||
return _T("");
|
||||
}
|
||||
close(fd);
|
||||
|
||||
umask(old_umask);
|
||||
|
||||
return string(t);
|
||||
return tstring(t);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -22,11 +22,14 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#if !defined(POSIXUtil_H)
|
||||
#define POSIXUtil_H
|
||||
#include "GlobalTypes.h"
|
||||
#include <string>
|
||||
#include "tchar.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -36,9 +39,9 @@
|
|||
uint32_t dwHighDateTime;
|
||||
} ALT_FILETIME;
|
||||
|
||||
ALT_FILETIME getFileTime(const char* sFileName);
|
||||
uint32_t getFileSize(const char* sFileName);
|
||||
string getTempFile();
|
||||
ALT_FILETIME getFileTime(const TCHAR* sFileName);
|
||||
uint32_t getFileSize(const TCHAR* sFileName);
|
||||
tstring getTempFile();
|
||||
}
|
||||
|
||||
#endif // POSIXUtil_H
|
||||
|
|
|
@ -22,7 +22,10 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#include "tchar.h"
|
||||
#include "PatchGenerator.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -85,12 +88,12 @@ void PatchGenerator::execute(vector<SameBlock*>& sameBlocks) {
|
|||
}
|
||||
|
||||
// we need to update the memory cache of target
|
||||
cout << "[CacheReload] File position = " << static_cast<unsigned int>(targetCDataBaseOffset) << "\n";
|
||||
tout << _T("[CacheReload] File position = ") << static_cast<unsigned int>(targetCDataBaseOffset) << _T("\n");
|
||||
|
||||
target.seekg(targetCDataBaseOffset,ios::beg);
|
||||
target.read(reinterpret_cast<char*>(targetCData),targetCDataSize);
|
||||
}
|
||||
//cout << currentOffset << " ";
|
||||
//tout << currentOffset << _T(" ");
|
||||
|
||||
SameBlock* currentSameBlock = findBlock(sourceTree,currentOffset);
|
||||
|
||||
|
@ -108,9 +111,9 @@ void PatchGenerator::execute(vector<SameBlock*>& sameBlocks) {
|
|||
|
||||
// debug info
|
||||
if(beVerbose) {
|
||||
cout << "Block found: " << static_cast<unsigned int>(currentSameBlock->targetOffset)
|
||||
<< " " << static_cast<unsigned int>(currentSameBlock->size)
|
||||
<< " (source offset=" << static_cast<unsigned int>(currentSameBlock->sourceOffset) << ")\n";
|
||||
tout << _T("Block found: ") << static_cast<unsigned int>(currentSameBlock->targetOffset)
|
||||
<< _T(" ") << static_cast<unsigned int>(currentSameBlock->size)
|
||||
<< _T(" (source offset=") << static_cast<unsigned int>(currentSameBlock->sourceOffset) << _T(")\n");
|
||||
}
|
||||
|
||||
currentOffset = currentSameBlock->targetOffset + currentSameBlock->size;
|
||||
|
@ -172,8 +175,8 @@ SameBlock* PatchGenerator::findBlock(ChunkedFile* sourceTree,
|
|||
if(beVerbose) {
|
||||
if(maxMatches != 0) {
|
||||
if(matchCount == maxMatches) {
|
||||
cout << "[FindBlock] Abort due to >" << static_cast<unsigned int>(maxMatches)
|
||||
<< " matches; file position = " << static_cast<unsigned int>(targetFileStartOffset) << "\n";
|
||||
tout << _T("[FindBlock] Abort due to >") << static_cast<unsigned int>(maxMatches)
|
||||
<< _T(" matches; file position = ") << static_cast<unsigned int>(targetFileStartOffset) << _T("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#if !defined(PatchGenerator_H)
|
||||
#define PatchGenerator_H
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
(nothing changed.)
|
||||
*/
|
||||
|
||||
#include "adler32.h"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
//---------------------------------------------------------------------------
|
||||
// Adler32
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#if !defined(Adler32_H)
|
||||
#define Adler32_H
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma argsused
|
||||
|
@ -31,10 +33,12 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "tchar.h"
|
||||
|
||||
#ifdef __WIN32__
|
||||
#define OPT_CHAR '/'
|
||||
#define OPT_CHAR _T('/')
|
||||
#else
|
||||
#define OPT_CHAR '-'
|
||||
#define OPT_CHAR _T('-')
|
||||
#endif
|
||||
|
||||
#include "GlobalTypes.h"
|
||||
|
@ -46,14 +50,14 @@
|
|||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
int main( int argc, char * argv[] ) {
|
||||
cout << "GenPat v3.1\n";
|
||||
cout << "===========\n\n(c) 2001-2005 Van de Sande Productions\n";
|
||||
cout << "Website: http://www.tibed.net/vpatch\n\n";
|
||||
int _tmain( int argc, TCHAR * argv[] ) {
|
||||
tout << _T("GenPat v3.1\n");
|
||||
tout << _T("===========\n\n(c) 2001-2005 Van de Sande Productions\n");
|
||||
tout << _T("Website: http://www.tibed.net/vpatch\n\n");
|
||||
|
||||
string sourceFileName;
|
||||
string targetFileName;
|
||||
string patchFileName;
|
||||
tstring sourceFileName;
|
||||
tstring targetFileName;
|
||||
tstring patchFileName;
|
||||
|
||||
bool showHelp = true;
|
||||
|
||||
|
@ -65,30 +69,30 @@ int main( int argc, char * argv[] ) {
|
|||
int fileNameArgument = 0;
|
||||
if(argc > 1) {
|
||||
for(int i = 1; i < argc; i++) {
|
||||
string s(argv[i]);
|
||||
tstring s(argv[i]);
|
||||
if(s.size() > 0) {
|
||||
if(s[0] == OPT_CHAR) {
|
||||
if(s.size() > 1) {
|
||||
if((s[1] == 'v') || (s[1] == 'V')) {
|
||||
if((s[1] == _T('v')) || (s[1] == _T('V'))) {
|
||||
beVerbose = true;
|
||||
}
|
||||
if((s[1] == 'o') || (s[1] == 'O')) {
|
||||
if((s[1] == _T('o')) || (s[1] == _T('O'))) {
|
||||
beOptimal = true;
|
||||
}
|
||||
if((s[1] == 'r') || (s[1] == 'R')) {
|
||||
if((s[1] == _T('r')) || (s[1] == _T('R'))) {
|
||||
existanceIsError = false;
|
||||
}
|
||||
}
|
||||
if(s.size() > 2) {
|
||||
if((s[1] == 'b') || (s[1] == 'B')) {
|
||||
if(s[2] == '=') {
|
||||
istringstream ss(s.substr(3));
|
||||
if((s[1] == _T('b')) || (s[1] == _T('B'))) {
|
||||
if(s[2] == _T('=')) {
|
||||
tistringstream ss(s.substr(3));
|
||||
ss >> blockSize;
|
||||
}
|
||||
}
|
||||
if((s[1] == 'a') || (s[1] == 'A')) {
|
||||
if(s[2] == '=') {
|
||||
istringstream ss(s.substr(3));
|
||||
if((s[1] == _T('a')) || (s[1] == _T('A'))) {
|
||||
if(s[2] == _T('=')) {
|
||||
tistringstream ss(s.substr(3));
|
||||
ss >> maxMatches;
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +110,7 @@ int main( int argc, char * argv[] ) {
|
|||
showHelp = false;
|
||||
break;
|
||||
default:
|
||||
cerr << "WARNING: extra filename argument not used: " << s << "\n";
|
||||
terr << _T("WARNING: extra filename argument not used: ") << s << _T("\n");
|
||||
}
|
||||
fileNameArgument++;
|
||||
}
|
||||
|
@ -117,45 +121,45 @@ int main( int argc, char * argv[] ) {
|
|||
maxMatches = 0;
|
||||
}
|
||||
if(showHelp) {
|
||||
cout << "This program will take (sourcefile) as input and create a (patchfile).\n";
|
||||
cout << "With this patchfile, you can convert a (sourcefile) into (targetfile).\n\n";
|
||||
cout << "Command line info:\n";
|
||||
cout << " GENPAT (sourcefile) (targetfile) (patchfile)\n\n";
|
||||
tout << _T("This program will take (sourcefile) as input and create a (patchfile).\n");
|
||||
tout << _T("With this patchfile, you can convert a (sourcefile) into (targetfile).\n\n");
|
||||
tout << _T("Command line info:\n");
|
||||
tout << _T(" GENPAT (sourcefile) (targetfile) (patchfile)\n\n");
|
||||
|
||||
cout << "Command line option (optional):\n";
|
||||
cout << OPT_CHAR << "R Replace a patch with same contents as source silently if it\n already exists.\n";
|
||||
cout << OPT_CHAR << "B=64 Set blocksize (default=64), multiple of 2 is required.\n";
|
||||
cout << OPT_CHAR << "V More verbose information during patch creation.\n";
|
||||
cout << OPT_CHAR << "O Deactivate match limit of the " << OPT_CHAR << "A switch (sometimes smaller patches).\n";
|
||||
cout << OPT_CHAR << "A=500 Maximum number of block matches per block (improves performance).\n";
|
||||
cout << " Default is 500, larger is slower. Use " << OPT_CHAR << "V to see the cut-off aborts.\n\n";
|
||||
cout << "Note: filenames should never start with " << OPT_CHAR << " character!\n\n";
|
||||
cout << "Possible exit codes:\n";
|
||||
cout << " 0 Success\n";
|
||||
cout << " 1 Arguments missing\n";
|
||||
cout << " 2 Other error\n";
|
||||
cout << " 3 Source file already has a patch in specified patch file (=error)\n";
|
||||
tout << _T("Command line option (optional):\n");
|
||||
tout << OPT_CHAR << _T("R Replace a patch with same contents as source silently if it\n already exists.\n");
|
||||
tout << OPT_CHAR << _T("B=64 Set blocksize (default=64), multiple of 2 is required.\n");
|
||||
tout << OPT_CHAR << _T("V More verbose information during patch creation.\n");
|
||||
tout << OPT_CHAR << _T("O Deactivate match limit of the ") << OPT_CHAR << _T("A switch (sometimes smaller patches).\n");
|
||||
tout << OPT_CHAR << _T("A=500 Maximum number of block matches per block (improves performance).\n");
|
||||
tout << _T(" Default is 500, larger is slower. Use ") << OPT_CHAR << _T("V to see the cut-off aborts.\n\n");
|
||||
tout << _T("Note: filenames should never start with ") << OPT_CHAR << _T(" character!\n\n");
|
||||
tout << _T("Possible exit codes:\n");
|
||||
tout << _T(" 0 Success\n");
|
||||
tout << _T(" 1 Arguments missing\n");
|
||||
tout << _T(" 2 Other error\n");
|
||||
tout << _T(" 3 Source file already has a patch in specified patch file (=error)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << "[Source] " << sourceFileName.c_str() << "\n";
|
||||
cout << "[Target] " << targetFileName.c_str() << "\n[PatchFile] " << patchFileName.c_str() << "\n";
|
||||
tout << _T("[Source] ") << sourceFileName.c_str() << _T("\n");
|
||||
tout << _T("[Target] ") << targetFileName.c_str() << _T("\n[PatchFile] ") << patchFileName.c_str() << _T("\n");
|
||||
|
||||
// get the file sizes
|
||||
TFileOffset sourceSize = 0;
|
||||
try {
|
||||
sourceSize = POSIX::getFileSize(sourceFileName.c_str());
|
||||
}
|
||||
catch(char* s) {
|
||||
cerr << "Source file size reading failed: " << s << "\n";
|
||||
catch(TCHAR* s) {
|
||||
terr << _T("Source file size reading failed: ") << s << _T("\n");
|
||||
return 2;
|
||||
}
|
||||
TFileOffset targetSize;
|
||||
try {
|
||||
targetSize = POSIX::getFileSize(targetFileName.c_str());
|
||||
}
|
||||
catch(const char* s) {
|
||||
cerr << "Target file size reading failed: " << s << "\n";
|
||||
catch(const TCHAR* s) {
|
||||
terr << _T("Target file size reading failed: ") << s << _T("\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -165,8 +169,8 @@ int main( int argc, char * argv[] ) {
|
|||
TChecksum* targetCRC = new TChecksum(targetFileName);
|
||||
targetCRC->mode = TChecksum::MD5; // default
|
||||
|
||||
string tempFileName = POSIX::getTempFile();
|
||||
if (tempFileName == "")
|
||||
tstring tempFileName = POSIX::getTempFile();
|
||||
if (tempFileName == _T(""))
|
||||
return 2;
|
||||
|
||||
// open the files
|
||||
|
@ -183,8 +187,8 @@ int main( int argc, char * argv[] ) {
|
|||
TFileOffset previousPatchSize = 0;
|
||||
try {
|
||||
previousPatchSize = POSIX::getFileSize(patchFileName.c_str());
|
||||
} catch(const char* s) {
|
||||
cout << "Patch file does not yet exist: " << s << ", it will be created.\n";
|
||||
} catch(const TCHAR* s) {
|
||||
tout << _T("Patch file does not yet exist: ") << s << _T(", it will be created.\n");
|
||||
std::ofstream newfile;
|
||||
newfile.open(patchFileName.c_str(), std::ios_base::binary | std::ios_base::out);
|
||||
newfile.close();
|
||||
|
@ -195,8 +199,8 @@ int main( int argc, char * argv[] ) {
|
|||
try {
|
||||
// this will copy the contents of previousPatch to patch, but without sourceCRC
|
||||
fileCount = FileFormat1::removeExistingPatch(previousPatch,previousPatchSize,patch,sourceCRC,existanceIsError);
|
||||
} catch(const char* s) {
|
||||
cerr << "ERROR: " << s << "\n";
|
||||
} catch(const TCHAR* s) {
|
||||
terr << _T("ERROR: ") << s << _T("\n");
|
||||
patch.close();
|
||||
unlink(tempFileName.c_str());
|
||||
return 3;
|
||||
|
@ -204,9 +208,9 @@ int main( int argc, char * argv[] ) {
|
|||
|
||||
// set them to the same checksum mode
|
||||
targetCRC->mode = sourceCRC->mode;
|
||||
cout << "[Checksum] Kind of checksums used: ";
|
||||
if(targetCRC->mode == TChecksum::MD5) cout << "MD5\n";
|
||||
if(targetCRC->mode == TChecksum::CRC32) cout << "CRC32\n";
|
||||
tout << _T("[Checksum] Kind of checksums used: ");
|
||||
if(targetCRC->mode == TChecksum::MD5) tout << _T("MD5\n");
|
||||
if(targetCRC->mode == TChecksum::CRC32) tout << _T("CRC32\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -227,26 +231,26 @@ int main( int argc, char * argv[] ) {
|
|||
}
|
||||
if((blockSize >> 1) == orgBlockSize) blockSize = orgBlockSize;
|
||||
if(blockSize != orgBlockSize) {
|
||||
cout << "[BlockSizeFix] Your blocksize had to be fixed since it is not a multiple of 2\n";
|
||||
tout << _T("[BlockSizeFix] Your blocksize had to be fixed since it is not a multiple of 2\n");
|
||||
}
|
||||
if(blockSize < 16) {
|
||||
blockSize = 16;
|
||||
cout << "[BlockSizeFix] Your blocksize had to be fixed since it is smaller than 16\n";
|
||||
tout << _T("[BlockSizeFix] Your blocksize had to be fixed since it is smaller than 16\n");
|
||||
}
|
||||
|
||||
gen->blockSize = blockSize;
|
||||
cout << "[BlockSize] " << static_cast<unsigned int>(gen->blockSize) << " bytes\n";
|
||||
tout << _T("[BlockSize] ") << static_cast<unsigned int>(gen->blockSize) << _T(" bytes\n");
|
||||
|
||||
gen->maxMatches = maxMatches;
|
||||
if(gen->maxMatches == 0) {
|
||||
cout << "[FindBlockMatchLimit] Unlimited matches\n";
|
||||
tout << _T("[FindBlockMatchLimit] Unlimited matches\n");
|
||||
} else {
|
||||
cout << "[FindBlockMatchLimit] " << gen->maxMatches << " matches\n";
|
||||
tout << _T("[FindBlockMatchLimit] ") << gen->maxMatches << _T(" matches\n");
|
||||
}
|
||||
|
||||
gen->beVerbose = beVerbose;
|
||||
if(beVerbose) {
|
||||
cout << "[Debug] Verbose output during patch generation activated.\n";
|
||||
tout << _T("[Debug] Verbose output during patch generation activated.\n");
|
||||
}
|
||||
|
||||
// create sameBlock storage
|
||||
|
@ -279,20 +283,20 @@ int main( int argc, char * argv[] ) {
|
|||
std::ofstream clearF;
|
||||
clearF.open(tempFileName.c_str(), std::ios_base::binary | std::ios_base::out);
|
||||
}
|
||||
catch(string s) {
|
||||
cerr << "Error thrown: " << s.c_str();
|
||||
catch(tstring s) {
|
||||
terr << _T("Error thrown: ") << s.c_str();
|
||||
return 2;
|
||||
}
|
||||
catch(const char* s) {
|
||||
cerr << "Error thrown: " << s;
|
||||
catch(const TCHAR* s) {
|
||||
terr << _T("Error thrown: ") << s;
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
cerr << "There was a problem opening the files.\n";
|
||||
terr << _T("There was a problem opening the files.\n");
|
||||
return 2;
|
||||
}
|
||||
if(*sourceCRC == *targetCRC)
|
||||
cerr << "WARNING: source and target file have equal CRCs!";
|
||||
terr << _T("WARNING: source and target file have equal CRCs!");
|
||||
delete sourceCRC;
|
||||
delete targetCRC;
|
||||
unlink(tempFileName.c_str());
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
L. Peter Deutsch
|
||||
ghost@aladdin.com
|
||||
|
||||
Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
*/
|
||||
/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
|
||||
/* $Id: md5.c,v 1.1 2005/09/17 09:25:44 kichik Exp $ */
|
||||
/*
|
||||
Independent implementation of MD5 (RFC 1321).
|
||||
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
L. Peter Deutsch
|
||||
ghost@aladdin.com
|
||||
|
||||
Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
*/
|
||||
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
|
||||
/* $Id: md5.h,v 1.1 2005/09/17 09:25:44 kichik Exp $ */
|
||||
/*
|
||||
Independent implementation of MD5 (RFC 1321).
|
||||
|
||||
|
|
28
Contrib/VPatch/Source/GenPat/tchar.h
Normal file
28
Contrib/VPatch/Source/GenPat/tchar.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Added for Unicode support by Jim Park -- 08/29/2007
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef _UNICODE
|
||||
# define tout wcout
|
||||
# define terr wcerr
|
||||
# define __T(x) L ## x
|
||||
# define _T(x) __T(x)
|
||||
# define _tmain wmain
|
||||
# define _tunlink _wunlink
|
||||
|
||||
typedef std::wstring tstring;
|
||||
typedef std::wistringstream tistringstream;
|
||||
|
||||
typedef wchar_t TCHAR;
|
||||
#else
|
||||
# define tout cout
|
||||
# define terr cerr
|
||||
# define _T(x) x
|
||||
# define _tmain main
|
||||
# define _tunlink _unlink
|
||||
|
||||
typedef std::string tstring;
|
||||
typedef std::istringstream tistringstream;
|
||||
typedef char TCHAR;
|
||||
#endif
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#include "apply_patch.h"
|
||||
#include "checksum.h"
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#ifndef apply_patch_INCLUDED
|
||||
#define apply_patch_INCLUDED
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#include "checksum.h"
|
||||
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
// The functions return ANSI strings so we use PushStringA to push it on
|
||||
// to the return stack correctly.
|
||||
|
||||
#ifndef checksum_INCLUDED
|
||||
#define checksum_INCLUDED
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
L. Peter Deutsch
|
||||
ghost@aladdin.com
|
||||
|
||||
Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
*/
|
||||
/* $Id: md5.c,v 1.1 2005/09/17 09:25:44 kichik Exp $ */
|
||||
/* $Id: md5.c,v 1.2 2005/09/20 17:42:28 kichik Exp $ */
|
||||
/*
|
||||
Independent implementation of MD5 (RFC 1321).
|
||||
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
L. Peter Deutsch
|
||||
ghost@aladdin.com
|
||||
|
||||
Reviewed for Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
*/
|
||||
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
|
||||
/* $Id: md5.h,v 1.1 2005/09/17 09:25:44 kichik Exp $ */
|
||||
/*
|
||||
Independent implementation of MD5 (RFC 1321).
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Unicode support by Jim Park -- 08/29/2007
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
@ -36,15 +38,15 @@ HINSTANCE g_hInstance;
|
|||
HWND g_hwndParent;
|
||||
|
||||
void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop) {
|
||||
TCHAR *variables, stack_t **stacktop) {
|
||||
g_hwndParent=hwndParent;
|
||||
|
||||
EXDLL_INIT();
|
||||
|
||||
{
|
||||
char source[MAX_PATH];
|
||||
char dest[MAX_PATH];
|
||||
char exename[MAX_PATH];
|
||||
TCHAR source[MAX_PATH];
|
||||
TCHAR dest[MAX_PATH];
|
||||
TCHAR exename[MAX_PATH];
|
||||
HANDLE hPatch, hSource, hDest;
|
||||
int result;
|
||||
|
||||
|
@ -55,7 +57,7 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
|
|||
hPatch = CreateFile(exename, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (hPatch == INVALID_HANDLE_VALUE) {
|
||||
pushstring("Unable to open patch file");
|
||||
pushstring(_T("Unable to open patch file"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -63,7 +65,7 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
|
|||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (hSource == INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(hPatch);
|
||||
pushstring("Unable to open source file");
|
||||
pushstring(_T("Unable to open source file"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -72,7 +74,7 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
|
|||
if (hDest == INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(hPatch);
|
||||
CloseHandle(hSource);
|
||||
pushstring("Unable to open output file");
|
||||
pushstring(_T("Unable to open output file"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -84,16 +86,16 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
|
|||
|
||||
if ((result != PATCH_SUCCESS)) {
|
||||
if (result == PATCH_ERROR)
|
||||
pushstring("An error occured while patching");
|
||||
pushstring(_T("An error occured while patching"));
|
||||
else if (result == PATCH_CORRUPT)
|
||||
pushstring("Patch data is invalid or corrupt");
|
||||
pushstring(_T("Patch data is invalid or corrupt"));
|
||||
else if (result == PATCH_NOMATCH)
|
||||
pushstring("No suitable patches were found");
|
||||
pushstring(_T("No suitable patches were found"));
|
||||
else if (result == PATCH_UPTODATE)
|
||||
pushstring("OK, new version already installed");
|
||||
pushstring(_T("OK, new version already installed"));
|
||||
DeleteFile(dest);
|
||||
} else {
|
||||
pushstring("OK");
|
||||
pushstring(_T("OK"));
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -102,13 +104,13 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
|
|||
|
||||
#ifdef DLL_CHECKSUMS
|
||||
void __declspec(dllexport) GetFileCRC32(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop) {
|
||||
TCHAR *variables, stack_t **stacktop) {
|
||||
g_hwndParent=hwndParent;
|
||||
|
||||
EXDLL_INIT();
|
||||
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
TCHAR filename[MAX_PATH];
|
||||
char crc_string[9];
|
||||
HANDLE hFile;
|
||||
unsigned long crc;
|
||||
|
@ -119,17 +121,17 @@ void __declspec(dllexport) GetFileCRC32(HWND hwndParent, int string_size,
|
|||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
//pushstring("ERROR: Unable to open file for CRC32 calculation");
|
||||
pushstring("");
|
||||
pushstring(_T(""));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FileCRC(hFile, &crc)) {
|
||||
//pushstring("ERROR: Unable to calculate CRC32");
|
||||
pushstring("");
|
||||
pushstring(_T(""));
|
||||
} else {
|
||||
crc_string[8] = '\0';
|
||||
CRC32ToString(crc_string,crc);
|
||||
pushstring(crc_string);
|
||||
PushStringA(crc_string);
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
|
@ -137,13 +139,13 @@ void __declspec(dllexport) GetFileCRC32(HWND hwndParent, int string_size,
|
|||
}
|
||||
|
||||
void __declspec(dllexport) GetFileMD5(HWND hwndParent, int string_size,
|
||||
char *variables, stack_t **stacktop) {
|
||||
TCHAR *variables, stack_t **stacktop) {
|
||||
g_hwndParent=hwndParent;
|
||||
|
||||
EXDLL_INIT();
|
||||
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
TCHAR filename[MAX_PATH];
|
||||
char md5_string[33];
|
||||
HANDLE hFile;
|
||||
md5_byte_t digest[16];
|
||||
|
@ -154,17 +156,17 @@ void __declspec(dllexport) GetFileMD5(HWND hwndParent, int string_size,
|
|||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
//pushstring("ERROR: Unable to open file for MD5 calculation");
|
||||
pushstring("");
|
||||
pushstring(_T(""));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FileMD5(hFile, digest)) {
|
||||
//pushstring("ERROR: Unable to calculate MD5");
|
||||
pushstring("");
|
||||
pushstring(_T(""));
|
||||
} else {
|
||||
md5_string[32] = '\0';
|
||||
MD5ToString(md5_string,digest);
|
||||
pushstring(md5_string);
|
||||
PushStringA(md5_string);
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
// Unicode support by Jim Park -- 08/10/2007
|
||||
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
#include <nsis/nsis_tchar.h>
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
|
@ -12,26 +15,26 @@ int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
BROWSEINFO bi;
|
||||
|
||||
char result[MAX_PATH];
|
||||
char initial[MAX_PATH];
|
||||
char title[1024];
|
||||
TCHAR result[MAX_PATH];
|
||||
TCHAR initial[MAX_PATH];
|
||||
TCHAR title[1024];
|
||||
LPITEMIDLIST resultPIDL;
|
||||
|
||||
EXDLL_INIT();
|
||||
|
||||
if (popstringn(title, sizeof(initial)))
|
||||
if (popstringn(title, _countof(initial)))
|
||||
{
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (popstringn(initial, sizeof(title)))
|
||||
if (popstringn(initial, _countof(title)))
|
||||
{
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -64,7 +67,7 @@ void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size,
|
|||
resultPIDL = SHBrowseForFolder(&bi);
|
||||
if (!resultPIDL)
|
||||
{
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -74,21 +77,21 @@ void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size,
|
|||
}
|
||||
else
|
||||
{
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
}
|
||||
|
||||
CoTaskMemFree(resultPIDL);
|
||||
}
|
||||
|
||||
void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
OPENFILENAME ofn={0,}; // XXX WTF
|
||||
int save;
|
||||
char type[5];
|
||||
static char path[1024];
|
||||
static char filter[1024];
|
||||
static char currentDirectory[1024];
|
||||
static char initialDir[1024];
|
||||
TCHAR type[5];
|
||||
static TCHAR path[1024];
|
||||
static TCHAR filter[1024];
|
||||
static TCHAR currentDirectory[1024];
|
||||
static TCHAR initialDir[1024];
|
||||
DWORD gfa;
|
||||
|
||||
EXDLL_INIT();
|
||||
|
@ -105,7 +108,7 @@ void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, ch
|
|||
popstringn(path, sizeof(path));
|
||||
popstringn(filter, sizeof(filter));
|
||||
|
||||
save = !lstrcmpi(type, "save");
|
||||
save = !lstrcmpi(type, _T("save"));
|
||||
|
||||
// Check if the path given is a folder. If it is we initialize the
|
||||
// ofn.lpstrInitialDir parameter
|
||||
|
@ -114,21 +117,21 @@ void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, ch
|
|||
{
|
||||
lstrcpy(initialDir, path);
|
||||
ofn.lpstrInitialDir = initialDir;
|
||||
path[0] = '\0'; // disable initial file selection as path is actually a directory
|
||||
path[0] = _T('\0'); // disable initial file selection as path is actually a directory
|
||||
}
|
||||
|
||||
if (!filter[0])
|
||||
{
|
||||
lstrcpy(filter, "All Files|*.*");
|
||||
lstrcpy(filter, _T("All Files|*.*"));
|
||||
}
|
||||
|
||||
{
|
||||
// Convert the filter to the format required by Windows: NULL after each
|
||||
// item followed by a terminating NULL
|
||||
char *p = filter;
|
||||
TCHAR *p = filter;
|
||||
while (*p) // XXX take care for 1024
|
||||
{
|
||||
if (*p == '|')
|
||||
if (*p == _T('|'))
|
||||
{
|
||||
*p++ = 0;
|
||||
}
|
||||
|
@ -149,19 +152,19 @@ void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, ch
|
|||
}
|
||||
else if (CommDlgExtendedError() == FNERR_INVALIDFILENAME)
|
||||
{
|
||||
*path = '\0';
|
||||
*path = _T('\0');
|
||||
if ((save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn)))
|
||||
{
|
||||
pushstring(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
pushstring("");
|
||||
pushstring(_T(""));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pushstring("");
|
||||
pushstring(_T(""));
|
||||
}
|
||||
|
||||
// restore working dir
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Unicode support by Jim Park -- 08/24/2007
|
||||
|
||||
#ifndef __NS_DIALOGS__DEFS_H__
|
||||
#define __NS_DIALOGS__DEFS_H__
|
||||
|
||||
|
@ -43,7 +45,7 @@ struct nsControl
|
|||
{
|
||||
HWND window;
|
||||
enum nsControlType type;
|
||||
char userData[USERDATA_SIZE];
|
||||
TCHAR userData[USERDATA_SIZE];
|
||||
struct nsControlCallbacks callbacks;
|
||||
WNDPROC oldWndProc;
|
||||
};
|
||||
|
@ -64,6 +66,6 @@ struct nsDialog
|
|||
struct nsControl* controls;
|
||||
};
|
||||
|
||||
#define NSCONTROL_ID_PROP "NSIS: nsControl pointer property"
|
||||
#define NSCONTROL_ID_PROP _T("NSIS: nsControl pointer property")
|
||||
|
||||
#endif//__NS_DIALOGS__DEFS_H__
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Unicode support by Jim Park -- 08/24/2007
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
|
@ -8,12 +10,12 @@
|
|||
|
||||
extern struct nsDialog g_dialog;
|
||||
|
||||
static int NSDFUNC ConvertPlacement(char *str, int total, int height)
|
||||
static int NSDFUNC ConvertPlacement(TCHAR *str, int total, int height)
|
||||
{
|
||||
char unit = *CharPrev(str, str + lstrlen(str));
|
||||
TCHAR unit = *CharPrev(str, str + lstrlen(str));
|
||||
int x = myatoi(str);
|
||||
|
||||
if (unit == '%')
|
||||
if (unit == _T('%'))
|
||||
{
|
||||
if (x < 0)
|
||||
{
|
||||
|
@ -22,7 +24,7 @@ static int NSDFUNC ConvertPlacement(char *str, int total, int height)
|
|||
|
||||
return MulDiv(total, x, 100);
|
||||
}
|
||||
else if (unit == 'u')
|
||||
else if (unit == _T('u'))
|
||||
{
|
||||
RECT r;
|
||||
|
||||
|
@ -50,7 +52,7 @@ int NSDFUNC PopPlacement(int *x, int *y, int *width, int *height)
|
|||
RECT dialogRect;
|
||||
int dialogWidth;
|
||||
int dialogHeight;
|
||||
char buf[1024];
|
||||
TCHAR buf[1024];
|
||||
|
||||
GetClientRect(g_dialog.hwDialog, &dialogRect);
|
||||
dialogWidth = dialogRect.right;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Reviewed for Unicode support by Jim Park -- 08/24/2007
|
||||
|
||||
#ifndef __NS_DIALOGS__INPUT_H__
|
||||
#define __NS_DIALOGS__INPUT_H__
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Unicode support by Jim Park -- 08/10/2007
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
|
@ -99,34 +101,34 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
if (ctl->callbacks.onChange)
|
||||
{
|
||||
pushint((int) hwCtl);
|
||||
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0);
|
||||
}
|
||||
pushint((int) hwCtl);
|
||||
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0);
|
||||
}
|
||||
}
|
||||
else if (HIWORD(wParam) == LBN_SELCHANGE && ctl->type == NSCTL_LISTBOX)
|
||||
{
|
||||
if (ctl->callbacks.onChange)
|
||||
{
|
||||
pushint((int) hwCtl);
|
||||
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0);
|
||||
}
|
||||
pushint((int) hwCtl);
|
||||
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0);
|
||||
}
|
||||
}
|
||||
else if ((HIWORD(wParam) == CBN_EDITUPDATE || HIWORD(wParam) == CBN_SELCHANGE)
|
||||
&& ctl->type == NSCTL_COMBOBOX)
|
||||
{
|
||||
if (ctl->callbacks.onChange)
|
||||
{
|
||||
pushint((int) hwCtl);
|
||||
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0);
|
||||
}
|
||||
pushint((int) hwCtl);
|
||||
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0);
|
||||
}
|
||||
}
|
||||
else if (HIWORD(wParam) == STN_CLICKED && ctl->type == NSCTL_STATIC)
|
||||
{
|
||||
if (ctl->callbacks.onClick)
|
||||
{
|
||||
pushint((int) hwCtl);
|
||||
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onClick - 1, 0);
|
||||
}
|
||||
pushint((int) hwCtl);
|
||||
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onClick - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -154,7 +156,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
|
||||
RECT rc;
|
||||
char text[1024];
|
||||
TCHAR text[1024];
|
||||
|
||||
// http://blogs.msdn.com/oldnewthing/archive/2005/05/03/414317.aspx#414357
|
||||
// says we should call SystemParametersInfo(SPI_GETKEYBOARDCUES,...) to make
|
||||
|
@ -171,7 +173,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
rc = lpdis->rcItem;
|
||||
|
||||
// Get button's text
|
||||
text[0] = '\0';
|
||||
text[0] = _T('\0');
|
||||
GetWindowText(lpdis->hwndItem, text, 1024);
|
||||
|
||||
// Calculate needed size of the control
|
||||
|
@ -242,7 +244,7 @@ static UINT_PTR PluginCallback(enum NSPIM msg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void __declspec(dllexport) Create(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) Create(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
HWND hwPlacementRect;
|
||||
RECT rcPlacement;
|
||||
|
@ -262,7 +264,7 @@ void __declspec(dllexport) Create(HWND hwndParent, int string_size, char *variab
|
|||
|
||||
if (g_dialog.hwDialog == NULL)
|
||||
{
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -288,10 +290,10 @@ void __declspec(dllexport) Create(HWND hwndParent, int string_size, char *variab
|
|||
pushint((int) g_dialog.hwDialog);
|
||||
}
|
||||
|
||||
void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
char *className;
|
||||
char *text;
|
||||
TCHAR *className;
|
||||
TCHAR *text;
|
||||
|
||||
HWND hwItem;
|
||||
int x, y, width, height;
|
||||
|
@ -300,18 +302,18 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char
|
|||
|
||||
// get info from stack
|
||||
|
||||
className = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, g_stringsize * 2);
|
||||
className = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (g_stringsize * 2)*sizeof(TCHAR));
|
||||
text = &className[g_stringsize];
|
||||
|
||||
if (!className)
|
||||
{
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (popstringn(className, 0))
|
||||
{
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
HeapFree(GetProcessHeap(), 0, className);
|
||||
return;
|
||||
}
|
||||
|
@ -323,7 +325,7 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char
|
|||
|
||||
if (popstringn(text, 0))
|
||||
{
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
HeapFree(GetProcessHeap(), 0, className);
|
||||
return;
|
||||
}
|
||||
|
@ -338,21 +340,21 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char
|
|||
g_dialog.controls,
|
||||
g_dialog.controlCount * sizeof(struct nsControl));
|
||||
|
||||
if (!lstrcmpi(className, "BUTTON"))
|
||||
if (!lstrcmpi(className, _T("BUTTON")))
|
||||
g_dialog.controls[id].type = NSCTL_BUTTON;
|
||||
else if (!lstrcmpi(className, "EDIT"))
|
||||
else if (!lstrcmpi(className, _T("EDIT")))
|
||||
g_dialog.controls[id].type = NSCTL_EDIT;
|
||||
else if (!lstrcmpi(className, "COMBOBOX"))
|
||||
else if (!lstrcmpi(className, _T("COMBOBOX")))
|
||||
g_dialog.controls[id].type = NSCTL_COMBOBOX;
|
||||
else if (!lstrcmpi(className, "LISTBOX"))
|
||||
else if (!lstrcmpi(className, _T("LISTBOX")))
|
||||
g_dialog.controls[id].type = NSCTL_LISTBOX;
|
||||
else if (!lstrcmpi(className, "RichEdit"))
|
||||
else if (!lstrcmpi(className, _T("RichEdit")))
|
||||
g_dialog.controls[id].type = NSCTL_RICHEDIT;
|
||||
else if (!lstrcmpi(className, "RICHEDIT_CLASS"))
|
||||
else if (!lstrcmpi(className, _T("RICHEDIT_CLASS")))
|
||||
g_dialog.controls[id].type = NSCTL_RICHEDIT2;
|
||||
else if (!lstrcmpi(className, "STATIC"))
|
||||
else if (!lstrcmpi(className, _T("STATIC")))
|
||||
g_dialog.controls[id].type = NSCTL_STATIC;
|
||||
else if (!lstrcmpi(className, "LINK"))
|
||||
else if (!lstrcmpi(className, _T("LINK")))
|
||||
g_dialog.controls[id].type = NSCTL_LINK;
|
||||
else
|
||||
g_dialog.controls[id].type = NSCTL_UNKNOWN;
|
||||
|
@ -365,7 +367,7 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char
|
|||
|
||||
hwItem = CreateWindowEx(
|
||||
exStyle,
|
||||
lstrcmpi(className, "LINK") ? className : "BUTTON",
|
||||
lstrcmpi(className, _T("LINK")) ? className : _T("BUTTON"),
|
||||
text,
|
||||
style,
|
||||
x, y, width, height,
|
||||
|
@ -399,12 +401,12 @@ void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char
|
|||
}
|
||||
|
||||
// for backward compatibility (2.29 had CreateItem)
|
||||
void __declspec(dllexport) CreateItem(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) CreateItem(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
CreateControl(hwndParent, string_size, variables, stacktop, extra);
|
||||
}
|
||||
|
||||
void __declspec(dllexport) SetUserData(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) SetUserData(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
HWND hwCtl;
|
||||
struct nsControl* ctl;
|
||||
|
@ -431,7 +433,7 @@ void __declspec(dllexport) SetUserData(HWND hwndParent, int string_size, char *v
|
|||
popstringn(ctl->userData, USERDATA_SIZE);
|
||||
}
|
||||
|
||||
void __declspec(dllexport) GetUserData(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) GetUserData(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
HWND hwCtl;
|
||||
struct nsControl* ctl;
|
||||
|
@ -442,7 +444,7 @@ void __declspec(dllexport) GetUserData(HWND hwndParent, int string_size, char *v
|
|||
|
||||
if (!IsWindow(hwCtl))
|
||||
{
|
||||
pushstring("");
|
||||
pushstring(_T(""));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -452,7 +454,7 @@ void __declspec(dllexport) GetUserData(HWND hwndParent, int string_size, char *v
|
|||
|
||||
if (ctl == NULL)
|
||||
{
|
||||
pushstring("");
|
||||
pushstring(_T(""));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -467,7 +469,7 @@ void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
|
|||
g_pluginParms->ExecuteCodeSegment(idEvent - 1, 0);
|
||||
}
|
||||
|
||||
void __declspec(dllexport) CreateTimer(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) CreateTimer(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
UINT callback;
|
||||
UINT interval;
|
||||
|
@ -489,7 +491,7 @@ void __declspec(dllexport) CreateTimer(HWND hwndParent, int string_size, char *v
|
|||
TimerProc);
|
||||
}
|
||||
|
||||
void nsdKillTimer(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void nsdKillTimer(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
UINT id;
|
||||
|
||||
|
@ -546,27 +548,27 @@ void NSDFUNC SetDialogCallback(size_t callbackIdx)
|
|||
}
|
||||
|
||||
|
||||
void __declspec(dllexport) OnClick(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) OnClick(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
SetControlCallback(CTL_CALLBACK_IDX(onClick));
|
||||
}
|
||||
|
||||
void __declspec(dllexport) OnChange(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) OnChange(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
SetControlCallback(CTL_CALLBACK_IDX(onChange));
|
||||
}
|
||||
|
||||
void __declspec(dllexport) OnNotify(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) OnNotify(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
SetControlCallback(CTL_CALLBACK_IDX(onNotify));
|
||||
}
|
||||
|
||||
void __declspec(dllexport) OnBack(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) OnBack(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
SetDialogCallback(DLG_CALLBACK_IDX(onBack));
|
||||
}
|
||||
|
||||
void __declspec(dllexport) Show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) Show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
// tell NSIS to remove old inner dialog and pass handle of the new inner dialog
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
extern struct nsDialog g_dialog;
|
||||
|
||||
void __declspec(dllexport) SetRTL(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
void __declspec(dllexport) SetRTL(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
|
||||
{
|
||||
g_dialog.rtl = (BOOL) popint();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ freely, subject to the following restrictions:
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Unicode support by Jim Park -- 08/24/2007
|
||||
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
|
@ -35,11 +37,12 @@ HWND g_hwndParent;
|
|||
HWND g_hwndList;
|
||||
|
||||
void ExecScript(BOOL log);
|
||||
void LogMessage(const char *pStr, BOOL bOEM);
|
||||
char *my_strstr(char *a, char *b);
|
||||
unsigned int my_atoi(char *s);
|
||||
void LogMessage(const TCHAR *pStr, BOOL bOEM);
|
||||
TCHAR *my_strstr(TCHAR *a, TCHAR *b);
|
||||
unsigned int my_atoi(TCHAR *s);
|
||||
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);
|
||||
|
||||
void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||
void __declspec(dllexport) Exec(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) {
|
||||
g_hwndParent=hwndParent;
|
||||
EXDLL_INIT();
|
||||
{
|
||||
|
@ -47,7 +50,7 @@ void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variable
|
|||
}
|
||||
}
|
||||
|
||||
void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||
void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) {
|
||||
g_hwndParent=hwndParent;
|
||||
EXDLL_INIT();
|
||||
{
|
||||
|
@ -55,7 +58,7 @@ void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *var
|
|||
}
|
||||
}
|
||||
|
||||
void __declspec(dllexport) ExecToStack(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||
void __declspec(dllexport) ExecToStack(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) {
|
||||
g_hwndParent=hwndParent;
|
||||
EXDLL_INIT();
|
||||
{
|
||||
|
@ -69,7 +72,7 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#define TAB_REPLACE " "
|
||||
#define TAB_REPLACE _T(" ")
|
||||
#define TAB_REPLACE_SIZE (sizeof(TAB_REPLACE)-1)
|
||||
|
||||
// Turn a pair of chars into a word
|
||||
|
@ -88,7 +91,7 @@ BOOL IsWOW64() {
|
|||
LPFN_ISWOW64PROCESS fnIsWow64Process;
|
||||
|
||||
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
|
||||
GetModuleHandle("kernel32"), "IsWow64Process");
|
||||
GetModuleHandle(_T("kernel32")), "IsWow64Process");
|
||||
|
||||
if (fnIsWow64Process != NULL) {
|
||||
if (fnIsWow64Process(GetCurrentProcess(), &wow64)) {
|
||||
|
@ -100,27 +103,28 @@ BOOL IsWOW64() {
|
|||
}
|
||||
|
||||
void ExecScript(int log) {
|
||||
char szRet[128] = "";
|
||||
char meDLLPath[MAX_PATH];
|
||||
char *executor;
|
||||
char *g_exec;
|
||||
char *pExec;
|
||||
TCHAR szRet[128] = _T("");
|
||||
TCHAR meDLLPath[MAX_PATH];
|
||||
TCHAR *executor;
|
||||
TCHAR *g_exec;
|
||||
TCHAR *pExec;
|
||||
unsigned int g_to;
|
||||
BOOL bOEM;
|
||||
|
||||
if (!IsWOW64()) {
|
||||
char *p;
|
||||
TCHAR* p;
|
||||
int nComSpecSize;
|
||||
|
||||
nComSpecSize = GetModuleFileName(g_hInst, meDLLPath, MAX_PATH) + 2; // 2 chars for quotes
|
||||
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+nComSpecSize+2); // 1 for space, 1 for null
|
||||
g_exec = (TCHAR *)GlobalAlloc(GPTR, sizeof(TCHAR)*(g_stringsize+nComSpecSize+2)); // 1 for space, 1 for null
|
||||
p = meDLLPath + nComSpecSize - 2; // point p at null char of meDLLPath
|
||||
*g_exec = '"';
|
||||
*g_exec = _T('"');
|
||||
executor = g_exec + 1;
|
||||
|
||||
// Look for the last '\' in path.
|
||||
do
|
||||
{
|
||||
if (*p == '\\')
|
||||
if (*p == _T('\\'))
|
||||
break;
|
||||
p = CharPrev(meDLLPath, p);
|
||||
}
|
||||
|
@ -128,15 +132,15 @@ void ExecScript(int log) {
|
|||
if (p == meDLLPath)
|
||||
{
|
||||
// bad path
|
||||
pushstring("error");
|
||||
pushstring(_T("error"));
|
||||
GlobalFree(g_exec);
|
||||
return;
|
||||
}
|
||||
|
||||
*p = 0;
|
||||
GetTempFileName(meDLLPath, "ns", 0, executor);
|
||||
*p = '\\';
|
||||
if (CopyFile(meDLLPath, executor, FALSE))
|
||||
GetTempFileName(meDLLPath, _T("ns"), 0, executor); // executor = new temp file name in module path.
|
||||
*p = _T('\\');
|
||||
if (CopyFile(meDLLPath, executor, FALSE)) // copy current DLL to temp file in module path.
|
||||
{
|
||||
HANDLE hFile, hMapping;
|
||||
LPBYTE pMapView;
|
||||
|
@ -147,25 +151,27 @@ void ExecScript(int log) {
|
|||
if (pMapView)
|
||||
{
|
||||
pNTHeaders = (PIMAGE_NT_HEADERS)(pMapView + ((PIMAGE_DOS_HEADER)pMapView)->e_lfanew);
|
||||
// Turning the copied DLL into a stripped down executable.
|
||||
pNTHeaders->FileHeader.Characteristics = IMAGE_FILE_32BIT_MACHINE | IMAGE_FILE_LOCAL_SYMS_STRIPPED |
|
||||
IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE;
|
||||
// Windows character-mode user interface (CUI) subsystem.
|
||||
pNTHeaders->OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
|
||||
pNTHeaders->OptionalHeader.AddressOfEntryPoint = (DWORD)WinMain - (DWORD)g_hInst;
|
||||
pNTHeaders->OptionalHeader.AddressOfEntryPoint = (DWORD)_tWinMain - (DWORD)g_hInst;
|
||||
UnmapViewOfFile(pMapView);
|
||||
}
|
||||
CloseHandle(hMapping);
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
|
||||
lstrcat(g_exec, "\"");
|
||||
lstrcat(g_exec, _T("\""));
|
||||
|
||||
// add space
|
||||
pExec = g_exec + lstrlen(g_exec);
|
||||
*pExec = ' ';
|
||||
*pExec = _T(' ');
|
||||
pExec++;
|
||||
} else {
|
||||
executor = NULL;
|
||||
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1); // 1 for null
|
||||
g_exec = (TCHAR *)GlobalAlloc(GPTR, sizeof(TCHAR)*(g_stringsize+1)); // 1 for NULL
|
||||
pExec = g_exec;
|
||||
}
|
||||
|
||||
|
@ -173,18 +179,24 @@ void ExecScript(int log) {
|
|||
bOEM = FALSE; // default is no OEM->ANSI conversion
|
||||
|
||||
g_hwndList = NULL;
|
||||
if (g_hwndParent)
|
||||
g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,"#32770",NULL),NULL,"SysListView32",NULL);
|
||||
|
||||
// g_hwndParent = the caller, usually NSIS installer.
|
||||
if (g_hwndParent) // The window class name for dialog boxes is "#32770"
|
||||
g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,_T("#32770"),NULL),NULL,_T("SysListView32"),NULL);
|
||||
|
||||
// g_exec is the complete command to run: It has the copy of this DLL turned
|
||||
// into an executable right now.
|
||||
|
||||
params:
|
||||
// Get the command I need to run from the NSIS stack.
|
||||
popstring(pExec);
|
||||
if (my_strstr(pExec, "/TIMEOUT=") == pExec) {
|
||||
char *szTimeout = pExec + 9;
|
||||
if (my_strstr(pExec, _T("/TIMEOUT=")) == pExec) {
|
||||
TCHAR *szTimeout = pExec + 9;
|
||||
g_to = my_atoi(szTimeout);
|
||||
*pExec = 0;
|
||||
goto params;
|
||||
}
|
||||
if (!lstrcmpi(pExec, "/OEM")) {
|
||||
if (!lstrcmpi(pExec, _T("/OEM"))) {
|
||||
bOEM = TRUE;
|
||||
*pExec = 0;
|
||||
goto params;
|
||||
|
@ -192,12 +204,14 @@ params:
|
|||
|
||||
if (!pExec[0])
|
||||
{
|
||||
pushstring("error");
|
||||
*(pExec-2) = '\0'; // skip space and quote
|
||||
pushstring(_T("error"));
|
||||
*(pExec-2) = _T('\0'); // skip space and quote
|
||||
if (executor) DeleteFile(executor);
|
||||
GlobalFree(g_exec);
|
||||
return;
|
||||
}
|
||||
|
||||
// Got all the params off the stack.
|
||||
|
||||
{
|
||||
STARTUPINFO si={sizeof(si),};
|
||||
|
@ -211,20 +225,20 @@ params:
|
|||
DWORD dwExit = 0;
|
||||
DWORD dwWait = WAIT_TIMEOUT;
|
||||
DWORD dwLastOutput;
|
||||
static char szBuf[1024];
|
||||
static TCHAR szBuf[1024];
|
||||
HGLOBAL hUnusedBuf = NULL;
|
||||
char *szUnusedBuf = 0;
|
||||
TCHAR *szUnusedBuf = 0;
|
||||
|
||||
if (log) {
|
||||
hUnusedBuf = GlobalAlloc(GHND, log & 2 ? g_stringsize : sizeof(szBuf)*4);
|
||||
hUnusedBuf = GlobalAlloc(GHND, log & 2 ? (g_stringsize*sizeof(TCHAR)) : sizeof(szBuf)*4);
|
||||
if (!hUnusedBuf) {
|
||||
lstrcpy(szRet, "error");
|
||||
lstrcpy(szRet, _T("error"));
|
||||
goto done;
|
||||
}
|
||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||
szUnusedBuf = (TCHAR *)GlobalLock(hUnusedBuf);
|
||||
}
|
||||
|
||||
GetVersionEx(&osv);
|
||||
GetVersionEx(&osv); // Get OS info
|
||||
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
|
||||
SetSecurityDescriptorDacl(&sd,true,NULL,false);
|
||||
|
@ -234,11 +248,11 @@ params:
|
|||
sa.lpSecurityDescriptor = NULL;
|
||||
sa.bInheritHandle = true;
|
||||
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
|
||||
lstrcpy(szRet, "error");
|
||||
lstrcpy(szRet, _T("error"));
|
||||
goto done;
|
||||
}
|
||||
if (!CreatePipe(&read_stdin,&newstdin,&sa,0)) {
|
||||
lstrcpy(szRet, "error");
|
||||
lstrcpy(szRet, _T("error"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -249,12 +263,13 @@ params:
|
|||
si.hStdOutput = newstdout;
|
||||
si.hStdError = newstdout;
|
||||
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
||||
lstrcpy(szRet, "error");
|
||||
lstrcpy(szRet, _T("error"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
dwLastOutput = GetTickCount();
|
||||
|
||||
// Now I'm talking with an executable copy of myself.
|
||||
while (dwWait != WAIT_OBJECT_0 || dwRead) {
|
||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||
if (dwRead) {
|
||||
|
@ -262,16 +277,16 @@ params:
|
|||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||
szBuf[dwRead] = 0;
|
||||
if (log) {
|
||||
char *p, *p2;
|
||||
TCHAR *p, *p2;
|
||||
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
||||
if (GlobalSize(hUnusedBuf) < iReqLen && (iReqLen < g_stringsize || !(log & 2))) {
|
||||
GlobalUnlock(hUnusedBuf);
|
||||
hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND);
|
||||
if (!hUnusedBuf) {
|
||||
lstrcpy(szRet, "error");
|
||||
lstrcpy(szRet, _T("error"));
|
||||
break;
|
||||
}
|
||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||
szUnusedBuf = (TCHAR *)GlobalLock(hUnusedBuf);
|
||||
}
|
||||
p = szUnusedBuf; // get the old left overs
|
||||
if (iReqLen < g_stringsize || !(log & 2)) lstrcat(p, szBuf);
|
||||
|
@ -280,33 +295,33 @@ params:
|
|||
}
|
||||
|
||||
if (!(log & 2)) {
|
||||
while ((p = my_strstr(p, "\t"))) {
|
||||
while ((p = my_strstr(p, _T("\t")))) {
|
||||
if ((int)(p - szUnusedBuf) > (int)(GlobalSize(hUnusedBuf) - TAB_REPLACE_SIZE - 1))
|
||||
{
|
||||
*p++ = ' ';
|
||||
*p++ = _T(' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
int len = lstrlen(p);
|
||||
char *c_out=(char*)p+TAB_REPLACE_SIZE+len;
|
||||
char *c_in=(char *)p+len;
|
||||
TCHAR *c_out=(TCHAR*)p+TAB_REPLACE_SIZE+len;
|
||||
TCHAR *c_in=(TCHAR *)p+len;
|
||||
while (len-- > 0) {
|
||||
*c_out--=*c_in--;
|
||||
}
|
||||
|
||||
lstrcpy(p, TAB_REPLACE);
|
||||
p += TAB_REPLACE_SIZE;
|
||||
*p = ' ';
|
||||
*p = _T(' ');
|
||||
}
|
||||
}
|
||||
|
||||
p = szUnusedBuf; // get the old left overs
|
||||
for (p2 = p; *p2;) {
|
||||
if (*p2 == '\r') {
|
||||
if (*p2 == _T('\r')) {
|
||||
*p2++ = 0;
|
||||
continue;
|
||||
}
|
||||
if (*p2 == '\n') {
|
||||
if (*p2 == _T('\n')) {
|
||||
*p2 = 0;
|
||||
while (!*p && p != p2) p++;
|
||||
LogMessage(p, bOEM);
|
||||
|
@ -318,7 +333,7 @@ params:
|
|||
|
||||
// If data was taken out from the unused buffer, move p contents to the start of szUnusedBuf
|
||||
if (p != szUnusedBuf) {
|
||||
char *p2 = szUnusedBuf;
|
||||
TCHAR *p2 = szUnusedBuf;
|
||||
while (*p) *p2++ = *p++;
|
||||
*p2 = 0;
|
||||
}
|
||||
|
@ -328,7 +343,7 @@ params:
|
|||
else {
|
||||
if (g_to && GetTickCount() > dwLastOutput+g_to) {
|
||||
TerminateProcess(pi.hProcess, -1);
|
||||
lstrcpy(szRet, "timeout");
|
||||
lstrcpy(szRet, _T("timeout"));
|
||||
}
|
||||
else Sleep(LOOPTIMEOUT);
|
||||
}
|
||||
|
@ -341,8 +356,8 @@ done:
|
|||
if (log & 2) pushstring(szUnusedBuf);
|
||||
if (log & 1 && *szUnusedBuf) LogMessage(szUnusedBuf, bOEM);
|
||||
if ( dwExit == STATUS_ILLEGAL_INSTRUCTION )
|
||||
lstrcpy(szRet, "error");
|
||||
if (!szRet[0]) wsprintf(szRet,"%d",dwExit);
|
||||
lstrcpy(szRet, _T("error"));
|
||||
if (!szRet[0]) wsprintf(szRet,_T("%d"),dwExit);
|
||||
pushstring(szRet);
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
|
@ -350,7 +365,7 @@ done:
|
|||
CloseHandle(read_stdout);
|
||||
CloseHandle(newstdin);
|
||||
CloseHandle(read_stdin);
|
||||
*(pExec-2) = '\0'; // skip space and quote
|
||||
*(pExec-2) = _T('\0'); // skip space and quote
|
||||
if (executor) DeleteFile(executor);
|
||||
GlobalFree(g_exec);
|
||||
if (log) {
|
||||
|
@ -361,27 +376,27 @@ done:
|
|||
}
|
||||
|
||||
// Tim Kosse's LogMessage
|
||||
void LogMessage(const char *pStr, BOOL bOEM) {
|
||||
void LogMessage(const TCHAR *pStr, BOOL bOEM) {
|
||||
LVITEM item={0};
|
||||
int nItemCount;
|
||||
if (!g_hwndList) return;
|
||||
//if (!lstrlen(pStr)) return;
|
||||
if (bOEM == TRUE) OemToCharBuff(pStr, (char *)pStr, lstrlen(pStr));
|
||||
if (bOEM == TRUE) OemToCharBuff(pStr, (TCHAR *)pStr, lstrlen(pStr));
|
||||
nItemCount=SendMessage(g_hwndList, LVM_GETITEMCOUNT, 0, 0);
|
||||
item.mask=LVIF_TEXT;
|
||||
item.pszText=(char *)pStr;
|
||||
item.pszText=(TCHAR *)pStr;
|
||||
item.cchTextMax=0;
|
||||
item.iItem=nItemCount;
|
||||
ListView_InsertItem(g_hwndList, &item);
|
||||
ListView_EnsureVisible(g_hwndList, item.iItem, 0);
|
||||
}
|
||||
|
||||
char *my_strstr(char *a, char *b)
|
||||
TCHAR *my_strstr(TCHAR *a, TCHAR *b)
|
||||
{
|
||||
int l = lstrlen(b);
|
||||
while (lstrlen(a) >= l)
|
||||
{
|
||||
char c = a[l];
|
||||
TCHAR c = a[l];
|
||||
a[l] = 0;
|
||||
if (!lstrcmpi(a, b))
|
||||
{
|
||||
|
@ -394,25 +409,25 @@ char *my_strstr(char *a, char *b)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
unsigned int my_atoi(char *s) {
|
||||
unsigned int my_atoi(TCHAR *s) {
|
||||
unsigned int v=0;
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) {
|
||||
if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X'))) {
|
||||
s+=2;
|
||||
for (;;) {
|
||||
int c=*s++;
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
else if (c >= 'a' && c <= 'f') c-='a'-10;
|
||||
else if (c >= 'A' && c <= 'F') c-='A'-10;
|
||||
if (c >= _T('0') && c <= _T('9')) c-=_T('0');
|
||||
else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10;
|
||||
else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10;
|
||||
else break;
|
||||
v<<=4;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
else if (*s == '0' && s[1] <= '7' && s[1] >= '0') {
|
||||
else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0')) {
|
||||
s++;
|
||||
for (;;) {
|
||||
int c=*s++;
|
||||
if (c >= '0' && c <= '7') c-='0';
|
||||
if (c >= _T('0') && c <= _T('7')) c-=_T('0');
|
||||
else break;
|
||||
v<<=3;
|
||||
v+=c;
|
||||
|
@ -420,7 +435,7 @@ unsigned int my_atoi(char *s) {
|
|||
}
|
||||
else {
|
||||
for (;;) {
|
||||
int c=*s++ - '0';
|
||||
int c=*s++ - _T('0');
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
|
@ -429,14 +444,14 @@ unsigned int my_atoi(char *s) {
|
|||
return (int)v;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
||||
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
DWORD Ret;
|
||||
STARTUPINFO si = {0};
|
||||
PROCESS_INFORMATION pi = {0};
|
||||
char command_line[1024];
|
||||
char seekchar=' ';
|
||||
char *cmdline;
|
||||
TCHAR command_line[1024];
|
||||
TCHAR seekchar=_T(' ');
|
||||
TCHAR *cmdline;
|
||||
|
||||
si.cb = sizeof(si);
|
||||
// Make child process use this app's standard files. Not needed because the handles
|
||||
|
@ -448,12 +463,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||
lstrcpyn(command_line, GetCommandLine(), 1024);
|
||||
|
||||
cmdline = command_line;
|
||||
if (*cmdline == '\"') seekchar = *cmdline++;
|
||||
if (*cmdline == _T('\"')) seekchar = *cmdline++;
|
||||
|
||||
while (*cmdline && *cmdline != seekchar) cmdline=CharNext(cmdline);
|
||||
cmdline=CharNext(cmdline);
|
||||
// skip any spaces before the arguments
|
||||
while (*cmdline && *cmdline == ' ') cmdline++;
|
||||
while (*cmdline && *cmdline == _T(' ')) cmdline++;
|
||||
|
||||
Ret = CreateProcess (NULL, cmdline,
|
||||
NULL, NULL,
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue