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.

1349 lines
39 KiB

  1. // OutPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "pdlcnfig.h"
  5. #include "common.h"
  6. #include "OutPage.h"
  7. #ifndef _tsplitpath
  8. #if _MBCS
  9. #define _tsplitpath _splitpath
  10. #else
  11. #define _tsplitpath _wsplitpath
  12. #endif
  13. #endif
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // COutputPropPage property page
  21. IMPLEMENT_DYNCREATE(COutputPropPage, CPropertyPage)
  22. COutputPropPage::COutputPropPage() : CPropertyPage(COutputPropPage::IDD)
  23. {
  24. //{{AFX_DATA_INIT(COutputPropPage)
  25. m_OutputFileName = _T("");
  26. m_RenameInterval = 0;
  27. m_BaseFileName = _T("");
  28. m_AutoNameIndex = -1;
  29. m_LogFileTypeIndex = -1;
  30. m_RenameUnitsIndex = -1;
  31. m_szLogDirectory = _T("");
  32. m_szCmdFilename = _T("");
  33. m_ExecuteCmd = 0;
  34. //}}AFX_DATA_INIT
  35. m_hKeyLogSettingsDefault = NULL;
  36. m_hKeyLogSettings = NULL;
  37. m_hKeyLogService = NULL;
  38. m_bFileNameChanged = NULL;
  39. m_bInitialized = FALSE;
  40. }
  41. COutputPropPage::~COutputPropPage()
  42. {
  43. if (m_hKeyLogSettingsDefault != NULL) RegCloseKey(m_hKeyLogSettingsDefault);
  44. if (m_hKeyLogSettings != NULL) RegCloseKey(m_hKeyLogSettings);
  45. if (m_hKeyLogService != NULL) RegCloseKey(m_hKeyLogService);
  46. }
  47. void COutputPropPage::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CPropertyPage::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(COutputPropPage)
  51. DDX_Text(pDX, IDC_OUTPUT_FILE_EDIT, m_OutputFileName);
  52. DDV_MaxChars(pDX, m_OutputFileName, 260);
  53. DDX_Text(pDX, IDC_RENAME_INTERVAL, m_RenameInterval);
  54. DDV_MinMaxDWord(pDX, m_RenameInterval, 0, 99999);
  55. DDX_Text(pDX, IDC_BASE_FILENAME_EDIT, m_BaseFileName);
  56. DDV_MaxChars(pDX, m_BaseFileName, 260);
  57. DDX_CBIndex(pDX, IDC_AUTO_NAME_COMBO, m_AutoNameIndex);
  58. DDX_CBIndex(pDX, IDC_LOG_FILETYPE, m_LogFileTypeIndex);
  59. DDX_CBIndex(pDX, IDC_RENAME_UNITS, m_RenameUnitsIndex);
  60. DDX_Text(pDX, IDC_LOG_DIRECTORY, m_szLogDirectory);
  61. DDV_MaxChars(pDX, m_szLogDirectory, 260);
  62. DDX_Text(pDX, IDC_CMD_FILENAME, m_szCmdFilename);
  63. DDV_MaxChars(pDX, m_szCmdFilename, 260);
  64. DDX_Check(pDX, IDC_EXECUTE_CHECK, m_ExecuteCmd);
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(COutputPropPage, CPropertyPage)
  68. //{{AFX_MSG_MAP(COutputPropPage)
  69. ON_BN_CLICKED(IDC_AUTOMATIC_NAME, OnAutomaticName)
  70. ON_BN_CLICKED(IDC_MANUAL_NAME, OnManualName)
  71. ON_CBN_SELCHANGE(IDC_AUTO_NAME_COMBO, OnSelchangeAutoNameCombo)
  72. ON_EN_CHANGE(IDC_BASE_FILENAME_EDIT, OnChangeBaseFilenameEdit)
  73. ON_BN_CLICKED(IDC_BROWSE_OUTPUT_FILE, OnBrowseOutputFile)
  74. ON_CBN_SELCHANGE(IDC_LOG_FILETYPE, OnSelchangeLogFiletype)
  75. ON_CBN_SELCHANGE(IDC_RENAME_UNITS, OnSelchangeRenameUnits)
  76. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_RENAME_INTERVAL, OnDeltaposSpinRenameInterval)
  77. ON_EN_CHANGE(IDC_OUTPUT_FILE_EDIT, OnChangeOutputFileEdit)
  78. ON_EN_CHANGE(IDC_RENAME_INTERVAL, OnChangeRenameInterval)
  79. ON_EN_UPDATE(IDC_BASE_FILENAME_EDIT, OnUpdateBaseFilenameEdit)
  80. ON_BN_CLICKED(IDC_BROWSE_FOLDER, OnBrowseFolder)
  81. ON_BN_CLICKED(IDC_EXECUTE_CHECK, OnExecuteCheck)
  82. ON_BN_CLICKED(IDC_BROWSE_CMD_FILE, OnBrowseCmdFile)
  83. ON_EN_CHANGE(IDC_CMD_FILENAME, OnChangeCmdFilename)
  84. //}}AFX_MSG_MAP
  85. ON_MESSAGE (PSM_QUERYSIBLINGS, OnQuerySiblings)
  86. END_MESSAGE_MAP()
  87. void COutputPropPage::InitDialogData (void)
  88. {
  89. LONG lStatus = ERROR_INVALID_FUNCTION;
  90. DWORD dwRegValType;
  91. DWORD dwRegValue;
  92. DWORD dwRegValueSize;
  93. CString csTempFilePath;
  94. TCHAR szRegString[MAX_PATH];
  95. TCHAR szDriveName[MAX_PATH];
  96. BOOL bAutoMode = FALSE;
  97. if (m_bInitialized) return;
  98. if (m_hKeyLogService == NULL) {
  99. // open registry key to service
  100. lStatus = RegOpenKeyEx (
  101. HKEY_LOCAL_MACHINE,
  102. TEXT("SYSTEM\\CurrentControlSet\\Services\\PerfDataLog"),
  103. 0,
  104. KEY_READ | KEY_WRITE,
  105. &m_hKeyLogService);
  106. }
  107. if ((m_hKeyLogSettings == NULL) &&
  108. (m_hKeyLogService != NULL)) {
  109. // open registry to log query info
  110. lStatus = RegOpenKeyEx (
  111. m_hKeyLogService,
  112. TEXT("Log Queries"),
  113. 0,
  114. KEY_READ | KEY_WRITE,
  115. &m_hKeyLogSettings);
  116. }
  117. if ((m_hKeyLogSettingsDefault == NULL) &&
  118. (m_hKeyLogSettings != NULL)) {
  119. // open registry to default log query
  120. lStatus = RegOpenKeyEx (
  121. m_hKeyLogSettings,
  122. TEXT("Default"),
  123. 0,
  124. KEY_READ | KEY_WRITE,
  125. &m_hKeyLogSettingsDefault);
  126. }
  127. if (lStatus != ERROR_SUCCESS) {
  128. return;
  129. // display error, close dialog and exit
  130. }
  131. // continue
  132. if (m_LogFileTypeIndex == -1) {
  133. // read log file format
  134. dwRegValType = 0;
  135. dwRegValue = 0;
  136. dwRegValueSize = sizeof(DWORD);
  137. lStatus = RegQueryValueEx (
  138. m_hKeyLogSettingsDefault,
  139. TEXT("Log File Type"),
  140. NULL,
  141. &dwRegValType,
  142. (LPBYTE)&dwRegValue,
  143. &dwRegValueSize);
  144. if (lStatus != ERROR_SUCCESS) {
  145. // then apply default value
  146. dwRegValue = OPD_CSV_FILE;
  147. }
  148. m_LogFileTypeIndex = dwRegValue;
  149. }
  150. if (m_RenameInterval == 0) {
  151. // set default mode
  152. dwRegValType = 0;
  153. dwRegValue = 0;
  154. dwRegValueSize = sizeof(DWORD);
  155. lStatus = RegQueryValueEx (
  156. m_hKeyLogSettingsDefault,
  157. TEXT("Auto Name Interval"),
  158. NULL,
  159. &dwRegValType,
  160. (LPBYTE)&dwRegValue,
  161. &dwRegValueSize);
  162. if (lStatus != ERROR_SUCCESS) {
  163. // then apply default value
  164. dwRegValue = 0; // manual naming is the default
  165. } else if (dwRegValType != REG_DWORD) {
  166. // then apply default value
  167. dwRegValue = 0; // manual naming is the default
  168. } // else assume it was OK
  169. if (dwRegValue == 0) {
  170. // initialize the rest of the manual name field(s)
  171. dwRegValType = 0;
  172. dwRegValueSize = MAX_PATH * sizeof(TCHAR);
  173. memset (szRegString, 0, dwRegValueSize);
  174. lStatus = RegQueryValueEx (
  175. m_hKeyLogSettingsDefault,
  176. TEXT("Log Filename"),
  177. NULL,
  178. &dwRegValType,
  179. (LPBYTE)&szRegString[0],
  180. &dwRegValueSize);
  181. if (lStatus != ERROR_SUCCESS) {
  182. // apply default name
  183. lstrcpy (szRegString, TEXT("perfdata."));
  184. switch (m_LogFileTypeIndex) {
  185. case OPD_TSV_FILE:
  186. lstrcat (szRegString, TEXT("tsv"));
  187. break;
  188. case OPD_BIN_FILE:
  189. lstrcat (szRegString, TEXT("blg"));
  190. break;
  191. case (OPD_CSV_FILE):
  192. default:
  193. lstrcat (szRegString, TEXT("csv"));
  194. break;
  195. }
  196. }
  197. // if the filename doesn't specify a directory, then use the
  198. csTempFilePath = szRegString;
  199. _tsplitpath ((LPCTSTR)csTempFilePath, szDriveName, szRegString,
  200. NULL, NULL);
  201. if ((lstrlen(szDriveName) == 0) && (lstrlen(szRegString) == 0)) {
  202. // default log file directory
  203. dwRegValType = 0;
  204. dwRegValueSize = MAX_PATH * sizeof(TCHAR);
  205. memset (szRegString, 0, dwRegValueSize);
  206. lStatus = RegQueryValueEx (
  207. m_hKeyLogSettingsDefault,
  208. TEXT("Log Default Directory"),
  209. NULL,
  210. &dwRegValType,
  211. (LPBYTE)&szRegString[0],
  212. &dwRegValueSize);
  213. if (lStatus != ERROR_SUCCESS) {
  214. // try to use the general default
  215. dwRegValType = 0;
  216. dwRegValueSize = MAX_PATH * sizeof(TCHAR);
  217. memset (szRegString, 0, dwRegValueSize);
  218. lStatus = RegQueryValueEx (
  219. m_hKeyLogSettings,
  220. TEXT("Log Default Directory"),
  221. NULL,
  222. &dwRegValType,
  223. (LPBYTE)&szRegString[0],
  224. &dwRegValueSize);
  225. if (lStatus != ERROR_SUCCESS) {
  226. // apply the default then since we can't find it
  227. // in the registry anywhere
  228. lstrcpy (szRegString, TEXT("c:\\perflogs"));
  229. }
  230. }
  231. // szRegString should have a valid path here
  232. m_szLogDirectory = szRegString; // load default dir for auto section
  233. m_OutputFileName = szRegString;
  234. m_OutputFileName += TEXT ("\\");
  235. } else {
  236. m_szLogDirectory = szDriveName;
  237. // the file parsing function leaves the trailing backslash
  238. // so remove it before concatenating it.
  239. if (szRegString[lstrlen(szRegString)-1] == TEXT('\\')) {
  240. szRegString[lstrlen(szRegString)-1] = 0;
  241. }
  242. m_szLogDirectory += szRegString;
  243. m_OutputFileName.Empty();
  244. }
  245. m_OutputFileName += csTempFilePath;
  246. // set auto combo boxes to default values
  247. m_BaseFileName = TEXT("perfdata");
  248. m_AutoNameIndex = OPD_NAME_YYMMDD;
  249. m_RenameUnitsIndex = OPD_RENAME_DAYS;
  250. m_RenameInterval = 1;
  251. bAutoMode = FALSE;
  252. } else {
  253. m_RenameInterval = dwRegValue;
  254. // get values for controls
  255. dwRegValType = 0;
  256. dwRegValueSize = MAX_PATH * sizeof(TCHAR);
  257. memset (szRegString, 0, dwRegValueSize);
  258. lStatus = RegQueryValueEx (
  259. m_hKeyLogSettingsDefault,
  260. TEXT("Log Default Directory"),
  261. NULL,
  262. &dwRegValType,
  263. (LPBYTE)&szRegString[0],
  264. &dwRegValueSize);
  265. if (lStatus != ERROR_SUCCESS) {
  266. // try to use the general default
  267. dwRegValType = 0;
  268. dwRegValueSize = MAX_PATH * sizeof(TCHAR);
  269. memset (szRegString, 0, dwRegValueSize);
  270. lStatus = RegQueryValueEx (
  271. m_hKeyLogSettings,
  272. TEXT("Log Default Directory"),
  273. NULL,
  274. &dwRegValType,
  275. (LPBYTE)&szRegString[0],
  276. &dwRegValueSize);
  277. if (lStatus != ERROR_SUCCESS) {
  278. // apply the default then since we can't find it
  279. // in the registry anywhere
  280. lstrcpy (szRegString, TEXT("c:\\perflogs"));
  281. }
  282. }
  283. // szRegString should have a valid path here
  284. m_szLogDirectory = szRegString;
  285. // base filename
  286. dwRegValType = 0;
  287. dwRegValueSize = MAX_PATH * sizeof(TCHAR);
  288. memset (szRegString, 0, dwRegValueSize);
  289. lStatus = RegQueryValueEx (
  290. m_hKeyLogSettingsDefault,
  291. TEXT("Base Filename"),
  292. NULL,
  293. &dwRegValType,
  294. (LPBYTE)&szRegString[0],
  295. &dwRegValueSize);
  296. if (lStatus != ERROR_SUCCESS) {
  297. // apply default name
  298. lstrcpy (szRegString, TEXT("perfdata"));
  299. }
  300. m_BaseFileName = szRegString;
  301. // get auto name format
  302. dwRegValType = 0;
  303. dwRegValue = 0;
  304. dwRegValueSize = sizeof(DWORD);
  305. lStatus = RegQueryValueEx (
  306. m_hKeyLogSettingsDefault,
  307. TEXT("Log File Auto Format"),
  308. NULL,
  309. &dwRegValType,
  310. (LPBYTE)&dwRegValue,
  311. &dwRegValueSize);
  312. if (lStatus != ERROR_SUCCESS) {
  313. // then apply default value
  314. dwRegValue = OPD_NAME_YYMMDD; // manual naming is the default
  315. }
  316. // set update interval information
  317. m_AutoNameIndex = dwRegValue;
  318. dwRegValType = 0;
  319. dwRegValue = 0;
  320. dwRegValueSize = sizeof(DWORD);
  321. lStatus = RegQueryValueEx (
  322. m_hKeyLogSettingsDefault,
  323. TEXT("Auto Rename Units"),
  324. NULL,
  325. &dwRegValType,
  326. (LPBYTE)&dwRegValue,
  327. &dwRegValueSize);
  328. if (lStatus != ERROR_SUCCESS) {
  329. // then apply default value
  330. dwRegValue = OPD_RENAME_DAYS; // manual naming is the default
  331. }
  332. m_RenameUnitsIndex = dwRegValue;
  333. dwRegValType = 0;
  334. dwRegValueSize = MAX_PATH * sizeof(TCHAR);
  335. memset (szRegString, 0, dwRegValueSize);
  336. lStatus = RegQueryValueEx (
  337. m_hKeyLogSettingsDefault,
  338. TEXT("Command File"),
  339. NULL,
  340. &dwRegValType,
  341. (LPBYTE)&szRegString[0],
  342. &dwRegValueSize);
  343. if (lStatus != ERROR_SUCCESS) {
  344. // then apply default value
  345. m_ExecuteCmd = 0;
  346. m_szCmdFilename = _T("");
  347. } else {
  348. // else use the one from the registry
  349. m_ExecuteCmd = 1;
  350. m_szCmdFilename = szRegString;
  351. }
  352. }
  353. }
  354. m_bInitialized = TRUE;
  355. return;
  356. }
  357. afx_msg LRESULT COutputPropPage::OnQuerySiblings (WPARAM wParam, LPARAM lParam)
  358. {
  359. switch (wParam) {
  360. case PDLCNFIG_PSM_QS_WILDCARD_LOG:
  361. switch (m_LogFileTypeIndex) {
  362. case -1:
  363. return PDLCNFIG_WILDCARD_LOG_DONT_KNOW;
  364. case OPD_BIN_FILE:
  365. return PDLCNFIG_WILDCARD_LOG_YES;
  366. case OPD_CSV_FILE:
  367. case OPD_TSV_FILE:
  368. default:
  369. return PDLCNFIG_WILDCARD_LOG_NO;
  370. }
  371. case PDLCNFIG_PSM_QS_ARE_YOU_READY:
  372. InitDialogData();
  373. return 0;
  374. default:
  375. return 0; // to pass to the next property page
  376. }
  377. }
  378. BOOL COutputPropPage::IsDirPathValid (LPCTSTR szPath,
  379. BOOL bLastNameIsDirectory,
  380. BOOL bCreateMissingDirs)
  381. /*++
  382. Routine Description:
  383. Creates the directory specified in szPath and any other "higher"
  384. directories in the specified path that don't exist.
  385. Arguments:
  386. IN LPCTSTR szPath
  387. directory path to create (assumed to be a DOS path, not a UNC)
  388. IN BOOL bLastNameIsDirectory
  389. TRUE when the last name in the path is a Directory and not a File
  390. FALSE if the last name is a file
  391. IN BOOL bCreateMissingDirs
  392. TRUE will create any dirs in the path that are not found
  393. FALSE will only test for existence and not create any
  394. missing dirs.
  395. Return Value:
  396. TRUE if the directory path now exists
  397. FALSE if error (GetLastError to find out why)
  398. --*/
  399. {
  400. LPTSTR szLocalPath;
  401. LPTSTR szEnd;
  402. LONG lReturn = 0L;
  403. LPSECURITY_ATTRIBUTES lpSA = NULL;
  404. DWORD dwAttr;
  405. TCHAR cBackslash = TEXT('\\');
  406. szLocalPath = (LPTSTR)HeapAlloc (GetProcessHeap(),
  407. HEAP_ZERO_MEMORY,
  408. MAX_PATH * sizeof(TCHAR));
  409. if (szLocalPath == NULL) {
  410. SetLastError (ERROR_OUTOFMEMORY);
  411. return FALSE;
  412. } else {
  413. // so far so good...
  414. SetLastError (ERROR_SUCCESS); // initialize error value to SUCCESS
  415. }
  416. if (GetFullPathName (szPath,
  417. MAX_PATH,
  418. szLocalPath,
  419. NULL) > 0) {
  420. szEnd = &szLocalPath[3];
  421. if (*szEnd != 0) {
  422. // then there are sub dirs to create
  423. while (*szEnd != 0) {
  424. // go to next backslash
  425. while ((*szEnd != cBackslash) && (*szEnd != 0)) szEnd++;
  426. if (*szEnd == cBackslash) {
  427. // terminate path here and create directory
  428. *szEnd = 0;
  429. if (bCreateMissingDirs) {
  430. if (!CreateDirectory (szLocalPath, lpSA)) {
  431. // see what the error was and "adjust" it if necessary
  432. if (GetLastError() == ERROR_ALREADY_EXISTS) {
  433. // this is OK
  434. SetLastError (ERROR_SUCCESS);
  435. } else {
  436. lReturn = 0;
  437. }
  438. } else {
  439. // directory created successfully so update count
  440. lReturn++;
  441. }
  442. } else {
  443. if ((dwAttr = GetFileAttributes(szLocalPath)) != 0xFFFFFFFF) {
  444. // make sure it's a dir
  445. if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) ==
  446. FILE_ATTRIBUTE_DIRECTORY) {
  447. lReturn++;
  448. } else {
  449. // if any dirs fail, then clear the return value
  450. lReturn = 0;
  451. }
  452. } else {
  453. // if any dirs fail, then clear the return value
  454. lReturn = 0;
  455. }
  456. }
  457. // replace backslash and go to next dir
  458. *szEnd++ = cBackslash;
  459. }
  460. }
  461. // create last dir in path now if it's a dir name and not a filename
  462. if (bLastNameIsDirectory) {
  463. if (bCreateMissingDirs) {
  464. if (!CreateDirectory (szLocalPath, lpSA)) {
  465. // see what the error was and "adjust" it if necessary
  466. if (GetLastError() == ERROR_ALREADY_EXISTS) {
  467. // this is OK
  468. SetLastError (ERROR_SUCCESS);
  469. lReturn++;
  470. } else {
  471. lReturn = 0;
  472. }
  473. } else {
  474. // directory created successfully
  475. lReturn++;
  476. }
  477. } else {
  478. if ((dwAttr = GetFileAttributes(szLocalPath)) != 0xFFFFFFFF) {
  479. // make sure it's a dir
  480. if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) ==
  481. FILE_ATTRIBUTE_DIRECTORY) {
  482. lReturn++;
  483. } else {
  484. // if any dirs fail, then clear the return value
  485. lReturn = 0;
  486. }
  487. } else {
  488. // if any dirs fail, then clear the return value
  489. lReturn = 0;
  490. }
  491. }
  492. }
  493. } else {
  494. // else this is a root dir only so return success.
  495. lReturn = 1;
  496. }
  497. }
  498. if (szLocalPath != NULL) HeapFree (GetProcessHeap(), 0, szLocalPath);
  499. return lReturn;
  500. }
  501. void COutputPropPage::AutoManualEnable (BOOL bAutomatic)
  502. {
  503. BOOL bShowCmdFile;
  504. GetDlgItem(IDC_MANUAL_NAME_GROUP)->EnableWindow(!bAutomatic);
  505. GetDlgItem(IDC_OUTPUT_FILE_EDIT)->EnableWindow(!bAutomatic);
  506. GetDlgItem(IDC_BROWSE_OUTPUT_FILE)->EnableWindow(!bAutomatic);
  507. GetDlgItem(IDC_AUTO_NAME_GROUP)->EnableWindow(bAutomatic);
  508. GetDlgItem(IDC_RENAME_INTERVAL)->EnableWindow(bAutomatic);
  509. GetDlgItem(IDC_SPIN_RENAME_INTERVAL)->EnableWindow(bAutomatic);
  510. GetDlgItem(IDC_RENAME_UNITS)->EnableWindow(bAutomatic);
  511. GetDlgItem(IDC_BROWSE_FOLDER)->EnableWindow(bAutomatic);
  512. GetDlgItem(IDC_LOG_DIRECTORY)->EnableWindow(bAutomatic);
  513. GetDlgItem(IDC_BASE_NAME_CAPTION)->EnableWindow(bAutomatic);
  514. GetDlgItem(IDC_BASE_FILENAME_EDIT)->EnableWindow(bAutomatic);
  515. GetDlgItem(IDC_AUTO_NAME_CAPTION)->EnableWindow(bAutomatic);
  516. GetDlgItem(IDC_AUTO_NAME_COMBO)->EnableWindow(bAutomatic);
  517. GetDlgItem(IDC_SAMPLE_NAME)->EnableWindow(bAutomatic);
  518. GetDlgItem(IDC_SAMPLE_NAME_TEXT)->EnableWindow(bAutomatic);
  519. GetDlgItem(IDC_EXECUTE_CHECK)->EnableWindow(bAutomatic);
  520. bShowCmdFile = bAutomatic && m_ExecuteCmd;
  521. GetDlgItem(IDC_CMD_FILENAME)->EnableWindow(bShowCmdFile);
  522. GetDlgItem(IDC_BROWSE_CMD_FILE)->EnableWindow(bShowCmdFile);
  523. }
  524. void COutputPropPage::UpdateSampleFilename()
  525. {
  526. CString cCompositeName;
  527. CString cBaseName;
  528. CString cDateString;
  529. CString cFileTypeString;
  530. CTime cCurrentTime = CTime::GetCurrentTime();
  531. LONG lAutoNameFormat;
  532. LONG lFileTypeIndex;
  533. BOOL bAutoName;
  534. bAutoName = IsDlgButtonChecked (IDC_AUTOMATIC_NAME);
  535. if (bAutoName) {
  536. // only update if the automatic button is checked
  537. // get base name text
  538. GetDlgItemText (IDC_BASE_FILENAME_EDIT, cBaseName);
  539. cBaseName += TEXT("_");
  540. // get date/time/serial integer format
  541. cCurrentTime.GetCurrentTime();
  542. lAutoNameFormat = ((CComboBox *)GetDlgItem(IDC_AUTO_NAME_COMBO))->GetCurSel();
  543. switch (lAutoNameFormat) {
  544. case OPD_NAME_NNNNNN:
  545. cDateString = TEXT("000001");
  546. break;
  547. case OPD_NAME_YYDDD:
  548. cDateString = cCurrentTime.Format (TEXT("%y%j"));
  549. break;
  550. case OPD_NAME_YYMM:
  551. cDateString = cCurrentTime.Format (TEXT("%y%m"));
  552. break;
  553. case OPD_NAME_YYMMDDHH:
  554. cDateString = cCurrentTime.Format (TEXT("%y%m%d%H"));
  555. break;
  556. case OPD_NAME_MMDDHH:
  557. cDateString = cCurrentTime.Format (TEXT("%m%d%H"));
  558. break;
  559. case OPD_NAME_YYMMDD:
  560. default:
  561. cDateString = cCurrentTime.Format (TEXT("%y%m%d"));
  562. break;
  563. }
  564. cCompositeName = cBaseName;
  565. cCompositeName += cDateString;
  566. } else {
  567. int nExtLoc;
  568. int nNameLen;
  569. // with a manual name, just update the extension
  570. // get the current filename
  571. if (GetDlgItemText (IDC_OUTPUT_FILE_EDIT, cBaseName) == 0) {
  572. // no name in the edit control, so make one up to use
  573. // as a default
  574. cCompositeName = TEXT("c:\\perflogs");
  575. cCompositeName += TEXT("\\perfdata");
  576. } else {
  577. //find last "." in string
  578. nExtLoc = cBaseName.ReverseFind (_T('.'));
  579. if (nExtLoc > 0) {
  580. // don't copy the "."
  581. cCompositeName = cBaseName.Left(nExtLoc);
  582. }
  583. }
  584. }
  585. // get file type
  586. lFileTypeIndex = ((CComboBox *)GetDlgItem(IDC_LOG_FILETYPE))->GetCurSel();
  587. switch (lFileTypeIndex) {
  588. case OPD_TSV_FILE:
  589. cFileTypeString = TEXT(".TSV");
  590. break;
  591. case OPD_BIN_FILE:
  592. cFileTypeString = TEXT(".BLG");
  593. break;
  594. case OPD_CSV_FILE:
  595. default:
  596. cFileTypeString = TEXT(".CSV");
  597. break;
  598. }
  599. cCompositeName += cFileTypeString;
  600. if (bAutoName) {
  601. SetDlgItemText (IDC_SAMPLE_NAME_TEXT, cCompositeName);
  602. } else {
  603. SetDlgItemText (IDC_OUTPUT_FILE_EDIT, cCompositeName);
  604. }
  605. }
  606. BOOL COutputPropPage::IsWildcardLogFileType (void)
  607. {
  608. switch (m_LogFileTypeIndex) {
  609. case OPD_BIN_FILE:
  610. return TRUE;
  611. case OPD_CSV_FILE:
  612. case OPD_TSV_FILE:
  613. default:
  614. return FALSE;
  615. }
  616. }
  617. /////////////////////////////////////////////////////////////////////////////
  618. // COutputPropPage message handlers
  619. BOOL COutputPropPage::OnInitDialog()
  620. {
  621. BOOL bAutoMode;
  622. InitDialogData();
  623. // now init other pages
  624. QuerySiblings (PDLCNFIG_PSM_QS_ARE_YOU_READY, 0);
  625. if (m_RenameInterval == 0) {
  626. // then manual naming has been selected:
  627. CheckRadioButton (IDC_MANUAL_NAME, IDC_AUTOMATIC_NAME, IDC_MANUAL_NAME);
  628. bAutoMode = FALSE;
  629. } else {
  630. CheckRadioButton (IDC_MANUAL_NAME, IDC_AUTOMATIC_NAME, IDC_AUTOMATIC_NAME);
  631. bAutoMode = TRUE;
  632. }
  633. CPropertyPage::OnInitDialog();
  634. // now finish updating the controls in the property page
  635. UpdateSampleFilename();
  636. // update control state to match selection
  637. AutoManualEnable (bAutoMode);
  638. SetModified(FALSE);
  639. return TRUE; // return TRUE unless you set the focus to a control
  640. // EXCEPTION: OCX Property Pages should return FALSE
  641. }
  642. void COutputPropPage::OnAutomaticName()
  643. {
  644. AutoManualEnable(TRUE);
  645. UpdateSampleFilename();
  646. SetModified(TRUE);
  647. }
  648. void COutputPropPage::OnManualName()
  649. {
  650. AutoManualEnable(FALSE);
  651. UpdateSampleFilename();
  652. SetModified(TRUE);
  653. }
  654. void COutputPropPage::OnSelchangeAutoNameCombo()
  655. {
  656. // TODO: Add your control notification handler code here
  657. UpdateSampleFilename();
  658. m_bFileNameChanged = TRUE;
  659. SetModified(TRUE);
  660. }
  661. void COutputPropPage::OnChangeBaseFilenameEdit()
  662. {
  663. // TODO: Add your control notification handler code here
  664. SetModified(TRUE);
  665. m_bFileNameChanged = TRUE;
  666. }
  667. void COutputPropPage::OnBrowseOutputFile()
  668. {
  669. OPENFILENAME ofn;
  670. CComboBox *cFileTypeCombo;
  671. CString csInitialDir;
  672. LONG lLogFileType;
  673. TCHAR szFileName[MAX_PATH];
  674. CString csBaseFilename;
  675. TCHAR szDrive[MAX_PATH];
  676. TCHAR szDir[MAX_PATH];
  677. TCHAR szExt[MAX_PATH];
  678. LPTSTR szDefExt = NULL;
  679. cFileTypeCombo = (CComboBox *)GetDlgItem(IDC_LOG_FILETYPE);
  680. lLogFileType = cFileTypeCombo->GetCurSel();
  681. if (lLogFileType == CB_ERR) lLogFileType = OPD_NUM_FILE_TYPES;
  682. GetDlgItemText (IDC_OUTPUT_FILE_EDIT, csBaseFilename);
  683. _tsplitpath((LPCTSTR)csBaseFilename,
  684. szDrive, szDir, szFileName, szExt);
  685. csInitialDir = szDrive;
  686. csInitialDir += szDir;
  687. lstrcat (szFileName, szExt);
  688. ofn.lStructSize = sizeof(ofn);
  689. ofn.hwndOwner = m_hWnd;
  690. ofn.hInstance = GetModuleHandle(NULL);
  691. ofn.lpstrFilter = TEXT("CSV Files (*.csv)\0*.csv\0TSV Files (*.tsv)\0*.tsv\0BLG Files (*.blg)\0*.blg\0All Files (*.*)\0*.*\0");
  692. ofn.lpstrCustomFilter = NULL;
  693. ofn.nMaxCustFilter = 0;
  694. ofn.nFilterIndex = lLogFileType + 1; // nFilterIndex is 1-based
  695. ofn.lpstrFile = szFileName;
  696. ofn.nMaxFile = MAX_PATH;
  697. ofn.lpstrFileTitle = NULL;
  698. ofn.nMaxFileTitle = 0;
  699. ofn.lpstrInitialDir = (LPCTSTR)csInitialDir;
  700. ofn.lpstrTitle = TEXT("Select Log Filename");
  701. ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
  702. ofn.nFileOffset = 0;
  703. ofn.nFileExtension = 0;
  704. ofn.lpstrDefExt = NULL;
  705. ofn.lCustData = 0;
  706. ofn.lpfnHook = NULL;
  707. ofn.lpTemplateName = NULL;
  708. if (GetOpenFileName (&ofn) == IDOK) {
  709. // Update the fields with the new information
  710. cFileTypeCombo->SetCurSel(ofn.nFilterIndex-1);
  711. // see if an file name extension needs to be added...
  712. if (ofn.nFileExtension == 0) {
  713. // then add the one that matches the current file type
  714. switch (ofn.nFilterIndex-1) {
  715. case OPD_CSV_FILE:
  716. szDefExt = TEXT(".csv");
  717. break;
  718. case OPD_TSV_FILE:
  719. szDefExt = TEXT(".tsv");
  720. break;
  721. case OPD_BIN_FILE:
  722. szDefExt = TEXT(".blg");
  723. break;
  724. default:
  725. szDefExt = NULL;
  726. break;
  727. }
  728. }
  729. if (szDefExt != NULL) {
  730. lstrcat (szFileName, szDefExt);
  731. }
  732. SetDlgItemText (IDC_OUTPUT_FILE_EDIT, szFileName);
  733. } // else ignore if they canceled out
  734. }
  735. void COutputPropPage::OnSelchangeLogFiletype()
  736. {
  737. UpdateData(TRUE);
  738. UpdateSampleFilename();
  739. if ((m_LogFileTypeIndex != OPD_BIN_FILE) &&
  740. (QuerySiblings (PDLCNFIG_PSM_QS_LISTBOX_STARS, 0) ==
  741. PDLCNFIG_LISTBOX_STARS_YES)) {
  742. AfxMessageBox (IDS_NOT_WILDCARD_FMT, MB_OK, 0);
  743. }
  744. m_bFileNameChanged = TRUE;
  745. SetModified(TRUE);
  746. }
  747. void COutputPropPage::OnSelchangeRenameUnits()
  748. {
  749. LONG lIndex;
  750. LONG lNewDefault;
  751. // Get new sample and update default extension based on rename
  752. // interval units
  753. lIndex = ((CComboBox *)GetDlgItem(IDC_RENAME_UNITS))->GetCurSel();
  754. switch (lIndex) {
  755. case OPD_RENAME_HOURS:
  756. lNewDefault = OPD_NAME_YYMMDDHH;
  757. break;
  758. case OPD_RENAME_DAYS:
  759. lNewDefault = OPD_NAME_YYMMDD;
  760. break;
  761. case OPD_RENAME_MONTHS:
  762. lNewDefault = OPD_NAME_YYMM;
  763. break;
  764. case OPD_RENAME_KBYTES:
  765. case OPD_RENAME_MBYTES:
  766. default:
  767. lNewDefault = OPD_NAME_NNNNNN;
  768. break;
  769. }
  770. // update new default selection
  771. ((CComboBox *)GetDlgItem(IDC_AUTO_NAME_COMBO))->SetCurSel(lNewDefault);
  772. UpdateSampleFilename();
  773. SetModified(TRUE);
  774. }
  775. void COutputPropPage::OnDeltaposSpinRenameInterval(NMHDR* pNMHDR, LRESULT* pResult)
  776. {
  777. TCHAR szStringValue[MAX_PATH];
  778. DWORD dwNumValue;
  779. int nChange;
  780. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  781. // get current value from edit window
  782. GetDlgItemText (IDC_RENAME_INTERVAL, szStringValue, MAX_PATH);
  783. // convert to integer
  784. dwNumValue = _tcstoul (szStringValue, NULL, 10);
  785. // delta is opposite of arrow direction
  786. nChange = -pNMUpDown->iDelta;
  787. // apply value from spin control
  788. if (nChange < 0) { // 1 is the minimum
  789. // make sure we haven't hit bottom already
  790. if (dwNumValue > 1) {
  791. dwNumValue += nChange;
  792. }
  793. } else {
  794. dwNumValue += nChange;
  795. }
  796. // update edit window
  797. _ultot (dwNumValue, szStringValue, 10);
  798. SetDlgItemText(IDC_RENAME_INTERVAL, szStringValue);
  799. SetModified(TRUE);
  800. *pResult = 0;
  801. }
  802. void COutputPropPage::OnCancel()
  803. {
  804. // TODO: Add your specialized code here and/or call the base class
  805. CPropertyPage::OnCancel();
  806. }
  807. void COutputPropPage::OnOK()
  808. {
  809. LONG lIndex;
  810. LONG lStatus;
  811. CString csFilename;
  812. DWORD dwAutoNameFormat;
  813. DWORD dwAutoChangeInterval;
  814. BOOL bManual;
  815. BOOL bBogus = FALSE;
  816. bManual = IsDlgButtonChecked (IDC_MANUAL_NAME);
  817. if (!bManual) {
  818. dwAutoNameFormat = ((CComboBox *)GetDlgItem(IDC_AUTO_NAME_COMBO))->GetCurSel();
  819. dwAutoChangeInterval = ((CComboBox *)GetDlgItem(IDC_RENAME_UNITS))->GetCurSel();
  820. }
  821. // save Log File Type
  822. lIndex = ((CComboBox *)GetDlgItem(IDC_LOG_FILETYPE))->GetCurSel();
  823. lStatus = RegSetValueEx (
  824. m_hKeyLogSettingsDefault,
  825. TEXT("Log File Type"),
  826. 0L,
  827. REG_DWORD,
  828. (LPBYTE)&lIndex,
  829. sizeof(lIndex));
  830. ASSERT (lStatus == ERROR_SUCCESS);
  831. // is manual filename button pushed?
  832. if (bManual) {
  833. // YES:
  834. csFilename.Empty();
  835. // write output filename frome edit box
  836. GetDlgItemText(IDC_OUTPUT_FILE_EDIT, csFilename);
  837. lStatus = RegSetValueEx (
  838. m_hKeyLogSettingsDefault,
  839. TEXT("Log Filename"),
  840. 0L,
  841. REG_SZ,
  842. (LPBYTE)(LPCTSTR)csFilename,
  843. (csFilename.GetLength()+1)*sizeof(TCHAR));
  844. ASSERT (lStatus == ERROR_SUCCESS);
  845. // write rename interval == 0
  846. lIndex = 0;
  847. lStatus = RegSetValueEx (
  848. m_hKeyLogSettingsDefault,
  849. TEXT("Auto Name Interval"),
  850. 0L,
  851. REG_DWORD,
  852. (LPBYTE)&lIndex,
  853. sizeof(lIndex));
  854. ASSERT (lStatus == ERROR_SUCCESS);
  855. // clear auto rename entries:
  856. // Log File Auto Format
  857. RegDeleteValue (m_hKeyLogSettingsDefault, TEXT("Log File Auto Format"));
  858. // Log Auto Name Units
  859. RegDeleteValue (m_hKeyLogSettingsDefault, TEXT("Auto Rename Units"));
  860. // Log Base Filename
  861. RegDeleteValue (m_hKeyLogSettingsDefault, TEXT("Base Log Filename"));
  862. // Command File name
  863. RegDeleteValue (m_hKeyLogSettingsDefault, TEXT("Command File"));
  864. } else {
  865. // auto is pressed so:
  866. csFilename.Empty();
  867. // save Log Default Directory
  868. GetDlgItemText (IDC_LOG_DIRECTORY, csFilename);
  869. lStatus = RegSetValueEx (
  870. m_hKeyLogSettingsDefault,
  871. TEXT("Log Default Directory"),
  872. 0L,
  873. REG_SZ,
  874. (LPBYTE)(LPCTSTR)csFilename,
  875. (csFilename.GetLength()+1)*sizeof(TCHAR));
  876. ASSERT (lStatus == ERROR_SUCCESS);
  877. // save Log Base Filename
  878. csFilename.Empty();
  879. GetDlgItemText (IDC_BASE_FILENAME_EDIT, csFilename);
  880. lStatus = RegSetValueEx (
  881. m_hKeyLogSettingsDefault,
  882. TEXT("Base Filename"),
  883. 0L,
  884. REG_SZ,
  885. (LPBYTE)(LPCTSTR)csFilename,
  886. (csFilename.GetLength()+1)*sizeof(TCHAR));
  887. ASSERT (lStatus == ERROR_SUCCESS);
  888. // save Log Auto Name Format
  889. lStatus = RegSetValueEx (
  890. m_hKeyLogSettingsDefault,
  891. TEXT("Log File Auto Format"),
  892. 0L,
  893. REG_DWORD,
  894. (LPBYTE)&dwAutoNameFormat,
  895. sizeof(DWORD));
  896. ASSERT (lStatus == ERROR_SUCCESS);
  897. if (lIndex == OPD_NAME_NNNNNN) {
  898. if (m_bFileNameChanged) {
  899. // reset serial number counter to 1
  900. lIndex = 1;
  901. lStatus = RegSetValueEx (
  902. m_hKeyLogSettingsDefault,
  903. TEXT("Log File Serial Number"),
  904. 0L,
  905. REG_DWORD,
  906. (LPBYTE)&lIndex,
  907. sizeof(DWORD));
  908. ASSERT (lStatus == ERROR_SUCCESS);
  909. }
  910. } else {
  911. // delete serial number entry
  912. lStatus = RegDeleteValue (
  913. m_hKeyLogSettingsDefault,
  914. TEXT("Log File Serial Number"));
  915. // this may fail if the key is already
  916. // deleted. That's ok.
  917. }
  918. // save Log Rename Interval
  919. csFilename.Empty();
  920. GetDlgItemText (IDC_RENAME_INTERVAL, csFilename);
  921. lIndex = _tcstol((LPCTSTR)csFilename, NULL, 10);
  922. lStatus = RegSetValueEx (
  923. m_hKeyLogSettingsDefault,
  924. TEXT("Auto Name Interval"),
  925. 0L,
  926. REG_DWORD,
  927. (LPBYTE)&lIndex,
  928. sizeof(DWORD));
  929. ASSERT (lStatus == ERROR_SUCCESS);
  930. // save Log Rename Units
  931. lStatus = RegSetValueEx (
  932. m_hKeyLogSettingsDefault,
  933. TEXT("Auto Rename Units"),
  934. 0L,
  935. REG_DWORD,
  936. (LPBYTE)&dwAutoChangeInterval,
  937. sizeof(DWORD));
  938. ASSERT (lStatus == ERROR_SUCCESS);
  939. if (m_ExecuteCmd != 0) {
  940. csFilename.Empty();
  941. GetDlgItemText (IDC_CMD_FILENAME, csFilename);
  942. lStatus = RegSetValueEx (
  943. m_hKeyLogSettingsDefault,
  944. TEXT("Command File"),
  945. 0L,
  946. REG_SZ,
  947. (LPBYTE)(LPCTSTR)csFilename,
  948. (csFilename.GetLength()+1)*sizeof(TCHAR));
  949. ASSERT (lStatus == ERROR_SUCCESS);
  950. } else {
  951. // no command file to be executed
  952. RegDeleteValue (m_hKeyLogSettingsDefault, TEXT("Command File"));
  953. }
  954. // clear Manual entries
  955. // Log Filename
  956. RegDeleteValue (m_hKeyLogSettingsDefault, TEXT("Log Filename"));
  957. }
  958. CancelToClose();
  959. }
  960. BOOL COutputPropPage::OnQueryCancel()
  961. {
  962. // TODO: Add your specialized code here and/or call the base class
  963. return CPropertyPage::OnQueryCancel();
  964. }
  965. void COutputPropPage::OnChangeOutputFileEdit()
  966. {
  967. // TODO: Add your control notification handler code here
  968. SetModified(TRUE);
  969. }
  970. void COutputPropPage::OnChangeRenameInterval()
  971. {
  972. // TODO: Add your control notification handler code here
  973. SetModified(TRUE);
  974. }
  975. void COutputPropPage::OnUpdateBaseFilenameEdit()
  976. {
  977. // TODO: Add your control notification handler code here
  978. UpdateSampleFilename();
  979. m_bFileNameChanged = TRUE;
  980. }
  981. void COutputPropPage::OnBrowseFolder()
  982. {
  983. OPENFILENAME ofn;
  984. CComboBox *cFileTypeCombo;
  985. CString csInitialDir;
  986. LONG lLogFileType;
  987. TCHAR szFileName[MAX_PATH];
  988. CString csBaseFilename;
  989. LONG lFileNameLength;
  990. cFileTypeCombo = (CComboBox *)GetDlgItem(IDC_LOG_FILETYPE);
  991. lLogFileType = cFileTypeCombo->GetCurSel();
  992. if (lLogFileType == CB_ERR) lLogFileType = OPD_NUM_FILE_TYPES;
  993. // should the default filename be the base or the synthesized one?
  994. GetDlgItemText (IDC_BASE_FILENAME_EDIT, szFileName, MAX_PATH);
  995. GetDlgItemText (IDC_LOG_DIRECTORY, csInitialDir);
  996. ofn.lStructSize = sizeof(ofn);
  997. ofn.hwndOwner = m_hWnd;
  998. ofn.hInstance = GetModuleHandle(NULL);
  999. ofn.lpstrFilter = TEXT("CSV Files (*.csv)\0*.csv\0TSV Files (*.tsv)\0*.tsv\0BLG Files (*.blg)\0*.blg\0All Files (*.*)\0*.*\0");
  1000. ofn.lpstrCustomFilter = NULL;
  1001. ofn.nMaxCustFilter = 0;
  1002. ofn.nFilterIndex = lLogFileType + 1; // nFilterIndex is 1 based
  1003. ofn.lpstrFile = szFileName;
  1004. ofn.nMaxFile = MAX_PATH;
  1005. ofn.lpstrFileTitle = NULL;
  1006. ofn.nMaxFileTitle = 0;
  1007. ofn.lpstrInitialDir = csInitialDir;
  1008. ofn.lpstrTitle = TEXT("Select Log Folder and Base Filename");
  1009. ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
  1010. ofn.nFileOffset = 0;
  1011. ofn.nFileExtension = 0;
  1012. ofn.lpstrDefExt = NULL;
  1013. ofn.lCustData = 0;
  1014. ofn.lpfnHook = NULL;
  1015. ofn.lpTemplateName = NULL;
  1016. if (GetOpenFileName (&ofn) == IDOK) {
  1017. // Update the fields with the new information
  1018. cFileTypeCombo->SetCurSel(ofn.nFilterIndex -1);
  1019. lFileNameLength = lstrlen(szFileName);
  1020. // truncate extension
  1021. if ((ofn.nFileExtension < lFileNameLength) && (ofn.nFileExtension > 0)) {
  1022. szFileName[ofn.nFileExtension-1] = 0;
  1023. }
  1024. if ((ofn.nFileOffset < lFileNameLength) && (ofn.nFileOffset >= 0)){
  1025. csBaseFilename = &szFileName[ofn.nFileOffset];
  1026. if (ofn.nFileOffset > 0) {
  1027. szFileName[ofn.nFileOffset-1] = 0;
  1028. }
  1029. SetDlgItemText (IDC_BASE_FILENAME_EDIT, csBaseFilename);
  1030. SetDlgItemText (IDC_LOG_DIRECTORY, szFileName);
  1031. }
  1032. UpdateSampleFilename();
  1033. } // else ignore if they canceled out
  1034. }
  1035. BOOL COutputPropPage::OnKillActive()
  1036. {
  1037. CString csFilename;
  1038. int nMbReturn;
  1039. DWORD dwAutoNameFormat;
  1040. DWORD dwAutoChangeInterval;
  1041. BOOL bManual;
  1042. BOOL bBogus = FALSE;
  1043. BOOL bPathHasFileName;
  1044. BOOL bReturn = TRUE; // assume all is OK
  1045. UpdateData(TRUE);
  1046. bManual = IsDlgButtonChecked (IDC_MANUAL_NAME);
  1047. if (!bManual) {
  1048. dwAutoNameFormat = ((CComboBox *)GetDlgItem(IDC_AUTO_NAME_COMBO))->GetCurSel();
  1049. dwAutoChangeInterval = ((CComboBox *)GetDlgItem(IDC_RENAME_UNITS))->GetCurSel();
  1050. // check for valid interval/name combinations
  1051. switch (dwAutoChangeInterval) {
  1052. case OPD_RENAME_HOURS:
  1053. if ((dwAutoNameFormat == OPD_NAME_YYDDD) ||
  1054. (dwAutoNameFormat == OPD_NAME_YYMM) ||
  1055. (dwAutoNameFormat == OPD_NAME_YYMMDD)) bBogus = TRUE;
  1056. break;
  1057. case OPD_RENAME_DAYS:
  1058. if (dwAutoNameFormat == OPD_NAME_YYMM) bBogus = TRUE;
  1059. break;
  1060. case OPD_RENAME_MONTHS:
  1061. break;
  1062. case OPD_RENAME_KBYTES:
  1063. case OPD_RENAME_MBYTES:
  1064. default:
  1065. if (dwAutoNameFormat != OPD_NAME_NNNNNN) bBogus = TRUE;
  1066. break;
  1067. }
  1068. }
  1069. if (bBogus) {
  1070. // display warning
  1071. if (AfxMessageBox (IDS_NAME_FORMAT_NOT_COMPATIBLE,
  1072. MB_OKCANCEL, 0) == IDCANCEL) {
  1073. // the user has selected to change it so this is not valid
  1074. bReturn = FALSE;
  1075. }
  1076. }
  1077. // is manual filename button pushed?
  1078. if (bManual) {
  1079. // YES:
  1080. csFilename.Empty();
  1081. // write output filename frome edit box
  1082. csFilename = m_OutputFileName;
  1083. bPathHasFileName = TRUE;
  1084. } else {
  1085. // auto is pressed so:
  1086. csFilename.Empty();
  1087. // save Log Default Directory
  1088. csFilename = m_szLogDirectory;
  1089. bPathHasFileName = FALSE;
  1090. }
  1091. // check to see if the dir path is valid
  1092. if (!IsDirPathValid (csFilename, !bPathHasFileName, FALSE)) {
  1093. nMbReturn = AfxMessageBox (IDS_DIR_NOT_FOUND,
  1094. MB_YESNOCANCEL, 0);
  1095. if (nMbReturn == IDYES) {
  1096. // create the dir(s)
  1097. if (!IsDirPathValid (csFilename, !bPathHasFileName, TRUE)) {
  1098. // unable to create the dir, display message
  1099. nMbReturn = AfxMessageBox (IDS_DIR_NOT_MADE,
  1100. MB_OK, 0);
  1101. bReturn = FALSE;
  1102. }
  1103. } else if (nMbReturn == IDCANCEL) {
  1104. // then abort and return to the dialog
  1105. bReturn = FALSE;
  1106. }
  1107. } // else the path is OK
  1108. return bReturn;
  1109. }
  1110. void COutputPropPage::OnExecuteCheck()
  1111. {
  1112. BOOL bExecuteCmd;
  1113. m_ExecuteCmd = IsDlgButtonChecked (IDC_EXECUTE_CHECK);
  1114. bExecuteCmd = (m_ExecuteCmd != 0 ? TRUE : FALSE);
  1115. GetDlgItem(IDC_CMD_FILENAME)->EnableWindow(bExecuteCmd);
  1116. GetDlgItem(IDC_BROWSE_CMD_FILE)->EnableWindow(bExecuteCmd);
  1117. SetModified(TRUE);
  1118. }
  1119. void COutputPropPage::OnBrowseCmdFile()
  1120. {
  1121. OPENFILENAME ofn;
  1122. CComboBox *cFileTypeCombo;
  1123. CString csInitialDir;
  1124. LONG lLogFileType;
  1125. TCHAR szFileName[MAX_PATH];
  1126. CString csBaseFilename;
  1127. TCHAR szDrive[MAX_PATH];
  1128. TCHAR szDir[MAX_PATH];
  1129. TCHAR szExt[MAX_PATH];
  1130. LPTSTR szDefExt = NULL;
  1131. GetDlgItemText (IDC_CMD_FILENAME, csBaseFilename);
  1132. _tsplitpath((LPCTSTR)csBaseFilename,
  1133. szDrive, szDir, szFileName, szExt);
  1134. csInitialDir = szDrive;
  1135. csInitialDir += szDir;
  1136. lstrcat (szFileName, szExt);
  1137. ofn.lStructSize = sizeof(ofn);
  1138. ofn.hwndOwner = m_hWnd;
  1139. ofn.hInstance = GetModuleHandle(NULL);
  1140. ofn.lpstrFilter = TEXT("Command Files (*.bat, *.cmd)\0*.cmd;*.bat\0Executable Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0");
  1141. ofn.lpstrCustomFilter = NULL;
  1142. ofn.nMaxCustFilter = 0;
  1143. ofn.nFilterIndex = 1; // nFilterIndex is 1-based
  1144. ofn.lpstrFile = szFileName;
  1145. ofn.nMaxFile = MAX_PATH;
  1146. ofn.lpstrFileTitle = NULL;
  1147. ofn.nMaxFileTitle = 0;
  1148. ofn.lpstrInitialDir = (LPCTSTR)csInitialDir;
  1149. ofn.lpstrTitle = TEXT("Select Command Filename");
  1150. ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
  1151. ofn.nFileOffset = 0;
  1152. ofn.nFileExtension = 0;
  1153. ofn.lpstrDefExt = NULL;
  1154. ofn.lCustData = 0;
  1155. ofn.lpfnHook = NULL;
  1156. ofn.lpTemplateName = NULL;
  1157. if (GetOpenFileName (&ofn) == IDOK) {
  1158. SetDlgItemText (IDC_CMD_FILENAME, szFileName);
  1159. SetModified(TRUE);
  1160. } // else ignore if they canceled out
  1161. }
  1162. void COutputPropPage::OnChangeCmdFilename()
  1163. {
  1164. SetModified(TRUE);
  1165. }