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.

477 lines
13 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File: make.cpp
  4. //
  5. // History: 06-Mar-01 markder Created.
  6. //
  7. // Desc: This file contains various member functions/constructors
  8. // used by the makefile objects.
  9. //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "StdAfx.h"
  12. #include "make.h"
  13. #include "fileio.h"
  14. ////////////////////////////////////////////////////////////////////////////////////
  15. //
  16. // Func: ReadDatabase
  17. //
  18. // Desc: Opens an XML file and calls read on the database object.
  19. //
  20. BOOL SdbMakefile::ReadMakefile(
  21. CString csMakefile)
  22. {
  23. BOOL bSuccess = FALSE;
  24. IXMLDOMNodePtr cpRootNode;
  25. IXMLDOMNodePtr cpMakefile;
  26. XMLNodeList XQL;
  27. if (!OpenXML(csMakefile, &cpRootNode)) {
  28. SDBERROR_PROPOGATE();
  29. goto eh;
  30. }
  31. if (!GetChild(_T("SHIMDBC_MAKEFILE"), cpRootNode, &cpMakefile)) {
  32. SDBERROR(_T("<SHIMDBC_MAKEFILE> object not found"));
  33. goto eh;
  34. }
  35. if (!ReadFromXML(cpMakefile, NULL)) {
  36. SDBERROR_PROPOGATE();
  37. goto eh;
  38. }
  39. bSuccess = TRUE;
  40. eh:
  41. return bSuccess;
  42. }
  43. BOOL SdbMakefile::ReadFromXML(IXMLDOMNode* pNode, SdbDatabase* pDB)
  44. {
  45. BOOL bSuccess = FALSE;
  46. SdbOutputFile* pOutputFile = NULL;
  47. if (!m_rgInputFiles.ReadFromXML(_T("INPUT"), NULL, pNode)) {
  48. SDBERROR_PROPOGATE();
  49. goto eh;
  50. }
  51. if (!m_rgOutputFiles.ReadFromXML(_T("OUTPUT"), NULL, pNode)) {
  52. SDBERROR_PROPOGATE();
  53. goto eh;
  54. }
  55. //
  56. // Propagate LANGID to output files if needed
  57. //
  58. for (int j = 0; j < m_rgOutputFiles.GetSize(); j++) {
  59. pOutputFile = (SdbOutputFile *) m_rgOutputFiles.GetAt(j);
  60. if (!pOutputFile->m_csLangID.GetLength()) {
  61. pOutputFile->m_csLangID = m_csLangID;
  62. }
  63. }
  64. if (!m_rgLangMaps.ReadFromXML(_T("LANG_MAP"), NULL, pNode)) {
  65. SDBERROR_PROPOGATE();
  66. goto eh;
  67. }
  68. bSuccess = TRUE;
  69. eh:
  70. return bSuccess;
  71. }
  72. BOOL SdbInputFile::ReadFromXML(IXMLDOMNode* pNode, SdbDatabase* pDB)
  73. {
  74. BOOL bSuccess = FALSE;
  75. CString csType, csParamName, csParamValue;
  76. XMLNodeList XQL;
  77. IXMLDOMNodePtr cpParam;
  78. long i;
  79. if (!ReadName(pNode, &m_csName)) {
  80. SDBERROR_PROPOGATE();
  81. goto eh;
  82. }
  83. m_csName = MakeFullPath(m_csName);
  84. ExpandEnvStrings(&m_csName);
  85. if (!XQL.Query(pNode, _T("PARAM"))) {
  86. SDBERROR_PROPOGATE();
  87. goto eh;
  88. }
  89. for (i = 0; i < XQL.GetSize(); i++) {
  90. if (!XQL.GetItem(i, &cpParam)) {
  91. SDBERROR_PROPOGATE();
  92. goto eh;
  93. }
  94. if (!GetAttribute(_T("NAME"), cpParam, &csParamName)) {
  95. SDBERROR_FORMAT((_T("<PARAM> requires NAME attribute:\n%s\n"),
  96. GetXML(cpParam)));
  97. }
  98. if (!GetAttribute(_T("VALUE"), cpParam, &csParamValue)) {
  99. SDBERROR_FORMAT((_T("<PARAM> requires VALUE attribute:\n%s\n"),
  100. GetXML(cpParam)));
  101. }
  102. ExpandEnvStrings(&csParamValue);
  103. if (csParamName == _T("FILTER")) {
  104. m_dwFilter = GetFilter(csParamValue);
  105. }
  106. m_mapParameters.SetAt(csParamName, csParamValue);
  107. cpParam.Release();
  108. }
  109. bSuccess = TRUE;
  110. eh:
  111. return bSuccess;
  112. }
  113. BOOL SdbOutputFile::ReadFromXML(IXMLDOMNode* pNode, SdbDatabase* pDB)
  114. {
  115. BOOL bSuccess = FALSE;
  116. CString csType, csParamName, csParamValue;
  117. XMLNodeList XQL;
  118. IXMLDOMNodePtr cpParam;
  119. long i;
  120. COleDateTime odtServicePackBaselineDate;
  121. if (!ReadName(pNode, &m_csName)) {
  122. SDBERROR_PROPOGATE();
  123. goto eh;
  124. }
  125. ExpandEnvStrings(&m_csName);
  126. m_csName = MakeFullPath(m_csName);
  127. if (!GetAttribute(_T("TYPE"), pNode, &csType)) {
  128. SDBERROR_FORMAT((_T("<OUTPUT> requires TYPE attribute:\n%s\n"),
  129. GetXML(pNode)));
  130. }
  131. m_OutputType = GetOutputType(csType);
  132. if (m_OutputType == SDB_OUTPUT_TYPE_UNKNOWN) {
  133. SDBERROR_FORMAT((_T("<OUTPUT TYPE> not recognized:\n%s\n"),
  134. csType));
  135. }
  136. if (!XQL.Query(pNode, _T("PARAM"))) {
  137. SDBERROR_PROPOGATE();
  138. goto eh;
  139. }
  140. for (i = 0; i < XQL.GetSize(); i++) {
  141. if (!XQL.GetItem(i, &cpParam)) {
  142. SDBERROR_PROPOGATE();
  143. goto eh;
  144. }
  145. if (!GetAttribute(_T("NAME"), cpParam, &csParamName)) {
  146. SDBERROR_FORMAT((_T("<PARAM> requires NAME attribute:\n%s\n"),
  147. GetXML(cpParam)));
  148. }
  149. if (!GetAttribute(_T("VALUE"), cpParam, &csParamValue)) {
  150. SDBERROR_FORMAT((_T("<PARAM> requires VALUE attribute:\n%s\n"),
  151. GetXML(cpParam)));
  152. }
  153. ExpandEnvStrings(&csParamValue);
  154. if (csParamName == _T("FILTER")) {
  155. m_dwFilter = GetFilter(csParamValue);
  156. }
  157. if (csParamName == _T("INCLUDE FILES")) {
  158. if (csParamValue.Right(1) != _T("\\")) {
  159. csParamValue += _T("\\");
  160. }
  161. }
  162. if (csParamName == _T("SERVICE PACK BASELINE DATE")) {
  163. if (csParamValue.GetLength()) {
  164. if (!odtServicePackBaselineDate.ParseDateTime(csParamValue, 0, 0x0409)) {
  165. SDBERROR_FORMAT((_T("Error parsing SERVICE PACK BASELINE DATE parameter in makefile: %s\n"),
  166. csParamValue));
  167. goto eh;
  168. }
  169. m_dtRevisionCutoff = odtServicePackBaselineDate.m_dt;
  170. }
  171. }
  172. if (csParamName == _T("LANGID")) {
  173. m_csLangID = csParamValue;
  174. }
  175. m_mapParameters.SetAt(csParamName, csParamValue);
  176. cpParam.Release();
  177. }
  178. bSuccess = TRUE;
  179. eh:
  180. return bSuccess;
  181. }
  182. BOOL SdbLangMap::ReadFromXML(IXMLDOMNode* pNode, SdbDatabase* pDB)
  183. {
  184. BOOL bSuccess = FALSE;
  185. CString csCodePage, csLCID;
  186. if (!ReadName(pNode, &m_csName)) {
  187. SDBERROR_PROPOGATE();
  188. goto eh;
  189. }
  190. m_csName.MakeUpper();
  191. if (!GetAttribute(_T("CODEPAGE"), pNode, &csCodePage)) {
  192. SDBERROR_FORMAT((_T("<LANG_MAP> requires CODEPAGE attribute:\n%s\n"),
  193. GetXML(pNode)));
  194. }
  195. if (!GetAttribute(_T("LCID"), pNode, &csLCID)) {
  196. SDBERROR_FORMAT((_T("<LANG_MAP> requires LCID attribute:\n%s\n"),
  197. GetXML(pNode)));
  198. }
  199. if (!GetAttribute(_T("HTML_CHARSET"), pNode, &m_csHtmlCharset)) {
  200. SDBERROR_FORMAT((_T("<LANG_MAP> requires HTML_CHARSET attribute:\n%s\n"),
  201. GetXML(pNode)));
  202. }
  203. m_dwCodePage = _ttol(csCodePage);
  204. m_lcid = _tcstol(csLCID, NULL, 0);
  205. bSuccess = TRUE;
  206. eh:
  207. return bSuccess;
  208. }
  209. BOOL WriteRedirMapFile(CString csFile, CString csTemplateFile, SdbDatabase* pDB)
  210. {
  211. BOOL bSuccess = FALSE;
  212. CString csID, csURL, csTemplate, csRow;
  213. try {
  214. CStdioFile TemplateFile(csTemplateFile, CFile::typeText|CFile::modeRead);
  215. while (TemplateFile.ReadString(csRow)) {
  216. csTemplate += csRow + _T("\n");
  217. }
  218. }
  219. catch(CFileException* pFileEx) {
  220. SDBERROR_FORMAT((_T("Error reading from redir template file: %s\n"), csTemplateFile));
  221. pFileEx->Delete();
  222. goto eh;
  223. }
  224. catch(CMemoryException* pMemEx) {
  225. pMemEx->Delete();
  226. goto eh;
  227. }
  228. try {
  229. SdbLocalizedString* pRedir = NULL;
  230. CStdioFile OutputFile(csFile, CFile::typeText |
  231. CFile::modeCreate |
  232. CFile::modeWrite |
  233. CFile::shareDenyWrite);
  234. OutputFile.WriteString(_T("<root>\n"));
  235. for (int i = 0; i < pDB->m_rgRedirs.GetSize(); i++) {
  236. pRedir = (SdbLocalizedString *) pDB->m_rgRedirs.GetAt(i);
  237. if (pRedir->m_csLangID == pDB->m_pCurrentOutputFile->m_csLangID)
  238. {
  239. csID = pRedir->m_csName;
  240. csURL = pRedir->m_csValue;
  241. csRow = csTemplate;
  242. csRow.Replace(_T("%REDIR_ID%"), csID);
  243. csRow.Replace(_T("%URL%"), csURL);
  244. OutputFile.WriteString(csRow);
  245. }
  246. }
  247. OutputFile.WriteString(_T("</root>\n"));
  248. OutputFile.Close();
  249. }
  250. catch(CFileException* pFileEx) {
  251. pFileEx->Delete();
  252. goto eh;
  253. }
  254. catch(CMemoryException* pMemEx) {
  255. pMemEx->Delete();
  256. goto eh;
  257. }
  258. bSuccess = TRUE;
  259. eh:
  260. return bSuccess;
  261. }
  262. void SdbMakefile::AddHistoryKeywords(LPCTSTR szStart)
  263. {
  264. LPCTSTR szEnd;
  265. szEnd = szStart;
  266. while (*szEnd) {
  267. if (*(szEnd+1) == _T(';') || *(szEnd+1) == _T('\0')) {
  268. m_rgHistoryKeywords.Add(szStart);
  269. m_rgHistoryKeywords[m_rgHistoryKeywords.GetSize()-1] =
  270. m_rgHistoryKeywords[m_rgHistoryKeywords.GetSize()-1].Left((int)(szEnd - szStart + 1));
  271. szStart = szEnd + 2;
  272. }
  273. szEnd++;
  274. }
  275. }
  276. SdbLangMap* SdbMakefile::GetLangMap(CString& csLangID)
  277. {
  278. SdbLangMap* pLangMap = NULL;
  279. return (SdbLangMap *) m_rgLangMaps.LookupName(csLangID);
  280. }
  281. BOOL WriteAppHelpReport(SdbOutputFile* pOutputFile, SdbDatabase* pDB)
  282. {
  283. BOOL bSuccess = FALSE;
  284. SdbAppHelp* pAppHelp;
  285. long i, j;
  286. CString csHTML, csRedirID, csRedirURL, csThisRedirURL, csURL, csTemp;
  287. SdbLocalizedString* pRedir = NULL;
  288. csRedirURL = pOutputFile->GetParameter(_T("REDIR URL"));
  289. try {
  290. CUTF16TextFile File(pOutputFile->m_csName, CFile::typeText |
  291. CFile::modeCreate |
  292. CFile::modeWrite |
  293. CFile::shareDenyWrite);
  294. File.WriteString(_T("<HTML><HEAD><STYLE>td { font-family: sans-serif; font-size: 8pt; }</STYLE></HEAD><BODY>"));
  295. File.WriteString(_T("<TABLE BORDER=0 CELLSPACING=0>"));
  296. File.WriteString(_T("<TR>\n"));
  297. File.WriteString(_T("<TD COLSPAN=3 ALIGN=CENTER>AppHelp Pages</TD>\n"));
  298. File.WriteString(_T("</TR><TR><TD COLSPAN=3>&nbsp;</TD></TR>\n"));
  299. File.WriteString(_T("<TR BGCOLOR=#E0E0E0>\n"));
  300. File.WriteString(_T("<TD>App</TD>\n"));
  301. File.WriteString(_T("<TD>Vendor</TD>\n"));
  302. File.WriteString(_T("<TD>HTMLHelpID</TD>\n"));
  303. File.WriteString(_T("</TR>\n"));
  304. for (i = 0; i < pDB->m_rgAppHelps.GetSize(); i++) {
  305. pAppHelp = (SdbAppHelp *) pDB->m_rgAppHelps[i];
  306. File.WriteString(_T("<TR>\n"));
  307. csHTML.Format(_T("<TD>%s</TD>\n"), pAppHelp->m_pApp->GetLocalizedAppName());
  308. File.WriteString(csHTML);
  309. csHTML.Format(_T("<TD>%s</TD>\n"), pAppHelp->m_pApp->GetLocalizedVendorName());
  310. File.WriteString(csHTML);
  311. csHTML.Format(_T("<TD><A TARGET=\"_new\" HREF=\"idh_w2_%s.htm\">%s</A></TD>\n"),
  312. pAppHelp->m_csName, pAppHelp->m_csName);
  313. File.WriteString(csHTML);
  314. File.WriteString(_T("</TR>\n"));
  315. }
  316. File.WriteString(_T("</TABLE><P><P>"));
  317. File.WriteString(_T("<TABLE BORDER=0 CELLSPACING=0>"));
  318. File.WriteString(_T("<TR>\n"));
  319. File.WriteString(_T("<TD COLSPAN=3 ALIGN=CENTER>Redirector Report</TD>\n"));
  320. File.WriteString(_T("</TR><TR><TD COLSPAN=3>&nbsp;</TD></TR>\n"));
  321. File.WriteString(_T("<TR BGCOLOR=#E0E0E0>\n"));
  322. File.WriteString(_T("<TD>RedirID</TD>\n"));
  323. File.WriteString(_T("<TD>URL</TD>\n"));
  324. File.WriteString(_T("<TD>FWLink Entry</TD>\n"));
  325. File.WriteString(_T("</TR>\n"));
  326. for (i = 0; i < pDB->m_rgRedirs.GetSize(); i++) {
  327. pRedir = (SdbLocalizedString *) pDB->m_rgRedirs.GetAt(i);
  328. if (pRedir->m_csLangID == pDB->m_pCurrentMakefile->m_csLangID)
  329. {
  330. csRedirID = pRedir->m_csName;
  331. csURL = pRedir->m_csValue;
  332. File.WriteString(_T("<TR>\n"));
  333. csHTML.Format(_T("<TD>%s</TD>\n"), csRedirID);
  334. File.WriteString(csHTML);
  335. csHTML.Format(_T("<TD>%s</TD>\n"), csURL);
  336. File.WriteString(csHTML);
  337. csThisRedirURL = csRedirURL;
  338. csThisRedirURL.Replace(_T("$REDIR_ID$"), csRedirID);
  339. csTemp.Format(_T("%X"), pDB->m_pCurrentMakefile->GetLangMap(pOutputFile->m_csLangID)->m_lcid);
  340. csThisRedirURL.Replace(_T("$LCID$"), csTemp);
  341. csHTML.Format(_T("<TD><A TARGET=\"_new\" HREF=\"%s\">%s</A></TD>\n"),
  342. csThisRedirURL, csThisRedirURL);
  343. File.WriteString(csHTML);
  344. File.WriteString(_T("</TR>\n"));
  345. }
  346. }
  347. File.WriteString(_T("</TABLE></BODY></HTML>"));
  348. File.Close();
  349. }
  350. catch(CFileException* pFileEx) {
  351. pFileEx->Delete();
  352. goto eh;
  353. }
  354. catch(CMemoryException* pMemEx) {
  355. pMemEx->Delete();
  356. goto eh;
  357. }
  358. bSuccess = TRUE;
  359. eh:
  360. return bSuccess;
  361. }