misc: Migrate usage of RuntimeInformation to OperatingSystem (#2901)
Very basic migration across the codebase.
This commit is contained in:
parent
7c9360d393
commit
f39fce8f54
17 changed files with 77 additions and 68 deletions
|
@ -151,7 +151,7 @@ namespace ARMeilleure.CodeGen.X86
|
|||
|
||||
public static CallConvName GetCurrentCallConv()
|
||||
{
|
||||
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||
return OperatingSystem.IsWindows()
|
||||
? CallConvName.Windows
|
||||
: CallConvName.SystemV;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace ARMeilleure.Signal
|
|||
{
|
||||
if (_initialized) return;
|
||||
|
||||
bool unix = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||
bool unix = OperatingSystem.IsLinux() || OperatingSystem.IsMacOS();
|
||||
ref SignalHandlerConfig config = ref GetConfigRef();
|
||||
|
||||
if (unix)
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace ARMeilleure.Translation.Cache
|
|||
|
||||
_cacheAllocator = new CacheMemoryAllocator(CacheSize);
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
JitUnwindWindows.InstallFunctionTableHandler(_jitRegion.Pointer, CacheSize, _jitRegion.Pointer + Allocate(PageSize));
|
||||
}
|
||||
|
|
|
@ -960,10 +960,10 @@ namespace ARMeilleure.Translation.PTC
|
|||
{
|
||||
uint osPlatform = 0u;
|
||||
|
||||
osPlatform |= (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD) ? 1u : 0u) << 0;
|
||||
osPlatform |= (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? 1u : 0u) << 1;
|
||||
osPlatform |= (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 1u : 0u) << 2;
|
||||
osPlatform |= (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 1u : 0u) << 3;
|
||||
osPlatform |= (OperatingSystem.IsFreeBSD() ? 1u : 0u) << 0;
|
||||
osPlatform |= (OperatingSystem.IsLinux() ? 1u : 0u) << 1;
|
||||
osPlatform |= (OperatingSystem.IsMacOS() ? 1u : 0u) << 2;
|
||||
osPlatform |= (OperatingSystem.IsWindows() ? 1u : 0u) << 3;
|
||||
|
||||
return osPlatform;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Ryujinx.Common.System
|
|||
|
||||
static public void Prevent()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace Ryujinx.Common.System
|
|||
|
||||
static public void Restore()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Common.System
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle Windows Multimedia timer resolution.
|
||||
/// </summary>
|
||||
[SupportedOSPlatform("windows")]
|
||||
public class WindowsMultimediaTimerResolution : IDisposable
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
|
|
@ -28,7 +28,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
||||
|
@ -473,7 +472,7 @@ namespace Ryujinx.Headless.SDL2
|
|||
|
||||
private static void ExecutionEntrypoint()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
_windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
|
||||
}
|
||||
|
@ -490,8 +489,11 @@ namespace Ryujinx.Headless.SDL2
|
|||
_emulationContext.Dispose();
|
||||
_window.Dispose();
|
||||
|
||||
_windowsMultimediaTimerResolution?.Dispose();
|
||||
_windowsMultimediaTimerResolution = null;
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
_windowsMultimediaTimerResolution?.Dispose();
|
||||
_windowsMultimediaTimerResolution = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool LoadApplication(Options options)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Memory
|
||||
{
|
||||
|
@ -7,14 +6,14 @@ namespace Ryujinx.Memory
|
|||
{
|
||||
public static IntPtr Allocate(ulong size)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
IntPtr sizeNint = new IntPtr((long)size);
|
||||
|
||||
return MemoryManagementWindows.Allocate(sizeNint);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Allocate(size);
|
||||
}
|
||||
|
@ -26,14 +25,14 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static IntPtr Reserve(ulong size)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
IntPtr sizeNint = new IntPtr((long)size);
|
||||
|
||||
return MemoryManagementWindows.Reserve(sizeNint);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Reserve(size);
|
||||
}
|
||||
|
@ -45,14 +44,14 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static bool Commit(IntPtr address, ulong size)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
IntPtr sizeNint = new IntPtr((long)size);
|
||||
|
||||
return MemoryManagementWindows.Commit(address, sizeNint);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Commit(address, size);
|
||||
}
|
||||
|
@ -64,14 +63,14 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static bool Decommit(IntPtr address, ulong size)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
IntPtr sizeNint = new IntPtr((long)size);
|
||||
|
||||
return MemoryManagementWindows.Decommit(address, sizeNint);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Decommit(address, size);
|
||||
}
|
||||
|
@ -85,14 +84,14 @@ namespace Ryujinx.Memory
|
|||
{
|
||||
bool result;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
IntPtr sizeNint = new IntPtr((long)size);
|
||||
|
||||
result = MemoryManagementWindows.Reprotect(address, sizeNint, permission);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
result = MemoryManagementUnix.Reprotect(address, size, permission);
|
||||
}
|
||||
|
@ -109,12 +108,12 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static bool Free(IntPtr address)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
return MemoryManagementWindows.Free(address);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Free(address);
|
||||
}
|
||||
|
@ -126,14 +125,14 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static IntPtr CreateSharedMemory(ulong size, bool reserve)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
IntPtr sizeNint = new IntPtr((long)size);
|
||||
|
||||
return MemoryManagementWindows.CreateSharedMemory(sizeNint, reserve);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.CreateSharedMemory(size, reserve);
|
||||
}
|
||||
|
@ -145,12 +144,12 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static void DestroySharedMemory(IntPtr handle)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
MemoryManagementWindows.DestroySharedMemory(handle);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
MemoryManagementUnix.DestroySharedMemory(handle);
|
||||
}
|
||||
|
@ -162,12 +161,12 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static IntPtr MapSharedMemory(IntPtr handle)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
return MemoryManagementWindows.MapSharedMemory(handle);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.MapSharedMemory(handle);
|
||||
}
|
||||
|
@ -179,12 +178,12 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static void UnmapSharedMemory(IntPtr address)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
MemoryManagementWindows.UnmapSharedMemory(address);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
MemoryManagementUnix.UnmapSharedMemory(address);
|
||||
}
|
||||
|
@ -196,8 +195,8 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static IntPtr Remap(IntPtr target, IntPtr source, ulong size)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Remap(target, source, size);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,12 @@ using System;
|
|||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Memory
|
||||
{
|
||||
[SupportedOSPlatform("linux")]
|
||||
[SupportedOSPlatform("macos")]
|
||||
static class MemoryManagementUnix
|
||||
{
|
||||
private struct UnixSharedMemory
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Memory
|
||||
{
|
||||
[SupportedOSPlatform("windows")]
|
||||
static class MemoryManagementWindows
|
||||
{
|
||||
private static readonly IntPtr InvalidHandleValue = new IntPtr(-1);
|
||||
|
@ -59,9 +61,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
static MemoryManagementWindows()
|
||||
{
|
||||
Version version = Environment.OSVersion.Version;
|
||||
|
||||
UseWin10Placeholders = (version.Major == 10 && version.Build >= 17134) || version.Major > 10;
|
||||
UseWin10Placeholders = OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134);
|
||||
}
|
||||
|
||||
public static IntPtr Allocate(IntPtr size)
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace Ryujinx.Modules
|
|||
{
|
||||
if (_restartQuery)
|
||||
{
|
||||
string ryuName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Ryujinx.exe" : "Ryujinx";
|
||||
string ryuName = OperatingSystem.IsWindows() ? "Ryujinx.exe" : "Ryujinx";
|
||||
string ryuExe = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ryuName);
|
||||
string ryuArg = string.Join(" ", Environment.GetCommandLineArgs().AsEnumerable().Skip(1).ToArray());
|
||||
|
||||
|
|
|
@ -51,17 +51,17 @@ namespace Ryujinx.Modules
|
|||
int artifactIndex = -1;
|
||||
|
||||
// Detect current platform
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
_platformExt = "osx_x64.zip";
|
||||
artifactIndex = 1;
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
else if (OperatingSystem.IsWindows())
|
||||
{
|
||||
_platformExt = "win_x64.zip";
|
||||
artifactIndex = 2;
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
_platformExt = "linux_x64.tar.gz";
|
||||
artifactIndex = 0;
|
||||
|
@ -372,7 +372,7 @@ namespace Ryujinx.Modules
|
|||
updateDialog.MainText.Text = "Extracting Update...";
|
||||
updateDialog.ProgressBar.Value = 0;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
using (Stream inStream = File.OpenRead(updateFile))
|
||||
using (Stream gzipStream = new GZipInputStream(inStream))
|
||||
|
@ -545,7 +545,7 @@ namespace Ryujinx.Modules
|
|||
{
|
||||
var files = Directory.EnumerateFiles(HomeDir); // All files directly in base dir.
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
foreach (string dir in WindowsDependencyDirs)
|
||||
{
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Ryujinx
|
|||
}
|
||||
}
|
||||
|
||||
// Enforce loading of Mono.Posix.NETStandard to avoid .NET runtime lazy loading it during an update.
|
||||
// Enforce loading of Mono.Posix to avoid .NET runtime lazy loading it during an update.
|
||||
Assembly.Load("Mono.Posix.NETStandard");
|
||||
|
||||
// Make process DPI aware for proper window sizing on high-res screens.
|
||||
|
|
|
@ -59,13 +59,13 @@ namespace Ryujinx.Ui
|
|||
|
||||
private SwappableNativeWindowBase RetrieveNativeWindow()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
IntPtr windowHandle = gdk_win32_window_get_handle(Window.Handle);
|
||||
|
||||
return new WGLWindow(new NativeHandle(windowHandle));
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
IntPtr displayHandle = gdk_x11_display_get_xdisplay(Display.Handle);
|
||||
IntPtr windowHandle = gdk_x11_window_get_xid(Window.Handle);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Ryujinx.Common.Logging;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Ui.Helper
|
||||
{
|
||||
|
@ -18,15 +18,15 @@ namespace Ryujinx.Ui.Helper
|
|||
|
||||
public static void OpenUrl(string url)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
Process.Start(new ProcessStartInfo("cmd", $"/c start {url.Replace("&", "^&")}"));
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
Process.Start("xdg-open", url);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
Process.Start("open", url);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -909,8 +908,12 @@ namespace Ryujinx.Ui
|
|||
|
||||
RendererWidget.Dispose();
|
||||
|
||||
_windowsMultimediaTimerResolution?.Dispose();
|
||||
_windowsMultimediaTimerResolution = null;
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
_windowsMultimediaTimerResolution?.Dispose();
|
||||
_windowsMultimediaTimerResolution = null;
|
||||
}
|
||||
|
||||
DisplaySleep.Restore();
|
||||
|
||||
_viewBox.Remove(RendererWidget);
|
||||
|
@ -941,7 +944,7 @@ namespace Ryujinx.Ui
|
|||
|
||||
private void CreateGameWindow()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
_windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@ namespace Ryujinx.Ui
|
|||
|
||||
private NativeWindowBase RetrieveNativeWindow()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
IntPtr windowHandle = gdk_win32_window_get_handle(Window.Handle);
|
||||
|
||||
return new SimpleWin32Window(new NativeHandle(windowHandle));
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
IntPtr displayHandle = gdk_x11_display_get_xdisplay(Display.Handle);
|
||||
IntPtr windowHandle = gdk_x11_window_get_xid(Window.Handle);
|
||||
|
|
Loading…
Reference in a new issue