From 7618ef134d7524278386e07b0a3ddc20e8a2edba Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Thu, 24 Oct 2024 14:10:10 -0500 Subject: [PATCH] misc: Code cleanups. --- .../Loaders/Processes/ProcessResult.cs | 4 +- src/Ryujinx.Headless.SDL2/Program.cs | 4 +- .../Configuration/ConfigurationState.cs | 4 +- .../DiscordIntegrationModule.cs | 21 +++++++-- src/Ryujinx/Common/ApplicationHelper.cs | 2 +- .../UI/Applet/ControllerAppletDialog.axaml.cs | 11 ++--- .../UI/Helpers/BitmapArrayValueConverter.cs | 22 +++++----- src/Ryujinx/UI/Helpers/ButtonKeyAssigner.cs | 6 +-- src/Ryujinx/UI/Helpers/GlyphValueConverter.cs | 21 +++------ .../UI/Helpers/LocalizedNeverConverter.cs | 44 ------------------- src/Ryujinx/UI/Models/StatusInitEventArgs.cs | 16 ------- .../UI/ViewModels/Input/InputViewModel.cs | 1 - src/Ryujinx/UI/Windows/IconColorPicker.cs | 2 +- 13 files changed, 45 insertions(+), 113 deletions(-) delete mode 100644 src/Ryujinx/UI/Helpers/LocalizedNeverConverter.cs delete mode 100644 src/Ryujinx/UI/Models/StatusInitEventArgs.cs diff --git a/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs b/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs index 1804d045c..10561a5a1 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs @@ -85,7 +85,9 @@ namespace Ryujinx.HLE.Loaders.Processes } // TODO: LibHac npdm currently doesn't support version field. - string version = ProgramId > 0x0100000000007FFF ? DisplayVersion : device.System.ContentManager.GetCurrentFirmwareVersion()?.VersionString ?? "?"; + string version = ProgramId > 0x0100000000007FFF + ? DisplayVersion + : device.System.ContentManager.GetCurrentFirmwareVersion()?.VersionString ?? "?"; Logger.Info?.Print(LogClass.Loader, $"Application Loaded: {Name} v{version} [{ProgramIdText}] [{(Is64Bit ? "64-bit" : "32-bit")}]"); diff --git a/src/Ryujinx.Headless.SDL2/Program.cs b/src/Ryujinx.Headless.SDL2/Program.cs index b8710d4de..b6ccb2ac4 100644 --- a/src/Ryujinx.Headless.SDL2/Program.cs +++ b/src/Ryujinx.Headless.SDL2/Program.cs @@ -119,12 +119,10 @@ namespace Ryujinx.Headless.SDL2 } } - IGamepad gamepad; + IGamepad gamepad = _inputManager.KeyboardDriver.GetGamepad(inputId); bool isKeyboard = true; - gamepad = _inputManager.KeyboardDriver.GetGamepad(inputId); - if (gamepad == null) { gamepad = _inputManager.GamepadDriver.GetGamepad(inputId); diff --git a/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs b/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs index dad4e7cea..f26a94bb7 100644 --- a/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs +++ b/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs @@ -325,12 +325,12 @@ namespace Ryujinx.UI.Common.Configuration public ReactiveObject EnableDockedMode { get; private set; } /// - /// Enables or disables profiled translation cache persistency + /// Enables or disables persistent profiled translation cache /// public ReactiveObject EnablePtc { get; private set; } /// - /// Enables or disables low-power profiled translation cache persistency loading + /// Enables or disables low-power persistent profiled translation cache loading /// public ReactiveObject EnableLowPowerPtc { get; private set; } diff --git a/src/Ryujinx.UI.Common/DiscordIntegrationModule.cs b/src/Ryujinx.UI.Common/DiscordIntegrationModule.cs index 420c8c0f5..0ddf08851 100644 --- a/src/Ryujinx.UI.Common/DiscordIntegrationModule.cs +++ b/src/Ryujinx.UI.Common/DiscordIntegrationModule.cs @@ -73,7 +73,7 @@ namespace Ryujinx.UI.Common { Assets = new Assets { - LargeImageKey = _discordGameAssetKeys.Contains(procRes.ProgramIdText.ToLower()) ? procRes.ProgramIdText : "game", + LargeImageKey = _discordGameAssetKeys.Contains(procRes.ProgramIdText) ? procRes.ProgramIdText : "game", LargeImageText = TruncateToByteLength($"{appMeta.Title} | {procRes.DisplayVersion}"), SmallImageKey = "ryujinx", SmallImageText = TruncateToByteLength(_description) @@ -121,8 +121,8 @@ namespace Ryujinx.UI.Common } private static readonly string[] _discordGameAssetKeys = - [ - "01002da013484000", // The Legend of Zelda: Skyward Sword HD +[ + "01002da013484000", // The Legend of Zelda: Skyward Sword HD "01007ef00011e000", // The Legend of Zelda: Breath of the Wild "0100f2c0115b6000", // The Legend of Zelda: Tears of the Kingdom "01008cf01baac000", // The Legend of Zelda: Echoes of Wisdom @@ -131,9 +131,15 @@ namespace Ryujinx.UI.Common "0100000000010000", // SUPER MARIO ODYSSEY "010015100b514000", // Super Mario Bros. Wonder "0100152000022000", // Mario Kart 8 Deluxe + "01006fe013472000", // Mario Party Superstars + "0100965017338000", // Super Mario Party Jamboree "010049900f546000", // Super Mario 3D All-Stars "010028600ebda000", // Super Mario 3D World + Bowser's Fury "0100ecd018ebe000", // Paper Mario: The Thousand-Year Door + "010019401051c000", // Mario Strikers League + "0100ea80032ea000", // Super Mario Bros. U Deluxe + "0100bc0018138000", // Super Mario RPG + "0100bde00862a000", // Mario Tennis Aces "010048701995e000", // Luigi's Mansion 2 HD "0100dca0064a6000", // Luigi's Mansion 3 @@ -148,15 +154,22 @@ namespace Ryujinx.UI.Common "0100d680194b2000", // Pikmin 2 "0100f4c009322000", // Pikmin 3 Deluxe "0100b7c00933a000", // Pikmin 4 + + "01004ad014bf0000", // Sonic Frontiers + + "01004d300c5ae000", // Kirby and the Forgotten Land + "01006b601380e000", // Kirby's Return to Dreamland Deluxe + "01007e3006dda000", // Kirby Star Allies "0100c2500fc20000", // Splatoon 3 "0100ba0018500000", // Splatoon 3: Splatfest World Premiere "01000a10041ea000", // The Elder Scrolls V: Skyrim "01007820196a6000", // Red Dead Redemption + "01008c8012920000", // Dying Light Platinum Edition "0100744001588000", // Cars 3: Driven to Win + "0100c1f0051b6000", // Donkey Kong Country: Tropical Freeze "01002b00111a2000", // Hyrule Warriors: Age of Calamity "01006f8002326000", // Animal Crossing: New Horizons - "01004d300c5ae000", // Kirby and the Forgotten Land "0100853015e86000", // No Man's Sky "01008d100d43e000", // Saints Row IV "0100de600beee000", // Saints Row: The Third - The Full Package diff --git a/src/Ryujinx/Common/ApplicationHelper.cs b/src/Ryujinx/Common/ApplicationHelper.cs index 4be9a1a01..43b69045c 100644 --- a/src/Ryujinx/Common/ApplicationHelper.cs +++ b/src/Ryujinx/Common/ApplicationHelper.cs @@ -68,7 +68,7 @@ namespace Ryujinx.Ava.Common Logger.Warning?.Print(LogClass.Application, "No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games."); } - Uid user = new((ulong)_accountManager.LastOpenedUser.UserId.High, (ulong)_accountManager.LastOpenedUser.UserId.Low); + Uid user = _accountManager.LastOpenedUser.UserId.ToLibHacUid(); result = _horizonClient.Fs.EnsureApplicationSaveData(out _, new ApplicationId(titleId), in control, in user); if (result.IsFailure()) diff --git a/src/Ryujinx/UI/Applet/ControllerAppletDialog.axaml.cs b/src/Ryujinx/UI/Applet/ControllerAppletDialog.axaml.cs index 6b999b1f4..de9d10ddd 100644 --- a/src/Ryujinx/UI/Applet/ControllerAppletDialog.axaml.cs +++ b/src/Ryujinx/UI/Applet/ControllerAppletDialog.axaml.cs @@ -37,14 +37,9 @@ namespace Ryujinx.Ava.UI.Applet public ControllerAppletDialog(MainWindow mainWindow, ControllerAppletUIArgs args) { - if (args.PlayerCountMin == args.PlayerCountMax) - { - PlayerCount = args.PlayerCountMin.ToString(); - } - else - { - PlayerCount = $"{args.PlayerCountMin} - {args.PlayerCountMax}"; - } + PlayerCount = args.PlayerCountMin == args.PlayerCountMax + ? args.PlayerCountMin.ToString() + : $"{args.PlayerCountMin} - {args.PlayerCountMax}"; SupportsProController = (args.SupportedStyles & ControllerType.ProController) != 0; SupportsLeftJoycon = (args.SupportedStyles & ControllerType.JoyconLeft) != 0; diff --git a/src/Ryujinx/UI/Helpers/BitmapArrayValueConverter.cs b/src/Ryujinx/UI/Helpers/BitmapArrayValueConverter.cs index 42bd8d5a8..7b599a48b 100644 --- a/src/Ryujinx/UI/Helpers/BitmapArrayValueConverter.cs +++ b/src/Ryujinx/UI/Helpers/BitmapArrayValueConverter.cs @@ -13,19 +13,19 @@ namespace Ryujinx.Ava.UI.Helpers public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value == null) + switch (value) { - return null; + case null: + return null; + case byte[] buffer when targetType == typeof(IImage): + { + MemoryStream mem = new(buffer); + + return new Bitmap(mem); + } + default: + throw new NotSupportedException(); } - - if (value is byte[] buffer && targetType == typeof(IImage)) - { - MemoryStream mem = new(buffer); - - return new Bitmap(mem); - } - - throw new NotSupportedException(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/src/Ryujinx/UI/Helpers/ButtonKeyAssigner.cs b/src/Ryujinx/UI/Helpers/ButtonKeyAssigner.cs index 4f2b8daae..2781a32b1 100644 --- a/src/Ryujinx/UI/Helpers/ButtonKeyAssigner.cs +++ b/src/Ryujinx/UI/Helpers/ButtonKeyAssigner.cs @@ -41,11 +41,7 @@ namespace Ryujinx.Ava.UI.Helpers if (_isWaitingForInput) { - Dispatcher.UIThread.Post(() => - { - Cancel(); - }); - + Dispatcher.UIThread.Post(() => Cancel()); return; } diff --git a/src/Ryujinx/UI/Helpers/GlyphValueConverter.cs b/src/Ryujinx/UI/Helpers/GlyphValueConverter.cs index 1544d33ae..94c3ab35d 100644 --- a/src/Ryujinx/UI/Helpers/GlyphValueConverter.cs +++ b/src/Ryujinx/UI/Helpers/GlyphValueConverter.cs @@ -22,22 +22,11 @@ namespace Ryujinx.Ava.UI.Helpers _key = key; } - public string this[string key] - { - get - { - if (_glyphs.TryGetValue(Enum.Parse(key), out var val)) - { - return val; - } + public string this[string key] => + _glyphs.TryGetValue(Enum.Parse(key), out var val) + ? val + : string.Empty; - return string.Empty; - } - } - - public override object ProvideValue(IServiceProvider serviceProvider) - { - return this[_key]; - } + public override object ProvideValue(IServiceProvider serviceProvider) => this[_key]; } } diff --git a/src/Ryujinx/UI/Helpers/LocalizedNeverConverter.cs b/src/Ryujinx/UI/Helpers/LocalizedNeverConverter.cs deleted file mode 100644 index 337404233..000000000 --- a/src/Ryujinx/UI/Helpers/LocalizedNeverConverter.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Avalonia.Data.Converters; -using Avalonia.Markup.Xaml; -using Ryujinx.Ava.Common.Locale; -using Ryujinx.UI.Common.Helper; -using System; -using System.Globalization; - -namespace Ryujinx.Ava.UI.Helpers -{ - /// - /// This makes sure that the string "Never" that's returned by is properly localized in the Avalonia UI. - /// After the Avalonia UI has been made the default and the GTK UI is removed, should be updated to directly return a localized string. - /// - // TODO: localize ValueFormatUtils.FormateDateTime - internal class LocalizedNeverConverter : MarkupExtension, IValueConverter - { - private static readonly LocalizedNeverConverter _instance = new(); - - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is not string valStr) - { - return ""; - } - - if (valStr == "Never") - { - return LocaleManager.Instance[LocaleKeys.Never]; - } - - return valStr; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - - public override object ProvideValue(IServiceProvider serviceProvider) - { - return _instance; - } - } -} diff --git a/src/Ryujinx/UI/Models/StatusInitEventArgs.cs b/src/Ryujinx/UI/Models/StatusInitEventArgs.cs deleted file mode 100644 index 4b08737e9..000000000 --- a/src/Ryujinx/UI/Models/StatusInitEventArgs.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace Ryujinx.Ava.UI.Models -{ - internal class StatusInitEventArgs : EventArgs - { - public string GpuBackend { get; } - public string GpuName { get; } - - public StatusInitEventArgs(string gpuBackend, string gpuName) - { - GpuBackend = gpuBackend; - GpuName = gpuName; - } - } -} diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index 3fb991531..c133f25fa 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -45,7 +45,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input private PlayerIndex _playerId; private int _controller; - private readonly int _controllerNumber; private string _controllerImage; private int _device; private object _configViewModel; diff --git a/src/Ryujinx/UI/Windows/IconColorPicker.cs b/src/Ryujinx/UI/Windows/IconColorPicker.cs index 7d6ef2138..088ab5116 100644 --- a/src/Ryujinx/UI/Windows/IconColorPicker.cs +++ b/src/Ryujinx/UI/Windows/IconColorPicker.cs @@ -139,7 +139,7 @@ namespace Ryujinx.Ava.UI.Windows var value = GetColorValue(color); // If the color is rarely used on the image, - // then chances are that theres a better candidate, even if the saturation value + // then chances are that there's a better candidate, even if the saturation value // is high. By multiplying the saturation value with a weight, we can lower // it if the color is almost never used (hit count is low). var satWeighted = quantSat;