From ffbbeedeffdaca33f0cf336c1ab458408c054f3c Mon Sep 17 00:00:00 2001 From: pointfeev Date: Mon, 24 Jan 2022 00:53:15 -0500 Subject: [PATCH] v2.2.4.0 - Optimized the number of SteamCMD instances that would open for appinfo gathering processes - Optimized the install form update delays so they're now way faster and still don't glitch the log - Added a 10ms delay to DLC iterations to reduce control & window freezing - Select form cancelling now runs on the proper thread to reduce cancellation delay --- CreamInstaller/Classes/SteamCMD.cs | 21 +++++++++------------ CreamInstaller/CreamInstaller.csproj | 2 +- CreamInstaller/Forms/InstallForm.cs | 12 ++++++------ CreamInstaller/Forms/SelectForm.cs | 11 +++++++---- CreamInstaller/Program.cs | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/CreamInstaller/Classes/SteamCMD.cs b/CreamInstaller/Classes/SteamCMD.cs index 8468761..e12ecb3 100644 --- a/CreamInstaller/Classes/SteamCMD.cs +++ b/CreamInstaller/Classes/SteamCMD.cs @@ -44,14 +44,12 @@ namespace CreamInstaller StandardOutputEncoding = Encoding.UTF8, StandardErrorEncoding = Encoding.UTF8 }; - using (Process process = Process.Start(processStartInfo)) - { - process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data); - process.BeginOutputReadLine(); - process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data); - process.BeginErrorReadLine(); - process.WaitForExit(); - } + using Process process = Process.Start(processStartInfo); + process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data); + process.BeginOutputReadLine(); + process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data); + process.BeginErrorReadLine(); + process.WaitForExit(); return string.Join("\r\n", logs); }); @@ -91,8 +89,7 @@ namespace CreamInstaller output = File.ReadAllText(appUpdateFile, Encoding.UTF8); else { - await Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +force_install_dir {appUpdatePath} +app_update 4 +quit"); - output = await Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +quit"); + output = await Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +force_install_dir {appUpdatePath} +app_update 4 +quit"); int openBracket = output.IndexOf("{"); int closeBracket = output.LastIndexOf("}"); if (openBracket != -1 && closeBracket != -1) @@ -112,7 +109,7 @@ namespace CreamInstaller } } if (appInfo.Value is VValue) goto restart; - if (appInfo is null || (appInfo.Value is not VValue && appInfo.Value.Children().ToList().Count == 0)) + if (appInfo is null || appInfo.Value is not VValue && appInfo.Value.Children().ToList().Count == 0) return appInfo; VToken type = appInfo.Value is VValue ? null : appInfo.Value?["common"]?["type"]; if (type is null || type.ToString() == "Game") @@ -137,7 +134,7 @@ namespace CreamInstaller internal static async Task> ParseDlcAppIds(VProperty appInfo) => await Task.Run(() => { List dlcIds = new(); - if (appInfo is not VProperty) return dlcIds; + if (Program.Canceled || appInfo is not VProperty) return dlcIds; if (appInfo.Value["extended"] is not null) foreach (VProperty property in appInfo.Value["extended"]) if (property.Key.ToString() == "listofdlc") diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index cae69ba..fe81bae 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -5,7 +5,7 @@ true Resources\ini.ico true - 2.2.3.0 + 2.2.4.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. diff --git a/CreamInstaller/Forms/InstallForm.cs b/CreamInstaller/Forms/InstallForm.cs index ad7d64a..0ee66a6 100644 --- a/CreamInstaller/Forms/InstallForm.cs +++ b/CreamInstaller/Forms/InstallForm.cs @@ -42,7 +42,7 @@ namespace CreamInstaller if (logTextBox.Text.Length > 0) logTextBox.AppendText(Environment.NewLine, color); logTextBox.AppendText(text, color); } - await Task.Run(() => Thread.Sleep(1)); // to keep the text box control from glitching + await Task.Run(() => Thread.Sleep(0)); // to keep the text box control from glitching } internal async Task WriteConfiguration(StreamWriter writer, int steamAppId, string name, SortedList steamDlcApps) @@ -170,7 +170,7 @@ namespace CreamInstaller } ++CompleteOperationsCount; } - await Program.Cleanup(); + Program.Cleanup(); List FailedSelections = ProgramSelection.AllUsableEnabled; if (FailedSelections.Any()) if (FailedSelections.Count == 1) throw new CustomMessageException($"Operation failed for {FailedSelections.First().Name}."); @@ -221,21 +221,21 @@ namespace CreamInstaller private void OnAccept(object sender, EventArgs e) { - Program.Cleanup().Wait(); + Program.Cleanup(); Close(); } private void OnRetry(object sender, EventArgs e) { - Program.Cleanup().Wait(); + Program.Cleanup(); Start(); } - private void OnCancel(object sender, EventArgs e) => Program.Cleanup().Wait(); + private void OnCancel(object sender, EventArgs e) => Program.Cleanup(); private void OnReselect(object sender, EventArgs e) { - Program.Cleanup().Wait(); + Program.Cleanup(); Reselecting = true; Close(); } diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index 0f290f6..c627a19 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -6,6 +6,7 @@ using System.Drawing; using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -190,8 +191,9 @@ namespace CreamInstaller }); dlcTasks.Add(task); RunningTasks.Add(task); + progress.Report(-RunningTasks.Count); + Thread.Sleep(10); // to reduce control & window freezing } - progress.Report(-RunningTasks.Count); } else if (appId > 0) return; if (Program.Canceled) return; @@ -250,11 +252,11 @@ namespace CreamInstaller } } }); + progress.Report(++cur); })); + progress.Report(-RunningTasks.Count); } - progress.Report(-RunningTasks.Count); - progress.Report(cur); foreach (Task task in RunningTasks.ToList()) { if (Program.Canceled) return; @@ -290,6 +292,7 @@ namespace CreamInstaller IProgress iProgress = progress; progress.ProgressChanged += (sender, _progress) => { + if (Program.Canceled) return; if (_progress < 0) maxProgress = -_progress; else curProgress = _progress; int p = Math.Max(Math.Min((int)((float)(curProgress / (float)maxProgress) * 100), 100), 0); @@ -507,7 +510,7 @@ namespace CreamInstaller private void OnCancel(object sender, EventArgs e) { progressLabel.Text = "Cancelling . . . "; - Task.Run(async () => await Program.Cleanup()); + Program.Cleanup(); } private void OnAllCheckBoxChanged(object sender, EventArgs e) diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index c00d975..6601f54 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -116,13 +116,13 @@ namespace CreamInstaller internal static List ProgramSelections = new(); internal static bool Canceled = false; - internal static async Task Cleanup(bool cancel = true) + internal static async void Cleanup(bool cancel = true) { Canceled = cancel; await SteamCMD.Kill(); } - private static void OnApplicationExit(object s, EventArgs e) => Cleanup().Wait(); + private static void OnApplicationExit(object s, EventArgs e) => Cleanup(); internal static void InheritLocation(this Form form, Form fromForm) {