mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Enable cascaded diffing of input files
Requested by @tractivo; allows for a series of DATs to be progressively pruned so that no dupes remain but the original info is intact.
This commit is contained in:
@@ -53,6 +53,7 @@ namespace SabreTools
|
||||
bool help = false,
|
||||
add = false,
|
||||
bare = false,
|
||||
cascade = false,
|
||||
convertMiss = false,
|
||||
convertCMP = false,
|
||||
convertRC = false,
|
||||
@@ -116,6 +117,10 @@ namespace SabreTools
|
||||
case "--bare":
|
||||
bare = true;
|
||||
break;
|
||||
case "-c":
|
||||
case "--cascade":
|
||||
cascade = true;
|
||||
break;
|
||||
case "-cc":
|
||||
case "--convert-cmp":
|
||||
convertCMP = true;
|
||||
@@ -466,7 +471,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, superdat);
|
||||
InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade);
|
||||
}
|
||||
|
||||
logger.Close();
|
||||
@@ -920,7 +925,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, superdat = false;
|
||||
bool dedup = false, diff = false, bare = false, forceunpack = false, old = false, superdat = false, cascade = false;
|
||||
while (selection.ToLowerInvariant() != "b")
|
||||
{
|
||||
Console.Clear();
|
||||
@@ -941,7 +946,8 @@ Make a selection:
|
||||
10) " + (forceunpack ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @"
|
||||
11) " + (old ? "Enable XML output" : "Enable ClrMamePro output") + @"
|
||||
12) " + (superdat ? "Disable SuperDAT output" : "Enable SuperDAT output") + @"
|
||||
13) Merge the DATs
|
||||
13) " + (cascade ? "Disable cascaded diffing (only if diff enabled)" : "Enable cascaded diffing (only if diff enabled)") + @"
|
||||
14) Merge the DATs
|
||||
B) Go back to the previous menu
|
||||
");
|
||||
Console.Write("Enter selection: ");
|
||||
@@ -997,9 +1003,12 @@ Make a selection:
|
||||
superdat = !superdat;
|
||||
break;
|
||||
case "13":
|
||||
cascade = !cascade;
|
||||
break;
|
||||
case "14":
|
||||
Console.Clear();
|
||||
List<string> inputs = new List<string>(input.Split(';'));
|
||||
InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat);
|
||||
InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade);
|
||||
Console.Write("\nPress any key to continue...");
|
||||
Console.ReadKey();
|
||||
selection = ""; input = ""; name = ""; desc = ""; cat = ""; version = ""; author = "";
|
||||
@@ -1485,8 +1494,9 @@ Make a selection:
|
||||
/// <param name="forceunpack">True if the forcepacking="unzip" tag is to be added, false otherwise</param>
|
||||
/// <param name="old">True if a old-style DAT should be output, false otherwise</param>
|
||||
/// <param name="superdat">True if DATs should be merged in SuperDAT style, false otherwise</param>
|
||||
/// <param name="cascade">True if the outputted diffs should be cascaded, false otherwise</param>
|
||||
private static void InitMergeDiff(List<string> inputs, string name, string desc, string cat, string version, string author,
|
||||
bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat)
|
||||
bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat, bool cascade)
|
||||
{
|
||||
// Make sure there are no folders in inputs
|
||||
List<string> newInputs = new List<string>();
|
||||
@@ -1519,7 +1529,7 @@ Make a selection:
|
||||
}
|
||||
}
|
||||
|
||||
MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, logger);
|
||||
MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade, logger);
|
||||
md.Process();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace SabreTools
|
||||
private bool _forceunpack;
|
||||
private bool _old;
|
||||
private bool _superdat;
|
||||
private bool _cascade;
|
||||
|
||||
// User specified strings
|
||||
private string _name;
|
||||
@@ -47,9 +48,10 @@ namespace SabreTools
|
||||
/// <param name="forceunpack">True if the forcepacking="unzip" tag is to be added, false otherwise</param>
|
||||
/// <param name="old">True if a old-style DAT should be output, false otherwise</param>
|
||||
/// <param name="superdat">True if DATs should be parsed into SuperDAT format, false otherwise</param>
|
||||
/// <param name="cascade">True if the outputted diffs should be cascaded, false otherwise</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
public MergeDiff(List<String> inputs, string name, string desc, string cat, string version, string author,
|
||||
bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat, Logger logger)
|
||||
bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat, bool cascade, Logger logger)
|
||||
{
|
||||
_inputs = inputs;
|
||||
_name = name;
|
||||
@@ -63,6 +65,7 @@ namespace SabreTools
|
||||
_forceunpack = forceunpack;
|
||||
_old = old;
|
||||
_superdat = superdat;
|
||||
_cascade = cascade;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -125,9 +128,10 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// Modify the Dictionary if necessary and output the results
|
||||
if (_diff)
|
||||
string post = "";
|
||||
if (_diff && !_cascade)
|
||||
{
|
||||
string post = " (No Duplicates)";
|
||||
post = " (No Duplicates)";
|
||||
|
||||
// Get all entries that don't have External dupes
|
||||
DatData outerDiffData = new DatData
|
||||
@@ -251,6 +255,59 @@ namespace SabreTools
|
||||
|
||||
Output.WriteDatfile(dupeData, "", _logger);
|
||||
}
|
||||
// If we're in cascade and diff, output only cascaded diffs
|
||||
else if (_diff && _cascade)
|
||||
{
|
||||
// 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].Split('¬')[0]) + " Only)";
|
||||
DatData diffData = new DatData
|
||||
{
|
||||
Name = _name + post,
|
||||
Description = _desc + post,
|
||||
Version = _version,
|
||||
Date = _date,
|
||||
Category = _cat,
|
||||
Author = _author,
|
||||
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
|
||||
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
|
||||
MergeRoms = _dedup,
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
|
||||
List<string> keys = userData.Roms.Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<RomData> oldroms = RomManipulation.Merge(userData.Roms[key]);
|
||||
List<RomData> newroms = new List<RomData>();
|
||||
|
||||
foreach (RomData rom in oldroms)
|
||||
{
|
||||
if (rom.SystemID == j)
|
||||
{
|
||||
if (diffData.Roms.ContainsKey(key))
|
||||
{
|
||||
diffData.Roms[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
diffData.Roms.Add(key, tl);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newroms.Add(rom);
|
||||
}
|
||||
}
|
||||
userData.Roms[key] = newroms;
|
||||
}
|
||||
|
||||
Output.WriteDatfile(diffData, "", _logger);
|
||||
}
|
||||
}
|
||||
// Output all entries with user-defined merge
|
||||
else
|
||||
{
|
||||
|
||||
@@ -123,6 +123,7 @@ Options:
|
||||
-lsy, --list-systems List all systems (id <= name)
|
||||
-m, --merge Merge one or more DATs
|
||||
-di, --diff Output all diffdats (merge flag not required)
|
||||
-c, --cascade Enable cascaded diffing
|
||||
-dd, --dedup Enable deduping in the created DAT
|
||||
-b, --bare Don't include date in file name
|
||||
-u, --unzip Force unzipping in created DAT
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace SabreTools.Helper
|
||||
{
|
||||
XElement elem = new XElement("datafile");
|
||||
|
||||
bool block = false, romfound = false;
|
||||
bool block = false;
|
||||
for (int k = 0; k < filecontents.Length; k++)
|
||||
{
|
||||
string line = filecontents[k];
|
||||
@@ -61,7 +61,6 @@ namespace SabreTools.Helper
|
||||
// If the line is a rom or disk and we're in a block
|
||||
else if ((line.Trim().StartsWith("rom (") || line.Trim().StartsWith("disk (")) && block)
|
||||
{
|
||||
romfound = true;
|
||||
string[] gc = line.Trim().Split(' ');
|
||||
|
||||
XElement temp = new XElement(gc[0]);
|
||||
@@ -152,7 +151,6 @@ namespace SabreTools.Helper
|
||||
// If we find an end bracket that's not associated with anything else, the block is done
|
||||
else if (Regex.IsMatch(line, _endPatternCMP) && block)
|
||||
{
|
||||
romfound = false;
|
||||
block = false;
|
||||
elem = elem.Parent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user