Vorbereitung Batch-Mode und Anpassung der Scripte und Readme

This commit is contained in:
2025-09-10 15:46:25 +02:00
parent e0a8aad59d
commit 7294486446
4 changed files with 294 additions and 200 deletions

View File

@@ -3,77 +3,91 @@
setlocal EnableExtensions EnableDelayedExpansion
rem ============================================
rem PPTX Image Compressor - Installer/Runner
rem - No admin rights required
rem - Uses local CaesiumCLT and Python Embeddable
rem - Pass-through of all CLI args to the .py
rem PPTX Image Compressor - Installer/Runner (Batch-enabled)
rem Fix: caesiumclt.exe aus [ROOT]\bin; Python-Discovery ohne MS Store Alias
rem ============================================
set "APP_NAME=PPTX Image Compressor"
set "SELF_DIR=%~dp0"
set "BIN_DIR=%SELF_DIR%\bin\"
set "SCRIPT=%SELF_DIR%pptx_image_compress.py"
rem ---- Python Embeddable config (adjust if needed) ----
set "PY_EMBED_VERSION=3.11.9"
rem ---- Python Embeddable config ----
set "PY_EMBED_VERSION=3.13.7"
set "PY_EMBED_ZIP=python-%PY_EMBED_VERSION%-embed-amd64.zip"
set "PY_EMBED_URL=https://www.python.org/ftp/python/%PY_EMBED_VERSION%/%PY_EMBED_ZIP%"
set "PY_DIR=%SELF_DIR%python-embed"
set "PY_EXE=%PY_DIR%\python.exe"
rem ---- CaesiumCLT discovery ----
rem ---- CaesiumCLT discovery (prefer [ROOT]\bin) ----
set "CAE_DIR=%SELF_DIR%bin"
set "CAE_EXE=caesiumclt.exe"
if exist "%BIN_DIR%%CAE_EXE%" (
rem Prefer local caesiumclt.exe near the BAT
set "PATH=%BIN_DIR%;%PATH%"
if exist "%CAE_DIR%\%CAE_EXE%" (
set "PATH=%CAE_DIR%;%PATH%"
) else (
where /q %CAE_EXE%
if errorlevel 1 (
echo [ERROR] ^> 'caesiumclt.exe' nicht gefunden.
echo Lege 'caesiumclt.exe' neben diese BAT (empfohlen)
echo oder sorge dafuer, dass es im PATH liegt.
exit /b 2
if exist "%SELF_DIR%%CAE_EXE%" (
set "PATH=%SELF_DIR%;%PATH%"
) else (
where /q %CAE_EXE%
if errorlevel 1 (
echo [ERROR] ^> 'caesiumclt.exe' nicht gefunden.
echo Lege 'caesiumclt.exe' in '%CAE_DIR%' oder neben diese BAT,
echo oder sorge dafuer, dass es im PATH liegt.
exit /b 2
)
)
)
rem ---- Python discovery / installation ----
rem ---- Determine ESC for ANSI (green check) ----
for /f "delims=" %%A in ('echo prompt $E^| cmd') do set "ESC=%%A"
rem ---- Python discovery (avoid MS Store alias) ----
set "PY_CMD="
set "USE_PY_LAUNCHER="
rem 1) existing python in PATH?
where /q python
if %errorlevel%==0 (
for /f "delims=" %%P in ('where python 2^>nul') do (
set "PY_CMD=%%P"
goto :have_python
)
)
rem 2) local embeddable python present?
rem 1) Prefer local embeddable first
if exist "%PY_EXE%" (
set "PY_CMD=%PY_EXE%"
goto :have_python
)
rem 3) download embeddable python locally
echo [INFO] Kein Python gefunden. Lade Embeddable Python %PY_EMBED_VERSION% ...
powershell -NoLogo -NoProfile -Command ^
"try { Invoke-WebRequest -Uri '%PY_EMBED_URL%' -OutFile '%SELF_DIR%%PY_EMBED_ZIP%' -UseBasicParsing; exit 0 } catch { Write-Error $_; exit 1 }"
if errorlevel 1 (
echo [WARN] Automatischer Download fehlgeschlagen.
echo Bitte lade die Datei manuell herunter:
echo %PY_EMBED_URL%
echo und speichere sie als:
echo %SELF_DIR%%PY_EMBED_ZIP%
pause
rem 2) Real python.exe in PATH (exclude WindowsApps alias)
for /f "delims=" %%P in ('where python.exe 2^>nul') do (
echo %%P | find /I "WindowsApps" >nul
if errorlevel 1 (
set "PY_CMD=%%P"
goto :have_python
)
)
for /f "delims=" %%P in ('where python3.exe 2^>nul') do (
echo %%P | find /I "WindowsApps" >nul
if errorlevel 1 (
set "PY_CMD=%%P"
goto :have_python
)
)
rem 3) Python launcher py.exe (exclude WindowsApps)
for /f "delims=" %%P in ('where py.exe 2^>nul') do (
echo %%P | find /I "WindowsApps" >nul
if errorlevel 1 (
set "PY_CMD=%%P"
set "USE_PY_LAUNCHER=1"
goto :have_python
)
)
rem 4) Download embeddable locally
if not exist "%SELF_DIR%%PY_EMBED_ZIP%" (
echo [INFO] Kein Python gefunden. Lade Embeddable Python %PY_EMBED_VERSION% ...
powershell -NoLogo -NoProfile -Command ^
"try { Invoke-WebRequest -Uri '%PY_EMBED_URL%' -OutFile '%SELF_DIR%%PY_EMBED_ZIP%' -UseBasicParsing; exit 0 } catch { Write-Error $_; exit 1 }"
)
if not exist "%SELF_DIR%%PY_EMBED_ZIP%" (
echo [ERROR] Embeddable-Python ZIP nicht vorhanden. Abbruch.
exit /b 3
)
echo [INFO] Entpacke Embeddable Python nach "%PY_DIR%" ...
echo [INFO] Entpacke nach "%PY_DIR%" ...
if exist "%PY_DIR%" rmdir /s /q "%PY_DIR%"
mkdir "%PY_DIR%" >nul 2>&1
powershell -NoLogo -NoProfile -Command ^
@@ -82,7 +96,6 @@ if errorlevel 1 (
echo [ERROR] Konnte ZIP nicht entpacken. Abbruch.
exit /b 4
)
set "PY_CMD=%PY_EXE%"
:have_python
@@ -91,21 +104,9 @@ if not defined PY_CMD (
exit /b 5
)
rem ---- Optional: 'import site' im Embeddable aktivieren ----
if exist "%PY_DIR%" (
for /f "delims=" %%F in ('dir /b "%PY_DIR%\python3*.pth" 2^>nul') do (
set "PTH_FILE=%PY_DIR%\%%F"
)
if defined PTH_FILE (
powershell -NoLogo -NoProfile -Command ^
"(Get-Content -Raw '%PTH_FILE%') -replace '^\s*#\s*import site','import site' | Set-Content -Encoding ASCII '%PTH_FILE%'"
)
)
rem ---- Verify script presence ----
if not exist "%SCRIPT%" (
echo [ERROR] Script nicht gefunden: "%SCRIPT%"
echo Lege 'pptx_image_compress.py' neben diese BAT.
exit /b 6
)
@@ -118,7 +119,7 @@ set "RC=%ERRORLEVEL%"
echo.
if "%RC%"=="0" (
echo [OK] Fertig.
echo Fertig.
) else (
echo [ERROR] Prozess endete mit Code %RC%.
)