summaryrefslogtreecommitdiff
path: root/shared/fileTraverser.h
blob: c1277d87357afa3c257721cdfb2fe0ce41d5254b (plain)
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
#ifndef FILETRAVERSER_H_INCLUDED
#define FILETRAVERSER_H_INCLUDED

#include "zstring.h"
#include <set>
#include <memory>
#include <wx/longlong.h>

//advanced file traverser returning metadata and hierarchical information on files and directories

namespace FreeFileSync
{
class TraverseCallback
{
public:
    virtual ~TraverseCallback() {}

    enum ReturnValue
    {
        TRAVERSING_STOP,
        TRAVERSING_CONTINUE
    };

    struct FileInfo
    {
        wxULongLong fileSize;        //unit: bytes!
        wxLongLong lastWriteTimeRaw; //number of seconds since Jan. 1st 1970 UTC
    };

    class ReturnValDir
    {
    public:
        //some proxy classes
        class Stop {};
        class Ignore {};
        class Continue {};

        ReturnValDir(const Stop&) : returnCode(TRAVERSING_STOP), subDirCb(NULL) {}
        ReturnValDir(const Ignore&) : returnCode(TRAVERSING_IGNORE_DIR), subDirCb(NULL) {}
        ReturnValDir(const Continue&, TraverseCallback* subDirCallback) : returnCode(TRAVERSING_CONTINUE), subDirCb(subDirCallback) {}


        enum ReturnValueEnh
        {
            TRAVERSING_STOP,
            TRAVERSING_IGNORE_DIR,
            TRAVERSING_CONTINUE
        };

        const ReturnValueEnh returnCode;
        TraverseCallback* const subDirCb;
    };

    //overwrite these virtual methods
    virtual ReturnValue  onError(const wxString& errorText) = 0;
    virtual ReturnValue  onFile(const DefaultChar* shortName, const Zstring& fullName, const FileInfo& details) = 0;
    virtual ReturnValDir onDir(const DefaultChar*  shortName, const Zstring& fullName) = 0;
};

//custom traverser with detail information about files
void traverseFolder(const Zstring& directory, const bool traverseDirectorySymlinks, TraverseCallback* sink); //throw()
}

#endif // FILETRAVERSER_H_INCLUDED
bgstack15