0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2024-12-22 07:35:47 +00:00

misc: Code cleanup

This commit is contained in:
Evan Husted 2024-10-25 08:34:50 -05:00
parent c69904afc6
commit 281be7ca62
19 changed files with 136 additions and 156 deletions

View file

@ -3,9 +3,13 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FSimpleTypes/@EntryIndexedValue">WARNING</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FSimpleTypes/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseExplicitType</s:String> <s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseExplicitType</s:String> <s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="I" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GL/@EntryIndexedValue">GL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SDL/@EntryIndexedValue">SDL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SDL/@EntryIndexedValue">OS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="I" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0b4bc4d_002Dd13b_002D4a37_002Db37e_002Dc9c6864e4302/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"&gt;&lt;ElementKinds&gt;&lt;Kind Name="NAMESPACE" /&gt;&lt;Kind Name="CLASS" /&gt;&lt;Kind Name="STRUCT" /&gt;&lt;Kind Name="ENUM" /&gt;&lt;Kind Name="DELEGATE" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="I" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0b4bc4d_002Dd13b_002D4a37_002Db37e_002Dc9c6864e4302/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"&gt;&lt;ElementKinds&gt;&lt;Kind Name="NAMESPACE" /&gt;&lt;Kind Name="CLASS" /&gt;&lt;Kind Name="STRUCT" /&gt;&lt;Kind Name="ENUM" /&gt;&lt;Kind Name="DELEGATE" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="I" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=amiibo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ASET/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=ASET/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Astc/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Astc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Luma/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Luma/@EntryIndexedValue">True</s:Boolean>
@ -20,4 +24,4 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Spirv/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Spirv/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Srgb/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Srgb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unorm/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Unorm/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary> </wpf:ResourceDictionary>

View file

@ -98,7 +98,7 @@ namespace Ryujinx.Common.Configuration
if (IsPathSymlink(BaseDirPath)) if (IsPathSymlink(BaseDirPath))
{ {
Logger.Warning?.Print(LogClass.Application, $"Application data directory is a symlink. This may be unintended."); Logger.Warning?.Print(LogClass.Application, "Application data directory is a symlink. This may be unintended.");
} }
SetupBasePaths(); SetupBasePaths();

View file

@ -212,9 +212,7 @@ namespace Ryujinx.Common.Logging
foreach (var log in logs) foreach (var log in logs)
{ {
if (log.HasValue) if (log.HasValue)
{
levels.Add(log.Value.Level); levels.Add(log.Value.Level);
}
} }
return levels; return levels;
@ -233,6 +231,7 @@ namespace Ryujinx.Common.Logging
case LogLevel.AccessLog : AccessLog = enabled ? new Log(LogLevel.AccessLog) : new Log?(); break; case LogLevel.AccessLog : AccessLog = enabled ? new Log(LogLevel.AccessLog) : new Log?(); break;
case LogLevel.Stub : Stub = enabled ? new Log(LogLevel.Stub) : new Log?(); break; case LogLevel.Stub : Stub = enabled ? new Log(LogLevel.Stub) : new Log?(); break;
case LogLevel.Trace : Trace = enabled ? new Log(LogLevel.Trace) : new Log?(); break; case LogLevel.Trace : Trace = enabled ? new Log(LogLevel.Trace) : new Log?(); break;
case LogLevel.Notice : break;
default: throw new ArgumentException("Unknown Log Level", nameof(logLevel)); default: throw new ArgumentException("Unknown Log Level", nameof(logLevel));
#pragma warning restore IDE0055 #pragma warning restore IDE0055
} }

View file

@ -469,7 +469,7 @@ namespace Ryujinx.Cpu.Jit
{ {
if (size == 0) if (size == 0)
{ {
return Enumerable.Empty<MemoryRange>(); return [];
} }
return GetPhysicalRegionsImpl(va, size); return GetPhysicalRegionsImpl(va, size);

View file

@ -12,6 +12,6 @@
</Application.Resources> </Application.Resources>
<Application.Styles> <Application.Styles>
<sty:FluentAvaloniaTheme PreferSystemTheme="False" /> <sty:FluentAvaloniaTheme PreferSystemTheme="False" />
<StyleInclude Source="/Assets/Styles/Styles.xaml"/> <StyleInclude Source="/Assets/Styles/Styles.xaml" />
</Application.Styles> </Application.Styles>
</Application> </Application>

View file

@ -66,11 +66,6 @@ namespace Ryujinx.Ava
} }
} }
private void CustomThemeChanged_Event(object sender, ReactiveEventArgs<bool> e)
{
ApplyConfiguredTheme();
}
private void ShowRestartDialog() private void ShowRestartDialog()
{ {
_ = Dispatcher.UIThread.InvokeAsync(async () => _ = Dispatcher.UIThread.InvokeAsync(async () =>
@ -93,11 +88,10 @@ namespace Ryujinx.Ava
} }
}); });
} }
private void CustomThemeChanged_Event(object _, ReactiveEventArgs<bool> __) => ApplyConfiguredTheme();
private void ThemeChanged_Event(object sender, ReactiveEventArgs<string> e) private void ThemeChanged_Event(object _, ReactiveEventArgs<string> __) => ApplyConfiguredTheme();
{
ApplyConfiguredTheme();
}
public void ApplyConfiguredTheme() public void ApplyConfiguredTheme()
{ {

View file

@ -57,7 +57,6 @@ using Key = Ryujinx.Input.Key;
using MouseButton = Ryujinx.Input.MouseButton; using MouseButton = Ryujinx.Input.MouseButton;
using ScalingFilter = Ryujinx.Common.Configuration.ScalingFilter; using ScalingFilter = Ryujinx.Common.Configuration.ScalingFilter;
using Size = Avalonia.Size; using Size = Avalonia.Size;
using Switch = Ryujinx.HLE.Switch;
namespace Ryujinx.Ava namespace Ryujinx.Ava
{ {
@ -130,7 +129,7 @@ namespace Ryujinx.Ava
public ContentManager ContentManager { get; } public ContentManager ContentManager { get; }
public NpadManager NpadManager { get; } public NpadManager NpadManager { get; }
public TouchScreenManager TouchScreenManager { get; } public TouchScreenManager TouchScreenManager { get; }
public Switch Device { get; set; } public HLE.Switch Device { get; set; }
public int Width { get; private set; } public int Width { get; private set; }
public int Height { get; private set; } public int Height { get; private set; }
@ -849,7 +848,7 @@ namespace Ryujinx.Ava
// Initialize Configuration. // Initialize Configuration.
var memoryConfiguration = ConfigurationState.Instance.System.DramSize.Value; var memoryConfiguration = ConfigurationState.Instance.System.DramSize.Value;
Device = new Switch(new HLEConfiguration( Device = new HLE.Switch(new HLEConfiguration(
VirtualFileSystem, VirtualFileSystem,
_viewModel.LibHacHorizonManager, _viewModel.LibHacHorizonManager,
ContentManager, ContentManager,

View file

@ -99,6 +99,9 @@ namespace Ryujinx.Ava.Common.Locale
_ => false _ => false
}; };
public static string FormatDynamicValue(LocaleKeys key, params object[] values)
=> Instance.UpdateAndGetDynamicValue(key, values);
public string UpdateAndGetDynamicValue(LocaleKeys key, params object[] values) public string UpdateAndGetDynamicValue(LocaleKeys key, params object[] values)
{ {
_dynamicValues[key] = values; _dynamicValues[key] = values;
@ -127,9 +130,9 @@ namespace Ryujinx.Ava.Common.Locale
_localeLanguageCode = languageCode; _localeLanguageCode = languageCode;
} }
foreach (var item in locale) foreach ((LocaleKeys key, string val) in locale)
{ {
_localeStrings[item.Key] = item.Value; _localeStrings[key] = val;
} }
OnPropertyChanged("Item"); OnPropertyChanged("Item");
@ -150,11 +153,11 @@ namespace Ryujinx.Ava.Common.Locale
var strings = JsonHelper.Deserialize(languageJson, CommonJsonContext.Default.StringDictionary); var strings = JsonHelper.Deserialize(languageJson, CommonJsonContext.Default.StringDictionary);
foreach (var item in strings) foreach ((string key, string val) in strings)
{ {
if (Enum.TryParse<LocaleKeys>(item.Key, out var key)) if (Enum.TryParse<LocaleKeys>(key, out var localeKey))
{ {
localeStrings[key] = item.Value; localeStrings[localeKey] = val;
} }
} }

View file

@ -1,7 +1,7 @@
using ARMeilleure;
using Avalonia; using Avalonia;
using Avalonia.Threading; using Avalonia.Threading;
using DiscordRPC; using DiscordRPC;
using Gommon;
using Projektanker.Icons.Avalonia; using Projektanker.Icons.Avalonia;
using Projektanker.Icons.Avalonia.FontAwesome; using Projektanker.Icons.Avalonia.FontAwesome;
using Projektanker.Icons.Avalonia.MaterialDesign; using Projektanker.Icons.Avalonia.MaterialDesign;
@ -23,6 +23,7 @@ using Ryujinx.UI.Common.Helper;
using Ryujinx.UI.Common.SystemInfo; using Ryujinx.UI.Common.SystemInfo;
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -103,8 +104,9 @@ namespace Ryujinx.Ava
Console.Title = $"Ryujinx Console {Version}"; Console.Title = $"Ryujinx Console {Version}";
// Hook unhandled exception and process exit events. // Hook unhandled exception and process exit events.
AppDomain.CurrentDomain.UnhandledException += (sender, e) => ProcessUnhandledException(e.ExceptionObject as Exception, e.IsTerminating); AppDomain.CurrentDomain.UnhandledException += (sender, e)
AppDomain.CurrentDomain.ProcessExit += (sender, e) => Exit(); => ProcessUnhandledException(sender, e.ExceptionObject as Exception, e.IsTerminating);
AppDomain.CurrentDomain.ProcessExit += (_, _) => Exit();
// Setup base data directory. // Setup base data directory.
AppDataManager.Initialize(CommandLineState.BaseDirPathArg); AppDataManager.Initialize(CommandLineState.BaseDirPathArg);
@ -189,7 +191,7 @@ namespace Ryujinx.Ava
} }
} }
UseHardwareAcceleration = ConfigurationState.Instance.EnableHardwareAcceleration.Value; UseHardwareAcceleration = ConfigurationState.Instance.EnableHardwareAcceleration;
// Check if graphics backend was overridden // Check if graphics backend was overridden
if (CommandLineState.OverrideGraphicsBackend is not null) if (CommandLineState.OverrideGraphicsBackend is not null)
@ -226,7 +228,13 @@ namespace Ryujinx.Ava
Logger.Notice.Print(LogClass.Application, $"Ryujinx Version: {Version}"); Logger.Notice.Print(LogClass.Application, $"Ryujinx Version: {Version}");
SystemInfo.Gather().Print(); SystemInfo.Gather().Print();
Logger.Notice.Print(LogClass.Application, $"Logs Enabled: {(Logger.GetEnabledLevels().Count == 0 ? "<None>" : string.Join(", ", Logger.GetEnabledLevels()))}"); var enabledLogLevels = Logger.GetEnabledLevels().ToArray();
Logger.Notice.Print(LogClass.Application, $"Logs Enabled: {
(enabledLogLevels.Length is 0
? "<None>"
: enabledLogLevels.JoinToString(", "))
}");
Logger.Notice.Print(LogClass.Application, Logger.Notice.Print(LogClass.Application,
AppDataManager.Mode == AppDataManager.LaunchMode.Custom AppDataManager.Mode == AppDataManager.LaunchMode.Custom
@ -234,21 +242,19 @@ namespace Ryujinx.Ava
: $"Launch Mode: {AppDataManager.Mode}"); : $"Launch Mode: {AppDataManager.Mode}");
} }
private static void ProcessUnhandledException(Exception ex, bool isTerminating) private static void ProcessUnhandledException(object sender, Exception ex, bool isTerminating)
{ {
Logger.Log log = Logger.Error ?? Logger.Notice;
string message = $"Unhandled exception caught: {ex}"; string message = $"Unhandled exception caught: {ex}";
Logger.Error?.PrintMsg(LogClass.Application, message); // ReSharper disable once ConstantConditionalAccessQualifier
if (sender?.GetType()?.AsPrettyString() is {} senderName)
if (Logger.Error == null) log.Print(LogClass.Application, message, senderName);
{ else
Logger.Notice.PrintMsg(LogClass.Application, message); log.PrintMsg(LogClass.Application, message);
}
if (isTerminating) if (isTerminating)
{
Exit(); Exit();
}
} }
public static void Exit() public static void Exit()

View file

@ -31,15 +31,11 @@ namespace Ryujinx.Ava.UI.Applet
public bool DisplayMessageDialog(ControllerAppletUIArgs args) public bool DisplayMessageDialog(ControllerAppletUIArgs args)
{ {
ManualResetEvent dialogCloseEvent = new(false); ManualResetEvent dialogCloseEvent = new(false);
bool ignoreApplet = ConfigurationState.Instance.IgnoreApplet;
bool okPressed = false; bool okPressed = false;
if (ignoreApplet) if (ConfigurationState.Instance.IgnoreApplet)
{
return false; return false;
}
Dispatcher.UIThread.InvokeAsync(async () => Dispatcher.UIThread.InvokeAsync(async () =>
{ {
@ -74,9 +70,9 @@ namespace Ryujinx.Ava.UI.Applet
UserResult response = await ContentDialogHelper.ShowDeferredContentDialog(_parent, UserResult response = await ContentDialogHelper.ShowDeferredContentDialog(_parent,
title, title,
message, message,
"", string.Empty,
LocaleManager.Instance[LocaleKeys.DialogOpenSettingsWindowLabel], LocaleManager.Instance[LocaleKeys.DialogOpenSettingsWindowLabel],
"", string.Empty,
LocaleManager.Instance[LocaleKeys.SettingsButtonClose], LocaleManager.Instance[LocaleKeys.SettingsButtonClose],
(int)Symbol.Important, (int)Symbol.Important,
deferEvent, deferEvent,
@ -179,12 +175,12 @@ namespace Ryujinx.Ava.UI.Applet
{ {
Title = title, Title = title,
WindowStartupLocation = WindowStartupLocation.CenterScreen, WindowStartupLocation = WindowStartupLocation.CenterScreen,
Width = 400, Width = 400
}; };
object response = await msgDialog.Run(); object response = await msgDialog.Run();
if (response != null && buttons != null && buttons.Length > 1 && (int)response != buttons.Length - 1) if (response != null && buttons is { Length: > 1 } && (int)response != buttons.Length - 1)
{ {
showDetails = true; showDetails = true;
} }

View file

@ -24,10 +24,13 @@ namespace Ryujinx.Ava.UI.Applet
public AvaloniaDynamicTextInputHandler(MainWindow parent) public AvaloniaDynamicTextInputHandler(MainWindow parent)
{ {
_parent = parent; _parent = parent;
(_parent.InputManager.KeyboardDriver as AvaloniaKeyboardDriver).KeyPressed += AvaloniaDynamicTextInputHandler_KeyPressed; if (_parent.InputManager.KeyboardDriver is AvaloniaKeyboardDriver avaloniaKeyboardDriver)
(_parent.InputManager.KeyboardDriver as AvaloniaKeyboardDriver).KeyRelease += AvaloniaDynamicTextInputHandler_KeyRelease; {
(_parent.InputManager.KeyboardDriver as AvaloniaKeyboardDriver).TextInput += AvaloniaDynamicTextInputHandler_TextInput; avaloniaKeyboardDriver.KeyPressed += AvaloniaDynamicTextInputHandler_KeyPressed;
avaloniaKeyboardDriver.KeyRelease += AvaloniaDynamicTextInputHandler_KeyRelease;
avaloniaKeyboardDriver.TextInput += AvaloniaDynamicTextInputHandler_TextInput;
}
_hiddenTextBox = _parent.HiddenTextBox; _hiddenTextBox = _parent.HiddenTextBox;
@ -44,7 +47,7 @@ namespace Ryujinx.Ava.UI.Applet
TextChangedEvent?.Invoke(text ?? string.Empty, _hiddenTextBox.SelectionStart, _hiddenTextBox.SelectionEnd, false); TextChangedEvent?.Invoke(text ?? string.Empty, _hiddenTextBox.SelectionStart, _hiddenTextBox.SelectionEnd, false);
} }
private void SelectionChanged(int selection) private void SelectionChanged(int _)
{ {
TextChangedEvent?.Invoke(_hiddenTextBox.Text ?? string.Empty, _hiddenTextBox.SelectionStart, _hiddenTextBox.SelectionEnd, false); TextChangedEvent?.Invoke(_hiddenTextBox.Text ?? string.Empty, _hiddenTextBox.SelectionStart, _hiddenTextBox.SelectionEnd, false);
} }
@ -112,10 +115,13 @@ namespace Ryujinx.Ava.UI.Applet
public void Dispose() public void Dispose()
{ {
(_parent.InputManager.KeyboardDriver as AvaloniaKeyboardDriver).KeyPressed -= AvaloniaDynamicTextInputHandler_KeyPressed; if (_parent.InputManager.KeyboardDriver is AvaloniaKeyboardDriver avaloniaKeyboardDriver)
(_parent.InputManager.KeyboardDriver as AvaloniaKeyboardDriver).KeyRelease -= AvaloniaDynamicTextInputHandler_KeyRelease; {
(_parent.InputManager.KeyboardDriver as AvaloniaKeyboardDriver).TextInput -= AvaloniaDynamicTextInputHandler_TextInput; avaloniaKeyboardDriver.KeyPressed -= AvaloniaDynamicTextInputHandler_KeyPressed;
avaloniaKeyboardDriver.KeyRelease -= AvaloniaDynamicTextInputHandler_KeyRelease;
avaloniaKeyboardDriver.TextInput -= AvaloniaDynamicTextInputHandler_TextInput;
}
_textChangedSubscription?.Dispose(); _textChangedSubscription?.Dispose();
_selectionStartChangedSubscription?.Dispose(); _selectionStartChangedSubscription?.Dispose();
_selectionEndtextChangedSubscription?.Dispose(); _selectionEndtextChangedSubscription?.Dispose();

View file

@ -47,42 +47,37 @@ namespace Ryujinx.Ava.UI.Controls
LoadProfiles(); LoadProfiles();
if (contentManager.GetCurrentFirmwareVersion() != null) if (contentManager.GetCurrentFirmwareVersion() != null)
{ Task.Run(() => UserFirmwareAvatarSelectorViewModel.PreloadAvatars(contentManager, virtualFileSystem));
Task.Run(() =>
{
UserFirmwareAvatarSelectorViewModel.PreloadAvatars(contentManager, virtualFileSystem);
});
}
InitializeComponent(); InitializeComponent();
} }
public void GoBack() public void GoBack()
{ {
if (ContentFrame.BackStack.Count > 0) if (ContentFrame.BackStack.Count > 0)
{
ContentFrame.GoBack(); ContentFrame.GoBack();
}
LoadProfiles(); LoadProfiles();
} }
public void Navigate(Type sourcePageType, object parameter) public void Navigate(Type sourcePageType, object parameter)
{ => ContentFrame.Navigate(sourcePageType, parameter);
ContentFrame.Navigate(sourcePageType, parameter);
}
public static async Task Show(AccountManager ownerAccountManager, ContentManager ownerContentManager, public static async Task Show(
VirtualFileSystem ownerVirtualFileSystem, HorizonClient ownerHorizonClient) AccountManager ownerAccountManager,
ContentManager ownerContentManager,
VirtualFileSystem ownerVirtualFileSystem,
HorizonClient ownerHorizonClient)
{ {
var content = new NavigationDialogHost(ownerAccountManager, ownerContentManager, ownerVirtualFileSystem, ownerHorizonClient); var content = new NavigationDialogHost(ownerAccountManager, ownerContentManager, ownerVirtualFileSystem, ownerHorizonClient);
ContentDialog contentDialog = new() ContentDialog contentDialog = new()
{ {
Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle], Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle],
PrimaryButtonText = "", PrimaryButtonText = string.Empty,
SecondaryButtonText = "", SecondaryButtonText = string.Empty,
CloseButtonText = "", CloseButtonText = string.Empty,
Content = content, Content = content,
Padding = new Thickness(0), Padding = new Thickness(0)
}; };
contentDialog.Closed += (_, _) => content.ViewModel.Dispose(); contentDialog.Closed += (_, _) => content.ViewModel.Dispose();
@ -160,14 +155,14 @@ namespace Ryujinx.Ava.UI.Controls
if (profile == null) if (profile == null)
{ {
Dispatcher.UIThread.Post(Action);
return;
static async void Action() static async void Action()
{ {
await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogUserProfileDeletionWarningMessage]); await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogUserProfileDeletionWarningMessage]);
} }
Dispatcher.UIThread.Post(Action);
return;
} }
AccountManager.OpenUser(profile.UserId); AccountManager.OpenUser(profile.UserId);

View file

@ -42,7 +42,7 @@ namespace Ryujinx.Ava.UI.Helpers
PrimaryButtonCommand = MiniCommand.Create(() => PrimaryButtonCommand = MiniCommand.Create(() =>
{ {
result = primaryButtonResult; result = primaryButtonResult;
}), })
}; };
contentDialog.SecondaryButtonCommand = MiniCommand.Create(() => contentDialog.SecondaryButtonCommand = MiniCommand.Create(() =>

View file

@ -1,5 +1,6 @@
using Avalonia.Logging; using Avalonia.Logging;
using Avalonia.Utilities; using Avalonia.Utilities;
using Gommon;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using System; using System;
using System.Text; using System.Text;
@ -90,7 +91,7 @@ namespace Ryujinx.Ava.UI.Helpers
if (source != null) if (source != null)
{ {
result.Append(" ("); result.Append(" (");
result.Append(source.GetType().Name); result.Append(source.GetType().AsFullNamePrettyString());
result.Append(" #"); result.Append(" #");
result.Append(source.GetHashCode()); result.Append(source.GetHashCode());
result.Append(')'); result.Append(')');

View file

@ -35,7 +35,7 @@ namespace Ryujinx.Ava.UI.Helpers
{ {
Text = text, Text = text,
Source = this, Source = this,
RoutedEvent = TextInputEvent, RoutedEvent = TextInputEvent
}); });
} }
} }

View file

@ -9,20 +9,12 @@ namespace Ryujinx.Ava.UI.Helpers
{ {
public static TimeZoneConverter Instance = new(); public static TimeZoneConverter Instance = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ => value is TimeZone timeZone
if (value == null) ? $"{timeZone.UtcDifference} {timeZone.Location} {timeZone.Abbreviation}"
{ : null;
return null;
}
var timeZone = (TimeZone)value; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
return string.Format("{0} {1} {2}", timeZone.UtcDifference, timeZone.Location, timeZone.Abbreviation); => throw new NotImplementedException();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} }
} }

View file

@ -3,12 +3,12 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading; using Avalonia.Threading;
using DynamicData; using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;
using Gommon;
using LibHac.Common; using LibHac.Common;
using Ryujinx.Ava.Common; using Ryujinx.Ava.Common;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
@ -41,6 +41,7 @@ using System.Collections.ObjectModel;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Key = Ryujinx.Input.Key; using Key = Ryujinx.Input.Key;
@ -113,6 +114,9 @@ namespace Ryujinx.Ava.UI.ViewModels
public ApplicationData ListSelectedApplication; public ApplicationData ListSelectedApplication;
public ApplicationData GridSelectedApplication; public ApplicationData GridSelectedApplication;
public static readonly Bitmap IconBitmap =
new(Assembly.GetAssembly(typeof(ConfigurationState))!.GetManifestResourceStream("Ryujinx.UI.Common.Resources.Logo_Ryujinx.png")!);
public MainWindow Window { get; init; } public MainWindow Window { get; init; }
internal AppHost AppHost { get; set; } internal AppHost AppHost { get; set; }
@ -179,18 +183,16 @@ namespace Ryujinx.Ava.UI.ViewModels
_searchTimer?.Dispose(); _searchTimer?.Dispose();
_searchTimer = new Timer(TimerCallback, null, 1000, 0); _searchTimer = new Timer(_ =>
{
RefreshView();
_searchTimer.Dispose();
_searchTimer = null;
}, null, 1000, 0);
} }
} }
private void TimerCallback(object obj)
{
RefreshView();
_searchTimer.Dispose();
_searchTimer = null;
}
public bool CanUpdate public bool CanUpdate
{ {
get => _canUpdate && EnableNonGameRunningControls && Updater.CanUpdate(false); get => _canUpdate && EnableNonGameRunningControls && Updater.CanUpdate(false);
@ -978,29 +980,26 @@ namespace Ryujinx.Ava.UI.ViewModels
#region PrivateMethods #region PrivateMethods
private IComparer<ApplicationData> GetComparer() private static IComparer<ApplicationData> CreateComparer(bool ascending, Func<ApplicationData, IComparable> selector) =>
{ ascending
return SortMode switch ? SortExpressionComparer<ApplicationData>.Ascending(selector)
: SortExpressionComparer<ApplicationData>.Descending(selector);
private IComparer<ApplicationData> GetComparer()
=> SortMode switch
{ {
#pragma warning disable IDE0055 // Disable formatting #pragma warning disable IDE0055 // Disable formatting
ApplicationSort.Title => IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.Name) ApplicationSort.Title => CreateComparer(IsAscending, app => app.Name),
: SortExpressionComparer<ApplicationData>.Descending(app => app.Name), ApplicationSort.Developer => CreateComparer(IsAscending, app => app.Developer),
ApplicationSort.Developer => IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.Developer)
: SortExpressionComparer<ApplicationData>.Descending(app => app.Developer),
ApplicationSort.LastPlayed => new LastPlayedSortComparer(IsAscending), ApplicationSort.LastPlayed => new LastPlayedSortComparer(IsAscending),
ApplicationSort.TotalTimePlayed => new TimePlayedSortComparer(IsAscending), ApplicationSort.TotalTimePlayed => new TimePlayedSortComparer(IsAscending),
ApplicationSort.FileType => IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.FileExtension) ApplicationSort.FileType => CreateComparer(IsAscending, app => app.FileExtension),
: SortExpressionComparer<ApplicationData>.Descending(app => app.FileExtension), ApplicationSort.FileSize => CreateComparer(IsAscending, app => app.FileSize),
ApplicationSort.FileSize => IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.FileSize) ApplicationSort.Path => CreateComparer(IsAscending, app => app.Path),
: SortExpressionComparer<ApplicationData>.Descending(app => app.FileSize), ApplicationSort.Favorite => CreateComparer(IsAscending, app => new AppListFavoriteComparable(app)),
ApplicationSort.Path => IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.Path)
: SortExpressionComparer<ApplicationData>.Descending(app => app.Path),
ApplicationSort.Favorite => IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => new AppListFavoriteComparable(app))
: SortExpressionComparer<ApplicationData>.Descending(app => new AppListFavoriteComparable(app)),
_ => null, _ => null,
#pragma warning restore IDE0055 #pragma warning restore IDE0055
}; };
}
public void RefreshView() public void RefreshView()
{ {
@ -1125,7 +1124,7 @@ namespace Ryujinx.Ava.UI.ViewModels
} }
catch (MissingKeyException ex) catch (MissingKeyException ex)
{ {
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime)
{ {
Logger.Error?.Print(LogClass.Application, ex.ToString()); Logger.Error?.Print(LogClass.Application, ex.ToString());
@ -1260,8 +1259,10 @@ namespace Ryujinx.Ava.UI.ViewModels
GameStatusText = args.GameStatus; GameStatusText = args.GameStatus;
VolumeStatusText = args.VolumeStatus; VolumeStatusText = args.VolumeStatus;
FifoStatusText = args.FifoStatus; FifoStatusText = args.FifoStatus;
ShaderCountText = args.ShaderCount > 0 ? $"Compiling shaders: {args.ShaderCount}" : string.Empty;
ShowRightmostSeparator = !ShaderCountText.IsNullOrEmpty(); ShaderCountText = (ShowRightmostSeparator = args.ShaderCount > 0)
? $"{LocaleManager.Instance[LocaleKeys.CompilingShaders]}: {args.ShaderCount}"
: string.Empty;
ShowStatusSeparator = true; ShowStatusSeparator = true;
}); });
@ -1641,8 +1642,7 @@ namespace Ryujinx.Ava.UI.ViewModels
gameThread.Start(); gameThread.Start();
} }
public void SwitchToRenderer(bool startFullscreen) public void SwitchToRenderer(bool startFullscreen) =>
{
Dispatcher.UIThread.Post(() => Dispatcher.UIThread.Post(() =>
{ {
SwitchToGameControl(startFullscreen); SwitchToGameControl(startFullscreen);
@ -1651,15 +1651,9 @@ namespace Ryujinx.Ava.UI.ViewModels
RendererHostControl.Focus(); RendererHostControl.Focus();
}); });
}
public static void UpdateGameMetadata(string titleId) public static void UpdateGameMetadata(string titleId)
{ => ApplicationLibrary.LoadAndSaveMetaData(titleId, appMetadata => appMetadata.UpdatePostGame());
ApplicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
{
appMetadata.UpdatePostGame();
});
}
public void RefreshFirmwareStatus() public void RefreshFirmwareStatus()
{ {

View file

@ -287,11 +287,11 @@ namespace Ryujinx.Ava.UI.ViewModels
public SettingsViewModel() public SettingsViewModel()
{ {
GameDirectories = new AvaloniaList<string>(); GameDirectories = [];
AutoloadDirectories = new AvaloniaList<string>(); AutoloadDirectories = [];
TimeZones = new AvaloniaList<TimeZone>(); TimeZones = [];
AvailableGpus = new ObservableCollection<ComboBoxItem>(); AvailableGpus = [];
_validTzRegions = new List<string>(); _validTzRegions = [];
_networkInterfaces = new Dictionary<string, string>(); _networkInterfaces = new Dictionary<string, string>();
Task.Run(CheckSoundBackends); Task.Run(CheckSoundBackends);

View file

@ -21,10 +21,10 @@ namespace Ryujinx.Ava.UI.Windows
private readonly struct PaletteColor(int qck, byte r, byte g, byte b) private readonly struct PaletteColor(int qck, byte r, byte g, byte b)
{ {
public int Qck { get; } = qck; public int Qck => qck;
public byte R { get; } = r; public byte R => r;
public byte G { get; } = g; public byte G => g;
public byte B { get; } = b; public byte B => b;
} }
public static SKColor GetFilteredColor(SKBitmap image) public static SKColor GetFilteredColor(SKBitmap image)
@ -54,15 +54,6 @@ namespace Ryujinx.Ava.UI.Windows
var buffer = GetBuffer(image); var buffer = GetBuffer(image);
int w = image.Width;
int w8 = w << 8;
int h8 = image.Height << 8;
#pragma warning disable IDE0059 // Unnecessary assignment
int xStep = w8 / ColorsPerLine;
int yStep = h8 / ColorsPerLine;
#pragma warning restore IDE0059
int i = 0; int i = 0;
int maxHitCount = 0; int maxHitCount = 0;