[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:
Matt Nadareski
2017-05-14 23:53:03 -07:00
parent bad61d1ed1
commit c65dd866d6
8 changed files with 70 additions and 49 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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)

View File

@@ -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,

View File

@@ -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);
}
});

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,