diff --git a/RombaSharp/Features/BaseFeature.cs b/RombaSharp/Features/BaseFeature.cs index 838b49f8..eab7c9fb 100644 --- a/RombaSharp/Features/BaseFeature.cs +++ b/RombaSharp/Features/BaseFeature.cs @@ -607,7 +607,7 @@ namespace RombaSharp.Features internal static void AddDatToDatabase(Rom dat, SqliteConnection dbc) { // Get the dat full path - string fullpath = Path.Combine(_dats, (dat.MachineName == "dats" ? string.Empty : dat.MachineName), dat.Name); + string fullpath = Path.Combine(_dats, (dat.Machine.Name == "dats" ? string.Empty : dat.Machine.Name), dat.Name); // Parse the Dat if possible Globals.Logger.User($"Adding from '{dat.Name}'"); diff --git a/SabreTools.Library/DatFiles/AttractMode.cs b/SabreTools.Library/DatFiles/AttractMode.cs index 24ba4c51..bedb142d 100644 --- a/SabreTools.Library/DatFiles/AttractMode.cs +++ b/SabreTools.Library/DatFiles/AttractMode.cs @@ -81,15 +81,21 @@ namespace SabreTools.Library.DatFiles SHA1 = Constants.SHA1Zero, ItemStatus = ItemStatus.None, - MachineName = gameinfo[0], - MachineDescription = gameinfo[1], - CloneOf = gameinfo[3], - Year = gameinfo[4], - Manufacturer = gameinfo[5], - Comment = gameinfo[15], + Machine = new Machine + { + Name = gameinfo[0], + Description = gameinfo[1], + CloneOf = gameinfo[3], + Year = gameinfo[4], + Manufacturer = gameinfo[5], + Comment = gameinfo[15], + }, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; // Now process and add the rom @@ -145,14 +151,14 @@ namespace SabreTools.Library.DatFiles DatItem item = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (item.Name == null || item.MachineName == null) + if (item.Name == null || item.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != item.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != item.Machine.Name.ToLowerInvariant()) WriteDatItem(svw, item, ignoreblanks); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -160,14 +166,14 @@ namespace SabreTools.Library.DatFiles && ((Rom)item).Size == -1 && ((Rom)item).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {item.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {item.Machine.Name}"); item.Name = (item.Name == "null" ? "-" : item.Name); ((Rom)item).Size = Constants.SizeZero; } // Set the new data to compare against - lastgame = item.MachineName; + lastgame = item.Machine.Name; } } @@ -243,7 +249,7 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Pre-process the item name ProcessItemName(datItem, true); diff --git a/SabreTools.Library/DatFiles/ClrMamePro.cs b/SabreTools.Library/DatFiles/ClrMamePro.cs index 332bbdef..d05fa04f 100644 --- a/SabreTools.Library/DatFiles/ClrMamePro.cs +++ b/SabreTools.Library/DatFiles/ClrMamePro.cs @@ -291,8 +291,8 @@ namespace SabreTools.Library.DatFiles // Then populate it with information item.CopyMachineInformation(machine); - item.IndexId = indexId; - item.IndexSource = filename; + item.Source.Index = indexId; + item.Source.Name = filename; // Loop through all of the attributes foreach (var kvp in cmpr.Internal) @@ -420,8 +420,11 @@ namespace SabreTools.Library.DatFiles { Blank blank = new Blank() { - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; blank.CopyMachineInformation(machine); @@ -475,18 +478,18 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } // If we have a different game and we're not at the start of the list, output the end of last item - if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteEndGame(cmpw, rom); // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteStartGame(cmpw, rom); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -494,7 +497,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); // If we're in a mode that doesn't allow for actual empty folders, add the blank info rom.Name = (rom.Name == "null" ? "-" : rom.Name); @@ -514,7 +517,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(cmpw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -613,27 +616,27 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Build the state based on excluded fields - cmpw.WriteStartElement(datItem.MachineType == MachineType.Bios ? "resource" : "game"); + cmpw.WriteStartElement(datItem.Machine.MachineType == MachineType.Bios ? "resource" : "game"); cmpw.WriteStandalone("name", datItem.GetField(Field.MachineName, Header.ExcludeFields)); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RomOf, Header.ExcludeFields))) - cmpw.WriteStandalone("romof", datItem.RomOf); + cmpw.WriteStandalone("romof", datItem.Machine.RomOf); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields))) - cmpw.WriteStandalone("cloneof", datItem.CloneOf); + cmpw.WriteStandalone("cloneof", datItem.Machine.CloneOf); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, Header.ExcludeFields))) - cmpw.WriteStandalone("sampleof", datItem.SampleOf); + cmpw.WriteStandalone("sampleof", datItem.Machine.SampleOf); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Description, Header.ExcludeFields))) - cmpw.WriteStandalone("description", datItem.MachineDescription); + cmpw.WriteStandalone("description", datItem.Machine.Description); else if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Description, Header.ExcludeFields))) - cmpw.WriteStandalone("description", datItem.MachineName); + cmpw.WriteStandalone("description", datItem.Machine.Name); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Year, Header.ExcludeFields))) - cmpw.WriteStandalone("year", datItem.Year); + cmpw.WriteStandalone("year", datItem.Machine.Year); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Manufacturer, Header.ExcludeFields))) - cmpw.WriteStandalone("manufacturer", datItem.Manufacturer); + cmpw.WriteStandalone("manufacturer", datItem.Machine.Manufacturer); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Category, Header.ExcludeFields))) - cmpw.WriteStandalone("category", datItem.Category); + cmpw.WriteStandalone("category", datItem.Machine.Category); cmpw.Flush(); } @@ -658,7 +661,7 @@ namespace SabreTools.Library.DatFiles { // Build the state based on excluded fields if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, Header.ExcludeFields))) - cmpw.WriteStandalone("sampleof", datItem.SampleOf); + cmpw.WriteStandalone("sampleof", datItem.Machine.SampleOf); // End game cmpw.WriteEndElement(); diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 87eab4ff..eb42c9da 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -288,7 +288,7 @@ namespace SabreTools.Library.DatFiles { DatItem newDatItem = datItem.Clone() as DatItem; if (Items.ContainsKey(key) && Items[key].Count() > 0) - newDatItem.ReplaceMachineFields(Items[key][0], updateFields, onlySame); + newDatItem.Machine.ReplaceFields(Items[key][0].Machine, updateFields, onlySame); newDatItems.Add(newDatItem); } @@ -499,13 +499,13 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { // There's odd cases where there are items with System ID < 0. Skip them for now - if (item.IndexId < 0) + if (item.Source.Index < 0) { Globals.Logger.Warning($"Item found with a <0 SystemID: {item.Name}"); continue; } - outDats[item.IndexId].Items.Add(key, item); + outDats[item.Source.Index].Items.Add(key, item); } }); @@ -581,7 +581,7 @@ namespace SabreTools.Library.DatFiles if (item.DupeType.HasFlag(DupeType.External)) { DatItem newrom = item.Clone() as DatItem; - newrom.MachineName += $" ({Path.GetFileNameWithoutExtension(inputs[item.IndexId].CurrentPath)})"; + newrom.Machine.Name += $" ({Path.GetFileNameWithoutExtension(inputs[item.Source.Index].CurrentPath)})"; dupeData.Items.Add(key, newrom); } @@ -660,7 +660,7 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { if (item.DupeType.HasFlag(DupeType.Internal) || item.DupeType == 0x00) - outDats[item.IndexId].Items.Add(key, item); + outDats[item.Source.Index].Items.Add(key, item); } }); @@ -736,7 +736,7 @@ namespace SabreTools.Library.DatFiles if (item.DupeType.HasFlag(DupeType.Internal) || item.DupeType == 0x00) { DatItem newrom = item.Clone() as DatItem; - newrom.MachineName += $" ({Path.GetFileNameWithoutExtension(inputs[item.IndexId].CurrentPath)})"; + newrom.Machine.Name += $" ({Path.GetFileNameWithoutExtension(inputs[item.Source.Index].CurrentPath)})"; outerDiffData.Items.Add(key, newrom); } } @@ -778,14 +778,14 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { DatItem newItem = item; - string filename = inputs[newItem.IndexId].CurrentPath; - string rootpath = inputs[newItem.IndexId].ParentPath; + string filename = inputs[newItem.Source.Index].CurrentPath; + string rootpath = inputs[newItem.Source.Index].ParentPath; rootpath += (string.IsNullOrWhiteSpace(rootpath) ? string.Empty : Path.DirectorySeparatorChar.ToString()); filename = filename.Remove(0, rootpath.Length); - newItem.MachineName = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + newItem.Machine.Name = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar - + newItem.MachineName; + + newItem.Machine.Name; newItems.Add(newItem); } @@ -933,26 +933,26 @@ namespace SabreTools.Library.DatFiles if (filter.RemoveUnicode) { item.Name = Sanitizer.RemoveUnicodeCharacters(item.Name); - item.MachineName = Sanitizer.RemoveUnicodeCharacters(item.MachineName); - item.MachineDescription = Sanitizer.RemoveUnicodeCharacters(item.MachineDescription); + item.Machine.Name = Sanitizer.RemoveUnicodeCharacters(item.Machine.Name); + item.Machine.Description = Sanitizer.RemoveUnicodeCharacters(item.Machine.Description); } // If we're in cleaning mode, do so from all relevant things if (filter.Clean) { - item.MachineName = Sanitizer.CleanGameName(item.MachineName); - item.MachineDescription = Sanitizer.CleanGameName(item.MachineDescription); + item.Machine.Name = Sanitizer.CleanGameName(item.Machine.Name); + item.Machine.Description = Sanitizer.CleanGameName(item.Machine.Description); } // If we are in single game mode, rename all games if (filter.Single) - item.MachineName = "!"; + item.Machine.Name = "!"; // If we are in NTFS trim mode, trim the game name if (filter.Trim) { // Windows max name length is 260 - int usableLength = 260 - item.MachineName.Length - filter.Root.Length; + int usableLength = 260 - item.Machine.Name.Length - filter.Root.Length; if (item.Name.Length > usableLength) { string ext = Path.GetExtension(item.Name); @@ -1030,7 +1030,7 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { // If the key mapping doesn't exist, add it - mapping.TryAdd(item.MachineName, item.MachineDescription.Replace('/', '_').Replace("\"", "''").Replace(":", " -")); + mapping.TryAdd(item.Machine.Name, item.Machine.Description.Replace('/', '_').Replace("\"", "''").Replace(":", " -")); } }); @@ -1042,20 +1042,20 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { // Update machine name - if (!string.IsNullOrWhiteSpace(item.MachineName) && mapping.ContainsKey(item.MachineName)) - item.MachineName = mapping[item.MachineName]; + if (!string.IsNullOrWhiteSpace(item.Machine.Name) && mapping.ContainsKey(item.Machine.Name)) + item.Machine.Name = mapping[item.Machine.Name]; // Update cloneof - if (!string.IsNullOrWhiteSpace(item.CloneOf) && mapping.ContainsKey(item.CloneOf)) - item.CloneOf = mapping[item.CloneOf]; + if (!string.IsNullOrWhiteSpace(item.Machine.CloneOf) && mapping.ContainsKey(item.Machine.CloneOf)) + item.Machine.CloneOf = mapping[item.Machine.CloneOf]; // Update romof - if (!string.IsNullOrWhiteSpace(item.RomOf) && mapping.ContainsKey(item.RomOf)) - item.RomOf = mapping[item.RomOf]; + if (!string.IsNullOrWhiteSpace(item.Machine.RomOf) && mapping.ContainsKey(item.Machine.RomOf)) + item.Machine.RomOf = mapping[item.Machine.RomOf]; // Update sampleof - if (!string.IsNullOrWhiteSpace(item.SampleOf) && mapping.ContainsKey(item.SampleOf)) - item.SampleOf = mapping[item.SampleOf]; + if (!string.IsNullOrWhiteSpace(item.Machine.SampleOf) && mapping.ContainsKey(item.Machine.SampleOf)) + item.Machine.SampleOf = mapping[item.Machine.SampleOf]; // Add the new item to the output list newItems.Add(item); @@ -1097,30 +1097,30 @@ namespace SabreTools.Library.DatFiles DatItem item = Items[key][0]; // Match on CloneOf first - if (!string.IsNullOrEmpty(item.CloneOf)) + if (!string.IsNullOrEmpty(item.Machine.CloneOf)) { - if (!parents.ContainsKey(item.CloneOf.ToLowerInvariant())) - parents.Add(item.CloneOf.ToLowerInvariant(), new List()); + if (!parents.ContainsKey(item.Machine.CloneOf.ToLowerInvariant())) + parents.Add(item.Machine.CloneOf.ToLowerInvariant(), new List()); - parents[item.CloneOf.ToLowerInvariant()].Add(item.MachineName.ToLowerInvariant()); + parents[item.Machine.CloneOf.ToLowerInvariant()].Add(item.Machine.Name.ToLowerInvariant()); } // Then by RomOf - else if (!string.IsNullOrEmpty(item.RomOf)) + else if (!string.IsNullOrEmpty(item.Machine.RomOf)) { - if (!parents.ContainsKey(item.RomOf.ToLowerInvariant())) - parents.Add(item.RomOf.ToLowerInvariant(), new List()); + if (!parents.ContainsKey(item.Machine.RomOf.ToLowerInvariant())) + parents.Add(item.Machine.RomOf.ToLowerInvariant(), new List()); - parents[item.RomOf.ToLowerInvariant()].Add(item.MachineName.ToLowerInvariant()); + parents[item.Machine.RomOf.ToLowerInvariant()].Add(item.Machine.Name.ToLowerInvariant()); } // Otherwise, treat it as a parent else { - if (!parents.ContainsKey(item.MachineName.ToLowerInvariant())) - parents.Add(item.MachineName.ToLowerInvariant(), new List()); + if (!parents.ContainsKey(item.Machine.Name.ToLowerInvariant())) + parents.Add(item.Machine.Name.ToLowerInvariant(), new List()); - parents[item.MachineName.ToLowerInvariant()].Add(item.MachineName.ToLowerInvariant()); + parents[item.Machine.Name.ToLowerInvariant()].Add(item.Machine.Name.ToLowerInvariant()); } } @@ -1171,7 +1171,7 @@ namespace SabreTools.Library.DatFiles for (int i = 0; i < items.Count; i++) { string[] splitname = items[i].Name.Split('.'); - items[i].MachineName += $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}"; + items[i].Machine.Name += $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}"; items[i].Name = Path.GetFileName(items[i].Name); } }); @@ -1220,11 +1220,11 @@ namespace SabreTools.Library.DatFiles for (int j = 0; j < items.Count; j++) { DatItem item = items[j]; - if (Regex.IsMatch(item.MachineName, pattern)) - item.MachineName = Regex.Replace(item.MachineName, pattern, "$2"); + if (Regex.IsMatch(item.Machine.Name, pattern)) + item.Machine.Name = Regex.Replace(item.Machine.Name, pattern, "$2"); - if (Regex.IsMatch(item.MachineDescription, pattern)) - item.MachineDescription = Regex.Replace(item.MachineDescription, pattern, "$2"); + if (Regex.IsMatch(item.Machine.Description, pattern)) + item.Machine.Description = Regex.Replace(item.Machine.Description, pattern, "$2"); items[j] = item; } @@ -1390,8 +1390,8 @@ namespace SabreTools.Library.DatFiles // Determine if the game has a parent or not string parent = null; - if (!string.IsNullOrWhiteSpace(Items[game][0].RomOf)) - parent = Items[game][0].RomOf; + if (!string.IsNullOrWhiteSpace(Items[game][0].Machine.RomOf)) + parent = Items[game][0].Machine.RomOf; // If the parent doesnt exist, we want to continue if (string.IsNullOrWhiteSpace(parent)) @@ -1430,20 +1430,20 @@ namespace SabreTools.Library.DatFiles continue; // If the game (is/is not) a bios, we want to continue - if (dev ^ (Items[game][0].MachineType.HasFlag(MachineType.Device))) + if (dev ^ (Items[game][0].Machine.MachineType.HasFlag(MachineType.Device))) continue; // If the game has no devices, we continue - if (Items[game][0].Devices == null - || Items[game][0].Devices.Count == 0 - || (slotoptions && Items[game][0].SlotOptions == null) - || (slotoptions && Items[game][0].SlotOptions.Count == 0)) + if (Items[game][0].Machine.Devices == null + || Items[game][0].Machine.Devices.Count == 0 + || (slotoptions && Items[game][0].Machine.SlotOptions == null) + || (slotoptions && Items[game][0].Machine.SlotOptions.Count == 0)) { continue; } // Determine if the game has any devices or not - List devices = Items[game][0].Devices; + List devices = Items[game][0].Machine.Devices; List newdevs = new List(); foreach (string device in devices) { @@ -1457,7 +1457,7 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in devItems) { DatItem datItem = (DatItem)item.Clone(); - newdevs.AddRange(datItem.Devices ?? new List()); + newdevs.AddRange(datItem.Machine.Devices ?? new List()); datItem.CopyMachineInformation(copyFrom); if (Items[game].Where(i => i.Name.ToLowerInvariant() == datItem.Name.ToLowerInvariant()).Count() == 0) { @@ -1470,15 +1470,15 @@ namespace SabreTools.Library.DatFiles // Now that every device is accounted for, add the new list of devices, if they don't already exist foreach (string device in newdevs) { - if (!Items[game][0].Devices.Contains(device)) - Items[game][0].Devices.Add(device); + if (!Items[game][0].Machine.Devices.Contains(device)) + Items[game][0].Machine.Devices.Add(device); } // If we're checking slotoptions too if (slotoptions) { // Determine if the game has any slotoptions or not - List slotopts = Items[game][0].SlotOptions; + List slotopts = Items[game][0].Machine.SlotOptions; List newslotopts = new List(); foreach (string slotopt in slotopts) { @@ -1492,7 +1492,7 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in slotItems) { DatItem datItem = (DatItem)item.Clone(); - newslotopts.AddRange(datItem.SlotOptions ?? new List()); + newslotopts.AddRange(datItem.Machine.SlotOptions ?? new List()); datItem.CopyMachineInformation(copyFrom); if (Items[game].Where(i => i.Name.ToLowerInvariant() == datItem.Name.ToLowerInvariant()).Count() == 0) { @@ -1505,8 +1505,8 @@ namespace SabreTools.Library.DatFiles // Now that every slotoption is accounted for, add the new list of slotoptions, if they don't already exist foreach (string slotopt in newslotopts) { - if (!Items[game][0].SlotOptions.Contains(slotopt)) - Items[game][0].SlotOptions.Add(slotopt); + if (!Items[game][0].Machine.SlotOptions.Contains(slotopt)) + Items[game][0].Machine.SlotOptions.Add(slotopt); } } } @@ -1528,8 +1528,8 @@ namespace SabreTools.Library.DatFiles // Determine if the game has a parent or not string parent = null; - if (!string.IsNullOrWhiteSpace(Items[game][0].CloneOf)) - parent = Items[game][0].CloneOf; + if (!string.IsNullOrWhiteSpace(Items[game][0].Machine.CloneOf)) + parent = Items[game][0].Machine.CloneOf; // If the parent doesnt exist, we want to continue if (string.IsNullOrWhiteSpace(parent)) @@ -1555,10 +1555,10 @@ namespace SabreTools.Library.DatFiles // Now we want to get the parent romof tag and put it in each of the items List items = Items[game]; - string romof = Items[parent][0].RomOf; + string romof = Items[parent][0].Machine.RomOf; foreach (DatItem item in items) { - item.RomOf = romof; + item.Machine.RomOf = romof; } } } @@ -1578,15 +1578,26 @@ namespace SabreTools.Library.DatFiles // Determine if the game has a parent or not string parent = null; - if (!string.IsNullOrWhiteSpace(Items[game][0].CloneOf)) - parent = Items[game][0].CloneOf; + if (!string.IsNullOrWhiteSpace(Items[game][0].Machine.CloneOf)) + parent = Items[game][0].Machine.CloneOf; // If there is no parent, then we continue if (string.IsNullOrWhiteSpace(parent)) continue; // Otherwise, move the items from the current game to a subfolder of the parent game - DatItem copyFrom = Items[parent].Count == 0 ? new Rom { MachineName = parent, MachineDescription = parent } : Items[parent][0]; + DatItem copyFrom; + if (Items[parent].Count == 0) + { + copyFrom = new Rom(); + copyFrom.Machine.Name = parent; + copyFrom.Machine.Description = parent; + } + else + { + copyFrom = Items[parent][0]; + } + List items = Items[game]; foreach (DatItem item in items) { @@ -1631,7 +1642,7 @@ namespace SabreTools.Library.DatFiles else if (rom.MergeTag != null && !Items[parent].Select(i => i.Name).Contains(rom.MergeTag)) { if (subfolder) - item.Name = $"{item.MachineName}\\{item.Name}"; + item.Name = $"{item.Machine.Name}\\{item.Name}"; item.CopyMachineInformation(copyFrom); Items.Add(parent, item); @@ -1641,7 +1652,7 @@ namespace SabreTools.Library.DatFiles else if (!Items[parent].Contains(item)) { if (subfolder) - item.Name = $"{item.MachineName}\\{item.Name}"; + item.Name = $"{item.Machine.Name}\\{item.Name}"; item.CopyMachineInformation(copyFrom); Items.Add(parent, item); @@ -1652,7 +1663,7 @@ namespace SabreTools.Library.DatFiles else if (!Items[parent].Contains(item)) { if (subfolder) - item.Name = $"{item.MachineName}\\{item.Name}"; + item.Name = $"{item.Machine.Name}\\{item.Name}"; item.CopyMachineInformation(copyFrom); Items.Add(parent, item); @@ -1673,8 +1684,8 @@ namespace SabreTools.Library.DatFiles foreach (string game in games) { if (Items[game].Count > 0 - && (Items[game][0].MachineType.HasFlag(MachineType.Bios) - || Items[game][0].MachineType.HasFlag(MachineType.Device))) + && (Items[game][0].Machine.MachineType.HasFlag(MachineType.Bios) + || Items[game][0].Machine.MachineType.HasFlag(MachineType.Device))) { Items.Remove(game); } @@ -1696,13 +1707,13 @@ namespace SabreTools.Library.DatFiles continue; // If the game (is/is not) a bios, we want to continue - if (bios ^ Items[game][0].MachineType.HasFlag(MachineType.Bios)) + if (bios ^ Items[game][0].Machine.MachineType.HasFlag(MachineType.Bios)) continue; // Determine if the game has a parent or not string parent = null; - if (!string.IsNullOrWhiteSpace(Items[game][0].RomOf)) - parent = Items[game][0].RomOf; + if (!string.IsNullOrWhiteSpace(Items[game][0].Machine.RomOf)) + parent = Items[game][0].Machine.RomOf; // If the parent doesnt exist, we want to continue if (string.IsNullOrWhiteSpace(parent)) @@ -1739,8 +1750,8 @@ namespace SabreTools.Library.DatFiles // Determine if the game has a parent or not string parent = null; - if (!string.IsNullOrWhiteSpace(Items[game][0].CloneOf)) - parent = Items[game][0].CloneOf; + if (!string.IsNullOrWhiteSpace(Items[game][0].Machine.CloneOf)) + parent = Items[game][0].Machine.CloneOf; // If the parent doesnt exist, we want to continue if (string.IsNullOrWhiteSpace(parent)) @@ -1763,10 +1774,10 @@ namespace SabreTools.Library.DatFiles // Now we want to get the parent romof tag and put it in each of the remaining items List items = Items[game]; - string romof = Items[parent][0].RomOf; + string romof = Items[parent][0].Machine.RomOf; foreach (DatItem item in items) { - item.RomOf = romof; + item.Machine.RomOf = romof; } } } @@ -1782,9 +1793,9 @@ namespace SabreTools.Library.DatFiles List items = Items[game]; foreach (DatItem item in items) { - item.CloneOf = null; - item.RomOf = null; - item.SampleOf = null; + item.Machine.CloneOf = null; + item.Machine.RomOf = null; + item.Machine.SampleOf = null; } } } @@ -2326,8 +2337,8 @@ namespace SabreTools.Library.DatFiles // Update rom information datItem.Name = romname; - datItem.MachineName = gamename; - datItem.MachineDescription = gamename; + datItem.Machine.Name = gamename; + datItem.Machine.Description = gamename; // If we have a Disk, then the ".chd" extension needs to be removed if (datItem.ItemType == ItemType.Disk) @@ -2879,14 +2890,14 @@ namespace SabreTools.Library.DatFiles // Get the item from the current file Rom item = new Rom(fileStream.GetInfo(keepReadOpen: true)); - item.MachineName = Path.GetFileNameWithoutExtension(item.Name); - item.MachineDescription = Path.GetFileNameWithoutExtension(item.Name); + item.Machine.Name = Path.GetFileNameWithoutExtension(item.Name); + item.Machine.Description = Path.GetFileNameWithoutExtension(item.Name); // If we are coming from an archive, set the correct machine name if (machinename != null) { - item.MachineName = machinename; - item.MachineDescription = machinename; + item.Machine.Name = machinename; + item.Machine.Description = machinename; } dupes.Add(item); @@ -3128,7 +3139,7 @@ namespace SabreTools.Library.DatFiles List roms = Items[key]; foreach (DatItem rom in roms) { - if (rom.IndexId == 99) + if (rom.Source.Index == 99) { if (rom.ItemType == ItemType.Disk || rom.ItemType == ItemType.Rom) matched.Items.Add(((Disk)rom).SHA1, rom); @@ -3145,7 +3156,7 @@ namespace SabreTools.Library.DatFiles List newroms = DatItem.Merge(roms); foreach (Rom rom in newroms) { - if (rom.IndexId == 99) + if (rom.Source.Index == 99) matched.Items.Add($"{rom.Size}-{rom.CRC}", rom); } } @@ -3396,8 +3407,8 @@ namespace SabreTools.Library.DatFiles // Clean the input list and set all games to be pathless List items = Items[key]; - items.ForEach(item => item.MachineName = Path.GetFileName(item.MachineName)); - items.ForEach(item => item.MachineDescription = Path.GetFileName(item.MachineDescription)); + items.ForEach(item => item.Machine.Name = Path.GetFileName(item.Machine.Name)); + items.ForEach(item => item.Machine.Description = Path.GetFileName(item.Machine.Description)); // Now add the game to the output DAT tempDat.Items.AddRange(key, items); @@ -3755,7 +3766,7 @@ namespace SabreTools.Library.DatFiles name += Header.AddExtension; if (Header.UseRomName && Header.GameName) - name = Path.Combine(item.MachineName, name); + name = Path.Combine(item.Machine.Name, name); // Now assign back the item name item.Name = pre + name + post; @@ -3778,11 +3789,8 @@ namespace SabreTools.Library.DatFiles { // Initialize strings string fix = string.Empty, - game = item.MachineName, + game = item.Machine.Name, name = item.Name, - manufacturer = item.Manufacturer, - publisher = item.Publisher, - category = item.Category, crc = string.Empty, md5 = string.Empty, ripemd160 = string.Empty, @@ -3831,9 +3839,9 @@ namespace SabreTools.Library.DatFiles .Replace("%game%", game) .Replace("%machine%", game) .Replace("%name%", name) - .Replace("%manufacturer%", manufacturer) - .Replace("%publisher%", publisher) - .Replace("%category%", category) + .Replace("%manufacturer%", item.Machine.Manufacturer) + .Replace("%publisher%", item.Machine.Publisher) + .Replace("%category%", item.Machine.Category) .Replace("%crc%", crc) .Replace("%md5%", md5) .Replace("%ripemd160%", ripemd160) diff --git a/SabreTools.Library/DatFiles/DepotInformation.cs b/SabreTools.Library/DatFiles/DepotInformation.cs index 63051894..cbbe0639 100644 --- a/SabreTools.Library/DatFiles/DepotInformation.cs +++ b/SabreTools.Library/DatFiles/DepotInformation.cs @@ -4,6 +4,9 @@ using SabreTools.Library.Data; namespace SabreTools.Library.DatFiles { + /// + /// Depot information wrapper + /// public class DepotInformation : ICloneable { /// diff --git a/SabreTools.Library/DatFiles/DosCenter.cs b/SabreTools.Library/DatFiles/DosCenter.cs index abb87b28..25050faf 100644 --- a/SabreTools.Library/DatFiles/DosCenter.cs +++ b/SabreTools.Library/DatFiles/DosCenter.cs @@ -197,9 +197,11 @@ namespace SabreTools.Library.DatFiles // Then populate it with information item.CopyMachineInformation(machine); - - item.IndexId = indexId; - item.IndexSource = filename; + item.Source = new Source + { + Index = indexId, + Name = filename, + }; // Loop through all of the attributes foreach (var kvp in cmpr.Internal) @@ -245,8 +247,11 @@ namespace SabreTools.Library.DatFiles { Blank blank = new Blank() { - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; blank.CopyMachineInformation(machine); @@ -301,20 +306,20 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } - List newsplit = rom.MachineName.Split('\\').ToList(); + List newsplit = rom.Machine.Name.Split('\\').ToList(); // If we have a different game and we're not at the start of the list, output the end of last item - if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteEndGame(cmpw); // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteStartGame(cmpw, rom); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -322,7 +327,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); rom.Name = (rom.Name == "null" ? "-" : rom.Name); ((Rom)rom).Size = Constants.SizeZero; @@ -341,7 +346,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(cmpw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -402,7 +407,7 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Build the state based on excluded fields cmpw.WriteStartElement("game"); diff --git a/SabreTools.Library/DatFiles/EverdriveSmdb.cs b/SabreTools.Library/DatFiles/EverdriveSmdb.cs index 12d70ada..6ed0646b 100644 --- a/SabreTools.Library/DatFiles/EverdriveSmdb.cs +++ b/SabreTools.Library/DatFiles/EverdriveSmdb.cs @@ -68,11 +68,17 @@ namespace SabreTools.Library.DatFiles SHA256 = gameinfo[0], ItemStatus = ItemStatus.None, - MachineName = fullname[0], - MachineDescription = fullname[0], + Machine = new Machine + { + Name = fullname[0], + Description = fullname[0], + }, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; // Now process and add the rom @@ -122,7 +128,7 @@ namespace SabreTools.Library.DatFiles DatItem item = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (item.Name == null || item.MachineName == null) + if (item.Name == null || item.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; @@ -133,7 +139,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)item).Size == -1 && ((Rom)item).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {item.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {item.Machine.Name}"); item.Name = (item.Name == "null" ? "-" : item.Name); ((Rom)item).Size = Constants.SizeZero; @@ -171,7 +177,7 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Pre-process the item name ProcessItemName(datItem, true); diff --git a/SabreTools.Library/DatFiles/Hashfile.cs b/SabreTools.Library/DatFiles/Hashfile.cs index cb3cb572..ac1be60b 100644 --- a/SabreTools.Library/DatFiles/Hashfile.cs +++ b/SabreTools.Library/DatFiles/Hashfile.cs @@ -84,10 +84,16 @@ namespace SabreTools.Library.DatFiles SHA512 = (_hash.HasFlag(Hash.SHA512) ? hash : null), ItemStatus = ItemStatus.None, - MachineName = Path.GetFileNameWithoutExtension(filename), + Machine = new Machine + { + Name = Path.GetFileNameWithoutExtension(filename), + }, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; // Now process and add the rom @@ -137,7 +143,7 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; @@ -148,7 +154,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); } // Now, output the rom data diff --git a/SabreTools.Library/DatFiles/Json.cs b/SabreTools.Library/DatFiles/Json.cs index 88548d9e..b18f8248 100644 --- a/SabreTools.Library/DatFiles/Json.cs +++ b/SabreTools.Library/DatFiles/Json.cs @@ -532,8 +532,7 @@ namespace SabreTools.Library.DatFiles DatItem datItem = DatItem.Create(itemType.Value); datItem.CopyMachineInformation(machine); - datItem.IndexId = indexId; - datItem.IndexSource = filename; + datItem.Source = new Source { Index = indexId, Name = filename }; datItem.Name = name; datItem.PartName = partName; @@ -795,18 +794,18 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } // If we have a different game and we're not at the start of the list, output the end of last item - if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteEndGame(jtw); // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteStartGame(jtw, rom); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -814,7 +813,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); rom.Name = (rom.Name == "null" ? "-" : rom.Name); ((Rom)rom).Size = Constants.SizeZero; @@ -833,7 +832,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(jtw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -997,7 +996,7 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Build the state based on excluded fields jtw.WriteStartObject(); @@ -1008,56 +1007,56 @@ namespace SabreTools.Library.DatFiles if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Comment, Header.ExcludeFields))) { jtw.WritePropertyName("comment"); - jtw.WriteValue(datItem.Comment); + jtw.WriteValue(datItem.Machine.Comment); } if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Description, Header.ExcludeFields))) { jtw.WritePropertyName("description"); - jtw.WriteValue(datItem.MachineDescription); + jtw.WriteValue(datItem.Machine.Description); } if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Year, Header.ExcludeFields))) { jtw.WritePropertyName("year"); - jtw.WriteValue(datItem.Year); + jtw.WriteValue(datItem.Machine.Year); } if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Manufacturer, Header.ExcludeFields))) { jtw.WritePropertyName("manufacturer"); - jtw.WriteValue(datItem.Manufacturer); + jtw.WriteValue(datItem.Machine.Manufacturer); } if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Publisher, Header.ExcludeFields))) { jtw.WritePropertyName("publisher"); - jtw.WriteValue(datItem.Publisher); + jtw.WriteValue(datItem.Machine.Publisher); } if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Category, Header.ExcludeFields))) { jtw.WritePropertyName("category"); - jtw.WriteValue(datItem.Category); + jtw.WriteValue(datItem.Machine.Category); } - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RomOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.RomOf, StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RomOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.RomOf, StringComparison.OrdinalIgnoreCase)) { jtw.WritePropertyName("romof"); - jtw.WriteValue(datItem.RomOf); + jtw.WriteValue(datItem.Machine.RomOf); } - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.CloneOf, StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase)) { jtw.WritePropertyName("cloneof"); - jtw.WriteValue(datItem.CloneOf); + jtw.WriteValue(datItem.Machine.CloneOf); } - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.SampleOf, StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.SampleOf, StringComparison.OrdinalIgnoreCase)) { jtw.WritePropertyName("sampleof"); - jtw.WriteValue(datItem.SampleOf); + jtw.WriteValue(datItem.Machine.SampleOf); } - if (!Header.ExcludeFields.Contains(Field.Supported) && datItem.Supported != null) + if (!Header.ExcludeFields.Contains(Field.Supported) && datItem.Machine.Supported != null) { - if (datItem.Supported == true) + if (datItem.Machine.Supported == true) { jtw.WritePropertyName("supported"); jtw.WriteValue("yes"); } - else if (datItem.Supported == false) + else if (datItem.Machine.Supported == false) { jtw.WritePropertyName("supported"); jtw.WriteValue("no"); @@ -1066,16 +1065,16 @@ namespace SabreTools.Library.DatFiles if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SourceFile, Header.ExcludeFields))) { jtw.WritePropertyName("sourcefile"); - jtw.WriteValue(datItem.SourceFile); + jtw.WriteValue(datItem.Machine.SourceFile); } - if (!Header.ExcludeFields.Contains(Field.Runnable) && datItem.Runnable != null) + if (!Header.ExcludeFields.Contains(Field.Runnable) && datItem.Machine.Runnable != null) { - if (datItem.Runnable == true) + if (datItem.Machine.Runnable == true) { jtw.WritePropertyName("runnable"); jtw.WriteValue("yes"); } - else if (datItem.Runnable == false) + else if (datItem.Machine.Runnable == false) { jtw.WritePropertyName("runnable"); jtw.WriteValue("no"); @@ -1084,18 +1083,18 @@ namespace SabreTools.Library.DatFiles if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Board, Header.ExcludeFields))) { jtw.WritePropertyName("board"); - jtw.WriteValue(datItem.Board); + jtw.WriteValue(datItem.Machine.Board); } if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RebuildTo, Header.ExcludeFields))) { jtw.WritePropertyName("rebuildto"); - jtw.WriteValue(datItem.RebuildTo); + jtw.WriteValue(datItem.Machine.RebuildTo); } if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Devices, Header.ExcludeFields))) { jtw.WritePropertyName("devices"); jtw.WriteStartArray(); - foreach (string device in datItem.Devices) + foreach (string device in datItem.Machine.Devices) { jtw.WriteValue(device); } @@ -1106,7 +1105,7 @@ namespace SabreTools.Library.DatFiles { jtw.WritePropertyName("slotoptions"); jtw.WriteStartArray(); - foreach (string slotoption in datItem.SlotOptions) + foreach (string slotoption in datItem.Machine.SlotOptions) { jtw.WriteValue(slotoption); } @@ -1117,7 +1116,7 @@ namespace SabreTools.Library.DatFiles { jtw.WritePropertyName("infos"); jtw.WriteStartArray(); - foreach (var info in datItem.Infos) + foreach (var info in datItem.Machine.Infos) { jtw.WriteStartObject(); jtw.WritePropertyName(info.Key); @@ -1129,17 +1128,17 @@ namespace SabreTools.Library.DatFiles } if (!Header.ExcludeFields.Contains(Field.MachineType)) { - if (datItem.MachineType.HasFlag(MachineType.Bios)) + if (datItem.Machine.MachineType.HasFlag(MachineType.Bios)) { jtw.WritePropertyName("isbios"); jtw.WriteValue("yes"); } - if (datItem.MachineType.HasFlag(MachineType.Device)) + if (datItem.Machine.MachineType.HasFlag(MachineType.Device)) { jtw.WritePropertyName("isdevice"); jtw.WriteValue("yes"); } - if (datItem.MachineType.HasFlag(MachineType.Mechanical)) + if (datItem.Machine.MachineType.HasFlag(MachineType.Mechanical)) { jtw.WritePropertyName("ismechanical"); jtw.WriteValue("yes"); diff --git a/SabreTools.Library/DatFiles/Listrom.cs b/SabreTools.Library/DatFiles/Listrom.cs index c5c61db4..9e6e93c7 100644 --- a/SabreTools.Library/DatFiles/Listrom.cs +++ b/SabreTools.Library/DatFiles/Listrom.cs @@ -109,10 +109,16 @@ namespace SabreTools.Library.DatFiles Name = romname, SHA1 = Sanitizer.CleanListromHashData(split[0]), - MachineName = gamename, + Machine = new Machine + { + Name = gamename, + }, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; ParseAddHelper(disk); @@ -127,10 +133,16 @@ namespace SabreTools.Library.DatFiles SHA1 = Sanitizer.CleanListromHashData(split[1]), ItemStatus = ItemStatus.BadDump, - MachineName = gamename, + Machine = new Machine + { + Name = gamename, + }, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; ParseAddHelper(disk); @@ -149,10 +161,16 @@ namespace SabreTools.Library.DatFiles CRC = Sanitizer.CleanListromHashData(split[1]), SHA1 = Sanitizer.CleanListromHashData(split[2]), - MachineName = gamename, + Machine = new Machine + { + Name = gamename, + }, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; ParseAddHelper(rom); @@ -166,10 +184,16 @@ namespace SabreTools.Library.DatFiles Name = romname, ItemStatus = ItemStatus.Nodump, - MachineName = gamename, + Machine = new Machine + { + Name = gamename, + }, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; ParseAddHelper(disk); @@ -189,10 +213,16 @@ namespace SabreTools.Library.DatFiles SHA1 = Sanitizer.CleanListromHashData(split[3]), ItemStatus = ItemStatus.BadDump, - MachineName = gamename, + Machine = new Machine + { + Name = gamename, + }, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; ParseAddHelper(rom); @@ -210,10 +240,16 @@ namespace SabreTools.Library.DatFiles Size = size, ItemStatus = ItemStatus.Nodump, - MachineName = gamename, + Machine = new Machine + { + Name = gamename, + }, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; ParseAddHelper(rom); @@ -266,18 +302,18 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } // If we have a different game and we're not at the start of the list, output the end of last item - if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteEndGame(sw); // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteStartGame(sw, rom); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -285,7 +321,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); rom.Name = (rom.Name == "null" ? "-" : rom.Name); ((Rom)rom).Size = Constants.SizeZero; @@ -301,7 +337,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(sw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -329,7 +365,7 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - rom.MachineName = rom.MachineName.TrimStart(Path.DirectorySeparatorChar); + rom.Machine.Name = rom.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Build the state based on excluded fields sw.Write($"ROMs required for driver \"{rom.GetField(Field.MachineName, Header.ExcludeFields)}\".\n"); diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs index 4336cf4f..63f7041d 100644 --- a/SabreTools.Library/DatFiles/Listxml.cs +++ b/SabreTools.Library/DatFiles/Listxml.cs @@ -191,8 +191,11 @@ namespace SabreTools.Library.DatFiles Description = reader.GetAttribute("description"), Default = reader.GetAttribute("default").AsYesNo(), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; biosset.CopyMachineInformation(machine); @@ -226,8 +229,11 @@ namespace SabreTools.Library.DatFiles ItemStatus = reader.GetAttribute("status").AsItemStatus(), Optional = reader.GetAttribute("optional").AsYesNo(), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; rom.CopyMachineInformation(machine); @@ -259,8 +265,11 @@ namespace SabreTools.Library.DatFiles ItemStatus = reader.GetAttribute("status").AsItemStatus(), Optional = reader.GetAttribute("optional").AsYesNo(), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; disk.CopyMachineInformation(machine); @@ -286,8 +295,11 @@ namespace SabreTools.Library.DatFiles { Name = reader.GetAttribute("name"), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; samplerom.CopyMachineInformation(machine); @@ -487,9 +499,13 @@ namespace SabreTools.Library.DatFiles { Blank blank = new Blank() { - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; + blank.CopyMachineInformation(machine); // Now process and add the rom @@ -587,18 +603,18 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } // If we have a different game and we're not at the start of the list, output the end of last item - if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteEndGame(xtw); // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteStartGame(xtw, rom); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -606,9 +622,9 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; continue; } @@ -616,7 +632,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(xtw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -674,51 +690,51 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Build the state based on excluded fields xtw.WriteStartElement("machine"); xtw.WriteAttributeString("name", datItem.GetField(Field.MachineName, Header.ExcludeFields)); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SourceFile, Header.ExcludeFields))) - xtw.WriteAttributeString("sourcefile", datItem.SourceFile); + xtw.WriteAttributeString("sourcefile", datItem.Machine.SourceFile); if (!Header.ExcludeFields.Contains(Field.MachineType)) { - if (datItem.MachineType.HasFlag(MachineType.Bios)) + if (datItem.Machine.MachineType.HasFlag(MachineType.Bios)) xtw.WriteAttributeString("isbios", "yes"); - if (datItem.MachineType.HasFlag(MachineType.Device)) + if (datItem.Machine.MachineType.HasFlag(MachineType.Device)) xtw.WriteAttributeString("isdevice", "yes"); - if (datItem.MachineType.HasFlag(MachineType.Mechanical)) + if (datItem.Machine.MachineType.HasFlag(MachineType.Mechanical)) xtw.WriteAttributeString("ismechanical", "yes"); } if (!Header.ExcludeFields.Contains(Field.Runnable)) { - if (datItem.Runnable == true) + if (datItem.Machine.Runnable == true) xtw.WriteAttributeString("runnable", "yes"); - else if (datItem.Runnable == false) + else if (datItem.Machine.Runnable == false) xtw.WriteAttributeString("runnable", "no"); } - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.CloneOf, StringComparison.OrdinalIgnoreCase)) - xtw.WriteAttributeString("cloneof", datItem.CloneOf); - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RomOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.RomOf, StringComparison.OrdinalIgnoreCase)) - xtw.WriteAttributeString("romof", datItem.RomOf); - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.SampleOf, StringComparison.OrdinalIgnoreCase)) - xtw.WriteAttributeString("sampleof", datItem.SampleOf); + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase)) + xtw.WriteAttributeString("cloneof", datItem.Machine.CloneOf); + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RomOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.RomOf, StringComparison.OrdinalIgnoreCase)) + xtw.WriteAttributeString("romof", datItem.Machine.RomOf); + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.SampleOf, StringComparison.OrdinalIgnoreCase)) + xtw.WriteAttributeString("sampleof", datItem.Machine.SampleOf); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Description, Header.ExcludeFields))) - xtw.WriteElementString("description", datItem.MachineDescription); + xtw.WriteElementString("description", datItem.Machine.Description); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Year, Header.ExcludeFields))) - xtw.WriteElementString("year", datItem.Year); + xtw.WriteElementString("year", datItem.Machine.Year); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Publisher, Header.ExcludeFields))) - xtw.WriteElementString("publisher", datItem.Publisher); + xtw.WriteElementString("publisher", datItem.Machine.Publisher); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Category, Header.ExcludeFields))) - xtw.WriteElementString("category", datItem.Category); + xtw.WriteElementString("category", datItem.Machine.Category); - if (!Header.ExcludeFields.Contains(Field.Infos) && datItem.Infos != null && datItem.Infos.Count > 0) + if (!Header.ExcludeFields.Contains(Field.Infos) && datItem.Machine.Infos != null && datItem.Machine.Infos.Count > 0) { - foreach (KeyValuePair kvp in datItem.Infos) + foreach (KeyValuePair kvp in datItem.Machine.Infos) { xtw.WriteStartElement("info"); xtw.WriteAttributeString("name", kvp.Key); diff --git a/SabreTools.Library/DatFiles/Logiqx.cs b/SabreTools.Library/DatFiles/Logiqx.cs index d31c8661..2c9c6223 100644 --- a/SabreTools.Library/DatFiles/Logiqx.cs +++ b/SabreTools.Library/DatFiles/Logiqx.cs @@ -417,8 +417,11 @@ namespace SabreTools.Library.DatFiles Description = reader.GetAttribute("description"), Default = reader.GetAttribute("default").AsYesNo(), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; biosset.CopyMachineInformation(machine); @@ -450,8 +453,11 @@ namespace SabreTools.Library.DatFiles Date = Sanitizer.CleanDate(reader.GetAttribute("date")), Inverted = reader.GetAttribute("inverted").AsYesNo(), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; rom.CopyMachineInformation(machine); @@ -479,8 +485,11 @@ namespace SabreTools.Library.DatFiles MergeTag = reader.GetAttribute("merge"), ItemStatus = reader.GetAttribute("status").AsItemStatus(), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; disk.CopyMachineInformation(machine); @@ -498,8 +507,11 @@ namespace SabreTools.Library.DatFiles { Name = reader.GetAttribute("name"), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; samplerom.CopyMachineInformation(machine); @@ -517,8 +529,11 @@ namespace SabreTools.Library.DatFiles { Name = reader.GetAttribute("name"), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; archiverom.CopyMachineInformation(machine); @@ -540,9 +555,13 @@ namespace SabreTools.Library.DatFiles { Blank blank = new Blank() { - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; + blank.CopyMachineInformation(machine); // Now process and add the rom @@ -685,18 +704,18 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } // If we have a different game and we're not at the start of the list, output the end of last item - if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteEndGame(xtw); // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteStartGame(xtw, rom); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -704,7 +723,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); rom.Name = (rom.Name == "null" ? "-" : rom.Name); ((Rom)rom).Size = Constants.SizeZero; @@ -723,7 +742,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(xtw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -856,48 +875,48 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Build the state based on excluded fields xtw.WriteStartElement(_deprecated ? "game" : "machine"); xtw.WriteAttributeString("name", datItem.GetField(Field.MachineName, Header.ExcludeFields)); if (!Header.ExcludeFields.Contains(Field.MachineType)) { - if (datItem.MachineType.HasFlag(MachineType.Bios)) + if (datItem.Machine.MachineType.HasFlag(MachineType.Bios)) xtw.WriteAttributeString("isbios", "yes"); - if (datItem.MachineType.HasFlag(MachineType.Device)) + if (datItem.Machine.MachineType.HasFlag(MachineType.Device)) xtw.WriteAttributeString("isdevice", "yes"); - if (datItem.MachineType.HasFlag(MachineType.Mechanical)) + if (datItem.Machine.MachineType.HasFlag(MachineType.Mechanical)) xtw.WriteAttributeString("ismechanical", "yes"); } - if (!Header.ExcludeFields.Contains(Field.Runnable) && datItem.Runnable != null) + if (!Header.ExcludeFields.Contains(Field.Runnable) && datItem.Machine.Runnable != null) { - if (datItem.Runnable == true) + if (datItem.Machine.Runnable == true) xtw.WriteAttributeString("runnable", "yes"); - else if (datItem.Runnable == false) + else if (datItem.Machine.Runnable == false) xtw.WriteAttributeString("runnable", "no"); } - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.CloneOf, StringComparison.OrdinalIgnoreCase)) - xtw.WriteAttributeString("cloneof", datItem.CloneOf); - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RomOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.RomOf, StringComparison.OrdinalIgnoreCase)) - xtw.WriteAttributeString("romof", datItem.RomOf); - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.SampleOf, StringComparison.OrdinalIgnoreCase)) - xtw.WriteAttributeString("sampleof", datItem.SampleOf); + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase)) + xtw.WriteAttributeString("cloneof", datItem.Machine.CloneOf); + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RomOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.RomOf, StringComparison.OrdinalIgnoreCase)) + xtw.WriteAttributeString("romof", datItem.Machine.RomOf); + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.SampleOf, StringComparison.OrdinalIgnoreCase)) + xtw.WriteAttributeString("sampleof", datItem.Machine.SampleOf); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Comment, Header.ExcludeFields))) - xtw.WriteElementString("comment", datItem.Comment); + xtw.WriteElementString("comment", datItem.Machine.Comment); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Description, Header.ExcludeFields))) - xtw.WriteElementString("description", datItem.MachineDescription); + xtw.WriteElementString("description", datItem.Machine.Description); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Year, Header.ExcludeFields))) - xtw.WriteElementString("year", datItem.Year); + xtw.WriteElementString("year", datItem.Machine.Year); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Publisher, Header.ExcludeFields))) - xtw.WriteElementString("publisher", datItem.Publisher); + xtw.WriteElementString("publisher", datItem.Machine.Publisher); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Manufacturer, Header.ExcludeFields))) - xtw.WriteElementString("manufacturer", datItem.Manufacturer); + xtw.WriteElementString("manufacturer", datItem.Machine.Manufacturer); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Category, Header.ExcludeFields))) - xtw.WriteElementString("category", datItem.Category); + xtw.WriteElementString("category", datItem.Machine.Category); xtw.Flush(); } diff --git a/SabreTools.Library/DatFiles/Missfile.cs b/SabreTools.Library/DatFiles/Missfile.cs index d1970668..8512b221 100644 --- a/SabreTools.Library/DatFiles/Missfile.cs +++ b/SabreTools.Library/DatFiles/Missfile.cs @@ -79,7 +79,7 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; @@ -90,8 +90,8 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); - lastgame = rom.MachineName; + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); + lastgame = rom.Machine.Name; continue; } @@ -99,7 +99,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(sw, rom, lastgame, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -140,10 +140,10 @@ namespace SabreTools.Library.DatFiles { sw.Write($"{datItem.GetField(Field.Name, Header.ExcludeFields)}\n"); } - else if (!Header.UseRomName && datItem.MachineName != lastgame) + else if (!Header.UseRomName && datItem.Machine.Name != lastgame) { sw.Write($"{datItem.GetField(Field.MachineName, Header.ExcludeFields)}\n"); - lastgame = datItem.MachineName; + lastgame = datItem.Machine.Name; } sw.Flush(); diff --git a/SabreTools.Library/DatFiles/OfflineList.cs b/SabreTools.Library/DatFiles/OfflineList.cs index 47da1f5e..60e87a17 100644 --- a/SabreTools.Library/DatFiles/OfflineList.cs +++ b/SabreTools.Library/DatFiles/OfflineList.cs @@ -643,8 +643,8 @@ namespace SabreTools.Library.DatFiles for (int i = 0; i < roms.Count; i++) { roms[i].Size = size; - roms[i].Publisher = publisher; roms[i].CopyMachineInformation(machine); + roms[i].Machine.Publisher = publisher; // Now process and add the rom ParseAddHelper(roms[i]); @@ -715,8 +715,11 @@ namespace SabreTools.Library.DatFiles ItemStatus = ItemStatus.None, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }); } @@ -769,7 +772,7 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; @@ -780,7 +783,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); rom.Name = (rom.Name == "null" ? "-" : rom.Name); ((Rom)rom).Size = Constants.SizeZero; @@ -799,7 +802,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(xtw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } diff --git a/SabreTools.Library/DatFiles/OpenMSX.cs b/SabreTools.Library/DatFiles/OpenMSX.cs index 3b3f103a..82489fa2 100644 --- a/SabreTools.Library/DatFiles/OpenMSX.cs +++ b/SabreTools.Library/DatFiles/OpenMSX.cs @@ -176,9 +176,13 @@ namespace SabreTools.Library.DatFiles { Blank blank = new Blank() { - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; + blank.CopyMachineInformation(machine); // Now process and add the rom @@ -316,8 +320,11 @@ namespace SabreTools.Library.DatFiles Size = -1, SHA1 = hash, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; rom.CopyMachineInformation(machine); @@ -389,8 +396,11 @@ namespace SabreTools.Library.DatFiles Size = -1, SHA1 = hash, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; rom.CopyMachineInformation(machine); @@ -457,8 +467,11 @@ namespace SabreTools.Library.DatFiles Size = -1, SHA1 = hash, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; rom.CopyMachineInformation(machine); @@ -513,18 +526,18 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } // If we have a different game and we're not at the start of the list, output the end of last item - if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteEndGame(xtw); // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteStartGame(xtw, rom); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -532,9 +545,9 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; continue; } @@ -542,7 +555,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(xtw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -613,7 +626,7 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Build the state based on excluded fields xtw.WriteStartElement("software"); diff --git a/SabreTools.Library/DatFiles/RomCenter.cs b/SabreTools.Library/DatFiles/RomCenter.cs index d06b69d4..31928453 100644 --- a/SabreTools.Library/DatFiles/RomCenter.cs +++ b/SabreTools.Library/DatFiles/RomCenter.cs @@ -344,14 +344,21 @@ namespace SabreTools.Library.DatFiles CRC = rominfo[6], ItemStatus = ItemStatus.None, - MachineName = rominfo[3], - MachineDescription = rominfo[4], - CloneOf = rominfo[1], - RomOf = rominfo[8], + Machine = new Machine + { + Name = rominfo[3], + Description = rominfo[4], + CloneOf = rominfo[1], + RomOf = rominfo[8], + }, + MergeTag = rominfo[9], - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; // Now process and add the rom @@ -403,7 +410,7 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; @@ -414,7 +421,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); rom.Name = (rom.Name == "null" ? "-" : rom.Name); ((Rom)rom).Size = Constants.SizeZero; @@ -433,7 +440,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(iw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -521,7 +528,7 @@ namespace SabreTools.Library.DatFiles iw.WriteString($"¬{datItem.GetField(Field.CloneOf, Header.ExcludeFields)}"); iw.WriteString($"¬{datItem.GetField(Field.CloneOf, Header.ExcludeFields)}"); iw.WriteString($"¬{datItem.GetField(Field.MachineName, Header.ExcludeFields)}"); - if (string.IsNullOrWhiteSpace(datItem.MachineDescription)) + if (string.IsNullOrWhiteSpace(datItem.Machine.Description)) iw.WriteString($"¬{datItem.GetField(Field.MachineName, Header.ExcludeFields)}"); else iw.WriteString($"¬{datItem.GetField(Field.Description, Header.ExcludeFields)}"); diff --git a/SabreTools.Library/DatFiles/SabreDat.cs b/SabreTools.Library/DatFiles/SabreDat.cs index 517ae543..1efef8a4 100644 --- a/SabreTools.Library/DatFiles/SabreDat.cs +++ b/SabreTools.Library/DatFiles/SabreDat.cs @@ -360,8 +360,11 @@ namespace SabreTools.Library.DatFiles { Name = reader.GetAttribute("name"), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; break; @@ -372,8 +375,11 @@ namespace SabreTools.Library.DatFiles Description = reader.GetAttribute("description"), Default = reader.GetAttribute("default").AsYesNo(), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; break; @@ -391,8 +397,11 @@ namespace SabreTools.Library.DatFiles SHA512 = reader.GetAttribute("sha512"), ItemStatus = its, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; break; @@ -405,8 +414,11 @@ namespace SabreTools.Library.DatFiles Date = reader.GetAttribute("date"), Default = reader.GetAttribute("default").AsYesNo(), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; break; @@ -427,8 +439,11 @@ namespace SabreTools.Library.DatFiles ItemStatus = its, Date = date, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; break; @@ -437,8 +452,11 @@ namespace SabreTools.Library.DatFiles { Name = reader.GetAttribute("name"), - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; break; @@ -576,20 +594,20 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } - List newsplit = rom.MachineName.Split('\\').ToList(); + List newsplit = rom.Machine.Name.Split('\\').ToList(); // If we have a different game and we're not at the start of the list, output the end of last item - if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) depth = WriteEndGame(xtw, splitpath, newsplit, depth, out last); // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) depth = WriteStartGame(xtw, rom, newsplit, depth, last); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -597,10 +615,10 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); splitpath = newsplit; - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; continue; } @@ -609,7 +627,7 @@ namespace SabreTools.Library.DatFiles // Set the new data to compare against splitpath = newsplit; - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -772,7 +790,7 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Build the state based on excluded fields for (int i = (last == -1 ? 0 : last); i < newsplit.Count; i++) diff --git a/SabreTools.Library/DatFiles/SeparatedValue.cs b/SabreTools.Library/DatFiles/SeparatedValue.cs index 25037c15..b120f44a 100644 --- a/SabreTools.Library/DatFiles/SeparatedValue.cs +++ b/SabreTools.Library/DatFiles/SeparatedValue.cs @@ -436,8 +436,11 @@ namespace SabreTools.Library.DatFiles AreaName = areaName, AreaSize = areaSize, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; archive.CopyMachineInformation(machine); @@ -457,8 +460,11 @@ namespace SabreTools.Library.DatFiles Description = biosDescription, Default = def, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; biosset.CopyMachineInformation(machine); @@ -490,8 +496,11 @@ namespace SabreTools.Library.DatFiles ItemStatus = status, Optional = optional, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; disk.CopyMachineInformation(machine); @@ -513,8 +522,11 @@ namespace SabreTools.Library.DatFiles Date = date, Default = default, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; release.CopyMachineInformation(machine); @@ -550,8 +562,11 @@ namespace SabreTools.Library.DatFiles Optional = optional, Inverted = inverted, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; rom.CopyMachineInformation(machine); @@ -568,8 +583,11 @@ namespace SabreTools.Library.DatFiles AreaName = areaName, AreaSize = areaSize, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; sample.CopyMachineInformation(machine); @@ -902,7 +920,7 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; @@ -913,7 +931,7 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); } // Now, output the rom data diff --git a/SabreTools.Library/DatFiles/SoftwareList.cs b/SabreTools.Library/DatFiles/SoftwareList.cs index dc12841b..8c76f0e2 100644 --- a/SabreTools.Library/DatFiles/SoftwareList.cs +++ b/SabreTools.Library/DatFiles/SoftwareList.cs @@ -207,9 +207,13 @@ namespace SabreTools.Library.DatFiles { Blank blank = new Blank() { - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; + blank.CopyMachineInformation(machine); // Now process and add the rom @@ -411,8 +415,11 @@ namespace SabreTools.Library.DatFiles PartName = partname, PartInterface = partinterface, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; rom.CopyMachineInformation(machine); @@ -500,8 +507,11 @@ namespace SabreTools.Library.DatFiles PartName = partname, PartInterface = partinterface, - IndexId = indexId, - IndexSource = filename, + Source = new Source + { + Index = indexId, + Name = filename, + }, }; disk.CopyMachineInformation(machine); @@ -567,18 +577,18 @@ namespace SabreTools.Library.DatFiles DatItem rom = roms[index]; // There are apparently times when a null rom can skip by, skip them - if (rom.Name == null || rom.MachineName == null) + if (rom.Name == null || rom.Machine.Name == null) { Globals.Logger.Warning("Null rom found!"); continue; } // If we have a different game and we're not at the start of the list, output the end of last item - if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteEndGame(xtw); // If we have a new game, output the beginning of the new item - if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) + if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) WriteStartGame(xtw, rom); // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -586,9 +596,9 @@ namespace SabreTools.Library.DatFiles && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { - Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}"); + Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}"); - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; continue; } @@ -596,7 +606,7 @@ namespace SabreTools.Library.DatFiles WriteDatItem(xtw, rom, ignoreblanks); // Set the new data to compare against - lastgame = rom.MachineName; + lastgame = rom.Machine.Name; } } @@ -693,37 +703,37 @@ namespace SabreTools.Library.DatFiles try { // No game should start with a path separator - datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar); + datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); // Build the state based on excluded fields xtw.WriteStartElement("software"); xtw.WriteAttributeString("name", datItem.GetField(Field.MachineName, Header.ExcludeFields)); - if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.MachineName, datItem.CloneOf, StringComparison.OrdinalIgnoreCase)) - xtw.WriteAttributeString("cloneof", datItem.CloneOf); + if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, Header.ExcludeFields)) && !string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase)) + xtw.WriteAttributeString("cloneof", datItem.Machine.CloneOf); if (!Header.ExcludeFields.Contains(Field.Supported)) { - if (datItem.Supported == true) + if (datItem.Machine.Supported == true) xtw.WriteAttributeString("supported", "yes"); - else if (datItem.Supported == false) + else if (datItem.Machine.Supported == false) xtw.WriteAttributeString("supported", "no"); else xtw.WriteAttributeString("supported", "partial"); } if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Description, Header.ExcludeFields))) - xtw.WriteElementString("description", datItem.MachineDescription); + xtw.WriteElementString("description", datItem.Machine.Description); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Year, Header.ExcludeFields))) - xtw.WriteElementString("year", datItem.Year); + xtw.WriteElementString("year", datItem.Machine.Year); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Publisher, Header.ExcludeFields))) - xtw.WriteElementString("publisher", datItem.Publisher); + xtw.WriteElementString("publisher", datItem.Machine.Publisher); if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Category, Header.ExcludeFields))) - xtw.WriteElementString("category", datItem.Category); + xtw.WriteElementString("category", datItem.Machine.Category); - if (!Header.ExcludeFields.Contains(Field.Infos) && datItem.Infos != null && datItem.Infos.Count > 0) + if (!Header.ExcludeFields.Contains(Field.Infos) && datItem.Machine.Infos != null && datItem.Machine.Infos.Count > 0) { - foreach (KeyValuePair kvp in datItem.Infos) + foreach (KeyValuePair kvp in datItem.Machine.Infos) { xtw.WriteStartElement("info"); xtw.WriteAttributeString("name", kvp.Key); diff --git a/SabreTools.Library/DatItems/Archive.cs b/SabreTools.Library/DatItems/Archive.cs index ea6deca2..90609856 100644 --- a/SabreTools.Library/DatItems/Archive.cs +++ b/SabreTools.Library/DatItems/Archive.cs @@ -12,8 +12,8 @@ /// public Archive() { - this.Name = string.Empty; - this.ItemType = ItemType.Archive; + Name = string.Empty; + ItemType = ItemType.Archive; } #endregion @@ -28,33 +28,15 @@ ItemType = this.ItemType, DupeType = this.DupeType, - Supported = this.Supported, - Publisher = this.Publisher, - Category = this.Category, - Infos = this.Infos, PartName = this.PartName, PartInterface = this.PartInterface, Features = this.Features, AreaName = this.AreaName, AreaSize = this.AreaSize, - MachineName = this.MachineName, - Comment = this.Comment, - MachineDescription = this.MachineDescription, - Year = this.Year, - Manufacturer = this.Manufacturer, - RomOf = this.RomOf, - CloneOf = this.CloneOf, - SampleOf = this.SampleOf, - SourceFile = this.SourceFile, - Runnable = this.Runnable, - Board = this.Board, - RebuildTo = this.RebuildTo, - Devices = this.Devices, - MachineType = this.MachineType, - - IndexId = this.IndexId, - IndexSource = this.IndexSource, + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, }; } @@ -65,14 +47,14 @@ public override bool Equals(DatItem other) { // If we don't have an archive, return false - if (this.ItemType != other.ItemType) + if (ItemType != other.ItemType) return false; // Otherwise, treat it as an archive Archive newOther = other as Archive; // If the archive information matches - return (this.Name == newOther.Name); + return (Name == newOther.Name); } #endregion diff --git a/SabreTools.Library/DatItems/BiosSet.cs b/SabreTools.Library/DatItems/BiosSet.cs index 2fd8a1d5..ff4ceece 100644 --- a/SabreTools.Library/DatItems/BiosSet.cs +++ b/SabreTools.Library/DatItems/BiosSet.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; + using SabreTools.Library.Filtering; using Newtonsoft.Json; @@ -9,7 +10,7 @@ namespace SabreTools.Library.DatItems /// public class BiosSet : DatItem { - #region Publicly facing variables + #region Fields /// /// Description of the BIOS @@ -68,8 +69,8 @@ namespace SabreTools.Library.DatItems /// public BiosSet() { - this.Name = string.Empty; - this.ItemType = ItemType.BiosSet; + Name = string.Empty; + ItemType = ItemType.BiosSet; } #endregion @@ -84,33 +85,15 @@ namespace SabreTools.Library.DatItems ItemType = this.ItemType, DupeType = this.DupeType, - Supported = this.Supported, - Publisher = this.Publisher, - Category = this.Category, - Infos = this.Infos, PartName = this.PartName, PartInterface = this.PartInterface, Features = this.Features, AreaName = this.AreaName, AreaSize = this.AreaSize, - MachineName = this.MachineName, - Comment = this.Comment, - MachineDescription = this.MachineDescription, - Year = this.Year, - Manufacturer = this.Manufacturer, - RomOf = this.RomOf, - CloneOf = this.CloneOf, - SampleOf = this.SampleOf, - SourceFile = this.SourceFile, - Runnable = this.Runnable, - Board = this.Board, - RebuildTo = this.RebuildTo, - Devices = this.Devices, - MachineType = this.MachineType, - - IndexId = this.IndexId, - IndexSource = this.IndexSource, + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, Description = this.Description, Default = this.Default, @@ -124,14 +107,14 @@ namespace SabreTools.Library.DatItems public override bool Equals(DatItem other) { // If we don't have a biosset, return false - if (this.ItemType != other.ItemType) + if (ItemType != other.ItemType) return false; // Otherwise, treat it as a biosset BiosSet newOther = other as BiosSet; // If the archive information matches - return (this.Name == newOther.Name && this.Description == newOther.Description && this.Default == newOther.Default); + return (Name == newOther.Name && Description == newOther.Description && Default == newOther.Default); } #endregion diff --git a/SabreTools.Library/DatItems/Blank.cs b/SabreTools.Library/DatItems/Blank.cs index 993df723..0f15ca42 100644 --- a/SabreTools.Library/DatItems/Blank.cs +++ b/SabreTools.Library/DatItems/Blank.cs @@ -1,6 +1,4 @@ -using SabreTools.Library.Data; - -namespace SabreTools.Library.DatItems +namespace SabreTools.Library.DatItems { /// /// Represents a blank set from an input DAT @@ -14,8 +12,8 @@ namespace SabreTools.Library.DatItems /// public Blank() { - this.Name = string.Empty; - this.ItemType = ItemType.Blank; + Name = string.Empty; + ItemType = ItemType.Blank; } #endregion @@ -30,33 +28,15 @@ namespace SabreTools.Library.DatItems ItemType = this.ItemType, DupeType = this.DupeType, - Supported = this.Supported, - Publisher = this.Publisher, - Category = this.Category, - Infos = this.Infos, PartName = this.PartName, PartInterface = this.PartInterface, Features = this.Features, AreaName = this.AreaName, AreaSize = this.AreaSize, - MachineName = this.MachineName, - Comment = this.Comment, - MachineDescription = this.MachineDescription, - Year = this.Year, - Manufacturer = this.Manufacturer, - RomOf = this.RomOf, - CloneOf = this.CloneOf, - SampleOf = this.SampleOf, - SourceFile = this.SourceFile, - Runnable = this.Runnable, - Board = this.Board, - RebuildTo = this.RebuildTo, - Devices = this.Devices, - MachineType = this.MachineType, - - IndexId = this.IndexId, - IndexSource = this.IndexSource, + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, }; } @@ -67,14 +47,14 @@ namespace SabreTools.Library.DatItems public override bool Equals(DatItem other) { // If we don't have a blank, return false - if (this.ItemType != other.ItemType) + if (ItemType != other.ItemType) return false; // Otherwise, treat it as a Blank Blank newOther = other as Blank; // If the archive information matches - return (_machine == newOther._machine); + return (Machine == newOther.Machine); } #endregion diff --git a/SabreTools.Library/DatItems/DatItem.cs b/SabreTools.Library/DatItems/DatItem.cs index 80246e13..ada09dee 100644 --- a/SabreTools.Library/DatItems/DatItem.cs +++ b/SabreTools.Library/DatItems/DatItem.cs @@ -19,15 +19,7 @@ namespace SabreTools.Library.DatItems /// public abstract class DatItem : IEquatable, IComparable, ICloneable { - // TODO: Can internal fields be mapped to Field in a more reasonable way? - #region Protected instance variables - - [JsonIgnore] - protected Machine _machine = new Machine(); - - #endregion - - #region Publicly facing variables + #region Fields #region Standard item information @@ -54,500 +46,10 @@ namespace SabreTools.Library.DatItems #region Machine information /// - /// Name of the machine associated with the item + /// Machine values /// [JsonIgnore] - public string MachineName - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Name; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Name = value; - } - } - - /// - /// Additional notes on the machine - /// - [JsonIgnore] - public string Comment - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Comment; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Comment = value; - } - } - - /// - /// Extended description of the machine - /// - [JsonIgnore] - public string MachineDescription - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Description; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Description = value; - } - } - - /// - /// Machine year(s) of release/manufacture - /// - [JsonIgnore] - public string Year - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Year; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Year = value; - } - } - - /// - /// Machine manufacturer, if available - /// - [JsonIgnore] - public string Manufacturer - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Manufacturer; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Manufacturer = value; - } - } - - /// - /// Machine publisher, if available - /// - [JsonIgnore] - public string Publisher - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Publisher; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Publisher = value; - } - } - - /// - /// Machine category, if available - /// - [JsonIgnore] - public string Category - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Category; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Category = value; - } - } - - /// - /// Machine romof parent - /// - [JsonIgnore] - public string RomOf - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.RomOf; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.RomOf = value; - } - } - - /// - /// Machine cloneof parent - /// - [JsonIgnore] - public string CloneOf - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.CloneOf; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.CloneOf = value; - } - } - - /// - /// Machine sampleof parent - /// - [JsonIgnore] - public string SampleOf - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.SampleOf; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.SampleOf = value; - } - } - - /// - /// Machine support status - /// - /// yes = true, partial = null, no = false - [JsonIgnore] - public bool? Supported - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Supported; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Supported = value; - } - } - - /// - /// Emulator source file related to the machine - /// - [JsonIgnore] - public string SourceFile - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.SourceFile; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.SourceFile = value; - } - } - - /// - /// Machine runnable status - /// - /// yes = true, partial = null, no = false - [JsonIgnore] - public bool? Runnable - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Runnable; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Runnable = value; - } - } - - /// - /// Machine board name - /// - [JsonIgnore] - public string Board - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Board; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Board = value; - } - } - - /// - /// Rebuild location if different than machine name - /// - [JsonIgnore] - public string RebuildTo - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.RebuildTo; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.RebuildTo = value; - } - } - - /// - /// List of associated device names - /// - [JsonIgnore] - public List Devices - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Devices; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Devices = value; - } - } - - /// - /// List of slot options - /// - [JsonIgnore] - public List SlotOptions - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.SlotOptions; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.SlotOptions = value; - } - } - - /// - /// List of info items - /// - [JsonIgnore] - public List> Infos - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Infos; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Infos = value; - } - } - - /// - /// Type of the associated machine - /// - [JsonIgnore] - public MachineType MachineType - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.MachineType; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.MachineType = value; - } - } + public Machine Machine { get; set; } = new Machine(); #endregion @@ -585,19 +87,13 @@ namespace SabreTools.Library.DatItems #endregion - #region Source metadata information + #region Metadata information /// - /// Internal DatFile index for organization + /// Source information /// [JsonIgnore] - public int IndexId { get; set; } - - /// - /// Internal DatFile name for organization - /// - [JsonIgnore] - public string IndexSource { get; set; } + public Source Source { get; set; } = new Source(); /// /// Flag if item should be removed @@ -688,7 +184,11 @@ namespace SabreTools.Library.DatItems if (excludeFields.Contains(field)) return string.Empty; - string fieldValue = null; + // Try to get the machine field first + string fieldValue = Machine.GetField(field, excludeFields); + if (fieldValue != null) + return fieldValue; + switch (field) { case Field.Name: @@ -710,64 +210,6 @@ namespace SabreTools.Library.DatItems fieldValue = AreaSize?.ToString(); break; - case Field.MachineName: - fieldValue = MachineName; - break; - case Field.Comment: - fieldValue = Comment; - break; - case Field.Description: - fieldValue = MachineDescription; - break; - case Field.Year: - fieldValue = Year; - break; - case Field.Manufacturer: - fieldValue = Manufacturer; - break; - case Field.Publisher: - fieldValue = Publisher; - break; - case Field.Category: - fieldValue = Category; - break; - case Field.RomOf: - fieldValue = RomOf; - break; - case Field.CloneOf: - fieldValue = CloneOf; - break; - case Field.SampleOf: - fieldValue = SampleOf; - break; - case Field.Supported: - fieldValue = Supported?.ToString(); - break; - case Field.SourceFile: - fieldValue = SourceFile; - break; - case Field.Runnable: - fieldValue = Runnable?.ToString(); - break; - case Field.Board: - fieldValue = Board; - break; - case Field.RebuildTo: - fieldValue = RebuildTo; - break; - case Field.Devices: - fieldValue = string.Join(";", Devices ?? new List()); - break; - case Field.SlotOptions: - fieldValue = string.Join(";", SlotOptions ?? new List()); - break; - case Field.Infos: - fieldValue = string.Join(";", (Infos ?? new List>()).Select(i => $"{i.Key}={i.Value}")); - break; - case Field.MachineType: - fieldValue = MachineType.ToString(); - break; - case Field.NULL: default: return string.Empty; @@ -880,7 +322,7 @@ namespace SabreTools.Library.DatItems /// Existing item to copy information from public void CopyMachineInformation(DatItem item) { - _machine = (Machine)item._machine.Clone(); + Machine = (Machine)item.Machine.Clone(); } /// @@ -889,7 +331,7 @@ namespace SabreTools.Library.DatItems /// Existing machine to copy information from public void CopyMachineInformation(Machine machine) { - _machine = (Machine)machine.Clone(); + Machine = (Machine)machine.Clone(); } #endregion @@ -932,9 +374,9 @@ namespace SabreTools.Library.DatItems return output; // If the duplicate is external already or should be, set it - if (lastItem.DupeType.HasFlag(DupeType.External) || lastItem.IndexId != IndexId) + if (lastItem.DupeType.HasFlag(DupeType.External) || lastItem.Source.Index != Source.Index) { - if (lastItem.MachineName == MachineName && lastItem.Name == Name) + if (lastItem.Machine.Name == Machine.Name && lastItem.Name == Name) output = DupeType.External | DupeType.All; else output = DupeType.External | DupeType.Hash; @@ -943,7 +385,7 @@ namespace SabreTools.Library.DatItems // Otherwise, it's considered an internal dupe else { - if (lastItem.MachineName == MachineName && lastItem.Name == Name) + if (lastItem.Machine.Name == Machine.Name && lastItem.Name == Name) output = DupeType.Internal | DupeType.All; else output = DupeType.Internal | DupeType.Hash; @@ -963,147 +405,10 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public virtual bool PassesFilter(Filter filter) { - #region Machine Filters - - // Filter on machine name - bool? machineNameFound = filter.MachineName.MatchesPositiveSet(MachineName); - if (filter.IncludeOfInGame) - { - machineNameFound |= (filter.MachineName.MatchesPositiveSet(CloneOf) == true); - machineNameFound |= (filter.MachineName.MatchesPositiveSet(RomOf) == true); - } - if (machineNameFound == false) + // Filter on machine fields + if (!Machine.PassesFilter(filter)) return false; - machineNameFound = filter.MachineName.MatchesNegativeSet(MachineName); - if (filter.IncludeOfInGame) - { - machineNameFound |= (filter.MachineName.MatchesNegativeSet(CloneOf) == true); - machineNameFound |= (filter.MachineName.MatchesNegativeSet(RomOf) == true); - } - if (machineNameFound == false) - return false; - - // Filter on comment - if (filter.Comment.MatchesPositiveSet(Comment) == false) - return false; - if (filter.Comment.MatchesNegativeSet(Comment) == true) - return false; - - // Filter on machine description - if (filter.MachineDescription.MatchesPositiveSet(MachineDescription) == false) - return false; - if (filter.MachineDescription.MatchesNegativeSet(MachineDescription) == true) - return false; - - // Filter on year - if (filter.Year.MatchesPositiveSet(Year) == false) - return false; - if (filter.Year.MatchesNegativeSet(Year) == true) - return false; - - // Filter on manufacturer - if (filter.Manufacturer.MatchesPositiveSet(Manufacturer) == false) - return false; - if (filter.Manufacturer.MatchesNegativeSet(Manufacturer) == true) - return false; - - // Filter on publisher - if (filter.Publisher.MatchesPositiveSet(Publisher) == false) - return false; - if (filter.Publisher.MatchesNegativeSet(Publisher) == true) - return false; - - // Filter on category - if (filter.Category.MatchesPositiveSet(Category) == false) - return false; - if (filter.Category.MatchesNegativeSet(Category) == true) - return false; - - // Filter on romof - if (filter.RomOf.MatchesPositiveSet(RomOf) == false) - return false; - if (filter.RomOf.MatchesNegativeSet(RomOf) == true) - return false; - - // Filter on cloneof - if (filter.CloneOf.MatchesPositiveSet(CloneOf) == false) - return false; - if (filter.CloneOf.MatchesNegativeSet(CloneOf) == true) - return false; - - // Filter on sampleof - if (filter.SampleOf.MatchesPositiveSet(SampleOf) == false) - return false; - if (filter.SampleOf.MatchesNegativeSet(SampleOf) == true) - return false; - - // Filter on supported - if (filter.Supported.MatchesNeutral(null, Supported) == false) - return false; - - // Filter on source file - if (filter.SourceFile.MatchesPositiveSet(SourceFile) == false) - return false; - if (filter.SourceFile.MatchesNegativeSet(SourceFile) == true) - return false; - - // Filter on runnable - if (filter.Runnable.MatchesNeutral(null, Runnable) == false) - return false; - - // Filter on board - if (filter.Board.MatchesPositiveSet(Board) == false) - return false; - if (filter.Board.MatchesNegativeSet(Board) == true) - return false; - - // Filter on rebuildto - if (filter.RebuildTo.MatchesPositiveSet(RebuildTo) == false) - return false; - if (filter.RebuildTo.MatchesNegativeSet(RebuildTo) == true) - return false; - - // Filter on devices - if (Devices != null && Devices.Any()) - { - bool anyPositiveDevice = false; - bool anyNegativeDevice = false; - foreach (string device in Devices) - { - anyPositiveDevice |= filter.Devices.MatchesPositiveSet(device) != false; - anyNegativeDevice |= filter.Devices.MatchesNegativeSet(device) == false; - } - - if (!anyPositiveDevice || anyNegativeDevice) - return false; - } - - // Filter on slot options - if (SlotOptions != null && SlotOptions.Any()) - { - bool anyPositiveSlotOption = false; - bool anyNegativeSlotOption = false; - foreach (string slotOption in SlotOptions) - { - anyPositiveSlotOption |= filter.SlotOptions.MatchesPositiveSet(slotOption) != false; - anyNegativeSlotOption |= filter.SlotOptions.MatchesNegativeSet(slotOption) == false; - } - - if (!anyPositiveSlotOption || anyNegativeSlotOption) - return false; - } - - // Filter on machine type - if (filter.MachineTypes.MatchesPositive(MachineType.NULL, MachineType) == false) - return false; - if (filter.MachineTypes.MatchesNegative(MachineType.NULL, MachineType) == true) - return false; - - #endregion - - #region DatItem Filters - // Filter on item type if (filter.ItemTypes.MatchesPositiveSet(ItemType.ToString()) == false) return false; @@ -1142,8 +447,6 @@ namespace SabreTools.Library.DatItems else if (filter.AreaSize.MatchesNegative(null, AreaSize) == false) return false; - #endregion - return true; } @@ -1153,68 +456,8 @@ namespace SabreTools.Library.DatItems /// List of Fields to remove public virtual void RemoveFields(List fields) { - #region Machine Fields - - if (fields.Contains(Field.MachineName)) - MachineName = null; - - if (fields.Contains(Field.Comment)) - Comment = null; - - if (fields.Contains(Field.Description)) - MachineDescription = null; - - if (fields.Contains(Field.Year)) - Year = null; - - if (fields.Contains(Field.Manufacturer)) - Manufacturer = null; - - if (fields.Contains(Field.Publisher)) - Publisher = null; - - if (fields.Contains(Field.Category)) - Category = null; - - if (fields.Contains(Field.RomOf)) - RomOf = null; - - if (fields.Contains(Field.CloneOf)) - CloneOf = null; - - if (fields.Contains(Field.SampleOf)) - SampleOf = null; - - if (fields.Contains(Field.Supported)) - Supported = null; - - if (fields.Contains(Field.SourceFile)) - SourceFile = null; - - if (fields.Contains(Field.Runnable)) - Runnable = null; - - if (fields.Contains(Field.Board)) - Board = null; - - if (fields.Contains(Field.RebuildTo)) - RebuildTo = null; - - if (fields.Contains(Field.Devices)) - Devices = null; - - if (fields.Contains(Field.SlotOptions)) - SlotOptions = null; - - if (fields.Contains(Field.Infos)) - Infos = null; - - if (fields.Contains(Field.MachineType)) - MachineType = MachineType.NULL; - - #endregion - - #region Item Fields + // Remove machine fields + Machine.RemoveFields(fields); if (fields.Contains(Field.Name)) Name = null; @@ -1233,8 +476,6 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.AreaSize)) AreaSize = null; - - #endregion } #endregion @@ -1262,11 +503,11 @@ namespace SabreTools.Library.DatItems case BucketedBy.Game: key = (norename ? string.Empty - : IndexId.ToString().PadLeft(10, '0') + : Source.Index.ToString().PadLeft(10, '0') + "-") - + (string.IsNullOrWhiteSpace(MachineName) + + (string.IsNullOrWhiteSpace(Machine.Name) ? "Default" - : MachineName); + : Machine.Name); if (lower) key = key.ToLowerInvariant(); @@ -1336,75 +577,6 @@ namespace SabreTools.Library.DatItems AreaSize = item.AreaSize; } - /// - /// Replace machine fields from another item - /// - /// DatItem to pull new information from - /// List of Fields representing what should be updated - /// True if descriptions should only be replaced if the game name is the same, false otherwise - public void ReplaceMachineFields(DatItem item, List fields, bool onlySame) - { - if (fields.Contains(Field.MachineName)) - MachineName = item.MachineName; - - if (fields.Contains(Field.Comment)) - Comment = item.Comment; - - if (fields.Contains(Field.Description)) - { - if (!onlySame || (onlySame && MachineName == MachineDescription)) - MachineDescription = item.MachineDescription; - } - - if (fields.Contains(Field.Year)) - Year = item.Year; - - if (fields.Contains(Field.Manufacturer)) - Manufacturer = item.Manufacturer; - - if (fields.Contains(Field.Publisher)) - Publisher = item.Publisher; - - if (fields.Contains(Field.Category)) - Category = item.Category; - - if (fields.Contains(Field.RomOf)) - RomOf = item.RomOf; - - if (fields.Contains(Field.CloneOf)) - CloneOf = item.CloneOf; - - if (fields.Contains(Field.SampleOf)) - SampleOf = item.SampleOf; - - if (fields.Contains(Field.Supported)) - Supported = item.Supported; - - if (fields.Contains(Field.SourceFile)) - SourceFile = item.SourceFile; - - if (fields.Contains(Field.Runnable)) - Runnable = item.Runnable; - - if (fields.Contains(Field.Board)) - Board = item.Board; - - if (fields.Contains(Field.RebuildTo)) - RebuildTo = item.RebuildTo; - - if (fields.Contains(Field.Devices)) - Devices = item.Devices; - - if (fields.Contains(Field.SlotOptions)) - SlotOptions = item.SlotOptions; - - if (fields.Contains(Field.Infos)) - Infos = item.Infos; - - if (fields.Contains(Field.MachineType)) - MachineType = item.MachineType; - } - #endregion #endregion // Instance Methods @@ -1503,16 +675,15 @@ namespace SabreTools.Library.DatItems saveditem.DupeType = dupetype; // If the current system has a lower ID than the previous, set the system accordingly - if (file.IndexId < saveditem.IndexId) + if (file.Source.Index < saveditem.Source.Index) { - saveditem.IndexId = file.IndexId; - saveditem.IndexSource = file.IndexSource; + saveditem.Source = file.Source.Clone() as Source; saveditem.CopyMachineInformation(file); saveditem.Name = file.Name; } // If the current machine is a child of the new machine, use the new machine instead - if (saveditem.CloneOf == file.MachineName || saveditem.RomOf == file.MachineName) + if (saveditem.Machine.CloneOf == file.Machine.Name || saveditem.Machine.RomOf == file.Machine.Name) { saveditem.CopyMachineInformation(file); saveditem.Name = file.Name; @@ -1649,9 +820,9 @@ namespace SabreTools.Library.DatItems try { NaturalComparer nc = new NaturalComparer(); - if (x.IndexId == y.IndexId) + if (x.Source.Index == y.Source.Index) { - if (x.MachineName == y.MachineName) + if (x.Machine.Name == y.Machine.Name) { // Special case for comparing a Disk or Rom to another item type if ((x.ItemType == ItemType.Disk || x.ItemType == ItemType.Rom) ^ (y.ItemType == ItemType.Disk || y.ItemType == ItemType.Rom)) @@ -1672,10 +843,10 @@ namespace SabreTools.Library.DatItems } } - return nc.Compare(x.MachineName, y.MachineName); + return nc.Compare(x.Machine.Name, y.Machine.Name); } - return (norename ? nc.Compare(x.MachineName, y.MachineName) : x.IndexId - y.IndexId); + return (norename ? nc.Compare(x.Machine.Name, y.Machine.Name) : x.Source.Index - y.Source.Index); } catch (Exception) { diff --git a/SabreTools.Library/DatItems/Disk.cs b/SabreTools.Library/DatItems/Disk.cs index 5b75f06e..47de1d68 100644 --- a/SabreTools.Library/DatItems/Disk.cs +++ b/SabreTools.Library/DatItems/Disk.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; + using SabreTools.Library.DatFiles; using SabreTools.Library.FileTypes; using SabreTools.Library.Filtering; @@ -25,7 +26,7 @@ namespace SabreTools.Library.DatItems #endregion - #region Publicly facing variables + #region Fields /// /// Data MD5 hash @@ -202,10 +203,10 @@ namespace SabreTools.Library.DatItems /// public Disk() { - this.Name = string.Empty; - this.ItemType = ItemType.Disk; - this.DupeType = 0x00; - this.ItemStatus = ItemStatus.None; + Name = string.Empty; + ItemType = ItemType.Disk; + DupeType = 0x00; + ItemStatus = ItemStatus.None; } /// @@ -214,7 +215,7 @@ namespace SabreTools.Library.DatItems /// public Disk(BaseFile baseFile) { - this.Name = baseFile.Filename; + Name = baseFile.Filename; _md5 = baseFile.MD5; #if NET_FRAMEWORK _ripemd160 = baseFile.RIPEMD160; @@ -224,9 +225,9 @@ namespace SabreTools.Library.DatItems _sha384 = baseFile.SHA384; _sha512 = baseFile.SHA512; - this.ItemType = ItemType.Disk; - this.DupeType = 0x00; - this.ItemStatus = ItemStatus.None; + ItemType = ItemType.Disk; + DupeType = 0x00; + ItemStatus = ItemStatus.None; } #endregion @@ -241,33 +242,15 @@ namespace SabreTools.Library.DatItems ItemType = this.ItemType, DupeType = this.DupeType, - Supported = this.Supported, - Publisher = this.Publisher, - Category = this.Category, - Infos = this.Infos, PartName = this.PartName, PartInterface = this.PartInterface, Features = this.Features, AreaName = this.AreaName, AreaSize = this.AreaSize, - MachineName = this.MachineName, - Comment = this.Comment, - MachineDescription = this.MachineDescription, - Year = this.Year, - Manufacturer = this.Manufacturer, - RomOf = this.RomOf, - CloneOf = this.CloneOf, - SampleOf = this.SampleOf, - SourceFile = this.SourceFile, - Runnable = this.Runnable, - Board = this.Board, - RebuildTo = this.RebuildTo, - Devices = this.Devices, - MachineType = this.MachineType, - - IndexId = this.IndexId, - IndexSource = this.IndexSource, + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, _md5 = this._md5, #if NET_FRAMEWORK @@ -277,7 +260,12 @@ namespace SabreTools.Library.DatItems _sha256 = this._sha256, _sha384 = this._sha384, _sha512 = this._sha512, + MergeTag = this.MergeTag, + Region = this.Region, + Index = this.Index, + Writable = this.Writable, ItemStatus = this.ItemStatus, + Optional = this.Optional, }; } @@ -293,6 +281,21 @@ namespace SabreTools.Library.DatItems ItemType = ItemType.Rom, DupeType = this.DupeType, + PartName = this.PartName, + PartInterface = this.PartInterface, + Features = this.Features, + AreaName = this.AreaName, + AreaSize = this.AreaSize, + + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, + + MergeTag = this.MergeTag, + Region = this.Region, + ItemStatus = this.ItemStatus, + Optional = this.Optional, + CRC = null, MD5 = this.MD5, #if NET_FRAMEWORK @@ -302,41 +305,6 @@ namespace SabreTools.Library.DatItems SHA256 = this.SHA256, SHA384 = this.SHA384, SHA512 = this.SHA512, - - MergeTag = this.MergeTag, - Region = this.Region, - ItemStatus = this.ItemStatus, - Optional = this.Optional, - - MachineName = this.MachineName, - Comment = this.Comment, - MachineDescription = this.MachineDescription, - Year = this.Year, - Manufacturer = this.Manufacturer, - Publisher = this.Publisher, - Category = this.Category, - RomOf = this.RomOf, - CloneOf = this.CloneOf, - SampleOf = this.SampleOf, - Supported = this.Supported, - SourceFile = this.SourceFile, - Runnable = this.Runnable, - Board = this.Board, - RebuildTo = this.RebuildTo, - Devices = this.Devices, - SlotOptions = this.SlotOptions, - Infos = this.Infos, - MachineType = this.MachineType, - - PartName = this.PartName, - PartInterface = this.PartInterface, - Features = this.Features, - AreaName = this.AreaName, - AreaSize = this.AreaSize, - - IndexId = this.IndexId, - IndexSource = this.IndexSource, - Remove = this.Remove, }; return rom; diff --git a/SabreTools.Library/DatItems/Machine.cs b/SabreTools.Library/DatItems/Machine.cs index 3b10f24a..3bad0bf8 100644 --- a/SabreTools.Library/DatItems/Machine.cs +++ b/SabreTools.Library/DatItems/Machine.cs @@ -1,7 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; -using SabreTools.Library.Data; +using SabreTools.Library.Filtering; using Newtonsoft.Json; namespace SabreTools.Library.DatItems @@ -11,7 +12,7 @@ namespace SabreTools.Library.DatItems /// public class Machine : ICloneable { - #region Publicly facing variables + #region Fields /// /// Name of the machine @@ -131,6 +132,91 @@ namespace SabreTools.Library.DatItems #endregion + #region Accessors + + /// + /// Get the value of that field as a string, if possible + /// + public string GetField(Field field, List excludeFields) + { + // If the field is to be excluded, return empty string + if (excludeFields.Contains(field)) + return string.Empty; + + string fieldValue = null; + switch (field) + { + case Field.MachineName: + fieldValue = Name; + break; + case Field.Comment: + fieldValue = Comment; + break; + case Field.Description: + fieldValue = Description; + break; + case Field.Year: + fieldValue = Year; + break; + case Field.Manufacturer: + fieldValue = Manufacturer; + break; + case Field.Publisher: + fieldValue = Publisher; + break; + case Field.Category: + fieldValue = Category; + break; + case Field.RomOf: + fieldValue = RomOf; + break; + case Field.CloneOf: + fieldValue = CloneOf; + break; + case Field.SampleOf: + fieldValue = SampleOf; + break; + case Field.Supported: + fieldValue = Supported?.ToString(); + break; + case Field.SourceFile: + fieldValue = SourceFile; + break; + case Field.Runnable: + fieldValue = Runnable?.ToString(); + break; + case Field.Board: + fieldValue = Board; + break; + case Field.RebuildTo: + fieldValue = RebuildTo; + break; + case Field.Devices: + fieldValue = string.Join(";", Devices ?? new List()); + break; + case Field.SlotOptions: + fieldValue = string.Join(";", SlotOptions ?? new List()); + break; + case Field.Infos: + fieldValue = string.Join(";", (Infos ?? new List>()).Select(i => $"{i.Key}={i.Value}")); + break; + case Field.MachineType: + fieldValue = MachineType.ToString(); + break; + + default: + return null; + } + + // Make sure we don't return null + if (string.IsNullOrEmpty(fieldValue)) + fieldValue = string.Empty; + + return fieldValue; + } + + #endregion + #region Constructors /// @@ -222,5 +308,291 @@ namespace SabreTools.Library.DatItems } #endregion + + #region Filtering + + /// + /// Check to see if a Machine passes the filter + /// + /// Filter to check against + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter) + { + // Filter on machine name + bool? machineNameFound = filter.MachineName.MatchesPositiveSet(Name); + if (filter.IncludeOfInGame) + { + machineNameFound |= (filter.MachineName.MatchesPositiveSet(CloneOf) == true); + machineNameFound |= (filter.MachineName.MatchesPositiveSet(RomOf) == true); + } + if (machineNameFound == false) + return false; + + machineNameFound = filter.MachineName.MatchesNegativeSet(Name); + if (filter.IncludeOfInGame) + { + machineNameFound |= (filter.MachineName.MatchesNegativeSet(CloneOf) == true); + machineNameFound |= (filter.MachineName.MatchesNegativeSet(RomOf) == true); + } + if (machineNameFound == false) + return false; + + // Filter on comment + if (filter.Comment.MatchesPositiveSet(Comment) == false) + return false; + if (filter.Comment.MatchesNegativeSet(Comment) == true) + return false; + + // Filter on machine description + if (filter.MachineDescription.MatchesPositiveSet(Description) == false) + return false; + if (filter.MachineDescription.MatchesNegativeSet(Description) == true) + return false; + + // Filter on year + if (filter.Year.MatchesPositiveSet(Year) == false) + return false; + if (filter.Year.MatchesNegativeSet(Year) == true) + return false; + + // Filter on manufacturer + if (filter.Manufacturer.MatchesPositiveSet(Manufacturer) == false) + return false; + if (filter.Manufacturer.MatchesNegativeSet(Manufacturer) == true) + return false; + + // Filter on publisher + if (filter.Publisher.MatchesPositiveSet(Publisher) == false) + return false; + if (filter.Publisher.MatchesNegativeSet(Publisher) == true) + return false; + + // Filter on category + if (filter.Category.MatchesPositiveSet(Category) == false) + return false; + if (filter.Category.MatchesNegativeSet(Category) == true) + return false; + + // Filter on romof + if (filter.RomOf.MatchesPositiveSet(RomOf) == false) + return false; + if (filter.RomOf.MatchesNegativeSet(RomOf) == true) + return false; + + // Filter on cloneof + if (filter.CloneOf.MatchesPositiveSet(CloneOf) == false) + return false; + if (filter.CloneOf.MatchesNegativeSet(CloneOf) == true) + return false; + + // Filter on sampleof + if (filter.SampleOf.MatchesPositiveSet(SampleOf) == false) + return false; + if (filter.SampleOf.MatchesNegativeSet(SampleOf) == true) + return false; + + // Filter on supported + if (filter.Supported.MatchesNeutral(null, Supported) == false) + return false; + + // Filter on source file + if (filter.SourceFile.MatchesPositiveSet(SourceFile) == false) + return false; + if (filter.SourceFile.MatchesNegativeSet(SourceFile) == true) + return false; + + // Filter on runnable + if (filter.Runnable.MatchesNeutral(null, Runnable) == false) + return false; + + // Filter on board + if (filter.Board.MatchesPositiveSet(Board) == false) + return false; + if (filter.Board.MatchesNegativeSet(Board) == true) + return false; + + // Filter on rebuildto + if (filter.RebuildTo.MatchesPositiveSet(RebuildTo) == false) + return false; + if (filter.RebuildTo.MatchesNegativeSet(RebuildTo) == true) + return false; + + // Filter on devices + if (Devices != null && Devices.Any()) + { + bool anyPositiveDevice = false; + bool anyNegativeDevice = false; + foreach (string device in Devices) + { + anyPositiveDevice |= filter.Devices.MatchesPositiveSet(device) != false; + anyNegativeDevice |= filter.Devices.MatchesNegativeSet(device) == false; + } + + if (!anyPositiveDevice || anyNegativeDevice) + return false; + } + + // Filter on slot options + if (SlotOptions != null && SlotOptions.Any()) + { + bool anyPositiveSlotOption = false; + bool anyNegativeSlotOption = false; + foreach (string slotOption in SlotOptions) + { + anyPositiveSlotOption |= filter.SlotOptions.MatchesPositiveSet(slotOption) != false; + anyNegativeSlotOption |= filter.SlotOptions.MatchesNegativeSet(slotOption) == false; + } + + if (!anyPositiveSlotOption || anyNegativeSlotOption) + return false; + } + + // Filter on machine type + if (filter.MachineTypes.MatchesPositive(MachineType.NULL, MachineType) == false) + return false; + if (filter.MachineTypes.MatchesNegative(MachineType.NULL, MachineType) == true) + return false; + + return true; + } + + /// + /// Remove fields from the Machine + /// + /// List of Fields to remove + public void RemoveFields(List fields) + { + if (fields.Contains(Field.MachineName)) + Name = null; + + if (fields.Contains(Field.Comment)) + Comment = null; + + if (fields.Contains(Field.Description)) + Description = null; + + if (fields.Contains(Field.Year)) + Year = null; + + if (fields.Contains(Field.Manufacturer)) + Manufacturer = null; + + if (fields.Contains(Field.Publisher)) + Publisher = null; + + if (fields.Contains(Field.Category)) + Category = null; + + if (fields.Contains(Field.RomOf)) + RomOf = null; + + if (fields.Contains(Field.CloneOf)) + CloneOf = null; + + if (fields.Contains(Field.SampleOf)) + SampleOf = null; + + if (fields.Contains(Field.Supported)) + Supported = null; + + if (fields.Contains(Field.SourceFile)) + SourceFile = null; + + if (fields.Contains(Field.Runnable)) + Runnable = null; + + if (fields.Contains(Field.Board)) + Board = null; + + if (fields.Contains(Field.RebuildTo)) + RebuildTo = null; + + if (fields.Contains(Field.Devices)) + Devices = null; + + if (fields.Contains(Field.SlotOptions)) + SlotOptions = null; + + if (fields.Contains(Field.Infos)) + Infos = null; + + if (fields.Contains(Field.MachineType)) + MachineType = MachineType.NULL; + } + + #endregion + + #region Sorting and Merging + + /// + /// Replace machine fields from another item + /// + /// DatItem to pull new information from + /// List of Fields representing what should be updated + /// True if descriptions should only be replaced if the game name is the same, false otherwise + public void ReplaceFields(Machine machine, List fields, bool onlySame) + { + if (fields.Contains(Field.MachineName)) + Name = machine.Name; + + if (fields.Contains(Field.Comment)) + Comment = machine.Comment; + + if (fields.Contains(Field.Description)) + { + if (!onlySame || (onlySame && Name == Description)) + Description = machine.Description; + } + + if (fields.Contains(Field.Year)) + Year = machine.Year; + + if (fields.Contains(Field.Manufacturer)) + Manufacturer = machine.Manufacturer; + + if (fields.Contains(Field.Publisher)) + Publisher = machine.Publisher; + + if (fields.Contains(Field.Category)) + Category = machine.Category; + + if (fields.Contains(Field.RomOf)) + RomOf = machine.RomOf; + + if (fields.Contains(Field.CloneOf)) + CloneOf = machine.CloneOf; + + if (fields.Contains(Field.SampleOf)) + SampleOf = machine.SampleOf; + + if (fields.Contains(Field.Supported)) + Supported = machine.Supported; + + if (fields.Contains(Field.SourceFile)) + SourceFile = machine.SourceFile; + + if (fields.Contains(Field.Runnable)) + Runnable = machine.Runnable; + + if (fields.Contains(Field.Board)) + Board = machine.Board; + + if (fields.Contains(Field.RebuildTo)) + RebuildTo = machine.RebuildTo; + + if (fields.Contains(Field.Devices)) + Devices = machine.Devices; + + if (fields.Contains(Field.SlotOptions)) + SlotOptions = machine.SlotOptions; + + if (fields.Contains(Field.Infos)) + Infos = machine.Infos; + + if (fields.Contains(Field.MachineType)) + MachineType = machine.MachineType; + } + + #endregion } } diff --git a/SabreTools.Library/DatItems/Release.cs b/SabreTools.Library/DatItems/Release.cs index d55566d3..01f37089 100644 --- a/SabreTools.Library/DatItems/Release.cs +++ b/SabreTools.Library/DatItems/Release.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; + using SabreTools.Library.Filtering; using Newtonsoft.Json; @@ -9,7 +10,7 @@ namespace SabreTools.Library.DatItems /// public class Release : DatItem { - #region Publicly facing variables + #region Fields /// /// Release region(s) @@ -86,12 +87,12 @@ namespace SabreTools.Library.DatItems /// public Release() { - this.Name = string.Empty; - this.ItemType = ItemType.Release; - this.Region = string.Empty; - this.Language = string.Empty; - this.Date = string.Empty; - this.Default = null; + Name = string.Empty; + ItemType = ItemType.Release; + Region = string.Empty; + Language = string.Empty; + Date = string.Empty; + Default = null; } #endregion @@ -106,33 +107,15 @@ namespace SabreTools.Library.DatItems ItemType = this.ItemType, DupeType = this.DupeType, - Supported = this.Supported, - Publisher = this.Publisher, - Category = this.Category, - Infos = this.Infos, PartName = this.PartName, PartInterface = this.PartInterface, Features = this.Features, AreaName = this.AreaName, AreaSize = this.AreaSize, - MachineName = this.MachineName, - Comment = this.Comment, - MachineDescription = this.MachineDescription, - Year = this.Year, - Manufacturer = this.Manufacturer, - RomOf = this.RomOf, - CloneOf = this.CloneOf, - SampleOf = this.SampleOf, - SourceFile = this.SourceFile, - Runnable = this.Runnable, - Board = this.Board, - RebuildTo = this.RebuildTo, - Devices = this.Devices, - MachineType = this.MachineType, - - IndexId = this.IndexId, - IndexSource = this.IndexSource, + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, Region = this.Region, Language = this.Language, @@ -148,18 +131,18 @@ namespace SabreTools.Library.DatItems public override bool Equals(DatItem other) { // If we don't have a release return false - if (this.ItemType != other.ItemType) + if (ItemType != other.ItemType) return false; // Otherwise, treat it as a Release Release newOther = other as Release; // If the archive information matches - return (this.Name == newOther.Name - && this.Region == newOther.Region - && this.Language == newOther.Language - && this.Date == newOther.Date - && this.Default == newOther.Default); + return (Name == newOther.Name + && Region == newOther.Region + && Language == newOther.Language + && Date == newOther.Date + && Default == newOther.Default); } #endregion diff --git a/SabreTools.Library/DatItems/Rom.cs b/SabreTools.Library/DatItems/Rom.cs index 345e33b4..80f89c2a 100644 --- a/SabreTools.Library/DatItems/Rom.cs +++ b/SabreTools.Library/DatItems/Rom.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; + using SabreTools.Library.Data; using SabreTools.Library.DatFiles; using SabreTools.Library.FileTypes; @@ -27,7 +28,7 @@ namespace SabreTools.Library.DatItems #endregion - #region Publicly facing variables + #region Fields /// /// What BIOS is required for this rom @@ -244,11 +245,11 @@ namespace SabreTools.Library.DatItems /// public Rom() { - this.Name = string.Empty; - this.ItemType = ItemType.Rom; - this.DupeType = 0x00; - this.ItemStatus = ItemStatus.None; - this.Date = string.Empty; + Name = string.Empty; + ItemType = ItemType.Rom; + DupeType = 0x00; + ItemStatus = ItemStatus.None; + Date = string.Empty; } /// @@ -259,12 +260,12 @@ namespace SabreTools.Library.DatItems /// public Rom(string name, string machineName) { - this.Name = name; - this.ItemType = ItemType.Rom; - this.Size = -1; - this.ItemStatus = ItemStatus.None; + Name = name; + ItemType = ItemType.Rom; + Size = -1; + ItemStatus = ItemStatus.None; - _machine = new Machine + Machine = new Machine { Name = machineName, Description = machineName, @@ -277,8 +278,8 @@ namespace SabreTools.Library.DatItems /// public Rom(BaseFile baseFile) { - this.Name = baseFile.Filename; - this.Size = baseFile.Size ?? -1; + Name = baseFile.Filename; + Size = baseFile.Size ?? -1; _crc = baseFile.CRC; _md5 = baseFile.MD5; #if NET_FRAMEWORK @@ -289,10 +290,10 @@ namespace SabreTools.Library.DatItems _sha384 = baseFile.SHA384; _sha512 = baseFile.SHA512; - this.ItemType = ItemType.Rom; - this.DupeType = 0x00; - this.ItemStatus = ItemStatus.None; - this.Date = baseFile.Date; + ItemType = ItemType.Rom; + DupeType = 0x00; + ItemStatus = ItemStatus.None; + Date = baseFile.Date; } #endregion @@ -307,34 +308,17 @@ namespace SabreTools.Library.DatItems ItemType = this.ItemType, DupeType = this.DupeType, - Supported = this.Supported, - Publisher = this.Publisher, - Category = this.Category, - Infos = this.Infos, PartName = this.PartName, PartInterface = this.PartInterface, Features = this.Features, AreaName = this.AreaName, AreaSize = this.AreaSize, - MachineName = this.MachineName, - Comment = this.Comment, - MachineDescription = this.MachineDescription, - Year = this.Year, - Manufacturer = this.Manufacturer, - RomOf = this.RomOf, - CloneOf = this.CloneOf, - SampleOf = this.SampleOf, - SourceFile = this.SourceFile, - Runnable = this.Runnable, - Board = this.Board, - RebuildTo = this.RebuildTo, - Devices = this.Devices, - MachineType = this.MachineType, - - IndexId = this.IndexId, - IndexSource = this.IndexSource, + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, + Bios = this.Bios, Size = this.Size, _crc = this._crc, _md5 = this._md5, @@ -345,8 +329,13 @@ namespace SabreTools.Library.DatItems _sha256 = this._sha256, _sha384 = this._sha384, _sha512 = this._sha512, - ItemStatus = this.ItemStatus, + MergeTag = this.MergeTag, + Region = this.Region, + Offset = this.Offset, Date = this.Date, + ItemStatus = this.ItemStatus, + Optional = this.Optional, + Inverted = this.Inverted, }; } diff --git a/SabreTools.Library/DatItems/Sample.cs b/SabreTools.Library/DatItems/Sample.cs index e15d3d73..c5b53252 100644 --- a/SabreTools.Library/DatItems/Sample.cs +++ b/SabreTools.Library/DatItems/Sample.cs @@ -12,8 +12,8 @@ /// public Sample() { - this.Name = string.Empty; - this.ItemType = ItemType.Sample; + Name = string.Empty; + ItemType = ItemType.Sample; } #endregion @@ -28,33 +28,15 @@ ItemType = this.ItemType, DupeType = this.DupeType, - Supported = this.Supported, - Publisher = this.Publisher, - Category = this.Category, - Infos = this.Infos, PartName = this.PartName, PartInterface = this.PartInterface, Features = this.Features, AreaName = this.AreaName, AreaSize = this.AreaSize, - MachineName = this.MachineName, - Comment = this.Comment, - MachineDescription = this.MachineDescription, - Year = this.Year, - Manufacturer = this.Manufacturer, - RomOf = this.RomOf, - CloneOf = this.CloneOf, - SampleOf = this.SampleOf, - SourceFile = this.SourceFile, - Runnable = this.Runnable, - Board = this.Board, - RebuildTo = this.RebuildTo, - Devices = this.Devices, - MachineType = this.MachineType, - - IndexId = this.IndexId, - IndexSource = this.IndexSource, + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, }; } @@ -65,14 +47,14 @@ public override bool Equals(DatItem other) { // If we don't have a sample, return false - if (this.ItemType != other.ItemType) + if (ItemType != other.ItemType) return false; // Otherwise, treat it as a Sample Sample newOther = other as Sample; // If the archive information matches - return (this.Name == newOther.Name); + return (Name == newOther.Name); } #endregion diff --git a/SabreTools.Library/DatItems/Source.cs b/SabreTools.Library/DatItems/Source.cs new file mode 100644 index 00000000..f848aa98 --- /dev/null +++ b/SabreTools.Library/DatItems/Source.cs @@ -0,0 +1,43 @@ +using System; + +namespace SabreTools.Library.DatItems +{ + /// + /// Source information wrapper + /// + public class Source : ICloneable + { + /// + /// Source index + /// + public int Index { get; set; } + + /// + /// Source name + /// + public string Name { get; set; } + + /// + /// Constructor + /// + /// Source ID, default 0 + /// Source name, default null + public Source(int id = 0, string source = null) + { + Index = id; + Name = source; + } + + #region Cloning + + /// + /// Clone the current object + /// + public object Clone() + { + return new Source(Index, Name); + } + + #endregion + } +} diff --git a/SabreTools.Library/FileTypes/Folder.cs b/SabreTools.Library/FileTypes/Folder.cs index 485eaca2..9eae283b 100644 --- a/SabreTools.Library/FileTypes/Folder.cs +++ b/SabreTools.Library/FileTypes/Folder.cs @@ -332,7 +332,7 @@ namespace SabreTools.Library.FileTypes FileStream outputStream = null; // Get the output folder name from the first rebuild rom - string fileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.MachineName), Sanitizer.RemovePathUnsafeCharacters(rom.Name)); + string fileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name), Sanitizer.RemovePathUnsafeCharacters(rom.Name)); try { diff --git a/SabreTools.Library/FileTypes/SevenZipArchive.cs b/SabreTools.Library/FileTypes/SevenZipArchive.cs index 5070a244..13bcb6e1 100644 --- a/SabreTools.Library/FileTypes/SevenZipArchive.cs +++ b/SabreTools.Library/FileTypes/SevenZipArchive.cs @@ -452,7 +452,7 @@ namespace SabreTools.Library.FileTypes inputStream.Seek(0, SeekOrigin.Begin); // Get the output archive name from the first rebuild rom - string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".zip") ? string.Empty : ".zip")); + string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name) + (rom.Machine.Name.EndsWith(".7z") ? string.Empty : ".7z")); // Set internal variables Stream writeStream = null; @@ -660,7 +660,7 @@ namespace SabreTools.Library.FileTypes } // Get the output archive name from the first rebuild rom - string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".zip") ? string.Empty : ".zip")); + string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(roms[0].Machine.Name) + (roms[0].Machine.Name.EndsWith(".7z") ? string.Empty : ".7z")); // Set internal variables Stream writeStream = null; diff --git a/SabreTools.Library/FileTypes/TapeArchive.cs b/SabreTools.Library/FileTypes/TapeArchive.cs index 8c0dbc84..cd88ea4a 100644 --- a/SabreTools.Library/FileTypes/TapeArchive.cs +++ b/SabreTools.Library/FileTypes/TapeArchive.cs @@ -324,7 +324,7 @@ namespace SabreTools.Library.FileTypes } // Get the output archive name from the first rebuild rom - string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".tar") ? string.Empty : ".tar")); + string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name) + (rom.Machine.Name.EndsWith(".tar") ? string.Empty : ".tar")); // Set internal variables TarArchive oldTarFile = TarArchive.Create(); @@ -486,7 +486,7 @@ namespace SabreTools.Library.FileTypes } // Get the output archive name from the first rebuild rom - string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".tar") ? string.Empty : ".tar")); + string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(roms[0].Machine.Name) + (roms[0].Machine.Name.EndsWith(".tar") ? string.Empty : ".tar")); // Set internal variables TarArchive oldTarFile = TarArchive.Create(); diff --git a/SabreTools.Library/FileTypes/ZipArchive.cs b/SabreTools.Library/FileTypes/ZipArchive.cs index dfaaa365..366c2a30 100644 --- a/SabreTools.Library/FileTypes/ZipArchive.cs +++ b/SabreTools.Library/FileTypes/ZipArchive.cs @@ -457,7 +457,7 @@ namespace SabreTools.Library.FileTypes inputStream.Seek(0, SeekOrigin.Begin); // Get the output archive name from the first rebuild rom - string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".zip") ? string.Empty : ".zip")); + string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name) + (rom.Machine.Name.EndsWith(".zip") ? string.Empty : ".zip")); // Set internal variables Stream writeStream = null; @@ -666,7 +666,7 @@ namespace SabreTools.Library.FileTypes } // Get the output archive name from the first rebuild rom - string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".zip") ? string.Empty : ".zip")); + string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(roms[0].Machine.Name) + (roms[0].Machine.Name.EndsWith(".zip") ? string.Empty : ".zip")); // Set internal variables Stream writeStream = null;