mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix filtering, merging, blanks, and bucketing
This commit is contained in:
@@ -1383,35 +1383,37 @@ namespace SabreTools.Library.DatFiles
|
||||
if (Items[game] == null || Items[game].Count == 0)
|
||||
continue;
|
||||
|
||||
// If the game (is/is not) a bios, we want to continue
|
||||
// If the game (is/is not) a device, we want to continue
|
||||
if (dev ^ (Items[game][0].Machine.MachineType.HasFlag(MachineType.Device)))
|
||||
continue;
|
||||
|
||||
// If the game has no devices, we continue
|
||||
// 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
|
||||
|| (slotoptions && Items[game][0].Machine.Slots == null)
|
||||
|| (slotoptions && Items[game][0].Machine.Slots.Count == 0))
|
||||
|| Items[game][0].Machine.DeviceReferences.Count == 0)
|
||||
{
|
||||
continue;
|
||||
devices = false;
|
||||
}
|
||||
|
||||
// If we're checking devices
|
||||
if (devices)
|
||||
{
|
||||
// Determine if the game has any devices or not
|
||||
List<ListXmlDeviceReference> deviceReferences = Items[game][0].Machine.DeviceReferences;
|
||||
List<ListXmlDeviceReference> newdevs = new List<ListXmlDeviceReference>();
|
||||
foreach (ListXmlDeviceReference deviceReference in deviceReferences)
|
||||
List<string> deviceReferences = Items[game][0].Machine.DeviceReferences.Select(d => d.Name).ToList();
|
||||
List<string> newdevs = new List<string>();
|
||||
foreach (string deviceReference in deviceReferences)
|
||||
{
|
||||
// If the device doesn't exist then we continue
|
||||
if (Items[deviceReference.Name].Count == 0)
|
||||
if (Items[deviceReference] == null || Items[deviceReference].Count == 0)
|
||||
continue;
|
||||
|
||||
// Otherwise, copy the items from the device to the current game
|
||||
DatItem copyFrom = Items[game][0];
|
||||
List<DatItem> devItems = Items[deviceReference.Name];
|
||||
List<DatItem> devItems = Items[deviceReference];
|
||||
foreach (DatItem item in devItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
newdevs.AddRange(datItem.Machine.DeviceReferences ?? new List<ListXmlDeviceReference>());
|
||||
newdevs.AddRange((datItem.Machine.DeviceReferences ?? new List<ListXmlDeviceReference>()).Select(d => d.Name).ToList());
|
||||
datItem.CopyMachineInformation(copyFrom);
|
||||
if (Items[game].Where(i => i.Name.ToLowerInvariant() == datItem.Name.ToLowerInvariant()).Count() == 0)
|
||||
{
|
||||
@@ -1422,34 +1424,54 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
|
||||
// Now that every device is accounted for, add the new list of devices, if they don't already exist
|
||||
foreach (ListXmlDeviceReference device in newdevs)
|
||||
foreach (string device in newdevs)
|
||||
{
|
||||
if (!Items[game][0].Machine.DeviceReferences.Select(d => d.Name).Contains(device.Name))
|
||||
Items[game][0].Machine.DeviceReferences.Add(new ListXmlDeviceReference() { Name = device.Name });
|
||||
if (!deviceReferences.Contains(device))
|
||||
Items[game][0].Machine.DeviceReferences.Add(new ListXmlDeviceReference() { Name = device });
|
||||
}
|
||||
}
|
||||
|
||||
// If we're checking slotoptions too
|
||||
|
||||
// If we're checking slotoptions
|
||||
if (slotoptions)
|
||||
{
|
||||
// Determine if the game has any slots or not
|
||||
List<ListXmlSlot> slots = Items[game][0].Machine.Slots;
|
||||
List<ListXmlSlot> newSlots = new List<ListXmlSlot>();
|
||||
foreach (ListXmlSlot slot in slots)
|
||||
// If the game has no slot options, we continue
|
||||
if (Items[game][0].Machine.Slots == null
|
||||
|| Items[game][0].Machine.Slots
|
||||
.SelectMany(s => s.SlotOptions ?? new List<ListXmlSlotOption>()).Count() == 0)
|
||||
{
|
||||
foreach (ListXmlSlotOption slotOption in slot.SlotOptions)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine if the game has any slot options or not
|
||||
List<string> slotOptions = Items[game][0].Machine.Slots
|
||||
.Where(s => s.SlotOptions != null && s.SlotOptions.Count != 0)
|
||||
.SelectMany(s => s.SlotOptions)
|
||||
.Select(o => o.DeviceName)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
List<string> newSlotOptions = new List<string>();
|
||||
foreach (string slotOption in slotOptions)
|
||||
{
|
||||
// If the slotoption doesn't exist then we continue
|
||||
if (Items[slotOption.Name].Count == 0)
|
||||
// If the slot option doesn't exist then we continue
|
||||
if (Items[slotOption] == null || Items[slotOption].Count == 0)
|
||||
continue;
|
||||
|
||||
// Otherwise, copy the items from the slotoption to the current game
|
||||
// Otherwise, copy the items from the slot option to the current game
|
||||
DatItem copyFrom = Items[game][0];
|
||||
List<DatItem> slotItems = Items[slotOption.Name];
|
||||
foreach (DatItem item in slotItems)
|
||||
List<DatItem> slotOptionItems = Items[slotOption];
|
||||
foreach (DatItem item in slotOptionItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
newSlots.AddRange(datItem.Machine.Slots ?? new List<ListXmlSlot>());
|
||||
List<string> machineSlotOptions =
|
||||
(datItem.Machine.Slots ?? new List<ListXmlSlot>())
|
||||
.Where(s => s.SlotOptions != null && s.SlotOptions.Count != 0)
|
||||
.SelectMany(s => s.SlotOptions)
|
||||
.Select(o => o.DeviceName)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
newSlotOptions.AddRange(machineSlotOptions);
|
||||
datItem.CopyMachineInformation(copyFrom);
|
||||
if (Items[game].Where(i => i.Name.ToLowerInvariant() == datItem.Name.ToLowerInvariant()).Count() == 0)
|
||||
{
|
||||
@@ -1458,12 +1480,15 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now that every slotoption is accounted for, add the new list of slots, if they don't already exist
|
||||
foreach (ListXmlSlot slot in newSlots)
|
||||
// Ensure we don't have unnecessary duplicates
|
||||
newSlotOptions = newSlotOptions.Distinct().ToList();
|
||||
|
||||
// Now that every slot option is accounted for, add the new list of options, if they don't already exist
|
||||
foreach (string slotOption in newSlotOptions)
|
||||
{
|
||||
Items[game][0].Machine.Slots.Add(slot);
|
||||
if (!slotOptions.Contains(slotOption))
|
||||
Items[game][0].Machine.Slots.Add(new ListXmlSlot() { SlotOptions = new List<ListXmlSlotOption> { new ListXmlSlotOption { DeviceName = slotOption } } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,9 +750,6 @@ namespace SabreTools.Library.DatFiles
|
||||
DatItem.Sort(ref sortedlist, false);
|
||||
});
|
||||
}
|
||||
|
||||
// Now clean up all empty keys
|
||||
ClearEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace SabreTools.Library.DatFiles
|
||||
reader.MoveToContent();
|
||||
|
||||
// Create a new machine
|
||||
MachineType machineType = MachineType.NULL;
|
||||
MachineType machineType = 0x0;
|
||||
if (reader.GetAttribute("isbios").AsYesNo() == true)
|
||||
machineType |= MachineType.Bios;
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace SabreTools.Library.DatFiles
|
||||
CloneOf = reader.GetAttribute("cloneof"),
|
||||
RomOf = reader.GetAttribute("romof"),
|
||||
SampleOf = reader.GetAttribute("sampleof"),
|
||||
MachineType = (machineType == MachineType.NULL ? MachineType.NULL : machineType),
|
||||
MachineType = (machineType == 0x0 ? MachineType.NULL : machineType),
|
||||
|
||||
SourceFile = reader.GetAttribute("sourcefile"),
|
||||
Runnable = reader.GetAttribute("runnable").AsRunnable(),
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace SabreTools.Library.DatFiles
|
||||
bool containsItems = false;
|
||||
|
||||
// Create a new machine
|
||||
MachineType machineType = MachineType.NULL;
|
||||
MachineType machineType = 0x0;
|
||||
if (reader.GetAttribute("isbios").AsYesNo() == true)
|
||||
machineType |= MachineType.Bios;
|
||||
|
||||
@@ -313,7 +313,7 @@ namespace SabreTools.Library.DatFiles
|
||||
RomOf = reader.GetAttribute("romof"),
|
||||
SampleOf = reader.GetAttribute("sampleof"),
|
||||
|
||||
MachineType = (machineType == MachineType.NULL ? MachineType.NULL : machineType),
|
||||
MachineType = (machineType == 0x0 ? MachineType.NULL : machineType),
|
||||
};
|
||||
|
||||
if (Header.Type == "SuperDAT" && !keep)
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace SabreTools.Library.DatFiles
|
||||
bool containsItems = false;
|
||||
|
||||
// Create a new machine
|
||||
MachineType machineType = MachineType.NULL;
|
||||
MachineType machineType = 0x0;
|
||||
if (reader.GetAttribute("isbios").AsYesNo() == true)
|
||||
machineType |= MachineType.Bios;
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace SabreTools.Library.DatFiles
|
||||
Supported = reader.GetAttribute("supported").AsSupported(),
|
||||
|
||||
CloneOf = reader.GetAttribute("cloneof"),
|
||||
MachineType = (machineType != MachineType.NULL ? machineType : MachineType.NULL),
|
||||
MachineType = (machineType == 0x0 ? MachineType.NULL : machineType),
|
||||
};
|
||||
|
||||
while (!reader.EOF)
|
||||
|
||||
@@ -1225,26 +1225,12 @@ namespace SabreTools.Library.DatItems
|
||||
if (x.Source.Index == y.Source.Index)
|
||||
{
|
||||
if (x.Machine.Name == y.Machine.Name)
|
||||
{
|
||||
// Special case for comparing a Disk, Media, or Rom to another item type
|
||||
if ((x.ItemType == ItemType.Disk || x.ItemType == ItemType.Media || x.ItemType == ItemType.Rom)
|
||||
^ (y.ItemType == ItemType.Disk || y.ItemType == ItemType.Media || x.ItemType == ItemType.Rom))
|
||||
{
|
||||
if (x.ItemType == ItemType.Disk || x.ItemType == ItemType.Media || x.ItemType == ItemType.Rom)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Otherwise, we compare names naturally
|
||||
else
|
||||
{
|
||||
if (Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name)))
|
||||
return nc.Compare(Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(y.Name)));
|
||||
|
||||
return nc.Compare(Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name)));
|
||||
}
|
||||
}
|
||||
|
||||
return nc.Compare(x.Machine.Name, y.Machine.Name);
|
||||
}
|
||||
|
||||
@@ -439,7 +439,7 @@ namespace SabreTools.Library.DatItems
|
||||
/// <summary>
|
||||
/// This is a fake flag that is used for filter only
|
||||
/// </summary>
|
||||
NULL = 0x00,
|
||||
NULL = 0,
|
||||
|
||||
None = 1 << 0,
|
||||
Good = 1 << 1,
|
||||
@@ -471,10 +471,14 @@ namespace SabreTools.Library.DatItems
|
||||
[Flags]
|
||||
public enum OpenMSXSubType
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a fake flag that is used for filter only
|
||||
/// </summary>
|
||||
NULL = 0,
|
||||
Rom = 1,
|
||||
MegaRom = 2,
|
||||
SCCPlusCart = 3,
|
||||
|
||||
Rom = 1 << 0,
|
||||
MegaRom = 1 << 1,
|
||||
SCCPlusCart = 1 << 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -483,10 +487,14 @@ namespace SabreTools.Library.DatItems
|
||||
[Flags]
|
||||
public enum MachineType
|
||||
{
|
||||
NULL = 0x00,
|
||||
Bios = 1 << 0,
|
||||
Device = 1 << 1,
|
||||
Mechanical = 1 << 2,
|
||||
/// <summary>
|
||||
/// This is a fake flag that is used for filter only
|
||||
/// </summary>
|
||||
NULL = 1 << 0,
|
||||
|
||||
Bios = 1 << 1,
|
||||
Device = 1 << 2,
|
||||
Mechanical = 1 << 3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -495,10 +503,14 @@ namespace SabreTools.Library.DatItems
|
||||
[Flags]
|
||||
public enum Runnable
|
||||
{
|
||||
NULL,
|
||||
No,
|
||||
Partial,
|
||||
Yes,
|
||||
/// <summary>
|
||||
/// This is a fake flag that is used for filter only
|
||||
/// </summary>
|
||||
NULL = 0,
|
||||
|
||||
No = 1 << 0,
|
||||
Partial = 1 << 1,
|
||||
Yes = 1 << 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -507,9 +519,13 @@ namespace SabreTools.Library.DatItems
|
||||
[Flags]
|
||||
public enum Supported
|
||||
{
|
||||
NULL,
|
||||
No,
|
||||
Partial,
|
||||
Yes,
|
||||
/// <summary>
|
||||
/// This is a fake flag that is used for filter only
|
||||
/// </summary>
|
||||
NULL = 0,
|
||||
|
||||
No = 1 << 0,
|
||||
Partial = 1 << 1,
|
||||
Yes = 1 << 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace SabreTools.Library.DatItems
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public MachineType MachineType { get; set; } = MachineType.NULL;
|
||||
public MachineType MachineType { get; set; } = 0x0;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -740,9 +740,9 @@ namespace SabreTools.Library.DatItems
|
||||
return false;
|
||||
|
||||
// Machine_Type
|
||||
if (filter.Machine_Type.MatchesPositive(MachineType.NULL, MachineType) == false)
|
||||
if (filter.Machine_Type.MatchesPositive(0x0, MachineType) == false)
|
||||
return false;
|
||||
if (filter.Machine_Type.MatchesNegative(MachineType.NULL, MachineType) == true)
|
||||
if (filter.Machine_Type.MatchesNegative(0x0, MachineType) == true)
|
||||
return false;
|
||||
|
||||
#endregion
|
||||
@@ -1501,7 +1501,7 @@ namespace SabreTools.Library.DatItems
|
||||
SampleOf = null;
|
||||
|
||||
if (fields.Contains(Field.Machine_Type))
|
||||
MachineType = MachineType.NULL;
|
||||
MachineType = 0x0;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
@@ -31,7 +30,7 @@ namespace SabreTools.Library.Filtering
|
||||
public FilterItem<string> Machine_RomOf { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<string> Machine_CloneOf { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<string> Machine_SampleOf { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<MachineType> Machine_Type { get; private set; } = new FilterItem<MachineType>() { Positive = MachineType.NULL, Negative = MachineType.NULL };
|
||||
public FilterItem<MachineType> Machine_Type { get; private set; } = new FilterItem<MachineType>() { Positive = 0x0, Negative = 0x0 };
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user