public XmlDocument Interpret(XmlDocument doc, XmlDocument interpreter) { //default type XmlNode defaultAttrib = null; defaultAttrib = interpreter.SelectSingleNode("/Converts/Default"); var internalFileDBs = interpreter.SelectNodes("/Converts/InternalCompression/Element"); var converts = interpreter.SelectNodes("/Converts/Converts/Convert"); //Convert internal FileDBs before conversion foreach (XmlNode n in internalFileDBs) { var nodes = doc.SelectNodes(n.Attributes["Path"].Value); foreach (XmlNode node in nodes) { var span = HexHelper.toSpan <byte>(node.InnerText); var filereader = new FileReader(); var decompressed = filereader.ReadSpan(span); node.InnerText = ""; node.AppendChild(doc.ImportNode(decompressed.DocumentElement, true)); //write the current decompressed internal filedb to a file //String path = Path.Combine("tests", "lists", DateTime.Now.ToString("HH-mm-ss-ff") + "_" + node.Name + ".bin"); //using FileStream fs = File.Create(path); //fs.Write(span); } } //converts foreach (XmlNode x in converts) { try { String Path = x.Attributes["Path"].Value; var Nodes = doc.SelectNodes(Path); ConvertNodeSet(Nodes, x); } catch (Exception e) { Console.WriteLine("Path not correctly set lol"); } } //DefaultType if (defaultAttrib != null) { //get a combined xpath of all List <String> StringList = new List <string>(); foreach (XmlNode convert in converts) { StringList.Add(convert.Attributes["Path"].Value); } foreach (XmlNode internalFileDB in internalFileDBs) { StringList.Add(internalFileDB.Attributes["Path"].Value); } String xPath = String.Join(" | ", StringList); //select all text that is not in the combined path var Base = doc.SelectNodes("//*[text()]"); var toFilter = doc.SelectNodes(xPath); var defaults = HexHelper.ExceptNodelists(Base, toFilter); ConvertNodeSet(defaults, defaultAttrib); } return(doc); }
//using String.Join for performance optimization over for loops. public static String Join <T>(String BinaryData) where T : struct { var span = HexHelper.toSpan <T>(BinaryData).ToArray(); return(String.Join <T>(" ", span)); }