From 76c3ff567b72180033506cb817f92cd1be305e32 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 17 May 2016 23:29:03 -0700 Subject: [PATCH] Add SuperDAT output to merge/dedupe --- DATabase/DATabase.cs | 27 +++++++++++++++++++-------- DATabase/MergeDiff.cs | 37 +++++++++++++++++++++++++++++++++---- SabreHelper/Build.cs | 1 + 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index 2541cd23..b2b46cc2 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -74,6 +74,7 @@ namespace SabreTools quotes = false, rem = false, romba = false, + superdat = false, trim = false, skip = false, usegame = true; @@ -198,6 +199,10 @@ namespace SabreTools case "--romba": romba = true; break; + case "-sd": + case "--superdat": + superdat = true; + break; case "--skip": skip = true; break; @@ -447,7 +452,7 @@ namespace SabreTools // Merge, diff, and dedupe at least 2 DATs else if (merge || diff) { - InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old); + InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat); } logger.Close(); @@ -909,7 +914,7 @@ Make a selection: private static void MergeDiffMenu() { string selection = "", input = "", name = "", desc = "", cat = "", version = "", author = ""; - bool dedup = false, diff = false, bare = false, forceunpack = false, old = false; + bool dedup = false, diff = false, bare = false, forceunpack = false, old = false, superdat = false; while (selection.ToLowerInvariant() != "b") { Console.Clear(); @@ -929,7 +934,8 @@ Make a selection: 9) " + (bare ? "Don't append the date to the name" : "Append the date to the name") + @" 10) " + (forceunpack ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @" 11) " + (old ? "Enable XML output" : "Enable ClrMamePro output") + @" - 12) Merge the DATs + 12) " + (superdat ? "Disable SuperDAT output" : "Enable SuperDAT output") + @" + 13) Merge the DATs B) Go back to the previous menu "); Console.Write("Enter selection: "); @@ -982,9 +988,12 @@ Make a selection: old = !old; break; case "12": + superdat = !superdat; + break; + case "13": Console.Clear(); List inputs = new List(input.Split(';')); - InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old); + InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat); Console.Write("\nPress any key to continue..."); Console.ReadKey(); selection = ""; input = ""; name = ""; desc = ""; cat = ""; version = ""; author = ""; @@ -1520,7 +1529,9 @@ Make a selection: /// True if the date should be omitted from the DAT, false otherwise /// True if the forcepacking="unzip" tag is to be added, false otherwise /// True if a old-style DAT should be output, false otherwise - private static void InitMergeDiff(List inputs, string name, string desc, string cat, string version, string author, bool diff, bool dedup, bool bare, bool forceunpack, bool old) + /// True if DATs should be merged in SuperDAT style, false otherwise + private static void InitMergeDiff(List inputs, string name, string desc, string cat, string version, string author, + bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat) { // Make sure there are no folders in inputs List newInputs = new List(); @@ -1532,7 +1543,7 @@ Make a selection: { try { - newInputs.Add(Path.GetFullPath(file)); + newInputs.Add(Path.GetFullPath(file) + "¬" + Path.GetFullPath(input.Replace("\"", ""))); } catch (PathTooLongException) { @@ -1544,7 +1555,7 @@ Make a selection: { try { - newInputs.Add(Path.GetFullPath(input.Replace("\"", ""))); + newInputs.Add(Path.GetFullPath(input.Replace("\"", "") + "¬")); } catch (PathTooLongException) { @@ -1553,7 +1564,7 @@ Make a selection: } } - MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, logger); + MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, logger); md.Process(); } diff --git a/DATabase/MergeDiff.cs b/DATabase/MergeDiff.cs index 1de06b29..b5fe64a5 100644 --- a/DATabase/MergeDiff.cs +++ b/DATabase/MergeDiff.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using SabreTools.Helper; @@ -17,6 +18,7 @@ namespace SabreTools private bool _bare; private bool _forceunpack; private bool _old; + private bool _superdat; // User specified strings private string _name; @@ -44,9 +46,10 @@ namespace SabreTools /// True if the date should be omitted from the DAT, false otherwise /// True if the forcepacking="unzip" tag is to be added, false otherwise /// True if a old-style DAT should be output, false otherwise + /// True if DATs should be parsed into SuperDAT format, false otherwise /// Logger object for console and file output public MergeDiff(List inputs, string name, string desc, string cat, string version, string author, - bool diff, bool dedup, bool bare, bool forceunpack, bool old, Logger logger) + bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat, Logger logger) { _inputs = inputs; _name = name; @@ -59,6 +62,7 @@ namespace SabreTools _bare = bare; _forceunpack = forceunpack; _old = old; + _superdat = superdat; _logger = logger; } @@ -111,11 +115,12 @@ namespace SabreTools OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml), MergeRoms = _dedup, Roms = new Dictionary>(), + Type = (_superdat ? "SuperDAT" : ""), }; foreach (string input in _inputs) { - _logger.User("Adding DAT: " + input); - userData = RomManipulation.Parse(input, i, 0, userData, _logger); + _logger.User("Adding DAT: " + input.Split('¬')[0]); + userData = RomManipulation.Parse(input.Split('¬')[0], i, 0, userData, _logger); i++; } @@ -168,7 +173,7 @@ namespace SabreTools // Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System" for (int j = 0; j < _inputs.Count; j++) { - post = " (" + Path.GetFileNameWithoutExtension(_inputs[j]) + " Only)"; + post = " (" + Path.GetFileNameWithoutExtension(_inputs[j].Split('¬')[0]) + " Only)"; DatData diffData = new DatData { Name = _name + post, @@ -249,6 +254,30 @@ namespace SabreTools // Output all entries with user-defined merge else { + // If we're in SuperDAT mode, prefix all games with their respective DATs + if (_superdat) + { + List keys = userData.Roms.Keys.ToList(); + foreach (string key in keys) + { + List newroms = new List(); + foreach (RomData rom in userData.Roms[key]) + { + RomData newrom = rom; + string filename = _inputs[newrom.SystemID].Split('¬')[0]; + string rootpath = _inputs[newrom.SystemID].Split('¬')[1]; + + rootpath += (rootpath == "" ? "" : Path.DirectorySeparatorChar.ToString()); + filename = filename.Remove(0, rootpath.Length); + newrom.Game = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar.ToString() + + Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar + newrom.Game; + newroms.Add(newrom); + Console.WriteLine(newrom.Game); + } + userData.Roms[key] = newroms; + } + } + Output.WriteDatfile(userData, "", _logger); } diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs index b3b73a91..a568424c 100644 --- a/SabreHelper/Build.cs +++ b/SabreHelper/Build.cs @@ -125,6 +125,7 @@ Options: -b, --bare Don't include date in file name -u, --unzip Force unzipping in created DAT -o, --old Output DAT in CMP format instead of XML + -sd, --superdat Enable SuperDAT creation -n=, --name= Set the internal name of the DAT -d=, --desc= Set the filename and description of the DAT -c=, --cat= Set the category of the DAT