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.

414 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. hwdatgen.c
  5. Abstract:
  6. This module creates a tool that generates hwcomp.dat and is designed for us by
  7. the NT build lab. It simply calls the code in hwcomp.lib, the same code that
  8. the Win9x upgrade uses to determine incompatibilities.
  9. Author:
  10. Jim Schmidt (jimschm) 12-Oct-1996
  11. Revision History:
  12. <alias> <date> <comments>
  13. --*/
  14. #include "pch.h"
  15. #ifdef UNICODE
  16. #error UNICODE not allowed
  17. #endif
  18. #define MAX_SOURCE_DIRS 10
  19. BOOL CancelFlag = FALSE;
  20. BOOL *g_CancelFlagPtr = &CancelFlag;
  21. #ifdef PRERELEASE
  22. BOOL g_Stress;
  23. #endif
  24. #ifdef DEBUG
  25. extern BOOL g_DoLog;
  26. #endif
  27. HANDLE g_hHeap;
  28. HINSTANCE g_hInst;
  29. CHAR g_TempDirBuf[MAX_MBCHAR_PATH]; // location for hwcomp.dat
  30. CHAR g_TempDirWackBuf[MAX_MBCHAR_PATH];
  31. PSTR g_TempDir;
  32. PSTR g_TempDirWack;
  33. INT g_TempDirWackChars;
  34. PSTR g_WinDir;
  35. CHAR g_WinDirBuf[MAX_MBCHAR_PATH];
  36. PCSTR g_SourceDirectories[MAX_SOURCE_COUNT]; // location of INFs
  37. DWORD g_SourceDirectoryCount;
  38. USEROPTIONS g_ConfigOptions;
  39. BOOL
  40. WINAPI
  41. MigUtil_Entry (
  42. HINSTANCE hinstDLL,
  43. DWORD fdwReason,
  44. LPVOID lpvReserved
  45. );
  46. VOID
  47. pInitProgBarVars (
  48. VOID
  49. );
  50. VOID
  51. HelpAndExit (
  52. VOID
  53. )
  54. {
  55. printf ("Command line syntax:\n\n"
  56. "hwdatgen [-i:<infdir>] [-o:<outputfile>] [-c] [-v]\n\n"
  57. "Optional Arguments:\n"
  58. " -i:<infdir> - Specifies input directory containing INF files.\n"
  59. " If -i is not specified, the default is %_NTTREE%\n"
  60. " -o:<outputfile> - Specifies path and file name of DAT file. By\n"
  61. " default, this file is %_NTTREE%\\hwcomp.dat\n"
  62. " -c - Clean build (deletes <outputfile>)\n"
  63. " -v - Verbose output\n"
  64. "\n"
  65. "A maximum of %u input directories can be specified.\n"
  66. "\n",
  67. MAX_SOURCE_DIRS
  68. );
  69. exit(255);
  70. }
  71. INT
  72. __cdecl
  73. main (
  74. INT argc,
  75. CHAR *argv[]
  76. )
  77. {
  78. CHAR NtTree[MAX_MBCHAR_PATH];
  79. CHAR InputPathBuf[MAX_SOURCE_DIRS][MAX_MBCHAR_PATH];
  80. UINT SourceDirs = 0;
  81. CHAR OutputFileBuf[MAX_MBCHAR_PATH];
  82. PSTR OutputFile;
  83. PSTR p;
  84. INT i;
  85. LONG rc;
  86. INT UIMode;
  87. BOOL CleanBuild;
  88. DWORD d; // for debugging only
  89. UINT u;
  90. DWORD Attribs;
  91. //
  92. // Get environment variables
  93. //
  94. p = getenv ("_NTx86TREE");
  95. if (!p || !(*p)) {
  96. p = getenv ("_NTTREE");
  97. }
  98. if (p && *p) {
  99. StringCopyA (NtTree, p);
  100. } else {
  101. StringCopyA (NtTree, ".");
  102. }
  103. //
  104. // Set defaults
  105. //
  106. g_TempDir = g_TempDirBuf;
  107. g_TempDirWack = g_TempDirWackBuf;
  108. g_WinDir = g_WinDirBuf;
  109. StringCopyA (OutputFileBuf, NtTree);
  110. AppendPathWack (OutputFileBuf);
  111. StringCatA (OutputFileBuf, "hwcomp.dat");
  112. OutputFile = OutputFileBuf;
  113. StringCopyA (InputPathBuf[0], NtTree);
  114. UIMode = REGULAR_OUTPUT;
  115. CleanBuild = FALSE;
  116. ZeroMemory (&g_ConfigOptions, sizeof (g_ConfigOptions));
  117. //
  118. // Parse command line
  119. //
  120. for (i = 1 ; i < argc ; i++) {
  121. if (argv[i][0] == '-' || argv[i][0] == '/') {
  122. switch (tolower (argv[i][1])) {
  123. case 'i':
  124. if (SourceDirs == MAX_SOURCE_DIRS) {
  125. HelpAndExit();
  126. }
  127. if (argv[i][2] == ':') {
  128. StringCopyA (InputPathBuf[SourceDirs], &argv[i][3]);
  129. } else if (i + 1 < argc) {
  130. i++;
  131. StringCopyA (InputPathBuf[SourceDirs], argv[i]);
  132. } else {
  133. HelpAndExit();
  134. }
  135. Attribs = GetFileAttributes (InputPathBuf[SourceDirs]);
  136. if (Attribs == INVALID_ATTRIBUTES || !(Attribs & FILE_ATTRIBUTE_DIRECTORY)) {
  137. HelpAndExit();
  138. }
  139. SourceDirs++;
  140. break;
  141. case 'o':
  142. if (argv[i][2] == ':') {
  143. OutputFile = &argv[i][3];
  144. } else if (i + 1 < argc) {
  145. i++;
  146. OutputFile = argv[i];
  147. } else {
  148. HelpAndExit();
  149. }
  150. break;
  151. case 'c':
  152. CleanBuild = TRUE;
  153. break;
  154. case 'v':
  155. UIMode = VERBOSE_OUTPUT;
  156. break;
  157. default:
  158. HelpAndExit();
  159. }
  160. } else {
  161. HelpAndExit();
  162. }
  163. }
  164. if (SourceDirs == 0) {
  165. SourceDirs = 1;
  166. }
  167. printf ("Building database of all NT-supported PNP IDs... Please wait.\n\n");
  168. g_SourceDirectoryCount = SourceDirs;
  169. for (u = 0 ; u < SourceDirs ; u++) {
  170. g_SourceDirectories[u] = InputPathBuf[u];
  171. if (!u) {
  172. printf ("Input path%s ", SourceDirs == 1 ? ": " : "s:");
  173. } else {
  174. printf (" ");
  175. }
  176. printf ("%s\n", g_SourceDirectories[u]);
  177. }
  178. //
  179. // Init hwcomp.lib
  180. //
  181. pInitProgBarVars();
  182. g_hHeap = GetProcessHeap();
  183. g_hInst = GetModuleHandle (NULL);
  184. GetTempPathA (MAX_MBCHAR_PATH, g_TempDir);
  185. StringCopyA (g_TempDirWack, g_TempDir);
  186. AppendWack (g_TempDirWack);
  187. g_TempDirWackChars = CharCountA (g_TempDirWack);
  188. if (!GetWindowsDirectoryA (g_WinDir, MAX_MBCHAR_PATH)) {
  189. printf ("Memory allocation failure!\n");
  190. return 254;
  191. }
  192. SuppressAllLogPopups (TRUE);
  193. if (!MigUtil_Entry (g_hInst, DLL_PROCESS_ATTACH, NULL)) {
  194. printf ("Initialization error!\n");
  195. return 254;
  196. }
  197. SuppressAllLogPopups (FALSE);
  198. if (!HwComp_Entry (g_hInst, DLL_PROCESS_ATTACH, NULL)) {
  199. printf ("Initialization error!\n");
  200. return 254;
  201. }
  202. #ifdef DEBUG
  203. g_DoLog = TRUE;
  204. #endif
  205. //
  206. // Build hwcomp.dat
  207. //
  208. if (CleanBuild) {
  209. SetFileAttributes (OutputFile, FILE_ATTRIBUTE_NORMAL);
  210. if (!DeleteFile (OutputFile)) {
  211. if (GetLastError() != ERROR_FILE_NOT_FOUND) {
  212. printf ("DeleteFile failed for %s. Win32 Error Code: %x\n",
  213. OutputFile, GetLastError ());
  214. return 252;
  215. }
  216. }
  217. }
  218. if (!CreateNtHardwareList (g_SourceDirectories, g_SourceDirectoryCount, OutputFile, UIMode)) {
  219. rc = GetLastError();
  220. printf ("Could not build complete device. Win32 Error Code: %x\n", rc);
  221. return 1;
  222. } else {
  223. printf ("%s was built successfully.\n", OutputFile);
  224. }
  225. //
  226. // Terminate hwcomp.lib
  227. //
  228. if (!HwComp_Entry (g_hInst, DLL_PROCESS_DETACH, NULL)) {
  229. printf ("Termination error!\n");
  230. return 253;
  231. }
  232. if (!MigUtil_Entry (g_hInst, DLL_PROCESS_DETACH, NULL)) {
  233. printf ("Termination error!\n");
  234. return 253;
  235. }
  236. return 0;
  237. }
  238. //
  239. // Stubs
  240. //
  241. HWND g_Component;
  242. HWND g_SubComponent;
  243. HANDLE g_ComponentCancelEvent;
  244. HANDLE g_SubComponentCancelEvent;
  245. VOID
  246. pInitProgBarVars (
  247. VOID
  248. )
  249. {
  250. g_Component = NULL;
  251. g_SubComponent = NULL;
  252. g_ComponentCancelEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  253. g_SubComponentCancelEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  254. }
  255. BOOL
  256. ProgressBar_SetWindowStringA (
  257. IN HWND Window,
  258. IN HANDLE CancelEvent,
  259. IN PCSTR Message, OPTIONAL
  260. IN DWORD MessageId OPTIONAL
  261. )
  262. {
  263. return TRUE;
  264. }
  265. BOOL
  266. TickProgressBar (
  267. VOID
  268. )
  269. {
  270. return TRUE;
  271. }
  272. BOOL
  273. TickProgressBarDelta (
  274. IN UINT TickCount
  275. )
  276. {
  277. return TRUE;
  278. }
  279. VOID
  280. InitializeProgressBar (
  281. IN HWND ProgressBar,
  282. IN HWND Component, OPTIONAL
  283. IN HWND SubComponent, OPTIONAL
  284. IN BOOL *CancelFlagPtr OPTIONAL
  285. )
  286. {
  287. return;
  288. }
  289. VOID
  290. TerminateProgressBar (
  291. VOID
  292. )
  293. {
  294. return;
  295. }
  296. VOID
  297. EndSliceProcessing (
  298. VOID
  299. )
  300. {
  301. return;
  302. }
  303. UINT
  304. RegisterProgressBarSlice (
  305. IN UINT InitialEstimate
  306. )
  307. {
  308. return 0;
  309. }
  310. VOID
  311. ReviseSliceEstimate (
  312. IN UINT SliceId,
  313. IN UINT RevisedEstimate
  314. )
  315. {
  316. return;
  317. }
  318. VOID
  319. BeginSliceProcessing (
  320. IN UINT SliceId
  321. )
  322. {
  323. }