diff --git a/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/Plugin.cs new file mode 100644 index 0000000..172bf2c --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/Plugin.cs @@ -0,0 +1,109 @@ +// Copyright © 2017-2025 QL-Win Contributors +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using MediaInfoLib; +using QuickLook.Common.Helpers; +using QuickLook.Common.Plugin; +using System; +using System.IO; +using System.Linq; +using System.Windows; +using System.Windows.Media; + +namespace QuickLook.Plugin.MediaInfoViewer; + +public class Plugin : IViewer +{ + private TextViewerPanel _tvp; + + public int Priority => 0; + + public void Init() + { + } + + public bool CanHandle(string path) + { + // We only handle files with specific caller + return false; + } + + public void Prepare(string path, ContextObject context) + { + context.PreferredSize = new Size { Width = 800, Height = 600 }; + } + + public void View(string path, ContextObject context) + { + using MediaInfo lib = new MediaInfo() + .WithOpen(path); + + _tvp = new TextViewerPanel(lib.Inform(), context); + AssignHighlightingManager(_tvp, context); + + _tvp.Tag = context; + _tvp.Drop += OnDrop; + + context.ViewerContent = _tvp; + context.Title = $"{Path.GetFileName(path)}"; + context.IsBusy = false; + } + + private void OnDrop(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + if (e.Data.GetData(DataFormats.FileDrop) is string[] files + && files.FirstOrDefault() is string path) + { + if (_tvp!.Tag is ContextObject context) + { + context.Title = $"{Path.GetFileName(path)}"; + } + + using MediaInfo lib = new MediaInfo() + .WithOpen(path); + _tvp!.Text = lib.Inform(); + } + } + } + + public void Cleanup() + { + GC.SuppressFinalize(this); + + _tvp = null!; + } + + private void AssignHighlightingManager(TextViewerPanel tvp, ContextObject context) + { + var isDark = OSThemeHelper.AppsUseDarkTheme(); + + if (isDark) + { + context.Theme = Themes.Dark; + tvp.Foreground = new BrushConverter().ConvertFromString("#FFEFEFEF") as SolidColorBrush; + tvp.Background = Brushes.Transparent; + } + else + { + context.Theme = Themes.Light; + tvp.Foreground = new BrushConverter().ConvertFromString("#BBFAFAFA") as SolidColorBrush; + tvp.Background = Brushes.Transparent; + } + } +} diff --git a/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/Properties/AssemblyInfo.cs b/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0316049 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/Properties/AssemblyInfo.cs @@ -0,0 +1,50 @@ +// Copyright © 2017-2025 QL-Win Contributors +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("QuickLook.Plugin.MediaInfoViewer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("pooi.moe")] +[assembly: AssemblyProduct("QuickLook.Plugin.MediaInfoViewer")] +[assembly: AssemblyCopyright("Copyright © 2017-2025 QL-Win Contributors")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b0054a16-472e-44ac-ba40-349303e524ff")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] diff --git a/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/QuickLook.Plugin.MediaInfoViewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/QuickLook.Plugin.MediaInfoViewer.csproj new file mode 100644 index 0000000..235471e --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/QuickLook.Plugin.MediaInfoViewer.csproj @@ -0,0 +1,83 @@ + + + + Library + net462 + QuickLook.Plugin.MediaInfoViewer + QuickLook.Plugin.MediaInfoViewer + 512 + false + true + latest + false + false + false + MinimumRecommendedRules.ruleset + {B0054A16-472E-44AC-BA40-349303E524FF} + + + + true + full + false + ..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.MediaInfoViewer\ + DEBUG;TRACE + prompt + + + + pdbonly + true + ..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.MediaInfoViewer\ + TRACE + prompt + + + + true + full + ..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.MediaInfoViewer\ + DEBUG;TRACE + x86 + prompt + + + + ..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.MediaInfoViewer\ + TRACE + true + pdbonly + x86 + prompt + + + + + {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95} + QuickLook.Common + False + + + + + + Properties\GitVersion.cs + + + + + + + + + + + + + + + PreserveNewest + + + + diff --git a/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/TextViewerPanel.cs b/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/TextViewerPanel.cs new file mode 100644 index 0000000..e558ddf --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.MediaInfoViewer/TextViewerPanel.cs @@ -0,0 +1,98 @@ +// Copyright © 2017-2025 QL-Win Contributors +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using QuickLook.Common.Helpers; +using QuickLook.Common.Plugin; +using System; +using System.Reflection; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; + +namespace QuickLook.Plugin.MediaInfoViewer; + +public class TextViewerPanel : TextBox +{ + public TextViewerPanel(string text, ContextObject context) + { + _ = context; + + Margin = new Thickness(8, 0, 0, 0); + FontSize = 14; + IsReadOnly = true; + IsManipulationEnabled = true; + + ContextMenu = new ContextMenu(); + ContextMenu.Items.Add(new MenuItem + { + Header = TranslationHelper.Get("Editor_Copy", domain: Assembly.GetExecutingAssembly().GetName().Name), + Command = ApplicationCommands.Copy + }); + ContextMenu.Items.Add(new MenuItem + { + Header = TranslationHelper.Get("Editor_SelectAll", + domain: Assembly.GetExecutingAssembly().GetName().Name), + Command = ApplicationCommands.SelectAll + }); + + ManipulationInertiaStarting += Viewer_ManipulationInertiaStarting; + ManipulationStarting += Viewer_ManipulationStarting; + ManipulationDelta += Viewer_ManipulationDelta; + + PreviewMouseWheel += Viewer_MouseWheel; + + FontFamily = new FontFamily("Consolas, " + TranslationHelper.Get("Editor_FontFamily", + domain: Assembly.GetExecutingAssembly().GetName().Name)); + + LoadTextAsync(text); + } + + private void Viewer_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e) + { + e.TranslationBehavior = new InertiaTranslationBehavior + { + InitialVelocity = e.InitialVelocities.LinearVelocity, + DesiredDeceleration = 10.0 * 96.0 / (1000.0 * 1000.0) + }; + } + + private void Viewer_MouseWheel(object sender, MouseWheelEventArgs e) + { + e.Handled = true; + + ScrollToVerticalOffset(VerticalOffset - e.Delta); + } + + private void Viewer_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) + { + e.Handled = true; + + var delta = e.DeltaManipulation; + ScrollToVerticalOffset(VerticalOffset - delta.Translation.Y); + } + + private void Viewer_ManipulationStarting(object sender, ManipulationStartingEventArgs e) + { + e.Mode = ManipulationModes.Translate; + } + + private void LoadTextAsync(string text) + { + Text = text; + } +} diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/QuickLook.Plugin.VideoViewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/QuickLook.Plugin.VideoViewer.csproj index 8b2151d..c41752c 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/QuickLook.Plugin.VideoViewer.csproj +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/QuickLook.Plugin.VideoViewer.csproj @@ -41,7 +41,7 @@ MediaInfoWrapper - + MediaInfoDLL @@ -187,17 +187,17 @@ $(OutDir)\LAVFilters-x86\ LAVFilters-x86\swscale-lav-8.dll - + PreserveNewest $(OutDir)MediaInfo-x64\ MediaInfo-x64\MediaInfo.dll - + PreserveNewest $(OutDir)MediaInfo-x86\ MediaInfo-x86\MediaInfo.dll -