Exemplo n.º 1
0
        protected virtual T ResolveById(ulong id)
        {
            Far3ProviderEntry <T> entry = null;

            if (EntriesById.TryGetValue(id, out entry))
            {
                return(Get(entry));
            }
            return(default(T));
        }
Exemplo n.º 2
0
        public string GetNameByID(ulong ID)
        {
            Far3ProviderEntry <T> entry = null;

            if (EntriesById.TryGetValue(ID, out entry))
            {
                return(entry.ToString());
            }
            return("unnamed");
        }
Exemplo n.º 3
0
        public void Init()
        {
            if (Initialized)
            {
                return;
            }
            Initialized = true;
            Cache       = new TimedReferenceCache <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.Replace('\\', '/')))
                        {
                            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[entry.Filename.ToLowerInvariant()] = referenceItem;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
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)
 {
     //thread safe.
     return(Cache.GetOrAdd(Entry.ID, (id) =>
     {
         byte[] data = Entry.Archive.GetEntry(Entry.FarEntry);
         using (var stream = new MemoryStream(data, false))
         {
             T result = this.Codec.Decode(stream);
             if (result is IFileInfoUtilizer)
             {
                 ((IFileInfoUtilizer)result).SetFilename(Entry.FarEntry.Filename);
             }
             return result;
         }
     }));
 }
        /// <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);
                    if (result is IFileInfoUtilizer)
                    {
                        ((IFileInfoUtilizer)result).SetFilename(Entry.FarEntry.Filename);
                    }
                    this.Cache.Add(Entry.ID, result);
                    return(result);
                }
            }
        }