diff --git a/Aaru.Checksums b/Aaru.Checksums index 01391f7a7..17934740d 160000 --- a/Aaru.Checksums +++ b/Aaru.Checksums @@ -1 +1 @@ -Subproject commit 01391f7a76904b1ed0853d3fc30c49001030ac0a +Subproject commit 17934740d855ec0fe7f0098f2220b7a85a511a41 diff --git a/Aaru.CommonTypes b/Aaru.CommonTypes index 58ca08969..133817872 160000 --- a/Aaru.CommonTypes +++ b/Aaru.CommonTypes @@ -1 +1 @@ -Subproject commit 58ca08969c78ab5673fca1ce3dee49aaca609d15 +Subproject commit 1338178726f60aa69e580c866e28a2bbb2cebd09 diff --git a/Aaru.Compression/BZip2.cs b/Aaru.Compression/BZip2.cs index 9accf5278..9f0b611e9 100644 --- a/Aaru.Compression/BZip2.cs +++ b/Aaru.Compression/BZip2.cs @@ -32,6 +32,9 @@ using System.IO; using System.Runtime.InteropServices; using Ionic.BZip2; +/// +/// Implements the BZIP2 compression algorithm +/// public class BZip2 { /// Set to true if this algorithm is supported, false otherwise. diff --git a/Aaru.Compression/FLAC.cs b/Aaru.Compression/FLAC.cs index 5bf9567f8..85dc7b4b1 100644 --- a/Aaru.Compression/FLAC.cs +++ b/Aaru.Compression/FLAC.cs @@ -34,6 +34,9 @@ using CUETools.Codecs; using CUETools.Codecs.Flake; // ReSharper disable once InconsistentNaming +/// +/// Implements the FLAC lossless audio compression algorithm +/// public class FLAC { /// Set to true if this algorithm is supported, false otherwise. @@ -77,7 +80,18 @@ public class FLAC /// Compresses a buffer using FLAC /// Data to compress /// Buffer to store the compressed data - /// + /// Block size + /// Do mid side stereo + /// Loose mid side stereo + /// Apodization algorithm + /// Maximum LPC order + /// QLP coefficient precision + /// Do precise search for QLP coefficient + /// Do exhaustive model search + /// Minimum residual partition order + /// Maximum residual partition order + /// Application ID + /// The size of the compressed data public static int EncodeBuffer(byte[] source, byte[] destination, uint blockSize, bool doMidSideStereo, bool looseMidSideStereo, string apodization, uint maxLpcOrder, uint qlpCoeffPrecision, bool doQlpCoeffPrecSearch, bool doExhaustiveModelSearch, diff --git a/Aaru.Compression/LZFSE.cs b/Aaru.Compression/LZFSE.cs index d3ae4d2bd..b3d0c451f 100644 --- a/Aaru.Compression/LZFSE.cs +++ b/Aaru.Compression/LZFSE.cs @@ -31,6 +31,9 @@ namespace Aaru.Compression; using System.Runtime.InteropServices; // ReSharper disable once InconsistentNaming +/// +/// Implements the LZFSE compression algorithm +/// public class LZFSE { /// Set to true if this algorithm is supported, false otherwise. diff --git a/Aaru.Compression/LZIP.cs b/Aaru.Compression/LZIP.cs index 66af13402..73267d969 100644 --- a/Aaru.Compression/LZIP.cs +++ b/Aaru.Compression/LZIP.cs @@ -31,6 +31,9 @@ namespace Aaru.Compression; using System.Runtime.InteropServices; // ReSharper disable once InconsistentNaming +/// +/// Implements the LZIP compression algorithm +/// public class LZIP { /// Set to true if this algorithm is supported, false otherwise. @@ -53,7 +56,9 @@ public class LZIP /// Compresses a buffer using LZIP /// Data to compress /// Buffer to store the compressed data - /// + /// Dictionary size in bytes + /// Match length limit + /// The size of the compressed data public static int EncodeBuffer(byte[] source, byte[] destination, int dictionarySize, int matchLengthLimit) => Native.IsSupported ? AARU_lzip_encode_buffer(destination, destination.Length, source, source.Length, dictionarySize, matchLengthLimit) : 0; diff --git a/Aaru.Compression/LZMA.cs b/Aaru.Compression/LZMA.cs index 7f05f6a22..66aa43018 100644 --- a/Aaru.Compression/LZMA.cs +++ b/Aaru.Compression/LZMA.cs @@ -32,6 +32,9 @@ using System.IO; using System.Runtime.InteropServices; using SharpCompress.Compressors.LZMA; +/// +/// Implements the LZMA compression algorithm +/// public class LZMA { /// Set to true if this algorithm is supported, false otherwise. @@ -49,6 +52,7 @@ public class LZMA /// Decodes a buffer compressed with LZMA /// Encoded buffer /// Buffer where to write the decoded data + /// LZMA stream properties /// The number of decoded bytes public static int DecodeBuffer(byte[] source, byte[] destination, byte[] properties) { @@ -73,6 +77,12 @@ public class LZMA /// Compresses a buffer using BZIP2 /// Data to compress /// Buffer to store the compressed data + /// LZMA stream properties + /// Compression level + /// Dictionary size + /// Literal context bits + /// Literal position bits + /// Position bits /// public static int EncodeBuffer(byte[] source, byte[] destination, out byte[] properties, int level, uint dictSize, int lc, int lp, int pb, int fb) diff --git a/Aaru.Compression/Native.cs b/Aaru.Compression/Native.cs index 83b2f00b8..0e7dd2ba4 100644 --- a/Aaru.Compression/Native.cs +++ b/Aaru.Compression/Native.cs @@ -34,6 +34,9 @@ namespace Aaru.Compression; using System.Runtime.InteropServices; +/// +/// Handles native implementations of compression algorithms +/// public static class Native { static bool _checked; diff --git a/Aaru.Compression/ZSTD.cs b/Aaru.Compression/ZSTD.cs index 9ee226b09..f1813716f 100644 --- a/Aaru.Compression/ZSTD.cs +++ b/Aaru.Compression/ZSTD.cs @@ -31,6 +31,9 @@ namespace Aaru.Compression; using System.Runtime.InteropServices; // ReSharper disable once InconsistentNaming +/// +/// Implements the zstandard compression algorithm +/// public class ZSTD { /// Set to true if this algorithm is supported, false otherwise. @@ -54,7 +57,8 @@ public class ZSTD /// Compresses a buffer using ZSTD /// Data to compress /// Buffer to store the compressed data - /// + /// Compression level + /// Length of the compressed data public static int EncodeBuffer(byte[] source, byte[] destination, int compressionLevel) => (int)(Native.IsSupported ? AARU_zstd_encode_buffer(destination, (nuint)destination.Length, source, (nuint)source.Length, diff --git a/Aaru.Core/Devices/Dumping/PlayStationPortable/UMD.cs b/Aaru.Core/Devices/Dumping/PlayStationPortable/UMD.cs index 9c7104fd8..aa1536467 100644 --- a/Aaru.Core/Devices/Dumping/PlayStationPortable/UMD.cs +++ b/Aaru.Core/Devices/Dumping/PlayStationPortable/UMD.cs @@ -159,7 +159,7 @@ public partial class Dump start = DateTime.UtcNow; double imageWriteDuration = 0; - outputOptical?.SetTracks(new List + outputOptical.SetTracks(new List { new() { diff --git a/Aaru.Core/Devices/Report/Scsi.cs b/Aaru.Core/Devices/Report/Scsi.cs index d832246c7..ed9acb518 100644 --- a/Aaru.Core/Devices/Report/Scsi.cs +++ b/Aaru.Core/Devices/Report/Scsi.cs @@ -418,7 +418,7 @@ public sealed partial class DeviceReport cdromMode = null; - if(!decMode.HasValue) + if(decMode == null) return; mediumType = decMode.Value.Header.MediumType; diff --git a/Aaru.Core/Remote.cs b/Aaru.Core/Remote.cs index 24ec1ee97..f3fe6972c 100644 --- a/Aaru.Core/Remote.cs +++ b/Aaru.Core/Remote.cs @@ -531,8 +531,8 @@ public static class Remote } }); - AaruConsole.WriteLine("Added {0} known iNES/NES 2.0 headers", addedDevices); - AaruConsole.WriteLine("Modified {0} known iNES/NES 2.0 headers", modifiedDevices); + AaruConsole.WriteLine("Added {0} known iNES/NES 2.0 headers", addedNesHeaders); + AaruConsole.WriteLine("Modified {0} known iNES/NES 2.0 headers", modifiedNesHeaders); } } catch(Exception ex) diff --git a/Aaru.Core/Spectre.cs b/Aaru.Core/Spectre.cs index 1fa242585..49a11eca7 100644 --- a/Aaru.Core/Spectre.cs +++ b/Aaru.Core/Spectre.cs @@ -3,8 +3,15 @@ namespace Aaru.Core; using System; using global::Spectre.Console; +/// +/// Implement core operations using the Spectre console +/// public static class Spectre { + /// + /// Initializes a progress bar with a single spinner + /// + /// Action to execute in the progress bar public static void ProgressSingleSpinner(Action action) => AnsiConsole.Progress().AutoClear(true). HideCompleted(true).Columns(new TaskDescriptionColumn(), new SpinnerColumn()).Start(action); } \ No newline at end of file diff --git a/Aaru.Devices/Device/Constructor.cs b/Aaru.Devices/Device/Constructor.cs index 6853063d8..e7b723ee0 100644 --- a/Aaru.Devices/Device/Constructor.cs +++ b/Aaru.Devices/Device/Constructor.cs @@ -551,8 +551,8 @@ public sealed partial class Device // I have to search for USB disks, floppies and CD-ROMs as separate device types foreach(string devGuid in new[] { - Usb.GuidDevinterfaceFloppy, Usb.GuidDevinterfaceCdrom, Usb.GuidDevinterfaceDisk, - Usb.GuidDevinterfaceTape + Usb.GUID_DEVINTERFACE_FLOPPY, Usb.GUID_DEVINTERFACE_CDROM, Usb.GUID_DEVINTERFACE_DISK, + Usb.GUID_DEVINTERFACE_TAPE }) { usbDevice = Usb.FindDrivePath(devicePath, devGuid); @@ -564,8 +564,8 @@ public sealed partial class Device if(usbDevice != null) { UsbDescriptors = usbDevice.BinaryDescriptors; - _usbVendor = (ushort)usbDevice.DeviceDescriptor.idVendor; - _usbProduct = (ushort)usbDevice.DeviceDescriptor.idProduct; + _usbVendor = (ushort)usbDevice._deviceDescriptor.idVendor; + _usbProduct = (ushort)usbDevice._deviceDescriptor.idProduct; UsbManufacturerString = usbDevice.Manufacturer; UsbProductString = usbDevice.Product; diff --git a/Aaru.Devices/Windows/ListDevices.cs b/Aaru.Devices/Windows/ListDevices.cs index 08f6ac0c7..5e39568fc 100644 --- a/Aaru.Devices/Windows/ListDevices.cs +++ b/Aaru.Devices/Windows/ListDevices.cs @@ -50,10 +50,10 @@ static class ListDevices static string HexStringToString(string hex) { var result = new StringBuilder(); - const string HEXTABLE = "0123456789abcdef"; + const string hexTable = "0123456789abcdef"; for(var i = 0; i < hex.Length / 2; i++) - result.Append((char)(16 * HEXTABLE.IndexOf(hex[2 * i]) + HEXTABLE.IndexOf(hex[2 * i + 1]))); + result.Append((char)(16 * hexTable.IndexOf(hex[2 * i]) + hexTable.IndexOf(hex[2 * i + 1]))); return result.ToString(); } diff --git a/Aaru.Devices/Windows/Usb.cs b/Aaru.Devices/Windows/Usb.cs index bffe2c948..86013d2e2 100644 --- a/Aaru.Devices/Windows/Usb.cs +++ b/Aaru.Devices/Windows/Usb.cs @@ -56,7 +56,7 @@ static partial class Usb // devices that match the interface GUID of a Hub Controller IntPtr h = SetupDiGetClassDevs(ref hostGuid, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); - if(h == INVALID_HANDLE_VALUE) + if(h == _invalidHandleValue) return new ReadOnlyCollection(hostList); IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); @@ -67,7 +67,7 @@ static partial class Usb { var host = new UsbController { - ControllerIndex = i + _controllerIndex = i }; // create a Device Interface Data structure @@ -93,11 +93,11 @@ static partial class Usb // now we can get some more detailed information var nRequiredSize = 0; - const int N_BYTES = BUFFER_SIZE; + const int nBytes = BUFFER_SIZE; - if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, N_BYTES, ref nRequiredSize, ref da)) + if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da)) { - host.ControllerDevicePath = didd.DevicePath; + host._controllerDevicePath = didd.DevicePath; // get the Device Description and DriverKeyName var requiredSize = 0; @@ -105,11 +105,11 @@ static partial class Usb if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, ref regType, ptrBuf, BUFFER_SIZE, ref requiredSize)) - host.ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf); + host._controllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf); if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, BUFFER_SIZE, ref requiredSize)) - host.ControllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuf); + host._controllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuf); } hostList.Add(host); @@ -131,13 +131,13 @@ static partial class Usb static string GetDescriptionByKeyName(string driverKeyName) { var ans = ""; - const string DEV_ENUM = REGSTR_KEY_USB; + const string devEnum = REGSTR_KEY_USB; // Use the "enumerator form" of the SetupDiGetClassDevs API // to generate a list of all USB devices - IntPtr h = SetupDiGetClassDevs(0, DEV_ENUM, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES); + IntPtr h = SetupDiGetClassDevs(0, devEnum, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES); - if(h == INVALID_HANDLE_VALUE) + if(h == _invalidHandleValue) return ans; IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); @@ -190,13 +190,13 @@ static partial class Usb static string GetInstanceIdByKeyName(string driverKeyName) { var ans = ""; - const string DEV_ENUM = REGSTR_KEY_USB; + const string devEnum = REGSTR_KEY_USB; // Use the "enumerator form" of the SetupDiGetClassDevs API // to generate a list of all USB devices - IntPtr h = SetupDiGetClassDevs(0, DEV_ENUM, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES); + IntPtr h = SetupDiGetClassDevs(0, devEnum, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES); - if(h == INVALID_HANDLE_VALUE) + if(h == _invalidHandleValue) return ans; IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); @@ -227,9 +227,9 @@ static partial class Usb // is it a match? if(keyName == driverKeyName) { - const int N_BYTES = BUFFER_SIZE; - var sb = new StringBuilder(N_BYTES); - SetupDiGetDeviceInstanceId(h, ref da, sb, N_BYTES, out requiredSize); + const int nBytes = BUFFER_SIZE; + var sb = new StringBuilder(nBytes); + SetupDiGetDeviceInstanceId(h, ref da, sb, nBytes, out requiredSize); ans = sb.ToString(); break; @@ -248,32 +248,32 @@ static partial class Usb /// Represents a USB Host Controller sealed class UsbController { - internal string ControllerDriverKeyName, ControllerDevicePath, ControllerDeviceDesc; - internal int ControllerIndex; + internal string _controllerDriverKeyName, _controllerDevicePath, _controllerDeviceDesc; + internal int _controllerIndex; /// A simple default constructor internal UsbController() { - ControllerIndex = 0; - ControllerDevicePath = ""; - ControllerDeviceDesc = ""; - ControllerDriverKeyName = ""; + _controllerIndex = 0; + _controllerDevicePath = ""; + _controllerDeviceDesc = ""; + _controllerDriverKeyName = ""; } /// Return the index of the instance - internal int Index => ControllerIndex; + internal int Index => _controllerIndex; /// /// Return the Device Path, such as "\\?\pci#ven_10de&dev_005a&subsys_815a1043&rev_a2#3&267a616a&0& /// 58#{3abf6f2d-71c4-462a-8a92-1e6861e6af27}" /// - internal string DevicePath => ControllerDevicePath; + internal string DevicePath => _controllerDevicePath; /// The DriverKeyName may be useful as a search key - internal string DriverKeyName => ControllerDriverKeyName; + internal string DriverKeyName => _controllerDriverKeyName; /// Return the Friendly Name, such as "VIA USB Enhanced Host Controller" - internal string Name => ControllerDeviceDesc; + internal string Name => _controllerDeviceDesc; /// Return Root Hub for this Controller internal UsbHub GetRootHub() @@ -282,15 +282,15 @@ static partial class Usb var root = new UsbHub { - HubIsRootHub = true, - HubDeviceDesc = "Root Hub" + _hubIsRootHub = true, + _hubDeviceDesc = "Root Hub" }; // Open a handle to the Host Controller - h = CreateFile(ControllerDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, + h = CreateFile(_controllerDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h == INVALID_HANDLE_VALUE) + if(h == _invalidHandleValue) return root; var hubName = new UsbRootHubName(); @@ -303,16 +303,16 @@ static partial class Usb { hubName = (UsbRootHubName)(Marshal.PtrToStructure(ptrHubName, typeof(UsbRootHubName)) ?? default(UsbRootHubName)); - root.HubDevicePath = @"\\.\" + hubName.RootHubName; + root._hubDevicePath = @"\\.\" + hubName.RootHubName; } // TODO: Get DriverKeyName for Root Hub // Now let's open the Hub (based upon the HubName we got above) - h2 = CreateFile(root.HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, + h2 = CreateFile(root._hubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h2 != INVALID_HANDLE_VALUE) + if(h2 != _invalidHandleValue) { var nodeInfo = new UsbNodeInformation { @@ -327,10 +327,11 @@ static partial class Usb if(DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes, out _, IntPtr.Zero)) { - nodeInfo = (UsbNodeInformation)Marshal.PtrToStructure(ptrNodeInfo, typeof(UsbNodeInformation)); + nodeInfo = (UsbNodeInformation)(Marshal.PtrToStructure(ptrNodeInfo, typeof(UsbNodeInformation)) ?? + default(UsbNodeInformation)); - root.HubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered); - root.HubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; + root._hubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered); + root._hubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; } Marshal.FreeHGlobal(ptrNodeInfo); @@ -347,55 +348,55 @@ static partial class Usb /// The Hub class internal class UsbHub { - internal string HubDriverKey, HubDevicePath, HubDeviceDesc; - internal bool HubIsBusPowered, HubIsRootHub; - internal string HubManufacturer, HubProduct, HubSerialNumber, HubInstanceId; - internal int HubPortCount; + internal string _hubDriverKey, _hubDevicePath, _hubDeviceDesc; + internal bool _hubIsBusPowered, _hubIsRootHub; + internal string _hubManufacturer, _hubProduct, _hubSerialNumber, _hubInstanceId; + internal int _hubPortCount; /// a simple default constructor internal UsbHub() { - HubPortCount = 0; - HubDevicePath = ""; - HubDeviceDesc = ""; - HubDriverKey = ""; - HubIsBusPowered = false; - HubIsRootHub = false; - HubManufacturer = ""; - HubProduct = ""; - HubSerialNumber = ""; - HubInstanceId = ""; + _hubPortCount = 0; + _hubDevicePath = ""; + _hubDeviceDesc = ""; + _hubDriverKey = ""; + _hubIsBusPowered = false; + _hubIsRootHub = false; + _hubManufacturer = ""; + _hubProduct = ""; + _hubSerialNumber = ""; + _hubInstanceId = ""; } /// return Port Count - internal int PortCount => HubPortCount; + internal int PortCount => _hubPortCount; /// /// return the Device Path, such as "\\?\pci#ven_10de&dev_005a&subsys_815a1043&rev_a2#3&267a616a&0& /// 58#{3abf6f2d-71c4-462a-8a92-1e6861e6af27}" /// - internal string DevicePath => HubDevicePath; + internal string DevicePath => _hubDevicePath; /// The DriverKey may be useful as a search key - internal string DriverKey => HubDriverKey; + internal string DriverKey => _hubDriverKey; /// return the Friendly Name, such as "VIA USB Enhanced Host Controller" - internal string Name => HubDeviceDesc; + internal string Name => _hubDeviceDesc; /// the device path of this device - internal string InstanceId => HubInstanceId; + internal string InstanceId => _hubInstanceId; /// is is this a self-powered hub? - internal bool IsBusPowered => HubIsBusPowered; + internal bool IsBusPowered => _hubIsBusPowered; /// is this a root hub? - internal bool IsRootHub => HubIsRootHub; + internal bool IsRootHub => _hubIsRootHub; - internal string Manufacturer => HubManufacturer; + internal string Manufacturer => _hubManufacturer; - internal string Product => HubProduct; + internal string Product => _hubProduct; - internal string SerialNumber => HubSerialNumber; + internal string SerialNumber => _hubSerialNumber; /// return a list of the down stream ports /// List of downstream ports @@ -404,10 +405,10 @@ static partial class Usb var portList = new List(); // Open a handle to the Hub device - IntPtr h = CreateFile(HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, + IntPtr h = CreateFile(_hubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h == INVALID_HANDLE_VALUE) + if(h == _invalidHandleValue) return new ReadOnlyCollection(portList); int nBytes = Marshal.SizeOf(typeof(UsbNodeConnectionInformationEx)); @@ -415,7 +416,7 @@ static partial class Usb // loop thru all of the ports on the hub // BTW: Ports are numbered starting at 1 - for(var i = 1; i <= HubPortCount; i++) + for(var i = 1; i <= _hubPortCount; i++) { var nodeConnection = new UsbNodeConnectionInformationEx { @@ -436,13 +437,13 @@ static partial class Usb // load up the USBPort class var port = new UsbPort { - PortPortNumber = i, - PortHubDevicePath = HubDevicePath, - PortStatus = ((UsbConnectionStatus)nodeConnection.ConnectionStatus).ToString(), - PortSpeed = ((UsbDeviceSpeed)nodeConnection.Speed).ToString(), - PortIsDeviceConnected = nodeConnection.ConnectionStatus == (int)UsbConnectionStatus.DeviceConnected, - PortIsHub = Convert.ToBoolean(nodeConnection.DeviceIsHub), - PortDeviceDescriptor = nodeConnection.DeviceDescriptor + _portPortNumber = i, + _portHubDevicePath = _hubDevicePath, + _portStatus = ((UsbConnectionStatus)nodeConnection.ConnectionStatus).ToString(), + _portSpeed = ((UsbDeviceSpeed)nodeConnection.Speed).ToString(), + _portIsDeviceConnected = nodeConnection.ConnectionStatus == (int)UsbConnectionStatus.DeviceConnected, + _portIsHub = Convert.ToBoolean(nodeConnection.DeviceIsHub), + _portDeviceDescriptor = nodeConnection.DeviceDescriptor }; // add it to the list @@ -460,61 +461,61 @@ static partial class Usb /// Represents an USB port internal class UsbPort { - internal UsbDeviceDescriptor PortDeviceDescriptor; - internal bool PortIsHub, PortIsDeviceConnected; - internal int PortPortNumber; - internal string PortStatus, PortHubDevicePath, PortSpeed; + internal UsbDeviceDescriptor _portDeviceDescriptor; + internal bool _portIsHub, _portIsDeviceConnected; + internal int _portPortNumber; + internal string _portStatus, _portHubDevicePath, _portSpeed; /// a simple default constructor internal UsbPort() { - PortPortNumber = 0; - PortStatus = ""; - PortHubDevicePath = ""; - PortSpeed = ""; - PortIsHub = false; - PortIsDeviceConnected = false; + _portPortNumber = 0; + _portStatus = ""; + _portHubDevicePath = ""; + _portSpeed = ""; + _portIsHub = false; + _portIsDeviceConnected = false; } /// return Port Index of the Hub - internal int PortNumber => PortPortNumber; + internal int PortNumber => _portPortNumber; /// return the Device Path of the Hub - internal string HubDevicePath => PortHubDevicePath; + internal string HubDevicePath => _portHubDevicePath; /// the status (see USB_CONNECTION_STATUS above) - internal string Status => PortStatus; + internal string Status => _portStatus; /// the speed of the connection (see USB_DEVICE_SPEED above) - internal string Speed => PortSpeed; + internal string Speed => _portSpeed; /// is this a downstream external hub? - internal bool IsHub => PortIsHub; + internal bool IsHub => _portIsHub; /// is anybody home? - internal bool IsDeviceConnected => PortIsDeviceConnected; + internal bool IsDeviceConnected => _portIsDeviceConnected; /// return a down stream external hub /// Downstream external hub internal UsbDevice GetDevice() { - if(!PortIsDeviceConnected) + if(!_portIsDeviceConnected) return null; // Copy over some values from the Port class // Ya know, I've given some thought about making Device a derived class... var device = new UsbDevice { - DevicePortNumber = PortPortNumber, - DeviceHubDevicePath = PortHubDevicePath, - DeviceDescriptor = PortDeviceDescriptor + _devicePortNumber = _portPortNumber, + _deviceHubDevicePath = _portHubDevicePath, + _deviceDescriptor = _portDeviceDescriptor }; // Open a handle to the Hub device - IntPtr h = CreateFile(PortHubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, + IntPtr h = CreateFile(_portHubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h == INVALID_HANDLE_VALUE) + if(h == _invalidHandleValue) return device; int nBytesReturned; @@ -527,17 +528,17 @@ static partial class Usb // Device Descriptor are really just indexes. So, we have to // request a String Descriptor to get the values for those strings. - if(PortDeviceDescriptor.iManufacturer > 0) + if(_portDeviceDescriptor.iManufacturer > 0) { // build a request for string descriptor var request = new UsbDescriptorRequest { - ConnectionIndex = PortPortNumber, + ConnectionIndex = _portPortNumber, SetupPacket = { // Language Code wIndex = 0x409, - wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iManufacturer) + wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + _portDeviceDescriptor.iManufacturer) } }; @@ -561,23 +562,23 @@ static partial class Usb (UsbStringDescriptor)(Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)) ?? default(UsbStringDescriptor)); - device.DeviceManufacturer = stringDesc.bString; + device._deviceManufacturer = stringDesc.bString; } Marshal.FreeHGlobal(ptrRequest); } - if(PortDeviceDescriptor.iProduct > 0) + if(_portDeviceDescriptor.iProduct > 0) { // build a request for string descriptor var request = new UsbDescriptorRequest { - ConnectionIndex = PortPortNumber, + ConnectionIndex = _portPortNumber, SetupPacket = { // Language Code wIndex = 0x409, - wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iProduct) + wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + _portDeviceDescriptor.iProduct) } }; @@ -598,23 +599,23 @@ static partial class Usb (UsbStringDescriptor)(Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)) ?? default(UsbStringDescriptor)); - device.DeviceProduct = stringDesc.bString; + device._deviceProduct = stringDesc.bString; } Marshal.FreeHGlobal(ptrRequest); } - if(PortDeviceDescriptor.iSerialNumber > 0) + if(_portDeviceDescriptor.iSerialNumber > 0) { // build a request for string descriptor var request = new UsbDescriptorRequest { - ConnectionIndex = PortPortNumber, + ConnectionIndex = _portPortNumber, SetupPacket = { // Language Code wIndex = 0x409, - wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iSerialNumber) + wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + _portDeviceDescriptor.iSerialNumber) } }; @@ -635,7 +636,7 @@ static partial class Usb (UsbStringDescriptor)(Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)) ?? default(UsbStringDescriptor)); - device.DeviceSerialNumber = stringDesc.bString; + device._deviceSerialNumber = stringDesc.bString; } Marshal.FreeHGlobal(ptrRequest); @@ -644,7 +645,7 @@ static partial class Usb // build a request for configuration descriptor var dcrRequest = new UsbDescriptorRequest { - ConnectionIndex = PortPortNumber, + ConnectionIndex = _portPortNumber, SetupPacket = { wIndex = 0, @@ -663,8 +664,8 @@ static partial class Usb nBytes, out nBytesReturned, IntPtr.Zero)) { var ptrStringDesc = IntPtr.Add(dcrPtrRequest, Marshal.SizeOf(dcrRequest)); - device.BinaryDeviceDescriptors = new byte[nBytesReturned]; - Marshal.Copy(ptrStringDesc, device.BinaryDeviceDescriptors, 0, nBytesReturned); + device._binaryDeviceDescriptors = new byte[nBytesReturned]; + Marshal.Copy(ptrStringDesc, device._binaryDeviceDescriptors, 0, nBytesReturned); } Marshal.FreeHGlobal(dcrPtrRequest); @@ -672,7 +673,7 @@ static partial class Usb // Get the Driver Key Name (usefull in locating a device) var driverKey = new UsbNodeConnectionDriverkeyName { - ConnectionIndex = PortPortNumber + ConnectionIndex = _portPortNumber }; nBytes = Marshal.SizeOf(driverKey); @@ -687,11 +688,11 @@ static partial class Usb typeof(UsbNodeConnectionDriverkeyName)) ?? default(UsbNodeConnectionDriverkeyName)); - device.DeviceDriverKey = driverKey.DriverKeyName; + device._deviceDriverKey = driverKey.DriverKeyName; // use the DriverKeyName to get the Device Description and Instance ID - device.DeviceName = GetDescriptionByKeyName(device.DeviceDriverKey); - device.DeviceInstanceId = GetInstanceIdByKeyName(device.DeviceDriverKey); + device._deviceName = GetDescriptionByKeyName(device._deviceDriverKey); + device._deviceInstanceId = GetInstanceIdByKeyName(device._deviceDriverKey); } Marshal.FreeHGlobal(ptrDriverKey); @@ -704,25 +705,25 @@ static partial class Usb /// Downstream external hub internal UsbHub GetHub() { - if(!PortIsHub) + if(!_portIsHub) return null; var hub = new UsbHub(); IntPtr h, h2; - hub.HubIsRootHub = false; - hub.HubDeviceDesc = "External Hub"; + hub._hubIsRootHub = false; + hub._hubDeviceDesc = "External Hub"; // Open a handle to the Host Controller - h = CreateFile(PortHubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, + h = CreateFile(_portHubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h == INVALID_HANDLE_VALUE) + if(h == _invalidHandleValue) return hub; // Get the DevicePath for downstream hub var nodeName = new UsbNodeConnectionName { - ConnectionIndex = PortPortNumber + ConnectionIndex = _portPortNumber }; int nBytes = Marshal.SizeOf(nodeName); @@ -736,14 +737,14 @@ static partial class Usb nodeName = (UsbNodeConnectionName)(Marshal.PtrToStructure(ptrNodeName, typeof(UsbNodeConnectionName)) ?? default(UsbNodeConnectionName)); - hub.HubDevicePath = @"\\.\" + nodeName.NodeName; + hub._hubDevicePath = @"\\.\" + nodeName.NodeName; } // Now let's open the Hub (based upon the HubName we got above) - h2 = CreateFile(hub.HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, + h2 = CreateFile(hub._hubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h2 != INVALID_HANDLE_VALUE) + if(h2 != _invalidHandleValue) { var nodeInfo = new UsbNodeInformation { @@ -761,8 +762,8 @@ static partial class Usb nodeInfo = (UsbNodeInformation)(Marshal.PtrToStructure(ptrNodeInfo, typeof(UsbNodeInformation)) ?? default(UsbNodeInformation)); - hub.HubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered); - hub.HubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; + hub._hubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered); + hub._hubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; } Marshal.FreeHGlobal(ptrNodeInfo); @@ -772,11 +773,11 @@ static partial class Usb // Fill in the missing Manufacture, Product, and SerialNumber values // values by just creating a Device instance and copying the values UsbDevice device = GetDevice(); - hub.HubInstanceId = device.DeviceInstanceId; - hub.HubManufacturer = device.Manufacturer; - hub.HubProduct = device.Product; - hub.HubSerialNumber = device.SerialNumber; - hub.HubDriverKey = device.DriverKey; + hub._hubInstanceId = device._deviceInstanceId; + hub._hubManufacturer = device.Manufacturer; + hub._hubProduct = device.Product; + hub._hubSerialNumber = device.SerialNumber; + hub._hubDriverKey = device.DriverKey; Marshal.FreeHGlobal(ptrNodeName); CloseHandle(h); @@ -788,48 +789,48 @@ static partial class Usb /// Represents an USB device internal class UsbDevice { - internal byte[] BinaryDeviceDescriptors; - internal UsbDeviceDescriptor DeviceDescriptor; - internal string DeviceDriverKey, DeviceHubDevicePath, DeviceInstanceId, DeviceName; - internal string DeviceManufacturer, DeviceProduct, DeviceSerialNumber; - internal int DevicePortNumber; + internal byte[] _binaryDeviceDescriptors; + internal UsbDeviceDescriptor _deviceDescriptor; + internal string _deviceDriverKey, _deviceHubDevicePath, _deviceInstanceId, _deviceName; + internal string _deviceManufacturer, _deviceProduct, _deviceSerialNumber; + internal int _devicePortNumber; /// a simple default constructor internal UsbDevice() { - DevicePortNumber = 0; - DeviceHubDevicePath = ""; - DeviceDriverKey = ""; - DeviceManufacturer = ""; - DeviceProduct = "Unknown USB Device"; - DeviceSerialNumber = ""; - DeviceName = ""; - DeviceInstanceId = ""; - BinaryDeviceDescriptors = null; + _devicePortNumber = 0; + _deviceHubDevicePath = ""; + _deviceDriverKey = ""; + _deviceManufacturer = ""; + _deviceProduct = "Unknown USB Device"; + _deviceSerialNumber = ""; + _deviceName = ""; + _deviceInstanceId = ""; + _binaryDeviceDescriptors = null; } /// return Port Index of the Hub - internal int PortNumber => DevicePortNumber; + internal int PortNumber => _devicePortNumber; /// return the Device Path of the Hub (the parent device) - internal string HubDevicePath => DeviceHubDevicePath; + internal string HubDevicePath => _deviceHubDevicePath; /// useful as a search key - internal string DriverKey => DeviceDriverKey; + internal string DriverKey => _deviceDriverKey; /// the device path of this device - internal string InstanceId => DeviceInstanceId; + internal string InstanceId => _deviceInstanceId; /// the friendly name - internal string Name => DeviceName; + internal string Name => _deviceName; - internal string Manufacturer => DeviceManufacturer; + internal string Manufacturer => _deviceManufacturer; - internal string Product => DeviceProduct; + internal string Product => _deviceProduct; - internal string SerialNumber => DeviceSerialNumber; + internal string SerialNumber => _deviceSerialNumber; - internal byte[] BinaryDescriptors => BinaryDeviceDescriptors; + internal byte[] BinaryDescriptors => _binaryDeviceDescriptors; } #region "API Region" @@ -839,7 +840,7 @@ static partial class Usb const int FILE_SHARE_READ = 0x1; const int FILE_SHARE_WRITE = 0x2; const int OPEN_EXISTING = 0x3; - static readonly IntPtr INVALID_HANDLE_VALUE = new(-1); + static readonly IntPtr _invalidHandleValue = new(-1); const int IOCTL_GET_HCD_DRIVERKEY_NAME = 0x220424; const int IOCTL_USB_GET_ROOT_HUB_NAME = 0x220408; diff --git a/Aaru.Devices/Windows/UsbFunctions.cs b/Aaru.Devices/Windows/UsbFunctions.cs index 5ab815512..a9fe7e30b 100644 --- a/Aaru.Devices/Windows/UsbFunctions.cs +++ b/Aaru.Devices/Windows/UsbFunctions.cs @@ -46,10 +46,10 @@ using System.Runtime.InteropServices; static partial class Usb { const int IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080; - internal const string GuidDevinterfaceDisk = "53f56307-b6bf-11d0-94f2-00a0c91efb8b"; - internal const string GuidDevinterfaceCdrom = "53f56308-b6bf-11d0-94f2-00a0c91efb8b"; - internal const string GuidDevinterfaceFloppy = "53f56311-b6bf-11d0-94f2-00a0c91efb8b"; - internal const string GuidDevinterfaceTape = "53f5630b-b6bf-11d0-94f2-00a0c91efb8b"; + internal const string GUID_DEVINTERFACE_DISK = "53f56307-b6bf-11d0-94f2-00a0c91efb8b"; + internal const string GUID_DEVINTERFACE_CDROM = "53f56308-b6bf-11d0-94f2-00a0c91efb8b"; + internal const string GUID_DEVINTERFACE_FLOPPY = "53f56311-b6bf-11d0-94f2-00a0c91efb8b"; + internal const string GUID_DEVINTERFACE_TAPE = "53f5630b-b6bf-11d0-94f2-00a0c91efb8b"; /// Get a list of all connected devices /// List of usb devices @@ -112,7 +112,7 @@ static partial class Usb UsbDevice device = port.GetDevice(); - if(device.DeviceDriverKey != driverKeyName) + if(device._deviceDriverKey != driverKeyName) continue; foundDevice = device; @@ -213,7 +213,7 @@ static partial class Usb // devices that match the interface GUID of a disk IntPtr h = SetupDiGetClassDevs(ref diskGuid, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); - if(h != INVALID_HANDLE_VALUE) + if(h != _invalidHandleValue) { bool success; var i = 0; @@ -241,9 +241,9 @@ static partial class Usb // now we can get some more detailed information var nRequiredSize = 0; - const int N_BYTES = BUFFER_SIZE; + const int nBytes = BUFFER_SIZE; - if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, N_BYTES, ref nRequiredSize, ref da)) + if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da)) if(GetDeviceNumber(didd.DevicePath) == devNum) { // current InstanceID is at the "USBSTOR" level, so we @@ -251,8 +251,8 @@ static partial class Usb CM_Get_Parent(out IntPtr ptrPrevious, da.DevInst, 0); // Now we get the InstanceID of the USB level device - IntPtr ptrInstanceBuf = Marshal.AllocHGlobal(N_BYTES); - CM_Get_Device_ID(ptrPrevious, ptrInstanceBuf, N_BYTES, 0); + IntPtr ptrInstanceBuf = Marshal.AllocHGlobal(nBytes); + CM_Get_Device_ID(ptrPrevious, ptrInstanceBuf, nBytes, 0); instanceId = Marshal.PtrToStringAuto(ptrInstanceBuf); Marshal.FreeHGlobal(ptrInstanceBuf); @@ -284,7 +284,7 @@ static partial class Usb IntPtr h = CreateFile(devicePath.TrimEnd('\\'), 0, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h == INVALID_HANDLE_VALUE) + if(h == _invalidHandleValue) return ans; var sdn = new StorageDeviceNumber(); @@ -293,7 +293,8 @@ static partial class Usb if(DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, IntPtr.Zero, 0, ptrSdn, nBytes, out _, IntPtr.Zero)) { - sdn = (StorageDeviceNumber)Marshal.PtrToStructure(ptrSdn, typeof(StorageDeviceNumber)); + sdn = (StorageDeviceNumber)(Marshal.PtrToStructure(ptrSdn, typeof(StorageDeviceNumber)) ?? + default(StorageDeviceNumber)); // just my way of combining the relevant parts of the // STORAGE_DEVICE_NUMBER into a single number diff --git a/Aaru.Filesystems/CPM/Info.cs b/Aaru.Filesystems/CPM/Info.cs index 4140e5364..b163b9475 100644 --- a/Aaru.Filesystems/CPM/Info.cs +++ b/Aaru.Filesystems/CPM/Info.cs @@ -375,8 +375,8 @@ public sealed partial class CPM var directoryLength = (uint)(((ulong)_dpb.drm + 1) * 32 / sectorSize); - errno = imagePlugin.ReadSectors(firstDirectorySector + partition.Start, directoryLength, - out directory); + imagePlugin.ReadSectors(firstDirectorySector + partition.Start, directoryLength, + out directory); AaruConsole.DebugWriteLine("CP/M Plugin", "Found CP/M-86 hard disk superblock."); @@ -902,8 +902,8 @@ public sealed partial class CPM { var directoryLength = (uint)(((ulong)_dpb.drm + 1) * 32 / imagePlugin.Info.SectorSize); - errno = imagePlugin.ReadSectors(firstDirectorySector86 + partition.Start, directoryLength, - out directory); + imagePlugin.ReadSectors(firstDirectorySector86 + partition.Start, directoryLength, + out directory); AaruConsole.DebugWriteLine("CP/M Plugin", "Found CP/M-86 floppy identifier."); } diff --git a/Aaru.Filesystems/FAT/BPB.cs b/Aaru.Filesystems/FAT/BPB.cs index d0768f520..ee05ffca8 100644 --- a/Aaru.Filesystems/FAT/BPB.cs +++ b/Aaru.Filesystems/FAT/BPB.cs @@ -376,7 +376,7 @@ public sealed partial class FAT // Volume is software interleaved 2:1 var rootMs = new MemoryStream(); - foreach(ulong rootSector in new[] + foreach(ulong rootSector in new ulong[] { 0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20 }) diff --git a/Aaru.Filesystems/FAT/Info.cs b/Aaru.Filesystems/FAT/Info.cs index 8ecfe7562..ed37466e4 100644 --- a/Aaru.Filesystems/FAT/Info.cs +++ b/Aaru.Filesystems/FAT/Info.cs @@ -1020,7 +1020,7 @@ public sealed partial class FAT { var rootMs = new MemoryStream(); - foreach(ulong rootSector in new[] + foreach(ulong rootSector in new ulong[] { 0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20 }) diff --git a/Aaru.Filesystems/FAT/Super.cs b/Aaru.Filesystems/FAT/Super.cs index 2dc1520bc..b9565b1f4 100644 --- a/Aaru.Filesystems/FAT/Super.cs +++ b/Aaru.Filesystems/FAT/Super.cs @@ -549,7 +549,7 @@ public sealed partial class FAT { var rootMs = new MemoryStream(); - foreach(ulong rootSector in new[] + foreach(ulong rootSector in new ulong[] { 0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20 }) diff --git a/Aaru.sln.DotSettings b/Aaru.sln.DotSettings index af5a9679b..2ea982ec2 100644 --- a/Aaru.sln.DotSettings +++ b/Aaru.sln.DotSettings @@ -432,6 +432,8 @@ True True True + True + True True True True @@ -566,4 +568,6 @@ True True True + True + True True \ No newline at end of file