mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-24 11:37:12 +01:00
[Get-(File)Hash] Use namespaces and add Pscx check
This commit is contained in:
parent
524adf93aa
commit
4bd9ad6969
@ -31,6 +31,30 @@ function Get-Credential-Backwards-Compatible()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-Hash-SHA265()
|
||||||
|
{
|
||||||
|
if (Test-Command -commandName 'Microsoft.PowerShell.Utility\Get-FileHash')
|
||||||
|
{
|
||||||
|
Write-Verbose("Hashing with Microsoft.PowerShell.Utility\Get-FileHash")
|
||||||
|
$downloadedFileHash = (Get-FileHash -Path $downloadPath -Algorithm SHA256).Hash
|
||||||
|
}
|
||||||
|
elseif(Test-Command -commandName 'Pscx\Get-Hash')
|
||||||
|
{
|
||||||
|
Write-Verbose("Hashing with Pscx\Get-Hash")
|
||||||
|
$downloadedFileHash = (Get-Hash -Path $downloadPath -Algorithm SHA256).HashString
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Verbose("Hashing with .NET")
|
||||||
|
$hashAlgorithm = [Security.Cryptography.HashAlgorithm]::Create("SHA256")
|
||||||
|
$fileAsByteArray = [io.File]::ReadAllBytes($downloadPath)
|
||||||
|
$hashByteArray = $hashAlgorithm.ComputeHash($fileAsByteArray)
|
||||||
|
$downloadedFileHash = -Join ($hashByteArray | ForEach-Object {"{0:x2}" -f $_})
|
||||||
|
}
|
||||||
|
|
||||||
|
return $downloadedFileHash.ToLower()
|
||||||
|
}
|
||||||
|
|
||||||
if (Test-Module -moduleName 'BitsTransfer')
|
if (Test-Module -moduleName 'BitsTransfer')
|
||||||
{
|
{
|
||||||
Import-Module BitsTransfer -Verbose:$false
|
Import-Module BitsTransfer -Verbose:$false
|
||||||
@ -233,20 +257,7 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
|
|||||||
|
|
||||||
performDownload $Dependency $url $downloadsDir $downloadPath $downloadVersion $requiredVersion
|
performDownload $Dependency $url $downloadsDir $downloadPath $downloadVersion $requiredVersion
|
||||||
|
|
||||||
#calculating the hash
|
$downloadedFileHash = Get-Hash-SHA265 $downloadPath
|
||||||
if (Test-Command -commandName 'Get-FileHash')
|
|
||||||
{
|
|
||||||
$downloadedFileHash = (Get-FileHash -Path $downloadPath -Algorithm SHA256).Hash
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$hashAlgorithm = [Security.Cryptography.HashAlgorithm]::Create("SHA256")
|
|
||||||
$fileAsByteArray = [io.File]::ReadAllBytes($downloadPath)
|
|
||||||
$hashByteArray = $hashAlgorithm.ComputeHash($fileAsByteArray)
|
|
||||||
$downloadedFileHash = -Join ($hashByteArray | ForEach-Object {"{0:x2}" -f $_})
|
|
||||||
}
|
|
||||||
|
|
||||||
$downloadedFileHash = $downloadedFileHash.ToLower()
|
|
||||||
if ($expectedDownloadedFileHash -ne $downloadedFileHash)
|
if ($expectedDownloadedFileHash -ne $downloadedFileHash)
|
||||||
{
|
{
|
||||||
Write-Host ("`nFile does not have expected hash:`n" +
|
Write-Host ("`nFile does not have expected hash:`n" +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user