2022-08-17 02:15:29 +05:00
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
|
|
|
|
|
using System;
|
2022-03-16 11:48:36 +05:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2022-03-03 16:38:17 +05:00
|
|
|
|
namespace CreamInstaller.Utility;
|
2022-02-25 10:51:11 +05:00
|
|
|
|
|
|
|
|
|
internal static class Diagnostics
|
|
|
|
|
{
|
2022-03-16 11:48:36 +05:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-19 04:04:49 +05:00
|
|
|
|
internal static string GetNotepadPath()
|
|
|
|
|
{
|
|
|
|
|
string npp = NotepadPlusPlusPath + @"\notepad++.exe";
|
|
|
|
|
return File.Exists(npp) ? npp : Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\notepad.exe";
|
|
|
|
|
}
|
2022-03-16 11:48:36 +05:00
|
|
|
|
|
|
|
|
|
internal static void OpenFileInNotepad(string path)
|
|
|
|
|
{
|
|
|
|
|
string npp = NotepadPlusPlusPath + @"\notepad++.exe";
|
2022-03-19 04:04:49 +05:00
|
|
|
|
if (File.Exists(npp))
|
2022-03-16 11:48:36 +05:00
|
|
|
|
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
|
2022-02-25 10:51:11 +05:00
|
|
|
|
{
|
|
|
|
|
FileName = "notepad.exe",
|
|
|
|
|
Arguments = path
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
internal static void OpenDirectoryInFileExplorer(string path) => Process.Start(new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = "explorer.exe",
|
|
|
|
|
Arguments = path
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
internal static void OpenUrlInInternetBrowser(string url) => Process.Start(new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = url,
|
|
|
|
|
UseShellExecute = true
|
|
|
|
|
});
|
2022-08-24 08:48:43 +05:00
|
|
|
|
|
|
|
|
|
internal static string BeautifyPath(this string path) => path is null ? null : Path.TrimEndingDirectorySeparator(Path.GetFullPath(path));
|
2022-02-25 10:51:11 +05:00
|
|
|
|
}
|