Skip to content

Commit bfd10f6

Browse files
committed
Crash when opening non-existent file
1 parent 7de420e commit bfd10f6

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,14 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
412412

413413
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
414414
{
415+
if (uri.IsFile)
416+
{
417+
if (!File.Exists(uri.LocalPath) && !Directory.Exists(uri.LocalPath))
418+
{
419+
ShowMsgError(GetTranslation("errorTitle"), $"File or directory not found: {uri.LocalPath}");
420+
return;
421+
}
422+
}
415423
if (forceBrowser || uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
416424
{
417425
var browserInfo = _settings.CustomBrowser;
@@ -441,13 +449,19 @@ private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
441449
}
442450
else
443451
{
444-
Process.Start(new ProcessStartInfo()
452+
try
445453
{
446-
FileName = uri.AbsoluteUri,
447-
UseShellExecute = true
448-
})?.Dispose();
449-
450-
return;
454+
Process.Start(new ProcessStartInfo()
455+
{
456+
FileName = uri.AbsoluteUri,
457+
UseShellExecute = true
458+
})?.Dispose();
459+
}
460+
catch (Exception e)
461+
{
462+
LogException(ClassName, $"Failed to open: {uri.AbsoluteUri}", e);
463+
ShowMsgError(GetTranslation("errorTitle"), e.Message);
464+
}
451465
}
452466
}
453467

0 commit comments

Comments
 (0)