mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 09:49:07 +00:00
detect string encoding when previewing .zip files, fix #24.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -52,13 +52,16 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="SharpCompress, Version=0.17.1.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\SharpCompress.0.17.1\lib\net45\SharpCompress.dll</HintPath>
|
||||
<Reference Include="SharpCompress, Version=0.18.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\SharpCompress.0.18.0\lib\net45\SharpCompress.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="UtfUnknown, Version=1.0.0.0, Culture=neutral, PublicKeyToken=90217ce7a23260d4, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\UTF.Unknown.1.0.0-beta1\lib\net40\UtfUnknown.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -69,6 +72,7 @@
|
||||
<DependentUpon>ArchiveInfoPanel.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ArchiveFileEntry.cs" />
|
||||
<Compile Include="ChardetReaderOptions.cs" />
|
||||
<Compile Include="IconManager.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="Converters.cs" />
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="SharpCompress" version="0.17.1" targetFramework="net462" />
|
||||
<package id="SharpCompress" version="0.18.0" targetFramework="net462" />
|
||||
<package id="UTF.Unknown" version="1.0.0-beta1" targetFramework="net462" />
|
||||
</packages>
|
Reference in New Issue
Block a user