Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 27, 2024
1 parent fb244b2 commit 71c54ab
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 120 deletions.
6 changes: 3 additions & 3 deletions JL.Core/Audio/AudioUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,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_jsoIgnoringNullWithEnumConverterAndIndentation));
JsonSerializer.Serialize(AudioSources, Utils.s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation));
}

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

internal static async Task DeserializeAudioSources()
Expand All @@ -217,7 +217,7 @@ internal static async Task DeserializeAudioSources()
await using (fileStream.ConfigureAwait(false))
{
Dictionary<string, AudioSource>? deserializedAudioSources = await JsonSerializer
.DeserializeAsync<Dictionary<string, AudioSource>>(fileStream, Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false);
.DeserializeAsync<Dictionary<string, AudioSource>>(fileStream, Utils.s_jsoWithEnumConverter).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 @@ -10,7 +10,7 @@ public static class StatsDBUtils
{
public static void InsertStats(SqliteConnection connection, Stats stats, int profileId)
{
InsertStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoNotIgnoringNullWithEnumConverterAndIndentation), profileId);
InsertStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoWithEnumConverterAndIndentation), profileId);
}

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

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

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

return statsValue is not null
? JsonSerializer.Deserialize<Stats>(statsValue, Utils.s_jsoNotIgnoringNullWithEnumConverter)
? JsonSerializer.Deserialize<Stats>(statsValue, Utils.s_jsoWithEnumConverter)
: 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_jsoNotIgnoringNull).ConfigureAwait(false))!;
Deconjugator.Rules = (await JsonSerializer.DeserializeAsync<Rule[]>(fileStream, Utils.s_jso).ConfigureAwait(false))!;
}

int rulesLength = Deconjugator.Rules.Length;
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 @@ -1361,13 +1361,13 @@ public static Task CreateDefaultDictsConfig()
{
_ = Directory.CreateDirectory(Utils.ConfigPath);
return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "dicts.json"),
JsonSerializer.Serialize(BuiltInDicts, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation));
JsonSerializer.Serialize(BuiltInDicts, Utils.s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation));
}

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

internal static async Task DeserializeDicts()
Expand All @@ -1376,7 +1376,7 @@ internal static async Task DeserializeDicts()
await using (dictStream.ConfigureAwait(false))
{
Dictionary<string, Dict>? deserializedDicts = await JsonSerializer
.DeserializeAsync<Dictionary<string, Dict>>(dictStream, Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false);
.DeserializeAsync<Dictionary<string, Dict>>(dictStream, Utils.s_jsoWithEnumConverter).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_jsoNotIgnoringNull) : DBNull.Value;
_ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jsoNotIgnoringNull);
_ = insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_jso) : DBNull.Value;
_ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jso);
_ = 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_jsoNotIgnoringNull);
alternativeSpellings = JsonSerializer.Deserialize<string[]>(alternativeSpellingsFromDB, Utils.s_jso);
}

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

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);
List<string> searchKeys = JsonSerializer.Deserialize<List<string>>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!;
List<string> searchKeys = JsonSerializer.Deserialize<List<string>>(dataReader.GetString(nameof(searchKeys)), Utils.s_jso)!;
for (int i = 0; i < searchKeys.Count; 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_jsoNotIgnoringNull);
alternativeSpellings = JsonSerializer.Deserialize<string[]>(alternativeSpellingsFromDB, Utils.s_jso);
}

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

return new EpwingNazekaRecord(primarySpelling, reading, alternativeSpellings, definitions);
}
Expand Down
2 changes: 1 addition & 1 deletion JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +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, Utils.s_jsoNotIgnoringNull).ConfigureAwait(false);
jsonObjects = await JsonSerializer.DeserializeAsync<List<JsonElement>>(fileStream, Utils.s_jso).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_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.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jso);
_ = insertRecordCommand.Parameters["@part_of_speech"].Value = record.WordClasses is not null ? JsonSerializer.Serialize(record.WordClasses, Utils.s_jso) : DBNull.Value;
_ = insertRecordCommand.Parameters["@glossary_tags"].Value = record.DefinitionTags is not null ? JsonSerializer.Serialize(record.DefinitionTags, Utils.s_jso) : 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);
List<string> searchKeys = JsonSerializer.Deserialize<List<string>>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!;
List<string> searchKeys = JsonSerializer.Deserialize<List<string>>(dataReader.GetString(nameof(searchKeys)), Utils.s_jso)!;
for (int i = 0; i < searchKeys.Count; 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_jsoNotIgnoringNull)!;
string[] definitions = JsonSerializer.Deserialize<string[]>(dataReader.GetString(nameof(definitions)), Utils.s_jso)!;

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

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

return new EpwingYomichanRecord(primarySpelling, reading, definitions, wordClasses, definitionTags);
Expand Down
Loading

0 comments on commit 71c54ab

Please sign in to comment.