From ffd0d224025b19d539f0247e2884d44df94db94a Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 14 Oct 2026 21:21:04 -0400 Subject: [PATCH] Port SystemEnvironment helpers from MPF --- SabreTools.IO/SystemEnvironment.cs | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 SabreTools.IO/SystemEnvironment.cs diff --git a/SabreTools.IO/SystemEnvironment.cs b/SabreTools.IO/SystemEnvironment.cs new file mode 100644 index 0000000..ad0e545 --- /dev/null +++ b/SabreTools.IO/SystemEnvironment.cs @@ -0,0 +1,60 @@ +#if NET5_0_OR_GREATER +using System; +#endif +#if NETCOREAPP3_1 +using System.Runtime.InteropServices; +#endif + +namespace SabreTools.IO +{ + /// + /// Helpers for the system environment + /// + public static class SystemEnvironment + { + /// + /// Determine if the current system is MacOS + /// + public static bool IsLinux() + { +#if NETFRAMEWORK + // .NET Framework can never be Linux + return false; +#elif NETCOREAPP3_1 + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux); +#else + return OperatingSystem.IsLinux(); +#endif + } + + /// + /// Determine if the current system is MacOS + /// + public static bool IsMacOS() + { +#if NETFRAMEWORK + // .NET Framework can never be MacOS + return false; +#elif NETCOREAPP3_1 + return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); +#else + return OperatingSystem.IsMacOS(); +#endif + } + + /// + /// Determine if the current system is Windows + /// + public static bool IsWindows() + { +#if NETFRAMEWORK + // .NET Framework is always Windows + return true; +#elif NETCOREAPP3_1 + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); +#else + return OperatingSystem.IsWindows(); +#endif + } + } +}