forked from Wargus/wargus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wargus.nsi
464 lines (368 loc) · 15.2 KB
/
wargus.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
; _________ __ __
; / _____// |_____________ _/ |______ ____ __ __ ______
; \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
; / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
; /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
; \/ \/ \//_____/ \/
; ______________________ ______________________
; T H E W A R B E G I N S
; Stratagus - A free fantasy real time strategy game engine
;
; wargus.nsi - Windows NSIS Installer for Wargus
; Copyright (C) 2010-2014 Pali Rohar <[email protected]>, cybermind <[email protected]>
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
;
;--------------------------------
!ifdef QUIET
!verbose 2
!endif
!define redefine "!insertmacro redefine"
!macro redefine symbol value
!undef ${symbol}
!define ${symbol} "${value}"
!macroend
!include "MUI2.nsh"
!include "Sections.nsh"
;--------------------------------
; General variables
!define NAME "Wargus"
!define VERSION "3.3.3"
!define VIVERSION "${VERSION}.0"
!define HOMEPAGE "https://wargus.github.io"
!define LICENSE "GPL v2+"
!define COPYRIGHT "Copyright (c) 1998-2022 by The Stratagus Project"
!define STRATAGUS_NAME "Stratagus"
!define STRATAGUS_HOMEPAGE "https://github.com/Wargus/stratagus"
;--------------------------------
!define ICON "wargus.ico"
!define EXE "wargus.exe"
!define WARTOOL "wartool.exe"
!define PUDCONVERT "pudconvert.exe"
; -- have to try and copy these, VS might have put them under (Release|Debug)
!system "powershell -Command $\"& {cp **\${WARTOOL} ${WARTOOL}}$\""
!system "powershell -Command $\"& {cp **\${EXE} ${EXE}}$\""
!system "powershell -Command $\"& {cp **\${PUDCONVERT} ${PUDCONVERT}}$\""
!define CDDA2WAV "cdda2wav.exe"
!define INNOEXTRACT "innoextract.exe"
!define FFMPEG "ffmpeg.exe"
!define SF2BANK "TimGM6mb.sf2"
!define VCREDIST "vc_redist.x86.exe"
!define VCREDISTREGKEY "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86"
!ifndef PORTABLE
!define UNINSTALL "uninstall.exe"
!define INSTALLER "${NAME}-${VERSION}.exe"
!define INSTALLDIR "$PROGRAMFILES\${NAME}\"
!else
!define INSTALLER "${NAME}-portable-${VERSION}.exe"
!define INSTALLDIR "$DESKTOP\${NAME}\"
!endif
; Installer for x86-64 systems
!ifdef x86_64
${redefine} INSTALLER "${NAME}-${VERSION}-x86_64.exe"
${redefine} INSTALLDIR "$PROGRAMFILES64\${NAME}\"
${redefine} NAME "Wargus (64 bit)"
${redefine} STRATAGUS_NAME "Stratagus (64 bit)"
${redefine} VCREDIST "vc_redist.x64.exe"
${redefine} VCREDISTREGKEY "SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"
!endif
; Registry paths
!ifndef PORTABLE
!define REGKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}"
!define STRATAGUS_REGKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${STRATAGUS_NAME}"
!endif
;--------------------------------
; Download and extract nessesary 3rd party programs
!ifndef NO_DOWNLOAD
!system "powershell -Command $\"& {wget https://github.com/Wargus/stratagus/releases/download/2015-30-11/${INNOEXTRACT} -OutFile ${INNOEXTRACT}}$\""
!system "powershell -Command $\"& {wget https://github.com/Wargus/stratagus/releases/download/2015-30-11/${FFMPEG} -OutFile ${FFMPEG}}$\""
!system "powershell -Command $\"& {wget https://github.com/Wargus/stratagus/releases/download/2015-30-11/${CDDA2WAV} -OutFile ${CDDA2WAV}}$\""
!system "powershell -Command $\"& {wget https://github.com/Wargus/stratagus/releases/download/2015-30-11/${SF2BANK} -OutFile ${SF2BANK}}$\""
!system "powershell -Command $\"& {wget https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/${VCREDIST} -OutFile ${VCREDIST}}$\""
!endif
!addplugindir .
;--------------------------------
!ifndef PORTABLE
Var STARTMENUDIR
!endif
!define MUI_ICON "${ICON}"
!define MUI_UNICON "${ICON}"
; Installer pages
!define MUI_ABORTWARNING
!define MUI_LANGDLL_ALLLANGUAGES
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
!define MUI_FINISHPAGE_RUN "$INSTDIR\${EXE}"
!define MUI_UNFINISHPAGE_NOAUTOCLOSE
!define MUI_UNFINISHPAGE_NOREBOOTSUPPORT
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${REGKEY}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "StartMenu"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "COPYING"
!insertmacro MUI_PAGE_LICENSE "COPYING-3rd"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!ifndef PORTABLE
!insertmacro MUI_PAGE_STARTMENU Application $STARTMENUDIR
!endif
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_COMPONENTS
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
; Available languages
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Russian"
!insertmacro MUI_RESERVEFILE_LANGDLL
; Language-dependent strings
LangString INSTALLER_RUNNING ${LANG_ENGLISH} "${NAME} Installer is already running"
LangString INSTALLER_RUNNING ${LANG_RUSSIAN} "Установщик ${NAME} уже запущен"
LangString NO_STRATAGUS ${LANG_ENGLISH} "${STRATAGUS_NAME} ${VERSION} is not installed.$\nYou need ${STRATAGUS_NAME} ${VERSION} to run ${NAME}!$\nFirst install ${STRATAGUS_NAME} ${VERSION} from ${STRATAGUS_HOMEPAGE}"
LangString NO_STRATAGUS ${LANG_RUSSIAN} "${STRATAGUS_NAME} ${VERSION} is not installed.$\nYou need ${STRATAGUS_NAME} ${VERSION} to run ${NAME}!$\nFirst install ${STRATAGUS_NAME} ${VERSION} from ${STRATAGUS_HOMEPAGE}"
LangString REMOVEPREVIOUS ${LANG_ENGLISH} "Removing previous installation"
LangString REMOVEPREVIOUS ${LANG_RUSSIAN} "Удаляются файлы из предыдущей установки"
LangString REMOVECONFIGURATION ${LANG_ENGLISH} "Removing configuration and data files:"
LangString REMOVECONFIGURATION ${LANG_RUSSIAN} "Удаляются данные и файлы конфигураций:"
LangString DESC_REMOVEEXE ${LANG_ENGLISH} "Remove ${NAME} binary executables"
LangString DESC_REMOVEEXE ${LANG_RUSSIAN} "Удаляются исполняемые файлы ${NAME}"
LangString DESC_REMOVECONF ${LANG_ENGLISH} "Remove all other configuration and extracted data files and directories in ${NAME} install directory created by user or ${NAME}"
LangString DESC_REMOVECONF ${LANG_RUSSIAN} "Удалить все прочие файлы и директории в установочной папке ${NAME}, созданные пользователем ${NAME}"
LangString STR_VERSION ${LANG_ENGLISH} "version"
LangString STR_VERSION ${LANG_RUSSIAN} "версия"
!ifdef x86_64
LangString x86_64_ONLY ${LANG_ENGLISH} "This version is for 64 bits computers only"
LangString x86_64_ONLY ${LANG_RUSSIAN} "Эта версия предназначена для 64-битных систем"
!endif
;--------------------------------
Name "${NAME}"
Icon "${ICON}"
OutFile "${INSTALLER}"
InstallDir "${INSTALLDIR}"
InstallDirRegKey HKLM "${REGKEY}" "InstallLocation"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "${NAME} Installer"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "InternalName" "${NAME} Installer"
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "${COPYRIGHT}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "License" "${LICENSE}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "Homepage" "${HOMEPAGE}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "OriginalFilename" "${INSTALLER}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${NAME} Installer"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "${VERSION}"
VIProductVersion "${VIVERSION}"
BrandingText "${NAME}, $(STR_VERSION) ${VERSION} ${HOMEPAGE}"
ShowInstDetails Show
!ifndef PORTABLE
ShowUnInstDetails Show
!endif
XPStyle on
!ifndef PORTABLE
RequestExecutionLevel admin
!else
RequestExecutionLevel user
!endif
ReserveFile "${WARTOOL}"
;--------------------------------
Section "${NAME}"
SectionIn RO
SectionEnd
!ifndef PORTABLE
Section "-${NAME}" UninstallPrevious
SectionIn RO
ReadRegStr $0 HKLM "${REGKEY}" "InstallLocation"
StrCmp $0 "" +7
DetailPrint "$(REMOVEPREVIOUS)"
SetDetailsPrint none
ExecWait "$0\${UNINSTALL} /S _?=$0"
Delete "$0\${UNINSTALL}"
RMDir $0
SetDetailsPrint lastused
SectionEnd
!endif
Section "-${NAME}"
SectionIn RO
SetOutPath "$INSTDIR"
File "${EXE}"
File "${WARTOOL}"
File "${PUDCONVERT}"
File "${CDDA2WAV}"
File "${INNOEXTRACT}"
File "${FFMPEG}"
; -- XXX TODO: include Stratagus and dependencies some better way
File "stratagus.exe"
File stratagus-midiplayer.exe
SetOutPath "$INSTDIR\music"
File "${SF2BANK}"
SetOutPath "$INSTDIR"
ClearErrors
ReadRegDword $R0 HKLM "${VCREDISTREGKEY}" "Installed"
IfErrors 0 NoErrors
StrCpy $R0 0
NoErrors:
${If} $R0 == 0
File "${VCREDIST}"
ExecWait "$\"$INSTDIR\${VCREDIST}$\" /passive /norestart"
Delete "$\"$INSTDIR\${VCREDIST}$\""
${EndIf}
ClearErrors
!cd ${CMAKE_CURRENT_SOURCE_DIR}
SetOutPath "$INSTDIR\maps"
File /r /x *.pud* "maps\"
SetOutPath "$INSTDIR\contrib"
File /r "contrib\"
SetOutPath "$INSTDIR\shaders"
File /r "shaders\"
SetOutPath "$INSTDIR\scripts"
File /r "scripts\"
SetOutPath "$INSTDIR\campaigns"
File /r "campaigns\"
SetOutPath "$INSTDIR"
CreateDirectory "$INSTDIR\music"
CreateDirectory "$INSTDIR\graphics"
CreateDirectory "$INSTDIR\graphics\ui"
CreateDirectory "$INSTDIR\graphics\ui\cursors"
CreateDirectory "$INSTDIR\graphics\missiles"
File "/oname=graphics\ui\cursors\cross.png" "contrib\cross.png"
File "/oname=graphics\missiles\red_cross.png" "contrib\red_cross.png"
File "/oname=graphics\ui\mana.png" "contrib\mana.png"
File "/oname=graphics\ui\mana2.png" "contrib\mana2.png"
File "/oname=graphics\ui\health.png" "contrib\health.png"
File "/oname=graphics\ui\health2.png" "contrib\health2.png"
File "/oname=graphics\ui\food.png" "contrib\food.png"
File "/oname=graphics\ui\score.png" "contrib\score.png"
File "/oname=graphics\ui\ore,stone,coal.png" "contrib\ore,stone,coal.png"
!cd ${CMAKE_CURRENT_BINARY_DIR}
!ifndef PORTABLE
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\$STARTMENUDIR"
CreateShortCut "$SMPROGRAMS\$STARTMENUDIR\${NAME}.lnk" "$INSTDIR\${EXE}"
CreateShortCut "$SMPROGRAMS\$STARTMENUDIR\${NAME} (Debug mode).lnk" "$INSTDIR\${EXE}" "-p -i"
CreateShortCut "$SMPROGRAMS\$STARTMENUDIR\${NAME} (Safe graphics mode).lnk" "$INSTDIR\${EXE}" "-g -W -v 640x480"
CreateShortCut "$SMPROGRAMS\$STARTMENUDIR\${NAME} Map Editor.lnk" "$INSTDIR\${EXE}" "-e -g -W -v 1280x960"
CreateShortCut "$SMPROGRAMS\$STARTMENUDIR\Uninstall.lnk" "$INSTDIR\${UNINSTALL}"
CreateShortcut "$DESKTOP\${NAME}.lnk" "$INSTDIR\${EXE}"
!insertmacro MUI_STARTMENU_WRITE_END
WriteRegStr HKLM "${REGKEY}" "DisplayName" "${NAME}"
WriteRegStr HKLM "${REGKEY}" "UninstallString" "$\"$INSTDIR\${UNINSTALL}$\""
WriteRegStr HKLM "${REGKEY}" "QuietUninstallString" "$\"$INSTDIR\${UNINSTALL}$\" /S"
WriteRegStr HKLM "${REGKEY}" "InstallLocation" "$INSTDIR"
WriteRegStr HKLM "${REGKEY}" "DisplayIcon" "$\"$INSTDIR\${EXE}$\",0"
WriteRegStr HKLM "${REGKEY}" "DisplayVersion" "${VERSION}"
WriteRegStr HKLM "${REGKEY}" "HelpLink" "${HOMEPAGE}"
WriteRegStr HKLM "${REGKEY}" "URLUpdateInfo" "${HOMEPAGE}"
WriteRegStr HKLM "${REGKEY}" "URLInfoAbout" "${HOMEPAGE}"
WriteRegDWORD HKLM "${REGKEY}" "NoModify" 1
WriteRegDWORD HKLM "${REGKEY}" "NoRepair" 1
WriteRegStr HKLM "${STRATAGUS_REGKEY}\Games" "${NAME}" "${VERSION}"
WriteUninstaller "$INSTDIR\${UNINSTALL}"
!else
!appendfile "$%temp%\compiletimefile" ""
File "/oname=$INSTDIR\portable-install" "$%temp%\compiletimefile"
CreateShortCut "$INSTDIR\${NAME}.lnk" "$INSTDIR\${EXE}"
CreateShortCut "$INSTDIR\${NAME} (Debug mode).lnk" "$INSTDIR\${EXE}" "-p -i"
CreateShortCut "$INSTDIR\${NAME} (Safe graphics mode).lnk" "$INSTDIR\${EXE}" "-g -W -v 640x480"
CreateShortCut "$INSTDIR\${NAME} Map Editor.lnk" "$INSTDIR\${EXE}" "-e -g -W -v 1280x960"
!endif
SectionEnd
;--------------------------------
!ifndef PORTABLE
Section "un.${NAME}" Executable
SectionIn RO
Delete "$INSTDIR\${EXE}"
Delete "$INSTDIR\${WARTOOL}"
Delete "$INSTDIR\${PUDCONVERT}"
Delete "$INSTDIR\${CDDA2WAV}"
Delete "$INSTDIR\${INNOEXTRACT}"
Delete "$INSTDIR\${FFMPEG}"
Delete "$INSTDIR\${UNINSTALL}"
IfFileExists "$INSTDIR\scripts\wc2-config.lua" 0 +2
Rename "$INSTDIR\scripts\wc2-config.lua" "$INSTDIR\wc2-config.lua"
RMDir /r "$INSTDIR\scripts"
IfFileExists "$INSTDIR\wc2-config.lua" 0 +3
CreateDirectory "$INSTDIR\scripts"
Rename "$INSTDIR\wc2-config.lua" "$INSTDIR\scripts\wc2-config.lua"
Delete "$INSTDIR\campaigns\human\level*h_c.sms"
Delete "$INSTDIR\campaigns\orc\level*o_c.sms"
Delete "$INSTDIR\campaigns\human-exp\levelx*h_c.sms"
Delete "$INSTDIR\campaigns\orc-exp\levelx*o_c.sms"
RMDir "$INSTDIR\campaigns\human"
RMDir "$INSTDIR\campaigns\orc"
RMDir "$INSTDIR\campaigns\human-exp"
RMDir "$INSTDIR\campaigns\orc-exp"
RMDir "$INSTDIR\campaigns"
RMDir "$INSTDIR"
!insertmacro MUI_STARTMENU_GETFOLDER Application $STARTMENUDIR
Delete "$SMPROGRAMS\$STARTMENUDIR\${NAME}.lnk"
Delete "$SMPROGRAMS\$STARTMENUDIR\Uninstall.lnk"
RMDir "$SMPROGRAMS\$STARTMENUDIR"
Delete "$DESKTOP\${NAME}.lnk"
DeleteRegKey HKLM "${REGKEY}"
DeleteRegValue HKLM "${STRATAGUS_REGKEY}\Games" "${NAME}"
ClearErrors
EnumRegValue $0 HKLM "${REGKEY}\Games" 0
IfErrors +2
DeleteRegKey /ifempty HKLM "${STRATAGUS_REGKEY}\Games"
SectionEnd
Section /o "un.Configuration" Configuration
DetailPrint "$(REMOVECONFIGURATION)"
RMDir /r "$INSTDIR"
SectionEnd
!insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT "${Executable}" "$(DESC_REMOVEEXE)"
!insertmacro MUI_DESCRIPTION_TEXT "${Configuration}" "$(DESC_REMOVECONF)"
!insertmacro MUI_UNFUNCTION_DESCRIPTION_END
!endif
;--------------------------------
Function .onInit
; Check if Wargus installer is already running
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${NAME}") i .r1 ?e'
Pop $0
StrCmp $0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "$(INSTALLER_RUNNING)"
Abort
!ifdef x86_64
System::Call "kernel32::GetCurrentProcess() i .s"
System::Call "kernel32::IsWow64Process(i s, *i .r0)"
IntCmp $0 0 0 0 +3
MessageBox MB_OK|MB_ICONSTOP "$(x86_64_ONLY)"
Abort
!endif
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
Function .onSelChange
FunctionEnd
;--------------------------------
!ifdef UPX
!ifndef UPX_FLAGS
!define UPX_FLAGS "-9"
!else
${redefine} UPX_FLAGS "${UPX_FLAGS} -9"
!endif
!ifdef QUIET
${redefine} UPX_FLAGS "${UPX_FLAGS} -q"
!endif
!packhdr "exehead.tmp" "${UPX} ${UPX_FLAGS} exehead.tmp"
!endif
;!finalize "gpg --armor --sign --detach-sig %1"
;--------------------------------
!ifndef NO_DOWNLOAD
!delfile "${INNOEXTRACT}"
!delfile "${FFMPEG}"
!delfile "${CDDA2WAV}"
!delfile "${SF2BANK}"
!endif
;--------------------------------