예제 #1
0
        public void Init()
        {
            bool Epfile = true;

            Cache         = new Dictionary <string, T>();
            EntriesByName = new Dictionary <string, Far1ProviderEntry <T> >();
            EntriesOfType = new Dictionary <string, List <Far1ProviderEntry <T> > >();

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

            foreach (var farPath in FarFiles)
            {
                if (farPath.Contains("Expansion") || farPath.Contains("Global") || farPath.Contains("Objects"))
                {
                    Epfile = false;
                }

                string dirpath = Epfile ? ContentManager.GetPath(farPath) : farPath;

                var archive = new FAR1Archive(dirpath, Epfile);
                var entries = archive.GetAllFarEntries();

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

                            EntriesByName[entry.Filename] = referenceItem;
                            List <Far1ProviderEntry <T> > group = null;
                            if (!EntriesOfType.TryGetValue(ext, out group))
                            {
                                group = new List <Far1ProviderEntry <T> >();
                                EntriesOfType[ext] = group;
                            }
                            group.Add(referenceItem);
                        }
                    }
                }
            }
        }
예제 #2
0
 public T ThrowawayGet(Far1ProviderEntry <T> entry)
 {
     byte[] data = entry.Archive.GetEntry(entry.FarEntry);
     using (var stream = new MemoryStream(data, false))
     {
         T result = this.Codec.Decode(stream);
         return(result);
     }
 }
예제 #3
0
 public T ThrowawayGet(Far1ProviderEntry <T> entry)
 {
     byte[] data = entry.Archive.GetEntry(entry.FarEntry);
     using (var stream = new MemoryStream(data, false))
     {
         if (Codec == null)
         {
             return((T)SmartCodec.Decode(stream, Path.GetExtension(entry.FarEntry.Filename)));
         }
         T result = this.Codec.Decode(stream);
         return(result);
     }
 }
예제 #4
0
        public void Init()
        {
            Cache         = new TimedReferenceCache <string, T>();
            EntriesByName = new Dictionary <string, Far1ProviderEntry <T> >();
            EntriesOfType = new Dictionary <string, List <Far1ProviderEntry <T> > >();

            if (FarFilePattern != null)
            {
                List <string> farFiles = new List <string>();
                string[]      allFiles = (TS1) ? ContentManager.TS1AllFiles : ContentManager.AllFiles;
                foreach (var file in allFiles)
                {
                    if (FarFilePattern.IsMatch(file.Replace('\\', '/')))
                    {
                        farFiles.Add(file);
                    }
                }
                FarFiles = farFiles.ToArray();
            }

            foreach (var farPath in FarFiles)
            {
                var archive = new FAR1Archive((TS1)?Path.Combine(ContentManager.TS1BasePath, farPath):ContentManager.GetPath(farPath), !TS1);
                var entries = archive.GetAllFarEntries();

                foreach (var entry in entries)
                {
                    var referenceItem = new Far1ProviderEntry <T>(this)
                    {
                        Archive  = archive,
                        FarEntry = entry
                    };
                    if (entry.Filename != null)
                    {
                        EntriesByName[entry.Filename] = referenceItem;
                        var ext = Path.GetExtension(entry.Filename).ToLowerInvariant();
                        List <Far1ProviderEntry <T> > group = null;
                        if (!EntriesOfType.TryGetValue(ext, out group))
                        {
                            group = new List <Far1ProviderEntry <T> >();
                            EntriesOfType[ext] = group;
                        }
                        group.Add(referenceItem);
                    }
                }
            }
        }
예제 #5
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.Replace('\\', '/')))
                    {
                        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;
                    }
                }
            }
        }
예제 #6
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);
                    if (result is IFileInfoUtilizer)
                    {
                        ((IFileInfoUtilizer)result).SetFilename(entry.FarEntry.Filename);
                    }
                    this.Cache.Add(entry.FarEntry.Filename, result);
                    return(result);
                }
            }
        }
예제 #7
0
 public T Get(Far1ProviderEntry <T> entry)
 {
     return(Cache.GetOrAdd(entry.FarEntry.Filename, (name) =>
     {
         byte[] data = entry.Archive.GetEntry(entry.FarEntry);
         using (var stream = new MemoryStream(data, false))
         {
             T result = default(T);
             if (Codec == null)
             {
                 result = (T)SmartCodec.Decode(stream, Path.GetExtension(entry.FarEntry.Filename));
             }
             else
             {
                 result = this.Codec.Decode(stream);
             }
             if (result is IFileInfoUtilizer)
             {
                 ((IFileInfoUtilizer)result).SetFilename(entry.FarEntry.Filename);
             }
             return result;
         }
     }));
 }