From 42e1ef45b4467cc8849c06fd920a8fbb3bfbcd94 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sun, 16 Oct 2022 23:15:09 -0700 Subject: [PATCH] Add multi-language helper for filter --- CHANGELIST.md | 1 + MPF.Library/InfoTool.cs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/CHANGELIST.md b/CHANGELIST.md index f5d082c3..62250869 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -145,6 +145,7 @@ - Add specialized CDS/SafeDisc filter - Add unused article formatter - Add language filtering to formatter +- Add multi-language helper for filter ### 2.3 (2022-02-05) - Start overhauling Redump information pulling, again diff --git a/MPF.Library/InfoTool.cs b/MPF.Library/InfoTool.cs index 0f324742..28f1e8ba 100644 --- a/MPF.Library/InfoTool.cs +++ b/MPF.Library/InfoTool.cs @@ -1180,6 +1180,35 @@ namespace MPF.Library #region Normalization + /// + /// Adjust a disc title so that it will be processed correctly by Redump + /// + /// Existing title to potentially reformat + /// Array of languages to use for assuming articles + /// The reformatted title + public static string NormalizeDiscTitle(string title, Language[] languages) + { + // If we have no set languages, then assume English + if (languages == null || languages.Length == 0) + languages = new Language[] { Language.English }; + + // Loop through all of the given languages + foreach (var language in languages) + { + // If the new title is different, assume it was normalized and return it + string newTitle = NormalizeDiscTitle(title, language); + if (newTitle == title) + return newTitle; + } + + // If we didn't already try English, try it now + if (!languages.Contains(Language.English)) + return NormalizeDiscTitle(title, Language.English); + + // If all fails, then the title didn't need normalization + return title; + } + /// /// Adjust a disc title so that it will be processed correctly by Redump ///