diff --git a/Docs/src/misc.but b/Docs/src/misc.but index 4aab15da..b1a99c60 100644 --- a/Docs/src/misc.but +++ b/Docs/src/misc.but @@ -1,5 +1,11 @@ \S1{miscinst} Miscellaneous Instructions +\S2{geterrorlevel} GetErrorLevel + +\c user_var(error level output) + +Returns the last error level set by \R{seterrorlevel}{SetErrorLevel} or -1 if it was never used. + \S2{getinstdirerror} GetInstDirError \c user_var(error output) @@ -16,6 +22,12 @@ Use in the leave function of a directory page. Reads the flag set if '\R{adirver Initializes the plugins dir (\R{varconstant}{$PLUGINSDIR}) if not already initialized. +\S2{seterrorlevel} SetErrorLevel + +\c error_level + +Sets the error level of the installer or uninstaller to \e{error_level}. See \R{errorlevels}{Error Levels} for more information. + \S2{setshellvarcontext} SetShellVarContext \c \\current\\|all diff --git a/Docs/src/usefulinfos.but b/Docs/src/usefulinfos.but index d8a8f819..769e64f9 100644 --- a/Docs/src/usefulinfos.but +++ b/Docs/src/usefulinfos.but @@ -20,21 +20,15 @@ When building with precompiled exehead .h files, you should set the USE_PRECOMPI Like other applications installers made by NSIS return error levels as a result of their execution. Checking the error level can be useful if you call an NSIS installer from another application or installer. -Normal installers: - \b 0 - Normal execution (no error) -\b 1 - Installation aborted by user +\b 1 - Installation aborted by user (cancel button) \b 2 - Installation aborted by script -Silent installers: +As of NSIS 2.01, you can set the error level to other values using \R{seterrorlevel}{SetErrorLevel}. -\b 0 - Normal execution (no error) - -\b 1 - Installation aborted by user - -\b 1 - Installation aborted by script +All of the above information applies both to installers and uninstallers. \H{useful_add_uninst_infos}Add uninstall information to Add/Remove Programs diff --git a/Source/exehead/Main.c b/Source/exehead/Main.c index 2012ad09..d2fbb256 100644 --- a/Source/exehead/Main.c +++ b/Source/exehead/Main.c @@ -70,7 +70,7 @@ char *ValidateTempDir() int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow) { - static int ret; + int ret; const char *m_Err = _LANG_ERRORWRITINGTEMP; int cl_flags = 0; @@ -81,6 +81,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, InitCommonControls(); + g_exec_flags.errlvl=-1; + #if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT) { extern HRESULT g_hres; @@ -243,6 +245,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, #endif//NSIS_CONFIG_UNINSTALL_SUPPORT ret = ui_doinstall(); + if (g_exec_flags.errlvl == -1) + g_exec_flags.errlvl = ret; #ifdef NSIS_CONFIG_LOG #ifndef NSIS_CONFIG_LOG_ODS @@ -254,13 +258,16 @@ end: CleanUp(); if (m_Err) + { my_MessageBox(m_Err, MB_OK | MB_ICONSTOP | (IDOK << 20)); + g_exec_flags.errlvl = 2; + } #if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT) OleUninitialize(); #endif - ExitProcess(ret); + ExitProcess(g_exec_flags.errlvl); } void NSISCALL CleanUp() diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index e9d242ae..737ee16a 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -302,7 +302,7 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) #ifdef NSIS_SUPPORT_CODECALLBACKS // Select language - if (ExecuteCallbackFunction(CB_ONINIT)) return 1; + if (ExecuteCallbackFunction(CB_ONINIT)) return 2; set_language(); #endif @@ -363,7 +363,7 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) #ifdef NSIS_SUPPORT_CODECALLBACKS if (!g_quit_flag) ExecuteCallbackFunction(CB_ONINSTFAILED); #endif//NSIS_SUPPORT_CODECALLBACKS - return 1; + return 2; } #ifdef NSIS_SUPPORT_CODECALLBACKS ExecuteCallbackFunction(CB_ONINSTSUCCESS); @@ -1596,7 +1596,7 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa { if (g_quit_flag) { - m_retcode=1; + m_retcode=2; outernotify(NOTIFY_BYE_BYE); } else diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h index f09c35de..08d117f3 100644 --- a/Source/exehead/fileform.h +++ b/Source/exehead/fileform.h @@ -467,6 +467,7 @@ typedef struct #endif int instdir_error; int rtl; + int errlvl; } exec_flags; #define FIELDN(x, y) (((int *)&x)[y]) diff --git a/Source/script.cpp b/Source/script.cpp index 3c9f218c..ad92190a 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -4280,6 +4280,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.offsets[1]=add_intstring(1); SCRIPT_MSG("SetErrors\n"); return add_entry(&ent); + case TOK_SETERRORLEVEL: + ent.which=EW_SETFLAG; + ent.offsets[0]=FLAG_OFFSET(errlvl); + ent.offsets[1]=add_string(line.gettoken_str(1)); + SCRIPT_MSG("SetErrorLevel: %s\n",line.gettoken_str(1)); + return add_entry(&ent); + case TOK_GETERRORLEVEL: + ent.which=EW_GETFLAG; + ent.offsets[0]=GetUserVarIndex(line, 1); + ent.offsets[1]=FLAG_OFFSET(errlvl); + if (line.gettoken_str(1)[0] && ent.offsets[0]<0) PRINTHELP() + SCRIPT_MSG("GetErrorLevel: %s\n",line.gettoken_str(1)); + return add_entry(&ent); #ifdef NSIS_SUPPORT_STROPTS case TOK_STRLEN: ent.which=EW_STRLEN; diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 02ea07f7..9b311ea4 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -177,6 +177,8 @@ static tokenType tokenlist[TOK__LAST] = {TOK_SETDETAILSVIEW,"SetDetailsView",1,0,"(hide|show)",TP_CODE}, {TOK_SETDETAILSPRINT,"SetDetailsPrint",1,0,"(none|listonly|textonly|both)",TP_CODE}, {TOK_SETERRORS,"SetErrors",0,0,"",TP_CODE}, +{TOK_SETERRORLEVEL,"SetErrorLevel",1,0,"error_level",TP_CODE}, +{TOK_GETERRORLEVEL,"GetErrorLevel",1,0,"$(user_var: output)",TP_CODE}, {TOK_SETFILEATTRIBUTES,"SetFileAttributes",2,0,"file attribute[|attribute[...]]\n attribute=(NORMAL|ARCHIVE|HIDDEN|OFFLINE|READONLY|SYSTEM|TEMPORARY|0)",TP_CODE}, {TOK_SETFONT,"SetFont",2,1,"[/LANG=lang_id] font_face_name font_size",TP_GLOBAL}, {TOK_SETOUTPATH,"SetOutPath",1,0,"output_path",TP_CODE}, diff --git a/Source/tokens.h b/Source/tokens.h index 29abb830..4442c132 100644 --- a/Source/tokens.h +++ b/Source/tokens.h @@ -237,6 +237,8 @@ enum TOK_ENABLEWINDOW, TOK_SETSILENT, TOK_IFSILENT, + TOK_SETERRORLEVEL, + TOK_GETERRORLEVEL, TOK_LOCKWINDOW, TOK__LAST,