diff --git a/GamesDat/Telemetry/Sources/Formula1/F12022RaceReplaySource.cs b/GamesDat/Telemetry/Sources/Formula1/F12022RaceReplaySource.cs index 8be9015..652116a 100644 --- a/GamesDat/Telemetry/Sources/Formula1/F12022RaceReplaySource.cs +++ b/GamesDat/Telemetry/Sources/Formula1/F12022RaceReplaySource.cs @@ -7,7 +7,7 @@ namespace GamesDat.Core.Telemetry.Sources.Formula1 public class F12022RaceReplaySource : F1RaceReplaySourceBase { public F12022RaceReplaySource(FileWatcherOptions options) - : base(ApplyDefaults(EnsurePath(options))) + : base(ApplyDefaults(options)) { } @@ -25,7 +25,13 @@ private static FileWatcherOptions EnsurePath(FileWatcherOptions options) { if (string.IsNullOrEmpty(options.Path)) { - options.Path = GetDefaultReplayPath(); + return new FileWatcherOptions + { + Path = GetDefaultReplayPath(), + Patterns = options.Patterns, + IncludeSubdirectories = options.IncludeSubdirectories, + DebounceDelay = options.DebounceDelay + }; } return options; } diff --git a/GamesDat/Telemetry/Sources/Formula1/F12023RaceReplaySource.cs b/GamesDat/Telemetry/Sources/Formula1/F12023RaceReplaySource.cs index fc1bf97..d46325e 100644 --- a/GamesDat/Telemetry/Sources/Formula1/F12023RaceReplaySource.cs +++ b/GamesDat/Telemetry/Sources/Formula1/F12023RaceReplaySource.cs @@ -7,7 +7,7 @@ namespace GamesDat.Core.Telemetry.Sources.Formula1 public class F12023RaceReplaySource : F1RaceReplaySourceBase { public F12023RaceReplaySource(FileWatcherOptions options) - : base(ApplyDefaults(EnsurePath(options))) + : base(ApplyDefaults(options)) { } @@ -25,7 +25,13 @@ private static FileWatcherOptions EnsurePath(FileWatcherOptions options) { if (string.IsNullOrEmpty(options.Path)) { - options.Path = GetDefaultReplayPath(); + return new FileWatcherOptions + { + Path = GetDefaultReplayPath(), + Patterns = options.Patterns, + IncludeSubdirectories = options.IncludeSubdirectories, + DebounceDelay = options.DebounceDelay + }; } return options; } diff --git a/GamesDat/Telemetry/Sources/Formula1/F12024RaceReplaySource.cs b/GamesDat/Telemetry/Sources/Formula1/F12024RaceReplaySource.cs index 4e8b4e9..a685f40 100644 --- a/GamesDat/Telemetry/Sources/Formula1/F12024RaceReplaySource.cs +++ b/GamesDat/Telemetry/Sources/Formula1/F12024RaceReplaySource.cs @@ -7,7 +7,7 @@ namespace GamesDat.Core.Telemetry.Sources.Formula1 public class F12024RaceReplaySource : F1RaceReplaySourceBase { public F12024RaceReplaySource(FileWatcherOptions options) - : base(ApplyDefaults(EnsurePath(options))) + : base(ApplyDefaults(options)) { } @@ -25,7 +25,13 @@ private static FileWatcherOptions EnsurePath(FileWatcherOptions options) { if (string.IsNullOrEmpty(options.Path)) { - options.Path = GetDefaultReplayPath(); + return new FileWatcherOptions + { + Path = GetDefaultReplayPath(), + Patterns = options.Patterns, + IncludeSubdirectories = options.IncludeSubdirectories, + DebounceDelay = options.DebounceDelay + }; } return options; } diff --git a/GamesDat/Telemetry/Sources/Formula1/F12025RaceReplaySource.cs b/GamesDat/Telemetry/Sources/Formula1/F12025RaceReplaySource.cs index fa8014d..905e589 100644 --- a/GamesDat/Telemetry/Sources/Formula1/F12025RaceReplaySource.cs +++ b/GamesDat/Telemetry/Sources/Formula1/F12025RaceReplaySource.cs @@ -7,7 +7,7 @@ namespace GamesDat.Core.Telemetry.Sources.Formula1 public class F12025RaceReplaySource : F1RaceReplaySourceBase { public F12025RaceReplaySource(FileWatcherOptions options) - : base(ApplyDefaults(EnsurePath(options))) + : base(ApplyDefaults(options)) { } @@ -25,7 +25,13 @@ private static FileWatcherOptions EnsurePath(FileWatcherOptions options) { if (string.IsNullOrEmpty(options.Path)) { - options.Path = GetDefaultReplayPath(); + return new FileWatcherOptions + { + Path = GetDefaultReplayPath(), + Patterns = options.Patterns, + IncludeSubdirectories = options.IncludeSubdirectories, + DebounceDelay = options.DebounceDelay + }; } return options; } diff --git a/GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySource.cs b/GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySource.cs index 60bdf68..97ffaec 100644 --- a/GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySource.cs +++ b/GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySource.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; namespace GamesDat.Core.Telemetry.Sources.Formula1 { @@ -12,7 +13,7 @@ namespace GamesDat.Core.Telemetry.Sources.Formula1 public class F1RaceReplaySource : F1RaceReplaySourceBase { public F1RaceReplaySource(FileWatcherOptions options) - : base(ApplyDefaults(EnsurePath(options))) + : base(ApplyDefaults(options)) { } @@ -23,7 +24,13 @@ private static FileWatcherOptions EnsurePath(FileWatcherOptions options) { if (string.IsNullOrEmpty(options.Path)) { - options.Path = F12025RaceReplaySource.GetDefaultReplayPath(); + return new FileWatcherOptions + { + Path = F12025RaceReplaySource.GetDefaultReplayPath(), + Patterns = options.Patterns, + IncludeSubdirectories = options.IncludeSubdirectories, + DebounceDelay = options.DebounceDelay + }; } return options; } @@ -60,17 +67,12 @@ public F1RaceReplaySource(string? customPath = null, bool autoDetectLatestInstal public static string GetLatestInstalledReplayPath() { var years = new[] { "25", "24", "23", "22" }; - foreach (var year in years) - { - var path = GetReplayPathForYear(year); - if (Directory.Exists(path)) - { - return path; - } - } + var existingPath = years + .Select(GetReplayPathForYear) + .FirstOrDefault(Directory.Exists); // Default to F1 25 even if it doesn't exist - return GetReplayPathForYear("25"); + return existingPath ?? GetReplayPathForYear("25"); } private static string ResolveReplayPath(string? customPath, bool autoDetectLatestInstalled) diff --git a/GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySourceBase.cs b/GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySourceBase.cs index e73c7dc..f459d5f 100644 --- a/GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySourceBase.cs +++ b/GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySourceBase.cs @@ -8,6 +8,18 @@ namespace GamesDat.Core.Telemetry.Sources.Formula1 /// public abstract class F1RaceReplaySourceBase : FileWatcherSourceBase { + /// + /// The default debounce delay used by FileWatcherOptions (1 second). + /// Note: This mirrors the default in FileWatcherOptions.DebounceDelay. + /// If that default changes, this constant should be updated to match. + /// + private static readonly TimeSpan LibraryDefaultDebounceDelay = TimeSpan.FromSeconds(1); + + /// + /// The F1-specific debounce delay (2 seconds) + /// + private static readonly TimeSpan F1DebounceDelay = TimeSpan.FromSeconds(2); + protected F1RaceReplaySourceBase(FileWatcherOptions options) : base(options) { } @@ -33,7 +45,7 @@ protected static FileWatcherOptions CreateDefaultOptions(string path) Path = path, Patterns = new[] { "*.frr" }, IncludeSubdirectories = false, - DebounceDelay = TimeSpan.FromSeconds(2) + DebounceDelay = F1DebounceDelay }; } @@ -54,8 +66,10 @@ protected static FileWatcherOptions ApplyDefaults(FileWatcherOptions options) ? new[] { "*.frr" } : options.Patterns, IncludeSubdirectories = options.IncludeSubdirectories, - DebounceDelay = options.DebounceDelay == default - ? TimeSpan.FromSeconds(2) + // Check for both default (00:00:00, used when constructed via string path) + // and LibraryDefaultDebounceDelay (1s, used when constructed via options without explicit delay) + DebounceDelay = options.DebounceDelay == default || options.DebounceDelay == LibraryDefaultDebounceDelay + ? F1DebounceDelay : options.DebounceDelay }; }