diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs index 466e18d..1a62a07 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs @@ -127,6 +127,9 @@ namespace QuickLook.Plugin.ArchiveViewer private string[] GetPathFragments(string path) { + if (string.IsNullOrEmpty(path)) + return new string[0]; + 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(); diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs index 773bb62..e479e60 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs @@ -16,18 +16,18 @@ namespace QuickLook.Plugin.ArchiveViewer if (Directory.Exists(path)) return false; - using (var stream = File.OpenRead(path)) + switch (Path.GetExtension(path).ToLower()) { - try - { - ArchiveFactory.Open(stream); - } - catch (Exception) - { + case ".zip": + case ".rar": + case ".7z": + case ".gz": + case ".tar": + return true; + + default: return false; - } } - return true; } public void Prepare(string path, ContextObject context) @@ -50,6 +50,7 @@ namespace QuickLook.Plugin.ArchiveViewer GC.SuppressFinalize(this); _panel?.Dispose(); + _panel = null; } ~Plugin() diff --git a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs index d9f892a..ca3f94b 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs @@ -48,6 +48,7 @@ namespace QuickLook.Plugin.HtmlViewer GC.SuppressFinalize(this); _panel?.Dispose(); + _panel = null; } ~Plugin() diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs index 31f1511..e222287 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs @@ -52,6 +52,7 @@ namespace QuickLook.Plugin.ImageViewer public void Cleanup() { + _ip = null; } } } \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs index d9037a4..f3c98b4 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs @@ -49,6 +49,7 @@ namespace QuickLook.Plugin.MarkdownViewer GC.SuppressFinalize(this); _panel?.Dispose(); + _panel = null; } ~Plugin() diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs index 51aae27..72a75bb 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs @@ -58,6 +58,7 @@ namespace QuickLook.Plugin.TextViewer public void Cleanup() { + _tvp = null; } } } \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/PluginInterface.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/PluginInterface.cs index 0c614af..d0f6356 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/PluginInterface.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/PluginInterface.cs @@ -55,6 +55,7 @@ namespace QuickLook.Plugin.VideoViewer public void Cleanup() { _vp?.Dispose(); + _vp = null; } } } \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs index 4077980..1dab8b3 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Diagnostics; using System.Windows.Controls; using System.Windows.Input; using FontAwesome.WPF; @@ -51,11 +52,16 @@ namespace QuickLook.Plugin.VideoViewer : FontAwesomeIcon.PlayCircleOutline; } + [DebuggerNonUserCode] private void ShowErrorNotification(object sender, MediaErrorRoutedEventArgs e) { + _context.ShowNotification("", "An error occurred while loading the video."); mediaElement.Stop(); - _context.ShowNotification("", "An error occurred while loading the video."); + Dispose(); + + + throw new Exception("fallback to default viewer."); } public void LoadAndPlay(string path) diff --git a/QuickLook/MainWindow.xaml.cs b/QuickLook/MainWindow.xaml.cs index 0b4ebfb..5a1bbf5 100644 --- a/QuickLook/MainWindow.xaml.cs +++ b/QuickLook/MainWindow.xaml.cs @@ -95,15 +95,20 @@ namespace QuickLook this.MoveWindow(newLeft, newTop, size.Width, size.Height); } + internal void UnloadPlugin() + { + container.Content = null; + + // clean up plugin and refresh ContextObject for next use + ContextObject.ViewerPlugin?.Cleanup(); + } + private new void Hide() { if (App.RunningAsViewer) Application.Current.Shutdown(); - container.Content = null; - - // clean up plugin and refresh ContextObject for next use - ContextObject.ViewerPlugin?.Cleanup(); + UnloadPlugin(); ContextObject.Reset(); GC.Collect(); @@ -111,8 +116,9 @@ namespace QuickLook // revert UI changes ContextObject.IsBusy = true; - Left -= 10000; - Dispatcher.Delay(100, _ => base.Hide()); + base.Hide(); + //Left -= 10000; + //Dispatcher.Delay(100, _ => base.Hide()); } internal void BeginShow(IViewer matchedPlugin, string path) @@ -121,13 +127,27 @@ namespace QuickLook ContextObject.ViewerPlugin = matchedPlugin; // get window size before showing it - matchedPlugin.Prepare(path, ContextObject); + ContextObject.ViewerPlugin.Prepare(path, ContextObject); Show(); // load plugin, do not block UI - Dispatcher.BeginInvoke(new Action(() => matchedPlugin.View(path, ContextObject)), - DispatcherPriority.Render); + Exception thrown = null; + Dispatcher.BeginInvoke(new Action(() => + { + try + { + ContextObject.ViewerPlugin.View(path, ContextObject); + } + catch (Exception e) + { + thrown = e; + } + }), + DispatcherPriority.Render).Wait(); + + if (thrown != null) + throw thrown; } internal bool BeginHide() diff --git a/QuickLook/Plugin/InfoPanel/PluginInterface.cs b/QuickLook/Plugin/InfoPanel/PluginInterface.cs index 68fb3d1..ef2de5a 100644 --- a/QuickLook/Plugin/InfoPanel/PluginInterface.cs +++ b/QuickLook/Plugin/InfoPanel/PluginInterface.cs @@ -15,24 +15,28 @@ namespace QuickLook.Plugin.InfoPanel public void Prepare(string path, ContextObject context) { - _ip = new InfoPanel(); - - context.CanResize = false; - context.PreferredSize = new Size {Width = _ip.Width, Height = _ip.Height}; + context.PreferredSize = new Size {Width = 453, Height = 172}; } public void View(string path, ContextObject context) { - _ip.DisplayInfo(path); + _ip = new InfoPanel(); context.ViewerContent = _ip; + context.CanResize = false; + + _ip.DisplayInfo(path); context.IsBusy = false; } public void Cleanup() { + if (_ip == null) + return; + _ip.Stop = true; + _ip = null; } } } \ No newline at end of file diff --git a/QuickLook/ViewWindowManager.cs b/QuickLook/ViewWindowManager.cs index 657e8ce..9e205e7 100644 --- a/QuickLook/ViewWindowManager.cs +++ b/QuickLook/ViewWindowManager.cs @@ -53,12 +53,15 @@ namespace QuickLook { try { + _viewWindow.UnloadPlugin(); _viewWindow.BeginShow(matchedPlugin, path); } catch (Exception e) // if current plugin failed, switch to default one. { _viewWindow.BeginHide(); + TrayIconManager.GetInstance().ShowNotification("", $"Failed to preview {Path.GetFileName(path)}", true); + Debug.WriteLine(e.ToString()); Debug.WriteLine(e.StackTrace);