diff --git a/AutoTrackR2/KillHistoryManager.cs b/AutoTrackR2/KillHistoryManager.cs index a96edd2..16871fa 100644 --- a/AutoTrackR2/KillHistoryManager.cs +++ b/AutoTrackR2/KillHistoryManager.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.IO; using System.Text; +using System.Linq; namespace AutoTrackR2; @@ -157,28 +158,70 @@ public class KillHistoryManager }); } + // Apply KillFeedLimit if specified + if (ConfigManager.KillFeedLimit.HasValue && ConfigManager.KillFeedLimit.Value > 0) + { + kills = kills.TakeLast(ConfigManager.KillFeedLimit.Value).ToList(); + } + return kills; } public List<KillData> GetKillsInCurrentMonth() { string currentMonth = DateTime.Now.ToString("MMM", CultureInfo.InvariantCulture); - var kills = GetKills(); + var kills = new List<KillData>(); - // Because we are not using UTCNOW anymore and users already have kills saved, we need to make sure both formats are compatable. Otherwise people gonna delete their csv. - return kills.Where(kill => + // Read all kills directly from file, ignoring KillFeedLimit + using var reader = new StreamReader(new FileStream(_killHistoryPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); + reader.ReadLine(); // Skip headers + + while (reader.Peek() >= 0) { - if (string.IsNullOrEmpty(kill.KillTime)) return false; + var line = reader.ReadLine(); + + // Remove extra quotes from CSV data + line = line?.Replace("\"", string.Empty); + + var data = line?.Split(','); + + // Check if the kill is from the current month before adding it + var killTime = data?[0]; + if (string.IsNullOrEmpty(killTime)) continue; // Try to parse as Unix timestamp first - if (long.TryParse(kill.KillTime, out long unixTime)) + if (long.TryParse(killTime, out long unixTime)) { var date = DateTimeOffset.FromUnixTimeSeconds(unixTime); - return date.ToString("MMM", CultureInfo.InvariantCulture) == currentMonth; + if (date.ToString("MMM", CultureInfo.InvariantCulture) != currentMonth) continue; + } + else if (!killTime.Contains(currentMonth)) + { + // Fall back to checking if it contains the month name (old format) + continue; } - // Fall back to checking if it contains the month name (old format) - return kill.KillTime.Contains(currentMonth); - }).ToList(); + kills.Add(new KillData + { + KillTime = killTime, + EnemyPilot = data?[1], + EnemyShip = data?[2], + Enlisted = data?[3], + RecordNumber = data?[4], + OrgAffiliation = data?[5], + Player = data?[6], + Weapon = data?[7], + Ship = data?[8], + Method = data?[9], + Mode = data?[10], + GameVersion = data?[11], + TrackRver = data?[12], + Logged = data?[13], + PFP = data?[14], + Hash = data?[15] + }); + } + + return kills; } } \ No newline at end of file diff --git a/AutoTrackR2/MainWindow.xaml.cs b/AutoTrackR2/MainWindow.xaml.cs index 32ac47b..6254e34 100644 --- a/AutoTrackR2/MainWindow.xaml.cs +++ b/AutoTrackR2/MainWindow.xaml.cs @@ -199,6 +199,7 @@ namespace AutoTrackR2 public static int StreamlinkEnabled { get; set; } public static int StreamlinkDuration { get; set; } = 30; public static int KillStreakEnabled { get; set; } = 1; // Default to enabled + public static int? KillFeedLimit { get; set; } = null; // Default to null (load all) static ConfigManager() { @@ -256,6 +257,11 @@ namespace AutoTrackR2 StreamlinkDuration = int.Parse(line.Substring("StreamlinkDuration=".Length).Trim()); else if (line.StartsWith("KillStreakEnabled=")) KillStreakEnabled = int.Parse(line.Substring("KillStreakEnabled=".Length).Trim()); + else if (line.StartsWith("KillFeedLimit=")) + { + var value = line.Substring("KillFeedLimit=".Length).Trim(); + KillFeedLimit = string.IsNullOrEmpty(value) ? null : int.Parse(value); + } } } } @@ -290,6 +296,7 @@ namespace AutoTrackR2 writer.WriteLine($"StreamlinkEnabled={StreamlinkEnabled}"); writer.WriteLine($"StreamlinkDuration={StreamlinkDuration}"); writer.WriteLine($"KillStreakEnabled={KillStreakEnabled}"); + writer.WriteLine($"KillFeedLimit={KillFeedLimit}"); } } }