From 14915d5918c6a96ca05b930449b51ba1caa6eeb5 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 9 Jan 2017 15:58:29 -0800 Subject: [PATCH] [DatFile, Machine] Allow for device references --- SabreTools.Helper/Dats/Machine.cs | 10 +- .../Dats/Partials/DatFile.Bucketing.cs | 107 ++++++++++++++++-- 2 files changed, 107 insertions(+), 10 deletions(-) diff --git a/SabreTools.Helper/Dats/Machine.cs b/SabreTools.Helper/Dats/Machine.cs index 85aa4c74..5f27f92a 100644 --- a/SabreTools.Helper/Dats/Machine.cs +++ b/SabreTools.Helper/Dats/Machine.cs @@ -1,4 +1,6 @@ -using SabreTools.Helper.Data; +using System.Collections.Generic; + +using SabreTools.Helper.Data; namespace SabreTools.Helper.Dats { @@ -19,6 +21,7 @@ namespace SabreTools.Helper.Dats protected bool _runnable; protected string _board; protected string _rebuildTo; + protected List _devices; protected MachineType _machineType; #endregion @@ -86,6 +89,11 @@ namespace SabreTools.Helper.Dats get { return _rebuildTo; } set { _rebuildTo = value; } } + public List Devices + { + get { return _devices; } + set { _devices = value; } + } public MachineType MachineType { get { return _machineType; } diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs b/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs index 8c66e280..9847db16 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs @@ -376,16 +376,8 @@ namespace SabreTools.Helper.Dats /// True if roms should be deduped, false otherwise /// Logger object for file and console output /// True if the number of hashes counted is to be output (default), false otherwise - /// TODO: This is not actually complete currently as it copies the code from CreateMergedSets public void CreateFullyNonMergedSets(bool mergeroms, Logger logger, bool output = true) { - // First, we try to add all device items first - /* - Here, we require that device_ref tags got read first, and then we can add them accordingly. - As of right now, those tags are NOT being read into the machine. We'd have to do this in - order to get this working correctly. At least this is a good placeholder for now. - */ - // For sake of ease, the first thing we want to do is sort by game BucketByGame(mergeroms, true, logger, output); _sortedBy = SortedBy.Default; @@ -394,6 +386,93 @@ namespace SabreTools.Helper.Dats List games = Keys.ToList(); foreach (string game in games) { + // Determine if the game has any devices or not + if (this[game][0].Machine.Devices.Count > 0) + { + List devices = this[game][0].Machine.Devices; + foreach (string device in devices) + { + // If the device doesn't exist then we continue + if (this[device].Count == 0) + { + continue; + } + + // Otherwise, copy the items from the device to the current game + Machine musheen = this[game][0].Machine; + List devItems = this[device]; + foreach (DatItem item in devItems) + { + // Figure out the type of the item and add it accordingly + switch (item.Type) + { + case ItemType.Archive: + Archive archive = ((Archive)item).Clone() as Archive; + archive.Machine = musheen; + if (!this[game].Contains(archive)) + { + this[game].Add(archive); + } + + break; + case ItemType.BiosSet: + BiosSet biosSet = ((BiosSet)item).Clone() as BiosSet; + biosSet.Machine = musheen; + if (!this[game].Contains(biosSet)) + { + this[game].Add(biosSet); + } + + break; + case ItemType.Disk: + Disk disk = ((Disk)item).Clone() as Disk; + disk.Machine = musheen; + if (!this[game].Contains(disk)) + { + this[game].Add(disk); + } + + break; + case ItemType.Release: + Release release = ((Release)item).Clone() as Release; + release.Machine = musheen; + if (!this[game].Contains(release)) + { + this[game].Add(release); + } + + break; + case ItemType.Rom: + Rom rom = ((Rom)item).Clone() as Rom; + rom.Machine = musheen; + if (!this[game].Contains(rom)) + { + this[game].Add(rom); + } + + break; + case ItemType.Sample: + Sample sample = ((Sample)item).Clone() as Sample; + sample.Machine = musheen; + if (!this[game].Contains(sample)) + { + this[game].Add(sample); + } + + break; + } + } + + // Then, remove the romof and cloneof tags so it's not picked up by the manager + devItems = this[game]; + foreach (DatItem item in devItems) + { + item.Machine.CloneOf = null; + item.Machine.RomOf = null; + } + } + } + // Determine if the game has a parent or not string parent = null; if (!String.IsNullOrEmpty(this[game][0].Machine.CloneOf)) @@ -489,7 +568,7 @@ namespace SabreTools.Helper.Dats } } - // Finally, remove the romof and cloneof tags so it's not picked up by the manager + // Then, remove the romof and cloneof tags so it's not picked up by the manager items = this[game]; foreach (DatItem item in items) { @@ -497,6 +576,16 @@ namespace SabreTools.Helper.Dats item.Machine.RomOf = null; } } + + // Finally, we want to remove all games that have the BIOS or Device tags + games = Keys.ToList(); + foreach (string game in games) + { + if (this[game][0].Machine.MachineType == MachineType.Bios || this[game][0].Machine.MachineType == MachineType.Device) + { + Remove(game); + } + } } ///