diff --git a/Installer/HaxmSetup.nsi b/Installer/HaxmSetup.nsi index 1250758f..f1e65aff 100644 --- a/Installer/HaxmSetup.nsi +++ b/Installer/HaxmSetup.nsi @@ -41,6 +41,7 @@ Unicode true !include 'UI.nsh' !include 'Utils.nsh' +Var level Var code Section Main @@ -58,6 +59,8 @@ Section Main File "assets\checktool.exe" ${Log} "Extract: checktool.exe... 100%" + StrCpy $level 0 + Check: Call CheckEnv Pop $0 @@ -66,18 +69,19 @@ Check: ${Case} ${ENV_STATUS_UNREADY} MessageBox MB_OK|MB_ICONEXCLAMATION "${DLG_WARNING}" /SD IDOK ${Log} "${DLG_WARNING}" + StrCpy $level ${EXIT_FLAG_WARNING} ${Break} ${Case} ${ENV_STATUS_INUSE} MessageBox MB_RETRYCANCEL|MB_ICONSTOP "${DLG_GUEST_ERROR}" /SD IDCANCEL \ IDRETRY Check ${Log} "${DLG_GUEST_ERROR}" - ${Exit} 0 3 + ${Exit} ${EXIT_MODE_NORMAL} ${EXIT_FLAG_ERROR} ${Break} ${Case} ${ENV_STATUS_UNSUPPORTED} MessageBox MB_OK|MB_ICONSTOP "${DLG_SYS_ERROR}" /SD IDOK ${Log} "${DLG_SYS_ERROR}" Call Restore - ${Exit} 0 3 + ${Exit} ${EXIT_MODE_NORMAL} ${EXIT_FLAG_ERROR} ${Break} ${Default} ${Break} @@ -91,6 +95,9 @@ Check: ${Log} "Create uninstaller: $INSTDIR\uninstall.exe" Call LoadDriver + + IntOp $code $level | $code + ${Exit} ${EXIT_MODE_NORMAL} $code SectionEnd Function .onInit @@ -127,18 +134,18 @@ Installed: ${Case} 0 MessageBox MB_YESNO|MB_ICONQUESTION "${DLG_REINSTALL}" /SD IDYES IDYES \ Reinstall - ${Exit} 1 0 + ${Exit} ${EXIT_MODE_QUIT} 0 Reinstall: - StrCpy $code 1 + StrCpy $code ${EXIT_FLAG_REINSTALL} ${Log} "${LOG_REINSTALL}: $0" ${Break} ${Case} 1 MessageBox MB_OK|MB_ICONEXCLAMATION "${DLG_DOWNGRADE}" /SD IDOK ${Log} "${LOG_UNINSTALL}: $0" - ${Exit} 1 3 + ${Exit} ${EXIT_MODE_QUIT} ${EXIT_FLAG_ERROR} ${Break} ${Default} - StrCpy $code 2 + StrCpy $code ${EXIT_FLAG_UPGRADE} ${Log} "${LOG_UPGRADE}: $0 => ${PRODUCT_VERSION}" ${Break} ${EndSwitch} @@ -212,8 +219,6 @@ Function LoadDriver Call StartService Call CreateRegItems - - ${Exit} 0 $code FunctionEnd Function onFinished @@ -239,5 +244,5 @@ Function onFinished FunctionEnd Function onAbort - ${Exit} 0 0 + ${Exit} ${EXIT_MODE_NORMAL} 0 FunctionEnd diff --git a/Installer/Resources.nsh b/Installer/Resources.nsh index b6f7b49b..3c5926db 100644 --- a/Installer/Resources.nsh +++ b/Installer/Resources.nsh @@ -153,4 +153,16 @@ !define ENV_STATUS_INUSE 2 !define ENV_STATUS_UNSUPPORTED 3 +# Exit code (%ERRORLEVEL%): +# Status levels +!define EXIT_FLAG_WARNING 0x00000001 +!define EXIT_FLAG_ERROR 0x00000002 +# Operation methods +!define EXIT_FLAG_REINSTALL 0x00000010 +!define EXIT_FLAG_UPGRADE 0x00000020 +# Exit mode: +!define EXIT_MODE_NORMAL 0 +!define EXIT_MODE_QUIT 1 +!define EXIT_MODE_ABORT 2 + !endif # RESOURCES_NSH_ diff --git a/Installer/Uninstall.nsi b/Installer/Uninstall.nsi index f8d5d4c9..70270480 100644 --- a/Installer/Uninstall.nsi +++ b/Installer/Uninstall.nsi @@ -48,7 +48,7 @@ SectionEnd Function un.onInit MessageBox MB_YESNO|MB_ICONEXCLAMATION "${DLG_UNINSTALL}" /SD IDYES IDYES \ Uninstall - ${Exit} 2 0 + ${Exit} ${EXIT_MODE_ABORT} 0 Uninstall: FunctionEnd @@ -65,7 +65,7 @@ Check: MessageBox MB_RETRYCANCEL|MB_ICONSTOP "${DLG_GUEST_ERROR}" /SD IDCANCEL \ IDRETRY Check ${Log} "${DLG_GUEST_ERROR}" - ${Exit} 1 3 + ${Exit} ${EXIT_MODE_QUIT} ${EXIT_FLAG_ERROR} ${EndIf} ; Sometimes checktool.exe is still locked when removing $INSTDIR. Below two @@ -84,7 +84,7 @@ Check: ${If} $1 == 1 ${Log} "Error: Installed program files are being locked." - ${Exit} 0 3 + ${Exit} ${EXIT_MODE_NORMAL} ${EXIT_FLAG_ERROR} ${EndIf} Remove: @@ -99,5 +99,5 @@ Remove: ${Log} "Delete folder: $INSTDIR" SetAutoClose true - ${Exit} 0 0 + ${Exit} ${EXIT_MODE_NORMAL} 0 SectionEnd diff --git a/Installer/Utils.nsh b/Installer/Utils.nsh index 0f0d8dce..1fad9552 100644 --- a/Installer/Utils.nsh +++ b/Installer/Utils.nsh @@ -84,10 +84,10 @@ ${CloseLog} SetErrorLevel ${Code} ${Switch} ${Mode} - ${Case} 1 + ${Case} ${EXIT_MODE_QUIT} Quit ${Break} - ${Case} 2 + ${Case} ${EXIT_MODE_ABORT} Abort ${Break} ${Default} diff --git a/Installer/silent_install.bat b/Installer/silent_install.bat index a65fa0ea..a7c849da 100644 --- a/Installer/silent_install.bat +++ b/Installer/silent_install.bat @@ -87,25 +87,36 @@ set timestamp= for /f "tokens=2 delims=-" %%i in ("%filename%") do set version=%%i call :log Start to install HAXM v%version% if exist %installer% %installer% /S + if %errorlevel% equ 5 ( + :: Cancelled UAC confirmation dialog when not running as administrator + call :log User canceled + set exit_code=1 + goto in_exit + ) for %%i in (haxm_install-*.log) do set log=%%i call :log Log saved: %TEMP%\%log% - goto in_exit%errorlevel% -:in_exit0 - echo Intel HAXM installed successfully! - goto in_end -:in_exit1 - echo Intel HAXM reinstalled successfully! - goto in_end -:in_exit2 - echo Intel HAXM upgraded successfully! - goto in_end -:in_exit3 - echo Intel HAXM installation failed! - echo For more details, please check the installation log: %TEMP%\%log% - set exit_code=1 - goto in_end -:in_exit5 -:in_end + if %errorlevel% equ 2 ( + echo Intel HAXM installation failed! + echo For more details, please check the installation log: %TEMP%\%log% + set exit_code=1 + goto in_exit + ) + set /a status="%errorlevel% & 0x0f" + set /a method="%errorlevel% & 0xf0" + if %method% equ 0 ( + set installed=installed + ) else if %method% equ 0x10 ( + set installed=reinstalled + ) else if %method% equ 0x20 ( + set installed=upgraded + ) else goto in_exit + if %status% equ 0x01 ( + echo Intel HAXM is %installed% but cannot be used until the system settings are ready. + echo For more details, please check the installation log: %TEMP%\%log% + goto in_exit + ) + echo Intel HAXM %installed% successfully! +:in_exit if exist %log% del /f %log% call :log End of installation exit /b %exit_code% @@ -117,38 +128,40 @@ set timestamp= set uninstaller=%install_path%\uninstall.exe if not exist %uninstaller% ( echo Intel HAXM is not installed. - goto un_end + call :log HAXM not found + goto un_exit ) :: Run below command to check if running as administrator - net session >nul 2>&1 || goto un_exit1 + net session >nul 2>&1 || goto un_fail :: Add _?= to execute uninstaller synchronously. :: By default, the uninstaller copies itself to the temporary directory and :: run asynchronously there. %uninstaller% /S _?=%ProgramFiles%\Intel\HAXM for %%i in (haxm_uninstall-*.log) do set log=%%i call :log Log saved: %TEMP%\%log% - goto un_exit%errorlevel% -:un_exit0 + if %errorlevel% equ 2 ( + echo Intel HAXM uninstallation failed! + echo Please terminate the running virtual machine processes first. + set exit_code=1 + goto un_exit + ) :: Rename installation folder to check if any files are locked. for %%i in (0, 1, 2) do ( ren %install_path% HAXM 2>nul && goto break || timeout 5 >nul ) - goto un_exit3 + echo Intel HAXM uninstallation failed! + echo For more details, please check the installation log: %TEMP%\%log% + set exit_code=1 + goto un_exit :break if exist %install_path% rmdir /s /q %install_path% echo Intel HAXM uninstalled successfully! - goto un_end -:un_exit1 + goto un_exit +:un_fail + call :log Permission denied echo Please run this command as administrator! set exit_code=1 - goto un_end -:un_exit3 - echo Intel HAXM uninstallation failed! - echo For more details, please check the uninstallation log: %TEMP%\%log% - set exit_code=1 - goto un_end -:un_exit5 -:un_end +:un_exit if exist %log% del /f %log% call :log End of uninstallation exit /b %exit_code%