internal static void WriteFlameFile(string fileName, FractalList fractals) { string name = null; try{ name = Path.GetFileNameWithoutExtension(fileName); }catch (Exception) {} if (name == null || name == "") { name = "unnamed"; } FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None); try{ XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.Encoding = System.Text.Encoding.UTF8; settings.OmitXmlDeclaration = true; settings.ConformanceLevel = ConformanceLevel.Fragment; XmlWriter output = XmlWriter.Create(fs, settings); WriteFlames(output, name, fractals); output.Flush(); } finally{ fs.Close(); } }
internal static void WriteFlames(XmlWriter xw, string name, FractalList fractals) { xw.WriteStartElement("flames"); xw.WriteAttributeString("name", name); foreach (Fractal fractal in fractals) { WriteFlame(xw, fractal); } xw.WriteEndElement(); }
internal static FractalList ReadFlameFile(string filename, FractronConfig conf) { FractalList newFractals = new FractalList(); Fractal newFractal; XmlReaderSettings settings = new XmlReaderSettings(); settings.CheckCharacters = false; settings.CloseInput = true; settings.ConformanceLevel = ConformanceLevel.Fragment; settings.IgnoreComments = false; settings.IgnoreWhitespace = false; settings.ValidationType = ValidationType.None; XmlReader reader = XmlReader.Create(filename, settings); XmlDocument doc = new XmlDocument(); doc.Load(reader); reader.Close(); XmlNode flamesNode = null; foreach (XmlNode node in doc.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { flamesNode = node; } } if (flamesNode == null) { return(newFractals); } foreach (XmlNode node in flamesNode) { if (node.Name == "flame") { newFractal = readFlameNode(node, conf); if (newFractal != null) { newFractals.Add(newFractal); } } } return(newFractals); }
public static void ReadFromFlameFile(string filename, FractronConfig conf) { FractalList newFractals = FlameFileIO.ReadFlameFile(filename, conf); fractals = newFractals; }