diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs index 77e112e..8d976e0 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs @@ -18,7 +18,6 @@ using System.IO; using System.Windows; using ICSharpCode.AvalonEdit.Highlighting; -using UtfUnknown; namespace QuickLook.Plugin.TextViewer { @@ -47,14 +46,14 @@ namespace QuickLook.Plugin.TextViewer if (HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(path)) != null) return new FileInfo(path).Length <= MAX_SIZE; - // otherwise, read the first 10KB, check if we can get something. - using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + // otherwise, read the first 512KB, check if we can get something. + using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { - const int bufferLength = 10 * 1024; + const int bufferLength = 512 * 1024; var buffer = new byte[bufferLength]; - s.Read(buffer, 0, bufferLength); + var size = s.Read(buffer, 0, bufferLength); - return CharsetDetector.DetectFromBytes(buffer).Detected != null && s.Length <= MAX_SIZE; + return IsText(buffer, size) && new FileInfo(path).Length <= MAX_SIZE; } } @@ -78,5 +77,14 @@ namespace QuickLook.Plugin.TextViewer { _tvp.viewer = null; } + + private bool IsText(byte[] buffer, int size) + { + for (var i = 1; i < size; i++) + if (buffer[i - 1] == 0 && buffer[i] == 0) + return false; + + return true; + } } } \ No newline at end of file