aboutsummaryrefslogtreecommitdiff
path: root/windowsRuntimeInstaller/InstallerRT.nsi
blob: d6c024a524296917f01c5fad79ff7406059a2559 (plain)
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
# NSIS Script for creating the Windows Vulkan RT installer.
#
# Copyright (C) 2016 Valve Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# Author: David Pinedo <david@lunarg.com>
#


# Version information
# Set VERSION_PATCH to:
#    x.pre.y for prereleases
#    a single number for releases
!define PRODUCTNAME "VulkanRT"
!define VERSION_ABI_MAJOR "0"
!define VERSION_API_MAJOR "0"
!define VERSION_MINOR "10"
!define VERSION_PATCH "3.pre.1"
#!define VERSION_PATCH "1"
!define PRODUCTVERSION "${VERSION_API_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"

# Includes
!include LogicLib.nsh

# This number is determined by doing an install, and then from Windows Explorer,
# doing a "Properties" on the install directory. Add to this the size of the
# files installed to C:\Windows\System32. And then add a little bit more.
# The units are 1K bytes.
!define ESTIMATEDSIZE "340"

# Set the icon
!define ICOFILE "Vulkan.ico"
Icon ${ICOFILE}
UninstallIcon ${ICOFILE}
WindowIcon off

# Define name of installer
OutFile "VulkanRT-${PRODUCTVERSION}-Installer.exe"

# Define default installation directory
InstallDir "C:\Program Files (x86)\${PRODUCTNAME}\${PRODUCTVERSION}"

# Variable that holds version string used in file names
Var FileVersion


#############################################
# StrRep - string replace

!define StrRep "!insertmacro StrRep"
!macro StrRep output string old new
    Push `${string}`
    Push `${old}`
    Push `${new}`
    !ifdef __UNINSTALL__
        Call un.StrRep
    !else
        Call StrRep
    !endif
    Pop ${output}
!macroend

!macro Func_StrRep un
    Function ${un}StrRep
        Exch $R2 ;new
        Exch 1
        Exch $R1 ;old
        Exch 2
        Exch $R0 ;string
        Push $R3
        Push $R4
        Push $R5
        Push $R6
        Push $R7
        Push $R8
        Push $R9

        StrCpy $R3 0
        StrLen $R4 $R1
        StrLen $R6 $R0
        StrLen $R9 $R2
        loop:
            StrCpy $R5 $R0 $R4 $R3
            StrCmp $R5 $R1 found
            StrCmp $R3 $R6 done
            IntOp $R3 $R3 + 1 ;move offset by 1 to check the next character
            Goto loop
        found:
            StrCpy $R5 $R0 $R3
            IntOp $R8 $R3 + $R4
            StrCpy $R7 $R0 "" $R8
            StrCpy $R0 $R5$R2$R7
            StrLen $R6 $R0
            IntOp $R3 $R3 + $R9 ;move offset by length of the replacement string
            Goto loop
        done:

        Pop $R9
        Pop $R8
        Pop $R7
        Pop $R6
        Pop $R5
        Pop $R4
        Pop $R3
        Push $R0
        Push $R1
        Pop $R0
        Pop $R1
        Pop $R0
        Pop $R2
        Exch $R1
    FunctionEnd
!macroend
!insertmacro Func_StrRep ""
!insertmacro Func_StrRep "un."

#############################################
# x64 macros

!define IsWow64 `"" IsWow64 ""`
!macro _IsWow64 _a _b _t _f
  !insertmacro _LOGICLIB_TEMP
  System::Call kernel32::GetCurrentProcess()p.s
  System::Call kernel32::IsWow64Process(ps,*i0s)
  Pop $_LOGICLIB_TEMP
  !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
!macroend

!define RunningX64 `"" RunningX64 ""`
!macro _RunningX64 _a _b _t _f
  !if ${NSIS_PTR_SIZE} > 4
    !insertmacro LogicLib_JumpToBranch `${_t}` `${_f}`
  !else
    !insertmacro _IsWow64 `${_a}` `${_b}` `${_t}` `${_f}`
  !endif
!macroend

!define DisableX64FSRedirection "!insertmacro DisableX64FSRedirection"
!macro DisableX64FSRedirection
  System::Call kernel32::Wow64EnableWow64FsRedirection(i0)
!macroend

!define EnableX64FSRedirection "!insertmacro EnableX64FSRedirection"
!macro EnableX64FSRedirection
  System::Call kernel32::Wow64EnableWow64FsRedirection(i1)
!macroend


Function .onInit

  # Make sure we are on Win64.
  ${IfNot} ${RunningX64}
     MessageBox MB_OK "The Vulkan Run Time Libraries must be installed on a Windows 64-bit system."
     abort
  ${Endif}

FunctionEnd

# Need admin to write to C:\Windows\System32 and install dir
RequestExecutionLevel admin

AddBrandingImage left 150
Caption "${PRODUCTNAME} ${PRODUCTVERSION} Setup"
Name "${PRODUCTNAME} ${PRODUCTVERSION}"
Page custom brandimage "" ": Brand Image"
Page directory
Page instfiles
UninstallCaption "\${PRODUCTNAME} ${PRODUCTVERSION} Uninstall"
UninstallText "This wizard will uninstall ${PRODUCTNAME} ${PRODUCTVERSION} from your computer. Click Uninstall to start the uninstallation."
UninstPage custom un.brandimage "" ": Brand Image"
UninstPage uninstConfirm
UninstPage instFiles

# Start default section
Section

    ${DisableX64FSRedirection}
    SetRegView 64

    # Set up version number for file names
    ${StrRep} $0 ${VERSION_PATCH} "." "-"
    StrCpy $FileVersion ${VERSION_ABI_MAJOR}-${VERSION_API_MAJOR}-${VERSION_MINOR}-$0

    # Libraries
    SetOutPath $WINDIR\System32
    File /oname=vulkan-$FileVersion.dll ..\build\loader\Release\vulkan-${VERSION_ABI_MAJOR}.dll

    # vulkaninfo.exe
    SetOutPath $WINDIR\System32
    File /oname=vulkaninfo-$FileVersion.exe ..\build\demos\Release\vulkaninfo.exe
    SetOutPath "$INSTDIR"
    File ..\build\demos\Release\vulkaninfo.exe
    SetShellVarContext all
    CreateDirectory "$SMPROGRAMS\Vulkan ${PRODUCTVERSION}"
    CreateDirectory "$SMPROGRAMS\Vulkan ${PRODUCTVERSION}\Demos"
    CreateShortCut "$SMPROGRAMS\Vulkan ${PRODUCTVERSION}\Demos\vulkaninfo.lnk" "$INSTDIR\vulkaninfo.exe"

    SetOutPath "$INSTDIR"
    File ${ICOFILE}
    File LICENSE.rtf
    File ConfigLayersAndVulkanDLL.ps1

    # Run the ConfigLayersAndVulkanDLL.ps1 script to copy the most recent version of
    # vulkan-<abimajor>-*.dll to vulkan-<abimajor>.dll, and to set up layer registry
    # entries to use layers from the corresponding SDK
    nsExec::ExecToStack 'powershell -NoLogo -NonInteractive -WindowStyle Hidden -inputformat none -ExecutionPolicy RemoteSigned -File ConfigLayersAndVulkanDLL.ps1 ${VERSION_ABI_MAJOR}'

    # We are done using ConfigLayersAndVulkanDLL.ps1, delete it. It will be re-installed
    # by the uninstaller when it needs to be run again during uninstall.
    Delete ConfigLayersAndVulkanDLL.ps1

    # Reference count the number of times we have been installed.
    # The reference count is stored in the regisry value IC
    ReadRegDword $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "IC"
    IntOp $1 $1 + 1
    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "IC" $1

    # Create the uninstaller
    WriteUninstaller "$INSTDIR\Uninstall${PRODUCTNAME}.exe"

    # Modify registry for Programs and Features
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "DisplayName" "Vulkan Run Time Libraries ${PRODUCTVERSION}"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "UninstallString" "$INSTDIR\Uninstall${PRODUCTNAME}.exe"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "Publisher" "LunarG, Inc."
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "DisplayVersion" "${PRODUCTVERSION}"
    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "VersionABIMajor" ${VERSION_ABI_MAJOR}
    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "VersionAPIMajor" ${VERSION_API_MAJOR}
    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "VersionMinor" ${VERSION_MINOR}
    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "VersionMinor" ${VERSION_PATCH}
    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "EstimatedSize" ${ESTIMATEDSIZE}
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "DisplayIcon" "$\"$INSTDIR\${ICOFILE}$\""

    # Possibly install MSVC 2013 redistributables
    ReadRegDword $1 HKLM "SOFTWARE\Microsoft\DevDiv\vc\Servicing\12.0\RuntimeMinimum" "Install"
    IntCmp $1 1 RedistributablesInstalled InstallRedistributables InstallRedistributables
    InstallRedistributables:
       SetOutPath "$TEMP"
       File vcredist_x64.exe
       ExecWait '"$TEMP\vcredist_x64.exe"  /passive /norestart'
     RedistributablesInstalled:

SectionEnd

# Uninstaller section start
Section "uninstall"

    ${DisableX64FSRedirection}
    SetRegView 64

    SetOutPath "$INSTDIR"

    # Set up version number for file names
    ${StrRep} $0 ${VERSION_PATCH} "." "-"
    StrCpy $FileVersion ${VERSION_ABI_MAJOR}-${VERSION_API_MAJOR}-${VERSION_MINOR}-$0

    # Decrement the number of times we have been installed.
    ReadRegDword $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "IC"
    IntOp $1 $1 - 1
    WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}" "IC" $1

    # Ref count is in $1. If it is zero, uninstall.
    ${If} $1 <= 0

        # Install the ConfigLayersAndVulkanDLL.ps1 so we can run it.
        # It will be deleted later when we remove the install directory.
        File ConfigLayersAndVulkanDLL.ps1

        # Delete vulkaninfo.exe in C:\Windows\System32
        Delete /REBOOTOK $WINDIR\System32\vulkaninfo.exe
        Delete /REBOOTOK "$WINDIR\System32\vulkaninfo-$FileVersion.exe"

        # Delete vullkan dll files: vulkan-<majorabi>.dll and vulkan-<majorabi>-<major>-<minor>-<patch>.dll
        Delete /REBOOTOK $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll
        ${StrRep} $0 ${VERSION_PATCH} "." "-"
        Delete /REBOOTOK $WINDIR\System32\vulkan-$FileVersion.dll

        # Run the ConfigLayersAndVulkanDLL.ps1 script to:
        #   Copy the most recent version of vulkan-<abimajor>-*.dll to vulkan-<abimajor>.dll
        #   Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe
        #   Set up layer registry entries to use layers from the corresponding SDK
        nsExec::ExecToStack 'powershell -NoLogo -NonInteractive -WindowStyle Hidden -inputformat none -ExecutionPolicy RemoteSigned -File "$INSTDIR\ConfigLayersAndVulkanDLL.ps1" ${VERSION_ABI_MAJOR}'

        # Delete vulkaninfo from start menu.
        # Delete vulkan start menu if the vulkan start menu is empty
        SetShellVarContext all
        Delete "$SMPROGRAMS\Vulkan ${PRODUCTVERSION}\Demos\vulkaninfo.lnk"
        StrCpy $0 "$SMPROGRAMS\Vulkan ${PRODUCTVERSION}\Demos"
        Call un.DeleteDirIfEmpty
        StrCpy $0 "$SMPROGRAMS\Vulkan ${PRODUCTVERSION}"
        Call un.DeleteDirIfEmpty

        # Modify registry for Programs and Features
        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}"

        # Remove files in install dir
        Delete /REBOOTOK "$INSTDIR\LICENSE.rtf"
        Delete /REBOOTOK "$INSTDIR\UninstallVulkanRT.exe"
        Delete /REBOOTOK "$INSTDIR\Vulkan.ico"
        Delete /REBOOTOK "$INSTDIR\ConfigLayersAndVulkanDLL.ps1"
        Delete /REBOOTOK "$INSTDIR\vulkaninfo.exe"

        # Need to do a SetOutPath to something outside of INSTDIR,
        # or the uninstall will think INSTDIR is busy
        SetOutPath "$TEMP"

        # Remove install directories
        Rmdir /REBOOTOK "$INSTDIR"
        StrCpy $0 "C:\Program Files (x86)\${PRODUCTNAME}"
        Call un.DeleteDirIfEmpty

        # If any of the remove commands failed, request a reboot
        IfRebootFlag 0 noreboot
             MessageBox MB_YESNO "A reboot is required to finish the uninstall. Do you wish to reboot now?" IDNO noreboot
        Reboot
        noreboot:
    ${EndIf}

SectionEnd

Function brandimage
  SetOutPath "$TEMP"
  SetFileAttributes VulkanLogo.bmp temporary
  File VulkanLogo.bmp
  SetBrandingImage "$TEMP/VulkanLogo.bmp"
Functionend


Function un.brandimage
  SetOutPath "$TEMP"
  SetFileAttributes VulkanLogo.bmp temporary
  File VulkanLogo.bmp
  SetBrandingImage "$TEMP/VulkanLogo.bmp"
Functionend

Function un.DeleteDirIfEmpty
  FindFirst $R0 $R1 "$0\*.*"
  strcmp $R1 "." 0 NoDelete
   FindNext $R0 $R1
   strcmp $R1 ".." 0 NoDelete
    ClearErrors
    FindNext $R0 $R1
    IfErrors 0 NoDelete
     FindClose $R0
     Sleep 1000
     RMDir "$0"
  NoDelete:
   FindClose $R0
FunctionEnd