Repository navigation
Expand file tree
/
Copy pathuninstall.ps1
More file actions
43 lines (35 loc) · 1.94 KB
/
Copy pathuninstall.ps1
File metadata and controls
43 lines (35 loc) · 1.94 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
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[string]$InstallDir = (Join-Path $env:LOCALAPPDATA "Programs\MiniClick")
)
$ErrorActionPreference = "Stop"
$programsRoot = [System.IO.Path]::GetFullPath((Join-Path $env:LOCALAPPDATA "Programs"))
$defaultInstallDir = [System.IO.Path]::GetFullPath((Join-Path $env:LOCALAPPDATA "Programs\MiniClick"))
$resolvedInstallDir = [System.IO.Path]::GetFullPath($InstallDir)
$temporaryRoot = [System.IO.Path]::GetFullPath([System.IO.Path]::GetTempPath()).TrimEnd([System.IO.Path]::DirectorySeparatorChar)
$temporaryTestPrefix = Join-Path $temporaryRoot "MiniClickInstallTests-"
$temporaryTestPattern = '^' + [System.Text.RegularExpressions.Regex]::Escape($temporaryTestPrefix) + '[0-9a-f]{32}\\install$'
$isDefaultInstallDir = [System.String]::Equals($resolvedInstallDir, $defaultInstallDir, [System.StringComparison]::OrdinalIgnoreCase)
$isTemporaryInstallDir = $resolvedInstallDir -match $temporaryTestPattern
$shortcutPath = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs\MiniClick.lnk"
$applied = $false
if (-not ($isDefaultInstallDir -or $isTemporaryInstallDir)) {
throw "Refusing to uninstall an unexpected target: $resolvedInstallDir"
}
if (-not ($isTemporaryInstallDir -or $resolvedInstallDir.StartsWith($programsRoot + [System.IO.Path]::DirectorySeparatorChar, [System.StringComparison]::OrdinalIgnoreCase))) {
throw "Refusing to remove an unexpected directory: $resolvedInstallDir"
}
if ($PSCmdlet.ShouldProcess($resolvedInstallDir, "Remove MiniClick")) {
if (Test-Path -LiteralPath $resolvedInstallDir) {
Remove-Item -LiteralPath $resolvedInstallDir -Recurse -Force
}
if ($isDefaultInstallDir -and (Test-Path -LiteralPath $shortcutPath)) {
Remove-Item -LiteralPath $shortcutPath -Force
}
$applied = $true
}
[pscustomobject]@{
InstallDir = $resolvedInstallDir
Shortcut = if ($isDefaultInstallDir) { $shortcutPath } else { $null }
Applied = $applied
}