Esempio n. 1
0
        public string GetPath(bool excludeEntry = true)
        {
            string path = "";

            if (this.Parent.Parent is BINContainer)
            {
                BINContainer container = this.Parent.Parent as BINContainer;
                path = string.Format("{0}/{1}[{2}]", this.Parent.Parent.GetPath(excludeEntry), BINGlobal.GetClass(this.Property), container.Values.IndexOf(this.Parent as BINValue));
            }
            else
            {
                path = string.Format("{0}/{1}", this.Parent.GetPath(excludeEntry), BINGlobal.GetClass(this.Property));
            }

            return(path);
        }
        public string GetPath(bool excludeEntry = true)
        {
            string path = "";

            if (this.Property == 0 && this.Parent is BINContainer)
            {
                path += string.Format("{0}/[{1}]", this.Parent.GetPath(excludeEntry), (this.Parent as BINContainer).Values.IndexOf(this));
            }
            else if (this.Property == 0 && this.Parent is BINMap)
            {
                BINMap map = this.Parent as BINMap;
                if (map.Values.ContainsValue(this))
                {
                    path += map.Values.First(x => x.Value == this).Key.GetPath(excludeEntry);
                }
                else
                {
                    if (map.KeyType == BINValueType.Byte)
                    {
                        path += string.Format("{0}/{1}", this.Parent.GetPath(excludeEntry), (byte)this.Value);
                    }
                    else if (map.KeyType == BINValueType.UInt16)
                    {
                        path += string.Format("{0}/{1}", this.Parent.GetPath(excludeEntry), (ushort)this.Value);
                    }
                    else if (map.KeyType == BINValueType.UInt32)
                    {
                        path += string.Format("{0}/{1}", this.Parent.GetPath(excludeEntry), (uint)this.Value);
                    }
                    else if (map.KeyType == BINValueType.UInt64)
                    {
                        path += string.Format("{0}/{1}", this.Parent.GetPath(excludeEntry), (ulong)this.Value);
                    }
                    else if (map.KeyType == BINValueType.String)
                    {
                        path += string.Format("{0}/{1}", this.Parent.GetPath(excludeEntry), (string)this.Value);
                    }
                    else if (map.KeyType == BINValueType.Hash)
                    {
                        path += string.Format("{0}/{1}", this.Parent.GetPath(excludeEntry), (uint)this.Value);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            else if (this.Property == 0 && this.Parent is BINOptional)
            {
                path += this.Parent.GetPath(excludeEntry);
            }
            else if (this.Parent is BINStructure)
            {
                path += string.Format("{0}.{1}", this.Parent.GetPath(excludeEntry), BINGlobal.GetField(this.Property));
            }
            else if (this.Parent is BINEntry)
            {
                path += string.Format("{0}/{1}", this.Parent.GetPath(excludeEntry), BINGlobal.GetField(this.Property));
            }
            else
            {
                path += string.Format("{0}/{1}", this.Parent.GetPath(excludeEntry), BINGlobal.GetClass(this.Property));
            }

            return(excludeEntry ? path.Remove(0, path.IndexOf('/') + 1) : path);
        }
Esempio n. 3
0
        private static List <TreeViewItem> ProcessMap(BINValue value)
        {
            BINMap map = value.Value as BINMap;
            List <TreeViewItem> nodes = new List <TreeViewItem>();

            foreach (KeyValuePair <BINValue, BINValue> pair in map.Values)
            {
                TreeViewItem node = new TreeViewItem()
                {
                    Header = ProcessKeyValue(pair.Key)
                };

                if (map.ValueType != BINValueType.Structure && map.ValueType != BINValueType.Embedded)
                {
                    node.Header += " => " + (ProcessPrimitiveValue(pair.Value, false).Children[0] as TextBlock).Text;
                }
                else
                {
                    BINStructure structure = pair.Value.Value as BINStructure;
                    node.Header += " : " + BINGlobal.GetClass(structure.Property);

                    foreach (TreeViewItem structureNode in ProcessStructure(pair.Value))
                    {
                        node.Items.Add(structureNode);
                    }
                }

                nodes.Add(node);
            }

            return(nodes);

            string ProcessKeyValue(BINValue keyValue)
            {
                if (map.KeyType == BINValueType.Byte)
                {
                    return(((byte)keyValue.Value).ToString());
                }
                else if (map.KeyType == BINValueType.UInt16)
                {
                    return(((ushort)keyValue.Value).ToString());
                }
                else if (map.KeyType == BINValueType.UInt32)
                {
                    return(((uint)keyValue.Value).ToString());
                }
                else if (map.KeyType == BINValueType.UInt64)
                {
                    return(((ulong)keyValue.Value).ToString());
                }
                else if (map.KeyType == BINValueType.String)
                {
                    return((string)keyValue.Value);
                }
                else if (map.KeyType == BINValueType.StringHash)
                {
                    return(((uint)keyValue.Value).ToString());
                }
                else
                {
                    return("");
                }
            }
        }