public Mod(XMLModMetadata metadata, XMLOmmelMetadata ommeldata, string dir_path) { Metadata = metadata; Ommeldata = ommeldata; DirPath = dir_path; DirName = Path.GetFileName(dir_path); }
private void LoadMod(string path) { try { var filename = Path.GetFileName(path); var metadata_path = Path.Combine(path, MOD_METADATA_NAME); if (!File.Exists(metadata_path)) { Logger.Warn($"Ignoring mod entry '{filename}' (missing {MOD_METADATA_NAME})"); return; } var ommeldata_path = Path.Combine(path, MOD_OMMELDATA_NAME); if (!File.Exists(ommeldata_path)) { Logger.Warn($"Ignoring mod entry '{filename}' (missing {MOD_OMMELDATA_NAME})"); return; } var metadata = new XMLModMetadata(); using (var f = XmlReader.Create(File.OpenRead(metadata_path), new XmlReaderSettings { CheckCharacters = false })) { var doc = new XmlDocument(); doc.Load(f); if (doc.ChildNodes.Count < 1) { metadata = null; } else { metadata.FillIn(doc.ChildNodes[0] as XmlElement); } } if (metadata == null) { Logger.Error($"Ignoring mod entry '{filename}' (failed to load metadata)"); return; } if (metadata.Name == null) { metadata.Name = "Unknown"; } var ommeldata = new XMLOmmelMetadata(); using (var f = XmlReader.Create(File.OpenRead(ommeldata_path), new XmlReaderSettings { CheckCharacters = false })) { var doc = new XmlDocument(); doc.Load(f); if (doc.ChildNodes.Count < 1) { ommeldata = null; } else { ommeldata.FillIn(doc.ChildNodes[0] as XmlElement); } } if (ommeldata == null) { Logger.Error($"Ignoring mod entry '{filename}' (failed to load ommeldata)"); return; } if (metadata.Name == null) { metadata.Name = "Unknown"; } if (ommeldata.Operations == null) { Logger.Error($"Ignoring mod entry '{filename}' (no file operations defined)"); return; } Logger.Info($"Found valid mod: '{metadata.Name}'"); Mods.Add(new Mod(metadata, ommeldata, path)); } catch (Exception e) { Logger.ErrorPretty($"Failed loading mod '{Path.GetFileName(path)}': {e}"); } }