Ejemplo n.º 1
0
        private static IEnumerable <DriverDetails> LoadDrivers(string environment, DriverArchitecture architecture)
        {
            string driversRegistryPath = @"SYSTEM\CurrentControlSet\Control\Print\Environments\{0}\Drivers\Version-3";

            List <DriverDetails> drivers = new List <DriverDetails>();

            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(string.Format(driversRegistryPath, environment)))
            {
                if (key != null)
                {
                    foreach (string driverName in key.GetSubKeyNames())
                    {
                        using (RegistryKey driverKey = key.OpenSubKey(driverName))
                        {
                            // The registry entry for the driver must have the DriverVersion.  If not,
                            // we will consider this entry NOT a driver...
                            if (driverKey?.GetValue("DriverVersion") != null)
                            {
                                DriverDetails driver = CreateDriverDetails(driverKey, driverName);
                                driver.Architecture = architecture;
                                drivers.Add(driver);
                            }
                        }
                    }
                }
            }
            return(drivers);
        }
Ejemplo n.º 2
0
        private static Collection <string> GetCollection(DriverArchitecture architecture)
        {
            Collection <string> processors = null;

            if (!_processorsByArchitecture.TryGetValue(architecture, out processors))
            {
                processors = new Collection <string>();
                _processorsByArchitecture.Add(architecture, processors);
            }

            return(processors);
        }
        private void SelectComboBoxItem(string name, DriverArchitecture architecture, DriverVersion version, string path)
        {
            int index = _manager.PrintDrivers.IndexOf(name, architecture, version, Path.GetFileName(path));

            TraceFactory.Logger.Debug("INDEX: {0}".FormatWith(index));

            if (index >= 0)
            {
                driverModel_ComboBox.SelectedIndex = index;
            }

            TraceFactory.Logger.Debug("Selected Index Updated");

            driverModel_ComboBox.SelectedText = string.Empty;
        }
        /// <summary>
        /// Gets the index of the <see cref="HP.ScalableTest.Print.PrintDeviceDriverCollection"/> based on the provided criteria
        /// </summary>
        /// <param name="name">The name of the driver.</param>
        /// <param name="architecture">The applicable system architecture.</param>
        /// <param name="version">The version of the driver.</param>
        /// <param name="infFile">The INF file path for.</param>
        /// <returns></returns>
        public int IndexOf(string name, DriverArchitecture architecture, DriverVersion version, string infFile)
        {
            var enumeratedProperties = _driverProperties.Select((item, i) => new { Items = item, Index = i });

            var entry =
                (
                    from p in enumeratedProperties
                    where p.Items.Architecture == architecture &&
                    p.Items.Name.EqualsIgnoreCase(name) &&
                    p.Items.Version.Equals(version) &&
                    string.IsNullOrEmpty(p.Items.InfPath) == false &&
                    Path.GetFileName(p.Items.InfPath).EqualsIgnoreCase(Path.GetFileName(infFile))
                    select p
                ).FirstOrDefault();

            return(entry != null ? entry.Index : -1);
        }
Ejemplo n.º 5
0
        public IEnumerable <DriverDetails> GetAvailableDrivers()
        {
            List <DriverDetails> availableDrivers = new List <DriverDetails>();

            // First, figure out what versions of the driver are available.
            foreach (string line in _reader.GetSection("Manufacturer"))
            {
                string cleanLine = ExpandVariables(line);

                // We only care what's on the right side of the equal sign.
                string versionLine = cleanLine.Split('=')[1];

                // The syntax of the right-side of the equal sign is "model-section-name[,TargetOSVersion][,TargetOSVersion]..."
                string[] versions = versionLine.Split(',');

                // The first index is our model-section-name.
                string modelName = versions[0].Trim();

                // Get all drivers in the model section.
                List <DriverDetails> topDrivers = GetDrivers(modelName).ToList();
                topDrivers.ForEach(n => n.Architecture = DriverArchitecture.NTx86);
                availableDrivers.AddRange(topDrivers);

                // Parse each of the subsections.
                foreach (string version in versions.Skip(1).Select(n => n.Trim()))
                {
                    List <DriverDetails> drivers      = GetDrivers($"{modelName}.{version}").ToList();
                    DriverArchitecture   architecture = GetArchitecture(version);
                    drivers.ForEach(n => n.Architecture = architecture);
                    availableDrivers.AddRange(drivers);
                }
            }

            // INF files could contain x86 and x64 entries, however with print drivers, the INF file can only support
            // one or the other.  When investigating some UPD drivers, I discovered that on x64 INF files, an entry
            // exists for x86 (and internally, they redirect the INF to install the x64-version of the driver).
            // For this reason, if we see any drivers that support x64, remove the x86 entries.
            if (availableDrivers.Any(n => n.Architecture == DriverArchitecture.NTAMD64) && availableDrivers.Any(n => n.Architecture == DriverArchitecture.NTx86))
            {
                DriverArchitecture current = Environment.Is64BitOperatingSystem ? DriverArchitecture.NTAMD64 : DriverArchitecture.NTx86;
                availableDrivers.RemoveAll(n => n.Architecture != current);
            }

            return(availableDrivers);
        }