@echo off
rem ===========================================================================
rem  RIOJoy standalone install entry point - for a computer WITHOUT the
rem  TeslaConsole launcher. Extract the whole zip somewhere permanent (e.g.
rem  C:\games), then run this as administrator. Installs the prerequisites
rem  for this Windows version (XP or 10/11) via the shared install core and
rem  creates Start Menu + desktop shortcuts to the right flavor of the app.
rem  Nothing auto-starts: launch RIOJoy from the shortcut when you want it.
rem  See README.txt for details.
rem ===========================================================================
setlocal
title RIOJoy install

rem --- elevate if we are not already administrator --------------------------
net session >nul 2>&1
if %errorlevel% neq 0 (
    rem "if errorlevel" evaluates at run time (a %var% here would be stale).
    ver | findstr /C:"Version 5.1" >nul
    if not errorlevel 1 (
        echo This installer must run as an Administrator user.
        pause
        exit /b 1
    )
    echo Requesting administrator privileges...
    powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
    exit /b 0
)

cd /d "%~dp0"

call "%~dp0RIOJoy\install-core.bat"
set RC=%errorlevel%
if %RC% neq 0 goto done

rem --- shortcuts (Start Menu + desktop) --------------------------------------
rem RIOJOY_APPDIR is set by install-core.bat to app (modern) or app-xp (XP).
set EXE=%RIOJOY_APPDIR%\RioJoy.Tray.exe
if not exist "%EXE%" (
    echo ERROR: app executable not found: %EXE%
    set RC=1
    goto done
)
echo Creating shortcuts...
cscript //nologo "%~dp0RIOJoy\make-shortcut.vbs" "%EXE%" "RIOJoy" "%RIOJOY_APPDIR%"

:done
echo.
if %RC% neq 0 (
    echo install FAILED with exit code %RC%.
) else (
    echo install completed. Launch RIOJoy from the Start Menu or desktop shortcut.
)
pause
exit /b %RC%
