aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/modplatform')
-rw-r--r--launcher/modplatform/flame/FlameInstanceCreationTask.cpp54
-rw-r--r--launcher/modplatform/flame/FlameInstanceCreationTask.h3
-rw-r--r--launcher/modplatform/helpers/HashUtils.cpp58
-rw-r--r--launcher/modplatform/helpers/HashUtils.h15
-rw-r--r--launcher/modplatform/modpacksch/FTBPackInstallTask.cpp60
-rw-r--r--launcher/modplatform/modpacksch/FTBPackInstallTask.h3
6 files changed, 176 insertions, 17 deletions
diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
index 48ac02e0..f0fbdc96 100644
--- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
+++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
@@ -372,13 +372,20 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
auto results = m_mod_id_resolver->getResults();
// first check for blocked mods
- QString text;
- QList<QUrl> urls;
+ QList<BlockedMod> blocked_mods;
auto anyBlocked = false;
for (const auto& result : results.files.values()) {
if (!result.resolved || result.url.isEmpty()) {
- text += QString("%1: <a href='%2'>%2</a><br/>").arg(result.fileName, result.websiteUrl);
- urls.append(QUrl(result.websiteUrl));
+
+ BlockedMod blocked_mod;
+ blocked_mod.name = result.fileName;
+ blocked_mod.websiteUrl = result.websiteUrl;
+ blocked_mod.hash = result.hash;
+ blocked_mod.matched = false;
+ blocked_mod.localPath = "";
+
+ blocked_mods.append(blocked_mod);
+
anyBlocked = true;
}
}
@@ -388,11 +395,12 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
auto message_dialog = new BlockedModsDialog(m_parent, tr("Blocked mods found"),
tr("The following mods were blocked on third party launchers.<br/>"
"You will need to manually download them and add them to the modpack"),
- text,
- urls);
+ blocked_mods);
message_dialog->setModal(true);
if (message_dialog->exec()) {
+ qDebug() << "Post dialog blocked mods list: " << blocked_mods;
+ copyBlockedMods(blocked_mods);
setupDownloadJob(loop);
} else {
m_mod_id_resolver.reset();
@@ -404,6 +412,38 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
}
}
+/// @brief copy the matched blocked mods to the instance staging area
+/// @param blocked_mods list of the blocked mods and their matched paths
+void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
+{
+ setStatus(tr("Copying Blocked Mods..."));
+ setAbortable(false);
+ int i = 0;
+ int total = blocked_mods.length();
+ setProgress(i, total);
+ for (auto const& mod : blocked_mods) {
+ if (!mod.matched) {
+ qDebug() << mod.name << "was not matched to a local file, skipping copy";
+ continue;
+ }
+
+ 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)));
+
+ qDebug() << "Will try to copy" << mod.localPath << "to" << dest_path;
+
+ if (!FS::copy(mod.localPath, dest_path)()) {
+ qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed";
+ }
+
+ i++;
+ setProgress(i, total);
+ }
+
+ setAbortable(true);
+}
+
void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
{
m_files_job = new NetJob(tr("Mod download"), APPLICATION->network());
@@ -449,7 +489,7 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
m_files_job.reset();
setError(reason);
});
- connect(m_files_job.get(), &NetJob::progress, [&](qint64 current, qint64 total) { setProgress(current, total); });
+ connect(m_files_job.get(), &NetJob::progress, this, &FlameCreationTask::setProgress);
connect(m_files_job.get(), &NetJob::finished, &loop, &QEventLoop::quit);
setStatus(tr("Downloading mods..."));
diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.h b/launcher/modplatform/flame/FlameInstanceCreationTask.h
index ded0e2ce..fbc7d5bf 100644
--- a/launcher/modplatform/flame/FlameInstanceCreationTask.h
+++ b/launcher/modplatform/flame/FlameInstanceCreationTask.h
@@ -10,6 +10,8 @@
#include "net/NetJob.h"
+#include "ui/dialogs/BlockedModsDialog.h"
+
class FlameCreationTask final : public InstanceCreationTask {
Q_OBJECT
@@ -29,6 +31,7 @@ class FlameCreationTask final : public InstanceCreationTask {
private slots:
void idResolverSucceeded(QEventLoop&);
void setupDownloadJob(QEventLoop&);
+ void copyBlockedMods(QList<BlockedMod> const& blocked_mods);
private:
QWidget* m_parent = nullptr;
diff --git a/launcher/modplatform/helpers/HashUtils.cpp b/launcher/modplatform/helpers/HashUtils.cpp
index b18c87af..f1e4759e 100644
--- a/launcher/modplatform/helpers/HashUtils.cpp
+++ b/launcher/modplatform/helpers/HashUtils.cpp
@@ -36,6 +36,18 @@ Hasher::Ptr createFlameHasher(QString file_path)
return new FlameHasher(file_path);
}
+Hasher::Ptr createBlockedModHasher(QString file_path, ModPlatform::Provider provider)
+{
+ return new BlockedModHasher(file_path, provider);
+}
+
+Hasher::Ptr createBlockedModHasher(QString file_path, ModPlatform::Provider provider, QString type)
+{
+ auto hasher = new BlockedModHasher(file_path, provider);
+ hasher->useHashType(type);
+ return hasher;
+}
+
void ModrinthHasher::executeTask()
{
QFile file(m_path);
@@ -79,4 +91,50 @@ void FlameHasher::executeTask()
}
}
+
+BlockedModHasher::BlockedModHasher(QString file_path, ModPlatform::Provider provider)
+ : Hasher(file_path), provider(provider) {
+ setObjectName(QString("BlockedModHasher: %1").arg(file_path));
+ hash_type = ProviderCaps.hashType(provider).first();
+}
+
+void BlockedModHasher::executeTask()
+{
+ QFile file(m_path);
+
+ try {
+ file.open(QFile::ReadOnly);
+ } catch (FS::FileSystemException& e) {
+ qCritical() << QString("Failed to open JAR file in %1").arg(m_path);
+ qCritical() << QString("Reason: ") << e.cause();
+
+ emitFailed("Failed to open file for hashing.");
+ return;
+ }
+
+ m_hash = ProviderCaps.hash(provider, &file, hash_type);
+
+ file.close();
+
+ if (m_hash.isEmpty()) {
+ emitFailed("Empty hash!");
+ } else {
+ emitSucceeded();
+ }
+}
+
+QStringList BlockedModHasher::getHashTypes() {
+ return ProviderCaps.hashType(provider);
+}
+
+bool BlockedModHasher::useHashType(QString type) {
+ auto types = ProviderCaps.hashType(provider);
+ if (types.contains(type)) {
+ hash_type = type;
+ return true;
+ }
+ qDebug() << "Bad hash type " << type << " for provider";
+ return false;
+}
+
} // namespace Hashing
diff --git a/launcher/modplatform/helpers/HashUtils.h b/launcher/modplatform/helpers/HashUtils.h
index 38fddf03..fa3244f6 100644
--- a/launcher/modplatform/helpers/HashUtils.h
+++ b/launcher/modplatform/helpers/HashUtils.h
@@ -40,8 +40,23 @@ class ModrinthHasher : public Hasher {
void executeTask() override;
};
+class BlockedModHasher : public Hasher {
+ public:
+ BlockedModHasher(QString file_path, ModPlatform::Provider provider);
+
+ void executeTask() override;
+
+ QStringList getHashTypes();
+ bool useHashType(QString type);
+ private:
+ ModPlatform::Provider provider;
+ QString hash_type;
+};
+
Hasher::Ptr createHasher(QString file_path, ModPlatform::Provider provider);
Hasher::Ptr createFlameHasher(QString file_path);
Hasher::Ptr createModrinthHasher(QString file_path);
+Hasher::Ptr createBlockedModHasher(QString file_path, ModPlatform::Provider provider);
+Hasher::Ptr createBlockedModHasher(QString file_path, ModPlatform::Provider provider, QString type);
} // namespace Hashing
diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
index 7b112d8f..40aee82b 100644
--- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
+++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
@@ -176,8 +176,6 @@ void PackInstallTask::resolveMods()
void PackInstallTask::onResolveModsSucceeded()
{
- QString text;
- QList<QUrl> urls;
auto anyBlocked = false;
Flame::Manifest results = m_mod_id_resolver_task->getResults();
@@ -191,11 +189,16 @@ void PackInstallTask::onResolveModsSucceeded()
// First check for blocked mods
if (!results_file.resolved || results_file.url.isEmpty()) {
- QString type(local_file.type);
- type[0] = type[0].toUpper();
- text += QString("%1: %2 - <a href='%3'>%3</a><br/>").arg(type, local_file.name, results_file.websiteUrl);
- urls.append(QUrl(results_file.websiteUrl));
+ BlockedMod blocked_mod;
+ blocked_mod.name = local_file.name;
+ blocked_mod.websiteUrl = results_file.websiteUrl;
+ blocked_mod.hash = results_file.hash;
+ blocked_mod.matched = false;
+ blocked_mod.localPath = "";
+
+ m_blocked_mods.append(blocked_mod);
+
anyBlocked = true;
} else {
local_file.url = results_file.url.toString();
@@ -210,13 +213,16 @@ void PackInstallTask::onResolveModsSucceeded()
auto message_dialog = new BlockedModsDialog(m_parent, tr("Blocked files found"),
tr("The following files are not available for download in third party launchers.<br/>"
"You will need to manually download them and add them to the instance."),
- text,
- urls);
+ m_blocked_mods);
- if (message_dialog->exec() == QDialog::Accepted)
+ if (message_dialog->exec() == QDialog::Accepted) {
+ qDebug() << "Post dialog blocked mods list: " << m_blocked_mods;
createInstance();
- else
+ }
+ else {
abort();
+ }
+
} else {
createInstance();
}
@@ -320,6 +326,9 @@ void PackInstallTask::downloadPack()
void PackInstallTask::onModDownloadSucceeded()
{
m_net_job.reset();
+ if (!m_blocked_mods.isEmpty()) {
+ copyBlockedMods();
+ }
emitSucceeded();
}
@@ -343,4 +352,35 @@ void PackInstallTask::onModDownloadFailed(QString reason)
emitFailed(reason);
}
+/// @brief copy the matched blocked mods to the instance staging area
+void PackInstallTask::copyBlockedMods()
+{
+ setStatus(tr("Copying Blocked Mods..."));
+ setAbortable(false);
+ int i = 0;
+ int total = m_blocked_mods.length();
+ setProgress(i, total);
+ for (auto const& mod : m_blocked_mods) {
+ if (!mod.matched) {
+ qDebug() << mod.name << "was not matched to a local file, skipping copy";
+ continue;
+ }
+
+ 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)));
+
+ qDebug() << "Will try to copy" << mod.localPath << "to" << dest_path;
+
+ if (!FS::copy(mod.localPath, dest_path)()) {
+ qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed";
+ }
+
+ i++;
+ setProgress(i, total);
+ }
+
+ setAbortable(true);
+}
+
} // namespace ModpacksCH
diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h
index 7c6fbeb9..2cd4d729 100644
--- a/launcher/modplatform/modpacksch/FTBPackInstallTask.h
+++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h
@@ -43,6 +43,7 @@
#include "QObjectPtr.h"
#include "modplatform/flame/FileResolvingTask.h"
#include "net/NetJob.h"
+#include "ui/dialogs/BlockedModsDialog.h"
#include <QWidget>
@@ -76,6 +77,7 @@ private:
void resolveMods();
void createInstance();
void downloadPack();
+ void copyBlockedMods();
private:
NetJob::Ptr m_net_job = nullptr;
@@ -90,6 +92,7 @@ private:
Version m_version;
QMap<QString, QString> m_files_to_copy;
+ QList<BlockedMod> m_blocked_mods;
//FIXME: nuke
QWidget* m_parent;