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.

467 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C F U T I L S . C P P
  7. //
  8. // Contents: Various utility functions for the connections folder
  9. //
  10. // Notes:
  11. //
  12. // Author: jeffspr 20 Jan 1998
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "foldinc.h" // Standard shell\folder includes
  18. #include "nsres.h" // Netshell strings
  19. #include "cfutils.h" // Connection folder utility functions
  20. VOID MapNCMToResourceId(
  21. NETCON_MEDIATYPE nct,
  22. DWORD dwCharacteristics,
  23. INT * piStringRes)
  24. {
  25. Assert(piStringRes);
  26. if (dwCharacteristics & NCCF_BRANDED)
  27. {
  28. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_CONMAN;
  29. }
  30. else
  31. if (dwCharacteristics & NCCF_INCOMING_ONLY)
  32. {
  33. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_INBOUND;
  34. }
  35. else
  36. {
  37. switch(nct)
  38. {
  39. case NCM_NONE:
  40. Assert(dwCharacteristics & NCCF_INCOMING_ONLY);
  41. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_INBOUND;
  42. break;
  43. case NCM_DIRECT:
  44. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_DIRECT;
  45. break;
  46. case NCM_ISDN:
  47. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_PHONE;
  48. break;
  49. case NCM_LAN:
  50. if(dwCharacteristics & NCCF_BRIDGED)
  51. {
  52. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_BRIDGE;
  53. }
  54. else
  55. {
  56. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_LAN;
  57. }
  58. break;
  59. case NCM_PHONE:
  60. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_PHONE;
  61. break;
  62. case NCM_TUNNEL:
  63. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_TUNNEL;
  64. break;
  65. case NCM_BRIDGE:
  66. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_BRIDGE;
  67. break;
  68. case NCM_SHAREDACCESSHOST_LAN:
  69. case NCM_SHAREDACCESSHOST_RAS:
  70. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_SHAREDACCESSHOST;
  71. break;
  72. case NCM_PPPOE:
  73. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_PPPOE;
  74. break;
  75. default:
  76. AssertSz(FALSE, "Marfa -- I can't find my teef! (You may ignore.)");
  77. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_UNKNOWN;
  78. break;
  79. }
  80. }
  81. }
  82. VOID MapNCSToComplexStatus(
  83. NETCON_STATUS ncs,
  84. NETCON_MEDIATYPE ncm,
  85. NETCON_SUBMEDIATYPE ncsm,
  86. DWORD dwCharacteristics,
  87. LPWSTR pszString,
  88. DWORD cString,
  89. GUID gdDevice)
  90. {
  91. Assert(cString >= CONFOLD_MAX_STATUS_LENGTH);
  92. *pszString = L'\0';
  93. PCWSTR szArgs[4] = {L"", L"", L"", L""};
  94. DWORD dwArg = 0;
  95. WCHAR szTmpString[MAX_PATH];
  96. INT iStringRes = 0;
  97. if ((NCM_NONE == ncm) && (dwCharacteristics & NCCF_INCOMING_ONLY) )
  98. {
  99. DWORD dwIncomingCount;
  100. HRESULT hr = g_ccl.HasActiveIncomingConnections(&dwIncomingCount);
  101. if (SUCCEEDED(hr) && dwIncomingCount)
  102. {
  103. if (1 == dwIncomingCount)
  104. {
  105. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_INCOMING_ONE);
  106. }
  107. else
  108. {
  109. if (DwFormatString(SzLoadIds(IDS_CONFOLD_STATUS_INCOMING_MULTI), szTmpString, MAX_PATH, dwIncomingCount))
  110. {
  111. szArgs[dwArg++] = szTmpString;
  112. }
  113. }
  114. }
  115. else
  116. {
  117. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_INCOMING_NONE);
  118. }
  119. }
  120. else
  121. {
  122. MapNCSToStatusResourceId(ncs, ncm, ncsm, dwCharacteristics, &iStringRes, gdDevice);
  123. }
  124. if (iStringRes)
  125. {
  126. szArgs[dwArg++] = SzLoadIds(iStringRes);
  127. }
  128. if (ncs == NCS_DISCONNECTED || fIsConnectedStatus(ncs))
  129. {
  130. if(NCCF_BRIDGED & dwCharacteristics)
  131. {
  132. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_BRIDGED);
  133. }
  134. if(NCCF_SHARED & dwCharacteristics)
  135. {
  136. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_SHARED);
  137. }
  138. if(NCCF_FIREWALLED & dwCharacteristics)
  139. {
  140. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_FIREWALLED);
  141. }
  142. }
  143. if(0 == FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, L"%1%2%3%4", 0, 0, pszString, cString, (va_list*) &szArgs))
  144. {
  145. *pszString = L'\0'; // on error return empty
  146. }
  147. }
  148. VOID MapNCSToStatusResourceId(
  149. NETCON_STATUS ncs,
  150. NETCON_MEDIATYPE ncm,
  151. NETCON_SUBMEDIATYPE ncsm,
  152. DWORD dwCharacteristics,
  153. INT * piStringRes,
  154. GUID gdDevice)
  155. {
  156. Assert(piStringRes);
  157. switch(ncs)
  158. {
  159. case NCS_DISCONNECTED:
  160. if (IsMediaLocalType(ncm) || NCM_SHAREDACCESSHOST_LAN == ncm)
  161. {
  162. *piStringRes = IDS_CONFOLD_STATUS_DISABLED;
  163. }
  164. else
  165. {
  166. *piStringRes = IDS_CONFOLD_STATUS_DISCONNECTED;
  167. }
  168. break;
  169. case NCS_CONNECTING:
  170. if (IsMediaLocalType(ncm) || NCM_SHAREDACCESSHOST_LAN == ncm)
  171. *piStringRes = IDS_CONFOLD_STATUS_ENABLING;
  172. else
  173. *piStringRes = IDS_CONFOLD_STATUS_CONNECTING;
  174. break;
  175. case NCS_CONNECTED:
  176. if (IsMediaLocalType(ncm) || NCM_SHAREDACCESSHOST_LAN == ncm)
  177. {
  178. *piStringRes = IDS_CONFOLD_STATUS_ENABLED;
  179. }
  180. else
  181. {
  182. *piStringRes = IDS_CONFOLD_STATUS_CONNECTED;
  183. }
  184. break;
  185. case NCS_DISCONNECTING:
  186. if (IsMediaLocalType(ncm) || NCM_SHAREDACCESSHOST_LAN == ncm)
  187. *piStringRes = IDS_CONFOLD_STATUS_DISABLING;
  188. else
  189. *piStringRes = IDS_CONFOLD_STATUS_DISCONNECTING;
  190. break;
  191. case NCS_HARDWARE_NOT_PRESENT:
  192. *piStringRes = IDS_CONFOLD_STATUS_HARDWARE_NOT_PRESENT;
  193. break;
  194. case NCS_HARDWARE_DISABLED:
  195. *piStringRes = IDS_CONFOLD_STATUS_HARDWARE_DISABLED;
  196. break;
  197. case NCS_HARDWARE_MALFUNCTION:
  198. *piStringRes = IDS_CONFOLD_STATUS_HARDWARE_MALFUNCTION;
  199. break;
  200. case NCS_MEDIA_DISCONNECTED:
  201. if ( (ncm == NCM_LAN) && (ncsm == NCSM_WIRELESS) )
  202. {
  203. *piStringRes = IDS_CONFOLD_STATUS_WIRELESS_DISCONNECTED;
  204. }
  205. else
  206. {
  207. *piStringRes = IDS_CONFOLD_STATUS_MEDIA_DISCONNECTED;
  208. }
  209. break;
  210. case NCS_INVALID_ADDRESS:
  211. *piStringRes = IDS_CONFOLD_STATUS_INVALID_ADDRESS;
  212. break;
  213. case NCS_AUTHENTICATION_FAILED:
  214. *piStringRes = IDS_CONFOLD_STATUS_AUTHENTICATION_FAILED;
  215. break;
  216. case NCS_AUTHENTICATING:
  217. *piStringRes = IDS_CONFOLD_STATUS_AUTHENTICATING;
  218. break;
  219. case NCS_AUTHENTICATION_SUCCEEDED:
  220. *piStringRes = IDS_CONFOLD_STATUS_AUTHENTICATION_SUCCEEDED;
  221. break;
  222. case NCS_CREDENTIALS_REQUIRED:
  223. *piStringRes = IDS_CONFOLD_STATUS_CREDENTIALS_REQUIRED;
  224. break;
  225. default:
  226. AssertSz(FALSE, "Unknown status in MapNCSToStatusResourceId");
  227. *piStringRes = IDS_CONFOLD_STATUS_DISCONNECTED;
  228. break;
  229. }
  230. }
  231. DWORD MapRSSIToWirelessSignalStrength(int iRSSI)
  232. {
  233. if (iRSSI < -90)
  234. {
  235. return 0;
  236. }
  237. if (iRSSI < -81)
  238. {
  239. return 1;
  240. }
  241. if (iRSSI < -71)
  242. {
  243. return 2;
  244. }
  245. if (iRSSI < -67)
  246. {
  247. return 3;
  248. }
  249. if (iRSSI < -57)
  250. {
  251. return 4;
  252. }
  253. return 5;
  254. }
  255. PCWSTR PszGetRSSIString(INT iRSSI)
  256. {
  257. DWORD wss = MapRSSIToWirelessSignalStrength(iRSSI);
  258. Assert(wss <= (IDS_802_11_LEVEL5 - IDS_802_11_LEVEL0) );
  259. return SzLoadIds(IDS_802_11_LEVEL0 + wss);
  260. }
  261. //+---------------------------------------------------------------------------
  262. //
  263. // Function: PszGetOwnerStringFromCharacteristics
  264. //
  265. // Purpose: Get the owner string from the CONFOLDENTRY. This will
  266. // return the string for "System" if the connection is for
  267. // all users, and will return the particular user if
  268. // appropriate
  269. //
  270. // Arguments:
  271. // pcfe [in] The ConFoldEntry for this connection
  272. //
  273. // Returns: The string for the user name
  274. //
  275. // Author: jeffspr 20 Jan 1998
  276. //
  277. // Notes:
  278. //
  279. PCWSTR PszGetOwnerStringFromCharacteristics(PCWSTR pszUserName, DWORD dwCharacteristics)
  280. {
  281. PCWSTR pszOwner = NULL;
  282. BOOL fAllUsers = (dwCharacteristics & NCCF_ALL_USERS) > 0;
  283. // If they both have the same user type, then they're equal
  284. //
  285. if (fAllUsers)
  286. {
  287. pszOwner = SzLoadIds(IDS_CONFOLD_DETAILS_OWNER_SYSTEM);
  288. }
  289. else
  290. {
  291. pszOwner = pszUserName;
  292. }
  293. return pszOwner;
  294. }
  295. BOOL IsMediaLocalType(NETCON_MEDIATYPE ncm)
  296. {
  297. return (ncm == NCM_LAN || ncm == NCM_BRIDGE);
  298. }
  299. BOOL IsMediaRASType(NETCON_MEDIATYPE ncm)
  300. {
  301. return (ncm == NCM_DIRECT || ncm == NCM_ISDN || ncm == NCM_PHONE || ncm == NCM_TUNNEL || ncm == NCM_PPPOE);// REVIEW DIRECT correct?
  302. }
  303. BOOL IsMediaSharedAccessHostType(NETCON_MEDIATYPE ncm)
  304. {
  305. return (ncm == NCM_SHAREDACCESSHOST_LAN || ncm == NCM_SHAREDACCESSHOST_RAS);
  306. }
  307. //+---------------------------------------------------------------------------
  308. //
  309. // Function Name: ImageList_LoadImageAndMirror
  310. //
  311. // Purpose: This function creates an image list from the specified bitmap or icon resource.
  312. //
  313. // Arguments:
  314. // hi [in] Handle to the instance of an application or DLL that contains an image.
  315. // lpbmp [in] Long pointer to the image to load.
  316. // If the uFlags parameter includes LR_LOADFROMFILE, lpbmp is the address
  317. // of a null-terminated string that names the file containing the image to load.
  318. //
  319. // If the hi parameter is non-NULL and LR_LOADFROMFILE is not specified, lpbmp is the
  320. // address of a null-terminated string that contains the name of the image resource in the hi module.
  321. //
  322. // If hi is NULL and LR_LOADFROMFILE is not specified, the low-order word of this
  323. // parameter must be the identifier of an OEM image to load. To create this value, use the
  324. // MAKEINTRESOURCE macro with one of the OEM image identifiers defined in Winuser.h.
  325. // These identifiers have the following prefixes:
  326. // OBM_ for OEM bitmaps
  327. // OIC_ for OEM icons
  328. //
  329. // cx [in] Width of each image. The height of each image and the initial number of images are inferred
  330. // by the dimensions of the specified resource.
  331. // cGrow [in] Number of images by which the image list can grow when the system needs to make room for new
  332. // images. This parameter represents the number of new images that the resized image list can contain.
  333. // crMask [in] Color used to generate a mask. Each pixel of this color in the specified bitmap or icon is changed to
  334. // black, and the corresponding bit in the mask is set to 1. If this parameter is the CLR_NONE value,
  335. // no mask is generated. If this parameter is the CLR_DEFAULT value, the color of the pixel at the
  336. // upper-left corner of the image is treated as the mask color.
  337. // uType [in] Flag that specifies the type of image to load. This parameter can be one of the following values:
  338. // IMAGE_BITMAP Loads a bitmap.
  339. // IMAGE_ICON Loads an icon.
  340. // uFlags [in] Unsupported; set to 0.
  341. //
  342. // Returns:
  343. // The handle to the image list indicates success. NULL indicates failure.
  344. //
  345. // Author: deonb 8 Feb 2001
  346. //
  347. // Notes:
  348. // This is an exact duplication of the implementation of shell's ImageList_LoadImage function EXCEPT for the
  349. // fact that we set ILC_MIRROR in order to create the second, mirrored image list which will be used
  350. // by RTL languages
  351. //
  352. HIMAGELIST WINAPI ImageList_LoadImageAndMirror(
  353. HINSTANCE hi,
  354. LPCTSTR lpbmp,
  355. int cx,
  356. int cGrow,
  357. COLORREF crMask,
  358. UINT uType,
  359. UINT uFlags)
  360. {
  361. HBITMAP hbmImage;
  362. HIMAGELIST piml = NULL;
  363. BITMAP bm;
  364. int cy, cInitial;
  365. UINT flags;
  366. hbmImage = (HBITMAP)LoadImage(hi, lpbmp, uType, 0, 0, uFlags);
  367. if (hbmImage && (sizeof(bm) == GetObject(hbmImage, sizeof(bm), &bm)))
  368. {
  369. // If cx is not stated assume it is the same as cy.
  370. // ASSERT(cx);
  371. cy = bm.bmHeight;
  372. if (cx == 0)
  373. cx = cy;
  374. cInitial = bm.bmWidth / cx;
  375. flags = 0;
  376. if (crMask != CLR_NONE)
  377. flags |= ILC_MASK;
  378. if (bm.bmBits)
  379. flags |= (bm.bmBitsPixel & ILC_COLORMASK);
  380. flags |= ILC_MIRROR;
  381. piml = ImageList_Create(cx, cy, flags, cInitial, cGrow);
  382. if (piml)
  383. {
  384. int added;
  385. if (crMask == CLR_NONE)
  386. added = ImageList_Add(piml, hbmImage, NULL);
  387. else
  388. added = ImageList_AddMasked(piml, hbmImage, crMask);
  389. if (added < 0)
  390. {
  391. ImageList_Destroy(piml);
  392. piml = NULL;
  393. }
  394. }
  395. }
  396. if (hbmImage)
  397. DeleteObject(hbmImage);
  398. return reinterpret_cast<HIMAGELIST>(piml);
  399. }