Skip to content

Commit 45232ca

Browse files
committed
Installer: Return well defined error code for install fail conditions
A few macros had to be adapted that used relative jump marks. Relative jump marks are not practical for macros in macros. Thus, the solution through a unique id (caller line number) was added.
1 parent 94977b8 commit 45232ca

File tree

2 files changed

+95
-43
lines changed

2 files changed

+95
-43
lines changed

Packages/doc/installation.rst

+17
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,23 @@ If the installation was run silent then the uninstaller is also called silent.
132132
The user can only uninstall previous installations from himself. If the previous installation
133133
was done by an admin the uninstaller will ask for privilege elevation.
134134

135+
List of Installer Return Codes
136+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137+
138+
+-------------+---------------------------------------------------------------------------------------------------------------------------------+--+--+--+--+--+--+--+--+
139+
| Return Code | Description | | | | | | | | |
140+
+=============+=================================================================================================================================+==+==+==+==+==+==+==+==+
141+
| 0 | No Error | | | | | | | | |
142+
| 1 | Another instance of the installer is already running | | | | | | | | |
143+
| 2 | Another instance of the uninstaller is already running | | | | | | | | |
144+
| 3 | Can not retrieve list of currently running processes | | | | | | | | |
145+
| 4 | The installation is run as non-admin user but a MIES installation that was installed with admin privileges is already present. | | | | | | | | |
146+
| 5 | Igor.exe is currently running | | | | | | | | |
147+
| 6 | Igor64.exe is currently running | | | | | | | | |
148+
| 7 | MIES requires a 64-bit operating system | | | | | | | | |
149+
| 8 | Admin privileges required | | | | | | | | |
150+
+-------------+---------------------------------------------------------------------------------------------------------------------------------+--+--+--+--+--+--+--+--+
151+
135152
Corrupted installations
136153
^^^^^^^^^^^^^^^^^^^^^^^
137154

tools/installer/installer.nsi

+78-43
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@
4545
# Temp file for command execution output for ExecDos::Exec
4646
!define EXECDOSOUTPUT "ExecOutput.log"
4747

48+
# Return codes
49+
!define ERROR_INSTALLER_ALREADY_RUNNING 1
50+
!define ERROR_UNINSTALLER_ALREADY_RUNNING 2
51+
!define ERROR_CANNOT_GET_TASKLIST 3
52+
!define ERROR_ADMIN_INSTALLATION_PRESENT 4
53+
!define ERROR_IGORPRO_IS_RUNNING 5
54+
!define ERROR_IGORPRO64_IS_RUNNING 6
55+
!define ERROR_64BIT_OS_REQUIRED 7
56+
!define ERROR_ADMIN_REQUIRED 8
57+
!define ERROR_MIES_ALREADY_INSTALLED 9
58+
!define ERROR_NO_IGOR9_PATH 10
59+
!define ERROR_NO_IGOR10_PATH 11
60+
!define ERROR_CANNOT_CREATE_UNINSTALL_FILELIST 12
61+
!define ERROR_CANNOT_DISABLE_ASLR 13
62+
!define ERROR_CANNOT_FIX_OFFICE365 14
63+
!define ERROR_CANNOT_CREATE_INSTALLCONFIG 15
64+
!define ERROR_ELEVATION_REQUIRED 740
65+
4866
#Unicode true
4967
SetCompressor /SOLID lzma
5068
!include "${NSISREQUEST}"
@@ -113,22 +131,29 @@ Var NSD_IF_CB4
113131

114132
!include "browsefolder.nsh"
115133

116-
!macro PreventMultipleInstaller
134+
!macro QuitWithCode code
135+
SetErrorLevel code
136+
Quit
137+
!macroend
138+
139+
!macro PreventMultipleInstaller uid
117140
System::Call 'kernel32::CreateMutex(p 0, i 0, t "MIESINSTALLMutex") p .r1 ?e'
118141
Pop $R0
119-
StrCmp $R0 0 +4
142+
StrCmp $R0 0 MacroEnd_${uid}
120143
IfSilent +2
121144
MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."
122-
Quit
145+
!insertmacro QuitWithCode ERROR_INSTALLER_ALREADY_RUNNING
146+
MacroEnd_${uid}:
123147
!macroend
124148

125-
!macro PreventMultipleUninstaller
149+
!macro PreventMultipleUninstaller uid
126150
System::Call 'kernel32::CreateMutex(p 0, i 0, t "MIESUNINSTALLMutex") p .r1 ?e'
127151
Pop $R0
128-
StrCmp $R0 0 +4
152+
StrCmp $R0 0 MacroEnd_${uid}
129153
IfSilent +2
130154
MessageBox MB_OK|MB_ICONEXCLAMATION "The uninstaller is already running."
131-
Quit
155+
!insertmacro QuitWithCode ERROR_UNINSTALLER_ALREADY_RUNNING
156+
MacroEnd_${uid}:
132157
!macroend
133158

134159
!macro FindProc result processName uid
@@ -148,7 +173,7 @@ Var NSD_IF_CB4
148173
${if} $0 <> 0
149174
IfSilent +2
150175
MessageBox MB_OK|MB_ICONEXCLAMATION "Can not get current task list through tasklist.exe."
151-
Quit
176+
!insertmacro QuitWithCode ERROR_CANNOT_GET_TASKLIST
152177
${EndIf}
153178

154179
ReadEnvStr $0 TEMP
@@ -169,7 +194,7 @@ Var NSD_IF_CB4
169194
Delete $1\${EXECDOSOUTPUT}
170195
!macroend
171196

172-
!macro CheckAllUninstalled
197+
!macro CheckAllUninstalled uid
173198
StrCpy $2 "0"
174199
ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName"
175200
StrLen $1 $0
@@ -186,10 +211,11 @@ Var NSD_IF_CB4
186211
IfFileExists "${USERINSTDIR}\uninstall.exe" 0 +2
187212
StrCpy $2 "1"
188213

189-
IntCmp $2 0 +4
214+
IntCmp $2 0 MacroEnd_${uid}
190215
ifSilent +2
191216
MessageBox MB_OK|MB_ICONSTOP "There is a already a installation of MIES present that was installed with administrative privileges. Uninstallation requires administrative privileges as well and can not be done with your current rights. Please contact an administrator to uninstall MIES through Add/Remove Programs first."
192-
Quit
217+
!insertmacro QuitWithCode ERROR_ADMIN_INSTALLATION_PRESENT
218+
MacroEnd_${uid}:
193219
!macroend
194220

195221
!macro UninstallAttemptAdmin
@@ -255,20 +281,22 @@ WFUEndWaitUninstA_${WFPID}:
255281
${EndIf}
256282
!macroend
257283

258-
!macro StopOnIgor32
284+
!macro StopOnIgor32 uid
259285
!insertmacro FindProc $processFound "Igor.exe" ${__LINE__}
260-
IntCmp $processFound ${FindProc_NOT_FOUND} +4
286+
IntCmp $processFound ${FindProc_NOT_FOUND} MacroEnd_${uid}
261287
IfSilent +2
262288
MessageBox MB_OK|MB_ICONEXCLAMATION "Igor Pro is running. Please close it first" /SD IDOK
263-
Quit
289+
!insertmacro QuitWithCode ERROR_IGORPRO_IS_RUNNING
290+
MacroEnd_${uid}:
264291
!macroend
265292

266-
!macro StopOnIgor64
293+
!macro StopOnIgor64 uid
267294
!insertmacro FindProc $processFound "Igor64.exe" ${__LINE__}
268-
IntCmp $processFound ${FindProc_NOT_FOUND} +4
295+
IntCmp $processFound ${FindProc_NOT_FOUND} MacroEnd_${uid}
269296
IfSilent +2
270297
MessageBox MB_OK|MB_ICONEXCLAMATION "Igor Pro (64-bit) is running. Please close it first" /SD IDOK
271-
Quit
298+
!insertmacro QuitWithCode ERROR_IGORPRO64_IS_RUNNING
299+
MacroEnd_${uid}:
272300
!macroend
273301

274302
!macro SetInstallPath
@@ -467,7 +495,7 @@ function .onInit
467495
${IfNot} ${RunningX64}
468496
IfSilent +2
469497
MessageBox MB_OK|MB_ICONEXCLAMATION "Aborting: MIES requires a 64-bit Windows OS."
470-
Quit
498+
!insertmacro QuitWithCode ERROR_64BIT_OS_REQUIRED
471499
${EndIf}
472500

473501
ClearErrors
@@ -497,7 +525,7 @@ function .onInit
497525
QuitCantAlluser:
498526
IfSilent +2
499527
MessageBox MB_OK|MB_ICONEXCLAMATION "Aborting: You need to administrator privileges for /ALLUSER installation."
500-
Quit
528+
!insertmacro QuitWithCode ERROR_ADMIN_REQUIRED
501529
${EndIf}
502530

503531
CheckIgorPaths:
@@ -554,15 +582,15 @@ IGOR10CheckEnd:
554582
${If} ${Errors}
555583
# normal installation
556584

557-
!insertmacro PreventMultipleInstaller
558-
!insertmacro StopOnIgor32
559-
!insertmacro StopOnIgor64
585+
!insertmacro PreventMultipleInstaller ${__LINE__}
586+
!insertmacro StopOnIgor32 ${__LINE__}
587+
!insertmacro StopOnIgor64 ${__LINE__}
560588
IntCmp $ISADMIN 0 SkipAdminUninstall
561589
!insertmacro UninstallAttemptAdmin
562590
SkipAdminUninstall:
563591
!insertmacro UninstallAttemptUser
564592

565-
!insertmacro CheckAllUninstalled
593+
!insertmacro CheckAllUninstalled ${__LINE__}
566594
${EndIf}
567595

568596
!insertmacro SetInstallPath
@@ -594,13 +622,14 @@ CLTDone_${CLTID}:
594622
!undef CLTID
595623
!macroend
596624

597-
!macro CheckMIESPresent Path NiceInfo
625+
!macro CheckMIESPresent Path NiceInfo uid
598626
!insertmacro CheckLinkTarget "${Path}\Igor Procedures" "MIES_Include.ipf"
599627
Pop $1
600-
IntCmp $1 0 +4
628+
IntCmp $1 0 MacroEnd_${uid}
601629
IfSilent +2
602630
MessageBox MB_OK|MB_ICONSTOP "It appears that there is already MIES for ${NiceInfo} installed. Please remove MIES manually first."
603-
Quit
631+
!insertmacro QuitWithCode ERROR_MIES_ALREADY_INSTALLED
632+
MacroEnd_${uid}:
604633
!macroend
605634

606635
!macro CreateIgorDirs
@@ -672,31 +701,30 @@ MIESCheck9:
672701
StrLen $0 $INSTALL_I9PATH
673702
${If} $0 = 0
674703
IfSilent +2
675-
MessageBox MB_OK "Bug: I have no Igor 9 Path."
676-
Quit
704+
MessageBox MB_OK "Bug: I have no Igor 9 Path."
705+
!insertmacro QuitWithCode ERROR_NO_IGOR9_PATH
677706
${EndIf}
678-
!insertmacro CheckMIESPresent "$DOCUMENTS\WaveMetrics\Igor Pro 9 User Files" "Igor Pro 9"
679-
!insertmacro CheckMIESPresent "$INSTALL_I9PATH" "Igor Pro 9"
707+
!insertmacro CheckMIESPresent "$DOCUMENTS\WaveMetrics\Igor Pro 9 User Files" "Igor Pro 9" ${__LINE__}
708+
!insertmacro CheckMIESPresent "$INSTALL_I9PATH" "Igor Pro 9" ${__LINE__}
680709
MIESCheck9End:
681710
IntCmp $INSTALL_I1064 1 MIESCheck10
682711
Goto MIESCheck10End
683712
MIESCheck10:
684713
StrLen $0 $INSTALL_I10PATH
685714
${If} $0 = 0
686715
IfSilent +2
687-
MessageBox MB_OK "Bug: I have no Igor 10 Path."
688-
Quit
716+
MessageBox MB_OK "Bug: I have no Igor 10 Path."
717+
!insertmacro QuitWithCode ERROR_NO_IGOR10_PATH
689718
${EndIf}
690-
!insertmacro CheckMIESPresent "$DOCUMENTS\WaveMetrics\Igor Pro 10 User Files" "Igor Pro 10"
691-
!insertmacro CheckMIESPresent "$INSTALL_I10PATH" "Igor Pro 10"
719+
!insertmacro CheckMIESPresent "$DOCUMENTS\WaveMetrics\Igor Pro 10 User Files" "Igor Pro 10" ${__LINE__}
720+
!insertmacro CheckMIESPresent "$INSTALL_I10PATH" "Igor Pro 10" ${__LINE__}
692721
MIESCheck10End:
693722

694723
IntCmp $ALLUSER 0 AdminCheckDone
695724
IntCmp $ISADMIN 1 AdminCheckDone
696725
IfSilent +2
697726
MessageBox mb_iconstop "You selected installation for All Users, but you don't have Administrator rights."
698-
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
699-
Quit
727+
!insertmacro QuitWithCode ERROR_ELEVATION_REQUIRED
700728
AdminCheckDone:
701729

702730
!include "${NSISINSTDIRLIST}"
@@ -768,7 +796,7 @@ InstallAEnd1064:
768796
FileError:
769797
IfSilent +2
770798
MessageBox MB_OK "Can not create $INSTDIR\uninstall.lst."
771-
Quit
799+
!insertmacro QuitWithCode ERROR_CANNOT_CREATE_UNINSTALL_FILELIST
772800

773801
EndOfLinks:
774802
FileClose $FILEHANDLE
@@ -828,8 +856,7 @@ SkipVCRedistInstallation:
828856
IntCmp $0 0 SkipASLRSetup
829857
IfSilent +2
830858
MessageBox MB_OK "Can not disable ASLR for Igor64.exe."
831-
SetErrorlevel 1
832-
Quit
859+
!insertmacro QuitWithCode ERROR_CANNOT_DISABLE_ASLR
833860

834861
SkipASLRSetup:
835862

@@ -839,8 +866,7 @@ SkipASLRSetup:
839866
IntCmp $0 0 FixOffice365Done
840867
IfSilent +2
841868
MessageBox MB_OK "Can not apply Office365 fixes."
842-
SetErrorlevel 1
843-
Quit
869+
!insertmacro QuitWithCode ERROR_CANNOT_FIX_OFFICE365
844870
FixOffice365Done:
845871
!insertmacro WriteITCRegistry
846872
${If} ${RunningX64}
@@ -853,7 +879,9 @@ SkipITCSetup:
853879
; Format of the json file:
854880
; /Installation/User : <string> ; for what user target the installation was done, either "current" or "all"
855881
; /Installation/WithHardware : <number> ; if the installation was done with hardware XOPs, either "1" or "0"
882+
ClearErrors
856883
FileOpen $FILEHANDLE "$INSTDIR\installation_configuration.json" w
884+
IfErrors FileErrorInstallConfig
857885
FileWrite $FILEHANDLE '{$\n'
858886
FileWrite $FILEHANDLE '$\t"Installation" : {$\n'
859887
IntCmp $ALLUSER 1 ConfigWriteUserAll
@@ -871,15 +899,22 @@ ConfigWriteWithHardwareEnd:
871899
FileWrite $FILEHANDLE '$\t}$\n'
872900
FileWrite $FILEHANDLE '}'
873901
FileClose $FILEHANDLE
902+
Goto EndOfInstallation
903+
FileErrorInstallConfig:
904+
IfSilent +2
905+
MessageBox MB_OK "Can not create installation configuration file."
906+
!insertmacro QuitWithCode ERROR_CANNOT_CREATE_INSTALLCONFIG
907+
908+
EndOfInstallation:
874909

875910
SectionEnd
876911

877912
# Uninstaller
878913

879914
function un.onInit
880-
!insertmacro PreventMultipleUninstaller
881-
!insertmacro StopOnIgor32
882-
!insertmacro StopOnIgor64
915+
!insertmacro PreventMultipleUninstaller ${__LINE__}
916+
!insertmacro StopOnIgor32 ${__LINE__}
917+
!insertmacro StopOnIgor64 ${__LINE__}
883918
functionEnd
884919

885920
Section "uninstall"

0 commit comments

Comments
 (0)