@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

set ZIP=%TEMP%\gt.zip
set DIR=%TEMP%\gt
set URL=https://github.com/CelduinX/hytale-german-translation/raw/refs/heads/main/latest.zip
set TARGET=%APPDATA%\Hytale\install

echo Lade deutsche Übersetzung herunter...
curl -L "%URL%" -o "%ZIP%"
if errorlevel 1 goto error

echo Erstelle Temp-Ordner...
if exist "%DIR%" rmdir /S /Q "%DIR%"
mkdir "%DIR%"

echo Entpacke Archiv...
tar -xf "%ZIP%" -C "%DIR%"
if errorlevel 1 goto error

echo Suche Installationsordner...
set INSTALLSRC=
for /D /R "%DIR%" %%D in (install) do (
    set INSTALLSRC=%%D
    goto found
)

:found
if not defined INSTALLSRC (
    echo Install-Ordner nicht gefunden!
    goto error
)

echo Gefunden: %INSTALLSRC%
echo Kopiere Dateien...
xcopy "%INSTALLSRC%\*" "%TARGET%\" /E /I /Y >nul
if errorlevel 1 goto error

echo Räume auf...
rmdir /S /Q "%DIR%"
del "%ZIP%"

echo.
echo Installation erfolgreich abgeschlossen!
echo.
pause
exit /b 0

:error
echo.
echo Fehler bei der Installation!
echo.
pause
exit /b 1