Example #1
0
        private void ConnectPageTree(BBeB book)
        {
            Debug.WriteLineIf(s_bDebugMode, "Connecting page tree");

            PageTreeObject pageTree = (PageTreeObject)book.FindFirstObject(typeof(PageTreeObject));

            if (pageTree == null)
            {
                throw new InvalidBookException("Couldn't find the required PageTree object");
            }

            UInt32ArrayTag pageListTag = (UInt32ArrayTag)pageTree.FindFirstTag(TagId.PageList);

            if (pageListTag == null)
            {
                throw new InvalidBookException("Couldn't find the required PageList tag");
            }

            foreach (uint id in pageListTag.Value)
            {
                PageObject page = (PageObject)book.FindObject((ushort)id);
                if (page == null)
                {
                    throw new InvalidBookException("Can't find page id " + id);
                }
                pageTree.Pages.Add(page);
            }
        }
Example #2
0
        private void ConnectPage(PageObject page, BBeB book)
        {
            Debug.WriteLineIf(s_bDebugMode, "Connecting page: " + page.ID);

            UInt32ArrayTag childIDs = (UInt32ArrayTag)page.FindFirstTag(TagId.PageObjectIds);

            if (childIDs != null)
            {
                foreach (uint id in childIDs.Value)
                {
                    BBeBObject child = book.FindObject((ushort)id);
                    if (child == null)
                    {
                        throw new InvalidBookException("Can't find object id " + id);
                    }

                    Debug.Assert(child.ID == id);

                    Debug.WriteLineIf(s_bDebugMode, "   Child: " + child.GetType().ToString() + " - id:" + child.ID);
                    page.Children.Add(child);
                }
            }

            UInt32Tag objInfoTag = (UInt32Tag)page.FindFirstTag(TagId.ObjectInfoLink);

            if (objInfoTag != null)
            {
                page.InfoObj = book.FindObject((ushort)objInfoTag.Value);
                if (page.InfoObj == null)
                {
                    throw new InvalidBookException("Can't find info object id " + objInfoTag.Value);
                }
            }

            StreamTagGroup stream = (StreamTagGroup)page.FindFirstTag(TagId.StreamGroup);

            if (stream != null)
            {
                BBeBObject tempObj = new BBeBObject(0x0);

                page.StreamTags = BBeBTagFactory.ParseAllTags(tempObj, stream.Data);
            }

            UInt32Tag linkTag = (UInt32Tag)page.FindFirstTag(TagId.Link);

            if (linkTag != null)
            {
                BBeBObject linkedObj = book.FindObject((ushort)linkTag.Value);
                if (linkedObj == null)
                {
                    throw new InvalidBookException("Can't find object id " + linkTag.Value);
                }
                page.LinkObj = linkedObj;
            }
        }
Example #3
0
        /// <summary>
        /// Write the tag serialized data using the supplied writer.
        /// </summary>
        /// <remarks>
        /// This is a really KLUDGY routine. Even though it deals with primitive
        /// types it has knowledge of what those types mean. For example the UInt16ArrayTag
        /// doesn't have a length value written, but the UInt32ArrayTag does. This is
        /// a very brittle solution to this problem and needs to be fixed. The solution is
        /// to have a serialize method for each tag type (uggh) - so you see why I took
        /// this shortcut.
        /// </remarks>
        /// <param name="tag"></param>
        /// <param name="writer"></param>
        private static void SerializeTag(BBeBTag tag, BBeBinaryWriter writer)
        {
            ushort id = (ushort)(0xf500 + tag.Id);

            if (tag.GetType() == typeof(ByteTag))
            {
                ByteTag t = (ByteTag)tag;
                writer.Write(id);
                writer.Write(t.Value);
            }
            else if (tag.GetType() == typeof(StreamTagGroup))
            {
                StreamTagSerializer.Serialize(writer, (StreamTagGroup)tag);
            }
            else if (tag.GetType() == typeof(ByteArrayTag))
            {
                ByteArrayTag t = (ByteArrayTag)tag;

                if (t.Id == TagId.StreamStart)
                {
                    byte[] data = t.Value;

                    writer.Write(BBeBLib.TagId.StreamSize);
                    writer.Write((uint)data.Length);
                    writer.Write(id);
                    writer.Write(data);
                    writer.Write(BBeBLib.TagId.StreamEnd);
                }
                else
                {
                    writer.Write(id);
                    writer.Write(t.Value);
                }
            }
            else if (tag.GetType() == typeof(UInt16Tag))
            {
                UInt16Tag t = (UInt16Tag)tag;
                writer.Write(id);
                writer.Write(t.Value);
            }
            else if (tag.GetType() == typeof(UInt16ArrayTag))
            {
                UInt16ArrayTag t = (UInt16ArrayTag)tag;
                writer.Write(id);
                foreach (ushort val in t.Value)
                {
                    writer.Write(val);
                }
            }
            else if (tag.GetType() == typeof(UInt32Tag))
            {
                UInt32Tag t = (UInt32Tag)tag;

                // StreamSize is written out by the StreamStart tag as the data may be compressed
                if (t.Id != TagId.StreamSize)
                {
                    writer.Write(id);

                    // Zero byte tags (but have hardcoded data associated with them
                    if (t.Id != TagId.BaseButtonStart &&
                        t.Id != TagId.FocusinButtonStart &&
                        t.Id != TagId.PushButtonStart &&
                        t.Id != TagId.UpButtonStart)
                    {
                        writer.Write(t.Value);
                    }
                }
            }
            else if (tag.GetType() == typeof(UInt32ArrayTag))
            {
                UInt32ArrayTag t = (UInt32ArrayTag)tag;
                writer.Write(id);

                // JumpTo doesn't have a length set and is hardcoded to 2!
                if (t.Id != TagId.JumpTo)
                {
                    writer.Write((ushort)t.Value.Length);
                }
                foreach (uint val in t.Value)
                {
                    writer.Write(val);
                }
            }
            else if (tag.GetType() == typeof(StringTag))
            {
                StringTag t = (StringTag)tag;
                writer.Write(id);
                writer.Write(t.Value);
            }
            else if (tag.GetType() == typeof(MessageTag))
            {
                MessageTag t = (MessageTag)tag;
                writer.Write(id);
                writer.Write((ushort)t.parameters);
                byte[] data = System.Text.Encoding.Unicode.GetBytes(t.param1);
                writer.Write((ushort)data.Length);
                writer.Write(data);
                data = System.Text.Encoding.Unicode.GetBytes(t.param2);
                writer.Write((ushort)data.Length);
                writer.Write(data);
            }
            else if (tag.GetType() == typeof(EmpDotsCodeTag))
            {
                EmpDotsCodeTag t = (EmpDotsCodeTag)tag;
                writer.Write(id);
                writer.Write((uint)t.Value);

                SerializeTag(t.FontFace, writer);

                writer.Write(t.DotsCode);
            }
            else if (tag.GetType() == typeof(IDOnlyTag))
            {
                IDOnlyTag t = (IDOnlyTag)tag;
                if (t.Id != TagId.StreamEnd)
                {
                    writer.Write(id);
                }
            }
            else if (tag.GetType() == typeof(BBeBTag))
            {
                BBeBTag t = (BBeBTag)tag;
                if (t.Id != TagId.StreamEnd)
                {
                    writer.Write(id);
                }
            }
            else
            {
                Debug.Assert(false, "Unknown tag type: " + tag.GetType().ToString());
            }
        }