mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-24 05:25:37 +00:00
Add isNetworkFileSystem() detection on Windows
This allows network mounts to be monitored correctly by polling timer.
This commit is contained in:
parent
fb8fad3fa1
commit
cff5af2e76
@ -58,18 +58,14 @@ FileSystemWatcher::FileSystemWatcher(QObject *parent)
|
|||||||
m_partialTorrentTimer.setSingleShot(true);
|
m_partialTorrentTimer.setSingleShot(true);
|
||||||
connect(&m_partialTorrentTimer, &QTimer::timeout, this, &FileSystemWatcher::processPartialTorrents);
|
connect(&m_partialTorrentTimer, &QTimer::timeout, this, &FileSystemWatcher::processPartialTorrents);
|
||||||
|
|
||||||
#ifndef Q_OS_WIN
|
|
||||||
connect(&m_watchTimer, &QTimer::timeout, this, &FileSystemWatcher::scanNetworkFolders);
|
connect(&m_watchTimer, &QTimer::timeout, this, &FileSystemWatcher::scanNetworkFolders);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList FileSystemWatcher::directories() const
|
QStringList FileSystemWatcher::directories() const
|
||||||
{
|
{
|
||||||
QStringList dirs = QFileSystemWatcher::directories();
|
QStringList dirs = QFileSystemWatcher::directories();
|
||||||
#ifndef Q_OS_WIN
|
|
||||||
for (const QDir &dir : qAsConst(m_watchedFolders))
|
for (const QDir &dir : qAsConst(m_watchedFolders))
|
||||||
dirs << dir.canonicalPath();
|
dirs << dir.canonicalPath();
|
||||||
#endif
|
|
||||||
return dirs;
|
return dirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +73,7 @@ void FileSystemWatcher::addPath(const QString &path)
|
|||||||
{
|
{
|
||||||
if (path.isEmpty()) return;
|
if (path.isEmpty()) return;
|
||||||
|
|
||||||
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU
|
#if !defined Q_OS_HAIKU
|
||||||
const QDir dir(path);
|
const QDir dir(path);
|
||||||
if (!dir.exists()) return;
|
if (!dir.exists()) return;
|
||||||
|
|
||||||
@ -100,13 +96,12 @@ void FileSystemWatcher::addPath(const QString &path)
|
|||||||
|
|
||||||
void FileSystemWatcher::removePath(const QString &path)
|
void FileSystemWatcher::removePath(const QString &path)
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_WIN
|
|
||||||
if (m_watchedFolders.removeOne(path)) {
|
if (m_watchedFolders.removeOne(path)) {
|
||||||
if (m_watchedFolders.isEmpty())
|
if (m_watchedFolders.isEmpty())
|
||||||
m_watchTimer.stop();
|
m_watchTimer.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
// Normal mode
|
// Normal mode
|
||||||
QFileSystemWatcher::removePath(path);
|
QFileSystemWatcher::removePath(path);
|
||||||
}
|
}
|
||||||
@ -116,13 +111,11 @@ void FileSystemWatcher::scanLocalFolder(const QString &path)
|
|||||||
QTimer::singleShot(2000, this, [this, path]() { processTorrentsInDir(path); });
|
QTimer::singleShot(2000, this, [this, path]() { processTorrentsInDir(path); });
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef Q_OS_WIN
|
|
||||||
void FileSystemWatcher::scanNetworkFolders()
|
void FileSystemWatcher::scanNetworkFolders()
|
||||||
{
|
{
|
||||||
for (const QDir &dir : qAsConst(m_watchedFolders))
|
for (const QDir &dir : qAsConst(m_watchedFolders))
|
||||||
processTorrentsInDir(dir);
|
processTorrentsInDir(dir);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void FileSystemWatcher::processPartialTorrents()
|
void FileSystemWatcher::processPartialTorrents()
|
||||||
{
|
{
|
||||||
|
@ -56,9 +56,7 @@ signals:
|
|||||||
protected slots:
|
protected slots:
|
||||||
void scanLocalFolder(const QString &path);
|
void scanLocalFolder(const QString &path);
|
||||||
void processPartialTorrents();
|
void processPartialTorrents();
|
||||||
#ifndef Q_OS_WIN
|
|
||||||
void scanNetworkFolders();
|
void scanNetworkFolders();
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processTorrentsInDir(const QDir &dir);
|
void processTorrentsInDir(const QDir &dir);
|
||||||
@ -67,10 +65,8 @@ private:
|
|||||||
QHash<QString, int> m_partialTorrents;
|
QHash<QString, int> m_partialTorrents;
|
||||||
QTimer m_partialTorrentTimer;
|
QTimer m_partialTorrentTimer;
|
||||||
|
|
||||||
#ifndef Q_OS_WIN
|
|
||||||
QList<QDir> m_watchedFolders;
|
QList<QDir> m_watchedFolders;
|
||||||
QTimer m_watchTimer;
|
QTimer m_watchTimer;
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FILESYSTEMWATCHER_H
|
#endif // FILESYSTEMWATCHER_H
|
||||||
|
@ -30,6 +30,10 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
#include <memory>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@ -301,9 +305,17 @@ bool Utils::Fs::isRegularFile(const QString &path)
|
|||||||
return (st.st_mode & S_IFMT) == S_IFREG;
|
return (st.st_mode & S_IFMT) == S_IFREG;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU
|
#if !defined Q_OS_HAIKU
|
||||||
bool Utils::Fs::isNetworkFileSystem(const QString &path)
|
bool Utils::Fs::isNetworkFileSystem(const QString &path)
|
||||||
{
|
{
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
const std::wstring pathW {path.toStdWString()};
|
||||||
|
std::unique_ptr<wchar_t[]> volumePath {new wchar_t[path.length() + 1] {}};
|
||||||
|
if (!::GetVolumePathNameW(pathW.c_str(), volumePath.get(), (path.length() + 1)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return (::GetDriveTypeW(volumePath.get()) == DRIVE_REMOTE);
|
||||||
|
#else
|
||||||
QString file = path;
|
QString file = path;
|
||||||
if (!file.endsWith('/'))
|
if (!file.endsWith('/'))
|
||||||
file += '/';
|
file += '/';
|
||||||
@ -312,7 +324,6 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path)
|
|||||||
struct statfs buf {};
|
struct statfs buf {};
|
||||||
if (statfs(file.toLocal8Bit().constData(), &buf) != 0)
|
if (statfs(file.toLocal8Bit().constData(), &buf) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#if defined(Q_OS_MAC) || defined(Q_OS_OPENBSD)
|
#if defined(Q_OS_MAC) || defined(Q_OS_OPENBSD)
|
||||||
// XXX: should we make sure HAVE_STRUCT_FSSTAT_F_FSTYPENAME is defined?
|
// XXX: should we make sure HAVE_STRUCT_FSSTAT_F_FSTYPENAME is defined?
|
||||||
return ((strncmp(buf.f_fstypename, "cifs", sizeof(buf.f_fstypename)) == 0)
|
return ((strncmp(buf.f_fstypename, "cifs", sizeof(buf.f_fstypename)) == 0)
|
||||||
@ -332,5 +343,6 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -62,7 +62,7 @@ namespace Utils
|
|||||||
|
|
||||||
QString tempPath();
|
QString tempPath();
|
||||||
|
|
||||||
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU
|
#if !defined Q_OS_HAIKU
|
||||||
bool isNetworkFileSystem(const QString &path);
|
bool isNetworkFileSystem(const QString &path);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user