core: 优化 windows 下的文件下载

This commit is contained in:
bin456789 2025-04-17 21:10:25 +08:00
parent 4061c5c6b6
commit ae69f6a841
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -126,11 +126,8 @@ call :check_cygwin_installed || (
--packages %pkgs% --packages %pkgs%
rem 检查 Cygwin 是否成功安装 rem 检查 Cygwin 是否成功安装
if errorlevel 1 ( if errorlevel 1 goto :install_cygwin_failed
goto :install_cygwin_failed call :check_cygwin_installed || goto :install_cygwin_failed
) else (
call :check_cygwin_installed || goto :install_cygwin_failed
)
) )
rem 在c盘根目录下执行 cygpath -ua . 会得到 /cygdrive/c因此末尾要有 / rem 在c盘根目录下执行 cygpath -ua . 会得到 /cygdrive/c因此末尾要有 /
@ -159,23 +156,28 @@ rem 或者添加 export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/
%SystemDrive%\cygwin\bin\bash %thisdir%reinstall.sh %* %SystemDrive%\cygwin\bin\bash %thisdir%reinstall.sh %*
exit /b exit /b
:download
rem bits 要求有 Content-Length 才能下载 rem bits 要求有 Content-Length 才能下载
rem cloudflare 的 cdn-cgi/trace 没有 Content-Length
rem 据说如果网络设为“按流量计费” bits 也无法下载 rem 据说如果网络设为“按流量计费” bits 也无法下载
rem https://learn.microsoft.com/en-us/windows/win32/bits/http-requirements-for-bits-downloads rem https://learn.microsoft.com/en-us/windows/win32/bits/http-requirements-for-bits-downloads
rem bitsadmin /transfer "%~3" /priority foreground %~1 %~2
:download
rem certutil 会被 windows Defender 报毒 rem certutil 会被 windows Defender 报毒
rem windows server 2019 要用第二条 certutil 命令 rem windows server 2019 要用第二条 certutil 命令
echo Download: %~1 %~2 echo Download: %~1 %~2
del /q "%~2" 2>nul del /q "%~2" 2>nul
if exist "%~2" (echo Cannot delete %~2 & exit /b 1) if exist "%~2" (echo Cannot delete %~2 & exit /b 1)
if not exist "%~2" certutil -urlcache -f -split "%~1" "%~2" >nul
if not exist "%~2" certutil -urlcache -split "%~1" "%~2" >nul certutil -urlcache -f -split "%~1" "%~2" >nul
if not exist "%~2" exit /b 1 if not errorlevel 1 if exist "%~2" exit /b 0
exit /b
certutil -urlcache -split "%~1" "%~2" >nul
if not errorlevel 1 if exist "%~2" exit /b 0
rem 下载失败时删除文件,防止下载了一部分导致下次运行时跳过了下载
del /q "%~2" 2>nul
exit /b 1
:download_with_curl :download_with_curl
rem 加 --insecure 防止以下错误 rem 加 --insecure 防止以下错误