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
|
namespace SabreTools.Library.Dats
|
||||||
{
|
{
|
||||||
public class Archive : DatItem, ICloneable
|
public class Archive : DatItem
|
||||||
{
|
{
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ namespace SabreTools.Library.Dats
|
|||||||
|
|
||||||
#region Cloning Methods
|
#region Cloning Methods
|
||||||
|
|
||||||
public object Clone()
|
public new object Clone()
|
||||||
{
|
{
|
||||||
return new Archive()
|
return new Archive()
|
||||||
{
|
{
|
||||||
@@ -28,7 +28,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Type = this.Type,
|
Type = this.Type,
|
||||||
Dupe = this.Dupe,
|
Dupe = this.Dupe,
|
||||||
|
|
||||||
Machine = this.Machine,
|
Machine = (Machine)this.Machine.Clone(),
|
||||||
|
|
||||||
Supported = this.Supported,
|
Supported = this.Supported,
|
||||||
Publisher = this.Publisher,
|
Publisher = this.Publisher,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using SabreTools.Library.Data;
|
|||||||
|
|
||||||
namespace SabreTools.Library.Dats
|
namespace SabreTools.Library.Dats
|
||||||
{
|
{
|
||||||
public class BiosSet : DatItem, ICloneable
|
public class BiosSet : DatItem
|
||||||
{
|
{
|
||||||
#region Private instance variables
|
#region Private instance variables
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ namespace SabreTools.Library.Dats
|
|||||||
|
|
||||||
#region Cloning Methods
|
#region Cloning Methods
|
||||||
|
|
||||||
public object Clone()
|
public new object Clone()
|
||||||
{
|
{
|
||||||
return new BiosSet()
|
return new BiosSet()
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Type = this.Type,
|
Type = this.Type,
|
||||||
Dupe = this.Dupe,
|
Dupe = this.Dupe,
|
||||||
|
|
||||||
Machine = this.Machine,
|
Machine = (Machine)this.Machine.Clone(),
|
||||||
|
|
||||||
Supported = this.Supported,
|
Supported = this.Supported,
|
||||||
Publisher = this.Publisher,
|
Publisher = this.Publisher,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using NaturalSort;
|
|||||||
|
|
||||||
namespace SabreTools.Library.Dats
|
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
|
#region Protected instance variables
|
||||||
|
|
||||||
@@ -144,6 +144,31 @@ namespace SabreTools.Library.Dats
|
|||||||
|
|
||||||
#region Instance Methods
|
#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
|
#region Comparision Methods
|
||||||
|
|
||||||
public int CompareTo(DatItem other)
|
public int CompareTo(DatItem other)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using SabreTools.Library.Data;
|
|||||||
|
|
||||||
namespace SabreTools.Library.Dats
|
namespace SabreTools.Library.Dats
|
||||||
{
|
{
|
||||||
public class Disk : DatItem, ICloneable
|
public class Disk : DatItem
|
||||||
{
|
{
|
||||||
#region Private instance variables
|
#region Private instance variables
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ namespace SabreTools.Library.Dats
|
|||||||
|
|
||||||
#region Cloning Methods
|
#region Cloning Methods
|
||||||
|
|
||||||
public object Clone()
|
public new object Clone()
|
||||||
{
|
{
|
||||||
return new Disk()
|
return new Disk()
|
||||||
{
|
{
|
||||||
@@ -79,7 +79,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Type = this.Type,
|
Type = this.Type,
|
||||||
Dupe = this.Dupe,
|
Dupe = this.Dupe,
|
||||||
|
|
||||||
Machine = this.Machine,
|
Machine = (Machine)this.Machine.Clone(),
|
||||||
|
|
||||||
Supported = this.Supported,
|
Supported = this.Supported,
|
||||||
Publisher = this.Publisher,
|
Publisher = this.Publisher,
|
||||||
|
|||||||
@@ -250,41 +250,37 @@ namespace SabreTools.Library.Dats
|
|||||||
List<DatItem> newItems = new List<DatItem>();
|
List<DatItem> newItems = new List<DatItem>();
|
||||||
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
{
|
{
|
||||||
try
|
// Clone the item first for easier working
|
||||||
|
DatItem newItem = (DatItem)item.Clone();
|
||||||
|
|
||||||
|
// Update machine name
|
||||||
|
if (!String.IsNullOrEmpty(newItem.Machine.Name) && mapping.ContainsKey(newItem.Machine.Name))
|
||||||
{
|
{
|
||||||
// Update machine name
|
newItem.Machine.Name = mapping[newItem.Machine.Name];
|
||||||
if (item.Machine.Name != null && mapping.ContainsKey(item.Machine.Name))
|
|
||||||
{
|
|
||||||
item.Machine.Name = mapping[item.Machine.Name];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update cloneof
|
|
||||||
if (item.Machine.CloneOf != null && mapping.ContainsKey(item.Machine.CloneOf))
|
|
||||||
{
|
|
||||||
item.Machine.CloneOf = mapping[item.Machine.CloneOf];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update romof
|
|
||||||
if (item.Machine.RomOf != null && mapping.ContainsKey(item.Machine.RomOf))
|
|
||||||
{
|
|
||||||
item.Machine.RomOf = mapping[item.Machine.RomOf];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update sampleof
|
|
||||||
if (item.Machine.SampleOf != null && mapping.ContainsKey(item.Machine.SampleOf))
|
|
||||||
{
|
|
||||||
item.Machine.SampleOf = mapping[item.Machine.SampleOf];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the new item to the output list
|
|
||||||
lock (newItems)
|
|
||||||
{
|
|
||||||
newItems.Add(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
// Update cloneof
|
||||||
|
if (!String.IsNullOrEmpty(newItem.Machine.CloneOf) && mapping.ContainsKey(newItem.Machine.CloneOf))
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning(ex.ToString());
|
newItem.Machine.CloneOf = mapping[newItem.Machine.CloneOf];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update romof
|
||||||
|
if (!String.IsNullOrEmpty(newItem.Machine.RomOf) && mapping.ContainsKey(newItem.Machine.RomOf))
|
||||||
|
{
|
||||||
|
newItem.Machine.RomOf = mapping[newItem.Machine.RomOf];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update sampleof
|
||||||
|
if (!String.IsNullOrEmpty(newItem.Machine.SampleOf) && mapping.ContainsKey(newItem.Machine.SampleOf))
|
||||||
|
{
|
||||||
|
newItem.Machine.SampleOf = mapping[newItem.Machine.SampleOf];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the new newItem to the output list
|
||||||
|
lock (newItems)
|
||||||
|
{
|
||||||
|
newItems.Add(newItem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using SabreTools.Library.Data;
|
|||||||
|
|
||||||
namespace SabreTools.Library.Dats
|
namespace SabreTools.Library.Dats
|
||||||
{
|
{
|
||||||
public class Release : DatItem, ICloneable
|
public class Release : DatItem
|
||||||
{
|
{
|
||||||
#region Private instance variables
|
#region Private instance variables
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ namespace SabreTools.Library.Dats
|
|||||||
|
|
||||||
#region Cloning Methods
|
#region Cloning Methods
|
||||||
|
|
||||||
public object Clone()
|
public new object Clone()
|
||||||
{
|
{
|
||||||
return new Release()
|
return new Release()
|
||||||
{
|
{
|
||||||
@@ -67,7 +67,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Type = this.Type,
|
Type = this.Type,
|
||||||
Dupe = this.Dupe,
|
Dupe = this.Dupe,
|
||||||
|
|
||||||
Machine = this.Machine,
|
Machine = (Machine)this.Machine.Clone(),
|
||||||
|
|
||||||
Supported = this.Supported,
|
Supported = this.Supported,
|
||||||
Publisher = this.Publisher,
|
Publisher = this.Publisher,
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Type = this.Type,
|
Type = this.Type,
|
||||||
Dupe = this.Dupe,
|
Dupe = this.Dupe,
|
||||||
|
|
||||||
Machine = this.Machine,
|
Machine = (Machine)this.Machine.Clone(),
|
||||||
|
|
||||||
Supported = this.Supported,
|
Supported = this.Supported,
|
||||||
Publisher = this.Publisher,
|
Publisher = this.Publisher,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using SabreTools.Library.Data;
|
|||||||
|
|
||||||
namespace SabreTools.Library.Dats
|
namespace SabreTools.Library.Dats
|
||||||
{
|
{
|
||||||
public class Sample : DatItem, ICloneable
|
public class Sample : DatItem
|
||||||
{
|
{
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ namespace SabreTools.Library.Dats
|
|||||||
|
|
||||||
#region Cloning Methods
|
#region Cloning Methods
|
||||||
|
|
||||||
public object Clone()
|
public new object Clone()
|
||||||
{
|
{
|
||||||
return new Sample()
|
return new Sample()
|
||||||
{
|
{
|
||||||
@@ -29,7 +29,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Type = this.Type,
|
Type = this.Type,
|
||||||
Dupe = this.Dupe,
|
Dupe = this.Dupe,
|
||||||
|
|
||||||
Machine = this.Machine,
|
Machine = (Machine)this.Machine.Clone(),
|
||||||
|
|
||||||
Supported = this.Supported,
|
Supported = this.Supported,
|
||||||
Publisher = this.Publisher,
|
Publisher = this.Publisher,
|
||||||
|
|||||||
Reference in New Issue
Block a user