open file with notepad if no associated app
MODIFY
WalletWasabi/Helpers/EnvironmentHelpers.cs
WalletWasabi/Helpers/EnvironmentHelpers.cs
@@ -3,6 +3,7 @@ using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using WalletWasabi.Logging;
+using Microsoft.Win32;
namespace WalletWasabi.Helpers
{
@@ -150,5 +151,30 @@ namespace WalletWasabi.Helpers
}
}
}
+
+ public static bool IsFileTypeAssociated(string fileExtension)
+ {
+ // Source article: https://edi.wang/post/2019/3/4/read-and-write-windows-registry-in-net-core
+
+ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ throw new InvalidOperationException("Operation only supported on windows.");
+ }
+
+ fileExtension = fileExtension.TrimStart('.'); // Remove . if added by the caller.
+
+ using (RegistryKey key = Registry.ClassesRoot.OpenSubKey($".{fileExtension}"))
+ {
+ if (key != null)
+ {
+ object val = key.GetValue(null); // Read the (Default) value.
+ if (val != null)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
}

MODIFY
WalletWasabi/Helpers/IoHelpers.cs
WalletWasabi/Helpers/IoHelpers.cs
@@ -272,6 +272,22 @@ namespace System.IO
}
else
{
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ if (!EnvironmentHelpers.IsFileTypeAssociated("json"))
+ {
+ // Open file using Notepad.
+ using (Process process = Process.Start(new ProcessStartInfo
+ {
+ FileName = "notepad.exe",
+ Arguments = filePath,
+ CreateNoWindow = true,
+ UseShellExecute = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
+ })) { }
+ }
+ }
+
+ // Open file wtih the default editor.
using (Process process = Process.Start(new ProcessStartInfo
{
FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? filePath : "open",

MODIFY
WalletWasabi/WalletWasabi.csproj
WalletWasabi/WalletWasabi.csproj
</PropertyGroup>
<ItemGroup>
+ <PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
<PackageReference Include="NBitcoin" Version="4.1.1.97" />
</ItemGroup>
<ItemGroup>

open file with notepad if no associated app