Beispiel #1
0
        public Chunk AddChunk(string ChunkType)
        {
            switch (ChunkType)
            {
            case CkType.cue:
                var cue = new CkCue();
                m_Chunks.Add(cue);
                return(cue);

            case CkType.LIST:
                var list = new CkList();
                m_Chunks.Add(list);
                return(list);
            }
            return(null);
        }
Beispiel #2
0
        private void Init(string Filename, bool ReadOnly)
        {
            BinaryReader fileReader;
            FileStream   fileStream;

            try
            {
                fileStream = new FileStream(Filename, FileMode.Open);
                fileReader = new BinaryReader(fileStream, Encoding.ASCII);
            }
            catch
            {
                return;
            }
            ID = new String(fileReader.ReadChars(4));
            fileReader.ReadUInt32();
            m_Format = new String(fileReader.ReadChars(4));
            m_Chunks = new List <Chunk>();

            while (fileReader.BaseStream.Position < fileReader.BaseStream.Length)
            {
                var    id        = new String(fileReader.ReadChars(4));
                uint   sizeInner = fileReader.ReadUInt32();
                Chunk  newChunk  = null;
                Byte[] chunkData;
                switch (id)
                {
                case CkType.fmt:
                    chunkData = fileReader.ReadBytes((int)sizeInner);
                    newChunk  = new CkFmt(chunkData);
                    break;

                case CkType.data:
                    if (ReadOnly)
                    {
                        fileReader.BaseStream.Seek(sizeInner, SeekOrigin.Current);
                    }
                    else
                    {
                        chunkData = fileReader.ReadBytes((int)sizeInner);
                        newChunk  = new CkData(chunkData);
                    }
                    break;

                case CkType.cue:
                    chunkData = fileReader.ReadBytes((int)sizeInner);
                    newChunk  = new CkCue(chunkData);
                    break;

                case CkType.LIST:
                    chunkData = fileReader.ReadBytes((int)sizeInner);
                    newChunk  = new CkList(chunkData);
                    break;

                default:
                    Console.WriteLine(String.Format("An unknown chunk {0} was found.", id));
                    chunkData = fileReader.ReadBytes((int)sizeInner);
                    newChunk  = new CkUnknown(chunkData, id);
                    break;
                }
                if (newChunk != null)
                {
                    m_Chunks.Add(newChunk);
                }
            }
            fileStream.Close();
            fileStream.Dispose();
            fileReader.Close();
        }