Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch Subdirectories of Watched folders in Blocked Mods Dialog #946

Merged
merged 10 commits into from
Apr 14, 2023
33 changes: 25 additions & 8 deletions launcher/ui/dialogs/BlockedModsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <QFileInfo>
#include <QMimeData>
#include <QPushButton>
#include <QMimeData>
#include <QStandardPaths>

BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods)
Expand Down Expand Up @@ -89,11 +88,11 @@ void BlockedModsDialog::dragEnterEvent(QDragEnterEvent* e)
void BlockedModsDialog::dropEvent(QDropEvent* e)
{
for (QUrl& url : e->mimeData()->urls()) {
if (url.scheme().isEmpty()) { // ensure isLocalFile() works correctly
if (url.scheme().isEmpty()) { // ensure isLocalFile() works correctly
url.setScheme("file");
}

if (!url.isLocalFile()) { // can't drop external files here.
if (!url.isLocalFile()) { // can't drop external files here.
continue;
}

Expand Down Expand Up @@ -172,7 +171,7 @@ void BlockedModsDialog::update()
}
}

/// @brief Signal fired when a watched direcotry has changed
/// @brief Signal fired when a watched directory has changed
/// @param path the path to the changed directory
void BlockedModsDialog::directoryChanged(QString path)
{
Expand All @@ -186,8 +185,26 @@ void BlockedModsDialog::setupWatch()
{
const QString downloadsFolder = APPLICATION->settings()->get("DownloadsDir").toString();
const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString();
m_watcher.addPath(downloadsFolder);
m_watcher.addPath(modsFolder);
watchPath(downloadsFolder, true);
Ryex marked this conversation as resolved.
Show resolved Hide resolved
watchPath(modsFolder, true);
}

void BlockedModsDialog::watchPath(QString path, bool watch_subdirectories)
{
qDebug() << "[Blocked Mods Dialog] Adding Watch Path:" << path;
m_watcher.addPath(path);

if (!watch_subdirectories)
return;

QDirIterator it(path, QDir::Filter::Dirs, QDirIterator::NoIteratorFlags);
while (it.hasNext()) {
QString dir_path = it.next();
QDir to_watch_dir(dir_path);
if (to_watch_dir.dirName() == "." || to_watch_dir.dirName() == "..")
Ryex marked this conversation as resolved.
Show resolved Hide resolved
continue;
watchPath(dir_path, watch_subdirectories);
}
}

/// @brief scan all watched folder
Expand Down Expand Up @@ -221,7 +238,7 @@ void BlockedModsDialog::scanPath(QString path, bool start_task)
}
}

/// @brief add a hashing task for the file located at path, add the path to the pending set if the hasing task is already running
/// @brief add a hashing task for the file located at path, add the path to the pending set if the hashing task is already running
/// @param path the path to the local file being hashed
void BlockedModsDialog::addHashTask(QString path)
{
Expand Down Expand Up @@ -328,7 +345,7 @@ void BlockedModsDialog::validateMatchedMods()
}
}

/// @brief run hash task or mark a pending run if it is already runing
/// @brief run hash task or mark a pending run if it is already running
void BlockedModsDialog::runHashTask()
{
if (!m_hashing_task->isRunning()) {
Expand Down
1 change: 1 addition & 0 deletions launcher/ui/dialogs/BlockedModsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class BlockedModsDialog : public QDialog {
void update();
void directoryChanged(QString path);
void setupWatch();
void watchPath(QString path, bool watch_subdirectories = false);
Scrumplex marked this conversation as resolved.
Show resolved Hide resolved
void scanPaths();
void scanPath(QString path, bool start_task);
void addHashTask(QString path);
Expand Down