misc: Abstract repeated logic in markup extensions & move Updater into the base of the Avalonia project.

This commit is contained in:
Evan Husted 2024-11-01 15:48:25 -05:00
parent 4c83794254
commit 1c07bf3dd0
10 changed files with 52 additions and 74 deletions

View File

@ -17,29 +17,19 @@ namespace Ryujinx.Common.Utilities
/// It is REQUIRED for you to save returned options statically or as a part of static serializer context
/// in order to avoid performance issues. You can safely modify returned options for your case before storing.
/// </remarks>
public static JsonSerializerOptions GetDefaultSerializerOptions(bool indented = true)
{
JsonSerializerOptions options = new()
public static JsonSerializerOptions GetDefaultSerializerOptions(bool indented = true) =>
new()
{
DictionaryKeyPolicy = _snakeCasePolicy,
PropertyNamingPolicy = _snakeCasePolicy,
WriteIndented = indented,
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip,
ReadCommentHandling = JsonCommentHandling.Skip
};
return options;
}
public static string Serialize<T>(T value, JsonTypeInfo<T> typeInfo) => JsonSerializer.Serialize(value, typeInfo);
public static string Serialize<T>(T value, JsonTypeInfo<T> typeInfo)
{
return JsonSerializer.Serialize(value, typeInfo);
}
public static T Deserialize<T>(string value, JsonTypeInfo<T> typeInfo)
{
return JsonSerializer.Deserialize(value, typeInfo);
}
public static T Deserialize<T>(string value, JsonTypeInfo<T> typeInfo) => JsonSerializer.Deserialize(value, typeInfo);
public static void SerializeToFile<T>(string filePath, T value, JsonTypeInfo<T> typeInfo)
{
@ -53,10 +43,7 @@ namespace Ryujinx.Common.Utilities
return JsonSerializer.Deserialize(file, typeInfo);
}
public static void SerializeToStream<T>(Stream stream, T value, JsonTypeInfo<T> typeInfo)
{
JsonSerializer.Serialize(stream, value, typeInfo);
}
public static void SerializeToStream<T>(Stream stream, T value, JsonTypeInfo<T> typeInfo) => JsonSerializer.Serialize(stream, value, typeInfo);
private class SnakeCaseNamingPolicy : JsonNamingPolicy
{

View File

@ -1,4 +1,4 @@
using Avalonia.Data.Core;
using Avalonia.Data.Core;
using Avalonia.Markup.Xaml;
using Avalonia.Markup.Xaml.MarkupExtensions;
using Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings;
@ -6,16 +6,10 @@ using System;
namespace Ryujinx.Ava.Common.Markup
{
internal class IconExtension(string iconString) : MarkupExtension
internal abstract class BasicMarkupExtension : MarkupExtension
{
private ClrPropertyInfo PropertyInfo
=> new(
"Item",
_ => new Projektanker.Icons.Avalonia.Icon { Value = iconString },
null,
typeof(Projektanker.Icons.Avalonia.Icon)
);
protected abstract ClrPropertyInfo PropertyInfo { get; }
public override object ProvideValue(IServiceProvider serviceProvider) =>
new CompiledBindingExtension(
new CompiledBindingPathBuilder()

View File

@ -0,0 +1,39 @@
using Avalonia.Data.Core;
using Projektanker.Icons.Avalonia;
using Ryujinx.Ava.Common.Locale;
namespace Ryujinx.Ava.Common.Markup
{
internal class IconExtension(string iconString) : BasicMarkupExtension
{
protected override ClrPropertyInfo PropertyInfo
=> new(
"Item",
_ => new Icon { Value = iconString },
null,
typeof(Icon)
);
}
internal class SpinningIconExtension(string iconString) : BasicMarkupExtension
{
protected override ClrPropertyInfo PropertyInfo
=> new(
"Item",
_ => new Icon { Value = iconString, Animation = IconAnimation.Spin },
null,
typeof(Icon)
);
}
internal class LocaleExtension(LocaleKeys key) : BasicMarkupExtension
{
protected override ClrPropertyInfo PropertyInfo
=> new(
"Item",
_ => LocaleManager.Instance[key],
null,
typeof(string)
);
}
}

View File

@ -1,29 +0,0 @@
using Avalonia.Data.Core;
using Avalonia.Markup.Xaml;
using Avalonia.Markup.Xaml.MarkupExtensions;
using Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings;
using Ryujinx.Ava.Common.Locale;
using System;
namespace Ryujinx.Ava.Common.Markup
{
internal class LocaleExtension(LocaleKeys key) : MarkupExtension
{
private ClrPropertyInfo PropertyInfo
=> new(
"Item",
_ => LocaleManager.Instance[key],
null,
typeof(string)
);
public override object ProvideValue(IServiceProvider serviceProvider) =>
new CompiledBindingExtension(
new CompiledBindingPathBuilder()
.Property(PropertyInfo, PropertyInfoAccessorFactory.CreateInpcPropertyAccessor)
.Build()
)
{ Source = LocaleManager.Instance }
.ProvideValue(serviceProvider);
}
}

View File

@ -14,7 +14,6 @@ using Ryujinx.Common.GraphicsDriver;
using Ryujinx.Common.Logging;
using Ryujinx.Common.SystemInterop;
using Ryujinx.Graphics.Vulkan.MoltenVK;
using Ryujinx.Modules;
using Ryujinx.SDL2.Common;
using Ryujinx.UI.App.Common;
using Ryujinx.UI.Common;
@ -46,8 +45,7 @@ namespace Ryujinx.Ava
public static int Main(string[] args)
{
Version = ReleaseInformation.Version;
if (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134))
{
_ = MessageBoxA(nint.Zero, "You are running an outdated version of Windows.\n\nRyujinx supports Windows 10 version 1803 and newer.\n", $"Ryujinx {Version}", MbIconwarning);

View File

@ -55,14 +55,7 @@
VerticalAlignment="Stretch"
ClipToBounds="True"
CornerRadius="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Grid ColumnDefinitions="Auto,10,*,150,100">
<Image
Grid.RowSpan="3"
Grid.Column="0"

View File

@ -29,7 +29,6 @@ using Ryujinx.HLE.HOS;
using Ryujinx.HLE.HOS.Services.Account.Acc;
using Ryujinx.HLE.UI;
using Ryujinx.Input.HLE;
using Ryujinx.Modules;
using Ryujinx.UI.App.Common;
using Ryujinx.UI.Common;
using Ryujinx.UI.Common.Configuration;

View File

@ -11,7 +11,6 @@ using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Ava.UI.Windows;
using Ryujinx.Common;
using Ryujinx.Common.Utilities;
using Ryujinx.Modules;
using Ryujinx.UI.App.Common;
using Ryujinx.UI.Common;
using Ryujinx.UI.Common.Configuration;

View File

@ -22,7 +22,6 @@ using Ryujinx.HLE.HOS;
using Ryujinx.HLE.HOS.Services.Account.Acc;
using Ryujinx.Input.HLE;
using Ryujinx.Input.SDL2;
using Ryujinx.Modules;
using Ryujinx.UI.App.Common;
using Ryujinx.UI.Common;
using Ryujinx.UI.Common.Configuration;

View File

@ -5,7 +5,6 @@ using Gommon;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
using ICSharpCode.SharpZipLib.Zip;
using Ryujinx.Ava;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Common;
@ -28,7 +27,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Ryujinx.Modules
namespace Ryujinx.Ava
{
internal static class Updater
{