2002-08-02 10:01:35 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2002 Robert Rainwater
|
|
|
|
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include <windows.h>
|
|
|
|
#include "resource.h"
|
|
|
|
#include "makensisw.h"
|
|
|
|
#include "noclib.h"
|
|
|
|
|
|
|
|
void SetTitle(HWND hwnd,char *substr) {
|
|
|
|
char title[64];
|
|
|
|
if (substr==NULL) wsprintf(title,"MakeNSISW");
|
|
|
|
else wsprintf(title,"MakeNSISW - %s",substr);
|
|
|
|
SetWindowText(hwnd,title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetBranding(HWND hwnd) {
|
2002-09-04 00:49:51 +00:00
|
|
|
SetDlgItemText(hwnd, IDC_VERSION, NSISW_VERSION);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CopyToClipboard(HWND hwnd) {
|
|
|
|
int len=SendDlgItemMessage(hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0);
|
2002-09-06 21:38:30 +00:00
|
|
|
HGLOBAL mem = GlobalAlloc(GHND,len);
|
|
|
|
char *existing_text = (char *)GlobalLock(mem);
|
2002-08-02 10:01:35 +00:00
|
|
|
if (!hwnd||!OpenClipboard(hwnd)||!existing_text) return;
|
|
|
|
EmptyClipboard();
|
|
|
|
existing_text[0]=0;
|
|
|
|
GetDlgItemText(hwnd, IDC_LOGWIN, existing_text, len);
|
2002-09-06 21:38:30 +00:00
|
|
|
GlobalUnlock(mem);
|
2002-08-02 10:01:35 +00:00
|
|
|
SetClipboardData(CF_TEXT,existing_text);
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ClearLog(HWND hwnd) {
|
|
|
|
SetDlgItemText(hwnd, IDC_LOGWIN, "");
|
|
|
|
}
|
|
|
|
|
2002-09-06 20:19:52 +00:00
|
|
|
char *g_output_exe;
|
|
|
|
char *g_input_script;
|
2002-08-28 17:44:47 +00:00
|
|
|
extern BOOL g_warnings;
|
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
void LogMessage(HWND hwnd,const char *str) {
|
2002-09-07 12:57:30 +00:00
|
|
|
SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_SETSEL, -1, 0);
|
2002-08-31 13:27:36 +00:00
|
|
|
SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_REPLACESEL, 0, (WPARAM)str);
|
2002-09-04 01:59:38 +00:00
|
|
|
SendDlgItemMessage(hwnd, IDC_LOGWIN, WM_VSCROLL, SB_BOTTOM, 0);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ErrorMessage(HWND hwnd,const char *str) {
|
|
|
|
if (!str) return;
|
|
|
|
char buf[1028];
|
|
|
|
wsprintf(buf,"Error - %s\r\n",str);
|
|
|
|
LogMessage(hwnd,buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableItems(HWND hwnd) {
|
|
|
|
EnableWindow(GetDlgItem(hwnd,IDC_CLOSE),0);
|
|
|
|
EnableWindow(GetDlgItem(hwnd,IDC_TEST),0);
|
|
|
|
HMENU m = GetMenu(hwnd);
|
|
|
|
EnableMenuItem(m,IDM_SAVE,MF_GRAYED);
|
|
|
|
EnableMenuItem(m,IDM_TEST,MF_GRAYED);
|
|
|
|
EnableMenuItem(m,IDM_EXIT,MF_GRAYED);
|
|
|
|
EnableMenuItem(m,IDM_RECOMPILE,MF_GRAYED);
|
|
|
|
EnableMenuItem(m,IDM_COPY,MF_GRAYED);
|
|
|
|
EnableMenuItem(m,IDM_COPYSELECTED,MF_GRAYED);
|
|
|
|
EnableMenuItem(m,IDM_EDITSCRIPT,MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableItems(HWND hwnd) {
|
2002-09-06 20:19:52 +00:00
|
|
|
#define MSG(a) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,0,0)
|
|
|
|
#define MSG1(a,b) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,b,0)
|
|
|
|
#define MSG2(a,b,c) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,b,c)
|
|
|
|
|
2002-09-06 22:18:47 +00:00
|
|
|
if (g_input_script) {
|
|
|
|
GlobalFree(g_input_script);
|
|
|
|
g_input_script = 0;
|
|
|
|
}
|
|
|
|
if (g_output_exe) {
|
|
|
|
GlobalFree(g_output_exe);
|
|
|
|
g_output_exe = 0;
|
|
|
|
}
|
2002-09-06 20:19:52 +00:00
|
|
|
|
2002-09-06 20:59:50 +00:00
|
|
|
TEXTRANGE tr;
|
2002-09-06 20:19:52 +00:00
|
|
|
FINDTEXT ft;
|
2002-09-06 20:59:50 +00:00
|
|
|
|
|
|
|
// find input script
|
2002-09-06 20:19:52 +00:00
|
|
|
ft.chrg.cpMin = 0;
|
|
|
|
ft.chrg.cpMax = MSG(WM_GETTEXTLENGTH);
|
|
|
|
ft.lpstrText = "Processing script file: \"";
|
2002-09-06 20:59:50 +00:00
|
|
|
ft.chrg.cpMin = tr.chrg.cpMin = MSG2(EM_FINDTEXT, 0, (LPARAM)&ft) + lstrlen("Processing script file: \"");
|
|
|
|
ft.lpstrText = "\"";
|
|
|
|
tr.chrg.cpMax = MSG2(EM_FINDTEXT, 0, (LPARAM)&ft);
|
|
|
|
tr.lpstrText = g_input_script = (char *)GlobalAlloc(GPTR, tr.chrg.cpMax-tr.chrg.cpMin+1);
|
|
|
|
MSG2(EM_GETTEXTRANGE, 0, (WPARAM)&tr);
|
2002-09-06 20:19:52 +00:00
|
|
|
|
2002-09-06 20:59:50 +00:00
|
|
|
// find output exe
|
|
|
|
ft.chrg.cpMin = 0;
|
|
|
|
ft.chrg.cpMax = MSG(WM_GETTEXTLENGTH);
|
2002-09-06 20:19:52 +00:00
|
|
|
ft.lpstrText = "Output: \"";
|
2002-09-06 20:59:50 +00:00
|
|
|
ft.chrg.cpMin = tr.chrg.cpMin = MSG2(EM_FINDTEXT, 0, (LPARAM)&ft) + lstrlen("Output: \"");
|
|
|
|
ft.lpstrText = "\"";
|
|
|
|
tr.chrg.cpMax = MSG2(EM_FINDTEXT, 0, (LPARAM)&ft);
|
|
|
|
tr.lpstrText = g_output_exe = (char *)GlobalAlloc(GPTR, tr.chrg.cpMax-tr.chrg.cpMin+1);
|
|
|
|
MSG2(EM_GETTEXTRANGE, 0, (WPARAM)&tr);
|
2002-09-06 20:19:52 +00:00
|
|
|
|
|
|
|
g_warnings = FALSE;
|
|
|
|
|
|
|
|
ft.lpstrText = "warning:";
|
|
|
|
if (MSG2(EM_FINDTEXT, 0, (LPARAM)&ft) != -1) g_warnings++;
|
|
|
|
ft.lpstrText = "warnings:";
|
|
|
|
if (MSG2(EM_FINDTEXT, 0, (LPARAM)&ft) != -1) g_warnings++;
|
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
HMENU m = GetMenu(hwnd);
|
2002-09-08 13:43:23 +00:00
|
|
|
if (g_output_exe && !g_retcode) {
|
2002-08-31 13:27:36 +00:00
|
|
|
EnableWindow(GetDlgItem(hwnd,IDC_TEST),1);
|
|
|
|
EnableMenuItem(m,IDM_TEST,MF_ENABLED);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
EnableWindow(GetDlgItem(hwnd,IDC_CLOSE),1);
|
|
|
|
EnableMenuItem(m,IDM_SAVE,MF_ENABLED);
|
|
|
|
EnableMenuItem(m,IDM_EXIT,MF_ENABLED);
|
|
|
|
EnableMenuItem(m,IDM_RECOMPILE,MF_ENABLED);
|
|
|
|
EnableMenuItem(m,IDM_COPY,MF_ENABLED);
|
|
|
|
EnableMenuItem(m,IDM_COPYSELECTED,MF_ENABLED);
|
|
|
|
EnableMenuItem(m,IDM_EDITSCRIPT,MF_ENABLED);
|
|
|
|
}
|
|
|
|
|
2002-09-04 17:15:31 +00:00
|
|
|
static BOOL g_appended = FALSE;
|
2002-08-02 10:01:35 +00:00
|
|
|
void CompileNSISScript() {
|
2002-09-06 20:19:52 +00:00
|
|
|
static char *s;
|
2002-08-02 10:01:35 +00:00
|
|
|
ClearLog(g_hwnd);
|
|
|
|
SetTitle(g_hwnd,NULL);
|
|
|
|
SetBranding(g_hwnd);
|
|
|
|
if (lstrlen(g_script)==0) {
|
|
|
|
HMENU m = GetMenu(g_hwnd);
|
|
|
|
LogMessage(g_hwnd,USAGE);
|
|
|
|
EnableMenuItem(m,IDM_RECOMPILE,MF_GRAYED);
|
|
|
|
EnableMenuItem(m,IDM_EDITSCRIPT,MF_GRAYED);
|
|
|
|
EnableMenuItem(m,IDM_TEST,MF_GRAYED);
|
|
|
|
EnableWindow(GetDlgItem(g_hwnd,IDC_TEST),0);
|
|
|
|
return;
|
|
|
|
}
|
2002-09-04 17:15:31 +00:00
|
|
|
if (!g_appended) {
|
2002-09-06 20:19:52 +00:00
|
|
|
if (s) GlobalFree(s);
|
2002-09-07 12:04:18 +00:00
|
|
|
s = (char *)GlobalAlloc(GPTR, lstrlen(g_script)+lstrlen(EXENAME)+2);
|
2002-09-04 17:15:31 +00:00
|
|
|
wsprintf(s,"%s %s",EXENAME,g_script);
|
2002-09-06 20:19:52 +00:00
|
|
|
g_script = s;
|
2002-09-04 17:15:31 +00:00
|
|
|
g_appended = TRUE;
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
// Disable buttons during compile
|
|
|
|
DisableItems(g_hwnd);
|
|
|
|
DWORD id;
|
|
|
|
g_hThread=CreateThread(NULL,0,MakeNSISProc,0,0,&id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreWindowPos(HWND hwnd) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveWindowPos(HWND hwnd) {
|
|
|
|
HKEY hKey;
|
|
|
|
WINDOWPLACEMENT p;
|
|
|
|
p.length = sizeof(p);
|
|
|
|
GetWindowPlacement(hwnd, &p);
|
|
|
|
if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) {
|
2002-08-31 13:27:36 +00:00
|
|
|
RegSetValueEx(hKey,REGLOC,0,REG_BINARY,(unsigned char*)&p,sizeof(p));
|
2002-08-02 10:01:35 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|