예제 #1
0
        public bool initFromData(ByteReader versionReader)
        {
            WrapperReader reader = new WrapperReader(versionReader);

            uint red = 0;
            reader.align(4);
            reader.mark();
            byte[] buffer = new byte[6];
            uint ret = reader.read(buffer,0,6);
            if (ret == 0xFFFFffff || ret < 6)
                return false;
            header = new Header(buffer);
            red += ret;
            red += reader.readString(out key);
            red += (uint)reader.align(4);
            if (header.wValueLength != 0)
            {
                if (header.wType == 0)
                {
                    values = new Data(null, (uint)header.wValueLength);
                    red += reader.readData(out values, (uint)header.wValueLength);
                }
                else if (header.wType == 1)
                {
                    values = new Data(null, (uint)header.wValueLength << 1);
                    //buffer = new byte[header.wValueLength << 1];
                    //red += reader.read(buffer, 0, (ulong)header.wValueLength << 1);
                    //values = new Data(buffer, (uint)header.wValueLength << 1);
                    red += reader.readData(out values, (uint)header.wValueLength << 1);

                }
                else
                    throw new ResourceException();

            }
            if (header.wLength > red)
            {
                buffer = new byte[header.wLength - red];

                reader.read(buffer, 0, header.wLength - red);
                rest = new Data(buffer, header.wLength - red);
            }
            reader.reset();
            buffer = new byte[header.wLength];

            reader.read(buffer, 0, header.wLength);
            allData = new Data(buffer, header.wLength);
            //dump();
            if (rest != null && rest.size() != 0)
            {
                bool bContinue = false;
                DataReader childReader = new DataReader(rest);
                do
                {
                    VersionInfo pNew = new VersionInfo();
                    bContinue = pNew.initFromData(childReader);
                    //pNew->dump();
                    if(bContinue)
                        children.Add(pNew);
                } while (bContinue);

            }
            return true;
        }
예제 #2
0
파일: Form1.cs 프로젝트: 1-Cs/SharpPlusPlus
        private void filename_TextChanged(object sender, EventArgs e)
        {
            path = filename.Text;
            if(!File.Exists(path))
            {
                return;
            }
            baseTree.Nodes.Clear();

            XmlReader xml = XmlReader.Create(path);
            Stack<String> backStack = new Stack<String>();
            Stack<TreeNode> nodeStack = new Stack<TreeNode>();
            TreeNode node = new TreeNode("ROOT");
            TreeNode oldnode = null;
            baseTree.Nodes.Add(node);

            while (xml.Read())
            {
                switch (xml.NodeType)
                {
                    case XmlNodeType.Element:
                        oldnode = node;
                        if (oldnode != null)
                            nodeStack.Push(oldnode);
                        node = new TreeNode(xml.Name);

                        node.Tag = new Dictionary<String, String>();
                        oldnode.Nodes.Add(node);
                        backStack.Push(xml.Name);
                        if (xml.HasAttributes)
                        {
                            xml.MoveToFirstAttribute();
                            do
                            {
                                ((Dictionary<String, String>)node.Tag).Add(xml.Name, xml.Value);
                            }
                            while (xml.MoveToNextAttribute());
                        }
                        break;
                    case XmlNodeType.Text:
                        node.Nodes.Add("Text").Tag = xml.Value;
                        break;
                    case XmlNodeType.Attribute:
                        ((Dictionary<String, String>)node.Tag).Add(xml.Name, xml.Value);
                        break;
                    case XmlNodeType.CDATA:
                        node.Nodes.Add("CDATA").Tag = xml.Value;
                        break;
                    case XmlNodeType.Comment:
                        node.Nodes.Add("Comment").Tag = xml.Value;
                        break;
                    case XmlNodeType.EndElement:
                        String nodeX = backStack.Pop();
                        if (nodeX != xml.Name)
                            throw new SyntaxErrorException();
                        node = nodeStack.Pop();
                        break;
                    case XmlNodeType.ProcessingInstruction:
                        break;
                    default:
                        break;

                }
            }
            xml.Close();
            baseTree.ExpandAll();
            return;
            byte[] buffer = version.getFileVersion(path);

            Data data = new Data(buffer, (uint)buffer.Length);
            DataReader reader = new DataReader(data);

            VersionInfo info = new VersionInfo();
            info.initFromData(reader);
            TreeNode vTree = info.makeNodes();
            if (vTree != null)
                baseTree.Nodes.Add(vTree);
            baseTree.Nodes.Add("ResourceTypes");
        }