diff --git a/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanLoader.cs b/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanLoader.cs index c03dcf4a..764b79c0 100644 --- a/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanLoader.cs +++ b/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanLoader.cs @@ -15,7 +15,7 @@ public static async Task Load(Dict dict) } IEnumerable jsonFiles = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly) - .Where(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal)); + .Where(static s => Utils.ValidYomichanFileSuffixes.Contains(s)); bool nonKanjiDict = dict.Type is not DictType.NonspecificKanjiWithWordSchemaYomichan; bool nonNameDict = dict.Type is not DictType.NonspecificNameYomichan; diff --git a/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs b/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs index ca3aa16c..494f2595 100644 --- a/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs +++ b/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs @@ -16,7 +16,7 @@ public static async Task Load(Freq freq) } IEnumerable jsonFiles = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly) - .Where(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal)); + .Where(static s => Utils.ValidYomichanFileSuffixes.Contains(s)); foreach (string jsonFile in jsonFiles) { diff --git a/JL.Core/Utilities/Utils.cs b/JL.Core/Utilities/Utils.cs index d45a2811..60a16062 100644 --- a/JL.Core/Utilities/Utils.cs +++ b/JL.Core/Utilities/Utils.cs @@ -1,3 +1,4 @@ +using System.Buffers; using System.Collections.Frozen; using System.Globalization; using System.Security.Cryptography; @@ -249,4 +250,6 @@ public static string GetPath(string path) return concatArray; } + + public static readonly SearchValues ValidYomichanFileSuffixes = SearchValues.Create(["term", "kanji"], StringComparison.Ordinal); } diff --git a/JL.Windows/GUI/AddDictionaryWindow.xaml.cs b/JL.Windows/GUI/AddDictionaryWindow.xaml.cs index 42233ec2..8444ef49 100644 --- a/JL.Windows/GUI/AddDictionaryWindow.xaml.cs +++ b/JL.Windows/GUI/AddDictionaryWindow.xaml.cs @@ -78,7 +78,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e) else { bool validPath = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly) - .Any(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal)); + .Any(static s => Utils.ValidYomichanFileSuffixes.Contains(s)); if (!validPath) { diff --git a/JL.Windows/GUI/AddFrequencyWindow.xaml.cs b/JL.Windows/GUI/AddFrequencyWindow.xaml.cs index ceae13ea..208e1de8 100644 --- a/JL.Windows/GUI/AddFrequencyWindow.xaml.cs +++ b/JL.Windows/GUI/AddFrequencyWindow.xaml.cs @@ -66,7 +66,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e) if (type is FreqType.Yomichan or FreqType.YomichanKanji) { bool validPath = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly) - .Any(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal)); + .Any(static s => Utils.ValidYomichanFileSuffixes.Contains(s)); if (!validPath) { diff --git a/JL.Windows/GUI/EditDictionaryWindow.xaml.cs b/JL.Windows/GUI/EditDictionaryWindow.xaml.cs index 6693b869..8bb966fb 100644 --- a/JL.Windows/GUI/EditDictionaryWindow.xaml.cs +++ b/JL.Windows/GUI/EditDictionaryWindow.xaml.cs @@ -79,7 +79,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e) else { bool validPath = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly) - .Any(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal)); + .Any(static s => Utils.ValidYomichanFileSuffixes.Contains(s)); if (!validPath) { diff --git a/JL.Windows/GUI/EditFrequencyWindow.xaml.cs b/JL.Windows/GUI/EditFrequencyWindow.xaml.cs index fa6397e8..1bba6cd7 100644 --- a/JL.Windows/GUI/EditFrequencyWindow.xaml.cs +++ b/JL.Windows/GUI/EditFrequencyWindow.xaml.cs @@ -66,7 +66,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e) if (_freq.Type is FreqType.Yomichan or FreqType.YomichanKanji) { bool hasValidFiles = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly) - .Any(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal)); + .Any(static s => Utils.ValidYomichanFileSuffixes.Contains(s)); if (!hasValidFiles) { diff --git a/JL.Windows/Utilities/KeyGestureUtils.cs b/JL.Windows/Utilities/KeyGestureUtils.cs index 598bc624..94380c38 100644 --- a/JL.Windows/Utilities/KeyGestureUtils.cs +++ b/JL.Windows/Utilities/KeyGestureUtils.cs @@ -1,3 +1,4 @@ +using System.Buffers; using System.Collections.Frozen; using System.Text; using System.Windows.Controls; @@ -10,6 +11,8 @@ namespace JL.Windows.Utilities; internal static class KeyGestureUtils { + private static readonly SearchValues s_validModifiers = SearchValues.Create(["Ctrl", "Alt", "Shift"], StringComparison.Ordinal); + public static readonly OrderedDictionary GlobalKeyGestureNameToKeyGestureDict = []; public static readonly KeyGesture AltF4KeyGesture = new(Key.F4, ModifierKeys.Alt); @@ -174,9 +177,7 @@ public static KeyGesture GetKeyGestureFromConfig(SqliteConnection connection, st { KeyGestureConverter keyGestureConverter = new(); - string keyGestureString = rawKeyGesture.Contains("Ctrl", StringComparison.Ordinal) - || rawKeyGesture.Contains("Alt", StringComparison.Ordinal) - || rawKeyGesture.Contains("Shift", StringComparison.Ordinal) + string keyGestureString = s_validModifiers.Contains(rawKeyGesture) ? rawKeyGesture : $"Win+{rawKeyGesture}";