Fixed all the cursed warnings when building.

Fixed all the values that can be nullable on the client.
This commit is contained in:
Heavy Bob 2025-04-07 10:18:52 +10:00
parent 2cd80970a4
commit 1acae27793
6 changed files with 52 additions and 29 deletions

View file

@ -399,11 +399,14 @@ namespace AutoTrackR2
dialog.ValidateNames = false; dialog.ValidateNames = false;
dialog.Filter = "All files|*.*"; dialog.Filter = "All files|*.*";
if (dialog.ShowDialog() == true) if (dialog.ShowDialog() == true && dialog.FileName != null)
{ {
// Extract only the directory path from the file // Extract only the directory path from the file
string selectedFolder = Path.GetDirectoryName(dialog.FileName); string? selectedFolder = Path.GetDirectoryName(dialog.FileName);
VideoPath.Text = selectedFolder; // Set the folder path if (selectedFolder != null)
{
VideoPath.Text = selectedFolder; // Set the folder path
}
} }
} }
@ -412,6 +415,11 @@ namespace AutoTrackR2
Slider slider = (Slider)sender; Slider slider = (Slider)sender;
// Build the dynamic file path for the current user // Build the dynamic file path for the current user
if (string.IsNullOrEmpty(ConfigManager.AHKScriptFolder))
{
MessageBox.Show("AHK script folder path is not configured.", "Configuration Error", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
string filePath = Path.Combine( string filePath = Path.Combine(
ConfigManager.AHKScriptFolder, ConfigManager.AHKScriptFolder,
"visorwipe.ahk" "visorwipe.ahk"
@ -524,7 +532,7 @@ namespace AutoTrackR2
private void FlashSaveButton() private void FlashSaveButton()
{ {
string originalText = SaveButton.Content.ToString(); string? originalText = SaveButton.Content?.ToString() ?? string.Empty;
SaveButton.Content = "Saved"; SaveButton.Content = "Saved";
// Save button color change effect // Save button color change effect

View file

@ -26,6 +26,10 @@ public partial class HomePage : UserControl
{ {
InitializeComponent(); InitializeComponent();
if (string.IsNullOrEmpty(ConfigManager.KillHistoryFile))
{
throw new InvalidOperationException("KillHistoryFile path is not configured.");
}
_killHistoryManager = new KillHistoryManager(ConfigManager.KillHistoryFile); _killHistoryManager = new KillHistoryManager(ConfigManager.KillHistoryFile);
// Set the TextBlock text // Set the TextBlock text
@ -51,7 +55,7 @@ public partial class HomePage : UserControl
} }
} }
private void CheckStarCitizenStatus(object sender, ElapsedEventArgs e) private void CheckStarCitizenStatus(object? sender, ElapsedEventArgs e)
{ {
bool isRunning = IsStarCitizenRunning(); bool isRunning = IsStarCitizenRunning();
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
@ -311,7 +315,7 @@ public partial class HomePage : UserControl
// Create the Image for the profile // Create the Image for the profile
var profileImage = new Image var profileImage = new Image
{ {
Source = new BitmapImage(new Uri(killData.PFP)), // Assuming the 8th part contains the profile image URL Source = new BitmapImage(new Uri(killData.PFP ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg")),
Width = 90, Width = 90,
Height = 90, Height = 90,
Stretch = Stretch.Fill, // Adjust how the image fits Stretch = Stretch.Fill, // Adjust how the image fits
@ -392,8 +396,13 @@ public partial class HomePage : UserControl
textBlock.FontSize = fontSize; textBlock.FontSize = fontSize;
} }
public static void RunAHKScript(string path) public static void RunAHKScript(string? path)
{ {
if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(ConfigManager.AHKScriptFolder))
{
return;
}
string scriptPath = Path.Combine(ConfigManager.AHKScriptFolder, path); string scriptPath = Path.Combine(ConfigManager.AHKScriptFolder, path);
if (!File.Exists(scriptPath)) if (!File.Exists(scriptPath))

View file

@ -19,7 +19,7 @@ public struct VehicleDestructionData
public class VehicleDestructionEvent : ILogEventHandler public class VehicleDestructionEvent : ILogEventHandler
{ {
public Regex Pattern { get; } public Regex Pattern { get; }
public VehicleDestructionEvent() public VehicleDestructionEvent()
{ {
Pattern = new Regex(""" Pattern = new Regex("""
@ -34,6 +34,10 @@ public class VehicleDestructionEvent : ILogEventHandler
public void Handle(LogEntry entry) public void Handle(LogEntry entry)
{ {
if (entry.Message == null)
{
return;
}
var match = Pattern.Match(entry.Message); var match = Pattern.Match(entry.Message);
if (!match.Success) if (!match.Success)
{ {

View file

@ -46,8 +46,12 @@ public class LogHandler
new RequestJumpFailedEvent() new RequestJumpFailedEvent()
]; ];
public LogHandler(string logPath) public LogHandler(string? logPath)
{ {
if (string.IsNullOrEmpty(logPath))
{
throw new ArgumentNullException(nameof(logPath), "Log path cannot be null or empty");
}
_logPath = logPath; _logPath = logPath;
} }

View file

@ -58,7 +58,7 @@ namespace AutoTrackR2
} }
} }
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
{ {
// Clean up resources // Clean up resources
homePage?.Cleanup(); homePage?.Cleanup();
@ -163,10 +163,10 @@ namespace AutoTrackR2
// Set the fields in ConfigPage.xaml.cs based on the loaded config // Set the fields in ConfigPage.xaml.cs based on the loaded config
configPage.SetConfigValues( configPage.SetConfigValues(
ConfigManager.LogFile, ConfigManager.LogFile ?? string.Empty,
ConfigManager.ApiUrl, ConfigManager.ApiUrl ?? string.Empty,
ConfigManager.ApiKey, ConfigManager.ApiKey ?? string.Empty,
ConfigManager.VideoPath, ConfigManager.VideoPath ?? string.Empty,
ConfigManager.VisorWipe, ConfigManager.VisorWipe,
ConfigManager.VideoRecord, ConfigManager.VideoRecord,
ConfigManager.OfflineMode, ConfigManager.OfflineMode,
@ -177,17 +177,14 @@ namespace AutoTrackR2
public static class ConfigManager public static class ConfigManager
{ {
public static string LogFile { get; set; } public static string? LogFile { get; set; } = string.Empty;
public static string KillHistoryFile { get; set; } public static string? KillHistoryFile { get; set; } = string.Empty;
public static string? AHKScriptFolder { get; set; } = string.Empty;
public static string AHKScriptFolder { get; set; } public static string? VisorWipeScript { get; set; } = string.Empty;
public static string? VideoRecordScript { get; set; } = string.Empty;
public static string VisorWipeScript { get; set; } public static string? ApiUrl { get; set; } = string.Empty;
public static string VideoRecordScript { get; set; } public static string? ApiKey { get; set; } = string.Empty;
public static string? VideoPath { get; set; } = string.Empty;
public static string ApiUrl { get; set; }
public static string ApiKey { get; set; }
public static string VideoPath { get; set; }
public static int VisorWipe { get; set; } public static int VisorWipe { get; set; }
public static int VideoRecord { get; set; } public static int VideoRecord { get; set; }
public static int OfflineMode { get; set; } public static int OfflineMode { get; set; }

View file

@ -10,7 +10,7 @@ namespace AutoTrackR2
public partial class UpdatePage : UserControl public partial class UpdatePage : UserControl
{ {
public static string currentVersion = "v2.09"; public static string currentVersion = "v2.09";
private string latestVersion; private string? latestVersion = string.Empty;
public UpdatePage() public UpdatePage()
{ {
@ -60,7 +60,7 @@ namespace AutoTrackR2
// Parse the JSON using System.Text.Json // Parse the JSON using System.Text.Json
using var document = System.Text.Json.JsonDocument.Parse(response); using var document = System.Text.Json.JsonDocument.Parse(response);
var root = document.RootElement; var root = document.RootElement;
var tagName = root.GetProperty("tag_name").GetString(); var tagName = root.GetProperty("tag_name").GetString() ?? "unknown";
return tagName; return tagName;
} }
@ -77,7 +77,8 @@ namespace AutoTrackR2
if (root.GetArrayLength() > 0) if (root.GetArrayLength() > 0)
{ {
var firstRelease = root[0]; var firstRelease = root[0];
return firstRelease.GetProperty("tag_name").GetString(); var tagName = firstRelease.GetProperty("tag_name").GetString() ?? "unknown";
return tagName;
} }
throw new Exception("No releases found."); throw new Exception("No releases found.");
@ -90,7 +91,7 @@ namespace AutoTrackR2
return !currentVersion.Equals(latestVersion, StringComparison.Ordinal); return !currentVersion.Equals(latestVersion, StringComparison.Ordinal);
} }
private async void InstallButton_Click(object sender, RoutedEventArgs e) private void InstallButton_Click(object sender, RoutedEventArgs e)
{ {
try try
{ {