diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs index 12cf528..84f5933 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveInfoPanel.xaml.cs @@ -101,7 +101,7 @@ namespace QuickLook.Plugin.ArchiveViewer if (useReader.Any(i => path.EndsWith(i))) { - var reader = ReaderFactory.Open(stream); + var reader = ReaderFactory.Open(stream, new ChardetReaderOptions()); _type = reader.ArchiveType.ToString(); @@ -113,7 +113,7 @@ namespace QuickLook.Plugin.ArchiveViewer } else { - var archive = ArchiveFactory.Open(stream); + var archive = ArchiveFactory.Open(stream, new ChardetReaderOptions()); _type = archive.Type.ToString(); @@ -138,8 +138,7 @@ namespace QuickLook.Plugin.ArchiveViewer if (_fileEntries.ContainsKey(f)) return; - ArchiveFileEntry parent; - _fileEntries.TryGetValue(GetDirectoryName(f), out parent); + _fileEntries.TryGetValue(GetDirectoryName(f), out ArchiveFileEntry parent); var afe = new ArchiveFileEntry(Path.GetFileName(f), true, parent); @@ -151,8 +150,7 @@ namespace QuickLook.Plugin.ArchiveViewer { var file = pf.Last(); - ArchiveFileEntry parent; - _fileEntries.TryGetValue(GetDirectoryName(file), out parent); + _fileEntries.TryGetValue(GetDirectoryName(file), out ArchiveFileEntry parent); _fileEntries.Add(file, new ArchiveFileEntry(Path.GetFileName(entry.Key), false, parent) { diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ChardetReaderOptions.cs b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ChardetReaderOptions.cs new file mode 100644 index 0000000..87848b7 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ChardetReaderOptions.cs @@ -0,0 +1,47 @@ +// Copyright © 2017 Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Text; +using SharpCompress.Common; +using SharpCompress.Readers; +using UtfUnknown; + +namespace QuickLook.Plugin.ArchiveViewer +{ + internal class ChardetReaderOptions : ReaderOptions + { + public ChardetReaderOptions() + { + ArchiveEncoding = new ArchiveEncoding + { + CustomDecoder = Chardet + }; + } + + public string Chardet(byte[] bytes, int index, int count) + { + var buffer = new byte[count]; + + Array.Copy(bytes, index, buffer, 0, count); + + var encoding = CharsetDetector.DetectFromBytes(buffer).Detected?.Encoding ?? Encoding.Default; + + return encoding.GetString(buffer); + } + } +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/QuickLook.Plugin.ArchiveViewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/QuickLook.Plugin.ArchiveViewer.csproj index 754f932..2a64279 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/QuickLook.Plugin.ArchiveViewer.csproj +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/QuickLook.Plugin.ArchiveViewer.csproj @@ -52,13 +52,16 @@ - - ..\..\packages\SharpCompress.0.17.1\lib\net45\SharpCompress.dll + + ..\..\packages\SharpCompress.0.18.0\lib\net45\SharpCompress.dll + + ..\..\packages\UTF.Unknown.1.0.0-beta1\lib\net40\UtfUnknown.dll + @@ -69,6 +72,7 @@ ArchiveInfoPanel.xaml + diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/packages.config b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/packages.config index 94fa7cd..08a41ee 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/packages.config +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/packages.config @@ -1,4 +1,5 @@  - + + \ No newline at end of file