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