mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Change code to better fit the logic behind the scenes
Conversations with Obiwantje cleared up what each part needs to do, allowing me to remove unnecessary pieces and clean up the logic behind each output.
This commit is contained in:
@@ -28,38 +28,24 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
// Instance variables
|
// Instance variables
|
||||||
private string _currentAllMerged;
|
private string _currentAllMerged;
|
||||||
private string _currentAllMissing;
|
private string _currentMissingMerged;
|
||||||
private List<String> _toAdd;
|
private string _currentNewMerged;
|
||||||
private string _currentWithReplaced;
|
|
||||||
private bool _fake;
|
private bool _fake;
|
||||||
private Logger _logger;
|
private Logger _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instantiate an OfflineMerge object
|
/// Instantiate an OfflineMerge object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="currentAllMerged">Old-current DAT with merged values</param>
|
/// <param name="currentAllMerged">Old-current DAT with merged and deduped values</param>
|
||||||
/// <param name="currentAllMissing">Old-current missing DAT with merged values</param>
|
/// <param name="currentMissingMerged">Old-current missing DAT with merged and deduped values</param>
|
||||||
/// <param name="toAdd">List of new files to merge in</param>
|
/// <param name="currentNewMerged">New-current DAT with merged and deduped values</param>
|
||||||
/// <param name="currentWithReplaced">New-current DAT with merged values</param>
|
|
||||||
/// <param name="fake">True if all values should be replaced with default 0-byte values, false otherwise</param>
|
/// <param name="fake">True if all values should be replaced with default 0-byte values, false otherwise</param>
|
||||||
/// <param name="logger">Logger object for console and file output</param>
|
/// <param name="logger">Logger object for console and file output</param>
|
||||||
public OfflineMerge (string currentAllMerged, string currentAllMissing, string toAdd, string currentWithReplaced, bool fake, Logger logger)
|
public OfflineMerge (string currentAllMerged, string currentMissingMerged, string currentNewMerged, bool fake, Logger logger)
|
||||||
{
|
{
|
||||||
_currentAllMerged = currentAllMerged.Replace("\"", "");
|
_currentAllMerged = currentAllMerged.Replace("\"", "");
|
||||||
_currentAllMissing = currentAllMissing.Replace("\"", "");
|
_currentMissingMerged = currentMissingMerged.Replace("\"", "");
|
||||||
_toAdd = new List<String>();
|
_currentNewMerged = currentNewMerged;
|
||||||
if (File.Exists(toAdd.Replace("\"", "")))
|
|
||||||
{
|
|
||||||
_toAdd.Add(toAdd.Replace("\"", ""));
|
|
||||||
}
|
|
||||||
else if (Directory.Exists(toAdd.Replace("\"", "")))
|
|
||||||
{
|
|
||||||
foreach (string file in Directory.EnumerateFiles(toAdd, "*", SearchOption.AllDirectories))
|
|
||||||
{
|
|
||||||
_toAdd.Add(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_currentWithReplaced = currentWithReplaced;
|
|
||||||
_fake = fake;
|
_fake = fake;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
@@ -71,9 +57,9 @@ namespace SabreTools
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Process the supplied inputs and create the three required outputs:
|
/// Process the supplied inputs and create the three required outputs:
|
||||||
/// (a) Net New - (currentWithReplaced)-(currentAllMerged)
|
/// (a) Net New - (currentNewMerged)-(currentAllMerged)
|
||||||
/// (b) New Missing - (a)+(currentAllMissing)
|
/// (b) Unneeded - (currentAllMerged)-(currentNewMerged)
|
||||||
/// (c) Unneeded - (currentAllMerged)-(currentWithReplaced)
|
/// (c) New Missing - (a)+(currentMissingMerged-(b))
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>True if the files were created properly, false otherwise</returns>
|
/// <returns>True if the files were created properly, false otherwise</returns>
|
||||||
public bool Process()
|
public bool Process()
|
||||||
@@ -81,7 +67,7 @@ namespace SabreTools
|
|||||||
// First get the combination Dictionary of currentWithReplaced and currentAllMerged
|
// First get the combination Dictionary of currentWithReplaced and currentAllMerged
|
||||||
Dictionary<string, List<RomData>> completeDats = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> completeDats = new Dictionary<string, List<RomData>>();
|
||||||
completeDats = RomManipulation.ParseDict(_currentAllMerged, 0, 0, completeDats, _logger);
|
completeDats = RomManipulation.ParseDict(_currentAllMerged, 0, 0, completeDats, _logger);
|
||||||
completeDats = RomManipulation.ParseDict(_currentWithReplaced, 0, 0, completeDats, _logger);
|
completeDats = RomManipulation.ParseDict(_currentNewMerged, 0, 0, completeDats, _logger);
|
||||||
|
|
||||||
// Now get Net New output dictionary
|
// Now get Net New output dictionary
|
||||||
Dictionary<string, List<RomData>> netNew = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> netNew = new Dictionary<string, List<RomData>>();
|
||||||
@@ -89,7 +75,7 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
if (completeDats[key].Count == 1)
|
if (completeDats[key].Count == 1)
|
||||||
{
|
{
|
||||||
if (completeDats[key][0].System == _currentWithReplaced)
|
if (completeDats[key][0].System == _currentNewMerged)
|
||||||
{
|
{
|
||||||
if (netNew.ContainsKey(key))
|
if (netNew.ContainsKey(key))
|
||||||
{
|
{
|
||||||
@@ -106,10 +92,6 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now create the New Missing dictionary
|
|
||||||
Dictionary<string, List<RomData>> newMissing = new Dictionary<string, List<RomData>>(netNew);
|
|
||||||
newMissing = RomManipulation.ParseDict(_currentAllMissing, 0, 0, newMissing, _logger);
|
|
||||||
|
|
||||||
// Now create the Unneeded dictionary
|
// Now create the Unneeded dictionary
|
||||||
Dictionary<string, List<RomData>> unneeded = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> unneeded = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in completeDats.Keys)
|
foreach (string key in completeDats.Keys)
|
||||||
@@ -133,6 +115,52 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now create the New Missing dictionary
|
||||||
|
Dictionary<string, List<RomData>> midMissing = new Dictionary<string, List<RomData>>();
|
||||||
|
midMissing = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midMissing, _logger);
|
||||||
|
foreach (string key in unneeded.Keys)
|
||||||
|
{
|
||||||
|
if (midMissing.ContainsKey(key))
|
||||||
|
{
|
||||||
|
midMissing[key].AddRange(unneeded[key]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
midMissing.Add(key, unneeded[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Dictionary<string, List<RomData>> newMissing = new Dictionary<string, List<RomData>>();
|
||||||
|
foreach (string key in midMissing.Keys)
|
||||||
|
{
|
||||||
|
if (midMissing[key].Count == 1)
|
||||||
|
{
|
||||||
|
if (midMissing[key][0].System == _currentMissingMerged)
|
||||||
|
{
|
||||||
|
if (newMissing.ContainsKey(key))
|
||||||
|
{
|
||||||
|
newMissing[key].Add(midMissing[key][0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(midMissing[key][0]);
|
||||||
|
newMissing.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (string key in netNew.Keys)
|
||||||
|
{
|
||||||
|
if (midMissing.ContainsKey(key))
|
||||||
|
{
|
||||||
|
midMissing[key].AddRange(netNew[key]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
midMissing.Add(key, netNew[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user