aboutsummaryrefslogtreecommitdiff
path: root/launcher/InstanceCreationTask.cpp
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-09-26 08:25:12 -0300
committerGitHub <noreply@github.com>2022-09-26 08:25:12 -0300
commit370c3aa5985698351e706e61c660a3a566a5f09b (patch)
tree5bd62ceec118396d676cf3799edafdb806e4375d /launcher/InstanceCreationTask.cpp
parent58a5331f7bafb149c18f560a0363daab65521262 (diff)
parentdd6f670dec7dfd1a9ad6f4595ad5447ac735c737 (diff)
downloadPrismLauncher-370c3aa5985698351e706e61c660a3a566a5f09b.tar.gz
PrismLauncher-370c3aa5985698351e706e61c660a3a566a5f09b.tar.bz2
PrismLauncher-370c3aa5985698351e706e61c660a3a566a5f09b.zip
Merge pull request #894 from flowln/update_from_external_source
epic PR
Diffstat (limited to 'launcher/InstanceCreationTask.cpp')
-rw-r--r--launcher/InstanceCreationTask.cpp78
1 files changed, 47 insertions, 31 deletions
diff --git a/launcher/InstanceCreationTask.cpp b/launcher/InstanceCreationTask.cpp
index e01bf306..3971effa 100644
--- a/launcher/InstanceCreationTask.cpp
+++ b/launcher/InstanceCreationTask.cpp
@@ -1,40 +1,56 @@
#include "InstanceCreationTask.h"
-#include "settings/INISettingsObject.h"
-#include "FileSystem.h"
-//FIXME: remove this
-#include "minecraft/MinecraftInstance.h"
-#include "minecraft/PackProfile.h"
+#include <QDebug>
+#include <QFile>
-InstanceCreationTask::InstanceCreationTask(BaseVersionPtr version)
-{
- m_version = version;
- m_usingLoader = false;
-}
-
-InstanceCreationTask::InstanceCreationTask(BaseVersionPtr version, QString loader, BaseVersionPtr loaderVersion)
-{
- m_version = version;
- m_usingLoader = true;
- m_loader = loader;
- m_loaderVersion = loaderVersion;
-}
+InstanceCreationTask::InstanceCreationTask() = default;
void InstanceCreationTask::executeTask()
{
- setStatus(tr("Creating instance from version %1").arg(m_version->name()));
- {
- auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(m_stagingPath, "instance.cfg"));
- instanceSettings->suspendSave();
- MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath);
- auto components = inst.getPackProfile();
- components->buildingFromScratch();
- components->setComponentVersion("net.minecraft", m_version->descriptor(), true);
- if(m_usingLoader)
- components->setComponentVersion(m_loader, m_loaderVersion->descriptor());
- inst.setName(m_instName);
- inst.setIconKey(m_instIcon);
- instanceSettings->resumeSave();
+ setAbortable(true);
+
+ if (updateInstance()) {
+ emitSucceeded();
+ return;
+ }
+
+ // When the user aborted in the update stage.
+ if (m_abort) {
+ emitAborted();
+ return;
}
+
+ if (!createInstance()) {
+ if (m_abort)
+ return;
+
+ qWarning() << "Instance creation failed!";
+ if (!m_error_message.isEmpty())
+ qWarning() << "Reason: " << m_error_message;
+ emitFailed(tr("Error while creating new instance."));
+ return;
+ }
+
+ // If this is set, it means we're updating an instance. So, we now need to remove the
+ // files scheduled to, and we'd better not let the user abort in the middle of it, since it'd
+ // put the instance in an invalid state.
+ if (shouldOverride()) {
+ setAbortable(false);
+ setStatus(tr("Removing old conflicting files..."));
+ qDebug() << "Removing old files";
+
+ for (auto path : m_files_to_remove) {
+ if (!QFile::exists(path))
+ continue;
+ qDebug() << "Removing" << path;
+ if (!QFile::remove(path)) {
+ qCritical() << "Couldn't remove the old conflicting files.";
+ emitFailed(tr("Failed to remove old conflicting files."));
+ return;
+ }
+ }
+ }
+
emitSucceeded();
+ return;
}