-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-PackageConfig.ps1
More file actions
63 lines (53 loc) · 2.13 KB
/
Copy pathUpdate-PackageConfig.ps1
File metadata and controls
63 lines (53 loc) · 2.13 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
# 配置檔案更新工具
# 確保所有套件都有預設的 selected 屬性設為 false
param(
[string]$ConfigPath = "packages-config.json"
)
function Update-PackageConfig {
param([string]$Path)
if (-not (Test-Path $Path)) {
Write-Host "配置文件不存在:$Path" -ForegroundColor Red
return
}
try {
# 讀取配置文件
$configContent = Get-Content $Path -Raw -Encoding UTF8
$config = $configContent | ConvertFrom-Json
$updated = $false
# 檢查每個分類的套件
foreach ($categoryName in $config.packageCategories.PSObject.Properties.Name) {
$category = $config.packageCategories.$categoryName
foreach ($package in $category.packages) {
# 如果沒有 selected 屬性,添加並設為 false
if (-not ($package.PSObject.Properties.Name -contains "selected")) {
$package | Add-Member -MemberType NoteProperty -Name "selected" -Value $false
$updated = $true
Write-Host "為套件 $($package.name) 添加 selected 屬性" -ForegroundColor Yellow
}
}
}
if ($updated) {
# 儲存更新後的配置
$updatedJson = $config | ConvertTo-Json -Depth 10
Set-Content $Path -Value $updatedJson -Encoding UTF8
Write-Host "配置文件已更新:$Path" -ForegroundColor Green
} else {
Write-Host "配置文件無需更新" -ForegroundColor Green
}
}
catch {
Write-Host "更新配置文件時發生錯誤:$($_.Exception.Message)" -ForegroundColor Red
}
}
# 執行更新
# 取得腳本所在目錄 (相容於 ps2exe 編譯版本)
$scriptDir = if ($PSScriptRoot) {
$PSScriptRoot
} elseif ($MyInvocation.MyCommand.Path) {
Split-Path $MyInvocation.MyCommand.Path -Parent
} else {
Get-Location | Select-Object -ExpandProperty Path
}
$fullPath = Join-Path $scriptDir $ConfigPath
Write-Host "配置檔路徑: $fullPath" -ForegroundColor Gray
Update-PackageConfig -Path $fullPath