internal PCIDeviceClassProgramingInterface(
            PCIDeviceBaseClass parentBaseClass,
            PCIDeviceSubClass parentSubClass,
            string subSystemInfo)
        {
            ParentBaseClass = parentBaseClass;
            ParentSubClass  = parentSubClass;
            var parts = subSystemInfo.Split(new[] { "  " }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length < 2)
            {
                throw new ArgumentException(@"Invalid device class programing interface info format.",
                                            nameof(subSystemInfo));
            }

            InterfaceId   = Convert.ToByte(parts[0], 16);
            InterfaceName = string.Join(" ", parts.Skip(2));
        }
Beispiel #2
0
        /// <summary>
        ///     Reloads cached list of vendors and classes from disk and into memory
        /// </summary>
        // ReSharper disable once ExcessiveIndentation
        public static void Reload()
        {
            lock (LockObject)
            {
                _vendors     = new List <PCIVendor>();
                _baseClasses = new List <PCIDeviceBaseClass>();

                using (var memoryStream = new MemoryStream(Resources.pci))
                {
                    using (var streamReader = new StreamReader(memoryStream))
                    {
                        PCIVendor          lastVendor    = null;
                        PCIDevice          lastDevice    = null;
                        PCIDeviceBaseClass lastBaseClass = null;
                        PCIDeviceSubClass  lastSubClass  = null;

                        while (!streamReader.EndOfStream)
                        {
                            var line = streamReader.ReadLine();

                            if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#"))
                            {
                                continue;
                            }

                            if (line.StartsWith("C "))
                            {
                                // Parse base class
                                lastVendor = null;
                                lastDevice = null;

                                try
                                {
                                    lastBaseClass = new PCIDeviceBaseClass(line.Substring(2).Trim());
                                    _baseClasses.Add(lastBaseClass);
                                }
                                catch
                                {
                                    lastBaseClass = null;
                                }
                            }
                            else if (line.StartsWith("\t\t"))
                            {
                                if (lastDevice != null)
                                {
                                    // Parse sub device
                                    try
                                    {
                                        var subDevice = new PCISubSystem(lastVendor, lastDevice, line.Trim());
                                        lastDevice.AddSubSystem(subDevice);
                                    }
                                    catch
                                    {
                                        // ignored
                                    }
                                }
                                else if (lastSubClass != null)
                                {
                                    // Parse class programing interface
                                    try
                                    {
                                        var programingInterface =
                                            new PCIDeviceClassProgramingInterface(lastBaseClass, lastSubClass,
                                                                                  line.Trim());
                                        lastSubClass.AddProgramingInterface(programingInterface);
                                    }
                                    catch
                                    {
                                        // ignored
                                    }
                                }
                            }
                            else if (line.StartsWith("\t"))
                            {
                                if (lastVendor != null)
                                {
                                    // Parse device
                                    try
                                    {
                                        lastDevice = new PCIDevice(lastVendor, line.Trim());
                                        lastVendor.AddDevice(lastDevice);
                                    }
                                    catch
                                    {
                                        lastDevice = null;
                                        lastVendor = null;
                                    }
                                }
                                else if (lastBaseClass != null)
                                {
                                    // Parse sub class
                                    try
                                    {
                                        lastSubClass = new PCIDeviceSubClass(lastBaseClass, line.Trim());
                                        lastBaseClass.AddSubClass(lastSubClass);
                                    }
                                    catch
                                    {
                                        lastSubClass  = null;
                                        lastBaseClass = null;
                                    }
                                }
                            }
                            else
                            {
                                // Parse vendor
                                lastBaseClass = null;
                                lastSubClass  = null;

                                try
                                {
                                    lastVendor = new PCIVendor(line.Trim());
                                    _vendors.Add(lastVendor);
                                }
                                catch
                                {
                                    lastVendor = null;
                                }
                            }
                        }
                    }
                }
            }
        }