Skip to content

Commit 26136e5

Browse files
wojtekmachjosevalim
authored andcommitted
Improve Windows Installer (#12945)
1. If we couldn't verify installed OTP, don't quit but let user proceed with installing just Elixir 2. When checking installed OTPs, pick the recent most installed. Previously we were picking the first one which was basically guaranteed to be too old. 3. If we find an existing Elixir installation but it doesn't match the OTP version, offer to download the OTP version this Elixir installer was compiled against (which usually would be the newer version) 4. Add "Verify Erlang/OTP" button which re-checks for installed OTP. Closes #12678.
1 parent 6654f1b commit 26136e5

File tree

1 file changed

+94
-30
lines changed

1 file changed

+94
-30
lines changed

Diff for: lib/elixir/scripts/windows_installer/installer.nsi

+94-30
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ InstallDir "$PROGRAMFILES64\Elixir"
1212

1313
Page custom CheckOTPPageShow CheckOTPPageLeave
1414

15-
var Dialog
16-
var DownloadOTPLink
1715
var InstalledOTPRelease
1816
var OTPPath
17+
18+
var Dialog
19+
var NoOTPLabel
20+
var NoOTPLabelCreated
21+
var OTPMismatchLabel
22+
var OTPMismatchLabelCreated
23+
var DownloadOTPLink
24+
var DownloadOTPLinkCreated
25+
var VerifyOTPButton
26+
var VerifyOTPButtonCreated
1927
Function CheckOTPPageShow
2028
!insertmacro MUI_HEADER_TEXT "Checking Erlang/OTP" ""
2129

@@ -26,15 +34,61 @@ Function CheckOTPPageShow
2634
Abort
2735
${EndIf}
2836

29-
EnumRegKey $0 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang" 0
30-
ReadRegStr $0 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang\$0" ""
31-
StrCpy $OTPPath $0
37+
Call VerifyOTP
3238

33-
${If} $OTPPath == ""
34-
${NSD_CreateLabel} 0 0 100% 20u "Couldn't find existing Erlang/OTP installation. Click the link below to download and install it before proceeding."
35-
${NSD_CreateLink} 0 25u 100% 20u "Download Erlang/OTP ${OTP_RELEASE}"
39+
nsDialogs::Show
40+
FunctionEnd
41+
42+
Function VerifyOTP
43+
${If} $NoOTPLabelCreated == "true"
44+
ShowWindow $NoOTPLabel ${SW_HIDE}
45+
${EndIf}
46+
47+
${If} $OTPMismatchLabelCreated == "true"
48+
ShowWindow $OTPMismatchLabel ${SW_HIDE}
49+
${EndIf}
50+
51+
${If} $DownloadOTPLinkCreated == "true"
52+
ShowWindow $DownloadOTPLink ${SW_HIDE}
53+
${Else}
54+
StrCpy $DownloadOTPLinkCreated "true"
55+
${NSD_CreateLink} 0 60u 100% 20u "Download Erlang/OTP ${OTP_RELEASE}"
3656
Pop $DownloadOTPLink
3757
${NSD_OnClick} $DownloadOTPLink OpenOTPDownloads
58+
ShowWindow $DownloadOTPLink ${SW_HIDE}
59+
${EndIf}
60+
61+
${If} $VerifyOTPButtonCreated == "true"
62+
ShowWindow $VerifyOTPButton ${SW_HIDE}
63+
${Else}
64+
StrCpy $VerifyOTPButtonCreated "true"
65+
${NSD_CreateButton} 0 80u 25% 12u "Verify Erlang/OTP"
66+
Pop $VerifyOTPButton
67+
${NSD_OnClick} $VerifyOTPButton VerifyOTP
68+
ShowWindow $VerifyOTPButton ${SW_HIDE}
69+
${EndIf}
70+
71+
StrCpy $0 0
72+
loop:
73+
EnumRegKey $1 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang" $0
74+
StrCmp $1 "" done
75+
ReadRegStr $1 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang\$1" ""
76+
StrCpy $OTPPath $1
77+
IntOp $0 $0 + 1
78+
goto loop
79+
done:
80+
81+
${If} $OTPPath == ""
82+
${If} $NoOTPLabelCreated != "true"
83+
StrCpy $NoOTPLabelCreated "true"
84+
${NSD_CreateLabel} 0 0 100% 20u "Couldn't find existing Erlang/OTP installation. Click the link below to download and install it before proceeding."
85+
Pop $NoOTPLabel
86+
${EndIf}
87+
88+
ShowWindow $NoOTPLabel ${SW_SHOW}
89+
ShowWindow $DownloadOTPLink ${SW_SHOW}
90+
ShowWindow $VerifyOTPButton ${SW_SHOW}
91+
3892
${Else}
3993
nsExec::ExecToStack `$OTPPath\bin\erl.exe -noinput -eval "\
4094
io:put_chars(erlang:system_info(otp_release)),\
@@ -45,24 +99,25 @@ Function CheckOTPPageShow
4599
${If} $0 == 0
46100
StrCpy $InstalledOTPRelease $1
47101
${If} $InstalledOTPRelease == ${OTP_RELEASE}
48-
${NSD_CreateLabel} 0 0 100% 20u "Found existing Erlang/OTP $InstalledOTPRelease installation at $OTPPath. Please proceed."
49-
${ElseIf} $2 < ${OTP_RELEASE}
50-
${NSD_CreateLabel} 0 0 100% 30u "Found existing Erlang/OTP $InstalledOTPRelease installation at $OTPPath but this Elixir installer was precompiled for Erlang/OTP ${OTP_RELEASE}. \
51-
We recommend checking if there is an Elixir version precompiled for Erlang/OTP $InstalledOTPRelease. Otherwise, proceed."
102+
${NSD_CreateLabel} 0 0 100% 60u "Found existing Erlang/OTP $InstalledOTPRelease installation at $OTPPath. Please proceed."
103+
52104
${Else}
53-
SetErrorlevel 5
54-
MessageBox MB_ICONSTOP "Found existing Erlang/OTP $InstalledOTPRelease installation at $OTPPath but this Elixir version was precompiled for Erlang/OTP ${OTP_RELEASE}. \
55-
Please upgrade your Erlang/OTP version or choose an Elixir installer matching your Erlang/OTP version"
56-
Quit
105+
${If} $OTPMismatchLabelCreated != "true"
106+
StrCpy $OTPMismatchLabelCreated "true"
107+
${NSD_CreateLabel} 0 0 100% 60u "Found existing Erlang/OTP $InstalledOTPRelease installation at $OTPPath but this Elixir installer was precompiled for Erlang/OTP ${OTP_RELEASE}. \
108+
$\r$\n$\r$\nYou can either search for another Elixir installer precompiled for Erlang/OTP $InstalledOTPRelease or download Erlang/OTP ${OTP_RELEASE} and install before proceeding."
109+
Pop $OTPMismatchLabel
110+
${EndIf}
111+
112+
ShowWindow $OTPMismatchLabel ${SW_SHOW}
113+
ShowWindow $DownloadOTPLink ${SW_SHOW}
114+
ShowWindow $VerifyOTPButton ${SW_SHOW}
57115
${EndIf}
58116
${Else}
59117
SetErrorlevel 5
60118
MessageBox MB_ICONSTOP "Found existing Erlang/OTP installation at $OTPPath but checking it exited with $0: $1"
61-
Quit
62119
${EndIf}
63120
${EndIf}
64-
65-
nsDialogs::Show
66121
FunctionEnd
67122

68123
Function OpenOTPDownloads
@@ -93,15 +148,18 @@ Function FinishPageShow
93148
Abort
94149
${EndIf}
95150

96-
${NSD_CreateCheckbox} 0 0 195u 10u "&Add $INSTDIR\bin to %PATH%"
97-
Pop $AddElixirToPathCheckbox
98-
SendMessage $AddElixirToPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0
151+
; we add to PATH using erlang, so there must be an OTP installed to do so.
152+
${If} "$OTPPath" != ""
153+
${NSD_CreateCheckbox} 0 0 195u 10u "&Add $INSTDIR\bin to %PATH%"
154+
Pop $AddElixirToPathCheckbox
155+
SendMessage $AddElixirToPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0
156+
157+
${NSD_CreateCheckbox} 0 20u 195u 10u "&Add $OTPPath\bin to %PATH%"
158+
Pop $AddOTPToPathCheckbox
159+
SendMessage $AddOTPToPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0
99160

100-
EnumRegKey $0 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang" 0
101-
ReadRegStr $0 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang\$0" ""
102-
${NSD_CreateCheckbox} 0 20u 195u 10u "&Add $0\bin to %PATH%"
103-
Pop $AddOTPToPathCheckbox
104-
SendMessage $AddOTPToPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0
161+
${NSD_CreateLabel} 0 40u 100% 20u "Note: you need to restart your shell for the environment variable changes to take effect."
162+
${EndIf}
105163

106164
nsDialogs::Show
107165
FunctionEnd
@@ -145,9 +203,15 @@ var RemoveElixirFromPathCheckbox
145203
Function un.FinishPageShow
146204
!insertmacro MUI_HEADER_TEXT "Remove from %PATH%" ""
147205

148-
EnumRegKey $0 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang" 0
149-
ReadRegStr $0 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang\$0" ""
150-
StrCpy $OTPPath $0
206+
StrCpy $0 0
207+
loop:
208+
EnumRegKey $1 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang" $0
209+
StrCmp $1 "" done
210+
ReadRegStr $1 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang\$1" ""
211+
StrCpy $OTPPath $1
212+
IntOp $0 $0 + 1
213+
goto loop
214+
done:
151215

152216
nsDialogs::Create 1018
153217
Pop $Dialog

0 commit comments

Comments
 (0)