public IffInfoNode(IffInfoNode parent, IffInfo info)
     : this(parent, info.Offset, info.TypeId, info.Length)
 {
 }
Esempio n. 2
0
 public IffInfoNode(IffInfoNode parent, IffInfo info)
     : this(parent, info.Offset, info.TypeId, info.Length)
 {
 }
        private void HandleIffInfo(IffInfo info, IffReader reader, int depth = 0)
        {
            string padding = new string(' ', depth * 4);
            string nestedPadding = new string(' ', 10 + 1 + 1 + 10 + 1 + 1 + (depth * 4) + 2);

            Console.Write("0x{0:x8} (0x{1:x8}) {2}{3}", info.Offset, info.Length, padding, info.TypeId);

            switch (info.TypeId)
            {
                case "FORM":
                    var formType = reader.ReadTypeId(info.ContentOffset);
                    Console.WriteLine(" - {0}", formType);
                    foreach (var chunk in reader.GetChunks(info.ContentOffset + 4))
                    {
                        this.HandleIffInfo(chunk, reader, depth + 1);
                    }
                    break;

                case "RIdx":
                    if (this.sawResources)
                    {
                        Console.WriteLine(" - already saw resource index!  Unexpected!");
                    }
                    else
                    {
                        Console.WriteLine();
                        var count = reader.ReadUint(info.Offset + 8);
                        uint expectedCount = (info.Length - 4) / 12;
                        System.Diagnostics.Debug.Assert(count == expectedCount);
                        for (uint i = 0; i < expectedCount; ++i)
                        {
                            var indexType = reader.ReadTypeId();
                            var indexId = reader.ReadUint();
                            var indexOffset = reader.ReadUint();
                            Console.WriteLine("{0}{1} {2:d2} @0x{3:x8}", nestedPadding, indexType, indexId, indexOffset);

                            switch (indexType)
                            {
                                case "Pict":
                                    this.UpdateResourceIndex(ref this.pictResources, indexId, indexOffset);
                                    break;
                                case "Snd ":
                                    this.UpdateResourceIndex(ref this.sndResources, indexId, indexOffset);
                                    break;
                                case "Data":
                                    this.UpdateResourceIndex(ref this.dataResources, indexId, indexOffset);
                                    break;
                                case "Exec":
                                    this.UpdateResourceIndex(ref this.execResources, indexId, indexOffset);
                                    break;
                                default:
                                    Console.WriteLine("* unknown resource type {0}", indexType);
                                    break;
                            }
                        }

                        this.sawResources = true;
                    }
                    break;

                case "IFmd":
                    if (metadata != null)
                    {
                        Console.WriteLine(" - extra ID metadata? This is unexpected!");
                    }
                    else
                    {
                        var xml = new XmlDocument();
                        var bytes = reader.ReadBytes(info.Offset + 8, info.Length);
                        using (var stream = new MemoryStream(bytes))
                        {
                            xml.Load(stream);
                        }
                        Console.WriteLine(" - extracted ({0})", xml.DocumentElement.Name);
                        this.metadata = xml;
                    }
                    break;

                case "Fspc":
                    if (this.coverImage.HasValue)
                    {
                        Console.WriteLine(" - already have a Frontspiece!  Unexpected!");
                    }
                    else
                    {
                        this.coverImage = reader.ReadUint(info.Offset + 8);
                        Console.WriteLine(" - image {0}", this.coverImage.Value);
                    }
                    break;

                default:
                    Console.WriteLine();
                    break;
            }
        }