forked from expired6978/EasyEDALoader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_Shared.ps1
More file actions
69 lines (58 loc) · 3.18 KB
/
Copy path_Shared.ps1
File metadata and controls
69 lines (58 loc) · 3.18 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
# Shared helpers - dot-source this file; do not run directly.
function Write-Header([string]$Text) {
Write-Host ""
Write-Host " $Text" -ForegroundColor Cyan
Write-Host " $('-' * $Text.Length)" -ForegroundColor DarkGray
}
function Write-Ok([string]$Text) { Write-Host " [OK] $Text" -ForegroundColor Green }
function Write-Info([string]$Text) { Write-Host " [ ] $Text" -ForegroundColor Gray }
function Write-Warn([string]$Text) { Write-Host " [!!] $Text" -ForegroundColor Yellow }
function Write-Fail([string]$Text) { Write-Host " [ERR] $Text" -ForegroundColor Red }
function Invoke-Cmd([string]$Exe, [string[]]$ArgList) {
Write-Info "$([System.IO.Path]::GetFileName($Exe)) $($ArgList -join ' ')"
$result = & $Exe @ArgList 2>&1
if ($LASTEXITCODE -ne 0) {
$result | Write-Host -ForegroundColor DarkGray
throw "Command failed (exit $LASTEXITCODE)"
}
$result | Where-Object { $_ -match 'error|warning' } |
ForEach-Object { Write-Host " $_" -ForegroundColor DarkGray }
}
function Find-MSBuild {
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhere) {
$vsPath = & $vswhere -latest -requires Microsoft.Component.MSBuild `
-find 'MSBuild\**\Bin\MSBuild.exe' 2>$null |
Select-Object -First 1
if ($vsPath -and (Test-Path $vsPath)) { return $vsPath }
}
$candidates = @(
"${env:ProgramFiles}\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe"
"${env:ProgramFiles}\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe"
"${env:ProgramFiles}\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe"
"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
)
foreach ($c in $candidates) { if (Test-Path $c) { return $c } }
$inPath = Get-Command 'MSBuild.exe' -ErrorAction SilentlyContinue
if ($inPath) { return $inPath.Source }
return $null
}
# Returns the path to the Extensions folder of the most-recently-modified
# Altium Designer installation that has an Extensions subfolder, or $null.
function Find-AltiumExtRoot {
$altiumBase = 'C:\ProgramData\Altium'
if (-not (Test-Path $altiumBase)) { return $null }
$candidates = Get-ChildItem $altiumBase -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match '^Altium Designer \{[0-9A-Fa-f\-]+\}$' } |
Where-Object { Test-Path (Join-Path $_.FullName 'Extensions') } |
Sort-Object LastWriteTime -Descending
if (-not $candidates) { return $null }
if (@($candidates).Count -gt 1) {
Write-Warn "Multiple Altium Designer installations found with an Extensions folder:"
$candidates | ForEach-Object { Write-Info " $($_.Name)" }
Write-Info "Using most recently modified: $($candidates[0].Name)"
}
return Join-Path $candidates[0].FullName 'Extensions'
}