@echo off
setlocal

set "SCRIPT_DIR=%~dp0"
set "WRAPPER_PS1=%SCRIPT_DIR%lib\cloudflared-firefox.ps1"

if not exist "%WRAPPER_PS1%" (
    echo ERROR: wrapper script not found: "%WRAPPER_PS1%"
    exit /b 1
)

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0lib\cloudflared-firefox.ps1" %*
set "EXIT_CODE=%ERRORLEVEL%"

if not "%EXIT_CODE%"=="0" (
    echo ERROR: cloudflared-firefox failed with exit code %EXIT_CODE%.
    exit /b %EXIT_CODE%
)

exit /b 0
