REFACTOR: Invert 'if' statement to reduce nesting.

This commit is contained in:
2017-12-21 06:06:19 +00:00
parent 9cd1869d1d
commit 4d886dae25
138 changed files with 9447 additions and 9806 deletions

View File

@@ -86,15 +86,13 @@ namespace DiscImageChef.Devices.Windows
if(port.IsHub) SearchHubDriverKeyName(port.GetHub(), ref foundDevice, driverKeyName);
else
{
if(port.IsDeviceConnected)
{
UsbDevice device = port.GetDevice();
if(device.DeviceDriverKey == driverKeyName)
{
foundDevice = device;
break;
}
}
if(!port.IsDeviceConnected) continue;
UsbDevice device = port.GetDevice();
if(device.DeviceDriverKey != driverKeyName) continue;
foundDevice = device;
break;
}
}
@@ -121,15 +119,13 @@ namespace DiscImageChef.Devices.Windows
if(port.IsHub) SearchHubInstanceId(port.GetHub(), ref foundDevice, instanceId);
else
{
if(port.IsDeviceConnected)
{
UsbDevice device = port.GetDevice();
if(device.InstanceId == instanceId)
{
foundDevice = device;
break;
}
}
if(!port.IsDeviceConnected) continue;
UsbDevice device = port.GetDevice();
if(device.InstanceId != instanceId) continue;
foundDevice = device;
break;
}
}
@@ -273,24 +269,23 @@ namespace DiscImageChef.Devices.Windows
int ans = -1;
IntPtr h = CreateFile(devicePath.TrimEnd('\\'), 0, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
if(h.ToInt32() != INVALID_HANDLE_VALUE)
{
int requiredSize;
StorageDeviceNumber sdn = new StorageDeviceNumber();
int nBytes = Marshal.SizeOf(sdn);
IntPtr ptrSdn = Marshal.AllocHGlobal(nBytes);
if(h.ToInt32() == INVALID_HANDLE_VALUE) return ans;
if(DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, IntPtr.Zero, 0, ptrSdn, nBytes, out requiredSize,
IntPtr.Zero))
{
sdn = (StorageDeviceNumber)Marshal.PtrToStructure(ptrSdn, typeof(StorageDeviceNumber));
// just my way of combining the relevant parts of the
// STORAGE_DEVICE_NUMBER into a single number
ans = (sdn.DeviceType << 8) + sdn.DeviceNumber;
}
Marshal.FreeHGlobal(ptrSdn);
CloseHandle(h);
int requiredSize;
StorageDeviceNumber sdn = new StorageDeviceNumber();
int nBytes = Marshal.SizeOf(sdn);
IntPtr ptrSdn = Marshal.AllocHGlobal(nBytes);
if(DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, IntPtr.Zero, 0, ptrSdn, nBytes, out requiredSize,
IntPtr.Zero))
{
sdn = (StorageDeviceNumber)Marshal.PtrToStructure(ptrSdn, typeof(StorageDeviceNumber));
// just my way of combining the relevant parts of the
// STORAGE_DEVICE_NUMBER into a single number
ans = (sdn.DeviceType << 8) + sdn.DeviceNumber;
}
Marshal.FreeHGlobal(ptrSdn);
CloseHandle(h);
return ans;
}
}