diff options
author | Thomas Preud'homme <robotux@celest.fr> | 2018-02-23 23:49:48 +0000 |
---|---|---|
committer | Thomas Preud'homme <robotux@celest.fr> | 2018-02-23 23:49:48 +0000 |
commit | bd56579c7d9de94c17287adefa118290e6b7ba33 (patch) | |
tree | 666d7d0b6945b442573b7a3145969f66a53aa460 /plugins/CopyEngine/Ultracopier/DriveManagement.cpp | |
parent | b3c8bdcc0d1e4b2ab298847a7902b6d60410a5bc (diff) |
New upstream version 1.4.0.3
Diffstat (limited to 'plugins/CopyEngine/Ultracopier/DriveManagement.cpp')
-rw-r--r-- | plugins/CopyEngine/Ultracopier/DriveManagement.cpp | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/plugins/CopyEngine/Ultracopier/DriveManagement.cpp b/plugins/CopyEngine/Ultracopier/DriveManagement.cpp index 221b4e8..8deaf3c 100644 --- a/plugins/CopyEngine/Ultracopier/DriveManagement.cpp +++ b/plugins/CopyEngine/Ultracopier/DriveManagement.cpp @@ -4,75 +4,77 @@ #include <QFileInfoList> #include <QStorageInfo> +#include "../../../cpp11addition.h" + DriveManagement::DriveManagement() { tryUpdate(); #ifdef Q_OS_WIN32 - reg1=QRegularExpression(QStringLiteral("^(\\\\\\\\|//)[^\\\\\\\\/]+(\\\\|/)[^\\\\\\\\/]+")); - reg2=QRegularExpression(QStringLiteral("^((\\\\\\\\|//)[^\\\\\\\\/]+(\\\\|/)[^\\\\\\\\/]+).*$")); - reg3=QRegularExpression(QStringLiteral("^[a-zA-Z]:[\\\\/]")); - reg4=QRegularExpression(QStringLiteral("^([a-zA-Z]:[\\\\/]).*$")); + reg1=std::regex("^(\\\\\\\\|//)[^\\\\\\\\/]+(\\\\|/)[^\\\\\\\\/]+"); + reg2=std::regex("^((\\\\\\\\|//)[^\\\\\\\\/]+(\\\\|/)[^\\\\\\\\/]+).*$"); + reg3=std::regex("^[a-zA-Z]:[\\\\/]"); + reg4=std::regex("^([a-zA-Z]:[\\\\/]).*$"); #endif /// \warn ULTRACOPIER_DEBUGCONSOLE() don't work here because the sinal slot is not connected! } //get drive of an file or folder -QString DriveManagement::getDrive(const QString &fileOrFolder) const +std::string DriveManagement::getDrive(const std::string &fileOrFolder) const { - const QString &inode=QDir::toNativeSeparators(fileOrFolder); + const std::string &inode=QDir::toNativeSeparators(QString::fromStdString(fileOrFolder)).toStdString(); int size=mountSysPoint.size(); for (int i = 0; i < size; ++i) { - if(inode.startsWith(mountSysPoint.at(i))) - return QDir::toNativeSeparators(mountSysPoint.at(i)); + if(stringStartWith(inode,mountSysPoint.at(i))) + return QDir::toNativeSeparators(QString::fromStdString(mountSysPoint.at(i))).toStdString(); } #ifdef Q_OS_WIN32 - if(fileOrFolder.contains(reg1)) + if(std::regex_match(fileOrFolder,reg1)) { - QString returnString=fileOrFolder; - returnString.replace(reg2,QStringLiteral("\\1")); + std::string returnString=fileOrFolder; + std::regex_replace(returnString,reg2,"$1"); return returnString; } //due to lack of WMI support into mingw, the new drive event is never called, this is a workaround - if(fileOrFolder.contains(reg3)) + if(std::regex_match(fileOrFolder,reg3)) { - QString returnString=fileOrFolder; - returnString.replace(reg4,QStringLiteral("\\1")); - return QDir::toNativeSeparators(returnString).toUpper(); + std::string returnString=fileOrFolder; + std::regex_replace(returnString,reg4,"$1"); + return QDir::toNativeSeparators(QString::fromStdString(returnString)).toUpper().toStdString(); } #endif //if unable to locate the right mount point - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("unable to locate the right mount point for: %1, mount point: %2").arg(fileOrFolder).arg(mountSysPoint.join(";"))); - return QString(); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"unable to locate the right mount point for: "+fileOrFolder+", mount point: "+stringimplode(mountSysPoint,";")); + return std::string(); } -QByteArray DriveManagement::getDriveType(const QString &drive) const +QByteArray DriveManagement::getDriveType(const std::string &drive) const { - int index=mountSysPoint.indexOf(drive); + int index=vectorindexOf(mountSysPoint,drive); if(index!=-1) return driveType.at(index); return QByteArray(); } -bool DriveManagement::isSameDrive(const QString &file1,const QString &file2) const +bool DriveManagement::isSameDrive(const std::string &file1,const std::string &file2) const { if(mountSysPoint.size()==0) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("no mount point found")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"no mount point found"); return false; } - const QString &drive1=getDrive(file1); - if(drive1.isEmpty()) + const std::string &drive1=getDrive(file1); + if(drive1.empty()) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("drive for the file1 not found: %1").arg(file1)); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"drive for the file1 not found: "+file1); return false; } - const QString &drive2=getDrive(file2); - if(drive2.isEmpty()) + const std::string &drive2=getDrive(file2); + if(drive2.empty()) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("drive for the file2 not found: %1").arg(file2)); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"drive for the file2 not found: "+file2); return false; } - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("%1 is egal to %2?").arg(drive1).arg(drive2)); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,drive1+" is egal to "+drive2); if(drive1==drive2) return true; else @@ -87,15 +89,15 @@ void DriveManagement::tryUpdate() int index=0; while(index<mountedVolumesList.size()) { - mountSysPoint << QDir::toNativeSeparators(mountedVolumesList.at(index).rootPath()); + mountSysPoint.push_back(QDir::toNativeSeparators(mountedVolumesList.at(index).rootPath()).toStdString()); #ifdef Q_OS_WIN32 - if(mountSysPoint.last()!="A:\\" && mountSysPoint.last()!="A:/" && mountSysPoint.last()!="A:" && mountSysPoint.last()!="A" && - mountSysPoint.last()!="a:\\" && mountSysPoint.last()!="a:/" && mountSysPoint.last()!="a:" && mountSysPoint.last()!="a") - driveType << mountedVolumesList.at(index).fileSystemType(); + if(mountSysPoint.back()!="A:\\" && mountSysPoint.back()!="A:/" && mountSysPoint.back()!="A:" && mountSysPoint.back()!="A" && + mountSysPoint.back()!="a:\\" && mountSysPoint.back()!="a:/" && mountSysPoint.back()!="a:" && mountSysPoint.back()!="a") + driveType.push_back(mountedVolumesList.at(index).fileSystemType()); else - driveType << QByteArray(); + driveType.push_back(QByteArray()); #else - driveType << mountedVolumesList.at(index).fileSystemType(); + driveType.push_back(mountedVolumesList.at(index).fileSystemType()); #endif index++; } |