Index: src/ch/CustomCopyDlg.cpp =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -690,19 +690,16 @@ { _sntprintf(szLoaded, 1024, _T("%s %s"), GetResManager().LoadString(IDS_DATECREATED_STRING+rFilter.GetDateType()), GetResManager().LoadString(IDS_LT_STRING+rFilter.GetDateCmpType1())); szLoaded[1023] = _T('\0'); - if (rFilter.GetUseDate1()) - _tcscat(szLoaded, rFilter.GetDate1().Format(_T(" %x"))); - if (rFilter.GetUseTime1()) - _tcscat(szLoaded, rFilter.GetTime1().Format(_T(" %X"))); + chcore::TString strFmtDateTime = rFilter.GetDateTime1().Format(rFilter.GetUseDate1(), rFilter.GetUseTime1()); + _tcscat(szLoaded, (PCTSTR)strFmtDateTime); if (rFilter.GetUseDateTime2()) { _tcscat(szLoaded, GetResManager().LoadString(IDS_AND_STRING)); - _tcscat(szLoaded, GetResManager().LoadString(IDS_LT_STRING+rFilter.GetDateCmpType2())); - if (rFilter.GetUseDate2()) - _tcscat(szLoaded, rFilter.GetDate2().Format(_T(" %x"))); - if (rFilter.GetUseTime2()) - _tcscat(szLoaded, rFilter.GetTime2().Format(_T(" %X"))); + _tcscat(szLoaded, GetResManager().LoadString(IDS_LT_STRING + rFilter.GetDateCmpType2())); + + strFmtDateTime = rFilter.GetDateTime2().Format(rFilter.GetUseDate2(), rFilter.GetUseTime2()); + _tcscat(szLoaded, (PCTSTR)strFmtDateTime); } } else Index: src/ch/FilterDlg.cpp =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/ch/FilterDlg.cpp (.../FilterDlg.cpp) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/ch/FilterDlg.cpp (.../FilterDlg.cpp) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -141,9 +141,9 @@ chcore::TString strData; m_ctlFilter.SetCurSel(m_ctlFilter.AddString(m_ffFilter.GetCombinedMask(strData))); for (int i=0;i(m_uiSize1)*static_cast(GetMultiplier(m_ctlSize1Multi.GetCurSel()))); m_ffFilter.SetSize2(static_cast(m_uiSize2)*static_cast(GetMultiplier(m_ctlSize2Multi.GetCurSel()))); // date - m_ffFilter.SetDateType((chcore::CFileFilter::EDateType)m_ctlDateType.GetCurSel()); + m_ffFilter.SetDateType((chcore::CFileFilter::EDateType)m_ctlDateType.GetCurSel()); - m_ffFilter.SetDateCmpType1((chcore::CFileFilter::EDateCompareType)m_ctlDateType1.GetCurSel()); + m_ffFilter.SetDateCmpType1((chcore::CFileFilter::EDateCompareType)m_ctlDateType1.GetCurSel()); m_ffFilter.SetDateCmpType2((chcore::CFileFilter::EDateCompareType)m_ctlDateType2.GetCurSel()); - CTime tDateTime; - m_ffFilter.SetUseDate1(m_ctlDate1.GetTime(tDateTime) == GDT_VALID); - m_ffFilter.SetDate1(tDateTime); - m_ffFilter.SetUseDate2(m_ctlDate2.GetTime(tDateTime) == GDT_VALID); - m_ffFilter.SetDate2(tDateTime); - m_ffFilter.SetUseTime1(m_ctlTime1.GetTime(tDateTime) == GDT_VALID); - m_ffFilter.SetTime1(tDateTime); - m_ffFilter.SetUseTime2(m_ctlTime2.GetTime(tDateTime) == GDT_VALID); - m_ffFilter.SetTime2(tDateTime); + CTime tDate; + CTime tTime; + m_ffFilter.SetUseDate1(m_ctlDate1.GetTime(tDate) == GDT_VALID); + m_ffFilter.SetUseTime1(m_ctlTime1.GetTime(tTime) == GDT_VALID); + m_ffFilter.SetDateTime1(chcore::TDateTime(tDate.GetYear(), tDate.GetMonth(), tDate.GetDay(), tTime.GetHour(), tTime.GetMinute(), tTime.GetSecond())); + + m_ffFilter.SetUseDate2(m_ctlDate2.GetTime(tDate) == GDT_VALID); + m_ffFilter.SetUseTime2(m_ctlTime2.GetTime(tTime) == GDT_VALID); + m_ffFilter.SetDateTime2(chcore::TDateTime(tDate.GetYear(), tDate.GetMonth(), tDate.GetDay(), tTime.GetHour(), tTime.GetMinute(), tTime.GetSecond())); m_ffFilter.SetUseDateTime1((m_bDate1 != 0) && (m_ffFilter.GetUseDate1() || m_ffFilter.GetUseTime1())); m_ffFilter.SetUseDateTime2((m_bDate2 != 0) && (m_ffFilter.GetUseDate2() || m_ffFilter.GetUseTime2())); Index: src/ch/FilterDlg.h =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/ch/FilterDlg.h (.../FilterDlg.h) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/ch/FilterDlg.h (.../FilterDlg.h) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -70,12 +70,12 @@ virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL -// Implementation + // Implementation public: void SetSize2(unsigned __int64 ullSize); - chcore::CFileFilter m_ffFilter; - CStringArray m_astrAddMask; - CStringArray m_astrAddExcludeMask; + chcore::CFileFilter m_ffFilter; + CStringArray m_astrAddMask; + CStringArray m_astrAddExcludeMask; protected: virtual void OnLanguageChanged(); Index: src/ch/TLocalFilesystem.h =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/ch/TLocalFilesystem.h (.../TLocalFilesystem.h) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/ch/TLocalFilesystem.h (.../TLocalFilesystem.h) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -28,8 +28,8 @@ namespace chcore { - class CFileInfo; - typedef boost::shared_ptr CFileInfoPtr; + class CFileInfo; + typedef boost::shared_ptr CFileInfoPtr; } class TAutoFileHandle; @@ -63,7 +63,7 @@ static bool RemoveDirectory(const chcore::TSmartPath& pathFile); static bool DeleteFile(const chcore::TSmartPath& pathFile); - static bool GetFileInfo(const chcore::TSmartPath& pathFile, chcore::CFileInfoPtr& rFileInfo, size_t stSrcIndex = std::numeric_limits::max(), const chcore::TPathContainer* pBasePaths = NULL); + static bool GetFileInfo(const chcore::TSmartPath& pathFile, chcore::CFileInfoPtr& rFileInfo, size_t stSrcIndex = std::numeric_limits::max(), const chcore::TPathContainer* pBasePaths = NULL); static bool FastMove(const chcore::TSmartPath& pathSource, const chcore::TSmartPath& pathDestination); static TLocalFilesystemFind CreateFinderObject(const chcore::TSmartPath& pathDir, const chcore::TSmartPath& pathMask); Index: src/ch/TSubTaskBase.h =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/ch/TSubTaskBase.h (.../TSubTaskBase.h) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/ch/TSubTaskBase.h (.../TSubTaskBase.h) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -54,7 +54,7 @@ protected: // some common operations - chcore::TSmartPath CalculateDestinationPath(const chcore::CFileInfoPtr& spFileInfo, chcore::TSmartPath strPath, int iFlags) const; + chcore::TSmartPath CalculateDestinationPath(const chcore::CFileInfoPtr& spFileInfo, chcore::TSmartPath strPath, int iFlags) const; chcore::TSmartPath FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath) const; private: Index: src/ch/TSubTaskCopyMove.h =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/ch/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/ch/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -28,7 +28,7 @@ namespace chcore { class TDataBuffer; - typedef boost::shared_ptr CFileInfoPtr; + typedef boost::shared_ptr CFileInfoPtr; } struct CUSTOM_COPY_PARAMS; @@ -42,7 +42,7 @@ ESubOperationResult Exec(); private: - bool GetMove(const chcore::CFileInfoPtr& spFileInfo); + bool GetMove(const chcore::CFileInfoPtr& spFileInfo); int GetBufferIndex(const chcore::CFileInfoPtr& spFileInfo); ESubOperationResult CustomCopyFileFB(CUSTOM_COPY_PARAMS* pData); Index: src/ch/TSubTaskDelete.cpp =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/ch/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/ch/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -39,7 +39,7 @@ { // log icpf::log_file& rLog = GetContext().GetLog(); - chcore::CFileInfoArray& rFilesCache = GetContext().GetFilesCache(); + chcore::CFileInfoArray& rFilesCache = GetContext().GetFilesCache(); chcore::TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); TTaskBasicProgressInfo& rBasicProgressInfo = GetContext().GetTaskBasicProgressInfo(); chcore::TWorkerThreadController& rThreadController = GetContext().GetThreadController(); @@ -50,7 +50,7 @@ // current processed path BOOL bSuccess; - chcore::CFileInfoPtr spFileInfo; + chcore::CFileInfoPtr spFileInfo; ictranslate::CFormat fmt; // index points to 0 or next item to process Index: src/ch/TSubTaskScanDirectory.cpp =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/ch/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/ch/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -80,7 +80,7 @@ size_t stSize = rTaskDefinition.GetSourcePathCount(); for(size_t stIndex = 0; stIndex < stSize ; stIndex++) { - chcore::CFileInfoPtr spFileInfo; + chcore::CFileInfoPtr spFileInfo; bSkipInputPath = false; @@ -220,12 +220,12 @@ int TSubTaskScanDirectories::ScanDirectory(chcore::TSmartPath pathDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs, chcore::CFiltersArray& afFilters) { - chcore::CFileInfoArray& rFilesCache = GetContext().GetFilesCache(); + chcore::CFileInfoArray& rFilesCache = GetContext().GetFilesCache(); chcore::TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); chcore::TWorkerThreadController& rThreadController = GetContext().GetThreadController(); TLocalFilesystemFind finder = TLocalFilesystem::CreateFinderObject(pathDirName, chcore::PathFromString(_T("*"))); - chcore::CFileInfoPtr spFileInfo(boost::make_shared()); + chcore::CFileInfoPtr spFileInfo(boost::make_shared()); while(finder.FindNext(spFileInfo)) { @@ -238,7 +238,7 @@ { spFileInfo->SetParentObject(stSrcIndex, &rTaskDefinition.GetSourcePaths()); rFilesCache.AddFileInfo(spFileInfo); - spFileInfo = boost::make_shared(); + spFileInfo = boost::make_shared(); } } else @@ -248,7 +248,7 @@ { spFileInfo->SetParentObject(stSrcIndex, &rTaskDefinition.GetSourcePaths()); rFilesCache.AddFileInfo(spFileInfo); - spFileInfo = boost::make_shared(); + spFileInfo = boost::make_shared(); } if(bRecurse) Index: src/ch/task.h =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/ch/task.h (.../task.h) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/ch/task.h (.../task.h) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -64,7 +64,7 @@ size_t m_stSize; chcore::TSmartPath m_pathDstPath; - chcore::CFiltersArray* m_pafFilters; + chcore::CFiltersArray* m_pafFilters; ETaskCurrentState m_eTaskState; chcore::EOperationType m_eOperationType; @@ -214,7 +214,7 @@ // current task state (derivatives of the task initial information) // changing slowly or only partially - chcore::CFileInfoArray m_files; // list of files/directories found during operating on the task input data (filled by search for files) + chcore::CFileInfoArray m_files; // list of files/directories found during operating on the task input data (filled by search for files) // changing fast volatile ETaskCurrentState m_eCurrentState; // current state of processing this task represents @@ -225,7 +225,7 @@ TTaskLocalStats m_localStats; // local statistics // task settings - chcore::CFiltersArray m_afFilters; // filtering settings for files (will be filtered according to the rules inside when searching for files) + chcore::CFiltersArray m_afFilters; // filtering settings for files (will be filtered according to the rules inside when searching for files) bool m_bForce; // if the continuation of tasks should be independent of max concurrently running task limit bool m_bContinue; // allows task to continue Index: src/libchcore/ErrorCodes.h =================================================================== diff -u -rab32897e61cc637a1e28d9dc3f0489b8d16a429c -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/libchcore/ErrorCodes.h (.../ErrorCodes.h) (revision ab32897e61cc637a1e28d9dc3f0489b8d16a429c) +++ src/libchcore/ErrorCodes.h (.../ErrorCodes.h) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -32,6 +32,7 @@ eErr_UnhandledCase = 3, eErr_InternalProblem = 4, eErr_UseOfUninitializedObject = 5, + eErr_InvalidData = 6, // shared memory (500+) eErr_CannotOpenSharedMemory = 500, Index: src/libchcore/FileFilter.cpp =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/libchcore/FileFilter.cpp (.../FileFilter.cpp) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/libchcore/FileFilter.cpp (.../FileFilter.cpp) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -53,17 +53,15 @@ m_bUseDateTime1=false; m_eDateType = eDateType_Created; m_eDateCmpType1 = eDateCmp_Greater; - m_bUseDate1=false; - m_tDate1=CTime::GetCurrentTime(); - m_bUseTime1=false; - m_tTime1=CTime::GetCurrentTime(); + m_bUseDate1 = false; + m_bUseTime1 = false; + m_tDateTime1.SetCurrentDateTime(); m_bUseDateTime2=false; m_eDateCmpType2 = eDateCmp_Less; m_bUseDate2=false; - m_tDate2=CTime::GetCurrentTime(); m_bUseTime2=false; - m_tTime2=CTime::GetCurrentTime(); + m_tDateTime2.SetCurrentDateTime(); // attribute filtering m_bUseAttributes=false; @@ -101,16 +99,14 @@ m_eDateType=rFilter.m_eDateType; m_eDateCmpType1=rFilter.m_eDateCmpType1; m_bUseDate1=rFilter.m_bUseDate1; - m_tDate1=rFilter.m_tDate1; m_bUseTime1=rFilter.m_bUseTime1; - m_tTime1=rFilter.m_tTime1; + m_tDateTime1 = rFilter.m_tDateTime1; m_bUseDateTime2=rFilter.m_bUseDateTime2; m_eDateCmpType2=rFilter.m_eDateCmpType2; m_bUseDate2=rFilter.m_bUseDate2; - m_tDate2=rFilter.m_tDate2; m_bUseTime2=rFilter.m_bUseTime2; - m_tTime2=rFilter.m_tTime2; + m_tDateTime2 = rFilter.m_tDateTime2; // attribute filtering m_bUseAttributes=rFilter.m_bUseAttributes; @@ -143,7 +139,7 @@ { m_astrMask.Clear(); - pMask.Split(_T("|"), m_astrMask); + pMask.Split(_T("|"), m_astrMask); } chcore::TString& CFileFilter::GetCombinedExcludeMask(chcore::TString& strMask) const @@ -166,7 +162,7 @@ { m_astrExcludeMask.Clear(); - pMask.Split(_T("|"), m_astrExcludeMask); + pMask.Split(_T("|"), m_astrExcludeMask); } void CFileFilter::StoreInConfig(chcore::TConfig& rConfig) const @@ -188,16 +184,14 @@ SetConfigValue(rConfig, _T("DateA.Type"), m_eDateType); // created/last modified/last accessed SetConfigValue(rConfig, _T("DateA.FilteringType"), m_eDateCmpType1); // before/after SetConfigValue(rConfig, _T("DateA.EnableDatePart"), m_bUseDate1); - SetConfigValue(rConfig, _T("DateA.DateValue"), m_tDate1.GetTime()); SetConfigValue(rConfig, _T("DateA.EnableTimePart"), m_bUseTime1); - SetConfigValue(rConfig, _T("DateA.TimeValue"), m_tTime1.GetTime()); + SetConfigValue(rConfig, _T("DateA.DateTimeValue"), m_tDateTime1); SetConfigValue(rConfig, _T("DateB.Type"), m_bUseDateTime2); SetConfigValue(rConfig, _T("DateB.FilteringType"), m_eDateCmpType2); SetConfigValue(rConfig, _T("DateB.EnableDatePart"), m_bUseDate2); - SetConfigValue(rConfig, _T("DateB.DateValue"), m_tDate2.GetTime()); SetConfigValue(rConfig, _T("DateB.EnableTimePart"), m_bUseTime2); - SetConfigValue(rConfig, _T("DateB.TimeValue"), m_tTime2.GetTime()); + SetConfigValue(rConfig, _T("DateB.DateTimeValue"), m_tDateTime2); SetConfigValue(rConfig, _T("Attributes.Use"), m_bUseAttributes); SetConfigValue(rConfig, _T("Attributes.Archive"), m_iArchive); @@ -209,8 +203,6 @@ void CFileFilter::ReadFromConfig(const chcore::TConfig& rConfig) { - __time64_t tTime = 0; - if(!GetConfigValue(rConfig, _T("IncludeMask.Use"), m_bUseMask)) m_bUseMask = false; @@ -245,17 +237,11 @@ m_eDateCmpType1 = eDateCmp_Equal; if(!GetConfigValue(rConfig, _T("DateA.EnableDatePart"), m_bUseDate1)) m_bUseDate1 = false; - - if(!GetConfigValue(rConfig, _T("DateA.DateValue"), tTime)) - tTime = 0; - m_tDate1 = tTime; - if(!GetConfigValue(rConfig, _T("DateA.EnableTimePart"), m_bUseTime1)) m_bUseTime1 = false; - if(!GetConfigValue(rConfig, _T("DateA.TimeValue"), tTime)) - tTime = 0; - m_tTime1 = tTime; + if(!GetConfigValue(rConfig, _T("DateA.DateTimeValue"), m_tDateTime1)) + m_tDateTime1.Clear(); if(!GetConfigValue(rConfig, _T("DateB.Type"), m_bUseDateTime2)) m_bUseDateTime2 = false; @@ -264,14 +250,10 @@ if(!GetConfigValue(rConfig, _T("DateB.EnableDatePart"), m_bUseDate2)) m_bUseDate2 = false; - if(!GetConfigValue(rConfig, _T("DateB.DateValue"), tTime)) - tTime = 0; - m_tDate2 = tTime; + if(!GetConfigValue(rConfig, _T("DateB.DateTimeValue"), m_tDateTime2)) + m_tDateTime2.Clear(); if(!GetConfigValue(rConfig, _T("DateB.EnableTimePart"), m_bUseTime2)) m_bUseTime2 = false; - if(!GetConfigValue(rConfig, _T("DateB.TimeValue"), tTime)) - tTime = 0; - m_tTime2 = tTime; if(!GetConfigValue(rConfig, _T("Attributes.Use"), m_bUseAttributes)) m_bUseAttributes = false; @@ -308,16 +290,14 @@ Serialize(rSerializer, m_eDateType); // created/last modified/last accessed Serialize(rSerializer, m_eDateCmpType1); // before/after Serialize(rSerializer, m_bUseDate1); - Serialize(rSerializer, m_tDate1); Serialize(rSerializer, m_bUseTime1); - Serialize(rSerializer, m_tTime1); + Serialize(rSerializer, m_tDateTime1); Serialize(rSerializer, m_bUseDateTime2); Serialize(rSerializer, m_eDateCmpType2); Serialize(rSerializer, m_bUseDate2); - Serialize(rSerializer, m_tDate2); Serialize(rSerializer, m_bUseTime2); - Serialize(rSerializer, m_tTime2); + Serialize(rSerializer, m_tDateTime2); Serialize(rSerializer, m_bUseAttributes); Serialize(rSerializer, m_iArchive); @@ -348,16 +328,14 @@ Serialize(rSerializer, m_eDateType); // created/last modified/last accessed Serialize(rSerializer, m_eDateCmpType1); // before/after Serialize(rSerializer, m_bUseDate1); - Serialize(rSerializer, m_tDate1); Serialize(rSerializer, m_bUseTime1); - Serialize(rSerializer, m_tTime1); + Serialize(rSerializer, m_tDateTime1); Serialize(rSerializer, m_bUseDateTime2); Serialize(rSerializer, m_eDateCmpType2); Serialize(rSerializer, m_bUseDate2); - Serialize(rSerializer, m_tDate2); Serialize(rSerializer, m_bUseTime2); - Serialize(rSerializer, m_tTime2); + Serialize(rSerializer, m_tDateTime2); Serialize(rSerializer, m_bUseAttributes); Serialize(rSerializer, m_iArchive); @@ -451,96 +429,74 @@ // date - get the time from rInfo if (m_bUseDateTime1) { - ATL::CTime tm; - switch (m_eDateType) + TDateTime tDateTime; + switch(m_eDateType) { case eDateType_Created: - tm=spInfo->GetCreationTime(); + tDateTime = spInfo->GetCreationTime(); break; case eDateType_Modified: - tm=spInfo->GetLastWriteTime(); + tDateTime = spInfo->GetLastWriteTime(); break; case eDateType_LastAccessed: - tm=spInfo->GetLastAccessTime(); + tDateTime = spInfo->GetLastAccessTime(); break; } // counting... - unsigned long ulInfo=0, ulCheck=0; - if (m_bUseDate1) - { - ulInfo=(tm.GetYear()-1970)*32140800+tm.GetMonth()*2678400+tm.GetDay()*86400; - ulCheck=(m_tDate1.GetYear()-1970)*32140800+m_tDate1.GetMonth()*2678400+m_tDate1.GetDay()*86400; - } + time_t tDiff = m_tDateTime1.Compare(tDateTime, m_bUseDate1, m_bUseTime1); - if (m_bUseTime1) - { - ulInfo+=tm.GetHour()*3600+tm.GetMinute()*60+tm.GetSecond(); - ulCheck+=m_tTime1.GetHour()*3600+m_tTime1.GetMinute()*60+m_tTime1.GetSecond(); - } - // ... and comparing - switch (m_eDateCmpType1) + switch(m_eDateCmpType1) { case eDateCmp_Less: - if (ulInfo >= ulCheck) + if(tDiff >= 0) return false; break; case eDateCmp_LessOrEqual: - if (ulInfo > ulCheck) + if(tDiff > 0) return false; break; case eDateCmp_Equal: - if (ulInfo != ulCheck) + if(tDiff != 0) return false; break; case eDateCmp_GreaterOrEqual: - if (ulInfo < ulCheck) + if(tDiff < 0) return false; break; case eDateCmp_Greater: - if (ulInfo <= ulCheck) + if(tDiff <= 0) return false; break; } if (m_bUseDateTime2) { // counting... - ulInfo=0, ulCheck=0; - if (m_bUseDate2) - { - ulInfo=(tm.GetYear()-1970)*32140800+tm.GetMonth()*2678400+tm.GetDay()*86400; - ulCheck=(m_tDate2.GetYear()-1970)*32140800+m_tDate2.GetMonth()*2678400+m_tDate2.GetDay()*86400; - } + tDiff = m_tDateTime2.Compare(tDateTime, m_bUseDate2, m_bUseTime2); - if (m_bUseTime2) - { - ulInfo+=tm.GetHour()*3600+tm.GetMinute()*60+tm.GetSecond(); - ulCheck+=m_tTime2.GetHour()*3600+m_tTime2.GetMinute()*60+m_tTime2.GetSecond(); - } - // ... comparing switch (m_eDateCmpType2) { case eDateCmp_Less: - if (ulInfo >= ulCheck) + if(tDiff >= 0) return false; break; case eDateCmp_LessOrEqual: - if (ulInfo > ulCheck) + if(tDiff > 0) return false; break; case eDateCmp_Equal: - if (ulInfo != ulCheck) + if(tDiff != 0) return false; break; case eDateCmp_GreaterOrEqual: - if (ulInfo < ulCheck) + if(tDiff < 0) return false; break; case eDateCmp_Greater: - if (ulInfo <= ulCheck) + if(tDiff <= 0) return false; break; } Index: src/libchcore/FileFilter.h =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/libchcore/FileFilter.h (.../FileFilter.h) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/libchcore/FileFilter.h (.../FileFilter.h) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -22,6 +22,7 @@ #include "libchcore.h" #include "FileInfo.h" #include +#include "TDateTime.h" BEGIN_CHCORE_NAMESPACE @@ -30,30 +31,30 @@ class LIBCHCORE_API CFileFilter { public: - enum ESizeCompareType - { - eSizeCmp_Less = 0, - eSizeCmp_LessOrEqual = 1, - eSizeCmp_Equal = 2, - eSizeCmp_GreaterOrEqual = 3, - eSizeCmp_Greater = 4 - }; + enum ESizeCompareType + { + eSizeCmp_Less = 0, + eSizeCmp_LessOrEqual = 1, + eSizeCmp_Equal = 2, + eSizeCmp_GreaterOrEqual = 3, + eSizeCmp_Greater = 4 + }; - enum EDateCompareType - { - eDateCmp_Less = 0, - eDateCmp_LessOrEqual = 1, - eDateCmp_Equal = 2, - eDateCmp_GreaterOrEqual = 3, - eDateCmp_Greater = 4 - }; + enum EDateCompareType + { + eDateCmp_Less = 0, + eDateCmp_LessOrEqual = 1, + eDateCmp_Equal = 2, + eDateCmp_GreaterOrEqual = 3, + eDateCmp_Greater = 4 + }; - enum EDateType - { - eDateType_Created = 0, - eDateType_Modified = 1, - eDateType_LastAccessed = 2 - }; + enum EDateType + { + eDateType_Created = 0, + eDateType_Modified = 1, + eDateType_LastAccessed = 2 + }; public: CFileFilter(); @@ -74,148 +75,140 @@ void Serialize(chcore::TReadBinarySerializer& rSerializer); void Serialize(chcore::TWriteBinarySerializer& rSerializer) const; - // atrributes access - bool GetUseMask() const { return m_bUseMask; } - void SetUseMask(bool bUseMask) { m_bUseMask = bUseMask; } + // atrributes access + bool GetUseMask() const { return m_bUseMask; } + void SetUseMask(bool bUseMask) { m_bUseMask = bUseMask; } -// const chcore::TStringArray& GetMaskArray() const { return m_astrMask; } -// chcore::TStringArray& GetMaskArray() { return m_astrMask; } + // const chcore::TStringArray& GetMaskArray() const { return m_astrMask; } + // chcore::TStringArray& GetMaskArray() { return m_astrMask; } - bool GetUseExcludeMask() const { return m_bUseExcludeMask; } - void SetUseExcludeMask(bool bUseExcludeMask) { m_bUseExcludeMask = bUseExcludeMask; } + bool GetUseExcludeMask() const { return m_bUseExcludeMask; } + void SetUseExcludeMask(bool bUseExcludeMask) { m_bUseExcludeMask = bUseExcludeMask; } -// const chcore::TStringArray& GetExcludeMaskArray() const { return m_astrExcludeMask; } -// chcore::TStringArray& GetExcludeMaskArray() { return m_astrExcludeMask; } + // const chcore::TStringArray& GetExcludeMaskArray() const { return m_astrExcludeMask; } + // chcore::TStringArray& GetExcludeMaskArray() { return m_astrExcludeMask; } - bool GetUseSize1() const { return m_bUseSize1; } - void SetUseSize1(bool bUseSize1) { m_bUseSize1 = bUseSize1; } + bool GetUseSize1() const { return m_bUseSize1; } + void SetUseSize1(bool bUseSize1) { m_bUseSize1 = bUseSize1; } - ESizeCompareType GetSizeType1() const { return m_eSizeCmpType1; } - void SetSizeType1(ESizeCompareType eSizeType1) { m_eSizeCmpType1 = eSizeType1; } + ESizeCompareType GetSizeType1() const { return m_eSizeCmpType1; } + void SetSizeType1(ESizeCompareType eSizeType1) { m_eSizeCmpType1 = eSizeType1; } - unsigned long long GetSize1() const { return m_ullSize1; } - void SetSize1(unsigned long long ullSize1) { m_ullSize1 = ullSize1; } + unsigned long long GetSize1() const { return m_ullSize1; } + void SetSize1(unsigned long long ullSize1) { m_ullSize1 = ullSize1; } - bool GetUseSize2() const { return m_bUseSize2; } - void SetUseSize2(bool bUseSize2) { m_bUseSize2 = bUseSize2; } + bool GetUseSize2() const { return m_bUseSize2; } + void SetUseSize2(bool bUseSize2) { m_bUseSize2 = bUseSize2; } - ESizeCompareType GetSizeType2() const { return m_eSizeCmpType2; } - void SetSizeType2(ESizeCompareType eSizeType2) { m_eSizeCmpType2 = eSizeType2; } + ESizeCompareType GetSizeType2() const { return m_eSizeCmpType2; } + void SetSizeType2(ESizeCompareType eSizeType2) { m_eSizeCmpType2 = eSizeType2; } - unsigned long long GetSize2() const { return m_ullSize2; } - void SetSize2(unsigned long long ullSize2) { m_ullSize2 = ullSize2; } + unsigned long long GetSize2() const { return m_ullSize2; } + void SetSize2(unsigned long long ullSize2) { m_ullSize2 = ullSize2; } - // dates - CFileFilter::EDateType GetDateType() const { return m_eDateType; } - void SetDateType(CFileFilter::EDateType eDateType) { m_eDateType = eDateType; } + // dates + CFileFilter::EDateType GetDateType() const { return m_eDateType; } + void SetDateType(CFileFilter::EDateType eDateType) { m_eDateType = eDateType; } - // date 1 - bool GetUseDateTime1() const { return m_bUseDateTime1; } - void SetUseDateTime1(bool bUseDateTime1) { m_bUseDateTime1 = bUseDateTime1; } + // date 1 + bool GetUseDateTime1() const { return m_bUseDateTime1; } + void SetUseDateTime1(bool bUseDateTime1) { m_bUseDateTime1 = bUseDateTime1; } - CFileFilter::EDateCompareType GetDateCmpType1() const { return m_eDateCmpType1; } - void SetDateCmpType1(CFileFilter::EDateCompareType eCmpType1) { m_eDateCmpType1 = eCmpType1; } + CFileFilter::EDateCompareType GetDateCmpType1() const { return m_eDateCmpType1; } + void SetDateCmpType1(CFileFilter::EDateCompareType eCmpType1) { m_eDateCmpType1 = eCmpType1; } - bool GetUseDate1() const { return m_bUseDate1; } - void SetUseDate1(bool tDate1) { m_bUseDate1 = tDate1; } + bool GetUseDate1() const { return m_bUseDate1; } + void SetUseDate1(bool tDate1) { m_bUseDate1 = tDate1; } - const ATL::CTime& GetDate1() const { return m_tDate1; } - void SetDate1(const ATL::CTime& tDate1) { m_tDate1 = tDate1; } + bool GetUseTime1() const { return m_bUseTime1; } + void SetUseTime1(bool tTime1) { m_bUseTime1 = tTime1; } - bool GetUseTime1() const { return m_bUseTime1; } - void SetUseTime1(bool tTime1) { m_bUseTime1 = tTime1; } + const TDateTime& GetDateTime1() const { return m_tDateTime1; } + void SetDateTime1(const TDateTime& tDateTime1) { m_tDateTime1 = tDateTime1; } - const ATL::CTime& GetTime1() const { return m_tTime1; } - void SetTime1(const ATL::CTime& val) { m_tTime1 = val; } + // date 2 + bool GetUseDateTime2() const { return m_bUseDateTime2; } + void SetUseDateTime2(bool bUseDateTime2) { m_bUseDateTime2 = bUseDateTime2; } - // date 2 - bool GetUseDateTime2() const { return m_bUseDateTime2; } - void SetUseDateTime2(bool bUseDateTime2) { m_bUseDateTime2 = bUseDateTime2; } + CFileFilter::EDateCompareType GetDateCmpType2() const { return m_eDateCmpType2; } + void SetDateCmpType2(CFileFilter::EDateCompareType eCmpType2) { m_eDateCmpType2 = eCmpType2; } - CFileFilter::EDateCompareType GetDateCmpType2() const { return m_eDateCmpType2; } - void SetDateCmpType2(CFileFilter::EDateCompareType eCmpType2) { m_eDateCmpType2 = eCmpType2; } + bool GetUseDate2() const { return m_bUseDate2; } + void SetUseDate2(bool tDate2) { m_bUseDate2 = tDate2; } - bool GetUseDate2() const { return m_bUseDate2; } - void SetUseDate2(bool tDate2) { m_bUseDate2 = tDate2; } + bool GetUseTime2() const { return m_bUseTime2; } + void SetUseTime2(bool tTime2) { m_bUseTime2 = tTime2; } - const ATL::CTime& GetDate2() const { return m_tDate2; } - void SetDate2(const ATL::CTime& tDate2) { m_tDate2 = tDate2; } + const TDateTime& GetDateTime2() const { return m_tDateTime2; } + void SetDateTime2(const TDateTime& tDateTime2) { m_tDateTime2 = tDateTime2; } - bool GetUseTime2() const { return m_bUseTime2; } - void SetUseTime2(bool tTime2) { m_bUseTime2 = tTime2; } + // attributes + bool GetUseAttributes() const { return m_bUseAttributes; } + void SetUseAttributes(bool bUseAttributes) { m_bUseAttributes = bUseAttributes; } - const ATL::CTime& GetTime2() const { return m_tTime2; } - void SetTime2(const ATL::CTime& val) { m_tTime2 = val; } + int GetArchive() const { return m_iArchive; } + void SetArchive(int iArchive) { m_iArchive = iArchive; } - // attributes - bool GetUseAttributes() const { return m_bUseAttributes; } - void SetUseAttributes(bool bUseAttributes) { m_bUseAttributes = bUseAttributes; } + int GetReadOnly() const { return m_iReadOnly; } + void SetReadOnly(int iReadOnly) { m_iReadOnly = iReadOnly; } - int GetArchive() const { return m_iArchive; } - void SetArchive(int iArchive) { m_iArchive = iArchive; } + int GetHidden() const { return m_iHidden; } + void SetHidden(int iHidden) { m_iHidden = iHidden; } - int GetReadOnly() const { return m_iReadOnly; } - void SetReadOnly(int iReadOnly) { m_iReadOnly = iReadOnly; } + int GetSystem() const { return m_iSystem; } + void SetSystem(int iSystem) { m_iSystem = iSystem; } - int GetHidden() const { return m_iHidden; } - void SetHidden(int iHidden) { m_iHidden = iHidden; } + int GetDirectory() const { return m_iDirectory; } + void SetDirectory(int iDirectory) { m_iDirectory = iDirectory; } - int GetSystem() const { return m_iSystem; } - void SetSystem(int iSystem) { m_iSystem = iSystem; } - - int GetDirectory() const { return m_iDirectory; } - void SetDirectory(int iDirectory) { m_iDirectory = iDirectory; } - protected: bool MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const; bool Scan(LPCTSTR& lpszMask, LPCTSTR& lpszString) const; private: - // files mask - bool m_bUseMask; - chcore::TStringArray m_astrMask; + // files mask + bool m_bUseMask; + chcore::TStringArray m_astrMask; - // files mask- - bool m_bUseExcludeMask; - chcore::TStringArray m_astrExcludeMask; + // files mask- + bool m_bUseExcludeMask; + chcore::TStringArray m_astrExcludeMask; - // size filtering - bool m_bUseSize1; - ESizeCompareType m_eSizeCmpType1; - unsigned long long m_ullSize1; + // size filtering + bool m_bUseSize1; + ESizeCompareType m_eSizeCmpType1; + unsigned long long m_ullSize1; - bool m_bUseSize2; - ESizeCompareType m_eSizeCmpType2; - unsigned long long m_ullSize2; + bool m_bUseSize2; + ESizeCompareType m_eSizeCmpType2; + unsigned long long m_ullSize2; - // date filtering - EDateType m_eDateType; // created/last modified/last accessed + // date filtering + EDateType m_eDateType; // created/last modified/last accessed - bool m_bUseDateTime1; + bool m_bUseDateTime1; #pragma warning(push) #pragma warning(disable: 4251) - EDateCompareType m_eDateCmpType1; // before/after - bool m_bUseDate1; - ATL::CTime m_tDate1; - bool m_bUseTime1; - ATL::CTime m_tTime1; + EDateCompareType m_eDateCmpType1; // before/after + bool m_bUseDate1; + bool m_bUseTime1; + TDateTime m_tDateTime1; - bool m_bUseDateTime2; + bool m_bUseDateTime2; - EDateCompareType m_eDateCmpType2; - bool m_bUseDate2; - ATL::CTime m_tDate2; - bool m_bUseTime2; - ATL::CTime m_tTime2; + EDateCompareType m_eDateCmpType2; + bool m_bUseDate2; + bool m_bUseTime2; + TDateTime m_tDateTime2; #pragma warning(pop) - // attribute filtering - bool m_bUseAttributes; - int m_iArchive; - int m_iReadOnly; - int m_iHidden; - int m_iSystem; - int m_iDirectory; + // attribute filtering + bool m_bUseAttributes; + int m_iArchive; + int m_iReadOnly; + int m_iHidden; + int m_iSystem; + int m_iDirectory; }; class LIBCHCORE_API CFiltersArray Index: src/libchcore/FileInfo.h =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/libchcore/FileInfo.h (.../FileInfo.h) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/libchcore/FileInfo.h (.../FileInfo.h) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -140,7 +140,7 @@ void Serialize(chcore::TWriteBinarySerializer& rSerializer, bool bOnlyFlags) const; protected: - const chcore::TPathContainer& m_rBasePaths; + const chcore::TPathContainer& m_rBasePaths; #pragma warning(push) #pragma warning(disable: 4251) Index: src/libchcore/SerializationHelpers.h =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/libchcore/SerializationHelpers.h (.../SerializationHelpers.h) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/libchcore/SerializationHelpers.h (.../SerializationHelpers.h) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -101,23 +101,6 @@ SerializerType::StoreValue(rSerializer, tValue); } -#ifdef _ATL_VER - template<> - inline void Serialize(TReadBinarySerializer& rSerializer, ATL::CTime& tValue) - { - long long llTime = 0; - Serialize(rSerializer, llTime); - tValue = ATL::CTime(llTime); - } - - template<> - inline void Serialize(TWriteBinarySerializer& rSerializer, const ATL::CTime& tValue) - { - long long llTime = tValue.GetTime(); - Serialize(rSerializer, llTime); - } -#endif - #ifdef _MFC_VER template<> inline void Serialize(TReadBinarySerializer& rSerializer, CString& tValue) @@ -133,22 +116,6 @@ Serialize(rSerializer, (PCTSTR)tValue); } -/* - template<> - inline void Serialize(TReadBinarySerializer& rSerializer, CTime& tValue) - { - long long llTime = 0; - Serialize(rSerializer, llTime); - tValue = CTime(llTime); - } - - template<> - inline void Serialize(TWriteBinarySerializer& rSerializer, const CTime& tValue) - { - long long llTime = tValue.GetTime(); - Serialize(rSerializer, llTime); - } -*/ #endif } Index: src/libchcore/TDateTime.cpp =================================================================== diff -u --- src/libchcore/TDateTime.cpp (revision 0) +++ src/libchcore/TDateTime.cpp (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -0,0 +1,229 @@ +// ============================================================================ +// Copyright (C) 2001-2011 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +/// @file TDateTime.cpp +/// @date 2011/10/26 +/// @brief Contains implementation of date&time handling class. +// ============================================================================ +#include "stdafx.h" +#include "TDateTime.h" +#include "SerializationHelpers.h" +#include "TBinarySerializer.h" + +BEGIN_CHCORE_NAMESPACE + +TDateTime::TDateTime() : + m_tTime(0) +{ +} + +TDateTime::TDateTime(int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond) +{ + if(iYear < 1900) + THROW_CORE_EXCEPTION(eErr_InvalidArgument); + + tm tTime; + + tTime.tm_sec = iSecond; + tTime.tm_min = iMinute; + tTime.tm_hour = iHour; + tTime.tm_mday = iDay; + tTime.tm_mon = iMonth - 1; + tTime.tm_year = iYear - 1900; + tTime.tm_isdst = -1; + + m_tTime = _mktime64(&tTime); + if(m_tTime == -1) + THROW_CORE_EXCEPTION_WIN32(eErr_InvalidArgument, GetLastError()); +} + +TDateTime::TDateTime(FILETIME ftDateTime) +{ + operator=(ftDateTime); +} + +TDateTime::TDateTime(SYSTEMTIME sysDateTime) +{ + operator=(sysDateTime); +} + +TDateTime::TDateTime(time_t tDateTime) : + m_tTime(tDateTime) +{ +} + +TDateTime& TDateTime::operator=(FILETIME ftDateTime) +{ + // convert and process as system time + FILETIME tLocalFileTime; + if(!FileTimeToLocalFileTime(&ftDateTime, &tLocalFileTime)) + THROW_CORE_EXCEPTION_WIN32(eErr_InvalidArgument, GetLastError()); + + SYSTEMTIME sysTime; + if(!FileTimeToSystemTime(&tLocalFileTime, &sysTime)) + THROW_CORE_EXCEPTION_WIN32(eErr_InvalidArgument, GetLastError()); + + return operator=(sysTime); +} + +TDateTime& TDateTime::operator=(SYSTEMTIME sysDateTime) +{ + if(sysDateTime.wYear < 1900) + THROW_CORE_EXCEPTION(eErr_InvalidArgument); + + tm tTime; + + tTime.tm_sec = sysDateTime.wSecond; + tTime.tm_min = sysDateTime.wMinute; + tTime.tm_hour = sysDateTime.wHour; + tTime.tm_mday = sysDateTime.wDay; + tTime.tm_mon = sysDateTime.wMonth - 1; + tTime.tm_year = sysDateTime.wYear - 1900; + tTime.tm_isdst = -1; + + m_tTime = _mktime64(&tTime); + if(m_tTime == -1) + THROW_CORE_EXCEPTION_WIN32(eErr_InvalidArgument, GetLastError()); + + return *this; +} + +TDateTime& TDateTime::operator=(time_t tDateTime) +{ + m_tTime = tDateTime; + return *this; +} + +void TDateTime::Clear() +{ + m_tTime = 0; +} + +void TDateTime::SetCurrentDateTime() +{ + m_tTime = _time64(NULL); +} + +void TDateTime::GetAsSystemTime(SYSTEMTIME& tSystemTime) const +{ + tm tThisTimeInfo; + errno_t err = _localtime64_s(&tThisTimeInfo, &m_tTime); + if(err != 0) + THROW_CORE_EXCEPTION(eErr_InvalidData); + + tSystemTime.wYear = (WORD)(tThisTimeInfo.tm_year + 1900); + tSystemTime.wMonth = (WORD)(tThisTimeInfo.tm_mon + 1); + tSystemTime.wDayOfWeek = (WORD)tThisTimeInfo.tm_wday; + tSystemTime.wDay = (WORD)tThisTimeInfo.tm_mday; + tSystemTime.wHour = (WORD)tThisTimeInfo.tm_hour; + tSystemTime.wMinute = (WORD)tThisTimeInfo.tm_min; + tSystemTime.wSecond = (WORD)tThisTimeInfo.tm_sec; + tSystemTime.wMilliseconds = 0; +} + +TString TDateTime::Format(bool bUseDate, bool bUseTime) const +{ + if(!bUseDate && !bUseTime) + return TString(); + + TString strTmp; + const size_t stMaxBufSize = 1024; + wchar_t* pszBuffer = strTmp.GetBuffer(stMaxBufSize); + + PCTSTR pszFmt = NULL; + if(bUseDate && bUseTime) + pszFmt = _T("%x %X"); + else if(bUseDate) + pszFmt = _T("%x"); + else if(bUseTime) + pszFmt = _T("%X"); + + tm tThisTimeInfo; + errno_t err = _localtime64_s(&tThisTimeInfo, &m_tTime); + if(err != 0) + THROW_CORE_EXCEPTION(eErr_InvalidData); + + if(!_tcsftime(pszBuffer, stMaxBufSize, pszFmt, &tThisTimeInfo)) + THROW_CORE_EXCEPTION(eErr_InvalidData); + + strTmp.ReleaseBuffer(); + return strTmp; +} + +time_t TDateTime::Compare(const TDateTime& rOtherDateTime, bool bCompareDate, bool bCompareTime) const +{ + if(!bCompareDate && !bCompareTime) + return 0; + + tm tThisTimeInfo; + tm tOtherTimeInfo; + errno_t err = _localtime64_s(&tThisTimeInfo, &m_tTime); + if(err != 0) + THROW_CORE_EXCEPTION(eErr_InvalidData); + err = _localtime64_s(&tOtherTimeInfo, &rOtherDateTime.m_tTime); + if(err != 0) + THROW_CORE_EXCEPTION(eErr_InvalidData); + if(tThisTimeInfo.tm_isdst != tOtherTimeInfo.tm_isdst) + THROW_CORE_EXCEPTION(eErr_InternalProblem); + + time_t tDiffDateTime = 0; + if(bCompareDate) + { + time_t tThisCompoundDate = (tThisTimeInfo.tm_year - 1900) * 32140800 + tThisTimeInfo.tm_mon * 2678400 + tThisTimeInfo.tm_mday * 86400; + time_t tOtherCompoundDate = (tOtherTimeInfo.tm_year - 1900) * 32140800 + tOtherTimeInfo.tm_mon * 2678400 + tOtherTimeInfo.tm_mday * 86400; + + // <0 means that this date is less than other date, 0 means they are equal, >0 means that other date is less than this date + tDiffDateTime = tOtherCompoundDate - tThisCompoundDate; + + // at this point we can return only if this date differs from other date; if they are equal, process time comparison if needed + if(tDiffDateTime != 0) + return tDiffDateTime; + } + + if(bCompareTime) + { + time_t tThisCompoundTime = tThisTimeInfo.tm_hour * 3600 + tThisTimeInfo.tm_min * 60 + tThisTimeInfo.tm_sec; + time_t tOtherCompoundTime = tOtherTimeInfo.tm_hour * 3600 + tOtherTimeInfo.tm_min * 60 + tOtherTimeInfo.tm_sec; + + tDiffDateTime = tOtherCompoundTime - tThisCompoundTime; + } + + return tDiffDateTime; +} + +void TDateTime::StoreInConfig(chcore::TConfig& rConfig, PCTSTR pszNodeName) const +{ + rConfig.SetValue(pszNodeName, m_tTime); +} + +bool TDateTime::ReadFromConfig(const chcore::TConfig& rConfig, PCTSTR pszNodeName) +{ + return rConfig.GetValue(pszNodeName, m_tTime); +} + +void TDateTime::Serialize(chcore::TReadBinarySerializer& rSerializer) +{ + Serializers::Serialize(rSerializer, m_tTime); +} + +void TDateTime::Serialize(chcore::TWriteBinarySerializer& rSerializer) const +{ + Serializers::Serialize(rSerializer, m_tTime); +} + +END_CHCORE_NAMESPACE Index: src/libchcore/TDateTime.h =================================================================== diff -u --- src/libchcore/TDateTime.h (revision 0) +++ src/libchcore/TDateTime.h (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -0,0 +1,74 @@ +// ============================================================================ +// Copyright (C) 2001-2011 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +/// @file TDateTime.h +/// @date 2011/10/26 +/// @brief Contains declaration of date&time handling class. +// ============================================================================ +#ifndef __TDATETIME_H__ +#define __TDATETIME_H__ + +#include "libchcore.h" +#include "TConfig.h" + +BEGIN_CHCORE_NAMESPACE + +class TConfig; +class TReadBinarySerializer; +class TWriteBinarySerializer; + +class LIBCHCORE_API TDateTime +{ +public: + TDateTime(); + TDateTime(int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond); + TDateTime(FILETIME ftDateTime); + TDateTime(SYSTEMTIME sysDateTime); + TDateTime(time_t tDateTime); + + TDateTime& operator=(FILETIME ftDateTime); + TDateTime& operator=(SYSTEMTIME sysDateTime); + TDateTime& operator=(time_t tDateTime); + + // content modification + void Clear(); + void SetCurrentDateTime(); + + // content extraction + void GetAsSystemTime(SYSTEMTIME& tSystemTime) const; + TString Format(bool bUseDate, bool bUseTime) const; + + // comparison + time_t Compare(const TDateTime& rOtherDateTime, bool bCompareDate, bool bCompareTime) const; + + // serialization + void StoreInConfig(chcore::TConfig& rConfig, PCTSTR pszNodeName) const; + bool ReadFromConfig(const chcore::TConfig& rConfig, PCTSTR pszNodeName); + + void Serialize(chcore::TReadBinarySerializer& rSerializer); + void Serialize(chcore::TWriteBinarySerializer& rSerializer) const; + +private: + time_t m_tTime; +}; + +END_CHCORE_NAMESPACE + +CONFIG_MEMBER_SERIALIZATION(TDateTime) + +#endif Index: src/libchcore/libchcore.vc90.vcproj =================================================================== diff -u -rd12e49decb8a3df3e28f6786d38542390484ac07 -rf46d334ffd78c7daa7626f214ae698adbac5f36d --- src/libchcore/libchcore.vc90.vcproj (.../libchcore.vc90.vcproj) (revision d12e49decb8a3df3e28f6786d38542390484ac07) +++ src/libchcore/libchcore.vc90.vcproj (.../libchcore.vc90.vcproj) (revision f46d334ffd78c7daa7626f214ae698adbac5f36d) @@ -412,6 +412,14 @@ > + + + +