|
| 1 | +# Onevox Windows Uninstaller |
| 2 | +# Run this script in PowerShell |
| 3 | + |
| 4 | +param( |
| 5 | + [switch]$KeepConfig = $false, |
| 6 | + [switch]$Force = $false |
| 7 | +) |
| 8 | + |
| 9 | +# Define paths |
| 10 | +$onevoxDir = "$env:LOCALAPPDATA\onevox" |
| 11 | +$configDir = "$env:APPDATA\onevox\onevox\config" |
| 12 | +$dataDir = "$env:APPDATA\onevox\onevox\data" |
| 13 | +$cacheDir = "$env:LOCALAPPDATA\onevox\onevox\cache" |
| 14 | +$logsDir = "$env:APPDATA\onevox\onevox\data\logs" |
| 15 | +$serviceName = "Onevox" |
| 16 | + |
| 17 | +# Colors for output |
| 18 | +function Write-Info { |
| 19 | + param([string]$message) |
| 20 | + Write-Host "[INFO] $message" -ForegroundColor Green |
| 21 | +} |
| 22 | + |
| 23 | +function Write-Warn { |
| 24 | + param([string]$message) |
| 25 | + Write-Host "[WARN] $message" -ForegroundColor Yellow |
| 26 | +} |
| 27 | + |
| 28 | +function Write-Error-Message { |
| 29 | + param([string]$message) |
| 30 | + Write-Host "[ERROR] $message" -ForegroundColor Red |
| 31 | +} |
| 32 | + |
| 33 | +# Check if running as administrator |
| 34 | +function Test-Administrator { |
| 35 | + $currentUser = [Security.Principal.WindowsIdentity]::GetCurrent() |
| 36 | + $principal = New-Object Security.Principal.WindowsPrincipal($currentUser) |
| 37 | + return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) |
| 38 | +} |
| 39 | + |
| 40 | +# Confirm uninstall |
| 41 | +function Confirm-Uninstall { |
| 42 | + Write-Host "" |
| 43 | + Write-Host "╔════════════════════════════════════════╗" -ForegroundColor Cyan |
| 44 | + Write-Host "║ Onevox Windows Uninstaller ║" -ForegroundColor Cyan |
| 45 | + Write-Host "╚════════════════════════════════════════╝" -ForegroundColor Cyan |
| 46 | + Write-Host "" |
| 47 | + Write-Host "This will remove Onevox and all its data." -ForegroundColor Yellow |
| 48 | + Write-Host "" |
| 49 | + Write-Host "The following will be deleted:" |
| 50 | + Write-Host " • Binary: $onevoxDir" -ForegroundColor Gray |
| 51 | + Write-Host " • Config: $configDir" -ForegroundColor Gray |
| 52 | + Write-Host " • Data: $dataDir" -ForegroundColor Gray |
| 53 | + Write-Host " • Cache: $cacheDir" -ForegroundColor Gray |
| 54 | + Write-Host " • Service: $serviceName (if registered)" -ForegroundColor Gray |
| 55 | + Write-Host "" |
| 56 | + |
| 57 | + if (-not $Force) { |
| 58 | + $response = Read-Host "Continue? (y/N)" |
| 59 | + if ($response -ne 'y' -and $response -ne 'Y') { |
| 60 | + Write-Info "Uninstall cancelled" |
| 61 | + exit 0 |
| 62 | + } |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +# Stop and remove Windows service |
| 67 | +function Remove-Service { |
| 68 | + try { |
| 69 | + $service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue |
| 70 | + |
| 71 | + if ($service) { |
| 72 | + Write-Info "Stopping service..." |
| 73 | + |
| 74 | + if ($service.Status -eq 'Running') { |
| 75 | + if (Test-Administrator) { |
| 76 | + Stop-Service -Name $serviceName -Force -ErrorAction SilentlyContinue |
| 77 | + Write-Info "Service stopped" |
| 78 | + } else { |
| 79 | + Write-Warn "Service is running but script is not running as Administrator" |
| 80 | + Write-Warn "Please run PowerShell as Administrator to stop the service, or stop it manually:" |
| 81 | + Write-Host " sc.exe stop $serviceName" -ForegroundColor Gray |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + if (Test-Administrator) { |
| 86 | + Write-Info "Removing service..." |
| 87 | + sc.exe delete $serviceName | Out-Null |
| 88 | + Write-Info "Service removed" |
| 89 | + } else { |
| 90 | + Write-Warn "Cannot remove service without Administrator privileges" |
| 91 | + Write-Warn "Please run PowerShell as Administrator and execute:" |
| 92 | + Write-Host " sc.exe delete $serviceName" -ForegroundColor Gray |
| 93 | + } |
| 94 | + } |
| 95 | + } catch { |
| 96 | + Write-Warn "Could not query/remove service: $_" |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +# Remove from PATH environment variable |
| 101 | +function Remove-FromPath { |
| 102 | + Write-Info "Removing from PATH..." |
| 103 | + |
| 104 | + try { |
| 105 | + # User PATH |
| 106 | + $userPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User) |
| 107 | + if ($userPath -like "*$onevoxDir*") { |
| 108 | + $newUserPath = ($userPath -split ';' | Where-Object { $_ -ne $onevoxDir }) -join ';' |
| 109 | + [Environment]::SetEnvironmentVariable("Path", $newUserPath, [EnvironmentVariableTarget]::User) |
| 110 | + Write-Info "Removed from user PATH" |
| 111 | + } |
| 112 | + |
| 113 | + # System PATH (requires admin) |
| 114 | + if (Test-Administrator) { |
| 115 | + $systemPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) |
| 116 | + if ($systemPath -like "*$onevoxDir*") { |
| 117 | + $newSystemPath = ($systemPath -split ';' | Where-Object { $_ -ne $onevoxDir }) -join ';' |
| 118 | + [Environment]::SetEnvironmentVariable("Path", $newSystemPath, [EnvironmentVariableTarget]::Machine) |
| 119 | + Write-Info "Removed from system PATH" |
| 120 | + } |
| 121 | + } |
| 122 | + } catch { |
| 123 | + Write-Warn "Could not remove from PATH: $_" |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +# Remove files and directories |
| 128 | +function Remove-Files { |
| 129 | + Write-Info "Removing files..." |
| 130 | + |
| 131 | + # Remove binary |
| 132 | + if (Test-Path $onevoxDir) { |
| 133 | + try { |
| 134 | + Remove-Item -Path $onevoxDir -Recurse -Force -ErrorAction Stop |
| 135 | + Write-Info "Removed binary and installation directory" |
| 136 | + } catch { |
| 137 | + Write-Error-Message "Failed to remove $onevoxDir : $_" |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + # Remove config (unless KeepConfig flag is set) |
| 142 | + if (-not $KeepConfig) { |
| 143 | + if (Test-Path $configDir) { |
| 144 | + try { |
| 145 | + Remove-Item -Path $configDir -Recurse -Force -ErrorAction Stop |
| 146 | + Write-Info "Removed config" |
| 147 | + } catch { |
| 148 | + Write-Error-Message "Failed to remove $configDir : $_" |
| 149 | + } |
| 150 | + } |
| 151 | + } else { |
| 152 | + Write-Info "Keeping config directory (--KeepConfig flag set)" |
| 153 | + } |
| 154 | + |
| 155 | + # Remove data |
| 156 | + if (Test-Path $dataDir) { |
| 157 | + try { |
| 158 | + Remove-Item -Path $dataDir -Recurse -Force -ErrorAction Stop |
| 159 | + Write-Info "Removed data" |
| 160 | + } catch { |
| 161 | + Write-Error-Message "Failed to remove $dataDir : $_" |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + # Remove cache |
| 166 | + if (Test-Path $cacheDir) { |
| 167 | + try { |
| 168 | + Remove-Item -Path $cacheDir -Recurse -Force -ErrorAction Stop |
| 169 | + Write-Info "Removed cache" |
| 170 | + } catch { |
| 171 | + Write-Error-Message "Failed to remove $cacheDir : $_" |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + # Clean up empty parent directories |
| 176 | + $appDataOnevox = "$env:APPDATA\onevox" |
| 177 | + if ((Test-Path $appDataOnevox) -and ((Get-ChildItem $appDataOnevox -Recurse | Measure-Object).Count -eq 0)) { |
| 178 | + Remove-Item -Path $appDataOnevox -Force -ErrorAction SilentlyContinue |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +# Main uninstall function |
| 183 | +function Main { |
| 184 | + Confirm-Uninstall |
| 185 | + |
| 186 | + Write-Host "" |
| 187 | + |
| 188 | + # Stop and remove service |
| 189 | + Remove-Service |
| 190 | + |
| 191 | + # Remove from PATH |
| 192 | + Remove-FromPath |
| 193 | + |
| 194 | + # Remove files |
| 195 | + Remove-Files |
| 196 | + |
| 197 | + Write-Host "" |
| 198 | + Write-Info "✅ Onevox uninstalled successfully" |
| 199 | + Write-Host "" |
| 200 | + |
| 201 | + if (-not (Test-Administrator)) { |
| 202 | + Write-Warn "Note: Some operations may require Administrator privileges" |
| 203 | + Write-Warn "If the service was not removed, run this script as Administrator" |
| 204 | + } |
| 205 | + |
| 206 | + Write-Host "You may need to restart your terminal or log out and back in for PATH changes to take effect." -ForegroundColor Gray |
| 207 | + Write-Host "" |
| 208 | +} |
| 209 | + |
| 210 | +# Run main function |
| 211 | +Main |
0 commit comments