From 5e6dc37aed22bd596db6a0e9c9a0527fc2a8e5b5 Mon Sep 17 00:00:00 2001 From: Ac_K Date: Tue, 1 Dec 2020 22:26:00 +0100 Subject: common: Fix last warning in SystemInfo (#1757) * common: Fix last warning in SystemInfo * info to Info * fix MacOSSystemInfo file name by delete the file * MacOSSysteminfo to MacOSSystemInfo --- Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs | 4 +- Ryujinx.Common/SystemInfo/MacOSSystemInfo.cs | 99 ++++++++++++++++++++++++++ Ryujinx.Common/SystemInfo/MacOSSysteminfo.cs | 99 -------------------------- Ryujinx.Common/SystemInfo/SystemInfo.cs | 29 +++----- Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs | 4 +- 5 files changed, 112 insertions(+), 123 deletions(-) create mode 100644 Ryujinx.Common/SystemInfo/MacOSSystemInfo.cs delete mode 100644 Ryujinx.Common/SystemInfo/MacOSSysteminfo.cs diff --git a/Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs b/Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs index c729ab3d..f067083e 100644 --- a/Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs +++ b/Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs @@ -5,12 +5,12 @@ using System.Runtime.Versioning; namespace Ryujinx.Common.SystemInfo { [SupportedOSPlatform("linux")] - internal class LinuxSysteminfo : SystemInfo + internal class LinuxSystemInfo : SystemInfo { public override string CpuName { get; } public override ulong RamSize { get; } - public LinuxSysteminfo() + public LinuxSystemInfo() { CpuName = File.ReadAllLines("/proc/cpuinfo").Where(line => line.StartsWith("model name")).ToList()[0].Split(":")[1].Trim(); RamSize = ulong.Parse(File.ReadAllLines("/proc/meminfo")[0].Split(":")[1].Trim().Split(" ")[0]) * 1024; diff --git a/Ryujinx.Common/SystemInfo/MacOSSystemInfo.cs b/Ryujinx.Common/SystemInfo/MacOSSystemInfo.cs new file mode 100644 index 00000000..ec069ca4 --- /dev/null +++ b/Ryujinx.Common/SystemInfo/MacOSSystemInfo.cs @@ -0,0 +1,99 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; +using System.Text; +using Ryujinx.Common.Logging; + +namespace Ryujinx.Common.SystemInfo +{ + [SupportedOSPlatform("macos")] + internal class MacOSSystemInfo : SystemInfo + { + public override string CpuName { get; } + public override ulong RamSize { get; } + + [DllImport("libSystem.dylib", CharSet = CharSet.Ansi, SetLastError = true)] + private static extern int sysctlbyname(string name, IntPtr oldValue, ref ulong oldSize, IntPtr newValue, ulong newValueSize); + + private static int sysctlbyname(string name, IntPtr oldValue, ref ulong oldSize) + { + if (sysctlbyname(name, oldValue, ref oldSize, IntPtr.Zero, 0) == -1) + { + return Marshal.GetLastWin32Error(); + } + + return 0; + } + + private static int sysctlbyname(string name, ref T oldValue) + { + unsafe + { + ulong oldValueSize = (ulong)Unsafe.SizeOf(); + + return sysctlbyname(name, (IntPtr)Unsafe.AsPointer(ref oldValue), ref oldValueSize); + } + } + + private static int sysctlbyname(string name, out string oldValue) + { + oldValue = default; + + ulong strSize = 0; + + int res = sysctlbyname(name, IntPtr.Zero, ref strSize); + + if (res == 0) + { + byte[] rawData = new byte[strSize]; + + unsafe + { + fixed (byte* rawDataPtr = rawData) + { + res = sysctlbyname(name, (IntPtr)rawDataPtr, ref strSize); + } + + if (res == 0) + { + oldValue = Encoding.ASCII.GetString(rawData); + } + } + } + + return res; + } + + public MacOSSystemInfo() + { + ulong ramSize = 0; + + int res = sysctlbyname("hw.memsize", ref ramSize); + + if (res == 0) + { + RamSize = ramSize; + } + else + { + Logger.Error?.Print(LogClass.Application, $"Cannot get memory size, sysctlbyname error: {res}"); + + RamSize = 0; + } + + res = sysctlbyname("machdep.cpu.brand_string", out string cpuName); + + if (res == 0) + { + CpuName = cpuName; + } + else + { + Logger.Error?.Print(LogClass.Application, $"Cannot get CPU name, sysctlbyname error: {res}"); + + CpuName = "Unknown"; + } + } + } +} \ No newline at end of file diff --git a/Ryujinx.Common/SystemInfo/MacOSSysteminfo.cs b/Ryujinx.Common/SystemInfo/MacOSSysteminfo.cs deleted file mode 100644 index 1cf18ca0..00000000 --- a/Ryujinx.Common/SystemInfo/MacOSSysteminfo.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Versioning; -using System.Text; -using Ryujinx.Common.Logging; - -namespace Ryujinx.Common.SystemInfo -{ - [SupportedOSPlatform("macos")] - internal class MacOSSysteminfo : SystemInfo - { - public override string CpuName { get; } - public override ulong RamSize { get; } - - [DllImport("libSystem.dylib", CharSet = CharSet.Ansi, SetLastError = true)] - private static extern int sysctlbyname(string name, IntPtr oldValue, ref ulong oldSize, IntPtr newValue, ulong newValueSize); - - private static int sysctlbyname(string name, IntPtr oldValue, ref ulong oldSize) - { - if (sysctlbyname(name, oldValue, ref oldSize, IntPtr.Zero, 0) == -1) - { - return Marshal.GetLastWin32Error(); - } - - return 0; - } - - private static int sysctlbyname(string name, ref T oldValue) - { - unsafe - { - ulong oldValueSize = (ulong)Unsafe.SizeOf(); - - return sysctlbyname(name, (IntPtr)Unsafe.AsPointer(ref oldValue), ref oldValueSize); - } - } - - private static int sysctlbyname(string name, out string oldValue) - { - oldValue = default; - - ulong strSize = 0; - - int res = sysctlbyname(name, IntPtr.Zero, ref strSize); - - if (res == 0) - { - byte[] rawData = new byte[strSize]; - - unsafe - { - fixed (byte* rawDataPtr = rawData) - { - res = sysctlbyname(name, (IntPtr)rawDataPtr, ref strSize); - } - - if (res == 0) - { - oldValue = Encoding.ASCII.GetString(rawData); - } - } - } - - return res; - } - - public MacOSSysteminfo() - { - ulong ramSize = 0; - - int res = sysctlbyname("hw.memsize", ref ramSize); - - if (res == 0) - { - RamSize = ramSize; - } - else - { - Logger.Error?.Print(LogClass.Application, $"Cannot get memory size, sysctlbyname error: {res}"); - - RamSize = 0; - } - - res = sysctlbyname("machdep.cpu.brand_string", out string cpuName); - - if (res == 0) - { - CpuName = cpuName; - } - else - { - Logger.Error?.Print(LogClass.Application, $"Cannot get CPU name, sysctlbyname error: {res}"); - - CpuName = "Unknown"; - } - } - } -} \ No newline at end of file diff --git a/Ryujinx.Common/SystemInfo/SystemInfo.cs b/Ryujinx.Common/SystemInfo/SystemInfo.cs index 9ab1419c..feb6b8f8 100644 --- a/Ryujinx.Common/SystemInfo/SystemInfo.cs +++ b/Ryujinx.Common/SystemInfo/SystemInfo.cs @@ -1,4 +1,5 @@ -using System.Runtime.InteropServices; +using System; +using System.Runtime.InteropServices; namespace Ryujinx.Common.SystemInfo { @@ -7,35 +8,23 @@ namespace Ryujinx.Common.SystemInfo public virtual string OsDescription => $"{RuntimeInformation.OSDescription} ({RuntimeInformation.OSArchitecture})"; public virtual string CpuName => "Unknown"; public virtual ulong RamSize => 0; - - public string RamSizeInMB - { - get - { - if (RamSize == 0) - { - return "Unknown"; - } - - return $"{RamSize / 1024 / 1024} MB"; - } - } + public string RamSizeInMB => (RamSize == 0) ? "Unknown" : $"{RamSize / 1024 / 1024} MB"; public static SystemInfo Instance { get; } static SystemInfo() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { - Instance = new WindowsSysteminfo(); + Instance = new WindowsSystemInfo(); } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (OperatingSystem.IsLinux()) { - Instance = new LinuxSysteminfo(); + Instance = new LinuxSystemInfo(); } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if (OperatingSystem.IsMacOS()) { - Instance = new MacOSSysteminfo(); + Instance = new MacOSSystemInfo(); } else { diff --git a/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs b/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs index 1b048c8e..479dd25f 100644 --- a/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs +++ b/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs @@ -7,12 +7,12 @@ using System.Runtime.Versioning; namespace Ryujinx.Common.SystemInfo { [SupportedOSPlatform("windows")] - internal class WindowsSysteminfo : SystemInfo + internal class WindowsSystemInfo : SystemInfo { public override string CpuName { get; } public override ulong RamSize { get; } - public WindowsSysteminfo() + public WindowsSystemInfo() { bool wmiNotAvailable = false; -- cgit v1.2.3