From 3840aa9f1b30434d049446cd9136c3f9db0ae0ad Mon Sep 17 00:00:00 2001 From: pointfeev Date: Sun, 6 Feb 2022 20:17:51 -0500 Subject: [PATCH] v2.3.1.0 - Synchronized namespaces - Code cleanup & refactoring - Moved target OS version up to 10.0.22000.0 (7.0+ still supported) --- CreamInstaller/Classes/ExceptionHandler.cs | 10 +----- CreamInstaller/Classes/InstallationLog.cs | 2 +- CreamInstaller/Classes/ProgramSelection.cs | 2 +- CreamInstaller/Classes/SteamCMD.cs | 6 ++-- CreamInstaller/Classes/ValveDataFile.cs | 5 +-- CreamInstaller/CreamInstaller.csproj | 9 ++--- CreamInstaller/Forms/Components/CustomForm.cs | 2 +- .../Forms/Components/CustomTreeView.cs | 10 +----- CreamInstaller/Forms/DialogForm.cs | 2 ++ CreamInstaller/Forms/InstallForm.cs | 4 +++ CreamInstaller/Forms/MainForm.Designer.cs | 4 ++- CreamInstaller/Forms/MainForm.cs | 5 ++- CreamInstaller/Forms/SelectForm.Designer.cs | 4 ++- CreamInstaller/Forms/SelectForm.cs | 35 ++++++++----------- CreamInstaller/Program.cs | 13 +++---- .../Resources/FileResourceExtensions.cs | 2 +- 16 files changed, 52 insertions(+), 63 deletions(-) diff --git a/CreamInstaller/Classes/ExceptionHandler.cs b/CreamInstaller/Classes/ExceptionHandler.cs index 42dc7e4..d208747 100644 --- a/CreamInstaller/Classes/ExceptionHandler.cs +++ b/CreamInstaller/Classes/ExceptionHandler.cs @@ -1,16 +1,14 @@ using System; using System.Windows.Forms; -namespace CreamInstaller; +namespace CreamInstaller.Classes; internal static class ExceptionHandler { internal static bool OutputException(Exception e) { while (e.InnerException is not null) - { e = e.InnerException; - } string output = ""; string[] stackTrace = e.StackTrace?.Split('\n'); @@ -21,27 +19,21 @@ internal static class ExceptionHandler { string line = stackTrace[i]; if (line is not null) - { output += "\n " + line[line.IndexOf("at")..]; - } } } string[] messageLines = e.Message?.Split('\n'); if (messageLines is not null && messageLines.Length > 0) { if (output.Length > 0) - { output += "\n\n"; - } output += "MESSAGE\n"; for (int i = 0; i < messageLines.Length; i++) { string line = messageLines[i]; if (line is not null) - { output += "\n " + messageLines[i]; - } } } return MessageBox.Show(output, caption: "CreamInstaller encountered an exception", buttons: MessageBoxButtons.RetryCancel, icon: MessageBoxIcon.Error) == DialogResult.Retry; diff --git a/CreamInstaller/Classes/InstallationLog.cs b/CreamInstaller/Classes/InstallationLog.cs index 9be189d..7842f89 100644 --- a/CreamInstaller/Classes/InstallationLog.cs +++ b/CreamInstaller/Classes/InstallationLog.cs @@ -1,7 +1,7 @@ using System.Drawing; using System.Windows.Forms; -namespace CreamInstaller; +namespace CreamInstaller.Classes; internal static class InstallationLog { diff --git a/CreamInstaller/Classes/ProgramSelection.cs b/CreamInstaller/Classes/ProgramSelection.cs index 0967de1..c327c69 100644 --- a/CreamInstaller/Classes/ProgramSelection.cs +++ b/CreamInstaller/Classes/ProgramSelection.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Gameloop.Vdf.Linq; -namespace CreamInstaller; +namespace CreamInstaller.Classes; internal class ProgramSelection { diff --git a/CreamInstaller/Classes/SteamCMD.cs b/CreamInstaller/Classes/SteamCMD.cs index 8d64a5d..f257ff9 100644 --- a/CreamInstaller/Classes/SteamCMD.cs +++ b/CreamInstaller/Classes/SteamCMD.cs @@ -9,9 +9,11 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using CreamInstaller.Resources; + using Gameloop.Vdf.Linq; -namespace CreamInstaller; +namespace CreamInstaller.Classes; internal static class SteamCMD { @@ -158,8 +160,6 @@ internal static class SteamCMD { Kill().Wait(); if (Directory.Exists(DirectoryPath)) - { Directory.Delete(DirectoryPath, true); - } } } diff --git a/CreamInstaller/Classes/ValveDataFile.cs b/CreamInstaller/Classes/ValveDataFile.cs index cbee8b2..b32027f 100644 --- a/CreamInstaller/Classes/ValveDataFile.cs +++ b/CreamInstaller/Classes/ValveDataFile.cs @@ -1,7 +1,8 @@ -using Gameloop.Vdf; + +using Gameloop.Vdf; using Gameloop.Vdf.Linq; -namespace CreamInstaller; +namespace CreamInstaller.Classes; internal static class ValveDataFile { diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index 3d376bb..9d5cd35 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -1,11 +1,11 @@  WinExe - net6.0-windows - true + net6.0-windows10.0.22000.0 + True Resources\ini.ico true - 2.3.0.0 + 2.3.1.0 Resources\ini.ico Automatically generates and installs CreamAPI files for Steam games on the user's computer. It can also generate and install CreamAPI for the Paradox Launcher should the user select a Paradox Interactive game. @@ -23,7 +23,8 @@ pointfeev pointfeev.creaminstaller CreamInstaller.Program - false + False + 7.0 embedded diff --git a/CreamInstaller/Forms/Components/CustomForm.cs b/CreamInstaller/Forms/Components/CustomForm.cs index 748a77a..1072c6e 100644 --- a/CreamInstaller/Forms/Components/CustomForm.cs +++ b/CreamInstaller/Forms/Components/CustomForm.cs @@ -1,6 +1,6 @@ using System.Windows.Forms; -namespace CreamInstaller; +namespace CreamInstaller.Forms.Components; internal class CustomForm : Form { diff --git a/CreamInstaller/Forms/Components/CustomTreeView.cs b/CreamInstaller/Forms/Components/CustomTreeView.cs index ed5a591..d29b8ec 100644 --- a/CreamInstaller/Forms/Components/CustomTreeView.cs +++ b/CreamInstaller/Forms/Components/CustomTreeView.cs @@ -2,20 +2,16 @@ using System.Drawing; using System.Windows.Forms; -namespace CreamInstaller; +namespace CreamInstaller.Forms.Components; internal class CustomTreeView : TreeView { protected override void WndProc(ref Message m) { if (m.Msg == 0x203) - { m.Result = IntPtr.Zero; - } else - { base.WndProc(ref m); - } } internal CustomTreeView() : base() @@ -29,9 +25,7 @@ internal class CustomTreeView : TreeView e.DrawDefault = true; TreeNode node = e.Node; if (!node.IsVisible) - { return; - } Graphics graphics = e.Graphics; Color backColor = BackColor; @@ -41,9 +35,7 @@ internal class CustomTreeView : TreeView string subText = node.Name; if (subText is null || !int.TryParse(subText, out int subInt) || subInt <= 0) - { return; - } Size subSize = TextRenderer.MeasureText(graphics, subText, subFont); Rectangle bounds = node.Bounds; diff --git a/CreamInstaller/Forms/DialogForm.cs b/CreamInstaller/Forms/DialogForm.cs index 1f14452..825d550 100644 --- a/CreamInstaller/Forms/DialogForm.cs +++ b/CreamInstaller/Forms/DialogForm.cs @@ -1,6 +1,8 @@ using System.Drawing; using System.Windows.Forms; +using CreamInstaller.Forms.Components; + namespace CreamInstaller; internal partial class DialogForm : CustomForm diff --git a/CreamInstaller/Forms/InstallForm.cs b/CreamInstaller/Forms/InstallForm.cs index 4a9b9d8..c402071 100644 --- a/CreamInstaller/Forms/InstallForm.cs +++ b/CreamInstaller/Forms/InstallForm.cs @@ -8,6 +8,10 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using CreamInstaller.Classes; +using CreamInstaller.Forms.Components; +using CreamInstaller.Resources; + namespace CreamInstaller; internal partial class InstallForm : CustomForm diff --git a/CreamInstaller/Forms/MainForm.Designer.cs b/CreamInstaller/Forms/MainForm.Designer.cs index a5cfd18..3a662da 100644 --- a/CreamInstaller/Forms/MainForm.Designer.cs +++ b/CreamInstaller/Forms/MainForm.Designer.cs @@ -2,6 +2,8 @@ using System; using System.Windows.Forms; +using CreamInstaller.Forms.Components; + namespace CreamInstaller { partial class MainForm @@ -36,7 +38,7 @@ namespace CreamInstaller this.updateButton = new System.Windows.Forms.Button(); this.ignoreButton = new System.Windows.Forms.Button(); this.progressBar1 = new System.Windows.Forms.ProgressBar(); - this.changelogTreeView = new CreamInstaller.CustomTreeView(); + this.changelogTreeView = new CustomTreeView(); this.SuspendLayout(); // // label1 diff --git a/CreamInstaller/Forms/MainForm.cs b/CreamInstaller/Forms/MainForm.cs index 7117644..9ed967d 100644 --- a/CreamInstaller/Forms/MainForm.cs +++ b/CreamInstaller/Forms/MainForm.cs @@ -9,6 +9,9 @@ using System.Threading.Tasks; using System.Web; using System.Windows.Forms; +using CreamInstaller.Classes; +using CreamInstaller.Forms.Components; + using HtmlAgilityPack; using Onova; @@ -113,7 +116,7 @@ internal partial class MainForm : CustomForm document.LoadHtml(reader.ReadToEnd()); foreach (HtmlNode node in document.DocumentNode.SelectNodes("//div[@data-test-selector='body-content']/ul/li")) { - changelogTreeView.TryMethodInvoke(delegate + Program.Invoke(changelogTreeView, delegate { TreeNode change = new(); change.Text = $"{HttpUtility.HtmlDecode(node.InnerText)}"; diff --git a/CreamInstaller/Forms/SelectForm.Designer.cs b/CreamInstaller/Forms/SelectForm.Designer.cs index a128c7b..c7480c8 100644 --- a/CreamInstaller/Forms/SelectForm.Designer.cs +++ b/CreamInstaller/Forms/SelectForm.Designer.cs @@ -1,6 +1,8 @@  using System.Windows.Forms; +using CreamInstaller.Forms.Components; + namespace CreamInstaller { partial class SelectForm @@ -40,7 +42,7 @@ namespace CreamInstaller this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.blockedGamesCheckBox = new System.Windows.Forms.CheckBox(); this.blockProtectedHelpButton = new System.Windows.Forms.Button(); - this.selectionTreeView = new CreamInstaller.CustomTreeView(); + this.selectionTreeView = new CustomTreeView(); this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel(); this.allCheckBox = new System.Windows.Forms.CheckBox(); this.progressBar = new System.Windows.Forms.ProgressBar(); diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index 49747c5..5ef280e 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -10,6 +10,9 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using CreamInstaller.Classes; +using CreamInstaller.Forms.Components; + using Gameloop.Vdf.Linq; using Microsoft.Win32; @@ -117,19 +120,15 @@ internal partial class SelectForm : CustomForm return treeNodes; } - internal List RunningTasks = new(); + private static void UpdateRemaining(Label label, List list, string descriptor) => + label.Text = list.Any() ? $"Remaining {descriptor} ({list.Count}): " + string.Join(", ", list).Replace("&", "&&") : ""; - private List RemainingGames = new(); - private void UpdateRemainingGames() - { - if (Program.Canceled) return; - progressLabelGames.Text = $"Remaining games ({RemainingGames.Count}): " - + (RemainingGames.Any() ? string.Join(", ", RemainingGames).Replace("&", "&&") : "None"); - } + private readonly List RemainingGames = new(); + private void UpdateRemainingGames() => UpdateRemaining(progressLabelGames, RemainingGames, "games"); private void AddToRemainingGames(string gameName) { if (Program.Canceled) return; - progressLabelGames.TryMethodInvoke(delegate + Program.Invoke(progressLabelGames, delegate { if (Program.Canceled) return; if (!RemainingGames.Contains(gameName)) @@ -140,7 +139,7 @@ internal partial class SelectForm : CustomForm private void RemoveFromRemainingGames(string gameName) { if (Program.Canceled) return; - progressLabelGames.TryMethodInvoke(delegate + Program.Invoke(progressLabelGames, delegate { if (Program.Canceled) return; if (RemainingGames.Contains(gameName)) @@ -149,17 +148,12 @@ internal partial class SelectForm : CustomForm }); } - private List RemainingDLCs = new(); - private void UpdateRemainingDLCs() - { - if (Program.Canceled) return; - progressLabelDLCs.Text = $"Remaining DLCs ({RemainingDLCs.Count}): " - + (RemainingDLCs.Any() ? string.Join(", ", RemainingDLCs).Replace("&", "&&") : "None"); - } + private readonly List RemainingDLCs = new(); + private void UpdateRemainingDLCs() => UpdateRemaining(progressLabelDLCs, RemainingDLCs, "DLCs"); private void AddToRemainingDLCs(string dlcId) { if (Program.Canceled) return; - progressLabelDLCs.TryMethodInvoke(delegate + Program.Invoke(progressLabelDLCs, delegate { if (Program.Canceled) return; if (!RemainingDLCs.Contains(dlcId)) @@ -170,7 +164,7 @@ internal partial class SelectForm : CustomForm private void RemoveFromRemainingDLCs(string dlcId) { if (Program.Canceled) return; - progressLabelDLCs.TryMethodInvoke(delegate + Program.Invoke(progressLabelDLCs, delegate { if (Program.Canceled) return; if (RemainingDLCs.Contains(dlcId)) @@ -179,6 +173,7 @@ internal partial class SelectForm : CustomForm }); } + internal readonly List RunningTasks = new(); private async Task GetCreamApiApplicablePrograms(IProgress progress) { if (Program.Canceled) return; @@ -295,7 +290,7 @@ internal partial class SelectForm : CustomForm await task; } if (Program.Canceled) return; - selectionTreeView.TryMethodInvoke(delegate + Program.Invoke(selectionTreeView, delegate { if (Program.Canceled) return; TreeNode programNode = TreeNodes.Find(s => s.Name == "" + appId) ?? new(); diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index 894bd51..5d564b9 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -10,6 +10,8 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using CreamInstaller.Classes; + namespace CreamInstaller; internal static class Program @@ -18,7 +20,7 @@ internal static class Program internal static readonly Assembly EntryAssembly = Assembly.GetEntryAssembly(); internal static readonly Process CurrentProcess = Process.GetCurrentProcess(); internal static readonly string CurrentProcessFilePath = CurrentProcess.MainModule.FileName; - internal static readonly string CurrentProcessDirectory = CurrentProcessFilePath.Substring(0, CurrentProcessFilePath.LastIndexOf("\\")); + internal static readonly string CurrentProcessDirectory = CurrentProcessFilePath[..CurrentProcessFilePath.LastIndexOf("\\")]; internal static readonly string BackupFileExtension = ".creaminstaller.backup"; internal static bool BlockProtectedGames = true; @@ -123,14 +125,7 @@ internal static class Program await SteamCMD.Kill(); } - internal static void TryMethodInvoke(this Control control, MethodInvoker methodInvoker) - { - try - { - control.Invoke(methodInvoker); - } - catch { } - } + internal static void Invoke(this Control control, MethodInvoker methodInvoker) => control.Invoke(methodInvoker); private static void OnApplicationExit(object s, EventArgs e) => Cleanup(); diff --git a/CreamInstaller/Resources/FileResourceExtensions.cs b/CreamInstaller/Resources/FileResourceExtensions.cs index 018689a..c908f25 100644 --- a/CreamInstaller/Resources/FileResourceExtensions.cs +++ b/CreamInstaller/Resources/FileResourceExtensions.cs @@ -1,6 +1,6 @@ using System.IO; -namespace CreamInstaller; +namespace CreamInstaller.Resources; internal static class FileResourceExtensions {