/// <summary> /// Print files from the store /// </summary> /// <param name="options">Print options, including filters</param> public void PrintFiles(QueryMetadataOptions options) { if (!string.IsNullOrEmpty(options.FileHash)) { var hashBytes = new byte[options.FileHash.Length / 2]; for (var i = 0; i < hashBytes.Length; i++) { hashBytes[i] = System.Convert.ToByte(options.FileHash.Substring(i * 2, 2), 16); } var hashBase64 = Convert.ToBase64String(hashBytes); if (!MetadataSource.HasFile(hashBase64)) { ConsoleOutput.WriteRed($"Cannot find file hash {options.FileHash}"); } var file = MetadataSource.GetFile(hashBase64); foreach (var update in MetadataSource.UpdatesIndex.Values) { if (update.HasFiles) { foreach (var updateFile in update.Files) { if (updateFile.Digests.Any(d => d.HexString.Equals(options.FileHash, StringComparison.OrdinalIgnoreCase))) { PrintUpdateMetadata(update, MetadataSource); break; } } } } } else if (options.IdFilter.Count() > 0) { var idFilter = FilterBuilder.StringGuidsToGuids(options.IdFilter); if (idFilter == null) { ConsoleOutput.WriteRed("The update ID filter must contain only GUIDs!"); return; } var update = MetadataSource.UpdatesIndex.Values.FirstOrDefault(u => u.Identity.ID.Equals(idFilter[0])); if (update == null) { ConsoleOutput.WriteRed($"Cannot find update with GUID {idFilter[0]}"); return; } var files = GetAllUpdateFiles(MetadataSource, update); PrintFileDetails(files); } }
public static void MatchDrivers(MatchDriverOptions options) { using (var source = Program.LoadMetadataSourceFromOptions(options as IMetadataSourceOptions)) { if (source == null) { return; } List <Guid> computerHardwareIds = FilterBuilder.StringGuidsToGuids(options.ComputerHardwareIds); if (computerHardwareIds == null) { ConsoleOutput.WriteRed($"The computer hardware ID must be a GUID"); return; } var prerequisites = FilterBuilder.StringGuidsToGuids(options.InstalledPrerequisites); if (prerequisites == null) { ConsoleOutput.WriteRed($"Prerequisites must be a list of GUIDs separated by '+'"); return; } var driverMatch = source.MatchDriver(options.HardwareIds, computerHardwareIds, prerequisites); if (driverMatch != null) { ConsoleOutput.WriteGreen("Matching result:"); Console.WriteLine($" Matched hardware id : {driverMatch.MatchedHardwareId}"); Console.WriteLine($" Driver version : [Date {driverMatch.MatchedVersion.Date} Version {driverMatch.MatchedVersion.VersionString}]"); if (driverMatch.MatchedComputerHardwareId.HasValue) { Console.WriteLine($" Matched computer hardware ID : {driverMatch.MatchedComputerHardwareId.Value}"); } if (driverMatch.MatchedFeatureScore != null) { Console.WriteLine($" Driver feature score : [OS {driverMatch.MatchedFeatureScore.OperatingSystem}, Score {driverMatch.MatchedFeatureScore.Score}]"); } PrintUpdateMetadata(driverMatch.Driver, source); } else { ConsoleOutput.WriteRed("No match found"); } } }