// LogFile.cpp : implementation file // #include "stdafx.h" #include "twnconfig.h" #include "LogFile.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CLogFile dialog CLogFile::CLogFile(L_BOOL bShowLog, CWnd* pParent /*=NULL*/) : CDialog(CLogFile::IDD, pParent) { //{{AFX_DATA_INIT(CLogFile) m_csFileName = _T(""); //}}AFX_DATA_INIT m_csDatFile = _T(""); m_csDatFileNum = _T(""); m_bShowLog = bShowLog; } void CLogFile::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CLogFile) DDX_Control(pDX, IDOK, m_btnOK); DDX_Control(pDX, IDC_EDIT_FILE_NAME, m_edtFileName); DDX_Text(pDX, IDC_EDIT_FILE_NAME, m_csFileName); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CLogFile, CDialog) //{{AFX_MSG_MAP(CLogFile) ON_BN_CLICKED(IDC_BTN_SEL_LOG_FILE, OnBtnSelLogFile) ON_EN_CHANGE(IDC_EDIT_FILE_NAME, OnChangeEditFileName) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLogFile message handlers void CLogFile::OnBtnSelLogFile() { L_TCHAR *pszFilters = (m_bShowLog) ? _T("Log Files (*.log)|*.log|") : _T("All Files (*.*)|*.*|"); CFileDialog FileDlg((m_bShowLog)? TRUE : FALSE, (m_bShowLog)? _T("LOG") : NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, pszFilters); if (FileDlg.DoModal() == IDOK) { CString csFPath = FileDlg.GetPathName(); CheckFileName(csFPath); } } L_BOOL CLogFile::CheckFileName(CString csFileName) { if (!m_bShowLog) { m_edtFileName.SetWindowText(csFileName); return TRUE; } if (DEMOACCESS(csFileName, 0) == -1) { AfxMessageBox(_T("Invalid File Name, please select another file...")); return FALSE; } TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; TCHAR szFName[_MAX_FNAME]; _tsplitpath(csFileName, szDrive, szDir, szFName, NULL); LPTSTR szBuffer = m_csDatFile.GetBuffer(MAX_PATH); _tmakepath(szBuffer, szDrive, szDir, szFName, _T("DAT")); m_csDatFile.ReleaseBuffer(); szBuffer = m_csDatFileNum.GetBuffer(MAX_PATH); _tmakepath(szBuffer, szDrive, szDir, szFName, _T("DATC")); m_csDatFileNum.ReleaseBuffer(); if (DEMOACCESS(m_csDatFile, 0) != -1 && DEMOACCESS(m_csDatFileNum, 0) != -1) m_edtFileName.SetWindowText(csFileName); else { AfxMessageBox(_T("Invalid Log file name,\nplease select another Log file...")); m_csDatFile = _T(""); m_csDatFileNum = _T(""); } return TRUE; } void CLogFile::OnChangeEditFileName() { CString csText; m_edtFileName.GetWindowText(csText); m_btnOK.EnableWindow(!csText.IsEmpty()); } BOOL CLogFile::OnInitDialog() { CDialog::OnInitDialog(); OnChangeEditFileName(); if (!m_bShowLog) SetWindowText(_T("Select File Name")); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CLogFile::OnOK() { CString csText; m_edtFileName.GetWindowText(csText); if (!CheckFileName(csText)) return; CDialog::OnOK(); }