From 84acd9a22eecc1f5f325ddcd5bc5430988b0c46a Mon Sep 17 00:00:00 2001 From: rampaa Date: Sun, 22 Dec 2024 19:46:26 +0300 Subject: [PATCH] Minor --- JL.Core/Dicts/Dict.cs | 7 +++---- JL.Core/Dicts/DictUtils.cs | 14 ++++++------- JL.Core/Freqs/Freq.cs | 4 ++-- JL.Core/Freqs/FreqUtils.cs | 6 +++--- JL.Core/Utilities/Utils.cs | 24 ++++++++++++++++------ JL.Windows/GUI/AddDictionaryWindow.xaml.cs | 2 +- JL.Windows/GUI/AddFrequencyWindow.xaml.cs | 2 +- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/JL.Core/Dicts/Dict.cs b/JL.Core/Dicts/Dict.cs index 15a91f08..5dcb5dac 100644 --- a/JL.Core/Dicts/Dict.cs +++ b/JL.Core/Dicts/Dict.cs @@ -4,7 +4,7 @@ namespace JL.Core.Dicts; -public sealed class Dict(DictType type, string name, string path, bool active, int priority, int size, bool ready, DictOptions options) +public sealed class Dict(DictType type, string name, string path, bool active, int priority, int size, DictOptions options) { public DictType Type { get; internal set; } = type; public string Name { get; set; } = name; @@ -14,12 +14,11 @@ public sealed class Dict(DictType type, string name, string path, bool active, i // ReSharper disable once MemberCanBeInternal public int Size { get; set; } = size; - - [JsonIgnore] public bool Ready { get; set; } = ready; + public DictOptions Options { get; set; } = options; + [JsonIgnore] public bool Ready { get; set; } // = false; #pragma warning disable CA2227 [JsonIgnore] public IDictionary> Contents { get; set; } = FrozenDictionary>.Empty; #pragma warning restore CA2227 - public DictOptions Options { get; set; } = options; } diff --git a/JL.Core/Dicts/DictUtils.cs b/JL.Core/Dicts/DictUtils.cs index d5d3f64b..200cbe6e 100644 --- a/JL.Core/Dicts/DictUtils.cs +++ b/JL.Core/Dicts/DictUtils.cs @@ -46,7 +46,7 @@ public static class DictUtils nameof(DictType.ProfileCustomWordDictionary), new Dict(DictType.ProfileCustomWordDictionary, "Custom Word Dictionary (Profile)", Path.Join(ProfileUtils.ProfileFolderPath, "Default_Custom_Words.txt"), - true, -1, 128, false, + true, -1, 128, new DictOptions( new UseDBOption(false), new NoAllOption(false), @@ -56,7 +56,7 @@ public static class DictUtils nameof(DictType.ProfileCustomNameDictionary), new Dict(DictType.ProfileCustomNameDictionary, "Custom Name Dictionary (Profile)", Path.Join(ProfileUtils.ProfileFolderPath, "Default_Custom_Names.txt"), - true, 0, 128, false, + true, 0, 128, new DictOptions( new UseDBOption(false), new NoAllOption(false))) @@ -65,7 +65,7 @@ public static class DictUtils nameof(DictType.CustomWordDictionary), new Dict(DictType.CustomWordDictionary, "Custom Word Dictionary", Path.Join(Utils.ResourcesPath, "custom_words.txt"), - true, 1, 128, false, + true, 1, 128, new DictOptions( new UseDBOption(false), new NoAllOption(false), @@ -75,7 +75,7 @@ public static class DictUtils nameof(DictType.CustomNameDictionary), new Dict(DictType.CustomNameDictionary, "Custom Name Dictionary", Path.Join(Utils.ResourcesPath, "custom_names.txt"), - true, 2, 128, false, + true, 2, 128, new DictOptions( new UseDBOption(false), new NoAllOption(false))) @@ -83,7 +83,7 @@ public static class DictUtils { nameof(DictType.JMdict), new Dict(DictType.JMdict, nameof(DictType.JMdict), Path.Join(Utils.ResourcesPath, $"{nameof(DictType.JMdict)}.xml"), - true, 3, 500000, false, + true, 3, 500000, new DictOptions( new UseDBOption(true), new NoAllOption(false), @@ -108,7 +108,7 @@ public static class DictUtils { nameof(DictType.Kanjidic), new Dict(DictType.Kanjidic, nameof(DictType.Kanjidic), Path.Join(Utils.ResourcesPath, "kanjidic2.xml"), - true, 4, 13108, false, + true, 4, 13108, new DictOptions( new UseDBOption(true), new NoAllOption(false), @@ -117,7 +117,7 @@ public static class DictUtils { nameof(DictType.JMnedict), new Dict(DictType.JMnedict, nameof(DictType.JMnedict), Path.Join(Utils.ResourcesPath, $"{nameof(DictType.JMnedict)}.xml"), - true, 5, 700000, false, + true, 5, 700000, new DictOptions( new UseDBOption(true), new NoAllOption(false), diff --git a/JL.Core/Freqs/Freq.cs b/JL.Core/Freqs/Freq.cs index 06f4ae68..1a905257 100644 --- a/JL.Core/Freqs/Freq.cs +++ b/JL.Core/Freqs/Freq.cs @@ -4,7 +4,7 @@ namespace JL.Core.Freqs; -public sealed class Freq(FreqType type, string name, string path, bool active, int priority, int size, int maxValue, bool ready, FreqOptions options) +public sealed class Freq(FreqType type, string name, string path, bool active, int priority, int size, int maxValue, FreqOptions options) { public FreqType Type { get; } = type; public string Name { get; set; } = name; @@ -18,7 +18,7 @@ public sealed class Freq(FreqType type, string name, string path, bool active, i // ReSharper disable once MemberCanBeInternal public int MaxValue { get; set; } = maxValue; - [JsonIgnore] public bool Ready { get; set; } = ready; + [JsonIgnore] public bool Ready { get; set; } // = false; #pragma warning disable CA2227 [JsonIgnore] public IDictionary> Contents { get; set; } = FrozenDictionary>.Empty; diff --git a/JL.Core/Freqs/FreqUtils.cs b/JL.Core/Freqs/FreqUtils.cs index 9a4f51f9..8f569135 100644 --- a/JL.Core/Freqs/FreqUtils.cs +++ b/JL.Core/Freqs/FreqUtils.cs @@ -20,19 +20,19 @@ public static class FreqUtils "VN (Nazeka)", new Freq(FreqType.Nazeka, "VN (Nazeka)", Path.Join(Utils.ResourcesPath, "freqlist_vns.json"), - true, 1, 57273, 35894, false, new FreqOptions(new UseDBOption(true), new HigherValueMeansHigherFrequencyOption(false))) + true, 1, 57273, 35894, new FreqOptions(new UseDBOption(true), new HigherValueMeansHigherFrequencyOption(false))) }, { "Narou (Nazeka)", new Freq(FreqType.Nazeka, "Narou (Nazeka)", Path.Join(Utils.ResourcesPath, "freqlist_narou.json"), - false, 2, 75588, 48528, false, new FreqOptions(new UseDBOption(true), new HigherValueMeansHigherFrequencyOption(false))) + false, 2, 75588, 48528, new FreqOptions(new UseDBOption(true), new HigherValueMeansHigherFrequencyOption(false))) }, { "Novel (Nazeka)", new Freq(FreqType.Nazeka, "Novel (Nazeka)", Path.Join(Utils.ResourcesPath, "freqlist_novels.json"), - false, 3, 114348, 74633, false, new FreqOptions(new UseDBOption(true), new HigherValueMeansHigherFrequencyOption(false))) + false, 3, 114348, 74633, new FreqOptions(new UseDBOption(true), new HigherValueMeansHigherFrequencyOption(false))) } }; diff --git a/JL.Core/Utilities/Utils.cs b/JL.Core/Utilities/Utils.cs index 60a16062..a5a40403 100644 --- a/JL.Core/Utilities/Utils.cs +++ b/JL.Core/Utilities/Utils.cs @@ -51,13 +51,17 @@ public static partial class Utils internal static readonly JsonSerializerOptions s_jsoNotIgnoringNull = new() { - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + RespectNullableAnnotations = true, + RespectRequiredConstructorParameters = true }; internal static readonly JsonSerializerOptions s_jsoIgnoringNull = new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + RespectNullableAnnotations = true, + RespectRequiredConstructorParameters = true }; internal static readonly JsonSerializerOptions s_jsoNotIgnoringNullWithEnumConverter = new() @@ -66,7 +70,9 @@ public static partial class Utils { new JsonStringEnumConverter() }, - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + RespectNullableAnnotations = true, + RespectRequiredConstructorParameters = true }; internal static readonly JsonSerializerOptions s_jsoIgnoringNullWithEnumConverter = new() @@ -76,7 +82,9 @@ public static partial class Utils new JsonStringEnumConverter() }, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + RespectNullableAnnotations = true, + RespectRequiredConstructorParameters = true }; internal static readonly JsonSerializerOptions s_jsoNotIgnoringNullWithEnumConverterAndIndentation = new() @@ -86,7 +94,9 @@ public static partial class Utils new JsonStringEnumConverter() }, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, - WriteIndented = true + WriteIndented = true, + RespectNullableAnnotations = true, + RespectRequiredConstructorParameters = true }; internal static readonly JsonSerializerOptions s_jsoIgnoringNullWithEnumConverterAndIndentation = new() @@ -97,7 +107,9 @@ public static partial class Utils }, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - WriteIndented = true + WriteIndented = true, + RespectNullableAnnotations = true, + RespectRequiredConstructorParameters = true }; internal static readonly FrozenDictionary s_iso6392BTo2T = new Dictionary(20, StringComparer.Ordinal) diff --git a/JL.Windows/GUI/AddDictionaryWindow.xaml.cs b/JL.Windows/GUI/AddDictionaryWindow.xaml.cs index b34d1470..726deed1 100644 --- a/JL.Windows/GUI/AddDictionaryWindow.xaml.cs +++ b/JL.Windows/GUI/AddDictionaryWindow.xaml.cs @@ -89,7 +89,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e) } DictOptions options = _dictOptionsControl.GetDictOptions(type); - Dict dict = new(type, name, path, true, DictUtils.Dicts.Count + 1, 0, false, options); + Dict dict = new(type, name, path, true, DictUtils.Dicts.Count + 1, 0, options); DictUtils.Dicts.Add(name, dict); if (dict.Type is DictType.PitchAccentYomichan) diff --git a/JL.Windows/GUI/AddFrequencyWindow.xaml.cs b/JL.Windows/GUI/AddFrequencyWindow.xaml.cs index b3445980..290fb8b4 100644 --- a/JL.Windows/GUI/AddFrequencyWindow.xaml.cs +++ b/JL.Windows/GUI/AddFrequencyWindow.xaml.cs @@ -78,7 +78,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e) FreqOptions options = _freqOptionsControl.GetFreqOptions(type); FreqUtils.FreqDicts.Add(name, - new Freq(type, name, path, true, FreqUtils.FreqDicts.Count + 1, 0, 0, false, options)); + new Freq(type, name, path, true, FreqUtils.FreqDicts.Count + 1, 0, 0, options)); Close(); }