2016-04-28 14:08:06 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
using SabreTools.Helper;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SabreTools
|
|
|
|
|
|
{
|
|
|
|
|
|
public class OfflineMerge
|
|
|
|
|
|
{
|
|
|
|
|
|
// Instance variables
|
|
|
|
|
|
private string _currentAllMerged;
|
2016-04-28 15:00:55 -07:00
|
|
|
|
private string _currentMissingMerged;
|
|
|
|
|
|
private string _currentNewMerged;
|
2016-04-28 14:08:06 -07:00
|
|
|
|
private bool _fake;
|
|
|
|
|
|
private Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Instantiate an OfflineMerge object
|
|
|
|
|
|
/// </summary>
|
2016-04-28 15:00:55 -07:00
|
|
|
|
/// <param name="currentAllMerged">Old-current DAT with merged and deduped values</param>
|
|
|
|
|
|
/// <param name="currentMissingMerged">Old-current missing DAT with merged and deduped values</param>
|
|
|
|
|
|
/// <param name="currentNewMerged">New-current DAT with merged and deduped values</param>
|
2016-04-28 14:08:06 -07:00
|
|
|
|
/// <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>
|
2016-04-28 15:00:55 -07:00
|
|
|
|
public OfflineMerge (string currentAllMerged, string currentMissingMerged, string currentNewMerged, bool fake, Logger logger)
|
2016-04-28 14:08:06 -07:00
|
|
|
|
{
|
|
|
|
|
|
_currentAllMerged = currentAllMerged.Replace("\"", "");
|
2016-04-28 15:00:55 -07:00
|
|
|
|
_currentMissingMerged = currentMissingMerged.Replace("\"", "");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
_currentNewMerged = currentNewMerged.Replace("\"", "");
|
2016-04-28 14:08:06 -07:00
|
|
|
|
_fake = fake;
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
|
{
|
2016-04-28 15:40:54 -07:00
|
|
|
|
// Perform initial setup and verification
|
2016-05-10 15:41:33 -07:00
|
|
|
|
Logger logger = new Logger(true, "offlinemerge.log");
|
2016-04-28 15:40:54 -07:00
|
|
|
|
logger.Start();
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
// Credits take precidence over all
|
|
|
|
|
|
if ((new List<string>(args)).Contains("--credits"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Build.Credits();
|
|
|
|
|
|
logger.Close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If there's no arguments, show the help
|
|
|
|
|
|
if (args.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Build.Help();
|
|
|
|
|
|
logger.Close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set all default values
|
|
|
|
|
|
bool help = false, fake = false;
|
|
|
|
|
|
string currentAllMerged = "", currentMissingMerged = "", currentNewMerged = "";
|
|
|
|
|
|
|
|
|
|
|
|
// Determine which switches are enabled (with values if necessary)
|
|
|
|
|
|
foreach (string arg in args)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "-?":
|
|
|
|
|
|
case "-h":
|
|
|
|
|
|
case "--help":
|
|
|
|
|
|
help = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "-f":
|
|
|
|
|
|
case "--fake":
|
|
|
|
|
|
fake = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2016-05-04 14:43:40 -07:00
|
|
|
|
string temparg = arg.Replace("\"", "");
|
2016-05-04 15:09:31 -07:00
|
|
|
|
if (temparg.StartsWith("-com="))
|
2016-04-28 15:40:54 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
currentAllMerged = temparg.Split('=')[1];
|
2016-04-28 15:40:54 -07:00
|
|
|
|
}
|
2016-05-04 15:09:31 -07:00
|
|
|
|
else if (temparg.StartsWith("-fix="))
|
2016-04-28 15:54:29 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
currentMissingMerged = temparg.Split('=')[1];
|
|
|
|
|
|
}
|
2016-05-04 15:09:31 -07:00
|
|
|
|
else if (temparg.StartsWith("-new="))
|
2016-05-04 14:43:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
currentNewMerged = temparg.Split('=')[1];
|
2016-04-28 15:54:29 -07:00
|
|
|
|
}
|
2016-04-28 15:40:54 -07:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.Warning("Invalid input detected: " + arg);
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
|
Build.Help();
|
|
|
|
|
|
logger.Close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2016-04-28 16:39:12 -07:00
|
|
|
|
}
|
2016-04-28 15:40:54 -07:00
|
|
|
|
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// If help is set or all of the inputs are empty, show help
|
|
|
|
|
|
if (help || (currentAllMerged == "" && currentMissingMerged == "" && currentNewMerged == ""))
|
2016-04-28 16:39:12 -07:00
|
|
|
|
{
|
|
|
|
|
|
Build.Help();
|
|
|
|
|
|
logger.Close();
|
|
|
|
|
|
return;
|
2016-04-28 15:40:54 -07:00
|
|
|
|
}
|
2016-04-28 16:39:12 -07:00
|
|
|
|
|
|
|
|
|
|
// Otherwise, run the program
|
|
|
|
|
|
OfflineMerge om = new OfflineMerge(currentAllMerged, currentMissingMerged, currentNewMerged, fake, logger);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
bool success = om.Process();
|
|
|
|
|
|
if (!success)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.Warning("At least one complete DAT and the fixdat is needed to run!");
|
|
|
|
|
|
}
|
2016-04-28 14:08:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-05-04 14:43:40 -07:00
|
|
|
|
/// Process the supplied inputs and create the four outputs
|
2016-04-28 14:08:06 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>True if the files were created properly, false otherwise</returns>
|
|
|
|
|
|
public bool Process()
|
|
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// Check all of the files for validity and break if one doesn't exist
|
|
|
|
|
|
if (_currentAllMerged != "" && !File.Exists(_currentAllMerged))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_currentMissingMerged != "" && !File.Exists(_currentMissingMerged))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_currentNewMerged != "" && !File.Exists(_currentNewMerged))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we have all three DATs, then generate everything
|
|
|
|
|
|
if (_currentAllMerged != "" && _currentMissingMerged != "" && _currentNewMerged != "")
|
2016-04-28 14:30:02 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// First get the combination Dictionary of currentAllMerged and currentNewMerged
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Adding Current and New Merged DATs to the dictionary");
|
2016-05-21 00:45:56 -07:00
|
|
|
|
DatData completeDats = new DatData();
|
2016-05-16 21:52:49 -07:00
|
|
|
|
completeDats = RomManipulation.Parse(_currentAllMerged, 0, 0, completeDats, _logger);
|
|
|
|
|
|
completeDats = RomManipulation.Parse(_currentNewMerged, 0, 0, completeDats, _logger);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
|
|
|
|
|
|
// Now get Net New output dictionary [(currentNewMerged)-(currentAllMerged)]
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Creating and populating Net New dictionary");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
Dictionary<string, List<RomData>> netNew = new Dictionary<string, List<RomData>>();
|
2016-05-16 14:28:23 -07:00
|
|
|
|
foreach (string key in completeDats.Roms.Keys)
|
2016-04-28 14:30:02 -07:00
|
|
|
|
{
|
2016-05-16 14:28:23 -07:00
|
|
|
|
List<RomData> templist = RomManipulation.Merge(completeDats.Roms[key]);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
foreach (RomData rom in templist)
|
2016-04-28 14:30:02 -07:00
|
|
|
|
{
|
2016-05-10 21:03:41 -07:00
|
|
|
|
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
2016-04-28 14:30:02 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
if (netNew.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
netNew[key].Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
netNew.Add(key, temp);
|
|
|
|
|
|
}
|
2016-04-28 14:30:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// Now create the Unneeded dictionary [(currentAllMerged)-(currentNewMerged)]
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Creating and populating Uneeded dictionary");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
Dictionary<string, List<RomData>> unneeded = new Dictionary<string, List<RomData>>();
|
2016-05-16 14:28:23 -07:00
|
|
|
|
foreach (string key in completeDats.Roms.Keys)
|
2016-04-28 14:30:02 -07:00
|
|
|
|
{
|
2016-05-16 14:28:23 -07:00
|
|
|
|
List<RomData> templist = RomManipulation.Merge(completeDats.Roms[key]);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
foreach (RomData rom in templist)
|
2016-04-28 14:30:02 -07:00
|
|
|
|
{
|
2016-05-10 21:03:41 -07:00
|
|
|
|
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
|
2016-04-28 14:30:02 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
if (unneeded.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
unneeded[key].Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
unneeded.Add(key, temp);
|
|
|
|
|
|
}
|
2016-04-28 14:30:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// Now create the New Missing dictionary [(Net New)+(currentMissingMerged-(Unneeded))]
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Creating and populating New Missing dictionary");
|
2016-05-21 00:45:56 -07:00
|
|
|
|
DatData midMissing = new DatData();
|
2016-05-16 21:52:49 -07:00
|
|
|
|
midMissing = RomManipulation.Parse(_currentMissingMerged, 0, 0, midMissing, _logger);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
foreach (string key in unneeded.Keys)
|
2016-04-28 15:00:55 -07:00
|
|
|
|
{
|
2016-05-16 14:28:23 -07:00
|
|
|
|
if (midMissing.Roms.ContainsKey(key))
|
2016-05-04 14:43:40 -07:00
|
|
|
|
{
|
2016-05-16 14:28:23 -07:00
|
|
|
|
midMissing.Roms[key].AddRange(unneeded[key]);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-05-16 14:28:23 -07:00
|
|
|
|
midMissing.Roms.Add(key, unneeded[key]);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
}
|
2016-04-28 15:00:55 -07:00
|
|
|
|
}
|
2016-05-04 14:43:40 -07:00
|
|
|
|
Dictionary<string, List<RomData>> newMissing = new Dictionary<string, List<RomData>>();
|
2016-05-16 14:28:23 -07:00
|
|
|
|
foreach (string key in midMissing.Roms.Keys)
|
2016-04-28 15:00:55 -07:00
|
|
|
|
{
|
2016-05-16 14:28:23 -07:00
|
|
|
|
List<RomData> templist = RomManipulation.Merge(midMissing.Roms[key]);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
foreach (RomData rom in templist)
|
2016-04-28 15:00:55 -07:00
|
|
|
|
{
|
2016-05-10 21:03:41 -07:00
|
|
|
|
if (rom.Dupe == DupeType.None && rom.System == _currentMissingMerged)
|
2016-04-28 15:00:55 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
if (newMissing.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
newMissing[key].Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
newMissing.Add(key, temp);
|
|
|
|
|
|
}
|
2016-04-28 15:00:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-05-04 14:43:40 -07:00
|
|
|
|
foreach (string key in netNew.Keys)
|
2016-04-28 15:00:55 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
if (newMissing.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
newMissing[key].AddRange(netNew[key]);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
newMissing.Add(key, netNew[key]);
|
|
|
|
|
|
}
|
2016-04-28 15:00:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// Now create the Have dictionary [(currentNewMerged)-(c)]
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Creating and populating Have dictionary");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
|
|
|
|
|
foreach (string key in newMissing.Keys)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
if (midHave.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
midHave[key].AddRange(newMissing[key]);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
midHave.Add(key, newMissing[key]);
|
|
|
|
|
|
}
|
2016-05-03 13:53:06 -07:00
|
|
|
|
}
|
2016-05-16 14:28:23 -07:00
|
|
|
|
foreach (string key in completeDats.Roms.Keys)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
if (midHave.ContainsKey(key))
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-16 14:28:23 -07:00
|
|
|
|
foreach (RomData rom in completeDats.Roms[key])
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
if (rom.System == _currentNewMerged)
|
|
|
|
|
|
{
|
|
|
|
|
|
midHave[key].Add(rom);
|
|
|
|
|
|
}
|
2016-05-03 13:53:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-05-04 14:43:40 -07:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> roms = new List<RomData>();
|
2016-05-16 14:28:23 -07:00
|
|
|
|
foreach (RomData rom in completeDats.Roms[key])
|
2016-05-04 14:43:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (rom.System == _currentNewMerged)
|
|
|
|
|
|
{
|
|
|
|
|
|
roms.Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
midHave.Add(key, roms);
|
|
|
|
|
|
}
|
2016-05-03 13:53:06 -07:00
|
|
|
|
}
|
2016-05-04 14:43:40 -07:00
|
|
|
|
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
|
|
|
|
|
foreach (string key in midHave.Keys)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
List<RomData> templist = RomManipulation.Merge(midHave[key]);
|
|
|
|
|
|
foreach (RomData rom in templist)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-10 21:03:41 -07:00
|
|
|
|
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
if (have.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
have[key].Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
have.Add(key, temp);
|
|
|
|
|
|
}
|
2016-05-03 13:53:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-05-04 14:43:40 -07:00
|
|
|
|
|
|
|
|
|
|
// If we are supposed to replace everything in the output with default values, do so
|
|
|
|
|
|
if (_fake)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Replacing all hashes in Net New with 0-byte values");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
List<string> keys = netNew.Keys.ToList();
|
|
|
|
|
|
foreach (string key in keys)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
List<RomData> roms = netNew[key];
|
|
|
|
|
|
for (int i = 0; i < roms.Count; i++)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
RomData rom = roms[i];
|
2016-05-22 13:15:13 -07:00
|
|
|
|
rom.Size = Constants.SizeZero;
|
|
|
|
|
|
rom.CRC = Constants.CRCZero;
|
|
|
|
|
|
rom.MD5 = Constants.MD5Zero;
|
|
|
|
|
|
rom.SHA1 = Constants.SHA1Zero;
|
2016-05-04 14:43:40 -07:00
|
|
|
|
temp.Add(rom);
|
2016-05-03 13:53:06 -07:00
|
|
|
|
}
|
2016-05-04 14:43:40 -07:00
|
|
|
|
netNew[key] = temp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Replacing all hashes in Unneeded with 0-byte values");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
keys = unneeded.Keys.ToList();
|
|
|
|
|
|
foreach (string key in keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
List<RomData> roms = unneeded[key];
|
|
|
|
|
|
for (int i = 0; i < roms.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
RomData rom = roms[i];
|
2016-05-22 13:15:13 -07:00
|
|
|
|
rom.Size = Constants.SizeZero;
|
|
|
|
|
|
rom.CRC = Constants.CRCZero;
|
|
|
|
|
|
rom.MD5 = Constants.MD5Zero;
|
|
|
|
|
|
rom.SHA1 = Constants.SHA1Zero;
|
2016-05-04 14:43:40 -07:00
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
unneeded[key] = temp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Replacing all hashes in New Missing with 0-byte values");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
keys = newMissing.Keys.ToList();
|
|
|
|
|
|
foreach (string key in keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
List<RomData> roms = newMissing[key];
|
|
|
|
|
|
for (int i = 0; i < roms.Count; i++)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
RomData rom = roms[i];
|
2016-05-22 13:15:13 -07:00
|
|
|
|
rom.Size = Constants.SizeZero;
|
|
|
|
|
|
rom.CRC = Constants.CRCZero;
|
|
|
|
|
|
rom.MD5 = Constants.MD5Zero;
|
|
|
|
|
|
rom.SHA1 = Constants.SHA1Zero;
|
2016-05-03 23:59:32 -07:00
|
|
|
|
temp.Add(rom);
|
2016-05-03 13:53:06 -07:00
|
|
|
|
}
|
2016-05-04 14:43:40 -07:00
|
|
|
|
newMissing[key] = temp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Replacing all hashes in Have with 0-byte values");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
keys = have.Keys.ToList();
|
|
|
|
|
|
foreach (string key in keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
List<RomData> roms = have[key];
|
|
|
|
|
|
for (int i = 0; i < roms.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
RomData rom = roms[i];
|
2016-05-22 13:15:13 -07:00
|
|
|
|
rom.Size = Constants.SizeZero;
|
|
|
|
|
|
rom.CRC = Constants.CRCZero;
|
|
|
|
|
|
rom.MD5 = Constants.MD5Zero;
|
|
|
|
|
|
rom.SHA1 = Constants.SHA1Zero;
|
2016-05-04 14:43:40 -07:00
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
have[key] = temp;
|
2016-05-03 13:53:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-05-04 14:43:40 -07:00
|
|
|
|
|
|
|
|
|
|
// Finally, output all of the files
|
2016-05-15 14:34:06 -07:00
|
|
|
|
DatData netNewData = new DatData
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Net New",
|
|
|
|
|
|
Description = "Net New",
|
|
|
|
|
|
Version = "",
|
|
|
|
|
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
|
|
|
|
Category = "",
|
|
|
|
|
|
Author = "SabreTools",
|
|
|
|
|
|
ForcePacking = ForcePacking.None,
|
|
|
|
|
|
OutputFormat = OutputFormat.Xml,
|
2016-05-16 13:42:21 -07:00
|
|
|
|
MergeRoms = true,
|
|
|
|
|
|
Roms = netNew,
|
2016-05-15 14:34:06 -07:00
|
|
|
|
};
|
|
|
|
|
|
DatData unneededData = new DatData
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Unneeded",
|
|
|
|
|
|
Description = "Unneeded",
|
|
|
|
|
|
Version = "",
|
|
|
|
|
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
|
|
|
|
Category = "",
|
|
|
|
|
|
Author = "SabreTools",
|
|
|
|
|
|
ForcePacking = ForcePacking.None,
|
|
|
|
|
|
OutputFormat = OutputFormat.Xml,
|
2016-05-16 13:42:21 -07:00
|
|
|
|
MergeRoms = true,
|
|
|
|
|
|
Roms = unneeded,
|
2016-05-15 14:34:06 -07:00
|
|
|
|
};
|
|
|
|
|
|
DatData newMissingData = new DatData
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "New Missing",
|
|
|
|
|
|
Description = "New Missing",
|
|
|
|
|
|
Version = "",
|
|
|
|
|
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
|
|
|
|
Category = "",
|
|
|
|
|
|
Author = "SabreTools",
|
|
|
|
|
|
ForcePacking = ForcePacking.None,
|
|
|
|
|
|
OutputFormat = OutputFormat.Xml,
|
2016-05-16 13:42:21 -07:00
|
|
|
|
MergeRoms = true,
|
|
|
|
|
|
Roms = newMissing,
|
2016-05-15 14:34:06 -07:00
|
|
|
|
};
|
|
|
|
|
|
DatData haveData = new DatData
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Have",
|
|
|
|
|
|
Description = "Have",
|
|
|
|
|
|
Version = "",
|
|
|
|
|
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
|
|
|
|
Category = "",
|
|
|
|
|
|
Author = "SabreTools",
|
|
|
|
|
|
ForcePacking = ForcePacking.None,
|
|
|
|
|
|
OutputFormat = OutputFormat.Xml,
|
2016-05-16 13:42:21 -07:00
|
|
|
|
MergeRoms = true,
|
|
|
|
|
|
Roms = have,
|
2016-05-15 14:34:06 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-05-16 21:52:49 -07:00
|
|
|
|
Output.WriteDatfile(netNewData, "", _logger);
|
|
|
|
|
|
Output.WriteDatfile(unneededData, "", _logger);
|
|
|
|
|
|
Output.WriteDatfile(newMissingData, "", _logger);
|
|
|
|
|
|
Output.WriteDatfile(haveData, "", _logger);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
|
|
|
|
|
|
return true;
|
2016-05-03 13:53:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// If we only have the old merged and missing, only generate Have
|
|
|
|
|
|
else if (_currentAllMerged != "" && _currentMissingMerged != "")
|
2016-04-28 15:21:08 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// Now create the Have dictionary [(currentAllMerged)-(currentMissingMerged)]
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Creating and populating Have dictionary");
|
2016-05-21 00:45:56 -07:00
|
|
|
|
DatData midHave = new DatData();
|
2016-05-16 21:52:49 -07:00
|
|
|
|
midHave = RomManipulation.Parse(_currentMissingMerged, 0, 0, midHave, _logger);
|
|
|
|
|
|
midHave = RomManipulation.Parse(_currentAllMerged, 0, 0, midHave, _logger);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
2016-05-16 14:28:23 -07:00
|
|
|
|
foreach (string key in midHave.Roms.Keys)
|
2016-04-28 15:21:08 -07:00
|
|
|
|
{
|
2016-05-16 14:28:23 -07:00
|
|
|
|
List<RomData> templist = RomManipulation.Merge(midHave.Roms[key]);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
foreach (RomData rom in templist)
|
2016-04-28 15:21:08 -07:00
|
|
|
|
{
|
2016-05-10 21:03:41 -07:00
|
|
|
|
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
|
2016-05-04 14:43:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (have.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
have[key].Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
have.Add(key, temp);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-04-28 15:21:08 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-04-28 23:15:32 -07:00
|
|
|
|
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// If we are supposed to replace everything in the output with default values, do so
|
|
|
|
|
|
if (_fake)
|
2016-04-28 15:21:08 -07:00
|
|
|
|
{
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Replacing all hashes in Have with 0-byte values");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
List<string> keys = have.Keys.ToList();
|
|
|
|
|
|
foreach (string key in keys)
|
2016-04-28 15:21:08 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
List<RomData> roms = have[key];
|
|
|
|
|
|
for (int i = 0; i < roms.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
RomData rom = roms[i];
|
2016-05-22 13:15:13 -07:00
|
|
|
|
rom.Size = Constants.SizeZero;
|
|
|
|
|
|
rom.CRC = Constants.CRCZero;
|
|
|
|
|
|
rom.MD5 = Constants.MD5Zero;
|
|
|
|
|
|
rom.SHA1 = Constants.SHA1Zero;
|
2016-05-04 14:43:40 -07:00
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
have[key] = temp;
|
2016-04-28 15:21:08 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-04-28 23:15:32 -07:00
|
|
|
|
|
2016-05-15 14:34:06 -07:00
|
|
|
|
DatData haveData = new DatData
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Have",
|
|
|
|
|
|
Description = "Have",
|
|
|
|
|
|
Version = "",
|
|
|
|
|
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
|
|
|
|
Category = "",
|
|
|
|
|
|
Author = "SabreTools",
|
|
|
|
|
|
ForcePacking = ForcePacking.None,
|
|
|
|
|
|
OutputFormat = OutputFormat.Xml,
|
2016-05-16 13:42:21 -07:00
|
|
|
|
MergeRoms = true,
|
|
|
|
|
|
Roms = have,
|
2016-05-15 14:34:06 -07:00
|
|
|
|
};
|
2016-05-16 21:52:49 -07:00
|
|
|
|
Output.WriteDatfile(haveData, "", _logger);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we only have the new merged and missing, only generate Have
|
|
|
|
|
|
else if (_currentNewMerged != "" && _currentMissingMerged != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
// Now create the Have dictionary [(currentNewMerged)-(currentMissingMerged)]
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Creating and populating Have dictionary");
|
2016-05-21 00:45:56 -07:00
|
|
|
|
DatData midHave = new DatData();
|
2016-05-16 21:52:49 -07:00
|
|
|
|
midHave = RomManipulation.Parse(_currentMissingMerged, 0, 0, midHave, _logger);
|
|
|
|
|
|
midHave = RomManipulation.Parse(_currentNewMerged, 0, 0, midHave, _logger);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
2016-05-16 14:28:23 -07:00
|
|
|
|
foreach (string key in midHave.Roms.Keys)
|
2016-04-28 15:21:08 -07:00
|
|
|
|
{
|
2016-05-16 14:28:23 -07:00
|
|
|
|
List<RomData> templist = RomManipulation.Merge(midHave.Roms[key]);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
foreach (RomData rom in templist)
|
2016-04-28 15:21:08 -07:00
|
|
|
|
{
|
2016-05-10 21:03:41 -07:00
|
|
|
|
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
2016-05-04 14:43:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (have.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
have[key].Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
have.Add(key, temp);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-04-28 15:21:08 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-05-03 13:53:06 -07:00
|
|
|
|
|
2016-05-04 14:43:40 -07:00
|
|
|
|
// If we are supposed to replace everything in the output with default values, do so
|
|
|
|
|
|
if (_fake)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-10 15:41:33 -07:00
|
|
|
|
_logger.User("Replacing all hashes in Have with 0-byte values");
|
2016-05-04 14:43:40 -07:00
|
|
|
|
List<string> keys = have.Keys.ToList();
|
|
|
|
|
|
foreach (string key in keys)
|
2016-05-03 13:53:06 -07:00
|
|
|
|
{
|
2016-05-04 14:43:40 -07:00
|
|
|
|
List<RomData> temp = new List<RomData>();
|
|
|
|
|
|
List<RomData> roms = have[key];
|
|
|
|
|
|
for (int i = 0; i < roms.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
RomData rom = roms[i];
|
2016-05-22 13:15:13 -07:00
|
|
|
|
rom.Size = Constants.SizeZero;
|
|
|
|
|
|
rom.CRC = Constants.CRCZero;
|
|
|
|
|
|
rom.MD5 = Constants.MD5Zero;
|
|
|
|
|
|
rom.SHA1 = Constants.SHA1Zero;
|
2016-05-04 14:43:40 -07:00
|
|
|
|
temp.Add(rom);
|
|
|
|
|
|
}
|
|
|
|
|
|
have[key] = temp;
|
2016-05-03 13:53:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-04-28 15:21:08 -07:00
|
|
|
|
|
2016-05-15 14:34:06 -07:00
|
|
|
|
DatData haveData = new DatData
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Have",
|
|
|
|
|
|
Description = "Have",
|
|
|
|
|
|
Version = "",
|
|
|
|
|
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
|
|
|
|
Category = "",
|
|
|
|
|
|
Author = "SabreTools",
|
|
|
|
|
|
ForcePacking = ForcePacking.None,
|
|
|
|
|
|
OutputFormat = OutputFormat.Xml,
|
2016-05-16 13:42:21 -07:00
|
|
|
|
MergeRoms = true,
|
|
|
|
|
|
Roms = have,
|
2016-05-15 14:34:06 -07:00
|
|
|
|
};
|
2016-05-16 21:52:49 -07:00
|
|
|
|
Output.WriteDatfile(haveData, "", _logger);
|
2016-05-04 14:43:40 -07:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2016-04-28 15:12:49 -07:00
|
|
|
|
|
2016-05-04 14:43:40 -07:00
|
|
|
|
return false;
|
2016-04-28 14:08:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|