public void LoadXml(string filename) { Libraries = new List <EntityLibrary>(); var root = Path.GetDirectoryName(filename); Debug.WriteLine(">> Loading XML file..."); var xml = new XmlDocument(); xml.Load(filename); var libsElem = xml.DocumentElement; if ((libsElem == null) || (libsElem.Name != "EntityLibraries")) { throw new InvalidOperationException("Not a valid EntityLibraries node"); } var attr32Bit = new AttributeData(DataType.Bool, libsElem.GetAttribute("Use32Bit")); Use32Bit = attr32Bit.ToBool(); Debug.WriteLine(">> Loading libraries..."); foreach (var node in libsElem.ChildNodes.OfType <XmlElement>()) { if (node.Name != "EntityLibrary") { throw new InvalidOperationException($"What the hell do I do with a '{node.Name}' element?!"); } var file = node.GetAttribute("File"); if (file != null) { var libName = Path.GetFileNameWithoutExtension(file); var libFile = Path.Combine(root, file); var libDoc = new XmlDocument(); libDoc.Load(libFile); var library = new EntityLibrary() { Use32Bit = Use32Bit, Name = libName, }; library.Deserialize(libDoc); Libraries.Add(library); Console.WriteLine($" > Loaded library '{libName}' via XML"); } else { throw new InvalidOperationException("Sorry, cannot load embedded EntityLibrary nodes :("); } } Console.WriteLine($"Processed {Libraries.Count} XML libraries and collected {Utils.GetTotalNumberOfNodes(GetNodeClass())} nodes in total."); }
public bool ToBool() => Data.ToBool();