@echo off
REM SellStar 1.1.1 - Minimal UAC Installer

REM Set working directory to batch file location (fixes UAC working directory issue)
cd /d "%~dp0"

REM Check if _internal directory exists
if not exist "%~dp0_internal" goto missing_internal

REM Check if GUI installer exists  
if not exist "%~dp0_internal\Install.ps1" goto missing_ps1

REM Check if running as administrator
net session >nul 2>&1
if %errorLevel% == 0 goto run_installer
REM Request admin privileges and restart this batch file
powershell.exe -Command "Start-Process '%~f0' -Verb RunAs"
exit /b

:run_installer
REM Launch PowerShell GUI installer
powershell.exe -ExecutionPolicy Bypass -File "%~dp0_internal\Install.ps1"
if %errorLevel% NEQ 0 goto ps_failed
exit /b 0

:missing_internal
echo ERROR: Installation files not found!
echo Missing: %~dp0_internal
pause
exit /b 1

:missing_ps1
echo ERROR: GUI installer not found!
echo Missing: %~dp0_internal\Install.ps1
pause
exit /b 1

:ps_failed
echo ERROR: PowerShell installer failed or was blocked.
echo.
echo Fallback options:
echo - Run Launch.cmd for portable mode
echo - Or run: _internal\SellStar\main.exe
echo.
pause
exit /b 1
