/// <summary> /// Adds the drivers to this control. /// </summary> /// <param name="drivers">The drivers.</param> public void AddDrivers(PrintDeviceDriverCollection drivers) { if (drivers == null) { throw new ArgumentNullException("drivers"); } Items.Clear(); foreach (PrintDeviceDriver driver in drivers) { // Sneak an extra space on each name that is the same to create uniqueness. if (!_padding.ContainsKey(driver.Name)) { _padding.Add(driver.Name, 0); } string name = driver.Name.PadRight(driver.Name.Length + _padding[driver.Name]++, ' '); AddItem ( name, EnumUtil.GetDescription(driver.Architecture), driver.Version.ToString(), Path.GetFileName(driver.InfPath) ); } }
/// <summary> /// Loads the drivers. /// </summary> public void LoadDrivers() { var selectedItem = installedDrivers_ComboBox.SelectedData; PrintDeviceDriverCollection drivers = new PrintDeviceDriverCollection(); drivers.AddRange(DriverController.LoadFromRegistry().Select(n => new PrintDeviceDriver(n))); drivers.Sort(); installedDrivers_ComboBox.Items.Clear(); installedDrivers_ComboBox.AddDrivers(drivers); if (selectedItem.Count > 0) { ProcessorArchitecture arch = EnumUtil.Parse <ProcessorArchitecture>(selectedItem["Architecture"]); DriverVersion version = new DriverVersion(selectedItem["Version"]); int index = drivers.IndexOf(selectedItem["Name"], arch.ToDriverArchitecture(), version, selectedItem["InfFile"]); if (index != -1) { installedDrivers_ComboBox.SelectedIndex = index; } } else { installedDrivers_ComboBox.SelectedIndex = 0; } }
/// <summary> /// Builds a <see cref="PrintDeviceDriverCollection"/> based off of the folder path to a print driver package. /// </summary> /// <param name="directory">Folder path to a print driver package.</param> /// <param name="versionPath">The base path to the driver repository. Everything after this path in parameter /// <paramref name="directory"/> is considered the version.</param> /// <returns> /// A <see cref="PrintDeviceDriverCollection"/> based on <paramref name="directory"/> /// </returns> public static PrintDeviceDriverCollection LoadDrivers(string directory, string versionPath) { if (string.IsNullOrEmpty(directory)) { throw new ArgumentNullException("directory"); } if (string.IsNullOrEmpty(versionPath)) { throw new ArgumentNullException("versionPath"); } PrintDeviceDriverCollection drivers = new PrintDeviceDriverCollection(); drivers.AddRange(DriverController.LoadFromDirectory(directory, true, SearchOption.AllDirectories).Select(n => new PrintDeviceDriver(n))); // The version of a package is defined as the relative path of the directory. // This is only used when copying a driver down from the CSL central repository. If this is a // local print driver install then this can be skipped as it won't be used. if (directory.StartsWith(versionPath, StringComparison.OrdinalIgnoreCase)) { drivers.Version = directory.Substring(versionPath.Length).Trim(Path.DirectorySeparatorChar); } return(drivers); }
/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { PrintDeviceDriverCollection drivers = obj as PrintDeviceDriverCollection; if (drivers == null) { return(false); } var setA = (from d in _driverProperties select d.InfPath); var setB = (from d in drivers select d.InfPath); // These packages are considered the same if their version and INF file locations are the same. return(drivers.Version.Equals(Version, StringComparison.OrdinalIgnoreCase) && new HashSet <string>(setA).SetEquals(setB)); }
private PrintDeviceDriverCollection LoadDrivers ( string currentDirectory, bool includeAllArchitectures, SearchOption searchOption ) { PrintDeviceDriverCollection drivers = new PrintDeviceDriverCollection(); drivers.AddRange(DriverController.LoadFromDirectory(currentDirectory, includeAllArchitectures, searchOption).Select(n => new PrintDeviceDriver(n))); if (_tokenSource.IsCancellationRequested) { TraceFactory.Logger.Debug("Cancellation received, returning..."); return(drivers); } _totalDirectoriesScanned++; FireScannedEvent(currentDirectory); return(drivers); }
/// <summary> /// Adds the elements of the specified collection to the end of the <see cref="HP.ScalableTest.Print.PrintDeviceDriverCollection"/>. /// </summary> /// <param name="collection">The collection whose elements should be added to the end of the <see cref="HP.ScalableTest.Print.PrintDeviceDriverCollection"/>.</param> public void Add(PrintDeviceDriverCollection collection) { AddRange(collection); }