mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile, DatItem] Fix desc-to-name replacements
Previously, sets that had multiple items would trigger issues because of shared information in the items, mostly the Machine parts. By making all of it a clone, it takes a little more memory but ends up resolving all issues in desc-to-name mapping and replacement.
This commit is contained in:
@@ -3,7 +3,7 @@ using SabreTools.Library.Data;
|
||||
|
||||
namespace SabreTools.Library.Dats
|
||||
{
|
||||
public class Archive : DatItem, ICloneable
|
||||
public class Archive : DatItem
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace SabreTools.Library.Dats
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public object Clone()
|
||||
public new object Clone()
|
||||
{
|
||||
return new Archive()
|
||||
{
|
||||
@@ -28,7 +28,7 @@ namespace SabreTools.Library.Dats
|
||||
Type = this.Type,
|
||||
Dupe = this.Dupe,
|
||||
|
||||
Machine = this.Machine,
|
||||
Machine = (Machine)this.Machine.Clone(),
|
||||
|
||||
Supported = this.Supported,
|
||||
Publisher = this.Publisher,
|
||||
|
||||
@@ -3,7 +3,7 @@ using SabreTools.Library.Data;
|
||||
|
||||
namespace SabreTools.Library.Dats
|
||||
{
|
||||
public class BiosSet : DatItem, ICloneable
|
||||
public class BiosSet : DatItem
|
||||
{
|
||||
#region Private instance variables
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace SabreTools.Library.Dats
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public object Clone()
|
||||
public new object Clone()
|
||||
{
|
||||
return new BiosSet()
|
||||
{
|
||||
@@ -50,7 +50,7 @@ namespace SabreTools.Library.Dats
|
||||
Type = this.Type,
|
||||
Dupe = this.Dupe,
|
||||
|
||||
Machine = this.Machine,
|
||||
Machine = (Machine)this.Machine.Clone(),
|
||||
|
||||
Supported = this.Supported,
|
||||
Publisher = this.Publisher,
|
||||
|
||||
@@ -14,7 +14,7 @@ using NaturalSort;
|
||||
|
||||
namespace SabreTools.Library.Dats
|
||||
{
|
||||
public abstract class DatItem : IEquatable<DatItem>, IComparable<DatItem>
|
||||
public abstract class DatItem : IEquatable<DatItem>, IComparable<DatItem>, ICloneable
|
||||
{
|
||||
#region Protected instance variables
|
||||
|
||||
@@ -144,6 +144,31 @@ namespace SabreTools.Library.Dats
|
||||
|
||||
#region Instance Methods
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
switch (_itemType)
|
||||
{
|
||||
case ItemType.Archive:
|
||||
return ((Archive)this).Clone();
|
||||
case ItemType.BiosSet:
|
||||
return ((BiosSet)this).Clone();
|
||||
case ItemType.Disk:
|
||||
return ((Disk)this).Clone();
|
||||
case ItemType.Release:
|
||||
return ((Release)this).Clone();
|
||||
case ItemType.Rom:
|
||||
return ((Rom)this).Clone();
|
||||
case ItemType.Sample:
|
||||
return ((Sample)this).Clone();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
public int CompareTo(DatItem other)
|
||||
|
||||
@@ -4,7 +4,7 @@ using SabreTools.Library.Data;
|
||||
|
||||
namespace SabreTools.Library.Dats
|
||||
{
|
||||
public class Disk : DatItem, ICloneable
|
||||
public class Disk : DatItem
|
||||
{
|
||||
#region Private instance variables
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace SabreTools.Library.Dats
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public object Clone()
|
||||
public new object Clone()
|
||||
{
|
||||
return new Disk()
|
||||
{
|
||||
@@ -79,7 +79,7 @@ namespace SabreTools.Library.Dats
|
||||
Type = this.Type,
|
||||
Dupe = this.Dupe,
|
||||
|
||||
Machine = this.Machine,
|
||||
Machine = (Machine)this.Machine.Clone(),
|
||||
|
||||
Supported = this.Supported,
|
||||
Publisher = this.Publisher,
|
||||
|
||||
@@ -250,41 +250,37 @@ namespace SabreTools.Library.Dats
|
||||
List<DatItem> newItems = new List<DatItem>();
|
||||
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// Clone the item first for easier working
|
||||
DatItem newItem = (DatItem)item.Clone();
|
||||
|
||||
// Update machine name
|
||||
if (item.Machine.Name != null && mapping.ContainsKey(item.Machine.Name))
|
||||
if (!String.IsNullOrEmpty(newItem.Machine.Name) && mapping.ContainsKey(newItem.Machine.Name))
|
||||
{
|
||||
item.Machine.Name = mapping[item.Machine.Name];
|
||||
newItem.Machine.Name = mapping[newItem.Machine.Name];
|
||||
}
|
||||
|
||||
// Update cloneof
|
||||
if (item.Machine.CloneOf != null && mapping.ContainsKey(item.Machine.CloneOf))
|
||||
if (!String.IsNullOrEmpty(newItem.Machine.CloneOf) && mapping.ContainsKey(newItem.Machine.CloneOf))
|
||||
{
|
||||
item.Machine.CloneOf = mapping[item.Machine.CloneOf];
|
||||
newItem.Machine.CloneOf = mapping[newItem.Machine.CloneOf];
|
||||
}
|
||||
|
||||
// Update romof
|
||||
if (item.Machine.RomOf != null && mapping.ContainsKey(item.Machine.RomOf))
|
||||
if (!String.IsNullOrEmpty(newItem.Machine.RomOf) && mapping.ContainsKey(newItem.Machine.RomOf))
|
||||
{
|
||||
item.Machine.RomOf = mapping[item.Machine.RomOf];
|
||||
newItem.Machine.RomOf = mapping[newItem.Machine.RomOf];
|
||||
}
|
||||
|
||||
// Update sampleof
|
||||
if (item.Machine.SampleOf != null && mapping.ContainsKey(item.Machine.SampleOf))
|
||||
if (!String.IsNullOrEmpty(newItem.Machine.SampleOf) && mapping.ContainsKey(newItem.Machine.SampleOf))
|
||||
{
|
||||
item.Machine.SampleOf = mapping[item.Machine.SampleOf];
|
||||
newItem.Machine.SampleOf = mapping[newItem.Machine.SampleOf];
|
||||
}
|
||||
|
||||
// Add the new item to the output list
|
||||
// Add the new newItem to the output list
|
||||
lock (newItems)
|
||||
{
|
||||
newItems.Add(item);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Warning(ex.ToString());
|
||||
newItems.Add(newItem);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using SabreTools.Library.Data;
|
||||
|
||||
namespace SabreTools.Library.Dats
|
||||
{
|
||||
public class Release : DatItem, ICloneable
|
||||
public class Release : DatItem
|
||||
{
|
||||
#region Private instance variables
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace SabreTools.Library.Dats
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public object Clone()
|
||||
public new object Clone()
|
||||
{
|
||||
return new Release()
|
||||
{
|
||||
@@ -67,7 +67,7 @@ namespace SabreTools.Library.Dats
|
||||
Type = this.Type,
|
||||
Dupe = this.Dupe,
|
||||
|
||||
Machine = this.Machine,
|
||||
Machine = (Machine)this.Machine.Clone(),
|
||||
|
||||
Supported = this.Supported,
|
||||
Publisher = this.Publisher,
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace SabreTools.Library.Dats
|
||||
Type = this.Type,
|
||||
Dupe = this.Dupe,
|
||||
|
||||
Machine = this.Machine,
|
||||
Machine = (Machine)this.Machine.Clone(),
|
||||
|
||||
Supported = this.Supported,
|
||||
Publisher = this.Publisher,
|
||||
|
||||
@@ -4,7 +4,7 @@ using SabreTools.Library.Data;
|
||||
|
||||
namespace SabreTools.Library.Dats
|
||||
{
|
||||
public class Sample : DatItem, ICloneable
|
||||
public class Sample : DatItem
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace SabreTools.Library.Dats
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public object Clone()
|
||||
public new object Clone()
|
||||
{
|
||||
return new Sample()
|
||||
{
|
||||
@@ -29,7 +29,7 @@ namespace SabreTools.Library.Dats
|
||||
Type = this.Type,
|
||||
Dupe = this.Dupe,
|
||||
|
||||
Machine = this.Machine,
|
||||
Machine = (Machine)this.Machine.Clone(),
|
||||
|
||||
Supported = this.Supported,
|
||||
Publisher = this.Publisher,
|
||||
|
||||
Reference in New Issue
Block a user