예제 #1
0
        /// <summary>
        /// Load/Add a Cache Item for the passed File
        /// </summary>
        /// <param name="filename">The Name of the File</param>
        public ScannerItem LoadItem(string filename)
        {
            CacheContainer mycc = this.UseConatiner(ContainerType.Package, filename);

            if (mycc.Items.Count == 0)
            {
                PackageCacheItem pci  = new PackageCacheItem();
                ScannerItem      item = new ScannerItem(pci, mycc);
                item.FileName = filename;
                pci.Name      = System.IO.Path.GetFileNameWithoutExtension(filename);
                mycc.Items.Add(pci);

                return(item);
            }
            else
            {
                ScannerItem item = new ScannerItem((PackageCacheItem)mycc.Items[0], mycc);
                item.FileName = filename;

                return(item);
            }
        }
예제 #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);
            }
        }