WindowsSystemInfo.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Ryujinx.Common.Logging;
  2. using System;
  3. using System.Management;
  4. using System.Runtime.InteropServices;
  5. using System.Runtime.Versioning;
  6. namespace Ryujinx.Common.SystemInfo
  7. {
  8. [SupportedOSPlatform("windows")]
  9. internal class WindowsSystemInfo : SystemInfo
  10. {
  11. public override string CpuName { get; }
  12. public override ulong RamSize { get; }
  13. public WindowsSystemInfo()
  14. {
  15. bool wmiNotAvailable = false;
  16. try
  17. {
  18. foreach (ManagementBaseObject mObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor").Get())
  19. {
  20. CpuName = mObject["Name"].ToString();
  21. }
  22. foreach (ManagementBaseObject mObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem").Get())
  23. {
  24. RamSize = ulong.Parse(mObject["TotalVisibleMemorySize"].ToString()) * 1024;
  25. }
  26. }
  27. catch (PlatformNotSupportedException)
  28. {
  29. wmiNotAvailable = true;
  30. }
  31. catch (COMException)
  32. {
  33. wmiNotAvailable = true;
  34. }
  35. if (wmiNotAvailable)
  36. {
  37. Logger.Error?.Print(LogClass.Application, "WMI isn't available, system informations will use default values.");
  38. CpuName = "Unknown";
  39. }
  40. }
  41. }
  42. }