feat: 为 Windows 依赖脚本添加网络代理配置支持
在脚本开头提供代理配置示例,取消注释即可生效。 支持 HTTP/HTTPS/SOCKS5 代理及认证代理。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e36fb1d931
commit
7314a16051
@ -5,6 +5,30 @@
|
|||||||
# ============================================================================
|
# ============================================================================
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 网络代理配置(如需通过代理下载,请取消注释并修改)
|
||||||
|
# ============================================================================
|
||||||
|
# 示例 1:HTTP 代理(最常见)
|
||||||
|
# $env:HTTPS_PROXY = "http://127.0.0.1:7890"
|
||||||
|
# $env:HTTP_PROXY = "http://127.0.0.1:7890"
|
||||||
|
|
||||||
|
# 示例 2:SOCKS5 代理
|
||||||
|
# $env:HTTPS_PROXY = "socks5://127.0.0.1:7890"
|
||||||
|
# $env:HTTP_PROXY = "socks5://127.0.0.1:7890"
|
||||||
|
|
||||||
|
# 示例 3:需要认证的代理
|
||||||
|
# $env:HTTPS_PROXY = "http://username:password@proxy.example.com:8080"
|
||||||
|
|
||||||
|
# 如果设置了代理,让 .NET WebClient 也使用它
|
||||||
|
if ($env:HTTPS_PROXY -or $env:HTTP_PROXY) {
|
||||||
|
$ProxyUrl = $env:HTTPS_PROXY ?? $env:HTTP_PROXY
|
||||||
|
Write-Host "[INFO] 使用代理: $ProxyUrl" -ForegroundColor Yellow
|
||||||
|
$ProxyUri = New-Object System.Uri($ProxyUrl)
|
||||||
|
[System.Net.WebRequest]::DefaultWebProxy = New-Object System.Net.WebProxy($ProxyUri)
|
||||||
|
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
|
||||||
|
}
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
# 项目根目录
|
# 项目根目录
|
||||||
$ProjectRoot = Split-Path $PSScriptRoot -Parent
|
$ProjectRoot = Split-Path $PSScriptRoot -Parent
|
||||||
$ThirdParty = Join-Path $ProjectRoot "third_party"
|
$ThirdParty = Join-Path $ProjectRoot "third_party"
|
||||||
@ -95,6 +119,10 @@ if ((Test-Path (Join-Path $OnnxWinDir "lib\onnxruntime.lib")) -or
|
|||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
$client = New-Object System.Net.WebClient
|
$client = New-Object System.Net.WebClient
|
||||||
$client.Headers.Add("User-Agent", "PowerShell")
|
$client.Headers.Add("User-Agent", "PowerShell")
|
||||||
|
# 如果配置了代理,让 WebClient 也使用
|
||||||
|
if ([System.Net.WebRequest]::DefaultWebProxy -ne $null) {
|
||||||
|
$client.Proxy = [System.Net.WebRequest]::DefaultWebProxy
|
||||||
|
}
|
||||||
$client.DownloadFile($ZipUrl, $ZipPath)
|
$client.DownloadFile($ZipUrl, $ZipPath)
|
||||||
Write-Host "[OK] 下载完成" -ForegroundColor Green
|
Write-Host "[OK] 下载完成" -ForegroundColor Green
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user