From 8de1fbc52fca9bf6a1cb2d88b5e610cd17ffb314 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 26 Mar 2026 22:51:14 -0400 Subject: [PATCH] Reduce enum overhead in metadata --- .../MetadataExtensionsTests.cs | 563 ++++++++++++ .../MetadataExtensions.cs | 717 +++++++++++++++ SabreTools.Data.Models/Metadata/Enums.cs | 482 ++++++++++ .../ConvertersTests.cs | 22 - .../DatFileTests.ToMetadata.cs | 1 - .../DatStatisticsTests.cs | 2 + .../ExtensionsTests.cs | 114 --- .../DatFile.FromMetadata.cs | 4 + .../DatFile.ToMetadata.cs | 6 +- SabreTools.Metadata.DatFiles/DatHeader.cs | 4 + SabreTools.Metadata.DatFiles/DatStatistics.cs | 18 +- SabreTools.Metadata.DatFiles/Enums.cs | 87 -- SabreTools.Metadata.DatFiles/Extensions.cs | 171 ---- .../Formats/ClrMamePro.cs | 9 +- .../Formats/Listxml.cs | 19 +- .../Formats/Logiqx.cs | 11 +- .../ItemDictionary.cs | 2 + .../ItemDictionaryDB.cs | 4 +- .../ConvertersTests.cs | 36 - .../ExtensionsTests.cs | 449 --------- SabreTools.Metadata.DatItems/Enums.cs | 574 +----------- SabreTools.Metadata.DatItems/Extensions.cs | 852 +++--------------- SabreTools.Metadata.DatItems/Formats/Chip.cs | 5 +- .../Formats/Condition.cs | 3 +- .../Formats/Control.cs | 3 +- .../Formats/DataArea.cs | 3 +- .../Formats/Device.cs | 3 +- SabreTools.Metadata.DatItems/Formats/Disk.cs | 3 +- .../Formats/Display.cs | 7 +- .../Formats/Driver.cs | 13 +- .../Formats/Feature.cs | 7 +- .../Formats/PartFeature.cs | 7 +- SabreTools.Metadata.DatItems/Formats/Rom.cs | 31 +- .../Formats/SoftwareList.cs | 3 +- SabreTools.Metadata.DatItems/Machine.cs | 2 +- SabreTools.Metadata/Converters.cs | 135 +-- SabreTools.Metadata/MappingAttribute.cs | 16 - SabreTools.Wrappers/N3DS.Encryption.cs | 4 +- 38 files changed, 2022 insertions(+), 2370 deletions(-) create mode 100644 SabreTools.Data.Models/Metadata/Enums.cs delete mode 100644 SabreTools.Metadata.DatFiles.Test/ConvertersTests.cs delete mode 100644 SabreTools.Metadata.DatFiles.Test/ExtensionsTests.cs delete mode 100644 SabreTools.Metadata.DatFiles/Extensions.cs delete mode 100644 SabreTools.Metadata.DatItems.Test/ConvertersTests.cs delete mode 100644 SabreTools.Metadata/MappingAttribute.cs diff --git a/SabreTools.Data.Extensions.Test/MetadataExtensionsTests.cs b/SabreTools.Data.Extensions.Test/MetadataExtensionsTests.cs index 165d09de..2502bc3c 100644 --- a/SabreTools.Data.Extensions.Test/MetadataExtensionsTests.cs +++ b/SabreTools.Data.Extensions.Test/MetadataExtensionsTests.cs @@ -1575,5 +1575,568 @@ namespace SabreTools.Data.Extensions.Test } #endregion + + #region String to Enum + + [Theory] + [InlineData(null, null)] + [InlineData("cpu", ChipType.CPU)] + [InlineData("audio", ChipType.Audio)] + public void AsChipTypeTest(string? field, ChipType? expected) + { + ChipType? actual = field.AsChipType(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("joy", ControlType.Joy)] + [InlineData("stick", ControlType.Stick)] + [InlineData("paddle", ControlType.Paddle)] + [InlineData("pedal", ControlType.Pedal)] + [InlineData("lightgun", ControlType.Lightgun)] + [InlineData("positional", ControlType.Positional)] + [InlineData("dial", ControlType.Dial)] + [InlineData("trackball", ControlType.Trackball)] + [InlineData("mouse", ControlType.Mouse)] + [InlineData("only_buttons", ControlType.OnlyButtons)] + [InlineData("keypad", ControlType.Keypad)] + [InlineData("keyboard", ControlType.Keyboard)] + [InlineData("mahjong", ControlType.Mahjong)] + [InlineData("hanafuda", ControlType.Hanafuda)] + [InlineData("gambling", ControlType.Gambling)] + public void AsControlTypeTest(string? field, ControlType? expected) + { + ControlType? actual = field.AsControlType(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("unknown", DeviceType.Unknown)] + [InlineData("cartridge", DeviceType.Cartridge)] + [InlineData("floppydisk", DeviceType.FloppyDisk)] + [InlineData("harddisk", DeviceType.HardDisk)] + [InlineData("cylinder", DeviceType.Cylinder)] + [InlineData("cassette", DeviceType.Cassette)] + [InlineData("punchcard", DeviceType.PunchCard)] + [InlineData("punchtape", DeviceType.PunchTape)] + [InlineData("printout", DeviceType.Printout)] + [InlineData("serial", DeviceType.Serial)] + [InlineData("parallel", DeviceType.Parallel)] + [InlineData("snapshot", DeviceType.Snapshot)] + [InlineData("quickload", DeviceType.QuickLoad)] + [InlineData("memcard", DeviceType.MemCard)] + [InlineData("cdrom", DeviceType.CDROM)] + [InlineData("magtape", DeviceType.MagTape)] + [InlineData("romimage", DeviceType.ROMImage)] + [InlineData("midiin", DeviceType.MIDIIn)] + [InlineData("midiout", DeviceType.MIDIOut)] + [InlineData("picture", DeviceType.Picture)] + [InlineData("vidfile", DeviceType.VidFile)] + public void AsDeviceTypeTest(string? field, DeviceType? expected) + { + DeviceType? actual = field.AsDeviceType(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("raster", DisplayType.Raster)] + [InlineData("vector", DisplayType.Vector)] + [InlineData("lcd", DisplayType.LCD)] + [InlineData("svg", DisplayType.SVG)] + [InlineData("unknown", DisplayType.Unknown)] + public void AsDisplayTypeTest(string? field, DisplayType? expected) + { + DisplayType? actual = field.AsDisplayType(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("big", Endianness.Big)] + [InlineData("little", Endianness.Little)] + public void AsEndiannessTest(string? field, Endianness? expected) + { + Endianness? actual = field.AsEndianness(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("unemulated", FeatureStatus.Unemulated)] + [InlineData("imperfect", FeatureStatus.Imperfect)] + public void AsFeatureStatusTest(string? field, FeatureStatus? expected) + { + FeatureStatus? actual = field.AsFeatureStatus(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("protection", FeatureType.Protection)] + [InlineData("palette", FeatureType.Palette)] + [InlineData("graphics", FeatureType.Graphics)] + [InlineData("sound", FeatureType.Sound)] + [InlineData("controls", FeatureType.Controls)] + [InlineData("keyboard", FeatureType.Keyboard)] + [InlineData("mouse", FeatureType.Mouse)] + [InlineData("microphone", FeatureType.Microphone)] + [InlineData("camera", FeatureType.Camera)] + [InlineData("disk", FeatureType.Disk)] + [InlineData("printer", FeatureType.Printer)] + [InlineData("lan", FeatureType.Lan)] + [InlineData("wan", FeatureType.Wan)] + [InlineData("timing", FeatureType.Timing)] + public void AsFeatureTypeTest(string? field, FeatureType? expected) + { + FeatureType? actual = field.AsFeatureType(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("none", ItemStatus.None)] + [InlineData("no", ItemStatus.None)] + [InlineData("good", ItemStatus.Good)] + [InlineData("baddump", ItemStatus.BadDump)] + [InlineData("nodump", ItemStatus.Nodump)] + [InlineData("yes", ItemStatus.Nodump)] + [InlineData("verified", ItemStatus.Verified)] + public void AsItemStatusTest(string? field, ItemStatus? expected) + { + ItemStatus? actual = field.AsItemStatus(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("load16_byte", LoadFlag.Load16Byte)] + [InlineData("load16_word", LoadFlag.Load16Word)] + [InlineData("load16_word_swap", LoadFlag.Load16WordSwap)] + [InlineData("load32_byte", LoadFlag.Load32Byte)] + [InlineData("load32_word", LoadFlag.Load32Word)] + [InlineData("load32_word_swap", LoadFlag.Load32WordSwap)] + [InlineData("load32_dword", LoadFlag.Load32DWord)] + [InlineData("load64_word", LoadFlag.Load64Word)] + [InlineData("load64_word_swap", LoadFlag.Load64WordSwap)] + [InlineData("reload", LoadFlag.Reload)] + [InlineData("fill", LoadFlag.Fill)] + [InlineData("continue", LoadFlag.Continue)] + [InlineData("reload_plain", LoadFlag.ReloadPlain)] + [InlineData("ignore", LoadFlag.Ignore)] + public void AsLoadFlagTest(string? field, LoadFlag? expected) + { + LoadFlag? actual = field.AsLoadFlag(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, MergingFlag.None)] + [InlineData("none", MergingFlag.None)] + [InlineData("split", MergingFlag.Split)] + [InlineData("merged", MergingFlag.Merged)] + [InlineData("nonmerged", MergingFlag.NonMerged)] + [InlineData("unmerged", MergingFlag.NonMerged)] + [InlineData("fullmerged", MergingFlag.FullMerged)] + [InlineData("device", MergingFlag.DeviceNonMerged)] + [InlineData("devicenonmerged", MergingFlag.DeviceNonMerged)] + [InlineData("deviceunmerged", MergingFlag.DeviceNonMerged)] + [InlineData("full", MergingFlag.FullNonMerged)] + [InlineData("fullnonmerged", MergingFlag.FullNonMerged)] + [InlineData("fullunmerged", MergingFlag.FullNonMerged)] + public void AsMergingFlagTest(string? field, MergingFlag expected) + { + MergingFlag actual = field.AsMergingFlag(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, NodumpFlag.None)] + [InlineData("none", NodumpFlag.None)] + [InlineData("obsolete", NodumpFlag.Obsolete)] + [InlineData("required", NodumpFlag.Required)] + [InlineData("ignore", NodumpFlag.Ignore)] + public void AsNodumpFlagTest(string? field, NodumpFlag expected) + { + NodumpFlag actual = field.AsNodumpFlag(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("rom", OpenMSXSubType.Rom)] + [InlineData("megarom", OpenMSXSubType.MegaRom)] + [InlineData("sccpluscart", OpenMSXSubType.SCCPlusCart)] + public void AsOpenMSXSubTypeTest(string? field, OpenMSXSubType? expected) + { + OpenMSXSubType? actual = field.AsOpenMSXSubType(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, PackingFlag.None)] + [InlineData("none", PackingFlag.None)] + [InlineData("yes", PackingFlag.Zip)] + [InlineData("zip", PackingFlag.Zip)] + [InlineData("no", PackingFlag.Unzip)] + [InlineData("unzip", PackingFlag.Unzip)] + [InlineData("partial", PackingFlag.Partial)] + [InlineData("flat", PackingFlag.Flat)] + [InlineData("fileonly", PackingFlag.FileOnly)] + public void AsPackingFlagTest(string? field, PackingFlag expected) + { + PackingFlag actual = field.AsPackingFlag(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("eq", Relation.Equal)] + [InlineData("ne", Relation.NotEqual)] + [InlineData("gt", Relation.GreaterThan)] + [InlineData("le", Relation.LessThanOrEqual)] + [InlineData("lt", Relation.LessThan)] + [InlineData("ge", Relation.GreaterThanOrEqual)] + public void AsRelationTest(string? field, Relation? expected) + { + Relation? actual = field.AsRelation(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("no", Runnable.No)] + [InlineData("partial", Runnable.Partial)] + [InlineData("yes", Runnable.Yes)] + public void AsRunnableTest(string? field, Runnable? expected) + { + Runnable? actual = field.AsRunnable(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("none", SoftwareListStatus.None)] + [InlineData("original", SoftwareListStatus.Original)] + [InlineData("compatible", SoftwareListStatus.Compatible)] + public void AsSoftwareListStatusTest(string? field, SoftwareListStatus? expected) + { + SoftwareListStatus? actual = field.AsSoftwareListStatus(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("no", Supported.No)] + [InlineData("unsupported", Supported.No)] + [InlineData("partial", Supported.Partial)] + [InlineData("yes", Supported.Yes)] + [InlineData("supported", Supported.Yes)] + public void AsSupportedTest(string? field, Supported? expected) + { + Supported? actual = field.AsSupported(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null)] + [InlineData("good", SupportStatus.Good)] + [InlineData("imperfect", SupportStatus.Imperfect)] + [InlineData("preliminary", SupportStatus.Preliminary)] + public void AsSupportStatusTest(string? field, SupportStatus? expected) + { + SupportStatus? actual = field.AsSupportStatus(); + Assert.Equal(expected, actual); + } + + #endregion + + #region Enum to String + + [Theory] + [InlineData((ChipType)int.MaxValue, null)] + [InlineData(ChipType.CPU, "cpu")] + [InlineData(ChipType.Audio, "audio")] + public void FromChipTypeTest(ChipType field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((ControlType)int.MaxValue, null)] + [InlineData(ControlType.Joy, "joy")] + [InlineData(ControlType.Stick, "stick")] + [InlineData(ControlType.Paddle, "paddle")] + [InlineData(ControlType.Pedal, "pedal")] + [InlineData(ControlType.Lightgun, "lightgun")] + [InlineData(ControlType.Positional, "positional")] + [InlineData(ControlType.Dial, "dial")] + [InlineData(ControlType.Trackball, "trackball")] + [InlineData(ControlType.Mouse, "mouse")] + [InlineData(ControlType.OnlyButtons, "only_buttons")] + [InlineData(ControlType.Keypad, "keypad")] + [InlineData(ControlType.Keyboard, "keyboard")] + [InlineData(ControlType.Mahjong, "mahjong")] + [InlineData(ControlType.Hanafuda, "hanafuda")] + [InlineData(ControlType.Gambling, "gambling")] + public void FromControlTypeTest(ControlType field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((DeviceType)int.MaxValue, null)] + [InlineData(DeviceType.Unknown, "unknown")] + [InlineData(DeviceType.Cartridge, "cartridge")] + [InlineData(DeviceType.FloppyDisk, "floppydisk")] + [InlineData(DeviceType.HardDisk, "harddisk")] + [InlineData(DeviceType.Cylinder, "cylinder")] + [InlineData(DeviceType.Cassette, "cassette")] + [InlineData(DeviceType.PunchCard, "punchcard")] + [InlineData(DeviceType.PunchTape, "punchtape")] + [InlineData(DeviceType.Printout, "printout")] + [InlineData(DeviceType.Serial, "serial")] + [InlineData(DeviceType.Parallel, "parallel")] + [InlineData(DeviceType.Snapshot, "snapshot")] + [InlineData(DeviceType.QuickLoad, "quickload")] + [InlineData(DeviceType.MemCard, "memcard")] + [InlineData(DeviceType.CDROM, "cdrom")] + [InlineData(DeviceType.MagTape, "magtape")] + [InlineData(DeviceType.ROMImage, "romimage")] + [InlineData(DeviceType.MIDIIn, "midiin")] + [InlineData(DeviceType.MIDIOut, "midiout")] + [InlineData(DeviceType.Picture, "picture")] + [InlineData(DeviceType.VidFile, "vidfile")] + public void FromDeviceTypeTest(DeviceType field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((DisplayType)int.MaxValue, null)] + [InlineData(DisplayType.Raster, "raster")] + [InlineData(DisplayType.Vector, "vector")] + [InlineData(DisplayType.LCD, "lcd")] + [InlineData(DisplayType.SVG, "svg")] + [InlineData(DisplayType.Unknown, "unknown")] + public void FromDisplayTypeTest(DisplayType field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((Endianness)int.MaxValue, null)] + [InlineData(Endianness.Big, "big")] + [InlineData(Endianness.Little, "little")] + public void FromEndiannessTest(Endianness field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((FeatureStatus)int.MaxValue, null)] + [InlineData(FeatureStatus.Unemulated, "unemulated")] + [InlineData(FeatureStatus.Imperfect, "imperfect")] + public void FromFeatureStatusTest(FeatureStatus field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((FeatureType)int.MaxValue, null)] + [InlineData(FeatureType.Protection, "protection")] + [InlineData(FeatureType.Palette, "palette")] + [InlineData(FeatureType.Graphics, "graphics")] + [InlineData(FeatureType.Sound, "sound")] + [InlineData(FeatureType.Controls, "controls")] + [InlineData(FeatureType.Keyboard, "keyboard")] + [InlineData(FeatureType.Mouse, "mouse")] + [InlineData(FeatureType.Microphone, "microphone")] + [InlineData(FeatureType.Camera, "camera")] + [InlineData(FeatureType.Disk, "disk")] + [InlineData(FeatureType.Printer, "printer")] + [InlineData(FeatureType.Lan, "lan")] + [InlineData(FeatureType.Wan, "wan")] + [InlineData(FeatureType.Timing, "timing")] + public void FromFeatureTypeTest(FeatureType field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((ItemStatus)int.MaxValue, true, null)] + [InlineData((ItemStatus)int.MaxValue, false, null)] + [InlineData(ItemStatus.None, true, "no")] + [InlineData(ItemStatus.None, false, "none")] + [InlineData(ItemStatus.Good, true, "good")] + [InlineData(ItemStatus.Good, false, "good")] + [InlineData(ItemStatus.BadDump, true, "baddump")] + [InlineData(ItemStatus.BadDump, false, "baddump")] + [InlineData(ItemStatus.Nodump, true, "yes")] + [InlineData(ItemStatus.Nodump, false, "nodump")] + [InlineData(ItemStatus.Verified, true, "verified")] + [InlineData(ItemStatus.Verified, false, "verified")] + public void FromItemStatusTest(ItemStatus field, bool useSecond, string? expected) + { + string? actual = field.AsStringValue(useSecond); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((LoadFlag)int.MaxValue, null)] + [InlineData(LoadFlag.Load16Byte, "load16_byte")] + [InlineData(LoadFlag.Load16Word, "load16_word")] + [InlineData(LoadFlag.Load16WordSwap, "load16_word_swap")] + [InlineData(LoadFlag.Load32Byte, "load32_byte")] + [InlineData(LoadFlag.Load32Word, "load32_word")] + [InlineData(LoadFlag.Load32WordSwap, "load32_word_swap")] + [InlineData(LoadFlag.Load32DWord, "load32_dword")] + [InlineData(LoadFlag.Load64Word, "load64_word")] + [InlineData(LoadFlag.Load64WordSwap, "load64_word_swap")] + [InlineData(LoadFlag.Reload, "reload")] + [InlineData(LoadFlag.Fill, "fill")] + [InlineData(LoadFlag.Continue, "continue")] + [InlineData(LoadFlag.ReloadPlain, "reload_plain")] + [InlineData(LoadFlag.Ignore, "ignore")] + public void FromLoadFlagTest(LoadFlag field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(MergingFlag.None, true, "none")] + [InlineData(MergingFlag.None, false, "none")] + [InlineData(MergingFlag.Split, true, "split")] + [InlineData(MergingFlag.Split, false, "split")] + [InlineData(MergingFlag.Merged, true, "merged")] + [InlineData(MergingFlag.Merged, false, "merged")] + [InlineData(MergingFlag.NonMerged, true, "unmerged")] + [InlineData(MergingFlag.NonMerged, false, "nonmerged")] + [InlineData(MergingFlag.FullMerged, true, "fullmerged")] + [InlineData(MergingFlag.FullMerged, false, "fullmerged")] + [InlineData(MergingFlag.DeviceNonMerged, true, "devicenonmerged")] + [InlineData(MergingFlag.DeviceNonMerged, false, "device")] + [InlineData(MergingFlag.FullNonMerged, true, "fullnonmerged")] + [InlineData(MergingFlag.FullNonMerged, false, "full")] + public void FromMergingFlagTest(MergingFlag field, bool useSecond, string? expected) + { + string? actual = field.AsStringValue(useSecond); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(NodumpFlag.None, "none")] + [InlineData(NodumpFlag.Obsolete, "obsolete")] + [InlineData(NodumpFlag.Required, "required")] + [InlineData(NodumpFlag.Ignore, "ignore")] + public void FromNodumpFlagTest(NodumpFlag field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((OpenMSXSubType)int.MaxValue, null)] + [InlineData(OpenMSXSubType.Rom, "rom")] + [InlineData(OpenMSXSubType.MegaRom, "megarom")] + [InlineData(OpenMSXSubType.SCCPlusCart, "sccpluscart")] + public void FromOpenMSXSubTypeTest(OpenMSXSubType field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(PackingFlag.None, true, "none")] + [InlineData(PackingFlag.None, false, "none")] + [InlineData(PackingFlag.Zip, true, "yes")] + [InlineData(PackingFlag.Zip, false, "zip")] + [InlineData(PackingFlag.Unzip, true, "no")] + [InlineData(PackingFlag.Unzip, false, "unzip")] + [InlineData(PackingFlag.Partial, true, "partial")] + [InlineData(PackingFlag.Partial, false, "partial")] + [InlineData(PackingFlag.Flat, true, "flat")] + [InlineData(PackingFlag.Flat, false, "flat")] + [InlineData(PackingFlag.FileOnly, true, "fileonly")] + [InlineData(PackingFlag.FileOnly, false, "fileonly")] + public void FromPackingFlagTest(PackingFlag field, bool useSecond, string? expected) + { + string? actual = field.AsStringValue(useSecond); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((Relation)int.MaxValue, null)] + [InlineData(Relation.Equal, "eq")] + [InlineData(Relation.NotEqual, "ne")] + [InlineData(Relation.GreaterThan, "gt")] + [InlineData(Relation.LessThanOrEqual, "le")] + [InlineData(Relation.LessThan, "lt")] + [InlineData(Relation.GreaterThanOrEqual, "ge")] + public void FromRelationTest(Relation field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((Runnable)int.MaxValue, null)] + [InlineData(Runnable.No, "no")] + [InlineData(Runnable.Partial, "partial")] + [InlineData(Runnable.Yes, "yes")] + public void FromRunnableTest(Runnable field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((SoftwareListStatus)int.MaxValue, null)] + [InlineData(SoftwareListStatus.None, "none")] + [InlineData(SoftwareListStatus.Original, "original")] + [InlineData(SoftwareListStatus.Compatible, "compatible")] + public void FromSoftwareListStatusTest(SoftwareListStatus field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((Supported)int.MaxValue, true, null)] + [InlineData((Supported)int.MaxValue, false, null)] + [InlineData(Supported.No, true, "unsupported")] + [InlineData(Supported.No, false, "no")] + [InlineData(Supported.Partial, true, "partial")] + [InlineData(Supported.Partial, false, "partial")] + [InlineData(Supported.Yes, true, "supported")] + [InlineData(Supported.Yes, false, "yes")] + public void FromSupportedTest(Supported field, bool useSecond, string? expected) + { + string? actual = field.AsStringValue(useSecond); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData((SupportStatus)int.MaxValue, null)] + [InlineData(SupportStatus.Good, "good")] + [InlineData(SupportStatus.Imperfect, "imperfect")] + [InlineData(SupportStatus.Preliminary, "preliminary")] + public void FromSupportStatusTest(SupportStatus field, string? expected) + { + string? actual = field.AsStringValue(); + Assert.Equal(expected, actual); + } + + #endregion } } diff --git a/SabreTools.Data.Extensions/MetadataExtensions.cs b/SabreTools.Data.Extensions/MetadataExtensions.cs index 2629216d..2a96b95c 100644 --- a/SabreTools.Data.Extensions/MetadataExtensions.cs +++ b/SabreTools.Data.Extensions/MetadataExtensions.cs @@ -859,5 +859,722 @@ namespace SabreTools.Data.Extensions } #endregion + + #region String to Enum + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static ChipType? AsChipType(this string? value) + { + return value?.ToLowerInvariant() switch + { + "cpu" => ChipType.CPU, + "audio" => ChipType.Audio, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static ControlType? AsControlType(this string? value) + { + return value?.ToLowerInvariant() switch + { + "joy" => ControlType.Joy, + "stick" => ControlType.Stick, + "paddle" => ControlType.Paddle, + "pedal" => ControlType.Pedal, + "lightgun" => ControlType.Lightgun, + "positional" => ControlType.Positional, + "dial" => ControlType.Dial, + "trackball" => ControlType.Trackball, + "mouse" => ControlType.Mouse, + "only_buttons" => ControlType.OnlyButtons, + "keypad" => ControlType.Keypad, + "keyboard" => ControlType.Keyboard, + "mahjong" => ControlType.Mahjong, + "hanafuda" => ControlType.Hanafuda, + "gambling" => ControlType.Gambling, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static DeviceType? AsDeviceType(this string? value) + { + return value?.ToLowerInvariant() switch + { + "unknown" => DeviceType.Unknown, + "cartridge" => DeviceType.Cartridge, + "floppydisk" => DeviceType.FloppyDisk, + "harddisk" => DeviceType.HardDisk, + "cylinder" => DeviceType.Cylinder, + "cassette" => DeviceType.Cassette, + "punchcard" => DeviceType.PunchCard, + "punchtape" => DeviceType.PunchTape, + "printout" => DeviceType.Printout, + "serial" => DeviceType.Serial, + "parallel" => DeviceType.Parallel, + "snapshot" => DeviceType.Snapshot, + "quickload" => DeviceType.QuickLoad, + "memcard" => DeviceType.MemCard, + "cdrom" => DeviceType.CDROM, + "magtape" => DeviceType.MagTape, + "romimage" => DeviceType.ROMImage, + "midiin" => DeviceType.MIDIIn, + "midiout" => DeviceType.MIDIOut, + "picture" => DeviceType.Picture, + "vidfile" => DeviceType.VidFile, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static DisplayType? AsDisplayType(this string? value) + { + return value?.ToLowerInvariant() switch + { + "raster" => DisplayType.Raster, + "vector" => DisplayType.Vector, + "lcd" => DisplayType.LCD, + "svg" => DisplayType.SVG, + "unknown" => DisplayType.Unknown, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static Endianness? AsEndianness(this string? value) + { + return value?.ToLowerInvariant() switch + { + "big" => Endianness.Big, + "little" => Endianness.Little, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static FeatureStatus? AsFeatureStatus(this string? value) + { + return value?.ToLowerInvariant() switch + { + "unemulated" => FeatureStatus.Unemulated, + "imperfect" => FeatureStatus.Imperfect, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static FeatureType? AsFeatureType(this string? value) + { + return value?.ToLowerInvariant() switch + { + "protection" => FeatureType.Protection, + "palette" => FeatureType.Palette, + "graphics" => FeatureType.Graphics, + "sound" => FeatureType.Sound, + "controls" => FeatureType.Controls, + "keyboard" => FeatureType.Keyboard, + "mouse" => FeatureType.Mouse, + "microphone" => FeatureType.Microphone, + "camera" => FeatureType.Camera, + "disk" => FeatureType.Disk, + "printer" => FeatureType.Printer, + "lan" => FeatureType.Lan, + "wan" => FeatureType.Wan, + "timing" => FeatureType.Timing, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static ItemStatus? AsItemStatus(this string? value) + { + return value?.ToLowerInvariant() switch + { + "none" or "no" => ItemStatus.None, + "good" => ItemStatus.Good, + "baddump" => ItemStatus.BadDump, + "nodump" or "yes" => ItemStatus.Nodump, + "verified" => ItemStatus.Verified, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static LoadFlag? AsLoadFlag(this string? value) + { + return value?.ToLowerInvariant() switch + { + "load16_byte" => LoadFlag.Load16Byte, + "load16_word" => LoadFlag.Load16Word, + "load16_word_swap" => LoadFlag.Load16WordSwap, + "load32_byte" => LoadFlag.Load32Byte, + "load32_word" => LoadFlag.Load32Word, + "load32_word_swap" => LoadFlag.Load32WordSwap, + "load32_dword" => LoadFlag.Load32DWord, + "load64_word" => LoadFlag.Load64Word, + "load64_word_swap" => LoadFlag.Load64WordSwap, + "reload" => LoadFlag.Reload, + "fill" => LoadFlag.Fill, + "continue" => LoadFlag.Continue, + "reload_plain" => LoadFlag.ReloadPlain, + "ignore" => LoadFlag.Ignore, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, default on error + public static MergingFlag AsMergingFlag(this string? value) + { + return value?.ToLowerInvariant() switch + { + "none" => MergingFlag.None, + "split" => MergingFlag.Split, + "merged" => MergingFlag.Merged, + "nonmerged" or "unmerged" => MergingFlag.NonMerged, + "fullmerged" => MergingFlag.FullMerged, + "device" or "deviceunmerged" or "devicenonmerged" => MergingFlag.DeviceNonMerged, + "full" or "fullunmerged" or "fullnonmerged" => MergingFlag.FullNonMerged, + _ => MergingFlag.None, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, default on error + public static NodumpFlag AsNodumpFlag(this string? value) + { + return value?.ToLowerInvariant() switch + { + "none" => NodumpFlag.None, + "obsolete" => NodumpFlag.Obsolete, + "required" => NodumpFlag.Required, + "ignore" => NodumpFlag.Ignore, + _ => NodumpFlag.None, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static OpenMSXSubType? AsOpenMSXSubType(this string? value) + { + return value?.ToLowerInvariant() switch + { + "rom" => OpenMSXSubType.Rom, + "megarom" => OpenMSXSubType.MegaRom, + "sccpluscart" => OpenMSXSubType.SCCPlusCart, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, default on error + public static PackingFlag AsPackingFlag(this string? value) + { + return value?.ToLowerInvariant() switch + { + "none" => PackingFlag.None, + "zip" or "yes" => PackingFlag.Zip, + "unzip" or "no" => PackingFlag.Unzip, + "partial" => PackingFlag.Partial, + "flat" => PackingFlag.Flat, + "fileonly" => PackingFlag.FileOnly, + _ => PackingFlag.None, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static Relation? AsRelation(this string? value) + { + return value?.ToLowerInvariant() switch + { + "eq" => Relation.Equal, + "ne" => Relation.NotEqual, + "gt" => Relation.GreaterThan, + "le" => Relation.LessThanOrEqual, + "lt" => Relation.LessThan, + "ge" => Relation.GreaterThanOrEqual, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static Runnable? AsRunnable(this string? value) + { + return value?.ToLowerInvariant() switch + { + "no" => Runnable.No, + "partial" => Runnable.Partial, + "yes" => Runnable.Yes, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static SoftwareListStatus? AsSoftwareListStatus(this string? value) + { + return value?.ToLowerInvariant() switch + { + "none" => SoftwareListStatus.None, + "original" => SoftwareListStatus.Original, + "compatible" => SoftwareListStatus.Compatible, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static Supported? AsSupported(this string? value) + { + return value?.ToLowerInvariant() switch + { + "no" or "unsupported" => Supported.No, + "partial" => Supported.Partial, + "yes" or "supported" => Supported.Yes, + _ => null, + }; + } + + /// + /// Get the enum value for an input string, if possible + /// + /// String value to parse/param> + /// Enum value representing the input, null on error + public static SupportStatus? AsSupportStatus(this string? value) + { + return value?.ToLowerInvariant() switch + { + "good" => SupportStatus.Good, + "imperfect" => SupportStatus.Imperfect, + "preliminary" => SupportStatus.Preliminary, + _ => null, + }; + } + + #endregion + + #region Enum to String + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this ChipType value) + { + return value switch + { + ChipType.CPU => "cpu", + ChipType.Audio => "audio", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this ControlType value) + { + return value switch + { + ControlType.Joy => "joy", + ControlType.Stick => "stick", + ControlType.Paddle => "paddle", + ControlType.Pedal => "pedal", + ControlType.Lightgun => "lightgun", + ControlType.Positional => "positional", + ControlType.Dial => "dial", + ControlType.Trackball => "trackball", + ControlType.Mouse => "mouse", + ControlType.OnlyButtons => "only_buttons", + ControlType.Keypad => "keypad", + ControlType.Keyboard => "keyboard", + ControlType.Mahjong => "mahjong", + ControlType.Hanafuda => "hanafuda", + ControlType.Gambling => "gambling", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this DeviceType value) + { + return value switch + { + DeviceType.Unknown => "unknown", + DeviceType.Cartridge => "cartridge", + DeviceType.FloppyDisk => "floppydisk", + DeviceType.HardDisk => "harddisk", + DeviceType.Cylinder => "cylinder", + DeviceType.Cassette => "cassette", + DeviceType.PunchCard => "punchcard", + DeviceType.PunchTape => "punchtape", + DeviceType.Printout => "printout", + DeviceType.Serial => "serial", + DeviceType.Parallel => "parallel", + DeviceType.Snapshot => "snapshot", + DeviceType.QuickLoad => "quickload", + DeviceType.MemCard => "memcard", + DeviceType.CDROM => "cdrom", + DeviceType.MagTape => "magtape", + DeviceType.ROMImage => "romimage", + DeviceType.MIDIIn => "midiin", + DeviceType.MIDIOut => "midiout", + DeviceType.Picture => "picture", + DeviceType.VidFile => "vidfile", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this DisplayType value) + { + return value switch + { + DisplayType.Raster => "raster", + DisplayType.Vector => "vector", + DisplayType.LCD => "lcd", + DisplayType.SVG => "svg", + DisplayType.Unknown => "unknown", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this Endianness value) + { + return value switch + { + Endianness.Big => "big", + Endianness.Little => "little", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this FeatureStatus value) + { + return value switch + { + FeatureStatus.Unemulated => "unemulated", + FeatureStatus.Imperfect => "imperfect", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this FeatureType value) + { + return value switch + { + FeatureType.Protection => "protection", + FeatureType.Palette => "palette", + FeatureType.Graphics => "graphics", + FeatureType.Sound => "sound", + FeatureType.Controls => "controls", + FeatureType.Keyboard => "keyboard", + FeatureType.Mouse => "mouse", + FeatureType.Microphone => "microphone", + FeatureType.Camera => "camera", + FeatureType.Disk => "disk", + FeatureType.Printer => "printer", + FeatureType.Lan => "lan", + FeatureType.Wan => "wan", + FeatureType.Timing => "timing", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// True to use the second mapping option, if it exists + /// String value representing the input, null on error + public static string? AsStringValue(this ItemStatus value, bool useSecond = false) + { + return value switch + { + ItemStatus.None => useSecond ? "no" : "none", + ItemStatus.Good => "good", + ItemStatus.BadDump => "baddump", + ItemStatus.Nodump => useSecond ? "yes" : "nodump", + ItemStatus.Verified => "verified", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this LoadFlag value) + { + return value switch + { + LoadFlag.Load16Byte => "load16_byte", + LoadFlag.Load16Word => "load16_word", + LoadFlag.Load16WordSwap => "load16_word_swap", + LoadFlag.Load32Byte => "load32_byte", + LoadFlag.Load32Word => "load32_word", + LoadFlag.Load32WordSwap => "load32_word_swap", + LoadFlag.Load32DWord => "load32_dword", + LoadFlag.Load64Word => "load64_word", + LoadFlag.Load64WordSwap => "load64_word_swap", + LoadFlag.Reload => "reload", + LoadFlag.Fill => "fill", + LoadFlag.Continue => "continue", + LoadFlag.ReloadPlain => "reload_plain", + LoadFlag.Ignore => "ignore", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// True to use the second mapping option, if it exists + /// String value representing the input, default on error + public static string? AsStringValue(this MergingFlag value, bool useSecond = false) + { + return value switch + { + MergingFlag.None => "none", + MergingFlag.Split => "split", + MergingFlag.Merged => "merged", + MergingFlag.NonMerged => useSecond ? "unmerged" : "nonmerged", + MergingFlag.FullMerged => "fullmerged", + MergingFlag.DeviceNonMerged => useSecond ? "devicenonmerged" : "device", + MergingFlag.FullNonMerged => useSecond ? "fullnonmerged" : "full", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, default on error + public static string? AsStringValue(this NodumpFlag value) + { + return value switch + { + NodumpFlag.None => "none", + NodumpFlag.Obsolete => "obsolete", + NodumpFlag.Required => "required", + NodumpFlag.Ignore => "ignore", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this OpenMSXSubType value) + { + return value switch + { + OpenMSXSubType.Rom => "rom", + OpenMSXSubType.MegaRom => "megarom", + OpenMSXSubType.SCCPlusCart => "sccpluscart", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// True to use the second mapping option, if it exists + /// String value representing the input, default on error + public static string? AsStringValue(this PackingFlag value, bool useSecond = false) + { + return value switch + { + PackingFlag.None => "none", + PackingFlag.Zip => useSecond ? "yes" : "zip", + PackingFlag.Unzip => useSecond ? "no" : "unzip", + PackingFlag.Partial => "partial", + PackingFlag.Flat => "flat", + PackingFlag.FileOnly => "fileonly", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this Relation value) + { + return value switch + { + Relation.Equal => "eq", + Relation.NotEqual => "ne", + Relation.GreaterThan => "gt", + Relation.LessThanOrEqual => "le", + Relation.LessThan => "lt", + Relation.GreaterThanOrEqual => "ge", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this Runnable value) + { + return value switch + { + Runnable.No => "no", + Runnable.Partial => "partial", + Runnable.Yes => "yes", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this SoftwareListStatus value) + { + return value switch + { + SoftwareListStatus.None => "none", + SoftwareListStatus.Original => "original", + SoftwareListStatus.Compatible => "compatible", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// True to use the second mapping option, if it exists + /// String value representing the input, null on error + public static string? AsStringValue(this Supported value, bool useSecond = false) + { + return value switch + { + Supported.No => useSecond ? "unsupported" : "no", + Supported.Partial => "partial", + Supported.Yes => useSecond ? "supported" : "yes", + _ => null, + }; + } + + /// + /// Get the string value for an input enum, if possible + /// + /// Enum value to parse/param> + /// String value representing the input, null on error + public static string? AsStringValue(this SupportStatus value) + { + return value switch + { + SupportStatus.Good => "good", + SupportStatus.Imperfect => "imperfect", + SupportStatus.Preliminary => "preliminary", + _ => null, + }; + } + + #endregion + } } diff --git a/SabreTools.Data.Models/Metadata/Enums.cs b/SabreTools.Data.Models/Metadata/Enums.cs new file mode 100644 index 00000000..dd84bd6f --- /dev/null +++ b/SabreTools.Data.Models/Metadata/Enums.cs @@ -0,0 +1,482 @@ +namespace SabreTools.Data.Models.Metadata +{ + /// + /// Determine the chip type + /// + public enum ChipType + { + /// "cpu" + CPU, + + /// "audio" + Audio, + } + + /// + /// Determine the control type + /// + public enum ControlType + { + /// "joy" + Joy, + + /// "stick" + Stick, + + /// "paddle" + Paddle, + + /// "pedal" + Pedal, + + /// "lightgun" + Lightgun, + + /// "positional" + Positional, + + /// "dial" + Dial, + + /// "trackball" + Trackball, + + /// "mouse" + Mouse, + + /// "only_buttons" + OnlyButtons, + + /// "keypad" + Keypad, + + /// "keyboard" + Keyboard, + + /// "mahjong" + Mahjong, + + /// "hanafuda" + Hanafuda, + + /// "gambling" + Gambling, + } + + /// + /// Determine the device type + /// + public enum DeviceType + { + /// "unknown" + Unknown, + + /// "cartridge" + Cartridge, + + /// "floppydisk" + FloppyDisk, + + /// "harddisk" + HardDisk, + + /// "cylinder" + Cylinder, + + /// "cassette" + Cassette, + + /// "punchcard" + PunchCard, + + /// "punchtape" + PunchTape, + + /// "printout" + Printout, + + /// "serial" + Serial, + + /// "parallel" + Parallel, + + /// "snapshot" + Snapshot, + + /// "quickload" + QuickLoad, + + /// "memcard" + MemCard, + + /// "cdrom" + CDROM, + + /// "magtape" + MagTape, + + /// "romimage" + ROMImage, + + /// "midiin" + MIDIIn, + + /// "midiout" + MIDIOut, + + /// "picture" + Picture, + + /// "vidfile" + VidFile, + } + + /// + /// Determine the display type + /// + public enum DisplayType + { + /// "raster" + Raster, + + /// "vector" + Vector, + + /// "lcd" + LCD, + + /// "svg" + SVG, + + /// "unknown" + Unknown, + } + + /// + /// Determine the endianness + /// + public enum Endianness + { + /// "big" + Big, + + /// "little" + Little, + } + + /// + /// Determine the emulation status + /// + public enum FeatureStatus + { + /// "unemulated" + Unemulated, + + /// "imperfect" + Imperfect, + } + + /// + /// Determine the feature type + /// + public enum FeatureType + { + /// "protection" + Protection, + + /// "palette" + Palette, + + /// "graphics" + Graphics, + + /// "sound" + Sound, + + /// "controls" + Controls, + + /// "keyboard" + Keyboard, + + /// "mouse" + Mouse, + + /// "microphone" + Microphone, + + /// "camera" + Camera, + + /// "disk" + Disk, + + /// "printer" + Printer, + + /// "lan" + Lan, + + /// "wan" + Wan, + + /// "timing" + Timing, + } + + /// + /// Determine the status of the item + /// + public enum ItemStatus + { + /// "none", "no" + None, + + /// "good" + Good, + + /// "baddump" + BadDump, + + /// "nodump", "yes" + Nodump, + + /// "verified" + Verified, + } + + /// + /// Determine the loadflag value + /// + public enum LoadFlag + { + /// "load16_byte" + Load16Byte, + + /// "load16_word" + Load16Word, + + /// "load16_word_swap" + Load16WordSwap, + + /// "load32_byte" + Load32Byte, + + /// "load32_word" + Load32Word, + + /// "load32_word_swap" + Load32WordSwap, + + /// "load32_dword" + Load32DWord, + + /// "load64_word" + Load64Word, + + /// "load64_word_swap" + Load64WordSwap, + + /// "reload" + Reload, + + /// "fill" + Fill, + + /// "continue" + Continue, + + /// "reload_plain" + ReloadPlain, + + /// "ignore" + Ignore, + } + + /// + /// Determines merging tag handling for DAT output + /// + public enum MergingFlag + { + /// "none" + None = 0, + + /// "split" + Split, + + /// "merged" + Merged, + + /// "nonmerged", "unmerged" + NonMerged, + + /// "fullmerged" + /// This is not usually defined for Merging flags + FullMerged, + + /// "device", "deviceunmerged", "devicenonmerged" + /// This is not usually defined for Merging flags + DeviceNonMerged, + + /// "full", "fullunmerged", "fullnonmerged" + /// This is not usually defined for Merging flags + FullNonMerged, + } + + /// + /// Determines nodump tag handling for DAT output + /// + public enum NodumpFlag + { + /// "none" + None = 0, + + /// "obsolete" + Obsolete, + + /// "required" + Required, + + /// "ignore" + Ignore, + } + + /// + /// Determine which OpenMSX subtype an item is + /// + public enum OpenMSXSubType + { + /// "rom" + Rom, + + /// "megarom" + MegaRom, + + /// "sccpluscart" + SCCPlusCart, + } + + /// + /// Determines packing tag handling for DAT output + /// + public enum PackingFlag + { + /// "none" + None = 0, + + /// + /// Force all sets to be in archives, except disk and media + /// + /// "zip", "yes" + Zip, + + /// + /// Force all sets to be extracted into subfolders + /// + /// "unzip", "no" + Unzip, + + /// + /// Force sets with single items to be extracted to the parent folder + /// + /// "partial" + Partial, + + /// + /// Force all sets to be extracted to the parent folder + /// + /// "flat" + Flat, + + /// + /// Force all sets to have all archives treated as files + /// + /// "fileonly" + FileOnly, + } + + /// + /// Determine relation of value to condition + /// + public enum Relation + { + /// "eq" + Equal, + + /// "ne" + NotEqual, + + /// "gt" + GreaterThan, + + /// "le" + LessThanOrEqual, + + /// "lt" + LessThan, + + /// "ge" + GreaterThanOrEqual, + } + + /// + /// Determine machine runnable status + /// + public enum Runnable + { + /// "no" + No, + + /// "partial" + Partial, + + /// "yes" + Yes, + } + + /// + /// Determine software list status + /// + public enum SoftwareListStatus + { + /// "none" + None, + + /// "original" + Original, + + /// "compatible" + Compatible, + } + + /// + /// Determine machine support status + /// + public enum Supported + { + /// "no", "unsupported" + No, + + /// "partial" + Partial, + + /// "yes", "supported" + Yes, + } + + /// + /// Determine driver support statuses + /// + public enum SupportStatus + { + /// "good" + Good, + + /// "imperfect" + Imperfect, + + /// "preliminary" + Preliminary, + } +} diff --git a/SabreTools.Metadata.DatFiles.Test/ConvertersTests.cs b/SabreTools.Metadata.DatFiles.Test/ConvertersTests.cs deleted file mode 100644 index a7603026..00000000 --- a/SabreTools.Metadata.DatFiles.Test/ConvertersTests.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Xunit; - -namespace SabreTools.Metadata.DatFiles.Test -{ - public class ConvertersTests - { - #region Generators - - [Theory] - [InlineData(MergingFlag.None, 12)] - [InlineData(NodumpFlag.None, 4)] - [InlineData(PackingFlag.None, 8)] - public void GenerateToEnumTest(T value, int expected) - { - var actual = Converters.GenerateToEnum(); - Assert.Equal(default, value); - Assert.Equal(expected, actual.Keys.Count); - } - - #endregion - } -} diff --git a/SabreTools.Metadata.DatFiles.Test/DatFileTests.ToMetadata.cs b/SabreTools.Metadata.DatFiles.Test/DatFileTests.ToMetadata.cs index 0b6c2d42..03bf581d 100644 --- a/SabreTools.Metadata.DatFiles.Test/DatFileTests.ToMetadata.cs +++ b/SabreTools.Metadata.DatFiles.Test/DatFileTests.ToMetadata.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using SabreTools.Data.Extensions; using SabreTools.Hashing; using SabreTools.Metadata.DatItems; using SabreTools.Metadata.DatItems.Formats; diff --git a/SabreTools.Metadata.DatFiles.Test/DatStatisticsTests.cs b/SabreTools.Metadata.DatFiles.Test/DatStatisticsTests.cs index 7ec44fb7..a0f75e80 100644 --- a/SabreTools.Metadata.DatFiles.Test/DatStatisticsTests.cs +++ b/SabreTools.Metadata.DatFiles.Test/DatStatisticsTests.cs @@ -1,7 +1,9 @@ +using SabreTools.Data.Extensions; using SabreTools.Hashing; using SabreTools.Metadata.DatItems; using SabreTools.Metadata.DatItems.Formats; using Xunit; +using ItemStatus = SabreTools.Data.Models.Metadata.ItemStatus; namespace SabreTools.Metadata.DatFiles.Test { diff --git a/SabreTools.Metadata.DatFiles.Test/ExtensionsTests.cs b/SabreTools.Metadata.DatFiles.Test/ExtensionsTests.cs deleted file mode 100644 index 899777d4..00000000 --- a/SabreTools.Metadata.DatFiles.Test/ExtensionsTests.cs +++ /dev/null @@ -1,114 +0,0 @@ -using Xunit; - -namespace SabreTools.Metadata.DatFiles.Test -{ - public class ExtensionsTests - { - #region String to Enum - - [Theory] - [InlineData(null, MergingFlag.None)] - [InlineData("none", MergingFlag.None)] - [InlineData("split", MergingFlag.Split)] - [InlineData("merged", MergingFlag.Merged)] - [InlineData("nonmerged", MergingFlag.NonMerged)] - [InlineData("unmerged", MergingFlag.NonMerged)] - [InlineData("fullmerged", MergingFlag.FullMerged)] - [InlineData("device", MergingFlag.DeviceNonMerged)] - [InlineData("devicenonmerged", MergingFlag.DeviceNonMerged)] - [InlineData("deviceunmerged", MergingFlag.DeviceNonMerged)] - [InlineData("full", MergingFlag.FullNonMerged)] - [InlineData("fullnonmerged", MergingFlag.FullNonMerged)] - [InlineData("fullunmerged", MergingFlag.FullNonMerged)] - public void AsMergingFlagTest(string? field, MergingFlag expected) - { - MergingFlag actual = field.AsMergingFlag(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, NodumpFlag.None)] - [InlineData("none", NodumpFlag.None)] - [InlineData("obsolete", NodumpFlag.Obsolete)] - [InlineData("required", NodumpFlag.Required)] - [InlineData("ignore", NodumpFlag.Ignore)] - public void AsNodumpFlagTest(string? field, NodumpFlag expected) - { - NodumpFlag actual = field.AsNodumpFlag(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, PackingFlag.None)] - [InlineData("none", PackingFlag.None)] - [InlineData("yes", PackingFlag.Zip)] - [InlineData("zip", PackingFlag.Zip)] - [InlineData("no", PackingFlag.Unzip)] - [InlineData("unzip", PackingFlag.Unzip)] - [InlineData("partial", PackingFlag.Partial)] - [InlineData("flat", PackingFlag.Flat)] - [InlineData("fileonly", PackingFlag.FileOnly)] - public void AsPackingFlagTest(string? field, PackingFlag expected) - { - PackingFlag actual = field.AsPackingFlag(); - Assert.Equal(expected, actual); - } - - #endregion - - #region Enum to String - - [Theory] - [InlineData(MergingFlag.None, true, "none")] - [InlineData(MergingFlag.None, false, "none")] - [InlineData(MergingFlag.Split, true, "split")] - [InlineData(MergingFlag.Split, false, "split")] - [InlineData(MergingFlag.Merged, true, "merged")] - [InlineData(MergingFlag.Merged, false, "merged")] - [InlineData(MergingFlag.NonMerged, true, "unmerged")] - [InlineData(MergingFlag.NonMerged, false, "nonmerged")] - [InlineData(MergingFlag.FullMerged, true, "fullmerged")] - [InlineData(MergingFlag.FullMerged, false, "fullmerged")] - [InlineData(MergingFlag.DeviceNonMerged, true, "deviceunmerged")] - [InlineData(MergingFlag.DeviceNonMerged, false, "device")] - [InlineData(MergingFlag.FullNonMerged, true, "fullunmerged")] - [InlineData(MergingFlag.FullNonMerged, false, "full")] - public void FromMergingFlagTest(MergingFlag field, bool useSecond, string? expected) - { - string? actual = field.AsStringValue(useSecond); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(NodumpFlag.None, "none")] - [InlineData(NodumpFlag.Obsolete, "obsolete")] - [InlineData(NodumpFlag.Required, "required")] - [InlineData(NodumpFlag.Ignore, "ignore")] - public void FromNodumpFlagTest(NodumpFlag field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(PackingFlag.None, true, "none")] - [InlineData(PackingFlag.None, false, "none")] - [InlineData(PackingFlag.Zip, true, "yes")] - [InlineData(PackingFlag.Zip, false, "zip")] - [InlineData(PackingFlag.Unzip, true, "no")] - [InlineData(PackingFlag.Unzip, false, "unzip")] - [InlineData(PackingFlag.Partial, true, "partial")] - [InlineData(PackingFlag.Partial, false, "partial")] - [InlineData(PackingFlag.Flat, true, "flat")] - [InlineData(PackingFlag.Flat, false, "flat")] - [InlineData(PackingFlag.FileOnly, true, "fileonly")] - [InlineData(PackingFlag.FileOnly, false, "fileonly")] - public void FromPackingFlagTest(PackingFlag field, bool useSecond, string? expected) - { - string? actual = field.AsStringValue(useSecond); - Assert.Equal(expected, actual); - } - - #endregion - } -} diff --git a/SabreTools.Metadata.DatFiles/DatFile.FromMetadata.cs b/SabreTools.Metadata.DatFiles/DatFile.FromMetadata.cs index 9fef07f6..e3704e9d 100644 --- a/SabreTools.Metadata.DatFiles/DatFile.FromMetadata.cs +++ b/SabreTools.Metadata.DatFiles/DatFile.FromMetadata.cs @@ -6,6 +6,10 @@ using System.Threading.Tasks; using SabreTools.Metadata.Filter; using SabreTools.Metadata.DatItems; using SabreTools.Metadata.DatItems.Formats; +using SabreTools.Data.Extensions; +using MergingFlag = SabreTools.Data.Models.Metadata.MergingFlag; +using NodumpFlag = SabreTools.Data.Models.Metadata.NodumpFlag; +using PackingFlag = SabreTools.Data.Models.Metadata.PackingFlag; #pragma warning disable IDE0056 // Use index operator #pragma warning disable IDE0060 // Remove unused parameter diff --git a/SabreTools.Metadata.DatFiles/DatFile.ToMetadata.cs b/SabreTools.Metadata.DatFiles/DatFile.ToMetadata.cs index c0f6c1e7..d57308c7 100644 --- a/SabreTools.Metadata.DatFiles/DatFile.ToMetadata.cs +++ b/SabreTools.Metadata.DatFiles/DatFile.ToMetadata.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Linq; +using SabreTools.Data.Extensions; using SabreTools.Metadata.DatItems; +using OpenMSXSubType = SabreTools.Data.Models.Metadata.OpenMSXSubType; namespace SabreTools.Metadata.DatFiles { @@ -935,7 +937,7 @@ namespace SabreTools.Metadata.DatFiles [Data.Models.Metadata.Video.AspectYKey] = displayItem.ReadLong(Data.Models.Metadata.Video.AspectYKey).ToString(), [Data.Models.Metadata.Video.HeightKey] = displayItem.ReadLong(Data.Models.Metadata.Display.HeightKey).ToString(), [Data.Models.Metadata.Video.RefreshKey] = displayItem.ReadDouble(Data.Models.Metadata.Display.RefreshKey).ToString(), - [Data.Models.Metadata.Video.ScreenKey] = displayItem.ReadString(Data.Models.Metadata.Display.DisplayTypeKey).AsDisplayType().AsStringValue(), + [Data.Models.Metadata.Video.ScreenKey] = displayItem.ReadString(Data.Models.Metadata.Display.DisplayTypeKey).AsDisplayType()?.AsStringValue(), [Data.Models.Metadata.Video.WidthKey] = displayItem.ReadLong(Data.Models.Metadata.Display.WidthKey).ToString() }; @@ -1060,8 +1062,6 @@ namespace SabreTools.Metadata.DatFiles EnsureMachineKey(machine, Data.Models.Metadata.Machine.DumpKey); AppendToMachineKey(machine, Data.Models.Metadata.Machine.DumpKey, dumpSccPlusCart); break; - case OpenMSXSubType.NULL: - break; default: // This should never happen break; diff --git a/SabreTools.Metadata.DatFiles/DatHeader.cs b/SabreTools.Metadata.DatFiles/DatHeader.cs index 84bd23ac..cdb1becc 100644 --- a/SabreTools.Metadata.DatFiles/DatHeader.cs +++ b/SabreTools.Metadata.DatFiles/DatHeader.cs @@ -1,7 +1,11 @@ using System; using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; using SabreTools.Metadata.Filter; +using MergingFlag = SabreTools.Data.Models.Metadata.MergingFlag; +using NodumpFlag = SabreTools.Data.Models.Metadata.NodumpFlag; +using PackingFlag = SabreTools.Data.Models.Metadata.PackingFlag; namespace SabreTools.Metadata.DatFiles { diff --git a/SabreTools.Metadata.DatFiles/DatStatistics.cs b/SabreTools.Metadata.DatFiles/DatStatistics.cs index 81466118..63eb73e9 100644 --- a/SabreTools.Metadata.DatFiles/DatStatistics.cs +++ b/SabreTools.Metadata.DatFiles/DatStatistics.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using SabreTools.Data.Extensions; using SabreTools.Hashing; using SabreTools.Metadata.DatItems; using SabreTools.Metadata.DatItems.Formats; +using ItemStatus = SabreTools.Data.Models.Metadata.ItemStatus; namespace SabreTools.Metadata.DatFiles { @@ -406,7 +408,7 @@ namespace SabreTools.Metadata.DatFiles /// Item to add info from private void AddItemStatistics(Disk disk) { - ItemStatus status = disk.ReadString(Data.Models.Metadata.Disk.StatusKey).AsItemStatus(); + ItemStatus? status = disk.ReadString(Data.Models.Metadata.Disk.StatusKey).AsItemStatus(); if (status != ItemStatus.Nodump) { AddHashCount(HashType.MD5, string.IsNullOrEmpty(disk.ReadString(Data.Models.Metadata.Disk.MD5Key)) ? 0 : 1); @@ -425,7 +427,7 @@ namespace SabreTools.Metadata.DatFiles /// Item to add info from private void AddItemStatistics(Data.Models.Metadata.Disk disk) { - ItemStatus status = disk.ReadString(Data.Models.Metadata.Disk.StatusKey).AsItemStatus(); + ItemStatus? status = disk.ReadString(Data.Models.Metadata.Disk.StatusKey).AsItemStatus(); if (status != ItemStatus.Nodump) { AddHashCount(HashType.MD5, string.IsNullOrEmpty(disk.ReadString(Data.Models.Metadata.Disk.MD5Key)) ? 0 : 1); @@ -481,7 +483,7 @@ namespace SabreTools.Metadata.DatFiles /// Item to add info from private void AddItemStatistics(Rom rom) { - ItemStatus status = rom.ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus(); + ItemStatus? status = rom.ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus(); if (status != ItemStatus.Nodump) { TotalSize += rom.ReadLong(Data.Models.Metadata.Rom.SizeKey) ?? 0; @@ -512,7 +514,7 @@ namespace SabreTools.Metadata.DatFiles /// Item to add info from private void AddItemStatistics(Data.Models.Metadata.Rom rom) { - ItemStatus status = rom.ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus(); + ItemStatus? status = rom.ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus(); if (status != ItemStatus.Nodump) { TotalSize += rom.ReadLong(Data.Models.Metadata.Rom.SizeKey) ?? 0; @@ -597,7 +599,7 @@ namespace SabreTools.Metadata.DatFiles /// Item to remove info for private void RemoveItemStatistics(Disk disk) { - ItemStatus status = disk.ReadString(Data.Models.Metadata.Disk.StatusKey).AsItemStatus(); + ItemStatus? status = disk.ReadString(Data.Models.Metadata.Disk.StatusKey).AsItemStatus(); if (status != ItemStatus.Nodump) { RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(disk.ReadString(Data.Models.Metadata.Disk.MD5Key)) ? 0 : 1); @@ -616,7 +618,7 @@ namespace SabreTools.Metadata.DatFiles /// Item to remove info for private void RemoveItemStatistics(Data.Models.Metadata.Disk disk) { - ItemStatus status = disk.ReadString(Data.Models.Metadata.Disk.StatusKey).AsItemStatus(); + ItemStatus? status = disk.ReadString(Data.Models.Metadata.Disk.StatusKey).AsItemStatus(); if (status != ItemStatus.Nodump) { RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(disk.ReadString(Data.Models.Metadata.Disk.MD5Key)) ? 0 : 1); @@ -672,7 +674,7 @@ namespace SabreTools.Metadata.DatFiles /// Item to remove info for private void RemoveItemStatistics(Rom rom) { - ItemStatus status = rom.ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus(); + ItemStatus? status = rom.ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus(); if (status != ItemStatus.Nodump) { TotalSize -= rom.ReadLong(Data.Models.Metadata.Rom.SizeKey) ?? 0; @@ -703,7 +705,7 @@ namespace SabreTools.Metadata.DatFiles /// Item to remove info for private void RemoveItemStatistics(Data.Models.Metadata.Rom rom) { - ItemStatus status = rom.ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus(); + ItemStatus? status = rom.ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus(); if (status != ItemStatus.Nodump) { TotalSize -= rom.ReadLong(Data.Models.Metadata.Rom.SizeKey) ?? 0; diff --git a/SabreTools.Metadata.DatFiles/Enums.cs b/SabreTools.Metadata.DatFiles/Enums.cs index 4c0ff495..92cc4208 100644 --- a/SabreTools.Metadata.DatFiles/Enums.cs +++ b/SabreTools.Metadata.DatFiles/Enums.cs @@ -177,91 +177,4 @@ namespace SabreTools.Metadata.DatFiles // Specialty combinations ALL = ulong.MaxValue, } - - /// - /// Determines merging tag handling for DAT output - /// - public enum MergingFlag - { - [Mapping("none")] - None = 0, - - [Mapping("split")] - Split, - - [Mapping("merged")] - Merged, - - [Mapping("nonmerged", "unmerged")] - NonMerged, - - /// This is not usually defined for Merging flags - [Mapping("fullmerged")] - FullMerged, - - /// This is not usually defined for Merging flags - [Mapping("device", "deviceunmerged", "devicenonmerged")] - DeviceNonMerged, - - /// This is not usually defined for Merging flags - [Mapping("full", "fullunmerged", "fullnonmerged")] - FullNonMerged, - } - - /// - /// Determines nodump tag handling for DAT output - /// - public enum NodumpFlag - { - [Mapping("none")] - None = 0, - - [Mapping("obsolete")] - Obsolete, - - [Mapping("required")] - Required, - - [Mapping("ignore")] - Ignore, - } - - /// - /// Determines packing tag handling for DAT output - /// - public enum PackingFlag - { - [Mapping("none")] - None = 0, - - /// - /// Force all sets to be in archives, except disk and media - /// - [Mapping("zip", "yes")] - Zip, - - /// - /// Force all sets to be extracted into subfolders - /// - [Mapping("unzip", "no")] - Unzip, - - /// - /// Force sets with single items to be extracted to the parent folder - /// - [Mapping("partial")] - Partial, - - /// - /// Force all sets to be extracted to the parent folder - /// - [Mapping("flat")] - Flat, - - /// - /// Force all sets to have all archives treated as files - /// - [Mapping("fileonly")] - FileOnly, - } } diff --git a/SabreTools.Metadata.DatFiles/Extensions.cs b/SabreTools.Metadata.DatFiles/Extensions.cs deleted file mode 100644 index d64c9fd6..00000000 --- a/SabreTools.Metadata.DatFiles/Extensions.cs +++ /dev/null @@ -1,171 +0,0 @@ -using System.Collections.Generic; - -namespace SabreTools.Metadata.DatFiles -{ - public static class Extensions - { - #region Private Maps - - /// - /// Set of enum to string mappings for MergingFlag - /// - private static readonly Dictionary _toMergingFlagMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for MergingFlag - /// - private static readonly Dictionary _fromMergingFlagMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of string to enum mappings for MergingFlag (secondary) - /// - private static readonly Dictionary _fromMergingFlagSecondaryMap = Converters.GenerateToString(useSecond: true); - - /// - /// Set of enum to string mappings for NodumpFlag - /// - private static readonly Dictionary _toNodumpFlagMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for NodumpFlag - /// - private static readonly Dictionary _fromNodumpFlagMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for PackingFlag - /// - private static readonly Dictionary _toPackingFlagMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for PackingFlag - /// - private static readonly Dictionary _fromPackingFlagMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of string to enum mappings for PackingFlag (secondary) - /// - private static readonly Dictionary _fromPackingFlagSecondaryMap = Converters.GenerateToString(useSecond: true); - - #endregion - - #region String to Enum - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static MergingFlag AsMergingFlag(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toMergingFlagMap.TryGetValue(value, out MergingFlag mergingFlag)) - return mergingFlag; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static NodumpFlag AsNodumpFlag(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toNodumpFlagMap.TryGetValue(value, out NodumpFlag nodumpFlag)) - return nodumpFlag; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static PackingFlag AsPackingFlag(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toPackingFlagMap.TryGetValue(value, out PackingFlag packingFlag)) - return packingFlag; - - // Otherwise, return the default value for the enum - return default; - } - - #endregion - - #region Enum to String - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this MergingFlag value, bool useSecond = false) - { - // Try to get the value from the mappings - if (!useSecond && _fromMergingFlagMap.TryGetValue(value, out string? mergingFlag)) - return mergingFlag; - else if (useSecond && _fromMergingFlagSecondaryMap.TryGetValue(value, out string? mergingFlagSecondary)) - return mergingFlagSecondary; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this NodumpFlag value) - { - // Try to get the value from the mappings - if (_fromNodumpFlagMap.TryGetValue(value, out string? nodumpFlag)) - return nodumpFlag; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this PackingFlag value, bool useSecond = false) - { - // Try to get the value from the mappings - if (!useSecond && _fromPackingFlagMap.TryGetValue(value, out string? packingFlag)) - return packingFlag; - else if (useSecond && _fromPackingFlagSecondaryMap.TryGetValue(value, out string? packingFlagSecondary)) - return packingFlagSecondary; - - // Otherwise, return null - return null; - } - - #endregion - } -} diff --git a/SabreTools.Metadata.DatFiles/Formats/ClrMamePro.cs b/SabreTools.Metadata.DatFiles/Formats/ClrMamePro.cs index 710f3800..69244997 100644 --- a/SabreTools.Metadata.DatFiles/Formats/ClrMamePro.cs +++ b/SabreTools.Metadata.DatFiles/Formats/ClrMamePro.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using SabreTools.Data.Extensions; using SabreTools.Metadata.DatItems; using SabreTools.Metadata.DatItems.Formats; using SabreTools.Metadata.Filter; @@ -133,14 +134,14 @@ namespace SabreTools.Metadata.DatFiles.Formats break; case Chip chip: - if (chip.ReadString(Data.Models.Metadata.Chip.ChipTypeKey).AsChipType() == ChipType.NULL) + if (chip.ReadString(Data.Models.Metadata.Chip.ChipTypeKey).AsChipType() is null) missingFields.Add(Data.Models.Metadata.Chip.ChipTypeKey); if (string.IsNullOrEmpty(chip.GetName())) missingFields.Add(Data.Models.Metadata.Chip.NameKey); break; case Display display: - if (display.ReadString(Data.Models.Metadata.Display.DisplayTypeKey).AsDisplayType() == DisplayType.NULL) + if (display.ReadString(Data.Models.Metadata.Display.DisplayTypeKey).AsDisplayType() is null) missingFields.Add(Data.Models.Metadata.Display.DisplayTypeKey); if (display.ReadLong(Data.Models.Metadata.Display.RotateKey) is null) missingFields.Add(Data.Models.Metadata.Display.RotateKey); @@ -164,9 +165,9 @@ namespace SabreTools.Metadata.DatFiles.Formats break; case Driver driver: - if (driver.ReadString(Data.Models.Metadata.Driver.StatusKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.StatusKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.StatusKey); - if (driver.ReadString(Data.Models.Metadata.Driver.EmulationKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.EmulationKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.EmulationKey); break; diff --git a/SabreTools.Metadata.DatFiles/Formats/Listxml.cs b/SabreTools.Metadata.DatFiles/Formats/Listxml.cs index 6c7cb880..cd20f0c8 100644 --- a/SabreTools.Metadata.DatFiles/Formats/Listxml.cs +++ b/SabreTools.Metadata.DatFiles/Formats/Listxml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using SabreTools.Data.Extensions; using SabreTools.Metadata.DatItems; using SabreTools.Metadata.DatItems.Formats; using SabreTools.Metadata.Filter; @@ -303,12 +304,12 @@ namespace SabreTools.Metadata.DatFiles.Formats case Chip chip: if (string.IsNullOrEmpty(chip.GetName())) missingFields.Add(Data.Models.Metadata.Chip.NameKey); - if (chip.ReadString(Data.Models.Metadata.Chip.ChipTypeKey).AsChipType() == ChipType.NULL) + if (chip.ReadString(Data.Models.Metadata.Chip.ChipTypeKey).AsChipType() is null) missingFields.Add(Data.Models.Metadata.Chip.ChipTypeKey); break; case Display display: - if (display.ReadString(Data.Models.Metadata.Display.DisplayTypeKey).AsDisplayType() == DisplayType.NULL) + if (display.ReadString(Data.Models.Metadata.Display.DisplayTypeKey).AsDisplayType() is null) missingFields.Add(Data.Models.Metadata.Display.DisplayTypeKey); if (display.ReadDouble(Data.Models.Metadata.Display.RefreshKey) is null) missingFields.Add(Data.Models.Metadata.Display.RefreshKey); @@ -349,23 +350,23 @@ namespace SabreTools.Metadata.DatFiles.Formats break; case Driver driver: - if (driver.ReadString(Data.Models.Metadata.Driver.StatusKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.StatusKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.StatusKey); - if (driver.ReadString(Data.Models.Metadata.Driver.EmulationKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.EmulationKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.EmulationKey); - if (driver.ReadString(Data.Models.Metadata.Driver.CocktailKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.CocktailKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.CocktailKey); - if (driver.ReadString(Data.Models.Metadata.Driver.SaveStateKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.SaveStateKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.SaveStateKey); break; case Feature feature: - if (feature.ReadString(Data.Models.Metadata.Feature.FeatureTypeKey).AsFeatureType() == FeatureType.NULL) + if (feature.ReadString(Data.Models.Metadata.Feature.FeatureTypeKey).AsFeatureType() is null) missingFields.Add(Data.Models.Metadata.Feature.FeatureTypeKey); break; case Device device: - if (device.ReadString(Data.Models.Metadata.Device.DeviceTypeKey).AsDeviceType() == DeviceType.NULL) + if (device.ReadString(Data.Models.Metadata.Device.DeviceTypeKey).AsDeviceType() is null) missingFields.Add(Data.Models.Metadata.Device.DeviceTypeKey); break; @@ -379,7 +380,7 @@ namespace SabreTools.Metadata.DatFiles.Formats missingFields.Add(Data.Models.Metadata.SoftwareList.TagKey); if (string.IsNullOrEmpty(softwarelist.GetName())) missingFields.Add(Data.Models.Metadata.SoftwareList.NameKey); - if (softwarelist.ReadString(Data.Models.Metadata.SoftwareList.StatusKey).AsSoftwareListStatus() == SoftwareListStatus.None) + if (softwarelist.ReadString(Data.Models.Metadata.SoftwareList.StatusKey).AsSoftwareListStatus() == null) missingFields.Add(Data.Models.Metadata.SoftwareList.StatusKey); break; diff --git a/SabreTools.Metadata.DatFiles/Formats/Logiqx.cs b/SabreTools.Metadata.DatFiles/Formats/Logiqx.cs index e3726e1b..e69367d6 100644 --- a/SabreTools.Metadata.DatFiles/Formats/Logiqx.cs +++ b/SabreTools.Metadata.DatFiles/Formats/Logiqx.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using SabreTools.Data.Extensions; using SabreTools.Metadata.DatItems; using SabreTools.Metadata.DatItems.Formats; @@ -343,13 +344,13 @@ namespace SabreTools.Metadata.DatFiles.Formats break; case Driver driver: - if (driver.ReadString(Data.Models.Metadata.Driver.StatusKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.StatusKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.StatusKey); - if (driver.ReadString(Data.Models.Metadata.Driver.EmulationKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.EmulationKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.EmulationKey); - if (driver.ReadString(Data.Models.Metadata.Driver.CocktailKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.CocktailKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.CocktailKey); - if (driver.ReadString(Data.Models.Metadata.Driver.SaveStateKey).AsSupportStatus() == SupportStatus.NULL) + if (driver.ReadString(Data.Models.Metadata.Driver.SaveStateKey).AsSupportStatus() is null) missingFields.Add(Data.Models.Metadata.Driver.SaveStateKey); break; @@ -358,7 +359,7 @@ namespace SabreTools.Metadata.DatFiles.Formats missingFields.Add(Data.Models.Metadata.SoftwareList.TagKey); if (string.IsNullOrEmpty(softwarelist.GetName())) missingFields.Add(Data.Models.Metadata.SoftwareList.NameKey); - if (softwarelist.ReadString(Data.Models.Metadata.SoftwareList.StatusKey).AsSoftwareListStatus() == SoftwareListStatus.None) + if (softwarelist.ReadString(Data.Models.Metadata.SoftwareList.StatusKey).AsSoftwareListStatus() == null) missingFields.Add(Data.Models.Metadata.SoftwareList.StatusKey); break; diff --git a/SabreTools.Metadata.DatFiles/ItemDictionary.cs b/SabreTools.Metadata.DatFiles/ItemDictionary.cs index 0ebb0bfc..a2a62eb1 100644 --- a/SabreTools.Metadata.DatFiles/ItemDictionary.cs +++ b/SabreTools.Metadata.DatFiles/ItemDictionary.cs @@ -14,6 +14,8 @@ using SabreTools.Hashing; using SabreTools.Logging; using SabreTools.Text.Compare; using SabreTools.Text.Extensions; +using SabreTools.Data.Extensions; +using ItemStatus = SabreTools.Data.Models.Metadata.ItemStatus; namespace SabreTools.Metadata.DatFiles { diff --git a/SabreTools.Metadata.DatFiles/ItemDictionaryDB.cs b/SabreTools.Metadata.DatFiles/ItemDictionaryDB.cs index 5b5cf994..1583133c 100644 --- a/SabreTools.Metadata.DatFiles/ItemDictionaryDB.cs +++ b/SabreTools.Metadata.DatFiles/ItemDictionaryDB.cs @@ -16,6 +16,8 @@ using SabreTools.Hashing; using SabreTools.Logging; using SabreTools.Text.Compare; using SabreTools.Text.Extensions; +using SabreTools.Data.Extensions; +using ItemStatus = SabreTools.Data.Models.Metadata.ItemStatus; /* * Planning Notes: @@ -451,7 +453,7 @@ namespace SabreTools.Metadata.DatFiles /// public Source? GetSource(long index) { - if (!_sources.TryGetValue(index, out var source)) + if (_sources.TryGetValue(index, out var source)) return source; return null; diff --git a/SabreTools.Metadata.DatItems.Test/ConvertersTests.cs b/SabreTools.Metadata.DatItems.Test/ConvertersTests.cs deleted file mode 100644 index 9b9a0a2e..00000000 --- a/SabreTools.Metadata.DatItems.Test/ConvertersTests.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Xunit; - -namespace SabreTools.Metadata.DatItems.Test -{ - public class ConvertersTests - { - #region Generators - - [Theory] - [InlineData(ChipType.NULL, 2)] - [InlineData(ControlType.NULL, 15)] - [InlineData(DeviceType.NULL, 21)] - [InlineData(DisplayType.NULL, 5)] - [InlineData(Endianness.NULL, 2)] - [InlineData(FeatureStatus.NULL, 2)] - [InlineData(FeatureType.NULL, 14)] - [InlineData(ItemStatus.NULL, 7)] - [InlineData(ItemType.NULL, 54)] - [InlineData(LoadFlag.NULL, 14)] - [InlineData(MachineType.None, 6)] - [InlineData(OpenMSXSubType.NULL, 3)] - [InlineData(Relation.NULL, 6)] - [InlineData(Runnable.NULL, 3)] - [InlineData(SoftwareListStatus.None, 3)] - [InlineData(Supported.NULL, 5)] - [InlineData(SupportStatus.NULL, 3)] - public void GenerateToEnumTest(T value, int expected) - { - var actual = Converters.GenerateToEnum(); - Assert.Equal(default, value); - Assert.Equal(expected, actual.Keys.Count); - } - - #endregion - } -} diff --git a/SabreTools.Metadata.DatItems.Test/ExtensionsTests.cs b/SabreTools.Metadata.DatItems.Test/ExtensionsTests.cs index 1ce4b2e3..dfb28c81 100644 --- a/SabreTools.Metadata.DatItems.Test/ExtensionsTests.cs +++ b/SabreTools.Metadata.DatItems.Test/ExtensionsTests.cs @@ -6,138 +6,6 @@ namespace SabreTools.Metadata.DatItems.Test { #region String to Enum - [Theory] - [InlineData(null, ChipType.NULL)] - [InlineData("cpu", ChipType.CPU)] - [InlineData("audio", ChipType.Audio)] - public void AsChipTypeTest(string? field, ChipType expected) - { - ChipType actual = field.AsChipType(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, ControlType.NULL)] - [InlineData("joy", ControlType.Joy)] - [InlineData("stick", ControlType.Stick)] - [InlineData("paddle", ControlType.Paddle)] - [InlineData("pedal", ControlType.Pedal)] - [InlineData("lightgun", ControlType.Lightgun)] - [InlineData("positional", ControlType.Positional)] - [InlineData("dial", ControlType.Dial)] - [InlineData("trackball", ControlType.Trackball)] - [InlineData("mouse", ControlType.Mouse)] - [InlineData("only_buttons", ControlType.OnlyButtons)] - [InlineData("keypad", ControlType.Keypad)] - [InlineData("keyboard", ControlType.Keyboard)] - [InlineData("mahjong", ControlType.Mahjong)] - [InlineData("hanafuda", ControlType.Hanafuda)] - [InlineData("gambling", ControlType.Gambling)] - public void AsControlTypeTest(string? field, ControlType expected) - { - ControlType actual = field.AsControlType(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, DeviceType.NULL)] - [InlineData("unknown", DeviceType.Unknown)] - [InlineData("cartridge", DeviceType.Cartridge)] - [InlineData("floppydisk", DeviceType.FloppyDisk)] - [InlineData("harddisk", DeviceType.HardDisk)] - [InlineData("cylinder", DeviceType.Cylinder)] - [InlineData("cassette", DeviceType.Cassette)] - [InlineData("punchcard", DeviceType.PunchCard)] - [InlineData("punchtape", DeviceType.PunchTape)] - [InlineData("printout", DeviceType.Printout)] - [InlineData("serial", DeviceType.Serial)] - [InlineData("parallel", DeviceType.Parallel)] - [InlineData("snapshot", DeviceType.Snapshot)] - [InlineData("quickload", DeviceType.QuickLoad)] - [InlineData("memcard", DeviceType.MemCard)] - [InlineData("cdrom", DeviceType.CDROM)] - [InlineData("magtape", DeviceType.MagTape)] - [InlineData("romimage", DeviceType.ROMImage)] - [InlineData("midiin", DeviceType.MIDIIn)] - [InlineData("midiout", DeviceType.MIDIOut)] - [InlineData("picture", DeviceType.Picture)] - [InlineData("vidfile", DeviceType.VidFile)] - public void AsDeviceTypeTest(string? field, DeviceType expected) - { - DeviceType actual = field.AsDeviceType(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, DisplayType.NULL)] - [InlineData("raster", DisplayType.Raster)] - [InlineData("vector", DisplayType.Vector)] - [InlineData("lcd", DisplayType.LCD)] - [InlineData("svg", DisplayType.SVG)] - [InlineData("unknown", DisplayType.Unknown)] - public void AsDisplayTypeTest(string? field, DisplayType expected) - { - DisplayType actual = field.AsDisplayType(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, Endianness.NULL)] - [InlineData("big", Endianness.Big)] - [InlineData("little", Endianness.Little)] - public void AsEndiannessTest(string? field, Endianness expected) - { - Endianness actual = field.AsEndianness(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, FeatureStatus.NULL)] - [InlineData("unemulated", FeatureStatus.Unemulated)] - [InlineData("imperfect", FeatureStatus.Imperfect)] - public void AsFeatureStatusTest(string? field, FeatureStatus expected) - { - FeatureStatus actual = field.AsFeatureStatus(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, FeatureType.NULL)] - [InlineData("protection", FeatureType.Protection)] - [InlineData("palette", FeatureType.Palette)] - [InlineData("graphics", FeatureType.Graphics)] - [InlineData("sound", FeatureType.Sound)] - [InlineData("controls", FeatureType.Controls)] - [InlineData("keyboard", FeatureType.Keyboard)] - [InlineData("mouse", FeatureType.Mouse)] - [InlineData("microphone", FeatureType.Microphone)] - [InlineData("camera", FeatureType.Camera)] - [InlineData("disk", FeatureType.Disk)] - [InlineData("printer", FeatureType.Printer)] - [InlineData("lan", FeatureType.Lan)] - [InlineData("wan", FeatureType.Wan)] - [InlineData("timing", FeatureType.Timing)] - public void AsFeatureTypeTest(string? field, FeatureType expected) - { - FeatureType actual = field.AsFeatureType(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, ItemStatus.NULL)] - [InlineData("none", ItemStatus.None)] - [InlineData("no", ItemStatus.None)] - [InlineData("good", ItemStatus.Good)] - [InlineData("baddump", ItemStatus.BadDump)] - [InlineData("nodump", ItemStatus.Nodump)] - [InlineData("yes", ItemStatus.Nodump)] - [InlineData("verified", ItemStatus.Verified)] - public void AsItemStatusTest(string? field, ItemStatus expected) - { - ItemStatus actual = field.AsItemStatus(); - Assert.Equal(expected, actual); - } - [Theory] [InlineData(null, ItemType.NULL)] [InlineData("adjuster", ItemType.Adjuster)] @@ -199,28 +67,6 @@ namespace SabreTools.Metadata.DatItems.Test Assert.Equal(expected, actual); } - [Theory] - [InlineData(null, LoadFlag.NULL)] - [InlineData("load16_byte", LoadFlag.Load16Byte)] - [InlineData("load16_word", LoadFlag.Load16Word)] - [InlineData("load16_word_swap", LoadFlag.Load16WordSwap)] - [InlineData("load32_byte", LoadFlag.Load32Byte)] - [InlineData("load32_word", LoadFlag.Load32Word)] - [InlineData("load32_word_swap", LoadFlag.Load32WordSwap)] - [InlineData("load32_dword", LoadFlag.Load32DWord)] - [InlineData("load64_word", LoadFlag.Load64Word)] - [InlineData("load64_word_swap", LoadFlag.Load64WordSwap)] - [InlineData("reload", LoadFlag.Reload)] - [InlineData("fill", LoadFlag.Fill)] - [InlineData("continue", LoadFlag.Continue)] - [InlineData("reload_plain", LoadFlag.ReloadPlain)] - [InlineData("ignore", LoadFlag.Ignore)] - public void AsLoadFlagTest(string? field, LoadFlag expected) - { - LoadFlag actual = field.AsLoadFlag(); - Assert.Equal(expected, actual); - } - [Theory] [InlineData(null, MachineType.None)] [InlineData("none", MachineType.None)] @@ -235,211 +81,10 @@ namespace SabreTools.Metadata.DatItems.Test Assert.Equal(expected, actual); } - [Theory] - [InlineData(null, OpenMSXSubType.NULL)] - [InlineData("rom", OpenMSXSubType.Rom)] - [InlineData("megarom", OpenMSXSubType.MegaRom)] - [InlineData("sccpluscart", OpenMSXSubType.SCCPlusCart)] - public void AsOpenMSXSubTypeTest(string? field, OpenMSXSubType expected) - { - OpenMSXSubType actual = field.AsOpenMSXSubType(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, Relation.NULL)] - [InlineData("eq", Relation.Equal)] - [InlineData("ne", Relation.NotEqual)] - [InlineData("gt", Relation.GreaterThan)] - [InlineData("le", Relation.LessThanOrEqual)] - [InlineData("lt", Relation.LessThan)] - [InlineData("ge", Relation.GreaterThanOrEqual)] - public void AsRelationTest(string? field, Relation expected) - { - Relation actual = field.AsRelation(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, Runnable.NULL)] - [InlineData("no", Runnable.No)] - [InlineData("partial", Runnable.Partial)] - [InlineData("yes", Runnable.Yes)] - public void AsRunnableTest(string? field, Runnable expected) - { - Runnable actual = field.AsRunnable(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, SoftwareListStatus.None)] - [InlineData("none", SoftwareListStatus.None)] - [InlineData("original", SoftwareListStatus.Original)] - [InlineData("compatible", SoftwareListStatus.Compatible)] - public void AsSoftwareListStatusTest(string? field, SoftwareListStatus expected) - { - SoftwareListStatus actual = field.AsSoftwareListStatus(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, Supported.NULL)] - [InlineData("no", Supported.No)] - [InlineData("unsupported", Supported.No)] - [InlineData("partial", Supported.Partial)] - [InlineData("yes", Supported.Yes)] - [InlineData("supported", Supported.Yes)] - public void AsSupportedTest(string? field, Supported expected) - { - Supported actual = field.AsSupported(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(null, SupportStatus.NULL)] - [InlineData("good", SupportStatus.Good)] - [InlineData("imperfect", SupportStatus.Imperfect)] - [InlineData("preliminary", SupportStatus.Preliminary)] - public void AsSupportStatusTest(string? field, SupportStatus expected) - { - SupportStatus actual = field.AsSupportStatus(); - Assert.Equal(expected, actual); - } - #endregion #region Enum to String - [Theory] - [InlineData(ChipType.NULL, null)] - [InlineData(ChipType.CPU, "cpu")] - [InlineData(ChipType.Audio, "audio")] - public void FromChipTypeTest(ChipType field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(ControlType.NULL, null)] - [InlineData(ControlType.Joy, "joy")] - [InlineData(ControlType.Stick, "stick")] - [InlineData(ControlType.Paddle, "paddle")] - [InlineData(ControlType.Pedal, "pedal")] - [InlineData(ControlType.Lightgun, "lightgun")] - [InlineData(ControlType.Positional, "positional")] - [InlineData(ControlType.Dial, "dial")] - [InlineData(ControlType.Trackball, "trackball")] - [InlineData(ControlType.Mouse, "mouse")] - [InlineData(ControlType.OnlyButtons, "only_buttons")] - [InlineData(ControlType.Keypad, "keypad")] - [InlineData(ControlType.Keyboard, "keyboard")] - [InlineData(ControlType.Mahjong, "mahjong")] - [InlineData(ControlType.Hanafuda, "hanafuda")] - [InlineData(ControlType.Gambling, "gambling")] - public void FromControlTypeTest(ControlType field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(DeviceType.NULL, null)] - [InlineData(DeviceType.Unknown, "unknown")] - [InlineData(DeviceType.Cartridge, "cartridge")] - [InlineData(DeviceType.FloppyDisk, "floppydisk")] - [InlineData(DeviceType.HardDisk, "harddisk")] - [InlineData(DeviceType.Cylinder, "cylinder")] - [InlineData(DeviceType.Cassette, "cassette")] - [InlineData(DeviceType.PunchCard, "punchcard")] - [InlineData(DeviceType.PunchTape, "punchtape")] - [InlineData(DeviceType.Printout, "printout")] - [InlineData(DeviceType.Serial, "serial")] - [InlineData(DeviceType.Parallel, "parallel")] - [InlineData(DeviceType.Snapshot, "snapshot")] - [InlineData(DeviceType.QuickLoad, "quickload")] - [InlineData(DeviceType.MemCard, "memcard")] - [InlineData(DeviceType.CDROM, "cdrom")] - [InlineData(DeviceType.MagTape, "magtape")] - [InlineData(DeviceType.ROMImage, "romimage")] - [InlineData(DeviceType.MIDIIn, "midiin")] - [InlineData(DeviceType.MIDIOut, "midiout")] - [InlineData(DeviceType.Picture, "picture")] - [InlineData(DeviceType.VidFile, "vidfile")] - public void FromDeviceTypeTest(DeviceType field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(DisplayType.NULL, null)] - [InlineData(DisplayType.Raster, "raster")] - [InlineData(DisplayType.Vector, "vector")] - [InlineData(DisplayType.LCD, "lcd")] - [InlineData(DisplayType.SVG, "svg")] - [InlineData(DisplayType.Unknown, "unknown")] - public void FromDisplayTypeTest(DisplayType field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(Endianness.NULL, null)] - [InlineData(Endianness.Big, "big")] - [InlineData(Endianness.Little, "little")] - public void FromEndiannessTest(Endianness field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(FeatureStatus.NULL, null)] - [InlineData(FeatureStatus.Unemulated, "unemulated")] - [InlineData(FeatureStatus.Imperfect, "imperfect")] - public void FromFeatureStatusTest(FeatureStatus field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(FeatureType.NULL, null)] - [InlineData(FeatureType.Protection, "protection")] - [InlineData(FeatureType.Palette, "palette")] - [InlineData(FeatureType.Graphics, "graphics")] - [InlineData(FeatureType.Sound, "sound")] - [InlineData(FeatureType.Controls, "controls")] - [InlineData(FeatureType.Keyboard, "keyboard")] - [InlineData(FeatureType.Mouse, "mouse")] - [InlineData(FeatureType.Microphone, "microphone")] - [InlineData(FeatureType.Camera, "camera")] - [InlineData(FeatureType.Disk, "disk")] - [InlineData(FeatureType.Printer, "printer")] - [InlineData(FeatureType.Lan, "lan")] - [InlineData(FeatureType.Wan, "wan")] - [InlineData(FeatureType.Timing, "timing")] - public void FromFeatureTypeTest(FeatureType field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(ItemStatus.NULL, null)] - [InlineData(ItemStatus.None, "none")] - [InlineData(ItemStatus.Good, "good")] - [InlineData(ItemStatus.BadDump, "baddump")] - [InlineData(ItemStatus.Nodump, "nodump")] - [InlineData(ItemStatus.Verified, "verified")] - public void FromItemStatusTest(ItemStatus field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - [Theory] [InlineData(ItemType.NULL, null)] [InlineData(ItemType.Adjuster, "adjuster")] @@ -491,100 +136,6 @@ namespace SabreTools.Metadata.DatItems.Test Assert.Equal(expected, actual); } - [Theory] - [InlineData(LoadFlag.NULL, null)] - [InlineData(LoadFlag.Load16Byte, "load16_byte")] - [InlineData(LoadFlag.Load16Word, "load16_word")] - [InlineData(LoadFlag.Load16WordSwap, "load16_word_swap")] - [InlineData(LoadFlag.Load32Byte, "load32_byte")] - [InlineData(LoadFlag.Load32Word, "load32_word")] - [InlineData(LoadFlag.Load32WordSwap, "load32_word_swap")] - [InlineData(LoadFlag.Load32DWord, "load32_dword")] - [InlineData(LoadFlag.Load64Word, "load64_word")] - [InlineData(LoadFlag.Load64WordSwap, "load64_word_swap")] - [InlineData(LoadFlag.Reload, "reload")] - [InlineData(LoadFlag.Fill, "fill")] - [InlineData(LoadFlag.Continue, "continue")] - [InlineData(LoadFlag.ReloadPlain, "reload_plain")] - [InlineData(LoadFlag.Ignore, "ignore")] - public void FromLoadFlagTest(LoadFlag field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(OpenMSXSubType.NULL, null)] - [InlineData(OpenMSXSubType.Rom, "rom")] - [InlineData(OpenMSXSubType.MegaRom, "megarom")] - [InlineData(OpenMSXSubType.SCCPlusCart, "sccpluscart")] - public void FromOpenMSXSubTypeTest(OpenMSXSubType field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(Relation.NULL, null)] - [InlineData(Relation.Equal, "eq")] - [InlineData(Relation.NotEqual, "ne")] - [InlineData(Relation.GreaterThan, "gt")] - [InlineData(Relation.LessThanOrEqual, "le")] - [InlineData(Relation.LessThan, "lt")] - [InlineData(Relation.GreaterThanOrEqual, "ge")] - public void FromRelationTest(Relation field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(Runnable.NULL, null)] - [InlineData(Runnable.No, "no")] - [InlineData(Runnable.Partial, "partial")] - [InlineData(Runnable.Yes, "yes")] - public void FromRunnableTest(Runnable field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(SoftwareListStatus.None, "none")] - [InlineData(SoftwareListStatus.Original, "original")] - [InlineData(SoftwareListStatus.Compatible, "compatible")] - public void FromSoftwareListStatusTest(SoftwareListStatus field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(Supported.NULL, true, null)] - [InlineData(Supported.NULL, false, null)] - [InlineData(Supported.No, true, "unsupported")] - [InlineData(Supported.No, false, "no")] - [InlineData(Supported.Partial, true, "partial")] - [InlineData(Supported.Partial, false, "partial")] - [InlineData(Supported.Yes, true, "supported")] - [InlineData(Supported.Yes, false, "yes")] - public void FromSupportedTest(Supported field, bool useSecond, string? expected) - { - string? actual = field.AsStringValue(useSecond); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(SupportStatus.NULL, null)] - [InlineData(SupportStatus.Good, "good")] - [InlineData(SupportStatus.Imperfect, "imperfect")] - [InlineData(SupportStatus.Preliminary, "preliminary")] - public void FromSupportStatusTest(SupportStatus field, string? expected) - { - string? actual = field.AsStringValue(); - Assert.Equal(expected, actual); - } - #endregion } } diff --git a/SabreTools.Metadata.DatItems/Enums.cs b/SabreTools.Metadata.DatItems/Enums.cs index 0d681d44..b0427e43 100644 --- a/SabreTools.Metadata.DatItems/Enums.cs +++ b/SabreTools.Metadata.DatItems/Enums.cs @@ -2,183 +2,6 @@ using System; namespace SabreTools.Metadata.DatItems { - /// - /// Determine the chip type - /// - [Flags] - public enum ChipType - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("cpu")] - CPU = 1 << 0, - - [Mapping("audio")] - Audio = 1 << 1, - } - - /// - /// Determine the control type - /// - [Flags] - public enum ControlType - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("joy")] - Joy = 1 << 0, - - [Mapping("stick")] - Stick = 1 << 1, - - [Mapping("paddle")] - Paddle = 1 << 2, - - [Mapping("pedal")] - Pedal = 1 << 3, - - [Mapping("lightgun")] - Lightgun = 1 << 4, - - [Mapping("positional")] - Positional = 1 << 5, - - [Mapping("dial")] - Dial = 1 << 6, - - [Mapping("trackball")] - Trackball = 1 << 7, - - [Mapping("mouse")] - Mouse = 1 << 8, - - [Mapping("only_buttons")] - OnlyButtons = 1 << 9, - - [Mapping("keypad")] - Keypad = 1 << 10, - - [Mapping("keyboard")] - Keyboard = 1 << 11, - - [Mapping("mahjong")] - Mahjong = 1 << 12, - - [Mapping("hanafuda")] - Hanafuda = 1 << 13, - - [Mapping("gambling")] - Gambling = 1 << 14, - } - - /// - /// Determine the device type - /// - [Flags] - public enum DeviceType - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("unknown")] - Unknown = 1 << 0, - - [Mapping("cartridge")] - Cartridge = 1 << 1, - - [Mapping("floppydisk")] - FloppyDisk = 1 << 2, - - [Mapping("harddisk")] - HardDisk = 1 << 3, - - [Mapping("cylinder")] - Cylinder = 1 << 4, - - [Mapping("cassette")] - Cassette = 1 << 5, - - [Mapping("punchcard")] - PunchCard = 1 << 6, - - [Mapping("punchtape")] - PunchTape = 1 << 7, - - [Mapping("printout")] - Printout = 1 << 8, - - [Mapping("serial")] - Serial = 1 << 9, - - [Mapping("parallel")] - Parallel = 1 << 10, - - [Mapping("snapshot")] - Snapshot = 1 << 11, - - [Mapping("quickload")] - QuickLoad = 1 << 12, - - [Mapping("memcard")] - MemCard = 1 << 13, - - [Mapping("cdrom")] - CDROM = 1 << 14, - - [Mapping("magtape")] - MagTape = 1 << 15, - - [Mapping("romimage")] - ROMImage = 1 << 16, - - [Mapping("midiin")] - MIDIIn = 1 << 17, - - [Mapping("midiout")] - MIDIOut = 1 << 18, - - [Mapping("picture")] - Picture = 1 << 19, - - [Mapping("vidfile")] - VidFile = 1 << 20, - } - - /// - /// Determine the display type - /// - [Flags] - public enum DisplayType - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("raster")] - Raster = 1 << 0, - - [Mapping("vector")] - Vector = 1 << 1, - - [Mapping("lcd")] - LCD = 1 << 2, - - [Mapping("svg")] - SVG = 1 << 3, - - [Mapping("unknown")] - Unknown = 1 << 4, - } - /// /// Determines which type of duplicate a file is /// @@ -194,96 +17,6 @@ namespace SabreTools.Metadata.DatItems External = 1 << 3, } - /// - /// Determine the endianness - /// - [Flags] - public enum Endianness - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("big")] - Big = 1 << 0, - - [Mapping("little")] - Little = 1 << 1, - } - - /// - /// Determine the emulation status - /// - [Flags] - public enum FeatureStatus - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("unemulated")] - Unemulated = 1 << 0, - - [Mapping("imperfect")] - Imperfect = 1 << 1, - } - - /// - /// Determine the feature type - /// - [Flags] - public enum FeatureType - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("protection")] - Protection = 1 << 0, - - [Mapping("palette")] - Palette = 1 << 1, - - [Mapping("graphics")] - Graphics = 1 << 2, - - [Mapping("sound")] - Sound = 1 << 3, - - [Mapping("controls")] - Controls = 1 << 4, - - [Mapping("keyboard")] - Keyboard = 1 << 5, - - [Mapping("mouse")] - Mouse = 1 << 6, - - [Mapping("microphone")] - Microphone = 1 << 7, - - [Mapping("camera")] - Camera = 1 << 8, - - [Mapping("disk")] - Disk = 1 << 9, - - [Mapping("printer")] - Printer = 1 << 10, - - [Mapping("lan")] - Lan = 1 << 11, - - [Mapping("wan")] - Wan = 1 << 12, - - [Mapping("timing")] - Timing = 1 << 13, - } - /// /// A subset of fields that can be used as keys /// @@ -308,33 +41,6 @@ namespace SabreTools.Metadata.DatItems SpamSum, } - /// - /// Determine the status of the item - /// - [Flags] - public enum ItemStatus - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("none", "no")] - None = 1 << 0, - - [Mapping("good")] - Good = 1 << 1, - - [Mapping("baddump")] - BadDump = 1 << 2, - - [Mapping("nodump", "yes")] - Nodump = 1 << 3, - - [Mapping("verified")] - Verified = 1 << 4, - } - /// /// Determine what type of file an item is /// @@ -347,341 +53,157 @@ namespace SabreTools.Metadata.DatItems // "Actionable" item types - [Mapping("rom")] + /// "rom" Rom, - [Mapping("disk")] + /// "disk" Disk, - [Mapping("file")] + /// "file" File, - [Mapping("media")] + /// "media" Media, // "Auxiliary" item types - [Mapping("adjuster")] + /// "adjuster" Adjuster, - [Mapping("analog")] + /// "analog" Analog, - [Mapping("archive")] + /// "archive" Archive, - [Mapping("biosset")] + /// "biosset" BiosSet, - [Mapping("chip")] + /// "chip" Chip, - [Mapping("condition")] + /// "condition" Condition, - [Mapping("configuration")] + /// "configuration" Configuration, - [Mapping("conflocation")] + /// "conflocation" ConfLocation, - [Mapping("confsetting")] + /// "confsetting" ConfSetting, - [Mapping("control")] + /// "control" Control, - [Mapping("dataarea")] + /// "dataarea" DataArea, - [Mapping("device")] + /// "device" Device, - [Mapping("device_ref", "deviceref")] + /// "device_ref", "deviceref" DeviceRef, - [Mapping("diplocation")] + /// "diplocation" DipLocation, - [Mapping("dipswitch")] + /// "dipswitch" DipSwitch, - [Mapping("dipvalue")] + /// "dipvalue" DipValue, - [Mapping("diskarea")] + /// "diskarea" DiskArea, - [Mapping("display")] + /// "display" Display, - [Mapping("driver")] + /// "driver" Driver, - [Mapping("extension")] + /// "extension" Extension, - [Mapping("feature")] + /// "feature" Feature, - [Mapping("info")] + /// "info" Info, - [Mapping("input")] + /// "input" Input, - [Mapping("instance")] + /// "instance" Instance, - [Mapping("original")] + /// "original" Original, - [Mapping("part")] + /// "part" Part, - [Mapping("part_feature", "partfeature")] + /// "part_feature", "partfeature" PartFeature, - [Mapping("port")] + /// "port" Port, - [Mapping("ramoption", "ram_option")] + /// "ramoption", "ram_option" RamOption, - [Mapping("release")] + /// "release" Release, - [Mapping("release_details", "releasedetails")] + /// "release_details", "releasedetails" ReleaseDetails, - [Mapping("sample")] + /// "sample" Sample, - [Mapping("serials")] + /// "serials" Serials, - [Mapping("sharedfeat", "shared_feat", "sharedfeature", "shared_feature")] + /// "sharedfeat", "shared_feat", "sharedfeature", "shared_feature" SharedFeat, - [Mapping("slot")] + /// "slot" Slot, - [Mapping("slotoption", "slot_option")] + /// "slotoption", "slot_option" SlotOption, - [Mapping("softwarelist", "software_list")] + /// "softwarelist", "software_list" SoftwareList, - [Mapping("sound")] + /// "sound" Sound, - [Mapping("source_details", "sourcedetails")] + /// "source_details", "sourcedetails" SourceDetails, - [Mapping("blank")] + /// "blank" Blank = 99, // This is not a real type, only used internally } - /// - /// Determine the loadflag value - /// - [Flags] - public enum LoadFlag - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("load16_byte")] - Load16Byte = 1 << 0, - - [Mapping("load16_word")] - Load16Word = 1 << 1, - - [Mapping("load16_word_swap")] - Load16WordSwap = 1 << 2, - - [Mapping("load32_byte")] - Load32Byte = 1 << 3, - - [Mapping("load32_word")] - Load32Word = 1 << 4, - - [Mapping("load32_word_swap")] - Load32WordSwap = 1 << 5, - - [Mapping("load32_dword")] - Load32DWord = 1 << 6, - - [Mapping("load64_word")] - Load64Word = 1 << 7, - - [Mapping("load64_word_swap")] - Load64WordSwap = 1 << 8, - - [Mapping("reload")] - Reload = 1 << 9, - - [Mapping("fill")] - Fill = 1 << 10, - - [Mapping("continue")] - Continue = 1 << 11, - - [Mapping("reload_plain")] - ReloadPlain = 1 << 12, - - [Mapping("ignore")] - Ignore = 1 << 13, - } - /// /// Determine what type of machine it is /// [Flags] public enum MachineType { - [Mapping("none")] + /// "none" None = 0, - [Mapping("bios")] + /// "bios" Bios = 1 << 0, - [Mapping("device", "dev")] + /// "device", "dev" Device = 1 << 1, - [Mapping("mechanical", "mech")] + /// "mechanical", "mech" Mechanical = 1 << 2, } - - /// - /// Determine which OpenMSX subtype an item is - /// - [Flags] - public enum OpenMSXSubType - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("rom")] - Rom = 1 << 0, - - [Mapping("megarom")] - MegaRom = 1 << 1, - - [Mapping("sccpluscart")] - SCCPlusCart = 1 << 2, - } - - /// - /// Determine relation of value to condition - /// - [Flags] - public enum Relation - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("eq")] - Equal = 1 << 0, - - [Mapping("ne")] - NotEqual = 1 << 1, - - [Mapping("gt")] - GreaterThan = 1 << 2, - - [Mapping("le")] - LessThanOrEqual = 1 << 3, - - [Mapping("lt")] - LessThan = 1 << 4, - - [Mapping("ge")] - GreaterThanOrEqual = 1 << 5, - } - - /// - /// Determine machine runnable status - /// - [Flags] - public enum Runnable - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("no")] - No = 1 << 0, - - [Mapping("partial")] - Partial = 1 << 1, - - [Mapping("yes")] - Yes = 1 << 2, - } - - /// - /// Determine software list status - /// - [Flags] - public enum SoftwareListStatus - { - [Mapping("none")] - None = 0, - - [Mapping("original")] - Original = 1 << 0, - - [Mapping("compatible")] - Compatible = 1 << 1, - } - - /// - /// Determine machine support status - /// - [Flags] - public enum Supported - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("no", "unsupported")] - No = 1 << 0, - - [Mapping("partial")] - Partial = 1 << 1, - - [Mapping("yes", "supported")] - Yes = 1 << 2, - } - - /// - /// Determine driver support statuses - /// - [Flags] - public enum SupportStatus - { - /// - /// This is a fake flag that is used for filter only - /// - NULL = 0, - - [Mapping("good")] - Good = 1 << 0, - - [Mapping("imperfect")] - Imperfect = 1 << 1, - - [Mapping("preliminary")] - Preliminary = 1 << 2, - } } diff --git a/SabreTools.Metadata.DatItems/Extensions.cs b/SabreTools.Metadata.DatItems/Extensions.cs index ba94939b..1f42603e 100644 --- a/SabreTools.Metadata.DatItems/Extensions.cs +++ b/SabreTools.Metadata.DatItems/Extensions.cs @@ -1,345 +1,9 @@ -using System.Collections.Generic; - namespace SabreTools.Metadata.DatItems { public static class Extensions { - #region Private Maps - - /// - /// Set of enum to string mappings for ChipType - /// - private static readonly Dictionary _toChipTypeMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for ChipType - /// - private static readonly Dictionary _fromChipTypeMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for ControlType - /// - private static readonly Dictionary _toControlTypeMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for ControlType - /// - private static readonly Dictionary _fromControlTypeMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for DeviceType - /// - private static readonly Dictionary _toDeviceTypeMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for DeviceType - /// - private static readonly Dictionary _fromDeviceTypeMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for DisplayType - /// - private static readonly Dictionary _toDisplayTypeMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for DisplayType - /// - private static readonly Dictionary _fromDisplayTypeMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for Endianness - /// - private static readonly Dictionary _toEndiannessMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for Endianness - /// - private static readonly Dictionary _fromEndiannessMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for FeatureStatus - /// - private static readonly Dictionary _toFeatureStatusMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for FeatureStatus - /// - private static readonly Dictionary _fromFeatureStatusMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for FeatureType - /// - private static readonly Dictionary _toFeatureTypeMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for FeatureType - /// - private static readonly Dictionary _fromFeatureTypeMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for ItemStatus - /// - private static readonly Dictionary _toItemStatusMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for ItemStatus - /// - private static readonly Dictionary _fromItemStatusMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for ItemType - /// - private static readonly Dictionary _toItemTypeMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for ItemType - /// - private static readonly Dictionary _fromItemTypeMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for LoadFlag - /// - private static readonly Dictionary _toLoadFlagMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for LoadFlag - /// - private static readonly Dictionary _fromLoadFlagMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for MachineType - /// - private static readonly Dictionary _toMachineTypeMap = Converters.GenerateToEnum(); - - /// - /// Set of enum to string mappings for OpenMSXSubType - /// - private static readonly Dictionary _toOpenMSXSubTypeMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for OpenMSXSubType - /// - private static readonly Dictionary _fromOpenMSXSubTypeMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for Relation - /// - private static readonly Dictionary _toRelationMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for Relation - /// - private static readonly Dictionary _fromRelationMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for Runnable - /// - private static readonly Dictionary _toRunnableMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for Runnable - /// - private static readonly Dictionary _fromRunnableMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for SoftwareListStatus - /// - private static readonly Dictionary _toSoftwareListStatusMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for SoftwareListStatus - /// - private static readonly Dictionary _fromSoftwareListStatusMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of enum to string mappings for Supported - /// - private static readonly Dictionary _toSupportedMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for Supported - /// - private static readonly Dictionary _fromSupportedMap = Converters.GenerateToString(useSecond: false); - - /// - /// Set of string to enum mappings for Supported (secondary) - /// - private static readonly Dictionary _fromSupportedSecondaryMap = Converters.GenerateToString(useSecond: true); - - /// - /// Set of enum to string mappings for SupportStatus - /// - private static readonly Dictionary _toSupportStatusMap = Converters.GenerateToEnum(); - - /// - /// Set of string to enum mappings for SupportStatus - /// - private static readonly Dictionary _fromSupportStatusMap = Converters.GenerateToString(useSecond: false); - - #endregion - #region String to Enum - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static ChipType AsChipType(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toChipTypeMap.ContainsKey(value)) - return _toChipTypeMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static ControlType AsControlType(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toControlTypeMap.ContainsKey(value)) - return _toControlTypeMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static DeviceType AsDeviceType(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toDeviceTypeMap.ContainsKey(value)) - return _toDeviceTypeMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static DisplayType AsDisplayType(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toDisplayTypeMap.ContainsKey(value)) - return _toDisplayTypeMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static Endianness AsEndianness(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toEndiannessMap.ContainsKey(value)) - return _toEndiannessMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static FeatureStatus AsFeatureStatus(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toFeatureStatusMap.ContainsKey(value)) - return _toFeatureStatusMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static FeatureType AsFeatureType(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toFeatureTypeMap.ContainsKey(value)) - return _toFeatureTypeMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static ItemStatus AsItemStatus(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toItemStatusMap.ContainsKey(value)) - return _toItemStatusMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - /// /// Get the enum value for an input string, if possible /// @@ -347,37 +11,57 @@ namespace SabreTools.Metadata.DatItems /// Enum value representing the input, default on error public static ItemType AsItemType(this string? value) { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; + return value?.ToLowerInvariant() switch + { + // "Actionable" item types + "rom" => ItemType.Rom, + "disk" => ItemType.Disk, + "file" => ItemType.File, + "media" => ItemType.Media, - // Try to get the value from the mappings - if (_toItemTypeMap.ContainsKey(value)) - return _toItemTypeMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static LoadFlag AsLoadFlag(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toLoadFlagMap.ContainsKey(value)) - return _toLoadFlagMap[value]; - - // Otherwise, return the default value for the enum - return default; + // "Auxiliary" item types + "adjuster" => ItemType.Adjuster, + "analog" => ItemType.Analog, + "archive" => ItemType.Archive, + "biosset" => ItemType.BiosSet, + "chip" => ItemType.Chip, + "condition" => ItemType.Condition, + "configuration" => ItemType.Configuration, + "conflocation" => ItemType.ConfLocation, + "confsetting" => ItemType.ConfSetting, + "control" => ItemType.Control, + "dataarea" => ItemType.DataArea, + "device" => ItemType.Device, + "device_ref" or "deviceref" => ItemType.DeviceRef, + "diplocation" => ItemType.DipLocation, + "dipswitch" => ItemType.DipSwitch, + "dipvalue" => ItemType.DipValue, + "diskarea" => ItemType.DiskArea, + "display" => ItemType.Display, + "driver" => ItemType.Driver, + "extension" => ItemType.Extension, + "feature" => ItemType.Feature, + "info" => ItemType.Info, + "input" => ItemType.Input, + "instance" => ItemType.Instance, + "original" => ItemType.Original, + "part" => ItemType.Part, + "part_feature" or "partfeature" => ItemType.PartFeature, + "port" => ItemType.Port, + "ramoption" or "ram_option" => ItemType.RamOption, + "release" => ItemType.Release, + "release_details" or "releasedetails" => ItemType.ReleaseDetails, + "sample" => ItemType.Sample, + "serials" => ItemType.Serials, + "sharedfeat" or "shared_feat" or "sharedfeature" or "shared_feature" => ItemType.SharedFeat, + "slot" => ItemType.Slot, + "slotoption" or "slot_option" => ItemType.SlotOption, + "softwarelist" or "software_list" => ItemType.SoftwareList, + "sound" => ItemType.Sound, + "source_details" or "sourcedetails" => ItemType.SourceDetails, + "blank" => ItemType.Blank, + _ => ItemType.NULL, + }; } /// @@ -387,137 +71,14 @@ namespace SabreTools.Metadata.DatItems /// Enum value representing the input, default on error public static MachineType AsMachineType(this string? value) { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toMachineTypeMap.ContainsKey(value)) - return _toMachineTypeMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static OpenMSXSubType AsOpenMSXSubType(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toOpenMSXSubTypeMap.ContainsKey(value)) - return _toOpenMSXSubTypeMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static Relation AsRelation(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toRelationMap.ContainsKey(value)) - return _toRelationMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static Runnable AsRunnable(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toRunnableMap.ContainsKey(value)) - return _toRunnableMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static SoftwareListStatus AsSoftwareListStatus(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toSoftwareListStatusMap.ContainsKey(value)) - return _toSoftwareListStatusMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static Supported AsSupported(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toSupportedMap.ContainsKey(value)) - return _toSupportedMap[value]; - - // Otherwise, return the default value for the enum - return default; - } - - /// - /// Get the enum value for an input string, if possible - /// - /// String value to parse/param> - /// Enum value representing the input, default on error - public static SupportStatus AsSupportStatus(this string? value) - { - // Normalize the input value - value = value?.ToLowerInvariant(); - if (value is null) - return default; - - // Try to get the value from the mappings - if (_toSupportStatusMap.ContainsKey(value)) - return _toSupportStatusMap[value]; - - // Otherwise, return the default value for the enum - return default; + return value?.ToLowerInvariant() switch + { + "none" => MachineType.None, + "bios" => MachineType.Bios, + "device" or "dev" => MachineType.Device, + "mechanical" or "mech" => MachineType.Mechanical, + _ => MachineType.None, + }; } #endregion @@ -528,258 +89,63 @@ namespace SabreTools.Metadata.DatItems /// Get the string value for an input enum, if possible /// /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this ChipType value) - { - // Try to get the value from the mappings - if (_fromChipTypeMap.ContainsKey(value)) - return _fromChipTypeMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this ControlType value) - { - // Try to get the value from the mappings - if (_fromControlTypeMap.ContainsKey(value)) - return _fromControlTypeMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this DeviceType value) - { - // Try to get the value from the mappings - if (_fromDeviceTypeMap.ContainsKey(value)) - return _fromDeviceTypeMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this DisplayType value) - { - // Try to get the value from the mappings - if (_fromDisplayTypeMap.ContainsKey(value)) - return _fromDisplayTypeMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this Endianness value) - { - // Try to get the value from the mappings - if (_fromEndiannessMap.ContainsKey(value)) - return _fromEndiannessMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this FeatureStatus value) - { - // Try to get the value from the mappings - if (_fromFeatureStatusMap.ContainsKey(value)) - return _fromFeatureStatusMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this FeatureType value) - { - // Try to get the value from the mappings - if (_fromFeatureTypeMap.ContainsKey(value)) - return _fromFeatureTypeMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this ItemStatus value) - { - // Try to get the value from the mappings - if (_fromItemStatusMap.ContainsKey(value)) - return _fromItemStatusMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists /// String value representing the input, default on error public static string? AsStringValue(this ItemType value) { - // Try to get the value from the mappings - if (_fromItemTypeMap.ContainsKey(value)) - return _fromItemTypeMap[value]; + return value switch + { + // "Actionable" item types + ItemType.Rom => "rom", + ItemType.Disk => "disk", + ItemType.File => "file", + ItemType.Media => "media", - // Otherwise, return null - return null; - } + // "Auxiliary" item types - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this LoadFlag value) - { - // Try to get the value from the mappings - if (_fromLoadFlagMap.ContainsKey(value)) - return _fromLoadFlagMap[value]; + ItemType.Adjuster => "adjuster", + ItemType.Analog => "analog", + ItemType.Archive => "archive", + ItemType.BiosSet => "biosset", + ItemType.Chip => "chip", + ItemType.Condition => "condition", + ItemType.Configuration => "configuration", + ItemType.ConfLocation => "conflocation", + ItemType.ConfSetting => "confsetting", + ItemType.Control => "control", + ItemType.DataArea => "dataarea", + ItemType.Device => "device", + ItemType.DeviceRef => "device_ref", + ItemType.DipLocation => "diplocation", + ItemType.DipSwitch => "dipswitch", + ItemType.DipValue => "dipvalue", + ItemType.DiskArea => "diskarea", + ItemType.Display => "display", + ItemType.Driver => "driver", + ItemType.Extension => "extension", + ItemType.Feature => "feature", + ItemType.Info => "info", + ItemType.Input => "input", + ItemType.Instance => "instance", + ItemType.Original => "original", + ItemType.Part => "part", + ItemType.PartFeature => "part_feature", + ItemType.Port => "port", + ItemType.RamOption => "ramoption", + ItemType.Release => "release", + ItemType.ReleaseDetails => "release_details", + ItemType.Sample => "sample", + ItemType.Serials => "serials", + ItemType.SharedFeat => "sharedfeat", + ItemType.Slot => "slot", + ItemType.SlotOption => "slotoption", + ItemType.SoftwareList => "softwarelist", + ItemType.Sound => "sound", + ItemType.SourceDetails => "source_details", + ItemType.Blank => "blank", - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this OpenMSXSubType value) - { - // Try to get the value from the mappings - if (_fromOpenMSXSubTypeMap.ContainsKey(value)) - return _fromOpenMSXSubTypeMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this Relation value) - { - // Try to get the value from the mappings - if (_fromRelationMap.ContainsKey(value)) - return _fromRelationMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this Runnable value) - { - // Try to get the value from the mappings - if (_fromRunnableMap.ContainsKey(value)) - return _fromRunnableMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this SoftwareListStatus value) - { - // Try to get the value from the mappings - if (_fromSoftwareListStatusMap.ContainsKey(value)) - return _fromSoftwareListStatusMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this Supported value, bool useSecond = false) - { - // Try to get the value from the mappings - if (!useSecond && _fromSupportedMap.ContainsKey(value)) - return _fromSupportedMap[value]; - else if (useSecond && _fromSupportedSecondaryMap.ContainsKey(value)) - return _fromSupportedSecondaryMap[value]; - - // Otherwise, return null - return null; - } - - /// - /// Get the string value for an input enum, if possible - /// - /// Enum value to parse/param> - /// True to use the second mapping option, if it exists - /// String value representing the input, default on error - public static string? AsStringValue(this SupportStatus value) - { - // Try to get the value from the mappings - if (_fromSupportStatusMap.ContainsKey(value)) - return _fromSupportStatusMap[value]; - - // Otherwise, return null - return null; + ItemType.NULL => null, + _ => null, + }; } #endregion diff --git a/SabreTools.Metadata.DatItems/Formats/Chip.cs b/SabreTools.Metadata.DatItems/Formats/Chip.cs index cf18885b..5fcddf7f 100644 --- a/SabreTools.Metadata.DatItems/Formats/Chip.cs +++ b/SabreTools.Metadata.DatItems/Formats/Chip.cs @@ -1,5 +1,6 @@ -using System.Xml.Serialization; +using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; namespace SabreTools.Metadata.DatItems.Formats { @@ -29,7 +30,7 @@ namespace SabreTools.Metadata.DatItems.Formats string? chipType = ReadString(Data.Models.Metadata.Chip.ChipTypeKey); if (chipType is not null) - Write(Data.Models.Metadata.Chip.ChipTypeKey, chipType.AsChipType().AsStringValue()); + Write(Data.Models.Metadata.Chip.ChipTypeKey, chipType.AsChipType()?.AsStringValue()); } public Chip(Data.Models.Metadata.Chip item, Machine machine, Source source) : this(item) diff --git a/SabreTools.Metadata.DatItems/Formats/Condition.cs b/SabreTools.Metadata.DatItems/Formats/Condition.cs index 6d76d0f4..81c93c97 100644 --- a/SabreTools.Metadata.DatItems/Formats/Condition.cs +++ b/SabreTools.Metadata.DatItems/Formats/Condition.cs @@ -1,5 +1,6 @@ using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; namespace SabreTools.Metadata.DatItems.Formats { @@ -25,7 +26,7 @@ namespace SabreTools.Metadata.DatItems.Formats // Process flag values string? condition = ReadString(Data.Models.Metadata.Condition.RelationKey); if (condition is not null) - Write(Data.Models.Metadata.Condition.RelationKey, condition.AsRelation().AsStringValue()); + Write(Data.Models.Metadata.Condition.RelationKey, condition.AsRelation()?.AsStringValue()); } public Condition(Data.Models.Metadata.Condition item, Machine machine, Source source) : this(item) diff --git a/SabreTools.Metadata.DatItems/Formats/Control.cs b/SabreTools.Metadata.DatItems/Formats/Control.cs index fd72bf7b..bdc8adce 100644 --- a/SabreTools.Metadata.DatItems/Formats/Control.cs +++ b/SabreTools.Metadata.DatItems/Formats/Control.cs @@ -1,5 +1,6 @@ using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; namespace SabreTools.Metadata.DatItems.Formats { @@ -57,7 +58,7 @@ namespace SabreTools.Metadata.DatItems.Formats string? controlType = ReadString(Data.Models.Metadata.Control.ControlTypeKey); if (controlType is not null) - Write(Data.Models.Metadata.Control.ControlTypeKey, controlType.AsControlType().AsStringValue()); + Write(Data.Models.Metadata.Control.ControlTypeKey, controlType.AsControlType()?.AsStringValue()); } public Control(Data.Models.Metadata.Control item, Machine machine, Source source) : this(item) diff --git a/SabreTools.Metadata.DatItems/Formats/DataArea.cs b/SabreTools.Metadata.DatItems/Formats/DataArea.cs index 97e3f167..32a6d55e 100644 --- a/SabreTools.Metadata.DatItems/Formats/DataArea.cs +++ b/SabreTools.Metadata.DatItems/Formats/DataArea.cs @@ -1,5 +1,6 @@ using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; namespace SabreTools.Metadata.DatItems.Formats { @@ -26,7 +27,7 @@ namespace SabreTools.Metadata.DatItems.Formats // Process flag values string? endianness = ReadString(Data.Models.Metadata.DataArea.EndiannessKey); if (endianness is not null) - Write(Data.Models.Metadata.DataArea.EndiannessKey, endianness.AsEndianness().AsStringValue()); + Write(Data.Models.Metadata.DataArea.EndiannessKey, endianness.AsEndianness()?.AsStringValue()); long? size = ReadLong(Data.Models.Metadata.DataArea.SizeKey); if (size is not null) diff --git a/SabreTools.Metadata.DatItems/Formats/Device.cs b/SabreTools.Metadata.DatItems/Formats/Device.cs index a88dbcf6..64884aea 100644 --- a/SabreTools.Metadata.DatItems/Formats/Device.cs +++ b/SabreTools.Metadata.DatItems/Formats/Device.cs @@ -1,6 +1,7 @@ using System; using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; namespace SabreTools.Metadata.DatItems.Formats { @@ -50,7 +51,7 @@ namespace SabreTools.Metadata.DatItems.Formats string? deviceType = ReadString(Data.Models.Metadata.Device.DeviceTypeKey); if (deviceType is not null) - Write(Data.Models.Metadata.Device.DeviceTypeKey, deviceType.AsDeviceType().AsStringValue()); + Write(Data.Models.Metadata.Device.DeviceTypeKey, deviceType.AsDeviceType()?.AsStringValue()); // Handle subitems var instance = item.Read(Data.Models.Metadata.Device.InstanceKey); diff --git a/SabreTools.Metadata.DatItems/Formats/Disk.cs b/SabreTools.Metadata.DatItems/Formats/Disk.cs index 2b44c186..44f4400a 100644 --- a/SabreTools.Metadata.DatItems/Formats/Disk.cs +++ b/SabreTools.Metadata.DatItems/Formats/Disk.cs @@ -1,6 +1,7 @@ using System.Xml.Serialization; using Newtonsoft.Json; using SabreTools.Data.Extensions; +using SabreTools.Data.Models.Metadata; using SabreTools.Text.Extensions; namespace SabreTools.Metadata.DatItems.Formats @@ -73,7 +74,7 @@ namespace SabreTools.Metadata.DatItems.Formats string? status = ReadString(Data.Models.Metadata.Disk.StatusKey); if (status is not null) - Write(Data.Models.Metadata.Disk.StatusKey, status.AsItemStatus().AsStringValue()); + Write(Data.Models.Metadata.Disk.StatusKey, status.AsItemStatus()?.AsStringValue()); bool? writable = ReadBool(Data.Models.Metadata.Disk.WritableKey); if (writable is not null) diff --git a/SabreTools.Metadata.DatItems/Formats/Display.cs b/SabreTools.Metadata.DatItems/Formats/Display.cs index d4197c40..df36e334 100644 --- a/SabreTools.Metadata.DatItems/Formats/Display.cs +++ b/SabreTools.Metadata.DatItems/Formats/Display.cs @@ -1,5 +1,6 @@ using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; using SabreTools.Text.Extensions; namespace SabreTools.Metadata.DatItems.Formats @@ -58,7 +59,7 @@ namespace SabreTools.Metadata.DatItems.Formats string? displayType = ReadString(Data.Models.Metadata.Display.DisplayTypeKey); if (displayType is not null) - Write(Data.Models.Metadata.Display.DisplayTypeKey, displayType.AsDisplayType().AsStringValue()); + Write(Data.Models.Metadata.Display.DisplayTypeKey, displayType.AsDisplayType()?.AsStringValue()); long? vbEnd = ReadLong(Data.Models.Metadata.Display.VBEndKey); if (vbEnd is not null) @@ -88,7 +89,7 @@ namespace SabreTools.Metadata.DatItems.Formats // TODO: Convert this block to more traditional set of if/then Write(Data.Models.Metadata.Video.AspectXKey, NumberHelper.ConvertToInt64(item.ReadString(Data.Models.Metadata.Video.AspectXKey))); Write(Data.Models.Metadata.Video.AspectYKey, NumberHelper.ConvertToInt64(item.ReadString(Data.Models.Metadata.Video.AspectYKey))); - Write(Data.Models.Metadata.Display.DisplayTypeKey, item.ReadString(Data.Models.Metadata.Video.ScreenKey).AsDisplayType().AsStringValue()); + Write(Data.Models.Metadata.Display.DisplayTypeKey, item.ReadString(Data.Models.Metadata.Video.ScreenKey).AsDisplayType()?.AsStringValue()); Write(Data.Models.Metadata.Display.HeightKey, NumberHelper.ConvertToInt64(item.ReadString(Data.Models.Metadata.Video.HeightKey))); Write(Data.Models.Metadata.Display.RefreshKey, NumberHelper.ConvertToDouble(item.ReadString(Data.Models.Metadata.Video.RefreshKey))); Write(Data.Models.Metadata.Display.WidthKey, NumberHelper.ConvertToInt64(item.ReadString(Data.Models.Metadata.Video.WidthKey))); @@ -125,7 +126,7 @@ namespace SabreTools.Metadata.DatItems.Formats string? screen = ReadString(Data.Models.Metadata.Video.ScreenKey); if (screen is not null) - Write(Data.Models.Metadata.Display.DisplayTypeKey, screen.AsDisplayType().AsStringValue()); + Write(Data.Models.Metadata.Display.DisplayTypeKey, screen.AsDisplayType()?.AsStringValue()); long? width = ReadLong(Data.Models.Metadata.Video.WidthKey); if (width is not null) diff --git a/SabreTools.Metadata.DatItems/Formats/Driver.cs b/SabreTools.Metadata.DatItems/Formats/Driver.cs index 369f9071..fb4695fe 100644 --- a/SabreTools.Metadata.DatItems/Formats/Driver.cs +++ b/SabreTools.Metadata.DatItems/Formats/Driver.cs @@ -1,5 +1,6 @@ using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; namespace SabreTools.Metadata.DatItems.Formats { @@ -25,15 +26,15 @@ namespace SabreTools.Metadata.DatItems.Formats // Process flag values string? cocktail = ReadString(Data.Models.Metadata.Driver.CocktailKey); if (cocktail is not null) - Write(Data.Models.Metadata.Driver.CocktailKey, cocktail.AsSupportStatus().AsStringValue()); + Write(Data.Models.Metadata.Driver.CocktailKey, cocktail.AsSupportStatus()?.AsStringValue()); string? color = ReadString(Data.Models.Metadata.Driver.ColorKey); if (color is not null) - Write(Data.Models.Metadata.Driver.ColorKey, color.AsSupportStatus().AsStringValue()); + Write(Data.Models.Metadata.Driver.ColorKey, color.AsSupportStatus()?.AsStringValue()); string? emulation = ReadString(Data.Models.Metadata.Driver.EmulationKey); if (emulation is not null) - Write(Data.Models.Metadata.Driver.EmulationKey, emulation.AsSupportStatus().AsStringValue()); + Write(Data.Models.Metadata.Driver.EmulationKey, emulation.AsSupportStatus()?.AsStringValue()); bool? incomplete = ReadBool(Data.Models.Metadata.Driver.IncompleteKey); if (incomplete is not null) @@ -53,15 +54,15 @@ namespace SabreTools.Metadata.DatItems.Formats string? saveState = ReadString(Data.Models.Metadata.Driver.SaveStateKey); if (saveState is not null) - Write(Data.Models.Metadata.Driver.SaveStateKey, saveState.AsSupported().AsStringValue(useSecond: true)); + Write(Data.Models.Metadata.Driver.SaveStateKey, saveState.AsSupported()?.AsStringValue(useSecond: true)); string? sound = ReadString(Data.Models.Metadata.Driver.SoundKey); if (sound is not null) - Write(Data.Models.Metadata.Driver.SoundKey, sound.AsSupportStatus().AsStringValue()); + Write(Data.Models.Metadata.Driver.SoundKey, sound.AsSupportStatus()?.AsStringValue()); string? status = ReadString(Data.Models.Metadata.Driver.StatusKey); if (status is not null) - Write(Data.Models.Metadata.Driver.StatusKey, status.AsSupportStatus().AsStringValue()); + Write(Data.Models.Metadata.Driver.StatusKey, status.AsSupportStatus()?.AsStringValue()); bool? unofficial = ReadBool(Data.Models.Metadata.Driver.UnofficialKey); if (unofficial is not null) diff --git a/SabreTools.Metadata.DatItems/Formats/Feature.cs b/SabreTools.Metadata.DatItems/Formats/Feature.cs index 9c9692d9..5ca812ee 100644 --- a/SabreTools.Metadata.DatItems/Formats/Feature.cs +++ b/SabreTools.Metadata.DatItems/Formats/Feature.cs @@ -1,5 +1,6 @@ using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; namespace SabreTools.Metadata.DatItems.Formats { @@ -25,15 +26,15 @@ namespace SabreTools.Metadata.DatItems.Formats // Process flag values string? overall = ReadString(Data.Models.Metadata.Feature.OverallKey); if (overall is not null) - Write(Data.Models.Metadata.Feature.OverallKey, overall.AsFeatureStatus().AsStringValue()); + Write(Data.Models.Metadata.Feature.OverallKey, overall.AsFeatureStatus()?.AsStringValue()); string? status = ReadString(Data.Models.Metadata.Feature.StatusKey); if (status is not null) - Write(Data.Models.Metadata.Feature.StatusKey, status.AsFeatureStatus().AsStringValue()); + Write(Data.Models.Metadata.Feature.StatusKey, status.AsFeatureStatus()?.AsStringValue()); string? featureType = ReadString(Data.Models.Metadata.Feature.FeatureTypeKey); if (featureType is not null) - Write(Data.Models.Metadata.Feature.FeatureTypeKey, featureType.AsFeatureType().AsStringValue()); + Write(Data.Models.Metadata.Feature.FeatureTypeKey, featureType.AsFeatureType()?.AsStringValue()); } public Feature(Data.Models.Metadata.Feature item, Machine machine, Source source) : this(item) diff --git a/SabreTools.Metadata.DatItems/Formats/PartFeature.cs b/SabreTools.Metadata.DatItems/Formats/PartFeature.cs index 9d9b2555..945f2f7c 100644 --- a/SabreTools.Metadata.DatItems/Formats/PartFeature.cs +++ b/SabreTools.Metadata.DatItems/Formats/PartFeature.cs @@ -1,5 +1,6 @@ using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; namespace SabreTools.Metadata.DatItems.Formats { @@ -34,15 +35,15 @@ namespace SabreTools.Metadata.DatItems.Formats // Process flag values string? overall = ReadString(Data.Models.Metadata.Feature.OverallKey); if (overall is not null) - Write(Data.Models.Metadata.Feature.OverallKey, overall.AsFeatureStatus().AsStringValue()); + Write(Data.Models.Metadata.Feature.OverallKey, overall.AsFeatureStatus()?.AsStringValue()); string? status = ReadString(Data.Models.Metadata.Feature.StatusKey); if (status is not null) - Write(Data.Models.Metadata.Feature.StatusKey, status.AsFeatureStatus().AsStringValue()); + Write(Data.Models.Metadata.Feature.StatusKey, status.AsFeatureStatus()?.AsStringValue()); string? featureType = ReadString(Data.Models.Metadata.Feature.FeatureTypeKey); if (featureType is not null) - Write(Data.Models.Metadata.Feature.FeatureTypeKey, featureType.AsFeatureType().AsStringValue()); + Write(Data.Models.Metadata.Feature.FeatureTypeKey, featureType.AsFeatureType()?.AsStringValue()); } public PartFeature(Data.Models.Metadata.Feature item, Machine machine, Source source) : this(item) diff --git a/SabreTools.Metadata.DatItems/Formats/Rom.cs b/SabreTools.Metadata.DatItems/Formats/Rom.cs index 8eda87ab..246b0657 100644 --- a/SabreTools.Metadata.DatItems/Formats/Rom.cs +++ b/SabreTools.Metadata.DatItems/Formats/Rom.cs @@ -1,6 +1,7 @@ using System.Xml.Serialization; using Newtonsoft.Json; using SabreTools.Data.Extensions; +using SabreTools.Data.Models.Metadata; using SabreTools.Text.Extensions; namespace SabreTools.Metadata.DatItems.Formats @@ -36,7 +37,7 @@ namespace SabreTools.Metadata.DatItems.Formats get { var status = ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus(); - return status != ItemStatus.NULL && status != ItemStatus.None; + return status is not null && status != ItemStatus.None; } } @@ -60,7 +61,7 @@ namespace SabreTools.Metadata.DatItems.Formats && (!string.IsNullOrEmpty(dataArea.GetName()) || dataArea.ReadLong(Data.Models.Metadata.DataArea.SizeKey) is not null || dataArea.ReadLong(Data.Models.Metadata.DataArea.WidthKey) is not null - || dataArea.ReadString(Data.Models.Metadata.DataArea.EndiannessKey).AsEndianness() != Endianness.NULL); + || dataArea.ReadString(Data.Models.Metadata.DataArea.EndiannessKey).AsEndianness() is not null); } } @@ -86,25 +87,25 @@ namespace SabreTools.Metadata.DatItems.Formats Write(Data.Models.Metadata.Rom.StatusKey, ItemStatus.None.AsStringValue()); } - public Rom(Data.Models.Metadata.Dump item, Machine machine, Source source, int index) + public Rom(Dump item, Machine machine, Source source, int index) { // If we don't have rom data, we can't do anything Data.Models.Metadata.Rom? rom = null; - OpenMSXSubType subType = OpenMSXSubType.NULL; + OpenMSXSubType? subType = null; - if (item.Read(Data.Models.Metadata.Dump.RomKey) is not null) + if (item.Read(Dump.RomKey) is not null) { - rom = item.Read(Data.Models.Metadata.Dump.RomKey); + rom = item.Read(Dump.RomKey); subType = OpenMSXSubType.Rom; } - else if (item.Read(Data.Models.Metadata.Dump.MegaRomKey) is not null) + else if (item.Read(Dump.MegaRomKey) is not null) { - rom = item.Read(Data.Models.Metadata.Dump.MegaRomKey); + rom = item.Read(Dump.MegaRomKey); subType = OpenMSXSubType.MegaRom; } - else if (item.Read(Data.Models.Metadata.Dump.SCCPlusCartKey) is not null) + else if (item.Read(Dump.SCCPlusCartKey) is not null) { - rom = item.Read(Data.Models.Metadata.Dump.SCCPlusCartKey); + rom = item.Read(Dump.SCCPlusCartKey); subType = OpenMSXSubType.SCCPlusCart; } @@ -116,14 +117,14 @@ namespace SabreTools.Metadata.DatItems.Formats SetName(name); Write(Data.Models.Metadata.Rom.OffsetKey, rom.ReadString(Data.Models.Metadata.Rom.StartKey)); - Write(Data.Models.Metadata.Rom.OpenMSXMediaType, subType.AsStringValue()); + Write(Data.Models.Metadata.Rom.OpenMSXMediaType, subType?.AsStringValue()); Write(Data.Models.Metadata.Rom.OpenMSXType, rom.ReadString(Data.Models.Metadata.Rom.OpenMSXType) ?? rom.ReadString(Data.Models.Metadata.DatItem.TypeKey)); Write(Data.Models.Metadata.Rom.RemarkKey, rom.ReadString(Data.Models.Metadata.Rom.RemarkKey)); Write(Data.Models.Metadata.Rom.SHA1Key, rom.ReadString(Data.Models.Metadata.Rom.SHA1Key)); Write(Data.Models.Metadata.Rom.StartKey, rom.ReadString(Data.Models.Metadata.Rom.StartKey)); Write(SourceKey, source); - var original = item.Read(Data.Models.Metadata.Dump.OriginalKey); + var original = item.Read(Dump.OriginalKey); if (original is not null) { Write("ORIGINAL", new Original @@ -206,11 +207,11 @@ namespace SabreTools.Metadata.DatItems.Formats string? loadFlag = ReadString(Data.Models.Metadata.Rom.LoadFlagKey); if (loadFlag is not null) - Write(Data.Models.Metadata.Rom.LoadFlagKey, loadFlag.AsLoadFlag().AsStringValue()); + Write(Data.Models.Metadata.Rom.LoadFlagKey, loadFlag.AsLoadFlag()?.AsStringValue()); string? openMSXMediaType = ReadString(Data.Models.Metadata.Rom.OpenMSXMediaType); if (openMSXMediaType is not null) - Write(Data.Models.Metadata.Rom.OpenMSXMediaType, openMSXMediaType.AsOpenMSXSubType().AsStringValue()); + Write(Data.Models.Metadata.Rom.OpenMSXMediaType, openMSXMediaType.AsOpenMSXSubType()?.AsStringValue()); bool? mia = ReadBool(Data.Models.Metadata.Rom.MIAKey); if (mia is not null) @@ -226,7 +227,7 @@ namespace SabreTools.Metadata.DatItems.Formats string? status = ReadString(Data.Models.Metadata.Rom.StatusKey); if (status is not null) - Write(Data.Models.Metadata.Rom.StatusKey, status.AsItemStatus().AsStringValue()); + Write(Data.Models.Metadata.Rom.StatusKey, status.AsItemStatus()?.AsStringValue()); // Process hash values long? size = ReadLong(Data.Models.Metadata.Rom.SizeKey); diff --git a/SabreTools.Metadata.DatItems/Formats/SoftwareList.cs b/SabreTools.Metadata.DatItems/Formats/SoftwareList.cs index 85f08e1a..e9d67a9e 100644 --- a/SabreTools.Metadata.DatItems/Formats/SoftwareList.cs +++ b/SabreTools.Metadata.DatItems/Formats/SoftwareList.cs @@ -1,5 +1,6 @@ using System.Xml.Serialization; using Newtonsoft.Json; +using SabreTools.Data.Extensions; namespace SabreTools.Metadata.DatItems.Formats { @@ -25,7 +26,7 @@ namespace SabreTools.Metadata.DatItems.Formats // Process flag values string? status = ReadString(Data.Models.Metadata.SoftwareList.StatusKey); if (status is not null) - Write(Data.Models.Metadata.SoftwareList.StatusKey, status.AsSoftwareListStatus().AsStringValue()); + Write(Data.Models.Metadata.SoftwareList.StatusKey, status.AsSoftwareListStatus()?.AsStringValue()); // Handle subitems // TODO: Handle the Software subitem diff --git a/SabreTools.Metadata.DatItems/Machine.cs b/SabreTools.Metadata.DatItems/Machine.cs index a2481f53..9d03288d 100644 --- a/SabreTools.Metadata.DatItems/Machine.cs +++ b/SabreTools.Metadata.DatItems/Machine.cs @@ -58,7 +58,7 @@ namespace SabreTools.Metadata.DatItems string? supported = ReadString(Data.Models.Metadata.Machine.SupportedKey); if (supported is not null) - Write(Data.Models.Metadata.Machine.SupportedKey, supported.AsSupported().AsStringValue()); + Write(Data.Models.Metadata.Machine.SupportedKey, supported.AsSupported()?.AsStringValue()); // Handle Trurip object, if it exists var truripItem = machine.Read(Data.Models.Metadata.Machine.TruripKey); diff --git a/SabreTools.Metadata/Converters.cs b/SabreTools.Metadata/Converters.cs index 3a65d59c..1286b3be 100644 --- a/SabreTools.Metadata/Converters.cs +++ b/SabreTools.Metadata/Converters.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; - -namespace SabreTools.Metadata +namespace SabreTools.Metadata { public static class Converters { @@ -22,49 +19,6 @@ namespace SabreTools.Metadata }; } - /// - /// Get a set of mappings from strings to enum values - /// - /// Enum type that is expected - /// Dictionary of string to enum values - public static Dictionary GenerateToEnum() - { - try - { - // Get all of the values for the enum type - var values = Enum.GetValues(typeof(T)); - - // Build the output dictionary - Dictionary mappings = []; - foreach (T? value in values) - { - // If the value is null - if (value is null) - continue; - - // Try to get the mapping attribute - MappingAttribute? attr = GetMappingAttribute(value); - if (attr?.Mappings is null || attr.Mappings.Length == 0) - continue; - - // Loop through the mappings and add each - foreach (string mapString in attr.Mappings) - { - if (mapString is not null) - mappings[mapString] = value; - } - } - - // Return the output dictionary - return mappings; - } - catch - { - // This should not happen, only if the type was not an enum - return []; - } - } - #endregion #region Enum to String @@ -84,93 +38,6 @@ namespace SabreTools.Metadata }; } - /// - /// Get a set of mappings from enum values to string - /// - /// True to use the second mapping option, if it exists - /// Enum type that is expected - /// Dictionary of enum to string values - public static Dictionary GenerateToString(bool useSecond) where T : notnull - { - try - { - // Get all of the values for the enum type - var values = Enum.GetValues(typeof(T)); - - // Build the output dictionary - Dictionary mappings = []; - foreach (T? value in values) - { - // If the value is null - if (value is null) - continue; - - // Try to get the mapping attribute - MappingAttribute? attr = GetMappingAttribute(value); - if (attr?.Mappings is null || attr.Mappings.Length == 0) - continue; - - // Use either the first or second item in the list - if (attr.Mappings.Length > 1 && useSecond) - mappings[value] = attr.Mappings[1]; - else - mappings[value] = attr.Mappings[0]; - } - - // Return the output dictionary - return mappings; - } - catch - { - // This should not happen, only if the type was not an enum - return []; - } - } - - #endregion - - #region Helpers - - /// - /// Get the MappingAttribute from a supported value - /// - /// Value to use - /// MappingAttribute attached to the value - internal static MappingAttribute? GetMappingAttribute(T? value) - { - // Null value in, null value out - if (value is null) - return null; - - // Current enumeration type - var enumType = typeof(T); - if (Nullable.GetUnderlyingType(enumType) is not null) - enumType = Nullable.GetUnderlyingType(enumType); - - // If the value returns a null on ToString, just return null - string? valueStr = value.ToString(); - if (string.IsNullOrEmpty(valueStr)) - return null; - - // Get the member info array - var memberInfos = enumType?.GetMember(valueStr); - if (memberInfos is null) - return null; - - // Get the enum value info from the array, if possible - var enumValueMemberInfo = Array.Find(memberInfos, m => m.DeclaringType == enumType); - if (enumValueMemberInfo is null) - return null; - - // Try to get the relevant attribute - var attributes = enumValueMemberInfo.GetCustomAttributes(typeof(MappingAttribute), true); - if (attributes is null || attributes.Length == 0) - return null; - - // Return the first attribute, if possible - return (MappingAttribute?)attributes[0]; - } - #endregion } } diff --git a/SabreTools.Metadata/MappingAttribute.cs b/SabreTools.Metadata/MappingAttribute.cs deleted file mode 100644 index 59f45d93..00000000 --- a/SabreTools.Metadata/MappingAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace SabreTools.Metadata -{ - /// - /// Maps a set of strings to an enum value - /// - [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] - public class MappingAttribute(params string[] mappings) : Attribute - { - /// - /// Set of mapping strings - /// - public string[] Mappings { get; } = mappings; - } -} diff --git a/SabreTools.Wrappers/N3DS.Encryption.cs b/SabreTools.Wrappers/N3DS.Encryption.cs index 113a706e..e4e3c431 100644 --- a/SabreTools.Wrappers/N3DS.Encryption.cs +++ b/SabreTools.Wrappers/N3DS.Encryption.cs @@ -212,7 +212,7 @@ namespace SabreTools.Wrappers { // Determine the keys needed for this partition N3DSPartitionKeys? keys = GetDecryptionKeys(index, settings); - if (keys == null) + if (keys is null) { Console.WriteLine($"Partition {index} could not generate keys. Skipping..."); return; @@ -637,7 +637,7 @@ namespace SabreTools.Wrappers { // Determine the keys needed for this partition N3DSPartitionKeys? keys = GetEncryptionKeys(index, settings); - if (keys == null) + if (keys is null) { Console.WriteLine($"Partition {index} could not generate keys. Skipping..."); return;