diff --git a/CHANGELOG.md b/CHANGELOG.md index b879a8f45..fbf9cbec0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file. - [GUI] Optimize label searches and handle spaces in names (#4270 by: HebaruSan) - [Core] Small performance tweaks for DLL scanning (#4275 by: HebaruSan) - [GUI] Fix broken version label in About dialog (#4277 by: HebaruSan) +- [Core] Handle missing indexes in Steam vdf file lists (#4279 by: HebaruSan) ### Internal 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";