Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Oct 12, 2024
1 parent c6ab4e6 commit d632e52
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 85 deletions.
6 changes: 3 additions & 3 deletions JL.Core/Audio/AudioUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ public static async Task GetAndPlayAudio(string foundSpelling, string? reading)
public static Task SerializeAudioSources()
{
return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "AudioSourceConfig.json"),
JsonSerializer.Serialize(AudioSources, Utils.s_jsoWithEnumConverterAndIndentation));
JsonSerializer.Serialize(AudioSources, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation));
}

public static Task CreateDefaultAudioSourceConfig()
{
_ = Directory.CreateDirectory(Utils.ConfigPath);
return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "AudioSourceConfig.json"),
JsonSerializer.Serialize(s_builtInAudioSources, Utils.s_jsoWithEnumConverterAndIndentation));
JsonSerializer.Serialize(s_builtInAudioSources, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation));
}

internal static async Task DeserializeAudioSources()
Expand All @@ -216,7 +216,7 @@ internal static async Task DeserializeAudioSources()
await using (fileStream.ConfigureAwait(false))
{
Dictionary<string, AudioSource>? deserializedAudioSources = await JsonSerializer
.DeserializeAsync<Dictionary<string, AudioSource>>(fileStream, Utils.s_jsoWithEnumConverter).ConfigureAwait(false);
.DeserializeAsync<Dictionary<string, AudioSource>>(fileStream, Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false);

if (deserializedAudioSources is not null)
{
Expand Down
6 changes: 3 additions & 3 deletions JL.Core/Config/StatsDBUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class StatsDBUtils
{
public static void InsertStats(SqliteConnection connection, Stats stats, int profileId)
{
InsertStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoWithEnumConverterAndIndentation), profileId);
InsertStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoNotIgnoringNullWithEnumConverterAndIndentation), profileId);
}

public static void InsertStats(SqliteConnection connection, string stats, int profileId)
Expand All @@ -28,7 +28,7 @@ INSERT INTO stats (profile_id, value)

private static void UpdateStats(SqliteConnection connection, Stats stats, int profileId)
{
UpdateStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoWithEnumConverterAndIndentation), profileId);
UpdateStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoNotIgnoringNullWithEnumConverterAndIndentation), profileId);
}

public static void UpdateStats(SqliteConnection connection, string stats, int profileId)
Expand Down Expand Up @@ -61,7 +61,7 @@ FROM stats
string? statsValue = (string?)command.ExecuteScalar();

return statsValue is not null
? JsonSerializer.Deserialize<Stats>(statsValue, Utils.s_jsoWithEnumConverter)
? JsonSerializer.Deserialize<Stats>(statsValue, Utils.s_jsoNotIgnoringNullWithEnumConverter)
: null;
}

Expand Down
2 changes: 1 addition & 1 deletion JL.Core/Deconjugation/DeconjugatorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static async Task DeserializeRules()
FileStream fileStream = File.OpenRead(Path.Join(Utils.ResourcesPath, "deconjugation_rules.json"));
await using (fileStream.ConfigureAwait(false))
{
Deconjugator.Rules = (await JsonSerializer.DeserializeAsync<Rule[]>(fileStream, Utils.s_defaultJso).ConfigureAwait(false))!;
Deconjugator.Rules = (await JsonSerializer.DeserializeAsync<Rule[]>(fileStream, Utils.s_jsoNotIgnoringNull).ConfigureAwait(false))!;
}

for (int i = 0; i < Deconjugator.Rules.Length; i++)
Expand Down
6 changes: 3 additions & 3 deletions JL.Core/Dicts/DictUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,13 +1375,13 @@ public static Task CreateDefaultDictsConfig()
{
_ = Directory.CreateDirectory(Utils.ConfigPath);
return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "dicts.json"),
JsonSerializer.Serialize(BuiltInDicts, Utils.s_jsoWithEnumConverterAndIndentation));
JsonSerializer.Serialize(BuiltInDicts, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation));
}

public static Task SerializeDicts()
{
return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "dicts.json"),
JsonSerializer.Serialize(Dicts, Utils.s_jsoWithEnumConverterAndIndentation));
JsonSerializer.Serialize(Dicts, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation));
}

internal static async Task DeserializeDicts()
Expand All @@ -1390,7 +1390,7 @@ internal static async Task DeserializeDicts()
await using (dictStream.ConfigureAwait(false))
{
Dictionary<string, Dict>? deserializedDicts = await JsonSerializer
.DeserializeAsync<Dictionary<string, Dict>>(dictStream, Utils.s_jsoWithEnumConverter).ConfigureAwait(false);
.DeserializeAsync<Dictionary<string, Dict>>(dictStream, Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false);

if (deserializedDicts is not null)
{
Expand Down
14 changes: 7 additions & 7 deletions JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ INSERT INTO record_search_key(record_id, search_key)
_ = insertRecordCommand.Parameters["@id"].Value = id;
_ = insertRecordCommand.Parameters["@primary_spelling"].Value = record.PrimarySpelling;
_ = insertRecordCommand.Parameters["@reading"].Value = record.Reading is not null ? record.Reading : DBNull.Value;
_ = insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_defaultJso) : DBNull.Value;
_ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_defaultJso);
_ = insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
_ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jsoNotIgnoringNull);
_ = insertRecordCommand.ExecuteNonQuery();

_ = insertSearchKeyCommand.Parameters["@record_id"].Value = id;
Expand Down Expand Up @@ -170,10 +170,10 @@ INSERT INTO record_search_key(record_id, search_key)
string[]? alternativeSpellings = null;
if (dataReader[nameof(alternativeSpellings)] is string alternativeSpellingsFromDB)
{
alternativeSpellings = JsonSerializer.Deserialize<string[]>(alternativeSpellingsFromDB, Utils.s_defaultJso);
alternativeSpellings = JsonSerializer.Deserialize<string[]>(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull);
}

string[] definitions = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(definitions)), Utils.s_defaultJso)!;
string[] definitions = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!;

if (results.TryGetValue(searchKey, out IList<IDictRecord>? result))
{
Expand Down Expand Up @@ -234,7 +234,7 @@ FROM record r
while (dataReader.Read())
{
EpwingNazekaRecord record = GetRecord(dataReader);
string[] searchKeys = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(searchKeys)), Utils.s_defaultJso)!;
string[] searchKeys = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!;
for (int i = 0; i < searchKeys.Length; i++)
{
string searchKey = searchKeys[i];
Expand Down Expand Up @@ -270,10 +270,10 @@ private static EpwingNazekaRecord GetRecord(SqliteDataReader dataReader)
string[]? alternativeSpellings = null;
if (dataReader[nameof(alternativeSpellings)] is string alternativeSpellingsFromDB)
{
alternativeSpellings = JsonSerializer.Deserialize<string[]>(alternativeSpellingsFromDB, Utils.s_defaultJso);
alternativeSpellings = JsonSerializer.Deserialize<string[]>(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull);
}

string[] definitions = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(definitions)), Utils.s_defaultJso)!;
string[] definitions = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!;

return new EpwingNazekaRecord(primarySpelling, reading, alternativeSpellings, definitions);
}
Expand Down
3 changes: 1 addition & 2 deletions JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public static async Task Load(Dict dict)
FileStream fileStream = File.OpenRead(fullPath);
await using (fileStream.ConfigureAwait(false))
{
jsonObjects = await JsonSerializer.DeserializeAsync<List<JsonElement>>(fileStream)
.ConfigureAwait(false);
jsonObjects = await JsonSerializer.DeserializeAsync<List<JsonElement>>(fileStream, Utils.s_jsoNotIgnoringNull).ConfigureAwait(false);
}

IDictionary<string, IList<IDictRecord>> nazekaEpwingDict = dict.Contents;
Expand Down
14 changes: 7 additions & 7 deletions JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ INSERT INTO record_search_key(record_id, search_key)
_ = insertRecordCommand.Parameters["@id"].Value = id;
_ = insertRecordCommand.Parameters["@primary_spelling"].Value = record.PrimarySpelling;
_ = insertRecordCommand.Parameters["@reading"].Value = record.Reading is not null ? record.Reading : DBNull.Value;
_ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_defaultJso);
_ = insertRecordCommand.Parameters["@part_of_speech"].Value = record.WordClasses is not null ? JsonSerializer.Serialize(record.WordClasses, Utils.s_defaultJso) : DBNull.Value;
_ = insertRecordCommand.Parameters["@glossary_tags"].Value = record.DefinitionTags is not null ? JsonSerializer.Serialize(record.DefinitionTags, Utils.s_defaultJso) : DBNull.Value;
_ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jsoNotIgnoringNull);
_ = insertRecordCommand.Parameters["@part_of_speech"].Value = record.WordClasses is not null ? JsonSerializer.Serialize(record.WordClasses, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
_ = insertRecordCommand.Parameters["@glossary_tags"].Value = record.DefinitionTags is not null ? JsonSerializer.Serialize(record.DefinitionTags, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
_ = insertRecordCommand.ExecuteNonQuery();

_ = insertSearchKeyCommand.Parameters["@record_id"].Value = id;
Expand Down Expand Up @@ -221,7 +221,7 @@ FROM record r
while (dataReader.Read())
{
EpwingYomichanRecord record = GetRecord(dataReader);
string[] searchKeys = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(searchKeys)), Utils.s_defaultJso)!;
string[] searchKeys = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!;
for (int i = 0; i < searchKeys.Length; i++)
{
string searchKey = searchKeys[i];
Expand Down Expand Up @@ -255,18 +255,18 @@ private static EpwingYomichanRecord GetRecord(SqliteDataReader dataReader)
reading = readingFromDB;
}

string[] definitions = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(definitions)), Utils.s_defaultJso)!;
string[] definitions = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!;

string[]? wordClasses = null;
if (dataReader[nameof(wordClasses)] is string wordClassesFromDB)
{
wordClasses = JsonSerializer.Deserialize<string[]>(wordClassesFromDB, Utils.s_defaultJso);
wordClasses = JsonSerializer.Deserialize<string[]>(wordClassesFromDB, Utils.s_jsoNotIgnoringNull);
}

string[]? definitionTags = null;
if (dataReader[nameof(definitionTags)] is string definitionTagsFromDB)
{
definitionTags = JsonSerializer.Deserialize<string[]>(definitionTagsFromDB, Utils.s_defaultJso);
definitionTags = JsonSerializer.Deserialize<string[]>(definitionTagsFromDB, Utils.s_jsoNotIgnoringNull);
}

return new EpwingYomichanRecord(primarySpelling, reading, definitions, wordClasses, definitionTags);
Expand Down
22 changes: 11 additions & 11 deletions JL.Core/Dicts/JMdict/JmdictDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ INSERT INTO record_search_key(record_id, search_key)
insertRecordCommand.Parameters["@id"].Value = id;
insertRecordCommand.Parameters["@edict_id"].Value = record.Id;
insertRecordCommand.Parameters["@primary_spelling"].Value = record.PrimarySpelling;
insertRecordCommand.Parameters["@primary_spelling_orthography_info"].Value = record.PrimarySpellingOrthographyInfo is not null ? JsonSerializer.Serialize(record.PrimarySpellingOrthographyInfo, Utils.s_defaultJso) : DBNull.Value;
insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_defaultJso) : DBNull.Value;
insertRecordCommand.Parameters["@primary_spelling_orthography_info"].Value = record.PrimarySpellingOrthographyInfo is not null ? JsonSerializer.Serialize(record.PrimarySpellingOrthographyInfo, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
insertRecordCommand.Parameters["@alternative_spellings_orthography_info"].Value = record.AlternativeSpellingsOrthographyInfo is not null ? JsonSerializer.Serialize(record.AlternativeSpellingsOrthographyInfo, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
insertRecordCommand.Parameters["@readings"].Value = record.Readings is not null ? JsonSerializer.Serialize(record.Readings, Utils.s_defaultJso) : DBNull.Value;
insertRecordCommand.Parameters["@readings"].Value = record.Readings is not null ? JsonSerializer.Serialize(record.Readings, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
insertRecordCommand.Parameters["@readings_orthography_info"].Value = record.ReadingsOrthographyInfo is not null ? JsonSerializer.Serialize(record.ReadingsOrthographyInfo, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
insertRecordCommand.Parameters["@reading_restrictions"].Value = record.ReadingRestrictions is not null ? JsonSerializer.Serialize(record.ReadingRestrictions, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_defaultJso);
insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jsoNotIgnoringNull);
insertRecordCommand.Parameters["@glossary_info"].Value = record.DefinitionInfo is not null ? JsonSerializer.Serialize(record.DefinitionInfo, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
insertRecordCommand.Parameters["@part_of_speech"].Value = JsonSerializer.Serialize(record.WordClasses, Utils.s_defaultJso);
insertRecordCommand.Parameters["@part_of_speech"].Value = JsonSerializer.Serialize(record.WordClasses, Utils.s_jsoNotIgnoringNull);
insertRecordCommand.Parameters["@spelling_restrictions"].Value = record.SpellingRestrictions is not null ? JsonSerializer.Serialize(record.SpellingRestrictions, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
insertRecordCommand.Parameters["@fields"].Value = record.Fields is not null ? JsonSerializer.Serialize(record.Fields, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
insertRecordCommand.Parameters["@misc"].Value = record.Misc is not null ? JsonSerializer.Serialize(record.Misc, Utils.s_jsoNotIgnoringNull) : DBNull.Value;
Expand Down Expand Up @@ -272,7 +272,7 @@ FROM record r
{
JmdictRecord record = GetRecord(dataReader);

string[] searchKeys = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(searchKeys)), Utils.s_defaultJso)!;
string[] searchKeys = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!;
for (int i = 0; i < searchKeys.Length; i++)
{
string searchKey = searchKeys[i];
Expand Down Expand Up @@ -303,7 +303,7 @@ private static JmdictRecord GetRecord(SqliteDataReader dataReader)
string[]? primarySpellingOrthographyInfo = null;
if (dataReader[nameof(primarySpellingOrthographyInfo)] is string primarySpellingOrthographyInfoFromDB)
{
primarySpellingOrthographyInfo = JsonSerializer.Deserialize<string[]>(primarySpellingOrthographyInfoFromDB, Utils.s_defaultJso);
primarySpellingOrthographyInfo = JsonSerializer.Deserialize<string[]>(primarySpellingOrthographyInfoFromDB, Utils.s_jsoNotIgnoringNull);
}

string[]?[]? spellingRestrictions = null;
Expand All @@ -315,7 +315,7 @@ private static JmdictRecord GetRecord(SqliteDataReader dataReader)
string[]? alternativeSpellings = null;
if (dataReader[nameof(alternativeSpellings)] is string alternativeSpellingsFromDB)
{
alternativeSpellings = JsonSerializer.Deserialize<string[]>(alternativeSpellingsFromDB, Utils.s_defaultJso);
alternativeSpellings = JsonSerializer.Deserialize<string[]>(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull);
}

string[]?[]? alternativeSpellingsOrthographyInfo = null;
Expand All @@ -327,7 +327,7 @@ private static JmdictRecord GetRecord(SqliteDataReader dataReader)
string[]? readings = null;
if (dataReader[nameof(readings)] is string readingsFromDB)
{
readings = JsonSerializer.Deserialize<string[]>(readingsFromDB, Utils.s_defaultJso);
readings = JsonSerializer.Deserialize<string[]>(readingsFromDB, Utils.s_jsoNotIgnoringNull);
}

string[]?[]? readingRestrictions = null;
Expand All @@ -342,8 +342,8 @@ private static JmdictRecord GetRecord(SqliteDataReader dataReader)
readingsOrthographyInfo = JsonSerializer.Deserialize<string[]?[]>(readingsOrthographyInfoFromDB, Utils.s_jsoNotIgnoringNull);
}

string[][] definitions = JsonSerializer.Deserialize<string[][]>(dataReader.GetString(nameof(definitions)), Utils.s_defaultJso)!;
string[][] wordClasses = JsonSerializer.Deserialize<string[][]>(dataReader.GetString(nameof(wordClasses)), Utils.s_defaultJso)!;
string[][] definitions = JsonSerializer.Deserialize<string[][]>(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!;
string[][] wordClasses = JsonSerializer.Deserialize<string[][]>(dataReader.GetString(nameof(wordClasses)), Utils.s_jsoNotIgnoringNull)!;

string[]?[]? fields = null;
if (dataReader[nameof(fields)] is string fieldsFromDB)
Expand Down
Loading

0 comments on commit d632e52

Please sign in to comment.