From 39c0420835cb36a7abe355faf41f8932c0744896 Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 20 May 2026 20:25:29 -0400 Subject: [PATCH] fix manifest temp msi locked --- bin/main.ps1 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bin/main.ps1 b/bin/main.ps1 index 253b4e9..3dd791a 100644 --- a/bin/main.ps1 +++ b/bin/main.ps1 @@ -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