@echo off setlocal enabledelayedexpansion REM Build script for the Parts Lookup app. REM Run from this folder in a Command Prompt (cmd.exe) or PowerShell. echo === Detecting Python === REM Activate virtual environment if present if exist .venv\Scripts\activate.bat ( echo Activating .venv virtual environment... call .venv\Scripts\activate.bat ) else if exist venv\Scripts\activate.bat ( echo Activating venv virtual environment... call venv\Scripts\activate.bat ) REM Determine the python command to use (prefer python, fallback to py) set PYTHON_CMD=python where %PYTHON_CMD% >nul 2>nul if errorlevel 1 ( set PYTHON_CMD=py where !PYTHON_CMD! >nul 2>nul if errorlevel 1 ( echo Python could not be found! Please ensure Python is installed and added to your system PATH. pause exit /b 1 ) ) echo Using Python command: !PYTHON_CMD! echo === Installing/updating dependencies === !PYTHON_CMD! -m pip install --upgrade pip !PYTHON_CMD! -m pip install -r requirements.txt if errorlevel 1 ( echo Failed to install dependencies. pause exit /b 1 ) echo === Preparing assets === if exist icon_small.png ( echo Generating high-quality icon.ico from icon_small.png... !PYTHON_CMD! -c "from PIL import Image; import os; img = Image.open('icon_small.png'); img.save(os.path.join('app', 'assets', 'icon.ico'), format='ICO', sizes=[(256, 256), (128, 128), (64, 64), (48, 48), (32, 32), (16, 16)])" >nul 2>nul ) echo === Cleaning previous build === REM Force-terminate any running instances of the app to release file locks echo Closing any running instances of CSGPackerShipperHelper.exe... taskkill /f /im CSGPackerShipperHelper.exe >nul 2>nul REM Clean stale Python bytecode caches. Stale .pyc files from earlier edits REM can cause PyInstaller to mark a source module as "invalid" and silently REM omit it from the bundle, leading to ModuleNotFoundError at runtime. echo Clearing __pycache__ directories... if exist __pycache__ rmdir /S /Q __pycache__ >nul 2>nul if exist app\__pycache__ rmdir /S /Q app\__pycache__ >nul 2>nul REM Clean build folder if exist build ( rmdir /S /Q build >nul 2>nul if exist build ( echo [WARNING] Could not clean the 'build' directory. Some files might be locked. ) ) REM Clean dist folder with robust lock detection and retry prompt if exist dist ( rmdir /S /Q dist >nul 2>nul if exist dist ( echo. echo ============================================================ echo [LOCK ERROR] The 'dist' output folder is locked by Windows! echo ============================================================ echo This usually happens if: echo 1. The 'CSGPackerShipperHelper.exe' app is still running in the background. echo 2. You have the 'dist' folder open in Windows File Explorer. echo. echo Please close the application and any open File Explorer windows, echo then press any key to retry cleaning and building... echo ============================================================ pause REM Retry terminating app and deleting dist taskkill /f /im CSGPackerShipperHelper.exe >nul 2>nul rmdir /S /Q dist >nul 2>nul if exist dist ( echo. echo [ERROR] Folder is still locked. Please manually delete: echo dist\ echo then run this script again. pause exit /b 1 ) ) ) echo === Building executable === !PYTHON_CMD! -m PyInstaller --clean --noconfirm PartsLookup.spec if errorlevel 1 ( echo Build failed. pause exit /b 1 ) echo. echo === Done === echo Output: dist\CSGPackerShipperHelper\CSGPackerShipperHelper.exe echo Copy the entire dist\CSGPackerShipperHelper folder to the target workstation, echo or to a shared drive that workstations can launch from. pause endlocal