From 426d87c3662ec37140d8befff41fe7e2b332d35e Mon Sep 17 00:00:00 2001 From: JosephSpearritt Date: Mon, 5 Aug 2019 21:21:10 +1000 Subject: [PATCH] UI rework v1; CommandLineString detection doesn't work yet --- Config.cs | 23 +++++- LoginServerStatus.cs | 67 +++++++++++++++++ MainWindow.xaml | 125 ++++++++++++++++++++++---------- MainWindow.xaml.cs | 145 ++++++++++++++++++++++++++++++++++--- Properties/AssemblyInfo.cs | 4 +- TribesLauncherSharp.csproj | 3 +- 6 files changed, 310 insertions(+), 57 deletions(-) create mode 100644 LoginServerStatus.cs diff --git a/Config.cs b/Config.cs index ce94a9c..2cbb9c5 100644 --- a/Config.cs +++ b/Config.cs @@ -34,6 +34,13 @@ enum InjectMode Automatic } + enum ProcessDetectionMode + { + ProcessName, + ProcessId, + CommandLineString + } + class Config : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; @@ -178,11 +185,19 @@ public int AutoInjectTimer { set { SetProperty(ref autoInjectTimer, value); } } - private bool injectByProcessId = false; - public bool InjectByProcessId + private ProcessDetectionMode processDetectionMode = ProcessDetectionMode.ProcessName; + public ProcessDetectionMode ProcessDetectionMode + { + get { return processDetectionMode; } + set { SetProperty(ref processDetectionMode, value); } + } + + private bool injectByProcessId_deprecated = false; + [YamlMember(Alias = "InjectByProcessId")] + public bool InjectByProcessId_Deprecated { - get { return injectByProcessId; } - set { SetProperty(ref injectByProcessId, value); } + get { return injectByProcessId_deprecated; } + set { SetProperty(ref injectByProcessId_deprecated, value); } } private string runningProcessName = "tribesascend"; diff --git a/LoginServerStatus.cs b/LoginServerStatus.cs new file mode 100644 index 0000000..fdb0754 --- /dev/null +++ b/LoginServerStatus.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Microsoft.CSharp.RuntimeBinder; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace TribesLauncherSharp +{ + class LoginServerStatus + { + public int? PlayersOnline { get; private set; } = null; + public int? ServersOnline { get; private set; } = null; + + public void Update(string loginServerHost, int loginServerWebPort = 9080) + { + System.Diagnostics.Debug.WriteLine("Updatarino"); + using (var wc = new WebClient()) + { + string rawData; + + try + { + rawData = wc.DownloadString($"http://{loginServerHost}:{loginServerWebPort}/status"); + } catch (WebException) + { + // Failed to get from server status API + Clear(); + return; + } + + dynamic data = null; + try + { + data = JObject.Parse(rawData); + } + catch (JsonReaderException) + { + // Failed to get data, just clear + Clear(); + return; + } + + try + { + PlayersOnline = data["online_players"]; + PlayersOnline = data["online_servers"]; + } + catch (RuntimeBinderException) + { + // Failed to parse response, just clear + Clear(); + return; + } + } + } + + public void Clear() + { + PlayersOnline = null; + ServersOnline = null; + } + } +} diff --git a/MainWindow.xaml b/MainWindow.xaml index a811da7..4fd446a 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -6,7 +6,7 @@ xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:TribesLauncherSharp" mc:Ignorable="d" - Title="TribesLauncher" Height="252.667" Width="556.933" ResizeMode="NoResize" Loaded="MainAppWindow_Loaded" Closing="MainAppWindow_Closing" Icon="Resources/icon.ico"> + Title="TribesLauncher" Height="352.533" Width="464.666" ResizeMode="CanMinimize" Loaded="MainAppWindow_Loaded" Closing="MainAppWindow_Closing" Icon="Resources/icon.ico"> @@ -28,44 +28,91 @@ -