- 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
This commit is contained in:
pointfeev 2022-01-24 00:53:15 -05:00
parent 9729e95e85
commit ffbbeedeff
5 changed files with 25 additions and 25 deletions

View file

@ -44,14 +44,12 @@ namespace CreamInstaller
StandardOutputEncoding = Encoding.UTF8, StandardOutputEncoding = Encoding.UTF8,
StandardErrorEncoding = Encoding.UTF8 StandardErrorEncoding = Encoding.UTF8
}; };
using (Process process = Process.Start(processStartInfo)) using Process process = Process.Start(processStartInfo);
{ process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data);
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data); process.BeginOutputReadLine();
process.BeginOutputReadLine(); process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data);
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data); process.BeginErrorReadLine();
process.BeginErrorReadLine(); process.WaitForExit();
process.WaitForExit();
}
return string.Join("\r\n", logs); return string.Join("\r\n", logs);
}); });
@ -91,8 +89,7 @@ namespace CreamInstaller
output = File.ReadAllText(appUpdateFile, Encoding.UTF8); output = File.ReadAllText(appUpdateFile, Encoding.UTF8);
else 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} +force_install_dir {appUpdatePath} +app_update 4 +quit");
output = await Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +quit");
int openBracket = output.IndexOf("{"); int openBracket = output.IndexOf("{");
int closeBracket = output.LastIndexOf("}"); int closeBracket = output.LastIndexOf("}");
if (openBracket != -1 && closeBracket != -1) if (openBracket != -1 && closeBracket != -1)
@ -112,7 +109,7 @@ namespace CreamInstaller
} }
} }
if (appInfo.Value is VValue) goto restart; 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; return appInfo;
VToken type = appInfo.Value is VValue ? null : appInfo.Value?["common"]?["type"]; VToken type = appInfo.Value is VValue ? null : appInfo.Value?["common"]?["type"];
if (type is null || type.ToString() == "Game") if (type is null || type.ToString() == "Game")
@ -137,7 +134,7 @@ namespace CreamInstaller
internal static async Task<List<int>> ParseDlcAppIds(VProperty appInfo) => await Task.Run(() => internal static async Task<List<int>> ParseDlcAppIds(VProperty appInfo) => await Task.Run(() =>
{ {
List<int> dlcIds = new(); List<int> 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) if (appInfo.Value["extended"] is not null)
foreach (VProperty property in appInfo.Value["extended"]) foreach (VProperty property in appInfo.Value["extended"])
if (property.Key.ToString() == "listofdlc") if (property.Key.ToString() == "listofdlc")

View file

@ -5,7 +5,7 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon> <ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>2.2.3.0</Version> <Version>2.2.4.0</Version>
<PackageIcon>Resources\ini.ico</PackageIcon> <PackageIcon>Resources\ini.ico</PackageIcon>
<PackageIconUrl /> <PackageIconUrl />
<Description>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.</Description> <Description>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.</Description>

View file

@ -42,7 +42,7 @@ namespace CreamInstaller
if (logTextBox.Text.Length > 0) logTextBox.AppendText(Environment.NewLine, color); if (logTextBox.Text.Length > 0) logTextBox.AppendText(Environment.NewLine, color);
logTextBox.AppendText(text, 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<int, string> steamDlcApps) internal async Task WriteConfiguration(StreamWriter writer, int steamAppId, string name, SortedList<int, string> steamDlcApps)
@ -170,7 +170,7 @@ namespace CreamInstaller
} }
++CompleteOperationsCount; ++CompleteOperationsCount;
} }
await Program.Cleanup(); Program.Cleanup();
List<ProgramSelection> FailedSelections = ProgramSelection.AllUsableEnabled; List<ProgramSelection> FailedSelections = ProgramSelection.AllUsableEnabled;
if (FailedSelections.Any()) if (FailedSelections.Any())
if (FailedSelections.Count == 1) throw new CustomMessageException($"Operation failed for {FailedSelections.First().Name}."); 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) private void OnAccept(object sender, EventArgs e)
{ {
Program.Cleanup().Wait(); Program.Cleanup();
Close(); Close();
} }
private void OnRetry(object sender, EventArgs e) private void OnRetry(object sender, EventArgs e)
{ {
Program.Cleanup().Wait(); Program.Cleanup();
Start(); 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) private void OnReselect(object sender, EventArgs e)
{ {
Program.Cleanup().Wait(); Program.Cleanup();
Reselecting = true; Reselecting = true;
Close(); Close();
} }

View file

@ -6,6 +6,7 @@ using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -190,8 +191,9 @@ namespace CreamInstaller
}); });
dlcTasks.Add(task); dlcTasks.Add(task);
RunningTasks.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; else if (appId > 0) return;
if (Program.Canceled) return; if (Program.Canceled) return;
@ -250,11 +252,11 @@ namespace CreamInstaller
} }
} }
}); });
progress.Report(++cur); progress.Report(++cur);
})); }));
progress.Report(-RunningTasks.Count);
} }
progress.Report(-RunningTasks.Count);
progress.Report(cur);
foreach (Task task in RunningTasks.ToList()) foreach (Task task in RunningTasks.ToList())
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
@ -290,6 +292,7 @@ namespace CreamInstaller
IProgress<int> iProgress = progress; IProgress<int> iProgress = progress;
progress.ProgressChanged += (sender, _progress) => progress.ProgressChanged += (sender, _progress) =>
{ {
if (Program.Canceled) return;
if (_progress < 0) maxProgress = -_progress; if (_progress < 0) maxProgress = -_progress;
else curProgress = _progress; else curProgress = _progress;
int p = Math.Max(Math.Min((int)((float)(curProgress / (float)maxProgress) * 100), 100), 0); 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) private void OnCancel(object sender, EventArgs e)
{ {
progressLabel.Text = "Cancelling . . . "; progressLabel.Text = "Cancelling . . . ";
Task.Run(async () => await Program.Cleanup()); Program.Cleanup();
} }
private void OnAllCheckBoxChanged(object sender, EventArgs e) private void OnAllCheckBoxChanged(object sender, EventArgs e)

View file

@ -116,13 +116,13 @@ namespace CreamInstaller
internal static List<ProgramSelection> ProgramSelections = new(); internal static List<ProgramSelection> ProgramSelections = new();
internal static bool Canceled = false; internal static bool Canceled = false;
internal static async Task Cleanup(bool cancel = true) internal static async void Cleanup(bool cancel = true)
{ {
Canceled = cancel; Canceled = cancel;
await SteamCMD.Kill(); 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) internal static void InheritLocation(this Form form, Form fromForm)
{ {