summaryrefslogtreecommitdiff
path: root/shared/fileHandling.h
blob: b5e75c17474dc3ec79eab51b3f8293f32784b95b (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef RECYCLER_H_INCLUDED
#define RECYCLER_H_INCLUDED

#include "zstring.h"
#include "fileError.h"
#include <wx/longlong.h>


namespace FreeFileSync
{
    Zstring getFormattedDirectoryName(const Zstring& dirname);

    bool fileExists(const DefaultChar* filename);   //replaces wxFileExists()!
    bool dirExists(const DefaultChar* dirname);     //replaces wxDirExists(): optional 'cause wxDirExists treats symlinks correctly
    bool symlinkExists(const DefaultChar* objname); //check if a symbolic link exists

    //recycler
    bool recycleBinExists(); //test existence of Recycle Bin API on current system

    //file handling
    void removeFile(const Zstring& filename, const bool useRecycleBin);       //throw (FileError, ::RuntimeException);
    void removeDirectory(const Zstring& directory, const bool useRecycleBin); //throw (FileError);


    class MoveFileCallback //callback functionality
    {
    public:
        virtual ~MoveFileCallback() {}

        enum Response
        {
            CONTINUE,
            CANCEL
        };
        virtual Response requestUiRefresh() = 0;  //DON'T throw exceptions here, at least in Windows build!
    };

    //move source to target; expectations: target not existing, all super-directories of target exist
    void moveFile(const Zstring& sourceFile, const Zstring& targetFile, MoveFileCallback* callback = NULL); //throw (FileError);

    //move source to target including subdirectories
    //"ignoreExistingDirs": existing directories will be enhanced as long as this is possible without overwriting files
    void moveDirectory(const Zstring& sourceDir, const Zstring& targetDir, bool ignoreExistingDirs, MoveFileCallback* callback = NULL); //throw (FileError);

    //creates superdirectories automatically:
    void createDirectory(const Zstring& directory, const Zstring& templateDir = Zstring(), const bool copyDirectorySymLinks = false); //throw (FileError);

    class CopyFileCallback //callback functionality
    {
    public:
        virtual ~CopyFileCallback() {}

        enum Response
        {
            CONTINUE,
            CANCEL
        };
        virtual Response updateCopyStatus(const wxULongLong& totalBytesTransferred) = 0; //DON'T throw exceptions here, at least in Windows build!
    };

#ifdef FFS_WIN
    class ShadowCopy;

    void copyFile(const Zstring& sourceFile,
                  const Zstring& targetFile,
                  const bool copyFileSymLinks,
                  ShadowCopy* shadowCopyHandler = NULL, //supply handler for making shadow copies
                  CopyFileCallback* callback = NULL); //throw (FileError);

#elif defined FFS_LINUX
    void copyFile(const Zstring& sourceFile,
                  const Zstring& targetFile,
                  const bool copyFileSymLinks,
                  CopyFileCallback* callback = NULL); //throw (FileError);
#endif
}


#endif // RECYCLER_H_INCLUDED
bgstack15