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)) {
Write-Information "Determining the file name of $location";
$tempDir = $context.GetTempDirectory();
$request = [System.Net.WebRequest]::Create($location);
$request.AllowAutoRedirect = $false;
$response = $request.GetResponse();
$fileName = [System.IO.Path]::GetFileName($response.GetResponseHeader("Location"));
$fileName = ([uri]$location).Segments[-1];
Write-Information "$fileName";
$filePath = Join-Path $tempDir $fileName;