diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs index 2a5ab58..934fb6d 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs @@ -4,6 +4,8 @@ using System.IO; using System.Linq; using System.Windows.Controls; using SharpCompress.Archives; +using SharpCompress.Common; +using SharpCompress.Readers; namespace QuickLook.Plugin.ArchiveViewer { @@ -13,7 +15,6 @@ namespace QuickLook.Plugin.ArchiveViewer public partial class ArchiveInfoPanel : UserControl, IDisposable { private readonly Dictionary _fileEntries = new Dictionary(); - private bool _solid; private ulong _totalZippedSize; private string _type; @@ -30,6 +31,7 @@ namespace QuickLook.Plugin.ArchiveViewer { GC.SuppressFinalize(this); + _fileEntries.Clear(); fileListView.Dispose(); } @@ -40,6 +42,8 @@ namespace QuickLook.Plugin.ArchiveViewer private void LoadArchive(string path) { + _totalZippedSize = (ulong) new FileInfo(path).Length; + LoadItemsFromArchive(path); var folders = -1; // do not count root node @@ -55,8 +59,6 @@ namespace QuickLook.Plugin.ArchiveViewer sizeU += e.Value.Size; }); - var s = _solid ? ", solid" : ""; - string t; var d = folders != 0 ? $"{folders} folders" : string.Empty; var f = files != 0 ? $"{files} files" : string.Empty; @@ -68,7 +70,7 @@ namespace QuickLook.Plugin.ArchiveViewer t = $", {d}{f}"; archiveCount.Content = - $"{_type} archive{s}{t}"; + $"{_type} archive{t}"; archiveSizeC.Content = $"Compressed size {_totalZippedSize.ToPrettySize(2)}"; archiveSizeU.Content = $"Uncompressed size {sizeU.ToPrettySize(2)}"; } @@ -77,21 +79,36 @@ namespace QuickLook.Plugin.ArchiveViewer { using (var stream = File.OpenRead(path)) { - var archive = ArchiveFactory.Open(stream); + // https://github.com/adamhathcock/sharpcompress/blob/master/FORMATS.md says: + // The 7Zip format doesn't allow for reading as a forward-only stream so 7Zip is only supported through the Archive API + if (Path.GetExtension(path).ToLower() == ".7z") + { + var archive = ArchiveFactory.Open(stream); - _totalZippedSize = (ulong) archive.TotalSize; - _solid = archive.IsSolid; - _type = archive.Type.ToString(); + _type = archive.Type.ToString(); - var root = new ArchiveFileEntry(Path.GetFileName(path), true); - _fileEntries.Add("", root); + var root = new ArchiveFileEntry(Path.GetFileName(path), true); + _fileEntries.Add("", root); - foreach (var entry in archive.Entries) - ProcessByLevel(entry); + foreach (var entry in archive.Entries) + ProcessByLevel(entry); + } + else + { + 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); + } } } - private void ProcessByLevel(IArchiveEntry entry) + private void ProcessByLevel(IEntry entry) { var pf = GetPathFragments(entry.Key); diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs index 779301c..dd1878d 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs @@ -22,11 +22,14 @@ namespace QuickLook.Plugin.ArchiveViewer switch (Path.GetExtension(path).ToLower()) { - case ".zip": case ".rar": - case ".7z": - case ".gz": + case ".zip": case ".tar": + case ".gz": + case ".bz2": + case ".lz": + case ".xz": + case ".7z": return true; default: diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/QuickLook.Plugin.ArchiveViewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/QuickLook.Plugin.ArchiveViewer.csproj index fc2da8c..cff609b 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/QuickLook.Plugin.ArchiveViewer.csproj +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/QuickLook.Plugin.ArchiveViewer.csproj @@ -52,8 +52,8 @@ - - ..\..\packages\SharpCompress.0.15.2\lib\net45\SharpCompress.dll + + ..\..\packages\SharpCompress.0.17.0\lib\net45\SharpCompress.dll diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/packages.config b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/packages.config index 64b6360..1419a16 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/packages.config +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/packages.config @@ -1,5 +1,4 @@  - - + \ No newline at end of file diff --git a/README.md b/README.md index 0b834c4..9f30829 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ You may ask, why you write this when there several alternatives available on the Till now, QuickLook supports the preview of - Images: e.g. `.png`, `.jpg`, `.bmp`, `.gif`, `.psd` and Camera RAW formats - - Compressed archives: `.zip`, `.rar`, `.7z` etc. + - Compressed archives: `.zip`, `.rar`, `.tar.gz`, `.7z` etc. - Pdf file - All kinds of text files (determined by file content) - Microsoft Word (`.doc`, `.docx`), Excel (`.xls`, `.xlsx`) and PowerPoint (`.ppt`, `.pptx`) files (requires MS Office installation)