using System.IO;
namespace Sandbox.Engine;
public static class SystemInfo
{
static DriveInfo _driveInfo;
static SystemInfo()
{
UpdateDriveInfo();
}
// I am worried about this taking like 4 seconds to run or something
static void UpdateDriveInfo()
{
_driveInfo = new DriveInfo( Path.GetPathRoot( System.Environment.CurrentDirectory ) );
StorageSizeAvailable = _driveInfo.AvailableFreeSpace;
StorageSizeTotal = _driveInfo.TotalSize;
}
///
/// Human-readable product name of this system's processor.
///
public static string ProcessorName { get; private set; } = "unset";
///
/// The frequency of this system's processor in GHz.
///
public static float ProcessorFrequency { get; private set; } = 0;
///
/// The number of logical processors in this system.
///
public static float ProcessorCount { get; private set; } = 0;
///
/// Total physical memory available on this machine, in bytes.
///
public static ulong TotalMemory { get; private set; } = 0;
///
/// Human-readable product name of the graphics card in this system.
///
public static string Gpu { get; private set; } = "unset";
///
/// The version number of the graphics card driver.
///
public static string GpuVersion { get; private set; } = "unset";
///
/// Total VRAM on this system's graphics card.
///
public static ulong GpuMemory { get; private set; } = 0;
internal static void Set( string cpu, ushort processorCount, ulong frequency, ulong memory )
{
ProcessorName = cpu;
ProcessorFrequency = frequency / 1000000000.0f; // cycles/sec -> GHz
ProcessorCount = processorCount;
TotalMemory = memory;
}
internal static void SetGpu( string driver, string version, ulong memory )
{
Gpu = driver;
GpuVersion = version;
GpuMemory = memory;
}
///
/// Indicates the amount of available free space on game drive in bytes
///
public static long StorageSizeAvailable { get; private set; }
///
/// Gets the total size of storage space on game drive in bytes
///
public static long StorageSizeTotal { get; private set; }
///
/// Return as an object, for sending to backends
///
internal static object AsObject()
{
return new
{
SystemInfo.ProcessorName,
SystemInfo.ProcessorCount,
SystemInfo.ProcessorFrequency,
SystemInfo.Gpu,
SystemInfo.GpuVersion,
GpuMb = SystemInfo.GpuMemory / (1024 * 1024),
RamMb = SystemInfo.TotalMemory / (1024 * 1024),
StorageSizeAvailable,
StorageSizeTotal
};
}
}