Exemple #1
0
        //prevent two loads at the same time.

        #region Methods

        public static ArchiveBase Load(Memory.Archive path, bool skipList = false)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(null);
            }
            lock (Locker)
            {
                if (CacheTryGetValue(path, out ArchiveBase value))
                {
                    return(value);
                }
                else
                {
                    value = new ArchiveZzz(path, skipList);
                    if (!value.IsOpen)
                    {
                        value = null;
                    }
                    if (value == null || string.IsNullOrWhiteSpace(path))
                    {
                        return(null);
                    }
                    if (CacheTryAdd(value.GetPath() ?? path, value))
                    {
                    }
                    path.SetFilename(value.GetPath() ?? path);
                }
                return(value);
            }
        }
Exemple #2
0
        public override ArchiveBase GetArchive(Memory.Archive archive)
        {
            if (archive == Memory.Archives.ZZZ_MAIN || archive == Memory.Archives.ZZZ_OTHER)
            {
                var zzz = archive.ZZZ;
                if (FindFile(ref zzz) <= -1 || string.IsNullOrWhiteSpace(zzz))
                {
                    return(null);
                }
                if (File.Exists(zzz))
                {
                    archive.SetFilename(zzz);
                }
                return(!CacheTryGetValue(archive, out var ab) ? ArchiveZzz.Load(zzz) : ab);
            }

            if (CacheTryGetValue(archive, out var value))
            {
                return(value);
            }
            GetArchive(archive, out var fI, out var fS, out StreamWithRangeValues fL);
            return(fI == null || fS == null || fL == null ||
                   fI.Length == 0 || fL.Length == 0
                ? null
                : new ArchiveWorker(archive, fI, fS, fL));
        }
Exemple #3
0
        private ArchiveZzz(Memory.Archive archive, bool skipList = false)
        {
            ArchiveBase tempArchive = null;

            ParentPath = FindParentPath(archive);
            if (ParentPath != null && ParentPath.Count > 0)
            {
                foreach (Memory.Archive p in ParentPath)
                {
                    if (p.IsDir)
                    {
                        tempArchive = ArchiveBase.Load(p);
                    }
                    else if (tempArchive != null)
                    {
                        throw new Exception("zzz shouldn't be inside an archive.");
                    }
                }
            }
            Archive = archive;
            if (tempArchive != null)
            {
                archive.SetFilename(tempArchive.GetListOfFiles()
                                    .FirstOrDefault(x => x.IndexOf(archive.ZZZ, StringComparison.OrdinalIgnoreCase) > 0));
            }
            Memory.Log.WriteLine($"{nameof(ArchiveZzz)}:: opening archiveFile: {archive}");
            if (string.IsNullOrWhiteSpace(archive))
            {
                return;
            }
            using (BinaryReader br = Open())
            {
                if (br == null)
                {
                    return;
                }
                ArchiveMap = Header.Load(br);
            }
            if (!skipList)
            {
                GetListOfFiles();
            }
            IsOpen = true;
        }