-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dir.h
210 lines (131 loc) · 5.31 KB
/
Dir.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#ifndef DIR_H
#define DIR_H
/** @file */
#include "StdList.h"
#include "StdTime.h"
#if defined(__unix__)
#include <dirent.h>
#endif /* __unix__ */
/** File sorting possibilities for files returned by RDir::read() */
enum TDirSortOrder
{
EDirSortNone, /**< No sorting */
EDirSortNameAscending, /**< Sort alphabetically in ascending order */
EDirSortNameDescending, /**< Sort alphabetically in descending order */
EDirSortSizeAscending, /**< Sort from smallest to largest */
EDirSortSizeDescending, /**< Sort from largest to smallest */
EDirSortDateAscending, /**< Sort from oldest to newest */
EDirSortDateDescending /**< Sort from newest to oldest */
};
/* An instance of this class represents a directory or filename and its associated */
/* attributes, such as name etc. It is filled in by the RDir class */
class TEntry
{
public:
StdListNode<TEntry> m_oStdListNode; /**< Standard list node */
char iName[MAX_PATH]; /**< Name of the file */
char iLink[MAX_PATH]; /**< Resolved link to the file, if it is a link. Note: This field is only
filled out by Utils::GetFileInfo(), not by methods in RDir */
TBool iIsDir; /**< ETrue if entry is a directory */
TBool iIsLink; /**< ETrue if entry is a link */
TInt64 iSize; /**< File size in bytes */
TUint iAttributes; /**< Protection attributes, in Amiga/UNIX/Windows format */
TTime iModified; /**< Time and date of the file */
#ifdef __amigaos__
struct DateStamp iPlatformDate; /**< Date and time in Amiga specific format */
#elif defined(__unix__)
time_t iPlatformDate; /**< Date and time in UNIX specific format */
#else /* ! __unix__ */
FILETIME iPlatformDate; /**< Date and time in Windows specific format */
#endif /* ! __unix__ */
public:
TEntry();
TEntry(const TDateTime &a_roDateTime);
void ClearArchive();
TBool IsDir() const;
TBool IsLink() const;
TBool IsHidden() const;
TBool IsReadable() const;
TBool IsWriteable() const;
TBool IsExecutable() const;
TBool IsDeleteable() const;
void Reset();
void Set(TBool a_bIsDir, TBool a_bIsLink, TInt64 a_iSize, TUint a_uiAttributes, const TDateTime &a_oDateTime);
};
/* An instance of this class represents a number of TEntry classes and is filled */
/* in by the RDir class */
class TEntryArray
{
private:
StdList<TEntry> iEntries; /**< List of entries */
public:
/* Note that having a destructor in T classes is non standard, but this is required */
/* to free the iEntries array, and this class is really private to RDir anyway */
~TEntryArray();
TEntry *Append(const char *a_pccName);
static TInt CompareEntries(const TEntry *a_poFirst, const TEntry *a_poSecond, void *a_pvUserData);
TInt Count() const;
const TEntry &operator[](TInt a_iIndex) const;
const TEntry *getHead() const;
const TEntry *getSucc(const TEntry *a_poEntry) const;
void Purge();
void remove(const TEntry *a_poEntry);
void Sort(enum TDirSortOrder a_eSortOrder);
};
/**
* Interface for all directory scanning classes.
* This pure virtual base class defines the interface that all directory scanning classes will adhere to. Instances
* of these classes can either be used directly, or obtained from RRemoteFactory::getDirObject().
*/
class RDirObject
{
protected:
TEntryArray m_entries; /**< Array of TEntry classes containing directory and file information */
public:
virtual TInt open(const char *a_pattern) = 0;
virtual void close()
{
/* Free the contents of the TEntry array in case the RDir class is reused */
m_entries.Purge();
}
virtual TInt read(TEntryArray *&a_entries, enum TDirSortOrder a_sortOrder = EDirSortNone) = 0;
};
/**
* A class for scanning directories for local directory and file entries.
* Instances of this class can be used to scan for file information on the local file system.
*/
class RDir : public RDirObject
{
private:
#ifdef __amigaos__
char *iPath; /**< Path to directory being scanned, minus wildcard */
char *iPattern; /**< Pattern to be used for MatchPatternNoCase() */
#ifdef __amigaos4__
APTR iContext; /**< Context used for scanning directory */
#else /* ! __amigaos4__ */
BPTR iLock; /**< Lock on the directory currently being scanned */
ExAllControl *iContext; /**< Control structure used for scanning directory */
ExAllData *iCurrent; /**< Pointer to the file currently being processed */
ExAllData *iExAllData; /**< Buffer used for all file data structures */
#endif /* ! __amigaos4__ */
#elif defined(__unix__)
char *iPathBuffer; /**< Ptr to memory used by iPath and iPattern buffers */
char *iPath; /**< Path to directory being scanned, minus wildcard */
char *iPattern; /**< Pattern to be used for pattern matching in RDir::read() */
DIR *iDir; /**< Pointer to object used for scanning directory */
#else /* ! __unix__ */
HANDLE iHandle; /**< Handle used for scanning directory */
#endif /* ! __unix__ */
TEntry iSingleEntry; /**< If a single entry is being examined, open() will populate this */
TBool iSingleEntryOk; /**< ETrue if the contents of iSingleEntry are valid, else EFalse */
private:
#ifdef WIN32
TInt AppendDirectoryEntry(WIN32_FIND_DATA *a_poFindData);
#endif /* WIN32 */
public:
RDir();
TInt open(const char *a_pccPattern);
void close();
TInt read(TEntryArray *&a_rpoEntries, enum TDirSortOrder a_eSortOrder = EDirSortNone);
};
#endif /* ! DIR_H */