Refactor detection of url file name
This commit is contained in:
parent
97eea747cc
commit
63e9bc36ca
1 changed files with 8 additions and 7 deletions
|
@ -5,16 +5,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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue