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.

247 lines
6.7 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "file.h"
  4. #include "ncsetup.h"
  5. //+---------------------------------------------------------------------------
  6. //
  7. // Parse the specified INF section which corresponds to a component's
  8. // defintion. Return the upper-range and lower-range that the component
  9. // can bind over.
  10. // e.g. a section like:
  11. // [Tcpip]
  12. // UpperRange = "tdi"
  13. // LowerRange = "ndis5,ndis4,ndisatm,ndiswanip,ndis5_ip"
  14. //
  15. // Arguments:
  16. // inf [in]
  17. // pszSection [in]
  18. // pstrUpperRange [out]
  19. // pstrLowerRange [out]
  20. //
  21. // Returns: S_OK or an error code.
  22. //
  23. // Author: shaunco 25 Oct 1998
  24. //
  25. // Notes:
  26. //
  27. HRESULT
  28. HrParseComponentSection (
  29. IN HINF inf,
  30. IN PCWSTR pszSection,
  31. OUT tstring* pstrUpperRange,
  32. OUT tstring* pstrLowerRange)
  33. {
  34. HRESULT hr;
  35. // Initialize the output parameters.
  36. //
  37. pstrUpperRange->erase();
  38. pstrLowerRange->erase();
  39. // Get the UpperRange string. It is a set of comma-separated sub-strings.
  40. //
  41. hr = HrSetupGetFirstString (
  42. inf,
  43. pszSection,
  44. L"UpperRange",
  45. pstrUpperRange);
  46. if (S_OK == hr)
  47. {
  48. if (0 == _wcsicmp (L"noupper", pstrUpperRange->c_str()))
  49. {
  50. pstrUpperRange->erase();
  51. }
  52. }
  53. else if (SPAPI_E_LINE_NOT_FOUND != hr)
  54. {
  55. goto finished;
  56. }
  57. // Get the LowerRange string. It is a set of comma-separated sub-strings.
  58. //
  59. hr = HrSetupGetFirstString (
  60. inf,
  61. pszSection,
  62. L"LowerRange",
  63. pstrLowerRange);
  64. if (S_OK == hr)
  65. {
  66. if (0 == _wcsicmp (L"nolower", pstrLowerRange->c_str()))
  67. {
  68. pstrLowerRange->erase();
  69. }
  70. }
  71. else if (SPAPI_E_LINE_NOT_FOUND == hr)
  72. {
  73. hr = S_OK;
  74. }
  75. finished:
  76. TraceHr (ttidError, FAL, hr, FALSE, "HrParseComponentSection");
  77. return hr;
  78. }
  79. //+---------------------------------------------------------------------------
  80. //
  81. // Initialize a CNetConfig instance by reading information from an
  82. // INF-style file.
  83. //
  84. // Arguments:
  85. // pszFilepath [in]
  86. // pNetConfig [out]
  87. //
  88. // Returns: S_OK or an error code.
  89. //
  90. // Author: shaunco 25 Oct 1998
  91. //
  92. // Notes:
  93. //
  94. HRESULT
  95. HrLoadNetworkConfigurationFromFile (
  96. IN PCTSTR pszFilepath,
  97. OUT CNetConfig* pNetConfig)
  98. {
  99. CSetupInfFile inf;
  100. UINT unErrorLine;
  101. HRESULT hr;
  102. INFCONTEXT ctx;
  103. // Open the answer file. It will close itself in it's destructor.
  104. //
  105. hr = inf.HrOpen (
  106. pszFilepath, NULL,
  107. INF_STYLE_OLDNT | INF_STYLE_WIN4,
  108. &unErrorLine);
  109. if (S_OK == hr)
  110. {
  111. tstring strInfId;
  112. tstring strPnpId;
  113. tstring strUpperRange;
  114. tstring strLowerRange;
  115. BASIC_COMPONENT_DATA Data;
  116. CComponent* pComponent;
  117. // Find the [Components] section. This is a list of all of
  118. // the components involved.
  119. //
  120. hr = HrSetupFindFirstLine (inf.Hinf(),
  121. L"Components",
  122. NULL,
  123. &ctx);
  124. // Process each line in this section by creating a CComponent instance
  125. // for it and inserting it into the list of components owned by
  126. // the CNetConfig instance we are initializing.
  127. //
  128. while (S_OK == hr)
  129. {
  130. ZeroMemory (&Data, sizeof(Data));
  131. // Get each string field into a local variable and create
  132. // a new CComponent instance if all succeed.
  133. //
  134. //hr = HrSetupGetStringField (ctx, 0, &strInstanceId);
  135. //if (S_OK != hr) goto finished;
  136. CoCreateGuid(&Data.InstanceGuid);
  137. hr = HrSetupGetStringField (ctx, 1, &strInfId);
  138. if (S_OK != hr) goto finished;
  139. Data.pszInfId = strInfId.c_str();
  140. hr = HrSetupGetIntField (ctx, 2, (INT*)&Data.Class);
  141. if (S_OK != hr) goto finished;
  142. hr = HrSetupGetIntField (ctx, 3, (INT*)&Data.dwCharacter);
  143. if (S_OK != hr) goto finished;
  144. hr = HrSetupGetStringField (ctx, 4, &strPnpId);
  145. if (S_OK != hr) goto finished;
  146. Data.pszPnpId = strPnpId.c_str();
  147. hr = HrParseComponentSection (inf.Hinf(), strInfId.c_str(),
  148. &strUpperRange, &strLowerRange);
  149. if (S_OK != hr) goto finished;
  150. //Data.pszUpperRange = strUpperRange.c_str();
  151. //Data.pszLowerRange = strLowerRange.c_str();
  152. hr = CComponent::HrCreateInstance(
  153. &Data,
  154. CCI_DEFAULT,
  155. NULL,
  156. &pComponent);
  157. if (S_OK == hr)
  158. {
  159. hr = pNetConfig->Core.Components.HrInsertComponent (
  160. pComponent, INS_NON_SORTED);
  161. }
  162. // S_FALSE returned if there is no next line.
  163. //
  164. hr = HrSetupFindNextMatchLine (ctx, NULL, &ctx);
  165. }
  166. }
  167. if (SUCCEEDED(hr))
  168. {
  169. CComponentList* pComponents = &pNetConfig->Core.Components;
  170. ULONG ulUpperIndex;
  171. ULONG ulLowerIndex;
  172. CStackEntry StackEntry;
  173. // Find the [StackTable] section. This is a list of how the
  174. // components are "stacked" on each other.
  175. //
  176. hr = HrSetupFindFirstLine (inf.Hinf(),
  177. L"StackTable",
  178. NULL,
  179. &ctx);
  180. // Process each line in this section by initialzing a CStackEntry
  181. // structure and inserting a copy of it into the stack table
  182. // maintained by the CNetConfig instance we are initializing.
  183. //
  184. while (S_OK == hr)
  185. {
  186. hr = HrSetupGetIntField (ctx, 0, (INT*)&ulUpperIndex);
  187. if (S_OK != hr) goto finished;
  188. hr = HrSetupGetIntField (ctx, 1, (INT*)&ulLowerIndex);
  189. if (S_OK != hr) goto finished;
  190. StackEntry.pUpper = pComponents->PGetComponentAtIndex (
  191. ulUpperIndex);
  192. StackEntry.pLower = pComponents->PGetComponentAtIndex (
  193. ulLowerIndex);
  194. hr = pNetConfig->Core.StackTable.HrInsertStackEntry (
  195. &StackEntry, INS_SORTED);
  196. if (S_OK != hr) goto finished;
  197. // S_FALSE returned if there is no next line.
  198. //
  199. hr = HrSetupFindNextMatchLine (ctx, NULL, &ctx);
  200. }
  201. }
  202. if (S_FALSE == hr)
  203. {
  204. hr = S_OK;
  205. }
  206. if (S_OK == hr)
  207. {
  208. pNetConfig->Core.DbgVerifyData();
  209. }
  210. finished:
  211. TraceHr (ttidError, FAL, hr, FALSE, "HrLoadNetworkConfigurationFromFile");
  212. return hr;
  213. }