-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscandir.h
236 lines (187 loc) · 6.95 KB
/
scandir.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* Copyright (c) Microsoft Corporation. All Rights Reserved.
*/
#ifndef __SCANDIR_H__
#define __SCANDIR_H__
/*
*
* scandir
*
*
* scan a directory tree and build a sorted list of filenames within that
* tree.
*
* the dir_buildlist function will scan the directories and files
* and return DIRLIST handle.
*
* calls to dir_firstitem and dir_nextitem will traverse the files in the
* listing in alphabetic order, returning a DIRITEM handle. This handle
* can be queried for the associated filename, filesize and checksum.
*
* calls to dir_firstitem and dir_nextitem will only show files, not
* directories, and will traverse the list in alphabetic order
* within a directory, and contents of subdirectories in
* alphabetic order within a directory. Within one directory, we traverse the
* files before listing the contents of the subdirectories.
*
* if the bSum argument is true, we checksum each readable file during the
* initial scan. If this is false, we will checksum the file on demand (during
* the first call to dir_getchecksum). if the file is not readable, the
* checksum will be 0.
*
*/
/* handle to the list of files scanned */
typedef struct dirlist FAR * DIRLIST;
/* handle to one item within the list of files */
typedef struct diritem FAR * DIRITEM;
/*
* scan the given directory for files, and return NULL if unsuccessful,
* or a DIRLIST handle to the items if successful. If bSums is true,
* checksum each file found.
*
* if pathname is not a directory, we return NULL. if it is a directory, but
* contains no files, we return a valid handle to an empty list.
*
* If bOnDemand is TRUE, the list will scanned as necessary to fulfil
* dir_firstitem/dir_nextitem requests. If this is false, the
* list will be fully built before the dir_buildlist function returns.
*/
DIRLIST dir_buildlist(LPSTR pathname, BOOL bSum, BOOL bOnDemand);
void dir_setotherdirlist(DIRLIST dl, DIRLIST otherdl);
/*
* build/append a directory list.
*
* If bSums is true, checksum each file found.
*
* if pathname is not a directory, we add it to the list.
* if it is a directory, it gets ignored.
*/
BOOL dir_appendlist(DIRLIST *pdl, LPCSTR pathname, BOOL bSum, int *psequence);
/* call this to delete this list, all the items in it and all the
* associated memory
*/
void dir_delete(DIRLIST list);
/* was this list built from a filename or a directory ? This function
* will return TRUE if the initial argument to the dir_buildlist()
* function.
*/
BOOL dir_isfile(DIRLIST list);
/* return the first file in the list in alphabetic order. will return
* null if no files found
*/
DIRITEM dir_firstitem(DIRLIST list);
/* return the next file in the list in alphabetic order, or null if no
* more files
*/
DIRITEM dir_nextitem(DIRLIST list, DIRITEM previtem, BOOL fDeep);
/*
* Return a handle to the DIRLIST given a handle to the DIRITEM within it.
*
*/
DIRLIST dir_getlist(DIRITEM item);
// get the name of this file, relative to the DIRLIST root.
LPSTR dir_getrelname(DIRITEM item);
// get the absolute path to the dirlist root directory
LPSTR dir_getrootpath(DIRLIST dl);
// get a description text for this dirlist
LPSTR dir_getrootdescription(DIRLIST dl);
// set custom description (instead of using calculated one)
void dir_setdescription(DIRLIST dl, LPCSTR psz);
/* free memory created by a previous call to dir_getrelname */
void dir_freerelname(DIRITEM item, LPSTR relname);
/* free memory possibly created by a call to dir_getroot_* */
void dir_freerootpath(DIRLIST dl, LPSTR rootname);
void dir_freerootdescription(DIRLIST dl, LPSTR rootname);
/*
* get an open-able name for the file. This will be the same as the fullname.
*/
LPSTR dir_getopenname(DIRITEM item);
/*
* free up memory created by a call to dir_getopenname(). This *may*
* cause the file to be deleted if it was a temporary copy.
*/
void dir_freeopenname(DIRITEM item, LPSTR openname);
/*
* open the file and return a read-only handle to it.
* close file using dir_closefile
*/
HANDLE dir_openfile(DIRITEM item);
/*
* close a file opened by dir_openfile. This *may* cause the file to be
* deleted if it was a temporary local copy
*/
void dir_closefile(DIRITEM item, HANDLE fh);
/* return a checksum for this file. If one has not yet been calculated
* for this file, open the file and calculate it.
* if the file was unreadable, this returns 0.
*/
DWORD dir_getchecksum(DIRITEM item);
/* Redo everything to do with checksums, size, etc */
void dir_rescanfile(DIRITEM di);
/* return a TRUE iff item has a valid checksum */
BOOL dir_validchecksum(DIRITEM item);
// return false if there is some error accessing this file
BOOL dir_fileerror(DIRITEM item);
/* return the (lower 32 bits) of the file size, as scanned at the
* call to dir_buildlist
*/
long dir_getfilesize(DIRITEM item);
/* return the file attributes, as scanned at the call to dir_buildlist
*/
DWORD dir_getattr(DIRITEM item);
/* MUST CALL dir_startcopy first and dir_endcopy after.
* create a copy of the file, in the new root directory. creates sub-dirs as
* necessary.
*
* returns TRUE for success and FALSE for failure.
*/
BOOL dir_copy(DIRITEM item, LPSTR newroot, BOOL HitReadOnly, BOOL IgnoreAttributes);
/* Call this before starting copying */
BOOL dir_startcopy(DIRLIST dl);
/* call this after copying. Negative retcode = number of bad files
else retcode = number of file copied (all good).
*/
int dir_endcopy(DIRLIST dl);
/* Build the real path from item and newroot into newpath.
* Create directories as needed so that it is valid.
*/
BOOL dir_MakeValidPath(LPSTR newpath, DIRITEM item, LPSTR newroot);
/*
* useful routine exported for other users
* returns TRUE if path is a valid directory
*/
BOOL dir_isvaliddir(LPCSTR path);
/*
* returns TRUE if the DIRLIST parameter has a wildcard specified
*/
BOOL dir_iswildcard(DIRLIST);
/*
* compares two relnames that are both based on wildcard DIRLISTs. if the
* directories match, then the filenames are compared after removing
* the fixed portion of the name - thus comparing only the
* wildcard portion.
*/
int dir_compwildcard(DIRLIST dleft, DIRLIST dright, LPSTR lname, LPSTR rname);
/*
* compares two DIRITEMs, based on a sequence number rather than filenames.
*/
BOOL dir_compsequencenumber(DIRITEM dleft, DIRITEM dright, int *pcmpvalue);
#ifndef WIN32
/* FILETIME structure from WIN32 */
typedef struct _FILETIME { /* ft */
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;
#define CONST const
long CompareFileTime( CONST FILETIME * lpft1, /* address of first file time */
CONST FILETIME * lpft2 /* address of second file time */
);
#endif
/* return the file time (last write time) (set during scanning), (0,0) if invalid */
FILETIME dir_GetFileTime(DIRITEM cur);
#endif