Exemple #1
0
        internal PCIDevice(PCIVendor parentVendor, string deviceInfo)
        {
            ParentVendor = parentVendor;
            var parts = deviceInfo.Split(new[] { "  " }, StringSplitOptions.RemoveEmptyEntries);

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

            DeviceId   = Convert.ToUInt16(parts[0], 16);
            DeviceName = string.Join(" ", parts.Skip(1));
        }
Exemple #2
0
        internal PCISubSystem(PCIVendor parentVendor, PCIDevice parentDevice, string subSystemInfo)
        {
            ParentVendor = parentVendor;
            ParentDevice = parentDevice;
            var parts = subSystemInfo.Split(new[] { "  " }, StringSplitOptions.RemoveEmptyEntries);

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

            var idParts = parts[0].Split(' ');

            if (idParts.Length < 2)
            {
                throw new ArgumentException(@"Invalid sub device info format.", nameof(subSystemInfo));
            }

            VendorId = Convert.ToUInt16(idParts[0], 16);
            DeviceId = Convert.ToUInt16(idParts[1], 16);

            SubSystemName = string.Join(" ", parts.Skip(1));
        }
Exemple #3
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;
                                }
                            }
                        }
                    }
                }
            }
        }