$ErrorActionPreference = "Stop"

$InstallDir = Join-Path $env:LOCALAPPDATA "Programs\LunaTunnel"
$DataDir = Join-Path $env:LOCALAPPDATA "LunaTunnel"

Remove-Item -Recurse -Force "HKCU:\Software\Google\Chrome\NativeMessagingHosts\run.lunatunnel.core" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "HKCU:\Software\Microsoft\Edge\NativeMessagingHosts\run.lunatunnel.core" -ErrorAction SilentlyContinue

Get-CimInstance Win32_Process | Where-Object {
    $_.ExecutablePath -and $_.ExecutablePath.StartsWith($InstallDir, [System.StringComparison]::OrdinalIgnoreCase)
} | ForEach-Object {
    Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
}

Remove-Item -Recurse -Force $InstallDir -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force $DataDir -ErrorAction SilentlyContinue
Write-Host "LunaTunnel Browser was removed." -ForegroundColor Green
