scantree.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef _RAR_SCANTREE_
  2. #define _RAR_SCANTREE_
  3. enum SCAN_DIRS
  4. {
  5. SCAN_SKIPDIRS, // Skip directories, but recurse for files if recursion mode is enabled.
  6. SCAN_GETDIRS, // Get subdirectories in recurse mode.
  7. SCAN_GETDIRSTWICE, // Get the directory name both before and after the list of files it contains.
  8. SCAN_GETCURDIRS // Get subdirectories in current directory even in RECURSE_NONE mode.
  9. };
  10. enum SCAN_CODE { SCAN_SUCCESS,SCAN_DONE,SCAN_ERROR,SCAN_NEXT };
  11. #define MAXSCANDEPTH (NM/2)
  12. class CommandData;
  13. class ScanTree
  14. {
  15. private:
  16. bool ExpandFolderMask();
  17. bool GetFilteredMask();
  18. bool GetNextMask();
  19. SCAN_CODE FindProc(FindData *FD);
  20. void ScanError(bool &Error);
  21. FindFile *FindStack[MAXSCANDEPTH];
  22. int Depth;
  23. int SetAllMaskDepth;
  24. StringList *FileMasks;
  25. RECURSE_MODE Recurse;
  26. bool GetLinks;
  27. SCAN_DIRS GetDirs;
  28. int Errors;
  29. // Set when processing paths like c:\ (root directory without wildcards).
  30. bool ScanEntireDisk;
  31. wchar CurMask[NM];
  32. wchar OrigCurMask[NM];
  33. // Store all folder masks generated from folder wildcard mask in non-recursive mode.
  34. StringList ExpandedFolderList;
  35. // Store a filter string for folder wildcard in recursive mode.
  36. StringList FilterList;
  37. // Save the list of unreadable dirs here.
  38. StringList *ErrDirList;
  39. Array<uint> *ErrDirSpecPathLength;
  40. // Set if processing a folder wildcard mask.
  41. bool FolderWildcards;
  42. bool SearchAllInRoot;
  43. size_t SpecPathLength;
  44. wchar ErrArcName[NM];
  45. CommandData *Cmd;
  46. public:
  47. ScanTree(StringList *FileMasks,RECURSE_MODE Recurse,bool GetLinks,SCAN_DIRS GetDirs);
  48. ~ScanTree();
  49. SCAN_CODE GetNext(FindData *FindData);
  50. size_t GetSpecPathLength() {return SpecPathLength;}
  51. int GetErrors() {return Errors;};
  52. void SetErrArcName(const wchar *Name) {wcsncpyz(ErrArcName,Name,ASIZE(ErrArcName));}
  53. void SetCommandData(CommandData *Cmd) {ScanTree::Cmd=Cmd;}
  54. void SetErrDirList(StringList *List,Array<uint> *Lengths)
  55. {
  56. ErrDirList=List;
  57. ErrDirSpecPathLength=Lengths;
  58. }
  59. };
  60. #endif