-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
d2-installer.nsi
570 lines (439 loc) · 17.3 KB
/
d2-installer.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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
; Release Manager:
;
; Preliminary instructions
; ------------------------
;
; Please use the special build of NSIS that supports large strings.
; Updating the PATH will often not work or work incorrectly with the
; regular build of NSIS.
;
; http://nsis.sourceforge.net/Special_Builds
;
;
; Instructions
; ------------
;
; Two defines must be set to use the installer:
; - EmbedD2Dir: The path to the directory tree recursively embedded in the
; generated installer.
; - Version2: The DMD version number.
;
; The easiest way is to use the /D command line options for makensis
; makensis /DEmbedD2Dir=<some path> /DVersion2=2.xxx
;
; The Extras that are downloaded should be updated to use the latest versions.
;--------------------------------------------------------
; Defines
;--------------------------------------------------------
; Required
; --------
; EmbedD2Dir. Can be specified here rather than on the makensis command line:
;!define EmbedD2Dir "<path to files to install>"
; Version2. Can be specified here rather than on the makensis command line:
;!define Version2 "2.0xx"
; Routinely Update
; ----------------
; Visual D
!define VersionVisualD "0.3.43"
; DMC
!define VersionDMC "857"
; D1
!define Version1 "1.076"
!define Version1ReleaseYear "2013" ; S3 file hosting includes the year in the URL so update this as needed
; Update Rarely Needed
; --------------------
; Files
!define VisualDFilename "VisualD-v${VersionVisualD}.exe"
!define DmcFilename "dmc-${VersionDMC}.exe"
!define Dmd1Filename "dmd-${Version1}.exe"
!define VS2013Filename "vs_community.exe"
; URLs
!define BaseURL "http://downloads.dlang.org"
!define BaseURLAlt "http://ftp.digitalmars.com"
!define VisualDBaseURL "https://github.com/dlang/visuald/releases/download"
!define VisualDUrl "${VisualDBaseURL}/v${VersionVisualD}/${VisualDFilename}"
!define DmcUrl "${BaseURL}/other/${DmcFilename}"
!define DmcAltUrl "${BaseURLAlt}/${DmcFilename}"
!define Dmd1Url "${BaseURL}/releases/${Version1ReleaseYear}/${Dmd1Filename}"
!define Dmd1AltUrl "${BaseURLAlt}/${Dmd1Filename}"
!define VS2013Url "http://go.microsoft.com/fwlink/?LinkId=517284"
; Publishing Details
!define DPublisher "Digital Mars"
!define DName "DMD"
!define ARP "Software\Microsoft\Windows\CurrentVersion\Uninstall\${DName}"
; Version2 Fallback
; The version will be pulled from the VERSION file in the dmd repository if
; not specified with /D to makensis or defined above. Change the path to match.
!define D2VersionPath "..\..\dmd\VERSION"
!ifndef Version2
!define /file Version2 ${D2VersionPath}
!endif
;--------------------------------------------------------
; Includes
;--------------------------------------------------------
!include "MUI.nsh"
!include "EnvVarUpdate.nsh"
!include "ReplaceInFile.nsh"
!include "FileFunc.nsh"
;------------------------------------------------------------
; Variables
;------------------------------------------------------------
Var I
Var J
Var K
Var InstanceCheck
Var VCVer
Var VCPath
Var WinSDKPath
Var UCRTPath
Var UCRTVersion
;--------------------------------------------------------
; General definitions
;--------------------------------------------------------
; Name of the installer
Name "D Programming Language"
; Name of the output file of the installer
!define InstallerFilename "dmd-${Version2}.exe"
OutFile ${InstallerFilename}
; Where the program will be installed
InstallDir "C:\D"
; Take the installation directory from the registry, if possible
InstallDirRegKey HKCU "Software\${DName}" "InstallationFolder"
; This is so no one can corrupt the installer
CRCCheck force
SetCompressor /SOLID lzma
;------------------------------------------------------------
; Macros definition
;------------------------------------------------------------
; Check if a dmd installer instance is already running
!macro OneInstanceOnly
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "digital_mars_d_compiler_installer") ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONSTOP "An instance of DMD installer is already running"
Abort
!macroend
!macro DownloadAndRun Filename Url AltUrl
inetc::get /CAPTION "Downloading ${Filename}..." /BANNER "" "${Url}" "$TEMP\${Filename}"
Pop $0
StrCmp $0 "OK" run
!if `${AltUrl}` != ""
inetc::get /CAPTION "Downloading ${Filename}..." /BANNER "" "${AltUrl}" "$TEMP\${Filename}"
Pop $0
StrCmp $0 "OK" run
!endif
; failed
MessageBox MB_OK|MB_ICONEXCLAMATION "Could not download ${Filename}$\r$\n$\r$\n${Url}"
Goto dandr_done
run:
DetailPrint "Running ${Filename}"
ExecWait "$TEMP\${Filename}"
Delete "$TEMP\${Filename}"
dandr_done:
!macroend
; Read SDK registry entry and check if kernel32.lib exists in the expected lib folder
!macro _DetectSDK REG_KEY VALUE LIBFOLDER
ClearErrors
ReadRegStr $0 HKLM "Software\Microsoft\${REG_KEY}" ${VALUE}
IfErrors +2 0
IfFileExists "$0${LIBFOLDER}\kernel32.lib" +2
SetErrors
!macroend
;--------------------------------------------------------
; Interface settings
;--------------------------------------------------------
; Confirmation when exiting the installer
!define MUI_ABORTWARNING
!define MUI_ICON "installer-icon.ico"
!define MUI_UNICON "uninstaller-icon.ico"
;--------------------------------------------------------
; Language selection dialog settings
;--------------------------------------------------------
; Remember the installation language
!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
!define MUI_LANGDLL_REGISTRY_KEY "Software\D"
!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
;--------------------------------------------------------
; Installer pages
;--------------------------------------------------------
!define MUI_WELCOMEFINISHPAGE_BITMAP "d2-installer-image.bmp"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------------------------------
; The languages
;--------------------------------------------------------
!insertmacro MUI_LANGUAGE "English"
; Reserve files needed by the installation
!insertmacro MUI_RESERVEFILE_LANGDLL
;--------------------------------------------------------
; Sections
;--------------------------------------------------------
SectionGroup /e "D2"
Section "-D2" Dmd2Files
; This section is mandatory
SectionIn RO
SetOutPath $INSTDIR
CreateDirectory "$INSTDIR"
; Embed the directory specified
File /r ${EmbedD2Dir}
; Create 32-bit command line batch file
FileOpen $0 "$INSTDIR\dmd2vars32.bat" w
FileWrite $0 "@echo.$\n"
FileWrite $0 "@echo Setting up 32-bit environment for using DMD 2 from %~dp0dmd2\windows\bin.$\n"
FileWrite $0 "@set PATH=%~dp0dmd2\windows\bin;%PATH%$\n"
FileClose $0
; Create 64-bit command line batch file
FileOpen $0 "$INSTDIR\dmd2vars64.bat" w
FileWrite $0 "@echo.$\n"
FileWrite $0 "@echo Setting up 64-bit environment for using DMD 2 from %~dp0dmd2\windows\bin.$\n"
FileWrite $0 "@echo.$\n"
FileWrite $0 "@echo dmd must still be called with -m64 in order to generate 64-bit code.$\n"
FileWrite $0 "@echo This command prompt adds the path of extra 64-bit DLLs so generated programs$\n"
FileWrite $0 "@echo which use the extra DLLs (notably libcurl) can be executed.$\n"
FileWrite $0 "@set PATH=%~dp0dmd2\windows\bin;%PATH%$\n"
FileWrite $0 "@set PATH=%~dp0dmd2\windows\bin64;%PATH%$\n"
FileClose $0
; Write installation dir in the registry
WriteRegStr HKLM "SOFTWARE\${DName}" "InstallationFolder" "$INSTDIR"
; Registry keys for dmd uninstaller
WriteRegStr HKLM "${ARP}" "DisplayName" "${DName}"
WriteRegStr HKLM "${ARP}" "DisplayVersion" "${Version2}"
WriteRegStr HKLM "${ARP}" "UninstallString" "$INSTDIR\uninstall.exe"
WriteRegStr HKLM "${ARP}" "DisplayIcon" "$INSTDIR\uninstall.exe"
WriteRegStr HKLM "${ARP}" "Publisher" "${DPublisher}"
WriteRegStr HKLM "${ARP}" "HelpLink" "http://dlang.org/"
WriteRegDWORD HKLM "${ARP}" "NoModify" 1
WriteRegDWORD HKLM "${ARP}" "NoRepair" 1
WriteUninstaller "uninstall.exe"
StrCmp $VCVer "" no_vc_detected write_vc_path
no_vc_detected:
MessageBox MB_OK "Could not detect Visual Studio (2008-2015 are supported). No 64-bit support."
goto finish_vc_path
write_vc_path:
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";VCINSTALLDIR=" "VCINSTALLDIR=$VCPath"
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";$VCVer " ""
finish_vc_path:
ClearErrors
StrCmp $WinSDKPath "" no_sdk_detected write_sdk_path
no_sdk_detected:
MessageBox MB_OK "Could not detect Windows SDK (6.0A-10.0 are supported). No 64-bit support."
goto finish_sdk_path
write_sdk_path:
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";WindowsSdkDir=" "WindowsSdkDir=$WinSDKPath"
finish_sdk_path:
ClearErrors
StrCmp $UCRTVersion "" no_ucrt_detected
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";UniversalCRTSdkDir=" "UniversalCRTSdkDir=$UCRTPath"
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";UCRTVersion=" "UCRTVersion=$UCRTVersion"
no_ucrt_detected:
ClearErrors
SectionEnd
Section "Add to PATH" AddD2ToPath
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\dmd2\windows\bin"
SectionEnd
Section "Start Menu" StartMenuShortcuts
CreateDirectory "$SMPROGRAMS\D"
CreateShortCut "$SMPROGRAMS\D\D2 HTML Documentation.lnk" "$INSTDIR\dmd2\html\d\index.html"
CreateShortCut "$SMPROGRAMS\D\D2 Documentation.lnk" "$INSTDIR\dmd2\windows\bin\d.chm"
CreateShortCut "$SMPROGRAMS\D\D2 32-bit Command Prompt.lnk" '%comspec%' '/k ""$INSTDIR\dmd2vars32.bat""' "" "" SW_SHOWNORMAL "" "Open D2 32-bit Command Prompt"
CreateShortCut "$SMPROGRAMS\D\D2 64-bit Command Prompt.lnk" '%comspec%' '/k ""$INSTDIR\dmd2vars64.bat""' "" "" SW_SHOWNORMAL "" "Open D2 64-bit Command Prompt"
SectionEnd
SectionGroupEnd
SectionGroup /e "Extras"
Section /o "Download Visual D" VisualDDownload
!insertmacro DownloadAndRun ${VisualDFilename} ${VisualDUrl} ""
SectionEnd
Section /o "Download DMC" DmcDownload
!insertmacro DownloadAndRun ${DmcFilename} ${DmcUrl} ${DmcAltUrl}
SectionEnd
Section /o "Download D1" Dmd1Download
!insertmacro DownloadAndRun ${Dmd1Filename} ${Dmd1Url} ${Dmd1AltUrl}
SectionEnd
SectionGroupEnd
;--------------------------------------------------------
; Helper functions
;--------------------------------------------------------
Function DetectVSAndSDK
ClearErrors
ReadRegStr $0 HKLM "Software\Microsoft\VisualStudio\14.0\Setup\VC" "ProductDir"
StrCpy $1 "VC2015"
IfErrors 0 done_vs
ClearErrors
ReadRegStr $0 HKLM "Software\Microsoft\VisualStudio\12.0\Setup\VC" "ProductDir"
StrCpy $1 "VC2013"
IfErrors 0 done_vs
ClearErrors
ReadRegStr $0 HKLM "Software\Microsoft\VisualStudio\11.0\Setup\VC" "ProductDir"
StrCpy $1 "VC2012"
IfErrors 0 done_vs
ClearErrors
ReadRegStr $0 HKLM "Software\Microsoft\VisualStudio\10.0\Setup\VC" "ProductDir"
StrCpy $1 "VC2010"
IfErrors 0 done_vs
ClearErrors
ReadRegStr $0 HKLM "Software\Microsoft\VisualStudio\9.0\Setup\VC" "ProductDir"
StrCpy $1 "VC2008"
IfErrors done done_vs
done_vs:
StrCpy $VCPath $0
StrCpy $VCVer $1
; detect ucrt
ReadRegStr $0 HKLM "Software\Microsoft\Windows Kits\Installed Roots" "KitsRoot10"
IfErrors done done_ucrt
done_ucrt:
StrCpy $UCRTPath $0
StrCpy $UCRTVersion ""
FindFirst $0 $1 $UCRTPath\Lib\*.*
loop_ff:
StrCmp $1 "" done_ff
StrCpy $UCRTVersion $1 ; hoping the directory is retrieved in ascending order (done by NTFS)
FindNext $0 $1
Goto loop_ff
done_ff:
FindClose $0
done:
!insertmacro _DetectSDK "Windows Kits\Installed Roots" "KitsRoot10" "Lib\$UCRTVersion\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Windows Kits\Installed Roots" "KitsRoot81" "Lib\winv6.3\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v8.1" "InstallationFolder" "Lib\winv6.3\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v8.1A" "InstallationFolder" "Lib\winv6.3\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Windows Kits\Installed Roots" "KitsRoot" "Lib\win8\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v8.0" "InstallationFolder" "Lib\win8\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v8.0A" "InstallationFolder" "Lib\win8\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v7.1A" "InstallationFolder" "Lib\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v7.0A" "InstallationFolder" "Lib\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v6.0A" "InstallationFolder" "Lib\x64"
IfErrors no_sdk done_sdk
done_sdk:
StrCpy $WinSDKPath $0
no_sdk:
FunctionEnd
;--------------------------------------------------------
; Installer functions
;--------------------------------------------------------
Function .onInit
; Check if a dmd installer instance is already running
!insertmacro OneInstanceOnly
; Force install without uninstall (useful if uninstall is broken)
${GetParameters} $R0
StrCmp $R0 "/f" done_uninst
; Remove previous dmd installation if any
; this section is for previous dmd installer only
ReadRegStr $R5 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\D" "UninstallString"
ReadRegStr $R6 HKLM "SOFTWARE\D" "Install_Dir"
StrCmp $R5 "" done_uninst_prev
MessageBox MB_OKCANCEL|MB_ICONQUESTION \
"A previous DMD is installed on your system$\n$\nPress 'OK' to replace by ${DName} ${Version2}" \
IDOK +2
Abort
ClearErrors
; Run uninstaller fron installed directory
ExecWait '$R5 /S _?=$R6' $K
; Exit if uninstaller return an error
IfErrors 0 +3
MessageBox MB_OK|MB_ICONSTOP \
"An error occurred when removing DMD$\n$\nRun '${InstallerFilename} /f' to force install ${DName} ${Version2}"
Abort
; Remove in background the remaining uninstaller program itself
Sleep 1000
Exec '$R5 /S'
; MessageBox MB_OK|MB_ICONINFORMATION "Previous DMD uninstalled"
done_uninst_prev:
; End of removing previous dmd installation section
; Remove if dmd is already installed
ReadRegStr $R0 HKLM "${ARP}" "UninstallString"
StrCmp $R0 "" done_uninst
ReadRegStr $I HKLM "${ARP}" "DisplayName"
ReadRegStr $J HKLM "${ARP}" "DisplayVersion"
MessageBox MB_OKCANCEL|MB_ICONQUESTION \
"$I v$J is installed on your system$\n$\nPress 'OK' to replace by ${DName} ${Version2}" \
IDOK uninst
Abort
uninst:
${GetParent} $R0 $INSTDIR
ClearErrors
; Run uninstaller from installed directory
ExecWait '$R0 /IC False _?=$INSTDIR' $K
; Exit if uninstaller return an error
IfErrors 0 +3
MessageBox MB_OK|MB_ICONSTOP \
"An error occurred when removing $I v$J$\n$\nRun '${InstallerFilename} /f' to force install ${DName} ${Version2}"
Abort
; Exit if uninstaller is cancelled by user
StrCmp $K 0 +2
Abort
; Remove in background the remaining uninstaller program itself
Exec '$R0 /IC False /S'
done_uninst:
Call DetectVSAndSDK
StrCmp $VCVer "" ask_vs
StrCmp $WinSDKPath "" ask_vs
Goto done_vs
ask_vs:
MessageBox MB_YESNO|MB_ICONQUESTION \
"For 64-bit support MSVC and the Windows SDK are needed but no compatible versions were found. Do you want to install VS2013?" \
IDYES install_vs IDNO done_vs
install_vs:
!insertmacro DownloadAndRun ${VS2013Filename} ${VS2013Url} ""
Call DetectVSAndSDK
done_vs:
FunctionEnd
; Contains descriptions of components and other stuff
!include d2-installer-descriptions.nsh
;--------------------------------------------------------
; Uninstaller
;--------------------------------------------------------
Section "Uninstall"
; Remove directories from PATH (for all users)
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\dmd2\windows\bin"
; Remove stuff from registry
DeleteRegKey HKLM "${ARP}"
DeleteRegKey HKLM "SOFTWARE\${DName}"
; Remove the uninstaller
Delete $INSTDIR\uninstall.exe
; Remove the generated batch files
Delete $INSTDIR\dmd2vars32.bat
Delete $INSTDIR\dmd2vars64.bat
; Remove shortcuts
Delete "$SMPROGRAMS\D\D2 HTML Documentation.lnk"
Delete "$SMPROGRAMS\D\D2 Documentation.lnk"
Delete "$SMPROGRAMS\D\D2 32-bit Command Prompt.lnk"
Delete "$SMPROGRAMS\D\D2 64-bit Command Prompt.lnk"
RMDir "$SMPROGRAMS\D"
${GetOptions} $CMDLINE "/S" $R0
IfErrors 0 rmdir
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"The uninstaller will now recursively delete ALL files and directories under '$INSTDIR\dmd2'. Continue?" \
/SD IDOK IDOK rmdir
Abort
rmdir:
; Remove used directories
RMDir /r "$INSTDIR\dmd2"
RMDir "$INSTDIR"
SectionEnd
;--------------------------------------------------------
; Uninstaller functions
;--------------------------------------------------------
Function un.onInit
; Check if a dmd installer instance is already running
; Do not check if "/IC False" argument is passed to uninstaller
${GetOptions} $CMDLINE "/IC" $InstanceCheck
${IfNot} "$InstanceCheck" == "False"
!insertmacro OneInstanceOnly
${EndIf}
FunctionEnd