Added EPUB plugin

This commit is contained in:
Marco Gavelli
2018-07-16 09:46:52 +02:00
parent 0e28a4a006
commit a78428c698
61 changed files with 2533 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using QuickLook.Common.Plugin;
using QuickLook.Plugin.HtmlViewer;
using VersOne.Epub;
namespace QuickLook.Plugin.EpubViewer
{
public class Plugin : IViewer
{
private EpubViewerControl _panel;
public int Priority => int.MaxValue;
public void Init()
{
}
public bool CanHandle(string path)
{
return !Directory.Exists(path) && new[] { ".epub" }.Any(path.ToLower().EndsWith);
}
public void Cleanup()
{
}
public void Prepare(string path, ContextObject context)
{
context.PreferredSize = new Size { Width = 1000, Height = 600 };
}
public void View(string path, ContextObject context)
{
_panel = new EpubViewerControl();
context.ViewerContent = _panel;
Exception exception = null;
_panel.Dispatcher.BeginInvoke(new Action(() =>
{
try
{
// Opens a book
EpubBookRef epubBook = EpubReader.OpenBook(path);
context.Title = epubBook.Title;
_panel.SetContent(epubBook);
context.IsBusy = false;
}
catch (Exception e)
{
exception = e;
}
}), DispatcherPriority.Loaded).Wait();
if (exception != null)
ExceptionDispatchInfo.Capture(exception).Throw();
}
}
}