Code cleanup

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1058 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
rainwater 2002-09-19 22:38:46 +00:00
parent 0910f0dd75
commit 19e6cde283
7 changed files with 49 additions and 95 deletions

View file

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2002 Robert Rainwater Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -24,18 +24,16 @@
#include "resource.h" #include "resource.h"
#include "noclib.h" #include "noclib.h"
char *g_script;
int g_retcode;
static RECT resizeRect; static RECT resizeRect;
static int dx; static int dx;
static int dy; static int dy;
char *g_script;
int g_retcode;
HINSTANCE g_hInstance; HINSTANCE g_hInstance;
HWND g_hwnd; HWND g_hwnd;
HANDLE g_hThread; HANDLE g_hThread;
BOOL g_warnings; BOOL g_warnings;
FINDREPLACE fr; FINDREPLACE fr;
UINT uFindReplaceMsg=0; UINT uFindReplaceMsg=0;
HWND hwndFind=0; HWND hwndFind=0;
@ -43,20 +41,18 @@ HWND hwndFind=0;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow) { int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow) {
HACCEL haccel; HACCEL haccel;
g_hInstance=GetModuleHandle(0); g_hInstance=GetModuleHandle(0);
g_script=GetCommandLine(); // set commandline global string g_script=GetCommandLine();
if (*g_script++=='"') while (*g_script++!='"'); if (*g_script++=='"') while (*g_script++!='"');
else while (*g_script++!=' '); else while (*g_script++!=' ');
while (*g_script==' ') g_script++; while (*g_script==' ') g_script++;
if (!InitBranding()) { if (!InitBranding()) {
MessageBox(0,"Unable to find makensis.exe.","Error",MB_ICONEXCLAMATION|MB_OK); MessageBox(0,NSISERROR,"Error",MB_ICONEXCLAMATION|MB_OK);
return 1; return 1;
} }
ResetObjects(); ResetObjects();
HWND hDialog = CreateDialog(g_hInstance,MAKEINTRESOURCE(DLG_MAIN),0,DialogProc); HWND hDialog = CreateDialog(g_hInstance,MAKEINTRESOURCE(DLG_MAIN),0,DialogProc);
if (!hDialog) { if (!hDialog) {
char buf [MAX_STRING]; MessageBox(0, DLGERROR, "Error", MB_ICONEXCLAMATION|MB_OK);
wsprintf(buf, "Error creating dialog box.\n\nError: %x", GetLastError ());
MessageBox(0, buf, "Error", MB_ICONEXCLAMATION | MB_OK);
return 1; return 1;
} }
haccel = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDK_ACCEL)); haccel = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDK_ACCEL));
@ -301,8 +297,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
} }
case IDM_FIND: case IDM_FIND:
{ {
if (!uFindReplaceMsg) if (!uFindReplaceMsg) uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
my_memset(&fr, 0, sizeof(FINDREPLACE)); my_memset(&fr, 0, sizeof(FINDREPLACE));
fr.lStructSize = sizeof(FINDREPLACE); fr.lStructSize = sizeof(FINDREPLACE);
fr.hwndOwner = hwndDlg; fr.hwndOwner = hwndDlg;
@ -329,8 +324,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
ft.chrg.cpMax = SendDlgItemMessage(hwndDlg, IDC_LOGWIN, WM_GETTEXTLENGTH, 0, 0); ft.chrg.cpMax = SendDlgItemMessage(hwndDlg, IDC_LOGWIN, WM_GETTEXTLENGTH, 0, 0);
ft.lpstrText = lpfr->lpstrFindWhat; ft.lpstrText = lpfr->lpstrFindWhat;
ft.chrg.cpMin = SendDlgItemMessage(hwndDlg, IDC_LOGWIN, EM_FINDTEXTEX, flags, (LPARAM)&ft); ft.chrg.cpMin = SendDlgItemMessage(hwndDlg, IDC_LOGWIN, EM_FINDTEXTEX, flags, (LPARAM)&ft);
if (ft.chrg.cpMin != -1) if (ft.chrg.cpMin != -1) SendDlgItemMessage(hwndDlg, IDC_LOGWIN, EM_SETSEL, ft.chrgText.cpMin, ft.chrgText.cpMax);
SendDlgItemMessage(hwndDlg, IDC_LOGWIN, EM_SETSEL, ft.chrgText.cpMin, ft.chrgText.cpMax);
else MessageBeep(MB_ICONASTERISK); else MessageBeep(MB_ICONASTERISK);
} }
if (lpfr->Flags & FR_DIALOGTERM) hwndFind = 0; if (lpfr->Flags & FR_DIALOGTERM) hwndFind = 0;
@ -345,7 +339,6 @@ DWORD WINAPI MakeNSISProc(LPVOID p) {
SECURITY_DESCRIPTOR sd={0,}; SECURITY_DESCRIPTOR sd={0,};
PROCESS_INFORMATION pi={0,}; PROCESS_INFORMATION pi={0,};
HANDLE newstdout=0,read_stdout=0; HANDLE newstdout=0,read_stdout=0;
OSVERSIONINFO osv={sizeof(osv)}; OSVERSIONINFO osv={sizeof(osv)};
GetVersionEx(&osv); GetVersionEx(&osv);
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) { if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
@ -374,11 +367,9 @@ DWORD WINAPI MakeNSISProc(LPVOID p) {
PostMessage(g_hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0); PostMessage(g_hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
return 1; return 1;
} }
char szBuf[1024]; char szBuf[1024];
DWORD dwRead = 1; DWORD dwRead = 1;
DWORD dwExit = !STILL_ACTIVE; DWORD dwExit = !STILL_ACTIVE;
while (dwExit == STILL_ACTIVE || dwRead) { while (dwExit == STILL_ACTIVE || dwRead) {
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL); PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
if (dwRead) { if (dwRead) {

View file

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2002 Robert Rainwater Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,7 @@
#define MAKENSIS_H #define MAKENSIS_H
#include <commctrl.h> #include <commctrl.h>
#include "utils.h"
#define _RICHEDIT_VER 0x0200 #define _RICHEDIT_VER 0x0200
#include <RichEdit.h> #include <RichEdit.h>
@ -32,30 +33,34 @@
#define NSIS_URL "http://sourceforge.net/projects/nsis/" #define NSIS_URL "http://sourceforge.net/projects/nsis/"
#define USAGE "Usage:\r\n\r\n - File | Load Script...\r\n - Drag the .nsi file into this window\r\n - Right click the .nsi file and choose \"Compile NSI\"" #define USAGE "Usage:\r\n\r\n - File | Load Script...\r\n - Drag the .nsi file into this window\r\n - Right click the .nsi file and choose \"Compile NSI\""
#define COPYRIGHT "Copyright (c) 2002 Robert Rainwater" #define COPYRIGHT "Copyright (c) 2002 Robert Rainwater"
#define CONTRIBUTOR "Portions Copyright (c) 2002 Justin Frankel, Fritz Elfert, and Amir Szekely" #define CONTRIBUTOR "Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely"
#define DOCPATH "http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/nsis/NSIS/docs/index.html?rev=HEAD" #define DOCPATH "http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/nsis/NSIS/docs/index.html?rev=HEAD"
#define LOCALDOCS "\\docs\\index.html" #define LOCALDOCS "\\docs\\index.html"
#define NSISERROR "Unable to intialize MakeNSIS. Please verify that makensis.exe is in the same directory as makensisw.exe."
#define DLGERROR "Unable to intialize MakeNSISW."
#define REGSEC HKEY_LOCAL_MACHINE #define REGSEC HKEY_LOCAL_MACHINE
#define REGKEY "Software\\NSIS" #define REGKEY "Software\\NSIS"
#define REGLOC "MakeNSISWPlacement" #define REGLOC "MakeNSISWPlacement"
#define EXENAME "makensis.exe" #define EXENAME "makensis.exe"
#define MAX_STRING 256 #define MAX_STRING 256
#define TIMEOUT 150 #define TIMEOUT 100
#define MINWIDTH 350 #define MINWIDTH 350
#define MINHEIGHT 180 #define MINHEIGHT 180
#define REGSEC HKEY_LOCAL_MACHINE
#define REGKEY "Software\\NSIS"
#define REGLOC "MakeNSISWPlacement"
#define WM_MAKENSIS_PROCESSCOMPLETE (WM_USER+1001) #define WM_MAKENSIS_PROCESSCOMPLETE (WM_USER+1001)
// Extern Variables // Extern Variables
extern const char *NSISW_VERSION; extern const char* NSISW_VERSION;
extern char *g_script; extern char* g_script;
extern HWND g_hwnd; extern HWND g_hwnd;
extern HANDLE g_hThread; extern HANDLE g_hThread;
extern char *g_output_exe; extern char * g_output_exe;
extern char *g_input_script; extern char * g_input_script;
extern int g_retcode; extern int g_retcode;
// makensisw
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow); int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow);
static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
DWORD WINAPI MakeNSISProc(LPVOID p); DWORD WINAPI MakeNSISProc(LPVOID p);
@ -63,20 +68,4 @@ BOOL CALLBACK DialogResize(HWND hWnd, LPARAM /* unused*/);
BOOL CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
void CompileNSISScript(); void CompileNSISScript();
// utils
void SetTitle(HWND hwnd,char *substr);
void SetBranding(HWND hwnd);
void CopyToClipboard(HWND hwnd);
void ClearLog(HWND hwnd);
void LogMessage(HWND hwnd,const char *str);
void ErrorMessage(HWND hwnd,const char *str);
void DisableItems(HWND hwnd);
void EnableItems(HWND hwnd);
void RestoreWindowPos(HWND hwnd);
void SaveWindowPos(HWND hwnd);
void ResetObjects();
int InitBranding();
void InitTooltips(HWND h);
void DestroyTooltips();
void AddTip(HWND hWnd,LPSTR lpszToolTip);
#endif #endif

View file

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2002 Robert Rainwater Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -18,21 +18,18 @@
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/
/*
Contribution by kickik
*/ */
#include <windows.h> #include <windows.h>
#include "noclib.h" #include "noclib.h"
// kickik's clib methods
char *my_strrchr(const char *string, int c) { char *my_strrchr(const char *string, int c) {
for (int i = lstrlen(string); i >= 0; i--) for (int i=lstrlen(string); i>=0; i--)
if (string[i] == c) if (string[i]==c) return (char*)&string[i];
return (char*)&string[i];
return 0; return 0;
} }
void *my_memset(void *dest, int c, size_t count) { void *my_memset(void *dest, int c, size_t count) {
for (size_t i = 0; i < count; i++) ((char*)dest)[i]=c; for (size_t i=0; i<count;i++) ((char*)dest)[i]=c;
return dest; return dest;
} }

View file

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2002 Robert Rainwater Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -18,13 +18,11 @@
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/
/*
Contribution by kickik
*/ */
#ifndef NOCLIB_H #ifndef NOCLIB_H
#define NOCLIB_H #define NOCLIB_H
// kickik's clib methods
char *my_strrchr(const char *string, int c); char *my_strrchr(const char *string, int c);
void *my_memset(void *dest, int c, size_t count); void *my_memset(void *dest, int c, size_t count);

View file

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2002 Robert Rainwater Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -25,6 +25,18 @@
#include "noclib.h" #include "noclib.h"
char *g_branding; char *g_branding;
char *g_output_exe;
char *g_input_script;
HWND g_tip;
HWND g_tip_p;
HHOOK g_hook;
LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam);
extern BOOL g_warnings;
extern HANDLE g_hThread;
extern int g_retcode;
static BOOL g_appended = FALSE;
void SetTitle(HWND hwnd,char *substr) { void SetTitle(HWND hwnd,char *substr) {
char title[64]; char title[64];
@ -52,15 +64,10 @@ void CopyToClipboard(HWND hwnd) {
CloseClipboard(); CloseClipboard();
} }
void ClearLog(HWND hwnd) { void ClearLog(HWND hwnd) {
SetDlgItemText(hwnd, IDC_LOGWIN, ""); SetDlgItemText(hwnd, IDC_LOGWIN, "");
} }
char *g_output_exe;
char *g_input_script;
extern BOOL g_warnings;
void LogMessage(HWND hwnd,const char *str) { void LogMessage(HWND hwnd,const char *str) {
DWORD dwLength = SendDlgItemMessage(hwnd, IDC_LOGWIN, WM_GETTEXTLENGTH, 0, 0); DWORD dwLength = SendDlgItemMessage(hwnd, IDC_LOGWIN, WM_GETTEXTLENGTH, 0, 0);
SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_SETSEL, dwLength, dwLength); SendDlgItemMessage(hwnd, IDC_LOGWIN, EM_SETSEL, dwLength, dwLength);
@ -93,7 +100,6 @@ void EnableItems(HWND hwnd) {
#define MSG(a) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,0,0) #define MSG(a) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,0,0)
#define MSG1(a,b) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,b,0) #define MSG1(a,b) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,b,0)
#define MSG2(a,b,c) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,b,c) #define MSG2(a,b,c) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,b,c)
if (g_input_script) { if (g_input_script) {
GlobalFree(g_input_script); GlobalFree(g_input_script);
g_input_script = 0; g_input_script = 0;
@ -102,7 +108,6 @@ void EnableItems(HWND hwnd) {
GlobalFree(g_output_exe); GlobalFree(g_output_exe);
g_output_exe = 0; g_output_exe = 0;
} }
TEXTRANGE tr; TEXTRANGE tr;
FINDTEXT ft; FINDTEXT ft;
@ -148,7 +153,6 @@ void EnableItems(HWND hwnd) {
EnableMenuItem(m,IDM_EDITSCRIPT,MF_ENABLED); EnableMenuItem(m,IDM_EDITSCRIPT,MF_ENABLED);
} }
static BOOL g_appended = FALSE;
void CompileNSISScript() { void CompileNSISScript() {
static char *s; static char *s;
DragAcceptFiles(g_hwnd,FALSE); DragAcceptFiles(g_hwnd,FALSE);
@ -203,9 +207,6 @@ void SaveWindowPos(HWND hwnd) {
} }
} }
extern HANDLE g_hThread;
extern int g_retcode;
void ResetObjects() { void ResetObjects() {
g_appended = FALSE; g_appended = FALSE;
g_warnings = FALSE; g_warnings = FALSE;
@ -262,11 +263,6 @@ int InitBranding() {
return 1; return 1;
} }
HWND g_tip;
HWND g_tip_p;
HHOOK g_hook;
LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam);
void InitTooltips(HWND h) { void InitTooltips(HWND h) {
if (h == NULL) return; if (h == NULL) return;
g_tip_p = h; g_tip_p = h;
@ -274,15 +270,10 @@ void InitTooltips(HWND h) {
icx.dwSize = sizeof(icx); icx.dwSize = sizeof(icx);
icx.dwICC = ICC_BAR_CLASSES; icx.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icx); InitCommonControlsEx(&icx);
DWORD dwStyle = WS_POPUP | WS_BORDER | TTS_ALWAYSTIP; DWORD dwStyle = WS_POPUP | WS_BORDER | TTS_ALWAYSTIP;
DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST; DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
g_tip = CreateWindowEx(dwExStyle,TOOLTIPS_CLASS, g_tip = CreateWindowEx(dwExStyle,TOOLTIPS_CLASS,NULL,dwStyle,0,0,0,0,h,NULL,GetModuleHandle(NULL),NULL);
NULL,dwStyle,0,0,0,0, if (!g_tip) return;
h, NULL,
GetModuleHandle(NULL),NULL);
if (!g_tip) {
return;
}
g_hook = SetWindowsHookEx(WH_GETMESSAGE,TipHookProc,NULL, GetCurrentThreadId()); g_hook = SetWindowsHookEx(WH_GETMESSAGE,TipHookProc,NULL, GetCurrentThreadId());
AddTip(GetDlgItem(h,IDC_CLOSE),TEXT("Close MakeNSISW")); AddTip(GetDlgItem(h,IDC_CLOSE),TEXT("Close MakeNSISW"));
AddTip(GetDlgItem(h,IDC_TEST),TEXT("Test the installer generated by MakeNSISW")); AddTip(GetDlgItem(h,IDC_TEST),TEXT("Test the installer generated by MakeNSISW"));
@ -313,5 +304,4 @@ LRESULT CALLBACK TipHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
break; break;
} }
return CallNextHookEx(g_hook, nCode, wParam, lParam); return CallNextHookEx(g_hook, nCode, wParam, lParam);
} }

View file

@ -22,16 +22,6 @@
#ifndef UTILS_H #ifndef UTILS_H
#define UTILS_H #define UTILS_H
#define REGSEC HKEY_LOCAL_MACHINE // JF> modified this to HKLM so that
// nsis uninstaller would remove. this means
// window placement is shared across users, but
// bfd.
#define REGKEY "Software\\NSIS"
#define REGLOC "MakeNSISWPlacement"
extern const char NSISW_VERSION[];
// Methods
void SetTitle(HWND hwnd,char *substr); void SetTitle(HWND hwnd,char *substr);
void SetBranding(HWND hwnd); void SetBranding(HWND hwnd);
void CopyToClipboard(HWND hwnd); void CopyToClipboard(HWND hwnd);

View file

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2002 Robert Rainwater Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert Contributors: Justin Frankel, Fritz Elfert, and Amir Szekely
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -19,12 +19,11 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
// Turns a define into a string
#define REALSTR(x) #x #define REALSTR(x) #x
#define STR(x) REALSTR(x) #define STR(x) REALSTR(x)
#ifdef RELEASE #ifdef RELEASE
const char *NSISW_VERSION = "MakeNSISW " STR(RELEASE); const char *NSISW_VERSION = "MakeNSISW " STR(RELEASE);
#else #else
const char *NSISW_VERSION = "MakeNSISW Local Build: " __DATE__; const char *NSISW_VERSION = "MakeNSISW Build: " __DATE__;
#endif #endif