Skip to content

Commit

Permalink
Finalize log tracer view (#375)
Browse files Browse the repository at this point in the history
also increased log polling rate for people with debug features enabled
  • Loading branch information
pizzaboxer committed Jul 22, 2023
1 parent 62b4897 commit 46e671e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 22 deletions.
13 changes: 9 additions & 4 deletions Bloxstrap/RobloxActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RobloxActivity : IDisposable

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?
Expand All @@ -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))
Expand All @@ -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()
Expand All @@ -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);
}
Expand Down
44 changes: 34 additions & 10 deletions Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
</ui:UiWindow>
19 changes: 13 additions & 6 deletions Bloxstrap/UI/Elements/ContextMenu/LogTracer.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls;

using Bloxstrap.UI.ViewModels.ContextMenu;

Expand All @@ -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();
}
}
}
10 changes: 8 additions & 2 deletions Bloxstrap/UI/ViewModels/ContextMenu/LogTracerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}\"");
}
}

0 comments on commit 46e671e

Please sign in to comment.