diff options
Diffstat (limited to 'scripts/fetchTool.ps1')
| -rw-r--r-- | scripts/fetchTool.ps1 | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/scripts/fetchTool.ps1 b/scripts/fetchTool.ps1 index 2c2f599ef..eca405b62 100644 --- a/scripts/fetchTool.ps1 +++ b/scripts/fetchTool.ps1 @@ -4,6 +4,7 @@ param( ) Set-StrictMode -Version Latest + $scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition . "$scriptsDir\VcpkgPowershellUtils.ps1" @@ -12,6 +13,7 @@ $vcpkgRootDir = vcpkgFindFileRecursivelyUp $scriptsDir .vcpkg-root $downloadsDir = "$vcpkgRootDir\downloads" vcpkgCreateDirectoryIfNotExists $downloadsDir +$downloadsDir = Resolve-Path $downloadsDir function fetchToolInternal([Parameter(Mandatory=$true)][string]$tool) { @@ -22,49 +24,81 @@ function fetchToolInternal([Parameter(Mandatory=$true)][string]$tool) if ($toolData -eq $null) { - throw "Unkown tool $tool" + throw "Unknown tool $tool" } - $exePath = "$downloadsDir\$($toolData.exeRelativePath)" + $toolPath="$downloadsDir\tools\$tool-$($toolData.version)-windows" + $exePath = "$toolPath\$($toolData.exeRelativePath)" if (Test-Path $exePath) { return $exePath } - $isArchive = vcpkgHasProperty -object $toolData -propertyName "archiveRelativePath" + $isArchive = vcpkgHasProperty -object $toolData -propertyName "archiveName" if ($isArchive) { - $downloadPath = "$downloadsDir\$($toolData.archiveRelativePath)" + $downloadPath = "$downloadsDir\$($toolData.archiveName)" } else { - $downloadPath = "$downloadsDir\$($toolData.exeRelativePath)" + $downloadPath = "$toolPath\$($toolData.exeRelativePath)" } - $url = $toolData.url + [String]$url = $toolData.url if (!(Test-Path $downloadPath)) { Write-Host "Downloading $tool..." - vcpkgDownloadFile $url $downloadPath - Write-Host "Downloading $tool has completed successfully." - } - $expectedDownloadedFileHash = $toolData.sha256 - $downloadedFileHash = vcpkgGetSHA256 $downloadPath - vcpkgCheckEqualFileHash -filePath $downloadPath -expectedHash $expectedDownloadedFileHash -actualHash $downloadedFileHash + # Download aria2 with .NET. aria2 will be used to download everything else. + if ($tool -eq "aria2") + { + vcpkgDownloadFile $url $downloadPath $toolData.sha512 + } + else + { + $aria2exe = fetchToolInternal "aria2" + vcpkgDownloadFileWithAria2 $aria2exe $url $downloadPath $toolData.sha512 + } + + Write-Host "Downloading $tool... done." + } + else + { + vcpkgCheckEqualFileHash -url $url -filePath $downloadPath -expectedHash $toolData.sha512 + } if ($isArchive) { - $outFilename = (Get-ChildItem $downloadPath).BaseName Write-Host "Extracting $tool..." - vcpkgExtractFile -File $downloadPath -DestinationDir $downloadsDir -outFilename $outFilename - Write-Host "Extracting $tool has completed successfully." + # Extract 7zip920 with shell because we need it to extract 7zip + # Extract aria2 with shell because we need it to download 7zip + if ($tool -eq "7zip920" -or $tool -eq "aria2") + { + vcpkgExtractZipFile -ArchivePath $downloadPath -DestinationDir $toolPath + } + elseif ($tool -eq "7zip") + { + $sevenZip920 = fetchToolInternal "7zip920" + $ec = vcpkgInvokeCommand "$sevenZip920" "x `"$downloadPath`" -o`"$toolPath`" -y" + if ($ec -ne 0) + { + Write-Host "Could not extract $downloadPath" + throw + } + } + else + { + $sevenZipExe = fetchToolInternal "7zip" + vcpkgExtractFileWith7z -sevenZipExe "$sevenZipExe" -ArchivePath $downloadPath -DestinationDir $toolPath + } + Write-Host "Extracting $tool... done." } if (-not (Test-Path $exePath)) { - throw ("Could not detect or download " + $tool) + Write-Error "Could not detect or download $tool" + throw } return $exePath |
