Пример #1
0
        public bool TryGetFile(uint key, out File file)
        {
            WeakReference <File> fileRef;

            if (_Files.TryGetValue(key, out fileRef) && fileRef.TryGetTarget(out file))
            {
                return(true);
            }

            IndexFile index;

            if (Index.Files.TryGetValue(key, out index))
            {
                file = FileFactory.Get(this.Pack, index);
                if (_Files.ContainsKey(key))
                {
                    _Files[key].SetTarget(file);
                }
                else
                {
                    _Files.Add(key, new WeakReference <File>(file));
                }
                return(true);
            }

            file = null;
            return(false);
        }
Пример #2
0
        public bool TryGetFile(uint hash, out File value)
        {
            WeakReference <File> fileRef;

            if (_Files.TryGetValue(hash, out fileRef) && fileRef.TryGetTarget(out value))
            {
                return(true);
            }

            Index2File index;

            if (Index.Files.TryGetValue(hash, out index))
            {
                value = FileFactory.Get(this.Pack, index);
                if (_Files.ContainsKey(hash))
                {
                    _Files[hash].SetTarget(value);
                }
                else
                {
                    _Files.Add(hash, new WeakReference <File>(value));
                }
                return(true);
            }

            value = null;
            return(false);
        }
Пример #3
0
        public File GetFile(uint hash)
        {
            if (_Files.TryGetValue(hash, out var fileRef) && fileRef.TryGetTarget(out var file))
            {
                return(file);
            }

            var index = Index.Files[hash];

            file = FileFactory.Get(this.Pack, index);
            if (_Files.ContainsKey(hash))
            {
                _Files[hash].SetTarget(file);
            }
            else
            {
                _Files.Add(hash, new WeakReference <File>(file));
            }
            return(file);
        }
Пример #4
0
        public File GetFile(uint key)
        {
            if (_Files.TryGetValue(key, out var fileRef) && fileRef.TryGetTarget(out var file))
            {
                return(file);
            }

            if (!Index.Files.TryGetValue(key, out var index))
            {
                return(null);
            }

            file = FileFactory.Get(this.Pack, index);
            _Files.AddOrUpdate(key,
                               k => new WeakReference <File>(file),
                               (k, r) => {
                r.SetTarget(file);
                return(r);
            });
            return(file);
        }
Пример #5
0
        public File GetFile(uint key)
        {
            if (_Files.TryGetValue(key, out var fileRef) && fileRef.TryGetTarget(out var file))
            {
                return(file);
            }

            if (!Index.Files.TryGetValue(key, out var index))
            {
                return(null);
            }
            file = FileFactory.Get(this.Pack, index);
            if (_Files.ContainsKey(key))
            {
                _Files[key].SetTarget(file);
            }
            else
            {
                _Files.Add(key, new WeakReference <File>(file));
            }
            return(file);
        }
Пример #6
0
        public bool TryGetFile(uint key, out File file)
        {
            if (_Files.TryGetValue(key, out var fileRef) && fileRef.TryGetTarget(out file))
            {
                return(true);
            }

            if (Index.Files.TryGetValue(key, out var index))
            {
                var theFile = FileFactory.Get(this.Pack, index);
                _Files.AddOrUpdate(key,
                                   k => new WeakReference <File>(theFile),
                                   (k, r) => {
                    r.SetTarget(theFile);
                    return(r);
                });
                file = theFile;
                return(true);
            }

            file = null;
            return(false);
        }