2021-01-18 12:58:54 +05:30
|
|
|
/* Copyright 2013-2021 MultiMC Contributors
|
2013-02-22 05:40:17 +05:30
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2013-09-22 07:51:36 +05:30
|
|
|
*
|
2013-02-22 05:40:17 +05:30
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2013-11-04 07:23:05 +05:30
|
|
|
|
2017-07-24 12:31:37 +05:30
|
|
|
#include "MinecraftUpdate.h"
|
|
|
|
#include "MinecraftInstance.h"
|
2013-02-22 05:40:17 +05:30
|
|
|
|
2013-05-08 23:26:43 +05:30
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QDataStream>
|
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "BaseInstance.h"
|
2020-06-27 15:32:31 +05:30
|
|
|
#include "minecraft/PackProfile.h"
|
2016-03-07 06:31:28 +05:30
|
|
|
#include "minecraft/Library.h"
|
2015-10-05 05:17:27 +05:30
|
|
|
#include <FileSystem.h>
|
2013-05-08 23:26:43 +05:30
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
#include "update/FoldersTask.h"
|
|
|
|
#include "update/LibrariesTask.h"
|
|
|
|
#include "update/FMLLibrariesTask.h"
|
|
|
|
#include "update/AssetUpdateTask.h"
|
2013-05-08 23:26:43 +05:30
|
|
|
|
2017-03-19 06:43:49 +05:30
|
|
|
#include <meta/Index.h>
|
|
|
|
#include <meta/Version.h>
|
|
|
|
|
2018-11-12 04:25:50 +05:30
|
|
|
MinecraftUpdate::MinecraftUpdate(MinecraftInstance *inst, QObject *parent) : Task(parent), m_inst(inst)
|
2013-05-08 23:26:43 +05:30
|
|
|
{
|
2017-11-11 06:08:31 +05:30
|
|
|
}
|
|
|
|
|
2018-11-12 04:25:50 +05:30
|
|
|
void MinecraftUpdate::executeTask()
|
2017-11-11 06:08:31 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
m_tasks.clear();
|
|
|
|
// create folders
|
|
|
|
{
|
2023-01-25 01:22:09 +05:30
|
|
|
m_tasks.append(makeShared<FoldersTask>(m_inst));
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// add metadata update task if necessary
|
|
|
|
{
|
2020-06-27 15:32:31 +05:30
|
|
|
auto components = m_inst->getPackProfile();
|
2018-07-15 18:21:05 +05:30
|
|
|
components->reload(Net::Mode::Online);
|
|
|
|
auto task = components->getCurrentTask();
|
|
|
|
if(task)
|
|
|
|
{
|
2022-08-04 22:28:30 +05:30
|
|
|
m_tasks.append(task);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// libraries download
|
|
|
|
{
|
2023-01-25 01:22:09 +05:30
|
|
|
m_tasks.append(makeShared<LibrariesTask>(m_inst));
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// FML libraries download and copy into the instance
|
|
|
|
{
|
2023-01-25 01:22:09 +05:30
|
|
|
m_tasks.append(makeShared<FMLLibrariesTask>(m_inst));
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// assets update
|
|
|
|
{
|
2023-01-25 01:22:09 +05:30
|
|
|
m_tasks.append(makeShared<AssetUpdateTask>(m_inst));
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if(!m_preFailure.isEmpty())
|
|
|
|
{
|
|
|
|
emitFailed(m_preFailure);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
next();
|
2016-08-14 06:03:31 +05:30
|
|
|
}
|
2013-09-22 07:51:36 +05:30
|
|
|
|
2018-11-12 04:25:50 +05:30
|
|
|
void MinecraftUpdate::next()
|
2016-08-14 06:03:31 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(m_abort)
|
|
|
|
{
|
|
|
|
emitFailed(tr("Aborted by user."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(m_failed_out_of_order)
|
|
|
|
{
|
|
|
|
emitFailed(m_fail_reason);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_currentTask ++;
|
|
|
|
if(m_currentTask > 0)
|
|
|
|
{
|
|
|
|
auto task = m_tasks[m_currentTask - 1];
|
2018-11-12 04:25:50 +05:30
|
|
|
disconnect(task.get(), &Task::succeeded, this, &MinecraftUpdate::subtaskSucceeded);
|
|
|
|
disconnect(task.get(), &Task::failed, this, &MinecraftUpdate::subtaskFailed);
|
2022-06-23 04:26:24 +05:30
|
|
|
disconnect(task.get(), &Task::aborted, this, &Task::abort);
|
2018-11-12 04:25:50 +05:30
|
|
|
disconnect(task.get(), &Task::progress, this, &MinecraftUpdate::progress);
|
2023-03-31 12:20:29 +05:30
|
|
|
disconnect(task.get(), &Task::stepProgress, this, &MinecraftUpdate::propogateStepProgress);
|
2018-11-12 04:25:50 +05:30
|
|
|
disconnect(task.get(), &Task::status, this, &MinecraftUpdate::setStatus);
|
2023-04-01 07:55:01 +05:30
|
|
|
disconnect(task.get(), &Task::details, this, &MinecraftUpdate::setDetails);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
if(m_currentTask == m_tasks.size())
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto task = m_tasks[m_currentTask];
|
|
|
|
// if the task is already finished by the time we look at it, skip it
|
|
|
|
if(task->isFinished())
|
|
|
|
{
|
2018-11-12 04:25:50 +05:30
|
|
|
qCritical() << "MinecraftUpdate: Skipping finished subtask" << m_currentTask << ":" << task.get();
|
2018-07-15 18:21:05 +05:30
|
|
|
next();
|
|
|
|
}
|
2018-11-12 04:25:50 +05:30
|
|
|
connect(task.get(), &Task::succeeded, this, &MinecraftUpdate::subtaskSucceeded);
|
|
|
|
connect(task.get(), &Task::failed, this, &MinecraftUpdate::subtaskFailed);
|
2022-06-23 04:26:24 +05:30
|
|
|
connect(task.get(), &Task::aborted, this, &Task::abort);
|
2018-11-12 04:25:50 +05:30
|
|
|
connect(task.get(), &Task::progress, this, &MinecraftUpdate::progress);
|
2023-03-31 12:20:29 +05:30
|
|
|
connect(task.get(), &Task::stepProgress, this, &MinecraftUpdate::propogateStepProgress);
|
2018-11-12 04:25:50 +05:30
|
|
|
connect(task.get(), &Task::status, this, &MinecraftUpdate::setStatus);
|
2023-04-01 07:55:01 +05:30
|
|
|
connect(task.get(), &Task::details, this, &MinecraftUpdate::setDetails);
|
2018-07-15 18:21:05 +05:30
|
|
|
// if the task is already running, do not start it again
|
|
|
|
if(!task->isRunning())
|
|
|
|
{
|
|
|
|
task->start();
|
|
|
|
}
|
2013-07-10 02:16:33 +05:30
|
|
|
}
|
|
|
|
|
2018-11-12 04:25:50 +05:30
|
|
|
void MinecraftUpdate::subtaskSucceeded()
|
2013-07-10 02:16:33 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(isFinished())
|
|
|
|
{
|
2018-11-12 04:25:50 +05:30
|
|
|
qCritical() << "MinecraftUpdate: Subtask" << sender() << "succeeded, but work was already done!";
|
2018-07-15 18:21:05 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto senderTask = QObject::sender();
|
|
|
|
auto currentTask = m_tasks[m_currentTask].get();
|
|
|
|
if(senderTask != currentTask)
|
|
|
|
{
|
2018-11-12 04:25:50 +05:30
|
|
|
qDebug() << "MinecraftUpdate: Subtask" << sender() << "succeeded out of order.";
|
2018-07-15 18:21:05 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
next();
|
2013-07-10 02:16:33 +05:30
|
|
|
}
|
|
|
|
|
2018-11-12 04:25:50 +05:30
|
|
|
void MinecraftUpdate::subtaskFailed(QString error)
|
2013-07-10 02:16:33 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(isFinished())
|
|
|
|
{
|
2018-11-12 04:25:50 +05:30
|
|
|
qCritical() << "MinecraftUpdate: Subtask" << sender() << "failed, but work was already done!";
|
2018-07-15 18:21:05 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto senderTask = QObject::sender();
|
|
|
|
auto currentTask = m_tasks[m_currentTask].get();
|
|
|
|
if(senderTask != currentTask)
|
|
|
|
{
|
2018-11-12 04:25:50 +05:30
|
|
|
qDebug() << "MinecraftUpdate: Subtask" << sender() << "failed out of order.";
|
2018-07-15 18:21:05 +05:30
|
|
|
m_failed_out_of_order = true;
|
|
|
|
m_fail_reason = error;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emitFailed(error);
|
2013-07-08 03:21:26 +05:30
|
|
|
}
|
2014-05-05 03:40:59 +05:30
|
|
|
|
|
|
|
|
2018-11-12 04:25:50 +05:30
|
|
|
bool MinecraftUpdate::abort()
|
2014-05-05 03:40:59 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!m_abort)
|
|
|
|
{
|
|
|
|
m_abort = true;
|
|
|
|
auto task = m_tasks[m_currentTask];
|
|
|
|
if(task->canAbort())
|
|
|
|
{
|
|
|
|
return task->abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2014-05-05 03:40:59 +05:30
|
|
|
}
|
|
|
|
|
2018-11-12 04:25:50 +05:30
|
|
|
bool MinecraftUpdate::canAbort() const
|
2014-05-05 03:40:59 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return true;
|
2014-05-11 20:13:20 +05:30
|
|
|
}
|