mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-10-19 10:07:38 +00:00
Fix long path handling issue in HtmlViewer #1643
This commit is contained in:
@@ -200,22 +200,4 @@ public class WebfontPanel : WebpagePanel
|
|||||||
using var reader = new StreamReader(ReadStream(key), Encoding.UTF8);
|
using var reader = new StreamReader(ReadStream(key), Encoding.UTF8);
|
||||||
return reader.ReadToEnd();
|
return reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MimeTypes
|
|
||||||
{
|
|
||||||
public const string Html = "text/html";
|
|
||||||
public const string JavaScript = "application/javascript";
|
|
||||||
public const string Css = "text/css";
|
|
||||||
public const string Binary = "application/octet-stream";
|
|
||||||
|
|
||||||
public static string GetContentType(string extension = null) => $"Content-Type: {GetMimeType(extension)}";
|
|
||||||
|
|
||||||
public static string GetMimeType(string extension = null) => extension?.ToLowerInvariant() switch
|
|
||||||
{
|
|
||||||
".js" => JavaScript, // Only handle known extensions from resources
|
|
||||||
".css" => Css,
|
|
||||||
".html" => Html,
|
|
||||||
_ => Binary,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -58,6 +58,7 @@ public class Plugin : IViewer
|
|||||||
|
|
||||||
if (path.ToLower().EndsWith(".url"))
|
if (path.ToLower().EndsWith(".url"))
|
||||||
path = Helper.GetUrlPath(path);
|
path = Helper.GetUrlPath(path);
|
||||||
|
_panel.FallbackPath = Path.GetDirectoryName(path); // Reserve opportunities for requesting exceeds MAX_PATH (260) limitation
|
||||||
_panel.NavigateToFile(path);
|
_panel.NavigateToFile(path);
|
||||||
_panel.Dispatcher.Invoke(() => { context.IsBusy = false; }, DispatcherPriority.Loaded);
|
_panel.Dispatcher.Invoke(() => { context.IsBusy = false; }, DispatcherPriority.Loaded);
|
||||||
}
|
}
|
||||||
|
@@ -191,8 +191,10 @@ public class WebpagePanel : UserControl
|
|||||||
{
|
{
|
||||||
var requestedUri = new Uri(args.Request.Uri);
|
var requestedUri = new Uri(args.Request.Uri);
|
||||||
|
|
||||||
|
if (requestedUri.Scheme == "file")
|
||||||
|
{
|
||||||
// Check if the request is for a local file
|
// Check if the request is for a local file
|
||||||
if (requestedUri.Scheme == "file" && !File.Exists(requestedUri.LocalPath))
|
if (!File.Exists(requestedUri.LocalPath))
|
||||||
{
|
{
|
||||||
// Try loading from fallback directory
|
// Try loading from fallback directory
|
||||||
var fileName = Path.GetFileName(requestedUri.LocalPath);
|
var fileName = Path.GetFileName(requestedUri.LocalPath);
|
||||||
@@ -217,6 +219,18 @@ public class WebpagePanel : UserControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check if the request exceeds MAX_PATH (260) limitation
|
||||||
|
else if (requestedUri.LocalPath.Length >= 260)
|
||||||
|
{
|
||||||
|
if (File.Exists(requestedUri.LocalPath))
|
||||||
|
{
|
||||||
|
var fileStream = new FileStream(requestedUri.LocalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
|
||||||
|
var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
|
||||||
|
fileStream, 200, "OK", MimeTypes.GetContentType(Path.GetExtension(requestedUri.LocalPath)));
|
||||||
|
args.Response = response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -245,4 +259,78 @@ public class WebpagePanel : UserControl
|
|||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class MimeTypes
|
||||||
|
{
|
||||||
|
public const string Html = "text/html";
|
||||||
|
public const string JavaScript = "application/javascript";
|
||||||
|
public const string Css = "text/css";
|
||||||
|
public const string Json = "application/json";
|
||||||
|
public const string Xml = "application/xml";
|
||||||
|
public const string Svg = "image/svg+xml";
|
||||||
|
public const string Png = "image/png";
|
||||||
|
public const string Jpeg = "image/jpeg";
|
||||||
|
public const string Gif = "image/gif";
|
||||||
|
public const string Webp = "image/webp";
|
||||||
|
public const string Ico = "image/x-icon";
|
||||||
|
public const string Avif = "image/avif";
|
||||||
|
public const string Woff = "font/woff";
|
||||||
|
public const string Woff2 = "font/woff2";
|
||||||
|
public const string Ttf = "font/ttf";
|
||||||
|
public const string Otf = "font/otf";
|
||||||
|
public const string Mp3 = "audio/mpeg";
|
||||||
|
public const string Mp4 = "video/mp4";
|
||||||
|
public const string Webm = "video/webm";
|
||||||
|
public const string Pdf = "application/pdf";
|
||||||
|
public const string Binary = "application/octet-stream";
|
||||||
|
public const string Text = "text/plain";
|
||||||
|
|
||||||
|
public static string GetContentType(string extension = null) => $"Content-Type: {GetMimeType(extension)}";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Only handle known extensions from resources
|
||||||
|
/// </summary>
|
||||||
|
public static string GetMimeType(string extension = null) => extension?.ToLowerInvariant() switch
|
||||||
|
{
|
||||||
|
// Core web files
|
||||||
|
".html" or ".htm" => Html,
|
||||||
|
".js" => JavaScript,
|
||||||
|
".css" => Css,
|
||||||
|
".json" => Json,
|
||||||
|
".xml" => Xml,
|
||||||
|
|
||||||
|
// Images
|
||||||
|
".png" => Png,
|
||||||
|
".jpg" or ".jpeg" => Jpeg,
|
||||||
|
".gif" => Gif,
|
||||||
|
".webp" => Webp,
|
||||||
|
".svg" => Svg,
|
||||||
|
".ico" => Ico,
|
||||||
|
".avif" => Avif,
|
||||||
|
|
||||||
|
// Fonts
|
||||||
|
".woff" => Woff,
|
||||||
|
".woff2" => Woff2,
|
||||||
|
".ttf" => Ttf,
|
||||||
|
".otf" => Otf,
|
||||||
|
|
||||||
|
// Media
|
||||||
|
".mp3" => Mp3,
|
||||||
|
".mp4" => Mp4,
|
||||||
|
".webm" => Webm,
|
||||||
|
|
||||||
|
// Documents
|
||||||
|
".pdf" => Pdf,
|
||||||
|
".txt" => Text,
|
||||||
|
|
||||||
|
// Archives
|
||||||
|
".zip" => "application/zip",
|
||||||
|
".gz" => "application/gzip",
|
||||||
|
".rar" => "application/vnd.rar",
|
||||||
|
".7z" => "application/x-7z-compressed",
|
||||||
|
|
||||||
|
// Default
|
||||||
|
_ => Binary,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user