-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSteamLibraryFactory.cs
32 lines (26 loc) · 989 Bytes
/
SteamLibraryFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Gamelib.Core.Util;
using GameLib.Plugin.Steam.Model;
using ValveKeyValue;
namespace GameLib.Plugin.Steam;
internal static class SteamLibraryFactory
{
public static IEnumerable<SteamLibrary> GetLibraries(string installDir)
{
var libraryVdfPath = Path.Combine(installDir, "config", "libraryfolders.vdf");
if (!File.Exists(libraryVdfPath))
{
return Enumerable.Empty<SteamLibrary>();
}
using var stream = File.OpenRead(libraryVdfPath);
var serializer = KVSerializer.Create(KVSerializationFormat.KeyValues1Text);
var deserializedLibraries = serializer.Deserialize<Dictionary<string, DeserializedSteamLibrary>>(stream);
return deserializedLibraries
.Select(lib => lib.Value)
.Select(lib =>
{
lib.Path = PathUtil.Sanitize(lib.Path) ?? string.Empty;
return lib.SteamLibraryBuilder();
})
.ToList();
}
}