mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 02:09:05 +00:00
Refresh SharpCompress library
This commit is contained in:
@@ -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<string, ArchiveFileEntry> _fileEntries = new Dictionary<string, ArchiveFileEntry>();
|
||||
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)}";
|
||||
}
|
||||
@@ -76,11 +78,13 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
private void LoadItemsFromArchive(string path)
|
||||
{
|
||||
using (var stream = File.OpenRead(path))
|
||||
{
|
||||
// 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();
|
||||
|
||||
var root = new ArchiveFileEntry(Path.GetFileName(path), true);
|
||||
@@ -89,9 +93,22 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
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);
|
||||
|
||||
|
@@ -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:
|
||||
|
@@ -52,8 +52,8 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="SharpCompress, Version=0.15.2.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\SharpCompress.0.15.2\lib\net45\SharpCompress.dll</HintPath>
|
||||
<Reference Include="SharpCompress, Version=0.17.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\SharpCompress.0.17.0\lib\net45\SharpCompress.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="SharpCompress" version="0.15.2" targetFramework="net452" />
|
||||
<package id="SharpCompress" version="0.17.0" targetFramework="net462" />
|
||||
</packages>
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user