2017-01-08 03:58:05 +00:00
|
|
|
/* Copyright 2013-2017 MultiMC Contributors
|
2013-02-22 00:10:17 +00:00
|
|
|
*
|
|
|
|
* 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 02:21:36 +00:00
|
|
|
*
|
2013-02-22 00:10:17 +00:00
|
|
|
* 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 01:53:05 +00:00
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "Env.h"
|
2016-03-26 15:56:57 +00:00
|
|
|
#include <minecraft/forge/ForgeXzDownload.h>
|
2017-07-24 07:01:37 +00:00
|
|
|
#include "MinecraftUpdate.h"
|
|
|
|
#include "MinecraftInstance.h"
|
2013-02-22 00:10:17 +00:00
|
|
|
|
2013-05-08 17:56:43 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QDataStream>
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "BaseInstance.h"
|
|
|
|
#include "minecraft/MinecraftProfile.h"
|
2016-03-07 01:01:28 +00:00
|
|
|
#include "minecraft/Library.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "net/URLConstants.h"
|
2015-10-04 23:47:27 +00:00
|
|
|
#include <FileSystem.h>
|
2013-05-08 17:56:43 +00:00
|
|
|
|
2016-08-14 00:33:31 +00:00
|
|
|
#include "update/FoldersTask.h"
|
|
|
|
#include "update/LibrariesTask.h"
|
|
|
|
#include "update/FMLLibrariesTask.h"
|
|
|
|
#include "update/AssetUpdateTask.h"
|
2013-05-08 17:56:43 +00:00
|
|
|
|
2017-03-19 01:13:49 +00:00
|
|
|
#include <meta/Index.h>
|
|
|
|
#include <meta/Version.h>
|
|
|
|
|
2017-07-24 07:01:37 +00:00
|
|
|
OneSixUpdate::OneSixUpdate(MinecraftInstance *inst, QObject *parent) : Task(parent), m_inst(inst)
|
2013-05-08 17:56:43 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
// create folders
|
2013-08-11 22:39:19 +00:00
|
|
|
{
|
2017-05-03 21:11:52 +00:00
|
|
|
m_tasks.append(std::make_shared<FoldersTask>(m_inst));
|
2013-08-11 22:39:19 +00:00
|
|
|
}
|
2013-09-22 02:21:36 +00:00
|
|
|
|
2017-04-23 23:30:51 +00:00
|
|
|
// add metadata update tasks, if necessary
|
2014-02-21 18:15:59 +00:00
|
|
|
{
|
2017-03-12 18:45:28 +00:00
|
|
|
/*
|
2017-03-19 01:13:49 +00:00
|
|
|
* FIXME: there are some corner cases here that remain unhandled:
|
|
|
|
* what if local load succeeds but remote fails? The version is still usable...
|
2017-04-23 23:30:51 +00:00
|
|
|
* We should not rely on the remote to be there... and prefer local files if it does not respond.
|
2017-03-19 01:13:49 +00:00
|
|
|
*/
|
2017-04-23 23:30:51 +00:00
|
|
|
qDebug() << "Updating patches...";
|
|
|
|
auto profile = m_inst->getMinecraftProfile();
|
|
|
|
m_inst->reloadProfile();
|
|
|
|
for(int i = 0; i < profile->rowCount(); i++)
|
2016-08-14 00:33:31 +00:00
|
|
|
{
|
2017-04-23 23:30:51 +00:00
|
|
|
auto patch = profile->versionPatch(i);
|
|
|
|
auto id = patch->getID();
|
|
|
|
auto metadata = patch->getMeta();
|
|
|
|
if(metadata)
|
2016-08-14 00:33:31 +00:00
|
|
|
{
|
2017-04-23 23:30:51 +00:00
|
|
|
metadata->load();
|
|
|
|
auto task = metadata->getCurrentTask();
|
|
|
|
if(task)
|
|
|
|
{
|
|
|
|
qDebug() << "Loading remote meta patch" << id;
|
2017-05-03 21:11:52 +00:00
|
|
|
m_tasks.append(task.unwrap());
|
2017-04-23 23:30:51 +00:00
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
}
|
2017-04-23 23:30:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "Ignoring local patch" << id;
|
|
|
|
}
|
|
|
|
}
|
2014-02-21 18:15:59 +00:00
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
|
|
|
|
// libraries download
|
2013-09-15 22:54:39 +00:00
|
|
|
{
|
2017-05-03 21:11:52 +00:00
|
|
|
m_tasks.append(std::make_shared<LibrariesTask>(m_inst));
|
2013-09-15 22:54:39 +00:00
|
|
|
}
|
2013-08-05 01:29:50 +00:00
|
|
|
|
2016-08-14 00:33:31 +00:00
|
|
|
// FML libraries download and copy into the instance
|
2013-12-10 06:12:52 +00:00
|
|
|
{
|
2017-05-03 21:11:52 +00:00
|
|
|
m_tasks.append(std::make_shared<FMLLibrariesTask>(m_inst));
|
2013-12-10 06:12:52 +00:00
|
|
|
}
|
2014-01-14 00:13:35 +00:00
|
|
|
|
2016-08-14 00:33:31 +00:00
|
|
|
// assets update
|
2013-12-10 06:12:52 +00:00
|
|
|
{
|
2017-05-03 21:11:52 +00:00
|
|
|
m_tasks.append(std::make_shared<AssetUpdateTask>(m_inst));
|
2013-12-10 06:12:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 00:33:31 +00:00
|
|
|
void OneSixUpdate::executeTask()
|
2013-08-05 01:29:50 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
if(!m_preFailure.isEmpty())
|
2014-03-09 22:42:25 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
emitFailed(m_preFailure);
|
2016-03-18 19:49:09 +00:00
|
|
|
return;
|
2013-08-05 01:29:50 +00:00
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
next();
|
|
|
|
}
|
2013-09-22 02:21:36 +00:00
|
|
|
|
2016-08-14 00:33:31 +00:00
|
|
|
void OneSixUpdate::next()
|
|
|
|
{
|
|
|
|
if(m_abort)
|
2013-12-10 19:33:24 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
emitFailed(tr("Aborted by user."));
|
|
|
|
return;
|
2013-12-10 19:33:24 +00:00
|
|
|
}
|
2017-07-21 06:49:58 +00:00
|
|
|
if(m_failed_out_of_order)
|
|
|
|
{
|
|
|
|
emitFailed(m_fail_reason);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
m_currentTask ++;
|
|
|
|
if(m_currentTask > 0)
|
2013-08-05 01:29:50 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
auto task = m_tasks[m_currentTask - 1];
|
|
|
|
disconnect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded);
|
|
|
|
disconnect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed);
|
|
|
|
disconnect(task.get(), &Task::progress, this, &OneSixUpdate::progress);
|
2017-05-03 21:11:52 +00:00
|
|
|
disconnect(task.get(), &Task::status, this, &OneSixUpdate::setStatus);
|
2013-08-05 01:29:50 +00:00
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
if(m_currentTask == m_tasks.size())
|
2014-04-13 21:06:28 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
emitSucceeded();
|
2014-04-13 21:06:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
auto task = m_tasks[m_currentTask];
|
2017-03-19 01:13:49 +00:00
|
|
|
// if the task is already finished by the time we look at it, skip it
|
|
|
|
if(task->isFinished())
|
|
|
|
{
|
2017-07-21 06:49:58 +00:00
|
|
|
qCritical() << "OneSixUpdate: Skipping finished subtask" << m_currentTask << ":" << task.get();
|
2017-03-19 01:13:49 +00:00
|
|
|
next();
|
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
connect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded);
|
|
|
|
connect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed);
|
|
|
|
connect(task.get(), &Task::progress, this, &OneSixUpdate::progress);
|
2017-05-03 21:11:52 +00:00
|
|
|
connect(task.get(), &Task::status, this, &OneSixUpdate::setStatus);
|
2017-03-19 01:13:49 +00:00
|
|
|
// if the task is already running, do not start it again
|
|
|
|
if(!task->isRunning())
|
|
|
|
{
|
|
|
|
task->start();
|
|
|
|
}
|
2013-07-09 20:46:33 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 00:33:31 +00:00
|
|
|
void OneSixUpdate::subtaskSucceeded()
|
2013-07-09 20:46:33 +00:00
|
|
|
{
|
2017-07-07 17:46:56 +00:00
|
|
|
if(isFinished())
|
|
|
|
{
|
|
|
|
qCritical() << "OneSixUpdate: Subtask" << sender() << "succeeded, but work was already done!";
|
|
|
|
return;
|
|
|
|
}
|
2017-07-21 06:49:58 +00:00
|
|
|
auto senderTask = QObject::sender();
|
|
|
|
auto currentTask = m_tasks[m_currentTask].get();
|
|
|
|
if(senderTask != currentTask)
|
|
|
|
{
|
|
|
|
qDebug() << "OneSixUpdate: Subtask" << sender() << "succeeded out of order.";
|
|
|
|
return;
|
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
next();
|
2013-07-09 20:46:33 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 00:33:31 +00:00
|
|
|
void OneSixUpdate::subtaskFailed(QString error)
|
2013-07-09 20:46:33 +00:00
|
|
|
{
|
2017-07-07 17:46:56 +00:00
|
|
|
if(isFinished())
|
|
|
|
{
|
|
|
|
qCritical() << "OneSixUpdate: Subtask" << sender() << "failed, but work was already done!";
|
|
|
|
return;
|
|
|
|
}
|
2017-07-21 06:49:58 +00:00
|
|
|
auto senderTask = QObject::sender();
|
|
|
|
auto currentTask = m_tasks[m_currentTask].get();
|
|
|
|
if(senderTask != currentTask)
|
|
|
|
{
|
|
|
|
qDebug() << "OneSixUpdate: Subtask" << sender() << "failed out of order.";
|
|
|
|
m_failed_out_of_order = true;
|
|
|
|
m_fail_reason = error;
|
|
|
|
return;
|
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
emitFailed(error);
|
2013-07-07 21:51:26 +00:00
|
|
|
}
|
2014-05-04 22:10:59 +00:00
|
|
|
|
|
|
|
|
2016-08-14 00:33:31 +00:00
|
|
|
bool OneSixUpdate::abort()
|
2014-05-04 22:10:59 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
if(!m_abort)
|
2014-05-04 22:10:59 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
m_abort = true;
|
|
|
|
auto task = m_tasks[m_currentTask];
|
|
|
|
if(task->canAbort())
|
2014-05-04 22:10:59 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
return task->abort();
|
2014-05-04 22:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-14 00:33:31 +00:00
|
|
|
return true;
|
2014-05-04 22:10:59 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 00:33:31 +00:00
|
|
|
bool OneSixUpdate::canAbort() const
|
2014-05-04 22:10:59 +00:00
|
|
|
{
|
2016-08-14 00:33:31 +00:00
|
|
|
return true;
|
2014-05-11 14:43:20 +00:00
|
|
|
}
|