Exemplo n.º 1
0
        /// <summary>
        /// Add a Object Item to the Cache
        /// </summary>
        /// <param name="oci">The Cache Item</param>
        /// <param name="filename">name of the package File where the Object was in</param>
        public void AddItem(ObjectCacheItem oci, string filename)
        {
            CacheContainer mycc = this.UseConatiner(ContainerType.Object, filename);

            mycc.Items.Add(oci);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load the Container from the Stream
        /// </summary>
        /// <param name="reader">the Stream Reader</param>
        internal void Load(System.IO.BinaryReader reader)
        {
            valid = ContainerValid.FileNotFound;
            items.Clear();
            int offset = reader.ReadInt32();

            version = reader.ReadByte();
            type    = (ContainerType)reader.ReadByte();
            int count = reader.ReadInt32();

            long pos = reader.BaseStream.Position;

            try
            {
                if (version <= VERSION)
                {
                    reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
                    added    = DateTime.FromFileTime(reader.ReadInt64());
                    filename = reader.ReadString();

                    if (System.IO.File.Exists(filename))
                    {
                        DateTime mod = System.IO.File.GetLastWriteTime(filename);
                        if (mod <= added)
                        {
                            valid = ContainerValid.Yes;
                        }
                        else
                        {
                            valid = ContainerValid.Modified;
                        }
                    }

                    if (valid == ContainerValid.Yes)
                    {
                        switch (type)
                        {
                        case ContainerType.Object:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                ObjectCacheItem oci = new ObjectCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }

                        case ContainerType.MaterialOverride:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                MMATCacheItem oci = new MMATCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }

                        case ContainerType.Rcol:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                RcolCacheItem oci = new RcolCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }

                        case ContainerType.Want:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                WantCacheItem oci = new WantCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }

                        case ContainerType.Memory:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                MemoryCacheItem oci = new MemoryCacheItem();
                                oci.Load(reader);
                                oci.ParentCacheContainer = this;
                                if (oci.Version >= MemoryCacheItem.DISCARD_VERSIONS_SMALLER_THAN)
                                {
                                    items.Add(oci);
                                }
                            }

                            break;
                        }

                        case ContainerType.Package:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                PackageCacheItem oci = new PackageCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }
                        }         //switch
                    }             // if valid
                }                 //if VERSION
                else
                {
                    valid = ContainerValid.UnknownVersion;
                }
            }
            finally
            {
                reader.BaseStream.Seek(pos, System.IO.SeekOrigin.Begin);
            }
        }