Merge branch 'fix_json_version' into integration_json_and_tools

Conflicts:
	logic/OneSixInstance.cpp
	logic/OneSixVersionBuilder.cpp

Some fixage. Yay for conflicts.
This commit is contained in:
Petr Mrázek 2014-02-24 02:35:01 +01:00
commit 49dc9695f5
10 changed files with 224 additions and 168 deletions

View File

@ -357,6 +357,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
QMenu myMenu; QMenu myMenu;
myMenu.addActions(actions); myMenu.addActions(actions);
myMenu.setEnabled(m_selectedInstance->canLaunch());
myMenu.exec(view->mapToGlobal(pos)); myMenu.exec(view->mapToGlobal(pos));
} }
@ -1464,7 +1465,7 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
(BaseInstance *)current.data(InstanceList::InstancePointerRole) (BaseInstance *)current.data(InstanceList::InstancePointerRole)
.value<void *>())) .value<void *>()))
{ {
ui->instanceToolBar->setEnabled(true); ui->instanceToolBar->setEnabled(m_selectedInstance->canLaunch());
renameButton->setText(m_selectedInstance->name()); renameButton->setText(m_selectedInstance->name());
ui->actionChangeInstLWJGLVersion->setEnabled( ui->actionChangeInstLWJGLVersion->setEnabled(
m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion")); m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion"));

View File

@ -37,6 +37,7 @@ BaseInstance::BaseInstance(BaseInstancePrivate *d_in, const QString &rootDir,
I_D(BaseInstance); I_D(BaseInstance);
d->m_settings = settings_obj; d->m_settings = settings_obj;
d->m_rootDir = rootDir; d->m_rootDir = rootDir;
d->m_flags = 0;
settings().registerSetting("name", "Unnamed Instance"); settings().registerSetting("name", "Unnamed Instance");
settings().registerSetting("iconKey", "default"); settings().registerSetting("iconKey", "default");
@ -146,6 +147,28 @@ SettingsObject &BaseInstance::settings() const
return *d->m_settings; return *d->m_settings;
} }
BaseInstance::InstanceFlags BaseInstance::flags() const
{
I_D(const BaseInstance);
return InstanceFlags(d->m_flags);
}
void BaseInstance::setFlags(const BaseInstance::InstanceFlags flags)
{
I_D(BaseInstance);
if (flags != d->m_flags)
{
d->m_flags = flags;
emit flagsChanged();
emit propertiesChanged(this);
}
}
bool BaseInstance::canLaunch() const
{
return !(flags() & VersionBrokenFlag);
}
QString BaseInstance::baseJar() const QString BaseInstance::baseJar() const
{ {
I_D(BaseInstance); I_D(BaseInstance);

View File

@ -179,6 +179,17 @@ public:
/// FIXME: this really should be elsewhere... /// FIXME: this really should be elsewhere...
virtual QString instanceConfigFolder() const = 0; virtual QString instanceConfigFolder() const = 0;
enum InstanceFlag
{
NoFlags = 0x00,
VersionBrokenFlag = 0x01
};
Q_DECLARE_FLAGS(InstanceFlags, InstanceFlag)
InstanceFlags flags() const;
void setFlags(const BaseInstance::InstanceFlags flags);
bool canLaunch() const;
signals: signals:
/*! /*!
* \brief Signal emitted when properties relevant to the instance view change * \brief Signal emitted when properties relevant to the instance view change
@ -193,6 +204,8 @@ signals:
*/ */
void nuked(BaseInstance *inst); void nuked(BaseInstance *inst);
void flagsChanged();
protected slots: protected slots:
void iconUpdated(QString key); void iconUpdated(QString key);
@ -202,3 +215,5 @@ protected:
// pointer for lazy people // pointer for lazy people
typedef std::shared_ptr<BaseInstance> InstancePtr; typedef std::shared_ptr<BaseInstance> InstancePtr;
Q_DECLARE_OPERATORS_FOR_FLAGS(BaseInstance::InstanceFlags)

View File

@ -26,4 +26,5 @@ struct BaseInstancePrivate
QString m_rootDir; QString m_rootDir;
QString m_group; QString m_group;
SettingsObject *m_settings; SettingsObject *m_settings;
}; int m_flags;
};

View File

@ -7,6 +7,10 @@ LegacyFTBInstance::LegacyFTBInstance(const QString &rootDir, SettingsObject *set
QString LegacyFTBInstance::getStatusbarDescription() QString LegacyFTBInstance::getStatusbarDescription()
{ {
if (flags() & VersionBrokenFlag)
{
return "Legacy FTB: " + intendedVersionId() + " (broken)";
}
return "Legacy FTB: " + intendedVersionId(); return "Legacy FTB: " + intendedVersionId();
} }

View File

@ -268,13 +268,23 @@ QString LegacyInstance::defaultCustomBaseJar() const
bool LegacyInstance::menuActionEnabled(QString action_name) const bool LegacyInstance::menuActionEnabled(QString action_name) const
{ {
if (action_name == "actionChangeInstMCVersion") if (flags() & VersionBrokenFlag)
{
return false; return false;
}
if (action_name == "actionChangeInstMCVersion")
{
return false;
}
return true; return true;
} }
QString LegacyInstance::getStatusbarDescription() QString LegacyInstance::getStatusbarDescription()
{ {
if (flags() & VersionBrokenFlag)
{
return "Legacy : " + intendedVersionId() + " (broken)";
}
if (shouldUpdate()) if (shouldUpdate())
return "Legacy : " + currentVersionId() + " -> " + intendedVersionId(); return "Legacy : " + currentVersionId() + " -> " + intendedVersionId();
else else

View File

@ -23,6 +23,10 @@ NostalgiaInstance::NostalgiaInstance(const QString &rootDir, SettingsObject *set
QString NostalgiaInstance::getStatusbarDescription() QString NostalgiaInstance::getStatusbarDescription()
{ {
if (flags() & VersionBrokenFlag)
{
return "Nostalgia : " + intendedVersionId() + " (broken)";
}
return "Nostalgia : " + intendedVersionId(); return "Nostalgia : " + intendedVersionId();
} }

View File

@ -182,6 +182,10 @@ bool OneSixFTBInstance::providesVersionFile() const
QString OneSixFTBInstance::getStatusbarDescription() QString OneSixFTBInstance::getStatusbarDescription()
{ {
if (flags() & VersionBrokenFlag)
{
return "OneSix FTB: " + intendedVersionId() + " (broken)";
}
return "OneSix FTB: " + intendedVersionId(); return "OneSix FTB: " + intendedVersionId();
} }
bool OneSixFTBInstance::menuActionEnabled(QString action_name) const bool OneSixFTBInstance::menuActionEnabled(QString action_name) const

View File

@ -325,8 +325,15 @@ bool OneSixInstance::reloadVersion(QWidget *widgetParent)
{ {
ret = d->vanillaVersion->reload(widgetParent, true, externalPatches()); ret = d->vanillaVersion->reload(widgetParent, true, externalPatches());
} }
if (ret)
emit versionReloaded(); {
setFlags(flags() & ~VersionBrokenFlag);
emit versionReloaded();
}
else
{
setFlags(flags() | VersionBrokenFlag);
}
return ret; return ret;
} }
@ -362,8 +369,14 @@ QString OneSixInstance::defaultCustomBaseJar() const
bool OneSixInstance::menuActionEnabled(QString action_name) const bool OneSixInstance::menuActionEnabled(QString action_name) const
{ {
if (action_name == "actionChangeInstLWJGLVersion") if (flags() & VersionBrokenFlag)
{
return false; return false;
}
if (action_name == "actionChangeInstLWJGLVersion")
{
return false;
}
return true; return true;
} }
@ -372,7 +385,11 @@ QString OneSixInstance::getStatusbarDescription()
QString descr = "OneSix : " + intendedVersionId(); QString descr = "OneSix : " + intendedVersionId();
if (versionIsCustom()) if (versionIsCustom())
{ {
descr + " (custom)"; descr += " (custom)";
}
if (flags() & VersionBrokenFlag)
{
descr += " (broken)";
} }
return descr; return descr;
} }

View File

@ -32,6 +32,8 @@
#include "modutils.h" #include "modutils.h"
#include "logger/QsLog.h" #include "logger/QsLog.h"
#define CURRENT_MINIMUM_LAUNCHER_VERSION 14
struct VersionFile struct VersionFile
{ {
int order; int order;
@ -95,6 +97,13 @@ struct VersionFile
QList<Library> addLibs; QList<Library> addLibs;
QList<QString> removeLibs; QList<QString> removeLibs;
enum ApplyError
{
LauncherVersionError,
OtherError,
NoApplyError
};
static Library fromLibraryJson(const QJsonObject &libObj, const QString &filename, static Library fromLibraryJson(const QJsonObject &libObj, const QString &filename,
bool &isError) bool &isError)
{ {
@ -547,15 +556,26 @@ struct VersionFile
} }
return -1; return -1;
} }
void applyTo(OneSixVersion *version, bool &isError) ApplyError applyTo(OneSixVersion *version)
{ {
isError = true; if (minimumLauncherVersion != -1)
{
if (minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
{
QLOG_ERROR() << filename << "is for a different launcher version ("
<< minimumLauncherVersion << "), current supported is"
<< CURRENT_MINIMUM_LAUNCHER_VERSION;
return LauncherVersionError;
}
}
if (!version->id.isNull() && !mcVersion.isNull()) if (!version->id.isNull() && !mcVersion.isNull())
{ {
if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(version->id) == -1) if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard)
.indexIn(version->id) == -1)
{ {
QLOG_ERROR() << filename << "is for a different version of Minecraft"; QLOG_ERROR() << filename << "is for a different version of Minecraft";
return; return OtherError;
} }
} }
@ -706,7 +726,7 @@ struct VersionFile
QLOG_ERROR() << "Error resolving library dependencies between" QLOG_ERROR() << "Error resolving library dependencies between"
<< otherLib->rawName() << "and" << lib.name << "in" << otherLib->rawName() << "and" << lib.name << "in"
<< filename; << filename;
return; return OtherError;
} }
else else
{ {
@ -734,7 +754,7 @@ struct VersionFile
QLOG_ERROR() << "Error resolving library dependencies between" QLOG_ERROR() << "Error resolving library dependencies between"
<< otherLib->rawName() << "and" << lib.name << "in" << otherLib->rawName() << "and" << lib.name << "in"
<< filename; << filename;
return; return OtherError;
} }
} }
} }
@ -778,7 +798,7 @@ struct VersionFile
versionFile.order = order; versionFile.order = order;
version->versionFiles.append(versionFile); version->versionFiles.append(versionFile);
isError = false; return NoApplyError;
} }
}; };
@ -812,166 +832,111 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla, const QStringList &exte
QDir root(m_instance->instanceRoot()); QDir root(m_instance->instanceRoot());
QDir patches(root.absoluteFilePath("patches/")); QDir patches(root.absoluteFilePath("patches/"));
if (external.isEmpty()) // if we do external files, do just those.
if(!external.isEmpty()) for (auto fileName : external)
{ {
if (QFile::exists(root.absoluteFilePath("custom.json"))) QLOG_INFO() << "Reading" << fileName;
VersionFile file;
ParseFlags flags = fileName.endsWith("pack.json") ? IsFTBPackJson : NoFlags;
if (!read(QFileInfo(fileName), false, &file, flags))
{ {
QLOG_INFO() << "Reading custom.json"; return false;
}
file.name = QFileInfo(fileName).fileName();
file.fileId = "org.multimc.external." + file.name;
file.version = QString();
file.mcVersion = QString();
bool isError = false;
auto errorcode = file.applyTo(m_version);
if(errorcode != VersionFile::NoApplyError)
return false;
}
// else, if there's custom json, we just do that.
else if (QFile::exists(root.absoluteFilePath("custom.json")))
{
QLOG_INFO() << "Reading custom.json";
VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("custom.json")), false, &file))
{
return false;
}
file.name = "custom.json";
file.filename = "custom.json";
file.fileId = "org.multimc.custom.json";
file.version = QString();
auto errorcode = file.applyTo(m_version);
if(errorcode != VersionFile::NoApplyError)
return false;
// QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC"));
// QObject::tr("Error while applying %1. Please check MultiMC-0.log for more info.")
}
// version.json -> patches/*.json -> user.json
else do
{
// version.json
QLOG_INFO() << "Reading version.json";
VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("version.json")), false, &file))
{
return false;
}
file.name = "version.json";
file.fileId = "org.multimc.version.json";
file.version = m_instance->intendedVersionId();
file.mcVersion = m_instance->intendedVersionId();
auto error = file.applyTo(m_version);
if (error != VersionFile::NoApplyError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("version.json")));
return false;
}
if (onlyVanilla)
break;
// patches/
// load all, put into map for ordering, apply in the right order
QMap<QString, int> overrideOrder = readOverrideOrders(m_instance);
QMap<int, QPair<QString, VersionFile>> files;
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
{
QLOG_INFO() << "Reading" << info.fileName();
VersionFile file; VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("custom.json")), false, &file)) if (!read(info, true, &file))
{ {
return false; return false;
} }
file.name = "custom.json"; if (overrideOrder.contains(file.fileId))
file.filename = "custom.json"; {
file.fileId = "org.multimc.custom.json"; file.order = overrideOrder.value(file.fileId);
file.version = QString(); }
bool isError = false; if (files.contains(file.order))
file.applyTo(m_version, isError); {
if (isError) QLOG_ERROR() << file.fileId << "has the same order as" << files[file.order].second.fileId;
return false;
}
files.insert(file.order, qMakePair(info.fileName(), file));
}
for (auto order : files.keys())
{
QLOG_DEBUG() << "Applying file with order" << order;
auto filePair = files[order];
auto error = filePair.second.applyTo(m_version);
if (error != VersionFile::NoApplyError)
{ {
QMessageBox::critical( QMessageBox::critical(
m_widgetParent, QObject::tr("Error"), m_widgetParent, QObject::tr("Error"),
QObject::tr( QObject::tr("Error while applying %1. Please check MultiMC-0.log "
"Error while applying %1. Please check MultiMC-0.log for more info.") "for more info.").arg(filePair.first));
.arg(root.absoluteFilePath("custom.json")));
return false; return false;
} }
} }
else } while(0);
{
// version.json -> patches/*.json -> user.json
// version.json
{
QLOG_INFO() << "Reading version.json";
VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("version.json")), false, &file))
{
return false;
}
file.name = "version.json";
file.fileId = "org.multimc.version.json";
file.version = m_instance->intendedVersionId();
file.mcVersion = m_instance->intendedVersionId();
bool isError = false;
file.applyTo(m_version, isError);
if (isError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("version.json")));
return false;
}
}
if (!onlyVanilla)
{
// patches/
{
// load all, put into map for ordering, apply in the right order
QMap<QString, int> overrideOrder = readOverrideOrders(m_instance);
QMap<int, QPair<QString, VersionFile>> files;
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
{
QLOG_INFO() << "Reading" << info.fileName();
VersionFile file;
if (!read(info, true, &file))
{
return false;
}
if (overrideOrder.contains(file.fileId))
{
file.order = overrideOrder.value(file.fileId);
}
if (files.contains(file.order))
{
QLOG_ERROR() << file.fileId << "has the same order as" << files[file.order].second.fileId;
return false;
}
files.insert(file.order, qMakePair(info.fileName(), file));
}
for (auto order : files.keys())
{
QLOG_DEBUG() << "Applying file with order" << order;
auto filePair = files[order];
bool isError = false;
filePair.second.applyTo(m_version, isError);
if (isError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr("Error while applying %1. Please check MultiMC-0.log "
"for more info.").arg(filePair.first));
return false;
}
}
}
#if 0
// user.json
{
if (QFile::exists(root.absoluteFilePath("user.json")))
{
QLOG_INFO() << "Reading user.json";
VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file))
{
return false;
}
file.name = "user.json";
file.fileId = "org.multimc.user.json";
file.version = QString();
file.mcVersion = QString();
bool isError = false;
file.applyTo(m_version, isError);
if (isError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("user.json")));
return false;
}
}
}
#endif
}
}
}
else
{
for (auto fileName : external)
{
QLOG_INFO() << "Reading" << fileName;
VersionFile file;
ParseFlags flags = fileName.endsWith("pack.json") ? IsFTBPackJson : NoFlags;
if (!read(QFileInfo(fileName), false, &file, flags))
{
return false;
}
file.name = QFileInfo(fileName).fileName();
file.fileId = "org.multimc.external." + file.name;
file.version = QString();
file.mcVersion = QString();
bool isError = false;
file.applyTo(m_version, isError);
if (isError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(fileName));
return false;
}
}
}
// some final touches // some final touches
{ {
@ -1016,14 +981,21 @@ bool OneSixVersionBuilder::read(const QJsonObject &obj)
QObject::tr("Error while reading. Please check MultiMC-0.log for more info.")); QObject::tr("Error while reading. Please check MultiMC-0.log for more info."));
return false; return false;
} }
file.applyTo(m_version, isError); VersionFile::ApplyError error = file.applyTo(m_version);
if (isError) if (error == VersionFile::OtherError)
{ {
QMessageBox::critical( QMessageBox::critical(
m_widgetParent, QObject::tr("Error"), m_widgetParent, QObject::tr("Error"),
QObject::tr("Error while applying. Please check MultiMC-0.log for more info.")); QObject::tr("Error while applying. Please check MultiMC-0.log for more info."));
return false; return false;
} }
else if (error == VersionFile::LauncherVersionError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC"));
return false;
}
return true; return true;
} }
@ -1070,7 +1042,8 @@ QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst
QFile orderFile(instance->instanceRoot() + "/order.json"); QFile orderFile(instance->instanceRoot() + "/order.json");
if (!orderFile.open(QFile::ReadOnly)) if (!orderFile.open(QFile::ReadOnly))
{ {
QLOG_ERROR() << "Couldn't open" << orderFile.fileName() << " for reading:" << orderFile.errorString(); QLOG_ERROR() << "Couldn't open" << orderFile.fileName()
<< " for reading:" << orderFile.errorString();
QLOG_WARN() << "Ignoring overriden order"; QLOG_WARN() << "Ignoring overriden order";
} }
else else
@ -1079,7 +1052,8 @@ QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst
QJsonDocument doc = QJsonDocument::fromJson(orderFile.readAll(), &error); QJsonDocument doc = QJsonDocument::fromJson(orderFile.readAll(), &error);
if (error.error != QJsonParseError::NoError || !doc.isObject()) if (error.error != QJsonParseError::NoError || !doc.isObject())
{ {
QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ":" << error.errorString(); QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ":"
<< error.errorString();
QLOG_WARN() << "Ignoring overriden order"; QLOG_WARN() << "Ignoring overriden order";
} }
else else
@ -1098,7 +1072,8 @@ QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst
} }
return out; return out;
} }
bool OneSixVersionBuilder::writeOverrideOrders(const QMap<QString, int> &order, OneSixInstance *instance) bool OneSixVersionBuilder::writeOverrideOrders(const QMap<QString, int> &order,
OneSixInstance *instance)
{ {
QJsonObject obj; QJsonObject obj;
for (auto it = order.cbegin(); it != order.cend(); ++it) for (auto it = order.cbegin(); it != order.cend(); ++it)
@ -1112,9 +1087,11 @@ bool OneSixVersionBuilder::writeOverrideOrders(const QMap<QString, int> &order,
QFile orderFile(instance->instanceRoot() + "/order.json"); QFile orderFile(instance->instanceRoot() + "/order.json");
if (!orderFile.open(QFile::WriteOnly)) if (!orderFile.open(QFile::WriteOnly))
{ {
QLOG_ERROR() << "Couldn't open" << orderFile.fileName() << "for writing:" << orderFile.errorString(); QLOG_ERROR() << "Couldn't open" << orderFile.fileName()
<< "for writing:" << orderFile.errorString();
return false; return false;
} }
orderFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented)); orderFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented));
return true; return true;
} }