Skip to content

Commit ef7b47f

Browse files
committed
[Shell] Added option to start/stop world/auth server from within the editor
1 parent b4d1c78 commit ef7b47f

15 files changed

Lines changed: 344 additions & 2 deletions

WoWDatabaseEditor.Common/WDE.Common/Services/Processes/IProcessService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface IProcess
1010
{
1111
bool IsRunning { get; }
1212
void Kill();
13+
event Action<int>? OnExit;
1314
}
1415

1516
[UniqueProvider]
504 Bytes
Loading
533 Bytes
Loading
565 Bytes
Loading
624 Bytes
Loading

WoWDatabaseEditor/Managers/StatusBar.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using WDE.Module.Attributes;
1313
using WDE.MVVM;
1414
using WoWDatabaseEditorCore.Services.ProblemsTool;
15+
using WoWDatabaseEditorCore.Services.ServerExecutable;
1516
using WoWDatabaseEditorCore.ViewModels;
1617

1718
namespace WoWDatabaseEditorCore.Managers
@@ -23,20 +24,25 @@ public partial class StatusBar : ObservableBase, IStatusBar
2324
private readonly TasksViewModel tasksViewModel;
2425
private readonly IMainThread mainThread;
2526
private readonly IPersonalGuidRangeService guidRangeService;
27+
private readonly IServerExecutableService serverExecutableService;
2628
private readonly Lazy<IClipboardService> clipboardService;
2729
private readonly Lazy<IMessageBoxService> messageBoxService;
2830

31+
public IServerExecutableService ServerExecutableService => serverExecutableService;
32+
2933
public StatusBar(Lazy<IDocumentManager> documentManager,
3034
TasksViewModel tasksViewModel,
3135
IEventAggregator eventAggregator,
3236
IMainThread mainThread,
3337
IPersonalGuidRangeService guidRangeService,
38+
IServerExecutableService serverExecutableService,
3439
Lazy<IClipboardService> clipboardService,
3540
Lazy<IMessageBoxService> messageBoxService)
3641
{
3742
this.tasksViewModel = tasksViewModel;
3843
this.mainThread = mainThread;
3944
this.guidRangeService = guidRangeService;
45+
this.serverExecutableService = serverExecutableService;
4046
this.clipboardService = clipboardService;
4147
this.messageBoxService = messageBoxService;
4248

WoWDatabaseEditor/Services/Processes/ProcessService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ public class ProcessData : IProcess
1919
public ProcessData(Process process)
2020
{
2121
this.process = process;
22+
process.EnableRaisingEvents = true;
23+
process.Exited += ProcessOnExited;
24+
}
25+
26+
private void ProcessOnExited(object? sender, EventArgs e)
27+
{
28+
OnExit?.Invoke(process.ExitCode);
2229
}
2330

2431
public bool IsRunning => !process.HasExited;
@@ -30,6 +37,8 @@ public void Kill()
3037
process.Kill();
3138
}
3239
}
40+
41+
public event Action<int>? OnExit;
3342
}
3443

3544
public IProcess RunAndForget(string path, string arguments, string? workingDirectory, bool noWindow,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using WDE.Module.Attributes;
2+
3+
namespace WoWDatabaseEditorCore.Services.ServerExecutable;
4+
5+
[UniqueProvider]
6+
public interface IServerExecutableConfiguration
7+
{
8+
string? WorldServerPath { get; }
9+
string? AuthServerPath { get; }
10+
void Update(string? worldServerPath, string? authServerPath);
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using AsyncAwaitBestPractices.MVVM;
2+
3+
namespace WoWDatabaseEditorCore.Services.ServerExecutable;
4+
5+
public interface IServerExecutableService
6+
{
7+
IAsyncCommand ToggleWorldServer { get; }
8+
bool IsWorldServerRunning { get; }
9+
10+
IAsyncCommand ToggleAuthServer { get; }
11+
bool IsAuthServerRunning { get; }
12+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using WDE.Common.Services;
2+
using WDE.Module.Attributes;
3+
4+
namespace WoWDatabaseEditorCore.Services.ServerExecutable;
5+
6+
[SingleInstance]
7+
[AutoRegister]
8+
public class ServerExecutableConfiguration : IServerExecutableConfiguration
9+
{
10+
private readonly IUserSettings userSettings;
11+
public string? WorldServerPath { get; set; }
12+
public string? AuthServerPath { get; set; }
13+
14+
public ServerExecutableConfiguration(IUserSettings userSettings)
15+
{
16+
this.userSettings = userSettings;
17+
var data = userSettings.Get<Data>();
18+
WorldServerPath = data.WorldServerPath;
19+
AuthServerPath = data.AuthServerPath;
20+
}
21+
22+
public void Update(string? worldServerPath, string? authServerPath)
23+
{
24+
worldServerPath = string.IsNullOrWhiteSpace(worldServerPath) ? null : worldServerPath;
25+
authServerPath = string.IsNullOrWhiteSpace(authServerPath) ? null : authServerPath;
26+
WorldServerPath = worldServerPath;
27+
AuthServerPath = authServerPath;
28+
userSettings.Update(new Data(){WorldServerPath = worldServerPath, AuthServerPath = authServerPath});
29+
}
30+
31+
private struct Data : ISettings
32+
{
33+
public string? WorldServerPath { get; set; }
34+
public string? AuthServerPath { get; set; }
35+
}
36+
}

0 commit comments

Comments
 (0)