Update enum handling, part 2

This commit is contained in:
Matt Nadareski
2023-04-20 12:12:56 -04:00
parent 1f601dfa3f
commit 0594a6296c
7 changed files with 440 additions and 320 deletions

View File

@@ -48,11 +48,11 @@ namespace SabreTools.Core
FullMerged,
/// <remarks>This is not usually defined for Merging flags</remarks>
[Mapping("device", "devicenonmerged", "deviceunmerged")]
[Mapping("device", "deviceunmerged", "devicenonmerged")]
DeviceNonMerged,
/// <remarks>This is not usually defined for Merging flags</remarks>
[Mapping("full", "fullnonmerged", "fullunmerged")]
[Mapping("full", "fullunmerged", "fullnonmerged")]
FullNonMerged,
}
@@ -85,13 +85,13 @@ namespace SabreTools.Core
/// <summary>
/// Force all sets to be in archives, except disk and media
/// </summary>
[Mapping("yes", "zip")]
[Mapping("zip", "yes")]
Zip,
/// <summary>
/// Force all sets to be extracted into subfolders
/// </summary>
[Mapping("no", "unzip")]
[Mapping("unzip", "no")]
Unzip,
/// <summary>
@@ -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,
}

View File

@@ -359,6 +359,7 @@ namespace SabreTools.Core.Tools
// Loop through the mappings and add each
foreach (string mapString in attr.Mappings)
{
if (mapString != null)
mappings[mapString] = value;
}
}
@@ -383,14 +384,7 @@ namespace SabreTools.Core.Tools
/// <param name="chipType">ChipType to get value from</param>
/// <returns>String value corresponding to the ChipType</returns>
public static string FromChipType(this ChipType chipType)
{
return chipType switch
{
ChipType.CPU => "cpu",
ChipType.Audio => "audio",
_ => null,
};
}
=> AsStringValue(chipType);
/// <summary>
/// Get string value from input ControlType
@@ -398,27 +392,7 @@ namespace SabreTools.Core.Tools
/// <param name="controlType">ControlType to get value from</param>
/// <returns>String value corresponding to the ControlType</returns>
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);
/// <summary>
/// Get string value from input DeviceType
@@ -426,33 +400,7 @@ namespace SabreTools.Core.Tools
/// <param name="deviceType">vDeviceType to get value from</param>
/// <returns>String value corresponding to the DeviceType</returns>
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);
/// <summary>
/// Get string value from input DisplayType
@@ -460,17 +408,7 @@ namespace SabreTools.Core.Tools
/// <param name="displayType">DisplayType to get value from</param>
/// <returns>String value corresponding to the DisplayType</returns>
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);
/// <summary>
/// Get string value from input Endianness
@@ -478,14 +416,7 @@ namespace SabreTools.Core.Tools
/// <param name="endianness">Endianness to get value from</param>
/// <returns>String value corresponding to the Endianness</returns>
public static string FromEndianness(this Endianness endianness)
{
return endianness switch
{
Endianness.Big => "big",
Endianness.Little => "little",
_ => null,
};
}
=> AsStringValue(endianness);
/// <summary>
/// Get string value from input FeatureStatus
@@ -493,14 +424,7 @@ namespace SabreTools.Core.Tools
/// <param name="featureStatus">FeatureStatus to get value from</param>
/// <returns>String value corresponding to the FeatureStatus</returns>
public static string FromFeatureStatus(this FeatureStatus featureStatus)
{
return featureStatus switch
{
FeatureStatus.Unemulated => "unemulated",
FeatureStatus.Imperfect => "imperfect",
_ => null,
};
}
=> AsStringValue(featureStatus);
/// <summary>
/// Get string value from input FeatureType
@@ -508,26 +432,7 @@ namespace SabreTools.Core.Tools
/// <param name="featureType">FeatureType to get value from</param>
/// <returns>String value corresponding to the FeatureType</returns>
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);
/// <summary>
/// Get string value from input ItemStatus
@@ -536,16 +441,15 @@ namespace SabreTools.Core.Tools
/// <param name="yesno">True to use Yes/No format instead</param>
/// <returns>String value corresponding to the ItemStatus</returns>
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);
/// <summary>
/// Get string value from input ItemType?
/// </summary>
/// <param name="itemType">ItemType? to get value from</param>
/// <returns>String value corresponding to the ItemType?</returns>
public static string FromItemType(this ItemType itemType)
=> AsStringValue(itemType);
/// <summary>
/// Get string value from input LoadFlag
@@ -553,79 +457,7 @@ namespace SabreTools.Core.Tools
/// <param name="loadFlag">LoadFlag to get value from</param>
/// <returns>String value corresponding to the LoadFlag</returns>
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,
};
}
/// <summary>
/// Get string value from input ItemType?
/// </summary>
/// <param name="itemType">ItemType? to get value from</param>
/// <returns>String value corresponding to the ItemType?</returns>
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);
/// <summary>
/// Get string value from input MachineType
@@ -634,15 +466,7 @@ namespace SabreTools.Core.Tools
/// <param name="romCenter">True to use old naming instead</param>
/// <returns>String value corresponding to the MachineType</returns>
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);
/// <summary>
/// Get string value from input MergingFlag
@@ -651,18 +475,7 @@ namespace SabreTools.Core.Tools
/// <param name="romCenter">True to use RomCenter naming instead</param>
/// <returns>String value corresponding to the MergingFlag</returns>
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);
/// <summary>
/// Get string value from input NodumpFlag
@@ -670,31 +483,15 @@ namespace SabreTools.Core.Tools
/// <param name="nodump">NodumpFlag to get value from</param>
/// <returns>String value corresponding to the NodumpFlag</returns>
public static string FromNodumpFlag(this NodumpFlag nodump)
{
return nodump switch
{
NodumpFlag.Obsolete => "obsolete",
NodumpFlag.Required => "required",
NodumpFlag.Ignore => "ignore",
_ => null,
};
}
=> AsStringValue(nodump);
/// <summary>
/// Get string value from input OpenMSXSubType
/// </summary>
/// <param name="itemType">OpenMSXSubType to get value from</param>
/// <param name="subType">OpenMSXSubType to get value from</param>
/// <returns>String value corresponding to the OpenMSXSubType</returns>
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);
/// <summary>
/// Get string value from input PackingFlag
@@ -703,16 +500,7 @@ namespace SabreTools.Core.Tools
/// <param name="yesno">True to use Yes/No format instead</param>
/// <returns>String value corresponding to the PackingFlag</returns>
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);
/// <summary>
/// Get string value from input Relation
@@ -720,18 +508,7 @@ namespace SabreTools.Core.Tools
/// <param name="relation">Relation to get value from</param>
/// <returns>String value corresponding to the Relation</returns>
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);
/// <summary>
/// Get string value from input Runnable
@@ -739,15 +516,7 @@ namespace SabreTools.Core.Tools
/// <param name="runnable">Runnable to get value from</param>
/// <returns>String value corresponding to the Runnable</returns>
public static string FromRunnable(this Runnable runnable)
{
return runnable switch
{
Runnable.No => "no",
Runnable.Partial => "partial",
Runnable.Yes => "yes",
_ => null,
};
}
=> AsStringValue(runnable);
/// <summary>
/// Get string value from input SoftwareListStatus
@@ -755,14 +524,7 @@ namespace SabreTools.Core.Tools
/// <param name="status">SoftwareListStatus to get value from</param>
/// <returns>String value corresponding to the SoftwareListStatus</returns>
public static string FromSoftwareListStatus(this SoftwareListStatus status)
{
return status switch
{
SoftwareListStatus.Original => "original",
SoftwareListStatus.Compatible => "compatible",
_ => null,
};
}
=> AsStringValue(status);
/// <summary>
/// Get string value from input Supported
@@ -771,15 +533,7 @@ namespace SabreTools.Core.Tools
/// <param name="verbose">True to use verbose output, false otherwise</param>
/// <returns>String value corresponding to the Supported</returns>
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);
/// <summary>
/// Get string value from input SupportStatus
@@ -787,15 +541,7 @@ namespace SabreTools.Core.Tools
/// <param name="supportStatus">SupportStatus to get value from</param>
/// <returns>String value corresponding to the SupportStatus</returns>
public static string FromSupportStatus(this SupportStatus supportStatus)
{
return supportStatus switch
{
SupportStatus.Good => "good",
SupportStatus.Imperfect => "imperfect",
SupportStatus.Preliminary => "preliminary",
_ => null,
};
}
=> AsStringValue(supportStatus);
/// <summary>
/// Get string value from input bool?
@@ -815,13 +561,14 @@ namespace SabreTools.Core.Tools
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="type">Enum value to parse/param>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>String value representing the input, default on error</returns>
private static string? AsStringValue<T>(T value)
private static string? AsStringValue<T>(T value, bool useSecond = false)
{
// Get the mapping dictionary
var mappings = GenerateToString<T>();
var mappings = GenerateToString<T>(useSecond);
// Try to get the value from the mappings
if (mappings.ContainsKey(value))
@@ -834,9 +581,10 @@ namespace SabreTools.Core.Tools
/// <summary>
/// Get a set of mappings from enum values to string
/// </summary>
/// <param name="type">Enum type to generate from</param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Dictionary of enum to string values</returns>
private static Dictionary<T, string> GenerateToString<T>()
private static Dictionary<T, string> GenerateToString<T>(bool useSecond)
{
try
{
@@ -852,7 +600,10 @@ namespace SabreTools.Core.Tools
if (attr?.Mappings == null || !attr.Mappings.Any())
continue;
// Always use the first value in the list
// 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];
}

View File

@@ -539,7 +539,9 @@ namespace SabreTools.DatFiles.Formats
cmpw.WriteOptionalStandalone("homepage", Header.Homepage);
cmpw.WriteOptionalStandalone("url", Header.Url);
cmpw.WriteOptionalStandalone("comment", Header.Comment);
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
@@ -624,6 +626,7 @@ 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);
if (disk.ItemStatus != ItemStatus.None)
cmpw.WriteOptionalAttributeString("flags", disk.ItemStatus.FromItemStatus(false));
cmpw.WriteEndElement();
break;
@@ -663,6 +666,7 @@ 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);
if (rom.ItemStatus != ItemStatus.None)
cmpw.WriteOptionalAttributeString("flags", rom.ItemStatus.FromItemStatus(false));
cmpw.WriteEndElement();
break;

View File

@@ -1722,6 +1722,7 @@ namespace SabreTools.DatFiles.Formats
xtw.WriteOptionalAttributeString("region", disk.Region);
xtw.WriteOptionalAttributeString("index", disk.Index);
xtw.WriteOptionalAttributeString("writable", disk.Writable.FromYesNo());
if (disk.ItemStatus != ItemStatus.None)
xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false));
xtw.WriteOptionalAttributeString("optional", disk.Optional.FromYesNo());
xtw.WriteEndElement();
@@ -1836,6 +1837,7 @@ namespace SabreTools.DatFiles.Formats
xtw.WriteOptionalAttributeString("merge", rom.MergeTag);
xtw.WriteOptionalAttributeString("region", rom.Region);
xtw.WriteOptionalAttributeString("offset", rom.Offset);
if (rom.ItemStatus != ItemStatus.None)
xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false));
xtw.WriteOptionalAttributeString("optional", rom.Optional.FromYesNo());
xtw.WriteEndElement();
@@ -1871,6 +1873,7 @@ namespace SabreTools.DatFiles.Formats
xtw.WriteStartElement("softwarelist");
xtw.WriteRequiredAttributeString("tag", softwareList.Tag);
xtw.WriteRequiredAttributeString("name", softwareList.Name);
if (softwareList.Status != SoftwareListStatus.None)
xtw.WriteRequiredAttributeString("status", softwareList.Status.FromSoftwareListStatus());
xtw.WriteOptionalAttributeString("filter", softwareList.Filter);
xtw.WriteEndElement();

View File

@@ -983,8 +983,11 @@ namespace SabreTools.DatFiles.Formats
{
xtw.WriteStartElement("clrmamepro");
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);
@@ -1000,8 +1003,11 @@ namespace SabreTools.DatFiles.Formats
xtw.WriteStartElement("romcenter");
xtw.WriteOptionalAttributeString("plugin", Header.System);
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());
@@ -1138,6 +1144,7 @@ namespace SabreTools.DatFiles.Formats
xtw.WriteRequiredAttributeString("name", disk.Name);
xtw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant());
xtw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant());
if (disk.ItemStatus != ItemStatus.None)
xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false));
xtw.WriteEndElement();
break;
@@ -1177,6 +1184,7 @@ namespace SabreTools.DatFiles.Formats
xtw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant());
xtw.WriteOptionalAttributeString("spamsum", rom.SpamSum?.ToLowerInvariant());
xtw.WriteOptionalAttributeString("date", rom.Date);
if (rom.ItemStatus != ItemStatus.None)
xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false));
xtw.WriteOptionalAttributeString("inverted", rom.Inverted.FromYesNo());
xtw.WriteOptionalAttributeString("mia", rom.MIA.FromYesNo());

View File

@@ -883,6 +883,7 @@ namespace SabreTools.DatFiles.Formats
xtw.WriteRequiredAttributeString("name", disk.Name);
xtw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant());
xtw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant());
if (disk.ItemStatus != ItemStatus.None)
xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false));
xtw.WriteOptionalAttributeString("writable", disk.Writable.FromYesNo());
xtw.WriteEndElement();
@@ -940,6 +941,7 @@ namespace SabreTools.DatFiles.Formats
xtw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant());
xtw.WriteOptionalAttributeString("offset", rom.Offset);
xtw.WriteOptionalAttributeString("value", rom.Value);
if (rom.ItemStatus != ItemStatus.None)
xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false));
xtw.WriteOptionalAttributeString("loadflag", rom.LoadFlag.FromLoadFlag());
xtw.WriteEndElement();

View File

@@ -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
}
}