mirror of
https://github.com/Ryubing/Ryujinx.git
synced 2025-12-01 03:12:52 -05:00
misc: Replace references to IntPtr/UIntPtr with nint/nuint + code cleanups.
This commit is contained in:
@@ -677,19 +677,18 @@ namespace Ryujinx.UI.App.Common
|
||||
EnumerationOptions options = new()
|
||||
{
|
||||
RecurseSubdirectories = true,
|
||||
IgnoreInaccessible = false,
|
||||
IgnoreInaccessible = false
|
||||
};
|
||||
|
||||
IEnumerable<string> files = Directory.EnumerateFiles(appDir, "*", options).Where(file =>
|
||||
{
|
||||
return
|
||||
(Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.UI.ShownFileTypes.NSP.Value) ||
|
||||
(Path.GetExtension(file).ToLower() is ".pfs0" && ConfigurationState.Instance.UI.ShownFileTypes.PFS0.Value) ||
|
||||
(Path.GetExtension(file).ToLower() is ".xci" && ConfigurationState.Instance.UI.ShownFileTypes.XCI.Value) ||
|
||||
(Path.GetExtension(file).ToLower() is ".nca" && ConfigurationState.Instance.UI.ShownFileTypes.NCA.Value) ||
|
||||
(Path.GetExtension(file).ToLower() is ".nro" && ConfigurationState.Instance.UI.ShownFileTypes.NRO.Value) ||
|
||||
(Path.GetExtension(file).ToLower() is ".nso" && ConfigurationState.Instance.UI.ShownFileTypes.NSO.Value);
|
||||
});
|
||||
IEnumerable<string> files = Directory.EnumerateFiles(appDir, "*", options)
|
||||
.Where(file =>
|
||||
(Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.UI.ShownFileTypes.NSP) ||
|
||||
(Path.GetExtension(file).ToLower() is ".pfs0" && ConfigurationState.Instance.UI.ShownFileTypes.PFS0) ||
|
||||
(Path.GetExtension(file).ToLower() is ".xci" && ConfigurationState.Instance.UI.ShownFileTypes.XCI) ||
|
||||
(Path.GetExtension(file).ToLower() is ".nca" && ConfigurationState.Instance.UI.ShownFileTypes.NCA) ||
|
||||
(Path.GetExtension(file).ToLower() is ".nro" && ConfigurationState.Instance.UI.ShownFileTypes.NRO) ||
|
||||
(Path.GetExtension(file).ToLower() is ".nso" && ConfigurationState.Instance.UI.ShownFileTypes.NSO)
|
||||
);
|
||||
|
||||
foreach (string app in files)
|
||||
{
|
||||
|
||||
@@ -27,9 +27,9 @@ namespace Ryujinx.UI.Common.Helper
|
||||
const int SW_HIDE = 0;
|
||||
const int SW_SHOW = 5;
|
||||
|
||||
IntPtr hWnd = GetConsoleWindow();
|
||||
nint hWnd = GetConsoleWindow();
|
||||
|
||||
if (hWnd == IntPtr.Zero)
|
||||
if (hWnd == nint.Zero)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Application, "Attempted to show/hide console window but console window does not exist");
|
||||
return;
|
||||
@@ -40,11 +40,11 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
[LibraryImport("kernel32")]
|
||||
private static partial IntPtr GetConsoleWindow();
|
||||
private static partial nint GetConsoleWindow();
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
[LibraryImport("user32")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
||||
private static partial bool ShowWindow(nint hWnd, int nCmdShow);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
private const int SHCNF_FLUSH = 0x1000;
|
||||
|
||||
[LibraryImport("shell32.dll", SetLastError = true)]
|
||||
public static partial void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
|
||||
public static partial void SHChangeNotify(uint wEventId, uint uFlags, nint dwItem1, nint dwItem2);
|
||||
|
||||
public static bool IsTypeAssociationSupported => (OperatingSystem.IsLinux() || OperatingSystem.IsWindows()) && !ReleaseInformation.IsFlatHubBuild;
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
}
|
||||
|
||||
// Notify Explorer the file association has been changed.
|
||||
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero);
|
||||
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, nint.Zero, nint.Zero);
|
||||
|
||||
return registered;
|
||||
}
|
||||
|
||||
@@ -10,44 +10,44 @@ namespace Ryujinx.UI.Common.Helper
|
||||
private const string ObjCRuntime = "/usr/lib/libobjc.A.dylib";
|
||||
|
||||
[LibraryImport(ObjCRuntime, StringMarshalling = StringMarshalling.Utf8)]
|
||||
private static partial IntPtr sel_getUid(string name);
|
||||
private static partial nint sel_getUid(string name);
|
||||
|
||||
[LibraryImport(ObjCRuntime, StringMarshalling = StringMarshalling.Utf8)]
|
||||
private static partial IntPtr objc_getClass(string name);
|
||||
private static partial nint objc_getClass(string name);
|
||||
|
||||
[LibraryImport(ObjCRuntime)]
|
||||
private static partial void objc_msgSend(IntPtr receiver, Selector selector);
|
||||
private static partial void objc_msgSend(nint receiver, Selector selector);
|
||||
|
||||
[LibraryImport(ObjCRuntime)]
|
||||
private static partial void objc_msgSend(IntPtr receiver, Selector selector, byte value);
|
||||
private static partial void objc_msgSend(nint receiver, Selector selector, byte value);
|
||||
|
||||
[LibraryImport(ObjCRuntime)]
|
||||
private static partial void objc_msgSend(IntPtr receiver, Selector selector, IntPtr value);
|
||||
private static partial void objc_msgSend(nint receiver, Selector selector, nint value);
|
||||
|
||||
[LibraryImport(ObjCRuntime)]
|
||||
private static partial void objc_msgSend(IntPtr receiver, Selector selector, NSRect point);
|
||||
private static partial void objc_msgSend(nint receiver, Selector selector, NSRect point);
|
||||
|
||||
[LibraryImport(ObjCRuntime)]
|
||||
private static partial void objc_msgSend(IntPtr receiver, Selector selector, double value);
|
||||
private static partial void objc_msgSend(nint receiver, Selector selector, double value);
|
||||
|
||||
[LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")]
|
||||
private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector);
|
||||
private static partial nint nint_objc_msgSend(nint receiver, Selector selector);
|
||||
|
||||
[LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")]
|
||||
private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector, IntPtr param);
|
||||
private static partial nint nint_objc_msgSend(nint receiver, Selector selector, nint param);
|
||||
|
||||
[LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend", StringMarshalling = StringMarshalling.Utf8)]
|
||||
private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector, string param);
|
||||
private static partial nint nint_objc_msgSend(nint receiver, Selector selector, string param);
|
||||
|
||||
[LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool bool_objc_msgSend(IntPtr receiver, Selector selector, IntPtr param);
|
||||
private static partial bool bool_objc_msgSend(nint receiver, Selector selector, nint param);
|
||||
|
||||
public readonly struct Object
|
||||
{
|
||||
public readonly IntPtr ObjPtr;
|
||||
public readonly nint ObjPtr;
|
||||
|
||||
private Object(IntPtr pointer)
|
||||
private Object(nint pointer)
|
||||
{
|
||||
ObjPtr = pointer;
|
||||
}
|
||||
@@ -84,22 +84,22 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
public Object GetFromMessage(Selector selector)
|
||||
{
|
||||
return new Object(IntPtr_objc_msgSend(ObjPtr, selector));
|
||||
return new Object(nint_objc_msgSend(ObjPtr, selector));
|
||||
}
|
||||
|
||||
public Object GetFromMessage(Selector selector, Object obj)
|
||||
{
|
||||
return new Object(IntPtr_objc_msgSend(ObjPtr, selector, obj.ObjPtr));
|
||||
return new Object(nint_objc_msgSend(ObjPtr, selector, obj.ObjPtr));
|
||||
}
|
||||
|
||||
public Object GetFromMessage(Selector selector, NSString nsString)
|
||||
{
|
||||
return new Object(IntPtr_objc_msgSend(ObjPtr, selector, nsString.StrPtr));
|
||||
return new Object(nint_objc_msgSend(ObjPtr, selector, nsString.StrPtr));
|
||||
}
|
||||
|
||||
public Object GetFromMessage(Selector selector, string param)
|
||||
{
|
||||
return new Object(IntPtr_objc_msgSend(ObjPtr, selector, param));
|
||||
return new Object(nint_objc_msgSend(ObjPtr, selector, param));
|
||||
}
|
||||
|
||||
public bool GetBoolFromMessage(Selector selector, Object obj)
|
||||
@@ -110,7 +110,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
public readonly struct Selector
|
||||
{
|
||||
public readonly IntPtr SelPtr;
|
||||
public readonly nint SelPtr;
|
||||
|
||||
private Selector(string name)
|
||||
{
|
||||
@@ -122,15 +122,15 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
public readonly struct NSString
|
||||
{
|
||||
public readonly IntPtr StrPtr;
|
||||
public readonly nint StrPtr;
|
||||
|
||||
public NSString(string aString)
|
||||
{
|
||||
IntPtr nsString = objc_getClass("NSString");
|
||||
StrPtr = IntPtr_objc_msgSend(nsString, "stringWithUTF8String:", aString);
|
||||
nint nsString = objc_getClass("NSString");
|
||||
StrPtr = nint_objc_msgSend(nsString, "stringWithUTF8String:", aString);
|
||||
}
|
||||
|
||||
public static implicit operator IntPtr(NSString nsString) => nsString.StrPtr;
|
||||
public static implicit operator nint(NSString nsString) => nsString.StrPtr;
|
||||
}
|
||||
|
||||
public readonly struct NSPoint
|
||||
|
||||
@@ -9,13 +9,13 @@ namespace Ryujinx.UI.Common.Helper
|
||||
public static partial class OpenHelper
|
||||
{
|
||||
[LibraryImport("shell32.dll", SetLastError = true)]
|
||||
private static partial int SHOpenFolderAndSelectItems(IntPtr pidlFolder, uint cidl, IntPtr apidl, uint dwFlags);
|
||||
private static partial int SHOpenFolderAndSelectItems(nint pidlFolder, uint cidl, nint apidl, uint dwFlags);
|
||||
|
||||
[LibraryImport("shell32.dll", SetLastError = true)]
|
||||
private static partial void ILFree(IntPtr pidlList);
|
||||
private static partial void ILFree(nint pidlList);
|
||||
|
||||
[LibraryImport("shell32.dll", SetLastError = true)]
|
||||
private static partial IntPtr ILCreateFromPathW([MarshalAs(UnmanagedType.LPWStr)] string pszPath);
|
||||
private static partial nint ILCreateFromPathW([MarshalAs(UnmanagedType.LPWStr)] string pszPath);
|
||||
|
||||
public static void OpenFolder(string path)
|
||||
{
|
||||
@@ -40,12 +40,12 @@ namespace Ryujinx.UI.Common.Helper
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
IntPtr pidlList = ILCreateFromPathW(path);
|
||||
if (pidlList != IntPtr.Zero)
|
||||
nint pidlList = ILCreateFromPathW(path);
|
||||
if (pidlList != nint.Zero)
|
||||
{
|
||||
try
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0));
|
||||
Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, nint.Zero, 0));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -68,11 +68,11 @@ namespace Ryujinx.UI.Common.SystemInfo
|
||||
private const string SystemLibraryName = "libSystem.dylib";
|
||||
|
||||
[LibraryImport(SystemLibraryName, SetLastError = true)]
|
||||
private static partial int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string name, IntPtr oldValue, ref ulong oldSize, IntPtr newValue, ulong newValueSize);
|
||||
private static partial int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string name, nint oldValue, ref ulong oldSize, nint newValue, ulong newValueSize);
|
||||
|
||||
private static int SysctlByName(string name, IntPtr oldValue, ref ulong oldSize)
|
||||
private static int SysctlByName(string name, nint oldValue, ref ulong oldSize)
|
||||
{
|
||||
if (sysctlbyname(name, oldValue, ref oldSize, IntPtr.Zero, 0) == -1)
|
||||
if (sysctlbyname(name, oldValue, ref oldSize, nint.Zero, 0) == -1)
|
||||
{
|
||||
int err = Marshal.GetLastWin32Error();
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Ryujinx.UI.Common.SystemInfo
|
||||
{
|
||||
ulong oldValueSize = (ulong)Unsafe.SizeOf<T>();
|
||||
|
||||
return SysctlByName(name, (IntPtr)Unsafe.AsPointer(ref oldValue), ref oldValueSize);
|
||||
return SysctlByName(name, (nint)Unsafe.AsPointer(ref oldValue), ref oldValueSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace Ryujinx.UI.Common.SystemInfo
|
||||
|
||||
ulong strSize = 0;
|
||||
|
||||
int res = SysctlByName(name, IntPtr.Zero, ref strSize);
|
||||
int res = SysctlByName(name, nint.Zero, ref strSize);
|
||||
|
||||
if (res == 0)
|
||||
{
|
||||
@@ -110,7 +110,7 @@ namespace Ryujinx.UI.Common.SystemInfo
|
||||
{
|
||||
fixed (byte* rawDataPtr = rawData)
|
||||
{
|
||||
res = SysctlByName(name, (IntPtr)rawDataPtr, ref strSize);
|
||||
res = SysctlByName(name, (nint)rawDataPtr, ref strSize);
|
||||
}
|
||||
|
||||
if (res == 0)
|
||||
|
||||
Reference in New Issue
Block a user