/// <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);
        }
示例#3
0
        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);
        }