/* Copyright 2013-2017 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 "minecraft/MinecraftProfile.h"
#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>
MinecraftProfile::MinecraftProfile(MinecraftInstance * instance)
: QAbstractListModel()
{
m_instance = instance;
clear();
}
MinecraftProfile::~MinecraftProfile()
{
}
void MinecraftProfile::reload()
{
beginResetModel();
load_internal();
reapplyPatches();
endResetModel();
}
void MinecraftProfile::clear()
{
m_minecraftVersion.clear();
m_minecraftVersionType.clear();
m_minecraftAssets.reset();
m_minecraftArguments.clear();
m_tweakers.clear();
m_mainClass.clear();
m_appletClass.clear();
m_libraries.clear();
m_traits.clear();
m_jarMods.clear();
m_mainJar.reset();
m_problemSeverity = ProblemSeverity::None;
}
void MinecraftProfile::clearPatches()
{
beginResetModel();
m_patches.clear();
endResetModel();
}
void MinecraftProfile::appendPatch(ProfilePatchPtr patch)
{
int index = m_patches.size();
beginInsertRows(QModelIndex(), index, index);
m_patches.append(patch);
endInsertRows();
}
bool MinecraftProfile::remove(const int index)
{
auto patch = versionPatch(index);
if (!patch->isRemovable())
{
qDebug() << "Patch" << patch->getID() << "is non-removable";
return false;
}
if(!removePatch_internal(patch))
{
qCritical() << "Patch" << patch->getID() << "could not be removed";
return false;
}
beginRemoveRows(QModelIndex(), index, index);
m_patches.removeAt(index);
endRemoveRows();
reapplyPatches();
saveCurrentOrder();
return true;
}
bool MinecraftProfile::remove(const QString id)
{
int i = 0;
for (auto patch : m_patches)
{
if (patch->getID() == id)
{
return remove(i);
}
i++;
}
return false;
}
bool MinecraftProfile::customize(int index)
{
auto patch = versionPatch(index);
if (!patch->isCustomizable())
{
qDebug() << "Patch" << patch->getID() << "is not customizable";
return false;
}
if(!customizePatch_internal(patch))
{
qCritical() << "Patch" << patch->getID() << "could not be customized";
return false;
}
reapplyPatches();
saveCurrentOrder();
// FIXME: maybe later in unstable
// emit dataChanged(createIndex(index, 0), createIndex(index, columnCount(QModelIndex()) - 1));
return true;
}
bool MinecraftProfile::revertToBase(int index)
{
auto patch = versionPatch(index);
if (!patch->isRevertible())
{
qDebug() << "Patch" << patch->getID() << "is not revertible";
return false;
}
if(!revertPatch_internal(patch))
{
qCritical() << "Patch" <<