private void LoadItemsFromArchive(string path) { using (var stream = File.OpenRead(path)) { var archive = ArchiveFactory.Open(stream); _totalZippedSize = (ulong)archive.TotalSize; _solid = archive.IsSolid; _type = archive.Type.ToString(); var root = new ArchiveFileEntry(Path.GetFileName(path), true); _fileEntries.Add("", root); foreach (var entry in archive.Entries) { ProcessByLevel(entry); } } }
private void ProcessByLevel(IEntry entry) { var pf = GetPathFragments(entry.Key); // process folders. When entry is a directory, all fragments are folders. pf.Take(entry.IsDirectory ? pf.Length : pf.Length - 1) .ForEach(f => { // skip if current dir is already added if (_fileEntries.ContainsKey(f)) { return; } ArchiveFileEntry parent; _fileEntries.TryGetValue(GetDirectoryName(f), out parent); var afe = new ArchiveFileEntry(Path.GetFileName(f), true, parent); _fileEntries.Add(f, afe); }); // add the last path fragments, which is a file if (!entry.IsDirectory) { var file = pf.Last(); ArchiveFileEntry parent; _fileEntries.TryGetValue(GetDirectoryName(file), out parent); _fileEntries.Add(file, new ArchiveFileEntry(Path.GetFileName(entry.Key), false, parent) { Encrypted = entry.IsEncrypted, Size = (ulong)entry.Size, ModifiedDate = entry.LastModifiedTime ?? new DateTime() }); } }
private void LoadItemsFromArchive(string path) { using (var stream = File.OpenRead(path)) { // ReaderFactory is slow... so limit its usage string[] useReader = { ".tar.gz", ".tgz", ".tar.bz2", ".tar.lz", ".tar.xz" }; if (useReader.Any(i => path.EndsWith(i))) { var reader = ReaderFactory.Open(stream); _type = reader.ArchiveType.ToString(); var root = new ArchiveFileEntry(Path.GetFileName(path), true); _fileEntries.Add("", root); while (reader.MoveToNextEntry()) { ProcessByLevel(reader.Entry); } } else { var archive = ArchiveFactory.Open(stream); _type = archive.Type.ToString(); var root = new ArchiveFileEntry(Path.GetFileName(path), true); _fileEntries.Add("", root); foreach (var entry in archive.Entries) { ProcessByLevel(entry); } } } }