Esempio n. 1
0
        /// <summary>
        /// Saves the PList to the specified stream.
        /// </summary>
        /// <param name="rootNode">Root node of the PList structure.</param>
        /// <param name="stream">The stream in which the PList is saves.</param>
        /// <param name="format">The format of the PList (Binary/Xml).</param>
        public static void Save(PNode rootNode, Stream stream, PListFormat format)
        {
            if (format == PListFormat.Xml)
            {
                const string newLine = "\n";

                var sets = new XmlWriterSettings
                {
                    Encoding     = Encoding.UTF8,
                    Indent       = true,
                    IndentChars  = "\t",
                    NewLineChars = newLine,
                };

                using (var tmpStream = new MemoryStream())
                {
                    using (var xmlWriter = XmlWriter.Create(tmpStream, sets))
                    {
                        xmlWriter.WriteStartDocument();
                        xmlWriter.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

                        // write out nodes, wrapped in plist root element
                        xmlWriter.WriteStartElement("plist");
                        xmlWriter.WriteAttributeString("version", "1.0");
                        rootNode.WriteXml(xmlWriter);
                        xmlWriter.WriteEndElement();
                        xmlWriter.Flush();
                    }

                    // XmlWriter always inserts a space before element closing (e.g. <true />)
                    // whereas the Apple parser can't deal with the space and expects <true/>
                    tmpStream.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(tmpStream))
                        using (var writer = new StreamWriter(stream, Encoding.UTF8, 4096, true))
                        {
                            writer.NewLine = newLine;
                            for (var line = reader.ReadLine(); line != null; line = reader.ReadLine())
                            {
                                if (line.Trim() == "<true />")
                                {
                                    line = line.Replace("<true />", "<true/>");
                                }
                                if (line.Trim() == "<false />")
                                {
                                    line = line.Replace("<false />", "<false/>");
                                }

                                writer.WriteLine(line);
                            }
                        }
                }
            }
            else
            {
                var writer = new BinaryFormatWriter();
                writer.Write(stream, rootNode);
            }
        }
Esempio n. 2
0
 // Token: 0x06000016 RID: 22 RVA: 0x00002244 File Offset: 0x00000444
 public bool Equals(PNode other)
 {
     if (other is PNode <T> )
     {
         T value = this.Value;
         return(value.Equals(((PNode <T>)other).Value));
     }
     return(false);
 }
Esempio n. 3
0
        // Token: 0x06000004 RID: 4 RVA: 0x000020B8 File Offset: 0x000002B8
        private static PNode LoadAsXml(Stream stream)
        {
            XmlReaderSettings settings = new XmlReaderSettings
            {
                ProhibitDtd = false,
                XmlResolver = null
            };
            PNode result;

            using (XmlReader xmlReader = XmlReader.Create(stream, settings))
            {
                xmlReader.MoveToContent();
                xmlReader.ReadStartElement("plist");
                xmlReader.MoveToContent();
                PNode pnode = NodeFactory.Create(xmlReader.LocalName);
                pnode.ReadXml(xmlReader);
                xmlReader.ReadEndElement();
                result = pnode;
            }
            return(result);
        }
Esempio n. 4
0
        // Token: 0x06000017 RID: 23 RVA: 0x00002280 File Offset: 0x00000480
        public override bool Equals(object obj)
        {
            PNode pnode = obj as PNode;

            return(pnode != null && this.Equals(pnode));
        }