mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Fix Windows list-devices not showing SD and MMC as supported.
This commit is contained in:
@@ -37,23 +37,22 @@ using System.Linq;
|
||||
using System.Management;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
static class ListDevices
|
||||
internal static class ListDevices
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a hex dump string to the ASCII string it represents
|
||||
/// </summary>
|
||||
/// <param name="hex">Hex dump</param>
|
||||
/// <returns>Decoded string</returns>
|
||||
static string HexStringToString(string hex)
|
||||
private static string HexStringToString(string hex)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
var result = new StringBuilder();
|
||||
const string HEXTABLE = "0123456789abcdef";
|
||||
|
||||
for(int i = 0; i < hex.Length / 2; i++)
|
||||
for (var i = 0; i < hex.Length / 2; i++)
|
||||
result.Append((char) (16 * HEXTABLE.IndexOf(hex[2 * i]) + HEXTABLE.IndexOf(hex[2 * i + 1])));
|
||||
|
||||
return result.ToString();
|
||||
@@ -66,13 +65,13 @@ namespace DiscImageChef.Devices.Windows
|
||||
[SuppressMessage("ReSharper", "RedundantCatchClause")]
|
||||
internal static DeviceInfo[] GetList()
|
||||
{
|
||||
List<string> deviceIDs = new List<string>();
|
||||
var deviceIDs = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
ManagementObjectSearcher mgmtObjSearcher =
|
||||
var mgmtObjSearcher =
|
||||
new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
|
||||
ManagementObjectCollection objCol = mgmtObjSearcher.Get();
|
||||
var objCol = mgmtObjSearcher.Get();
|
||||
|
||||
deviceIDs.AddRange(from ManagementObject drive in objCol select (string) drive["DeviceID"]);
|
||||
|
||||
@@ -95,20 +94,20 @@ namespace DiscImageChef.Devices.Windows
|
||||
#endif
|
||||
}
|
||||
|
||||
List<DeviceInfo> devList = new List<DeviceInfo>();
|
||||
var devList = new List<DeviceInfo>();
|
||||
|
||||
foreach(string devId in deviceIDs)
|
||||
foreach (var devId in deviceIDs)
|
||||
{
|
||||
if (devId is null) continue;
|
||||
|
||||
string physId = devId;
|
||||
var physId = devId;
|
||||
// TODO: This can be done better
|
||||
if (devId.Length == 2 && devId[1] == ':') physId = "\\\\?\\" + devId;
|
||||
SafeFileHandle fd = Extern.CreateFile(physId, 0, FileShare.Read | FileShare.Write, IntPtr.Zero,
|
||||
var fd = Extern.CreateFile(physId, 0, FileShare.Read | FileShare.Write, IntPtr.Zero,
|
||||
FileMode.OpenExisting, 0, IntPtr.Zero);
|
||||
if (fd.IsInvalid) continue;
|
||||
|
||||
StoragePropertyQuery query = new StoragePropertyQuery
|
||||
var query = new StoragePropertyQuery
|
||||
{
|
||||
PropertyId = StoragePropertyId.Device,
|
||||
QueryType = StorageQueryType.Standard,
|
||||
@@ -118,13 +117,13 @@ namespace DiscImageChef.Devices.Windows
|
||||
//StorageDeviceDescriptor descriptor = new StorageDeviceDescriptor();
|
||||
//descriptor.RawDeviceProperties = new byte[16384];
|
||||
|
||||
IntPtr descriptorPtr = Marshal.AllocHGlobal(1000);
|
||||
byte[] descriptorB = new byte[1000];
|
||||
var descriptorPtr = Marshal.AllocHGlobal(1000);
|
||||
var descriptorB = new byte[1000];
|
||||
|
||||
uint returned = 0;
|
||||
int error = 0;
|
||||
var error = 0;
|
||||
|
||||
bool hasError = !Extern.DeviceIoControlStorageQuery(fd, WindowsIoctl.IoctlStorageQueryProperty,
|
||||
var hasError = !Extern.DeviceIoControlStorageQuery(fd, WindowsIoctl.IoctlStorageQueryProperty,
|
||||
ref query, (uint) Marshal.SizeOf(query),
|
||||
descriptorPtr, 1000, ref returned, IntPtr.Zero);
|
||||
|
||||
@@ -134,7 +133,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
if (hasError && error != 0) continue;
|
||||
|
||||
StorageDeviceDescriptor descriptor = new StorageDeviceDescriptor
|
||||
var descriptor = new StorageDeviceDescriptor
|
||||
{
|
||||
Version = BitConverter.ToUInt32(descriptorB, 0),
|
||||
Size = BitConverter.ToUInt32(descriptorB, 4),
|
||||
@@ -150,7 +149,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
RawPropertiesLength = BitConverter.ToUInt32(descriptorB, 32)
|
||||
};
|
||||
|
||||
DeviceInfo info = new DeviceInfo {Path = physId, Bus = descriptor.BusType.ToString()};
|
||||
var info = new DeviceInfo {Path = physId, Bus = descriptor.BusType.ToString()};
|
||||
|
||||
if (descriptor.VendorIdOffset > 0)
|
||||
info.Vendor =
|
||||
@@ -171,7 +170,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
if ((string.IsNullOrEmpty(info.Vendor) || info.Vendor == "ATA") && info.Model != null)
|
||||
{
|
||||
string[] pieces = info.Model.Split(' ');
|
||||
var pieces = info.Model.Split(' ');
|
||||
if (pieces.Length > 1)
|
||||
{
|
||||
info.Vendor = pieces[0];
|
||||
@@ -191,6 +190,8 @@ namespace DiscImageChef.Devices.Windows
|
||||
case StorageBusType.iSCSI:
|
||||
case StorageBusType.SAS:
|
||||
case StorageBusType.SATA:
|
||||
case StorageBusType.SecureDigital:
|
||||
case StorageBusType.MultiMediaCard:
|
||||
info.Supported = true;
|
||||
break;
|
||||
}
|
||||
@@ -199,7 +200,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
devList.Add(info);
|
||||
}
|
||||
|
||||
DeviceInfo[] devices = devList.ToArray();
|
||||
var devices = devList.ToArray();
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
|
||||
<Import Project="..\packages\Unclassified.NetRevisionTask.0.2.5\build\Unclassified.NetRevisionTask.props" Condition="Exists('..\packages\Unclassified.NetRevisionTask.0.2.5\build\Unclassified.NetRevisionTask.props')" />
|
||||
|
||||
Reference in New Issue
Block a user