Exemplo n.º 1
0
        public FSTree ReadFSTree()
        {
            var extractor = this.extractorPool.Get();
            var root      = new FSTreeNode(true);

            foreach (var entry in extractor.ArchiveFileData)
            {
                // Console.WriteLine($"Loading {entry.FileName} into FS tree");
                var paths = entry.FileName.Split('/', '\\');
                var node  = root;
                for (var i = 0; i < paths.Length - 1; i++)
                {
                    node = node.GetOrAddChild(true, paths[i]);
                }

                if (!string.IsNullOrEmpty(paths[paths.Length - 1]))
                {
                    node = node.GetOrAddChild(entry.IsDirectory, paths[paths.Length - 1], (long)entry.Size,
                                              (long)entry.Size, entry.Index);
                    node.CreationTime   = entry.CreationTime;
                    node.LastAccessTime = entry.LastAccessTime;
                    node.LastWriteTime  = entry.LastWriteTime;
                    // if (!node.IsDirectory && node.Buffer == IntPtr.Zero)
                    // {
                    //     node.Buffer = Marshal.AllocHGlobal((IntPtr) node.Length);
                    // }
                }
            }

            Console.WriteLine($"Loaded {extractor.FilesCount} entries from archive");
            this.extractorPool.Put(extractor);
            return(new FSTree {
                Root = root
            });
        }
Exemplo n.º 2
0
        public FSTree ReadFSTree()
        {
            var root = new FSTreeNode(true);

            foreach (var entry in archive.Entries)
            {
                Console.WriteLine($"Loading {entry.FullName} into FS tree");
                var paths = entry.FullName.Split('/', '\\');
                var node  = root;
                for (var i = 0; i < paths.Length - 1; i++)
                {
                    node = node.GetOrAddChild(true, paths[i]);
                }

                var name = paths[paths.Length - 1];
                if (!string.IsNullOrEmpty(name))
                {
                    node = node.GetOrAddChild(false, name, entry.Length, entry.CompressedLength, entry);
                    node.LastWriteTime = entry.LastWriteTime.DateTime;
                }

                node.Context = entry;
            }

            Console.WriteLine($"Loaded {archive.Entries.Count} entries from archive");
            return(new FSTree {
                Root = root
            });
        }
Exemplo n.º 3
0
        public void ExtractFileUnmanaged(FSTreeNode node, IntPtr buffer)
        {
            if (!(node.Context is ZipArchiveEntry entry))
            {
                throw new ArgumentException();
            }

            unsafe
            {
                using var source = entry.Open();
                using var target = new UnmanagedMemoryStream((byte *)buffer.ToPointer(), node.Length, node.Length,
                                                             FileAccess.Write);
                source.CopyTo(target);
            }
        }
Exemplo n.º 4
0
        public void ExtractFileUnmanaged(FSTreeNode node, IntPtr buffer)
        {
            if (!(node.Context is int index))
            {
                throw new ArgumentException();
            }

            unsafe
            {
                using var target = new UnmanagedMemoryStream((byte *)buffer.ToPointer(), node.Length, node.Length,
                                                             FileAccess.Write);
                var extractor = this.extractorPool.Get();
                extractor.ExtractFile(index, target);
                this.extractorPool.Put(extractor);
            }
        }
Exemplo n.º 5
0
        public FSTreeNode GetOrAddChild(bool isDirectory, string name, long length = 0, long compressedLength = 0,
                                        object context = null)
        {
            if (this.Children == null)
            {
                return(null);
            }

            var caseInsensitiveName = name.ToLower();

            if (this.Children.ContainsKey(caseInsensitiveName))
            {
                return(this.Children[caseInsensitiveName]);
            }

            var child = new FSTreeNode(isDirectory)
            {
                Parent           = this,
                Name             = name,
                FullName         = $"{this.FullName}\\{name}",
                Length           = length,
                CompressedLength = compressedLength,
                Context          = context,
            };

            this.Children[caseInsensitiveName] = child;

            if (!isDirectory)
            {
                var parent = this;
                while (parent != null)
                {
                    parent.Length           += length;
                    parent.CompressedLength += compressedLength;
                    parent = parent.Parent;
                }
            }

            return(child);
        }