[DatFile, Machine] Fix description-to-name

This commit is contained in:
Matt Nadareski
2017-07-17 13:47:51 -07:00
parent a5ef8aeb0e
commit e4776cb43a
3 changed files with 89 additions and 74 deletions

View File

@@ -5,7 +5,7 @@ using SabreTools.Library.Data;
namespace SabreTools.Library.Dats namespace SabreTools.Library.Dats
{ {
public struct Machine public class Machine
{ {
#region Protected instance variables #region Protected instance variables
@@ -35,6 +35,28 @@ namespace SabreTools.Library.Dats
#region Constructors #region Constructors
/// <summary>
/// Create a new Machine object
/// </summary>
public Machine()
{
Name = null;
Comment = null;
Description = null;
Year = null;
Manufacturer = null;
RomOf = null;
CloneOf = null;
SampleOf = null;
SourceFile = null;
Runnable = null;
Board = null;
RebuildTo = null;
Devices = null;
MachineType = MachineType.NULL;
_guid = new Guid();
}
/// <summary> /// <summary>
/// Create a new Machine object with the included information /// Create a new Machine object with the included information
/// </summary> /// </summary>
@@ -63,54 +85,40 @@ namespace SabreTools.Library.Dats
#region Equality comparerers #region Equality comparerers
/// <summary>
/// Override the equality comparer
/// </summary>
public static bool operator ==(Machine a, Machine b)
{
return (a.Name == b.Name
&& a.Comment == b.Comment
&& a.Description == b.Description
&& a.Year == b.Year
&& a.Manufacturer == b.Manufacturer
&& a.RomOf == b.RomOf
&& a.CloneOf == b.CloneOf
&& a.SampleOf == b.SampleOf
&& a.SourceFile == b.SourceFile
&& a.Runnable == b.Runnable
&& a.Board == b.Board
&& a.RebuildTo == b.RebuildTo
&& a.Devices == b.Devices
&& a.MachineType == b.MachineType);
}
/// <summary>
/// Override the inequality comparer
/// </summary>
public static bool operator !=(Machine a, Machine b)
{
return !(a == b);
}
/// <summary> /// <summary>
/// Override the Equals method /// Override the Equals method
/// </summary> /// </summary>
public override bool Equals(object o) public override bool Equals(object o)
{ {
if (o.GetType() != typeof(Machine)) if (this == null && o == null)
{
return true;
}
else if (this == null || o == null)
{
return false;
}
else if (o.GetType() != typeof(Machine))
{ {
return false; return false;
} }
return this == (Machine)o; Machine b = (Machine)o;
}
/// <summary> return (this.Name == b.Name
/// Override the GetHashCode method && this.Comment == b.Comment
/// </summary> && this.Description == b.Description
public override int GetHashCode() && this.Year == b.Year
{ && this.Manufacturer == b.Manufacturer
return OCRC.OptimizedCRC.Compute(_guid.ToByteArray()); && this.RomOf == b.RomOf
&& this.CloneOf == b.CloneOf
&& this.SampleOf == b.SampleOf
&& this.SourceFile == b.SourceFile
&& this.Runnable == b.Runnable
&& this.Board == b.Board
&& this.RebuildTo == b.RebuildTo
&& this.Devices == b.Devices
&& this.MachineType == b.MachineType);
} }
#endregion #endregion

View File

@@ -180,10 +180,12 @@ namespace SabreTools.Library.Dats
/// <param name="single">True if all games should be replaced by '!', false otherwise</param> /// <param name="single">True if all games should be replaced by '!', false otherwise</param>
/// <param name="root">String representing root directory to compare against for length calculation</param> /// <param name="root">String representing root directory to compare against for length calculation</param>
public void Filter(Filter filter, bool single, bool trim, string root) public void Filter(Filter filter, bool single, bool trim, string root)
{
try
{ {
// Loop over every key in the dictionary // Loop over every key in the dictionary
List<string> keys = Keys.ToList(); List<string> keys = Keys.ToList();
Parallel.ForEach(keys, key => foreach (string key in keys)
{ {
// For every item in the current key // For every item in the current key
List<DatItem> items = this[key]; List<DatItem> items = this[key];
@@ -222,7 +224,12 @@ namespace SabreTools.Library.Dats
Remove(key); Remove(key);
AddRange(key, newitems); AddRange(key, newitems);
}); }
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
}
} }
/// <summary> /// <summary>
@@ -281,7 +288,7 @@ namespace SabreTools.Library.Dats
} }
// Add the new item to the output list // Add the new item to the output list
items.Add(item); newItems.Add(item);
} }
// Replace the old list of roms with the new one // Replace the old list of roms with the new one