mirror of
https://github.com/GreemDev/Ryujinx
synced 2024-11-24 10:46:54 +01:00
misc: Abstract repeated logic in markup extensions & move Updater into the base of the Avalonia project.
This commit is contained in:
parent
4c83794254
commit
1c07bf3dd0
10 changed files with 52 additions and 74 deletions
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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()
|
39
src/Ryujinx/Common/Markup/MarkupExtensions.cs
Normal file
39
src/Ryujinx/Common/Markup/MarkupExtensions.cs
Normal 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)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
{
|
Loading…
Reference in a new issue