winrtinstaller: Allow layers from SDK older than RT to be configured for use

Layers from SDK can be used by an RT if their major, minor, and patch numbers
are the same.

For example, if SDK 1.0.5.0 is already installed, and then RT 1.0.5.1 is
installed. During the RT installation, the layer registry entries will be set
to point to the layers in SDK 1.0.5.0.
diff --git a/windowsRuntimeInstaller/ConfigLayersAndVulkanDLL.ps1 b/windowsRuntimeInstaller/ConfigLayersAndVulkanDLL.ps1
index 4666f33..00c7ee6 100644
--- a/windowsRuntimeInstaller/ConfigLayersAndVulkanDLL.ps1
+++ b/windowsRuntimeInstaller/ConfigLayersAndVulkanDLL.ps1
@@ -49,6 +49,7 @@
 $vulkandll = "vulkan-"+$majorabi+".dll"

 $windrive  = $env:SYSTEMDRIVE

 $winfolder = $env:SYSTEMROOT

+$script:VulkanDllList=@()

 

 function notNumeric ($x) {

     try {

@@ -95,8 +96,9 @@
    # Push the current path on the stack and go to $dir

    Push-Location -Path $dir

 

-   # Create a list for all the DLLs in the folder

-   $VulkanDllList=@()

+   # Create a list for all the DLLs in the folder.

+   # First Initialize the list to empty

+   $script:VulkanDllList = @()

 

    # Find all DLL objects in this directory

    dir -name vulkan-$majorabi-*.dll |

@@ -171,21 +173,21 @@
        $prebuildno = $prebuildno.padleft(10,'0')

 

        # Add a new element to the $VulkanDllList array

-       $VulkanDllList+="$major=$minor=$patch=$buildno=$prerelease=$prebuildno= $_ @$majorOrig@$minorOrig@$patchOrig@$buildnoOrig@$prereleaseOrig@$prebuildnoOrig@"

+       $script:VulkanDllList+="$major=$minor=$patch=$buildno=$prerelease=$prebuildno= $_ @$majorOrig@$minorOrig@$patchOrig@$buildnoOrig@$prereleaseOrig@$prebuildnoOrig@"

    }

 

     # If $VulkanDllList contains at least one element, there's at least one vulkan*.dll file.

     # Copy the most recent vulkan*.dll (named in the last element of $VulkanDllList) to vulkan-$majorabi.dll.

 

-    if ($VulkanDllList.Length -gt 0) {

+    if ($script:VulkanDllList.Length -gt 0) {

 

         # Sort the list. The most recent vulkan-*.dll will be in the last element of the list.

-        [array]::sort($VulkanDllList)

+        [array]::sort($script:VulkanDllList)

 

         # Put the name of the most recent vulkan-*.dll in $mrVulkanDLL.

         # The most recent vulkanDLL is the second word in the last element of the

         # sorted $VulkanDllList. Copy it to $vulkandll.

-        $mrVulkanDll=$VulkanDllList[-1].Split(' ')[1]

+        $mrVulkanDll=$script:VulkanDllList[-1].Split(' ')[1]

         copy $mrVulkanDll $vulkandll

 

         # Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe.

@@ -195,12 +197,12 @@
         copy $mrVulkaninfo vulkaninfo.exe

 

         # Create the name used in the registry for the SDK associated with $mrVulkanDll.

-        $major=$VulkanDLLList[-1].Split('@')[1]

-        $minor=$VulkanDLLList[-1].Split('@')[2]

-        $patch=$VulkanDLLList[-1].Split('@')[3]

-        $buildno=$VulkanDLLList[-1].Split('@')[4]

-        $prerelease=$VulkanDLLList[-1].Split('@')[5]

-        $prebuildno=$VulkanDLLList[-1].Split('@')[6]

+        $major=$script:VulkanDllList[-1].Split('@')[1]

+        $minor=$script:VulkanDllList[-1].Split('@')[2]

+        $patch=$script:VulkanDllList[-1].Split('@')[3]

+        $buildno=$script:VulkanDllList[-1].Split('@')[4]

+        $prerelease=$script:VulkanDllList[-1].Split('@')[5]

+        $prebuildno=$script:VulkanDllList[-1].Split('@')[6]

 

         $sdktempname="VulkanSDK"+$major + "." + $minor + "." + $patch + "." + $buildno

         if ($prerelease -ne "") {

@@ -251,6 +253,42 @@
        }

    }

 

+

+# Search list of sdk install dirs for an sdk compatible with $script:sdkname.

+# We go backwards through VulkanDllList to generate SDK names, because we want the most recent SDK.

+if ($mrVulkanDllInstallDir -eq "") {

+    ForEach ($idx in ($script:VulkanDllList.Length-1)..0) {

+        $vulkanDllMajor=$script:VulkanDllList[$idx].Split('@')[1]

+        $vulkanDllMinor=$script:VulkanDllList[$idx].Split('@')[2]

+        $vulkanDllPatch=$script:VulkanDllList[$idx].Split('@')[3]

+        $vulkanDllBuildno=$script:VulkanDllList[$idx].Split('@')[4]

+        $vulkanDllPrerelease=$script:VulkanDllList[$idx].Split('@')[5]

+        $vulkanDllPrebuildno=$script:VulkanDllList[$idx].Split('@')[6]

+        $regEntry="VulkanSDK"+$vulkanDllMajor+"."+$vulkanDllMinor+"."+$vulkanDllPatch+"."+$vulkanDllBuildno

+        if ($vulkanDllPrerelease) {

+            $regEntry=$regEntry+"."+$vulkanDllPrerelease

+        }

+        if ($vulkanDllPrebuildno) {

+            $regEntry=$regEntry+"."+$vulkanDllPrebuildno

+        }

+        $rval=Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$regEntry -ErrorAction SilentlyContinue

+        $instDir=$rval

+        $instDir=$instDir -replace "\\Uninstall.exe.*",""

+        $instDir=$instDir -replace ".*=.",""

+        if ($rval) {

+            $rval=$rval -replace ".* DisplayVersion=",""

+            $rval=$rval -replace ";.*",""

+            $reMajor=$rval.Split('.')[0]

+            $reMinor=$rval.Split('.')[1]

+            $rePatch=$rval.Split('.')[2]

+            if ($reMajor+$reMinor+$rePatch -eq $vulkanDllMajor+$vulkanDllMinor+$vulkanDllPatch) {

+                $mrVulkanDllInstallDir=$instDir

+                break

+            }

+        }

+    }

+}

+

 # Add C:\Vulkan\SDK\0.9.3 to list of SDK install dirs.

 # We do this because there is in a bug in SDK 0.9.3 in which layer

 # reg entries were not removed on uninstall. So we'll try to clean up

diff --git a/windowsRuntimeInstaller/InstallerRT.nsi b/windowsRuntimeInstaller/InstallerRT.nsi
index aa7e04c..d35e146 100644
--- a/windowsRuntimeInstaller/InstallerRT.nsi
+++ b/windowsRuntimeInstaller/InstallerRT.nsi
@@ -534,53 +534,54 @@
         DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}${PRODUCTVERSION}"
     ${EndIf}
 
-    # Ref count is in $1. If it is zero, uninstall everything
+
+    # Install the ConfigLayersAndVulkanDLL.ps1 so we can run it.
+    # It will be deleted later when we remove the install directory.
+    File ConfigLayersAndVulkanDLL.ps1
+
+    # If running on a 64-bit OS machine
+    ${If} ${RunningX64}
+
+        # Delete vulkaninfo.exe in C:\Windows\System32 and C:\Windows\SysWOW64
+        Delete /REBOOTOK $WINDIR\SysWow64\vulkaninfo.exe
+        Delete /REBOOTOK "$WINDIR\SysWow64\vulkaninfo-$FileVersion.exe"
+        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>-<buildno>.dll
+        Delete /REBOOTOK $WINDIR\SysWow64\vulkan-${VERSION_ABI_MAJOR}.dll
+        Delete /REBOOTOK $WINDIR\SysWow64\vulkan-$FileVersion.dll
+        Delete /REBOOTOK $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll
+        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 "$IDir\ConfigLayersAndVulkanDLL.ps1" ${VERSION_ABI_MAJOR} 64'
+
+    # Else, running on a 32-bit OS machine
+    ${Else}
+
+        # 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>-<buildno>.dll
+        Delete /REBOOTOK $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll
+        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 "$IDir\ConfigLayersAndVulkanDLL.ps1" ${VERSION_ABI_MAJOR} 32'
+
+    ${EndIf}
+
+    # If Ref Count is zero, uninstall everything
     ${If} $IC <= 0
 
-        # Install the ConfigLayersAndVulkanDLL.ps1 so we can run it.
-        # It will be deleted later when we remove the install directory.
-        File ConfigLayersAndVulkanDLL.ps1
-
-        # If running on a 64-bit OS machine
-        ${If} ${RunningX64}
-
-            # Delete vulkaninfo.exe in C:\Windows\System32 and C:\Windows\SysWOW64
-            Delete /REBOOTOK $WINDIR\SysWow64\vulkaninfo.exe
-            Delete /REBOOTOK "$WINDIR\SysWow64\vulkaninfo-$FileVersion.exe"
-            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>-<buildno>.dll
-            Delete /REBOOTOK $WINDIR\SysWow64\vulkan-${VERSION_ABI_MAJOR}.dll
-            Delete /REBOOTOK $WINDIR\SysWow64\vulkan-$FileVersion.dll
-            Delete /REBOOTOK $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll
-            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 "$IDir\ConfigLayersAndVulkanDLL.ps1" ${VERSION_ABI_MAJOR} 64'
-
-        # Else, running on a 32-bit OS machine
-        ${Else}
-
-            # 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>-<buildno>.dll
-            Delete /REBOOTOK $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll
-            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 "$IDir\ConfigLayersAndVulkanDLL.ps1" ${VERSION_ABI_MAJOR} 32'
-
-        ${EndIf}
-
         # Delete vulkaninfo from start menu.
         SetShellVarContext all
         Delete "$SMPROGRAMS\Vulkan\vulkaninfo.lnk"