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.

1578 lines
42 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. badappid.c
  5. Abstract:
  6. Implements a upgwiz wizard for obtaining various application information.
  7. Author:
  8. Calin Negreanu (calinn) 10-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. #include "dialogs.h"
  16. #include <commdlg.h>
  17. #include <badapps.h>
  18. #include <newexe.h>
  19. DATATYPE g_DataTypes[] = {
  20. {UPGWIZ_VERSION,
  21. "Generate AppsHelp entry",
  22. "You must specify the main EXE and a variable number of additional files.",
  23. 0,
  24. DTF_REQUIRE_DESCRIPTION,
  25. 1024,
  26. "&Application name:"
  27. },
  28. };
  29. typedef struct _ITEM_INFO {
  30. PSTR FilePath;
  31. PSTR VersionValue;
  32. UINT VersionIndex;
  33. } ITEM_INFO, *PITEM_INFO;
  34. PSTR g_MainFile = NULL;
  35. GROWBUFFER g_AddnlFiles = GROWBUF_INIT;
  36. UINT g_AppProblem = APPTYPE_INC_NOBLOCK;
  37. BOOL g_AppFlags = 0;
  38. BOOL g_SaveMigDb = TRUE;
  39. DWORD g_MsgId = 0;
  40. GROWBUFFER g_DataObjects = GROWBUF_INIT;
  41. POOLHANDLE g_DataObjectPool;
  42. HINSTANCE g_OurInst;
  43. BOOL
  44. Init (
  45. VOID
  46. )
  47. {
  48. #ifndef UPGWIZ4FLOPPY
  49. return InitToolMode (g_OurInst);
  50. #else
  51. return TRUE;
  52. #endif
  53. }
  54. VOID
  55. Terminate (
  56. VOID
  57. )
  58. {
  59. //
  60. // Local cleanup
  61. //
  62. FreeGrowBuffer (&g_DataObjects);
  63. if (g_DataObjectPool) {
  64. PoolMemDestroyPool (g_DataObjectPool);
  65. }
  66. #ifndef UPGWIZ4FLOPPY
  67. TerminateToolMode (g_OurInst);
  68. #endif
  69. }
  70. BOOL
  71. WINAPI
  72. DllMain (
  73. IN HINSTANCE hInstance,
  74. IN DWORD dwReason,
  75. IN LPVOID lpReserved
  76. )
  77. {
  78. if (dwReason == DLL_PROCESS_DETACH) {
  79. MYASSERT (g_OurInst == hInstance);
  80. Terminate();
  81. }
  82. g_OurInst = hInstance;
  83. return TRUE;
  84. }
  85. UINT
  86. GiveVersion (
  87. VOID
  88. )
  89. {
  90. Init();
  91. g_DataObjectPool = PoolMemInitNamedPool ("Data Objects");
  92. return UPGWIZ_VERSION;
  93. }
  94. PDATATYPE
  95. GiveDataTypeList (
  96. OUT PUINT Count
  97. )
  98. {
  99. UINT u;
  100. *Count = sizeof (g_DataTypes) / sizeof (g_DataTypes[0]);
  101. for (u = 0 ; u < *Count ; u++) {
  102. g_DataTypes[u].DataTypeId = u;
  103. }
  104. return g_DataTypes;
  105. }
  106. BOOL CALLBACK
  107. pSetDefGuiFontProc(
  108. IN HWND hwnd,
  109. IN LPARAM lParam)
  110. {
  111. SendMessage(hwnd, WM_SETFONT, lParam, 0L);
  112. return TRUE;
  113. }
  114. void
  115. pSetDefGUIFont(
  116. IN HWND hdlg
  117. )
  118. {
  119. EnumChildWindows(hdlg, pSetDefGuiFontProc, (LPARAM)GetStockObject(DEFAULT_GUI_FONT));
  120. }
  121. BOOL
  122. CALLBACK
  123. pGetFilesUIProc (
  124. HWND hdlg,
  125. UINT uMsg,
  126. WPARAM wParam,
  127. LPARAM lParam
  128. )
  129. {
  130. CHAR tempStr [MEMDB_MAX];
  131. static CHAR lastDir [MEMDB_MAX] = "";
  132. OPENFILENAME ofn;
  133. UINT Index;
  134. switch (uMsg) {
  135. case WM_INITDIALOG:
  136. pSetDefGUIFont(hdlg);
  137. CheckDlgButton (hdlg, IDC_SAVEMIGDB, BST_CHECKED);
  138. CheckDlgButton (hdlg, IDC_NONET, BST_UNCHECKED);
  139. CheckDlgButton (hdlg, IDC_APPTYPE1, BST_CHECKED);
  140. CheckDlgButton (hdlg, IDC_APPTYPE2, BST_UNCHECKED);
  141. CheckDlgButton (hdlg, IDC_APPTYPE3, BST_UNCHECKED);
  142. CheckDlgButton (hdlg, IDC_APPTYPE4, BST_UNCHECKED);
  143. CheckDlgButton (hdlg, IDC_APPTYPE5, BST_UNCHECKED);
  144. CheckDlgButton (hdlg, IDC_APPTYPE6, BST_UNCHECKED);
  145. sprintf (tempStr, "%d", g_MsgId);
  146. SendDlgItemMessage (hdlg, IDC_MSGID, WM_SETTEXT, 0, (LPARAM)tempStr);
  147. EnableWindow (GetDlgItem (hdlg, ID_CONTINUE), FALSE);
  148. EnableWindow (GetDlgItem (hdlg, IDC_VERSION), FALSE);
  149. PostMessage (hdlg, WM_COMMAND, IDC_BROWSE, 0);
  150. return FALSE;
  151. case WM_COMMAND:
  152. switch (LOWORD (wParam)) {
  153. case IDC_MAINFILE:
  154. if (HIWORD (wParam) == EN_CHANGE) {
  155. if (g_MainFile) {
  156. FreePathString (g_MainFile);
  157. g_MainFile = NULL;
  158. }
  159. SendDlgItemMessage (hdlg, IDC_MAINFILE, WM_GETTEXT, MEMDB_MAX, (LPARAM)tempStr);
  160. g_MainFile = DuplicatePathString (tempStr, 0);
  161. if (DoesFileExist (g_MainFile)) {
  162. EnableWindow (GetDlgItem (hdlg, ID_CONTINUE), TRUE);
  163. } else {
  164. EnableWindow (GetDlgItem (hdlg, ID_CONTINUE), FALSE);
  165. }
  166. }
  167. break;
  168. case IDC_BROWSE:
  169. if (g_MainFile) {
  170. StringCopy (tempStr, g_MainFile);
  171. } else {
  172. *tempStr = 0;
  173. }
  174. ZeroMemory (&ofn, sizeof (OPENFILENAME));
  175. ofn.lStructSize = sizeof (OPENFILENAME);
  176. ofn.hwndOwner = hdlg;
  177. ofn.lpstrFile = tempStr;
  178. ofn.nMaxFile = MEMDB_MAX;
  179. ofn.lpstrInitialDir = lastDir;
  180. ofn.lpstrTitle = "Select Main File";
  181. ofn.Flags = OFN_NOCHANGEDIR | OFN_NODEREFERENCELINKS | OFN_HIDEREADONLY;
  182. if (GetOpenFileName (&ofn)) {
  183. //let's copy the last directory
  184. StringCopyAB (lastDir, tempStr, _mbsdec (tempStr, tempStr + ofn.nFileOffset));
  185. if (g_MainFile) {
  186. FreePathString (g_MainFile);
  187. }
  188. g_MainFile = DuplicatePathString (tempStr, 0);
  189. if (DoesFileExist (g_MainFile)) {
  190. EnableWindow (GetDlgItem (hdlg, ID_CONTINUE), TRUE);
  191. } else {
  192. EnableWindow (GetDlgItem (hdlg, ID_CONTINUE), FALSE);
  193. }
  194. SendDlgItemMessage (hdlg, IDC_MAINFILE, WM_SETTEXT, 0, (LPARAM)g_MainFile);
  195. }
  196. break;
  197. case IDC_ADDFILE:
  198. *tempStr = 0;
  199. ZeroMemory (&ofn, sizeof (OPENFILENAME));
  200. ofn.lStructSize = sizeof (OPENFILENAME);
  201. ofn.hwndOwner = hdlg;
  202. ofn.lpstrFile = tempStr;
  203. ofn.nMaxFile = MEMDB_MAX;
  204. ofn.lpstrInitialDir = lastDir;
  205. ofn.lpstrTitle = "Add Required File";
  206. ofn.Flags = OFN_NOCHANGEDIR | OFN_NODEREFERENCELINKS | OFN_HIDEREADONLY;
  207. if (GetOpenFileName (&ofn)) {
  208. //let's copy the last directory
  209. StringCopyAB (lastDir, tempStr, _mbsdec (tempStr, tempStr + ofn.nFileOffset));
  210. Index = SendDlgItemMessage (hdlg, IDC_REQFILES, LB_ADDSTRING, 0, (LPARAM)tempStr);
  211. SendDlgItemMessage (hdlg, IDC_REQFILES, LB_SETCURSEL, Index, 0);
  212. }
  213. break;
  214. case IDC_REMOVEFILE:
  215. Index = SendDlgItemMessage (hdlg, IDC_REQFILES, LB_GETCURSEL, 0, 0);
  216. if (Index != LB_ERR) {
  217. SendDlgItemMessage (hdlg, IDC_REQFILES, LB_DELETESTRING, Index, 0);
  218. if (Index >= (UINT)SendDlgItemMessage (hdlg, IDC_REQFILES, LB_GETCOUNT, 0, 0)) {
  219. SendDlgItemMessage (
  220. hdlg,
  221. IDC_REQFILES,
  222. LB_SETCURSEL,
  223. SendDlgItemMessage (hdlg, IDC_REQFILES, LB_GETCOUNT, 0, 0) - 1,
  224. 0
  225. );
  226. } else {
  227. SendDlgItemMessage (hdlg, IDC_REQFILES, LB_SETCURSEL, Index, 0);
  228. }
  229. }
  230. break;
  231. case IDC_APPTYPE1:
  232. case IDC_APPTYPE2:
  233. case IDC_APPTYPE3:
  234. case IDC_APPTYPE4:
  235. case IDC_APPTYPE5:
  236. case IDC_APPTYPE6:
  237. if (IsDlgButtonChecked (hdlg, IDC_APPTYPE5)) {
  238. EnableWindow (GetDlgItem (hdlg, IDC_FLAG1), FALSE);
  239. EnableWindow (GetDlgItem (hdlg, IDC_FLAG2), FALSE);
  240. EnableWindow (GetDlgItem (hdlg, IDC_FLAG3), FALSE);
  241. EnableWindow (GetDlgItem (hdlg, IDC_SAVEMIGDB), FALSE);
  242. EnableWindow (GetDlgItem (hdlg, IDC_MSGID), FALSE);
  243. EnableWindow (GetDlgItem (hdlg, IDC_VERSION), TRUE);
  244. } else if (IsDlgButtonChecked (hdlg, IDC_APPTYPE6)) {
  245. EnableWindow (GetDlgItem (hdlg, IDC_FLAG1), FALSE);
  246. EnableWindow (GetDlgItem (hdlg, IDC_FLAG2), FALSE);
  247. EnableWindow (GetDlgItem (hdlg, IDC_FLAG3), FALSE);
  248. EnableWindow (GetDlgItem (hdlg, IDC_SAVEMIGDB), FALSE);
  249. EnableWindow (GetDlgItem (hdlg, IDC_MSGID), FALSE);
  250. EnableWindow (GetDlgItem (hdlg, IDC_VERSION), FALSE);
  251. } else {
  252. EnableWindow (GetDlgItem (hdlg, IDC_FLAG1), TRUE);
  253. EnableWindow (GetDlgItem (hdlg, IDC_FLAG2), TRUE);
  254. EnableWindow (GetDlgItem (hdlg, IDC_FLAG3), TRUE);
  255. EnableWindow (GetDlgItem (hdlg, IDC_SAVEMIGDB), TRUE);
  256. EnableWindow (GetDlgItem (hdlg, IDC_MSGID), TRUE);
  257. EnableWindow (GetDlgItem (hdlg, IDC_VERSION), FALSE);
  258. }
  259. break;
  260. case ID_CONTINUE:
  261. g_SaveMigDb = IsDlgButtonChecked (hdlg, IDC_SAVEMIGDB);
  262. if (IsDlgButtonChecked (hdlg, IDC_FLAG1)) {
  263. g_AppFlags |= APPTYPE_FLAG_NONET;
  264. }
  265. if (IsDlgButtonChecked (hdlg, IDC_FLAG2)) {
  266. g_AppFlags |= APPTYPE_FLAG_FAT32;
  267. }
  268. if (IsDlgButtonChecked (hdlg, IDC_FLAG3)) {
  269. g_AppFlags |= APPTYPE_FLAG_NTFS;
  270. }
  271. g_AppProblem = APPTYPE_INC_NOBLOCK;
  272. if (IsDlgButtonChecked (hdlg, IDC_APPTYPE1)) {
  273. g_AppProblem = APPTYPE_INC_NOBLOCK;
  274. } else if (IsDlgButtonChecked (hdlg, IDC_APPTYPE2)) {
  275. g_AppProblem = APPTYPE_INC_HARDBLOCK;
  276. } else if (IsDlgButtonChecked (hdlg, IDC_APPTYPE3)) {
  277. g_AppProblem = APPTYPE_MINORPROBLEM;
  278. } else if (IsDlgButtonChecked (hdlg, IDC_APPTYPE4)) {
  279. g_AppProblem = APPTYPE_REINSTALL;
  280. } else if (IsDlgButtonChecked (hdlg, IDC_APPTYPE5)) {
  281. g_AppProblem = APPTYPE_VERSIONSUB;
  282. } else if (IsDlgButtonChecked (hdlg, IDC_APPTYPE6)) {
  283. g_AppProblem = APPTYPE_SHIM;
  284. }
  285. if (g_AppProblem == APPTYPE_VERSIONSUB) {
  286. SendDlgItemMessage (hdlg, IDC_VERSION, WM_GETTEXT, MEMDB_MAX, (LPARAM)tempStr);
  287. g_SaveMigDb = FALSE;
  288. g_AppFlags = 0;
  289. } else if (g_AppProblem == APPTYPE_SHIM) {
  290. tempStr[0] = 0;
  291. g_SaveMigDb = FALSE;
  292. g_AppFlags = 0;
  293. } else {
  294. SendDlgItemMessage (hdlg, IDC_MSGID, WM_GETTEXT, MEMDB_MAX, (LPARAM)tempStr);
  295. }
  296. g_MsgId = strtoul (tempStr, NULL, 10);
  297. Index = (UINT)SendDlgItemMessage (hdlg, IDC_REQFILES, LB_GETCOUNT, 0, 0);
  298. while (Index) {
  299. if (SendDlgItemMessage (hdlg, IDC_REQFILES, LB_GETTEXT, Index - 1, (LPARAM) tempStr) != LB_ERR) {
  300. MultiSzAppend (&g_AddnlFiles, tempStr);
  301. }
  302. Index --;
  303. }
  304. EndDialog (hdlg, LOWORD (wParam));
  305. break;
  306. case IDCANCEL:
  307. case ID_QUIT:
  308. EndDialog (hdlg, LOWORD (wParam));
  309. break;
  310. }
  311. break;
  312. }
  313. return FALSE;
  314. }
  315. BOOL
  316. GatherInfoUI (
  317. HINSTANCE LocalDllInstance,
  318. IN UINT DataTypeId
  319. )
  320. {
  321. BOOL result = TRUE;
  322. switch (DataTypeId) {
  323. case 0:
  324. if (g_MainFile) {
  325. FreePathString (g_MainFile);
  326. g_MainFile = NULL;
  327. }
  328. if (g_AddnlFiles.Buf) {
  329. FreeGrowBuffer (&g_AddnlFiles);
  330. }
  331. g_AppFlags = 0;
  332. g_SaveMigDb = TRUE;
  333. g_MsgId = 0;
  334. result = (ID_CONTINUE == DialogBox (LocalDllInstance, MAKEINTRESOURCE(IDD_GETFILES), NULL, pGetFilesUIProc));
  335. break;
  336. default:
  337. MessageBox (NULL, "Internal BadApps DLL error:00004. Please contact calinn.", "Error", MB_OK);
  338. result = FALSE;
  339. }
  340. return result;
  341. }
  342. PSTR g_ExeTypesStr[] = {
  343. "NONE",
  344. "DOS",
  345. "WIN16",
  346. "WIN32"
  347. };
  348. PCTSTR
  349. QueryCompanyName (
  350. IN PCTSTR FilePath
  351. )
  352. {
  353. return QueryVersionEntry (FilePath, "COMPANYNAME");
  354. }
  355. PCTSTR
  356. QueryProductVersion (
  357. IN PCTSTR FilePath
  358. )
  359. {
  360. return QueryVersionEntry (FilePath, "PRODUCTVERSION");
  361. }
  362. PCTSTR
  363. QueryProductName (
  364. IN PCTSTR FilePath
  365. )
  366. {
  367. return QueryVersionEntry (FilePath, "PRODUCTNAME");
  368. }
  369. PCTSTR
  370. QueryFileDescription (
  371. IN PCTSTR FilePath
  372. )
  373. {
  374. return QueryVersionEntry (FilePath, "FILEDESCRIPTION");
  375. }
  376. PCTSTR
  377. QueryFileVersion (
  378. IN PCTSTR FilePath
  379. )
  380. {
  381. return QueryVersionEntry (FilePath, "FILEVERSION");
  382. }
  383. PCTSTR
  384. QueryOriginalFileName (
  385. IN PCTSTR FilePath
  386. )
  387. {
  388. return QueryVersionEntry (FilePath, "ORIGINALFILENAME");
  389. }
  390. PCTSTR
  391. QueryInternalName (
  392. IN PCTSTR FilePath
  393. )
  394. {
  395. return QueryVersionEntry (FilePath, "INTERNALNAME");
  396. }
  397. PCTSTR
  398. QueryLegalCopyright (
  399. IN PCTSTR FilePath
  400. )
  401. {
  402. return QueryVersionEntry (FilePath, "LEGALCOPYRIGHT");
  403. }
  404. PCTSTR
  405. Query16BitDescription (
  406. IN PCTSTR FilePath
  407. )
  408. {
  409. return Get16ModuleDescription (FilePath);
  410. }
  411. PCTSTR
  412. QueryModuleType (
  413. IN PCTSTR FilePath
  414. )
  415. {
  416. return g_ExeTypesStr [GetModuleType (FilePath)];
  417. }
  418. PCTSTR
  419. QueryFileSize (
  420. IN PCSTR FilePath
  421. )
  422. {
  423. HANDLE findHandle;
  424. WIN32_FIND_DATA findData;
  425. CHAR result[10];
  426. findHandle = FindFirstFile (FilePath, &findData);
  427. if (findHandle == INVALID_HANDLE_VALUE) {
  428. return NULL;
  429. }
  430. sprintf (result, "0x%08lX", findData.nFileSizeLow);
  431. FindClose (findHandle);
  432. return PoolMemDuplicateString (g_DataObjectPool, result);
  433. }
  434. PCTSTR
  435. QueryFileCheckSum (
  436. IN PCTSTR FilePath
  437. )
  438. {
  439. UINT checkSum;
  440. FILE_HELPER_PARAMS Params;
  441. WIN32_FIND_DATA findData;
  442. TCHAR result[10];
  443. HANDLE findHandle;
  444. Params.Handled = 0;
  445. Params.FullFileSpec = FilePath;
  446. Params.IsDirectory = FALSE;
  447. Params.Extension = GetFileExtensionFromPath (FilePath);
  448. Params.CurrentDirData = NULL;
  449. findHandle = FindFirstFile (FilePath, &findData);
  450. if (findHandle == INVALID_HANDLE_VALUE) {
  451. return NULL;
  452. }
  453. Params.FindData = &findData;
  454. Params.VirtualFile = FALSE;
  455. checkSum = ComputeCheckSum (&Params);
  456. sprintf (result, "0x%08lX", checkSum);
  457. FindClose (findHandle);
  458. return PoolMemDuplicateString (g_DataObjectPool, result);
  459. }
  460. PCTSTR
  461. QueryFilePECheckSum (
  462. IN PCSTR FilePath
  463. )
  464. {
  465. ULONG checkSum;
  466. TCHAR result[sizeof (ULONG) * 2 + 2];
  467. checkSum = GetPECheckSum (FilePath);
  468. if (checkSum == 0) {
  469. return NULL;
  470. }
  471. sprintf (result, "0x%0lX", checkSum);
  472. return PoolMemDuplicateString (g_DataObjectPool, result);
  473. }
  474. PCTSTR
  475. QueryBinFileVer (
  476. IN PCSTR FilePath
  477. )
  478. {
  479. ULONGLONG value;
  480. PWORD valueIdx;
  481. TCHAR result[24];
  482. valueIdx = (PWORD) (&value);
  483. value = GetBinFileVer (FilePath);
  484. if (value == 0) {
  485. return NULL;
  486. }
  487. sprintf (result, "%d.%d.%d.%d", *(valueIdx + 3), *(valueIdx + 2), *(valueIdx + 1), *valueIdx);
  488. return PoolMemDuplicateString (g_DataObjectPool, result);
  489. }
  490. PCTSTR
  491. QueryBinProductVer (
  492. IN PCSTR FilePath
  493. )
  494. {
  495. ULONGLONG value;
  496. PWORD valueIdx;
  497. TCHAR result[24];
  498. valueIdx = (PWORD) (&value);
  499. value = GetBinProductVer (FilePath);
  500. if (value == 0) {
  501. return NULL;
  502. }
  503. sprintf (result, "%d.%d.%d.%d", *(valueIdx + 3), *(valueIdx + 2), *(valueIdx + 1), *valueIdx);
  504. return PoolMemDuplicateString (g_DataObjectPool, result);
  505. }
  506. PCTSTR
  507. QueryFileDateHi (
  508. IN PCSTR FilePath
  509. )
  510. {
  511. DWORD value;
  512. TCHAR result[sizeof (ULONG) * 2 + 2];
  513. value = GetFileDateHi (FilePath);
  514. if (value == 0) {
  515. return NULL;
  516. }
  517. sprintf (result, "0x%08lX", value);
  518. return PoolMemDuplicateString (g_DataObjectPool, result);
  519. }
  520. PCTSTR
  521. QueryFileDateLo (
  522. IN PCSTR FilePath
  523. )
  524. {
  525. DWORD value;
  526. TCHAR result[sizeof (ULONG) * 2 + 2];
  527. value = GetFileDateLo (FilePath);
  528. if (value == 0) {
  529. return NULL;
  530. }
  531. sprintf (result, "0x%08lX", value);
  532. return PoolMemDuplicateString (g_DataObjectPool, result);
  533. }
  534. PCTSTR
  535. QueryFileVerOs (
  536. IN PCSTR FilePath
  537. )
  538. {
  539. DWORD value;
  540. TCHAR result[sizeof (ULONG) * 2 + 2];
  541. value = GetFileVerOs (FilePath);
  542. if (value == 0) {
  543. return NULL;
  544. }
  545. sprintf (result, "0x%08lX", value);
  546. return PoolMemDuplicateString (g_DataObjectPool, result);
  547. }
  548. PCTSTR
  549. QueryFileVerType (
  550. IN PCSTR FilePath
  551. )
  552. {
  553. DWORD value;
  554. TCHAR result[sizeof (ULONG) * 2 + 2];
  555. value = GetFileVerType (FilePath);
  556. if (value == 0) {
  557. return NULL;
  558. }
  559. sprintf (result, "0x%08lX", value);
  560. return PoolMemDuplicateString (g_DataObjectPool, result);
  561. }
  562. PCTSTR
  563. QueryPrevOsMajorVersion (
  564. IN PCSTR FilePath
  565. )
  566. {
  567. OSVERSIONINFO osInfo;
  568. TCHAR result[20];
  569. ZeroMemory (&osInfo, sizeof (OSVERSIONINFO));
  570. osInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  571. GetVersionEx (&osInfo);
  572. sprintf (result, "%ld", osInfo.dwMajorVersion);
  573. return PoolMemDuplicateString (g_DataObjectPool, result);
  574. }
  575. PCTSTR
  576. QueryPrevOsMinorVersion (
  577. IN PCSTR FilePath
  578. )
  579. {
  580. OSVERSIONINFO osInfo;
  581. TCHAR result[20];
  582. ZeroMemory (&osInfo, sizeof (OSVERSIONINFO));
  583. osInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  584. GetVersionEx (&osInfo);
  585. sprintf (result, "%ld", osInfo.dwMinorVersion);
  586. return PoolMemDuplicateString (g_DataObjectPool, result);
  587. }
  588. PCTSTR
  589. QueryPrevOsPlatformId (
  590. IN PCSTR FilePath
  591. )
  592. {
  593. OSVERSIONINFO osInfo;
  594. TCHAR result[20];
  595. ZeroMemory (&osInfo, sizeof (OSVERSIONINFO));
  596. osInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  597. GetVersionEx (&osInfo);
  598. sprintf (result, "%ld", osInfo.dwPlatformId);
  599. return PoolMemDuplicateString (g_DataObjectPool, result);
  600. }
  601. PCTSTR
  602. QueryPrevOsBuildNo (
  603. IN PCSTR FilePath
  604. )
  605. {
  606. OSVERSIONINFO osInfo;
  607. TCHAR result[20];
  608. ZeroMemory (&osInfo, sizeof (OSVERSIONINFO));
  609. osInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  610. GetVersionEx (&osInfo);
  611. sprintf (result, "%ld", osInfo.dwBuildNumber);
  612. return PoolMemDuplicateString (g_DataObjectPool, result);
  613. }
  614. BOOL
  615. OutputDecValue (
  616. IN PCSTR VersionValue,
  617. OUT DWORD *Size,
  618. OUT PBYTE *Data
  619. )
  620. {
  621. PDWORD result;
  622. result = MemAlloc (g_hHeap, 0, sizeof (DWORD));
  623. if (!result) {
  624. return FALSE;
  625. }
  626. sscanf (VersionValue, "%ld", result);
  627. *Data = (PBYTE)result;
  628. *Size = sizeof (DWORD);
  629. return TRUE;
  630. }
  631. BOOL
  632. OutputHexValue (
  633. IN PCSTR VersionValue,
  634. OUT DWORD *Size,
  635. OUT PBYTE *Data
  636. )
  637. {
  638. PDWORD result;
  639. result = MemAlloc (g_hHeap, 0, sizeof (DWORD));
  640. if (!result) {
  641. return FALSE;
  642. }
  643. sscanf (VersionValue, "%lx", result);
  644. *Data = (PBYTE)result;
  645. *Size = sizeof (DWORD);
  646. return TRUE;
  647. }
  648. BOOL
  649. OutputModuleTypeValue (
  650. IN PCSTR VersionValue,
  651. OUT DWORD *Size,
  652. OUT PBYTE *Data
  653. )
  654. {
  655. PDWORD result;
  656. result = MemAlloc (g_hHeap, 0, sizeof (DWORD));
  657. if (!result) {
  658. return FALSE;
  659. }
  660. *result = 0;
  661. if (StringIMatch (VersionValue, "NONE")) {
  662. *result = 0;
  663. }
  664. if (StringIMatch (VersionValue, "DOS")) {
  665. *result = 1;
  666. }
  667. if (StringIMatch (VersionValue, "WIN16")) {
  668. *result = 2;
  669. }
  670. if (StringIMatch (VersionValue, "WIN32")) {
  671. *result = 3;
  672. }
  673. *Data = (PBYTE)result;
  674. *Size = sizeof (DWORD);
  675. return TRUE;
  676. }
  677. BOOL
  678. OutputStrValue (
  679. IN PCSTR VersionValue,
  680. OUT DWORD *Size,
  681. OUT PBYTE *Data
  682. )
  683. {
  684. PWSTR result;
  685. PCWSTR convStr;
  686. convStr = ConvertAtoW (VersionValue);
  687. *Size = (wcslen (convStr) + 1) * sizeof (WCHAR);
  688. result = MemAlloc (g_hHeap, 0, *Size);
  689. if (!result) {
  690. return FALSE;
  691. }
  692. StringCopyW (result, convStr);
  693. FreeConvertedStr (convStr);
  694. *Data = (PBYTE)result;
  695. return TRUE;
  696. }
  697. typedef struct {
  698. ULONGLONG Value;
  699. ULONGLONG Mask;
  700. } BINVER_DATA, *PBINVER_DATA;
  701. BOOL
  702. OutputBinVerValue (
  703. IN PCSTR VersionValue,
  704. OUT DWORD *Size,
  705. OUT PBYTE *Data
  706. )
  707. {
  708. PBINVER_DATA result;
  709. PWORD maskIdx;
  710. PWORD valueIdx;
  711. UINT index;
  712. result = MemAlloc (g_hHeap, 0, sizeof (BINVER_DATA));
  713. if (!result) {
  714. return FALSE;
  715. }
  716. result->Value = 0;
  717. result->Mask = 0;
  718. *Size = sizeof (BINVER_DATA);
  719. maskIdx = (PWORD)&(result->Mask) + 3;
  720. valueIdx = (PWORD)&(result->Value) + 3;
  721. index = 0;
  722. while (VersionValue && *VersionValue) {
  723. *valueIdx = (WORD) strtoul ((PSTR)VersionValue, &((PSTR)VersionValue), 10);
  724. if (*VersionValue && (_mbsnextc (VersionValue) != '.')) {
  725. *Data = (PBYTE)result;
  726. return TRUE;
  727. }
  728. VersionValue = _mbsinc (VersionValue);
  729. *maskIdx = 0xFFFF;
  730. valueIdx --;
  731. maskIdx --;
  732. index ++;
  733. if (index >= 4) {
  734. break;
  735. }
  736. }
  737. *Data = (PBYTE)result;
  738. return TRUE;
  739. }
  740. BOOL
  741. OutputUpToBinVerValue (
  742. IN PCSTR VersionValue,
  743. OUT DWORD *Size,
  744. OUT PBYTE *Data
  745. )
  746. {
  747. PULONGLONG result;
  748. PWORD valueIdx;
  749. UINT index;
  750. result = MemAlloc (g_hHeap, 0, sizeof (ULONGLONG));
  751. if (!result) {
  752. return FALSE;
  753. }
  754. *result = 0;
  755. *Size = sizeof (ULONGLONG);
  756. valueIdx = (PWORD)result + 3;
  757. index = 0;
  758. while (VersionValue && *VersionValue) {
  759. *valueIdx = (WORD) strtoul ((PSTR)VersionValue, &((PSTR)VersionValue), 10);
  760. if (*VersionValue && (_mbsnextc (VersionValue) != '.')) {
  761. *Data = (PBYTE)result;
  762. return TRUE;
  763. }
  764. VersionValue = _mbsinc (VersionValue);
  765. valueIdx --;
  766. index ++;
  767. if (index >= 4) {
  768. break;
  769. }
  770. }
  771. *Data = (PBYTE)result;
  772. return TRUE;
  773. }
  774. typedef PCTSTR (VERSION_QUERY_PROTOTYPE) (PCTSTR FilePath);
  775. typedef VERSION_QUERY_PROTOTYPE * PVERSION_QUERY_PROTOTYPE;
  776. typedef BOOL (VERSION_OUTPUT_PROTOTYPE) (PCTSTR VersionValue, DWORD *Size, PBYTE *Data);
  777. typedef VERSION_OUTPUT_PROTOTYPE * PVERSION_OUTPUT_PROTOTYPE;
  778. typedef struct _VERSION_DATA {
  779. DWORD VersionId;
  780. PCSTR VersionName;
  781. PCSTR DisplayName;
  782. PCSTR VersionValue;
  783. DWORD Allowance;
  784. BOOL Modifiable;
  785. PVERSION_QUERY_PROTOTYPE VersionQuery;
  786. PVERSION_OUTPUT_PROTOTYPE VersionOutput;
  787. } VERSION_DATA, *PVERSION_DATA;
  788. #define LIBARGS(id, fn) {id,
  789. #define TOOLARGS(name, dispName, allowance, edit, query, output) name,dispName,NULL,allowance,edit,query,output},
  790. VERSION_DATA g_ToolVersionData [] = {
  791. VERSION_STAMPS
  792. {0, NULL, NULL, NULL, 0, FALSE, NULL, NULL}
  793. };
  794. #undef TOOLARGS
  795. #undef LIBARGS
  796. VOID
  797. pGatherFilesAttributes (
  798. VOID
  799. )
  800. {
  801. PDATAOBJECT Data;
  802. MULTISZ_ENUM multiSzEnum;
  803. PSTR filePath;
  804. PVERSION_DATA p;
  805. PITEM_INFO info;
  806. UINT versionIdx;
  807. TCHAR buffer [MEMDB_MAX];
  808. p = g_ToolVersionData;
  809. versionIdx = 0;
  810. while (p->VersionName) {
  811. p->VersionValue = p->VersionQuery(g_MainFile);
  812. if ((p->VersionValue) && (p->Allowance & VA_ALLOWMAINFILE)) {
  813. Data = (PDATAOBJECT) GrowBuffer (&g_DataObjects, sizeof (DATAOBJECT));
  814. filePath = PoolMemDuplicateString (g_DataObjectPool, g_MainFile);
  815. ReplaceWacks (filePath);
  816. sprintf (buffer, "%s - %s", p->DisplayName, p->VersionValue);
  817. Data->NameOrPath = JoinPaths (filePath, buffer);
  818. Data->Version = UPGWIZ_VERSION;
  819. Data->Flags = DOF_NO_SORT;
  820. info = (PITEM_INFO) PoolMemGetMemory (g_DataObjectPool, sizeof (ITEM_INFO));
  821. info->FilePath = PoolMemDuplicateString (g_DataObjectPool, g_MainFile);
  822. info->VersionValue = PoolMemDuplicateString (g_DataObjectPool, p->VersionValue);
  823. info->VersionIndex = versionIdx;
  824. Data->DllParam = info;
  825. }
  826. p++;
  827. versionIdx++;
  828. }
  829. if (EnumFirstMultiSz (&multiSzEnum, g_AddnlFiles.Buf)) {
  830. do {
  831. p = g_ToolVersionData;
  832. versionIdx = 0;
  833. while (p->VersionName) {
  834. p->VersionValue = p->VersionQuery(multiSzEnum.CurrentString);
  835. if ((p->VersionValue) && (p->Allowance & VA_ALLOWADDNLFILES)) {
  836. Data = (PDATAOBJECT) GrowBuffer (&g_DataObjects, sizeof (DATAOBJECT));
  837. filePath = PoolMemDuplicateString (g_DataObjectPool, multiSzEnum.CurrentString);
  838. ReplaceWacks (filePath);
  839. sprintf (buffer, "%s - %s", p->DisplayName, p->VersionValue);
  840. Data->NameOrPath = JoinPaths (filePath, buffer);
  841. Data->Version = UPGWIZ_VERSION;
  842. Data->Flags = DOF_NO_SORT;
  843. info = (PITEM_INFO) PoolMemGetMemory (g_DataObjectPool, sizeof (ITEM_INFO));
  844. info->FilePath = PoolMemDuplicateString (g_DataObjectPool, multiSzEnum.CurrentString);
  845. info->VersionValue = PoolMemDuplicateString (g_DataObjectPool, p->VersionValue);
  846. info->VersionIndex = versionIdx;
  847. Data->DllParam = info;
  848. }
  849. p++;
  850. versionIdx++;
  851. }
  852. } while (EnumNextMultiSz (&multiSzEnum));
  853. }
  854. }
  855. PDATAOBJECT
  856. GiveDataObjectList (
  857. IN UINT DataTypeId,
  858. OUT PUINT Count
  859. )
  860. {
  861. switch (DataTypeId) {
  862. case 0:
  863. // Bad apps
  864. pGatherFilesAttributes ();
  865. break;
  866. default:
  867. MessageBox (NULL, "Internal BadApps DLL error:00001. Please contact calinn.", "Error", MB_OK);
  868. break;
  869. }
  870. *Count = g_DataObjects.End / sizeof (DATAOBJECT);
  871. return (PDATAOBJECT) g_DataObjects.Buf;
  872. }
  873. #define ID_EDITMENUITEM 200
  874. BOOL
  875. CALLBACK
  876. pEditItemUIProc (
  877. HWND hdlg,
  878. UINT uMsg,
  879. WPARAM wParam,
  880. LPARAM lParam
  881. )
  882. {
  883. static PSTR * editStr;
  884. CHAR tempStr [MEMDB_MAX];
  885. switch (uMsg) {
  886. case WM_INITDIALOG:
  887. editStr = ((PSTR *) lParam);
  888. pSetDefGUIFont(hdlg);
  889. SendDlgItemMessage (hdlg, IDC_MAINEDIT, WM_SETTEXT, 0, (LPARAM)(*editStr));
  890. return FALSE;
  891. case WM_COMMAND:
  892. switch (LOWORD (wParam)) {
  893. case IDC_MAINEDIT:
  894. if (HIWORD (wParam) == EN_CHANGE) {
  895. if (*editStr) {
  896. FreePathString (*editStr);
  897. *editStr = NULL;
  898. }
  899. SendDlgItemMessage (hdlg, IDC_MAINEDIT, WM_GETTEXT, MEMDB_MAX, (LPARAM)tempStr);
  900. *editStr = DuplicatePathString (tempStr, 0);
  901. }
  902. break;
  903. case IDOK:
  904. EndDialog (hdlg, LOWORD (wParam));
  905. break;
  906. case IDCANCEL:
  907. case ID_QUIT:
  908. EndDialog (hdlg, LOWORD (wParam));
  909. break;
  910. }
  911. break;
  912. }
  913. return FALSE;
  914. }
  915. BOOL
  916. Handle_RMouse (
  917. IN HINSTANCE LocalDllInstance,
  918. IN HWND Owner,
  919. IN PDATAOBJECT DataObject,
  920. IN PPOINT pt
  921. )
  922. {
  923. PITEM_INFO info;
  924. TCHAR buffer [MEMDB_MAX];
  925. PVERSION_DATA p;
  926. UINT versionIdx;
  927. HMENU menu;
  928. PSTR newVersion;
  929. info = (PITEM_INFO) DataObject->DllParam;
  930. p = g_ToolVersionData;
  931. versionIdx = 0;
  932. while (p->VersionName) {
  933. if (versionIdx == info->VersionIndex) {
  934. break;
  935. }
  936. versionIdx ++;
  937. p ++;
  938. }
  939. if (!p->VersionName) {
  940. return FALSE;
  941. }
  942. if (!p->Modifiable) {
  943. return FALSE;
  944. }
  945. menu = CreatePopupMenu ();
  946. AppendMenu (menu, MF_STRING, ID_EDITMENUITEM, "Edit");
  947. if (TrackPopupMenu (menu, TPM_RETURNCMD | TPM_LEFTALIGN | TPM_TOPALIGN, pt->x, pt->y, 0, Owner, NULL) == ID_EDITMENUITEM) {
  948. newVersion = DuplicatePathString (info->VersionValue, 0);
  949. if (DialogBoxParam (LocalDllInstance, MAKEINTRESOURCE(IDD_EDITITEM), NULL, pEditItemUIProc, (LPARAM)(&newVersion)) == IDOK) {
  950. FreePathString (DataObject->NameOrPath);
  951. PoolMemReleaseMemory (g_DataObjectPool, (PVOID)info->VersionValue);
  952. info->VersionValue = PoolMemDuplicateString (g_DataObjectPool, newVersion);
  953. sprintf (buffer, "%s - %s", p->DisplayName, newVersion);
  954. DataObject->NameOrPath = DuplicatePathString (buffer, 0);
  955. return TRUE;
  956. }
  957. FreePathString (newVersion);
  958. }
  959. return FALSE;
  960. }
  961. PSTR
  962. pGetRelativePath (
  963. IN PCSTR MainFile,
  964. IN PCSTR AddnlFile
  965. )
  966. {
  967. UINT Index = 0;
  968. PCSTR p,q;
  969. CHAR result [MEMDB_MAX] = "";
  970. PSTR resultIdx = result;
  971. p = _mbschr (MainFile, '\\');
  972. q = _mbschr (AddnlFile, '\\');
  973. while (p && q) {
  974. if ((p - MainFile) != (q - AddnlFile)) {
  975. break;
  976. }
  977. if (!StringIMatchByteCount (MainFile, AddnlFile, p - MainFile)) {
  978. break;
  979. }
  980. if (!StringIMatchByteCount (MainFile, AddnlFile, q - AddnlFile)) {
  981. break;
  982. }
  983. Index += (p - MainFile);
  984. MainFile = _mbsinc (p);
  985. AddnlFile = _mbsinc (q);
  986. p = _mbschr (MainFile, '\\');
  987. q = _mbschr (AddnlFile, '\\');
  988. }
  989. if (Index > 0) {
  990. while (p) {
  991. StringCopy (resultIdx, "..\\");
  992. resultIdx = GetEndOfString (resultIdx);
  993. MainFile = _mbsinc (p);
  994. p = _mbschr (MainFile, '\\');
  995. }
  996. StringCopy (resultIdx, AddnlFile);
  997. return (DuplicatePathString (result, 0));
  998. }
  999. return NULL;
  1000. }
  1001. BOOL
  1002. pFilesAttribOutput_MigDb (
  1003. IN HANDLE File,
  1004. IN POUTPUTARGS Args
  1005. )
  1006. {
  1007. PITEM_INFO info;
  1008. UINT sectCount;
  1009. CHAR sectName [MEMDB_MAX];
  1010. PSTR relPath;
  1011. MULTISZ_ENUM multiSzEnum;
  1012. PDATAOBJECT Data = NULL;
  1013. switch (g_AppProblem) {
  1014. case APPTYPE_INC_NOBLOCK:
  1015. case APPTYPE_INC_HARDBLOCK:
  1016. WizardWriteRealString (File, "[Incompatible]\r\n");
  1017. break;
  1018. case APPTYPE_MINORPROBLEM:
  1019. WizardWriteRealString (File, "[MinorProblems]\r\n");
  1020. break;
  1021. case APPTYPE_REINSTALL:
  1022. WizardWriteRealString (File, "[Reinstall]\r\n");
  1023. break;
  1024. default:
  1025. MessageBox (NULL, "Internal BadApps DLL error:00006. Please contact calinn.", "Error", MB_OK);
  1026. }
  1027. WizardWriteQuotedColumn (File, Args->OptionalDescription, 30);
  1028. if (g_AppProblem == APPTYPE_MINORPROBLEM) {
  1029. WizardWriteRealString (File, ", %");
  1030. WizardWriteInfString (File, Args->OptionalDescription, FALSE, FALSE, TRUE, '_', 0);
  1031. WizardWriteRealString (File, "%");
  1032. }
  1033. if (g_AddnlFiles.Buf) {
  1034. // we have additional files. We will create as many sections as needed.
  1035. Data = (PDATAOBJECT) g_DataObjects.Buf;
  1036. WizardWriteRealString (File, ", ");
  1037. WizardWriteRealString (File, GetFileNameFromPath (g_MainFile));
  1038. while ((DWORD)Data < (DWORD)g_DataObjects.Buf + g_DataObjects.End) {
  1039. if (Data->Flags & DOF_SELECTED) {
  1040. info = (PITEM_INFO)Data->DllParam;
  1041. if (StringIMatch (g_MainFile, info->FilePath)) {
  1042. WizardWriteRealString (File, ", ");
  1043. WizardWriteRealString (File, g_ToolVersionData[info->VersionIndex].VersionName);
  1044. WizardWriteRealString (File, "(");
  1045. WizardWriteInfString (File, info->VersionValue, TRUE, FALSE, FALSE, 0, 0);
  1046. WizardWriteRealString (File, ")");
  1047. }
  1048. }
  1049. Data++;
  1050. }
  1051. sectCount = 1;
  1052. if (EnumFirstMultiSz (&multiSzEnum, g_AddnlFiles.Buf)) {
  1053. do {
  1054. sprintf (sectName, "REQFILE(%s.Req%d)", Args->OptionalDescription, sectCount);
  1055. WizardWriteRealString (File, ", ");
  1056. WizardWriteInfString (File, sectName, FALSE, FALSE, TRUE, '_', 0);
  1057. sectCount ++;
  1058. } while (EnumNextMultiSz (&multiSzEnum));
  1059. }
  1060. WizardWriteRealString (File, "\r\n");
  1061. WizardWriteRealString (File, "\r\n");
  1062. sectCount = 1;
  1063. if (EnumFirstMultiSz (&multiSzEnum, g_AddnlFiles.Buf)) {
  1064. do {
  1065. sprintf (sectName, "[%s.Req%d]\r\n", Args->OptionalDescription, sectCount);
  1066. WizardWriteInfString (File, sectName, FALSE, FALSE, TRUE, '_', 0);
  1067. relPath = pGetRelativePath (g_MainFile, multiSzEnum.CurrentString);
  1068. if (!relPath) {
  1069. sprintf (sectName, "Could not get relative path for:%s)", multiSzEnum.CurrentString);
  1070. MessageBox (NULL, sectName, "Error", MB_OK);
  1071. relPath = DuplicatePathString (multiSzEnum.CurrentString, 0);
  1072. }
  1073. WizardWriteRealString (File, relPath);
  1074. FreePathString (relPath);
  1075. Data = (PDATAOBJECT) g_DataObjects.Buf;
  1076. while ((DWORD)Data < (DWORD)g_DataObjects.Buf + g_DataObjects.End) {
  1077. if (Data->Flags & DOF_SELECTED) {
  1078. info = (PITEM_INFO)Data->DllParam;
  1079. if (StringIMatch (multiSzEnum.CurrentString, info->FilePath)) {
  1080. WizardWriteRealString (File, ", ");
  1081. WizardWriteRealString (File, g_ToolVersionData[info->VersionIndex].VersionName);
  1082. WizardWriteRealString (File, "(");
  1083. WizardWriteInfString (File, info->VersionValue, TRUE, FALSE, FALSE, 0, 0);
  1084. WizardWriteRealString (File, ")");
  1085. }
  1086. }
  1087. Data++;
  1088. }
  1089. WizardWriteRealString (File, "\r\n");
  1090. WizardWriteRealString (File, "\r\n");
  1091. sectCount ++;
  1092. } while (EnumNextMultiSz (&multiSzEnum));
  1093. }
  1094. } else {
  1095. // we have only one file. We will write it in the same line.
  1096. Data = (PDATAOBJECT) g_DataObjects.Buf;
  1097. WizardWriteRealString (File, ", ");
  1098. WizardWriteRealString (File, GetFileNameFromPath (g_MainFile));
  1099. while ((DWORD)Data < (DWORD)g_DataObjects.Buf + g_DataObjects.End) {
  1100. if (Data->Flags & DOF_SELECTED) {
  1101. info = (PITEM_INFO)Data->DllParam;
  1102. WizardWriteRealString (File, ", ");
  1103. WizardWriteRealString (File, g_ToolVersionData[info->VersionIndex].VersionName);
  1104. WizardWriteRealString (File, "(");
  1105. WizardWriteInfString (File, info->VersionValue, TRUE, FALSE, FALSE, 0, 0);
  1106. WizardWriteRealString (File, ")");
  1107. }
  1108. Data++;
  1109. }
  1110. WizardWriteRealString (File, "\r\n");
  1111. WizardWriteRealString (File, "\r\n");
  1112. }
  1113. if (g_AppProblem == APPTYPE_MINORPROBLEM) {
  1114. WizardWriteRealString (File, "[Strings]\r\n");
  1115. WizardWriteInfString (File, Args->OptionalDescription, FALSE, FALSE, TRUE, '_', 0);
  1116. WizardWriteRealString (File, "=");
  1117. WizardWriteInfString (File, Args->OptionalText, TRUE, TRUE, FALSE, 0, 0);
  1118. WizardWriteRealString (File, "\r\n");
  1119. WizardWriteRealString (File, "\r\n");
  1120. }
  1121. return TRUE;
  1122. }
  1123. BOOL
  1124. pWriteBlob (
  1125. IN HANDLE File,
  1126. IN PBYTE Data,
  1127. IN DWORD Size,
  1128. IN DWORD LineLen
  1129. )
  1130. {
  1131. CHAR result[4];
  1132. DWORD lineLen = 0;
  1133. while (Size>1) {
  1134. sprintf (result, "%02X,", *Data);
  1135. WizardWriteRealString (File, result);
  1136. lineLen += 3;
  1137. if (lineLen >= LineLen) {
  1138. WizardWriteRealString (File, "\\\r\n");
  1139. lineLen = 0;
  1140. }
  1141. Size --;
  1142. Data ++;
  1143. }
  1144. if (Size) {
  1145. sprintf (result, "%02X", *Data);
  1146. WizardWriteRealString (File, result);
  1147. }
  1148. return TRUE;
  1149. }
  1150. BOOL
  1151. pFilesAttribOutput_BadApps (
  1152. IN HANDLE File,
  1153. IN POUTPUTARGS Args
  1154. )
  1155. {
  1156. PSTR fullKey;
  1157. GROWBUFFER Buffer = GROWBUF_INIT;
  1158. BADAPP_PROP appProp;
  1159. PDATAOBJECT DataObject = NULL;
  1160. PITEM_INFO info;
  1161. PVERSION_DATA p;
  1162. UINT versionIdx;
  1163. PBYTE Data;
  1164. DWORD DataSize;
  1165. DWORD TotalSize = 0;
  1166. MULTISZ_ENUM multiSzEnum;
  1167. PSTR relPath;
  1168. CHAR tmpStr[MEMDB_MAX];
  1169. WizardWriteRealString (File, "HKLM,");
  1170. fullKey = JoinPaths ("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\AppCompatibility", GetFileNameFromPath (g_MainFile));
  1171. WizardWriteQuotedColumn (File, fullKey, 0);
  1172. FreePathString (fullKey);
  1173. WizardWriteRealString (File, ",");
  1174. WizardWriteQuotedColumn (File, "Sequencer", 0);
  1175. WizardWriteRealString (File, ",0x00030003,\\\r\n");
  1176. //now it's a good time to generate the BLOB
  1177. //first thing - add data about MsgId and the app problem
  1178. appProp.Size = sizeof (BADAPP_PROP);
  1179. appProp.MsgId = g_MsgId;
  1180. appProp.AppType = 0;
  1181. appProp.AppType = g_AppProblem | g_AppFlags;
  1182. CopyMemory (GrowBuffer (&Buffer, sizeof (BADAPP_PROP)), &appProp, sizeof (BADAPP_PROP));
  1183. TotalSize += sizeof (BADAPP_PROP);
  1184. //next - add data about main file attributes
  1185. DataObject = (PDATAOBJECT) g_DataObjects.Buf;
  1186. while ((DWORD)DataObject < (DWORD)g_DataObjects.Buf + g_DataObjects.End) {
  1187. if (DataObject->Flags & DOF_SELECTED) {
  1188. info = (PITEM_INFO)DataObject->DllParam;
  1189. if (StringIMatch (g_MainFile, info->FilePath)) {
  1190. p = g_ToolVersionData;
  1191. versionIdx = 0;
  1192. while (p->VersionName) {
  1193. if (versionIdx == info->VersionIndex) {
  1194. break;
  1195. }
  1196. versionIdx ++;
  1197. p ++;
  1198. }
  1199. if (p->VersionName) {
  1200. if (p->VersionOutput (info->VersionValue, &DataSize, &Data)) {
  1201. CopyMemory (GrowBuffer (&Buffer, sizeof (DWORD)), &(p->VersionId), sizeof (DWORD));
  1202. TotalSize += sizeof (DWORD);
  1203. CopyMemory (GrowBuffer (&Buffer, sizeof (DWORD)), &DataSize, sizeof (DWORD));
  1204. TotalSize += sizeof (DWORD);
  1205. CopyMemory (GrowBuffer (&Buffer, DataSize), Data, DataSize);
  1206. TotalSize += DataSize;
  1207. MemFree (g_hHeap, 0, Data);
  1208. }
  1209. }
  1210. }
  1211. }
  1212. DataObject++;
  1213. }
  1214. if (g_AddnlFiles.Buf) {
  1215. // we have additional files. We will create as many sections as needed.
  1216. if (EnumFirstMultiSz (&multiSzEnum, g_AddnlFiles.Buf)) {
  1217. do {
  1218. relPath = pGetRelativePath (g_MainFile, multiSzEnum.CurrentString);
  1219. if (!relPath) {
  1220. sprintf (tmpStr, "Could not get relative path for:%s)", multiSzEnum.CurrentString);
  1221. MessageBox (NULL, tmpStr, "Error", MB_OK);
  1222. relPath = DuplicatePathString (multiSzEnum.CurrentString, 0);
  1223. }
  1224. // now let's write the addnl file in UNICODE
  1225. DataSize = VTID_REQFILE;
  1226. CopyMemory (GrowBuffer (&Buffer, sizeof (DWORD)), &DataSize, sizeof (DWORD));
  1227. TotalSize += sizeof (DWORD);
  1228. OutputStrValue (relPath, &DataSize, &Data);
  1229. CopyMemory (GrowBuffer (&Buffer, sizeof (DWORD)), &DataSize, sizeof (DWORD));
  1230. TotalSize += sizeof (DWORD);
  1231. CopyMemory (GrowBuffer (&Buffer, DataSize), Data, DataSize);
  1232. TotalSize += DataSize;
  1233. MemFree (g_hHeap, 0, Data);
  1234. DataObject = (PDATAOBJECT) g_DataObjects.Buf;
  1235. while ((DWORD)DataObject < (DWORD)g_DataObjects.Buf + g_DataObjects.End) {
  1236. if (DataObject->Flags & DOF_SELECTED) {
  1237. info = (PITEM_INFO)DataObject->DllParam;
  1238. if (StringIMatch (multiSzEnum.CurrentString, info->FilePath)) {
  1239. p = g_ToolVersionData;
  1240. versionIdx = 0;
  1241. while (p->VersionName) {
  1242. if (versionIdx == info->VersionIndex) {
  1243. break;
  1244. }
  1245. versionIdx ++;
  1246. p ++;
  1247. }
  1248. if (p->VersionName) {
  1249. if (p->VersionOutput (info->VersionValue, &DataSize, &Data)) {
  1250. CopyMemory (GrowBuffer (&Buffer, sizeof (DWORD)), &(p->VersionId), sizeof (DWORD));
  1251. TotalSize += sizeof (DWORD);
  1252. CopyMemory (GrowBuffer (&Buffer, sizeof (DWORD)), &DataSize, sizeof (DWORD));
  1253. TotalSize += sizeof (DWORD);
  1254. CopyMemory (GrowBuffer (&Buffer, DataSize), Data, DataSize);
  1255. TotalSize += DataSize;
  1256. MemFree (g_hHeap, 0, Data);
  1257. }
  1258. }
  1259. }
  1260. }
  1261. DataObject++;
  1262. }
  1263. } while (EnumNextMultiSz (&multiSzEnum));
  1264. }
  1265. }
  1266. DataSize = 0;
  1267. CopyMemory (GrowBuffer (&Buffer, sizeof (DWORD)), &DataSize, sizeof (DWORD));
  1268. TotalSize += sizeof (DWORD);
  1269. //now it's a good time to write the BLOB
  1270. pWriteBlob (File, Buffer.Buf, TotalSize, 80);
  1271. return TRUE;
  1272. }
  1273. BOOL
  1274. GenerateOutput (
  1275. IN POUTPUTARGS Args
  1276. )
  1277. {
  1278. BOOL b = FALSE;
  1279. HANDLE File;
  1280. CHAR Path[MAX_MBCHAR_PATH];
  1281. switch (Args->DataTypeId) {
  1282. case 0:
  1283. // bad apps
  1284. wsprintf (Path, "%s\\badapps.txt", Args->OutboundDir);
  1285. break;
  1286. default:
  1287. MessageBox (NULL, "Internal BadApps DLL error:00002. Please contact calinn.", "Error", MB_OK);
  1288. }
  1289. printf ("Saving data to %s\n\n", Path);
  1290. File = CreateFile (
  1291. Path,
  1292. GENERIC_WRITE,
  1293. 0,
  1294. NULL,
  1295. OPEN_ALWAYS,
  1296. FILE_ATTRIBUTE_NORMAL,
  1297. NULL
  1298. );
  1299. if (File == INVALID_HANDLE_VALUE) {
  1300. printf ("Can't open file for output.\n");
  1301. return FALSE;
  1302. }
  1303. __try {
  1304. SetFilePointer (File, 0, NULL, FILE_END);
  1305. //
  1306. // Write user name and date/time
  1307. //
  1308. if (!WriteHeader (File)) {
  1309. __leave;
  1310. }
  1311. switch (Args->DataTypeId) {
  1312. case 0:
  1313. // bad apps
  1314. if (g_SaveMigDb) {
  1315. b = pFilesAttribOutput_MigDb (File, Args);
  1316. } else {
  1317. b = TRUE;
  1318. }
  1319. b = b && pFilesAttribOutput_BadApps (File, Args);
  1320. break;
  1321. default:
  1322. MessageBox (NULL, "Internal BadApps DLL error:00003. Please contact calinn.", "Error", MB_OK);
  1323. }
  1324. //
  1325. // Write a final blank line
  1326. //
  1327. b = b && WizardWriteRealString (File, "\r\n");
  1328. }
  1329. __finally {
  1330. CloseHandle (File);
  1331. }
  1332. return b;
  1333. }
  1334. BOOL
  1335. DisplayOptionalUI (
  1336. IN POUTPUTARGS Args
  1337. )
  1338. {
  1339. switch (Args->DataTypeId) {
  1340. case 0:
  1341. if (g_AppProblem == APPTYPE_MINORPROBLEM) {
  1342. g_DataTypes[Args->DataTypeId].Flags |= (DTF_REQUIRE_TEXT);
  1343. }
  1344. break;
  1345. default:
  1346. MessageBox (NULL, "Internal BadApps DLL error:00005. Please contact calinn.", "Error", MB_OK);
  1347. }
  1348. return TRUE;
  1349. }