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.

412 lines
8.0 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. if (!MigUtil_Entry (g_hInst, DLL_PROCESS_ATTACH, NULL)) {
  193. printf ("Initialization error!\n");
  194. return 254;
  195. }
  196. if (!HwComp_Entry (g_hInst, DLL_PROCESS_ATTACH, NULL)) {
  197. printf ("Initialization error!\n");
  198. return 254;
  199. }
  200. #ifdef DEBUG
  201. g_DoLog = TRUE;
  202. #endif
  203. //
  204. // Build hwcomp.dat
  205. //
  206. if (CleanBuild) {
  207. SetFileAttributes (OutputFile, FILE_ATTRIBUTE_NORMAL);
  208. if (!DeleteFile (OutputFile)) {
  209. if (GetLastError() != ERROR_FILE_NOT_FOUND) {
  210. printf ("DeleteFile failed for %s. Win32 Error Code: %x\n",
  211. OutputFile, GetLastError ());
  212. return 252;
  213. }
  214. }
  215. }
  216. if (!CreateNtHardwareList (g_SourceDirectories, g_SourceDirectoryCount, OutputFile, UIMode)) {
  217. rc = GetLastError();
  218. printf ("Could not build complete device. Win32 Error Code: %x\n", rc);
  219. return 1;
  220. } else {
  221. printf ("%s was built successfully.\n", OutputFile);
  222. }
  223. //
  224. // Terminate hwcomp.lib
  225. //
  226. if (!HwComp_Entry (g_hInst, DLL_PROCESS_DETACH, NULL)) {
  227. printf ("Termination error!\n");
  228. return 253;
  229. }
  230. if (!MigUtil_Entry (g_hInst, DLL_PROCESS_DETACH, NULL)) {
  231. printf ("Termination error!\n");
  232. return 253;
  233. }
  234. return 0;
  235. }
  236. //
  237. // Stubs
  238. //
  239. HWND g_Component;
  240. HWND g_SubComponent;
  241. HANDLE g_ComponentCancelEvent;
  242. HANDLE g_SubComponentCancelEvent;
  243. VOID
  244. pInitProgBarVars (
  245. VOID
  246. )
  247. {
  248. g_Component = NULL;
  249. g_SubComponent = NULL;
  250. g_ComponentCancelEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  251. g_SubComponentCancelEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  252. }
  253. BOOL
  254. ProgressBar_SetWindowStringA (
  255. IN HWND Window,
  256. IN HANDLE CancelEvent,
  257. IN PCSTR Message, OPTIONAL
  258. IN DWORD MessageId OPTIONAL
  259. )
  260. {
  261. return TRUE;
  262. }
  263. BOOL
  264. TickProgressBar (
  265. VOID
  266. )
  267. {
  268. return TRUE;
  269. }
  270. BOOL
  271. TickProgressBarDelta (
  272. IN UINT TickCount
  273. )
  274. {
  275. return TRUE;
  276. }
  277. VOID
  278. InitializeProgressBar (
  279. IN HWND ProgressBar,
  280. IN HWND Component, OPTIONAL
  281. IN HWND SubComponent, OPTIONAL
  282. IN BOOL *CancelFlagPtr OPTIONAL
  283. )
  284. {
  285. return;
  286. }
  287. VOID
  288. TerminateProgressBar (
  289. VOID
  290. )
  291. {
  292. return;
  293. }
  294. VOID
  295. EndSliceProcessing (
  296. VOID
  297. )
  298. {
  299. return;
  300. }
  301. UINT
  302. RegisterProgressBarSlice (
  303. IN UINT InitialEstimate
  304. )
  305. {
  306. return 0;
  307. }
  308. VOID
  309. ReviseSliceEstimate (
  310. IN UINT SliceId,
  311. IN UINT RevisedEstimate
  312. )
  313. {
  314. return;
  315. }
  316. VOID
  317. BeginSliceProcessing (
  318. IN UINT SliceId
  319. )
  320. {
  321. }