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.

297 lines
6.3 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. tztest.c
  5. Abstract:
  6. Tztest checks the timezone information stored in win95upg.inf and hivesft.inf against
  7. the actual information on a win9x machine. This way, discrepencies in our database can
  8. be rooted out and fixed.
  9. Author:
  10. Marc R. Whitten (marcw) Jul-29-1998
  11. Revision History:
  12. --*/
  13. #include "pch.h"
  14. BOOL
  15. Init (
  16. VOID
  17. )
  18. {
  19. HINSTANCE hInstance;
  20. hInstance = GetModuleHandle (NULL);
  21. return InitToolMode (hInstance);
  22. }
  23. VOID
  24. Terminate (
  25. VOID
  26. )
  27. {
  28. HINSTANCE hInstance;
  29. hInstance = GetModuleHandle (NULL);
  30. TerminateToolMode (hInstance);
  31. }
  32. BOOL
  33. pInitTimeZoneData (
  34. VOID
  35. );
  36. extern HANDLE g_TzTestHiveSftInf;
  37. VOID
  38. Usage (
  39. VOID
  40. )
  41. {
  42. printf (
  43. "Usage:\n\n"
  44. "tztest [-?v] [-h:<path>] [-w:<path>]\n\n"
  45. "\t-? - This message.\n"
  46. "\t-v - Verbose messages.\n"
  47. "\t-h:<path> - Specify full path for hivesft.inf file.\n"
  48. "\t-w:<path> - Specify full path for win95upg.inf file.\n"
  49. "\n\n"
  50. );
  51. }
  52. INT
  53. __cdecl
  54. main (
  55. INT argc,
  56. CHAR *argv[]
  57. )
  58. {
  59. REGTREE_ENUM eTree;
  60. PCTSTR displayName;
  61. TCHAR path[MAX_TCHAR_PATH];
  62. TCHAR key[MEMDB_MAX];
  63. UINT count;
  64. INT i;
  65. BOOL verbose = FALSE;
  66. PCTSTR win9xUpgPath;
  67. PCTSTR hiveSftPath;
  68. PCTSTR dbPath;
  69. PTSTR p;
  70. MEMDB_ENUM e;
  71. MEMDB_ENUM e2;
  72. PTSTR end;
  73. HASHTABLE tab;
  74. HASHTABLE_ENUM eTab;
  75. TCHAR buffer[MAX_PATH];
  76. if (!Init()) {
  77. printf ("Unable to initialize!\n");
  78. return 255;
  79. }
  80. //
  81. // Set path defaults.
  82. //
  83. if (!GetModuleFileName (NULL, path, MAX_TCHAR_PATH)) {
  84. printf ("TZTEST: Error during initialization (rc %d).", GetLastError());
  85. return GetLastError();
  86. }
  87. p = _tcsrchr(path, TEXT('\\'));
  88. if (p) {
  89. *p = 0;
  90. }
  91. win9xUpgPath = JoinPaths (path, TEXT("win95upg.inf"));
  92. hiveSftPath = JoinPaths (path, TEXT("hivesft.inf"));
  93. dbPath = JoinPaths (path, TEXT("badPaths.dat"));
  94. //
  95. // Parse command line parameters.
  96. //
  97. for (i = 1; i < argc; i++) {
  98. if (argv[i][0] == TEXT('-') || argv[i][0] == TEXT('\\')) {
  99. switch (argv[i][1]) {
  100. case TEXT('v'): case TEXT('V'):
  101. verbose = TRUE;
  102. break;
  103. case TEXT('w'): case TEXT('W'):
  104. if (argv[i][2] == TEXT(':')) {
  105. win9xUpgPath = argv[i] + 3;
  106. }
  107. else {
  108. Usage();
  109. return 0;
  110. }
  111. break;
  112. case TEXT('h'): case TEXT('H'):
  113. if (argv[i][2] == TEXT(':')) {
  114. hiveSftPath = argv[i] + 3;
  115. }
  116. else {
  117. Usage();
  118. return 0;
  119. }
  120. break;
  121. default:
  122. Usage();
  123. return 0;
  124. break;
  125. }
  126. }
  127. }
  128. //
  129. // Load in current bad path information.
  130. //
  131. MemDbLoad (dbPath);
  132. printf("TZTEST: path for win95upg.inf is %s.\n", win9xUpgPath);
  133. printf("TZTEST: path for hivesft.inf is %s.\n", hiveSftPath);
  134. g_Win95UpgInf = InfOpenInfFile (win9xUpgPath);
  135. if (g_Win95UpgInf == INVALID_HANDLE_VALUE || !g_Win95UpgInf) {
  136. printf("TZTEST: Unable to open %s (rc %d)\n", win9xUpgPath, GetLastError());
  137. return GetLastError();
  138. }
  139. g_TzTestHiveSftInf = InfOpenInfFile (hiveSftPath);
  140. if (g_TzTestHiveSftInf == INVALID_HANDLE_VALUE || !g_TzTestHiveSftInf) {
  141. printf("TZTEST: Unable to open %s (rc %d)\n", win9xUpgPath, GetLastError());
  142. InfCloseInfFile (g_Win95UpgInf);
  143. return GetLastError();
  144. }
  145. pInitTimeZoneData ();
  146. printf("TZTEST: Checking all timezones on system.\n\n");
  147. if (EnumFirstRegKeyInTree (&eTree, S_TIMEZONES)) {
  148. do {
  149. displayName = GetRegValueString (eTree.CurrentKey->KeyHandle, S_DISPLAY);
  150. if (!displayName) {
  151. continue;
  152. }
  153. MemDbBuildKey (key, MEMDB_CATEGORY_9X_TIMEZONES, displayName, MEMDB_FIELD_COUNT, NULL);
  154. if (!MemDbGetValue (key, &count)) {
  155. printf ("TZTEST: Timezone not in win9upg.inf - %s\n", displayName);
  156. MemDbSetValueEx(TEXT("NoMatch"), displayName, NULL, NULL, 0, NULL);
  157. }
  158. else if (verbose) {
  159. printf ("TZTEST: %s found in win95upg.inf. %d NT timezones match.\n", displayName, count);
  160. }
  161. MemFree (g_hHeap, 0, displayName);
  162. } while (EnumNextRegKeyInTree (&eTree));
  163. }
  164. //
  165. // Save bad path information.
  166. //
  167. MemDbSave (dbPath);
  168. //
  169. // Do exhaustive search for indexes:
  170. //
  171. if (MemDbEnumItems (&e, MEMDB_CATEGORY_9X_TIMEZONES)) {
  172. do {
  173. tab = HtAlloc ();
  174. printf ("9x Timezone %s matches:\n", e.szName);
  175. p = _tcschr (e.szName, TEXT(')'));
  176. if (p) {
  177. p+=1;
  178. }
  179. while (p) {
  180. end = _tcschr (p, TEXT(','));
  181. if (end) {
  182. *end = 0;
  183. }
  184. p = (PTSTR) SkipSpace (p);
  185. if (MemDbEnumItems (&e2, MEMDB_CATEGORY_NT_TIMEZONES)) {
  186. do {
  187. if (MemDbGetEndpointValueEx (MEMDB_CATEGORY_NT_TIMEZONES, e2.szName, NULL, key)) {
  188. if (_tcsistr (key, p)) {
  189. wsprintf (buffer, "%s (%s)\n", key, e2.szName);
  190. HtAddString (tab, buffer);
  191. }
  192. }
  193. } while (MemDbEnumNextValue (&e2));
  194. }
  195. p = end;
  196. if (p) {
  197. p++;
  198. }
  199. }
  200. if (EnumFirstHashTableString (&eTab, tab)) {
  201. do {
  202. printf (eTab.String);
  203. } while (EnumNextHashTableString (&eTab));
  204. }
  205. else {
  206. printf ("Nothing.\n");
  207. }
  208. HtFree (tab);
  209. printf ("\n");
  210. } while (MemDbEnumNextValue (&e));
  211. }
  212. printf("TZTEST: Done.\n\n");
  213. InfCloseInfFile (g_Win95UpgInf);
  214. InfCloseInfFile (g_TzTestHiveSftInf);
  215. Terminate();
  216. return 0;
  217. }