Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sorting of Errored Packages by using 'Sort-Object' instead of 'IComparer' approach #2

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions functions/private/Invoke-WinUtilMicroWin-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,6 @@ 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 @@ -223,8 +199,7 @@ function Remove-Packages {
Write-Host "$failedCount package(s) could not be removed. Your image will still work fine, however. Below is information on what packages failed to be removed and why."
if ($erroredPackages.Count -gt 0)
{
$ErrorMessageComparer = [ErroredPackageComparer]::new("ErrorMessage")
$erroredPackages.Sort($ErrorMessageComparer)
$erroredPackages = $erroredPackages | Sort-Object -Property ErrorMessage

$previousErroredPackage = $erroredPackages[0]
$counter = 0
Expand Down
Loading