From 2502f124ee1753221a5103e89b3caa00d1abb83e Mon Sep 17 00:00:00 2001 From: Frog Date: Mon, 20 Jul 2026 22:46:33 -0700 Subject: [PATCH] Add Clear Cache / Reconfigure SteamCMD Buttons - Add button to clear app cache in settings - Add button to reconfigure SteamCMD in settings - Add a few edge cases to cleanup old legacy folders --- CreamInstaller/Forms/DialogForm.Designer.cs | 2 +- CreamInstaller/Forms/SettingsForm.Designer.cs | 60 +++++++++++++++++-- CreamInstaller/Forms/SettingsForm.cs | 58 ++++++++++++++++++ CreamInstaller/Utility/ProgramData.cs | 7 +++ 4 files changed, 121 insertions(+), 6 deletions(-) diff --git a/CreamInstaller/Forms/DialogForm.Designer.cs b/CreamInstaller/Forms/DialogForm.Designer.cs index 64cd5ac..0de12e2 100644 --- a/CreamInstaller/Forms/DialogForm.Designer.cs +++ b/CreamInstaller/Forms/DialogForm.Designer.cs @@ -98,7 +98,7 @@ namespace CreamInstaller.Forms // // descriptionLabelPanel // - descriptionLabelPanel.AutoScroll = true; + descriptionLabelPanel.AutoScroll = false; descriptionLabelPanel.AutoSize = true; descriptionLabelPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; descriptionLabelPanel.Controls.Add(descriptionLabel); diff --git a/CreamInstaller/Forms/SettingsForm.Designer.cs b/CreamInstaller/Forms/SettingsForm.Designer.cs index 4ec2631..6ac8d82 100644 --- a/CreamInstaller/Forms/SettingsForm.Designer.cs +++ b/CreamInstaller/Forms/SettingsForm.Designer.cs @@ -1,6 +1,10 @@ +using System; using System.ComponentModel; using System.Drawing; +using System.IO; using System.Windows.Forms; +using CreamInstaller.Platforms.Steam; +using CreamInstaller.Utility; namespace CreamInstaller.Forms; @@ -23,10 +27,14 @@ partial class SettingsForm gameManagementGroup = new GroupBox(); blockedGamesCheckBox = new CheckBox(); sortByNameCheckBox = new CheckBox(); + maintenanceGroup = new GroupBox(); + clearCacheButton = new Button(); + reconfigureSteamCMDButton = new Button(); saveButton = new Button(); cancelButton = new Button(); appearanceGroup.SuspendLayout(); gameManagementGroup.SuspendLayout(); + maintenanceGroup.SuspendLayout(); SuspendLayout(); // // settingsToolTip @@ -94,14 +102,50 @@ partial class SettingsForm sortByNameCheckBox.UseVisualStyleBackColor = true; SettingsToolTip.SetToolTip(sortByNameCheckBox, "When enabled, games in the main list are sorted alphabetically by name. When disabled, games appear in their default platform order."); // + // maintenanceGroup + // + maintenanceGroup.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + maintenanceGroup.Controls.Add(clearCacheButton); + maintenanceGroup.Controls.Add(reconfigureSteamCMDButton); + maintenanceGroup.Location = new Point(12, 160); + maintenanceGroup.Name = "maintenanceGroup"; + maintenanceGroup.Size = new Size(376, 55); + maintenanceGroup.TabIndex = 2; + maintenanceGroup.TabStop = false; + maintenanceGroup.Text = "Maintenance"; + // + // clearCacheButton + // + clearCacheButton.AutoSize = true; + clearCacheButton.Location = new Point(12, 20); + clearCacheButton.Name = "clearCacheButton"; + clearCacheButton.Size = new Size(175, 25); + clearCacheButton.TabIndex = 0; + clearCacheButton.Text = "Clear Cached Data"; + clearCacheButton.UseVisualStyleBackColor = true; + clearCacheButton.Click += OnClearCacheClick; + SettingsToolTip.SetToolTip(clearCacheButton, "Deletes all cached game data, forcing a fresh scan on the next launch. Settings are preserved."); + // + // reconfigureSteamCMDButton + // + reconfigureSteamCMDButton.AutoSize = true; + reconfigureSteamCMDButton.Location = new Point(195, 20); + reconfigureSteamCMDButton.Name = "reconfigureSteamCMDButton"; + reconfigureSteamCMDButton.Size = new Size(175, 25); + reconfigureSteamCMDButton.TabIndex = 1; + reconfigureSteamCMDButton.Text = "Reconfigure SteamCMD"; + reconfigureSteamCMDButton.UseVisualStyleBackColor = true; + reconfigureSteamCMDButton.Click += OnReconfigureSteamCMDClick; + SettingsToolTip.SetToolTip(reconfigureSteamCMDButton, "Removes the existing SteamCMD installation. It will be re-downloaded automatically on the next scan."); + // // saveButton // saveButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; saveButton.AutoSize = true; - saveButton.Location = new Point(232, 160); + saveButton.Location = new Point(232, 228); saveButton.Name = "saveButton"; saveButton.Size = new Size(75, 25); - saveButton.TabIndex = 2; + saveButton.TabIndex = 3; saveButton.Text = "Save"; saveButton.UseVisualStyleBackColor = true; saveButton.Click += OnSaveClick; @@ -110,10 +154,10 @@ partial class SettingsForm // cancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; cancelButton.AutoSize = true; - cancelButton.Location = new Point(313, 160); + cancelButton.Location = new Point(313, 228); cancelButton.Name = "cancelButton"; cancelButton.Size = new Size(75, 25); - cancelButton.TabIndex = 3; + cancelButton.TabIndex = 4; cancelButton.Text = "Cancel"; cancelButton.UseVisualStyleBackColor = true; cancelButton.Click += OnCancelClick; @@ -122,9 +166,10 @@ partial class SettingsForm // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(400, 197); + ClientSize = new Size(400, 265); Controls.Add(cancelButton); Controls.Add(saveButton); + Controls.Add(maintenanceGroup); Controls.Add(gameManagementGroup); Controls.Add(appearanceGroup); FormBorderStyle = FormBorderStyle.FixedDialog; @@ -134,15 +179,20 @@ partial class SettingsForm StartPosition = FormStartPosition.CenterParent; appearanceGroup.ResumeLayout(false); gameManagementGroup.ResumeLayout(false); + maintenanceGroup.ResumeLayout(false); + maintenanceGroup.PerformLayout(); ResumeLayout(false); PerformLayout(); } private GroupBox appearanceGroup; private GroupBox gameManagementGroup; + private GroupBox maintenanceGroup; private CheckBox darkModeCheckBox; private CheckBox blockedGamesCheckBox; private CheckBox sortByNameCheckBox; + private Button clearCacheButton; + private Button reconfigureSteamCMDButton; private Button saveButton; private Button cancelButton; private ToolTip SettingsToolTip; diff --git a/CreamInstaller/Forms/SettingsForm.cs b/CreamInstaller/Forms/SettingsForm.cs index ce4eaca..c5dd2e9 100644 --- a/CreamInstaller/Forms/SettingsForm.cs +++ b/CreamInstaller/Forms/SettingsForm.cs @@ -1,7 +1,10 @@ using System; using System.Drawing; +using System.IO; +using System.Threading.Tasks; using System.Windows.Forms; using CreamInstaller.Components; +using CreamInstaller.Platforms.Steam; using CreamInstaller.Utility; namespace CreamInstaller.Forms; @@ -62,4 +65,59 @@ internal sealed partial class SettingsForm : CustomForm DialogResult = DialogResult.Cancel; Close(); } + + private void OnClearCacheClick(object sender, EventArgs e) + { + using DialogForm confirm = new(this); + if (confirm.Show(SystemIcons.Warning, + "This will delete all cached game data, installed game records, and proxy configurations.\n\nYour settings will be preserved. A fresh scan will be required on the next launch.", + acceptButtonText: "Clear Cache", cancelButtonText: "Cancel", customFormText: "Clear Cached Data") != DialogResult.OK) + return; + + string cachePath = ProgramData.DirectoryPath + @"\Cache"; + if (Directory.Exists(cachePath)) + { + foreach (string file in Directory.GetFiles(cachePath)) + { + if (Path.GetFileName(file).Equals("settings.json", StringComparison.OrdinalIgnoreCase)) + continue; + try { File.Delete(file); } catch { /* skip locked files */ } + } + foreach (string dir in Directory.GetDirectories(cachePath)) + { + try { Directory.Delete(dir, true); } catch { /* skip locked dirs */ } + } + } + + ProgramData.SaveSettings(Program.AppSettings); + } + + private async void OnReconfigureSteamCMDClick(object sender, EventArgs e) + { + using DialogForm confirm = new(this); + if (confirm.Show(SystemIcons.Warning, + "This will delete and re-download the SteamCMD installation.\n\nCached app data will be preserved.", + acceptButtonText: "Reconfigure", cancelButtonText: "Cancel", customFormText: "Reconfigure SteamCMD") != DialogResult.OK) + return; + + reconfigureSteamCMDButton.Enabled = false; + reconfigureSteamCMDButton.Text = "Reconfiguring..."; + + string steamCmdPath = ProgramData.DirectoryPath + @"\SteamCMD"; + await Task.Run(() => + { + try { Directory.Delete(steamCmdPath, true); } catch { /* directory may not exist */ } + }); + + Progress progress = new(); + await SteamCMD.Setup(progress); + + Color originalColor = reconfigureSteamCMDButton.ForeColor; + reconfigureSteamCMDButton.Text = "Complete"; + reconfigureSteamCMDButton.ForeColor = Color.Green; + await Task.Delay(2000); + reconfigureSteamCMDButton.Text = "Reconfigure SteamCMD"; + reconfigureSteamCMDButton.ForeColor = originalColor; + reconfigureSteamCMDButton.Enabled = true; + } } diff --git a/CreamInstaller/Utility/ProgramData.cs b/CreamInstaller/Utility/ProgramData.cs index 6de833f..fa7a07d 100644 --- a/CreamInstaller/Utility/ProgramData.cs +++ b/CreamInstaller/Utility/ProgramData.cs @@ -250,6 +250,10 @@ internal static event Action OnLog; MigrateOldPath(DirectoryPath + @"\cream-steam.log", SteamLogPath); MigrateOldPath(DirectoryPath + @"\CreamInstaller.log", AppLogPath); MigrateOldPath(DirectoryPath + @"\unlocker.log", UnlockerLogPath); + + // cleanup legacy paths no longer used + string oldCooldown = DirectoryPath + @"\cooldown"; + try { if (Directory.Exists(oldCooldown)) Directory.Delete(oldCooldown, true); } catch { } }); private static void MigrateOldPath(string oldPath, string newPath) @@ -257,7 +261,10 @@ internal static event Action OnLog; if (!oldPath.FileExists()) return; if (newPath.FileExists()) + { + oldPath.DeleteFile(); return; + } try { string content = oldPath.ReadFile();