@echo off
setlocal
cd /d "%~dp0"
title Build TiHiY Voice Translator v9.11.2

where py >nul 2>nul
if errorlevel 1 (
  echo [ERROR] Python launcher "py" was not found.
  pause
  exit /b 1
)

py tools\VERIFY_NO_SECRETS.py
if errorlevel 1 goto :fail

py -m pip install --upgrade pip
if errorlevel 1 goto :fail
py -m pip install -r requirements-build.txt
if errorlevel 1 goto :fail

rmdir /s /q build 2>nul
rmdir /s /q dist 2>nul
py -m PyInstaller --noconfirm --clean TiHiY_Voice_Translator.spec
if errorlevel 1 goto :fail

py tools\VERIFY_NO_SECRETS.py
if errorlevel 1 goto :fail

if exist "dist\TiHiY Voice Translator\settings.json" (
  echo [ERROR] settings.json must not be included in the portable build.
  goto :fail
)

echo.
echo [OK] Portable build:
echo %CD%\dist\TiHiY Voice Translator\TiHiY Voice Translator.exe
pause
exit /b 0

:fail
echo.
echo [ERROR] Build failed.
pause
exit /b 1
