mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-10 09:19:06 +00:00
Fix CSV viewer not support formats other than UTF8
This may have the disadvantage of slowing down the startup speed of large CSV files.
This commit is contained in:
@@ -22,10 +22,12 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using UtfUnknown;
|
||||||
|
|
||||||
namespace QuickLook.Plugin.CsvViewer;
|
namespace QuickLook.Plugin.CsvViewer;
|
||||||
|
|
||||||
@@ -39,14 +41,17 @@ public partial class CsvViewerPanel : UserControl
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string[]> Rows { get; private set; } = new List<string[]>();
|
public List<string[]> Rows { get; private set; } = [];
|
||||||
|
|
||||||
public void LoadFile(string path)
|
public void LoadFile(string path)
|
||||||
{
|
{
|
||||||
const int limit = 10000;
|
const int limit = 10000;
|
||||||
var binded = false;
|
var binded = false;
|
||||||
|
|
||||||
using (var sr = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
|
var encoding = CharsetDetector.DetectFromFile(path).Detected?.Encoding ??
|
||||||
|
Encoding.Default;
|
||||||
|
|
||||||
|
using (var sr = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), encoding))
|
||||||
{
|
{
|
||||||
var conf = new CsvConfiguration(CultureInfo.CurrentUICulture) { MissingFieldFound = null, BadDataFound = null, DetectDelimiter = true };
|
var conf = new CsvConfiguration(CultureInfo.CurrentUICulture) { MissingFieldFound = null, BadDataFound = null, DetectDelimiter = true };
|
||||||
|
|
||||||
@@ -58,7 +63,7 @@ public partial class CsvViewerPanel : UserControl
|
|||||||
var row = parser.Record;
|
var row = parser.Record;
|
||||||
if (row == null)
|
if (row == null)
|
||||||
break;
|
break;
|
||||||
row = Concat(new[] { $"{i++ + 1}".PadLeft(6) }, row);
|
row = Concat([$"{i++ + 1}".PadLeft(6)], row);
|
||||||
|
|
||||||
if (!binded)
|
if (!binded)
|
||||||
{
|
{
|
||||||
|
@@ -52,7 +52,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CsvHelper" Version="27.1.1" />
|
<PackageReference Include="CsvHelper" Version="33.0.1" />
|
||||||
|
<PackageReference Include="UTF.Unknown" Version="2.5.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Reference in New Issue
Block a user