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.

2704 lines
67 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File: write.cpp
  4. //
  5. // History: 16-Nov-00 markder Created.
  6. //
  7. // Desc: This file contains all code needed to create SDB files
  8. // from the SdbDatabase internal C++ object.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////////
  11. #include "StdAfx.h"
  12. #include "make.h"
  13. DWORD g_dwCurrentWriteFilter = SDB_FILTER_INCLUDE_ALL;
  14. DATE g_dtCurrentWriteRevisionCutoff = 0;
  15. ////////////////////////////////////////////////////////////////////////////////////
  16. //
  17. // Func: GetUniqueCount
  18. //
  19. // Desc: Returns the count of unique index entries given an "ordered"
  20. // array of exes
  21. //
  22. DWORD GetUniqueCount(SdbRefArray<SdbExe>* prgExes, DWORD dwFilter, DATE dtRevisionCutoff, BOOL bWildCard)
  23. {
  24. int i;
  25. SdbExe* pExe;
  26. DWORD dwCount = 0;
  27. ULONGLONG ullKey = 0;
  28. for (i = 0; i < prgExes->GetSize(); ++i) {
  29. pExe = (SdbExe*)prgExes->GetAt(i);
  30. if (!(pExe->m_bWildcardInName ^ bWildCard)) { // XOR is 1 if the args are different and
  31. // is 0 if the args are the same
  32. if ((pExe->m_dwFilter & dwFilter) &&
  33. dtRevisionCutoff <= pExe->m_dtLastRevision) {
  34. if (ullKey != pExe->m_ullKey) {
  35. ullKey = pExe->m_ullKey;
  36. ++dwCount;
  37. }
  38. }
  39. }
  40. }
  41. return dwCount;
  42. }
  43. BOOL WriteDatabase(
  44. SdbOutputFile* pOutputFile,
  45. SdbDatabase* pDatabase)
  46. {
  47. BOOL bSuccess = FALSE;
  48. PDB pdb = NULL;
  49. pdb = SdbCreateDatabase(pOutputFile->m_csName, DOS_PATH);
  50. if (pdb == NULL) {
  51. SDBERROR_FORMAT((_T("Error creating database \"%s\".\n"), pOutputFile->m_csName));
  52. goto eh;
  53. }
  54. pDatabase->m_Library.SanitizeTagIDs();
  55. if (!pDatabase->WriteToSDB(pdb)) {
  56. SDBERROR_PROPOGATE();
  57. goto eh;
  58. }
  59. bSuccess = TRUE;
  60. eh:
  61. if (pdb) {
  62. SdbCloseDatabase(pdb);
  63. }
  64. if (bSuccess == FALSE) {
  65. //
  66. // We need to delete the .SDB that has been created. We had an error
  67. // but shimdbc has made the .SDB for the XML till it hit the error. This is typically
  68. // in the case when we hit a tag in the summary part of a XML for a custom SDB
  69. // that is not allowed in the summary part. For e.g if we have
  70. // *********************************************************************
  71. // <LIBRARY>
  72. // <MESSAGE NAME="1" ID="{5DE255AF-350F-4A94-896E-249561039F13}">
  73. // <SUMMARY>
  74. // <B>sd</B>
  75. // </SUMMARY>
  76. // </MESSAGE>
  77. // </LIBRARY>
  78. //
  79. //**********************************************************************
  80. // Such an .SDB is an invalid .SDB and should be removed
  81. //
  82. DeleteFile(pOutputFile->GetFullPath());
  83. }
  84. return bSuccess;
  85. }
  86. VOID SdbLibrary::SanitizeTagIDs(VOID)
  87. {
  88. INT i;
  89. for (i = 0; i < m_rgShims.GetSize(); ++i) {
  90. SdbShim* pShim = (SdbShim*)m_rgShims.GetAt(i);
  91. pShim->m_tiTagID = TAGID_NULL;
  92. }
  93. for (i = 0; i < m_rgPatches.GetSize(); ++i) {
  94. SdbPatch* pPatch = (SdbPatch*)m_rgPatches.GetAt(i);
  95. pPatch->m_tiTagID = TAGID_NULL;
  96. }
  97. for (i = 0; i < m_rgLayers.GetSize(); ++i) {
  98. SdbLayer* pLayer = (SdbLayer*)m_rgLayers.GetAt(i);
  99. pLayer->m_tiTagID = TAGID_NULL;
  100. }
  101. for (i = 0; i < m_rgFiles.GetSize(); ++i) {
  102. SdbFile* pFile = (SdbFile*)m_rgFiles.GetAt(i);
  103. pFile->m_tiTagID = TAGID_NULL;
  104. }
  105. for (i = 0; i < m_rgMsiTransforms.GetSize(); ++i) {
  106. SdbMsiTransform* pTransform = (SdbMsiTransform*)m_rgMsiTransforms.GetAt(i);
  107. pTransform->m_tiTagID = TAGID_NULL;
  108. }
  109. }
  110. BOOL SdbDatabase::WriteToSDB(PDB pdb)
  111. {
  112. BOOL bSuccess = FALSE;
  113. BOOL bAtLeastOneIndex = FALSE;
  114. TAGID tiDatabase;
  115. FILETIME ftBuildStamp;
  116. LARGE_INTEGER liBuildStamp;
  117. DWORD dwHTMLHelpID;
  118. LANGID langID;
  119. DWORD dwUniqueCount = 0;
  120. long i, j;
  121. SdbAppHelp* pAppHelp;
  122. SdbMessage* pMessage;
  123. CString csURL, csLinkText, csContactInfo;
  124. CString csAppTitle, csSummary, csDetails, csID, csDBName;
  125. CString csLanguagesParam, csLangID;
  126. CStringArray rgLanguages;
  127. csLanguagesParam = m_pCurrentOutputFile->GetParameter(_T("LANGUAGES"));
  128. if (csLanguagesParam.GetLength()) {
  129. if (!ParseLanguagesString(csLanguagesParam, &rgLanguages)) {
  130. SDBERROR_FORMAT((_T("Error parsing LANGUAGES parameter in makefile: %s\n"), csLanguagesParam));
  131. goto eh;
  132. }
  133. } else {
  134. rgLanguages.Add(m_pCurrentMakefile->m_csLangID);
  135. }
  136. //
  137. // Allocate indexes
  138. //
  139. dwUniqueCount = GetUniqueCount(&m_rgExes, m_pCurrentOutputFile->m_dwFilter, g_dtCurrentWriteRevisionCutoff, FALSE);
  140. if (m_pCurrentOutputFile->m_dwFilter & (SDB_FILTER_FIX | SDB_FILTER_DRIVER)) {
  141. if (!SdbDeclareIndex(pdb, TAG_EXE, TAG_NAME, dwUniqueCount, TRUE, &m_iiExeIndex)) {
  142. SDBERROR(_T("Error declaring index for Exes.\n"));
  143. goto eh;
  144. }
  145. bAtLeastOneIndex = TRUE;
  146. }
  147. if (m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_FIX) {
  148. if (!SdbDeclareIndex(pdb,
  149. TAG_EXE,
  150. TAG_WILDCARD_NAME,
  151. (DWORD)m_rgWildcardExes.GetFilteredCount(m_pCurrentOutputFile->m_dwFilter, g_dtCurrentWriteRevisionCutoff),
  152. FALSE,
  153. &m_iiWildcardExeIndex)) {
  154. SDBERROR(_T("Error declaring index for wildcard Exes.\n"));
  155. goto eh;
  156. }
  157. if (!SdbDeclareIndex(pdb,
  158. TAG_EXE,
  159. TAG_16BIT_MODULE_NAME,
  160. (DWORD)m_rgModuleExes.GetFilteredCount(m_pCurrentOutputFile->m_dwFilter, g_dtCurrentWriteRevisionCutoff),
  161. FALSE,
  162. &m_iiModuleExeIndex)) {
  163. SDBERROR(_T("Error declaring index for wildcard Exes.\n"));
  164. goto eh;
  165. }
  166. if (!SdbDeclareIndex(pdb,
  167. TAG_SHIM,
  168. TAG_NAME,
  169. (DWORD)m_Library.m_rgShims.GetFilteredCount(m_pCurrentOutputFile->m_dwFilter, 0),
  170. FALSE,
  171. &m_iiShimIndex)) {
  172. SDBERROR(_T("Error declaring index for Shims.\n"));
  173. goto eh;
  174. }
  175. bAtLeastOneIndex = TRUE;
  176. }
  177. if (m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_APPHELP) {
  178. if (!SdbDeclareIndex(pdb,
  179. TAG_APPHELP,
  180. TAG_HTMLHELPID,
  181. (DWORD) (m_rgAppHelps.GetFilteredCount(m_pCurrentOutputFile->m_dwFilter, g_dtCurrentWriteRevisionCutoff)
  182. * rgLanguages.GetSize()),
  183. FALSE,
  184. &m_iiHtmlHelpID)) {
  185. SDBERROR(_T("Error declaring index for HTMLHELPID\n"));
  186. goto eh;
  187. }
  188. bAtLeastOneIndex = TRUE;
  189. }
  190. if (m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_MSI) {
  191. //
  192. // MSI_TRANSFORM index, unique style (it's more efficient) - these are "fixes"
  193. //
  194. if (!SdbDeclareIndex(pdb,
  195. TAG_MSI_TRANSFORM,
  196. TAG_NAME,
  197. (DWORD)m_Library.m_rgMsiTransforms.GetFilteredCount(m_pCurrentOutputFile->m_dwFilter, g_dtCurrentWriteRevisionCutoff),
  198. TRUE,
  199. &m_iiMsiTransformIndex)) {
  200. SDBERROR(_T("Error declaring index for MSI Transforms.\n"));
  201. goto eh;
  202. }
  203. //
  204. // MSI_PACKAGE index, unique style (it's more efficient, again)
  205. //
  206. if (!SdbDeclareIndex(pdb,
  207. TAG_MSI_PACKAGE,
  208. TAG_MSI_PACKAGE_ID,
  209. m_rgMsiPackages.GetFilteredCount(m_pCurrentOutputFile->m_dwFilter, g_dtCurrentWriteRevisionCutoff),
  210. FALSE,
  211. &m_iiMsiPackageIndex)) {
  212. SDBERROR(_T("Error declaring index for MSI Packages.\n"));
  213. goto eh;
  214. }
  215. if (!SdbDeclareIndex(pdb,
  216. TAG_MSI_PACKAGE,
  217. TAG_EXE_ID,
  218. m_rgMsiPackages.GetFilteredCount(m_pCurrentOutputFile->m_dwFilter, g_dtCurrentWriteRevisionCutoff),
  219. TRUE,
  220. &m_iiMsiIDIndex)) {
  221. SDBERROR(_T("Error declaring index for MSI Exe IDs.\n"));
  222. goto eh;
  223. }
  224. bAtLeastOneIndex = TRUE;
  225. }
  226. if (m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_DRIVER) {
  227. if (!SdbDeclareIndex(pdb,
  228. TAG_EXE,
  229. TAG_EXE_ID,
  230. m_rgExes.GetFilteredCount(m_pCurrentOutputFile->m_dwFilter, g_dtCurrentWriteRevisionCutoff),
  231. FALSE,
  232. &m_iiDrvIDIndex)) {
  233. SDBERROR(_T("Error declaring index for DRIVER ID\n"));
  234. goto eh;
  235. }
  236. bAtLeastOneIndex = TRUE;
  237. }
  238. if (bAtLeastOneIndex) {
  239. if (!SdbCommitIndexes(pdb)) {
  240. SDBERROR(_T("Error ending index declarations.\n"));
  241. goto eh;
  242. }
  243. }
  244. //
  245. // Open tag
  246. //
  247. tiDatabase = SdbBeginWriteListTag(pdb, TAG_DATABASE);
  248. if (!tiDatabase) {
  249. SDBERROR(_T("Error writing DATABASE tag\n"));
  250. goto eh;
  251. }
  252. //
  253. // Stamp the build time
  254. //
  255. GetSystemTimeAsFileTime(&ftBuildStamp);
  256. liBuildStamp.LowPart = ftBuildStamp.dwLowDateTime;
  257. liBuildStamp.HighPart = ftBuildStamp.dwHighDateTime;
  258. if (!SdbWriteQWORDTag(pdb, TAG_TIME, liBuildStamp.QuadPart)) {
  259. SDBERROR(_T("Error writing TIME\n"));
  260. goto eh;
  261. }
  262. //
  263. // Stamp the compiler version
  264. //
  265. if (!SdbWriteStringTag(pdb, TAG_COMPILER_VERSION, g_szVersion)) {
  266. SDBERROR(_T("Error writing COMPILER_VERSION\n"));
  267. goto eh;
  268. }
  269. //
  270. // Look for name from makefile
  271. //
  272. csDBName = m_pDB->m_pCurrentOutputFile->GetParameter(_T("DATABASE NAME"));
  273. if (csDBName.IsEmpty()) {
  274. csDBName = m_csName;
  275. }
  276. //
  277. // Write the name of the database
  278. //
  279. if (!SdbWriteStringTag(pdb, TAG_NAME, csDBName)) {
  280. SDBERROR(_T("Error writing TAG_NAME\n"));
  281. goto eh;
  282. }
  283. //
  284. // Look for GUID from makefile
  285. //
  286. csID = m_pDB->m_pCurrentOutputFile->GetParameter(_T("DATABASE ID"));
  287. if (csID.GetLength()) {
  288. if (!GUIDFromString(csID, &m_CurrentDBID)) {
  289. SDBERROR_FORMAT((_T("Bad GUID specified for DATABASE_ID: %s\n"), csID));
  290. goto eh;
  291. }
  292. } else {
  293. //
  294. // Not there, take the ID from the XML file
  295. //
  296. m_CurrentDBID = m_ID;
  297. }
  298. //
  299. // Write the GUID
  300. //
  301. if (!SdbWriteBinaryTag(pdb, TAG_DATABASE_ID, (PBYTE)&m_CurrentDBID, sizeof(m_CurrentDBID))) {
  302. SDBERROR(_T("Error writing TAG_DATABASE_ID\n"));
  303. goto eh;
  304. }
  305. if (m_pCurrentOutputFile->m_dwFilter & ~SDB_FILTER_DRIVER) {
  306. //
  307. // Write the Library
  308. //
  309. if (!m_Library.WriteToSDB(pdb)) {
  310. SDBERROR_PROPOGATE();
  311. goto eh;
  312. }
  313. }
  314. //
  315. // Action
  316. //
  317. if (!m_rgAction.WriteToSDB(pdb)) {
  318. SDBERROR_PROPOGATE();
  319. goto eh;
  320. }
  321. if (m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_FIX) {
  322. //
  323. // First write all the EXEs with wild-card names
  324. //
  325. if (!SdbStartIndexing(pdb, m_iiWildcardExeIndex)) {
  326. SDBERROR(_T("Error starting to index wildcard Exes.\n"));
  327. goto eh;
  328. }
  329. //
  330. // Wildcard Exes
  331. //
  332. if (!m_rgWildcardExes.WriteToSDB(pdb)) {
  333. SDBERROR_PROPOGATE();
  334. goto eh;
  335. }
  336. //
  337. // Done indexing the wildcard exes
  338. //
  339. if (!SdbStopIndexing(pdb, m_iiWildcardExeIndex)) {
  340. SDBERROR(_T("Error stopping indexing wildcard Exes.\n"));
  341. goto eh;
  342. }
  343. //
  344. // Next write all the EXEs with module names
  345. //
  346. if (!SdbStartIndexing(pdb, m_iiModuleExeIndex)) {
  347. SDBERROR(_T("Error starting to index Module Exes.\n"));
  348. goto eh;
  349. }
  350. //
  351. // Module Exes
  352. //
  353. if (!m_rgModuleExes.WriteToSDB(pdb)) {
  354. SDBERROR_PROPOGATE();
  355. goto eh;
  356. }
  357. //
  358. // Done indexing the module exes
  359. //
  360. if (!SdbStopIndexing(pdb, m_iiModuleExeIndex)) {
  361. SDBERROR(_T("Error stopping indexing Module Exes.\n"));
  362. goto eh;
  363. }
  364. }
  365. if (m_pCurrentOutputFile->m_dwFilter & (SDB_FILTER_FIX | SDB_FILTER_DRIVER)) {
  366. //
  367. // Go ahead and start indexing normal exes
  368. //
  369. if (!SdbStartIndexing(pdb, m_iiExeIndex)) {
  370. SDBERROR(_T("Error starting to index Exes.\n"));
  371. goto eh;
  372. }
  373. if (m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_DRIVER) {
  374. if (!SdbStartIndexing(pdb, m_iiDrvIDIndex)) {
  375. SDBERROR(_T("Error starting to index driver IDs\n"));
  376. goto eh;
  377. }
  378. }
  379. if (!m_rgExes.WriteToSDB(pdb)) {
  380. SDBERROR_PROPOGATE();
  381. goto eh;
  382. }
  383. if (m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_DRIVER) {
  384. if (!SdbStopIndexing(pdb, m_iiDrvIDIndex)) {
  385. SDBERROR(_T("Error stopping indexing driver IDs\n"));
  386. goto eh;
  387. }
  388. }
  389. //
  390. // Done indexing the exes
  391. //
  392. if (!SdbStopIndexing(pdb, m_iiExeIndex)) {
  393. SDBERROR(_T("Error stopping indexing Exes.\n"));
  394. goto eh;
  395. }
  396. }
  397. if (m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_MSI) {
  398. //
  399. // MSI Packages, they are just like EXEs
  400. // but indexed not by name but by their GUID IDs
  401. //
  402. if (!SdbStartIndexing(pdb, m_iiMsiPackageIndex)) {
  403. SDBERROR(_T("Error starting to index MSI Packages.\n"));
  404. goto eh;
  405. }
  406. if (!SdbStartIndexing(pdb, m_iiMsiIDIndex)) {
  407. SDBERROR(_T("Error starting to index MSI packages by exe id\n"));
  408. goto eh;
  409. }
  410. if (!m_rgMsiPackages.WriteToSDB(pdb)) {
  411. SDBERROR_PROPOGATE();
  412. goto eh;
  413. }
  414. if (!SdbStopIndexing(pdb, m_iiMsiIDIndex)) {
  415. SDBERROR(_T("Error stopping indexing of MSI packages by exe id\n"));
  416. goto eh;
  417. }
  418. if (!SdbStopIndexing(pdb, m_iiMsiPackageIndex)) {
  419. SDBERROR(_T("Error stopping indexing MSI Packages.\n"));
  420. goto eh;
  421. }
  422. }
  423. if (m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_APPHELP) {
  424. //
  425. // Start indexing apphelps
  426. //
  427. if (!SdbStartIndexing(pdb, m_iiHtmlHelpID)) {
  428. SDBERROR( _T("Error starting to index HTMLHELPID.\n"));
  429. goto eh;
  430. }
  431. for (i = 0; i < m_rgAppHelps.GetSize(); i++) {
  432. pAppHelp = (SdbAppHelp *) m_rgAppHelps[i];
  433. if (!(pAppHelp->m_dwFilter & m_pCurrentOutputFile->m_dwFilter)) {
  434. continue;
  435. }
  436. if (g_dtCurrentWriteRevisionCutoff > pAppHelp->m_dtLastRevision) {
  437. continue;
  438. }
  439. for (j = 0; j < rgLanguages.GetSize(); j++) {
  440. csLangID = rgLanguages[j];
  441. pMessage = (SdbMessage *) m_rgMessages.LookupName(pAppHelp->m_csMessage, csLangID);
  442. if (pMessage == NULL) {
  443. SDBERROR_FORMAT((_T("Localized MESSAGE not found for\n NAME: %s\n HTMLHELPID: %s\n LANG: %s\n"),
  444. pAppHelp->m_csMessage, pAppHelp->m_csName, csLangID));
  445. goto eh;
  446. }
  447. if (!ConstructMessageParts(
  448. pAppHelp,
  449. pMessage,
  450. csLangID,
  451. &dwHTMLHelpID,
  452. &csURL,
  453. &csContactInfo,
  454. &csAppTitle,
  455. &csSummary,
  456. &csDetails)) {
  457. SDBERROR_PROPOGATE();
  458. goto eh;
  459. }
  460. if (g_bStrict) {
  461. if (csURL.IsEmpty()) {
  462. SDBERROR_FORMAT((_T("ERROR: Empty string for URL on\n NAME: %s\n HTMLHELPID: %s\n LANG: %s\n\n"),
  463. pAppHelp->m_pApp->m_csName, pAppHelp->m_csName, csLangID));
  464. goto eh;
  465. }
  466. if (csAppTitle.IsEmpty()) {
  467. SDBERROR_FORMAT((_T("ERROR: Empty string for APP_TITLE on\n NAME: %s\n HTMLHELPID: %s\n LANG: %s\n\n"),
  468. pAppHelp->m_pApp->m_csName, pAppHelp->m_csName, csLangID));
  469. goto eh;
  470. }
  471. if (csSummary.IsEmpty()) {
  472. SDBERROR_FORMAT((_T("ERROR: Empty string for SUMMARY on\n NAME: %s\n HTMLHELPID: %s\n LANG: %s\n\n"),
  473. pAppHelp->m_pApp->m_csName, pAppHelp->m_csName, csLangID));
  474. goto eh;
  475. }
  476. }
  477. if (!WriteAppHelpRefTag(
  478. pdb,
  479. pAppHelp->m_csName,
  480. csLangID == _T("---") ? 0 : m_pCurrentMakefile->GetLangMap(csLangID)->m_lcid,
  481. csURL,
  482. csAppTitle,
  483. csSummary)) {
  484. SDBERROR_PROPOGATE();
  485. goto eh;
  486. }
  487. }
  488. }
  489. //
  490. // Stop indexing apphelps
  491. //
  492. if (!SdbStopIndexing(pdb, m_iiHtmlHelpID)) {
  493. SDBERROR( _T("Error stopping indexing HTMLHELPID.\n"));
  494. goto eh;
  495. }
  496. }
  497. //
  498. // Close tag
  499. //
  500. if (!SdbEndWriteListTag(pdb, tiDatabase)) {
  501. SDBERROR(_T("Error writing TAG_DATABASE\n"));
  502. goto eh;
  503. }
  504. bSuccess = TRUE;
  505. eh:
  506. return bSuccess;
  507. }
  508. BOOL SdbLibrary::WriteToSDB(PDB pdb)
  509. {
  510. BOOL bSuccess = FALSE;
  511. TAGID tiLibrary;
  512. //
  513. // Open tag
  514. //
  515. tiLibrary = SdbBeginWriteListTag(pdb, TAG_LIBRARY);
  516. if (!tiLibrary) {
  517. SDBERROR(_T("Error writing TAG_LIBRARY\n"));
  518. goto eh;
  519. }
  520. if (m_pDB->m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_FIX) {
  521. //
  522. // Global exclusion list
  523. //
  524. if (!m_rgCallers.WriteToSDB(pdb)) {
  525. SDBERROR_PROPOGATE();
  526. goto eh;
  527. }
  528. //
  529. // Index the shims
  530. //
  531. if (!SdbStartIndexing(pdb, m_pDB->m_iiShimIndex)) {
  532. SDBERROR(_T("Error starting to index Dlls.\n"));
  533. goto eh;
  534. }
  535. //
  536. // Shims
  537. //
  538. if (!m_rgShims.WriteToSDB(pdb)) {
  539. SDBERROR_PROPOGATE();
  540. goto eh;
  541. }
  542. //
  543. // Done indexing the shims
  544. //
  545. if (!SdbStopIndexing(pdb, m_pDB->m_iiShimIndex)) {
  546. SDBERROR(_T("Error stopping indexing shims.\n"));
  547. goto eh;
  548. }
  549. //
  550. // Patches
  551. //
  552. if (!m_rgPatches.WriteToSDB(pdb)) {
  553. SDBERROR_PROPOGATE();
  554. goto eh;
  555. }
  556. //
  557. // Flags
  558. //
  559. if (!m_rgFlags.WriteToSDB(pdb)) {
  560. SDBERROR_PROPOGATE();
  561. goto eh;
  562. }
  563. }
  564. //
  565. // Included files
  566. //
  567. if (!m_rgFiles.WriteToSDB(pdb)) {
  568. SDBERROR_PROPOGATE();
  569. goto eh;
  570. }
  571. if (m_pDB->m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_MSI) {
  572. //
  573. // Msi Transforms, indexed by the their respective name
  574. //
  575. if (!SdbStartIndexing(pdb, m_pDB->m_iiMsiTransformIndex)) {
  576. SDBERROR(_T("Error starting to index MSI Transforms.\n"));
  577. goto eh;
  578. }
  579. if (!m_rgMsiTransforms.WriteToSDB(pdb)) {
  580. SDBERROR_PROPOGATE();
  581. goto eh;
  582. }
  583. if (!SdbStopIndexing(pdb, m_pDB->m_iiMsiTransformIndex)) {
  584. SDBERROR(_T("Error stopping indexing MSI Transforms.\n"));
  585. goto eh;
  586. }
  587. }
  588. //
  589. // Close tag
  590. //
  591. if (!SdbEndWriteListTag(pdb, tiLibrary)) {
  592. SDBERROR(_T("Error ending TAG_LIBRARY\n"));
  593. goto eh;
  594. }
  595. if (m_pDB->m_pCurrentOutputFile->m_dwFilter & SDB_FILTER_FIX) {
  596. //
  597. // Layers
  598. //
  599. // BUGBUG: Layers should be *inside* the library
  600. //
  601. if (!m_rgLayers.WriteToSDB(pdb)) {
  602. SDBERROR_PROPOGATE();
  603. goto eh;
  604. }
  605. }
  606. bSuccess = TRUE;
  607. eh:
  608. return bSuccess;
  609. }
  610. BOOL SdbExe::WriteToSDB(PDB pdb)
  611. {
  612. BOOL bSuccess = FALSE;
  613. TAGID tiExe;
  614. long i;
  615. ULONGLONG ullFlagsNTVDM1 = 0;
  616. ULONGLONG ullFlagsNTVDM2 = 0;
  617. ULONGLONG ullFlagsNTVDM3 = 0;
  618. //
  619. // Open tag
  620. //
  621. tiExe = SdbBeginWriteListTag(pdb, TAG_EXE);
  622. if (!tiExe) {
  623. SDBERROR(_T("Error writing TAG_EXE\n"));
  624. goto eh;
  625. }
  626. //
  627. // NAME (i.e., EXE filename)
  628. //
  629. if (m_csName.GetLength()) {
  630. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  631. SDBERROR(_T("Error writing TAG_NAME\n"));
  632. goto eh;
  633. }
  634. //
  635. // If there's a wildcard in the name, write WILDCARD_NAME
  636. // as well, for the indexing
  637. //
  638. if (m_bWildcardInName) {
  639. if (!SdbWriteStringTag(pdb, TAG_WILDCARD_NAME, m_csName)) {
  640. SDBERROR(_T("Error writing TAG_WILDCARD_NAME\n"));
  641. goto eh;
  642. }
  643. }
  644. //
  645. // If this is supposed to match on module name, write that out too
  646. //
  647. if (m_bMatchOnModule) {
  648. if (!SdbWriteStringTag(pdb, TAG_16BIT_MODULE_NAME, m_csName)) {
  649. SDBERROR(_T("Error writing TAG_16BIT_MODULE_NAME\n"));
  650. goto eh;
  651. }
  652. }
  653. }
  654. //
  655. // APP_NAME (i.e., application title)
  656. //
  657. if (m_pApp != NULL) {
  658. if (m_pApp->m_csName.GetLength()) {
  659. if (!SdbWriteStringTag(pdb, TAG_APP_NAME, m_pApp->m_csName)) {
  660. SDBERROR(_T("Error writing TAG_APP_NAME\n"));
  661. goto eh;
  662. }
  663. }
  664. }
  665. //
  666. // VENDOR
  667. //
  668. if (m_pApp != NULL) {
  669. if (m_pApp->m_csVendor.GetLength()) {
  670. if (!SdbWriteStringTag(pdb, TAG_VENDOR, m_pApp->m_csVendor)) {
  671. SDBERROR(_T("Error writing TAG_VENDOR\n"));
  672. goto eh;
  673. }
  674. }
  675. }
  676. //
  677. // GUID (Unique ID)
  678. //
  679. if (!SdbWriteBinaryTag(pdb, TAG_EXE_ID, (PBYTE)&m_ID, sizeof(m_ID))) {
  680. SDBERROR(_T("Error writing TAG_EXE_ID\n"));
  681. goto eh;
  682. }
  683. //
  684. // OS SERVICE PACK mask if it's anything other than 0xFFFFFFFF
  685. //
  686. if (m_dwSPMask != 0xFFFFFFFF) {
  687. if (!SdbWriteDWORDTag(pdb, TAG_OS_SERVICE_PACK, m_dwSPMask)) {
  688. SDBERROR(_T("Error writing TAG_OS_SERVICE_PACK\n"));
  689. goto eh;
  690. }
  691. }
  692. //
  693. // Write the MATCH_MODE tag if it's anything other than NORMAL
  694. //
  695. if (m_dwMatchMode != MATCH_DEFAULT) {
  696. BOOL bWriteMatchMode = FALSE;
  697. if (m_pDB->IsStandardDatabase()) {
  698. //
  699. // standard db, we write match mode if it's not "normal"
  700. // since normal is the default
  701. //
  702. bWriteMatchMode = (m_dwMatchMode != MATCHMODE_DEFAULT_MAIN);
  703. } else {
  704. //
  705. // for custom dbs default match mode is additive
  706. //
  707. bWriteMatchMode = (m_dwMatchMode != MATCHMODE_DEFAULT_CUSTOM);
  708. }
  709. if (bWriteMatchMode && !SdbWriteWORDTag(pdb, TAG_MATCH_MODE, (WORD)m_dwMatchMode)) {
  710. SDBERROR(_T("Error writing TAG_MATCH_MODE\n"));
  711. goto eh;
  712. }
  713. }
  714. //
  715. // Write the RUNTIME_PLATFORM tag if it's anything other than RUNTIME_PLATFORM_ANY
  716. //
  717. if (m_dwRuntimePlatform != RUNTIME_PLATFORM_ANY) {
  718. if (!SdbWriteDWORDTag(pdb, TAG_RUNTIME_PLATFORM, m_dwRuntimePlatform)) {
  719. SDBERROR(_T("Error writing RUNTIME_PLATFORM\n"));
  720. goto eh;
  721. }
  722. }
  723. //
  724. // Write the OS_SKU tag if it's anything other than OS_SKU_ALL
  725. //
  726. if (m_dwOSSKU != OS_SKU_ALL) {
  727. if (!SdbWriteDWORDTag(pdb, TAG_OS_SKU, m_dwOSSKU)) {
  728. SDBERROR(_T("Error writing OS_SKU\n"));
  729. goto eh;
  730. }
  731. }
  732. //
  733. // Message reference
  734. //
  735. if (m_AppHelpRef.m_pAppHelp) {
  736. if (!m_AppHelpRef.WriteToSDB(pdb)) {
  737. SDBERROR_PROPOGATE();
  738. goto eh;
  739. }
  740. }
  741. //
  742. // Matching Files
  743. //
  744. if (!m_rgMatchingFiles.WriteToSDB(pdb)) {
  745. SDBERROR_PROPOGATE();
  746. goto eh;
  747. }
  748. //
  749. // Shim references
  750. //
  751. if (!m_rgShimRefs.WriteToSDB(pdb)) {
  752. SDBERROR_PROPOGATE();
  753. goto eh;
  754. }
  755. //
  756. // Flag references
  757. //
  758. if (!m_rgFlagRefs.WriteToSDB(pdb)) {
  759. SDBERROR_PROPOGATE();
  760. goto eh;
  761. }
  762. //
  763. // Patches (by reference)
  764. //
  765. if (!m_rgPatches.WriteToSDB(pdb, TRUE)) {
  766. SDBERROR_PROPOGATE();
  767. goto eh;
  768. }
  769. //
  770. // Layers references
  771. //
  772. if (!m_rgLayerRefs.WriteToSDB(pdb)) {
  773. SDBERROR_PROPOGATE();
  774. goto eh;
  775. }
  776. if (!m_csSXSManifest.IsEmpty()) {
  777. //
  778. // Add XML header tag
  779. //
  780. WCHAR wszXMLHeader[] = L"<?xml version=\"1.0\" encoding=\"UCS-2\" standalone=\"yes\"?>";
  781. //
  782. // The whole manifest consists of the Unicode byte marker (1 byte), the XML header,
  783. // the manifest itself, and a NULL terminator (1 byte).
  784. //
  785. DWORD dwSXSEntryLen = wcslen(wszXMLHeader) + m_csSXSManifest.GetLength() + 2;
  786. LPWSTR wszSXSEntry = (LPWSTR) (malloc(dwSXSEntryLen * sizeof(WCHAR)));
  787. //
  788. // Begin with 0xFF 0xFE Unicode byte order marker
  789. //
  790. UCHAR* szSXSEntry = (UCHAR*) wszSXSEntry;
  791. szSXSEntry[0] = 0xFF;
  792. szSXSEntry[1] = 0xFE;
  793. //
  794. // Add the XML header
  795. //
  796. StringCchCopy(wszSXSEntry + 1, dwSXSEntryLen, wszXMLHeader);
  797. //
  798. // Add the manifest
  799. //
  800. StringCchCat(wszSXSEntry, dwSXSEntryLen, m_csSXSManifest);
  801. if (!SdbWriteStringTag(pdb, TAG_SXS_MANIFEST, wszSXSEntry)) {
  802. goto eh;
  803. }
  804. free(wszSXSEntry);
  805. }
  806. //
  807. // Data
  808. //
  809. if (!m_rgData.WriteToSDB(pdb)) {
  810. SDBERROR_PROPOGATE();
  811. goto eh;
  812. }
  813. //
  814. // Action
  815. //
  816. if (!m_rgAction.WriteToSDB(pdb)) {
  817. SDBERROR_PROPOGATE();
  818. goto eh;
  819. }
  820. //
  821. // Close tag
  822. //
  823. if (!SdbEndWriteListTag(pdb, tiExe)) {
  824. SDBERROR(_T("Error ending TAG_EXE\n"));
  825. goto eh;
  826. }
  827. bSuccess = TRUE;
  828. eh:
  829. return bSuccess;
  830. }
  831. BOOL SdbMsiPackage::WriteToSDB(PDB pdb)
  832. {
  833. BOOL bSuccess = FALSE;
  834. TAGID tiMsiPackage;
  835. //
  836. // Open tag
  837. //
  838. tiMsiPackage = SdbBeginWriteListTag(pdb, TAG_MSI_PACKAGE);
  839. if (!tiMsiPackage) {
  840. SDBERROR(_T("Error writing TAG_MSI_PACKAGE\n"));
  841. goto eh;
  842. }
  843. //
  844. // NAME (i.e., EXE filename)
  845. //
  846. if (m_csName.GetLength()) {
  847. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  848. SDBERROR(_T("Error writing TAG_NAME for MSI_PACKAGE\n"));
  849. goto eh;
  850. }
  851. }
  852. //
  853. // APP_NAME (i.e., application title)
  854. //
  855. if (m_pApp != NULL) {
  856. if (m_pApp->m_csName.GetLength()) {
  857. if (!SdbWriteStringTag(pdb, TAG_APP_NAME, m_pApp->m_csName)) {
  858. SDBERROR(_T("Error writing TAG_APP_NAME for MSI_PACKAGE\n"));
  859. goto eh;
  860. }
  861. }
  862. }
  863. //
  864. // GUID (unique ID)
  865. //
  866. if (!SdbWriteBinaryTag(pdb, TAG_EXE_ID, (PBYTE)&m_ID, sizeof(m_ID))) {
  867. SDBERROR(_T("Error writing TAG_EXE_ID\n"));
  868. goto eh;
  869. }
  870. //
  871. // GUID (non-Unique ID)
  872. //
  873. if (!SdbWriteBinaryTag(pdb, TAG_MSI_PACKAGE_ID, (PBYTE)&m_MsiPackageID, sizeof(m_MsiPackageID))) {
  874. SDBERROR(_T("Error writing TAG_MSI_PACKAGE_ID\n"));
  875. goto eh;
  876. }
  877. //
  878. // RUNTIME_PLATFORM data
  879. //
  880. if (m_dwRuntimePlatform != RUNTIME_PLATFORM_ANY) {
  881. if (!SdbWriteDWORDTag(pdb, TAG_RUNTIME_PLATFORM, m_dwRuntimePlatform)) {
  882. SDBERROR(_T("Error writing RUNTIME_PLATFORM\n"));
  883. goto eh;
  884. }
  885. }
  886. //
  887. // Write the OS_SKU tag if it's anything other than OS_SKU_ALL
  888. //
  889. if (m_dwOSSKU != OS_SKU_ALL) {
  890. if (!SdbWriteDWORDTag(pdb, TAG_OS_SKU, m_dwOSSKU)) {
  891. SDBERROR(_T("Error writing OS_SKU\n"));
  892. goto eh;
  893. }
  894. }
  895. //
  896. // Supplemental data
  897. //
  898. if (!m_rgData.WriteToSDB(pdb)) {
  899. SDBERROR_PROPOGATE();
  900. goto eh;
  901. }
  902. //
  903. // applicable fixes (reference to transforms)
  904. //
  905. if (!m_rgMsiTransformRefs.WriteToSDB(pdb)) {
  906. SDBERROR_PROPOGATE();
  907. goto eh;
  908. }
  909. //
  910. // Message reference
  911. //
  912. if (m_AppHelpRef.m_pAppHelp) {
  913. if (!m_AppHelpRef.WriteToSDB(pdb)) {
  914. SDBERROR_PROPOGATE();
  915. goto eh;
  916. }
  917. }
  918. //
  919. // custom actions
  920. //
  921. if (!m_rgCustomActions.WriteToSDB(pdb)) {
  922. SDBERROR_PROPOGATE();
  923. goto eh;
  924. }
  925. //
  926. // Close tag
  927. //
  928. if (!SdbEndWriteListTag(pdb, tiMsiPackage)) {
  929. SDBERROR(_T("Error ending TAG_MSI_PACKAGE\n"));
  930. goto eh;
  931. }
  932. bSuccess = TRUE;
  933. eh:
  934. return bSuccess;
  935. }
  936. BOOL SdbMsiCustomAction::WriteToSDB(PDB pdb)
  937. {
  938. TAGID tiMsiCustomAction;
  939. BOOL bSuccess = FALSE;
  940. //
  941. // Open tag
  942. //
  943. tiMsiCustomAction = SdbBeginWriteListTag(pdb, TAG_MSI_CUSTOM_ACTION);
  944. if (!tiMsiCustomAction) {
  945. SDBERROR(_T("Error writing TAG_MSI_CUSTOM_ACTION\n"));
  946. goto eh;
  947. }
  948. //
  949. // NAME (i.e., EXE filename)
  950. //
  951. if (m_csName.GetLength()) {
  952. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  953. SDBERROR(_T("Error writing TAG_NAME for MSI_CUSTOM_ACTION\n"));
  954. goto eh;
  955. }
  956. }
  957. //
  958. // Shim references
  959. //
  960. if (!m_rgShimRefs.WriteToSDB(pdb)) {
  961. SDBERROR_PROPOGATE();
  962. goto eh;
  963. }
  964. if (!m_rgLayerRefs.WriteToSDB(pdb)) {
  965. SDBERROR_PROPOGATE();
  966. goto eh;
  967. }
  968. //
  969. // Close tag
  970. //
  971. if (!SdbEndWriteListTag(pdb, tiMsiCustomAction)) {
  972. SDBERROR(_T("Error ending TAG_MSI_CUSTOM_ACTION\n"));
  973. goto eh;
  974. }
  975. bSuccess = TRUE;
  976. eh:
  977. return bSuccess;
  978. }
  979. BOOL SdbCaller::WriteToSDB(PDB pdb)
  980. {
  981. BOOL bSuccess = FALSE;
  982. TAGID tiCaller;
  983. //
  984. // Open tag
  985. //
  986. tiCaller = SdbBeginWriteListTag(pdb, TAG_INEXCLUDE);
  987. if (!tiCaller) {
  988. SDBERROR(_T("Error writing TAG_INEXCLUDE\n"));
  989. goto eh;
  990. }
  991. //
  992. // If it's an <INCLUDE> tag, write out the indicator
  993. //
  994. if (m_CallerType == SDB_CALLER_INCLUDE) {
  995. if (!SdbWriteNULLTag(pdb, TAG_INCLUDE)) {
  996. SDBERROR(_T("Error writing TAG_INCLUDE\n"));
  997. goto eh;
  998. }
  999. }
  1000. //
  1001. // Module
  1002. //
  1003. if (m_csModule.GetLength()) {
  1004. if (!SdbWriteStringTag(pdb, TAG_MODULE, m_csModule)) {
  1005. SDBERROR(_T("Error writing TAG_MODULE\n"));
  1006. goto eh;
  1007. }
  1008. }
  1009. //
  1010. // Close tag
  1011. //
  1012. if (!SdbEndWriteListTag(pdb, tiCaller)) {
  1013. SDBERROR(_T("Error ending TAG_INEXCLUDE\n"));
  1014. goto eh;
  1015. }
  1016. bSuccess = TRUE;
  1017. eh:
  1018. return bSuccess;
  1019. }
  1020. BOOL SdbFile::WriteToSDB(PDB pdb)
  1021. {
  1022. BOOL bSuccess = FALSE;
  1023. TAGID tiFile;
  1024. CString csFileDir, csFilename;
  1025. csFileDir = MakeFullPath(m_pDB->m_pCurrentOutputFile->GetParameter(_T("INCLUDE FILES")));
  1026. //
  1027. // Check if filtered out
  1028. //
  1029. if (!(m_dwFilter & m_pDB->m_pCurrentOutputFile->m_dwFilter)) {
  1030. //
  1031. // Filtered out, return success
  1032. //
  1033. return TRUE;
  1034. }
  1035. //
  1036. // Open tag
  1037. //
  1038. tiFile = SdbBeginWriteListTag(pdb, TAG_FILE);
  1039. if (!tiFile) {
  1040. SDBERROR(_T("Error writing TAG_FILE\n"));
  1041. goto eh;
  1042. }
  1043. //
  1044. // NAME
  1045. //
  1046. if (m_csName.GetLength()) {
  1047. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1048. SDBERROR(_T("Error writing TAG_NAME\n"));
  1049. goto eh;
  1050. }
  1051. }
  1052. //
  1053. // Binary data
  1054. //
  1055. if (csFileDir.GetLength()) {
  1056. csFilename = csFileDir;
  1057. csFilename += m_csName;
  1058. if (!SdbWriteBinaryTagFromFile(pdb, TAG_FILE_BITS, csFilename)) {
  1059. if (g_bStrict) {
  1060. SDBERROR_FORMAT((_T("Can't find FILE \"%s\". No bits written.\n"), csFilename));
  1061. goto eh;
  1062. }
  1063. }
  1064. } else {
  1065. if (g_bStrict) {
  1066. SDBERROR_FORMAT((_T("Can't find FILE \"%s\". -f compiler flag required.\n"), m_csName));
  1067. goto eh;
  1068. }
  1069. }
  1070. //
  1071. // Close tag
  1072. //
  1073. if (!SdbEndWriteListTag(pdb, tiFile)) {
  1074. SDBERROR(_T("Error ending TAG_FILE\n"));
  1075. goto eh;
  1076. }
  1077. m_tiTagID = tiFile; // this is the tagid as it was written into the database
  1078. bSuccess = TRUE;
  1079. eh:
  1080. return bSuccess;
  1081. }
  1082. BOOL SdbShimRef::WriteToSDB(PDB pdb)
  1083. {
  1084. BOOL bSuccess = FALSE;
  1085. TAGID tiShimRef;
  1086. //
  1087. // Open tag
  1088. //
  1089. tiShimRef = SdbBeginWriteListTag(pdb, TAG_SHIM_REF);
  1090. if (!tiShimRef) {
  1091. SDBERROR(_T("Error writing TAG_SHIM_REF\n"));
  1092. goto eh;
  1093. }
  1094. //
  1095. // NAME
  1096. //
  1097. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1098. SDBERROR(_T("Error writing NAME tag\n"));
  1099. goto eh;
  1100. }
  1101. //
  1102. // Write TAGID of the SHIM in the LIBRARY, if any
  1103. //
  1104. if (m_pShim && m_pShim->m_tiTagID) {
  1105. if (!SdbWriteDWORDTag(pdb, TAG_SHIM_TAGID, m_pShim->m_tiTagID)) {
  1106. SDBERROR(_T("Error writing TAG_SHIM_TAGID\n"));
  1107. goto eh;
  1108. }
  1109. }
  1110. //
  1111. // COMMAND_LINE
  1112. //
  1113. if (m_csCommandLine.GetLength()) {
  1114. //
  1115. // process this command line first
  1116. //
  1117. CString csProcessedCmdLine = ProcessShimCmdLine(m_csCommandLine, m_pDB->m_CurrentDBID, tiShimRef);
  1118. if (!SdbWriteStringTag(pdb, TAG_COMMAND_LINE, csProcessedCmdLine)) {
  1119. SDBERROR(_T("Error writing COMMAND_LINE tag\n"));
  1120. goto eh;
  1121. }
  1122. }
  1123. //
  1124. // Inclusion/exclusion list
  1125. //
  1126. if (!m_rgCallers.WriteToSDB(pdb)) {
  1127. SDBERROR_PROPOGATE();
  1128. goto eh;
  1129. }
  1130. //
  1131. // child data tags
  1132. //
  1133. if (!m_rgData.WriteToSDB(pdb)) {
  1134. SDBERROR_PROPOGATE();
  1135. goto eh;
  1136. }
  1137. //
  1138. // Close tag
  1139. //
  1140. if (!SdbEndWriteListTag(pdb, tiShimRef)) {
  1141. SDBERROR(_T("Error ending TAG_SHIM_REF\n"));
  1142. goto eh;
  1143. }
  1144. bSuccess = TRUE;
  1145. eh:
  1146. return bSuccess;
  1147. }
  1148. BOOL SdbShim::WriteToSDB(PDB pdb)
  1149. {
  1150. BOOL bSuccess = FALSE;
  1151. TAGID tiShim;
  1152. //
  1153. // Open tag
  1154. //
  1155. tiShim = SdbBeginWriteListTag(pdb, TAG_SHIM);
  1156. if (!tiShim) {
  1157. SDBERROR(_T("Error writing TAG_SHIM\n"));
  1158. goto eh;
  1159. }
  1160. m_tiTagID = tiShim;
  1161. //
  1162. // NAME
  1163. //
  1164. if (m_csName.GetLength()) {
  1165. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1166. SDBERROR(_T("Error writing TAG_NAME\n"));
  1167. goto eh;
  1168. }
  1169. }
  1170. if (m_csDllFile.GetLength()) {
  1171. if (!SdbWriteStringTag(pdb, TAG_DLLFILE, m_csDllFile)) {
  1172. SDBERROR(_T("Error writing TAG_DLLFILE\n"));
  1173. goto eh;
  1174. }
  1175. }
  1176. //
  1177. // DESCRIPTION, only written for general-purpose shims
  1178. //
  1179. if (m_csDesc.GetLength() && m_Purpose == SDB_PURPOSE_GENERAL) {
  1180. //
  1181. // Remove all extra white space and new line characters
  1182. // via TrimParagraph()
  1183. //
  1184. if (!SdbWriteStringTag(pdb, TAG_DESCRIPTION, TrimParagraph(m_csDesc))) {
  1185. SDBERROR(_T("Error writing TAG_DESCRIPTION\n"));
  1186. goto eh;
  1187. }
  1188. }
  1189. //
  1190. // Purpose (if general)
  1191. //
  1192. if (m_Purpose == SDB_PURPOSE_GENERAL) {
  1193. if (!SdbWriteNULLTag(pdb, TAG_GENERAL)) {
  1194. SDBERROR(_T("Error writing TAG_GENERAL\n"));
  1195. goto eh;
  1196. }
  1197. }
  1198. //
  1199. // APPLY_ALL_SHIMS flag
  1200. //
  1201. if (m_bApplyAllShims) {
  1202. if (!SdbWriteNULLTag(pdb, TAG_APPLY_ALL_SHIMS)) {
  1203. SDBERROR(_T("Error writing TAG_APPLY_ALL_SHIMS\n"));
  1204. goto eh;
  1205. }
  1206. }
  1207. //
  1208. // Inclusion/exclusion list
  1209. //
  1210. if (!m_rgCallers.WriteToSDB(pdb)) {
  1211. SDBERROR_PROPOGATE();
  1212. goto eh;
  1213. }
  1214. //
  1215. // Close tag
  1216. //
  1217. if (!SdbEndWriteListTag(pdb, tiShim)) {
  1218. SDBERROR(_T("Error ending TAG_SHIM\n"));
  1219. goto eh;
  1220. }
  1221. bSuccess = TRUE;
  1222. eh:
  1223. return bSuccess;
  1224. }
  1225. BOOL SdbPatch::WriteToSDB(PDB pdb)
  1226. {
  1227. BOOL bSuccess = FALSE;
  1228. TAGID tiPatch;
  1229. //
  1230. // Open tag
  1231. //
  1232. tiPatch = SdbBeginWriteListTag(pdb, TAG_PATCH);
  1233. if (!tiPatch) {
  1234. SDBERROR(_T("Error writing TAG_PATCH\n"));
  1235. goto eh;
  1236. }
  1237. m_tiTagID = tiPatch;
  1238. //
  1239. // NAME
  1240. //
  1241. if (m_csName.GetLength()) {
  1242. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1243. SDBERROR(_T("Error writing TAG_NAME\n"));
  1244. goto eh;
  1245. }
  1246. }
  1247. //
  1248. // Patch bits
  1249. //
  1250. if (GetBlobSize()) {
  1251. if (!SdbWriteBinaryTag(pdb, TAG_PATCH_BITS, GetBlobBytes(), GetBlobSize())) {
  1252. SDBERROR_FORMAT((_T("Error writing patch bytes \"%s\"\n"), m_csName));
  1253. goto eh;
  1254. }
  1255. }
  1256. //
  1257. // Close tag
  1258. //
  1259. if (!SdbEndWriteListTag(pdb, tiPatch)) {
  1260. SDBERROR(_T("Error ending TAG_PATCH\n"));
  1261. goto eh;
  1262. }
  1263. bSuccess = TRUE;
  1264. eh:
  1265. return bSuccess;
  1266. }
  1267. BOOL SdbPatch::WriteRefToSDB(PDB pdb)
  1268. {
  1269. BOOL bSuccess = FALSE;
  1270. TAGID tiPatch;
  1271. //
  1272. // Open tag
  1273. //
  1274. tiPatch = SdbBeginWriteListTag(pdb, TAG_PATCH_REF);
  1275. if (!tiPatch) {
  1276. SDBERROR(_T("Error writing TAG_PATCH\n"));
  1277. goto eh;
  1278. }
  1279. //
  1280. // NAME
  1281. //
  1282. if (m_csName.GetLength()) {
  1283. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1284. SDBERROR(_T("Error writing TAG_NAME\n"));
  1285. goto eh;
  1286. }
  1287. }
  1288. //
  1289. // Write TAGID of the PATCH in the LIBRARY, if any
  1290. //
  1291. if (m_tiTagID) {
  1292. if (!SdbWriteDWORDTag(pdb, TAG_PATCH_TAGID, m_tiTagID)) {
  1293. SDBERROR(_T("Error writing TAG_PATCH_TAGID\n"));
  1294. goto eh;
  1295. }
  1296. }
  1297. //
  1298. // Close tag
  1299. //
  1300. if (!SdbEndWriteListTag(pdb, tiPatch)) {
  1301. SDBERROR(_T("Error ending TAG_PATCH\n"));
  1302. goto eh;
  1303. }
  1304. bSuccess = TRUE;
  1305. eh:
  1306. return bSuccess;
  1307. }
  1308. BOOL SdbFlag::WriteToSDB(PDB pdb)
  1309. {
  1310. BOOL bSuccess = FALSE;
  1311. TAGID tiFlag;
  1312. //
  1313. // Open tag
  1314. //
  1315. tiFlag = SdbBeginWriteListTag(pdb, TAG_FLAG);
  1316. if (!tiFlag) {
  1317. SDBERROR(_T("Error writing TAG_FLAG\n"));
  1318. goto eh;
  1319. }
  1320. m_tiTagID = tiFlag;
  1321. //
  1322. // NAME
  1323. //
  1324. if (m_csName.GetLength()) {
  1325. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1326. SDBERROR(_T("Error writing TAG_NAME\n"));
  1327. goto eh;
  1328. }
  1329. }
  1330. //
  1331. // DESCRIPTION, only general-purpose descriptions
  1332. //
  1333. if (m_csDesc.GetLength() && m_Purpose == SDB_PURPOSE_GENERAL) {
  1334. //
  1335. // Remove all extra white space and new line characters
  1336. // via TrimParagraph()
  1337. //
  1338. if (!SdbWriteStringTag(pdb, TAG_DESCRIPTION, TrimParagraph(m_csDesc))) {
  1339. SDBERROR(_T("Error writing TAG_DESCRIPTION\n"));
  1340. goto eh;
  1341. }
  1342. }
  1343. //
  1344. // Mask
  1345. //
  1346. if (!SdbWriteQWORDTag(pdb, TagFromType(m_dwType), m_ullMask)) {
  1347. SDBERROR(_T("Error writing <FLAG> in <LIBRARY>\n"));
  1348. goto eh;
  1349. }
  1350. //
  1351. // Purpose (if general)
  1352. //
  1353. if (m_Purpose == SDB_PURPOSE_GENERAL) {
  1354. if (!SdbWriteNULLTag(pdb, TAG_GENERAL)) {
  1355. SDBERROR(_T("Error writing TAG_GENERAL\n"));
  1356. goto eh;
  1357. }
  1358. }
  1359. //
  1360. // Close tag
  1361. //
  1362. if (!SdbEndWriteListTag(pdb, tiFlag)) {
  1363. SDBERROR(_T("Error ending TAG_FLAG\n"));
  1364. goto eh;
  1365. }
  1366. bSuccess = TRUE;
  1367. eh:
  1368. return bSuccess;
  1369. }
  1370. BOOL SdbFlagRef::WriteToSDB(PDB pdb)
  1371. {
  1372. BOOL bSuccess = FALSE;
  1373. TAGID tiFlagRef;
  1374. //
  1375. // Open tag
  1376. //
  1377. tiFlagRef = SdbBeginWriteListTag(pdb, TAG_FLAG_REF);
  1378. if (!tiFlagRef) {
  1379. SDBERROR(_T("Error writing TAG_FLAG_REF\n"));
  1380. goto eh;
  1381. }
  1382. //
  1383. // NAME
  1384. //
  1385. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1386. SDBERROR(_T("Error writing NAME tag\n"));
  1387. goto eh;
  1388. }
  1389. //
  1390. // Write TAGID of the FLAG in the LIBRARY, if any
  1391. //
  1392. if (m_pFlag && m_pFlag->m_tiTagID) {
  1393. if (!SdbWriteDWORDTag(pdb, TAG_FLAG_TAGID, m_pFlag->m_tiTagID)) {
  1394. SDBERROR(_T("Error writing TAG_FLAG_TAGID\n"));
  1395. goto eh;
  1396. }
  1397. }
  1398. //
  1399. // Write Command Line tag
  1400. //
  1401. if (m_csCommandLine.GetLength()) {
  1402. if (!SdbWriteStringTag(pdb, TAG_COMMAND_LINE, m_csCommandLine)) {
  1403. SDBERROR(_T("Error writing COMMAND_LINE tag for flag\n"));
  1404. goto eh;
  1405. }
  1406. }
  1407. //
  1408. // Close tag
  1409. //
  1410. if (!SdbEndWriteListTag(pdb, tiFlagRef)) {
  1411. SDBERROR(_T("Error ending TAG_FLAG_REF\n"));
  1412. goto eh;
  1413. }
  1414. bSuccess = TRUE;
  1415. eh:
  1416. return bSuccess;
  1417. }
  1418. BOOL SdbMsiTransformRef::WriteToSDB(PDB pdb)
  1419. {
  1420. BOOL bSuccess = FALSE;
  1421. TAGID tiMsiTransformRef;
  1422. tiMsiTransformRef = SdbBeginWriteListTag(pdb, TAG_MSI_TRANSFORM_REF);
  1423. if (!tiMsiTransformRef) {
  1424. SDBERROR(_T("Error writing TAG_MSI_TRANSFORM_REF\n"));
  1425. goto eh;
  1426. }
  1427. //
  1428. // write out the reference to the transform by name first
  1429. //
  1430. if (m_csName.GetLength()) {
  1431. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1432. SDBERROR(_T("Error writing TAG_NAME\n"));
  1433. goto eh;
  1434. }
  1435. }
  1436. //
  1437. // now -- satisfy the judgement by writing reference to the
  1438. // actual transform object if available
  1439. //
  1440. if (m_pMsiTransform != NULL) {
  1441. if (!SdbWriteDWORDTag(pdb, TAG_MSI_TRANSFORM_TAGID, m_pMsiTransform->m_tiTagID)) {
  1442. SDBERROR(_T("Error writing TAG_MSI_TRANSFORM_TAGID for MSI_TRANSFORM_REF\n"));
  1443. goto eh;
  1444. }
  1445. }
  1446. if (!SdbEndWriteListTag(pdb, tiMsiTransformRef)) {
  1447. SDBERROR(_T("Error ending TAG_MSI_TRANSFORM_REF\n"));
  1448. goto eh;
  1449. }
  1450. bSuccess = TRUE;
  1451. eh:
  1452. return bSuccess;
  1453. }
  1454. BOOL SdbMsiTransform::WriteToSDB(PDB pdb)
  1455. {
  1456. BOOL bSuccess = FALSE;
  1457. TAGID tiMsiTransform;
  1458. //
  1459. // write out the name of the transform
  1460. tiMsiTransform = SdbBeginWriteListTag(pdb, TAG_MSI_TRANSFORM);
  1461. if (!tiMsiTransform) {
  1462. SDBERROR(_T("Error writing TAG_MSI_TRANSFORM\n"));
  1463. goto eh;
  1464. }
  1465. //
  1466. // NAME
  1467. //
  1468. if (m_csName.GetLength()) {
  1469. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1470. SDBERROR(_T("Error writing TAG_NAME\n"));
  1471. goto eh;
  1472. }
  1473. }
  1474. //
  1475. // MSI transform file name
  1476. //
  1477. if (m_csMsiTransformFile.GetLength()) {
  1478. if (!SdbWriteStringTag(pdb, TAG_MSI_TRANSFORM_FILE, m_csMsiTransformFile)) {
  1479. SDBERROR(_T("Error writing TAG_MSI_TRANSFORM_FILE\n"));
  1480. goto eh;
  1481. }
  1482. }
  1483. //
  1484. // REFERENCE the Actual file bits
  1485. //
  1486. if (m_pSdbFile != NULL && m_pSdbFile->m_tiTagID != TAGID_NULL) {
  1487. if (!SdbWriteDWORDTag(pdb, TAG_MSI_TRANSFORM_TAGID, m_pSdbFile->m_tiTagID)) {
  1488. SDBERROR(_T("Error writing TAG_MSI_TRANSFORM_TAGID\n"));
  1489. goto eh;
  1490. }
  1491. }
  1492. //
  1493. // Close tag
  1494. //
  1495. if (!SdbEndWriteListTag(pdb, tiMsiTransform)) {
  1496. SDBERROR(_T("Error ending TAG_MSI_TRANSFORM\n"));
  1497. goto eh;
  1498. }
  1499. m_tiTagID = tiMsiTransform;
  1500. bSuccess = TRUE;
  1501. eh:
  1502. return bSuccess;
  1503. }
  1504. BOOL SdbLayer::WriteToSDB(PDB pdb)
  1505. {
  1506. BOOL bSuccess = FALSE;
  1507. TAGID tiLayer;
  1508. long i;
  1509. //
  1510. // Open tag
  1511. //
  1512. tiLayer = SdbBeginWriteListTag(pdb, TAG_LAYER);
  1513. if (!tiLayer) {
  1514. SDBERROR(_T("Error writing TAG_LAYER\n"));
  1515. goto eh;
  1516. }
  1517. m_tiTagID = tiLayer;
  1518. //
  1519. // NAME
  1520. //
  1521. if (m_csName.GetLength()) {
  1522. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1523. SDBERROR(_T("Error writing TAG_NAME\n"));
  1524. goto eh;
  1525. }
  1526. }
  1527. //
  1528. // Display name
  1529. //
  1530. if (m_csDisplayName.GetLength()) {
  1531. if (!SdbWriteStringTag(pdb, TAG_LAYER_DISPLAYNAME, m_csDisplayName)) {
  1532. SDBERROR(_T("Error writing TAG_LAYER_DISPLAYNAME\n"));
  1533. goto eh;
  1534. }
  1535. }
  1536. //
  1537. // Shim references
  1538. //
  1539. if (!m_rgShimRefs.WriteToSDB(pdb)) {
  1540. SDBERROR_PROPOGATE();
  1541. goto eh;
  1542. }
  1543. //
  1544. // Flags
  1545. //
  1546. if (!m_rgFlagRefs.WriteToSDB(pdb)) {
  1547. SDBERROR_PROPOGATE();
  1548. goto eh;
  1549. }
  1550. //
  1551. // Close tag
  1552. //
  1553. if (!SdbEndWriteListTag(pdb, tiLayer)) {
  1554. SDBERROR(_T("Error ending TAG_LAYER\n"));
  1555. goto eh;
  1556. }
  1557. bSuccess = TRUE;
  1558. eh:
  1559. return bSuccess;
  1560. }
  1561. BOOL SdbLayerRef::WriteToSDB(PDB pdb)
  1562. {
  1563. BOOL bSuccess = FALSE;
  1564. TAGID tiLayer;
  1565. //
  1566. // Open tag
  1567. //
  1568. tiLayer = SdbBeginWriteListTag(pdb, TAG_LAYER);
  1569. if (!tiLayer) {
  1570. SDBERROR(_T("Error writing TAG_LAYER\n"));
  1571. goto eh;
  1572. }
  1573. //
  1574. // NAME
  1575. //
  1576. if (m_csName.GetLength()) {
  1577. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1578. SDBERROR(_T("Error writing TAG_NAME\n"));
  1579. goto eh;
  1580. }
  1581. }
  1582. //
  1583. // Write TAGID of the LAYER in the LIBRARY, if any
  1584. //
  1585. if (m_pLayer) {
  1586. if (m_pLayer->m_tiTagID) {
  1587. if (!SdbWriteDWORDTag(pdb, TAG_LAYER_TAGID, m_pLayer->m_tiTagID)) {
  1588. SDBERROR(_T("Error writing TAG_LAYER_TAGID\n"));
  1589. goto eh;
  1590. }
  1591. }
  1592. }
  1593. //
  1594. // child data tags
  1595. //
  1596. if (!m_rgData.WriteToSDB(pdb)) {
  1597. SDBERROR_PROPOGATE();
  1598. goto eh;
  1599. }
  1600. //
  1601. // Close tag
  1602. //
  1603. if (!SdbEndWriteListTag(pdb, tiLayer)) {
  1604. SDBERROR(_T("Error ending TAG_LAYER\n"));
  1605. goto eh;
  1606. }
  1607. bSuccess = TRUE;
  1608. eh:
  1609. return bSuccess;
  1610. }
  1611. BOOL SdbMatchingFile::WriteToSDB(PDB pdb)
  1612. {
  1613. BOOL bSuccess = FALSE;
  1614. TAGID tiMatchingFile;
  1615. //
  1616. // Open tag
  1617. //
  1618. tiMatchingFile = SdbBeginWriteListTag(pdb, TAG_MATCHING_FILE);
  1619. if (!tiMatchingFile) {
  1620. SDBERROR(_T("Error writing TAG_MATCHING_FILE\n"));
  1621. goto eh;
  1622. }
  1623. //
  1624. // NAME
  1625. //
  1626. if (m_csName.GetLength()) {
  1627. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  1628. SDBERROR(_T("Error writing TAG_NAME\n"));
  1629. goto eh;
  1630. }
  1631. }
  1632. //
  1633. // platform should be first if it exists -- along with the logic bit
  1634. //
  1635. if (m_bMatchLogicNot) {
  1636. if (!SdbWriteNULLTag(pdb, TAG_MATCH_LOGIC_NOT)) {
  1637. SDBERROR(_T("Error writing MATCH_LOGIC_NOT\n"));
  1638. goto eh;
  1639. }
  1640. }
  1641. // matching information
  1642. if (m_dwMask & SDB_MATCHINGINFO_SIZE) {
  1643. if (!SdbWriteDWORDTag(pdb, TAG_SIZE, m_dwSize)) {
  1644. SDBERROR(_T("Error writing SIZE\n"));
  1645. goto eh;
  1646. }
  1647. }
  1648. if (m_dwMask & SDB_MATCHINGINFO_CHECKSUM) {
  1649. if (!SdbWriteDWORDTag(pdb, TAG_CHECKSUM, m_dwChecksum)) {
  1650. SDBERROR(_T("Error writing CHECKSUM\n"));
  1651. goto eh;
  1652. }
  1653. }
  1654. if (m_dwMask & SDB_MATCHINGINFO_COMPANY_NAME) {
  1655. if (!SdbWriteStringTag(pdb, TAG_COMPANY_NAME, m_csCompanyName)) {
  1656. SDBERROR(_T("Error writing COMPANY_NAME tag\n"));
  1657. goto eh;
  1658. }
  1659. }
  1660. if (m_dwMask & SDB_MATCHINGINFO_PRODUCT_NAME) {
  1661. if (!SdbWriteStringTag(pdb, TAG_PRODUCT_NAME, m_csProductName)) {
  1662. SDBERROR(_T("Error writing PRODUCT_NAME tag\n"));
  1663. goto eh;
  1664. }
  1665. }
  1666. if (m_dwMask & SDB_MATCHINGINFO_PRODUCT_VERSION) {
  1667. if (!SdbWriteStringTag(pdb, TAG_PRODUCT_VERSION, m_csProductVersion)) {
  1668. SDBERROR(_T("Error writing PRODUCT_VERSION tag\n"));
  1669. goto eh;
  1670. }
  1671. }
  1672. if (m_dwMask & SDB_MATCHINGINFO_FILE_DESCRIPTION) {
  1673. if (!SdbWriteStringTag(pdb, TAG_FILE_DESCRIPTION, m_csFileDescription)) {
  1674. SDBERROR(_T("Error writing FILE_DESCRIPTION tag\n"));
  1675. goto eh;
  1676. }
  1677. }
  1678. if (m_dwMask & SDB_MATCHINGINFO_BIN_FILE_VERSION) {
  1679. if (!SdbWriteQWORDTag(pdb, TAG_BIN_FILE_VERSION, m_ullBinFileVersion)) {
  1680. SDBERROR(_T("Error writing BIN_FILE_VERSION\n"));
  1681. goto eh;
  1682. }
  1683. }
  1684. if (m_dwMask & SDB_MATCHINGINFO_BIN_PRODUCT_VERSION) {
  1685. if (!SdbWriteQWORDTag(pdb, TAG_BIN_PRODUCT_VERSION, m_ullBinProductVersion)) {
  1686. SDBERROR(_T("Error writing BIN_PRODUCT_VERSION\n"));
  1687. goto eh;
  1688. }
  1689. }
  1690. if (m_dwMask & SDB_MATCHINGINFO_MODULE_TYPE) {
  1691. if (!SdbWriteDWORDTag(pdb, TAG_MODULE_TYPE, m_dwModuleType)) {
  1692. SDBERROR(_T("Error writing MODULE_TYPE\n"));
  1693. goto eh;
  1694. }
  1695. }
  1696. if (m_dwMask & SDB_MATCHINGINFO_VERFILEDATEHI) {
  1697. if (!SdbWriteDWORDTag(pdb, TAG_VERDATEHI, m_dwFileDateMS)) {
  1698. SDBERROR(_T("Error writing MODULE_TYPE\n"));
  1699. goto eh;
  1700. }
  1701. }
  1702. if (m_dwMask & SDB_MATCHINGINFO_VERFILEDATELO) {
  1703. if (!SdbWriteDWORDTag(pdb, TAG_VERDATELO, m_dwFileDateLS)) {
  1704. SDBERROR(_T("Error writing MODULE_TYPE\n"));
  1705. goto eh;
  1706. }
  1707. }
  1708. if (m_dwMask & SDB_MATCHINGINFO_VERFILEOS) {
  1709. if (!SdbWriteDWORDTag(pdb, TAG_VERFILEOS, m_dwFileOS)) {
  1710. SDBERROR(_T("Error writing VERFILEOS\n"));
  1711. goto eh;
  1712. }
  1713. }
  1714. if (m_dwMask & SDB_MATCHINGINFO_VERFILETYPE) {
  1715. if (!SdbWriteDWORDTag(pdb, TAG_VERFILETYPE, m_dwFileType)) {
  1716. SDBERROR(_T("Error writing VERFILETYPE\n"));
  1717. goto eh;
  1718. }
  1719. }
  1720. if (m_dwMask & SDB_MATCHINGINFO_PE_CHECKSUM) {
  1721. if (!SdbWriteDWORDTag(pdb, TAG_PE_CHECKSUM, m_ulPECheckSum)) {
  1722. SDBERROR(_T("Error writing PE_CHECKSUM\n"));
  1723. goto eh;
  1724. }
  1725. }
  1726. if (m_dwMask & SDB_MATCHINGINFO_LINKER_VERSION) {
  1727. if (!SdbWriteDWORDTag(pdb, TAG_LINKER_VERSION, m_dwLinkerVersion)) {
  1728. SDBERROR(_T("Error writing LINKER_VERSION\n"));
  1729. goto eh;
  1730. }
  1731. }
  1732. if (m_dwMask & SDB_MATCHINGINFO_FILE_VERSION) {
  1733. if (!SdbWriteStringTag(pdb, TAG_FILE_VERSION, m_csFileVersion)) {
  1734. SDBERROR(_T("Error writing FILE_VERSION\n"));
  1735. goto eh;
  1736. }
  1737. }
  1738. if (m_dwMask & SDB_MATCHINGINFO_ORIGINAL_FILENAME) {
  1739. if (!SdbWriteStringTag(pdb, TAG_ORIGINAL_FILENAME, m_csOriginalFileName)) {
  1740. SDBERROR(_T("Error writing ORIGINAL_FILENAME\n"));
  1741. goto eh;
  1742. }
  1743. }
  1744. if (m_dwMask & SDB_MATCHINGINFO_INTERNAL_NAME) {
  1745. if (!SdbWriteStringTag(pdb, TAG_INTERNAL_NAME, m_csInternalName)) {
  1746. SDBERROR(_T("Error writing INTERNAL_NAME\n"));
  1747. goto eh;
  1748. }
  1749. }
  1750. if (m_dwMask & SDB_MATCHINGINFO_LEGAL_COPYRIGHT) {
  1751. if (!SdbWriteStringTag(pdb, TAG_LEGAL_COPYRIGHT, m_csLegalCopyright)) {
  1752. SDBERROR(_T("Error writing LEGAL_COPYRIGHT\n"));
  1753. goto eh;
  1754. }
  1755. }
  1756. if (m_dwMask & SDB_MATCHINGINFO_16BIT_DESCRIPTION) {
  1757. if (!SdbWriteStringTag(pdb, TAG_16BIT_DESCRIPTION, m_cs16BitDescription)) {
  1758. SDBERROR(_T("Error writing 16BIT_DESCRIPTION\n"));
  1759. goto eh;
  1760. }
  1761. }
  1762. if (m_dwMask & SDB_MATCHINGINFO_16BIT_MODULE_NAME) {
  1763. if (!SdbWriteStringTag(pdb, TAG_16BIT_MODULE_NAME, m_cs16BitModuleName)) {
  1764. SDBERROR(_T("Error Writing 16BIT_MODULE_NAME\n"));
  1765. goto eh;
  1766. }
  1767. }
  1768. if (m_dwMask & SDB_MATCHINGINFO_UPTO_BIN_PRODUCT_VERSION) {
  1769. if (!SdbWriteQWORDTag(pdb, TAG_UPTO_BIN_PRODUCT_VERSION, m_ullUpToBinProductVersion)) {
  1770. SDBERROR(_T("Error writing UPTO_BIN_PRODUCT_VERSION\n"));
  1771. goto eh;
  1772. }
  1773. }
  1774. if (m_dwMask & SDB_MATCHINGINFO_UPTO_BIN_FILE_VERSION) {
  1775. if (!SdbWriteQWORDTag(pdb, TAG_UPTO_BIN_FILE_VERSION, m_ullUpToBinFileVersion)) {
  1776. SDBERROR(_T("Error writing UPTO_BIN_FILE_VERSION\n"));
  1777. goto eh;
  1778. }
  1779. }
  1780. if (m_dwMask & SDB_MATCHINGINFO_PREVOSMAJORVERSION) {
  1781. if (!SdbWriteDWORDTag(pdb, TAG_PREVOSMAJORVER, m_dwPrevOSMajorVersion)) {
  1782. SDBERROR(_T("Error writing PREVOSMAJORVER\n"));
  1783. goto eh;
  1784. }
  1785. }
  1786. if (m_dwMask & SDB_MATCHINGINFO_PREVOSMINORVERSION) {
  1787. if (!SdbWriteDWORDTag(pdb, TAG_PREVOSMINORVER, m_dwPrevOSMinorVersion)) {
  1788. SDBERROR(_T("Error writing PREVOSMINORVER\n"));
  1789. goto eh;
  1790. }
  1791. }
  1792. if (m_dwMask & SDB_MATCHINGINFO_PREVOSPLATFORMID) {
  1793. if (!SdbWriteDWORDTag(pdb, TAG_PREVOSPLATFORMID, m_dwPrevOSPlatformID)) {
  1794. SDBERROR(_T("Error writing PREVOSPLATFORMID\n"));
  1795. goto eh;
  1796. }
  1797. }
  1798. if (m_dwMask & SDB_MATCHINGINFO_PREVOSBUILDNO) {
  1799. if (!SdbWriteDWORDTag(pdb, TAG_PREVOSBUILDNO, m_dwPrevOSBuildNo)) {
  1800. SDBERROR(_T("Error writing PREVOSBUILDNO\n"));
  1801. goto eh;
  1802. }
  1803. }
  1804. if (m_dwMask & SDB_MATCHINGINFO_LINK_DATE) {
  1805. if (!SdbWriteDWORDTag(pdb, TAG_LINK_DATE, (DWORD) m_timeLinkDate)) {
  1806. SDBERROR(_T("Error writing LINK_DATE\n"));
  1807. goto eh;
  1808. }
  1809. }
  1810. if (m_dwMask & SDB_MATCHINGINFO_UPTO_LINK_DATE) {
  1811. if (!SdbWriteDWORDTag(pdb, TAG_UPTO_LINK_DATE, (DWORD) m_timeUpToLinkDate)) {
  1812. SDBERROR(_T("Error writing UPTO_LINK_DATE\n"));
  1813. goto eh;
  1814. }
  1815. }
  1816. if (m_dwMask & SDB_MATCHINGINFO_VER_LANGUAGE) {
  1817. if (!SdbWriteDWORDTag(pdb, TAG_VER_LANGUAGE, m_dwVerLanguage)) {
  1818. SDBERROR(_T("Error writing VER_LANGUAGE tag\n"));
  1819. goto eh;
  1820. }
  1821. }
  1822. //
  1823. // Close tag
  1824. //
  1825. if (!SdbEndWriteListTag(pdb, tiMatchingFile)) {
  1826. SDBERROR(_T("Error ending TAG_MATCHING_FILE\n"));
  1827. goto eh;
  1828. }
  1829. bSuccess = TRUE;
  1830. eh:
  1831. return bSuccess;
  1832. }
  1833. BOOL SdbAppHelpRef::WriteToSDB(PDB pdb)
  1834. {
  1835. BOOL bSuccess = FALSE;
  1836. TAGID tiAppHelp;
  1837. CString cs;
  1838. //
  1839. // Open tag
  1840. //
  1841. tiAppHelp = SdbBeginWriteListTag(pdb, TAG_APPHELP);
  1842. if (!tiAppHelp) {
  1843. SDBERROR(_T("Error writing TAG_APPHELP\n"));
  1844. goto eh;
  1845. }
  1846. if (m_pDB->m_pCurrentOutputFile->m_dwFilter & ~SDB_FILTER_DRIVER) {
  1847. //
  1848. // If this EXE entry contains only APPHELP entries, set
  1849. // a flag.
  1850. //
  1851. if (m_bApphelpOnly) {
  1852. if (!SdbWriteDWORDTag(pdb, TAG_FLAGS, SHIMDB_APPHELP_ONLY)) {
  1853. SDBERROR(_T("Error writing FLAGS in APPHELP entry\n"));
  1854. goto eh;
  1855. }
  1856. }
  1857. //
  1858. // Severity
  1859. //
  1860. if (!SdbWriteDWORDTag(pdb, TAG_PROBLEMSEVERITY, (DWORD)m_pAppHelp->m_Type)) {
  1861. SDBERROR( _T("Error writing PROBLEM_SEVERITY\n"));
  1862. goto eh;
  1863. }
  1864. }
  1865. //
  1866. // HTMLHELPID
  1867. //
  1868. if (!SdbWriteDWORDTag(pdb, TAG_HTMLHELPID, (DWORD)_ttol(m_pAppHelp->m_csName))) {
  1869. SDBERROR( _T("Error writing HTMLHELPID\n"));
  1870. goto eh;
  1871. }
  1872. //
  1873. // Check for service pack parameters.
  1874. //
  1875. cs = m_pDB->m_pCurrentOutputFile->GetParameter("DATE AFTER WHICH TO USE SERVICE PACK APPHELP SDB");
  1876. if (cs.GetLength()) {
  1877. COleDateTime odt;
  1878. if (!odt.ParseDateTime(cs)) {
  1879. SDBERROR_FORMAT((_T("Error parsing DATE AFTER WHICH TO USE SERVICE PACK APPHELP SDB parameter: \"%s\"\n"), cs));
  1880. goto eh;
  1881. }
  1882. if (odt.m_dt <= m_pAppHelp->m_dtLastRevision) {
  1883. if (!SdbWriteNULLTag(pdb, TAG_USE_SERVICE_PACK_FILES)) {
  1884. SDBERROR( _T("Error writing USE_SERVICE_PACK_FILES\n"));
  1885. goto eh;
  1886. }
  1887. }
  1888. }
  1889. //
  1890. // Close tag
  1891. //
  1892. if (!SdbEndWriteListTag(pdb, tiAppHelp)) {
  1893. SDBERROR(_T("Error ending TAG_APPHELP\n"));
  1894. goto eh;
  1895. }
  1896. bSuccess = TRUE;
  1897. eh:
  1898. return bSuccess;
  1899. }
  1900. BOOL SdbDatabase::ConstructMigrationMessage(
  1901. SdbWin9xMigration* pMigApp,
  1902. SdbMessage* pMessage,
  1903. CString* pcsMessage
  1904. )
  1905. {
  1906. BOOL bSuccess = FALSE;
  1907. CString csSummaryXML, csRedirURL;
  1908. SdbRefArray<SdbMessageField> rgFields;
  1909. SdbMessageField TitleField;
  1910. SdbMessageField VendorField;
  1911. if (pMessage->m_csSummaryXML.IsEmpty()) {
  1912. if (pMessage->m_pTemplate != NULL) {
  1913. csSummaryXML = pMessage->m_pTemplate->m_csSummaryXML;
  1914. }
  1915. } else {
  1916. csSummaryXML = pMessage->m_csSummaryXML;
  1917. }
  1918. TitleField.m_csName = _T("TITLE");
  1919. TitleField.m_csValue = pMigApp->m_pApp->GetLocalizedAppName();
  1920. VendorField.m_csName = _T("VENDOR");
  1921. VendorField.m_csValue = pMigApp->m_pApp->GetLocalizedVendorName();
  1922. rgFields.Add(&TitleField);
  1923. rgFields.Add(&VendorField);
  1924. rgFields.Append(pMessage->m_rgFields);
  1925. if (!ReplaceFields(csSummaryXML, pcsMessage, &rgFields)) {
  1926. SDBERROR_PROPOGATE();
  1927. goto eh;
  1928. }
  1929. csRedirURL = m_pCurrentOutputFile->GetParameter(_T("REDIR URL"));
  1930. if (!RedirectLinks(pcsMessage,
  1931. m_pCurrentMakefile->GetLangMap(m_pCurrentOutputFile->m_csLangID)->m_lcid, csRedirURL)) {
  1932. SDBERROR_PROPOGATE();
  1933. goto eh;
  1934. }
  1935. if (g_bStrict) {
  1936. if (pcsMessage->IsEmpty()) {
  1937. SDBERROR_FORMAT((_T("ERROR: Empty string for SUMMARY on\n NAME: %s\n MESSAGE: %s\n LANG: %s\n\n"),
  1938. pMigApp->m_pApp->m_csName, pMigApp->m_csMessage, m_pCurrentMakefile->m_csLangID));
  1939. goto eh;
  1940. }
  1941. }
  1942. //
  1943. // Remove redundant spacing
  1944. //
  1945. *pcsMessage = TrimParagraph(*pcsMessage);
  1946. //
  1947. // Replace <BR/> with \r\n
  1948. //
  1949. ReplaceStringNoCase(*pcsMessage, _T("<BR/>"), _T("<BR>"));
  1950. ReplaceStringNoCase(*pcsMessage, _T("<P/>"), _T("<BR>"));
  1951. ReplaceStringNoCase(*pcsMessage, _T("&amp;"), _T("&"));
  1952. bSuccess = TRUE;
  1953. eh:
  1954. return bSuccess;
  1955. }
  1956. BOOL SdbDatabase::ConstructMessageParts(
  1957. SdbAppHelp* pAppHelp,
  1958. SdbMessage* pMessage,
  1959. CString& csLangID,
  1960. DWORD* pdwHTMLHelpID,
  1961. CString* pcsURL,
  1962. CString* pcsContactInfo,
  1963. CString* pcsAppTitle,
  1964. CString* pcsSummary,
  1965. CString* pcsDetails)
  1966. {
  1967. BOOL bSuccess = FALSE;
  1968. SdbContactInfo* pContactInfo;
  1969. SdbMessageTemplate* pTemplate;
  1970. SdbMessageField* pField;
  1971. CString csContactInfoXML, csSummaryXML, csDetailsXML;
  1972. CString csField, csRedirURL, csBaseURL, csLCID;
  1973. long i;
  1974. SdbRefArray<SdbMessageField> rgFields;
  1975. SdbMessageField TitleField;
  1976. SdbMessageField VendorField;
  1977. //
  1978. // If there's a custom URL for this apphelp, use it. If a base content URL was given
  1979. // via the makefile, use that to construct the URL.
  1980. //
  1981. csBaseURL = m_pCurrentOutputFile->GetParameter(_T("BASE ONLINE CONTENT URL"));
  1982. *pdwHTMLHelpID = (DWORD)_ttol(pAppHelp->m_csName);
  1983. if (pAppHelp->m_csURL.GetLength()) {
  1984. *pcsURL = pAppHelp->m_csURL;
  1985. } else if (csBaseURL.GetLength()) {
  1986. *pcsURL = csBaseURL;
  1987. ReplaceStringNoCase(*pcsURL, _T("$HTMLHELPID$"), pAppHelp->m_csName);
  1988. ReplaceStringNoCase(*pcsURL, _T("$LANGID$"), csLangID);
  1989. csLCID.Format(_T("%X"), m_pCurrentMakefile->GetLangMap(csLangID)->m_lcid);
  1990. ReplaceStringNoCase(*pcsURL, _T("$LCID$"), csLCID);
  1991. }
  1992. if (pMessage->m_csContactInfoXML.IsEmpty()) {
  1993. pContactInfo = (SdbContactInfo *) m_rgContactInfo.LookupName(pAppHelp->m_pApp->m_csVendor, csLangID);
  1994. if (pContactInfo == NULL) {
  1995. pContactInfo = (SdbContactInfo *) m_rgContactInfo.LookupName(_T("__DEFAULT__"), csLangID);
  1996. }
  1997. if (pContactInfo == NULL) {
  1998. if (g_bStrict) {
  1999. SDBERROR_FORMAT((_T("ERROR: Localized CONTACT_INFO not found for\n NAME: %s\n HTMLHELPID: %s\n LANG: %s\n\n"),
  2000. pAppHelp->m_pApp->m_csVendor, pAppHelp->m_csName, csLangID));
  2001. goto eh;
  2002. } else {
  2003. csContactInfoXML = pAppHelp->m_pApp->m_csVendorXML;
  2004. }
  2005. } else {
  2006. csContactInfoXML = pContactInfo->m_csXML;
  2007. }
  2008. } else {
  2009. csContactInfoXML = pMessage->m_csContactInfoXML;
  2010. }
  2011. *pcsAppTitle = pAppHelp->m_pApp->GetLocalizedAppName(csLangID);
  2012. if (pMessage->m_csSummaryXML.IsEmpty()) {
  2013. if (pMessage->m_pTemplate != NULL) {
  2014. csSummaryXML = pMessage->m_pTemplate->m_csSummaryXML;
  2015. }
  2016. } else {
  2017. csSummaryXML = pMessage->m_csSummaryXML;
  2018. }
  2019. if (pMessage->m_csDetailsXML.IsEmpty()) {
  2020. if (pMessage->m_pTemplate != NULL) {
  2021. csDetailsXML = pMessage->m_pTemplate->m_csDetailsXML;
  2022. }
  2023. } else {
  2024. csDetailsXML = pMessage->m_csDetailsXML;
  2025. }
  2026. TitleField.m_csName = _T("TITLE");
  2027. TitleField.m_csValue = pAppHelp->m_pApp->GetLocalizedAppName(csLangID);
  2028. VendorField.m_csName = _T("VENDOR");
  2029. VendorField.m_csValue = pAppHelp->m_pApp->GetLocalizedVendorName(csLangID);
  2030. rgFields.Add(&TitleField);
  2031. rgFields.Add(&VendorField);
  2032. rgFields.Append(pMessage->m_rgFields);
  2033. if (!ReplaceFields(csContactInfoXML, pcsContactInfo, &rgFields)) {
  2034. SDBERROR_PROPOGATE();
  2035. goto eh;
  2036. }
  2037. if (pcsSummary) {
  2038. if (!ReplaceFields(csSummaryXML, pcsSummary, &rgFields)) {
  2039. SDBERROR_PROPOGATE();
  2040. goto eh;
  2041. }
  2042. }
  2043. if (!ReplaceFields(csDetailsXML, pcsDetails, &rgFields)) {
  2044. SDBERROR_PROPOGATE();
  2045. goto eh;
  2046. }
  2047. csRedirURL = m_pCurrentOutputFile->GetParameter(_T("REDIR URL"));
  2048. if (!RedirectLinks(pcsContactInfo,
  2049. m_pCurrentMakefile->GetLangMap(csLangID)->m_lcid, csRedirURL)) {
  2050. SDBERROR_PROPOGATE();
  2051. goto eh;
  2052. }
  2053. if (!RedirectLinks(pcsDetails,
  2054. m_pCurrentMakefile->GetLangMap(csLangID)->m_lcid, csRedirURL)) {
  2055. SDBERROR_PROPOGATE();
  2056. goto eh;
  2057. }
  2058. //
  2059. // Remove redundant spacing
  2060. //
  2061. *pcsURL = TrimParagraph(*pcsURL);
  2062. *pcsAppTitle = TrimParagraph(*pcsAppTitle);
  2063. if (pcsSummary) {
  2064. *pcsSummary = TrimParagraph(*pcsSummary);
  2065. //
  2066. // Replace various HTML entities with equivalents
  2067. //
  2068. ReplaceStringNoCase(*pcsSummary, _T("<BR/>"), _T("\r\n"));
  2069. ReplaceStringNoCase(*pcsSummary, _T("<P/>"), _T("\r\n"));
  2070. ReplaceStringNoCase(*pcsSummary, _T("&amp;"), _T("&"));
  2071. if (-1 != pcsSummary->Find(_T('<'))) {
  2072. SDBERROR_FORMAT((_T("ERROR: <SUMMARY> can only contain <BR/> and <P/> formatting tags:\n%s\n"),
  2073. *pcsSummary));
  2074. goto eh;
  2075. }
  2076. }
  2077. bSuccess = TRUE;
  2078. eh:
  2079. return bSuccess;
  2080. }
  2081. BOOL SdbDatabase::WriteAppHelpRefTag(
  2082. PDB pdb,
  2083. CString csHTMLHelpID,
  2084. LCID lcid,
  2085. CString csURL,
  2086. CString csAppTitle,
  2087. CString csSummary)
  2088. {
  2089. TAGID tiMessageSummary;
  2090. TAGID tiLink;
  2091. INT i;
  2092. BOOL bReturn = FALSE;
  2093. tiMessageSummary = SdbBeginWriteListTag(pdb, TAG_APPHELP);
  2094. if (!tiMessageSummary) {
  2095. SDBERROR(_T("Error writing APPHELP_DETAILS tag\n"));
  2096. goto eh;
  2097. }
  2098. if (!SdbWriteDWORDTag(pdb, TAG_HTMLHELPID, (DWORD)_ttol(csHTMLHelpID))) {
  2099. SDBERROR( _T("Error writing HTMLHELPID\n"));
  2100. goto eh;
  2101. }
  2102. if (lcid != 0) {
  2103. if (!SdbWriteDWORDTag(pdb, TAG_LANGID, lcid)) {
  2104. SDBERROR( _T("Error writing LANGID\n"));
  2105. goto eh;
  2106. }
  2107. }
  2108. // for each, write a list tag
  2109. tiLink = SdbBeginWriteListTag(pdb,TAG_LINK);
  2110. if (!tiLink) {
  2111. SDBERROR(_T("Error writing APPHELP LINK tag\n"));
  2112. goto eh;
  2113. }
  2114. if (!SdbWriteStringTag(pdb, TAG_LINK_URL, csURL)) {
  2115. SDBERROR(_T("Error writing APPHELP URL tag\n"));
  2116. goto eh;
  2117. }
  2118. if (!SdbEndWriteListTag(pdb, tiLink)) {
  2119. SDBERROR(_T("Error closing APPHELP LINK tag\n"));
  2120. goto eh;
  2121. }
  2122. if (!csAppTitle.IsEmpty() &&
  2123. !SdbWriteStringTag(pdb, TAG_APPHELP_TITLE, csAppTitle)) {
  2124. SDBERROR(_T("Error writing APPHELP_TITLE tag\n"));
  2125. goto eh;
  2126. }
  2127. if (!csSummary.IsEmpty() &&
  2128. !SdbWriteStringTag(pdb, TAG_APPHELP_DETAILS, csSummary)) {
  2129. SDBERROR(_T("Error writing APPHELP_DETAILS tag\n"));
  2130. goto eh;
  2131. }
  2132. if (!SdbEndWriteListTag(pdb, tiMessageSummary)) {
  2133. SDBERROR(_T("Error closing APPHELP_DETAILS tag\n"));
  2134. goto eh;
  2135. }
  2136. bReturn = TRUE;
  2137. eh:
  2138. return bReturn;
  2139. }
  2140. BOOL SdbData::WriteToSDB(PDB pdb)
  2141. {
  2142. BOOL bSuccess = FALSE;
  2143. TAGID tiData;
  2144. //
  2145. // Open tag
  2146. //
  2147. tiData = SdbBeginWriteListTag(pdb, TAG_DATA);
  2148. if (!tiData) {
  2149. SDBERROR(_T("Error writing TAG_DATA\n"));
  2150. goto eh;
  2151. }
  2152. //
  2153. // NAME
  2154. //
  2155. if (m_csName.GetLength()) {
  2156. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  2157. SDBERROR(_T("Error writing TAG_NAME\n"));
  2158. goto eh;
  2159. }
  2160. }
  2161. //
  2162. // Value type
  2163. //
  2164. if (!SdbWriteDWORDTag(pdb, TAG_DATA_VALUETYPE, m_DataType)) {
  2165. SDBERROR(_T("Error writing TAG_DATA_VALUETYPE for DRIVER_POLICY\n"));
  2166. goto eh;
  2167. }
  2168. //
  2169. // Value
  2170. //
  2171. switch(m_DataType) {
  2172. case eValueNone:
  2173. break;
  2174. case eValueString:
  2175. if (m_szValue != NULL && !SdbWriteStringTag(pdb, TAG_DATA_STRING, m_szValue)) {
  2176. SDBERROR(_T("Error writing TAG_DATA_STRING\n"));
  2177. goto eh;
  2178. }
  2179. break;
  2180. case eValueDWORD:
  2181. if (!SdbWriteDWORDTag(pdb, TAG_DATA_DWORD, m_dwValue)) {
  2182. SDBERROR(_T("Error writing TAG_DATA_DWORD\n"));
  2183. goto eh;
  2184. }
  2185. break;
  2186. case eValueQWORD:
  2187. if (!SdbWriteQWORDTag(pdb, TAG_DATA_QWORD, m_ullValue)) {
  2188. SDBERROR(_T("Error writing TAG_DATA_QWORD\n"));
  2189. goto eh;
  2190. }
  2191. break;
  2192. case eValueBinary:
  2193. if (!SdbWriteBinaryTag(pdb, TAG_DATA_BITS, m_pBinValue, m_dwDataSize)) {
  2194. SDBERROR(_T("Error writing TAG_DATA_BITS\n"));
  2195. goto eh;
  2196. }
  2197. break;
  2198. }
  2199. //
  2200. // Data
  2201. //
  2202. if (!m_rgData.WriteToSDB(pdb)) {
  2203. SDBERROR_PROPOGATE();
  2204. goto eh;
  2205. }
  2206. //
  2207. // Close tag
  2208. //
  2209. if (!SdbEndWriteListTag(pdb, tiData)) {
  2210. SDBERROR(_T("Error ending TAG_DATA\n"));
  2211. goto eh;
  2212. }
  2213. bSuccess = TRUE;
  2214. eh:
  2215. return bSuccess;
  2216. }
  2217. BOOL SdbAction::WriteToSDB(PDB pdb)
  2218. {
  2219. BOOL bSuccess = FALSE;
  2220. TAGID tiAction;
  2221. //
  2222. // Open tag
  2223. //
  2224. tiAction = SdbBeginWriteListTag(pdb, TAG_ACTION);
  2225. if (!tiAction) {
  2226. SDBERROR(_T("Error writing TAG_ACTION\n"));
  2227. goto eh;
  2228. }
  2229. //
  2230. // NAME
  2231. //
  2232. if (!SdbWriteStringTag(pdb, TAG_NAME, m_csName)) {
  2233. SDBERROR(_T("Error writing NAME tag\n"));
  2234. goto eh;
  2235. }
  2236. //
  2237. // TYPE
  2238. //
  2239. if (m_csType.GetLength()) {
  2240. if (!SdbWriteStringTag(pdb, TAG_ACTION_TYPE, m_csType)) {
  2241. SDBERROR(_T("Error writing TAG_ACTION_TYPE tag\n"));
  2242. goto eh;
  2243. }
  2244. }
  2245. //
  2246. // child data tags
  2247. //
  2248. if (!m_rgData.WriteToSDB(pdb)) {
  2249. SDBERROR_PROPOGATE();
  2250. goto eh;
  2251. }
  2252. //
  2253. // Close tag
  2254. //
  2255. if (!SdbEndWriteListTag(pdb, tiAction)) {
  2256. SDBERROR(_T("Error ending TAG_ACTION\n"));
  2257. goto eh;
  2258. }
  2259. bSuccess = TRUE;
  2260. eh:
  2261. return bSuccess;
  2262. }