Simplify file name detection in URLs

This commit is contained in:
Manuel Thalmann 2023-07-16 01:56:51 +02:00
parent e49d6af4e1
commit 6419257cd8

View file

@ -6,11 +6,7 @@ function Install-SoftwarePackage([Context] $context, [string] $location, [string
if (-not ($local.IsPresent)) { if (-not ($local.IsPresent)) {
Write-Information "Determining the file name of $location"; Write-Information "Determining the file name of $location";
$tempDir = $context.GetTempDirectory(); $fileName = ([uri]$location).Segments[-1];
$request = [System.Net.WebRequest]::Create($location);
$request.AllowAutoRedirect = $false;
$response = $request.GetResponse();
$fileName = [System.IO.Path]::GetFileName($response.GetResponseHeader("Location"));
Write-Information "$fileName"; Write-Information "$fileName";
$filePath = Join-Path $tempDir $fileName; $filePath = Join-Path $tempDir $fileName;