Use Create method for creating Device class.

This commit is contained in:
2022-03-26 17:46:59 +00:00
parent 9ec5aca447
commit d2d3bb560c
11 changed files with 290 additions and 281 deletions

View File

@@ -65,13 +65,15 @@ public sealed partial class Device
{ {
/// <summary>Opens the device for sending direct commands</summary> /// <summary>Opens the device for sending direct commands</summary>
/// <param name="devicePath">Device path</param> /// <param name="devicePath">Device path</param>
public Device(string devicePath) public static Device Create(string devicePath)
{ {
PlatformId = DetectOS.GetRealPlatformID(); var dev = new Device();
Timeout = 15;
Error = false; dev.PlatformId = DetectOS.GetRealPlatformID();
IsRemovable = false; dev.Timeout = 15;
_devicePath = devicePath; dev.Error = false;
dev.IsRemovable = false;
dev._devicePath = devicePath;
Uri aaruUri; Uri aaruUri;
@@ -95,86 +97,86 @@ public sealed partial class Device
if(devicePath.StartsWith("dev", StringComparison.Ordinal)) if(devicePath.StartsWith("dev", StringComparison.Ordinal))
devicePath = $"/{devicePath}"; devicePath = $"/{devicePath}";
_remote = new Remote.Remote(aaruUri); dev._remote = new Remote.Remote(aaruUri);
Error = !_remote.Open(devicePath, out int errno); dev.Error = !dev._remote.Open(devicePath, out int errno);
LastError = errno; dev.LastError = errno;
} }
else else
switch(PlatformId) switch(dev.PlatformId)
{ {
case PlatformID.Win32NT: case PlatformID.Win32NT:
{ {
FileHandle = Extern.CreateFile(devicePath, FileAccess.GenericRead | FileAccess.GenericWrite, dev.FileHandle = Extern.CreateFile(devicePath, FileAccess.GenericRead | FileAccess.GenericWrite,
FileShare.Read | FileShare.Write, IntPtr.Zero, FileMode.OpenExisting, FileShare.Read | FileShare.Write, IntPtr.Zero,
FileAttributes.Normal, IntPtr.Zero); FileMode.OpenExisting, FileAttributes.Normal, IntPtr.Zero);
if(((SafeFileHandle)FileHandle).IsInvalid) if(((SafeFileHandle)dev.FileHandle).IsInvalid)
{ {
Error = true; dev.Error = true;
LastError = Marshal.GetLastWin32Error(); dev.LastError = Marshal.GetLastWin32Error();
} }
break; break;
} }
case PlatformID.Linux: case PlatformID.Linux:
{ {
FileHandle = dev.FileHandle =
Linux.Extern.open(devicePath, Linux.Extern.open(devicePath,
FileFlags.ReadWrite | FileFlags.NonBlocking | FileFlags.CreateNew); FileFlags.ReadWrite | FileFlags.NonBlocking | FileFlags.CreateNew);
if((int)FileHandle < 0) if((int)dev.FileHandle < 0)
{ {
LastError = Marshal.GetLastWin32Error(); dev.LastError = Marshal.GetLastWin32Error();
if(LastError is 13 or 30) // EACCES or EROFS if(dev.LastError is 13 or 30) // EACCES or EROFS
{ {
FileHandle = Linux.Extern.open(devicePath, FileFlags.Readonly | FileFlags.NonBlocking); dev.FileHandle = Linux.Extern.open(devicePath, FileFlags.Readonly | FileFlags.NonBlocking);
if((int)FileHandle < 0) if((int)dev.FileHandle < 0)
{ {
Error = true; dev.Error = true;
LastError = Marshal.GetLastWin32Error(); dev.LastError = Marshal.GetLastWin32Error();
} }
} }
else else
Error = true; dev.Error = true;
LastError = Marshal.GetLastWin32Error(); dev.LastError = Marshal.GetLastWin32Error();
} }
break; break;
} }
default: throw new DeviceException($"Platform {PlatformId} not supported."); default: throw new DeviceException($"Platform {dev.PlatformId} not supported.");
} }
if(Error) if(dev.Error)
throw new DeviceException(LastError); throw new DeviceException(dev.LastError);
// Seems ioctl(2) does not allow the atomicity needed // Seems ioctl(2) does not allow the atomicity needed
if(_remote is null) if(dev._remote is null)
{ {
if(PlatformId == PlatformID.Linux) if(dev.PlatformId == PlatformID.Linux)
_readMultipleBlockCannotSetBlockCount = true; _readMultipleBlockCannotSetBlockCount = true;
} }
else if(_remote.ServerOperatingSystem == "Linux") else if(dev._remote.ServerOperatingSystem == "Linux")
_readMultipleBlockCannotSetBlockCount = true; _readMultipleBlockCannotSetBlockCount = true;
Type = DeviceType.Unknown; dev.Type = DeviceType.Unknown;
ScsiType = PeripheralDeviceTypes.UnknownDevice; dev.ScsiType = PeripheralDeviceTypes.UnknownDevice;
byte[] ataBuf; byte[] ataBuf;
byte[] inqBuf = null; byte[] inqBuf = null;
if(Error) if(dev.Error)
throw new DeviceException(LastError); throw new DeviceException(dev.LastError);
var scsiSense = true; var scsiSense = true;
if(_remote is null) if(dev._remote is null)
// Windows is answering SCSI INQUIRY for all device types so it needs to be detected first // Windows is answering SCSI INQUIRY for all device types so it needs to be detected first
switch(PlatformId) switch(dev.PlatformId)
{ {
case PlatformID.Win32NT: case PlatformID.Win32NT:
var query = new StoragePropertyQuery(); var query = new StoragePropertyQuery();
@@ -188,7 +190,7 @@ public sealed partial class Device
uint returned = 0; uint returned = 0;
var error = 0; var error = 0;
bool hasError = !Extern.DeviceIoControlStorageQuery((SafeFileHandle)FileHandle, bool hasError = !Extern.DeviceIoControlStorageQuery((SafeFileHandle)dev.FileHandle,
WindowsIoctl.IoctlStorageQueryProperty, WindowsIoctl.IoctlStorageQueryProperty,
ref query, (uint)Marshal.SizeOf(query), ref query, (uint)Marshal.SizeOf(query),
descriptorPtr, 1000, ref returned, IntPtr.Zero); descriptorPtr, 1000, ref returned, IntPtr.Zero);
@@ -228,62 +230,62 @@ public sealed partial class Device
case StorageBusType.Fibre: case StorageBusType.Fibre:
case StorageBusType.iSCSI: case StorageBusType.iSCSI:
case StorageBusType.SAS: case StorageBusType.SAS:
Type = DeviceType.SCSI; dev.Type = DeviceType.SCSI;
break; break;
case StorageBusType.FireWire: case StorageBusType.FireWire:
IsFireWire = true; dev.IsFireWire = true;
Type = DeviceType.SCSI; dev.Type = DeviceType.SCSI;
break; break;
case StorageBusType.USB: case StorageBusType.USB:
IsUsb = true; dev.IsUsb = true;
Type = DeviceType.SCSI; dev.Type = DeviceType.SCSI;
break; break;
case StorageBusType.ATAPI: case StorageBusType.ATAPI:
Type = DeviceType.ATAPI; dev.Type = DeviceType.ATAPI;
break; break;
case StorageBusType.ATA: case StorageBusType.ATA:
case StorageBusType.SATA: case StorageBusType.SATA:
Type = DeviceType.ATA; dev.Type = DeviceType.ATA;
break; break;
case StorageBusType.MultiMediaCard: case StorageBusType.MultiMediaCard:
Type = DeviceType.MMC; dev.Type = DeviceType.MMC;
break; break;
case StorageBusType.SecureDigital: case StorageBusType.SecureDigital:
Type = DeviceType.SecureDigital; dev.Type = DeviceType.SecureDigital;
break; break;
case StorageBusType.NVMe: case StorageBusType.NVMe:
Type = DeviceType.NVMe; dev.Type = DeviceType.NVMe;
break; break;
} }
switch(Type) switch(dev.Type)
{ {
case DeviceType.SCSI: case DeviceType.SCSI:
case DeviceType.ATAPI: case DeviceType.ATAPI:
scsiSense = ScsiInquiry(out inqBuf, out _); scsiSense = dev.ScsiInquiry(out inqBuf, out _);
break; break;
case DeviceType.ATA: case DeviceType.ATA:
bool atapiSense = AtapiIdentify(out ataBuf, out _); bool atapiSense = dev.AtapiIdentify(out ataBuf, out _);
if(!atapiSense) if(!atapiSense)
{ {
Type = DeviceType.ATAPI; dev.Type = DeviceType.ATAPI;
Identify.IdentifyDevice? ataid = Identify.Decode(ataBuf); Identify.IdentifyDevice? ataid = Identify.Decode(ataBuf);
if(ataid.HasValue) if(ataid.HasValue)
scsiSense = ScsiInquiry(out inqBuf, out _); scsiSense = dev.ScsiInquiry(out inqBuf, out _);
} }
else else
Manufacturer = "ATA"; dev.Manufacturer = "ATA";
break; break;
} }
@@ -291,66 +293,66 @@ public sealed partial class Device
Marshal.FreeHGlobal(descriptorPtr); Marshal.FreeHGlobal(descriptorPtr);
if(Windows.Command.IsSdhci((SafeFileHandle)FileHandle)) if(Windows.Command.IsSdhci((SafeFileHandle)dev.FileHandle))
{ {
var sdBuffer = new byte[16]; var sdBuffer = new byte[16];
LastError = Windows.Command.SendMmcCommand((SafeFileHandle)FileHandle, MmcCommands.SendCsd, dev.LastError = Windows.Command.SendMmcCommand((SafeFileHandle)dev.FileHandle,
false, false, MmcCommands.SendCsd, false, false,
MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 | MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 |
MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer, out _, MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer,
out _, out bool sense); out _, out _, out bool sense);
if(!sense) if(!sense)
{ {
_cachedCsd = new byte[16]; dev._cachedCsd = new byte[16];
Array.Copy(sdBuffer, 0, _cachedCsd, 0, 16); Array.Copy(sdBuffer, 0, dev._cachedCsd, 0, 16);
} }
sdBuffer = new byte[16]; sdBuffer = new byte[16];
LastError = Windows.Command.SendMmcCommand((SafeFileHandle)FileHandle, MmcCommands.SendCid, dev.LastError = Windows.Command.SendMmcCommand((SafeFileHandle)dev.FileHandle,
false, false, MmcCommands.SendCid, false, false,
MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 | MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 |
MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer, out _, MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer,
out _, out sense); out _, out _, out sense);
if(!sense) if(!sense)
{ {
_cachedCid = new byte[16]; dev._cachedCid = new byte[16];
Array.Copy(sdBuffer, 0, _cachedCid, 0, 16); Array.Copy(sdBuffer, 0, dev._cachedCid, 0, 16);
} }
sdBuffer = new byte[8]; sdBuffer = new byte[8];
LastError = Windows.Command.SendMmcCommand((SafeFileHandle)FileHandle, dev.LastError = Windows.Command.SendMmcCommand((SafeFileHandle)dev.FileHandle,
(MmcCommands)SecureDigitalCommands.SendScr, false, (MmcCommands)SecureDigitalCommands.SendScr,
true, false, true,
MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 | MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 |
MmcFlags.CommandAdtc, 0, 8, 1, ref sdBuffer, out _, MmcFlags.CommandAdtc, 0, 8, 1, ref sdBuffer,
out _, out sense); out _, out _, out sense);
if(!sense) if(!sense)
{ {
_cachedScr = new byte[8]; dev._cachedScr = new byte[8];
Array.Copy(sdBuffer, 0, _cachedScr, 0, 8); Array.Copy(sdBuffer, 0, dev._cachedScr, 0, 8);
} }
sdBuffer = new byte[4]; sdBuffer = new byte[4];
LastError = Windows.Command.SendMmcCommand((SafeFileHandle)FileHandle, dev.LastError = Windows.Command.SendMmcCommand((SafeFileHandle)dev.FileHandle,
_cachedScr != null dev._cachedScr != null
? (MmcCommands)SecureDigitalCommands. ? (MmcCommands)SecureDigitalCommands.
SendOperatingCondition SendOperatingCondition
: MmcCommands.SendOpCond, false, true, : MmcCommands.SendOpCond, false, true,
MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 | MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 |
MmcFlags.CommandBcr, 0, 4, 1, ref sdBuffer, out _, MmcFlags.CommandBcr, 0, 4, 1, ref sdBuffer,
out _, out sense); out _, out _, out sense);
if(!sense) if(!sense)
{ {
_cachedScr = new byte[4]; dev._cachedScr = new byte[4];
Array.Copy(sdBuffer, 0, _cachedScr, 0, 4); Array.Copy(sdBuffer, 0, dev._cachedScr, 0, 4);
} }
} }
@@ -360,7 +362,7 @@ public sealed partial class Device
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) || devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/st", StringComparison.Ordinal) || devicePath.StartsWith("/dev/st", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/sg", StringComparison.Ordinal)) devicePath.StartsWith("/dev/sg", StringComparison.Ordinal))
scsiSense = ScsiInquiry(out inqBuf, out _); scsiSense = dev.ScsiInquiry(out inqBuf, out _);
// MultiMediaCard and SecureDigital go here // MultiMediaCard and SecureDigital go here
else if(devicePath.StartsWith("/dev/mmcblk", StringComparison.Ordinal)) else if(devicePath.StartsWith("/dev/mmcblk", StringComparison.Ordinal))
@@ -369,60 +371,65 @@ public sealed partial class Device
if(File.Exists("/sys/block/" + devPath + "/device/csd")) if(File.Exists("/sys/block/" + devPath + "/device/csd"))
{ {
int len = ConvertFromFileHexAscii("/sys/block/" + devPath + "/device/csd", out _cachedCsd); int len = ConvertFromFileHexAscii("/sys/block/" + devPath + "/device/csd",
out dev._cachedCsd);
if(len == 0) if(len == 0)
_cachedCsd = null; dev._cachedCsd = null;
} }
if(File.Exists("/sys/block/" + devPath + "/device/cid")) if(File.Exists("/sys/block/" + devPath + "/device/cid"))
{ {
int len = ConvertFromFileHexAscii("/sys/block/" + devPath + "/device/cid", out _cachedCid); int len = ConvertFromFileHexAscii("/sys/block/" + devPath + "/device/cid",
out dev._cachedCid);
if(len == 0) if(len == 0)
_cachedCid = null; dev._cachedCid = null;
} }
if(File.Exists("/sys/block/" + devPath + "/device/scr")) if(File.Exists("/sys/block/" + devPath + "/device/scr"))
{ {
int len = ConvertFromFileHexAscii("/sys/block/" + devPath + "/device/scr", out _cachedScr); int len = ConvertFromFileHexAscii("/sys/block/" + devPath + "/device/scr",
out dev._cachedScr);
if(len == 0) if(len == 0)
_cachedScr = null; dev._cachedScr = null;
} }
if(File.Exists("/sys/block/" + devPath + "/device/ocr")) if(File.Exists("/sys/block/" + devPath + "/device/ocr"))
{ {
int len = ConvertFromFileHexAscii("/sys/block/" + devPath + "/device/ocr", out _cachedOcr); int len = ConvertFromFileHexAscii("/sys/block/" + devPath + "/device/ocr",
out dev._cachedOcr);
if(len == 0) if(len == 0)
_cachedOcr = null; dev._cachedOcr = null;
} }
} }
break; break;
default: default:
scsiSense = ScsiInquiry(out inqBuf, out _); scsiSense = dev.ScsiInquiry(out inqBuf, out _);
break; break;
} }
else else
{ {
Type = _remote.GetDeviceType(); dev.Type = dev._remote.GetDeviceType();
switch(Type) switch(dev.Type)
{ {
case DeviceType.ATAPI: case DeviceType.ATAPI:
case DeviceType.SCSI: case DeviceType.SCSI:
scsiSense = ScsiInquiry(out inqBuf, out _); scsiSense = dev.ScsiInquiry(out inqBuf, out _);
break; break;
case DeviceType.SecureDigital: case DeviceType.SecureDigital:
case DeviceType.MMC: case DeviceType.MMC:
if(!_remote.GetSdhciRegisters(out _cachedCsd, out _cachedCid, out _cachedOcr, out _cachedScr)) if(!dev._remote.GetSdhciRegisters(out dev._cachedCsd, out dev._cachedCid, out dev._cachedOcr,
out dev._cachedScr))
{ {
Type = DeviceType.SCSI; dev.Type = DeviceType.SCSI;
ScsiType = PeripheralDeviceTypes.DirectAccess; dev.ScsiType = PeripheralDeviceTypes.DirectAccess;
} }
break; break;
@@ -430,41 +437,43 @@ public sealed partial class Device
} }
#region SecureDigital / MultiMediaCard #region SecureDigital / MultiMediaCard
if(_cachedCid != null) if(dev._cachedCid != null)
{ {
ScsiType = PeripheralDeviceTypes.DirectAccess; dev.ScsiType = PeripheralDeviceTypes.DirectAccess;
IsRemovable = false; dev.IsRemovable = false;
if(_cachedScr != null) if(dev._cachedScr != null)
{ {
Type = DeviceType.SecureDigital; dev.Type = DeviceType.SecureDigital;
CID decoded = Decoders.DecodeCID(_cachedCid); CID decoded = Decoders.DecodeCID(dev._cachedCid);
Manufacturer = VendorString.Prettify(decoded.Manufacturer); dev.Manufacturer = VendorString.Prettify(decoded.Manufacturer);
Model = decoded.ProductName; dev.Model = decoded.ProductName;
FirmwareRevision = $"{(decoded.ProductRevision & 0xF0) >> 4:X2}.{decoded.ProductRevision & 0x0F:X2}"; dev.FirmwareRevision =
$"{(decoded.ProductRevision & 0xF0) >> 4:X2}.{decoded.ProductRevision & 0x0F:X2}";
Serial = $"{decoded.ProductSerialNumber}"; dev.Serial = $"{decoded.ProductSerialNumber}";
} }
else else
{ {
Type = DeviceType.MMC; dev.Type = DeviceType.MMC;
Aaru.Decoders.MMC.CID decoded = Aaru.Decoders.MMC.Decoders.DecodeCID(_cachedCid); Aaru.Decoders.MMC.CID decoded = Aaru.Decoders.MMC.Decoders.DecodeCID(dev._cachedCid);
Manufacturer = Aaru.Decoders.MMC.VendorString.Prettify(decoded.Manufacturer); dev.Manufacturer = Aaru.Decoders.MMC.VendorString.Prettify(decoded.Manufacturer);
Model = decoded.ProductName; dev.Model = decoded.ProductName;
FirmwareRevision = $"{(decoded.ProductRevision & 0xF0) >> 4:X2}.{decoded.ProductRevision & 0x0F:X2}"; dev.FirmwareRevision =
$"{(decoded.ProductRevision & 0xF0) >> 4:X2}.{decoded.ProductRevision & 0x0F:X2}";
Serial = $"{decoded.ProductSerialNumber}"; dev.Serial = $"{decoded.ProductSerialNumber}";
} }
return; return dev;
} }
#endregion SecureDigital / MultiMediaCard #endregion SecureDigital / MultiMediaCard
#region USB #region USB
if(_remote is null) if(dev._remote is null)
switch(PlatformId) switch(dev.PlatformId)
{ {
case PlatformID.Linux: case PlatformID.Linux:
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) || if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
@@ -495,15 +504,15 @@ public sealed partial class Device
var usbBuf = new byte[65536]; var usbBuf = new byte[65536];
int usbCount = usbFs.Read(usbBuf, 0, 65536); int usbCount = usbFs.Read(usbBuf, 0, 65536);
UsbDescriptors = new byte[usbCount]; dev.UsbDescriptors = new byte[usbCount];
Array.Copy(usbBuf, 0, UsbDescriptors, 0, usbCount); Array.Copy(usbBuf, 0, dev.UsbDescriptors, 0, usbCount);
usbFs.Close(); usbFs.Close();
var usbSr = new StreamReader(resolvedLink + "/idProduct"); var usbSr = new StreamReader(resolvedLink + "/idProduct");
string usbTemp = usbSr.ReadToEnd(); string usbTemp = usbSr.ReadToEnd();
ushort.TryParse(usbTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture, ushort.TryParse(usbTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
out _usbProduct); out dev._usbProduct);
usbSr.Close(); usbSr.Close();
@@ -511,32 +520,32 @@ public sealed partial class Device
usbTemp = usbSr.ReadToEnd(); usbTemp = usbSr.ReadToEnd();
ushort.TryParse(usbTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture, ushort.TryParse(usbTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
out _usbVendor); out dev._usbVendor);
usbSr.Close(); usbSr.Close();
if(File.Exists(resolvedLink + "/manufacturer")) if(File.Exists(resolvedLink + "/manufacturer"))
{ {
usbSr = new StreamReader(resolvedLink + "/manufacturer"); usbSr = new StreamReader(resolvedLink + "/manufacturer");
UsbManufacturerString = usbSr.ReadToEnd().Trim(); dev.UsbManufacturerString = usbSr.ReadToEnd().Trim();
usbSr.Close(); usbSr.Close();
} }
if(File.Exists(resolvedLink + "/product")) if(File.Exists(resolvedLink + "/product"))
{ {
usbSr = new StreamReader(resolvedLink + "/product"); usbSr = new StreamReader(resolvedLink + "/product");
UsbProductString = usbSr.ReadToEnd().Trim(); dev.UsbProductString = usbSr.ReadToEnd().Trim();
usbSr.Close(); usbSr.Close();
} }
if(File.Exists(resolvedLink + "/serial")) if(File.Exists(resolvedLink + "/serial"))
{ {
usbSr = new StreamReader(resolvedLink + "/serial"); usbSr = new StreamReader(resolvedLink + "/serial");
UsbSerialString = usbSr.ReadToEnd().Trim(); dev.UsbSerialString = usbSr.ReadToEnd().Trim();
usbSr.Close(); usbSr.Close();
} }
IsUsb = true; dev.IsUsb = true;
break; break;
} }
@@ -563,53 +572,53 @@ public sealed partial class Device
if(usbDevice != null) if(usbDevice != null)
{ {
UsbDescriptors = usbDevice.BinaryDescriptors; dev.UsbDescriptors = usbDevice.BinaryDescriptors;
_usbVendor = (ushort)usbDevice._deviceDescriptor.idVendor; dev._usbVendor = (ushort)usbDevice._deviceDescriptor.idVendor;
_usbProduct = (ushort)usbDevice._deviceDescriptor.idProduct; dev._usbProduct = (ushort)usbDevice._deviceDescriptor.idProduct;
UsbManufacturerString = usbDevice.Manufacturer; dev.UsbManufacturerString = usbDevice.Manufacturer;
UsbProductString = usbDevice.Product; dev.UsbProductString = usbDevice.Product;
UsbSerialString = dev.UsbSerialString =
usbDevice.SerialNumber; // This is incorrect filled by Windows with SCSI/ATA serial number usbDevice.SerialNumber; // This is incorrect filled by Windows with SCSI/ATA serial number
} }
break; break;
default: default:
IsUsb = false; dev.IsUsb = false;
break; break;
} }
else else
{ {
if(_remote.GetUsbData(out byte[] remoteUsbDescriptors, out ushort remoteUsbVendor, if(dev._remote.GetUsbData(out byte[] remoteUsbDescriptors, out ushort remoteUsbVendor,
out ushort remoteUsbProduct, out string remoteUsbManufacturer, out ushort remoteUsbProduct, out string remoteUsbManufacturer,
out string remoteUsbProductString, out string remoteUsbSerial)) out string remoteUsbProductString, out string remoteUsbSerial))
{ {
IsUsb = true; dev.IsUsb = true;
UsbDescriptors = remoteUsbDescriptors; dev.UsbDescriptors = remoteUsbDescriptors;
_usbVendor = remoteUsbVendor; dev._usbVendor = remoteUsbVendor;
_usbProduct = remoteUsbProduct; dev._usbProduct = remoteUsbProduct;
UsbManufacturerString = remoteUsbManufacturer; dev.UsbManufacturerString = remoteUsbManufacturer;
UsbProductString = remoteUsbProductString; dev.UsbProductString = remoteUsbProductString;
UsbSerialString = remoteUsbSerial; dev.UsbSerialString = remoteUsbSerial;
} }
} }
#endregion USB #endregion USB
#region FireWire #region FireWire
if(!(_remote is null)) if(!(dev._remote is null))
{ {
if(_remote.GetFireWireData(out _firewireVendor, out _firewireModel, out _firewireGuid, if(dev._remote.GetFireWireData(out dev._firewireVendor, out dev._firewireModel, out dev._firewireGuid,
out string remoteFireWireVendorName, out string remoteFireWireModelName)) out string remoteFireWireVendorName, out string remoteFireWireModelName))
{ {
IsFireWire = true; dev.IsFireWire = true;
FireWireVendorName = remoteFireWireVendorName; dev.FireWireVendorName = remoteFireWireVendorName;
FireWireModelName = remoteFireWireModelName; dev.FireWireModelName = remoteFireWireModelName;
} }
} }
else else
{ {
if(PlatformId == PlatformID.Linux) if(dev.PlatformId == PlatformID.Linux)
{ {
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) || if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) || devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
@@ -636,7 +645,7 @@ public sealed partial class Device
string fwTemp = fwSr.ReadToEnd(); string fwTemp = fwSr.ReadToEnd();
uint.TryParse(fwTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture, uint.TryParse(fwTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
out _firewireModel); out dev._firewireModel);
fwSr.Close(); fwSr.Close();
@@ -644,7 +653,7 @@ public sealed partial class Device
fwTemp = fwSr.ReadToEnd(); fwTemp = fwSr.ReadToEnd();
uint.TryParse(fwTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture, uint.TryParse(fwTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
out _firewireVendor); out dev._firewireVendor);
fwSr.Close(); fwSr.Close();
@@ -652,25 +661,25 @@ public sealed partial class Device
fwTemp = fwSr.ReadToEnd(); fwTemp = fwSr.ReadToEnd();
ulong.TryParse(fwTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture, ulong.TryParse(fwTemp, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
out _firewireGuid); out dev._firewireGuid);
fwSr.Close(); fwSr.Close();
if(File.Exists(resolvedLink + "/model_name")) if(File.Exists(resolvedLink + "/model_name"))
{ {
fwSr = new StreamReader(resolvedLink + "/model_name"); fwSr = new StreamReader(resolvedLink + "/model_name");
FireWireModelName = fwSr.ReadToEnd().Trim(); dev.FireWireModelName = fwSr.ReadToEnd().Trim();
fwSr.Close(); fwSr.Close();
} }
if(File.Exists(resolvedLink + "/vendor_name")) if(File.Exists(resolvedLink + "/vendor_name"))
{ {
fwSr = new StreamReader(resolvedLink + "/vendor_name"); fwSr = new StreamReader(resolvedLink + "/vendor_name");
FireWireVendorName = fwSr.ReadToEnd().Trim(); dev.FireWireVendorName = fwSr.ReadToEnd().Trim();
fwSr.Close(); fwSr.Close();
} }
IsFireWire = true; dev.IsFireWire = true;
break; break;
} }
@@ -680,14 +689,14 @@ public sealed partial class Device
// TODO: Implement for other operating systems // TODO: Implement for other operating systems
else else
IsFireWire = false; dev.IsFireWire = false;
} }
#endregion FireWire #endregion FireWire
#region PCMCIA #region PCMCIA
if(_remote is null) if(dev._remote is null)
{ {
if(PlatformId == PlatformID.Linux) if(dev.PlatformId == PlatformID.Linux)
{ {
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) || if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) || devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
@@ -726,11 +735,11 @@ public sealed partial class Device
var cisBuf = new byte[65536]; var cisBuf = new byte[65536];
int cisCount = cisFs.Read(cisBuf, 0, 65536); int cisCount = cisFs.Read(cisBuf, 0, 65536);
Cis = new byte[cisCount]; dev.Cis = new byte[cisCount];
Array.Copy(cisBuf, 0, Cis, 0, cisCount); Array.Copy(cisBuf, 0, dev.Cis, 0, cisCount);
cisFs.Close(); cisFs.Close();
IsPcmcia = true; dev.IsPcmcia = true;
break; break;
} }
@@ -740,14 +749,14 @@ public sealed partial class Device
// TODO: Implement for other operating systems // TODO: Implement for other operating systems
else else
IsPcmcia = false; dev.IsPcmcia = false;
} }
else else
{ {
if(_remote.GetPcmciaData(out byte[] cisBuf)) if(dev._remote.GetPcmciaData(out byte[] cisBuf))
{ {
IsPcmcia = true; dev.IsPcmcia = true;
Cis = cisBuf; dev.Cis = cisBuf;
} }
} }
#endregion PCMCIA #endregion PCMCIA
@@ -756,57 +765,57 @@ public sealed partial class Device
{ {
Inquiry? inquiry = Inquiry.Decode(inqBuf); Inquiry? inquiry = Inquiry.Decode(inqBuf);
Type = DeviceType.SCSI; dev.Type = DeviceType.SCSI;
bool serialSense = ScsiInquiry(out inqBuf, out _, 0x80); bool serialSense = dev.ScsiInquiry(out inqBuf, out _, 0x80);
if(!serialSense) if(!serialSense)
Serial = EVPD.DecodePage80(inqBuf); dev.Serial = EVPD.DecodePage80(inqBuf);
if(inquiry.HasValue) if(inquiry.HasValue)
{ {
string tmp = StringHandlers.CToString(inquiry.Value.ProductRevisionLevel); string tmp = StringHandlers.CToString(inquiry.Value.ProductRevisionLevel);
if(tmp != null) if(tmp != null)
FirmwareRevision = tmp.Trim(); dev.FirmwareRevision = tmp.Trim();
tmp = StringHandlers.CToString(inquiry.Value.ProductIdentification); tmp = StringHandlers.CToString(inquiry.Value.ProductIdentification);
if(tmp != null) if(tmp != null)
Model = tmp.Trim(); dev.Model = tmp.Trim();
tmp = StringHandlers.CToString(inquiry.Value.VendorIdentification); tmp = StringHandlers.CToString(inquiry.Value.VendorIdentification);
if(tmp != null) if(tmp != null)
Manufacturer = tmp.Trim(); dev.Manufacturer = tmp.Trim();
IsRemovable = inquiry.Value.RMB; dev.IsRemovable = inquiry.Value.RMB;
ScsiType = (PeripheralDeviceTypes)inquiry.Value.PeripheralDeviceType; dev.ScsiType = (PeripheralDeviceTypes)inquiry.Value.PeripheralDeviceType;
} }
bool atapiSense = AtapiIdentify(out ataBuf, out _); bool atapiSense = dev.AtapiIdentify(out ataBuf, out _);
if(!atapiSense) if(!atapiSense)
{ {
Type = DeviceType.ATAPI; dev.Type = DeviceType.ATAPI;
Identify.IdentifyDevice? ataId = Identify.Decode(ataBuf); Identify.IdentifyDevice? ataId = Identify.Decode(ataBuf);
if(ataId.HasValue) if(ataId.HasValue)
Serial = ataId.Value.SerialNumber; dev.Serial = ataId.Value.SerialNumber;
} }
LastError = 0; dev.LastError = 0;
Error = false; dev.Error = false;
} }
if(scsiSense && !(IsUsb || IsFireWire) || if(scsiSense && !(dev.IsUsb || dev.IsFireWire) ||
Manufacturer == "ATA") dev.Manufacturer == "ATA")
{ {
bool ataSense = AtaIdentify(out ataBuf, out _); bool ataSense = dev.AtaIdentify(out ataBuf, out _);
if(!ataSense) if(!ataSense)
{ {
Type = DeviceType.ATA; dev.Type = DeviceType.ATA;
Identify.IdentifyDevice? ataid = Identify.Decode(ataBuf); Identify.IdentifyDevice? ataid = Identify.Decode(ataBuf);
if(ataid.HasValue) if(ataid.HasValue)
@@ -814,91 +823,95 @@ public sealed partial class Device
string[] separated = ataid.Value.Model.Split(' '); string[] separated = ataid.Value.Model.Split(' ');
if(separated.Length == 1) if(separated.Length == 1)
Model = separated[0]; dev.Model = separated[0];
else else
{ {
Manufacturer = separated[0]; dev.Manufacturer = separated[0];
Model = separated[^1]; dev.Model = separated[^1];
} }
FirmwareRevision = ataid.Value.FirmwareRevision; dev.FirmwareRevision = ataid.Value.FirmwareRevision;
Serial = ataid.Value.SerialNumber; dev.Serial = ataid.Value.SerialNumber;
ScsiType = PeripheralDeviceTypes.DirectAccess; dev.ScsiType = PeripheralDeviceTypes.DirectAccess;
if((ushort)ataid.Value.GeneralConfiguration != 0x848A) if((ushort)ataid.Value.GeneralConfiguration != 0x848A)
IsRemovable |= dev.IsRemovable |=
(ataid.Value.GeneralConfiguration & Identify.GeneralConfigurationBit.Removable) == (ataid.Value.GeneralConfiguration & Identify.GeneralConfigurationBit.Removable) ==
Identify.GeneralConfigurationBit.Removable; Identify.GeneralConfigurationBit.Removable;
else else
IsCompactFlash = true; dev.IsCompactFlash = true;
} }
} }
} }
if(Type == DeviceType.Unknown) if(dev.Type == DeviceType.Unknown)
{ {
Manufacturer = null; dev.Manufacturer = null;
Model = null; dev.Model = null;
FirmwareRevision = null; dev.FirmwareRevision = null;
Serial = null; dev.Serial = null;
} }
if(IsUsb) if(dev.IsUsb)
{ {
if(string.IsNullOrEmpty(Manufacturer)) if(string.IsNullOrEmpty(dev.Manufacturer))
Manufacturer = UsbManufacturerString; dev.Manufacturer = dev.UsbManufacturerString;
if(string.IsNullOrEmpty(Model)) if(string.IsNullOrEmpty(dev.Model))
Model = UsbProductString; dev.Model = dev.UsbProductString;
if(string.IsNullOrEmpty(Serial)) if(string.IsNullOrEmpty(dev.Serial))
Serial = UsbSerialString; dev.Serial = dev.UsbSerialString;
else else
foreach(char c in Serial.Where(c => !char.IsControl(c))) foreach(char c in dev.Serial.Where(c => !char.IsControl(c)))
Serial = $"{Serial}{c:X2}"; dev.Serial = $"{dev.Serial}{c:X2}";
} }
if(IsFireWire) if(dev.IsFireWire)
{ {
if(string.IsNullOrEmpty(Manufacturer)) if(string.IsNullOrEmpty(dev.Manufacturer))
Manufacturer = FireWireVendorName; dev.Manufacturer = dev.FireWireVendorName;
if(string.IsNullOrEmpty(Model)) if(string.IsNullOrEmpty(dev.Model))
Model = FireWireModelName; dev.Model = dev.FireWireModelName;
if(string.IsNullOrEmpty(Serial)) if(string.IsNullOrEmpty(dev.Serial))
Serial = $"{_firewireGuid:X16}"; dev.Serial = $"{dev._firewireGuid:X16}";
else else
foreach(char c in Serial.Where(c => !char.IsControl(c))) foreach(char c in dev.Serial.Where(c => !char.IsControl(c)))
Serial = $"{Serial}{c:X2}"; dev.Serial = $"{dev.Serial}{c:X2}";
} }
// Some optical drives are not getting the correct serial, and IDENTIFY PACKET DEVICE is blocked without // Some optical drives are not getting the correct serial, and IDENTIFY PACKET DEVICE is blocked without
// administrator privileges // administrator privileges
if(ScsiType != PeripheralDeviceTypes.MultiMediaDevice) if(dev.ScsiType != PeripheralDeviceTypes.MultiMediaDevice)
return; return dev;
bool featureSense = GetConfiguration(out byte[] featureBuffer, out _, 0x0108, MmcGetConfigurationRt.Single, bool featureSense = dev.GetConfiguration(out byte[] featureBuffer, out _, 0x0108, MmcGetConfigurationRt.Single,
Timeout, out _); dev.Timeout, out _);
if(featureSense) if(featureSense)
return; return dev;
Features.SeparatedFeatures features = Features.Separate(featureBuffer); Features.SeparatedFeatures features = Features.Separate(featureBuffer);
if(features.Descriptors?.Length != 1 || if(features.Descriptors?.Length != 1 ||
features.Descriptors[0].Code != 0x0108) features.Descriptors[0].Code != 0x0108)
return; return dev;
Feature_0108? serialFeature = Features.Decode_0108(features.Descriptors[0].Data); Feature_0108? serialFeature = Features.Decode_0108(features.Descriptors[0].Data);
if(serialFeature is null) if(serialFeature is null)
return; return dev;
Serial = serialFeature.Value.Serial; dev.Serial = serialFeature.Value.Serial;
return dev;
} }
Device() {}
static int ConvertFromFileHexAscii(string file, out byte[] outBuf) static int ConvertFromFileHexAscii(string file, out byte[] outBuf)
{ {
var sr = new StreamReader(file); var sr = new StreamReader(file);

View File

@@ -38,22 +38,22 @@ using Aaru.CommonTypes.Structs.Devices.SCSI;
public sealed partial class Device public sealed partial class Device
{ {
readonly ushort _usbVendor; ushort _usbVendor;
readonly ushort _usbProduct; ushort _usbProduct;
readonly ulong _firewireGuid; ulong _firewireGuid;
readonly uint _firewireModel; uint _firewireModel;
readonly uint _firewireVendor; uint _firewireVendor;
// MMC and SecureDigital, values that need to be get with card idle, something that may // MMC and SecureDigital, values that need to be get with card idle, something that may
// not be possible to do but usually is already done by the SDHCI driver. // not be possible to do but usually is already done by the SDHCI driver.
readonly byte[] _cachedCsd; byte[] _cachedCsd;
readonly byte[] _cachedCid; byte[] _cachedCid;
readonly byte[] _cachedScr; byte[] _cachedScr;
readonly byte[] _cachedOcr; byte[] _cachedOcr;
/// <summary>Gets the Platform ID for this device</summary> /// <summary>Gets the Platform ID for this device</summary>
/// <value>The Platform ID</value> /// <value>The Platform ID</value>
public PlatformID PlatformId { get; } public PlatformID PlatformId { get; private set; }
/// <summary>Gets the file handle representing this device</summary> /// <summary>Gets the file handle representing this device</summary>
/// <value>The file handle</value> /// <value>The file handle</value>
@@ -61,7 +61,7 @@ public sealed partial class Device
/// <summary>Gets or sets the standard timeout for commands sent to this device</summary> /// <summary>Gets or sets the standard timeout for commands sent to this device</summary>
/// <value>The timeout in seconds</value> /// <value>The timeout in seconds</value>
public uint Timeout { get; } public uint Timeout { get; set; }
/// <summary>Gets a value indicating whether this <see cref="Device" /> is in error.</summary> /// <summary>Gets a value indicating whether this <see cref="Device" /> is in error.</summary>
/// <value><c>true</c> if error; otherwise, <c>false</c>.</value> /// <value><c>true</c> if error; otherwise, <c>false</c>.</value>
@@ -73,35 +73,35 @@ public sealed partial class Device
/// <summary>Gets the device type.</summary> /// <summary>Gets the device type.</summary>
/// <value>The device type.</value> /// <value>The device type.</value>
public DeviceType Type { get; } public DeviceType Type { get; private set; }
/// <summary>Gets the device's manufacturer</summary> /// <summary>Gets the device's manufacturer</summary>
/// <value>The manufacturer.</value> /// <value>The manufacturer.</value>
public string Manufacturer { get; } public string Manufacturer { get; private set; }
/// <summary>Gets the device model</summary> /// <summary>Gets the device model</summary>
/// <value>The model.</value> /// <value>The model.</value>
public string Model { get; } public string Model { get; private set; }
/// <summary>Gets the device's firmware version.</summary> /// <summary>Gets the device's firmware version.</summary>
/// <value>The firmware version.</value> /// <value>The firmware version.</value>
public string FirmwareRevision { get; } public string FirmwareRevision { get; private set; }
/// <summary>Gets the device's serial number.</summary> /// <summary>Gets the device's serial number.</summary>
/// <value>The serial number.</value> /// <value>The serial number.</value>
public string Serial { get; } public string Serial { get; private set; }
/// <summary>Gets the device's SCSI peripheral device type</summary> /// <summary>Gets the device's SCSI peripheral device type</summary>
/// <value>The SCSI peripheral device type.</value> /// <value>The SCSI peripheral device type.</value>
public PeripheralDeviceTypes ScsiType { get; } public PeripheralDeviceTypes ScsiType { get; private set; }
/// <summary>Gets a value indicating whether this device's media is removable.</summary> /// <summary>Gets a value indicating whether this device's media is removable.</summary>
/// <value><c>true</c> if this device's media is removable; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this device's media is removable; otherwise, <c>false</c>.</value>
public bool IsRemovable { get; } public bool IsRemovable { get; private set; }
/// <summary>Gets a value indicating whether this device is attached via USB.</summary> /// <summary>Gets a value indicating whether this device is attached via USB.</summary>
/// <value><c>true</c> if this device is attached via USB; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this device is attached via USB; otherwise, <c>false</c>.</value>
public bool IsUsb { get; } public bool IsUsb { get; private set; }
/// <summary>Gets the USB vendor ID.</summary> /// <summary>Gets the USB vendor ID.</summary>
/// <value>The USB vendor ID.</value> /// <value>The USB vendor ID.</value>
@@ -113,23 +113,23 @@ public sealed partial class Device
/// <summary>Gets the USB descriptors.</summary> /// <summary>Gets the USB descriptors.</summary>
/// <value>The USB descriptors.</value> /// <value>The USB descriptors.</value>
public byte[] UsbDescriptors { get; } public byte[] UsbDescriptors { get; private set; }
/// <summary>Gets the USB manufacturer string.</summary> /// <summary>Gets the USB manufacturer string.</summary>
/// <value>The USB manufacturer string.</value> /// <value>The USB manufacturer string.</value>
public string UsbManufacturerString { get; } public string UsbManufacturerString { get; private set; }
/// <summary>Gets the USB product string.</summary> /// <summary>Gets the USB product string.</summary>
/// <value>The USB product string.</value> /// <value>The USB product string.</value>
public string UsbProductString { get; } public string UsbProductString { get; private set; }
/// <summary>Gets the USB serial string.</summary> /// <summary>Gets the USB serial string.</summary>
/// <value>The USB serial string.</value> /// <value>The USB serial string.</value>
public string UsbSerialString { get; } public string UsbSerialString { get; private set; }
/// <summary>Gets a value indicating whether this device is attached via FireWire.</summary> /// <summary>Gets a value indicating whether this device is attached via FireWire.</summary>
/// <value><c>true</c> if this device is attached via FireWire; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this device is attached via FireWire; otherwise, <c>false</c>.</value>
public bool IsFireWire { get; } public bool IsFireWire { get; private set; }
/// <summary>Gets the FireWire GUID</summary> /// <summary>Gets the FireWire GUID</summary>
/// <value>The FireWire GUID.</value> /// <value>The FireWire GUID.</value>
@@ -141,7 +141,7 @@ public sealed partial class Device
/// <summary>Gets the FireWire model name.</summary> /// <summary>Gets the FireWire model name.</summary>
/// <value>The FireWire model name.</value> /// <value>The FireWire model name.</value>
public string FireWireModelName { get; } public string FireWireModelName { get; private set; }
/// <summary>Gets the FireWire vendor number.</summary> /// <summary>Gets the FireWire vendor number.</summary>
/// <value>The FireWire vendor number.</value> /// <value>The FireWire vendor number.</value>
@@ -149,22 +149,22 @@ public sealed partial class Device
/// <summary>Gets the FireWire vendor name.</summary> /// <summary>Gets the FireWire vendor name.</summary>
/// <value>The FireWire vendor name.</value> /// <value>The FireWire vendor name.</value>
public string FireWireVendorName { get; } public string FireWireVendorName { get; private set; }
/// <summary>Gets a value indicating whether this device is a CompactFlash device.</summary> /// <summary>Gets a value indicating whether this device is a CompactFlash device.</summary>
/// <value><c>true</c> if this device is a CompactFlash device; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this device is a CompactFlash device; otherwise, <c>false</c>.</value>
public bool IsCompactFlash { get; } public bool IsCompactFlash { get; private set; }
/// <summary>Gets a value indicating whether this device is a PCMCIA device.</summary> /// <summary>Gets a value indicating whether this device is a PCMCIA device.</summary>
/// <value><c>true</c> if this device is a PCMCIA device; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this device is a PCMCIA device; otherwise, <c>false</c>.</value>
public bool IsPcmcia { get; } public bool IsPcmcia { get; private set; }
/// <summary>Contains the PCMCIA CIS if applicable</summary> /// <summary>Contains the PCMCIA CIS if applicable</summary>
public byte[] Cis { get; } public byte[] Cis { get; private set; }
readonly Remote.Remote _remote; Remote.Remote _remote;
bool? _isRemoteAdmin; bool? _isRemoteAdmin;
readonly string _devicePath; string _devicePath;
/// <summary>Returns if remote is running under administrative (aka root) privileges</summary> /// <summary>Returns if remote is running under administrative (aka root) privileges</summary>
public bool IsRemoteAdmin public bool IsRemoteAdmin

View File

@@ -154,18 +154,15 @@ public sealed class MainWindowViewModel : ViewModelBase
_usbIcon = _usbIcon =
new new
Bitmap(_assets.Open(new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-removable-media-usb.png")));
Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-removable-media-usb.png")));
_removableIcon = _removableIcon =
new new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-removable-media.png")));
Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-removable-media.png")));
_sdIcon = _sdIcon =
new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/media-flash-sd-mmc.png"))); new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/media-flash-sd-mmc.png")));
_ejectIcon = _ejectIcon = new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/media-eject.png")));
new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/media-eject.png")));
} }
public bool DevicesSupported public bool DevicesSupported
@@ -251,7 +248,7 @@ public sealed class MainWindowViewModel : ViewModelBase
if(deviceModel.ViewModel is null) if(deviceModel.ViewModel is null)
try try
{ {
var dev = new Device(deviceModel.Path); var dev = Device.Create(deviceModel.Path);
if(dev.IsRemote) if(dev.IsRemote)
Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion,
@@ -790,7 +787,7 @@ public sealed class MainWindowViewModel : ViewModelBase
try try
{ {
var dev = new Device(device.Path); var dev = Device.Create(device.Path);
if(dev.IsRemote) if(dev.IsRemote)
Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem, Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem,

View File

@@ -726,7 +726,7 @@ public sealed class MediaDumpViewModel : ViewModelBase
try try
{ {
_dev = new Device(_devicePath); _dev = Device.Create(_devicePath);
if(_dev.IsRemote) if(_dev.IsRemote)
Statistics.AddRemote(_dev.RemoteApplication, _dev.RemoteVersion, _dev.RemoteOperatingSystem, Statistics.AddRemote(_dev.RemoteApplication, _dev.RemoteVersion, _dev.RemoteOperatingSystem,

View File

@@ -328,7 +328,7 @@ public sealed class MediaScanViewModel : ViewModelBase
char.IsLetter(_devicePath[0])) char.IsLetter(_devicePath[0]))
_devicePath = "\\\\.\\" + char.ToUpper(_devicePath[0]) + ':'; _devicePath = "\\\\.\\" + char.ToUpper(_devicePath[0]) + ':';
var dev = new Device(_devicePath); var dev = Device.Create(_devicePath);
if(dev.IsRemote) if(dev.IsRemote)
Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem, Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem,

View File

@@ -30,7 +30,6 @@ namespace Aaru.Tests.Devices;
using System; using System;
using Aaru.Console; using Aaru.Console;
using Aaru.Devices;
using Aaru.Helpers; using Aaru.Helpers;
static partial class MainClass static partial class MainClass
@@ -40,7 +39,7 @@ static partial class MainClass
AaruConsole.WriteLine("Going to open {0}. Press any key to continue...", devPath); AaruConsole.WriteLine("Going to open {0}. Press any key to continue...", devPath);
Console.ReadKey(); Console.ReadKey();
var dev = new Device(devPath); var dev = Aaru.Devices.Device.Create(devPath);
while(true) while(true)
{ {

View File

@@ -128,7 +128,7 @@ sealed class DeviceReportCommand : Command
try try
{ {
dev = new Device(devicePath); dev = Device.Create(devicePath);
if(dev.IsRemote) if(dev.IsRemote)
Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem, Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem,

View File

@@ -132,7 +132,7 @@ sealed class DeviceInfoCommand : Command
try try
{ {
dev = new Device(devicePath); dev = Device.Create(devicePath);
if(dev.IsRemote) if(dev.IsRemote)
Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem, Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem,

View File

@@ -543,7 +543,7 @@ sealed class DumpMediaCommand : Command
Spectre.ProgressSingleSpinner(ctx => Spectre.ProgressSingleSpinner(ctx =>
{ {
ctx.AddTask("Opening device...").IsIndeterminate(); ctx.AddTask("Opening device...").IsIndeterminate();
dev = new Device(devicePath); dev = Device.Create(devicePath);
}); });
if(dev.IsRemote) if(dev.IsRemote)

View File

@@ -136,7 +136,7 @@ sealed class MediaInfoCommand : Command
Spectre.ProgressSingleSpinner(ctx => Spectre.ProgressSingleSpinner(ctx =>
{ {
ctx.AddTask("Opening device...").IsIndeterminate(); ctx.AddTask("Opening device...").IsIndeterminate();
dev = new Device(devicePath); dev = Device.Create(devicePath);
}); });
if(dev.IsRemote) if(dev.IsRemote)

View File

@@ -137,7 +137,7 @@ sealed class MediaScanCommand : Command
Spectre.ProgressSingleSpinner(ctx => Spectre.ProgressSingleSpinner(ctx =>
{ {
ctx.AddTask("Opening device...").IsIndeterminate(); ctx.AddTask("Opening device...").IsIndeterminate();
dev = new Device(devicePath); dev = Device.Create(devicePath);
}); });
if(dev.IsRemote) if(dev.IsRemote)