Files
core/Common/cfcpp/directoryentry.h
Elena.Subbotina f5f2a38c7e .
2022-10-27 10:27:58 +03:00

140 lines
6.0 KiB
C++

/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "svector.h"
#include "idirectoryentry.h"
namespace CFCPP
{
class DirectoryEntry : public IDirectoryEntry
{
public:
static const int THIS_IS_GREATER = 1;
static const int OTHER_IS_GREATER = -1;
static const int NOSTREAM = 0xFFFFFFFF;
static const int ZERO = 0;
DirectoryEntry(std::wstring name, StgType stgType, SVector<IDirectoryEntry>& dirRepository);
DirectoryEntry(std::wstring name, StgType stgType);
RedBlackTree::PIRBNode getLeft() const override;
RedBlackTree::PIRBNode getRight() const override;
void setLeft(RedBlackTree::PIRBNode pNode) override;
void setRight(RedBlackTree::PIRBNode pNode) override;
std::streamsize getSize() const override {return size;}
void setSize(std::streamsize value) override {size = value;}
int getStateBits() const override {return stateBits;}
void setStateBits(int value) override {stateBits = value;}
inline void setColor(RedBlackTree::Color clr) override {stgColor = (StgColor)clr;}
inline RedBlackTree::Color getColor()const override {return (RedBlackTree::Color)stgColor;}
void setParent(RedBlackTree::PIRBNode pParent) override {parent = pParent;}
inline RedBlackTree::PIRBNode getParent() const override {return parent.lock();}
inline RedBlackTree::PIRBNode Grandparent() const override
{return (parent.use_count() ? parent.lock()->getParent() : RedBlackTree::PIRBNode());}
RedBlackTree::PIRBNode Sibling() const override; // check parent before using
RedBlackTree::PIRBNode Uncle() const override;
void AssignValueTo(RedBlackTree::PIRBNode other) override;
int CompareTo(const RedBlackTree::PIRBNode& other) const override;
std::wstring ToString() const override;
inline int getChild() const override {return child;}
inline void setChild(int value) override {child = value;}
inline int getLeftSibling() const override {return leftSibling;}
inline void setLeftSibling(int value) override {leftSibling = value;}
inline int getRightSibling() const override {return rightSibling;}
inline void setRightSibling(int value) override {rightSibling = value;}
inline UINT64 getCreationDate() const override {return creationDate;}
inline void setCreationDate(const UINT64& value) override {creationDate = value;}
inline UINT64 getModifyDate() const override {return modifyDate;}
inline void setModifyDate(const UINT64& value) override {modifyDate = value;}
int getSid() const override;
void setSid(int newSid) override;
std::wstring GetEntryName() const override;
void SetEntryName(const std::wstring &entryName) override;
inline unsigned short getNameLength() const override {return nameLength;}
void setStartSetc(int value) override {startSetc = value;};
int getStartSetc() const override {return startSetc;};
void Read(Stream stream, CFSVersion ver = CFSVersion::Ver_3) override;
void Write(Stream stream) const override;
inline StgColor getStgColor() const override {return stgColor;}
inline void setStgColor(StgColor value) override {stgColor = value;}
inline StgType getStgType() const override {return stgType;}
inline void setStgType(StgType value) override {stgType = value;}
inline GUID getStorageCLSID() const override {return storageCLSID;}
inline void setStorageCLSID(GUID value) override {storageCLSID = value;}
int GetHashCode() const override;
inline std::wstring Name() const {return GetEntryName();}
public:
UINT64 creationDate = 0;
UINT64 modifyDate = 0;
int startSetc = 0xFFFFFFFE;
LONG64 size = 0;
int leftSibling = NOSTREAM;
int rightSibling = NOSTREAM;
int child = NOSTREAM;
int stateBits = 0;
static std::shared_ptr<IDirectoryEntry> New(std::wstring name, StgType stgType, SVector<IDirectoryEntry>& dirRepository);
static std::shared_ptr<IDirectoryEntry> TryNew(std::wstring name, StgType stgType, SVector<IDirectoryEntry> &dirRepository);
static std::shared_ptr<IDirectoryEntry> Mock(std::wstring name, StgType stgType);
private:
static ULONG64 fnv_hash(const char *buffer, int lenght);
private:
int sid = -1;
char entryName[64] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned short nameLength = 0;
StgType stgType = StgType::StgInvalid;
StgColor stgColor = StgColor::Red;
SVector<IDirectoryEntry> emptyDir;
SVector<IDirectoryEntry>& dirRepository;
std::weak_ptr<RedBlackTree::IRBNode> parent;
GUID storageCLSID;
};
}