Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.2 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1995
  4. * TITLE: ENUMFAIL.CPP
  5. * VERSION: 1.0
  6. * AUTHOR: jsenior
  7. * DATE: 10/28/1998
  8. *
  9. ********************************************************************************
  10. *
  11. * CHANGE LOG:
  12. *
  13. * DATE REV DESCRIPTION
  14. * ---------- ------- ----------------------------------------------------------
  15. * 10/28/1998 jsenior Original implementation.
  16. *
  17. *******************************************************************************/
  18. #include "usbpopup.h"
  19. #include "itemfind.h"
  20. #include "debug.h"
  21. #include "usbutil.h"
  22. //
  23. // Refresh the contents of the treeview control.
  24. // Find all hubs with unused ports on them. If there are none, find some which
  25. // have devices requiring less than 100 mA.
  26. //
  27. BOOL UsbEnumFailPopup::Refresh()
  28. {
  29. TV_INSERTSTRUCT item;
  30. int i=0; //, size;
  31. PUSB_ACQUIRE_INFO acquireInfoController = 0;
  32. BOOL result = FALSE;
  33. TCHAR buf[MAX_PATH];
  34. String hubName = HubAcquireInfo->Buffer;
  35. //
  36. // Set the window's title bar and the rest of the messages
  37. //
  38. LoadString(gHInst, IDS_ENUMERATION_FAILURE, buf, MAX_PATH);
  39. SetWindowText(hWnd, buf);
  40. if (!SetTextItem(hWnd, IDC_POWER_NOTIFICATION, IDS_ENUMFAIL_NOTIFICATION) ||
  41. !SetTextItem(hWnd, IDC_POWER_EXPLANATION, IDS_ENUMFAIL_COURSE) ||
  42. !SetTextItem(hWnd, IDC_POWER_RECOMMENDATION, IDS_ENUMFAIL_RECOMMENDATION)) {
  43. goto OvercurrentRefreshError;
  44. }
  45. //
  46. // Clear all UI components, and then recreate the rootItem
  47. //
  48. UsbTreeView_DeleteAllItems(hTreeDevices);
  49. if (rootItem) {
  50. DeleteChunk(rootItem);
  51. delete rootItem;
  52. }
  53. rootItem = new UsbItem;
  54. AddChunk(rootItem);
  55. //
  56. // Get the controller name and enumerate the tree
  57. //
  58. acquireInfoController = GetControllerName(WmiHandle,
  59. InstanceName);
  60. if (!acquireInfoController) {
  61. goto OvercurrentRefreshError;
  62. }
  63. if (!rootItem->EnumerateController(0,
  64. acquireInfoController->Buffer,
  65. &ImageList,
  66. 0)) {
  67. goto OvercurrentRefreshError;
  68. }
  69. acquireInfoController =
  70. (PUSB_ACQUIRE_INFO) LocalFree(acquireInfoController);
  71. if (rootItem->child) {
  72. if (!deviceItem.configInfo->devInst) {
  73. //
  74. // Device has been removed by either the hub or the user. Find the
  75. // hub that the device was attached to and highlight the port.
  76. //
  77. UsbItemActionFindOvercurrentHubPort f2(hubName, deviceItem.cxnAttributes.ConnectionIndex);
  78. rootItem->Walk(f2);
  79. if (f2.GetDevice()) {
  80. result=InsertTreeItem (hTreeDevices,
  81. rootItem->child,
  82. TreeView_GetRoot(hTreeDevices),
  83. &item,
  84. TrueAlways,
  85. UsbItemActionFindOvercurrentHubPort::IsValid,
  86. UsbItemActionFindOvercurrentHubPort::IsExpanded);
  87. }
  88. } else {
  89. //
  90. // The device hasn't been removed by either the hub or the user yet
  91. // Find the overcurrent device
  92. //
  93. UsbItemActionFindOvercurrentDevice f1(deviceItem.configInfo->devInst);
  94. rootItem->Walk(f1);
  95. if (f1.GetDevice()) {
  96. //
  97. // Device is still attached
  98. //
  99. result=InsertTreeItem (hTreeDevices,
  100. rootItem->child,
  101. TreeView_GetRoot(hTreeDevices),
  102. &item,
  103. TrueAlways,
  104. UsbItemActionFindOvercurrentDevice::IsValid,
  105. UsbItemActionFindOvercurrentDevice::IsExpanded);
  106. }
  107. }
  108. }
  109. return result;
  110. OvercurrentRefreshError:
  111. if (acquireInfoController) {
  112. LocalFree(acquireInfoController);
  113. }
  114. return FALSE;
  115. }