@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul
title VibeEdit - Go cai dat

set "BUNDLEID=com.vibeedit.panel"
set "EXTROOT=%APPDATA%\Adobe\CEP\extensions"
set "DATADIR=%LOCALAPPDATA%\VibeEdit"

echo.
echo   ========================================
echo     VibeEdit - Go cai dat
echo   ========================================
echo.

REM --- 1. Yeu cau dong Premiere ---
:checkpr
tasklist /fi "imagename eq Adobe Premiere Pro.exe" 2>nul | find /i "Adobe Premiere Pro.exe" >nul
if not errorlevel 1 (
  echo   [!] Premiere Pro dang mo. Vui long DONG han Premiere roi nhan phim bat ky...
  pause >nul
  goto checkpr
)
taskkill /f /im vibeedit-engine.exe >nul 2>&1

REM --- 2. Go thu muc extension (moi ban cung BundleId) ---
echo   - Go extension...
if exist "%EXTROOT%" (
  for /d %%D in ("%EXTROOT%\*") do (
    if exist "%%D\CSXS\manifest.xml" (
      findstr /c:"%BUNDLEID%" "%%D\CSXS\manifest.xml" >nul 2>&1
      if not errorlevel 1 (
        echo       go: %%~nxD
        rd /s /q "%%D"
      )
    )
  )
)

REM --- 3. Hoi truoc khi xoa data (model/engine co the vai tram MB) ---
echo.
if exist "%DATADIR%" (
  echo   Du lieu cuc bo (settings, model, engine da tai) nam o:
  echo     %DATADIR%
  set /p DELDATA="  Xoa luon du lieu nay? (y/N): "
  if /i "!DELDATA!"=="y" (
    rd /s /q "%DATADIR%"
    echo   - Da xoa du lieu.
  ) else (
    echo   - Giu lai du lieu (cai lai sau khong phai tai model/engine lai).
  )
)

REM --- 4. KHONG tat PlayerDebugMode (extension khac co the can) ---
echo.
echo   Luu y: KHONG tat PlayerDebugMode (extension khac co the dang dung).
echo.
echo   Da go cai dat VibeEdit.
echo.
pause
exit /b 0
