change json to ini
This commit is contained in:
33
bin/main.ps1
33
bin/main.ps1
@@ -20,24 +20,37 @@ 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) ===
|
# === 2.1 加载外部开关配置 (selection.ini) ===
|
||||||
# 尝试查找根目录下的 selection.json (位于 bin 的上一级)
|
# 尝试查找根目录下的 selection.ini (位于 bin 的上一级)
|
||||||
$selectionPath = Join-Path (Split-Path $PSScriptRoot -Parent) "selection.json"
|
$selectionPath = Join-Path (Split-Path $PSScriptRoot -Parent) "selection.ini"
|
||||||
|
|
||||||
if (Test-Path $selectionPath) {
|
if (Test-Path $selectionPath) {
|
||||||
Write-Host "Loading selection overrides from selection.json..." -ForegroundColor Cyan
|
Write-Host "Loading selection overrides from selection.ini..." -ForegroundColor Cyan
|
||||||
try {
|
try {
|
||||||
$selectionConfig = Get-Content $selectionPath -Encoding UTF8 | ConvertFrom-Json
|
# 读取所有行,过滤掉注释和空行
|
||||||
|
$iniLines = Get-Content $selectionPath -Encoding UTF8 | Where-Object { $_ -match "=" -and $_ -notmatch "^;" -and $_ -notmatch "^\[" }
|
||||||
|
|
||||||
|
# 创建一个哈希表来存储 INI 配置
|
||||||
|
$selectionConfig = @{}
|
||||||
|
foreach ($line in $iniLines) {
|
||||||
|
# 按第一个等号分割,限制分割次数为 2
|
||||||
|
$parts = $line -split '=', 2
|
||||||
|
if ($parts.Count -eq 2) {
|
||||||
|
$key = $parts[0].Trim()
|
||||||
|
$value = $parts[1].Trim()
|
||||||
|
$selectionConfig[$key] = $value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 应用配置
|
||||||
foreach ($app in $apps) {
|
foreach ($app in $apps) {
|
||||||
# 检查 selection.json 中是否有对应的 Key (按 Name 匹配)
|
if ($selectionConfig.ContainsKey($app.Name)) {
|
||||||
if ($null -ne $selectionConfig.($app.Name)) {
|
# 转换为整数 1 或 0
|
||||||
# 直接赋值 1 或 0
|
$app.Enabled = [int]$selectionConfig[$app.Name]
|
||||||
$app.Enabled = $selectionConfig.($app.Name)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Warning "Error reading selection.json: $_"
|
Write-Warning "Error reading selection.ini: $_"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
selection.ini
Normal file
12
selection.ini
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[Apps]
|
||||||
|
7-Zip=1
|
||||||
|
Google Chrome=1
|
||||||
|
OpenOffice=1
|
||||||
|
Microsoft Teams=1
|
||||||
|
KeePassXC=1
|
||||||
|
VeraCrypt=1
|
||||||
|
File Shredder=1
|
||||||
|
VLC=1
|
||||||
|
Revo Uninstaller=1
|
||||||
|
Adobe Acrobat Reader=0
|
||||||
|
System Optimize=1
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"7-Zip": 1,
|
|
||||||
"Google Chrome": 1,
|
|
||||||
"OpenOffice": 1,
|
|
||||||
"Microsoft Teams": 1,
|
|
||||||
"KeePassXC": 1,
|
|
||||||
"VeraCrypt": 1,
|
|
||||||
"File Shredder": 1,
|
|
||||||
"VLC": 1,
|
|
||||||
"Revo Uninstaller": 1,
|
|
||||||
"Adobe Acrobat Reader": 0,
|
|
||||||
"System Optimize": 1
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user