mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[Peek]Peek and Monaco file encoding issues are solved with a encoding detector (#26955)
* [Peek] Peek and Monaco file encoding issues are solved with a encoding detector. * [Peek] Monaco encoding parameter is moved to another function. * [Peek] NOTICE.md update. * [Peek] Spell Check update. * UTF-Unknown is added to Nuget list in Notice.md * System.Text.Encoding.CodePages is added to Nuget list in Notice.md * [Peek] Unncessary mainfest files are deleted. * [Peek ] Unncessary mainfest file are deleted. * [Peek] Encoding null check is added. * Update NOTICE.md * Update NOTICE.md * ci: Add signing to UtfUnknown
This commit is contained in:
@@ -31,6 +31,8 @@
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
||||
<PackageReference Include="SharpCompress" />
|
||||
<PackageReference Include="System.Drawing.Common" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" />
|
||||
<PackageReference Include="UTF.Unknown" />
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UtfUnknown;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers
|
||||
{
|
||||
@@ -12,8 +13,14 @@ namespace Peek.FilePreviewer.Previewers
|
||||
{
|
||||
public static async Task<string> Read(string path)
|
||||
{
|
||||
DetectionResult result = CharsetDetector.DetectFromFile(path);
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
|
||||
// Check if the detected encoding is not null, otherwise default to UTF-8
|
||||
Encoding encodingToUse = result.Detected?.Encoding ?? Encoding.UTF8;
|
||||
|
||||
using var fs = OpenReadOnly(path);
|
||||
using var sr = new StreamReader(fs, Encoding.UTF8);
|
||||
using var sr = new StreamReader(fs, encodingToUse);
|
||||
|
||||
string content = await sr.ReadToEndAsync();
|
||||
return content;
|
||||
|
||||
Reference in New Issue
Block a user