Files
niumasoftware/build_installer.bat
T
2026-09-23 16:51:40 +08:00

85 lines
2.3 KiB
Batchfile

@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
REM Build flow: PyInstaller -> generate ISS -> optional ISCC compile
REM Requirements:
REM - Python + PyInstaller
REM - Inno Setup (optional, for auto compile)
cd /d "%~dp0"
echo.
echo === Check Python architecture ===
for /f %%i in ('python -c "import platform; print(platform.architecture()[0][:2])"') do set "PY_BITS=%%i"
if not defined PY_BITS goto :pycheck_fail
if not "%PY_BITS%"=="64" goto :pycheck_fail
echo Python architecture: %PY_BITS%-bit
echo.
echo === Clean old build artifacts ===
if exist "build" rmdir /s /q "build"
if exist "dist" rmdir /s /q "dist"
echo.
echo === Build main app (onedir) ===
python -m PyInstaller --noconfirm --onedir --name niumasoftware --windowed ^
--icon "logo.ico" ^
--add-data "assets;assets" ^
--add-data "logo.png;." ^
main.py
if errorlevel 1 goto :fail
echo.
echo === Build update helper (onefile -> dist\niumasoftware) ===
python -m PyInstaller --noconfirm --onefile --name update_helper --console --distpath dist\niumasoftware ^
--icon "logo.ico" ^
update_helper.py
if errorlevel 1 goto :fail
echo.
echo === Generate Inno Setup script with AppVersion ===
python installer\build_installer.py
if errorlevel 1 goto :fail
echo.
echo === (Optional) Compile installer via ISCC.exe ===
set "ISCC="
if exist "%ProgramFiles(x86)%\Inno Setup 6\ISCC.exe" set "ISCC=%ProgramFiles(x86)%\Inno Setup 6\ISCC.exe"
if exist "%ProgramFiles%\Inno Setup 6\ISCC.exe" set "ISCC=%ProgramFiles%\Inno Setup 6\ISCC.exe"
if not defined ISCC (
echo ISCC.exe not found, skip compiling installer.
echo You can compile: installer\niumasoftware.generated.iss
goto :ok
)
echo Using ISCC: "%ISCC%"
"%ISCC%" "installer\niumasoftware.generated.iss"
if errorlevel 1 goto :fail
:ok
echo.
echo === Done ===
echo dist\niumasoftware\niumasoftware.exe
echo dist\niumasoftware\update_helper.exe
echo installer\niumasoftware.generated.iss
echo.
exit /b 0
:pycheck_fail
echo.
echo ERROR: Current python is not 64-bit, cannot build 64-bit installer payload.
echo Please use 64-bit Python, for example:
echo py -3.13-64 -m pip install -r requirements.txt
echo py -3.13-64 -m pip install pyinstaller
echo py -3.13-64 -m PyInstaller --version
echo Then rerun this script.
exit /b 1
:fail
echo.
echo Build failed.
exit /b 1