fix: auto-scan installers repo, sort by name, space-separated selection, remove BOM
This commit is contained in:
parent
60c771784e
commit
bb2b87f132
71
setup.ps1
71
setup.ps1
|
|
@ -1,4 +1,4 @@
|
|||
# ============================================================
|
||||
# ============================================================
|
||||
# Skript ustanovki programm
|
||||
# Zapusk: irm https://git.help-d.ru/helmut/auto-turning/raw/branch/main/setup.ps1 | iex
|
||||
# ============================================================
|
||||
|
|
@ -59,58 +59,19 @@ try {
|
|||
exit 1
|
||||
}
|
||||
|
||||
# Gruppiruem programmy po kategoriyam iz konfiga
|
||||
$categories = @{}
|
||||
$currentCat = $null
|
||||
|
||||
Get-Content $configPath | ForEach-Object {
|
||||
if ($_ -match "^\s*(\w+):\s*$" -and $_ -notmatch "basic:") {
|
||||
$currentCat = $matches[1]
|
||||
$categories[$currentCat] = @()
|
||||
}
|
||||
if ($currentCat -and $_ -match '\d+:\s*"(.+)"') {
|
||||
$categories[$currentCat] += $matches[1]
|
||||
}
|
||||
}
|
||||
|
||||
# Sozdayom kartu: imya faila -> programma
|
||||
$programMap = @{}
|
||||
# Sozdayom spisok programm
|
||||
$programList = @()
|
||||
foreach ($file in $files) {
|
||||
$fileName = $file.name
|
||||
$programMap[$fileName] = @{
|
||||
Name = $fileName -replace '\.exe$|\.msi$', ''
|
||||
$programList += @{
|
||||
Name = ($fileName -replace '\.(exe|msi)$', '') -replace '\.', ' '
|
||||
File = $fileName
|
||||
Type = if ($fileName -match '\.msi$') { 'msi' } else { 'exe' }
|
||||
}
|
||||
}
|
||||
|
||||
# Avtomaticheski raspredelyaem programmy po kategoriyam
|
||||
$autoCategories = @{}
|
||||
$uncategorized = @()
|
||||
|
||||
foreach ($prog in $programMap.Values) {
|
||||
$assigned = $false
|
||||
foreach ($cat in $categories.Keys) {
|
||||
foreach ($keyword in $categories[$cat]) {
|
||||
if ($prog.Name -match [regex]::Escape($keyword)) {
|
||||
if (-not $autoCategories.ContainsKey($cat)) {
|
||||
$autoCategories[$cat] = @()
|
||||
}
|
||||
$autoCategories[$cat] += $prog
|
||||
$assigned = $true
|
||||
break
|
||||
}
|
||||
}
|
||||
if ($assigned) { break }
|
||||
}
|
||||
if (-not $assigned) {
|
||||
$uncategorized += $prog
|
||||
}
|
||||
}
|
||||
|
||||
if ($uncategorized.Count -gt 0) {
|
||||
$autoCategories["Other"] = $uncategorized
|
||||
}
|
||||
# Sortiruem po imeni
|
||||
$programList = $programList | Sort-Object Name
|
||||
|
||||
# ============================================================
|
||||
# 3. VYBOR PROGRAMM
|
||||
|
|
@ -119,24 +80,21 @@ Write-Host "[3/4] Program selection..." -ForegroundColor Yellow
|
|||
|
||||
Write-Host "`nAvailable programs in repo:`n" -ForegroundColor Cyan
|
||||
|
||||
$i = 1
|
||||
$progMap = @{}
|
||||
$allPrograms = @()
|
||||
$i = 1
|
||||
|
||||
foreach ($cat in ($autoCategories.Keys | Sort-Object)) {
|
||||
Write-Host "`n [$cat]" -ForegroundColor Magenta
|
||||
foreach ($prog in $autoCategories[$cat]) {
|
||||
Write-Host " $i - $($prog.Name)" -ForegroundColor Yellow
|
||||
foreach ($prog in $programList) {
|
||||
Write-Host (" {0,2} - {1}" -f $i, $prog.Name) -ForegroundColor Yellow
|
||||
$progMap[$i] = $prog
|
||||
$allPrograms += $prog
|
||||
$i++
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "`n a - ALL programs" -ForegroundColor Green
|
||||
Write-Host " 0 - Cancel`n" -ForegroundColor Gray
|
||||
|
||||
$choice = Read-Host "Select programs (1,2,3 or a)"
|
||||
$choice = Read-Host "Select (numbers separated by space, or a)"
|
||||
|
||||
if ($choice -eq "0") {
|
||||
Write-Host "Canceled" -ForegroundColor Red
|
||||
|
|
@ -147,10 +105,9 @@ $selectedPrograms = @()
|
|||
if ($choice -eq "a") {
|
||||
$selectedPrograms = $allPrograms
|
||||
} else {
|
||||
foreach ($num in $choice.Split(',')) {
|
||||
$num = $num.Trim()
|
||||
if ($progMap[$num]) {
|
||||
$selectedPrograms += $progMap[$num]
|
||||
foreach ($num in ($choice -split '\s+') | Where-Object { $_ -match '^\d+$' }) {
|
||||
if ($progMap[[int]$num]) {
|
||||
$selectedPrograms += $progMap[[int]$num]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue