Skip to content
0.2.0-dev Download ZIP
56 lines ·1.9 KB Raw
1using System.Text;
2using System.Text.RegularExpressions;
3using EvilEngine.Mounts;
4
5namespace EvilEngine.Adapters.Satisfactory;
6
7public static partial class Catalogue
8{
9 public static readonly VirtualPath Resources = "CommunityResources";
10
11 public static readonly VirtualPath Docs = "CommunityResources/Docs";
12
13 public static readonly VirtualPath English = "CommunityResources/Docs/en-US.json";
14
15 public static readonly VirtualPath Mappings = "CommunityResources/FactoryGame.usmap";
16
17 public static readonly VirtualPath CustomVersions = "CommunityResources/CustomVersions.json";
18
19 public static IReadOnlyList<VirtualPath> Packages(IFileSource tree, List<string> notes)
20 {
21 if (!tree.Exists(English))
22 {
23 notes.Add($"{English} isn't there, so catalogue names no packages.");
24 return [];
25 }
26
27 string text;
28 using (var reader = new StreamReader(tree.Open(English), Encoding.UTF8, true))
29 {
30 text = reader.ReadToEnd();
31 }
32
33 var packages = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
34 foreach (Match match in GamePath().Matches(text))
35 {
36 var package = match.Value.Split('.')[0];
37 if (VirtualPath.TryParse($"FactoryGame/Content/{package["/Game/".Length..]}", out var path) && !path.IsRoot)
38 packages.Add(path.Value);
39 }
40
41 return [.. packages.Select(VirtualPath.Parse)];
42 }
43
44 public static IEnumerable<VirtualPath> Files(IFileSource tree)
45 {
46 if (tree.DirectoryExists(Docs))
47 foreach (var entry in tree.Enumerate(Docs, true))
48 yield return entry.Path;
49 foreach (var path in new[] { Mappings, CustomVersions })
50 if (tree.Exists(path))
51 yield return path;
52 }
53
54 [GeneratedRegex(@"/Game/[^'""\s,()\\]+")]
55 private static partial Regex GamePath();
56}