mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #4004 from dcog989/404-local-file-crash
Crash when opening non-existent local file
This commit is contained in:
commit
1e8819af0c
3 changed files with 34 additions and 12 deletions
|
|
@ -150,6 +150,16 @@ namespace Flow.Launcher.Plugin.SharedCommands
|
||||||
return File.Exists(filePath);
|
return File.Exists(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if a file or directory exists
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool FileOrLocationExists(this string path)
|
||||||
|
{
|
||||||
|
return LocationExists(path) || FileExists(path);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Open a directory window (using the OS's default handler, usually explorer)
|
/// Open a directory window (using the OS's default handler, usually explorer)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -590,6 +590,7 @@
|
||||||
<system:String x:Key="errorTitle">Error</system:String>
|
<system:String x:Key="errorTitle">Error</system:String>
|
||||||
<system:String x:Key="folderOpenError">An error occurred while opening the folder. {0}</system:String>
|
<system:String x:Key="folderOpenError">An error occurred while opening the folder. {0}</system:String>
|
||||||
<system:String x:Key="browserOpenError">An error occurred while opening the URL in the browser. Please check your Default Web Browser configuration in the General section of the settings window</system:String>
|
<system:String x:Key="browserOpenError">An error occurred while opening the URL in the browser. Please check your Default Web Browser configuration in the General section of the settings window</system:String>
|
||||||
|
<system:String x:Key="fileNotFoundError">File or directory not found: {0}</system:String>
|
||||||
|
|
||||||
<!-- General Notice -->
|
<!-- General Notice -->
|
||||||
<system:String x:Key="pleaseWait">Please wait...</system:String>
|
<system:String x:Key="pleaseWait">Please wait...</system:String>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
|
|
@ -74,7 +74,6 @@ namespace Flow.Launcher
|
||||||
_mainVM.ChangeQueryText(query, requery);
|
_mainVM.ChangeQueryText(query, requery);
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]
|
|
||||||
public void RestartApp()
|
public void RestartApp()
|
||||||
{
|
{
|
||||||
_mainVM.Hide();
|
_mainVM.Hide();
|
||||||
|
|
@ -179,7 +178,7 @@ namespace Flow.Launcher
|
||||||
|
|
||||||
Clipboard.SetFileDropList(paths);
|
Clipboard.SetFileDropList(paths);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exception == null)
|
if (exception == null)
|
||||||
{
|
{
|
||||||
if (showDefaultNotification)
|
if (showDefaultNotification)
|
||||||
|
|
@ -218,7 +217,7 @@ namespace Flow.Launcher
|
||||||
{
|
{
|
||||||
LogException(nameof(PublicAPIInstance), "Failed to copy text to clipboard", exception);
|
LogException(nameof(PublicAPIInstance), "Failed to copy text to clipboard", exception);
|
||||||
ShowMsgError(GetTranslation("failedToCopy"));
|
ShowMsgError(GetTranslation("failedToCopy"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -327,7 +326,7 @@ namespace Flow.Launcher
|
||||||
|
|
||||||
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
|
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null)
|
public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -412,6 +411,12 @@ namespace Flow.Launcher
|
||||||
|
|
||||||
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
|
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
|
||||||
{
|
{
|
||||||
|
if (uri.IsFile && !FilesFolders.FileOrLocationExists(uri.LocalPath))
|
||||||
|
{
|
||||||
|
ShowMsgError(GetTranslation("errorTitle"), string.Format(GetTranslation("fileNotFoundError"), uri.LocalPath));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (forceBrowser || uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
|
if (forceBrowser || uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
|
||||||
{
|
{
|
||||||
var browserInfo = _settings.CustomBrowser;
|
var browserInfo = _settings.CustomBrowser;
|
||||||
|
|
@ -441,13 +446,19 @@ namespace Flow.Launcher
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Process.Start(new ProcessStartInfo()
|
try
|
||||||
{
|
{
|
||||||
FileName = uri.AbsoluteUri,
|
Process.Start(new ProcessStartInfo()
|
||||||
UseShellExecute = true
|
{
|
||||||
})?.Dispose();
|
FileName = uri.AbsoluteUri,
|
||||||
|
UseShellExecute = true
|
||||||
return;
|
})?.Dispose();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogException(ClassName, $"Failed to open: {uri.AbsoluteUri}", e);
|
||||||
|
ShowMsgError(GetTranslation("errorTitle"), e.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -481,7 +492,7 @@ namespace Flow.Launcher
|
||||||
OpenUri(appUri);
|
OpenUri(appUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToggleGameMode()
|
public void ToggleGameMode()
|
||||||
{
|
{
|
||||||
_mainVM.ToggleGameMode();
|
_mainVM.ToggleGameMode();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue