Promote SoftwareList

This commit is contained in:
Matt Nadareski
2020-08-31 23:26:07 -07:00
parent 3e9b4e510c
commit 6bc91732e6
14 changed files with 288 additions and 167 deletions

View File

@@ -377,21 +377,6 @@ namespace SabreTools.Library.DatFiles
if (item.ItemType == ItemType.Release)
(item as Release).Language = attrVal;
break;
case "tag":
if (item.ItemType == ItemType.Chip)
(item as Chip).Tag = attrVal;
break;
case "type":
if (item.ItemType == ItemType.Chip)
(item as Chip).ChipType = attrVal;
break;
case "clock":
if (item.ItemType == ItemType.Chip)
(item as Chip).Clock = attrVal;
break;
}
}
@@ -631,16 +616,6 @@ namespace SabreTools.Library.DatFiles
cmpw.WriteEndElement();
break;
case ItemType.Chip:
var chip = datItem as Chip;
cmpw.WriteStartElement("chip");
cmpw.WriteRequiredAttributeString("name", chip.Name);
cmpw.WriteOptionalAttributeString("tag", chip.Tag);
cmpw.WriteOptionalAttributeString("type", chip.ChipType);
cmpw.WriteOptionalAttributeString("clock", chip.Clock);
cmpw.WriteEndElement();
break;
case ItemType.DeviceReference:
cmpw.WriteStartElement("device_ref");
cmpw.WriteRequiredAttributeString("name", datItem.Name);

View File

@@ -131,6 +131,12 @@ namespace SabreTools.Library.DatFiles
[JsonIgnore]
public long SampleCount { get; private set; } = 0;
/// <summary>
/// Number of SoftwareList items
/// </summary>
[JsonIgnore]
public long SoftwareListCount { get; private set; } = 0;
/// <summary>
/// Number of machines
/// </summary>
@@ -516,6 +522,9 @@ namespace SabreTools.Library.DatFiles
case ItemType.Sample:
SampleCount++;
break;
case ItemType.SoftwareList:
SoftwareListCount++;
break;
}
}
@@ -648,6 +657,9 @@ namespace SabreTools.Library.DatFiles
case ItemType.Sample:
SampleCount--;
break;
case ItemType.SoftwareList:
SoftwareListCount--;
break;
}
}

View File

@@ -238,6 +238,9 @@ namespace SabreTools.Library.DatFiles
case ItemType.Sample:
datItem = datItemObj.ToObject<Sample>();
break;
case ItemType.SoftwareList:
datItem = datItemObj.ToObject<DatItems.SoftwareList>();
break;
}
}

View File

@@ -497,18 +497,21 @@ namespace SabreTools.Library.DatFiles
break;
case "softwarelist":
var softwareList = new ListXmlSoftwareList();
softwareList.Name = reader.GetAttribute("name");
softwareList.Status = reader.GetAttribute("status").AsSoftwareListStatus();
softwareList.Filter = reader.GetAttribute("filter");
datItems.Add(new DatItems.SoftwareList
{
Name = reader.GetAttribute("name"),
Status = reader.GetAttribute("status").AsSoftwareListStatus(),
Filter = reader.GetAttribute("filter"),
// Ensure the list exists
if (machine.SoftwareLists == null)
machine.SoftwareLists = new List<ListXmlSoftwareList>();
machine.SoftwareLists.Add(softwareList);
Source = new Source
{
Index = indexId,
Name = filename,
},
});
reader.Read();
break;
case "ramoption":
@@ -1405,20 +1408,6 @@ namespace SabreTools.Library.DatFiles
xtw.WriteEndElement();
}
}
if (datItem.Machine.SoftwareLists != null)
{
foreach (var softwarelist in datItem.Machine.SoftwareLists)
{
xtw.WriteStartElement("softwarelist");
xtw.WriteOptionalAttributeString("name", softwarelist.Name);
xtw.WriteOptionalAttributeString("status", softwarelist.Status.FromSoftwareListStatus());
xtw.WriteOptionalAttributeString("filter", softwarelist.Filter);
// End softwarelist
xtw.WriteEndElement();
}
}
if (datItem.Machine.RamOptions != null)
{
foreach (var ramOption in datItem.Machine.RamOptions)
@@ -1551,6 +1540,15 @@ namespace SabreTools.Library.DatFiles
xtw.WriteRequiredAttributeString("name", datItem.Name);
xtw.WriteEndElement();
break;
case ItemType.SoftwareList:
var softwareList = datItem as DatItems.SoftwareList;
xtw.WriteStartElement("softwarelist");
xtw.WriteRequiredAttributeString("name", datItem.Name);
xtw.WriteOptionalAttributeString("status", softwareList.Status.FromSoftwareListStatus());
xtw.WriteOptionalAttributeString("sha512", softwareList.Filter);
xtw.WriteEndElement();
break;
}
xtw.Flush();

View File

@@ -412,31 +412,6 @@ namespace SabreTools.Library.DatFiles
reader.Read();
break;
case "chip":
containsItems = true;
DatItem chip = new Chip
{
Name = reader.GetAttribute("name"),
Tag = reader.GetAttribute("tag"),
ChipType = reader.GetAttribute("type"),
Clock = reader.GetAttribute("clock"),
Source = new Source
{
Index = indexId,
Name = filename,
},
};
chip.CopyMachineInformation(machine);
// Now process and add the chip
key = ParseAddHelper(chip);
reader.Read();
break;
case "disk":
containsItems = true;
@@ -978,16 +953,6 @@ namespace SabreTools.Library.DatFiles
xtw.WriteEndElement();
break;
case ItemType.Chip:
var chip = datItem as Chip;
xtw.WriteStartElement("chip");
xtw.WriteRequiredAttributeString("name", chip.Name);
xtw.WriteOptionalAttributeString("tag", chip.Tag);
xtw.WriteOptionalAttributeString("type", chip.ChipType);
xtw.WriteOptionalAttributeString("clock", chip.Clock);
xtw.WriteEndElement();
break;
case ItemType.DeviceReference:
xtw.WriteStartElement("device_ref");
xtw.WriteRequiredAttributeString("name", datItem.Name);

View File

@@ -956,6 +956,16 @@ namespace SabreTools.Library.DatFiles
xtw.WriteRequiredAttributeString("name", datItem.Name);
xtw.WriteEndElement();
break;
case ItemType.SoftwareList:
var softwareList = datItem as DatItems.SoftwareList;
xtw.WriteStartElement("file");
xtw.WriteAttributeString("type", "softwarelist");
xtw.WriteRequiredAttributeString("name", datItem.Name);
xtw.WriteOptionalAttributeString("status", softwareList.Status.FromSoftwareListStatus());
xtw.WriteOptionalAttributeString("sha512", softwareList.Filter);
xtw.WriteEndElement();
break;
}
xtw.Flush();

View File

@@ -418,23 +418,6 @@ namespace SabreTools.Library.DatItems
public bool? Default { get; set; }
}
/// <summary>
/// Represents one ListXML softwarelist
/// </summary>
/// TODO: Promote this to the same level as Sample?
[JsonObject("softwarelist")]
public class ListXmlSoftwareList
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("status")]
public SoftwareListStatus Status { get; set; }
[JsonProperty("filter")]
public string Filter { get; set; }
}
/// <summary>
/// Represents one ListXML sound
/// </summary>

View File

@@ -53,7 +53,7 @@ namespace SabreTools.Library.DatItems
#region Constructors
/// <summary>
/// Create a default, empty Sample object
/// Create a default, empty BiosSet object
/// </summary>
public BiosSet()
{
@@ -106,14 +106,14 @@ namespace SabreTools.Library.DatItems
public override bool Equals(DatItem other)
{
// If we don't have a biosset, return false
// If we don't have a BiosSet, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a biosset
// Otherwise, treat it as a BiosSet
BiosSet newOther = other as BiosSet;
// If the archive information matches
// If the BiosSet information matches
return (Name == newOther.Name && Description == newOther.Description && Default == newOther.Default);
}

View File

@@ -470,6 +470,9 @@ namespace SabreTools.Library.DatItems
case ItemType.Sample:
return new Sample();
case ItemType.SoftwareList:
return new SoftwareList();
default:
return new Rom();
}

View File

@@ -275,12 +275,6 @@ namespace SabreTools.Library.DatItems
Machine_Slot_SlotOption_DeviceName,
Machine_Slot_SlotOption_Default,
// SoftwareLists
Machine_SoftwareLists,
Machine_SoftwareList_Name,
Machine_SoftwareList_Status,
Machine_SoftwareList_Filter,
// RamOptions
Machine_RamOptions,
Machine_RamOption_Default,
@@ -425,6 +419,10 @@ namespace SabreTools.Library.DatItems
// Release
DatItem_Language,
// Software List
DatItem_SoftwareListStatus,
DatItem_Filter,
#endregion
#endregion // Item-Specific
@@ -467,6 +465,7 @@ namespace SabreTools.Library.DatItems
DeviceReference,
Release,
Sample,
SoftwareList,
Blank = 99, // This is not a real type, only used internally
}

View File

@@ -226,12 +226,6 @@ namespace SabreTools.Library.DatItems
[JsonProperty("slots", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<ListXmlSlot> Slots { get; set; } = null;
/// <summary>
/// List of software lists
/// </summary>
[JsonProperty("softwarelists", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<ListXmlSoftwareList> SoftwareLists { get; set; } = null;
/// <summary>
/// List of ramoptions
/// </summary>
@@ -602,7 +596,6 @@ namespace SabreTools.Library.DatItems
Features = this.Features,
Devices = this.Devices,
Slots = this.Slots,
SoftwareLists = this.SoftwareLists,
RamOptions = this.RamOptions,
#endregion

View File

@@ -0,0 +1,194 @@
using System.Collections.Generic;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
{
/// <summary>
/// Represents which SoftwareList(s) is associated with a set
/// </summary>
[JsonObject("softwarelist")]
public class SoftwareList : DatItem
{
#region Fields
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
public SoftwareListStatus Status { get; set; }
[JsonProperty("filter", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Filter { get; set; }
#endregion
#region Accessors
/// <summary>
/// Set fields with given values
/// </summary>
/// <param name="mappings">Mappings dictionary</param>
public override void SetFields(Dictionary<Field, string> mappings)
{
// Set base fields
base.SetFields(mappings);
// Handle SoftwareList-specific fields
if (mappings.Keys.Contains(Field.DatItem_SoftwareListStatus))
Status = mappings[Field.DatItem_Default].AsSoftwareListStatus();
if (mappings.Keys.Contains(Field.DatItem_Filter))
Filter = mappings[Field.DatItem_Filter];
}
#endregion
#region Constructors
/// <summary>
/// Create a default, empty SoftwareList object
/// </summary>
public SoftwareList()
{
Name = string.Empty;
ItemType = ItemType.SoftwareList;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new SoftwareList()
{
Name = this.Name,
ItemType = this.ItemType,
DupeType = this.DupeType,
AltName = this.AltName,
AltTitle = this.AltTitle,
Original = this.Original,
OpenMSXSubType = this.OpenMSXSubType,
OpenMSXType = this.OpenMSXType,
Remark = this.Remark,
Boot = this.Boot,
Part = this.Part,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
AreaWidth = this.AreaWidth,
AreaEndianness = this.AreaEndianness,
Value = this.Value,
LoadFlag = this.LoadFlag,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Status = this.Status,
Filter = this.Filter,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a sample, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a SoftwareList
SoftwareList newOther = other as SoftwareList;
// If the SoftwareList information matches
return (Name == newOther.Name
&& Status == newOther.Status
&& Filter == newOther.Filter);
}
#endregion
#region Filtering
/// <summary>
/// Check to see if a DatItem passes the filter
/// </summary>
/// <param name="filter">Filter to check against</param>
/// <returns>True if the item passed the filter, false otherwise</returns>
public override bool PassesFilter(Filter filter)
{
// Check common fields first
if (!base.PassesFilter(filter))
return false;
// Filter on status
if (filter.DatItem_SoftwareListStatus.MatchesPositive(SoftwareListStatus.NULL, Status) == false)
return false;
if (filter.DatItem_SoftwareListStatus.MatchesNegative(SoftwareListStatus.NULL, Status) == true)
return false;
// Filter on filter
if (filter.DatItem_Filter.MatchesPositiveSet(Filter) == false)
return false;
if (filter.DatItem_Filter.MatchesNegativeSet(Filter) == true)
return false;
return true;
}
/// <summary>
/// Remove fields from the DatItem
/// </summary>
/// <param name="fields">List of Fields to remove</param>
public override void RemoveFields(List<Field> fields)
{
// Remove common fields first
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_SoftwareListStatus))
Status = SoftwareListStatus.NULL;
if (fields.Contains(Field.DatItem_Filter))
Filter = null;
}
#endregion
#region Sorting and Merging
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="fields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> fields)
{
// Replace common fields first
base.ReplaceFields(item, fields);
// If we don't have a SoftwareList to replace from, ignore specific fields
if (item.ItemType != ItemType.SoftwareList)
return;
// Cast for easier access
SoftwareList newItem = item as SoftwareList;
// Replace the fields
if (fields.Contains(Field.DatItem_SoftwareListStatus))
Status = newItem.Status;
if (fields.Contains(Field.DatItem_Filter))
Filter = newItem.Filter;
}
#endregion
}
}

View File

@@ -197,12 +197,6 @@ namespace SabreTools.Library.Filtering
public FilterItem<string> Machine_Slot_SlotOption_DeviceName { get; private set; } = new FilterItem<string>();
public FilterItem<bool?> Machine_Slot_SlotOption_Default { get; private set; } = new FilterItem<bool?>() { Neutral = null };
// SoftwareLists
public FilterItem<bool?> Machine_SoftwareLists { get; private set; } = new FilterItem<bool?>() { Neutral = null };
public FilterItem<string> Machine_SoftwareList_Name { get; private set; } = new FilterItem<string>();
public FilterItem<string> Machine_SoftwareList_Status { get; private set; } = new FilterItem<string>();
public FilterItem<string> Machine_SoftwareList_Filter { get; private set; } = new FilterItem<string>();
// RamOptions
public FilterItem<bool?> Machine_RamOptions { get; private set; } = new FilterItem<bool?>() { Neutral = null };
public FilterItem<bool?> Machine_RamOption_Default { get; private set; } = new FilterItem<bool?>() { Neutral = null };
@@ -347,6 +341,10 @@ namespace SabreTools.Library.Filtering
// Release
public FilterItem<string> DatItem_Language { get; private set; } = new FilterItem<string>();
// Software List
public FilterItem<SoftwareListStatus> DatItem_SoftwareListStatus { get; private set; } = new FilterItem<SoftwareListStatus>() { Positive = SoftwareListStatus.NULL, Negative = SoftwareListStatus.NULL };
public FilterItem<string> DatItem_Filter { get; private set; } = new FilterItem<string>();
#endregion
#endregion // Item-Specific
@@ -1310,35 +1308,6 @@ namespace SabreTools.Library.Filtering
Machine_Slot_SlotOption_Default.Neutral = true;
break;
// SoftwareLists
case Field.Machine_SoftwareLists:
if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase))
Machine_SoftwareLists.Neutral = false;
else
Machine_SoftwareLists.Neutral = true;
break;
case Field.Machine_SoftwareList_Name:
if (negate)
Machine_SoftwareList_Name.NegativeSet.Add(value);
else
Machine_SoftwareList_Name.PositiveSet.Add(value);
break;
case Field.Machine_SoftwareList_Status:
if (negate)
Machine_SoftwareList_Status.NegativeSet.Add(value);
else
Machine_SoftwareList_Status.PositiveSet.Add(value);
break;
case Field.Machine_SoftwareList_Filter:
if (negate)
Machine_SoftwareList_Filter.NegativeSet.Add(value);
else
Machine_SoftwareList_Filter.PositiveSet.Add(value);
break;
// RamOptions
case Field.Machine_RamOptions:
if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase))
@@ -1966,11 +1935,26 @@ namespace SabreTools.Library.Filtering
DatItem_Language.PositiveSet.Add(value);
break;
#endregion
// Software List
case Field.DatItem_SoftwareListStatus:
if (negate)
DatItem_SoftwareListStatus.Negative |= value.AsSoftwareListStatus();
else
DatItem_SoftwareListStatus.Positive |= value.AsSoftwareListStatus();
break;
#endregion // Item-Specific
case Field.DatItem_Filter:
if (negate)
DatItem_Filter.NegativeSet.Add(value);
else
DatItem_Filter.PositiveSet.Add(value);
break;
#endregion // DatItem Filters
#endregion
#endregion // Item-Specific
#endregion // DatItem Filters
}
}

View File

@@ -762,18 +762,6 @@ namespace SabreTools.Library.Tools
case "slot_slotoption_default":
return Field.Machine_Slot_SlotOption_Default;
case "softwarelists":
return Field.Machine_SoftwareLists;
case "softwarelist_name":
return Field.Machine_SoftwareList_Name;
case "softwarelist_status":
return Field.Machine_SoftwareList_Status;
case "softwarelist_filter":
return Field.Machine_SoftwareList_Filter;
case "ramoptions":
return Field.Machine_RamOptions;
@@ -1100,6 +1088,14 @@ namespace SabreTools.Library.Tools
case "language":
return Field.DatItem_Language;
// Software List
case "softwareliststatus":
case "softwarelist_status":
return Field.DatItem_SoftwareListStatus;
case "filter":
return Field.DatItem_Filter;
#endregion
#endregion // Item-Specific
@@ -1614,6 +1610,8 @@ namespace SabreTools.Library.Tools
return ItemType.Rom;
case "sample":
return ItemType.Sample;
case "softwarelist":
return ItemType.SoftwareList;
default:
return null;
}
@@ -1630,6 +1628,7 @@ namespace SabreTools.Library.Tools
"release" => ItemType.Release,
"rom" => ItemType.Rom,
"sample" => ItemType.Sample,
"softwarelist" => ItemType.SoftwareList,
_ => null,
};
#endif
@@ -2041,6 +2040,8 @@ namespace SabreTools.Library.Tools
return "rom";
case ItemType.Sample:
return "sample";
case ItemType.SoftwareList:
return "softwarelist";
default:
return null;
}
@@ -2057,6 +2058,7 @@ namespace SabreTools.Library.Tools
ItemType.Release => "release",
ItemType.Rom => "rom",
ItemType.Sample => "sample",
ItemType.SoftwareList => "softwarelist",
_ => null,
};
#endif