[Ryujinx.Ava] Address dotnet-format issues (#5361)

* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0060 warnings

* Silence dotnet format IDE0052 warnings

* Silence dotnet format IDE0059 warnings

* Address or silence dotnet format IDE1006 warnings

* Address dotnet format CA1816 warnings

* Address dotnet format CA1822 warnings

* Address or silence dotnet format CA1069 warnings

* Make dotnet format succeed in style mode

* Address dotnet format CA1401 warnings

* Address remaining dotnet format analyzer warnings

* Address review comments

* dotnet-format fixes after rebase

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Format if-blocks correctly

* Another rebase, another dotnet format run

* Run dotnet format whitespace after rebase

* Run dotnet format style after rebase

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Add comments to disabled warnings

* Remove a few unused parameters

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Start working on disabled warnings

* Fix and silence a few dotnet-format warnings again

* Address IDE0260 warnings

* Address a few disabled IDE0060 warnings

* Silence IDE0060 in .editorconfig

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* dotnet format pass with new editorconfig

* Fix naming style issues

* Apply suggestions from code review

Co-authored-by: Ac_K <Acoustik666@gmail.com>

* Revert one suggestion

* Second dotnet format pass and fix build issues

* Final pass of dotnet format

* Add trailing commas

* Fix formatting issues

* Keep unnecessary assignment in IconColorPicker.cs

* Use using declarations and extend resource lifetimes

* Fix rebase issues

* Adjust comment spacing

* Fix typo

* Fix naming issues

* Apply suggestions from code review

Co-authored-by: Ac_K <Acoustik666@gmail.com>

* Revert unintentional change

* Remove unused file

* Remove static keyword from ViewModels

Binding of static members doesn't work and is silently ignored.

---------

Co-authored-by: Ac_K <Acoustik666@gmail.com>
This commit is contained in:
TSRBerry
2023-07-07 23:03:27 +02:00
committed by GitHub
parent 8a363b5df2
commit 6c515e1822
108 changed files with 1140 additions and 1503 deletions

View File

@@ -13,4 +13,4 @@ namespace Ryujinx.Ava.UI.Helpers
RoutedEvent = routedEvent;
}
}
}
}

View File

@@ -33,4 +33,4 @@ namespace Ryujinx.Ava.UI.Helpers
throw new NotSupportedException();
}
}
}
}

View File

@@ -23,7 +23,7 @@ namespace Ryujinx.Ava.UI.Helpers
IsAssigned = isAssigned;
}
}
public ToggleButton ToggledButton { get; set; }
private bool _isWaitingForInput;

View File

@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Threading;
using FluentAvalonia.Core;
@@ -32,18 +33,17 @@ namespace Ryujinx.Ava.UI.Helpers
ContentDialog contentDialog = new()
{
Title = title,
PrimaryButtonText = primaryButton,
Title = title,
PrimaryButtonText = primaryButton,
SecondaryButtonText = secondaryButton,
CloseButtonText = closeButton,
Content = content
CloseButtonText = closeButton,
Content = content,
PrimaryButtonCommand = MiniCommand.Create(() =>
{
result = primaryButtonResult;
}),
};
contentDialog.PrimaryButtonCommand = MiniCommand.Create(() =>
{
result = primaryButtonResult;
});
contentDialog.SecondaryButtonCommand = MiniCommand.Create(() =>
{
result = UserResult.No;
@@ -96,7 +96,6 @@ namespace Ryujinx.Ava.UI.Helpers
Func<Window, Task> doWhileDeferred = null)
{
bool startedDeferring = false;
UserResult result = UserResult.None;
return await ShowTextDialog(
title,
@@ -123,8 +122,6 @@ namespace Ryujinx.Ava.UI.Helpers
var deferral = args.GetDeferral();
result = primaryButton == LocaleManager.Instance[LocaleKeys.InputDialogYes] ? UserResult.Yes : UserResult.Ok;
sender.PrimaryButtonClick -= DeferClose;
_ = Task.Run(() =>
@@ -150,18 +147,18 @@ namespace Ryujinx.Ava.UI.Helpers
{
Grid content = new()
{
RowDefinitions = new RowDefinitions() { new RowDefinition(), new RowDefinition() },
ColumnDefinitions = new ColumnDefinitions() { new ColumnDefinition(GridLength.Auto), new ColumnDefinition() },
RowDefinitions = new RowDefinitions { new(), new() },
ColumnDefinitions = new ColumnDefinitions { new(GridLength.Auto), new() },
MinHeight = 80
MinHeight = 80,
};
SymbolIcon icon = new()
{
Symbol = (Symbol)symbol,
Margin = new Thickness(10),
FontSize = 40,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center
Symbol = (Symbol)symbol,
Margin = new Thickness(10),
FontSize = 40,
VerticalAlignment = VerticalAlignment.Center,
};
Grid.SetColumn(icon, 0);
@@ -170,18 +167,18 @@ namespace Ryujinx.Ava.UI.Helpers
TextBlock primaryLabel = new()
{
Text = primaryText,
Margin = new Thickness(5),
Text = primaryText,
Margin = new Thickness(5),
TextWrapping = TextWrapping.Wrap,
MaxWidth = 450
MaxWidth = 450,
};
TextBlock secondaryLabel = new()
{
Text = secondaryText,
Margin = new Thickness(5),
Text = secondaryText,
Margin = new Thickness(5),
TextWrapping = TextWrapping.Wrap,
MaxWidth = 450
MaxWidth = 450,
};
Grid.SetColumn(primaryLabel, 1);
@@ -318,14 +315,14 @@ namespace Ryujinx.Ava.UI.Helpers
Window parent = GetMainWindow();
if (parent != null && parent.IsActive && (parent as MainWindow).ViewModel.IsGameRunning)
if (parent is { IsActive: true } and MainWindow window && window.ViewModel.IsGameRunning)
{
contentDialogOverlayWindow = new()
{
Height = parent.Bounds.Height,
Width = parent.Bounds.Width,
Position = parent.PointToScreen(new Point()),
ShowInTaskbar = false
Height = parent.Bounds.Height,
Width = parent.Bounds.Width,
Position = parent.PointToScreen(new Point()),
ShowInTaskbar = false,
};
parent.PositionChanged += OverlayOnPositionChanged;
@@ -389,7 +386,7 @@ namespace Ryujinx.Ava.UI.Helpers
private static Window GetMainWindow()
{
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime al)
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime al)
{
foreach (Window item in al.Windows)
{
@@ -403,4 +400,4 @@ namespace Ryujinx.Ava.UI.Helpers
return null;
}
}
}
}

View File

@@ -1,5 +1,6 @@
using Avalonia.Data;
using Avalonia.Markup.Xaml;
using Avalonia.Markup.Xaml.MarkupExtensions;
using FluentAvalonia.UI.Controls;
using System;
using System.Collections.Generic;
@@ -8,13 +9,13 @@ namespace Ryujinx.Ava.UI.Helpers
{
public class GlyphValueConverter : MarkupExtension
{
private string _key;
private readonly string _key;
private static Dictionary<Glyph, string> _glyphs = new Dictionary<Glyph, string>
private static readonly Dictionary<Glyph, string> _glyphs = new()
{
{ Glyph.List, char.ConvertFromUtf32((int)Symbol.List).ToString() },
{ Glyph.Grid, char.ConvertFromUtf32((int)Symbol.ViewAll).ToString() },
{ Glyph.Chip, char.ConvertFromUtf32(59748).ToString() }
{ Glyph.List, char.ConvertFromUtf32((int)Symbol.List) },
{ Glyph.Grid, char.ConvertFromUtf32((int)Symbol.ViewAll) },
{ Glyph.Chip, char.ConvertFromUtf32(59748) },
};
public GlyphValueConverter(string key)
@@ -37,13 +38,13 @@ namespace Ryujinx.Ava.UI.Helpers
public override object ProvideValue(IServiceProvider serviceProvider)
{
Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension binding = new($"[{_key}]")
ReflectionBindingExtension binding = new($"[{_key}]")
{
Mode = BindingMode.OneWay,
Source = this
Source = this,
};
return binding.ProvideValue(serviceProvider);
}
}
}
}

View File

@@ -49,4 +49,4 @@ namespace Ryujinx.Ava.UI.Helpers
}
}
}
}
}

View File

@@ -43,4 +43,4 @@ namespace Ryujinx.Ava.UI.Helpers
return key;
}
}
}
}

View File

@@ -1,15 +1,17 @@
using Avalonia.Logging;
using Avalonia.Utilities;
using Ryujinx.Common.Logging;
using System;
using System.Text;
namespace Ryujinx.Ava.UI.Helpers
{
using AvaLogger = Avalonia.Logging.Logger;
using AvaLogLevel = Avalonia.Logging.LogEventLevel;
using RyuLogClass = Ryujinx.Common.Logging.LogClass;
using RyuLogger = Ryujinx.Common.Logging.Logger;
using AvaLogger = Avalonia.Logging.Logger;
using AvaLogLevel = LogEventLevel;
using RyuLogClass = LogClass;
using RyuLogger = Ryujinx.Common.Logging.Logger;
internal class LoggerAdapter : Avalonia.Logging.ILogSink
internal class LoggerAdapter : ILogSink
{
public static void Register()
{
@@ -20,13 +22,13 @@ namespace Ryujinx.Ava.UI.Helpers
{
return level switch
{
AvaLogLevel.Verbose => RyuLogger.Debug,
AvaLogLevel.Debug => RyuLogger.Debug,
AvaLogLevel.Verbose => RyuLogger.Debug,
AvaLogLevel.Debug => RyuLogger.Debug,
AvaLogLevel.Information => RyuLogger.Debug,
AvaLogLevel.Warning => RyuLogger.Debug,
AvaLogLevel.Error => RyuLogger.Error,
AvaLogLevel.Fatal => RyuLogger.Error,
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
AvaLogLevel.Warning => RyuLogger.Debug,
AvaLogLevel.Error => RyuLogger.Error,
AvaLogLevel.Fatal => RyuLogger.Error,
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null),
};
}
@@ -45,7 +47,7 @@ namespace Ryujinx.Ava.UI.Helpers
GetLog(level)?.PrintMsg(RyuLogClass.Ui, Format(level, area, messageTemplate, source, new object[] { propertyValue0 }));
}
public void Log<T0, T1>(AvaLogLevel level, string area, object source, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
public void Log<T0, T1>(AvaLogLevel level, string area, object source, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
GetLog(level)?.PrintMsg(RyuLogClass.Ui, Format(level, area, messageTemplate, source, new object[] { propertyValue0, propertyValue1 }));
}
@@ -112,4 +114,4 @@ namespace Ryujinx.Ava.UI.Helpers
return result.ToString();
}
}
}
}

View File

@@ -8,7 +8,7 @@ namespace Ryujinx.Ava.UI.Helpers
{
private readonly Action<T> _callback;
private bool _busy;
private Func<T, Task> _asyncCallback;
private readonly Func<T, Task> _asyncCallback;
public MiniCommand(Action<T> callback)
{
@@ -68,4 +68,4 @@ namespace Ryujinx.Ava.UI.Helpers
public abstract void Execute(object parameter);
public abstract event EventHandler CanExecuteChanged;
}
}
}

View File

@@ -12,12 +12,12 @@ namespace Ryujinx.Ava.UI.Helpers
{
public static class NotificationHelper
{
private const int MaxNotifications = 4;
private const int MaxNotifications = 4;
private const int NotificationDelayInMs = 5000;
private static WindowNotificationManager _notificationManager;
private static readonly BlockingCollection<Notification> _notifications = new();
private static readonly BlockingCollection<Notification> _notifications = new();
public static void SetNotificationManager(Window host)
{
@@ -25,7 +25,7 @@ namespace Ryujinx.Ava.UI.Helpers
{
Position = NotificationPosition.BottomRight,
MaxItems = MaxNotifications,
Margin = new Thickness(0, 0, 15, 40)
Margin = new Thickness(0, 0, 15, 40),
};
var maybeAsyncWorkQueue = new Lazy<AsyncWorkQueue<Notification>>(
@@ -67,4 +67,4 @@ namespace Ryujinx.Ava.UI.Helpers
Show(LocaleManager.Instance[LocaleKeys.DialogErrorTitle], $"{LocaleManager.Instance[LocaleKeys.DialogErrorMessage]}\n\n{message}", NotificationType.Error);
}
}
}
}

View File

@@ -35,4 +35,4 @@ namespace Ryujinx.Ava.UI.Helpers
return _instance;
}
}
}
}

View File

@@ -6,12 +6,12 @@ namespace Ryujinx.Ava.UI.Helpers
{
public class OffscreenTextBox : TextBox
{
public RoutedEvent<KeyEventArgs> GetKeyDownRoutedEvent()
public static RoutedEvent<KeyEventArgs> GetKeyDownRoutedEvent()
{
return KeyDownEvent;
}
public RoutedEvent<KeyEventArgs> GetKeyUpRoutedEvent()
public static RoutedEvent<KeyEventArgs> GetKeyUpRoutedEvent()
{
return KeyUpEvent;
}
@@ -28,13 +28,13 @@ namespace Ryujinx.Ava.UI.Helpers
public void SendText(string text)
{
OnTextInput(new TextInputEventArgs()
OnTextInput(new TextInputEventArgs
{
Text = text,
Device = KeyboardDevice.Instance,
Source = this,
RoutedEvent = TextInputEvent
RoutedEvent = TextInputEvent,
});
}
}
}
}

View File

@@ -1,5 +1,4 @@
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Windows;
using Ryujinx.Ui.Common;
using Ryujinx.Ui.Common.Helper;
using System.Threading.Tasks;
@@ -24,7 +23,7 @@ namespace Ryujinx.Ava.UI.Helpers
UserError.FirmwareParsingFailed => LocaleManager.Instance[LocaleKeys.UserErrorFirmwareParsingFailed],
UserError.ApplicationNotFound => LocaleManager.Instance[LocaleKeys.UserErrorApplicationNotFound],
UserError.Unknown => LocaleManager.Instance[LocaleKeys.UserErrorUnknown],
_ => LocaleManager.Instance[LocaleKeys.UserErrorUndefined]
_ => LocaleManager.Instance[LocaleKeys.UserErrorUndefined],
};
}
@@ -37,7 +36,7 @@ namespace Ryujinx.Ava.UI.Helpers
UserError.FirmwareParsingFailed => LocaleManager.Instance[LocaleKeys.UserErrorFirmwareParsingFailedDescription],
UserError.ApplicationNotFound => LocaleManager.Instance[LocaleKeys.UserErrorApplicationNotFoundDescription],
UserError.Unknown => LocaleManager.Instance[LocaleKeys.UserErrorUnknownDescription],
_ => LocaleManager.Instance[LocaleKeys.UserErrorUndefinedDescription]
_ => LocaleManager.Instance[LocaleKeys.UserErrorUndefinedDescription],
};
}
@@ -48,7 +47,7 @@ namespace Ryujinx.Ava.UI.Helpers
UserError.NoKeys or
UserError.NoFirmware or
UserError.FirmwareParsingFailed => true,
_ => false
_ => false,
};
}
@@ -63,11 +62,11 @@ namespace Ryujinx.Ava.UI.Helpers
{
UserError.NoKeys => SetupGuideUrl + "#initial-setup---placement-of-prodkeys",
UserError.NoFirmware => SetupGuideUrl + "#initial-setup-continued---installation-of-firmware",
_ => SetupGuideUrl
_ => SetupGuideUrl,
};
}
public static async Task ShowUserErrorDialog(UserError error, StyleableWindow owner)
public static async Task ShowUserErrorDialog(UserError error)
{
string errorCode = GetErrorCode(error);
@@ -88,4 +87,4 @@ namespace Ryujinx.Ava.UI.Helpers
}
}
}
}
}

View File

@@ -9,4 +9,4 @@ namespace Ryujinx.Ava.UI.Helpers
Cancel,
None,
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
@@ -10,46 +11,47 @@ namespace Ryujinx.Ava.UI.Helpers
[Flags]
public enum ClassStyles : uint
{
CS_CLASSDC = 0x40,
CS_OWNDC = 0x20,
CsClassdc = 0x40,
CsOwndc = 0x20,
}
[Flags]
public enum WindowStyles : uint
{
WS_CHILD = 0x40000000
WsChild = 0x40000000,
}
public enum Cursors : uint
{
IDC_ARROW = 32512
IdcArrow = 32512,
}
[SuppressMessage("Design", "CA1069: Enums values should not be duplicated")]
public enum WindowsMessages : uint
{
MOUSEMOVE = 0x0200,
LBUTTONDOWN = 0x0201,
LBUTTONUP = 0x0202,
LBUTTONDBLCLK = 0x0203,
RBUTTONDOWN = 0x0204,
RBUTTONUP = 0x0205,
RBUTTONDBLCLK = 0x0206,
MBUTTONDOWN = 0x0207,
MBUTTONUP = 0x0208,
MBUTTONDBLCLK = 0x0209,
MOUSEWHEEL = 0x020A,
XBUTTONDOWN = 0x020B,
XBUTTONUP = 0x020C,
XBUTTONDBLCLK = 0x020D,
MOUSEHWHEEL = 0x020E,
MOUSELAST = 0x020E
Mousemove = 0x0200,
Lbuttondown = 0x0201,
Lbuttonup = 0x0202,
Lbuttondblclk = 0x0203,
Rbuttondown = 0x0204,
Rbuttonup = 0x0205,
Rbuttondblclk = 0x0206,
Mbuttondown = 0x0207,
Mbuttonup = 0x0208,
Mbuttondblclk = 0x0209,
Mousewheel = 0x020A,
Xbuttondown = 0x020B,
Xbuttonup = 0x020C,
Xbuttondblclk = 0x020D,
Mousehwheel = 0x020E,
Mouselast = 0x020E,
}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
internal delegate IntPtr WindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam);
[StructLayout(LayoutKind.Sequential)]
public struct WNDCLASSEX
public struct WndClassEx
{
public int cbSize;
public ClassStyles style;
@@ -64,9 +66,9 @@ namespace Ryujinx.Ava.UI.Helpers
public IntPtr lpszClassName;
public IntPtr hIconSm;
public WNDCLASSEX()
public WndClassEx()
{
cbSize = Marshal.SizeOf<WNDCLASSEX>();
cbSize = Marshal.SizeOf<WndClassEx>();
}
}
@@ -77,17 +79,17 @@ namespace Ryujinx.Ava.UI.Helpers
public static IntPtr CreateArrowCursor()
{
return LoadCursor(IntPtr.Zero, (IntPtr)Cursors.IDC_ARROW);
return LoadCursor(IntPtr.Zero, (IntPtr)Cursors.IdcArrow);
}
[LibraryImport("user32.dll")]
public static partial IntPtr SetCursor(IntPtr handle);
[LibraryImport("user32.dll")]
public static partial IntPtr CreateCursor(IntPtr hInst, int xHotSpot, int yHotSpot, int nWidth, int nHeight, byte[] pvANDPlane, byte[] pvXORPlane);
public static partial IntPtr CreateCursor(IntPtr hInst, int xHotSpot, int yHotSpot, int nWidth, int nHeight, byte[] pvAndPlane, byte[] pvXorPlane);
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "RegisterClassExW")]
public static partial ushort RegisterClassEx(ref WNDCLASSEX param);
public static partial ushort RegisterClassEx(ref WndClassEx param);
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "UnregisterClassW")]
public static partial short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, IntPtr instance);