/// <summary> /// Creates a collection of <see cref="DriverDetails" /> for drivers in the specified directory, optionally ignoring subdirectories. /// </summary> /// <param name="path">The path.</param> /// <param name="includeAllArchitectures">if set to <c>true</c> include drivers with architectures other than <see cref="LocalArchitecture" />.</param> /// <param name="searchOption">Specifies whether to search subdirectories for drivers.</param> /// <returns>A collection of <see cref="DriverDetails" /> representing all drivers in the specified directory.</returns> public static IEnumerable <DriverDetails> LoadFromDirectory(string path, bool includeAllArchitectures, SearchOption searchOption) { LogDebug($"Loading drivers from {path}"); List <DriverDetails> drivers = new List <DriverDetails>(); foreach (string fileName in Directory.GetFiles(path, "*.inf", searchOption)) { using (DriverInfReader reader = new DriverInfReader(fileName)) { DriverInfParser parser = new DriverInfParser(reader); DriverInf inf = parser.BuildInf(); if (inf.Drivers.Any()) { if (includeAllArchitectures) { drivers.AddRange(inf.Drivers); } else { drivers.AddRange(inf.Drivers.Where(n => n.Architecture == LocalArchitecture)); } } } } LogDebug($"{drivers.Count} drivers loaded."); return(drivers); }
/// <summary> /// Builds a <see cref="DriverInf" /> object from the specified INF file. /// </summary> /// <returns>A <see cref="DriverInf" /> object.</returns> public DriverInf BuildInf() { DriverInf inf = new DriverInf(_reader.FileLocation); inf.DriverClass = GetClass(); if (inf.DriverClass == "Printer") { foreach (DriverDetails driver in GetAvailableDrivers()) { inf.Drivers.Add(driver); } } return(inf); }