summaryrefslogtreecommitdiff
path: root/plugins/CopyEngine/Ultracopier/DriveManagement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/CopyEngine/Ultracopier/DriveManagement.cpp')
-rw-r--r--plugins/CopyEngine/Ultracopier/DriveManagement.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/plugins/CopyEngine/Ultracopier/DriveManagement.cpp b/plugins/CopyEngine/Ultracopier/DriveManagement.cpp
new file mode 100644
index 0000000..221b4e8
--- /dev/null
+++ b/plugins/CopyEngine/Ultracopier/DriveManagement.cpp
@@ -0,0 +1,102 @@
+#include "DriveManagement.h"
+
+#include <QDir>
+#include <QFileInfoList>
+#include <QStorageInfo>
+
+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]:[\\\\/]).*$"));
+ #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
+{
+ const QString &inode=QDir::toNativeSeparators(fileOrFolder);
+ int size=mountSysPoint.size();
+ for (int i = 0; i < size; ++i) {
+ if(inode.startsWith(mountSysPoint.at(i)))
+ return QDir::toNativeSeparators(mountSysPoint.at(i));
+ }
+ #ifdef Q_OS_WIN32
+ if(fileOrFolder.contains(reg1))
+ {
+ QString returnString=fileOrFolder;
+ returnString.replace(reg2,QStringLiteral("\\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))
+ {
+ QString returnString=fileOrFolder;
+ returnString.replace(reg4,QStringLiteral("\\1"));
+ return QDir::toNativeSeparators(returnString).toUpper();
+ }
+ #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();
+}
+
+QByteArray DriveManagement::getDriveType(const QString &drive) const
+{
+ int index=mountSysPoint.indexOf(drive);
+ if(index!=-1)
+ return driveType.at(index);
+ return QByteArray();
+}
+
+bool DriveManagement::isSameDrive(const QString &file1,const QString &file2) const
+{
+ if(mountSysPoint.size()==0)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("no mount point found"));
+ return false;
+ }
+ const QString &drive1=getDrive(file1);
+ if(drive1.isEmpty())
+ {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("drive for the file1 not found: %1").arg(file1));
+ return false;
+ }
+ const QString &drive2=getDrive(file2);
+ if(drive2.isEmpty())
+ {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("drive for the file2 not found: %1").arg(file2));
+ return false;
+ }
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("%1 is egal to %2?").arg(drive1).arg(drive2));
+ if(drive1==drive2)
+ return true;
+ else
+ return false;
+}
+
+void DriveManagement::tryUpdate()
+{
+ mountSysPoint.clear();
+ driveType.clear();
+ const QList<QStorageInfo> mountedVolumesList=QStorageInfo::mountedVolumes();
+ int index=0;
+ while(index<mountedVolumesList.size())
+ {
+ mountSysPoint << QDir::toNativeSeparators(mountedVolumesList.at(index).rootPath());
+ #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();
+ else
+ driveType << QByteArray();
+ #else
+ driveType << mountedVolumesList.at(index).fileSystemType();
+ #endif
+ index++;
+ }
+}