示例#1
0
        public static void Save(string filePath, PNode rootNode, PListFormat format = PListFormat.Binary)
        {
            FileStream fs = File.OpenWrite(filePath);

            Save(fs, rootNode, format);
            fs.Close();
        }
示例#2
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)
            {
                var sets = new XmlWriterSettings
                {
                    Encoding     = Encoding.UTF8,
                    Indent       = true,
                    IndentChars  = "\t",
                    NewLineChars = "\n",
                };

                using (var xmlWriter = XmlWriter.Create(stream, 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();
                }
            }
            else
            {
                var writer = new BinaryFormatWriter();
                writer.Write(stream, rootNode);
            }
        }
示例#3
0
        public PListFile(byte[] plistBytes)
        {
            m_format = PListHelper.DetectFormat(plistBytes);
            MemoryStream stream = new MemoryStream(plistBytes);

            RootNode = PList.Load(stream);
        }
示例#4
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);
            }
        }
示例#5
0
 public void Save(Stream stream, PListFormat format)
 {
     if (format == PListFormat.Xml)
     {
         XmlWriter writer = XmlWriter.Create(stream, new XmlWriterSettings()
         {
             Encoding = Encoding.UTF8, Indent = true, IndentChars = "\t", NewLineChars = "\n"
         });
         writer.WriteStartDocument();
         writer.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", (string)null);
         this.WriteXml(writer);
         writer.Flush();
     }
     else
     {
         new PListBinaryWriter().Write(stream, this.Root);
     }
 }
示例#6
0
        public byte[] GetBytes(PListFormat format)
        {
            MemoryStream result = new MemoryStream();

            PList.Save(RootNode, result, format);
            if (format == PListFormat.Xml)
            {
                result.Position = 0;
                string xml = new StreamReader(result).ReadToEnd();
                xml = RemoveUTF8BOM(xml);
                // iOS 10.3.3 Will crash the application if it's using '<false />' instead of '<false/>'
                // in the entitlements file embedded in the executable.
                xml = xml.Replace(" />", "/>");
#if MAX_PLIST_COMPATIBILITY
                // Optional: Use exactly the same XML declaration and indentation as XCode
                const string DesiredXmlDeclaration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
                if (xml.StartsWith(DesiredXmlDeclaration, StringComparison.OrdinalIgnoreCase))
                {
                    // PList produces by Apple have encoding set to "UTF-8" in uppercase letters.
                    xml = DesiredXmlDeclaration + xml.Substring(DesiredXmlDeclaration.Length);
                }

                string[] lines = xml.Split('\n');
                for (int index = 0; index < lines.Length; index++)
                {
                    if (lines[index].StartsWith("\t"))
                    {
                        lines[index] = lines[index].Substring(1);
                    }
                }
                xml = String.Join("\n", lines) + "\n";
#endif
                byte[] bytes = Encoding.UTF8.GetBytes(xml);
                return(bytes);
            }
            return(result.ToArray());
        }
示例#7
0
        /// <summary>
        /// Saves the PList to the specified stream.
        /// </summary>
        /// <param name="stream">The stream in which the PList is saves.</param>
        /// <param name="format">The format of the PList (Binary/Xml).</param>
        public void Save(Stream stream, PListFormat format)
        {
            if (format == PListFormat.Xml)
            {
                XmlWriterSettings sets = new XmlWriterSettings();
                sets.Encoding     = Encoding.UTF8;
                sets.Indent       = true;
                sets.IndentChars  = "\t";
                sets.NewLineChars = "\n";

                XmlWriter xmlWriter = XmlTextWriter.Create(stream, sets);

                xmlWriter.WriteStartDocument();
                xmlWriter.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

                WriteXml(xmlWriter);
                xmlWriter.Flush();
            }
            else
            {
                PListBinaryWriter writer = new PListBinaryWriter();
                writer.Write(stream, Root);
            }
        }
示例#8
0
 public static void Save(Stream stream, PNode rootNode, PListFormat format)
 {
     PListNet.PList.Save(rootNode, stream, format);
 }
示例#9
0
 /// <summary>
 /// Saves the PList to the specified path.
 /// </summary>
 /// <param name="fileName">The path of the PList.</param>
 /// <param name="format">The format of the PList (Binary/Xml).</param>
 public void Save(String fileName, PListFormat format)
 {
     using (FileStream fs = new FileStream(fileName, FileMode.Create)) {
         Save(fs, format);
     }
 }
示例#10
0
        /// <summary>
        /// Saves the PList to the specified stream.
        /// </summary>
        /// <param name="stream">The stream in which the PList is saves.</param>
        /// <param name="format">The format of the PList (Binary/Xml).</param>
        public void Save(Stream stream, PListFormat format)
        {
            if (format == PListFormat.Xml) {
                XmlWriterSettings sets = new XmlWriterSettings();
                sets.Encoding = Encoding.UTF8;
                sets.Indent = true;
                sets.IndentChars = "\t";
                sets.NewLineChars = "\n";

                XmlWriter xmlWriter = XmlTextWriter.Create(stream, sets);

                xmlWriter.WriteStartDocument();
                xmlWriter.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

                WriteXml(xmlWriter);
                xmlWriter.Flush();
            } else {
                PListBinaryWriter writer = new PListBinaryWriter();
                writer.Write(stream, Root);
            }
        }
示例#11
0
 /// <summary>
 /// Saves the PList to the specified path.
 /// </summary>
 /// <param name="fileName">The path of the PList.</param>
 /// <param name="format">The format of the PList (Binary/Xml).</param>
 public void Save(String fileName, PListFormat format)
 {
     using (FileStream fs = new FileStream(fileName, FileMode.Create)) {
         Save(fs, format);
     }
 }
示例#12
0
 public void Save(string fileName, PListFormat format)
 {
     using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
         this.Save((Stream)fileStream, format);
 }