aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--launcher/FileSystem.cpp22
-rw-r--r--launcher/FileSystem.h2
-rw-r--r--launcher/modplatform/flame/FlameInstanceCreationTask.cpp35
-rw-r--r--launcher/modplatform/flame/FlameInstanceCreationTask.h3
-rw-r--r--launcher/modplatform/modpacksch/FTBPackInstallTask.cpp46
-rw-r--r--launcher/modplatform/modpacksch/FTBPackInstallTask.h3
-rw-r--r--launcher/ui/dialogs/BlockedModsDialog.cpp7
-rw-r--r--launcher/ui/dialogs/BlockedModsDialog.h1
-rw-r--r--launcher/ui/dialogs/BlockedModsDialog.ui37
9 files changed, 137 insertions, 19 deletions
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp
index 4026d6c1..4285fa87 100644
--- a/launcher/FileSystem.cpp
+++ b/launcher/FileSystem.cpp
@@ -163,6 +163,28 @@ bool ensureFolderPathExists(QString foldernamepath)
return success;
}
+bool copyFile(QString &src, QString &dst) {
+ using copy_opts = fs::copy_options;
+
+ std::error_code err;
+
+ fs::copy_options opt = copy_opts::none;
+ // The default behavior is to follow symlinks
+ opt |= copy_opts::copy_symlinks;
+
+ ensureFilePathExists(dst);
+
+ fs::copy(toStdString(src), toStdString(dst), opt, err);
+ if (err) {
+ qWarning() << "Failed to copy files:" << QString::fromStdString(err.message());
+ qDebug() << "Source file:" << src;
+ qDebug() << "Destination file:" << dst;
+ }
+
+ return err.value() == 0;
+
+}
+
bool copy::operator()(const QString& offset)
{
using copy_opts = fs::copy_options;
diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h
index b46f3281..68f6bc4c 100644
--- a/launcher/FileSystem.h
+++ b/launcher/FileSystem.h
@@ -75,6 +75,8 @@ bool ensureFilePathExists(QString filenamepath);
*/
bool ensureFolderPathExists(QString filenamepath);
+bool copyFile(QString &src, QString &dst);
+
class copy {
public:
copy(const QString& src, const QString& dst)
diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
index 15e660a9..fbc4ecf3 100644
--- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
+++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
@@ -399,6 +399,7 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
message_dialog->setModal(true);
if (message_dialog->exec()) {
+ copyBlockedMods(blocked_mods);
setupDownloadJob(loop);
} else {
m_mod_id_resolver.reset();
@@ -410,6 +411,36 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
}
}
+void FlameCreationTask::copyBlockedMods(QList<BlockedMod> blocked_mods) {
+
+ setStatus(tr("Copying Blocked Mods..."));
+ setAbortable(false);
+ int i = 0;
+ int total = blocked_mods.length();
+ setProgress(i, total);
+ for (auto mod = blocked_mods.begin(); mod != blocked_mods.end(); mod++, i++) {
+
+ 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::copyFile(mod->localPath, dest_path)) {
+ qDebug() << "Copy of" << mod->localPath << "to" << dest_path << "Failed";
+ }
+
+ setProgress(i+1, total);
+ }
+
+ setAbortable(true);
+}
+
void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
{
m_files_job = new NetJob(tr("Mod download"), APPLICATION->network());
@@ -455,7 +486,9 @@ 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, [&](qint64 current, qint64 total) {
+ setProgress(current, total);
+ });
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..69a8f1ab 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> blocked_mods);
private:
QWidget* m_parent = nullptr;
diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
index 75fda208..f6bf2488 100644
--- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
+++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
@@ -176,7 +176,6 @@ void PackInstallTask::resolveMods()
void PackInstallTask::onResolveModsSucceeded()
{
- QList<BlockedMod> blocked_mods;
auto anyBlocked = false;
Flame::Manifest results = m_mod_id_resolver_task->getResults();
@@ -201,7 +200,7 @@ void PackInstallTask::onResolveModsSucceeded()
blocked_mod.matched = false;
blocked_mod.localPath = "";
- blocked_mods.append(blocked_mod);
+ m_blocked_mods.append(blocked_mod);
anyBlocked = true;
} else {
@@ -217,12 +216,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."),
- blocked_mods);
+ m_blocked_mods);
- if (message_dialog->exec() == QDialog::Accepted)
+ if (message_dialog->exec() == QDialog::Accepted) {
+ qDebug() << "Post dialog mods list: " << m_blocked_mods;
createInstance();
- else
+ }
+ else {
abort();
+ }
+
} else {
createInstance();
}
@@ -326,6 +329,9 @@ void PackInstallTask::downloadPack()
void PackInstallTask::onModDownloadSucceeded()
{
m_net_job.reset();
+ if (m_blocked_mods.length() > 0) {
+ copyBlockedMods();
+ }
emitSucceeded();
}
@@ -349,4 +355,34 @@ void PackInstallTask::onModDownloadFailed(QString reason)
emitFailed(reason);
}
+void PackInstallTask::copyBlockedMods() {
+
+ setStatus(tr("Copying Blocked Mods..."));
+ setAbortable(false);
+ int i = 0;
+ int total = m_blocked_mods.length();
+ setProgress(i, total);
+ for (auto mod = m_blocked_mods.begin(); mod != m_blocked_mods.end(); mod++, i++) {
+
+ 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::copyFile(mod->localPath, dest_path)) {
+ qDebug() << "Copy of" << mod->localPath << "to" << dest_path << "Failed";
+ }
+
+ setProgress(i+1, 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;
diff --git a/launcher/ui/dialogs/BlockedModsDialog.cpp b/launcher/ui/dialogs/BlockedModsDialog.cpp
index 9ba033d7..542d0681 100644
--- a/launcher/ui/dialogs/BlockedModsDialog.cpp
+++ b/launcher/ui/dialogs/BlockedModsDialog.cpp
@@ -31,6 +31,7 @@ BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, cons
this->setWindowTitle(title);
ui->label->setText(text);
+ ui->labelModsFound->setText("Please download the missing mods.");
update();
}
@@ -60,6 +61,12 @@ void BlockedModsDialog::update() {
}
ui->textBrowser->setText(text);
+
+ if (allModsMatched()) {
+ ui->labelModsFound->setText("All mods found ✔");
+ } else {
+ ui->labelModsFound->setText("Please download the missing mods.");
+ }
}
void BlockedModsDialog::directoryChanged(QString path) {
diff --git a/launcher/ui/dialogs/BlockedModsDialog.h b/launcher/ui/dialogs/BlockedModsDialog.h
index f1ea99ca..93b9f46a 100644
--- a/launcher/ui/dialogs/BlockedModsDialog.h
+++ b/launcher/ui/dialogs/BlockedModsDialog.h
@@ -51,3 +51,4 @@ private:
bool allModsMatched();
};
+QDebug operator<<(QDebug debug, const BlockedMod &m); \ No newline at end of file
diff --git a/launcher/ui/dialogs/BlockedModsDialog.ui b/launcher/ui/dialogs/BlockedModsDialog.ui
index f4ae95b6..371549cf 100644
--- a/launcher/ui/dialogs/BlockedModsDialog.ui
+++ b/launcher/ui/dialogs/BlockedModsDialog.ui
@@ -13,8 +13,8 @@
<property name="windowTitle">
<string notr="true">BlockedModsDialog</string>
</property>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
<widget class="QLabel" name="label">
<property name="text">
<string notr="true"/>
@@ -24,17 +24,7 @@
</property>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
+ <item>
<widget class="QTextBrowser" name="textBrowser">
<property name="acceptRichText">
<bool>true</bool>
@@ -44,6 +34,27 @@
</property>
</widget>
</item>
+ <item>
+ <layout class="QHBoxLayout" name="bottomBoxH">
+ <item>
+ <widget class="QLabel" name="labelModsFound">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
<resources/>