diff --git a/scripts/setup_deps_windows.ps1 b/scripts/setup_deps_windows.ps1 index 63809c9..f7672bc 100644 --- a/scripts/setup_deps_windows.ps1 +++ b/scripts/setup_deps_windows.ps1 @@ -5,6 +5,30 @@ # ============================================================================ $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 $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 $client = New-Object System.Net.WebClient $client.Headers.Add("User-Agent", "PowerShell") + # 如果配置了代理,让 WebClient 也使用 + if ([System.Net.WebRequest]::DefaultWebProxy -ne $null) { + $client.Proxy = [System.Net.WebRequest]::DefaultWebProxy + } $client.DownloadFile($ZipUrl, $ZipPath) Write-Host "[OK] 下载完成" -ForegroundColor Green } catch {