mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-10 17:29:08 +00:00
COM is really a nightmare... Use managed solution (SharpCompress) instead
This commit is contained in:
2
MakeZip.bat
Normal file
2
MakeZip.bat
Normal file
@@ -0,0 +1,2 @@
|
||||
bc a -r Debug_%date:~-4,4%%date:~-7,2%%date:~-10,2%.zip Build\Debug\*.exe Build\Debug\*.dll
|
||||
bc a -r Release_%date:~-4,4%%date:~-7,2%%date:~-10,2%.zip Build\Release\*.exe Build\Release\*.dll
|
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
using SevenZip;
|
||||
using SharpCompress.Archives;
|
||||
|
||||
namespace QuickLook.Plugin.ArchiveViewer
|
||||
{
|
||||
@@ -65,23 +65,25 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
|
||||
private void LoadItemsFromArchive(string path)
|
||||
{
|
||||
using (var reader = new SevenZipExtractor(path))
|
||||
using (var stream = File.OpenRead(path))
|
||||
{
|
||||
_totalZippedSize = (ulong) reader.PackedSize;
|
||||
_solid = reader.IsSolid;
|
||||
_type = reader.Format.ToString();
|
||||
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 reader.ArchiveFileData)
|
||||
foreach (var entry in archive.Entries)
|
||||
ProcessByLevel(entry);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessByLevel(ArchiveFileInfo entry)
|
||||
private void ProcessByLevel(IArchiveEntry entry)
|
||||
{
|
||||
var pf = GetPathFragments(entry.FileName);
|
||||
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)
|
||||
@@ -107,11 +109,11 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
ArchiveFileEntry parent;
|
||||
_fileEntries.TryGetValue(GetDirectoryName(file), out parent);
|
||||
|
||||
_fileEntries.Add(file, new ArchiveFileEntry(Path.GetFileName(entry.FileName), false, parent)
|
||||
_fileEntries.Add(file, new ArchiveFileEntry(Path.GetFileName(entry.Key), false, parent)
|
||||
{
|
||||
Encrypted = entry.Encrypted,
|
||||
Size = entry.Size,
|
||||
ModifiedDate = entry.LastWriteTime
|
||||
Encrypted = entry.IsEncrypted,
|
||||
Size = (ulong) entry.Size,
|
||||
ModifiedDate = entry.LastModifiedTime ?? new DateTime()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -125,7 +127,7 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
|
||||
private string[] GetPathFragments(string path)
|
||||
{
|
||||
var frags = path.Split('\\');
|
||||
var frags = path.Split('\\', '/').Where(f => !string.IsNullOrEmpty(f)).ToArray();
|
||||
|
||||
return frags.Select((s, i) => frags.Take(i + 1).Aggregate((a, b) => a + "\\" + b)).ToArray();
|
||||
}
|
||||
|
@@ -9,6 +9,9 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values[0] == DependencyProperty.UnsetValue)
|
||||
values[0] = 1;
|
||||
|
||||
var level = (int) values[0];
|
||||
var indent = (double) values[1];
|
||||
return indent * level;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using SevenZip;
|
||||
using SharpCompress.Archives;
|
||||
|
||||
namespace QuickLook.Plugin.ArchiveViewer
|
||||
{
|
||||
@@ -16,41 +16,26 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
if (Directory.Exists(path))
|
||||
return false;
|
||||
|
||||
try
|
||||
using (var stream = File.OpenRead(path))
|
||||
{
|
||||
using (var archive = new SevenZipExtractor(path))
|
||||
try
|
||||
{
|
||||
// dummy access to the data. If it throws exception, return false
|
||||
if (archive.ArchiveFileData == null)
|
||||
return false;
|
||||
|
||||
// ignore some formats
|
||||
switch (archive.Format)
|
||||
{
|
||||
case InArchiveFormat.Chm:
|
||||
case InArchiveFormat.Flv:
|
||||
case InArchiveFormat.Elf:
|
||||
case InArchiveFormat.Msi:
|
||||
case InArchiveFormat.PE:
|
||||
case InArchiveFormat.Swf:
|
||||
return false;
|
||||
}
|
||||
ArchiveFactory.Open(stream);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void BoundViewSize(string path, ViewerObject context)
|
||||
public void BoundViewSize(string path, ContextObject context)
|
||||
{
|
||||
context.PreferredSize = new Size {Width = 800, Height = 600};
|
||||
}
|
||||
|
||||
public void View(string path, ViewerObject context)
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
_panel = new ArchiveInfoPanel(path);
|
||||
|
||||
|
@@ -34,9 +34,8 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="SevenZipSharp">
|
||||
<HintPath>References\SevenZipSharp.dll</HintPath>
|
||||
<EmbedInteropTypes>False</EmbedInteropTypes>
|
||||
<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>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -81,5 +80,8 @@
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="SharpCompress" version="0.15.2" targetFramework="net452" />
|
||||
</packages>
|
@@ -33,14 +33,14 @@ namespace QuickLook.Plugin.ImageViewer
|
||||
}
|
||||
}
|
||||
|
||||
public void BoundViewSize(string path, ViewerObject context)
|
||||
public void BoundViewSize(string path, ContextObject context)
|
||||
{
|
||||
_imageSize = ImageFileHelper.GetImageSize(path);
|
||||
|
||||
context.SetPreferredSizeFit(_imageSize, 0.8);
|
||||
}
|
||||
|
||||
public void View(string path, ViewerObject context)
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
_ip = new ImagePanel(path);
|
||||
|
||||
|
@@ -31,12 +31,12 @@ namespace QuickLook.Plugin.OfficeViewer
|
||||
return false;
|
||||
}
|
||||
|
||||
public void BoundViewSize(string path, ViewerObject context)
|
||||
public void BoundViewSize(string path, ContextObject context)
|
||||
{
|
||||
context.SetPreferredSizeFit(new Size {Width = 800, Height = 600}, 0.8);
|
||||
}
|
||||
|
||||
public void View(string path, ViewerObject context)
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
using (var officeApp = new OfficeInteropWrapper(path))
|
||||
{
|
||||
|
@@ -24,7 +24,7 @@ namespace QuickLook.Plugin.PDFViewer
|
||||
}
|
||||
}
|
||||
|
||||
public void BoundViewSize(string path, ViewerObject context)
|
||||
public void BoundViewSize(string path, ContextObject context)
|
||||
{
|
||||
_pdfControl = new PdfViewerControl();
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace QuickLook.Plugin.PDFViewer
|
||||
context.SetPreferredSizeFit(desiredSize, 0.8);
|
||||
}
|
||||
|
||||
public void View(string path, ViewerObject context)
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
context.ViewerContent = _pdfControl;
|
||||
|
||||
|
@@ -40,12 +40,12 @@ namespace QuickLook.Plugin.TextViewer
|
||||
}
|
||||
}
|
||||
|
||||
public void BoundViewSize(string path, ViewerObject context)
|
||||
public void BoundViewSize(string path, ContextObject context)
|
||||
{
|
||||
context.PreferredSize = new Size {Width = 800, Height = 600};
|
||||
}
|
||||
|
||||
public void View(string path, ViewerObject context)
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
_tvp = new TextViewerPanel(path);
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
|
||||
@@ -11,6 +12,14 @@ namespace QuickLook
|
||||
{
|
||||
public static string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException +=
|
||||
(sender, args) => MessageBox.Show(((Exception) args.ExceptionObject).Message);
|
||||
|
||||
base.OnStartup(e);
|
||||
}
|
||||
|
||||
private void Application_Startup(object sender, StartupEventArgs e)
|
||||
{
|
||||
PluginManager.GetInstance();
|
||||
|
@@ -23,7 +23,7 @@
|
||||
<DockPanel.Style>
|
||||
<Style TargetType="{x:Type DockPanel}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ViewerObject.IsBusy, ElementName=mainWindow}" Value="False">
|
||||
<DataTrigger Binding="{Binding ContextObject.IsBusy, ElementName=mainWindow}" Value="False">
|
||||
<DataTrigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
@@ -43,7 +43,7 @@
|
||||
<fa:ImageAwesome DockPanel.Dock="Right" x:Name="buttonCloseWindow" Icon="TimesCircle"
|
||||
Height="15" Margin="10,0" Foreground="Gray"
|
||||
Cursor="Hand" />
|
||||
<Label x:Name="titlebarTitleArea" Content="{Binding ViewerObject.Title, ElementName=mainWindow}"
|
||||
<Label x:Name="titlebarTitleArea" Content="{Binding ContextObject.Title, ElementName=mainWindow}"
|
||||
FontSize="14" HorizontalContentAlignment="Center"
|
||||
VerticalContentAlignment="Center" />
|
||||
</DockPanel>
|
||||
@@ -55,7 +55,7 @@
|
||||
<Grid.Style>
|
||||
<Style TargetType="{x:Type Grid}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ViewerObject.IsBusy, ElementName=mainWindow}" Value="False">
|
||||
<DataTrigger Binding="{Binding ContextObject.IsBusy, ElementName=mainWindow}" Value="False">
|
||||
<DataTrigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
|
@@ -16,7 +16,7 @@ namespace QuickLook
|
||||
internal MainWindow()
|
||||
{
|
||||
// this object should be initialized before loading UI components, because many of which are binding to it.
|
||||
ViewerObject = new ViewerObject();
|
||||
ContextObject = new ContextObject();
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
@@ -34,13 +34,13 @@ namespace QuickLook
|
||||
titlebarTitleArea.MouseLeftButtonDown += DragMoveCurrentWindow;
|
||||
}
|
||||
|
||||
public ViewerObject ViewerObject { get; }
|
||||
public ContextObject ContextObject { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
ViewerObject?.Dispose();
|
||||
ContextObject?.Dispose();
|
||||
}
|
||||
|
||||
private void DragMoveCurrentWindow(object sender, MouseButtonEventArgs e)
|
||||
@@ -63,12 +63,12 @@ namespace QuickLook
|
||||
|
||||
private new void Show()
|
||||
{
|
||||
Height = ViewerObject.PreferredSize.Height + titlebar.Height + windowBorder.BorderThickness.Top +
|
||||
Height = ContextObject.PreferredSize.Height + titlebar.Height + windowBorder.BorderThickness.Top +
|
||||
windowBorder.BorderThickness.Bottom;
|
||||
Width = ViewerObject.PreferredSize.Width + windowBorder.BorderThickness.Left +
|
||||
Width = ContextObject.PreferredSize.Width + windowBorder.BorderThickness.Left +
|
||||
windowBorder.BorderThickness.Right;
|
||||
|
||||
ResizeMode = ViewerObject.CanResize ? ResizeMode.CanResizeWithGrip : ResizeMode.NoResize;
|
||||
ResizeMode = ContextObject.CanResize ? ResizeMode.CanResizeWithGrip : ResizeMode.NoResize;
|
||||
|
||||
base.Show();
|
||||
|
||||
@@ -77,15 +77,15 @@ namespace QuickLook
|
||||
|
||||
internal void BeginShow(IViewer matchedPlugin, string path)
|
||||
{
|
||||
ViewerObject.CurrentContentContainer = viewContentContainer;
|
||||
ViewerObject.ViewerPlugin = matchedPlugin;
|
||||
ContextObject.CurrentContentContainer = viewContentContainer;
|
||||
ContextObject.ViewerPlugin = matchedPlugin;
|
||||
|
||||
// get window size before showing it
|
||||
matchedPlugin.BoundViewSize(path, ViewerObject);
|
||||
matchedPlugin.BoundViewSize(path, ContextObject);
|
||||
|
||||
Show();
|
||||
|
||||
matchedPlugin.View(path, ViewerObject);
|
||||
matchedPlugin.View(path, ContextObject);
|
||||
}
|
||||
|
||||
~MainWindow()
|
||||
|
@@ -9,7 +9,7 @@ namespace QuickLook.Plugin
|
||||
/// <summary>
|
||||
/// A runtime object which allows interaction between this plugin and QuickLook.
|
||||
/// </summary>
|
||||
public class ViewerObject : INotifyPropertyChanged, IDisposable
|
||||
public class ContextObject : INotifyPropertyChanged, IDisposable
|
||||
{
|
||||
private bool _isBusy = true;
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace QuickLook.Plugin
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
~ViewerObject()
|
||||
~ContextObject()
|
||||
{
|
||||
Dispose();
|
||||
}
|
@@ -22,7 +22,7 @@
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the target file.</param>
|
||||
/// <param name="context">A runtime object which allows interaction between this plugin and QuickLook.</param>
|
||||
void BoundViewSize(string path, ViewerObject context);
|
||||
void BoundViewSize(string path, ContextObject context);
|
||||
|
||||
/// <summary>
|
||||
/// Start the loading process. During the process a busy indicator will be shown. Finish by setting context.IsBusy to
|
||||
@@ -30,7 +30,7 @@
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the target file.</param>
|
||||
/// <param name="context">A runtime object which allows interaction between this plugin and QuickLook.</param>
|
||||
void View(string path, ViewerObject context);
|
||||
void View(string path, ContextObject context);
|
||||
|
||||
/// <summary>
|
||||
/// Release any unmanaged resource here.
|
||||
|
@@ -14,7 +14,7 @@ namespace QuickLook.Plugin.InfoPanel
|
||||
return true;
|
||||
}
|
||||
|
||||
public void BoundViewSize(string path, ViewerObject context)
|
||||
public void BoundViewSize(string path, ContextObject context)
|
||||
{
|
||||
_ip = new InfoPanel();
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace QuickLook.Plugin.InfoPanel
|
||||
context.PreferredSize = new Size {Width = _ip.Width, Height = _ip.Height};
|
||||
}
|
||||
|
||||
public void View(string path, ViewerObject context)
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
_ip.DisplayInfo(path);
|
||||
|
||||
|
@@ -13,6 +13,7 @@
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
@@ -25,7 +26,6 @@
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
@@ -92,7 +92,7 @@
|
||||
<Compile Include="ViewContentContainer.xaml.cs">
|
||||
<DependentUpon>ViewContentContainer.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Plugin\ViewerObject.cs" />
|
||||
<Compile Include="Plugin\ContextObject.cs" />
|
||||
<Compile Include="Helpers\WindowHelper.cs" />
|
||||
<Compile Include="ViewWindowManager.cs" />
|
||||
<Page Include="Plugin\InfoPanel\InfoPanel.xaml">
|
||||
|
@@ -52,7 +52,10 @@ namespace QuickLook
|
||||
Debug.WriteLine(e.StackTrace);
|
||||
|
||||
if (matchedPlugin.GetType() != PluginManager.GetInstance().DefaultPlugin)
|
||||
{
|
||||
matchedPlugin.Dispose();
|
||||
_viewWindow.BeginShow(PluginManager.GetInstance().DefaultPlugin.CreateInstance<IViewer>(), path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user