Consolidate save load reset functionalities into one button each & fix DLC selection saving

This commit is contained in:
pointfeev 2024-07-21 22:51:43 -04:00
parent a8bfc73d6a
commit abf4172787
4 changed files with 183 additions and 247 deletions

View file

@ -39,10 +39,7 @@ namespace CreamInstaller.Forms
sortCheckBox = new CheckBox(); sortCheckBox = new CheckBox();
saveButton = new Button(); saveButton = new Button();
loadButton = new Button(); loadButton = new Button();
resetProxyButton = new Button();
resetButton = new Button(); resetButton = new Button();
saveProxyButton = new Button();
loadProxyButton = new Button();
selectionTreeView = new CustomTreeView(); selectionTreeView = new CustomTreeView();
programsGroupBox.SuspendLayout(); programsGroupBox.SuspendLayout();
proxyFlowPanel.SuspendLayout(); proxyFlowPanel.SuspendLayout();
@ -305,9 +302,9 @@ namespace CreamInstaller.Forms
saveButton.Name = "saveButton"; saveButton.Name = "saveButton";
saveButton.Size = new System.Drawing.Size(66, 25); saveButton.Size = new System.Drawing.Size(66, 25);
saveButton.TabIndex = 10006; saveButton.TabIndex = 10006;
saveButton.Text = "Save DLC"; saveButton.Text = "Save";
saveButton.UseVisualStyleBackColor = true; saveButton.UseVisualStyleBackColor = true;
saveButton.Click += OnSaveDlc; saveButton.Click += OnSaveSelections;
// //
// loadButton // loadButton
// //
@ -319,23 +316,9 @@ namespace CreamInstaller.Forms
loadButton.Name = "loadButton"; loadButton.Name = "loadButton";
loadButton.Size = new System.Drawing.Size(68, 25); loadButton.Size = new System.Drawing.Size(68, 25);
loadButton.TabIndex = 10005; loadButton.TabIndex = 10005;
loadButton.Text = "Load DLC"; loadButton.Text = "Load";
loadButton.UseVisualStyleBackColor = true; loadButton.UseVisualStyleBackColor = true;
loadButton.Click += OnLoadDlc; loadButton.Click += OnLoadSelections;
//
// resetProxyButton
//
resetProxyButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
resetProxyButton.AutoSize = true;
resetProxyButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
resetProxyButton.Enabled = false;
resetProxyButton.Location = new System.Drawing.Point(12, 295);
resetProxyButton.Name = "resetProxyButton";
resetProxyButton.Size = new System.Drawing.Size(101, 25);
resetProxyButton.TabIndex = 10010;
resetProxyButton.Text = "Reset Proxy";
resetProxyButton.UseVisualStyleBackColor = true;
resetProxyButton.Click += OnResetProxy;
// //
// resetButton // resetButton
// //
@ -347,37 +330,9 @@ namespace CreamInstaller.Forms
resetButton.Name = "resetButton"; resetButton.Name = "resetButton";
resetButton.Size = new System.Drawing.Size(70, 25); resetButton.Size = new System.Drawing.Size(70, 25);
resetButton.TabIndex = 10007; resetButton.TabIndex = 10007;
resetButton.Text = "Reset DLC"; resetButton.Text = "Reset";
resetButton.UseVisualStyleBackColor = true; resetButton.UseVisualStyleBackColor = true;
resetButton.Click += OnResetDlc; resetButton.Click += OnResetSelections;
//
// saveProxyButton
//
saveProxyButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
saveProxyButton.AutoSize = true;
saveProxyButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
saveProxyButton.Enabled = false;
saveProxyButton.Location = new System.Drawing.Point(119, 295);
saveProxyButton.Name = "saveProxyButton";
saveProxyButton.Size = new System.Drawing.Size(97, 25);
saveProxyButton.TabIndex = 10009;
saveProxyButton.Text = "Save Proxy";
saveProxyButton.UseVisualStyleBackColor = true;
saveProxyButton.Click += OnSaveProxy;
//
// loadProxyButton
//
loadProxyButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
loadProxyButton.AutoSize = true;
loadProxyButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
loadProxyButton.Enabled = false;
loadProxyButton.Location = new System.Drawing.Point(222, 295);
loadProxyButton.Name = "loadProxyButton";
loadProxyButton.Size = new System.Drawing.Size(99, 25);
loadProxyButton.TabIndex = 10008;
loadProxyButton.Text = "Load Proxy";
loadProxyButton.UseVisualStyleBackColor = true;
loadProxyButton.Click += OnLoadProxy;
// //
// SelectForm // SelectForm
// //
@ -386,10 +341,7 @@ namespace CreamInstaller.Forms
AutoSize = true; AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink; AutoSizeMode = AutoSizeMode.GrowAndShrink;
ClientSize = new System.Drawing.Size(584, 361); ClientSize = new System.Drawing.Size(584, 361);
Controls.Add(loadProxyButton);
Controls.Add(saveProxyButton);
Controls.Add(resetButton); Controls.Add(resetButton);
Controls.Add(resetProxyButton);
Controls.Add(loadButton); Controls.Add(loadButton);
Controls.Add(saveButton); Controls.Add(saveButton);
Controls.Add(sortCheckBox); Controls.Add(sortCheckBox);
@ -445,10 +397,7 @@ namespace CreamInstaller.Forms
internal CheckBox proxyAllCheckBox; internal CheckBox proxyAllCheckBox;
private Button saveButton; private Button saveButton;
private Button loadButton; private Button loadButton;
private Button resetProxyButton;
private Button resetButton; private Button resetButton;
private Button saveProxyButton;
private Button loadProxyButton;
} }
} }

View file

@ -16,7 +16,6 @@ using CreamInstaller.Platforms.Steam;
using CreamInstaller.Platforms.Ubisoft; using CreamInstaller.Platforms.Ubisoft;
using CreamInstaller.Resources; using CreamInstaller.Resources;
using CreamInstaller.Utility; using CreamInstaller.Utility;
using Gameloop.Vdf.Linq;
using static CreamInstaller.Resources.Resources; using static CreamInstaller.Resources.Resources;
namespace CreamInstaller.Forms; namespace CreamInstaller.Forms;
@ -563,9 +562,6 @@ internal sealed partial class SelectForm : CustomForm
saveButton.Enabled = false; saveButton.Enabled = false;
loadButton.Enabled = false; loadButton.Enabled = false;
resetButton.Enabled = false; resetButton.Enabled = false;
saveProxyButton.Enabled = false;
loadProxyButton.Enabled = false;
resetProxyButton.Enabled = false;
progressLabel.Text = "Waiting for user to select which programs/games to scan . . ."; progressLabel.Text = "Waiting for user to select which programs/games to scan . . .";
ShowProgressBar(); ShowProgressBar();
await ProgramData.Setup(this); await ProgramData.Setup(this);
@ -686,8 +682,7 @@ internal sealed partial class SelectForm : CustomForm
await SteamCMD.Cleanup(); await SteamCMD.Cleanup();
} }
OnLoadDlc(null, null); OnLoadSelections(null, null);
OnLoadProxy(null, null);
HideProgressBar(); HideProgressBar();
selectionTreeView.Enabled = !Selection.All.IsEmpty; selectionTreeView.Enabled = !Selection.All.IsEmpty;
allCheckBox.Enabled = selectionTreeView.Enabled; allCheckBox.Enabled = selectionTreeView.Enabled;
@ -695,12 +690,9 @@ internal sealed partial class SelectForm : CustomForm
noneFoundLabel.Visible = !selectionTreeView.Enabled; noneFoundLabel.Visible = !selectionTreeView.Enabled;
installButton.Enabled = Selection.AllEnabled.Any(); installButton.Enabled = Selection.AllEnabled.Any();
uninstallButton.Enabled = installButton.Enabled; uninstallButton.Enabled = installButton.Enabled;
saveButton.Enabled = CanSaveDlc(); saveButton.Enabled = CanSaveSelections();
loadButton.Enabled = CanLoadDlc(); loadButton.Enabled = CanLoadSelections();
resetButton.Enabled = CanResetDlc(); resetButton.Enabled = CanResetSelections();
saveProxyButton.Enabled = CanSaveProxy();
loadProxyButton.Enabled = CanLoadProxy();
resetProxyButton.Enabled = CanResetProxy();
cancelButton.Enabled = false; cancelButton.Enabled = false;
scanButton.Enabled = true; scanButton.Enabled = true;
blockedGamesCheckBox.Enabled = true; blockedGamesCheckBox.Enabled = true;
@ -722,8 +714,10 @@ internal sealed partial class SelectForm : CustomForm
allCheckBox.CheckedChanged += OnAllCheckBoxChanged; allCheckBox.CheckedChanged += OnAllCheckBoxChanged;
installButton.Enabled = Selection.AllEnabled.Any(); installButton.Enabled = Selection.AllEnabled.Any();
uninstallButton.Enabled = installButton.Enabled; uninstallButton.Enabled = installButton.Enabled;
saveButton.Enabled = CanSaveDlc(); if (sender is "OnLoadSelections" or "OnResetSelections")
resetButton.Enabled = CanResetDlc(); return;
saveButton.Enabled = CanSaveSelections();
resetButton.Enabled = CanResetSelections();
} }
private static void SyncNodeAncestors(TreeNode node) private static void SyncNodeAncestors(TreeNode node)
@ -1029,7 +1023,7 @@ internal sealed partial class SelectForm : CustomForm
foreach (Selection selection in Selection.All.Keys.Where(s => s.Enabled != shouldEnable)) foreach (Selection selection in Selection.All.Keys.Where(s => s.Enabled != shouldEnable))
{ {
selection.Enabled = shouldEnable; selection.Enabled = shouldEnable;
OnTreeViewNodeCheckedChanged(null, new(selection.TreeNode, TreeViewAction.ByMouse)); OnTreeViewNodeCheckedChanged("OnAllCheckBoxChanged", new(selection.TreeNode, TreeViewAction.ByMouse));
} }
allCheckBox.CheckedChanged -= OnAllCheckBoxChanged; allCheckBox.CheckedChanged -= OnAllCheckBoxChanged;
@ -1046,7 +1040,7 @@ internal sealed partial class SelectForm : CustomForm
proxyAllCheckBox.CheckedChanged -= OnProxyAllCheckBoxChanged; proxyAllCheckBox.CheckedChanged -= OnProxyAllCheckBoxChanged;
proxyAllCheckBox.Checked = shouldEnable; proxyAllCheckBox.Checked = shouldEnable;
proxyAllCheckBox.CheckedChanged += OnProxyAllCheckBoxChanged; proxyAllCheckBox.CheckedChanged += OnProxyAllCheckBoxChanged;
resetProxyButton.Enabled = CanResetProxy(); resetButton.Enabled = CanResetSelections();
} }
private bool AreSelectionsDefault() private bool AreSelectionsDefault()
@ -1054,96 +1048,79 @@ internal sealed partial class SelectForm : CustomForm
=> node.Parent is null || node.Tag is not Platform and not DLCType || => node.Parent is null || node.Tag is not Platform and not DLCType ||
(node.Text == "Unknown" ? !node.Checked : node.Checked)); (node.Text == "Unknown" ? !node.Checked : node.Checked));
private static bool AreProxySelectionsDefault() => Selection.All.Keys.All(selection => !selection.UseProxy);
private bool CanSaveDlc() => private bool CanSaveDlc() =>
installButton.Enabled && (ProgramData.ReadDlcChoices().Any() || !AreSelectionsDefault()); installButton.Enabled && (ProgramData.ReadDlcChoices().Any() || !AreSelectionsDefault());
private void OnSaveDlc(object sender, EventArgs e)
{
List<(Platform platform, string gameId, string dlcId)> choices = ProgramData.ReadDlcChoices().ToList();
foreach (SelectionDLC dlc in SelectionDLC.All.Keys)
if ((dlc.Name == "Unknown" ? dlc.Enabled : !dlc.Enabled)
&& !choices.Any(c =>
c.platform == dlc.Selection.Platform && c.gameId == dlc.Selection.Id && c.dlcId == dlc.Id))
choices.Add((dlc.Selection.Platform, dlc.Selection.Id, dlc.Id));
else
_ = choices.RemoveAll(n =>
n.platform == dlc.Selection.Platform && n.gameId == dlc.Selection.Id && n.dlcId == dlc.Id);
ProgramData.WriteDlcChoices(choices);
loadButton.Enabled = CanLoadDlc();
saveButton.Enabled = CanSaveDlc();
}
private static bool CanLoadDlc() => ProgramData.ReadDlcChoices().Any();
private void OnLoadDlc(object sender, EventArgs e)
{
List<(Platform platform, string gameId, string dlcId)> choices = ProgramData.ReadDlcChoices().ToList();
foreach (SelectionDLC dlc in SelectionDLC.All.Keys)
{
dlc.Enabled = choices.Any(c =>
c.platform == dlc.Selection?.Platform && c.gameId == dlc.Selection?.Id && c.dlcId == dlc.Id)
? dlc.Name == "Unknown"
: dlc.Name != "Unknown";
OnTreeViewNodeCheckedChanged(null, new(dlc.TreeNode, TreeViewAction.ByMouse));
}
}
private bool CanResetDlc() => !AreSelectionsDefault();
private void OnResetDlc(object sender, EventArgs e)
{
foreach (SelectionDLC dlc in SelectionDLC.All.Keys)
{
dlc.Enabled = dlc.Name != "Unknown";
OnTreeViewNodeCheckedChanged(null, new(dlc.TreeNode, TreeViewAction.ByMouse));
}
resetButton.Enabled = CanResetDlc();
}
private static bool AreProxySelectionsDefault() =>
Selection.All.Keys.All(selection => !selection.UseProxy && selection.Proxy is null);
private static bool CanSaveProxy() => private static bool CanSaveProxy() =>
ProgramData.ReadProxyChoices().Any() || !AreProxySelectionsDefault(); ProgramData.ReadProxyChoices().Any() || !AreProxySelectionsDefault();
private void OnSaveProxy(object sender, EventArgs e) private bool CanSaveSelections() => CanSaveDlc() || CanSaveProxy();
private void OnSaveSelections(object sender, EventArgs e)
{ {
List<(Platform platform, string id, string proxy, bool enabled)> choices = List<(Platform platform, string gameId, string dlcId)> dlcChoices = ProgramData.ReadDlcChoices().ToList();
foreach (SelectionDLC dlc in SelectionDLC.All.Keys)
{
_ = dlcChoices.RemoveAll(n =>
n.platform == dlc.Selection.Platform && n.gameId == dlc.Selection.Id && n.dlcId == dlc.Id);
if (dlc.Name == "Unknown" ? dlc.Enabled : !dlc.Enabled)
dlcChoices.Add((dlc.Selection.Platform, dlc.Selection.Id, dlc.Id));
}
ProgramData.WriteDlcChoices(dlcChoices);
List<(Platform platform, string id, string proxy, bool enabled)> proxyChoices =
ProgramData.ReadProxyChoices().ToList(); ProgramData.ReadProxyChoices().ToList();
foreach (Selection selection in Selection.All.Keys) foreach (Selection selection in Selection.All.Keys)
{ {
_ = choices.RemoveAll(c => c.platform == selection.Platform && c.id == selection.Id); _ = proxyChoices.RemoveAll(c => c.platform == selection.Platform && c.id == selection.Id);
if (selection.Proxy is not null and not Selection.DefaultProxy || selection.UseProxy) if (selection.UseProxy)
choices.Add((selection.Platform, selection.Id, proxyChoices.Add((selection.Platform, selection.Id,
selection.Proxy == Selection.DefaultProxy ? null : selection.Proxy, selection.Proxy == Selection.DefaultProxy ? null : selection.Proxy,
selection.UseProxy)); selection.UseProxy));
} }
ProgramData.WriteProxyChoices(choices); ProgramData.WriteProxyChoices(proxyChoices);
saveProxyButton.Enabled = CanSaveProxy();
loadProxyButton.Enabled = CanLoadProxy(); loadButton.Enabled = CanLoadSelections();
saveButton.Enabled = CanSaveSelections();
} }
private static bool CanLoadDlc() => ProgramData.ReadDlcChoices().Any();
private static bool CanLoadProxy() => ProgramData.ReadProxyChoices().Any(); private static bool CanLoadProxy() => ProgramData.ReadProxyChoices().Any();
private void OnLoadProxy(object sender, EventArgs e) private bool CanLoadSelections() => CanLoadDlc() || CanLoadProxy();
private void OnLoadSelections(object sender, EventArgs e)
{ {
List<(Platform platform, string id, string proxy, bool enabled)> choices = List<(Platform platform, string gameId, string dlcId)> dlcChoices = ProgramData.ReadDlcChoices().ToList();
foreach (SelectionDLC dlc in SelectionDLC.All.Keys)
{
dlc.Enabled = dlcChoices.Any(c =>
c.platform == dlc.Selection?.Platform && c.gameId == dlc.Selection?.Id && c.dlcId == dlc.Id)
? dlc.Name == "Unknown"
: dlc.Name != "Unknown";
OnTreeViewNodeCheckedChanged("OnLoadSelections", new(dlc.TreeNode, TreeViewAction.ByMouse));
}
List<(Platform platform, string id, string proxy, bool enabled)> proxyChoices =
ProgramData.ReadProxyChoices().ToList(); ProgramData.ReadProxyChoices().ToList();
foreach (Selection selection in Selection.All.Keys) foreach (Selection selection in Selection.All.Keys)
if (choices.Any(c => c.platform == selection.Platform && c.id == selection.Id)) if (proxyChoices.Any(c => c.platform == selection.Platform && c.id == selection.Id))
{ {
(Platform platform, string id, string proxy, bool enabled) (Platform platform, string id, string proxy, bool enabled)
choice = choices.First(c => c.platform == selection.Platform && c.id == selection.Id); choice = proxyChoices.First(c => c.platform == selection.Platform && c.id == selection.Id);
(Platform platform, string id, string proxy, bool enabled) = choice; (Platform platform, string id, string proxy, bool enabled) = choice;
string currentProxy = proxy; string currentProxy = proxy;
if (proxy is not null && proxy.Contains('.')) // convert pre-v4.1.0.0 choices if (proxy is not null && proxy.Contains('.')) // convert pre-v4.1.0.0 choices
proxy.GetProxyInfoFromIdentifier(out currentProxy, out _); proxy.GetProxyInfoFromIdentifier(out currentProxy, out _);
if (proxy != currentProxy && choices.Remove(choice)) // convert pre-v4.1.0.0 choices if (proxy != currentProxy && proxyChoices.Remove(choice)) // convert pre-v4.1.0.0 choices
choices.Add((platform, id, currentProxy, enabled)); proxyChoices.Add((platform, id, currentProxy, enabled));
if (currentProxy is null or Selection.DefaultProxy && !enabled) if (currentProxy is null or Selection.DefaultProxy && !enabled)
_ = choices.RemoveAll(c => c.platform == platform && c.id == id); _ = proxyChoices.RemoveAll(c => c.platform == platform && c.id == id);
else else
{ {
selection.UseProxy = enabled; selection.UseProxy = enabled;
@ -1156,15 +1133,26 @@ internal sealed partial class SelectForm : CustomForm
selection.Proxy = null; selection.Proxy = null;
} }
ProgramData.WriteProxyChoices(choices); ProgramData.WriteProxyChoices(proxyChoices);
loadProxyButton.Enabled = CanLoadProxy(); loadButton.Enabled = CanLoadSelections();
OnProxyChanged(); OnProxyChanged();
} }
private bool CanResetDlc() => !AreSelectionsDefault();
private static bool CanResetProxy() => !AreProxySelectionsDefault(); private static bool CanResetProxy() => !AreProxySelectionsDefault();
private void OnResetProxy(object sender, EventArgs e) private bool CanResetSelections() => CanResetDlc() || CanResetProxy();
private void OnResetSelections(object sender, EventArgs e)
{ {
foreach (SelectionDLC dlc in SelectionDLC.All.Keys)
{
dlc.Enabled = dlc.Name != "Unknown";
OnTreeViewNodeCheckedChanged("OnResetSelections", new(dlc.TreeNode, TreeViewAction.ByMouse));
}
foreach (Selection selection in Selection.All.Keys) foreach (Selection selection in Selection.All.Keys)
{ {
selection.UseProxy = false; selection.UseProxy = false;
@ -1177,8 +1165,8 @@ internal sealed partial class SelectForm : CustomForm
internal void OnProxyChanged() internal void OnProxyChanged()
{ {
selectionTreeView.Invalidate(); selectionTreeView.Invalidate();
saveProxyButton.Enabled = CanSaveProxy(); saveButton.Enabled = CanSaveSelections();
resetProxyButton.Enabled = CanResetProxy(); resetButton.Enabled = CanResetSelections();
proxyAllCheckBox.CheckedChanged -= OnProxyAllCheckBoxChanged; proxyAllCheckBox.CheckedChanged -= OnProxyAllCheckBoxChanged;
proxyAllCheckBox.Checked = Selection.All.Keys.All(selection => !selection.CanUseProxy || selection.UseProxy); proxyAllCheckBox.Checked = Selection.All.Keys.All(selection => !selection.CanUseProxy || selection.UseProxy);
proxyAllCheckBox.CheckedChanged += OnProxyAllCheckBoxChanged; proxyAllCheckBox.CheckedChanged += OnProxyAllCheckBoxChanged;

View file

@ -18,7 +18,7 @@
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data> <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value> <value>[base64 mime encoded serialized .NET Framework object]</value>
</data> </data>
@ -59,8 +59,7 @@
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType> <xsd:complexType>

View file

@ -13,7 +13,7 @@ internal static partial class SteamCMD
private const int CooldownGame = 600; private const int CooldownGame = 600;
private const int CooldownDlc = 1200; private const int CooldownDlc = 1200;
internal static async Task<CmdAppData> QueryWebAPI(string appId, bool isDlc = false, int attempts = 0) private static async Task<CmdAppData> QueryWebAPI(string appId, bool isDlc = false, int attempts = 0)
{ {
while (!Program.Canceled) while (!Program.Canceled)
{ {