2008-02-16 17:53:17 +00:00
/*
Copyright ( c ) 2002 Robert Rainwater
Contributors : Justin Frankel , Fritz Elfert , Amir Szekely , Sunil Kamath , Joost Verburg
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 .
2010-03-24 17:22:56 +00:00
Unicode support by Jim Park - - 08 / 18 / 2007
2008-02-16 17:53:17 +00:00
*/
# define MAKENSISW_CPP
# include "makensisw.h"
# include <windowsx.h>
2010-04-12 16:00:17 +00:00
# include <shlwapi.h>
2008-02-16 17:53:17 +00:00
# include <stdio.h>
# include "resource.h"
# include "toolbar.h"
# include "update.h"
2013-03-14 18:00:00 +00:00
namespace MakensisAPI {
2014-06-11 22:01:38 +00:00
# ifdef _WIN64
const TCHAR * SigintEventNameFmt = _T ( " makensis win32 sigint event %Iu " ) ;
# else
2013-03-14 18:00:00 +00:00
const TCHAR * SigintEventNameFmt = _T ( " makensis win32 sigint event %u " ) ;
2014-06-11 22:01:38 +00:00
# endif
2013-03-14 18:00:00 +00:00
const TCHAR * SigintEventNameLegacy = _T ( " makensis win32 signint event " ) ;
}
2008-02-16 17:53:17 +00:00
NSCRIPTDATA g_sdata ;
NRESIZEDATA g_resize ;
NFINDREPLACE g_find ;
2013-05-26 19:47:22 +00:00
TCHAR g_findbuf [ 128 ] ;
2008-02-16 17:53:17 +00:00
extern NTOOLBAR g_toolbar ;
2018-11-04 21:25:52 +00:00
void * g_ModalDlgData ;
2021-01-17 20:57:20 +00:00
BYTE g_MiniCommand = false ;
2008-02-16 17:53:17 +00:00
2012-10-13 01:47:50 +00:00
NSIS_ENTRYPOINT_SIMPLEGUI
int WINAPI _tWinMain ( HINSTANCE hInst , HINSTANCE hOldInst , LPTSTR CmdLineParams , int ShowCmd ) {
2016-03-23 13:42:16 +00:00
2016-03-27 23:24:43 +00:00
// We can be associated with .nsi files and when launched from the shell we inherit the current directory so
// we need to prevent LoadLibrary from searching the current directory because it can contain untrusted DLLs!
2018-11-11 22:05:32 +00:00
FARPROC SDDA = GetSysProcAddr ( " KERNEL32 " , " SetDllDirectoryA " ) ; // WinXP.SP1+
2016-03-23 13:42:16 +00:00
if ( SDDA ) ( ( BOOL ( WINAPI * ) ( LPCSTR ) ) SDDA ) ( " " ) ; // Remove the current directory from the default DLL search order
2018-11-11 22:05:32 +00:00
// Try to register the SysLink class
2021-08-21 22:18:38 +00:00
enum { icc_link_class = 0x8000 } ; // ComCtl32v6
2021-07-27 18:56:42 +00:00
# if (!defined(_MSC_VER) && !defined(_WIN64)) || (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_IA64))) // x86 or Itanium
2021-08-21 22:18:38 +00:00
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
2018-11-11 22:05:32 +00:00
{
FARPROC lwrc = GetSysProcAddr ( " SHELL32 " , ( LPCSTR ) 258 ) ; // LinkWindow_RegisterClass
if ( lwrc ) ( ( BOOL ( WINAPI * ) ( ) ) lwrc ) ( ) ;
WNDCLASS wc ;
if ( GetClassInfo ( NULL , _T ( " Link Window " ) , & wc ) )
{
wc . lpszClassName = _T ( " SysLink " ) ;
RegisterClass ( & wc ) ; // Superclass the old link window class if SysLink is not available
}
}
2021-07-27 18:56:42 +00:00
# endif
2018-11-11 22:05:32 +00:00
2010-04-12 16:00:17 +00:00
memset ( & g_sdata , 0 , sizeof ( NSCRIPTDATA ) ) ;
memset ( & g_resize , 0 , sizeof ( NRESIZEDATA ) ) ;
memset ( & g_find , 0 , sizeof ( NFINDREPLACE ) ) ;
2013-06-08 18:48:38 +00:00
g_sdata . hInstance = hInst ;
2008-02-16 17:53:17 +00:00
g_sdata . symbols = NULL ;
2013-03-14 18:00:00 +00:00
g_sdata . sigint_event_legacy = CreateEvent ( NULL , FALSE , FALSE , MakensisAPI : : SigintEventNameLegacy ) ;
2013-06-08 18:48:38 +00:00
g_sdata . verbosity = ( unsigned char ) ReadRegSettingDW ( REGVERBOSITY , 4 ) ;
if ( g_sdata . verbosity > 4 ) g_sdata . verbosity = 4 ;
2021-09-20 16:48:42 +00:00
g_sdata . log_zoom = 100 ;
2008-02-16 17:53:17 +00:00
RestoreSymbols ( ) ;
2018-11-11 22:05:32 +00:00
LoadSysLibrary ( " RichEd20 " ) ;
2008-02-16 17:53:17 +00:00
if ( ! InitBranding ( ) ) {
2014-10-12 20:09:35 +00:00
MessageBox ( 0 , NSISERROR , ERRBOXTITLE , MB_ICONEXCLAMATION | MB_OK | MB_TASKMODAL ) ;
2008-02-16 17:53:17 +00:00
return 1 ;
}
ResetObjects ( ) ;
2021-01-17 20:57:20 +00:00
HACCEL haccel = LoadAccelerators ( g_sdata . hInstance , MAKEINTRESOURCE ( IDK_ACCEL ) ) ;
2008-02-16 17:53:17 +00:00
HWND hDialog = CreateDialog ( g_sdata . hInstance , MAKEINTRESOURCE ( DLG_MAIN ) , 0 , DialogProc ) ;
2021-01-17 20:57:20 +00:00
if ( ! hDialog & & ! g_MiniCommand ) {
2014-10-12 20:09:35 +00:00
MessageBox ( 0 , DLGERROR , ERRBOXTITLE , MB_ICONEXCLAMATION | MB_OK | MB_TASKMODAL ) ;
2008-02-16 17:53:17 +00:00
return 1 ;
}
2016-03-23 13:42:16 +00:00
MSG msg ;
int status ;
2008-02-16 17:53:17 +00:00
while ( ( status = GetMessage ( & msg , 0 , 0 , 0 ) ) ! = 0 ) {
if ( status = = - 1 ) return - 1 ;
if ( ! IsDialogMessage ( g_find . hwndFind , & msg ) ) {
if ( ! TranslateAccelerator ( hDialog , haccel , & msg ) ) {
if ( ! IsDialogMessage ( hDialog , & msg ) ) {
TranslateMessage ( & msg ) ;
DispatchMessage ( & msg ) ;
}
}
}
}
2013-05-26 19:47:22 +00:00
MemSafeFree ( g_sdata . script ) ;
2008-02-16 17:53:17 +00:00
if ( g_sdata . script_cmd_args ) GlobalFree ( g_sdata . script_cmd_args ) ;
if ( g_sdata . sigint_event ) CloseHandle ( g_sdata . sigint_event ) ;
2013-03-14 18:00:00 +00:00
if ( g_sdata . sigint_event_legacy ) CloseHandle ( g_sdata . sigint_event_legacy ) ;
2014-10-12 20:09:35 +00:00
return ( int ) msg . wParam ;
2008-02-16 17:53:17 +00:00
}
2010-03-24 17:22:56 +00:00
void SetScript ( const TCHAR * script , bool clearArgs /*= true*/ )
2008-02-16 17:53:17 +00:00
{
2013-05-26 19:47:22 +00:00
MemSafeFree ( g_sdata . script ) ;
2008-02-16 17:53:17 +00:00
if ( clearArgs )
{
if ( g_sdata . script_cmd_args )
{
GlobalFree ( g_sdata . script_cmd_args ) ;
}
2010-03-24 17:22:56 +00:00
// Pointing to a single char. Maybe _T('\0')
g_sdata . script_cmd_args = GlobalAlloc ( GHND , sizeof ( TCHAR ) ) ;
2008-02-16 17:53:17 +00:00
}
2013-05-26 19:47:22 +00:00
g_sdata . script = ( TCHAR * ) MemAlloc ( ( lstrlen ( script ) + 1 ) * sizeof ( TCHAR ) ) ;
2008-02-16 17:53:17 +00:00
lstrcpy ( g_sdata . script , script ) ;
}
2015-09-28 16:08:54 +00:00
static void AddScriptCmdArgs ( const TCHAR * arg )
2008-02-16 17:53:17 +00:00
{
g_sdata . script_cmd_args = GlobalReAlloc ( g_sdata . script_cmd_args ,
2010-03-24 17:22:56 +00:00
GlobalSize ( g_sdata . script_cmd_args ) + ( lstrlen ( arg ) + 2 /* quotes */ + 1 /* space */ ) * sizeof ( TCHAR ) ,
2008-02-16 17:53:17 +00:00
0 ) ;
2010-03-24 17:22:56 +00:00
TCHAR * args = ( TCHAR * ) GlobalLock ( g_sdata . script_cmd_args ) ;
2008-02-16 17:53:17 +00:00
2010-03-24 17:22:56 +00:00
lstrcat ( args , _T ( " \" " ) ) ;
2008-02-16 17:53:17 +00:00
lstrcat ( args , arg ) ;
2010-03-24 17:22:56 +00:00
lstrcat ( args , _T ( " \" " ) ) ;
2008-02-16 17:53:17 +00:00
GlobalUnlock ( g_sdata . script_cmd_args ) ;
}
2021-01-17 20:57:20 +00:00
enum { CMD_PICKCOMP = 0x0001 , CMD_SPY = 0x0080 , CMD_LOOKUP = 0x8000 } ;
static UINT ProcessCommandLine ( )
2008-02-16 17:53:17 +00:00
{
2010-03-24 17:22:56 +00:00
TCHAR * * argv ;
2021-01-17 20:57:20 +00:00
int i , j , retflags = 0 ;
2010-04-19 10:06:48 +00:00
int argc = SetArgv ( ( TCHAR * ) GetCommandLine ( ) , & argv ) ;
2008-02-16 17:53:17 +00:00
if ( argc > 1 ) {
for ( i = 1 ; i < argc ; i + + )
{
2021-01-17 20:57:20 +00:00
if ( ! lstrcmpi ( argv [ i ] , _T ( " /Spy " ) ) ) retflags | = CMD_SPY ;
else if ( ! lstrcmpi ( argv [ i ] , _T ( " /Lookup " ) ) ) retflags | = CMD_LOOKUP ;
else if ( ! StrCmpNI ( argv [ i ] , _T ( " /XSetCompressor " ) , COUNTOF ( " /XSetCompressor " ) - ! 0 ) )
2008-02-16 17:53:17 +00:00
{
2021-01-17 20:57:20 +00:00
TCHAR * p = argv [ i ] + lstrlen ( _T ( " /XSetCompressor " ) ) , cchSlashFinalSpace = COUNTOF ( " /FINAL " ) - ! 0 ;
if ( ! StrCmpNI ( p , _T ( " /FINAL " ) , cchSlashFinalSpace ) ) p + = cchSlashFinalSpace ;
2010-03-24 17:22:56 +00:00
while ( * p = = _T ( ' ' ) ) p + + ;
2008-02-16 17:53:17 +00:00
for ( j = ( int ) COMPRESSOR_SCRIPT + 1 ; j < ( int ) COMPRESSOR_BEST ; j + + )
{
if ( ! lstrcmpi ( p , compressor_names [ j ] ) )
{
SetCompressor ( ( NCOMPRESSOR ) j ) ;
}
}
}
2010-03-24 17:22:56 +00:00
else if ( ! lstrcmpi ( argv [ i ] , _T ( " /ChooseCompressor " ) ) )
2008-02-16 17:53:17 +00:00
{
2021-01-17 20:57:20 +00:00
retflags | = CMD_PICKCOMP ;
2008-02-16 17:53:17 +00:00
}
2010-03-24 17:22:56 +00:00
else if ( argv [ i ] [ 0 ] = = _T ( ' - ' ) | | argv [ i ] [ 0 ] = = _T ( ' / ' ) )
2008-02-16 17:53:17 +00:00
{
AddScriptCmdArgs ( argv [ i ] ) ;
}
else
{
SetScript ( argv [ i ] , false ) ;
PushMRUFile ( g_sdata . script ) ;
break ;
}
}
}
2013-05-26 19:47:22 +00:00
MemSafeFree ( argv ) ;
2021-01-17 20:57:20 +00:00
return retflags ;
2008-02-16 17:53:17 +00:00
}
2014-10-12 20:09:35 +00:00
DWORD CALLBACK SaveFileStreamCallback ( DWORD_PTR dwCookie , LPBYTE pbBuff , LONG cb , LONG * pcb )
{
HANDLE hFile = ( HANDLE ) ( ( DWORD_PTR * ) dwCookie ) [ 0 ] ;
DWORD cbio ;
# ifdef UNICODE
if ( ! ( ( DWORD_PTR * ) dwCookie ) [ 1 ] )
{
if ( ! WriteUTF16LEBOM ( hFile ) ) return - 1 ;
( ( DWORD_PTR * ) dwCookie ) [ 1 ] = TRUE ;
}
# endif
BOOL wop = WriteFile ( hFile , pbBuff , cb , & cbio , 0 ) ;
return ( * pcb = ( LONG ) cbio , ! wop ) ;
}
2018-11-06 21:04:37 +00:00
static void ToolBarSizeChanged ( HWND hDlg )
{
RECT r ;
2021-09-20 17:21:35 +00:00
HWND hEd = g_sdata . logwnd ;
2018-11-06 21:04:37 +00:00
GetWindowRect ( g_toolbar . hwnd , & r ) ;
LONG tbh = RectH ( r ) ;
GetWindowRect ( hEd , & r ) ;
LONG oldh = RectH ( r ) , margin = DlgUnitToPixelY ( hDlg , 7 ) , top = tbh + margin ;
POINT pt = { r . left , r . top } ;
ScreenToClient ( hDlg , & pt ) ;
SetWindowPos ( hEd , 0 , pt . x , top , RectW ( r ) , oldh + ( pt . y - top ) , SWP_NOZORDER | SWP_NOACTIVATE ) ; // Update IDC_LOGWIN position and size
}
2019-05-23 21:58:23 +00:00
static BOOL CALLBACK DialogResize ( HWND hWnd , LPARAM param )
2018-11-06 21:04:37 +00:00
{
2019-05-23 21:58:23 +00:00
RECT r , r2 , & dlgrect = * ( RECT * ) param ;
2018-11-06 21:04:37 +00:00
GetWindowRect ( hWnd , & r ) ;
ScreenToClient ( g_sdata . hwnd , ( ( LPPOINT ) & r ) + 0 ) , ScreenToClient ( g_sdata . hwnd , ( ( LPPOINT ) & r ) + 1 ) ;
switch ( GetDlgCtrlID ( hWnd ) )
{
case IDC_TOOLBAR :
GetWindowRect ( hWnd , & r2 ) ;
SetWindowPos ( hWnd , 0 , 0 , 0 , RectW ( r ) + g_resize . dx , RectH ( r2 ) , SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE ) ;
break ;
case IDC_LOGWIN :
2019-05-23 21:58:23 +00:00
if ( ! g_resize . bottompanelsize )
{
r2 . top = 246 , r2 . bottom = 22 + 190 ; // Dialog units from the .rc file
MapDialogRect ( GetParent ( hWnd ) , & r2 ) ;
g_resize . bottompanelsize = r2 . top - r2 . bottom ;
}
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 ) ;
2018-11-06 21:04:37 +00:00
break ;
case IDC_TEST :
case IDCANCEL :
SetWindowPos ( hWnd , 0 , r . left + g_resize . dx , r . top + g_resize . dy , 0 , 0 , SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE ) ;
break ;
default :
SetWindowPos ( hWnd , 0 , r . left , r . top + g_resize . dy , RectW ( r ) + g_resize . dx , RectH ( r ) , SWP_NOZORDER | SWP_NOACTIVATE ) ;
break ;
}
RedrawWindow ( hWnd , NULL , NULL , RDW_INVALIDATE ) ;
return TRUE ;
}
2014-10-12 20:09:35 +00:00
2013-05-26 19:47:22 +00:00
INT_PTR CALLBACK DialogProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam ) {
2008-02-16 17:53:17 +00:00
switch ( msg ) {
case WM_INITDIALOG :
{
2021-09-20 17:21:35 +00:00
g_sdata . hwnd = hwndDlg , g_sdata . logwnd = GetDlgItem ( hwndDlg , IDC_LOGWIN ) ;
2008-02-16 17:53:17 +00:00
HICON hIcon = LoadIcon ( g_sdata . hInstance , MAKEINTRESOURCE ( IDI_ICON ) ) ;
2013-08-07 23:04:23 +00:00
SetClassLongPtr ( hwndDlg , GCLP_HICON , ( LONG_PTR ) hIcon ) ;
2008-02-16 17:53:17 +00:00
// Altered by Darren Owen (DrO) on 29/9/2003
// Added in receiving of mouse and key events from the richedit control
2021-09-20 17:21:35 +00:00
SendMessage ( g_sdata . logwnd , EM_SETEVENTMASK , ( WPARAM ) NULL , ENM_SELCHANGE | ENM_MOUSEEVENTS | ENM_KEYEVENTS ) ;
2021-08-18 23:48:20 +00:00
InitializeLogWindow ( ) ;
2008-02-16 17:53:17 +00:00
g_sdata . menu = GetMenu ( g_sdata . hwnd ) ;
g_sdata . fileSubmenu = FindSubMenu ( g_sdata . menu , IDM_FILE ) ;
g_sdata . editSubmenu = FindSubMenu ( g_sdata . menu , IDM_EDIT ) ;
g_sdata . toolsSubmenu = FindSubMenu ( g_sdata . menu , IDM_TOOLS ) ;
2021-09-20 17:21:35 +00:00
SetMenuDefaultItem ( FindSubMenu ( g_sdata . menu , IDM_SCRIPT ) , IDM_RECOMPILE_TEST , MF_BYCOMMAND ) ;
2008-02-16 17:53:17 +00:00
RestoreMRUList ( ) ;
CreateToolBar ( ) ;
InitTooltips ( g_sdata . hwnd ) ;
2013-05-26 19:47:22 +00:00
SetDlgItemText ( g_sdata . hwnd , IDC_VERSION , g_sdata . branding ) ;
2021-01-01 20:10:26 +00:00
LPCTSTR fontname = _T ( " Courier New " ) , fontconsolas = _T ( " Consolas " ) ;
BYTE fontsize = 8 , fontcharset = DEFAULT_CHARSET , suppwin4 = SupportsWNT4 ( ) | | SupportsW9X ( ) ;
if ( FontExists ( fontconsolas ) )
{
fontname = fontconsolas , + + fontsize ;
}
else if ( SupportsW2000 ( ) & & GetACP ( ) = = 932 ) // According to older Inno, Courier New cannot display Japanese on < WinXP
{
LPCWSTR msgothlocalutf = L " \xff2d \xff33 \xff30 \x30b4 \x30b7 \x30c3 \x30af " ;
const CHAR msgothlocal932 [ ] = { - 126 , ' l ' , - 126 , ' r ' , ' ' , - 125 , ' S ' , - 125 , ' V ' , - 125 , ' b ' , - 125 , ' N ' , ' \0 ' } ;
fontcharset = SHIFTJIS_CHARSET , + + fontsize ;
fontname = _T ( " MS Gothic " ) ; // Win2000 can handle this, downlevel cannot
if ( suppwin4 & & ! FontExists ( fontname ) ) fontname = sizeof ( TCHAR ) > 1 ? ( LPCTSTR ) msgothlocalutf : ( LPCTSTR ) msgothlocal932 ;
}
HFONT hFont = CreateFontPt ( hwndDlg , fontsize , FW_NORMAL , FIXED_PITCH | FF_DONTCARE , fontcharset , fontname ) ;
2021-09-20 17:21:35 +00:00
SendMessage ( g_sdata . logwnd , WM_SETFONT , ( WPARAM ) hFont , 0 ) ;
2008-02-16 17:53:17 +00:00
g_sdata . compressor = COMPRESSOR_NONE_SELECTED ;
2021-01-17 20:57:20 +00:00
SetScript ( _T ( " " ) ) ;
RestoreCompressor ( ) ;
2018-11-06 21:04:37 +00:00
ToolBarSizeChanged ( hwndDlg ) ;
2013-05-26 19:47:22 +00:00
2021-01-17 20:57:20 +00:00
UINT docmd = ProcessCommandLine ( ) ;
if ( ( docmd & ( CMD_SPY | CMD_LOOKUP ) ) )
{
INT_PTR r = ( ( docmd & CMD_LOOKUP ) ? ShowLookupDialog : ShowWndSpy ) ( 0 ) ;
g_sdata . hwnd = NULL ; // Don't save window pos
g_MiniCommand + + ;
return SendMessage ( hwndDlg , WM_CLOSE , r , r ) ;
}
RestoreWindowPos ( g_sdata . hwnd ) ;
2008-02-16 17:53:17 +00:00
if ( g_sdata . compressor = = COMPRESSOR_NONE_SELECTED ) {
SetCompressor ( g_sdata . default_compressor ) ;
}
2021-01-17 20:57:20 +00:00
if ( docmd & CMD_PICKCOMP ) {
2018-11-06 21:04:37 +00:00
if ( DialogBox ( g_sdata . hInstance , MAKEINTRESOURCE ( DLG_COMPRESSOR ) , g_sdata . hwnd , API_cast < DLGPROC > ( CompressorProc ) ) ) {
2008-02-16 17:53:17 +00:00
EnableItems ( g_sdata . hwnd ) ;
return TRUE ;
}
}
CompileNSISScript ( ) ;
return TRUE ;
}
case WM_PAINT :
{
PAINTSTRUCT ps ;
2013-05-26 19:47:22 +00:00
GetGripperPos ( hwndDlg , g_resize . griprect ) ;
HDC hdc = BeginPaint ( hwndDlg , & ps ) ;
2018-10-18 17:45:47 +00:00
DrawGripper ( hwndDlg , hdc , g_resize . griprect ) ;
2013-05-26 19:47:22 +00:00
EndPaint ( hwndDlg , & ps ) ;
2008-02-16 17:53:17 +00:00
return TRUE ;
}
case WM_DESTROY :
{
SaveSymbols ( ) ;
SaveMRUList ( ) ;
SaveWindowPos ( g_sdata . hwnd ) ;
2021-08-18 23:48:20 +00:00
ReleaseLogWindow ( ) ;
2008-02-16 17:53:17 +00:00
ImageList_Destroy ( g_toolbar . imagelist ) ;
ImageList_Destroy ( g_toolbar . imagelistd ) ;
ImageList_Destroy ( g_toolbar . imagelisth ) ;
DestroyTooltips ( ) ;
PostQuitMessage ( 0 ) ;
return TRUE ;
}
2021-01-17 20:57:20 +00:00
case WM_CLOSE : tryquitapp :
2008-02-16 17:53:17 +00:00
{
if ( ! g_sdata . thread ) {
DestroyWindow ( hwndDlg ) ;
2021-01-17 20:57:20 +00:00
PostQuitMessage ( ( int ) wParam ) ;
2008-02-16 17:53:17 +00:00
}
return TRUE ;
}
case WM_DROPFILES : {
int num ;
2010-03-24 17:22:56 +00:00
TCHAR szTmp [ MAX_PATH ] ;
2008-02-16 17:53:17 +00:00
num = DragQueryFile ( ( HDROP ) wParam , ( UINT ) - 1 , NULL , 0 ) ;
if ( num = = 1 ) {
DragQueryFile ( ( HDROP ) wParam , 0 , szTmp , MAX_PATH ) ;
2015-10-30 03:55:30 +00:00
if ( szTmp [ 0 ] ) {
2008-02-16 17:53:17 +00:00
SetScript ( szTmp ) ;
PushMRUFile ( g_sdata . script ) ;
ResetObjects ( ) ;
CompileNSISScript ( ) ;
}
} else {
2013-05-26 19:47:22 +00:00
MessageBox ( hwndDlg , MULTIDROPERROR , ERRBOXTITLE , MB_OK | MB_ICONSTOP ) ;
2008-02-16 17:53:17 +00:00
}
DragFinish ( ( HDROP ) wParam ) ;
break ;
}
case WM_GETMINMAXINFO :
{
( ( MINMAXINFO * ) lParam ) - > ptMinTrackSize . x = MINWIDTH ;
( ( MINMAXINFO * ) lParam ) - > ptMinTrackSize . y = MINHEIGHT ;
}
case WM_ENTERSIZEMOVE :
{
GetClientRect ( g_sdata . hwnd , & g_resize . resizeRect ) ;
2010-03-24 17:22:56 +00:00
return TRUE ;
2008-02-16 17:53:17 +00:00
}
case WM_SIZE :
{
2018-11-06 21:04:37 +00:00
if ( wParam = = SIZE_MAXHIDE | | wParam = = SIZE_MAXSHOW ) return TRUE ;
const LONG oldW = g_resize . resizeRect . right , oldH = g_resize . resizeRect . bottom ;
GetClientRect ( hwndDlg , & g_resize . resizeRect ) ;
g_resize . dx = g_resize . resizeRect . right - oldW ;
g_resize . dy = g_resize . resizeRect . bottom - oldH ;
2019-05-23 21:58:23 +00:00
EnumChildWindows ( g_sdata . hwnd , DialogResize , ( LPARAM ) & g_resize . resizeRect ) ;
2008-02-16 17:53:17 +00:00
return TRUE ;
}
case WM_SIZING :
{
2013-05-26 19:47:22 +00:00
InvalidateRect ( hwndDlg , & g_resize . griprect , TRUE ) ;
GetGripperPos ( hwndDlg , g_resize . griprect ) ;
2008-02-16 17:53:17 +00:00
return TRUE ;
}
2013-05-26 19:47:22 +00:00
case WM_NCHITTEST :
{
RECT r = g_resize . griprect ;
MapWindowPoints ( hwndDlg , 0 , ( POINT * ) & r , 2 ) ;
2018-11-06 21:04:37 +00:00
POINT pt = { GET_X_LPARAM ( lParam ) , GET_Y_LPARAM ( lParam ) } ;
2013-05-26 19:47:22 +00:00
if ( PtInRect ( & r , pt ) )
{
SetWindowLongPtr ( hwndDlg , DWLP_MSGRESULT , HTBOTTOMRIGHT ) ;
return TRUE ;
}
return FALSE ;
}
2008-02-16 17:53:17 +00:00
case WM_MAKENSIS_PROCESSCOMPLETE :
{
if ( g_sdata . thread ) {
CloseHandle ( g_sdata . thread ) ;
g_sdata . thread = 0 ;
}
if ( g_sdata . compressor = = COMPRESSOR_BEST ) {
if ( g_sdata . retcode = = 0 & & FileExists ( g_sdata . output_exe ) ) {
2013-08-07 19:26:03 +00:00
TCHAR temp_file_name [ 1024 ] ; // BUGBUG: Hardcoded buffer size
2010-03-24 17:22:56 +00:00
wsprintf ( temp_file_name , _T ( " %s_makensisw_temp " ) , g_sdata . output_exe ) ;
2008-02-16 17:53:17 +00:00
if ( ! lstrcmpi ( g_sdata . compressor_name , compressor_names [ ( int ) COMPRESSOR_SCRIPT + 1 ] ) ) {
SetCompressorStats ( ) ;
CopyFile ( g_sdata . output_exe , temp_file_name , false ) ;
g_sdata . best_compressor_name = g_sdata . compressor_name ;
g_sdata . compressor_name = compressor_names [ ( int ) COMPRESSOR_SCRIPT + 2 ] ;
ResetObjects ( ) ;
CompileNSISScript ( ) ;
return TRUE ;
}
else {
2014-10-23 15:34:10 +00:00
int this_compressor = 0 , i ;
2008-02-16 17:53:17 +00:00
HANDLE hPrev , hThis ;
DWORD prevSize = 0 , thisSize = 0 ;
for ( i = ( int ) COMPRESSOR_SCRIPT + 2 ; i < ( int ) COMPRESSOR_BEST ; i + + ) {
if ( ! lstrcmpi ( g_sdata . compressor_name , compressor_names [ i ] ) ) {
this_compressor = i ;
break ;
}
}
if ( FileExists ( temp_file_name ) ) {
hPrev = CreateFile ( temp_file_name , GENERIC_READ , FILE_SHARE_READ ,
2014-10-23 15:34:10 +00:00
NULL , OPEN_EXISTING , 0 , NULL ) ;
2008-02-16 17:53:17 +00:00
if ( hPrev ! = INVALID_HANDLE_VALUE ) {
prevSize = GetFileSize ( hPrev , 0 ) ;
CloseHandle ( hPrev ) ;
if ( prevSize ! = INVALID_FILE_SIZE ) {
hThis = CreateFile ( g_sdata . output_exe , GENERIC_READ , FILE_SHARE_READ ,
2014-10-23 15:34:10 +00:00
NULL , OPEN_EXISTING , 0 , NULL ) ;
2008-02-16 17:53:17 +00:00
if ( hThis ! = INVALID_HANDLE_VALUE ) {
thisSize = GetFileSize ( hThis , 0 ) ;
CloseHandle ( hThis ) ;
if ( thisSize ! = INVALID_FILE_SIZE ) {
if ( prevSize > thisSize ) {
CopyFile ( g_sdata . output_exe , temp_file_name , false ) ;
SetCompressorStats ( ) ;
g_sdata . best_compressor_name = g_sdata . compressor_name ;
}
}
}
}
}
}
if ( this_compressor = = ( ( int ) COMPRESSOR_BEST - 1 ) ) {
2010-03-24 17:22:56 +00:00
TCHAR buf [ 1024 ] ;
2008-02-16 17:53:17 +00:00
g_sdata . compressor_name = compressor_names [ ( int ) COMPRESSOR_SCRIPT + 1 ] ;
if ( ! lstrcmpi ( g_sdata . best_compressor_name , compressor_names [ this_compressor ] ) ) {
wsprintf ( buf , COMPRESSOR_MESSAGE , g_sdata . best_compressor_name , thisSize ) ;
LogMessage ( g_sdata . hwnd , buf ) ;
}
else {
CopyFile ( temp_file_name , g_sdata . output_exe , false ) ;
wsprintf ( buf , RESTORED_COMPRESSOR_MESSAGE , g_sdata . best_compressor_name , prevSize ) ;
LogMessage ( g_sdata . hwnd , buf ) ;
LogMessage ( g_sdata . hwnd , g_sdata . compressor_stats ) ;
}
DeleteFile ( temp_file_name ) ;
2014-05-19 22:03:09 +00:00
g_sdata . compressor_stats [ 0 ] = _T ( ' \0 ' ) ;
2008-02-16 17:53:17 +00:00
}
else {
g_sdata . compressor_name = compressor_names [ this_compressor + 1 ] ;
ResetObjects ( ) ;
CompileNSISScript ( ) ;
return TRUE ;
}
}
}
}
EnableItems ( g_sdata . hwnd ) ;
if ( ! g_sdata . retcode ) {
2019-10-13 16:49:35 +00:00
if ( g_sdata . warnings ) {
2010-03-24 17:22:56 +00:00
SetTitle ( g_sdata . hwnd , _T ( " Finished with Warnings " ) ) ;
2019-10-13 16:49:35 +00:00
PlayAppSoundAsync ( ( " BuildWarning " ) , MB_ICONWARNING ) ;
SetLogColor ( LC_WARNING ) ;
}
else {
2010-03-24 17:22:56 +00:00
SetTitle ( g_sdata . hwnd , _T ( " Finished Sucessfully " ) ) ;
2019-10-13 16:49:35 +00:00
PlayAppSoundAsync ( ( " BuildComplete " ) , MB_ICONASTERISK ) ;
SetLogColor ( LC_SUCCESS ) ;
}
2008-02-16 17:53:17 +00:00
// 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 {
2010-03-24 17:22:56 +00:00
SetTitle ( g_sdata . hwnd , _T ( " Compile Error: See Log for Details " ) ) ;
2019-10-13 16:49:35 +00:00
PlayAppSoundAsync ( ( " BuildError " ) , MB_ICONEXCLAMATION ) ;
SetLogColor ( LC_ERROR ) ;
2008-02-16 17:53:17 +00:00
}
// Added by Darren Owen (DrO) on 1/10/2003
// ensures the recompile and run state is reset after use
g_sdata . recompile_test = 0 ;
DragAcceptFiles ( g_sdata . hwnd , TRUE ) ;
return TRUE ;
}
2013-05-04 13:32:47 +00:00
case MakensisAPI : : QUERYHOST : {
2014-10-22 16:49:45 +00:00
if ( MakensisAPI : : QH_OUTPUTCHARSET = = wParam ) {
2013-05-28 20:07:47 +00:00
const UINT reqcp = 1200 ; // We want UTF-16LE
2020-04-20 17:21:04 +00:00
return DlgRet ( hwndDlg , ( LONG_PTR ) ( 1 + reqcp ) ) ;
2013-05-04 13:32:47 +00:00
}
2020-04-20 17:21:04 +00:00
else if ( MakensisAPI : : QH_SUPPORTEDVERSION = = wParam )
return DlgRet ( hwndDlg , 0x03006000 ) ;
2013-05-04 13:32:47 +00:00
return FALSE ;
}
2008-02-16 17:53:17 +00:00
case WM_NOTIFY :
switch ( ( ( NMHDR * ) lParam ) - > code ) {
case EN_SELCHANGE :
2021-09-20 17:21:35 +00:00
EnableMenuItem ( g_sdata . menu , IDM_COPYSELECTED , RicheditHasSelection ( g_sdata . logwnd ) ? MF_ENABLED : MF_GRAYED ) ;
2018-11-07 00:26:29 +00:00
break ;
2008-02-16 17:53:17 +00:00
// Altered by Darren Owen (DrO) on 6/10/2003
// Allows the detection of the right-click menu when running on OSes below Windows 2000
// and will then simulate the effective WM_CONTEXTMENU message that would be received
// note: removed the WM_CONTEXTMENU handling to prevent a duplicate menu appearing on
// Windows 2000 and higher
case EN_MSGFILTER :
# define lpnmMsg ((MSGFILTER*)lParam)
2018-11-07 00:26:29 +00:00
if ( WM_RBUTTONUP = = lpnmMsg - > msg | | ( WM_KEYUP = = lpnmMsg - > msg & & lpnmMsg - > wParam = = VK_APPS ) )
{
POINT pt ;
2021-09-20 17:21:35 +00:00
HWND edit = g_sdata . logwnd ;
2018-11-07 00:26:29 +00:00
RECT r ;
2008-02-16 17:53:17 +00:00
GetCursorPos ( & pt ) ;
// Added and altered by Darren Owen (DrO) on 29/9/2003
// Will place the right-click menu in the top left corner of the window
// if the application key is pressed and the mouse is not in the window
// from here...
ScreenToClient ( edit , & pt ) ;
GetClientRect ( edit , & r ) ;
2018-11-07 00:26:29 +00:00
if ( ! PtInRect ( & r , pt ) ) pt . x = pt . y = 0 ;
2008-02-16 17:53:17 +00:00
MapWindowPoints ( edit , HWND_DESKTOP , & pt , 1 ) ;
2021-08-18 16:38:26 +00:00
TrackPopupMenu ( g_sdata . editSubmenu , GetMenuDropAlignment ( ) | TPM_LEFTBUTTON | TPM_RIGHTBUTTON , pt . x , pt . y , 0 , g_sdata . hwnd , 0 ) ;
2008-02-16 17:53:17 +00:00
}
2018-11-07 00:26:29 +00:00
break ;
2008-02-16 17:53:17 +00:00
case TBN_DROPDOWN :
{
LPNMTOOLBAR pToolBar = ( LPNMTOOLBAR ) lParam ;
2018-10-21 12:28:10 +00:00
if ( pToolBar - > hdr . hwndFrom = = g_toolbar . hwnd & & pToolBar - > iItem = = IDM_COMPRESSOR ) {
ShowCompressorToolbarDropdownMenu ( * pToolBar ) ;
2008-02-16 17:53:17 +00:00
return TBDDRET_DEFAULT ;
}
2018-10-21 12:28:10 +00:00
return TBDDRET_NODEFAULT ;
2008-02-16 17:53:17 +00:00
}
}
return TRUE ;
case WM_COPYDATA :
{
2020-04-20 17:21:04 +00:00
using namespace MakensisAPI ;
COPYDATASTRUCT * cds = ( COPYDATASTRUCT * ) lParam , cdsret ;
2008-02-16 17:53:17 +00:00
switch ( cds - > dwData ) {
2013-03-14 18:00:00 +00:00
case MakensisAPI : : NOTIFY_SCRIPT :
2013-05-26 19:47:22 +00:00
MemSafeFree ( g_sdata . input_script ) ;
2018-11-07 00:26:29 +00:00
if ( ( g_sdata . input_script = ( TCHAR * ) MemAlloc ( cds - > cbData * sizeof ( TCHAR ) ) ) )
lstrcpy ( g_sdata . input_script , ( TCHAR * ) cds - > lpData ) ;
EnableUICommand ( IDM_BROWSESCR , ! ! g_sdata . input_script ) ;
2008-02-16 17:53:17 +00:00
break ;
2013-03-14 18:00:00 +00:00
case MakensisAPI : : NOTIFY_WARNING :
2008-02-16 17:53:17 +00:00
g_sdata . warnings + + ;
break ;
2013-03-14 18:00:00 +00:00
case MakensisAPI : : NOTIFY_ERROR :
2008-02-16 17:53:17 +00:00
break ;
2013-03-14 18:00:00 +00:00
case MakensisAPI : : NOTIFY_OUTPUT :
2013-05-26 19:47:22 +00:00
MemSafeFree ( g_sdata . output_exe ) ;
g_sdata . output_exe = ( TCHAR * ) MemAlloc ( cds - > cbData * sizeof ( TCHAR ) ) ;
2010-03-24 17:22:56 +00:00
lstrcpy ( g_sdata . output_exe , ( TCHAR * ) cds - > lpData ) ;
2008-02-16 17:53:17 +00:00
break ;
2020-04-20 17:21:04 +00:00
case MakensisAPI : : PROMPT_FILEPATH :
if ( ( ( ( PROMPT_FILEPATH_DATA * ) cds - > lpData ) - > Platform & 7 ) = = sizeof ( TCHAR ) )
{
TCHAR buf [ MAX_PATH ] ;
lstrcpyn ( buf , FSPath : : FindLastComponent ( ( ( PROMPT_FILEPATH_DATA * ) cds - > lpData ) - > Path ) , COUNTOF ( buf ) ) ;
2021-08-20 14:56:26 +00:00
OPENFILENAME of = { SizeOfStruct ( of ) } ;
2020-04-20 17:21:04 +00:00
of . hwndOwner = hwndDlg ;
of . lpstrFilter = _T ( " *.exe \0 *.exe \0 * \0 *.* \0 " ) ;
of . lpstrFile = buf , of . nMaxFile = COUNTOF ( buf ) ;
of . Flags = OFN_EXPLORER | OFN_ENABLESIZING | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR ;
if ( GetSaveFileName ( & of ) )
{
cdsret . dwData = cds - > dwData , cdsret . cbData = ( lstrlen ( buf ) + 1 ) * sizeof ( TCHAR ) , cdsret . lpData = buf ;
SendMessage ( ( HWND ) wParam , WM_COPYDATA , ( SIZE_T ) hwndDlg , ( SIZE_T ) & cdsret ) ;
}
return TRUE ;
}
return FALSE ;
2008-02-16 17:53:17 +00:00
}
return TRUE ;
}
2018-11-07 00:26:29 +00:00
case WM_INITMENU :
EnableMenuItem ( g_sdata . menu , IDM_CANCEL , g_sdata . thread ? MF_ENABLED : MF_GRAYED ) ;
break ;
case WM_MAKENSIS_UPDATEUISTATE :
{
2021-09-20 17:21:35 +00:00
UINT i , emptylog = SendMessage ( g_sdata . logwnd , WM_GETTEXTLENGTH , 0 , 0 ) = = 0 ;
2018-11-07 00:26:29 +00:00
static const PACKEDCMDID_T nonemptylogids [ ] = { PACKCMDID ( IDM_COPY ) , PACKCMDID ( IDM_COPYALL ) , PACKCMDID ( IDM_CLEARLOG ) , PACKCMDID ( IDM_SELECTALL ) } ;
for ( i = 0 ; i < COUNTOF ( nonemptylogids ) ; + + i ) EnableUICommand ( UNPACKCMDID ( nonemptylogids [ i ] ) , ! emptylog ) ;
EnableUICommand ( IDM_BROWSESCR , ! ! g_sdata . input_script ) ;
break ;
}
2021-08-26 17:09:42 +00:00
case WM_MAKENSIS_FREEZEEDITOR :
2021-09-01 18:58:53 +00:00
RicheditFreeze ( g_sdata . pLogTextDoc , lParam ) ;
2021-08-26 17:09:42 +00:00
break ;
2021-08-20 11:46:56 +00:00
case WM_TIMER :
{
HWND hCtl ;
switch ( wParam ) {
case TID_CONFIGURECLOSEORABORT :
SendMessage ( hCtl = GetDlgItem ( hwndDlg , IDCANCEL ) , WM_SETTEXT , 0 , ( LPARAM ) ( g_sdata . thread ? _T ( " &Abort " ) : _T ( " &Close " ) ) ) ;
EnableWindow ( hCtl , true ) ;
2021-08-20 14:56:26 +00:00
UpdateCloseButtonTooltip ( ) ;
2021-08-20 11:46:56 +00:00
return KillTimer ( hwndDlg , wParam ) ;
}
break ;
}
2008-02-16 17:53:17 +00:00
case WM_COMMAND :
{
switch ( LOWORD ( wParam ) ) {
2019-10-23 02:50:39 +00:00
case IDM_UI_SWITCHSECTION : //devblogs.microsoft.com/oldnewthing/20191022-00/?p=103016
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
break ;
2008-02-16 17:53:17 +00:00
case IDM_BROWSESCR : {
if ( g_sdata . input_script ) {
2010-03-24 17:22:56 +00:00
TCHAR str [ MAX_PATH ] , * str2 ;
2008-02-16 17:53:17 +00:00
lstrcpy ( str , g_sdata . input_script ) ;
2010-04-12 16:00:17 +00:00
str2 = _tcsrchr ( str , _T ( ' \\ ' ) ) ;
2008-02-16 17:53:17 +00:00
if ( str2 ! = NULL ) * ( str2 + 1 ) = 0 ;
2010-03-24 17:22:56 +00:00
ShellExecute ( g_sdata . hwnd , _T ( " open " ) , str , NULL , NULL , SW_SHOWNORMAL ) ;
2008-02-16 17:53:17 +00:00
}
return TRUE ;
}
2018-11-04 21:25:52 +00:00
case IDM_DOCS : return ( ShowDocs ( ) , TRUE ) ;
case IDM_NSISHOME : return OpenUrlInDefaultBrowser ( g_sdata . hwnd , NSIS_URL ) ;
case IDM_FORUM : return OpenUrlInDefaultBrowser ( g_sdata . hwnd , NSIS_FORUM_URL ) ;
case IDM_NSISUPDATE : return ( CheckForUpdate ( ) , TRUE ) ;
case IDM_ABOUT : return ShowAboutDialog ( hwndDlg ) | TRUE ;
2008-02-16 17:53:17 +00:00
case IDM_SELECTALL :
{
2021-09-20 17:21:35 +00:00
SendMessage ( g_sdata . logwnd , EM_SETSEL , 0 , - 1 ) ;
2008-02-16 17:53:17 +00:00
return TRUE ;
}
case IDM_LOADSCRIPT :
{
if ( ! g_sdata . thread ) {
2021-08-20 14:56:26 +00:00
OPENFILENAME l = { SizeOfStruct ( l ) } ;
2010-03-24 17:22:56 +00:00
TCHAR buf [ MAX_PATH ] ;
2008-02-16 17:53:17 +00:00
l . hwndOwner = hwndDlg ;
2010-03-24 17:22:56 +00:00
l . lpstrFilter = _T ( " NSIS Script (*.nsi) \0 *.nsi \0 All Files (*.*) \0 *.* \0 " ) ;
2008-02-16 17:53:17 +00:00
l . lpstrFile = buf ;
l . nMaxFile = MAX_STRING - 1 ;
2010-03-24 17:22:56 +00:00
l . lpstrTitle = _T ( " Load Script " ) ;
l . lpstrDefExt = _T ( " log " ) ;
2008-02-16 17:53:17 +00:00
l . Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST ;
2014-05-19 22:03:09 +00:00
buf [ 0 ] = _T ( ' \0 ' ) ;
2008-02-16 17:53:17 +00:00
if ( GetOpenFileName ( & l ) ) {
SetScript ( buf ) ;
PushMRUFile ( g_sdata . script ) ;
ResetObjects ( ) ;
CompileNSISScript ( ) ;
}
}
return TRUE ;
}
case IDM_MRU_FILE :
case IDM_MRU_FILE + 1 :
case IDM_MRU_FILE + 2 :
case IDM_MRU_FILE + 3 :
case IDM_MRU_FILE + 4 :
LoadMRUFile ( LOWORD ( wParam ) - IDM_MRU_FILE ) ;
return TRUE ;
case IDM_CLEAR_MRU_LIST :
ClearMRUList ( ) ;
return TRUE ;
case IDM_COMPRESSOR :
{
SetCompressor ( ( NCOMPRESSOR ) ( g_sdata . compressor + 1 ) ) ;
return TRUE ;
}
case IDM_CLEARLOG :
{
if ( ! g_sdata . thread ) {
2021-09-20 17:21:35 +00:00
ClearLog ( ) ;
2008-02-16 17:53:17 +00:00
}
return TRUE ;
}
2021-09-20 16:48:42 +00:00
case IDM_ZOOM_INC : g_sdata . log_zoom + = 25 ; goto set_log_zoom ;
case IDM_ZOOM_DEC : g_sdata . log_zoom - = 25 ; goto set_log_zoom ;
case IDM_ZOOM_RST :
g_sdata . log_zoom = 100 ; set_log_zoom :
2021-09-20 17:21:35 +00:00
SendMessage ( g_sdata . logwnd , EM_SETZOOM , g_sdata . log_zoom = STD_MAX ( ( int ) g_sdata . log_zoom , 25 ) , 100 ) ;
InvalidateRect ( g_sdata . logwnd , 0 , false ) ;
2021-09-20 16:48:42 +00:00
break ;
2008-02-16 17:53:17 +00:00
case IDM_RECOMPILE :
{
CompileNSISScript ( ) ;
return TRUE ;
}
// Added by Darren Owen (DrO) on 1/10/2003
case IDM_RECOMPILE_TEST :
{
g_sdata . recompile_test = 1 ;
CompileNSISScript ( ) ;
return TRUE ;
}
case IDM_SETTINGS :
{
2018-11-06 21:04:37 +00:00
DialogBox ( g_sdata . hInstance , MAKEINTRESOURCE ( DLG_SETTINGS ) , g_sdata . hwnd , API_cast < DLGPROC > ( SettingsProc ) ) ;
2008-02-16 17:53:17 +00:00
return TRUE ;
}
2021-01-17 20:57:20 +00:00
case IDM_WNDSPY : return ShowWndSpy ( hwndDlg ) ;
case IDM_LOOKUP : return ShowLookupDialog ( hwndDlg ) ;
2020-04-21 18:53:55 +00:00
case IDM_GUIDGEN :
{
GUID guid ;
TCHAR buf [ 41 * ( 1 + ( sizeof ( TCHAR ) < 2 ) ) ] ;
FARPROC func = GetKeyState ( VK_CONTROL ) < 0 ? GetSysProcAddr ( " RPCRT4 " , " UuidCreateSequential " ) : NULL ;
( ( HRESULT ( WINAPI * ) ( GUID * ) ) ( func ? func : GetSysProcAddr ( " RPCRT4 " , " UuidCreate " ) ) ) ( & guid ) ;
( ( int ( WINAPI * ) ( GUID * , TCHAR * , int ) ) ( GetSysProcAddr ( " OLE32 " , " StringFromGUID2 " ) ) ) ( & guid , buf , 39 ) ;
for ( UINT i = 0 ; sizeof ( TCHAR ) < 2 ; + + i ) if ( ! ( buf [ i ] = ( CHAR ) ( ( WCHAR * ) buf ) [ i ] ) ) break ; // WCHAR to TCHAR if ANSI
LogMessage ( g_sdata . hwnd , ( buf [ 38 ] = ' \r ' , buf [ 39 ] = ' \n ' , buf [ 40 ] = ' \0 ' , buf ) ) ;
2021-09-20 16:48:42 +00:00
SendMessage ( g_sdata . hwnd , WM_MAKENSIS_UPDATEUISTATE , 0 , 0 ) ; // Update clear log command state
2020-04-21 18:53:55 +00:00
break ;
}
2008-02-16 17:53:17 +00:00
case IDM_TEST :
case IDC_TEST :
{
if ( g_sdata . output_exe ) {
2010-03-24 17:22:56 +00:00
ShellExecute ( g_sdata . hwnd , _T ( " open " ) , g_sdata . output_exe , NULL , NULL , SW_SHOWNORMAL ) ;
2008-02-16 17:53:17 +00:00
}
return TRUE ;
}
case IDM_EDITSCRIPT :
{
if ( g_sdata . input_script ) {
2014-02-08 00:13:52 +00:00
LPCTSTR verb = _T ( " open " ) ; // BUGBUG: Should not force the open verb?
HINSTANCE hi = ShellExecute ( g_sdata . hwnd , verb , g_sdata . input_script , NULL , NULL , SW_SHOWNORMAL ) ;
if ( ( UINT_PTR ) hi < = 32 ) {
2010-03-24 17:22:56 +00:00
TCHAR path [ MAX_PATH ] ;
2008-02-16 17:53:17 +00:00
if ( GetWindowsDirectory ( path , sizeof ( path ) ) ) {
2010-03-24 17:22:56 +00:00
lstrcat ( path , _T ( " \\ notepad.exe " ) ) ;
2014-02-08 00:13:52 +00:00
ShellExecute ( g_sdata . hwnd , verb , path , g_sdata . input_script , NULL , SW_SHOWNORMAL ) ;
2008-02-16 17:53:17 +00:00
}
}
}
return TRUE ;
}
case IDCANCEL :
2021-08-20 11:46:56 +00:00
if ( g_sdata . thread )
return PostMessage ( hwndDlg , WM_COMMAND , IDM_CANCEL , 0 ) ;
2008-02-16 17:53:17 +00:00
case IDM_EXIT :
2021-01-17 20:57:20 +00:00
wParam = 0 ;
goto tryquitapp ;
2008-02-16 17:53:17 +00:00
case IDM_CANCEL :
{
SetEvent ( g_sdata . sigint_event ) ;
2013-03-14 18:00:00 +00:00
SetEvent ( g_sdata . sigint_event_legacy ) ;
2008-02-16 17:53:17 +00:00
return TRUE ;
}
case IDM_COPY :
2021-09-20 17:21:35 +00:00
if ( RicheditHasSelection ( g_sdata . logwnd ) ) goto logwndcopysel ;
2018-11-07 00:26:29 +00:00
// fall through
case IDM_COPYALL :
2008-02-16 17:53:17 +00:00
CopyToClipboard ( g_sdata . hwnd ) ;
return TRUE ;
2018-11-07 00:26:29 +00:00
case IDM_COPYSELECTED : logwndcopysel :
2021-09-20 17:21:35 +00:00
SendMessage ( g_sdata . logwnd , WM_COPY , 0 , 0 ) ;
2008-02-16 17:53:17 +00:00
return TRUE ;
case IDM_SAVE :
{
2021-08-20 14:56:26 +00:00
OPENFILENAME l = { SizeOfStruct ( l ) } ;
2010-03-24 17:22:56 +00:00
TCHAR buf [ MAX_STRING ] ;
2008-02-16 17:53:17 +00:00
l . hwndOwner = hwndDlg ;
2010-03-24 17:22:56 +00:00
l . lpstrFilter = _T ( " Log Files (*.log) \0 *.log \0 Text Files (*.txt) \0 *.txt \0 All Files (*.*) \0 *.* \0 " ) ;
2008-02-16 17:53:17 +00:00
l . lpstrFile = buf ;
l . nMaxFile = MAX_STRING - 1 ;
2010-03-24 17:22:56 +00:00
l . lpstrTitle = _T ( " Save Output " ) ;
l . lpstrDefExt = _T ( " log " ) ;
2008-02-16 17:53:17 +00:00
l . lpstrInitialDir = NULL ;
l . Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_PATHMUSTEXIST ;
2010-03-24 17:22:56 +00:00
lstrcpy ( buf , _T ( " output " ) ) ;
2008-02-16 17:53:17 +00:00
if ( GetSaveFileName ( & l ) ) {
2014-10-12 20:09:35 +00:00
HANDLE hFile = CreateFile ( buf , GENERIC_WRITE , 0 , 0 , CREATE_ALWAYS , 0 , 0 ) ;
if ( INVALID_HANDLE_VALUE ! = hFile ) { // BUGBUG:TODO: Error message for bad hFile or failed EM_STREAMOUT?
WPARAM opts = sizeof ( TCHAR ) > 1 ? ( SF_TEXT | SF_UNICODE ) : ( SF_TEXT ) ;
DWORD_PTR cookie [ 2 ] = { ( DWORD_PTR ) hFile , FALSE } ;
EDITSTREAM es = { ( DWORD_PTR ) & cookie , 0 , SaveFileStreamCallback } ;
2021-09-20 17:21:35 +00:00
SendMessage ( g_sdata . logwnd , EM_STREAMOUT , opts , ( LPARAM ) & es ) ;
2008-02-16 17:53:17 +00:00
CloseHandle ( hFile ) ;
}
}
return TRUE ;
}
case IDM_FIND :
{
2019-10-23 02:50:39 +00:00
bool reuseWindow = true ;
2008-02-16 17:53:17 +00:00
if ( ! g_find . uFindReplaceMsg ) g_find . uFindReplaceMsg = RegisterWindowMessage ( FINDMSGSTRING ) ;
2010-04-12 16:00:17 +00:00
memset ( & g_find . fr , 0 , sizeof ( FINDREPLACE ) ) ;
2008-02-16 17:53:17 +00:00
g_find . fr . lStructSize = sizeof ( FINDREPLACE ) ;
g_find . fr . hwndOwner = hwndDlg ;
g_find . fr . Flags = FR_NOUPDOWN ;
2013-05-26 19:47:22 +00:00
g_find . fr . lpstrFindWhat = g_findbuf ;
g_find . fr . wFindWhatLen = COUNTOF ( g_findbuf ) ;
2019-10-23 02:50:39 +00:00
if ( ! reuseWindow | | ! SetForegroundWindow ( g_find . hwndFind ) )
g_find . hwndFind = FindText ( & g_find . fr ) ;
2008-02-16 17:53:17 +00:00
return TRUE ;
}
default :
{
int i ;
DWORD command = LOWORD ( wParam ) ;
for ( i = ( int ) COMPRESSOR_SCRIPT ; i < = ( int ) COMPRESSOR_BEST ; i + + ) {
if ( command = = compressor_commands [ i ] ) {
SetCompressor ( ( NCOMPRESSOR ) i ) ;
return TRUE ;
}
}
}
}
}
}
2019-10-23 02:50:39 +00:00
if ( msg = = g_find . uFindReplaceMsg & & msg ) {
2008-02-16 17:53:17 +00:00
LPFINDREPLACE lpfr = ( LPFINDREPLACE ) lParam ;
if ( lpfr - > Flags & FR_FINDNEXT ) {
WPARAM flags = FR_DOWN ;
if ( lpfr - > Flags & FR_MATCHCASE ) flags | = FR_MATCHCASE ;
if ( lpfr - > Flags & FR_WHOLEWORD ) flags | = FR_WHOLEWORD ;
FINDTEXTEX ft ;
2021-09-20 17:21:35 +00:00
SendMessage ( g_sdata . logwnd , EM_EXGETSEL , 0 , ( LPARAM ) & ft . chrg ) ;
2014-10-12 20:09:35 +00:00
ft . chrg . cpMin = ( ft . chrg . cpMax = = ft . chrg . cpMin ) ? 0 : ft . chrg . cpMax ;
2021-09-20 17:21:35 +00:00
ft . chrg . cpMax = ( LONG ) SendMessage ( g_sdata . logwnd , WM_GETTEXTLENGTH , 0 , 0 ) ;
2008-02-16 17:53:17 +00:00
ft . lpstrText = lpfr - > lpstrFindWhat ;
2021-09-20 17:21:35 +00:00
ft . chrg . cpMin = ( LONG ) SendMessage ( g_sdata . logwnd , EM_FINDTEXTEX , flags , ( LPARAM ) & ft ) ;
2014-10-12 20:09:35 +00:00
if ( ft . chrg . cpMin ! = - 1 )
2021-09-20 17:21:35 +00:00
SendMessage ( g_sdata . logwnd , EM_SETSEL , ft . chrgText . cpMin , ft . chrgText . cpMax ) ;
2014-10-12 20:09:35 +00:00
else
MessageBeep ( MB_ICONASTERISK ) ;
2008-02-16 17:53:17 +00:00
}
if ( lpfr - > Flags & FR_DIALOGTERM ) g_find . hwndFind = 0 ;
return TRUE ;
}
return 0 ;
}
2013-05-28 20:07:47 +00:00
DWORD WINAPI MakeNSISProc ( LPVOID TreadParam ) {
2013-03-14 18:00:00 +00:00
TCHAR eventnamebuf [ 100 ] ;
2013-05-04 13:32:47 +00:00
wsprintf ( eventnamebuf , MakensisAPI : : SigintEventNameFmt , g_sdata . hwnd ) ;
2013-03-14 18:00:00 +00:00
if ( g_sdata . sigint_event ) CloseHandle ( g_sdata . sigint_event ) ;
2013-05-04 13:32:47 +00:00
g_sdata . sigint_event = CreateEvent ( NULL , FALSE , FALSE , eventnamebuf ) ;
2013-03-14 18:00:00 +00:00
if ( ! g_sdata . sigint_event ) {
2013-05-04 13:32:47 +00:00
ErrorMessage ( g_sdata . hwnd , _T ( " There was an error creating the abort event. " ) ) ;
PostMessage ( g_sdata . hwnd , WM_MAKENSIS_PROCESSCOMPLETE , 0 , 0 ) ;
2013-03-14 18:00:00 +00:00
return 1 ;
}
2013-05-04 13:32:47 +00:00
STARTUPINFO si ;
HANDLE newstdout , read_stdout ;
if ( ! InitSpawn ( si , read_stdout , newstdout ) ) {
ErrorMessage ( g_sdata . hwnd , _T ( " There was an error creating the pipe. " ) ) ;
PostMessage ( g_sdata . hwnd , WM_MAKENSIS_PROCESSCOMPLETE , 0 , 0 ) ;
2008-02-16 17:53:17 +00:00
return 1 ;
}
2013-05-04 13:32:47 +00:00
PROCESS_INFORMATION pi ;
if ( ! CreateProcess ( 0 , g_sdata . compile_command , 0 , 0 , TRUE , CREATE_NEW_CONSOLE , 0 , 0 , & si , & pi ) ) {
TCHAR buf [ MAX_STRING ] ; // BUGBUG: TODO: Too small?
wsprintf ( buf , _T ( " Could not execute: \r \n %s. " ) , g_sdata . compile_command ) ;
ErrorMessage ( g_sdata . hwnd , buf ) ;
FreeSpawn ( 0 , read_stdout , newstdout ) ;
PostMessage ( g_sdata . hwnd , WM_MAKENSIS_PROCESSCOMPLETE , 0 , 0 ) ;
2008-02-16 17:53:17 +00:00
return 1 ;
}
2014-10-23 15:34:10 +00:00
CloseHandle ( newstdout ) ; // Close this handle (duplicated in subprocess) now so we get ERROR_BROKEN_PIPE
2013-05-28 20:07:47 +00:00
2014-07-16 20:22:44 +00:00
char iob [ ( 1024 & ~ 1 ) + sizeof ( WCHAR ) ] ;
WCHAR * p = ( WCHAR * ) iob , wcl = 0 ;
DWORD cbiob = sizeof ( iob ) - sizeof ( WCHAR ) , cb = 0 , cbofs = 0 , cch , cbio ;
2013-05-28 20:07:47 +00:00
for ( ; ; )
2010-05-07 13:54:03 +00:00
{
2014-07-16 20:22:44 +00:00
BOOL rok = ReadFile ( read_stdout , iob + cbofs , cbiob - cbofs , & cbio , NULL ) ;
cb + = cbio , cch = cb / sizeof ( WCHAR ) ;
2013-05-28 20:07:47 +00:00
if ( ! cch )
{
2014-10-23 15:34:10 +00:00
if ( ! rok ) break ; // TODO: If cb is non-zero we should report a incomplete read error?
2014-07-16 20:22:44 +00:00
cbofs + = cbio ; // We only have 1 byte, need to read more to get a complete WCHAR
2013-05-28 20:07:47 +00:00
continue ;
}
2014-07-17 09:21:07 +00:00
char oddbyte = ( char ) ( cb % 2 ) , incompsurr ;
cbofs = 0 ;
2014-07-19 19:21:43 +00:00
if ( ( incompsurr = IS_HIGH_SURROGATE ( p [ cch - 1 ] ) ) )
2014-07-16 20:22:44 +00:00
wcl = p [ - - cch ] , cbofs = sizeof ( WCHAR ) ; // Store leading surrogate part and complete it later
2014-07-17 09:21:07 +00:00
if ( oddbyte )
oddbyte = iob [ cb - 1 ] , + + cbofs ;
2014-07-16 20:22:44 +00:00
logappendfinal :
2013-05-28 20:07:47 +00:00
p [ cch ] = L ' \0 ' ;
LogMessage ( g_sdata . hwnd , p ) ;
2014-07-17 09:21:07 +00:00
p [ 0 ] = wcl , iob [ cbofs - ! ! oddbyte ] = oddbyte , cb = 0 ;
2014-07-16 20:22:44 +00:00
if ( ! rok ) // No more data can be read
2013-05-28 20:07:47 +00:00
{
2014-07-17 09:21:07 +00:00
if ( cbofs ) // Unable to complete the surrogate pair or odd byte
2013-05-28 20:07:47 +00:00
{
2014-07-17 09:21:07 +00:00
p [ 0 ] = 0xfffd , cch = 1 , cbofs = 0 ;
2014-07-16 20:22:44 +00:00
goto logappendfinal ;
2013-05-28 20:07:47 +00:00
}
break ;
}
2008-02-16 17:53:17 +00:00
}
2013-05-04 13:32:47 +00:00
FreeSpawn ( & pi , read_stdout , 0 ) ;
g_sdata . retcode = pi . dwProcessId ;
PostMessage ( g_sdata . hwnd , WM_MAKENSIS_PROCESSCOMPLETE , 0 , 0 ) ;
2008-02-16 17:53:17 +00:00
return 0 ;
}
2018-11-04 21:25:52 +00:00
static INT_PTR CALLBACK AboutProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam ) {
ABOUTDLGDATA & dd = * ( ABOUTDLGDATA * ) g_ModalDlgData ;
2008-02-16 17:53:17 +00:00
switch ( msg ) {
2018-11-04 21:25:52 +00:00
case WM_DRAWITEM :
if ( wParam = = IDC_ABOUTHEADER )
{
DRAWITEMSTRUCT & dis = * ( DRAWITEMSTRUCT * ) lParam ;
RECT r , r2 ;
const TCHAR txt [ ] = TEXT ( " MakeNSISW " ) ;
INT dt = DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER , cch = COUNTOF ( txt ) - 1 , line = DpiScaleY ( dis . hwndItem , 2 ) , shadow = 1 ;
GetClientRect ( dis . hwndItem , & r ) ;
2018-11-06 21:04:37 +00:00
if ( ! dd . hHeaderFont )
2018-11-04 21:25:52 +00:00
dd . hHeaderFont = CreateFont ( 0 , CFF_RAWSIZE , r . bottom / 2 , FW_BOLD , DEFAULT_PITCH | FF_DONTCARE , ANSI_CHARSET , _T ( " Trebuchet MS " ) ) ; // IE4.01SP2+
HGDIOBJ hOrgFont = SelectObject ( dis . hDC , dd . hHeaderFont ) ;
DrawHorzGradient ( dis . hDC , r . left , r . top , r . right , r . bottom - line , RGB ( 22 , 77 , 160 ) , RGB ( 29 , 100 , 207 ) ) ;
DrawHorzGradient ( dis . hDC , r . left , r . bottom - line , r . right , r . bottom , RGB ( 255 , 142 , 42 ) , RGB ( 190 , 90 , 2 ) ) ;
SetBkMode ( dis . hDC , TRANSPARENT ) ;
if ( ! dd . FinalHeaderPos )
{
r2 = r ;
DrawText ( dis . hDC , txt , cch , & r2 , dt | DT_CALCRECT ) ;
dd . FinalHeaderPos = r . right - ( r2 . right - r2 . left ) ;
dd . FinalHeaderPos - = DlgUnitToPixelX ( hwndDlg , 7 ) ; // Margin
}
r . left + = dd . AnimPos ;
SetTextColor ( dis . hDC , RGB ( 0 , 0 , 0 ) ) , OffsetRect ( & r , + shadow , + shadow ) ;
DrawText ( dis . hDC , txt , cch , & r , dt ) ;
SetTextColor ( dis . hDC , RGB ( 255 , 255 , 255 ) ) , OffsetRect ( & r , - shadow , - shadow ) ;
DrawText ( dis . hDC , txt , cch , & r , dt ) ;
SelectObject ( dis . hDC , hOrgFont ) ;
return TRUE ;
}
break ;
case WM_TIMER :
if ( wParam = = ABOUTDLGDATA : : TID_HEADER )
{
INT finalpos = dd . FinalHeaderPos , dir ;
if ( dd . AnimSpeed > = 4 )
{
dd . AnimPos + = ( dir = ( dd . AnimPos > = finalpos ) ) ? - ( INT ) dd . AnimSpeed : + ( INT ) dd . AnimSpeed ;
if ( dd . AnimDir ! = dir ) dd . AnimDir = dir , dd . AnimSpeed / = 2 ;
}
else
{
dd . AnimPos = finalpos ;
2021-08-21 22:18:38 +00:00
KillTimer ( hwndDlg , ABOUTDLGDATA : : TID_HEADER ) ;
2018-11-04 21:25:52 +00:00
}
InvalidateRect ( GetDlgItem ( hwndDlg , IDC_ABOUTHEADER ) , NULL , false ) ;
}
break ;
case WM_DESTROY :
2020-08-16 16:19:46 +00:00
DeleteObject ( dd . hHeaderFont ) ;
2018-11-04 21:25:52 +00:00
DeleteObject ( dd . hFont ) ;
DeleteObject ( dd . hBoldFont ) ;
break ;
2008-02-16 17:53:17 +00:00
case WM_INITDIALOG :
{
2018-10-16 16:55:37 +00:00
CenterOnParent ( hwndDlg ) ;
2018-11-04 21:25:52 +00:00
HFONT fontnorm = CreateFontPt ( hwndDlg , 8 , FW_NORMAL , FIXED_PITCH | FF_DONTCARE , ANSI_CHARSET , _T ( " Tahoma " ) ) ,
fontbold = CreateFontPt ( hwndDlg , 8 , FW_BOLD , FIXED_PITCH | FF_DONTCARE , ANSI_CHARSET , _T ( " Tahoma " ) ) ;
if ( ! fontbold & & ( SupportsWNT4 ( ) | | SupportsW95 ( ) ) ) { // Tahoma shipped with 98+ and 2000+
fontnorm = CreateFontPt ( hwndDlg , 8 , FW_NORMAL , FIXED_PITCH | FF_DONTCARE , ANSI_CHARSET , _T ( " MS Shell Dlg " ) ) ;
fontbold = CreateFontPt ( hwndDlg , 8 , FW_BOLD , FIXED_PITCH | FF_DONTCARE , ANSI_CHARSET , _T ( " MS Shell Dlg " ) ) ;
2008-02-16 17:53:17 +00:00
}
2018-11-04 21:25:52 +00:00
dd . hFont = fontnorm , dd . hBoldFont = fontbold ;
2013-05-26 19:47:22 +00:00
SendDlgItemMessage ( hwndDlg , IDC_ABOUTVERSION , WM_SETFONT , ( WPARAM ) fontbold , FALSE ) ;
2018-11-11 22:05:32 +00:00
static const BYTE fontnormctlids [ ] = { IDC_ABOUTCOPY , IDC_ABOUTPORTIONS , IDC_ABOUTDONATE , IDC_OTHERCONTRIB , IDC_NSISVER } ;
for ( UINT i = 0 ; i < COUNTOF ( fontnormctlids ) ; + + i ) SendDlgItemMessage ( hwndDlg , fontnormctlids [ i ] , WM_SETFONT , ( WPARAM ) fontnorm , FALSE ) ;
2018-10-30 23:22:00 +00:00
SendMessage ( hwndDlg , WM_APP , 0 , 0 ) ; // Set IDC_ABOUTVERSION
2013-05-26 19:47:22 +00:00
SetDlgItemText ( hwndDlg , IDC_ABOUTCOPY , COPYRIGHT ) ;
SetDlgItemText ( hwndDlg , IDC_OTHERCONTRIB , CONTRIB ) ;
2018-11-11 22:05:32 +00:00
SetDlgItemText ( hwndDlg , IDC_ABOUTDONATE , DONATE ) ;
2018-10-30 23:22:00 +00:00
SetDlgItemText ( hwndDlg , IDC_NSISVER , g_sdata . branding ) ;
2018-11-04 21:25:52 +00:00
SetTimer ( hwndDlg , ABOUTDLGDATA : : TID_HEADER , 50 , NULL ) ;
2008-02-16 17:53:17 +00:00
break ;
}
2018-11-11 22:05:32 +00:00
case WM_NOTIFY :
switch ( ( ( NMHDR * ) lParam ) - > code )
{
case NM_CLICK :
// fall through
case NM_RETURN :
if ( ( ( NMHDR * ) lParam ) - > idFrom = = IDC_ABOUTDONATE )
{
static const BYTE x = 128 , encurl [ ] = DONATEURL ;
char url [ COUNTOF ( encurl ) ] ;
for ( UINT i = 0 ; ; + + i ) if ( ! ( url [ i ] = ( char ) ( encurl [ i ] & ~ x ) ) ) break ; // "Decrypt" URL
OpenUrlInDefaultBrowser ( hwndDlg , url ) ;
}
break ;
}
break ;
2008-02-16 17:53:17 +00:00
case WM_COMMAND :
2018-10-30 23:22:00 +00:00
if ( wParam = = MAKELONG ( IDC_ABOUTVERSION , STN_DBLCLK ) ) goto showversion ;
2013-08-05 14:53:57 +00:00
if ( IDOK ! = LOWORD ( wParam ) ) break ;
// fall through
case WM_CLOSE :
return EndDialog ( hwndDlg , TRUE ) ;
2018-10-30 23:22:00 +00:00
case WM_APP : showversion :
{
TCHAR buf [ 200 ] , showver = wParam ! = 0 ;
wsprintf ( buf , _T ( " MakeNSISW %s%s(NSIS Compiler Interface) " ) , showver ? NSISW_VERSION : _T ( " " ) , showver ? _T ( " " ) : _T ( " " ) ) ;
SetDlgItemText ( hwndDlg , IDC_ABOUTVERSION , buf ) ;
}
break ;
2008-02-16 17:53:17 +00:00
}
return FALSE ;
}
2018-11-04 21:25:52 +00:00
INT_PTR ShowAboutDialog ( HWND hwndOwner )
{
ABOUTDLGDATA dd ;
g_ModalDlgData = & dd ;
dd . hHeaderFont = NULL , dd . FinalHeaderPos = 0 ;
dd . AnimSpeed = 55 , dd . AnimPos = 0 , dd . AnimDir = 0 ;
return DialogBox ( g_sdata . hInstance , MAKEINTRESOURCE ( DLG_ABOUT ) , hwndOwner , API_cast < DLGPROC > ( AboutProc ) ) ;
}
2015-09-28 16:08:54 +00:00
static void EnableSymbolSetButtons ( HWND hwndDlg )
2008-02-16 17:53:17 +00:00
{
2014-10-12 20:09:35 +00:00
LRESULT n = SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETCOUNT , 0 , 0 ) ;
2013-08-07 19:26:03 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDC_CLEAR ) , n > 0 ) ;
EnableWindow ( GetDlgItem ( hwndDlg , IDC_SAVE ) , n > 0 ) ;
2008-02-16 17:53:17 +00:00
}
2015-09-28 16:08:54 +00:00
static void EnableSymbolEditButtons ( HWND hwndDlg )
2008-02-16 17:53:17 +00:00
{
2014-10-12 20:09:35 +00:00
LRESULT n = SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETSELCOUNT , 0 , 0 ) ;
2013-08-07 19:26:03 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDC_LEFT ) , n = = 1 ) ;
EnableWindow ( GetDlgItem ( hwndDlg , IDC_DEL ) , n ! = 0 ) ;
2008-02-16 17:53:17 +00:00
}
2015-09-28 16:08:54 +00:00
static void SetSymbols ( HWND hwndDlg , TCHAR * * symbols )
2008-02-16 17:53:17 +00:00
{
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_RESETCONTENT , 0 , 0 ) ;
if ( symbols ) {
2015-09-28 16:08:54 +00:00
for ( SIZE_T i = 0 ; symbols [ i ] ; + + i )
2008-02-16 17:53:17 +00:00
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_ADDSTRING , 0 , ( LPARAM ) symbols [ i ] ) ;
}
EnableSymbolSetButtons ( hwndDlg ) ;
2013-08-07 19:26:03 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDC_RIGHT ) , FALSE ) ;
EnableWindow ( GetDlgItem ( hwndDlg , IDC_LEFT ) , FALSE ) ;
EnableWindow ( GetDlgItem ( hwndDlg , IDC_DEL ) , FALSE ) ;
2008-02-16 17:53:17 +00:00
}
2015-09-28 16:08:54 +00:00
static TCHAR * * GetSymbols ( HWND hwndDlg )
2008-02-16 17:53:17 +00:00
{
2014-10-12 20:09:35 +00:00
LRESULT n = SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETCOUNT , 0 , 0 ) ;
2010-03-24 17:22:56 +00:00
TCHAR * * symbols = NULL ;
2008-02-16 17:53:17 +00:00
if ( n > 0 ) {
2015-09-28 16:08:54 +00:00
symbols = ( TCHAR * * ) GlobalAlloc ( GPTR , ( n + 1 ) * sizeof ( TCHAR * ) ) ;
2014-10-12 20:09:35 +00:00
for ( LRESULT i = 0 ; i < n ; i + + ) {
LRESULT len = SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETTEXTLEN , ( WPARAM ) i , 0 ) ;
2013-05-26 19:47:22 +00:00
symbols [ i ] = ( TCHAR * ) MemAllocZI ( ( len + 1 ) * sizeof ( TCHAR ) ) ;
2015-09-28 16:08:54 +00:00
if ( ! symbols [ i ] ) {
FreeSymbolSet ( symbols ) ;
return NULL ;
}
2008-02-16 17:53:17 +00:00
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETTEXT , ( WPARAM ) i , ( LPARAM ) symbols [ i ] ) ;
}
symbols [ n ] = NULL ;
}
return symbols ;
}
2013-05-26 19:47:22 +00:00
INT_PTR CALLBACK SettingsProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam ) {
2008-02-16 17:53:17 +00:00
switch ( msg ) {
case WM_INITDIALOG :
{
2018-10-16 16:55:37 +00:00
CenterOnParent ( hwndDlg ) ;
2014-10-23 15:34:10 +00:00
for ( int i = ( int ) COMPRESSOR_SCRIPT ; i < = ( int ) COMPRESSOR_BEST ; i + + )
2012-09-08 02:50:09 +00:00
SendDlgItemMessage ( hwndDlg , IDC_COMPRESSOR , CB_ADDSTRING , 0 , ( LPARAM ) compressor_display_names [ i ] ) ;
SendDlgItemMessage ( hwndDlg , IDC_COMPRESSOR , CB_SETCURSEL , ( WPARAM ) g_sdata . default_compressor , ( LPARAM ) 0 ) ;
2008-02-16 17:53:17 +00:00
SetSymbols ( hwndDlg , g_sdata . symbols ) ;
SetFocus ( GetDlgItem ( hwndDlg , IDC_SYMBOL ) ) ;
break ;
}
case WM_MAKENSIS_LOADSYMBOLSET :
{
2010-03-24 17:22:56 +00:00
TCHAR * name = ( TCHAR * ) wParam ;
TCHAR * * symbols = LoadSymbolSet ( name ) ;
2008-02-16 17:53:17 +00:00
if ( symbols ) {
2015-09-28 16:08:54 +00:00
SetSymbols ( hwndDlg , symbols ) ;
GlobalFree ( ( HGLOBAL ) symbols ) ;
2008-02-16 17:53:17 +00:00
}
break ;
}
case WM_MAKENSIS_SAVESYMBOLSET :
{
2010-03-24 17:22:56 +00:00
TCHAR * name = ( TCHAR * ) wParam ;
TCHAR * * symbols = GetSymbols ( hwndDlg ) ;
2008-02-16 17:53:17 +00:00
if ( symbols ) {
SaveSymbolSet ( name , symbols ) ;
2015-09-28 16:08:54 +00:00
GlobalFree ( ( HGLOBAL ) symbols ) ;
2008-02-16 17:53:17 +00:00
}
break ;
}
case WM_COMMAND :
{
switch ( LOWORD ( wParam ) ) {
case IDOK :
{
ResetObjects ( ) ;
ResetSymbols ( ) ;
g_sdata . symbols = GetSymbols ( hwndDlg ) ;
2014-10-12 20:09:35 +00:00
INT_PTR n = SendDlgItemMessage ( hwndDlg , IDC_COMPRESSOR , CB_GETCURSEL , ( WPARAM ) 0 , ( LPARAM ) 0 ) ;
2015-09-28 16:08:54 +00:00
if ( n > = ( INT_PTR ) COMPRESSOR_SCRIPT & & n < = ( INT_PTR ) COMPRESSOR_BEST )
2008-02-16 17:53:17 +00:00
g_sdata . default_compressor = ( NCOMPRESSOR ) n ;
2015-09-28 16:08:54 +00:00
else
2008-02-16 17:53:17 +00:00
g_sdata . default_compressor = COMPRESSOR_SCRIPT ;
2015-09-28 16:08:54 +00:00
SaveCompressor ( ) ;
2008-02-16 17:53:17 +00:00
SetCompressor ( g_sdata . default_compressor ) ;
2015-09-28 16:08:54 +00:00
EndDialog ( hwndDlg , TRUE ) ;
2008-02-16 17:53:17 +00:00
}
break ;
case IDCANCEL :
EndDialog ( hwndDlg , TRUE ) ;
break ;
2013-08-07 19:26:03 +00:00
case IDC_RIGHT :
2008-02-16 17:53:17 +00:00
{
2014-10-12 20:09:35 +00:00
LRESULT n = SendDlgItemMessage ( hwndDlg , IDC_SYMBOL , WM_GETTEXTLENGTH , 0 , 0 ) ;
2008-02-16 17:53:17 +00:00
if ( n > 0 ) {
2013-05-26 19:47:22 +00:00
TCHAR * buf = ( TCHAR * ) MemAllocZI ( ( n + 1 ) * sizeof ( TCHAR ) ) ;
2008-02-16 17:53:17 +00:00
SendDlgItemMessage ( hwndDlg , IDC_SYMBOL , WM_GETTEXT , n + 1 , ( LPARAM ) buf ) ;
2010-04-12 16:00:17 +00:00
if ( _tcsstr ( buf , _T ( " " ) ) | | _tcsstr ( buf , _T ( " \t " ) ) ) {
2013-05-26 19:47:22 +00:00
MessageBox ( hwndDlg , SYMBOLSERROR , ERRBOXTITLE , MB_OK | MB_ICONSTOP ) ;
MemFree ( buf ) ;
2008-02-16 17:53:17 +00:00
break ;
}
n = SendDlgItemMessage ( hwndDlg , IDC_VALUE , WM_GETTEXTLENGTH , 0 , 0 ) ;
if ( n > 0 ) {
2013-05-26 19:47:22 +00:00
TCHAR * buf2 = ( TCHAR * ) MemAllocZI ( ( n + 1 ) * sizeof ( TCHAR ) ) ;
2008-02-16 17:53:17 +00:00
SendDlgItemMessage ( hwndDlg , IDC_VALUE , WM_GETTEXT , n + 1 , ( LPARAM ) buf2 ) ;
2013-05-26 19:47:22 +00:00
TCHAR * buf3 = ( TCHAR * ) MemAllocZI ( ( lstrlen ( buf ) + lstrlen ( buf2 ) + 2 ) * sizeof ( TCHAR ) ) ;
2010-03-24 17:22:56 +00:00
wsprintf ( buf3 , _T ( " %s=%s " ) , buf , buf2 ) ;
2013-05-26 19:47:22 +00:00
MemFree ( buf ) ;
2008-02-16 17:53:17 +00:00
buf = buf3 ;
2013-05-26 19:47:22 +00:00
MemFree ( buf2 ) ;
2008-02-16 17:53:17 +00:00
}
2014-10-12 20:09:35 +00:00
INT_PTR idx = SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_ADDSTRING , 0 , ( LPARAM ) buf ) ;
2008-02-16 17:53:17 +00:00
if ( idx > = 0 )
{
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_SETSEL , FALSE , - 1 ) ;
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_SETSEL , TRUE , idx ) ;
}
EnableSymbolEditButtons ( hwndDlg ) ;
SendDlgItemMessage ( hwndDlg , IDC_SYMBOL , WM_SETTEXT , 0 , 0 ) ;
SendDlgItemMessage ( hwndDlg , IDC_VALUE , WM_SETTEXT , 0 , 0 ) ;
2013-05-26 19:47:22 +00:00
MemFree ( buf ) ;
2008-02-16 17:53:17 +00:00
EnableSymbolSetButtons ( hwndDlg ) ;
}
}
break ;
2013-08-07 19:26:03 +00:00
case IDC_LEFT :
2008-02-16 17:53:17 +00:00
{
if ( SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETSELCOUNT , 0 , 0 ) ! = 1 )
break ;
int index ;
2014-10-12 20:09:35 +00:00
INT_PTR num = SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETSELITEMS , 1 , ( LPARAM ) & index ) ;
2008-02-16 17:53:17 +00:00
if ( num = = 1 ) {
2014-10-12 20:09:35 +00:00
INT_PTR n = SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETTEXTLEN , ( WPARAM ) index , 0 ) ;
2008-02-16 17:53:17 +00:00
if ( n > 0 ) {
2013-05-26 19:47:22 +00:00
TCHAR * buf = ( TCHAR * ) MemAllocZI ( ( n + 1 ) * sizeof ( TCHAR ) ) ;
2008-02-16 17:53:17 +00:00
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETTEXT , ( WPARAM ) index , ( LPARAM ) buf ) ;
2010-04-12 16:00:17 +00:00
TCHAR * p = _tcsstr ( buf , _T ( " = " ) ) ;
2008-02-16 17:53:17 +00:00
if ( p ) {
SendDlgItemMessage ( hwndDlg , IDC_VALUE , WM_SETTEXT , 0 , ( LPARAM ) ( p + 1 ) ) ;
* p = 0 ;
}
SendDlgItemMessage ( hwndDlg , IDC_SYMBOL , WM_SETTEXT , 0 , ( LPARAM ) buf ) ;
2013-05-26 19:47:22 +00:00
MemFree ( buf ) ;
2008-02-16 17:53:17 +00:00
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_DELETESTRING , ( WPARAM ) index , 0 ) ;
2013-08-07 19:26:03 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDC_LEFT ) , FALSE ) ;
EnableWindow ( GetDlgItem ( hwndDlg , IDC_DEL ) , FALSE ) ;
2008-02-16 17:53:17 +00:00
EnableSymbolSetButtons ( hwndDlg ) ;
}
}
}
break ;
2013-08-07 19:26:03 +00:00
case IDC_CLEAR :
2008-02-16 17:53:17 +00:00
{
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_RESETCONTENT , 0 , 0 ) ;
EnableSymbolSetButtons ( hwndDlg ) ;
}
break ;
2013-08-07 19:26:03 +00:00
case IDC_LOAD :
case IDC_SAVE :
2018-11-04 21:25:52 +00:00
ShowSymbolSetDialog ( hwndDlg , IDC_LOAD = = LOWORD ( wParam ) ) ;
2008-02-16 17:53:17 +00:00
break ;
2013-08-07 19:26:03 +00:00
case IDC_DEL :
2008-02-16 17:53:17 +00:00
{
2014-10-12 20:09:35 +00:00
INT_PTR n = SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETSELCOUNT , 0 , 0 ) ;
2013-05-26 19:47:22 +00:00
int * items = ( int * ) MemAllocZI ( n * sizeof ( int ) ) ;
if ( items ) {
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_GETSELITEMS , ( WPARAM ) n , ( LPARAM ) items ) ;
2014-10-12 20:09:35 +00:00
for ( INT_PTR i = n - 1 ; i > = 0 ; i - - )
2013-05-26 19:47:22 +00:00
SendDlgItemMessage ( hwndDlg , IDC_SYMBOLS , LB_DELETESTRING , ( WPARAM ) items [ i ] , 0 ) ;
MemFree ( items ) ;
2008-02-16 17:53:17 +00:00
}
EnableSymbolEditButtons ( hwndDlg ) ;
EnableSymbolSetButtons ( hwndDlg ) ;
}
break ;
case IDC_SYMBOL :
if ( HIWORD ( wParam ) = = EN_CHANGE )
{
2014-10-12 20:09:35 +00:00
LRESULT n = SendDlgItemMessage ( hwndDlg , IDC_SYMBOL , WM_GETTEXTLENGTH , 0 , 0 ) ;
2013-08-07 19:26:03 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDC_RIGHT ) , n > 0 ) ;
2008-02-16 17:53:17 +00:00
}
break ;
case IDC_SYMBOLS :
if ( HIWORD ( wParam ) = = LBN_SELCHANGE )
{
EnableSymbolEditButtons ( hwndDlg ) ;
}
else if ( HIWORD ( wParam ) = = LBN_DBLCLK )
{
2013-08-07 19:26:03 +00:00
SendDlgItemMessage ( hwndDlg , IDC_LEFT , BM_CLICK , 0 , 0 ) ;
2008-02-16 17:53:17 +00:00
}
break ;
}
break ;
}
}
return FALSE ;
}
2013-05-26 19:47:22 +00:00
INT_PTR CALLBACK CompressorProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam ) {
2008-02-16 17:53:17 +00:00
switch ( msg ) {
case WM_INITDIALOG :
{
2018-10-16 16:55:37 +00:00
CenterOnParent ( hwndDlg ) ;
for ( int i = ( int ) COMPRESSOR_SCRIPT ; i < = ( int ) COMPRESSOR_BEST ; i + + ) {
2012-09-08 02:50:09 +00:00
SendDlgItemMessage ( hwndDlg , IDC_COMPRESSOR , CB_ADDSTRING , 0 , ( LPARAM ) compressor_display_names [ i ] ) ;
2008-02-16 17:53:17 +00:00
}
2012-09-08 02:50:09 +00:00
SendDlgItemMessage ( hwndDlg , IDC_COMPRESSOR , CB_SETCURSEL , ( WPARAM ) g_sdata . compressor , ( LPARAM ) 0 ) ;
2008-02-16 17:53:17 +00:00
SetFocus ( GetDlgItem ( hwndDlg , IDC_COMPRESSOR ) ) ;
break ;
}
case WM_COMMAND :
{
switch ( LOWORD ( wParam ) ) {
case IDOK :
{
2014-10-12 20:09:35 +00:00
INT_PTR n = SendDlgItemMessage ( hwndDlg , IDC_COMPRESSOR , CB_GETCURSEL , ( WPARAM ) 0 , ( LPARAM ) 0 ) ;
if ( n > = ( INT_PTR ) COMPRESSOR_SCRIPT & & n < = ( INT_PTR ) COMPRESSOR_BEST )
2008-02-16 17:53:17 +00:00
SetCompressor ( ( NCOMPRESSOR ) n ) ;
2014-10-12 20:09:35 +00:00
else
2008-02-16 17:53:17 +00:00
SetCompressor ( g_sdata . default_compressor ) ;
EndDialog ( hwndDlg , 0 ) ;
break ;
}
case IDCANCEL :
{
EndDialog ( hwndDlg , 1 ) ;
LogMessage ( g_sdata . hwnd , USAGE ) ;
break ;
}
}
break ;
}
}
return FALSE ;
}
2018-11-04 21:25:52 +00:00
static void FixSimpleComboBoxSizeBug ( HWND hCombo ) // Fix Win10 CBS_SIMPLE height drawing bug when DPI != 96
{
RECT r ;
GetWindowRect ( hCombo , & r ) ;
SetWindowPos ( hCombo , 0 , 0 , 0 , RectW ( r ) , RectH ( r ) - 1 , SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE ) ;
SetWindowPos ( hCombo , 0 , 0 , 0 , RectW ( r ) , RectH ( r ) , SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE | SWP_FRAMECHANGED ) ;
}
# define SymbolSetDlgDpiChanged(hwndDlg) ( FixSimpleComboBoxSizeBug(GetDlgItem((hwndDlg), IDC_NAMES)) )
static INT_PTR CALLBACK SymbolSetProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam ) {
SYMSETDLGDATA & dd = * ( SYMSETDLGDATA * ) g_ModalDlgData ;
2008-02-16 17:53:17 +00:00
switch ( msg ) {
case WM_INITDIALOG :
{
HKEY hKey ;
2018-10-16 16:55:37 +00:00
CenterOnParent ( hwndDlg ) ;
2013-08-07 19:26:03 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDC_DEL ) , FALSE ) ;
2008-02-16 17:53:17 +00:00
if ( OpenRegSettingsKey ( hKey ) ) {
HKEY hSubKey ;
2018-11-04 21:25:52 +00:00
if ( RegOpenKeyEx ( hKey , REGSYMSUBKEY , 0 , KEY_READ , & hSubKey ) = = ERROR_SUCCESS ) {
2010-03-24 17:22:56 +00:00
TCHAR subkey [ 1024 ] ;
2008-02-16 17:53:17 +00:00
int i = 0 ;
2018-11-04 21:25:52 +00:00
while ( RegEnumKey ( hSubKey , i , subkey , sizeof ( subkey ) ) = = ERROR_SUCCESS ) {
2008-02-16 17:53:17 +00:00
SendDlgItemMessage ( hwndDlg , IDC_NAMES , CB_ADDSTRING , 0 , ( LPARAM ) subkey ) ;
i + + ;
}
RegCloseKey ( hSubKey ) ;
}
RegCloseKey ( hKey ) ;
}
2018-11-04 21:25:52 +00:00
HWND hwndEdit = GetComboEdit ( GetDlgItem ( hwndDlg , IDC_NAMES ) ) ;
2015-09-28 16:08:54 +00:00
SendMessage ( hwndEdit , EM_LIMITTEXT , ( WPARAM ) SYMSETNAME_MAXLEN , 0 ) ;
2018-11-04 21:25:52 +00:00
if ( dd . LoadingMode ) {
2008-02-16 17:53:17 +00:00
SetWindowText ( hwndDlg , LOAD_SYMBOL_SET_DLG_NAME ) ;
SetWindowText ( GetDlgItem ( hwndDlg , IDOK ) , LOAD_BUTTON_TEXT ) ;
SendMessage ( hwndEdit , EM_SETREADONLY , ( WPARAM ) TRUE , 0 ) ;
}
else {
SetWindowText ( hwndDlg , SAVE_SYMBOL_SET_DLG_NAME ) ;
SetWindowText ( GetDlgItem ( hwndDlg , IDOK ) , SAVE_BUTTON_TEXT ) ;
}
2018-11-04 21:25:52 +00:00
SymbolSetDlgDpiChanged ( hwndDlg ) ;
2008-02-16 17:53:17 +00:00
break ;
}
case WM_COMMAND :
{
switch ( LOWORD ( wParam ) ) {
case IDOK :
{
2015-09-28 16:08:54 +00:00
TCHAR name [ SYMSETNAME_MAXLEN + 1 ] ;
2018-11-04 21:25:52 +00:00
HWND hwndEdit = GetComboEdit ( GetDlgItem ( hwndDlg , IDC_NAMES ) ) ;
2015-09-28 16:08:54 +00:00
SendMessage ( hwndEdit , WM_GETTEXT , ( WPARAM ) COUNTOF ( name ) , ( LPARAM ) name ) ;
2018-11-04 21:25:52 +00:00
if ( ! * name ) {
LPCTSTR msg = dd . LoadingMode ? LOAD_SYMBOL_SET_MESSAGE : SAVE_SYMBOL_SET_MESSAGE ;
LPCTSTR tit = dd . LoadingMode ? LOAD_SYMBOL_SET_DLG_NAME : SAVE_SYMBOL_SET_DLG_NAME ;
MessageBox ( hwndDlg , msg , tit , MB_OK | MB_ICONEXCLAMATION ) ;
2008-02-16 17:53:17 +00:00
}
else {
HWND hwndParent = GetParent ( hwndDlg ) ;
2018-11-04 21:25:52 +00:00
UINT msg = dd . LoadingMode ? WM_MAKENSIS_LOADSYMBOLSET : WM_MAKENSIS_SAVESYMBOLSET ;
SendMessage ( hwndParent , msg , ( WPARAM ) name , ( LPARAM ) NULL ) ;
2008-02-16 17:53:17 +00:00
EndDialog ( hwndDlg , TRUE ) ;
}
break ;
}
case IDCANCEL :
{
EndDialog ( hwndDlg , TRUE ) ;
break ;
}
2013-08-07 19:26:03 +00:00
case IDC_DEL :
2008-02-16 17:53:17 +00:00
{
2014-10-12 20:09:35 +00:00
LONG_PTR n = SendDlgItemMessage ( hwndDlg , IDC_NAMES , CB_GETCURSEL , 0 , 0 ) ;
2008-02-16 17:53:17 +00:00
if ( n ! = CB_ERR ) {
2014-10-12 20:09:35 +00:00
INT_PTR len = SendDlgItemMessage ( hwndDlg , IDC_NAMES , CB_GETLBTEXTLEN , ( WPARAM ) n , 0 ) ;
2013-05-26 19:47:22 +00:00
TCHAR * buf = ( TCHAR * ) MemAllocZI ( ( len + 1 ) * sizeof ( TCHAR ) ) ;
2008-02-16 17:53:17 +00:00
if ( SendDlgItemMessage ( hwndDlg , IDC_NAMES , CB_GETLBTEXT , ( WPARAM ) n , ( LPARAM ) buf ) ! = CB_ERR ) {
SendDlgItemMessage ( hwndDlg , IDC_NAMES , CB_DELETESTRING , n , 0 ) ;
DeleteSymbolSet ( buf ) ;
}
2013-05-26 19:47:22 +00:00
MemFree ( buf ) ;
2008-02-16 17:53:17 +00:00
}
2013-08-07 19:26:03 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDC_DEL ) , FALSE ) ;
2008-02-16 17:53:17 +00:00
break ;
}
case IDC_NAMES :
{
if ( HIWORD ( wParam ) = = CBN_SELCHANGE )
{
2014-10-12 20:09:35 +00:00
LONG_PTR n = SendDlgItemMessage ( hwndDlg , IDC_NAMES , CB_GETCURSEL , 0 , 0 ) ;
2013-08-07 19:26:03 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDC_DEL ) , CB_ERR ! = n ) ;
2008-02-16 17:53:17 +00:00
}
else if ( HIWORD ( wParam ) = = CBN_DBLCLK )
{
2014-10-12 20:09:35 +00:00
LONG_PTR n = SendDlgItemMessage ( hwndDlg , IDC_NAMES , CB_GETCURSEL , 0 , 0 ) ;
if ( n ! = CB_ERR ) SendDlgItemMessage ( hwndDlg , IDOK , BM_CLICK , 0 , 0 ) ;
2008-02-16 17:53:17 +00:00
}
break ;
}
}
break ;
}
}
return FALSE ;
}
2018-11-04 21:25:52 +00:00
INT_PTR ShowSymbolSetDialog ( HWND hwndOwner , BOOL LoadingSet )
{
SYMSETDLGDATA dd = { g_ModalDlgData , LoadingSet } ;
g_ModalDlgData = & dd ;
INT_PTR retval = DialogBox ( g_sdata . hInstance , MAKEINTRESOURCE ( DLG_SYMBOLSET ) , hwndOwner , API_cast < DLGPROC > ( SymbolSetProc ) ) ;
g_ModalDlgData = dd . pOldMDD ; // Restore the old pointer
return retval ;
}
2008-02-16 17:53:17 +00:00
void SetCompressor ( NCOMPRESSOR compressor )
{
int i ;
if ( g_sdata . compressor ! = compressor ) {
WORD command ;
2011-11-09 18:12:57 +00:00
LPCTSTR compressor_name ;
2008-02-16 17:53:17 +00:00
if ( compressor > COMPRESSOR_SCRIPT & & compressor < COMPRESSOR_BEST ) {
command = compressor_commands [ ( int ) compressor ] ;
compressor_name = compressor_names [ ( int ) compressor ] ;
}
else if ( compressor = = COMPRESSOR_BEST ) {
command = compressor_commands [ ( int ) compressor ] ;
compressor_name = compressor_names [ ( int ) COMPRESSOR_SCRIPT + 1 ] ;
}
else {
compressor = COMPRESSOR_SCRIPT ;
command = IDM_COMPRESSOR_SCRIPT ;
2010-03-24 17:22:56 +00:00
compressor_name = _T ( " " ) ;
2008-02-16 17:53:17 +00:00
}
g_sdata . compressor = compressor ;
g_sdata . compressor_name = compressor_name ;
UpdateToolBarCompressorButton ( ) ;
for ( i = ( int ) COMPRESSOR_SCRIPT ; i < = ( int ) COMPRESSOR_BEST ; i + + ) {
CheckMenuItem ( g_sdata . menu , compressor_commands [ i ] , MF_BYCOMMAND | MF_UNCHECKED ) ;
}
CheckMenuItem ( g_sdata . menu , command , MF_BYCOMMAND | MF_CHECKED ) ;
ResetObjects ( ) ;
}
}