@Echo Off
Title ip1云端更新 多配置文件下载
cd /d %~dp0

:: 确保子目录 a 存在
if not exist ".\a" md ".\a"

:: 下载任务列表
call :DownloadFile "Xray.json" "xray"
call :DownloadFile "hysteria2.json" "hysteria2"
call :DownloadFile "naiveproxy.json" "naiveproxy"
call :DownloadFile "singbox.json" "singbox"
call :DownloadFile "juicity.json" "juicity"

exit

:DownloadFile
set "filename=%~1"
set "folder=%~2"
set "target=.\a\%filename%"

:: 清理旧文件
if exist "%target%" del "%target%"

:: 第一个源
wget -t 2 --no-check-certificate -O "%target%" "https://www.gitlabip.xyz/Alvin9999/PAC/master/backup/img/1/2/ipp/%folder%/1/config.json"

:: 校验大小
for %%F in ("%target%") do if %%~zF GEQ 100 goto :eof

:: 第二个源
..\..\wget -t 2 --no-check-certificate -O "%target%" "https://gitlab.com/free9999/ipupdate/-/raw/master/backup/img/1/2/ipp/%folder%/1/config.json"

:: 再次校验
for %%F in ("%target%") do if %%~zF GEQ 100 goto :eof

:: 下载失败提示（可选）
echo %filename% 下载失败，请检查链接或网络。
goto :eof
