mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make all-diff standard for diff
This commit is contained in:
@@ -51,7 +51,6 @@ namespace SabreTools
|
||||
|
||||
// Set all default values
|
||||
bool help = false,
|
||||
ad = false,
|
||||
add = false,
|
||||
bare = false,
|
||||
convertMiss = false,
|
||||
@@ -109,10 +108,6 @@ namespace SabreTools
|
||||
case "--add":
|
||||
add = true;
|
||||
break;
|
||||
case "-ad":
|
||||
case "--all-diff":
|
||||
ad = true;
|
||||
break;
|
||||
case "-b":
|
||||
case "--bare":
|
||||
bare = true;
|
||||
@@ -432,7 +427,7 @@ namespace SabreTools
|
||||
// Merge, diff, and dedupe at least 2 DATs
|
||||
else if (merge || diff)
|
||||
{
|
||||
InitMergeDiff(inputs, name, desc, cat, version, author, ad, diff, dedup, bare, forceunpack, old);
|
||||
InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old);
|
||||
}
|
||||
|
||||
logger.Close();
|
||||
@@ -859,7 +854,7 @@ Make a selection:
|
||||
private static void MergeDiffMenu()
|
||||
{
|
||||
string selection = "", input = "", name = "", desc = "", cat = "", version = "", author = "";
|
||||
bool ad = false, dedup = false, diff = false, bare = false, forceunpack = false, old = false;
|
||||
bool dedup = false, diff = false, bare = false, forceunpack = false, old = false;
|
||||
while (selection.ToLowerInvariant() != "b")
|
||||
{
|
||||
Console.Clear();
|
||||
@@ -874,13 +869,12 @@ Make a selection:
|
||||
4) Category" + (cat != "" ? ":\t" + cat : "") + @"
|
||||
5) Version" + (version != "" ? ":\t" + version : "") + @"
|
||||
6) Author" + (author != "" ? ":\t" + author : "") + @"
|
||||
7) " + (ad ? "Only output normal diff" : "Output all diff variants (2 files only)") + @"
|
||||
8) " + (dedup ? "Don't dedup files in output" : "Dedup files in output") + @"
|
||||
9) " + (diff ? "Only merge the input files" : "Diff the input files") + @"
|
||||
10) " + (bare ? "Don't append the date to the name" : "Append the date to the name") + @"
|
||||
11) " + (forceunpack ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @"
|
||||
12) " + (old ? "Enable XML output" : "Enable ClrMamePro output") + @"
|
||||
13) Merge the DATs
|
||||
7) " + (dedup ? "Don't dedup files in output" : "Dedup files in output") + @"
|
||||
8) " + (diff ? "Only merge the input files" : "Diff the input files") + @"
|
||||
9) " + (bare ? "Don't append the date to the name" : "Append the date to the name") + @"
|
||||
10) " + (forceunpack ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @"
|
||||
11) " + (old ? "Enable XML output" : "Enable ClrMamePro output") + @"
|
||||
12) Merge the DATs
|
||||
B) Go back to the previous menu
|
||||
");
|
||||
Console.Write("Enter selection: ");
|
||||
@@ -918,31 +912,28 @@ Make a selection:
|
||||
author = Console.ReadLine();
|
||||
break;
|
||||
case "7":
|
||||
ad = !ad;
|
||||
break;
|
||||
case "8":
|
||||
dedup = !dedup;
|
||||
break;
|
||||
case "9":
|
||||
case "8":
|
||||
diff = !diff;
|
||||
break;
|
||||
case "10":
|
||||
case "9":
|
||||
bare = !bare;
|
||||
break;
|
||||
case "11":
|
||||
case "10":
|
||||
forceunpack = !forceunpack;
|
||||
break;
|
||||
case "12":
|
||||
case "11":
|
||||
old = !old;
|
||||
break;
|
||||
case "13":
|
||||
case "12":
|
||||
Console.Clear();
|
||||
List<string> inputs = new List<string>(input.Split(';'));
|
||||
InitMergeDiff(inputs, name, desc, cat, version, author, ad, diff, dedup, bare, forceunpack, old);
|
||||
InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old);
|
||||
Console.Write("\nPress any key to continue...");
|
||||
Console.ReadKey();
|
||||
selection = ""; input = ""; name = ""; desc = ""; cat = ""; version = ""; author = "";
|
||||
ad = false; dedup = false; diff = false; bare = false; forceunpack = false; old = false;
|
||||
dedup = false; diff = false; bare = false; forceunpack = false; old = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1380,7 +1371,7 @@ Make a selection:
|
||||
/// <param name="bare">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>
|
||||
private static void InitMergeDiff(List<string> inputs, string name, string desc, string cat, string version, string author, bool ad, bool diff, bool dedup, bool bare, bool forceunpack, bool old)
|
||||
private static void InitMergeDiff(List<string> inputs, string name, string desc, string cat, string version, string author, bool diff, bool dedup, bool bare, bool forceunpack, bool old)
|
||||
{
|
||||
// Make sure there are no folders in inputs
|
||||
List<string> newInputs = new List<string>();
|
||||
@@ -1399,7 +1390,7 @@ Make a selection:
|
||||
}
|
||||
}
|
||||
|
||||
MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, ad, diff, dedup, bare, forceunpack, old, logger);
|
||||
MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, logger);
|
||||
md.Process();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace SabreTools
|
||||
private List<String> _inputs;
|
||||
|
||||
// User specified flags
|
||||
private bool _ad;
|
||||
private bool _diff;
|
||||
private bool _dedup;
|
||||
private bool _bare;
|
||||
@@ -47,7 +46,7 @@ namespace SabreTools
|
||||
/// <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 ad, bool diff, bool dedup, bool bare, bool forceunpack, bool old, Logger logger)
|
||||
bool diff, bool dedup, bool bare, bool forceunpack, bool old, Logger logger)
|
||||
{
|
||||
_inputs = inputs;
|
||||
_name = name;
|
||||
@@ -55,7 +54,6 @@ namespace SabreTools
|
||||
_cat = cat;
|
||||
_version = version;
|
||||
_author = author;
|
||||
_ad = ad;
|
||||
_diff = diff;
|
||||
_dedup = dedup;
|
||||
_bare = bare;
|
||||
@@ -71,9 +69,9 @@ namespace SabreTools
|
||||
public bool Process()
|
||||
{
|
||||
// Check if there are enough inputs
|
||||
if ((!_ad && _inputs.Count < 1) || (_ad && _inputs.Count < 2))
|
||||
if (_inputs.Count < 1)
|
||||
{
|
||||
_logger.Warning("At least " + (_ad ? "2" : "1") + " input(s) are required!");
|
||||
_logger.Warning("At least 1 input is required!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -110,7 +108,7 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// Modify the Dictionary if necessary and output the results
|
||||
if (_diff || _ad)
|
||||
if (_diff)
|
||||
{
|
||||
// Get all entries that don't have External dupes
|
||||
Dictionary<string, List<RomData>> diffed = new Dictionary<string, List<RomData>>();
|
||||
@@ -121,7 +119,7 @@ namespace SabreTools
|
||||
|
||||
foreach (RomData rom in temp)
|
||||
{
|
||||
if ((_dedup && rom.Dupe != DupeType.InternalHash) || (!_dedup && rom.Dupe != DupeType.InternalAll))
|
||||
if ((_dedup && rom.Dupe != DupeType.ExternalHash) || (!_dedup && rom.Dupe != DupeType.ExternalAll))
|
||||
{
|
||||
if (diffed.ContainsKey(key))
|
||||
{
|
||||
@@ -137,44 +135,68 @@ namespace SabreTools
|
||||
}
|
||||
}
|
||||
|
||||
// Output the difflist only if we're in diff mode and not AB
|
||||
if (_diff)
|
||||
{
|
||||
Output.WriteToDatFromDict(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", diffed, _logger);
|
||||
}
|
||||
// Output the difflist (a-b)+(b-a) diff
|
||||
Output.WriteToDatFromDict(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", diffed, _logger);
|
||||
|
||||
// For the AB mode, get all required dictionaries and output with a new name
|
||||
if (_ad)
|
||||
// For the AB mode-style diffs, get all required dictionaries and output with a new name
|
||||
// Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System"
|
||||
string post = "";
|
||||
int j = 0;
|
||||
foreach (string filename in _inputs)
|
||||
{
|
||||
// Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System"
|
||||
string post = "";
|
||||
foreach (string filename in _inputs)
|
||||
Dictionary<string, List<RomData>> sysDict = new Dictionary<string, List<RomData>>();
|
||||
foreach (string key in diffed.Keys)
|
||||
{
|
||||
Dictionary<string, List<RomData>> sysDict = new Dictionary<string, List<RomData>>();
|
||||
foreach (string key in diffed.Keys)
|
||||
foreach (RomData rom in diffed[key])
|
||||
{
|
||||
if (diffed[key][0].System == filename)
|
||||
if (rom.SystemID == j)
|
||||
{
|
||||
sysDict.Add(key, diffed[key]);
|
||||
if (sysDict.ContainsKey(key))
|
||||
{
|
||||
sysDict[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
sysDict.Add(key, tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post = " (" + Path.GetFileNameWithoutExtension(filename) + ")";
|
||||
Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", sysDict, _logger);
|
||||
}
|
||||
|
||||
// Then loop through all that have a count > 1 for the AB merged DAT
|
||||
Dictionary<string, List<RomData>> duplicates = new Dictionary<string, List<RomData>>();
|
||||
post = " (dupes)";
|
||||
foreach (string key in dict.Keys)
|
||||
post = " (" + Path.GetFileNameWithoutExtension(filename) + ")";
|
||||
Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", sysDict, _logger);
|
||||
|
||||
j++;
|
||||
}
|
||||
|
||||
// Get all entries that have External dupes
|
||||
Dictionary<string, List<RomData>> duplicates = new Dictionary<string, List<RomData>>();
|
||||
post = " (dupes)";
|
||||
foreach (string key in dict.Keys)
|
||||
{
|
||||
List<RomData> temp = dict[key];
|
||||
temp = RomManipulation.Merge(temp);
|
||||
|
||||
foreach (RomData rom in temp)
|
||||
{
|
||||
if (dict[key].Count > 1)
|
||||
if ((_dedup && rom.Dupe == DupeType.ExternalHash) || (!_dedup && rom.Dupe == DupeType.ExternalAll))
|
||||
{
|
||||
duplicates.Add(key, dict[key]);
|
||||
if (duplicates.ContainsKey(key))
|
||||
{
|
||||
duplicates[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
duplicates.Add(key, tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", duplicates, _logger);
|
||||
}
|
||||
Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", duplicates, _logger);
|
||||
}
|
||||
// Output all entries with user-defined merge
|
||||
else
|
||||
|
||||
@@ -117,8 +117,7 @@ Options:
|
||||
-lso, --list-sources List all sources (id <= name)
|
||||
-lsy, --list-systems List all systems (id <= name)
|
||||
-m, --merge Merge one or more DATs
|
||||
-ad, --all-diff Enable output of all diff variants
|
||||
-di, --diff Switch to diffdat mode (merge flag not required)
|
||||
-di, --diff Output all diffdats (merge flag not required)
|
||||
-dd, --dedup Enable deduping in the created DAT
|
||||
-b, --bare Don't include date in file name
|
||||
-u, --unzip Force unzipping in created DAT
|
||||
|
||||
Reference in New Issue
Block a user