WindowsSystemInfo.cs 1.4 KB

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