summaryrefslogtreecommitdiff
path: root/algorithm.h
blob: e198906c4cfc2b105e59eb87067aef2b800ada56 (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
#ifndef ALGORITHM_H_INCLUDED
#define ALGORITHM_H_INCLUDED

#include "FreeFileSync.h"
#include "library/statusHandler.h"
#include "library/resources.h"


namespace FreeFileSync
{
    wxString formatFilesizeToShortString(const wxULongLong& filesize);
    wxString formatFilesizeToShortString(const double filesize);
    Zstring getFormattedDirectoryName(const Zstring& dirname);

    bool endsWithPathSeparator(const Zstring& name);

    void swapGrids(FileCompareResult& grid);

    void addSubElements(const FileCompareResult& grid, const FileCompareLine& relevantRow, std::set<int>& subElements);

    //manual deletion of files on main grid
    wxString deleteFromGridAndHDPreview(const FileCompareResult& grid,
                                        const std::set<int>& rowsToDeleteOnLeft,
                                        const std::set<int>& rowsToDeleteOnRight,
                                        const bool deleteOnBothSides);

    void deleteFromGridAndHD(FileCompareResult& grid,
                             const std::set<int>& rowsToDeleteOnLeft,
                             const std::set<int>& rowsToDeleteOnRight,
                             const bool deleteOnBothSides,
                             const bool useRecycleBin,
                             ErrorHandler* errorHandler);

    void filterGridData(FileCompareResult& currentGridData, const wxString& includeFilter, const wxString& excludeFilter);
    void includeAllRowsOnGrid(FileCompareResult& currentGridData);
    void excludeAllRowsOnGrid(FileCompareResult& currentGridData);

    wxString utcTimeToLocalString(const wxLongLong& utcTime);

    //enhanced binary search template: returns an iterator
    template <class ForwardIterator, class T>
    ForwardIterator custom_binary_search (ForwardIterator first, ForwardIterator last, const T& value)
    {
        first = lower_bound(first, last, value);
        if (first != last && !(value < *first))
            return first;
        else
            return last;
    }

#ifdef FFS_WIN
    Zstring getLastErrorFormatted(const unsigned long lastError = 0); //try to get additional Windows error information
#elif defined FFS_LINUX
    Zstring getLastErrorFormatted(const int lastError = 0); //try to get additional Linux error information
#endif
}


inline
bool FreeFileSync::endsWithPathSeparator(const Zstring& name)
{
    const size_t len = name.length();
    return len && (name[len - 1] == GlobalResources::FILE_NAME_SEPARATOR);
}



#endif // ALGORITHM_H_INCLUDED
bgstack15