Leaked source code of windows server 2003
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.

136 lines
3.6 KiB

  1. // moninf.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "moninf.h"
  5. #include "moninfDlg.h"
  6. #include "mon.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMoninfApp
  14. BEGIN_MESSAGE_MAP(CMoninfApp, CWinApp)
  15. //{{AFX_MSG_MAP(CMoninfApp)
  16. // NOTE - the ClassWizard will add and remove mapping macros here.
  17. // DO NOT EDIT what you see in these blocks of generated code!
  18. //}}AFX_MSG
  19. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  20. END_MESSAGE_MAP()
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CMoninfApp construction
  23. CMoninfApp::CMoninfApp()
  24. {
  25. // TODO: add construction code here,
  26. // Place all significant initialization in InitInstance
  27. }
  28. /////////////////////////////////////////////////////////////////////////////
  29. // The one and only CMoninfApp object
  30. CMoninfApp theApp;
  31. /////////////////////////////////////////////////////////////////////////////
  32. // Private Functions
  33. void ReadMonitorInfs(LPCSTR);
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMoninfApp initialization
  36. BOOL CMoninfApp::InitInstance()
  37. {
  38. gSumInf.Initialize(REPORT_FILE_NAME);
  39. ReadMonitorInfs(SRC_INF_PATH);
  40. gSumInf.CheckDupSections();
  41. gSumInf.CheckDupMonIDs();
  42. gSumInf.CheckDupAlias();
  43. gSumInf.DumpMonitorInf(DEST_INF_PATH, FILE_BREAK_SIZE);
  44. return FALSE;
  45. }
  46. void ReadMonitorInfs(LPCSTR srcDir)
  47. {
  48. CString fileName;
  49. fileName = CString(srcDir) + "\\*.*";
  50. CFileFind finder;
  51. if (finder.FindFile(fileName))
  52. {
  53. BOOL bWorking = TRUE;
  54. while (bWorking)
  55. {
  56. bWorking = finder.FindNextFile();
  57. if (finder.IsDots())
  58. continue;
  59. if (finder.IsDirectory())
  60. {
  61. ReadMonitorInfs((LPCSTR)finder.GetFilePath());
  62. continue;
  63. }
  64. //////////////////////////////////////////////
  65. // Check if it's INF file
  66. CString fName = finder.GetFileName();
  67. if (stricmp(fName.Right(4), ".inf") != 0)
  68. continue;
  69. CMonitorInf *pMonitorInf = new(CMonitorInf);
  70. if (pMonitorInf == NULL)
  71. continue;
  72. //////////////////////////////////////////////
  73. // Check if it's INF file
  74. ReadOneMonitorInf(finder.GetFilePath(), pMonitorInf);
  75. for (int i = 0; i < pMonitorInf->ManufacturerArray.GetSize(); i++)
  76. gSumInf.AddOneManufacturer((CManufacturer*)pMonitorInf->ManufacturerArray[i]);
  77. pMonitorInf->ManufacturerArray.RemoveAll();
  78. delete pMonitorInf;
  79. }
  80. }
  81. }
  82. VOID ReadOneMonitorInf(LPCSTR fileName, CMonitorInf *pMonitorInf)
  83. {
  84. lstrcpy(gszInputFileName, fileName);
  85. fprintf(gSumInf.m_fpReport, "Handling %s\n", gszInputFileName);
  86. CFile InfFile(fileName, CFile::modeRead);
  87. DWORD len = InfFile.GetLength();
  88. if (len > MAX_INFFILE_SIZE || len <= 20)
  89. return;
  90. pMonitorInf->pReadFileBuf = (LPSTR)malloc(len+1024);
  91. if (pMonitorInf->pReadFileBuf == NULL)
  92. return;
  93. if (InfFile.Read(pMonitorInf->pReadFileBuf, len) < len)
  94. {
  95. free(pMonitorInf->pReadFileBuf);
  96. return;
  97. }
  98. TokenizeInf((LPSTR)pMonitorInf->pReadFileBuf, pMonitorInf);
  99. pMonitorInf->ParseInf();
  100. free(pMonitorInf->pReadFileBuf);
  101. pMonitorInf->pReadFileBuf = NULL;
  102. }