Use URI class to detect web URL

This commit is contained in:
Garulf 2022-09-21 12:01:58 -04:00
parent b5c212504a
commit d62d710878
2 changed files with 8 additions and 2 deletions

View file

@ -114,7 +114,10 @@ namespace Flow.Launcher.Infrastructure.Image
{
return new ImageResult(ImageCache[path], ImageType.Cache);
}
if (path.StartsWith("http://") || path.StartsWith("https://"))
Uri uriResult;
bool IsUriScheme = Uri.TryCreate(path, UriKind.Absolute, out uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
if (IsUriScheme)
{
// Download image from url
using (WebClient client = new WebClient())

View file

@ -130,8 +130,11 @@ namespace Flow.Launcher.Plugin
get { return _pluginDirectory; }
set
{
Uri uriResult;
bool IsUriScheme = Uri.TryCreate(IcoPath, UriKind.Absolute, out uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
_pluginDirectory = value;
if (!string.IsNullOrEmpty(IcoPath) && !Path.IsPathRooted(IcoPath) && !IcoPath.StartsWith("http://") && !IcoPath.StartsWith("https://"))
if (!string.IsNullOrEmpty(IcoPath) && !Path.IsPathRooted(IcoPath) && !IsUriScheme)
{
IcoPath = Path.Combine(value, IcoPath);
}