2017-01-08 09:28:05 +05:30
|
|
|
/* Copyright 2013-2017 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
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "Env.h"
|
2016-03-26 21:26:57 +05:30
|
|
|
#include <minecraft/forge/ForgeXzDownload.h>
|
2013-08-04 18:16:33 +05:30
|
|
|
#include "OneSixUpdate.h"
|
2016-02-28 00:28:40 +05:30
|
|
|
#include "OneSixInstance.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"
|
|
|
|
#include "minecraft/MinecraftProfile.h"
|
2016-03-07 06:31:28 +05:30
|
|
|
#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>
|
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>
|
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent), m_inst(inst)
|
2013-05-08 23:26:43 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
// create folders
|
2013-08-12 04:09:19 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
m_tasks.append(std::make_shared<FoldersTask>(m_inst));
|
2013-08-12 04:09:19 +05:30
|
|
|
}
|
2013-09-22 07:51:36 +05:30
|
|
|
|
2017-04-24 05:00:51 +05:30
|
|
|
// add metadata update tasks, if necessary
|
2014-02-21 23:45:59 +05:30
|
|
|
{
|
2017-03-13 00:15:28 +05:30
|
|
|
/*
|
2017-03-19 06:43:49 +05:30
|
|
|
* 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-24 05:00:51 +05:30
|
|
|
* We should not rely on the remote to be there... and prefer local files if it does not respond.
|
2017-03-19 06:43:49 +05:30
|
|
|
*/
|
2017-04-24 05:00:51 +05:30
|
|
|
qDebug() << "Updating patches...";
|
|
|
|
auto profile = m_inst->getMinecraftProfile();
|
|
|
|
m_inst->reloadProfile();
|
|
|
|
for(int i = 0; i < profile->rowCount(); i++)
|
2016-08-14 06:03:31 +05:30
|
|
|
{
|
2017-04-24 05:00:51 +05:30
|
|
|
auto patch = profile->versionPatch(i);
|
|
|
|
auto id = patch->getID();
|
|
|
|
auto metadata = patch->getMeta();
|
|
|
|
if(metadata)
|
2016-08-14 06:03:31 +05:30
|
|
|
{
|
2017-04-24 05:00:51 +05:30
|
|
|
metadata->load();
|
|
|
|
auto task = metadata->getCurrentTask();
|
|
|
|
if(task)
|
|
|
|
{
|
|
|
|
qDebug() << "Loading remote meta patch" << id;
|
|
|
|
m_tasks.append(task.unwrap());
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
}
|
2017-04-24 05:00:51 +05:30
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "Ignoring local patch" << id;
|
|
|
|
}
|
|
|
|
}
|
2014-02-21 23:45:59 +05:30
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
|
|
|
|
// libraries download
|
2013-09-16 04:24:39 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
m_tasks.append(std::make_shared<LibrariesTask>(m_inst));
|
2013-09-16 04:24:39 +05:30
|
|
|
}
|
2013-08-05 06:59:50 +05:30
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
// FML libraries download and copy into the instance
|
2013-12-10 11:42:52 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
m_tasks.append(std::make_shared<FMLLibrariesTask>(m_inst));
|
2013-12-10 11:42:52 +05:30
|
|
|
}
|
2014-01-14 05:43:35 +05:30
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
// assets update
|
2013-12-10 11:42:52 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
m_tasks.append(std::make_shared<AssetUpdateTask>(m_inst));
|
2013-12-10 11:42:52 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
void OneSixUpdate::executeTask()
|
2013-08-05 06:59:50 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
if(!m_preFailure.isEmpty())
|
2014-03-10 04:12:25 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
emitFailed(m_preFailure);
|
2016-03-19 01:19:09 +05:30
|
|
|
return;
|
2013-08-05 06:59:50 +05:30
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
next();
|
|
|
|
}
|
2013-09-22 07:51:36 +05:30
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
void OneSixUpdate::next()
|
|
|
|
{
|
|
|
|
if(m_abort)
|
2013-12-11 01:03:24 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
emitFailed(tr("Aborted by user."));
|
|
|
|
return;
|
2013-12-11 01:03:24 +05:30
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
m_currentTask ++;
|
|
|
|
if(m_currentTask > 0)
|
2013-08-05 06:59:50 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +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);
|
2017-04-29 05:54:00 +05:30
|
|
|
disconnect(task.get(), &Task::status, this, &OneSixUpdate::setStatusText);
|
2013-08-05 06:59:50 +05:30
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
if(m_currentTask == m_tasks.size())
|
2014-04-14 02:36:28 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
emitSucceeded();
|
2014-04-14 02:36:28 +05:30
|
|
|
return;
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
auto task = m_tasks[m_currentTask];
|
2017-03-19 06:43:49 +05:30
|
|
|
// if the task is already finished by the time we look at it, skip it
|
|
|
|
if(task->isFinished())
|
|
|
|
{
|
|
|
|
next();
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
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-04-29 05:54:00 +05:30
|
|
|
connect(task.get(), &Task::status, this, &OneSixUpdate::setStatusText);
|
2017-03-19 06:43:49 +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
|
|
|
}
|
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
void OneSixUpdate::subtaskSucceeded()
|
2013-07-10 02:16:33 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
next();
|
2013-07-10 02:16:33 +05:30
|
|
|
}
|
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
void OneSixUpdate::subtaskFailed(QString error)
|
2013-07-10 02:16:33 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
emitFailed(error);
|
2013-07-08 03:21:26 +05:30
|
|
|
}
|
2014-05-05 03:40:59 +05:30
|
|
|
|
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
bool OneSixUpdate::abort()
|
2014-05-05 03:40:59 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
if(!m_abort)
|
2014-05-05 03:40:59 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
m_abort = true;
|
|
|
|
auto task = m_tasks[m_currentTask];
|
|
|
|
if(task->canAbort())
|
2014-05-05 03:40:59 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
return task->abort();
|
2014-05-05 03:40:59 +05:30
|
|
|
}
|
|
|
|
}
|
2016-08-14 06:03:31 +05:30
|
|
|
return true;
|
2014-05-05 03:40:59 +05:30
|
|
|
}
|
|
|
|
|
2016-08-14 06:03:31 +05:30
|
|
|
bool OneSixUpdate::canAbort() const
|
2014-05-05 03:40:59 +05:30
|
|
|
{
|
2016-08-14 06:03:31 +05:30
|
|
|
return true;
|
2014-05-11 20:13:20 +05:30
|
|
|
}
|