[MonacoPreview]Fix crash with FileNotFoundException (#31853)

This commit is contained in:
Jaime Bernardo
2024-03-11 17:24:42 +00:00
committed by GitHub
parent ac9159b9f1
commit 8189c52e39

View File

@@ -109,6 +109,8 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
_webView = new WebView2();
_webView.DefaultBackgroundColor = Color.Transparent;
try
{
// Checks if dataSource is a string
if (!(dataSource is string filePath))
{
@@ -119,8 +121,6 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
long fileSize = new FileInfo(filePath).Length;
if (fileSize < _settings.MaxFileSize)
{
try
{
InitializeIndexFileAndSelectedFile(filePath);
@@ -197,6 +197,12 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
}
});
}
else
{
Logger.LogInfo("File is too big to display. Showing error message");
AddTextBoxControl(Resources.Max_File_Size_Error.Replace("%1", (_settings.MaxFileSize / 1000).ToString(CultureInfo.CurrentCulture), StringComparison.InvariantCulture));
}
}
catch (UnauthorizedAccessException e)
{
Logger.LogError(e.Message);
@@ -214,12 +220,6 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
this.Resize += FormResize;
}
else
{
Logger.LogInfo("File is too big to display. Showing error message");
AddTextBoxControl(Resources.Max_File_Size_Error.Replace("%1", (_settings.MaxFileSize / 1000).ToString(CultureInfo.CurrentCulture), StringComparison.InvariantCulture));
}
}
private async void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
{