mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-13 19:19:10 +00:00
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "QuickLook.Common"]
|
||||
path = QuickLook.Common
|
||||
url = git@github.com:QL-Win/QuickLook.Common.git
|
1
QuickLook.Common
Submodule
1
QuickLook.Common
Submodule
Submodule QuickLook.Common added at 44448c9f28
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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<object> action, object parm = null)
|
||||
{
|
||||
Task.Delay(delayMs).ContinueWith(t => { disp.Invoke(action, parm); });
|
||||
}
|
||||
|
||||
public static void DelayWithPriority(this Dispatcher disp, int delayMs,
|
||||
Action<object> 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<object> action, object parm = null,
|
||||
DispatcherPriority priority = DispatcherPriority.ApplicationIdle)
|
||||
{
|
||||
await Task.Delay(delayMs);
|
||||
await disp.BeginInvoke(action, priority, parm);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuickLook.Common.ExtensionMethods
|
||||
{
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)
|
||||
{
|
||||
foreach (var item in enumeration)
|
||||
action(item);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
|
||||
namespace QuickLook.Common.ExtensionMethods
|
||||
{
|
||||
public static class TypeExtensions
|
||||
{
|
||||
public static T CreateInstance<T>(this Type t, params object[] paramArray)
|
||||
{
|
||||
return (T)Activator.CreateInstance(t, paramArray);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Logical pixels inch in X
|
||||
/// </summary>
|
||||
LOGPIXELSX = 88,
|
||||
/// <summary>
|
||||
/// Logical pixels inch in Y
|
||||
/// </summary>
|
||||
LOGPIXELSY = 90
|
||||
}
|
||||
|
||||
public struct ScaleFactor
|
||||
{
|
||||
public float Horizontal;
|
||||
public float Vertical;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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<string, XmlDocument> FileCache = new Dictionary<string, XmlDocument>();
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static T Get<T>(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<T>(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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<string, XPathNavigator> FileCache = new Dictionary<string, XPathNavigator>();
|
||||
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using QuickLook.Common.Annotations;
|
||||
using QuickLook.Common.Helpers;
|
||||
|
||||
namespace QuickLook.Common.Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// A runtime object which allows interaction between this plugin and QuickLook.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Get or set the title of Viewer window.
|
||||
/// </summary>
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set
|
||||
{
|
||||
_title = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set the viewer content control.
|
||||
/// </summary>
|
||||
public object ViewerContent
|
||||
{
|
||||
get => _viewerContent;
|
||||
set
|
||||
{
|
||||
_viewerContent = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show or hide the busy indicator icon.
|
||||
/// </summary>
|
||||
public bool IsBusy
|
||||
{
|
||||
get => _isBusy;
|
||||
set
|
||||
{
|
||||
_isBusy = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the exact size you want.
|
||||
/// </summary>
|
||||
public Size PreferredSize { get; set; } = new Size {Width = 800, Height = 600};
|
||||
|
||||
/// <summary>
|
||||
/// Set whether user are allowed to resize the viewer window.
|
||||
/// </summary>
|
||||
public bool CanResize
|
||||
{
|
||||
get => _canResize;
|
||||
set
|
||||
{
|
||||
_canResize = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set whether the full viewer window can be used for mouse dragging.
|
||||
/// </summary>
|
||||
public bool FullWindowDragging
|
||||
{
|
||||
get => _fullWindowDragging;
|
||||
set
|
||||
{
|
||||
_fullWindowDragging = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set whether the viewer content is overlapped by the title bar
|
||||
/// </summary>
|
||||
public bool TitlebarOverlap
|
||||
{
|
||||
get => _titlebarOverlap;
|
||||
set
|
||||
{
|
||||
_titlebarOverlap = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set whether the title bar shows a blurred background
|
||||
/// </summary>
|
||||
public bool TitlebarBlurVisibility
|
||||
{
|
||||
get => _titlebarBlurVisibility;
|
||||
set
|
||||
{
|
||||
if (value == _titlebarBlurVisibility) return;
|
||||
_titlebarBlurVisibility = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set whether the title bar shows a colour overlay
|
||||
/// </summary>
|
||||
public bool TitlebarColourVisibility
|
||||
{
|
||||
get => _titlebarColourVisibility;
|
||||
set
|
||||
{
|
||||
if (value == _titlebarColourVisibility) return;
|
||||
_titlebarColourVisibility = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should the titlebar hides itself after a short period of inactivity?
|
||||
/// </summary>
|
||||
public bool TitlebarAutoHide
|
||||
{
|
||||
get => _titlebarAutoHide;
|
||||
set
|
||||
{
|
||||
if (value == _titlebarAutoHide) return;
|
||||
_titlebarAutoHide = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Switch to dark theme?
|
||||
/// </summary>
|
||||
public Themes Theme
|
||||
{
|
||||
get => _theme;
|
||||
set
|
||||
{
|
||||
_theme = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Set the size of viewer window, scale or shrink to fit (to screen resolution).
|
||||
/// The window can take maximum (maxRatio*resolution) space.
|
||||
/// </summary>
|
||||
/// <param name="size">The desired size.</param>
|
||||
/// <param name="maxRatio">The maximum percent (over screen resolution) it can take.</param>
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace QuickLook.Common.Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface implemented by every QuickLook.Plugin
|
||||
/// </summary>
|
||||
public interface IViewer
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Do ont-time job when application starts. You may extract nessessary resource here.
|
||||
/// </summary>
|
||||
void Init();
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether this plugin can open this file. Please also check the file header, if applicable.
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the target file.</param>
|
||||
bool CanHandle(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Do some preparation stuff before the window is showing. Please not do any work that costs a lot of time.
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the target file.</param>
|
||||
/// <param name="context">A runtime object which allows interaction between this plugin and QuickLook.</param>
|
||||
void Prepare(string path, ContextObject context);
|
||||
|
||||
/// <summary>
|
||||
/// Start the loading process. During the process a busy indicator will be shown. Finish by setting context.IsBusy to
|
||||
/// false.
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the target file.</param>
|
||||
/// <param name="context">A runtime object which allows interaction between this plugin and QuickLook.</param>
|
||||
void View(string path, ContextObject context);
|
||||
|
||||
/// <summary>
|
||||
/// Release any unmanaged resource here.
|
||||
/// </summary>
|
||||
void Cleanup();
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace QuickLook.Common.Plugin
|
||||
{
|
||||
public enum Themes
|
||||
{
|
||||
None,
|
||||
Dark,
|
||||
Light
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -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.*")]
|
@@ -1,83 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>QuickLook.Common</RootNamespace>
|
||||
<AssemblyName>QuickLook.Common</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\Build\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\Build\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\GitVersion.cs">
|
||||
<Link>Properties\GitVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Plugin\ContextObject.cs" />
|
||||
<Compile Include="Helpers\DpiHelper.cs" />
|
||||
<Compile Include="ExtensionMethods\BitmapExtensions.cs" />
|
||||
<Compile Include="ExtensionMethods\DispatcherExtensions.cs" />
|
||||
<Compile Include="ExtensionMethods\EnumerableExtensions.cs" />
|
||||
<Compile Include="ExtensionMethods\FileExtensions.cs" />
|
||||
<Compile Include="ExtensionMethods\TypeExtensions.cs" />
|
||||
<Compile Include="Helpers\FileHelper.cs" />
|
||||
<Compile Include="Plugin\IViewer.cs" />
|
||||
<Compile Include="NativeMethods\Kernel32.cs" />
|
||||
<Compile Include="Helpers\ProcessHelper.cs" />
|
||||
<Compile Include="Plugin\Themes.cs" />
|
||||
<Compile Include="Properties\Annotations.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Helpers\SettingHelper.cs" />
|
||||
<Compile Include="Helpers\TranslationHelper.cs" />
|
||||
<Compile Include="NativeMethods\User32.cs" />
|
||||
<Compile Include="Helpers\WindowHelper.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Styles\MainWindowStyles.Dark.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Styles\MainWindowStyles.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Styles\ScrollBarStyleDictionary.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
@@ -1,15 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="MainWindowBackground" Color="#CC292929" />
|
||||
<SolidColorBrush x:Key="MainWindowBackgroundNoTransparent" Color="#FF292929" />
|
||||
<SolidColorBrush x:Key="WindowTextForeground" Color="#FFEFEFEF" />
|
||||
<SolidColorBrush x:Key="WindowTextForegroundAlternative" Color="#FFD4D4D4" />
|
||||
<SolidColorBrush x:Key="CaptionTextHoverBorder" Color="#DDB9B9B9" />
|
||||
<SolidColorBrush x:Key="CaptionButtonIconForeground" Color="#E5EFEFEF" />
|
||||
<SolidColorBrush x:Key="CaptionButtonHoverBackground" Color="#22FFFFFF" />
|
||||
<SolidColorBrush x:Key="CaptionButtonPressBackground" Color="#44FFFFFF" />
|
||||
<SolidColorBrush x:Key="CaptionCloseButtonHoverForeground" Color="#E5EFEFEF" />
|
||||
<SolidColorBrush x:Key="CaptionCloseButtonHoverBackground" Color="#FFE81123" />
|
||||
<SolidColorBrush x:Key="CaptionCloseButtonPressBackground" Color="#FFB5394B" />
|
||||
<SolidColorBrush x:Key="CaptionBackground" Color="#CC0E0E0E" />
|
||||
</ResourceDictionary>
|
@@ -1,93 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
<Thickness x:Key="MainWindowShadowMarginThickness">1</Thickness>
|
||||
<Thickness x:Key="MainWindowResizeThickness">6</Thickness>
|
||||
<system:Double x:Key="MainWindowCaptionHeight">32</system:Double>
|
||||
<SolidColorBrush x:Key="MainWindowBackground" Color="#BBFAFAFA" />
|
||||
<SolidColorBrush x:Key="MainWindowBackgroundNoTransparent" Color="#FFFAFAFA" />
|
||||
<SolidColorBrush x:Key="WindowTextForeground" Color="#FF0E0E0E" />
|
||||
<SolidColorBrush x:Key="WindowTextForegroundAlternative" Color="#FF626262" />
|
||||
<SolidColorBrush x:Key="CaptionTextHoverBorder" Color="#FF3D3D3D" />
|
||||
<SolidColorBrush x:Key="CaptionButtonIconForeground" Color="#E50E0E0E" />
|
||||
<SolidColorBrush x:Key="CaptionButtonHoverBackground" Color="#44FFFFFF" />
|
||||
<SolidColorBrush x:Key="CaptionButtonPressBackground" Color="#88FFFFFF" />
|
||||
<SolidColorBrush x:Key="CaptionCloseButtonHoverForeground" Color="#E5EFEFEF" />
|
||||
<SolidColorBrush x:Key="CaptionCloseButtonHoverBackground" Color="#FFE81123" />
|
||||
<SolidColorBrush x:Key="CaptionCloseButtonPressBackground" Color="#FFB5394B" />
|
||||
<SolidColorBrush x:Key="CaptionBackground" Color="#BBDADADA" />
|
||||
|
||||
<Style x:Key="CaptionButtonBaseStyle" TargetType="Button">
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="Cursor" Value="Hand" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource WindowTextForeground}" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="CaptionTextButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonBaseStyle}">
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Padding" Value="6,2,6,2" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}" Padding="{TemplateBinding Padding}">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource CaptionTextHoverBorder}" />
|
||||
<Setter Property="Background" Value="{DynamicResource CaptionButtonHoverBackground}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource CaptionButtonPressBackground}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="CaptionButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonBaseStyle}">
|
||||
<Setter Property="Width" Value="45" />
|
||||
<Setter Property="Height" Value="32" />
|
||||
<Setter Property="FontSize" Value="13" />
|
||||
<Setter Property="FontFamily" Value="{StaticResource SegoeMDL2}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource CaptionButtonIconForeground}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
<Border Background="{TemplateBinding Background}" BorderThickness="0"
|
||||
Padding="{TemplateBinding Padding}">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource CaptionButtonHoverBackground}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource CaptionButtonPressBackground}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="CaptionCloseButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource CaptionCloseButtonHoverForeground}" />
|
||||
<Setter Property="Background" Value="{DynamicResource CaptionCloseButtonHoverBackground}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource CaptionCloseButtonPressBackground}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
@@ -1,171 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="StandardBorderBrush" Color="#888" />
|
||||
<SolidColorBrush x:Key="StandardBackgroundBrush" Color="#FFF" />
|
||||
<SolidColorBrush x:Key="HoverBorderBrush" Color="#DDD" />
|
||||
<SolidColorBrush x:Key="SelectedBackgroundBrush" Color="Gray" />
|
||||
<SolidColorBrush x:Key="SelectedForegroundBrush" Color="White" />
|
||||
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
|
||||
<SolidColorBrush x:Key="NormalBrush" Color="#888" />
|
||||
<SolidColorBrush x:Key="NormalBorderBrush" Color="#888" />
|
||||
<SolidColorBrush x:Key="HorizontalNormalBrush" Color="#888" />
|
||||
<SolidColorBrush x:Key="HorizontalNormalBorderBrush" Color="#888" />
|
||||
<LinearGradientBrush x:Key="StandardBrush"
|
||||
StartPoint="0,0" EndPoint="0,1">
|
||||
<GradientBrush.GradientStops>
|
||||
<GradientStopCollection>
|
||||
<GradientStop Color="#FFF" Offset="0.0" />
|
||||
<GradientStop Color="#CCC" Offset="1.0" />
|
||||
</GradientStopCollection>
|
||||
</GradientBrush.GradientStops>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="GlyphBrush" Color="#444" />
|
||||
<LinearGradientBrush x:Key="PressedBrush"
|
||||
StartPoint="0,0" EndPoint="0,1">
|
||||
<GradientBrush.GradientStops>
|
||||
<GradientStopCollection>
|
||||
<GradientStop Color="#BBB" Offset="0.0" />
|
||||
<GradientStop Color="#EEE" Offset="0.1" />
|
||||
<GradientStop Color="#EEE" Offset="0.9" />
|
||||
<GradientStop Color="#FFF" Offset="1.0" />
|
||||
</GradientStopCollection>
|
||||
</GradientBrush.GradientStops>
|
||||
</LinearGradientBrush>
|
||||
|
||||
<!-- SrollViewer ScrollBar Repeat Buttons (at each end) -->
|
||||
<Style x:Key="ScrollBarLineButton" TargetType="{x:Type RepeatButton}">
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="true" />
|
||||
<Setter Property="Focusable" Value="false" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type RepeatButton}">
|
||||
<Border x:Name="Border" Margin="1" CornerRadius="2" Background="{StaticResource NormalBrush}"
|
||||
BorderBrush="{StaticResource NormalBorderBrush}" BorderThickness="0.25">
|
||||
<Path HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Fill="{StaticResource GlyphBrush}"
|
||||
Data="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsPressed" Value="true">
|
||||
<Setter TargetName="Border" Property="Background"
|
||||
Value="{StaticResource PressedBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Foreground"
|
||||
Value="{StaticResource DisabledForegroundBrush}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<!-- SrollViewer ScrollBar Repeat Buttons (The part in the middle,
|
||||
not the thumb the long area between the buttons ) -->
|
||||
<Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="true" />
|
||||
<Setter Property="IsTabStop" Value="false" />
|
||||
<Setter Property="Focusable" Value="false" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type RepeatButton}">
|
||||
<Border Background="Transparent" />
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<!-- ScrollViewer ScrollBar Thumb, that part that can be dragged
|
||||
up/down or left/right Buttons -->
|
||||
<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="true" />
|
||||
<Setter Property="IsTabStop" Value="false" />
|
||||
<Setter Property="Focusable" Value="false" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Thumb}">
|
||||
<Border CornerRadius="2" Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0.25" />
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<!-- VerticalScrollBar Template using the previously created Templates -->
|
||||
<ControlTemplate x:Key="VerticalScrollBar"
|
||||
TargetType="{x:Type ScrollBar}">
|
||||
<Grid Width="13">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Border Grid.RowSpan="3" CornerRadius="2" Background="Transparent" />
|
||||
<Track x:Name="PART_Track" Grid.Row="0" IsDirectionReversed="true">
|
||||
<Track.DecreaseRepeatButton>
|
||||
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageUpCommand" />
|
||||
</Track.DecreaseRepeatButton>
|
||||
<Track.Thumb>
|
||||
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0"
|
||||
Background="{StaticResource HorizontalNormalBrush}"
|
||||
BorderBrush="{StaticResource HorizontalNormalBorderBrush}" />
|
||||
</Track.Thumb>
|
||||
<Track.IncreaseRepeatButton>
|
||||
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageDownCommand" />
|
||||
</Track.IncreaseRepeatButton>
|
||||
</Track>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
<!-- HorizontalScrollBar Template using the previously created Templates -->
|
||||
<ControlTemplate x:Key="HorizontalScrollBar"
|
||||
TargetType="{x:Type ScrollBar}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border
|
||||
Grid.ColumnSpan="3"
|
||||
CornerRadius="2"
|
||||
Background="Transparent" />
|
||||
<Track
|
||||
x:Name="PART_Track"
|
||||
Grid.Column="0"
|
||||
IsDirectionReversed="False">
|
||||
<Track.DecreaseRepeatButton>
|
||||
<RepeatButton
|
||||
Style="{StaticResource ScrollBarPageButton}"
|
||||
Command="ScrollBar.PageLeftCommand" />
|
||||
</Track.DecreaseRepeatButton>
|
||||
<Track.Thumb>
|
||||
<Thumb
|
||||
Style="{StaticResource ScrollBarThumb}"
|
||||
Margin="0,2"
|
||||
Background="{StaticResource NormalBrush}"
|
||||
BorderBrush="{StaticResource NormalBorderBrush}" />
|
||||
</Track.Thumb>
|
||||
<Track.IncreaseRepeatButton>
|
||||
<RepeatButton
|
||||
Style="{StaticResource ScrollBarPageButton}"
|
||||
Command="ScrollBar.PageRightCommand" />
|
||||
</Track.IncreaseRepeatButton>
|
||||
</Track>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
<!-- Style for overall ScrollBar -->
|
||||
<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="true" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Orientation" Value="Horizontal">
|
||||
<Setter Property="Width" Value="Auto" />
|
||||
<Setter Property="Height" Value="15" />
|
||||
<Setter Property="Template"
|
||||
Value="{StaticResource HorizontalScrollBar}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Orientation" Value="Vertical">
|
||||
<Setter Property="Width" Value="13" />
|
||||
<Setter Property="Height" Value="Auto" />
|
||||
<Setter Property="Template"
|
||||
Value="{StaticResource VerticalScrollBar}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
@@ -30,7 +30,7 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
|
||||
private ArchiveInfoPanel _panel;
|
||||
|
||||
public int Priority => 0;
|
||||
public int Priority => -5;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
@@ -26,7 +26,7 @@ namespace QuickLook.Plugin.CsvViewer
|
||||
{
|
||||
private CsvViewerPanel _panel;
|
||||
|
||||
public int Priority => int.MaxValue;
|
||||
public int Priority => 0;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
|
@@ -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()
|
||||
{
|
||||
|
@@ -30,7 +30,7 @@ namespace QuickLook.Plugin.HtmlViewer
|
||||
|
||||
private WebpagePanel _panel;
|
||||
|
||||
public int Priority => int.MaxValue;
|
||||
public int Priority => 0;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// A Windows Forms host for Preview Handlers.
|
||||
/// </summary>
|
||||
public class PreviewHandlerHost : Control
|
||||
{
|
||||
/// <summary>
|
||||
/// The GUID for the IShellItem interface.
|
||||
/// </summary>
|
||||
internal const string GuidIshellitem = "43826d1e-e718-42ee-bc55-a1e261c37bfe";
|
||||
|
||||
private IPreviewHandler _mCurrentPreviewHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initialialises a new instance of the PreviewHandlerHost class.
|
||||
/// </summary>
|
||||
public PreviewHandlerHost()
|
||||
{
|
||||
Size = new Size(320, 240);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the GUID of the current preview handler.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
[ReadOnly(true)]
|
||||
public Guid CurrentPreviewHandler { get; private set; } = Guid.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the PreviewHandlerHost and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
UnloadPreviewHandler();
|
||||
|
||||
if (_mCurrentPreviewHandler != null)
|
||||
{
|
||||
Marshal.FinalReleaseComObject(_mCurrentPreviewHandler);
|
||||
_mCurrentPreviewHandler = null;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the GUID of the preview handler associated with the specified file.
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the hosted preview handler when this PreviewHandlerHost is resized.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
||||
var r = ClientRectangle;
|
||||
_mCurrentPreviewHandler?.SetRect(ref r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the specified file using the appropriate preview handler and displays the result in this PreviewHandlerHost.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unloads the preview handler hosted in this PreviewHandlerHost and closes the file stream.
|
||||
/// </summary>
|
||||
public void UnloadPreviewHandler()
|
||||
{
|
||||
try
|
||||
{
|
||||
_mCurrentPreviewHandler?.Unload();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
<UserControl x:Class="QuickLook.Plugin.IPreviewHandlers.PreviewPanel"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
x:Name="panel"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<WindowsFormsHost x:Name="presenter" />
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for PreviewPanel.xaml
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||
//inside a <PropertyGroup>. For example, if you are using US english
|
||||
//in your source files, set the <UICulture> 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.*")]
|
@@ -1,108 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E37675EA-D957-4495-8655-2609BF86756C}</ProjectGuid>
|
||||
<OutputType>library</OutputType>
|
||||
<RootNamespace>QuickLook.Plugin.IPreviewHandlers</RootNamespace>
|
||||
<AssemblyName>QuickLook.Plugin.IPreviewHandlers</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.IPreviewHandlers\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.IPreviewHandlers\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.IPreviewHandlers\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<OutputPath>..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.IPreviewHandlers\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>
|
||||
</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="WindowsFormsIntegration" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\GitVersion.cs">
|
||||
<Link>Properties\GitVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="IInitializeWithFile.cs" />
|
||||
<Compile Include="IPreviewHandler.cs" />
|
||||
<Compile Include="Plugin.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PreviewHandlerHost.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="PreviewPanel.xaml.cs">
|
||||
<DependentUpon>PreviewPanel.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\QuickLook.Common\QuickLook.Common.csproj">
|
||||
<Project>{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}</Project>
|
||||
<Name>QuickLook.Common</Name>
|
||||
<Private>False</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="PreviewPanel.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
@@ -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()
|
||||
{
|
||||
|
@@ -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()
|
||||
{
|
||||
|
@@ -30,7 +30,7 @@ namespace QuickLook.Plugin.MarkdownViewer
|
||||
{
|
||||
private WebpagePanel _panel;
|
||||
|
||||
public int Priority => int.MaxValue;
|
||||
public int Priority => 0;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
|
@@ -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()
|
||||
{
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<UserControl x:Class="QuickLook.Plugin.PluginInstaller.PluginInfoPanel"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
FontSize="14"
|
||||
mc:Ignorable="d" Width="460" Height="200">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/QuickLook.Common;component/Styles/MainWindowStyles.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="15" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="15" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="10" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="10" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="40" />
|
||||
<RowDefinition Height="10" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock x:Name="filename" Grid.Row="1" Grid.Column="1" FontSize="19" Padding="3"
|
||||
TextWrapping="Wrap"
|
||||
LineHeight="25" MaxHeight="60" TextTrimming="CharacterEllipsis" FontWeight="SemiBold">
|
||||
QuickLook.Plugin.PluginInstaller
|
||||
</TextBlock>
|
||||
<TextBlock x:Name="description" Grid.Row="3" Grid.Column="1" Padding="3"
|
||||
Foreground="{DynamicResource WindowTextForegroundAlternative}">
|
||||
I am a potato.
|
||||
</TextBlock>
|
||||
<Button x:Name="btnInstall" Content="Click here to install this plugin." Grid.Column="1" Grid.Row="4"
|
||||
|
||||
FontWeight="SemiBold" Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||
Style="{StaticResource CaptionTextButtonStyle}" HorizontalAlignment="Right" Margin="0,0,20,0" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -0,0 +1,160 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Xml;
|
||||
using QuickLook.Common.ExtensionMethods;
|
||||
using QuickLook.Common.Plugin;
|
||||
|
||||
namespace QuickLook.Plugin.PluginInstaller
|
||||
{
|
||||
public partial class PluginInfoPanel : UserControl
|
||||
{
|
||||
private readonly ContextObject _context;
|
||||
private readonly string _path;
|
||||
private string _namespace;
|
||||
|
||||
public PluginInfoPanel(string path, ContextObject context)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// apply global theme
|
||||
Resources.MergedDictionaries[0].Clear();
|
||||
|
||||
_path = path;
|
||||
_context = context;
|
||||
ReadInfo();
|
||||
|
||||
btnInstall.Click += BtnInstall_Click;
|
||||
}
|
||||
|
||||
private void BtnInstall_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
btnInstall.Content = "Installing ...";
|
||||
btnInstall.IsEnabled = false;
|
||||
|
||||
var t=DoInstall();
|
||||
t.ContinueWith(_ =>
|
||||
Dispatcher.BeginInvoke(new Action(() => btnInstall.Content = "Done! Please restart QuickLook.")));
|
||||
t.Start();
|
||||
}
|
||||
|
||||
private Task DoInstall()
|
||||
{
|
||||
var targetFolder = Path.Combine(App.UserPluginPath, _namespace);
|
||||
return new Task(() =>
|
||||
{
|
||||
CleanUp();
|
||||
|
||||
try
|
||||
{
|
||||
ZipFile.ExtractToDirectory(_path, targetFolder);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Dispatcher.BeginInvoke(new Action(() => description.Text = ex.Message));
|
||||
CleanUp();
|
||||
}
|
||||
});
|
||||
|
||||
void CleanUp()
|
||||
{
|
||||
if (!Directory.Exists(targetFolder))
|
||||
{
|
||||
Directory.CreateDirectory(targetFolder);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Directory.GetFiles(targetFolder, "*", SearchOption.AllDirectories)
|
||||
.ForEach(file => File.Move(file, new Guid() + ".to_be_deleted"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Dispatcher.BeginInvoke(new Action(() => description.Text = ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ReadInfo()
|
||||
{
|
||||
filename.Text = Path.GetFileNameWithoutExtension(_path);
|
||||
|
||||
var xml = LoadXml(GetFileFromZip(_path, "QuickLook.Plugin.Metadata.config"));
|
||||
|
||||
_namespace = GetString(xml, @"/Metadata/Namespace");
|
||||
|
||||
var okay = _namespace != null && _namespace.StartsWith("QuickLook.Plugin.");
|
||||
|
||||
filename.Text = okay ? _namespace : "Invalid plugin.";
|
||||
description.Text = GetString(xml, @"/Metadata/Description", string.Empty);
|
||||
|
||||
btnInstall.Visibility = okay ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private static string GetString(XmlNode xml, string xpath, string def = null)
|
||||
{
|
||||
var n = xml?.SelectSingleNode(xpath);
|
||||
|
||||
return n?.InnerText;
|
||||
}
|
||||
|
||||
private static XmlDocument LoadXml(Stream data)
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
try
|
||||
{
|
||||
doc.Load(data);
|
||||
return doc;
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static MemoryStream GetFileFromZip(string archive, string entry)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
|
||||
try
|
||||
{
|
||||
using (var zip = ZipFile.Open(archive, ZipArchiveMode.Read))
|
||||
{
|
||||
using (var s = zip?.GetEntry(entry)?.Open())
|
||||
{
|
||||
s?.CopyTo(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return ms;
|
||||
}
|
||||
|
||||
ms.Position = 0;
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
}
|
@@ -21,12 +21,12 @@ using System.Runtime.InteropServices;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("QuickLook.Plugin.ImageViewer")]
|
||||
[assembly: AssemblyTitle("QuickLook.Plugin.PluginInstaller")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("pooi.moe")]
|
||||
[assembly: AssemblyProduct("QuickLook.Plugin.ImageViewer")]
|
||||
[assembly: AssemblyCopyright("Copyright © Paddy Xu 2017")]
|
||||
[assembly: AssemblyProduct("QuickLook.Plugin.PluginInstaller")]
|
||||
[assembly: AssemblyCopyright("Copyright © Paddy Xu 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@@ -36,7 +36,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("fe5a5111-9607-4721-a7be-422754002ed8")]
|
||||
[assembly: Guid("042b5cb9-aaf0-4a61-b847-deb2e06f60ab")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
@@ -7,8 +7,8 @@
|
||||
<ProjectGuid>{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>QuickLook.Plugin.CameraRawViewer</RootNamespace>
|
||||
<AssemblyName>QuickLook.Plugin.CameraRawViewer</AssemblyName>
|
||||
<RootNamespace>QuickLook.Plugin.PluginInstaller</RootNamespace>
|
||||
<AssemblyName>QuickLook.Plugin.PluginInstaller</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
@@ -35,7 +35,7 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.CameraRawViewer\</OutputPath>
|
||||
<OutputPath>..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.PluginInstaller\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -43,7 +43,7 @@
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<OutputPath>..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.CameraRawViewer\</OutputPath>
|
||||
<OutputPath>..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.PluginInstaller\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@@ -63,14 +63,19 @@
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\GitVersion.cs">
|
||||
<Link>Properties\GitVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="DCraw.cs" />
|
||||
<Compile Include="PluginInfoPanel.xaml.cs">
|
||||
<DependentUpon>PluginInfoPanel.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Plugin.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
@@ -80,19 +85,16 @@
|
||||
<Name>QuickLook.Common</Name>
|
||||
<Private>False</Private>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\QuickLook.Plugin.ImageViewer\QuickLook.Plugin.ImageViewer.csproj">
|
||||
<Project>{fe5a5111-9607-4721-a7be-422754002ed8}</Project>
|
||||
<Name>QuickLook.Plugin.ImageViewer</Name>
|
||||
<Private>False</Private>
|
||||
<ProjectReference Include="..\..\QuickLook\QuickLook.csproj">
|
||||
<Project>{8b4a9ce5-67b5-4a94-81cb-3771f688fdeb}</Project>
|
||||
<Name>QuickLook</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="dcraw32.exe">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dcraw64.exe">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Page Include="PluginInfoPanel.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
@@ -31,7 +31,7 @@ namespace QuickLook.Plugin.TextViewer
|
||||
{
|
||||
private TextViewerPanel _tvp;
|
||||
|
||||
public int Priority => 0;
|
||||
public int Priority => -5;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
|
@@ -43,7 +43,7 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
|
||||
private ViewerPanel _vp;
|
||||
|
||||
public int Priority => 0 - 10; // make it lower than TextViewer
|
||||
public int Priority => -10; // make it lower than TextViewer
|
||||
|
||||
public void Init()
|
||||
{
|
||||
|
@@ -48,13 +48,10 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "QuickLook.Installer", "Quic
|
||||
{DE2E3BC5-6AB2-4420-A160-48C7A7506C1C} = {DE2E3BC5-6AB2-4420-A160-48C7A7506C1C}
|
||||
{794E4DCF-F715-4836-9D30-ABD296586D23} = {794E4DCF-F715-4836-9D30-ABD296586D23}
|
||||
{8B4A9CE5-67B5-4A94-81CB-3771F688FDEB} = {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}
|
||||
{E37675EA-D957-4495-8655-2609BF86756C} = {E37675EA-D957-4495-8655-2609BF86756C}
|
||||
{CE22A1F3-7F2C-4EC8-BFDE-B58D0EB625FC} = {CE22A1F3-7F2C-4EC8-BFDE-B58D0EB625FC}
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA} = {BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.IPreviewHandlers", "QuickLook.Plugin\QuickLook.Plugin.IPreviewHandlers\QuickLook.Plugin.IPreviewHandlers.csproj", "{E37675EA-D957-4495-8655-2609BF86756C}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QuickLook.Native64", "QuickLook.Native\QuickLook.Native64\QuickLook.Native64.vcxproj", "{794E4DCF-F715-4836-9D30-ABD296586D23}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{2C58F9B2-D8FA-4586-942B-5170CECE5963} = {2C58F9B2-D8FA-4586-942B-5170CECE5963}
|
||||
@@ -73,10 +70,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.MailViewer
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Common", "QuickLook.Common\QuickLook.Common.csproj", "{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.CameraRawViewer", "QuickLook.Plugin\QuickLook.Plugin.CameraRawViewer\QuickLook.Plugin.CameraRawViewer.csproj", "{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.EpubViewer", "QuickLook.Plugin\QuickLook.Plugin.EpubViewer\QuickLook.Plugin.EpubViewer.csproj", "{260C9E70-0582-471F-BFB5-022CFE7984C8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.PluginInstaller", "QuickLook.Plugin\QuickLook.Plugin.PluginInstaller\QuickLook.Plugin.PluginInstaller.csproj", "{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -163,14 +160,6 @@ Global
|
||||
{F0214FC2-EFBE-426C-842D-B42BC37D9525}.Release|Any CPU.Build.0 = Release|x86
|
||||
{F0214FC2-EFBE-426C-842D-B42BC37D9525}.Release|x86.ActiveCfg = Release|x86
|
||||
{F0214FC2-EFBE-426C-842D-B42BC37D9525}.Release|x86.Build.0 = Release|x86
|
||||
{E37675EA-D957-4495-8655-2609BF86756C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E37675EA-D957-4495-8655-2609BF86756C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E37675EA-D957-4495-8655-2609BF86756C}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{E37675EA-D957-4495-8655-2609BF86756C}.Debug|x86.Build.0 = Debug|x86
|
||||
{E37675EA-D957-4495-8655-2609BF86756C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E37675EA-D957-4495-8655-2609BF86756C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E37675EA-D957-4495-8655-2609BF86756C}.Release|x86.ActiveCfg = Release|x86
|
||||
{E37675EA-D957-4495-8655-2609BF86756C}.Release|x86.Build.0 = Release|x86
|
||||
{794E4DCF-F715-4836-9D30-ABD296586D23}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{794E4DCF-F715-4836-9D30-ABD296586D23}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{794E4DCF-F715-4836-9D30-ABD296586D23}.Debug|x86.ActiveCfg = Debug|x64
|
||||
@@ -207,13 +196,6 @@ Global
|
||||
{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|x86.Build.0 = Release|Any CPU
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Debug|x86.Build.0 = Debug|x86
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Release|x86.ActiveCfg = Release|x86
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Release|x86.Build.0 = Release|x86
|
||||
{260C9E70-0582-471F-BFB5-022CFE7984C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{260C9E70-0582-471F-BFB5-022CFE7984C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{260C9E70-0582-471F-BFB5-022CFE7984C8}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
@@ -222,6 +204,14 @@ Global
|
||||
{260C9E70-0582-471F-BFB5-022CFE7984C8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{260C9E70-0582-471F-BFB5-022CFE7984C8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{260C9E70-0582-471F-BFB5-022CFE7984C8}.Release|x86.Build.0 = Release|Any CPU
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Debug|x86.Build.0 = Debug|x86
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Release|x86.ActiveCfg = Release|x86
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -235,13 +225,12 @@ Global
|
||||
{1B746D92-49A5-4A37-9D75-DCC490393290} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93}
|
||||
{CE22A1F3-7F2C-4EC8-BFDE-B58D0EB625FC} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93}
|
||||
{AB1270AF-7EB4-4B4F-9E09-6404F1A28EA0} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93}
|
||||
{E37675EA-D957-4495-8655-2609BF86756C} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93}
|
||||
{794E4DCF-F715-4836-9D30-ABD296586D23} = {D18A23FF-76BD-43BD-AC32-786D166EBAC9}
|
||||
{2C58F9B2-D8FA-4586-942B-5170CECE5963} = {D18A23FF-76BD-43BD-AC32-786D166EBAC9}
|
||||
{863ECAAC-18D9-4256-A27D-0F308089FB47} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93}
|
||||
{45E94893-3076-4A8E-8969-6955B6340739} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93}
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93}
|
||||
{260C9E70-0582-471F-BFB5-022CFE7984C8} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93}
|
||||
{BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D3761C32-8C5F-498A-892B-3B0882994B62}
|
||||
|
@@ -34,6 +34,7 @@ namespace QuickLook
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public static readonly string UserPluginPath = Path.Combine(SettingHelper.LocalDataPath, "QuickLook.Plugin\\");
|
||||
public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location;
|
||||
public static readonly string AppPath = Path.GetDirectoryName(AppFullPath);
|
||||
public static readonly bool Is64Bit = Environment.Is64BitProcess;
|
||||
|
@@ -22,6 +22,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using QuickLook.Common.ExtensionMethods;
|
||||
using QuickLook.Common.Helpers;
|
||||
using QuickLook.Common.Plugin;
|
||||
|
||||
namespace QuickLook
|
||||
@@ -32,7 +33,10 @@ namespace QuickLook
|
||||
|
||||
private PluginManager()
|
||||
{
|
||||
LoadPlugins();
|
||||
CleanupOldPlugins(App.UserPluginPath);
|
||||
LoadPlugins(App.UserPluginPath);
|
||||
LoadPlugins(Path.Combine(App.AppPath, "QuickLook.Plugin\\"));
|
||||
InitLoadedPlugins();
|
||||
}
|
||||
|
||||
internal IViewer DefaultPlugin { get; } = new Plugin.InfoPanel.Plugin();
|
||||
@@ -74,9 +78,12 @@ namespace QuickLook
|
||||
return (matched ?? DefaultPlugin).GetType().CreateInstance<IViewer>();
|
||||
}
|
||||
|
||||
private void LoadPlugins()
|
||||
private void LoadPlugins(string folder)
|
||||
{
|
||||
Directory.GetFiles(Path.Combine(App.AppPath, "QuickLook.Plugin\\"), "QuickLook.Plugin.*.dll",
|
||||
if (!Directory.Exists(folder))
|
||||
return;
|
||||
|
||||
Directory.GetFiles(folder, "QuickLook.Plugin.*.dll",
|
||||
SearchOption.AllDirectories)
|
||||
.ToList()
|
||||
.ForEach(
|
||||
@@ -90,7 +97,10 @@ namespace QuickLook
|
||||
});
|
||||
|
||||
LoadedPlugins = LoadedPlugins.OrderByDescending(i => i.Priority).ToList();
|
||||
}
|
||||
|
||||
private void InitLoadedPlugins()
|
||||
{
|
||||
LoadedPlugins.ForEach(i =>
|
||||
{
|
||||
try
|
||||
@@ -99,7 +109,25 @@ namespace QuickLook
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
ProcessHelper.WriteLog(e.ToString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void CleanupOldPlugins(string folder)
|
||||
{
|
||||
if (!Directory.Exists(folder))
|
||||
return;
|
||||
|
||||
Directory.GetFiles(folder, "*.to_be_deleted", SearchOption.AllDirectories).ForEach(file =>
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -267,7 +267,7 @@
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>powershell -file "$(SolutionDir)Scripts\update-version.ps1"
|
||||
</PreBuildEvent>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user