@echo off
setlocal EnableExtensions

set "INSTALL_ROOT=%USERPROFILE%\MurtCoPdfDrag"
set "HOST_EXE=%INSTALL_ROOT%\host\MurtCoDragHost.exe"

if exist "%HOST_EXE%" (
  "%HOST_EXE%" --unregister
  if errorlevel 1 (
    echo ERROR: Edge and Chrome native-host registration could not be removed.
    pause
    exit /b 1
  )
)

taskkill /F /IM MurtCoDragHost.exe >nul 2>&1

set "CLEANUP=%TEMP%\MurtCoPdfDragCleanup-%RANDOM%.cmd"
> "%CLEANUP%" echo @echo off
>> "%CLEANUP%" echo timeout /t 2 /nobreak ^>nul
>> "%CLEANUP%" echo rmdir /S /Q "%INSTALL_ROOT%"
>> "%CLEANUP%" echo del /Q "%%~f0"
start "" /min cmd.exe /D /C ""%CLEANUP%""

echo Native-host registration and installed pilot files were removed.
echo Remove "MurtCo PDF Drag Pilot" from edge://extensions/ and
echo chrome://extensions/ in every browser profile where it was loaded.
echo Diagnostic logs are retained under:
echo   %%LOCALAPPDATA%%\Willett\MurtCoDrag\Logs
pause
