| 1 |
/* |
| 2 |
Copyright (c) 2002 Robert Rainwater |
| 3 |
Contributors: Justin Frankel, Fritz Elfert, Amir Szekely, Sunil Kamath, Joost Verburg |
| 4 |
|
| 5 |
This software is provided 'as-is', without any express or implied |
| 6 |
warranty. In no event will the authors be held liable for any damages |
| 7 |
arising from the use of this software. |
| 8 |
|
| 9 |
Permission is granted to anyone to use this software for any purpose, |
| 10 |
including commercial applications, and to alter it and redistribute it |
| 11 |
freely, subject to the following restrictions: |
| 12 |
|
| 13 |
1. The origin of this software must not be misrepresented; you must not |
| 14 |
claim that you wrote the original software. If you use this software |
| 15 |
in a product, an acknowledgment in the product documentation would be |
| 16 |
appreciated but is not required. |
| 17 |
2. Altered source versions must be plainly marked as such, and must not be |
| 18 |
misrepresented as being the original software. |
| 19 |
3. This notice may not be removed or altered from any source distribution. |
| 20 |
|
| 21 |
Unicode support by Jim Park -- 08/18/2007 |
| 22 |
*/ |
| 23 |
#define MAKENSISW_CPP |
| 24 |
|
| 25 |
#include "makensisw.h" |
| 26 |
#include <windowsx.h> |
| 27 |
#include <shlwapi.h> |
| 28 |
#include <stdio.h> |
| 29 |
#include "resource.h" |
| 30 |
#include "toolbar.h" |
| 31 |
#include "update.h" |
| 32 |
|
| 33 |
namespace MakensisAPI { |
| 34 |
#ifdef _WIN64 |
| 35 |
const TCHAR* SigintEventNameFmt = _T("makensis win32 sigint event %Iu"); |
| 36 |
#else |
| 37 |
const TCHAR* SigintEventNameFmt = _T("makensis win32 sigint event %u"); |
| 38 |
#endif |
| 39 |
const TCHAR* SigintEventNameLegacy = _T("makensis win32 signint event"); |
| 40 |
} |
| 41 |
|
| 42 |
NSCRIPTDATA g_sdata; |
| 43 |
NRESIZEDATA g_resize; |
| 44 |
NFINDREPLACE g_find; |
| 45 |
TCHAR g_findbuf[128]; |
| 46 |
extern NTOOLBAR g_toolbar; |
| 47 |
void* g_ModalDlgData; |
| 48 |
BYTE g_MiniCommand = false; |
| 49 |
|
| 50 |
NSIS_ENTRYPOINT_SIMPLEGUI |
| 51 |
int WINAPI _tWinMain(HINSTANCE hInst,HINSTANCE hOldInst,LPTSTR CmdLineParams,int ShowCmd) { |
| 52 |
|
| 53 |
// We can be associated with .nsi files and when launched from the shell we inherit the current directory so |
| 54 |
// we need to prevent LoadLibrary from searching the current directory because it can contain untrusted DLLs! |
| 55 |
FARPROC SDDA = GetSysProcAddr("KERNEL32", "SetDllDirectoryA"); // WinXP.SP1+ |
| 56 |
if (SDDA) ((BOOL(WINAPI*)(LPCSTR))SDDA)(""); // Remove the current directory from the default DLL search order |
| 57 |
|
| 58 |
// Try to register the SysLink class |
| 59 |
enum { icc_link_class = 0x8000 }; // ComCtl32v6 |
| 60 |
#if (!defined(_MSC_VER) && !defined(_WIN64)) || (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_IA64))) // x86 or Itanium |
| 61 |
if (!InitCCEx(icc_link_class) && (sizeof(void*) > 4 || LOBYTE(GetVersion()) >= 5)) // Must check the version because older shell32 versions have a incompatible function at the same ordinal |
| 62 |
{ |
| 63 |
FARPROC lwrc = GetSysProcAddr("SHELL32", (LPCSTR) 258); // LinkWindow_RegisterClass |
| 64 |
if (lwrc) ((BOOL(WINAPI*)())lwrc)(); |
| 65 |
WNDCLASS wc; |
| 66 |
if (GetClassInfo(NULL, _T("Link Window"), &wc)) |
| 67 |
{ |
| 68 |
wc.lpszClassName = _T("SysLink"); |
| 69 |
RegisterClass(&wc); // Superclass the old link window class if SysLink is not available |
| 70 |
} |
| 71 |
} |
| 72 |
#endif |
| 73 |
|
| 74 |
memset(&g_sdata,0,sizeof(NSCRIPTDATA)); |
| 75 |
memset(&g_resize,0,sizeof(NRESIZEDATA)); |
| 76 |
memset(&g_find,0,sizeof(NFINDREPLACE)); |
| 77 |
g_sdata.hInstance = hInst; |
| 78 |
g_sdata.symbols = NULL; |
| 79 |
g_sdata.sigint_event_legacy = CreateEvent(NULL, FALSE, FALSE, MakensisAPI::SigintEventNameLegacy); |
| 80 |
g_sdata.verbosity = (unsigned char) ReadRegSettingDW(REGVERBOSITY, 4); |
| 81 |
if (g_sdata.verbosity > 4) g_sdata.verbosity = 4; |
| 82 |
g_sdata.log_zoom = 100; |
| 83 |
RestoreSymbols(); |
| 84 |
LoadSysLibrary("RichEd20"); |
| 85 |
|
| 86 |
if (!InitBranding()) { |
| 87 |
MessageBox(0,NSISERROR,ERRBOXTITLE,MB_ICONEXCLAMATION|MB_OK|MB_TASKMODAL); |
| 88 |
return 1; |
| 89 |
} |
| 90 |
ResetObjects(); |
| 91 |
HACCEL haccel = LoadAccelerators(g_sdata.hInstance, MAKEINTRESOURCE(IDK_ACCEL)); |
| 92 |
HWND hDialog = CreateDialog(g_sdata.hInstance,MAKEINTRESOURCE(DLG_MAIN),0,DialogProc); |
| 93 |
if (!hDialog && !g_MiniCommand) { |
| 94 |
MessageBox(0,DLGERROR,ERRBOXTITLE,MB_ICONEXCLAMATION|MB_OK|MB_TASKMODAL); |
| 95 |
return 1; |
| 96 |
} |
| 97 |
MSG msg; |
| 98 |
int status; |
| 99 |
while ((status=GetMessage(&msg,0,0,0))!=0) { |
| 100 |
if (status==-1) return -1; |
| 101 |
if (!IsDialogMessage(g_find.hwndFind, &msg)) { |
| 102 |
if (!TranslateAccelerator(hDialog,haccel,&msg)) { |
| 103 |
if (!IsDialogMessage(hDialog,&msg)) { |
| 104 |
TranslateMessage(&msg); |
| 105 |
DispatchMessage(&msg); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
MemSafeFree(g_sdata.script); |
| 111 |
if (g_sdata.script_cmd_args) GlobalFree(g_sdata.script_cmd_args); |
| 112 |
if (g_sdata.sigint_event) CloseHandle(g_sdata.sigint_event); |
| 113 |
if (g_sdata.sigint_event_legacy) CloseHandle(g_sdata.sigint_event_legacy); |
| 114 |
return (int) msg.wParam; |
| 115 |
} |
| 116 |
|
| 117 |
void SetScript(const TCHAR *script, bool clearArgs /*= true*/) |
| 118 |
{ |
| 119 |
MemSafeFree(g_sdata.script); |
| 120 |
|
| 121 |
if (clearArgs) |
| 122 |
{ |
| 123 |
if (g_sdata.script_cmd_args) |
| 124 |
{ |
| 125 |
GlobalFree(g_sdata.script_cmd_args); |
| 126 |
} |
| 127 |
|
| 128 |
// Pointing to a single char. Maybe _T('\0') |
| 129 |
g_sdata.script_cmd_args = GlobalAlloc(GHND, sizeof(TCHAR)); |
| 130 |
} |
| 131 |
|
| 132 |
g_sdata.script = (TCHAR*) MemAlloc((lstrlen(script) + 1)*sizeof(TCHAR)); |
| 133 |
lstrcpy(g_sdata.script, script); |
| 134 |
} |
| 135 |
|
| 136 |
static void AddScriptCmdArgs(const TCHAR *arg) |
| 137 |
{ |
| 138 |
g_sdata.script_cmd_args = GlobalReAlloc(g_sdata.script_cmd_args, |
| 139 |
GlobalSize(g_sdata.script_cmd_args) + (lstrlen(arg) + 2/* quotes */ + 1 /* space */)*sizeof(TCHAR), |
| 140 |
0); |
| 141 |
|
| 142 |
TCHAR *args = (TCHAR *) GlobalLock(g_sdata.script_cmd_args); |
| 143 |
|
| 144 |
lstrcat(args, _T(" \"")); |
| 145 |
lstrcat(args, arg); |
| 146 |
lstrcat(args, _T("\"")); |
| 147 |
|
| 148 |
GlobalUnlock(g_sdata.script_cmd_args); |
| 149 |
} |
| 150 |
|
| 151 |
enum { CMD_PICKCOMP = 0x0001, CMD_SPY = 0x0080, CMD_LOOKUP = 0x8000 }; |
| 152 |
static UINT ProcessCommandLine() |
| 153 |
{ |
| 154 |
LPCWSTR alwaysextraparam[] = { _T("INPUTCHARSET"), _T("ICS"), _T("OUTPUTCHARSET"), _T("OCS") }; |
| 155 |
TCHAR **argv; |
| 156 |
int i, j, retflags = 0, in_files = 0; |
| 157 |
int argc = SetArgv((TCHAR *)GetCommandLine(), &argv); |
| 158 |
if (argc > 1) { |
| 159 |
for (i = 1; i < argc; i++) |
| 160 |
{ |
| 161 |
if (in_files) goto openfile; |
| 162 |
else if (!lstrcmpi(argv[i], _T("--"))) ++in_files; |
| 163 |
else if (!lstrcmpi(argv[i], _T("/Spy"))) retflags |= CMD_SPY; |
| 164 |
else if (!lstrcmpi(argv[i], _T("/Lookup"))) retflags |= CMD_LOOKUP; |
| 165 |
else if (!StrCmpNI(argv[i], _T("/XSetCompressor "), COUNTOF("/XSetCompressor ") - !0)) |
| 166 |
{ |
| 167 |
TCHAR *p = argv[i] + lstrlen(_T("/XSetCompressor ")), cchSlashFinalSpace = COUNTOF("/FINAL ") - !0; |
| 168 |
if (!StrCmpNI(p,_T("/FINAL "), cchSlashFinalSpace)) p += cchSlashFinalSpace; |
| 169 |
while (*p == _T(' ')) p++; |
| 170 |
|
| 171 |
for (j = (int) COMPRESSOR_SCRIPT + 1; j < (int) COMPRESSOR_BEST; j++) |
| 172 |
{ |
| 173 |
if (!lstrcmpi(p, compressor_names[j])) |
| 174 |
{ |
| 175 |
SetCompressor((NCOMPRESSOR) j); |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
else if (!lstrcmpi(argv[i], _T("/ChooseCompressor"))) |
| 180 |
{ |
| 181 |
retflags |= CMD_PICKCOMP; |
| 182 |
} |
| 183 |
else if (argv[i][0] == _T('-') || argv[i][0] == _T('/')) |
| 184 |
{ |
| 185 |
AddScriptCmdArgs(argv[i]); |
| 186 |
for (SIZE_T k = 0; k < COUNTOF(alwaysextraparam); ++k) |
| 187 |
if (!lstrcmpi(argv[i] + 1, alwaysextraparam[k]) && ++i < argc) |
| 188 |
AddScriptCmdArgs(argv[i]); |
| 189 |
} |
| 190 |
else openfile: |
| 191 |
{ |
| 192 |
SetScript(argv[i], false); |
| 193 |
PushMRUFile(g_sdata.script); |
| 194 |
break; |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
MemSafeFree(argv); |
| 199 |
return retflags; |
| 200 |
} |
| 201 |
|
| 202 |
DWORD CALLBACK SaveFileStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) |
| 203 |
{ |
| 204 |
HANDLE hFile = (HANDLE) ((DWORD_PTR*)dwCookie)[0]; |
| 205 |
DWORD cbio; |
| 206 |
#ifdef UNICODE |
| 207 |
if (!((DWORD_PTR*)dwCookie)[1]) |
| 208 |
{ |
| 209 |
if (!WriteUTF16LEBOM(hFile)) return -1; |
| 210 |
((DWORD_PTR*)dwCookie)[1] = TRUE; |
| 211 |
} |
| 212 |
#endif |
| 213 |
BOOL wop = WriteFile(hFile, pbBuff, cb, &cbio, 0); |
| 214 |
return (*pcb = (LONG) cbio, !wop); |
| 215 |
} |
| 216 |
|
| 217 |
static void ToolBarSizeChanged(HWND hDlg) |
| 218 |
{ |
| 219 |
RECT r; |
| 220 |
HWND hEd = g_sdata.logwnd; |
| 221 |
GetWindowRect(g_toolbar.hwnd, &r); |
| 222 |
LONG tbh = RectH(r); |
| 223 |
GetWindowRect(hEd, &r); |
| 224 |
LONG oldh = RectH(r), margin = DlgUnitToPixelY(hDlg, 7), top = tbh + margin; |
| 225 |
POINT pt = { r.left, r.top }; |
| 226 |
ScreenToClient(hDlg, &pt); |
| 227 |
SetWindowPos(hEd, 0, pt.x, top, RectW(r), oldh + (pt.y - top), SWP_NOZORDER|SWP_NOACTIVATE); // Update IDC_LOGWIN position and size |
| 228 |
} |
| 229 |
|
| 230 |
static BOOL CALLBACK DialogResize(HWND hWnd, LPARAM param) |
| 231 |
{ |
| 232 |
RECT r, r2, &dlgrect = *(RECT*) param; |
| 233 |
GetWindowRect(hWnd, &r); |
| 234 |
ScreenToClient(g_sdata.hwnd, ((LPPOINT)&r)+0), ScreenToClient(g_sdata.hwnd, ((LPPOINT)&r)+1); |
| 235 |
switch (GetDlgCtrlID(hWnd)) |
| 236 |
{ |
| 237 |
case IDC_TOOLBAR: |
| 238 |
GetWindowRect(hWnd, &r2); |
| 239 |
SetWindowPos(hWnd, 0, 0, 0, RectW(r) + g_resize.dx, RectH(r2), SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); |
| 240 |
break; |
| 241 |
case IDC_LOGWIN: |
| 242 |
if (!g_resize.bottompanelsize) |
| 243 |
{ |
| 244 |
r2.top = 246, r2.bottom = 22 + 190; // Dialog units from the .rc file |
| 245 |
MapDialogRect(GetParent(hWnd), &r2); |
| 246 |
g_resize.bottompanelsize = r2.top - r2.bottom; |
| 247 |
} |
| 248 |
SetWindowPos(hWnd, 0, r.left, r.top, dlgrect.right - (r.left * 2), dlgrect.bottom - (r.top + g_resize.bottompanelsize), SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE); |
| 249 |
break; |
| 250 |
case IDC_TEST: |
| 251 |
case IDCANCEL: |
| 252 |
SetWindowPos(hWnd, 0, r.left + g_resize.dx, r.top + g_resize.dy, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE); |
| 253 |
break; |
| 254 |
default: |
| 255 |
SetWindowPos(hWnd, 0, r.left, r.top + g_resize.dy, RectW(r) + g_resize.dx, RectH(r), SWP_NOZORDER|SWP_NOACTIVATE); |
| 256 |
break; |
| 257 |
} |
| 258 |
RedrawWindow(hWnd,NULL,NULL,RDW_INVALIDATE); |
| 259 |
return TRUE; |
| 260 |
} |
| 261 |
|
| 262 |
INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 263 |
switch (msg) { |
| 264 |
case WM_INITDIALOG: |
| 265 |
{ |
| 266 |
g_sdata.hwnd=hwndDlg, g_sdata.logwnd = GetDlgItem(hwndDlg, IDC_LOGWIN); |
| 267 |
HICON hIcon = LoadIcon(g_sdata.hInstance,MAKEINTRESOURCE(IDI_ICON)); |
| 268 |
SetClassLongPtr(hwndDlg,GCLP_HICON,(LONG_PTR)hIcon); |
| 269 |
// Altered by Darren Owen (DrO) on 29/9/2003 |
| 270 |
// Added in receiving of mouse and key events from the richedit control |
| 271 |
SendMessage(g_sdata.logwnd,EM_SETEVENTMASK,(WPARAM)NULL,ENM_SELCHANGE|ENM_MOUSEEVENTS|ENM_KEYEVENTS); |
| 272 |
InitializeLogWindow(); |
| 273 |
g_sdata.menu = GetMenu(g_sdata.hwnd); |
| 274 |
g_sdata.fileSubmenu = FindSubMenu(g_sdata.menu, IDM_FILE); |
| 275 |
g_sdata.editSubmenu = FindSubMenu(g_sdata.menu, IDM_EDIT); |
| 276 |
g_sdata.toolsSubmenu = FindSubMenu(g_sdata.menu, IDM_TOOLS); |
| 277 |
SetMenuDefaultItem(FindSubMenu(g_sdata.menu, IDM_SCRIPT), IDM_RECOMPILE_TEST, MF_BYCOMMAND); |
| 278 |
RestoreMRUList(); |
| 279 |
CreateToolBar(); |
| 280 |
InitTooltips(g_sdata.hwnd); |
| 281 |
SetDlgItemText(g_sdata.hwnd,IDC_VERSION,g_sdata.branding); |
| 282 |
LPCTSTR fontname = _T("Courier New"), fontconsolas = _T("Consolas"); |
| 283 |
BYTE fontsize = 8, fontcharset = DEFAULT_CHARSET, suppwin4 = SupportsWNT4() || SupportsW9X(); |
| 284 |
if (FontExists(fontconsolas)) |
| 285 |
{ |
| 286 |
fontname = fontconsolas, ++fontsize; |
| 287 |
} |
| 288 |
else if (SupportsW2000() && GetACP() == 932) // According to older Inno, Courier New cannot display Japanese on < WinXP |
| 289 |
{ |
| 290 |
LPCWSTR msgothlocalutf = L"\xff2d\xff33 \xff30\x30b4\x30b7\x30c3\x30af"; |
| 291 |
const CHAR msgothlocal932[] = { -126, 'l', -126, 'r', ' ', -125, 'S', -125, 'V', -125, 'b', -125, 'N', '\0' }; |
| 292 |
fontcharset = SHIFTJIS_CHARSET, ++fontsize; |
| 293 |
fontname = _T("MS Gothic"); // Win2000 can handle this, downlevel cannot |
| 294 |
if (suppwin4 && !FontExists(fontname)) fontname = sizeof(TCHAR) > 1 ? (LPCTSTR) msgothlocalutf : (LPCTSTR) msgothlocal932; |
| 295 |
} |
| 296 |
HFONT hFont = CreateFontPt(hwndDlg,fontsize,FW_NORMAL,FIXED_PITCH|FF_DONTCARE,fontcharset,fontname); |
| 297 |
SendMessage(g_sdata.logwnd,WM_SETFONT,(WPARAM)hFont,0); |
| 298 |
g_sdata.compressor = COMPRESSOR_NONE_SELECTED; |
| 299 |
SetScript(_T("")); |
| 300 |
RestoreCompressor(); |
| 301 |
ToolBarSizeChanged(hwndDlg); |
| 302 |
|
| 303 |
UINT docmd = ProcessCommandLine(); |
| 304 |
if ((docmd & (CMD_SPY|CMD_LOOKUP))) |
| 305 |
{ |
| 306 |
INT_PTR r = ((docmd & CMD_LOOKUP) ? ShowLookupDialog : ShowWndSpy)(0); |
| 307 |
g_sdata.hwnd = NULL; // Don't save window pos |
| 308 |
g_MiniCommand++; |
| 309 |
return SendMessage(hwndDlg, WM_CLOSE, r, r); |
| 310 |
} |
| 311 |
|
| 312 |
RestoreWindowPos(g_sdata.hwnd); |
| 313 |
|
| 314 |
if(g_sdata.compressor == COMPRESSOR_NONE_SELECTED) { |
| 315 |
SetCompressor(g_sdata.default_compressor); |
| 316 |
} |
| 317 |
|
| 318 |
if(docmd & CMD_PICKCOMP) { |
| 319 |
if (DialogBox(g_sdata.hInstance,MAKEINTRESOURCE(DLG_COMPRESSOR),g_sdata.hwnd,API_cast<DLGPROC>(CompressorProc))) { |
| 320 |
EnableItems(g_sdata.hwnd); |
| 321 |
return TRUE; |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
CompileNSISScript(); |
| 326 |
return TRUE; |
| 327 |
} |
| 328 |
case WM_PAINT: |
| 329 |
{ |
| 330 |
PAINTSTRUCT ps; |
| 331 |
GetGripperPos(hwndDlg, g_resize.griprect); |
| 332 |
HDC hdc = BeginPaint(hwndDlg, &ps); |
| 333 |
DrawGripper(hwndDlg, hdc, g_resize.griprect); |
| 334 |
EndPaint(hwndDlg, &ps); |
| 335 |
return TRUE; |
| 336 |
} |
| 337 |
case WM_DESTROY: |
| 338 |
{ |
| 339 |
SaveSymbols(); |
| 340 |
SaveMRUList(); |
| 341 |
SaveWindowPos(g_sdata.hwnd); |
| 342 |
ReleaseLogWindow(); |
| 343 |
ImageList_Destroy(g_toolbar.imagelist); |
| 344 |
ImageList_Destroy(g_toolbar.imagelistd); |
| 345 |
ImageList_Destroy(g_toolbar.imagelisth); |
| 346 |
DestroyTooltips(); |
| 347 |
PostQuitMessage(0); |
| 348 |
return TRUE; |
| 349 |
} |
| 350 |
case WM_CLOSE: tryquitapp: |
| 351 |
{ |
| 352 |
if (!g_sdata.thread) { |
| 353 |
DestroyWindow(hwndDlg); |
| 354 |
PostQuitMessage((int) wParam); |
| 355 |
} |
| 356 |
return TRUE; |
| 357 |
} |
| 358 |
case WM_DROPFILES: { |
| 359 |
int num; |
| 360 |
TCHAR szTmp[MAX_PATH]; |
| 361 |
num = DragQueryFile((HDROP)wParam,(UINT)-1,NULL,0); |
| 362 |
if (num==1) { |
| 363 |
DragQueryFile((HDROP)wParam,0,szTmp,MAX_PATH); |
| 364 |
if (szTmp[0]) { |
| 365 |
SetScript(szTmp); |
| 366 |
PushMRUFile(g_sdata.script); |
| 367 |
ResetObjects(); |
| 368 |
CompileNSISScript(); |
| 369 |
} |
| 370 |
} else { |
| 371 |
MessageBox(hwndDlg,MULTIDROPERROR,ERRBOXTITLE,MB_OK|MB_ICONSTOP); |
| 372 |
} |
| 373 |
DragFinish((HDROP)wParam); |
| 374 |
break; |
| 375 |
} |
| 376 |
case WM_GETMINMAXINFO: |
| 377 |
{ |
| 378 |
((MINMAXINFO*)lParam)->ptMinTrackSize.x=MINWIDTH; |
| 379 |
((MINMAXINFO*)lParam)->ptMinTrackSize.y=MINHEIGHT; |
| 380 |
} |
| 381 |
case WM_ENTERSIZEMOVE: |
| 382 |
{ |
| 383 |
GetClientRect(g_sdata.hwnd, &g_resize.resizeRect); |
| 384 |
return TRUE; |
| 385 |
} |
| 386 |
case WM_SIZE: |
| 387 |
{ |
| 388 |
if (wParam == SIZE_MAXHIDE || wParam == SIZE_MAXSHOW) return TRUE; |
| 389 |
const LONG oldW = g_resize.resizeRect.right, oldH = g_resize.resizeRect.bottom; |
| 390 |
GetClientRect(hwndDlg, &g_resize.resizeRect); |
| 391 |
g_resize.dx = g_resize.resizeRect.right - oldW; |
| 392 |
g_resize.dy = g_resize.resizeRect.bottom - oldH; |
| 393 |
EnumChildWindows(g_sdata.hwnd, DialogResize, (LPARAM) &g_resize.resizeRect); |
| 394 |
return TRUE; |
| 395 |
} |
| 396 |
case WM_SIZING: |
| 397 |
{ |
| 398 |
InvalidateRect(hwndDlg, &g_resize.griprect, TRUE); |
| 399 |
GetGripperPos(hwndDlg, g_resize.griprect); |
| 400 |
return TRUE; |
| 401 |
} |
| 402 |
case WM_NCHITTEST: |
| 403 |
{ |
| 404 |
RECT r = g_resize.griprect; |
| 405 |
MapWindowPoints(hwndDlg, 0, (POINT*)&r, 2); |
| 406 |
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; |
| 407 |
if (PtInRect(&r, pt)) |
| 408 |
{ |
| 409 |
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, HTBOTTOMRIGHT); |
| 410 |
return TRUE; |
| 411 |
} |
| 412 |
return FALSE; |
| 413 |
} |
| 414 |
case WM_MAKENSIS_PROCESSCOMPLETE: |
| 415 |
{ |
| 416 |
if (g_sdata.thread) { |
| 417 |
CloseHandle(g_sdata.thread); |
| 418 |
g_sdata.thread=0; |
| 419 |
} |
| 420 |
if(g_sdata.compressor == COMPRESSOR_BEST) { |
| 421 |
if (g_sdata.retcode==0 && FileExists(g_sdata.output_exe)) { |
| 422 |
TCHAR temp_file_name[1024]; // BUGBUG: Hardcoded buffer size |
| 423 |
wsprintf(temp_file_name,_T("%s_makensisw_temp"),g_sdata.output_exe); |
| 424 |
if(!lstrcmpi(g_sdata.compressor_name,compressor_names[(int)COMPRESSOR_SCRIPT+1])) { |
| 425 |
SetCompressorStats(); |
| 426 |
CopyFile(g_sdata.output_exe,temp_file_name,false); |
| 427 |
g_sdata.best_compressor_name = g_sdata.compressor_name; |
| 428 |
g_sdata.compressor_name = compressor_names[(int)COMPRESSOR_SCRIPT+2]; |
| 429 |
ResetObjects(); |
| 430 |
|
| 431 |
CompileNSISScript(); |
| 432 |
return TRUE; |
| 433 |
} |
| 434 |
else { |
| 435 |
int this_compressor=0, i; |
| 436 |
HANDLE hPrev, hThis; |
| 437 |
DWORD prevSize=0, thisSize=0; |
| 438 |
|
| 439 |
for(i=(int)COMPRESSOR_SCRIPT+2; i<(int)COMPRESSOR_BEST; i++) { |
| 440 |
if(!lstrcmpi(g_sdata.compressor_name,compressor_names[i])) { |
| 441 |
this_compressor = i; |
| 442 |
break; |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
if(FileExists(temp_file_name)) { |
| 447 |
hPrev = CreateFile(temp_file_name,GENERIC_READ, FILE_SHARE_READ, |
| 448 |
NULL, OPEN_EXISTING, 0, NULL); |
| 449 |
if(hPrev != INVALID_HANDLE_VALUE) { |
| 450 |
prevSize = GetFileSize(hPrev, 0); |
| 451 |
CloseHandle(hPrev); |
| 452 |
|
| 453 |
if(prevSize != INVALID_FILE_SIZE) { |
| 454 |
hThis = CreateFile(g_sdata.output_exe,GENERIC_READ, FILE_SHARE_READ, |
| 455 |
NULL, OPEN_EXISTING, 0, NULL); |
| 456 |
if(hThis != INVALID_HANDLE_VALUE) { |
| 457 |
thisSize = GetFileSize(hThis, 0); |
| 458 |
CloseHandle(hThis); |
| 459 |
|
| 460 |
if(thisSize != INVALID_FILE_SIZE) { |
| 461 |
if(prevSize > thisSize) { |
| 462 |
CopyFile(g_sdata.output_exe,temp_file_name,false); |
| 463 |
SetCompressorStats(); |
| 464 |
g_sdata.best_compressor_name = g_sdata.compressor_name; |
| 465 |
} |
| 466 |
} |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
if(this_compressor == ((int)COMPRESSOR_BEST - 1)) { |
| 473 |
TCHAR buf[1024]; |
| 474 |
|
| 475 |
g_sdata.compressor_name = compressor_names[(int)COMPRESSOR_SCRIPT+1]; |
| 476 |
|
| 477 |
if(!lstrcmpi(g_sdata.best_compressor_name,compressor_names[this_compressor])) { |
| 478 |
wsprintf(buf,COMPRESSOR_MESSAGE,g_sdata.best_compressor_name,thisSize); |
| 479 |
LogMessage(g_sdata.hwnd,buf); |
| 480 |
} |
| 481 |
else { |
| 482 |
CopyFile(temp_file_name,g_sdata.output_exe,false); |
| 483 |
wsprintf(buf,RESTORED_COMPRESSOR_MESSAGE,g_sdata.best_compressor_name,prevSize); |
| 484 |
LogMessage(g_sdata.hwnd,buf); |
| 485 |
LogMessage(g_sdata.hwnd, g_sdata.compressor_stats); |
| 486 |
} |
| 487 |
DeleteFile(temp_file_name); |
| 488 |
g_sdata.compressor_stats[0] = _T('\0'); |
| 489 |
} |
| 490 |
else { |
| 491 |
g_sdata.compressor_name = compressor_names[this_compressor+1]; |
| 492 |
ResetObjects(); |
| 493 |
|
| 494 |
CompileNSISScript(); |
| 495 |
return TRUE; |
| 496 |
} |
| 497 |
} |
| 498 |
} |
| 499 |
} |
| 500 |
EnableItems(g_sdata.hwnd); |
| 501 |
if (!g_sdata.retcode) { |
| 502 |
if (g_sdata.warnings) { |
| 503 |
SetTitle(g_sdata.hwnd,_T("Finished with Warnings")); |
| 504 |
PlayAppSoundAsync(("BuildWarning"), MB_ICONWARNING); |
| 505 |
SetLogColor(LC_WARNING); |
| 506 |
} |
| 507 |
else { |
| 508 |
SetTitle(g_sdata.hwnd,_T("Finished Successfully")); |
| 509 |
PlayAppSoundAsync(("BuildComplete"), MB_ICONASTERISK); |
| 510 |
SetLogColor(LC_SUCCESS); |
| 511 |
} |
| 512 |
// Added by Darren Owen (DrO) on 1/10/2003 |
| 513 |
if(g_sdata.recompile_test) |
| 514 |
PostMessage(g_sdata.hwnd, WM_COMMAND, LOWORD(IDC_TEST), 0); |
| 515 |
} |
| 516 |
else { |
| 517 |
SetTitle(g_sdata.hwnd,_T("Compile Error: See Log for Details")); |
| 518 |
PlayAppSoundAsync(("BuildError"), MB_ICONEXCLAMATION); |
| 519 |
SetLogColor(LC_ERROR); |
| 520 |
} |
| 521 |
|
| 522 |
// Added by Darren Owen (DrO) on 1/10/2003 |
| 523 |
// ensures the recompile and run state is reset after use |
| 524 |
g_sdata.recompile_test = 0; |
| 525 |
DragAcceptFiles(g_sdata.hwnd,TRUE); |
| 526 |
return TRUE; |
| 527 |
} |
| 528 |
case MakensisAPI::QUERYHOST: { |
| 529 |
if (MakensisAPI::QH_OUTPUTCHARSET == wParam) { |
| 530 |
const UINT reqcp = 1200; // We want UTF-16LE |
| 531 |
return DlgRet(hwndDlg, (LONG_PTR)(1+reqcp)); |
| 532 |
} |
| 533 |
else if (MakensisAPI::QH_SUPPORTEDVERSION == wParam) |
| 534 |
return DlgRet(hwndDlg, 0x03006000); |
| 535 |
return FALSE; |
| 536 |
} |
| 537 |
case WM_NOTIFY: |
| 538 |
switch (((NMHDR*)lParam)->code ) { |
| 539 |
case EN_SELCHANGE: |
| 540 |
EnableMenuItem(g_sdata.menu, IDM_COPYSELECTED, RicheditHasSelection(g_sdata.logwnd) ? MF_ENABLED : MF_GRAYED); |
| 541 |
break; |
| 542 |
|
| 543 |
// Altered by Darren Owen (DrO) on 6/10/2003 |
| 544 |
// Allows the detection of the right-click menu when running on OSes below Windows 2000 |
| 545 |
// and will then simulate the effective WM_CONTEXTMENU message that would be received |
| 546 |
// note: removed the WM_CONTEXTMENU handling to prevent a duplicate menu appearing on |
| 547 |
// Windows 2000 and higher |
| 548 |
case EN_MSGFILTER: |
| 549 |
#define lpnmMsg ((MSGFILTER*)lParam) |
| 550 |
if(WM_RBUTTONUP == lpnmMsg->msg || (WM_KEYUP == lpnmMsg->msg && lpnmMsg->wParam == VK_APPS)) |
| 551 |
{ |
| 552 |
POINT pt; |
| 553 |
HWND edit = g_sdata.logwnd; |
| 554 |
RECT r; |
| 555 |
GetCursorPos(&pt); |
| 556 |
|
| 557 |
// Added and altered by Darren Owen (DrO) on 29/9/2003 |
| 558 |
// Will place the right-click menu in the top left corner of the window |
| 559 |
// if the application key is pressed and the mouse is not in the window |
| 560 |
// from here... |
| 561 |
ScreenToClient(edit, &pt); |
| 562 |
GetClientRect(edit, &r); |
| 563 |
if (!PtInRect(&r, pt)) pt.x = pt.y = 0; |
| 564 |
MapWindowPoints(edit, HWND_DESKTOP, &pt, 1); |
| 565 |
TrackPopupMenu(g_sdata.editSubmenu, GetMenuDropAlignment() | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, pt.x, pt.y, 0, g_sdata.hwnd, 0); |
| 566 |
} |
| 567 |
break; |
| 568 |
case TBN_DROPDOWN: |
| 569 |
{ |
| 570 |
LPNMTOOLBAR pToolBar = (LPNMTOOLBAR) lParam; |
| 571 |
if (pToolBar->hdr.hwndFrom == g_toolbar.hwnd && pToolBar->iItem == IDM_COMPRESSOR) { |
| 572 |
ShowCompressorToolbarDropdownMenu(*pToolBar); |
| 573 |
return TBDDRET_DEFAULT; |
| 574 |
} |
| 575 |
return TBDDRET_NODEFAULT; |
| 576 |
} |
| 577 |
} |
| 578 |
return TRUE; |
| 579 |
case WM_COPYDATA: |
| 580 |
{ |
| 581 |
using namespace MakensisAPI; |
| 582 |
COPYDATASTRUCT *cds = (COPYDATASTRUCT*) lParam, cdsret; |
| 583 |
switch (cds->dwData) { |
| 584 |
case MakensisAPI::NOTIFY_SCRIPT: |
| 585 |
MemSafeFree(g_sdata.input_script); |
| 586 |
if ((g_sdata.input_script = (TCHAR*) MemAlloc(cds->cbData * sizeof(TCHAR)))) |
| 587 |
lstrcpy(g_sdata.input_script, (TCHAR*) cds->lpData); |
| 588 |
EnableUICommand(IDM_BROWSESCR, !!g_sdata.input_script); |
| 589 |
break; |
| 590 |
case MakensisAPI::NOTIFY_WARNING: |
| 591 |
g_sdata.warnings++; |
| 592 |
break; |
| 593 |
case MakensisAPI::NOTIFY_ERROR: |
| 594 |
break; |
| 595 |
case MakensisAPI::NOTIFY_OUTPUT: |
| 596 |
MemSafeFree(g_sdata.output_exe); |
| 597 |
g_sdata.output_exe = (TCHAR*) MemAlloc(cds->cbData * sizeof(TCHAR)); |
| 598 |
lstrcpy(g_sdata.output_exe, (TCHAR *)cds->lpData); |
| 599 |
break; |
| 600 |
case MakensisAPI::PROMPT_FILEPATH: |
| 601 |
if ((((PROMPT_FILEPATH_DATA*)cds->lpData)->Platform & 7) == sizeof(TCHAR)) |
| 602 |
{ |
| 603 |
TCHAR buf[MAX_PATH]; |
| 604 |
lstrcpyn(buf, FSPath::FindLastComponent(((PROMPT_FILEPATH_DATA*)cds->lpData)->Path), COUNTOF(buf)); |
| 605 |
OPENFILENAME of = { SizeOfStruct(of) }; |
| 606 |
of.hwndOwner = hwndDlg; |
| 607 |
of.lpstrFilter = _T("*.exe\0*.exe\0*\0*.*\0"); |
| 608 |
of.lpstrFile = buf, of.nMaxFile = COUNTOF(buf); |
| 609 |
of.Flags = OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST|OFN_NOCHANGEDIR; |
| 610 |
if (GetSaveFileName(&of)) |
| 611 |
{ |
| 612 |
cdsret.dwData = cds->dwData, cdsret.cbData = (lstrlen(buf) + 1) * sizeof(TCHAR), cdsret.lpData = buf; |
| 613 |
SendMessage((HWND) wParam, WM_COPYDATA, (SIZE_T) hwndDlg, (SIZE_T) &cdsret); |
| 614 |
} |
| 615 |
return TRUE; |
| 616 |
} |
| 617 |
return FALSE; |
| 618 |
} |
| 619 |
return TRUE; |
| 620 |
} |
| 621 |
case WM_INITMENU: |
| 622 |
EnableMenuItem(g_sdata.menu, IDM_CANCEL, g_sdata.thread ? MF_ENABLED : MF_GRAYED); |
| 623 |
break; |
| 624 |
case WM_MAKENSIS_UPDATEUISTATE: |
| 625 |
{ |
| 626 |
UINT i, emptylog = SendMessage(g_sdata.logwnd, WM_GETTEXTLENGTH, 0, 0) == 0; |
| 627 |
static const PACKEDCMDID_T nonemptylogids [] = { PACKCMDID(IDM_COPY), PACKCMDID(IDM_COPYALL), PACKCMDID(IDM_CLEARLOG), PACKCMDID(IDM_SELECTALL) }; |
| 628 |
for (i = 0; i < COUNTOF(nonemptylogids); ++i) EnableUICommand(UNPACKCMDID(nonemptylogids[i]), !emptylog); |
| 629 |
EnableUICommand(IDM_BROWSESCR, !!g_sdata.input_script); |
| 630 |
break; |
| 631 |
} |
| 632 |
case WM_MAKENSIS_FREEZEEDITOR: |
| 633 |
RicheditFreeze(g_sdata.pLogTextDoc, lParam); |
| 634 |
break; |
| 635 |
case WM_TIMER: |
| 636 |
{ |
| 637 |
HWND hCtl; |
| 638 |
switch(wParam) { |
| 639 |
case TID_CONFIGURECLOSEORABORT: |
| 640 |
SendMessage(hCtl = GetDlgItem(hwndDlg, IDCANCEL), WM_SETTEXT, 0, (LPARAM) (g_sdata.thread ? _T("&Abort") : _T("&Close"))); |
| 641 |
EnableWindow(hCtl, true); |
| 642 |
UpdateCloseButtonTooltip(); |
| 643 |
return KillTimer(hwndDlg, wParam); |
| 644 |
} |
| 645 |
break; |
| 646 |
} |
| 647 |
case WM_COMMAND: |
| 648 |
{ |
| 649 |
switch (LOWORD(wParam)) { |
| 650 |
case IDM_UI_SWITCHSECTION: //devblogs.microsoft.com/oldnewthing/20191022-00/?p=103016 |
| 651 |
SetDialogFocus(hwndDlg, g_toolbar.hwnd); // Toolbar does not have WS_TABSTOP and we have no other "UI areas" to switch to so just go there |
| 652 |
break; |
| 653 |
case IDM_BROWSESCR: { |
| 654 |
if (g_sdata.input_script) { |
| 655 |
TCHAR str[MAX_PATH],*str2; |
| 656 |
lstrcpy(str,g_sdata.input_script); |
| 657 |
str2=_tcsrchr(str,_T('\\')); |
| 658 |
if(str2!=NULL) *(str2+1)=0; |
| 659 |
ShellExecuteWithErrorBox(hwndDlg, str); |
| 660 |
} |
| 661 |
return TRUE; |
| 662 |
} |
| 663 |
case IDM_DOCS: return (ShowDocs(), TRUE); |
| 664 |
case IDM_NSISHOME: return OpenUrlInDefaultBrowser(g_sdata.hwnd, NSIS_URL); |
| 665 |
case IDM_FORUM: return OpenUrlInDefaultBrowser(g_sdata.hwnd, NSIS_FORUM_URL); |
| 666 |
case IDM_NSISUPDATE: return (CheckForUpdate(), TRUE); |
| 667 |
case IDM_ABOUT: return ShowAboutDialog(hwndDlg)|TRUE; |
| 668 |
case IDM_SELECTALL: |
| 669 |
{ |
| 670 |
SendMessage(g_sdata.logwnd, EM_SETSEL, 0, -1); |
| 671 |
return TRUE; |
| 672 |
} |
| 673 |
case IDM_LOADSCRIPT: |
| 674 |
{ |
| 675 |
if (!g_sdata.thread) { |
| 676 |
OPENFILENAME l = { SizeOfStruct(l) }; |
| 677 |
TCHAR buf[MAX_PATH]; |
| 678 |
l.hwndOwner = hwndDlg; |
| 679 |
l.lpstrFilter = _T("NSIS Script (*.nsi)\0*.nsi\0All Files (*.*)\0*.*\0"); |
| 680 |
l.lpstrFile = buf; |
| 681 |
l.nMaxFile = MAX_STRING-1; |
| 682 |
l.lpstrTitle = _T("Load Script"); |
| 683 |
l.lpstrDefExt = _T("log"); |
| 684 |
l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST; |
| 685 |
buf[0] = _T('\0'); |
| 686 |
if (GetOpenFileName(&l)) { |
| 687 |
SetScript(buf); |
| 688 |
PushMRUFile(g_sdata.script); |
| 689 |
ResetObjects(); |
| 690 |
CompileNSISScript(); |
| 691 |
} |
| 692 |
} |
| 693 |
return TRUE; |
| 694 |
} |
| 695 |
case IDM_MRU_FILE: |
| 696 |
case IDM_MRU_FILE+1: |
| 697 |
case IDM_MRU_FILE+2: |
| 698 |
case IDM_MRU_FILE+3: |
| 699 |
case IDM_MRU_FILE+4: |
| 700 |
LoadMRUFile(LOWORD(wParam)-IDM_MRU_FILE); |
| 701 |
return TRUE; |
| 702 |
case IDM_CLEAR_MRU_LIST: |
| 703 |
ClearMRUList(); |
| 704 |
return TRUE; |
| 705 |
case IDM_COMPRESSOR: |
| 706 |
{ |
| 707 |
SetCompressor((NCOMPRESSOR)(g_sdata.compressor+1)); |
| 708 |
return TRUE; |
| 709 |
} |
| 710 |
case IDM_CLEARLOG: |
| 711 |
{ |
| 712 |
if (!g_sdata.thread) { |
| 713 |
ClearLog(); |
| 714 |
} |
| 715 |
return TRUE; |
| 716 |
} |
| 717 |
case IDM_ZOOM_INC: g_sdata.log_zoom += 25; goto set_log_zoom; |
| 718 |
case IDM_ZOOM_DEC: g_sdata.log_zoom -= 25; goto set_log_zoom; |
| 719 |
case IDM_ZOOM_RST: |
| 720 |
g_sdata.log_zoom = 100; set_log_zoom: |
| 721 |
SendMessage(g_sdata.logwnd, EM_SETZOOM, g_sdata.log_zoom = STD_MAX((int)g_sdata.log_zoom, 25), 100); |
| 722 |
InvalidateRect(g_sdata.logwnd, 0, false); |
| 723 |
break; |
| 724 |
case IDM_RECOMPILE: |
| 725 |
{ |
| 726 |
CompileNSISScript(); |
| 727 |
return TRUE; |
| 728 |
} |
| 729 |
// Added by Darren Owen (DrO) on 1/10/2003 |
| 730 |
case IDM_RECOMPILE_TEST: |
| 731 |
{ |
| 732 |
g_sdata.recompile_test = 1; |
| 733 |
CompileNSISScript(); |
| 734 |
return TRUE; |
| 735 |
} |
| 736 |
case IDM_SETTINGS: |
| 737 |
{ |
| 738 |
DialogBox(g_sdata.hInstance,MAKEINTRESOURCE(DLG_SETTINGS),g_sdata.hwnd,API_cast<DLGPROC>(SettingsProc)); |
| 739 |
return TRUE; |
| 740 |
} |
| 741 |
case IDM_WNDSPY: return ShowWndSpy(hwndDlg); |
| 742 |
case IDM_LOOKUP: return ShowLookupDialog(hwndDlg); |
| 743 |
case IDM_GUIDGEN: |
| 744 |
{ |
| 745 |
GUID guid; |
| 746 |
TCHAR buf[41 * (1 + (sizeof(TCHAR) < 2))]; |
| 747 |
FARPROC func = GetKeyState(VK_CONTROL) < 0 ? GetSysProcAddr("RPCRT4", "UuidCreateSequential") : NULL; |
| 748 |
((HRESULT(WINAPI*)(GUID*))(func ? func : GetSysProcAddr("RPCRT4", "UuidCreate")))(&guid); |
| 749 |
((int(WINAPI*)(GUID*, TCHAR*, int))(GetSysProcAddr("OLE32", "StringFromGUID2")))(&guid, buf, 39); |
| 750 |
for (UINT i = 0; sizeof(TCHAR) < 2; ++i) if (!(buf[i] = (CHAR) ((WCHAR*)buf)[i])) break; // WCHAR to TCHAR if ANSI |
| 751 |
LogMessage(g_sdata.hwnd, (buf[38] = '\r', buf[39] = '\n', buf[40] = '\0', buf)); |
| 752 |
SendMessage(g_sdata.hwnd, WM_MAKENSIS_UPDATEUISTATE, 0, 0); // Update clear log command state |
| 753 |
break; |
| 754 |
} |
| 755 |
case IDM_ARP: |
| 756 |
{ |
| 757 |
TCHAR dir[MAX_PATH]; |
| 758 |
GetSystemDirectory(dir, COUNTOF(dir)); |
| 759 |
ShellExecute(hwndDlg, NULL, TEXT("control.exe"), TEXT("appwiz.cpl"), dir, SW_SHOW); |
| 760 |
break; |
| 761 |
} |
| 762 |
case IDM_TEST: |
| 763 |
case IDC_TEST: |
| 764 |
{ |
| 765 |
if (g_sdata.output_exe) { |
| 766 |
ShellExecuteWithErrorBox(hwndDlg, g_sdata.output_exe); |
| 767 |
} |
| 768 |
return TRUE; |
| 769 |
} |
| 770 |
case IDM_EDITSCRIPT: |
| 771 |
{ |
| 772 |
if (g_sdata.input_script) { |
| 773 |
if (!ShellExecuteSilent(hwndDlg, g_sdata.input_script)) { |
| 774 |
TCHAR app[MAX_PATH]; |
| 775 |
if (GetWindowsDirectory(app, COUNTOF(app))) { |
| 776 |
lstrcat(app,_T("\\notepad.exe")); |
| 777 |
ShellExecuteWithErrorBox(hwndDlg, app, g_sdata.input_script); |
| 778 |
} |
| 779 |
} |
| 780 |
} |
| 781 |
return TRUE; |
| 782 |
} |
| 783 |
case IDCANCEL: |
| 784 |
if (g_sdata.thread) |
| 785 |
return PostMessage(hwndDlg, WM_COMMAND, IDM_CANCEL, 0); |
| 786 |
case IDM_EXIT: |
| 787 |
wParam = 0; |
| 788 |
goto tryquitapp; |
| 789 |
case IDM_CANCEL: |
| 790 |
{ |
| 791 |
SetEvent(g_sdata.sigint_event); |
| 792 |
SetEvent(g_sdata.sigint_event_legacy); |
| 793 |
return TRUE; |
| 794 |
} |
| 795 |
case IDM_COPY: |
| 796 |
if (RicheditHasSelection(g_sdata.logwnd)) goto logwndcopysel; |
| 797 |
// fall through |
| 798 |
case IDM_COPYALL: |
| 799 |
CopyToClipboard(g_sdata.hwnd); |
| 800 |
return TRUE; |
| 801 |
case IDM_COPYSELECTED: logwndcopysel: |
| 802 |
SendMessage(g_sdata.logwnd, WM_COPY, 0, 0); |
| 803 |
return TRUE; |
| 804 |
case IDM_SAVE: |
| 805 |
{ |
| 806 |
OPENFILENAME l = { SizeOfStruct(l) }; |
| 807 |
TCHAR buf[MAX_STRING]; |
| 808 |
l.hwndOwner = hwndDlg; |
| 809 |
l.lpstrFilter = _T("Log Files (*.log)\0*.log\0Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"); |
| 810 |
l.lpstrFile = buf; |
| 811 |
l.nMaxFile = MAX_STRING-1; |
| 812 |
l.lpstrTitle = _T("Save Output"); |
| 813 |
l.lpstrDefExt = _T("log"); |
| 814 |
l.lpstrInitialDir = NULL; |
| 815 |
l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST; |
| 816 |
lstrcpy(buf,_T("output")); |
| 817 |
if (GetSaveFileName(&l)) { |
| 818 |
HANDLE hFile = CreateFile(buf, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); |
| 819 |
if (INVALID_HANDLE_VALUE != hFile) { // BUGBUG:TODO: Error message for bad hFile or failed EM_STREAMOUT? |
| 820 |
WPARAM opts = sizeof(TCHAR) > 1 ? (SF_TEXT|SF_UNICODE) : (SF_TEXT); |
| 821 |
DWORD_PTR cookie[2] = { (DWORD_PTR)hFile, FALSE }; |
| 822 |
EDITSTREAM es = { (DWORD_PTR)&cookie, 0, SaveFileStreamCallback }; |
| 823 |
SendMessage(g_sdata.logwnd, EM_STREAMOUT, opts, (LPARAM)&es); |
| 824 |
CloseHandle(hFile); |
| 825 |
} |
| 826 |
} |
| 827 |
return TRUE; |
| 828 |
} |
| 829 |
case IDM_FIND: |
| 830 |
{ |
| 831 |
bool reuseWindow = true; |
| 832 |
if (!g_find.uFindReplaceMsg) g_find.uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING); |
| 833 |
memset(&g_find.fr, 0, sizeof(FINDREPLACE)); |
| 834 |
g_find.fr.lStructSize = sizeof(FINDREPLACE); |
| 835 |
g_find.fr.hwndOwner = hwndDlg; |
| 836 |
g_find.fr.Flags = FR_NOUPDOWN; |
| 837 |
g_find.fr.lpstrFindWhat = g_findbuf; |
| 838 |
g_find.fr.wFindWhatLen = COUNTOF(g_findbuf); |
| 839 |
if (!reuseWindow || !SetForegroundWindow(g_find.hwndFind)) |
| 840 |
g_find.hwndFind = FindText(&g_find.fr); |
| 841 |
return TRUE; |
| 842 |
} |
| 843 |
default: |
| 844 |
{ |
| 845 |
int i; |
| 846 |
DWORD command = LOWORD(wParam); |
| 847 |
for(i=(int)COMPRESSOR_SCRIPT; i<=(int)COMPRESSOR_BEST; i++) { |
| 848 |
if(command == compressor_commands[i]) { |
| 849 |
SetCompressor((NCOMPRESSOR)i); |
| 850 |
return TRUE; |
| 851 |
} |
| 852 |
} |
| 853 |
} |
| 854 |
} |
| 855 |
} |
| 856 |
} |
| 857 |
if (msg == g_find.uFindReplaceMsg && msg) { |
| 858 |
LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam; |
| 859 |
if (lpfr->Flags & FR_FINDNEXT) { |
| 860 |
WPARAM flags = FR_DOWN; |
| 861 |
if (lpfr->Flags & FR_MATCHCASE) flags |= FR_MATCHCASE; |
| 862 |
if (lpfr->Flags & FR_WHOLEWORD) flags |= FR_WHOLEWORD; |
| 863 |
FINDTEXTEX ft; |
| 864 |
SendMessage(g_sdata.logwnd, EM_EXGETSEL, 0, (LPARAM)&ft.chrg); |
| 865 |
ft.chrg.cpMin = (ft.chrg.cpMax == ft.chrg.cpMin) ? 0 : ft.chrg.cpMax; |
| 866 |
ft.chrg.cpMax = (LONG) SendMessage(g_sdata.logwnd, WM_GETTEXTLENGTH, 0, 0); |
| 867 |
ft.lpstrText = lpfr->lpstrFindWhat; |
| 868 |
ft.chrg.cpMin = (LONG) SendMessage(g_sdata.logwnd, EM_FINDTEXTEX, flags, (LPARAM)&ft); |
| 869 |
if (ft.chrg.cpMin != -1) |
| 870 |
SendMessage(g_sdata.logwnd, EM_SETSEL, ft.chrgText.cpMin, ft.chrgText.cpMax); |
| 871 |
else |
| 872 |
MessageBeep(MB_ICONASTERISK); |
| 873 |
} |
| 874 |
if (lpfr->Flags & FR_DIALOGTERM) g_find.hwndFind = 0; |
| 875 |
return TRUE; |
| 876 |
} |
| 877 |
return 0; |
| 878 |
} |
| 879 |
|
| 880 |
DWORD WINAPI MakeNSISProc(LPVOID TreadParam) { |
| 881 |
TCHAR eventnamebuf[100]; |
| 882 |
wsprintf(eventnamebuf, MakensisAPI::SigintEventNameFmt, g_sdata.hwnd); |
| 883 |
if (g_sdata.sigint_event) CloseHandle(g_sdata.sigint_event); |
| 884 |
g_sdata.sigint_event = CreateEvent(NULL, FALSE, FALSE, eventnamebuf); |
| 885 |
if (!g_sdata.sigint_event) { |
| 886 |
ErrorMessage(g_sdata.hwnd, _T("There was an error creating the abort event.")); |
| 887 |
PostMessage(g_sdata.hwnd, WM_MAKENSIS_PROCESSCOMPLETE, 0, 0); |
| 888 |
return 1; |
| 889 |
} |
| 890 |
|
| 891 |
STARTUPINFO si; |
| 892 |
HANDLE newstdout,read_stdout; |
| 893 |
|
| 894 |
if (!InitSpawn(si, read_stdout, newstdout)) { |
| 895 |
ErrorMessage(g_sdata.hwnd, _T("There was an error creating the pipe.")); |
| 896 |
PostMessage(g_sdata.hwnd, WM_MAKENSIS_PROCESSCOMPLETE, 0, 0); |
| 897 |
return 1; |
| 898 |
} |
| 899 |
PROCESS_INFORMATION pi; |
| 900 |
if (!CreateProcess(0, g_sdata.compile_command, 0, 0, TRUE, CREATE_NEW_CONSOLE, 0, 0, &si, &pi)) { |
| 901 |
TCHAR buf[MAX_STRING]; // BUGBUG: TODO: Too small? |
| 902 |
wsprintf(buf,_T("Could not execute:\r\n %s."), g_sdata.compile_command); |
| 903 |
ErrorMessage(g_sdata.hwnd, buf); |
| 904 |
FreeSpawn(0, read_stdout, newstdout); |
| 905 |
PostMessage(g_sdata.hwnd, WM_MAKENSIS_PROCESSCOMPLETE, 0, 0); |
| 906 |
return 1; |
| 907 |
} |
| 908 |
CloseHandle(newstdout); // Close this handle (duplicated in subprocess) now so we get ERROR_BROKEN_PIPE |
| 909 |
|
| 910 |
char iob[(1024 & ~1) + sizeof(WCHAR)]; |
| 911 |
WCHAR *p = (WCHAR*) iob, wcl = 0; |
| 912 |
DWORD cbiob = sizeof(iob) - sizeof(WCHAR), cb = 0, cbofs = 0, cch, cbio; |
| 913 |
for(;;) |
| 914 |
{ |
| 915 |
BOOL rok = ReadFile(read_stdout, iob+cbofs, cbiob-cbofs, &cbio, NULL); |
| 916 |
cb += cbio, cch = cb / sizeof(WCHAR); |
| 917 |
if (!cch) |
| 918 |
{ |
| 919 |
if (!rok) break; // TODO: If cb is non-zero we should report a incomplete read error? |
| 920 |
cbofs += cbio; // We only have 1 byte, need to read more to get a complete WCHAR |
| 921 |
continue; |
| 922 |
} |
| 923 |
char oddbyte = (char)(cb % 2), incompsurr; |
| 924 |
cbofs = 0; |
| 925 |
if ((incompsurr = IS_HIGH_SURROGATE(p[cch-1]))) |
| 926 |
wcl = p[--cch], cbofs = sizeof(WCHAR); // Store leading surrogate part and complete it later |
| 927 |
if (oddbyte) |
| 928 |
oddbyte = iob[cb-1], ++cbofs; |
| 929 |
logappendfinal: |
| 930 |
p[cch] = L'\0'; |
| 931 |
LogMessage(g_sdata.hwnd, p); |
| 932 |
p[0] = wcl, iob[cbofs - !!oddbyte] = oddbyte, cb = 0; |
| 933 |
if (!rok) // No more data can be read |
| 934 |
{ |
| 935 |
if (cbofs) // Unable to complete the surrogate pair or odd byte |
| 936 |
{ |
| 937 |
p[0] = 0xfffd, cch = 1, cbofs = 0; |
| 938 |
goto logappendfinal; |
| 939 |
} |
| 940 |
break; |
| 941 |
} |
| 942 |
} |
| 943 |
FreeSpawn(&pi, read_stdout, 0); |
| 944 |
g_sdata.retcode = pi.dwProcessId; |
| 945 |
PostMessage(g_sdata.hwnd, WM_MAKENSIS_PROCESSCOMPLETE, 0, 0); |
| 946 |
return 0; |
| 947 |
} |
| 948 |
|
| 949 |
static INT_PTR CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 950 |
ABOUTDLGDATA &dd = *(ABOUTDLGDATA*) g_ModalDlgData; |
| 951 |
switch(msg) { |
| 952 |
case WM_DRAWITEM: |
| 953 |
if (wParam == IDC_ABOUTHEADER) |
| 954 |
{ |
| 955 |
DRAWITEMSTRUCT &dis = *(DRAWITEMSTRUCT*) lParam; |
| 956 |
RECT r, r2; |
| 957 |
const TCHAR txt[] = TEXT("MakeNSISW"); |
| 958 |
INT dt = DT_NOCLIP|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER, cch = COUNTOF(txt) - 1, line = DpiScaleY(dis.hwndItem, 2), shadow = 1; |
| 959 |
GetClientRect(dis.hwndItem, &r); |
| 960 |
if (!dd.hHeaderFont) |
| 961 |
dd.hHeaderFont = CreateFont(0, CFF_RAWSIZE, r.bottom / 2, FW_BOLD, DEFAULT_PITCH|FF_DONTCARE, ANSI_CHARSET, _T("Trebuchet MS")); // IE4.01SP2+ |
| 962 |
HGDIOBJ hOrgFont = SelectObject(dis.hDC, dd.hHeaderFont); |
| 963 |
DrawHorzGradient(dis.hDC, r.left, r.top, r.right, r.bottom - line, RGB(22, 77, 160), RGB(29, 100, 207)); |
| 964 |
DrawHorzGradient(dis.hDC, r.left, r.bottom - line, r.right, r.bottom, RGB(255, 142, 42), RGB(190, 90, 2)); |
| 965 |
SetBkMode(dis.hDC, TRANSPARENT); |
| 966 |
if (!dd.FinalHeaderPos) |
| 967 |
{ |
| 968 |
r2 = r; |
| 969 |
DrawText(dis.hDC, txt, cch, &r2, dt|DT_CALCRECT); |
| 970 |
dd.FinalHeaderPos = r.right - (r2.right - r2.left); |
| 971 |
dd.FinalHeaderPos -= DlgUnitToPixelX(hwndDlg, 7); // Margin |
| 972 |
} |
| 973 |
r.left += dd.AnimPos; |
| 974 |
SetTextColor(dis.hDC, RGB(0, 0, 0)), OffsetRect(&r, +shadow, +shadow); |
| 975 |
DrawText(dis.hDC, txt, cch, &r, dt); |
| 976 |
SetTextColor(dis.hDC, RGB(255, 255, 255)), OffsetRect(&r, -shadow, -shadow); |
| 977 |
DrawText(dis.hDC, txt, cch, &r, dt); |
| 978 |
SelectObject(dis.hDC, hOrgFont); |
| 979 |
return TRUE; |
| 980 |
} |
| 981 |
break; |
| 982 |
case WM_TIMER: |
| 983 |
if (wParam == ABOUTDLGDATA::TID_HEADER) |
| 984 |
{ |
| 985 |
INT finalpos = dd.FinalHeaderPos, dir; |
| 986 |
if (dd.AnimSpeed >= 4) |
| 987 |
{ |
| 988 |
dd.AnimPos += (dir = (dd.AnimPos >= finalpos)) ? -(INT)dd.AnimSpeed : +(INT)dd.AnimSpeed; |
| 989 |
if (dd.AnimDir != dir) dd.AnimDir = dir, dd.AnimSpeed /= 2; |
| 990 |
} |
| 991 |
else |
| 992 |
{ |
| 993 |
dd.AnimPos = finalpos; |
| 994 |
KillTimer(hwndDlg, ABOUTDLGDATA::TID_HEADER); |
| 995 |
} |
| 996 |
InvalidateRect(GetDlgItem(hwndDlg, IDC_ABOUTHEADER), NULL, false); |
| 997 |
} |
| 998 |
break; |
| 999 |
case WM_DESTROY: |
| 1000 |
DeleteObject(dd.hHeaderFont); |
| 1001 |
DeleteObject(dd.hFont); |
| 1002 |
DeleteObject(dd.hBoldFont); |
| 1003 |
break; |
| 1004 |
case WM_INITDIALOG: |
| 1005 |
{ |
| 1006 |
CenterOnParent(hwndDlg); |
| 1007 |
HFONT fontnorm = CreateFontPt(hwndDlg, 8, FW_NORMAL, FIXED_PITCH|FF_DONTCARE, ANSI_CHARSET, _T("Tahoma")), |
| 1008 |
fontbold = CreateFontPt(hwndDlg, 8, FW_BOLD, FIXED_PITCH|FF_DONTCARE, ANSI_CHARSET, _T("Tahoma")); |
| 1009 |
if (!fontbold && (SupportsWNT4() || SupportsW95())) { // Tahoma shipped with 98+ and 2000+ |
| 1010 |
fontnorm = CreateFontPt(hwndDlg, 8, FW_NORMAL, FIXED_PITCH|FF_DONTCARE, ANSI_CHARSET, _T("MS Shell Dlg")); |
| 1011 |
fontbold = CreateFontPt(hwndDlg, 8, FW_BOLD, FIXED_PITCH|FF_DONTCARE, ANSI_CHARSET, _T("MS Shell Dlg")); |
| 1012 |
} |
| 1013 |
dd.hFont = fontnorm, dd.hBoldFont = fontbold; |
| 1014 |
SendDlgItemMessage(hwndDlg, IDC_ABOUTVERSION, WM_SETFONT, (WPARAM)fontbold, FALSE); |
| 1015 |
static const BYTE fontnormctlids[] = { IDC_ABOUTCOPY, IDC_ABOUTPORTIONS, IDC_ABOUTDONATE, IDC_OTHERCONTRIB, IDC_NSISVER }; |
| 1016 |
for (UINT i = 0; i < COUNTOF(fontnormctlids); ++i) SendDlgItemMessage(hwndDlg, fontnormctlids[i], WM_SETFONT, (WPARAM)fontnorm, FALSE); |
| 1017 |
SendMessage(hwndDlg, WM_APP, 0, 0); // Set IDC_ABOUTVERSION |
| 1018 |
SetDlgItemText(hwndDlg, IDC_ABOUTCOPY, COPYRIGHT); |
| 1019 |
SetDlgItemText(hwndDlg, IDC_OTHERCONTRIB, CONTRIB); |
| 1020 |
SetDlgItemText(hwndDlg, IDC_ABOUTDONATE, DONATE); |
| 1021 |
SetDlgItemText(hwndDlg, IDC_NSISVER, g_sdata.branding); |
| 1022 |
SetTimer(hwndDlg, ABOUTDLGDATA::TID_HEADER, 50, NULL); |
| 1023 |
break; |
| 1024 |
} |
| 1025 |
case WM_NOTIFY: |
| 1026 |
switch (((NMHDR*)lParam)->code) |
| 1027 |
{ |
| 1028 |
case NM_CLICK: |
| 1029 |
// fall through |
| 1030 |
case NM_RETURN: |
| 1031 |
if (((NMHDR*)lParam)->idFrom == IDC_ABOUTDONATE) |
| 1032 |
{ |
| 1033 |
static const BYTE x = 128, encurl[] = DONATEURL; |
| 1034 |
char url[COUNTOF(encurl)]; |
| 1035 |
for (UINT i = 0;; ++i) if (!(url[i] = (char) (encurl[i] & ~x))) break; // "Decrypt" URL |
| 1036 |
OpenUrlInDefaultBrowser(hwndDlg, url); |
| 1037 |
} |
| 1038 |
break; |
| 1039 |
} |
| 1040 |
break; |
| 1041 |
case WM_COMMAND: |
| 1042 |
if (wParam == MAKELONG(IDC_ABOUTVERSION, STN_DBLCLK)) goto showversion; |
| 1043 |
if (IDOK != LOWORD(wParam)) break; |
| 1044 |
// fall through |
| 1045 |
case WM_CLOSE: |
| 1046 |
return EndDialog(hwndDlg, TRUE); |
| 1047 |
case WM_APP: showversion: |
| 1048 |
{ |
| 1049 |
TCHAR buf[200], showver = wParam != 0; |
| 1050 |
wsprintf(buf, _T("MakeNSISW %s%s(NSIS Compiler Interface)"), showver ? NSISW_VERSION : _T(""), showver ? _T(" ") : _T("")); |
| 1051 |
SetDlgItemText(hwndDlg, IDC_ABOUTVERSION, buf); |
| 1052 |
} |
| 1053 |
break; |
| 1054 |
} |
| 1055 |
return FALSE; |
| 1056 |
} |
| 1057 |
|
| 1058 |
INT_PTR ShowAboutDialog(HWND hwndOwner) |
| 1059 |
{ |
| 1060 |
ABOUTDLGDATA dd; |
| 1061 |
g_ModalDlgData = ⅆ |
| 1062 |
dd.hHeaderFont = NULL, dd.FinalHeaderPos = 0; |
| 1063 |
dd.AnimSpeed = 55, dd.AnimPos = 0, dd.AnimDir = 0; |
| 1064 |
return DialogBox(g_sdata.hInstance, MAKEINTRESOURCE(DLG_ABOUT), hwndOwner, API_cast<DLGPROC>(AboutProc)); |
| 1065 |
} |
| 1066 |
|
| 1067 |
static void EnableSymbolSetButtons(HWND hwndDlg) |
| 1068 |
{ |
| 1069 |
LRESULT n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETCOUNT, 0, 0); |
| 1070 |
EnableWindow(GetDlgItem(hwndDlg, IDC_CLEAR), n > 0); |
| 1071 |
EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), n > 0); |
| 1072 |
} |
| 1073 |
|
| 1074 |
static void EnableSymbolEditButtons(HWND hwndDlg) |
| 1075 |
{ |
| 1076 |
LRESULT n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELCOUNT, 0, 0); |
| 1077 |
EnableWindow(GetDlgItem(hwndDlg, IDC_LEFT), n == 1); |
| 1078 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), n != 0); |
| 1079 |
} |
| 1080 |
|
| 1081 |
static void SetSymbols(HWND hwndDlg, TCHAR **symbols) |
| 1082 |
{ |
| 1083 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_RESETCONTENT , 0, 0); |
| 1084 |
if (symbols) { |
| 1085 |
for (SIZE_T i = 0; symbols[i]; ++i) |
| 1086 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_ADDSTRING, 0, (LPARAM)symbols[i]); |
| 1087 |
} |
| 1088 |
EnableSymbolSetButtons(hwndDlg); |
| 1089 |
EnableWindow(GetDlgItem(hwndDlg, IDC_RIGHT), FALSE); |
| 1090 |
EnableWindow(GetDlgItem(hwndDlg, IDC_LEFT), FALSE); |
| 1091 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), FALSE); |
| 1092 |
} |
| 1093 |
|
| 1094 |
static TCHAR **GetSymbols(HWND hwndDlg) |
| 1095 |
{ |
| 1096 |
LRESULT n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETCOUNT, 0, 0); |
| 1097 |
TCHAR **symbols = NULL; |
| 1098 |
if(n > 0) { |
| 1099 |
symbols = (TCHAR **) GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR *)); |
| 1100 |
for (LRESULT i = 0; i < n; i++) { |
| 1101 |
LRESULT len = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXTLEN, (WPARAM)i, 0); |
| 1102 |
symbols[i] = (TCHAR*) MemAllocZI((len+1)*sizeof(TCHAR)); |
| 1103 |
if (!symbols[i]) { |
| 1104 |
FreeSymbolSet(symbols); |
| 1105 |
return NULL; |
| 1106 |
} |
| 1107 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)i, (LPARAM)symbols[i]); |
| 1108 |
} |
| 1109 |
symbols[n] = NULL; |
| 1110 |
} |
| 1111 |
|
| 1112 |
return symbols; |
| 1113 |
} |
| 1114 |
|
| 1115 |
INT_PTR CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 1116 |
switch(msg) { |
| 1117 |
case WM_INITDIALOG: |
| 1118 |
{ |
| 1119 |
CenterOnParent(hwndDlg); |
| 1120 |
for(int i = (int)COMPRESSOR_SCRIPT; i <= (int)COMPRESSOR_BEST; i++) |
| 1121 |
SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_ADDSTRING, 0, (LPARAM)compressor_display_names[i]); |
| 1122 |
SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_SETCURSEL, (WPARAM)g_sdata.default_compressor, (LPARAM)0); |
| 1123 |
|
| 1124 |
SetSymbols(hwndDlg, g_sdata.symbols); |
| 1125 |
SetFocus(GetDlgItem(hwndDlg, IDC_SYMBOL)); |
| 1126 |
break; |
| 1127 |
} |
| 1128 |
case WM_MAKENSIS_LOADSYMBOLSET: |
| 1129 |
{ |
| 1130 |
TCHAR *name = (TCHAR *)wParam; |
| 1131 |
TCHAR **symbols = LoadSymbolSet(name); |
| 1132 |
if(symbols) { |
| 1133 |
SetSymbols(hwndDlg, symbols); |
| 1134 |
GlobalFree((HGLOBAL) symbols); |
| 1135 |
} |
| 1136 |
break; |
| 1137 |
} |
| 1138 |
case WM_MAKENSIS_SAVESYMBOLSET: |
| 1139 |
{ |
| 1140 |
TCHAR *name = (TCHAR *)wParam; |
| 1141 |
TCHAR **symbols = GetSymbols(hwndDlg); |
| 1142 |
if(symbols) { |
| 1143 |
SaveSymbolSet(name, symbols); |
| 1144 |
GlobalFree((HGLOBAL) symbols); |
| 1145 |
} |
| 1146 |
break; |
| 1147 |
} |
| 1148 |
case WM_COMMAND: |
| 1149 |
{ |
| 1150 |
switch (LOWORD(wParam)) { |
| 1151 |
case IDOK: |
| 1152 |
{ |
| 1153 |
ResetObjects(); |
| 1154 |
ResetSymbols(); |
| 1155 |
g_sdata.symbols = GetSymbols(hwndDlg); |
| 1156 |
|
| 1157 |
INT_PTR n = SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_GETCURSEL, (WPARAM)0, (LPARAM)0); |
| 1158 |
if (n >= (INT_PTR)COMPRESSOR_SCRIPT && n <= (INT_PTR)COMPRESSOR_BEST) |
| 1159 |
g_sdata.default_compressor = (NCOMPRESSOR)n; |
| 1160 |
else |
| 1161 |
g_sdata.default_compressor = COMPRESSOR_SCRIPT; |
| 1162 |
SaveCompressor(); |
| 1163 |
SetCompressor(g_sdata.default_compressor); |
| 1164 |
EndDialog(hwndDlg, TRUE); |
| 1165 |
} |
| 1166 |
break; |
| 1167 |
case IDCANCEL: |
| 1168 |
EndDialog(hwndDlg, TRUE); |
| 1169 |
break; |
| 1170 |
case IDC_RIGHT: |
| 1171 |
{ |
| 1172 |
LRESULT n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0); |
| 1173 |
if(n > 0) { |
| 1174 |
TCHAR *buf = (TCHAR*) MemAllocZI((n+1)*sizeof(TCHAR)); |
| 1175 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXT, n+1, (LPARAM)buf); |
| 1176 |
if(_tcsstr(buf,_T(" ")) || _tcsstr(buf,_T("\t"))) { |
| 1177 |
MessageBox(hwndDlg,SYMBOLSERROR,ERRBOXTITLE,MB_OK|MB_ICONSTOP); |
| 1178 |
MemFree(buf); |
| 1179 |
break; |
| 1180 |
} |
| 1181 |
|
| 1182 |
n = SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXTLENGTH, 0, 0); |
| 1183 |
if(n > 0) { |
| 1184 |
TCHAR *buf2 = (TCHAR*) MemAllocZI((n+1)*sizeof(TCHAR)); |
| 1185 |
SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXT, n+1, (LPARAM)buf2); |
| 1186 |
TCHAR *buf3 = (TCHAR*) MemAllocZI((lstrlen(buf)+lstrlen(buf2)+2)*sizeof(TCHAR)); |
| 1187 |
wsprintf(buf3,_T("%s=%s"),buf,buf2); |
| 1188 |
MemFree(buf); |
| 1189 |
buf = buf3; |
| 1190 |
MemFree(buf2); |
| 1191 |
} |
| 1192 |
INT_PTR idx = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_ADDSTRING, 0, (LPARAM)buf); |
| 1193 |
if (idx >= 0) |
| 1194 |
{ |
| 1195 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_SETSEL, FALSE, -1); |
| 1196 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_SETSEL, TRUE, idx); |
| 1197 |
} |
| 1198 |
EnableSymbolEditButtons(hwndDlg); |
| 1199 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_SETTEXT, 0, 0); |
| 1200 |
SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, 0); |
| 1201 |
MemFree(buf); |
| 1202 |
EnableSymbolSetButtons(hwndDlg); |
| 1203 |
} |
| 1204 |
} |
| 1205 |
break; |
| 1206 |
case IDC_LEFT: |
| 1207 |
{ |
| 1208 |
if (SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELCOUNT, 0, 0) != 1) |
| 1209 |
break; |
| 1210 |
|
| 1211 |
int index; |
| 1212 |
INT_PTR num = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELITEMS, 1, (LPARAM)&index); |
| 1213 |
if(num == 1) { |
| 1214 |
INT_PTR n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXTLEN, (WPARAM)index, 0); |
| 1215 |
if(n > 0) { |
| 1216 |
TCHAR *buf = (TCHAR*) MemAllocZI((n+1)*sizeof(TCHAR)); |
| 1217 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)index, (LPARAM)buf); |
| 1218 |
TCHAR *p = _tcsstr(buf,_T("=")); |
| 1219 |
if(p) { |
| 1220 |
SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, (LPARAM)(p+1)); |
| 1221 |
*p=0; |
| 1222 |
} |
| 1223 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_SETTEXT, 0, (LPARAM)buf); |
| 1224 |
MemFree(buf); |
| 1225 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_DELETESTRING, (WPARAM)index, 0); |
| 1226 |
EnableWindow(GetDlgItem(hwndDlg, IDC_LEFT), FALSE); |
| 1227 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), FALSE); |
| 1228 |
EnableSymbolSetButtons(hwndDlg); |
| 1229 |
} |
| 1230 |
} |
| 1231 |
} |
| 1232 |
break; |
| 1233 |
case IDC_CLEAR: |
| 1234 |
{ |
| 1235 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_RESETCONTENT , 0, 0); |
| 1236 |
EnableSymbolSetButtons(hwndDlg); |
| 1237 |
} |
| 1238 |
break; |
| 1239 |
case IDC_LOAD: |
| 1240 |
case IDC_SAVE: |
| 1241 |
ShowSymbolSetDialog(hwndDlg, IDC_LOAD == LOWORD(wParam)); |
| 1242 |
break; |
| 1243 |
case IDC_DEL: |
| 1244 |
{ |
| 1245 |
INT_PTR n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELCOUNT, 0, 0); |
| 1246 |
int *items = (int*) MemAllocZI(n*sizeof(int)); |
| 1247 |
if (items) { |
| 1248 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELITEMS, (WPARAM)n, (LPARAM)items); |
| 1249 |
for(INT_PTR i=n-1;i>=0;i--) |
| 1250 |
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_DELETESTRING, (WPARAM)items[i], 0); |
| 1251 |
MemFree(items); |
| 1252 |
} |
| 1253 |
EnableSymbolEditButtons(hwndDlg); |
| 1254 |
EnableSymbolSetButtons(hwndDlg); |
| 1255 |
} |
| 1256 |
break; |
| 1257 |
case IDC_SYMBOL: |
| 1258 |
if(HIWORD(wParam) == EN_CHANGE) |
| 1259 |
{ |
| 1260 |
LRESULT n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0); |
| 1261 |
EnableWindow(GetDlgItem(hwndDlg, IDC_RIGHT), n > 0); |
| 1262 |
} |
| 1263 |
break; |
| 1264 |
case IDC_SYMBOLS: |
| 1265 |
if (HIWORD(wParam) == LBN_SELCHANGE) |
| 1266 |
{ |
| 1267 |
EnableSymbolEditButtons(hwndDlg); |
| 1268 |
} |
| 1269 |
else if (HIWORD(wParam) == LBN_DBLCLK) |
| 1270 |
{ |
| 1271 |
SendDlgItemMessage(hwndDlg, IDC_LEFT, BM_CLICK, 0, 0); |
| 1272 |
} |
| 1273 |
break; |
| 1274 |
} |
| 1275 |
break; |
| 1276 |
} |
| 1277 |
} |
| 1278 |
return FALSE; |
| 1279 |
} |
| 1280 |
|
| 1281 |
INT_PTR CALLBACK CompressorProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 1282 |
switch(msg) { |
| 1283 |
case WM_INITDIALOG: |
| 1284 |
{ |
| 1285 |
CenterOnParent(hwndDlg); |
| 1286 |
for(int i=(int)COMPRESSOR_SCRIPT; i <= (int)COMPRESSOR_BEST; i++) { |
| 1287 |
SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_ADDSTRING, 0, (LPARAM)compressor_display_names[i]); |
| 1288 |
} |
| 1289 |
SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_SETCURSEL, (WPARAM)g_sdata.compressor, (LPARAM)0); |
| 1290 |
|
| 1291 |
SetFocus(GetDlgItem(hwndDlg, IDC_COMPRESSOR)); |
| 1292 |
break; |
| 1293 |
} |
| 1294 |
case WM_COMMAND: |
| 1295 |
{ |
| 1296 |
switch (LOWORD(wParam)) { |
| 1297 |
case IDOK: |
| 1298 |
{ |
| 1299 |
INT_PTR n = SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_GETCURSEL, (WPARAM)0, (LPARAM)0); |
| 1300 |
if(n >= (INT_PTR)COMPRESSOR_SCRIPT && n <= (INT_PTR)COMPRESSOR_BEST) |
| 1301 |
SetCompressor((NCOMPRESSOR)n); |
| 1302 |
else |
| 1303 |
SetCompressor(g_sdata.default_compressor); |
| 1304 |
EndDialog(hwndDlg, 0); |
| 1305 |
break; |
| 1306 |
} |
| 1307 |
case IDCANCEL: |
| 1308 |
{ |
| 1309 |
EndDialog(hwndDlg, 1); |
| 1310 |
LogMessage(g_sdata.hwnd,USAGE); |
| 1311 |
break; |
| 1312 |
} |
| 1313 |
} |
| 1314 |
break; |
| 1315 |
} |
| 1316 |
} |
| 1317 |
return FALSE; |
| 1318 |
} |
| 1319 |
|
| 1320 |
static void FixSimpleComboBoxSizeBug(HWND hCombo) // Fix Win10 CBS_SIMPLE height drawing bug when DPI != 96 |
| 1321 |
{ |
| 1322 |
RECT r; |
| 1323 |
GetWindowRect(hCombo, &r); |
| 1324 |
SetWindowPos(hCombo, 0, 0, 0, RectW(r), RectH(r)-1, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE); |
| 1325 |
SetWindowPos(hCombo, 0, 0, 0, RectW(r), RectH(r), SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE|SWP_FRAMECHANGED); |
| 1326 |
} |
| 1327 |
|
| 1328 |
#define SymbolSetDlgDpiChanged(hwndDlg) ( FixSimpleComboBoxSizeBug(GetDlgItem((hwndDlg), IDC_NAMES)) ) |
| 1329 |
|
| 1330 |
static INT_PTR CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 1331 |
SYMSETDLGDATA &dd = *(SYMSETDLGDATA*) g_ModalDlgData; |
| 1332 |
switch(msg) { |
| 1333 |
case WM_INITDIALOG: |
| 1334 |
{ |
| 1335 |
HKEY hKey; |
| 1336 |
CenterOnParent(hwndDlg); |
| 1337 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), FALSE); |
| 1338 |
if (OpenRegSettingsKey(hKey)) { |
| 1339 |
HKEY hSubKey; |
| 1340 |
|
| 1341 |
if (RegOpenKeyEx(hKey, REGSYMSUBKEY, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS) { |
| 1342 |
TCHAR subkey[1024]; |
| 1343 |
int i=0; |
| 1344 |
|
| 1345 |
while (RegEnumKey(hSubKey, i, subkey, sizeof(subkey)) == ERROR_SUCCESS) { |
| 1346 |
SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_ADDSTRING, 0, (LPARAM)subkey); |
| 1347 |
i++; |
| 1348 |
} |
| 1349 |
RegCloseKey(hSubKey); |
| 1350 |
} |
| 1351 |
RegCloseKey(hKey); |
| 1352 |
} |
| 1353 |
HWND hwndEdit = GetComboEdit(GetDlgItem(hwndDlg, IDC_NAMES)); |
| 1354 |
SendMessage(hwndEdit, EM_LIMITTEXT, (WPARAM)SYMSETNAME_MAXLEN, 0); |
| 1355 |
if (dd.LoadingMode) { |
| 1356 |
SetWindowText(hwndDlg, LOAD_SYMBOL_SET_DLG_NAME); |
| 1357 |
SetWindowText(GetDlgItem(hwndDlg, IDOK), LOAD_BUTTON_TEXT); |
| 1358 |
SendMessage(hwndEdit, EM_SETREADONLY, (WPARAM)TRUE, 0); |
| 1359 |
} |
| 1360 |
else { |
| 1361 |
SetWindowText(hwndDlg, SAVE_SYMBOL_SET_DLG_NAME); |
| 1362 |
SetWindowText(GetDlgItem(hwndDlg, IDOK), SAVE_BUTTON_TEXT); |
| 1363 |
} |
| 1364 |
SymbolSetDlgDpiChanged(hwndDlg); |
| 1365 |
break; |
| 1366 |
} |
| 1367 |
case WM_COMMAND: |
| 1368 |
{ |
| 1369 |
switch (LOWORD(wParam)) { |
| 1370 |
case IDOK: |
| 1371 |
{ |
| 1372 |
TCHAR name[SYMSETNAME_MAXLEN+1]; |
| 1373 |
HWND hwndEdit = GetComboEdit(GetDlgItem(hwndDlg, IDC_NAMES)); |
| 1374 |
SendMessage(hwndEdit, WM_GETTEXT, (WPARAM)COUNTOF(name), (LPARAM)name); |
| 1375 |
if (!*name) { |
| 1376 |
LPCTSTR msg = dd.LoadingMode ? LOAD_SYMBOL_SET_MESSAGE : SAVE_SYMBOL_SET_MESSAGE; |
| 1377 |
LPCTSTR tit = dd.LoadingMode ? LOAD_SYMBOL_SET_DLG_NAME : SAVE_SYMBOL_SET_DLG_NAME; |
| 1378 |
MessageBox(hwndDlg, msg, tit, MB_OK|MB_ICONEXCLAMATION); |
| 1379 |
} |
| 1380 |
else { |
| 1381 |
HWND hwndParent = GetParent(hwndDlg); |
| 1382 |
UINT msg = dd.LoadingMode ? WM_MAKENSIS_LOADSYMBOLSET : WM_MAKENSIS_SAVESYMBOLSET; |
| 1383 |
SendMessage(hwndParent, msg, (WPARAM)name, (LPARAM)NULL); |
| 1384 |
EndDialog(hwndDlg, TRUE); |
| 1385 |
} |
| 1386 |
break; |
| 1387 |
} |
| 1388 |
case IDCANCEL: |
| 1389 |
{ |
| 1390 |
EndDialog(hwndDlg, TRUE); |
| 1391 |
break; |
| 1392 |
} |
| 1393 |
case IDC_DEL: |
| 1394 |
{ |
| 1395 |
LONG_PTR n = SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETCURSEL, 0, 0); |
| 1396 |
if(n != CB_ERR) { |
| 1397 |
INT_PTR len = SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETLBTEXTLEN, (WPARAM)n, 0); |
| 1398 |
TCHAR *buf = (TCHAR*) MemAllocZI((len+1)*sizeof(TCHAR)); |
| 1399 |
if(SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETLBTEXT, (WPARAM)n, (LPARAM)buf) != CB_ERR) { |
| 1400 |
SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_DELETESTRING, n, 0); |
| 1401 |
DeleteSymbolSet(buf); |
| 1402 |
} |
| 1403 |
MemFree(buf); |
| 1404 |
} |
| 1405 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), FALSE); |
| 1406 |
break; |
| 1407 |
} |
| 1408 |
case IDC_NAMES: |
| 1409 |
{ |
| 1410 |
if(HIWORD(wParam) == CBN_SELCHANGE) |
| 1411 |
{ |
| 1412 |
LONG_PTR n = SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETCURSEL, 0, 0); |
| 1413 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), CB_ERR != n); |
| 1414 |
} |
| 1415 |
else if(HIWORD(wParam) == CBN_DBLCLK) |
| 1416 |
{ |
| 1417 |
LONG_PTR n = SendDlgItemMessage(hwndDlg, IDC_NAMES, CB_GETCURSEL, 0, 0); |
| 1418 |
if (n != CB_ERR) SendDlgItemMessage(hwndDlg, IDOK, BM_CLICK, 0, 0); |
| 1419 |
} |
| 1420 |
break; |
| 1421 |
} |
| 1422 |
} |
| 1423 |
break; |
| 1424 |
} |
| 1425 |
} |
| 1426 |
return FALSE; |
| 1427 |
} |
| 1428 |
|
| 1429 |
INT_PTR ShowSymbolSetDialog(HWND hwndOwner, BOOL LoadingSet) |
| 1430 |
{ |
| 1431 |
SYMSETDLGDATA dd = { g_ModalDlgData, LoadingSet }; |
| 1432 |
g_ModalDlgData = ⅆ |
| 1433 |
INT_PTR retval = DialogBox(g_sdata.hInstance, MAKEINTRESOURCE(DLG_SYMBOLSET), hwndOwner, API_cast<DLGPROC>(SymbolSetProc)); |
| 1434 |
g_ModalDlgData = dd.pOldMDD; // Restore the old pointer |
| 1435 |
return retval; |
| 1436 |
} |
| 1437 |
|
| 1438 |
void SetCompressor(NCOMPRESSOR compressor) |
| 1439 |
{ |
| 1440 |
int i; |
| 1441 |
|
| 1442 |
if(g_sdata.compressor != compressor) { |
| 1443 |
WORD command; |
| 1444 |
LPCTSTR compressor_name; |
| 1445 |
|
| 1446 |
if(compressor > COMPRESSOR_SCRIPT && compressor < COMPRESSOR_BEST) { |
| 1447 |
command = compressor_commands[(int)compressor]; |
| 1448 |
compressor_name = compressor_names[(int)compressor]; |
| 1449 |
} |
| 1450 |
else if(compressor == COMPRESSOR_BEST) { |
| 1451 |
command = compressor_commands[(int)compressor]; |
| 1452 |
compressor_name = compressor_names[(int)COMPRESSOR_SCRIPT+1]; |
| 1453 |
} |
| 1454 |
else { |
| 1455 |
compressor = COMPRESSOR_SCRIPT; |
| 1456 |
command = IDM_COMPRESSOR_SCRIPT; |
| 1457 |
compressor_name = _T(""); |
| 1458 |
} |
| 1459 |
g_sdata.compressor = compressor; |
| 1460 |
g_sdata.compressor_name = compressor_name; |
| 1461 |
UpdateToolBarCompressorButton(); |
| 1462 |
for(i=(int)COMPRESSOR_SCRIPT; i<= (int)COMPRESSOR_BEST; i++) { |
| 1463 |
CheckMenuItem(g_sdata.menu, compressor_commands[i], MF_BYCOMMAND | MF_UNCHECKED); |
| 1464 |
} |
| 1465 |
CheckMenuItem(g_sdata.menu, command, MF_BYCOMMAND | MF_CHECKED); |
| 1466 |
ResetObjects(); |
| 1467 |
} |
| 1468 |
} |