fix manifest temp msi locked

This commit is contained in:
2026-05-20 20:25:29 -04:00
parent e9aa6024ff
commit 39c0420835

View File

@@ -21,6 +21,29 @@ Write-Host "Reading configurations..." -ForegroundColor Cyan
$apps = Get-Content $jsonPath -Encoding UTF8 | ConvertFrom-Json
$forcePostInstall = $false
function Unblock-WinGetCache {
param(
[Parameter(Mandatory=$true)] [string]$PackageId
)
$wingetCacheRoot = Join-Path $env:TEMP "WinGet"
if (-not (Test-Path $wingetCacheRoot)) {
return
}
$cacheItems = Get-ChildItem -Path $wingetCacheRoot -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -like "*\$PackageId.*" }
foreach ($item in $cacheItems) {
try {
Unblock-File -LiteralPath $item.FullName -ErrorAction Stop
Write-Host "-> Unblocked cached installer: $($item.FullName)" -ForegroundColor DarkGray
} catch {
Write-Warning "Failed to unblock cached installer: $($item.FullName), $_"
}
}
}
# === 2.1 加载外部开关配置 (selection.ini) ===
# 尝试查找根目录下的 selection.ini (位于 bin 的上一级)
$selectionPath = Join-Path (Split-Path $PSScriptRoot -Parent) "selection.ini"
@@ -167,6 +190,14 @@ foreach ($app in $apps) {
try {
& winget @wingetArgs
$exitCode = $LASTEXITCODE
if ($exitCode -eq -1978335231 -and -not [string]::IsNullOrWhiteSpace($app.Manifest)) {
Write-Warning "winget failed after download. Unblocking cached installer and retrying once..."
Unblock-WinGetCache -PackageId $app.Id
& winget @wingetArgs
$exitCode = $LASTEXITCODE
}
} finally {
if ($manifestTempDir -and (Test-Path $manifestTempDir)) {
Remove-Item -LiteralPath $manifestTempDir -Recurse -Force