diff --git a/SabreTools.Core/Enums.cs b/SabreTools.Core/Enums.cs index 7939e53a..963cf5b9 100644 --- a/SabreTools.Core/Enums.cs +++ b/SabreTools.Core/Enums.cs @@ -48,11 +48,11 @@ namespace SabreTools.Core FullMerged, /// This is not usually defined for Merging flags - [Mapping("device", "devicenonmerged", "deviceunmerged")] + [Mapping("device", "deviceunmerged", "devicenonmerged")] DeviceNonMerged, /// This is not usually defined for Merging flags - [Mapping("full", "fullnonmerged", "fullunmerged")] + [Mapping("full", "fullunmerged", "fullnonmerged")] FullNonMerged, } @@ -85,13 +85,13 @@ namespace SabreTools.Core /// /// Force all sets to be in archives, except disk and media /// - [Mapping("yes", "zip")] + [Mapping("zip", "yes")] Zip, /// /// Force all sets to be extracted into subfolders /// - [Mapping("no", "unzip")] + [Mapping("unzip", "no")] Unzip, /// @@ -461,7 +461,7 @@ namespace SabreTools.Core [Mapping("device")] Device, - [Mapping("deviceref", "device_ref")] + [Mapping("device_ref", "deviceref")] DeviceReference, [Mapping("dipswitch")] @@ -497,7 +497,7 @@ namespace SabreTools.Core [Mapping("part")] Part, - [Mapping("partfeature", "part_feature")] + [Mapping("part_feature", "partfeature")] PartFeature, [Mapping("port")] @@ -509,7 +509,7 @@ namespace SabreTools.Core [Mapping("release")] Release, - [Mapping("releasedetails", "release_details")] + [Mapping("release_details", "releasedetails")] ReleaseDetails, [Mapping("sample")] @@ -536,7 +536,7 @@ namespace SabreTools.Core [Mapping("sound")] Sound, - [Mapping("sourcedetails", "source_details")] + [Mapping("source_details", "sourcedetails")] SourceDetails, [Mapping("blank")] @@ -609,10 +609,10 @@ namespace SabreTools.Core [Mapping("bios")] Bios = 1 << 0, - [Mapping("dev", "device")] + [Mapping("device", "dev")] Device = 1 << 1, - [Mapping("mech", "mechanical")] + [Mapping("mechanical", "mech")] Mechanical = 1 << 2, } diff --git a/SabreTools.Core/Tools/Converters.cs b/SabreTools.Core/Tools/Converters.cs index 1261e8d9..0ec1fdf4 100644 --- a/SabreTools.Core/Tools/Converters.cs +++ b/SabreTools.Core/Tools/Converters.cs @@ -359,7 +359,8 @@ namespace SabreTools.Core.Tools // Loop through the mappings and add each foreach (string mapString in attr.Mappings) { - mappings[mapString] = value; + if (mapString != null) + mappings[mapString] = value; } } @@ -383,14 +384,7 @@ namespace SabreTools.Core.Tools /// ChipType to get value from /// String value corresponding to the ChipType public static string FromChipType(this ChipType chipType) - { - return chipType switch - { - ChipType.CPU => "cpu", - ChipType.Audio => "audio", - _ => null, - }; - } + => AsStringValue(chipType); /// /// Get string value from input ControlType @@ -398,27 +392,7 @@ namespace SabreTools.Core.Tools /// ControlType to get value from /// String value corresponding to the ControlType public static string FromControlType(this ControlType controlType) - { - return controlType 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, - }; - } + => AsStringValue(controlType); /// /// Get string value from input DeviceType @@ -426,33 +400,7 @@ namespace SabreTools.Core.Tools /// vDeviceType to get value from /// String value corresponding to the DeviceType public static string FromDeviceType(this DeviceType deviceType) - { - return deviceType 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, - }; - } + => AsStringValue(deviceType); /// /// Get string value from input DisplayType @@ -460,17 +408,7 @@ namespace SabreTools.Core.Tools /// DisplayType to get value from /// String value corresponding to the DisplayType public static string FromDisplayType(this DisplayType displayType) - { - return displayType switch - { - DisplayType.Raster => "raster", - DisplayType.Vector => "vector", - DisplayType.LCD => "lcd", - DisplayType.SVG => "svg", - DisplayType.Unknown => "unknown", - _ => null, - }; - } + => AsStringValue(displayType); /// /// Get string value from input Endianness @@ -478,14 +416,7 @@ namespace SabreTools.Core.Tools /// Endianness to get value from /// String value corresponding to the Endianness public static string FromEndianness(this Endianness endianness) - { - return endianness switch - { - Endianness.Big => "big", - Endianness.Little => "little", - _ => null, - }; - } + => AsStringValue(endianness); /// /// Get string value from input FeatureStatus @@ -493,14 +424,7 @@ namespace SabreTools.Core.Tools /// FeatureStatus to get value from /// String value corresponding to the FeatureStatus public static string FromFeatureStatus(this FeatureStatus featureStatus) - { - return featureStatus switch - { - FeatureStatus.Unemulated => "unemulated", - FeatureStatus.Imperfect => "imperfect", - _ => null, - }; - } + => AsStringValue(featureStatus); /// /// Get string value from input FeatureType @@ -508,26 +432,7 @@ namespace SabreTools.Core.Tools /// FeatureType to get value from /// String value corresponding to the FeatureType public static string FromFeatureType(this FeatureType featureType) - { - return featureType 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, - }; - } + => AsStringValue(featureType); /// /// Get string value from input ItemStatus @@ -536,16 +441,15 @@ namespace SabreTools.Core.Tools /// True to use Yes/No format instead /// String value corresponding to the ItemStatus public static string FromItemStatus(this ItemStatus status, bool yesno) - { - return status switch - { - ItemStatus.Good => "good", - ItemStatus.BadDump => "baddump", - ItemStatus.Nodump => yesno ? "yes" : "nodump", - ItemStatus.Verified => "verified", - _ => null, - }; - } + => AsStringValue(status, yesno); + + /// + /// Get string value from input ItemType? + /// + /// ItemType? to get value from + /// String value corresponding to the ItemType? + public static string FromItemType(this ItemType itemType) + => AsStringValue(itemType); /// /// Get string value from input LoadFlag @@ -553,79 +457,7 @@ namespace SabreTools.Core.Tools /// LoadFlag to get value from /// String value corresponding to the LoadFlag public static string FromLoadFlag(this LoadFlag loadFlag) - { - return loadFlag 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 string value from input ItemType? - /// - /// ItemType? to get value from - /// String value corresponding to the ItemType? - public static string FromItemType(this ItemType? itemType) - { - return itemType switch - { - ItemType.Adjuster => "adjuster", - ItemType.Analog => "analog", - ItemType.Archive => "archive", - ItemType.BiosSet => "biosset", - ItemType.Blank => "blank", - ItemType.Chip => "chip", - ItemType.Condition => "condition", - ItemType.Configuration => "configuration", - ItemType.Control => "control", - ItemType.DataArea => "dataarea", - ItemType.Device => "device", - ItemType.DeviceReference => "device_ref", - ItemType.DipSwitch => "dipswitch", - ItemType.Disk => "disk", - 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.Location => "location", - ItemType.Media => "media", - ItemType.Part => "part", - ItemType.PartFeature => "part_feature", - ItemType.Port => "port", - ItemType.RamOption => "ramoption", - ItemType.Release => "release", - ItemType.ReleaseDetails => "release_details", - ItemType.Rom => "rom", - ItemType.Sample => "sample", - ItemType.Serials => "serials", - ItemType.Setting => "setting", - ItemType.SharedFeature => "sharedfeat", - ItemType.Slot => "slot", - ItemType.SlotOption => "slotoption", - ItemType.SoftwareList => "softwarelist", - ItemType.Sound => "sound", - ItemType.SourceDetails => "source_details", - _ => null, - }; - } + => AsStringValue(loadFlag); /// /// Get string value from input MachineType @@ -634,15 +466,7 @@ namespace SabreTools.Core.Tools /// True to use old naming instead /// String value corresponding to the MachineType public static string FromMachineType(this MachineType gametype, bool old) - { - return gametype switch - { - MachineType.Bios => "bios", - MachineType.Device => old ? "dev" : "device", - MachineType.Mechanical => old ? "mech" : "mechanical", - _ => null, - }; - } + => AsStringValue(gametype, old); /// /// Get string value from input MergingFlag @@ -651,18 +475,7 @@ namespace SabreTools.Core.Tools /// True to use RomCenter naming instead /// String value corresponding to the MergingFlag public static string FromMergingFlag(this MergingFlag merging, bool romCenter) - { - return merging switch - { - MergingFlag.Split => "split", - MergingFlag.Merged => "merged", - MergingFlag.FullMerged => "fullmerged", - MergingFlag.NonMerged => romCenter ? "unmerged" : "nonmerged", - MergingFlag.FullNonMerged => "full", - MergingFlag.DeviceNonMerged => "device", - _ => null, - }; - } + => AsStringValue(merging, romCenter); /// /// Get string value from input NodumpFlag @@ -670,31 +483,15 @@ namespace SabreTools.Core.Tools /// NodumpFlag to get value from /// String value corresponding to the NodumpFlag public static string FromNodumpFlag(this NodumpFlag nodump) - { - return nodump switch - { - NodumpFlag.Obsolete => "obsolete", - NodumpFlag.Required => "required", - NodumpFlag.Ignore => "ignore", - _ => null, - }; - } + => AsStringValue(nodump); /// /// Get string value from input OpenMSXSubType /// - /// OpenMSXSubType to get value from + /// OpenMSXSubType to get value from /// String value corresponding to the OpenMSXSubType - public static string FromOpenMSXSubType(this OpenMSXSubType itemType) - { - return itemType switch - { - OpenMSXSubType.Rom => "rom", - OpenMSXSubType.MegaRom => "megarom", - OpenMSXSubType.SCCPlusCart => "sccpluscart", - _ => null, - }; - } + public static string FromOpenMSXSubType(this OpenMSXSubType subType) + => AsStringValue(subType); /// /// Get string value from input PackingFlag @@ -703,16 +500,7 @@ namespace SabreTools.Core.Tools /// True to use Yes/No format instead /// String value corresponding to the PackingFlag public static string FromPackingFlag(this PackingFlag packing, bool yesno) - { - return packing switch - { - PackingFlag.Zip => yesno ? "yes" : "zip", - PackingFlag.Unzip => yesno ? "no" : "unzip", - PackingFlag.Partial => "partial", - PackingFlag.Flat => "flat", - _ => null, - }; - } + => AsStringValue(packing, yesno); /// /// Get string value from input Relation @@ -720,18 +508,7 @@ namespace SabreTools.Core.Tools /// Relation to get value from /// String value corresponding to the Relation public static string FromRelation(this Relation relation) - { - return relation switch - { - Relation.Equal => "eq", - Relation.NotEqual => "ne", - Relation.GreaterThan => "gt", - Relation.LessThanOrEqual => "le", - Relation.LessThan => "lt", - Relation.GreaterThanOrEqual => "ge", - _ => null, - }; - } + => AsStringValue(relation); /// /// Get string value from input Runnable @@ -739,15 +516,7 @@ namespace SabreTools.Core.Tools /// Runnable to get value from /// String value corresponding to the Runnable public static string FromRunnable(this Runnable runnable) - { - return runnable switch - { - Runnable.No => "no", - Runnable.Partial => "partial", - Runnable.Yes => "yes", - _ => null, - }; - } + => AsStringValue(runnable); /// /// Get string value from input SoftwareListStatus @@ -755,14 +524,7 @@ namespace SabreTools.Core.Tools /// SoftwareListStatus to get value from /// String value corresponding to the SoftwareListStatus public static string FromSoftwareListStatus(this SoftwareListStatus status) - { - return status switch - { - SoftwareListStatus.Original => "original", - SoftwareListStatus.Compatible => "compatible", - _ => null, - }; - } + => AsStringValue(status); /// /// Get string value from input Supported @@ -771,15 +533,7 @@ namespace SabreTools.Core.Tools /// True to use verbose output, false otherwise /// String value corresponding to the Supported public static string FromSupported(this Supported supported, bool verbose) - { - return supported switch - { - Supported.No => verbose ? "unsupported" : "no", - Supported.Partial => "partial", - Supported.Yes => verbose ? "supported" : "yes", - _ => null, - }; - } + => AsStringValue(supported, verbose); /// /// Get string value from input SupportStatus @@ -787,15 +541,7 @@ namespace SabreTools.Core.Tools /// SupportStatus to get value from /// String value corresponding to the SupportStatus public static string FromSupportStatus(this SupportStatus supportStatus) - { - return supportStatus switch - { - SupportStatus.Good => "good", - SupportStatus.Imperfect => "imperfect", - SupportStatus.Preliminary => "preliminary", - _ => null, - }; - } + => AsStringValue(supportStatus); /// /// Get string value from input bool? @@ -815,13 +561,14 @@ namespace SabreTools.Core.Tools /// /// Get the string value for an input enum, if possible /// - /// Enum value to parse/param> + /// Enum value to parse/param> + /// True to use the second mapping option, if it exists /// Enum type that is expected /// String value representing the input, default on error - private static string? AsStringValue(T value) + private static string? AsStringValue(T value, bool useSecond = false) { // Get the mapping dictionary - var mappings = GenerateToString(); + var mappings = GenerateToString(useSecond); // Try to get the value from the mappings if (mappings.ContainsKey(value)) @@ -834,9 +581,10 @@ namespace SabreTools.Core.Tools /// /// Get a set of mappings from enum values to string /// - /// Enum type to generate from + /// True to use the second mapping option, if it exists + /// Enum type that is expected /// Dictionary of enum to string values - private static Dictionary GenerateToString() + private static Dictionary GenerateToString(bool useSecond) { try { @@ -852,8 +600,11 @@ namespace SabreTools.Core.Tools if (attr?.Mappings == null || !attr.Mappings.Any()) continue; - // Always use the first value in the list - mappings[value] = attr.Mappings[0]; + // 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 diff --git a/SabreTools.DatFiles/Formats/ClrMamePro.cs b/SabreTools.DatFiles/Formats/ClrMamePro.cs index 607b62ff..aa7a5d92 100644 --- a/SabreTools.DatFiles/Formats/ClrMamePro.cs +++ b/SabreTools.DatFiles/Formats/ClrMamePro.cs @@ -338,7 +338,7 @@ namespace SabreTools.DatFiles.Formats (item as Media).SHA256 = attrVal; else if (item.ItemType == ItemType.Rom) (item as Rom).SHA256 = attrVal; - + break; case "sha384": if (item.ItemType == ItemType.Rom) @@ -539,8 +539,10 @@ namespace SabreTools.DatFiles.Formats cmpw.WriteOptionalStandalone("homepage", Header.Homepage); cmpw.WriteOptionalStandalone("url", Header.Url); cmpw.WriteOptionalStandalone("comment", Header.Comment); - cmpw.WriteOptionalStandalone("forcezipping", Header.ForcePacking.FromPackingFlag(true), false); - cmpw.WriteOptionalStandalone("forcemerging", Header.ForceMerging.FromMergingFlag(false), false); + if (Header.ForcePacking != PackingFlag.None) + cmpw.WriteOptionalStandalone("forcezipping", Header.ForcePacking.FromPackingFlag(true), false); + if (Header.ForceMerging != MergingFlag.None) + cmpw.WriteOptionalStandalone("forcemerging", Header.ForceMerging.FromMergingFlag(false), false); // End clrmamepro cmpw.WriteEndElement(); @@ -624,7 +626,8 @@ namespace SabreTools.DatFiles.Formats cmpw.WriteRequiredAttributeString("name", disk.Name); cmpw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant(), quoteOverride: false); cmpw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant(), quoteOverride: false); - cmpw.WriteOptionalAttributeString("flags", disk.ItemStatus.FromItemStatus(false)); + if (disk.ItemStatus != ItemStatus.None) + cmpw.WriteOptionalAttributeString("flags", disk.ItemStatus.FromItemStatus(false)); cmpw.WriteEndElement(); break; @@ -663,7 +666,8 @@ namespace SabreTools.DatFiles.Formats cmpw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant(), quoteOverride: false); cmpw.WriteOptionalAttributeString("spamsum", rom.SpamSum?.ToLowerInvariant(), quoteOverride: false); cmpw.WriteOptionalAttributeString("date", rom.Date); - cmpw.WriteOptionalAttributeString("flags", rom.ItemStatus.FromItemStatus(false)); + if (rom.ItemStatus != ItemStatus.None) + cmpw.WriteOptionalAttributeString("flags", rom.ItemStatus.FromItemStatus(false)); cmpw.WriteEndElement(); break; diff --git a/SabreTools.DatFiles/Formats/Listxml.cs b/SabreTools.DatFiles/Formats/Listxml.cs index ba3568d0..8211d928 100644 --- a/SabreTools.DatFiles/Formats/Listxml.cs +++ b/SabreTools.DatFiles/Formats/Listxml.cs @@ -1722,7 +1722,8 @@ namespace SabreTools.DatFiles.Formats xtw.WriteOptionalAttributeString("region", disk.Region); xtw.WriteOptionalAttributeString("index", disk.Index); xtw.WriteOptionalAttributeString("writable", disk.Writable.FromYesNo()); - xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false)); + if (disk.ItemStatus != ItemStatus.None) + xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false)); xtw.WriteOptionalAttributeString("optional", disk.Optional.FromYesNo()); xtw.WriteEndElement(); break; @@ -1836,7 +1837,8 @@ namespace SabreTools.DatFiles.Formats xtw.WriteOptionalAttributeString("merge", rom.MergeTag); xtw.WriteOptionalAttributeString("region", rom.Region); xtw.WriteOptionalAttributeString("offset", rom.Offset); - xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false)); + if (rom.ItemStatus != ItemStatus.None) + xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false)); xtw.WriteOptionalAttributeString("optional", rom.Optional.FromYesNo()); xtw.WriteEndElement(); break; @@ -1871,7 +1873,8 @@ namespace SabreTools.DatFiles.Formats xtw.WriteStartElement("softwarelist"); xtw.WriteRequiredAttributeString("tag", softwareList.Tag); xtw.WriteRequiredAttributeString("name", softwareList.Name); - xtw.WriteRequiredAttributeString("status", softwareList.Status.FromSoftwareListStatus()); + if (softwareList.Status != SoftwareListStatus.None) + xtw.WriteRequiredAttributeString("status", softwareList.Status.FromSoftwareListStatus()); xtw.WriteOptionalAttributeString("filter", softwareList.Filter); xtw.WriteEndElement(); break; diff --git a/SabreTools.DatFiles/Formats/Logiqx.cs b/SabreTools.DatFiles/Formats/Logiqx.cs index c99c3c96..8302e2db 100644 --- a/SabreTools.DatFiles/Formats/Logiqx.cs +++ b/SabreTools.DatFiles/Formats/Logiqx.cs @@ -983,9 +983,12 @@ namespace SabreTools.DatFiles.Formats { xtw.WriteStartElement("clrmamepro"); - xtw.WriteOptionalAttributeString("forcepacking", Header.ForcePacking.FromPackingFlag(false)); - xtw.WriteOptionalAttributeString("forcemerging", Header.ForceMerging.FromMergingFlag(false)); - xtw.WriteOptionalAttributeString("forcenodump", Header.ForceNodump.FromNodumpFlag()); + if (Header.ForcePacking != PackingFlag.None) + xtw.WriteOptionalAttributeString("forcepacking", Header.ForcePacking.FromPackingFlag(false)); + if (Header.ForceMerging != MergingFlag.None) + xtw.WriteOptionalAttributeString("forcemerging", Header.ForceMerging.FromMergingFlag(false)); + if (Header.ForceNodump != NodumpFlag.None) + xtw.WriteOptionalAttributeString("forcenodump", Header.ForceNodump.FromNodumpFlag()); xtw.WriteOptionalAttributeString("header", Header.HeaderSkipper); // End clrmamepro @@ -1000,9 +1003,12 @@ namespace SabreTools.DatFiles.Formats xtw.WriteStartElement("romcenter"); xtw.WriteOptionalAttributeString("plugin", Header.System); - xtw.WriteOptionalAttributeString("rommode", Header.RomMode.FromMergingFlag(true)); - xtw.WriteOptionalAttributeString("biosmode", Header.BiosMode.FromMergingFlag(true)); - xtw.WriteOptionalAttributeString("samplemode", Header.SampleMode.FromMergingFlag(true)); + if (Header.RomMode != MergingFlag.None) + xtw.WriteOptionalAttributeString("rommode", Header.RomMode.FromMergingFlag(true)); + if (Header.BiosMode != MergingFlag.None) + xtw.WriteOptionalAttributeString("biosmode", Header.BiosMode.FromMergingFlag(true)); + if (Header.SampleMode != MergingFlag.None) + xtw.WriteOptionalAttributeString("samplemode", Header.SampleMode.FromMergingFlag(true)); xtw.WriteOptionalAttributeString("lockrommode", Header.LockRomMode.FromYesNo()); xtw.WriteOptionalAttributeString("lockbiosmode", Header.LockBiosMode.FromYesNo()); xtw.WriteOptionalAttributeString("locksamplemode", Header.LockSampleMode.FromYesNo()); @@ -1138,7 +1144,8 @@ namespace SabreTools.DatFiles.Formats xtw.WriteRequiredAttributeString("name", disk.Name); xtw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant()); xtw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant()); - xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false)); + if (disk.ItemStatus != ItemStatus.None) + xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false)); xtw.WriteEndElement(); break; @@ -1177,7 +1184,8 @@ namespace SabreTools.DatFiles.Formats xtw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant()); xtw.WriteOptionalAttributeString("spamsum", rom.SpamSum?.ToLowerInvariant()); xtw.WriteOptionalAttributeString("date", rom.Date); - xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false)); + if (rom.ItemStatus != ItemStatus.None) + xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false)); xtw.WriteOptionalAttributeString("inverted", rom.Inverted.FromYesNo()); xtw.WriteOptionalAttributeString("mia", rom.MIA.FromYesNo()); xtw.WriteEndElement(); diff --git a/SabreTools.DatFiles/Formats/SoftwareList.cs b/SabreTools.DatFiles/Formats/SoftwareList.cs index cf3b4844..949663a0 100644 --- a/SabreTools.DatFiles/Formats/SoftwareList.cs +++ b/SabreTools.DatFiles/Formats/SoftwareList.cs @@ -883,7 +883,8 @@ namespace SabreTools.DatFiles.Formats xtw.WriteRequiredAttributeString("name", disk.Name); xtw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant()); xtw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant()); - xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false)); + if (disk.ItemStatus != ItemStatus.None) + xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false)); xtw.WriteOptionalAttributeString("writable", disk.Writable.FromYesNo()); xtw.WriteEndElement(); @@ -940,7 +941,8 @@ namespace SabreTools.DatFiles.Formats xtw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant()); xtw.WriteOptionalAttributeString("offset", rom.Offset); xtw.WriteOptionalAttributeString("value", rom.Value); - xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false)); + if (rom.ItemStatus != ItemStatus.None) + xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false)); xtw.WriteOptionalAttributeString("loadflag", rom.LoadFlag.FromLoadFlag()); xtw.WriteEndElement(); diff --git a/SabreTools.Test/Core/ConvertersTests.cs b/SabreTools.Test/Core/ConvertersTests.cs index 08311330..2f8dd620 100644 --- a/SabreTools.Test/Core/ConvertersTests.cs +++ b/SabreTools.Test/Core/ConvertersTests.cs @@ -505,5 +505,357 @@ namespace SabreTools.Test.Core } #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.FromChipType(); + 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.FromControlType(); + Assert.Equal(expected, actual); + } + + // TODO: Write new test for all supported DatHeaderField values + // TODO: Write new test for all supported DatItemField values + + [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.FromDeviceType(); + 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.FromDisplayType(); + 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.FromEndianness(); + 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.FromFeatureStatus(); + 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.FromFeatureType(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(ItemStatus.NULL, true, null)] + [InlineData(ItemStatus.NULL, 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 yesno, string expected) + { + string actual = field.FromItemStatus(yesno); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(ItemType.NULL, null)] + [InlineData(ItemType.Adjuster, "adjuster")] + [InlineData(ItemType.Analog, "analog")] + [InlineData(ItemType.Archive, "archive")] + [InlineData(ItemType.BiosSet, "biosset")] + [InlineData(ItemType.Blank, "blank")] + [InlineData(ItemType.Chip, "chip")] + [InlineData(ItemType.Condition, "condition")] + [InlineData(ItemType.Configuration, "configuration")] + [InlineData(ItemType.Control, "control")] + [InlineData(ItemType.DataArea, "dataarea")] + [InlineData(ItemType.Device, "device")] + [InlineData(ItemType.DeviceReference, "device_ref")] + [InlineData(ItemType.DipSwitch, "dipswitch")] + [InlineData(ItemType.Disk, "disk")] + [InlineData(ItemType.DiskArea, "diskarea")] + [InlineData(ItemType.Display, "display")] + [InlineData(ItemType.Driver, "driver")] + [InlineData(ItemType.Extension, "extension")] + [InlineData(ItemType.Feature, "feature")] + [InlineData(ItemType.File, "file")] + [InlineData(ItemType.Info, "info")] + [InlineData(ItemType.Input, "input")] + [InlineData(ItemType.Instance, "instance")] + [InlineData(ItemType.Location, "location")] + [InlineData(ItemType.Media, "media")] + [InlineData(ItemType.Part, "part")] + [InlineData(ItemType.PartFeature, "part_feature")] + [InlineData(ItemType.Port, "port")] + [InlineData(ItemType.RamOption, "ramoption")] + [InlineData(ItemType.Release, "release")] + [InlineData(ItemType.ReleaseDetails, "release_details")] + [InlineData(ItemType.Rom, "rom")] + [InlineData(ItemType.Sample, "sample")] + [InlineData(ItemType.Serials, "serials")] + [InlineData(ItemType.Setting, "setting")] + [InlineData(ItemType.SharedFeature, "sharedfeat")] + [InlineData(ItemType.Slot, "slot")] + [InlineData(ItemType.SlotOption, "slotoption")] + [InlineData(ItemType.SoftwareList, "softwarelist")] + [InlineData(ItemType.Sound, "sound")] + [InlineData(ItemType.SourceDetails, "source_details")] + public void FromItemTypeTest(ItemType field, string expected) + { + string actual = field.FromItemType(); + 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.FromLoadFlag(); + Assert.Equal(expected, actual); + } + + // TODO: Write new test for all supported MachineField values + + [Theory] + [InlineData(MachineType.None, true, "none")] + [InlineData(MachineType.None, false, "none")] + [InlineData(MachineType.Bios, true, "bios")] + [InlineData(MachineType.Bios, false, "bios")] + [InlineData(MachineType.Device, true, "dev")] + [InlineData(MachineType.Device, false, "device")] + [InlineData(MachineType.Mechanical, true, "mech")] + [InlineData(MachineType.Mechanical, false, "mechanical")] + public void FromMachineTypeTest(MachineType field, bool old, string expected) + { + string actual = field.FromMachineType(old); + 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, "deviceunmerged")] + [InlineData(MergingFlag.DeviceNonMerged, false, "device")] + [InlineData(MergingFlag.FullNonMerged, true, "fullunmerged")] + [InlineData(MergingFlag.FullNonMerged, false, "full")] + public void FromMergingFlagTest(MergingFlag field, bool romcenter, string expected) + { + string actual = field.FromMergingFlag(romcenter); + 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.FromNodumpFlag(); + 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.FromOpenMSXSubType(); + 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")] + public void FromPackingFlagTest(PackingFlag field, bool yesno, string expected) + { + string actual = field.FromPackingFlag(yesno); + 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.FromRelation(); + 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.FromRunnable(); + 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.FromSoftwareListStatus(); + 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 verbose, string expected) + { + string actual = field.FromSupported(verbose); + 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.FromSupportStatus(); + Assert.Equal(expected, actual); + } + + #endregion } } \ No newline at end of file