support force post install
This commit is contained in:
38
bin/main.ps1
38
bin/main.ps1
@@ -19,6 +19,7 @@ if (-not (Test-Path $jsonPath)) {
|
||||
Write-Host "Reading configurations..." -ForegroundColor Cyan
|
||||
# 使用 UTF8 读取防止中文乱码
|
||||
$apps = Get-Content $jsonPath -Encoding UTF8 | ConvertFrom-Json
|
||||
$forcePostInstall = $false
|
||||
|
||||
# === 2.1 加载外部开关配置 (selection.ini) ===
|
||||
# 尝试查找根目录下的 selection.ini (位于 bin 的上一级)
|
||||
@@ -27,20 +28,43 @@ $selectionPath = Join-Path (Split-Path $PSScriptRoot -Parent) "selection.ini"
|
||||
if (Test-Path $selectionPath) {
|
||||
Write-Host "Loading selection overrides from selection.ini..." -ForegroundColor Cyan
|
||||
try {
|
||||
# 读取所有行,过滤掉注释和空行
|
||||
$iniLines = Get-Content $selectionPath -Encoding UTF8 | Where-Object { $_ -match "=" -and $_ -notmatch "^;" -and $_ -notmatch "^\[" }
|
||||
|
||||
# 创建一个哈希表来存储 INI 配置
|
||||
# 创建哈希表分别存储 App 开关和全局选项
|
||||
$selectionConfig = @{}
|
||||
foreach ($line in $iniLines) {
|
||||
$optionsConfig = @{}
|
||||
$currentSection = ""
|
||||
|
||||
foreach ($line in (Get-Content $selectionPath -Encoding UTF8)) {
|
||||
$line = $line.Trim()
|
||||
if ([string]::IsNullOrWhiteSpace($line) -or $line.StartsWith(";") -or $line.StartsWith("#")) {
|
||||
continue
|
||||
}
|
||||
|
||||
if ($line -match '^\[(.+)\]$') {
|
||||
$currentSection = $matches[1].Trim()
|
||||
continue
|
||||
}
|
||||
|
||||
if ($line -notmatch "=") {
|
||||
continue
|
||||
}
|
||||
|
||||
# 按第一个等号分割,限制分割次数为 2
|
||||
$parts = $line -split '=', 2
|
||||
if ($parts.Count -eq 2) {
|
||||
$key = $parts[0].Trim()
|
||||
$value = $parts[1].Trim()
|
||||
|
||||
if ($currentSection -eq "Options") {
|
||||
$optionsConfig[$key] = $value
|
||||
} else {
|
||||
$selectionConfig[$key] = $value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($optionsConfig.ContainsKey("ForcePostInstall")) {
|
||||
$forcePostInstall = $optionsConfig["ForcePostInstall"] -eq "1"
|
||||
}
|
||||
|
||||
# 应用配置
|
||||
foreach ($app in $apps) {
|
||||
@@ -153,8 +177,12 @@ foreach ($app in $apps) {
|
||||
if ($exitCode -eq 0) {
|
||||
Write-Host "[Success]" -ForegroundColor Green
|
||||
} elseif ($exitCode -eq -1978335189) {
|
||||
if ($forcePostInstall) {
|
||||
Write-Host "[Skip] Already installed, running PostInstall..." -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host "[Skip] Already installed" -ForegroundColor Yellow
|
||||
continue # 已经安装的为了避免覆盖配置,也就不配置了
|
||||
}
|
||||
} else {
|
||||
Write-Error "[Fail] Error code: $exitCode"
|
||||
continue # 安装失败则跳过后续配置
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# yaml-language-server: $schema=https://aka.ms/winget-manifest.singleton.1.12.0.schema.json
|
||||
|
||||
PackageIdentifier: Google.Chrome
|
||||
PackageVersion: 146.0.7680.178
|
||||
PackageVersion: 148.0.7778.168
|
||||
PackageLocale: zh-CN
|
||||
Publisher: Google LLC
|
||||
PackageName: Google Chrome
|
||||
@@ -29,11 +29,11 @@ FileExtensions:
|
||||
ElevationRequirement: elevatesSelf
|
||||
Installers:
|
||||
- Architecture: x64
|
||||
InstallerUrl: https://dl.volan.top/winget-repo/manifests/g/Google/Chrome/146.0.7680.178/googlechromestandaloneenterprise64.msi
|
||||
InstallerSha256: DB9C5E0519C83FBECFE5E5AC1FAC0FE44C15B3943C9611D52759FE474436D31E
|
||||
ProductCode: '{6939CB9C-515D-372C-AF4A-BA8D6A40CC4B}'
|
||||
InstallerUrl: https://dl.volan.top/winget-repo/manifests/g/Google/Chrome/148.0.7778.168/googlechromestandaloneenterprise64.msi
|
||||
InstallerSha256: A42AEA4FBC79A1B2C5872FAA39414567AB9D79473626D2B4C58ED6A4FFA60386
|
||||
ProductCode: '{AB53BB27-D54C-3E8F-8EFF-C3B1068B5BA5}'
|
||||
AppsAndFeaturesEntries:
|
||||
- ProductCode: '{6939CB9C-515D-372C-AF4A-BA8D6A40CC4B}'
|
||||
- ProductCode: '{042C29DE-2EAE-34E1-A978-C2BE5AB65557}'
|
||||
UpgradeCode: '{C1DFDF69-5945-32F2-A35E-EE94C99C7CF4}'
|
||||
ManifestType: singleton
|
||||
ManifestVersion: 1.12.0
|
||||
@@ -1,3 +1,8 @@
|
||||
[Options]
|
||||
# 设为 0 表示已安装的软件不会进行设置
|
||||
# 设为 1 表示已安装的软件也会进行设置
|
||||
ForcePostInstall=0
|
||||
|
||||
[Apps]
|
||||
7-Zip=1
|
||||
Google Chrome=1
|
||||
|
||||
Reference in New Issue
Block a user