예제 #1
0
        public void Read(Stream stream)
        {
            ByChunkId   = new Dictionary <Type, Dictionary <ushort, object> >();
            ByChunkType = new Dictionary <Type,List <object> >();

            using (var io = IoBuffer.FromStream(stream,ByteOrder.BIG_ENDIAN))
            {
                var identifier = io.ReadChars(60,false).Replace("\0","");
                if (identifier != "IFF FILE 2.5:TYPE FOLLOWED BY SIZE JAMIE DOORNBOS & MAXIS 1")
                {
                    throw new Exception("Invalid iff file!");
                }

                var rsmpOffset = io.ReadUInt32();

                while (io.HasMore)
                {
                    var chunkType     = io.ReadChars(4);
                    var chunkSize     = io.ReadUInt32();
                    var chunkID       = io.ReadUInt16();
                    var chunkFlags    = io.ReadUInt16();
                    var chunkLabel    = io.ReadChars(64);
                    var chunkDataSize = chunkSize - 76;

                    /** Do we understand this chunk type? **/
                    if (!CHUNK_TYPES.ContainsKey(chunkType))
                    {
                        /** Skip it! **/
                        io.Skip(chunkDataSize);
                    }
                    else
                    {
                        Type             chunkClass = CHUNK_TYPES[chunkType];
                        AbstractIffChunk newChunk   = (AbstractIffChunk)Activator.CreateInstance(chunkClass);
                        newChunk.ChunkID     = chunkID;
                        newChunk.ChunkFlags  = chunkFlags;
                        newChunk.ChunkLabel  = chunkLabel;
                        newChunk.ChunkData   = io.ReadBytes(chunkDataSize);
                        newChunk.ChunkParent = this;

                        if (!ByChunkType.ContainsKey(chunkClass))
                        {
                            ByChunkType.Add(chunkClass,new List <object>());
                        }
                        if (!ByChunkId.ContainsKey(chunkClass))
                        {
                            ByChunkId.Add(chunkClass,new Dictionary <ushort,object>());
                        }

                        ByChunkType[chunkClass].Add(newChunk);
                        //if (chunkID != 0){
                        ByChunkId[chunkClass].Add(chunkID,newChunk);
                        //}
                    }
                }
            }
        }
예제 #2
0
        private T prepare <T>(object input)
        {
            AbstractIffChunk chunk = (AbstractIffChunk)input;

            lock (chunk)
            {
                if (chunk.ChunkProcessed != true)
                {
                    using (var stream = new MemoryStream(chunk.ChunkData))
                    {
                        chunk.Read(this,stream);
                        chunk.ChunkProcessed = true;
                    }
                    return((T)input);
                }
                return((T)input);
            }
        }