public Widget LoadWidget(WidgetArgs args, Widget parent, MiniYamlNode node) { var widget = NewWidget(node.Key, args); if (parent != null) { parent.AddChild(widget); } if (node.Key.Contains("@")) { FieldLoader.LoadField(widget, "Id", node.Key.Split('@')[1]); } foreach (var child in node.Value.Nodes) { if (child.Key != "Children") { FieldLoader.LoadField(widget, child.Key, child.Value.Value); } } widget.Initialize(args); foreach (var child in node.Value.Nodes) { if (child.Key == "Children") { foreach (var c in child.Value.Nodes) { LoadWidget(args, widget, c); } } } widget.PostInit(args); return(widget); }
internal void Register(Manifest mod, string launchPath, IEnumerable <string> launchArgs, ModRegistration registration) { if (mod.Metadata.Hidden) { return; } var key = ExternalMod.MakeKey(mod); var yaml = new MiniYamlNode("Registration", new MiniYaml("", new List <MiniYamlNode>() { new MiniYamlNode("Id", mod.Id), new MiniYamlNode("Version", mod.Metadata.Version), new MiniYamlNode("Title", mod.Metadata.Title), new MiniYamlNode("LaunchPath", launchPath), new MiniYamlNode("LaunchArgs", new[] { "Game.Mod=" + mod.Id }.Concat(launchArgs).JoinWith(", ")) })); using (var stream = mod.Package.GetStream("icon.png")) if (stream != null) { yaml.Value.Nodes.Add(new MiniYamlNode("Icon", Convert.ToBase64String(stream.ReadAllBytes()))); } using (var stream = mod.Package.GetStream("icon-2x.png")) if (stream != null) { yaml.Value.Nodes.Add(new MiniYamlNode("Icon2x", Convert.ToBase64String(stream.ReadAllBytes()))); } using (var stream = mod.Package.GetStream("icon-3x.png")) if (stream != null) { yaml.Value.Nodes.Add(new MiniYamlNode("Icon3x", Convert.ToBase64String(stream.ReadAllBytes()))); } var sources = new List <string>(); if (registration.HasFlag(ModRegistration.System)) { sources.Add(Platform.GetSupportDir(SupportDirType.System)); } if (registration.HasFlag(ModRegistration.User)) { sources.Add(Platform.GetSupportDir(SupportDirType.User)); // If using the modern support dir we must also write the registration // to the legacy support dir for older engine versions, but ONLY if it exists var legacyPath = Platform.GetSupportDir(SupportDirType.LegacyUser); if (Directory.Exists(legacyPath)) { sources.Add(legacyPath); } } // Make sure the mod is available for this session, even if saving it fails LoadMod(yaml.Value, forceRegistration: true); var lines = new List <MiniYamlNode> { yaml }.ToLines().ToArray(); foreach (var source in sources.Distinct()) { var metadataPath = Path.Combine(source, "ModMetadata"); try { Directory.CreateDirectory(metadataPath); File.WriteAllLines(Path.Combine(metadataPath, key + ".yaml"), lines); } catch (Exception e) { Log.Write("debug", "Failed to register current mod metadata"); Log.Write("debug", e.ToString()); } } }