mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Change Supported to Enum
This commit is contained in:
@@ -640,7 +640,7 @@ namespace SabreTools.Library.DatFiles
|
||||
#region SoftwareList
|
||||
|
||||
case "supported":
|
||||
machine.Supported = jtr.ReadAsString().AsYesNo();
|
||||
machine.Supported = jtr.ReadAsString().AsSupported();
|
||||
break;
|
||||
|
||||
case "sharedfeat":
|
||||
@@ -663,7 +663,7 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
|
||||
case "dipswitches":
|
||||
machine.DipSwitches = new List<SoftwareListDipSwitch>();
|
||||
machine.DipSwitches = new List<ListXMLDipSwitch>();
|
||||
jtr.Read(); // Start Array
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
@@ -678,7 +678,7 @@ namespace SabreTools.Library.DatFiles
|
||||
jtr.Read(); // Mask Key
|
||||
string mask = jtr.ReadAsString();
|
||||
|
||||
var dip = new SoftwareListDipSwitch(name, tag, mask);
|
||||
var dip = new ListXMLDipSwitch(name, tag, mask);
|
||||
|
||||
jtr.Read(); // Start dipvalues object
|
||||
while (!sr.EndOfStream)
|
||||
@@ -695,7 +695,7 @@ namespace SabreTools.Library.DatFiles
|
||||
bool? def = jtr.ReadAsString().AsYesNo();
|
||||
jtr.Read(); // End object
|
||||
|
||||
dip.Values.Add(new SoftwareListDipValue(valname, value, def));
|
||||
dip.Values.Add(new ListXMLDipValue(valname, value, def));
|
||||
}
|
||||
|
||||
jtr.Read(); // End object
|
||||
@@ -1843,17 +1843,22 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
if (!Header.ExcludeFields.Contains(Field.Supported) && datItem.Machine.Supported != null)
|
||||
if (!Header.ExcludeFields.Contains(Field.Supported) && datItem.Machine.Supported != Supported.NULL)
|
||||
{
|
||||
if (datItem.Machine.Supported == true)
|
||||
switch (datItem.Machine.Supported)
|
||||
{
|
||||
jtw.WritePropertyName("supported");
|
||||
jtw.WriteValue("yes");
|
||||
}
|
||||
else if (datItem.Machine.Supported == false)
|
||||
{
|
||||
jtw.WritePropertyName("supported");
|
||||
jtw.WriteValue("no");
|
||||
case Supported.No:
|
||||
jtw.WritePropertyName("supported");
|
||||
jtw.WriteValue("yes");
|
||||
break;
|
||||
case Supported.Partial:
|
||||
jtw.WritePropertyName("supported");
|
||||
jtw.WriteValue("partial");
|
||||
break;
|
||||
case Supported.Yes:
|
||||
jtw.WritePropertyName("supported");
|
||||
jtw.WriteValue("no");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SharedFeatures, Header.ExcludeFields)))
|
||||
@@ -1885,7 +1890,7 @@ namespace SabreTools.Library.DatFiles
|
||||
jtw.WriteValue(dip.Mask);
|
||||
jtw.WriteStartArray();
|
||||
|
||||
foreach (SoftwareListDipValue dipval in dip.Values)
|
||||
foreach (ListXMLDipValue dipval in dip.Values)
|
||||
{
|
||||
jtw.WriteStartObject();
|
||||
jtw.WritePropertyName("name");
|
||||
|
||||
@@ -386,23 +386,23 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
|
||||
case "dipswitch":
|
||||
// TODO: Make a new object for this
|
||||
// string dipswitch_name = reader.GetAttribute("name");
|
||||
// string dipswitch_tag = reader.GetAttribute("tag");
|
||||
// string dipswitch_mask = reader.GetAttribute("mask");
|
||||
// TODO: Use these dipswitches
|
||||
var dipSwitch = new ListXMLDipSwitch(reader.GetAttribute("name"), reader.GetAttribute("tag"), reader.GetAttribute("mask"));
|
||||
ReadDipSwitch(reader.ReadSubtree(), dipSwitch);
|
||||
|
||||
// // While the subtree contains <diplocation> elements...
|
||||
// TODO: Make a new object for this
|
||||
// TODO: Populate the dipswitch with the diplocations
|
||||
// string diplocation_name = reader.GetAttribute("name");
|
||||
// string diplocation_number = reader.GetAttribute("number");
|
||||
// bool? diplocation_inverted = Utilities.GetYesNo(reader.GetAttribute("inverted"));
|
||||
|
||||
// // While the subtree contains <dipvalue> elements...
|
||||
// TODO: Make a new object for this
|
||||
// TODO: Populate the dipswitch with the dipvalues
|
||||
// string dipvalue_name = reader.GetAttribute("name");
|
||||
// string dipvalue_value = reader.GetAttribute("value");
|
||||
// bool? dipvalue_default = Utilities.GetYesNo(reader.GetAttribute("default"));
|
||||
|
||||
// Skip the dipswitch now that we've processed it
|
||||
reader.Skip();
|
||||
break;
|
||||
|
||||
@@ -584,6 +584,59 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read DipSwitch DipValues information
|
||||
/// </summary>
|
||||
/// <param name="reader">XmlReader representing a diskarea block</param>
|
||||
/// <param name="dipSwitch">ListXMLDipSwitch to populate</param>
|
||||
private void ReadDipSwitch(XmlReader reader, ListXMLDipSwitch dipSwitch)
|
||||
{
|
||||
// If we have an empty trurip, skip it
|
||||
if (reader == null)
|
||||
return;
|
||||
|
||||
// Get lists ready
|
||||
dipSwitch.Locations = new List<ListXMLDipLocation>();
|
||||
dipSwitch.Values = new List<ListXMLDipValue>();
|
||||
|
||||
// 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 "diplocation":
|
||||
dipSwitch.Locations.Add(new ListXMLDipLocation(
|
||||
reader.GetAttribute("name"),
|
||||
reader.GetAttribute("number"),
|
||||
reader.GetAttribute("inverted").AsYesNo()));
|
||||
reader.Read();
|
||||
break;
|
||||
|
||||
case "dipvalue":
|
||||
dipSwitch.Values.Add(new ListXMLDipValue(
|
||||
reader.GetAttribute("name"),
|
||||
reader.GetAttribute("value"),
|
||||
reader.GetAttribute("default").AsYesNo()));
|
||||
reader.Read();
|
||||
break;
|
||||
|
||||
default:
|
||||
reader.Read();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create and open an output file for writing direct from a dictionary
|
||||
/// </summary>
|
||||
|
||||
@@ -483,7 +483,7 @@ namespace SabreTools.Library.DatFiles
|
||||
#region SoftwareList
|
||||
|
||||
case "Machine.Supported":
|
||||
machine.Supported = value.AsYesNo();
|
||||
machine.Supported = value.AsSupported();
|
||||
break;
|
||||
|
||||
case "Machine.SharedFeatures":
|
||||
@@ -498,7 +498,7 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
|
||||
case "Machine.DipSwitches":
|
||||
machine.DipSwitches = new List<SoftwareListDipSwitch>();
|
||||
machine.DipSwitches = new List<ListXMLDipSwitch>();
|
||||
// TODO: There is no way this would work... Just use empty for now
|
||||
break;
|
||||
|
||||
|
||||
@@ -142,12 +142,12 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
Name = reader.GetAttribute("name"),
|
||||
Description = reader.GetAttribute("name"),
|
||||
Supported = reader.GetAttribute("supported").AsYesNo(), // (yes|partial|no) "yes"
|
||||
Supported = reader.GetAttribute("supported").AsSupported(),
|
||||
|
||||
CloneOf = reader.GetAttribute("cloneof") ?? string.Empty,
|
||||
Infos = new List<ListXmlInfo>(),
|
||||
SharedFeatures = new List<SoftwareListSharedFeature>(),
|
||||
DipSwitches = new List<SoftwareListDipSwitch>(),
|
||||
DipSwitches = new List<ListXMLDipSwitch>(),
|
||||
|
||||
MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType),
|
||||
};
|
||||
@@ -248,7 +248,7 @@ namespace SabreTools.Library.DatFiles
|
||||
areaEndinaness;
|
||||
long? areasize = null;
|
||||
var features = new List<SoftwareListFeature>();
|
||||
var dipswitches = new List<SoftwareListDipSwitch>();
|
||||
var dipswitches = new List<ListXMLDipSwitch>();
|
||||
bool containsItems = false;
|
||||
|
||||
while (!reader.EOF)
|
||||
@@ -334,13 +334,8 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
case "dipswitch":
|
||||
// TODO: Use these dipswitches
|
||||
var dip = new SoftwareListDipSwitch(
|
||||
reader.GetAttribute("name"),
|
||||
reader.GetAttribute("tag"),
|
||||
reader.GetAttribute("mask"));
|
||||
|
||||
dip.Values = ReadDipSwitch(reader.ReadSubtree());
|
||||
dipswitches.Add(dip);
|
||||
var dipSwitch = new ListXMLDipSwitch(reader.GetAttribute("name"), reader.GetAttribute("tag"), reader.GetAttribute("mask"));
|
||||
ReadDipSwitch(reader.ReadSubtree(), dipSwitch);
|
||||
|
||||
// Skip the dipswitch now that we've processed it
|
||||
reader.Skip();
|
||||
@@ -568,15 +563,16 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <summary>
|
||||
/// Read DipSwitch DipValues information
|
||||
/// </summary>
|
||||
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||
private List<SoftwareListDipValue> ReadDipSwitch(XmlReader reader)
|
||||
/// <param name="reader">XmlReader representing a diskarea block</param>
|
||||
/// <param name="dipSwitch">ListXMLDipSwitch to populate</param>
|
||||
private void ReadDipSwitch(XmlReader reader, ListXMLDipSwitch dipSwitch)
|
||||
{
|
||||
// If we have an empty trurip, skip it
|
||||
if (reader == null)
|
||||
return null;
|
||||
return;
|
||||
|
||||
// Get list ready
|
||||
List<SoftwareListDipValue> dipValues = new List<SoftwareListDipValue>();
|
||||
dipSwitch.Values = new List<ListXMLDipValue>();
|
||||
|
||||
// Otherwise, add what is possible
|
||||
reader.MoveToContent();
|
||||
@@ -594,10 +590,11 @@ namespace SabreTools.Library.DatFiles
|
||||
switch (reader.Name)
|
||||
{
|
||||
case "dipvalue":
|
||||
dipValues.Add(new SoftwareListDipValue(
|
||||
dipSwitch.Values.Add(new ListXMLDipValue(
|
||||
reader.GetAttribute("name"),
|
||||
reader.GetAttribute("value"),
|
||||
reader.GetAttribute("default").AsYesNo()));
|
||||
reader.Read();
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -605,8 +602,6 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return dipValues;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -792,12 +787,18 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
if (!Header.ExcludeFields.Contains(Field.Supported))
|
||||
{
|
||||
if (datItem.Machine.Supported == true)
|
||||
xtw.WriteAttributeString("supported", "yes");
|
||||
else if (datItem.Machine.Supported == false)
|
||||
xtw.WriteAttributeString("supported", "no");
|
||||
else
|
||||
xtw.WriteAttributeString("supported", "partial");
|
||||
switch (datItem.Machine.Supported)
|
||||
{
|
||||
case Supported.No:
|
||||
xtw.WriteAttributeString("supported", "no");
|
||||
break;
|
||||
case Supported.Partial:
|
||||
xtw.WriteAttributeString("supported", "partial");
|
||||
break;
|
||||
case Supported.Yes:
|
||||
xtw.WriteAttributeString("supported", "yes");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Description, Header.ExcludeFields)))
|
||||
@@ -833,14 +834,14 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
if (!Header.ExcludeFields.Contains(Field.DipSwitches) && datItem.Machine.DipSwitches != null && datItem.Machine.DipSwitches.Count > 0)
|
||||
{
|
||||
foreach (SoftwareListDipSwitch dip in datItem.Machine.DipSwitches)
|
||||
foreach (ListXMLDipSwitch dip in datItem.Machine.DipSwitches)
|
||||
{
|
||||
xtw.WriteStartElement("dipswitch");
|
||||
xtw.WriteAttributeString("name", dip.Name);
|
||||
xtw.WriteAttributeString("tag", dip.Tag);
|
||||
xtw.WriteAttributeString("mask", dip.Mask);
|
||||
|
||||
foreach (SoftwareListDipValue dipval in dip.Values)
|
||||
foreach (ListXMLDipValue dipval in dip.Values)
|
||||
{
|
||||
xtw.WriteStartElement("dipvalue");
|
||||
xtw.WriteAttributeString("name", dipval.Name);
|
||||
|
||||
@@ -45,37 +45,58 @@ namespace SabreTools.Library.DatItems
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
#region ListXML
|
||||
|
||||
/// <summary>
|
||||
/// Represents one SoftwareList dipswitch
|
||||
/// Represents one ListXML dipswitch
|
||||
/// </summary>
|
||||
public class SoftwareListDipSwitch
|
||||
/// <remarks>Also used by SoftwareList</remarks>
|
||||
public class ListXMLDipSwitch
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Tag { get; set; }
|
||||
public string Mask { get; set; }
|
||||
public List<SoftwareListDipValue> Values { get; set; }
|
||||
public List<ListXMLDipLocation> Locations { get; set; }
|
||||
public List<ListXMLDipValue> Values { get; set; }
|
||||
|
||||
public SoftwareListDipSwitch(string name, string tag, string mask)
|
||||
public ListXMLDipSwitch(string name, string tag, string mask)
|
||||
{
|
||||
Name = name;
|
||||
Tag = tag;
|
||||
Mask = mask;
|
||||
Values = new List<SoftwareListDipValue>();
|
||||
Locations = new List<ListXMLDipLocation>();
|
||||
Values = new List<ListXMLDipValue>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents one SoftwareList dipswitch
|
||||
/// Represents one ListXML diplocation
|
||||
/// </summary>
|
||||
public class SoftwareListDipValue
|
||||
public class ListXMLDipLocation
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Number { get; set; }
|
||||
public bool? Inverted { get; set; }
|
||||
|
||||
public ListXMLDipLocation(string name, string number, bool? inverted)
|
||||
{
|
||||
Name = name;
|
||||
Number = number;
|
||||
Inverted = inverted;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents one ListXML dipvalue
|
||||
/// </summary>
|
||||
/// <remarks>Also used by SoftwareList</remarks>
|
||||
public class ListXMLDipValue
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
public bool? Default { get; set; }
|
||||
|
||||
public SoftwareListDipValue(string name, string value, bool? def)
|
||||
public ListXMLDipValue(string name, string value, bool? def)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
@@ -83,6 +104,10 @@ namespace SabreTools.Library.DatItems
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
/// <summary>
|
||||
/// Represents one SoftwareList shared feature object
|
||||
/// </summary>
|
||||
|
||||
@@ -240,4 +240,16 @@ namespace SabreTools.Library.DatItems
|
||||
Device = 1 << 2,
|
||||
Mechanical = 1 << 3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine machine support status
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum Supported
|
||||
{
|
||||
NULL,
|
||||
No,
|
||||
Partial,
|
||||
Yes,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,9 +272,8 @@ namespace SabreTools.Library.DatItems
|
||||
/// <summary>
|
||||
/// Support status
|
||||
/// </summary>
|
||||
/// <remarks>yes = true, partial = null, no = false</remarks>
|
||||
[JsonProperty("supported")]
|
||||
public bool? Supported { get; set; } = true;
|
||||
public Supported Supported { get; set; } = Supported.NULL;
|
||||
|
||||
/// <summary>
|
||||
/// List of shared feature items
|
||||
@@ -287,7 +286,7 @@ namespace SabreTools.Library.DatItems
|
||||
/// </summary>
|
||||
/// <remarks>Also in SoftwareList</remarks>
|
||||
[JsonProperty("dipswitches")]
|
||||
public List<SoftwareListDipSwitch> DipSwitches { get; set; } = null;
|
||||
public List<ListXMLDipSwitch> DipSwitches { get; set; } = null;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -451,7 +450,7 @@ namespace SabreTools.Library.DatItems
|
||||
#region SoftwareList
|
||||
|
||||
case Field.Supported:
|
||||
fieldValue = Supported?.ToString();
|
||||
fieldValue = Supported.ToString();
|
||||
break;
|
||||
case Field.SharedFeatures:
|
||||
fieldValue = string.Join(";", (SharedFeatures ?? new List<SoftwareListSharedFeature>()).Select(i => $"{i.Name}={i.Value}"));
|
||||
@@ -640,7 +639,7 @@ namespace SabreTools.Library.DatItems
|
||||
#region SoftwareList
|
||||
|
||||
if (mappings.Keys.Contains(Field.Supported))
|
||||
Supported = mappings[Field.Supported].AsYesNo();
|
||||
Supported = mappings[Field.Supported].AsSupported();
|
||||
|
||||
if (mappings.Keys.Contains(Field.SharedFeatures))
|
||||
{
|
||||
@@ -658,7 +657,7 @@ namespace SabreTools.Library.DatItems
|
||||
if (mappings.Keys.Contains(Field.DipSwitches))
|
||||
{
|
||||
if (DipSwitches == null)
|
||||
DipSwitches = new List<SoftwareListDipSwitch>();
|
||||
DipSwitches = new List<ListXMLDipSwitch>();
|
||||
|
||||
// TODO: There's no way this will work... just create the new list for now
|
||||
}
|
||||
@@ -1058,7 +1057,9 @@ namespace SabreTools.Library.DatItems
|
||||
#region SoftwareList
|
||||
|
||||
// Filter on supported
|
||||
if (filter.Supported.MatchesNeutral(null, Supported) == false)
|
||||
if (filter.SupportedStatus.MatchesPositive(Supported.NULL, Supported) == false)
|
||||
return false;
|
||||
if (filter.SupportedStatus.MatchesNegative(Supported.NULL, Supported) == true)
|
||||
return false;
|
||||
|
||||
#endregion
|
||||
@@ -1210,7 +1211,7 @@ namespace SabreTools.Library.DatItems
|
||||
#region SoftwareList
|
||||
|
||||
if (fields.Contains(Field.Supported))
|
||||
Supported = null;
|
||||
Supported = Supported.NULL;
|
||||
|
||||
if (fields.Contains(Field.SharedFeatures))
|
||||
SharedFeatures = null;
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace SabreTools.Library.Filtering
|
||||
/// <summary>
|
||||
/// Include or exclude items with the "Supported" tag
|
||||
/// </summary>
|
||||
public FilterItem<bool?> Supported { get; private set; } = new FilterItem<bool?>() { Neutral = null };
|
||||
public FilterItem<Supported> SupportedStatus { get; private set; } = new FilterItem<Supported>() { Positive = Supported.NULL, Negative = Supported.NULL };
|
||||
|
||||
// TODO: Machine.SharedFeatures - List<SoftwareListSharedFeature>
|
||||
|
||||
@@ -838,10 +838,10 @@ namespace SabreTools.Library.Filtering
|
||||
#region SoftwareList
|
||||
|
||||
case Field.Supported:
|
||||
if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase))
|
||||
Supported.Neutral = false;
|
||||
if (negate)
|
||||
SupportedStatus.Negative |= value.AsSupported();
|
||||
else
|
||||
Supported.Neutral = true;
|
||||
SupportedStatus.Positive |= value.AsSupported();
|
||||
break;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -819,6 +819,37 @@ namespace SabreTools.Library.Tools
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Supported value from input string
|
||||
/// </summary>
|
||||
/// <param name="supported">String to get value from</param>
|
||||
/// <returns>Supported value corresponding to the string</returns>
|
||||
public static Supported AsSupported(this string supported)
|
||||
{
|
||||
#if NET_FRAMEWORK
|
||||
switch (supported?.ToLowerInvariant())
|
||||
{
|
||||
case "no":
|
||||
return Supported.No;
|
||||
case "partial":
|
||||
return Supported.Partial;
|
||||
case "yes":
|
||||
return Supported.Yes;
|
||||
default:
|
||||
return Supported.NULL;
|
||||
}
|
||||
#else
|
||||
return supported?.ToLowerInvariant() switch
|
||||
{
|
||||
"no" => Supported.No,
|
||||
"partial" => Supported.Partial,
|
||||
"yes" => Supported.Yes,
|
||||
_ => Supported.NULL,
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get bool? value from input string
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user