@echo off setlocal enabledelayedexpansion REM === WindowMsgBot Build Script === REM Usage: build.bat [/skip-cert] [/skip-sign] REM build.bat [--skip-cert] [--skip-sign] REM build.bat [skip-cert] [skip-sign] set "SCRIPT_DIR=%~dp0" set "PROJECT_DIR=%SCRIPT_DIR%.." set "PYTHON=%PROJECT_DIR%\.venv311\Scripts\python.exe" REM Default: skip cert and sign (no signtool on most machines) REM To enable: set SKIP_CERT=0 or SKIP_SIGN=0 before running set "SKIP_CERT=1" set "SKIP_SIGN=1" :parse_args if "%~1"=="" goto :start_build set "_arg=%~1" REM Normalize: remove / -- - prefixes set "_arg=!_arg:/=!" set "_arg=!_arg:--=!" set "_arg=!_arg:-=!" REM Match (case-insensitive not needed, all lowercase) if /i "!_arg!"=="skipcert" set "SKIP_CERT=1" if /i "!_arg!"=="skipsign" set "SKIP_SIGN=1" REM Also match enable variants if /i "!_arg!"=="enablecert" set "SKIP_CERT=0" if /i "!_arg!"=="enablesign" set "SKIP_SIGN=0" shift goto :parse_args :start_build echo === WindowMsgBot Build === echo Project: %PROJECT_DIR% echo Python: %PYTHON% echo. REM Check Python if not exist "%PYTHON%" ( echo [ERROR] Python not found: %PYTHON% pause exit /b 1 ) REM Check PyInstaller "%PYTHON%" -c "import PyInstaller" >nul 2>&1 if %errorlevel% neq 0 ( echo Installing PyInstaller... "%PYTHON%" -m pip install pyinstaller ) REM 1. Certificate (optional) if "%SKIP_CERT%"=="0" ( echo 1. Generating self-signed certificate... if exist "%SCRIPT_DIR%code_signing_cert.pfx" ( echo Certificate already exists, skipping ) else ( powershell -ExecutionPolicy Bypass -File "%SCRIPT_DIR%generate_cert.ps1" if %errorlevel% neq 0 ( echo [WARN] Certificate generation failed, continuing... ) ) ) else ( echo 1. Skipped certificate generation ) REM 2. Clean old builds echo. echo 2. Cleaning old builds... if exist "%PROJECT_DIR%\build\build" rmdir /s /q "%PROJECT_DIR%\build\build" if exist "%PROJECT_DIR%\dist" rmdir /s /q "%PROJECT_DIR%\dist" REM 3. PyInstaller build echo. echo 3. Building with PyInstaller... REM Disable CUDA to prevent PyInstaller isolated subprocess access violation set "PYTORCH_NO_CUDA_DISPATCH=1" set "CUDA_VISIBLE_DEVICES=" cd /d "%PROJECT_DIR%" "%PYTHON%" -m PyInstaller "%SCRIPT_DIR%windowmsgbot.spec" --noconfirm --clean if %errorlevel% neq 0 ( echo [ERROR] PyInstaller build failed! pause exit /b 1 ) echo Build complete REM 4. Sign (optional) if "%SKIP_SIGN%"=="0" ( echo. echo 4. Signing exe... if exist "%SCRIPT_DIR%code_signing_cert.pfx" ( call "%SCRIPT_DIR%sign.bat" ) else ( echo [WARN] Certificate not found, skipping signing ) ) else ( echo. echo 4. Skipped signing ) REM 5. Output echo. echo 5. Build result... if exist "%PROJECT_DIR%\dist\WindowMsgBot\WindowMsgBot.exe" ( echo EXE: %PROJECT_DIR%\dist\WindowMsgBot\WindowMsgBot.exe for %%A in ("%PROJECT_DIR%\dist\WindowMsgBot\WindowMsgBot.exe") do echo Size: %%~zA bytes echo Output: %PROJECT_DIR%\dist\WindowMsgBot\ ) else ( echo [ERROR] EXE not generated ) echo. echo === Build Complete === echo Output: %PROJECT_DIR%\dist echo. pause