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.

349 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. hwwiz.c
  5. Abstract:
  6. Implements a upgwiz wizard for obtaining dos configuration information.
  7. Author:
  8. Jim Schmidt (jimschm) 12-Oct-1998
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. #include "pch.h"
  13. #include "..\inc\dgdll.h"
  14. DATATYPE g_DataTypes[] = {
  15. {UPGWIZ_VERSION,
  16. "DOS Device or TSR should be compatible",
  17. "You specify the DOS configuration line that was incorrectly marked as incompatible.",
  18. 0,
  19. DTF_REQUIRE_TEXT|DTF_REQUIRE_DESCRIPTION|DTF_ONE_SELECTION,
  20. 1024,
  21. "&Name of Device or TSR Program:"
  22. },
  23. {UPGWIZ_VERSION,
  24. "DOS Device or TSR should be incompatible",
  25. "You specify the DOS configuration lines that need to be reported as incompatible.",
  26. 0,
  27. DTF_REQUIRE_TEXT|DTF_REQUIRE_DESCRIPTION|DTF_ONE_SELECTION,
  28. 1024,
  29. "&Name of Device or TSR Program:",
  30. "&Describe the Problem:"
  31. }
  32. };
  33. GROWBUFFER g_DataObjects = GROWBUF_INIT;
  34. POOLHANDLE g_DataObjectPool;
  35. HINSTANCE g_OurInst;
  36. BOOL
  37. Init (
  38. VOID
  39. )
  40. {
  41. #ifndef UPGWIZ4FLOPPY
  42. return InitToolMode (g_OurInst);
  43. #else
  44. return TRUE;
  45. #endif
  46. }
  47. VOID
  48. Terminate (
  49. VOID
  50. )
  51. {
  52. //
  53. // Local cleanup
  54. //
  55. FreeGrowBuffer (&g_DataObjects);
  56. if (g_DataObjectPool) {
  57. PoolMemDestroyPool (g_DataObjectPool);
  58. }
  59. #ifndef UPGWIZ4FLOPPY
  60. TerminateToolMode (g_OurInst);
  61. #endif
  62. }
  63. BOOL
  64. WINAPI
  65. DllMain (
  66. IN HINSTANCE hInstance,
  67. IN DWORD dwReason,
  68. IN LPVOID lpReserved
  69. )
  70. {
  71. if (dwReason == DLL_PROCESS_DETACH) {
  72. MYASSERT (g_OurInst == hInstance);
  73. Terminate();
  74. }
  75. g_OurInst = hInstance;
  76. return TRUE;
  77. }
  78. UINT
  79. GiveVersion (
  80. VOID
  81. )
  82. {
  83. Init();
  84. return UPGWIZ_VERSION;
  85. }
  86. PDATATYPE
  87. GiveDataTypeList (
  88. OUT PUINT Count
  89. )
  90. {
  91. UINT u;
  92. *Count = sizeof (g_DataTypes) / sizeof (g_DataTypes[0]);
  93. for (u = 0 ; u < *Count ; u++) {
  94. g_DataTypes[u].DataTypeId = u;
  95. }
  96. return g_DataTypes;
  97. }
  98. PDATAOBJECT
  99. GiveDataObjectList (
  100. IN UINT DataTypeId,
  101. OUT PUINT Count
  102. )
  103. {
  104. PDATAOBJECT data;
  105. MEMDB_ENUM e;
  106. TCHAR line[MEMDB_MAX];
  107. TCHAR key[MEMDB_MAX];
  108. TCHAR file[MEMDB_MAX];
  109. DWORD offset;
  110. DWORD value;
  111. DWORD curOffset;
  112. PTSTR name;
  113. g_DataObjectPool = PoolMemInitNamedPool ("Data Objects");
  114. //
  115. // Parse the dos files.
  116. //
  117. ParseDosFiles ();
  118. curOffset = 0;
  119. //
  120. // Send the list back.
  121. //
  122. if (MemDbEnumItems (&e, MEMDB_CATEGORY_DM_LINES)) {
  123. do {
  124. //
  125. // Get the actual line contents.
  126. //
  127. if (MemDbGetEndpointValueEx (MEMDB_CATEGORY_DM_LINES, e.szName, NULL, line)) {
  128. //
  129. // Get the value and flags from this endpoint.
  130. //
  131. MemDbBuildKey (key, MEMDB_CATEGORY_DM_LINES, e.szName, NULL, line);
  132. MemDbGetValueAndFlags( key, &offset, &value);
  133. if (curOffset != offset) {
  134. MemDbBuildKeyFromOffset (offset, file, 1, NULL);
  135. curOffset = offset;
  136. ReplaceWacks (file);
  137. }
  138. ReplaceWacks (line);
  139. name = JoinPaths(file,line);
  140. //
  141. // create dataobject with this data.
  142. //
  143. data = (PDATAOBJECT) GrowBuffer (&g_DataObjects, sizeof (DATAOBJECT));
  144. data -> Version = UPGWIZ_VERSION;
  145. data -> NameOrPath = PoolMemDuplicateString (g_DataObjectPool, name);
  146. data -> Flags = DOF_NO_SORT;
  147. data -> DllParam = PoolMemDuplicateString (g_DataObjectPool, key);
  148. FreePathString (name);
  149. }
  150. } while (MemDbEnumNextValue (&e));
  151. }
  152. *Count = g_DataObjects.End / sizeof (DATAOBJECT);
  153. return (PDATAOBJECT) g_DataObjects.Buf;
  154. }
  155. BOOL
  156. GenerateOutput (
  157. IN POUTPUTARGS Args
  158. )
  159. {
  160. BOOL rSuccess = FALSE;
  161. TCHAR path[MAX_TCHAR_PATH];
  162. HANDLE file;
  163. PDATAOBJECT data = (PDATAOBJECT) g_DataObjects.Buf;
  164. UINT count = g_DataObjects.End / sizeof (DATAOBJECT);
  165. UINT i;
  166. LINESTRUCT ls;
  167. PTSTR p;
  168. //
  169. // Create path to outbond file
  170. //
  171. wsprintf (
  172. path,
  173. TEXT("%s\\%s"),
  174. Args -> OutboundDir,
  175. Args -> DataTypeId ? "incmpdos.txt" : "cmpdos.txt"
  176. );
  177. printf ("Saving data to %s\n\n", path);
  178. file = CreateFile (
  179. path,
  180. GENERIC_WRITE,
  181. 0,
  182. NULL,
  183. OPEN_ALWAYS,
  184. FILE_ATTRIBUTE_NORMAL,
  185. NULL
  186. );
  187. if (file == INVALID_HANDLE_VALUE) {
  188. printf ("Can't open file for output.\n");
  189. return FALSE;
  190. }
  191. __try {
  192. SetFilePointer (file, 0, NULL, FILE_END);
  193. //
  194. // log user name and date/time
  195. //
  196. if (!WriteHeader (file)) {
  197. __leave;
  198. }
  199. //
  200. // write data.
  201. //
  202. rSuccess = TRUE;
  203. for (i = 0; i < count; i++) {
  204. if (data -> Flags & DOF_SELECTED) {
  205. //
  206. // Write the full line.
  207. //
  208. p = _mbschr (data -> NameOrPath, '\\');
  209. MYASSERT (p);
  210. *p = 0;
  211. RestoreWacks ((PTSTR) data -> NameOrPath);
  212. rSuccess &= WizardWriteString (file, "file: ");
  213. rSuccess &= WizardWriteString (file, data -> NameOrPath);
  214. rSuccess &= WizardWriteString (file, "\r\n");
  215. p = _mbsinc (p);
  216. RestoreWacks (p);
  217. rSuccess &= WizardWriteString (file, "line: ");
  218. rSuccess &= WizardWriteString (file, p);
  219. rSuccess &= WizardWriteString (file, "\r\n");
  220. StringCopy (path, p);
  221. do {
  222. InitLineStruct (&ls, path);
  223. if (DoesFileExist (ls.FullPath)) {
  224. //
  225. // Write File Attributes
  226. //
  227. rSuccess &= WriteFileAttributes (Args, NULL, file, ls.FullPath, NULL);
  228. }
  229. p = ls.Arguments;
  230. if (*p == '=') {
  231. p = _mbsinc (p);
  232. }
  233. p = (PTSTR) SkipSpace (p);
  234. if (p) {
  235. if (*p == '=') {
  236. p = (PTSTR) SkipSpace(_mbsinc (p));
  237. }
  238. if (p) {
  239. StringCopy (path, p);
  240. }
  241. }
  242. if (!p) {
  243. *path = 0;
  244. }
  245. } while (*ls.Arguments && StringCompare (ls.FullLine,ls.Arguments));
  246. }
  247. data++;
  248. }
  249. //
  250. // write a final blank line.
  251. //
  252. WizardWriteRealString (file, "\r\n\r\n");
  253. }
  254. __finally {
  255. CloseHandle (file);
  256. }
  257. return rSuccess;
  258. }