mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 02:09:05 +00:00
working on HtmlViewer
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user