Exemplo n.º 1
0
        public Viewer_C2DArray(CR2WFile file)
        {
            this.file = file;

            InitializeComponent();

            CR2WValue[] header = this.file.Exports[0].NewData["headers"].As <CR2WValue[]>();

            CR2WValue[] data;
            if (this.file.Exports[0].NewData.ContainsKey("data"))
            {
                data = this.file.Exports[0].NewData["data"].As <CR2WValue[]>();
            }
            else
            {
                data = new CR2WValue[0];
            }

            // Read Header
            foreach (CR2WValue headerName in header)
            {
                this.dataGridView1.Columns.Add(headerName.As <string>(), headerName.As <string>());
            }

            // Read data
            {
                for (uint r = 0; r < data.Length; r++)
                {
                    DataGridViewRow gridRow = new DataGridViewRow();

                    gridRow.CreateCells(this.dataGridView1);

                    CR2WValue[] row = data[r].As <CR2WValue[]>();
                    for (int c = 0; c < row.Length; c++)
                    {
                        gridRow.Cells[c].Value = row[c].As <string>();
                    }

                    this.dataGridView1.Rows.Add(gridRow);
                }
            }
        }
Exemplo n.º 2
0
        public override void Read(BinaryReader reader)
        {
            uint nameIdx = reader.ReadUInt16();

            if (this.File.CNames.Length <= nameIdx)
            {
                throw new FormatException();
            }

            if (nameIdx == 0) // Empty property
            {
                return;
            }

            uint typeIdx = reader.ReadUInt16();

            if (this.File.CNames.Length <= typeIdx)
            {
                throw new FormatException();
            }

            this.name      = this.File.CNames[nameIdx];
            this.valueType = this.File.CNames[typeIdx];
            this.size      = reader.ReadInt32();

            long endPosition = reader.BaseStream.Position + this.size - 4;

            try {
                if (this.size > 4)
                {
                    this.value = CR2WValue.ReadValue(this.File, this.valueType, reader);
                }
            } catch (TypeAccessException e) {
                Console.Error.WriteLine($"Failed to read proprty {this.name}: {e.ToString()}");
                throw;
            } finally {
                reader.BaseStream.Seek(endPosition, SeekOrigin.Begin);
            }
        }
Exemplo n.º 3
0
        public List <TreeNode> GenerateValueNodes(CR2WValue value)
        {
            List <TreeNode> nodes = new List <TreeNode>();

            if (value.Type.IsArray)
            {
                CR2WValue[] array = value.As <CR2WValue[]>();
                foreach (CR2WValue subVal in array)
                {
                    nodes.AddRange(this.GenerateValueNodes(subVal));
                }
            }
            else if (value.InternalRepresentation is CR2WExport)
            {
                nodes = this.GenerateCPropertyNodes(value.As <CR2WExport>().NewData);
            }
            else
            {
                nodes.Add(new TreeNode(value.InternalRepresentation.ToString()));
            }

            return(nodes);
        }
Exemplo n.º 4
0
        private void LoadData()
        {
            if (this.data != null)
            {
                return;
            }

            this.data = new Dictionary <String, CR2WVariant>();

            // Read variants
            {
                this.stream.Seek(this.entry.Offset, SeekOrigin.Begin);
                BinaryReader reader = new BinaryReader(this.stream);

                if (reader.ReadByte() != 0)
                {
                    return;
                }

                while (true)
                {
                    CR2WVariant variant = CR2WVariant.FromStream(this.file, this.stream);
                    if (variant == null)
                    {
                        break;
                    }

                    this.data.Add(variant.Name, variant);
                }
            }

            // Read new variants
            try {
                this.newData = new Dictionary <string, CProperty>();

                this.stream.Seek(this.entry.Offset, SeekOrigin.Begin);
                BinaryReader reader = new BinaryReader(this.stream);

                if (reader.ReadByte() != 0)
                {
                    return;
                }

                while (this.stream.Position < (this.entry.Offset + this.entry.Size))
                {
                    try {
                        CProperty prop = CR2WValue.ReadValue(this.file, reader);
                        if (prop.Name == null)
                        {
                            break;
                        }

                        this.newData.Add(prop.Name, prop);
                    } catch (Exception e) {
                        continue;
                    }
                }
            } catch (Exception e) {
                Console.Error.Write(e);
            }
        }