From 5b6e3521d8b1c5a03e5216ece320a189b3051a98 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Fri, 11 Oct 2024 23:55:12 -0500 Subject: [PATCH] misc: More minor style changes. --- src/Ryujinx.Common/Logging/Logger.cs | 4 +-- src/Ryujinx/App.axaml.cs | 2 +- src/Ryujinx/Common/Locale/LocaleManager.cs | 24 ++++---------- src/Ryujinx/Program.cs | 28 ++++++---------- src/Ryujinx/UI/Windows/MainWindow.axaml.cs | 37 ++++++++-------------- src/Ryujinx/UI/Windows/StyleableWindow.cs | 4 +-- 6 files changed, 35 insertions(+), 64 deletions(-) diff --git a/src/Ryujinx.Common/Logging/Logger.cs b/src/Ryujinx.Common/Logging/Logger.cs index db46739ac..b689ccbde 100644 --- a/src/Ryujinx.Common/Logging/Logger.cs +++ b/src/Ryujinx.Common/Logging/Logger.cs @@ -24,7 +24,7 @@ namespace Ryujinx.Common.Logging public readonly struct Log { private static readonly string _homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); - private static readonly string _homeDirRedacted = Path.Combine(Directory.GetParent(_homeDir).FullName, "[redacted]"); + private static readonly string _homeDirRedacted = Path.Combine(Directory.GetParent(_homeDir)!.FullName, "[redacted]"); internal readonly LogLevel Level; @@ -233,7 +233,7 @@ namespace Ryujinx.Common.Logging 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.Trace : Trace = enabled ? new Log(LogLevel.Trace) : new Log?(); break; - default: throw new ArgumentException("Unknown Log Level"); + default: throw new ArgumentException("Unknown Log Level", nameof(logLevel)); #pragma warning restore IDE0055 } } diff --git a/src/Ryujinx/App.axaml.cs b/src/Ryujinx/App.axaml.cs index ec9cd77c7..9c1ccaf8d 100644 --- a/src/Ryujinx/App.axaml.cs +++ b/src/Ryujinx/App.axaml.cs @@ -112,7 +112,7 @@ namespace Ryujinx.Ava } catch (Exception) { - Logger.Warning?.Print(LogClass.Application, "Failed to Apply Theme. A restart is needed to apply the selected theme"); + Logger.Warning?.Print(LogClass.Application, "Failed to apply theme. A restart is needed to apply the selected theme."); ShowRestartDialog(); } diff --git a/src/Ryujinx/Common/Locale/LocaleManager.cs b/src/Ryujinx/Common/Locale/LocaleManager.cs index 96f648761..995a07881 100644 --- a/src/Ryujinx/Common/Locale/LocaleManager.cs +++ b/src/Ryujinx/Common/Locale/LocaleManager.cs @@ -57,40 +57,32 @@ namespace Ryujinx.Ava.Common.Locale { // Check if the localized string needs to be formatted. if (_dynamicValues.TryGetValue(key, out var dynamicValue)) - { try { return string.Format(value, dynamicValue); } - catch (Exception) + catch { // If formatting failed use the default text instead. if (_localeDefaultStrings.TryGetValue(key, out value)) - { try { return string.Format(value, dynamicValue); } - catch (Exception) + catch { // If formatting the default text failed return the key. return key.ToString(); } - } } - } return value; } // If the locale doesn't contain the key return the default one. - if (_localeDefaultStrings.TryGetValue(key, out string defaultValue)) - { - return defaultValue; - } - - // If the locale text doesn't exist return the key. - return key.ToString(); + return _localeDefaultStrings.TryGetValue(key, out string defaultValue) + ? defaultValue + : key.ToString(); // If the locale text doesn't exist return the key. } set { @@ -100,14 +92,12 @@ namespace Ryujinx.Ava.Common.Locale } } - public bool IsRTL() - { - return _localeLanguageCode switch + public bool IsRTL() => + _localeLanguageCode switch { "ar_SA" or "he_IL" => true, _ => false }; - } public string UpdateAndGetDynamicValue(LocaleKeys key, params object[] values) { diff --git a/src/Ryujinx/Program.cs b/src/Ryujinx/Program.cs index b555554a3..3d5fadd41 100644 --- a/src/Ryujinx/Program.cs +++ b/src/Ryujinx/Program.cs @@ -182,41 +182,33 @@ namespace Ryujinx.Ava UseHardwareAcceleration = ConfigurationState.Instance.EnableHardwareAcceleration.Value; // Check if graphics backend was overridden - if (CommandLineState.OverrideGraphicsBackend != null) - { - if (CommandLineState.OverrideGraphicsBackend.ToLower() == "opengl") + if (CommandLineState.OverrideGraphicsBackend is not null) + ConfigurationState.Instance.Graphics.GraphicsBackend.Value = CommandLineState.OverrideGraphicsBackend.ToLower() switch { - ConfigurationState.Instance.Graphics.GraphicsBackend.Value = GraphicsBackend.OpenGl; - } - else if (CommandLineState.OverrideGraphicsBackend.ToLower() == "vulkan") - { - ConfigurationState.Instance.Graphics.GraphicsBackend.Value = GraphicsBackend.Vulkan; - } - } + "opengl" => GraphicsBackend.OpenGl, + "vulkan" => GraphicsBackend.Vulkan, + _ => ConfigurationState.Instance.Graphics.GraphicsBackend + }; // Check if docked mode was overriden. if (CommandLineState.OverrideDockedMode.HasValue) - { ConfigurationState.Instance.System.EnableDockedMode.Value = CommandLineState.OverrideDockedMode.Value; - } + // Check if HideCursor was overridden. if (CommandLineState.OverrideHideCursor is not null) - { - ConfigurationState.Instance.HideCursor.Value = CommandLineState.OverrideHideCursor!.ToLower() switch + ConfigurationState.Instance.HideCursor.Value = CommandLineState.OverrideHideCursor.ToLower() switch { "never" => HideCursorMode.Never, "onidle" => HideCursorMode.OnIdle, "always" => HideCursorMode.Always, - _ => ConfigurationState.Instance.HideCursor.Value, + _ => ConfigurationState.Instance.HideCursor, }; - } + // Check if hardware-acceleration was overridden. if (CommandLineState.OverrideHardwareAcceleration != null) - { UseHardwareAcceleration = CommandLineState.OverrideHardwareAcceleration.Value; - } } private static void PrintSystemInfo() diff --git a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs index 8e8abf1af..1aa3bab7b 100644 --- a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs @@ -443,10 +443,7 @@ namespace Ryujinx.Ava.UI.Windows Initialize(); - /// - /// Subscribe to the ColorValuesChanged event - /// - PlatformSettings.ColorValuesChanged += OnPlatformColorValuesChanged; + PlatformSettings!.ColorValuesChanged += OnPlatformColorValuesChanged; ViewModel.Initialize( ContentManager, @@ -467,7 +464,7 @@ namespace Ryujinx.Ava.UI.Windows _appLibraryAppsSubscription?.Dispose(); _appLibraryAppsSubscription = ApplicationLibrary.Applications .Connect() - .ObserveOn(SynchronizationContext.Current) + .ObserveOn(SynchronizationContext.Current!) .Bind(ViewModel.Applications) .Subscribe(); @@ -656,28 +653,20 @@ namespace Ryujinx.Ava.UI.Windows applicationLibraryThread.Start(); } - private Task ShowNewContentAddedDialog(int numDlcAdded, int numUpdatesAdded) + private void ShowNewContentAddedDialog(int numDlcAdded, int numUpdatesAdded) { - var msg = ""; + string msg = numDlcAdded > 0 && numUpdatesAdded > 0 + ? string.Format(LocaleManager.Instance[LocaleKeys.AutoloadDlcAndUpdateAddedMessage], numDlcAdded, numUpdatesAdded) + : numDlcAdded > 0 + ? string.Format(LocaleManager.Instance[LocaleKeys.AutoloadDlcAddedMessage], numDlcAdded) + : numUpdatesAdded > 0 + ? string.Format(LocaleManager.Instance[LocaleKeys.AutoloadUpdateAddedMessage], numUpdatesAdded) + : null; - if (numDlcAdded > 0 && numUpdatesAdded > 0) - { - msg = string.Format(LocaleManager.Instance[LocaleKeys.AutoloadDlcAndUpdateAddedMessage], numDlcAdded, numUpdatesAdded); - } - else if (numDlcAdded > 0) - { - msg = string.Format(LocaleManager.Instance[LocaleKeys.AutoloadDlcAddedMessage], numDlcAdded); - } - else if (numUpdatesAdded > 0) - { - msg = string.Format(LocaleManager.Instance[LocaleKeys.AutoloadUpdateAddedMessage], numUpdatesAdded); - } - else - { - return Task.CompletedTask; - } + if (msg is null) return; + - return Dispatcher.UIThread.InvokeAsync(async () => + Dispatcher.UIThread.InvokeAsync(async () => { await ContentDialogHelper.ShowTextDialog(LocaleManager.Instance[LocaleKeys.DialogConfirmationTitle], msg, "", "", "", LocaleManager.Instance[LocaleKeys.InputDialogOk], (int)Symbol.Checkmark); diff --git a/src/Ryujinx/UI/Windows/StyleableWindow.cs b/src/Ryujinx/UI/Windows/StyleableWindow.cs index a12d2b3e8..94efb764e 100644 --- a/src/Ryujinx/UI/Windows/StyleableWindow.cs +++ b/src/Ryujinx/UI/Windows/StyleableWindow.cs @@ -17,9 +17,9 @@ namespace Ryujinx.Ava.UI.Windows public StyleableWindow() { WindowStartupLocation = WindowStartupLocation.CenterOwner; - TransparencyLevelHint = new[] { WindowTransparencyLevel.None }; + TransparencyLevelHint = [WindowTransparencyLevel.None]; - using Stream stream = Assembly.GetAssembly(typeof(ConfigurationState)).GetManifestResourceStream("Ryujinx.UI.Common.Resources.Logo_Ryujinx.png"); + using Stream stream = Assembly.GetAssembly(typeof(ConfigurationState))!.GetManifestResourceStream("Ryujinx.UI.Common.Resources.Logo_Ryujinx.png")!; Icon = new WindowIcon(stream); stream.Position = 0;