@echo off
setlocal

net session >nul 2>&1
if not "%ERRORLEVEL%"=="0" (
    echo Olive install requires administrator rights to trust the MSIX signing certificate.
    echo Requesting administrator rights...
    powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%ComSpec%' -ArgumentList '/k ""%~f0"" %*' -Verb RunAs"
    exit /b 0
)

pwsh -NoProfile -ExecutionPolicy Bypass -File "%~dp0Install-Olive.ps1" %*
set "OLIVE_EXIT_CODE=%ERRORLEVEL%"
echo.
if "%OLIVE_EXIT_CODE%"=="0" (
    echo Install completed successfully.
) else (
    echo Install failed with exit code %OLIVE_EXIT_CODE%.
)
echo Press Enter to close this window.
pause >nul
exit /b %OLIVE_EXIT_CODE%
