Example #1
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);
            }
        }
Example #2
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);
            }
        }