Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

476 lines
14 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. fileenum.h
  5. Abstract:
  6. Declares interface for callback-based file enumeration. The
  7. file enumerator has several capabilities, such as directory-
  8. first or directory-last enumeration, enumeration depth limiting,
  9. suppression of files or directories, and a global hook ability.
  10. This is *OLD CODE* changed significantly by MikeCo. And because
  11. of the callback interface, it is overly complex.
  12. ** Do not use these routines in new Win9x upgrade code.
  13. Instead, see file.h for much better routines.
  14. There is one handy routine in here: DeleteDirectoryContents
  15. Author:
  16. Jim Schmidt (jimschm) 03-Dec-1996
  17. Revision History:
  18. mikeco ??-???-1997 Ran code through train_wreck.exe
  19. --*/
  20. #ifndef _FILEENUM_H
  21. #define _FILEENUM_H
  22. //
  23. // Callback typedef -> return FALSE if enumeration should stop
  24. //
  25. typedef INT (CALLBACK * FILEENUMPROCA)(LPCSTR szFullFileSpec,
  26. LPCSTR szDestFileSpec,
  27. WIN32_FIND_DATAA *pFindData,
  28. DWORD EnumTreeID,
  29. LPVOID pParam,
  30. PDWORD CurrentDirData
  31. );
  32. typedef INT (CALLBACK * FILEENUMPROCW)(LPCWSTR szFullFileSpec,
  33. LPCWSTR szDestFileSpec,
  34. WIN32_FIND_DATAW *pFindData,
  35. DWORD EnumTreeID,
  36. LPVOID pParam,
  37. PDWORD CurrentDirData
  38. );
  39. //
  40. // Failure-reporting callbacks -- sink the names of paths that
  41. // fail for reasons of length or code-page incompatibility
  42. //
  43. typedef VOID (CALLBACK * FILEENUMFAILPROCA) (LPCSTR szFailPath);
  44. typedef VOID (CALLBACK * FILEENUMFAILPROCW) (LPCWSTR szFailPath);
  45. //
  46. // CopyTree flags. If neither COPYTREE_DOCOPY or COPYTREE_DOMOVE is
  47. // passed in, the CopyTree functions will just enumerate.
  48. //
  49. #define COPYTREE_DOCOPY 0x0001
  50. #define COPYTREE_NOOVERWRITE 0x0002
  51. #define COPYTREE_DOMOVE 0x0004
  52. #define COPYTREE_DODELETE 0x0008
  53. #define COPYTREE_IGNORE_ERRORS 0x0010
  54. //
  55. // Level flags
  56. //
  57. #define ENUM_ALL_LEVELS 0
  58. #define ENUM_THIS_DIRECTORY 1
  59. #define ENUM_MAX_LEVELS MAX_PATH
  60. //
  61. // Filter flags
  62. //
  63. #define FILTER_DIRECTORIES 0x0001
  64. #define FILTER_FILES 0x0002
  65. #define FILTER_DIRS_LAST 0x0004
  66. #define FILTER_ALL (FILTER_DIRECTORIES|FILTER_FILES)
  67. #define FILTER_ALL_DIRS_LAST (FILTER_DIRECTORIES|FILTER_FILES|FILTER_DIRS_LAST)
  68. //
  69. // Callback return values
  70. //
  71. #define CALLBACK_DO_NOT_RECURSE_THIS_DIRECTORY (-3)
  72. #define CALLBACK_FAILED (-2)
  73. #define CALLBACK_SUBDIR_DONE (-1)
  74. #define CALLBACK_CONTINUE (0)
  75. #define CALLBACK_THIS_LEVEL_ONLY (1)
  76. //
  77. // CopyTree parameter block
  78. //
  79. #include <pshpack1.h>
  80. typedef struct COPYTREE_PARAMS_STRUCTA
  81. {
  82. LPCSTR szEnumRootInWack; // Root of source tree
  83. LPCSTR szEnumRootOutWack; // Root of target tree
  84. CHAR szFullFileSpecOut[MAX_MBCHAR_PATH]; // Proposed target filespec (callback may change)
  85. int nCharsInRootInWack;
  86. int nCharsInRootOutWack;
  87. DWORD flags;
  88. FILEENUMPROCA pfnCallback;
  89. } COPYTREE_PARAMSA, *PCOPYTREE_PARAMSA;
  90. typedef struct COPYTREE_PARAMS_STRUCTW
  91. {
  92. LPCWSTR szEnumRootInWack;
  93. LPCWSTR szEnumRootOutWack;
  94. WCHAR szFullFileSpecOut[MAX_WCHAR_PATH * 2];
  95. int nCharsInRootInWack;
  96. int nCharsInRootOutWack;
  97. DWORD flags;
  98. FILEENUMPROCW pfnCallback;
  99. } COPYTREE_PARAMSW, *PCOPYTREE_PARAMSW;
  100. #include <poppack.h>
  101. //
  102. // Exported functions from FILEENUM.DLL
  103. //
  104. //
  105. // EnumerateAllDrives first builds an exclusion list if an exclusion INF path
  106. // is provided, and then enumerates every file on every drive that is not
  107. // excluded. The callback function is called once per file. The pParam
  108. // parameter is passed to the callback.
  109. //
  110. // fnEnumCallback - A pointer to your callback function
  111. // EnumTreeID - A value used to identify the exclusion list
  112. // (see GenerateEnumID)
  113. // pParam - LPVOID passed to callback function
  114. // szExclusionInfPath - Path to INF file containing exclusions
  115. // szPathSection - A string that identifies the path exclusion
  116. // section in the INF.
  117. // szFileSection - A string that identifies the file exclusion
  118. // section in the INF.
  119. //
  120. typedef struct {
  121. LPCSTR ExclusionInfPath;
  122. LPCSTR PathSection;
  123. LPCSTR FileSection;
  124. } EXCLUDEINFA, *PEXCLUDEINFA;
  125. typedef struct {
  126. LPCWSTR ExclusionInfPath;
  127. LPCWSTR PathSection;
  128. LPCWSTR FileSection;
  129. } EXCLUDEINFW, *PEXCLUDEINFW;
  130. BOOL
  131. EnumerateAllDrivesA (
  132. IN FILEENUMPROCA fnEnumCallback,
  133. IN FILEENUMFAILPROCA fnFailCallback, OPTIONAL
  134. IN DWORD EnumTreeID,
  135. IN LPVOID pParam,
  136. IN PEXCLUDEINFA ExcludeInfStruct, OPTIONAL
  137. IN DWORD AttributeFilter
  138. );
  139. BOOL
  140. EnumerateAllDrivesW (
  141. IN FILEENUMPROCW fnEnumCallback,
  142. IN FILEENUMFAILPROCW fnFailCallback, OPTIONAL
  143. IN DWORD EnumTreeID,
  144. IN LPVOID pParam,
  145. IN PEXCLUDEINFW ExcludeInfStruct, OPTIONAL
  146. IN DWORD AttributeFilter
  147. );
  148. //
  149. // EnumerateTree is similar to EnumarateAllDrives, except it allows you to
  150. // enumerate a specific drive, or a specific subdir on a drive. Supply the
  151. // drive letter and optional subdirectory in szEnumRoot. Before enumerating,
  152. // EnumerateTree will first build an exclusion list if an exclusion INF path
  153. // is provided. Then every file below szEnumRoot is enumerated, and the
  154. // callback is called once per file, passing pParam unchanged.
  155. //
  156. // szEnumRoot - Drive and optional path to enumerate
  157. // fnEnumCallback - A pointer to your callback function
  158. // fnFailCallback - A pointer to optional callback that logs a path
  159. // that be enumerated due to length or other reason.
  160. // EnumTreeID - A value used to identify the exclusion list
  161. // (see GenerateEnumID)
  162. // pParam - LPVOID passed to callback function
  163. // szExclusionInfPath - Path to INF file containing exclusions
  164. // szPathSection - A string that identifies the path exclusion
  165. // section in the INF.
  166. // szFileSection - A string that identifies the file exclusion
  167. // section in the INF.
  168. //
  169. BOOL
  170. EnumerateTreeA (
  171. IN LPCSTR szEnumRoot,
  172. IN FILEENUMPROCA fnEnumCallback,
  173. IN FILEENUMFAILPROCA fnFailCallback,
  174. IN DWORD EnumTreeID,
  175. IN LPVOID pParam,
  176. IN DWORD Level,
  177. IN PEXCLUDEINFA ExcludeInfStruct, OPTIONAL
  178. IN DWORD AttributeFilter
  179. );
  180. BOOL
  181. EnumerateTreeW (
  182. IN LPCWSTR szEnumRoot,
  183. IN FILEENUMPROCW fnEnumCallback,
  184. IN FILEENUMFAILPROCW fnFailCallback,
  185. IN DWORD EnumTreeID,
  186. IN LPVOID pParam,
  187. IN DWORD Level,
  188. IN PEXCLUDEINFW ExcludeInfStruct, OPTIONAL
  189. IN DWORD AttributeFilter
  190. );
  191. //
  192. // ClearExclusions removes all enumaration exclusions. It is called
  193. // automatically at the end of enumeration when an exclusion INF file is
  194. // used. Use it when you need to programmatically build an exclusion list
  195. // with ExcludePath and ExcludeFile.
  196. //
  197. // You can combine programmatic exclusions with an exclusion INF file, but
  198. // beware that the programmatic exclusions will be cleared after
  199. // EnumarteAllDrives or EnumerateTree completes.
  200. //
  201. // If you do not use an INF, the programmatic exclusions will NOT
  202. // automatically be cleared. This allows you to build exclusions and
  203. // enumerate multiple times without having to rebuild the exclusion
  204. // list.
  205. //
  206. // EnumTreeID - The value that identifies the enumeration exclusion list
  207. // (See GenerateEnumID)
  208. //
  209. void
  210. ClearExclusionsA (DWORD EnumTreeID);
  211. void
  212. ClearExclusionsW (DWORD EnumTreeID);
  213. //
  214. // ExcludePath adds a path name to the exclusion list. There are two
  215. // cases:
  216. //
  217. // 1. If a drive letter is supplied, the exclusion will apply only to
  218. // that drive letter and path. (Path may be only a drive letter,
  219. // colon and backslash to exclude an entire drive.)
  220. // 2. If the path does not begin with a drive letter, it is considered
  221. // relative, and any occurance of the path will be excluded, regardless
  222. // of drive letter and parent directory.
  223. //
  224. // The dot and double-dot directories are not supported. The entire path
  225. // specification may contain wildcard characters. (For example, ?:\ indicates
  226. // any drive letter.)
  227. //
  228. // EnumTreeID - The value that identifies the enumeration exclusion list
  229. // (See GenerateEnumID)
  230. // szPath - The path specification as described above
  231. //
  232. void
  233. ExcludePathA (
  234. IN DWORD EnumTreeID,
  235. IN LPCSTR szPath
  236. );
  237. void
  238. ExcludePathW (
  239. IN DWORD EnumTreeID,
  240. IN LPCWSTR szPath
  241. );
  242. //
  243. // ExcludeFile adds a file name to the exclusion list. There are two
  244. // cases:
  245. //
  246. // 1. If a drive letter is supplied, the exclusion will only apply to that
  247. // drive letter, path and file.
  248. // 2. If the path does not begin with a drive letter, any occurance of the file
  249. // or path/file will be excluded, regardless of drive letter and
  250. // parent directory.
  251. //
  252. // Both the path and file name may contain wildcard characters.
  253. //
  254. // EnumTreeID - The value that identifies the enumeration exclusion list
  255. // (See GenerateEnumID)
  256. // szFile - The file specification as described above
  257. //
  258. void
  259. ExcludeFileA (
  260. IN DWORD EnumTreeID,
  261. IN LPCSTR szFile
  262. );
  263. void
  264. ExcludeFileW (
  265. IN DWORD EnumTreeID,
  266. IN LPCWSTR szFile
  267. );
  268. BOOL
  269. IsPathExcludedA (
  270. DWORD EnumID,
  271. PCSTR Path
  272. );
  273. BOOL
  274. IsPathExcludedW (
  275. DWORD EnumID,
  276. PCWSTR Path
  277. );
  278. //
  279. //
  280. // BuildExclusionsFromInf adds all of the files and paths in the specified exclude.inf into
  281. // the memdb under the specified EnumId.
  282. //
  283. //
  284. BOOL
  285. BuildExclusionsFromInfW (
  286. IN DWORD EnumID,
  287. IN PEXCLUDEINFW ExcludeInfStruct
  288. );
  289. BOOL
  290. BuildExclusionsFromInfA (
  291. IN DWORD EnumID,
  292. IN PEXCLUDEINFA ExcludeInfStruct
  293. );
  294. //
  295. // GenerateEnumID returns a unique DWORD that an application may use to
  296. // build an exclusion list. While use of this function is not technically
  297. // required, it is provided to allow multiple threads to obtain a unique
  298. // value. If one caller uses this function, all callers must as well.
  299. //
  300. DWORD
  301. GenerateEnumID ();
  302. //
  303. // CopyTree enumerates a tree and optionally copies or moves its files
  304. // to another location. The caller is responsible to see that the source
  305. // and target trees are disjoint. (If not, the results could be uncool.)
  306. //
  307. // The callback function can veto a copy or move by returning FALSE,
  308. // or change the target destination by modifying the szFullFileSpecOut
  309. // string in the COPY_PARAMS block, and returning TRUE.
  310. //
  311. BOOL
  312. CopyTreeA(
  313. IN LPCSTR szEnumRootIn,
  314. IN LPCSTR szEnumRootOut,
  315. IN DWORD EnumTreeID,
  316. IN DWORD dwFlags,
  317. IN DWORD Levels,
  318. IN DWORD AttributeFilter,
  319. IN PEXCLUDEINFA ExcludeInfStruct, OPTIONAL
  320. IN FILEENUMPROCA pfnCallback, OPTIONAL
  321. IN FILEENUMFAILPROCA pfnFailCallback OPTIONAL
  322. );
  323. BOOL
  324. CopyTreeW(
  325. IN LPCWSTR szEnumRootIn,
  326. IN LPCWSTR szEnumRootOut,
  327. IN DWORD EnumTreeID,
  328. IN DWORD dwFlags,
  329. IN DWORD Levels,
  330. IN DWORD AttributeFilter,
  331. IN PEXCLUDEINFW ExcludeInfStruct, OPTIONAL
  332. IN FILEENUMPROCW pfnCallback, OPTIONAL
  333. IN FILEENUMFAILPROCW pfnFailCallback OPTIONAL
  334. );
  335. #define DeleteDirectoryContentsA(dir) CopyTreeA(dir,NULL,0,COPYTREE_DODELETE,\
  336. ENUM_ALL_LEVELS,FILTER_ALL_DIRS_LAST,\
  337. NULL,NULL,NULL)
  338. #define DeleteDirectoryContentsW(dir) CopyTreeW(dir,NULL,0,COPYTREE_DODELETE,\
  339. ENUM_ALL_LEVELS,FILTER_ALL_DIRS_LAST,\
  340. NULL,NULL,NULL)
  341. DWORD
  342. GetShellLinkPath(
  343. IN HWND hwnd,
  344. IN LPCTSTR tszLinkFile,
  345. OUT LPTSTR tszPath);
  346. HRESULT
  347. SetShellLinkPath(
  348. IN HWND hwnd,
  349. IN LPCTSTR tszLinkFile,
  350. IN LPCTSTR tszPath);
  351. DWORD
  352. CreateEmptyDirectoryA (
  353. PCSTR Dir
  354. );
  355. DWORD
  356. CreateEmptyDirectoryW (
  357. PCWSTR Dir
  358. );
  359. #ifdef UNICODE
  360. #define EnumerateAllDrives EnumerateAllDrivesW
  361. #define EnumerateTree EnumerateTreeW
  362. #define ExcludePath ExcludePathW
  363. #define ExcludeFile ExcludeFileW
  364. #define BuildExclusionsFromInf BuildExclusionsFromInfW
  365. #define CopyTree CopyTreeW
  366. #define IsPathExcluded IsPathExcludedW
  367. #define ClearExclusions ClearExclusionsW
  368. #define COPYTREE_PARAMS COPYTREE_PARAMSW
  369. #define PCOPYTREE_PARAMS PCOPYTREE_PARAMSW
  370. #define FILEENUMPROC FILEENUMPROCW
  371. #define FILEENUMFAILPROC FILEENUMFAILPROCW
  372. #define EXCLUDEINF EXCLUDEINFW
  373. #define PEXCLUDEINF PEXCLUDEINFW
  374. #define DeleteDirectoryContents DeleteDirectoryContentsW
  375. #define CreateEmptyDirectory CreateEmptyDirectoryW
  376. #else
  377. #define EnumerateAllDrives EnumerateAllDrivesA
  378. #define EnumerateTree EnumerateTreeA
  379. #define ExcludePath ExcludePathA
  380. #define ExcludeFile ExcludeFileA
  381. #define IsPathExcluded IsPathExcludedA
  382. #define BuildExclusionsFromInf BuildExclusionsFromInfA
  383. #define CopyTree CopyTreeA
  384. #define ClearExclusions ClearExclusionsA
  385. #define COPYTREE_PARAMS COPYTREE_PARAMSA
  386. #define PCOPYTREE_PARAMS PCOPYTREE_PARAMSA
  387. #define FILEENUMPROC FILEENUMPROCA
  388. #define FILEENUMFAILPROC FILEENUMFAILPROCA
  389. #define EXCLUDEINF EXCLUDEINFA
  390. #define PEXCLUDEINF PEXCLUDEINFA
  391. #define DeleteDirectoryContents DeleteDirectoryContentsA
  392. #define CreateEmptyDirectory CreateEmptyDirectoryA
  393. #endif
  394. #endif