Files
SabreTools/DiffDat/MergeDAT.cs

102 lines
2.2 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;
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 16:58:47 -07:00
bool tofile = false, help = false, merge = 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;
2016-04-19 16:58:47 -07:00
case "-m":
case "--merge":
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;
}
// Otherwise, read in the files, diff 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);
A = RomManipulation.Diff(A, B);
}
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-19 16:39:17 -07:00
Output.WriteToDat("diffdat", "diffdat", "", "", "DiffDat", "SabreTools", false, !RomManipulation.IsXmlDat(inputs[0]), "", A, logger);
}
}
}