Files
SabreTools/MergeDAT/MergeDAT.cs

126 lines
3.0 KiB
C#
Raw Normal View History

2016-04-19 16:39:17 -07:00
using System;
using System.Collections.Generic;
using System.IO;
using SabreTools.Helper;
namespace SabreTools
{
2016-04-19 17:29:09 -07:00
public class MergeDAT
2016-04-19 16:39:17 -07:00
{
private static Logger logger;
2016-04-19 17:48:27 -07:00
/// <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.
2016-04-19 16:39:17 -07:00
public static void Main(string[] args)
{
Console.Clear();
// Credits take precidence over all
if ((new List<string>(args)).Contains("--credits"))
{
Build.Credits();
return;
}
if (args.Length == 0)
{
Build.Help();
return;
}
logger = new Logger(false, "diffdat.log");
logger.Start();
// Output the title
Build.Start("DiffDat");
List<String> inputs = new List<String>();
2016-04-19 17:31:03 -07:00
bool tofile = false, help = false, merge = false, diff = false;
2016-04-19 16:39:17 -07:00
foreach (string arg in args)
{
switch (arg)
{
case "-h":
case "-?":
case "--help":
help = true;
break;
case "-l":
case "--log":
tofile = true;
break;
case "-di":
2016-04-19 17:31:03 -07:00
case "--diff":
diff = true;
break;
case "-dd":
case "--dedup":
2016-04-19 16:58:47 -07:00
merge = true;
break;
2016-04-19 16:39:17 -07:00
default:
// Add actual files to the list of inputs
if (File.Exists(arg.Replace("\"", "")))
{
inputs.Add(Path.GetFullPath(arg.Replace("\"", "")));
}
else if (Directory.Exists(arg.Replace("\"", "")))
{
foreach (string file in Directory.EnumerateFiles(arg, "*", SearchOption.AllDirectories))
{
inputs.Add(Path.GetFullPath(file));
}
}
break;
}
}
// Set the possibly new value for logger
logger.ToFile = tofile;
// Show help if explicitly asked for it or if not enough files are supplied
if (help || inputs.Count < 2)
{
Build.Help();
logger.Close();
return;
}
2016-04-19 17:31:03 -07:00
// Otherwise, read in the files, process them and write the result to the file type that the first one is
2016-04-19 16:39:17 -07:00
List<RomData> A = new List<RomData>();
foreach (string input in inputs)
{
logger.Log("Adding DAT: " + input);
2016-04-19 16:39:17 -07:00
List<RomData> B = RomManipulation.Parse(input, 0, 0, logger);
2016-04-19 17:31:03 -07:00
if (diff)
{
A = RomManipulation.Diff(A, B);
}
else
{
A.AddRange(B);
}
2016-04-19 16:39:17 -07:00
}
2016-04-19 16:58:47 -07:00
// If we want a merged list, send it for merging before outputting
if (merge)
{
A = RomManipulation.Merge(A);
}
2016-04-20 12:31:51 -07:00
if (diff)
{
Output.WriteToDat("diffdat" + (merge ? "-merged" : ""), "diffdat" + (merge ? "-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);
}
2016-04-19 16:39:17 -07:00
}
}
}