aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/modplatform/modpacksch/FTBPackInstallTask.cpp')
-rw-r--r--launcher/modplatform/modpacksch/FTBPackInstallTask.cpp151
1 files changed, 68 insertions, 83 deletions
diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
index 97ce1dc6..7b112d8f 100644
--- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
+++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
@@ -58,6 +58,9 @@ PackInstallTask::PackInstallTask(Modpack pack, QString version, QWidget* parent)
bool PackInstallTask::abort()
{
+ if (!canAbort())
+ return false;
+
bool aborted = true;
if (m_net_job)
@@ -65,15 +68,13 @@ bool PackInstallTask::abort()
if (m_mod_id_resolver_task)
aborted &= m_mod_id_resolver_task->abort();
- if (aborted)
- emitAborted();
-
- return aborted;
+ return aborted ? InstanceTask::abort() : false;
}
void PackInstallTask::executeTask()
{
setStatus(tr("Getting the manifest..."));
+ setAbortable(false);
// Find pack version
auto version_it = std::find_if(m_pack.versions.constBegin(), m_pack.versions.constEnd(),
@@ -93,10 +94,12 @@ void PackInstallTask::executeTask()
QObject::connect(netJob, &NetJob::succeeded, this, &PackInstallTask::onManifestDownloadSucceeded);
QObject::connect(netJob, &NetJob::failed, this, &PackInstallTask::onManifestDownloadFailed);
+ QObject::connect(netJob, &NetJob::aborted, this, &PackInstallTask::abort);
QObject::connect(netJob, &NetJob::progress, this, &PackInstallTask::setProgress);
m_net_job = netJob;
+ setAbortable(true);
netJob->start();
}
@@ -130,6 +133,7 @@ void PackInstallTask::onManifestDownloadSucceeded()
void PackInstallTask::resolveMods()
{
setStatus(tr("Resolving mods..."));
+ setAbortable(false);
setProgress(0, 100);
m_file_id_map.clear();
@@ -162,15 +166,16 @@ void PackInstallTask::resolveMods()
connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::succeeded, this, &PackInstallTask::onResolveModsSucceeded);
connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::failed, this, &PackInstallTask::onResolveModsFailed);
+ connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::aborted, this, &PackInstallTask::abort);
connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::progress, this, &PackInstallTask::setProgress);
+ setAbortable(true);
+
m_mod_id_resolver_task->start();
}
void PackInstallTask::onResolveModsSucceeded()
{
- m_abortable = false;
-
QString text;
QList<QUrl> urls;
auto anyBlocked = false;
@@ -209,94 +214,23 @@ void PackInstallTask::onResolveModsSucceeded()
urls);
if (message_dialog->exec() == QDialog::Accepted)
- downloadPack();
+ createInstance();
else
abort();
} else {
- downloadPack();
+ createInstance();
}
}
-void PackInstallTask::downloadPack()
+void PackInstallTask::createInstance()
{
- setStatus(tr("Downloading mods..."));
+ setAbortable(false);
- auto* jobPtr = new NetJob(tr("Mod download"), APPLICATION->network());
- for (auto const& file : m_version.files) {
- if (file.serverOnly || file.url.isEmpty())
- continue;
-
- QFileInfo file_info(file.name);
- auto cacheName = file_info.completeBaseName() + "-" + file.sha1 + "." + file_info.suffix();
-
- auto entry = APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", cacheName);
- entry->setStale(true);
-
- auto relpath = FS::PathCombine("minecraft", file.path, file.name);
- auto path = FS::PathCombine(m_stagingPath, relpath);
-
- if (m_files_to_copy.contains(path)) {
- qWarning() << "Ignoring" << file.url << "as a file of that path is already downloading.";
- continue;
- }
-
- qDebug() << "Will download" << file.url << "to" << path;
- m_files_to_copy[path] = entry->getFullPath();
-
- auto dl = Net::Download::makeCached(file.url, entry);
- if (!file.sha1.isEmpty()) {
- auto rawSha1 = QByteArray::fromHex(file.sha1.toLatin1());
- dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
- }
-
- jobPtr->addNetAction(dl);
- }
-
- connect(jobPtr, &NetJob::succeeded, this, &PackInstallTask::onModDownloadSucceeded);
- connect(jobPtr, &NetJob::failed, this, &PackInstallTask::onModDownloadFailed);
- connect(jobPtr, &NetJob::progress, this, &PackInstallTask::setProgress);
-
- m_net_job = jobPtr;
- jobPtr->start();
-
- m_abortable = true;
-}
-
-void PackInstallTask::onModDownloadSucceeded()
-{
- m_net_job.reset();
- install();
-}
-
-void PackInstallTask::install()
-{
- setStatus(tr("Copying modpack files..."));
- setProgress(0, m_files_to_copy.size());
- QCoreApplication::processEvents();
-
- m_abortable = false;
-
- int i = 0;
- for (auto iter = m_files_to_copy.constBegin(); iter != m_files_to_copy.constEnd(); iter++) {
- auto& to = iter.key();
- auto& from = iter.value();
- FS::copy fileCopyOperation(from, to);
- if (!fileCopyOperation()) {
- qWarning() << "Failed to copy" << from << "to" << to;
- emitFailed(tr("Failed to copy files"));
- return;
- }
-
- setProgress(i++, m_files_to_copy.size());
- QCoreApplication::processEvents();
- }
-
- setStatus(tr("Installing modpack..."));
+ setStatus(tr("Creating the instance..."));
QCoreApplication::processEvents();
auto instanceConfigPath = FS::PathCombine(m_stagingPath, "instance.cfg");
auto instanceSettings = std::make_shared<INISettingsObject>(instanceConfigPath);
- instanceSettings->suspendSave();
MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
auto components = instance.getPackProfile();
@@ -337,8 +271,55 @@ void PackInstallTask::install()
instance.setName(name());
instance.setIconKey(m_instIcon);
instance.setManagedPack("modpacksch", QString::number(m_pack.id), m_pack.name, QString::number(m_version.id), m_version.name);
- instanceSettings->resumeSave();
+ instance.saveNow();
+
+ onCreateInstanceSucceeded();
+}
+
+void PackInstallTask::onCreateInstanceSucceeded()
+{
+ downloadPack();
+}
+
+void PackInstallTask::downloadPack()
+{
+ setStatus(tr("Downloading mods..."));
+ setAbortable(false);
+
+ auto* jobPtr = new NetJob(tr("Mod download"), APPLICATION->network());
+ for (auto const& file : m_version.files) {
+ if (file.serverOnly || file.url.isEmpty())
+ continue;
+
+ auto path = FS::PathCombine(m_stagingPath, ".minecraft", file.path, file.name);
+ qDebug() << "Will try to download" << file.url << "to" << path;
+
+ QFileInfo file_info(file.name);
+
+ auto dl = Net::Download::makeFile(file.url, path);
+ if (!file.sha1.isEmpty()) {
+ auto rawSha1 = QByteArray::fromHex(file.sha1.toLatin1());
+ dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
+ }
+
+ jobPtr->addNetAction(dl);
+ }
+
+ connect(jobPtr, &NetJob::succeeded, this, &PackInstallTask::onModDownloadSucceeded);
+ connect(jobPtr, &NetJob::failed, this, &PackInstallTask::onModDownloadFailed);
+ connect(jobPtr, &NetJob::aborted, this, &PackInstallTask::abort);
+ connect(jobPtr, &NetJob::progress, this, &PackInstallTask::setProgress);
+
+ m_net_job = jobPtr;
+
+ setAbortable(true);
+ jobPtr->start();
+}
+
+void PackInstallTask::onModDownloadSucceeded()
+{
+ m_net_job.reset();
emitSucceeded();
}
@@ -352,6 +333,10 @@ void PackInstallTask::onResolveModsFailed(QString reason)
m_net_job.reset();
emitFailed(reason);
}
+void PackInstallTask::onCreateInstanceFailed(QString reason)
+{
+ emitFailed(reason);
+}
void PackInstallTask::onModDownloadFailed(QString reason)
{
m_net_job.reset();