@echo off
setlocal
title X3F Tester Installer

set "PS1_URL=https://x3f-tester.jbcapp.com/X3FTester_x64.appinstaller"
set "PS1_URL=%PS1_URL:X3FTester_x64.appinstaller=install-x64.ps1%"
set "PS1_PATH=%TEMP%\install-x64.ps1"

echo Starting X3F Tester installer...
echo Downloading installer script...
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri '%PS1_URL%' -OutFile '%PS1_PATH%'"
if not "%ERRORLEVEL%"=="0" (
  echo Failed to download installer script from:
  echo   %PS1_URL%
  echo.
  pause
  exit /b %ERRORLEVEL%
)

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%PS1_PATH%"
set "EXITCODE=%ERRORLEVEL%"

echo.
if not "%EXITCODE%"=="0" (
  echo Installation failed with exit code %EXITCODE%.
  echo Keep this window open and share any errors shown.
) else (
  echo Installation completed.
)
echo.
pause
exit /b %EXITCODE%
