From 19e6cde283d5e81b0b12dfc3f100a61b2f68dca5 Mon Sep 17 00:00:00 2001 From: rainwater Date: Thu, 19 Sep 2002 22:38:46 +0000 Subject: [PATCH] Code cleanup git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1058 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Makensisw/makensisw.cpp | 25 ++++++------------ Contrib/Makensisw/makensisw.h | 39 ++++++++++------------------ Contrib/Makensisw/noclib.cpp | 13 ++++------ Contrib/Makensisw/noclib.h | 6 ++--- Contrib/Makensisw/utils.cpp | 46 +++++++++++++-------------------- Contrib/Makensisw/utils.h | 10 ------- Contrib/Makensisw/version.cpp | 5 ++-- 7 files changed, 49 insertions(+), 95 deletions(-) diff --git a/Contrib/Makensisw/makensisw.cpp b/Contrib/Makensisw/makensisw.cpp index 108fed7c..2ad8fff6 100644 --- a/Contrib/Makensisw/makensisw.cpp +++ b/Contrib/Makensisw/makensisw.cpp @@ -1,6 +1,6 @@ /* 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 warranty. In no event will the authors be held liable for any damages @@ -24,18 +24,16 @@ #include "resource.h" #include "noclib.h" -char *g_script; -int g_retcode; - static RECT resizeRect; static int dx; static int dy; +char *g_script; +int g_retcode; HINSTANCE g_hInstance; HWND g_hwnd; HANDLE g_hThread; BOOL g_warnings; - FINDREPLACE fr; UINT uFindReplaceMsg=0; HWND hwndFind=0; @@ -43,20 +41,18 @@ HWND hwndFind=0; int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow) { HACCEL haccel; g_hInstance=GetModuleHandle(0); - g_script=GetCommandLine(); // set commandline global string + g_script=GetCommandLine(); if (*g_script++=='"') while (*g_script++!='"'); else while (*g_script++!=' '); while (*g_script==' ') g_script++; if (!InitBranding()) { - MessageBox(0,"Unable to find makensis.exe.","Error",MB_ICONEXCLAMATION|MB_OK); + MessageBox(0,NSISERROR,"Error",MB_ICONEXCLAMATION|MB_OK); return 1; } ResetObjects(); HWND hDialog = CreateDialog(g_hInstance,MAKEINTRESOURCE(DLG_MAIN),0,DialogProc); if (!hDialog) { - char buf [MAX_STRING]; - wsprintf(buf, "Error creating dialog box.\n\nError: %x", GetLastError ()); - MessageBox(0, buf, "Error", MB_ICONEXCLAMATION | MB_OK); + MessageBox(0, DLGERROR, "Error", MB_ICONEXCLAMATION|MB_OK); return 1; } 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: { - if (!uFindReplaceMsg) - uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING); + if (!uFindReplaceMsg) uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING); my_memset(&fr, 0, sizeof(FINDREPLACE)); fr.lStructSize = sizeof(FINDREPLACE); 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.lpstrText = lpfr->lpstrFindWhat; ft.chrg.cpMin = SendDlgItemMessage(hwndDlg, IDC_LOGWIN, EM_FINDTEXTEX, flags, (LPARAM)&ft); - if (ft.chrg.cpMin != -1) - SendDlgItemMessage(hwndDlg, IDC_LOGWIN, EM_SETSEL, ft.chrgText.cpMin, ft.chrgText.cpMax); + if (ft.chrg.cpMin != -1) SendDlgItemMessage(hwndDlg, IDC_LOGWIN, EM_SETSEL, ft.chrgText.cpMin, ft.chrgText.cpMax); else MessageBeep(MB_ICONASTERISK); } if (lpfr->Flags & FR_DIALOGTERM) hwndFind = 0; @@ -345,7 +339,6 @@ DWORD WINAPI MakeNSISProc(LPVOID p) { SECURITY_DESCRIPTOR sd={0,}; PROCESS_INFORMATION pi={0,}; HANDLE newstdout=0,read_stdout=0; - OSVERSIONINFO osv={sizeof(osv)}; GetVersionEx(&osv); if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) { @@ -374,11 +367,9 @@ DWORD WINAPI MakeNSISProc(LPVOID p) { PostMessage(g_hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0); return 1; } - char szBuf[1024]; DWORD dwRead = 1; DWORD dwExit = !STILL_ACTIVE; - while (dwExit == STILL_ACTIVE || dwRead) { PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL); if (dwRead) { diff --git a/Contrib/Makensisw/makensisw.h b/Contrib/Makensisw/makensisw.h index baacd91e..ab1c6b30 100644 --- a/Contrib/Makensisw/makensisw.h +++ b/Contrib/Makensisw/makensisw.h @@ -1,6 +1,6 @@ /* 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 warranty. In no event will the authors be held liable for any damages @@ -23,6 +23,7 @@ #define MAKENSIS_H #include +#include "utils.h" #define _RICHEDIT_VER 0x0200 #include @@ -32,30 +33,34 @@ #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 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 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 REGKEY "Software\\NSIS" #define REGLOC "MakeNSISWPlacement" #define EXENAME "makensis.exe" #define MAX_STRING 256 -#define TIMEOUT 150 +#define TIMEOUT 100 #define MINWIDTH 350 #define MINHEIGHT 180 +#define REGSEC HKEY_LOCAL_MACHINE +#define REGKEY "Software\\NSIS" +#define REGLOC "MakeNSISWPlacement" #define WM_MAKENSIS_PROCESSCOMPLETE (WM_USER+1001) // Extern Variables -extern const char *NSISW_VERSION; -extern char *g_script; +extern const char* NSISW_VERSION; +extern char* g_script; extern HWND g_hwnd; extern HANDLE g_hThread; -extern char *g_output_exe; -extern char *g_input_script; -extern int g_retcode; +extern char * g_output_exe; +extern char * g_input_script; +extern int g_retcode; -// makensisw int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow); static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 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); 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 \ No newline at end of file diff --git a/Contrib/Makensisw/noclib.cpp b/Contrib/Makensisw/noclib.cpp index 0d4fbe51..73a6a708 100644 --- a/Contrib/Makensisw/noclib.cpp +++ b/Contrib/Makensisw/noclib.cpp @@ -1,6 +1,6 @@ /* 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 warranty. In no event will the authors be held liable for any damages @@ -18,21 +18,18 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. -*/ -/* -Contribution by kickik */ #include #include "noclib.h" +// kickik's clib methods char *my_strrchr(const char *string, int c) { - for (int i = lstrlen(string); i >= 0; i--) - if (string[i] == c) - return (char*)&string[i]; + for (int i=lstrlen(string); i>=0; i--) + if (string[i]==c) return (char*)&string[i]; return 0; } 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 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 SetBranding(HWND hwnd); void CopyToClipboard(HWND hwnd); diff --git a/Contrib/Makensisw/version.cpp b/Contrib/Makensisw/version.cpp index 5f76949b..b0cdd60b 100644 --- a/Contrib/Makensisw/version.cpp +++ b/Contrib/Makensisw/version.cpp @@ -1,6 +1,6 @@ /* 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 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. */ -// Turns a define into a string #define REALSTR(x) #x #define STR(x) REALSTR(x) #ifdef RELEASE const char *NSISW_VERSION = "MakeNSISW " STR(RELEASE); #else -const char *NSISW_VERSION = "MakeNSISW Local Build: " __DATE__; +const char *NSISW_VERSION = "MakeNSISW Build: " __DATE__; #endif \ No newline at end of file