2002-08-02 10:01:35 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2002 Robert Rainwater
|
2003-05-28 04:51:20 +00:00
|
|
|
Contributors: Justin Frankel, Fritz Elfert, Amir Szekely, and Sunil Kamath
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
2002-12-24 20:35:26 +00:00
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
2002-08-02 10:01:35 +00:00
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
2002-12-24 20:35:26 +00:00
|
|
|
misrepresented as being the original software.
|
2002-08-02 10:01:35 +00:00
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include <windows.h>
|
|
|
|
#include "resource.h"
|
|
|
|
#include "makensisw.h"
|
2003-05-28 04:51:20 +00:00
|
|
|
#include "toolbar.h"
|
2002-08-02 10:01:35 +00:00
|
|
|
#include "noclib.h"
|
|
|
|
|
2002-10-09 20:41:37 +00:00
|
|
|
NTOOLTIP g_tip;
|
2002-09-19 22:38:46 +00:00
|
|
|
LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
2003-08-12 17:57:14 +00:00
|
|
|
char g_mru_files[MRU_SIZE][MAX_PATH] = { NULL, NULL, NULL, NULL, NULL };
|
|
|
|
|
2002-10-09 20:41:37 +00:00
|
|
|
extern NSCRIPTDATA g_sdata;
|
2002-09-19 15:29:16 +00:00
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
void SetTitle(HWND hwnd,char *substr) {
|
2002-12-24 20:35:26 +00:00
|
|
|
char title[64];
|
|
|
|
if (substr==NULL) wsprintf(title,"MakeNSISW");
|
|
|
|
else wsprintf(title,"MakeNSISW - %s",substr);
|
|
|
|
SetWindowText(hwnd,title);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetBranding(HWND hwnd) {
|
2002-12-24 20:35:26 +00:00
|
|
|
SetDlgItemText(hwnd, IDC_VERSION, g_sdata.branding);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CopyToClipboard(HWND hwnd) {
|
2002-12-24 20:35:26 +00:00
|
|
|
if (!hwnd||!OpenClipboard(hwnd)) return;
|
|
|
|
int len=SendDlgItemMessage(hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0);
|
|
|
|
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE,len+1);
|
|
|
|
if (!mem) { CloseClipboard(); return; }
|
|
|
|
char *existing_text = (char *)GlobalLock(mem);
|
|
|
|
if (!existing_text) { CloseClipboard(); return; }
|
|
|
|
EmptyClipboard();
|
|
|
|
existing_text[0]=0;
|
|
|
|
GetDlgItemText(hwnd, IDC_LOGWIN, existing_text, len+1);
|
|
|
|
GlobalUnlock(mem);
|
|
|
|
SetClipboardData(CF_TEXT,mem);
|
|
|
|
CloseClipboard();
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearLog(HWND hwnd) {
|
2002-12-24 20:35:26 +00:00
|
|
|
SetDlgItemText(hwnd, IDC_LOGWIN, "");
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LogMessage(HWND hwnd,const char *str) {
|
2002-12-24 20:35:26 +00:00
|
|
|
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_SCROLLCARET, 0, 0);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ErrorMessage(HWND hwnd,const char *str) {
|
2002-12-24 20:35:26 +00:00
|
|
|
if (!str) return;
|
|
|
|
char buf[1028];
|
|
|
|
wsprintf(buf,"[Error] %s\r\n",str);
|
|
|
|
LogMessage(hwnd,buf);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisableItems(HWND hwnd) {
|
2003-01-17 14:11:23 +00:00
|
|
|
g_sdata.focused_hwnd = GetFocus();
|
|
|
|
|
2002-12-24 20:35:26 +00:00
|
|
|
EnableWindow(GetDlgItem(hwnd,IDC_CLOSE),0);
|
|
|
|
EnableWindow(GetDlgItem(hwnd,IDC_TEST),0);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_SAVE,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_TEST,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_EXIT,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_LOADSCRIPT,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_RECOMPILE,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_COPY,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_COPYSELECTED,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_EDITSCRIPT,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_CLEARLOG,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_BROWSESCR,MF_GRAYED);
|
2003-01-17 14:11:23 +00:00
|
|
|
|
2003-05-28 04:51:20 +00:00
|
|
|
EnableToolBarButton(IDM_SAVE,FALSE);
|
|
|
|
EnableToolBarButton(IDM_TEST,FALSE);
|
|
|
|
EnableToolBarButton(IDM_EXIT,FALSE);
|
|
|
|
EnableToolBarButton(IDM_LOADSCRIPT,FALSE);
|
|
|
|
EnableToolBarButton(IDM_RECOMPILE,FALSE);
|
|
|
|
EnableToolBarButton(IDM_COPY,FALSE);
|
|
|
|
EnableToolBarButton(IDM_EDITSCRIPT,FALSE);
|
|
|
|
EnableToolBarButton(IDM_CLEARLOG,FALSE);
|
|
|
|
EnableToolBarButton(IDM_BROWSESCR,FALSE);
|
|
|
|
|
2003-01-17 14:11:23 +00:00
|
|
|
if (!IsWindowEnabled(g_sdata.focused_hwnd))
|
|
|
|
SetFocus(GetDlgItem(hwnd,IDC_LOGWIN));
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EnableItems(HWND hwnd) {
|
2002-12-24 20:35:26 +00:00
|
|
|
if (g_sdata.output_exe && !g_sdata.retcode) {
|
2003-05-08 16:41:07 +00:00
|
|
|
EnableWindow(GetDlgItem(hwnd,IDC_TEST),1);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_TEST,MF_ENABLED);
|
2003-05-28 04:51:20 +00:00
|
|
|
EnableToolBarButton(IDM_TEST,TRUE);
|
2002-12-24 20:35:26 +00:00
|
|
|
}
|
|
|
|
EnableWindow(GetDlgItem(hwnd,IDC_CLOSE),1);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_SAVE,MF_ENABLED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_EXIT,MF_ENABLED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_LOADSCRIPT,MF_ENABLED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_RECOMPILE,MF_ENABLED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_COPY,MF_ENABLED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_COPYSELECTED,MF_ENABLED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_EDITSCRIPT,MF_ENABLED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_CLEARLOG,MF_ENABLED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_BROWSESCR,MF_ENABLED);
|
2003-05-28 04:51:20 +00:00
|
|
|
|
|
|
|
EnableToolBarButton(IDM_SAVE,TRUE);
|
|
|
|
EnableToolBarButton(IDM_EXIT,TRUE);
|
|
|
|
EnableToolBarButton(IDM_LOADSCRIPT,TRUE);
|
|
|
|
EnableToolBarButton(IDM_RECOMPILE,TRUE);
|
|
|
|
EnableToolBarButton(IDM_COPY,TRUE);
|
|
|
|
EnableToolBarButton(IDM_EDITSCRIPT,TRUE);
|
|
|
|
EnableToolBarButton(IDM_CLEARLOG,TRUE);
|
|
|
|
EnableToolBarButton(IDM_BROWSESCR,TRUE);
|
2003-01-17 14:11:23 +00:00
|
|
|
|
|
|
|
SetFocus(g_sdata.focused_hwnd);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompileNSISScript() {
|
2002-12-24 20:35:26 +00:00
|
|
|
static char *s;
|
|
|
|
DragAcceptFiles(g_sdata.hwnd,FALSE);
|
|
|
|
ClearLog(g_sdata.hwnd);
|
|
|
|
SetTitle(g_sdata.hwnd,NULL);
|
|
|
|
if (lstrlen(g_sdata.script)==0) {
|
|
|
|
LogMessage(g_sdata.hwnd,USAGE);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_RECOMPILE,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_EDITSCRIPT,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_TEST,MF_GRAYED);
|
|
|
|
EnableMenuItem(g_sdata.menu,IDM_BROWSESCR,MF_GRAYED);
|
2003-05-28 04:51:20 +00:00
|
|
|
EnableToolBarButton(IDM_RECOMPILE,FALSE);
|
|
|
|
EnableToolBarButton(IDM_EDITSCRIPT,FALSE);
|
|
|
|
EnableToolBarButton(IDM_TEST,FALSE);
|
|
|
|
EnableToolBarButton(IDM_BROWSESCR,FALSE);
|
|
|
|
|
2002-12-24 20:35:26 +00:00
|
|
|
EnableWindow(GetDlgItem(g_sdata.hwnd,IDC_TEST),0);
|
|
|
|
DragAcceptFiles(g_sdata.hwnd,TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!g_sdata.appended) {
|
|
|
|
if (s) GlobalFree(s);
|
2003-05-08 16:41:07 +00:00
|
|
|
char *defines = BuildDefines();
|
|
|
|
s = (char *)GlobalAlloc(GPTR, lstrlen(g_sdata.script)+lstrlen(defines)+sizeof(EXENAME)+sizeof(" /NOTIFYHWND ")+16);
|
|
|
|
wsprintf(s,"%s %s /NOTIFYHWND %d %s",EXENAME,defines,g_sdata.hwnd,g_sdata.script);
|
|
|
|
GlobalFree(defines);
|
2002-12-24 20:35:26 +00:00
|
|
|
if (g_sdata.script_alloced) GlobalFree(g_sdata.script);
|
|
|
|
g_sdata.script_alloced = true;
|
|
|
|
g_sdata.script = s;
|
|
|
|
g_sdata.appended = TRUE;
|
|
|
|
}
|
|
|
|
GlobalFree(g_sdata.input_script);
|
|
|
|
GlobalFree(g_sdata.output_exe);
|
|
|
|
g_sdata.input_script = 0;
|
|
|
|
g_sdata.output_exe = 0;
|
|
|
|
g_sdata.warnings = 0;
|
|
|
|
g_sdata.logLength = 0;
|
|
|
|
// Disable buttons during compile
|
|
|
|
DisableItems(g_sdata.hwnd);
|
|
|
|
DWORD id;
|
|
|
|
g_sdata.thread=CreateThread(NULL,0,MakeNSISProc,0,0,&id);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreWindowPos(HWND hwnd) {
|
2002-12-24 20:35:26 +00:00
|
|
|
HKEY hKey;
|
|
|
|
WINDOWPLACEMENT p;
|
|
|
|
if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) {
|
|
|
|
DWORD l = sizeof(p);
|
|
|
|
DWORD t;
|
|
|
|
if ((RegQueryValueEx(hKey,REGLOC,NULL,&t,(unsigned char*)&p,&l)==ERROR_SUCCESS)&&(t == REG_BINARY)&&(l==sizeof(p))) {
|
|
|
|
p.length = sizeof(p);
|
|
|
|
SetWindowPlacement(hwnd, &p);
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveWindowPos(HWND hwnd) {
|
2002-12-24 20:35:26 +00:00
|
|
|
HKEY hKey;
|
|
|
|
WINDOWPLACEMENT p;
|
|
|
|
p.length = sizeof(p);
|
|
|
|
GetWindowPlacement(hwnd, &p);
|
|
|
|
if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) {
|
|
|
|
RegSetValueEx(hKey,REGLOC,0,REG_BINARY,(unsigned char*)&p,sizeof(p));
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
2002-09-09 16:43:45 +00:00
|
|
|
|
2003-05-28 04:51:20 +00:00
|
|
|
void RestoreDefines()
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
HKEY hSubKey;
|
|
|
|
if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) {
|
|
|
|
int n = 0;
|
|
|
|
DWORD l = sizeof(n);
|
|
|
|
DWORD t;
|
|
|
|
if ((RegQueryValueEx(hKey,REGDEFCOUNT,NULL,&t,(unsigned char*)&n,&l)==ERROR_SUCCESS)&&(t == REG_DWORD)&&(l==sizeof(n))) {
|
|
|
|
if(n > 0) {
|
|
|
|
if (RegCreateKey(hKey,REGDEFSUBKEY,&hSubKey) == ERROR_SUCCESS) {
|
|
|
|
char buf[8];
|
|
|
|
g_sdata.defines = (char **)GlobalAlloc(GPTR, (n+1)*sizeof(char *));
|
|
|
|
for(int i=0; i<n; i++) {
|
|
|
|
wsprintf(buf,"%d",i);
|
|
|
|
l = 0;
|
|
|
|
if ((RegQueryValueEx(hSubKey,buf,NULL,&t,NULL,&l)==ERROR_SUCCESS)&&(t == REG_SZ)) {
|
|
|
|
l++;
|
|
|
|
g_sdata.defines[i] = (char *)GlobalAlloc(GPTR, l*sizeof(char));
|
|
|
|
RegQueryValueEx(hSubKey,buf,NULL,&t,(unsigned char*)g_sdata.defines[i],&l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_sdata.defines[n] = NULL;
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveDefines()
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
HKEY hSubKey;
|
|
|
|
int n = 0;
|
|
|
|
if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) {
|
|
|
|
RegDeleteKey(hKey,REGDEFSUBKEY);
|
|
|
|
if(g_sdata.defines) {
|
|
|
|
if (RegCreateKey(hKey,REGDEFSUBKEY,&hSubKey) == ERROR_SUCCESS) {
|
|
|
|
char buf[8];
|
|
|
|
while(g_sdata.defines[n]) {
|
|
|
|
wsprintf(buf,"%d",n);
|
|
|
|
RegSetValueEx(hSubKey,buf,0,REG_SZ,(CONST BYTE *)g_sdata.defines[n],lstrlen(g_sdata.defines[n]));
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegSetValueEx(hKey,REGDEFCOUNT,0,REG_DWORD,(CONST BYTE *)&n,sizeof(n));
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-09 16:43:45 +00:00
|
|
|
void ResetObjects() {
|
2003-05-28 04:51:20 +00:00
|
|
|
g_sdata.appended = FALSE;
|
|
|
|
g_sdata.warnings = FALSE;
|
|
|
|
g_sdata.retcode = -1;
|
|
|
|
g_sdata.thread = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetDefines() {
|
2003-05-08 16:41:07 +00:00
|
|
|
if(g_sdata.defines) {
|
|
|
|
int i=0;
|
|
|
|
while(g_sdata.defines[i]) {
|
|
|
|
GlobalFree(g_sdata.defines[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
GlobalFree(g_sdata.defines);
|
|
|
|
g_sdata.defines = NULL;
|
|
|
|
}
|
2002-09-19 15:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int InitBranding() {
|
2002-12-24 20:35:26 +00:00
|
|
|
char *s;
|
|
|
|
s = (char *)GlobalAlloc(GPTR,lstrlen(EXENAME)+10);
|
|
|
|
wsprintf(s,"%s /version",EXENAME);
|
|
|
|
{
|
|
|
|
STARTUPINFO si={sizeof(si),};
|
|
|
|
SECURITY_ATTRIBUTES sa={sizeof(sa),};
|
|
|
|
SECURITY_DESCRIPTOR sd={0,};
|
|
|
|
PROCESS_INFORMATION pi={0,};
|
|
|
|
HANDLE newstdout=0,read_stdout=0;
|
2002-09-19 15:29:16 +00:00
|
|
|
|
2002-12-24 20:35:26 +00:00
|
|
|
OSVERSIONINFO osv={sizeof(osv)};
|
|
|
|
GetVersionEx(&osv);
|
|
|
|
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
|
|
|
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
SetSecurityDescriptorDacl(&sd,true,NULL,false);
|
|
|
|
sa.lpSecurityDescriptor = &sd;
|
|
|
|
}
|
|
|
|
else sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = true;
|
|
|
|
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
GetStartupInfo(&si);
|
|
|
|
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
|
|
si.hStdOutput = newstdout;
|
|
|
|
si.hStdError = newstdout;
|
|
|
|
if (!CreateProcess(NULL,s,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
|
|
|
CloseHandle(newstdout);
|
|
|
|
CloseHandle(read_stdout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
char szBuf[1024];
|
|
|
|
DWORD dwRead = 1;
|
|
|
|
DWORD dwExit = !STILL_ACTIVE;
|
|
|
|
if (WaitForSingleObject(pi.hProcess,10000)!=WAIT_OBJECT_0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
lstrcpy(g_sdata.brandingv,szBuf);
|
|
|
|
GlobalFree(s);
|
|
|
|
}
|
|
|
|
return 1;
|
2002-09-19 15:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitTooltips(HWND h) {
|
2002-12-24 20:35:26 +00:00
|
|
|
if (h == NULL) return;
|
|
|
|
my_memset(&g_tip,0,sizeof(NTOOLTIP));
|
|
|
|
g_tip.tip_p = h;
|
|
|
|
INITCOMMONCONTROLSEX icx;
|
|
|
|
icx.dwSize = sizeof(icx);
|
|
|
|
icx.dwICC = ICC_BAR_CLASSES;
|
|
|
|
InitCommonControlsEx(&icx);
|
|
|
|
DWORD dwStyle = WS_POPUP | WS_BORDER | TTS_ALWAYSTIP;
|
|
|
|
DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
|
|
|
|
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,IDC_CLOSE),TEXT("Close MakeNSISW"));
|
|
|
|
AddTip(GetDlgItem(h,IDC_TEST),TEXT("Test the installer generated by MakeNSISW"));
|
2003-05-28 04:51:20 +00:00
|
|
|
AddToolBarTooltips();
|
2002-09-19 15:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyTooltips() {
|
2002-12-24 20:35:26 +00:00
|
|
|
UnhookWindowsHookEx(g_tip.hook);
|
2002-09-19 15:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddTip(HWND hWnd,LPSTR lpszToolTip) {
|
2002-12-24 20:35:26 +00:00
|
|
|
TOOLINFO ti;
|
|
|
|
ti.cbSize = sizeof(TOOLINFO);
|
|
|
|
ti.uFlags = TTF_IDISHWND;
|
|
|
|
ti.hwnd = g_tip.tip_p;
|
|
|
|
ti.uId = (UINT) hWnd;
|
|
|
|
ti.lpszText = lpszToolTip;
|
|
|
|
SendMessage(g_tip.tip, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
|
2002-09-19 15:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
2002-12-24 20:35:26 +00:00
|
|
|
if (nCode < 0) return CallNextHookEx(g_tip.hook, nCode, wParam, lParam);
|
|
|
|
switch (((MSG*)lParam)->message) {
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
if (IsChild(g_tip.tip_p,((MSG*)lParam)->hwnd))
|
2003-05-08 16:41:07 +00:00
|
|
|
SendMessage(g_tip.tip, TTM_RELAYEVENT, 0,lParam);
|
2002-12-24 20:35:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return CallNextHookEx(g_tip.hook, nCode, wParam, lParam);
|
2002-09-20 14:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShowDocs() {
|
2002-12-24 20:35:26 +00:00
|
|
|
char pathf[MAX_PATH],*path;
|
|
|
|
GetModuleFileName(NULL,pathf,sizeof(pathf));
|
|
|
|
path=my_strrchr(pathf,'\\');
|
|
|
|
if(path!=NULL) *path=0;
|
|
|
|
lstrcat(pathf,LOCALDOCS);
|
|
|
|
if ((int)ShellExecute(g_sdata.hwnd,"open",pathf,NULL,NULL,SW_SHOWNORMAL)<=32)
|
2003-05-08 16:41:07 +00:00
|
|
|
ShellExecute(g_sdata.hwnd,"open",DOCPATH,NULL,NULL,SW_SHOWNORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* BuildDefines()
|
|
|
|
{
|
|
|
|
char *buf = NULL;
|
|
|
|
|
|
|
|
if(g_sdata.defines) {
|
|
|
|
int i=0;
|
|
|
|
while(g_sdata.defines[i]) {
|
|
|
|
if(buf) {
|
|
|
|
char *buf3 = (char *)GlobalAlloc(GPTR,(lstrlen(buf)+lstrlen(g_sdata.defines[i])+6)*sizeof(char));
|
|
|
|
wsprintf(buf3,"%s \"/D%s\"",buf,g_sdata.defines[i]);
|
|
|
|
GlobalFree(buf);
|
|
|
|
buf = buf3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buf = (char *)GlobalAlloc(GPTR,(lstrlen(g_sdata.defines[i])+5)*sizeof(char));
|
|
|
|
wsprintf(buf,"\"/D%s\"",g_sdata.defines[i]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buf = (char *)GlobalAlloc(GPTR, sizeof(char));
|
|
|
|
lstrcpy(buf,"");
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
2003-08-12 17:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL PopMRUFile(char* fname)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0; i<MRU_SIZE; i++) {
|
|
|
|
if(!lstrcmpi(g_mru_files[i], fname)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(i < MRU_SIZE) {
|
|
|
|
int j;
|
|
|
|
for(j = i; j < MRU_SIZE-1; j++) {
|
|
|
|
lstrcpy(g_mru_files[j],g_mru_files[j+1]);
|
|
|
|
}
|
|
|
|
g_mru_files[MRU_SIZE-1][0]='\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PushMRUFile(char* fname)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char buf[MAX_PATH+1];
|
|
|
|
|
|
|
|
if(!fname || fname[0] == '\0') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fname[0] == '"') {
|
|
|
|
fname++;
|
|
|
|
}
|
|
|
|
lstrcpy(buf,fname);
|
|
|
|
if(buf[lstrlen(buf)-1] == '"') {
|
|
|
|
buf[lstrlen(buf)-1] = '\0';
|
|
|
|
}
|
|
|
|
PopMRUFile(buf);
|
|
|
|
for(i = MRU_SIZE - 2; i >= 0; i--) {
|
|
|
|
lstrcpy(g_mru_files[i+1], g_mru_files[i]);
|
|
|
|
}
|
|
|
|
lstrcpy(g_mru_files[0],buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BuildMRUMenu(HMENU hMenu)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
MENUITEMINFO mii;
|
|
|
|
|
|
|
|
for(i = 0; i < MRU_SIZE; i++) {
|
|
|
|
DeleteMenu(hMenu, IDM_MRU_FILE+i, MF_BYCOMMAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < MRU_SIZE; i++) {
|
|
|
|
if(g_mru_files[i][0]) {
|
|
|
|
my_memset(&mii, 0, sizeof(mii));
|
|
|
|
mii.cbSize = sizeof(mii);
|
|
|
|
mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
|
|
|
|
mii.wID = IDM_MRU_FILE+i;
|
|
|
|
mii.fType = MFT_STRING;
|
|
|
|
mii.dwTypeData = g_mru_files[i];
|
|
|
|
mii.cch = sizeof(g_mru_files[i]);
|
|
|
|
mii.fState = MFS_ENABLED;
|
|
|
|
InsertMenuItem(hMenu, IDM_MRU_FILE+i, TRUE, &mii);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadMRUFile(int position)
|
|
|
|
{
|
|
|
|
if (!g_sdata.thread && position >=0 && position < MRU_SIZE && g_mru_files[position][0]) {
|
|
|
|
g_sdata.script = (char *)GlobalAlloc(GPTR,lstrlen(g_mru_files[position])+3);
|
|
|
|
wsprintf(g_sdata.script,"\"%s\"",g_mru_files[position]);
|
|
|
|
PushMRUFile(g_sdata.script);
|
|
|
|
ResetObjects();
|
|
|
|
CompileNSISScript();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreMRUList()
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
HKEY hSubKey;
|
|
|
|
int n = 0;
|
|
|
|
int i;
|
|
|
|
if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) {
|
|
|
|
if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) {
|
|
|
|
char buf[8];
|
|
|
|
DWORD l;
|
|
|
|
for(int i=0; i<MRU_SIZE; i++) {
|
|
|
|
wsprintf(buf,"%d",i);
|
|
|
|
l = sizeof(g_mru_files[n]);
|
|
|
|
RegQueryValueEx(hSubKey,buf,NULL,NULL,(unsigned char*)g_mru_files[n],&l);
|
|
|
|
if(g_mru_files[n][0] != '\0') {
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
for(i = n; i < MRU_SIZE; i++) {
|
|
|
|
g_mru_files[i][0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveMRUList()
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
HKEY hSubKey;
|
|
|
|
int i = 0;
|
|
|
|
if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) {
|
|
|
|
if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) {
|
|
|
|
char buf[8];
|
|
|
|
for(i = 0; i < MRU_SIZE; i++) {
|
|
|
|
wsprintf(buf,"%d",i);
|
|
|
|
RegSetValueEx(hSubKey,buf,0,REG_SZ,(const unsigned char *)g_mru_files[i],lstrlen(g_mru_files[i]));
|
|
|
|
}
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|