Skip to content

Commit 9b7e742

Browse files
committed
Create standalone Windows installer for cmdline.
This uses NullSoft Scriptable Install System to create the executable, which is fully contained and downloads the necessary files, including Java, from the internet. This prevents the installer itself from needing to be updated on each update. Eventually, the installer should be signed, but for now it's unsigned, causing various scary warnings upon installation. In any case, the installer code itself works, as well as the installer.
1 parent 5e04ddf commit 9b7e742

File tree

6 files changed

+312
-0
lines changed

6 files changed

+312
-0
lines changed
Binary file not shown.

src/installer/Windows/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This installer is written so that in general it shouldn't need updating.
2+
However, if it does need updating, you need the NSIS compiler. This can
3+
be found [here](https://sourceforge.net/projects/nsis/). You will also need the
4+
INetC plugin, found [here](http://nsis.sourceforge.net/Inetc_plug-in). Copy the
5+
dlls into C:\Program Files (x86)\NSIS\Plugins.
6+
7+
Install and launch the compiler. Open the installer.nsi file in the compiler, and
8+
compile it. This will create the installer.exe file.

src/installer/Windows/installer.nsi

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
2+
; MethodScript Installer
3+
; Checks for Java, and if not present, downloads and installs AdoptOpenJDK
4+
; then downloads the latest MethodScript jar, running the install command.
5+
; Optionally, sample files from the 'examples' command can be installed.
6+
7+
Unicode true
8+
9+
!include "MUI2.nsh"
10+
!include "LogicLib.nsh"
11+
!include "nsDialogs.nsh"
12+
!include "x64.nsh"
13+
!include "FileFunc.nsh"
14+
15+
Name "MethodScript Cmdline Installer"
16+
Caption "MethodScript Cmdline"
17+
OutFile "MethodScriptInstaller.exe"
18+
ShowInstDetails show
19+
20+
Function .onInit
21+
${If} ${RunningX64}
22+
SetRegView 64
23+
${EndIf}
24+
SetOutPath $TEMP
25+
File /oname=spltmp.bmp "..\..\main\resources\siteDeploy\resources\images\CommandHelper_IconHighRes_Sprite.bmp"
26+
advsplash::show 750 1500 1500 0xFF00FF $TEMP\spltmp
27+
Pop $0
28+
Delete $TEMP\spltmp.bmp
29+
FunctionEnd
30+
31+
Function un.onInit
32+
${If} ${RunningX64}
33+
SetRegView 64
34+
${EndIf}
35+
FunctionEnd
36+
37+
!define MUI_ICON "..\..\main\resources\siteDeploy\resources\images\favicon.ico"
38+
!define MUI_HEADERIMAGE
39+
!define MUI_HEADERIMAGE_BITMAP "..\..\main\resources\siteDeploy\resources\images\CommandHelper_Icon.bmp"
40+
!define MUI_HEADERIMAGE_RIGHT
41+
42+
43+
!define MUI_WELCOMEPAGE_TITLE "MethodScript Cmdline Installer"
44+
!define MUI_WELCOMEPAGE_TEXT "This installer downloads and configures your system with everything you need to \
45+
run MethodScript from the command line. If Java is already installed, that version will be used, but if you don't \
46+
have Java installed, AdoptOpenJDK will be installed for you. If you wish to use another version of Java other than \
47+
those offered, please exit the installer, install Java manually, then restart the installer."
48+
!insertmacro MUI_PAGE_WELCOME
49+
!insertmacro MUI_PAGE_LICENSE "..\..\..\LICENSE.txt"
50+
Page Custom CheckJava LeaveJava
51+
52+
!insertmacro MUI_PAGE_INSTFILES
53+
54+
55+
!insertmacro MUI_LANGUAGE "English"
56+
Var JavaInstallationPath
57+
Var Dialog
58+
Var InstallJava
59+
Var JavaVersion
60+
Var JDK
61+
Var JRE
62+
Var UseJRE
63+
Var Use64Bit
64+
65+
Function CheckJava
66+
67+
Call _FindJava
68+
${If} $JavaInstallationPath != ""
69+
StrCpy $InstallJava "false"
70+
Abort
71+
${EndIf}
72+
73+
StrCpy $InstallJava "true"
74+
!insertmacro MUI_HEADER_TEXT "Java Installation" "Select the Java version you wish to install. \
75+
If you wish to install another version, exit the installer, manually install Java, then run it again. \
76+
Only LTS versions are available through this installer."
77+
nsDialogs::Create 1018
78+
Pop $Dialog
79+
80+
${If} $Dialog == error
81+
Abort
82+
${EndIf}
83+
84+
${NSD_CreateGroupBox} 10% 10u 80% 62u "JDK/JRE"
85+
Pop $0
86+
87+
${NSD_CreateLabel} 20% 25u 50% 10u "If you aren't sure which one to select, use JRE"
88+
89+
${NSD_CreateRadioButton} 20% 35u 20% 10u "JRE"
90+
Pop $JRE
91+
92+
${NSD_CreateRadioButton} 20% 45u 20% 10u "JDK"
93+
Pop $JDK
94+
95+
${NSD_CreateGroupBox} 5% 75u 90% 34u "Java Version"
96+
Pop $0
97+
98+
${NSD_CreateDropList} 10% 87u 80% 80u "Version"
99+
Pop $JavaVersion
100+
${NSD_CB_AddString} $JavaVersion "8 (recommended)"
101+
${NSD_CB_AddString} $JavaVersion "11"
102+
103+
nsDialogs::Show
104+
FunctionEnd
105+
106+
Function LeaveJava
107+
${NSD_GetState} $JRE $R0
108+
${NSD_GetState} $JDK $R1
109+
110+
${If} $R0 == 1
111+
StrCpy $UseJRE "true"
112+
${ElseIf} $R1 == 1
113+
StrCpy $UseJRE "false"
114+
${Else}
115+
MessageBox MB_ICONEXCLAMATION "Please select either the JDK or JRE"
116+
Abort
117+
${EndIf}
118+
119+
${NSD_GetText} $JavaVersion $R0
120+
121+
${If} $R0 == ""
122+
MessageBox MB_ICONEXCLAMATION "Please select the Java version you wish to install"
123+
Abort
124+
${ElseIf} $R0 == "8 (recommended)"
125+
StrCpy $JavaVersion "8"
126+
${Else}
127+
StrCpy $JavaVersion $R0
128+
${EndIf}
129+
130+
${If} ${RunningX64}
131+
StrCpy $Use64Bit "true"
132+
${Else}
133+
StrCpy $Use64Bit "false"
134+
${EndIf}
135+
FunctionEnd
136+
137+
Section DoOverview
138+
${If} $InstallJava == "true"
139+
DetailPrint "Installing Java"
140+
DetailPrint "Using JRE: $UseJRE"
141+
DetailPrint "Java Version to install: $JavaVersion"
142+
DetailPrint "Install 64 bit Java: $Use64Bit"
143+
${Else}
144+
DetailPrint "Skipping Java Installation"
145+
${EndIf}
146+
SectionEnd
147+
148+
Var JavaDownload
149+
Section DoJavaInstall
150+
${If} $InstallJava == "false"
151+
goto DoJavaInstallEnd
152+
${EndIf}
153+
${If} $InstallJava == "true"
154+
${If} $JavaVersion == "8"
155+
${If} $UseJRE == "true"
156+
${If} $Use64Bit == "true"
157+
StrCpy $JavaDownload "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u282-b08/OpenJDK8U-jre_x64_windows_hotspot_8u282b08.msi"
158+
${Else}
159+
StrCpy $JavaDownload "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u282-b08/OpenJDK8U-jre_x86-32_windows_hotspot_8u282b08.msi"
160+
${EndIf}
161+
${Else}
162+
${If} $Use64Bit == "true"
163+
StrCpy $JavaDownload "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u282-b08/OpenJDK8U-jdk_x64_windows_hotspot_8u282b08.msi"
164+
${Else}
165+
StrCpy $JavaDownload "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u282-b08/OpenJDK8U-jdk_x86-32_windows_hotspot_8u282b08.msi"
166+
${EndIf}
167+
${EndIf}
168+
${ElseIf} $JavaVersion == "11"
169+
${If} $UseJRE == "true"
170+
${If} $Use64Bit == "true"
171+
StrCpy $JavaDownload "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jre_x64_windows_hotspot_11.0.10_9.msi"
172+
${Else}
173+
StrCpy $JavaDownload "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jre_x86-32_windows_hotspot_11.0.10_9.msi"
174+
${EndIf}
175+
${Else}
176+
${If} $Use64Bit == "true"
177+
StrCpy $JavaDownload "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_windows_hotspot_11.0.10_9.msi"
178+
${Else}
179+
StrCpy $JavaDownload "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x86-32_windows_hotspot_11.0.10_9.msi"
180+
${EndIf}
181+
${EndIf}
182+
${Else}
183+
;; Forgotten use case!
184+
MessageBox MB_ICONSTOP "Error, missing use case!"
185+
${EndIf}
186+
${EndIf}
187+
GetInstaller:
188+
DetailPrint "Downloading Java Installer from $JavaDownload to $TEMP\JavaInstaller.msi"
189+
inetc::get $JavaDownload $TEMP\JavaInstaller.msi
190+
Pop $R0 ;Get the return value
191+
${If} $R0 == "success"
192+
MessageBox MB_ICONSTOP "Download failed: $R0"
193+
Abort
194+
${EndIf}
195+
DetailPrint "Installing Java"
196+
ExecWait "msiexec /i $\"$TEMP\JavaInstaller.msi$\"" $0
197+
${If} $0 != 0
198+
MessageBox MB_ABORTRETRYIGNORE "Java installation failed or was cancelled" IDABORT AbortInstaller IDRETRY GetInstaller
199+
${EndIf}
200+
201+
Delete $TEMP\JavaInstaller.msi
202+
Call _FindJava
203+
${If} $JavaInstallationPath == ""
204+
MessageBox MB_ABORTRETRYIGNORE "After installation, Java still cannot be found" IDABORT AbortInstaller IDRETRY GetInstaller
205+
${EndIf}
206+
goto DoJavaInstallEnd
207+
AbortInstaller:
208+
Abort
209+
DoJavaInstallEnd:
210+
SectionEnd
211+
212+
Section DoDownloadMethodScript
213+
; First, create the AppData folder, which is where the jar will go
214+
;;;; TODO: Write out the icon in the installer, and update the DoConfigureUninstaller location
215+
CreateDirectory $LOCALAPPDATA\MethodScript
216+
DetailPrint "Downloading latest MethodScript jar to $LOCALAPPDATA\MethodScript\MethodScript.jar"
217+
inetc::get "https://methodscript.com/MethodScript.jar" $LOCALAPPDATA\MethodScript\MethodScript.jar
218+
ExecWait "java -jar $LOCALAPPDATA\MethodScript\MethodScript.jar install-cmdline"
219+
ExecWait "java -jar $LOCALAPPDATA\MethodScript\MethodScript.jar eval $\"exit()$\""
220+
SetOutPath $LOCALAPPDATA\MethodScript
221+
File /oname=icon.ico "..\..\main\resources\siteDeploy\resources\images\commandhelper_icon.ico"
222+
; This might not be working, but anyways, the icon is used in the uninstaller, so putting the icon in the folder is necessary.
223+
WriteINIStr "$LOCALAPPDATA\MethodScript\desktop.ini" ".ShellClassInfo" "IconResource" "$LOCALAPPDATA\MethodScript\icon.ico,0"
224+
WriteINIStr "$LOCALAPPDATA\MethodScript\desktop.ini" "ViewState" "FolderType" "Documents"
225+
SetFileAttributes "$LOCALAPPDATA\MethodScript\desktop.ini" HIDDEN|SYSTEM
226+
SectionEnd
227+
228+
Section DoConfigureUninstaller
229+
WriteUninstaller "$LOCALAPPDATA\MethodScript\uninstall.exe"
230+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" "DisplayName" "MethodScript"
231+
WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" \
232+
"UninstallString" "$\"$LOCALAPPDATA\MethodScript\uninstall.exe$\""
233+
WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" \
234+
"InstallLocation" "$\"$LOCALAPPDATA\MethodScript$\""
235+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" \
236+
"DisplayIcon" "$\"$LOCALAPPDATA\MethodScript\icon.ico$\""
237+
; TODO Once a silent uninstall is ready
238+
;WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" \
239+
; "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
240+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" \
241+
"NoRepair" "1"
242+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" \
243+
"NoModify" "1"
244+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" "Publisher" "MethodScript Contributors"
245+
${GetSize} "$LOCALAPPDATA\MethodScript" "/S=OK" $0 $1 $2
246+
IntFmt $0 "0x%08X" $0
247+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" "EstimatedSize" "$0"
248+
nsExec::ExecToStack "java -jar $LOCALAPPDATA\MethodScript\MethodScript.jar eval $\"engine_build_date()$\""
249+
Pop $0 ; Return
250+
Pop $1 ; Output
251+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript" "DisplayVersion" "$1"
252+
253+
DetailPrint "Cmdline MethodScript is now installed! You may need to reboot your computer to use it from the shell."
254+
DetailPrint "Try running `mscript` or `mscript -- help`."
255+
SectionEnd
256+
257+
Section un.DoMethodScriptUninstall
258+
ExecWait "java -jar $LOCALAPPDATA\MethodScript\MethodScript.jar uninstall-cmdline"
259+
SectionEnd
260+
261+
Section un.DoPreferencesUninstall
262+
MessageBox MB_YESNO "Would you like to remove your preferences and other files located at $LOCALAPPDATA\MethodScript?" IDNO DoPreferencesUninstallEnd
263+
RMDir /R /REBOOTOK "$LOCALAPPDATA\MethodScript"
264+
DoPreferencesUninstallEnd:
265+
SectionEnd
266+
267+
Section un.DoJavaUninstall
268+
MessageBox MB_ICONINFORMATION "If you wish to uninstall Java as well, please find the uninstaller in Add/Remove Programs."
269+
SectionEnd
270+
271+
Section un.DoUninstallerUninstall
272+
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MethodScript"
273+
SectionEnd
274+
275+
Function _FindJava
276+
StrCpy $1 "SOFTWARE\JavaSoft\Java Runtime Environment"
277+
StrCpy $2 0
278+
ReadRegStr $2 HKLM "$1" "CurrentVersion"
279+
StrCmp $2 "" DetectTry2 JRE
280+
JRE:
281+
ReadRegStr $5 HKLM "$1\$2" "JavaHome"
282+
StrCmp $5 "" DetectTry2 GetValue
283+
284+
DetectTry2:
285+
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
286+
StrCmp $2 "" NoJava JDK
287+
JDK:
288+
ReadRegStr $5 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$2" "JavaHome"
289+
StrCmp $5 "" NoJava GetValue
290+
291+
GetValue:
292+
StrCpy $JavaInstallationPath $5
293+
DetailPrint "Javahome value: $JavaInstallationPath"
294+
Goto done
295+
296+
NoJava:
297+
DetailPrint "No Java installation detected."
298+
# Install Java
299+
StrCpy $JavaInstallationPath ""
300+
Goto done
301+
302+
done:
303+
#$JavaInstallationPath should contain the system path to Java
304+
FunctionEnd
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)