From 267357c3e32d9aada3e7ad887ec003f04d08a843 Mon Sep 17 00:00:00 2001 From: LotP1 Date: Mon, 16 Dec 2024 21:50:02 +0100 Subject: [PATCH] Use correct JsonTypeInfo implementation --- src/Ryujinx/Common/LocaleManager.cs | 16 +++++++++++----- .../UI/Views/Main/MainMenuBarView.axaml.cs | 3 +-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx/Common/LocaleManager.cs b/src/Ryujinx/Common/LocaleManager.cs index 7a475e8b5..fe7a05475 100644 --- a/src/Ryujinx/Common/LocaleManager.cs +++ b/src/Ryujinx/Common/LocaleManager.cs @@ -11,7 +11,7 @@ using System.IO; using System.Linq; using System.Text.Encodings.Web; using System.Text.Json; -using System.Text.Json.Serialization.Metadata; +using System.Text.Json.Serialization; using System.Text.Unicode; namespace Ryujinx.Ava.Common.Locale @@ -160,8 +160,7 @@ namespace Ryujinx.Ava.Common.Locale return null; } - JsonSerializerOptions helperOptions = JsonHelper.GetDefaultSerializerOptions(); - LocalesJSON json = JsonHelper.Deserialize(fileData, (JsonTypeInfo)helperOptions.GetTypeInfo(typeof(LocalesJSON))); + LocalesJSON json = JsonHelper.Deserialize(fileData, LocalesJSONContext.Default.LocalesJSON); foreach (LocalesEntry locale in json.Locales) { @@ -211,12 +210,15 @@ namespace Ryujinx.Ava.Common.Locale string location = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.GetDirectories("Assets")[0].GetFiles("locales.json")[0].FullName; - JsonSerializerOptions options = new JsonSerializerOptions + JsonSerializerOptions jsonOptions = new JsonSerializerOptions { WriteIndented = true, Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) }; - string jsonString = JsonSerializer.Serialize(json, options);//GetSubEventString(rootEvent, 0); + + LocalesJSONContext context = new LocalesJSONContext(jsonOptions); + + string jsonString = JsonHelper.Serialize(json, context.LocalesJSON); using (StreamWriter sw = new StreamWriter(location)) { @@ -241,4 +243,8 @@ namespace Ryujinx.Ava.Common.Locale public string ID { get; set; } public Dictionary Translations { get; set; } } + + [JsonSourceGenerationOptions(WriteIndented = true)] + [JsonSerializable(typeof(LocalesJSON))] + internal partial class LocalesJSONContext : JsonSerializerContext { } } diff --git a/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs b/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs index 40bb01b08..61b27e49f 100644 --- a/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs +++ b/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs @@ -60,8 +60,7 @@ namespace Ryujinx.Ava.UI.Views.Main string languageJson = EmbeddedResources.ReadAllText(localePath); - JsonSerializerOptions helperOptions = JsonHelper.GetDefaultSerializerOptions(); - LocalesJSON locales = JsonHelper.Deserialize(languageJson, (JsonTypeInfo)helperOptions.GetTypeInfo(typeof(LocalesJSON))); + LocalesJSON locales = JsonHelper.Deserialize(languageJson, LocalesJSONContext.Default.LocalesJSON); foreach (string language in locales.Languages) {