From 53a64881cd9fac996730ab599fd26e1d15a9bdd4 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Thu, 20 Jul 2023 18:17:25 +0100 Subject: [PATCH] Add log tracer window --- Bloxstrap/RobloxActivity.cs | 9 ++++- .../UI/Elements/ContextMenu/LogTracer.xaml | 38 +++++++++++++++++++ .../UI/Elements/ContextMenu/LogTracer.xaml.cs | 24 ++++++++++++ .../Elements/ContextMenu/MenuContainer.xaml | 1 + .../ContextMenu/ServerInformation.xaml | 38 +++++++++---------- Bloxstrap/UI/NotifyIconWrapper.cs | 30 ++++++++++++--- .../ContextMenu/LogTracerViewModel.cs | 30 +++++++++++++++ .../ContextMenu/ServerInformationViewModel.cs | 6 +-- 8 files changed, 145 insertions(+), 31 deletions(-) create mode 100644 Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml create mode 100644 Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml.cs create mode 100644 Bloxstrap/UI/ViewModels/ContextMenu/LogTracerViewModel.cs diff --git a/Bloxstrap/RobloxActivity.cs b/Bloxstrap/RobloxActivity.cs index 1966ac1..3c0c495 100644 --- a/Bloxstrap/RobloxActivity.cs +++ b/Bloxstrap/RobloxActivity.cs @@ -17,12 +17,15 @@ private int _logEntriesRead = 0; + public event EventHandler? OnLogEntry; public event EventHandler? OnGameJoin; public event EventHandler? OnGameLeave; public event EventHandler? OnGameMessage; private Dictionary GeolcationCache = new(); + public string LogFilename = null!; + // these are values to use assuming the player isn't currently in a game // keep in mind ActivityIsTeleport is only reset by DiscordRichPresence when it's done accessing it // because of the weird chronology of where the teleporting entry is outputted, there's no way to reset it in here @@ -72,8 +75,9 @@ await Task.Delay(1000); } + LogFilename = logFileInfo.Name; FileStream logFileStream = logFileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - App.Logger.WriteLine($"[RobloxActivity::StartWatcher] Opened {logFileInfo.Name}"); + App.Logger.WriteLine($"[RobloxActivity::StartWatcher] Opened {LogFilename}"); AutoResetEvent logUpdatedEvent = new(false); FileSystemWatcher logWatcher = new() @@ -99,7 +103,8 @@ private void ExamineLogEntry(string entry) { - // App.Logger.WriteLine(entry); + OnLogEntry?.Invoke(this, entry); + _logEntriesRead += 1; // debug stats to ensure that the log reader is working correctly diff --git a/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml b/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml new file mode 100644 index 0000000..89188c0 --- /dev/null +++ b/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml.cs b/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml.cs new file mode 100644 index 0000000..622ef96 --- /dev/null +++ b/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml.cs @@ -0,0 +1,24 @@ +using System.Windows.Controls; + +using Bloxstrap.UI.ViewModels.ContextMenu; + +namespace Bloxstrap.UI.Elements.ContextMenu +{ + /// + /// Interaction logic for LogTracer.xaml + /// + public partial class LogTracer + { + private readonly LogTracerViewModel _viewModel; + + public LogTracer(RobloxActivity activityWatcher) + { + _viewModel = new LogTracerViewModel(this, activityWatcher); + DataContext = _viewModel; + + InitializeComponent(); + } + + private void RichTextBox_TextChanged(object sender, TextChangedEventArgs e) => ScrollViewer.ScrollToEnd(); + } +} diff --git a/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml b/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml index 824de2c..cc41190 100644 --- a/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml +++ b/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml @@ -22,6 +22,7 @@ + diff --git a/Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml b/Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml index 4233e52..551e430 100644 --- a/Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml +++ b/Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml @@ -18,29 +18,27 @@ ExtendsContentIntoTitleBar="True" WindowStartupLocation="CenterScreen"> - - - - - - + + + + + - + - - - + + + - - + + + + + + +