1; Copyright 2007-2020 OpenRA developers (see AUTHORS)
2; This file is part of OpenRA.
3;
4;  OpenRA is free software: you can redistribute it and/or modify
5;  it under the terms of the GNU General Public License as published by
6;  the Free Software Foundation, either version 3 of the License, or
7;  (at your option) any later version.
8;
9;  OpenRA is distributed in the hope that it will be useful,
10;  but WITHOUT ANY WARRANTY; without even the implied warranty of
11;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12;  GNU General Public License for more details.
13;
14;  You should have received a copy of the GNU General Public License
15;  along with OpenRA.  If not, see <http://www.gnu.org/licenses/>.
16
17!include "MUI2.nsh"
18!include "FileFunc.nsh"
19!include "WordFunc.nsh"
20
21Name "OpenRA"
22OutFile "OpenRA.Setup.exe"
23
24ManifestDPIAware true
25
26Function .onInit
27	!ifndef USE_PROGRAMFILES32
28		SetRegView 64
29	!endif
30	ReadRegStr $INSTDIR HKLM "Software\OpenRA${SUFFIX}" "InstallDir"
31	StrCmp $INSTDIR "" unset done
32	unset:
33	!ifndef USE_PROGRAMFILES32
34		StrCpy $INSTDIR "$PROGRAMFILES64\OpenRA${SUFFIX}"
35	!else
36		StrCpy $INSTDIR "$PROGRAMFILES32\OpenRA${SUFFIX}"
37	!endif
38	done:
39FunctionEnd
40
41SetCompressor lzma
42RequestExecutionLevel admin
43
44!insertmacro MUI_PAGE_WELCOME
45!insertmacro MUI_PAGE_LICENSE "${SRCDIR}\COPYING"
46!insertmacro MUI_PAGE_DIRECTORY
47
48!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
49!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\OpenRA${SUFFIX}"
50!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
51!define MUI_STARTMENUPAGE_DEFAULTFOLDER "OpenRA"
52
53Var StartMenuFolder
54!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
55
56!insertmacro MUI_PAGE_COMPONENTS
57!insertmacro MUI_PAGE_INSTFILES
58
59!insertmacro MUI_UNPAGE_CONFIRM
60!insertmacro MUI_UNPAGE_INSTFILES
61!insertmacro MUI_UNPAGE_FINISH
62
63!insertmacro MUI_LANGUAGE "English"
64
65;***************************
66;Section Definitions
67;***************************
68Section "-Reg" Reg
69
70	; Installation directory
71	WriteRegStr HKLM "Software\OpenRA${SUFFIX}" "InstallDir" $INSTDIR
72
73	; Join server URL Scheme
74	WriteRegStr HKLM "Software\Classes\openra-ra-${TAG}" "" "URL:Join OpenRA server"
75	WriteRegStr HKLM "Software\Classes\openra-ra-${TAG}" "URL Protocol" ""
76	WriteRegStr HKLM "Software\Classes\openra-ra-${TAG}\DefaultIcon" "" "$INSTDIR\RedAlert.ico,0"
77	WriteRegStr HKLM "Software\Classes\openra-ra-${TAG}\Shell\Open\Command" "" "$INSTDIR\RedAlert.exe Launch.URI=%1"
78
79	WriteRegStr HKLM "Software\Classes\openra-cnc-${TAG}" "" "URL:Join OpenRA server"
80	WriteRegStr HKLM "Software\Classes\openra-cnc-${TAG}" "URL Protocol" ""
81	WriteRegStr HKLM "Software\Classes\openra-cnc-${TAG}\DefaultIcon" "" "$INSTDIR\TiberianDawn.ico,0"
82	WriteRegStr HKLM "Software\Classes\openra-cnc-${TAG}\Shell\Open\Command" "" "$INSTDIR\TiberianDawn.exe Launch.URI=%1"
83
84	WriteRegStr HKLM "Software\Classes\openra-d2k-${TAG}" "" "URL:Join OpenRA server"
85	WriteRegStr HKLM "Software\Classes\openra-d2k-${TAG}" "URL Protocol" ""
86	WriteRegStr HKLM "Software\Classes\openra-d2k-${TAG}\DefaultIcon" "" "$INSTDIR\Dune2000.ico,0"
87	WriteRegStr HKLM "Software\Classes\openra-d2k-${TAG}\Shell\Open\Command" "" "$INSTDIR\Dune2000.exe Launch.URI=%1"
88
89	; Remove obsolete file associations
90	DeleteRegKey HKLM "Software\Classes\.orarep"
91	DeleteRegKey HKLM "Software\Classes\OpenRA_replay"
92	DeleteRegKey HKLM "Software\Classes\.oramod"
93	DeleteRegKey HKLM "Software\Classes\OpenRA_mod"
94	DeleteRegKey HKLM "Software\Classes\openra"
95
96SectionEnd
97
98Section "Game" GAME
99	SectionIn RO
100
101	RMDir /r "$INSTDIR\mods"
102	SetOutPath "$INSTDIR\mods"
103	File /r "${SRCDIR}\mods\common"
104	File /r "${SRCDIR}\mods\cnc"
105	File /r "${SRCDIR}\mods\d2k"
106	File /r "${SRCDIR}\mods\ra"
107	File /r "${SRCDIR}\mods\modcontent"
108
109	SetOutPath "$INSTDIR"
110	File "${SRCDIR}\RedAlert.exe"
111	File "${SRCDIR}\TiberianDawn.exe"
112	File "${SRCDIR}\Dune2000.exe"
113	File "${SRCDIR}\OpenRA.Game.exe"
114	File "${SRCDIR}\OpenRA.Game.exe.config"
115	File "${SRCDIR}\OpenRA.Utility.exe"
116	File "${SRCDIR}\OpenRA.Server.exe"
117	File "${SRCDIR}\OpenRA.Platforms.Default.dll"
118	File "${SRCDIR}\ICSharpCode.SharpZipLib.dll"
119	File "${SRCDIR}\FuzzyLogicLibrary.dll"
120	File "${SRCDIR}\Open.Nat.dll"
121	File "${SRCDIR}\VERSION"
122	File "${SRCDIR}\AUTHORS"
123	File "${SRCDIR}\COPYING"
124	File "${SRCDIR}\README.html"
125	File "${SRCDIR}\CHANGELOG.html"
126	File "${SRCDIR}\CONTRIBUTING.html"
127	File "${SRCDIR}\OpenRA.ico"
128	File "${SRCDIR}\RedAlert.ico"
129	File "${SRCDIR}\TiberianDawn.ico"
130	File "${SRCDIR}\Dune2000.ico"
131	File "${SRCDIR}\SDL2-CS.dll"
132	File "${SRCDIR}\OpenAL-CS.Core.dll"
133	File "${SRCDIR}\global mix database.dat"
134	File "${SRCDIR}\IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP"
135	File "${SRCDIR}\eluant.dll"
136	File "${SRCDIR}\BeaconLib.dll"
137	File "${SRCDIR}\soft_oal.dll"
138	File "${SRCDIR}\SDL2.dll"
139	File "${SRCDIR}\freetype6.dll"
140	File "${SRCDIR}\lua51.dll"
141
142	!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
143		CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
144		CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Red Alert${SUFFIX}.lnk" $OUTDIR\RedAlert.exe "" \
145			"$OUTDIR\RedAlert.exe" "" "" "" ""
146		CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Tiberian Dawn${SUFFIX}.lnk" $OUTDIR\TiberianDawn.exe "" \
147			"$OUTDIR\TiberianDawn.exe" "" "" "" ""
148		CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Dune 2000${SUFFIX}.lnk" $OUTDIR\Dune2000.exe "" \
149			"$OUTDIR\Dune2000.exe" "" "" "" ""
150	!insertmacro MUI_STARTMENU_WRITE_END
151
152	SetOutPath "$INSTDIR\lua"
153	File "${SRCDIR}\lua\*.lua"
154
155	SetOutPath "$INSTDIR\glsl"
156	File "${SRCDIR}\glsl\*.frag"
157	File "${SRCDIR}\glsl\*.vert"
158
159	; Estimated install size for the control panel properties
160	${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
161	IntFmt $0 "0x%08X" $0
162	WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "EstimatedSize" "$0"
163
164	SetShellVarContext all
165	CreateDirectory "$APPDATA\OpenRA\ModMetadata"
166	nsExec::ExecToLog '"$INSTDIR\OpenRA.Utility.exe" ra --register-mod "$INSTDIR\RedAlert.exe" system'
167	nsExec::ExecToLog '"$INSTDIR\OpenRA.Utility.exe" ra --clear-invalid-mod-registrations system'
168	nsExec::ExecToLog '"$INSTDIR\OpenRA.Utility.exe" cnc --register-mod "$INSTDIR\TiberianDawn.exe" system'
169	nsExec::ExecToLog '"$INSTDIR\OpenRA.Utility.exe" cnc --clear-invalid-mod-registrations system'
170	nsExec::ExecToLog '"$INSTDIR\OpenRA.Utility.exe" d2k --register-mod "$INSTDIR\Dune2000.exe" system'
171	nsExec::ExecToLog '"$INSTDIR\OpenRA.Utility.exe" d2k --clear-invalid-mod-registrations system'
172	SetShellVarContext current
173
174SectionEnd
175
176Section "Desktop Shortcut" DESKTOPSHORTCUT
177	SetOutPath "$INSTDIR"
178	CreateShortCut "$DESKTOP\OpenRA - Red Alert${SUFFIX}.lnk" $INSTDIR\RedAlert.exe "" \
179		"$INSTDIR\RedAlert.exe" "" "" "" ""
180	CreateShortCut "$DESKTOP\OpenRA - Tiberian Dawn${SUFFIX}.lnk" $INSTDIR\TiberianDawn.exe "" \
181		"$INSTDIR\TiberianDawn.exe" "" "" "" ""
182	CreateShortCut "$DESKTOP\OpenRA - Dune 2000${SUFFIX}.lnk" $INSTDIR\Dune2000.exe "" \
183		"$INSTDIR\Dune2000.exe" "" "" "" ""
184SectionEnd
185
186;***************************
187;Dependency Sections
188;***************************
189Section "-DotNet" DotNet
190	ClearErrors
191	; https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
192	ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Release"
193	IfErrors error 0
194	IntCmp $0 461808 done error done
195	error:
196		MessageBox MB_OK ".NET Framework v4.7.2 or later is required to run OpenRA."
197		Abort
198	done:
199SectionEnd
200
201;***************************
202;Uninstaller Sections
203;***************************
204Section "-Uninstaller"
205	WriteUninstaller $INSTDIR\uninstaller.exe
206	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "DisplayName" "OpenRA${SUFFIX}"
207	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "UninstallString" "$INSTDIR\uninstaller.exe"
208	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
209	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "InstallLocation" "$INSTDIR"
210	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "DisplayIcon" "$INSTDIR\OpenRA.ico"
211	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "Publisher" "OpenRA developers"
212	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "URLInfoAbout" "http://openra.net"
213	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "Readme" "$INSTDIR\README.html"
214	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "DisplayVersion" "${TAG}"
215	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "NoModify" "1"
216	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}" "NoRepair" "1"
217SectionEnd
218
219!macro Clean UN
220Function ${UN}Clean
221	nsExec::ExecToLog '"$INSTDIR\OpenRA.Utility.exe" ra --unregister-mod system'
222	nsExec::ExecToLog '"$INSTDIR\OpenRA.Utility.exe" cnc --unregister-mod system'
223	nsExec::ExecToLog '"$INSTDIR\OpenRA.Utility.exe" d2k --unregister-mod system'
224
225	RMDir /r $INSTDIR\mods
226	RMDir /r $INSTDIR\maps
227	RMDir /r $INSTDIR\glsl
228	RMDir /r $INSTDIR\lua
229	Delete $INSTDIR\RedAlert.exe
230	Delete $INSTDIR\TiberianDawn.exe
231	Delete $INSTDIR\Dune2000.exe
232	Delete $INSTDIR\OpenRA.Game.exe
233	Delete $INSTDIR\OpenRA.Game.exe.config
234	Delete $INSTDIR\OpenRA.Utility.exe
235	Delete $INSTDIR\OpenRA.Server.exe
236	Delete $INSTDIR\OpenRA.Platforms.Default.dll
237	Delete $INSTDIR\ICSharpCode.SharpZipLib.dll
238	Delete $INSTDIR\FuzzyLogicLibrary.dll
239	Delete $INSTDIR\Open.Nat.dll
240	Delete $INSTDIR\VERSION
241	Delete $INSTDIR\AUTHORS
242	Delete $INSTDIR\COPYING
243	Delete $INSTDIR\README.html
244	Delete $INSTDIR\CHANGELOG.html
245	Delete $INSTDIR\CONTRIBUTING.html
246	Delete $INSTDIR\OpenRA.ico
247	Delete $INSTDIR\RedAlert.ico
248	Delete $INSTDIR\TiberianDawn.ico
249	Delete $INSTDIR\Dune2000.ico
250	Delete "$INSTDIR\global mix database.dat"
251	Delete $INSTDIR\IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP
252	Delete $INSTDIR\soft_oal.dll
253	Delete $INSTDIR\SDL2.dll
254	Delete $INSTDIR\lua51.dll
255	Delete $INSTDIR\eluant.dll
256	Delete $INSTDIR\freetype6.dll
257	Delete $INSTDIR\SDL2-CS.dll
258	Delete $INSTDIR\OpenAL-CS.Core.dll
259	Delete $INSTDIR\BeaconLib.dll
260	RMDir /r $INSTDIR\Support
261
262	DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA${SUFFIX}"
263	DeleteRegKey HKLM "Software\Classes\openra-ra-${TAG}"
264	DeleteRegKey HKLM "Software\Classes\openra-cnc-${TAG}"
265	DeleteRegKey HKLM "Software\Classes\openra-d2k-${TAG}"
266
267	Delete $INSTDIR\uninstaller.exe
268	RMDir $INSTDIR
269
270	!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
271
272	; Clean up start menu: Delete all our icons, and the OpenRA folder
273	; *only* if we were the only installed version
274	Delete "$SMPROGRAMS\$StartMenuFolder\Red Alert${SUFFIX}.lnk"
275	Delete "$SMPROGRAMS\$StartMenuFolder\Tiberian Dawn${SUFFIX}.lnk"
276	Delete "$SMPROGRAMS\$StartMenuFolder\Dune 2000${SUFFIX}.lnk"
277	RMDir "$SMPROGRAMS\$StartMenuFolder"
278
279	Delete "$DESKTOP\OpenRA - Red Alert${SUFFIX}.lnk"
280	Delete "$DESKTOP\OpenRA - Tiberian Dawn${SUFFIX}.lnk"
281	Delete "$DESKTOP\OpenRA - Dune 2000${SUFFIX}.lnk"
282	DeleteRegKey HKLM "Software\OpenRA${SUFFIX}"
283FunctionEnd
284!macroend
285
286!insertmacro Clean ""
287!insertmacro Clean "un."
288
289Section "Uninstall"
290	Call un.Clean
291SectionEnd
292
293;***************************
294;Section Descriptions
295;***************************
296LangString DESC_GAME ${LANG_ENGLISH} "OpenRA engine, official mods and dependencies"
297LangString DESC_DESKTOPSHORTCUT ${LANG_ENGLISH} "Place shortcut on the Desktop."
298
299!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
300	!insertmacro MUI_DESCRIPTION_TEXT ${GAME} $(DESC_GAME)
301	!insertmacro MUI_DESCRIPTION_TEXT ${DESKTOPSHORTCUT} $(DESC_DESKTOPSHORTCUT)
302!insertmacro MUI_FUNCTION_DESCRIPTION_END
303
304;***************************
305;Callbacks
306;***************************
307
308Function .onInstFailed
309	Call Clean
310FunctionEnd
311