@echo off setlocal REM Navigate to the project root from the scripts folder pushd .. REM Now current directory is project_root/ REM --- Ensure bin directory exists at project root --- echo. echo Ensuring 'bin' directory exists at project root... IF NOT EXIST "bin" ( mkdir "bin" echo Created 'bin' directory. ) echo. REM --- Cleanup Previous Build Artifacts within bin folder --- echo. echo Cleaning up previous build artifacts in 'bin' folder... IF EXIST "bin\build" ( rmdir /s /q "bin\build" echo Removed 'bin\build' directory. ) IF EXIST "bin\dist" ( rmdir /s /q "bin\dist" echo Removed 'bin\dist' directory. ) IF EXIST "bin\JarvisKeyPressUtility.spec" ( del /q "bin\JarvisKeyPressUtility.spec" echo Removed 'bin\JarvisKeyPressUtility.spec' file. ) echo Cleanup in 'bin' complete. echo. REM Navigate back to the scripts folder where exe_compile.cmd is popd REM Now current directory is project_root/scripts/ REM This is the PyInstaller command to build your executable. REM Paths are now relative to the current directory (scripts/). pyinstaller --onefile --windowed --name "JarvisKeyPressUtility" ^ --add-binary "C:\Program Files\AutoHotkey\v2\AutoHotkey.exe;." ^ --add-data "..\resources;resources" ^ --uac-admin ..\main.py ^ --distpath ..\bin ^ --workpath ..\bin ^ --specpath ..\bin REM Capture the exit code of the PyInstaller command. set "EXIT_CODE=%ERRORLEVEL%" REM Check the exit code. If it's not 0 (indicating a compilation error), pause. IF %EXIT_CODE% NEQ 0 ( echo. echo PyInstaller compilation failed! echo PyInstaller exited with code: %EXIT_CODE% echo. pause ) ELSE ( REM If compilation was successful, print a message and allow the window to close. echo PyInstaller compilation successful. echo The executable "JarvisKeyPressUtility.exe" should be in the 'bin\dist' folder. REM --- Copy template.ahk to bin\dist folder (already handled by --add-data) --- REM This line is now effectively redundant as the entire 'resources' folder REM including 'template.ahk' is bundled by '--add-data "..\resources;resources"' REM PyInstaller places it within the extracted temp folder, accessible via sys._MEIPASS ) endlocal REM Exit the batch script with the same exit code as PyInstaller. exit /b %EXIT_CODE%