@echo off
REM Install-KioskApp.cmd - Install Lobby Display or Dashboard kiosk app
REM
REM Reads C:\Enrollment\display-type.txt to determine which app to install.
REM Only runs on Display PCs (PCTypes filter in preinstall.json).
REM Both installers live alongside this script in the staged display\ subtree.

set "TYPEFILE=C:\Enrollment\display-type.txt"

if not exist "%TYPEFILE%" (
    echo No display-type.txt found - skipping kiosk app install.
    exit /b 0
)

set /p DISPLAYTYPE=<"%TYPEFILE%"

if /i "%DISPLAYTYPE%"=="Lobby" (
    set "INSTALLER=%~dp0GEAerospaceLobbyDisplaySetup.exe"
    set "APPNAME=Lobby Display"
) else if /i "%DISPLAYTYPE%"=="Dashboard" (
    set "INSTALLER=%~dp0GEAerospaceDashboardSetup.exe"
    set "APPNAME=Dashboard"
) else (
    echo Unknown display type: %DISPLAYTYPE%
    exit /b 1
)

if not exist "%INSTALLER%" (
    echo %APPNAME% installer not found: %INSTALLER%
    exit /b 1
)

echo Installing %APPNAME%...
"%INSTALLER%" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /LOG="C:\Logs\PreInstall\%APPNAME%-install.log"
set EXITCODE=%errorlevel%

if %EXITCODE% equ 0 (
    echo %APPNAME% installed successfully.
) else (
    echo %APPNAME% exited with code %EXITCODE%.
)

exit /b %EXITCODE%
