diff options
author | Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com> | 2024-02-11 02:09:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-11 03:09:18 +0100 |
commit | f06d22d6f01e657ebbc0c8ef082739cd468e47b5 (patch) | |
tree | c10a566438d3801b33c1d7b4eff73ea62b2f1a63 /src/Ryujinx.UI.Common/SystemInfo/LinuxSystemInfo.cs | |
parent | 84d6e8d121a1b329d26cc0e462aadd1108d99a04 (diff) |
Infra: Capitalisation Consistency (#6296)1.1.1187
* Rename Ryujinx.UI.Common
* Rename Ryujinx.UI.LocaleGenerator
* Update in Files
AboutWindow
* Configuration State
* Rename projects
* Ryujinx/UI
* Fix build
* Main remaining inconsistencies
* HLE.UI Namespace
* HLE.UI Files
* Namespace
* Ryujinx.UI.Common.Configuration.UI
* Ryujinx.UI.Common,Configuration.UI Files
* More instances
Diffstat (limited to 'src/Ryujinx.UI.Common/SystemInfo/LinuxSystemInfo.cs')
-rw-r--r-- | src/Ryujinx.UI.Common/SystemInfo/LinuxSystemInfo.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/Ryujinx.UI.Common/SystemInfo/LinuxSystemInfo.cs b/src/Ryujinx.UI.Common/SystemInfo/LinuxSystemInfo.cs new file mode 100644 index 00000000..c7fe05a0 --- /dev/null +++ b/src/Ryujinx.UI.Common/SystemInfo/LinuxSystemInfo.cs @@ -0,0 +1,85 @@ +using Ryujinx.Common.Logging; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Runtime.Versioning; + +namespace Ryujinx.UI.Common.SystemInfo +{ + [SupportedOSPlatform("linux")] + class LinuxSystemInfo : SystemInfo + { + internal LinuxSystemInfo() + { + string cpuName = GetCpuidCpuName(); + + if (cpuName == null) + { + var cpuDict = new Dictionary<string, string>(StringComparer.Ordinal) + { + ["model name"] = null, + ["Processor"] = null, + ["Hardware"] = null, + }; + + ParseKeyValues("/proc/cpuinfo", cpuDict); + + cpuName = cpuDict["model name"] ?? cpuDict["Processor"] ?? cpuDict["Hardware"] ?? "Unknown"; + } + + var memDict = new Dictionary<string, string>(StringComparer.Ordinal) + { + ["MemTotal"] = null, + ["MemAvailable"] = null, + }; + + ParseKeyValues("/proc/meminfo", memDict); + + // Entries are in KiB + ulong.TryParse(memDict["MemTotal"]?.Split(' ')[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out ulong totalKiB); + ulong.TryParse(memDict["MemAvailable"]?.Split(' ')[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out ulong availableKiB); + + CpuName = $"{cpuName} ; {LogicalCoreCount} logical"; + RamTotal = totalKiB * 1024; + RamAvailable = availableKiB * 1024; + } + + private static void ParseKeyValues(string filePath, Dictionary<string, string> itemDict) + { + if (!File.Exists(filePath)) + { + Logger.Error?.Print(LogClass.Application, $"File \"{filePath}\" not found"); + + return; + } + + int count = itemDict.Count; + + using StreamReader file = new(filePath); + + string line; + while ((line = file.ReadLine()) != null) + { + string[] kvPair = line.Split(':', 2, StringSplitOptions.TrimEntries); + + if (kvPair.Length < 2) + { + continue; + } + + string key = kvPair[0]; + + if (itemDict.TryGetValue(key, out string value) && value == null) + { + itemDict[key] = kvPair[1]; + + if (--count <= 0) + { + break; + } + } + } + } + } +} |