aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2020-07-30 21:02:06 +0200
committerGitHub <noreply@github.com>2020-07-30 21:02:06 +0200
commit16bab8fb886673608d950a765f07a706cb506103 (patch)
treee6dc00eabaca4af0b7e92db99be6d4e6e1ce7194
parent9878fc2d3cf4c64f56c44c2a5de013acb6bcbade (diff)
common: Fix WMI exception (#1422)
* common: Fix WMI exception We currently don't check if WMI service is available when we get the CPU name and the RAM size. This fix the issue by catching all exceptions and set default values instead. Close #1353 * remove useless assign * Fix Exception * Address comments Co-authored-by: Thog <me@thog.eu>
-rw-r--r--Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs31
1 files changed, 27 insertions, 4 deletions
diff --git a/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs b/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs
index 1d4e61fa..6bbed215 100644
--- a/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs
+++ b/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs
@@ -1,4 +1,7 @@
+using Ryujinx.Common.Logging;
+using System;
using System.Management;
+using System.Runtime.InteropServices;
namespace Ryujinx.Common.SystemInfo
{
@@ -9,14 +12,34 @@ namespace Ryujinx.Common.SystemInfo
public WindowsSysteminfo()
{
- foreach (ManagementBaseObject mObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor").Get())
+ bool wmiNotAvailable = false;
+
+ try
+ {
+ foreach (ManagementBaseObject mObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor").Get())
+ {
+ CpuName = mObject["Name"].ToString();
+ }
+
+ foreach (ManagementBaseObject mObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem").Get())
+ {
+ RamSize = ulong.Parse(mObject["TotalVisibleMemorySize"].ToString()) * 1024;
+ }
+ }
+ catch (PlatformNotSupportedException)
{
- CpuName = mObject["Name"].ToString();
+ wmiNotAvailable = true;
+ }
+ catch (COMException)
+ {
+ wmiNotAvailable = true;
}
- foreach (ManagementBaseObject mObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem").Get())
+ if (wmiNotAvailable)
{
- RamSize = ulong.Parse(mObject["TotalVisibleMemorySize"].ToString()) * 1024;
+ Logger.PrintError(LogClass.Application, "WMI isn't available, system informations will use default values.");
+
+ CpuName = "Unknown";
}
}
}