public BigworldXmlReader(Stream contentStream)
        {
            var content = XmlDecoder.Decode(contentStream);

            _contentStream             = content.ToStream();
            _reader                    = new XmlTextReader(_contentStream);
            _reader.WhitespaceHandling = WhitespaceHandling.None;
        }
        public BigworldXmlReader(string path)
        {
            var content = XmlDecoder.Decode(path, out _encodeType);

            _contentStream             = content.ToStream();
            _reader                    = new XmlTextReader(_contentStream);
            _reader.WhitespaceHandling = WhitespaceHandling.None;
        }
Beispiel #3
0
        public BigworldXmlReader(string path)
        {
            var content = XmlDecoder.Decode(path);

#if DEBUG
            this.DecodedXml = content;
#endif
            _contentStream             = content.ToStream();
            _reader                    = new XmlTextReader(_contentStream);
            _reader.WhitespaceHandling = WhitespaceHandling.None;
        }
        public static string Decode(string path)
        {
            var packedFileName = Path.GetFileName(path).ToLower();

            using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    Int32 header = reader.ReadInt32();
                    if (header == PackedSection.PackedHeader)
                    {
                        reader.ReadSByte();

                        var document = new XmlDocument();

                        var packedSection = new PackedSection();
                        var dictionary    = packedSection.ReadDictionary(reader);
                        var xmlroot       = document.CreateNode(XmlNodeType.Element, packedFileName, "");
                        packedSection.ReadElement(reader, xmlroot, document, dictionary);
                        document.AppendChild(xmlroot);

                        return(XmlDecoder.FormatXml(document.OuterXml));
                    }
                    if (header == BinaryHeader)
                    {
                        stream.Seek(0, SeekOrigin.Begin);

                        var document = new XmlDocument();

                        var xmlPrimitives   = document.CreateNode(XmlNodeType.Element, "primitives", "");
                        var primitiveReader = new PrimitiveReader();
                        primitiveReader.ReadPrimitives(reader, xmlPrimitives, document);
                        document.AppendChild(xmlPrimitives);

                        return(XmlDecoder.FormatXml(document.OuterXml));
                    }
                    var extension = Path.GetExtension(path);
                    if (extension == ".xml" || extension == ".def" || extension == ".visual" || extension == ".chunk" || extension == ".settings" || extension == ".model" ||
                        extension == ".visual_processed")
                    {
                        return(File.ReadAllText(path));
                    }
                    throw new NotSupportedException();
                }
            }
        }
Beispiel #5
0
        public static string Decode(Stream stream)
        {
            using (BinaryReader reader = new BinaryReader(stream))
            {
                Int32 header = reader.ReadInt32();
                if (header == PackedSection.PackedHeader)
                {
                    reader.ReadSByte();

                    var document = new XmlDocument();

                    var packedSection = new PackedSection();
                    var dictionary    = packedSection.readDictionary(reader);
                    var xmlroot       = document.CreateNode(XmlNodeType.Element, "FromStream", "");
                    packedSection.readElement(reader, xmlroot, document, dictionary);
                    document.AppendChild(xmlroot);

                    return(XmlDecoder.FormatXml(document.OuterXml));
                }
                else if (header == BinaryHeader)
                {
                    stream.Seek(0, SeekOrigin.Begin);

                    var document = new XmlDocument();

                    var xmlPrimitives   = document.CreateNode(XmlNodeType.Element, "primitives", "");
                    var primitiveReader = new PrimitiveReader();
                    primitiveReader.ReadPrimitives(reader, xmlPrimitives, document);
                    document.AppendChild(xmlPrimitives);

                    return(XmlDecoder.FormatXml(document.OuterXml));
                }
                else
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    using (var streamReader = new StreamReader(stream))
                    {
                        return(streamReader.ReadToEnd());
                    }
                }
            }
        }
Beispiel #6
0
        public static string Decode(string path, out EncodeType encodeType, bool wellFormatted = false)
        {
            var packedFileName = UnifiedPath.GetFileName(path).ToLower();

            using (var stream = UnifiedFile.OpenRead(path))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    Int32 header = reader.ReadInt32();
                    if (header == PackedSection.PackedHeader)
                    {
                        reader.ReadSByte();

                        var document = new XmlDocument();

                        var packedSection = new PackedSection();
                        var dictionary    = packedSection.readDictionary(reader);
                        var xmlroot       = document.CreateNode(XmlNodeType.Element, packedFileName, "");
                        packedSection.readElement(reader, xmlroot, document, dictionary);
                        document.AppendChild(xmlroot);

                        encodeType = EncodeType.Packed;

                        if (wellFormatted)
                        {
                            return(XmlDecoder.FormatXml(document.OuterXml));
                        }
                        else
                        {
                            return(document.OuterXml);
                        }
                    }
                    else if (header == BinaryHeader)
                    {
                        stream.Seek(0, SeekOrigin.Begin);

                        var document = new XmlDocument();

                        var xmlPrimitives   = document.CreateNode(XmlNodeType.Element, "primitives", "");
                        var primitiveReader = new PrimitiveReader();
                        primitiveReader.ReadPrimitives(reader, xmlPrimitives, document);
                        document.AppendChild(xmlPrimitives);

                        encodeType = EncodeType.Binary;

                        if (wellFormatted)
                        {
                            return(XmlDecoder.FormatXml(document.OuterXml));
                        }
                        else
                        {
                            return(document.OuterXml);
                        }
                    }
                    else
                    {
                        var extension = UnifiedPath.GetExtension(path);
                        if (extension == ".xml" || extension == ".def" || extension == ".visual" || extension == ".chunk" || extension == ".settings" || extension == ".model")
                        {
                            encodeType = EncodeType.Plain;
                            return(File.ReadAllText(path));
                        }
                        else
                        {
                            throw new NotSupportedException();
                        }
                    }
                }
            }
        }