[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:
gokcekantarci
2023-11-14 18:27:45 +03:00
committed by GitHub
parent 59a133b9e2
commit 89a87e6db4
9 changed files with 991 additions and 2 deletions

View File

@@ -4,11 +4,13 @@
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text;
using Common;
using ManagedCommon;
using Microsoft.PowerToys.PreviewHandler.Monaco.Properties;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;
using UtfUnknown;
using Windows.System;
namespace Microsoft.PowerToys.PreviewHandler.Monaco
@@ -358,7 +360,13 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
Logger.LogInfo("Starting getting monaco language id out of filetype");
_vsCodeLangSet = FileHandler.GetLanguage(Path.GetExtension(filePath));
using (StreamReader fileReader = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
DetectionResult result = CharsetDetector.DetectFromFile(filePath);
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 (StreamReader fileReader = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), encodingToUse))
{
Logger.LogInfo("Starting reading requested file");
var fileContent = fileReader.ReadToEnd();