File: algorithm.h

package info (click to toggle)
freefilesync 13.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,044 kB
  • sloc: cpp: 66,712; ansic: 447; makefile: 216
file content (112 lines) | stat: -rw-r--r-- 5,431 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under    *
// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0          *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************

#ifndef ALGORITHM_H_34218518475321452548
#define ALGORITHM_H_34218518475321452548

//#include <functional>
#include <span>
#include "structures.h"
#include "file_hierarchy.h"
#include "soft_filter.h"
#include "process_callback.h"


namespace fff
{
void swapGrids(const MainConfiguration& mainCfg, FolderComparison& folderCmp,
               PhaseCallback& callback /*throw X*/); //throw X

std::vector<std::pair<BaseFolderPair*, SyncDirectionConfig>> extractDirectionCfg(FolderComparison& folderCmp, const MainConfiguration& mainCfg);

void redetermineSyncDirection(const std::vector<std::pair<BaseFolderPair*, SyncDirectionConfig>>& directCfgs,
                              PhaseCallback& callback /*throw X*/); //throw X

void setSyncDirectionRec(SyncDirection newDirection, FileSystemObject& fsObj); //set new direction (recursively)

bool allElementsEqual(const FolderComparison& folderCmp);

//filtering
void applyFiltering  (FolderComparison& folderCmp, const MainConfiguration& mainCfg); //full filter apply
void addHardFiltering(BaseFolderPair& baseFolder, const Zstring& excludeFilter);     //exclude additional entries only
void addSoftFiltering(BaseFolderPair& baseFolder, const SoftFilter& timeSizeFilter); //exclude additional entries only

void applyTimeSpanFilter(FolderComparison& folderCmp, time_t timeFrom, time_t timeTo); //overwrite current active/inactive settings

void setActiveStatus(bool newStatus, FolderComparison& folderCmp); //activate or deactivate all rows
void setActiveStatus(bool newStatus, FileSystemObject& fsObj);     //activate or deactivate row: (not recursively anymore)

struct PathDependency
{
    AbstractPath itemPathParent;
    Zstring relPath; //filled if child path is subfolder of parent path; empty if child path == parent path
};
std::optional<PathDependency> getPathDependency(const AbstractPath& itemPathL, const AbstractPath& itemPathR);
std::optional<PathDependency> getFolderPathDependency(const AbstractPath& folderPathL, const PathFilter& filterL,
                                                      const AbstractPath& folderPathR, const PathFilter& filterR);

//manual copy to alternate folder:
void copyToAlternateFolder(const std::vector<const FileSystemObject*>& selectionL, //all pointers need to be bound and !isEmpty<side>!
                           const std::vector<const FileSystemObject*>& selectionR, //
                           const Zstring& targetFolderPathPhrase,
                           bool keepRelPaths, bool overwriteIfExists,
                           WarningDialogs& warnings,
                           ProcessCallback& callback /*throw X*/); //throw X

//manual deletion of files on main grid
void deleteFiles(const std::vector<FileSystemObject*>& selectionL, //all pointers need to be bound and !isEmpty<side>!
                 const std::vector<FileSystemObject*>& selectionR, //refresh GUI grid after deletion to remove invalid rows
                 const std::vector<std::pair<BaseFolderPair*, SyncDirectionConfig>>& directCfgs, //attention: rows will be physically deleted!
                 bool moveToRecycler,
                 bool& warnRecyclerMissing,
                 ProcessCallback& callback /*throw X*/); //throw X

void renameItems(const std::vector<FileSystemObject*>& selectionL, //all pointers need to be bound and !isEmpty<side>!
                 const std::span<const Zstring> newNamesL,
                 const std::vector<FileSystemObject*>& selectionR, //refresh GUI grid after deletion to remove invalid rows
                 const std::span<const Zstring> newNamesR,
                 const std::vector<std::pair<BaseFolderPair*, SyncDirectionConfig>>& directCfgs,
                 ProcessCallback& callback /*throw X*/); //throw X

void deleteListOfFiles(const std::vector<Zstring>& filesToDeletePaths,
                       std::vector<Zstring>& deletedPaths,
                       bool moveToRecycler,
                       bool& warnRecyclerMissing,
                       ProcessCallback& callback /*throw X*/); //throw X

struct FileDescriptor
{
    AbstractPath path;
    FileAttributes attr;

    std::weak_ordering operator<=>(const FileDescriptor&) const = default;
};

//get native Win32 paths or create temporary copy for SFTP/MTP, etc.
class TempFileBuffer
{
public:
    TempFileBuffer() {}
    ~TempFileBuffer();

    Zstring getAndCreateFolderPath(); //throw FileError

    Zstring getTempPath(const FileDescriptor& descr) const; //returns empty if not in buffer (item not existing, error during copy)

    //contract: only add files not yet in the buffer!
    void createTempFiles(const std::set<FileDescriptor>& workLoad, ProcessCallback& callback /*throw X*/); //throw X

private:
    TempFileBuffer           (const TempFileBuffer&) = delete;
    TempFileBuffer& operator=(const TempFileBuffer&) = delete;

    void createTempFolderPath(); //throw FileError

    std::map<FileDescriptor, Zstring> tempFilePaths_;
    Zstring tempFolderPath_;
};
}
#endif //ALGORITHM_H_34218518475321452548