This commit is contained in:
Heavy Bob 2025-04-11 10:10:38 +10:00
parent f8446f047e
commit 9b4b25921e
3 changed files with 666 additions and 640 deletions
AutoTrackR2

View file

@ -1,8 +1,7 @@
<Application x:Class="AutoTrackR2.App" <Application x:Class="AutoTrackR2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AutoTrackR2" xmlns:local="clr-namespace:AutoTrackR2">
StartupUri="MainWindow.xaml">
<Application.Resources> <Application.Resources>
<FontFamily x:Key="Orbitron">/AutoTrackR2;component/Fonts/Orbitron-Bold.ttf#Orbitron</FontFamily> <FontFamily x:Key="Orbitron">/AutoTrackR2;component/Fonts/Orbitron-Bold.ttf#Orbitron</FontFamily>
<FontFamily x:Key="Roboto">/AutoTrackR2;component/Fonts/Roboto-Regular.ttf#Roboto</FontFamily> <FontFamily x:Key="Roboto">/AutoTrackR2;component/Fonts/Roboto-Regular.ttf#Roboto</FontFamily>
@ -164,11 +163,10 @@
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="Button"> <ControlTemplate TargetType="Button">
<Border Background="{DynamicResource BackgroundDarkBrush}" <Border Background="{TemplateBinding Background}"
BorderBrush="{DynamicResource AccentBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="2" BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="5" CornerRadius="5">
Margin="0,1,4,1">
<ContentPresenter HorizontalAlignment="Center" <ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
</Border> </Border>
@ -572,17 +570,26 @@
</Style> </Style>
<!-- Standard Slider Style --> <!-- Standard Slider Style -->
<Style x:Key="SliderStyle" TargetType="Slider"> <Style x:Key="SliderStyle"
<Setter Property="Height" Value="40"/> TargetType="Slider">
<Setter Property="Width" Value="160"/> <Setter Property="Height"
<Setter Property="Foreground" Value="{DynamicResource TextBrush}"/> Value="40"/>
<Setter Property="Background" Value="{DynamicResource BackgroundDarkBrush}"/> <Setter Property="Width"
<Setter Property="BorderBrush" Value="{DynamicResource AccentBrush}"/> Value="160"/>
<Setter Property="BorderThickness" Value="2"/> <Setter Property="Foreground"
Value="{DynamicResource TextBrush}"/>
<Setter Property="Background"
Value="{DynamicResource BackgroundDarkBrush}"/>
<Setter Property="BorderBrush"
Value="{DynamicResource AccentBrush}"/>
<Setter Property="BorderThickness"
Value="2"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="Slider"> <ControlTemplate TargetType="Slider">
<Grid Width="100" Height="30" HorizontalAlignment="Left"> <Grid Width="100"
Height="30"
HorizontalAlignment="Left">
<!-- Track Background --> <!-- Track Background -->
<Border Background="{DynamicResource BackgroundDarkBrush}" <Border Background="{DynamicResource BackgroundDarkBrush}"
BorderBrush="{DynamicResource AccentBrush}" BorderBrush="{DynamicResource AccentBrush}"

View file

@ -22,6 +22,8 @@ namespace AutoTrackR2
private StreamlinkHandler? _streamlinkHandler; private StreamlinkHandler? _streamlinkHandler;
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{
try
{ {
// Ensure crash log directory exists // Ensure crash log directory exists
Directory.CreateDirectory(Path.GetDirectoryName(CrashLogPath)); Directory.CreateDirectory(Path.GetDirectoryName(CrashLogPath));
@ -38,13 +40,26 @@ namespace AutoTrackR2
if (!createdNew) if (!createdNew)
{ {
// App is already running, silently exit // App is already running, show message and exit
MessageBox.Show("AutoTrackR2 is already running.", "AutoTrackR2", MessageBoxButton.OK, MessageBoxImage.Information);
Current.Shutdown(); Current.Shutdown();
return; return;
} }
base.OnStartup(e); // Initialize StreamlinkHandler before creating the main window
_streamlinkHandler = new StreamlinkHandler(); _streamlinkHandler = new StreamlinkHandler();
// Create and show the main window
var mainWindow = new MainWindow();
mainWindow.Show();
base.OnStartup(e);
}
catch (Exception ex)
{
MessageBox.Show($"Failed to start AutoTrackR2: {ex.Message}", "AutoTrackR2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
Current.Shutdown();
}
} }
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
@ -94,21 +109,25 @@ namespace AutoTrackR2
} }
protected override void OnExit(ExitEventArgs e) protected override void OnExit(ExitEventArgs e)
{
if (_mutex != null && _mutexOwned)
{ {
try try
{
if (_mutex != null && _mutexOwned)
{ {
_mutex.ReleaseMutex(); _mutex.ReleaseMutex();
_mutex.Close();
_mutex = null;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
// Log the mutex release error but don't throw // Log the error but don't prevent shutdown
LogCrash(ex); File.AppendAllText(CrashLogPath, $"[{DateTime.Now}] Error during shutdown: {ex.Message}\n");
}
_mutex.Dispose();
} }
finally
{
base.OnExit(e); base.OnExit(e);
} }
} }
}
} }

View file

@ -20,7 +20,7 @@ public class ActorDeathEvent : ILogEventHandler
public Regex Pattern { get; } public Regex Pattern { get; }
private Regex _shipManufacturerPattern; private Regex _shipManufacturerPattern;
private string _lastKillShip = string.Empty; private string _lastKillShip = string.Empty;
private Regex cleanUpPattern = new Regex(@"^(.+?)(?:_\d+)*$"); private Regex cleanUpPattern = new Regex(@"^(.+?)_\d+$");
public ActorDeathEvent() public ActorDeathEvent()
{ {