error fixes

This commit is contained in:
pointfeev 2021-11-06 05:25:25 -04:00
parent 351847727b
commit 51d3a1c9cb
No known key found for this signature in database
GPG key ID: AA14DC36C4D7D13C
2 changed files with 31 additions and 39 deletions

View file

@ -139,8 +139,6 @@ namespace CreamInstaller
List<Task> dlcTasks = new(); List<Task> dlcTasks = new();
List<int> dlcIds = new(); List<int> dlcIds = new();
if (!(appInfo is null)) if (!(appInfo is null))
{
try
{ {
if (!(appInfo.Value["extended"] is null)) if (!(appInfo.Value["extended"] is null))
foreach (VProperty property in appInfo.Value["extended"]) foreach (VProperty property in appInfo.Value["extended"])
@ -148,18 +146,12 @@ namespace CreamInstaller
foreach (string id in property.Value.ToString().Split(",")) foreach (string id in property.Value.ToString().Split(","))
if (!dlcIds.Contains(int.Parse(id))) if (!dlcIds.Contains(int.Parse(id)))
dlcIds.Add(int.Parse(id)); dlcIds.Add(int.Parse(id));
}
catch { }
try
{
if (!(appInfo.Value["depots"] is null)) if (!(appInfo.Value["depots"] is null))
foreach (VProperty _property in appInfo.Value["depots"]) foreach (VProperty _property in appInfo.Value["depots"])
if (int.TryParse(_property.Key.ToString(), out int _)) if (int.TryParse(_property.Key.ToString(), out int _) && !(_property.Value is VValue))
if (int.TryParse(_property.Value?["dlcappid"]?.ToString(), out int appid) && !dlcIds.Contains(appid)) if (int.TryParse(_property.Value?["dlcappid"]?.ToString(), out int appid) && !dlcIds.Contains(appid))
dlcIds.Add(appid); dlcIds.Add(appid);
} }
catch { }
}
if (!(dlcIds is null) && dlcIds.Count > 0) if (!(dlcIds is null) && dlcIds.Count > 0)
{ {
foreach (int id in dlcIds) foreach (int id in dlcIds)
@ -170,7 +162,7 @@ namespace CreamInstaller
if (Program.Canceled) return; if (Program.Canceled) return;
string dlcName = null; string dlcName = null;
VProperty dlcAppInfo = null; VProperty dlcAppInfo = null;
if (SteamCMD.GetAppInfo(id, 0, out dlcAppInfo)) try { dlcName = dlcAppInfo?.Value?["common"]?["name"]?.ToString(); } catch { } if (SteamCMD.GetAppInfo(id, 0, out dlcAppInfo)) dlcName = dlcAppInfo?.Value?["common"]?["name"]?.ToString();
if (Program.Canceled) return; if (Program.Canceled) return;
if (string.IsNullOrWhiteSpace(dlcName)) dlcName = $"Unnamed DLC ({id})"; if (string.IsNullOrWhiteSpace(dlcName)) dlcName = $"Unnamed DLC ({id})";
dlc.Add(new Tuple<int, string>(id, dlcName)); dlc.Add(new Tuple<int, string>(id, dlcName));

View file

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq;
using System.Net; using System.Net;
namespace CreamInstaller namespace CreamInstaller
@ -70,32 +71,31 @@ namespace CreamInstaller
Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +quit", out output); Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +quit", out output);
int openBracket = output.IndexOf("{"); int openBracket = output.IndexOf("{");
int closeBracket = output.LastIndexOf("}"); int closeBracket = output.LastIndexOf("}");
if (openBracket != -1 && closeBracket != -1)
{
output = $"\"{appId}\"\n" + output.Substring(openBracket, 1 + closeBracket - openBracket); output = $"\"{appId}\"\n" + output.Substring(openBracket, 1 + closeBracket - openBracket);
File.WriteAllText(appUpdateFile, output); File.WriteAllText(appUpdateFile, output);
} }
}
if (Program.Canceled || output is null) return false; if (Program.Canceled || output is null) return false;
appInfo = VdfConvert.Deserialize(output); appInfo = VdfConvert.Deserialize(output);
try
{
VToken type = appInfo?.Value?["common"]?["type"]; VToken type = appInfo?.Value?["common"]?["type"];
if (type is null || type.ToString() == "Game") if (type is null || type.ToString() == "Game")
{ {
string buildid = appInfo.Value["depots"]?["public"]?["buildid"]?.ToString(); string buildid = appInfo?.Value?["depots"]?["public"]?["buildid"]?.ToString();
buildid = buildid ?? appInfo.Value["depots"]?["branches"]?["public"]?["buildid"]?.ToString(); if (appInfo?.Value?.Children()?.ToList()?.Count > 0 && !(buildid is null)
if (type is null || int.Parse(buildid) < buildId && (type is null || int.Parse(buildid?.ToString()) < buildId
|| appInfo.Value["extended"] is null || appInfo.Value["extended"] is null
|| appInfo.Value["depots"] is null) || appInfo.Value["depots"] is null))
{ {
if (retries.TryGetValue(appId, out int count)) retries[appId] = ++count; //if (retries.TryGetValue(appId, out int count)) retries[appId] = ++count;
else retries.Add(appId, 1); //else retries.Add(appId, 1);
if (count > 3) return false; //if (count > 10) return false;
File.Delete(appUpdateFile); File.Delete(appUpdateFile);
bool success = GetAppInfo(appId, buildId, out appInfo); bool success = GetAppInfo(appId, buildId, out appInfo);
return success; return success;
} }
} }
}
catch { }
return true; return true;
} }