Repository navigation
Add Remove Ghost Devices action - #514
Open
PrimeBuild-pc wants to merge 2 commits into
Open
PrimeBuild-pc wants to merge 2 commits into
PrimeBuild-pc wants to merge 2 commits into
Conversation
Lists non-present devices (CfgMgr32, CM_Get_DevNode_Status returning CR_NO_SUCH_DEVNODE) in a checkbox dialog and uninstalls the selected ones with CM_Uninstall_DevNode. Presence is checked again right before removal, software-enumerated devices (ROOT, SWD, HTREE, SW, UMB, GUID buses) are not pre-selected, and the action is disabled for offline driver stores. The driver list is refreshed afterwards so packages left unused show up. Refs lostindark#345
There was a problem hiding this comment.
🟡 Changes recommended
The tests do not exercise the removal workflow, leaving the last-moment presence guard against uninstalling reconnected devices and uninstall failure handling unverified.
1 open issue
What changed in this PR
Adds built-in ghost-device cleanup to complement driver-package management, addressing #345 without requiring a separate cleanup tool.
Changes:
- Adds an online-only File > Remove Ghost Devices action with device selection, confirmation, and result reporting.
- Rechecks device presence before removal and refreshes the driver list afterward.
- Adds resource strings and tests for ghost classification and default-selection rules.
| File | Description |
|---|---|
RaprTests/Utils/GhostDeviceTests.cs |
Tests ghost classification and software-device selection exclusions. |
Rapr/Utils/GhostDevice.cs |
Defines ghost-device metadata and selection rules. |
Rapr/Utils/ConfigManager.cs |
Adds ghost enumeration and presence-checked native removal. |
Rapr/Lang/Language.resx |
Adds English menu, dialog, confirmation, and status strings. |
Rapr/GhostDevicesForm.cs |
Adds the checkbox-based device-selection dialog. |
Rapr/DSEForm.cs |
Integrates the menu action, operation controls, and post-removal refresh. |
Review effort: Balanced
| if (result == ConfigManagerResult.Success) | ||
| { | ||
| // Check again: the device may have been connected since the scan. | ||
| if (!GhostDevice.IsGhost(IsDevicePresent(devInst))) |
Author
There was a problem hiding this comment.
Done in 8873bbb. TryRemoveGhostDevice now takes the locate, status and uninstall calls as delegates (same pattern as GetDeviceIds / ReadDevNodeProperty). New data-driven test covers: absent device is uninstalled; uninstall failure returns false; present, unknown status, and locate failures never call uninstall.
TryRemoveGhostDevice now takes the locate, status and uninstall calls as delegates, like GetDeviceIds and ReadDevNodeProperty, so tests can check that present, unknown or unlocatable devices are never uninstalled and that uninstall failures are reported.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Refs #345
I know you pointed to Uwe Sieber's Device Cleanup Tool in that issue, and it is a good tool. I still put together a small built-in version because people looking at unused packages in DSE are usually the same people who want to clear the stale devices that keep those packages "in use", and doing both in one place saves a separate download. If you'd rather not take it, no problem at all.
What it does
File > Remove Ghost Devices... scans for non-present devices, shows them in a dialog with checkboxes (device, class, instance ID), and uninstalls the checked ones. Afterwards the driver list is refreshed, so packages that only served the removed devices show up as unused.
Implementation
ConfigManager: same device ID enumeration,CM_Locate_DevNode(PHANTOM)andCM_Get_DevNode_Status. A device counts as a ghost only when the status call returnsCR_NO_SUCH_DEVNODE; any other error is treated as present.CM_Uninstall_DevNode(one new P/Invoke). No pnputil, no new NuGet package.GhostDevicesFormis built in code, like the details pane and the newer menu items, since its strings have no generatedLanguageproperties yet. New strings are only in the neutralLanguage.resx.Safety
ROOT\,SWD\,HTREE\,SW\,UMB\,{GUID}\buses) are listed but not checked by default.Testing
dotnet test: 204 passed, including new tests for the ghost / pre-selection rules.Get-PnpDevice | ? { -not $_.Present }.Get-PnpDevice); removing the 83 pre-selected ones succeeded 83/83, they no longer appear, the present device count stayed 63/63, and a call on a present device was refused and left it untouched. The VM was then reverted to its checkpoint.