mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 02:09:05 +00:00
Fix #539: replace IE WebView with Edge WebView2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright © 2017 Paddy Xu
|
||||
// Copyright © 2021 Paddy Xu and mooflu
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
@@ -15,6 +15,7 @@
|
||||
// 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.Text;
|
||||
using Microsoft.Win32;
|
||||
@@ -23,13 +24,26 @@ namespace QuickLook.Plugin.HtmlViewer
|
||||
{
|
||||
internal static class Helper
|
||||
{
|
||||
public static string FilePathToFileUrl(string filePath)
|
||||
public static bool IsWebView2Available()
|
||||
{
|
||||
var path = App.Is64Bit
|
||||
? @"SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}\"
|
||||
: @"SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}\";
|
||||
|
||||
using (var key = Registry.LocalMachine.OpenSubKey(path, RegistryKeyPermissionCheck.ReadSubTree))
|
||||
{
|
||||
var pv = key?.GetValue("pv");
|
||||
return !string.IsNullOrEmpty(pv as string);
|
||||
}
|
||||
}
|
||||
|
||||
public static Uri FilePathToFileUrl(string filePath)
|
||||
{
|
||||
var uri = new StringBuilder();
|
||||
foreach (var v in filePath)
|
||||
if (v >= 'a' && v <= 'z' || v >= 'A' && v <= 'Z' || v >= '0' && v <= '9' ||
|
||||
v == '+' || v == '/' || v == ':' || v == '.' || v == '-' || v == '_' || v == '~' ||
|
||||
v > '\xFF')
|
||||
v > '\x80')
|
||||
uri.Append(v);
|
||||
else if (v == Path.DirectorySeparatorChar || v == Path.AltDirectorySeparatorChar)
|
||||
uri.Append('/');
|
||||
@@ -39,48 +53,34 @@ namespace QuickLook.Plugin.HtmlViewer
|
||||
uri.Insert(0, "file:");
|
||||
else
|
||||
uri.Insert(0, "file:///");
|
||||
return uri.ToString();
|
||||
}
|
||||
|
||||
public static void SetBrowserFeatureControl()
|
||||
{
|
||||
var exeName = Path.GetFileName(App.AppFullPath);
|
||||
|
||||
// use latest engine
|
||||
SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", exeName, 0);
|
||||
//
|
||||
SetBrowserFeatureControlKey("FEATURE_GPU_RENDERING", exeName, 0);
|
||||
// turn on hi-dpi mode
|
||||
SetBrowserFeatureControlKey("FEATURE_96DPI_PIXEL", exeName, 1);
|
||||
}
|
||||
|
||||
private static void SetBrowserFeatureControlKey(string feature, string appName, uint value)
|
||||
{
|
||||
using (var key = Registry.CurrentUser.CreateSubKey(
|
||||
string.Concat(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature),
|
||||
RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||
try
|
||||
{
|
||||
key?.SetValue(appName, value, RegistryValueKind.DWord);
|
||||
return new Uri(uri.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetUrlPath(string url)
|
||||
{
|
||||
int index = -1;
|
||||
string[] lines = File.ReadAllLines(url);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
var index = -1;
|
||||
var lines = File.ReadAllLines(url);
|
||||
foreach (var line in lines)
|
||||
if (line.ToLower().Contains("url="))
|
||||
{
|
||||
index = System.Array.IndexOf(lines, line);
|
||||
index = Array.IndexOf(lines, line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
var fullLine = lines.GetValue(index);
|
||||
return fullLine.ToString().Substring(fullLine.ToString().LastIndexOf('=') + 1);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user