mirror of
https://github.com/cmderdev/cmder.git
synced 2025-04-16 22:52:32 +08:00
use BITS for more performant downloads when possible
This commit is contained in:
parent
f9cb2d6264
commit
473e9566e7
@ -69,6 +69,7 @@ $version = Get-VersionStr
|
|||||||
# Check for requirements
|
# Check for requirements
|
||||||
Ensure-Exists $sourcesPath
|
Ensure-Exists $sourcesPath
|
||||||
Ensure-Executable "7z"
|
Ensure-Executable "7z"
|
||||||
|
Ensure-Executable "msbuild"
|
||||||
New-Item -Type Directory -Path (Join-Path $saveTo "/tmp/") -ErrorAction SilentlyContinue >$null
|
New-Item -Type Directory -Path (Join-Path $saveTo "/tmp/") -ErrorAction SilentlyContinue >$null
|
||||||
|
|
||||||
# Preserve modified (by user) ConEmu setting file
|
# Preserve modified (by user) ConEmu setting file
|
||||||
@ -91,7 +92,7 @@ foreach ($ssh_agent in $(get-process ssh-agent -erroraction silentlycontinue)) {
|
|||||||
|
|
||||||
$vend = $pwd
|
$vend = $pwd
|
||||||
foreach ($s in $sources) {
|
foreach ($s in $sources) {
|
||||||
Write-Verbose "Downloading $($s.name) from URL $($s.url)"
|
Write-Verbose "Getting vendored $($s.name) $($s.version)..."
|
||||||
|
|
||||||
# We do not care about the extensions/type of archive
|
# We do not care about the extensions/type of archive
|
||||||
$tempArchive = "tmp/$($s.name).tmp"
|
$tempArchive = "tmp/$($s.name).tmp"
|
||||||
|
@ -10,10 +10,10 @@ function Ensure-Executable($command) {
|
|||||||
try { Get-Command $command -ErrorAction Stop > $null }
|
try { Get-Command $command -ErrorAction Stop > $null }
|
||||||
catch {
|
catch {
|
||||||
If( ($command -eq "7z") -and (Test-Path "$env:programfiles\7-zip\7z.exe") ){
|
If( ($command -eq "7z") -and (Test-Path "$env:programfiles\7-zip\7z.exe") ){
|
||||||
set-alias -Name "7z" -Value "$env:programfiles\7-zip\7z.exe" -Scope script
|
Set-Alias -Name "7z" -Value "$env:programfiles\7-zip\7z.exe" -Scope script
|
||||||
}
|
}
|
||||||
ElseIf( ($command -eq "7z") -and (Test-Path "$env:programw6432\7-zip\7z.exe") ) {
|
ElseIf( ($command -eq "7z") -and (Test-Path "$env:programw6432\7-zip\7z.exe") ) {
|
||||||
set-alias -Name "7z" -Value "$env:programw6432\7-zip\7z.exe" -Scope script
|
Set-Alias -Name "7z" -Value "$env:programw6432\7-zip\7z.exe" -Scope script
|
||||||
}
|
}
|
||||||
Else {
|
Else {
|
||||||
Write-Error "Missing $command! Ensure it is installed and on in the PATH"
|
Write-Error "Missing $command! Ensure it is installed and on in the PATH"
|
||||||
@ -23,8 +23,10 @@ function Ensure-Executable($command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Delete-Existing($path) {
|
function Delete-Existing($path) {
|
||||||
Write-Verbose "Remove $path"
|
if (Test-Path $path) {
|
||||||
Remove-Item -Recurse -force $path -ErrorAction SilentlyContinue
|
Write-Verbose "Remove existing $path"
|
||||||
|
}
|
||||||
|
Remove-Item -Recurse -Force $path -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
function Extract-Archive($source, $target) {
|
function Extract-Archive($source, $target) {
|
||||||
@ -197,13 +199,26 @@ function Download-File {
|
|||||||
)
|
)
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
|
|
||||||
# I think this is the problem
|
$useBitTransfer = $null -ne (Get-Module -Name BitsTransfer -ListAvailable) -and ($PSVersionTable.PSVersion.Major -le 5)
|
||||||
|
|
||||||
$File = $File -Replace "/", "\"
|
$File = $File -Replace "/", "\"
|
||||||
Write-Verbose "Downloading from $Url to $File"
|
|
||||||
|
try {
|
||||||
|
if ($useBitTransfer) {
|
||||||
|
Start-BitsTransfer -Source $Url -Destination $File -DisplayName "Downloading $Url to $File"
|
||||||
|
Return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Failed to download file using BITS, reason: $_`nUsing fallback method instead...`n"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Verbose "Downloading from $Url to $File`n"
|
||||||
|
|
||||||
$wc = New-Object System.Net.WebClient
|
$wc = New-Object System.Net.WebClient
|
||||||
if ($env:https_proxy) {
|
if ($env:https_proxy) {
|
||||||
$wc.proxy = (New-Object System.Net.WebProxy($env:https_proxy))
|
$wc.proxy = (New-Object System.Net.WebProxy($env:https_proxy))
|
||||||
}
|
}
|
||||||
$wc.Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials;
|
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials;
|
||||||
$wc.DownloadFile($Url, $File)
|
$wc.DownloadFile($Url, $File)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user