Esempio n. 1
0
        /// <summary>
        /// Loads the GFF file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to load the GFF file from.s</param>
        private void LoadStream(Stream stream)
        {
            // Read the header.
            NWNLogger.Log(0, "Gff.LoadStream loading header");
            GffHeader header = new GffHeader(stream);
            NWNLogger.Log(1, "Gff.LoadStream version {0}", header.VersionText);
            if ("V3.2" != header.VersionText)
                throw new NWNException("Version {0} GFF files are unsupported", header.VersionText);

            NWNLogger.Log(0, "Gff.LoadStream reading raw GFF data");
            RawGffData rawData = new RawGffData(stream, header);
            topLevel = GffStructField.GetFieldStruct(rawData.GetStruct(0), rawData);
        }
Esempio n. 2
0
        /// <summary>
        /// This method initializes the module header based on the contents of
        /// the raw data object.
        /// </summary>
        /// <param name="header">The header to initialize</param>
        public void InitializeHeader(ref GffHeader header)
        {
            int offset = Marshal.SizeOf(typeof(GffHeader));

            header.StructCount = (int) structsStream.Length / Marshal.SizeOf(typeof(RawGffStruct));;
            header.StructOffset = offset;
            offset += (int) structsStream.Length;

            header.FieldCount = (int) fieldsStream.Length / Marshal.SizeOf(typeof(RawGffField));
            header.FieldOffset = offset;
            offset += (int) fieldsStream.Length;

            header.LabelCount = (int) labelsStream.Length / ResRefLength;
            header.LabelOffset = offset;
            offset += (int) labelsStream.Length;

            header.FieldDataCount = (int) complexDataStream.Length;
            header.FieldDataOffset = offset;
            offset += (int) complexDataStream.Length;

            header.FieldIndecesCount = (int) fieldIndecesStream.Length;
            header.FieldIndecesOffset = offset;
            offset += (int) fieldIndecesStream.Length;

            header.ListIndecesCount = (int) listIndecesStream.Length;
            header.ListIndecesOffset = offset;
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the GFF, using a new file name.
        /// </summary>
        /// <param name="fileName">The new file name for the GFF</param>
        public void SaveAs(string fileName)
        {
            // Save the top level structure to the raw data.
            RawGffData rawData = new RawGffData();
            GffStructField.SaveFieldStruct(0xffffffff, topLevel, rawData);

            // Create a header for the GFF file.
            string type = Path.GetExtension(fileName);
            type = type.Substring(1, type.Length - 1);
            GffHeader header = new GffHeader(type);
            rawData.InitializeHeader(ref header);

            // Create the disk file and save the header and raw data.
            using (FileStream writer = new FileStream(fileName, FileMode.Create,
                       FileAccess.Write, FileShare.Write))
            {
                header.Serialize(writer);
                rawData.Save(writer);
                writer.Close();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor to create a RawGffData object used for reading a GFF file
        /// </summary>
        /// <param name="s">Stream for the file</param>
        /// <param name="header">The file's header</param>
        public RawGffData(Stream s, GffHeader header)
        {
            access = FileAccess.Read;

            // Read the various pieces of the GFF file into memory, placing
            // each in a read only memory stream.
            structsStream = CreateReadingStream(s, header.StructOffset,
                header.StructCount * Marshal.SizeOf(typeof(RawGffStruct)));
            fieldsStream = CreateReadingStream(s, header.FieldOffset,
                header.FieldCount * Marshal.SizeOf(typeof(RawGffField)));
            labelsStream = CreateReadingStream(s, header.LabelOffset,
                header.LabelCount * ResRefLength);
            complexDataStream = CreateReadingStream(s, header.FieldDataOffset,
                header.FieldDataCount);
            fieldIndecesStream = CreateReadingStream(s, header.FieldIndecesOffset,
                header.FieldIndecesCount);
            listIndecesStream = CreateReadingStream(s, header.ListIndecesOffset,
                header.ListIndecesCount);
        }