clang_format and code cleanup
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
6010ce0dc5
commit
209a1650e4
@ -413,15 +413,14 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
|
|||||||
|
|
||||||
/// @brief copy the matched blocked mods to the instance staging area
|
/// @brief copy the matched blocked mods to the instance staging area
|
||||||
/// @param blocked_mods list of the blocked mods and their matched paths
|
/// @param blocked_mods list of the blocked mods and their matched paths
|
||||||
void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods) {
|
void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
|
||||||
|
{
|
||||||
setStatus(tr("Copying Blocked Mods..."));
|
setStatus(tr("Copying Blocked Mods..."));
|
||||||
setAbortable(false);
|
setAbortable(false);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int total = blocked_mods.length();
|
int total = blocked_mods.length();
|
||||||
setProgress(i, total);
|
setProgress(i, total);
|
||||||
for (auto &mod : blocked_mods) {
|
for (auto const& mod : blocked_mods) {
|
||||||
|
|
||||||
if (!mod.matched) {
|
if (!mod.matched) {
|
||||||
qDebug() << mod.name << "was not matched to a local file, skipping copy";
|
qDebug() << mod.name << "was not matched to a local file, skipping copy";
|
||||||
continue;
|
continue;
|
||||||
|
@ -353,31 +353,31 @@ void PackInstallTask::onModDownloadFailed(QString reason)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief copy the matched blocked mods to the instance staging area
|
/// @brief copy the matched blocked mods to the instance staging area
|
||||||
void PackInstallTask::copyBlockedMods() {
|
void PackInstallTask::copyBlockedMods()
|
||||||
|
{
|
||||||
setStatus(tr("Copying Blocked Mods..."));
|
setStatus(tr("Copying Blocked Mods..."));
|
||||||
setAbortable(false);
|
setAbortable(false);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int total = m_blocked_mods.length();
|
int total = m_blocked_mods.length();
|
||||||
setProgress(i, total);
|
setProgress(i, total);
|
||||||
for (auto mod = m_blocked_mods.begin(); mod != m_blocked_mods.end(); mod++, i++) {
|
for (auto const& mod : m_blocked_mods) {
|
||||||
|
if (!mod.matched) {
|
||||||
if (!mod->matched) {
|
qDebug() << mod.name << "was not matched to a local file, skipping copy";
|
||||||
qDebug() << mod->name << "was not matched to a local file, skipping copy";
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dest_path = FS::PathCombine(m_stagingPath, ".minecraft", "mods", mod->name);
|
auto dest_path = FS::PathCombine(m_stagingPath, ".minecraft", "mods", mod.name);
|
||||||
|
|
||||||
setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total)));
|
setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total)));
|
||||||
|
|
||||||
qDebug() << "Will try to copy" << mod->localPath << "to" << dest_path;
|
qDebug() << "Will try to copy" << mod.localPath << "to" << dest_path;
|
||||||
|
|
||||||
if (!FS::copy(mod->localPath, dest_path)()) {
|
if (!FS::copy(mod.localPath, dest_path)()) {
|
||||||
qDebug() << "Copy of" << mod->localPath << "to" << dest_path << "Failed";
|
qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
setProgress(i+1, total);
|
i++;
|
||||||
|
setProgress(i, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
setAbortable(true);
|
setAbortable(true);
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
#include "Application.h"
|
|
||||||
#include "BlockedModsDialog.h"
|
#include "BlockedModsDialog.h"
|
||||||
#include "ui_BlockedModsDialog.h"
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include "Application.h"
|
||||||
|
#include "ui_BlockedModsDialog.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods)
|
||||||
|
: QDialog(parent), ui(new Ui::BlockedModsDialog), mods(mods)
|
||||||
|
{
|
||||||
BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, QList<BlockedMod> &mods) :
|
|
||||||
QDialog(parent), ui(new Ui::BlockedModsDialog), mods(mods) {
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
auto openAllButton = ui->buttonBox->addButton(tr("Open All"), QDialogButtonBox::ActionRole);
|
auto openAllButton = ui->buttonBox->addButton(tr("Open All"), QDialogButtonBox::ActionRole);
|
||||||
@ -33,22 +31,25 @@ BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, cons
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockedModsDialog::~BlockedModsDialog() {
|
BlockedModsDialog::~BlockedModsDialog()
|
||||||
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockedModsDialog::openAll() {
|
void BlockedModsDialog::openAll()
|
||||||
for(auto &mod : mods) {
|
{
|
||||||
|
for (auto& mod : mods) {
|
||||||
QDesktopServices::openUrl(mod.websiteUrl);
|
QDesktopServices::openUrl(mod.websiteUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief update UI with current status of the blocked mod detection
|
/// @brief update UI with current status of the blocked mod detection
|
||||||
void BlockedModsDialog::update() {
|
void BlockedModsDialog::update()
|
||||||
|
{
|
||||||
QString text;
|
QString text;
|
||||||
QString span;
|
QString span;
|
||||||
|
|
||||||
for (auto &mod : mods) {
|
for (auto& mod : mods) {
|
||||||
if (mod.matched) {
|
if (mod.matched) {
|
||||||
// ✔ -> html for HEAVY CHECK MARK : ✔
|
// ✔ -> html for HEAVY CHECK MARK : ✔
|
||||||
span = QString(tr("<span style=\"color:green\"> ✔ Found at %1 </span>")).arg(mod.localPath);
|
span = QString(tr("<span style=\"color:green\"> ✔ Found at %1 </span>")).arg(mod.localPath);
|
||||||
@ -70,24 +71,25 @@ void BlockedModsDialog::update() {
|
|||||||
|
|
||||||
/// @brief Signal fired when a watched direcotry has changed
|
/// @brief Signal fired when a watched direcotry 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)
|
||||||
|
{
|
||||||
qDebug() << "Directory changed: " << path;
|
qDebug() << "Directory changed: " << path;
|
||||||
scanPath(path);
|
scanPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// @brief add the user downloads folder and the global mods folder to the filesystem watcher
|
/// @brief add the user downloads folder and the global mods folder to the filesystem watcher
|
||||||
void BlockedModsDialog::setupWatch() {
|
void BlockedModsDialog::setupWatch()
|
||||||
|
{
|
||||||
const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||||
const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString();
|
const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString();
|
||||||
watcher.addPath(downloadsFolder);
|
watcher.addPath(downloadsFolder);
|
||||||
watcher.addPath(modsFolder);
|
watcher.addPath(modsFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// @brief scan all watched folder
|
/// @brief scan all watched folder
|
||||||
void BlockedModsDialog::scanPaths() {
|
void BlockedModsDialog::scanPaths()
|
||||||
for (auto &dir : watcher.directories()) {
|
{
|
||||||
|
for (auto& dir : watcher.directories()) {
|
||||||
scanPath(dir);
|
scanPath(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,8 +97,8 @@ void BlockedModsDialog::scanPaths() {
|
|||||||
/// @brief Scan the directory at path, skip paths that do not contain a file name
|
/// @brief Scan the directory at path, skip paths that do not contain a file name
|
||||||
/// of a blocked mod we are looking for
|
/// of a blocked mod we are looking for
|
||||||
/// @param path the directory to scan
|
/// @param path the directory to scan
|
||||||
void BlockedModsDialog::scanPath(QString path) {
|
void BlockedModsDialog::scanPath(QString path)
|
||||||
|
{
|
||||||
QDir scan_dir(path);
|
QDir scan_dir(path);
|
||||||
QDirIterator scan_it(path, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::NoIteratorFlags);
|
QDirIterator scan_it(path, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::NoIteratorFlags);
|
||||||
while (scan_it.hasNext()) {
|
while (scan_it.hasNext()) {
|
||||||
@ -110,30 +112,26 @@ void BlockedModsDialog::scanPath(QString path) {
|
|||||||
|
|
||||||
qDebug() << "Creating Hash task for path: " << file;
|
qDebug() << "Creating Hash task for path: " << file;
|
||||||
|
|
||||||
connect(hash_task.get(), &Task::succeeded, [this, hash_task, file] {
|
connect(hash_task.get(), &Task::succeeded, [this, hash_task, file] { checkMatchHash(hash_task->getResult(), file); });
|
||||||
checkMatchHash(hash_task->getResult(), file);
|
connect(hash_task.get(), &Task::failed, [file] { qDebug() << "Failed to hash path: " << file; });
|
||||||
});
|
|
||||||
connect(hash_task.get(), &Task::failed, [this, hash_task, file] {
|
|
||||||
qDebug() << "Failed to hash path: " << file;
|
|
||||||
});
|
|
||||||
|
|
||||||
hashing_task->addTask(hash_task);
|
hashing_task->addTask(hash_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
hashing_task->start();
|
hashing_task->start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief check if the computed hash for the provided path matches a blocked
|
/// @brief check if the computed hash for the provided path matches a blocked
|
||||||
/// mod we are looking for
|
/// mod we are looking for
|
||||||
/// @param hash the computed hash for the provided path
|
/// @param hash the computed hash for the provided path
|
||||||
/// @param path the path to the local file being compared
|
/// @param path the path to the local file being compared
|
||||||
void BlockedModsDialog::checkMatchHash(QString hash, QString path) {
|
void BlockedModsDialog::checkMatchHash(QString hash, QString path)
|
||||||
|
{
|
||||||
bool match = false;
|
bool match = false;
|
||||||
|
|
||||||
qDebug() << "Checking for match on hash: " << hash << " | From path:" << path;
|
qDebug() << "Checking for match on hash: " << hash << "| From path:" << path;
|
||||||
|
|
||||||
for (auto &mod : mods) {
|
for (auto& mod : mods) {
|
||||||
if (mod.matched) {
|
if (mod.matched) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -142,7 +140,7 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path) {
|
|||||||
mod.localPath = path;
|
mod.localPath = path;
|
||||||
match = true;
|
match = true;
|
||||||
|
|
||||||
qDebug() << "Hash match found: " << mod.name << " " << hash << " | From path:" << path;
|
qDebug() << "Hash match found:" << mod.name << hash << "| From path:" << path;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -156,14 +154,14 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path) {
|
|||||||
/// @brief Check if the name of the file at path matches the name of a blocked mod we are searching for
|
/// @brief Check if the name of the file at path matches the name of a blocked mod we are searching for
|
||||||
/// @param path the path to check
|
/// @param path the path to check
|
||||||
/// @return boolean: did the path match the name of a blocked mod?
|
/// @return boolean: did the path match the name of a blocked mod?
|
||||||
bool BlockedModsDialog::checkValidPath(QString path) {
|
bool BlockedModsDialog::checkValidPath(QString path)
|
||||||
|
{
|
||||||
QFileInfo file = QFileInfo(path);
|
QFileInfo file = QFileInfo(path);
|
||||||
QString filename = file.fileName();
|
QString filename = file.fileName();
|
||||||
|
|
||||||
for (auto &mod : mods) {
|
for (auto& mod : mods) {
|
||||||
if (mod.name.compare(filename, Qt::CaseInsensitive) == 0) {
|
if (mod.name.compare(filename, Qt::CaseInsensitive) == 0) {
|
||||||
qDebug() << "Name match found: " << mod.name << " | From path:" << path;
|
qDebug() << "Name match found:" << mod.name << "| From path:" << path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,21 +169,18 @@ bool BlockedModsDialog::checkValidPath(QString path) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlockedModsDialog::allModsMatched() {
|
bool BlockedModsDialog::allModsMatched()
|
||||||
for (auto &mod : mods) {
|
{
|
||||||
if (!mod.matched)
|
return std::all_of(mods.begin(), mods.end(), [](auto const& mod) { return mod.matched; });
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// qDebug print support for the BlockedMod struct
|
/// qDebug print support for the BlockedMod struct
|
||||||
QDebug operator<<(QDebug debug, const BlockedMod &m) {
|
QDebug operator<<(QDebug debug, const BlockedMod& m)
|
||||||
|
{
|
||||||
QDebugStateSaver saver(debug);
|
QDebugStateSaver saver(debug);
|
||||||
|
|
||||||
debug.nospace() << "{ name: " << m.name << ", websiteUrl: " << m.websiteUrl
|
debug.nospace() << "{ name: " << m.name << ", websiteUrl: " << m.websiteUrl << ", hash: " << m.hash << ", matched: " << m.matched
|
||||||
<< ", hash: " << m.hash << ", matched: " << m.matched
|
<< ", localPath: " << m.localPath << "}";
|
||||||
<< ", localPath: " << m.localPath <<"}";
|
|
||||||
|
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user