@echo off
setlocal

REM Ciphon for Excel - Windows uninstaller.
REM
REM Served with a .cmd_ pseudo-extension, not .cmd, for the same reasons as the installer: a real
REM .cmd download is browser-flagged, and a .cmd.txt suffix is hidden by Explorer. Delete the
REM trailing underscore to get uninstall-windows.cmd, then double-click it.
REM
REM Deliberately self-contained: unlike the installer this downloads nothing, so it
REM still works when the add-in site is unreachable or has been decommissioned — which is exactly
REM when someone needs to uninstall. The cost is that the registry key, value name, and install
REM directory below are duplicated from install-windows.ps1 and must be kept in step with it.
REM No administrator rights are required.

echo.
echo  Removing Ciphon for Excel
echo  -------------------------
echo.

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$key = 'HKCU:\Software\Microsoft\Office\16.0\WEF\Developer';" ^
  "$dir = Join-Path $env:LOCALAPPDATA 'Ciphon\ExcelAddin';" ^
  "$found = $false;" ^
  "if (Get-ItemProperty -Path $key -Name 'CiphonForExcel' -ErrorAction SilentlyContinue) { $found = $true };" ^
  "if (Test-Path $dir) { $found = $true };" ^
  "Remove-ItemProperty -Path $key -Name 'CiphonForExcel' -ErrorAction SilentlyContinue;" ^
  "Remove-Item -Path $dir -Recurse -Force -ErrorAction SilentlyContinue;" ^
  "if ($found) { Write-Host '  Ciphon for Excel has been removed.' -ForegroundColor Green } else { Write-Host '  Ciphon for Excel was not installed - nothing to remove.' -ForegroundColor Yellow };" ^
  "if (Get-Process -Name 'EXCEL' -ErrorAction SilentlyContinue) { Write-Host ''; Write-Host '  Excel is open. Close it completely and reopen it to clear it from the ribbon.' -ForegroundColor Yellow }"

echo.
REM Without pause the window closes instantly on double-click and the message above is never read.
pause
exit /b 0
