notepad++ attempt

This commit is contained in:
pointfeev 2022-03-16 02:48:36 -04:00
parent 28773bca50
commit 55683bd7b2
2 changed files with 36 additions and 3 deletions

View file

@ -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

View file

@ -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");