diff options
author | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2022-10-25 20:18:14 -0700 |
---|---|---|
committer | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2022-11-01 04:24:11 -0700 |
commit | e9d4793b1e98944dad910b3952c117bb2d3369de (patch) | |
tree | 220af12faafe97d903d5c2298befee2aee91f050 /launcher/ui | |
parent | 13c7efa0584caf34950a6e6efa4b8e3bee16d764 (diff) | |
download | PrismLauncher-e9d4793b1e98944dad910b3952c117bb2d3369de.tar.gz PrismLauncher-e9d4793b1e98944dad910b3952c117bb2d3369de.tar.bz2 PrismLauncher-e9d4793b1e98944dad910b3952c117bb2d3369de.zip |
minor clean up and add some docs
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'launcher/ui')
-rw-r--r-- | launcher/ui/dialogs/BlockedModsDialog.cpp | 42 | ||||
-rw-r--r-- | launcher/ui/dialogs/BlockedModsDialog.h | 5 |
2 files changed, 27 insertions, 20 deletions
diff --git a/launcher/ui/dialogs/BlockedModsDialog.cpp b/launcher/ui/dialogs/BlockedModsDialog.cpp index 542d0681..f5bc7f73 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.cpp +++ b/launcher/ui/dialogs/BlockedModsDialog.cpp @@ -1,5 +1,3 @@ -#include <qfileinfo.h> -#include <qnamespace.h> #include "Application.h" #include "BlockedModsDialog.h" #include "ui_BlockedModsDialog.h" @@ -27,7 +25,7 @@ BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, cons qDebug() << "Mods List: " << mods; setupWatch(); - scanPaths(true); + scanPaths(); this->setWindowTitle(title); ui->label->setText(text); @@ -45,6 +43,7 @@ void BlockedModsDialog::openAll() { } } +/// @brief update UI with current status of the blocked mod detection void BlockedModsDialog::update() { QString text; QString span; @@ -69,12 +68,15 @@ void BlockedModsDialog::update() { } } +/// @brief Signal fired when a watched direcotry has changed +/// @param path the path to the changed directory void BlockedModsDialog::directoryChanged(QString path) { qDebug() << "Directory changed: " << path; - scanPath(path, false); + scanPath(path); } +/// @brief add the user downloads folder and the global mods folder to the filesystem watcher void BlockedModsDialog::setupWatch() { const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString(); @@ -82,23 +84,24 @@ void BlockedModsDialog::setupWatch() { watcher.addPath(modsFolder); } -void BlockedModsDialog::scanPaths(bool init) { + +/// @brief scan all watched folder +void BlockedModsDialog::scanPaths() { for (auto &dir : watcher.directories()) { - scanPath(dir, init); + scanPath(dir); } } -void BlockedModsDialog::scanPath(QString path, bool init) { +/// @brief Scan the directory at path, skip paths that do not contain a file name +/// of a blocked mod we are looking for +/// @param path the directory to scan +void BlockedModsDialog::scanPath(QString path) { QDir scan_dir(path); QDirIterator scan_it(path, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::NoIteratorFlags); while (scan_it.hasNext()) { QString file = scan_it.next(); - if (checked_paths.contains(file)){ - continue; - } - if (!checkValidPath(file)) { continue; } @@ -113,10 +116,6 @@ void BlockedModsDialog::scanPath(QString path, bool init) { connect(hash_task.get(), &Task::failed, [this, hash_task, file] { qDebug() << "Failed to hash path: " << file; }); - - if (init) { - checked_paths.insert(file); - } hashing_task->addTask(hash_task); } @@ -125,6 +124,10 @@ void BlockedModsDialog::scanPath(QString path, bool init) { } +/// @brief check if the conputed hash for the provided path matches a blocked +/// mod we are looking for +/// @param hash the computed hash for the provided path +/// @param path the path to the local file being compared void BlockedModsDialog::checkMatchHash(QString hash, QString path) { bool match = false; @@ -150,6 +153,9 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path) { } } +/// @brief Check if the name of the file at path matches the naem of a blocked mod we are searching for +/// @param path the path to check +/// @return boolean: did the path match the name of a blocked mod? bool BlockedModsDialog::checkValidPath(QString path) { QFileInfo file = QFileInfo(path); @@ -165,6 +171,8 @@ bool BlockedModsDialog::checkValidPath(QString path) { return false; } +/// @brief have we found all the mods we're lookign for? +/// @return boolean bool BlockedModsDialog::allModsMatched() { for (auto &mod : mods) { if (!mod.matched) @@ -173,7 +181,7 @@ bool BlockedModsDialog::allModsMatched() { return true; } - +/// qDebug print support for the BlockedMod struct QDebug operator<<(QDebug debug, const BlockedMod &m) { QDebugStateSaver saver(debug); @@ -182,4 +190,4 @@ QDebug operator<<(QDebug debug, const BlockedMod &m) { << ", localPath: " << m.localPath <<"}"; return debug; -}
\ No newline at end of file +} diff --git a/launcher/ui/dialogs/BlockedModsDialog.h b/launcher/ui/dialogs/BlockedModsDialog.h index 93b9f46a..cf1d3b3d 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.h +++ b/launcher/ui/dialogs/BlockedModsDialog.h @@ -37,14 +37,13 @@ private: QList<BlockedMod> &mods; QFileSystemWatcher watcher; shared_qobject_ptr<ConcurrentTask> hashing_task; - QSet<QString> checked_paths; void openAll(); void update(); void directoryChanged(QString path); void setupWatch(); - void scanPaths(bool init); - void scanPath(QString path, bool init); + void scanPaths(); + void scanPath(QString path); void checkMatchHash(QString hash, QString path); bool checkValidPath(QString path); |