Skip to content

Commit

Permalink
update to 3.6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
SplitGemini committed May 19, 2020
1 parent 6e4f62b commit 72dda7d
Showing 70 changed files with 1,350 additions and 1,812 deletions.
23 changes: 23 additions & 0 deletions PRIVACY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# QuickLook Privacy Policy

## Website

When accessing our Website, QuickLook website will learn certain information about you during your visit. How we will handle information we learn about you depends upon what you do when visiting our site.

If you visit our site to read or download information on our pages, we collect and store only the following information about you:

The name of the domain from which you access the Internet
The date and time you access our site
The Internet address of the website you used to link directly to our site.
Third party vendors, including Google and GitHub, use cookies to serve ads based on a user’s prior visits to your website.
If you identify yourself by sending us an e-mail containing personal information, then the information collected will be solely used to respond to your message.

The information collected is for statistical purposes. QuickLook website may use software programs to create summary statistics, which are used for such purposes as assessing the number of visitors to the different sections of our site, what information is of most and least interest, determining technical design specifications, and identifying system performance or problem areas.

QuickLook website will not obtain personally-identifying information about you when you visit our site, unless you choose to provide such information to us, nor will such information be sold or otherwise transferred to unaffiliated third parties without the approval of the user at the time of collection.

## Desktop

The software application doesn’t collect anything personal information from you.

The software application exchange data only with https://github.com using the GitHub Releases API. If you are viewing a remote content via the software, data exchange will happen between you and the remove content.
116 changes: 116 additions & 0 deletions QuickLook.Common/ExtensionMethods/EncodingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuickLook.Common.ExtensionMethods
{
public static class EncodingExtensions
{
/// <summary>
/// 判断读入文本的编码格式
/// 来自:http://stackoverflow.com/questions/1025332/determine-a-strings-encoding-in-c-sharp
/// </summary>
public static Encoding GetEncoding(string filename, int taster = 1000)
{
// Function to detect the encoding for UTF-7, UTF-8/16/32 (bom, no bom, little
// & big endian), and local default codepage, and potentially other codepages.
// 'taster' = number of bytes to check of the file (to save processing). Higher
// value is slower, but more reliable (especially UTF-8 with special characters
// later on may appear to be ASCII initially). If taster = 0, then taster
// becomes the length of the file (for maximum reliability). 'text' is simply
// the string with the discovered encoding applied to the file.
string text;
byte[] b = File.ReadAllBytes(filename);

//////////////// First check the low hanging fruit by checking if a
//////////////// BOM/signature exists (sourced from http://www.unicode.org/faq/utf_bom.html#bom4)
if (b.Length >= 4 && b[0] == 0x00 && b[1] == 0x00 && b[2] == 0xFE && b[3] == 0xFF) { text = Encoding.GetEncoding("utf-32BE").GetString(b, 4, b.Length - 4); return Encoding.GetEncoding("utf-32BE"); } // UTF-32, big-endian
else if (b.Length >= 4 && b[0] == 0xFF && b[1] == 0xFE && b[2] == 0x00 && b[3] == 0x00) { text = Encoding.UTF32.GetString(b, 4, b.Length - 4); return Encoding.UTF32; } // UTF-32, little-endian
else if (b.Length >= 2 && b[0] == 0xFE && b[1] == 0xFF) { text = Encoding.BigEndianUnicode.GetString(b, 2, b.Length - 2); return Encoding.BigEndianUnicode; } // UTF-16, big-endian
else if (b.Length >= 2 && b[0] == 0xFF && b[1] == 0xFE) { text = Encoding.Unicode.GetString(b, 2, b.Length - 2); return Encoding.Unicode; } // UTF-16, little-endian
else if (b.Length >= 3 && b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF) { text = Encoding.UTF8.GetString(b, 3, b.Length - 3); return Encoding.UTF8; } // UTF-8
else if (b.Length >= 3 && b[0] == 0x2b && b[1] == 0x2f && b[2] == 0x76) { text = Encoding.UTF7.GetString(b, 3, b.Length - 3); return Encoding.UTF7; } // UTF-7


//////////// If the code reaches here, no BOM/signature was found, so now
//////////// we need to 'taste' the file to see if can manually discover
//////////// the encoding. A high taster value is desired for UTF-8
if (taster == 0 || taster > b.Length) taster = b.Length; // Taster size can't be bigger than the filesize obviously.


// Some text files are encoded in UTF8, but have no BOM/signature. Hence
// the below manually checks for a UTF8 pattern. This code is based off
// the top answer at: http://stackoverflow.com/questions/6555015/check-for-invalid-utf8
// For our purposes, an unnecessarily strict (and terser/slower)
// implementation is shown at: http://stackoverflow.com/questions/1031645/how-to-detect-utf-8-in-plain-c
// For the below, false positives should be exceedingly rare (and would
// be either slightly malformed UTF-8 (which would suit our purposes
// anyway) or 8-bit extended ASCII/UTF-16/32 at a vanishingly long shot).
int i = 0;
bool utf8 = false;
while (i < taster - 4)
{
if (b[i] <= 0x7F) { i += 1; continue; } // If all characters are below 0x80, then it is valid UTF8, but UTF8 is not 'required' (and therefore the text is more desirable to be treated as the default codepage of the computer). Hence, there's no "utf8 = true;" code unlike the next three checks.
if (b[i] >= 0xC2 && b[i] <= 0xDF && b[i + 1] >= 0x80 && b[i + 1] < 0xC0) { i += 2; utf8 = true; continue; }
if (b[i] >= 0xE0 && b[i] <= 0xF0 && b[i + 1] >= 0x80 && b[i + 1] < 0xC0 && b[i + 2] >= 0x80 && b[i + 2] < 0xC0) { i += 3; utf8 = true; continue; }
if (b[i] >= 0xF0 && b[i] <= 0xF4 && b[i + 1] >= 0x80 && b[i + 1] < 0xC0 && b[i + 2] >= 0x80 && b[i + 2] < 0xC0 && b[i + 3] >= 0x80 && b[i + 3] < 0xC0) { i += 4; utf8 = true; continue; }
utf8 = false; break;
}
if (utf8 == true)
{
text = Encoding.UTF8.GetString(b);
return Encoding.UTF8;
}


// The next check is a heuristic attempt to detect UTF-16 without a BOM.
// We simply look for zeroes in odd or even byte places, and if a certain
// threshold is reached, the code is 'probably' UF-16.
double threshold = 0.1; // proportion of chars step 2 which must be zeroed to be diagnosed as utf-16. 0.1 = 10%
int count = 0;
for (int n = 0; n < taster; n += 2) if (b[n] == 0) count++;
if (((double)count) / taster > threshold) { text = Encoding.BigEndianUnicode.GetString(b); return Encoding.BigEndianUnicode; }
count = 0;
for (int n = 1; n < taster; n += 2) if (b[n] == 0) count++;
if (((double)count) / taster > threshold) { text = Encoding.Unicode.GetString(b); return Encoding.Unicode; } // (little-endian)


// Finally, a long shot - let's see if we can find "charset=xyz" or
// "encoding=xyz" to identify the encoding:
for (int n = 0; n < taster - 9; n++)
{
if (
((b[n + 0] == 'c' || b[n + 0] == 'C') && (b[n + 1] == 'h' || b[n + 1] == 'H') && (b[n + 2] == 'a' || b[n + 2] == 'A') && (b[n + 3] == 'r' || b[n + 3] == 'R') && (b[n + 4] == 's' || b[n + 4] == 'S') && (b[n + 5] == 'e' || b[n + 5] == 'E') && (b[n + 6] == 't' || b[n + 6] == 'T') && (b[n + 7] == '=')) ||
((b[n + 0] == 'e' || b[n + 0] == 'E') && (b[n + 1] == 'n' || b[n + 1] == 'N') && (b[n + 2] == 'c' || b[n + 2] == 'C') && (b[n + 3] == 'o' || b[n + 3] == 'O') && (b[n + 4] == 'd' || b[n + 4] == 'D') && (b[n + 5] == 'i' || b[n + 5] == 'I') && (b[n + 6] == 'n' || b[n + 6] == 'N') && (b[n + 7] == 'g' || b[n + 7] == 'G') && (b[n + 8] == '='))
)
{
if (b[n + 0] == 'c' || b[n + 0] == 'C') n += 8; else n += 9;
if (b[n] == '"' || b[n] == '\'') n++;
int oldn = n;
while (n < taster && (b[n] == '_' || b[n] == '-' || (b[n] >= '0' && b[n] <= '9') || (b[n] >= 'a' && b[n] <= 'z') || (b[n] >= 'A' && b[n] <= 'Z')))
{ n++; }
byte[] nb = new byte[n - oldn];
Array.Copy(b, oldn, nb, 0, n - oldn);
try
{
string internalEnc = Encoding.ASCII.GetString(nb);
text = Encoding.GetEncoding(internalEnc).GetString(b);
return Encoding.GetEncoding(internalEnc);
}
catch { break; } // If C# doesn't recognize the name of the encoding, break.
}
}


// If all else fails, the encoding is probably (though certainly not
// definitely) the user's local codepage! One might present to the user a
// list of alternative encodings as shown here: http://stackoverflow.com/questions/8509339/what-is-the-most-common-encoding-of-each-language
// A full list can be found using Encoding.GetEncodings();
text = Encoding.Default.GetString(b);
return Encoding.Default;
}
}
}
24 changes: 19 additions & 5 deletions QuickLook.Common/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
@@ -33,9 +33,20 @@ public enum WindowCompositionAttribute
WcaAccentPolicy = 19
}

public static Rect GetCurrentWindowRect()
public static Rect GetCurrentDesktopRect()
{
var screen = Screen.FromPoint(Cursor.Position).WorkingArea;
return GetDesktopRectFromWindow(User32.GetForegroundWindow());
}

public static Rect GetDesktopRectFromWindow(Window window)
{
return GetDesktopRectFromWindow(new WindowInteropHelper(window).Handle);
}

public static Rect GetDesktopRectFromWindow(IntPtr hwnd)
{
var screen = Screen.FromHandle(hwnd).WorkingArea;

var scale = DpiHelper.GetCurrentScaleFactor();
return new Rect(
new Point(screen.X / scale.Horizontal, screen.Y / scale.Vertical),
@@ -45,6 +56,8 @@ public static Rect GetCurrentWindowRect()
public static void BringToFront(this Window window, bool keep)
{
var handle = new WindowInteropHelper(window).Handle;
keep |= window.Topmost;

User32.SetWindowPos(handle, User32.HWND_TOPMOST, 0, 0, 0, 0,
User32.SWP_NOMOVE | User32.SWP_NOSIZE | User32.SWP_NOACTIVATE);

@@ -100,10 +113,11 @@ public static bool IsForegroundWindowBelongToSelf()
return procId == Process.GetCurrentProcess().Id;
}

public static void SetNoactivate(WindowInteropHelper window)
public static void SetNoactivate(this Window window)
{
User32.SetWindowLong(window.Handle, User32.GWL_EXSTYLE,
User32.GetWindowLong(window.Handle, User32.GWL_EXSTYLE) |
var hwnd = new WindowInteropHelper(window);
User32.SetWindowLong(hwnd.Handle, User32.GWL_EXSTYLE,
User32.GetWindowLong(hwnd.Handle, User32.GWL_EXSTYLE) |
User32.WS_EX_NOACTIVATE);
}

159 changes: 159 additions & 0 deletions QuickLook.Common/Helpers/WindowHelper.cs.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// 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;
}
}
}
2 changes: 1 addition & 1 deletion QuickLook.Common/Plugin/ContextObject.cs
Original file line number Diff line number Diff line change
@@ -191,7 +191,7 @@ public double SetPreferredSizeFit(Size size, double maxRatio)
if (maxRatio > 1)
maxRatio = 1;

var max = WindowHelper.GetCurrentWindowRect();
var max = WindowHelper.GetCurrentDesktopRect();

var widthRatio = max.Width * maxRatio / size.Width;
var heightRatio = max.Height * maxRatio / size.Height;
1 change: 1 addition & 0 deletions QuickLook.Common/QuickLook.Common.csproj
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@
<Compile Include="..\GitVersion.cs">
<Link>Properties\GitVersion.cs</Link>
</Compile>
<Compile Include="ExtensionMethods\EncodingExtensions.cs" />
<Compile Include="ExtensionMethods\WindowsThumbnailExtension.cs" />
<Compile Include="Plugin\ContextObject.cs" />
<Compile Include="Helpers\DpiHelper.cs" />
Loading
Oops, something went wrong.

0 comments on commit 72dda7d

Please sign in to comment.