diff --git a/src/modules/Hosts/HostsUILib/Helpers/HostsService.cs b/src/modules/Hosts/HostsUILib/Helpers/HostsService.cs index 9b16e04f20..0746f93f5c 100644 --- a/src/modules/Hosts/HostsUILib/Helpers/HostsService.cs +++ b/src/modules/Hosts/HostsUILib/Helpers/HostsService.cs @@ -16,7 +16,6 @@ using System.Threading.Tasks; using HostsUILib.Exceptions; using HostsUILib.Models; using HostsUILib.Settings; -using Microsoft.Win32; namespace HostsUILib.Helpers { @@ -223,64 +222,17 @@ namespace HostsUILib.Helpers public void OpenHostsFile() { - var notepadFallback = false; - try { - // Try to open in default editor - var key = Registry.ClassesRoot.OpenSubKey("SystemFileAssociations\\text\\shell\\edit\\command"); - if (key != null) - { - var commandPattern = key.GetValue(string.Empty).ToString(); // Default value - var file = null as string; - var args = null as string; - - if (commandPattern.StartsWith('\"')) - { - var endQuoteIndex = commandPattern.IndexOf('\"', 1); - if (endQuoteIndex != -1) - { - file = commandPattern[1..endQuoteIndex]; - args = commandPattern[(endQuoteIndex + 1)..].Trim(); - } - } - else - { - var spaceIndex = commandPattern.IndexOf(' '); - if (spaceIndex != -1) - { - file = commandPattern[..spaceIndex]; - args = commandPattern[(spaceIndex + 1)..].Trim(); - } - } - - if (file != null && args != null) - { - args = args.Replace("%1", HostsFilePath); - Process.Start(new ProcessStartInfo(file, args)); - } - else - { - notepadFallback = true; - } - } + var notepadPath = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.Windows), + "System32", + "notepad.exe"); + Process.Start(new ProcessStartInfo(notepadPath, HostsFilePath)); } catch (Exception ex) { - LoggerInstance.Logger.LogError("Failed to open default editor", ex); - notepadFallback = true; - } - - if (notepadFallback) - { - try - { - Process.Start(new ProcessStartInfo("notepad.exe", HostsFilePath)); - } - catch (Exception ex) - { - LoggerInstance.Logger.LogError("Failed to open notepad", ex); - } + LoggerInstance.Logger.LogError("Failed to open notepad", ex); } }