@echo off
NET SESSION >nul 2>&1
if %ERRORLEVEL% neq 0 (
    echo Admin-Rechte werden benoetigt...
    powershell -Command "Start-Process '%~f0' -Verb RunAs"
    exit /b
)

echo.
echo === MyGymApp Int Installer ===
echo.

set "DOWNLOAD_URL=https://downloads.mygymapp.win/int/MyGymApp Int.msix"
set "MSIX_PATH=%TEMP%\MyGymApp Int.msix"
set "CERT_PATH=%TEMP%\mygymapp.cer"

echo [1/3] Lade MyGymApp Int herunter...
powershell -Command "Invoke-WebRequest -Uri '%DOWNLOAD_URL%' -OutFile '%MSIX_PATH%'"
echo       Download abgeschlossen.

echo [2/3] Installiere Zertifikat...
powershell -Command "$sig = Get-AuthenticodeSignature '%MSIX_PATH%'; $cert = $sig.SignerCertificate; [System.IO.File]::WriteAllBytes('%CERT_PATH%', $cert.Export('Cert')); Import-Certificate -FilePath '%CERT_PATH%' -CertStoreLocation Cert:\LocalMachine\TrustedPeople | Out-Null"
echo       Zertifikat installiert.

echo [3/3] Installiere App...
powershell -Command "Add-AppxPackage -Path '%MSIX_PATH%'"
echo       App installiert!

del "%MSIX_PATH%" 2>nul
del "%CERT_PATH%" 2>nul

echo.
echo === MyGymApp Int wurde erfolgreich installiert! ===
echo Starte die App ueber das Startmenue: 'MyGymApp Int'
echo.
pause
