summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gui/MainWindow.cpp3
-rw-r--r--logic/BaseInstance.cpp23
-rw-r--r--logic/BaseInstance.h15
-rw-r--r--logic/BaseInstance_p.h3
-rw-r--r--logic/LegacyFTBInstance.cpp4
-rw-r--r--logic/LegacyInstance.cpp10
-rw-r--r--logic/NostalgiaInstance.cpp4
-rw-r--r--logic/OneSixFTBInstance.cpp4
-rw-r--r--logic/OneSixInstance.cpp23
-rw-r--r--logic/OneSixVersionBuilder.cpp287
10 files changed, 216 insertions, 160 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index ebbace52..121c2a73 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -357,6 +357,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
QMenu myMenu;
myMenu.addActions(actions);
+ myMenu.setEnabled(m_selectedInstance->canLaunch());
myMenu.exec(view->mapToGlobal(pos));
}
@@ -1464,7 +1465,7 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
(BaseInstance *)current.data(InstanceList::InstancePointerRole)
.value<void *>()))
{
- ui->instanceToolBar->setEnabled(true);
+ ui->instanceToolBar->setEnabled(m_selectedInstance->canLaunch());
renameButton->setText(m_selectedInstance->name());
ui->actionChangeInstLWJGLVersion->setEnabled(
m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion"));
diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp
index 222004a3..d78f1ea0 100644
--- a/logic/BaseInstance.cpp
+++ b/logic/BaseInstance.cpp
@@ -37,6 +37,7 @@ BaseInstance::BaseInstance(BaseInstancePrivate *d_in, const QString &rootDir,
I_D(BaseInstance);
d->m_settings = settings_obj;
d->m_rootDir = rootDir;
+ d->m_flags = 0;
settings().registerSetting("name", "Unnamed Instance");
settings().registerSetting("iconKey", "default");
@@ -146,6 +147,28 @@ SettingsObject &BaseInstance::settings() const
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
{
I_D(BaseInstance);
diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h
index 341a6adb..27f939bc 100644
--- a/logic/BaseInstance.h
+++ b/logic/BaseInstance.h
@@ -179,6 +179,17 @@ public:
/// FIXME: this really should be elsewhere...
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:
/*!
* \brief Signal emitted when properties relevant to the instance view change
@@ -193,6 +204,8 @@ signals:
*/
void nuked(BaseInstance *inst);
+ void flagsChanged();
+
protected slots:
void iconUpdated(QString key);
@@ -202,3 +215,5 @@ protected:
// pointer for lazy people
typedef std::shared_ptr<BaseInstance> InstancePtr;
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(BaseInstance::InstanceFlags)
diff --git a/logic/BaseInstance_p.h b/logic/BaseInstance_p.h
index 06581a34..73eebec7 100644
--- a/logic/BaseInstance_p.h
+++ b/logic/BaseInstance_p.h
@@ -26,4 +26,5 @@ struct BaseInstancePrivate
QString m_rootDir;
QString m_group;
SettingsObject *m_settings;
-}; \ No newline at end of file
+ int m_flags;
+};
diff --git a/logic/LegacyFTBInstance.cpp b/logic/LegacyFTBInstance.cpp
index 6c6bd10b..23cb259d 100644
--- a/logic/LegacyFTBInstance.cpp
+++ b/logic/LegacyFTBInstance.cpp
@@ -7,6 +7,10 @@ LegacyFTBInstance::LegacyFTBInstance(const QString &rootDir, SettingsObject *set
QString LegacyFTBInstance::getStatusbarDescription()
{
+ if (flags() & VersionBrokenFlag)
+ {
+ return "Legacy FTB: " + intendedVersionId() + " (broken)";
+ }
return "Legacy FTB: " + intendedVersionId();
}
diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp
index 6cd17fea..3b9181e0 100644
--- a/logic/LegacyInstance.cpp
+++ b/logic/LegacyInstance.cpp
@@ -268,13 +268,23 @@ QString LegacyInstance::defaultCustomBaseJar() const
bool LegacyInstance::menuActionEnabled(QString action_name) const
{
+ if (flags() & VersionBrokenFlag)
+ {
+ return false;
+ }
if (action_name == "actionChangeInstMCVersion")
+ {
return false;
+ }
return true;
}
QString LegacyInstance::getStatusbarDescription()
{
+ if (flags() & VersionBrokenFlag)
+ {
+ return "Legacy : " + intendedVersionId() + " (broken)";
+ }
if (shouldUpdate())
return "Legacy : " + currentVersionId() + " -> " + intendedVersionId();
else
diff --git a/logic/NostalgiaInstance.cpp b/logic/NostalgiaInstance.cpp
index 2e23ee71..96ce4cc7 100644
--- a/logic/NostalgiaInstance.cpp
+++ b/logic/NostalgiaInstance.cpp
@@ -23,6 +23,10 @@ NostalgiaInstance::NostalgiaInstance(const QString &rootDir, SettingsObject *set
QString NostalgiaInstance::getStatusbarDescription()
{
+ if (flags() & VersionBrokenFlag)
+ {
+ return "Nostalgia : " + intendedVersionId() + " (broken)";
+ }
return "Nostalgia : " + intendedVersionId();
}
diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp
index 307ddb7c..91efce8e 100644
--- a/logic/OneSixFTBInstance.cpp
+++ b/logic/OneSixFTBInstance.cpp
@@ -182,6 +182,10 @@ bool OneSixFTBInstance::providesVersionFile() const
QString OneSixFTBInstance::getStatusbarDescription()
{
+ if (flags() & VersionBrokenFlag)
+ {
+ return "OneSix FTB: " + intendedVersionId() + " (broken)";
+ }
return "OneSix FTB: " + intendedVersionId();
}
bool OneSixFTBInstance::menuActionEnabled(QString action_name) const
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index 3f1c5b0c..10411c56 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -325,8 +325,15 @@ bool OneSixInstance::reloadVersion(QWidget *widgetParent)
{
ret = d->vanillaVersion->reload(widgetParent, true, externalPatches());
}
-
- emit versionReloaded();
+ if (ret)
+ {
+ setFlags(flags() & ~VersionBrokenFlag);
+ emit versionReloaded();
+ }
+ else
+ {
+ setFlags(flags() | VersionBrokenFlag);
+ }
return ret;
}
@@ -362,8 +369,14 @@ QString OneSixInstance::defaultCustomBaseJar() const
bool OneSixInstance::menuActionEnabled(QString action_name) const
{
+ if (flags() & VersionBrokenFlag)
+ {
+ return false;
+ }
if (action_name == "actionChangeInstLWJGLVersion")
+ {
return false;
+ }
return true;
}
@@ -372,7 +385,11 @@ QString OneSixInstance::getStatusbarDescription()
QString descr = "OneSix : " + intendedVersionId();
if (versionIsCustom())
{
- descr + " (custom)";
+ descr += " (custom)";
+ }
+ if (flags() & VersionBrokenFlag)
+ {
+ descr += " (broken)";
}
return descr;
}
diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp
index f1d0477e..f6917697 100644
--- a/logic/OneSixVersionBuilder.cpp
+++ b/logic/OneSixVersionBuilder.cpp
@@ -32,6 +32,8 @@
#include "modutils.h"
#include "logger/QsLog.h"
+#define CURRENT_MINIMUM_LAUNCHER_VERSION 14
+
struct VersionFile
{
int order;
@@ -95,6 +97,13 @@ struct VersionFile
QList<Library> addLibs;
QList<QString> removeLibs;
+ enum ApplyError
+ {
+ LauncherVersionError,
+ OtherError,
+ NoApplyError
+ };
+
static Library fromLibraryJson(const QJsonObject &libObj, const QString &filename,
bool &isError)
{
@@ -547,15 +556,26 @@ struct VersionFile
}
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 (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";
- return;
+ return OtherError;
}
}
@@ -706,7 +726,7 @@ struct VersionFile
QLOG_ERROR() << "Error resolving library dependencies between"
<< otherLib->rawName() << "and" << lib.name << "in"
<< filename;
- return;
+ return OtherError;
}
else
{
@@ -734,7 +754,7 @@ struct VersionFile
QLOG_ERROR() << "Error resolving library dependencies between"
<< otherLib->rawName() << "and" << lib.name << "in"
<< filename;
- return;
+ return OtherError;
}
}
}
@@ -778,7 +798,7 @@ struct VersionFile
versionFile.order = order;
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 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";
- 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();
- 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("custom.json")));
- return false;
- }
+ return false;
}
- else
+ 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))
{
- // 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
- }
+ 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.")
}
- else
+ // version.json -> patches/*.json -> user.json
+ else do
{
- for (auto fileName : external)
+ // 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)
{
- QLOG_INFO() << "Reading" << fileName;
+ 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;
- ParseFlags flags = fileName.endsWith("pack.json") ? IsFTBPackJson : NoFlags;
- if (!read(QFileInfo(fileName), false, &file, flags))
+ if (!read(info, true, &file))
{
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)
+ 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];
+ auto error = filePair.second.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(fileName));
+ QObject::tr("Error while applying %1. Please check MultiMC-0.log "
+ "for more info.").arg(filePair.first));
return false;
}
}
- }
+ } while(0);
// 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."));
return false;
}
- file.applyTo(m_version, isError);
- if (isError)
+ VersionFile::ApplyError error = file.applyTo(m_version);
+ if (error == VersionFile::OtherError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr("Error while applying. Please check MultiMC-0.log for more info."));
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;
}
@@ -1070,7 +1042,8 @@ QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst
QFile orderFile(instance->instanceRoot() + "/order.json");
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";
}
else
@@ -1079,7 +1052,8 @@ QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst
QJsonDocument doc = QJsonDocument::fromJson(orderFile.readAll(), &error);
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";
}
else
@@ -1098,7 +1072,8 @@ QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst
}
return out;
}
-bool OneSixVersionBuilder::writeOverrideOrders(const QMap<QString, int> &order, OneSixInstance *instance)
+bool OneSixVersionBuilder::writeOverrideOrders(const QMap<QString, int> &order,
+ OneSixInstance *instance)
{
QJsonObject obj;
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");
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;
}
orderFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented));
return true;
}
+