mlaumcherb/Mlaumcherb.Client.Avalonia/холопы/PlatformHelper.cs
2024-11-06 00:04:12 +05:00

56 lines
1.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Runtime.InteropServices;
using Mlaumcherb.Client.Avalonia.классы;
// ReSharper disable CollectionNeverUpdated.Global
namespace Mlaumcherb.Client.Avalonia.холопы;
public static class PlatformHelper
{
public static bool CheckOs(Os os) =>
os.name switch
{
null => true,
"osx" => OperatingSystem.IsMacOS(),
"linux" => OperatingSystem.IsLinux(),
"windows" => OperatingSystem.IsWindows(),
_ => throw new ArgumentOutOfRangeException(os.name)
}
&& os.arch switch
{
null => true,
"i386" or "x86" => RuntimeInformation.OSArchitecture == Architecture.X86,
"x64" => RuntimeInformation.OSArchitecture == Architecture.X64,
"arm64" => RuntimeInformation.OSArchitecture == Architecture.Arm64,
_ => false
};
public static string GetOs() =>
Environment.OSVersion.Platform switch
{
PlatformID.Win32NT => "windows",
PlatformID.Unix => "linux",
PlatformID.MacOSX => "osx",
_ => throw new PlatformNotSupportedException("OS not supported")
};
public static string GetArch() =>
RuntimeInformation.OSArchitecture switch
{
Architecture.X86 => "x86",
Architecture.X64 => "x64",
Architecture.Arm64 => "arm64",
_ => throw new PlatformNotSupportedException("OS not supported")
};
public static string GetArchOld() =>
RuntimeInformation.OSArchitecture switch
{
Architecture.X86 => "32",
Architecture.X64 => "64",
_ => throw new PlatformNotSupportedException("OS not supported")
};
public static string GetOsAndArch() => GetOs() + '-' + GetArch();
}