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.

960 lines
30 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. fileprop.cpp
  5. Abstract:
  6. Implementation of the files property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include "smlogs.h"
  10. #include "smcfgmsg.h"
  11. #include "smlogqry.h"
  12. #include "FileLogs.h"
  13. #include "sqlprop.h"
  14. #include "fileprop.h"
  15. #include "globals.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. USE_HANDLE_MACROS("SMLOGCFG(fileprop.cpp)");
  22. static ULONG
  23. s_aulHelpIds[] =
  24. {
  25. IDC_FILES_COMMENT_EDIT, IDH_FILES_COMMENT_EDIT,
  26. IDC_FILES_LOG_TYPE_COMBO, IDH_FILES_LOG_TYPE_COMBO,
  27. IDC_CFG_BTN, IDH_CFG_BTN,
  28. IDC_FILES_AUTO_SUFFIX_CHK, IDH_FILES_AUTO_SUFFIX_CHK,
  29. IDC_FILES_SUFFIX_COMBO, IDH_FILES_SUFFIX_COMBO,
  30. IDC_FILES_FIRST_SERIAL_EDIT,IDH_FILES_FIRST_SERIAL_EDIT,
  31. IDC_FILES_SAMPLE_DISPLAY, IDH_FILES_SAMPLE_DISPLAY,
  32. IDC_FILES_OVERWRITE_CHK, IDH_FILES_OVERWRITE_CHK,
  33. 0,0
  34. };
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CFilesProperty property page
  37. IMPLEMENT_DYNCREATE(CFilesProperty, CSmPropertyPage)
  38. CFilesProperty::CFilesProperty(MMC_COOKIE mmcCookie, LONG_PTR hConsole)
  39. : CSmPropertyPage ( CFilesProperty::IDD, hConsole )
  40. {
  41. // ::OutputDebugStringA("\nCFilesProperty::CFilesProperty");
  42. // save pointers from arg list
  43. m_pQuery = reinterpret_cast <CSmLogQuery *>(mmcCookie);
  44. m_dwSuffixValue = 0;
  45. m_dwLogFileTypeValue = 0;
  46. m_dwAppendMode = 0;
  47. m_dwMaxSizeInternal = 0;
  48. m_dwSubDlgFocusCtrl = 0;
  49. // EnableAutomation();
  50. //{{AFX_DATA_INIT(CFilesProperty)
  51. m_iLogFileType = -1;
  52. m_dwSuffix = -1;
  53. m_dwSerialNumber = 1;
  54. m_bAutoNameSuffix = FALSE;
  55. m_bOverWriteFile = FALSE;
  56. //}}AFX_DATA_INIT
  57. }
  58. CFilesProperty::CFilesProperty() : CSmPropertyPage ( CFilesProperty::IDD )
  59. {
  60. ASSERT (FALSE); // only the constructor with args above should be used
  61. EnableAutomation();
  62. m_dwSuffixValue = 0;
  63. m_dwAppendMode = 0;
  64. m_dwMaxSizeInternal = 0;
  65. m_dwSubDlgFocusCtrl = 0;
  66. // //{{AFX_DATA_INIT(CFilesProperty)
  67. m_iLogFileType = -1;
  68. m_dwSuffix = -1;
  69. m_dwSerialNumber = 1;
  70. m_bAutoNameSuffix = FALSE;
  71. m_bOverWriteFile = FALSE;
  72. // //}}AFX_DATA_INIT
  73. // CString variables are empty on construction.
  74. }
  75. CFilesProperty::~CFilesProperty()
  76. {
  77. // ::OutputDebugStringA("\nCFilesProperty::~CFilesProperty");
  78. }
  79. void CFilesProperty::OnFinalRelease()
  80. {
  81. // When the last reference for an automation object is released
  82. // OnFinalRelease is called. The base class will automatically
  83. // deletes the object. Add additional cleanup required for your
  84. // object before calling the base class.
  85. CPropertyPage::OnFinalRelease();
  86. }
  87. void CFilesProperty::DoDataExchange(CDataExchange* pDX)
  88. {
  89. CString strTemp;
  90. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  91. CPropertyPage::DoDataExchange(pDX);
  92. //{{AFX_DATA_MAP(CFilesProperty)
  93. DDX_Text(pDX, IDC_FILES_COMMENT_EDIT, m_strCommentText);
  94. DDV_MaxChars(pDX, m_strCommentText, MAX_PATH);
  95. DDX_CBIndex(pDX, IDC_FILES_LOG_TYPE_COMBO, m_iLogFileType);
  96. DDX_CBIndex(pDX, IDC_FILES_SUFFIX_COMBO, m_dwSuffix);
  97. DDX_Check(pDX, IDC_FILES_AUTO_SUFFIX_CHK, m_bAutoNameSuffix);
  98. DDX_Check(pDX, IDC_FILES_OVERWRITE_CHK, m_bOverWriteFile);
  99. ValidateTextEdit(pDX, IDC_FILES_FIRST_SERIAL_EDIT, 6, (DWORD *) & m_dwSerialNumber, eMinFirstSerial, eMaxFirstSerial);
  100. //}}AFX_DATA_MAP
  101. if ( pDX->m_bSaveAndValidate ) {
  102. m_dwLogFileTypeValue = (DWORD)((CComboBox *)GetDlgItem(IDC_FILES_LOG_TYPE_COMBO))->GetItemData(m_iLogFileType);
  103. if ( m_bAutoNameSuffix ) {
  104. m_dwSuffixValue = (DWORD)((CComboBox *)GetDlgItem(IDC_FILES_SUFFIX_COMBO))->GetItemData(m_dwSuffix);
  105. }
  106. }
  107. }
  108. BEGIN_MESSAGE_MAP(CFilesProperty, CSmPropertyPage)
  109. //{{AFX_MSG_MAP(CFilesProperty)
  110. ON_WM_DESTROY()
  111. ON_BN_CLICKED(IDC_FILES_AUTO_SUFFIX_CHK, OnAutoSuffixChk)
  112. ON_BN_CLICKED(IDC_FILES_OVERWRITE_CHK, OnOverWriteChk)
  113. ON_EN_CHANGE(IDC_FILES_COMMENT_EDIT, OnChangeFilesCommentEdit)
  114. ON_EN_KILLFOCUS(IDC_FILES_COMMENT_EDIT, OnKillfocusFilesCommentEdit)
  115. ON_EN_CHANGE(IDC_FILES_FIRST_SERIAL_EDIT, OnChangeFilesFirstSerialEdit)
  116. ON_EN_KILLFOCUS(IDC_FILES_FIRST_SERIAL_EDIT, OnKillfocusFirstSerialEdit)
  117. ON_CBN_SELENDOK(IDC_FILES_LOG_TYPE_COMBO, OnSelendokFilesLogFileTypeCombo)
  118. ON_CBN_SELENDOK(IDC_FILES_SUFFIX_COMBO, OnSelendokFilesSuffixCombo)
  119. ON_CBN_KILLFOCUS(IDC_FILES_SUFFIX_COMBO, OnKillfocusFilesSuffixCombo)
  120. ON_CBN_KILLFOCUS(IDC_FILES_LOG_TYPE_COMBO, OnKillfocusFilesLogFileTypeCombo)
  121. ON_BN_CLICKED(IDC_CFG_BTN, OnCfgBtn)
  122. //}}AFX_MSG_MAP
  123. END_MESSAGE_MAP()
  124. BEGIN_DISPATCH_MAP(CFilesProperty, CSmPropertyPage)
  125. //{{AFX_DISPATCH_MAP(CFilesProperty)
  126. // NOTE - the ClassWizard will add and remove mapping macros here.
  127. //}}AFX_DISPATCH_MAP
  128. END_DISPATCH_MAP()
  129. // Note: we add support for IID_IFilesProperty to support typesafe binding
  130. // from VBA. This IID must match the GUID that is attached to the
  131. // dispinterface in the .ODL file.
  132. // {65154EAB-BDBE-11D1-BF99-00C04F94A83A}
  133. static const IID IID_IFilesProperty =
  134. { 0x65154eab, 0xbdbe, 0x11d1, { 0xbf, 0x99, 0x0, 0xc0, 0x4f, 0x94, 0xa8, 0x3a } };
  135. BEGIN_INTERFACE_MAP(CFilesProperty, CSmPropertyPage)
  136. INTERFACE_PART(CFilesProperty, IID_IFilesProperty, Dispatch)
  137. END_INTERFACE_MAP()
  138. void
  139. CFilesProperty::EnableSerialNumber( void )
  140. {
  141. BOOL bEnable = ( SLF_NAME_NNNNNN == m_dwSuffixValue );
  142. if ( bEnable )
  143. bEnable = m_bAutoNameSuffix;
  144. GetDlgItem(IDC_FILES_FIRST_SERIAL_CAPTION)->EnableWindow( bEnable );
  145. GetDlgItem(IDC_FILES_FIRST_SERIAL_EDIT)->EnableWindow( bEnable );
  146. }
  147. BOOL
  148. CFilesProperty::UpdateSampleFileName( void )
  149. {
  150. CString strCompositeName;
  151. BOOL bIsValid = TRUE;
  152. DWORD dwLocalSuffixValue = SLF_NAME_NONE;
  153. ResourceStateManager rsm;
  154. if (m_bAutoNameSuffix) {
  155. dwLocalSuffixValue = m_dwSuffixValue;
  156. }
  157. CreateSampleFileName (
  158. m_pQuery->GetLogName(),
  159. m_pQuery->GetLogService()->GetMachineName(),
  160. m_strFolderName,
  161. m_strFileBaseName,
  162. m_strSqlName,
  163. dwLocalSuffixValue,
  164. m_dwLogFileTypeValue,
  165. m_dwSerialNumber,
  166. strCompositeName );
  167. m_strSampleFileName = strCompositeName;
  168. // Or call UpdateData ( FALSE );
  169. SetDlgItemText (IDC_FILES_SAMPLE_DISPLAY, strCompositeName);
  170. // Clear the selection
  171. ((CEdit*)GetDlgItem( IDC_FILES_SAMPLE_DISPLAY ))->SetSel ( -1, FALSE );
  172. if ( MAX_PATH <= m_strSampleFileName.GetLength() ) {
  173. bIsValid = FALSE;
  174. }
  175. return bIsValid;
  176. }
  177. void
  178. CFilesProperty::HandleLogTypeChange()
  179. {
  180. int nSel;
  181. nSel = ((CComboBox *)GetDlgItem(IDC_FILES_LOG_TYPE_COMBO))->GetCurSel();
  182. // nSel != m_iLogFileType determines data change.
  183. if ((nSel != LB_ERR) && (nSel != m_iLogFileType)) {
  184. UpdateData( TRUE );
  185. if ( (m_pQuery->GetLogService()->TargetOs() == OS_WIN2K) ||
  186. (SLF_BIN_FILE != m_dwLogFileTypeValue && SLF_SEQ_TRACE_FILE != m_dwLogFileTypeValue ))
  187. {
  188. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow(FALSE);
  189. } else {
  190. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow( TRUE );
  191. }
  192. OnOverWriteChk();
  193. EnableSerialNumber();
  194. UpdateSampleFileName();
  195. SetModifiedPage(TRUE);
  196. }
  197. }
  198. BOOL
  199. CFilesProperty::IsValidLocalData()
  200. {
  201. BOOL bIsValid = TRUE;
  202. CString strTest;
  203. eValueRange eMaxFileSize;
  204. ResourceStateManager rsm;
  205. // assumes UpdateData has been called
  206. if ( !UpdateSampleFileName() ) {
  207. CString strMessage;
  208. strMessage.LoadString ( IDS_FILE_ERR_NAMETOOLONG );
  209. MessageBox ( strMessage, m_pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  210. bIsValid = FALSE;
  211. if ( SLF_SQL_LOG != m_dwLogFileTypeValue ) {
  212. m_dwSubDlgFocusCtrl = IDC_FILES_FILENAME_EDIT;
  213. } else {
  214. m_dwSubDlgFocusCtrl = IDC_SQL_LOG_SET_EDIT;
  215. }
  216. OnCfgBtn();
  217. }
  218. if ( bIsValid ) {
  219. if ( m_strFolderName.IsEmpty() && (SLF_SQL_LOG != m_dwLogFileTypeValue)) {
  220. CString strMessage;
  221. strMessage.LoadString ( IDS_FILE_ERR_NOFOLDERNAME );
  222. MessageBox ( strMessage, m_pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  223. bIsValid = FALSE;
  224. m_dwSubDlgFocusCtrl = IDC_FILES_FOLDER_EDIT;
  225. OnCfgBtn();
  226. }
  227. }
  228. if ( bIsValid ) {
  229. if ( SLF_SQL_LOG != m_dwLogFileTypeValue ) {
  230. if ( m_strFileBaseName.IsEmpty() && !m_bAutoNameSuffix ) {
  231. CString strMessage;
  232. strMessage.LoadString ( IDS_FILE_ERR_NOFILENAME );
  233. MessageBox ( strMessage, m_pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  234. bIsValid = FALSE;
  235. m_dwSubDlgFocusCtrl = IDC_FILES_FILENAME_EDIT;
  236. OnCfgBtn();
  237. }
  238. if ( bIsValid ) {
  239. if ( !FileNameIsValid ( &m_strFileBaseName ) ) {
  240. CString strMessage;
  241. strMessage.LoadString (IDS_ERRMSG_INVALIDCHAR);
  242. MessageBox( strMessage, m_pQuery->GetLogName(), MB_OK| MB_ICONERROR );
  243. bIsValid = FALSE;
  244. m_dwSubDlgFocusCtrl = IDC_FILES_FILENAME_EDIT;
  245. OnCfgBtn();
  246. }
  247. }
  248. } else {
  249. ExtractDSN ( strTest );
  250. if ( strTest.IsEmpty() ) {
  251. CString strMessage;
  252. strMessage.LoadString ( IDS_SQL_ERR_NODSN );
  253. MessageBox ( strMessage, m_pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  254. bIsValid = FALSE;
  255. m_dwSubDlgFocusCtrl = IDC_SQL_DSN_COMBO;
  256. OnCfgBtn();
  257. }
  258. if ( bIsValid ) {
  259. ExtractLogSetName ( strTest );
  260. if ( strTest.IsEmpty() && !m_bAutoNameSuffix ) {
  261. CString strMessage;
  262. strMessage.LoadString ( IDS_SQL_ERR_NOLOGSETNAME );
  263. MessageBox ( strMessage, m_pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  264. bIsValid = FALSE;
  265. m_dwSubDlgFocusCtrl = IDC_SQL_LOG_SET_EDIT;
  266. OnCfgBtn();
  267. } else if ( !FileNameIsValid ( &strTest ) ){
  268. CString strMessage;
  269. strMessage.LoadString (IDS_ERRMSG_INVALIDCHAR);
  270. MessageBox( strMessage, m_pQuery->GetLogName(), MB_OK| MB_ICONERROR );
  271. bIsValid = FALSE;
  272. m_dwSubDlgFocusCtrl = IDC_SQL_LOG_SET_EDIT;
  273. OnCfgBtn();
  274. }
  275. }
  276. }
  277. }
  278. // Must set max log file size if circular file.
  279. if (bIsValid)
  280. {
  281. if ( SLQ_DISK_MAX_SIZE == m_dwMaxSizeInternal
  282. && ( SLF_BIN_CIRC_FILE == m_dwLogFileTypeValue
  283. || SLF_CIRC_TRACE_FILE == m_dwLogFileTypeValue ) )
  284. {
  285. CString strMessage;
  286. strMessage.LoadString ( IDS_ERRMSG_SETMAXSIZE );
  287. MessageBox ( strMessage, m_pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  288. bIsValid = FALSE;
  289. m_dwSubDlgFocusCtrl = IDC_FILES_SIZE_LIMIT_EDIT;
  290. m_dwMaxSizeInternal = eMinFileLimit; // Default value
  291. OnCfgBtn();
  292. }
  293. }
  294. // Validate max log file size based on log file type
  295. if ( bIsValid ){
  296. if ( SLQ_DISK_MAX_SIZE != m_dwMaxSizeInternal ) {
  297. if ( SLF_BIN_FILE == m_dwLogFileTypeValue ) {
  298. eMaxFileSize = eMaxCtrSeqBinFileLimit;
  299. } else if ( SLF_SEQ_TRACE_FILE == m_dwLogFileTypeValue ) {
  300. eMaxFileSize = eMaxTrcSeqBinFileLimit;
  301. } else if ( SLF_SQL_LOG == m_dwLogFileTypeValue ) {
  302. eMaxFileSize = eMaxSqlRecordsLimit;
  303. } else {
  304. eMaxFileSize = eMaxFileLimit;
  305. }
  306. bIsValid = ValidateDWordInterval(IDC_CFG_BTN,
  307. m_pQuery->GetLogName(),
  308. (long) m_dwMaxSizeInternal,
  309. eMinFileLimit,
  310. eMaxFileSize);
  311. if ( !bIsValid ) {
  312. if ( SLF_SQL_LOG == m_dwLogFileTypeValue ) {
  313. m_dwSubDlgFocusCtrl = IDC_SQL_SIZE_LIMIT_EDIT;
  314. } else {
  315. m_dwSubDlgFocusCtrl = IDC_FILES_SIZE_LIMIT_EDIT;
  316. }
  317. OnCfgBtn();
  318. }
  319. }
  320. }
  321. if (bIsValid)
  322. {
  323. bIsValid = ValidateDWordInterval(IDC_FILES_FIRST_SERIAL_EDIT,
  324. m_pQuery->GetLogName(),
  325. (long) m_dwSerialNumber,
  326. eMinFirstSerial,
  327. eMaxFirstSerial);
  328. }
  329. return bIsValid;
  330. }
  331. /////////////////////////////////////////////////////////////////////////////
  332. // CFilesProperty message handlers
  333. void
  334. CFilesProperty::OnCancel()
  335. {
  336. m_pQuery->SyncPropPageSharedData(); // Clear the memory shared between property pages.
  337. }
  338. BOOL
  339. CFilesProperty::OnApply()
  340. {
  341. BOOL bContinue = TRUE;
  342. ResourceStateManager rsm;
  343. // load data from dialog
  344. bContinue = UpdateData (TRUE);
  345. if ( bContinue ) {
  346. bContinue = IsValidData(m_pQuery, VALIDATE_APPLY );
  347. }
  348. if ( bContinue ) {
  349. bContinue = SampleTimeIsLessThanSessionTime ( m_pQuery );
  350. }
  351. // pass data to the query object
  352. if ( bContinue ) {
  353. bContinue = UpdateSharedData( TRUE );
  354. }
  355. if ( bContinue ) {
  356. m_pQuery->SetLogComment(m_strCommentText);
  357. m_pQuery->SetFileNameParts(m_strFolderName, m_strFileBaseName);
  358. m_pQuery->SetSqlName(m_strSqlName);
  359. if ( TRUE == m_bAutoNameSuffix ) {
  360. m_pQuery->SetFileNameAutoFormat(m_dwSuffixValue);
  361. } else {
  362. m_pQuery->SetFileNameAutoFormat(SLF_NAME_NONE);
  363. }
  364. m_pQuery->SetFileSerialNumber( m_dwSerialNumber );
  365. m_pQuery->SetMaxSize(m_dwMaxSizeInternal);
  366. // Save property page shared data.
  367. m_pQuery->UpdatePropPageSharedData();
  368. if ( LOWORD(m_dwLogFileTypeValue) == SLF_BIN_FILE
  369. || SLF_SEQ_TRACE_FILE == LOWORD(m_dwLogFileTypeValue) ) {
  370. if ( m_bOverWriteFile ) {
  371. m_pQuery->SetDataStoreAppendMode( SLF_DATA_STORE_OVERWRITE );
  372. } else {
  373. m_pQuery->SetDataStoreAppendMode( SLF_DATA_STORE_APPEND );
  374. }
  375. } else {
  376. if ( SLF_SQL_LOG == LOWORD(m_dwLogFileTypeValue) ) {
  377. m_pQuery->SetDataStoreAppendMode ( SLF_DATA_STORE_APPEND );
  378. } else {
  379. m_pQuery->SetDataStoreAppendMode ( SLF_DATA_STORE_OVERWRITE );
  380. }
  381. }
  382. m_pQuery->SetLogFileType ( m_dwLogFileTypeValue );
  383. if ( bContinue ) {
  384. // ApplyRunAs must be called before UpdateService
  385. bContinue = ApplyRunAs(m_pQuery);
  386. }
  387. bContinue = CSmPropertyPage::OnApply();
  388. // Sync the service with changes.
  389. if ( bContinue ) {
  390. bContinue = UpdateService( m_pQuery, FALSE );
  391. if ( bContinue ) {
  392. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  393. CWaitCursor WaitCursor;
  394. // Service might have changed the serial number, so sync it.
  395. // Don't sync data that is modified by other pages.
  396. m_pQuery->SyncSerialNumberWithRegistry();
  397. m_dwSerialNumber = m_pQuery->GetFileSerialNumber();
  398. }
  399. }
  400. }
  401. return bContinue;
  402. }
  403. BOOL CFilesProperty::OnInitDialog()
  404. {
  405. UINT nIndex;
  406. CString strComboBoxString;
  407. CComboBox *pCombo;
  408. UINT nResult;
  409. DWORD dwEntries;
  410. PCOMBO_BOX_DATA_MAP pCbData;
  411. ResourceStateManager rsm;
  412. m_strLogName = m_pQuery->GetLogName();
  413. m_pQuery->GetLogComment ( m_strCommentText );
  414. // Why get max size internal when it is in the shared data?
  415. // This should not be a problem, because only this page
  416. // modifies the value, and GetMaxSize is only called in OnInitDialog.
  417. m_dwMaxSizeInternal = m_pQuery->GetMaxSize();
  418. // load log file type combo box
  419. m_pQuery->GetLogFileType ( m_dwLogFileTypeValue );
  420. //
  421. // If remote box is Win2K system, we don't support SQL data base, use
  422. // .CSV instead
  423. //
  424. if (m_dwLogFileTypeValue == SLF_SQL_LOG && m_pQuery->GetLogService()->TargetOs() == OS_WIN2K) {
  425. m_dwLogFileTypeValue = SLF_CSV_FILE;
  426. }
  427. m_pQuery->GetDataStoreAppendMode ( dwEntries );
  428. m_bOverWriteFile = ( SLF_DATA_STORE_OVERWRITE == dwEntries );
  429. if ( SLQ_TRACE_LOG == m_pQuery->GetLogType() ) {
  430. dwEntries = dwTraceFileTypeComboEntries;
  431. pCbData = (PCOMBO_BOX_DATA_MAP)&TraceFileTypeCombo[0];
  432. } else {
  433. dwEntries = dwFileTypeComboEntries;
  434. pCbData = (PCOMBO_BOX_DATA_MAP)&FileTypeCombo[0];
  435. }
  436. pCombo = (CComboBox *)GetDlgItem(IDC_FILES_LOG_TYPE_COMBO);
  437. pCombo->ResetContent();
  438. for (nIndex = 0; nIndex < dwEntries; nIndex++) {
  439. if (pCbData[nIndex].nResId == IDS_FT_SQL && m_pQuery->GetLogService()->TargetOs() == OS_WIN2K) {
  440. continue;
  441. }
  442. strComboBoxString.LoadString( pCbData[nIndex].nResId );
  443. nResult = pCombo->InsertString (nIndex, (LPCWSTR)strComboBoxString);
  444. ASSERT (nResult != CB_ERR);
  445. nResult = pCombo->SetItemData (nIndex, (DWORD)pCbData[nIndex].nData);
  446. ASSERT (nResult != CB_ERR);
  447. // set log type in combo box here
  448. if (m_dwLogFileTypeValue == (int)(pCbData[nIndex].nData)) {
  449. m_iLogFileType = nIndex;
  450. nResult = pCombo->SetCurSel(nIndex);
  451. ASSERT (nResult != CB_ERR);
  452. if ( SLF_BIN_FILE != m_dwLogFileTypeValue
  453. && SLF_SEQ_TRACE_FILE != m_dwLogFileTypeValue )
  454. {
  455. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow(FALSE);
  456. } else {
  457. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow( TRUE );
  458. }
  459. }
  460. }
  461. if (m_pQuery->GetLogService()->TargetOs() == OS_WIN2K) {
  462. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow(FALSE);
  463. }
  464. m_pQuery->GetFileNameParts ( m_strFolderName, m_strFileBaseName );
  465. m_pQuery->GetSqlName ( m_strSqlName );
  466. m_dwSerialNumber = m_pQuery->GetFileSerialNumber();
  467. // load the filename suffix combo box here
  468. m_dwSuffixValue = m_pQuery->GetFileNameAutoFormat();
  469. pCombo = (CComboBox *)GetDlgItem(IDC_FILES_SUFFIX_COMBO);
  470. pCombo->ResetContent();
  471. for (nIndex = 0; nIndex < dwFileNameSuffixComboEntries; nIndex++) {
  472. strComboBoxString.LoadString ( FileNameSuffixCombo[nIndex].nResId );
  473. nResult = pCombo->InsertString (nIndex, (LPCWSTR)strComboBoxString);
  474. ASSERT (nResult != CB_ERR);
  475. pCombo->SetItemData (nIndex, (DWORD)FileNameSuffixCombo[nIndex].nData);
  476. ASSERT (nResult != CB_ERR);
  477. // set the correct entry in the combo box here
  478. if (m_dwSuffixValue == (int)(FileNameSuffixCombo[nIndex].nData)) {
  479. m_dwSuffix = nIndex;
  480. nResult = pCombo->SetCurSel(nIndex);
  481. ASSERT (nResult != CB_ERR);
  482. }
  483. if ( SLF_NAME_NNNNNN == (int)(FileNameSuffixCombo[nIndex].nData ) ) {
  484. m_dwSuffixIndexNNNNNN = nIndex;
  485. }
  486. }
  487. if ( SLF_NAME_NONE == m_dwSuffixValue ) {
  488. // then the combo box will not have been selected so:
  489. pCombo->SetCurSel(m_dwSuffixIndexNNNNNN);
  490. // disable
  491. pCombo->EnableWindow(FALSE);
  492. // and clear the check box
  493. m_bAutoNameSuffix = FALSE;
  494. } else {
  495. m_bAutoNameSuffix = TRUE;
  496. }
  497. // set the check box in UpdateData ( FALSE );
  498. // update the dialog box
  499. CSmPropertyPage::OnInitDialog();
  500. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  501. EnableSerialNumber();
  502. UpdateSampleFileName();
  503. SetModifiedPage( FALSE );
  504. return TRUE; // return TRUE unless you set the focus to a control
  505. // EXCEPTION: OCX Property Pages should return FALSE
  506. }
  507. void
  508. CFilesProperty::OnAutoSuffixChk()
  509. {
  510. UpdateData( TRUE );
  511. // enable the suffix combo window based on the state of the button
  512. GetDlgItem(IDC_FILES_SUFFIX_COMBO)->EnableWindow (m_bAutoNameSuffix);
  513. if (m_bAutoNameSuffix) {
  514. if ( SLF_NAME_NONE == m_dwSuffixValue ) {
  515. // then initialize a new default
  516. // select the default serial numbering
  517. ((CComboBox *)(GetDlgItem(IDC_FILES_SUFFIX_COMBO)))->SetCurSel( m_dwSuffixIndexNNNNNN );
  518. m_dwSuffixValue = SLF_NAME_NNNNNN;
  519. }
  520. }
  521. EnableSerialNumber();
  522. UpdateSampleFileName();
  523. // This method is only called when the checkbox value has changed.
  524. SetModifiedPage(TRUE);
  525. }
  526. void
  527. CFilesProperty::OnOverWriteChk()
  528. {
  529. BOOL bOldValue;
  530. bOldValue = m_bOverWriteFile;
  531. UpdateData(TRUE);
  532. if (bOldValue != m_bOverWriteFile) {
  533. SetModifiedPage(TRUE);
  534. }
  535. }
  536. void CFilesProperty::OnChangeFilesFirstSerialEdit()
  537. {
  538. DWORD dwOldValue;
  539. dwOldValue = m_dwSerialNumber;
  540. UpdateData( TRUE );
  541. UpdateSampleFileName();
  542. if (dwOldValue != m_dwSerialNumber) {
  543. SetModifiedPage(TRUE);
  544. }
  545. }
  546. void CFilesProperty::OnChangeFilesCommentEdit()
  547. {
  548. CString strOldText;
  549. strOldText = m_strCommentText;
  550. UpdateData ( TRUE );
  551. if ( 0 != strOldText.Compare ( m_strCommentText ) ) {
  552. SetModifiedPage(TRUE);
  553. }
  554. }
  555. void CFilesProperty::OnSelendokFilesSuffixCombo()
  556. {
  557. int nSel;
  558. nSel = ((CComboBox *)GetDlgItem(IDC_FILES_SUFFIX_COMBO))->GetCurSel();
  559. // Check of m_dwSuffix ensures that the value has changed.
  560. if ( LB_ERR != nSel && m_dwSuffix != nSel ) {
  561. UpdateData ( TRUE );
  562. EnableSerialNumber();
  563. /*
  564. if (m_dwLogFileTypeValue == SLF_BIN_FILE) {
  565. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow(
  566. m_dwSuffixValue == SLF_NAME_NNNNNN ? FALSE : TRUE);
  567. }
  568. else {
  569. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow(FALSE);
  570. }
  571. */
  572. UpdateSampleFileName();
  573. SetModifiedPage(TRUE);
  574. }
  575. }
  576. void
  577. CFilesProperty::OnSelendokFilesLogFileTypeCombo()
  578. {
  579. HandleLogTypeChange();
  580. return;
  581. }
  582. void CFilesProperty::OnKillfocusFilesCommentEdit()
  583. {
  584. CString strOldText;
  585. strOldText = m_strCommentText;
  586. UpdateData ( TRUE );
  587. if ( 0 != strOldText.Compare ( m_strCommentText ) ) {
  588. SetModifiedPage(TRUE);
  589. }
  590. }
  591. void CFilesProperty::OnKillfocusFirstSerialEdit()
  592. {
  593. DWORD dwOldValue;
  594. dwOldValue = m_dwSerialNumber;
  595. UpdateData ( TRUE );
  596. if (dwOldValue != m_dwSerialNumber) {
  597. SetModifiedPage(TRUE);
  598. }
  599. }
  600. void CFilesProperty::OnKillfocusFilesSuffixCombo()
  601. {
  602. int nSel;
  603. nSel = ((CComboBox *)GetDlgItem(IDC_FILES_SUFFIX_COMBO))->GetCurSel();
  604. if ((nSel != LB_ERR) && (nSel != m_dwSuffix)) {
  605. SetModifiedPage(TRUE);
  606. }
  607. }
  608. void CFilesProperty::OnKillfocusFilesLogFileTypeCombo()
  609. {
  610. int nSel;
  611. nSel = ((CComboBox *)GetDlgItem(IDC_FILES_LOG_TYPE_COMBO))->GetCurSel();
  612. if ((nSel != LB_ERR) && (nSel != m_iLogFileType)) {
  613. SetModifiedPage(TRUE);
  614. }
  615. }
  616. void CFilesProperty::PostNcDestroy()
  617. {
  618. // delete this;
  619. CPropertyPage::PostNcDestroy();
  620. }
  621. BOOL
  622. CFilesProperty::UpdateSharedData( BOOL bUpdateModel )
  623. {
  624. BOOL bContinue = TRUE;
  625. if ( SLQ_AUTO_MODE_SIZE == m_SharedData.stiStopTime.dwAutoMode ) {
  626. CString strMsg;
  627. if ( ( SLF_BIN_CIRC_FILE == m_dwLogFileTypeValue
  628. || SLF_CIRC_TRACE_FILE == m_dwLogFileTypeValue )
  629. || SLQ_DISK_MAX_SIZE == m_dwMaxSizeInternal )
  630. {
  631. if ( SLF_BIN_CIRC_FILE == m_dwLogFileTypeValue
  632. || SLF_CIRC_TRACE_FILE == m_dwLogFileTypeValue )
  633. {
  634. strMsg.LoadString ( IDS_FILE_CIRC_SET_MANUAL_STOP );
  635. } else {
  636. ASSERT( SLQ_DISK_MAX_SIZE == m_dwMaxSizeInternal );
  637. strMsg.LoadString ( IDS_FILE_MAX_SET_MANUAL_STOP );
  638. }
  639. MessageBox( strMsg, m_pQuery->GetLogName(), MB_OK | MB_ICONINFORMATION);
  640. m_SharedData.stiStopTime.dwAutoMode = SLQ_AUTO_MODE_NONE;
  641. if ( bUpdateModel ) {
  642. SLQ_TIME_INFO slqTime;
  643. memset (&slqTime, 0, sizeof(slqTime));
  644. slqTime.wTimeType = SLQ_TT_TTYPE_STOP;
  645. slqTime.wDataType = SLQ_TT_DTYPE_DATETIME;
  646. slqTime.dwAutoMode = SLQ_AUTO_MODE_NONE;
  647. bContinue = m_pQuery->SetLogTime ( &slqTime, (DWORD)slqTime.wTimeType );
  648. }
  649. }
  650. }
  651. m_SharedData.strFileBaseName = m_strFileBaseName;
  652. m_SharedData.strFolderName = m_strFolderName;
  653. m_SharedData.strSqlName = m_strSqlName;
  654. m_SharedData.dwLogFileType = m_dwLogFileTypeValue;
  655. if ( TRUE == m_bAutoNameSuffix ) {
  656. m_SharedData.dwSuffix = m_dwSuffixValue;
  657. } else {
  658. m_SharedData.dwSuffix = SLF_NAME_NONE;
  659. }
  660. m_SharedData.dwSerialNumber = m_dwSerialNumber;
  661. m_SharedData.dwMaxFileSize = m_dwMaxSizeInternal;
  662. m_pQuery->SetPropPageSharedData ( &m_SharedData );
  663. return bContinue;
  664. }
  665. BOOL CFilesProperty::OnKillActive()
  666. {
  667. BOOL bContinue = TRUE;
  668. ResourceStateManager rsm;
  669. bContinue = CPropertyPage::OnKillActive();
  670. if ( bContinue ) {
  671. bContinue = IsValidData(m_pQuery, VALIDATE_FOCUS );
  672. }
  673. if ( bContinue ) {
  674. m_SharedData.dwLogFileType = m_dwLogFileTypeValue;
  675. bContinue = UpdateSharedData( FALSE );
  676. }
  677. if ( bContinue ) {
  678. SetIsActive ( FALSE );
  679. }
  680. return bContinue;
  681. }
  682. BOOL CFilesProperty::OnSetActive()
  683. {
  684. BOOL bReturn;
  685. bReturn = CSmPropertyPage::OnSetActive();
  686. if ( bReturn ) {
  687. m_pQuery->GetPropPageSharedData ( &m_SharedData );
  688. UpdateData( FALSE );
  689. }
  690. return bReturn;
  691. }
  692. DWORD
  693. CFilesProperty::ExtractDSN ( CString& rstrDSN )
  694. {
  695. DWORD dwStatus = ERROR_SUCCESS;
  696. INT iTotalLength;
  697. INT iRightLength;
  698. // Format string: "SQL:%s!%s"
  699. MFC_TRY
  700. iTotalLength = m_strSqlName.GetLength();
  701. iRightLength = iTotalLength - m_strSqlName.Find(L"!");
  702. rstrDSN = m_strSqlName.Mid ( 4, iTotalLength - iRightLength - 4 );
  703. MFC_CATCH_DWSTATUS;
  704. return dwStatus;
  705. }
  706. DWORD
  707. CFilesProperty::ExtractLogSetName ( CString& rstrLogSetName )
  708. {
  709. DWORD dwStatus = ERROR_SUCCESS;
  710. // Format string: "SQL:%s!%s"
  711. MFC_TRY
  712. rstrLogSetName = m_strSqlName.Right(m_strSqlName.GetLength() - m_strSqlName.Find(L"!") - 1);
  713. MFC_CATCH_DWSTATUS;
  714. return dwStatus;
  715. }
  716. void CFilesProperty::OnCfgBtn()
  717. {
  718. DWORD dwStatus = ERROR_SUCCESS;
  719. CFileLogs FilelogsDlg;
  720. CSqlProp SqlLogDlg;
  721. CString strTempBaseName;
  722. CString strTempFolderName;
  723. CString strTempSqlName;
  724. DWORD dwTempMaxSize;
  725. if ( SLF_SQL_LOG == m_dwLogFileTypeValue ){
  726. SqlLogDlg.m_pLogQuery = m_pQuery;
  727. SqlLogDlg.m_dwLogFileTypeValue = m_dwLogFileTypeValue;
  728. SqlLogDlg.m_bAutoNameSuffix = m_bAutoNameSuffix;
  729. //Extract the DSN and logset name from the formatted Sql Log name
  730. dwStatus = ExtractDSN ( SqlLogDlg.m_strDSN );
  731. dwStatus = ExtractLogSetName ( SqlLogDlg.m_strLogSetName );
  732. // Default the log set name to the base file name.
  733. if (SqlLogDlg.m_strLogSetName.IsEmpty() ) {
  734. SqlLogDlg.m_strLogSetName = m_strFileBaseName;
  735. }
  736. // Todo: Handle bad status
  737. SqlLogDlg.m_dwFocusControl = m_dwSubDlgFocusCtrl;
  738. SqlLogDlg.m_dwMaxSizeInternal = m_dwMaxSizeInternal;
  739. SqlLogDlg.SetContextHelpFilePath(GetContextHelpFilePath());
  740. if ( IDOK == SqlLogDlg.DoModal() ) {
  741. strTempSqlName = m_strSqlName;
  742. dwTempMaxSize = m_dwMaxSizeInternal;
  743. m_strSqlName = SqlLogDlg.m_SqlFormattedLogName;
  744. m_dwMaxSizeInternal = SqlLogDlg.m_dwMaxSizeInternal;
  745. if ( 0 != strTempSqlName.CompareNoCase ( m_strSqlName )
  746. || m_dwMaxSizeInternal != dwTempMaxSize )
  747. {
  748. SetModifiedPage(TRUE);
  749. }
  750. }
  751. }else{
  752. FilelogsDlg.m_pLogQuery = m_pQuery;
  753. FilelogsDlg.m_dwLogFileTypeValue = m_dwLogFileTypeValue;
  754. FilelogsDlg.m_strFolderName = m_strFolderName;
  755. FilelogsDlg.m_strFileBaseName = m_strFileBaseName;
  756. FilelogsDlg.m_dwMaxSizeInternal = m_dwMaxSizeInternal;
  757. FilelogsDlg.m_bAutoNameSuffix = m_bAutoNameSuffix;
  758. FilelogsDlg.SetContextHelpFilePath(GetContextHelpFilePath());
  759. FilelogsDlg.m_dwFocusControl = m_dwSubDlgFocusCtrl;
  760. if ( IDOK == FilelogsDlg.DoModal() ) {
  761. strTempFolderName = m_strFolderName;
  762. strTempBaseName = m_strFileBaseName;
  763. dwTempMaxSize = m_dwMaxSizeInternal;
  764. m_strFolderName = FilelogsDlg.m_strFolderName ;
  765. m_strFileBaseName = FilelogsDlg.m_strFileBaseName;
  766. m_dwMaxSizeInternal = FilelogsDlg.m_dwMaxSizeInternal;
  767. if ( 0 != strTempFolderName.CompareNoCase ( m_strFolderName )
  768. || 0 != strTempBaseName.CompareNoCase ( m_strFileBaseName )
  769. || m_dwMaxSizeInternal != dwTempMaxSize )
  770. {
  771. SetModifiedPage(TRUE);
  772. }
  773. }
  774. }
  775. m_dwSubDlgFocusCtrl = 0;
  776. UpdateSampleFileName();
  777. }