11!include " MUI2.nsh"
22!include " StrFunc.nsh"
3- ${Using:StrFunc} StrStr
43${Using:StrFunc} UnStrStr
5- ${Using:StrFunc} UnStrRep
64
75Name " Elixir"
86ManifestDPIAware true
@@ -16,7 +14,6 @@ Page custom CheckOTPPageShow CheckOTPPageLeave
1614
1715var Dialog
1816var DownloadOTPLink
19- var InstalledERTSVersion
2017var InstalledOTPRelease
2118var OTPPath
2219Function CheckOTPPageShow
@@ -30,11 +27,10 @@ Function CheckOTPPageShow
3027 ${EndIf}
3128
3229 EnumRegKey $0 HKLM " SOFTWARE\WOW6432NODE\Ericsson\Erlang" 0
33- ReadRegStr $1 HKLM " SOFTWARE\WOW6432NODE\Ericsson\Erlang\$0" " "
34- StrCpy $InstalledERTSVersion $0
35- StrCpy $OTPPath $1
30+ ReadRegStr $0 HKLM " SOFTWARE\WOW6432NODE\Ericsson\Erlang\$0" " "
31+ StrCpy $OTPPath $0
3632
37- ${If} $1 == " "
33+ ${If} $OTPPath == " "
3834 ${NSD_CreateLabel} 0 0 100 % 20u " Couldn't find existing Erlang/OTP installation. Click the link below to download and install it before proceeding."
3935 ${NSD_CreateLink} 0 25u 100 % 20u " Download Erlang/OTP ${OTP_RELEASE}"
4036 Pop $DownloadOTPLink
@@ -103,62 +99,55 @@ Function FinishPageShow
10399
104100 EnumRegKey $0 HKLM " SOFTWARE\WOW6432NODE\Ericsson\Erlang" 0
105101 ReadRegStr $0 HKLM " SOFTWARE\WOW6432NODE\Ericsson\Erlang\$0" " "
106- StrCpy $OTPPath $0
107- ${If} $0 != " "
108- ${NSD_CreateCheckbox} 0 20u 195u 10u " &Add $0\bin to %PATH%"
109- Pop $AddOTPToPathCheckbox
110- SendMessage $AddOTPToPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0
111- ${EndIf}
102+ ${NSD_CreateCheckbox} 0 20u 195u 10u " &Add $0\bin to %PATH%"
103+ Pop $AddOTPToPathCheckbox
104+ SendMessage $AddOTPToPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0
112105
113106 nsDialogs::Show
114107FunctionEnd
115108
109+ var PathsToAdd
116110Function FinishPageLeave
117111 ${NSD_GetState} $AddOTPToPathCheckbox $0
118112 ${If} $0 <> ${BST_UNCHECKED}
119- ReadRegStr $0 HKCU " Environment" " Path"
120- ${StrStr} $1 " $0" " $OTPPath\bin"
121- ${If} $1 == " "
122- WriteRegExpandStr HKCU " Environment" " Path" " $OTPPath\bin;$0"
123- ${Else}
124- MessageBox MB_OK " $OTPPath\bin already in %PATH%"
125- ${EndIf}
113+ StrCpy $PathsToAdd " ;$OTPPath\bin"
126114 ${EndIf}
127115
128116 ${NSD_GetState} $AddElixirToPathCheckbox $0
129117 ${If} $0 <> ${BST_UNCHECKED}
130- ReadRegStr $0 HKCU " Environment" " Path"
131- ${StrStr} $1 " $0" " $INSTDIR\bin"
132- ${If} $1 == " "
133- WriteRegExpandStr HKCU " Environment" " Path" " $INSTDIR\bin;$0"
134- ${Else}
135- MessageBox MB_OK " $INSTDIR\bin already in %PATH%"
118+ StrCpy $PathsToAdd " $PathsToAdd;$INSTDIR\bin"
119+ ${EndIf}
120+
121+ ${If} " $PathsToAdd" != " "
122+ nsExec::ExecToStack ` "$OTPPath\bin\escript.exe" "$INSTDIR\update_system_path.erl" add "$PathsToAdd"`
123+ Pop $0
124+ Pop $1
125+ ${If} $0 != 0
126+ SetErrorlevel 5
127+ MessageBox MB_ICONSTOP " adding paths failed with $0: $1"
128+ Quit
136129 ${EndIf}
137130 ${EndIf}
138131FunctionEnd
139132
140133Section " Install Elixir" SectionElixir
141134 SetOutPath " $INSTDIR"
142135 File /r " ${ELIXIR_DIR}\"
136+ File " update_system_path.erl"
143137
144138 WriteUninstaller " Uninstall.exe"
145139SectionEnd
146140
147- ; Uninstall Page: Files
148-
149- !insertmacro MUI_UNPAGE_DIRECTORY
150- !insertmacro MUI_UNPAGE_INSTFILES
151-
152- Section " Uninstall"
153- RMDir /r " $INSTDIR"
154- SectionEnd
155-
156- ; Uninstall Page: Finish
141+ ; Uninstall Page: Remove from %PATH%
157142
158143var RemoveOTPFromPathCheckbox
159144var RemoveElixirFromPathCheckbox
160145Function un.FinishPageShow
161- !insertmacro MUI_HEADER_TEXT " Finish Setup" " "
146+ !insertmacro MUI_HEADER_TEXT " Remove from %PATH%" " "
147+
148+ EnumRegKey $0 HKLM " SOFTWARE\WOW6432NODE\Ericsson\Erlang" 0
149+ ReadRegStr $0 HKLM " SOFTWARE\WOW6432NODE\Ericsson\Erlang\$0" " "
150+ StrCpy $OTPPath $0
162151
163152 nsDialogs::Create 1018
164153 Pop $Dialog
@@ -168,16 +157,14 @@ Function un.FinishPageShow
168157 ${EndIf}
169158
170159 ReadRegStr $0 HKCU " Environment" " Path"
160+
171161 ${UnStrStr} $1 " $0" " $INSTDIR\bin"
172162 ${If} $1 != " "
173163 ${NSD_CreateCheckbox} 0 0 195u 10u " &Remove $INSTDIR\bin from %PATH%"
174164 Pop $RemoveElixirFromPathCheckbox
175165 SendMessage $RemoveElixirFromPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0
176166 ${EndIf}
177167
178- EnumRegKey $1 HKLM " SOFTWARE\WOW6432NODE\Ericsson\Erlang" 0
179- ReadRegStr $1 HKLM " SOFTWARE\WOW6432NODE\Ericsson\Erlang\$1" " "
180- StrCpy $OTPPath $1
181168 ${UnStrStr} $1 " $0" " $OTPPath\bin"
182169 ${If} $1 != " "
183170 ${NSD_CreateCheckbox} 0 20u 195u 10u " &Remove $OTPPath\bin from %PATH%"
@@ -188,22 +175,37 @@ Function un.FinishPageShow
188175 nsDialogs::Show
189176FunctionEnd
190177
178+ var PathsToRemove
191179Function un.FinishPageLeave
192- ReadRegStr $0 HKCU " Environment" " Path"
193-
194180 ${NSD_GetState} $RemoveOTPFromPathCheckbox $1
195181 ${If} $1 <> ${BST_UNCHECKED}
196- ${UnStrRep} $0 " $0 " " $ OTPPath\bin; " " "
182+ StrCpy $PathsToRemove " ;$ OTPPath\bin"
197183 ${EndIf}
198184
199185 ${NSD_GetState} $RemoveElixirFromPathCheckbox $1
200186 ${If} $1 <> ${BST_UNCHECKED}
201- ${UnStrRep} $0 " $0 " " $INSTDIR\bin; " " "
187+ StrCpy $PathsToRemove " $PathsToRemove; $INSTDIR\bin"
202188 ${EndIf}
203189
204- WriteRegExpandStr HKCU " Environment" " Path" " $0"
190+ ${If} " $PathsToRemove" != " "
191+ nsExec::ExecToStack ` "$OTPPath\bin\escript.exe" "$INSTDIR\update_system_path.erl" remove "$PathsToRemove"`
192+ Pop $0
193+ Pop $1
194+ ${If} $0 != 0
195+ SetErrorlevel 5
196+ MessageBox MB_ICONSTOP " removing paths failed with $0: $1"
197+ Quit
198+ ${EndIf}
199+ ${EndIf}
205200FunctionEnd
206201
207202UninstPage custom un.FinishPageShow un.FinishPageLeave
208203
204+ !insertmacro MUI_UNPAGE_DIRECTORY
205+ !insertmacro MUI_UNPAGE_INSTFILES
206+
207+ Section " Uninstall"
208+ RMDir /r " $INSTDIR"
209+ SectionEnd
210+
209211!insertmacro MUI_LANGUAGE " English"
0 commit comments