@echo off
setlocal enabledelayedexpansion
title Everything is Crab - cesky preklad (build 24809473)

set "BUNDLE=localization-string-tables-polish(pl)_assets_all_0573a05f9694abe1389cc77da9761409.bundle"
set "SRC=%~dp0data"

echo ==========================================================
echo   EVERYTHING IS CRAB - CESKY PREKLAD
echo   Pro verzi hry build 24809473
echo ==========================================================
echo.

if not exist "%SRC%\polish.bundle" (
  echo CHYBA: Chybi slozka "data" vedle tohoto souboru.
  echo Rozbal cely ZIP a spust INSTALUJ.bat znovu.
  echo.
  pause
  exit /b 1
)

rem ---------- Najdi slozku hry ----------
set "GAME="

rem 0) Slozka predana jako parametr (nebo pretazena mysi na INSTALUJ.bat)
if not "%~1"=="" (
  set "DROP=%~1"
  call :resolve "%~1"
)

rem 1) Automaticke hledani (Steam vcetne knihoven na jinych discich,
rem    Epic, GOG, bezne slozky na vsech discich)
if not defined GAME (
  echo Hledam slozku hry...
  for /f "usebackq delims=" %%G in (`powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0find_game.ps1" 2^>nul`) do set "GAME=%%G"
  echo.
)

rem 2) Zaloha: vychozi Steam cesty, kdyby PowerShell selhal
if not defined GAME (
  for %%P in ("%ProgramFiles(x86)%\Steam" "%ProgramFiles%\Steam") do (
    if exist "%%~P\steamapps\common\Everything is Crab\Everything is Crab.exe" (
      set "GAME=%%~P\steamapps\common\Everything is Crab"
    )
  )
)

rem 3) Potvrzeni / rucni zadani
if not defined GAME goto :askpath
echo Nalezena hra:
echo   %GAME%
echo.
set "OK="
set /p "OK=Nainstalovat sem? (a = ano / j = jina slozka): "
if /i "%OK%"=="j" set "GAME="
if /i "%OK%"=="n" set "GAME="
echo.

:askpath
if not defined GAME (
  echo Otevri slozku s hrou ^(je v ni "Everything is Crab.exe"^),
  echo zkopiruj cestu z adresniho radku a vloz ji sem
  echo ^(prave tlacitko mysi = vlozit^).
  echo.
  echo Priklad: C:\Hry\Everything is Crab\game
  echo.
  set /p "INPATH=Cesta ke hre: "
  set "INPATH=!INPATH:"=!"
  echo.
  if not "!INPATH!"=="" call :resolve "!INPATH!"
)

if not defined GAME (
  echo CHYBA: V zadane slozce ani v jejich podslozkach
  echo        neni "Everything is Crab.exe". Zkus to znovu.
  echo.
  goto :askpath
)

set "DATA=%GAME%\Everything is Crab_Data"
set "AA=%DATA%\StreamingAssets\aa"
set "SW=%AA%\StandaloneWindows64"

if not exist "%SW%" (
  echo CHYBA: Neocekavana struktura hry - chybi slozka StandaloneWindows64.
  echo.
  pause
  exit /b 1
)

echo Instaluji do:
echo   %GAME%
echo.

rem ---------- Kontrola 1: lokalizacni bundle ----------
rem (dir s maskou - funguje i kdyz cela cesta presahuje 260 znaku)
dir /b "%SW%\localization-string-tables-polish(pl)_assets_all_0573a05f*.bundle" >nul 2>&1
if not errorlevel 1 goto :bundle_ok

echo ==========================================================
echo   POZOR: Tato verze hry NENI build 24809473.
echo   Preklad nebude fungovat.
echo   Aktualni verzi hledej na https://crabcz.shano.eu
echo ==========================================================
echo.
set "GO="
set /p "GO=Presto pokracovat? (a/n): "
if /i not "%GO%"=="a" goto :cancelled
echo.
:bundle_ok

rem Font (sharedassets0.assets) se lisi mezi vydanimi hry - Steam / standalone.
rem Spravnou variantu vybere install.ps1 podle velikosti souboru; pokud vydani
rem nepozna, font vynecha a nainstaluje jen preklad textu.

rem ---------- Zaloha + kopirovani ----------
rem Pres PowerShell s prefixem \\?\ - zvladne i cesty delsi nez 260 znaku
echo Zalohuji puvodni soubory a kopiruji cestinu...
echo.

powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0install.ps1" -Src "%SRC%" -Game "%GAME%" -Bundle "%BUNDLE%"
if errorlevel 1 goto :failed

echo.
echo ==========================================================
echo   HOTOVO!
echo.
echo   Spust hru a v nastaveni vyber jazyk: Polish
echo   (cestina je ulozena v polskem slotu^)
echo.
echo   Odinstalace:
echo   - Steam: prave tlacitko na hru - Vlastnosti -
echo     Lokalni soubory - Overit integritu hernich souboru
echo   - Jinak: u souboru *.orig_backup odstran
echo     priponu .orig_backup
echo ==========================================================
echo.
pause
exit /b 0

:cancelled
echo.
echo Instalace zrusena - nic nebylo zmeneno.
echo.
pause
exit /b 1

:failed
echo.
echo CHYBA pri kopirovani. Zavri hru a spust INSTALUJ.bat
echo znovu jako spravce (prave tlacitko - Spustit jako spravce^).
echo.
pause
exit /b 1


rem ==========================================================
rem  :resolve "cesta"  ->  nastavi GAME, pokud najde hru
rem  Hleda: primo / v podslozkach (2 urovne) / o uroven vyse
rem ==========================================================
:resolve
set "P=%~1"
if "%P%"=="" exit /b 0
rem odstran koncove zpetne lomitko
if "%P:~-1%"=="\" set "P=%P:~0,-1%"

rem a) primo v zadane slozce
if exist "%P%\Everything is Crab.exe" (
  set "GAME=%P%"
  exit /b 0
)

rem b) uzivatel omylem vlozil cestu k .exe misto slozky
if /i "%~nx1"=="Everything is Crab.exe" (
  if exist "%~dp1Everything is Crab.exe" (
    set "GAME=%~dp1"
    if "!GAME:~-1!"=="\" set "GAME=!GAME:~0,-1!"
    exit /b 0
  )
)

rem c) podslozky - 2 urovne do hloubky
for /d %%A in ("%P%\*") do (
  if exist "%%~A\Everything is Crab.exe" (
    set "GAME=%%~A"
    exit /b 0
  )
  for /d %%B in ("%%~A\*") do (
    if exist "%%~B\Everything is Crab.exe" (
      set "GAME=%%~B"
      exit /b 0
    )
  )
)

rem d) o uroven vyse (uzivatel vlezl moc hluboko, napr. do ...\game\Everything is Crab_Data)
for %%U in ("%P%\..") do (
  if exist "%%~fU\Everything is Crab.exe" (
    set "GAME=%%~fU"
    exit /b 0
  )
)
exit /b 0
