Fixed kill streak cleanup and added trackrver constant.

This commit is contained in:
Heavy Bob 2025-04-13 05:58:44 +10:00
parent 36cfdaba8a
commit 3c23f34d3f
6 changed files with 47 additions and 32 deletions

View file

@ -20,6 +20,13 @@ namespace AutoTrackR2
"crash.log"
);
private StreamlinkHandler? _streamlinkHandler;
private KillStreakManager? _killStreakManager;
private void HandleException(Exception ex)
{
MessageBox.Show($"Failed to start AutoTrackR2: {ex.Message}", "AutoTrackR2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
Current.Shutdown();
}
protected override void OnStartup(StartupEventArgs e)
{
@ -49,6 +56,10 @@ namespace AutoTrackR2
// Initialize StreamlinkHandler before creating the main window
_streamlinkHandler = new StreamlinkHandler();
// Initialize KillStreakManager
var soundsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sounds");
_killStreakManager = new KillStreakManager(soundsPath);
// Create and show the main window
var mainWindow = new MainWindow();
mainWindow.Show();
@ -57,8 +68,7 @@ namespace AutoTrackR2
}
catch (Exception ex)
{
MessageBox.Show($"Failed to start AutoTrackR2: {ex.Message}", "AutoTrackR2 Error", MessageBoxButton.OK, MessageBoxImage.Error);
Current.Shutdown();
HandleException(ex);
}
}
@ -110,24 +120,10 @@ namespace AutoTrackR2
protected override void OnExit(ExitEventArgs e)
{
try
{
if (_mutex != null && _mutexOwned)
{
_mutex.ReleaseMutex();
_mutex.Close();
_mutex = null;
}
}
catch (Exception ex)
{
// Log the error but don't prevent shutdown
File.AppendAllText(CrashLogPath, $"[{DateTime.Now}] Error during shutdown: {ex.Message}\n");
}
finally
{
base.OnExit(e);
}
// Clean up resources
_killStreakManager?.Cleanup();
_mutex?.Dispose();
base.OnExit(e);
}
}
}

View file

@ -154,10 +154,10 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Kill Streak Test Button -->
<!--
<Button Grid.Column="0"
Grid.Row="0"
Grid.ColumnSpan="2"
@ -167,12 +167,13 @@
Margin="0,0,0,10"
Style="{StaticResource ButtonStyle}"
Click="TestKillStreakButton_Click"/>
-->
<!-- Left Column Controls -->
<!-- Visor Wipe Toggle -->
<StackPanel Grid.Column="0"
Grid.Row="1"
Grid.Row="0"
Orientation="Horizontal"
Margin="0,0,5,5">
<TextBlock Text="ⓘ"
@ -198,7 +199,7 @@
<!-- Video Record Toggle -->
<StackPanel Grid.Column="0"
Grid.Row="2"
Grid.Row="1"
Orientation="Horizontal"
Margin="0,0,5,5">
<TextBlock Text="ⓘ"
@ -224,7 +225,7 @@
<!-- Offline Mode Toggle -->
<StackPanel Grid.Column="0"
Grid.Row="3"
Grid.Row="2"
Orientation="Horizontal"
Margin="0,0,5,5">
<TextBlock Text="ⓘ"
@ -252,7 +253,7 @@
<!-- Streamlink Toggle -->
<StackPanel Grid.Column="1"
Grid.Row="1"
Grid.Row="0"
Orientation="Horizontal"
Margin="5,0,0,5">
<TextBlock Text="ⓘ"
@ -278,7 +279,7 @@
<!-- Streamlink Duration -->
<StackPanel Grid.Column="1"
Grid.Row="2"
Grid.Row="1"
Orientation="Horizontal"
Margin="5,0,0,5">
<TextBlock Text="ⓘ"
@ -309,7 +310,7 @@
<!-- Test Streamlink Button -->
<Button Grid.Column="1"
Grid.Row="3"
Grid.Row="2"
Content="Test Streamlink"
Width="120"
Height="30"
@ -320,7 +321,7 @@
<!-- Theme Slider -->
<StackPanel Grid.Column="0"
Grid.Row="5"
Grid.Row="3"
Grid.ColumnSpan="2"
Orientation="Horizontal"
Margin="0,0,0,5">

View file

@ -12,6 +12,7 @@ using System.Windows.Media.Effects;
using System.Windows.Threading;
using Microsoft.Win32;
using System.Threading.Tasks;
using AutoTrackR2.Constants;
namespace AutoTrackR2;
@ -418,7 +419,7 @@ public partial class ConfigPage : UserControl
client.DefaultRequestHeaders.UserAgent.ParseAdd("AutoTrackR2");
// Create JSON body with version
var jsonBody = new { version = "2.10" };
var jsonBody = new { version = AppConstants.Version };
var content = new StringContent(JsonSerializer.Serialize(jsonBody), Encoding.UTF8, "application/json");
// Send POST
@ -506,7 +507,7 @@ public partial class ConfigPage : UserControl
client.DefaultRequestHeaders.UserAgent.ParseAdd("AutoTrackR2");
// Create JSON body with version
var jsonBody = new { version = "2.10" };
var jsonBody = new { version = AppConstants.Version };
var content = new StringContent(JsonSerializer.Serialize(jsonBody), Encoding.UTF8, "application/json");
// Send POST to test endpoint

6
AutoTrackR2/Constants.cs Normal file
View file

@ -0,0 +1,6 @@
namespace AutoTrackR2.Constants;
public static class AppConstants
{
public const string Version = "2.11";
}

View file

@ -11,7 +11,7 @@ using System.Windows.Media.Imaging;
using AutoTrackR2.LogEventHandlers;
using System.Timers;
using System.Linq;
using AutoTrackR2.Constants;
namespace AutoTrackR2;
@ -231,7 +231,7 @@ public partial class HomePage : UserControl
Method = actorDeathData.DamageType,
RecordNumber = playerData?.UEERecord,
GameVersion = LocalPlayerData.GameVersion ?? "Unknown",
TrackRver = "2.10",
TrackRver = AppConstants.Version,
Enlisted = playerData?.JoinDate,
KillTime = ((DateTimeOffset)DateTime.ParseExact(actorDeathData.Timestamp, "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal)).ToUnixTimeSeconds().ToString(),
PFP = playerData?.PFPURL ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg",

View file

@ -105,6 +105,17 @@ public class KillStreakManager
}
}
public void Cleanup()
{
lock (_lock)
{
_killStreakTimer.Stop();
_killStreakTimer.Dispose();
_waveOut?.Dispose();
_waveOut = null;
}
}
private void PlayNextSound()
{
if (_soundQueue.Count > 0)