コード例 #1
0
        public static string UISelectHardwareID(PNPDriverDirectory pnpDriverDirectory, WindowsInstallation installation, bool useLocalHardwareConfig, string enumExportPath)
        {
            string hardwareID;
            bool   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))
            {
                List <string> matchingHardwareIDs;
                if (useLocalHardwareConfig)
                {
                    matchingHardwareIDs = PNPLocalHardwareDetector.DetectMatchingLocalHardware(pnpDriverDirectory, installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType);
                }
                else
                {
                    matchingHardwareIDs = PNPExportedHardwareDetector.DetectMatchingExportedHardware(enumExportPath, pnpDriverDirectory, installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType);
                }
                List <KeyValuePair <string, string> > 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
                List <KeyValuePair <string, string> > matchingDevices = new List <KeyValuePair <string, string> >();
                foreach (KeyValuePair <string, string> 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);
                hardwareID = UISelectMatchingHardwareID(matchingDevices);
            }
            else
            {
                hardwareID = UISelectMatchingHardwareID(pnpDriverDirectory, installation.ArchitectureIdentifier, installation.MinorOSVersion, installation.ProductType);
            }

            return(hardwareID);
        }
コード例 #2
0
        public void RegisterPhysicalDevice(PNPDriverINFFile pnpDriverInf)
        {
            if (m_preconfigure && pnpDriverInf.IsNetworkAdapter && (m_useLocalHardwareConfig || m_enumExportPath != String.Empty))
            {
                string deviceID;
                string deviceInstanceID;

                if (m_useLocalHardwareConfig)
                {
                    deviceInstanceID = PNPLocalHardwareDetector.DetectLocalDeviceInstanceID(this.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(m_enumExportPath, this.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 (this.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)
                        NetworkDeviceService deviceService = this.NetworkDeviceServices[0];
                        string enumerator = PNPDriverIntegratorUtils.GetEnumeratorNameFromHardwareID(this.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!", this.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
                    m_installation.TextSetupInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName, PNPDriverINFFile.NetworkAdapterClassGUID);
                    m_installation.HiveSystemInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName, PNPDriverINFFile.NetworkAdapterClassGUID);
                }
                else
                {
                    m_installation.TextSetupInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName);
                    m_installation.HiveSystemInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName);
                }
            }
        }