Add extra checks
MODIFY
WalletWasabi.Fluent/Helpers/LinuxStartUpHelper.cs
WalletWasabi.Fluent/Helpers/LinuxStartUpHelper.cs
@@ -7,7 +7,7 @@ namespace WalletWasabi.Fluent.Helpers
{
public static class LinuxStartupHelper
{
- public static async Task AddOrRemoveDesktopFile(bool runOnSystemStartup)
+ public static async Task AddOrRemoveDesktopFileAsync(bool runOnSystemStartup)
{
string pathToDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config", "autostart");
string pathToDesktopFile = Path.Combine(pathToDir, "Wasabi.desktop");
@@ -17,6 +17,12 @@ namespace WalletWasabi.Fluent.Helpers
if (runOnSystemStartup)
{
string pathToExec = EnvironmentHelpers.GetExecutablePath();
+
+ if (!File.Exists(pathToExec))
+ {
+ throw new InvalidOperationException($"Path: {pathToExec} does not exist.");
+ }
+
string fileContents = string.Join(
"\n",
"[Desktop Entry]",

MODIFY
WalletWasabi.Fluent/Helpers/MacOsStartUpHelper.cs
WalletWasabi.Fluent/Helpers/MacOsStartUpHelper.cs
@@ -8,7 +8,7 @@ namespace WalletWasabi.Fluent.Helpers
private static readonly string AddCmd = $"osascript -e \' tell application \"System Events\" to make new login item at end with properties {{name:\"{Constants.AppName}\", path:\"/Applications/{Constants.AppName}.app\", hidden:true}} \'";
private static readonly string DeleteCmd = $"osascript -e \' tell application \"System Events\" to delete login item \"{Constants.AppName}\" \'";
- public static async Task AddOrRemoveLoginItem(bool runOnSystemStartup)
+ public static async Task AddOrRemoveLoginItemAsync(bool runOnSystemStartup)
{
if (runOnSystemStartup)
{

MODIFY
WalletWasabi.Fluent/Helpers/StartupHelper.cs
WalletWasabi.Fluent/Helpers/StartupHelper.cs
@@ -12,20 +12,15 @@ namespace WalletWasabi.Fluent.Helpers
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- string pathToExeFile = EnvironmentHelpers.GetExecutablePath();
- if (!File.Exists(pathToExeFile))
- {
- throw new InvalidOperationException($"Path {pathToExeFile} does not exist.");
- }
- WindowsStartupHelper.AddOrRemoveRegistryKey(runOnSystemStartup, pathToExeFile);
+ WindowsStartupHelper.AddOrRemoveRegistryKey(runOnSystemStartup);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
- await LinuxStartupHelper.AddOrRemoveDesktopFile(runOnSystemStartup).ConfigureAwait(false);
+ await LinuxStartupHelper.AddOrRemoveDesktopFileAsync(runOnSystemStartup).ConfigureAwait(false);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
- await MacOsStartupHelper.AddOrRemoveLoginItem(runOnSystemStartup).ConfigureAwait(false);
+ await MacOsStartupHelper.AddOrRemoveLoginItemAsync(runOnSystemStartup).ConfigureAwait(false);
}
}
}

MODIFY
WalletWasabi.Fluent/Helpers/WindowsStartUpHelper.cs
WalletWasabi.Fluent/Helpers/WindowsStartUpHelper.cs
using Microsoft.Win32;
using System;
+using System.IO;
using System.Runtime.InteropServices;
+using WalletWasabi.Helpers;
namespace WalletWasabi.Fluent.Helpers
{
@@ -8,13 +10,20 @@ namespace WalletWasabi.Fluent.Helpers
{
private const string KeyPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
- public static void AddOrRemoveRegistryKey(bool runOnSystemStartup, string pathToExeFile)
+ public static void AddOrRemoveRegistryKey(bool runOnSystemStartup)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
throw new InvalidOperationException("Registry modification can only be done on Windows.");
}
+ string pathToExeFile = EnvironmentHelpers.GetExecutablePath();
+
+ if (!File.Exists(pathToExeFile))
+ {
+ throw new InvalidOperationException($"Path: {pathToExeFile} does not exist.");
+ }
+
using RegistryKey key = Registry.CurrentUser.OpenSubKey(KeyPath, writable: true) ?? throw new InvalidOperationException("Registry operation failed.");
if (runOnSystemStartup)
{

Add extra checks