Index: src/libchcore/TFileInfo.cpp =================================================================== diff -u -N -ra7834ba278464cb62739f22d35f9bc16269706a1 -ra5aa3c3cb78f3767641de2627d1a49a1dc35b429 --- src/libchcore/TFileInfo.cpp (.../TFileInfo.cpp) (revision a7834ba278464cb62739f22d35f9bc16269706a1) +++ src/libchcore/TFileInfo.cpp (.../TFileInfo.cpp) (revision a5aa3c3cb78f3767641de2627d1a49a1dc35b429) @@ -20,11 +20,11 @@ // Almost everything has changed since then. #include "stdafx.h" #include "TFileInfo.h" -#include "TBinarySerializer.h" -#include "SerializationHelpers.h" #include "TCoreException.h" #include "ErrorCodes.h" -#include "TModPathContainer.h" +#include "TRowData.h" +#include "ISerializerRowData.h" +#include "ISerializerContainer.h" BEGIN_CHCORE_NAMESPACE @@ -33,14 +33,17 @@ ////////////////////////////////////////////////////////////////////// TFileInfo::TFileInfo() : - m_pathFile(), - m_dwAttributes(0), - m_uhFileSize(0), - m_uiFlags(0) + m_pathFile(m_setModifications), + m_spBasePathData(m_setModifications), + m_dwAttributes(m_setModifications, 0), + m_uhFileSize(m_setModifications, 0), + m_ftCreation(m_setModifications), + m_ftLastAccess(m_setModifications), + m_ftLastWrite(m_setModifications), + m_uiFlags(m_setModifications, 0), + m_stObjectID(0) { - m_ftCreation.dwHighDateTime = m_ftCreation.dwLowDateTime = 0; - m_ftLastAccess.dwHighDateTime = m_ftLastAccess.dwLowDateTime = 0; - m_ftLastWrite.dwHighDateTime = m_ftLastWrite.dwLowDateTime = 0; + m_setModifications[eMod_Added] = true; } TFileInfo::TFileInfo(const TFileInfo& rSrc) : @@ -51,14 +54,33 @@ m_ftCreation(rSrc.m_ftCreation), m_ftLastAccess(rSrc.m_ftLastAccess), m_ftLastWrite(rSrc.m_ftLastWrite), - m_uiFlags(rSrc.m_uiFlags) + m_uiFlags(rSrc.m_uiFlags), + m_stObjectID(rSrc.m_stObjectID) { } TFileInfo::~TFileInfo() { } +TFileInfo& TFileInfo::operator=(const TFileInfo& rSrc) +{ + if(this != & rSrc) + { + m_pathFile = rSrc.m_pathFile; + m_spBasePathData = rSrc.m_spBasePathData; + m_dwAttributes = rSrc.m_dwAttributes; + m_uhFileSize = rSrc.m_uhFileSize; + m_ftCreation = rSrc.m_ftCreation; + m_ftLastAccess = rSrc.m_ftLastAccess; + m_ftLastWrite = rSrc.m_ftLastWrite; + m_uiFlags = rSrc.m_uiFlags; + m_stObjectID = rSrc.m_stObjectID; + } + + return *this; +} + void TFileInfo::Init(const TBasePathDataPtr& spBasePathData, const TSmartPath& rpathFile, DWORD dwAttributes, ULONGLONG uhFileSize, FILETIME ftCreation, FILETIME ftLastAccess, FILETIME ftLastWrite, uint_t uiFlags) @@ -72,15 +94,15 @@ m_ftLastWrite = ftLastWrite; m_uiFlags = uiFlags; - if(m_spBasePathData) - m_pathFile.MakeRelativePath(m_spBasePathData->GetSrcPath()); + if(m_spBasePathData.Get()) + m_pathFile.Modify().MakeRelativePath(m_spBasePathData.Get()->GetSrcPath()); } void TFileInfo::Init(const TSmartPath& rpathFile, DWORD dwAttributes, ULONGLONG uhFileSize, FILETIME ftCreation, FILETIME ftLastAccess, FILETIME ftLastWrite, uint_t uiFlags) { m_pathFile = rpathFile; - m_spBasePathData.reset(); + m_spBasePathData.Modify().reset(); m_dwAttributes = dwAttributes; m_uhFileSize = uhFileSize; m_ftCreation = ftCreation; @@ -92,25 +114,27 @@ void TFileInfo::SetParentObject(const TBasePathDataPtr& spBasePathData) { // cannot set parent object if there is already one specified - if(m_spBasePathData) + if(m_spBasePathData.Get()) THROW_CORE_EXCEPTION(eErr_InvalidArgument); m_spBasePathData = spBasePathData; - if(m_spBasePathData) - m_pathFile.MakeRelativePath(m_spBasePathData->GetSrcPath()); + if(m_spBasePathData.Get()) + m_pathFile.Modify().MakeRelativePath(m_spBasePathData.Get()->GetSrcPath()); } -bool TFileInfo::operator==(const TFileInfo& rInfo) +bool TFileInfo::operator==(const TFileInfo& rInfo) const { - return (rInfo.m_dwAttributes == m_dwAttributes && rInfo.m_ftCreation.dwHighDateTime == m_ftCreation.dwHighDateTime && rInfo.m_ftCreation.dwLowDateTime == m_ftCreation.dwLowDateTime - && rInfo.m_ftLastWrite.dwHighDateTime == m_ftLastWrite.dwHighDateTime && rInfo.m_ftLastWrite.dwLowDateTime == m_ftLastWrite.dwLowDateTime && rInfo.m_uhFileSize == m_uhFileSize); + return (rInfo.m_dwAttributes == m_dwAttributes && + rInfo.m_ftCreation.Get() == m_ftCreation.Get() && + rInfo.m_ftLastWrite.Get() == m_ftLastWrite.Get() && + rInfo.m_uhFileSize == m_uhFileSize); } TSmartPath TFileInfo::GetFullFilePath() const { - if(m_spBasePathData) + if(m_spBasePathData.Get()) { - TSmartPath pathCombined = m_spBasePathData->GetSrcPath(); + TSmartPath pathCombined = m_spBasePathData.Get()->GetSrcPath(); pathCombined += m_pathFile; return pathCombined; } @@ -120,8 +144,8 @@ size_t TFileInfo::GetSrcObjectID() const { - if(m_spBasePathData) - return m_spBasePathData->GetObjectID(); + if(m_spBasePathData.Get()) + return m_spBasePathData.Get()->GetObjectID(); return std::numeric_limits::max(); } @@ -130,4 +154,168 @@ return m_spBasePathData; } +void TFileInfo::MarkAsProcessed(bool bProcessed) +{ + if(bProcessed) + m_uiFlags.Modify() |= eFlag_Processed; + else + m_uiFlags.Modify() &= ~eFlag_Processed; +} + +bool TFileInfo::IsProcessed() const +{ + return m_uiFlags & eFlag_Processed; +} + +ULONGLONG TFileInfo::GetLength64() const +{ + return m_uhFileSize; +} + +void TFileInfo::SetLength64(ULONGLONG uhSize) +{ + m_uhFileSize=uhSize; +} + +const TSmartPath& TFileInfo::GetFilePath() const +{ + return m_pathFile; +} + +void TFileInfo::SetFilePath(const TSmartPath& tPath) +{ + m_pathFile = tPath; +} + +const TFileTime& TFileInfo::GetCreationTime() const +{ + return m_ftCreation; +} + +const TFileTime& TFileInfo::GetLastAccessTime() const +{ + return m_ftLastAccess; +} + +const TFileTime& TFileInfo::GetLastWriteTime() const +{ + return m_ftLastWrite; +} + +DWORD TFileInfo::GetAttributes() const +{ + return m_dwAttributes; +} + +bool TFileInfo::IsDirectory() const +{ + return (m_dwAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; +} + +bool TFileInfo::IsArchived() const +{ + return (m_dwAttributes & FILE_ATTRIBUTE_ARCHIVE) != 0; +} + +bool TFileInfo::IsReadOnly() const +{ + return (m_dwAttributes & FILE_ATTRIBUTE_READONLY) != 0; +} + +bool TFileInfo::IsCompressed() const +{ + return (m_dwAttributes & FILE_ATTRIBUTE_COMPRESSED) != 0; +} + +bool TFileInfo::IsSystem() const +{ + return (m_dwAttributes & FILE_ATTRIBUTE_SYSTEM) != 0; +} + +bool TFileInfo::IsHidden() const +{ + return (m_dwAttributes & FILE_ATTRIBUTE_HIDDEN) != 0; +} + +bool TFileInfo::IsTemporary() const +{ + return (m_dwAttributes & FILE_ATTRIBUTE_TEMPORARY) != 0; +} + +bool TFileInfo::IsNormal() const +{ + return m_dwAttributes == 0; +} + +void TFileInfo::Store(const ISerializerContainerPtr& spContainer) const +{ + ISerializerRowDataPtr spRow; + if(m_setModifications[eMod_Added]) + spRow = spContainer->AddRow(m_stObjectID); + else if(m_setModifications.any()) + spRow = spContainer->GetRow(m_stObjectID); + else + return; + + if(m_setModifications[eMod_Path]) + *spRow % TRowData(_T("rel_path"), m_pathFile); + if(m_setModifications[eMod_BasePath]) + *spRow % TRowData(_T("base_path_id"), m_spBasePathData.Get()->GetObjectID()); + if(m_setModifications[eMod_Attributes]) + *spRow % TRowData(_T("attr"), m_dwAttributes); + if(m_setModifications[eMod_FileSize]) + *spRow % TRowData(_T("size"), m_uhFileSize); + if(m_setModifications[eMod_TimeCreated]) + *spRow % TRowData(_T("time_created"), m_ftCreation.Get().ToUInt64()); + if(m_setModifications[eMod_TimeLastWrite]) + *spRow % TRowData(_T("time_last_write"), m_ftLastWrite.Get().ToUInt64()); + if(m_setModifications[eMod_TimeLastAccess]) + *spRow % TRowData(_T("time_last_access"), m_ftLastAccess.Get().ToUInt64()); + if(m_setModifications[eMod_Flags]) + *spRow % TRowData(_T("flags"), m_uiFlags); + + m_setModifications.reset(); +} + +void TFileInfo::InitLoader(const IColumnsDefinitionPtr& spColumns) +{ + *spColumns % _T("id") % _T("rel_path") % _T("base_path_id") % _T("attr") % _T("size") % _T("time_created") % _T("time_last_write") % _T("time_last_access") % _T("flags"); +} + +void TFileInfo::Load(const ISerializerRowReaderPtr& spRowReader, const TBasePathDataContainerPtr& spSrcContainer) +{ + size_t stBaseObjectID = 0; + unsigned long long ullTime = 0; + spRowReader->GetValue(_T("id"), m_stObjectID); + spRowReader->GetValue(_T("rel_path"), m_pathFile.Modify()); + spRowReader->GetValue(_T("base_path_id"), stBaseObjectID); + spRowReader->GetValue(_T("attr"), m_dwAttributes.Modify()); + spRowReader->GetValue(_T("size"), m_uhFileSize.Modify()); + + spRowReader->GetValue(_T("time_created"), ullTime); + m_ftCreation.Modify().FromUInt64(ullTime); + + spRowReader->GetValue(_T("time_last_write"), ullTime); + m_ftLastWrite.Modify().FromUInt64(ullTime); + + spRowReader->GetValue(_T("time_last_access"), ullTime); + m_ftLastAccess.Modify().FromUInt64(ullTime); + + spRowReader->GetValue(_T("flags"), m_uiFlags.Modify()); + + m_spBasePathData = spSrcContainer->FindByID(stBaseObjectID); + + m_setModifications.reset(); +} + +size_t TFileInfo::GetObjectID() const +{ + return m_stObjectID; +} + +void TFileInfo::SetObjectID(size_t stObjectID) +{ + m_stObjectID = stObjectID; +} + END_CHCORE_NAMESPACE