From c4f18c639218fa212f72e6222aec7a4ef7d4e195 Mon Sep 17 00:00:00 2001 From: X9VoiD Date: Wed, 1 Nov 2023 01:09:57 +0800 Subject: [PATCH 1/2] feat: add support for uninstalling inf immediately after device uninstallation/removal --- src/cleanup_modules/device_cleanup.rs | 18 +++++++- src/cleanup_modules/driver_cleanup.rs | 66 +++++++++++++++------------ 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/cleanup_modules/device_cleanup.rs b/src/cleanup_modules/device_cleanup.rs index cb986c0..5303a76 100644 --- a/src/cleanup_modules/device_cleanup.rs +++ b/src/cleanup_modules/device_cleanup.rs @@ -133,6 +133,22 @@ impl ModuleStrategy for DeviceCleanupModule { run_info.reboot_required = true; } + if to_uninstall.uninstall_inf.unwrap_or(false) { + let inf_path = Path::new(object.driver_store_location().unwrap()) + .join(object.inf_original_name().unwrap()); + let driver_uninstall = super::driver_cleanup::DriverToUninstall { + friendly_name: object.friendly_name().unwrap().to_string(), + original_name: None, + provider: None, + class: None + }; + + super::driver_cleanup::uninstall_driver(&inf_path, &driver_uninstall, run_info) + .attach_printable_lazy(|| { + format!("failed to uninstall driver for device {}", object.instance_id()) + })? + } + Ok(()) } } @@ -181,13 +197,13 @@ impl Dumper for DeviceDumper { } #[derive(Deserialize, Debug)] -#[serde(deny_unknown_fields)] pub struct DeviceToUninstall { friendly_name: String, device_desc: Option, manufacturer: Option, hardware_id: Option, class_uuid: Option, + uninstall_inf: Option } impl ToUninstall for DeviceToUninstall { diff --git a/src/cleanup_modules/driver_cleanup.rs b/src/cleanup_modules/driver_cleanup.rs index a184a38..6589398 100644 --- a/src/cleanup_modules/driver_cleanup.rs +++ b/src/cleanup_modules/driver_cleanup.rs @@ -85,36 +85,43 @@ impl ModuleStrategy for DriverCleanupModule { ) -> Result<(), UninstallError> { let inf_path = Path::new(object.driver_store_location().unwrap()) .join(object.inf_original_name().unwrap()); + uninstall_driver(&inf_path, to_uninstall, run_info) + } - unsafe { - let mut reboot: BOOL = false.into(); - if !DiUninstallDriverW( - None, - &HSTRING::from(inf_path.as_path()), - 0, - Some(&mut reboot), - ) - .as_bool() - { - let err = windows::core::Error::from_win32(); - return Err(err) - .into_report() - .attach_printable_lazy(|| { - format!("failed to uninstall inf: {}", inf_path.display()) - }) - .into_uninstall_report(to_uninstall); - } + fn get_dumper(&self) -> Option<&dyn Dumper> { + Some(&self.driver_dumper) + } +} - if reboot.as_bool() { - run_info.reboot_required = true; - } +pub(crate) fn uninstall_driver( + inf_path: &Path, + to_uninstall: &DriverToUninstall, + run_info: &mut ModuleRunInfo, +) -> Result<(), UninstallError> { + unsafe { + let mut reboot: BOOL = false.into(); + if !DiUninstallDriverW( + None, + &HSTRING::from(inf_path), + 0, + Some(&mut reboot), + ) + .as_bool() + { + let err = windows::core::Error::from_win32(); + return Err(err) + .into_report() + .attach_printable_lazy(|| { + format!("failed to uninstall inf: {}", inf_path.display()) + }) + .into_uninstall_report(to_uninstall); + } - Ok(()) + if reboot.as_bool() { + run_info.reboot_required = true; } - } - fn get_dumper(&self) -> Option<&dyn Dumper> { - Some(&self.driver_dumper) + Ok(()) } } @@ -155,12 +162,11 @@ impl Dumper for DriverDumper { } #[derive(Deserialize, Debug)] -#[serde(deny_unknown_fields)] pub struct DriverToUninstall { - friendly_name: String, - original_name: Option, - provider: Option, - class: Option, + pub friendly_name: String, + pub original_name: Option, + pub provider: Option, + pub class: Option, } impl ToUninstall for DriverToUninstall { From fa3dd7d9c826fb51e5d5d2956049cb89941209a8 Mon Sep 17 00:00:00 2001 From: X9VoiD Date: Wed, 1 Nov 2023 01:14:49 +0800 Subject: [PATCH 2/2] feat: uninstall Wacom LibUsbK device first --- config/device_identifiers.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/device_identifiers.json b/config/device_identifiers.json index b7399b5..3f67a8d 100644 --- a/config/device_identifiers.json +++ b/config/device_identifiers.json @@ -11,6 +11,13 @@ "hardware_id": "pentablet\\\\hid", "class_uuid": "745a17a0-74d3-11d0-b6fe-00a0c90f57da" }, + { + "friendly_name": "Wacom LibusbK Device", + "device_desc": ".*\\(Interface[ _]\\d+\\)", + "manufacturer": "Wacom", + "class_uuid": "ecfb0cfd-74c4-4f52-bbf7-343461cd72ac", + "uninstall_inf": true + }, { "friendly_name": "Wacom Driver Downloader", "device_desc": "Wacom Driver Downloader",