@echo off
setlocal
set "INSTALLER=%TEMP%\dadan-installer-windows.ps1"
set "ORIGIN=https://ai2028.com.cn"
if defined AI2028_INSTALL_ORIGIN set "ORIGIN=%AI2028_INSTALL_ORIGIN%"

echo Downloading DaDan AI Installer...
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; Invoke-WebRequest -UseBasicParsing '%ORIGIN%/install/dadan-installer-windows.ps1' -OutFile '%INSTALLER%'"
if errorlevel 1 (
  echo Download failed. Please check your network and try again.
  start "" "%ORIGIN%/my/connections?repair=download^&os=windows"
  pause
  exit /b 1
)

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%INSTALLER%"
set "RESULT=%ERRORLEVEL%"
del /q "%INSTALLER%" >nul 2>nul
exit /b %RESULT%
