SteamCMD setup tweaks
This commit is contained in:
parent
f6b7c7899a
commit
d5893f7470
2 changed files with 23 additions and 18 deletions
|
@ -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<int> 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<VProperty> 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<List<int>> ParseDlcAppIds(VProperty appInfo) => await Task.Run(() =>
|
||||
{
|
||||
List<int> 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)
|
||||
|
|
|
@ -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 . . . ";
|
||||
|
|
Loading…
Reference in a new issue