mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make inputs explicit for OfflineMerge
This commit is contained in:
@@ -36,7 +36,7 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
_currentAllMerged = currentAllMerged.Replace("\"", "");
|
_currentAllMerged = currentAllMerged.Replace("\"", "");
|
||||||
_currentMissingMerged = currentMissingMerged.Replace("\"", "");
|
_currentMissingMerged = currentMissingMerged.Replace("\"", "");
|
||||||
_currentNewMerged = currentNewMerged;
|
_currentNewMerged = currentNewMerged.Replace("\"", "");
|
||||||
_fake = fake;
|
_fake = fake;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
@@ -83,48 +83,18 @@ namespace SabreTools
|
|||||||
fake = true;
|
fake = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (File.Exists(arg.Replace("\"", "")))
|
string temparg = arg.Replace("\"", "");
|
||||||
|
if (temparg.StartsWith("com="))
|
||||||
{
|
{
|
||||||
logger.Log("File found: " + arg);
|
currentAllMerged = temparg.Split('=')[1];
|
||||||
if (currentAllMerged == "")
|
|
||||||
{
|
|
||||||
currentAllMerged = arg.Replace("\"", "");
|
|
||||||
}
|
}
|
||||||
else if (currentMissingMerged == "")
|
else if (temparg.StartsWith("fix="))
|
||||||
{
|
{
|
||||||
currentMissingMerged = arg.Replace("\"", "");
|
currentMissingMerged = temparg.Split('=')[1];
|
||||||
}
|
}
|
||||||
else if (currentNewMerged == "")
|
else if (temparg.StartsWith("new="))
|
||||||
{
|
{
|
||||||
currentNewMerged = arg.Replace("\"", "");
|
currentNewMerged = temparg.Split('=')[1];
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.Warning("Only 3 input files are required; ignoring " + arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Directory.Exists(arg.Replace("\"", "")))
|
|
||||||
{
|
|
||||||
logger.Log("Directory found: " + arg);
|
|
||||||
foreach (string file in Directory.GetFiles(arg.Replace("\"", ""), "*", SearchOption.AllDirectories))
|
|
||||||
{
|
|
||||||
if (currentAllMerged == "")
|
|
||||||
{
|
|
||||||
currentAllMerged = file.Replace("\"", "");
|
|
||||||
}
|
|
||||||
else if (currentMissingMerged == "")
|
|
||||||
{
|
|
||||||
currentMissingMerged = file.Replace("\"", "");
|
|
||||||
}
|
|
||||||
else if (currentNewMerged == "")
|
|
||||||
{
|
|
||||||
currentNewMerged = file.Replace("\"", "");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.Warning("Only 3 input files are required; ignoring " + arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -138,8 +108,8 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If help is set or any of the inputs are empty, show help
|
// If help is set or all of the inputs are empty, show help
|
||||||
if (help || currentAllMerged == "" || currentMissingMerged == "" || currentNewMerged == "")
|
if (help || (currentAllMerged == "" && currentMissingMerged == "" && currentNewMerged == ""))
|
||||||
{
|
{
|
||||||
Build.Help();
|
Build.Help();
|
||||||
logger.Close();
|
logger.Close();
|
||||||
@@ -148,18 +118,37 @@ namespace SabreTools
|
|||||||
|
|
||||||
// Otherwise, run the program
|
// Otherwise, run the program
|
||||||
OfflineMerge om = new OfflineMerge(currentAllMerged, currentMissingMerged, currentNewMerged, fake, logger);
|
OfflineMerge om = new OfflineMerge(currentAllMerged, currentMissingMerged, currentNewMerged, fake, logger);
|
||||||
om.Process();
|
bool success = om.Process();
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
logger.Warning("At least one complete DAT and the fixdat is needed to run!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Process the supplied inputs and create the three required outputs:
|
/// Process the supplied inputs and create the four outputs
|
||||||
/// (a) Net New - (currentNewMerged)-(currentAllMerged)
|
|
||||||
/// (b) Unneeded - (currentAllMerged)-(currentNewMerged)
|
|
||||||
/// (c) New Missing - (a)+(currentMissingMerged-(b))
|
|
||||||
/// (d) Have - (currentNewMerged)-(c)
|
|
||||||
/// </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()
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine(_currentAllMerged + " " + _currentMissingMerged + " " + _currentNewMerged);
|
||||||
|
|
||||||
|
// If we have all three DATs, then generate everything
|
||||||
|
if (_currentAllMerged != "" && _currentMissingMerged != "" && _currentNewMerged != "")
|
||||||
{
|
{
|
||||||
// First get the combination Dictionary of currentAllMerged and currentNewMerged
|
// First get the combination Dictionary of currentAllMerged and currentNewMerged
|
||||||
_logger.Log("Adding Current and New Merged DATs to the dictionary");
|
_logger.Log("Adding Current and New Merged DATs to the dictionary");
|
||||||
@@ -408,5 +397,122 @@ namespace SabreTools
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we only have the old merged and missing, only generate Have
|
||||||
|
else if (_currentAllMerged != "" && _currentMissingMerged != "")
|
||||||
|
{
|
||||||
|
// Now create the Have dictionary [(currentAllMerged)-(currentMissingMerged)]
|
||||||
|
_logger.Log("Creating and populating Have dictionary");
|
||||||
|
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
||||||
|
midHave = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midHave, _logger);
|
||||||
|
midHave = RomManipulation.ParseDict(_currentAllMerged, 0, 0, midHave, _logger);
|
||||||
|
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
||||||
|
foreach (string key in midHave.Keys)
|
||||||
|
{
|
||||||
|
List<RomData> templist = RomManipulation.Merge(midHave[key]);
|
||||||
|
foreach (RomData rom in templist)
|
||||||
|
{
|
||||||
|
if (!rom.Dupe && rom.System == _currentAllMerged)
|
||||||
|
{
|
||||||
|
if (have.ContainsKey(key))
|
||||||
|
{
|
||||||
|
have[key].Add(rom);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(rom);
|
||||||
|
have.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we are supposed to replace everything in the output with default values, do so
|
||||||
|
if (_fake)
|
||||||
|
{
|
||||||
|
_logger.Log("Replacing all hashes in Have with 0-byte values");
|
||||||
|
List<string> 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];
|
||||||
|
rom.Size = sizezero;
|
||||||
|
rom.CRC = crczero;
|
||||||
|
rom.MD5 = md5zero;
|
||||||
|
rom.SHA1 = sha1zero;
|
||||||
|
temp.Add(rom);
|
||||||
|
}
|
||||||
|
have[key] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Output.WriteToDatFromDict("Have", "Have", "", DateTime.Now.ToString("yyyy-MM-dd"), "", "SabreTools", false, false, true, "", have, _logger);
|
||||||
|
|
||||||
|
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)]
|
||||||
|
_logger.Log("Creating and populating Have dictionary");
|
||||||
|
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
||||||
|
midHave = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midHave, _logger);
|
||||||
|
midHave = RomManipulation.ParseDict(_currentNewMerged, 0, 0, midHave, _logger);
|
||||||
|
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
||||||
|
foreach (string key in midHave.Keys)
|
||||||
|
{
|
||||||
|
List<RomData> templist = RomManipulation.Merge(midHave[key]);
|
||||||
|
foreach (RomData rom in templist)
|
||||||
|
{
|
||||||
|
if (!rom.Dupe && rom.System == _currentNewMerged)
|
||||||
|
{
|
||||||
|
if (have.ContainsKey(key))
|
||||||
|
{
|
||||||
|
have[key].Add(rom);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(rom);
|
||||||
|
have.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we are supposed to replace everything in the output with default values, do so
|
||||||
|
if (_fake)
|
||||||
|
{
|
||||||
|
_logger.Log("Replacing all hashes in Have with 0-byte values");
|
||||||
|
List<string> 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];
|
||||||
|
rom.Size = sizezero;
|
||||||
|
rom.CRC = crczero;
|
||||||
|
rom.MD5 = md5zero;
|
||||||
|
rom.SHA1 = sha1zero;
|
||||||
|
temp.Add(rom);
|
||||||
|
}
|
||||||
|
have[key] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Output.WriteToDatFromDict("Have", "Have", "", DateTime.Now.ToString("yyyy-MM-dd"), "", "SabreTools", false, false, true, "", have, _logger);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,17 +174,23 @@ Options:
|
|||||||
case "OfflineMerge":
|
case "OfflineMerge":
|
||||||
Console.WriteLine(@"OfflineMerge - Update DATS for offline arrays
|
Console.WriteLine(@"OfflineMerge - Update DATS for offline arrays
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
Usage: OfflineMerge [options] [Complete] [Missing] [NewComplete]
|
Usage: OfflineMerge [options] [inputs]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, -?, --help Show this help dialog
|
-h, -?, --help Show this help dialog
|
||||||
-f, --fake Replace all hashes and sizes by the default
|
-f, --fake Replace all hashes and sizes by the default
|
||||||
|
|
||||||
|
Inputs:
|
||||||
|
com= Complete current DAT
|
||||||
|
fix= Complete current Missing
|
||||||
|
new= New Complete DAT
|
||||||
|
|
||||||
This program will output the following DATs:
|
This program will output the following DATs:
|
||||||
(a) Net New - (NewComplete)-(Complete)
|
(a) Net New - (NewComplete)-(Complete)
|
||||||
(b) Unneeded - (Complete)-(NewComplete)
|
(b) Unneeded - (Complete)-(NewComplete)
|
||||||
(c) New Missing - (Net New)+(Missing-(Unneeded))
|
(c) New Missing - (Net New)+(Missing-(Unneeded))
|
||||||
(d) Have - (NewComplete)-(New Missing)");
|
(d) Have - (NewComplete)-(New Missing)
|
||||||
|
OR (Complete or NewComplete)-(Missing) if one is missing");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.Write("This is the default help output");
|
Console.Write("This is the default help output");
|
||||||
|
|||||||
Reference in New Issue
Block a user