Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
installer: Improve silent installation
Browse files Browse the repository at this point in the history
When some OS features or some BIOS settings need to be changed, prompt
user to perform further settings after installation, otherwise HAXM
will not work properly.

* In case of successful installation, add a level of warning in the
  installer exit code to provide extra messages in the command output
* Uninstallation only fails when there are virtual machines running on
  HAXM
* Add macro definitions for exit mode

Signed-off-by: Wenchao Wang <[email protected]>
  • Loading branch information
wcwang committed Nov 6, 2022
1 parent cde1006 commit 8b7b2be
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 47 deletions.
23 changes: 14 additions & 9 deletions Installer/HaxmSetup.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Unicode true
!include 'UI.nsh'
!include 'Utils.nsh'

Var level
Var code

Section Main
Expand All @@ -58,6 +59,8 @@ Section Main
File "assets\checktool.exe"
${Log} "Extract: checktool.exe... 100%"

StrCpy $level 0

Check:
Call CheckEnv
Pop $0
Expand All @@ -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}
Expand All @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -212,8 +219,6 @@ Function LoadDriver

Call StartService
Call CreateRegItems

${Exit} 0 $code
FunctionEnd

Function onFinished
Expand All @@ -239,5 +244,5 @@ Function onFinished
FunctionEnd

Function onAbort
${Exit} 0 0
${Exit} ${EXIT_MODE_NORMAL} 0
FunctionEnd
12 changes: 12 additions & 0 deletions Installer/Resources.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -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_
8 changes: 4 additions & 4 deletions Installer/Uninstall.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -99,5 +99,5 @@ Remove:
${Log} "Delete folder: $INSTDIR"

SetAutoClose true
${Exit} 0 0
${Exit} ${EXIT_MODE_NORMAL} 0
SectionEnd
4 changes: 2 additions & 2 deletions Installer/Utils.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
77 changes: 45 additions & 32 deletions Installer/silent_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand All @@ -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%
Expand Down

0 comments on commit 8b7b2be

Please sign in to comment.