From bd56579c7d9de94c17287adefa118290e6b7ba33 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Fri, 23 Feb 2018 23:49:48 +0000 Subject: New upstream version 1.4.0.3 --- plugins/CopyEngine/Ultracopier/DriveManagement.cpp | 70 +++++++++++----------- 1 file changed, 36 insertions(+), 34 deletions(-) (limited to 'plugins/CopyEngine/Ultracopier/DriveManagement.cpp') 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 #include +#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