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

Commit 287fc6f

Browse files
committed
installer: Improve user interaction
Improve the processing flow according to the return value of check tool: prohibits user to install HAXM only when the system hardware or OS does not support; allows user to retry when VMs are occupying HAXM; and if the system needs to be configured, prompts a warning but proceed installation. When uninstalling, only the occupancy of VMs is checked. * Add status and flags according to the error code of check tool * Update the function of checking environment to comply with check tool upgrade * Add message boxes to show and handle the check result for both installation and uninstallation process Signed-off-by: Wenchao Wang <[email protected]>
1 parent eee2a37 commit 287fc6f

File tree

6 files changed

+150
-50
lines changed

6 files changed

+150
-50
lines changed

Installer/HaxmSetup.nsi

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,39 @@ Section Main
5858
File "assets\checktool.exe"
5959
${Log} "Extract: checktool.exe... 100%"
6060

61+
Check:
6162
Call CheckEnv
63+
Pop $0
64+
65+
${Switch} $0
66+
${Case} ${ENV_STATUS_UNREADY}
67+
MessageBox MB_OK|MB_ICONEXCLAMATION "${DLG_WARNING}" /SD IDOK
68+
${Log} "${DLG_WARNING}"
69+
${Break}
70+
${Case} ${ENV_STATUS_INUSE}
71+
MessageBox MB_RETRYCANCEL|MB_ICONSTOP "${DLG_GUEST_ERROR}" /SD IDCANCEL \
72+
IDRETRY Check
73+
${Log} "${DLG_GUEST_ERROR}"
74+
${Exit} 0 3
75+
${Break}
76+
${Case} ${ENV_STATUS_UNSUPPORTED}
77+
MessageBox MB_OK|MB_ICONSTOP "${DLG_SYS_ERROR}" /SD IDOK
78+
${Log} "${DLG_SYS_ERROR}"
79+
Call Restore
80+
${Exit} 0 3
81+
${Break}
82+
${Default}
83+
${Break}
84+
${EndSwitch}
85+
6286
Call UninstallMsiVersion
6387
Call InstallDriver
6488

6589
; WriteUninstaller is not used directly because a signed binary is needed
6690
File "assets\uninstall.exe"
6791
${Log} "Create uninstaller: $INSTDIR\uninstall.exe"
68-
SectionEnd
6992

70-
Section -Post
71-
Call onInstalled
93+
Call LoadDriver
7294
SectionEnd
7395

7496
Function .onInit
@@ -93,33 +115,42 @@ Function CheckVersion
93115

94116
ClearErrors
95117
EnumRegKey $0 ${REG_ROOT_KEY} ${REG_KEY_PRODUCT} 0
96-
IfErrors not_installed installed
97-
not_installed:
98-
StrCpy $code 0
99-
${Log} "Version: ${PRODUCT_VERSION}"
118+
IfErrors NotInstalled Installed
119+
NotInstalled:
120+
StrCpy $code 0
121+
${Log} "Version: ${PRODUCT_VERSION}"
122+
Return
123+
Installed:
124+
ReadRegStr $0 ${REG_ROOT_KEY} ${REG_KEY_PRODUCT} "DisplayVersion"
125+
${VersionCompare} $0 ${PRODUCT_VERSION} $R0
126+
${Switch} $R0
127+
${Case} 0
128+
MessageBox MB_YESNO|MB_ICONQUESTION "${DLG_REINSTALL}" /SD IDYES IDYES \
129+
Reinstall
130+
${Exit} 1 0
131+
Reinstall:
132+
StrCpy $code 1
133+
${Log} "${LOG_REINSTALL}: $0"
134+
${Break}
135+
${Case} 1
136+
MessageBox MB_OK|MB_ICONEXCLAMATION "${DLG_DOWNGRADE}" /SD IDOK
137+
${Log} "${LOG_UNINSTALL}: $0"
138+
${Exit} 1 3
139+
${Break}
140+
${Default}
141+
StrCpy $code 2
142+
${Log} "${LOG_UPGRADE}: $0 => ${PRODUCT_VERSION}"
143+
${Break}
144+
${EndSwitch}
145+
FunctionEnd
146+
147+
Function Restore
148+
${If} $code != 0
100149
Return
101-
installed:
102-
ReadRegStr $0 ${REG_ROOT_KEY} ${REG_KEY_PRODUCT} "DisplayVersion"
103-
${VersionCompare} $0 ${PRODUCT_VERSION} $R0
104-
${Switch} $R0
105-
${Case} 0
106-
MessageBox MB_YESNO|MB_ICONQUESTION "${DLG_REINSTALL}" /SD IDYES IDYES \
107-
reinstall
108-
${Exit} 1 0
109-
reinstall:
110-
StrCpy $code 1
111-
${Log} "${LOG_REINSTALL}: $0"
112-
${Break}
113-
${Case} 1
114-
MessageBox MB_OK|MB_ICONEXCLAMATION "${DLG_DOWNGRADE}" /SD IDOK
115-
${Log} "${LOG_UNINSTALL}: $0"
116-
${Exit} 1 3
117-
${Break}
118-
${Default}
119-
StrCpy $code 2
120-
${Log} "${LOG_UPGRADE}: $0 => ${PRODUCT_VERSION}"
121-
${Break}
122-
${EndSwitch}
150+
${EndIf}
151+
152+
RMDir /r "$INSTDIR"
153+
${Log} "Delete folder: $INSTDIR"
123154
FunctionEnd
124155

125156
Function UninstallMsiVersion
@@ -174,7 +205,7 @@ Function InstallDriver
174205
${Log} "Copy to ${DRIVER_DIR}\${DRIVER_FILE}"
175206
FunctionEnd
176207

177-
Function onInstalled
208+
Function LoadDriver
178209
${If} $code == 0
179210
Call CreateService
180211
${EndIf}

Installer/RegOps.nsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
!endif
3737

3838
!include 'Log.nsh'
39-
!include 'Strings.nsh'
39+
!include 'Resources.nsh'
4040

4141
!ifdef INSTALL
4242

Installer/Strings.nsh renamed to Installer/Resources.nsh

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@
2828
* POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030

31-
!ifndef STRINGS_NSH_
32-
!define STRINGS_NSH_
31+
!ifndef RESOURCES_NSH_
32+
!define RESOURCES_NSH_
3333

34+
# Strings
3435
!define PRODUCT_NAME "HAXM"
3536
!define PRODUCT_FULL_NAME "Hardware Accelerated Execution Manager"
3637
!define PRODUCT_VERSION "7.6.5"
3738
!define PRODUCT_YEAR "2020"
3839
!define PRODUCT_PUBLISHER "Intel Corporation"
3940
!define PRODUCT_BRAND "Intel${U+00AE}"
4041
!define PRODUCT_WEBSITE "https://github.com/intel/haxm"
42+
!define PRODUCT_WIKIPAGE "/wiki/Windows-System-Configurations"
4143
!define PRODUCT_GUID "AAA802A8DF574F4CA0489512D2D91818"
4244

4345
!define PROGRAM_DIR "\Intel\${PRODUCT_NAME}"
@@ -60,15 +62,59 @@
6062
!define DRIVER_WIN7_64 "assets\win7\x64\${DRIVER_FILE}"
6163
!define DRIVER_WIN7_32 "assets\win7\x86\${DRIVER_FILE}"
6264

63-
!define DLG_CHECK_ENV "The system requirements are not satisfied."
64-
!define DLG_DOWNGRADE "The existing version is greater than the version to \
65+
!define DLG_SYS_ERROR "The system environment does not meet the \
66+
installation requirements."
67+
!define DLG_GUEST_ERROR "${PRODUCT_NAME} is being used by running virtual \
68+
machines now. Please terminate these virtual machine processes first."
69+
!define DLG_WARNING "The ${PRODUCT_NAME} driver can be installed on this \
70+
computer. However, it is required to further configure the system to \
71+
make it usable. Then ${PRODUCT_NAME} will be automatically loaded for \
72+
use."
73+
!define DLG_DOWNGRADE "The existing version is greater than the version to \
6574
be installed. Please uninstall the existing version manually before \
6675
proceeding."
67-
!define DLG_REINSTALL "${PRODUCT_NAME} v${PRODUCT_VERSION} has already been \
76+
!define DLG_REINSTALL "${PRODUCT_NAME} v${PRODUCT_VERSION} has already been \
6877
installed. Are you sure to continue?"
69-
!define DLG_UNINSTALL "Are you sure you want to remove $(^Name)?"
70-
!define LOG_REINSTALL "To reinstall the current version"
71-
!define LOG_UNINSTALL "To uninstall the current version"
72-
!define LOG_UPGRADE "To upgrade version"
78+
!define DLG_UNINSTALL "Are you sure you want to remove $(^Name)?"
79+
!define LOG_REINSTALL "To reinstall the current version"
80+
!define LOG_UNINSTALL "To uninstall the current version"
81+
!define LOG_UPGRADE "To upgrade version"
7382

74-
!endif # STRINGS_NSH_
83+
# Constants
84+
# Environment flags
85+
!define ENV_FLAG_CPU_SUPPORTED 0x00000001
86+
!define ENV_FLAG_VMX_SUPPORTED 0x00000002
87+
!define ENV_FLAG_NX_SUPPORTED 0x00000004
88+
!define ENV_FLAG_EM64T_SUPPORTED 0x00000008
89+
!define ENV_FLAG_EPT_SUPPORTED 0x00000010
90+
!define ENV_FLAG_VMX_ENABLED 0x00000100
91+
!define ENV_FLAG_NX_ENABLED 0x00000200
92+
!define ENV_FLAG_EM64T_ENABLED 0x00000400
93+
!define ENV_FLAG_OSVER_SUPPORTED 0x00010000
94+
!define ENV_FLAG_OSARCH_SUPPORTED 0x00020000
95+
!define ENV_FLAG_HYPERV_DISABLED 0x00040000
96+
!define ENV_FLAG_SANDBOX_DISABLED 0x00080000
97+
!define ENV_FLAG_GUEST_UNOCCUPIED 0x01000000
98+
99+
# Hardware supports:
100+
# ENV_FLAG_CPU_SUPPORTED, ENV_FLAG_VMX_SUPPORTED, ENV_FLAG_NX_SUPPORTED,
101+
# ENV_FLAG_EM64T_SUPPORTED, ENV_FLAG_EPT_SUPPORTED
102+
# OS supports:
103+
# ENV_FLAG_OSVER_SUPPORTED, ENV_FLAG_OSARCH_SUPPORTED
104+
!define ENV_FLAGS_SYS_SUPPORTED 0x000300ff
105+
# BIOS settings:
106+
# ENV_FLAG_VMX_ENABLED, ENV_FLAG_NX_ENABLED, ENV_FLAG_EM64T_ENABLED
107+
# OS settings:
108+
# ENV_FLAG_HYPERV_DISABLED, ENV_FLAG_SANDBOX_DISABLED
109+
!define ENV_FLAGS_HOST_READY 0x00fcff00
110+
# Guest status:
111+
# ENV_FLAG_GUEST_UNOCCUPIED
112+
!define ENV_FLAGS_GUEST_READY 0xff000000
113+
114+
# Environment status
115+
!define ENV_STATUS_READY 0
116+
!define ENV_STATUS_UNREADY 1
117+
!define ENV_STATUS_INUSE 2
118+
!define ENV_STATUS_UNSUPPORTED 3
119+
120+
!endif # RESOURCES_NSH_

Installer/UI.nsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
!include "MUI.nsh"
3535

36-
!include 'Strings.nsh'
36+
!include 'Resources.nsh'
3737

3838
RequestExecutionLevel admin
3939
ShowInstDetails show

Installer/Uninstall.nsi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@ Section Uninstall
5757

5858
${OpenLog}
5959
${Log} "Version: ${PRODUCT_VERSION}"
60+
Check:
6061
Call un.CheckEnv
62+
Pop $0
63+
64+
${If} $0 == ${ENV_STATUS_INUSE}
65+
MessageBox MB_RETRYCANCEL|MB_ICONSTOP "${DLG_GUEST_ERROR}" /SD IDCANCEL \
66+
IDRETRY Check
67+
${Log} "${DLG_GUEST_ERROR}"
68+
${Exit} 1 3
69+
${EndIf}
6170

6271
; Sometimes checktool.exe is still locked when removing $INSTDIR. Below two
6372
; parts ensure that checktool.exe is completely unlocked for removal.

Installer/Utils.nsh

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
!include "LogicLib.nsh"
3535

3636
!include 'Log.nsh'
37-
!include 'Strings.nsh'
37+
!include 'Resources.nsh'
3838

3939
# ExecCommand --------------------------
4040

@@ -91,6 +91,7 @@
9191
Abort
9292
${Break}
9393
${Default}
94+
Return
9495
${Break}
9596
${EndSwitch}
9697
!macroend
@@ -99,16 +100,29 @@
99100

100101
# CheckEnv -----------------------------
101102

103+
Var status
104+
105+
!macro CheckReturn Ret Flags
106+
IntOp $0 $status & ${Flags}
107+
108+
${If} $0 != 0
109+
Push ${Ret}
110+
Return
111+
${EndIf}
112+
!macroend
113+
114+
!define CheckReturn `!insertmacro CheckReturn`
115+
102116
!macro CheckEnv un
103117
Function ${un}CheckEnv
104-
${${un}ExecCommand} '$INSTDIR\checktool.exe --verbose' true
105-
Pop $0
118+
${${un}ExecCommand} '$INSTDIR\checktool.exe' true
119+
Pop $status
106120

107-
${If} $0 != "0"
108-
MessageBox MB_OK|MB_ICONSTOP "${DLG_CHECK_ENV}" /SD IDOK
109-
${Log} "${DLG_CHECK_ENV}"
110-
${Exit} 2 3
111-
${EndIf}
121+
${CheckReturn} ${ENV_STATUS_UNSUPPORTED} ${ENV_FLAGS_SYS_SUPPORTED}
122+
${CheckReturn} ${ENV_STATUS_INUSE} ${ENV_FLAGS_GUEST_READY}
123+
${CheckReturn} ${ENV_STATUS_UNREADY} ${ENV_FLAGS_HOST_READY}
124+
125+
Push ${ENV_STATUS_READY}
112126
FunctionEnd
113127
!macroend
114128

0 commit comments

Comments
 (0)