• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# NSIS Script for creating the Windows Vulkan RT installer.
2#
3# Copyright (c) 2015-2016 The Khronos Group Inc.
4# Copyright (c) 2015-2016 Valve Corporation
5# Copyright (c) 2015-2016 LunarG, Inc.
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and/or associated documentation files (the "Materials"), to
9# deal in the Materials without restriction, including without limitation the
10# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11# sell copies of the Materials, and to permit persons to whom the Materials are
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice(s) and this permission notice shall be included in
15# all copies or substantial portions of the Materials.
16#
17# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20#
21# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
24# USE OR OTHER DEALINGS IN THE MATERIALS.
25#
26# Author: David Pinedo <david@LunarG.com>
27# Author: Mark Young <mark@LunarG.com>
28#
29
30
31# Version information
32# Set VERSION_BUILDNO to:
33#    x.pre.z for prereleases
34#    x for releases
35#
36!define PRODUCTNAME "VulkanRT"
37!define VERSION_ABI_MAJOR "1"
38!define VERSION_API_MAJOR "1"
39!define VERSION_MINOR "0"
40!define VERSION_PATCH "1"
41!define VERSION_BUILDNO "0.pre.1"
42!define PUBLISHER "YourCompany, Inc."
43#!define VERSION_BUILDNO "0"
44!define PRODUCTVERSION "${VERSION_API_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILDNO}"
45
46# Includes
47!include LogicLib.nsh
48
49# This number is determined by doing an install, and then from Windows Explorer,
50# doing a "Properties" on the install directory. Add to this the size of the
51# files installed to C:\Windows\System32. And then add a little bit more.
52# The units are 1K bytes.
53!define ESTIMATEDSIZE "1700"
54
55# This is used for the error message if a problem occurs during install.
56!define errorMessage1 "Installation of ${PRODUCTNAME} failed!$\r$\n"
57!define errorMessage1un "Uninstall of ${PRODUCTNAME} failed!$\r$\n"
58!define errorMessage2 "Uninstalling any installed items and exiting.$\r$\n"
59
60# Set the icon
61!define ICOFILE "V.ico"
62Icon ${ICOFILE}
63UninstallIcon ${ICOFILE}
64WindowIcon off
65
66# If /DUNINSTALLER was specified, Create the uinstaller
67!ifdef UNINSTALLER
68  !echo "Creating RT uninstaller...."
69  OutFile "$%TEMP%\tempinstaller.exe"
70  SetCompress off
71!else
72  !echo "Creating RT installer...."
73
74  # Define name of installer
75  OutFile "VulkanRT-${PRODUCTVERSION}-Installer.exe"
76  SetCompressor /SOLID lzma
77
78!endif
79
80# Define default installation directory
81InstallDir "$PROGRAMFILES\${PRODUCTNAME}\${PRODUCTVERSION}"
82
83# Version string used in file names
84Var FileVersion
85
86# Directory RT was installed to.
87# The uninstaller can't just use $INSTDIR because it is set to the
88# directory the uninstaller exe file is located in.
89!ifdef UNINSTALLER
90Var IDir
91!endif
92
93# Install count
94Var IC
95
96# Error code from powershell script
97Var PsErr
98
99
100#############################################
101# StrRep - string replace
102
103!define StrRep "!insertmacro StrRep"
104!macro StrRep output string old new
105    Push `${string}`
106    Push `${old}`
107    Push `${new}`
108    !ifdef __UNINSTALL__
109        Call un.StrRep
110    !else
111        Call StrRep
112    !endif
113    Pop ${output}
114!macroend
115
116!macro Func_StrRep un
117    Function ${un}StrRep
118        Exch $R2 ;new
119        Exch 1
120        Exch $R1 ;old
121        Exch 2
122        Exch $R0 ;string
123        Push $R3
124        Push $R4
125        Push $R5
126        Push $R6
127        Push $R7
128        Push $R8
129        Push $R9
130
131        StrCpy $R3 0
132        StrLen $R4 $R1
133        StrLen $R6 $R0
134        StrLen $R9 $R2
135        loop:
136            StrCpy $R5 $R0 $R4 $R3
137            StrCmp $R5 $R1 found
138            StrCmp $R3 $R6 done
139            IntOp $R3 $R3 + 1 ;move offset by 1 to check the next character
140            Goto loop
141        found:
142            StrCpy $R5 $R0 $R3
143            IntOp $R8 $R3 + $R4
144            StrCpy $R7 $R0 "" $R8
145            StrCpy $R0 $R5$R2$R7
146            StrLen $R6 $R0
147            IntOp $R3 $R3 + $R9 ;move offset by length of the replacement string
148            Goto loop
149        done:
150
151        Pop $R9
152        Pop $R8
153        Pop $R7
154        Pop $R6
155        Pop $R5
156        Pop $R4
157        Pop $R3
158        Push $R0
159        Push $R1
160        Pop $R0
161        Pop $R1
162        Pop $R0
163        Pop $R2
164        Exch $R1
165    FunctionEnd
166!macroend
167!insertmacro Func_StrRep ""
168!insertmacro Func_StrRep "un."
169
170#############################################
171# x64 macros
172
173!define IsWow64 `"" IsWow64 ""`
174!macro _IsWow64 _a _b _t _f
175  !insertmacro _LOGICLIB_TEMP
176  System::Call kernel32::GetCurrentProcess()p.s
177  System::Call kernel32::IsWow64Process(ps,*i0s)
178  Pop $_LOGICLIB_TEMP
179  !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
180!macroend
181
182!define RunningX64 `"" RunningX64 ""`
183!macro _RunningX64 _a _b _t _f
184  !if ${NSIS_PTR_SIZE} > 4
185    !insertmacro LogicLib_JumpToBranch `${_t}` `${_f}`
186  !else
187    !insertmacro _IsWow64 `${_a}` `${_b}` `${_t}` `${_f}`
188  !endif
189!macroend
190
191!define DisableX64FSRedirection "!insertmacro DisableX64FSRedirection"
192!macro DisableX64FSRedirection
193  System::Call kernel32::Wow64EnableWow64FsRedirection(i0)
194!macroend
195
196!define EnableX64FSRedirection "!insertmacro EnableX64FSRedirection"
197!macro EnableX64FSRedirection
198  System::Call kernel32::Wow64EnableWow64FsRedirection(i1)
199!macroend
200
201
202# Need admin to write to C:\Windows\System32 and install dir
203RequestExecutionLevel admin
204
205Function .onInit
206
207!ifdef UNINSTALLER
208   ; Write out the uinstaller and quit
209   WriteUninstaller "$%TEMP%\Uninstall${PRODUCTNAME}.exe"
210   Quit
211!endif
212
213FunctionEnd
214
215AddBrandingImage left 150
216Caption "${PRODUCTNAME} ${PRODUCTVERSION} Setup"
217Name "${PRODUCTNAME} ${PRODUCTVERSION}"
218LIcenseData "VULKANRT_LICENSE.rtf"
219Page custom brandimage "" ": Brand Image"
220Page license
221Page directory
222Page instfiles
223UninstallCaption "\${PRODUCTNAME} ${PRODUCTVERSION} Uninstall"
224UninstallText "This wizard will uninstall ${PRODUCTNAME} ${PRODUCTVERSION} from your computer. Click Uninstall to start the uninstallation."
225UninstPage custom un.brandimage "" ": Brand Image"
226UninstPage uninstConfirm
227UninstPage instFiles
228
229# File Properties
230VIProductVersion "${PRODUCTVERSION}"
231VIAddVersionKey  "ProductName" "Vulkan Runtime"
232VIAddVersionKey  "FileVersion" "${PRODUCTVERSION}"
233VIAddVersionKey  "ProductVersion" "${PRODUCTVERSION}"
234VIAddVersionKey  "FileDescription" "Vulkan Runtime Installer"
235VIAddVersionKey  "LegalCopyright" ""
236
237# Start default section
238Section
239
240    # If running on a 64-bit OS machine, disable registry re-direct since we're running as a 32-bit executable.
241    ${If} ${RunningX64}
242
243        ${DisableX64FSRedirection}
244        SetRegView 64
245
246    ${Endif}
247
248    # Create our temp directory, with minimal permissions
249    SetOutPath "$TEMP\VulkanRT"
250    AccessControl::DisableFileInheritance $TEMP\VulkanRT
251    AccessControl::SetFileOwner $TEMP\VulkanRT "Administrators"
252    AccessControl::ClearOnFile  $TEMP\VulkanRT "Administrators" "FullAccess"
253    AccessControl::SetOnFile    $TEMP\VulkanRT "SYSTEM" "FullAccess"
254    AccessControl::GrantOnFile  $TEMP\VulkanRT "Everyone" "ListDirectory"
255    AccessControl::GrantOnFile  $TEMP\VulkanRT "Everyone" "GenericExecute"
256    AccessControl::GrantOnFile  $TEMP\VulkanRT "Everyone" "GenericRead"
257    AccessControl::GrantOnFile  $TEMP\VulkanRT "Everyone" "ReadAttributes"
258    StrCpy $1 10
259    Call CheckForError
260
261    # Check the registry to see if we are already installed
262    ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "InstallDir"
263
264    # If the registry entry isn't there, it will throw an error as well as return a blank value.  So, clear the errors.
265    ${If} ${Errors}
266
267        # Nothing else to do since there is no previous install
268        ClearErrors
269
270    ${Else}
271
272        # Use the previous install directory, so we don't have to keep tracking every possible runtime install.
273        strcmp $INSTDIR $0 notinstalled
274
275        ${If} $0 != ""
276            MessageBox MB_OK "The Windows Vulkan Runtime is already installed to $0. It will be re-installed to the same folder." /SD IDOK
277            Strcpy $INSTDIR $0
278        ${Endif}
279
280        notinstalled:
281
282    ${EndIf}
283
284    SetOutPath "$INSTDIR"
285    AccessControl::DisableFileInheritance $INSTDIR
286    AccessControl::SetFileOwner $INSTDIR "Administrators"
287    AccessControl::ClearOnFile  $INSTDIR "Administrators" "FullAccess"
288    AccessControl::SetOnFile    $INSTDIR "SYSTEM" "FullAccess"
289    AccessControl::GrantOnFile  $INSTDIR "Everyone" "ListDirectory"
290    AccessControl::GrantOnFile  $INSTDIR "Everyone" "GenericExecute"
291    AccessControl::GrantOnFile  $INSTDIR "Everyone" "GenericRead"
292    AccessControl::GrantOnFile  $INSTDIR "Everyone" "ReadAttributes"
293    File ${ICOFILE}
294    File VULKANRT_LICENSE.RTF
295    File LICENSE.txt
296    File ConfigLayersAndVulkanDLL.ps1
297    StrCpy $1 15
298    Call CheckForError
299
300    # Add the signed uninstaller
301    !ifndef UNINSTALLER
302        SetOutPath $INSTDIR
303        File "Uninstall${PRODUCTNAME}.exe"
304    !endif
305
306    StrCpy $1 20
307    Call CheckForError
308
309    # Reference count the number of times we have been installed.
310    # The reference count is stored in the registry value InstallCount
311    ReadRegDword $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "InstallCount"
312    IntOp $1 $1 + 1
313    StrCpy $IC $1
314
315    # We need to create a new folder for each install. Since we are using counted installs,
316    # an uninstall when the count is greater than one would result in the install
317    # count being decremented and nothing being removed. But Windows Add/Remove Programs
318    # generates a warning Window if the install dir for a package that is removed is not
319    # deleted. So we create a unique folder for each counted install.
320    # We fudge it a little and only create one folder, and rename it after each
321    # install/uninstall.
322
323    # Create the install instance folder. We rename the install instance folder if it already exists.
324    # Then copy the uninstaller to it.
325    ${If} $IC > 2
326        IntOp $1 $IC - 1
327        Rename "$INSTDIR\Instance_$1" "$INSTDIR\Instance_$IC"
328        CopyFiles /SILENT "$INSTDIR\Uninstall${PRODUCTNAME}.exe" "$INSTDIR\Instance_$IC"
329    ${ElseIf} $IC = 2
330        CreateDirectory "$INSTDIR\Instance_$IC"
331        CopyFiles /SILENT "$INSTDIR\Uninstall${PRODUCTNAME}.exe" "$INSTDIR\Instance_$IC"
332    ${EndIf}
333
334
335    # If the registry entry isn't there, it will throw an error as well as return a blank value.  So, clear the errors.
336    ${If} ${Errors}
337        ClearErrors
338    ${EndIf}
339
340    # Modify registry for Programs and Features
341    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "DisplayName" "Vulkan Run Time Libraries ${PRODUCTVERSION}"
342    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "UninstallString" "$INSTDIR\Uninstall${PRODUCTNAME}.exe"
343    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "Publisher" "${PUBLISHER}"
344    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "DisplayVersion" "${PRODUCTVERSION}"
345    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "EstimatedSize" ${ESTIMATEDSIZE}
346    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "DisplayIcon" "$\"$INSTDIR\${ICOFILE}$\""
347    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "InstallDir" "$INSTDIR"
348    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "InstallCount" $IC
349
350    ${If} $IC > 1
351        WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "DisplayName" "Vulkan Run Time Libraries ${PRODUCTVERSION}"
352        WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "UninstallString" "$INSTDIR\Instance_$IC\Uninstall${PRODUCTNAME}.exe"
353        WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "Publisher" "${PUBLISHER}"
354        WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "DisplayVersion" "${PRODUCTVERSION}"
355        WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "EstimatedSize" ${ESTIMATEDSIZE}
356        WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "DisplayIcon" "$\"$INSTDIR\${ICOFILE}$\""
357        WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "InstallDir" "$INSTDIR\Instance_$IC"
358        WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "InstallCount" $IC
359    ${EndIf}
360
361    # Set SystemComponent to 1 for those instances that are not to be visible to Add/Remove Programs.
362    # Set SystemComponent to 0 for the instance that is to be visible to Add/Remove Programs.
363    ${If} $IC > 2
364        IntOp $1 $IC - 1
365        WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "SystemComponent" 0
366        WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$1" "SystemComponent" 1
367    ${ElseIf} $IC = 2
368        WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "SystemComponent" 0
369        WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "SystemComponent" 1
370    ${Else}
371        WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "SystemComponent" 0
372    ${EndIf}
373
374    StrCpy $1 25
375    Call CheckForError
376
377    # Set up version number for file names
378    ${StrRep} $0 ${VERSION_BUILDNO} "." "-"
379    StrCpy $FileVersion ${VERSION_ABI_MAJOR}-${VERSION_API_MAJOR}-${VERSION_MINOR}-${VERSION_PATCH}-$0
380
381    # Remove vulkaninfo from Start Menu
382    SetShellVarContext all
383    Delete "$SMPROGRAMS\Vulkan\vulkaninfo32.lnk"
384    Delete "$SMPROGRAMS\Vulkan\vulkaninfo.lnk"
385    ClearErrors
386
387    # Create Vulkan in the Start Menu
388    CreateDirectory "$SMPROGRAMS\Vulkan"
389    ClearErrors
390
391    # If running on a 64-bit OS machine
392    ${If} ${RunningX64}
393
394        # 32-bit DLLs/EXEs destined for SysWOW64
395        ##########################################
396        SetOutPath $WINDIR\SysWow64
397        File /oname=vulkan-$FileVersion.dll ..\build32\loader\Release\vulkan-${VERSION_ABI_MAJOR}.dll
398        File /oname=vulkaninfo-$FileVersion.exe ..\build32\demos\Release\vulkaninfo.exe
399        StrCpy $1 30
400        Call CheckForError
401
402        # 64-bit DLLs/EXEs
403        ##########################################
404        SetOutPath $WINDIR\System32
405        File /oname=vulkan-$FileVersion.dll ..\build\loader\Release\vulkan-${VERSION_ABI_MAJOR}.dll
406        StrCpy $1 35
407        Call CheckForError
408
409        # vulkaninfo.exe
410        File /oname=vulkaninfo-$FileVersion.exe ..\build\demos\Release\vulkaninfo.exe
411        SetOutPath "$INSTDIR"
412        File ..\build\demos\Release\vulkaninfo.exe
413        File /oname=vulkaninfo32.exe ..\build32\demos\Release\vulkaninfo.exe
414        StrCpy $1 40
415        Call CheckForError
416
417        # Run the ConfigLayersAndVulkanDLL.ps1 script to copy the most recent version of
418        # vulkan-<abimajor>-*.dll to vulkan-<abimajor>.dll, and to set up layer registry
419        # entries to use layers from the corresponding SDK
420        nsExec::ExecToStack 'powershell -NoLogo -NonInteractive -WindowStyle Hidden -inputformat none -ExecutionPolicy RemoteSigned -File ConfigLayersAndVulkanDLL.ps1 ${VERSION_ABI_MAJOR} 64'
421        pop $PsErr
422        ${If} $PsErr != 0
423            SetErrors
424        ${EndIf}
425        StrCpy $1 45
426        Call CheckForError
427
428    # Else, running on a 32-bit OS machine
429    ${Else}
430
431        # 32-bit DLLs/EXEs destined for SysWOW64
432        ##########################################
433        SetOutPath $WINDIR\System32
434        File /oname=vulkan-$FileVersion.dll ..\build32\loader\Release\vulkan-${VERSION_ABI_MAJOR}.dll
435        StrCpy $1 50
436        Call CheckForError
437
438        # vulkaninfo.exe
439        File /oname=vulkaninfo-$FileVersion.exe ..\build32\demos\Release\vulkaninfo.exe
440        SetOutPath "$INSTDIR"
441        File ..\build32\demos\Release\vulkaninfo.exe
442        StrCpy $1 55
443        Call CheckForError
444
445        # Run the ConfigLayersAndVulkanDLL.ps1 script to copy the most recent version of
446        # vulkan-<abimajor>-*.dll to vulkan-<abimajor>.dll, and to set up layer registry
447        # entries to use layers from the corresponding SDK
448        nsExec::ExecToStack 'powershell -NoLogo -NonInteractive -WindowStyle Hidden -inputformat none -ExecutionPolicy RemoteSigned -File ConfigLayersAndVulkanDLL.ps1 ${VERSION_ABI_MAJOR} 32'
449        pop $PsErr
450        ${If} $PsErr != 0
451            SetErrors
452        ${EndIf}
453        StrCpy $1 60
454        Call CheckForError
455
456    ${Endif}
457
458    # We are done using ConfigLayersAndVulkanDLL.ps1, delete it. It will be re-installed
459    # by the uninstaller when it needs to be run again during uninstall.
460    Delete ConfigLayersAndVulkanDLL.ps1
461
462    # Add vulkaninfo to Start Menu
463    SetShellVarContext all
464    IfFileExists $WINDIR\System32\vulkaninfo.exe 0 +2
465        CreateShortCut "$SMPROGRAMS\Vulkan\vulkaninfo.lnk" "$WINDIR\System32\vulkaninfo.exe"
466    IfFileExists $WINDIR\SysWow64\vulkaninfo.exe 0 +2
467        CreateShortCut "$SMPROGRAMS\Vulkan\vulkaninfo32.lnk" "$WINDIR\SysWow64\vulkaninfo.exe"
468
469    # Possibly install MSVC 2013 redistributables
470    ClearErrors
471    ${If} ${RunningX64}
472        ReadRegDword $1 HKLM "SOFTWARE\WOW6432Node\Microsoft\DevDiv\vc\Servicing\12.0\RuntimeMinimum" "Install"
473        ${If} ${Errors}
474           StrCpy $1 0
475           ClearErrors
476        ${Endif}
477    ${Else}
478       StrCpy $1 1
479    ${Endif}
480    ReadRegDword $2 HKLM "SOFTWARE\Microsoft\DevDiv\vc\Servicing\12.0\RuntimeMinimum" "Install"
481    ${If} ${Errors}
482       StrCpy $2 0
483       ClearErrors
484    ${Endif}
485    IntOp $3 $1 + $2
486    ${If} $3 <= 1
487        # If either x86 or x64 redistributables are not present, install redistributables.
488        # We install both resdistributables because we have found that the x86 redist
489        # will uninstall the x64 redist if the x64 redistrib is an old version. Amazing, isn't it?
490        SetOutPath "$TEMP\VulkanRT"
491        ${If} ${RunningX64}
492            File vcredist_x64.exe
493            ExecWait '"$TEMP\VulkanRT\vcredist_x64.exe"  /quiet /norestart'
494        ${Endif}
495        File vcredist_x86.exe
496        ExecWait '"$TEMP\VulkanRT\vcredist_x86.exe"  /quiet /norestart'
497    ${Endif}
498    StrCpy $1 65
499    Call CheckForError
500
501SectionEnd
502
503# Uninstaller section start
504!ifdef UNINSTALLER
505Section "uninstall"
506
507    # If running on a 64-bit OS machine, disable registry re-direct since we're running as a 32-bit executable.
508    ${If} ${RunningX64}
509
510        ${DisableX64FSRedirection}
511        SetRegView 64
512
513    ${Endif}
514
515    # Look up the install dir and remove files from that directory.
516    # We do this so that the uninstaller can be run from any directory.
517    ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "InstallDir"
518    StrCpy $IDir $0
519
520    StrCpy $1 70
521    Call un.CheckForError
522
523    SetOutPath "$IDir"
524
525    # Set up version number for file names
526    ${StrRep} $0 ${VERSION_BUILDNO} "." "-"
527    StrCpy $FileVersion ${VERSION_ABI_MAJOR}-${VERSION_API_MAJOR}-${VERSION_MINOR}-${VERSION_PATCH}-$0
528
529    # Decrement the number of times we have been installed.
530    ReadRegDword $IC HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "InstallCount"
531    IntOp $1 $IC - 1
532    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "InstallCount" $1
533
534    # Rename the install dir for this instance if is not the last uninstall
535    ${If} $IC > 2
536        IntOp $1 $IC - 1
537        Rename "$IDir\Instance_$IC" "$IDir\Instance_$1"
538    ${ElseIf} $IC = 2
539        Delete /REBOOTOK "$IDir\Instance_$IC\Uninstall${PRODUCTNAME}.exe"
540        Rmdir /REBOOTOK "$IDir\Instance_$IC"
541    ${Endif}
542
543    # Modify registry for Programs and Features
544
545    ${If} $IC > 1
546        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC"
547    ${EndIf}
548    ${If} $IC > 2
549        IntOp $IC $IC - 1
550        WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}-$IC" "SystemComponent" 0
551    ${ElseIf} $IC = 2
552        WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "SystemComponent" 0
553    ${Else}
554        # Last uninstall
555        IntOp $IC $IC - 1
556        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}"
557    ${EndIf}
558
559
560    # Install the ConfigLayersAndVulkanDLL.ps1 so we can run it.
561    # It will be deleted later when we remove the install directory.
562    File ConfigLayersAndVulkanDLL.ps1
563
564    # If running on a 64-bit OS machine
565    ${If} ${RunningX64}
566
567        # Delete vulkaninfo.exe in C:\Windows\System32 and C:\Windows\SysWOW64
568        Delete /REBOOTOK $WINDIR\SysWow64\vulkaninfo.exe
569        Delete /REBOOTOK "$WINDIR\SysWow64\vulkaninfo-$FileVersion.exe"
570        Delete /REBOOTOK $WINDIR\System32\vulkaninfo.exe
571        Delete /REBOOTOK "$WINDIR\System32\vulkaninfo-$FileVersion.exe"
572
573        # Delete vullkan dll files: vulkan-<majorabi>.dll and vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>.dll
574        Delete /REBOOTOK $WINDIR\SysWow64\vulkan-${VERSION_ABI_MAJOR}.dll
575        Delete /REBOOTOK $WINDIR\SysWow64\vulkan-$FileVersion.dll
576        Delete /REBOOTOK $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll
577        Delete /REBOOTOK $WINDIR\System32\vulkan-$FileVersion.dll
578
579        # Run the ConfigLayersAndVulkanDLL.ps1 script to:
580        #   Copy the most recent version of vulkan-<abimajor>-*.dll to vulkan-<abimajor>.dll
581        #   Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe
582        #   Set up layer registry entries to use layers from the corresponding SDK
583        nsExec::ExecToStack 'powershell -NoLogo -NonInteractive -WindowStyle Hidden -inputformat none -ExecutionPolicy RemoteSigned -File "$IDir\ConfigLayersAndVulkanDLL.ps1" ${VERSION_ABI_MAJOR} 64'
584
585    # Else, running on a 32-bit OS machine
586    ${Else}
587
588        # Delete vulkaninfo.exe in C:\Windows\System32
589        Delete /REBOOTOK $WINDIR\System32\vulkaninfo.exe
590        Delete /REBOOTOK "$WINDIR\System32\vulkaninfo-$FileVersion.exe"
591
592        # Delete vullkan dll files: vulkan-<majorabi>.dll and vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>.dll
593        Delete /REBOOTOK $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll
594        Delete /REBOOTOK $WINDIR\System32\vulkan-$FileVersion.dll
595
596        # Run the ConfigLayersAndVulkanDLL.ps1 script to:
597        #   Copy the most recent version of vulkan-<abimajor>-*.dll to vulkan-<abimajor>.dll
598        #   Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe
599        #   Set up layer registry entries to use layers from the corresponding SDK
600        nsExec::ExecToStack 'powershell -NoLogo -NonInteractive -WindowStyle Hidden -inputformat none -ExecutionPolicy RemoteSigned -File "$IDir\ConfigLayersAndVulkanDLL.ps1" ${VERSION_ABI_MAJOR} 32'
601
602    ${EndIf}
603
604    # If Ref Count is zero, uninstall everything
605    ${If} $IC <= 0
606
607        # Delete vulkaninfo from start menu.
608        SetShellVarContext all
609        Delete "$SMPROGRAMS\Vulkan\vulkaninfo.lnk"
610
611        # If running on a 64-bit OS machine
612        ${If} ${RunningX64}
613            Delete "$SMPROGRAMS\Vulkan\vulkaninfo32.lnk"
614        ${EndIf}
615
616        # Possibly add vulkaninfo to Start Menu
617        SetShellVarContext all
618        IfFileExists $WINDIR\System32\vulkaninfo.exe 0 +2
619            CreateShortCut "$SMPROGRAMS\Vulkan\vulkaninfo.lnk" "$WINDIR\System32\vulkaninfo.exe"
620        IfFileExists $WINDIR\SysWow64\vulkaninfo.exe 0 +2
621            CreateShortCut "$SMPROGRAMS\Vulkan\vulkaninfo32.lnk" "$WINDIR\SysWow64\vulkaninfo.exe"
622
623        # Possibly delete vulkan Start Menu
624        StrCpy $0 "$SMPROGRAMS\Vulkan"
625        Call un.DeleteDirIfEmpty
626        ClearErrors
627
628        # Remove files in install dir
629        Delete /REBOOTOK "$IDir\VULKANRT_LICENSE.rtf"
630        Delete /REBOOTOK "$IDir\LICENSE.txt"
631        Delete /REBOOTOK "$IDir\Uninstall${PRODUCTNAME}.exe"
632        Delete /REBOOTOK "$IDir\V.ico"
633        Delete /REBOOTOK "$IDir\ConfigLayersAndVulkanDLL.ps1"
634        Delete /REBOOTOK "$IDir\vulkaninfo.exe"
635
636        # If running on a 64-bit OS machine
637        ${If} ${RunningX64}
638            Delete /REBOOTOK "$IDir\vulkaninfo32.exe"
639        ${EndIf}
640
641        StrCpy $1 75
642        Call un.CheckForError
643
644        # Need to do a SetOutPath to something outside of install dir,
645        # or the uninstall will think install dir is busy
646        SetOutPath "$TEMP"
647
648        # Remove install directories
649        StrCpy $0 "$IDir"
650        Call un.DeleteDirIfEmpty
651        StrCpy $0 "$PROGRAMFILES\${PRODUCTNAME}"
652        Call un.DeleteDirIfEmpty
653        ClearErrors
654
655        # If any of the remove commands failed, request a reboot
656        IfRebootFlag 0 noreboot
657            MessageBox MB_YESNO "A reboot is required to finish the uninstall. Do you wish to reboot now?" /SD IDNO IDNO returnerror
658            Reboot
659
660            returnerror:
661
662            # Set an error message to output because we should reboot but didn't (whether because silent uninstall or user choice)
663            SetErrorLevel 3 # ERROR_TOO_MANY_OPEN_FILES
664
665        noreboot:
666
667    ${Endif}
668
669    StrCpy $1 80
670    Call un.CheckForError
671
672    # Remove temp dir
673    SetOutPath "$TEMP"
674    RmDir /R "$TEMP\VulkanRT"
675
676SectionEnd
677!endif
678
679Function brandimage
680  SetOutPath "$TEMP"
681  SetFileAttributes V.bmp temporary
682  File V.bmp
683  SetBrandingImage "$TEMP/V.bmp"
684Functionend
685
686
687Function un.brandimage
688  SetOutPath "$TEMP"
689  SetFileAttributes V.bmp temporary
690  File V.bmp
691  SetBrandingImage "$TEMP/V.bmp"
692Functionend
693
694Function un.DeleteDirIfEmpty
695  FindFirst $R0 $R1 "$0\*.*"
696  strcmp $R1 "." 0 NoDelete
697   FindNext $R0 $R1
698   strcmp $R1 ".." 0 NoDelete
699    ClearErrors
700    FindNext $R0 $R1
701    IfErrors 0 NoDelete
702     FindClose $R0
703     Sleep 1000
704     RMDir "$0"
705  NoDelete:
706   FindClose $R0
707FunctionEnd
708
709# Check for errors during install.  If we hit an error, stop, uninstall what we've put in so far, and quit.
710# NOTE: We return a non-zero error code as well.
711Function CheckForError
712    ${If} ${Errors}
713        # IHV's using this install may want no message box.
714        MessageBox MB_OK|MB_ICONSTOP "${errorMessage1}${errorMessage2}Errorcode: $1$\r$\n" /SD IDOK
715
716        # Copy the uninstaller to a temp folder of our own creation so we can completely
717        # delete the old contents.
718        SetOutPath "$TEMP\VulkanRT"
719        CopyFiles "$INSTDIR\Uninstall${PRODUCTNAME}.exe" "$TEMP\VulkanRT"
720
721        # No uninstall using the version in the temporary folder.
722        ExecWait '"$TEMP\VulkanRT\Uninstall${PRODUCTNAME}.exe" /S _?=$INSTDIR'
723
724        # Delete the copy of the uninstaller we ran
725        Delete /REBOOTOK "$TEMP\VulkanRT\Uninstall${PRODUCTNAME}.exe"
726        RmDir /R /REBOOTOK "$TEMP\VulkanRT"
727
728        # Set an error message to output
729        SetErrorLevel $1
730
731        Quit
732    ${EndIf}
733FunctionEnd
734
735# Check for errors during uninstall.  If we hit an error, don't attempt
736# to do anything. Just set a non-zero return code and quit.
737Function un.CheckForError
738    ${If} ${Errors}
739        # IHV's using this install may want no message box.
740        MessageBox MB_OK|MB_ICONSTOP "${errorMessage1un}${errorMessage2}Errorcode: $1$\r$\n" /SD IDOK
741
742        # Set an error message to output
743        SetErrorLevel $1
744
745        Quit
746    ${EndIf}
747FunctionEnd
748