[MergeDiff] Make main method less monolithic

This commit is contained in:
Matt Nadareski
2016-06-10 16:59:02 -07:00
parent 91980cd610
commit e78135f5a3

View File

@@ -114,12 +114,40 @@ namespace SabreTools
_author = "SabreTools"; _author = "SabreTools";
} }
// For inplace use only // Create a dictionary of all ROMs from the input DATs
DatData userData;
List<DatData> datHeaders = PopulateUserData(out userData);
// Modify the Dictionary if necessary and output the results
if (_diff && !_cascade)
{
DiffNoCascade(userData, datHeaders);
}
// If we're in cascade and diff, output only cascaded diffs
else if (_diff && _cascade)
{
DiffCascade(userData, datHeaders);
}
// Output all entries with user-defined merge
else
{
MergeNoDiff(userData, datHeaders);
}
return true;
}
/// <summary>
/// Populate the user DatData object from the input files
/// </summary>
/// <param name="userData">Output user DatData object to output</param>
/// <returns>List of DatData objects representing headers</returns>
private List<DatData> PopulateUserData(out DatData userData)
{
List<DatData> datHeaders = new List<DatData>(); List<DatData> datHeaders = new List<DatData>();
// Create a dictionary of all ROMs from the input DATs
int i = 0; int i = 0;
DatData userData = new DatData userData = new DatData
{ {
Roms = new Dictionary<string, List<RomData>>(), Roms = new Dictionary<string, List<RomData>>(),
MergeRoms = _dedup, MergeRoms = _dedup,
@@ -173,11 +201,17 @@ namespace SabreTools
userData.OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml); userData.OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml);
userData.Type = (_superdat ? "SuperDAT" : ""); userData.Type = (_superdat ? "SuperDAT" : "");
// Modify the Dictionary if necessary and output the results return datHeaders;
string post = ""; }
if (_diff && !_cascade)
/// <summary>
/// Output non-cascading diffs
/// </summary>
/// <param name="userData">Main DatData to draw information from</param>
/// <param name="datHeaders">Dat headers used optionally</param>
private void DiffNoCascade(DatData userData, List<DatData> datHeaders)
{ {
post = " (No Duplicates)"; string post = " (No Duplicates)";
// Get all entries that don't have External dupes // Get all entries that don't have External dupes
DatData outerDiffData = new DatData DatData outerDiffData = new DatData
@@ -310,9 +344,16 @@ namespace SabreTools
Output.WriteDatfile(dupeData, _outdir, _logger); Output.WriteDatfile(dupeData, _outdir, _logger);
} }
// If we're in cascade and diff, output only cascaded diffs
else if (_diff && _cascade) /// <summary>
/// Output cascading diffs
/// </summary>
/// <param name="userData">Main DatData to draw information from</param>
/// <param name="datHeaders">Dat headers used optionally</param>
private void DiffCascade(DatData userData, List<DatData> datHeaders)
{ {
string post = "";
// Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System" // Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System"
for (int j = 0; j < _inputs.Count; j++) for (int j = 0; j < _inputs.Count; j++)
{ {
@@ -390,8 +431,13 @@ namespace SabreTools
} }
} }
} }
// Output all entries with user-defined merge
else /// <summary>
/// Output user defined merge
/// </summary>
/// <param name="userData">Main DatData to draw information from</param>
/// <param name="datHeaders">Dat headers used optionally</param>
private void MergeNoDiff(DatData userData, List<DatData> datHeaders)
{ {
// If we're in SuperDAT mode, prefix all games with their respective DATs // If we're in SuperDAT mode, prefix all games with their respective DATs
if (_superdat) if (_superdat)
@@ -418,8 +464,5 @@ namespace SabreTools
Output.WriteDatfile(userData, _outdir, _logger); Output.WriteDatfile(userData, _outdir, _logger);
} }
return true;
}
} }
} }