Files

113 lines
3.0 KiB
Batchfile

@echo off
setlocal EnableDelayedExpansion
:: ============================================
:: Piano Highlight Generator - Startup Script
:: ============================================
set "PROJECT_DIR=%~dp0"
set "SRC_DIR=%PROJECT_DIR%src"
set "VENV_DIR=%PROJECT_DIR%venv"
set "PYTHON_SRC=D:\ProgramData\anaconda3\envs\py312_cuda\python.exe"
set "STATE_FILE=%PROJECT_DIR%piano_highlight_state.json"
echo ============================================
echo Piano Highlight Generator - Launcher
echo ============================================
echo.
:: --------------------------------------------
:: 1. Create venv using working Python
:: --------------------------------------------
echo [1/4] Setting up Python environment...
if exist "%VENV_DIR%\Scripts\python.exe" (
echo venv exists, skipping creation
) else (
echo Creating venv using py312_cuda Python...
"%PYTHON_SRC%" -m venv "%VENV_DIR%"
if errorlevel 1 (
echo [ERROR] Failed to create venv
pause
exit /b 1
)
echo venv created
)
:: --------------------------------------------
:: 2. Install dependencies
:: --------------------------------------------
echo.
echo [2/4] Installing dependencies...
set "VENV_PIP=%VENV_DIR%\Scripts\pip.exe"
:: Check if PySide6 installed
"%VENV_DIR%\python.exe" -c "import PySide6" 2>nul
if errorlevel 1 (
echo Installing PySide6 and dependencies...
"%VENV_PIP%" install PySide6 pyyaml requests pypinyin
if errorlevel 1 (
echo [ERROR] Failed to install dependencies
pause
exit /b 1
)
) else (
echo Dependencies already installed
)
:: --------------------------------------------
:: 3. Setup FFmpeg
:: --------------------------------------------
echo.
echo [3/4] Setting up FFmpeg...
set "FFMPEG_SOURCE=D:\ProgramData\anaconda3\envs\py312_cuda\Scripts"
set "FFMPEG_LOCAL=%PROJECT_DIR%ffmpeg"
if exist "%FFMPEG_LOCAL%\ffmpeg-8.1-full_build\bin\ffmpeg.exe" (
echo Local FFmpeg found
) else (
echo Copying FFmpeg from conda env...
if not exist "%FFMPEG_LOCAL%\ffmpeg-8.1-full_build\bin" mkdir "%FFMPEG_LOCAL%\ffmpeg-8.1-full_build\bin"
for %%f in (ffmpeg.exe ffprobe.exe ffplay.exe) do (
if exist "%FFMPEG_SOURCE%\%%f" copy /Y "%FFMPEG_SOURCE%\%%f" "%FFMPEG_LOCAL%\ffmpeg-8.1-full_build\bin\%%f" >nul
)
)
set "FFMPEG_BIN=%FFMPEG_LOCAL%\ffmpeg-8.1-full_build\bin"
echo FFmpeg ready
:: --------------------------------------------
:: 4. Launch Application
:: --------------------------------------------
echo.
echo [4/4] Launching...
set "PATH=%FFMPEG_BIN%;%PATH%"
if exist "%STATE_FILE%" (
echo.
echo Found incomplete work. Resume?
set /p RESTORE=" [Y/N]: "
if /i "!RESTORE!"=="N" (
del /f "%STATE_FILE%" >nul 2>&1
)
)
echo.
echo ============================================
echo Starting...
echo ============================================
cd /d "%SRC_DIR%"
"%VENV_DIR%\Scripts\python.exe" main.py
if errorlevel 1 (
echo.
echo [ERROR] Exit code: !errorlevel!
) else (
echo.
echo Done
)
pause