mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Get MergeDAT ready for merging
This commit is contained in:
@@ -8,14 +8,24 @@ namespace SabreTools
|
||||
{
|
||||
public class MergeDAT
|
||||
{
|
||||
private static Logger logger;
|
||||
// Instance variables
|
||||
private bool _diff;
|
||||
private bool _dedup;
|
||||
private List<String> _inputs;
|
||||
private Logger _logger;
|
||||
|
||||
public MergeDAT(List<String> inputs, bool diff, bool dedup, Logger logger)
|
||||
{
|
||||
_inputs = inputs;
|
||||
_diff = diff;
|
||||
_dedup = dedup;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entry point for MergeDat program
|
||||
/// </summary>
|
||||
/// <param name="args">String array representing command line parameters</param>
|
||||
/// 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<String> inputs = new List<String>();
|
||||
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<RomData> A = new List<RomData>();
|
||||
foreach (string input in inputs)
|
||||
MergeDAT md = new MergeDAT(inputs, diff, dedup, logger);
|
||||
md.MergeDiff();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Combine DATs, optionally diffing and deduping them
|
||||
/// </summary>
|
||||
/// <returns>True if the DATs merged correctly, false otherwise</returns>
|
||||
/// <remarks>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
public bool MergeDiff()
|
||||
{
|
||||
// Check if there are any inputs
|
||||
if (_inputs.Count == 0)
|
||||
{
|
||||
logger.Log("Adding DAT: " + input);
|
||||
List<RomData> B = RomManipulation.Parse(input, 0, 0, logger);
|
||||
if (diff)
|
||||
_logger.Warning("No inputs were found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
List<RomData> A = new List<RomData>();
|
||||
foreach (string input in _inputs)
|
||||
{
|
||||
_logger.Log("Adding DAT: " + input);
|
||||
List<RomData> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user