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.

416 lines
13 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File: ntcompat.cpp
  4. //
  5. // History: 27-Mar-01 markder Created.
  6. //
  7. // Desc: This file contains all code needed to create ntcompat.inx
  8. // additions.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////////
  11. #include "StdAfx.h"
  12. #include "make.h"
  13. #include "fileio.h"
  14. BOOL NtCompatCreateWinNTUpgradeEntry(
  15. SdbWinNTUpgrade* pNTUpg,
  16. CString* pcsInfLine)
  17. {
  18. BOOL bSuccess = FALSE;
  19. CString csLinkDate, csAttr, csBinProductVersion, csBinFileVersion, csTemp;
  20. CString csFileName, csServiceName;
  21. ULONGLONG ullAttr = 0;
  22. if (pNTUpg->m_AppHelpRef.m_pAppHelp == NULL) {
  23. SDBERROR_FORMAT((_T("NTCOMPAT entry requires APPHELP: \"%s\"\n"),
  24. pNTUpg->m_pApp->m_csName));
  25. goto eh;
  26. }
  27. if (pNTUpg->m_MatchingFile.m_csName.GetLength() ||
  28. pNTUpg->m_MatchingFile.m_csServiceName.GetLength()) {
  29. if (pNTUpg->m_MatchingFile.m_dwMask & (~(
  30. SDB_MATCHINGINFO_BIN_PRODUCT_VERSION |
  31. SDB_MATCHINGINFO_UPTO_BIN_PRODUCT_VERSION |
  32. SDB_MATCHINGINFO_BIN_FILE_VERSION |
  33. SDB_MATCHINGINFO_UPTO_BIN_FILE_VERSION |
  34. SDB_MATCHINGINFO_LINK_DATE |
  35. SDB_MATCHINGINFO_UPTO_LINK_DATE))) {
  36. SDBERROR_FORMAT((_T("NTCOMPAT entry can only use (UPTO_)LINK_DATE and (UPTO_)BIN_xxxx_VERSION as matching info: \"%s\"\n"),
  37. pNTUpg->m_pApp->m_csName));
  38. goto eh;
  39. }
  40. if (pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_BIN_PRODUCT_VERSION ||
  41. pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_UPTO_BIN_PRODUCT_VERSION) {
  42. csAttr.Empty();
  43. if (pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_BIN_PRODUCT_VERSION) {
  44. ullAttr = pNTUpg->m_MatchingFile.m_ullBinProductVersion;
  45. } else {
  46. ullAttr = pNTUpg->m_MatchingFile.m_ullUpToBinProductVersion;
  47. }
  48. if (((WORD)(ullAttr >> 48)) != 0xFFFF) {
  49. csTemp.Format(_T("%d"), (WORD)(ullAttr >> 48));
  50. csAttr += csTemp;
  51. if (((WORD)(ullAttr >> 32)) != 0xFFFF) {
  52. csTemp.Format(_T(".%d"), (WORD)(ullAttr >> 32));
  53. csAttr += csTemp;
  54. if (((WORD)(ullAttr >> 16)) != 0xFFFF) {
  55. csTemp.Format(_T(".%d"), (WORD)(ullAttr >> 16));
  56. csAttr += csTemp;
  57. if (((WORD)(ullAttr)) != 0xFFFF) {
  58. csTemp.Format(_T(".%d"), (WORD)(ullAttr));
  59. csAttr += csTemp;
  60. }
  61. }
  62. }
  63. }
  64. if (pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_BIN_PRODUCT_VERSION) {
  65. csAttr = _T("=") + csAttr;
  66. }
  67. csAttr = _T("\"") + csAttr;
  68. csAttr += _T("\"");
  69. csBinProductVersion = csAttr;
  70. }
  71. if (pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_BIN_FILE_VERSION ||
  72. pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_UPTO_BIN_FILE_VERSION) {
  73. csAttr.Empty();
  74. if (pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_BIN_FILE_VERSION) {
  75. ullAttr = pNTUpg->m_MatchingFile.m_ullBinFileVersion;
  76. } else {
  77. ullAttr = pNTUpg->m_MatchingFile.m_ullUpToBinFileVersion;
  78. }
  79. if (((WORD)(ullAttr >> 48)) != 0xFFFF) {
  80. csTemp.Format(_T("%d"), (WORD)(ullAttr >> 48));
  81. csAttr += csTemp;
  82. if (((WORD)(ullAttr >> 32)) != 0xFFFF) {
  83. csTemp.Format(_T(".%d"), (WORD)(ullAttr >> 32));
  84. csAttr += csTemp;
  85. if (((WORD)(ullAttr >> 16)) != 0xFFFF) {
  86. csTemp.Format(_T(".%d"), (WORD)(ullAttr >> 16));
  87. csAttr += csTemp;
  88. if (((WORD)(ullAttr)) != 0xFFFF) {
  89. csTemp.Format(_T(".%d"), (WORD)(ullAttr));
  90. csAttr += csTemp;
  91. }
  92. }
  93. }
  94. }
  95. if (pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_BIN_FILE_VERSION) {
  96. csAttr = _T("=") + csAttr;
  97. }
  98. csAttr = _T("\"") + csAttr;
  99. csAttr += _T("\"");
  100. csBinFileVersion = csAttr;
  101. }
  102. if (pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_UPTO_LINK_DATE) {
  103. csLinkDate.Format(_T("\"0x%08X\""), (DWORD) pNTUpg->m_MatchingFile.m_timeUpToLinkDate);
  104. }
  105. if (pNTUpg->m_MatchingFile.m_dwMask & SDB_MATCHINGINFO_LINK_DATE) {
  106. csLinkDate.Format(_T("\"=0x%08X\""), (DWORD) pNTUpg->m_MatchingFile.m_timeLinkDate);
  107. }
  108. if (pNTUpg->m_MatchingFile.m_csServiceName.IsEmpty()) {
  109. pcsInfLine->Format(
  110. _T("f,\"%s\",%s,*idh_w2_%s.htm,,%%drvmain__%s__%%,,,,%s,%s"),
  111. pNTUpg->m_MatchingFile.m_csName,
  112. csBinFileVersion,
  113. pNTUpg->m_AppHelpRef.m_pAppHelp->m_csName,
  114. pNTUpg->m_AppHelpRef.m_pAppHelp->m_csName,
  115. csLinkDate,
  116. csBinProductVersion);
  117. } else {
  118. if (!pNTUpg->m_MatchingFile.m_csName.IsEmpty()) {
  119. csFileName = _T("\"");
  120. csFileName += pNTUpg->m_MatchingFile.m_csName;
  121. csFileName += _T("\"");
  122. }
  123. if (!pNTUpg->m_MatchingFile.m_csServiceName.IsEmpty()) {
  124. csServiceName = _T("\"");
  125. csServiceName += pNTUpg->m_MatchingFile.m_csServiceName;
  126. csServiceName += _T("\"");
  127. }
  128. pcsInfLine->Format(
  129. _T("s,%s,*idh_w2_%s.htm,,%%drvmain__%s__%%,%s,%s,,,,%s,%s"),
  130. csServiceName,
  131. pNTUpg->m_AppHelpRef.m_pAppHelp->m_csName,
  132. pNTUpg->m_AppHelpRef.m_pAppHelp->m_csName,
  133. csFileName,
  134. csBinFileVersion,
  135. csLinkDate,
  136. csBinProductVersion);
  137. }
  138. } else if (pNTUpg->m_MatchingRegistryEntry.m_csName.GetLength()) {
  139. CString csKey, csValueName, csValue;
  140. csKey = pNTUpg->m_MatchingRegistryEntry.m_csName;
  141. csValueName = pNTUpg->m_MatchingRegistryEntry.m_csValueName;
  142. csValue = pNTUpg->m_MatchingRegistryEntry.m_csValue;
  143. if (!csKey.IsEmpty()) {
  144. csKey = _T("\"") + csKey + _T("\"");
  145. }
  146. if (!csValueName.IsEmpty()) {
  147. csValueName = _T("\"") + csValueName + _T("\"");
  148. }
  149. if (!csValue.IsEmpty()) {
  150. csValue = _T("\"") + csValue + _T("\"");
  151. }
  152. pcsInfLine->Format(
  153. _T("r,%s,%s,%s,*idh_w2_%s.htm,*idh_w2_%s.htm,%%drvmain__%s__%%"),
  154. csKey,
  155. csValueName,
  156. csValue,
  157. pNTUpg->m_AppHelpRef.m_pAppHelp->m_csName,
  158. pNTUpg->m_AppHelpRef.m_pAppHelp->m_csName,
  159. pNTUpg->m_AppHelpRef.m_pAppHelp->m_csName);
  160. } else {
  161. SDBERROR_FORMAT((_T("NTCOMPAT entry requires 1 matching specification: \"%s\"\n"),
  162. pNTUpg->m_pApp->m_csName));
  163. goto eh;
  164. }
  165. bSuccess = TRUE;
  166. eh:
  167. return bSuccess;
  168. }
  169. BOOL NtCompatWriteInfAdditions(
  170. SdbOutputFile* pOutputFile,
  171. SdbDatabase* pDB)
  172. {
  173. BOOL bSuccess = FALSE;
  174. CStringArray rgServicesToDisable;
  175. CStringArray rgServicesToStopInstallation;
  176. CMapStringToString mapStrings;
  177. CString csInfLine, csStringKey, csStringLine;
  178. SdbWinNTUpgrade* pNTUpg = NULL;
  179. long i;
  180. for (i = 0; i < pDB->m_rgWinNTUpgradeEntries.GetSize(); i++) {
  181. pNTUpg = (SdbWinNTUpgrade *) pDB->m_rgWinNTUpgradeEntries.GetAt(i);
  182. if (!(pNTUpg->m_dwFilter & g_dwCurrentWriteFilter)) {
  183. continue;
  184. }
  185. if (!NtCompatCreateWinNTUpgradeEntry(pNTUpg, &csInfLine)) {
  186. SDBERROR_PROPOGATE();
  187. goto eh;
  188. }
  189. if (pNTUpg->m_AppHelpRef.m_pAppHelp->m_bBlockUpgrade) {
  190. rgServicesToStopInstallation.Add(csInfLine);
  191. } else {
  192. rgServicesToDisable.Add(csInfLine);
  193. }
  194. csStringKey.Format(_T("drvmain__%s__"),
  195. pNTUpg->m_AppHelpRef.m_pAppHelp->m_csName);
  196. csStringLine.Format(_T("drvmain__%s__=\"%s\""),
  197. pNTUpg->m_AppHelpRef.m_pAppHelp->m_csName,
  198. pNTUpg->m_AppHelpRef.m_pAppHelp->m_pApp->GetLocalizedAppName());
  199. mapStrings.SetAt(csStringKey,csStringLine);
  200. }
  201. try {
  202. POSITION pos;
  203. CANSITextFile File(pOutputFile->m_csName,
  204. pDB->m_pCurrentMakefile->GetLangMap(pDB->m_pCurrentOutputFile->m_csLangID)->m_dwCodePage,
  205. CFile::typeText |
  206. CFile::modeCreate |
  207. CFile::modeWrite |
  208. CFile::shareDenyWrite);
  209. File.WriteString(_T(";\n"));
  210. File.WriteString(_T("; App Compat entries start here\n"));
  211. File.WriteString(_T(";\n"));
  212. File.WriteString(_T("; ___APPCOMPAT_NTCOMPAT_ENTRIES___\n"));
  213. File.WriteString(_T(";\n"));
  214. pos = mapStrings.GetStartPosition();
  215. while (pos) {
  216. mapStrings.GetNextAssoc(pos, csStringKey, csStringLine);
  217. File.WriteString(csStringLine + _T("\n"));
  218. }
  219. File.WriteString(_T("\n\n[ServicesToDisable]\n"));
  220. for (i = 0; i < rgServicesToDisable.GetSize(); i++) {
  221. File.WriteString(rgServicesToDisable[i] + _T("\n"));
  222. }
  223. File.WriteString(_T("\n\n[ServicesToStopInstallation]\n"));
  224. for (i = 0; i < rgServicesToStopInstallation.GetSize(); i++) {
  225. File.WriteString(rgServicesToStopInstallation[i] + _T("\n"));
  226. }
  227. File.Close();
  228. }
  229. catch(...) {
  230. SDBERROR_FORMAT((_T("Error writing NTCOMPAT file \"%s\"."),
  231. pOutputFile->m_csName));
  232. goto eh;
  233. }
  234. bSuccess = TRUE;
  235. eh:
  236. return bSuccess;
  237. }
  238. BOOL NtCompatWriteMessageInf(
  239. SdbOutputFile* pOutputFile,
  240. SdbDatabase* pDB)
  241. {
  242. BOOL bSuccess = FALSE;
  243. SdbAppHelp* pAppHelp;
  244. SdbMessage* pMessage;
  245. CString csInfLine;
  246. long i;
  247. // Message parts
  248. DWORD dwHTMLHelpID;
  249. LANGID langID;
  250. CString csURL, csContactInfo, csAppTitle;
  251. CString csDetails;
  252. try {
  253. CANSITextFile File(pOutputFile->m_csName,
  254. pDB->m_pCurrentMakefile->GetLangMap(pDB->m_pCurrentOutputFile->m_csLangID)->m_dwCodePage,
  255. CFile::typeText |
  256. CFile::modeCreate |
  257. CFile::modeWrite |
  258. CFile::shareDenyWrite);
  259. File.WriteString(_T(";\n; AppHelp Message INF for NTCOMPAT-style upgrades\n"));
  260. File.WriteString(_T(";\n; This file is generated from XML via ShimDBC\n;\n"));
  261. File.WriteString(_T("\n\n[Version]\nsignature=\"$windows nt$\"\n\n"));
  262. for (i = 0; i < pDB->m_rgAppHelps.GetSize(); i++) {
  263. pAppHelp = (SdbAppHelp *) pDB->m_rgAppHelps.GetAt(i);
  264. if (!(pAppHelp->m_dwFilter & g_dwCurrentWriteFilter)) {
  265. continue;
  266. }
  267. pMessage =
  268. (SdbMessage *) pDB->m_rgMessages.LookupName(pAppHelp->m_csMessage, pDB->m_pCurrentMakefile->m_csLangID);
  269. if (pMessage == NULL) {
  270. SDBERROR_FORMAT((_T("Error looking up message for AppHelp HTMLHELPID %s\n"),
  271. pAppHelp->m_csName));
  272. goto eh;
  273. }
  274. if (!pDB->ConstructMessageParts(
  275. pAppHelp,
  276. pMessage,
  277. pDB->m_pCurrentMakefile->m_csLangID,
  278. &dwHTMLHelpID,
  279. &csURL,
  280. &csContactInfo,
  281. &csAppTitle,
  282. NULL,
  283. &csDetails)) {
  284. SDBERROR_PROPOGATE();
  285. goto eh;
  286. }
  287. csInfLine.Format(_T("[idh_w2_%d.htm]\n"), dwHTMLHelpID);
  288. File.WriteString(csInfLine);
  289. csDetails = TrimParagraph(csDetails);
  290. if (!pDB->HTMLtoText(csDetails, &csInfLine)) {
  291. SDBERROR_PROPOGATE();
  292. goto eh;
  293. }
  294. ReplaceStringNoCase(csInfLine, _T(" \n"), _T("\n"));
  295. ReplaceStringNoCase(csInfLine, _T("\n "), _T("\n"));
  296. ReplaceStringNoCase(csInfLine, _T("\""), _T("'"));
  297. ReplaceStringNoCase(csInfLine, _T("\n"), _T("\"\n\""));
  298. csInfLine.TrimLeft();
  299. csInfLine.TrimRight();
  300. csInfLine = _T("\"") + csInfLine;
  301. csInfLine += _T("\"\n\"\"\n");
  302. File.WriteString(csInfLine);
  303. csContactInfo = TrimParagraph(csContactInfo);
  304. if (!pDB->HTMLtoText(csContactInfo, &csInfLine)) {
  305. SDBERROR_PROPOGATE();
  306. goto eh;
  307. }
  308. ReplaceStringNoCase(csInfLine, _T(" \n"), _T("\n"));
  309. ReplaceStringNoCase(csInfLine, _T("\n "), _T("\n"));
  310. ReplaceStringNoCase(csInfLine, _T("\""), _T("'"));
  311. ReplaceStringNoCase(csInfLine, _T("\n"), _T("\"\n\""));
  312. csInfLine.TrimLeft();
  313. csInfLine.TrimRight();
  314. csInfLine = _T("\"") + csInfLine;
  315. csInfLine += _T("\"\n\n");
  316. File.WriteString(csInfLine);
  317. }
  318. File.Close();
  319. }
  320. catch(...) {
  321. SDBERROR_FORMAT((_T("Error writing to NTCOMPAT INF for HTMLHELPID %s.\n"),
  322. pAppHelp->m_csName));
  323. }
  324. bSuccess = TRUE;
  325. eh:
  326. return bSuccess;
  327. }