misc: Replace references to IntPtr/UIntPtr with nint/nuint + code cleanups.

This commit is contained in:
Evan Husted 2024-10-26 08:46:41 -05:00
parent a09d314817
commit dfb4854d19
172 changed files with 902 additions and 914 deletions

View file

@ -35,23 +35,23 @@ namespace Ryujinx.Ava.UI.Helpers
}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
internal delegate IntPtr WindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam);
internal delegate nint WindowProc(nint hWnd, WindowsMessages msg, nint wParam, nint lParam);
[StructLayout(LayoutKind.Sequential)]
public struct WndClassEx
{
public int cbSize;
public ClassStyles style;
public IntPtr lpfnWndProc; // not WndProc
public nint lpfnWndProc; // not WndProc
public int cbClsExtra;
public int cbWndExtra;
public IntPtr hInstance;
public IntPtr hIcon;
public IntPtr hCursor;
public IntPtr hbrBackground;
public IntPtr lpszMenuName;
public IntPtr lpszClassName;
public IntPtr hIconSm;
public nint hInstance;
public nint hIcon;
public nint hCursor;
public nint hbrBackground;
public nint lpszMenuName;
public nint lpszClassName;
public nint hIconSm;
public WndClassEx()
{
@ -59,43 +59,43 @@ namespace Ryujinx.Ava.UI.Helpers
}
}
public static IntPtr CreateEmptyCursor()
public static nint CreateEmptyCursor()
{
return CreateCursor(IntPtr.Zero, 0, 0, 1, 1, new byte[] { 0xFF }, new byte[] { 0x00 });
return CreateCursor(nint.Zero, 0, 0, 1, 1, [0xFF], [0x00]);
}
public static IntPtr CreateArrowCursor()
public static nint CreateArrowCursor()
{
return LoadCursor(IntPtr.Zero, (IntPtr)Cursors.IdcArrow);
return LoadCursor(nint.Zero, (nint)Cursors.IdcArrow);
}
[LibraryImport("user32.dll")]
public static partial IntPtr SetCursor(IntPtr handle);
public static partial nint SetCursor(nint handle);
[LibraryImport("user32.dll")]
public static partial IntPtr CreateCursor(IntPtr hInst, int xHotSpot, int yHotSpot, int nWidth, int nHeight, [In] byte[] pvAndPlane, [In] byte[] pvXorPlane);
public static partial nint CreateCursor(nint hInst, int xHotSpot, int yHotSpot, int nWidth, int nHeight, [In] byte[] pvAndPlane, [In] byte[] pvXorPlane);
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "RegisterClassExW")]
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);
public static partial short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, nint instance);
[LibraryImport("user32.dll", EntryPoint = "DefWindowProcW")]
public static partial IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam);
public static partial nint DefWindowProc(nint hWnd, WindowsMessages msg, nint wParam, nint lParam);
[LibraryImport("kernel32.dll", EntryPoint = "GetModuleHandleA")]
public static partial IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPStr)] string lpModuleName);
public static partial nint GetModuleHandle([MarshalAs(UnmanagedType.LPStr)] string lpModuleName);
[LibraryImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool DestroyWindow(IntPtr hwnd);
public static partial bool DestroyWindow(nint hwnd);
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "LoadCursorA")]
public static partial IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName);
public static partial nint LoadCursor(nint hInstance, nint lpCursorName);
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "CreateWindowExW")]
public static partial IntPtr CreateWindowEx(
public static partial nint CreateWindowEx(
uint dwExStyle,
[MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
[MarshalAs(UnmanagedType.LPWStr)] string lpWindowName,
@ -104,12 +104,12 @@ namespace Ryujinx.Ava.UI.Helpers
int y,
int nWidth,
int nHeight,
IntPtr hWndParent,
IntPtr hMenu,
IntPtr hInstance,
IntPtr lpParam);
nint hWndParent,
nint hMenu,
nint hInstance,
nint lpParam);
[LibraryImport("user32.dll", SetLastError = true)]
public static partial IntPtr SetWindowLongPtrW(IntPtr hWnd, int nIndex, IntPtr value);
public static partial nint SetWindowLongPtrW(nint hWnd, int nIndex, nint value);
}
}

View file

@ -25,15 +25,15 @@ namespace Ryujinx.Ava.UI.Renderer
protected GLXWindow X11Window { get; set; }
protected IntPtr WindowHandle { get; set; }
protected IntPtr X11Display { get; set; }
protected IntPtr NsView { get; set; }
protected IntPtr MetalLayer { get; set; }
protected nint WindowHandle { get; set; }
protected nint X11Display { get; set; }
protected nint NsView { get; set; }
protected nint MetalLayer { get; set; }
public delegate void UpdateBoundsCallbackDelegate(Rect rect);
private UpdateBoundsCallbackDelegate _updateBoundsCallback;
public event EventHandler<IntPtr> WindowCreated;
public event EventHandler<nint> WindowCreated;
public event EventHandler<Size> BoundsChanged;
public EmbeddedWindow()
@ -49,10 +49,10 @@ namespace Ryujinx.Ava.UI.Renderer
protected virtual void OnWindowDestroying()
{
WindowHandle = IntPtr.Zero;
X11Display = IntPtr.Zero;
NsView = IntPtr.Zero;
MetalLayer = IntPtr.Zero;
WindowHandle = nint.Zero;
X11Display = nint.Zero;
NsView = nint.Zero;
MetalLayer = nint.Zero;
}
private void OnNativeEmbeddedWindowCreated(object sender, EventArgs e)
@ -139,7 +139,7 @@ namespace Ryujinx.Ava.UI.Renderer
{
_className = "NativeWindow-" + Guid.NewGuid();
_wndProcDelegate = delegate (IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam)
_wndProcDelegate = delegate (nint hWnd, WindowsMessages msg, nint wParam, nint lParam)
{
switch (msg)
{
@ -162,7 +162,7 @@ namespace Ryujinx.Ava.UI.Renderer
RegisterClassEx(ref wndClassEx);
WindowHandle = CreateWindowEx(0, _className, "NativeWindow", WindowStyles.WsChild, 0, 0, 640, 480, control.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
WindowHandle = CreateWindowEx(0, _className, "NativeWindow", WindowStyles.WsChild, 0, 0, 640, 480, control.Handle, nint.Zero, nint.Zero, nint.Zero);
SetWindowLongPtrW(control.Handle, GWLP_WNDPROC, wndClassEx.lpfnWndProc);
@ -195,7 +195,7 @@ namespace Ryujinx.Ava.UI.Renderer
metalLayer.SendMessage("setContentsScale:", Program.DesktopScaleFactor);
};
IntPtr nsView = child.ObjPtr;
nint nsView = child.ObjPtr;
MetalLayer = metalLayer.ObjPtr;
NsView = nsView;

View file

@ -5,14 +5,14 @@ namespace Ryujinx.Ava.UI.Renderer
{
internal class OpenTKBindingsContext : IBindingsContext
{
private readonly Func<string, IntPtr> _getProcAddress;
private readonly Func<string, nint> _getProcAddress;
public OpenTKBindingsContext(Func<string, IntPtr> getProcAddress)
public OpenTKBindingsContext(Func<string, nint> getProcAddress)
{
_getProcAddress = getProcAddress;
}
public IntPtr GetProcAddress(string procName)
public nint GetProcAddress(string procName)
{
return _getProcAddress(procName);
}

View file

@ -60,7 +60,7 @@ namespace Ryujinx.Ava.UI.Renderer
BoundsChanged?.Invoke(sender, e);
}
private void CurrentWindow_WindowCreated(object sender, IntPtr e)
private void CurrentWindow_WindowCreated(object sender, nint e)
{
WindowCreated?.Invoke(this, EventArgs.Empty);
}

View file

@ -36,23 +36,17 @@ namespace Ryujinx.Ava.UI.Views.Main
ChangeLanguageMenuItem.ItemsSource = GenerateLanguageMenuItems();
}
private CheckBox[] GenerateToggleFileTypeItems()
{
List<CheckBox> checkBoxes = new();
foreach (var item in Enum.GetValues(typeof(FileTypes)))
{
string fileName = Enum.GetName(typeof(FileTypes), item);
checkBoxes.Add(new CheckBox
{
Content = $".{fileName}",
IsChecked = ((FileTypes)item).GetConfigValue(ConfigurationState.Instance.UI.ShownFileTypes),
Command = MiniCommand.Create(() => Window.ToggleFileType(fileName)),
});
}
return checkBoxes.ToArray();
}
private CheckBox[] GenerateToggleFileTypeItems() =>
Enum.GetValues<FileTypes>()
.Select(it => (FileName: Enum.GetName(it)!, FileType: it))
.Select(it =>
new CheckBox
{
Content = $".{it.FileName}",
IsChecked = it.FileType.GetConfigValue(ConfigurationState.Instance.UI.ShownFileTypes),
Command = MiniCommand.Create(() => Window.ToggleFileType(it.FileName))
}
).ToArray();
private static MenuItem[] GenerateLanguageMenuItems()
{
@ -80,7 +74,7 @@ namespace Ryujinx.Ava.UI.Views.Main
{
Padding = new Thickness(10, 0, 0, 0),
Header = " " + languageName,
Command = MiniCommand.Create(() => MainWindowViewModel.ChangeLanguage(languageCode)),
Command = MiniCommand.Create(() => MainWindowViewModel.ChangeLanguage(languageCode))
};
menuItems.Add(menuItem);

View file

@ -5,6 +5,7 @@ using Avalonia.Interactivity;
using Avalonia.Threading;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Windows;
using Ryujinx.Common;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.UI.Common.Configuration;
@ -46,7 +47,7 @@ namespace Ryujinx.Ava.UI.Views.Main
private void DockedStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
{
ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value;
ConfigurationState.Instance.System.EnableDockedMode.Toggle();
}
private void AspectRatioStatus_OnClick(object sender, RoutedEventArgs e)

View file

@ -201,6 +201,7 @@
Text="{locale:Locale SettingsTabSystemHacks}" />
<TextBlock
Foreground="{DynamicResource SecondaryTextColor}"
TextDecorations="Underline"
Text="{locale:Locale SettingsTabSystemHacksNote}" />
</StackPanel>
<StackPanel

View file

@ -6,8 +6,6 @@ using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS;
using Ryujinx.UI.App.Common;
using Ryujinx.UI.Common.Configuration;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

View file

@ -14,6 +14,7 @@ using Ryujinx.Ava.Input;
using Ryujinx.Ava.UI.Applet;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Gpu;
using Ryujinx.HLE.FileSystem;
@ -471,10 +472,8 @@ namespace Ryujinx.Ava.UI.Windows
{
LoadApplications();
}
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
CheckLaunchState();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_ = CheckLaunchState();
}
private void SetMainContent(Control content = null)
@ -496,7 +495,9 @@ namespace Ryujinx.Ava.UI.Windows
public static void UpdateGraphicsConfig()
{
#pragma warning disable IDE0055 // Disable formatting
GraphicsConfig.ResScale = ConfigurationState.Instance.Graphics.ResScale == -1 ? ConfigurationState.Instance.Graphics.ResScaleCustom : ConfigurationState.Instance.Graphics.ResScale;
GraphicsConfig.ResScale = ConfigurationState.Instance.Graphics.ResScale == -1
? ConfigurationState.Instance.Graphics.ResScaleCustom
: ConfigurationState.Instance.Graphics.ResScale;
GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;
@ -540,7 +541,7 @@ namespace Ryujinx.Ava.UI.Windows
if (ViewModel.AppHost != null)
{
ViewModel.AppHost.AppExit -= ViewModel.AppHost_AppExit;
ViewModel.AppHost.AppExit += (sender, e) =>
ViewModel.AppHost.AppExit += (_, _) =>
{
ViewModel.AppHost = null;
@ -599,18 +600,16 @@ namespace Ryujinx.Ava.UI.Windows
public void ToggleFileType(string fileType)
{
_ = fileType switch
switch (fileType)
{
#pragma warning disable IDE0055 // Disable formatting
"NSP" => ConfigurationState.Instance.UI.ShownFileTypes.NSP.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NSP,
"PFS0" => ConfigurationState.Instance.UI.ShownFileTypes.PFS0.Value = !ConfigurationState.Instance.UI.ShownFileTypes.PFS0,
"XCI" => ConfigurationState.Instance.UI.ShownFileTypes.XCI.Value = !ConfigurationState.Instance.UI.ShownFileTypes.XCI,
"NCA" => ConfigurationState.Instance.UI.ShownFileTypes.NCA.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NCA,
"NRO" => ConfigurationState.Instance.UI.ShownFileTypes.NRO.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NRO,
"NSO" => ConfigurationState.Instance.UI.ShownFileTypes.NSO.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NSO,
_ => throw new ArgumentOutOfRangeException(fileType),
#pragma warning restore IDE0055
};
case "NSP": ConfigurationState.Instance.UI.ShownFileTypes.NSP.Toggle(); break;
case "PFS0": ConfigurationState.Instance.UI.ShownFileTypes.PFS0.Toggle(); break;
case "XCI": ConfigurationState.Instance.UI.ShownFileTypes.XCI.Toggle(); break;
case "NCA": ConfigurationState.Instance.UI.ShownFileTypes.NCA.Toggle(); break;
case "NRO": ConfigurationState.Instance.UI.ShownFileTypes.NRO.Toggle(); break;
case "NSO": ConfigurationState.Instance.UI.ShownFileTypes.NSO.Toggle(); break;
default: throw new ArgumentOutOfRangeException(fileType);
}
ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
LoadApplications();

View file

@ -8,9 +8,9 @@ using Ryujinx.Ava.UI.ViewModels;
namespace Ryujinx.Ava.UI.Windows
{
public class StyleableAppWindow : AppWindow
public abstract class StyleableAppWindow : AppWindow
{
public StyleableAppWindow()
protected StyleableAppWindow()
{
WindowStartupLocation = WindowStartupLocation.CenterOwner;
TransparencyLevelHint = [WindowTransparencyLevel.None];
@ -34,9 +34,9 @@ namespace Ryujinx.Ava.UI.Windows
}
}
public class StyleableWindow : Window
public abstract class StyleableWindow : Window
{
public StyleableWindow()
protected StyleableWindow()
{
WindowStartupLocation = WindowStartupLocation.CenterOwner;
TransparencyLevelHint = [WindowTransparencyLevel.None];