@echo off
setlocal EnableExtensions

if /i not "%OS%"=="Windows_NT" (
  echo Siraya Printer Service requires Windows.
  pause
  exit /b 1
)

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

cd /d "%~dp0"
echo ===========================================
echo   Siraya Printer Service - Repair
echo ===========================================
echo.

powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0repair-from-folder.ps1" -BundleRoot "%~dp0."
set ERR=%errorlevel%

if %ERR% neq 0 (
  echo.
  echo Repair failed. See %TEMP%\SirayaPrinter-Repair.log
  echo Service logs: %ProgramData%\Siraya\Printer\logs\
  pause
  exit /b %ERR%
)

echo.
echo Repair complete.
pause
exit /b 0
