mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-04-01 17:12:09 +00:00
Hold errored packages in a list
Items are being added correctly, but I can't get that to show to the end-user. Perhaps a different approach will work
This commit is contained in:
parent
02a133bfa8
commit
2acdeea520
@ -25,6 +25,17 @@ function Test-CompatibleImage() {
|
||||
}
|
||||
}
|
||||
|
||||
class ErroredPackage {
|
||||
[string]$PackageName
|
||||
[string]$ErrorMessage
|
||||
ErroredPackage() { $this.Init(@{} )}
|
||||
# Constructor for packages that have errored out
|
||||
ErroredPackage([string]$pkgName, [string]$reason) {
|
||||
$this.PackageName = $pkgName
|
||||
$this.ErrorMessage = $reason
|
||||
}
|
||||
}
|
||||
|
||||
function Get-FidoLangFromCulture {
|
||||
|
||||
param (
|
||||
@ -168,14 +179,16 @@ function Remove-Packages {
|
||||
|
||||
$failedCount = 0
|
||||
|
||||
$erroredPackages = [System.Collections.Generic.List[ErroredPackage]]::new()
|
||||
|
||||
foreach ($pkg in $pkglist) {
|
||||
try {
|
||||
$status = "Removing $pkg"
|
||||
Write-Progress -Activity "Removing Packages" -Status $status -PercentComplete ($counter++/$pkglist.Count*100)
|
||||
Remove-WindowsPackage -Path "$scratchDir" -PackageName $pkg -NoRestart -ErrorAction SilentlyContinue
|
||||
} catch {
|
||||
# This can happen if the package that is being removed is a permanent one, like FodMetadata
|
||||
Write-Host "Could not remove OS package $($pkg)"
|
||||
# This can happen if the package that is being removed is a permanent one
|
||||
$erroredPackages.Add([ErroredPackage]::new($pkg, $_.Exception.Message))
|
||||
$failedCount += 1
|
||||
continue
|
||||
}
|
||||
@ -184,6 +197,10 @@ function Remove-Packages {
|
||||
if ($failedCount -gt 0)
|
||||
{
|
||||
Write-Host "Some packages could not be removed. Do not worry: your image will still work fine. This can happen if the package is permanent or has been superseded by a newer one."
|
||||
if ($erroredPackages.Count -gt 0)
|
||||
{
|
||||
$erroredPackages
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-Host "Unable to get information about the packages. MicroWin processing will continue, but packages will not be processed"
|
||||
|
Loading…
Reference in New Issue
Block a user