00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __TOOLBOX_DIRECTORY_H
00010 #define __TOOLBOX_DIRECTORY_H
00011
00012
00016 #define DU_FREADDONLY 0x01
00017
00021 #define DU_FHIDDEN 0x02
00022
00026 #define DU_FSYSTEM 0x04
00027
00031 #define DU_FDIRECTORY 0x10
00032
00036 #define DU_FARCHIVE 0x20
00037
00042 #define DU_FALLFLAGS 0x3F
00043
00048 #define DU_FNOFLAGS 0x00
00049
00053 #define DU_INVALID -1
00054
00055
00056 namespace toolbox
00057 {
00066 class Directory
00067 {
00068 private:
00069
00073 ContainingList<DirectoryEntry> * Entries;
00074
00075 #ifdef _TOOLBOX_TEST
00076
00079 static int InstanceCount;
00080 #endif
00081
00096 void ReadFromInternal(Path * RootWithFilter,
00097 int requiredAttributes, int forbiddenAttributes, bool recurse);
00098
00099 public:
00100
00104 Directory();
00105
00109 ~Directory();
00110
00115 inline void AppendEntry(DirectoryEntry * Entry);
00116
00120 inline void DeleteAll();
00121
00127 inline bool DeleteEntry(long nr);
00128
00134 inline bool DeleteEntry(DirectoryEntry * Entry);
00135
00140 inline bool DeleteFirstEntry();
00141
00146 inline bool DeleteLastEntry();
00147
00153 inline DirectoryEntry * GetEntry(long nr);
00154
00159 inline int GetEntryCount();
00160
00165 inline DirectoryEntry * GetFirstEntry();
00166
00171 inline DirectoryEntry * GetLastEntry();
00172
00180 inline void InsertEntry(DirectoryEntry * Entry, long nr);
00181
00185 inline bool IsEmpty();
00186
00191 inline void PrependEntry(DirectoryEntry * Entry);
00192
00209 void ReadFrom(const char * rootWithFilter,
00210 int requiredAttributes, int forbiddenAttributes, bool recurse);
00211
00228 void ReadFrom(const char * root, const char * filter,
00229 int requiredAttributes, int forbiddenAttributes, bool recurse);
00230
00247 void ReadFrom(Path * RootWithFilter,
00248 int requiredAttributes, int forbiddenAttributes, bool recurse);
00249
00266 void ReadFrom(Path * Root, const char * filter,
00267 int requiredAttributes, int forbiddenAttributes, bool recurse);
00268
00275 inline DirectoryEntry * UnlinkEntry(long nr);
00276
00283 inline DirectoryEntry * UnlinkEntry(DirectoryEntry * Entry);
00284
00290 inline DirectoryEntry * UnlinkFirstEntry();
00291
00297 inline DirectoryEntry * UnlinkLastEntry();
00298
00299 #ifdef _TOOLBOX_TEST
00300
00306 static void RunTestSuite(int * performedTests, int * failedTests);
00307 #endif
00308 };
00309
00310
00317 class DirectoryEntry : public ContainingListItem<DirectoryEntry>
00318 {
00319 friend Directory;
00320
00321 private:
00322
00326 struct tm AccessTime;
00327
00331 struct tm CreateTime;
00332
00336 bool ExistsFlag;
00337
00341 long Flags;
00342
00343 #ifdef _TOOLBOX_TEST
00344
00347 static int InstanceCount;
00348 #endif
00349
00353 struct tm ModifyTime;
00354
00358 class Path * Path;
00359
00363 unsigned long Size;
00364
00368 DirectoryEntry();
00369
00375 void Invalidate();
00376
00384 static void InvalidateTime(struct tm * time);
00385
00386 public:
00387
00394 DirectoryEntry(class Path * Path);
00395
00402 DirectoryEntry(const char * path);
00403
00407 ~DirectoryEntry();
00408
00415 DirectoryEntry * Clone();
00416
00422 inline bool Exists();
00423
00428 long GetAccessTime();
00429
00434 inline int GetAccessTimeSecond();
00435
00440 inline int GetAccessTimeMinute();
00441
00446 inline int GetAccessTimeHour();
00447
00452 inline int GetAccessTimeDay();
00453
00458 inline int GetAccessTimeMonth();
00459
00464 inline int GetAccessTimeYear();
00465
00470 long GetCreateTime();
00471
00476 inline int GetCreateTimeSecond();
00477
00482 inline int GetCreateTimeMinute();
00483
00488 inline int GetCreateTimeHour();
00489
00494 inline int GetCreateTimeDay();
00495
00500 inline int GetCreateTimeMonth();
00501
00506 inline int GetCreateTimeYear();
00507
00512 inline long GetFlags();
00513
00518 long GetModifyTime();
00519
00524 inline int GetModifyTimeSecond();
00525
00530 inline int GetModifyTimeMinute();
00531
00536 inline int GetModifyTimeHour();
00537
00542 inline int GetModifyTimeDay();
00543
00548 inline int GetModifyTimeMonth();
00549
00554 inline int GetModifyTimeYear();
00555
00560 inline class DirectoryEntry * GetNextEntry();
00561
00566 inline class Path * GetPath();
00567
00572 inline class DirectoryEntry * GetPrevEntry();
00573
00578 inline unsigned long GetSize();
00579
00584 void Refresh();
00585
00586 #ifdef _TOOLBOX_TEST
00587
00593 static void RunTestSuite(int * performedTests, int * failedTests);
00594 #endif
00595 };
00596
00597
00604 class Path
00605 {
00606 private:
00607
00611 ContainingList<PathElement> * Elements;
00612
00613 #ifdef _TOOLBOX_TEST
00614
00617 static int InstanceCount;
00618 #endif
00619
00624 char * Root;
00625
00626 public:
00627
00631 Path();
00632
00638 Path(const char * path);
00639
00643 ~Path();
00644
00650 inline void AppendElement(const char * elementName);
00651
00657 inline void AppendElement(PathElement * Element);
00658
00664 void AppendPath(const char * path);
00665
00672 void AppendPath(class Path * Path);
00673
00680 Path * Clone();
00681
00689 bool Contains(const char * path);
00690
00698 bool Contains(class Path * Path);
00699
00706 static Path * CreateApplicationFolderPath();
00707
00714 static Path * CreateApplicationPath();
00715
00738 Path * CreateRelativePathTo(const char * path);
00739
00762 class Path * CreateRelativePathTo(class Path * Path);
00763
00775 class Path * CreateTargetPath(const char * path);
00776
00788 class Path * CreateTargetPath(class Path * Path);
00789
00794 inline void DeleteAll();
00795
00802 inline bool DeleteElement(long nr);
00803
00810 inline bool DeleteElement(PathElement * Element);
00811
00817 inline bool DeleteFirstElement();
00818
00824 inline bool DeleteLastElement();
00825
00831 bool Exists();
00832
00838 inline PathElement * GetElement(long nr);
00839
00844 inline int GetElementCount();
00845
00850 inline PathElement * GetFirstElement();
00851
00856 inline PathElement * GetLastElement();
00857
00863 inline char * GetRoot();
00864
00871 inline void InsertElement(const char * elementName, long nr);
00872
00879 inline void InsertElement(PathElement * Element, long nr);
00880
00885 inline bool IsAbsolute();
00886
00891 inline bool IsEmpty();
00892
00897 inline bool IsRelative();
00898
00903 bool MakeDirectory();
00904
00910 inline void PrependElement(const char * elementName);
00911
00917 inline void PrependElement(PathElement * Element);
00918
00924 void PrependPath(const char * path);
00925
00932 void PrependPath(class Path * Path);
00933
00934 #ifdef _TOOLBOX_TEST
00935
00941 static void RunTestSuite(int * performedTests, int * failedTests);
00942 #endif
00943
00949 void SetRoot(const char * root);
00950
00959 inline char * ToString();
00960
00969 char * ToString(bool trailingSlash);
00970
00977 inline PathElement * UnlinkElement(long nr);
00978
00985 inline PathElement * UnlinkElement(PathElement * Element);
00986
00992 inline PathElement * UnlinkFirstElement();
00993
00999 inline PathElement * UnlinkLastElement();
01000 };
01001
01002
01008 class PathElement : public ContainingListItem<PathElement>
01009 {
01010 private:
01011
01012 #ifdef _TOOLBOX_TEST
01013
01016 static int InstanceCount;
01017 #endif
01018
01022 char * Name;
01023
01024 public:
01025
01029 PathElement();
01030
01036 PathElement(const char * Name);
01037
01041 ~PathElement();
01042
01048 bool ChangeExtension(const char * newExtension);
01049
01056 PathElement * Clone();
01057
01062 inline char * GetName();
01063
01068 inline class PathElement * GetNextElement();
01069
01074 inline class PathElement * GetPrevElement();
01075
01076 #ifdef _TOOLBOX_TEST
01077
01083 static void RunTestSuite(int * performedTests, int * failedTests);
01084 #endif
01085
01092 void SetName(const char * name);
01093 };
01094 }
01095
01096
01097 #endif