2015-02-02 14:25:30 -08:00
|
|
|
/* Copyright 2013-2015 MultiMC Contributors
|
2013-02-21 18:10:17 -06: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 04:21:36 +02:00
|
|
|
*
|
2013-02-21 18:10:17 -06: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 02:53:05 +01:00
|
|
|
|
2015-02-09 01:51:14 +01:00
|
|
|
#include "Env.h"
|
2016-03-26 16:56:57 +01:00
|
|
|
#include <minecraft/forge/ForgeXzDownload.h>
|
2013-08-04 14:46:33 +02:00
|
|
|
#include "OneSixUpdate.h"
|
2016-02-27 19:58:40 +01:00
|
|
|
#include "OneSixInstance.h"
|
2013-02-21 18:10:17 -06:00
|
|
|
|
2013-05-08 12:56:43 -05:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QDataStream>
|
|
|
|
|
2015-02-09 01:51:14 +01:00
|
|
|
#include "BaseInstance.h"
|
|
|
|
#include "minecraft/MinecraftVersionList.h"
|
|
|
|
#include "minecraft/MinecraftProfile.h"
|
2016-03-07 02:01:28 +01:00
|
|
|
#include "minecraft/Library.h"
|
2015-02-09 01:51:14 +01:00
|
|
|
#include "net/URLConstants.h"
|
2015-10-05 01:47:27 +02:00
|
|
|
#include <FileSystem.h>
|
2013-05-08 12:56:43 -05:00
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
#include "update/FoldersTask.h"
|
|
|
|
#include "update/LibrariesTask.h"
|
|
|
|
#include "update/FMLLibrariesTask.h"
|
|
|
|
#include "update/AssetUpdateTask.h"
|
2013-05-08 12:56:43 -05:00
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent), m_inst(inst)
|
2013-05-08 12:56:43 -05:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
// create folders
|
2013-08-12 00:39:19 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
m_tasks.append(std::make_shared<FoldersTask>(m_inst));
|
2013-08-12 00:39:19 +02:00
|
|
|
}
|
2013-09-22 04:21:36 +02:00
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
// add a version update task, if necessary
|
2014-02-21 19:15:59 +01:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
auto list = std::dynamic_pointer_cast<MinecraftVersionList>(ENV.getVersionList("net.minecraft"));
|
|
|
|
auto version = std::dynamic_pointer_cast<MinecraftVersion>(list->findVersion(m_inst->intendedVersionId()));
|
|
|
|
if (version == nullptr)
|
|
|
|
{
|
|
|
|
// don't do anything if it was invalid
|
|
|
|
m_preFailure = tr("The specified Minecraft version is invalid. Choose a different one.");
|
|
|
|
}
|
|
|
|
else if (m_inst->providesVersionFile() || !version->needsUpdate())
|
|
|
|
{
|
|
|
|
qDebug() << "Instance either provides a version file or doesn't need an update.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto versionUpdateTask = list->createUpdateTask(m_inst->intendedVersionId());
|
|
|
|
if (!versionUpdateTask)
|
|
|
|
{
|
|
|
|
qDebug() << "Didn't spawn an update task.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_tasks.append(versionUpdateTask);
|
|
|
|
}
|
|
|
|
}
|
2014-02-21 19:15:59 +01:00
|
|
|
}
|
2016-08-14 02:33:31 +02:00
|
|
|
|
|
|
|
// libraries download
|
2013-09-16 00:54:39 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
m_tasks.append(std::make_shared<LibrariesTask>(m_inst));
|
2013-09-16 00:54:39 +02:00
|
|
|
}
|
2013-08-05 03:29:50 +02:00
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
// FML libraries download and copy into the instance
|
2013-12-10 07:12:52 +01:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
m_tasks.append(std::make_shared<FMLLibrariesTask>(m_inst));
|
2013-12-10 07:12:52 +01:00
|
|
|
}
|
2014-01-14 01:13:35 +01:00
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
// assets update
|
2013-12-10 07:12:52 +01:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
m_tasks.append(std::make_shared<AssetUpdateTask>(m_inst));
|
2013-12-10 07:12:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
void OneSixUpdate::executeTask()
|
2013-08-05 03:29:50 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
if(!m_preFailure.isEmpty())
|
2014-03-09 23:42:25 +01:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
emitFailed(m_preFailure);
|
2016-03-18 20:49:09 +01:00
|
|
|
return;
|
2013-08-05 03:29:50 +02:00
|
|
|
}
|
2016-08-14 02:33:31 +02:00
|
|
|
next();
|
|
|
|
}
|
2013-09-22 04:21:36 +02:00
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
void OneSixUpdate::next()
|
|
|
|
{
|
|
|
|
if(m_abort)
|
2013-12-10 20:33:24 +01:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
emitFailed(tr("Aborted by user."));
|
|
|
|
return;
|
2013-12-10 20:33:24 +01:00
|
|
|
}
|
2016-08-14 02:33:31 +02:00
|
|
|
m_currentTask ++;
|
|
|
|
if(m_currentTask > 0)
|
2013-08-05 03:29:50 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02: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);
|
|
|
|
disconnect(task.get(), &Task::status, this, &OneSixUpdate::setStatus);
|
2013-08-05 03:29:50 +02:00
|
|
|
}
|
2016-08-14 02:33:31 +02:00
|
|
|
if(m_currentTask == m_tasks.size())
|
2014-04-13 23:06:28 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
emitSucceeded();
|
2014-04-13 23:06:28 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-08-14 02:33:31 +02:00
|
|
|
auto task = m_tasks[m_currentTask];
|
|
|
|
connect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded);
|
|
|
|
connect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed);
|
|
|
|
connect(task.get(), &Task::progress, this, &OneSixUpdate::progress);
|
|
|
|
connect(task.get(), &Task::status, this, &OneSixUpdate::setStatus);
|
|
|
|
task->start();
|
2013-07-09 22:46:33 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
void OneSixUpdate::subtaskSucceeded()
|
2013-07-09 22:46:33 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
next();
|
2013-07-09 22:46:33 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
void OneSixUpdate::subtaskFailed(QString error)
|
2013-07-09 22:46:33 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
emitFailed(error);
|
2013-07-07 23:51:26 +02:00
|
|
|
}
|
2014-05-05 00:10:59 +02:00
|
|
|
|
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
bool OneSixUpdate::abort()
|
2014-05-05 00:10:59 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
if(!m_abort)
|
2014-05-05 00:10:59 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
m_abort = true;
|
|
|
|
auto task = m_tasks[m_currentTask];
|
|
|
|
if(task->canAbort())
|
2014-05-05 00:10:59 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
return task->abort();
|
2014-05-05 00:10:59 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-14 02:33:31 +02:00
|
|
|
return true;
|
2014-05-05 00:10:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 02:33:31 +02:00
|
|
|
bool OneSixUpdate::canAbort() const
|
2014-05-05 00:10:59 +02:00
|
|
|
{
|
2016-08-14 02:33:31 +02:00
|
|
|
return true;
|
2014-05-11 16:43:20 +02:00
|
|
|
}
|