Files
adaptronic_label-printer/prepare_ghostscript.bat

122 lines
3.9 KiB
Batchfile

@echo off
REM ============================================================
REM prepare_ghostscript.bat
REM Finds the system GhostScript installation and copies the
REM files needed for bundling into conf\ghostscript\
REM
REM Files copied:
REM conf\ghostscript\bin\gswin64c.exe (or gswin32c.exe)
REM conf\ghostscript\bin\gsdll64.dll (or gsdll32.dll)
REM conf\ghostscript\lib\*.ps (PostScript init files)
REM
REM Run this ONCE before building the exe with build_windows.bat.
REM Only the two executables + the lib/ folder are needed (~15-20 MB).
REM The full GhostScript fonts/Resources are NOT bundled to keep
REM the exe size manageable; Windows system fonts are used instead.
REM ============================================================
setlocal enabledelayedexpansion
set GS_FOUND=0
set GS_BIN_SRC=
set GS_LIB_SRC=
set GS_EXE=
REM Pre-assign ProgramFiles(x86) to avoid batch parser choking on the parentheses
set "PF64=%ProgramFiles%"
set "PF32=%ProgramFiles(x86)%"
echo.
echo ============================================================
echo GhostScript Bundle Preparation
echo ============================================================
echo.
REM ---- Search for GhostScript in both Program Files locations ----
for %%P in ("%PF64%" "%PF32%") do (
if exist "%%~P\gs" (
for /d %%V in ("%%~P\gs\gs*") do (
if exist "%%~V\bin\gswin64c.exe" (
set GS_BIN_SRC=%%~V\bin
set GS_LIB_SRC=%%~V\lib
set GS_EXE=gswin64c.exe
set GS_DLL=gsdll64.dll
set GS_FOUND=1
echo Found GhostScript (64-bit): %%~V
)
if !GS_FOUND!==0 (
if exist "%%~V\bin\gswin32c.exe" (
set GS_BIN_SRC=%%~V\bin
set GS_LIB_SRC=%%~V\lib
set GS_EXE=gswin32c.exe
set GS_DLL=gsdll32.dll
set GS_FOUND=1
echo Found GhostScript (32-bit): %%~V
)
)
)
)
)
if %GS_FOUND%==0 (
echo.
echo WARNING: GhostScript is NOT installed on this machine.
echo.
echo The exe will still build successfully, but GhostScript will
echo NOT be bundled. On the target machine the app will fall back
echo to SumatraPDF for printing (which may produce dotted output).
echo.
echo To get sharp vector-quality printing, install GhostScript:
echo https://ghostscript.com/releases/gsdnld.html
echo Then re-run this script before building.
echo.
exit /b 0
)
REM ---- Create destination folders ----
set GS_DEST_BIN=conf\ghostscript\bin
set GS_DEST_LIB=conf\ghostscript\lib
if not exist "%GS_DEST_BIN%" mkdir "%GS_DEST_BIN%"
if not exist "%GS_DEST_LIB%" mkdir "%GS_DEST_LIB%"
REM ---- Copy executable and DLL ----
echo.
echo Copying GhostScript binaries...
copy /y "%GS_BIN_SRC%\%GS_EXE%" "%GS_DEST_BIN%\%GS_EXE%" >nul
if errorlevel 1 ( echo ERROR copying %GS_EXE% & exit /b 1 )
echo + %GS_EXE%
copy /y "%GS_BIN_SRC%\%GS_DLL%" "%GS_DEST_BIN%\%GS_DLL%" >nul
if errorlevel 1 ( echo ERROR copying %GS_DLL% & exit /b 1 )
echo + %GS_DLL%
REM ---- Copy lib/ (PostScript init files .ps) ----
echo.
echo Copying GhostScript lib (PostScript init files)...
for %%F in ("%GS_LIB_SRC%\*.ps") do (
copy /y "%%F" "%GS_DEST_LIB%\" >nul
)
echo + *.ps copied from %GS_LIB_SRC%
REM ---- Report ----
echo.
echo ============================================================
echo GhostScript prepared successfully in conf\ghostscript\
echo ============================================================
echo.
REM Show size summary
set BIN_COUNT=0
set LIB_COUNT=0
for %%F in ("%GS_DEST_BIN%\*") do set /a BIN_COUNT+=1
for %%F in ("%GS_DEST_LIB%\*") do set /a LIB_COUNT+=1
echo bin\ : %BIN_COUNT% file(s)
echo lib\ : %LIB_COUNT% file(s)
echo.
echo GhostScript will be embedded into LabelPrinter.exe at build time.
echo.
endlocal
exit /b 0