mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-16 02:13:39 +12:00
[BUG] IndexOutOfRangeException when BrowserSelector as Standard browser (#237), version 1.1.1.3
This commit is contained in:
parent
b7a7364b40
commit
b1226d15a1
|
@ -642,13 +642,8 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
IconReader.MainPreload = true;
|
||||
|
||||
if (FileUrl.GetDefaultBrowserPath(out string browserPath))
|
||||
{
|
||||
IconReader.GetFileIconWithCache(browserPath, true, true, true, out _);
|
||||
}
|
||||
|
||||
timerShowProcessStartedAsLoadingIcon.Tick += Tick;
|
||||
timerShowProcessStartedAsLoadingIcon.Interval = 50;
|
||||
timerShowProcessStartedAsLoadingIcon.Interval = 5;
|
||||
timerShowProcessStartedAsLoadingIcon.Start();
|
||||
void Tick(object sender, EventArgs e)
|
||||
{
|
||||
|
|
|
@ -104,10 +104,7 @@ namespace SystemTrayMenu
|
|||
|
||||
internal static void ShowHelpFAQ()
|
||||
{
|
||||
if (FileUrl.GetDefaultBrowserPath(out string browserPath))
|
||||
{
|
||||
Process.Start(browserPath, "https://github.com/Hofknecht/SystemTrayMenu#FAQ");
|
||||
}
|
||||
Log.ProcessStart("https://github.com/Hofknecht/SystemTrayMenu#FAQ");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -112,7 +112,7 @@ namespace SystemTrayMenu.DataClasses
|
|||
}
|
||||
else if (fileExtension == ".url")
|
||||
{
|
||||
handled = SetUrl(level);
|
||||
SetText($"{FileInfo.Name[0..^4]}");
|
||||
showOverlay = true;
|
||||
}
|
||||
else if (fileExtension == ".sln")
|
||||
|
@ -290,46 +290,6 @@ namespace SystemTrayMenu.DataClasses
|
|||
return handled;
|
||||
}
|
||||
|
||||
private bool SetUrl(int level)
|
||||
{
|
||||
bool handled = false;
|
||||
string iconFile = string.Empty;
|
||||
try
|
||||
{
|
||||
FileIni file = new(TargetFilePath);
|
||||
iconFile = file.Value("IconFile", string.Empty);
|
||||
if (string.IsNullOrEmpty(iconFile))
|
||||
{
|
||||
if (FileUrl.GetDefaultBrowserPath(out string browserPath))
|
||||
{
|
||||
FilePathIcon = browserPath;
|
||||
icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, level == 0, out bool loading);
|
||||
IconLoading = loading;
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if (File.Exists(iconFile))
|
||||
{
|
||||
FilePathIcon = iconFile;
|
||||
icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, level == 0, out bool loading);
|
||||
IconLoading = loading;
|
||||
handled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Info($"Resolve *.URL '{TargetFilePath}' has no icon");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warn($"path:'{TargetFilePath}', iconFile:'{iconFile}'", ex);
|
||||
}
|
||||
|
||||
SetText($"{FileInfo.Name[0..^4]}");
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
private bool SetSln(int level)
|
||||
{
|
||||
bool handled = false;
|
||||
|
|
|
@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.1.2")]
|
||||
[assembly: AssemblyFileVersion("1.1.1.2")]
|
||||
[assembly: AssemblyVersion("1.1.1.3")]
|
||||
[assembly: AssemblyFileVersion("1.1.1.3")]
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
// <copyright file="FileIni.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace SystemTrayMenu.Utilities
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
public class FileIni
|
||||
{
|
||||
private readonly Dictionary<string, string> values;
|
||||
|
||||
public FileIni(string path)
|
||||
{
|
||||
values = File.ReadLines(path)
|
||||
.Where(line => !string.IsNullOrWhiteSpace(line) &&
|
||||
!line.StartsWith("#", System.StringComparison.InvariantCulture))
|
||||
.Select(line => line.Split(new char[] { '=' }, 2, 0))
|
||||
.ToDictionary(parts => parts[0].Trim(), parts =>
|
||||
parts.Length > 1 ? parts[1].Trim() : null);
|
||||
}
|
||||
|
||||
public string Value(string name, string value = null)
|
||||
{
|
||||
if (values != null && values.ContainsKey(name))
|
||||
{
|
||||
return values[name];
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
// <copyright file="FileUrl.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace SystemTrayMenu.Utilities
|
||||
{
|
||||
using Microsoft.Win32;
|
||||
|
||||
public static class FileUrl
|
||||
{
|
||||
private static string browserPath = string.Empty;
|
||||
|
||||
public static bool GetDefaultBrowserPath(out string browserPath)
|
||||
{
|
||||
bool valid = true;
|
||||
string urlAssociation = @"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http";
|
||||
string browserPathKey = @"$BROWSER$\shell\open\command";
|
||||
|
||||
RegistryKey userChoiceKey;
|
||||
browserPath = FileUrl.browserPath;
|
||||
|
||||
if (string.IsNullOrEmpty(browserPath))
|
||||
{
|
||||
// Read default browser path from userChoiceLKey
|
||||
userChoiceKey = Registry.CurrentUser.OpenSubKey(urlAssociation + @"\UserChoice", false);
|
||||
|
||||
// If user choice was not found, try machine default
|
||||
if (userChoiceKey == null)
|
||||
{
|
||||
// Read default browser path from Win XP registry key
|
||||
RegistryKey browserKey = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command", false);
|
||||
|
||||
// If browser path wasn’t found, try Win Vista (and newer) registry key
|
||||
if (browserKey == null)
|
||||
{
|
||||
browserKey =
|
||||
Registry.CurrentUser.OpenSubKey(
|
||||
urlAssociation, false);
|
||||
}
|
||||
|
||||
if (browserKey != null)
|
||||
{
|
||||
string path = CleanifyBrowserPath(browserKey.GetValue(null) as string);
|
||||
browserKey.Close();
|
||||
browserPath = path;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// user defined browser choice was found
|
||||
string progId = userChoiceKey.GetValue("ProgId").ToString();
|
||||
userChoiceKey.Close();
|
||||
|
||||
// now look up the path of the executable
|
||||
string concreteBrowserKey = browserPathKey.Replace("$BROWSER$", progId, System.StringComparison.InvariantCulture);
|
||||
RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(concreteBrowserKey, false);
|
||||
if (registryKey != null)
|
||||
{
|
||||
browserPath = CleanifyBrowserPath(registryKey.GetValue(null) as string);
|
||||
registryKey.Close();
|
||||
}
|
||||
}
|
||||
|
||||
FileUrl.browserPath = browserPath;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(browserPath))
|
||||
{
|
||||
valid = false;
|
||||
Log.Info($"No default browser found!");
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
private static string CleanifyBrowserPath(string p)
|
||||
{
|
||||
string[] url = p.Split('"');
|
||||
string clean = url[1];
|
||||
return clean;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue