Example #1
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 4:
            {
                this.m_SecureLevel = (SecureLevel)reader.ReadInt();
                goto case 3;
            }

            case 3:
            case 2:
            {
                BookContent content = this.DefaultContent;

                SaveFlags flags = (SaveFlags)reader.ReadByte();

                if ((flags & SaveFlags.Title) != 0)
                {
                    this.m_Title = Utility.Intern(reader.ReadString());
                }
                else if (content != null)
                {
                    this.m_Title = content.Title;
                }

                if ((flags & SaveFlags.Author) != 0)
                {
                    this.m_Author = reader.ReadString();
                }
                else if (content != null)
                {
                    this.m_Author = content.Author;
                }

                this.m_Writable = (flags & SaveFlags.Writable) != 0;

                if ((flags & SaveFlags.Content) != 0)
                {
                    this.m_Pages = new BookPageInfo[reader.ReadEncodedInt()];

                    for (int i = 0; i < this.m_Pages.Length; ++i)
                    {
                        this.m_Pages[i] = new BookPageInfo(reader);
                    }
                }
                else
                {
                    if (content != null)
                    {
                        this.m_Pages = content.Copy();
                    }
                    else
                    {
                        this.m_Pages = new BookPageInfo[0];
                    }
                }

                break;
            }

            case 1:
            case 0:
            {
                this.m_Title    = reader.ReadString();
                this.m_Author   = reader.ReadString();
                this.m_Writable = reader.ReadBool();

                if (version == 0 || reader.ReadBool())
                {
                    this.m_Pages = new BookPageInfo[reader.ReadInt()];

                    for (int i = 0; i < this.m_Pages.Length; ++i)
                    {
                        this.m_Pages[i] = new BookPageInfo(reader);
                    }
                }
                else
                {
                    BookContent content = this.DefaultContent;

                    if (content != null)
                    {
                        this.m_Pages = content.Copy();
                    }
                    else
                    {
                        this.m_Pages = new BookPageInfo[0];
                    }
                }

                break;
            }
            }

            if (version < 3 && (this.Weight == 1 || this.Weight == 2))
            {
                this.Weight = -1;
            }
        }