diff --git a/SabreTools.Library/Dats/Machine.cs b/SabreTools.Library/Dats/Machine.cs
index 3b6bfc25..bd0ef316 100644
--- a/SabreTools.Library/Dats/Machine.cs
+++ b/SabreTools.Library/Dats/Machine.cs
@@ -5,7 +5,7 @@ using SabreTools.Library.Data;
namespace SabreTools.Library.Dats
{
- public struct Machine
+ public class Machine
{
#region Protected instance variables
@@ -35,6 +35,28 @@ namespace SabreTools.Library.Dats
#region Constructors
+ ///
+ /// Create a new Machine object
+ ///
+ 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();
+ }
+
///
/// Create a new Machine object with the included information
///
@@ -63,54 +85,40 @@ namespace SabreTools.Library.Dats
#region Equality comparerers
- ///
- /// Override the equality comparer
- ///
- 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);
- }
-
- ///
- /// Override the inequality comparer
- ///
- public static bool operator !=(Machine a, Machine b)
- {
- return !(a == b);
- }
-
///
/// Override the Equals method
///
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 this == (Machine)o;
- }
+ Machine b = (Machine)o;
- ///
- /// Override the GetHashCode method
- ///
- public override int GetHashCode()
- {
- return OCRC.OptimizedCRC.Compute(_guid.ToByteArray());
+ return (this.Name == b.Name
+ && this.Comment == b.Comment
+ && this.Description == b.Description
+ && this.Year == b.Year
+ && this.Manufacturer == b.Manufacturer
+ && 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
diff --git a/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs b/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs
index b4f63086..d479afeb 100644
--- a/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs
+++ b/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs
@@ -604,7 +604,7 @@ namespace SabreTools.Library.Dats
innerDatdata.Filter(filter, trim, single, root);
// Try to output the file
- innerDatdata.WriteToFile((realOutDir == Environment.CurrentDirectory ? Path.GetDirectoryName(inputFileName) : realOutDir), overwrite: (realOutDir != Environment.CurrentDirectory));
+ innerDatdata.WriteToFile((realOutDir == Environment.CurrentDirectory ? Path.GetDirectoryName(inputFileName) : realOutDir), overwrite: (realOutDir != Environment.CurrentDirectory));
}
else if (Directory.Exists(inputFileName))
{
diff --git a/SabreTools.Library/Dats/Partials/DatFile.Manipulate.cs b/SabreTools.Library/Dats/Partials/DatFile.Manipulate.cs
index b5f3b4f1..769a5c53 100644
--- a/SabreTools.Library/Dats/Partials/DatFile.Manipulate.cs
+++ b/SabreTools.Library/Dats/Partials/DatFile.Manipulate.cs
@@ -181,48 +181,55 @@ namespace SabreTools.Library.Dats
/// String representing root directory to compare against for length calculation
public void Filter(Filter filter, bool single, bool trim, string root)
{
- // Loop over every key in the dictionary
- List keys = Keys.ToList();
- Parallel.ForEach(keys, key =>
+ try
{
- // For every item in the current key
- List items = this[key];
- List newitems = new List();
- foreach (DatItem item in items)
+ // Loop over every key in the dictionary
+ List keys = Keys.ToList();
+ foreach (string key in keys)
{
- // If the rom passes the filter, include it
- if (filter.ItemPasses(item))
+ // For every item in the current key
+ List items = this[key];
+ List newitems = new List();
+ foreach (DatItem item in items)
{
- // If we are in single game mode, rename all games
- if (single)
+ // If the rom passes the filter, include it
+ if (filter.ItemPasses(item))
{
- item.Machine.UpdateName("!");
- }
-
- // If we are in NTFS trim mode, trim the game name
- if (trim)
- {
- // Windows max name length is 260
- int usableLength = 260 - item.Machine.Name.Length - root.Length;
- if (item.Name.Length > usableLength)
+ // If we are in single game mode, rename all games
+ if (single)
{
- string ext = Path.GetExtension(item.Name);
- item.Name = item.Name.Substring(0, usableLength - ext.Length);
- item.Name += ext;
+ item.Machine.UpdateName("!");
+ }
+
+ // If we are in NTFS trim mode, trim the game name
+ if (trim)
+ {
+ // Windows max name length is 260
+ int usableLength = 260 - item.Machine.Name.Length - root.Length;
+ if (item.Name.Length > usableLength)
+ {
+ string ext = Path.GetExtension(item.Name);
+ item.Name = item.Name.Substring(0, usableLength - ext.Length);
+ item.Name += ext;
+ }
+ }
+
+ // Lock the list and add the item back
+ lock (newitems)
+ {
+ newitems.Add(item);
}
}
-
- // Lock the list and add the item back
- lock (newitems)
- {
- newitems.Add(item);
- }
}
- }
- Remove(key);
- AddRange(key, newitems);
- });
+ Remove(key);
+ AddRange(key, newitems);
+ }
+ }
+ catch (Exception ex)
+ {
+ Globals.Logger.Error(ex.ToString());
+ }
}
///
@@ -281,7 +288,7 @@ namespace SabreTools.Library.Dats
}
// Add the new item to the output list
- items.Add(item);
+ newItems.Add(item);
}
// Replace the old list of roms with the new one