Skip to content

Commit

Permalink
Add sorting to error messages
Browse files Browse the repository at this point in the history
Thanks @og-mrk for the suggestion and the patch (even though I applied it myself)
  • Loading branch information
CodingWonders committed Oct 4, 2024
1 parent 9e920ab commit 9909797
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions functions/private/Invoke-WinUtilMicroWin-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ class ErroredPackage {
}
}

class ErroredPackageComparer : System.Collections.Generic.IComparer[ErroredPackage] {
[string]$PropertyName
[bool]$Descending = $false

ErroredPackageComparer([string]$property) {
$this.PropertyName = $property
}

ErroredPackageComparer([string]$property, [bool]$descending) {
$this.PropertyName = $property
$this.Descending = $descending
}

[int]Compare([ErroredPackage]$a, [ErroredPackage]$b) {
if ($a.$($this.PropertyName) -eq $b.$($this.PropertyName)) { $res = 0 }
elseif ($a.$($this.PropertyName) -lt $b.$($this.PropertyName)) { $res = -1 }
else { $res = 1 }

if ($this.Descending) { $res *= -1 }

return $res
}
}

function Get-FidoLangFromCulture {

param (
Expand Down Expand Up @@ -200,6 +224,12 @@ function Remove-Packages {
if ($erroredPackages.Count -gt 0)
{
$erroredPackages
$ErrorMessageComparer = [ErroredPackageComparer]::new("ErrorMessage")
$erroredPackages.Sort($ErrorMessageComparer)
foreach ($erroredPackage in $erroredPackages) {
Write-Host "Failed to remove Package $($erroredPackage.PackageName) due to $($erroredPackage.ErrorMessage)" -NoNewline
}
#$erroredPackages
}
}
} catch {
Expand Down

0 comments on commit 9909797

Please sign in to comment.