/* Copyright 2013-2019 MultiMC Contributors
*
* 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
*
* 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.
*/
#include <QFile>
#include <QCryptographicHash>
#include <Version.h>
#include <QDir>
#include <QJsonDocument>
#include <QJsonArray>
#include <QDebug>
#include "Exception.h"
#include <minecraft/OneSixVersionFormat.h>
#include <FileSystem.h>
#include <QSaveFile>
#include <Env.h>
#include <meta/Index.h>
#include <minecraft/MinecraftInstance.h>
#include <QUuid>
#include <QTimer>
#include <Json.h>
#include "PackProfile.h"
#include "PackProfile_p.h"
#include "ComponentUpdateTask.h"
PackProfile::PackProfile(MinecraftInstance * instance)
: QAbstractListModel()
{
d.reset(new PackProfileData);
d->m_instance = instance;
d->m_saveTimer.setSingleShot(true);
d->m_saveTimer.setInterval(5000);
d->interactionDisabled = instance->isRunning();
connect(d->m_instance, &BaseInstance::runningStatusChanged, this, &PackProfile::disableInteraction);
connect(&d->m_saveTimer, &QTimer::timeout, this, &PackProfile::save_internal);
}
PackProfile::~PackProfile()
{
saveNow();
}
// BEGIN: component file format
static const int currentComponentsFileVersion = 1;
static QJsonObject componentToJsonV1(ComponentPtr component)
{
QJsonObject obj;
// critical
obj.insert("uid", component->m_uid);
if(!component->m_version.isEmpty())
{
obj.insert("version", component->m_version);
}
if(component->m_dependencyOnly)
{
obj.insert("dependencyOnly", true);
}
if(component->m_important)
{
obj.insert("important", true);
}
if(component->m_disabled)
{
obj.insert("disabled", true);
}
// cached
if(!component->m_cachedVersion.isEmpty())
{
obj.insert("cachedVersion", component->m_cachedVersion);
}
if(!component->m_cachedName.isEmpty())
{
obj.insert("cachedName", component->m_cachedName);
}
Meta::serializeRequires(obj, &component->m_cachedRequires, "cachedRequires");
Meta::serializeRequires(obj, &component->m_cachedConflicts, "cachedConflicts");
if(component->m_cachedVolatile)
{
obj.insert("cachedVolatile", true);
}
return obj;
}
static ComponentPtr componentFromJsonV1(PackProfile * parent, const QString & componentJsonPattern, const QJsonObject &obj)
{
// critical
auto uid = Json::requireString(obj.value("uid"));
auto filePath