0
0
Fork 0

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>
This commit is contained in:
Ac_K 2020-07-30 21:02:06 +02:00 committed by GitHub
parent 9878fc2d3c
commit 16bab8fb88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,7 @@
using Ryujinx.Common.Logging;
using System;
using System.Management; using System.Management;
using System.Runtime.InteropServices;
namespace Ryujinx.Common.SystemInfo namespace Ryujinx.Common.SystemInfo
{ {
@ -9,14 +12,34 @@ namespace Ryujinx.Common.SystemInfo
public WindowsSysteminfo() public WindowsSysteminfo()
{ {
foreach (ManagementBaseObject mObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor").Get()) bool wmiNotAvailable = false;
try
{ {
CpuName = mObject["Name"].ToString(); 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)
{
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";
} }
} }
} }