mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 18:39:45 +00:00
Improve PDF magic detection
This commit is contained in:
@@ -26,8 +26,7 @@ namespace QuickLook.Plugin.PDFViewer;
|
|||||||
internal class AsyncPageToThumbnailConverter : IMultiValueConverter
|
internal class AsyncPageToThumbnailConverter : IMultiValueConverter
|
||||||
{
|
{
|
||||||
private static readonly BitmapImage Loading =
|
private static readonly BitmapImage Loading =
|
||||||
new BitmapImage(
|
new(new Uri("pack://application:,,,/QuickLook.Plugin.PdfViewer;component/Resources/loading.png"));
|
||||||
new Uri("pack://application:,,,/QuickLook.Plugin.PdfViewer;component/Resources/loading.png"));
|
|
||||||
|
|
||||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
|
@@ -22,7 +22,6 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
@@ -46,13 +45,16 @@ public class Plugin : IViewer
|
|||||||
if (Directory.Exists(path))
|
if (Directory.Exists(path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (File.Exists(path) && Path.GetExtension(path).ToLower() == ".pdf")
|
if (File.Exists(path) && Path.GetExtension(path).EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
using (var br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
|
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||||
{
|
byte[] buffer = new byte[4];
|
||||||
return Encoding.ASCII.GetString(br.ReadBytes(4)) == "%PDF";
|
if (fs.Read(buffer, 0, 4) < 4) return false;
|
||||||
}
|
return buffer[0] == (byte)'%' &&
|
||||||
|
buffer[1] == (byte)'P' &&
|
||||||
|
buffer[2] == (byte)'D' &&
|
||||||
|
buffer[3] == (byte)'F';
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Prepare(string path, ContextObject context)
|
public void Prepare(string path, ContextObject context)
|
||||||
|
Reference in New Issue
Block a user