using System.Runtime.InteropServices;
namespace AtomicLib;
///
/// Class that has information about the current running operating system.
///
public static class OS
{
///
/// Determines if the current OS is Windows.
///
public static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
///
/// Determines if the current OS is Linux.
///
public static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
///
/// Determines if the current OS is Mac.
///
public static readonly bool IsMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
///
/// Determines if the current OS is a unix based system (Mac or Linux).
///
public static readonly bool IsUnix = IsLinux || IsMac;
///
/// Gets a string representation of the current OS.
///
public static readonly string Name = DetermineOsName();
///
/// Generates a string representation of the current OS
///
private static string DetermineOsName()
{
if (IsWindows)
return "Windows";
if (IsLinux)
return "Linux";
if (IsMac)
return "Mac";
return "Unknown OS";
}
///
/// Checks if this is run via WINE.
///
public static readonly bool IsThisRunningFromWINE = CheckIfRunFromWINE();
///
/// Checks if this is run via Flatpak.
///
public static readonly bool IsThisRunningFromFlatpak = CheckIfRunFromFlatpak();
///
/// Checks if the Launcher is ran from WINE.
///
/// if run from WINE, if not.
private static bool CheckIfRunFromWINE()
{
// We check for wine by seeing if a reg entry exists.
// Not the best way, and could be removed from the future, but good enough for our purposes.
#pragma warning disable CA1416
if (IsWindows && (Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Wine") != null))
return true;
#pragma warning restore CA1416
return false;
}
///
/// Checks if the Launcher is ran from a Flatpak.
///
/// if run from a Flatpak, if not.
private static bool CheckIfRunFromFlatpak()
{
if (!IsLinux) return false;
// This file is present in all flatpaks
if (File.Exists("/.flatpak-info"))
return true;
return false;
}
}