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.

306 lines
11 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1995
  4. * TITLE: LEGACY.CPP
  5. * VERSION: 1.0
  6. * AUTHOR: randyau
  7. * DATE: 9/19/2000
  8. *
  9. ********************************************************************************
  10. *
  11. * CHANGE LOG:
  12. *
  13. * DATE REV DESCRIPTION
  14. * ---------- ------- ----------------------------------------------------------
  15. * 9/19/2000 randyau Original implementation.
  16. *
  17. *******************************************************************************/
  18. #include "UsbPopup.h"
  19. #include "itemfind.h"
  20. #include "debug.h"
  21. #include "usbutil.h"
  22. BOOL
  23. Usb20ControllersOnly (
  24. UsbItem *Item)
  25. {
  26. if (Item->IsController()) {
  27. if (Item->child &&
  28. Item->child->UsbVersion() >= 0x200) {
  29. return TRUE;
  30. }
  31. return FALSE;
  32. }
  33. return TRUE;
  34. }
  35. BOOL
  36. UsbLegacyPopup::Refresh()
  37. {
  38. TV_INSERTSTRUCT item;
  39. int i=0; //, size;
  40. String hubName;
  41. int stage;
  42. TCHAR buf[MAX_PATH];
  43. TCHAR formatString[MAX_PATH];
  44. PUSB_ACQUIRE_INFO acquireInfo = 0;
  45. LPCTSTR deviceName = deviceItem.configInfo->deviceDesc.c_str();
  46. UsbItem *realItem;
  47. //
  48. // Clear all UI components, and then recreate the rootItem
  49. //
  50. UsbTreeView_DeleteAllItems(hTreeDevices);
  51. if (deviceState == DeviceReattached) {
  52. //
  53. // Set the notification using the name of the offending device
  54. //
  55. LoadString(gHInst,
  56. IDS_LEGACY_SOLVED,
  57. formatString,
  58. MAX_PATH);
  59. UsbSprintf(buf, formatString, deviceName);
  60. LoadString(gHInst,
  61. IDS_USB2_DEVICE_IN_USB1_HUB,
  62. formatString,
  63. MAX_PATH);
  64. MessageBox(hWnd, buf, formatString, MB_OK);
  65. EndDialog(hWnd, 0);
  66. return TRUE;
  67. }
  68. //
  69. // Set the notification using the name of the offending device
  70. //
  71. LoadString(gHInst,
  72. IDS_LEGACY_NOTIFICATION,
  73. formatString,
  74. MAX_PATH);
  75. UsbSprintf(buf, formatString, deviceName);
  76. if (!SetTextItem(hWnd, IDC_LEGACY_NOTIFICATION, buf)) {
  77. goto LegacyRefreshError;
  78. }
  79. for (stage=0; stage < 2; stage++) {
  80. //
  81. // Recreate the rootItem for each enumeration attempt
  82. //
  83. if (rootItem) {
  84. DeleteChunk(rootItem);
  85. delete rootItem;
  86. }
  87. realItem = rootItem = new UsbItem;
  88. if (!realItem) {
  89. USBERROR((_T("Out of memory!\n")));
  90. goto LegacyRefreshError;
  91. }
  92. AddChunk(rootItem);
  93. if (stage == 0) {
  94. acquireInfo = GetControllerName(WmiHandle,
  95. InstanceName.c_str());
  96. if (!acquireInfo) {
  97. goto LegacyRefreshError;
  98. }
  99. if (!rootItem->EnumerateController(0,
  100. acquireInfo->Buffer,
  101. &ImageList,
  102. 0)) {
  103. goto LegacyRefreshError;
  104. }
  105. //
  106. // Usability: Rename the "Root Hub" to "My Computer" and change the
  107. // USB "shovel" icon to a computer icon.
  108. //
  109. LoadString(gHInst,
  110. IDS_MY_COMPUTER,
  111. buf,
  112. MAX_PATH);
  113. rootItem->child->configInfo->deviceDesc = buf;
  114. wsprintf(buf, _T(" (%d ports)"), rootItem->child->NumPorts());
  115. rootItem->child->configInfo->deviceDesc += buf;
  116. ImageList.GetClassImageIndex(MyComputerClass,
  117. &rootItem->child->imageIndex);
  118. acquireInfo = (PUSB_ACQUIRE_INFO) LocalFree(acquireInfo);
  119. } else {
  120. if (!rootItem->EnumerateAll(&ImageList)) {
  121. goto LegacyRefreshError;
  122. }
  123. if (rootItem->NumChildren() == 1) {
  124. realItem = rootItem->child;
  125. break;
  126. }
  127. }
  128. if (rootItem->child) {
  129. //
  130. // Find all usb 2.0 hubs with free ports.
  131. //
  132. USBTRACE((_T("Looking for free ports on usb 2.0 hubs\n")));
  133. UsbItemActionFindUsb2xHubsWithFreePorts find1(rootItem);
  134. rootItem->Walk(find1);
  135. UsbItemList& devices1 = find1.GetHubs();
  136. if (!devices1.empty()) {
  137. USBTRACE((_T("Found free ports on usb 2.0 hubs\n")));
  138. return AssembleDialog(rootItem->child,
  139. &item,
  140. deviceName,
  141. IDS_FREE_USB2_PORTS,
  142. IDS_FREE_USB2_PORTS_RECOMMENDATION,
  143. Usb20ControllersOnly,
  144. UsbItemActionFindUsb2xHubsWithFreePorts::IsValid,
  145. UsbItemActionFindUsb2xHubsWithFreePorts::IsExpanded);
  146. }
  147. USBTRACE((_T("Didn't find free ports on usb 2.0 hubs\n")));
  148. //
  149. // Find all usb 2.0 hubs that have usb 1.0 devices attached.
  150. // These devices can be switched with the offending device.
  151. //
  152. USBTRACE((_T("Looking for usb 1.0 devices on usb 2.0 hubs\n")));
  153. UsbItemActionFindUsb1xDevicesOnUsb2xHubs find2(rootItem);
  154. rootItem->Walk(find2);
  155. UsbItemList& devices2 = find2.GetDevices();
  156. if (!devices2.empty()) {
  157. USBTRACE((_T("Found usb 1.0 devices on usb 2.0 hubs\n")));
  158. return AssembleDialog(rootItem->child,
  159. &item,
  160. deviceName,
  161. IDS_USB1_DEVICE_IN_USB2_HUB,
  162. IDS_USB1_DEVICE_IN_USB2_HUB_RECOMMENDATION,
  163. Usb20ControllersOnly,
  164. UsbItemActionFindUsb1xDevicesOnUsb2xHubs::IsValid,
  165. UsbItemActionFindUsb1xDevicesOnUsb2xHubs::IsExpanded);
  166. }
  167. USBTRACE((_T("Didn't find usb 1.0 devices on usb 2.0 hubs\n")));
  168. }
  169. }
  170. {
  171. //
  172. // Check to see if there are ANY usb 2.0 hubs on the machine
  173. //
  174. USBTRACE((_T("Looking for ANY usb 2.0 ports\n")));
  175. UsbItemActionFindUsb2xHubs find1(realItem);
  176. realItem->Walk(find1);
  177. UsbItemList& devices = find1.GetHubs();
  178. if(devices.empty()) {
  179. USBTRACE((_T("There aren't any usb 2.0 ports on this machine\n")));
  180. return AssembleDialog(realItem->child,
  181. &item,
  182. deviceName,
  183. IDS_NO_USB2_HUBS,
  184. IDS_NO_USB2_HUBS_RECOMMENDATION,
  185. TrueAlways,
  186. UsbItemActionFindUsb2xHubs::IsValid,
  187. UsbItemActionFindUsb2xHubs::IsExpanded);
  188. } else {
  189. //
  190. // Find all unknown devices attached to usb 2.0 hubs.
  191. // These devices can be switched with the offending device.
  192. //
  193. USBTRACE((_T("Looking for unknown devices attached to usb 2.0 hubs\n")));
  194. UsbItemActionFindUnknownDevicesOnUsb2xHubs find2(realItem);
  195. realItem->Walk(find2);
  196. UsbItemList& devices2 = find2.GetDevices();
  197. if (!devices2.empty()) {
  198. USBTRACE((_T("Found unknown devices attached to usb 2.0 hubs\n")));
  199. return AssembleDialog(realItem->child,
  200. &item,
  201. deviceName,
  202. IDS_UNKNOWN_DEVICE_IN_USB2_HUB,
  203. IDS_UNKNOWN_DEVICE_IN_USB2_HUB_RECOMMENDATION,
  204. Usb20ControllersOnly,
  205. UsbItemActionFindUnknownDevicesOnUsb2xHubs::IsValid,
  206. UsbItemActionFindUnknownDevicesOnUsb2xHubs::IsExpanded);
  207. } else {
  208. USBTRACE((_T("Didn't find unknown devices on usb 2.0 hubs\n")));
  209. //
  210. // Last resort here. Highlight usb 2.0 hubs and tell the user
  211. // to put it there if they want the device to work.
  212. //
  213. USBTRACE((_T("Last resort. Highlight usb 2.0 hubs\n")));
  214. return AssembleDialog(realItem->child,
  215. &item,
  216. deviceName,
  217. IDS_USB2_DEVICE_IN_USB2_HUB,
  218. IDS_USB2_DEVICE_IN_USB2_HUB_RECOMMENDATION,
  219. Usb20ControllersOnly,
  220. UsbItemActionFindUsb2xHubs::IsValid,
  221. UsbItemActionFindUsb2xHubs::IsValid);
  222. }
  223. }
  224. }
  225. USBTRACE((_T("Didn't find usb 2.0 devices on usb 2.0 hubs\n")));
  226. return TRUE;
  227. LegacyRefreshError:
  228. USBTRACE((_T("LegacyRefreshError\n")));
  229. if (acquireInfo) {
  230. LocalFree(acquireInfo);
  231. }
  232. return FALSE;
  233. }
  234. BOOL
  235. UsbLegacyPopup::AssembleDialog(UsbItem* RootItem,
  236. LPTV_INSERTSTRUCT LvItem,
  237. LPCTSTR DeviceName,
  238. UINT Explanation,
  239. UINT Recommendation,
  240. PUsbItemActionIsValid IsValid,
  241. PUsbItemActionIsValid IsBold,
  242. PUsbItemActionIsValid IsExpanded)
  243. {
  244. HTREEITEM hDevice;
  245. TCHAR buf[MAX_PATH], formatString[MAX_PATH];
  246. LoadString(gHInst,
  247. Recommendation,
  248. formatString,
  249. MAX_PATH);
  250. UsbSprintf(buf, formatString, DeviceName);
  251. if (!SetTextItem(hWnd, IDC_LEGACY_RECOMMENDATION, buf) ||
  252. !SetTextItem(hWnd, IDC_LEGACY_EXPLANATION, Explanation)) {
  253. return FALSE;
  254. }
  255. if (!InsertTreeItem(hTreeDevices,
  256. RootItem,
  257. NULL,
  258. LvItem,
  259. IsValid,
  260. IsBold,
  261. IsExpanded)) {
  262. return FALSE;
  263. }
  264. if (NULL != (hDevice = TreeView_FindItem(hTreeDevices,
  265. DeviceName))) {
  266. return TreeView_SelectItem (hTreeDevices, hDevice);
  267. }
  268. return TRUE;
  269. }
  270. USBINT_PTR
  271. UsbLegacyPopup::OnTimer()
  272. {
  273. if (deviceState == DeviceAttachedError) {
  274. if (S_FALSE == QueryContinue()) {
  275. // Update the device state
  276. deviceState = DeviceDetachedError;
  277. }
  278. }
  279. return 0;
  280. }