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.

256 lines
7.4 KiB

  1. #include "stdafx.h"
  2. #include "mon.h"
  3. extern int compareManufacturers(CManufacturer *, CManufacturer *);
  4. extern int compareMonitors(CMonitor *, CMonitor *);
  5. CSumInf gSumInf;
  6. CSumInf::CSumInf()
  7. {
  8. m_fpReport = NULL;
  9. }
  10. CSumInf::~CSumInf()
  11. {
  12. if (m_fpReport)
  13. fclose(m_fpReport);
  14. for (int i = 0; i < m_ManufacturerArray.GetSize(); i++)
  15. {
  16. delete((CManufacturer *)m_ManufacturerArray[i]);
  17. }
  18. m_ManufacturerArray.RemoveAll();
  19. m_SectionNameArray.RemoveAll();
  20. }
  21. VOID CSumInf::Initialize(LPCSTR reportFileName)
  22. {
  23. m_fpReport = fopen(reportFileName, "w");
  24. if (m_fpReport == NULL)
  25. {
  26. ASSERT(FALSE);
  27. }
  28. m_ManufacturerArray.RemoveAll();
  29. m_SectionNameArray.RemoveAll();
  30. }
  31. VOID CSumInf::AddOneManufacturer(CManufacturer *pManufacturer)
  32. {
  33. /////////////////////////////////////////////////
  34. // Insert the manufacturer into the array.
  35. // It's sorted by name
  36. int comp = 1;
  37. for (int i = 0; i < m_ManufacturerArray.GetSize(); i++)
  38. {
  39. comp = compareManufacturers(pManufacturer, (CManufacturer *)m_ManufacturerArray[i]);
  40. if (comp <= 0)
  41. break;
  42. }
  43. if (comp == 0)
  44. {
  45. MergeOneManufacturer((CManufacturer *)m_ManufacturerArray[i], pManufacturer);
  46. delete pManufacturer;
  47. }
  48. else
  49. {
  50. m_ManufacturerArray.InsertAt(i, (LPVOID)pManufacturer);
  51. }
  52. }
  53. VOID CSumInf::MergeOneManufacturer(CManufacturer *pDestManufacturer,
  54. CManufacturer *pSrcManufacturer)
  55. {
  56. CPtrArray &SrcMonitorArray = pSrcManufacturer->MonitorArray,
  57. &DestMonitorArray = pDestManufacturer->MonitorArray;
  58. for (int i = 0; i < SrcMonitorArray.GetSize(); i++)
  59. {
  60. CMonitor *pMonitor = (CMonitor *)SrcMonitorArray[i];
  61. /////////////////////////////////////////////////
  62. // Insert the monitor into the array.
  63. // It's sorted by ID
  64. int comp = 1;
  65. for (int k = 0; k < DestMonitorArray.GetSize(); k++)
  66. {
  67. comp = compareMonitors(pMonitor, (CMonitor *)DestMonitorArray[k]);
  68. if (comp <= 0)
  69. break;
  70. }
  71. if (comp == 0)
  72. {
  73. fprintf(m_fpReport, "Warning: %s is duplicated. Please Check.\n", pMonitor->ID);
  74. delete pMonitor;
  75. }
  76. else
  77. {
  78. DestMonitorArray.InsertAt(k, (LPVOID)pMonitor);
  79. }
  80. }
  81. SrcMonitorArray.RemoveAll();
  82. }
  83. VOID CSumInf::CheckDupSections(VOID)
  84. {
  85. fprintf(m_fpReport, "\n");
  86. CPtrArray sectionNameArray;
  87. int comp = 1;
  88. for (int i = 0; i < m_ManufacturerArray.GetSize(); i++)
  89. {
  90. CManufacturer *pMan = (CManufacturer *)m_ManufacturerArray[i];
  91. sectionNameArray.Add(pMan->name);
  92. /////////////////////////////////////////////////////////////
  93. // Search for duplicated Install section inside one manufacturer
  94. // Only this duplication is allowed.
  95. for (int j = 0; j < pMan->MonitorArray.GetSize(); j++)
  96. {
  97. CMonitor *pMon = (CMonitor*)pMan->MonitorArray[j];
  98. if (pMon->bDupInstSection)
  99. continue;
  100. for (int k = j+1; k < pMan->MonitorArray.GetSize(); k++)
  101. {
  102. CMonitor *pMon1 = (CMonitor*)pMan->MonitorArray[k];
  103. if (stricmp(pMon->InstallSectionName, pMon1->InstallSectionName) == 0)
  104. {
  105. pMon1->bDupInstSection = TRUE;
  106. fprintf(m_fpReport, "Information: \"%s\" AND \"%s\" have same install section [%s]. Please check.\n",
  107. &pMon->ID[8], &pMon1->ID[8], pMon->InstallSectionName);
  108. }
  109. }
  110. sectionNameArray.Add(pMon->InstallSectionName);
  111. sectionNameArray.Add(pMon->AddRegSectionName);
  112. }
  113. }
  114. fprintf(m_fpReport, "\n");
  115. for (i = 0; i < sectionNameArray.GetSize(); i++)
  116. {
  117. LPCSTR pName = (LPCSTR)sectionNameArray[i];
  118. /////////////////////////////////////////////////
  119. // Insert the sectionName into m_SectionNameArray.
  120. // It's sorted by name
  121. int comp = 1;
  122. for (int j = 0; j < m_SectionNameArray.GetSize(); j++)
  123. {
  124. comp = stricmp(pName, (LPCSTR)m_SectionNameArray[j]);
  125. if (comp <= 0)
  126. break;
  127. }
  128. if (comp == 0)
  129. {
  130. fprintf(m_fpReport, "Error: Found duplicated section %s\n", pName);
  131. }
  132. else
  133. {
  134. m_SectionNameArray.InsertAt(j, (LPVOID)pName);
  135. }
  136. }
  137. fprintf(m_fpReport, "\n");
  138. }
  139. ////////////////////////////////////////////////////////////////////
  140. // Check if different manufacturers may contain same IDs
  141. // So these manufacturers can be potentialy merged
  142. VOID CSumInf::CheckDupMonIDs(VOID)
  143. {
  144. for (int i = 0; i < m_ManufacturerArray.GetSize(); i++)
  145. {
  146. CManufacturer *pMan = (CManufacturer *)m_ManufacturerArray[i];
  147. pMan->m_MonitorIDArray.RemoveAll();
  148. ASSERT(pMan->MonitorArray.GetSize() > 0);
  149. LPCTSTR pID = ((CMonitor*)pMan->MonitorArray[0])->ID;
  150. pMan->m_MonitorIDArray.Add((LPVOID)pID);
  151. for (int j = 1; j < pMan->MonitorArray.GetSize(); j++)
  152. {
  153. CMonitor *pMon = (CMonitor*)pMan->MonitorArray[j];
  154. if (strnicmp(pID, pMon->ID, lstrlen("Monitor\\NEC")) != 0)
  155. {
  156. pID = pMon->ID;
  157. pMan->m_MonitorIDArray.Add((LPVOID)pID);
  158. }
  159. }
  160. }
  161. for (i = 0; i < m_ManufacturerArray.GetSize(); i++)
  162. {
  163. CManufacturer *pMan = (CManufacturer *)m_ManufacturerArray[i];
  164. for (int j = 0; j < pMan->m_MonitorIDArray.GetSize(); j++)
  165. {
  166. LPCTSTR pID = (LPCTSTR)pMan->m_MonitorIDArray[j];
  167. for (int i1 = i+1; i1 < m_ManufacturerArray.GetSize(); i1++)
  168. {
  169. CManufacturer *pMan1 = (CManufacturer *)m_ManufacturerArray[i1];
  170. for (int j1 = 0; j1 < pMan1->m_MonitorIDArray.GetSize(); j1++)
  171. {
  172. LPCTSTR pID1 = (LPCTSTR)pMan1->m_MonitorIDArray[j1];
  173. if (strnicmp(pID, pID1, lstrlen("Monitor\\NEC")) == 0)
  174. {
  175. fprintf(m_fpReport, "Warning: \"%s\" AND \"%s\" have same monitor ID %c%c%c. Consider merging.\n",
  176. pMan->name, pMan1->name, pID[8], pID[9], pID[10]);
  177. }
  178. }
  179. }
  180. }
  181. }
  182. fprintf(m_fpReport, "\n");
  183. }
  184. VOID CSumInf::CheckDupAlias(VOID)
  185. {
  186. LPCOMMON_ALIAS pAlias;
  187. for (int i = 0; i < gCommonAlias.GetSize(); i++)
  188. {
  189. pAlias = gCommonAlias.GetAt(i);
  190. pAlias->refCount = 0;
  191. }
  192. ///////////////////////////////////////////
  193. // Calculate RefCount
  194. for (i = 0; i < m_ManufacturerArray.GetSize(); i++)
  195. {
  196. CManufacturer *pManufacturer = (CManufacturer*)m_ManufacturerArray[i];
  197. pAlias = pManufacturer->pAlias;
  198. ASSERT(pAlias != NULL);
  199. pAlias->refCount++;
  200. for (int j = 0; j < pManufacturer->MonitorArray.GetSize(); j++)
  201. {
  202. CMonitor *pMonitor = (CMonitor*)pManufacturer->MonitorArray[j];
  203. pAlias = pMonitor->pAlias;
  204. ASSERT(pAlias != NULL);
  205. pAlias->refCount++;
  206. }
  207. }
  208. for (i = 0; i < gCommonAlias.GetSize(); i++)
  209. {
  210. pAlias = gCommonAlias.GetAt(i);
  211. if (pAlias->refCount != 1)
  212. {
  213. fprintf(m_fpReport, "Information: String %%%s%% has RefCount %d\n",
  214. pAlias->lpAlias, pAlias->refCount);
  215. }
  216. }
  217. fprintf(m_fpReport, "\n");
  218. }