fix manifest temp msi locked
This commit is contained in:
31
bin/main.ps1
31
bin/main.ps1
@@ -21,6 +21,29 @@ Write-Host "Reading configurations..." -ForegroundColor Cyan
|
|||||||
$apps = Get-Content $jsonPath -Encoding UTF8 | ConvertFrom-Json
|
$apps = Get-Content $jsonPath -Encoding UTF8 | ConvertFrom-Json
|
||||||
$forcePostInstall = $false
|
$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) ===
|
# === 2.1 加载外部开关配置 (selection.ini) ===
|
||||||
# 尝试查找根目录下的 selection.ini (位于 bin 的上一级)
|
# 尝试查找根目录下的 selection.ini (位于 bin 的上一级)
|
||||||
$selectionPath = Join-Path (Split-Path $PSScriptRoot -Parent) "selection.ini"
|
$selectionPath = Join-Path (Split-Path $PSScriptRoot -Parent) "selection.ini"
|
||||||
@@ -167,6 +190,14 @@ foreach ($app in $apps) {
|
|||||||
try {
|
try {
|
||||||
& winget @wingetArgs
|
& winget @wingetArgs
|
||||||
$exitCode = $LASTEXITCODE
|
$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 {
|
} finally {
|
||||||
if ($manifestTempDir -and (Test-Path $manifestTempDir)) {
|
if ($manifestTempDir -and (Test-Path $manifestTempDir)) {
|
||||||
Remove-Item -LiteralPath $manifestTempDir -Recurse -Force
|
Remove-Item -LiteralPath $manifestTempDir -Recurse -Force
|
||||||
|
|||||||
Reference in New Issue
Block a user