namespace TravelEar.Core; /// /// Picks the WASAPI render endpoint for the Sink from the user's SinkEndpoint setting. /// Pure: the Helper enumerates device friendly names and passes them in. /// public static class SinkEndpointSelector { /// Index value meaning "use the system default render device". public const int DefaultDevice = -1; // [impl->REQ-SINK-ENDPOINT-CONFIG] /// /// Resolves against (enumeration /// order). Empty or whitespace = . Otherwise an exact /// case-insensitive name match wins, then the first case-insensitive substring match. /// Returns false when nothing matches, so the caller can refuse to render to a guess. /// public static bool TryChoose(IReadOnlyList friendlyNames, string? setting, out int index) { if (string.IsNullOrWhiteSpace(setting)) { index = DefaultDevice; return true; } var wanted = setting.Trim(); for (var i = 0; i < friendlyNames.Count; i++) { if (string.Equals(friendlyNames[i], wanted, StringComparison.OrdinalIgnoreCase)) { index = i; return true; } } for (var i = 0; i < friendlyNames.Count; i++) { if (friendlyNames[i].Contains(wanted, StringComparison.OrdinalIgnoreCase)) { index = i; return true; } } index = DefaultDevice; return false; } }