Пример #1
0
        private static ExtraBlock ParseExtraBlock(BinaryReader inputReader, ExtraBlockType type)
        {
            ExtraBlock block = CreateExtraBlock(type);

            if (block == null)
            {
                Debug.Assert(false, "Extra block cannot be created!");
                return(null);
            }

            if (!block.Parse(inputReader))
            {
                return(null);
            }

            return(block);
        }
Пример #2
0
        public static ExtraBlock[] ParseExtraBlocks(BinaryReader inputReader)
        {
            List <ExtraBlock> blocks = new List <ExtraBlock>();

            while (true)
            {
                Int32 typeId = inputReader.ReadInt32();
                if (typeId == 0)
                {
                    break;
                }

                inputReader.BaseStream.Seek(-sizeof(Int32), SeekOrigin.Current);

                string typeName = inputReader.ReadUInt32AsString();
                if (!Enum.IsDefined(typeof(ExtraBlockType), typeName))
                {
                    Trace.Assert(false, "Undefined extra block type encountered!");
                    return(null);
                }

                ExtraBlockType type = (ExtraBlockType)Enum.Parse(typeof(ExtraBlockType), typeName);
                switch (type)
                {
                case ExtraBlockType.ConM:
                case ExtraBlockType.TV__:
                {
                    ExtraBlock block = ParseExtraBlock(inputReader, type);
                    if (block == null)
                    {
                        return(new ExtraBlock[0]);
                    }

                    blocks.Add(block);
                }
                break;

                default:
                    Trace.Assert(false, "Unimplemented extra block type!");
                    break;
                }
            }

            return(blocks.ToArray());
        }