From eec1e9821d3f13e3a9ed1db216d4ae3811fa77b9 Mon Sep 17 00:00:00 2001 From: pointfeev Date: Sun, 29 Jan 2023 22:31:02 -0500 Subject: [PATCH] fix branch detection --- CreamInstaller/Platforms/Steam/SteamCMD.cs | 94 +++++++++++-------- .../Platforms/Steam/SteamLibrary.cs | 10 +- CreamInstaller/Platforms/Steam/SteamStore.cs | 44 +++++---- 3 files changed, 91 insertions(+), 57 deletions(-) diff --git a/CreamInstaller/Platforms/Steam/SteamCMD.cs b/CreamInstaller/Platforms/Steam/SteamCMD.cs index 87b2222..ff47b05 100644 --- a/CreamInstaller/Platforms/Steam/SteamCMD.cs +++ b/CreamInstaller/Platforms/Steam/SteamCMD.cs @@ -190,49 +190,67 @@ internal static class SteamCMD internal static async Task GetAppInfo(string appId, string branch = "public", int buildId = 0) { - if (Program.Canceled) - return null; - string appUpdateFile = $@"{AppInfoPath}\{appId}.vdf"; - restart: - if (Program.Canceled) - return null; - string output = appUpdateFile.ReadFile(); - if (output is null) + int attempts = 0; + while (!Program.Canceled) { - output = await Run(appId) ?? ""; - int openBracket = output.IndexOf("{", StringComparison.Ordinal); - int closeBracket = output.LastIndexOf("}", StringComparison.Ordinal); - if (openBracket != -1 && closeBracket != -1 && closeBracket > openBracket) + attempts++; + if (attempts > 10) { - output = $"\"{appId}\"\n" + output[openBracket..(1 + closeBracket)]; - output = output.Replace("ERROR! Failed to install app '4' (Invalid platform)", ""); - appUpdateFile.WriteFile(output); +#if DEBUG + DebugForm.Current.Log("Failed to query SteamCMD after 10 tries: " + appId + " (" + branch + ")", LogTextBox.Warning); +#endif + break; } - else - goto restart; - } - if (Program.Canceled) - return null; - if (!ValveDataFile.TryDeserialize(output, out VProperty appInfo) || appInfo.Value is VValue) - { + string appUpdateFile = $@"{AppInfoPath}\{appId}.vdf"; + string output = appUpdateFile.ReadFile(); + if (output is null) + { + output = await Run(appId) ?? ""; + int openBracket = output.IndexOf("{", StringComparison.Ordinal); + int closeBracket = output.LastIndexOf("}", StringComparison.Ordinal); + if (openBracket != -1 && closeBracket != -1 && closeBracket > openBracket) + { + output = $"\"{appId}\"\n" + output[openBracket..(1 + closeBracket)]; + output = output.Replace("ERROR! Failed to install app '4' (Invalid platform)", ""); + appUpdateFile.WriteFile(output); + } + else + { +#if DEBUG + DebugForm.Current.Log("SteamCMD query failed on attempt #" + attempts + " for " + appId + " (" + branch + "): Bad output", + LogTextBox.Warning); +#endif + continue; + } + } + if (!ValveDataFile.TryDeserialize(output, out VProperty appInfo) || appInfo.Value is VValue) + { + appUpdateFile.DeleteFile(); +#if DEBUG + DebugForm.Current.Log("SteamCMD query failed on attempt #" + attempts + " for " + appId + " (" + branch + "): Deserialization failed", + LogTextBox.Warning); +#endif + continue; + } + if (appInfo.Value.Children().ToList().Count == 0) + return appInfo; + VToken type = appInfo.Value.GetChild("common")?.GetChild("type"); + if (type is not null && type.ToString() != "Game") + return appInfo; + string buildid = appInfo.Value.GetChild("depots")?.GetChild("branches")?.GetChild(branch)?.GetChild("buildid")?.ToString(); + if (buildid is null && type is not null) + return appInfo; + if (type is not null && (!int.TryParse(buildid, out int gamebuildId) || gamebuildId >= buildId)) + return appInfo; + List dlcAppIds = await ParseDlcAppIds(appInfo); + foreach (string dlcAppUpdateFile in dlcAppIds.Select(id => $@"{AppInfoPath}\{id}.vdf")) + dlcAppUpdateFile.DeleteFile(); appUpdateFile.DeleteFile(); - goto restart; +#if DEBUG + DebugForm.Current.Log("SteamCMD query skipped on attempt #" + attempts + " for " + appId + " (" + branch + "): Outdated cache", LogTextBox.Warning); +#endif } - if (appInfo.Value.Children().ToList().Count == 0) - return appInfo; - VToken type = appInfo.Value.GetChild("common")?.GetChild("type"); - if (type is not null && type.ToString() != "Game") - return appInfo; - string buildid = appInfo.Value.GetChild("depots")?.GetChild("branches")?.GetChild(branch)?.GetChild("buildid")?.ToString(); - if (buildid is null && type is not null) - return appInfo; - if (type is not null && (!int.TryParse(buildid, out int gamebuildId) || gamebuildId >= buildId)) - return appInfo; - List dlcAppIds = await ParseDlcAppIds(appInfo); - foreach (string dlcAppUpdateFile in dlcAppIds.Select(id => $@"{AppInfoPath}\{id}.vdf")) - dlcAppUpdateFile.DeleteFile(); - appUpdateFile.DeleteFile(); - goto restart; + return null; } internal static async Task> ParseDlcAppIds(VProperty appInfo) diff --git a/CreamInstaller/Platforms/Steam/SteamLibrary.cs b/CreamInstaller/Platforms/Steam/SteamLibrary.cs index 854fa44..028e9fa 100644 --- a/CreamInstaller/Platforms/Steam/SteamLibrary.cs +++ b/CreamInstaller/Platforms/Steam/SteamLibrary.cs @@ -69,7 +69,15 @@ internal static class SteamLibrary continue; if (!int.TryParse(buildId, out int buildIdInt)) continue; - string branch = result.Value.GetChild("UserConfig")?.GetChild("betakey")?.ToString(); + VToken userConfig = result.Value.GetChild("UserConfig"); + string branch = userConfig?.GetChild("BetaKey")?.ToString(); + branch ??= userConfig?.GetChild("betakey")?.ToString(); + if (branch is null) + { + VToken mountedConfig = result.Value.GetChild("MountedConfig"); + branch = mountedConfig?.GetChild("BetaKey")?.ToString(); + branch ??= mountedConfig?.GetChild("betakey")?.ToString(); + } if (string.IsNullOrWhiteSpace(branch)) branch = "public"; games.Add((appId, name, branch, buildIdInt, gameDirectory)); diff --git a/CreamInstaller/Platforms/Steam/SteamStore.cs b/CreamInstaller/Platforms/Steam/SteamStore.cs index 9f18831..05f256f 100644 --- a/CreamInstaller/Platforms/Steam/SteamStore.cs +++ b/CreamInstaller/Platforms/Steam/SteamStore.cs @@ -30,10 +30,9 @@ internal static class SteamStore internal static async Task QueryStoreAPI(string appId, bool isDlc = false, int attempts = 0) { - while (true) + while (!Program.Canceled) { - if (Program.Canceled) - return null; + attempts++; string cacheFile = ProgramData.AppInfoPath + @$"\{appId}.json"; bool cachedExists = cacheFile.FileExists(); if (!cachedExists || ProgramData.CheckCooldown(appId, isDlc ? CooldownDlc : CooldownGame)) @@ -54,8 +53,8 @@ internal static class SteamStore { #if DEBUG DebugForm.Current.Log( - $"Query unsuccessful for appid {appId}{(isDlc ? " (DLC)" : "")}: {app.Value.ToString(Formatting.None)}", - LogTextBox.Warning); + "Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "") + + ": Query unsuccessful (" + app.Value.ToString(Formatting.None) + ")", LogTextBox.Warning); #endif if (data is null) return null; @@ -70,8 +69,8 @@ internal static class SteamStore #if DEBUG (Exception e) { - DebugForm.Current.Log( - $"Unsuccessful serialization of query for appid {appId}{(isDlc ? " (DLC)" : "")}: {e.GetType()} ({e.Message})"); + DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "") + + ": Unsuccessful serialization (" + e.Message + ")"); } #else { @@ -81,22 +80,22 @@ internal static class SteamStore return data; } #if DEBUG - DebugForm.Current.Log( - $"Response data null for appid {appId}{(isDlc ? " (DLC)" : "")}: {app.Value.ToString(Formatting.None)}"); + DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "") + + ": Response data null (" + app.Value.ToString(Formatting.None) + ")"); #endif } #if DEBUG else - DebugForm.Current.Log( - $"Response details null for appid {appId}{(isDlc ? " (DLC)" : "")}: {app.Value.ToString(Formatting.None)}"); + DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "") + + ": Response details null (" + app.Value.ToString(Formatting.None) + ")"); #endif } catch #if DEBUG (Exception e) { - DebugForm.Current.Log( - $"Unsuccessful deserialization of query for appid {appId}{(isDlc ? " (DLC)" : "")}: {e.GetType()} ({e.Message})"); + DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "") + + ": Unsuccessful deserialization (" + e.Message + ")"); } #else { @@ -105,13 +104,15 @@ internal static class SteamStore #endif #if DEBUG else - DebugForm.Current.Log("Response deserialization null for appid " + appId); + DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "") + + ": Response deserialization null"); #endif } else { #if DEBUG - DebugForm.Current.Log("Response null for appid " + appId, LogTextBox.Warning); + DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "") + ": Response null", + LogTextBox.Warning); #endif } } @@ -124,10 +125,17 @@ internal static class SteamStore { cacheFile.DeleteFile(); } - if (isDlc || attempts >= 10) - return null; + if (isDlc) + break; + if (attempts > 10) + { +#if DEBUG + DebugForm.Current.Log("Failed to query Steam store after 10 tries: " + appId); +#endif + break; + } Thread.Sleep(1000); - attempts = ++attempts; } + return null; } } \ No newline at end of file