diff --git a/SabreTools.Library/Dats/Archive.cs b/SabreTools.Library/Dats/Archive.cs index ba9cd3b2..7c90fb46 100644 --- a/SabreTools.Library/Dats/Archive.cs +++ b/SabreTools.Library/Dats/Archive.cs @@ -28,7 +28,7 @@ namespace SabreTools.Library.Dats Type = this.Type, Dupe = this.Dupe, - Machine = (Machine)this.Machine.Clone(), + Machine = this.Machine, Supported = this.Supported, Publisher = this.Publisher, diff --git a/SabreTools.Library/Dats/BiosSet.cs b/SabreTools.Library/Dats/BiosSet.cs index 266f512f..48ed1ea6 100644 --- a/SabreTools.Library/Dats/BiosSet.cs +++ b/SabreTools.Library/Dats/BiosSet.cs @@ -50,7 +50,7 @@ namespace SabreTools.Library.Dats Type = this.Type, Dupe = this.Dupe, - Machine = (Machine)this.Machine.Clone(), + Machine = this.Machine, Supported = this.Supported, Publisher = this.Publisher, diff --git a/SabreTools.Library/Dats/DatHeader.cs b/SabreTools.Library/Dats/DatHeader.cs new file mode 100644 index 00000000..acd36e4c --- /dev/null +++ b/SabreTools.Library/Dats/DatHeader.cs @@ -0,0 +1,217 @@ +using System.Collections.Generic; + +using SabreTools.Library.Data; + +namespace SabreTools.Library.Dats +{ + public struct DatHeader + { + #region Private instance variables + + // Data common to most DAT types + private string _fileName; + private string _name; + private string _description; + private string _rootDir; + private string _category; + private string _version; + private string _date; + private string _author; + private string _email; + private string _homepage; + private string _url; + private string _comment; + private string _header; + private string _type; // Generally only used for SuperDAT + private ForceMerging _forceMerging; + private ForceNodump _forceNodump; + private ForcePacking _forcePacking; + private DatFormat _datFormat; + private bool _excludeOf; + private bool _mergeRoms; + private Hash _stripHash; + private bool _oneGameOneRegion; + private List _regions; + + // Data specific to the Miss DAT type + private bool _useGame; + private string _prefix; + private string _postfix; + private bool _quotes; + private string _repExt; + private string _addExt; + private bool _remExt; + private bool _gameName; + private bool _romba; + + #endregion + + #region Publicly facing variables + + // Data common to most DAT types + public string FileName + { + get { return _fileName; } + set { _fileName = value; } + } + public string Name + { + get { return _name; } + set { _name = value; } + } + public string Description + { + get { return _description; } + set { _description = value; } + } + public string RootDir + { + get { return _rootDir; } + set { _rootDir = value; } + } + public string Category + { + get { return _category; } + set { _category = value; } + } + public string Version + { + get { return _version; } + set { _version = value; } + } + public string Date + { + get { return _date; } + set { _date = value; } + } + public string Author + { + get { return _author; } + set { _author = value; } + } + public string Email + { + get { return _email; } + set { _email = value; } + } + public string Homepage + { + get { return _homepage; } + set { _homepage = value; } + } + public string Url + { + get { return _url; } + set { _url = value; } + } + public string Comment + { + get { return _comment; } + set { _comment = value; } + } + public string Header + { + get { return _header; } + set { _header = value; } + } + public string Type // Generally only used for SuperDAT + { + get { return _type; } + set { _type = value; } + } + public ForceMerging ForceMerging + { + get { return _forceMerging; } + set { _forceMerging = value; } + } + public ForceNodump ForceNodump + { + get { return _forceNodump; } + set { _forceNodump = value; } + } + public ForcePacking ForcePacking + { + get { return _forcePacking; } + set { _forcePacking = value; } + } + public DatFormat DatFormat + { + get { return _datFormat; } + set { _datFormat = value; } + } + public bool ExcludeOf + { + get { return _excludeOf; } + set { _excludeOf = value; } + } + public bool MergeRoms + { + get { return _mergeRoms; } + set { _mergeRoms = value; } + } + public Hash StripHash + { + get { return _stripHash; } + set { _stripHash = value; } + } + public bool OneGameOneRegion + { + get { return _oneGameOneRegion; } + set { _oneGameOneRegion = value; } + } + public List Regions + { + get { return _regions; } + set { _regions = value; } + } + + // Data specific to the Miss DAT type + public bool UseGame + { + get { return _useGame; } + set { _useGame = value; } + } + public string Prefix + { + get { return _prefix; } + set { _prefix = value; } + } + public string Postfix + { + get { return _postfix; } + set { _postfix = value; } + } + public bool Quotes + { + get { return _quotes; } + set { _quotes = value; } + } + public string RepExt + { + get { return _repExt; } + set { _repExt = value; } + } + public string AddExt + { + get { return _addExt; } + set { _addExt = value; } + } + public bool RemExt + { + get { return _remExt; } + set { _remExt = value; } + } + public bool GameName + { + get { return _gameName; } + set { _gameName = value; } + } + public bool Romba + { + get { return _romba; } + set { _romba = value; } + } + + #endregion + } +} diff --git a/SabreTools.Library/Dats/DatItem.cs b/SabreTools.Library/Dats/DatItem.cs index b8f80aed..dfb72939 100644 --- a/SabreTools.Library/Dats/DatItem.cs +++ b/SabreTools.Library/Dats/DatItem.cs @@ -608,7 +608,7 @@ namespace SabreTools.Library.Dats { saveditem.SystemID = file.SystemID; saveditem.System = file.System; - saveditem.Machine = (Machine)file.Machine.Clone(); + saveditem.Machine = file.Machine; saveditem.Name = file.Name; } @@ -617,7 +617,7 @@ namespace SabreTools.Library.Dats { saveditem.SourceID = file.SourceID; saveditem.Source = file.Source; - saveditem.Machine = (Machine)file.Machine.Clone(); + saveditem.Machine = file.Machine; saveditem.Name = file.Name; } diff --git a/SabreTools.Library/Dats/Disk.cs b/SabreTools.Library/Dats/Disk.cs index 178ac08d..0125e6f9 100644 --- a/SabreTools.Library/Dats/Disk.cs +++ b/SabreTools.Library/Dats/Disk.cs @@ -79,7 +79,7 @@ namespace SabreTools.Library.Dats Type = this.Type, Dupe = this.Dupe, - Machine = (Machine)this.Machine.Clone(), + Machine = this.Machine, Supported = this.Supported, Publisher = this.Publisher, diff --git a/SabreTools.Library/Dats/Machine.cs b/SabreTools.Library/Dats/Machine.cs index e54f3177..489238ee 100644 --- a/SabreTools.Library/Dats/Machine.cs +++ b/SabreTools.Library/Dats/Machine.cs @@ -5,25 +5,26 @@ using SabreTools.Library.Data; namespace SabreTools.Library.Dats { - public class Machine : ICloneable + public struct Machine { #region Protected instance variables // Machine information - protected string _name; - protected string _comment; - protected string _description; - protected string _year; - protected string _manufacturer; - protected string _romOf; - protected string _cloneOf; - protected string _sampleOf; - protected string _sourceFile; - protected bool? _runnable; - protected string _board; - protected string _rebuildTo; - protected List _devices; - protected MachineType _machineType; + private string _name; + private string _comment; + private string _description; + private string _year; + private string _manufacturer; + private string _romOf; + private string _cloneOf; + private string _sampleOf; + private string _sourceFile; + private bool? _runnable; + private string _board; + private string _rebuildTo; + private List _devices; + private MachineType _machineType; + private Guid _guid; #endregion @@ -105,16 +106,6 @@ namespace SabreTools.Library.Dats #region Constructors - /// - /// Create a default, empty Machine object - /// - public Machine() - { - _name = ""; - _description = ""; - _runnable = null; - } - /// /// Create a new Machine object with the included information /// @@ -123,33 +114,134 @@ namespace SabreTools.Library.Dats public Machine(string name, string description) { _name = name; + _comment = null; _description = description; + _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(); } #endregion - #region Cloneing + #region Equality comparerers - public object Clone() + /// + /// Override the equality comparer + /// + public static bool operator ==(Machine a, Machine b) { - return new Machine() + 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)) { - Name = _name, - Comment = _comment, - Description = _description, - Year = _year, - Manufacturer = _manufacturer, - RomOf = _romOf, - CloneOf = _cloneOf, - SampleOf = _sampleOf, - SourceFile = _sourceFile, - Runnable = _runnable, - Board = _board, - RebuildTo = _rebuildTo, - Devices = _devices, - MachineType = _machineType, - }; + return false; + } + + return this == (Machine)o; + } + + /// + /// Override the GetHashCode method + /// + public override int GetHashCode() + { + return OCRC.OptimizedCRC.Compute(_guid.ToByteArray()); + } + + #endregion + + #region Update fields + + /// + /// Append a string to the description + /// + public void AppendDescription(string append) + { + UpdateDescription(this.Description + append); + } + + /// + /// Append a string to the name + /// + public void AppendName(string append) + { + UpdateName(this.Name + append); + } + + /// + /// Update the cloneof + /// + public void UpdateCloneOf(string update) + { + _cloneOf = update; + } + + /// + /// Update the description + /// + public void UpdateDescription(string update) + { + _description = update; + } + + /// + /// Update the romof + /// + public void UpdateRomOf(string update) + { + _romOf = update; + } + + /// + /// Update the sampleof + /// + public void UpdateSampleOf(string update) + { + _sampleOf = update; + } + + /// + /// Update the name + /// + public void UpdateName(string update) + { + _name = update; } #endregion diff --git a/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs b/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs index 2d516bfb..13aca6ca 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs @@ -251,8 +251,8 @@ namespace SabreTools.Library.Dats intDat.WriteToFile(interOutDir); } - // Due to possible memory requirements, each DAT, after written, will be nulled out - intDat = null; + // Due to possible memory requirements, we force a garbage collection + GC.Collect(); }); } @@ -467,7 +467,7 @@ namespace SabreTools.Library.Dats if ((diff & DiffMode.NoDupes) != 0) { DatItem newrom = item.Clone() as DatItem; - newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")"; + newrom.Machine.AppendName(" (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")"); outerDiffData.Add(key, newrom); } @@ -480,7 +480,7 @@ namespace SabreTools.Library.Dats if ((item.Dupe & DupeType.External) != 0) { DatItem newrom = item.Clone() as DatItem; - newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")"; + newrom.Machine.AppendName(" (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")"); dupeData.Add(key, newrom); } @@ -549,9 +549,9 @@ namespace SabreTools.Library.Dats rootpath += (rootpath == "" ? "" : Path.DirectorySeparatorChar.ToString()); filename = filename.Remove(0, rootpath.Length); - newItem.Machine.Name = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + newItem.Machine.UpdateName(Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar - + newItem.Machine.Name; + + newItem.Machine.Name); newItems.Add(newItem); } diff --git a/SabreTools.Library/Dats/Partials/DatFile.DFD.cs b/SabreTools.Library/Dats/Partials/DatFile.DFD.cs index 65f71b56..21c723b4 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.DFD.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.DFD.cs @@ -402,7 +402,7 @@ namespace SabreTools.Library.Dats // Update rom information datItem.Name = romname; - if (datItem.Machine == null) + if (datItem.Machine == default(Machine)) { datItem.Machine = new Machine { @@ -412,8 +412,8 @@ namespace SabreTools.Library.Dats } else { - datItem.Machine.Name = gamename; - datItem.Machine.Description = gamename; + datItem.Machine.UpdateName(gamename); + datItem.Machine.UpdateDescription(gamename); } // Add the file information to the DAT diff --git a/SabreTools.Library/Dats/Partials/DatFile.Manipulate.cs b/SabreTools.Library/Dats/Partials/DatFile.Manipulate.cs index 7bf03ac7..b5d03bc1 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.Manipulate.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.Manipulate.cs @@ -21,146 +21,152 @@ namespace SabreTools.Library.Dats #region Bucketing - /// - /// Take the arbitrarily sorted Files Dictionary and convert to one sorted by a user-defined method - /// - /// SortedBy enum representing how to sort the individual items - /// True if roms should be deduped, false otherwise - /// True if the key should be lowercased (default), false otherwise - /// True if games should only be compared on game and file name, false if system and source are counted - public void BucketBy(SortedBy bucketBy, bool mergeroms, bool lower = true, bool norename = true) + /// + /// Take the arbitrarily sorted Files Dictionary and convert to one sorted by a user-defined method + /// + /// SortedBy enum representing how to sort the individual items + /// True if roms should be deduped, false otherwise + /// True if the key should be lowercased (default), false otherwise + /// True if games should only be compared on game and file name, false if system and source are counted + public void BucketBy(SortedBy bucketBy, bool mergeroms, bool lower = true, bool norename = true) + { + // If we already have the right sorting, trust it + if (_sortedBy == bucketBy) + { + return; + } + + // If we have a situation where there's no dictionary or no keys at all, we skip + if (_files == null || _files.Count == 0) + { + return; + } + + // Set the sorted type + _sortedBy = bucketBy; + + // Create the temporary dictionary to sort into + SortedDictionary> sortable = new SortedDictionary>(); + + Globals.Logger.User("Organizing roms by " + bucketBy +(mergeroms ? " and merging" : "")); + + // First do the initial sort of all of the roms + List keys = Keys.ToList(); + Parallel.ForEach(keys, Globals.ParallelOptions, key => + { + List roms = this[key]; + + // Now add each of the roms to their respective games + foreach (DatItem rom in roms) { - // If we already have the right sorting, trust it - if (_sortedBy == bucketBy) + string newkey = ""; + + // We want to get the key most appropriate for the given sorting type + switch (bucketBy) { - return; - } - - // Set the sorted type - _sortedBy = bucketBy; - - // Create the temporary dictionary to sort into - SortedDictionary> sortable = new SortedDictionary>(); - - Globals.Logger.User("Organizing roms by " + bucketBy +(mergeroms ? " and merging" : "")); - - // First do the initial sort of all of the roms - List keys = Keys.ToList(); - Parallel.ForEach(keys, Globals.ParallelOptions, key => - { - List roms = this[key]; - - // Now add each of the roms to their respective games - foreach (DatItem rom in roms) - { - string newkey = ""; - - // We want to get the key most appropriate for the given sorting type - switch (bucketBy) + case SortedBy.CRC: + newkey = (rom.Type == ItemType.Rom ? ((Rom)rom).CRC : Constants.CRCZero); + break; + case SortedBy.Game: + newkey = (norename ? "" + : rom.SystemID.ToString().PadLeft(10, '0') + + "-" + + rom.SourceID.ToString().PadLeft(10, '0') + "-") + + (String.IsNullOrEmpty(rom.Machine.Name) + ? "Default" + : rom.Machine.Name); + if (lower) { - case SortedBy.CRC: - newkey = (rom.Type == ItemType.Rom ? ((Rom)rom).CRC : Constants.CRCZero); - break; - case SortedBy.Game: - newkey = (norename ? "" - : rom.SystemID.ToString().PadLeft(10, '0') - + "-" - + rom.SourceID.ToString().PadLeft(10, '0') + "-") - + (String.IsNullOrEmpty(rom.Machine.Name) - ? "Default" - : rom.Machine.Name); - if (lower) - { - newkey = newkey.ToLowerInvariant(); - } - if (newkey == null) - { - newkey = "null"; - } - - newkey = HttpUtility.HtmlEncode(newkey); - break; - case SortedBy.MD5: - newkey = (rom.Type == ItemType.Rom - ? ((Rom)rom).MD5 - : (rom.Type == ItemType.Disk - ? ((Disk)rom).MD5 - : Constants.MD5Zero)); - break; - case SortedBy.SHA1: - newkey = (rom.Type == ItemType.Rom - ? ((Rom)rom).SHA1 - : (rom.Type == ItemType.Disk - ? ((Disk)rom).SHA1 - : Constants.SHA1Zero)); - break; - case SortedBy.SHA256: - newkey = (rom.Type == ItemType.Rom - ? ((Rom)rom).SHA256 - : (rom.Type == ItemType.Disk - ? ((Disk)rom).SHA256 - : Constants.SHA256Zero)); - break; - case SortedBy.SHA384: - newkey = (rom.Type == ItemType.Rom - ? ((Rom)rom).SHA384 - : (rom.Type == ItemType.Disk - ? ((Disk)rom).SHA384 - : Constants.SHA384Zero)); - break; - case SortedBy.SHA512: - newkey = (rom.Type == ItemType.Rom - ? ((Rom)rom).SHA512 - : (rom.Type == ItemType.Disk - ? ((Disk)rom).SHA512 - : Constants.SHA512Zero)); - break; + newkey = newkey.ToLowerInvariant(); } - - // Double and triple check the key if (newkey == null) { - newkey = ""; + newkey = "null"; } - // Add the DatItem to the temp dictionary - lock (sortable) - { - if (!sortable.ContainsKey(newkey)) - { - sortable.Add(newkey, new List()); - } - sortable[newkey].Add(rom); - } - } - }); + newkey = HttpUtility.HtmlEncode(newkey); + break; + case SortedBy.MD5: + newkey = (rom.Type == ItemType.Rom + ? ((Rom)rom).MD5 + : (rom.Type == ItemType.Disk + ? ((Disk)rom).MD5 + : Constants.MD5Zero)); + break; + case SortedBy.SHA1: + newkey = (rom.Type == ItemType.Rom + ? ((Rom)rom).SHA1 + : (rom.Type == ItemType.Disk + ? ((Disk)rom).SHA1 + : Constants.SHA1Zero)); + break; + case SortedBy.SHA256: + newkey = (rom.Type == ItemType.Rom + ? ((Rom)rom).SHA256 + : (rom.Type == ItemType.Disk + ? ((Disk)rom).SHA256 + : Constants.SHA256Zero)); + break; + case SortedBy.SHA384: + newkey = (rom.Type == ItemType.Rom + ? ((Rom)rom).SHA384 + : (rom.Type == ItemType.Disk + ? ((Disk)rom).SHA384 + : Constants.SHA384Zero)); + break; + case SortedBy.SHA512: + newkey = (rom.Type == ItemType.Rom + ? ((Rom)rom).SHA512 + : (rom.Type == ItemType.Disk + ? ((Disk)rom).SHA512 + : Constants.SHA512Zero)); + break; + } - // Now go through and sort all of the individual lists - keys = sortable.Keys.ToList(); - Parallel.ForEach(keys, Globals.ParallelOptions, key => + // Double and triple check the key + if (newkey == null) { - // Get the possibly unsorted list - List sortedlist = sortable[key]; + newkey = ""; + } - // Sort the list of items to be consistent - DatItem.Sort(ref sortedlist, false); - - // If we're merging the roms, do so - if (mergeroms) + // Add the DatItem to the temp dictionary + lock (sortable) + { + if (!sortable.ContainsKey(newkey)) { - sortedlist = DatItem.Merge(sortedlist); + sortable.Add(newkey, new List()); } - - // Add the list back to the temp dictionary - lock (sortable) - { - sortable[key] = sortedlist; - } - }); - - // Now assign the dictionary back - _files = sortable; + sortable[newkey].Add(rom); + } } + }); + + // Now go through and sort all of the individual lists + keys = sortable.Keys.ToList(); + Parallel.ForEach(keys, Globals.ParallelOptions, key => + { + // Get the possibly unsorted list + List sortedlist = sortable[key]; + + // Sort the list of items to be consistent + DatItem.Sort(ref sortedlist, false); + + // If we're merging the roms, do so + if (mergeroms) + { + sortedlist = DatItem.Merge(sortedlist); + } + + // Add the list back to the temp dictionary + lock (sortable) + { + sortable[key] = sortedlist; + } + }); + + // Now assign the dictionary back + _files = sortable; + } #endregion @@ -190,7 +196,7 @@ namespace SabreTools.Library.Dats // If we are in single game mode, rename all games if (single) { - item.Machine.Name = "!"; + item.Machine.UpdateName("!"); } // If we are in NTFS trim mode, trim the game name @@ -253,25 +259,25 @@ namespace SabreTools.Library.Dats // Update machine name if (!String.IsNullOrEmpty(item.Machine.Name) && mapping.ContainsKey(item.Machine.Name)) { - item.Machine.Name = mapping[item.Machine.Name]; + item.Machine.UpdateName(mapping[item.Machine.Name]); } // Update cloneof if (!String.IsNullOrEmpty(item.Machine.CloneOf) && mapping.ContainsKey(item.Machine.CloneOf)) { - item.Machine.CloneOf = mapping[item.Machine.CloneOf]; + item.Machine.UpdateCloneOf(mapping[item.Machine.CloneOf]); } // Update romof if (!String.IsNullOrEmpty(item.Machine.RomOf) && mapping.ContainsKey(item.Machine.RomOf)) { - item.Machine.RomOf = mapping[item.Machine.RomOf]; + item.Machine.UpdateRomOf(mapping[item.Machine.RomOf]); } // Update sampleof if (!String.IsNullOrEmpty(item.Machine.SampleOf) && mapping.ContainsKey(item.Machine.SampleOf)) { - item.Machine.SampleOf = mapping[item.Machine.SampleOf]; + item.Machine.UpdateSampleOf(mapping[item.Machine.SampleOf]); } // Add the new item to the output list @@ -759,7 +765,7 @@ namespace SabreTools.Library.Dats string romof = this[parent][0].Machine.RomOf; foreach (DatItem item in items) { - item.Machine.RomOf = romof; + item.Machine.UpdateRomOf(romof); } } } @@ -1025,7 +1031,7 @@ namespace SabreTools.Library.Dats string romof = this[parent][0].Machine.RomOf; foreach (DatItem item in items) { - item.Machine.RomOf = romof; + item.Machine.UpdateRomOf(romof); } } } @@ -1041,8 +1047,8 @@ namespace SabreTools.Library.Dats List items = this[game]; foreach (DatItem item in items) { - item.Machine.CloneOf = null; - item.Machine.RomOf = null; + item.Machine.UpdateCloneOf(null); + item.Machine.UpdateRomOf(null); } } } diff --git a/SabreTools.Library/Dats/Partials/DatFile.Parsers.cs b/SabreTools.Library/Dats/Partials/DatFile.Parsers.cs index e03922cd..dfdadf85 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.Parsers.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.Parsers.cs @@ -3018,14 +3018,14 @@ namespace SabreTools.Library.Dats } // If we're in cleaning mode, sanitize the game name - item.Machine.Name = (clean ? Style.CleanGameName(item.Machine.Name) : item.Machine.Name); + item.Machine.UpdateName((clean ? Style.CleanGameName(item.Machine.Name) : item.Machine.Name)); // If we're stripping unicode characters, do so from all relevant things if (remUnicode) { item.Name = Style.RemoveUnicodeCharacters(item.Name); - item.Machine.Name = Style.RemoveUnicodeCharacters(item.Machine.Name); - item.Machine.Description = Style.RemoveUnicodeCharacters(item.Machine.Description); + item.Machine.UpdateName(Style.RemoveUnicodeCharacters(item.Machine.Name)); + item.Machine.UpdateDescription(Style.RemoveUnicodeCharacters(item.Machine.Description)); } // If we have a Rom or a Disk, clean the hash data diff --git a/SabreTools.Library/Dats/Partials/DatFile.Rebuild.cs b/SabreTools.Library/Dats/Partials/DatFile.Rebuild.cs index 52e8a9dc..4f230621 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.Rebuild.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.Rebuild.cs @@ -645,8 +645,8 @@ namespace SabreTools.Library.Dats // If we are coming from an archive, set the correct machine name if (machinename != null) { - item.Machine.Name = machinename; - item.Machine.Description = machinename; + item.Machine.UpdateName(machinename); + item.Machine.UpdateDescription(machinename); } Globals.Logger.User("No matches found for '" + Style.GetFileName(rom.Name) + "', rebuilding accordingly from inverse flag..."); diff --git a/SabreTools.Library/Dats/Partials/DatFile.Splitters.cs b/SabreTools.Library/Dats/Partials/DatFile.Splitters.cs index d11b0e54..93e2bff7 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.Splitters.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.Splitters.cs @@ -435,8 +435,8 @@ namespace SabreTools.Library.Dats // Clean the input list and set all games to be pathless List items = this[key]; - items.ForEach(item => item.Machine.Name = Style.GetFileName(item.Machine.Name)); - items.ForEach(item => item.Machine.Description = Style.GetFileName(item.Machine.Description)); + items.ForEach(item => item.Machine.UpdateName(Style.GetFileName(item.Machine.Name))); + items.ForEach(item => item.Machine.UpdateDescription(Style.GetFileName(item.Machine.Description))); // Now add the game to the output DAT tempDat.AddRange(key, items); diff --git a/SabreTools.Library/Dats/Partials/DatFile.Writers.cs b/SabreTools.Library/Dats/Partials/DatFile.Writers.cs index b6ab3fc5..4bf5d581 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.Writers.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.Writers.cs @@ -474,7 +474,7 @@ namespace SabreTools.Library.Dats // No game should start with a path separator if (rom.Machine.Name.StartsWith(Path.DirectorySeparatorChar.ToString())) { - rom.Machine.Name = rom.Machine.Name.Substring(1); + rom.Machine.UpdateName(rom.Machine.Name.Substring(1)); } string state = ""; diff --git a/SabreTools.Library/Dats/Release.cs b/SabreTools.Library/Dats/Release.cs index 6412732d..fb3eadbb 100644 --- a/SabreTools.Library/Dats/Release.cs +++ b/SabreTools.Library/Dats/Release.cs @@ -67,7 +67,7 @@ namespace SabreTools.Library.Dats Type = this.Type, Dupe = this.Dupe, - Machine = (Machine)this.Machine.Clone(), + Machine = this.Machine, Supported = this.Supported, Publisher = this.Publisher, diff --git a/SabreTools.Library/Dats/Rom.cs b/SabreTools.Library/Dats/Rom.cs index b8cae250..8d1f9da1 100644 --- a/SabreTools.Library/Dats/Rom.cs +++ b/SabreTools.Library/Dats/Rom.cs @@ -107,7 +107,7 @@ namespace SabreTools.Library.Dats Type = this.Type, Dupe = this.Dupe, - Machine = (Machine)this.Machine.Clone(), + Machine = this.Machine, Supported = this.Supported, Publisher = this.Publisher, diff --git a/SabreTools.Library/Dats/Sample.cs b/SabreTools.Library/Dats/Sample.cs index 2740e8a2..5a5d55b5 100644 --- a/SabreTools.Library/Dats/Sample.cs +++ b/SabreTools.Library/Dats/Sample.cs @@ -29,7 +29,7 @@ namespace SabreTools.Library.Dats Type = this.Type, Dupe = this.Dupe, - Machine = (Machine)this.Machine.Clone(), + Machine = this.Machine, Supported = this.Supported, Publisher = this.Publisher, diff --git a/SabreTools.Library/SabreTools.Library.csproj b/SabreTools.Library/SabreTools.Library.csproj index 50304a7f..db56785e 100644 --- a/SabreTools.Library/SabreTools.Library.csproj +++ b/SabreTools.Library/SabreTools.Library.csproj @@ -115,6 +115,7 @@ +