private static List <string> UISelectHardwareID(PNPDriverDirectory pnpDriverDirectory, WindowsInstallation installation,
                                                        bool useLocalHardwareConfig, string enumExportPath)
        {
            var hardwareIDs         = new List <string>();
            var containsRootDevices = pnpDriverDirectory.ContainsRootDevices(installation.ArchitectureIdentifier,
                                                                             installation.MinorOSVersion, installation.ProductType);

            // We should not use our detection mechanism if a driver directory contains a root device.
            if (!containsRootDevices && (useLocalHardwareConfig || enumExportPath != string.Empty))
            {
                var matchingHardwareIDs = useLocalHardwareConfig
                                        ? PNPLocalHardwareDetector.DetectMatchingLocalHardware(pnpDriverDirectory, installation.ArchitectureIdentifier,
                                                                                               installation.MinorOSVersion, installation.ProductType)
                                        : PNPExportedHardwareDetector.DetectMatchingExportedHardware(enumExportPath, pnpDriverDirectory,
                                                                                                     installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType);

                var devices = pnpDriverDirectory.ListDevices(installation.ArchitectureIdentifier, installation.MinorOSVersion,
                                                             installation.ProductType);
                // We now have a list of hardware IDs that matches (some of) our devices, let's found out which of the devices match
                var matchingDevices = new List <KeyValuePair <string, string> >();
                foreach (var device in devices)
                {
                    if (matchingHardwareIDs.Contains(device.Key))
                    {
                        matchingDevices.Add(device);
                    }
                }
                Console.WriteLine();
                Console.WriteLine("Looking for matching device drivers in directory '{0}':", pnpDriverDirectory.Path);
                foreach (var device in matchingDevices)
                {
                    hardwareIDs.Add(device.Key);
                }
            }
            else
            {
                foreach (var device in pnpDriverDirectory.ListDevices(
                             installation.ArchitectureIdentifier,
                             installation.MinorOSVersion,
                             installation.ProductType))
                {
                    hardwareIDs.Add(device.Key);
                }
            }

            return(hardwareIDs);
        }
Пример #2
0
        private void RegisterPhysicalDevice(PNPDriverINFFile pnpDriverInf)
        {
            if (_preconfigure && pnpDriverInf.IsNetworkAdapter && (_useLocalHardwareConfig || _enumExportPath != string.Empty))
            {
                string deviceID;
                string deviceInstanceID;

                if (_useLocalHardwareConfig)
                {
                    deviceInstanceID = PNPLocalHardwareDetector.DetectLocalDeviceInstanceID(HardwareID, out deviceID);
                    if (deviceInstanceID == string.Empty)
                    {
                        Console.WriteLine(
                            "Warning: Could not detect matching device installed locally, configuration will not be applied!");
                    }
                }
                else                 // m_enumExportPath != string.Empty
                {
                    deviceInstanceID = PNPExportedHardwareDetector.DetectExportedDeviceInstanceID(_enumExportPath, HardwareID, out deviceID);
                    if (deviceInstanceID == string.Empty)
                    {
                        Console.WriteLine(
                            "Warning: Could not detect matching device in the exported registry, configuration will not be applied!");
                    }
                }

                if (deviceInstanceID != string.Empty)
                {
                    // m_netDeviceServices is now populated
                    if (NetworkDeviceServices.Count > 0)
                    {
                        // unlike other types of hardware (SCSI controllers etc.), it's not enough to add a NIC to the
                        // Criticla Device Database (CDDB) to make it usable during boot, as mentioned in the comments above RegisterNicAsCriticalDevice()
                        // at the very least, a CDDB entry and a "Device" registry value under Enum\Enumerator\DeviceID\DeviceInstanceID is required
                        // (as well as DeviceDesc if not automatically added by the kernel-PNP)
                        // here we manually register the hardware in advance, but it's better to use NICBootConf to do this during boot,
                        // NICBootConf will also work if the NIC has been moved to another PCI slot since creating the installation media.

                        // the first item in m_netDeviceServices should be the actual NIC (CHECKME: what about NIC / bus driver combination like nVIdia)
                        var deviceService = NetworkDeviceServices[0];
                        var enumerator    = PNPDriverIntegratorUtils.GetEnumeratorNameFromHardwareID(HardwareID);
                        PreconfigureDeviceInstance(pnpDriverInf, enumerator, deviceID, deviceInstanceID, deviceService);
                    }
                    else
                    {
                        Console.WriteLine(
                            "Warning: failed to install '{0}', because the service for this network adapter has not been registered!",
                            HardwareID);
                    }
                }
            }
            else
            {
                // if it's a NIC, We assume the user will integrate NICBootConf, which will configure the network adapter during boot.
                // we'll just add the device to the Criticla Device Database (CDDB), and let kernel-PNP and NICBootConf do the rest.
                if (pnpDriverInf.IsNetworkAdapter)
                {
                    // NICBootConf needs the ClassGUID in place for each DeviceInstance Key,
                    // if we put the ClassGUID in the CDDB, the ClassGUID will be applied to each DeviceInstance with matching hardwareID
                    _installation.TextSetupInf.AddDeviceToCriticalDeviceDatabase(HardwareID, DeviceServices[0].ServiceName, PNPDriverINFFile.NetworkAdapterClassGUID);
                    _installation.HiveSystemInf.AddDeviceToCriticalDeviceDatabase(HardwareID, DeviceServices[0].ServiceName, PNPDriverINFFile.NetworkAdapterClassGUID);
                }
                else
                {
                    _installation.TextSetupInf.AddDeviceToCriticalDeviceDatabase(HardwareID, DeviceServices[0].ServiceName);
                    _installation.HiveSystemInf.AddDeviceToCriticalDeviceDatabase(HardwareID, DeviceServices[0].ServiceName);
                }
            }
        }