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.

243 lines
4.8 KiB

  1. #include "stdafx.h"
  2. #include <infnode.h>
  3. InfnodeClass::InfnodeClass(void)
  4. {
  5. szInfName = NULL;
  6. szInfProvider = NULL;
  7. szDevLoader = NULL;
  8. szDriverName = NULL;
  9. szDriverDate = NULL;
  10. szDriverDesc = NULL;
  11. szDriverVersion= NULL;
  12. szInfSection = NULL;
  13. }
  14. InfnodeClass::InfnodeClass(DEVNODE hDevice, DEVNODE hParent) : DevnodeClass(hDevice, hParent)
  15. {
  16. szInfName = NULL;
  17. szInfProvider = NULL;
  18. szDevLoader = NULL;
  19. szDriverName = NULL;
  20. szDriverDate = NULL;
  21. szDriverDesc = NULL;
  22. szDriverVersion= NULL;
  23. szInfSection = NULL;
  24. GetInfInformation();
  25. }
  26. InfnodeClass::~InfnodeClass()
  27. {
  28. if (szInfName)
  29. {
  30. delete szInfName;
  31. szInfName = NULL;
  32. }
  33. if (szInfProvider)
  34. {
  35. delete szInfProvider;
  36. szInfProvider = NULL;
  37. }
  38. if (szDevLoader)
  39. {
  40. delete szDevLoader;
  41. szDevLoader = NULL;
  42. }
  43. if (szDriverName)
  44. {
  45. delete szDriverName;
  46. szDriverName = NULL;
  47. }
  48. if (szDriverDate)
  49. {
  50. delete szDriverDate;
  51. szDriverDate = NULL;
  52. }
  53. if (szDriverDesc)
  54. {
  55. delete szDriverDesc;
  56. szDriverDesc = NULL;
  57. }
  58. if (szDriverVersion)
  59. {
  60. delete szDriverVersion;
  61. szDriverVersion = NULL;
  62. }
  63. if (szInfSection)
  64. {
  65. delete szInfSection;
  66. szInfSection = NULL;
  67. }
  68. }
  69. BOOL InfnodeClass::SetHandle(DEVNODE hDevnode, DEVNODE hParent)
  70. {
  71. this->DevnodeClass::SetHandle(hDevnode, hParent);
  72. if (szInfName)
  73. {
  74. delete szInfName;
  75. szInfName = NULL;
  76. }
  77. if (szInfProvider)
  78. {
  79. delete szInfProvider;
  80. szInfProvider = NULL;
  81. }
  82. if (szDevLoader)
  83. {
  84. delete szDevLoader;
  85. szDevLoader = NULL;
  86. }
  87. if (szDriverName)
  88. {
  89. delete szDriverName;
  90. szDriverName = NULL;
  91. }
  92. if (szDriverDate)
  93. {
  94. delete szDriverDate;
  95. szDriverDate = NULL;
  96. }
  97. if (szDriverDesc)
  98. {
  99. delete szDriverDesc;
  100. szDriverDesc = NULL;
  101. }
  102. if (szDriverVersion)
  103. {
  104. delete szDriverVersion;
  105. szDriverVersion = NULL;
  106. }
  107. if (szInfSection)
  108. {
  109. delete szInfSection;
  110. szInfSection = NULL;
  111. }
  112. return GetInfInformation();
  113. }
  114. ULONG InfnodeClass::GetInfInformation(void)
  115. {
  116. if (!hDevnode)
  117. {
  118. return CR_NO_SUCH_DEVNODE;
  119. }
  120. CONFIGRET retval;
  121. HKEY DriverKey;
  122. // open the device key
  123. retval = CM_Open_DevNode_Key(hDevnode,
  124. KEY_READ,
  125. 0, // current Profile
  126. RegDisposition_OpenExisting,
  127. &DriverKey,
  128. CM_REGISTRY_SOFTWARE);
  129. if (retval || !DriverKey || (DriverKey == INVALID_HANDLE_VALUE)) return retval;
  130. // read the szInfName
  131. retval = ReadRegKeyInformationSZ(DriverKey, TEXT("InfPath"), &szInfName );
  132. // read the szInfProvider
  133. retval = ReadRegKeyInformationSZ(DriverKey, TEXT("ProviderName"), &szInfProvider );
  134. // read the szDevLoader
  135. retval = ReadRegKeyInformationSZ(DriverKey, TEXT("DevLoader"), &szDevLoader );
  136. // read the szDriverName
  137. retval = ReadRegKeyInformationSZ(DriverKey, TEXT("Driver"), &szDriverName );
  138. // read the szDriverDate
  139. retval = ReadRegKeyInformationSZ(DriverKey, TEXT("DriverDate"), &szDriverDate );
  140. // read the driver description
  141. retval = ReadRegKeyInformationSZ(DriverKey, TEXT("DriverDesc"), &szDriverDesc );
  142. // read the driver version
  143. retval = ReadRegKeyInformationSZ(DriverKey, TEXT("DriverVersion"), &szDriverVersion );
  144. // read the section name
  145. retval = ReadRegKeyInformationSZ(DriverKey, TEXT("InfSection"), &szInfSection );
  146. if (!pszClass)
  147. {
  148. TCHAR text[512];
  149. TCHAR InfNameAndPath[_MAX_PATH];
  150. // find windows inf dir
  151. sprintf(text, _T("%%windir%%\\inf\\%s"), szInfName);
  152. ExpandEnvironmentStrings(text, InfNameAndPath, _MAX_PATH);
  153. if (GetPrivateProfileString(_T("Version"), _T("Class"), _T("Unknown"), text, 511, InfNameAndPath))
  154. {
  155. pszClass = new TCHAR[strlen(text) + 1];
  156. strcpy(pszClass, text);
  157. _strupr(pszClass);
  158. }
  159. }
  160. return retval;
  161. }
  162. BOOL Enumerate_WalkTree_Infnode(DEVNODE hDevnode, DEVNODE hParent)
  163. {
  164. CONFIGRET retval;
  165. DevnodeClass *pNewDevice;
  166. DEVNODE hSib;
  167. pNewDevice = new InfnodeClass(hDevnode, hParent);
  168. retval = pNewDevice->GetChild(&hSib);
  169. if ( !retval )
  170. {
  171. Enumerate_WalkTree_Infnode(hSib, hDevnode);
  172. }
  173. retval = pNewDevice->GetSibling(&hSib);
  174. if ( !retval )
  175. {
  176. Enumerate_WalkTree_Infnode(hSib, hParent);
  177. }
  178. return (retval);
  179. }
  180. ULONG EnumerateTree_Infnode(void)
  181. {
  182. DEVNODE hDevnode;
  183. CM_Locate_DevNode(&hDevnode, NULL, CM_LOCATE_DEVNODE_NORMAL);
  184. Enumerate_WalkTree_Infnode(hDevnode, NULL);
  185. return (DevnodeClass::ALCCount());
  186. }