@echo off
rem ===========================================================================
rem  RIOJoy cockpit pre-uninstall entry point (run by the console before it
rem  deletes the RIOJoy folder). Lives INSIDE the RIOJoy folder beside
rem  uninstall-rio.ps1; elevates, then runs uninstall-rio.ps1 to stop the app,
rem  remove the logon entry, uninstall ViGEmBus, and clear per-user config.
rem ===========================================================================
setlocal
title RIOJoy pre-uninstall

rem --- elevate if we are not already administrator --------------------------
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo Requesting administrator privileges...
    powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
    exit /b 0
)

cd /d "%~dp0"

powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0uninstall-rio.ps1"
set RC=%errorlevel%

echo.
if %RC% neq 0 (
    echo pre-uninstall FAILED with exit code %RC%.
) else (
    echo pre-uninstall completed.
)
exit /b %RC%
