diff --git a/ARMeilleure/CodeGen/X86/CallingConvention.cs b/ARMeilleure/CodeGen/X86/CallingConvention.cs index 2769fd93..74799623 100644 --- a/ARMeilleure/CodeGen/X86/CallingConvention.cs +++ b/ARMeilleure/CodeGen/X86/CallingConvention.cs @@ -151,7 +151,7 @@ namespace ARMeilleure.CodeGen.X86 public static CallConvName GetCurrentCallConv() { - return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + return OperatingSystem.IsWindows() ? CallConvName.Windows : CallConvName.SystemV; } diff --git a/ARMeilleure/Signal/NativeSignalHandler.cs b/ARMeilleure/Signal/NativeSignalHandler.cs index babc7d42..9f14dd6b 100644 --- a/ARMeilleure/Signal/NativeSignalHandler.cs +++ b/ARMeilleure/Signal/NativeSignalHandler.cs @@ -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) diff --git a/ARMeilleure/Translation/Cache/JitCache.cs b/ARMeilleure/Translation/Cache/JitCache.cs index c0d0a25d..24affa34 100644 --- a/ARMeilleure/Translation/Cache/JitCache.cs +++ b/ARMeilleure/Translation/Cache/JitCache.cs @@ -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)); } diff --git a/ARMeilleure/Translation/PTC/Ptc.cs b/ARMeilleure/Translation/PTC/Ptc.cs index 8e5349e5..04cab561 100644 --- a/ARMeilleure/Translation/PTC/Ptc.cs +++ b/ARMeilleure/Translation/PTC/Ptc.cs @@ -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; } diff --git a/Ryujinx.Common/System/DisplaySleep.cs b/Ryujinx.Common/System/DisplaySleep.cs index 77f9dd75..bad964b9 100644 --- a/Ryujinx.Common/System/DisplaySleep.cs +++ b/Ryujinx.Common/System/DisplaySleep.cs @@ -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); } diff --git a/Ryujinx.Common/System/WindowsMultimediaTimerResolution.cs b/Ryujinx.Common/System/WindowsMultimediaTimerResolution.cs index 69ce145b..d19fbe73 100644 --- a/Ryujinx.Common/System/WindowsMultimediaTimerResolution.cs +++ b/Ryujinx.Common/System/WindowsMultimediaTimerResolution.cs @@ -2,12 +2,14 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace Ryujinx.Common.System { /// /// Handle Windows Multimedia timer resolution. /// + [SupportedOSPlatform("windows")] public class WindowsMultimediaTimerResolution : IDisposable { [StructLayout(LayoutKind.Sequential)] diff --git a/Ryujinx.Headless.SDL2/Program.cs b/Ryujinx.Headless.SDL2/Program.cs index 508daae5..39dbddcd 100644 --- a/Ryujinx.Headless.SDL2/Program.cs +++ b/Ryujinx.Headless.SDL2/Program.cs @@ -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) diff --git a/Ryujinx.Memory/MemoryManagement.cs b/Ryujinx.Memory/MemoryManagement.cs index 3e5ec341..680969b6 100644 --- a/Ryujinx.Memory/MemoryManagement.cs +++ b/Ryujinx.Memory/MemoryManagement.cs @@ -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); } diff --git a/Ryujinx.Memory/MemoryManagementUnix.cs b/Ryujinx.Memory/MemoryManagementUnix.cs index 69852787..edfc98dd 100644 --- a/Ryujinx.Memory/MemoryManagementUnix.cs +++ b/Ryujinx.Memory/MemoryManagementUnix.cs @@ -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 diff --git a/Ryujinx.Memory/MemoryManagementWindows.cs b/Ryujinx.Memory/MemoryManagementWindows.cs index b14fb6c1..48616ec3 100644 --- a/Ryujinx.Memory/MemoryManagementWindows.cs +++ b/Ryujinx.Memory/MemoryManagementWindows.cs @@ -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) diff --git a/Ryujinx/Modules/Updater/UpdateDialog.cs b/Ryujinx/Modules/Updater/UpdateDialog.cs index 81727769..804f7ab5 100644 --- a/Ryujinx/Modules/Updater/UpdateDialog.cs +++ b/Ryujinx/Modules/Updater/UpdateDialog.cs @@ -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()); diff --git a/Ryujinx/Modules/Updater/Updater.cs b/Ryujinx/Modules/Updater/Updater.cs index 320928e4..933e59d8 100644 --- a/Ryujinx/Modules/Updater/Updater.cs +++ b/Ryujinx/Modules/Updater/Updater.cs @@ -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) { diff --git a/Ryujinx/Program.cs b/Ryujinx/Program.cs index 5b67e2b9..a4528fb0 100644 --- a/Ryujinx/Program.cs +++ b/Ryujinx/Program.cs @@ -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. diff --git a/Ryujinx/Ui/GLRenderer.cs b/Ryujinx/Ui/GLRenderer.cs index e10c03a3..6d392020 100644 --- a/Ryujinx/Ui/GLRenderer.cs +++ b/Ryujinx/Ui/GLRenderer.cs @@ -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); diff --git a/Ryujinx/Ui/Helper/OpenHelper.cs b/Ryujinx/Ui/Helper/OpenHelper.cs index 6ccf4de3..2b25d8f3 100644 --- a/Ryujinx/Ui/Helper/OpenHelper.cs +++ b/Ryujinx/Ui/Helper/OpenHelper.cs @@ -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); } diff --git a/Ryujinx/Ui/MainWindow.cs b/Ryujinx/Ui/MainWindow.cs index 519e0287..c399400a 100644 --- a/Ryujinx/Ui/MainWindow.cs +++ b/Ryujinx/Ui/MainWindow.cs @@ -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); } diff --git a/Ryujinx/Ui/VKRenderer.cs b/Ryujinx/Ui/VKRenderer.cs index 7b01f709..ac7801ee 100644 --- a/Ryujinx/Ui/VKRenderer.cs +++ b/Ryujinx/Ui/VKRenderer.cs @@ -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);