Exemplo n.º 1
0
 /// <summary>
 /// Perform segment-specific processing on the raw data. At this point the four byte type has already been read
 /// in, so the position is at the four byte length int.
 /// </summary>
 /// <param name="file">The city file that is being read in.</param>
 internal virtual void ParseSegment(FileStream file)
 {
     Length = file.Read4ByteInt();
     RawDataFileOffset = (int)file.Position;
     Data = new byte[Length];
     file.Read(Data, 0, Length);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Read in and validate the header of a city file.
        /// </summary>
        /// <param name="stream">File stream waiting at the header for instructions.</param>
        /// <returns>The length (in bytes) of the data portion of this file.</returns>
        private static int ParseHeader(FileStream reader)
        {
            // Case for too small of a file
            if (reader.Length < 12)
                throw new Exception("Unexpected file length.");

            // Read 12-byte header.
            string headChunk = reader.ReadString();
            int dataLength = reader.Read4ByteInt();
            string fileType = reader.ReadString();

            // Make sure the header represents a valid city file.
            if (!headChunk.Equals(HEADERCHUNK) || !fileType.Equals(FILETYPE))
                throw new Exception("Invalid SC2000 file or corrupted header.");

            return dataLength;
        }