VdfConvert.Deserialize exception fixes

This commit is contained in:
pointfeev 2021-11-09 01:12:46 -05:00
parent 382b47964c
commit 898bb5803c
No known key found for this signature in database
GPG key ID: AA14DC36C4D7D13C
3 changed files with 35 additions and 27 deletions

View file

@ -22,7 +22,7 @@ namespace CreamInstaller
[STAThread] [STAThread]
private static void Main() private static void Main()
{ {
Mutex mutex = new Mutex(true, "CreamInstaller", out bool createdNew); Mutex mutex = new(true, "CreamInstaller", out bool createdNew);
if (createdNew) if (createdNew)
{ {
Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.SetHighDpiMode(HighDpiMode.SystemAware);

View file

@ -34,6 +34,8 @@ namespace CreamInstaller
{ {
string libraryFolder = steamInstallPath + @"\steamapps"; string libraryFolder = steamInstallPath + @"\steamapps";
gameDirectories.Add(libraryFolder); gameDirectories.Add(libraryFolder);
try
{
string libraryFolders = libraryFolder + @"\libraryfolders.vdf"; string libraryFolders = libraryFolder + @"\libraryfolders.vdf";
dynamic property = VdfConvert.Deserialize(File.ReadAllText(libraryFolders)); dynamic property = VdfConvert.Deserialize(File.ReadAllText(libraryFolders));
foreach (dynamic _property in property.Value) foreach (dynamic _property in property.Value)
@ -46,6 +48,8 @@ namespace CreamInstaller
} }
} }
} }
catch {}
}
return gameDirectories; return gameDirectories;
} }
} }
@ -79,6 +83,8 @@ namespace CreamInstaller
{ {
if (Program.Canceled) return false; if (Program.Canceled) return false;
if (Path.GetExtension(directory) == ".acf") if (Path.GetExtension(directory) == ".acf")
{
try
{ {
dynamic property = VdfConvert.Deserialize(File.ReadAllText(directory)); dynamic property = VdfConvert.Deserialize(File.ReadAllText(directory));
string _appid = property.Value.appid.ToString(); string _appid = property.Value.appid.ToString();
@ -94,6 +100,8 @@ namespace CreamInstaller
if (!int.TryParse(_buildid, out int buildid)) continue; if (!int.TryParse(_buildid, out int buildid)) continue;
games.Add(new(appid, name, buildid, gameDirectory)); games.Add(new(appid, name, buildid, gameDirectory));
} }
catch {}
}
} }
if (!games.Any()) return false; if (!games.Any()) return false;
return true; return true;

View file

@ -76,8 +76,8 @@ namespace CreamInstaller
} }
} }
if (Program.Canceled || output is null) return false; if (Program.Canceled || output is null) return false;
appInfo = VdfConvert.Deserialize(output); try { appInfo = VdfConvert.Deserialize(output); } catch { }
if (!(appInfo.Value is VValue) && appInfo.Value.Children().ToList().Count == 0) return true; if (appInfo is null || (!(appInfo.Value is VValue) && appInfo.Value.Children().ToList().Count == 0)) return true;
VToken type = appInfo.Value is VValue ? null : appInfo.Value?["common"]?["type"]; VToken type = appInfo.Value is VValue ? null : appInfo.Value?["common"]?["type"];
if (type is null || type.ToString() == "Game") if (type is null || type.ToString() == "Game")
{ {