support individual selection
This commit is contained in:
21
bin/main.ps1
21
bin/main.ps1
@@ -20,6 +20,27 @@ Write-Host "Reading configurations..." -ForegroundColor Cyan
|
|||||||
# 使用 UTF8 读取防止中文乱码
|
# 使用 UTF8 读取防止中文乱码
|
||||||
$apps = Get-Content $jsonPath -Encoding UTF8 | ConvertFrom-Json
|
$apps = Get-Content $jsonPath -Encoding UTF8 | ConvertFrom-Json
|
||||||
|
|
||||||
|
# === 2.1 加载外部开关配置 (selection.json) ===
|
||||||
|
# 尝试查找根目录下的 selection.json (位于 bin 的上一级)
|
||||||
|
$selectionPath = Join-Path (Split-Path $PSScriptRoot -Parent) "selection.json"
|
||||||
|
|
||||||
|
if (Test-Path $selectionPath) {
|
||||||
|
Write-Host "Loading selection overrides from selection.json..." -ForegroundColor Cyan
|
||||||
|
try {
|
||||||
|
$selectionConfig = Get-Content $selectionPath -Encoding UTF8 | ConvertFrom-Json
|
||||||
|
|
||||||
|
foreach ($app in $apps) {
|
||||||
|
# 检查 selection.json 中是否有对应的 Key (按 Name 匹配)
|
||||||
|
if ($null -ne $selectionConfig.($app.Name)) {
|
||||||
|
# 直接赋值 1 或 0
|
||||||
|
$app.Enabled = $selectionConfig.($app.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Warning "Error reading selection.json: $_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# === 3. 主循环 ===
|
# === 3. 主循环 ===
|
||||||
foreach ($app in $apps) {
|
foreach ($app in $apps) {
|
||||||
if ($app.Enabled -ne 1) {
|
if ($app.Enabled -ne 1) {
|
||||||
|
|||||||
12
selection.json
Normal file
12
selection.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"7-Zip": 1,
|
||||||
|
"Google Chrome": 1,
|
||||||
|
"OpenOffice": 1,
|
||||||
|
"Microsoft Teams": 1,
|
||||||
|
"KeePassXC": 1,
|
||||||
|
"VeraCrypt": 1,
|
||||||
|
"File Shredder": 1,
|
||||||
|
"VLC": 1,
|
||||||
|
"Adobe Acrobat Reader": 0,
|
||||||
|
"System Optimize": 1
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user