Fix extension and conversion methods

This commit is contained in:
Matt Nadareski
2021-08-18 23:17:47 -07:00
parent c4793e849c
commit 68b932bad0
6 changed files with 866 additions and 956 deletions

View File

@@ -16,40 +16,6 @@ namespace MPF.Converters
{
#region Cross-enumeration conversions
/// <summary>
/// Convert master list of all media types to currently known Redump disc types
/// </summary>
/// <param name="mediaType">MediaType value to check</param>
/// <returns>DiscType if possible, null on error</returns>
public static DiscType? ToDiscType(this MediaType? mediaType)
{
switch (mediaType)
{
case MediaType.BluRay:
return DiscType.BD50;
case MediaType.CDROM:
return DiscType.CD;
case MediaType.DVD:
return DiscType.DVD9;
case MediaType.GDROM:
return DiscType.GDROM;
case MediaType.HDDVD:
return DiscType.HDDVDSL;
// case MediaType.MILCD: // TODO: Support this?
// return DiscType.MILCD;
case MediaType.NintendoGameCubeGameDisc:
return DiscType.NintendoGameCubeGameDisc;
case MediaType.NintendoWiiOpticalDisc:
return DiscType.NintendoWiiOpticalDiscDL;
case MediaType.NintendoWiiUOpticalDisc:
return DiscType.NintendoWiiUOpticalDiscSL;
case MediaType.UMD:
return DiscType.UMDDL;
default:
return null;
}
}
/// <summary>
/// Convert drive type to internal version, if possible
/// </summary>
@@ -111,44 +77,6 @@ namespace MPF.Converters
}
#endif
/// <summary>
/// Convert currently known Redump disc types to master list of all media types
/// </summary>
/// <param name="discType">DiscType value to check</param>
/// <returns>MediaType if possible, null on error</returns>
public static MediaType? ToMediaType(this DiscType? discType)
{
switch (discType)
{
case DiscType.BD25:
case DiscType.BD50:
return MediaType.BluRay;
case DiscType.CD:
return MediaType.CDROM;
case DiscType.DVD5:
case DiscType.DVD9:
return MediaType.DVD;
case DiscType.GDROM:
return MediaType.GDROM;
case DiscType.HDDVDSL:
return MediaType.HDDVD;
// case DiscType.MILCD: // TODO: Support this?
// return MediaType.MILCD;
case DiscType.NintendoGameCubeGameDisc:
return MediaType.NintendoGameCubeGameDisc;
case DiscType.NintendoWiiOpticalDiscSL:
case DiscType.NintendoWiiOpticalDiscDL:
return MediaType.NintendoWiiOpticalDisc;
case DiscType.NintendoWiiUOpticalDiscSL:
return MediaType.NintendoWiiUOpticalDisc;
case DiscType.UMDSL:
case DiscType.UMDDL:
return MediaType.UMD;
default:
return null;
}
}
/// <summary>
/// Convert physical media type to a MediaType
/// </summary>
@@ -214,7 +142,12 @@ namespace MPF.Converters
if (!LongNameMethods.TryGetValue(sourceType, out MethodInfo method))
{
method = typeof(EnumConverter).GetMethod("LongName", new[] { typeof(Nullable<>).MakeGenericType(sourceType) });
method = typeof(RedumpLib.Data.Extensions).GetMethod("LongName", new[] { typeof(Nullable<>).MakeGenericType(sourceType) });
if (method == null)
method = typeof(EnumConverter).GetMethod("LongName", new[] { typeof(Nullable<>).MakeGenericType(sourceType) });
LongNameMethods.TryAdd(sourceType, method);
}
@@ -269,96 +202,6 @@ namespace MPF.Converters
}
}
/// <summary>
/// Get the string representation of the MediaType enum values
/// </summary>
/// <param name="type">MediaType value to convert</param>
/// <returns>String representing the value, if possible</returns>
public static string LongName(this MediaType? type)
{
switch (type)
{
#region Punched Media
case MediaType.ApertureCard:
return "Aperture card";
case MediaType.JacquardLoomCard:
return "Jacquard Loom card";
case MediaType.MagneticStripeCard:
return "Magnetic stripe card";
case MediaType.OpticalPhonecard:
return "Optical phonecard";
case MediaType.PunchedCard:
return "Punched card";
case MediaType.PunchedTape:
return "Punched tape";
#endregion
#region Tape
case MediaType.OpenReel:
return "Open Reel Tape";
case MediaType.DataCartridge:
return "Data Tape Cartridge";
case MediaType.Cassette:
return "Cassette Tape";
#endregion
#region Disc / Disc
case MediaType.BluRay:
return "BD-ROM";
case MediaType.CDROM:
return "CD-ROM";
case MediaType.DVD:
return "DVD-ROM";
case MediaType.FloppyDisk:
return "Floppy Disk";
case MediaType.Floptical:
return "Floptical";
case MediaType.GDROM:
return "GD-ROM";
case MediaType.HDDVD:
return "HD-DVD-ROM";
case MediaType.HardDisk:
return "Hard Disk";
case MediaType.IomegaBernoulliDisk:
return "Iomega Bernoulli Disk";
case MediaType.IomegaJaz:
return "Iomega Jaz";
case MediaType.IomegaZip:
return "Iomega Zip";
case MediaType.LaserDisc:
return "LD-ROM / LV-ROM";
case MediaType.Nintendo64DD:
return "64DD Disk";
case MediaType.NintendoFamicomDiskSystem:
return "Famicom Disk System Disk";
case MediaType.NintendoGameCubeGameDisc:
return "GameCube Game Disc";
case MediaType.NintendoWiiOpticalDisc:
return "Wii Optical Disc";
case MediaType.NintendoWiiUOpticalDisc:
return "Wii U Optical Disc";
case MediaType.UMD:
return "UMD";
#endregion
// Unsorted Formats
case MediaType.Cartridge:
return "Cartridge";
case MediaType.CED:
return "CED";
case MediaType.NONE:
default:
return "Unknown";
}
}
#endregion
#region Convert to Short Name
@@ -398,96 +241,6 @@ namespace MPF.Converters
}
}
/// <summary>
/// Get the short string representation of the MediaType enum values
/// </summary>
/// <param name="type">MediaType value to convert</param>
/// <returns>Short string representing the value, if possible</returns>
public static string ShortName(this MediaType? type)
{
switch (type)
{
#region Punched Media
case MediaType.ApertureCard:
return "aperture";
case MediaType.JacquardLoomCard:
return "jacquard loom card";
case MediaType.MagneticStripeCard:
return "magnetic stripe";
case MediaType.OpticalPhonecard:
return "optical phonecard";
case MediaType.PunchedCard:
return "punchcard";
case MediaType.PunchedTape:
return "punchtape";
#endregion
#region Tape
case MediaType.OpenReel:
return "open reel";
case MediaType.DataCartridge:
return "data cartridge";
case MediaType.Cassette:
return "cassette";
#endregion
#region Disc / Disc
case MediaType.BluRay:
return "bdrom";
case MediaType.CDROM:
return "cdrom";
case MediaType.DVD:
return "dvd";
case MediaType.FloppyDisk:
return "fd";
case MediaType.Floptical:
return "floptical";
case MediaType.GDROM:
return "gdrom";
case MediaType.HDDVD:
return "hddvd";
case MediaType.HardDisk:
return "hdd";
case MediaType.IomegaBernoulliDisk:
return "bernoulli";
case MediaType.IomegaJaz:
return "jaz";
case MediaType.IomegaZip:
return "zip";
case MediaType.LaserDisc:
return "ldrom";
case MediaType.Nintendo64DD:
return "64dd";
case MediaType.NintendoFamicomDiskSystem:
return "fds";
case MediaType.NintendoGameCubeGameDisc:
return "gc";
case MediaType.NintendoWiiOpticalDisc:
return "wii";
case MediaType.NintendoWiiUOpticalDisc:
return "wiiu";
case MediaType.UMD:
return "umd";
#endregion
// Unsorted Formats
case MediaType.Cartridge:
return "cart";
case MediaType.CED:
return "ced";
case MediaType.NONE:
default:
return "unknown";
}
}
#endregion
#region Convert From String

View File

@@ -104,7 +104,7 @@ namespace MPF.Test.Converters
case SystemCategory.Other: marker = RedumpSystem.MarkerOtherEnd; break;
}
Assert.NotEqual(null, marker);
Assert.NotNull(marker);
Assert.True(marker > system);
Array.ForEach(markers, mmarker =>

View File

@@ -14,7 +14,7 @@ namespace MPF.Test.Converters
[InlineData(MediaType.NONE, "Unknown")]
public void MediaTypeToStringTest(MediaType? mediaType, string expected)
{
string actual = EnumConverter.LongName(mediaType);
string actual = mediaType.LongName();
Assert.Equal(expected, actual);
}

View File

@@ -948,7 +948,7 @@ namespace MPF.GUI.ViewModels
if (index != -1)
App.Instance.MediaTypeComboBox.SelectedIndex = index;
else
App.Instance.StatusLabel.Content = $"Disc of type '{EnumConverter.LongName(CurrentMediaType)}' found, but the current system does not support it!";
App.Instance.StatusLabel.Content = $"Disc of type '{CurrentMediaType.LongName()}' found, but the current system does not support it!";
// Ensure the UI gets updated
App.Instance.UpdateLayout();

View File

@@ -276,57 +276,120 @@ namespace RedumpLib.Data
/// </summary>
public enum MediaType
{
[HumanReadable(Available = false, LongName = "Unknown", ShortName = "unknown")]
NONE = 0,
#region Punched Media
[HumanReadable(Available = false, LongName = "Aperture card", ShortName = "aperture")]
ApertureCard,
[HumanReadable(Available = false, LongName = "Jacquard Loom card", ShortName = "jacquard loom card")]
JacquardLoomCard,
[HumanReadable(Available = false, LongName = "Magnetic stripe card", ShortName = "magnetic stripe")]
MagneticStripeCard,
[HumanReadable(Available = false, LongName = "Optical phonecard", ShortName = "optical phonecard")]
OpticalPhonecard,
[HumanReadable(Available = false, LongName = "Punched card", ShortName = "punchcard")]
PunchedCard,
[HumanReadable(Available = false, LongName = "Punched tape", ShortName = "punchtape")]
PunchedTape,
#endregion
#region Tape
[HumanReadable(Available = false, LongName = "Cassette Tape", ShortName = "cassette")]
Cassette,
[HumanReadable(Available = false, LongName = "Data Tape Cartridge", ShortName = "data cartridge")]
DataCartridge,
[HumanReadable(Available = false, LongName = "Open Reel Tape", ShortName = "open reel")]
OpenReel,
#endregion
#region Disc / Disc
[HumanReadable(LongName = "BD-ROM", ShortName = "bdrom")]
BluRay,
[HumanReadable(LongName = "CD-ROM", ShortName = "cdrom")]
CDROM,
[HumanReadable(LongName = "DVD-ROM", ShortName = "dvd")]
DVD,
[HumanReadable(LongName = "Floppy Disk", ShortName = "fd")]
FloppyDisk,
[HumanReadable(Available = false, LongName = "Floptical", ShortName = "floptical")]
Floptical,
[HumanReadable(LongName = "GD-ROM", ShortName = "gdrom")]
GDROM,
[HumanReadable(LongName = "HD-DVD-ROM", ShortName = "hddvd")]
HDDVD,
[HumanReadable(LongName = "Hard Disk", ShortName = "hdd")]
HardDisk,
[HumanReadable(Available = false, LongName = "Iomega Bernoulli Disk", ShortName = "bernoulli")]
IomegaBernoulliDisk,
[HumanReadable(Available = false, LongName = "Iomega Jaz", ShortName = "jaz")]
IomegaJaz,
[HumanReadable(Available = false, LongName = "Iomega Zip", ShortName = "zip")]
IomegaZip,
[HumanReadable(LongName = "LD-ROM / LV-ROM", ShortName = "ldrom")]
LaserDisc, // LD-ROM and LV-ROM variants
[HumanReadable(Available = false, LongName = "64DD Disk", ShortName = "64dd")]
Nintendo64DD,
[HumanReadable(Available = false, LongName = "Famicom Disk System Disk", ShortName = "fds")]
NintendoFamicomDiskSystem,
[HumanReadable(LongName = "GameCube Game Disc", ShortName = "gc")]
NintendoGameCubeGameDisc,
[HumanReadable(LongName = "Wii Optical Disc", ShortName = "wii")]
NintendoWiiOpticalDisc,
[HumanReadable(LongName = "Wii U Optical Disc", ShortName = "wiiu")]
NintendoWiiUOpticalDisc,
[HumanReadable(LongName = "UMD", ShortName = "umd")]
UMD,
#endregion
#region Unsorted Formats
[HumanReadable(Available = false, LongName = "Cartridge", ShortName = "cart")]
Cartridge,
[HumanReadable(Available = false, LongName = "CED", ShortName = "ced")]
CED,
[HumanReadable(Available = false, LongName = "Compact Flash", ShortName = "cf")]
CompactFlash,
[HumanReadable(Available = false, LongName = "MMC", ShortName = "mmc")]
MMC,
[HumanReadable(Available = false, LongName = "SD Card", ShortName = "sd")]
SDCard,
[HumanReadable(Available = false, LongName = "Flash Drive", ShortName = "fkd")]
FlashDrive,
#endregion

File diff suppressed because it is too large Load Diff