From 3ed1cc453ac5f0582633e693eced03172bbbe6ad Mon Sep 17 00:00:00 2001 From: Alexandru Macocian Date: Fri, 23 Apr 2021 20:24:28 +0200 Subject: [PATCH] Implemented functionality to launch guildwars with lower privilege. --- Daybreak/Configuration/ExperimentalFeatures.cs | 2 ++ Daybreak/Daybreak.csproj | 2 +- .../ApplicationLauncher/ApplicationLauncher.cs | 12 ++++++++++++ Daybreak/Views/ExperimentalSettingsView.xaml | 3 +++ Daybreak/Views/ExperimentalSettingsView.xaml.cs | 9 +++++++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Daybreak/Configuration/ExperimentalFeatures.cs b/Daybreak/Configuration/ExperimentalFeatures.cs index 8dfca543..14464b93 100644 --- a/Daybreak/Configuration/ExperimentalFeatures.cs +++ b/Daybreak/Configuration/ExperimentalFeatures.cs @@ -10,5 +10,7 @@ public sealed class ExperimentalFeatures public int ToolboxAutoLaunchDelay { get; set; } = 5000; [JsonProperty("DynamicBuildLoading")] public bool DynamicBuildLoading { get; set; } = true; + [JsonProperty("LaunchGuildwarsAsCurrentUser")] + public bool LaunchGuildwarsAsCurrentUser { get; set; } = true; } } diff --git a/Daybreak/Daybreak.csproj b/Daybreak/Daybreak.csproj index 69fd5122..118197e0 100644 --- a/Daybreak/Daybreak.csproj +++ b/Daybreak/Daybreak.csproj @@ -9,7 +9,7 @@ false preview Daybreak.ico - 0.7.7 + 0.7.8 app.manifest diff --git a/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs b/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs index 32b1ce99..3ff8bc17 100644 --- a/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs +++ b/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs @@ -129,6 +129,18 @@ private void LaunchGuildwarsProcess(string email, Models.SecureString password, args.Add(character); } + var identity = this.configurationManager.GetConfiguration().ExperimentalFeatures.LaunchGuildwarsAsCurrentUser ? + System.Security.Principal.WindowsIdentity.GetCurrent().Name : + System.Security.Principal.WindowsIdentity.GetAnonymous().Name; + this.logger.LogInformation($"Launching guildwars as [{identity}] identity"); + var process = new Process() + { + StartInfo = new ProcessStartInfo + { + Arguments = string.Join(" ", args), + UserName = identity + } + }; if (Process.Start(executable.Path, args) is null) { throw new InvalidOperationException($"Unable to launch {executable}"); diff --git a/Daybreak/Views/ExperimentalSettingsView.xaml b/Daybreak/Views/ExperimentalSettingsView.xaml index eaa67a90..5e4a68fc 100644 --- a/Daybreak/Views/ExperimentalSettingsView.xaml +++ b/Daybreak/Views/ExperimentalSettingsView.xaml @@ -91,6 +91,7 @@ + + diff --git a/Daybreak/Views/ExperimentalSettingsView.xaml.cs b/Daybreak/Views/ExperimentalSettingsView.xaml.cs index 7c7b75f3..cd489812 100644 --- a/Daybreak/Views/ExperimentalSettingsView.xaml.cs +++ b/Daybreak/Views/ExperimentalSettingsView.xaml.cs @@ -21,10 +21,17 @@ public partial class ExperimentalSettingsView : UserControl DependencyPropertyExtensions.Register(nameof(GWToolboxLaunchDelay)); public static readonly DependencyProperty DynamicBuildLoadingProperty = DependencyPropertyExtensions.Register(nameof(DynamicBuildLoading)); + public static readonly DependencyProperty LaunchAsCurrentUserProperty = + DependencyPropertyExtensions.Register(nameof(LaunchAsCurrentUser)); private readonly IViewManager viewManager; private readonly IConfigurationManager configurationManager; + public bool LaunchAsCurrentUser + { + get => this.GetTypedValue(LaunchAsCurrentUserProperty); + set => this.SetValue(LaunchAsCurrentUserProperty, value); + } public bool MultiLaunch { get => this.GetTypedValue(MultiLaunchProperty); @@ -57,6 +64,7 @@ private void LoadExperimentalSettings() this.MultiLaunch = config.ExperimentalFeatures.MultiLaunchSupport; this.GWToolboxLaunchDelay = config.ExperimentalFeatures.ToolboxAutoLaunchDelay.ToString(); this.DynamicBuildLoading = config.ExperimentalFeatures.DynamicBuildLoading; + this.LaunchAsCurrentUser = config.ExperimentalFeatures.LaunchGuildwarsAsCurrentUser; } private void SaveExperimentalSettings() @@ -64,6 +72,7 @@ private void SaveExperimentalSettings() var config = this.configurationManager.GetConfiguration(); config.ExperimentalFeatures.MultiLaunchSupport = this.MultiLaunch; config.ExperimentalFeatures.DynamicBuildLoading = this.DynamicBuildLoading; + config.ExperimentalFeatures.LaunchGuildwarsAsCurrentUser = this.LaunchAsCurrentUser; if (int.TryParse(this.GWToolboxLaunchDelay, out var gwToolboxLaunchDelay)) { config.ExperimentalFeatures.ToolboxAutoLaunchDelay = gwToolboxLaunchDelay;