forked from ETS2LA/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.nsi
More file actions
444 lines (381 loc) · 15 KB
/
main.nsi
File metadata and controls
444 lines (381 loc) · 15 KB
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
Unicode True
!include "MUI2.nsh"
!include "nsDialogs.nsh"
RequestExecutionLevel user
# Variables
InstallDir "C:\ETS2LA"
!define BRANCH "main"
!define GITLAB_URL "https://gitlab.com/ETS2LA/ETS2LA"
!define GITHUB_URL "https://github.com/ETS2LA/Euro-Truck-Simulator-2-Lane-Assist.git"
!define SOURCEFORGE_URL "https://git.code.sf.net/p/eurotrucksimulator2-laneassist/code"
!define CNB_URL "https://cnb.cool/ETS2LA-CN/Euro-Truck-Simulator-2-Lane-Assist.git"
# Installer Information
Name "ETS2LA"
BrandingText $(BrandingText)
Icon "img\favicon.ico"
OutFile "ETS2LA-Windows-Installer.exe"
# MUI Setup
!define MUI_ICON "img\favicon.ico"
!define MUI_UNICON "img\favicon.ico"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "img\header.bmp2"
!define MUI_HEADERIMAGE_UNBITMAP "img\header.bmp2"
!include "MUI2.nsh"
# Welcome Page
!define MUI_WELCOMEPAGE_TITLE $(WelcomeTitle)
!define MUI_WELCOMEPAGE_TEXT $(WelcomeText)
!define MUI_WELCOMEFINISHPAGE_BITMAP "img\welcome.bmp2"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "img\welcome.bmp2"
!insertmacro MUI_PAGE_WELCOME
# License Page
!define MUI_LICENSEPAGE_TEXT_BOTTOM $(LicenseText)
!insertmacro MUI_PAGE_LICENSE "LICENSE.txt"
# Scam page
Page custom ScamWarningPage ScamWarningPageLeave
Var Dialog
Var ScamCheckbox
Var ScamState
# Directory Page
!define MUI_DIRECTORYPAGE_TEXT_TOP $(DirectoryTitle)
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION $(DirectoryText)
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE DirPageLeave
!insertmacro MUI_PAGE_DIRECTORY
# Mirror selection
Page custom SelectMirrorPage SelectMirrorPageLeave
Var MirrorSelection
Var PyPi
Var RadioGitLab
Var RadioGitHub
Var RadioSourceForge
Var RadioCNB
Var PyPiMirrorSelection
Var pip_mirror_opts
# Shortcuts
Page custom ShortcutSelectionPage ShortcutSelectionPageLeave
Var StartMenuShortcut
Var DesktopShortcut
Var CheckStartMenu
Var CheckDesktop
# Installation Page
!insertmacro MUI_PAGE_INSTFILES
# Finish Page
!define MUI_FINISHPAGE_TITLE $(FinishTitle)
!define MUI_FINISHPAGE_TEXT $(FinishText)
!define MUI_FINISHPAGE_SHOWREADME "https://ets2la.com"
!define MUI_FINISHPAGE_SHOWREADME_TEXT $(WebsiteText)
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_TEXT $(LaunchText)
!define MUI_FINISHPAGE_RUN_FUNCTION LaunchETS2LA
!insertmacro MUI_PAGE_FINISH
# Block if directory not empty
Function DirPageLeave
IfFileExists "$INSTDIR\*.*" 0 dirEmpty
MessageBox MB_ICONSTOP|MB_OK $(DirectoryNotEmpty)
Abort
dirEmpty:
FunctionEnd
# Mirror page def
Function SelectMirrorPage
!insertmacro MUI_HEADER_TEXT $(MirrorHeader) $(MirrorHeaderDescription)
nsDialogs::Create 1018
Pop $0
${If} $0 == error
Abort
${EndIf}
# Create a label
${NSD_CreateLabel} 0 0 100% 24u $(MirrorTitle)
Pop $0
# Create radio buttons for mirrors
${NSD_CreateRadioButton} 0 30u 100% 12u "GitLab"
Pop $RadioGitLab
${NSD_CreateRadioButton} 0 45u 100% 12u "GitHub"
Pop $RadioGitHub
${NSD_CreateRadioButton} 0 60u 100% 12u "SourceForge"
Pop $RadioSourceForge
${NSD_CreateRadioButton} 0 75u 100% 12u "CNB"
Pop $RadioCNB
# Create a label for PyPi mirror selection
${NSD_CreateLabel} 0 95u 100% 12u "PyPi Mirror:"
Pop $0
# Create a ComboBox for PyPi mirrors
${NSD_CreateComboBox} 0 110u 100% 12u ""
Pop $PyPiMirrorSelection
${NSD_CB_AddString} $PyPiMirrorSelection "Default (pypi.org)"
${NSD_CB_AddString} $PyPiMirrorSelection "Aliyun"
${NSD_CB_AddString} $PyPiMirrorSelection "USTC (China)"
SendMessage $PyPiMirrorSelection ${CB_SETCURSEL} 2 0 # Default to USTC
# Set default selection (GitLab)
${NSD_SetState} $RadioGitLab ${BST_CHECKED}
# Show the dialog
nsDialogs::Show
FunctionEnd
Function SelectMirrorPageLeave
${NSD_GetState} $RadioGitLab $0
${If} $0 == ${BST_CHECKED}
StrCpy $MirrorSelection "GitLab"
${Else}
${NSD_GetState} $RadioGitHub $0
${If} $0 == ${BST_CHECKED}
StrCpy $MirrorSelection "GitHub"
${Else}
${NSD_GetState} $RadioSourceForge $0
${If} $0 == ${BST_CHECKED}
StrCpy $MirrorSelection "SourceForge"
${Else}
${NSD_GetState} $RadioCNB $0
${If} $0 == ${BST_CHECKED}
StrCpy $MirrorSelection "CNB"
${EndIf}
${EndIf}
${EndIf}
${EndIf}
SendMessage $PyPiMirrorSelection ${CB_GETCURSEL} 0 0 $PyPi
FunctionEnd
# Scam page def
Function ScamWarningPage
!insertmacro MUI_HEADER_TEXT $(ScamWarningHeader) $(ScamWarningHeaderDescription)
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
# Create a label with warning text
${NSD_CreateLabel} 0 0 100% 60u $(ScamWarningTitle)
Pop $0
# Create checkbox that must be checked
${NSD_CreateCheckBox} 0 70u 100% 20u $(ScamWarningCheckbox)
Pop $ScamCheckbox
# Show the page
nsDialogs::Show
FunctionEnd
Function ScamWarningPageLeave
${NSD_GetState} $ScamCheckbox $ScamState
${If} $ScamState != ${BST_CHECKED}
MessageBox MB_ICONEXCLAMATION $(ScamWarningNotChecked)
Abort
${EndIf}
FunctionEnd
# Shortcut page def
Function ShortcutSelectionPage
!insertmacro MUI_HEADER_TEXT $(ShortcutHeader) $(ShortcutHeaderDescription)
nsDialogs::Create 1018
Pop $0
${If} $0 == error
Abort
${EndIf}
# Create a label
${NSD_CreateLabel} 0 0 100% 24u $(ShortcutSelectionTitle)
Pop $0
# Create checkboxes for shortcuts
${NSD_CreateCheckBox} 0 30u 100% 12u $(CreateStartMenuShortcut)
Pop $CheckStartMenu
${NSD_CreateCheckBox} 0 50u 100% 12u $(CreateDesktopShortcut)
Pop $CheckDesktop
# Set default states (checked by default)
${NSD_SetState} $CheckStartMenu ${BST_CHECKED}
${NSD_SetState} $CheckDesktop ${BST_UNCHECKED}
# Show the dialog
nsDialogs::Show
FunctionEnd
Function ShortcutSelectionPageLeave
${NSD_GetState} $CheckStartMenu $0
${If} $0 == ${BST_CHECKED}
StrCpy $StartMenuShortcut "1"
${Else}
StrCpy $StartMenuShortcut "0"
${EndIf}
${NSD_GetState} $CheckDesktop $0
${If} $0 == ${BST_CHECKED}
StrCpy $DesktopShortcut "1"
${Else}
StrCpy $DesktopShortcut "0"
${EndIf}
FunctionEnd
Section "Python" SEC01
# Copy python
SetOutPath "$INSTDIR\system\python"
File /r "3rd-party\python\*.*"
File /r "3rd-party\python\*"
# Copy tkinter
File /r "3rd-party\tkinter-standalone-main\3.12\python_embedded\*"
# Install pip
DetailPrint $(InstallingPip)
nsExec::ExecToLog '"$INSTDIR\system\python\python.exe" "$INSTDIR\system\python\get-pip.py"'
Pop $0
${If} $0 != 0
MessageBox MB_ICONSTOP|MB_OK $(PipInstallError)
Abort $(PipInstallError)
${EndIf}
SectionEnd
Section "Git" SEC02
# Set output path for Git
SetOutPath "$INSTDIR\system\git"
File /r "3rd-party\git-for-windows\*.*"
File /r "3rd-party\git-for-windows\*"
SectionEnd
Section "Download" SEC03
# Set the output path for the app directory
SetOutPath "$INSTDIR\app"
DetailPrint "$(Cloning) $MirrorSelection"
Sleep 1000
# Clone the repository based on the selected mirror with progress
${If} $MirrorSelection == "GitLab"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${GITLAB_URL} .'
${ElseIf} $MirrorSelection == "GitHub"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${GITHUB_URL} .'
${ElseIf} $MirrorSelection == "SourceForge"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${SOURCEFORGE_URL} .'
${ElseIf} $MirrorSelection == "CNB"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${CNB_URL} .'
${EndIf}
# Check if git clone was successful
Pop $0
${If} $0 != 0
MessageBox MB_ICONSTOP|MB_OK $(GitCloneError)
DetailPrint $(GitCloneFailed)
# Try another mirror automatically
${If} $MirrorSelection == "GitLab"
DetailPrint $(TryingAnotherMirror)
DetailPrint "GitHub"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${GITHUB_URL} .' $0
Pop $0
${If} $0 != 0
DetailPrint $(TryingAnotherMirror)
DetailPrint "SourceForge"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${SOURCEFORGE_URL} .' $0
Pop $0
${If} $0 != 0
DetailPrint $(TryingAnotherMirror)
DetailPrint "CNB"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${CNB_URL} .' $0
Pop $0
${If} $0 != 0
MessageBox MB_ICONSTOP|MB_OK $(AllMirrorsFailed)
Abort $(InstallationAborted)
${EndIf}
${EndIf}
${EndIf}
${ElseIf} $MirrorSelection == "GitHub"
DetailPrint $(TryingAnotherMirror)
DetailPrint "GitLab"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${GITLAB_URL} .' $0
Pop $0
${If} $0 != 0
DetailPrint $(TryingAnotherMirror)
DetailPrint "SourceForge"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${SOURCEFORGE_URL} .' $0
Pop $0
${If} $0 != 0
DetailPrint $(TryingAnotherMirror)
DetailPrint "CNB"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${CNB_URL} .' $0
Pop $0
${If} $0 != 0
MessageBox MB_ICONSTOP|MB_OK $(AllMirrorsFailed)
Abort $(InstallationAborted)
${EndIf}
${EndIf}
${EndIf}
${ElseIf} $MirrorSelection == "SourceForge"
DetailPrint $(TryingAnotherMirror)
DetailPrint "GitLab"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${GITLAB_URL} .' $0
Pop $0
${If} $0 != 0
DetailPrint $(TryingAnotherMirror)
DetailPrint "GitHub"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${GITHUB_URL} .' $0
Pop $0
${If} $0 != 0
DetailPrint $(TryingAnotherMirror)
DetailPrint "CNB"
nsExec::ExecToLog '"$INSTDIR\system\git\bin\git.exe" clone --quiet --depth=20 --branch=${BRANCH} --single-branch ${CNB_URL} .' $0
Pop $0
${If} $0 != 0
MessageBox MB_ICONSTOP|MB_OK $(AllMirrorsFailed)
Abort $(InstallationAborted)
${EndIf}
${EndIf}
${EndIf}
${EndIf}
${EndIf}
# Verify that the repository was cloned successfully by checking README and requirements
${If} ${FileExists} "$INSTDIR\app\README.md"
${AndIf} ${FileExists} "$INSTDIR\app\requirements.txt"
DetailPrint $(GitCloneSuccess)
${Else}
MessageBox MB_ICONSTOP|MB_OK $(IncompleteRepo)
Abort $(InstallationAborted)
${EndIf}
# Install python requirements
StrCpy $pip_mirror_opts ""
${If} $PyPi == "1" # Aliyun
StrCpy $pip_mirror_opts '--index-url https://mirrors.aliyun.com/pypi/simple/'
${ElseIf} $PyPi == "2" # USTC
StrCpy $pip_mirror_opts '--index-url https://mirrors.ustc.edu.cn/pypi/simple'
${EndIf}
DetailPrint $(PythonRequirements)
nsExec::ExecToLog '"$INSTDIR\system\python\python.exe" -m pip install --verbose --no-warn-script-location $pip_mirror_opts --no-cache-dir wheel setuptools poetry requests'
DetailPrint $(PythonTakesLong)
nsExec::ExecToLog '"$INSTDIR\system\python\python.exe" -m pip install --verbose --no-warn-script-location $pip_mirror_opts --no-cache-dir -r "$INSTDIR\app\requirements.txt"'
SectionEnd
Section "Executables" SEC04
SetOutPath "$INSTDIR"
File /r "executables\*.*"
File /r "executables\*"
SetOutPath "$INSTDIR\system"
File /r "img\favicon.ico"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ETS2LA" "DisplayName" "ETS2LA"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ETS2LA" "UninstallString" "$INSTDIR\ETS2LA-Uninstaller.exe"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ETS2LA" "InstallLocation" "$INSTDIR"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ETS2LA" "DisplayIcon" "$INSTDIR\system\favicon.ico"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ETS2LA" "Publisher" "ETS2LA Team"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ETS2LA" "DisplayVersion" "0.3.0"
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ETS2LA" "NoModify" 1
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ETS2LA" "NoRepair" 1
SectionEnd
Section "Create Shortcuts" SEC05
# Create Start Menu shortcut
${If} $StartMenuShortcut == "1"
CreateDirectory "$SMPROGRAMS\ETS2LA"
CreateShortCut "$SMPROGRAMS\ETS2LA\ETS2LA.lnk" "$INSTDIR\start.bat" "" "$INSTDIR\system\favicon.ico"
${EndIf}
# Create Desktop shortcut
${If} $DesktopShortcut == "1"
CreateShortCut "$DESKTOP\ETS2LA.lnk" "$INSTDIR\start.bat" "" "$INSTDIR\system\favicon.ico"
${EndIf}
SectionEnd
Function LaunchETS2LA
Exec '"$INSTDIR\start.bat"'
FunctionEnd
Section "Copy Uninstaller" SEC06
WriteUninstaller "$INSTDIR\ETS2LA-Uninstaller.exe"
SectionEnd
# Uninstaller Section
Section "Uninstall"
# Remove installed files
Delete "$INSTDIR\start.bat"
Delete "$INSTDIR\app\*.*"
Delete "$INSTDIR\system\python\*.*"
Delete "$INSTDIR\system\git\*.*"
Delete "$INSTDIR\*.*"
# Remove directories
RMDir /r "$INSTDIR\app"
RMDir /r "$INSTDIR\system\python"
RMDir /r "$INSTDIR\system\git"
RMDir /r "$INSTDIR\system"
RMDir /r "$INSTDIR\executables"
RMDir /r "$INSTDIR"
# Remove uninstaller
Delete "$INSTDIR\ETS2LA-Uninstaller.exe"
# Remove registry entries
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ETS2LA"
# Remove Start Menu shortcut
Delete "$SMPROGRAMS\ETS2LA\ETS2LA.lnk"
RMDir "$SMPROGRAMS\ETS2LA"
# Remove Desktop shortcut
Delete "$DESKTOP\ETS2LA.lnk"
DetailPrint "Uninstallation complete."
SectionEnd
!include "languages.nsh"