-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathuninstall.ps1
More file actions
103 lines (90 loc) · 3.12 KB
/
uninstall.ps1
File metadata and controls
103 lines (90 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<#
.SYNOPSIS
Uninstall dk (droid key manager) for Windows
.DESCRIPTION
Removes dk.ps1 from %LOCALAPPDATA%\oroio\bin
Optionally removes data directory and PATH entry
.EXAMPLE
irm https://raw.githubusercontent.com/notdp/oroio/main/uninstall.ps1 | iex
#>
param(
[switch]$RemoveData,
[switch]$Force
)
$ErrorActionPreference = "Stop"
$INSTALL_DIR = Join-Path $env:LOCALAPPDATA "oroio"
$OROIO_DIR = Join-Path $env:USERPROFILE ".oroio"
$BIN_DIR = Join-Path $INSTALL_DIR "bin"
function Write-Info {
param([string]$Message)
Write-Host $Message -ForegroundColor Cyan
}
function Write-Success {
param([string]$Message)
Write-Host $Message -ForegroundColor Green
}
function Write-Warn {
param([string]$Message)
Write-Host $Message -ForegroundColor Yellow
}
# Confirm
if (-not $Force) {
$confirm = Read-Host "Uninstall dk? (y/N)"
if ($confirm -ne "y" -and $confirm -ne "Y") {
Write-Host "Cancelled."
exit 0
}
}
# Remove dk.ps1
if (Test-Path $BIN_DIR) {
Write-Info "Removing dk.ps1..."
Remove-Item -Path $BIN_DIR -Recurse -Force
}
# Remove empty install dir
if ((Test-Path $INSTALL_DIR) -and (Get-ChildItem $INSTALL_DIR -ErrorAction SilentlyContinue).Count -eq 0) {
Remove-Item -Path $INSTALL_DIR -Force
}
# Remove from PATH
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -like "*$BIN_DIR*") {
Write-Info "Removing from PATH..."
$newPath = ($userPath -split ";" | Where-Object { $_ -ne $BIN_DIR }) -join ";"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
}
# Remove profile entries
$profilePath = $PROFILE.CurrentUserAllHosts
if (Test-Path $profilePath) {
$content = Get-Content $profilePath -Raw
if ($content -like "*# dk (droid key manager)*") {
Write-Info "Removing PowerShell profile entries..."
# 容忍在文件开头/结尾且无换行的情况
$newContent = $content -replace "(?s)# dk \(droid key manager\).*?# end dk\r?\n?", ""
Set-Content -Path $profilePath -Value $newContent -NoNewline
}
}
# Remove data directory
if ($RemoveData) {
if (Test-Path $OROIO_DIR) {
Write-Warn "Removing data directory ($OROIO_DIR)..."
Remove-Item -Path $OROIO_DIR -Recurse -Force
}
}
else {
if (Test-Path $OROIO_DIR) {
# 与 macOS 卸载行为对齐:默认保留 keys.enc,清理其他缓存/配置文件
Get-ChildItem -Path $OROIO_DIR -Recurse -File | Where-Object { $_.Name -ne "keys.enc" } | ForEach-Object {
Remove-Item -Path $_.FullName -Force -ErrorAction SilentlyContinue
}
# 删除可能空的子目录
Get-ChildItem -Path $OROIO_DIR -Recurse -Directory | Where-Object { ($_ | Get-ChildItem -Force | Measure-Object).Count -eq 0 } | ForEach-Object {
Remove-Item -Path $_.FullName -Force -ErrorAction SilentlyContinue
}
Write-Warn "Data directory preserved (keys.enc 保留): $OROIO_DIR"
Write-Host " Use -RemoveData to delete it."
}
}
Write-Host ""
Write-Success "Uninstall complete!"
Write-Host ""
Write-Host "Restart your terminal for changes to take effect."
Write-Host ""