From 35feef44458a4aa096b59574ec9ad794ae091466 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sun, 16 Jul 2023 01:46:57 +0200 Subject: [PATCH] Refactor detection of url file name --- scripts/Windows/Scripts/SoftwarePackage.ps1 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/Windows/Scripts/SoftwarePackage.ps1 b/scripts/Windows/Scripts/SoftwarePackage.ps1 index 6b146d5e..954d11a8 100644 --- a/scripts/Windows/Scripts/SoftwarePackage.ps1 +++ b/scripts/Windows/Scripts/SoftwarePackage.ps1 @@ -6,16 +6,17 @@ function Install-SoftwarePackage([Context] $context, [string] $location, [string [string]$tempDir = $null; if (-not ($local.IsPresent)) { + Write-Information "Determining the file name of $location"; $tempDir = $context.GetTempDirectory(); - $tempFile = Join-Path $tempDir "download.tmp"; + $request = [System.Net.WebRequest]::Create($url); + $request.AllowAutoRedirect = $false; + $response = $request.GetResponse(); + $fileName = [System.IO.Path]::GetFileName($response.GetResponseHeader("Location")); + Write-Information "$fileName"; + $filePath = Join-Path $tempDir $fileName; Write-Information "Downloading setup file from $location"; - $response = Invoke-WebRequest $location -OutFile $tempFile; - $fileName = [System.IO.Path]::GetFileName($response.Headers["Location"]); - - Write-Information "Renaming setup file to $fileName"; - $filePath = Join-Path $tempDir $fileName; - Move-Item $tempFile $filePath; + Invoke-WebRequest $location -OutFile $filePath; } else { $filePath = $location; }