Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cManifestDir.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cManifestDir_h
7 #define _INC_cManifestDir_h
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../Hash/cCRC.h"
20 
21 namespace GrayLib
22 {
23  class cManifestRoot;
24  class cManifestBuilder;
25 
27  {
33 
34  public:
39  // TODO Secure Hash Code. More collision proof hash than CRC
40 
41  public:
43  cManifestElemData(const cFileStatus& rStatus, CRC32_t nCRC32 = 0);
45 
46  void InitData(FILEATTR_MASK_t Attributes = FILEATTR_None);
47  void InitDataS(const cFileStatus& rStatus);
48 
49  bool IsAttrMask(FILEATTR_MASK_t dwAttrMask) const noexcept
50  {
51  return((m_Attributes&dwAttrMask) ? true : false);
52  }
53  bool isAttrDir() const noexcept
54  {
56  return IsAttrMask(FILEATTR_Directory);
57  }
58  bool isAttrHidden() const noexcept
59  {
62  return IsAttrMask(FILEATTR_Hidden);
63  }
64 
65  bool IsEqual(const cManifestElemData& Test) const;
66  bool IsSameFileDataS(const cFileStatus& status) const;
67  bool IsSameFileData(const cManifestElemData& Test) const;
68  };
69 
71  : public cRefBase
72  {
77 
78  public:
81 
82  public:
83  cManifestElem(const cManifestElem& rCopy);
84  cManifestElem(cStringF sFileName, const cManifestElemData& rData);
85  virtual ~cManifestElem();
86 
87  static HRESULT GRAYCALL ParseLine(IniChar_t* pszLine, OUT cStringF& sFileName, OUT cManifestElemData& data);
88 
89  virtual cStringF get_Name() const noexcept
90  {
91  return m_sFileName;
92  }
93  };
95 
97  {
102 
103  public:
105  {
107 #define cManifestDirProp(a,b,c) MANTAG_##a,
108 #include "cManifestDirProps.tbl"
109 #undef cManifestDirProp
110  MANTAG_QTY
111  };
112  static const IniChar_t* k_ManTags[MANTAG_QTY + 1];
113  static const IniChar_t* k_pszSectionName;
115 
116  protected:
119 
120  protected:
121  HRESULT BuildManifestElem(cManifestBuilder& root, const cManifestDir* pManifestOld, cFileFindEntry& FileEntry);
122  HRESULT BuildManifestMerge(cManifestBuilder& root, const cManifestDir* pManifestOld, FILEATTR_MASK_t dwAttributes);
123 
124  public:
125  cManifestDir(cStringF sDirFullPath);
126  cManifestDir(const cManifestRoot& root);
127  virtual ~cManifestDir();
128 
129  const FILECHAR_t* get_Name() const
130  {
131  return cFilePath::GetFileName(m_sDirPath);
132  }
133  cStringF get_DirPath() const noexcept
134  {
135  return m_sDirPath;
136  }
138  {
139  return m_ManData;
140  }
142  {
143  return m_ManData.m_CRC32;
144  }
145  bool HasChild(const cManifestDir& rManChild) const;
146 
148  HRESULT ReadManifestFile(cStringF sFullManifestPath);
149  HRESULT ReadManifestFile(const cManifestRoot& root, const FILECHAR_t* pszManifestName = nullptr);
150  HRESULT ReadSearchForTitle(const cManifestRoot& root, cStringF& sPathRet, const FILECHAR_t* pszTitle, int iDescendLevels);
151 
152  HRESULT WriteManifestSection(cStreamOutput& file);
153  HRESULT WriteManifestFile(const cManifestRoot& root);
154  HRESULT BuildManifest(cManifestBuilder& root, FILEATTR_MASK_t dwAttributes = FILEATTR_Directory);
155 
156  cStringF makeFilePath(const FILECHAR_t* pszFileName) const
157  {
159  return cFilePath::CombineFilePathX(m_sDirPath, pszFileName);
160  }
161 
162  ITERATE_t addManifestElem(cManifestElem* pData);
163  bool rebuildManifestData();
164  };
165 
167  {
171 
172  public:
175 
176  protected:
178 
179  public:
180  cManifestRoot(cStringF sRootDir, const FILECHAR_t* pszManifestFileName = nullptr);
181  ~cManifestRoot();
182 
184  {
186  return m_sRootDir;
187  }
188  void put_RootDir(cStringF sRootDir)
189  {
190  m_sRootDir = sRootDir;
191  }
192 
193  bool isRootDir(const FILECHAR_t* pszDirPath) const
194  {
195  return !m_sRootDir.CompareNoCase(pszDirPath);
196  }
197  bool isInRootPath(const FILECHAR_t* pszDirPath) const
198  {
199  return cFilePath::IsRelativeRoot(pszDirPath, get_RootDir());
200  }
201  cStringF makeFullPath(const FILECHAR_t* pszRelativePath) const
202  {
203  return cFilePath::CombineFilePathX(get_RootDir(), pszRelativePath);
204  }
205  cStringF makeRelativePath(const FILECHAR_t* pszDirPath) const
206  {
208  return cFilePath::MakeRelativePath(pszDirPath, get_RootDir());
209  }
210 
211  HRESULT ReadSearchForTitle(cStringF& sPathRet, const FILECHAR_t* pszTitle, int iDescendLevels) const;
212  };
213 
215  {
218 
219  public:
220  // callbacks for progress
223 
224  public:
225  cManifestContext(cStringF sDirRoot, const FILECHAR_t* pszManifestFileName = nullptr, cLogProcessor* pLog = nullptr, IStreamProgressCallback* pProgress = nullptr);
226  ~cManifestContext();
227 
229  {
231  if (m_pProgress == nullptr) // ignore this.
232  return S_OK;
233  return m_pProgress->onProgressCallback(s);
234  }
235  };
236 
238  {
243 
244  friend class cManifestDir;
245 
246  public:
248 
249  bool m_bTrustCRC;
252 
253  protected:
255 
256  protected:
257  bool isTrustedDir(const FILECHAR_t* pszDirPath) const;
258 
260  virtual HRESULT onFilePrep(cManifestDir* pManLocal, cFileFindEntry& FileEntry, cManifestElem* pElementOld); // callback when file is about to be checked.
261  virtual HRESULT onDirComplete(cManifestDir* pManLocal, HRESULT hRes); // callback when dir manifest is verified/computed.
262  virtual HRESULT onChangeManifest(cManifestDir* pManLocal, const FILECHAR_t* pszElemName);
263 
264  public:
266  virtual ~cManifestBuilder();
267 
268  HRESULT DoBuildManifest(const FILECHAR_t* pszRelativePath = nullptr);
269 
271  };
272 }
273 
274 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
Using X files without the sources and the makefile How to use you just create a debug directory e the sample3 directory must contain Sample3 Final Sample3 exe Sample3 Final Debug Sample3 Final Gfx OpenGL bmp Sample3 Final Gfx tiny_skin bmp Sample3 Final Gfx tiny_4anim x The source files have the DevCpp project file plus the makefile The demos use standard FreeGlut functions Technical without warranty Neither Paul Coppens nor GameDev net make any or either express or with respect to the their or fitness for a specific purpose neither Paul Coppens nor GameDev net shall have any liability to you or any other person or entity with respect to any or damage caused or alleged to have been caused directly or indirectly by the programs provided by Paul Coppens and GameDev net This but is not limited interruption of loss of data
Definition: Readme.txt:39
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
static const CRC32_t k_nStart
Default starting value for CRC.
Definition: cCRC.h:31
Definition: cManifestDir.h:238
cStreamProgressF m_ManProgress
How far into processing the full tree are we?
Definition: cManifestDir.h:254
cArraySortString< FILECHAR_t > * m_pChangeList
Don't trust these paths. Assume they have changed. nullptr = descend all directories.
Definition: cManifestDir.h:250
bool m_bTrustCRC
trust manifest CRC if file matches by date & size. so don't bother recalculating CRC....
Definition: cManifestDir.h:249
cManifestContext & m_Context
Config info regarding my root and preferences.
Definition: cManifestDir.h:247
UNITTEST_FRIEND(cManifestDir)
int m_iChanges
Count changes for the last DoBuildManifest.
Definition: cManifestDir.h:251
Definition: cManifestDir.h:215
HRESULT UpdateProgress(const cStreamProgress &s)
Definition: cManifestDir.h:228
cLogProcessor * m_pLog
Route status messages to this logger.
Definition: cManifestDir.h:221
IStreamProgressCallback * m_pProgress
Send progress info to some outside party on the action(s) we are taking.
Definition: cManifestDir.h:222
Definition: cManifestDir.h:97
cManifestElemData & ref_ElemData()
Definition: cManifestDir.h:137
cManifestElemData m_ManData
represents all files in this directory.
Definition: cManifestDir.h:118
MANTAG_TYPE
Definition: cManifestDir.h:105
cStringF makeFilePath(const FILECHAR_t *pszFileName) const
Definition: cManifestDir.h:156
static const IniChar_t * k_pszSectionName
"Package"
Definition: cManifestDir.h:113
CRC32_t get_ManCRC32() const
Definition: cManifestDir.h:141
const FILECHAR_t * get_Name() const
Definition: cManifestDir.h:129
cArraySortName< cManifestElem > m_aElems
Name sorted list.
Definition: cManifestDir.h:114
cStringF get_DirPath() const noexcept
Definition: cManifestDir.h:133
const cStringF m_sDirPath
Full (local) Dir path. Does NOT include the wild card. Not relative to cManifestRoot.
Definition: cManifestDir.h:117
Definition: cManifestDir.h:27
cTimeInt m_timeChange
m_mtime = real world time/date of last modification. (UTC)(FAT32 only accurate to 2 sec)
Definition: cManifestDir.h:37
bool isAttrDir() const noexcept
Definition: cManifestDir.h:53
bool IsAttrMask(FILEATTR_MASK_t dwAttrMask) const noexcept
Definition: cManifestDir.h:49
FILE_SIZE_t m_Size
file size in bytes.
Definition: cManifestDir.h:36
bool isAttrHidden() const noexcept
Definition: cManifestDir.h:58
FILEATTR_MASK_t m_Attributes
Mask of FILEATTR_MASK_t attribute bits. FILEATTR_Hidden, FILEATTR_Directory?
Definition: cManifestDir.h:35
CRC32_t m_CRC32
32 bit CRC for the file or directory of files. NOTE: is there a trick to get this from the OS?...
Definition: cManifestDir.h:38
Definition: cManifestDir.h:72
cManifestElemData m_ElemData
details about this element.
Definition: cManifestDir.h:80
virtual cStringF get_Name() const noexcept
Definition: cManifestDir.h:89
cStringF m_sFileName
File title (no path info) for this element.
Definition: cManifestDir.h:79
Definition: cManifestDir.h:167
cStringF makeRelativePath(const FILECHAR_t *pszDirPath) const
Definition: cManifestDir.h:205
static const FILECHAR_t * k_pszManifestDefault
"Manifest.scp"
Definition: cManifestDir.h:173
const FILECHAR_t * m_pszManifestFileName
"Manifest.scp" // name of the local manifest files. (one per dir)
Definition: cManifestDir.h:174
cStringF get_RootDir() const
Definition: cManifestDir.h:183
cStringF m_sRootDir
full path to the (local system) root directory we are syncing or building manifests for.
Definition: cManifestDir.h:177
bool isRootDir(const FILECHAR_t *pszDirPath) const
Definition: cManifestDir.h:193
cStringF makeFullPath(const FILECHAR_t *pszRelativePath) const
Definition: cManifestDir.h:201
bool isInRootPath(const FILECHAR_t *pszDirPath) const
Definition: cManifestDir.h:197
void put_RootDir(cStringF sRootDir)
Definition: cManifestDir.h:188
COMPARE_t CompareNoCase(const _TYPE_CH *pszStr) const
Definition: cString.h:269
Definition: cArraySortRef.h:199
Definition: cFileDir.h:86
static FILECHAR_t *__stdcall GetFileName(const FILECHAR_t *pszPath, StrLen_t iLenPath=k_StrLen_UNK)
Definition: cFilePath.cpp:342
static cStringF __stdcall MakeRelativePath(const FILECHAR_t *pszFullPath, const FILECHAR_t *pszRootDir)
Definition: cFilePath.cpp:659
static bool __stdcall IsRelativeRoot(const FILECHAR_t *pszFullPath, const FILECHAR_t *pszRootDir, StrLen_t iLen=k_StrLen_UNK)
Definition: cFilePath.cpp:630
static cStringF __stdcall CombineFilePathX(const FILECHAR_t *pszBase, const FILECHAR_t *pszName, FILECHAR_t chSep=k_DirSep)
Definition: cFilePath.cpp:596
Definition: cFileStatus.h:58
Definition: cLogAppender.h:168
Definition: cRefPtr.h:22
Definition: cRefPtr.h:225
Definition: cStream.h:126
Definition: cStreamProgress.h:71
< similar to the MFC CTime and cTimeSpan, not as accurate or large ranged as COleDateTime
Definition: cTimeInt.h:101
static const TIMESEC_t k_nZero
January 1, 1970 UTC.
Definition: cTimeInt.h:111
Definition: cMesh.h:22
cRefPtr< cManifestElem > cManifestElemPtr
Definition: cManifestDir.h:94
UINT32 CRC32_t
32 bit CRC
Definition: cCRC.h:19
@ FILEATTR_Hidden
FILE_ATTRIBUTE_HIDDEN. linux starts with .
Definition: cFileStatus.h:40
@ FILEATTR_None
Definition: cFileStatus.h:38
@ FILEATTR_Directory
FILE_ATTRIBUTE_DIRECTORY.
Definition: cFileStatus.h:45
int ITERATE_t
like size_t but signed
Definition: Index.h:28
char IniChar_t
char format even on UNICODE system! Screw M$, INI files should ALWAYS have UTF8 contents
Definition: cIniBase.h:17
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
UINT32 FILEATTR_MASK_t
Definition: cFileStatus.h:55
UINT64 FILE_SIZE_t
similar to STREAM_POS_t size_t
Definition: cFileStatus.h:31
Definition: cStreamProgress.h:168
virtual HRESULT _stdcall onProgressCallback(const cStreamProgress &progress)
Definition: cStreamProgress.h:176