From 6e35ed30e90638c12b6172ded63911900bdf0272 Mon Sep 17 00:00:00 2001 From: David Pinedo Date: Thu, 9 Jun 2016 16:12:44 -0600 Subject: [PATCH] winrt: configure loader even if ps script fails --- .../ConfigLayersAndVulkanDLL.ps1 | 2 +- windowsRuntimeInstaller/InstallerRT.nsi | 60 ++++++++++++++++------ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/windowsRuntimeInstaller/ConfigLayersAndVulkanDLL.ps1 b/windowsRuntimeInstaller/ConfigLayersAndVulkanDLL.ps1 index 0936853..341df5f 100644 --- a/windowsRuntimeInstaller/ConfigLayersAndVulkanDLL.ps1 +++ b/windowsRuntimeInstaller/ConfigLayersAndVulkanDLL.ps1 @@ -29,7 +29,7 @@ # - Set the layer registry entries to point to the layer json files # in the Vulkan SDK associated with the most recent vulkan*dll. # -# This script takes the following parameters: +# This script can be called with the following two parameters: # $majorabi : a single string number specifying the major abi version. # $ossize : an integer indicating if the target is a 64 (64) or 32 (32) bit OS. # diff --git a/windowsRuntimeInstaller/InstallerRT.nsi b/windowsRuntimeInstaller/InstallerRT.nsi index 1286542..5d8b3f1 100644 --- a/windowsRuntimeInstaller/InstallerRT.nsi +++ b/windowsRuntimeInstaller/InstallerRT.nsi @@ -230,36 +230,45 @@ VIAddVersionKey "LegalCopyright" "" # Function to run ConfigLayersAndVulkanDll ps script. -# We define it as a macro so we can create an install and uninstall version. # Return value is in $0 - 0 is success, all else is failure. !macro ConfigLayersAndVulkanDLL un Function ${un}ConfigLayersAndVulkanDLL + ${If} ${RunningX64} Strcpy $1 64 ${Else} Strcpy $1 32 ${Endif} + + # Create the script, the first two lines are the majorabi and ossize. nsExec::ExecToStack 'cmd /k echo $$majorabi=${VERSION_ABI_MAJOR} >"$TEMP\VulkanRT\VulkanRT.ps1"' nsExec::ExecToStack 'cmd /k echo $$ossize=$1 >>"$TEMP\VulkanRT\VulkanRT.ps1"' nsExec::ExecToStack 'cmd /k type ConfigLayersAndVulkanDLL.ps1 >>"$TEMP\VulkanRT\VulkanRT.ps1"' + + # Exectute the script by piping it to powershell.exe. This gets around possible OS + # security restrictions on running powershell scripts. nsExec::ExecToStack 'cmd /k type "$TEMP\VulkanRT\VulkanRT.ps1" | powershell -NoProfile -NoLogo -NonInteractive -WindowStyle Hidden -inputformat none -Command -' Rename "$TEMP\ConfigLayersAndVulkanDLL.log" "$TEMP\VulkanRT\ConfigLayersAndVulkanDLL1.${un}log" pop $0 + + # If it failed, try again, with a full path to powershell.exe ${If} $0 != 0 nsExec::ExecToStack 'cmd /k type "$TEMP\VulkanRT\VulkanRT.ps1" | "$WINDIR\System32\WindowsPowerShell\v1.0\powershell" -NoProfile -NoLogo -NonInteractive -WindowStyle Hidden -inputformat none -Command -' pop $0 Rename "$TEMP\ConfigLayersAndVulkanDLL.log" "$TEMP\VulkanRT\ConfigLayersAndVulkanDLL2.${un}log" ${Endif} - ${If} $0 = 0 - # Read the return value of the script and put it in $0, stripping trailing newline - FileOpen $1 "$TEMP\ConfigLayersAndVulkanDLL.stat" r - FileRead $1 $2 - FileClose $1 - ${StrRep} $3 $2 "$\n" "" - ${StrRep} $0 $3 "$\r" "" - ${Endif} + + # Read the return value of the script and put it in $0, stripping trailing newline + FileOpen $1 "$TEMP\ConfigLayersAndVulkanDLL.stat" r + FileRead $1 $2 + FileClose $1 + ${StrRep} $3 $2 "$\n" "" + ${StrRep} $0 $3 "$\r" "" + + # Cleanup Delete "$TEMP\ConfigLayersAndVulkanDLL.stat" Delete "$TEMP\VulkanRT\VulkanRT.ps1" + FunctionEnd !macroend !insertmacro ConfigLayersAndVulkanDLL "" @@ -267,7 +276,6 @@ FunctionEnd # Function to run diagnostics if ConfigLayersAndVulkanDll ps script failed. -# We define it as a macro so we can create an install and uninstall version. # On entry $0, contains the return value from ConfigLayersAndVulkanDll.ps1. It shouldn't be changed. !macro DiagConfigLayersAndVulkanDLL un Function ${un}DiagConfigLayersAndVulkanDLL @@ -493,11 +501,24 @@ Section ${If} $0 != 0 SetOutPath "$INSTDIR" Call DiagConfigLayersAndVulkanDLL - SetErrors - IntOp $1 10000 + $0 - ${Else} - StrCpy $1 60 + ClearErrors + + # The Powershell script failed, and we don't know why. + # Simply configure system to use our loader and vulkaninfo. + MessageBox MB_OK "Warning!$\n$\nPowershell script called by VulkanRT Installer failed with error $0. Is Powershell installed on your system?$\n$\nWill configure system with Vulkan $FileVersion." /SD IDOK + ${If} ${RunningX64} + Delete $WINDIR\SysWow64\vulkan-${VERSION_ABI_MAJOR}.dll + Delete $WINDIR\SysWow64\vulkaninfo.exe + CopyFiles /SILENT $WINDIR\SysWow64\vulkan-$FileVersion.dll $WINDIR\SysWow64\vulkan-${VERSION_ABI_MAJOR}.dll + CopyFiles /SILENT $WINDIR\SysWow64\vulkaninfo-$FileVersion.exe $WINDIR\SysWow64\vulkaninfo.exe + ${Endif} + Delete $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll + Delete $WINDIR\System32\vulkaninfo.exe + CopyFiles /SILENT $WINDIR\System32\vulkan-$FileVersion.dll $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll + CopyFiles /SILENT $WINDIR\System32\vulkaninfo-$FileVersion.exe $WINDIR\System32\vulkaninfo.exe + ClearErrors ${Endif} + StrCpy $1 60 Call CheckForError # We are done using ConfigLayersAndVulkanDLL.ps1, delete it. It will be re-installed @@ -613,13 +634,18 @@ Section "uninstall" # vulkan--*.dll to vulkan-.dll, and to set up layer registry # entries to use layers from the corresponding SDK SetOutPath "$IDir" - #ClearErrors Call un.ConfigLayersAndVulkanDLL ${If} $0 != 0 SetOutPath "$IDir" Call un.DiagConfigLayersAndVulkanDLL - SetErrors - IntOp $1 20000 + $0 + MessageBox MB_OK "Warning!$\n$\nPowershell script called by VulkanRT Uninstaller failed with error $0. Is Powershell installed on your system?$\n$\nVulkan $FileVersion has been uninstalled from your system." /SD IDOK + ${If} ${RunningX64} + Delete $WINDIR\SysWow64\vulkan-${VERSION_ABI_MAJOR}.dll + Delete $WINDIR\SysWow64\vulkaninfo.exe + ${Endif} + Delete $WINDIR\System32\vulkan-${VERSION_ABI_MAJOR}.dll + Delete $WINDIR\System32\vulkaninfo.exe + ClearErrors ${Else} StrCpy $1 85 ${Endif} -- 2.7.4