notepad++ attempt
This commit is contained in:
parent
28773bca50
commit
55683bd7b2
2 changed files with 36 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
Loading…
Reference in a new issue