File: ListThreadNew.cpp

package info (click to toggle)
ultracopier 2.2.6.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 40,480 kB
  • sloc: ansic: 60,903; cpp: 59,790; sh: 6,882; asm: 723; xml: 675; makefile: 320; perl: 264
file content (134 lines) | stat: -rwxr-xr-x 6,037 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "ListThread.h"
#include <QStorageInfo>
#include <QtGlobal>
#include "../../../cpp11addition.h"

#include "async/TransferThreadAsync.h"

// -> add thread safe, by Qt::BlockingQueuedConnection
bool ListThread::newCopy(const std::vector<std::string> &sources,const std::string &destination)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"sources: "+stringimplode(sources,";")+", destination: "+destination);
    ScanFileOrFolder * scanFileOrFolderThread=newScanThread(Ultracopier::Copy);
    if(scanFileOrFolderThread==NULL)
    {
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to get new thread");
        return false;
    }
    std::regex base_regex("^[a-z][a-z][a-z]*:/.*");
    std::smatch base_match;
    std::vector<INTERNALTYPEPATH> sourcesClean;
    unsigned int index=0;
    while(index<sources.size())
    {
        std::string source=sources.at(index);
        //can be: file://192.168.0.99/share/file.txt
        //can be: file:///C:/file.txt
        //can be: file:///home/user/fileatrootunderunix
        #ifndef Q_OS_WIN
        if(stringStartWith(source,"file:///"))
            source.replace(0,7,"");
        #else
        if(stringStartWith(source,"file:///"))
            source.replace(0,8,"");
        else if(stringStartWith(source,"file://"))
            source.replace(0,5,"");
        else if(stringStartWith(source,"file:/"))
            source.replace(0,6,"");
        #endif
        else if (std::regex_match(source, base_match, base_regex))
            return false;
        if(index<99)
        {
            if(sources.at(index)!=source)
                ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,sources.at(index)+" -> "+source);
        }
        index++;
        sourcesClean.push_back(TransferThread::stringToInternalString(source));
    }
    //ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"sourcesClean: "+stringimplode(sourcesClean,";"));
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination: "+destination);
    const INTERNALTYPEPATH &Wdest=TransferThread::stringToInternalString(destination);
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination: "+TransferThread::internalStringTostring(Wdest));
    scanFileOrFolderThread->addToList(sourcesClean,Wdest);
    scanThreadHaveFinish(true);
    detectDrivesOfCurrentTransfer(sourcesClean,TransferThread::stringToInternalString(destination));
    return true;
}

// -> add thread safe, by Qt::BlockingQueuedConnection
bool ListThread::newMove(const std::vector<std::string> &sources,const std::string &destination)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start");

    #ifdef ULTRACOPIER_PLUGIN_DEBUG
    {
        unsigned int index=0;
        while(index<sources.size())
        {
            std::string source=sources.at(index);
            //can be: file://192.168.0.99/share/file.txt
            //can be: file:///C:/file.txt
            //can be: file:///home/user/fileatrootunderunix
            #ifndef Q_OS_WIN
            if(stringStartWith(source,"file:///"))
                source.replace(0,7,"");
            #else
            if(stringStartWith(source,"file:///"))
                source.replace(0,8,"");
            else if(stringStartWith(source,"file://"))
                source.replace(0,5,"");
            else if(stringStartWith(source,"file:/"))
                source.replace(0,6,"");
            #endif
            if(index<99)
                ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,sources.at(index)+" -> "+source);
            index++;
            ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"source is_file: "+std::to_string(TransferThread::is_file(TransferThread::stringToInternalString(source)))+" is_dir: "+std::to_string(TransferThread::is_dir(TransferThread::stringToInternalString(source))));
        }
    }
    #endif

    ScanFileOrFolder * scanFileOrFolderThread = newScanThread(Ultracopier::Move);
    if(scanFileOrFolderThread==NULL)
    {
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to get new thread");
        return false;
    }
    std::regex base_regex("^[a-z][a-z][a-z]*:/.*");
    std::smatch base_match;
    std::vector<INTERNALTYPEPATH> sourcesClean;
    unsigned int index=0;
    while(index<sources.size())
    {
        std::string source=sources.at(index);
        //can be: file://192.168.0.99/share/file.txt
        //can be: file:///C:/file.txt
        //can be: file:///home/user/fileatrootunderunix
        #ifndef Q_OS_WIN
        if(stringStartWith(source,"file:///"))
            source.replace(0,7,"");
        #else
        if(stringStartWith(source,"file:///"))
            source.replace(0,8,"");
        else if(stringStartWith(source,"file://"))
            source.replace(0,5,"");
        else if(stringStartWith(source,"file:/"))
            source.replace(0,6,"");
        #endif
        else if (std::regex_match(source, base_match, base_regex))
            return false;
        if(index<99)
            ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,sources.at(index)+" -> "+source);
        index++;
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"source is_file: "+std::to_string(TransferThread::is_file(TransferThread::stringToInternalString(source)))+" is_dir: "+std::to_string(TransferThread::is_dir(TransferThread::stringToInternalString(source))));
        sourcesClean.push_back(TransferThread::stringToInternalString(source));
    }
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination: "+destination);
    const INTERNALTYPEPATH &Wdest=TransferThread::stringToInternalString(destination);
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination: "+TransferThread::internalStringTostring(Wdest));
    scanFileOrFolderThread->addToList(sourcesClean,Wdest);
    scanThreadHaveFinish(true);
    detectDrivesOfCurrentTransfer(sourcesClean,TransferThread::stringToInternalString(destination));
    return true;
}