source: filezilla/trunk/fuentes/src/interface/recursive_operation.h @ 3185

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 2 years ago

Update new version: 3.15.02

File size: 3.0 KB
Line 
1#ifndef __RECURSIVE_OPERATION_H__
2#define __RECURSIVE_OPERATION_H__
3
4#include "state.h"
5#include <set>
6#include "filter.h"
7#include <optional.h>
8
9class CChmodDialog;
10class CQueueView;
11
12class recursion_root final
13{
14public:
15        recursion_root() = default;
16        recursion_root(CServerPath const& start_dir, bool allow_parent);
17
18        void add_dir_to_visit(CServerPath const& path, wxString const& subdir, CLocalPath const& localDir = CLocalPath(), bool is_link = false);
19        void add_dir_to_visit_restricted(CServerPath const& path, wxString const& restrict, bool recurse);
20
21        bool empty() const { return m_dirsToVisit.empty(); }
22
23private:
24        friend class CRecursiveOperation;
25
26        class new_dir final
27        {
28        public:
29                CServerPath parent;
30                wxString subdir;
31                CLocalPath localDir;
32                CSparseOptional<wxString> restrict;
33
34                // Symlink target might be outside actual start dir. Yet
35                // sometimes user wants to download symlink target contents
36                CServerPath start_dir;
37
38                // 0 = not a link
39                // 1 = link, added by class during the operation
40                // 2 = link, added by user of class
41                int link{};
42
43                bool doVisit{ true };
44                bool recurse{ true };
45                bool second_try{};
46        };
47
48        CServerPath m_startDir;
49        std::set<CServerPath> m_visitedDirs;
50        std::deque<new_dir> m_dirsToVisit;
51        bool m_allowParent{};
52};
53
54class CRecursiveOperation final : public CStateEventHandler
55{
56public:
57        CRecursiveOperation(CState* pState);
58        ~CRecursiveOperation();
59
60        enum OperationMode
61        {
62                recursive_none,
63                recursive_download,
64                recursive_addtoqueue,
65                recursive_download_flatten,
66                recursive_addtoqueue_flatten,
67                recursive_delete,
68                recursive_chmod,
69                recursive_list
70        };
71
72        void AddRecursionRoot(recursion_root && root);
73        void StartRecursiveOperation(OperationMode mode, std::vector<CFilter> const& filters, CServerPath const& finalDir);
74
75        void StopRecursiveOperation();
76
77        bool IsActive() const { return GetOperationMode() != recursive_none; }
78        OperationMode GetOperationMode() const { return m_operationMode; }
79        int64_t GetProcessedFiles() const { return m_processedFiles; }
80        int64_t GetProcessedDirectories() const { return m_processedDirectories; }
81
82        // Needed for recursive_chmod
83        void SetChmodDialog(CChmodDialog* pChmodDialog);
84
85        void SetQueue(CQueueView* pQueue);
86
87        bool ChangeOperationMode(OperationMode mode);
88
89protected:
90        void LinkIsNotDir();
91        void ListingFailed(int error);
92
93        // Processes the directory listing in case of a recursive operation
94        void ProcessDirectoryListing(const CDirectoryListing* pDirectoryListing);
95
96        bool NextOperation();
97
98        virtual void OnStateChange(CState* pState, t_statechange_notifications notification, const wxString&, const void* data2);
99
100        OperationMode m_operationMode;
101
102        bool BelowRecursionRoot(const CServerPath& path, recursion_root::new_dir &dir);
103
104        std::deque<recursion_root> recursion_roots_;
105
106        CServerPath m_finalDir;
107
108        // Needed for recursive_chmod
109        CChmodDialog* m_pChmodDlg{};
110
111        CQueueView* m_pQueue{};
112
113        std::vector<CFilter> m_filters;
114
115        friend class CCommandQueue;
116
117        uint64_t m_processedFiles{};
118        uint64_t m_processedDirectories{};
119};
120
121#endif //__RECURSIVE_OPERATION_H__
Note: See TracBrowser for help on using the repository browser.