diff --git a/CreamInstaller/Utility/Diagnostics.cs b/CreamInstaller/Utility/Diagnostics.cs index 0f03d77..fabc564 100644 --- a/CreamInstaller/Utility/Diagnostics.cs +++ b/CreamInstaller/Utility/Diagnostics.cs @@ -1,10 +1,43 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; +using System.IO; + +using Microsoft.Win32; namespace CreamInstaller.Utility; internal static class Diagnostics { - internal static void OpenFileInNotepad(string path) => Process.Start(new ProcessStartInfo + private static string notepadPlusPlusPath; + internal static string NotepadPlusPlusPath + { + get + { + notepadPlusPlusPath ??= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Notepad++", "", null) as string; + notepadPlusPlusPath ??= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432NODE\Notepad++", "", null) as string; + return notepadPlusPlusPath; + } + } + + internal static string GetNotepadPath() => NotepadPlusPlusPath is not null ? NotepadPlusPlusPath + @"\notepad++.exe" + : Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\notepad.exe"; + + internal static void OpenFileInNotepad(string path) + { + string npp = NotepadPlusPlusPath + @"\notepad++.exe"; + if (Directory.Exists(NotepadPlusPlusPath) && File.Exists(npp)) + OpenFileInNotepadPlusPlus(npp, path); + else + OpenFileInWindowsNotepad(path); + } + + private static void OpenFileInNotepadPlusPlus(string npp, string path) => Process.Start(new ProcessStartInfo + { + FileName = npp, + Arguments = path + }); + + private static void OpenFileInWindowsNotepad(string path) => Process.Start(new ProcessStartInfo { FileName = "notepad.exe", Arguments = path diff --git a/CreamInstaller/Utility/IconGrabber.cs b/CreamInstaller/Utility/IconGrabber.cs index 3714d34..2a15de4 100644 --- a/CreamInstaller/Utility/IconGrabber.cs +++ b/CreamInstaller/Utility/IconGrabber.cs @@ -16,7 +16,7 @@ internal static class IconGrabber internal static Image GetFileIconImage(string path) => File.Exists(path) ? Icon.ExtractAssociatedIcon(path).ToBitmap() : null; - internal static Image GetNotepadImage() => GetFileIconImage(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\notepad.exe"); + internal static Image GetNotepadImage() => GetFileIconImage(Diagnostics.GetNotepadPath()); internal static Image GetCommandPromptImage() => GetFileIconImage(Environment.SystemDirectory + @"\cmd.exe");