New v2 project structure

This commit is contained in:
Marcel Baumgartner
2024-03-18 09:31:33 +01:00
parent e20415a5bd
commit 0a807605ad
727 changed files with 51204 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using MoonCore.Helpers;
namespace Moonlight.Core.Helpers;
public static class HostSystemHelper
{
public static Task<string> GetOsName()
{
try
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Windows platform detected
var osVersion = Environment.OSVersion.Version;
return Task.FromResult($"Windows {osVersion.Major}.{osVersion.Minor}.{osVersion.Build}");
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var releaseRaw = File
.ReadAllLines("/etc/os-release")
.FirstOrDefault(x => x.StartsWith("PRETTY_NAME="));
if (string.IsNullOrEmpty(releaseRaw))
return Task.FromResult("Linux (unknown release)");
var release = releaseRaw
.Replace("PRETTY_NAME=", "")
.Replace("\"", "");
if(string.IsNullOrEmpty(release))
return Task.FromResult("Linux (unknown release)");
return Task.FromResult(release);
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
// macOS platform detected
var osVersion = Environment.OSVersion.Version;
return Task.FromResult($"macOS {osVersion.Major}.{osVersion.Minor}.{osVersion.Build}");
}
// Unknown platform
return Task.FromResult("N/A");
}
catch (Exception e)
{
Logger.Warn("Error retrieving os information");
Logger.Warn(e);
return Task.FromResult("N/A");
}
}
public static Task<long> GetMemoryUsage()
{
var process = Process.GetCurrentProcess();
var bytes = process.WorkingSet64;
return Task.FromResult(bytes);
}
public static Task<int> GetCpuUsage()
{
var process = Process.GetCurrentProcess();
var cpuTime = process.TotalProcessorTime;
var wallClockTime = DateTime.UtcNow - process.StartTime.ToUniversalTime();
var cpuUsage = (int)(100.0 * cpuTime.TotalMilliseconds / wallClockTime.TotalMilliseconds / Environment.ProcessorCount);
return Task.FromResult(cpuUsage);
}
}