mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Merge MergeDAT, part 6
This commit is contained in:
129
DATabase/MergeDiff.cs
Normal file
129
DATabase/MergeDiff.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Helper;
|
||||
|
||||
namespace SabreTools
|
||||
{
|
||||
public class MergeDiff
|
||||
{
|
||||
// Listing related variables
|
||||
private List<String> _inputs;
|
||||
|
||||
// User specified flags
|
||||
private bool _diff;
|
||||
private bool _dedup;
|
||||
private bool _noDate;
|
||||
private bool _forceunpack;
|
||||
private bool _old;
|
||||
|
||||
// User specified strings
|
||||
private string _name;
|
||||
private string _desc;
|
||||
private string _cat;
|
||||
private string _version;
|
||||
private string _author;
|
||||
|
||||
// Other required variables
|
||||
private string _date = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
private Logger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new MergeDAT object
|
||||
/// </summary>
|
||||
/// <param name="inputs">A List of Strings representing the DATs or DAT folders to be merged</param>
|
||||
/// <param name="name">Internal name of the DAT</param>
|
||||
/// <param name="desc">Description and external name of the DAT</param>
|
||||
/// <param name="cat">Category for the DAT</param>
|
||||
/// <param name="version">Version of the DAT</param>
|
||||
/// <param name="author">Author of the DAT</param>
|
||||
/// <param name="diff">True if a DiffDat of all inputs is wanted, false otherwise</param>
|
||||
/// <param name="dedup">True if the outputted file should remove duplicates, false otherwise</param>
|
||||
/// <param name="noDate">True if the date should be omitted from the DAT, false otherwise</param>
|
||||
/// <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="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 noDate, bool forceunpack, bool old, Logger logger)
|
||||
{
|
||||
_inputs = inputs;
|
||||
_name = name;
|
||||
_desc = desc;
|
||||
_cat = cat;
|
||||
_version = version;
|
||||
_author = author;
|
||||
_diff = diff;
|
||||
_dedup = dedup;
|
||||
_noDate = noDate;
|
||||
_forceunpack = forceunpack;
|
||||
_old = old;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <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 Process()
|
||||
{
|
||||
// Check if there are enough inputs
|
||||
if (_inputs.Count < 0)
|
||||
{
|
||||
_logger.Warning("At least inputs are required!");
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
A.AddRange(B);
|
||||
}
|
||||
}
|
||||
|
||||
// If we want a merged list, send it for merging before outputting
|
||||
if (_dedup)
|
||||
{
|
||||
A = RomManipulation.Merge(A);
|
||||
}
|
||||
|
||||
// Get the names that will be used
|
||||
if (_name == "")
|
||||
{
|
||||
_name = (_diff ? "diffdat" : "mergedat") + (_dedup ? "-merged" : "");
|
||||
}
|
||||
if (_desc == "")
|
||||
{
|
||||
_desc = (_diff ? "diffdat" : "mergedat") + (_dedup ? "-merged" : "");
|
||||
if (!_noDate)
|
||||
{
|
||||
_desc += " (" + _date + ")";
|
||||
}
|
||||
}
|
||||
if (_cat == "" && _diff)
|
||||
{
|
||||
_cat = "DiffDAT";
|
||||
}
|
||||
if (_author == "")
|
||||
{
|
||||
_author = "SabreTools";
|
||||
}
|
||||
|
||||
// Now write the file out
|
||||
Output.WriteToDat(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, "", A, _logger);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user