support custom manifest

This commit is contained in:
2026-05-15 19:21:54 -04:00
parent 11cfa1e823
commit 8b8d109ba6

View File

@@ -54,6 +54,11 @@ if (Test-Path $selectionPath) {
}
}
# === 2.2 启用本地 Manifest 安装 ===
# winget install --manifest 需要先启用 LocalManifestFiles重复执行不会影响后续安装。
Write-Host "Enabling winget local manifest support..." -ForegroundColor Cyan
winget settings --enable LocalManifestFiles
# === 3. 主循环 ===
foreach ($app in $apps) {
if ($app.Enabled -ne 1) {
@@ -70,31 +75,78 @@ foreach ($app in $apps) {
Write-Host "[System Config] Skipping install..." -ForegroundColor Magenta
} else {
# --- 步骤 A: Winget 安装 ---
$wingetArgs = @(
"install",
"--id", $app.Id,
"-e",
"--silent",
"--accept-package-agreements",
"--accept-source-agreements",
"--disable-interactivity"
# "--scope", "machine"
)
$manifestPath = $null
$manifestTempDir = $null
# [版本检查逻辑]
# 检查 Version 是否存在且不为空字符串
if (-not [string]::IsNullOrWhiteSpace($app.Version)) {
Write-Host "-> Version: $($app.Version)"
$wingetArgs += "-v"
$wingetArgs += $app.Version
if (-not [string]::IsNullOrWhiteSpace($app.Manifest)) {
Write-Host "-> Manifest: $($app.Manifest)"
if ($app.Manifest -match '^https?://') {
$manifestTempDir = Join-Path $env:TEMP ("winit-helper-manifest-" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $manifestTempDir -Force | Out-Null
$manifestFileName = [System.IO.Path]::GetFileName(([uri]$app.Manifest).AbsolutePath)
if ([string]::IsNullOrWhiteSpace($manifestFileName)) {
$manifestFileName = "$($app.Id).yaml"
}
$manifestPath = Join-Path $manifestTempDir $manifestFileName
Write-Host "-> Downloading custom manifest..."
Invoke-WebRequest -Uri $app.Manifest -OutFile $manifestPath
} else {
$manifestPath = $app.Manifest
if (-not [System.IO.Path]::IsPathRooted($manifestPath)) {
$manifestPath = Join-Path $PSScriptRoot $manifestPath
}
if (-not (Test-Path $manifestPath)) {
Write-Error "Cannot find manifest: $manifestPath"
continue
}
}
$wingetArgs = @(
"install",
"--manifest", $manifestPath,
"--silent",
"--accept-package-agreements",
"--accept-source-agreements",
"--disable-interactivity"
# "--scope", "machine"
)
} else {
Write-Host "-> Version: latest"
$wingetArgs = @(
"install",
"--id", $app.Id,
"-e",
"--silent",
"--accept-package-agreements",
"--accept-source-agreements",
"--disable-interactivity"
# "--scope", "machine"
)
# [版本检查逻辑]
# 检查 Version 是否存在且不为空字符串
if (-not [string]::IsNullOrWhiteSpace($app.Version)) {
Write-Host "-> Version: $($app.Version)"
$wingetArgs += "-v"
$wingetArgs += $app.Version
} else {
Write-Host "-> Version: latest"
}
}
Write-Host "-> Installing via winget..."
# 执行安装
$proc = Start-Process -FilePath "winget" -ArgumentList $wingetArgs -Wait -PassThru -NoNewWindow
try {
$proc = Start-Process -FilePath "winget" -ArgumentList $wingetArgs -Wait -PassThru -NoNewWindow
} finally {
if ($manifestTempDir -and (Test-Path $manifestTempDir)) {
Remove-Item -LiteralPath $manifestTempDir -Recurse -Force
}
}
# 检查安装结果 (0=成功, -1978335189=已安装)
if ($proc.ExitCode -eq 0) {