From 071007c3e5f810480126446e610b32cd8c29f3cb Mon Sep 17 00:00:00 2001 From: Alexandru Macocian Date: Mon, 12 Apr 2021 19:35:08 +0200 Subject: [PATCH] Create application manifest. Require highest available rights. Return dialog message when registry is failed to be set. --- Daybreak/Daybreak.csproj | 3 ++- .../ApplicationDetector.cs | 26 ++++++++++++++----- Daybreak/app.manifest | 22 ++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 Daybreak/app.manifest diff --git a/Daybreak/Daybreak.csproj b/Daybreak/Daybreak.csproj index e46d0c63..254248aa 100644 --- a/Daybreak/Daybreak.csproj +++ b/Daybreak/Daybreak.csproj @@ -9,7 +9,8 @@ false preview Daybreak.ico - 0.4.0 + 0.4.1 + app.manifest diff --git a/Daybreak/Services/ApplicationDetection/ApplicationDetector.cs b/Daybreak/Services/ApplicationDetection/ApplicationDetector.cs index 6fd6454c..dfb68a4c 100644 --- a/Daybreak/Services/ApplicationDetection/ApplicationDetector.cs +++ b/Daybreak/Services/ApplicationDetection/ApplicationDetector.cs @@ -1,7 +1,9 @@ using Daybreak.Models; using Daybreak.Services.Configuration; using Daybreak.Services.Credentials; +using Daybreak.Services.Logging; using Daybreak.Services.Mutex; +using Daybreak.Utils; using Microsoft.Win32; using Pepa.Wpf.Utilities; using System; @@ -11,6 +13,8 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; +using System.Security; +using System.Security.Permissions; namespace Daybreak.Services.ApplicationDetection { @@ -23,6 +27,7 @@ public class ApplicationDetector : IApplicationDetector private readonly IConfigurationManager configurationManager; private readonly ICredentialManager credentialManager; private readonly IMutexHandler mutexHandler; + private readonly ILogger logger; public bool IsGuildwarsRunning => this.GuildwarsProcessDetected(); public bool IsToolboxRunning => GuildwarsToolboxProcessDetected(); @@ -30,8 +35,10 @@ public class ApplicationDetector : IApplicationDetector public ApplicationDetector( IConfigurationManager configurationManager, ICredentialManager credentialManager, - IMutexHandler mutexHandler) + IMutexHandler mutexHandler, + ILogger logger) { + this.logger = logger.ThrowIfNull(nameof(logger)); this.mutexHandler = mutexHandler.ThrowIfNull(nameof(mutexHandler)); this.credentialManager = credentialManager.ThrowIfNull(nameof(credentialManager)); this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager)); @@ -77,7 +84,7 @@ public void LaunchGuildwarsToolbox() } } - private void LaunchGuildwarsProcess(string email, SecureString password, string character) + private void LaunchGuildwarsProcess(string email, Models.SecureString password, string character) { var executable = this.configurationManager.GetConfiguration().GamePath; if (File.Exists(executable) is false) @@ -121,10 +128,17 @@ private void ClearGwLocks() private void SetRegistryGuildwarsPath() { var gamePath = this.configurationManager.GetConfiguration().GamePath; - var registryKey = GetGuildwarsRegistryKey(true); - registryKey.SetValue("Path", gamePath); - registryKey.SetValue("Src", gamePath); - registryKey.Close(); + try + { + var registryKey = GetGuildwarsRegistryKey(true); + registryKey.SetValue("Path", gamePath); + registryKey.SetValue("Src", gamePath); + registryKey.Close(); + } + catch (SecurityException ex) + { + this.logger.LogCritical($"Multi-launch requires administrator rights. Details: {ex}"); + } } private RegistryKey GetGuildwarsRegistryKey(bool write) diff --git a/Daybreak/app.manifest b/Daybreak/app.manifest new file mode 100644 index 00000000..9af61fc0 --- /dev/null +++ b/Daybreak/app.manifest @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + true + + +