Skip to content

Commit c169ca1

Browse files
author
Alexandru Macocian
committed
Menu to manage guildwars executables.
1 parent 88214ea commit c169ca1

17 files changed

+340
-50
lines changed

Daybreak/Configuration/ApplicationConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ namespace Daybreak.Configuration
66
{
77
public sealed class ApplicationConfiguration
88
{
9-
[JsonProperty("GamePath")]
10-
public string GamePath { get; set; }
119
[JsonProperty("ToolboxPath")]
1210
public string ToolboxPath { get; set; }
1311
[JsonProperty("LeftBrowserDefault")]
1412
public string LeftBrowserDefault { get; set; }
1513
[JsonProperty("RightBrowserDefault")]
1614
public string RightBrowserDefault { get; set; }
15+
[JsonProperty("GuildwarsPaths")]
16+
public List<GuildwarsPath> GuildwarsPaths { get; set; } = new();
1717
[JsonProperty("ProtectedLoginCredentials")]
18-
public List<ProtectedLoginCredentials> ProtectedLoginCredentials { get; set; }
18+
public List<ProtectedLoginCredentials> ProtectedLoginCredentials { get; set; } = new();
1919
[JsonProperty("AddressBarReadonly")]
2020
public bool AddressBarReadonly { get; set; } = true;
2121
[JsonProperty("ExperimentalFeatures")]

Daybreak/Configuration/ProjectConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static void RegisterViews(IViewProducer viewProducer)
5252
viewProducer.RegisterView<SettingsCategoryView>();
5353
viewProducer.RegisterView<AccountsView>();
5454
viewProducer.RegisterView<ExperimentalSettingsView>();
55+
viewProducer.RegisterView<ExecutablesView>();
5556
}
5657
}
5758
}

Daybreak/Controls/FileGlyph.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<UserControl x:Class="Daybreak.Controls.FileGlyph"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Daybreak.Controls"
7+
mc:Ignorable="d"
8+
x:Name="_this"
9+
d:DesignHeight="450" d:DesignWidth="800">
10+
<Viewbox>
11+
<Path Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
12+
Data="m52,0l-40,0c-6.627,0 -12,5.373 -12,12l0,72c0,6.627 5.373,12 12,12l55.875,0c6.627,0 12.125,-5.373 12.125,-12l0,-56c-4,-4 -22,-22 -28,-28zm0,11.178l16.709,16.822l-16.709,0l0,-16.822zm15.875,76.822l-55.875,0c-2.206,0 -4,-1.794 -4,-4l0,-72c0,-2.206 1.794,-4 4,-4l32,0l0,20l0,8l8,0l20,0l0,48c0,2.168 -1.889,4 -4.125,4z"></Path>
13+
</Viewbox>
14+
</UserControl>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Windows.Controls;
2+
3+
namespace Daybreak.Controls
4+
{
5+
/// <summary>
6+
/// Interaction logic for FileGlyph.xaml
7+
/// </summary>
8+
public partial class FileGlyph : UserControl
9+
{
10+
public FileGlyph()
11+
{
12+
InitializeComponent();
13+
}
14+
}
15+
}

Daybreak/Controls/FilePickerGlyph.xaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
x:Name="_this"
99
d:DesignHeight="450" d:DesignWidth="800">
1010
<Grid>
11-
<Rectangle x:Name="BackgroundEllipse" Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Visibility="Visible" Opacity="0.1" />
12-
<Viewbox>
13-
<StackPanel Orientation="Horizontal">
14-
<Ellipse Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Height="1" Width="1"></Ellipse>
15-
<Ellipse Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Height="1" Width="1"></Ellipse>
16-
<Ellipse Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Height="1" Width="1"></Ellipse>
17-
</StackPanel>
11+
<Ellipse x:Name="BackgroundEllipse" Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Visibility="Visible" Opacity="0.1" />
12+
<Viewbox Stretch="Fill">
13+
<Grid>
14+
<Ellipse Height="4" Width="4" StrokeThickness="0.2" Stroke="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"></Ellipse>
15+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
16+
<Ellipse Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Height="1" Width="1"></Ellipse>
17+
<Ellipse Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Height="1" Width="1"></Ellipse>
18+
<Ellipse Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Height="1" Width="1"></Ellipse>
19+
</StackPanel>
20+
</Grid>
1821
</Viewbox>
19-
<Rectangle Fill="Transparent" MouseEnter="Ellipse_MouseEnter" MouseLeave="Ellipse_MouseLeave" MouseLeftButtonDown="Ellipse_MouseLeftButtonDown"></Rectangle>
22+
<Ellipse Fill="Transparent" MouseEnter="Ellipse_MouseEnter" MouseLeave="Ellipse_MouseLeave" MouseLeftButtonDown="Ellipse_MouseLeftButtonDown"></Ellipse>
2023
</Grid>
2124
</UserControl>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<UserControl x:Class="Daybreak.Controls.GuildwarsPathTemplate"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:converters="clr-namespace:Daybreak.Converters"
7+
xmlns:local="clr-namespace:Daybreak.Controls"
8+
mc:Ignorable="d"
9+
x:Name="_this"
10+
d:DesignHeight="450" d:DesignWidth="800">
11+
<UserControl.Resources>
12+
<ResourceDictionary>
13+
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter"></converters:InverseBooleanConverter>
14+
</ResourceDictionary>
15+
</UserControl.Resources>
16+
<Grid>
17+
<Grid.ColumnDefinitions>
18+
<ColumnDefinition Width="*"></ColumnDefinition>
19+
<ColumnDefinition Width="auto"></ColumnDefinition>
20+
</Grid.ColumnDefinitions>
21+
<Grid HorizontalAlignment="Stretch">
22+
<Grid.RowDefinitions>
23+
<RowDefinition Height="auto"></RowDefinition>
24+
</Grid.RowDefinitions>
25+
<Grid.ColumnDefinitions>
26+
<ColumnDefinition Width="auto"></ColumnDefinition>
27+
<ColumnDefinition Width="*"></ColumnDefinition>
28+
</Grid.ColumnDefinitions>
29+
<TextBlock FontSize="22" Text="Path:" Foreground="White" Margin="5" Grid.Row="0" HorizontalAlignment="Right"></TextBlock>
30+
<TextBox Foreground="White" Background="Transparent" Text="{Binding ElementName=_this, Path=Path, Mode=TwoWay}"
31+
BorderThickness="1" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1"
32+
FontSize="22" TextChanged="TextBox_TextChanged" Margin="5"></TextBox>
33+
</Grid>
34+
<WrapPanel Grid.Column="1">
35+
<local:FilePickerGlyph Width="30" Height="30" Foreground="White" VerticalAlignment="Top" Margin="5"
36+
Clicked="FilePickerGlyph_Clicked"></local:FilePickerGlyph>
37+
<local:BinButton Grid.Column="2" Height="30" Width="30" Foreground="White" VerticalAlignment="Top" Margin="5"
38+
Clicked="BinButton_Clicked"></local:BinButton>
39+
<local:StarGlyph Grid.Column="2" Height="30" Width="30" Foreground="White" VerticalAlignment="Top" Margin="5"
40+
Clicked="StarGlyph_Clicked" IsEnabled="{Binding ElementName=_this, Path=IsDefault, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}"></local:StarGlyph>
41+
</WrapPanel>
42+
</Grid>
43+
</UserControl>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using Daybreak.Models;
2+
using Microsoft.Win32;
3+
using System;
4+
using System.Extensions;
5+
using System.Windows;
6+
using System.Windows.Controls;
7+
using System.Windows.Extensions;
8+
9+
namespace Daybreak.Controls
10+
{
11+
/// <summary>
12+
/// Interaction logic for GuildwarsPathTemplate.xaml
13+
/// </summary>
14+
public partial class GuildwarsPathTemplate : UserControl
15+
{
16+
public static readonly DependencyProperty PathProperty = DependencyPropertyExtensions.Register<GuildwarsPathTemplate, string>(nameof(Path));
17+
public static readonly DependencyProperty IsDefaultProperty = DependencyPropertyExtensions.Register<GuildwarsPathTemplate, bool>(nameof(IsDefault));
18+
19+
public event EventHandler RemoveClicked;
20+
public event EventHandler DefaultClicked;
21+
22+
public string Path
23+
{
24+
get => this.GetTypedValue<string>(PathProperty);
25+
set => this.SetValue(PathProperty, value);
26+
}
27+
public bool IsDefault
28+
{
29+
get => this.GetTypedValue<bool>(IsDefaultProperty);
30+
set => this.SetValue(IsDefaultProperty, value);
31+
}
32+
33+
public GuildwarsPathTemplate()
34+
{
35+
this.InitializeComponent();
36+
this.DataContextChanged += GuildwarsPathTemplate_DataContextChanged;
37+
}
38+
39+
private void GuildwarsPathTemplate_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
40+
{
41+
if (e.NewValue is GuildwarsPath guildwarsPath)
42+
{
43+
this.IsDefault = guildwarsPath.Default;
44+
this.Path = guildwarsPath.Path;
45+
}
46+
}
47+
48+
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
49+
{
50+
this.Path = sender.As<TextBox>()?.Text;
51+
this.DataContext.As<GuildwarsPath>().Path = this.Path;
52+
}
53+
54+
private void StarGlyph_Clicked(object sender, EventArgs e)
55+
{
56+
this.DefaultClicked?.Invoke(this, e);
57+
}
58+
59+
private void BinButton_Clicked(object sender, EventArgs e)
60+
{
61+
this.RemoveClicked?.Invoke(this, e);
62+
}
63+
64+
private void FilePickerGlyph_Clicked(object sender, EventArgs e)
65+
{
66+
var filePicker = new OpenFileDialog()
67+
{
68+
CheckFileExists = true,
69+
CheckPathExists = true,
70+
DefaultExt = "exe",
71+
Multiselect = false
72+
};
73+
if (filePicker.ShowDialog() is true)
74+
{
75+
this.Path = filePicker.FileName;
76+
this.DataContext.As<GuildwarsPath>().Path = filePicker.FileName;
77+
}
78+
}
79+
}
80+
}

Daybreak/Daybreak.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
1010
<LangVersion>preview</LangVersion>
1111
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
12-
<Version>0.5.1</Version>
12+
<Version>0.6.0</Version>
1313
<ApplicationManifest>app.manifest</ApplicationManifest>
1414
</PropertyGroup>
1515

Daybreak/Models/GuildwarsPath.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Daybreak.Models
4+
{
5+
public sealed class GuildwarsPath
6+
{
7+
[JsonProperty("path")]
8+
public string Path { get; set; }
9+
[JsonProperty("default")]
10+
public bool Default { get; set; }
11+
}
12+
}

Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ public Task LaunchGuildwarsToolbox()
8282

8383
private void LaunchGuildwarsProcess(string email, Models.SecureString password, string character)
8484
{
85-
var executable = this.configurationManager.GetConfiguration().GamePath;
86-
if (File.Exists(executable) is false)
85+
var executable = this.configurationManager.GetConfiguration().GuildwarsPaths.Where(path => path.Default).FirstOrDefault();
86+
if (executable is null)
87+
{
88+
throw new ExecutableNotFoundException($"No executable selected");
89+
}
90+
91+
if (File.Exists(executable.Path) is false)
8792
{
8893
throw new ExecutableNotFoundException($"Guildwars executable doesn't exist at {executable}");
8994
}
@@ -101,7 +106,7 @@ private void LaunchGuildwarsProcess(string email, Models.SecureString password,
101106
args.Add(character);
102107
}
103108

104-
if (Process.Start(executable, args) is null)
109+
if (Process.Start(executable.Path, args) is null)
105110
{
106111
throw new InvalidOperationException($"Unable to launch {executable}");
107112
}
@@ -113,7 +118,13 @@ private bool GuildwarsProcessDetected()
113118
{
114119
try
115120
{
116-
using var stream = File.OpenWrite(this.configurationManager.GetConfiguration().GamePath);
121+
var path = this.configurationManager.GetConfiguration().GuildwarsPaths.Where(path => path.Default).FirstOrDefault();
122+
if (path is null)
123+
{
124+
return false;
125+
}
126+
127+
using var stream = File.OpenWrite(path.Path);
117128
return false;
118129
}
119130
catch
@@ -136,7 +147,13 @@ private void ClearGwLocks()
136147

137148
private void SetRegistryGuildwarsPath()
138149
{
139-
var gamePath = this.configurationManager.GetConfiguration().GamePath;
150+
var path = this.configurationManager.GetConfiguration().GuildwarsPaths.Where(path => path.Default).FirstOrDefault();
151+
if (path is null)
152+
{
153+
throw new ExecutableNotFoundException("No executable currently selected");
154+
}
155+
156+
var gamePath = path.Path;
140157
try
141158
{
142159
var registryKey = GetGuildwarsRegistryKey(true);

0 commit comments

Comments
 (0)