using System.Xml; using EvilEngine.Mounts; namespace EvilEngine.Adapters.Hpl3; public sealed record ResourceFolder(VirtualPath Path, bool Subfolders); public static class ResourceFolders { public static readonly VirtualPath FileName = "resources.cfg"; public static IReadOnlyList Read(IFileSource tree, VirtualPath file, List notes) { if (!tree.Exists(file)) { notes.Add($"{file} isn't in the install, so nothing is found by name."); return []; } return Parse(file, tree.ReadAllText(file), notes); } public static IReadOnlyList Parse(VirtualPath file, string text, List notes) { IReadOnlyList elements; try { elements = HplConfig.Elements(text); } catch (XmlException error) { notes.Add($"{file} can't be read, so nothing is found by name: {error.Message}"); return []; } var folders = new List(); foreach (var element in elements.Where(element => element.Name == "Directory")) { var path = (element["Path"] ?? "").Replace('\\', VirtualPath.Separator).Trim(VirtualPath.Separator); if (!VirtualPath.TryParse(path, out var folder)) { notes.Add($"{file} names {element["Path"]}, which isn't a folder in the install, so it's left out."); continue; } folders.Add(new ResourceFolder(file.Parent.Join(folder), string.Equals(element["AddSubDirs"], "true", StringComparison.OrdinalIgnoreCase))); } return folders; } }