diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..790c61e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "QuickLook.Common"] + path = QuickLook.Common + url = git@github.com:QL-Win/QuickLook.Common.git diff --git a/QuickLook.Common b/QuickLook.Common new file mode 160000 index 0000000..44448c9 --- /dev/null +++ b/QuickLook.Common @@ -0,0 +1 @@ +Subproject commit 44448c9f28dc826db4c15e3e1b0b352b743b0885 diff --git a/QuickLook.Common/ExtensionMethods/BitmapExtensions.cs b/QuickLook.Common/ExtensionMethods/BitmapExtensions.cs deleted file mode 100644 index 71090bb..0000000 --- a/QuickLook.Common/ExtensionMethods/BitmapExtensions.cs +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Threading.Tasks; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using PixelFormat = System.Windows.Media.PixelFormat; - -namespace QuickLook.Common.ExtensionMethods -{ - public static class BitmapExtensions - { - public static BitmapSource ToBitmapSource(this Bitmap source) - { - var orgSource = source; - BitmapSource bs = null; - try - { - var data = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), - ImageLockMode.ReadOnly, source.PixelFormat); - - // BitmapSource.Create throws an exception when the image is scanned backward. - // The Clone() will make it back scanning forward. - if (data.Stride < 0) - { - source.UnlockBits(data); - source = (Bitmap) source.Clone(); - data = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), - ImageLockMode.ReadOnly, source.PixelFormat); - } - - bs = BitmapSource.Create(source.Width, source.Height, Math.Floor(source.HorizontalResolution), - Math.Floor(source.VerticalResolution), ConvertPixelFormat(source.PixelFormat), null, - data.Scan0, data.Stride * source.Height, data.Stride); - - source.UnlockBits(data); - - bs.Freeze(); - } - catch - { - // ignored - } - finally - { - if (orgSource != source) - source.Dispose(); - } - - return bs; - } - - public static Bitmap ToBitmap(this BitmapSource source) - { - using (var outStream = new MemoryStream()) - { - BitmapEncoder enc = new BmpBitmapEncoder(); - enc.Frames.Add(BitmapFrame.Create(source)); - enc.Save(outStream); - var bitmap = new Bitmap(outStream); - - return new Bitmap(bitmap); - } - } - - private static PixelFormat ConvertPixelFormat( - System.Drawing.Imaging.PixelFormat sourceFormat) - { - switch (sourceFormat) - { - case System.Drawing.Imaging.PixelFormat.Format24bppRgb: - return PixelFormats.Bgr24; - - case System.Drawing.Imaging.PixelFormat.Format32bppArgb: - return PixelFormats.Bgra32; - - case System.Drawing.Imaging.PixelFormat.Format32bppRgb: - return PixelFormats.Bgr32; - } - - return new PixelFormat(); - } - - public static bool IsDarkImage(this Bitmap image) - { - // convert to 24-bit RGB image - image = image.Clone(new Rectangle(0, 0, image.Width, image.Height), - System.Drawing.Imaging.PixelFormat.Format24bppRgb); - - var sampleCount = (int) (0.2 * 400 * 400); - const int pixelSize = 24 / 8; - var data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), - ImageLockMode.ReadWrite, image.PixelFormat); - - var darks = 0; - unsafe - { - var pFirst = (byte*) data.Scan0; - - Parallel.For(0, sampleCount, n => - { - var rand = new Random(n); - var row = rand.Next(0, data.Height); - var col = rand.Next(0, data.Width); - var pos = pFirst + row * data.Stride + col * pixelSize; - - var b = pos[0]; - var g = pos[1]; - var r = pos[2]; - - var y = (0.299 * r + 0.587 * g + 0.114 * b) / 255; - - if (y < 0.5) - darks++; - }); - } - - image.UnlockBits(data); - image.Dispose(); - - return darks > 0.65 * sampleCount; - } - - public static BitmapImage LoadBitmapImage(this Uri source) - { - var bitmap = new BitmapImage(); - bitmap.BeginInit(); - bitmap.CacheOption = BitmapCacheOption.OnLoad; - bitmap.UriSource = source; - bitmap.EndInit(); - return bitmap; - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/ExtensionMethods/DispatcherExtensions.cs b/QuickLook.Common/ExtensionMethods/DispatcherExtensions.cs deleted file mode 100644 index 8d19f0f..0000000 --- a/QuickLook.Common/ExtensionMethods/DispatcherExtensions.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Threading.Tasks; -using System.Windows.Threading; - -namespace QuickLook.Common.ExtensionMethods -{ - public static class DispatcherExtensions - { - public static void Delay(this Dispatcher disp, int delayMs, - Action action, object parm = null) - { - Task.Delay(delayMs).ContinueWith(t => { disp.Invoke(action, parm); }); - } - - public static void DelayWithPriority(this Dispatcher disp, int delayMs, - Action action, object parm = null, - DispatcherPriority priority = DispatcherPriority.ApplicationIdle) - { - Task.Delay(delayMs).ContinueWith(t => { disp.BeginInvoke(action, priority, parm); }); - } - - public static async Task DelayAsync(this Dispatcher disp, int delayMs, - Action action, object parm = null, - DispatcherPriority priority = DispatcherPriority.ApplicationIdle) - { - await Task.Delay(delayMs); - await disp.BeginInvoke(action, priority, parm); - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/ExtensionMethods/EnumerableExtensions.cs b/QuickLook.Common/ExtensionMethods/EnumerableExtensions.cs deleted file mode 100644 index 404d843..0000000 --- a/QuickLook.Common/ExtensionMethods/EnumerableExtensions.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Collections.Generic; - -namespace QuickLook.Common.ExtensionMethods -{ - public static class EnumerableExtensions - { - public static void ForEach(this IEnumerable enumeration, Action action) - { - foreach (var item in enumeration) - action(item); - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/ExtensionMethods/FileExtensions.cs b/QuickLook.Common/ExtensionMethods/FileExtensions.cs deleted file mode 100644 index c856194..0000000 --- a/QuickLook.Common/ExtensionMethods/FileExtensions.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; - -namespace QuickLook.Common.ExtensionMethods -{ - public static class FileExtensions - { - public static string ToPrettySize(this long value, int decimalPlaces = 0) - { - const long OneKb = 1024; - const long OneMb = OneKb * 1024; - const long OneGb = OneMb * 1024; - const long OneTb = OneGb * 1024; - - var asTb = Math.Round((double) value / OneTb, decimalPlaces); - var asGb = Math.Round((double) value / OneGb, decimalPlaces); - var asMb = Math.Round((double) value / OneMb, decimalPlaces); - var asKb = Math.Round((double) value / OneKb, decimalPlaces); - var chosenValue = asTb > 1 - ? $"{asTb} TB" - : asGb > 1 - ? $"{asGb} GB" - : asMb > 1 - ? $"{asMb} MB" - : asKb > 1 - ? $"{asKb} KB" - : $"{Math.Round((double) value, decimalPlaces)} bytes"; - - return chosenValue; - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/ExtensionMethods/TypeExtensions.cs b/QuickLook.Common/ExtensionMethods/TypeExtensions.cs deleted file mode 100644 index 21d9c39..0000000 --- a/QuickLook.Common/ExtensionMethods/TypeExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; - -namespace QuickLook.Common.ExtensionMethods -{ - public static class TypeExtensions - { - public static T CreateInstance(this Type t, params object[] paramArray) - { - return (T)Activator.CreateInstance(t, paramArray); - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/Helpers/DpiHelper.cs b/QuickLook.Common/Helpers/DpiHelper.cs deleted file mode 100644 index 9bc4c73..0000000 --- a/QuickLook.Common/Helpers/DpiHelper.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace QuickLook.Common.Helpers -{ - public static class DpiHelper - { - public const float DefaultDpi = 96; - - public static ScaleFactor GetCurrentScaleFactor() - { - var g = Graphics.FromHwnd(IntPtr.Zero); - var desktop = g.GetHdc(); - - var horizontalDpi = GetDeviceCaps(desktop, (int) DeviceCap.LOGPIXELSX); - var verticalDpi = GetDeviceCaps(desktop, (int) DeviceCap.LOGPIXELSY); - - return new ScaleFactor {Horizontal = horizontalDpi / DefaultDpi, Vertical = verticalDpi / DefaultDpi}; - } - - [DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] - private static extern int GetDeviceCaps(IntPtr hDC, int nIndex); - - private enum DeviceCap - { - /// - /// Logical pixels inch in X - /// - LOGPIXELSX = 88, - /// - /// Logical pixels inch in Y - /// - LOGPIXELSY = 90 - } - - public struct ScaleFactor - { - public float Horizontal; - public float Vertical; - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/Helpers/FileHelper.cs b/QuickLook.Common/Helpers/FileHelper.cs deleted file mode 100644 index b067398..0000000 --- a/QuickLook.Common/Helpers/FileHelper.cs +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace QuickLook.Common.Helpers -{ - public class FileHelper - { - public static bool IsExecutable(string path, out string appFriendlyName) - { - appFriendlyName = string.Empty; - var ext = Path.GetExtension(path).ToLower(); - var isExe = new[] {".cmd", ".bat", ".pif", ".scf", ".exe", ".com", ".scr"}.Contains(ext.ToLower()); - - if (!isExe) - return false; - - appFriendlyName = FileVersionInfo.GetVersionInfo(path).FileDescription; - if (string.IsNullOrEmpty(appFriendlyName)) - appFriendlyName = Path.GetFileName(path); - - return true; - } - - public static bool GetAssocApplication(string path, out string appFriendlyName) - { - appFriendlyName = string.Empty; - var ext = Path.GetExtension(path).ToLower(); - - // no assoc. app. found - if (string.IsNullOrEmpty(GetAssocApplicationNative(ext, AssocStr.Command))) - if (string.IsNullOrEmpty(GetAssocApplicationNative(ext, AssocStr.AppId))) // UWP - return false; - - appFriendlyName = GetAssocApplicationNative(ext, AssocStr.FriendlyAppName); - if (string.IsNullOrEmpty(appFriendlyName)) - appFriendlyName = Path.GetFileName(path); - - return true; - } - - [DllImport("shlwapi.dll", CharSet = CharSet.Auto, SetLastError = true)] - private static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, - [Out] StringBuilder sOut, [In] [Out] ref uint nOut); - - private static string GetAssocApplicationNative(string fileExtensionIncludingDot, AssocStr str) - { - uint cOut = 0; - if (AssocQueryString(AssocF.Verify | AssocF.RemapRunDll | AssocF.InitIgnoreUnknown, str, - fileExtensionIncludingDot, null, null, - ref cOut) != 1) - return null; - - var pOut = new StringBuilder((int) cOut); - if (AssocQueryString(AssocF.Verify | AssocF.RemapRunDll | AssocF.InitIgnoreUnknown, str, - fileExtensionIncludingDot, null, pOut, - ref cOut) != 0) - return null; - - return pOut.ToString(); - } - - [SuppressMessage("ReSharper", "InconsistentNaming")] - [Flags] - private enum AssocF - { - InitNoRemapCLSID = 0x1, - InitByExeName = 0x2, - OpenByExeName = 0x2, - InitDefaultToStar = 0x4, - InitDefaultToFolder = 0x8, - NoUserSettings = 0x10, - NoTruncate = 0x20, - Verify = 0x40, - RemapRunDll = 0x80, - NoFixUps = 0x100, - IgnoreBaseClass = 0x200, - InitIgnoreUnknown = 0x400, - InitFixedProgid = 0x800, - IsProtocol = 0x1000, - InitForFile = 0x2000 - } - - //[SuppressMessage("ReSharper", "InconsistentNaming")] - private enum AssocStr - { - Command = 1, - Executable, - FriendlyDocName, - FriendlyAppName, - NoOpen, - ShellNewValue, - DdeCommand, - DdeIfExec, - DdeApplication, - DdeTopic, - InfoTip, - QuickTip, - TileInfo, - ContentType, - DefaultIcon, - ShellExtension, - DropTarget, - DelegateExecute, - SupportedUriProtocols, - ProgId, - AppId, - AppPublisher, - AppIconReference, - Max - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/Helpers/ProcessHelper.cs b/QuickLook.Common/Helpers/ProcessHelper.cs deleted file mode 100644 index 2afebbb..0000000 --- a/QuickLook.Common/Helpers/ProcessHelper.cs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Threading.Tasks; -using QuickLook.Common.NativeMethods; - -namespace QuickLook.Common.Helpers -{ - public class ProcessHelper - { - private const int ErrorInsufficientBuffer = 0x7A; - - // ReSharper disable once InconsistentNaming - public static void PerformAggressiveGC() - { - // delay some time to make sure that all windows are closed - Task.Delay(2000).ContinueWith(t => GC.Collect(GC.MaxGeneration)); - } - - public static bool IsRunningAsUWP() - { - try - { - uint len = 0; - var r = Kernel32.GetCurrentPackageFullName(ref len, null); - - return r == ErrorInsufficientBuffer; - } - catch (EntryPointNotFoundException) - { - return false; - } - } - - [SuppressMessage("ReSharper", "InconsistentNaming")] - public static bool IsOnWindows10S() - { - const uint PRODUCT_CLOUD = 0x000000B2; // Windows 10 S - const uint PRODUCT_CLOUDN = 0x000000B3; // Windows 10 S N - - Kernel32.GetProductInfo(Environment.OSVersion.Version.Major, - Environment.OSVersion.Version.Minor, 0, 0, out var osType); - - return osType == PRODUCT_CLOUD || osType == PRODUCT_CLOUDN; - } - - public static void WriteLog(string msg) - { - var logFilePath = Path.Combine(SettingHelper.LocalDataPath, @"QuickLook.Exception.log"); - - using (var writer = new StreamWriter(new FileStream(logFilePath, FileMode.OpenOrCreate, - FileAccess.ReadWrite, FileShare.Read))) - { - writer.BaseStream.Seek(0, SeekOrigin.End); - - writer.WriteLine($"========{DateTime.Now}========"); - writer.WriteLine(msg); - writer.WriteLine(); - } - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/Helpers/SettingHelper.cs b/QuickLook.Common/Helpers/SettingHelper.cs deleted file mode 100644 index 75358ac..0000000 --- a/QuickLook.Common/Helpers/SettingHelper.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright © 2018 Paddy Xu -// -// 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; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.Serialization; -using System.Xml; - -namespace QuickLook.Common.Helpers -{ - public class SettingHelper - { - public static readonly string LocalDataPath = - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"pooi.moe\QuickLook\"); - - private static readonly Dictionary FileCache = new Dictionary(); - - [MethodImpl(MethodImplOptions.NoInlining)] - public static T Get(string id, T failsafe = default(T), Assembly calling = null) - { - if (!typeof(T).IsSerializable && !typeof(ISerializable).IsAssignableFrom(typeof(T))) - throw new InvalidOperationException("A serializable Type is required"); - - var file = Path.Combine(LocalDataPath, - (calling ?? Assembly.GetCallingAssembly()).GetName().Name + ".config"); - - var doc = GetConfigFile(file); - - // try to get setting - var s = GetSettingFromXml(doc, id, failsafe); - - return s != null ? s : failsafe; - } - - [MethodImpl(MethodImplOptions.NoInlining)] - public static void Set(string id, object value, Assembly calling = null) - { - if (!value.GetType().IsSerializable) - throw new NotSupportedException("New value if not serializable."); - - var file = Path.Combine(LocalDataPath, - (calling ?? Assembly.GetCallingAssembly()).GetName().Name + ".config"); - - WriteSettingToXml(GetConfigFile(file), id, value); - } - - private static T GetSettingFromXml(XmlDocument doc, string id, T failsafe) - { - var v = doc.SelectSingleNode($@"/Settings/{id}"); - - try - { - var result = v == null ? failsafe : (T) Convert.ChangeType(v.InnerText, typeof(T)); - return result; - } - catch (Exception) - { - return failsafe; - } - } - - private static void WriteSettingToXml(XmlDocument doc, string id, object value) - { - var v = doc.SelectSingleNode($@"/Settings/{id}"); - - if (v != null) - { - v.InnerText = value.ToString(); - } - else - { - var node = doc.CreateNode(XmlNodeType.Element, id, doc.NamespaceURI); - node.InnerText = value.ToString(); - doc.SelectSingleNode(@"/Settings")?.AppendChild(node); - } - - doc.Save(new Uri(doc.BaseURI).LocalPath); - } - - private static XmlDocument GetConfigFile(string file) - { - if (FileCache.ContainsKey(file)) - return FileCache[file]; - - Directory.CreateDirectory(Path.GetDirectoryName(file)); - if (!File.Exists(file)) - CreateNewConfig(file); - - var doc = new XmlDocument(); - try - { - doc.Load(file); - } - catch (XmlException) - { - CreateNewConfig(file); - doc.Load(file); - } - - if (doc.SelectSingleNode(@"/Settings") == null) - { - CreateNewConfig(file); - doc.Load(file); - } - - FileCache.Add(file, doc); - return doc; - } - - private static void CreateNewConfig(string file) - { - using (var writer = XmlWriter.Create(file)) - { - writer.WriteStartDocument(); - writer.WriteStartElement("Settings"); - writer.WriteEndElement(); - writer.WriteEndDocument(); - - writer.Flush(); - } - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/Helpers/TranslationHelper.cs b/QuickLook.Common/Helpers/TranslationHelper.cs deleted file mode 100644 index 19f9b8f..0000000 --- a/QuickLook.Common/Helpers/TranslationHelper.cs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Xml.XPath; - -namespace QuickLook.Common.Helpers -{ - public class TranslationHelper - { - private static readonly CultureInfo CurrentCultureInfo = CultureInfo.CurrentUICulture; - //private static readonly CultureInfo CurrentCultureInfo = CultureInfo.GetCultureInfo("zh-CN"); - - private static readonly Dictionary FileCache = new Dictionary(); - - [MethodImpl(MethodImplOptions.NoInlining)] - public static string Get(string id, string file = null, CultureInfo locale = null, string failsafe = null, - Assembly calling = null) - { - if (file == null) - file = Path.Combine(Path.GetDirectoryName((calling ?? Assembly.GetCallingAssembly()).Location), - "Translations.config"); - - if (!File.Exists(file)) - return failsafe ?? id; - - if (locale == null) - locale = CurrentCultureInfo; - - var nav = GetLangFile(file); - - // try to get string - var s = GetStringFromXml(nav, id, locale); - if (s != null) - return s; - - // try again for parent language - if (locale.Parent.Name != string.Empty) - s = GetStringFromXml(nav, id, locale.Parent); - if (s != null) - return s; - - // use fallback language - s = GetStringFromXml(nav, id, CultureInfo.GetCultureInfo("en")); - if (s != null) - return s; - - return failsafe ?? id; - } - - private static string GetStringFromXml(XPathNavigator nav, string id, CultureInfo locale) - { - var result = nav.SelectSingleNode($@"/Translations/{locale.Name}/{id}"); - - return result?.Value; - } - - private static XPathNavigator GetLangFile(string file) - { - if (FileCache.ContainsKey(file)) - return FileCache[file]; - - var res = new XPathDocument(file).CreateNavigator(); - FileCache.Add(file, res); - return res; - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/Helpers/WindowHelper.cs b/QuickLook.Common/Helpers/WindowHelper.cs deleted file mode 100644 index c5eac6b..0000000 --- a/QuickLook.Common/Helpers/WindowHelper.cs +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Windows; -using System.Windows.Forms; -using System.Windows.Interop; -using System.Windows.Media; -using QuickLook.Common.NativeMethods; - -namespace QuickLook.Common.Helpers -{ - public static class WindowHelper - { - public enum WindowCompositionAttribute - { - WcaAccentPolicy = 19 - } - - public static Rect GetCurrentWindowRect() - { - var screen = Screen.FromPoint(Cursor.Position).WorkingArea; - var scale = DpiHelper.GetCurrentScaleFactor(); - return new Rect( - new Point(screen.X / scale.Horizontal, screen.Y / scale.Vertical), - new Size(screen.Width / scale.Horizontal, screen.Height / scale.Vertical)); - } - - public static void BringToFront(this Window window, bool keep) - { - var handle = new WindowInteropHelper(window).Handle; - User32.SetWindowPos(handle, User32.HWND_TOPMOST, 0, 0, 0, 0, - User32.SWP_NOMOVE | User32.SWP_NOSIZE | User32.SWP_NOACTIVATE); - - if (!keep) - User32.SetWindowPos(handle, User32.HWND_NOTOPMOST, 0, 0, 0, 0, - User32.SWP_NOMOVE | User32.SWP_NOSIZE | User32.SWP_NOACTIVATE); - } - - public static void MoveWindow(this Window window, - double left, - double top, - double width, - double height) - { - int pxLeft = 0, pxTop = 0; - if (left != 0 || top != 0) - TransformToPixels(window, left, top, - out pxLeft, out pxTop); - - TransformToPixels(window, width, height, - out var pxWidth, out var pxHeight); - - User32.MoveWindow(new WindowInteropHelper(window).Handle, pxLeft, pxTop, pxWidth, pxHeight, true); - } - - private static void TransformToPixels(this Visual visual, - double unitX, - double unitY, - out int pixelX, - out int pixelY) - { - Matrix matrix; - var source = PresentationSource.FromVisual(visual); - if (source != null) - matrix = source.CompositionTarget.TransformToDevice; - else - using (var src = new HwndSource(new HwndSourceParameters())) - { - matrix = src.CompositionTarget.TransformToDevice; - } - - pixelX = (int) Math.Round(matrix.M11 * unitX); - pixelY = (int) Math.Round(matrix.M22 * unitY); - } - - public static bool IsForegroundWindowBelongToSelf() - { - var hwnd = User32.GetForegroundWindow(); - if (hwnd == IntPtr.Zero) - return false; - - User32.GetWindowThreadProcessId(hwnd, out var procId); - return procId == Process.GetCurrentProcess().Id; - } - - public static void SetNoactivate(WindowInteropHelper window) - { - User32.SetWindowLong(window.Handle, User32.GWL_EXSTYLE, - User32.GetWindowLong(window.Handle, User32.GWL_EXSTYLE) | - User32.WS_EX_NOACTIVATE); - } - - public static void EnableBlur(Window window) - { - var accent = new AccentPolicy(); - var accentStructSize = Marshal.SizeOf(accent); - accent.AccentState = AccentState.AccentEnableBlurbehind; - accent.AccentFlags = 2; - accent.GradientColor = 0x99FFFFFF; - - var accentPtr = Marshal.AllocHGlobal(accentStructSize); - Marshal.StructureToPtr(accent, accentPtr, false); - - var data = new WindowCompositionAttributeData - { - Attribute = WindowCompositionAttribute.WcaAccentPolicy, - SizeOfData = accentStructSize, - Data = accentPtr - }; - - User32.SetWindowCompositionAttribute(new WindowInteropHelper(window).Handle, ref data); - - Marshal.FreeHGlobal(accentPtr); - } - - [StructLayout(LayoutKind.Sequential)] - public struct WindowCompositionAttributeData - { - public WindowCompositionAttribute Attribute; - public IntPtr Data; - public int SizeOfData; - } - - private enum AccentState - { - AccentDisabled = 0, - AccentEnableGradient = 1, - AccentEnableTransparentgradient = 2, - AccentEnableBlurbehind = 3, - AccentInvalidState = 4 - } - - [StructLayout(LayoutKind.Sequential)] - private struct AccentPolicy - { - public AccentState AccentState; - public int AccentFlags; - public uint GradientColor; - public readonly int AnimationId; - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/NativeMethods/Kernel32.cs b/QuickLook.Common/NativeMethods/Kernel32.cs deleted file mode 100644 index 7fb7555..0000000 --- a/QuickLook.Common/NativeMethods/Kernel32.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Runtime.InteropServices; -using System.Text; - -namespace QuickLook.Common.NativeMethods -{ - public static class Kernel32 - { - [DllImport("kernel32.dll")] - public static extern IntPtr LoadLibrary(string lpFileName); - - [DllImport("kernel32.dll")] - public static extern int GetCurrentPackageFullName(ref uint packageFullNameLength, - [MarshalAs(UnmanagedType.LPWStr)] StringBuilder packageFullName); - - [DllImport("kernel32.dll")] - public static extern IntPtr GetCurrentThreadId(); - - [DllImport("kernel32.dll")] - public static extern bool GetProductInfo(int dwOSMajorVersion, int dwOSMinorVersion, int dwSpMajorVersion, - int dwSpMinorVersion, out uint pdwReturnedProductType); - } -} \ No newline at end of file diff --git a/QuickLook.Common/NativeMethods/User32.cs b/QuickLook.Common/NativeMethods/User32.cs deleted file mode 100644 index c414d36..0000000 --- a/QuickLook.Common/NativeMethods/User32.cs +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; -using System.Text; -using QuickLook.Common.Helpers; - -namespace QuickLook.Common.NativeMethods -{ - public static class User32 - { - public delegate int KeyboardHookProc(int code, int wParam, ref KeyboardHookStruct lParam); - - [DllImport("user32.dll")] - public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, - [MarshalAs(UnmanagedType.Bool)] bool bRepaint); - - [DllImport("user32.dll")] - public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, - uint uFlags); - - [DllImport("user32.dll")] - public static extern IntPtr SetWindowsHookEx(int idHook, KeyboardHookProc callback, IntPtr hInstance, - uint threadId); - - [DllImport("user32.dll")] - public static extern bool UnhookWindowsHookEx(IntPtr hInstance); - - [DllImport("user32.dll")] - public static extern int CallNextHookEx(IntPtr idHook, int nCode, int wParam, ref KeyboardHookStruct lParam); - - [DllImport("user32.dll")] - public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); - - [DllImport("user32.dll")] - public static extern int GetWindowLong(IntPtr hWnd, int nIndex); - - [DllImport("user32.dll")] - public static extern IntPtr GetForegroundWindow(); - - [DllImport("user32.dll")] - public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr processId); - - [DllImport("user32.dll")] - public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint processId); - - [DllImport("user32.dll")] - public static extern IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, bool fAttach); - - [DllImport("user32.dll")] - public static extern IntPtr GetFocus(); - - [DllImport("user32.dll", CharSet = CharSet.Auto)] - public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); - - [DllImport("user32.dll")] - public static extern IntPtr GetParent(IntPtr hWnd); - - [DllImport("user32.dll")] - public static extern int SetWindowCompositionAttribute(IntPtr hwnd, - ref WindowHelper.WindowCompositionAttributeData data); - - [SuppressMessage("ReSharper", "InconsistentNaming")] - public struct KeyboardHookStruct - { - public int vkCode; - public int scanCode; - public int flags; - public int time; - public int dwExtraInfo; - } - - // ReSharper disable InconsistentNaming - public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); - public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); - public static readonly IntPtr HWND_TOP = new IntPtr(0); - public static readonly IntPtr HWND_BOTTOM = new IntPtr(1); - - public const uint SWP_NOSIZE = 0x0001; - public const uint SWP_NOMOVE = 0x0002; - public const uint SWP_NOZORDER = 0x0004; - public const uint SWP_NOREDRAW = 0x0008; - public const uint SWP_NOACTIVATE = 0x0010; - public const uint SWP_DRAWFRAME = 0x0020; - public const uint SWP_FRAMECHANGED = 0x0020; - public const uint SWP_SHOWWINDOW = 0x0040; - public const uint SWP_HIDEWINDOW = 0x0080; - public const uint SWP_NOCOPYBITS = 0x0100; - public const uint SWP_NOOWNERZORDER = 0x0200; - public const uint SWP_NOREPOSITION = 0x0200; - public const uint SWP_NOSENDCHANGING = 0x0400; - public const uint SWP_DEFERERASE = 0x2000; - public const uint SWP_ASYNCWINDOWPOS = 0x4000; - - public const int WH_KEYBOARD_LL = 13; - public const int WM_KEYDOWN = 0x100; - public const int WM_KEYUP = 0x101; - public const int WM_SYSKEYDOWN = 0x104; - public const int WM_SYSKEYUP = 0x105; - public const int GWL_EXSTYLE = -20; - public const int WS_EX_NOACTIVATE = 0x08000000; - // ReSharper restore InconsistentNaming - } -} \ No newline at end of file diff --git a/QuickLook.Common/Plugin/ContextObject.cs b/QuickLook.Common/Plugin/ContextObject.cs deleted file mode 100644 index 3fd0a30..0000000 --- a/QuickLook.Common/Plugin/ContextObject.cs +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows; -using QuickLook.Common.Annotations; -using QuickLook.Common.Helpers; - -namespace QuickLook.Common.Plugin -{ - /// - /// A runtime object which allows interaction between this plugin and QuickLook. - /// - public class ContextObject : INotifyPropertyChanged - { - private bool _canResize = true; - private bool _fullWindowDragging; - private bool _isBusy; - private string _title = string.Empty; - private bool _titlebarAutoHide; - private bool _titlebarBlurVisibility; - private bool _titlebarColourVisibility = true; - private bool _titlebarOverlap; - private Themes _theme = Themes.None; - private object _viewerContent; - - /// - /// Get or set the title of Viewer window. - /// - public string Title - { - get => _title; - set - { - _title = value; - OnPropertyChanged(); - } - } - - /// - /// Get or set the viewer content control. - /// - public object ViewerContent - { - get => _viewerContent; - set - { - _viewerContent = value; - OnPropertyChanged(); - } - } - - /// - /// Show or hide the busy indicator icon. - /// - public bool IsBusy - { - get => _isBusy; - set - { - _isBusy = value; - OnPropertyChanged(); - } - } - - /// - /// Set the exact size you want. - /// - public Size PreferredSize { get; set; } = new Size {Width = 800, Height = 600}; - - /// - /// Set whether user are allowed to resize the viewer window. - /// - public bool CanResize - { - get => _canResize; - set - { - _canResize = value; - OnPropertyChanged(); - } - } - - /// - /// Set whether the full viewer window can be used for mouse dragging. - /// - public bool FullWindowDragging - { - get => _fullWindowDragging; - set - { - _fullWindowDragging = value; - OnPropertyChanged(); - } - } - - /// - /// Set whether the viewer content is overlapped by the title bar - /// - public bool TitlebarOverlap - { - get => _titlebarOverlap; - set - { - _titlebarOverlap = value; - OnPropertyChanged(); - } - } - - /// - /// Set whether the title bar shows a blurred background - /// - public bool TitlebarBlurVisibility - { - get => _titlebarBlurVisibility; - set - { - if (value == _titlebarBlurVisibility) return; - _titlebarBlurVisibility = value; - OnPropertyChanged(); - } - } - - /// - /// Set whether the title bar shows a colour overlay - /// - public bool TitlebarColourVisibility - { - get => _titlebarColourVisibility; - set - { - if (value == _titlebarColourVisibility) return; - _titlebarColourVisibility = value; - OnPropertyChanged(); - } - } - - /// - /// Should the titlebar hides itself after a short period of inactivity? - /// - public bool TitlebarAutoHide - { - get => _titlebarAutoHide; - set - { - if (value == _titlebarAutoHide) return; - _titlebarAutoHide = value; - OnPropertyChanged(); - } - } - - /// - /// Switch to dark theme? - /// - public Themes Theme - { - get => _theme; - set - { - _theme = value; - OnPropertyChanged(); - } - } - - public event PropertyChangedEventHandler PropertyChanged; - - /// - /// Set the size of viewer window, scale or shrink to fit (to screen resolution). - /// The window can take maximum (maxRatio*resolution) space. - /// - /// The desired size. - /// The maximum percent (over screen resolution) it can take. - public double SetPreferredSizeFit(Size size, double maxRatio) - { - if (maxRatio > 1) - maxRatio = 1; - - var max = WindowHelper.GetCurrentWindowRect(); - - var widthRatio = max.Width * maxRatio / size.Width; - var heightRatio = max.Height * maxRatio / size.Height; - - var ratio = Math.Min(widthRatio, heightRatio); - if (ratio > 1) ratio = 1; - - PreferredSize = new Size {Width = size.Width * ratio, Height = size.Height * ratio}; - - return ratio; - } - - public void Reset() - { - Title = string.Empty; - // set to False to prevent showing loading icon - IsBusy = false; - PreferredSize = new Size(); - CanResize = true; - FullWindowDragging = false; - - Theme = Themes.None; - TitlebarOverlap = false; - TitlebarAutoHide = false; - TitlebarBlurVisibility = false; - TitlebarColourVisibility = true; - - ViewerContent = null; - } - - [NotifyPropertyChangedInvocator] - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - } -} \ No newline at end of file diff --git a/QuickLook.Common/Plugin/IViewer.cs b/QuickLook.Common/Plugin/IViewer.cs deleted file mode 100644 index f56e36f..0000000 --- a/QuickLook.Common/Plugin/IViewer.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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 . - -namespace QuickLook.Common.Plugin -{ - /// - /// Interface implemented by every QuickLook.Plugin - /// - public interface IViewer - { - /// - /// Set the priority of this plugin. A plugin with a higher priority may override one with lower priority. - /// Set this to int.MaxValue for a maximum priority, int.MinValue for minimum. - /// - int Priority { get; } - - /// - /// Do ont-time job when application starts. You may extract nessessary resource here. - /// - void Init(); - - /// - /// Determine whether this plugin can open this file. Please also check the file header, if applicable. - /// - /// The full path of the target file. - bool CanHandle(string path); - - /// - /// Do some preparation stuff before the window is showing. Please not do any work that costs a lot of time. - /// - /// The full path of the target file. - /// A runtime object which allows interaction between this plugin and QuickLook. - void Prepare(string path, ContextObject context); - - /// - /// Start the loading process. During the process a busy indicator will be shown. Finish by setting context.IsBusy to - /// false. - /// - /// The full path of the target file. - /// A runtime object which allows interaction between this plugin and QuickLook. - void View(string path, ContextObject context); - - /// - /// Release any unmanaged resource here. - /// - void Cleanup(); - } -} \ No newline at end of file diff --git a/QuickLook.Common/Plugin/Themes.cs b/QuickLook.Common/Plugin/Themes.cs deleted file mode 100644 index 50971a1..0000000 --- a/QuickLook.Common/Plugin/Themes.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright © 2018 Paddy Xu -// -// 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 . - -namespace QuickLook.Common.Plugin -{ - public enum Themes - { - None, - Dark, - Light - } -} \ No newline at end of file diff --git a/QuickLook.Common/Properties/Annotations.cs b/QuickLook.Common/Properties/Annotations.cs deleted file mode 100644 index aaea76c..0000000 --- a/QuickLook.Common/Properties/Annotations.cs +++ /dev/null @@ -1,1241 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; - -#pragma warning disable 1591 -// ReSharper disable UnusedMember.Global -// ReSharper disable MemberCanBePrivate.Global -// ReSharper disable UnusedAutoPropertyAccessor.Global -// ReSharper disable IntroduceOptionalParameters.Global -// ReSharper disable MemberCanBeProtected.Global -// ReSharper disable InconsistentNaming - -namespace QuickLook.Common.Annotations -{ - /// - /// Indicates that the value of the marked element could be null sometimes, - /// so the check for null is necessary before its usage. - /// - /// - /// - /// [CanBeNull] object Test() => null; - /// - /// void UseTest() { - /// var p = Test(); - /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException' - /// } - /// - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] - public sealed class CanBeNullAttribute : Attribute - { - } - - /// - /// Indicates that the value of the marked element could never be null. - /// - /// - /// - /// [NotNull] object Foo() { - /// return null; // Warning: Possible 'null' assignment - /// } - /// - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] - public sealed class NotNullAttribute : Attribute - { - } - - /// - /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task - /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property - /// or of the Lazy.Value property can never be null. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field)] - public sealed class ItemNotNullAttribute : Attribute - { - } - - /// - /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task - /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property - /// or of the Lazy.Value property can be null. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field)] - public sealed class ItemCanBeNullAttribute : Attribute - { - } - - /// - /// Indicates that the marked method builds string by format pattern and (optional) arguments. - /// Parameter, which contains format string, should be given in constructor. The format string - /// should be in -like form. - /// - /// - /// - /// [StringFormatMethod("message")] - /// void ShowError(string message, params object[] args) { /* do something */ } - /// - /// void Foo() { - /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string - /// } - /// - /// - [AttributeUsage( - AttributeTargets.Constructor | AttributeTargets.Method | - AttributeTargets.Property | AttributeTargets.Delegate)] - public sealed class StringFormatMethodAttribute : Attribute - { - /// - /// Specifies which parameter of an annotated method should be treated as format-string - /// - public StringFormatMethodAttribute([NotNull] string formatParameterName) - { - FormatParameterName = formatParameterName; - } - - [NotNull] - public string FormatParameterName { get; } - } - - /// - /// For a parameter that is expected to be one of the limited set of values. - /// Specify fields of which type should be used as values for this parameter. - /// - [AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field, - AllowMultiple = true)] - public sealed class ValueProviderAttribute : Attribute - { - public ValueProviderAttribute([NotNull] string name) - { - Name = name; - } - - [NotNull] - public string Name { get; } - } - - /// - /// Indicates that the function argument should be string literal and match one - /// of the parameters of the caller function. For example, ReSharper annotates - /// the parameter of . - /// - /// - /// - /// void Foo(string param) { - /// if (param == null) - /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol - /// } - /// - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class InvokerParameterNameAttribute : Attribute - { - } - - /// - /// Indicates that the method is contained in a type that implements - /// System.ComponentModel.INotifyPropertyChanged interface and this method - /// is used to notify that some property value changed. - /// - /// - /// The method should be non-static and conform to one of the supported signatures: - /// - /// - /// NotifyChanged(string) - /// - /// - /// NotifyChanged(params string[]) - /// - /// - /// NotifyChanged{T}(Expression{Func{T}}) - /// - /// - /// NotifyChanged{T,U}(Expression{Func{T,U}}) - /// - /// - /// SetProperty{T}(ref T, T, string) - /// - /// - /// - /// - /// - /// public class Foo : INotifyPropertyChanged { - /// public event PropertyChangedEventHandler PropertyChanged; - /// - /// [NotifyPropertyChangedInvocator] - /// protected virtual void NotifyChanged(string propertyName) { ... } - /// - /// string _name; - /// - /// public string Name { - /// get { return _name; } - /// set { _name = value; NotifyChanged("LastName"); /* Warning */ } - /// } - /// } - /// - /// Examples of generated notifications: - /// - /// - /// NotifyChanged("Property") - /// - /// - /// NotifyChanged(() => Property) - /// - /// - /// NotifyChanged((VM x) => x.Property) - /// - /// - /// SetProperty(ref myField, value, "Property") - /// - /// - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class NotifyPropertyChangedInvocatorAttribute : Attribute - { - public NotifyPropertyChangedInvocatorAttribute() - { - } - - public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName) - { - ParameterName = parameterName; - } - - [CanBeNull] - public string ParameterName { get; } - } - - /// - /// Describes dependency between method input and output. - /// - /// - ///

Function Definition Table syntax:

- /// - /// FDT ::= FDTRow [;FDTRow]* - /// FDTRow ::= Input => Output | Output <= Input - /// Input ::= ParameterName: Value [, Input]* - /// Output ::= [ParameterName: Value]* {halt|stop|void|nothing|Value} - /// Value ::= true | false | null | notnull | canbenull - /// - /// If method has single input parameter, it's name could be omitted.
- /// Using halt (or void/nothing, which is the same) for method output - /// means that the methos doesn't return normally (throws or terminates the process).
- /// Value canbenull is only applicable for output parameters.
- /// You can use multiple [ContractAnnotation] for each FDT row, or use single attribute - /// with rows separated by semicolon. There is no notion of order rows, all rows are checked - /// for applicability and applied per each program state tracked by R# analysis.
- ///
- /// - /// - /// - /// - /// [ContractAnnotation("=> halt")] - /// public void TerminationMethod() - /// - /// - /// - /// - /// [ContractAnnotation("halt <= condition: false")] - /// public void Assert(bool condition, string text) // regular assertion method - /// - /// - /// - /// - /// [ContractAnnotation("s:null => true")] - /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty() - /// - /// - /// - /// - /// // A method that returns null if the parameter is null, - /// // and not null if the parameter is not null - /// [ContractAnnotation("null => null; notnull => notnull")] - /// public object Transform(object data) - /// - /// - /// - /// - /// [ContractAnnotation("=> true, result: notnull; => false, result: null")] - /// public bool TryParse(string s, out Person result) - /// - /// - /// - /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - public sealed class ContractAnnotationAttribute : Attribute - { - public ContractAnnotationAttribute([NotNull] string contract) - : this(contract, false) - { - } - - public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates) - { - Contract = contract; - ForceFullStates = forceFullStates; - } - - [NotNull] - public string Contract { get; } - - public bool ForceFullStates { get; } - } - - /// - /// Indicates that marked element should be localized or not. - /// - /// - /// - /// [LocalizationRequiredAttribute(true)] - /// class Foo { - /// string str = "my string"; // Warning: Localizable string - /// } - /// - /// - [AttributeUsage(AttributeTargets.All)] - public sealed class LocalizationRequiredAttribute : Attribute - { - public LocalizationRequiredAttribute() : this(true) - { - } - - public LocalizationRequiredAttribute(bool required) - { - Required = required; - } - - public bool Required { get; } - } - - /// - /// Indicates that the value of the marked type (or its derivatives) - /// cannot be compared using '==' or '!=' operators and Equals() - /// should be used instead. However, using '==' or '!=' for comparison - /// with null is always permitted. - /// - /// - /// - /// [CannotApplyEqualityOperator] - /// class NoEquality { } - /// - /// class UsesNoEquality { - /// void Test() { - /// var ca1 = new NoEquality(); - /// var ca2 = new NoEquality(); - /// if (ca1 != null) { // OK - /// bool condition = ca1 == ca2; // Warning - /// } - /// } - /// } - /// - /// - [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct)] - public sealed class CannotApplyEqualityOperatorAttribute : Attribute - { - } - - /// - /// When applied to a target attribute, specifies a requirement for any type marked - /// with the target attribute to implement or inherit specific type or types. - /// - /// - /// - /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement - /// class ComponentAttribute : Attribute { } - /// - /// [Component] // ComponentAttribute requires implementing IComponent interface - /// class MyComponent : IComponent { } - /// - /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - [BaseTypeRequired(typeof(Attribute))] - public sealed class BaseTypeRequiredAttribute : Attribute - { - public BaseTypeRequiredAttribute([NotNull] Type baseType) - { - BaseType = baseType; - } - - [NotNull] - public Type BaseType { get; } - } - - /// - /// Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library), - /// so this symbol will not be marked as unused (as well as by other usage inspections). - /// - [AttributeUsage(AttributeTargets.All)] - public sealed class UsedImplicitlyAttribute : Attribute - { - public UsedImplicitlyAttribute() - : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) - { - } - - public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags) - : this(useKindFlags, ImplicitUseTargetFlags.Default) - { - } - - public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags) - : this(ImplicitUseKindFlags.Default, targetFlags) - { - } - - public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) - { - UseKindFlags = useKindFlags; - TargetFlags = targetFlags; - } - - public ImplicitUseKindFlags UseKindFlags { get; } - - public ImplicitUseTargetFlags TargetFlags { get; } - } - - /// - /// Should be used on attributes and causes ReSharper to not mark symbols marked with such attributes - /// as unused (as well as by other usage inspections) - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter)] - public sealed class MeansImplicitUseAttribute : Attribute - { - public MeansImplicitUseAttribute() - : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) - { - } - - public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags) - : this(useKindFlags, ImplicitUseTargetFlags.Default) - { - } - - public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags) - : this(ImplicitUseKindFlags.Default, targetFlags) - { - } - - public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) - { - UseKindFlags = useKindFlags; - TargetFlags = targetFlags; - } - - [UsedImplicitly] - public ImplicitUseKindFlags UseKindFlags { get; } - - [UsedImplicitly] - public ImplicitUseTargetFlags TargetFlags { get; } - } - - [Flags] - public enum ImplicitUseKindFlags - { - Default = Access | Assign | InstantiatedWithFixedConstructorSignature, - /// Only entity marked with attribute considered used. - Access = 1, - /// Indicates implicit assignment to a member. - Assign = 2, - /// - /// Indicates implicit instantiation of a type with fixed constructor signature. - /// That means any unused constructor parameters won't be reported as such. - /// - InstantiatedWithFixedConstructorSignature = 4, - /// Indicates implicit instantiation of a type. - InstantiatedNoFixedConstructorSignature = 8 - } - - /// - /// Specify what is considered used implicitly when marked - /// with or . - /// - [Flags] - public enum ImplicitUseTargetFlags - { - Default = Itself, - Itself = 1, - /// Members of entity marked with attribute are considered used. - Members = 2, - /// Entity marked with attribute and all its members considered used. - WithMembers = Itself | Members - } - - /// - /// This attribute is intended to mark publicly available API - /// which should not be removed and so is treated as used. - /// - [MeansImplicitUse(ImplicitUseTargetFlags.WithMembers)] - public sealed class PublicAPIAttribute : Attribute - { - public PublicAPIAttribute() - { - } - - public PublicAPIAttribute([NotNull] string comment) - { - Comment = comment; - } - - [CanBeNull] - public string Comment { get; } - } - - /// - /// Tells code analysis engine if the parameter is completely handled when the invoked method is on stack. - /// If the parameter is a delegate, indicates that delegate is executed while the method is executed. - /// If the parameter is an enumerable, indicates that it is enumerated while the method is executed. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class InstantHandleAttribute : Attribute - { - } - - /// - /// Indicates that a method does not make any observable state changes. - /// The same as System.Diagnostics.Contracts.PureAttribute. - /// - /// - /// - /// [Pure] int Multiply(int x, int y) => x * y; - /// - /// void M() { - /// Multiply(123, 42); // Waring: Return value of pure method is not used - /// } - /// - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class PureAttribute : Attribute - { - } - - /// - /// Indicates that the return value of method invocation must be used. - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class MustUseReturnValueAttribute : Attribute - { - public MustUseReturnValueAttribute() - { - } - - public MustUseReturnValueAttribute([NotNull] string justification) - { - Justification = justification; - } - - [CanBeNull] - public string Justification { get; } - } - - /// - /// Indicates the type member or parameter of some type, that should be used instead of all other ways - /// to get the value that type. This annotation is useful when you have some "context" value evaluated - /// and stored somewhere, meaning that all other ways to get this value must be consolidated with existing one. - /// - /// - /// - /// class Foo { - /// [ProvidesContext] IBarService _barService = ...; - /// - /// void ProcessNode(INode node) { - /// DoSomething(node, node.GetGlobalServices().Bar); - /// // ^ Warning: use value of '_barService' field - /// } - /// } - /// - /// - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.Method | - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | - AttributeTargets.GenericParameter)] - public sealed class ProvidesContextAttribute : Attribute - { - } - - /// - /// Indicates that a parameter is a path to a file or a folder within a web project. - /// Path can be relative or absolute, starting from web root (~). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class PathReferenceAttribute : Attribute - { - public PathReferenceAttribute() - { - } - - public PathReferenceAttribute([NotNull] [PathReference] string basePath) - { - BasePath = basePath; - } - - [CanBeNull] - public string BasePath { get; } - } - - /// - /// An extension method marked with this attribute is processed by ReSharper code completion - /// as a 'Source Template'. When extension method is completed over some expression, it's source code - /// is automatically expanded like a template at call site. - /// - /// - /// Template method body can contain valid source code and/or special comments starting with '$'. - /// Text inside these comments is added as source code when the template is applied. Template parameters - /// can be used either as additional method parameters or as identifiers wrapped in two '$' signs. - /// Use the attribute to specify macros for parameters. - /// - /// - /// In this example, the 'forEach' method is a source template available over all values - /// of enumerable types, producing ordinary C# 'foreach' statement and placing caret inside block: - /// - /// [SourceTemplate] - /// public static void forEach<T>(this IEnumerable<T> xs) { - /// foreach (var x in xs) { - /// //$ $END$ - /// } - /// } - /// - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class SourceTemplateAttribute : Attribute - { - } - - /// - /// Allows specifying a macro for a parameter of a source template. - /// - /// - /// You can apply the attribute on the whole method or on any of its additional parameters. The macro expression - /// is defined in the property. When applied on a method, the target - /// template parameter is defined in the property. To apply the macro silently - /// for the parameter, set the property value = -1. - /// - /// - /// Applying the attribute on a source template method: - /// - /// [SourceTemplate, Macro(Target = "item", Expression = "suggestVariableName()")] - /// public static void forEach<T>(this IEnumerable<T> collection) { - /// foreach (var item in collection) { - /// //$ $END$ - /// } - /// } - /// - /// Applying the attribute on a template method parameter: - /// - /// [SourceTemplate] - /// public static void something(this Entity x, [Macro(Expression = "guid()", Editable = -1)] string newguid) { - /// /*$ var $x$Id = "$newguid$" + x.ToString(); - /// x.DoSomething($x$Id); */ - /// } - /// - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method, AllowMultiple = true)] - public sealed class MacroAttribute : Attribute - { - /// - /// Allows specifying a macro that will be executed for a source template - /// parameter when the template is expanded. - /// - [CanBeNull] - public string Expression { get; set; } - - /// - /// Allows specifying which occurrence of the target parameter becomes editable when the template is deployed. - /// - /// - /// If the target parameter is used several times in the template, only one occurrence becomes editable; - /// other occurrences are changed synchronously. To specify the zero-based index of the editable occurrence, - /// use values >= 0. To make the parameter non-editable when the template is expanded, use -1. - /// - /// > - public int Editable { get; set; } - - /// - /// Identifies the target parameter of a source template if the - /// is applied on a template method. - /// - [CanBeNull] - public string Target { get; set; } - } - - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = - true)] - public sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute - { - public AspMvcAreaMasterLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] - public string Format { get; } - } - - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = - true)] - public sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute - { - public AspMvcAreaPartialViewLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] - public string Format { get; } - } - - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = - true)] - public sealed class AspMvcAreaViewLocationFormatAttribute : Attribute - { - public AspMvcAreaViewLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] - public string Format { get; } - } - - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = - true)] - public sealed class AspMvcMasterLocationFormatAttribute : Attribute - { - public AspMvcMasterLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] - public string Format { get; } - } - - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = - true)] - public sealed class AspMvcPartialViewLocationFormatAttribute : Attribute - { - public AspMvcPartialViewLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] - public string Format { get; } - } - - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = - true)] - public sealed class AspMvcViewLocationFormatAttribute : Attribute - { - public AspMvcViewLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] - public string Format { get; } - } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter - /// is an MVC action. If applied to a method, the MVC action name is calculated - /// implicitly from the context. Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcActionAttribute : Attribute - { - public AspMvcActionAttribute() - { - } - - public AspMvcActionAttribute([NotNull] string anonymousProperty) - { - AnonymousProperty = anonymousProperty; - } - - [CanBeNull] - public string AnonymousProperty { get; } - } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC area. - /// Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcAreaAttribute : Attribute - { - public AspMvcAreaAttribute() - { - } - - public AspMvcAreaAttribute([NotNull] string anonymousProperty) - { - AnonymousProperty = anonymousProperty; - } - - [CanBeNull] - public string AnonymousProperty { get; } - } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is - /// an MVC controller. If applied to a method, the MVC controller name is calculated - /// implicitly from the context. Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String, String). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcControllerAttribute : Attribute - { - public AspMvcControllerAttribute() - { - } - - public AspMvcControllerAttribute([NotNull] string anonymousProperty) - { - AnonymousProperty = anonymousProperty; - } - - [CanBeNull] - public string AnonymousProperty { get; } - } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC Master. Use this attribute - /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcMasterAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC model type. Use this attribute - /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, Object). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcModelTypeAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is an MVC - /// partial view. If applied to a method, the MVC partial view name is calculated implicitly - /// from the context. Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcPartialViewAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. Allows disabling inspections for MVC views within a class or a method. - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] - public sealed class AspMvcSuppressViewErrorAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC display template. - /// Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.DisplayExtensions.DisplayForModel(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcDisplayTemplateAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC editor template. - /// Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.EditorExtensions.EditorForModel(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcEditorTemplateAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC template. - /// Use this attribute for custom wrappers similar to - /// System.ComponentModel.DataAnnotations.UIHintAttribute(System.String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcTemplateAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter - /// is an MVC view component. If applied to a method, the MVC view name is calculated implicitly - /// from the context. Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Controller.View(Object). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcViewAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter - /// is an MVC view component name. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcViewComponentAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter - /// is an MVC view component view. If applied to a method, the MVC view component view name is default. - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcViewComponentViewAttribute : Attribute - { - } - - /// - /// ASP.NET MVC attribute. When applied to a parameter of an attribute, - /// indicates that this parameter is an MVC action name. - /// - /// - /// - /// [ActionName("Foo")] - /// public ActionResult Login(string returnUrl) { - /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK - /// return RedirectToAction("Bar"); // Error: Cannot resolve action - /// } - /// - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)] - public sealed class AspMvcActionSelectorAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field)] - public sealed class HtmlElementAttributesAttribute : Attribute - { - public HtmlElementAttributesAttribute() - { - } - - public HtmlElementAttributesAttribute([NotNull] string name) - { - Name = name; - } - - [CanBeNull] - public string Name { get; } - } - - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] - public sealed class HtmlAttributeValueAttribute : Attribute - { - public HtmlAttributeValueAttribute([NotNull] string name) - { - Name = name; - } - - [NotNull] - public string Name { get; } - } - - /// - /// Razor attribute. Indicates that a parameter or a method is a Razor section. - /// Use this attribute for custom wrappers similar to - /// System.Web.WebPages.WebPageBase.RenderSection(String). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class RazorSectionAttribute : Attribute - { - } - - /// - /// Indicates how method, constructor invocation or property access - /// over collection type affects content of the collection. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property)] - public sealed class CollectionAccessAttribute : Attribute - { - public CollectionAccessAttribute(CollectionAccessType collectionAccessType) - { - CollectionAccessType = collectionAccessType; - } - - public CollectionAccessType CollectionAccessType { get; } - } - - [Flags] - public enum CollectionAccessType - { - /// Method does not use or modify content of the collection. - None = 0, - /// Method only reads content of the collection but does not modify it. - Read = 1, - /// Method can change content of the collection but does not add new elements. - ModifyExistingContent = 2, - /// Method can add new elements to the collection. - UpdatedContent = ModifyExistingContent | 4 - } - - /// - /// Indicates that the marked method is assertion method, i.e. it halts control flow if - /// one of the conditions is satisfied. To set the condition, mark one of the parameters with - /// attribute. - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class AssertionMethodAttribute : Attribute - { - } - - /// - /// Indicates the condition parameter of the assertion method. The method itself should be - /// marked by attribute. The mandatory argument of - /// the attribute is the assertion type. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AssertionConditionAttribute : Attribute - { - public AssertionConditionAttribute(AssertionConditionType conditionType) - { - ConditionType = conditionType; - } - - public AssertionConditionType ConditionType { get; } - } - - /// - /// Specifies assertion type. If the assertion method argument satisfies the condition, - /// then the execution continues. Otherwise, execution is assumed to be halted. - /// - public enum AssertionConditionType - { - /// Marked parameter should be evaluated to true. - IS_TRUE = 0, - /// Marked parameter should be evaluated to false. - IS_FALSE = 1, - /// Marked parameter should be evaluated to null value. - IS_NULL = 2, - /// Marked parameter should be evaluated to not null value. - IS_NOT_NULL = 3 - } - - /// - /// Indicates that the marked method unconditionally terminates control flow execution. - /// For example, it could unconditionally throw exception. - /// - [Obsolete("Use [ContractAnnotation('=> halt')] instead")] - [AttributeUsage(AttributeTargets.Method)] - public sealed class TerminatesProgramAttribute : Attribute - { - } - - /// - /// Indicates that method is pure LINQ method, with postponed enumeration (like Enumerable.Select, - /// .Where). This annotation allows inference of [InstantHandle] annotation for parameters - /// of delegate type by analyzing LINQ method chains. - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class LinqTunnelAttribute : Attribute - { - } - - /// - /// Indicates that IEnumerable, passed as parameter, is not enumerated. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class NoEnumerationAttribute : Attribute - { - } - - /// - /// Indicates that parameter is regular expression pattern. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class RegexPatternAttribute : Attribute - { - } - - /// - /// Prevents the Member Reordering feature from tossing members of the marked class. - /// - /// - /// The attribute must be mentioned in your member reordering patterns - /// - [AttributeUsage( - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enum)] - public sealed class NoReorderAttribute : Attribute - { - } - - /// - /// XAML attribute. Indicates the type that has ItemsSource property and should be treated - /// as ItemsControl-derived type, to enable inner items DataContext type resolve. - /// - [AttributeUsage(AttributeTargets.Class)] - public sealed class XamlItemsControlAttribute : Attribute - { - } - - /// - /// XAML attribute. Indicates the property of some BindingBase-derived type, that - /// is used to bind some item of ItemsControl-derived type. This annotation will - /// enable the DataContext type resolve for XAML bindings for such properties. - /// - /// - /// Property should have the tree ancestor of the ItemsControl type or - /// marked with the attribute. - /// - [AttributeUsage(AttributeTargets.Property)] - public sealed class XamlItemBindingOfItemsControlAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - public sealed class AspChildControlTypeAttribute : Attribute - { - public AspChildControlTypeAttribute([NotNull] string tagName, [NotNull] Type controlType) - { - TagName = tagName; - ControlType = controlType; - } - - [NotNull] - public string TagName { get; } - - [NotNull] - public Type ControlType { get; } - } - - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] - public sealed class AspDataFieldAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] - public sealed class AspDataFieldsAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Property)] - public sealed class AspMethodPropertyAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - public sealed class AspRequiredAttributeAttribute : Attribute - { - public AspRequiredAttributeAttribute([NotNull] string attribute) - { - Attribute = attribute; - } - - [NotNull] - public string Attribute { get; } - } - - [AttributeUsage(AttributeTargets.Property)] - public sealed class AspTypePropertyAttribute : Attribute - { - public AspTypePropertyAttribute(bool createConstructorReferences) - { - CreateConstructorReferences = createConstructorReferences; - } - - public bool CreateConstructorReferences { get; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class RazorImportNamespaceAttribute : Attribute - { - public RazorImportNamespaceAttribute([NotNull] string name) - { - Name = name; - } - - [NotNull] - public string Name { get; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class RazorInjectionAttribute : Attribute - { - public RazorInjectionAttribute([NotNull] string type, [NotNull] string fieldName) - { - Type = type; - FieldName = fieldName; - } - - [NotNull] - public string Type { get; } - - [NotNull] - public string FieldName { get; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class RazorDirectiveAttribute : Attribute - { - public RazorDirectiveAttribute([NotNull] string directive) - { - Directive = directive; - } - - [NotNull] - public string Directive { get; } - } - - [AttributeUsage(AttributeTargets.Method)] - public sealed class RazorHelperCommonAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Property)] - public sealed class RazorLayoutAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Method)] - public sealed class RazorWriteLiteralMethodAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Method)] - public sealed class RazorWriteMethodAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class RazorWriteMethodParameterAttribute : Attribute - { - } -} \ No newline at end of file diff --git a/QuickLook.Common/Properties/AssemblyInfo.cs b/QuickLook.Common/Properties/AssemblyInfo.cs deleted file mode 100644 index 5dd010b..0000000 --- a/QuickLook.Common/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -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.Common")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("QuickLook.Common")] -[assembly: AssemblyCopyright("Copyright © Paddy Xu 2018")] -[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("85fdd6ba-871d-46c8-bd64-f6bb0cb5ea95")] - -// 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.*")] \ No newline at end of file diff --git a/QuickLook.Common/QuickLook.Common.csproj b/QuickLook.Common/QuickLook.Common.csproj deleted file mode 100644 index e100f7b..0000000 --- a/QuickLook.Common/QuickLook.Common.csproj +++ /dev/null @@ -1,83 +0,0 @@ - - - - - Debug - AnyCPU - {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95} - Library - Properties - QuickLook.Common - QuickLook.Common - v4.6.2 - 512 - - - - true - full - false - ..\Build\Debug\ - DEBUG;TRACE - prompt - 4 - true - - - pdbonly - true - ..\Build\Release\ - TRACE - prompt - 4 - true - - - - - - - - - - - - - - Properties\GitVersion.cs - - - - - - - - - - - - - - - - - - - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - - \ No newline at end of file diff --git a/QuickLook.Common/Styles/MainWindowStyles.Dark.xaml b/QuickLook.Common/Styles/MainWindowStyles.Dark.xaml deleted file mode 100644 index 8a4910a..0000000 --- a/QuickLook.Common/Styles/MainWindowStyles.Dark.xaml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/QuickLook.Common/Styles/MainWindowStyles.xaml b/QuickLook.Common/Styles/MainWindowStyles.xaml deleted file mode 100644 index bc6c8f9..0000000 --- a/QuickLook.Common/Styles/MainWindowStyles.xaml +++ /dev/null @@ -1,93 +0,0 @@ - - 1 - 6 - 32 - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/QuickLook.Common/Styles/ScrollBarStyleDictionary.xaml b/QuickLook.Common/Styles/ScrollBarStyleDictionary.xaml deleted file mode 100644 index 4674848..0000000 --- a/QuickLook.Common/Styles/ScrollBarStyleDictionary.xaml +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs index 0467af8..55fd71c 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs @@ -30,7 +30,7 @@ namespace QuickLook.Plugin.ArchiveViewer private ArchiveInfoPanel _panel; - public int Priority => 0; + public int Priority => -5; public void Init() { diff --git a/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/DCraw.cs b/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/DCraw.cs deleted file mode 100644 index a0e0bab..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/DCraw.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Text; - -namespace QuickLook.Plugin.CameraRawViewer -{ - internal class DCraw - { - private static readonly string DCrawPath = - Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), - Environment.Is64BitProcess ? "dcraw64.exe" : "dcraw32.exe"); - - public static string ConvertToTiff(string input) - { - var output = Path.GetTempFileName(); - - using (var p = new Process()) - { - p.StartInfo.UseShellExecute = false; - p.StartInfo.CreateNoWindow = true; - p.StartInfo.RedirectStandardOutput = true; - p.StartInfo.FileName = DCrawPath; - p.StartInfo.Arguments = $"-w -W -h -T -O \"{output}\" \"{input}\""; - p.StartInfo.StandardOutputEncoding = Encoding.UTF8; - p.Start(); - - p.WaitForExit(10000); - } - - return new FileInfo(output).Length > 0 ? output : string.Empty; - } - } -} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/Plugin.cs deleted file mode 100644 index 8ea30ac..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/Plugin.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.IO; -using System.Linq; -using QuickLook.Common.Plugin; - -namespace QuickLook.Plugin.CameraRawViewer -{ - public class Plugin : IViewer - { - private static readonly string[] Formats = - { - // camera raw - ".ari", ".arw", ".bay", ".crw", ".cr2", ".cap", ".dcs", ".dcr", ".dng", ".drf", ".eip", ".erf", ".fff", - ".iiq", ".k25", ".kdc", ".mdc", ".mef", ".mos", ".mrw", ".nef", ".nrw", ".obm", ".orf", ".pef", ".ptx", - ".pxn", ".r3d", ".raf", ".raw", ".rwl", ".rw2", ".rwz", ".sr2", ".srf", ".srw", ".x3f" - }; - private string _image = string.Empty; - - private ImageViewer.Plugin _imageViewierPlugin; - - public int Priority => -1;//int.MaxValue; - - public void Init() - { - } - - public bool CanHandle(string path) - { - return false; - return !Directory.Exists(path) && Formats.Any(path.ToLower().EndsWith); - } - - public void Prepare(string path, ContextObject context) - { - _imageViewierPlugin=new ImageViewer.Plugin(); - - _imageViewierPlugin.Prepare(path, context); - } - - public void View(string path, ContextObject context) - { - _image = DCraw.ConvertToTiff(path); - - if (string.IsNullOrEmpty(_image)) - throw new Exception("DCraw failed."); - - _imageViewierPlugin.View(_image, context); - - // correct title - context.Title = Path.GetFileName(path); - } - - public void Cleanup() - { - _imageViewierPlugin.Cleanup(); - _imageViewierPlugin = null; - - try - { - File.Delete(_image); - } - catch (Exception) - { - // ignored - } - } - } -} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/dcraw32.exe b/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/dcraw32.exe deleted file mode 100644 index bdca298..0000000 Binary files a/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/dcraw32.exe and /dev/null differ diff --git a/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/dcraw64.exe b/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/dcraw64.exe deleted file mode 100644 index 060dc48..0000000 Binary files a/QuickLook.Plugin/QuickLook.Plugin.CameraRawViewer/dcraw64.exe and /dev/null differ diff --git a/QuickLook.Plugin/QuickLook.Plugin.CsvViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.CsvViewer/Plugin.cs index 817e39a..bc61016 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.CsvViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.CsvViewer/Plugin.cs @@ -26,7 +26,7 @@ namespace QuickLook.Plugin.CsvViewer { private CsvViewerPanel _panel; - public int Priority => int.MaxValue; + public int Priority => 0; public void Init() { diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/Plugin.cs index b02f8c3..2698a99 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/Plugin.cs @@ -30,7 +30,7 @@ namespace QuickLook.Plugin.EpubViewer { private ContextObject _context; private EpubViewerControl _epubControl; - public int Priority => int.MaxValue; + public int Priority => 0; public void Init() { diff --git a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs index 7c90f4c..c0ec593 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs @@ -30,7 +30,7 @@ namespace QuickLook.Plugin.HtmlViewer private WebpagePanel _panel; - public int Priority => int.MaxValue; + public int Priority => 0; public void Init() { diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/IInitializeWithFile.cs b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/IInitializeWithFile.cs deleted file mode 100644 index 1243763..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/IInitializeWithFile.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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.Runtime.InteropServices; - -namespace QuickLook.Plugin.IPreviewHandlers -{ - [ComImport] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - [Guid("b7d14566-0509-4cce-a71f-0a554233bd9b")] - internal interface IInitializeWithFile - { - void Initialize([MarshalAs(UnmanagedType.LPWStr)] string pszFilePath, uint grfMode); - } -} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/IPreviewHandler.cs b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/IPreviewHandler.cs deleted file mode 100644 index e3175d9..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/IPreviewHandler.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Drawing; -using System.Runtime.InteropServices; -using System.Windows.Forms; - -namespace QuickLook.Plugin.IPreviewHandlers -{ - [ComImport] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - [Guid("8895b1c6-b41f-4c1c-a562-0d564250836f")] - internal interface IPreviewHandler - { - void SetWindow(IntPtr hwnd, ref Rectangle rect); - void SetRect(ref Rectangle rect); - void DoPreview(); - void Unload(); - void SetFocus(); - void QueryFocus(out IntPtr phwnd); - - [PreserveSig] - uint TranslateAccelerator(ref Message pmsg); - } -} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewHandlerHost.cs b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewHandlerHost.cs deleted file mode 100644 index a1278b6..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewHandlerHost.cs +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.ComponentModel; -using System.Drawing; -using System.IO; -using System.Runtime.InteropServices; -using System.Windows.Forms; -using Microsoft.Win32; - -namespace QuickLook.Plugin.IPreviewHandlers -{ - /// - /// A Windows Forms host for Preview Handlers. - /// - public class PreviewHandlerHost : Control - { - /// - /// The GUID for the IShellItem interface. - /// - internal const string GuidIshellitem = "43826d1e-e718-42ee-bc55-a1e261c37bfe"; - - private IPreviewHandler _mCurrentPreviewHandler; - - /// - /// Initialialises a new instance of the PreviewHandlerHost class. - /// - public PreviewHandlerHost() - { - Size = new Size(320, 240); - } - - /// - /// Gets the GUID of the current preview handler. - /// - [Browsable(false)] - [ReadOnly(true)] - public Guid CurrentPreviewHandler { get; private set; } = Guid.Empty; - - /// - /// Releases the unmanaged resources used by the PreviewHandlerHost and optionally releases the managed resources. - /// - /// - protected override void Dispose(bool disposing) - { - UnloadPreviewHandler(); - - if (_mCurrentPreviewHandler != null) - { - Marshal.FinalReleaseComObject(_mCurrentPreviewHandler); - _mCurrentPreviewHandler = null; - GC.Collect(); - } - - base.Dispose(disposing); - } - - /// - /// Returns the GUID of the preview handler associated with the specified file. - /// - /// - /// - public static Guid GetPreviewHandlerGUID(string filename) - { - // open the registry key corresponding to the file extension - var ext = Registry.ClassesRoot.OpenSubKey(Path.GetExtension(filename)); - if (ext != null) - { - // open the key that indicates the GUID of the preview handler type - var test = ext.OpenSubKey("shellex\\{8895b1c6-b41f-4c1c-a562-0d564250836f}"); - if (test != null) return new Guid(Convert.ToString(test.GetValue(null))); - - // sometimes preview handlers are declared on key for the class - var className = Convert.ToString(ext.GetValue(null)); - if (className != null) - { - test = Registry.ClassesRoot.OpenSubKey( - className + "\\shellex\\{8895b1c6-b41f-4c1c-a562-0d564250836f}"); - if (test != null) return new Guid(Convert.ToString(test.GetValue(null))); - } - } - - return Guid.Empty; - } - - /// - /// Resizes the hosted preview handler when this PreviewHandlerHost is resized. - /// - /// - protected override void OnResize(EventArgs e) - { - base.OnResize(e); - - var r = ClientRectangle; - _mCurrentPreviewHandler?.SetRect(ref r); - } - - /// - /// Opens the specified file using the appropriate preview handler and displays the result in this PreviewHandlerHost. - /// - /// - /// - public bool Open(string path) - { - UnloadPreviewHandler(); - - if (string.IsNullOrEmpty(path)) - return false; - - // try to get GUID for the preview handler - var guid = GetPreviewHandlerGUID(path); - - if (guid == Guid.Empty) - return false; - - CurrentPreviewHandler = guid; - var o = Activator.CreateInstance(Type.GetTypeFromCLSID(CurrentPreviewHandler, true)); - - var fileInit = o as IInitializeWithFile; - - if (fileInit == null) - return false; - - fileInit.Initialize(path, 0); - _mCurrentPreviewHandler = o as IPreviewHandler; - if (_mCurrentPreviewHandler == null) - return false; - - if (IsDisposed) - return false; - - // bind the preview handler to the control's bounds and preview the content - var r = ClientRectangle; - _mCurrentPreviewHandler.SetWindow(Handle, ref r); - _mCurrentPreviewHandler.DoPreview(); - - return true; - } - - /// - /// Unloads the preview handler hosted in this PreviewHandlerHost and closes the file stream. - /// - public void UnloadPreviewHandler() - { - try - { - _mCurrentPreviewHandler?.Unload(); - } - catch (Exception) - { - // ignored - } - } - } -} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml deleted file mode 100644 index 004b288..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml.cs deleted file mode 100644 index f1cf581..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Runtime.InteropServices; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Threading; -using QuickLook.Common.Plugin; - -namespace QuickLook.Plugin.IPreviewHandlers -{ - /// - /// Interaction logic for PreviewPanel.xaml - /// - public partial class PreviewPanel : UserControl, IDisposable - { - private PreviewHandlerHost _control; - - public PreviewPanel() - { - InitializeComponent(); - } - - public void Dispose() - { - Application.Current.Dispatcher.BeginInvoke(new Action(() => - { - presenter.Child = null; - presenter?.Dispose(); - - _control?.Dispose(); - _control = null; - })); - } - - public void PreviewFile(string file, ContextObject context) - { - _control = new PreviewHandlerHost(); - presenter.Child = _control; - _control.Open(file); - - //SetForegroundWindow(new WindowInteropHelper(context.ViewerWindow).Handle); - //SetActiveWindow(presenter.Handle); - } - - [DllImport("user32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool SetForegroundWindow(IntPtr hWnd); - - [DllImport("user32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool SetActiveWindow(IntPtr hWnd); - } -} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/Properties/AssemblyInfo.cs b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/Properties/AssemblyInfo.cs deleted file mode 100644 index 3d6c9b8..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright © 2017 Paddy Xu -// -// 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; -using System.Windows; - -// 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.IPreviewHandlers")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("pooi.moe")] -[assembly: AssemblyProduct("QuickLook.Plugin.IPreviewHandlers")] -[assembly: AssemblyCopyright("Copyright © Paddy Xu 2017")] -[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)] - -//In order to begin building localizable applications, set -//CultureYouAreCodingWith in your .csproj file -//inside a . For example, if you are using US english -//in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in -//the line below to match the UICulture setting in the project file. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] - - -// 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.*")] \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/QuickLook.Plugin.IPreviewHandlers.csproj b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/QuickLook.Plugin.IPreviewHandlers.csproj deleted file mode 100644 index f487101..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/QuickLook.Plugin.IPreviewHandlers.csproj +++ /dev/null @@ -1,108 +0,0 @@ - - - - - Debug - AnyCPU - {E37675EA-D957-4495-8655-2609BF86756C} - library - QuickLook.Plugin.IPreviewHandlers - QuickLook.Plugin.IPreviewHandlers - v4.6.2 - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - - - - true - ..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.IPreviewHandlers\ - DEBUG;TRACE - full - x86 - prompt - MinimumRecommendedRules.ruleset - - - ..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.IPreviewHandlers\ - TRACE - true - pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - - - true - ..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.IPreviewHandlers\ - DEBUG;TRACE - full - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - ..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.IPreviewHandlers\ - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - false - - - - - - - - - - - - 4.0 - - - - - - - - - Properties\GitVersion.cs - - - - - Code - - - - - Component - - - PreviewPanel.xaml - - - Code - - - - - {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95} - QuickLook.Common - False - - - - - Designer - MSBuild:Compile - - - - \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs index 3ee949c..dcc0d2f 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs @@ -43,7 +43,7 @@ namespace QuickLook.Plugin.ImageViewer private ImagePanel _ip; private NConvert _meta; - public int Priority => int.MaxValue; + public int Priority => 0; public void Init() { diff --git a/QuickLook.Plugin/QuickLook.Plugin.MailViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.MailViewer/Plugin.cs index 5d12aff..aa2cfba 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.MailViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.MailViewer/Plugin.cs @@ -31,7 +31,7 @@ namespace QuickLook.Plugin.MailViewer private WebpagePanel _panel; private string _tmpDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); - public int Priority => int.MaxValue; + public int Priority => 0; public void Init() { diff --git a/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs index 8b6b1a2..0db6532 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs @@ -30,7 +30,7 @@ namespace QuickLook.Plugin.MarkdownViewer { private WebpagePanel _panel; - public int Priority => int.MaxValue; + public int Priority => 0; public void Init() { diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs index dd57658..2bb29e1 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs @@ -30,7 +30,7 @@ namespace QuickLook.Plugin.PDFViewer private string _path; private PdfViewerControl _pdfControl; - public int Priority => int.MaxValue; + public int Priority => 0; public void Init() { diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.PluginInstaller/Plugin.cs similarity index 56% rename from QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/Plugin.cs rename to QuickLook.Plugin/QuickLook.Plugin.PluginInstaller/Plugin.cs index 5baffe3..5bb906a 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PluginInstaller/Plugin.cs @@ -1,4 +1,4 @@ -// Copyright © 2017 Paddy Xu +// Copyright © 2018 Paddy Xu // // This file is part of QuickLook program. // @@ -21,21 +21,10 @@ using System.Linq; using System.Windows; using QuickLook.Common.Plugin; -namespace QuickLook.Plugin.IPreviewHandlers +namespace QuickLook.Plugin.PluginInstaller { public class Plugin : IViewer { - private static readonly string[] Extensions = - { - ".doc", ".docx", ".docm", - ".xls", ".xlsx", ".xlsm", ".xlsb", - /*".vsd", ".vsdx",*/ - ".ppt", ".pptx", - ".odt", ".ods", ".odp" - }; - - private PreviewPanel _panel; - public int Priority => int.MaxValue; public void Init() @@ -44,37 +33,30 @@ namespace QuickLook.Plugin.IPreviewHandlers public bool CanHandle(string path) { - if (Directory.Exists(path)) - return false; - - if (Extensions.Any(path.ToLower().EndsWith)) - return PreviewHandlerHost.GetPreviewHandlerGUID(path) != Guid.Empty; - - return false; + return !Directory.Exists(path) && path.ToLower().EndsWith(".qlplugin"); } public void Prepare(string path, ContextObject context) { - context.SetPreferredSizeFit(new Size {Width = 800, Height = 800}, 0.8); + context.PreferredSize = new Size { Width = 460, Height = 200 }; + + context.Title = ""; + context.TitlebarOverlap = false; + context.TitlebarBlurVisibility = false; + context.TitlebarColourVisibility = false; + context.CanResize = false; + context.FullWindowDragging = true; } public void View(string path, ContextObject context) { - _panel = new PreviewPanel(); - context.ViewerContent = _panel; - context.Title = Path.GetFileName(path); - - _panel.PreviewFile(path, context); + context.ViewerContent = new PluginInfoPanel(path, context); context.IsBusy = false; } public void Cleanup() { - GC.SuppressFinalize(this); - - _panel?.Dispose(); - _panel = null; } } } \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.PluginInstaller/PluginInfoPanel.xaml b/QuickLook.Plugin/QuickLook.Plugin.PluginInstaller/PluginInfoPanel.xaml new file mode 100644 index 0000000..4420267 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.PluginInstaller/PluginInfoPanel.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + QuickLook.Plugin.PluginInstaller + + + I am a potato. + +