From 7c554d02f581480c9b8c9203c30f307bb1319740 Mon Sep 17 00:00:00 2001 From: pointfeev Date: Sun, 6 Mar 2022 21:43:46 -0500 Subject: [PATCH] v3.2.0.4 - Fixed appid sorting --- CreamInstaller/Components/AppIdComparer.cs | 19 +++++++++++++++++++ CreamInstaller/CreamInstaller.csproj | 2 +- CreamInstaller/ProgramSelection.cs | 6 ++++-- CreamInstaller/SelectForm.cs | 14 +------------- 4 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 CreamInstaller/Components/AppIdComparer.cs diff --git a/CreamInstaller/Components/AppIdComparer.cs b/CreamInstaller/Components/AppIdComparer.cs new file mode 100644 index 0000000..260bcb5 --- /dev/null +++ b/CreamInstaller/Components/AppIdComparer.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; + +namespace CreamInstaller.Components; + +internal class AppIdComparer : IComparer +{ + private static AppIdComparer comparer; + public static AppIdComparer Comparer => comparer ??= new AppIdComparer(); + + public int Compare(string a, string b) => + a == "ParadoxLauncher" ? -1 + : b == "ParadoxLauncher" ? 1 + : !int.TryParse(a, out _) && !int.TryParse(b, out _) ? string.Compare(a, b) + : !int.TryParse(a, out int A) ? 1 + : !int.TryParse(b, out int B) ? -1 + : A > B ? 1 + : A < B ? -1 + : 0; +} diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index 3a6510d..00a4727 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -5,7 +5,7 @@ True Resources\ini.ico true - 3.2.0.3 + 3.2.0.4 Resources\ini.ico diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index 0c88f12..c39f0f0 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using CreamInstaller.Components; + namespace CreamInstaller; internal enum DlcType @@ -31,8 +33,8 @@ internal class ProgramSelection internal bool IsSteam = false; - internal readonly SortedList AllDlc = new(); - internal readonly SortedList SelectedDlc = new(); + internal readonly SortedList AllDlc = new(AppIdComparer.Comparer); + internal readonly SortedList SelectedDlc = new(AppIdComparer.Comparer); internal readonly List>> ExtraDlc = new(); // for Paradox Launcher internal bool AreDllsLocked diff --git a/CreamInstaller/SelectForm.cs b/CreamInstaller/SelectForm.cs index f36a0dd..eedb442 100644 --- a/CreamInstaller/SelectForm.cs +++ b/CreamInstaller/SelectForm.cs @@ -503,19 +503,7 @@ internal partial class SelectForm : CustomForm private class TreeNodeSorter : IComparer { - public int Compare(object a, object b) - { - string aId = (a as TreeNode).Name; - string bId = (b as TreeNode).Name; - return aId == "ParadoxLauncher" ? -1 - : bId == "ParadoxLauncher" ? 1 - : !int.TryParse(aId, out _) && !int.TryParse(bId, out _) ? string.Compare(aId, bId) - : !int.TryParse(aId, out int A) ? 1 - : !int.TryParse(bId, out int B) ? -1 - : A > B ? 1 - : A < B ? -1 - : 0; - } + public int Compare(object a, object b) => AppIdComparer.Comparer.Compare((a as TreeNode).Name, (b as TreeNode).Name); } private void ShowProgressBar()