@echo off setlocal EnableExtensions EnableDelayedExpansion rem ============================================ rem PPTX Image Compressor - Installer/Runner (Batch-enabled) rem Version 1.2.0 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.6" 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%" rem ---- Fix embedded Python isolation for the installation of pip ---- set "PTH_FILE=%PY_DIR%\python314._pth" if exist "%PTH_FILE%" ( echo [INFO] Enabling site-packages in embedded Python... powershell -Command ^ "(Get-Content '%PTH_FILE%') -replace '^#?\s*import site','import site' | Set-Content '%PTH_FILE%'" ) :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 "ALL_ARGS=%*" set "RUN_ARGS=%ALL_ARGS%" set "DEBUG_MODE=0" if "%~1"=="--debug" ( set "DEBUG_MODE=1" set "RUN_ARGS=!ALL_ARGS:~8!" if "!RUN_ARGS:~0,1!"==" " set "RUN_ARGS=!RUN_ARGS:~1!" ) if "!RUN_ARGS!"=="" 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 --no-warn-script-location svg-polish ) else ( "%PY_CMD%" -m pip install --disable-pip-version-check --quiet --no-warn-script-location 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. if %DEBUG_MODE%==1 ( echo [DEBUG] pip list: if defined USE_PY_LAUNCHER ( "%PY_CMD%" -3 -m pip list ) else ( "%PY_CMD%" -m pip list ) ) ) ) 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%