mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-11-18 01:52:19 +00:00
Port SystemEnvironment helpers from MPF
This commit is contained in:
60
SabreTools.IO/SystemEnvironment.cs
Normal file
60
SabreTools.IO/SystemEnvironment.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
#if NET5_0_OR_GREATER
|
||||
using System;
|
||||
#endif
|
||||
#if NETCOREAPP3_1
|
||||
using System.Runtime.InteropServices;
|
||||
#endif
|
||||
|
||||
namespace SabreTools.IO
|
||||
{
|
||||
/// <summary>
|
||||
/// Helpers for the system environment
|
||||
/// </summary>
|
||||
public static class SystemEnvironment
|
||||
{
|
||||
/// <summary>
|
||||
/// Determine if the current system is MacOS
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine if the current system is MacOS
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine if the current system is Windows
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user