Exemplo n.º 1
0
        public void Init()
        {
            Cache = new Dictionary <ulong, T>();
            lock (Cache)
            {
                EntriesById   = new Dictionary <ulong, Far3ProviderEntry <T> >();
                EntriesByName = new Dictionary <string, Far3ProviderEntry <T> >();

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

                    m_FarFiles = FarFiles.ToArray();
                }

                foreach (var FarPath in m_FarFiles)
                {
                    var archive = new FAR3Archive(ContentManager.GetPath(FarPath));
                    var entries = archive.GetAllFAR3Entries();

                    foreach (var entry in entries)
                    {
                        var fileID = ((ulong)entry.FileID) << 32;

                        var referenceItem = new Far3ProviderEntry <T>(this)
                        {
                            ID       = fileID | entry.TypeID,
                            Archive  = archive,
                            FarEntry = entry
                        };

                        EntriesById.Add(referenceItem.ID, referenceItem);
                        if (entry.Filename != null)
                        {
                            EntriesByName.Add(entry.Filename.ToLower(), referenceItem);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets an archive based on a Far3ProviderEntry.
        /// </summary>
        /// <param name="Entry">The Far3ProviderEntry of the archive.</param>
        /// <returns>A FAR3 archive.</returns>
        public T Get(Far3ProviderEntry <T> Entry)
        {
            lock (Cache)
            {
                if (this.Cache.ContainsKey(Entry.ID))
                {
                    return(this.Cache[Entry.ID]);
                }

                byte[] data = Entry.Archive.GetEntry(Entry.FarEntry);
                using (var stream = new MemoryStream(data, false))
                {
                    T result = this.Codec.Decode(stream);
                    this.Cache.Add(Entry.ID, result);
                    return(result);
                }
            }
        }