mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add and use DeviceType
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string DeviceType { get; set; }
|
||||
public DeviceType DeviceType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
@@ -45,6 +45,40 @@ namespace SabreTools.Library.DatItems
|
||||
Gambling = 1 << 14,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine the device type
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum DeviceType
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a fake flag that is used for filter only
|
||||
/// </summary>
|
||||
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,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine the display type
|
||||
/// </summary>
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace SabreTools.Library.Filtering
|
||||
public FilterItem<Endianness> DatItem_AreaEndianness { get; private set; } = new FilterItem<Endianness>() { Positive = Endianness.NULL, Negative = Endianness.NULL };
|
||||
|
||||
// Device
|
||||
public FilterItem<string> DatItem_DeviceType { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<DeviceType> DatItem_DeviceType { get; private set; } = new FilterItem<DeviceType>() { Positive = DeviceType.NULL, Negative = DeviceType.NULL };
|
||||
public FilterItem<string> DatItem_FixedImage { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<string> DatItem_Mandatory { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<string> DatItem_Interface { get; private set; } = new FilterItem<string>();
|
||||
@@ -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:
|
||||
|
||||
@@ -242,6 +242,90 @@ namespace SabreTools.Library.Tools
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get DeviceType value from input string
|
||||
/// </summary>
|
||||
/// <param name="deviceType">String to get value from</param>
|
||||
/// <returns>DeviceType value corresponding to the string</returns>
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get DisplayType value from input string
|
||||
/// </summary>
|
||||
@@ -2386,6 +2470,91 @@ namespace SabreTools.Library.Tools
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input DeviceType
|
||||
/// </summary>
|
||||
/// <param name="deviceType">vDeviceType to get value from</param>
|
||||
/// <returns>String value corresponding to the DeviceType</returns>
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input DisplayType
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user