From: boca4711 <boc...@us...> - 2005-10-16 12:09:47
|
Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19755 Added Files: FilePropTouch.cpp FilePropTouch.h Log Message: Page to show or modify file timestamps. --- NEW FILE: FilePropTouch.cpp --- // FilePropTouch.cpp: Implementierungsdatei // #include "stdafx.h" #include "anyedit.h" #include "FilePropTouch.h" #include "AnyEditDoc.h" #include "AnyEditView.h" #include "DateTimeFormat.h" #include "FilePropertyDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // Dialogfeld CFilePropTouch CFilePropTouch::CFilePropTouch(CWnd* pParent /*=NULL*/) : CPropertyPage(CFilePropTouch::IDD) { //{{AFX_DATA_INIT(CFilePropTouch) // HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein //}}AFX_DATA_INIT m_pFileProp = NULL; } void CFilePropTouch::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CFilePropTouch) DDX_Control(pDX, IDC_EDIT_TIME_OPTIONS, m_wndTime); DDX_Control(pDX, IDC_EDIT_DATE_OPTIONS, m_wndDate); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CFilePropTouch, CPropertyPage) //{{AFX_MSG_MAP(CFilePropTouch) ON_WM_TIMER() ON_BN_CLICKED(IDC_EDIT_TOUCH, OnEditTouch) ON_BN_CLICKED(IDC_EDIT_RADIO1, OnEditRadio1) ON_BN_CLICKED(IDC_EDIT_RADIO2, OnEditRadio2) ON_BN_CLICKED(IDC_EDIT_RADIO3, OnEditRadio3) ON_BN_CLICKED(IDC_TOUCH, OnTouch) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // Behandlungsroutinen für Nachrichten CFilePropTouch BOOL CFilePropTouch::OnInitDialog() { CPropertyPage::OnInitDialog(); SetDlgItemText(IDC_EDIT_TIME, _T("")); CheckRadioButton(IDC_EDIT_RADIO1, IDC_EDIT_RADIO3, IDC_EDIT_RADIO1); m_nTimerID = SetTimer(m_nTimerID, 1000, NULL); // if (m_pFileInfo && !m_strFilePath.IsEmpty()) m_strFilePath = m_pFileProp->m_strFilePath; if (!m_strFilePath.IsEmpty()) { CTime objTime; CFileStatus fStatus; CFile::GetStatus(m_strFilePath, fStatus); SetDlgItemText(IDC_EDIT_DEFAULTS, GetDateString(fStatus.m_ctime)); // Update the controls to the current file time m_wndDate.SetTime(&(fStatus.m_ctime)); m_wndTime.SetTime(&(fStatus.m_ctime)); } CString strTime = CTime::GetCurrentTime().Format(_T("Current Time: %X")); //TODO--PAUL-from resource SetDlgItemText(IDC_EDIT_TIME, strTime); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurückgeben } void CFilePropTouch::OnTimer(UINT nIDEvent) { ASSERT(m_nTimerID == nIDEvent); if (nIDEvent == m_nTimerID) { CString strTime = CTime::GetCurrentTime().Format(_T("Current Time: %X")); //TODO--PAUL-from resource SetDlgItemText(IDC_EDIT_TIME, strTime); } } void CFilePropTouch::OnEditTouch() { SYSTEMTIME stTempDate; // Temporarily holds date data SYSTEMTIME stTempTime; // Temporarily holds date data // Firstly, the Modified Date/Time Info ... // Get the Date info from the DTP m_wndDate.GetTime(&stTempDate); // Get the Time info m_wndTime.GetTime(&stTempTime); // Fill the Date and time CTime objTime(stTempDate.wYear, stTempDate.wMonth, stTempDate.wDay, stTempTime.wHour, stTempTime.wMinute, stTempTime.wSecond); FILETIME ftTouch; TimeToFileTime(objTime, &ftTouch); if (IsDlgButtonChecked(IDC_EDIT_RADIO1)) // change creation time { Touch(m_strFilePath, NULL, NULL, &ftTouch); UpdateControls(1); } else if (IsDlgButtonChecked(IDC_EDIT_RADIO2)) // change modification time { Touch(m_strFilePath, NULL, &ftTouch, NULL); UpdateControls(2); } else if (IsDlgButtonChecked(IDC_EDIT_RADIO3)) // change accessing time { Touch(m_strFilePath, &ftTouch, NULL, NULL); UpdateControls(2); } } // The magic function which does all the touching DWORD CFilePropTouch::Touch(LPCTSTR lpszFile, FILETIME* atime, FILETIME* mtime, FILETIME* ctime) { ASSERT(lpszFile); if (lpszFile == NULL) return 0; SetLastError(ERROR_SUCCESS); HANDLE hFile = CreateFile( lpszFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); DWORD dwRetVal = GetLastError(); // Check for CreateFile() special cases if (dwRetVal != ERROR_SUCCESS) { if (dwRetVal == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS; // not an error else if(hFile != INVALID_HANDLE_VALUE && dwRetVal == ERROR_ALREADY_EXISTS) dwRetVal = ERROR_SUCCESS; // not an error according to MSDN docs } if(dwRetVal != ERROR_SUCCESS) return dwRetVal; // Is there any template timestamp? if (atime || mtime || ctime) { SetLastError(ERROR_SUCCESS); SetFileTime(hFile, ctime, atime, mtime); dwRetVal = GetLastError(); } CloseHandle(hFile); return dwRetVal; } void CFilePropTouch::OnEditRadio1() { UpdateControls(1); } void CFilePropTouch::OnEditRadio2() { UpdateControls(2); } void CFilePropTouch::OnEditRadio3() { UpdateControls(3); } void CFilePropTouch::UpdateControls(int nRadioButton) { if (!m_strFilePath.IsEmpty()) { CFileStatus fStatus; CFile::GetStatus(m_strFilePath, fStatus); CTime t; switch(nRadioButton) { case 1: t = fStatus.m_ctime; break; case 2: t = fStatus.m_mtime; break; case 3: t = fStatus.m_atime; break; } m_wndDate.SetTime(&t); m_wndTime.SetTime(&t); SetDlgItemText(IDC_EDIT_DEFAULTS, GetDateString(t)); } } CString CFilePropTouch::GetDateString(CTime t) { COleDateTime odt(t.GetTime()); CDateTimeFormat dtf; dtf.SetDateTime(odt); CString strFormat; TCHAR szTemp[MAX_PATH] = {0}; GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, szTemp, MAX_PATH); strFormat = szTemp; GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, szTemp, MAX_PATH); strFormat += _T(", "); strFormat += szTemp; dtf.SetFormat(strFormat); return dtf.GetString(); } void CFilePropTouch::SetFileInfo(CFileProperty *pFileInfo) { m_pFileProp = pFileInfo; } void CFilePropTouch::OnTouch() { // Fill the Date and time CTime objTime = CTime::GetCurrentTime(); FILETIME ftTouch; TimeToFileTime(objTime, &ftTouch); if (IsDlgButtonChecked(IDC_EDIT_RADIO1)) // change creation time { Touch(m_strFilePath, NULL, NULL, &ftTouch); UpdateControls(1); } else if (IsDlgButtonChecked(IDC_EDIT_RADIO2)) // change modification time { Touch(m_strFilePath, NULL, &ftTouch, NULL); UpdateControls(2); } else if (IsDlgButtonChecked(IDC_EDIT_RADIO3)) // change accessing time { Touch(m_strFilePath, &ftTouch, NULL, NULL); UpdateControls(2); } } --- NEW FILE: FilePropTouch.h --- (This appears to be a binary file; contents omitted.) |