From d7cb9fc2b45ad9a448604e0f7e6cab90602b1783 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 20 Apr 2016 20:17:57 -0700 Subject: [PATCH] Get MergeDAT ready for merging --- MergeDAT/MergeDAT.cs | 63 +++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/MergeDAT/MergeDAT.cs b/MergeDAT/MergeDAT.cs index 8bfb058d..cee4478a 100644 --- a/MergeDAT/MergeDAT.cs +++ b/MergeDAT/MergeDAT.cs @@ -8,14 +8,24 @@ namespace SabreTools { public class MergeDAT { - private static Logger logger; + // Instance variables + private bool _diff; + private bool _dedup; + private List _inputs; + private Logger _logger; + + public MergeDAT(List inputs, bool diff, bool dedup, Logger logger) + { + _inputs = inputs; + _diff = diff; + _dedup = dedup; + _logger = logger; + } /// /// Entry point for MergeDat program /// /// String array representing command line parameters - /// TODO: @tractivo -for the A and B and AB output you could let this be determined by comparing the hashes. - /// when a hash is present in both dats then this entry goes to AB, if its only in A then it stay in A if in B then in B. public static void Main(string[] args) { Console.Clear(); @@ -33,14 +43,14 @@ namespace SabreTools return; } - logger = new Logger(false, "diffdat.log"); + Logger logger = new Logger(false, "diffdat.log"); logger.Start(); // Output the title Build.Start("DiffDat"); List inputs = new List(); - bool tofile = false, help = false, merge = false, diff = false; + bool tofile = false, help = false, dedup = false, diff = false; foreach (string arg in args) { switch (arg) @@ -60,7 +70,7 @@ namespace SabreTools break; case "-dd": case "--dedup": - merge = true; + dedup = true; break; default: // Add actual files to the list of inputs @@ -91,12 +101,33 @@ namespace SabreTools } // Otherwise, read in the files, process them and write the result to the file type that the first one is - List A = new List(); - foreach (string input in inputs) + MergeDAT md = new MergeDAT(inputs, diff, dedup, logger); + md.MergeDiff(); + } + + /// + /// Combine DATs, optionally diffing and deduping them + /// + /// True if the DATs merged correctly, false otherwise + /// + /// TODO: @tractivo -for the A and B and AB output you could let this be determined by comparing the hashes. + /// when a hash is present in both dats then this entry goes to AB, if its only in A then it stay in A if in B then in B. + /// + public bool MergeDiff() + { + // Check if there are any inputs + if (_inputs.Count == 0) { - logger.Log("Adding DAT: " + input); - List B = RomManipulation.Parse(input, 0, 0, logger); - if (diff) + _logger.Warning("No inputs were found!"); + return false; + } + + List A = new List(); + foreach (string input in _inputs) + { + _logger.Log("Adding DAT: " + input); + List B = RomManipulation.Parse(input, 0, 0, _logger); + if (_diff) { A = RomManipulation.Diff(A, B); } @@ -107,19 +138,21 @@ namespace SabreTools } // If we want a merged list, send it for merging before outputting - if (merge) + if (_dedup) { A = RomManipulation.Merge(A); } - if (diff) + if (_diff) { - Output.WriteToDat("diffdat" + (merge ? "-merged" : ""), "diffdat" + (merge ? "-merged" : ""), "", "", "DiffDat", "SabreTools", false, !RomManipulation.IsXmlDat(inputs[0]), "", A, logger); + Output.WriteToDat("diffdat" + (_dedup ? "-merged" : ""), "diffdat" + (_dedup ? "-merged" : ""), "", "", "DiffDat", "SabreTools", false, !RomManipulation.IsXmlDat(_inputs[0]), "", A, _logger); } else { - Output.WriteToDat("combinedat" + (merge ? "-merged" : ""), "combinedat" + (merge ? "-merged" : ""), "", "", "", "SabreTools", false, !RomManipulation.IsXmlDat(inputs[0]), "", A, logger); + Output.WriteToDat("combinedat" + (_dedup ? "-merged" : ""), "combinedat" + (_dedup ? "-merged" : ""), "", "", "", "SabreTools", false, !RomManipulation.IsXmlDat(_inputs[0]), "", A, _logger); } + + return true; } } }