fix branch detection

This commit is contained in:
pointfeev 2023-01-29 22:31:02 -05:00
parent 2d773481cc
commit eec1e9821d
3 changed files with 91 additions and 57 deletions

View file

@ -190,49 +190,67 @@ internal static class SteamCMD
internal static async Task<VProperty> GetAppInfo(string appId, string branch = "public", int buildId = 0) internal static async Task<VProperty> GetAppInfo(string appId, string branch = "public", int buildId = 0)
{ {
if (Program.Canceled) int attempts = 0;
return null; while (!Program.Canceled)
string appUpdateFile = $@"{AppInfoPath}\{appId}.vdf";
restart:
if (Program.Canceled)
return null;
string output = appUpdateFile.ReadFile();
if (output is null)
{ {
output = await Run(appId) ?? ""; attempts++;
int openBracket = output.IndexOf("{", StringComparison.Ordinal); if (attempts > 10)
int closeBracket = output.LastIndexOf("}", StringComparison.Ordinal);
if (openBracket != -1 && closeBracket != -1 && closeBracket > openBracket)
{ {
output = $"\"{appId}\"\n" + output[openBracket..(1 + closeBracket)]; #if DEBUG
output = output.Replace("ERROR! Failed to install app '4' (Invalid platform)", ""); DebugForm.Current.Log("Failed to query SteamCMD after 10 tries: " + appId + " (" + branch + ")", LogTextBox.Warning);
appUpdateFile.WriteFile(output); #endif
break;
} }
else string appUpdateFile = $@"{AppInfoPath}\{appId}.vdf";
goto restart; string output = appUpdateFile.ReadFile();
} if (output is null)
if (Program.Canceled) {
return null; output = await Run(appId) ?? "";
if (!ValveDataFile.TryDeserialize(output, out VProperty appInfo) || appInfo.Value is VValue) 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<string> dlcAppIds = await ParseDlcAppIds(appInfo);
foreach (string dlcAppUpdateFile in dlcAppIds.Select(id => $@"{AppInfoPath}\{id}.vdf"))
dlcAppUpdateFile.DeleteFile();
appUpdateFile.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 null;
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<string> dlcAppIds = await ParseDlcAppIds(appInfo);
foreach (string dlcAppUpdateFile in dlcAppIds.Select(id => $@"{AppInfoPath}\{id}.vdf"))
dlcAppUpdateFile.DeleteFile();
appUpdateFile.DeleteFile();
goto restart;
} }
internal static async Task<List<string>> ParseDlcAppIds(VProperty appInfo) internal static async Task<List<string>> ParseDlcAppIds(VProperty appInfo)

View file

@ -69,7 +69,15 @@ internal static class SteamLibrary
continue; continue;
if (!int.TryParse(buildId, out int buildIdInt)) if (!int.TryParse(buildId, out int buildIdInt))
continue; 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)) if (string.IsNullOrWhiteSpace(branch))
branch = "public"; branch = "public";
games.Add((appId, name, branch, buildIdInt, gameDirectory)); games.Add((appId, name, branch, buildIdInt, gameDirectory));

View file

@ -30,10 +30,9 @@ internal static class SteamStore
internal static async Task<AppData> QueryStoreAPI(string appId, bool isDlc = false, int attempts = 0) internal static async Task<AppData> QueryStoreAPI(string appId, bool isDlc = false, int attempts = 0)
{ {
while (true) while (!Program.Canceled)
{ {
if (Program.Canceled) attempts++;
return null;
string cacheFile = ProgramData.AppInfoPath + @$"\{appId}.json"; string cacheFile = ProgramData.AppInfoPath + @$"\{appId}.json";
bool cachedExists = cacheFile.FileExists(); bool cachedExists = cacheFile.FileExists();
if (!cachedExists || ProgramData.CheckCooldown(appId, isDlc ? CooldownDlc : CooldownGame)) if (!cachedExists || ProgramData.CheckCooldown(appId, isDlc ? CooldownDlc : CooldownGame))
@ -54,8 +53,8 @@ internal static class SteamStore
{ {
#if DEBUG #if DEBUG
DebugForm.Current.Log( DebugForm.Current.Log(
$"Query unsuccessful for appid {appId}{(isDlc ? " (DLC)" : "")}: {app.Value.ToString(Formatting.None)}", "Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "")
LogTextBox.Warning); + ": Query unsuccessful (" + app.Value.ToString(Formatting.None) + ")", LogTextBox.Warning);
#endif #endif
if (data is null) if (data is null)
return null; return null;
@ -70,8 +69,8 @@ internal static class SteamStore
#if DEBUG #if DEBUG
(Exception e) (Exception e)
{ {
DebugForm.Current.Log( DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "")
$"Unsuccessful serialization of query for appid {appId}{(isDlc ? " (DLC)" : "")}: {e.GetType()} ({e.Message})"); + ": Unsuccessful serialization (" + e.Message + ")");
} }
#else #else
{ {
@ -81,22 +80,22 @@ internal static class SteamStore
return data; return data;
} }
#if DEBUG #if DEBUG
DebugForm.Current.Log( DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "")
$"Response data null for appid {appId}{(isDlc ? " (DLC)" : "")}: {app.Value.ToString(Formatting.None)}"); + ": Response data null (" + app.Value.ToString(Formatting.None) + ")");
#endif #endif
} }
#if DEBUG #if DEBUG
else else
DebugForm.Current.Log( DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "")
$"Response details null for appid {appId}{(isDlc ? " (DLC)" : "")}: {app.Value.ToString(Formatting.None)}"); + ": Response details null (" + app.Value.ToString(Formatting.None) + ")");
#endif #endif
} }
catch catch
#if DEBUG #if DEBUG
(Exception e) (Exception e)
{ {
DebugForm.Current.Log( DebugForm.Current.Log("Steam store query failed on attempt #" + attempts + " for " + appId + (isDlc ? " (DLC)" : "")
$"Unsuccessful deserialization of query for appid {appId}{(isDlc ? " (DLC)" : "")}: {e.GetType()} ({e.Message})"); + ": Unsuccessful deserialization (" + e.Message + ")");
} }
#else #else
{ {
@ -105,13 +104,15 @@ internal static class SteamStore
#endif #endif
#if DEBUG #if DEBUG
else 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 #endif
} }
else else
{ {
#if DEBUG #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 #endif
} }
} }
@ -124,10 +125,17 @@ internal static class SteamStore
{ {
cacheFile.DeleteFile(); cacheFile.DeleteFile();
} }
if (isDlc || attempts >= 10) if (isDlc)
return null; break;
if (attempts > 10)
{
#if DEBUG
DebugForm.Current.Log("Failed to query Steam store after 10 tries: " + appId);
#endif
break;
}
Thread.Sleep(1000); Thread.Sleep(1000);
attempts = ++attempts;
} }
return null;
} }
} }