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]
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);

View file

@ -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;

View file

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