@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 Dev Installer ===
echo.

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

echo [1/3] Lade MyGymApp Dev 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 Dev wurde erfolgreich installiert! ===
echo Starte die App ueber das Startmenue: 'MyGymApp Dev'
echo.
pause
