Beispiel #1
0
        public ArchiveMap(StreamWithRangeValues fI, StreamWithRangeValues fL, int max)
        {
            if (fI == null || fL == null)
            {
                throw new ArgumentNullException($"{nameof(ArchiveMap)}::{nameof(ArchiveMap)} {nameof(fI)} or {nameof(fL)} is null");
            }
            Max = max;
            Stream s1     = Uncompress(fL, out long flOffset);
            Stream s2     = Uncompress(fI, out long fiOffset);
            long   fiSize = fI.UncompressedSize == 0 ? fI.Size : fI.UncompressedSize;

            using (StreamReader sr = new StreamReader(s1, System.Text.Encoding.UTF8))
                using (BinaryReader br = new BinaryReader(s2))
                {
                    s1.Seek(flOffset, SeekOrigin.Begin);
                    s2.Seek(fiOffset, SeekOrigin.Begin);
                    _entries = new Dictionary <string, FI>();
                    long count = fiSize / 12;
                    while (count-- > 0)
                    {
                        _entries.Add(sr.ReadLine()?.TrimEnd() ?? throw new InvalidOperationException(), Extended.ByteArrayToClass <FI>(br.ReadBytes(12)));
                    }
                }
            CorrectCompressionForLzsFiles();
        }
Beispiel #2
0
 public void GetArchive(Memory.Archive archive, out StreamWithRangeValues fi, out ArchiveBase fs, out StreamWithRangeValues fl)
 {
     Memory.Log.WriteLine($"{nameof(ArchiveBase)}::{nameof(GetArchive)} - Reading: {archive.FI}, {archive.FS}, {archive.FL}");
     fi = GetStreamWithRangeValues(archive.FI);
     fs = this;
     fl = GetStreamWithRangeValues(archive.FL);
 }
Beispiel #3
0
 public FL(StreamWithRangeValues fL)
 {
     using (StreamReader br = new StreamReader(fL, System.Text.Encoding.UTF8))
     {
         fL.Seek(fL.Offset, SeekOrigin.Begin);
         while (fL.Position < fL.Max)
         {
             _data.Add(br.ReadLine()?.TrimEnd());
         }
     }
 }
Beispiel #4
0
        private ArchiveWorker(Memory.Archive archive, StreamWithRangeValues fI, ArchiveBase fS, StreamWithRangeValues fL, bool skipList = false)
        {
            ArchiveMap = new ArchiveMap(fI, fL, fS.GetMaxSize(archive));
            Archive    = archive;
            FsArchive  = fS;
            //FS = null;
            if (!skipList)
            {
                GetListOfFiles();
            }

            IsOpen = true;
        }
 public StreamWithRangeValues(Stream s, long offset, long size, CompressionType compression = 0, int uncompressedSize = 0)
 {
     if (typeof(StreamWithRangeValues) == s.GetType())
     {
         StreamWithRangeValues r = (StreamWithRangeValues)s;
         Debug.Assert(r.Compression == 0);
         offset += r.Offset;
     }
     _s               = s;
     Size             = size;
     Offset           = offset;
     Position         = offset;
     Compression      = compression;
     UncompressedSize = checked ((int)(uncompressedSize == 0 ? size : uncompressedSize));
 }
Beispiel #6
0
        /// <summary>
        /// Load Archive with out storing FS in byte[] works for archive that aren't compressed.
        /// </summary>
        /// <param name="path">Archive file archive.</param>
        /// <param name="fI">Stream containing the FI file</param>
        /// <param name="fS">Archive where the FS file is.</param>
        /// <param name="fL">Stream containing the FL file</param>
        /// <param name="skipList">Skip generating list of files</param>
        /// <returns>ArchiveWorker</returns>
        public static ArchiveBase Load(Memory.Archive path, StreamWithRangeValues fI, ArchiveBase fS, StreamWithRangeValues fL, bool skipList = false)
        {
            if (CacheTryGetValue(path, out var value))
            {
                return(value);
            }

            value = new ArchiveWorker(path, fI, fS, fL, skipList);
            if (!value.IsOpen)
            {
                value = null;
            }
            if (CacheTryAdd(path, value))
            {
            }
            return(value);
        }