示例#1
0
        public virtual ResXMLTree_startelement ReadResXMLTree_startelement(ResXMLTree_node node,
                                                                           ResXMLTree_attrExt attrExt)
        {
            var element = new ResXMLTree_startelement
            {
                Node       = node,
                AttrExt    = attrExt,
                Attributes = new List <ResXMLTree_attribute>()
            };

            var bytesLeft = node.Header.Size - 0x24u;

            for (var i = 0; i < attrExt.AttributeCount; i++)
            {
                element.Attributes.Add(ReadResXMLTree_attribute());
                bytesLeft -= 0x14u;
            }

            if (bytesLeft < 0)
            {
                throw new InvalidDataException("The length of the content exceeds the ResStringPool block boundary.");
            }
            if (bytesLeft > 0)
            {
                Debug.WriteLine("Warning: Garbage at the end of the StringPool block. Padding?");
                ReadBytes((int)bytesLeft);
            }

            return(element);
        }
示例#2
0
 public virtual void Write(ResXMLTree_node data)
 {
     Write(data.Header);
     _writer.Write(data.LineNumber);
     Write(data.Comment);
 }
示例#3
0
        private IEnumerable <XmlParserEventCode> ParserIterator()
        {
            while (true)
            {
                ClearState();

                if (_reader.BaseStream.Position >= _reader.BaseStream.Length)
                {
                    // If we're at the end of the file, stop reading chunks.
                    // Don't try to catch an EndOfStreamException - this way,
                    // we avoid an exception being created.
                    break;
                }

                ResChunk_header header;
                try
                {
                    header = _reader.ReadResChunk_header();
                }
                catch (EndOfStreamException)
                {
                    // Keep this just in case.
                    break;
                }

                var subStream = new BoundedStream(_reader.BaseStream, header.Size - 8);
                var subReader = new ResReader(subStream);
                switch (header.Type)
                {
                case ResourceType.RES_XML_TYPE:
                    yield return(XmlParserEventCode.StartDocument);

                    _reader = subReader; // Bound whole file
                    continue;            // Don't skip content

                case ResourceType.RES_STRING_POOL_TYPE:
                    var stringPoolHeader = subReader.ReadResStringPool_header(header);
                    Strings = subReader.ReadResStringPool(stringPoolHeader);
                    break;

                case ResourceType.RES_XML_RESOURCE_MAP_TYPE:
                    var resourceMap = subReader.ReadResResourceMap(header);
                    ResourceMap = resourceMap;
                    break;

                case ResourceType.RES_XML_START_NAMESPACE_TYPE:
                    _currentNode      = subReader.ReadResXMLTree_node(header);
                    _currentExtension = subReader.ReadResXMLTree_namespaceExt();
                    yield return(XmlParserEventCode.StartNamespace);

                    break;

                case ResourceType.RES_XML_END_NAMESPACE_TYPE:
                    _currentNode      = subReader.ReadResXMLTree_node(header);
                    _currentExtension = subReader.ReadResXMLTree_namespaceExt();
                    yield return(XmlParserEventCode.EndNamespace);

                    break;

                case ResourceType.RES_XML_START_ELEMENT_TYPE:
                    _currentNode = subReader.ReadResXMLTree_node(header);
                    var attrExt = subReader.ReadResXMLTree_attrExt();
                    _currentExtension = attrExt;

                    _attributes = new List <ResXMLTree_attribute>();
                    for (var i = 0; i < attrExt.AttributeCount; i++)
                    {
                        _attributes.Add(subReader.ReadResXMLTree_attribute());
                    }
                    yield return(XmlParserEventCode.StartTag);

                    break;

                case ResourceType.RES_XML_END_ELEMENT_TYPE:
                    _currentNode      = subReader.ReadResXMLTree_node(header);
                    _currentExtension = subReader.ReadResXMLTree_endElementExt();
                    yield return(XmlParserEventCode.EndTag);

                    break;

                case ResourceType.RES_XML_CDATA_TYPE:
                    _currentNode      = subReader.ReadResXMLTree_node(header);
                    _currentExtension = subReader.ReadResXMLTree_cdataExt();
                    yield return(XmlParserEventCode.Text);

                    break;

                default:
                    Debug.WriteLine(String.Format("Warning: Skipping chunk of type {0} (0x{1:x4})",
                                                  header.Type, (int)header.Type));
                    break;
                }
                var junk = subStream.ReadFully();
                if (junk.Length > 0)
                {
                    Debug.WriteLine(String.Format("Warning: Skipping {0} bytes at the end of a {1} (0x{2:x4}) chunk.",
                                                  junk.Length, header.Type, (int)header.Type));
                }
            }
        }
示例#4
0
 private void ClearState()
 {
     _currentNode      = null;
     _currentExtension = null;
     _attributes       = null;
 }