diff --git a/CHANGELIST.md b/CHANGELIST.md
index 61255452..a69d0770 100644
--- a/CHANGELIST.md
+++ b/CHANGELIST.md
@@ -49,6 +49,7 @@
- Make implicit Result bidirectional
- Rename Result to ResultEventArgs for consistency
- Reduce accessors for DumpEnvironment
+- Better handle interface constants
### 3.1.9a (2024-05-21)
diff --git a/MPF.Core/Data/Constants.cs b/MPF.Core/Data/Constants.cs
deleted file mode 100644
index 7e97848b..00000000
--- a/MPF.Core/Data/Constants.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using SabreTools.RedumpLib.Data;
-
-namespace MPF.Core.Data
-{
- ///
- /// Constant values for UI
- ///
- public static class Interface
- {
- // Lists of known drive speed ranges
-#if NET20 || NET35 || NET40
- public static IList CD { get; } = new List { 1, 2, 3, 4, 6, 8, 12, 16, 20, 24, 32, 40, 44, 48, 52, 56, 72 };
- public static IList DVD { get; } = CD.Where(s => s <= 24).ToList();
- public static IList HDDVD { get; } = CD.Where(s => s <= 24).ToList();
- public static IList BD { get; } = CD.Where(s => s <= 16).ToList();
- public static IList Unknown { get; } = new List { 1 };
-#else
- public static IReadOnlyList CD { get; } = new List { 1, 2, 3, 4, 6, 8, 12, 16, 20, 24, 32, 40, 44, 48, 52, 56, 72 };
- public static IReadOnlyList DVD { get; } = CD.Where(s => s <= 24).ToList();
- public static IReadOnlyList HDDVD { get; } = CD.Where(s => s <= 24).ToList();
- public static IReadOnlyList BD { get; } = CD.Where(s => s <= 16).ToList();
- public static IReadOnlyList Unknown { get; } = new List { 1 };
-#endif
-
- ///
- /// Get list of all drive speeds for a given MediaType
- ///
- /// MediaType? that represents the current item
- /// Read-only list of drive speeds
-#if NET20 || NET35 || NET40
- public static IList GetSpeedsForMediaType(MediaType? type)
-#else
- public static IReadOnlyList GetSpeedsForMediaType(MediaType? type)
-#endif
- {
- return type switch
- {
- MediaType.CDROM
- or MediaType.GDROM => CD,
- MediaType.DVD
- or MediaType.NintendoGameCubeGameDisc
- or MediaType.NintendoWiiOpticalDisc => DVD,
- MediaType.HDDVD => HDDVD,
- MediaType.BluRay => BD,
- _ => Unknown,
- };
- }
- }
-}
diff --git a/MPF.Core/UI/InterfaceConstants.cs b/MPF.Core/UI/InterfaceConstants.cs
new file mode 100644
index 00000000..b9cfaa9b
--- /dev/null
+++ b/MPF.Core/UI/InterfaceConstants.cs
@@ -0,0 +1,62 @@
+using System.Collections.Generic;
+using System.Linq;
+using SabreTools.RedumpLib.Data;
+
+namespace MPF.Core.UI
+{
+ ///
+ /// Constant values for UI
+ ///
+ public static class InterfaceConstants
+ {
+ ///
+ /// Set of all accepted speed values
+ ///
+ private static readonly List _speedValues = [1, 2, 3, 4, 6, 8, 12, 16, 20, 24, 32, 40, 44, 48, 52, 56, 72];
+
+ ///
+ /// Set of accepted speeds for CD and GD media
+ ///
+ public static IList CD => _speedValues.Where(s => s <= 72).ToList();
+
+ ///
+ /// Set of accepted speeds for DVD media
+ ///
+ public static IList DVD => _speedValues.Where(s => s <= 24).ToList();
+
+ ///
+ /// Set of accepted speeds for HD-DVD media
+ ///
+ public static IList HDDVD => _speedValues.Where(s => s <= 24).ToList();
+
+ ///
+ /// Set of accepted speeds for BD media
+ ///
+ public static IList BD => _speedValues.Where(s => s <= 16).ToList();
+
+ ///
+ /// Set of accepted speeds for all other media
+ ///
+ public static IList Unknown => _speedValues.Where(s => s <= 1).ToList();
+
+ ///
+ /// Get list of all drive speeds for a given MediaType
+ ///
+ /// MediaType? that represents the current item
+ /// Read-only list of drive speeds
+ public static IList GetSpeedsForMediaType(MediaType? type)
+ {
+ return type switch
+ {
+ MediaType.CDROM
+ or MediaType.GDROM => CD,
+ MediaType.DVD
+ or MediaType.NintendoGameCubeGameDisc
+ or MediaType.NintendoWiiOpticalDisc => DVD,
+ MediaType.HDDVD => HDDVD,
+ MediaType.BluRay => BD,
+ _ => Unknown,
+ };
+ }
+ }
+}
diff --git a/MPF.Core/UI/ViewModels/MainViewModel.cs b/MPF.Core/UI/ViewModels/MainViewModel.cs
index 85e20ff2..7b7f18f2 100644
--- a/MPF.Core/UI/ViewModels/MainViewModel.cs
+++ b/MPF.Core/UI/ViewModels/MainViewModel.cs
@@ -1606,7 +1606,7 @@ namespace MPF.Core.UI.ViewModels
public void SetSupportedDriveSpeed()
{
// Set the drive speed list that's appropriate
- this.DriveSpeeds = (List)Interface.GetSpeedsForMediaType(CurrentMediaType);
+ this.DriveSpeeds = (List)InterfaceConstants.GetSpeedsForMediaType(CurrentMediaType);
VerboseLogLn($"Supported media speeds: {string.Join(", ", this.DriveSpeeds.Select(ds => ds.ToString()).ToArray())}");
// Set the selected speed
diff --git a/MPF.Test/UI/AllowedSpeedsTest.cs b/MPF.Test/UI/AllowedSpeedsTest.cs
index 799d734f..c1a196d8 100644
--- a/MPF.Test/UI/AllowedSpeedsTest.cs
+++ b/MPF.Test/UI/AllowedSpeedsTest.cs
@@ -14,7 +14,7 @@ namespace MPF.Test.Data
[InlineData(null, 1)]
public void GetAllowedDriveSpeedForMediaTypeTest(MediaType? mediaType, int maxExpected)
{
- var actual = Interface.GetSpeedsForMediaType(mediaType);
+ var actual = InterfaceConstants.GetSpeedsForMediaType(mediaType);
Assert.Equal(maxExpected, actual[actual.Count - 1]);
}
}
diff --git a/MPF.UI.Core/Constants.cs b/MPF.UI.Core/Constants.cs
index 5c2627a6..f27b57a4 100644
--- a/MPF.UI.Core/Constants.cs
+++ b/MPF.UI.Core/Constants.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
-using static MPF.Core.Data.Interface;
+using static MPF.Core.UI.InterfaceConstants;
namespace MPF.UI.Core
{
@@ -11,17 +11,30 @@ namespace MPF.UI.Core
///
public static class Constants
{
- // Create collections for UI based on known drive speeds
- public static DoubleCollection SpeedsForCDAsCollection { get; } = GetDoubleCollectionFromIntList(CD);
- public static DoubleCollection SpeedsForDVDAsCollection { get; } = GetDoubleCollectionFromIntList(DVD);
- public static DoubleCollection SpeedsForHDDVDAsCollection { get; } = GetDoubleCollectionFromIntList(HDDVD);
- public static DoubleCollection SpeedsForBDAsCollection { get; } = GetDoubleCollectionFromIntList(BD);
+ ///
+ /// Set of accepted speeds for CD and GD media
+ ///
+ public static DoubleCollection SpeedsForCDAsCollection => GetDoubleCollectionFromIntList(CD);
-#if NET20 || NET35 || NET40
+ ///
+ /// Set of accepted speeds for DVD media
+ ///
+ public static DoubleCollection SpeedsForDVDAsCollection => GetDoubleCollectionFromIntList(DVD);
+
+ ///
+ /// Set of accepted speeds for HD-DVD media
+ ///
+ public static DoubleCollection SpeedsForHDDVDAsCollection => GetDoubleCollectionFromIntList(HDDVD);
+
+ ///
+ /// Set of accepted speeds for BD media
+ ///
+ public static DoubleCollection SpeedsForBDAsCollection => GetDoubleCollectionFromIntList(BD);
+
+ ///
+ /// Create a DoubleCollection out of a list of integer values
+ ///
private static DoubleCollection GetDoubleCollectionFromIntList(IList list)
-#else
- private static DoubleCollection GetDoubleCollectionFromIntList(IReadOnlyList list)
-#endif
=> new(list.Select(i => Convert.ToDouble(i)).ToList());
}
}