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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#include "ListThread.h"
#include <QStorageInfo>
#include <QtGlobal>
#include "../../../cpp11addition.h"
#include "async/TransferThreadAsync.h"
// -> add thread safe, by Qt::BlockingQueuedConnection
bool ListThread::haveSameSource(const std::vector<std::string> &sources)
{
if(stopIt)
return false;
if(sourceDriveMultiple)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"sourceDriveMultiple");
return false;
}
if(sourceDrive.empty())
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"sourceDrive.isEmpty()");
return true;
}
unsigned int index=0;
while(index<sources.size())
{
if(driveManagement.getDrive(sources.at(index))!=sourceDrive)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"sources.at(index))!=sourceDrive");
return false;
}
index++;
}
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"seam have same source");
return true;
}
// -> add thread safe, by Qt::BlockingQueuedConnection
bool ListThread::haveSameDestination(const std::string &destination)
{
if(stopIt)
return false;
if(destinationDriveMultiple)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destinationDriveMultiple");
return false;
}
if(destinationDrive.empty())
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destinationDrive.isEmpty()");
return true;
}
if(driveManagement.getDrive(destination)!=destinationDrive)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination!=destinationDrive");
return false;
}
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"seam have same destination");
return true;
}
/// \return empty if multiple or no destination
std::string ListThread::getUniqueDestinationFolder() const
{
if(stopIt)
return std::string();
if(destinationFolderMultiple)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destinationDriveMultiple");
return std::string();
}
return TransferThread::internalStringTostring(destinationFolder);
}
void ListThread::detectDrivesOfCurrentTransfer(const std::vector<INTERNALTYPEPATH> &sources,const INTERNALTYPEPATH &destination)
{
/* code to detect volume/mount point to group by windows */
if(!sourceDriveMultiple)
{
unsigned int index=0;
while(index<sources.size())
{
const std::string &tempDrive=driveManagement.getDrive(TransferThread::internalStringTostring(sources.at(index)));
//if have not already source, set the source
if(sourceDrive.empty())
sourceDrive=tempDrive;
//if have previous source and the news source is not the same
if(sourceDrive!=tempDrive)
{
sourceDriveMultiple=true;
break;
}
index++;
}
}
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("source informations, sourceDrive: %1, sourceDriveMultiple: %2").arg(QString::fromStdString(sourceDrive)).arg(sourceDriveMultiple).toStdString());
if(!destinationDriveMultiple)
{
const std::string &tempDrive=driveManagement.getDrive(TransferThread::internalStringTostring(destination));
//if have not already destination, set the destination
if(destinationDrive.empty())
destinationDrive=tempDrive;
//if have previous destination and the news destination is not the same
if(destinationDrive!=tempDrive)
destinationDriveMultiple=true;
}
if(!destinationFolderMultiple)
{
//if have not already destination, set the destination
if(destinationFolder.empty())
destinationFolder=destination;
//if have previous destination and the news destination is not the same
if(destinationFolder!=destination)
destinationFolderMultiple=true;
}
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("destination informations, destinationDrive: %1, destinationDriveMultiple: %2").arg(QString::fromStdString(destinationDrive)).arg(destinationDriveMultiple).toStdString());
}
//return
bool ListThread::needMoreSpace() const
{
if(!checkDiskSpace)
return false;
std::vector<Diskspace> diskspace_list;
for( auto& spaceDrive : requiredSpace ) {
const QString &drive=QString::fromStdString(spaceDrive.first);
#ifdef Q_OS_WIN32
if(spaceDrive.first!="A:\\" && spaceDrive.first!="A:/" && spaceDrive.first!="A:" && spaceDrive.first!="A" && spaceDrive.first!="a:\\" && spaceDrive.first!="a:/" && spaceDrive.first!="a:" && spaceDrive.first!="a")
{
#endif
QStorageInfo storageInfo(drive);
storageInfo.refresh();
const qint64 &availableSpace=storageInfo.bytesAvailable();
#ifdef ULTRACOPIER_PLUGIN_DEBUG
const qint64 &bytesFree=storageInfo.bytesFree();
#endif
if(availableSpace<0 ||
//workaround for all 0 value in case of bug from Qt
(availableSpace==0 && storageInfo.bytesTotal()==0)
)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("availableSpace: %1, space needed: %2, on: %3, bytesFree: %4").arg(availableSpace).arg(spaceDrive.second).arg(drive).arg(bytesFree).toStdString());
}
else if(spaceDrive.second>(quint64)availableSpace)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("availableSpace: %1, space needed: %2, on: %3, bytesFree: %4").arg(availableSpace).arg(spaceDrive.second).arg(drive).arg(bytesFree).toStdString());
#ifdef Q_OS_WIN32
//if(drive.contains(QRegularExpression("^[a-zA-Z]:[\\\\/]")))
if(drive.contains(QRegularExpression("^[a-zA-Z]:")))
#endif
{
Diskspace diskspace;
diskspace.drive=spaceDrive.first;
diskspace.freeSpace=availableSpace;
diskspace.requiredSpace=spaceDrive.second;
diskspace_list.push_back(diskspace);
}
#ifdef Q_OS_WIN32
else
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"not local drive");
#endif
}
#ifdef Q_OS_WIN32
}
#endif
}
if(!diskspace_list.empty())
emit missingDiskSpace(diskspace_list);
return ! diskspace_list.empty();
}
|