mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-24 21:37:11 +02:00
Use source generated json serializers in order to improve code trimming (#4094)
* Use source generated json serializers in order to improve code trimming * Use strongly typed github releases model to fetch updates instead of raw Newtonsoft.Json parsing * Use separate model for LogEventArgs serialization * Make dynamic object formatter static. Fix string builder pooling. * Do not inherit json version of LogEventArgs from EventArgs * Fix extra space in object formatting * Write log json directly to stream instead of using buffer writer * Rebase fixes * Rebase fixes * Rebase fixes * Enforce block-scoped namespaces in the solution. Convert style for existing code * Apply suggestions from code review Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com> * Rebase indent fix * Fix indent * Delete unnecessary json properties * Rebase fix * Remove overridden json property names as they are handled in the options * Apply suggestions from code review Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com> * Use default json options in github api calls * Indentation and spacing fixes --------- Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
This commit is contained in:
parent
17620d18db
commit
4ce4299ca2
73 changed files with 887 additions and 609 deletions
|
@ -31,7 +31,7 @@ namespace Ryujinx.Ui.Windows
|
|||
{
|
||||
string patreonJsonString = await httpClient.GetStringAsync("https://patreon.ryujinx.org/");
|
||||
|
||||
_patreonNamesText.Buffer.Text = string.Join(", ", JsonHelper.Deserialize<string[]>(patreonJsonString));
|
||||
_patreonNamesText.Buffer.Text = string.Join(", ", JsonHelper.Deserialize(patreonJsonString, CommonJsonContext.Default.StringArray));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@ using Ryujinx.Common;
|
|||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.Ui.Common.Configuration;
|
||||
using Ryujinx.Ui.Common.Models.Amiibo;
|
||||
using Ryujinx.Ui.Widgets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -11,65 +12,15 @@ using System.Linq;
|
|||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using AmiiboApi = Ryujinx.Ui.Common.Models.Amiibo.AmiiboApi;
|
||||
using AmiiboJsonSerializerContext = Ryujinx.Ui.Common.Models.Amiibo.AmiiboJsonSerializerContext;
|
||||
|
||||
namespace Ryujinx.Ui.Windows
|
||||
{
|
||||
public partial class AmiiboWindow : Window
|
||||
{
|
||||
private struct AmiiboJson
|
||||
{
|
||||
[JsonPropertyName("amiibo")]
|
||||
public List<AmiiboApi> Amiibo { get; set; }
|
||||
[JsonPropertyName("lastUpdated")]
|
||||
public DateTime LastUpdated { get; set; }
|
||||
}
|
||||
|
||||
private struct AmiiboApi
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonPropertyName("head")]
|
||||
public string Head { get; set; }
|
||||
[JsonPropertyName("tail")]
|
||||
public string Tail { get; set; }
|
||||
[JsonPropertyName("image")]
|
||||
public string Image { get; set; }
|
||||
[JsonPropertyName("amiiboSeries")]
|
||||
public string AmiiboSeries { get; set; }
|
||||
[JsonPropertyName("character")]
|
||||
public string Character { get; set; }
|
||||
[JsonPropertyName("gameSeries")]
|
||||
public string GameSeries { get; set; }
|
||||
[JsonPropertyName("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonPropertyName("release")]
|
||||
public Dictionary<string, string> Release { get; set; }
|
||||
|
||||
[JsonPropertyName("gamesSwitch")]
|
||||
public List<AmiiboApiGamesSwitch> GamesSwitch { get; set; }
|
||||
}
|
||||
|
||||
private class AmiiboApiGamesSwitch
|
||||
{
|
||||
[JsonPropertyName("amiiboUsage")]
|
||||
public List<AmiiboApiUsage> AmiiboUsage { get; set; }
|
||||
[JsonPropertyName("gameID")]
|
||||
public List<string> GameId { get; set; }
|
||||
[JsonPropertyName("gameName")]
|
||||
public string GameName { get; set; }
|
||||
}
|
||||
|
||||
private class AmiiboApiUsage
|
||||
{
|
||||
[JsonPropertyName("Usage")]
|
||||
public string Usage { get; set; }
|
||||
[JsonPropertyName("write")]
|
||||
public bool Write { get; set; }
|
||||
}
|
||||
|
||||
private const string DEFAULT_JSON = "{ \"amiibo\": [] }";
|
||||
|
||||
public string AmiiboId { get; private set; }
|
||||
|
@ -96,6 +47,8 @@ namespace Ryujinx.Ui.Windows
|
|||
|
||||
private List<AmiiboApi> _amiiboList;
|
||||
|
||||
private static readonly AmiiboJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
||||
|
||||
public AmiiboWindow() : base($"Ryujinx {Program.Version} - Amiibo")
|
||||
{
|
||||
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png");
|
||||
|
@ -127,9 +80,9 @@ namespace Ryujinx.Ui.Windows
|
|||
|
||||
if (File.Exists(_amiiboJsonPath))
|
||||
{
|
||||
amiiboJsonString = File.ReadAllText(_amiiboJsonPath);
|
||||
amiiboJsonString = await File.ReadAllTextAsync(_amiiboJsonPath);
|
||||
|
||||
if (await NeedsUpdate(JsonHelper.Deserialize<AmiiboJson>(amiiboJsonString).LastUpdated))
|
||||
if (await NeedsUpdate(JsonHelper.Deserialize(amiiboJsonString, SerializerContext.AmiiboJson).LastUpdated))
|
||||
{
|
||||
amiiboJsonString = await DownloadAmiiboJson();
|
||||
}
|
||||
|
@ -148,7 +101,7 @@ namespace Ryujinx.Ui.Windows
|
|||
}
|
||||
}
|
||||
|
||||
_amiiboList = JsonHelper.Deserialize<AmiiboJson>(amiiboJsonString).Amiibo;
|
||||
_amiiboList = JsonHelper.Deserialize(amiiboJsonString, SerializerContext.AmiiboJson).Amiibo;
|
||||
_amiiboList = _amiiboList.OrderBy(amiibo => amiibo.AmiiboSeries).ToList();
|
||||
|
||||
if (LastScannedAmiiboShowAll)
|
||||
|
|
|
@ -115,6 +115,8 @@ namespace Ryujinx.Ui.Windows
|
|||
private bool _mousePressed;
|
||||
private bool _middleMousePressed;
|
||||
|
||||
private static readonly InputConfigJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
||||
|
||||
public ControllerWindow(MainWindow mainWindow, PlayerIndex controllerId) : this(mainWindow, new Builder("Ryujinx.Ui.Windows.ControllerWindow.glade"), controllerId) { }
|
||||
|
||||
private ControllerWindow(MainWindow mainWindow, Builder builder, PlayerIndex controllerId) : base(builder.GetRawOwnedObject("_controllerWin"))
|
||||
|
@ -1120,10 +1122,7 @@ namespace Ryujinx.Ui.Windows
|
|||
|
||||
try
|
||||
{
|
||||
using (Stream stream = File.OpenRead(path))
|
||||
{
|
||||
config = JsonHelper.Deserialize<InputConfig>(stream);
|
||||
}
|
||||
config = JsonHelper.DeserializeFromFile(path, SerializerContext.InputConfig);
|
||||
}
|
||||
catch (JsonException) { }
|
||||
}
|
||||
|
@ -1145,9 +1144,7 @@ namespace Ryujinx.Ui.Windows
|
|||
if (profileDialog.Run() == (int)ResponseType.Ok)
|
||||
{
|
||||
string path = System.IO.Path.Combine(GetProfileBasePath(), profileDialog.FileName);
|
||||
string jsonString;
|
||||
|
||||
jsonString = JsonHelper.Serialize(inputConfig, true);
|
||||
string jsonString = JsonHelper.Serialize(inputConfig, SerializerContext.InputConfig);
|
||||
|
||||
File.WriteAllText(path, jsonString);
|
||||
}
|
||||
|
|
|
@ -7,15 +7,13 @@ using LibHac.Tools.Fs;
|
|||
using LibHac.Tools.FsSystem;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.Ui.Widgets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using GUI = Gtk.Builder.ObjectAttribute;
|
||||
using JsonHelper = Ryujinx.Common.Utilities.JsonHelper;
|
||||
using GUI = Gtk.Builder.ObjectAttribute;
|
||||
|
||||
namespace Ryujinx.Ui.Windows
|
||||
{
|
||||
|
@ -26,6 +24,8 @@ namespace Ryujinx.Ui.Windows
|
|||
private readonly string _dlcJsonPath;
|
||||
private readonly List<DownloadableContentContainer> _dlcContainerList;
|
||||
|
||||
private static readonly DownloadableContentJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
||||
|
||||
#pragma warning disable CS0649, IDE0044
|
||||
[GUI] Label _baseTitleInfoLabel;
|
||||
[GUI] TreeView _dlcTreeView;
|
||||
|
@ -45,7 +45,7 @@ namespace Ryujinx.Ui.Windows
|
|||
|
||||
try
|
||||
{
|
||||
_dlcContainerList = JsonHelper.DeserializeFromFile<List<DownloadableContentContainer>>(_dlcJsonPath);
|
||||
_dlcContainerList = JsonHelper.DeserializeFromFile(_dlcJsonPath, SerializerContext.ListDownloadableContentContainer);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -260,10 +260,7 @@ namespace Ryujinx.Ui.Windows
|
|||
while (_dlcTreeView.Model.IterNext(ref parentIter));
|
||||
}
|
||||
|
||||
using (FileStream dlcJsonStream = File.Create(_dlcJsonPath, 4096, FileOptions.WriteThrough))
|
||||
{
|
||||
dlcJsonStream.Write(Encoding.UTF8.GetBytes(JsonHelper.Serialize(_dlcContainerList, true)));
|
||||
}
|
||||
JsonHelper.SerializeToFile(_dlcJsonPath, _dlcContainerList, SerializerContext.ListDownloadableContentContainer);
|
||||
|
||||
Dispose();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ using LibHac.Ns;
|
|||
using LibHac.Tools.FsSystem;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.HLE.HOS;
|
||||
using Ryujinx.Ui.Widgets;
|
||||
|
@ -14,10 +15,8 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using GUI = Gtk.Builder.ObjectAttribute;
|
||||
using JsonHelper = Ryujinx.Common.Utilities.JsonHelper;
|
||||
using GUI = Gtk.Builder.ObjectAttribute;
|
||||
using SpanHelpers = LibHac.Common.SpanHelpers;
|
||||
|
||||
namespace Ryujinx.Ui.Windows
|
||||
{
|
||||
|
@ -31,6 +30,7 @@ namespace Ryujinx.Ui.Windows
|
|||
private TitleUpdateMetadata _titleUpdateWindowData;
|
||||
|
||||
private readonly Dictionary<RadioButton, string> _radioButtonToPathDictionary;
|
||||
private static readonly TitleUpdateMetadataJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
||||
|
||||
#pragma warning disable CS0649, IDE0044
|
||||
[GUI] Label _baseTitleInfoLabel;
|
||||
|
@ -53,7 +53,7 @@ namespace Ryujinx.Ui.Windows
|
|||
|
||||
try
|
||||
{
|
||||
_titleUpdateWindowData = JsonHelper.DeserializeFromFile<TitleUpdateMetadata>(_updateJsonPath);
|
||||
_titleUpdateWindowData = JsonHelper.DeserializeFromFile(_updateJsonPath, SerializerContext.TitleUpdateMetadata);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -192,10 +192,7 @@ namespace Ryujinx.Ui.Windows
|
|||
}
|
||||
}
|
||||
|
||||
using (FileStream dlcJsonStream = File.Create(_updateJsonPath, 4096, FileOptions.WriteThrough))
|
||||
{
|
||||
dlcJsonStream.Write(Encoding.UTF8.GetBytes(JsonHelper.Serialize(_titleUpdateWindowData, true)));
|
||||
}
|
||||
JsonHelper.SerializeToFile(_updateJsonPath, _titleUpdateWindowData, SerializerContext.TitleUpdateMetadata);
|
||||
|
||||
_parent.UpdateGameTable();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue