Beispiel #1
0
        private static bool TryGetFromCache(Context context, VirtualFile parent, IPath path, IStreamFactory extractedFile, Hash hash, out VirtualFile found)
        {
            var result = _vfsCache.Get(hash.ToArray());

            if (result == null)
            {
                found = null;
                return(false);
            }

            var data = IndexedVirtualFile.Read(new MemoryStream(result));

            found      = ConvertFromIndexedFile(context, data, path, parent, extractedFile);
            found.Name = path;
            found.Hash = hash;
            return(true);
        }
        public static IndexedVirtualFile Read(Stream s)
        {
            using var br = new BinaryReader(s);
            var ivf = new IndexedVirtualFile
            {
                Size = br.ReadInt64(),
            };
            var lst = new List <IndexedVirtualFile>();

            ivf.Children = lst;
            var count = br.ReadInt32();

            for (int x = 0; x < count; x++)
            {
                lst.Add(Read(br));
            }
            return(ivf);
        }
Beispiel #3
0
        private static VirtualFile ConvertFromIndexedFile(Context context, IndexedVirtualFile file, IPath path, VirtualFile vparent, IExtractedFile extractedFile)
        {
            var vself = new VirtualFile
            {
                Context      = context,
                Name         = path,
                Parent       = vparent,
                Size         = file.Size,
                LastModified = extractedFile.LastModifiedUtc.AsUnixTime(),
                LastAnalyzed = DateTime.Now.AsUnixTime(),
                Hash         = file.Hash
            };

            vself.FillFullPath();

            vself.Children = file.Children.Select(f => ConvertFromIndexedFile(context, f, f.Name, vself, extractedFile)).ToImmutableList();

            return(vself);
        }
Beispiel #4
0
        private static bool TryGetFromCache(Context context, VirtualFile parent, IPath path, IStreamFactory extractedFile, Hash hash, out VirtualFile found)
        {
            using var cmd   = new SQLiteCommand(_conn);
            cmd.CommandText = @"SELECT Contents FROM VFSCache WHERE Hash = @hash";
            cmd.Parameters.AddWithValue("@hash", (long)hash);

            using var rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                var data = IndexedVirtualFile.Read(rdr.GetStream(0));
                found      = ConvertFromIndexedFile(context, data, path, parent, extractedFile);
                found.Name = path;
                found.Hash = hash;
                return(true);
            }

            found = default;
            return(false);
        }
        private static IndexedVirtualFile Read(BinaryReader br)
        {
            var ivf = new IndexedVirtualFile
            {
                Name = (RelativePath)br.ReadString(),
                Hash = Hash.FromULong(br.ReadUInt64()),
                Size = br.ReadInt64(),
            };
            var lst = new List <IndexedVirtualFile>();

            ivf.Children = lst;
            var count = br.ReadInt32();

            for (int x = 0; x < count; x++)
            {
                lst.Add(Read(br));
            }

            return(ivf);
        }