private bool ProcessCatalog() { string tempFile = Path.Combine(Path.GetTempPath(), "HPClientDriverPackCatalog.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)) { XElement catalog = XElement.Load(stream); comboBoxOS.Items.Clear(); List <XElement> nodeList = catalog.Element("HPClientDriverPackCatalog").Element("OSList").Elements("OS").ToList(); foreach (XElement node in nodeList) { string os = node.Element("Name").Value; comboBoxOS.Items.Add(os); comboBoxOS.SelectedIndex = 0; } } } } return(true); }
/// <summary> /// Prepares to extract a MS Cabinet archive contained in a stream. /// </summary> /// <param name="stream">The stream containing the archive data to be extracted. Will be disposed when the extractor is disposed.</param> /// <param name="targetPath">The path to the directory to extract into.</param> /// <exception cref="IOException">The archive is damaged.</exception> internal CabExtractor(Stream stream, string targetPath) : base(targetPath) { CabStream = stream ?? throw new ArgumentNullException(nameof(stream)); try { UnitsTotal = CabEngine.GetFileInfo(this, _ => true).Sum(x => x.Length); } #region Error handling catch (CabException ex) { // Wrap exception since only certain exception types are allowed throw new IOException(Resources.ArchiveInvalid, ex); } #endregion }
/// <summary> /// Prepares to extract a MS Cabinet archive contained in a stream. /// </summary> /// <param name="stream">The stream containing the archive data to be extracted. Will be disposed when the extractor is disposed.</param> /// <param name="target">The path to the directory to extract into.</param> /// <exception cref="IOException">The archive is damaged.</exception> internal CabExtractor([NotNull] Stream stream, [NotNull] string target) : base(target) { #region Sanity checks if (stream == null) { throw new ArgumentNullException("stream"); } #endregion CabStream = stream; try { UnitsTotal = CabEngine.GetFileInfo(this, _ => true).Sum(x => x.Length); } #region Error handling catch (CabException ex) { // Wrap exception since only certain exception types are allowed throw new IOException(Resources.ArchiveInvalid, ex); } #endregion }
private void ProcessCatalog() { dataGridViewDriverPackages.Rows.Clear(); bool known = false; string prefix = string.IsNullOrEmpty(registry.ReadString("HPFolderPrefix")) ? "HP" : registry.ReadString("HPFolderPrefix"); string tempFile = Path.Combine(Path.GetTempPath(), "HPClientDriverPackCatalog.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); IEnumerable <XElement> nodeList = catalog.Element("HPClientDriverPackCatalog").Element("ProductOSDriverPackList").Elements("ProductOSDriverPack").Where( x => x.Element("OSName").Value == UserData["OS"].ToString() ); foreach (XElement node in nodeList) { HPDriverPackage package = new HPDriverPackage(node) { SoftPaq = catalog.Element("HPClientDriverPackCatalog").Element("SoftPaqList").Elements("SoftPaq").Where( x => x.Element("Id").Value == node.Element("SoftPaqId").Value ).FirstOrDefault(), Vendor = prefix }; package.ProcessSoftPaq(); 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.VersionShort; dataGridViewRow.Cells[3].Value = package.Size.ToString(); dataGridViewRow.Tag = package; dataGridViewDriverPackages.Rows.Add(dataGridViewRow); } } } } // TODO: will implement when I have an HP device to test with //string query = "SELECT DISTINCT Model FROM SMS_G_System_COMPUTER_SYSTEM WHERE Manufacturer = 'HP' OR Manufacturer = 'Hewlett-Packard'"; //List<IResultObject> models = Utility.SearchWMIToList(ConnectionManager, query); //foreach (IResultObject model in models) //{ // string testModel = model["Model"].StringValue; // testModel = Regex.Replace(testModel, "HP", "", RegexOptions.IgnoreCase); // testModel = Regex.Replace(testModel, "COMPAQ", "", RegexOptions.IgnoreCase); // testModel = Regex.Replace(testModel, "SFF", "Small Form Factor"); // testModel = Regex.Replace(testModel, "USDT", "Desktop"); // testModel = Regex.Replace(testModel, " TWR", " Tower"); // testModel = testModel.TrimEnd("PC").Trim(); // DataGridViewRow row = dataGridViewDriverPackages.Rows // .Cast<DataGridViewRow>() // .Where(r => r.Cells[1].Value.ToString().Equals(testModel, 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) { HPDriverPackage package = (HPDriverPackage)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; }
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; }