Repository navigation
Expand file tree
/
Copy pathuninstall.ps1
More file actions
93 lines (83 loc) · 4.04 KB
/
Copy pathuninstall.ps1
File metadata and controls
93 lines (83 loc) · 4.04 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
<#
.SYNOPSIS
Removes xpp-lens: the MCP entries in Claude and, optionally, the index and program files.
.DESCRIPTION
Only MCP entries that point to this installation are removed. The index location is read
from the configuration (by default %LOCALAPPDATA%\xpp-lens\index); only the index files
(xpp.db*) are deleted, never other content of that folder. Source code and build outputs
found in the installation folder (src, dist, build, *.cs, *.csproj) are left untouched.
Nothing in PackagesLocalDirectory is ever modified.
.EXAMPLE
.\uninstall.ps1 # unregister + ask before deleting files
.EXAMPLE
.\uninstall.ps1 -All -Force # delete everything without asking
#>
[CmdletBinding()]
param(
[string] $InstallDir = $PSScriptRoot,
[switch] $KeepIndex,
[switch] $All,
[switch] $Force
)
$ErrorActionPreference = 'Stop'
function Say($m) { Write-Host " $m" }
function Confirm-Step($question) {
if ($All -or $Force) { return $true }
return (Read-Host " $question [y/N]") -match '^[yYtT]'
}
Write-Host "`nRemoving xpp-lens from $InstallDir" -ForegroundColor Cyan
$exe = Join-Path $InstallDir 'bin\xpplens.exe'
# Find the index before the program is removed: the configuration knows where it lives.
$indexFolders = @()
if (Test-Path $exe) {
$line = & $exe config 2>$null | Where-Object { $_ -match '^indexPath:' } | Select-Object -First 1
if ($line) {
$indexPath = ($line -replace '^indexPath:\s*', '').Trim()
if ($indexPath) { $indexFolders += Split-Path $indexPath -Parent }
}
}
# The default %LOCALAPPDATA% index may be shared by other installations of this user:
# consider it only when the configuration could not be read.
if ($indexFolders.Count -eq 0) { $indexFolders += Join-Path $env:LOCALAPPDATA 'xpp-lens\index' }
$indexFolders += Join-Path $InstallDir 'index' # older installations
$indexFolders = @($indexFolders | Select-Object -Unique | Where-Object { Test-Path (Join-Path $_ 'xpp.db*') })
if (Test-Path $exe) { & $exe unregister } else { Say "$exe not found - skipping unregistration" }
$target = [IO.Path]::GetFullPath($InstallDir).TrimEnd('\') + '\'
Get-CimInstance Win32_Process -Filter "Name='xpplens.exe'" |
Where-Object { $_.ExecutablePath -and $_.ExecutablePath.StartsWith($target, [StringComparison]::OrdinalIgnoreCase) } |
ForEach-Object {
Say "stopping xpplens process (PID $($_.ProcessId))"
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
}
Start-Sleep -Milliseconds 500
if (-not $KeepIndex) {
foreach ($folder in $indexFolders) {
$files = @(Get-ChildItem $folder -Filter 'xpp.db*' -File)
$size = [math]::Round(($files | Measure-Object Length -Sum).Sum / 1MB)
if (Confirm-Step "Delete the index in $folder ($size MB)?") {
$files | Remove-Item -Force
Say "index deleted: $folder"
# Remove the folders only when nothing else is left in them.
foreach ($d in @($folder, (Split-Path $folder -Parent))) {
if ((Test-Path $d) -and -not (Get-ChildItem $d -Force)) { Remove-Item $d -Force }
}
}
}
}
if (Confirm-Step "Delete the program files in $InstallDir?") {
$self = $MyInvocation.MyCommand.Path
# Source code and user content stay untouched - only what the installer put there is removed.
$keep = @('src', 'dist', 'build', 'build.ps1', 'pack.ps1', 'nuget.config')
$skipped = @()
foreach ($item in Get-ChildItem $InstallDir -Force) {
if ($item.FullName -eq $self) { continue }
if ($keep -contains $item.Name -or $item.Extension -eq '.cs' -or $item.Extension -eq '.csproj') {
$skipped += $item.Name
continue
}
Remove-Item $item.FullName -Recurse -Force -ErrorAction SilentlyContinue
}
Say "program files deleted (this script stays - delete the folder manually)"
if ($skipped.Count) { Say "left in place (source / build outputs): $($skipped -join ', ')" }
}
Write-Host "`nDone. No files in PackagesLocalDirectory were changed." -ForegroundColor Cyan