@echo off 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 ============================================ set "APP_NAME=PPTX Image Compressor" set "SELF_DIR=%~dp0" set "SCRIPT=%SELF_DIR%pptx_image_compress.py" rem ---- Python Embeddable config (adjust if needed) ---- set "PY_EMBED_VERSION=3.11.9" 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 ---- set "CAE_EXE=caesiumclt.exe" if exist "%SELF_DIR%%CAE_EXE%" ( rem Prefer local caesiumclt.exe near the BAT set "PATH=%SELF_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 ) ) rem ---- Python discovery / installation ---- set "PY_CMD=" 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? 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 ) 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%" ... if exist "%PY_DIR%" rmdir /s /q "%PY_DIR%" mkdir "%PY_DIR%" >nul 2>&1 powershell -NoLogo -NoProfile -Command ^ "Expand-Archive -Path '%SELF_DIR%%PY_EMBED_ZIP%' -DestinationPath '%PY_DIR%' -Force" if errorlevel 1 ( echo [ERROR] Konnte ZIP nicht entpacken. Abbruch. exit /b 4 ) set "PY_CMD=%PY_EXE%" :have_python if not defined PY_CMD ( echo [ERROR] Konnte Python nicht ermitteln. Abbruch. 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 ) echo. echo [%APP_NAME%] Starte ... echo Command: "%PY_CMD%" "%SCRIPT%" %* echo. "%PY_CMD%" "%SCRIPT%" %* set "RC=%ERRORLEVEL%" echo. if "%RC%"=="0" ( echo [OK] Fertig. ) else ( echo [ERROR] Prozess endete mit Code %RC%. ) endlocal & exit /b %RC%