Reduce more Linq usage

This commit is contained in:
Matt Nadareski
2024-12-06 13:57:48 -05:00
parent ea753aeb06
commit d78ff5eb67
7 changed files with 89 additions and 101 deletions

View File

@@ -87,7 +87,7 @@ namespace SabreTools.Core.Tools
if (string.IsNullOrEmpty(input)) if (string.IsNullOrEmpty(input))
return string.Empty; return string.Empty;
return new string(input.Where(c => c <= 255).ToArray()); return new string(input!.Where(c => c <= 255).ToArray());
} }
#endregion #endregion

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Xml.Serialization; using System.Xml.Serialization;
using SabreTools.Models; using SabreTools.Models;
@@ -22,21 +21,13 @@ namespace SabreTools.Core.Tools
if (fields == null) if (fields == null)
return null; return null;
#if NET20 || NET35 || NET40 FieldInfo[] noFilterFields = Array.FindAll(fields,
return fields f => f.IsLiteral
.Where(f => f.IsLiteral && !f.IsInitOnly) && !f.IsInitOnly
.Where(f => Attribute.GetCustomAttributes(f, typeof(NoFilterAttribute)).Length == 0) && Attribute.GetCustomAttributes(f, typeof(NoFilterAttribute)).Length == 0);
.Select(f => f.GetRawConstantValue() as string) string[] constantValues = Array.ConvertAll(noFilterFields,
.Where(v => v != null) f => (f.GetRawConstantValue() as string) ?? string.Empty);
.ToArray()!; return Array.FindAll(constantValues, s => s.Length > 0);
#else
return fields
.Where(f => f.IsLiteral && !f.IsInitOnly)
.Where(f => !f.CustomAttributes.Any(a => a.AttributeType == typeof(NoFilterAttribute)))
.Select(f => f.GetRawConstantValue() as string)
.Where(v => v != null)
.ToArray()!;
#endif
} }
/// <summary> /// <summary>

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using SabreTools.Core.Tools; using SabreTools.Core.Tools;
using SabreTools.DatItems; using SabreTools.DatItems;
@@ -270,8 +269,7 @@ namespace SabreTools.DatFiles
} }
if (item.ContainsKey(Models.Metadata.Machine.DiskKey)) if (item.ContainsKey(Models.Metadata.Machine.DiskKey))
{ {
var items = ReadItemArray<Models.Metadata.Disk>(item, Models.Metadata.Machine.DiskKey) var items = ReadItemArray<Models.Metadata.Disk>(item, Models.Metadata.Machine.DiskKey);
?? ReadItemArray<Models.Metadata.DatItem>(item, Models.Metadata.Machine.DiskKey)?.Select(d => (d as Models.Metadata.Disk)!)?.ToArray(); // TODO: Remove case when Serialization fixed
ProcessItems(items, machine, machineIndex, source, sourceIndex, statsOnly); ProcessItems(items, machine, machineIndex, source, sourceIndex, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.DisplayKey)) if (item.ContainsKey(Models.Metadata.Machine.DisplayKey))
@@ -332,8 +330,7 @@ namespace SabreTools.DatFiles
} }
if (item.ContainsKey(Models.Metadata.Machine.RomKey)) if (item.ContainsKey(Models.Metadata.Machine.RomKey))
{ {
var items = ReadItemArray<Models.Metadata.Rom>(item, Models.Metadata.Machine.RomKey) var items = ReadItemArray<Models.Metadata.Rom>(item, Models.Metadata.Machine.RomKey);
?? ReadItemArray<Models.Metadata.DatItem>(item, Models.Metadata.Machine.RomKey)?.Select(d => (d as Models.Metadata.Rom)!)?.ToArray(); // TODO: Remove case when Serialization fixed
ProcessItems(items, machine, machineIndex, source, sourceIndex, statsOnly); ProcessItems(items, machine, machineIndex, source, sourceIndex, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.SampleKey)) if (item.ContainsKey(Models.Metadata.Machine.SampleKey))

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Xml.Serialization; using System.Xml.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
using SabreTools.Core.Filter; using SabreTools.Core.Filter;
@@ -829,7 +828,8 @@ namespace SabreTools.DatFiles
// If we have an item type not in the list of supported values // If we have an item type not in the list of supported values
string datFormat = Header?.GetFieldValue<DatFormat>(DatHeader.DatFormatKey).ToString() ?? "Unknown Format"; string datFormat = Header?.GetFieldValue<DatFormat>(DatHeader.DatFormatKey).ToString() ?? "Unknown Format";
if (!GetSupportedTypes().Contains(datItem.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>())) ItemType itemType = datItem.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>();
if (!Array.Exists(GetSupportedTypes(), t => t == itemType))
{ {
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None); string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
logger?.Verbose($"Item '{itemString}' was skipped because it was not supported in {datFormat}"); logger?.Verbose($"Item '{itemString}' was skipped because it was not supported in {datFormat}");
@@ -898,7 +898,8 @@ namespace SabreTools.DatFiles
// If we have an item type not in the list of supported values // If we have an item type not in the list of supported values
string datFormat = Header?.GetFieldValue<DatFormat>(DatHeader.DatFormatKey).ToString() ?? "Unknown Format"; string datFormat = Header?.GetFieldValue<DatFormat>(DatHeader.DatFormatKey).ToString() ?? "Unknown Format";
if (!GetSupportedTypes().Contains(datItem.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>())) ItemType itemType = datItem.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>();
if (!Array.Exists(GetSupportedTypes(), t => t == itemType))
{ {
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None); string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
logger?.Verbose($"Item '{itemString}' was skipped because it was not supported in {datFormat}"); logger?.Verbose($"Item '{itemString}' was skipped because it was not supported in {datFormat}");

View File

@@ -434,10 +434,9 @@ namespace SabreTools.DatFiles
return []; return [];
// Filter the list // Filter the list
return fi.Where(i => i != null) return fi.FindAll(i => i != null)
.Where(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true) .FindAll(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true)
.Where(i => i.GetFieldValue<Machine>(DatItem.MachineKey) != null) .FindAll(i => i.GetFieldValue<Machine>(DatItem.MachineKey) != null);
.ToList();
} }
} }
@@ -1116,11 +1115,9 @@ namespace SabreTools.DatFiles
if (datItem is Rom) if (datItem is Rom)
{ {
string[] splitname = machine.Split('.'); string[] splitname = machine.Split('.');
#if NET20 || NET35 machine = datItem.GetFieldValue<Machine>(DatItem.MachineKey)!
machine = datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1).ToArray())}"; .GetStringFieldValue(Models.Metadata.Machine.NameKey)
#else + $"/{string.Join(".", splitname, 0, splitname.Length > 1 ? splitname.Length - 1 : 1)}";
machine = datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}";
#endif
} }
// Strip off "Default" prefix only for ORPG // Strip off "Default" prefix only for ORPG
@@ -1254,17 +1251,17 @@ namespace SabreTools.DatFiles
// Get all device reference names from the current machine // Get all device reference names from the current machine
List<string?> deviceReferences = this[machine]! List<string?> deviceReferences = this[machine]!
.Where(i => i is DeviceRef) .FindAll(i => i is DeviceRef)
.Select(i => i as DeviceRef) .ConvertAll(i => i as DeviceRef)
.Select(dr => dr!.GetName()) .ConvertAll(dr => dr!.GetName())
.Distinct() .Distinct()
.ToList(); .ToList();
// Get all slot option names from the current machine // Get all slot option names from the current machine
List<string?> slotOptions = this[machine]! List<string?> slotOptions = this[machine]!
.Where(i => i is Slot) .FindAll(i => i is Slot)
.Select(i => i as Slot) .ConvertAll(i => i as Slot)
.Where(s => s!.SlotOptionsSpecified) .FindAll(s => s!.SlotOptionsSpecified)
.SelectMany(s => s!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!) .SelectMany(s => s!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
.Select(so => so.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)) .Select(so => so.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey))
.Distinct() .Distinct()
@@ -1287,15 +1284,15 @@ namespace SabreTools.DatFiles
continue; continue;
newDeviceReferences.UnionWith(devItems newDeviceReferences.UnionWith(devItems
.Where(i => i is DeviceRef) .FindAll(i => i is DeviceRef)
.Select(i => (i as DeviceRef)!.GetName()!)); .ConvertAll(i => (i as DeviceRef)!.GetName()!));
// Set new machine information and add to the current machine // Set new machine information and add to the current machine
DatItem copyFrom = this[machine]![0]; DatItem copyFrom = this[machine]![0];
foreach (DatItem item in devItems) foreach (DatItem item in devItems)
{ {
// If the parent machine doesn't already contain this item, add it // If the parent machine doesn't already contain this item, add it
if (!this[machine]!.Any(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName())) if (!this[machine]!.Exists(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName()))
{ {
// Set that we found new items // Set that we found new items
foundnew = true; foundnew = true;
@@ -1337,8 +1334,8 @@ namespace SabreTools.DatFiles
continue; continue;
newSlotOptions.UnionWith(slotItems newSlotOptions.UnionWith(slotItems
.Where(i => i is Slot) .FindAll(i => i is Slot)
.Where(s => (s as Slot)!.SlotOptionsSpecified) .FindAll(s => (s as Slot)!.SlotOptionsSpecified)
.SelectMany(s => (s as Slot)!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!) .SelectMany(s => (s as Slot)!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
.Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!)); .Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!));
@@ -1347,7 +1344,7 @@ namespace SabreTools.DatFiles
foreach (DatItem item in slotItems) foreach (DatItem item in slotItems)
{ {
// If the parent machine doesn't already contain this item, add it // If the parent machine doesn't already contain this item, add it
if (!this[machine]!.Any(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName())) if (!this[machine]!.Exists(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName()))
{ {
// Set that we found new items // Set that we found new items
foundnew = true; foundnew = true;
@@ -1486,16 +1483,16 @@ namespace SabreTools.DatFiles
// If the merge tag exists and the parent already contains it, skip // If the merge tag exists and the parent already contains it, skip
if (mergeTag != null && this[cloneOf!]! if (mergeTag != null && this[cloneOf!]!
.Where(i => i is Disk) .FindAll(i => i is Disk)
.Select(i => (i as Disk)!.GetName()).Contains(mergeTag)) .ConvertAll(i => (i as Disk)!.GetName()).Contains(mergeTag))
{ {
continue; continue;
} }
// If the merge tag exists but the parent doesn't contain it, add to parent // If the merge tag exists but the parent doesn't contain it, add to parent
else if (mergeTag != null && !this[cloneOf!]! else if (mergeTag != null && !this[cloneOf!]!
.Where(i => i is Disk) .FindAll(i => i is Disk)
.Select(i => (i as Disk)!.GetName()).Contains(mergeTag)) .ConvertAll(i => (i as Disk)!.GetName()).Contains(mergeTag))
{ {
disk.CopyMachineInformation(copyFrom); disk.CopyMachineInformation(copyFrom);
Add(cloneOf!, disk); Add(cloneOf!, disk);
@@ -1514,7 +1511,8 @@ namespace SabreTools.DatFiles
{ {
// If the merge tag exists and the parent already contains it, skip // If the merge tag exists and the parent already contains it, skip
if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && this[cloneOf!]! if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && this[cloneOf!]!
.Where(i => i is Rom).Select(i => (i as Rom)!.GetName()) .FindAll(i => i is Rom)
.ConvertAll(i => (i as Rom)!.GetName())
.Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey))) .Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey)))
{ {
continue; continue;
@@ -1522,7 +1520,8 @@ namespace SabreTools.DatFiles
// If the merge tag exists but the parent doesn't contain it, add to subfolder of parent // If the merge tag exists but the parent doesn't contain it, add to subfolder of parent
else if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && !this[cloneOf!]! else if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && !this[cloneOf!]!
.Where(i => i is Rom).Select(i => (i as Rom)!.GetName()) .FindAll(i => i is Rom)
.ConvertAll(i => (i as Rom)!.GetName())
.Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey))) .Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey)))
{ {
if (subfolder) if (subfolder)

View File

@@ -302,7 +302,7 @@ namespace SabreTools.DatFiles
#endif #endif
// If there are no non-blank items, remove // If there are no non-blank items, remove
else if (!_buckets[key].Any(i => GetItem(i) != null && GetItem(i) is not Blank)) else if (!_buckets[key].Exists(i => GetItem(i) != null && GetItem(i) is not Blank))
#if NET40_OR_GREATER || NETCOREAPP #if NET40_OR_GREATER || NETCOREAPP
_buckets.TryRemove(key, out _); _buckets.TryRemove(key, out _);
#else #else
@@ -653,7 +653,8 @@ namespace SabreTools.DatFiles
} }
// Add back all roms with the proper flags // Add back all roms with the proper flags
_buckets[key] = output.Concat(left).Select(i => i.Item1).ToList(); List<(long, DatItem)> combined = [.. output, .. left];
_buckets[key] = combined.ConvertAll(i => i.Item1);
return output; return output;
} }
@@ -699,7 +700,8 @@ namespace SabreTools.DatFiles
} }
// Add back all roms with the proper flags // Add back all roms with the proper flags
_buckets[key] = output.Concat(left).Select(i => i.Item1).ToList(); List<(long, DatItem)> combined = [.. output, .. left];
_buckets[key] = combined.ConvertAll(i => i.Item1);
return output; return output;
} }
@@ -1110,13 +1112,12 @@ namespace SabreTools.DatFiles
} }
var datItems = itemIndices var datItems = itemIndices
.Where(i => _items.ContainsKey(i)) .FindAll(i => _items.ContainsKey(i))
.Select(i => (i, _items[i])) .ConvertAll(i => (i, _items[i]));
.ToList();
Sort(ref datItems, norename); Sort(ref datItems, norename);
_buckets[bucketKeys[i]] = datItems.Select(m => m.Item1).ToList(); _buckets[bucketKeys[i]] = datItems.ConvertAll(m => m.Item1);
#if NET40_OR_GREATER || NETCOREAPP #if NET40_OR_GREATER || NETCOREAPP
}); });
#else #else
@@ -1532,11 +1533,9 @@ namespace SabreTools.DatFiles
if (datItem.Item2 is Rom) if (datItem.Item2 is Rom)
{ {
string[] splitname = machineName.Split('.'); string[] splitname = machineName.Split('.');
#if NET20 || NET35 machineName = datItem.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!
machineName = datItem.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1).ToArray())}"; .GetStringFieldValue(Models.Metadata.Machine.NameKey)
#else + $"/{string.Join(".", splitname, 0, splitname.Length > 1 ? splitname.Length - 1 : 1)}";
machineName = datItem.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}";
#endif
} }
// Strip off "Default" prefix only for ORPG // Strip off "Default" prefix only for ORPG
@@ -1682,18 +1681,19 @@ namespace SabreTools.DatFiles
continue; continue;
// Get all device reference names from the current machine // Get all device reference names from the current machine
List<string?> deviceReferences = items List<(long, DatItem)> itemsList = [.. items];
.Where(i => i.Item2 is DeviceRef) List<string?> deviceReferences = itemsList
.Select(i => i.Item2 as DeviceRef) .FindAll(i => i.Item2 is DeviceRef)
.Select(dr => dr!.GetName()) .ConvertAll(i => i.Item2 as DeviceRef)
.ConvertAll(dr => dr!.GetName())
.Distinct() .Distinct()
.ToList(); .ToList();
// Get all slot option names from the current machine // Get all slot option names from the current machine
List<string?> slotOptions = items List<string?> slotOptions = itemsList
.Where(i => i.Item2 is Slot) .FindAll(i => i.Item2 is Slot)
.Select(i => i.Item2 as Slot) .ConvertAll(i => i.Item2 as Slot)
.Where(s => s!.SlotOptionsSpecified) .FindAll(s => s!.SlotOptionsSpecified)
.SelectMany(s => s!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!) .SelectMany(s => s!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
.Select(so => so.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)) .Select(so => so.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey))
.Distinct() .Distinct()
@@ -1716,20 +1716,21 @@ namespace SabreTools.DatFiles
continue; continue;
// Add to the list of new device reference names // Add to the list of new device reference names
newDeviceReferences.UnionWith(devItems List<(long, DatItem)> devItemsList = [.. devItems];
.Where(i => i.Item2 is DeviceRef) newDeviceReferences.UnionWith(devItemsList
.Select(i => (i.Item2 as DeviceRef)!.GetName()!)); .FindAll(i => i.Item2 is DeviceRef)
.ConvertAll(i => (i.Item2 as DeviceRef)!.GetName()!));
// Set new machine information and add to the current machine // Set new machine information and add to the current machine
var copyFrom = GetMachineForItem(GetItemsForBucket(game)![0].Item1); var copyFrom = GetMachineForItem(items[0].Item1);
if (copyFrom.Item2 == null) if (copyFrom.Item2 == null)
continue; continue;
foreach ((long, DatItem) item in devItems) foreach ((long, DatItem) item in devItems)
{ {
// If the parent machine doesn't already contain this item, add it // If the parent machine doesn't already contain this item, add it
if (!GetItemsForBucket(game)! if (!Array.Exists(items,
.Any(i => i.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) i => i.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey)
&& i.Item2.GetName() == item.Item2.GetName())) && i.Item2.GetName() == item.Item2.GetName()))
{ {
// Set that we found new items // Set that we found new items
@@ -1771,9 +1772,10 @@ namespace SabreTools.DatFiles
continue; continue;
// Add to the list of new slot option names // Add to the list of new slot option names
newSlotOptions.UnionWith(slotItems List<(long, DatItem)> slotItemsList = [.. slotItems];
.Where(i => i.Item2 is Slot) newSlotOptions.UnionWith(slotItemsList
.Where(s => (s.Item2 as Slot)!.SlotOptionsSpecified) .FindAll(i => i.Item2 is Slot)
.FindAll(s => (s.Item2 as Slot)!.SlotOptionsSpecified)
.SelectMany(s => (s.Item2 as Slot)!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!) .SelectMany(s => (s.Item2 as Slot)!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
.Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!)); .Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!));
@@ -1785,8 +1787,8 @@ namespace SabreTools.DatFiles
foreach ((long, DatItem) item in slotItems) foreach ((long, DatItem) item in slotItems)
{ {
// If the parent machine doesn't already contain this item, add it // If the parent machine doesn't already contain this item, add it
if (!GetItemsForBucket(game)! if (!Array.Exists(items,
.Any(i => i.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) i => i.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey)
&& i.Item2.GetName() == item.Item2.GetName())) && i.Item2.GetName() == item.Item2.GetName()))
{ {
// Set that we found new items // Set that we found new items
@@ -1915,9 +1917,10 @@ namespace SabreTools.DatFiles
{ {
// Get the parent items and current machine name // Get the parent items and current machine name
var parentItems = GetItemsForBucket(cloneOf!); var parentItems = GetItemsForBucket(cloneOf!);
if (parentItems == null) if (parentItems == null || parentItems.Length == 0)
continue; continue;
List<(long, DatItem)> parentItemslist = [.. parentItems];
string? machineName = GetMachineForItem(item.Item1).Item2?.GetStringFieldValue(Models.Metadata.Machine.NameKey); string? machineName = GetMachineForItem(item.Item1).Item2?.GetStringFieldValue(Models.Metadata.Machine.NameKey);
// Special disk handling // Special disk handling
@@ -1926,18 +1929,18 @@ namespace SabreTools.DatFiles
string? mergeTag = disk.GetStringFieldValue(Models.Metadata.Disk.MergeKey); string? mergeTag = disk.GetStringFieldValue(Models.Metadata.Disk.MergeKey);
// If the merge tag exists and the parent already contains it, skip // If the merge tag exists and the parent already contains it, skip
if (mergeTag != null && parentItems if (mergeTag != null && parentItemslist
.Where(i => i.Item2 is Disk) .FindAll(i => i.Item2 is Disk)
.Select(i => (i.Item2 as Disk)!.GetName()) .ConvertAll(i => (i.Item2 as Disk)!.GetName())
.Contains(mergeTag)) .Contains(mergeTag))
{ {
continue; continue;
} }
// If the merge tag exists but the parent doesn't contain it, add to parent // If the merge tag exists but the parent doesn't contain it, add to parent
else if (mergeTag != null && !parentItems else if (mergeTag != null && !parentItemslist
.Where(i => i.Item2 is Disk) .FindAll(i => i.Item2 is Disk)
.Select(i => (i.Item2 as Disk)!.GetName()) .ConvertAll(i => (i.Item2 as Disk)!.GetName())
.Contains(mergeTag)) .Contains(mergeTag))
{ {
_itemToMachineMapping[item.Item1] = cloneOfMachine.Item1; _itemToMachineMapping[item.Item1] = cloneOfMachine.Item1;
@@ -1956,18 +1959,18 @@ namespace SabreTools.DatFiles
else if (item.Item2 is Rom rom) else if (item.Item2 is Rom rom)
{ {
// If the merge tag exists and the parent already contains it, skip // If the merge tag exists and the parent already contains it, skip
if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && parentItems if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && parentItemslist
.Where(i => i.Item2 is Rom) .FindAll(i => i.Item2 is Rom)
.Select(i => (i.Item2 as Rom)!.GetName()) .ConvertAll(i => (i.Item2 as Rom)!.GetName())
.Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey))) .Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey)))
{ {
continue; continue;
} }
// If the merge tag exists but the parent doesn't contain it, add to subfolder of parent // If the merge tag exists but the parent doesn't contain it, add to subfolder of parent
else if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && !parentItems else if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && !parentItemslist
.Where(i => i.Item2 is Rom) .FindAll(i => i.Item2 is Rom)
.Select(i => (i.Item2 as Rom)!.GetName()) .ConvertAll(i => (i.Item2 as Rom)!.GetName())
.Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey))) .Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey)))
{ {
if (subfolder) if (subfolder)
@@ -1989,7 +1992,7 @@ namespace SabreTools.DatFiles
} }
// All other that would be missing to subfolder of parent // All other that would be missing to subfolder of parent
else if (Array.IndexOf(parentItems, item) == -1) else if (parentItemslist.IndexOf(item) == -1)
{ {
if (subfolder) if (subfolder)
item.Item2.SetName($"{machineName}\\{item.Item2.GetName()}"); item.Item2.SetName($"{machineName}\\{item.Item2.GetName()}");

View File

@@ -462,10 +462,7 @@ namespace SabreTools.FileTypes.Archives
BinaryWriter sw = new(outputStream); BinaryWriter sw = new(outputStream);
// Write standard header and TGZ info // Write standard header and TGZ info
byte[] data = TorrentGZHeader byte[] data = [.. TorrentGZHeader, .. baseFile.MD5!, .. baseFile.CRC!];
.Concat(baseFile.MD5!) // MD5
.Concat(baseFile.CRC!) // CRC
.ToArray();
sw.Write(data); sw.Write(data);
sw.Write((ulong)(baseFile.Size ?? 0)); // Long size (Unsigned, Mirrored) sw.Write((ulong)(baseFile.Size ?? 0)); // Long size (Unsigned, Mirrored)