From 549198031d1469b9aff18b67be09be08afe4cc4a Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 17 Feb 2014 17:19:58 +0100 Subject: [PATCH 1/4] Check if the json version is one we know how to handle Also some formatting. --- logic/OneSixVersionBuilder.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index bbd33ddc..6d1e128f 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 13 + struct VersionFile { int order; @@ -538,9 +540,22 @@ struct VersionFile void applyTo(OneSixVersion *version, bool &isError) { 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; + } + } + 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; @@ -876,7 +891,8 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) } if (files.contains(file.order)) { - QLOG_ERROR() << file.fileId << "has the same order as" << files[file.order].second.fileId; + QLOG_ERROR() << file.fileId << "has the same order as" + << files[file.order].second.fileId; return false; } files.insert(file.order, qMakePair(info.fileName(), file)); @@ -1027,7 +1043,8 @@ QMap 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 @@ -1036,7 +1053,8 @@ QMap 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 @@ -1055,7 +1073,8 @@ QMap OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst } return out; } -bool OneSixVersionBuilder::writeOverrideOrders(const QMap &order, OneSixInstance *instance) +bool OneSixVersionBuilder::writeOverrideOrders(const QMap &order, + OneSixInstance *instance) { QJsonObject obj; for (auto it = order.cbegin(); it != order.cend(); ++it) @@ -1069,7 +1088,8 @@ bool OneSixVersionBuilder::writeOverrideOrders(const QMap &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)); From 8d0ff990896207e7ef9c70a095b45573197d4fbe Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 17 Feb 2014 17:36:29 +0100 Subject: [PATCH 2/4] Actually remove instances if they fail to load --- logic/OneSixInstance.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index ae172f21..048e635c 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -323,7 +323,14 @@ bool OneSixInstance::reloadVersion(QWidget *widgetParent) { ret = d->vanillaVersion->reload(widgetParent, true); } - emit versionReloaded(); + if (ret) + { + emit versionReloaded(); + } + else + { + nuke(); + } return ret; } From 4e8be668cb9b3c4929748aafb1baf53e6b1c098b Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 17 Feb 2014 17:46:43 +0100 Subject: [PATCH 3/4] Different error message if it's a launcher version mismatch --- logic/OneSixVersionBuilder.cpp | 68 ++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index 6d1e128f..932374f9 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -97,6 +97,13 @@ struct VersionFile QList addLibs; QList removeLibs; + enum ApplyError + { + LauncherVersionError, + OtherError, + NoApplyError + }; + static Library fromLibraryJson(const QJsonObject &libObj, const QString &filename, bool &isError) { @@ -537,10 +544,8 @@ 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) @@ -548,7 +553,7 @@ struct VersionFile QLOG_ERROR() << filename << "is for a different launcher version (" << minimumLauncherVersion << "), current supported is" << CURRENT_MINIMUM_LAUNCHER_VERSION; - return; + return LauncherVersionError; } } @@ -558,7 +563,7 @@ struct VersionFile .indexIn(version->id) == -1) { QLOG_ERROR() << filename << "is for a different version of Minecraft"; - return; + return OtherError; } } @@ -709,7 +714,7 @@ struct VersionFile QLOG_ERROR() << "Error resolving library dependencies between" << otherLib->rawName() << "and" << lib.name << "in" << filename; - return; + return OtherError; } else { @@ -737,7 +742,7 @@ struct VersionFile QLOG_ERROR() << "Error resolving library dependencies between" << otherLib->rawName() << "and" << lib.name << "in" << filename; - return; + return OtherError; } } } @@ -781,7 +786,7 @@ struct VersionFile versionFile.order = order; version->versionFiles.append(versionFile); - isError = false; + return NoApplyError; } }; @@ -827,9 +832,8 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) file.filename = "custom.json"; file.fileId = "org.multimc.custom.json"; file.version = QString(); - bool isError = 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"), @@ -838,6 +842,13 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) .arg(root.absoluteFilePath("custom.json"))); return false; } + else if (error == VersionFile::LauncherVersionError) + { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); + return false; + } } else { @@ -855,9 +866,8 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) 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) + VersionFile::ApplyError error = file.applyTo(m_version); + if (error == VersionFile::OtherError) { QMessageBox::critical( m_widgetParent, QObject::tr("Error"), @@ -866,6 +876,13 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) .arg(root.absoluteFilePath("version.json"))); return false; } + else if (error == VersionFile::LauncherVersionError) + { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); + return false; + } } if (!onlyVanilla) @@ -901,9 +918,8 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) { QLOG_DEBUG() << "Applying file with order" << order; auto filePair = files[order]; - bool isError = false; - filePair.second.applyTo(m_version, isError); - if (isError) + VersionFile::ApplyError error = filePair.second.applyTo(m_version); + if (error == VersionFile::OtherError) { QMessageBox::critical( m_widgetParent, QObject::tr("Error"), @@ -911,6 +927,13 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) "for more info.").arg(filePair.first)); return false; } + else if (error == VersionFile::LauncherVersionError) + { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); + return false; + } } } @@ -989,14 +1012,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 now compatible with the current version of MultiMC")); + return false; + } return true; } From 0b56b5efafffca77d6deee966097c55e78fb0aef Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 17 Feb 2014 20:31:50 +0100 Subject: [PATCH 4/4] Instance flags. Currently used for marking instances as broken. Can later be used for badges. --- gui/MainWindow.cpp | 3 ++- logic/BaseInstance.cpp | 23 +++++++++++++++++++++++ logic/BaseInstance.h | 15 +++++++++++++++ logic/BaseInstance_p.h | 3 ++- logic/LegacyFTBInstance.cpp | 4 ++++ logic/LegacyInstance.cpp | 12 +++++++++++- logic/NostalgiaInstance.cpp | 4 ++++ logic/OneSixFTBInstance.cpp | 4 ++++ logic/OneSixInstance.cpp | 17 ++++++++++++++--- logic/OneSixVersionBuilder.cpp | 8 ++++---- 10 files changed, 83 insertions(+), 10 deletions(-) diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 29f7c8e8..a4c04d89 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -354,6 +354,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos) QMenu myMenu; myMenu.addActions(actions); + myMenu.setEnabled(m_selectedInstance->canLaunch()); myMenu.exec(view->mapToGlobal(pos)); } @@ -1366,7 +1367,7 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex & (BaseInstance *)current.data(InstanceList::InstancePointerRole) .value())) { - 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 cd49f99b..91b83bfc 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -175,6 +175,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 @@ -189,6 +200,8 @@ signals: */ void nuked(BaseInstance *inst); + void flagsChanged(); + protected slots: void iconUpdated(QString key); @@ -198,3 +211,5 @@ protected: // pointer for lazy people typedef std::shared_ptr 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 a9f0d112..f58f0e76 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 (action_name == "actionChangeInstMCVersion") + 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 ca88142a..dfd57046 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -97,6 +97,10 @@ QString OneSixFTBInstance::id() 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 048e635c..b85a593c 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -325,11 +325,12 @@ bool OneSixInstance::reloadVersion(QWidget *widgetParent) } if (ret) { + setFlags(flags() & ~VersionBrokenFlag); emit versionReloaded(); } else { - nuke(); + setFlags(flags() | VersionBrokenFlag); } return ret; } @@ -366,8 +367,14 @@ QString OneSixInstance::defaultCustomBaseJar() const bool OneSixInstance::menuActionEnabled(QString action_name) const { - if (action_name == "actionChangeInstLWJGLVersion") + if (flags() & VersionBrokenFlag) + { return false; + } + if (action_name == "actionChangeInstLWJGLVersion") + { + return false; + } return true; } @@ -376,7 +383,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 932374f9..a4bac80a 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -846,7 +846,7 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) { QMessageBox::critical( m_widgetParent, QObject::tr("Error"), - QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); + QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC")); return false; } } @@ -880,7 +880,7 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) { QMessageBox::critical( m_widgetParent, QObject::tr("Error"), - QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); + QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC")); return false; } } @@ -931,7 +931,7 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla) { QMessageBox::critical( m_widgetParent, QObject::tr("Error"), - QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); + QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC")); return false; } } @@ -1024,7 +1024,7 @@ bool OneSixVersionBuilder::read(const QJsonObject &obj) { QMessageBox::critical( m_widgetParent, QObject::tr("Error"), - QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); + QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC")); return false; }