diff --git a/reactos/base/applications/mscutils/devmgmt_new/DeviceView.cpp b/reactos/base/applications/mscutils/devmgmt_new/DeviceView.cpp index a58593d56d8..0d68c830d76 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/DeviceView.cpp +++ b/reactos/base/applications/mscutils/devmgmt_new/DeviceView.cpp @@ -95,6 +95,8 @@ CDeviceView::Initialize() BOOL CDeviceView::Uninitialize() { + EmptyDeviceView(); + (VOID)m_Devices->Uninitialize(); return TRUE; @@ -186,12 +188,8 @@ unsigned int __stdcall CDeviceView::ListDevicesThread(void *Param) { CDeviceView *This = (CDeviceView *)Param; - /* Check if there are any items in the tree */ - if (TreeView_GetRoot(This->m_hTreeView) != NULL) - { - /* Delete all the items */ - (VOID)TreeView_DeleteAllItems(This->m_hTreeView); - } + /* Clear any existing data */ + This->EmptyDeviceView(); /* Reset the tree root */ This->m_hTreeRoot = NULL; @@ -515,3 +513,66 @@ CDeviceView::InsertIntoTreeView( return TreeView_InsertItem(m_hTreeView, &tvins); } + +VOID +CDeviceView::RecurseDeviceView( + _In_ HTREEITEM hParentItem + ) +{ + HTREEITEM hItem; + TVITEMW tvItem; + + /* Check if this node has any children */ + hItem = TreeView_GetChild(m_hTreeView, hParentItem); + if (hItem == NULL) return; + + /* The lParam contains the device id */ + tvItem.hItem = hItem; + tvItem.mask = TVIF_PARAM; + + if (TreeView_GetItem(m_hTreeView, &tvItem) && + tvItem.lParam != NULL) + { + /* Free the device id */ + HeapFree(GetProcessHeap(), 0, (LPVOID)tvItem.lParam); + } + + /* This node may have its own children */ + RecurseDeviceView(hItem); + + for (;;) + { + /* Get the next item at this level */ + hItem = TreeView_GetNextSibling(m_hTreeView, hItem); + if (hItem == NULL) break; + + tvItem.hItem = hItem; + tvItem.mask = TVIF_PARAM; + + if (TreeView_GetItem(m_hTreeView, &tvItem)) + { + if (tvItem.lParam != NULL) + HeapFree(GetProcessHeap(), 0, (LPVOID)tvItem.lParam); + } + + /* This node may have its own children */ + RecurseDeviceView(hItem); + } +} + + +VOID +CDeviceView::EmptyDeviceView() +{ + HTREEITEM hItem; + + /* Check if there are any items in the tree */ + hItem = TreeView_GetRoot(m_hTreeView); + if (hItem == NULL) return; + + /* Free all the Device Ids */ + RecurseDeviceView(hItem); + + /* Delete all the items */ + (VOID)TreeView_DeleteAllItems(m_hTreeView); +} \ No newline at end of file diff --git a/reactos/base/applications/mscutils/devmgmt_new/DeviceView.h b/reactos/base/applications/mscutils/devmgmt_new/DeviceView.h index e6ca729c56e..c2e3ea2a5a5 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/DeviceView.h +++ b/reactos/base/applications/mscutils/devmgmt_new/DeviceView.h @@ -81,5 +81,12 @@ private: _In_ INT DevImage, _In_ UINT OverlayImage ); + + VOID RecurseDeviceView( + _In_ HTREEITEM hParentItem + ); + + VOID EmptyDeviceView( + ); }; diff --git a/reactos/base/applications/mscutils/devmgmt_new/Devices.cpp b/reactos/base/applications/mscutils/devmgmt_new/Devices.cpp index 8e6e15e8152..42f2cf99c95 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/Devices.cpp +++ b/reactos/base/applications/mscutils/devmgmt_new/Devices.cpp @@ -11,6 +11,9 @@ #include "devmgmt.h" #include "Devices.h" + +/* PUBLIC METHODS *****************************************/ + CDevices::CDevices(void) : m_bInitialized(FALSE), m_RootImageIndex(-1) @@ -133,7 +136,7 @@ CDevices::GetDevice( _In_ DEVINST Device, _Out_writes_(DeviceNameSize) LPWSTR DeviceName, _In_ DWORD DeviceNameSize, - _Out_ LPWSTR *DeviceId, + _Outptr_ LPWSTR *DeviceId, _Out_ PINT ClassImage, _Out_ LPBOOL IsUnknown, _Out_ LPBOOL IsHidden @@ -146,6 +149,7 @@ CDevices::GetDevice( *DeviceId = NULL; + /* Get the length of the device id string */ cr = CM_Get_Device_ID_Size(&ulLength, Device, 0); if (cr == CR_SUCCESS) { @@ -166,6 +170,7 @@ CDevices::GetDevice( } } + /* Make sure we got the string */ if (*DeviceId == NULL) return FALSE; @@ -180,8 +185,10 @@ CDevices::GetDevice( 0); if (cr == CR_SUCCESS) { + /* Convert the string to a proper guid */ CLSIDFromString(ClassGuidString, &ClassGuid); + /* Check if this is a hidden device */ if ((IsEqualGUID(ClassGuid, GUID_DEVCLASS_LEGACYDRIVER) || IsEqualGUID(ClassGuid, GUID_DEVCLASS_VOLUME))) { @@ -195,13 +202,12 @@ CDevices::GetDevice( *IsUnknown = TRUE; } - + /* Get the image for the class this device is in */ SetupDiGetClassImageIndex(&m_ImageListData, &ClassGuid, ClassImage); - - + /* Get the description for the device */ ulLength = DeviceNameSize * sizeof(WCHAR); cr = CM_Get_DevNode_Registry_PropertyW(Device, CM_DRP_FRIENDLYNAME, @@ -221,6 +227,7 @@ CDevices::GetDevice( } + /* Cleanup if something failed */ if (cr != CR_SUCCESS) { HeapFree(GetProcessHeap(), 0, *DeviceId); @@ -346,7 +353,7 @@ CDevices::EnumDevicesForClass( _Out_ LPBOOL MoreItems, _Out_ LPTSTR DeviceName, _In_ DWORD DeviceNameSize, - _Out_ LPTSTR *DeviceId + _Outptr_ LPTSTR *DeviceId ) { SP_DEVINFO_DATA DeviceInfoData; diff --git a/reactos/base/applications/mscutils/devmgmt_new/Devices.h b/reactos/base/applications/mscutils/devmgmt_new/Devices.h index 9cd6988ff76..7a7dc64574a 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/Devices.h +++ b/reactos/base/applications/mscutils/devmgmt_new/Devices.h @@ -42,7 +42,7 @@ public: _In_ DEVINST Device, _Out_writes_(DeviceNameSize) LPTSTR DeviceName, _In_ DWORD DeviceNameSize, - _Out_ LPTSTR *DeviceId, + _Outptr_ LPTSTR *DeviceId, _Out_ PINT ClassImage, _Out_ LPBOOL IsUnknown, _Out_ LPBOOL IsHidden @@ -67,7 +67,7 @@ public: _Out_ LPBOOL MoreItems, _Out_writes_(DeviceNameSize) LPTSTR DeviceName, _In_ DWORD DeviceNameSize, - _Out_ LPTSTR *DeviceId + _Outptr_ LPTSTR *DeviceId ); BOOL GetDeviceStatus( diff --git a/reactos/base/applications/mscutils/devmgmt_new/devmgmt_new.sln b/reactos/base/applications/mscutils/devmgmt_new/devmgmt_new.sln index 4dfdd1bd018..b0138673dae 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/devmgmt_new.sln +++ b/reactos/base/applications/mscutils/devmgmt_new/devmgmt_new.sln @@ -26,7 +26,4 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(Performance) = preSolution - HasPerformanceSessions = true - EndGlobalSection EndGlobal