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.

310 lines
7.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: perfanal.cpp
  7. //
  8. // Contents: implementation of CPerformAnalysis
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "snapmgr.h"
  14. #include "PerfAnal.h"
  15. #include "wrapper.h"
  16. #include "util.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CPerformAnalysis dialog
  24. CPerformAnalysis::CPerformAnalysis(CWnd * pParent, UINT nTemplateID)
  25. : CHelpDialog(a215HelpIDs, nTemplateID ? nTemplateID : IDD, pParent)
  26. {
  27. //{{AFX_DATA_INIT(CPerformAnalysis)
  28. m_strLogFile = _T("");
  29. //}}AFX_DATA_INIT
  30. }
  31. void CPerformAnalysis::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CDialog::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CPerformAnalysis)
  35. DDX_Control(pDX, IDOK, m_ctlOK);
  36. DDX_Text(pDX, IDC_ERROR, m_strError);
  37. DDX_Text(pDX, IDC_LOG_FILE, m_strLogFile);
  38. //}}AFX_DATA_MAP
  39. }
  40. BEGIN_MESSAGE_MAP(CPerformAnalysis, CHelpDialog)
  41. //{{AFX_MSG_MAP(CPerformAnalysis)
  42. ON_BN_CLICKED(IDOK, OnOK)
  43. ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  44. ON_EN_CHANGE(IDC_LOG_FILE, OnChangeLogFile)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CPerformAnalysis message handlers
  49. void CPerformAnalysis::OnBrowse()
  50. {
  51. CString strLogFileExt;
  52. CString strLogFileFilter;
  53. CString strTitle;
  54. OPENFILENAME ofn;
  55. ::ZeroMemory (&ofn, sizeof (OPENFILENAME));
  56. ofn.lStructSize = sizeof(OPENFILENAME);
  57. UpdateData(TRUE);
  58. strLogFileExt.LoadString(IDS_LOGFILE_DEF_EXT);
  59. strLogFileFilter.LoadString(IDS_LOGFILE_FILTER);
  60. strTitle.LoadString(IDS_LOGFILE_PICKER_TITLE);
  61. // Translate filter into commdlg format (lots of \0)
  62. LPTSTR szFilter = strLogFileFilter.GetBuffer(0); // modify the buffer in place
  63. // MFC delimits with '|' not '\0'
  64. LPTSTR pch = szFilter;
  65. while ((pch = _tcschr(pch, '|')) != NULL)
  66. *pch++ = '\0';
  67. // do not call ReleaseBuffer() since the string contains '\0' characters
  68. ofn.lpstrFilter = szFilter;
  69. ofn.lpstrFile = m_strLogFile.GetBuffer(MAX_PATH),
  70. ofn.nMaxFile = MAX_PATH;
  71. ofn.lpstrDefExt = strLogFileExt,
  72. ofn.hwndOwner = m_hWnd;
  73. ofn.Flags = OFN_HIDEREADONLY |
  74. OFN_EXPLORER |
  75. OFN_DONTADDTORECENT|
  76. OFN_NOREADONLYRETURN,
  77. ofn.lpstrTitle = strTitle;
  78. //
  79. // Default to the currently picked log file
  80. //
  81. if (GetOpenFileName(&ofn)) {
  82. m_strLogFile.ReleaseBuffer();
  83. UpdateData(FALSE);
  84. } else {
  85. m_strLogFile.ReleaseBuffer();
  86. }
  87. }
  88. //+--------------------------------------------------------------------------
  89. //
  90. // Method: DoIt
  91. //
  92. // Synopsis: Actually Analyzes the system (separated from OnOK so it can
  93. // be overridden to Configure the system, etc. while still using
  94. // the same OnOK shell code
  95. //
  96. //---------------------------------------------------------------------------
  97. DWORD CPerformAnalysis::DoIt() {
  98. //
  99. // Store the log file we're using for next time
  100. //
  101. LPTSTR szLogFile = m_strLogFile.GetBuffer(0);
  102. m_pComponentData->GetWorkingDir(GWD_ANALYSIS_LOG,&szLogFile,TRUE,TRUE);
  103. m_strLogFile.ReleaseBuffer();
  104. //
  105. // InspectSystem will handle multi-threading and progress UI so
  106. // SCE doesn't get wierd on the user
  107. //
  108. return InspectSystem(
  109. NULL, // Always use the configuration assigned to the DB
  110. m_strDataBase.IsEmpty() ? NULL: (LPCTSTR)m_strDataBase,
  111. (LPCTSTR)m_strLogFile,
  112. AREA_ALL
  113. );
  114. }
  115. //+--------------------------------------------------------------------------
  116. //
  117. // Method: OnOK
  118. //
  119. // Synopsis: Analyzes the system
  120. //
  121. //---------------------------------------------------------------------------
  122. afx_msg void CPerformAnalysis::OnOK()
  123. {
  124. CWnd *cwnd;
  125. HANDLE hLogFile;
  126. UpdateData(TRUE);
  127. //
  128. // We require a log file that we can write to
  129. //
  130. if (m_strLogFile.IsEmpty()) {
  131. return;
  132. }
  133. else {
  134. m_strLogFile = ExpandEnvironmentStringWrapper(m_strLogFile);
  135. }
  136. LONG dwPosLow = 0, dwPosHigh = 0;
  137. hLogFile = CreateFile(m_strLogFile, // pointer to name of the file
  138. GENERIC_WRITE, // access (read-write) mode
  139. 0, // share mode
  140. NULL, // pointer to security attributes
  141. OPEN_ALWAYS, // how to create
  142. FILE_ATTRIBUTE_NORMAL, // file attributes
  143. NULL // handle to file with attributes to copy
  144. );
  145. if (INVALID_HANDLE_VALUE == hLogFile) {
  146. CString strFormat;
  147. CString strError;
  148. CString strTitle;
  149. strFormat.LoadString(IDS_CANT_OPEN_LOG_FILE);
  150. strError.Format(strFormat,m_strLogFile);
  151. strTitle.LoadString(IDS_ANALYSIS_VIEWER_NAME);
  152. MessageBox(strError,strTitle,MB_OK);
  153. return;
  154. }
  155. dwPosLow = SetFilePointer(hLogFile, 0, &dwPosHigh, FILE_END );
  156. CloseHandle(hLogFile);
  157. CWaitCursor wc;
  158. DWORD smstatus = ERROR_SUCCESS;
  159. LPNOTIFY pNotify = m_pComponentData->GetNotifier();
  160. ASSERT(pNotify);
  161. //
  162. // Lock the analysis pane since its data is invalid while we're inspecting
  163. //
  164. if (pNotify) {
  165. pNotify->LockAnalysisPane(TRUE);
  166. }
  167. CFolder *pFolder = m_pComponentData->GetAnalFolder();
  168. //
  169. // Force the Analysis root node to be selected so that we display
  170. // the generating information message. If we forse this repaint to happen
  171. // now then we don't seem to have that AV problem.
  172. //
  173. if(pFolder && pNotify){
  174. pNotify->SelectScopeItem(pFolder->GetScopeItem()->ID);
  175. }
  176. //
  177. // Make sure we don't have the database open. That'll prevent us
  178. // from being able to configure.
  179. //
  180. m_pComponentData->UnloadSadInfo();
  181. //
  182. // Disable the child windows so they don't respond to input while we're
  183. // performing the inspection
  184. //
  185. cwnd = GetWindow(GW_CHILD);
  186. while(cwnd) {
  187. cwnd->EnableWindow(FALSE);
  188. cwnd = cwnd->GetNextWindow();
  189. }
  190. //Raid #358503, 4/17/2001
  191. HWND framehwnd = NULL;
  192. LPCONSOLE pconsole = m_pComponentData->GetConsole();
  193. if( pconsole )
  194. {
  195. pconsole->GetMainWindow(&framehwnd);
  196. if( framehwnd )
  197. {
  198. ::EnableWindow(framehwnd, FALSE);
  199. }
  200. }
  201. smstatus = DoIt();
  202. //Raid #358503, 4/17/2001
  203. if( framehwnd )
  204. {
  205. ::EnableWindow(framehwnd, TRUE);
  206. }
  207. //
  208. // The inspection data is valid now, so let people back at it
  209. //
  210. if (pNotify) {
  211. pNotify->LockAnalysisPane(false, false);
  212. }
  213. m_pComponentData->SetErroredLogFile(m_strLogFile, dwPosLow );
  214. //
  215. // There was an error so display the log file (if any)
  216. //
  217. if (ERROR_SUCCESS != smstatus) {
  218. m_pComponentData->SetFlags( CComponentDataImpl::flag_showLogFile );
  219. }
  220. //
  221. // We're done inspecting so reenable input to the child windows
  222. //
  223. cwnd = GetWindow(GW_CHILD);
  224. while(cwnd) {
  225. cwnd->EnableWindow(TRUE);
  226. cwnd = cwnd->GetNextWindow();
  227. }
  228. //CDialog::OnOK();
  229. UpdateData();
  230. DestroyWindow();
  231. }
  232. BOOL CPerformAnalysis::OnInitDialog()
  233. {
  234. CDialog::OnInitDialog();
  235. UpdateData(FALSE);
  236. if (m_strLogFile.IsEmpty()) {
  237. m_ctlOK.EnableWindow(FALSE);
  238. }
  239. m_strOriginalLogFile = m_strLogFile;
  240. return TRUE; // return TRUE unless you set the focus to a control
  241. // EXCEPTION: OCX Property Pages should return FALSE
  242. }
  243. void CPerformAnalysis::OnChangeLogFile()
  244. {
  245. UpdateData(TRUE);
  246. if (m_strLogFile.IsEmpty())
  247. m_ctlOK.EnableWindow(FALSE);
  248. else
  249. m_ctlOK.EnableWindow(TRUE);
  250. m_strError.Empty();
  251. UpdateData(FALSE);
  252. }
  253. void CPerformAnalysis::OnCancel() {
  254. // CDialog::OnCancel();
  255. m_strLogFile = m_strOriginalLogFile;
  256. DestroyWindow();
  257. }