Пример #1
0
        /// <summary>
        /// A static initializer which populates the FileVersion and the ObjectModelVersion with the parsed contents of V_CURRENT.
        /// </summary>
        static VimConstants()
        {
            var parsedCurrent = SerializableHeader.Parse(V_CURRENT);

            FileVersion        = parsedCurrent.FileVersion;
            ObjectModelVersion = parsedCurrent.ObjectModelVersion;
        }
Пример #2
0
        public static SerializableDocument ReadBuffer(this SerializableDocument doc, Stream stream, string name, long numBytes)
        {
            Debug.WriteLine($"Reading buffer {name} of size {Util.BytesToString(numBytes)}");
            switch (name)
            {
            case BufferNames.Header:
                var bytes = stream.ReadArray <byte>((int)numBytes);
                doc.Header = SerializableHeader.Parse(Encoding.UTF8.GetString(bytes));
                return(doc);

            case BufferNames.Assets:
                if (doc.Options?.SkipAssets == true)
                {
                    Debug.WriteLine("Skipping assets");
                    stream.Advance(numBytes);
                    return(doc);
                }
                doc.Assets = stream.ReadBFast().ToArray();
                return(doc);

            case BufferNames.Strings:
                var stringBytes       = stream.ReadArray <byte>((int)numBytes);
                var joinedStringTable = Encoding.UTF8.GetString(stringBytes);
                doc.StringTable = joinedStringTable.Split('\0');
                return(doc);

            case BufferNames.Geometry:
                if (doc.Options?.SkipGeometry == true)
                {
                    Debug.WriteLine("Skipping geometry");
                    stream.Advance(numBytes);
                    return(doc);
                }
                doc.Geometry = G3D.Read(stream);
                return(doc);

            case BufferNames.Nodes:
                if (doc.Options?.SkipGeometry == true)
                {
                    Debug.WriteLine("Skipping nodes");
                    stream.Advance(numBytes);
                    return(doc);
                }
                var cnt = (int)(numBytes / SerializableSceneNode.Size);
                Debug.Assert(numBytes % SerializableSceneNode.Size == 0, $"Number of bytes is not divisible by {SerializableSceneNode.Size}");
                if (cnt < 0)
                {
                    throw new Exception($"More than {int.MaxValue} items in array");
                }
                doc.Nodes = stream.ReadArray <SerializableSceneNode>(cnt);
                return(doc);

            case BufferNames.Entities:
                doc.EntityTables = ReadEntityTables(stream);
                return(doc);
            }

            // NOTE: unrecognized buffers are not an error.
            Debug.WriteLine($"Unrecognized buffer {name}");
            stream.ReadArray <byte>((int)numBytes);
            return(doc);
        }