From 382f74afaa4bfdbb20ec27817c2e8ab5c07831d0 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 10 May 2016 20:55:51 -0700 Subject: [PATCH] An attempt to make diffing work the way I think it should Basically, if a rom is a duplicate, it can be a duplicate within a system or source or across system or source, and by hash alone or by all data matching. The four combinations make an enum now and the diff function is the only one that uses them right now. If we're in dedup mode, we want to check hashes only in diff. Otherwise, we want to check against ones that match all information. This needs field testing. --- DATabase/MergeDiff.cs | 25 +++++++++++++++++++++---- SabreHelper/Enums.cs | 12 ++++++++++++ SabreHelper/RomManipulation.cs | 25 ++++++++++++++++++++++++- SabreHelper/Structs.cs | 2 +- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/DATabase/MergeDiff.cs b/DATabase/MergeDiff.cs index e087da81..57ce3eba 100644 --- a/DATabase/MergeDiff.cs +++ b/DATabase/MergeDiff.cs @@ -100,23 +100,40 @@ namespace SabreTools } // Create a dictionary of all ROMs from the input DATs + int i = 0; Dictionary> dict = new Dictionary>(); foreach (string input in _inputs) { _logger.User("Adding DAT: " + input); - dict = RomManipulation.ParseDict(input, 0, 0, dict, _logger); + dict = RomManipulation.ParseDict(input, i, 0, dict, _logger); + i++; } // Modify the Dictionary if necessary and output the results if (_diff || _ad) { - // Get all entries that have only one item in their list + // Get all entries that don't have External dupes Dictionary> diffed = new Dictionary>(); foreach (string key in dict.Keys) { - if (dict[key].Count == 1) + List temp = dict[key]; + temp = RomManipulation.Merge(temp); + + foreach (RomData rom in temp) { - diffed.Add(key, dict[key]); + if ((_dedup && rom.Dupe != DupeType.InternalHash) || (!_dedup && rom.Dupe != DupeType.InternalAll)) + { + if (diffed.ContainsKey(key)) + { + diffed[key].Add(rom); + } + else + { + List tl = new List(); + tl.Add(rom); + diffed.Add(key, tl); + } + } } } diff --git a/SabreHelper/Enums.cs b/SabreHelper/Enums.cs index d3520de4..e2345949 100644 --- a/SabreHelper/Enums.cs +++ b/SabreHelper/Enums.cs @@ -50,4 +50,16 @@ namespace SabreTools.Helper WARNING, ERROR, } + + /// + /// Determines which type of duplicate a file is + /// + public enum DupeType + { + None = 0, + InternalHash, + ExternalHash, + InternalAll, + ExternalAll, + } } diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index 142ed412..58b4affc 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -628,7 +628,30 @@ namespace SabreTools.Helper last.CRC = (last.CRC == "" && rom.CRC != "" ? rom.CRC : last.CRC); last.MD5 = (last.MD5 == "" && rom.MD5 != "" ? rom.MD5 : last.MD5); last.SHA1 = (last.SHA1 == "" && rom.SHA1 != "" ? rom.SHA1 : last.SHA1); - last.Dupe = true; + + // If the duplicate is in the same system and dupe is not already set to External + if ((last.SystemID == rom.SystemID || last.SourceID == rom.SourceID) && last.Dupe != DupeType.ExternalHash) + { + if (last.Game == rom.Game && last.Name == rom.Name) + { + last.Dupe = DupeType.InternalAll; + } + else + { + last.Dupe = DupeType.InternalHash; + } + } + else + { + if (last.Game == rom.Game && last.Name == rom.Name) + { + last.Dupe = DupeType.ExternalAll; + } + else + { + last.Dupe = DupeType.ExternalHash; + } + } outroms.RemoveAt(outroms.Count - 1); outroms.Insert(outroms.Count, last); diff --git a/SabreHelper/Structs.cs b/SabreHelper/Structs.cs index 7e2647bf..e77a77f1 100644 --- a/SabreHelper/Structs.cs +++ b/SabreHelper/Structs.cs @@ -18,6 +18,6 @@ public string CRC; public string MD5; public string SHA1; - public bool Dupe; + public DupeType Dupe; } }