diff --git a/CHANGELIST.md b/CHANGELIST.md
index 7c71613e..77f7eea5 100644
--- a/CHANGELIST.md
+++ b/CHANGELIST.md
@@ -73,6 +73,7 @@
- Remove automatic eject and reset options
- Remove options from UI
- Remove firmware output for Redumper (Deterous)
+- Merge EnumConverter and EnumExtensions
### 3.1.9a (2024-05-21)
diff --git a/MPF.Core/Data/Drive.cs b/MPF.Core/Data/Drive.cs
index 255ee836..499e910e 100644
--- a/MPF.Core/Data/Drive.cs
+++ b/MPF.Core/Data/Drive.cs
@@ -6,6 +6,7 @@ using System.Linq;
using Microsoft.Management.Infrastructure;
using Microsoft.Management.Infrastructure.Generic;
#endif
+using MPF.Core.Utilities;
using SabreTools.IO;
using SabreTools.RedumpLib.Data;
@@ -633,7 +634,7 @@ namespace MPF.Core.Data
{
drives = DriveInfo.GetDrives()
.Where(d => desiredDriveTypes.Contains(d.DriveType))
- .Select(d => Create(EnumConverter.ToInternalDriveType(d.DriveType), d.Name) ?? new Drive())
+ .Select(d => Create(EnumExtensions.ToInternalDriveType(d.DriveType), d.Name) ?? new Drive())
.ToList();
}
catch
diff --git a/MPF.Core/Data/EnumConverter.cs b/MPF.Core/Data/EnumConverter.cs
deleted file mode 100644
index d91b6a40..00000000
--- a/MPF.Core/Data/EnumConverter.cs
+++ /dev/null
@@ -1,392 +0,0 @@
-using System;
-#if NET20 || NET35
-using System.Collections.Generic;
-#else
-using System.Collections.Concurrent;
-#endif
-using System.IO;
-using System.Reflection;
-using SabreTools.RedumpLib.Data;
-
-namespace MPF.Core.Data
-{
- public static class EnumConverter
- {
- #region Cross-enumeration conversions
-
- ///
- /// Convert drive type to internal version, if possible
- ///
- /// DriveType value to check
- /// InternalDriveType, if possible, null on error
- public static InternalDriveType? ToInternalDriveType(this DriveType driveType)
- {
- return driveType switch
- {
- DriveType.CDRom => (InternalDriveType?)InternalDriveType.Optical,
- DriveType.Fixed => (InternalDriveType?)InternalDriveType.HardDisk,
- DriveType.Removable => (InternalDriveType?)InternalDriveType.Removable,
- _ => null,
- };
- }
-
- #endregion
-
- #region Convert to Long Name
-
- ///
- /// Long name method cache
- ///
-#if NET20 || NET35
- private static readonly Dictionary LongNameMethods = [];
-#else
- private static readonly ConcurrentDictionary LongNameMethods = [];
-#endif
-
- ///
- /// Get the string representation of a generic enumerable value
- ///
- /// Enum value to convert
- /// String representation of that value if possible, empty string on error
- public static string GetLongName(Enum value)
- {
- try
- {
- var sourceType = value.GetType();
- sourceType = Nullable.GetUnderlyingType(sourceType) ?? sourceType;
-
- if (!LongNameMethods.TryGetValue(sourceType, out var method))
- {
- method = typeof(Extensions).GetMethod("LongName", [typeof(Nullable<>).MakeGenericType(sourceType)]);
- method ??= typeof(EnumConverter).GetMethod("LongName", [typeof(Nullable<>).MakeGenericType(sourceType)]);
-
-#if NET20 || NET35
- LongNameMethods[sourceType] = method;
-#else
- LongNameMethods.TryAdd(sourceType, method);
-#endif
- }
-
- if (method != null)
- return method.Invoke(null, new[] { value }) as string ?? string.Empty;
- else
- return string.Empty;
- }
- catch
- {
- // Converter is not implemented for the given type
- return string.Empty;
- }
- }
-
- ///
- /// Get the string representation of the InternalProgram enum values
- ///
- /// InternalProgram value to convert
- /// String representing the value, if possible
- public static string LongName(this InternalProgram? prog)
- {
- return (prog) switch
- {
- #region Dumping support
-
- InternalProgram.Aaru => "Aaru",
- InternalProgram.DiscImageCreator => "DiscImageCreator",
- InternalProgram.Redumper => "Redumper",
-
- #endregion
-
- #region Verification support only
-
- InternalProgram.CleanRip => "CleanRip",
- InternalProgram.PS3CFW => "PS3 CFW",
- InternalProgram.UmdImageCreator => "UmdImageCreator",
- InternalProgram.XboxBackupCreator => "XboxBackupCreator",
-
- #endregion
-
- InternalProgram.NONE => "Unknown",
- _ => "Unknown",
- };
- }
-
- ///
- /// Get the string representation of the RedumperReadMethod enum values
- ///
- /// RedumperReadMethod value to convert
- /// String representing the value, if possible
- public static string LongName(this RedumperReadMethod? method)
- {
- return (method) switch
- {
- RedumperReadMethod.D8 => "D8",
- RedumperReadMethod.BE => "BE",
- RedumperReadMethod.BE_CDDA => "BE_CDDA",
-
- RedumperReadMethod.NONE => "Default",
- _ => "Unknown",
- };
- }
-
- ///
- /// Get the string representation of the RedumperSectorOrder enum values
- ///
- /// RedumperSectorOrder value to convert
- /// String representing the value, if possible
- public static string LongName(this RedumperSectorOrder? order)
- {
- return (order) switch
- {
- RedumperSectorOrder.DATA_C2_SUB => "DATA_C2_SUB",
- RedumperSectorOrder.DATA_SUB_C2 => "DATA_SUB_C2",
- RedumperSectorOrder.DATA_SUB => "DATA_SUB",
- RedumperSectorOrder.DATA_C2 => "DATA_C2",
-
- RedumperSectorOrder.NONE => "Default",
- _ => "Unknown",
- };
- }
-
- #endregion
-
- #region Convert From String
-
- ///
- /// Get the InternalProgram enum value for a given string
- ///
- /// String value to convert
- /// InternalProgram represented by the string, if possible
- public static InternalProgram ToInternalProgram(string? internalProgram)
- {
- return (internalProgram?.ToLowerInvariant()) switch
- {
- // Dumping support
- "aaru"
- or "chef"
- or "dichef"
- or "discimagechef" => InternalProgram.Aaru,
- "creator"
- or "dic"
- or "dicreator"
- or "discimagecreator" => InternalProgram.DiscImageCreator,
- "rd"
- or "redumper" => InternalProgram.Redumper,
-
- // Verification support only
- "cleanrip"
- or "cr" => InternalProgram.CleanRip,
- "ps3cfw"
- or "ps3"
- or "getkey"
- or "managunz"
- or "multiman" => InternalProgram.PS3CFW,
- "uic"
- or "umd"
- or "umdcreator"
- or "umdimagecreator" => InternalProgram.UmdImageCreator,
- "xbc"
- or "xbox"
- or "xbox360"
- or "xboxcreator"
- or "xboxbackupcreator" => InternalProgram.XboxBackupCreator,
-
- _ => InternalProgram.NONE,
- };
- }
-
- ///
- /// Get the MediaType enum value for a given string
- ///
- /// String value to convert
- /// MediaType represented by the string, if possible
- public static MediaType ToMediaType(string type)
- {
- return (type.ToLowerInvariant()) switch
- {
- #region Punched Media
-
- "aperture"
- or "aperturecard"
- or "aperture card" => MediaType.ApertureCard,
- "jacquardloom"
- or "jacquardloomcard"
- or "jacquard loom card" => MediaType.JacquardLoomCard,
- "magneticstripe"
- or "magneticstripecard"
- or "magnetic stripe card" => MediaType.MagneticStripeCard,
- "opticalphone"
- or "opticalphonecard"
- or "optical phonecard" => MediaType.OpticalPhonecard,
- "punchcard"
- or "punchedcard"
- or "punched card" => MediaType.PunchedCard,
- "punchtape"
- or "punchedtape"
- or "punched tape" => MediaType.PunchedTape,
-
- #endregion
-
- #region Tape
-
- "openreel"
- or "openreeltape"
- or "open reel tape" => MediaType.OpenReel,
- "datacart"
- or "datacartridge"
- or "datatapecartridge"
- or "data tape cartridge" => MediaType.DataCartridge,
- "cassette"
- or "cassettetape"
- or "cassette tape" => MediaType.Cassette,
-
- #endregion
-
- #region Disc / Disc
-
- "bd"
- or "bdrom"
- or "bd-rom"
- or "bluray" => MediaType.BluRay,
- "cd"
- or "cdrom"
- or "cd-rom" => MediaType.CDROM,
- "dvd"
- or "dvd5"
- or "dvd-5"
- or "dvd9"
- or "dvd-9"
- or "dvdrom"
- or "dvd-rom" => MediaType.DVD,
- "fd"
- or "floppy"
- or "floppydisk"
- or "floppy disk"
- or "floppy diskette" => MediaType.FloppyDisk,
- "floptical" => MediaType.Floptical,
- "gd"
- or "gdrom"
- or "gd-rom" => MediaType.GDROM,
- "hddvd"
- or "hd-dvd"
- or "hddvdrom"
- or "hd-dvd-rom" => MediaType.HDDVD,
- "hdd"
- or "harddisk"
- or "hard disk" => MediaType.HardDisk,
- "bernoullidisk"
- or "iomegabernoullidisk"
- or "bernoulli disk"
- or "iomega bernoulli disk" => MediaType.IomegaBernoulliDisk,
- "jaz"
- or "iomegajaz"
- or "iomega jaz" => MediaType.IomegaJaz,
- "zip"
- or "zipdisk"
- or "iomegazip"
- or "iomega zip" => MediaType.IomegaZip,
- "ldrom"
- or "lvrom"
- or "ld-rom"
- or "lv-rom"
- or "laserdisc"
- or "laservision"
- or "ld-rom / lv-rom" => MediaType.LaserDisc,
- "64dd"
- or "n64dd"
- or "64dddisk"
- or "n64dddisk"
- or "64dd disk"
- or "n64dd disk" => MediaType.Nintendo64DD,
- "fds"
- or "famicom"
- or "nfds"
- or "nintendofamicom"
- or "famicomdisksystem"
- or "famicom disk system"
- or "famicom disk system disk" => MediaType.NintendoFamicomDiskSystem,
- "gc"
- or "gamecube"
- or "nintendogamecube"
- or "nintendo gamecube"
- or "gamecube disc"
- or "gamecube game disc" => MediaType.NintendoGameCubeGameDisc,
- "wii"
- or "nintendowii"
- or "nintendo wii"
- or "nintendo wii disc"
- or "wii optical disc" => MediaType.NintendoWiiOpticalDisc,
- "wiiu"
- or "nintendowiiu"
- or "nintendo wiiu"
- or "nintendo wiiu disc"
- or "wiiu optical disc"
- or "wii u optical disc" => MediaType.NintendoWiiUOpticalDisc,
- "umd" => MediaType.UMD,
-
- #endregion
-
- // Unsorted Formats
- "cartridge" => MediaType.Cartridge,
- "ced"
- or "rcaced"
- or "rca ced"
- or "videodisc"
- or "rca videodisc" => MediaType.CED,
-
- _ => MediaType.NONE,
- };
- }
-
- ///
- /// Get the RedumperReadMethod enum value for a given string
- ///
- /// String value to convert
- /// RedumperReadMethod represented by the string, if possible
- public static RedumperReadMethod ToRedumperReadMethod(string? method)
- {
- return (method?.ToLowerInvariant()) switch
- {
- "d8" => RedumperReadMethod.D8,
- "be" => RedumperReadMethod.BE,
- "be_cdda"
- or "be cdda"
- or "be-cdda"
- or "becdda" => RedumperReadMethod.BE_CDDA,
-
- _ => RedumperReadMethod.NONE,
- };
- }
-
- ///
- /// Get the RedumperSectorOrder enum value for a given string
- ///
- /// String value to convert
- /// RedumperSectorOrder represented by the string, if possible
- public static RedumperSectorOrder ToRedumperSectorOrder(string? order)
- {
- return (order?.ToLowerInvariant()) switch
- {
- "data_c2_sub"
- or "data c2 sub"
- or "data-c2-sub"
- or "datac2sub" => RedumperSectorOrder.DATA_C2_SUB,
- "data_sub_c2"
- or "data sub c2"
- or "data-sub-c2"
- or "datasubc2" => RedumperSectorOrder.DATA_SUB_C2,
- "data_sub"
- or "data sub"
- or "data-sub"
- or "datasub" => RedumperSectorOrder.DATA_SUB,
- "data_c2"
- or "data c2"
- or "data-c2"
- or "datac2" => RedumperSectorOrder.DATA_C2,
-
- _ => RedumperSectorOrder.NONE,
- };
- }
-
- #endregion
- }
-}
diff --git a/MPF.Core/Data/Options.cs b/MPF.Core/Data/Options.cs
index 77f34dfd..397e7f64 100644
--- a/MPF.Core/Data/Options.cs
+++ b/MPF.Core/Data/Options.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using MPF.Core.Utilities;
using SabreTools.RedumpLib.Data;
namespace MPF.Core.Data
@@ -56,7 +57,7 @@ namespace MPF.Core.Data
get
{
var valueString = GetStringSetting(Settings, "InternalProgram", InternalProgram.Redumper.ToString());
- var valueEnum = EnumConverter.ToInternalProgram(valueString);
+ var valueEnum = EnumExtensions.ToInternalProgram(valueString);
return valueEnum == InternalProgram.NONE ? InternalProgram.Redumper : valueEnum;
}
set
@@ -359,7 +360,7 @@ namespace MPF.Core.Data
get
{
var valueString = GetStringSetting(Settings, "RedumperReadMethod", RedumperReadMethod.NONE.ToString());
- return EnumConverter.ToRedumperReadMethod(valueString);
+ return EnumExtensions.ToRedumperReadMethod(valueString);
}
set
{
@@ -375,7 +376,7 @@ namespace MPF.Core.Data
get
{
var valueString = GetStringSetting(Settings, "RedumperSectorOrder", RedumperSectorOrder.NONE.ToString());
- return EnumConverter.ToRedumperSectorOrder(valueString);
+ return EnumExtensions.ToRedumperSectorOrder(valueString);
}
set
{
diff --git a/MPF.Core/Processors/Aaru.cs b/MPF.Core/Processors/Aaru.cs
index 016f7c81..b7178c68 100644
--- a/MPF.Core/Processors/Aaru.cs
+++ b/MPF.Core/Processors/Aaru.cs
@@ -7,6 +7,7 @@ using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using MPF.Core.Data;
+using MPF.Core.Utilities;
using SabreTools.Models.CueSheets;
using SabreTools.Models.Logiqx;
using SabreTools.RedumpLib;
@@ -109,7 +110,7 @@ namespace MPF.Core.Processors
info = Builder.EnsureAllSections(info);
// TODO: Determine if there's an Aaru version anywhere
- info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(InternalProgram.Aaru);
+ info.DumpingInfo!.DumpingProgram = EnumExtensions.LongName(InternalProgram.Aaru);
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate(basePath + ".cicm.xml")?.ToString("yyyy-MM-dd HH:mm:ss");
// Deserialize the sidecar, if possible
diff --git a/MPF.Core/Processors/CleanRip.cs b/MPF.Core/Processors/CleanRip.cs
index ad9d2d0f..09a76e0b 100644
--- a/MPF.Core/Processors/CleanRip.cs
+++ b/MPF.Core/Processors/CleanRip.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using MPF.Core.Data;
+using MPF.Core.Utilities;
using SabreTools.Hashing;
using SabreTools.Models.Logiqx;
using SabreTools.RedumpLib;
@@ -65,7 +66,7 @@ namespace MPF.Core.Processors
info = Builder.EnsureAllSections(info);
// TODO: Determine if there's a CleanRip version anywhere
- info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(InternalProgram.CleanRip);
+ info.DumpingInfo!.DumpingProgram = EnumExtensions.LongName(InternalProgram.CleanRip);
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate(basePath + "-dumpinfo.txt")?.ToString("yyyy-MM-dd HH:mm:ss");
// Get the Datafile information
diff --git a/MPF.Core/Processors/DiscImageCreator.cs b/MPF.Core/Processors/DiscImageCreator.cs
index e1a35791..96e52d0f 100644
--- a/MPF.Core/Processors/DiscImageCreator.cs
+++ b/MPF.Core/Processors/DiscImageCreator.cs
@@ -295,7 +295,7 @@ namespace MPF.Core.Processors
// Get the dumping program and version
var (dicCmd, dicVersion) = GetCommandFilePathAndVersion(basePath);
- info.DumpingInfo!.DumpingProgram = $"{EnumConverter.LongName(InternalProgram.DiscImageCreator)} {dicVersion ?? "Unknown Version"}";
+ info.DumpingInfo!.DumpingProgram = $"{EnumExtensions.LongName(InternalProgram.DiscImageCreator)} {dicVersion ?? "Unknown Version"}";
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate(dicCmd)?.ToString("yyyy-MM-dd HH:mm:ss");
// Fill in the hardware data
diff --git a/MPF.Core/Processors/PS3CFW.cs b/MPF.Core/Processors/PS3CFW.cs
index 0878846b..f9143140 100644
--- a/MPF.Core/Processors/PS3CFW.cs
+++ b/MPF.Core/Processors/PS3CFW.cs
@@ -2,6 +2,7 @@
using System.IO;
using System.Text.RegularExpressions;
using MPF.Core.Data;
+using MPF.Core.Utilities;
using SabreTools.Hashing;
using SabreTools.Models.Logiqx;
using SabreTools.RedumpLib;
@@ -59,7 +60,7 @@ namespace MPF.Core.Processors
// Ensure that required sections exist
info = Builder.EnsureAllSections(info);
- info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(InternalProgram.PS3CFW);
+ info.DumpingInfo!.DumpingProgram = EnumExtensions.LongName(InternalProgram.PS3CFW);
// Get the Datafile information
Datafile? datafile = GeneratePS3CFWDatafile(basePath + ".iso");
diff --git a/MPF.Core/Processors/Redumper.cs b/MPF.Core/Processors/Redumper.cs
index 5e56a82c..5f5f62b3 100644
--- a/MPF.Core/Processors/Redumper.cs
+++ b/MPF.Core/Processors/Redumper.cs
@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using MPF.Core.Data;
+using MPF.Core.Utilities;
using SabreTools.Models.CueSheets;
using SabreTools.RedumpLib;
using SabreTools.RedumpLib.Data;
@@ -177,7 +178,7 @@ namespace MPF.Core.Processors
info = Builder.EnsureAllSections(info);
// Get the dumping program and version
- info.DumpingInfo!.DumpingProgram = $"{EnumConverter.LongName(InternalProgram.Redumper)} {GetVersion($"{basePath}.log") ?? "Unknown Version"}";
+ info.DumpingInfo!.DumpingProgram = $"{EnumExtensions.LongName(InternalProgram.Redumper)} {GetVersion($"{basePath}.log") ?? "Unknown Version"}";
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate($"{basePath}.log")?.ToString("yyyy-MM-dd HH:mm:ss");
// Fill in the hardware data
diff --git a/MPF.Core/Processors/UmdImageCreator.cs b/MPF.Core/Processors/UmdImageCreator.cs
index 4e56a4c2..5f9c5644 100644
--- a/MPF.Core/Processors/UmdImageCreator.cs
+++ b/MPF.Core/Processors/UmdImageCreator.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using MPF.Core.Data;
+using MPF.Core.Utilities;
using SabreTools.Hashing;
using SabreTools.Models.Logiqx;
using SabreTools.RedumpLib;
@@ -75,7 +76,7 @@ namespace MPF.Core.Processors
info = Builder.EnsureAllSections(info);
// TODO: Determine if there's a UMDImageCreator version anywhere
- info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(InternalProgram.UmdImageCreator);
+ info.DumpingInfo!.DumpingProgram = EnumExtensions.LongName(InternalProgram.UmdImageCreator);
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate(basePath + "_disc.txt")?.ToString("yyyy-MM-dd HH:mm:ss");
// Fill in the volume labels
diff --git a/MPF.Core/Processors/XboxBackupCreator.cs b/MPF.Core/Processors/XboxBackupCreator.cs
index 8df32f43..d91cae98 100644
--- a/MPF.Core/Processors/XboxBackupCreator.cs
+++ b/MPF.Core/Processors/XboxBackupCreator.cs
@@ -93,7 +93,7 @@ namespace MPF.Core.Processors
return;
// XBC dump info
- info.DumpingInfo!.DumpingProgram = $"{EnumConverter.LongName(InternalProgram.XboxBackupCreator)} {GetVersion(logPath) ?? "Unknown Version"}";
+ info.DumpingInfo!.DumpingProgram = $"{EnumExtensions.LongName(InternalProgram.XboxBackupCreator)} {GetVersion(logPath) ?? "Unknown Version"}";
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate(logPath)?.ToString("yyyy-MM-dd HH:mm:ss");
info.DumpingInfo.Model = GetDrive(logPath) ?? "Unknown Drive";
diff --git a/MPF.Core/UI/ComboBoxItems/Element.cs b/MPF.Core/UI/ComboBoxItems/Element.cs
index cb0ec467..6746a4a0 100644
--- a/MPF.Core/UI/ComboBoxItems/Element.cs
+++ b/MPF.Core/UI/ComboBoxItems/Element.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using MPF.Core.Data;
+using MPF.Core.Utilities;
namespace MPF.Core.UI.ComboBoxItems
{
@@ -22,7 +22,7 @@ namespace MPF.Core.UI.ComboBoxItems
public static implicit operator T? (Element item) => item?.Data;
///
- public string Name => EnumConverter.GetLongName(Data);
+ public string Name => EnumExtensions.GetLongName(Data);
public override string ToString() => Name;
diff --git a/MPF.Core/Utilities/EnumExtensions.cs b/MPF.Core/Utilities/EnumExtensions.cs
index 68d24b03..feda000c 100644
--- a/MPF.Core/Utilities/EnumExtensions.cs
+++ b/MPF.Core/Utilities/EnumExtensions.cs
@@ -1,5 +1,10 @@
using System;
using System.Collections.Generic;
+#if NET40_OR_GREATER || NETCOREAPP
+using System.Collections.Concurrent;
+#endif
+using System.IO;
+using System.Reflection;
using MPF.Core.Data;
using SabreTools.RedumpLib.Data;
@@ -7,6 +12,385 @@ namespace MPF.Core.Utilities
{
public static class EnumExtensions
{
+ #region Cross-enumeration conversions
+
+ ///
+ /// Convert drive type to internal version, if possible
+ ///
+ /// DriveType value to check
+ /// InternalDriveType, if possible, null on error
+ public static InternalDriveType? ToInternalDriveType(this DriveType driveType)
+ {
+ return driveType switch
+ {
+ DriveType.CDRom => (InternalDriveType?)InternalDriveType.Optical,
+ DriveType.Fixed => (InternalDriveType?)InternalDriveType.HardDisk,
+ DriveType.Removable => (InternalDriveType?)InternalDriveType.Removable,
+ _ => null,
+ };
+ }
+
+ #endregion
+
+ #region Convert to Long Name
+
+ ///
+ /// Long name method cache
+ ///
+#if NET20 || NET35
+ private static readonly Dictionary LongNameMethods = [];
+#else
+ private static readonly ConcurrentDictionary LongNameMethods = [];
+#endif
+
+ ///
+ /// Get the string representation of a generic enumerable value
+ ///
+ /// Enum value to convert
+ /// String representation of that value if possible, empty string on error
+ public static string GetLongName(Enum value)
+ {
+ try
+ {
+ var sourceType = value.GetType();
+ sourceType = Nullable.GetUnderlyingType(sourceType) ?? sourceType;
+
+ if (!LongNameMethods.TryGetValue(sourceType, out var method))
+ {
+ method = typeof(Extensions).GetMethod("LongName", [typeof(Nullable<>).MakeGenericType(sourceType)]);
+ method ??= typeof(EnumExtensions).GetMethod("LongName", [typeof(Nullable<>).MakeGenericType(sourceType)]);
+
+#if NET20 || NET35
+ LongNameMethods[sourceType] = method;
+#else
+ LongNameMethods.TryAdd(sourceType, method);
+#endif
+ }
+
+ if (method != null)
+ return method.Invoke(null, new[] { value }) as string ?? string.Empty;
+ else
+ return string.Empty;
+ }
+ catch
+ {
+ // Converter is not implemented for the given type
+ return string.Empty;
+ }
+ }
+
+ ///
+ /// Get the string representation of the InternalProgram enum values
+ ///
+ /// InternalProgram value to convert
+ /// String representing the value, if possible
+ public static string LongName(this InternalProgram? prog)
+ {
+ return (prog) switch
+ {
+ #region Dumping support
+
+ InternalProgram.Aaru => "Aaru",
+ InternalProgram.DiscImageCreator => "DiscImageCreator",
+ InternalProgram.Redumper => "Redumper",
+
+ #endregion
+
+ #region Verification support only
+
+ InternalProgram.CleanRip => "CleanRip",
+ InternalProgram.PS3CFW => "PS3 CFW",
+ InternalProgram.UmdImageCreator => "UmdImageCreator",
+ InternalProgram.XboxBackupCreator => "XboxBackupCreator",
+
+ #endregion
+
+ InternalProgram.NONE => "Unknown",
+ _ => "Unknown",
+ };
+ }
+
+ ///
+ /// Get the string representation of the RedumperReadMethod enum values
+ ///
+ /// RedumperReadMethod value to convert
+ /// String representing the value, if possible
+ public static string LongName(this RedumperReadMethod? method)
+ {
+ return (method) switch
+ {
+ RedumperReadMethod.D8 => "D8",
+ RedumperReadMethod.BE => "BE",
+ RedumperReadMethod.BE_CDDA => "BE_CDDA",
+
+ RedumperReadMethod.NONE => "Default",
+ _ => "Unknown",
+ };
+ }
+
+ ///
+ /// Get the string representation of the RedumperSectorOrder enum values
+ ///
+ /// RedumperSectorOrder value to convert
+ /// String representing the value, if possible
+ public static string LongName(this RedumperSectorOrder? order)
+ {
+ return (order) switch
+ {
+ RedumperSectorOrder.DATA_C2_SUB => "DATA_C2_SUB",
+ RedumperSectorOrder.DATA_SUB_C2 => "DATA_SUB_C2",
+ RedumperSectorOrder.DATA_SUB => "DATA_SUB",
+ RedumperSectorOrder.DATA_C2 => "DATA_C2",
+
+ RedumperSectorOrder.NONE => "Default",
+ _ => "Unknown",
+ };
+ }
+
+ #endregion
+
+ #region Convert From String
+
+ ///
+ /// Get the InternalProgram enum value for a given string
+ ///
+ /// String value to convert
+ /// InternalProgram represented by the string, if possible
+ public static InternalProgram ToInternalProgram(string? internalProgram)
+ {
+ return (internalProgram?.ToLowerInvariant()) switch
+ {
+ // Dumping support
+ "aaru"
+ or "chef"
+ or "dichef"
+ or "discimagechef" => InternalProgram.Aaru,
+ "creator"
+ or "dic"
+ or "dicreator"
+ or "discimagecreator" => InternalProgram.DiscImageCreator,
+ "rd"
+ or "redumper" => InternalProgram.Redumper,
+
+ // Verification support only
+ "cleanrip"
+ or "cr" => InternalProgram.CleanRip,
+ "ps3cfw"
+ or "ps3"
+ or "getkey"
+ or "managunz"
+ or "multiman" => InternalProgram.PS3CFW,
+ "uic"
+ or "umd"
+ or "umdcreator"
+ or "umdimagecreator" => InternalProgram.UmdImageCreator,
+ "xbc"
+ or "xbox"
+ or "xbox360"
+ or "xboxcreator"
+ or "xboxbackupcreator" => InternalProgram.XboxBackupCreator,
+
+ _ => InternalProgram.NONE,
+ };
+ }
+
+ ///
+ /// Get the MediaType enum value for a given string
+ ///
+ /// String value to convert
+ /// MediaType represented by the string, if possible
+ public static MediaType ToMediaType(string type)
+ {
+ return (type.ToLowerInvariant()) switch
+ {
+ #region Punched Media
+
+ "aperture"
+ or "aperturecard"
+ or "aperture card" => MediaType.ApertureCard,
+ "jacquardloom"
+ or "jacquardloomcard"
+ or "jacquard loom card" => MediaType.JacquardLoomCard,
+ "magneticstripe"
+ or "magneticstripecard"
+ or "magnetic stripe card" => MediaType.MagneticStripeCard,
+ "opticalphone"
+ or "opticalphonecard"
+ or "optical phonecard" => MediaType.OpticalPhonecard,
+ "punchcard"
+ or "punchedcard"
+ or "punched card" => MediaType.PunchedCard,
+ "punchtape"
+ or "punchedtape"
+ or "punched tape" => MediaType.PunchedTape,
+
+ #endregion
+
+ #region Tape
+
+ "openreel"
+ or "openreeltape"
+ or "open reel tape" => MediaType.OpenReel,
+ "datacart"
+ or "datacartridge"
+ or "datatapecartridge"
+ or "data tape cartridge" => MediaType.DataCartridge,
+ "cassette"
+ or "cassettetape"
+ or "cassette tape" => MediaType.Cassette,
+
+ #endregion
+
+ #region Disc / Disc
+
+ "bd"
+ or "bdrom"
+ or "bd-rom"
+ or "bluray" => MediaType.BluRay,
+ "cd"
+ or "cdrom"
+ or "cd-rom" => MediaType.CDROM,
+ "dvd"
+ or "dvd5"
+ or "dvd-5"
+ or "dvd9"
+ or "dvd-9"
+ or "dvdrom"
+ or "dvd-rom" => MediaType.DVD,
+ "fd"
+ or "floppy"
+ or "floppydisk"
+ or "floppy disk"
+ or "floppy diskette" => MediaType.FloppyDisk,
+ "floptical" => MediaType.Floptical,
+ "gd"
+ or "gdrom"
+ or "gd-rom" => MediaType.GDROM,
+ "hddvd"
+ or "hd-dvd"
+ or "hddvdrom"
+ or "hd-dvd-rom" => MediaType.HDDVD,
+ "hdd"
+ or "harddisk"
+ or "hard disk" => MediaType.HardDisk,
+ "bernoullidisk"
+ or "iomegabernoullidisk"
+ or "bernoulli disk"
+ or "iomega bernoulli disk" => MediaType.IomegaBernoulliDisk,
+ "jaz"
+ or "iomegajaz"
+ or "iomega jaz" => MediaType.IomegaJaz,
+ "zip"
+ or "zipdisk"
+ or "iomegazip"
+ or "iomega zip" => MediaType.IomegaZip,
+ "ldrom"
+ or "lvrom"
+ or "ld-rom"
+ or "lv-rom"
+ or "laserdisc"
+ or "laservision"
+ or "ld-rom / lv-rom" => MediaType.LaserDisc,
+ "64dd"
+ or "n64dd"
+ or "64dddisk"
+ or "n64dddisk"
+ or "64dd disk"
+ or "n64dd disk" => MediaType.Nintendo64DD,
+ "fds"
+ or "famicom"
+ or "nfds"
+ or "nintendofamicom"
+ or "famicomdisksystem"
+ or "famicom disk system"
+ or "famicom disk system disk" => MediaType.NintendoFamicomDiskSystem,
+ "gc"
+ or "gamecube"
+ or "nintendogamecube"
+ or "nintendo gamecube"
+ or "gamecube disc"
+ or "gamecube game disc" => MediaType.NintendoGameCubeGameDisc,
+ "wii"
+ or "nintendowii"
+ or "nintendo wii"
+ or "nintendo wii disc"
+ or "wii optical disc" => MediaType.NintendoWiiOpticalDisc,
+ "wiiu"
+ or "nintendowiiu"
+ or "nintendo wiiu"
+ or "nintendo wiiu disc"
+ or "wiiu optical disc"
+ or "wii u optical disc" => MediaType.NintendoWiiUOpticalDisc,
+ "umd" => MediaType.UMD,
+
+ #endregion
+
+ // Unsorted Formats
+ "cartridge" => MediaType.Cartridge,
+ "ced"
+ or "rcaced"
+ or "rca ced"
+ or "videodisc"
+ or "rca videodisc" => MediaType.CED,
+
+ _ => MediaType.NONE,
+ };
+ }
+
+ ///
+ /// Get the RedumperReadMethod enum value for a given string
+ ///
+ /// String value to convert
+ /// RedumperReadMethod represented by the string, if possible
+ public static RedumperReadMethod ToRedumperReadMethod(string? method)
+ {
+ return (method?.ToLowerInvariant()) switch
+ {
+ "d8" => RedumperReadMethod.D8,
+ "be" => RedumperReadMethod.BE,
+ "be_cdda"
+ or "be cdda"
+ or "be-cdda"
+ or "becdda" => RedumperReadMethod.BE_CDDA,
+
+ _ => RedumperReadMethod.NONE,
+ };
+ }
+
+ ///
+ /// Get the RedumperSectorOrder enum value for a given string
+ ///
+ /// String value to convert
+ /// RedumperSectorOrder represented by the string, if possible
+ public static RedumperSectorOrder ToRedumperSectorOrder(string? order)
+ {
+ return (order?.ToLowerInvariant()) switch
+ {
+ "data_c2_sub"
+ or "data c2 sub"
+ or "data-c2-sub"
+ or "datac2sub" => RedumperSectorOrder.DATA_C2_SUB,
+ "data_sub_c2"
+ or "data sub c2"
+ or "data-sub-c2"
+ or "datasubc2" => RedumperSectorOrder.DATA_SUB_C2,
+ "data_sub"
+ or "data sub"
+ or "data-sub"
+ or "datasub" => RedumperSectorOrder.DATA_SUB,
+ "data_c2"
+ or "data c2"
+ or "data-c2"
+ or "datac2" => RedumperSectorOrder.DATA_C2,
+
+ _ => RedumperSectorOrder.NONE,
+ };
+ }
+
+ #endregion
+
+ #region Enum Helpers
+
///
/// Determine if the media supports drive speeds
///
@@ -44,5 +428,7 @@ namespace MPF.Core.Utilities
return programs;
}
+
+ #endregion
}
}
diff --git a/MPF.Core/Utilities/OptionsLoader.cs b/MPF.Core/Utilities/OptionsLoader.cs
index 5c60a41b..1b59d5a3 100644
--- a/MPF.Core/Utilities/OptionsLoader.cs
+++ b/MPF.Core/Utilities/OptionsLoader.cs
@@ -80,7 +80,7 @@ namespace MPF.Core.Utilities
return (false, MediaType.NONE, null, "Invalid number of arguments");
// Check the MediaType
- var mediaType = EnumConverter.ToMediaType(args[0].Trim('"'));
+ var mediaType = EnumExtensions.ToMediaType(args[0].Trim('"'));
if (mediaType == MediaType.NONE)
return (false, MediaType.NONE, null, $"{args[0]} is not a recognized media type");
@@ -131,12 +131,12 @@ namespace MPF.Core.Utilities
if (args[startIndex].StartsWith("-u=") || args[startIndex].StartsWith("--use="))
{
string internalProgram = args[startIndex].Split('=')[1];
- options.InternalProgram = EnumConverter.ToInternalProgram(internalProgram);
+ options.InternalProgram = EnumExtensions.ToInternalProgram(internalProgram);
}
else if (args[startIndex] == "-u" || args[startIndex] == "--use")
{
string internalProgram = args[startIndex + 1];
- options.InternalProgram = EnumConverter.ToInternalProgram(internalProgram);
+ options.InternalProgram = EnumExtensions.ToInternalProgram(internalProgram);
startIndex++;
}
diff --git a/MPF.Test/Core/Converters/EnumConverterTests.cs b/MPF.Test/Core/Converters/EnumConverterTests.cs
index e40d08a8..45715450 100644
--- a/MPF.Test/Core/Converters/EnumConverterTests.cs
+++ b/MPF.Test/Core/Converters/EnumConverterTests.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using MPF.Core.Data;
+using MPF.Core.Utilities;
using Xunit;
namespace MPF.Test.Core.Converters