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.

344 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. hwwiz.c
  5. Abstract:
  6. Implements an upgrade wizard for gathering virus scanner information.
  7. Author:
  8. Marc Whitten (marcw) 16-Oct-1998
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. #include "pch.h"
  13. #include "..\inc\dgdll.h"
  14. #include "..\..\w95upg\migapp\migdbp.h"
  15. DATATYPE g_DataTypes[] = {
  16. {UPGWIZ_VERSION,
  17. "Virus Scanner should be detected",
  18. "You identify running executables that correspond with installed virus scanners on your system.",
  19. 0,
  20. DTF_REQUIRE_DESCRIPTION|DTF_ONE_SELECTION,
  21. 1024,
  22. "&Name of Virus Scanner (<company> <product> <version>)"
  23. }
  24. };
  25. GROWBUFFER g_DataObjects = GROWBUF_INIT;
  26. POOLHANDLE g_DataObjectPool;
  27. HINSTANCE g_OurInst;
  28. BOOL g_GoodVersion = FALSE;
  29. BOOL
  30. Init (
  31. VOID
  32. )
  33. {
  34. #ifndef UPGWIZ4FLOPPY
  35. return InitToolMode (g_OurInst);
  36. #else
  37. return TRUE;
  38. #endif
  39. }
  40. VOID
  41. Terminate (
  42. VOID
  43. )
  44. {
  45. //
  46. // Local cleanup
  47. //
  48. FreeGrowBuffer (&g_DataObjects);
  49. if (g_DataObjectPool) {
  50. PoolMemDestroyPool (g_DataObjectPool);
  51. }
  52. #ifndef UPGWIZ4FLOPPY
  53. TerminateToolMode (g_OurInst);
  54. #endif
  55. }
  56. BOOL
  57. WINAPI
  58. DllMain (
  59. IN HINSTANCE hInstance,
  60. IN DWORD dwReason,
  61. IN LPVOID lpReserved
  62. )
  63. {
  64. if (dwReason == DLL_PROCESS_DETACH) {
  65. MYASSERT (g_OurInst == hInstance);
  66. Terminate();
  67. }
  68. g_OurInst = hInstance;
  69. return TRUE;
  70. }
  71. UINT
  72. GiveVersion (
  73. VOID
  74. )
  75. {
  76. Init();
  77. return UPGWIZ_VERSION;
  78. }
  79. PDATATYPE
  80. GiveDataTypeList (
  81. OUT PUINT Count
  82. )
  83. {
  84. UINT u;
  85. *Count = sizeof (g_DataTypes) / sizeof (g_DataTypes[0]);
  86. for (u = 0 ; u < *Count ; u++) {
  87. g_DataTypes[u].DataTypeId = u;
  88. }
  89. return g_DataTypes;
  90. }
  91. BOOL ParseDosFiles (VOID);
  92. PDATAOBJECT
  93. GiveDataObjectList (
  94. IN UINT DataTypeId,
  95. OUT PUINT Count
  96. )
  97. {
  98. PDATAOBJECT data;
  99. HANDLE snapShot;
  100. PROCESSENTRY32 process;
  101. CHAR name[MEMDB_MAX];
  102. CHAR fixedPath[MAX_MBCHAR_PATH];
  103. PSTR company;
  104. PSTR product;
  105. PSTR version;
  106. g_DataObjectPool = PoolMemInitNamedPool ("Data Objects");
  107. g_GoodVersion = FALSE;
  108. //
  109. // Get list of currently running applications.
  110. //
  111. snapShot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
  112. if (snapShot != INVALID_HANDLE_VALUE) {
  113. //
  114. // Enumerate all the processes running and retrieve their executables.
  115. //
  116. process.dwSize = sizeof (PROCESSENTRY32);
  117. if (Process32First (snapShot, &process)) {
  118. do {
  119. //
  120. // Get version information if it exists.
  121. //
  122. company = QueryVersionEntry (process.szExeFile, "COMPANYNAME");
  123. product = QueryVersionEntry (process.szExeFile, "PRODUCTNAME");
  124. version = QueryVersionEntry (process.szExeFile, "PRODUCTVERSION");
  125. StringCopy (fixedPath, process.szExeFile);
  126. ReplaceWacks (fixedPath);
  127. wsprintf (
  128. name,
  129. "%s\\%s %s\\%s",
  130. company ? company : "<unknown>",
  131. product ? product : "<unknown>",
  132. version ? version : "<unknown>",
  133. fixedPath
  134. );
  135. //
  136. // Create data object for this executable.
  137. //
  138. data = (PDATAOBJECT) GrowBuffer (&g_DataObjects, sizeof(DATAOBJECT));
  139. data -> Version = UPGWIZ_VERSION;
  140. data -> NameOrPath = PoolMemDuplicateString (g_DataObjectPool, name);
  141. data -> Flags = 0;
  142. data -> DllParam = PoolMemDuplicateString (g_DataObjectPool, process.szExeFile);
  143. //
  144. // Clean up version resources.
  145. //
  146. FreePathString (company);
  147. FreePathString (product);
  148. FreePathString (version);
  149. } while (Process32Next (snapShot, &process));
  150. }
  151. }
  152. *Count = g_DataObjects.End / sizeof (DATAOBJECT);
  153. return (PDATAOBJECT) g_DataObjects.Buf;
  154. }
  155. BOOL
  156. DisplayOptionalUI (
  157. IN POUTPUTARGS Args
  158. )
  159. {
  160. PDATAOBJECT data = (PDATAOBJECT) g_DataObjects.Buf;
  161. UINT count = g_DataObjects.End / sizeof (DATAOBJECT);
  162. UINT i;
  163. for (i = 0; i < count; i++) {
  164. if (data -> Flags & DOF_SELECTED) {
  165. //
  166. // If we got good version info, don't worry about the text. We'll use
  167. // what we have.
  168. //
  169. if (!IsPatternMatch("<unknown>\\<unknown> <unknown>*",data->NameOrPath)) {
  170. g_DataTypes[0].Flags &= ~DTF_REQUIRE_DESCRIPTION;
  171. g_GoodVersion = TRUE;
  172. }
  173. break;
  174. }
  175. data++;
  176. }
  177. return TRUE;
  178. }
  179. BOOL
  180. GenerateOutput (
  181. IN POUTPUTARGS Args
  182. )
  183. {
  184. BOOL rSuccess = FALSE;
  185. HANDLE file;
  186. CHAR path[MAX_MBCHAR_PATH];
  187. PSTR p;
  188. PDATAOBJECT data = (PDATAOBJECT) g_DataObjects.Buf;
  189. UINT count = g_DataObjects.End / sizeof (DATAOBJECT);
  190. UINT i;
  191. //
  192. // create outbound file path.
  193. //
  194. wsprintf (
  195. path,
  196. "%s\\vscan.txt",
  197. Args -> OutboundDir
  198. );
  199. //
  200. // open file.
  201. //
  202. printf ("Saving data to %s\n\n", path);
  203. file = CreateFile (
  204. path,
  205. GENERIC_WRITE,
  206. 0,
  207. NULL,
  208. OPEN_ALWAYS,
  209. FILE_ATTRIBUTE_NORMAL,
  210. NULL
  211. );
  212. if (file == INVALID_HANDLE_VALUE) {
  213. printf ("Can't open file for output.\n");
  214. return FALSE;
  215. }
  216. __try {
  217. SetFilePointer (file, 0, NULL, FILE_END);
  218. //
  219. // log user name and date/time
  220. //
  221. if (!WriteHeader (file)) {
  222. __leave;
  223. }
  224. //
  225. // write data.
  226. //
  227. rSuccess = TRUE;
  228. for (i = 0; i < count; i++) {
  229. if (data -> Flags & DOF_SELECTED) {
  230. if (g_GoodVersion) {
  231. //
  232. // Use the data that we have.
  233. //
  234. p = _mbsrchr (data -> NameOrPath, '\\');
  235. MYASSERT (p);
  236. *p = 0;
  237. }
  238. //
  239. // Ask for info if we didn't get any version info, otherwise,
  240. // we'll use what we got.
  241. //
  242. rSuccess &= WriteFileAttributes (
  243. Args,
  244. g_GoodVersion ? data -> NameOrPath : NULL,
  245. file,
  246. data -> DllParam,
  247. NULL
  248. );
  249. }
  250. data++;
  251. }
  252. //
  253. // write a final blank line.
  254. //
  255. WizardWriteRealString (file, "\r\n\r\n");
  256. }
  257. __finally {
  258. //
  259. // Don't forget to cleanup resources.
  260. //
  261. CloseHandle (file);
  262. }
  263. return rSuccess;
  264. }