Merge pull request #946 from Ryex/subfolder-watch
This commit is contained in:
commit
1b05303250
@ -517,6 +517,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
m_settings->registerSetting({"CentralModsDir", "ModsDir"}, "mods");
|
m_settings->registerSetting({"CentralModsDir", "ModsDir"}, "mods");
|
||||||
m_settings->registerSetting("IconsDir", "icons");
|
m_settings->registerSetting("IconsDir", "icons");
|
||||||
m_settings->registerSetting("DownloadsDir", QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
|
m_settings->registerSetting("DownloadsDir", QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
|
||||||
|
m_settings->registerSetting("DownloadsDirWatchRecursive", false);
|
||||||
|
|
||||||
// Editors
|
// Editors
|
||||||
m_settings->registerSetting("JsonEditor", QString());
|
m_settings->registerSetting("JsonEditor", QString());
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QMimeData>
|
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods)
|
BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods)
|
||||||
@ -89,11 +88,11 @@ void BlockedModsDialog::dragEnterEvent(QDragEnterEvent* e)
|
|||||||
void BlockedModsDialog::dropEvent(QDropEvent* e)
|
void BlockedModsDialog::dropEvent(QDropEvent* e)
|
||||||
{
|
{
|
||||||
for (QUrl& url : e->mimeData()->urls()) {
|
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");
|
url.setScheme("file");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!url.isLocalFile()) { // can't drop external files here.
|
if (!url.isLocalFile()) { // can't drop external files here.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
/// @param path the path to the changed directory
|
||||||
void BlockedModsDialog::directoryChanged(QString path)
|
void BlockedModsDialog::directoryChanged(QString path)
|
||||||
{
|
{
|
||||||
@ -186,8 +185,30 @@ void BlockedModsDialog::setupWatch()
|
|||||||
{
|
{
|
||||||
const QString downloadsFolder = APPLICATION->settings()->get("DownloadsDir").toString();
|
const QString downloadsFolder = APPLICATION->settings()->get("DownloadsDir").toString();
|
||||||
const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString();
|
const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString();
|
||||||
m_watcher.addPath(downloadsFolder);
|
const bool downloadsFolderWatchRecursive = APPLICATION->settings()->get("DownloadsDirWatchRecursive").toBool();
|
||||||
m_watcher.addPath(modsFolder);
|
watchPath(downloadsFolder, downloadsFolderWatchRecursive);
|
||||||
|
watchPath(modsFolder, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlockedModsDialog::watchPath(QString path, bool watch_recursive)
|
||||||
|
{
|
||||||
|
auto to_watch = QFileInfo(path);
|
||||||
|
auto to_watch_path = to_watch.canonicalFilePath();
|
||||||
|
if (m_watcher.directories().contains(to_watch_path))
|
||||||
|
return; // don't watch the same path twice (no loops!)
|
||||||
|
|
||||||
|
qDebug() << "[Blocked Mods Dialog] Adding Watch Path:" << path;
|
||||||
|
m_watcher.addPath(to_watch_path);
|
||||||
|
|
||||||
|
if (!to_watch.isDir() || !watch_recursive)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
QDirIterator it(to_watch_path, QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot, QDirIterator::NoIteratorFlags);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QString watch_dir = QDir(it.next()).canonicalPath(); // resolve symlinks and relative paths
|
||||||
|
watchPath(watch_dir, watch_recursive);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief scan all watched folder
|
/// @brief scan all watched folder
|
||||||
@ -221,7 +242,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
|
/// @param path the path to the local file being hashed
|
||||||
void BlockedModsDialog::addHashTask(QString path)
|
void BlockedModsDialog::addHashTask(QString path)
|
||||||
{
|
{
|
||||||
@ -328,7 +349,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()
|
void BlockedModsDialog::runHashTask()
|
||||||
{
|
{
|
||||||
if (!m_hashing_task->isRunning()) {
|
if (!m_hashing_task->isRunning()) {
|
||||||
|
@ -79,6 +79,7 @@ class BlockedModsDialog : public QDialog {
|
|||||||
void update();
|
void update();
|
||||||
void directoryChanged(QString path);
|
void directoryChanged(QString path);
|
||||||
void setupWatch();
|
void setupWatch();
|
||||||
|
void watchPath(QString path, bool watch_recursive = false);
|
||||||
void scanPaths();
|
void scanPaths();
|
||||||
void scanPath(QString path, bool start_task);
|
void scanPath(QString path, bool start_task);
|
||||||
void addHashTask(QString path);
|
void addHashTask(QString path);
|
||||||
|
@ -217,6 +217,7 @@ void LauncherPage::applySettings()
|
|||||||
s->set("CentralModsDir", ui->modsDirTextBox->text());
|
s->set("CentralModsDir", ui->modsDirTextBox->text());
|
||||||
s->set("IconsDir", ui->iconsDirTextBox->text());
|
s->set("IconsDir", ui->iconsDirTextBox->text());
|
||||||
s->set("DownloadsDir", ui->downloadsDirTextBox->text());
|
s->set("DownloadsDir", ui->downloadsDirTextBox->text());
|
||||||
|
s->set("DownloadsDirWatchRecursive", ui->downloadsDirWatchRecursiveCheckBox->isChecked());
|
||||||
|
|
||||||
auto sortMode = (InstSortMode)ui->sortingModeGroup->checkedId();
|
auto sortMode = (InstSortMode)ui->sortingModeGroup->checkedId();
|
||||||
switch (sortMode)
|
switch (sortMode)
|
||||||
@ -274,6 +275,7 @@ void LauncherPage::loadSettings()
|
|||||||
ui->modsDirTextBox->setText(s->get("CentralModsDir").toString());
|
ui->modsDirTextBox->setText(s->get("CentralModsDir").toString());
|
||||||
ui->iconsDirTextBox->setText(s->get("IconsDir").toString());
|
ui->iconsDirTextBox->setText(s->get("IconsDir").toString());
|
||||||
ui->downloadsDirTextBox->setText(s->get("DownloadsDir").toString());
|
ui->downloadsDirTextBox->setText(s->get("DownloadsDir").toString());
|
||||||
|
ui->downloadsDirWatchRecursiveCheckBox->setChecked(s->get("DownloadsDirWatchRecursive").toBool());
|
||||||
|
|
||||||
QString sortMode = s->get("InstSortMode").toString();
|
QString sortMode = s->get("InstSortMode").toString();
|
||||||
|
|
||||||
|
@ -67,19 +67,16 @@
|
|||||||
<string>Folders</string>
|
<string>Folders</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="foldersBoxLayout">
|
<layout class="QGridLayout" name="foldersBoxLayout">
|
||||||
<item row="0" column="2">
|
<item row="3" column="0">
|
||||||
<widget class="QToolButton" name="instDirBrowseBtn">
|
<widget class="QLabel" name="labelDownloadsDir">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">...</string>
|
<string>&Downloads:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>downloadsDirTextBox</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLineEdit" name="modsDirTextBox"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QLineEdit" name="instDirTextBox"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="labelInstDir">
|
<widget class="QLabel" name="labelInstDir">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -90,16 +87,25 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="instDirTextBox"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QLineEdit" name="downloadsDirTextBox"/>
|
||||||
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QLineEdit" name="iconsDirTextBox"/>
|
<widget class="QLineEdit" name="iconsDirTextBox"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
<item row="3" column="2">
|
||||||
<widget class="QToolButton" name="iconsDirBrowseBtn">
|
<widget class="QToolButton" name="downloadsDirBrowseBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">...</string>
|
<string notr="true">...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="modsDirTextBox"/>
|
||||||
|
</item>
|
||||||
<item row="1" column="2">
|
<item row="1" column="2">
|
||||||
<widget class="QToolButton" name="modsDirBrowseBtn">
|
<widget class="QToolButton" name="modsDirBrowseBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -117,6 +123,20 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QToolButton" name="instDirBrowseBtn">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QToolButton" name="iconsDirBrowseBtn">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="labelIconsDir">
|
<widget class="QLabel" name="labelIconsDir">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -127,23 +147,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="4" column="1" colspan="2">
|
||||||
<widget class="QLabel" name="labelDownloadsDir">
|
<widget class="QCheckBox" name="downloadsDirWatchRecursiveCheckBox">
|
||||||
<property name="text">
|
<property name="toolTip">
|
||||||
<string>&Downloads:</string>
|
<string>When enabled, in addition to the downloads folder, its sub folders will also be searched when looking for resources (e.g. when looking for blocked mods on CurseForge).</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy">
|
|
||||||
<cstring>downloadsDirTextBox</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QLineEdit" name="downloadsDirTextBox"/>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="2">
|
|
||||||
<widget class="QToolButton" name="downloadsDirBrowseBtn">
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>...</string>
|
<string>Check downloads folder recursively</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user