Finalize log tracer view (#375)

also increased log polling rate for people with debug features enabled
This commit is contained in:
pizzaboxer 2023-07-22 12:14:37 +01:00
parent 62b4897bcc
commit 46e671e3ff
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
4 changed files with 64 additions and 22 deletions

View File

@ -28,7 +28,7 @@
private Dictionary<string, string> 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 @@
//
// 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 @@
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 @@
string? log = await sr.ReadLineAsync();
if (string.IsNullOrEmpty(log))
logUpdatedEvent.WaitOne(1000);
logUpdatedEvent.WaitOne(delay);
else
ExamineLogEntry(log);
}

View File

@ -19,20 +19,44 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ui:TitleBar Grid.Row="0" Grid.ColumnSpan="2" Padding="8" x:Name="RootTitleBar" Title="Log tracer" ShowMinimize="True" ShowMaximize="True" CanMaximize="True" KeyboardNavigation.TabNavigation="None" Icon="pack://application:,,,/Bloxstrap.ico" />
<TextBlock Grid.Row="1" Padding="12" Text="{Binding LogLocation, Mode=OneWay, StringFormat='Tracing \{0\}'}" />
<StackPanel Grid.Row="1" Orientation="Horizontal" Background="{ui:ThemeResource ControlFillColorDefaultBrush}">
<ui:MenuItem Margin="4,8,0,8" Header="Keep on top" IsCheckable="True" Click="KeepOnTopMenuItem_Click" />
<ui:MenuItem Margin="0,8,0,8" Header="Scroll to end" IsCheckable="True" IsChecked="True" Click="AutoScrollMenuItem_Click" />
<ui:MenuItem Name="TextWrappingToggle" Margin="0,8,0,8" Header="Text wrapping" IsCheckable="True" IsChecked="False" />
<ui:MenuItem Margin="0,8,4,8" Header="Locate log file" Command="{Binding LocateLogFileCommand, Mode=OneTime}" />
</StackPanel>
<ScrollViewer x:Name="ScrollViewer" Grid.Row="2">
<RichTextBox Grid.Row="1" Block.LineHeight="2" IsReadOnly="True" Background="Transparent" BorderThickness="0" TextChanged="RichTextBox_TextChanged">
<FlowDocument x:Name="FlowDocument">
<Paragraph FontFamily="Courier New" FontSize="14">
<Run Text="{Binding LogContents, Mode=OneWay}" />
</Paragraph>
</FlowDocument>
</RichTextBox>
<ScrollViewer x:Name="ScrollViewer" Grid.Row="2" VerticalAlignment="Top">
<ScrollViewer.Style>
<Style TargetType="ScrollViewer">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=TextWrappingToggle, Path=IsChecked}" Value="True">
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=TextWrappingToggle, Path=IsChecked}" Value="False">
<Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
</DataTrigger>
</Style.Triggers>
</Style>
</ScrollViewer.Style>
<TextBox Padding="0" Background="Transparent" TextWrapping="WrapWithOverflow" BorderThickness="0" IsReadOnly="True" FontFamily="Courier New" Text="{Binding LogContents, Mode=OneWay}" TextChanged="TextBox_TextChanged" />
</ScrollViewer>
<StatusBar Grid.Row="3" Padding="8">
<StatusBarItem>
<TextBlock>
<TextBlock.Text>
<MultiBinding Mode="OneWay" StringFormat="Tracing {0}">
<Binding Path="LogFilename" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StatusBarItem>
</StatusBar>
</Grid>
</ui:UiWindow>

View File

@ -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
/// </summary>
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();
}
}
}

View File

@ -9,10 +9,12 @@ namespace Bloxstrap.UI.ViewModels.ContextMenu
{
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 @@ namespace Bloxstrap.UI.ViewModels.ContextMenu
_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}\"");
}
}