mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
[MonacoPreview]Fix crash with FileNotFoundException (#31853)
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user