diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-10-30 18:51:55 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-10-31 17:31:10 -0700 |
| commit | eb7e1e481bbebc13d277d6a89f0a270767962286 (patch) | |
| tree | e5f1c0e505a5c0ca0360079567846d253da98505 /scripts | |
| parent | a705df80b0f8db81b201492b4012e23e08a53694 (diff) | |
| download | vcpkg-eb7e1e481bbebc13d277d6a89f0a270767962286.tar.gz vcpkg-eb7e1e481bbebc13d277d6a89f0a270767962286.zip | |
Fix proxy usage in Win7 (powershell 2.0)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/fetchDependency.ps1 | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/scripts/fetchDependency.ps1 b/scripts/fetchDependency.ps1 index 89e37c428..6cd28ad8e 100644 --- a/scripts/fetchDependency.ps1 +++ b/scripts/fetchDependency.ps1 @@ -18,6 +18,19 @@ function Test-Module($moduleName) return [bool](Get-Module -ListAvailable -Name $moduleName) } +function Get-Credential-Backwards-Compatible() +{ + if (Test-CommandParameter -commandName 'Get-Credential' -parameterName 'Message') + { + return Get-Credential -Message "Enter credentials for Proxy Authentication" + } + else + { + Write-Host "Enter credentials for Proxy Authentication" + return Get-Credential + } +} + if (Test-Module -moduleName 'BitsTransfer') { Import-Module BitsTransfer -Verbose:$false @@ -54,28 +67,18 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) $WC = New-Object System.Net.WebClient $ProxyAuth = !$WC.Proxy.IsBypassed($url) - if ($ProxyAuth) - { - if (Test-CommandParameter -commandName 'Get-Credential' -parameterName 'Message') - { - $ProxyCred = Get-Credential -Message "Enter credentials for Proxy Authentication" - } - else - { - "Enter credentials for Proxy Authentication" - $ProxyCred = Get-Credential - } - - $PSDefaultParameterValues.Add("Start-BitsTransfer:ProxyAuthentication","Basic") - $PSDefaultParameterValues.Add("Start-BitsTransfer:ProxyCredential",$ProxyCred) - $WC.Proxy.Credentials=$ProxyCred - } # git and installerbase fail with Start-BitsTransfer if ((Test-Command -commandName 'Start-BitsTransfer') -and ($Dependency -ne "git")-and ($Dependency -ne "installerbase")) { try { + if ($ProxyAuth) + { + $ProxyCred = Get-Credential-Backwards-Compatible + $PSDefaultParameterValues.Add("Start-BitsTransfer:ProxyAuthentication","Basic") + $PSDefaultParameterValues.Add("Start-BitsTransfer:ProxyCredential", $ProxyCred) + } Start-BitsTransfer -Source $url -Destination $downloadPath -ErrorAction Stop return } @@ -89,6 +92,11 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) } } + if ($ProxyAuth) + { + $WC.Proxy.Credentials = Get-Credential-Backwards-Compatible + } + Write-Verbose("Downloading $Dependency...") $WC.DownloadFile($url, $downloadPath) } |
