Leaked source code of windows server 2003
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.

246 lines
5.2 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. CString strPath;
  150. TCHAR InfNameAndPath[_MAX_PATH];
  151. // find windows inf dir
  152. //sprintf(text, _T("%%windir%%\\inf\\%s"), szInfName);
  153. strPath.Format(_T("%%windir%%\\inf\\%s"), szInfName);
  154. ExpandEnvironmentStrings(strPath, InfNameAndPath, _MAX_PATH);
  155. TCHAR text[512];
  156. if (GetPrivateProfileString(_T("Version"), _T("Class"), _T("Unknown"), text, 511, InfNameAndPath))
  157. {
  158. pszClass = new TCHAR[strlen(text) + 1];
  159. strcpy(pszClass, text);
  160. _strupr(pszClass);
  161. }
  162. }
  163. return retval;
  164. }
  165. BOOL Enumerate_WalkTree_Infnode(DEVNODE hDevnode, DEVNODE hParent)
  166. {
  167. CONFIGRET retval;
  168. DevnodeClass *pNewDevice;
  169. DEVNODE hSib;
  170. pNewDevice = new InfnodeClass(hDevnode, hParent);
  171. retval = pNewDevice->GetChild(&hSib);
  172. if ( !retval )
  173. {
  174. Enumerate_WalkTree_Infnode(hSib, hDevnode);
  175. }
  176. retval = pNewDevice->GetSibling(&hSib);
  177. if ( !retval )
  178. {
  179. Enumerate_WalkTree_Infnode(hSib, hParent);
  180. }
  181. return (retval);
  182. }
  183. ULONG EnumerateTree_Infnode(void)
  184. {
  185. DEVNODE hDevnode;
  186. CM_Locate_DevNode(&hDevnode, NULL, CM_LOCATE_DEVNODE_NORMAL);
  187. Enumerate_WalkTree_Infnode(hDevnode, NULL);
  188. return (DevnodeClass::ALCCount());
  189. }