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

Commit 455b127

Browse files
committed
installer: Improve silent installation
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]>
1 parent fcceb5a commit 455b127

File tree

5 files changed

+77
-47
lines changed

5 files changed

+77
-47
lines changed

Installer/HaxmSetup.nsi

+14-9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Unicode true
4141
!include 'UI.nsh'
4242
!include 'Utils.nsh'
4343

44+
Var level
4445
Var code
4546

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

62+
StrCpy $level 0
63+
6164
Check:
6265
Call CheckEnv
6366
Pop $0
@@ -66,18 +69,19 @@ Check:
6669
${Case} ${ENV_STATUS_UNREADY}
6770
MessageBox MB_OK|MB_ICONEXCLAMATION "${DLG_WARNING}" /SD IDOK
6871
${Log} "${DLG_WARNING}"
72+
StrCpy $level ${EXIT_FLAG_WARNING}
6973
${Break}
7074
${Case} ${ENV_STATUS_INUSE}
7175
MessageBox MB_RETRYCANCEL|MB_ICONSTOP "${DLG_GUEST_ERROR}" /SD IDCANCEL \
7276
IDRETRY Check
7377
${Log} "${DLG_GUEST_ERROR}"
74-
${Exit} 0 3
78+
${Exit} ${EXIT_MODE_NORMAL} ${EXIT_FLAG_ERROR}
7579
${Break}
7680
${Case} ${ENV_STATUS_UNSUPPORTED}
7781
MessageBox MB_OK|MB_ICONSTOP "${DLG_SYS_ERROR}" /SD IDOK
7882
${Log} "${DLG_SYS_ERROR}"
7983
Call Restore
80-
${Exit} 0 3
84+
${Exit} ${EXIT_MODE_NORMAL} ${EXIT_FLAG_ERROR}
8185
${Break}
8286
${Default}
8387
${Break}
@@ -91,6 +95,9 @@ Check:
9195
${Log} "Create uninstaller: $INSTDIR\uninstall.exe"
9296

9397
Call LoadDriver
98+
99+
IntOp $code $level | $code
100+
${Exit} ${EXIT_MODE_NORMAL} $code
94101
SectionEnd
95102

96103
Function .onInit
@@ -127,18 +134,18 @@ Installed:
127134
${Case} 0
128135
MessageBox MB_YESNO|MB_ICONQUESTION "${DLG_REINSTALL}" /SD IDYES IDYES \
129136
Reinstall
130-
${Exit} 1 0
137+
${Exit} ${EXIT_MODE_QUIT} 0
131138
Reinstall:
132-
StrCpy $code 1
139+
StrCpy $code ${EXIT_FLAG_REINSTALL}
133140
${Log} "${LOG_REINSTALL}: $0"
134141
${Break}
135142
${Case} 1
136143
MessageBox MB_OK|MB_ICONEXCLAMATION "${DLG_DOWNGRADE}" /SD IDOK
137144
${Log} "${LOG_UNINSTALL}: $0"
138-
${Exit} 1 3
145+
${Exit} ${EXIT_MODE_QUIT} ${EXIT_FLAG_ERROR}
139146
${Break}
140147
${Default}
141-
StrCpy $code 2
148+
StrCpy $code ${EXIT_FLAG_UPGRADE}
142149
${Log} "${LOG_UPGRADE}: $0 => ${PRODUCT_VERSION}"
143150
${Break}
144151
${EndSwitch}
@@ -212,8 +219,6 @@ Function LoadDriver
212219

213220
Call StartService
214221
Call CreateRegItems
215-
216-
${Exit} 0 $code
217222
FunctionEnd
218223

219224
Function onFinished
@@ -239,5 +244,5 @@ Function onFinished
239244
FunctionEnd
240245

241246
Function onAbort
242-
${Exit} 0 0
247+
${Exit} ${EXIT_MODE_NORMAL} 0
243248
FunctionEnd

Installer/Resources.nsh

+12
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,16 @@
153153
!define ENV_STATUS_INUSE 2
154154
!define ENV_STATUS_UNSUPPORTED 3
155155

156+
# Exit code (%ERRORLEVEL%):
157+
# Status levels
158+
!define EXIT_FLAG_WARNING 0x00000001
159+
!define EXIT_FLAG_ERROR 0x00000002
160+
# Operation methods
161+
!define EXIT_FLAG_REINSTALL 0x00000010
162+
!define EXIT_FLAG_UPGRADE 0x00000020
163+
# Exit mode:
164+
!define EXIT_MODE_NORMAL 0
165+
!define EXIT_MODE_QUIT 1
166+
!define EXIT_MODE_ABORT 2
167+
156168
!endif # RESOURCES_NSH_

Installer/Uninstall.nsi

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ SectionEnd
4848
Function un.onInit
4949
MessageBox MB_YESNO|MB_ICONEXCLAMATION "${DLG_UNINSTALL}" /SD IDYES IDYES \
5050
Uninstall
51-
${Exit} 2 0
51+
${Exit} ${EXIT_MODE_ABORT} 0
5252
Uninstall:
5353
FunctionEnd
5454

@@ -65,7 +65,7 @@ Check:
6565
MessageBox MB_RETRYCANCEL|MB_ICONSTOP "${DLG_GUEST_ERROR}" /SD IDCANCEL \
6666
IDRETRY Check
6767
${Log} "${DLG_GUEST_ERROR}"
68-
${Exit} 1 3
68+
${Exit} ${EXIT_MODE_QUIT} ${EXIT_FLAG_ERROR}
6969
${EndIf}
7070

7171
; Sometimes checktool.exe is still locked when removing $INSTDIR. Below two
@@ -84,7 +84,7 @@ Check:
8484

8585
${If} $1 == 1
8686
${Log} "Error: Installed program files are being locked."
87-
${Exit} 0 3
87+
${Exit} ${EXIT_MODE_NORMAL} ${EXIT_FLAG_ERROR}
8888
${EndIf}
8989

9090
Remove:
@@ -99,5 +99,5 @@ Remove:
9999
${Log} "Delete folder: $INSTDIR"
100100

101101
SetAutoClose true
102-
${Exit} 0 0
102+
${Exit} ${EXIT_MODE_NORMAL} 0
103103
SectionEnd

Installer/Utils.nsh

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@
8484
${CloseLog}
8585
SetErrorLevel ${Code}
8686
${Switch} ${Mode}
87-
${Case} 1
87+
${Case} ${EXIT_MODE_QUIT}
8888
Quit
8989
${Break}
90-
${Case} 2
90+
${Case} ${EXIT_MODE_ABORT}
9191
Abort
9292
${Break}
9393
${Default}

Installer/silent_install.bat

+45-32
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,36 @@ set timestamp=
8787
for /f "tokens=2 delims=-" %%i in ("%filename%") do set version=%%i
8888
call :log Start to install HAXM v%version%
8989
if exist %installer% %installer% /S
90+
if %errorlevel% equ 5 (
91+
:: Cancelled UAC confirmation dialog when not running as administrator
92+
call :log User canceled
93+
set exit_code=1
94+
goto in_exit
95+
)
9096
for %%i in (haxm_install-*.log) do set log=%%i
9197
call :log Log saved: %TEMP%\%log%
92-
goto in_exit%errorlevel%
93-
:in_exit0
94-
echo Intel HAXM installed successfully!
95-
goto in_end
96-
:in_exit1
97-
echo Intel HAXM reinstalled successfully!
98-
goto in_end
99-
:in_exit2
100-
echo Intel HAXM upgraded successfully!
101-
goto in_end
102-
:in_exit3
103-
echo Intel HAXM installation failed!
104-
echo For more details, please check the installation log: %TEMP%\%log%
105-
set exit_code=1
106-
goto in_end
107-
:in_exit5
108-
:in_end
98+
if %errorlevel% equ 2 (
99+
echo Intel HAXM installation failed!
100+
echo For more details, please check the installation log: %TEMP%\%log%
101+
set exit_code=1
102+
goto in_exit
103+
)
104+
set /a status="%errorlevel% & 0x0f"
105+
set /a method="%errorlevel% & 0xf0"
106+
if %method% equ 0 (
107+
set installed=installed
108+
) else if %method% equ 0x10 (
109+
set installed=reinstalled
110+
) else if %method% equ 0x20 (
111+
set installed=upgraded
112+
) else goto in_exit
113+
if %status% equ 0x01 (
114+
echo Intel HAXM is %installed% but cannot be used until the system settings are ready.
115+
echo For more details, please check the installation log: %TEMP%\%log%
116+
goto in_exit
117+
)
118+
echo Intel HAXM %installed% successfully!
119+
:in_exit
109120
if exist %log% del /f %log%
110121
call :log End of installation
111122
exit /b %exit_code%
@@ -117,38 +128,40 @@ set timestamp=
117128
set uninstaller=%install_path%\uninstall.exe
118129
if not exist %uninstaller% (
119130
echo Intel HAXM is not installed.
120-
goto un_end
131+
call :log HAXM not found
132+
goto un_exit
121133
)
122134
:: Run below command to check if running as administrator
123-
net session >nul 2>&1 || goto un_exit1
135+
net session >nul 2>&1 || goto un_fail
124136
:: Add _?= to execute uninstaller synchronously.
125137
:: By default, the uninstaller copies itself to the temporary directory and
126138
:: run asynchronously there.
127139
%uninstaller% /S _?=%ProgramFiles%\Intel\HAXM
128140
for %%i in (haxm_uninstall-*.log) do set log=%%i
129141
call :log Log saved: %TEMP%\%log%
130-
goto un_exit%errorlevel%
131-
:un_exit0
142+
if %errorlevel% equ 2 (
143+
echo Intel HAXM uninstallation failed!
144+
echo Please terminate the running virtual machine processes first.
145+
set exit_code=1
146+
goto un_exit
147+
)
132148
:: Rename installation folder to check if any files are locked.
133149
for %%i in (0, 1, 2) do (
134150
ren %install_path% HAXM 2>nul && goto break || timeout 5 >nul
135151
)
136-
goto un_exit3
152+
echo Intel HAXM uninstallation failed!
153+
echo For more details, please check the installation log: %TEMP%\%log%
154+
set exit_code=1
155+
goto un_exit
137156
:break
138157
if exist %install_path% rmdir /s /q %install_path%
139158
echo Intel HAXM uninstalled successfully!
140-
goto un_end
141-
:un_exit1
159+
goto un_exit
160+
:un_fail
161+
call :log Permission denied
142162
echo Please run this command as administrator!
143163
set exit_code=1
144-
goto un_end
145-
:un_exit3
146-
echo Intel HAXM uninstallation failed!
147-
echo For more details, please check the uninstallation log: %TEMP%\%log%
148-
set exit_code=1
149-
goto un_end
150-
:un_exit5
151-
:un_end
164+
:un_exit
152165
if exist %log% del /f %log%
153166
call :log End of uninstallation
154167
exit /b %exit_code%

0 commit comments

Comments
 (0)