From 898bb5803cd3c4d70bbfb5fb63c861afe292c1a8 Mon Sep 17 00:00:00 2001 From: pointfeev Date: Tue, 9 Nov 2021 01:12:46 -0500 Subject: [PATCH] VdfConvert.Deserialize exception fixes --- CreamInstaller/Program.cs | 2 +- CreamInstaller/SelectForm.cs | 56 ++++++++++++++++++++---------------- CreamInstaller/SteamCMD.cs | 4 +-- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index 461d390..e847bcf 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -22,7 +22,7 @@ namespace CreamInstaller [STAThread] private static void Main() { - Mutex mutex = new Mutex(true, "CreamInstaller", out bool createdNew); + Mutex mutex = new(true, "CreamInstaller", out bool createdNew); if (createdNew) { Application.SetHighDpiMode(HighDpiMode.SystemAware); diff --git a/CreamInstaller/SelectForm.cs b/CreamInstaller/SelectForm.cs index c4ac46c..76bd106 100644 --- a/CreamInstaller/SelectForm.cs +++ b/CreamInstaller/SelectForm.cs @@ -34,17 +34,21 @@ namespace CreamInstaller { string libraryFolder = steamInstallPath + @"\steamapps"; gameDirectories.Add(libraryFolder); - string libraryFolders = libraryFolder + @"\libraryfolders.vdf"; - dynamic property = VdfConvert.Deserialize(File.ReadAllText(libraryFolders)); - foreach (dynamic _property in property.Value) - { - if (int.TryParse(_property.Key, out int _)) - { - string path = _property.Value.path.ToString() + @"\steamapps"; - if (string.IsNullOrWhiteSpace(path)) continue; - if (!gameDirectories.Contains(path)) gameDirectories.Add(path); - } - } + try + { + string libraryFolders = libraryFolder + @"\libraryfolders.vdf"; + dynamic property = VdfConvert.Deserialize(File.ReadAllText(libraryFolders)); + foreach (dynamic _property in property.Value) + { + if (int.TryParse(_property.Key, out int _)) + { + string path = _property.Value.path.ToString() + @"\steamapps"; + if (string.IsNullOrWhiteSpace(path)) continue; + if (!gameDirectories.Contains(path)) gameDirectories.Add(path); + } + } + } + catch {} } return gameDirectories; } @@ -80,19 +84,23 @@ namespace CreamInstaller if (Program.Canceled) return false; if (Path.GetExtension(directory) == ".acf") { - dynamic property = VdfConvert.Deserialize(File.ReadAllText(directory)); - string _appid = property.Value.appid.ToString(); - string installdir = property.Value.installdir.ToString(); - string name = property.Value.name.ToString(); - string _buildid = property.Value.buildid.ToString(); - if (string.IsNullOrWhiteSpace(_appid) - || string.IsNullOrWhiteSpace(installdir) - || string.IsNullOrWhiteSpace(name) - || string.IsNullOrWhiteSpace(_buildid)) continue; - string gameDirectory = libraryDirectory + @"\common\" + installdir; - if (!int.TryParse(_appid, out int appid)) continue; - if (!int.TryParse(_buildid, out int buildid)) continue; - games.Add(new(appid, name, buildid, gameDirectory)); + try + { + dynamic property = VdfConvert.Deserialize(File.ReadAllText(directory)); + string _appid = property.Value.appid.ToString(); + string installdir = property.Value.installdir.ToString(); + string name = property.Value.name.ToString(); + string _buildid = property.Value.buildid.ToString(); + if (string.IsNullOrWhiteSpace(_appid) + || string.IsNullOrWhiteSpace(installdir) + || string.IsNullOrWhiteSpace(name) + || string.IsNullOrWhiteSpace(_buildid)) continue; + string gameDirectory = libraryDirectory + @"\common\" + installdir; + if (!int.TryParse(_appid, out int appid)) continue; + if (!int.TryParse(_buildid, out int buildid)) continue; + games.Add(new(appid, name, buildid, gameDirectory)); + } + catch {} } } if (!games.Any()) return false; diff --git a/CreamInstaller/SteamCMD.cs b/CreamInstaller/SteamCMD.cs index 3595466..ffd7e2f 100644 --- a/CreamInstaller/SteamCMD.cs +++ b/CreamInstaller/SteamCMD.cs @@ -76,8 +76,8 @@ namespace CreamInstaller } } if (Program.Canceled || output is null) return false; - appInfo = VdfConvert.Deserialize(output); - if (!(appInfo.Value is VValue) && appInfo.Value.Children().ToList().Count == 0) return true; + try { appInfo = VdfConvert.Deserialize(output); } catch { } + 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"]; if (type is null || type.ToString() == "Game") {