diff --git a/CreamInstaller/Components/CustomTreeView.cs b/CreamInstaller/Components/CustomTreeView.cs index ff0e5aa..f4d6423 100644 --- a/CreamInstaller/Components/CustomTreeView.cs +++ b/CreamInstaller/Components/CustomTreeView.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Drawing; using System.Windows.Forms; @@ -19,7 +18,7 @@ internal class CustomTreeView : TreeView { DrawMode = TreeViewDrawMode.OwnerDrawAll; DrawNode += new DrawTreeNodeEventHandler(DrawTreeNode); - TreeViewNodeSorter = PlatformIdComparer.TreeNodes; + TreeViewNodeSorter = PlatformIdComparer.NodeName; } private void DrawTreeNode(object sender, DrawTreeNodeEventArgs e) diff --git a/CreamInstaller/Components/PlatformIdComparer.cs b/CreamInstaller/Components/PlatformIdComparer.cs index 1b0792a..d27e955 100644 --- a/CreamInstaller/Components/PlatformIdComparer.cs +++ b/CreamInstaller/Components/PlatformIdComparer.cs @@ -7,14 +7,20 @@ namespace CreamInstaller.Components; internal static class PlatformIdComparer { - private static PlatformIdStringComparer stringComparer; - internal static PlatformIdStringComparer Strings => stringComparer ??= new(); + private static StringComparer stringComparer; + internal static StringComparer String => stringComparer ??= new(); - private static PlatformIdNodeComparer nodeComparer; - internal static PlatformIdNodeComparer TreeNodes => nodeComparer ??= new(); + private static NodeComparer nodeComparer; + internal static NodeComparer Node => nodeComparer ??= new(); + + private static NodeNameComparer nodeNameComparer; + internal static NodeNameComparer NodeName => nodeNameComparer ??= new(); + + private static NodeTextComparer nodeTextComparer; + internal static NodeTextComparer NodeText => nodeTextComparer ??= new(); } -internal class PlatformIdStringComparer : IComparer +internal class StringComparer : IComparer { public int Compare(string a, string b) => !int.TryParse(a, out _) && !int.TryParse(b, out _) ? string.Compare(a, b, StringComparison.Ordinal) @@ -22,12 +28,25 @@ internal class PlatformIdStringComparer : IComparer : A > B ? 1 : A < B ? -1 : 0; } -internal class PlatformIdNodeComparer : IComparer +internal class NodeComparer : IComparer +{ + public int Compare(TreeNode a, TreeNode b) => + a.Tag is not Platform A ? 1 : b.Tag is not Platform B ? -1 + : A > B ? 1 : A < B ? -1 : 0; +} + +internal class NodeNameComparer : IComparer { public int Compare(object a, object b) => a is not TreeNode A ? 1 : b is not TreeNode B ? -1 - : A.Tag is not Platform pA ? 1 : B.Tag is not Platform pB ? -1 - : pA > pB ? 1 : pA < pB ? -1 - : PlatformIdComparer.Strings.Compare(A.Name, B.Name); - + : PlatformIdComparer.Node.Compare(A, B) is int c && c != 0 ? c + : PlatformIdComparer.String.Compare(A.Name, B.Name); +} + +internal class NodeTextComparer : IComparer +{ + public int Compare(object a, object b) => + a is not TreeNode A ? 1 : b is not TreeNode B ? -1 + : PlatformIdComparer.Node.Compare(A, B) is int c && c != 0 ? c + : PlatformIdComparer.String.Compare(A.Text, B.Text); } \ No newline at end of file diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index fef903e..d4fadd0 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -5,7 +5,7 @@ True Resources\ini.ico true - 3.6.1.0 + 3.6.1.1 Resources\ini.ico LICENSE 2021, pointfeev (https://github.com/pointfeev) diff --git a/CreamInstaller/Forms/SelectDialogForm.cs b/CreamInstaller/Forms/SelectDialogForm.cs index 1bf7251..295c1cb 100644 --- a/CreamInstaller/Forms/SelectDialogForm.cs +++ b/CreamInstaller/Forms/SelectDialogForm.cs @@ -2,17 +2,12 @@ using CreamInstaller.Utility; using System; -using System.Collections; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; -using Windows.Foundation.Metadata; - -using static CreamInstaller.Components.CustomTreeView; - namespace CreamInstaller; internal partial class SelectDialogForm : CustomForm @@ -77,7 +72,8 @@ internal partial class SelectDialogForm : CustomForm ? Program.ApplicationNameShort : Program.ApplicationName; - private void OnSortCheckBoxChanged(object sender, EventArgs e) => selectionTreeView.TreeViewNodeSorter = PlatformIdComparer.TreeNodes; + private void OnSortCheckBoxChanged(object sender, EventArgs e) => selectionTreeView.TreeViewNodeSorter + = sortCheckBox.Checked ? PlatformIdComparer.NodeText : PlatformIdComparer.NodeName; private void OnAllCheckBoxChanged(object sender, EventArgs e) { diff --git a/CreamInstaller/Forms/SelectForm.Designer.cs b/CreamInstaller/Forms/SelectForm.Designer.cs index 4920dec..3910b75 100644 --- a/CreamInstaller/Forms/SelectForm.Designer.cs +++ b/CreamInstaller/Forms/SelectForm.Designer.cs @@ -48,6 +48,7 @@ namespace CreamInstaller this.uninstallButton = new System.Windows.Forms.Button(); this.progressLabelGames = new System.Windows.Forms.Label(); this.progressLabelDLCs = new System.Windows.Forms.Label(); + this.sortCheckBox = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); this.flowLayoutPanel1.SuspendLayout(); this.flowLayoutPanel2.SuspendLayout(); @@ -56,11 +57,14 @@ namespace CreamInstaller // installButton // this.installButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.installButton.AutoSize = true; + this.installButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.installButton.Enabled = false; this.installButton.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.installButton.Location = new System.Drawing.Point(422, 326); + this.installButton.Location = new System.Drawing.Point(420, 325); this.installButton.Name = "installButton"; - this.installButton.Size = new System.Drawing.Size(150, 23); + this.installButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0); + this.installButton.Size = new System.Drawing.Size(149, 24); this.installButton.TabIndex = 10003; this.installButton.Text = "Generate and Install"; this.installButton.UseVisualStyleBackColor = true; @@ -69,10 +73,13 @@ namespace CreamInstaller // cancelButton // this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.cancelButton.AutoSize = true; + this.cancelButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.cancelButton.Location = new System.Drawing.Point(12, 326); + this.cancelButton.Location = new System.Drawing.Point(12, 325); this.cancelButton.Name = "cancelButton"; - this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0); + this.cancelButton.Size = new System.Drawing.Size(81, 24); this.cancelButton.TabIndex = 10000; this.cancelButton.Text = "Cancel"; this.cancelButton.UseVisualStyleBackColor = true; @@ -97,7 +104,7 @@ namespace CreamInstaller this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System; this.groupBox1.Location = new System.Drawing.Point(12, 12); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(560, 240); + this.groupBox1.Size = new System.Drawing.Size(560, 239); this.groupBox1.TabIndex = 8; this.groupBox1.TabStop = false; this.groupBox1.Text = "Programs / Games"; @@ -107,7 +114,7 @@ namespace CreamInstaller this.noneFoundLabel.Dock = System.Windows.Forms.DockStyle.Fill; this.noneFoundLabel.Location = new System.Drawing.Point(3, 19); this.noneFoundLabel.Name = "noneFoundLabel"; - this.noneFoundLabel.Size = new System.Drawing.Size(554, 218); + this.noneFoundLabel.Size = new System.Drawing.Size(554, 217); this.noneFoundLabel.TabIndex = 1002; this.noneFoundLabel.Text = "No applicable programs nor games were found on your computer!"; this.noneFoundLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -167,7 +174,7 @@ namespace CreamInstaller this.selectionTreeView.FullRowSelect = true; this.selectionTreeView.Location = new System.Drawing.Point(3, 19); this.selectionTreeView.Name = "selectionTreeView"; - this.selectionTreeView.Size = new System.Drawing.Size(554, 218); + this.selectionTreeView.Size = new System.Drawing.Size(554, 217); this.selectionTreeView.Sorted = true; this.selectionTreeView.TabIndex = 1001; // @@ -202,7 +209,7 @@ namespace CreamInstaller // this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.progressBar.Location = new System.Drawing.Point(12, 297); + this.progressBar.Location = new System.Drawing.Point(12, 296); this.progressBar.Name = "progressBar"; this.progressBar.Size = new System.Drawing.Size(560, 23); this.progressBar.TabIndex = 9; @@ -211,7 +218,7 @@ namespace CreamInstaller // this.progressLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.progressLabel.Location = new System.Drawing.Point(12, 255); + this.progressLabel.Location = new System.Drawing.Point(12, 254); this.progressLabel.Name = "progressLabel"; this.progressLabel.Size = new System.Drawing.Size(560, 15); this.progressLabel.TabIndex = 10; @@ -220,24 +227,30 @@ namespace CreamInstaller // scanButton // this.scanButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.scanButton.AutoSize = true; + this.scanButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.scanButton.Enabled = false; this.scanButton.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.scanButton.Location = new System.Drawing.Point(140, 326); + this.scanButton.Location = new System.Drawing.Point(235, 325); this.scanButton.Name = "scanButton"; - this.scanButton.Size = new System.Drawing.Size(180, 23); + this.scanButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0); + this.scanButton.Size = new System.Drawing.Size(82, 24); this.scanButton.TabIndex = 10001; - this.scanButton.Text = "Rescan Programs / Games"; + this.scanButton.Text = "Rescan"; this.scanButton.UseVisualStyleBackColor = true; this.scanButton.Click += new System.EventHandler(this.OnScan); // // uninstallButton // this.uninstallButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.uninstallButton.AutoSize = true; + this.uninstallButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.uninstallButton.Enabled = false; this.uninstallButton.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.uninstallButton.Location = new System.Drawing.Point(326, 326); + this.uninstallButton.Location = new System.Drawing.Point(323, 325); this.uninstallButton.Name = "uninstallButton"; - this.uninstallButton.Size = new System.Drawing.Size(90, 23); + this.uninstallButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0); + this.uninstallButton.Size = new System.Drawing.Size(91, 24); this.uninstallButton.TabIndex = 10002; this.uninstallButton.Text = "Uninstall"; this.uninstallButton.UseVisualStyleBackColor = true; @@ -248,7 +261,7 @@ namespace CreamInstaller this.progressLabelGames.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.progressLabelGames.Font = new System.Drawing.Font("Segoe UI", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.progressLabelGames.Location = new System.Drawing.Point(12, 270); + this.progressLabelGames.Location = new System.Drawing.Point(12, 269); this.progressLabelGames.Name = "progressLabelGames"; this.progressLabelGames.Size = new System.Drawing.Size(560, 12); this.progressLabelGames.TabIndex = 11; @@ -259,12 +272,25 @@ namespace CreamInstaller this.progressLabelDLCs.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.progressLabelDLCs.Font = new System.Drawing.Font("Segoe UI", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.progressLabelDLCs.Location = new System.Drawing.Point(12, 282); + this.progressLabelDLCs.Location = new System.Drawing.Point(12, 281); this.progressLabelDLCs.Name = "progressLabelDLCs"; this.progressLabelDLCs.Size = new System.Drawing.Size(560, 12); this.progressLabelDLCs.TabIndex = 10004; this.progressLabelDLCs.Text = "Remaining DLC (2): 123456, 654321"; // + // sortCheckBox + // + this.sortCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.sortCheckBox.AutoSize = true; + this.sortCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.sortCheckBox.Location = new System.Drawing.Point(120, 328); + this.sortCheckBox.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); + this.sortCheckBox.Name = "sortCheckBox"; + this.sortCheckBox.Size = new System.Drawing.Size(104, 20); + this.sortCheckBox.TabIndex = 1; + this.sortCheckBox.Text = "Sort By Name"; + this.sortCheckBox.CheckedChanged += new System.EventHandler(this.OnSortCheckBoxChanged); + // // SelectForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -272,6 +298,7 @@ namespace CreamInstaller this.AutoSize = true; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.ClientSize = new System.Drawing.Size(584, 361); + this.Controls.Add(this.sortCheckBox); this.Controls.Add(this.progressLabelDLCs); this.Controls.Add(this.progressLabelGames); this.Controls.Add(this.uninstallButton); @@ -296,6 +323,7 @@ namespace CreamInstaller this.flowLayoutPanel1.PerformLayout(); this.flowLayoutPanel2.ResumeLayout(false); this.ResumeLayout(false); + this.PerformLayout(); } @@ -318,6 +346,7 @@ namespace CreamInstaller private Button uninstallButton; private Label progressLabelGames; private Label progressLabelDLCs; + private CheckBox sortCheckBox; } } diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index 01adcfe..ae5b838 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -21,8 +21,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using Windows.Foundation.Metadata; - namespace CreamInstaller; internal partial class SelectForm : CustomForm @@ -640,7 +638,7 @@ internal partial class SelectForm : CustomForm TreeNode node = e.Node; if (node is null || !node.Bounds.Contains(e.Location) || e.Button != MouseButtons.Right || e.Clicks != 1) return; - ContextMenuStrip contextMenuStrip = new(); + using ContextMenuStrip contextMenuStrip = new(); selectionTreeView.SelectedNode = node; string id = node.Name; Platform platform = (Platform)node.Tag; @@ -876,6 +874,9 @@ internal partial class SelectForm : CustomForm "\n\nBlocked game sub-directory exceptions (not blocked):" + blockedDirectoryExceptions, "OK", customFormText: "Block Protected Games"); } + + private void OnSortCheckBoxChanged(object sender, EventArgs e) => selectionTreeView.TreeViewNodeSorter + = sortCheckBox.Checked ? PlatformIdComparer.NodeText : PlatformIdComparer.NodeName; } #pragma warning restore IDE0058 \ No newline at end of file diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index b647249..27fe3ba 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -1,7 +1,6 @@ using CreamInstaller.Components; using CreamInstaller.Resources; -using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -44,8 +43,8 @@ internal class ProgramSelection internal string RootDirectory; internal List DllDirectories; - internal readonly SortedList AllDlc = new(PlatformIdComparer.Strings); - internal readonly SortedList SelectedDlc = new(PlatformIdComparer.Strings); + internal readonly SortedList AllDlc = new(PlatformIdComparer.String); + internal readonly SortedList SelectedDlc = new(PlatformIdComparer.String); internal readonly List<(string id, string name, SortedList dlc)> ExtraDlc = new(); // for Paradox Launcher internal readonly List<(string id, string name, SortedList dlc)> ExtraSelectedDlc = new(); // for Paradox Launcher diff --git a/CreamInstaller/Resources/ScreamAPI.cs b/CreamInstaller/Resources/ScreamAPI.cs index e564728..173244a 100644 --- a/CreamInstaller/Resources/ScreamAPI.cs +++ b/CreamInstaller/Resources/ScreamAPI.cs @@ -151,8 +151,8 @@ internal static class ScreamAPI File.Create(config).Close(); StreamWriter writer = new(config, true, Encoding.UTF8); WriteConfig(writer, - new(overrideCatalogItems.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.Strings), - new(entitlements.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.Strings), + new(overrideCatalogItems.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), + new(entitlements.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm); writer.Flush(); writer.Close(); diff --git a/CreamInstaller/Resources/SmokeAPI.cs b/CreamInstaller/Resources/SmokeAPI.cs index 8183607..241ab07 100644 --- a/CreamInstaller/Resources/SmokeAPI.cs +++ b/CreamInstaller/Resources/SmokeAPI.cs @@ -165,8 +165,8 @@ internal static class SmokeAPI File.Create(config).Close(); StreamWriter writer = new(config, true, Encoding.UTF8); WriteConfig(writer, - new(overrideDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.Strings), - new(injectDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.Strings), + new(overrideDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), + new(injectDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm); writer.Flush(); writer.Close(); diff --git a/CreamInstaller/Resources/UplayR1.cs b/CreamInstaller/Resources/UplayR1.cs index 800219f..8f454d0 100644 --- a/CreamInstaller/Resources/UplayR1.cs +++ b/CreamInstaller/Resources/UplayR1.cs @@ -123,7 +123,7 @@ internal static class UplayR1 installForm.UpdateUser("Generating Uplay R1 Unlocker configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation); File.Create(config).Close(); StreamWriter writer = new(config, true, Encoding.UTF8); - WriteConfig(writer, new(blacklistDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.Strings), installForm); + WriteConfig(writer, new(blacklistDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm); writer.Flush(); writer.Close(); } diff --git a/CreamInstaller/Resources/UplayR2.cs b/CreamInstaller/Resources/UplayR2.cs index 0a296a6..79d19e3 100644 --- a/CreamInstaller/Resources/UplayR2.cs +++ b/CreamInstaller/Resources/UplayR2.cs @@ -131,7 +131,7 @@ internal static class UplayR2 installForm.UpdateUser("Generating Uplay R2 Unlocker configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation); File.Create(config).Close(); StreamWriter writer = new(config, true, Encoding.UTF8); - WriteConfig(writer, new(blacklistDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.Strings), installForm); + WriteConfig(writer, new(blacklistDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm); writer.Flush(); writer.Close(); } diff --git a/CreamInstaller/Utility/ProgramData.cs b/CreamInstaller/Utility/ProgramData.cs index 714f08f..e161866 100644 --- a/CreamInstaller/Utility/ProgramData.cs +++ b/CreamInstaller/Utility/ProgramData.cs @@ -3,10 +3,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; -using System.Text.Json; -using System.Text.Json.Nodes; using System.Threading.Tasks; using System.Windows.Forms;