@echo off setlocal EnableExtensions EnableDelayedExpansion rem ============================================ 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 "SCRIPT=%SELF_DIR%pptx_image_compress.py" rem ---- Python Embeddable config ---- set "PY_EMBED_VERSION=3.14.5" 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 (prefer [ROOT]\bin) ---- set "CAE_DIR=%SELF_DIR%bin" set "CAE_EXE=caesiumclt.exe" if exist "%CAE_DIR%\%CAE_EXE%" ( set "PATH=%CAE_DIR%;%PATH%" ) else ( 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 ---- 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=" if defined VIRTUAL_ENV ( if exist "%VIRTUAL_ENV%\Scripts\python.exe" ( set "PY_CMD=%VIRTUAL_ENV%\Scripts\python.exe" goto :have_python ) ) if exist "%SELF_DIR%.venv\Scripts\python.exe" ( set "PY_CMD=%SELF_DIR%.venv\Scripts\python.exe" goto :have_python ) if exist "%SELF_DIR%venv\Scripts\python.exe" ( set "PY_CMD=%SELF_DIR%venv\Scripts\python.exe" goto :have_python ) 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 ) ) 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 ) ) if exist "%PY_EXE%" ( set "PY_CMD=%PY_EXE%" goto :have_python ) 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 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 ---- Verify script presence ---- if not exist "%SCRIPT%" ( echo [ERROR] Script nicht gefunden: "%SCRIPT%" exit /b 6 ) set "RUN_ARGS=%*" if "%~1"=="" set "RUN_ARGS=-h" echo [INFO] Pruefe und installiere Python-Abhaengigkeit: svg-polish ... set "PIP_OK=0" if defined USE_PY_LAUNCHER ( "%PY_CMD%" -3 -m pip --version >nul 2>&1 ) else ( "%PY_CMD%" -m pip --version >nul 2>&1 ) if not errorlevel 1 set "PIP_OK=1" if "%PIP_OK%"=="0" ( echo [INFO] pip nicht verfuegbar. Versuche ensurepip ... if defined USE_PY_LAUNCHER ( "%PY_CMD%" -3 -m ensurepip --upgrade >nul 2>&1 ) else ( "%PY_CMD%" -m ensurepip --upgrade >nul 2>&1 ) if defined USE_PY_LAUNCHER ( "%PY_CMD%" -3 -m pip --version >nul 2>&1 ) else ( "%PY_CMD%" -m pip --version >nul 2>&1 ) if not errorlevel 1 set "PIP_OK=1" ) if "%PIP_OK%"=="0" ( if /I "%PY_CMD%"=="%PY_EXE%" ( echo [INFO] ensurepip nicht verfuegbar. Lade get-pip.py ... powershell -NoLogo -NoProfile -Command ^ "try { Invoke-WebRequest -Uri 'https://bootstrap.pypa.io/get-pip.py' -OutFile '%SELF_DIR%get-pip.py' -UseBasicParsing; exit 0 } catch { Write-Error $_; exit 1 }" if exist "%SELF_DIR%get-pip.py" ( "%PY_CMD%" "%SELF_DIR%get-pip.py" >nul 2>&1 del "%SELF_DIR%get-pip.py" >nul 2>&1 ) "%PY_CMD%" -m pip --version >nul 2>&1 if not errorlevel 1 set "PIP_OK=1" ) ) if "%PIP_OK%"=="1" ( if defined USE_PY_LAUNCHER ( "%PY_CMD%" -3 -m pip install --disable-pip-version-check --quiet svg-polish ) else ( "%PY_CMD%" -m pip install --disable-pip-version-check --quiet svg-polish ) if errorlevel 1 ( echo [WARN] 'svg-polish' konnte nicht installiert werden. SVG-Dateien werden nicht komprimiert. ) else ( echo [OK] 'svg-polish' ist verfuegbar. ) ) else ( echo [WARN] pip konnte nicht eingerichtet werden. SVG-Dateien werden nicht komprimiert. ) echo. echo [%APP_NAME%] Starte ... echo Command: "%PY_CMD%" "%SCRIPT%" %RUN_ARGS% echo. "%PY_CMD%" "%SCRIPT%" %RUN_ARGS% set "RC=%ERRORLEVEL%" echo. if "%RC%"=="0" ( echo Fertig. ) else ( echo [ERROR] Prozess endete mit Code %RC%. ) endlocal & exit /b %RC%