@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul

echo Flasher.
echo.
echo Files in current folder:
dir /b *.img 2>nul
echo.

set "IMG="
set /p "IMG=Enter image file name (e.g. magisk_patched-30700_KzbW8.img): "

if not defined IMG (
  echo No file name entered. Exiting.
  pause
  exit /b 1
)

if not exist "%IMG%" (
  echo File "%IMG%" not found in current folder.
  pause
  exit /b 1
)

echo.
echo Select partition:
echo   1. boot      (Pixel 6 and older)
echo   2. init_boot (Pixel 7, 8, 9, 10, Fold)
echo.
set "PART="
set /p "PART=Enter 1 or 2: "

if "%PART%"=="1" (
  set "PARTITION=boot"
) else if "%PART%"=="2" (
  set "PARTITION=init_boot"
) else (
  echo Invalid choice. Exiting.
  pause
  exit /b 1
)

echo.
echo Flashing %IMG% to %PARTITION% ...
adb devices
adb reboot bootloader
timeout /t 15 /nobreak >nul
fastboot devices
fastboot flash %PARTITION% "%IMG%"

timeout /t 20 /nobreak >nul
fastboot reboot
echo.
echo Done.
pause
