forked from jamespetts/simutrans-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimutrans-offline.nsi
411 lines (310 loc) · 10.5 KB
/
simutrans-offline.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
; Section define/macro header file
; See this header file for more info
!include "MUI2.nsh"
!include "Sections.nsh"
!include "zipdll.nsh"
; Parameter for functions
var downloadlink
var downloadname
var archievename
var group1
var multiuserinstall
;******** This script assumes, you have installed all the paks and GDI exe to this directory *******
;******** There should be also a folder SDL containing the SDL exe and DLL *******
;******** There should be also a folder pak64addon containing the food chain addon *******
;******** There should be also a folder pak64addon/font with the chinese font *******
!define SP_PATH "C:\Programme\simutrans"
Name "Simutrans Transport Simulator"
OutFile "simutrans-offline-install.exe"
; The default installation directory
InstallDir $PROGRAMFILES\Simutrans
XPStyle on
; Request application privileges for Windows Vista
RequestExecutionLevel admin
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "simutranssmall.bmp"
!define MUI_BGCOLOR 000000
!insertmacro MUI_LANGUAGE "English" ;first language is the default language
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "German"
!insertmacro MUI_LANGUAGE "Spanish"
!insertmacro MUI_LANGUAGE "SpanishInternational"
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "TradChinese"
!insertmacro MUI_LANGUAGE "Japanese"
!insertmacro MUI_LANGUAGE "Italian"
!insertmacro MUI_LANGUAGE "Dutch"
!insertmacro MUI_LANGUAGE "Danish"
!insertmacro MUI_LANGUAGE "Swedish"
!insertmacro MUI_LANGUAGE "Norwegian"
!insertmacro MUI_LANGUAGE "NorwegianNynorsk"
!insertmacro MUI_LANGUAGE "Finnish"
!insertmacro MUI_LANGUAGE "Greek"
!insertmacro MUI_LANGUAGE "Russian"
!insertmacro MUI_LANGUAGE "Portuguese"
!insertmacro MUI_LANGUAGE "PortugueseBR"
!insertmacro MUI_LANGUAGE "Polish"
!insertmacro MUI_LANGUAGE "Czech"
!insertmacro MUI_LANGUAGE "Slovak"
!insertmacro MUI_LANGUAGE "Croatian"
!insertmacro MUI_LANGUAGE "Bulgarian"
!insertmacro MUI_LANGUAGE "Hungarian"
!insertmacro MUI_LANGUAGE "Romanian"
!insertmacro MUI_LANGUAGE "Latvian"
!insertmacro MUI_LANGUAGE "Estonian"
!insertmacro MUI_LANGUAGE "Turkish"
!insertmacro MUI_LANGUAGE "Lithuanian"
!insertmacro MUI_LANGUAGE "Indonesian"
!insertmacro MUI_LANGUAGE "Belarusian"
!insertmacro MUI_LANGUAGE "Catalan"
; we need to start with sections first for the second licence
SectionGroup !Simutrans
Function PostExeInstall
StrCmp $multiuserinstall "1" NotPortable
; just change to simuconf.tab "singleuser_install = 1"
FileOpen $0 "$INSTDIR\config\simuconf.tab" a
FileSeek $0 866
FileWrite $0 "singleuser_install = 1 "
FileClose $0
goto finishGDIexe
NotPortable:
; make start menu entries
CreateDirectory "$SMPROGRAMS\Simutrans"
CreateShortCut "$SMPROGRAMS\Simutrans\Simutrans.lnk" "$INSTDIR\Simutrans.exe" "-log 1 -debug 3"
finishGDIexe:
; uninstaller not working yet
;WriteUninstaller $INSTDIR\uninstaller.exe
FunctionEnd
Section "Executable (GDI, Unicode)" GDIexe
SetOutPath $INSTDIR
File "${SP_PATH}\simutrans.exe"
File "${SP_PATH}\*.txt"
File /r "${SP_PATH}\text"
File /r "${SP_PATH}\font"
File /r "${SP_PATH}\skin"
File /r "${SP_PATH}\music"
File /r "${SP_PATH}\config\simuconf.tab"
SectionEnd
Section /o "Executable (SDL, better sound)" SDLexe
SetOutPath $INSTDIR
File "${SP_PATH}\SDL\*.*"
File "${SP_PATH}\*.txt"
File /r "${SP_PATH}\text"
File /r "${SP_PATH}\font"
File /r "${SP_PATH}\skin"
File /r "${SP_PATH}\music"
File /r "${SP_PATH}\config\simuconf.tab"
SectionEnd
Section /o "Chinese Font" wenquanyi_font
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak64addon\font"
SectionEnd
SectionGroupEnd
SectionGroup "Pak64: main and addons" pak64group
Section "!pak64 (standard)" pak64
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak"
SectionEnd
Section /o "pak64 Food addon 102.2.1"
StrCmp $multiuserinstall "1" InstallInUserDir
; no multiuser => install in normal directory
SetOutPath $INSTDIR
goto FinishFood64
InstallInUserDir:
SetOutPath $DOCUMENTS\simutrans
FinishFood64:
File /r "${SP_PATH}\pak64addon\pak"
SectionEnd
SectionGroupEnd
Section /o "pak64.german (Freeware)" pak64german
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak"
SectionEnd
Section /o "pak64 HAJO (Freeware) 102.2" pak64HAJO
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak.german"
SectionEnd
Section /o "pak96 Comic (beta, Freeware) 102.2" pak96comic
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak96.comic"
SectionEnd
Section /o "pak128 (Freeware) 102.2.2" pak128
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak128"
SectionEnd
Section /o "pak128 Japan 101.0" pak128japan
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak128.japan"
SectionEnd
Section /o "pak128 Britain (0.7) 102.2.1" pak128britain
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak128.britain"
SectionEnd
Section /o "pak192 Comic (Freeware) 102.2.1" pak192comic
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak192.comic"
SectionEnd
Section /o "pak32 Comic (alpha) 102.2.1" pak32comic
SetOutPath $INSTDIR
File /r "${SP_PATH}\pak32.comic"
SectionEnd
# create a section to define what the uninstaller does.
# the section will always be named "Uninstall"
section "Uninstall"
Delete $INSTDIR\uninstaller.exe
RMDir /r $INSTDIR
sectionEnd
;***************************************************** from here on come sections *****************************************
; we just ask for Artistic licences, the other re only asked for certain paks
PageEx license
LicenseData "license.rtf"
PageExEnd
; If not installed to program dir, ask for a portable installation
Function CheckForPortableInstall
StrCpy $multiuserinstall "1"
StrCmp $INSTDIR $PROGRAMFILES\Simutrans NonPortable
MessageBox MB_YESNO|MB_ICONINFORMATION "Should this be a portable installation?" IDYES Portable IDNO NonPortable
Portable:
StrCpy $multiuserinstall "0"
NonPortable:
FunctionEnd
PageEx directory
PageCallbacks "" "" CheckForPortableInstall
PageExEnd
PageEx components
PageExEnd
; Some packs have not opene source license, so we have to show additional licences
Function CheckForClosedSource
SectionGetFlags ${pak64german} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show
SectionGetFlags ${pak64HAJO} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show
SectionGetFlags ${pak96comic} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show
SectionGetFlags ${pak128} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show
SectionGetFlags ${pak192comic} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show
Abort
show:
; here is ok
FunctionEnd
PageEx License
LicenseData "pak128.txt"
PageCallbacks CheckForClosedSource "" ""
PageExEnd
PageEx instfiles
PageExEnd
; ******************************** From here on Functions ***************************
Function .oninit
StrCpy $multiuserinstall "1"
; activates GDI by default
StrCpy $group1 ${GDIexe} ; Group 1 - Option 1 is selected by default
; avoids two instance at the same time ...
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "SimutransMutex") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."
Abort
FunctionEnd
; ConnectInternet (uses Dialer plug-in)
; Written by Joost Verburg
;
; This function attempts to make a connection to the internet if there is no
; connection available. If you are not sure that a system using the installer
; has an active internet connection, call this function before downloading
; files with NSISdl.
;
; The function requires Internet Explorer 3, but asks to connect manually if
; IE3 is not installed.
Function ConnectInternet
Push $R0
ClearErrors
Dialer::AttemptConnect
IfErrors noie3
Pop $R0
StrCmp $R0 "online" connected
MessageBox MB_OK|MB_ICONSTOP "Cannot connect to the internet."
Quit ;This will quit the installer. You might want to add your own error handling.
noie3:
; IE3 not installed
MessageBox MB_OK|MB_ICONINFORMATION "Please connect to the internet now."
connected:
Pop $R0
FunctionEnd
; make sure, at least one executable is installed
Function .onSelChange
!insertmacro StartRadioButtons $group1
!insertmacro RadioButton ${GDIexe}
!insertmacro RadioButton ${SDLexe}
!insertmacro EndRadioButtons
; make sure GDI is installed when chinese is selected
SectionGetFlags ${wenquanyi_font} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} +1 test_for_pak
; force selection of GDI exe
SectionGetFlags ${GDIexe} $R0
IntOp $R0 $R0 | ${SF_SELECTED}
SectionSetFlags ${GDIexe} $R0
SectionGetFlags ${SDLexe} $R0
IntOp $R0 $R0 & ${SECTION_OFF}
SectionSetFlags ${SDLexe} $R0
test_for_pak:
; Make sure at least some pak is selected
SectionGetFlags ${pak64} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show_not
SectionGetFlags ${pak64german} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show_not
SectionGetFlags ${pak64HAJO} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show_not
SectionGetFlags ${pak96comic} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show_not
SectionGetFlags ${pak128} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show_not
SectionGetFlags ${pak128japan} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show_not
SectionGetFlags ${pak128britain} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show_not
SectionGetFlags ${pak192comic} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show_not
SectionGetFlags ${pak32comic} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show_not
; not pak selected!
MessageBox MB_OK|MB_ICONSTOP "At least on pak set must be selected!"
show_not:
FunctionEnd
; $downloadlink is then name of the link, $downloadanme the name of the pak for error messages
Function DownloadInstall
; MessageBox MB_OK|MB_ICONINFORMATION "Download of $downloadname from\n$downloadlink$archievename"
Call ConnectInternet
RMdir /r "$TEMP\simutrans"
NSISdl::download $downloadlink$archievename "$Temp\$archievename"
Pop $R0 ;Get the return value
StrCmp $R0 "success" +3
MessageBox MB_OK "Download of $archievename failed: $R0"
Quit
ZipDLL::extractall "$TEMP\$archievename" "$TEMP"
Pop $0
StrCmp $0 "success" exeok
DetailPrint "$0" ;print error message to log
RMdir /r "$TEMP\simutrans"
Quit
exeok:
CreateDirectory "$INSTDIR"
CopyFiles "$TEMP\Simutrans\*.*" "$INSTDIR"
RMdir /r "$TEMP\simutrans"
FunctionEnd