示例#1
0
        /// <summary>
        /// Import a driver package file (Self-extracting .exe or .zip)
        /// </summary>
        private bool ImportPackageFile()
        {
            string source = _welcomeControl.PrintDriverPaths.FirstOrDefault();
            string destinationDirectory = _completionControl.DestinationPaths.FirstOrDefault();
            string destination          = Path.Combine(PrintDriversManager.DriverRepositoryLocation, destinationDirectory);

            try
            {
                if (!CheckDestination(destination))
                {
                    return(false);
                }

                // Unzips the package to the destination server
                ZipFile.ExtractToDirectory(source, destination);

                // Read .inf files in the new destination folder to create database entries
                using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
                {
                    //add the x86 and x64 drivers
                    foreach (string fileName in Directory.GetFiles(destination, "*.inf", SearchOption.TopDirectoryOnly))
                    {
                        using (DriverInfReader reader = new DriverInfReader(fileName))
                        {
                            DriverInfParser parser = new DriverInfParser(reader);
                            DriverInf       inf    = parser.BuildInf();
                            if (inf.DriverClass == "Printer")
                            {
                                //if this is a fax driver, ignore it
                                string driverName = parser.GetDiscreteDriverName();
                                if (!driverName.Contains("fax", StringComparison.OrdinalIgnoreCase))
                                {
                                    UpdateRepositoryDatabase(inf, driverName, destinationDirectory, context);
                                }
                            }
                        }
                    }
                    context.SaveChanges();
                }

                return(true);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                TraceFactory.Logger.Error(ex.Message, ex);
                MessageBox.Show(ex.Message, "Import Package File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (InvalidDataException ex)
            {
                TraceFactory.Logger.Error(ex.Message, ex);
                StringBuilder message = new StringBuilder("Unable to extract:");
                message.AppendLine();
                message.AppendLine(source);
                message.AppendLine("Try manually extracting the driver package, then import using 'Driver INF Folder'.");
                MessageBox.Show(message.ToString(), "Import Package File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(false);
        }
示例#2
0
        private string ExtractDriverName(string infSoucePath)
        {
            using (DriverInfReader reader = new DriverInfReader(infSoucePath))
            {
                DriverInfParser parser     = new DriverInfParser(reader);
                string          driverName = parser.GetDiscreteDriverName();

                //if this is a fax driver, ignore it
                if (!driverName.Contains("fax", StringComparison.OrdinalIgnoreCase))
                {
                    return(driverName);
                }
            }

            return(string.Empty);
        }
示例#3
0
        private void GetInfFile(string folderPath)
        {
            //only searching the top level directory for INF files, the discrete driver has lot of INF files in various directory, which is unnecessary to go through.
            Collection <DriverInf> files = new Collection <DriverInf>();

            foreach (string fileName in Directory.GetFiles(folderPath, "*.inf", SearchOption.TopDirectoryOnly))
            {
                using (DriverInfReader reader = new DriverInfReader(fileName))
                {
                    DriverInfParser parser = new DriverInfParser(reader);
                    DriverInf       inf    = parser.BuildInf();
                    if (inf.DriverClass == "Printer")
                    {
                        files.Add(inf);
                    }
                }
            }

            switch (files.Count())
            {
            case 0:
                MessageBox.Show("The selected directory does not contain any print drivers. \nPlease select the directory which has the print driver setup information file (*.inf).", "Print Driver not found",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                break;

            case 1:
                location_ListBox.Items.Add(files[0].Location);
                break;

            default:
                MessageBox.Show("The selected directory contains more than one print driver setup information file (*.inf).\nPlease choose the file you want to use.", "Multiple .INF Files Found",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                using (InfPreviewForm previewForm = new InfPreviewForm())
                {
                    previewForm.Text = folderPath;
                    previewForm.Initialize(files);
                    if (previewForm.ShowDialog(this) == DialogResult.OK)
                    {
                        location_ListBox.Items.Add(previewForm.SelectedFile);
                    }
                }
                break;
            }
        }
        /// <summary>
        /// add the driver to the repository
        /// </summary>
        /// <param name="driverDirectory"></param>
        private void AddDiscretePrinterDriver(string driverDirectory)
        {
            //only searching the top level directory for INF files, the discrete driver has lot of INF files in various directory, which is unnecessary to go through.
            if (Directory.GetFiles(driverDirectory, "*.inf", SearchOption.TopDirectoryOnly).Count() == 0)
            {
                MessageBox.Show("The selected directory does not contain any print drivers, please select the directory which has the print driver setup information file (*.inf).", "Print Driver not found",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
            }

            //add the x86 and x64 drivers
            foreach (string fileName in Directory.GetFiles(driverDirectory, "*.inf", SearchOption.TopDirectoryOnly))
            {
                using (DriverInfReader reader = new DriverInfReader(fileName))
                {
                    DriverInfParser parser = new DriverInfParser(reader);
                    DriverInf       inf    = parser.BuildInf();
                    if (inf.DriverClass == "Printer")
                    {
                        string driverName = parser.GetDiscreteDriverName();
                        UploadDiscreteDriver(inf, driverName);
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Import the driver from a pre-installed directory location.
        /// </summary>
        private bool ImportFromFolder()
        {
            string source      = _welcomeControl.PrintDriverPaths.FirstOrDefault();
            string destination = _completionControl.DestinationPaths.FirstOrDefault();

            var path = Path.Combine(PrintDriversManager.DriverRepositoryLocation, destination);

            if (!CheckDestination(path))
            {
                return(false);
            }

            PrintDriverPackage printDriverPackage = null;

            using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
            {
                //add the drivers
                using (DriverInfReader reader = new DriverInfReader(source))
                {
                    DriverInfParser parser     = new DriverInfParser(reader);
                    DriverInf       inf        = parser.BuildInf();
                    string          driverName = parser.GetDiscreteDriverName();

                    //if this is a fax driver, ignore it
                    if (!driverName.Contains("fax", StringComparison.OrdinalIgnoreCase))
                    {
                        printDriverPackage = UpdateRepositoryDatabase(inf, driverName, destination, context);
                        UploadFolder(inf, printDriverPackage);
                    }
                }

                context.SaveChanges();
            }

            return(true);
        }