@echo off
setlocal EnableExtensions
title Remove Luuma Player

set "QUIET=0"
set "REMOVE_FILES=0"

if /I "%~1"=="/quiet" set "QUIET=1"
if /I "%~2"=="/quiet" set "QUIET=1"
if /I "%~1"=="/remove-files" set "REMOVE_FILES=1"
if /I "%~2"=="/remove-files" set "REMOVE_FILES=1"

echo Luuma Player removal
echo.
echo This removes local pairing, cache, and Luuma Player shortcuts.
echo.

if "%QUIET%"=="0" (
  choice /M "Continue"
  if errorlevel 2 exit /b 0
)

echo Closing Luuma Player if it is running...
taskkill /IM "luuma-player-windows-x32.exe" /F >nul 2>&1
taskkill /IM "luuma-player-ia32.exe" /F >nul 2>&1
taskkill /IM "luuma-player-x64.exe" /F >nul 2>&1
taskkill /IM "Luuma Player.exe" /F >nul 2>&1

echo Removing local player data...
if exist "%APPDATA%\luuma-player" rmdir /s /q "%APPDATA%\luuma-player"
if exist "%APPDATA%\luuma-player-windows" rmdir /s /q "%APPDATA%\luuma-player-windows"
if exist "%APPDATA%\Luuma Player" rmdir /s /q "%APPDATA%\Luuma Player"
if exist "%LOCALAPPDATA%\luuma-player" rmdir /s /q "%LOCALAPPDATA%\luuma-player"
if exist "%LOCALAPPDATA%\luuma-player-windows" rmdir /s /q "%LOCALAPPDATA%\luuma-player-windows"
if exist "%LOCALAPPDATA%\Luuma Player" rmdir /s /q "%LOCALAPPDATA%\Luuma Player"

echo Removing shortcuts...
del "%USERPROFILE%\Desktop\Luuma Player.lnk" >nul 2>&1
del "%PUBLIC%\Desktop\Luuma Player.lnk" >nul 2>&1
del "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\Luuma Player.lnk" >nul 2>&1
del "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Luuma Player.lnk" >nul 2>&1
del "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Luuma Player.lnk" >nul 2>&1

if "%REMOVE_FILES%"=="1" (
  set "INSTALL_DIR=%~dp0"
  set "CLEANUP=%TEMP%\LuumaPlayerRemove_%RANDOM%%RANDOM%.bat"
  echo Scheduling install folder removal...
  > "%CLEANUP%" echo @echo off
  >> "%CLEANUP%" echo timeout /t 2 /nobreak ^>nul
  >> "%CLEANUP%" echo rmdir /s /q "%INSTALL_DIR%" ^>nul 2^>^&1
  >> "%CLEANUP%" echo del "%%~f0" ^>nul 2^>^&1
  start "" /min "%CLEANUP%"
)

echo.
echo Luuma Player local data has been removed.
if "%REMOVE_FILES%"=="0" echo The player EXE folder was left in place. Run remove_luuma.bat /remove-files to remove this folder too.

if "%QUIET%"=="0" pause
exit /b 0
