-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Shell] Added option to start/stop world/auth server from within the …
…editor
- Loading branch information
Showing
15 changed files
with
344 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
WoWDatabaseEditor/Services/ServerExecutable/IServerExecutableConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using WDE.Module.Attributes; | ||
|
||
namespace WoWDatabaseEditorCore.Services.ServerExecutable; | ||
|
||
[UniqueProvider] | ||
public interface IServerExecutableConfiguration | ||
{ | ||
string? WorldServerPath { get; } | ||
string? AuthServerPath { get; } | ||
void Update(string? worldServerPath, string? authServerPath); | ||
} |
12 changes: 12 additions & 0 deletions
12
WoWDatabaseEditor/Services/ServerExecutable/IServerExecutableService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using AsyncAwaitBestPractices.MVVM; | ||
|
||
namespace WoWDatabaseEditorCore.Services.ServerExecutable; | ||
|
||
public interface IServerExecutableService | ||
{ | ||
IAsyncCommand ToggleWorldServer { get; } | ||
bool IsWorldServerRunning { get; } | ||
|
||
IAsyncCommand ToggleAuthServer { get; } | ||
bool IsAuthServerRunning { get; } | ||
} |
36 changes: 36 additions & 0 deletions
36
WoWDatabaseEditor/Services/ServerExecutable/ServerExecutableConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using WDE.Common.Services; | ||
using WDE.Module.Attributes; | ||
|
||
namespace WoWDatabaseEditorCore.Services.ServerExecutable; | ||
|
||
[SingleInstance] | ||
[AutoRegister] | ||
public class ServerExecutableConfiguration : IServerExecutableConfiguration | ||
{ | ||
private readonly IUserSettings userSettings; | ||
public string? WorldServerPath { get; set; } | ||
public string? AuthServerPath { get; set; } | ||
|
||
public ServerExecutableConfiguration(IUserSettings userSettings) | ||
{ | ||
this.userSettings = userSettings; | ||
var data = userSettings.Get<Data>(); | ||
WorldServerPath = data.WorldServerPath; | ||
AuthServerPath = data.AuthServerPath; | ||
} | ||
|
||
public void Update(string? worldServerPath, string? authServerPath) | ||
{ | ||
worldServerPath = string.IsNullOrWhiteSpace(worldServerPath) ? null : worldServerPath; | ||
authServerPath = string.IsNullOrWhiteSpace(authServerPath) ? null : authServerPath; | ||
WorldServerPath = worldServerPath; | ||
AuthServerPath = authServerPath; | ||
userSettings.Update(new Data(){WorldServerPath = worldServerPath, AuthServerPath = authServerPath}); | ||
} | ||
|
||
private struct Data : ISettings | ||
{ | ||
public string? WorldServerPath { get; set; } | ||
public string? AuthServerPath { get; set; } | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
WoWDatabaseEditor/Services/ServerExecutable/ServerExecutableConfigurationPanel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Windows.Input; | ||
using Prism.Commands; | ||
using PropertyChanged.SourceGenerator; | ||
using WDE.Common; | ||
using WDE.Common.Managers; | ||
using WDE.Common.Utils; | ||
using WDE.Module.Attributes; | ||
using WDE.MVVM; | ||
|
||
namespace WoWDatabaseEditorCore.Services.ServerExecutable; | ||
|
||
[AutoRegister] | ||
public partial class ServerExecutableConfigurationPanelViewModel : ObservableBase, IConfigurable | ||
{ | ||
private readonly IWindowManager windowManager; | ||
private readonly IServerExecutableConfiguration configuration; | ||
public ICommand Save { get; } | ||
public string Name => "World server executable"; | ||
public string? ShortDescription => "You can configure your world and auth server paths for easy start/stop button access in the statusbar"; | ||
public bool IsRestartRequired => false; | ||
public ConfigurableGroup Group => ConfigurableGroup.Advanced; | ||
|
||
public bool IsModified => worldServerPath != configuration.WorldServerPath || authServerPath != configuration.AuthServerPath; | ||
[Notify] [AlsoNotify(nameof(IsModified))] private string? worldServerPath; | ||
[Notify] [AlsoNotify(nameof(IsModified))] private string? authServerPath; | ||
|
||
public ICommand PickWorldPath { get; } | ||
public ICommand PickAuthPath { get; } | ||
|
||
public ServerExecutableConfigurationPanelViewModel(IWindowManager windowManager, | ||
IServerExecutableConfiguration configuration) | ||
{ | ||
this.windowManager = windowManager; | ||
this.configuration = configuration; | ||
worldServerPath = configuration.WorldServerPath; | ||
authServerPath = configuration.AuthServerPath; | ||
Save = new DelegateCommand(() => | ||
{ | ||
configuration.Update(worldServerPath, authServerPath); | ||
RaisePropertyChanged(nameof(IsModified)); | ||
}); | ||
|
||
string filter = "All files|*"; | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
filter = "Windows executable|exe|All files|*"; | ||
|
||
PickWorldPath = new AsyncAutoCommand(async () => | ||
{ | ||
var path = await windowManager.ShowOpenFileDialog(filter, File.Exists(WorldServerPath) ? Directory.GetParent(WorldServerPath)?.FullName : null); | ||
if (path != null && File.Exists(path)) | ||
WorldServerPath = path; | ||
}); | ||
|
||
PickAuthPath = new AsyncAutoCommand(async () => | ||
{ | ||
var path = await windowManager.ShowOpenFileDialog(filter, File.Exists(AuthServerPath) ? Directory.GetParent(AuthServerPath)?.FullName : null); | ||
if (path != null && File.Exists(path)) | ||
AuthServerPath = path; | ||
}); | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
WoWDatabaseEditor/Services/ServerExecutable/ServerExecutableService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using AsyncAwaitBestPractices.MVVM; | ||
using PropertyChanged.SourceGenerator; | ||
using WDE.Common.Managers; | ||
using WDE.Common.Services.MessageBox; | ||
using WDE.Common.Services.Processes; | ||
using WDE.Module.Attributes; | ||
using WDE.MVVM; | ||
|
||
namespace WoWDatabaseEditorCore.Services.ServerExecutable; | ||
|
||
[AutoRegister] | ||
[SingleInstance] | ||
public partial class ServerExecutableService : ObservableBase, IServerExecutableService | ||
{ | ||
private readonly IProcessService processService; | ||
private readonly IMessageBoxService messageBoxService; | ||
private readonly IServerExecutableConfiguration configuration; | ||
private readonly Lazy<IStatusBar> statusBar; | ||
[Notify] private bool isWorldServerRunning; | ||
[Notify] private bool isAuthServerRunning; | ||
public IAsyncCommand ToggleWorldServer { get; } | ||
public IAsyncCommand ToggleAuthServer { get; } | ||
|
||
private IProcess? worldProcess; | ||
private IProcess? authProcess; | ||
|
||
public ServerExecutableService(IProcessService processService, | ||
IMessageBoxService messageBoxService, | ||
IServerExecutableConfiguration configuration, | ||
Lazy<IStatusBar> statusBar) | ||
{ | ||
this.processService = processService; | ||
this.messageBoxService = messageBoxService; | ||
this.configuration = configuration; | ||
this.statusBar = statusBar; | ||
ToggleWorldServer = new AsyncCommand(async () => | ||
{ | ||
if (string.IsNullOrWhiteSpace(configuration.WorldServerPath) || | ||
!File.Exists(configuration.WorldServerPath)) | ||
{ | ||
await ShowConfigureDialog(); | ||
return; | ||
} | ||
if (worldProcess != null && worldProcess.IsRunning) | ||
{ | ||
worldProcess.Kill(); | ||
IsWorldServerRunning = false; | ||
worldProcess = null; | ||
} | ||
else | ||
{ | ||
worldProcess = processService.RunAndForget( | ||
configuration.WorldServerPath, | ||
"", Directory.GetParent(configuration.WorldServerPath)?.FullName, true); | ||
worldProcess.OnExit += WorldProcessOnOnExit; | ||
IsWorldServerRunning = true; | ||
} | ||
}); | ||
|
||
ToggleAuthServer = new AsyncCommand(async () => | ||
{ | ||
if (string.IsNullOrWhiteSpace(configuration.AuthServerPath) || | ||
!File.Exists(configuration.AuthServerPath)) | ||
{ | ||
await ShowConfigureDialog(); | ||
return; | ||
} | ||
if (authProcess != null && authProcess.IsRunning) | ||
{ | ||
authProcess.Kill(); | ||
IsAuthServerRunning = false; | ||
authProcess = null; | ||
} | ||
else | ||
{ | ||
authProcess = processService.RunAndForget( | ||
configuration.AuthServerPath, | ||
"", Directory.GetParent(configuration.AuthServerPath)?.FullName, true); | ||
authProcess.OnExit += AuthProcessOnOnExit; | ||
IsAuthServerRunning = true; | ||
} | ||
}); | ||
} | ||
|
||
private Task ShowConfigureDialog() | ||
{ | ||
return messageBoxService.ShowDialog(new MessageBoxFactory<bool>() | ||
.SetTitle("Configuration error") | ||
.SetMainInstruction("Setup server path first") | ||
.SetContent("In order to use quick executable start, configure the server paths in the settings") | ||
.WithOkButton(true) | ||
.Build()); | ||
} | ||
|
||
private void AuthProcessOnOnExit(int code) | ||
{ | ||
if (authProcess != null) | ||
authProcess.OnExit -= AuthProcessOnOnExit; | ||
if (code != 0) | ||
statusBar.Value.PublishNotification(new PlainNotification(NotificationType.Warning, "Auth server exited with code " + code)); | ||
IsAuthServerRunning = false; | ||
authProcess = null; | ||
} | ||
|
||
private void WorldProcessOnOnExit(int code) | ||
{ | ||
if (worldProcess != null) | ||
worldProcess.OnExit -= WorldProcessOnOnExit; | ||
if (code != 0) | ||
statusBar.Value.PublishNotification(new PlainNotification(NotificationType.Warning, "World server exited with code " + code)); | ||
IsWorldServerRunning = false; | ||
worldProcess = null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ditorCore.Avalonia/Services/ServerExecutable/ServerExecutableConfigurationPanelView.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:serverExecutable="clr-namespace:WoWDatabaseEditorCore.Services.ServerExecutable;assembly=WoWDatabaseEditorCore" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:DataType="serverExecutable:ServerExecutableConfigurationPanelViewModel" | ||
x:Class="WoWDatabaseEditorCore.Avalonia.Services.ServerExecutable.ServerExecutableConfigurationPanelView"> | ||
<Grid RowDefinitions="Auto,5,Auto" ColumnDefinitions="Auto,5,*,5,Auto"> | ||
<TextBlock VerticalAlignment="Center">World server:</TextBlock> | ||
<TextBox Text="{CompiledBinding WorldServerPath}" | ||
Grid.Row="0" Grid.Column="2" /> | ||
<Button Grid.Row="0" Grid.Column="4" Command="{CompiledBinding PickWorldPath}" Content="..." /> | ||
|
||
<TextBlock VerticalAlignment="Center" Grid.Row="2">Auth server:</TextBlock> | ||
<TextBox Text="{CompiledBinding AuthServerPath}" | ||
Grid.Row="2" Grid.Column="2" /> | ||
<Button Grid.Row="2" Grid.Column="4" Command="{CompiledBinding PickAuthPath}" Content="..." /> | ||
</Grid> | ||
</UserControl> |
18 changes: 18 additions & 0 deletions
18
...orCore.Avalonia/Services/ServerExecutable/ServerExecutableConfigurationPanelView.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace WoWDatabaseEditorCore.Avalonia.Services.ServerExecutable; | ||
|
||
public class ServerExecutableConfigurationPanelView : UserControl | ||
{ | ||
public ServerExecutableConfigurationPanelView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} |
Oops, something went wrong.