From 46e671e3ffdcda8034afcc561afd074a13e00e83 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sat, 22 Jul 2023 12:14:37 +0100 Subject: [PATCH] Finalize log tracer view (#375) also increased log polling rate for people with debug features enabled --- Bloxstrap/RobloxActivity.cs | 13 ++++-- .../UI/Elements/ContextMenu/LogTracer.xaml | 44 ++++++++++++++----- .../UI/Elements/ContextMenu/LogTracer.xaml.cs | 19 +++++--- .../ContextMenu/LogTracerViewModel.cs | 10 ++++- 4 files changed, 64 insertions(+), 22 deletions(-) diff --git a/Bloxstrap/RobloxActivity.cs b/Bloxstrap/RobloxActivity.cs index 4cc6fa8a..be511728 100644 --- a/Bloxstrap/RobloxActivity.cs +++ b/Bloxstrap/RobloxActivity.cs @@ -28,7 +28,7 @@ public class RobloxActivity : IDisposable private Dictionary GeolcationCache = new(); - public string LogFilename = null!; + public string LogLocation = null!; // these are values to use assuming the player isn't currently in a game // hmm... do i move this to a model? @@ -55,6 +55,11 @@ public async void StartWatcher() // // we'll tail the log file continuously, monitoring for any log entries that we need to determine the current game activity + int delay = 1000; + + if (App.Settings.Prop.OhHeyYouFoundMe) + delay = 250; + string logDirectory = Path.Combine(Directories.LocalAppData, "Roblox\\logs"); if (!Directory.Exists(logDirectory)) @@ -79,9 +84,9 @@ public async void StartWatcher() await Task.Delay(1000); } - LogFilename = logFileInfo.Name; + LogLocation = logFileInfo.FullName; FileStream logFileStream = logFileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - App.Logger.WriteLine($"[RobloxActivity::StartWatcher] Opened {LogFilename}"); + App.Logger.WriteLine($"[RobloxActivity::StartWatcher] Opened {LogLocation}"); AutoResetEvent logUpdatedEvent = new(false); FileSystemWatcher logWatcher = new() @@ -99,7 +104,7 @@ public async void StartWatcher() string? log = await sr.ReadLineAsync(); if (string.IsNullOrEmpty(log)) - logUpdatedEvent.WaitOne(1000); + logUpdatedEvent.WaitOne(delay); else ExamineLogEntry(log); } diff --git a/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml b/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml index 89188c08..135cdc5b 100644 --- a/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml +++ b/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml @@ -19,20 +19,44 @@ + - + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml.cs b/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml.cs index 622ef96e..5ff2de36 100644 --- a/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml.cs +++ b/Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows.Controls; +using System.Windows; +using System.Windows.Controls; using Bloxstrap.UI.ViewModels.ContextMenu; @@ -9,16 +10,22 @@ namespace Bloxstrap.UI.Elements.ContextMenu /// public partial class LogTracer { - private readonly LogTracerViewModel _viewModel; + private bool _autoscroll = true; public LogTracer(RobloxActivity activityWatcher) { - _viewModel = new LogTracerViewModel(this, activityWatcher); - DataContext = _viewModel; - + DataContext = new LogTracerViewModel(this, activityWatcher); InitializeComponent(); } - private void RichTextBox_TextChanged(object sender, TextChangedEventArgs e) => ScrollViewer.ScrollToEnd(); + private void KeepOnTopMenuItem_Click(object sender, RoutedEventArgs e) => Topmost = ((MenuItem)sender).IsChecked; + + private void AutoScrollMenuItem_Click(object sender, RoutedEventArgs e) => _autoscroll = ((MenuItem)sender).IsChecked; + + private void TextBox_TextChanged(object sender, TextChangedEventArgs e) + { + if (_autoscroll) + ScrollViewer.ScrollToEnd(); + } } } diff --git a/Bloxstrap/UI/ViewModels/ContextMenu/LogTracerViewModel.cs b/Bloxstrap/UI/ViewModels/ContextMenu/LogTracerViewModel.cs index 40fc1799..cb398b13 100644 --- a/Bloxstrap/UI/ViewModels/ContextMenu/LogTracerViewModel.cs +++ b/Bloxstrap/UI/ViewModels/ContextMenu/LogTracerViewModel.cs @@ -9,10 +9,12 @@ internal class LogTracerViewModel : NotifyPropertyChangedViewModel { private readonly Window _window; private readonly RobloxActivity _activityWatcher; + private int _lineNumber = 1; public ICommand CloseWindowCommand => new RelayCommand(_window.Close); + public ICommand LocateLogFileCommand => new RelayCommand(LocateLogFile); - public string LogLocation => _activityWatcher.LogFilename; + public string LogFilename => Path.GetFileName(_activityWatcher.LogLocation); public string LogContents { get; private set; } = ""; public LogTracerViewModel(Window window, RobloxActivity activityWatcher) @@ -22,9 +24,13 @@ public LogTracerViewModel(Window window, RobloxActivity activityWatcher) _activityWatcher.OnLogEntry += (_, message) => { - LogContents += message += "\r\n"; + LogContents += $"{_lineNumber}: {message}\r\n"; OnPropertyChanged(nameof(LogContents)); + + _lineNumber += 1; }; } + + private void LocateLogFile() => Process.Start("explorer.exe", $"/select,\"{_activityWatcher.LogLocation}\""); } }