-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
62 lines (53 loc) · 2.63 KB
/
install.ps1
File metadata and controls
62 lines (53 loc) · 2.63 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
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[string]$InstallDir = (Join-Path $env:LOCALAPPDATA "Programs\MiniClick"),
[switch]$SkipBuildAndTest
)
$ErrorActionPreference = "Stop"
$builtExe = Join-Path $PSScriptRoot "build\mini_click.exe"
$buildDir = Split-Path -Parent $builtExe
$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
$installedExe = Join-Path $resolvedInstallDir "mini_click.exe"
$shortcutPath = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs\MiniClick.lnk"
$applied = $false
if (-not ($isDefaultInstallDir -or $isTemporaryInstallDir)) {
throw "Refusing to install into an unexpected target: $resolvedInstallDir"
}
if ($SkipBuildAndTest -and -not $isTemporaryInstallDir) {
throw "SkipBuildAndTest is allowed only for temporary test installations."
}
if ($PSCmdlet.ShouldProcess($resolvedInstallDir, "Build, test and register the current MiniClick build")) {
if (-not $SkipBuildAndTest) {
& (Join-Path $PSScriptRoot "build.ps1") | Out-Null
& (Join-Path $PSScriptRoot "test.ps1")
}
if (Test-Path -LiteralPath $resolvedInstallDir) {
Remove-Item -LiteralPath $resolvedInstallDir -Recurse -Force
}
if ($isDefaultInstallDir) {
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $builtExe
$shortcut.WorkingDirectory = $buildDir
$shortcut.Description = "MiniClick lightweight auto clicker"
$shortcut.IconLocation = "$builtExe,0"
$shortcut.Save()
}
else {
New-Item -ItemType Directory -Force -Path $resolvedInstallDir | Out-Null
Copy-Item -LiteralPath $builtExe -Destination $installedExe -Force
}
$applied = $true
}
[pscustomobject]@{
InstalledExe = if ($isDefaultInstallDir) { $null } else { $installedExe }
Shortcut = if ($isDefaultInstallDir) { $shortcutPath } else { $null }
ShortcutTarget = if ($isDefaultInstallDir) { $builtExe } else { $null }
Applied = $applied
}