@echo off
chcp 65001 >nul
setlocal

set "PY=.venv\Scripts\python.exe"
set "DIST=build\a1packer"

if not exist "%DIST%" mkdir "%DIST%"

"%PY%" -m nuitka ^
  --mode=standalone ^
  --msvc=latest ^
  --enable-plugin=pyside6 ^
  --include-qt-plugins=platforms,imageformats,styles,iconengines ^
  --include-data-dir="a1_swap_mod_packer/i18n=a1_swap_mod_packer/i18n" ^
  --windows-console-mode=disable ^
  --output-dir="%DIST%" ^
  --output-filename=a1packer.exe ^
  --remove-output ^
  run_gui.py
if errorlevel 1 exit /b %ERRORLEVEL%

echo.
echo GUI build done.

set "OUTPUT=%DIST%\a1packer.dist"
robocopy "swap_gcode" "%OUTPUT%\swap_gcode" /E
if %ERRORLEVEL% GEQ 8 exit /b %ERRORLEVEL%

copy /Y "gcode_patches.ini" "%OUTPUT%\gcode_patches.ini" >nul
if errorlevel 1 exit /b %ERRORLEVEL%

copy /Y "x.png" "%OUTPUT%\x.png" >nul
if errorlevel 1 exit /b %ERRORLEVEL%

echo.
echo Build done: %OUTPUT%
echo The entire "%OUTPUT%" folder is the portable distribution.
exit /b 0
