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,17 +34,21 @@ namespace CreamInstaller
{ {
string libraryFolder = steamInstallPath + @"\steamapps"; string libraryFolder = steamInstallPath + @"\steamapps";
gameDirectories.Add(libraryFolder); gameDirectories.Add(libraryFolder);
string libraryFolders = libraryFolder + @"\libraryfolders.vdf"; try
dynamic property = VdfConvert.Deserialize(File.ReadAllText(libraryFolders)); {
foreach (dynamic _property in property.Value) string libraryFolders = libraryFolder + @"\libraryfolders.vdf";
{ dynamic property = VdfConvert.Deserialize(File.ReadAllText(libraryFolders));
if (int.TryParse(_property.Key, out int _)) foreach (dynamic _property in property.Value)
{ {
string path = _property.Value.path.ToString() + @"\steamapps"; if (int.TryParse(_property.Key, out int _))
if (string.IsNullOrWhiteSpace(path)) continue; {
if (!gameDirectories.Contains(path)) gameDirectories.Add(path); string path = _property.Value.path.ToString() + @"\steamapps";
} if (string.IsNullOrWhiteSpace(path)) continue;
} if (!gameDirectories.Contains(path)) gameDirectories.Add(path);
}
}
}
catch {}
} }
return gameDirectories; return gameDirectories;
} }
@ -80,19 +84,23 @@ namespace CreamInstaller
if (Program.Canceled) return false; if (Program.Canceled) return false;
if (Path.GetExtension(directory) == ".acf") if (Path.GetExtension(directory) == ".acf")
{ {
dynamic property = VdfConvert.Deserialize(File.ReadAllText(directory)); try
string _appid = property.Value.appid.ToString(); {
string installdir = property.Value.installdir.ToString(); dynamic property = VdfConvert.Deserialize(File.ReadAllText(directory));
string name = property.Value.name.ToString(); string _appid = property.Value.appid.ToString();
string _buildid = property.Value.buildid.ToString(); string installdir = property.Value.installdir.ToString();
if (string.IsNullOrWhiteSpace(_appid) string name = property.Value.name.ToString();
|| string.IsNullOrWhiteSpace(installdir) string _buildid = property.Value.buildid.ToString();
|| string.IsNullOrWhiteSpace(name) if (string.IsNullOrWhiteSpace(_appid)
|| string.IsNullOrWhiteSpace(_buildid)) continue; || string.IsNullOrWhiteSpace(installdir)
string gameDirectory = libraryDirectory + @"\common\" + installdir; || string.IsNullOrWhiteSpace(name)
if (!int.TryParse(_appid, out int appid)) continue; || string.IsNullOrWhiteSpace(_buildid)) continue;
if (!int.TryParse(_buildid, out int buildid)) continue; string gameDirectory = libraryDirectory + @"\common\" + installdir;
games.Add(new(appid, name, buildid, gameDirectory)); 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; if (!games.Any()) return false;

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")
{ {