[fetchDependency] Call Get-FileHash if available, otherwise fallback

This commit is contained in:
Alexander Karatarakis 2017-10-17 13:58:36 -07:00
parent d6d5540cc5
commit ffd91c0c1d

View File

@ -194,17 +194,17 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
performDownload $Dependency $url $downloadsDir $downloadPath $downloadVersion $requiredVersion performDownload $Dependency $url $downloadsDir $downloadPath $downloadVersion $requiredVersion
#calculating the hash #calculating the hash
if ($PSVersionTable.PSEdition -ne "Core") if (Test-Command -commandName 'Get-FileHash')
{
$downloadedFileHash = (Get-FileHash -Path $downloadPath -Algorithm SHA256).Hash
}
else
{ {
$hashAlgorithm = [Security.Cryptography.HashAlgorithm]::Create("SHA256") $hashAlgorithm = [Security.Cryptography.HashAlgorithm]::Create("SHA256")
$fileAsByteArray = [io.File]::ReadAllBytes($downloadPath) $fileAsByteArray = [io.File]::ReadAllBytes($downloadPath)
$hashByteArray = $hashAlgorithm.ComputeHash($fileAsByteArray) $hashByteArray = $hashAlgorithm.ComputeHash($fileAsByteArray)
$downloadedFileHash = -Join ($hashByteArray | ForEach-Object {"{0:x2}" -f $_}) $downloadedFileHash = -Join ($hashByteArray | ForEach-Object {"{0:x2}" -f $_})
} }
else
{
$downloadedFileHash = (Get-FileHash -Path $downloadPath -Algorithm SHA256).Hash
}
if ($expectedDownloadedFileHash -ne $downloadedFileHash) if ($expectedDownloadedFileHash -ne $downloadedFileHash)
{ {