mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
feat: download game files during instance creation
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
aa9896031d
commit
625f0060a1
5 changed files with 54 additions and 11 deletions
|
|
@ -2,7 +2,23 @@
|
|||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include "FileSystem.h"
|
||||
|
||||
#include "minecraft/MinecraftLoadAndCheck.h"
|
||||
#include "tasks/SequentialTask.h"
|
||||
|
||||
bool InstanceCreationTask::abort()
|
||||
{
|
||||
if (!canAbort()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_abort = true;
|
||||
if (m_gameFilesTask) {
|
||||
return m_gameFilesTask->abort();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InstanceCreationTask::executeTask()
|
||||
{
|
||||
|
|
@ -19,7 +35,8 @@ void InstanceCreationTask::executeTask()
|
|||
return;
|
||||
}
|
||||
|
||||
if (!createInstance()) {
|
||||
m_instance = createInstance();
|
||||
if (!m_instance) {
|
||||
if (m_abort)
|
||||
return;
|
||||
|
||||
|
|
@ -61,6 +78,32 @@ void InstanceCreationTask::executeTask()
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (!m_abort)
|
||||
emitSucceeded();
|
||||
|
||||
if (!m_abort) {
|
||||
setAbortable(true);
|
||||
setStatus(tr("Downloading game files"));
|
||||
qDebug() << "Downloading game files";
|
||||
|
||||
auto updateTasks = m_instance->createUpdateTask();
|
||||
if (updateTasks.isEmpty()) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
auto task = makeShared<SequentialTask>();
|
||||
task->addTask(makeShared<MinecraftLoadAndCheck>(m_instance.get(), Net::Mode::Online));
|
||||
for (const auto& t : updateTasks) {
|
||||
task->addTask(t);
|
||||
}
|
||||
connect(task.get(), &Task::finished, this, [this, task] {
|
||||
if (task->wasSuccessful() || m_abort) {
|
||||
emitSucceeded();
|
||||
} else {
|
||||
emitFailed(tr("Could not download game files: %1").arg(task->failReason()));
|
||||
}
|
||||
});
|
||||
propagateFromOther(task.get());
|
||||
|
||||
m_gameFilesTask = task;
|
||||
m_gameFilesTask->start();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue