mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
REFACTOR: Use preferred braces style.
This commit is contained in:
@@ -496,7 +496,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
uint k = 0;
|
||||
if(!Extern.DeviceIoControlGetDeviceNumber(deviceHandle, WindowsIoctl.IoctlStorageGetDeviceNumber,
|
||||
IntPtr.Zero, 0, ref sdn, (uint)Marshal.SizeOf(sdn), ref k,
|
||||
IntPtr.Zero)) { return uint.MaxValue; }
|
||||
IntPtr.Zero)) return uint.MaxValue;
|
||||
|
||||
return (uint)sdn.deviceNumber;
|
||||
}
|
||||
|
||||
@@ -46,10 +46,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
StringBuilder result = new StringBuilder();
|
||||
const string hextable = "0123456789abcdef";
|
||||
|
||||
for(int i = 0; i < hex.Length / 2; i++)
|
||||
{
|
||||
result.Append((char)(16 * hextable.IndexOf(hex[2 * i]) + hextable.IndexOf(hex[2 * i + 1])));
|
||||
}
|
||||
for(int 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();
|
||||
}
|
||||
@@ -150,11 +147,8 @@ namespace DiscImageChef.Devices.Windows
|
||||
start: (int)descriptor.SerialNumberOffset);
|
||||
|
||||
// fix any serial numbers that are returned as hex-strings
|
||||
if(Array.TrueForAll(info.Serial.ToCharArray(), (char c) => "0123456789abcdef".IndexOf(c) >= 0)
|
||||
&& (info.Serial.Length == 40))
|
||||
{
|
||||
info.Serial = HexStringToString(info.Serial).Trim();
|
||||
}
|
||||
if(Array.TrueForAll(info.Serial.ToCharArray(), (char c) => "0123456789abcdef".IndexOf(c) >= 0)
|
||||
&& info.Serial.Length == 40) info.Serial = HexStringToString(info.Serial).Trim();
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(info.Vendor) || info.Vendor == "ATA")
|
||||
|
||||
@@ -532,15 +532,9 @@ namespace DiscImageChef.Devices.Windows
|
||||
int regType = REG_SZ;
|
||||
|
||||
if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, ref regType, ptrBuf,
|
||||
BUFFER_SIZE, ref requiredSize))
|
||||
{
|
||||
host.ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf);
|
||||
}
|
||||
BUFFER_SIZE, ref requiredSize)) host.ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf);
|
||||
if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf,
|
||||
BUFFER_SIZE, ref requiredSize))
|
||||
{
|
||||
host.ControllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuf);
|
||||
}
|
||||
BUFFER_SIZE, ref requiredSize)) host.ControllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuf);
|
||||
}
|
||||
hostList.Add(host);
|
||||
}
|
||||
@@ -855,7 +849,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
// return a down stream external hub
|
||||
internal UsbDevice GetDevice()
|
||||
{
|
||||
if(!PortIsDeviceConnected) { return null; }
|
||||
if(!PortIsDeviceConnected) return null;
|
||||
|
||||
UsbDevice device = new UsbDevice();
|
||||
|
||||
@@ -1011,7 +1005,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
// return a down stream external hub
|
||||
internal UsbHub GetHub()
|
||||
{
|
||||
if(!PortIsHub) { return null; }
|
||||
if(!PortIsHub) return null;
|
||||
|
||||
UsbHub hub = new UsbHub();
|
||||
IntPtr h, h2;
|
||||
@@ -1189,19 +1183,13 @@ namespace DiscImageChef.Devices.Windows
|
||||
keyName = "";
|
||||
|
||||
if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, BUFFER_SIZE,
|
||||
ref requiredSize))
|
||||
{
|
||||
keyName = Marshal.PtrToStringAuto(ptrBuf);
|
||||
}
|
||||
ref requiredSize)) keyName = Marshal.PtrToStringAuto(ptrBuf);
|
||||
|
||||
// is it a match?
|
||||
if(keyName == driverKeyName)
|
||||
{
|
||||
if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, ref regType, ptrBuf,
|
||||
BUFFER_SIZE, ref requiredSize))
|
||||
{
|
||||
ans = Marshal.PtrToStringAuto(ptrBuf);
|
||||
}
|
||||
BUFFER_SIZE, ref requiredSize)) ans = Marshal.PtrToStringAuto(ptrBuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1250,10 +1238,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
keyName = "";
|
||||
if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, BUFFER_SIZE,
|
||||
ref requiredSize))
|
||||
{
|
||||
keyName = Marshal.PtrToStringAuto(ptrBuf);
|
||||
}
|
||||
ref requiredSize)) keyName = Marshal.PtrToStringAuto(ptrBuf);
|
||||
|
||||
// is it a match?
|
||||
if(keyName == driverKeyName)
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
List<UsbDevice> devList = new List<UsbDevice>();
|
||||
|
||||
foreach(UsbController controller in GetHostControllers()) { ListHub(controller.GetRootHub(), devList); }
|
||||
foreach(UsbController controller in GetHostControllers()) ListHub(controller.GetRootHub(), devList);
|
||||
|
||||
return devList;
|
||||
}
|
||||
@@ -59,14 +59,8 @@ namespace DiscImageChef.Devices.Windows
|
||||
static void ListHub(UsbHub hub, List<UsbDevice> devList)
|
||||
{
|
||||
foreach(UsbPort port in hub.GetPorts())
|
||||
{
|
||||
if(port.IsHub)
|
||||
{
|
||||
// recursive
|
||||
ListHub(port.GetHub(), devList);
|
||||
}
|
||||
else { if(port.IsDeviceConnected) { devList.Add(port.GetDevice()); } }
|
||||
}
|
||||
if(port.IsHub) ListHub(port.GetHub(), devList);
|
||||
else { if(port.IsDeviceConnected) devList.Add(port.GetDevice()); }
|
||||
}
|
||||
|
||||
//
|
||||
@@ -89,12 +83,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
static void SearchHubDriverKeyName(UsbHub hub, ref UsbDevice foundDevice, string driverKeyName)
|
||||
{
|
||||
foreach(UsbPort port in hub.GetPorts())
|
||||
{
|
||||
if(port.IsHub)
|
||||
{
|
||||
// recursive
|
||||
SearchHubDriverKeyName(port.GetHub(), ref foundDevice, driverKeyName);
|
||||
}
|
||||
if(port.IsHub) SearchHubDriverKeyName(port.GetHub(), ref foundDevice, driverKeyName);
|
||||
else
|
||||
{
|
||||
if(port.IsDeviceConnected)
|
||||
@@ -107,7 +96,6 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -130,12 +118,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
static void SearchHubInstanceId(UsbHub hub, ref UsbDevice foundDevice, string instanceId)
|
||||
{
|
||||
foreach(UsbPort port in hub.GetPorts())
|
||||
{
|
||||
if(port.IsHub)
|
||||
{
|
||||
// recursive
|
||||
SearchHubInstanceId(port.GetHub(), ref foundDevice, instanceId);
|
||||
}
|
||||
if(port.IsHub) SearchHubInstanceId(port.GetHub(), ref foundDevice, instanceId);
|
||||
else
|
||||
{
|
||||
if(port.IsDeviceConnected)
|
||||
@@ -148,7 +131,6 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const int IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080;
|
||||
@@ -198,7 +180,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
// DriveLetter. We'll use this later to find a matching
|
||||
// DevicePath "symbolic name"
|
||||
int devNum = GetDeviceNumber(@"\\.\" + driveLetter.TrimEnd('\\'));
|
||||
if(devNum < 0) { return null; }
|
||||
if(devNum < 0) return null;
|
||||
|
||||
return FindDeviceNumber(devNum, deviceGuid);
|
||||
}
|
||||
@@ -212,7 +194,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
// DriveLetter. We'll use this later to find a matching
|
||||
// DevicePath "symbolic name"
|
||||
int devNum = GetDeviceNumber(drivePath);
|
||||
if(devNum < 0) { return null; }
|
||||
if(devNum < 0) return null;
|
||||
|
||||
return FindDeviceNumber(devNum, deviceGuid);
|
||||
}
|
||||
@@ -256,10 +238,6 @@ namespace DiscImageChef.Devices.Windows
|
||||
int nRequiredSize = 0;
|
||||
int nBytes = BUFFER_SIZE;
|
||||
if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da))
|
||||
{
|
||||
// Now that we have a DevicePath... we can use it to
|
||||
// generate another DeviceNumber to see if it matches
|
||||
// the one we're looking for.
|
||||
if(GetDeviceNumber(didd.DevicePath) == devNum)
|
||||
{
|
||||
// current InstanceID is at the "USBSTOR" level, so we
|
||||
@@ -276,7 +254,6 @@ namespace DiscImageChef.Devices.Windows
|
||||
System.Console.WriteLine("InstanceId: {0}", instanceId);
|
||||
//break;
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -286,7 +263,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
// Did we find an InterfaceID of a USB device?
|
||||
if(instanceId.StartsWith("USB\\")) { foundDevice = FindDeviceByInstanceId(instanceId); }
|
||||
if(instanceId.StartsWith("USB\\")) foundDevice = FindDeviceByInstanceId(instanceId);
|
||||
return foundDevice;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user