Exemple #1
0
        protected override Stream UnParse()
        {
            Stream       s = new MemoryStream();
            BinaryWriter w = new BinaryWriter(s);

            if (this.structureList == null)
            {
                this.structureList = new StructureList(OnResourceChanged);
            }
            if (this.dataList == null)
            {
                this.dataList = new DataList(OnResourceChanged, this);
            }

            // Write Header with blank offsets
            w.Write((uint)FOURCC("DATA"));
            w.Write(this.version);
            w.Write(blank); // data table offset
            w.Write(this.dataList.Count);
            w.Write(blank); // structure table offset
            w.Write(this.structureList.Count);

            // Padding between header and data table?
            w.Write(blank);
            w.Write(blank);

            // Write Data Table with blank Name and Structure offsets
            this.dataTablePosition = (uint)s.Position;
            this.dataList.UnParse(w);

            // Write Structure Table blank Name offsets
            this.structureTablePosition = (uint)s.Position;

            // Write Names and set Name positions in data
            foreach (Structure structure in this.structureList)
            {
                foreach (Field field in structure.FieldTable)
                {
                    if (string.IsNullOrEmpty(field.Name))
                    {
                        field.NamePosition = Util.NullOffset;
                    }
                    else
                    {
                        field.NamePosition = (uint)s.Position;
                        Util.WriteString(w, field.Name);
                    }
                }
                if (string.IsNullOrEmpty(structure.Name))
                {
                    structure.NamePosition = Util.NullOffset;
                }
                else
                {
                    structure.NamePosition = (uint)s.Position;
                    Util.WriteString(w, structure.Name);
                }
            }
            foreach (Data data in this.dataList)
            {
                if (string.IsNullOrEmpty(data.Name))
                {
                    data.NamePosition = Util.NullOffset;
                }
                else
                {
                    data.NamePosition = (uint)s.Position;
                    Util.WriteString(w, data.Name);
                }
            }

            // Go back, calculate and write offsets
            this.structureList.WriteOffsets(w);
            this.dataList.WriteOffsets(w);

            return(s);
        }