From c036b195d86f051595f637b504924cb91769b347 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Thu, 19 Dec 2024 09:18:44 -0600 Subject: [PATCH] Handle missing indexes in Steam vdf file lists --- Core/SteamLibrary.cs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/Core/SteamLibrary.cs b/Core/SteamLibrary.cs index 0d0c9605d..5623421dd 100644 --- a/Core/SteamLibrary.cs +++ b/Core/SteamLibrary.cs @@ -22,17 +22,26 @@ public SteamLibrary() public SteamLibrary(string? libraryPath) { if (libraryPath != null - && OpenRead(LibraryFoldersConfigPath(libraryPath)) is FileStream stream) + && LibraryFoldersConfigPath(libraryPath) is string libFoldersConfigPath + && OpenRead(libFoldersConfigPath) is FileStream stream) { log.InfoFormat("Found Steam at {0}", libraryPath); var txtParser = KVSerializer.Create(KVSerializationFormat.KeyValues1Text); - var appPaths = txtParser.Deserialize>(stream) - .Select(lf => lf.Path is string libPath - ? appRelPaths.Select(p => Path.Combine(libPath, p)) - .FirstOrDefault(Directory.Exists) - : null) - .OfType() - .ToArray(); + var appPaths = (Utilities.DefaultIfThrows( + () => txtParser.Deserialize>(stream), + exc => + { + log.Warn($"Failed to parse {libFoldersConfigPath}", exc); + return null; + }) + ?.Values + .Select(lf => lf.Path is string libPath + ? appRelPaths.Select(p => Path.Combine(libPath, p)) + .FirstOrDefault(Directory.Exists) + : null) + .OfType() + ?? Enumerable.Empty()) + .ToArray(); var steamGames = appPaths.SelectMany(p => LibraryPathGames(txtParser, p)); var binParser = KVSerializer.Create(KVSerializationFormat.KeyValues1Binary); var nonSteamGames = Directory.EnumerateDirectories(Path.Combine(libraryPath, "userdata")) @@ -84,8 +93,14 @@ private static IEnumerable LibraryPathGames(KVSerializer acfParser, private static IEnumerable ShortcutsFileGames(KVSerializer vdfParser, string path) - => Utilities.DefaultIfThrows(() => vdfParser.Deserialize>(File.OpenRead(path))) - ?.Select(nsg => nsg.NormalizeDir(path)) + => Utilities.DefaultIfThrows(() => vdfParser.Deserialize>(File.OpenRead(path)), + exc => + { + log.Warn($"Failed to parse {path}", exc); + return null; + }) + ?.Values + .Select(nsg => nsg.NormalizeDir(path)) ?? Enumerable.Empty(); private const string registryKey = @"HKEY_CURRENT_USER\Software\Valve\Steam";