diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs b/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs index 7059f682..b41c5c09 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs @@ -370,6 +370,65 @@ namespace SabreTools.Helper.Dats _files = sortable; } + /// + /// Use cloneof tags to create merged sets and remove the tags plus using the device_ref tags to get full sets + /// + /// 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 + public void CreateFullyMergedSets(bool mergeroms, Logger logger, bool output = true) + { + // For sake of ease, the first thing we want to do is sort by game + BucketByGame(mergeroms, false, logger, output); + + // Now we want to loop through all of the games and set the correct information + List games = Keys.ToList(); + foreach (string game in games) + { + // 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. + */ + + // Determine if the game has a parent or not + string parent = null; + if (this[game][0].Machine.CloneOf != null) + { + parent = this[game][0].Machine.CloneOf; + } + else if (this[game][0].Machine.RomOf != null) + { + parent = this[game][0].Machine.RomOf; + } + + // If there is no parent, then we continue + if (parent == null) + { + continue; + } + + // If the parent doesn't exist, then we continue + if (this[parent].Count == 0) + { + continue; + } + + // Otherwise, move the items from the current game to a subfolder of the parent game + Machine parentMachine = this[parent][0].Machine; + List items = this[game]; + foreach (DatItem item in items) + { + item.Name = item.Machine.Name + "\\" + item.Name; + item.Machine = parentMachine; + } + + // Finally, remove the old game so it's not picked up by the writer + Remove(game); + } + } + /// /// Use cloneof tags to create merged sets and remove the tags /// @@ -460,18 +519,53 @@ namespace SabreTools.Helper.Dats continue; } - /* - * Okay, so here actual copies of the roms need to be copied into the current game, so - * you need to make sure that you make a copy and don't ruin the original version since the original - * parnt is still a valid piece of set - */ - // Otherwise, copy the items from the parent to the current game - Machine parentMachine = this[game][0].Machine; + Machine currentMachine = this[game][0].Machine; List items = this[parent]; foreach (DatItem item in items) { - + // Figure out the type of the item and add it accordingly + switch (item.Type) + { + case ItemType.Archive: + Archive archive = (Archive)item; + archive.Machine = currentMachine; + this[parent].Add(archive); + break; + case ItemType.BiosSet: + BiosSet biosSet = (BiosSet)item; + biosSet.Machine = currentMachine; + this[parent].Add(biosSet); + break; + case ItemType.Disk: + Disk disk = (Disk)item; + disk.Machine = currentMachine; + this[parent].Add(disk); + break; + case ItemType.Release: + Release release = (Release)item; + release.Machine = currentMachine; + this[parent].Add(release); + break; + case ItemType.Rom: + Rom rom = (Rom)item; + rom.Machine = currentMachine; + this[parent].Add(rom); + break; + case ItemType.Sample: + Sample sample = (Sample)item; + sample.Machine = currentMachine; + this[parent].Add(sample); + break; + } + } + + // Finally, remove the romof and cloneof tags so it's not picked up by the manager + items = this[game]; + foreach (DatItem item in items) + { + item.Machine.CloneOf = null; + item.Machine.RomOf = null; } } } diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs b/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs index 7363ca15..49765580 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs @@ -137,7 +137,7 @@ namespace SabreTools.Helper.Dats } else if (splitType == SplitType.MergedWithDevice) { - logger.User("Full merging is not yet available. Sorry for the inconvenience"); + CreateFullyMergedSets(false, logger, output: false); } }