From 06588752adb57b1792c3e290e2affeb89455e1bd Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 25 Dec 2021 21:37:19 -0800 Subject: [PATCH] Allow for better matching of multi track discs --- CHANGELIST.md | 1 + MPF.Library/InfoTool.cs | 100 ++++++++++++++++++++++++++-------------- 2 files changed, 66 insertions(+), 35 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 18f4ef18..3c395ab9 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -45,6 +45,7 @@ - Fix missing ISN usages - Fix ISN string - Validate track count when matching Redump +- Allow for better matching of multi track discs ### 2.1 (2021-07-22) - Enum, no more diff --git a/MPF.Library/InfoTool.cs b/MPF.Library/InfoTool.cs index 2df7bd75..64c01778 100644 --- a/MPF.Library/InfoTool.cs +++ b/MPF.Library/InfoTool.cs @@ -93,41 +93,7 @@ namespace MPF.Library // Get a list of matching IDs for each line in the DAT if (!string.IsNullOrEmpty(info.TracksAndWriteOffsets.ClrMameProData) && options.HasRedumpLogin) - { - // Set the current dumper based on username - info.DumpersAndStatus.Dumpers = new string[] { options.RedumpUsername }; - - info.MatchedIDs = new List(); - using (RedumpWebClient wc = new RedumpWebClient()) - { - // Login to Redump - bool? loggedIn = wc.Login(options.RedumpUsername, options.RedumpPassword); - if (loggedIn == null) - { - resultProgress?.Report(Result.Failure("There was an unknown error connecting to Redump")); - } - else if (loggedIn == true) - { - // Loop through all of the hashdata to find matching IDs - resultProgress?.Report(Result.Success("Finding disc matches on Redump...")); - string[] splitData = info.TracksAndWriteOffsets.ClrMameProData.Split('\n'); - foreach (string hashData in splitData) - { - ValidateSingleTrack(wc, info, hashData, resultProgress); - } - - resultProgress?.Report(Result.Success("Match finding complete! " + (info.MatchedIDs.Count > 0 ? "Matched IDs: " + string.Join(",", info.MatchedIDs) : "No matches found"))); - - // If we have exactly 1 ID and the track count matches, we can grab a bunch of info from it - if (info.MatchedIDs.Count == 1 && ValidateTrackCount(wc, info.MatchedIDs[0], splitData.Length)) - { - resultProgress?.Report(Result.Success($"Filling fields from existing ID {info.MatchedIDs[0]}...")); - FillFromId(wc, info, info.MatchedIDs[0]); - resultProgress?.Report(Result.Success("Information filling complete!")); - } - } - } - } + FillFromRedump(options, info, resultProgress); // If we have both ClrMamePro and Size and Checksums data, remove the ClrMamePro if (!string.IsNullOrWhiteSpace(info.SizeAndChecksums.CRC32)) @@ -439,6 +405,7 @@ namespace MPF.Library return info; } + /// /// Ensures that all required output files have been created /// @@ -1231,6 +1198,69 @@ namespace MPF.Library } } + /// + /// Fill in a SubmissionInfo object from Redump, if possible + /// + /// Options object representing user-defined options + /// Existing SubmissionInfo object to fill + /// Optional result progress callback + private static void FillFromRedump(Options options, SubmissionInfo info, IProgress resultProgress = null) + { + // Set the current dumper based on username + info.DumpersAndStatus.Dumpers = new string[] { options.RedumpUsername }; + info.MatchedIDs = new List(); + + using (RedumpWebClient wc = new RedumpWebClient()) + { + // Login to Redump + bool? loggedIn = wc.Login(options.RedumpUsername, options.RedumpPassword); + if (loggedIn == null) + { + resultProgress?.Report(Result.Failure("There was an unknown error connecting to Redump")); + return; + } + else if (loggedIn == false) + { + // Don't log the as a failure or error + return; + } + + // Loop through all of the hashdata to find matching IDs + resultProgress?.Report(Result.Success("Finding disc matches on Redump...")); + string[] splitData = info.TracksAndWriteOffsets.ClrMameProData.Split('\n'); + foreach (string hashData in splitData) + { + ValidateSingleTrack(wc, info, hashData, resultProgress); + } + + resultProgress?.Report(Result.Success("Match finding complete! " + (info.MatchedIDs.Count > 0 + ? "Matched IDs: " + string.Join(",", info.MatchedIDs) + : "No matches found"))); + + // Exit early if there are no matched IDs + if (info.MatchedIDs.Count == 0) + return; + + // Find the first matched ID where the track count matches, we can grab a bunch of info from it + int totalMatchedIDsCount = info.MatchedIDs.Count; + for (int i = 0; i < totalMatchedIDsCount; i++) + { + // Skip if the track count doesn't match + if (!ValidateTrackCount(wc, info.MatchedIDs[i], splitData.Length)) + continue; + + // Fill in the fields from the existing ID + resultProgress?.Report(Result.Success($"Filling fields from existing ID {info.MatchedIDs[i]}...")); + FillFromId(wc, info, info.MatchedIDs[0]); + resultProgress?.Report(Result.Success("Information filling complete!")); + + // Set the matched IDs to just the current + info.MatchedIDs = new List { info.MatchedIDs[i] }; + break; + } + } + } + /// /// Process a comment block and replace with internal identifiers ///