working on HtmlViewer

This commit is contained in:
Paddy Xu
2017-05-13 19:34:41 +03:00
parent 9e64e068d0
commit 3f82070deb
20 changed files with 637 additions and 126 deletions

View File

@@ -0,0 +1,54 @@
using System;
using System.IO;
using System.Text;
using System.Windows.Controls;
namespace QuickLook.Plugin.HtmlViewer
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class WebkitPanel : UserControl
{
public WebkitPanel()
{
InitializeComponent();
}
public void Navigate(string path)
{
//path = "http://pooi.moe/QuickLook";
if (Path.IsPathRooted(path))
path = FilePathToFileUrl(path);
browser.Loaded += (sender, e) => browser.Navigate(path);
}
private static string FilePathToFileUrl(string filePath)
{
StringBuilder uri = new StringBuilder();
foreach (char 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')
{
uri.Append(v);
}
else if (v == Path.DirectorySeparatorChar || v == Path.AltDirectorySeparatorChar)
{
uri.Append('/');
}
else
{
uri.Append($"%{(int) v:X2}");
}
}
if (uri.Length >= 2 && uri[0] == '/' && uri[1] == '/') // UNC path
uri.Insert(0, "file:");
else
uri.Insert(0, "file:///");
return uri.ToString();
}
}
}