From d5893f7470829a5d5363c84a8bc8cdbc84fcc23f Mon Sep 17 00:00:00 2001 From: pointfeev Date: Thu, 10 Feb 2022 10:50:53 -0500 Subject: [PATCH] SteamCMD setup tweaks --- CreamInstaller/Classes/SteamCMD.cs | 22 +++++++++++++++++++--- CreamInstaller/Forms/SelectForm.cs | 19 ++++--------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CreamInstaller/Classes/SteamCMD.cs b/CreamInstaller/Classes/SteamCMD.cs index f257ff9..46494ce 100644 --- a/CreamInstaller/Classes/SteamCMD.cs +++ b/CreamInstaller/Classes/SteamCMD.cs @@ -54,9 +54,10 @@ internal static class SteamCMD return string.Join("\r\n", logs); }); - internal static async Task Setup() + internal static async Task Setup(IProgress progress = null) { await Kill(); + if (!Directory.Exists(DirectoryPath)) Directory.CreateDirectory(DirectoryPath); if (!File.Exists(FilePath)) { using (HttpClient httpClient = new()) @@ -74,7 +75,20 @@ internal static class SteamCMD Directory.CreateDirectory(AppInfoPath); File.WriteAllText(AppInfoVersionPath, Application.ProductVersion, Encoding.UTF8); } - if (!File.Exists(DllPath)) await Run($@"+quit"); + if (!File.Exists(DllPath)) + { + FileSystemWatcher watcher = new(DirectoryPath); + watcher.Filter = "*"; + watcher.IncludeSubdirectories = true; + watcher.EnableRaisingEvents = true; + if (File.Exists(DllPath)) progress.Report(-15); // update (not used at the moment) + else progress.Report(-1660); // install + int cur = 0; + progress.Report(cur); + watcher.Changed += (sender, e) => progress.Report(++cur); + await Run($@"+quit"); + watcher.Dispose(); + } } internal static async Task GetAppInfo(int appId, string branch = "public", int buildId = 0) @@ -89,7 +103,7 @@ internal static class SteamCMD if (File.Exists(appUpdateFile)) output = File.ReadAllText(appUpdateFile, Encoding.UTF8); else { - output = await Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +force_install_dir {appUpdatePath} +app_update 4 +quit"); + output = await Run($@"+login anonymous +app_info_print {appId} +force_install_dir {appUpdatePath} +app_update 4 +quit"); // we add app_update 4 to allow the app_info_print to finish int openBracket = output.IndexOf("{"); int closeBracket = output.LastIndexOf("}"); if (openBracket != -1 && closeBracket != -1) @@ -129,7 +143,9 @@ internal static class SteamCMD internal static async Task> ParseDlcAppIds(VProperty appInfo) => await Task.Run(() => { List dlcIds = new(); +#pragma warning disable IDE0150 // Prefer 'null' check over type check if (Program.Canceled || appInfo is not VProperty) return dlcIds; +#pragma warning restore IDE0150 // Prefer 'null' check over type check VToken extended = appInfo.Value.GetChild("extended"); if (extended is not null) foreach (VProperty property in extended) diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index 0ad5905..8078754 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -361,27 +361,16 @@ internal partial class SelectForm : CustomForm progress.ProgressChanged += (sender, _progress) => { if (Program.Canceled) return; - if (_progress < 0) maxProgress = -_progress; + if (_progress < 0 || _progress > maxProgress) maxProgress = -_progress; else curProgress = _progress; int p = Math.Max(Math.Min((int)((float)(curProgress / (float)maxProgress) * 100), 100), 0); - progressLabel.Text = setup ? $"Setting up SteamCMD . . . {p}% ({curProgress}/{maxProgress})" + progressLabel.Text = setup ? $"Setting up SteamCMD . . . {p}%" : $"Gathering and caching your applicable games and their DLCs . . . {p}%"; progressBar.Value = p; }; - iProgress.Report(-1660); // not exact, number varies - int cur = 0; - iProgress.Report(cur); - progressLabel.Text = "Setting up SteamCMD . . . "; - if (!Directory.Exists(SteamCMD.DirectoryPath)) Directory.CreateDirectory(SteamCMD.DirectoryPath); - - FileSystemWatcher watcher = new(SteamCMD.DirectoryPath); - watcher.Changed += (sender, e) => iProgress.Report(++cur); - watcher.Filter = "*"; - watcher.IncludeSubdirectories = true; - watcher.EnableRaisingEvents = true; - await SteamCMD.Setup(); - watcher.Dispose(); + progressLabel.Text = $"Setting up SteamCMD . . . "; + await SteamCMD.Setup(iProgress); setup = false; progressLabel.Text = "Gathering and caching your applicable games and their DLCs . . . ";