示例#1
0
        /// <summary>
        /// Imports collection by reading its data from a <see cref="BinaryReader"/> provided.
        /// </summary>
        /// <param name="type"><see cref="SerializeType"/> type of importing collection.</param>
        /// <param name="br"><see cref="BinaryReader"/> to read data with.</param>
        public override void Import(SerializeType type, BinaryReader br)
        {
            var position = br.BaseStream.Position;
            var header   = new SerializationHeader();

            header.Read(br);

            if (header.ID != BinBlockID.Nikki)
            {
                throw new Exception($"Missing serialized header in the imported collection");
            }

            if (header.Game != this.GameINT)
            {
                throw new Exception($"Stated game inside collection is {header.Game}, while should be {this.GameINT}");
            }

            var manager = this.GetManager(header.Name);

            if (manager == null)
            {
                throw new Exception($"Cannot find manager named {header.Name}");
            }

            br.BaseStream.Position = position;
            manager.Import(type, br);
        }
示例#2
0
        /// <summary>
        /// Imports collection from file provided and attempts to add it to the end of
        /// this <see cref="Manager{T}"/> in case it does not exist.
        /// </summary>
        /// <param name="type">Type of serialization of a collection.</param>
        /// <param name="br"><see cref="BinaryReader"/> to read data with.</param>
        public override void Import(SerializeType type, BinaryReader br)
        {
            var position = br.BaseStream.Position;
            var header   = new SerializationHeader();

            header.Read(br);

            var collection = new FNGroup();

            if (header.ID != BinBlockID.Nikki)
            {
                br.BaseStream.Position = position;
                collection.Disassemble(br);
            }
            else
            {
                if (header.Game != this.GameINT)
                {
                    throw new Exception($"Stated game inside collection is {header.Game}, while should be {this.GameINT}");
                }

                if (header.Name != this.Name)
                {
                    throw new Exception($"Imported collection is not a collection of type {this.Name}");
                }

                collection.Deserialize(br);
            }

            var index = this.IndexOf(collection);

            if (index == -1)
            {
                // Allow import of FNGroups because it is safe
                this._is_read_only = false;
                ++this.Capacity;
                collection.Manager = this;
                this.Add(collection);
                this._is_read_only = true;
            }
            else
            {
                switch (type)
                {
                case SerializeType.Negate:
                    break;

                case SerializeType.Synchronize:
                case SerializeType.Override:
                    collection.Manager = this;
                    this.Replace(collection, index);
                    break;

                default:
                    break;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Imports collection from file provided and attempts to add it to the end of
        /// this <see cref="Manager{T}"/> in case it does not exist.
        /// </summary>
        /// <param name="type">Type of serialization of a collection.</param>
        /// <param name="br"><see cref="BinaryReader"/> to read data with.</param>
        public override void Import(SerializeType type, BinaryReader br)
        {
            var position = br.BaseStream.Position;
            var header   = new SerializationHeader();

            header.Read(br);

            var collection = new DBModelPart();

            if (header.ID != BinBlockID.Nikki)
            {
                throw new Exception($"Missing serialized header in the imported collection");
            }
            else
            {
                if (header.Game != this.GameINT)
                {
                    throw new Exception($"Stated game inside collection is {header.Game}, while should be {this.GameINT}");
                }

                if (header.Name != this.Name)
                {
                    throw new Exception($"Imported collection is not a collection of type {this.Name}");
                }

                collection.Deserialize(br);
            }

            var index = this.IndexOf(collection);

            if (index == -1)
            {
                collection.Manager = this;
                this.Add(collection);
            }
            else
            {
                switch (type)
                {
                case SerializeType.Negate:
                    break;

                case SerializeType.Override:
                    collection.Manager = this;
                    this.Replace(collection, index);
                    break;

                case SerializeType.Synchronize:
                    this[index].Synchronize(collection);
                    break;

                default:
                    break;
                }
            }
        }
示例#4
0
        /// <summary>
        /// Imports collection from file provided and attempts to add it to the end of
        /// this <see cref="Manager{T}"/> in case it does not exist.
        /// </summary>
        /// <param name="type">Type of serialization of a collection.</param>
        /// <param name="br"><see cref="BinaryReader"/> to read data with.</param>
        public override void Import(SerializeType type, BinaryReader br)
        {
            var position = br.BaseStream.Position;
            var header   = new SerializationHeader();

            header.Read(br);

            var collection = new TPKBlock();

            if (header.ID != BinBlockID.Nikki)
            {
                br.BaseStream.Position = position;

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    var offset = br.BaseStream.Position;
                    var id     = br.ReadEnum <BinBlockID>();
                    var size   = br.ReadInt32();

                    br.BaseStream.Position = offset;

                    if (id == BinBlockID.EmitterTexturePage)
                    {
                        collection.ReadTexturePages(br);
                    }

                    if (id == BinBlockID.TPKBlocks)
                    {
                        collection.Disassemble(br);
                        break;
                    }

                    br.BaseStream.Position = offset + size + 8;
                }
            }
            else
            {
                if (header.Game != this.GameINT)
                {
                    throw new Exception($"Stated game inside collection is {header.Game}, while should be {this.GameINT}");
                }

                if (header.Name != this.Name)
                {
                    throw new Exception($"Imported collection is not a collection of type {this.Name}");
                }

                collection.Deserialize(br);
            }

            var index = this.IndexOf(collection);

            if (index == -1)
            {
                collection.Manager = this;
                this.Add(collection);
            }
            else
            {
                switch (type)
                {
                case SerializeType.Negate:
                    break;

                case SerializeType.Override:
                    collection.Manager = this;
                    this.Replace(collection, index);
                    break;

                case SerializeType.Synchronize:
                    this[index].Synchronize(collection);
                    break;

                default:
                    break;
                }
            }
        }