diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs index 4fe5bd7d..b2cb6a31 100644 --- a/SabreTools.Library/DatFiles/Listxml.cs +++ b/SabreTools.Library/DatFiles/Listxml.cs @@ -273,7 +273,7 @@ namespace SabreTools.Library.DatFiles case "device": var device = new Device { - DeviceType = reader.GetAttribute("type"), + DeviceType = reader.GetAttribute("type").AsDeviceType(), Tag = reader.GetAttribute("tag"), FixedImage = reader.GetAttribute("fixed_image"), Mandatory = reader.GetAttribute("mandatory"), @@ -1418,7 +1418,7 @@ namespace SabreTools.Library.DatFiles case ItemType.Device: var device = datItem as Device; xtw.WriteStartElement("device"); - xtw.WriteOptionalAttributeString("type", device.DeviceType); + xtw.WriteOptionalAttributeString("type", device.DeviceType.FromDeviceType()); xtw.WriteOptionalAttributeString("tag", device.Tag); xtw.WriteOptionalAttributeString("fixed_image", device.FixedImage); xtw.WriteOptionalAttributeString("mandatory", device.Mandatory); diff --git a/SabreTools.Library/DatFiles/SabreDat.cs b/SabreTools.Library/DatFiles/SabreDat.cs index d8cb1276..c050ad13 100644 --- a/SabreTools.Library/DatFiles/SabreDat.cs +++ b/SabreTools.Library/DatFiles/SabreDat.cs @@ -1321,7 +1321,7 @@ namespace SabreTools.Library.DatFiles var device = datItem as Device; xtw.WriteStartElement("file"); xtw.WriteAttributeString("type", "device"); - xtw.WriteOptionalAttributeString("type", device.DeviceType); + xtw.WriteOptionalAttributeString("type", device.DeviceType.FromDeviceType()); xtw.WriteOptionalAttributeString("tag", device.Tag); xtw.WriteOptionalAttributeString("fixed_image", device.FixedImage); xtw.WriteOptionalAttributeString("mandatory", device.Mandatory); diff --git a/SabreTools.Library/DatItems/Device.cs b/SabreTools.Library/DatItems/Device.cs index 02f80ed1..0850a991 100644 --- a/SabreTools.Library/DatItems/Device.cs +++ b/SabreTools.Library/DatItems/Device.cs @@ -2,6 +2,7 @@ using System.Linq; using SabreTools.Library.Filtering; +using SabreTools.Library.Tools; using Newtonsoft.Json; namespace SabreTools.Library.DatItems @@ -18,7 +19,7 @@ namespace SabreTools.Library.DatItems /// Device type /// [JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)] - public string DeviceType { get; set; } + public DeviceType DeviceType { get; set; } /// /// Device tag @@ -72,7 +73,7 @@ namespace SabreTools.Library.DatItems // Handle Device-specific fields if (mappings.Keys.Contains(Field.DatItem_DeviceType)) - DeviceType = mappings[Field.DatItem_DeviceType]; + DeviceType = mappings[Field.DatItem_DeviceType].AsDeviceType(); if (mappings.Keys.Contains(Field.DatItem_Tag)) Tag = mappings[Field.DatItem_Tag]; @@ -199,9 +200,9 @@ namespace SabreTools.Library.DatItems return false; // Filter on device type - if (filter.DatItem_DeviceType.MatchesPositiveSet(DeviceType) == false) + if (filter.DatItem_DeviceType.MatchesPositive(DeviceType.NULL, DeviceType) == false) return false; - if (filter.DatItem_DeviceType.MatchesNegativeSet(DeviceType) == true) + if (filter.DatItem_DeviceType.MatchesNegative(DeviceType.NULL, DeviceType) == true) return false; // Filter on tag @@ -262,7 +263,7 @@ namespace SabreTools.Library.DatItems // Remove the fields if (fields.Contains(Field.DatItem_DeviceType)) - DeviceType = null; + DeviceType = DeviceType.NULL; if (fields.Contains(Field.DatItem_Tag)) Tag = null; diff --git a/SabreTools.Library/DatItems/Enums.cs b/SabreTools.Library/DatItems/Enums.cs index 48b51988..18a5217b 100644 --- a/SabreTools.Library/DatItems/Enums.cs +++ b/SabreTools.Library/DatItems/Enums.cs @@ -45,6 +45,40 @@ namespace SabreTools.Library.DatItems Gambling = 1 << 14, } + /// + /// Determine the device type + /// + [Flags] + public enum DeviceType + { + /// + /// This is a fake flag that is used for filter only + /// + NULL = 0, + + Unknown = 1 << 0, + Cartridge = 1 << 1, + FloppyDisk = 1 << 2, + HardDisk = 1 << 3, + Cylinder = 1 << 4, + Cassette = 1 << 5, + PunchCard = 1 << 6, + PunchTape = 1 << 7, + Printout = 1 << 8, + Serial = 1 << 9, + Parallel = 1 << 10, + Snapshot = 1 << 11, + QuickLoad = 1 << 12, + MemCard = 1 << 13, + CDROM = 1 << 14, + MagTape = 1 << 15, + ROMImage = 1 << 16, + MIDIIn = 1 << 17, + MIDIOut = 1 << 18, + Picture = 1 << 19, + VidFile = 1 << 20, + } + /// /// Determine the display type /// diff --git a/SabreTools.Library/Filtering/Filter.cs b/SabreTools.Library/Filtering/Filter.cs index b9482547..13db577a 100644 --- a/SabreTools.Library/Filtering/Filter.cs +++ b/SabreTools.Library/Filtering/Filter.cs @@ -189,7 +189,7 @@ namespace SabreTools.Library.Filtering public FilterItem DatItem_AreaEndianness { get; private set; } = new FilterItem() { Positive = Endianness.NULL, Negative = Endianness.NULL }; // Device - public FilterItem DatItem_DeviceType { get; private set; } = new FilterItem(); + public FilterItem DatItem_DeviceType { get; private set; } = new FilterItem() { Positive = DeviceType.NULL, Negative = DeviceType.NULL }; public FilterItem DatItem_FixedImage { get; private set; } = new FilterItem(); public FilterItem DatItem_Mandatory { get; private set; } = new FilterItem(); public FilterItem DatItem_Interface { get; private set; } = new FilterItem(); @@ -815,7 +815,10 @@ namespace SabreTools.Library.Filtering // Device case Field.DatItem_DeviceType: - SetStringFilter(DatItem_DeviceType, value, negate); + if (negate) + DatItem_DeviceType.Negative |= value.AsDeviceType(); + else + DatItem_DeviceType.Positive |= value.AsDeviceType(); break; case Field.DatItem_FixedImage: diff --git a/SabreTools.Library/Tools/Converters.cs b/SabreTools.Library/Tools/Converters.cs index fc2fc183..b2b465f7 100644 --- a/SabreTools.Library/Tools/Converters.cs +++ b/SabreTools.Library/Tools/Converters.cs @@ -242,6 +242,90 @@ namespace SabreTools.Library.Tools } } + /// + /// Get DeviceType value from input string + /// + /// String to get value from + /// DeviceType value corresponding to the string + public static DeviceType AsDeviceType(this string deviceType) + { +#if NET_FRAMEWORK + switch (deviceType?.ToLowerInvariant()) + { + case "unknown": + return DeviceType.Unknown; + case "cartridge": + return DeviceType.Cartridge; + case "floppydisk": + return DeviceType.FloppyDisk; + case "harddisk": + return DeviceType.HardDisk; + case "cylinder": + return DeviceType.Cylinder; + case "cassette": + return DeviceType.Cassette; + case "punchcard": + return DeviceType.PunchCard; + case "punchtape": + return DeviceType.PunchTape; + case "printout": + return DeviceType.Printout; + case "serial": + return DeviceType.Serial; + case "parallel": + return DeviceType.Parallel; + case "snapshot": + return DeviceType.Snapshot; + case "quickload": + return DeviceType.QuickLoad; + case "memcard": + return DeviceType.MemCard; + case "cdrom": + return DeviceType.CDROM; + case "magtape": + return DeviceType.MagTape; + case "romimage": + return DeviceType.ROMImage; + case "midiin": + return DeviceType.MIDIIn; + case "midiout": + return DeviceType.MIDIOut; + case "picture": + return DeviceType.Picture; + case "vidfile": + return DeviceType.VidFile; + default: + return DeviceType.NULL; + } +#else + return deviceType?.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, + _ => DeviceType.NULL, + }; +#endif + } + /// /// Get DisplayType value from input string /// @@ -2386,6 +2470,91 @@ namespace SabreTools.Library.Tools #endif } + /// + /// Get string value from input DeviceType + /// + /// vDeviceType to get value from + /// String value corresponding to the DeviceType + public static string FromDeviceType(this DeviceType deviceType) + { +#if NET_FRAMEWORK + switch (deviceType) + { + case DeviceType.Unknown: + return "unknown"; + case DeviceType.Cartridge: + return "cartridge"; + case DeviceType.FloppyDisk: + return "floppydisk"; + case DeviceType.HardDisk: + return "harddisk"; + case DeviceType.Cylinder: + return "cylinder"; + case DeviceType.Cassette: + return "cassette"; + case DeviceType.PunchCard: + return "punchcard"; + case DeviceType.PunchTape: + return "punchtape"; + case DeviceType.Printout: + return "printout"; + case DeviceType.Serial: + return "serial"; + case DeviceType.Parallel: + return "parallel"; + case DeviceType.Snapshot: + return "snapshot"; + case DeviceType.QuickLoad: + return "quickload"; + case DeviceType.MemCard: + return "memcard"; + case DeviceType.CDROM: + return "cdrom"; + case DeviceType.MagTape: + return "magtape"; + case DeviceType.ROMImage: + return "romimage"; + case DeviceType.MIDIIn: + return "midiin"; + case DeviceType.MIDIOut: + return "midiout"; + case DeviceType.Picture: + return "picture"; + case DeviceType.VidFile: + return "vidfile"; + default: + return null; + } +#else + 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, + }; +#endif + } + + /// /// Get string value from input DisplayType ///