Beispiel #1
0
        private void NewClick(object sender, EventArgs e)
        {
            TreeNode nodeSelected = treeView.SelectedNode;
            ShowNode newNode      = new ShowNode("new" + ((CustomItem)NewNodeType.SelectedItem).Text);

            newNode.Type = ((CustomItem)NewNodeType.SelectedItem).Value;
            nodeSelected.Nodes.Add(newNode);
        }
 public JsonClip(ShowNode sNode)
 {
     childs = new List <JsonClip>();
     Type   = sNode.Type;
     Text   = sNode.Text;
     foreach (var node in sNode.Nodes)
     {
         childs.Add(new JsonClip((ShowNode)node));
     }
 }
 public override void Show(ShowNode parent, List <string> nodes, List <string> values)
 {
     foreach (var node in Nodes)
     {
         ShowNode treeNode = new ShowNode(nodes[node.Key]);
         treeNode.Type = node.Value.Type;
         parent.Nodes.Add(treeNode);
         node.Value.Show(treeNode, nodes, values);
     }
 }
Beispiel #4
0
        private void PasteClick(object sender, EventArgs e)
        {
            IDataObject iData = Clipboard.GetDataObject();

            if (iData.GetDataPresent(DataFormats.Text))
            {
                ClipText = (string)iData.GetData(DataFormats.Text);
                var jsonClip = JsonConvert.DeserializeObject <JsonClip>(ClipText);
                var showNode = new ShowNode(jsonClip);
                treeView.SelectedNode.Nodes.Add(showNode);
                treeView.SelectedNode = showNode;
                treeView.Focus();
            }
        }
Beispiel #5
0
        //更新nodes,values中的字符串
        private void UpdateStrings(ShowNode rootNode)
        {
            switch (rootNode.Type)
            {
            case ByamlNodeType.String:
                if (!values.Contains(rootNode.Nodes[0].Text))
                {
                    values.Add(rootNode.Nodes[0].Text);
                }
                break;

            case ByamlNodeType.Boolean:
            case ByamlNodeType.UInt:
            case ByamlNodeType.Hash:
            case ByamlNodeType.Single:
                break;

            case ByamlNodeType.UnamedNode:
                foreach (ShowNode node in rootNode.Nodes)
                {
                    UpdateStrings(node);
                }
                break;

            case ByamlNodeType.NamedNode:
                foreach (ShowNode node in rootNode.Nodes)
                {
                    if (!nodes.Contains(node.Text))
                    {
                        nodes.Add(node.Text);
                    }
                    UpdateStrings(node);
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #6
0
        private void WriteByamlNodes(ShowNode root, int offset, EndianBinaryWriter writer)
        {
            writer.BaseStream.Seek(offset, SeekOrigin.Begin);

            bool Existed       = false;
            int  existedOffset = 0;


            int           value = 0;
            int           p0    = 0;
            int           p1    = 0;
            int           p2    = 0;
            ByamlNodeType type  = root.Type;

            switch (type)
            {
            case ByamlNodeType.UnamedNode:
                //写入头部
                value = 0xc0 << 24 | root.Nodes.Count;
                writer.Write(value);

                //p0:type区域的写入偏移 p1:节点地址区域的写入偏移 p2:节点区域的写入偏移
                p0 = (int)writer.BaseStream.Position;

                int lenght = root.Nodes.Count;
                while (lenght % 4 != 0)
                {
                    lenght++;
                }
                p1 = (int)writer.BaseStream.Position + lenght;
                p2 = p1 + 4 * root.Nodes.Count;

                foreach (ShowNode node in root.Nodes)
                {
                    //写入类型
                    writer.BaseStream.Seek(p0, SeekOrigin.Begin);
                    writer.Write((byte)node.Type);
                    p0 = (int)writer.BaseStream.Position;

                    //写入节点
                    switch (node.Type)
                    {
                    case ByamlNodeType.String:
                        writer.BaseStream.Seek(p1, SeekOrigin.Begin);
                        writer.Write(values.IndexOf(node.Nodes[0].Text));
                        p1 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.Boolean:
                        writer.BaseStream.Seek(p1, SeekOrigin.Begin);
                        value = bool.Parse(node.Nodes[0].Text) ? 1 : 0;
                        writer.Write(value);
                        p1 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.UInt:
                        writer.BaseStream.Seek(p1, SeekOrigin.Begin);
                        writer.Write(uint.Parse(node.Nodes[0].Text));
                        p1 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.Hash:
                        writer.BaseStream.Seek(p1, SeekOrigin.Begin);
                        writer.Write(uint.Parse(node.Nodes[0].Text));
                        p1 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.Single:
                        writer.BaseStream.Seek(p1, SeekOrigin.Begin);
                        writer.Write(float.Parse(node.Nodes[0].Text));
                        p1 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.UnamedNode:
                    case ByamlNodeType.NamedNode:
                        Existed = false;
                        foreach (var item in nodeChaches)
                        {
                            if (TreeNodeCmp(item.Value, node))
                            {
                                Existed       = true;
                                existedOffset = item.Key;
                            }
                        }
                        if (Existed)
                        {
                            //写入节点地址
                            writer.BaseStream.Seek(p1, SeekOrigin.Begin);
                            writer.Write(existedOffset);
                            p1 = (int)writer.BaseStream.Position;
                        }
                        else
                        {
                            nodeChaches.Add(new KeyValuePair <int, ShowNode>(p2, node));

                            //写入节点地址
                            writer.BaseStream.Seek(p1, SeekOrigin.Begin);
                            writer.Write(p2);
                            p1 = (int)writer.BaseStream.Position;

                            //写入节点数据
                            writer.BaseStream.Seek(p2, SeekOrigin.Begin);
                            WriteByamlNodes(node, p2, writer);
                            p2 = (int)writer.BaseStream.Position;
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }

                writer.BaseStream.Seek(p2, SeekOrigin.Begin);
                break;

            case ByamlNodeType.NamedNode:
                //写入头部
                value = 0xc1 << 24 | root.Nodes.Count;
                writer.Write(value);

                //p0:节点基本信息区域写入偏移 p1:节点实例写入区域区域偏移
                p0 = (int)writer.BaseStream.Position;
                p1 = (int)writer.BaseStream.Position + 8 * root.Nodes.Count;


                foreach (ShowNode node in root.Nodes)
                {
                    //写入节点信息头部
                    writer.BaseStream.Seek(p0, SeekOrigin.Begin);
                    writer.Write(nodes.IndexOf(node.Text) << 8 | (int)node.Type);
                    //写入节点的值或地址
                    switch (node.Type)
                    {
                    case ByamlNodeType.String:
                        writer.Write(values.IndexOf(node.Nodes[0].Text));
                        p0 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.Boolean:
                        value = bool.Parse(node.Nodes[0].Text) ? 1 : 0;
                        writer.Write(value);
                        p0 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.UInt:
                        writer.Write(uint.Parse(node.Nodes[0].Text));
                        p0 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.Hash:
                        writer.Write(uint.Parse(node.Nodes[0].Text));
                        p0 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.Single:
                        writer.Write(float.Parse(node.Nodes[0].Text));
                        p0 = (int)writer.BaseStream.Position;
                        break;

                    case ByamlNodeType.UnamedNode:
                    case ByamlNodeType.NamedNode:
                        Existed = false;
                        foreach (var item in nodeChaches)
                        {
                            if (TreeNodeCmp(item.Value, node))
                            {
                                Existed       = true;
                                existedOffset = item.Key;
                            }
                        }
                        if (Existed)
                        {
                            //写入节点的实例地址
                            writer.Write(existedOffset);
                            p0 = (int)writer.BaseStream.Position;
                        }
                        else
                        {
                            nodeChaches.Add(new KeyValuePair <int, ShowNode>(p1, node));

                            //写入节点的实例地址
                            writer.Write(p1);
                            p0 = (int)writer.BaseStream.Position;
                            //写入节点实例
                            WriteByamlNodes(node, p1, writer);
                            p1 = (int)writer.BaseStream.Position;
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }

                writer.BaseStream.Seek(p1, SeekOrigin.Begin);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #7
0
        public Byaml(string byamlFile)
        {
            nodes  = new List <string>();
            values = new List <string>();

            nodeChaches = new List <KeyValuePair <int, ShowNode> >();

            searched_nodes = new List <TreeNode>();

            byte[] bytes = File.ReadAllBytes(byamlFile);
            isYaz0 = Yaz0.IsYaz0(bytes);
            if (isYaz0)
            {
                bytes = Yaz0.decode(bytes);
            }

            var stream = new MemoryStream(bytes);
            var reader = new EndianBinaryReader(stream);

            reader.Endianness = Endianness.BigEndian;

            if (reader.ReadUInt16() != 0x4259)
            {
                throw new InvalidDataException();
            }
            if (reader.ReadUInt16() != 0x0002)
            {
                throw new InvalidDataException();
            }

            path = byamlFile;

            uint nodeOffset = reader.ReadUInt32();

            if (nodeOffset > reader.BaseStream.Length)
            {
                throw new InvalidDataException();
            }

            uint valuesOffset = reader.ReadUInt32();

            if (valuesOffset > reader.BaseStream.Length)
            {
                throw new InvalidDataException();
            }

            uint treeOffset = reader.ReadUInt32();

            if (treeOffset > reader.BaseStream.Length)
            {
                throw new InvalidDataException();
            }

            if (nodeOffset != 0)
            {
                reader.BaseStream.Seek(nodeOffset, SeekOrigin.Begin);
                nodes.AddRange(new ByamlNode.StringList(reader).Strings);
            }
            if (valuesOffset != 0)
            {
                reader.BaseStream.Seek(valuesOffset, SeekOrigin.Begin);
                values.AddRange(new ByamlNode.StringList(reader).Strings);
            }

            ByamlNodeType rootType;

            reader.BaseStream.Seek(treeOffset, SeekOrigin.Begin);
            rootType = (ByamlNodeType)reader.ReadByte();
            reader.BaseStream.Seek(-1, SeekOrigin.Current);
            if (rootType == ByamlNodeType.UnamedNode)
            {
                tree = new ByamlNode.UnamedNode(reader);
            }
            else
            {
                tree = new ByamlNode.NamedNode(reader);
            }

            root      = new ShowNode("root");
            root.Type = tree.Type;

            reader.Close();
        }
Beispiel #8
0
        private void ChangeTypeClick(object sender, EventArgs e)
        {
            ShowNode nodeSelected = (ShowNode)treeView.SelectedNode;

            nodeSelected.Type = ((CustomItem)NewNodeType.SelectedItem).Value;
        }
 public virtual void Show(ShowNode parent, List <string> nodes, List <string> values)
 {
     throw new NotImplementedException();
 }