From 4bccaa8ecf296e56b35f5d10455302acbf2b5bd1 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 23 Feb 2023 22:29:26 -0500 Subject: [PATCH] Introduce cross-platform MMI --- CHANGELIST.md | 1 + MPF.Core/Data/Drive.cs | 22 +++++++++------------- MPF.Core/MPF.Core.csproj | 1 + 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 60bc43f1..3ce4f81b 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -60,6 +60,7 @@ - Fix other `-windows` places for .NET 6 - Fix typo in DICMultiSectorReadValue - Semi-unify drive finding +- Introduce cross-platform MMI ### 2.4 (2022-10-26) diff --git a/MPF.Core/Data/Drive.cs b/MPF.Core/Data/Drive.cs index 5df2983b..a7c3d102 100644 --- a/MPF.Core/Data/Drive.cs +++ b/MPF.Core/Data/Drive.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Management.Infrastructure; +using Microsoft.Management.Infrastructure.Generic; using MPF.Core.Converters; using MPF.Core.Utilities; using RedumpLib.Data; @@ -211,7 +213,7 @@ namespace MPF.Core.Data { return RedumpSystem.MattelFisherPriceiXL; } - + // Microsoft Xbox 360 try { @@ -522,22 +524,18 @@ namespace MPF.Core.Data .Select(d => Create(EnumConverter.ToInternalDriveType(d.DriveType), d.Name)) .ToList(); - #if NETFRAMEWORK - - // Get the floppy drives and set the flag from removable try { - ManagementObjectSearcher searcher = - new ManagementObjectSearcher("root\\CIMV2", - "SELECT * FROM Win32_LogicalDisk"); + CimSession session = CimSession.Create(null); + var collection = session.QueryInstances("root\\CIMV2", "WQL", "SELECT * FROM Win32_LogicalDisk"); - var collection = searcher.Get(); - foreach (ManagementObject queryObj in collection) + foreach (CimInstance instance in collection) { - uint? mediaType = (uint?)queryObj["MediaType"]; + CimKeyedCollection properties = instance.CimInstanceProperties; + uint? mediaType = properties["MediaType"]?.Value as uint?; if (mediaType != null && ((mediaType > 0 && mediaType < 11) || (mediaType > 12 && mediaType < 22))) { - char devId = queryObj["DeviceID"].ToString()[0]; + char devId = (properties["Caption"].Value as string)[0]; drives.ForEach(d => { if (d.Letter == devId) { d.InternalDriveType = Data.InternalDriveType.Floppy; } }); } } @@ -547,8 +545,6 @@ namespace MPF.Core.Data // No-op } - #endif - return drives; } diff --git a/MPF.Core/MPF.Core.csproj b/MPF.Core/MPF.Core.csproj index e79845bc..2026e538 100644 --- a/MPF.Core/MPF.Core.csproj +++ b/MPF.Core/MPF.Core.csproj @@ -45,6 +45,7 @@ +