@echo off
setlocal
cd /d "%~dp0"
title Copita - First Setup

echo.
echo ==========================================
echo  Copita - First Setup
echo ==========================================
echo.
echo This installs the Python environment and the caption tagger.
echo Bundled sd-scripts will be checked during setup.
echo It can take a long time on the first run.
echo.

set "SETUP_LOG=%~dp0setup_log.txt"
echo Setup log: %SETUP_LOG%
echo.

powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference = 'Stop'; try { & '%~dp0Copita\install.ps1' -DownloadTagger *>&1 | Tee-Object -FilePath '%SETUP_LOG%'; exit 0 } catch { $_ | Out-String | Tee-Object -FilePath '%SETUP_LOG%' -Append; exit 1 }"

echo.
if errorlevel 1 (
    echo Setup failed.
    echo Please send setup_log.txt if you need help.
    echo Then run setup_first_time.bat again.
) else (
    echo Setup finished.
    echo Next: run start_copita.bat
)
echo.
pause
