Esempio n. 1
0
        public T Get(Far1ProviderEntry <T> entry)
        {
            lock (Cache)
            {
                if (this.Cache.ContainsKey(entry.FarEntry.Filename))
                {
                    return(this.Cache[entry.FarEntry.Filename]);
                }

                byte[] data = entry.Archive.GetEntry(entry.FarEntry);
                using (var stream = new MemoryStream(data, false))
                {
                    T result = this.Codec.Decode(stream);
                    this.Cache.Add(entry.FarEntry.Filename, result);
                    return(result);
                }
            }
        }
Esempio n. 2
0
        public void Init()
        {
            Cache         = new Dictionary <string, T>();
            EntriesByName = new Dictionary <string, Far1ProviderEntry <T> >();

            if (FarFilePattern != null)
            {
                List <string> farFiles = new List <string>();
                foreach (var file in ContentManager.AllFiles)
                {
                    if (FarFilePattern.IsMatch(file))
                    {
                        farFiles.Add(file);
                    }
                }
                FarFiles = farFiles.ToArray();
            }

            foreach (var farPath in FarFiles)
            {
                var archive = new FAR1Archive(ContentManager.GetPath(farPath));
                var entries = archive.GetAllFarEntries();

                foreach (var entry in entries)
                {
                    var referenceItem = new Far1ProviderEntry <T>(this)
                    {
                        Archive  = archive,
                        FarEntry = entry
                    };
                    if (entry.Filename != null)
                    {
                        if (EntriesByName.ContainsKey(entry.Filename))
                        {
                            System.Diagnostics.Debug.WriteLine("Duplicate! " + entry.Filename);
                        }
                        EntriesByName[entry.Filename] = referenceItem;
                    }
                }
            }
        }