diff --git a/AutoTrackR2/App.xaml.cs b/AutoTrackR2/App.xaml.cs index 55a1e85..7441812 100644 --- a/AutoTrackR2/App.xaml.cs +++ b/AutoTrackR2/App.xaml.cs @@ -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); } } } diff --git a/AutoTrackR2/ConfigPage.xaml b/AutoTrackR2/ConfigPage.xaml index ef9c43d..55374eb 100644 --- a/AutoTrackR2/ConfigPage.xaml +++ b/AutoTrackR2/ConfigPage.xaml @@ -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"> diff --git a/AutoTrackR2/ConfigPage.xaml.cs b/AutoTrackR2/ConfigPage.xaml.cs index 6912307..e7cd94b 100644 --- a/AutoTrackR2/ConfigPage.xaml.cs +++ b/AutoTrackR2/ConfigPage.xaml.cs @@ -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 diff --git a/AutoTrackR2/Constants.cs b/AutoTrackR2/Constants.cs new file mode 100644 index 0000000..14a8c8a --- /dev/null +++ b/AutoTrackR2/Constants.cs @@ -0,0 +1,6 @@ +namespace AutoTrackR2.Constants; + +public static class AppConstants +{ + public const string Version = "2.11"; +} \ No newline at end of file diff --git a/AutoTrackR2/HomePage.xaml.cs b/AutoTrackR2/HomePage.xaml.cs index 61778db..b202b55 100644 --- a/AutoTrackR2/HomePage.xaml.cs +++ b/AutoTrackR2/HomePage.xaml.cs @@ -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", diff --git a/AutoTrackR2/KillStreakManager.cs b/AutoTrackR2/KillStreakManager.cs index 40961ca..6d4fb28 100644 --- a/AutoTrackR2/KillStreakManager.cs +++ b/AutoTrackR2/KillStreakManager.cs @@ -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)