Add a remaining ListXML-specific objects

Also fixes the usage of some other objects, adds proper objects for certain cases, and adds a bunch of TODOs around the new objects. There will be a lot of overhauls needed to properly support things like Devices and Slots
This commit is contained in:
Matt Nadareski
2020-08-23 15:34:42 -07:00
parent 90f55078d5
commit 2576e22c85
10 changed files with 649 additions and 180 deletions

View File

@@ -539,7 +539,7 @@ namespace SabreTools.Library.DatFiles
machine.SourceFile = jtr.ReadAsString(); machine.SourceFile = jtr.ReadAsString();
break; break;
case "runnable": case "runnable":
machine.Runnable = jtr.ReadAsString().AsYesNo(); machine.Runnable = jtr.ReadAsString().AsRunnable();
break; break;
case "devices": case "devices":
machine.Devices = new List<string>(); machine.Devices = new List<string>();
@@ -568,12 +568,14 @@ namespace SabreTools.Library.DatFiles
if (jtr.TokenType == JsonToken.EndArray) if (jtr.TokenType == JsonToken.EndArray)
break; break;
var info = new ListXmlInfo();
jtr.Read(); // Key jtr.Read(); // Key
string key = jtr.Value as string; info.Name = jtr.Value as string;
string value = jtr.ReadAsString(); info.Value = jtr.ReadAsString();
jtr.Read(); // End object jtr.Read(); // End object
machine.Infos.Add(new ListXmlInfo(key, value)); machine.Infos.Add(info);
} }
break; break;
@@ -663,7 +665,7 @@ namespace SabreTools.Library.DatFiles
break; break;
case "dipswitches": case "dipswitches":
machine.DipSwitches = new List<ListXMLDipSwitch>(); machine.DipSwitches = new List<ListXmlDipSwitch>();
jtr.Read(); // Start Array jtr.Read(); // Start Array
while (!sr.EndOfStream) while (!sr.EndOfStream)
{ {
@@ -678,7 +680,7 @@ namespace SabreTools.Library.DatFiles
jtr.Read(); // Mask Key jtr.Read(); // Mask Key
string mask = jtr.ReadAsString(); string mask = jtr.ReadAsString();
var dipSwitch = new ListXMLDipSwitch(); var dipSwitch = new ListXmlDipSwitch();
dipSwitch.Name = name; dipSwitch.Name = name;
dipSwitch.Tag = tag; dipSwitch.Tag = tag;
dipSwitch.Mask = mask; dipSwitch.Mask = mask;
@@ -698,7 +700,7 @@ namespace SabreTools.Library.DatFiles
bool? def = jtr.ReadAsString().AsYesNo(); bool? def = jtr.ReadAsString().AsYesNo();
jtr.Read(); // End object jtr.Read(); // End object
var dipValue = new ListXMLDipValue(); var dipValue = new ListXmlDipValue();
dipValue.Name = valname; dipValue.Name = valname;
dipValue.Value = value; dipValue.Value = value;
dipValue.Default = def; dipValue.Default = def;
@@ -1706,15 +1708,20 @@ namespace SabreTools.Library.DatFiles
} }
if (!Header.ExcludeFields.Contains(Field.Runnable) && datItem.Machine.Runnable != null) if (!Header.ExcludeFields.Contains(Field.Runnable) && datItem.Machine.Runnable != null)
{ {
if (datItem.Machine.Runnable == true) switch (datItem.Machine.Runnable)
{ {
jtw.WritePropertyName("runnable"); case Runnable.No:
jtw.WriteValue("yes"); jtw.WritePropertyName("runnable");
} jtw.WriteValue("no");
else if (datItem.Machine.Runnable == false) break;
{ case Runnable.Partial:
jtw.WritePropertyName("runnable"); jtw.WritePropertyName("runnable");
jtw.WriteValue("no"); jtw.WriteValue("partial");
break;
case Runnable.Yes:
jtw.WritePropertyName("runnable");
jtw.WriteValue("yes");
break;
} }
} }
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Devices, Header.ExcludeFields))) if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Devices, Header.ExcludeFields)))
@@ -1898,7 +1905,7 @@ namespace SabreTools.Library.DatFiles
jtw.WriteValue(dip.Mask); jtw.WriteValue(dip.Mask);
jtw.WriteStartArray(); jtw.WriteStartArray();
foreach (ListXMLDipValue dipval in dip.Values) foreach (ListXmlDipValue dipval in dip.Values)
{ {
jtw.WriteStartObject(); jtw.WriteStartObject();
jtw.WritePropertyName("name"); jtw.WritePropertyName("name");

View File

@@ -145,7 +145,7 @@ namespace SabreTools.Library.DatFiles
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
Description = reader.GetAttribute("name"), Description = reader.GetAttribute("name"),
SourceFile = reader.GetAttribute("sourcefile"), SourceFile = reader.GetAttribute("sourcefile"),
Runnable = reader.GetAttribute("runnable").AsYesNo(), Runnable = reader.GetAttribute("runnable").AsRunnable(),
Comment = string.Empty, Comment = string.Empty,
@@ -281,9 +281,13 @@ namespace SabreTools.Library.DatFiles
break; break;
case "device_ref": case "device_ref":
string device_ref_name = reader.GetAttribute("name"); // TODO: Use these device references
if (!machine.Devices.Contains(device_ref_name)) var deviceReference = new ListXmlDeviceReference();
machine.Devices.Add(device_ref_name); deviceReference.Name = reader.GetAttribute("name");
// TODO: Retire this direct machine setter
if (!machine.Devices.Contains(deviceReference.Name))
machine.Devices.Add(deviceReference.Name);
reader.Read(); reader.Read();
break; break;
@@ -310,12 +314,9 @@ namespace SabreTools.Library.DatFiles
reader.Read(); reader.Read();
break; break;
// TODO: Should these be new DatItem types?
// TODO: Should any be additional Machine fields?
case "chip": case "chip":
// TODO: Use these chips // TODO: Use these chips
var chip = new ListXMLChip(); var chip = new ListXmlChip();
chip.Name = reader.GetAttribute("name"); chip.Name = reader.GetAttribute("name");
chip.Tag = reader.GetAttribute("tag"); chip.Tag = reader.GetAttribute("tag");
chip.Type = reader.GetAttribute("type"); chip.Type = reader.GetAttribute("type");
@@ -326,7 +327,7 @@ namespace SabreTools.Library.DatFiles
case "display": case "display":
// TODO: Use these displays // TODO: Use these displays
var display = new ListXMLDisplay(); var display = new ListXmlDisplay();
display.Tag = reader.GetAttribute("tag"); display.Tag = reader.GetAttribute("tag");
display.Type = reader.GetAttribute("type"); display.Type = reader.GetAttribute("type");
display.Rotate = reader.GetAttribute("rotate"); display.Rotate = reader.GetAttribute("rotate");
@@ -347,7 +348,7 @@ namespace SabreTools.Library.DatFiles
case "sound": case "sound":
// TODO: Use these sounds // TODO: Use these sounds
var sound = new ListXMLSound(); var sound = new ListXmlSound();
sound.Channels = reader.GetAttribute("channels"); sound.Channels = reader.GetAttribute("channels");
reader.Read(); reader.Read();
@@ -355,7 +356,7 @@ namespace SabreTools.Library.DatFiles
case "condition": case "condition":
// TODO: Use these conditions // TODO: Use these conditions
var condition = new ListXMLCondition(); var condition = new ListXmlCondition();
condition.Tag = reader.GetAttribute("tag"); condition.Tag = reader.GetAttribute("tag");
condition.Mask = reader.GetAttribute("mask"); condition.Mask = reader.GetAttribute("mask");
condition.Relation = reader.GetAttribute("relation"); condition.Relation = reader.GetAttribute("relation");
@@ -366,7 +367,7 @@ namespace SabreTools.Library.DatFiles
case "input": case "input":
// TODO: Use these inputs // TODO: Use these inputs
var input = new ListXMLInput(); var input = new ListXmlInput();
input.Service = reader.GetAttribute("service").AsYesNo(); input.Service = reader.GetAttribute("service").AsYesNo();
input.Tilt = reader.GetAttribute("tilt").AsYesNo(); input.Tilt = reader.GetAttribute("tilt").AsYesNo();
input.Players = reader.GetAttribute("players"); input.Players = reader.GetAttribute("players");
@@ -381,7 +382,7 @@ namespace SabreTools.Library.DatFiles
case "dipswitch": case "dipswitch":
// TODO: Use these dipswitches // TODO: Use these dipswitches
var dipSwitch = new ListXMLDipSwitch(); var dipSwitch = new ListXmlDipSwitch();
dipSwitch.Name = reader.GetAttribute("name"); dipSwitch.Name = reader.GetAttribute("name");
dipSwitch.Tag = reader.GetAttribute("tag"); dipSwitch.Tag = reader.GetAttribute("tag");
dipSwitch.Mask = reader.GetAttribute("mask"); dipSwitch.Mask = reader.GetAttribute("mask");
@@ -394,110 +395,106 @@ namespace SabreTools.Library.DatFiles
break; break;
case "configuration": case "configuration":
// TODO: Make a new object for this // TODO: Use these configurations
// string configuration_name = reader.GetAttribute("name"); var configuration = new ListXmlConfiguration();
// string configuration_tag = reader.GetAttribute("tag"); configuration.Name = reader.GetAttribute("name");
// string configuration_mask = reader.GetAttribute("mask"); configuration.Tag = reader.GetAttribute("tag");
configuration.Mask = reader.GetAttribute("mask");
// // While the subtree contains <conflocation> elements... // Now read the internal tags
// TODO: Make a new object for this ReadConfiguration(reader.ReadSubtree(), configuration);
// string conflocation_name = reader.GetAttribute("name");
// string conflocation_number = reader.GetAttribute("number");
// bool? conflocation_inverted = Utilities.GetYesNo(reader.GetAttribute("inverted"));
// // While the subtree contains <confsetting> elements...
// TODO: Make a new object for this
// string confsetting_name = reader.GetAttribute("name");
// string confsetting_value = reader.GetAttribute("value");
// bool? confsetting_default = Utilities.GetYesNo(reader.GetAttribute("default"));
// Skip the configuration now that we've processed it
reader.Skip(); reader.Skip();
break; break;
case "port": case "port":
// TODO: Make a new object for this // TODO: Use these ports
// string port_tag = reader.GetAttribute("tag"); var port = new ListXmlPort();
port.Tag = reader.GetAttribute("tag");
// // While the subtree contains <analog> elements... // Now read the internal tags
// TODO: Make a new object for this ReadPort(reader.ReadSubtree(), port);
// string analog_mask = reader.GetAttribute("mask");
// Skip the port now that we've processed it
reader.Skip(); reader.Skip();
break; break;
case "adjuster": case "adjuster":
// TODO: Make a new object for this // TODO: Use these adjusters
// string adjuster_name = reader.GetAttribute("name"); var adjuster = new ListXmlAdjuster();
// bool? adjuster_default = Utilities.GetYesNo(reader.GetAttribute("default")); adjuster.Name = reader.GetAttribute("name");
adjuster.Default = reader.GetAttribute("default").AsYesNo();
// // For the one possible <condition> element... // Now read the internal tags
// TODO: Make a new object for this ReadAdjuster(reader.ReadSubtree(), adjuster);
// string condition_tag = reader.GetAttribute("tag");
// string condition_mask = reader.GetAttribute("mask");
// string condition_relation = reader.GetAttribute("relation"); // (eq|ne|gt|le|lt|ge)
// string condition_value = reader.GetAttribute("value");
// Skip the adjuster now that we've processed it
reader.Skip(); reader.Skip();
break; break;
case "driver": case "driver":
// TODO: Make a new object for this // TODO: Use these drivers
// string driver_status = reader.GetAttribute("status"); // (good|imperfect|preliminary) var driver = new ListXmlDriver();
// string driver_emulation = reader.GetAttribute("emulation"); // (good|imperfect|preliminary) driver.Status = reader.GetAttribute("status");
// string driver_cocktail = reader.GetAttribute("cocktail"); // (good|imperfect|preliminary) driver.Emulation = reader.GetAttribute("emulation");
// string driver_savestate = reader.GetAttribute("savestate"); // (supported|unsupported) driver.Cocktail = reader.GetAttribute("cocktail");
driver.SaveState = reader.GetAttribute("savestate");
reader.Read(); reader.Read();
break; break;
case "feature": case "feature":
// TODO: Make a new object for this // TODO: Use these features
// string feature_type = reader.GetAttribute("type"); // (protection|palette|graphics|sound|controls|keyboard|mouse|microphone|camera|disk|printer|lan|wan|timing) var feature = new ListXmlFeature();
// string feature_status = reader.GetAttribute("status"); // (unemulated|imperfect) feature.Type = reader.GetAttribute("type");
// string feature_overall = reader.GetAttribute("overall"); // (unemulated|imperfect) feature.Status = reader.GetAttribute("status");
feature.Overall = reader.GetAttribute("overall");
reader.Read(); reader.Read();
break; break;
case "device": case "device":
// TODO: Make a new object for this // TODO: Use these devices
// string device_type = reader.GetAttribute("type"); var device = new ListXmlDevice();
// string device_tag = reader.GetAttribute("tag"); device.Type = reader.GetAttribute("type");
// string device_fixed_image = reader.GetAttribute("fixed_image"); device.Tag = reader.GetAttribute("tag");
// string device_mandatory = reader.GetAttribute("mandatory"); device.FixedImage = reader.GetAttribute("fixed_image");
// string device_interface = reader.GetAttribute("interface"); device.Mandatory = reader.GetAttribute("mandatory");
device.Interface = reader.GetAttribute("interface");
// // For the one possible <instance> element... // Now read the internal tags
// TODO: Make a new object for this ReadDevice(reader.ReadSubtree(), device);
// string instance_name = reader.GetAttribute("name");
// string instance_briefname = reader.GetAttribute("briefname");
// // While the subtree contains <extension> elements...
// TODO: Make a new object for this
// string extension_name = reader.GetAttribute("name");
// Skip the device now that we've processed it
reader.Skip(); reader.Skip();
break; break;
case "slot": case "slot":
// string slot_name = reader.GetAttribute("name"); // TODO: Use these slots
ReadSlot(reader.ReadSubtree(), machine); var slot = new ListXmlSlot();
slot.Name = reader.GetAttribute("name");
// Now read the internal tags
ReadSlot(reader.ReadSubtree(), slot, machine);
// Skip the slot now that we've processed it // Skip the slot now that we've processed it
reader.Skip(); reader.Skip();
break; break;
case "softwarelist": case "softwarelist":
// TODO: Make a new object for this // TODO: Use these softwarelists
// string softwarelist_name = reader.GetAttribute("name"); var softwareList = new ListXmlSoftwareList();
// string softwarelist_status = reader.GetAttribute("status"); // (original|compatible) softwareList.Name = reader.GetAttribute("name");
// string softwarelist_filter = reader.GetAttribute("filter"); softwareList.Status = reader.GetAttribute("status");
softwareList.Filter = reader.GetAttribute("filter");
reader.Read(); reader.Read();
break; break;
case "ramoption": case "ramoption":
// TODO: Make a new object for this // TODO: Use these ramoptions
// string ramoption_default = reader.GetAttribute("default"); var ramOption = new ListXmlRamOption();
ramOption.Default = reader.GetAttribute("default").AsYesNo();
reader.Read(); reader.Read();
break; break;
@@ -531,13 +528,17 @@ namespace SabreTools.Library.DatFiles
/// Read slot information /// Read slot information
/// </summary> /// </summary>
/// <param name="reader">XmlReader representing a machine block</param> /// <param name="reader">XmlReader representing a machine block</param>
/// <param name="slot">ListXmlSlot to populate</param>
/// <param name="machine">Machine information to pass to contained items</param> /// <param name="machine">Machine information to pass to contained items</param>
private void ReadSlot(XmlReader reader, Machine machine) private void ReadSlot(XmlReader reader, ListXmlSlot slot, Machine machine)
{ {
// If we have an empty machine, skip it // If we have an empty machine, skip it
if (reader == null) if (reader == null)
return; return;
// Get list ready
slot.SlotOptions = new List<ListXmlSlotOption>();
// Otherwise, add what is possible // Otherwise, add what is possible
reader.MoveToContent(); reader.MoveToContent();
@@ -554,13 +555,17 @@ namespace SabreTools.Library.DatFiles
switch (reader.Name) switch (reader.Name)
{ {
case "slotoption": case "slotoption":
// string slotoption_name = reader.GetAttribute("name"); var slotOption = new ListXmlSlotOption();
string devname = reader.GetAttribute("devname"); slotOption.Name = reader.GetAttribute("name");
if (!machine.SlotOptions.Contains(devname)) slotOption.DeviceName = reader.GetAttribute("devname");
{ slotOption.Default = reader.GetAttribute("default").AsYesNo();
machine.SlotOptions.Add(devname);
} // TODO: Retire this direct machine setter
// bool? slotoption_default = Utilities.GetYesNo(reader.GetAttribute("default")); if (!machine.SlotOptions.Contains(slotOption.DeviceName))
machine.SlotOptions.Add(slotOption.DeviceName);
slot.SlotOptions.Add(slotOption);
reader.Read(); reader.Read();
break; break;
@@ -575,15 +580,15 @@ namespace SabreTools.Library.DatFiles
/// Read Input information /// Read Input information
/// </summary> /// </summary>
/// <param name="reader">XmlReader representing a diskarea block</param> /// <param name="reader">XmlReader representing a diskarea block</param>
/// <param name="input">ListXMLInput to populate</param> /// <param name="input">ListXmlInput to populate</param>
private void ReadInput(XmlReader reader, ListXMLInput input) private void ReadInput(XmlReader reader, ListXmlInput input)
{ {
// If we have an empty trurip, skip it // If we have an empty input, skip it
if (reader == null) if (reader == null)
return; return;
// Get list ready // Get list ready
input.Controls = new List<ListXMLControl>(); input.Controls = new List<ListXmlControl>();
// Otherwise, add what is possible // Otherwise, add what is possible
reader.MoveToContent(); reader.MoveToContent();
@@ -601,7 +606,7 @@ namespace SabreTools.Library.DatFiles
switch (reader.Name) switch (reader.Name)
{ {
case "control": case "control":
var control = new ListXMLControl(); var control = new ListXmlControl();
control.Type = reader.GetAttribute("type"); control.Type = reader.GetAttribute("type");
control.Player = reader.GetAttribute("player"); control.Player = reader.GetAttribute("player");
control.Buttons = reader.GetAttribute("buttons"); control.Buttons = reader.GetAttribute("buttons");
@@ -631,16 +636,16 @@ namespace SabreTools.Library.DatFiles
/// Read DipSwitch information /// Read DipSwitch information
/// </summary> /// </summary>
/// <param name="reader">XmlReader representing a diskarea block</param> /// <param name="reader">XmlReader representing a diskarea block</param>
/// <param name="dipSwitch">ListXMLDipSwitch to populate</param> /// <param name="dipSwitch">ListXmlDipSwitch to populate</param>
private void ReadDipSwitch(XmlReader reader, ListXMLDipSwitch dipSwitch) private void ReadDipSwitch(XmlReader reader, ListXmlDipSwitch dipSwitch)
{ {
// If we have an empty trurip, skip it // If we have an empty dipswitch, skip it
if (reader == null) if (reader == null)
return; return;
// Get lists ready // Get lists ready
dipSwitch.Locations = new List<ListXMLDipLocation>(); dipSwitch.Locations = new List<ListXmlDipLocation>();
dipSwitch.Values = new List<ListXMLDipValue>(); dipSwitch.Values = new List<ListXmlDipValue>();
// Otherwise, add what is possible // Otherwise, add what is possible
reader.MoveToContent(); reader.MoveToContent();
@@ -658,7 +663,7 @@ namespace SabreTools.Library.DatFiles
switch (reader.Name) switch (reader.Name)
{ {
case "diplocation": case "diplocation":
var dipLocation = new ListXMLDipLocation(); var dipLocation = new ListXmlDipLocation();
dipLocation.Name = reader.GetAttribute("name"); dipLocation.Name = reader.GetAttribute("name");
dipLocation.Number = reader.GetAttribute("number"); dipLocation.Number = reader.GetAttribute("number");
dipLocation.Inverted = reader.GetAttribute("inverted").AsYesNo(); dipLocation.Inverted = reader.GetAttribute("inverted").AsYesNo();
@@ -669,7 +674,7 @@ namespace SabreTools.Library.DatFiles
break; break;
case "dipvalue": case "dipvalue":
var dipValue = new ListXMLDipValue(); var dipValue = new ListXmlDipValue();
dipValue.Name = reader.GetAttribute("name"); dipValue.Name = reader.GetAttribute("name");
dipValue.Value = reader.GetAttribute("value"); dipValue.Value = reader.GetAttribute("value");
dipValue.Default = reader.GetAttribute("default").AsYesNo(); dipValue.Default = reader.GetAttribute("default").AsYesNo();
@@ -686,6 +691,214 @@ namespace SabreTools.Library.DatFiles
} }
} }
/// <summary>
/// Read Configuration information
/// </summary>
/// <param name="reader">XmlReader representing a diskarea block</param>
/// <param name="configuration">ListXmlConfiguration to populate</param>
private void ReadConfiguration(XmlReader reader, ListXmlConfiguration configuration)
{
// If we have an empty configuration, skip it
if (reader == null)
return;
// Get lists ready
configuration.Locations = new List<ListXmlConfLocation>();
configuration.Settings = new List<ListXmlConfSetting>();
// Otherwise, add what is possible
reader.MoveToContent();
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get the information from the dipswitch
switch (reader.Name)
{
case "conflocation":
var confLocation = new ListXmlConfLocation();
confLocation.Name = reader.GetAttribute("name");
confLocation.Number = reader.GetAttribute("number");
confLocation.Inverted = reader.GetAttribute("inverted").AsYesNo();
configuration.Locations.Add(confLocation);
reader.Read();
break;
case "confsetting":
var confSetting = new ListXmlConfSetting();
confSetting.Name = reader.GetAttribute("name");
confSetting.Value = reader.GetAttribute("value");
confSetting.Default = reader.GetAttribute("default").AsYesNo();
configuration.Settings.Add(confSetting);
reader.Read();
break;
default:
reader.Read();
break;
}
}
}
/// <summary>
/// Read Port information
/// </summary>
/// <param name="reader">XmlReader representing a diskarea block</param>
/// <param name="port">ListXmlPort to populate</param>
private void ReadPort(XmlReader reader, ListXmlPort port)
{
// If we have an empty port, skip it
if (reader == null)
return;
// Get list ready
port.Analogs = new List<ListXmlAnalog>();
// Otherwise, add what is possible
reader.MoveToContent();
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get the information from the port
switch (reader.Name)
{
case "analog":
var analog = new ListXmlAnalog();
analog.Mask = reader.GetAttribute("mask");
port.Analogs.Add(analog);
reader.Read();
break;
default:
reader.Read();
break;
}
}
}
/// <summary>
/// Read Adjuster information
/// </summary>
/// <param name="reader">XmlReader representing a diskarea block</param>
/// <param name="adjuster">ListXmlAdjuster to populate</param>
private void ReadAdjuster(XmlReader reader, ListXmlAdjuster adjuster)
{
// If we have an empty port, skip it
if (reader == null)
return;
// Get list ready
adjuster.Conditions = new List<ListXmlCondition>();
// Otherwise, add what is possible
reader.MoveToContent();
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get the information from the adjuster
switch (reader.Name)
{
case "condition":
var condition = new ListXmlCondition();
condition.Tag = reader.GetAttribute("tag");
condition.Mask = reader.GetAttribute("mask");
condition.Relation = reader.GetAttribute("relation");
condition.Value = reader.GetAttribute("value");
adjuster.Conditions.Add(condition);
reader.Read();
break;
default:
reader.Read();
break;
}
}
}
/// <summary>
/// Read Device information
/// </summary>
/// <param name="reader">XmlReader representing a diskarea block</param>
/// <param name="device">ListXmlDevice to populate</param>
private void ReadDevice(XmlReader reader, ListXmlDevice device)
{
// If we have an empty port, skip it
if (reader == null)
return;
// Get lists ready
device.Instances = new List<ListXmlInstance>();
device.Extensions = new List<ListXmlExtension>();
// Otherwise, add what is possible
reader.MoveToContent();
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get the information from the adjuster
switch (reader.Name)
{
case "instance":
var instance = new ListXmlInstance();
instance.Name = reader.GetAttribute("name");
instance.BriefName = reader.GetAttribute("briefname");
device.Instances.Add(instance);
reader.Read();
break;
case "extension":
var extension = new ListXmlExtension();
extension.Name = reader.GetAttribute("name");
device.Extensions.Add(extension);
reader.Read();
break;
default:
reader.Read();
break;
}
}
}
/// <summary> /// <summary>
/// Create and open an output file for writing direct from a dictionary /// Create and open an output file for writing direct from a dictionary
/// </summary> /// </summary>
@@ -852,10 +1065,18 @@ namespace SabreTools.Library.DatFiles
if (!Header.ExcludeFields.Contains(Field.Runnable)) if (!Header.ExcludeFields.Contains(Field.Runnable))
{ {
if (datItem.Machine.Runnable == true) switch (datItem.Machine.Runnable)
xtw.WriteAttributeString("runnable", "yes"); {
else if (datItem.Machine.Runnable == false) case Runnable.No:
xtw.WriteAttributeString("runnable", "no"); xtw.WriteAttributeString("runnable", "no");
break;
case Runnable.Partial:
xtw.WriteAttributeString("runnable", "partial");
break;
case Runnable.Yes:
xtw.WriteAttributeString("runnable", "yes");
break;
}
} }
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase)) if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase))

View File

@@ -313,7 +313,7 @@ namespace SabreTools.Library.DatFiles
SourceFile = reader.GetAttribute("sourcefile"), SourceFile = reader.GetAttribute("sourcefile"),
Board = reader.GetAttribute("board"), Board = reader.GetAttribute("board"),
RebuildTo = reader.GetAttribute("rebuildto"), RebuildTo = reader.GetAttribute("rebuildto"),
Runnable = reader.GetAttribute("runnable").AsYesNo(), // Listxml-specific, used by older DATs Runnable = reader.GetAttribute("runnable").AsRunnable(), // Used by older DATs
Comment = string.Empty, Comment = string.Empty,
@@ -982,10 +982,18 @@ namespace SabreTools.Library.DatFiles
if (!Header.ExcludeFields.Contains(Field.Runnable) && datItem.Machine.Runnable != null) if (!Header.ExcludeFields.Contains(Field.Runnable) && datItem.Machine.Runnable != null)
{ {
if (datItem.Machine.Runnable == true) switch (datItem.Machine.Runnable)
xtw.WriteAttributeString("runnable", "yes"); {
else if (datItem.Machine.Runnable == false) case Runnable.No:
xtw.WriteAttributeString("runnable", "no"); xtw.WriteAttributeString("runnable", "no");
break;
case Runnable.Partial:
xtw.WriteAttributeString("runnable", "partial");
break;
case Runnable.Yes:
xtw.WriteAttributeString("runnable", "yes");
break;
}
} }
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase)) if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase))

View File

@@ -376,7 +376,7 @@ namespace SabreTools.Library.DatFiles
break; break;
case "Machine.Runnable": case "Machine.Runnable":
machine.Runnable = value.AsYesNo(); machine.Runnable = value.AsRunnable();
break; break;
case "Machine.Devices": case "Machine.Devices":
@@ -405,7 +405,12 @@ namespace SabreTools.Library.DatFiles
foreach (var info in infos) foreach (var info in infos)
{ {
var infoPair = info.Split('='); var infoPair = info.Split('=');
machine.Infos.Add(new ListXmlInfo(infoPair[0], infoPair[1]));
var infoObj = new ListXmlInfo();
infoObj.Name = infoPair[0];
infoObj.Value = infoPair[1];
machine.Infos.Add(infoObj);
} }
break; break;
@@ -498,7 +503,7 @@ namespace SabreTools.Library.DatFiles
break; break;
case "Machine.DipSwitches": case "Machine.DipSwitches":
machine.DipSwitches = new List<ListXMLDipSwitch>(); machine.DipSwitches = new List<ListXmlDipSwitch>();
// TODO: There is no way this would work... Just use empty for now // TODO: There is no way this would work... Just use empty for now
break; break;

View File

@@ -147,7 +147,7 @@ namespace SabreTools.Library.DatFiles
CloneOf = reader.GetAttribute("cloneof") ?? string.Empty, CloneOf = reader.GetAttribute("cloneof") ?? string.Empty,
Infos = new List<ListXmlInfo>(), Infos = new List<ListXmlInfo>(),
SharedFeatures = new List<SoftwareListSharedFeature>(), SharedFeatures = new List<SoftwareListSharedFeature>(),
DipSwitches = new List<ListXMLDipSwitch>(), DipSwitches = new List<ListXmlDipSwitch>(),
MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType), MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType),
}; };
@@ -181,7 +181,12 @@ namespace SabreTools.Library.DatFiles
break; break;
case "info": case "info":
machine.Infos.Add(new ListXmlInfo(reader.GetAttribute("name"), reader.GetAttribute("value"))); var info = new ListXmlInfo();
info.Name = reader.GetAttribute("name");
info.Value = reader.GetAttribute("value");
machine.Infos.Add(info);
reader.Read(); reader.Read();
break; break;
@@ -248,7 +253,6 @@ namespace SabreTools.Library.DatFiles
areaEndinaness; areaEndinaness;
long? areasize = null; long? areasize = null;
var features = new List<SoftwareListFeature>(); var features = new List<SoftwareListFeature>();
var dipswitches = new List<ListXMLDipSwitch>();
bool containsItems = false; bool containsItems = false;
while (!reader.EOF) while (!reader.EOF)
@@ -334,7 +338,7 @@ namespace SabreTools.Library.DatFiles
case "dipswitch": case "dipswitch":
// TODO: Use these dipswitches // TODO: Use these dipswitches
var dipSwitch = new ListXMLDipSwitch(); var dipSwitch = new ListXmlDipSwitch();
dipSwitch.Name = reader.GetAttribute("name"); dipSwitch.Name = reader.GetAttribute("name");
dipSwitch.Tag = reader.GetAttribute("tag"); dipSwitch.Tag = reader.GetAttribute("tag");
dipSwitch.Mask = reader.GetAttribute("mask"); dipSwitch.Mask = reader.GetAttribute("mask");
@@ -570,14 +574,14 @@ namespace SabreTools.Library.DatFiles
/// </summary> /// </summary>
/// <param name="reader">XmlReader representing a diskarea block</param> /// <param name="reader">XmlReader representing a diskarea block</param>
/// <param name="dipSwitch">ListXMLDipSwitch to populate</param> /// <param name="dipSwitch">ListXMLDipSwitch to populate</param>
private void ReadDipSwitch(XmlReader reader, ListXMLDipSwitch dipSwitch) private void ReadDipSwitch(XmlReader reader, ListXmlDipSwitch dipSwitch)
{ {
// If we have an empty trurip, skip it // If we have an empty dipswitch, skip it
if (reader == null) if (reader == null)
return; return;
// Get list ready // Get list ready
dipSwitch.Values = new List<ListXMLDipValue>(); dipSwitch.Values = new List<ListXmlDipValue>();
// Otherwise, add what is possible // Otherwise, add what is possible
reader.MoveToContent(); reader.MoveToContent();
@@ -595,7 +599,7 @@ namespace SabreTools.Library.DatFiles
switch (reader.Name) switch (reader.Name)
{ {
case "dipvalue": case "dipvalue":
var dipValue = new ListXMLDipValue(); var dipValue = new ListXmlDipValue();
dipValue.Name = reader.GetAttribute("name"); dipValue.Name = reader.GetAttribute("name");
dipValue.Value = reader.GetAttribute("value"); dipValue.Value = reader.GetAttribute("value");
dipValue.Default = reader.GetAttribute("default").AsYesNo(); dipValue.Default = reader.GetAttribute("default").AsYesNo();
@@ -842,14 +846,14 @@ namespace SabreTools.Library.DatFiles
if (!Header.ExcludeFields.Contains(Field.DipSwitches) && datItem.Machine.DipSwitches != null && datItem.Machine.DipSwitches.Count > 0) if (!Header.ExcludeFields.Contains(Field.DipSwitches) && datItem.Machine.DipSwitches != null && datItem.Machine.DipSwitches.Count > 0)
{ {
foreach (ListXMLDipSwitch dip in datItem.Machine.DipSwitches) foreach (ListXmlDipSwitch dip in datItem.Machine.DipSwitches)
{ {
xtw.WriteStartElement("dipswitch"); xtw.WriteStartElement("dipswitch");
xtw.WriteAttributeString("name", dip.Name); xtw.WriteAttributeString("name", dip.Name);
xtw.WriteAttributeString("tag", dip.Tag); xtw.WriteAttributeString("tag", dip.Tag);
xtw.WriteAttributeString("mask", dip.Mask); xtw.WriteAttributeString("mask", dip.Mask);
foreach (ListXMLDipValue dipval in dip.Values) foreach (ListXmlDipValue dipval in dip.Values)
{ {
xtw.WriteStartElement("dipvalue"); xtw.WriteStartElement("dipvalue");
xtw.WriteAttributeString("name", dipval.Name); xtw.WriteAttributeString("name", dipval.Name);

View File

@@ -10,41 +10,32 @@ namespace SabreTools.Library.DatItems
#region ListXML #region ListXML
/// <summary> /// <summary>
/// Represents one ListXML info object /// Represents one ListXML adjuster
/// </summary> /// </summary>
public class ListXmlInfo public class ListXmlAdjuster
{ {
public string Name { get; set; } public string Name { get; set; }
public string Value { get; set; } public bool? Default { get; set; }
public List<ListXmlCondition> Conditions { get; set; }
public ListXmlInfo(string name, string value) public ListXmlAdjuster()
{ {
Name = name; Conditions = new List<ListXmlCondition>();
Value = value;
} }
} }
#endregion
#region OpenMSX
/// <summary> /// <summary>
/// Represents the OpenMSX original value /// Represents one ListXML analog
/// </summary> /// </summary>
public class OpenMSXOriginal public class ListXmlAnalog
{ {
public string Name { get; set; } public string Mask { get; set; }
public bool? Value { get; set; }
} }
#endregion
#region ListXML
/// <summary> /// <summary>
/// Represents one ListXML chip /// Represents one ListXML chip
/// </summary> /// </summary>
public class ListXMLChip public class ListXmlChip
{ {
public string Name { get; set; } public string Name { get; set; }
public string Tag { get; set; } public string Tag { get; set; }
@@ -55,7 +46,7 @@ namespace SabreTools.Library.DatItems
/// <summary> /// <summary>
/// Represents one ListXML condition /// Represents one ListXML condition
/// </summary> /// </summary>
public class ListXMLCondition public class ListXmlCondition
{ {
public string Tag { get; set; } public string Tag { get; set; }
public string Mask { get; set; } public string Mask { get; set; }
@@ -63,10 +54,48 @@ namespace SabreTools.Library.DatItems
public string Value { get; set; } public string Value { get; set; }
} }
/// <summary>
/// Represents one ListXML configuration
/// </summary>
public class ListXmlConfiguration
{
public string Name { get; set; }
public string Tag { get; set; }
public string Mask { get; set; }
public List<ListXmlConfLocation> Locations { get; set; }
public List<ListXmlConfSetting> Settings { get; set; }
public ListXmlConfiguration()
{
Locations = new List<ListXmlConfLocation>();
Settings = new List<ListXmlConfSetting>();
}
}
/// <summary>
/// Represents one ListXML conflocation
/// </summary>
public class ListXmlConfLocation
{
public string Name { get; set; }
public string Number { get; set; }
public bool? Inverted { get; set; }
}
/// <summary>
/// Represents one ListXML confsetting
/// </summary>
public class ListXmlConfSetting
{
public string Name { get; set; }
public string Value { get; set; }
public bool? Default { get; set; }
}
/// <summary> /// <summary>
/// Represents one ListXML control /// Represents one ListXML control
/// </summary> /// </summary>
public class ListXMLControl public class ListXmlControl
{ {
public string Type { get; set; } public string Type { get; set; }
public string Player { get; set; } // TODO: Int32? public string Player { get; set; } // TODO: Int32?
@@ -82,10 +111,38 @@ namespace SabreTools.Library.DatItems
public string Ways3 { get; set; } // TODO: Int32? Float? public string Ways3 { get; set; } // TODO: Int32? Float?
} }
/// <summary>
/// Represents one ListXML device
/// </summary>
public class ListXmlDevice
{
public string Type { get; set; }
public string Tag { get; set; }
public string FixedImage { get; set; }
public string Mandatory { get; set; } // TODO: bool?
public string Interface { get; set; }
public List<ListXmlInstance> Instances { get; set; }
public List<ListXmlExtension> Extensions { get; set; }
public ListXmlDevice()
{
Instances = new List<ListXmlInstance>();
Extensions = new List<ListXmlExtension>();
}
}
/// <summary>
/// Represents one ListXML deviceref
/// </summary>
public class ListXmlDeviceReference
{
public string Name { get; set; }
}
/// <summary> /// <summary>
/// Represents one ListXML display /// Represents one ListXML display
/// </summary> /// </summary>
public class ListXMLDisplay public class ListXmlDisplay
{ {
public string Tag { get; set; } public string Tag { get; set; }
public string Type { get; set; } // TODO: (raster|vector|lcd|svg|unknown) public string Type { get; set; } // TODO: (raster|vector|lcd|svg|unknown)
@@ -107,25 +164,25 @@ namespace SabreTools.Library.DatItems
/// Represents one ListXML dipswitch /// Represents one ListXML dipswitch
/// </summary> /// </summary>
/// <remarks>Also used by SoftwareList</remarks> /// <remarks>Also used by SoftwareList</remarks>
public class ListXMLDipSwitch public class ListXmlDipSwitch
{ {
public string Name { get; set; } public string Name { get; set; }
public string Tag { get; set; } public string Tag { get; set; }
public string Mask { get; set; } public string Mask { get; set; }
public List<ListXMLDipLocation> Locations { get; set; } public List<ListXmlDipLocation> Locations { get; set; }
public List<ListXMLDipValue> Values { get; set; } public List<ListXmlDipValue> Values { get; set; }
public ListXMLDipSwitch() public ListXmlDipSwitch()
{ {
Locations = new List<ListXMLDipLocation>(); Locations = new List<ListXmlDipLocation>();
Values = new List<ListXMLDipValue>(); Values = new List<ListXmlDipValue>();
} }
} }
/// <summary> /// <summary>
/// Represents one ListXML diplocation /// Represents one ListXML diplocation
/// </summary> /// </summary>
public class ListXMLDipLocation public class ListXmlDipLocation
{ {
public string Name { get; set; } public string Name { get; set; }
public string Number { get; set; } public string Number { get; set; }
@@ -136,40 +193,156 @@ namespace SabreTools.Library.DatItems
/// Represents one ListXML dipvalue /// Represents one ListXML dipvalue
/// </summary> /// </summary>
/// <remarks>Also used by SoftwareList</remarks> /// <remarks>Also used by SoftwareList</remarks>
public class ListXMLDipValue public class ListXmlDipValue
{ {
public string Name { get; set; } public string Name { get; set; }
public string Value { get; set; } public string Value { get; set; }
public bool? Default { get; set; } public bool? Default { get; set; }
} }
/// <summary>
/// Represents one ListXML driver
/// </summary>
public class ListXmlDriver
{
public string Status { get; set; } // TODO: (good|imperfect|preliminary)
public string Emulation { get; set; } // TODO: (good|imperfect|preliminary)
public string Cocktail { get; set; } // TODO: bool? (good|imperfect|preliminary)?
public string SaveState { get; set; } // TODO: (supported|unsupported)
}
/// <summary>
/// Represents one ListXML extension
/// </summary>
public class ListXmlExtension
{
public string Name { get; set; }
}
/// <summary>
/// Represents one ListXML feature
/// </summary>
public class ListXmlFeature
{
public string Type { get; set; } // TODO: (protection|palette|graphics|sound|controls|keyboard|mouse|microphone|camera|disk|printer|lan|wan|timing)
public string Status { get; set; } // TODO: (unemulated|imperfect)
public string Overall { get; set; } // TODO: (unemulated|imperfect)
}
/// <summary>
/// Represents one ListXML info
/// </summary>
public class ListXmlInfo
{
public string Name { get; set; }
public string Value { get; set; }
}
/// <summary> /// <summary>
/// Represents one ListXML input /// Represents one ListXML input
/// </summary> /// </summary>
public class ListXMLInput public class ListXmlInput
{ {
public bool? Service { get; set; } public bool? Service { get; set; }
public bool? Tilt { get; set; } public bool? Tilt { get; set; }
public string Players { get; set; } // TODO: Int32? public string Players { get; set; } // TODO: Int32?
public string Coins { get; set; } // TODO: Int32? public string Coins { get; set; } // TODO: Int32?
public List<ListXMLControl> Controls { get; set; } public List<ListXmlControl> Controls { get; set; }
public ListXMLInput() public ListXmlInput()
{ {
Controls = new List<ListXMLControl>(); Controls = new List<ListXmlControl>();
} }
} }
/// <summary>
/// Represents one ListXML instance
/// </summary>
public class ListXmlInstance
{
public string Name { get; set; }
public string BriefName { get; set; }
}
/// <summary>
/// Represents one ListXML port
/// </summary>
public class ListXmlPort
{
public string Tag { get; set; }
public List<ListXmlAnalog> Analogs { get; set; }
public ListXmlPort()
{
Analogs = new List<ListXmlAnalog>();
}
}
/// <summary>
/// Represents one ListXML ramoption
/// </summary>
public class ListXmlRamOption
{
public bool? Default { get; set; }
}
/// <summary>
/// Represents one ListXML slot
/// </summary>
public class ListXmlSlot
{
public string Name { get; set; }
public List<ListXmlSlotOption> SlotOptions { get; set; }
public ListXmlSlot()
{
SlotOptions = new List<ListXmlSlotOption>();
}
}
/// <summary>
/// Represents one ListXML slotoption
/// </summary>
public class ListXmlSlotOption
{
public string Name { get; set; }
public string DeviceName { get; set; }
public bool? Default { get; set; }
}
/// <summary>
/// Represents one ListXML softwarelist
/// </summary>
public class ListXmlSoftwareList
{
public string Name { get; set; }
public string Status { get; set; } // TODO: (original|compatible)
public string Filter { get; set; }
}
/// <summary> /// <summary>
/// Represents one ListXML sound /// Represents one ListXML sound
/// </summary> /// </summary>
public class ListXMLSound public class ListXmlSound
{ {
public string Channels { get; set; } // TODO: Int32? public string Channels { get; set; } // TODO: Int32?
} }
#endregion #endregion
#region OpenMSX
/// <summary>
/// Represents the OpenMSX original value
/// </summary>
public class OpenMSXOriginal
{
public string Name { get; set; }
public bool? Value { get; set; }
}
#endregion
#region SoftwareList #region SoftwareList
/// <summary> /// <summary>

View File

@@ -241,6 +241,18 @@ namespace SabreTools.Library.DatItems
Mechanical = 1 << 3, Mechanical = 1 << 3,
} }
/// <summary>
/// Determine machine runnable status
/// </summary>
[Flags]
public enum Runnable
{
NULL,
No,
Partial,
Yes,
}
/// <summary> /// <summary>
/// Determine machine support status /// Determine machine support status
/// </summary> /// </summary>

View File

@@ -145,20 +145,21 @@ namespace SabreTools.Library.DatItems
/// <summary> /// <summary>
/// Machine runnable status /// Machine runnable status
/// </summary> /// </summary>
/// <remarks>yes = true, partial = null, no = false</remarks>
/// <remarks>Also in Logiqx</remarks> /// <remarks>Also in Logiqx</remarks>
[JsonProperty("runnable")] [JsonProperty("runnable")]
public bool? Runnable { get; set; } = null; public Runnable Runnable { get; set; } = Runnable.NULL;
/// <summary> /// <summary>
/// List of associated device names /// List of associated device names
/// </summary> /// </summary>
/// TODO: Use ListXmlDeviceReference for this...
[JsonProperty("devices")] [JsonProperty("devices")]
public List<string> Devices { get; set; } = null; public List<string> Devices { get; set; } = null;
/// <summary> /// <summary>
/// List of slot options /// List of slot options
/// </summary> /// </summary>
/// TODO: Use ListXmlSlot for this...
[JsonProperty("slotoptions")] [JsonProperty("slotoptions")]
public List<string> SlotOptions { get; set; } = null; public List<string> SlotOptions { get; set; } = null;
@@ -285,8 +286,10 @@ namespace SabreTools.Library.DatItems
/// List of shared feature items /// List of shared feature items
/// </summary> /// </summary>
/// <remarks>Also in SoftwareList</remarks> /// <remarks>Also in SoftwareList</remarks>
/// TODO: Move to ListXML section
/// TODO: Order ListXML and SoftwareList outputs by area names
[JsonProperty("dipswitches")] [JsonProperty("dipswitches")]
public List<ListXMLDipSwitch> DipSwitches { get; set; } = null; public List<ListXmlDipSwitch> DipSwitches { get; set; } = null;
#endregion #endregion
@@ -376,7 +379,7 @@ namespace SabreTools.Library.DatItems
fieldValue = SourceFile; fieldValue = SourceFile;
break; break;
case Field.Runnable: case Field.Runnable:
fieldValue = Runnable?.ToString(); fieldValue = Runnable.ToString();
break; break;
case Field.Devices: case Field.Devices:
fieldValue = string.Join(";", Devices ?? new List<string>()); fieldValue = string.Join(";", Devices ?? new List<string>());
@@ -547,7 +550,7 @@ namespace SabreTools.Library.DatItems
SourceFile = mappings[Field.SourceFile]; SourceFile = mappings[Field.SourceFile];
if (mappings.Keys.Contains(Field.Runnable)) if (mappings.Keys.Contains(Field.Runnable))
Runnable = mappings[Field.Runnable].AsYesNo(); Runnable = mappings[Field.Runnable].AsRunnable();
if (mappings.Keys.Contains(Field.Devices)) if (mappings.Keys.Contains(Field.Devices))
{ {
@@ -576,7 +579,12 @@ namespace SabreTools.Library.DatItems
foreach (string pair in pairs) foreach (string pair in pairs)
{ {
string[] split = pair.Split('='); string[] split = pair.Split('=');
Infos.Add(new ListXmlInfo(split[0], split[1]));
var infoObj = new ListXmlInfo();
infoObj.Name = split[0];
infoObj.Value = split[1];
Infos.Add(infoObj);
} }
} }
@@ -657,7 +665,7 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.DipSwitches)) if (mappings.Keys.Contains(Field.DipSwitches))
{ {
if (DipSwitches == null) if (DipSwitches == null)
DipSwitches = new List<ListXMLDipSwitch>(); DipSwitches = new List<ListXmlDipSwitch>();
// TODO: There's no way this will work... just create the new list for now // TODO: There's no way this will work... just create the new list for now
} }
@@ -919,7 +927,9 @@ namespace SabreTools.Library.DatItems
return false; return false;
// Filter on runnable // Filter on runnable
if (filter.Runnable.MatchesNeutral(null, Runnable) == false) if (filter.Runnables.MatchesPositive(Runnable.NULL, Runnable) == false)
return false;
if (filter.Runnables.MatchesNegative(Runnable.NULL, Runnable) == true)
return false; return false;
// Filter on devices // Filter on devices
@@ -1141,7 +1151,7 @@ namespace SabreTools.Library.DatItems
SourceFile = null; SourceFile = null;
if (fields.Contains(Field.Runnable)) if (fields.Contains(Field.Runnable))
Runnable = null; Runnable = Runnable.NULL;
if (fields.Contains(Field.Devices)) if (fields.Contains(Field.Devices))
Devices = null; Devices = null;

View File

@@ -121,7 +121,7 @@ namespace SabreTools.Library.Filtering
/// <summary> /// <summary>
/// Include or exclude items with the "Runnable" tag /// Include or exclude items with the "Runnable" tag
/// </summary> /// </summary>
public FilterItem<bool?> Runnable { get; private set; } = new FilterItem<bool?>() { Neutral = null }; public FilterItem<Runnable> Runnables { get; private set; } = new FilterItem<Runnable>() { Positive = Runnable.NULL, Negative = Runnable.NULL };
/// <summary> /// <summary>
/// Include or exclude machine devices /// Include or exclude machine devices
@@ -703,10 +703,10 @@ namespace SabreTools.Library.Filtering
break; break;
case Field.Runnable: case Field.Runnable:
if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) if (negate)
Runnable.Neutral = false; Runnables.Negative |= value.AsRunnable();
else else
Runnable.Neutral = true; Runnables.Positive |= value.AsRunnable();
break; break;
case Field.Devices: case Field.Devices:

View File

@@ -745,6 +745,36 @@ namespace SabreTools.Library.Tools
#endif #endif
} }
/// <summary>
/// Get Runnable value from input string
/// </summary>
/// <param name="runnable">String to get value from</param>
/// <returns>Runnable value corresponding to the string</returns>
public static Runnable AsRunnable(this string runnable)
{
#if NET_FRAMEWORK
switch (runnable?.ToLowerInvariant())
{
case "no":
return Runnable.No;
case "partial":
return Runnable.Partial;
case "yes":
return Runnable.Yes;
default:
return Runnable.NULL;
}
#else
return runnable?.ToLowerInvariant() switch
{
"no" => Runnable.No,
"partial" => Runnable.Partial,
"yes" => Runnable.Yes,
_ => Runnable.NULL,
};
#endif
}
/// <summary> /// <summary>
/// Get SplitType value from input ForceMerging /// Get SplitType value from input ForceMerging
/// </summary> /// </summary>
@@ -849,7 +879,6 @@ namespace SabreTools.Library.Tools
#endif #endif
} }
/// <summary> /// <summary>
/// Get bool? value from input string /// Get bool? value from input string
/// </summary> /// </summary>