Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup launch configurations #420

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Daybreak/Configuration/Options/CredentialManagerOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Daybreak.Attributes;
using Daybreak.Models;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Daybreak.Configuration.Options;

[OptionsIgnore]
public sealed class CredentialManagerOptions
{
[JsonProperty(nameof(ProtectedLoginCredentials))]
public List<ProtectedLoginCredentials> ProtectedLoginCredentials { get; set; } = new();
}
11 changes: 11 additions & 0 deletions Daybreak/Configuration/Options/GuildwarsExecutableOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Daybreak.Attributes;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Daybreak.Configuration.Options;
[OptionsIgnore]
public sealed class GuildwarsExecutableOptions
{
[JsonProperty(nameof(ExecutablePaths))]
public List<string> ExecutablePaths { get; set; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Daybreak.Attributes;
using Daybreak.Models.LaunchConfigurations;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Daybreak.Configuration.Options;

[OptionsIgnore]
public sealed class LaunchConfigurationServiceOptions
{
[JsonProperty(nameof(LaunchConfigurations))]
public List<LaunchConfiguration> LaunchConfigurations { get; set; } = new();
}
8 changes: 0 additions & 8 deletions Daybreak/Configuration/Options/LauncherOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ public sealed class LauncherOptions
[OptionName(Name = "Launch GuildWars As Current User", Description = "If true, will attempt to launch GuildWars as the current user. Otherwise will attempt to launch as system user")]
public bool LaunchGuildwarsAsCurrentUser { get; set; } = true;

[JsonProperty(nameof(GuildwarsPaths))]
[OptionIgnore]
public List<GuildwarsPath> GuildwarsPaths { get; set; } = new();

[JsonProperty(nameof(ProtectedLoginCredentials))]
[OptionIgnore]
public List<ProtectedLoginCredentials> ProtectedLoginCredentials { get; set; } = new();

[JsonProperty(nameof(ShortcutLocation))]
[OptionName(Name = "Shortcut Location", Description = "Location where the shortcut will be placed")]
public string? ShortcutLocation { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Expand Down
10 changes: 10 additions & 0 deletions Daybreak/Configuration/ProjectConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
using Daybreak.Services.Injection;
using Daybreak.Services.ReShade;
using Daybreak.Views.Onboarding.ReShade;
using Daybreak.Services.LaunchConfigurations;
using Daybreak.Services.ExecutableManagement;
using Daybreak.Views.Launch;

namespace Daybreak.Configuration;

Expand Down Expand Up @@ -198,6 +201,7 @@ public override void RegisterServices(IServiceCollection services)
services.AddSingleton<IGuildwarsMemoryCache, GuildwarsMemoryCache>();
services.AddSingleton<IPluginsService, PluginsService>();
services.AddSingleton<ISplashScreenService, SplashScreenService>();
services.AddSingleton<IGuildWarsExecutableManager, GuildWarsExecutableManager>();
services.AddScoped<ICredentialManager, CredentialManager>();
services.AddScoped<IApplicationLauncher, ApplicationLauncher>();
services.AddScoped<IScreenshotProvider, ScreenshotProvider>();
Expand Down Expand Up @@ -235,6 +239,7 @@ public override void RegisterServices(IServiceCollection services)
services.AddScoped<IUModClient, UModClient>();
services.AddScoped<IToolboxClient, ToolboxClient>();
services.AddScoped<IProcessInjector, ProcessInjector>();
services.AddScoped<ILaunchConfigurationService, LaunchConfigurationService>();
}

public override void RegisterViews(IViewProducer viewProducer)
Expand Down Expand Up @@ -294,6 +299,8 @@ public override void RegisterViews(IViewProducer viewProducer)
viewProducer.RegisterView<ReShadeStockEffectsSelectorView>();
viewProducer.RegisterView<ReShadeConfigView>();
viewProducer.RegisterView<ReShadePresetView>();
viewProducer.RegisterView<LaunchConfigurationView>();
viewProducer.RegisterView<LaunchConfigurationsView>();
}

public override void RegisterStartupActions(IStartupActionProducer startupActionProducer)
Expand Down Expand Up @@ -391,6 +398,9 @@ public override void RegisterOptions(IOptionsProducer optionsProducer)
optionsProducer.RegisterOptions<TraderMessagesOptions>();
optionsProducer.RegisterOptions<EventNotifierOptions>();
optionsProducer.RegisterOptions<PluginsServiceOptions>();
optionsProducer.RegisterOptions<GuildwarsExecutableOptions>();
optionsProducer.RegisterOptions<CredentialManagerOptions>();
optionsProducer.RegisterOptions<LaunchConfigurationServiceOptions>();
}

public override void RegisterNotificationHandlers(INotificationHandlerProducer notificationHandlerProducer)
Expand Down
7 changes: 7 additions & 0 deletions Daybreak/Controls/MenuList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@
Cursor="Hand"
Clicked="GuildwarsSettingsButton_Clicked"
ToolTip="Executables settings"/>
<buttons:MenuButton Title="Launch configurations"
Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}"
HighlightColor="{DynamicResource MahApps.Brushes.Accent}"
Height="30"
Cursor="Hand"
Clicked="LaunchConfigurationsSettingsButton_Clicked"
ToolTip="Launch configurations settings" />
<options:OptionsSection />
</local:ExpandableMenuSection.Children>
</local:ExpandableMenuSection>
Expand Down
6 changes: 6 additions & 0 deletions Daybreak/Controls/MenuList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Daybreak.Services.Notifications;
using Daybreak.Views;
using Daybreak.Views.Copy;
using Daybreak.Views.Launch;
using Daybreak.Views.Onboarding.DSOAL;
using Daybreak.Views.Onboarding.ReShade;
using Daybreak.Views.Onboarding.Toolbox;
Expand Down Expand Up @@ -66,6 +67,11 @@ private void AccountSettingsButton_Clicked(object sender, EventArgs e)
this.viewManager.ShowView<AccountsView>();
}

private void LaunchConfigurationsSettingsButton_Clicked(object sender, EventArgs e)
{
this.viewManager.ShowView<LaunchConfigurationsView>();
}

private void GuildwarsSettingsButton_Clicked(object sender, EventArgs e)
{
this.viewManager.ShowView<ExecutablesView>();
Expand Down
5 changes: 1 addition & 4 deletions Daybreak/Controls/Templates/AccountTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@
FontSize="16" TextChanged="CharacterNameTextbox_TextChanged" Margin="5"
ToolTip="Character name" />
</Grid>
<buttons:BinButton Grid.Column="2" Height="30" Width="30" Foreground="{StaticResource MahApps.Brushes.ThemeForeground}" VerticalAlignment="Top" Margin="5, 15, 5, 5"
<buttons:BinButton Grid.Column="2" Height="30" Width="30" Foreground="{StaticResource MahApps.Brushes.ThemeForeground}" VerticalAlignment="Center" Margin="5, 5, 5, 5"
Clicked="BinButton_Clicked"
ToolTip="Delete entry" />
<buttons:StarButton Grid.Column="2" Height="30" Width="30" Foreground="{StaticResource MahApps.Brushes.ThemeForeground}" VerticalAlignment="Top" Margin="5, 55, 5, 5"
Clicked="StarGlyph_Clicked" IsEnabled="{Binding ElementName=_this, Path=IsDefault, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}"
ToolTip="Mark entry as active"/>
</Grid>
</UserControl>
5 changes: 1 addition & 4 deletions Daybreak/Controls/Templates/AccountTemplate.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public partial class AccountTemplate : UserControl
private string password = string.Empty;
[GenerateDependencyProperty]
private string characterName = string.Empty;
[GenerateDependencyProperty]
private bool isDefault;

public AccountTemplate()
{
Expand All @@ -39,7 +37,6 @@ private void AccountTemplate_DataContextChanged(object sender, DependencyPropert
this.PasswordBox.Password = loginCredentials.Password;
this.Username = loginCredentials.Username;
this.CharacterName = loginCredentials.CharacterName;
this.IsDefault = loginCredentials.Default;
}
}

Expand All @@ -61,7 +58,7 @@ private void CharacterNameTextbox_TextChanged(object sender, EventArgs e)
private void Passwordbox_PasswordChanged(object sender, EventArgs e)
{
this.Password = sender.As<PasswordBox>()?.Password;
this.DataContext.As<LoginCredentials>()!.Password = this.Password;
this.DataContext.As<LoginCredentials>()!.Password = this.Password!;
}

private void StarGlyph_Clicked(object sender, EventArgs e)
Expand Down
7 changes: 2 additions & 5 deletions Daybreak/Controls/Templates/GuildwarsPathTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock FontSize="16" Text="Path:" Foreground="{StaticResource MahApps.Brushes.ThemeForeground}" Margin="5" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center"/>
<TextBox Foreground="{StaticResource MahApps.Brushes.ThemeForeground}" Background="Transparent" Text="{Binding ElementName=_this, Path=Path, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
<TextBox Foreground="{StaticResource MahApps.Brushes.ThemeForeground}" Background="Transparent" Text="{Binding Path=Path, Mode=TwoWay }"
BorderThickness="1" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1"
FontSize="16" TextChanged="TextBox_TextChanged" Margin="5"
FontSize="16" Margin="5"
ToolTip="Path to Gw.exe"/>
</Grid>
<WrapPanel Grid.Column="1">
Expand All @@ -40,9 +40,6 @@
<buttons:BinButton Grid.Column="2" Height="30" Width="30" VerticalAlignment="Top" Margin="5"
Clicked="BinButton_Clicked"
ToolTip="Remove entry"/>
<buttons:StarButton Grid.Column="2" Height="30" Width="30" VerticalAlignment="Top" Margin="5"
Clicked="StarGlyph_Clicked" IsEnabled="{Binding ElementName=_this, Path=IsDefault, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}"
ToolTip="Mark entry as active"/>
</WrapPanel>
</Grid>
</UserControl>
26 changes: 1 addition & 25 deletions Daybreak/Controls/Templates/GuildwarsPathTemplate.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,13 @@ namespace Daybreak.Controls;
public partial class GuildwarsPathTemplate : UserControl
{
public event EventHandler? RemoveClicked;
public event EventHandler? DefaultClicked;

[GenerateDependencyProperty]
private string path = string.Empty;
[GenerateDependencyProperty]
private bool isDefault;

public GuildwarsPathTemplate()
{
this.InitializeComponent();
this.DataContextChanged += this.GuildwarsPathTemplate_DataContextChanged;
}

private void GuildwarsPathTemplate_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is GuildwarsPath guildwarsPath)
{
this.IsDefault = guildwarsPath.Default;
this.Path = guildwarsPath.Path;
}
}

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
this.DataContext.As<GuildwarsPath>()!.Path = this.Path;
}

private void StarGlyph_Clicked(object sender, EventArgs e)
{
this.DefaultClicked?.Invoke(this, e);
}

private void BinButton_Clicked(object sender, EventArgs e)
Expand All @@ -64,8 +41,7 @@ private void FilePickerGlyph_Clicked(object sender, EventArgs e)
};
if (filePicker.ShowDialog() is true)
{
this.Path = filePicker.FileName;
this.DataContext.As<GuildwarsPath>()!.Path = filePicker.FileName;
this.DataContext.As<ExecutablePath>()!.Path = filePicker.FileName;
}
}
}
64 changes: 64 additions & 0 deletions Daybreak/Controls/Templates/LaunchButtonTemplate.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<UserControl x:Class="Daybreak.Controls.Templates.LaunchButtonTemplate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Daybreak.Controls.Templates"
xmlns:buttons="clr-namespace:Daybreak.Controls.Buttons"
xmlns:configs="clr-namespace:Daybreak.Models.LaunchConfigurations"
xmlns:converters="clr-namespace:Daybreak.Converters"
mc:Ignorable="d"
Loaded="UserControl_Loaded"
Unloaded="UserControl_Unloaded"
x:Name="_this"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<converters:BooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" TriggerValue="True"></converters:BooleanToVisibilityConverter>
</UserControl.Resources>
<Grid>
<StackPanel
Visibility="{Binding ElementName=_this, Path=CanShowFocusView, Mode=OneWay, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
<WrapPanel VerticalAlignment="Center"
HorizontalAlignment="Center">
<TextBlock Text="Launch "
FontSize="22"
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
Visibility="{Binding ElementName=_this, Path=GameRunning, Mode=OneWay, Converter={StaticResource InverseBooleanToVisibilityConverter}}"/>
<TextBlock Text="{Binding Credentials.Username}"
FontSize="22"
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"/>
<TextBlock Text=" running"
FontSize="22"
Foreground="{StaticResource MahApps.Brushes.Accent}"
Visibility="{Binding ElementName=_this, Path=GameRunning, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</WrapPanel>
<TextBlock Text="{Binding Credentials.CharacterName}"
FontSize="16"
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"/>
<TextBlock Text="{Binding ExecutablePath}"
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
FontSize="12"
TextWrapping="Wrap"/>
</StackPanel>
<StackPanel
Visibility="{Binding ElementName=_this, Path=CanShowFocusView, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
<WrapPanel VerticalAlignment="Center"
HorizontalAlignment="Center">
<TextBlock Text="Attach "
FontSize="22"
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}" />
<TextBlock Text="{Binding Credentials.Username}"
FontSize="22"
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"/>
</WrapPanel>
<TextBlock Text="{Binding Credentials.CharacterName}"
FontSize="16"
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"/>
<TextBlock Text="{Binding ExecutablePath}"
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
FontSize="12"
TextWrapping="Wrap"/>
</StackPanel>
</Grid>
</UserControl>
92 changes: 92 additions & 0 deletions Daybreak/Controls/Templates/LaunchButtonTemplate.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Daybreak.Configuration.Options;
using Daybreak.Models.LaunchConfigurations;
using Daybreak.Services.ApplicationLauncher;
using Daybreak.Services.LaunchConfigurations;
using Microsoft.Extensions.DependencyInjection;
using Slim.Attributes;
using System;
using System.Configuration;
using System.Core.Extensions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Extensions;

namespace Daybreak.Controls.Templates;
/// <summary>
/// Interaction logic for LaunchButtonTemplate.xaml
/// </summary>
public partial class LaunchButtonTemplate : UserControl
{
private static readonly TimeSpan CheckGameDelay = TimeSpan.FromSeconds(1);

private readonly ILaunchConfigurationService launchConfigurationService;
private readonly IApplicationLauncher applicationLauncher;
private readonly ILiveOptions<FocusViewOptions> liveOptions;

[GenerateDependencyProperty]
private bool canShowFocusView;

[GenerateDependencyProperty]
private bool gameRunning;

private CancellationTokenSource? tokenSource;

public LaunchButtonTemplate(
ILaunchConfigurationService launchConfigurationService,
IApplicationLauncher applicationLauncher,
ILiveOptions<FocusViewOptions> liveOptions)
{
this.launchConfigurationService = launchConfigurationService.ThrowIfNull();
this.applicationLauncher = applicationLauncher.ThrowIfNull();
this.liveOptions = liveOptions.ThrowIfNull();
this.InitializeComponent();
}

[DoNotInject]
public LaunchButtonTemplate()
:this(
Launch.Launcher.Instance.ApplicationServiceProvider.GetRequiredService<ILaunchConfigurationService>(),
Launch.Launcher.Instance.ApplicationServiceProvider.GetRequiredService<IApplicationLauncher>(),
Launch.Launcher.Instance.ApplicationServiceProvider.GetRequiredService<ILiveOptions<FocusViewOptions>>())
{
}

private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
this.tokenSource?.Dispose();
this.tokenSource = new CancellationTokenSource();
this.CheckGameState(this.tokenSource.Token);
}

private void UserControl_Unloaded(object sender, System.Windows.RoutedEventArgs e)
{
this.tokenSource?.Dispose();
this.tokenSource = default;
}

private async void CheckGameState(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
if (this.DataContext is not LaunchConfigurationWithCredentials config)
{
await Task.Delay(CheckGameDelay, cancellationToken);
continue;
}

if (this.applicationLauncher.GetGuildwarsProcess(config) is null)
{
this.GameRunning = false;
}
else
{
this.GameRunning = true;
}

this.CanShowFocusView = this.liveOptions.Value.Enabled && this.GameRunning;

await Task.Delay(CheckGameDelay, cancellationToken);
}
}
}
Loading