public bool DeleteDriver(DriverStoreEntry driverStoreEntry, bool forceDelete) { if (driverStoreEntry == null) { throw new ArgumentNullException(nameof(driverStoreEntry)); } switch (this.Type) { case DriverStoreType.Online: try { SetupAPI.DeleteDriver(driverStoreEntry, forceDelete); } catch (Win32Exception ex) { Trace.TraceError(ex.ToString()); return(false); } return(true); case DriverStoreType.Offline: throw new NotImplementedException(); default: throw new NotSupportedException(); } }
public bool DeleteDriver(DriverStoreEntry driverStoreEntry, bool forceDelete) { if (driverStoreEntry == null) { throw new ArgumentNullException(nameof(driverStoreEntry)); } switch (this.Type) { case DriverStoreType.Online: return(SetupAPI.DeleteDriver(driverStoreEntry, forceDelete)); case DriverStoreType.Offline: DismApi.Initialize(DismLogLevel.LogErrors); try { using (DismSession session = this.GetSession()) { DismApi.RemoveDriver(session, driverStoreEntry.DriverPublishedName); } } finally { DismApi.Shutdown(); } return(true); default: throw new NotSupportedException(); } }
public bool AddDriver(string infFullPath, bool install) { switch (this.Type) { case DriverStoreType.Online: return(SetupAPI.AddDriver(infFullPath, install)); case DriverStoreType.Offline: DismApi.Initialize(DismLogLevel.LogErrors); try { using (DismSession session = this.GetSession()) { DismApi.AddDriver(session, infFullPath, false); } } finally { DismApi.Shutdown(); } return(true); default: throw new NotSupportedException(); } }
public bool DeleteDriver(DriverStoreEntry driverStoreEntry, bool forceDelete) { if (driverStoreEntry == null) { throw new ArgumentNullException(nameof(driverStoreEntry)); } switch (this.Type) { case DriverStoreType.Online: try { SetupAPI.DeleteDriver(driverStoreEntry, forceDelete); } catch (Win32Exception ex) { Trace.TraceError(ex.ToString()); return(false); } return(true); case DriverStoreType.Offline: try { DismApi.Initialize(DismLogLevel.LogErrors); try { using (DismSession session = this.GetSession()) { DismApi.RemoveDriver(session, driverStoreEntry.DriverPublishedName); } } finally { DismApi.Shutdown(); } } catch (DismRebootRequiredException) { return(true); } catch (DismException ex) { Trace.TraceError(ex.ToString()); return(false); } return(true); default: throw new NotSupportedException(); } }
public bool AddDriver(string infFullPath, bool install) { switch (this.Type) { case DriverStoreType.Online: try { SetupAPI.AddDriver(infFullPath, install); } catch (Win32Exception ex) { Trace.TraceError(ex.ToString()); return(false); } return(true); case DriverStoreType.Offline: try { DismApi.Initialize(DismLogLevel.LogErrors); try { using (DismSession session = this.GetSession()) { DismApi.AddDriver(session, infFullPath, false); } } finally { DismApi.Shutdown(); } } catch (DismRebootRequiredException) { return(true); } catch (DismException ex) { Trace.TraceError(ex.ToString()); return(false); } return(true); default: throw new NotSupportedException(); } }
public bool AddDriver(string infFullPath, bool install) { switch (this.Type) { case DriverStoreType.Online: try { SetupAPI.AddDriver(infFullPath, install); } catch (Win32Exception ex) { Trace.TraceError(ex.ToString()); return(false); } return(true); case DriverStoreType.Offline: throw new NotImplementedException(); default: throw new NotSupportedException(); } }
public List <DriverStoreEntry> EnumeratePackages() { List <DriverStoreEntry> driverStoreEntries = new List <DriverStoreEntry>(); DismApi.Initialize(DismLogLevel.LogErrors); try { using (DismSession session = this.GetSession()) { List <DeviceDriverInfo> driverInfo = this.Type == DriverStoreType.Online ? ConfigManager.GetDeviceDriverInfo() : null; foreach (var driverPackage in DismApi.GetDrivers(session, false)) { DriverStoreEntry driverStoreEntry = new DriverStoreEntry { DriverClass = driverPackage.ClassDescription, DriverInfName = Path.GetFileName(driverPackage.OriginalFileName), DriverPublishedName = driverPackage.PublishedName, DriverPkgProvider = driverPackage.ProviderName, DriverSignerName = driverPackage.DriverSignature == DismDriverSignature.Signed ? SetupAPI.GetDriverSignerInfo(driverPackage.OriginalFileName) : string.Empty, DriverDate = driverPackage.Date, DriverVersion = driverPackage.Version, DriverFolderLocation = Path.GetDirectoryName(driverPackage.OriginalFileName), DriverSize = DriverStoreRepository.GetFolderSize(new DirectoryInfo(Path.GetDirectoryName(driverPackage.OriginalFileName))), BootCritical = driverPackage.BootCritical, }; var deviceInfo = driverInfo?.OrderByDescending(d => d.IsPresent)?.FirstOrDefault(e => string.Equals(Path.GetFileName(e.DriverInf), driverStoreEntry.DriverPublishedName, StringComparison.OrdinalIgnoreCase) && e.DriverVersion == driverStoreEntry.DriverVersion && e.DriverDate == driverStoreEntry.DriverDate); driverStoreEntry.DeviceName = deviceInfo?.DeviceName; driverStoreEntry.DevicePresent = deviceInfo?.IsPresent; driverStoreEntries.Add(driverStoreEntry); } } } finally { DismApi.Shutdown(); } return(driverStoreEntries); }