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.

195 lines
5.2 KiB

  1. #include "stdafx.h"
  2. #include "shimgdata.h"
  3. #include "shui.h"
  4. #include "netplace.h"
  5. #include <Ntquery.h>
  6. #include <shellp.h>
  7. #include "pubwiz.h"
  8. #include "gdiplus\gdiplus.h"
  9. #include "imgprop.h"
  10. #pragma hdrstop
  11. // handle the provider list XML document, reading properties etc.
  12. HRESULT GetStrFromElement(IXMLDOMNode *pdn, LPCTSTR pszElementName, LPTSTR pszBuffer, int cch)
  13. {
  14. HRESULT hr;
  15. IXMLDOMNode *pdnElement;
  16. if (pszElementName)
  17. hr = pdn->selectSingleNode((BSTR)pszElementName, &pdnElement);
  18. else
  19. hr = pdn->QueryInterface(IID_PPV_ARG(IXMLDOMNode, &pdnElement));
  20. if (SUCCEEDED(hr) && (hr == S_OK))
  21. {
  22. VARIANT var = {VT_BSTR};
  23. hr = pdnElement->get_nodeTypedValue(&var);
  24. if (SUCCEEDED(hr))
  25. {
  26. VariantToStr(&var, pszBuffer, cch);
  27. VariantClear(&var);
  28. }
  29. pdnElement->Release();
  30. }
  31. return (hr == S_FALSE) ? E_FAIL:hr;
  32. }
  33. HRESULT GetStrFromAttribute(IXMLDOMNode *pdn, LPCTSTR pszAttribute, LPTSTR pszBuffer, int cch)
  34. {
  35. IXMLDOMElement *pdel;
  36. HRESULT hr = pdn->QueryInterface(IID_PPV_ARG(IXMLDOMElement, &pdel));
  37. if (SUCCEEDED(hr))
  38. {
  39. VARIANT var = {VT_BSTR};
  40. hr = pdel->getAttribute((BSTR)pszAttribute, &var);
  41. if (S_OK == hr)
  42. {
  43. VariantToStr(&var, pszBuffer, cch);
  44. VariantClear(&var);
  45. }
  46. pdel->Release();
  47. }
  48. return (hr == S_FALSE) ? E_FAIL:hr;
  49. }
  50. HRESULT GetIntFromAttribute(IXMLDOMNode *pdn, LPCTSTR pszAttribute, int *piValue)
  51. {
  52. TCHAR szBuffer[64];
  53. HRESULT hr = GetStrFromAttribute(pdn, pszAttribute, szBuffer, ARRAYSIZE(szBuffer));
  54. if (SUCCEEDED(hr))
  55. {
  56. hr = StrToIntEx(szBuffer, STIF_SUPPORT_HEX, piValue) ? S_OK:E_FAIL;
  57. }
  58. return hr;
  59. }
  60. HRESULT CreateElement(IXMLDOMDocument *pdoc, LPCTSTR pszName, VARIANT *pvar, IXMLDOMElement **ppdelResult)
  61. {
  62. IXMLDOMElement *pdel;
  63. HRESULT hr = pdoc->createElement((BSTR)pszName, &pdel);
  64. if (SUCCEEDED(hr))
  65. {
  66. VARIANT var;
  67. var.vt = VT_I4;
  68. var.lVal = NODE_TEXT;
  69. IXMLDOMNode *pdnText;
  70. hr = pdoc->createNode(var, NULL, NULL, &pdnText);
  71. if (SUCCEEDED(hr))
  72. {
  73. if (pvar)
  74. hr = pdnText->put_nodeTypedValue(*pvar);
  75. if (SUCCEEDED(hr))
  76. {
  77. IXMLDOMNode *pdn;
  78. hr = pdel->QueryInterface(IID_PPV_ARG(IXMLDOMNode, &pdn));
  79. if (SUCCEEDED(hr))
  80. {
  81. hr = pdn->appendChild(pdnText, NULL);
  82. pdn->Release();
  83. }
  84. }
  85. pdnText->Release();
  86. }
  87. hr = pdel->QueryInterface(IID_PPV_ARG(IXMLDOMElement, ppdelResult));
  88. pdel->Release();
  89. }
  90. return hr;
  91. }
  92. HRESULT CreateAndAppendElement(IXMLDOMDocument *pdoc, IXMLDOMNode *pdnParent, LPCTSTR pszName, VARIANT *pvar, IXMLDOMElement **ppdelOut)
  93. {
  94. IXMLDOMElement *pdel;
  95. HRESULT hr = CreateElement(pdoc, pszName, pvar, &pdel);
  96. if (SUCCEEDED(hr))
  97. {
  98. hr = pdnParent->appendChild(pdel, NULL);
  99. if (SUCCEEDED(hr) && ppdelOut)
  100. {
  101. hr = pdel->QueryInterface(IID_PPV_ARG(IXMLDOMElement, ppdelOut));
  102. }
  103. pdel->Release();
  104. }
  105. return hr;
  106. }
  107. void SpewXML(IUnknown *punk)
  108. {
  109. IXMLDOMNode *pdn;
  110. HRESULT hr = punk->QueryInterface(IID_PPV_ARG(IXMLDOMNode, &pdn));
  111. if (SUCCEEDED(hr))
  112. {
  113. BSTR bstrXML;
  114. hr = pdn->get_xml(&bstrXML);
  115. if (SUCCEEDED(hr))
  116. {
  117. MessageBox(NULL, bstrXML, NULL, MB_OK);
  118. SysFreeString(bstrXML);
  119. }
  120. pdn->Release();
  121. }
  122. }
  123. // this helper is here for compatibility with previous manifest formats, first look for
  124. // a HREF attribute, if its not defined then look for the body text to be the URL.
  125. HRESULT GetURLFromElement(IXMLDOMNode *pdn, LPCTSTR pszElement, LPTSTR pszBuffer, int cch)
  126. {
  127. IXMLDOMNode *pdnElement;
  128. HRESULT hr = pdn->selectSingleNode((BSTR)pszElement, &pdnElement);
  129. if (hr == S_OK)
  130. {
  131. hr = GetStrFromAttribute(pdnElement, L"href", pszBuffer, cch);
  132. pdnElement->Release();
  133. }
  134. if (hr != S_OK)
  135. hr = GetStrFromElement(pdn, pszElement, pszBuffer, cch);
  136. return hr;
  137. }
  138. // set an attribute to a string
  139. HRESULT SetAttributeFromStr(IXMLDOMNode *pdn, LPCTSTR pszAttribute, LPCTSTR pszValue)
  140. {
  141. VARIANT var;
  142. HRESULT hr = InitVariantFromStr(&var, pszValue);
  143. if (SUCCEEDED(hr))
  144. {
  145. IXMLDOMElement *pdel;
  146. hr = pdn->QueryInterface(IID_PPV_ARG(IXMLDOMElement, &pdel));
  147. if (SUCCEEDED(hr))
  148. {
  149. hr = pdel->setAttribute((BSTR)pszAttribute, var);
  150. pdel->Release();
  151. }
  152. VariantClear(&var);
  153. }
  154. return hr;
  155. }
  156. // wrapper for WNetGetConnection to fix drive root case.
  157. DWORD SHWNetGetConnection(LPCTSTR lpLocalName, LPCTSTR lpRemoteName, LPDWORD lpnLength)
  158. {
  159. WCHAR szLocalName[3];
  160. // Kludge allert, don't pass c:\ to API, instead only pass C:
  161. if (lpLocalName && lstrlen(lpLocalName) > 2)
  162. {
  163. szLocalName[0] = lpLocalName[0];
  164. szLocalName[1] = L':';
  165. szLocalName[2] = 0;
  166. lpLocalName = szLocalName;
  167. }
  168. return WNetGetConnection(lpLocalName, (LPWSTR)lpRemoteName, lpnLength);
  169. }