Skip to content

Commit

Permalink
Skip Steam library folders missing config/libraryfolders.vdf
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Oct 4, 2024
1 parent cc28793 commit 68d703e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Core/SteamLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ namespace CKAN
public class SteamLibrary
{
public SteamLibrary()
: this(SteamPaths.Where(p => !string.IsNullOrEmpty(p))
.FirstOrDefault(Directory.Exists))
: this(SteamPaths.FirstOrDefault(p => !string.IsNullOrEmpty(p)
&& Directory.Exists(p)
&& File.Exists(LibraryFoldersConfigPath(p))))
{
}

public SteamLibrary(string? libraryPath)
{
if (libraryPath != null
&& OpenRead(Path.Combine(libraryPath,
"config",
"libraryfolders.vdf")) is FileStream stream)
&& OpenRead(LibraryFoldersConfigPath(libraryPath)) is FileStream stream)
{
log.InfoFormat("Found Steam at {0}", libraryPath);
var txtParser = KVSerializer.Create(KVSerializationFormat.KeyValues1Text);
Expand Down Expand Up @@ -54,6 +53,15 @@ public SteamLibrary(string? libraryPath)
}
}

public IEnumerable<Uri> GameAppURLs(DirectoryInfo gameDir)
=> Games.Where(g => gameDir.FullName.Equals(g.GameDir?.FullName, Platform.PathComparison))
.Select(g => g.LaunchUrl);

public readonly GameBase[] Games;

private static string LibraryFoldersConfigPath(string libraryPath)
=> Path.Combine(libraryPath, "config", "libraryfolders.vdf");

private static FileStream? OpenRead(string path)
=> Utilities.DefaultIfThrows(() => File.OpenRead(path),
exc =>
Expand All @@ -62,12 +70,6 @@ public SteamLibrary(string? libraryPath)
return null;
});

public IEnumerable<Uri> GameAppURLs(DirectoryInfo gameDir)
=> Games.Where(g => gameDir.FullName.Equals(g.GameDir?.FullName, Platform.PathComparison))
.Select(g => g.LaunchUrl);

public readonly GameBase[] Games;

private static IEnumerable<GameBase> LibraryPathGames(KVSerializer acfParser,
string appPath)
=> Directory.EnumerateFiles(appPath, "*.acf")
Expand Down

0 comments on commit 68d703e

Please sign in to comment.