@echo off
setlocal

echo === Activating virtual environment ===
if exist ".venv\Scripts\activate.bat" (
    call .venv\Scripts\activate.bat
) else (
    echo Virtual environment not found. Creating...
    python -m venv .venv
    if errorlevel 1 (
        echo [ERROR] Failed to create virtual environment. Please ensure Python is installed.
        pause
        exit /b 1
    )
    echo Virtual environment created. Activating...
    call .venv\Scripts\activate.bat
)

echo === Installing dependencies ===
pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple -r requirements.txt 
if errorlevel 1 (
    echo [ERROR] pip failed to install dependencies.
    pause
    exit /b 1
)

echo === Building with pyinstaller ===
python .\utils\hook.py
pyinstaller .\main.spec
if errorlevel 1 (
    echo [ERROR] Build failed.
    pause
    exit /b 1
)

echo === Build completed ===
