Exemple #1
0
        private void addItemToGui(QbItemBase itm, int indent)
        {
            //let exceptions be raised
            ListViewItem li = new ListViewItem(itm.QbItemType.ToString());
            li.IndentCount = indent;
            if (itm.DebugName.Length != 0)
                li.SubItems.Add(itm.DebugName);
            else if (itm.ItemQbKey != null && itm.ItemQbKey.Crc != 0)
                li.SubItems.Add(itm.ItemQbKey.Crc.ToString("X").PadLeft(8, '0'));
            else
                li.SubItems.Add(string.Empty);

            li.SubItems.Add(getValueForList(itm));
            li.SubItems.Add(string.Format("{0} ({1})", itm.Position.ToString("X").PadLeft(8, '0'), itm.Position.ToString()));
            li.SubItems.Add(itm.Length.ToString());
            li.SubItems.Add(itm.GetType().Name);
            li.ImageIndex = getQbItemImageIndex(itm.QbItemType);
            li.Tag = itm; //hold a reference to the item
            lstQbItems.Items.Add(li);
        }
Exemple #2
0
        public static void SetGenericItems(QbItemBase item, List<GenericQbItem> gItems)
        {
            MemberInfo[] ms = item.GetType().FindMembers(MemberTypes.Property,
                /*BindingFlags.DeclaredOnly |*/ BindingFlags.Instance | BindingFlags.Public,
                Type.FilterName, "*");

            int i = 0;
            GenericQbItem gi;
            List<GenericQbItem> list = null;

            if (gItems.Count == 0)
            {
                //test if this is an array item
                GenericQbItem gqi = QbFile.CreateGenericArrayItem(item);

                //null if not an array type
                if (gqi != null)
                {
                    //use this item to identify the array to set to 0 items
                    MemberInfo m = Array.Find(ms, delegate(MemberInfo mi)
                    {
                        return (mi.Name == gqi.SourceProperty);
                    });
                    if (m != null)
                    {
                        Type t = ((PropertyInfo)m).GetValue(item, null).GetType();
                        if (t == typeof(QbKey[]))
                            ((PropertyInfo)m).SetValue(item, new QbKey[0], null);
                        else if (t == typeof(float[]))
                            ((PropertyInfo)m).SetValue(item, new float[0], null);
                        else if (t == typeof(uint[]))
                            ((PropertyInfo)m).SetValue(item, new uint[0], null);
                        else if (t == typeof(int[]))
                            ((PropertyInfo)m).SetValue(item, new int[0], null);
                        else if (t == typeof(string[]))
                            ((PropertyInfo)m).SetValue(item, new string[0], null);
                    }
                }
            }

            while (i < gItems.Count)
            {
                gi = gItems[i++];

                if (gi.ReadOnly)
                    continue;

                //list = null;

                list = new List<GenericQbItem>();
                list.Add(gi);
                while (i < gItems.Count && gi.SourceProperty == gItems[i].SourceProperty)
                    list.Add(gItems[i++]);

                MemberInfo m = Array.Find(ms, delegate(MemberInfo mi)
                {
                    return (mi.Name == gi.SourceProperty);
                });

                if (m != null)
                {
                    Type t = ((PropertyInfo)m).GetValue(item, null).GetType();
                    if (t == typeof(QbKey[]))
                    {
                        QbKey[] qb = new QbKey[list.Count];
                        QbKey q;
                        string qS;

                        for (int c = 0; c < list.Count; c++)
                        {
                            q = list[c].ToQbKey();
                            qS = item.Root.LookupDebugName(q.Crc);
                            if (qS.Length != 0)
                                q = QbKey.Create(q.Crc, qS);
                            qb[c] = q;
                        }
                        ((PropertyInfo)m).SetValue(item, qb, null);
                    }
                    else if (t == typeof(float[]))
                    {
                        float[] f = new float[list.Count];
                        for (int c = 0; c < list.Count; c++)
                            f[c] = list[c].ToSingle();
                        ((PropertyInfo)m).SetValue(item, f, null);
                    }
                    else if (t == typeof(uint[]))
                    {
                        uint[] ui = new uint[list.Count];
                        for (int c = 0; c < list.Count; c++)
                            ui[c] = list[c].ToUInt32();
                        ((PropertyInfo)m).SetValue(item, ui, null);
                    }
                    else if (t == typeof(int[]))
                    {
                        int[] si = new int[list.Count];
                        for (int c = 0; c < list.Count; c++)
                            si[c] = list[c].ToInt32();
                        ((PropertyInfo)m).SetValue(item, si, null);
                    }
                    else if (t == typeof(string[]))
                    {
                        string[] s = new string[list.Count];
                        for (int c = 0; c < list.Count; c++)
                            s[c] = list[c].ToString();
                        ((PropertyInfo)m).SetValue(item, s, null);
                    }
                    else if (t == typeof(QbKey))
                    {
                        QbKey q = gi.ToQbKey();
                        string qS = item.Root.LookupDebugName(q.Crc);
                        if (qS.Length != 0)
                            q = QbKey.Create(q.Crc, qS);
                        ((PropertyInfo)m).SetValue(item, q, null);
                    }
                    else if (t == typeof(float))
                        ((PropertyInfo)m).SetValue(item, gi.ToSingle(), null);
                    else if (t == typeof(uint))
                        ((PropertyInfo)m).SetValue(item, gi.ToUInt32(), null);
                    else if (t == typeof(int))
                        ((PropertyInfo)m).SetValue(item, gi.ToInt32(), null);
                    else if (t == typeof(string))
                        ((PropertyInfo)m).SetValue(item, gi.ToString(), null);
                    else if (t == typeof(byte[]))
                        ((PropertyInfo)m).SetValue(item, gi.ToByteArray(), null);
                    else
                    {
                        throw new ApplicationException(string.Format("DataType {0} not supported.", t.Name));
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Analyse the attributes on the item and return the editable items
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static List <GenericQbItem> GetGenericItems(QbItemBase item)
        {
            List <GenericQbItem> items = new List <GenericQbItem>();
            GenericQbItem        itm   = null;

            MemberInfo[] ms = item.GetType().FindMembers(MemberTypes.Property,
                                                         /*BindingFlags.DeclaredOnly |*/ BindingFlags.Instance | BindingFlags.Public,
                                                         Type.FilterName, "*");

            foreach (MemberInfo m in ms)
            {
                GenericEditableAttribute a = Attribute.GetCustomAttribute(m, typeof(GenericEditableAttribute)) as GenericEditableAttribute;
                if (a != null)
                {
                    //return attribute value and pass in to generic items and return
                    object o = ((PropertyInfo)m).GetValue(item, null);
                    if (o == null)
                    {
                        continue;
                    }
                    if (o is byte[]) //hex
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (byte[])o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is string[])
                    {
                        foreach (string s in ((string[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is string)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (string)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is uint[])
                    {
                        foreach (uint s in ((uint[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is uint)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (uint)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is int[])
                    {
                        foreach (int s in ((int[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is int)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (int)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is float[])
                    {
                        foreach (float s in ((float[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is float)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (float)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is QbKey[])
                    {
                        foreach (QbKey s in ((QbKey[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is QbKey)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (QbKey)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("Unknown generic data type item '{0}'", o.GetType().Name));
                    }
                }
            }
            return(items);
        }
Exemple #4
0
        /// <summary>
        /// Analyse the attributes on the item and return the editable items
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static List<GenericQbItem> GetGenericItems(QbItemBase item)
        {
            List<GenericQbItem> items = new List<GenericQbItem>();
            GenericQbItem itm = null;

            MemberInfo[] ms = item.GetType().FindMembers(MemberTypes.Property,
                /*BindingFlags.DeclaredOnly |*/ BindingFlags.Instance | BindingFlags.Public,
                Type.FilterName, "*");

            foreach (MemberInfo m in ms)
            {
                GenericEditableAttribute a = Attribute.GetCustomAttribute(m, typeof(GenericEditableAttribute)) as GenericEditableAttribute;
                if (a != null)
                {

                    //return attribute value and pass in to generic items and return
                    object o = ((PropertyInfo)m).GetValue(item, null);
                    if (o == null)
                        continue;
                    if (o is byte[]) //hex
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (byte[])o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is string[])
                    {
                        foreach (string s in ((string[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is string)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (string)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is uint[])
                    {
                        foreach (uint s in ((uint[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is uint)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (uint)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is int[])
                    {
                        foreach (int s in ((int[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is int)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (int)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is float[])
                    {
                        foreach (float s in ((float[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is float)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (float)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is QbKey[])
                    {
                        foreach (QbKey s in ((QbKey[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is QbKey)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (QbKey)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else
                        throw new ApplicationException(string.Format("Unknown generic data type item '{0}'", o.GetType().Name));
                }
            }
            return items;
        }
Exemple #5
0
        public static void SetGenericItems(QbItemBase item, List <GenericQbItem> gItems)
        {
            MemberInfo[] ms = item.GetType().FindMembers(MemberTypes.Property,
                                                         /*BindingFlags.DeclaredOnly |*/ BindingFlags.Instance | BindingFlags.Public,
                                                         Type.FilterName, "*");

            int                  i = 0;
            GenericQbItem        gi;
            List <GenericQbItem> list = null;

            if (gItems.Count == 0)
            {
                //test if this is an array item
                GenericQbItem gqi = QbFile.CreateGenericArrayItem(item);

                //null if not an array type
                if (gqi != null)
                {
                    //use this item to identify the array to set to 0 items
                    MemberInfo m = Array.Find(ms, delegate(MemberInfo mi)
                    {
                        return(mi.Name == gqi.SourceProperty);
                    });
                    if (m != null)
                    {
                        Type t = ((PropertyInfo)m).GetValue(item, null).GetType();
                        if (t == typeof(QbKey[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new QbKey[0], null);
                        }
                        else if (t == typeof(float[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new float[0], null);
                        }
                        else if (t == typeof(uint[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new uint[0], null);
                        }
                        else if (t == typeof(int[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new int[0], null);
                        }
                        else if (t == typeof(string[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new string[0], null);
                        }
                    }
                }
            }


            while (i < gItems.Count)
            {
                gi = gItems[i++];

                if (gi.ReadOnly)
                {
                    continue;
                }

                //list = null;

                list = new List <GenericQbItem>();
                list.Add(gi);
                while (i < gItems.Count && gi.SourceProperty == gItems[i].SourceProperty)
                {
                    list.Add(gItems[i++]);
                }

                MemberInfo m = Array.Find(ms, delegate(MemberInfo mi)
                {
                    return(mi.Name == gi.SourceProperty);
                });

                if (m != null)
                {
                    Type t = ((PropertyInfo)m).GetValue(item, null).GetType();
                    if (t == typeof(QbKey[]))
                    {
                        QbKey[] qb = new QbKey[list.Count];
                        QbKey   q;
                        string  qS;

                        for (int c = 0; c < list.Count; c++)
                        {
                            q  = list[c].ToQbKey();
                            qS = item.Root.LookupDebugName(q.Crc);
                            if (qS.Length != 0)
                            {
                                q = QbKey.Create(q.Crc, qS);
                            }
                            qb[c] = q;
                        }
                        ((PropertyInfo)m).SetValue(item, qb, null);
                    }
                    else if (t == typeof(float[]))
                    {
                        float[] f = new float[list.Count];
                        for (int c = 0; c < list.Count; c++)
                        {
                            f[c] = list[c].ToSingle();
                        }
                        ((PropertyInfo)m).SetValue(item, f, null);
                    }
                    else if (t == typeof(uint[]))
                    {
                        uint[] ui = new uint[list.Count];
                        for (int c = 0; c < list.Count; c++)
                        {
                            ui[c] = list[c].ToUInt32();
                        }
                        ((PropertyInfo)m).SetValue(item, ui, null);
                    }
                    else if (t == typeof(int[]))
                    {
                        int[] si = new int[list.Count];
                        for (int c = 0; c < list.Count; c++)
                        {
                            si[c] = list[c].ToInt32();
                        }
                        ((PropertyInfo)m).SetValue(item, si, null);
                    }
                    else if (t == typeof(string[]))
                    {
                        string[] s = new string[list.Count];
                        for (int c = 0; c < list.Count; c++)
                        {
                            s[c] = list[c].ToString();
                        }
                        ((PropertyInfo)m).SetValue(item, s, null);
                    }
                    else if (t == typeof(QbKey))
                    {
                        QbKey  q  = gi.ToQbKey();
                        string qS = item.Root.LookupDebugName(q.Crc);
                        if (qS.Length != 0)
                        {
                            q = QbKey.Create(q.Crc, qS);
                        }
                        ((PropertyInfo)m).SetValue(item, q, null);
                    }
                    else if (t == typeof(float))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToSingle(), null);
                    }
                    else if (t == typeof(uint))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToUInt32(), null);
                    }
                    else if (t == typeof(int))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToInt32(), null);
                    }
                    else if (t == typeof(string))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToString(), null);
                    }
                    else if (t == typeof(byte[]))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToByteArray(), null);
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("DataType {0} not supported.", t.Name));
                    }
                }
            }
        }