pollymc/api/logic/minecraft/onesix/OneSixUpdate.cpp

156 lines
3.8 KiB
C++
Raw Normal View History

2015-02-03 03:55:30 +05:30
/* Copyright 2013-2015 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-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.
*/
2015-02-09 06:21:14 +05:30
#include "Env.h"
#include <minecraft/forge/ForgeXzDownload.h>
2013-08-04 18:16:33 +05:30
#include "OneSixUpdate.h"
#include "OneSixInstance.h"
2013-02-22 05:40:17 +05:30
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
#include <QDataStream>
2015-02-09 06:21:14 +05:30
#include "BaseInstance.h"
#include "minecraft/MinecraftVersionList.h"
#include "minecraft/MinecraftProfile.h"
#include "minecraft/Library.h"
2015-02-09 06:21:14 +05:30
#include "net/URLConstants.h"
2015-10-05 05:17:27 +05:30
#include <FileSystem.h>
#include "update/FoldersTask.h"
#include "update/LibrariesTask.h"
#include "update/FMLLibrariesTask.h"
#include "update/AssetUpdateTask.h"
OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent), m_inst(inst)
{
// create folders
{
m_tasks.append(std::make_shared<FoldersTask>(m_inst));
}
// add a version update task, if necessary
2014-02-21 23:45:59 +05:30
{
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 23:45:59 +05:30
}
// libraries download
{
m_tasks.append(std::make_shared<LibrariesTask>(m_inst));
}
2013-08-05 06:59:50 +05:30
// FML libraries download and copy into the instance
2013-12-10 11:42:52 +05:30
{
m_tasks.append(std::make_shared<FMLLibrariesTask>(m_inst));
2013-12-10 11:42:52 +05:30
}
// assets update
2013-12-10 11:42:52 +05:30
{
m_tasks.append(std::make_shared<AssetUpdateTask>(m_inst));
2013-12-10 11:42:52 +05:30
}
}
void OneSixUpdate::executeTask()
2013-08-05 06:59:50 +05:30
{
if(!m_preFailure.isEmpty())
{
emitFailed(m_preFailure);
return;
2013-08-05 06:59:50 +05:30
}
next();
}
void OneSixUpdate::next()
{
if(m_abort)
{
emitFailed(tr("Aborted by user."));
return;
}
m_currentTask ++;
if(m_currentTask > 0)
2013-08-05 06:59:50 +05:30
{
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 06:59:50 +05:30
}
if(m_currentTask == m_tasks.size())
{
emitSucceeded();
return;
}
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();
}
void OneSixUpdate::subtaskSucceeded()
{
next();
}
void OneSixUpdate::subtaskFailed(QString error)
{
emitFailed(error);
}
2014-05-05 03:40:59 +05:30
bool OneSixUpdate::abort()
2014-05-05 03:40:59 +05:30
{
if(!m_abort)
2014-05-05 03:40:59 +05:30
{
m_abort = true;
auto task = m_tasks[m_currentTask];
if(task->canAbort())
2014-05-05 03:40:59 +05:30
{
return task->abort();
2014-05-05 03:40:59 +05:30
}
}
return true;
2014-05-05 03:40:59 +05:30
}
bool OneSixUpdate::canAbort() const
2014-05-05 03:40:59 +05:30
{
return true;
}