using System; using System.Collections.Generic; using System.Text; namespace Bwg.Hardware { /// /// This class represents a hardware device as extracted from the registry. /// public class HardwareDevice { #region private member variables private string m_name; private string m_desc; private string m_class; private Guid m_class_guid; private string m_key_name ; private string m_location; private string[] m_hardware; #endregion #region constructor /// /// The constructor for a device. /// /// the name of the registry key that contains info about this device public HardwareDevice(string key) { m_key_name = key; m_name = string.Empty ; m_desc = string.Empty ; m_location = string.Empty; m_hardware = new string[0]; } #endregion #region public methods /// /// Add a new hardware address to the device /// /// the new address to add to the device public void AddHardware(string addr) { int count = m_hardware.GetLength(0); Array.Resize(ref m_hardware, count + 1); m_hardware[count] = addr; } #endregion #region public properties /// /// The name of the key where this information was extracted /// public string KeyName { get { return m_key_name; } } /// /// This property is the (friendly) name of the device /// public string Name { get { if (m_name != string.Empty) return m_name; if (m_desc != string.Empty) return m_desc; return m_key_name; } set { m_name = value; } } /// /// This property is the description of the device /// public string Description { get { return m_desc; } set { m_desc = value; } } /// /// This property is the class that the device belong to /// public string Class { get { return m_class; } set { m_class = value; } } /// /// This property is the GUID for the class that the device belongs to /// public Guid ClassGUID { get { return m_class_guid; } set { m_class_guid = value; } } /// /// This property is the location of the device /// public string Location { get { return m_location; } set { m_location = value; } } /// /// This class is the hardware addresses assocaited with the device /// public string[] Hardware { get { return m_hardware; } } /// /// This property returns true if the device is an IDE device /// public bool IsIde { get { return HardwareStartsWith("IDE"); } } /// /// This property returns true if this is a USB device /// public bool IsUsb { get { return HardwareStartsWith("USB") ; } } /// /// This property returns true if this is a Firewire device /// public bool IsFirewire { get { return HardwareStartsWith("SBP2"); } } /// /// This property returns true if this is a SCSI device /// public bool IsScsi { get { return HardwareStartsWith("SCSI"); } } #endregion #region private methods /// /// This method returns true if the hardware address start with the string given /// /// the string to start with /// true if the string begins with the right value, otherwise false public bool HardwareStartsWith(string begin) { foreach (string str in m_hardware) { if (str.StartsWith(begin)) return true; } return false; } #endregion } }