- added GetErrorLevel and SetErrorLevl

- fixed some inconsistencies in the error levels the installer/uninstaller set


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3668 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2004-09-25 10:49:08 +00:00
parent f4089b9d60
commit e82748702c
8 changed files with 45 additions and 14 deletions

View file

@ -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 \\<b\\>current\\</b\\>|all

View file

@ -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

View file

@ -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()

View file

@ -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

View file

@ -467,6 +467,7 @@ typedef struct
#endif
int instdir_error;
int rtl;
int errlvl;
} exec_flags;
#define FIELDN(x, y) (((int *)&x)[y])

View file

@ -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;

View file

@ -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},

View file

@ -237,6 +237,8 @@ enum
TOK_ENABLEWINDOW,
TOK_SETSILENT,
TOK_IFSILENT,
TOK_SETERRORLEVEL,
TOK_GETERRORLEVEL,
TOK_LOCKWINDOW,
TOK__LAST,