Skip to content

Commit

Permalink
Merge #4279 Handle missing indexes in Steam vdf file lists
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 19, 2024
2 parents 4a232bd + c036b19 commit 2d87f78
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 25 additions & 10 deletions Core/SteamLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<LibraryFolder>>(stream)
.Select(lf => lf.Path is string libPath
? appRelPaths.Select(p => Path.Combine(libPath, p))
.FirstOrDefault(Directory.Exists)
: null)
.OfType<string>()
.ToArray();
var appPaths = (Utilities.DefaultIfThrows(
() => txtParser.Deserialize<Dictionary<int, LibraryFolder>>(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<string>()
?? Enumerable.Empty<string>())
.ToArray();
var steamGames = appPaths.SelectMany(p => LibraryPathGames(txtParser, p));
var binParser = KVSerializer.Create(KVSerializationFormat.KeyValues1Binary);
var nonSteamGames = Directory.EnumerateDirectories(Path.Combine(libraryPath, "userdata"))
Expand Down Expand Up @@ -84,8 +93,14 @@ private static IEnumerable<GameBase> LibraryPathGames(KVSerializer acfParser,

private static IEnumerable<GameBase> ShortcutsFileGames(KVSerializer vdfParser,
string path)
=> Utilities.DefaultIfThrows(() => vdfParser.Deserialize<List<NonSteamGame>>(File.OpenRead(path)))
?.Select(nsg => nsg.NormalizeDir(path))
=> Utilities.DefaultIfThrows(() => vdfParser.Deserialize<Dictionary<int, NonSteamGame>>(File.OpenRead(path)),
exc =>
{
log.Warn($"Failed to parse {path}", exc);
return null;
})
?.Values
.Select(nsg => nsg.NormalizeDir(path))
?? Enumerable.Empty<NonSteamGame>();

private const string registryKey = @"HKEY_CURRENT_USER\Software\Valve\Steam";
Expand Down

0 comments on commit 2d87f78

Please sign in to comment.