Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions GamesDat/Telemetry/Sources/Formula1/F12022RaceReplaySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
}

Expand All @@ -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;
}
Expand Down
10 changes: 8 additions & 2 deletions GamesDat/Telemetry/Sources/Formula1/F12023RaceReplaySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
}

Expand All @@ -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;
}
Expand Down
10 changes: 8 additions & 2 deletions GamesDat/Telemetry/Sources/Formula1/F12024RaceReplaySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
}

Expand All @@ -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;
}
Expand Down
10 changes: 8 additions & 2 deletions GamesDat/Telemetry/Sources/Formula1/F12025RaceReplaySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
}

Expand All @@ -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;
}
Expand Down
24 changes: 13 additions & 11 deletions GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;

namespace GamesDat.Core.Telemetry.Sources.Formula1
{
Expand All @@ -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))
{
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 17 additions & 3 deletions GamesDat/Telemetry/Sources/Formula1/F1RaceReplaySourceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ namespace GamesDat.Core.Telemetry.Sources.Formula1
/// </summary>
public abstract class F1RaceReplaySourceBase : FileWatcherSourceBase
{
/// <summary>
/// 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.
/// </summary>
private static readonly TimeSpan LibraryDefaultDebounceDelay = TimeSpan.FromSeconds(1);

/// <summary>
/// The F1-specific debounce delay (2 seconds)
/// </summary>
private static readonly TimeSpan F1DebounceDelay = TimeSpan.FromSeconds(2);

protected F1RaceReplaySourceBase(FileWatcherOptions options) : base(options)
{
}
Expand All @@ -33,7 +45,7 @@ protected static FileWatcherOptions CreateDefaultOptions(string path)
Path = path,
Patterns = new[] { "*.frr" },
IncludeSubdirectories = false,
DebounceDelay = TimeSpan.FromSeconds(2)
DebounceDelay = F1DebounceDelay
};
}

Expand All @@ -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
};
}
Expand Down