mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add DeviceReference type, cleanup TODOs
This commit is contained in:
@@ -641,6 +641,12 @@ namespace SabreTools.Library.DatFiles
|
||||
cmpw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.DeviceReference:
|
||||
cmpw.WriteStartElement("device_ref");
|
||||
cmpw.WriteRequiredAttributeString("name", datItem.Name);
|
||||
cmpw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Disk:
|
||||
var disk = datItem as Disk;
|
||||
cmpw.WriteStartElement("disk");
|
||||
|
||||
@@ -1389,8 +1389,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
// If the game has no devices, mark it
|
||||
bool devices = true;
|
||||
if (Items[game][0].Machine.DeviceReferences == null
|
||||
|| Items[game][0].Machine.DeviceReferences.Count == 0)
|
||||
if (Items[game].Count(i => i.ItemType == ItemType.DeviceReference) == 0)
|
||||
{
|
||||
devices = false;
|
||||
}
|
||||
@@ -1399,7 +1398,10 @@ namespace SabreTools.Library.DatFiles
|
||||
if (devices)
|
||||
{
|
||||
// Determine if the game has any devices or not
|
||||
List<string> deviceReferences = Items[game][0].Machine.DeviceReferences.Select(d => d.Name).ToList();
|
||||
List<string> deviceReferences = Items[game]
|
||||
.Where(i => i.ItemType == ItemType.DeviceReference)
|
||||
.Select(i => i.Name)
|
||||
.ToList();
|
||||
List<string> newdevs = new List<string>();
|
||||
foreach (string deviceReference in deviceReferences)
|
||||
{
|
||||
@@ -1410,10 +1412,13 @@ namespace SabreTools.Library.DatFiles
|
||||
// Otherwise, copy the items from the device to the current game
|
||||
DatItem copyFrom = Items[game][0];
|
||||
List<DatItem> devItems = Items[deviceReference];
|
||||
newdevs.AddRange((Items[deviceReference] ?? new List<DatItem>())
|
||||
.Where(i => i.ItemType == ItemType.DeviceReference)
|
||||
.Select(i => i.Name));
|
||||
|
||||
foreach (DatItem item in devItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
newdevs.AddRange((datItem.Machine.DeviceReferences ?? new List<ListXmlDeviceReference>()).Select(d => d.Name).ToList());
|
||||
datItem.CopyMachineInformation(copyFrom);
|
||||
if (Items[game].Where(i => i.ItemType == datItem.ItemType && i.Name == datItem.Name).Count() == 0)
|
||||
{
|
||||
@@ -1427,7 +1432,7 @@ namespace SabreTools.Library.DatFiles
|
||||
foreach (string device in newdevs)
|
||||
{
|
||||
if (!deviceReferences.Contains(device))
|
||||
Items[game][0].Machine.DeviceReferences.Add(new ListXmlDeviceReference() { Name = device });
|
||||
Items[game].Add(new DeviceReference() { Name = device });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,12 @@ namespace SabreTools.Library.DatFiles
|
||||
[JsonIgnore]
|
||||
public long ChipCount { get; private set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Number of Device Reference items
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public long DeviceReferenceCount { get; private set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Number of Disk items
|
||||
/// </summary>
|
||||
@@ -461,6 +467,9 @@ namespace SabreTools.Library.DatFiles
|
||||
case ItemType.Chip:
|
||||
ChipCount++;
|
||||
break;
|
||||
case ItemType.DeviceReference:
|
||||
DeviceReferenceCount++;
|
||||
break;
|
||||
case ItemType.Disk:
|
||||
DiskCount++;
|
||||
if ((item as Disk).ItemStatus != ItemStatus.Nodump)
|
||||
@@ -590,6 +599,9 @@ namespace SabreTools.Library.DatFiles
|
||||
case ItemType.Chip:
|
||||
ChipCount--;
|
||||
break;
|
||||
case ItemType.DeviceReference:
|
||||
DeviceReferenceCount--;
|
||||
break;
|
||||
case ItemType.Disk:
|
||||
DiskCount--;
|
||||
if ((item as Disk).ItemStatus != ItemStatus.Nodump)
|
||||
|
||||
@@ -220,6 +220,9 @@ namespace SabreTools.Library.DatFiles
|
||||
case ItemType.Chip:
|
||||
datItem = datItemObj.ToObject<Chip>();
|
||||
break;
|
||||
case ItemType.DeviceReference:
|
||||
datItem = datItemObj.ToObject<DeviceReference>();
|
||||
break;
|
||||
case ItemType.Disk:
|
||||
datItem = datItemObj.ToObject<Disk>();
|
||||
break;
|
||||
|
||||
@@ -238,14 +238,10 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
|
||||
case "device_ref":
|
||||
var deviceReference = new ListXmlDeviceReference();
|
||||
deviceReference.Name = reader.GetAttribute("name");
|
||||
|
||||
// Ensure the list exists
|
||||
if (machine.DeviceReferences == null)
|
||||
machine.DeviceReferences = new List<ListXmlDeviceReference>();
|
||||
|
||||
machine.DeviceReferences.Add(deviceReference);
|
||||
datItems.Add(new DeviceReference
|
||||
{
|
||||
Name = reader.GetAttribute("name"),
|
||||
});
|
||||
|
||||
reader.Read();
|
||||
break;
|
||||
@@ -503,7 +499,7 @@ namespace SabreTools.Library.DatFiles
|
||||
case "softwarelist":
|
||||
var softwareList = new ListXmlSoftwareList();
|
||||
softwareList.Name = reader.GetAttribute("name");
|
||||
softwareList.Status = reader.GetAttribute("status");
|
||||
softwareList.Status = reader.GetAttribute("status").AsSoftwareListStatus();
|
||||
softwareList.Filter = reader.GetAttribute("filter");
|
||||
|
||||
// Ensure the list exists
|
||||
@@ -1080,18 +1076,6 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteOptionalElementString("manufacturer", datItem.Machine.Manufacturer);
|
||||
|
||||
// TODO: These should go *after* the datitems
|
||||
if (datItem.Machine.DeviceReferences != null)
|
||||
{
|
||||
foreach (var deviceReference in datItem.Machine.DeviceReferences)
|
||||
{
|
||||
xtw.WriteStartElement("device_ref");
|
||||
|
||||
xtw.WriteOptionalAttributeString("name", deviceReference.Name);
|
||||
|
||||
// End device_ref
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
}
|
||||
if (datItem.Machine.Displays != null)
|
||||
{
|
||||
foreach (var display in datItem.Machine.Displays)
|
||||
@@ -1428,7 +1412,7 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteStartElement("softwarelist");
|
||||
|
||||
xtw.WriteOptionalAttributeString("name", softwarelist.Name);
|
||||
xtw.WriteOptionalAttributeString("status", softwarelist.Status);
|
||||
xtw.WriteOptionalAttributeString("status", softwarelist.Status.FromSoftwareListStatus());
|
||||
xtw.WriteOptionalAttributeString("filter", softwarelist.Filter);
|
||||
|
||||
// End softwarelist
|
||||
@@ -1518,6 +1502,12 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.DeviceReference:
|
||||
xtw.WriteStartElement("device_ref");
|
||||
xtw.WriteRequiredAttributeString("name", datItem.Name);
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Disk:
|
||||
var disk = datItem as Disk;
|
||||
xtw.WriteStartElement("disk");
|
||||
|
||||
@@ -988,6 +988,12 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.DeviceReference:
|
||||
xtw.WriteStartElement("device_ref");
|
||||
xtw.WriteRequiredAttributeString("name", datItem.Name);
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Disk:
|
||||
var disk = datItem as Disk;
|
||||
xtw.WriteStartElement("disk");
|
||||
|
||||
@@ -867,6 +867,13 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.DeviceReference:
|
||||
xtw.WriteStartElement("file");
|
||||
xtw.WriteAttributeString("type", "device_ref");
|
||||
xtw.WriteRequiredAttributeString("name", datItem.Name);
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Disk:
|
||||
var disk = datItem as Disk;
|
||||
xtw.WriteStartElement("file");
|
||||
|
||||
Reference in New Issue
Block a user