예제 #1
0
        private void DownloadFiles()
        {
            if (_downloadUrls.Any())
            {
                KeyValuePair <DellDriverPackage, Uri> data = _downloadUrls.Dequeue();

                DellDriverPackage package = data.Key;
                Uri url = data.Value;

                string filename = Path.GetFileName(url.LocalPath);

                currentDownloadFileName = Path.Combine(registry.ReadString("TempDownloadPath"), filename);
                currentModel            = package.Model;
                currentPackage          = package;

                // check if file already exists and is the same size as the one that will be downloaded
                if (File.Exists(currentDownloadFileName))
                {
                    long fileSize = new FileInfo(currentDownloadFileName).Length;
                    long webSize  = Utility.GetFileSize(url);

                    if (fileSize == webSize)
                    {
                        _extractFiles.Enqueue(new KeyValuePair <DellDriverPackage, string>(package, currentDownloadFileName));

                        CheckDownloadQueueCompleted();

                        return;
                    }
                }

                // enable https downloads
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                webClient = new WebClient();
                webClient.DownloadProgressChanged += Client_DownloadProgressChanged;
                webClient.DownloadFileCompleted   += Client_DownloadFileCompleted;
                webClient.DownloadFileAsync(url, currentDownloadFileName);

                return;
            }
        }
예제 #2
0
        private void ExtractFiles()
        {
            if (_extractFiles.Any())
            {
                KeyValuePair <DellDriverPackage, string> data = _extractFiles.Dequeue();

                // add model so we can re-use it in functions
                DellDriverPackage package = data.Key;
                currentModel = package.Model;

                // update my best friend the progress bar
                backgroundWorker.ReportProgress(Convert.ToInt32(50 + ((40 / totalPacks * extracted) * 0.5)), string.Format("Processing {0} : extracting to temp folder", currentModel));
                // generate model folder name

                // hp sp extract does not work directly to network share, put in temp folder first and than copy to share
                string tempFolder        = Path.Combine(tempFolderPath, "extract", package.FolderName);
                string destinationFolder = Path.Combine(sourceFolderPath, package.FolderName);

                try
                {
                    var cab = new CabInfo(data.Value);
                    cab.Unpack(tempFolder);

                    // update my best friend the progress bar
                    backgroundWorker.ReportProgress(Convert.ToInt32(50 + ((80 / totalPacks * extracted) * 0.5)), string.Format("Processing {0} : moving to destination folder", currentModel));

                    if (!Directory.Exists(tempFolder))
                    {
                        throw new DirectoryNotFoundException("Temp folder not found " + tempFolder);
                    }

                    // add a version file to the folder so we can check later if there is an update to the download
                    string versionFile = Path.Combine(tempFolderPath, "extract", package.FolderName, package.VersionFile);
                    File.Create(versionFile).Close();

                    // wipe old soruce folder
                    if (registry.ReadBool("WipeSource") && Directory.Exists(destinationFolder))
                    {
                        Directory.Delete(destinationFolder, true);
                    }

                    // remove old version file
                    if (Directory.Exists(destinationFolder))
                    {
                        string[] fileList = Directory.GetFiles(destinationFolder, "*.version");
                        foreach (string file in fileList)
                        {
                            File.Delete(file);
                        }
                    }

                    Utility.Copy(tempFolder, destinationFolder, true);

                    Directory.Delete(tempFolder, true);
                }
                catch (Exception ex)
                {
                    error.Add(package.Model, "Cannot extract driver pack: " + ex.Message);

                    CheckExtractQueueCompleted();

                    return;
                }

                successful.Add(currentModel);

                CheckExtractQueueCompleted();

                return;
            }
            // fix if all download fails, dont get stuck in this loop
            else if (_extractFiles.Count == 0)
            {
                extractQueueFinished = true;

                return;
            }
        }
예제 #3
0
        private void ProcessCatalog()
        {
            dataGridViewDriverPackages.Rows.Clear();

            bool   known  = false;
            string prefix = string.IsNullOrEmpty(registry.ReadString("DellFolderPrefix")) ? "Dell" : registry.ReadString("DellFolderPrefix");

            string tempFile = Path.Combine(Path.GetTempPath(), "DriverPackCatalog.cab");

            using (FileStream innerCab = new FileStream(tempFile, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                CabEngine engine = new CabEngine();
                foreach (ArchiveFileInfo archiveFileInfo in engine.GetFileInfo(innerCab))
                {
                    using (Stream stream = engine.Unpack(innerCab, archiveFileInfo.Name))
                    {
                        catalog = XElement.Load(stream);
                        XNamespace ns = catalog.GetDefaultNamespace();
                        // Get download base location from DriverPackCatalog.xml
                        UserData["baseLocation"] = catalog.Attribute("baseLocation").Value;

                        IEnumerable <XElement> nodeList = catalog.Elements(ns + "DriverPackage").Where(
                            x => x.Element(ns + "SupportedOperatingSystems").Elements(ns + "OperatingSystem").Any(
                                y => y.Attribute("osCode").Value == UserData["OS"].ToString().Replace(" ", string.Empty) &&
                                y.Attribute("osArch").Value == UserData["Architecture"].ToString()
                                )
                            );
                        foreach (XElement node in nodeList)
                        {
                            DellDriverPackage package = new DellDriverPackage(node)
                            {
                                Vendor = prefix
                            };
                            package.GenerateModelFolderName(os, structure);

                            DataGridViewRow dataGridViewRow = new DataGridViewRow();
                            dataGridViewRow.CreateCells(dataGridViewDriverPackages);

                            dataGridViewRow.Cells[0].Value = false;
                            dataGridViewRow.Cells[1].Value = package.Model;
                            dataGridViewRow.Cells[2].Value = package.Version;
                            dataGridViewRow.Cells[3].Value = package.Size.ToString();

                            dataGridViewRow.Tag = package;
                            dataGridViewDriverPackages.Rows.Add(dataGridViewRow);
                        }
                    }
                }
            }

            string query = "SELECT DISTINCT Model FROM SMS_G_System_COMPUTER_SYSTEM WHERE Manufacturer = 'Dell Inc.'";
            List <IResultObject> models = Utility.SearchWMIToList(ConnectionManager, query);

            foreach (IResultObject model in models)
            {
                DataGridViewRow row = dataGridViewDriverPackages.Rows
                                      .Cast <DataGridViewRow>()
                                      .Where(r => r.Cells[1].Value.ToString().Equals(model["Model"].StringValue, StringComparison.CurrentCultureIgnoreCase))
                                      .FirstOrDefault();

                if (row != null)
                {
                    row.Cells[0].Value = true;
                    row.Cells[4].Value = "Model detected";
                    known = true;
                }
            }

            foreach (DataGridViewRow dataGridViewRow in dataGridViewDriverPackages.Rows)
            {
                DellDriverPackage package = (DellDriverPackage)dataGridViewRow.Tag;

                string path = Path.Combine(sourceFolderPath, package.FolderName);

                if (Directory.Exists(path))
                {
                    string[] fileList = Directory.GetFiles(path, "*.version");
                    if (File.Exists(Path.Combine(path, package.VersionFile)))
                    {
                        dataGridViewRow.Cells[0].Value = false;
                        dataGridViewRow.Cells[4].Value = "Downloaded";
                    }
                    else if (fileList.Length > 0)
                    {
                        dataGridViewRow.Cells[0].Value = false;
                        dataGridViewRow.Cells[4].Value = "New version";
                    }
                }
            }

            dataGridViewDriverPackages.Sort(known ? columnStatus : columnPack, known ? ListSortDirection.Descending : ListSortDirection.Ascending);

            Initialized = true;
        }