diff --git a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/Plugin.cs index 918093a..d6b96d1 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/Plugin.cs @@ -134,11 +134,22 @@ public class Plugin : IViewer } } - _panel = new PreviewPanel(); - context.ViewerContent = _panel; - context.Title = Path.GetFileName(path); - - _panel.PreviewFile(path, context); + try + { + _panel = new PreviewPanel(); + context.ViewerContent = _panel; + context.Title = Path.GetFileName(path); + _panel.PreviewFile(path, context); + } + catch (Exception e) + { + context.ViewerContent = new Label() + { + Content = e.ToString(), + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Center, + }; + } context.IsBusy = false; } diff --git a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PreviewHandlerHost.cs b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PreviewHandlerHost.cs index a1d304d..57fd238 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PreviewHandlerHost.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PreviewHandlerHost.cs @@ -102,9 +102,7 @@ public class PreviewHandlerHost : Control CurrentPreviewHandler = guid; var o = Activator.CreateInstance(Type.GetTypeFromCLSID(CurrentPreviewHandler, true)); - var fileInit = o as IInitializeWithFile; - - if (fileInit == null) + if (o is not IInitializeWithFile fileInit) return false; fileInit.Initialize(path, 0); diff --git a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PreviewPanel.cs b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PreviewPanel.cs index d5fd6f9..6b0dc95 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PreviewPanel.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PreviewPanel.cs @@ -44,9 +44,6 @@ public class PreviewPanel : WindowsFormsHost, IDisposable _control = new PreviewHandlerHost(); Child = _control; _control.Open(file); - - //SetForegroundWindow(new WindowInteropHelper(context.ViewerWindow).Handle); - //SetActiveWindow(presenter.Handle); } [DllImport("user32.dll")]