예제 #1
0
        /// <summary>
        /// Updates a structure that has already been written.
        /// </summary>
        /// <param name="index">The index of the structure to update</param>
        /// <param name="rawStruct">The new data</param>
        public void UpdateStruct(uint index, RawGffStruct rawStruct)
        {
            if (FileAccess.Write != access) throw new InvalidOperationException();

            // Make sure that the index is valid.
            int size = Marshal.SizeOf(typeof(RawGffStruct));
            int count = (int) structsStream.Length / size;
            if (index >= count) throw new ArgumentOutOfRangeException();

            // Seek to the structure in the stream and update the struct.
            structsStream.Seek(index * size, SeekOrigin.Begin);
            rawStruct.Serialize(structsStream);
        }
예제 #2
0
        /// <summary>
        /// Adds a new structure to the end of the structure stream.  This method
        /// is only valid for write access raw data.
        /// </summary>
        /// <param name="rawStruct">The structure to add</param>
        /// <returns>The index of the addes structure, it is always added to the
        /// end of the list</returns>
        public uint AddStruct(RawGffStruct rawStruct)
        {
            if (FileAccess.Write != access) throw new InvalidOperationException();

            // Seek to the end of the stream and add the struct.
            structsStream.Seek(0, SeekOrigin.End);
            rawStruct.Serialize(structsStream);

            // Count the number of structs in the stream and return the index of
            // the last one, which is the one we just added.
            int count = (int) structsStream.Length / Marshal.SizeOf(typeof(RawGffStruct));
            return (uint) (count - 1);
        }