From a9e228a91b338526bceca47004b66630e346ff45 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 26 Mar 2022 17:12:08 +0000 Subject: [PATCH] Add new official .NET guards for OS dependant code. --- Aaru.Devices/Device/List.cs | 17 +++++++++-------- Aaru.Devices/Linux/ListDevices.cs | 1 + Aaru.Devices/Windows/ListDevices.cs | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Aaru.Devices/Device/List.cs b/Aaru.Devices/Device/List.cs index 5cb1dc851..0a60ad7fe 100644 --- a/Aaru.Devices/Device/List.cs +++ b/Aaru.Devices/Device/List.cs @@ -36,7 +36,6 @@ using System; using System.Runtime.InteropServices; using Aaru.CommonTypes.Interop; using Aaru.Console; -using PlatformID = Aaru.CommonTypes.Interop.PlatformID; /// Contains device information [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] @@ -102,13 +101,15 @@ public sealed partial class Device serverArchitecture = null; if(aaruRemote is null) - switch(DetectOS.GetRealPlatformID()) - { - case PlatformID.Win32NT: return Windows.ListDevices.GetList(); - case PlatformID.Linux: return Linux.ListDevices.GetList(); - default: - throw new InvalidOperationException($"Platform {DetectOS.GetRealPlatformID()} not yet supported."); - } + { + if(OperatingSystem.IsWindows()) + return Windows.ListDevices.GetList(); + + if(OperatingSystem.IsLinux()) + return Linux.ListDevices.GetList(); + + throw new InvalidOperationException($"Platform {DetectOS.GetRealPlatformID()} not yet supported."); + } try { diff --git a/Aaru.Devices/Linux/ListDevices.cs b/Aaru.Devices/Linux/ListDevices.cs index 466ff6aa8..61441e027 100644 --- a/Aaru.Devices/Linux/ListDevices.cs +++ b/Aaru.Devices/Linux/ListDevices.cs @@ -36,6 +36,7 @@ using System; using System.IO; using System.Text; +[System.Runtime.Versioning.SupportedOSPlatform("linux")] static class ListDevices { const string PATH_SYS_DEVBLOCK = "/sys/block/"; diff --git a/Aaru.Devices/Windows/ListDevices.cs b/Aaru.Devices/Windows/ListDevices.cs index 5e39568fc..251992dfb 100644 --- a/Aaru.Devices/Windows/ListDevices.cs +++ b/Aaru.Devices/Windows/ListDevices.cs @@ -42,6 +42,7 @@ using Aaru.Helpers; using Microsoft.Win32.SafeHandles; using Marshal = System.Runtime.InteropServices.Marshal; +[System.Runtime.Versioning.SupportedOSPlatform("windows")] static class ListDevices { /// Converts a hex dump string to the ASCII string it represents