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.

578 lines
17 KiB

  1. // WiaLogCFGDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "WiaLogCFG.h"
  5. #include "WiaLogCFGDlg.h"
  6. #include "AddRemove.h"
  7. #include "LogViewer.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CWiaLogCFGDlg dialog
  15. CWiaLogCFGDlg::CWiaLogCFGDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CWiaLogCFGDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CWiaLogCFGDlg)
  19. m_dwCustomLevel = 0;
  20. //}}AFX_DATA_INIT
  21. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  22. m_bColorCodeLogViewerText = FALSE;
  23. }
  24. void CWiaLogCFGDlg::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CWiaLogCFGDlg)
  28. DDX_Control(pDX, IDC_COLOR_CODE_LOGVIEWER_TEXT, m_ColorCodeLogViewerTextCheckBox);
  29. DDX_Control(pDX, IDC_LOG_TO_DEBUGGER, m_LogToDebuggerCheckBox);
  30. DDX_Control(pDX, IDC_CLEARLOG_ON_BOOT, m_ClearLogOnBootCheckBox);
  31. DDX_Control(pDX, IDC_PARSE_PROGRESS, m_ProgressCtrl);
  32. DDX_Control(pDX, IDC_ADD_TIME, m_AddTimeCheckBox);
  33. DDX_Control(pDX, IDC_ADD_THREADID, m_AddThreadIDCheckBox);
  34. DDX_Control(pDX, IDC_ADD_MODULENAME, m_AddModuleCheckBox);
  35. DDX_Control(pDX, IDC_TRUNCATE_ON_BOOT, m_TruncateOnBootCheckBox);
  36. DDX_Control(pDX, IDC_SELECT_MODULE_COMBOBOX, m_ModuleComboBox);
  37. DDX_Control(pDX, IDC_LOG_LEVEL_WARNING, m_WarningCheckBox);
  38. DDX_Control(pDX, IDC_LOG_LEVEL_ERROR, m_ErrorCheckBox);
  39. DDX_Control(pDX, IDC_LOG_LEVEL_TRACE, m_TraceCheckBox);
  40. DDX_Control(pDX, IDC_FILTER_OFF, m_FilterOff);
  41. DDX_Control(pDX, IDC_FILTER_1, m_Filter1);
  42. DDX_Control(pDX, IDC_FILTER_2, m_Filter2);
  43. DDX_Control(pDX, IDC_FILTER_3, m_Filter3);
  44. DDX_Control(pDX, IDC_FILTER_CUSTOM, m_FilterCustom);
  45. DDX_Text(pDX, IDC_EDIT_CUSTOM_LEVEL, m_dwCustomLevel);
  46. DDV_MinMaxDWord(pDX, m_dwCustomLevel, 0, 9999);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CWiaLogCFGDlg, CDialog)
  50. //{{AFX_MSG_MAP(CWiaLogCFGDlg)
  51. ON_WM_PAINT()
  52. ON_WM_QUERYDRAGICON()
  53. ON_BN_CLICKED(IDC_ADD_MODULE_BUTTON, OnAddModuleButton)
  54. ON_BN_CLICKED(IDC_DELETE_MODULE_BUTTON, OnDeleteModuleButton)
  55. ON_BN_CLICKED(IDC_WRITE_SETTINGS_BUTTON, OnWriteSettingsButton)
  56. ON_CBN_SELCHANGE(IDC_SELECT_MODULE_COMBOBOX, OnSelchangeSelectModuleCombobox)
  57. ON_BN_CLICKED(IDC_CLEARLOG_BUTTON, OnClearlogButton)
  58. ON_BN_CLICKED(IDC_VIEW_LOG_BUTTON, OnViewLogButton)
  59. ON_CBN_SETFOCUS(IDC_SELECT_MODULE_COMBOBOX, OnSetfocusSelectModuleCombobox)
  60. ON_CBN_DROPDOWN(IDC_SELECT_MODULE_COMBOBOX, OnDropdownSelectModuleCombobox)
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CWiaLogCFGDlg message handlers
  65. BOOL CWiaLogCFGDlg::OnInitDialog()
  66. {
  67. m_hInstance = NULL;
  68. m_hInstance = AfxGetInstanceHandle();
  69. CDialog::OnInitDialog();
  70. ShowProgress(FALSE);
  71. SetIcon(m_hIcon, TRUE); // Set big icon
  72. SetIcon(m_hIcon, FALSE); // Set small icon
  73. m_LogInfo.dwLevel = 0;
  74. m_LogInfo.dwMaxSize = 100000;
  75. m_LogInfo.dwMode = 0;
  76. m_LogInfo.dwTruncateOnBoot = 0;
  77. memset(m_LogInfo.szKeyName,0,sizeof(m_LogInfo.szKeyName));
  78. m_CurrentSelection = 0;
  79. InitializeDialogSettings(SETTINGS_RESET_DIALOG);
  80. RegistryOperation(REG_READ);
  81. InitializeDialogSettings(SETTINGS_TO_DIALOG);
  82. CheckGlobalServiceSettings();
  83. return TRUE; // return TRUE unless you set the focus to a control
  84. }
  85. // If you add a minimize button to your dialog, you will need the code below
  86. // to draw the icon. For MFC applications using the document/view model,
  87. // this is automatically done for you by the framework.
  88. void CWiaLogCFGDlg::OnPaint()
  89. {
  90. if (IsIconic())
  91. {
  92. CPaintDC dc(this); // device context for painting
  93. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  94. // Center icon in client rectangle
  95. int cxIcon = GetSystemMetrics(SM_CXICON);
  96. int cyIcon = GetSystemMetrics(SM_CYICON);
  97. CRect rect;
  98. GetClientRect(&rect);
  99. int x = (rect.Width() - cxIcon + 1) / 2;
  100. int y = (rect.Height() - cyIcon + 1) / 2;
  101. // Draw the icon
  102. dc.DrawIcon(x, y, m_hIcon);
  103. }
  104. else
  105. {
  106. CDialog::OnPaint();
  107. }
  108. }
  109. HCURSOR CWiaLogCFGDlg::OnQueryDragIcon()
  110. {
  111. return (HCURSOR) m_hIcon;
  112. }
  113. void CWiaLogCFGDlg::OnAddModuleButton()
  114. {
  115. CAddRemove AddRemoveDlg;
  116. AddRemoveDlg.SetTitle(TEXT("Add a Module"));
  117. AddRemoveDlg.SetStatusText(TEXT("Enter a Module Name:"));
  118. if(AddRemoveDlg.DoModal() == IDOK) {
  119. m_TruncateOnBootCheckBox.SetCheck(0);
  120. m_ClearLogOnBootCheckBox.SetCheck(0);
  121. AddRemoveDlg.GetNewKeyName(m_LogInfo.szKeyName);
  122. RegistryOperation(REG_ADD_KEY);
  123. RegistryOperation(REG_READ);
  124. CheckGlobalServiceSettings();
  125. }
  126. }
  127. void CWiaLogCFGDlg::OnDeleteModuleButton()
  128. {
  129. if(MessageBox(TEXT("Are you sure you want to DELETE this module?"),
  130. TEXT("Delete Module"),
  131. MB_YESNO|MB_ICONQUESTION) == IDYES) {
  132. //
  133. // Delete this module
  134. //
  135. RegistryOperation(REG_DELETE_KEY);
  136. RegistryOperation(REG_READ);
  137. }
  138. }
  139. void CWiaLogCFGDlg::RegistryOperation(ULONG ulFlags)
  140. {
  141. TCHAR szAppRegistryKey[MAX_PATH];
  142. TCHAR szValueName[MAX_PATH];
  143. LoadString(m_hInstance, REGSTR_PATH_STICONTROL, szAppRegistryKey, MAX_PATH);
  144. CRegistry Registry(szAppRegistryKey,HKEY_LOCAL_MACHINE);
  145. //
  146. // move to logging
  147. //
  148. LoadString(m_hInstance,REGSTR_VAL_LOGGING , szValueName, MAX_PATH);
  149. Registry.MoveToSubKey(szValueName);
  150. if(ulFlags == REG_ADD_KEY) {
  151. //
  152. // Add a new key
  153. //
  154. Registry.CreateKey(m_LogInfo.szKeyName);
  155. //
  156. // change current selection to an invalid selection
  157. //
  158. m_CurrentSelection = -99;
  159. return;
  160. }
  161. if( ulFlags == REG_DELETE_KEY) {
  162. //
  163. // delete a Key
  164. //
  165. Registry.DeleteKey(m_LogInfo.szKeyName);
  166. return;
  167. }
  168. //
  169. // enumerate keys
  170. //
  171. DWORD dwIndex = 0;
  172. TCHAR pszKeyName[64];
  173. m_ModuleComboBox.ResetContent();
  174. while(Registry.EnumerateKeys(dwIndex++,pszKeyName, sizeof(pszKeyName)) != ERROR_NO_MORE_ITEMS) {
  175. m_ModuleComboBox.AddString(pszKeyName);
  176. }
  177. if(m_CurrentSelection == -99){
  178. INT nIndex = m_ModuleComboBox.FindString(-1, m_LogInfo.szKeyName);
  179. m_CurrentSelection = nIndex;
  180. m_ModuleComboBox.SetCurSel(nIndex);
  181. } else {
  182. m_ModuleComboBox.GetLBText(m_CurrentSelection,m_LogInfo.szKeyName);
  183. }
  184. m_ModuleComboBox.SetCurSel(m_CurrentSelection);
  185. //
  186. // move to DLL specifc subkey
  187. //
  188. Registry.MoveToSubKey(m_LogInfo.szKeyName);
  189. switch(ulFlags) {
  190. case REG_WRITE:
  191. LoadString(m_hInstance,REGSTR_VAL_LOG_LEVEL , szValueName, MAX_PATH);
  192. Registry.SetValue(szValueName,m_LogInfo.dwLevel);
  193. LoadString(m_hInstance,REGSTR_VAL_MODE , szValueName, MAX_PATH);
  194. Registry.SetValue(szValueName,m_LogInfo.dwMode);
  195. LoadString(m_hInstance,REGSTR_VAL_MAXSIZE , szValueName, MAX_PATH);
  196. Registry.SetValue(szValueName,m_LogInfo.dwMaxSize);
  197. LoadString(m_hInstance,REGSTR_VAL_TRUNCATE_ON_BOOT , szValueName, MAX_PATH);
  198. Registry.SetValue(szValueName,m_LogInfo.dwTruncateOnBoot);
  199. LoadString(m_hInstance,REGSTR_VAL_CLEARLOG_ON_BOOT , szValueName, MAX_PATH);
  200. Registry.SetValue(szValueName,m_LogInfo.dwClearLogOnBoot);
  201. LoadString(m_hInstance,REGSTR_VAL_DETAIL , szValueName, MAX_PATH);
  202. Registry.SetValue(szValueName,m_LogInfo.dwDetail);
  203. LoadString(m_hInstance,REGSTR_VAL_LOG_TO_DEBUGGER, szValueName, MAX_PATH);
  204. Registry.SetValue(szValueName,m_LogInfo.dwLogToDebugger);
  205. break;
  206. case REG_READ:
  207. default:
  208. LoadString(m_hInstance,REGSTR_VAL_LOG_LEVEL , szValueName, MAX_PATH);
  209. m_LogInfo.dwLevel = Registry.GetValue(szValueName,WIALOG_NO_LEVEL);
  210. LoadString(m_hInstance,REGSTR_VAL_MODE , szValueName, MAX_PATH);
  211. m_LogInfo.dwMode = Registry.GetValue(szValueName,WIALOG_ADD_MODULE|WIALOG_ADD_THREAD);
  212. LoadString(m_hInstance,REGSTR_VAL_MAXSIZE , szValueName, MAX_PATH);
  213. m_LogInfo.dwMaxSize = Registry.GetValue(szValueName,100000);
  214. LoadString(m_hInstance,REGSTR_VAL_TRUNCATE_ON_BOOT, szValueName, MAX_PATH);
  215. m_LogInfo.dwTruncateOnBoot = Registry.GetValue(szValueName,0);
  216. LoadString(m_hInstance,REGSTR_VAL_CLEARLOG_ON_BOOT, szValueName, MAX_PATH);
  217. m_LogInfo.dwClearLogOnBoot = Registry.GetValue(szValueName,0);
  218. LoadString(m_hInstance,REGSTR_VAL_DETAIL , szValueName, MAX_PATH);
  219. m_LogInfo.dwDetail = Registry.GetValue(szValueName,0);
  220. LoadString(m_hInstance,REGSTR_VAL_LOG_TO_DEBUGGER, szValueName, MAX_PATH);
  221. m_LogInfo.dwLogToDebugger = Registry.GetValue(szValueName,0);
  222. break;
  223. }
  224. }
  225. void CWiaLogCFGDlg::InitializeDialogSettings(ULONG ulFlags)
  226. {
  227. switch (ulFlags) {
  228. case SETTINGS_TO_DIALOG:
  229. //
  230. // set level of detail
  231. //
  232. switch (m_LogInfo.dwDetail) {
  233. case WIALOG_NO_LEVEL:
  234. m_FilterOff.SetCheck(1);
  235. break;
  236. case WIALOG_LEVEL1 :
  237. m_Filter1.SetCheck(1);
  238. break;
  239. case WIALOG_LEVEL2:
  240. m_Filter2.SetCheck(1);
  241. break;
  242. case WIALOG_LEVEL3:
  243. m_Filter3.SetCheck(1);
  244. break;
  245. default:
  246. m_FilterCustom.SetCheck(1);
  247. m_dwCustomLevel = m_LogInfo.dwDetail;
  248. UpdateData(FALSE);
  249. break;
  250. }
  251. //
  252. // set truncate on boot check box
  253. //
  254. if (m_LogInfo.dwTruncateOnBoot != 0)
  255. m_TruncateOnBootCheckBox.SetCheck(1);
  256. else
  257. m_TruncateOnBootCheckBox.SetCheck(0);
  258. //
  259. // set clear log on boot check box
  260. //
  261. if (m_LogInfo.dwClearLogOnBoot != 0)
  262. m_ClearLogOnBootCheckBox.SetCheck(1);
  263. else
  264. m_ClearLogOnBootCheckBox.SetCheck(0);
  265. //
  266. // set log to debugger check box
  267. //
  268. if (m_LogInfo.dwLogToDebugger != 0)
  269. m_LogToDebuggerCheckBox.SetCheck(1);
  270. else
  271. m_LogToDebuggerCheckBox.SetCheck(0);
  272. //
  273. // set trace level check boxes
  274. //
  275. if (m_LogInfo.dwLevel & WIALOG_TRACE)
  276. m_TraceCheckBox.SetCheck(1);
  277. if (m_LogInfo.dwLevel & WIALOG_ERROR)
  278. m_ErrorCheckBox.SetCheck(1);
  279. if (m_LogInfo.dwLevel & WIALOG_WARNING)
  280. m_WarningCheckBox.SetCheck(1);
  281. //
  282. // set additional details check boxes
  283. //
  284. if (m_LogInfo.dwMode & WIALOG_ADD_TIME)
  285. m_AddTimeCheckBox.SetCheck(1);
  286. if (m_LogInfo.dwMode & WIALOG_ADD_MODULE)
  287. m_AddModuleCheckBox.SetCheck(1);
  288. if (m_LogInfo.dwMode & WIALOG_ADD_THREAD)
  289. m_AddThreadIDCheckBox.SetCheck(1);
  290. break;
  291. case SETTINGS_FROM_DIALOG:
  292. //
  293. // get level of detail
  294. //
  295. if (m_FilterOff.GetCheck() == 1)
  296. m_LogInfo.dwDetail = WIALOG_NO_LEVEL;
  297. if (m_Filter1.GetCheck() == 1)
  298. m_LogInfo.dwDetail = WIALOG_LEVEL1;
  299. if (m_Filter2.GetCheck() == 1)
  300. m_LogInfo.dwDetail = WIALOG_LEVEL2;
  301. if (m_Filter3.GetCheck() == 1)
  302. m_LogInfo.dwDetail = WIALOG_LEVEL3;
  303. if (m_FilterCustom.GetCheck() == 1) {
  304. UpdateData(TRUE);
  305. m_LogInfo.dwDetail = m_dwCustomLevel;
  306. }
  307. //
  308. // get truncate on boot check box
  309. //
  310. if (m_TruncateOnBootCheckBox.GetCheck() == 1)
  311. m_LogInfo.dwTruncateOnBoot = 1;
  312. else
  313. m_LogInfo.dwTruncateOnBoot = 0;
  314. //
  315. // get clear log on boot check box
  316. //
  317. if (m_ClearLogOnBootCheckBox.GetCheck() == 1)
  318. m_LogInfo.dwClearLogOnBoot = 1;
  319. else
  320. m_LogInfo.dwClearLogOnBoot = 0;
  321. //
  322. // get log to debugger check box
  323. //
  324. if(m_LogToDebuggerCheckBox.GetCheck() == 1)
  325. m_LogInfo.dwLogToDebugger = 1;
  326. else
  327. m_LogInfo.dwLogToDebugger = 0;
  328. //
  329. // get trace level check boxes
  330. //
  331. m_LogInfo.dwLevel = 0;
  332. if (m_TraceCheckBox.GetCheck() == 1)
  333. m_LogInfo.dwLevel = m_LogInfo.dwLevel | WIALOG_TRACE;
  334. if (m_ErrorCheckBox.GetCheck() == 1)
  335. m_LogInfo.dwLevel = m_LogInfo.dwLevel | WIALOG_ERROR;
  336. if (m_WarningCheckBox.GetCheck() == 1)
  337. m_LogInfo.dwLevel = m_LogInfo.dwLevel | WIALOG_WARNING;
  338. //
  339. // set additional details check boxes
  340. //
  341. m_LogInfo.dwMode = 0;
  342. if (m_AddTimeCheckBox.GetCheck() == 1)
  343. m_LogInfo.dwMode = m_LogInfo.dwMode | WIALOG_ADD_TIME;
  344. if (m_AddModuleCheckBox.GetCheck() == 1)
  345. m_LogInfo.dwMode = m_LogInfo.dwMode | WIALOG_ADD_MODULE;
  346. if (m_AddThreadIDCheckBox.GetCheck() == 1)
  347. m_LogInfo.dwMode = m_LogInfo.dwMode | WIALOG_ADD_THREAD;
  348. break;
  349. default:
  350. m_FilterOff.SetCheck(0);
  351. m_Filter1.SetCheck(0);
  352. m_Filter2.SetCheck(0);
  353. m_Filter3.SetCheck(0);
  354. m_FilterCustom.SetCheck(0);
  355. m_TruncateOnBootCheckBox.SetCheck(0);
  356. m_TraceCheckBox.SetCheck(0);
  357. m_ErrorCheckBox.SetCheck(0);
  358. m_WarningCheckBox.SetCheck(0);
  359. m_AddTimeCheckBox.SetCheck(0);
  360. m_AddModuleCheckBox.SetCheck(0);
  361. m_AddThreadIDCheckBox.SetCheck(0);
  362. m_dwCustomLevel = 0;
  363. UpdateData(FALSE);
  364. break;
  365. }
  366. }
  367. void CWiaLogCFGDlg::OnOK()
  368. {
  369. InitializeDialogSettings(SETTINGS_FROM_DIALOG);
  370. RegistryOperation(REG_WRITE);
  371. CDialog::OnOK();
  372. }
  373. void CWiaLogCFGDlg::OnWriteSettingsButton()
  374. {
  375. InitializeDialogSettings(SETTINGS_FROM_DIALOG);
  376. RegistryOperation(REG_WRITE);
  377. }
  378. void CWiaLogCFGDlg::OnSelchangeSelectModuleCombobox()
  379. {
  380. m_CurrentSelection = m_ModuleComboBox.GetCurSel();
  381. if(m_CurrentSelection < 0)
  382. return;
  383. CheckGlobalServiceSettings();
  384. InitializeDialogSettings(SETTINGS_RESET_DIALOG);
  385. RegistryOperation(REG_READ);
  386. InitializeDialogSettings(SETTINGS_TO_DIALOG);
  387. }
  388. void CWiaLogCFGDlg::OnClearlogButton()
  389. {
  390. //
  391. // Get Windows Directory
  392. //
  393. TCHAR szLogFilePath[MAX_PATH];
  394. DWORD dwLength = 0;
  395. dwLength = ::GetWindowsDirectory(szLogFilePath,sizeof(szLogFilePath));
  396. if (( dwLength == 0) || !*szLogFilePath ) {
  397. OutputDebugString(TEXT("Could not GetWindowsDirectory()"));
  398. return;
  399. }
  400. //
  401. // Add log file name to Windows Directory
  402. //
  403. lstrcat(lstrcat(szLogFilePath,TEXT("\\")),TEXT("wiaservc.log"));
  404. //
  405. // Create / open Log file
  406. //
  407. HANDLE hLogFile = ::CreateFile(szLogFilePath,
  408. GENERIC_WRITE,
  409. FILE_SHARE_WRITE | FILE_SHARE_READ,
  410. NULL, // security attributes
  411. CREATE_ALWAYS,
  412. FILE_ATTRIBUTE_NORMAL,
  413. NULL); // template file handle
  414. if(hLogFile != NULL)
  415. CloseHandle(hLogFile);
  416. }
  417. void CWiaLogCFGDlg::OnViewLogButton()
  418. {
  419. CLogViewer LogViewer;
  420. if (m_ColorCodeLogViewerTextCheckBox.GetCheck() == 1)
  421. m_bColorCodeLogViewerText = TRUE;
  422. else
  423. m_bColorCodeLogViewerText = FALSE;
  424. LogViewer.ColorizeText(m_bColorCodeLogViewerText);
  425. //
  426. // initialize progress
  427. //
  428. m_ProgCtrl.SetControl(&m_ProgressCtrl);
  429. LogViewer.SetProgressCtrl(&m_ProgCtrl);
  430. ShowProgress(TRUE);
  431. LogViewer.DoModal();
  432. ShowProgress(FALSE);
  433. }
  434. void CWiaLogCFGDlg::ShowProgress(BOOL bShow)
  435. {
  436. if(bShow) {
  437. m_ProgressCtrl.ShowWindow(SW_SHOW);
  438. } else {
  439. m_ProgressCtrl.ShowWindow(SW_HIDE);
  440. }
  441. }
  442. void CWiaLogCFGDlg::OnSetfocusSelectModuleCombobox()
  443. {
  444. OnWriteSettingsButton();
  445. }
  446. void CWiaLogCFGDlg::OnDropdownSelectModuleCombobox()
  447. {
  448. OnWriteSettingsButton();
  449. }
  450. void CWiaLogCFGDlg::CheckGlobalServiceSettings()
  451. {
  452. TCHAR szKeyName[MAX_PATH];
  453. m_ModuleComboBox.GetLBText(m_CurrentSelection,szKeyName);
  454. if(lstrcmp(szKeyName,TEXT("WIASERVC")) == 0) {
  455. m_TruncateOnBootCheckBox.EnableWindow(TRUE);
  456. m_ClearLogOnBootCheckBox.EnableWindow(TRUE);
  457. } else {
  458. m_TruncateOnBootCheckBox.EnableWindow(FALSE);
  459. m_ClearLogOnBootCheckBox.EnableWindow(FALSE);
  460. }
  461. }