From 7c24bcc83476dcbdd7f7acbe14ecef4398962689 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 1 Mar 2014 23:06:47 +0100 Subject: Reorganize the version-related code. --- logic/OneSixInstance.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'logic/OneSixInstance.h') diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 06fd9de3..75edec1e 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -17,7 +17,7 @@ #include "BaseInstance.h" -#include "OneSixVersion.h" +#include "VersionFinal.h" #include "ModList.h" class OneSixInstance : public BaseInstance @@ -58,9 +58,9 @@ public: /// clears all version information in preparation for an update void clearVersion(); /// get the current full version info - std::shared_ptr getFullVersion() const; + std::shared_ptr getFullVersion() const; /// gets the current version info, but only for version.json - std::shared_ptr getVanillaVersion() const; + std::shared_ptr getVanillaVersion() const; /// is the current version original, or custom? virtual bool versionIsCustom() override; @@ -80,5 +80,5 @@ signals: private: QStringList processMinecraftArgs(AuthSessionPtr account); - QDir reconstructAssets(std::shared_ptr version); + QDir reconstructAssets(std::shared_ptr version); }; -- cgit From 80d146866c8c5f00c6d790b476a774def71010bf Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 2 Mar 2014 02:17:55 +0100 Subject: Remove widgets from logic. --- gui/dialogs/OneSixModEditDialog.cpp | 18 +++++++++--------- logic/OneSixInstance.cpp | 6 +++--- logic/OneSixInstance.h | 2 +- logic/OneSixVersionBuilder.cpp | 21 +++++++++++++++++---- logic/OneSixVersionBuilder.h | 4 +--- logic/VersionFinal.cpp | 4 ++-- logic/VersionFinal.h | 2 +- 7 files changed, 34 insertions(+), 23 deletions(-) (limited to 'logic/OneSixInstance.h') diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp index 67210217..d936f3f1 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -124,7 +124,7 @@ void OneSixModEditDialog::disableVersionControls() void OneSixModEditDialog::on_reloadLibrariesBtn_clicked() { - m_inst->reloadVersion(this); + m_inst->reloadVersion(); } void OneSixModEditDialog::on_removeLibraryBtn_clicked() @@ -137,7 +137,7 @@ void OneSixModEditDialog::on_removeLibraryBtn_clicked() } else { - m_inst->reloadVersion(this); + m_inst->reloadVersion(); } } } @@ -145,7 +145,7 @@ void OneSixModEditDialog::on_removeLibraryBtn_clicked() void OneSixModEditDialog::on_resetLibraryOrderBtn_clicked() { QDir(m_inst->instanceRoot()).remove("order.json"); - m_inst->reloadVersion(this); + m_inst->reloadVersion(); } void OneSixModEditDialog::on_moveLibraryUpBtn_clicked() { @@ -181,7 +181,7 @@ void OneSixModEditDialog::on_moveLibraryUpBtn_clicked() } else { - m_inst->reloadVersion(this); + m_inst->reloadVersion(); ui->libraryTreeView->selectionModel()->select(m_version->index(ourRow - 1), QItemSelectionModel::SelectCurrent); } } @@ -218,7 +218,7 @@ void OneSixModEditDialog::on_moveLibraryDownBtn_clicked() } else { - m_inst->reloadVersion(this); + m_inst->reloadVersion(); ui->libraryTreeView->selectionModel()->select(m_version->index(ourRow + 1), QItemSelectionModel::SelectCurrent); } } @@ -232,7 +232,7 @@ void OneSixModEditDialog::on_forgeBtn_clicked() return; } QDir(m_inst->instanceRoot()).remove("custom.json"); - m_inst->reloadVersion(this); + m_inst->reloadVersion(); } VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); vselect.setFilter(1, m_inst->currentVersionId()); @@ -277,7 +277,7 @@ void OneSixModEditDialog::on_forgeBtn_clicked() } } } - m_inst->reloadVersion(this); + m_inst->reloadVersion(); } void OneSixModEditDialog::on_liteloaderBtn_clicked() @@ -289,7 +289,7 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked() return; } QDir(m_inst->instanceRoot()).remove("custom.json"); - m_inst->reloadVersion(this); + m_inst->reloadVersion(); } VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"), this); vselect.setFilter(1, m_inst->currentVersionId()); @@ -310,7 +310,7 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked() } else { - m_inst->reloadVersion(this); + m_inst->reloadVersion(); } } } diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index bd5d559e..0e0be4d8 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -316,14 +316,14 @@ QString OneSixInstance::currentVersionId() const return intendedVersionId(); } -bool OneSixInstance::reloadVersion(QWidget *widgetParent) +bool OneSixInstance::reloadVersion() { I_D(OneSixInstance); - bool ret = d->version->reload(widgetParent, false, externalPatches()); + bool ret = d->version->reload(false, externalPatches()); if (ret) { - ret = d->vanillaVersion->reload(widgetParent, true, externalPatches()); + ret = d->vanillaVersion->reload(true, externalPatches()); } if (ret) { diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 75edec1e..c7ef2ee8 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -54,7 +54,7 @@ public: virtual QDialog *createModEditDialog(QWidget *parent) override; /// reload the full version json files. return true on success! - bool reloadVersion(QWidget *widgetParent = 0); + bool reloadVersion(); /// clears all version information in preparation for an update void clearVersion(); /// get the current full version info diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index 2b05e45a..98e4b54e 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -37,13 +37,11 @@ OneSixVersionBuilder::OneSixVersionBuilder() { } -bool OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance, - QWidget *widgetParent, const bool onlyVanilla, const QStringList &external) +bool OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance, const bool onlyVanilla, const QStringList &external) { OneSixVersionBuilder builder; builder.m_version = version; builder.m_instance = instance; - builder.m_widgetParent = widgetParent; return builder.buildInternal(onlyVanilla, external); } @@ -52,7 +50,6 @@ bool OneSixVersionBuilder::readJsonAndApplyToVersion(VersionFinal *version, cons OneSixVersionBuilder builder; builder.m_version = version; builder.m_instance = 0; - builder.m_widgetParent = 0; return builder.readJsonAndApply(obj); } @@ -117,11 +114,13 @@ bool OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringLi 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; } @@ -159,10 +158,12 @@ bool OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringLi 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(filePair.first)); + */ return false; } } @@ -206,24 +207,30 @@ bool OneSixVersionBuilder::readJsonAndApply(const QJsonObject &obj) VersionFile file = VersionFile::fromJson(QJsonDocument(obj), QString(), false, isError); if (isError) { + /* QMessageBox::critical( m_widgetParent, QObject::tr("Error"), QObject::tr("Error while reading. Please check MultiMC-0.log for more info.")); + */ return false; } 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; } @@ -235,29 +242,35 @@ bool OneSixVersionBuilder::parseJsonFile(const QFileInfo& fileInfo, const bool r QFile file(fileInfo.absoluteFilePath()); if (!file.open(QFile::ReadOnly)) { + /* QMessageBox::critical( m_widgetParent, QObject::tr("Error"), QObject::tr("Unable to open %1: %2").arg(file.fileName(), file.errorString())); + */ return false; } QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error); if (error.error != QJsonParseError::NoError) { + /* QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Unable to parse %1: %2 at %3") .arg(file.fileName(), error.errorString()) .arg(error.offset)); + */ return false; } bool isError = false; *out = VersionFile::fromJson(doc, file.fileName(), requireOrder, isError, isFTB); if (isError) { + /* QMessageBox::critical( m_widgetParent, QObject::tr("Error"), QObject::tr("Error while reading %1. Please check MultiMC-0.log for more info.") .arg(file.fileName())); + */ } return true; } diff --git a/logic/OneSixVersionBuilder.h b/logic/OneSixVersionBuilder.h index fe77ed9d..789fe3f1 100644 --- a/logic/OneSixVersionBuilder.h +++ b/logic/OneSixVersionBuilder.h @@ -20,7 +20,6 @@ class VersionFinal; class OneSixInstance; -class QWidget; class QJsonObject; class QFileInfo; class VersionFile; @@ -29,7 +28,7 @@ class OneSixVersionBuilder { OneSixVersionBuilder(); public: - static bool build(VersionFinal *version, OneSixInstance *instance, QWidget *widgetParent, const bool onlyVanilla, const QStringList &external); + static bool build(VersionFinal *version, OneSixInstance *instance, const bool onlyVanilla, const QStringList &external); static bool readJsonAndApplyToVersion(VersionFinal *version, const QJsonObject &obj); static QMap readOverrideOrders(OneSixInstance *instance); @@ -38,7 +37,6 @@ public: private: VersionFinal *m_version; OneSixInstance *m_instance; - QWidget *m_widgetParent; bool buildInternal(const bool onlyVanilla, const QStringList &external); bool readJsonAndApply(const QJsonObject &obj); diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp index ce78e8e3..3aa95ed7 100644 --- a/logic/VersionFinal.cpp +++ b/logic/VersionFinal.cpp @@ -26,10 +26,10 @@ VersionFinal::VersionFinal(OneSixInstance *instance, QObject *parent) clear(); } -bool VersionFinal::reload(QWidget *widgetParent, const bool onlyVanilla, const QStringList &external) +bool VersionFinal::reload(const bool onlyVanilla, const QStringList &external) { beginResetModel(); - bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, onlyVanilla, external); + bool ret = OneSixVersionBuilder::build(this, m_instance, onlyVanilla, external); endResetModel(); return ret; } diff --git a/logic/VersionFinal.h b/logic/VersionFinal.h index c9a5f469..e5a38423 100644 --- a/logic/VersionFinal.h +++ b/logic/VersionFinal.h @@ -37,7 +37,7 @@ public: virtual int columnCount(const QModelIndex &parent) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const; - bool reload(QWidget *widgetParent, const bool onlyVanilla = false, const QStringList &external = QStringList()); + bool reload(const bool onlyVanilla = false, const QStringList &external = QStringList()); void clear(); void dump() const; -- cgit From 44f21406e91c68b230d38441b950eb7c3d6a8ec5 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 9 Mar 2014 08:18:50 +0100 Subject: Some pre/post related stuff Reload the onesix version config after the commands (addresses https://www.pivotaltracker.com/story/show/60360652) Add a few more variables and also substitute them in the command (fixes https://www.pivotaltracker.com/story/show/66994828) --- logic/BaseInstance.cpp | 6 ++ logic/BaseInstance.h | 2 + logic/MinecraftProcess.cpp | 198 ++++++++++++++++++++++++++++----------------- logic/MinecraftProcess.h | 7 ++ logic/OneSixInstance.cpp | 5 ++ logic/OneSixInstance.h | 2 + 6 files changed, 148 insertions(+), 72 deletions(-) (limited to 'logic/OneSixInstance.h') diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index d78f1ea0..aea91ef2 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -169,6 +169,12 @@ bool BaseInstance::canLaunch() const return !(flags() & VersionBrokenFlag); } +bool BaseInstance::reload() +{ + // TODO reload the instance settings + return true; +} + QString BaseInstance::baseJar() const { I_D(BaseInstance); diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index 27f939bc..195fd339 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -190,6 +190,8 @@ public: bool canLaunch() const; + virtual bool reload(); + signals: /*! * \brief Signal emitted when properties relevant to the instance view change diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp index 89cd71ed..1001cee5 100644 --- a/logic/MinecraftProcess.cpp +++ b/logic/MinecraftProcess.cpp @@ -49,9 +49,11 @@ MinecraftProcess::MinecraftProcess(BaseInstance *inst) : m_instance(inst) #endif // export some infos - env.insert("INST_NAME", inst->name()); - env.insert("INST_ID", inst->id()); - env.insert("INST_DIR", QDir(inst->instanceRoot()).absolutePath()); + auto variables = getVariables(); + for (auto it = variables.begin(); it != variables.end(); ++it) + { + env.insert(it.key(), it.value()); + } this->setProcessEnvironment(env); m_prepostlaunchprocess.setProcessEnvironment(env); @@ -63,10 +65,10 @@ MinecraftProcess::MinecraftProcess(BaseInstance *inst) : m_instance(inst) // Log prepost launch command output (can be disabled.) if (m_instance->settings().get("LogPrePostOutput").toBool()) { - connect(&m_prepostlaunchprocess, &QProcess::readyReadStandardError, - this, &MinecraftProcess::on_prepost_stdErr); - connect(&m_prepostlaunchprocess, &QProcess::readyReadStandardOutput, - this, &MinecraftProcess::on_prepost_stdOut); + connect(&m_prepostlaunchprocess, &QProcess::readyReadStandardError, this, + &MinecraftProcess::on_prepost_stdErr); + connect(&m_prepostlaunchprocess, &QProcess::readyReadStandardOutput, this, + &MinecraftProcess::on_prepost_stdOut); } } @@ -79,10 +81,10 @@ void MinecraftProcess::setWorkdir(QString path) QString MinecraftProcess::censorPrivateInfo(QString in) { - if(!m_session) + if (!m_session) return in; - if(m_session->session != "-") + if (m_session->session != "-") in.replace(m_session->session, ""); in.replace(m_session->access_token, ""); in.replace(m_session->client_token, ""); @@ -113,7 +115,7 @@ MessageLevel::Enum MinecraftProcess::guessLevel(const QString &line, MessageLeve level = MessageLevel::Fatal; if (line.contains("[DEBUG]")) level = MessageLevel::Debug; - if(line.contains("overwriting existing")) + if (line.contains("overwriting existing")) level = MessageLevel::Fatal; return level; } @@ -139,17 +141,15 @@ MessageLevel::Enum MinecraftProcess::getLevel(const QString &levelName) return MessageLevel::Message; } -void MinecraftProcess::logOutput(const QStringList &lines, - MessageLevel::Enum defaultLevel, +void MinecraftProcess::logOutput(const QStringList &lines, MessageLevel::Enum defaultLevel, bool guessLevel, bool censor) { for (int i = 0; i < lines.size(); ++i) logOutput(lines[i], defaultLevel, guessLevel, censor); } -void MinecraftProcess::logOutput(QString line, - MessageLevel::Enum defaultLevel, - bool guessLevel, bool censor) +void MinecraftProcess::logOutput(QString line, MessageLevel::Enum defaultLevel, bool guessLevel, + bool censor) { MessageLevel::Enum level = defaultLevel; @@ -251,33 +251,7 @@ void MinecraftProcess::finish(int code, ExitStatus status) m_prepostlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(code)); // run post-exit - QString postlaunch_cmd = m_instance->settings().get("PostExitCommand").toString(); - if (!postlaunch_cmd.isEmpty()) - { - emit log(tr("Running Post-Launch command: %1").arg(postlaunch_cmd)); - m_prepostlaunchprocess.start(postlaunch_cmd); - m_prepostlaunchprocess.waitForFinished(); - // Flush console window - if (!m_err_leftover.isEmpty()) - { - logOutput(m_err_leftover, MessageLevel::PrePost); - m_err_leftover.clear(); - } - if (!m_out_leftover.isEmpty()) - { - logOutput(m_out_leftover, MessageLevel::PrePost); - m_out_leftover.clear(); - } - if (m_prepostlaunchprocess.exitStatus() != NormalExit) - { - emit log(tr("Post-Launch command failed with code %1.\n\n").arg(m_prepostlaunchprocess.exitCode()), - MessageLevel::Error); - emit postlaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(), - m_prepostlaunchprocess.exitStatus()); - } - else - emit log(tr("Post-Launch command ran successfully.\n\n")); - } + postLaunch(); m_instance->cleanupAfterRun(); emit ended(m_instance, code, status); } @@ -288,14 +262,12 @@ void MinecraftProcess::killMinecraft() kill(); } -void MinecraftProcess::arm() +bool MinecraftProcess::preLaunch() { - emit log("MultiMC version: " + MMC->version().toString() + "\n\n"); - emit log("Minecraft folder is:\n" + workingDirectory() + "\n\n"); - QString prelaunch_cmd = m_instance->settings().get("PreLaunchCommand").toString(); if (!prelaunch_cmd.isEmpty()) { + prelaunch_cmd = substituteVariables(prelaunch_cmd); // Launch emit log(tr("Running Pre-Launch command: %1").arg(prelaunch_cmd)); m_prepostlaunchprocess.start(prelaunch_cmd); @@ -315,46 +287,128 @@ void MinecraftProcess::arm() // Process return values if (m_prepostlaunchprocess.exitStatus() != NormalExit) { - emit log(tr("Pre-Launch command failed with code %1.\n\n").arg(m_prepostlaunchprocess.exitCode()), + emit log(tr("Pre-Launch command failed with code %1.\n\n") + .arg(m_prepostlaunchprocess.exitCode()), MessageLevel::Fatal); m_instance->cleanupAfterRun(); emit prelaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(), m_prepostlaunchprocess.exitStatus()); - return; + return false; } else emit log(tr("Pre-Launch command ran successfully.\n\n")); + + return m_instance->reload(); + } + return true; +} +bool MinecraftProcess::postLaunch() +{ + QString postlaunch_cmd = m_instance->settings().get("PostExitCommand").toString(); + if (!postlaunch_cmd.isEmpty()) + { + postlaunch_cmd = substituteVariables(postlaunch_cmd); + emit log(tr("Running Post-Launch command: %1").arg(postlaunch_cmd)); + m_prepostlaunchprocess.start(postlaunch_cmd); + m_prepostlaunchprocess.waitForFinished(); + // Flush console window + if (!m_err_leftover.isEmpty()) + { + logOutput(m_err_leftover, MessageLevel::PrePost); + m_err_leftover.clear(); + } + if (!m_out_leftover.isEmpty()) + { + logOutput(m_out_leftover, MessageLevel::PrePost); + m_out_leftover.clear(); + } + if (m_prepostlaunchprocess.exitStatus() != NormalExit) + { + emit log(tr("Post-Launch command failed with code %1.\n\n") + .arg(m_prepostlaunchprocess.exitCode()), + MessageLevel::Error); + emit postlaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(), + m_prepostlaunchprocess.exitStatus()); + } + else + emit log(tr("Post-Launch command ran successfully.\n\n")); + + return m_instance->reload(); } + return true; +} - m_instance->setLastLaunch(); - auto &settings = m_instance->settings(); +QMap MinecraftProcess::getVariables() const +{ + QMap out; + out.insert("INST_NAME", m_instance->name()); + out.insert("INST_ID", m_instance->id()); + out.insert("INST_DIR", QDir(m_instance->instanceRoot()).absolutePath()); + out.insert("INST_MC_DIR", QDir(m_instance->minecraftRoot()).absolutePath()); + out.insert("INST_JAVA", m_instance->settings().get("JavaPath").toString()); + out.insert("INST_JAVA_ARGS", javaArguments().join(' ')); + return out; +} +QString MinecraftProcess::substituteVariables(const QString &cmd) const +{ + QString out = cmd; + auto variables = getVariables(); + for (auto it = variables.begin(); it != variables.end(); ++it) + { + out.replace("$" + it.key(), it.value()); + } + auto env = QProcessEnvironment::systemEnvironment(); + for (auto var : env.keys()) + { + out.replace("$" + var, env.value(var)); + } + return out; +} - //////////// java arguments //////////// +QStringList MinecraftProcess::javaArguments() const +{ QStringList args; + + // custom args go first. we want to override them if we have our own here. + args.append(m_instance->extraArguments()); + +// OSX dock icon and name +#ifdef OSX + args << "-Xdock:icon=icon.png"; + args << QString("-Xdock:name=\"%1\"").arg(m_instance->windowTitle()); +#endif + +// HACK: Stupid hack for Intel drivers. See: https://mojang.atlassian.net/browse/MCL-767 +#ifdef Q_OS_WIN32 + args << QString("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_" + "minecraft.exe.heapdump"); +#endif + + args << QString("-Xms%1m").arg(m_instance->settings().get("MinMemAlloc").toInt()); + args << QString("-Xmx%1m").arg(m_instance->settings().get("MaxMemAlloc").toInt()); + args << QString("-XX:PermSize=%1m").arg(m_instance->settings().get("PermGen").toInt()); + if (!m_nativeFolder.isEmpty()) + args << QString("-Djava.library.path=%1").arg(m_nativeFolder); + args << "-jar" << PathCombine(MMC->bin(), "jars", "NewLaunch.jar"); + + return args; +} + +void MinecraftProcess::arm() +{ + emit log("MultiMC version: " + MMC->version().toString() + "\n\n"); + emit log("Minecraft folder is:\n" + workingDirectory() + "\n\n"); + + if (!preLaunch()) { - // custom args go first. we want to override them if we have our own here. - args.append(m_instance->extraArguments()); - - // OSX dock icon and name - #ifdef OSX - args << "-Xdock:icon=icon.png"; - args << QString("-Xdock:name=\"%1\"").arg(m_instance->windowTitle()); - #endif - - // HACK: Stupid hack for Intel drivers. See: https://mojang.atlassian.net/browse/MCL-767 - #ifdef Q_OS_WIN32 - args << QString("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_" - "minecraft.exe.heapdump"); - #endif - - args << QString("-Xms%1m").arg(settings.get("MinMemAlloc").toInt()); - args << QString("-Xmx%1m").arg(settings.get("MaxMemAlloc").toInt()); - args << QString("-XX:PermSize=%1m").arg(settings.get("PermGen").toInt()); - if(!m_nativeFolder.isEmpty()) - args << QString("-Djava.library.path=%1").arg(m_nativeFolder); - args << "-jar" << PathCombine(MMC->bin(), "jars", "NewLaunch.jar"); + return; } + m_instance->setLastLaunch(); + auto &settings = m_instance->settings(); + + QStringList args = javaArguments(); + QString JavaPath = m_instance->settings().get("JavaPath").toString(); emit log("Java path is:\n" + JavaPath + "\n\n"); QString allArgs = args.join(", "); diff --git a/logic/MinecraftProcess.h b/logic/MinecraftProcess.h index 56340962..d91dad56 100644 --- a/logic/MinecraftProcess.h +++ b/logic/MinecraftProcess.h @@ -131,6 +131,13 @@ protected: QString launchScript; QString m_nativeFolder; + bool preLaunch(); + bool postLaunch(); + QMap getVariables() const; + QString substituteVariables(const QString &cmd) const; + + QStringList javaArguments() const; + protected slots: void finish(int, QProcess::ExitStatus status); diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 10411c56..4f8fef5b 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -413,6 +413,11 @@ bool OneSixInstance::providesVersionFile() const return false; } +bool OneSixInstance::reload() +{ + return BaseInstance::reload() && reloadVersion(); +} + QString OneSixInstance::loaderModsDir() const { return PathCombine(minecraftRoot(), "mods"); diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 06fd9de3..fafb34a0 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -75,6 +75,8 @@ public: virtual QStringList externalPatches() const; virtual bool providesVersionFile() const; + bool reload() override; + signals: void versionReloaded(); -- cgit From b2c803a378695026f12aabc3729eb2139bee1b2c Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 9 Mar 2014 23:42:25 +0100 Subject: Improve reporting of version file errors.x --- MMCError.h | 8 +-- gui/dialogs/OneSixModEditDialog.cpp | 60 ++++++++++++----- gui/dialogs/OneSixModEditDialog.h | 4 +- logic/MMCJson.h | 4 -- logic/OneSixFTBInstance.cpp | 9 ++- logic/OneSixInstance.cpp | 17 +++-- logic/OneSixInstance.h | 8 ++- logic/OneSixUpdate.cpp | 40 ++++++----- logic/OneSixVersionBuilder.cpp | 129 +++++++++++++++++++----------------- logic/VersionFile.cpp | 11 ++- logic/VersionFile.h | 36 ++++++++-- logic/VersionFinal.cpp | 2 +- 12 files changed, 202 insertions(+), 126 deletions(-) (limited to 'logic/OneSixInstance.h') diff --git a/MMCError.h b/MMCError.h index 33591e06..7b2bd0c4 100644 --- a/MMCError.h +++ b/MMCError.h @@ -9,7 +9,7 @@ public: MMCError(QString cause) { exceptionCause = cause; - QLOG_ERROR() << errorName() + ": " + cause; + QLOG_ERROR() << "Exception: " + cause; }; virtual ~MMCError(){}; virtual const char *what() const noexcept @@ -20,10 +20,6 @@ public: { return exceptionCause; } - virtual QString errorName() - { - return "MultiMC Error"; - } private: QString exceptionCause; -}; \ No newline at end of file +}; diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp index c211d3e1..78585a05 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -42,8 +42,7 @@ #include "logic/LiteLoaderInstaller.h" #include "logic/OneSixVersionBuilder.h" -template -QMap invert(const QMap &in) +template QMap invert(const QMap &in) { QMap out; for (auto it = in.begin(); it != in.end(); ++it) @@ -96,7 +95,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) m_resourcepacks->startWatching(); } - connect(m_inst, &OneSixInstance::versionReloaded, this, &OneSixModEditDialog::updateVersionControls); + connect(m_inst, &OneSixInstance::versionReloaded, this, + &OneSixModEditDialog::updateVersionControls); } OneSixModEditDialog::~OneSixModEditDialog() @@ -120,9 +120,30 @@ void OneSixModEditDialog::disableVersionControls() ui->removeLibraryBtn->setEnabled(false); } +bool OneSixModEditDialog::reloadInstanceVersion() +{ + try + { + m_inst->reloadVersion(); + return true; + } + catch (MMCError &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + return false; + } + catch (...) + { + QMessageBox::critical( + this, tr("Error"), + tr("Failed to load the version description file for reasons unknown.")); + return false; + } +} + void OneSixModEditDialog::on_reloadLibrariesBtn_clicked() { - m_inst->reloadVersion(); + reloadInstanceVersion(); } void OneSixModEditDialog::on_removeLibraryBtn_clicked() @@ -136,7 +157,7 @@ void OneSixModEditDialog::on_removeLibraryBtn_clicked() } else { - m_inst->reloadVersion(); + reloadInstanceVersion(); } } } @@ -163,18 +184,20 @@ void OneSixModEditDialog::on_forgeBtn_clicked() // FIXME: model::isCustom(); if (QDir(m_inst->instanceRoot()).exists("custom.json")) { - if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes) + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove your custom.json. Continue?")) != + QMessageBox::Yes) { return; } // FIXME: model::revertToBase(); QDir(m_inst->instanceRoot()).remove("custom.json"); - m_inst->reloadVersion(); + reloadInstanceVersion(); } VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); vselect.setFilter(1, m_inst->currentVersionId()); vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + - m_inst->currentVersionId()); + m_inst->currentVersionId()); if (vselect.exec() && vselect.selectedVersion()) { ForgeVersionPtr forgeVersion = @@ -214,28 +237,32 @@ void OneSixModEditDialog::on_forgeBtn_clicked() } } } - m_inst->reloadVersion(); + reloadInstanceVersion(); } void OneSixModEditDialog::on_liteloaderBtn_clicked() { + // FIXME: model... if (QDir(m_inst->instanceRoot()).exists("custom.json")) { - if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes) + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove your custom.json. Continue?")) != + QMessageBox::Yes) { return; } QDir(m_inst->instanceRoot()).remove("custom.json"); - m_inst->reloadVersion(); + reloadInstanceVersion(); } - VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"), this); + VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"), + this); vselect.setFilter(1, m_inst->currentVersionId()); vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + - m_inst->currentVersionId()); + m_inst->currentVersionId()); if (vselect.exec() && vselect.selectedVersion()) { LiteLoaderVersionPtr liteloaderVersion = - std::dynamic_pointer_cast(vselect.selectedVersion()); + std::dynamic_pointer_cast(vselect.selectedVersion()); if (!liteloaderVersion) return; LiteLoaderInstaller liteloader(liteloaderVersion); @@ -247,7 +274,7 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked() } else { - m_inst->reloadVersion(); + reloadInstanceVersion(); } } } @@ -369,7 +396,8 @@ void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previou ui->frame->updateWithMod(m); } -void OneSixModEditDialog::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous) +void OneSixModEditDialog::versionCurrent(const QModelIndex ¤t, + const QModelIndex &previous) { if (!current.isValid()) { diff --git a/gui/dialogs/OneSixModEditDialog.h b/gui/dialogs/OneSixModEditDialog.h index 1f3f9f67..e106c6fe 100644 --- a/gui/dialogs/OneSixModEditDialog.h +++ b/gui/dialogs/OneSixModEditDialog.h @@ -57,6 +57,8 @@ protected: bool eventFilter(QObject *obj, QEvent *ev); bool loaderListFilter(QKeyEvent *ev); bool resourcePackListFilter(QKeyEvent *ev); + /// FIXME: this shouldn't be necessary! + bool reloadInstanceVersion(); private: Ui::OneSixModEditDialog *ui; @@ -66,8 +68,6 @@ private: EnabledItemFilter *main_model; OneSixInstance *m_inst; - QMap getExistingOrder() const; - public slots: void loaderCurrent(QModelIndex current, QModelIndex previous); diff --git a/logic/MMCJson.h b/logic/MMCJson.h index b0d898fc..f2cc4b31 100644 --- a/logic/MMCJson.h +++ b/logic/MMCJson.h @@ -15,10 +15,6 @@ class JSONValidationError : public MMCError { public: JSONValidationError(QString cause) : MMCError(cause) {}; - virtual QString errorName() - { - return "JSONValidationError"; - }; virtual ~JSONValidationError() {}; }; diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp index cdb3f53e..8f70ed08 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -17,7 +17,14 @@ OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *set void OneSixFTBInstance::init() { - reloadVersion(); + try + { + reloadVersion(); + } + catch(MMCError & e) + { + // QLOG_ERROR() << "Caught exception on instance init: " << e.cause(); + } } void OneSixFTBInstance::copy(const QDir &newDir) diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index f6fe49f1..3c1f6545 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -41,9 +41,17 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, void OneSixInstance::init() { + // FIXME: why is this decided here? what does this even mean? if (QDir(instanceRoot()).exists("version.json")) { - reloadVersion(); + try + { + reloadVersion(); + } + catch(MMCError & e) + { + // QLOG_ERROR() << "Caught exception on instance init: " << e.cause(); + } } else { @@ -317,7 +325,7 @@ QString OneSixInstance::currentVersionId() const return intendedVersionId(); } -bool OneSixInstance::reloadVersion() +void OneSixInstance::reloadVersion() { I_D(OneSixInstance); @@ -327,16 +335,15 @@ bool OneSixInstance::reloadVersion() d->vanillaVersion->reload(true, externalPatches()); setFlags(flags() & ~VersionBrokenFlag); emit versionReloaded(); - return true; } - catch(MMCError error) + catch(MMCError & error) { d->version->clear(); d->vanillaVersion->clear(); setFlags(flags() | VersionBrokenFlag); //TODO: rethrow to show some error message(s)? emit versionReloaded(); - return false; + throw; } } diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index c7ef2ee8..d2bc9b01 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -53,8 +53,12 @@ public: virtual QDialog *createModEditDialog(QWidget *parent) override; - /// reload the full version json files. return true on success! - bool reloadVersion(); + /** + * reload the full version json files. return true on success! + * + * throws various exceptions :3 + */ + void reloadVersion(); /// clears all version information in preparation for an update void clearVersion(); /// get the current full version info diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index 750aeabb..65f30cda 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -48,7 +48,7 @@ void OneSixUpdate::executeTask() QDir mcDir(m_inst->minecraftRoot()); if (!mcDir.exists() && !mcDir.mkpath(".")) { - emitFailed("Failed to create bin folder."); + emitFailed(tr("Failed to create folder for minecraft binaries.")); return; } @@ -60,7 +60,7 @@ void OneSixUpdate::executeTask() if (targetVersion == nullptr) { // don't do anything if it was invalid - emitFailed("The specified Minecraft version is invalid. Choose a different one."); + emitFailed(tr("The specified Minecraft version is invalid. Choose a different one.")); return; } versionFileStart(); @@ -108,20 +108,19 @@ void OneSixUpdate::versionFileFinished() QSaveFile vfile1(version1); if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly)) { - emitFailed("Can't open " + version1 + " for writing."); + emitFailed(tr("Can't open %1 for writing.").arg(version1)); return; } auto data = std::dynamic_pointer_cast(DlJob)->m_data; qint64 actual = 0; if ((actual = vfile1.write(data)) != data.size()) { - emitFailed("Failed to write into " + version1 + ". Written " + actual + " out of " + - data.size() + '.'); + emitFailed(tr("Failed to write into %1. Written %2 out of %3.").arg(version1).arg(actual).arg(data.size())); return; } if (!vfile1.commit()) { - emitFailed("Can't commit changes to " + version1); + emitFailed(tr("Can't commit changes to %1").arg(version1)); return; } } @@ -136,14 +135,13 @@ void OneSixUpdate::versionFileFinished() { finfo.remove(); } - inst->reloadVersion(); - + // NOTE: Version is reloaded in jarlibStart jarlibStart(); } void OneSixUpdate::versionFileFailed() { - emitFailed("Failed to download the version description. Try again."); + emitFailed(tr("Failed to download the version description. Try again.")); } void OneSixUpdate::assetIndexStart() @@ -180,7 +178,7 @@ void OneSixUpdate::assetIndexFinished() QString asset_fname = "assets/indexes/" + assetName + ".json"; if (!AssetsUtils::loadAssetsIndexJson(asset_fname, &index)) { - emitFailed("Failed to read the assets index!"); + emitFailed(tr("Failed to read the assets index!")); } QList dls; @@ -216,7 +214,7 @@ void OneSixUpdate::assetIndexFinished() void OneSixUpdate::assetIndexFailed() { - emitFailed("Failed to download the assets index!"); + emitFailed(tr("Failed to download the assets index!")); } void OneSixUpdate::assetsFinished() @@ -226,7 +224,7 @@ void OneSixUpdate::assetsFinished() void OneSixUpdate::assetsFailed() { - emitFailed("Failed to download assets!"); + emitFailed(tr("Failed to download assets!")); } void OneSixUpdate::jarlibStart() @@ -234,11 +232,18 @@ void OneSixUpdate::jarlibStart() setStatus(tr("Getting the library files from Mojang...")); QLOG_INFO() << m_inst->name() << ": downloading libraries"; OneSixInstance *inst = (OneSixInstance *)m_inst; - bool successful = inst->reloadVersion(); - if (!successful) + try + { + inst->reloadVersion(); + } + catch(MMCError & e) + { + emitFailed(e.cause()); + return; + } + catch(...) { - emitFailed("Failed to load the version description file. It might be " - "corrupted, missing or simply too new."); + emitFailed(tr("Failed to load the version description file for reasons unknown.")); return; } @@ -326,6 +331,5 @@ void OneSixUpdate::jarlibFailed() { QStringList failed = jarlibDownloadJob->getFailedFiles(); QString failed_all = failed.join("\n"); - emitFailed("Failed to download the following files:\n" + failed_all + - "\n\nPlease try again."); + emitFailed(tr("Failed to download the following files:\n%1\n\nPlease try again.").arg(failed_all)); } diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index 8abeb0d8..8eacbce4 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -38,7 +38,8 @@ OneSixVersionBuilder::OneSixVersionBuilder() { } -void OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance, const bool onlyVanilla, const QStringList &external) +void OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance, + const bool onlyVanilla, const QStringList &external) { OneSixVersionBuilder builder; builder.m_version = version; @@ -46,7 +47,8 @@ void OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance builder.buildInternal(onlyVanilla, external); } -void OneSixVersionBuilder::readJsonAndApplyToVersion(VersionFinal *version, const QJsonObject &obj) +void OneSixVersionBuilder::readJsonAndApplyToVersion(VersionFinal *version, + const QJsonObject &obj) { OneSixVersionBuilder builder; builder.m_version = version; @@ -62,17 +64,19 @@ void OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringLi QDir patches(root.absoluteFilePath("patches/")); // if we do external files, do just those. - if(!external.isEmpty()) for (auto fileName : external) - { - QLOG_INFO() << "Reading" << fileName; - auto file = parseJsonFile(QFileInfo(fileName), false, fileName.endsWith("pack.json")); - file->name = QFileInfo(fileName).fileName(); - file->fileId = "org.multimc.external." + file->name; - file->version = QString(); - file->mcVersion = QString(); - file->applyTo(m_version); - m_version->versionFiles.append(file); - } + if (!external.isEmpty()) + for (auto fileName : external) + { + QLOG_INFO() << "Reading" << fileName; + auto file = + parseJsonFile(QFileInfo(fileName), false, fileName.endsWith("pack.json")); + file->name = QFileInfo(fileName).fileName(); + file->fileId = "org.multimc.external." + file->name; + file->version = QString(); + file->mcVersion = QString(); + file->applyTo(m_version); + m_version->versionFiles.append(file); + } // else, if there's custom json, we just do that. else if (QFile::exists(root.absoluteFilePath("custom.json"))) { @@ -84,48 +88,52 @@ void OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringLi file->version = QString(); file->applyTo(m_version); m_version->versionFiles.append(file); - // QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC")); + // 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"; - auto file = parseJsonFile(QFileInfo(root.absoluteFilePath("version.json")), false); - file->name = "Minecraft"; - file->fileId = "org.multimc.version.json"; - file->version = m_instance->intendedVersionId(); - file->mcVersion = m_instance->intendedVersionId(); - file->applyTo(m_version); - m_version->versionFiles.append(file); - // QObject::tr("Error while applying %1. Please check MultiMC-0.log for more info.").arg(root.absoluteFilePath("version.json"))); + else + do + { + // version.json + QLOG_INFO() << "Reading version.json"; + auto file = parseJsonFile(QFileInfo(root.absoluteFilePath("version.json")), false); + file->name = "Minecraft"; + file->fileId = "org.multimc.version.json"; + file->version = m_instance->intendedVersionId(); + file->mcVersion = m_instance->intendedVersionId(); + file->applyTo(m_version); + m_version->versionFiles.append(file); + // QObject::tr("Error while applying %1. Please check MultiMC-0.log for more + // info.").arg(root.absoluteFilePath("version.json"))); - if (onlyVanilla) - break; + if (onlyVanilla) + break; - // patches/ - // load all, put into map for ordering, apply in the right order + // patches/ + // load all, put into map for ordering, apply in the right order - QMap> files; - for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) - { - QLOG_INFO() << "Reading" << info.fileName(); - auto file = parseJsonFile(info, true); - if (files.contains(file->order)) + QMap> files; + for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) { - throw VersionBuildError(QObject::tr("%1 has the same order as %2").arg(file->fileId, files[file->order].second->fileId)); + QLOG_INFO() << "Reading" << info.fileName(); + auto file = parseJsonFile(info, true); + if (files.contains(file->order)) + { + throw VersionBuildError(QObject::tr("%1 has the same order as %2").arg( + file->fileId, files[file->order].second->fileId)); + } + files.insert(file->order, qMakePair(info.fileName(), file)); } - files.insert(file->order, qMakePair(info.fileName(), file)); - } - for (auto order : files.keys()) - { - QLOG_DEBUG() << "Applying file with order" << order; - auto & filePair = files[order]; - filePair.second->applyTo(m_version); - m_version->versionFiles.append(filePair.second); - } - } while(0); + for (auto order : files.keys()) + { + QLOG_DEBUG() << "Applying file with order" << order; + auto &filePair = files[order]; + filePair.second->applyTo(m_version); + m_version->versionFiles.append(filePair.second); + } + } while (0); // some final touches finalizeVersion(); @@ -168,26 +176,30 @@ void OneSixVersionBuilder::readJsonAndApply(const QJsonObject &obj) file->applyTo(m_version); m_version->versionFiles.append(file); // QObject::tr("Error while applying. Please check MultiMC-0.log for more info.")); - // QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC")); + // QObject::tr("The version descriptors of this instance are not compatible with the current + // version of MultiMC")); } -VersionFilePtr OneSixVersionBuilder::parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder, bool isFTB) +VersionFilePtr OneSixVersionBuilder::parseJsonFile(const QFileInfo &fileInfo, + const bool requireOrder, bool isFTB) { QFile file(fileInfo.absoluteFilePath()); if (!file.open(QFile::ReadOnly)) { - throw JSONValidationError(QObject::tr("Unable to open %1: %2").arg(file.fileName(), file.errorString())); + throw JSONValidationError(QObject::tr("Unable to open the version file %1: %2.") + .arg(fileInfo.fileName(), file.errorString())); } QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error); if (error.error != QJsonParseError::NoError) { - throw JSONValidationError(QObject::tr("Unable to parse %1: %2 at %3") - .arg(file.fileName(), error.errorString()) - .arg(error.offset)); + throw JSONValidationError(QObject::tr("Unable to process the version file %1: %2 at %3.") + .arg(fileInfo.fileName(), error.errorString()) + .arg(error.offset)); } return VersionFile::fromJson(doc, file.fileName(), requireOrder, isFTB); - // QObject::tr("Error while reading %1. Please check MultiMC-0.log for more info.").arg(file.fileName()); + // QObject::tr("Error while reading %1. Please check MultiMC-0.log for more + // info.").arg(file.fileName()); } QMap OneSixVersionBuilder::readOverrideOrders(OneSixInstance *instance) @@ -203,7 +215,7 @@ QMap OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst if (!orderFile.open(QFile::ReadOnly)) { QLOG_ERROR() << "Couldn't open" << orderFile.fileName() - << " for reading:" << orderFile.errorString(); + << " for reading:" << orderFile.errorString(); QLOG_WARN() << "Ignoring overriden order"; return out; } @@ -211,9 +223,9 @@ QMap OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst // and it's valid JSON QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(orderFile.readAll(), &error); - if (error.error != QJsonParseError::NoError ) + if (error.error != QJsonParseError::NoError) { - QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ":" << error.errorString(); + QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ":" << error.errorString(); QLOG_WARN() << "Ignoring overriden order"; return out; } @@ -231,7 +243,7 @@ QMap OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst out.insert(it.key(), MMCJson::ensureInteger(it.value())); } } - catch (JSONValidationError err) + catch (JSONValidationError &err) { QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ": bad file format"; QLOG_WARN() << "Ignoring overriden order"; @@ -262,4 +274,3 @@ bool OneSixVersionBuilder::writeOverrideOrders(const QMap &order, orderFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented)); return true; } - diff --git a/logic/VersionFile.cpp b/logic/VersionFile.cpp index 40dcb0c3..831b086e 100644 --- a/logic/VersionFile.cpp +++ b/logic/VersionFile.cpp @@ -311,9 +311,7 @@ void VersionFile::applyTo(VersionFinal *version) { if (minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION) { - throw VersionBuildError( - QString("%1 is for a different launcher version (%2), current supported is %3") - .arg(filename, minimumLauncherVersion, CURRENT_MINIMUM_LAUNCHER_VERSION)); + throw LauncherVersionError(minimumLauncherVersion, CURRENT_MINIMUM_LAUNCHER_VERSION); } } @@ -322,8 +320,7 @@ void VersionFile::applyTo(VersionFinal *version) if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(version->id) == -1) { - throw VersionBuildError( - QString("%1 is for a different version of Minecraft").arg(filename)); + throw MinecraftVersionMismatch(fileId, mcVersion, version->id); } } @@ -471,7 +468,7 @@ void VersionFile::applyTo(VersionFinal *version) (lib->dependType == RawLibrary::Hard && ourVersion != otherVersion)) { throw VersionBuildError( - QString( + QObject::tr( "Error resolving library dependencies between %1 and %2 in %3.") .arg(otherLib->rawName(), lib->name, filename)); } @@ -498,7 +495,7 @@ void VersionFile::applyTo(VersionFinal *version) // it: fail if (lib->dependType == RawLibrary::Hard) { - throw VersionBuildError(QString( + throw VersionBuildError(QObject::tr( "Error resolving library dependencies between %1 and %2 in %3.") .arg(otherLib->rawName(), lib->name, filename)); diff --git a/logic/VersionFile.h b/logic/VersionFile.h index 504fcbff..67d22b23 100644 --- a/logic/VersionFile.h +++ b/logic/VersionFile.h @@ -13,13 +13,39 @@ class VersionBuildError : public MMCError { public: VersionBuildError(QString cause) : MMCError(cause) {}; - virtual QString errorName() - { - return "VersionBuildError"; - }; virtual ~VersionBuildError() {}; }; +/** + * the base version file was meant for a newer version of the vanilla launcher than we support + */ +class LauncherVersionError : public VersionBuildError +{ +public: + LauncherVersionError(int actual, int supported) + : VersionBuildError(QObject::tr( + "The base version file of this instance was meant for a newer (%1) " + "version of the vanilla launcher than this version of MultiMC supports (%2).") + .arg(actual) + .arg(supported)) {}; + virtual ~LauncherVersionError() {}; +}; + +/** + * some patch was intended for a different version of minecraft + */ +class MinecraftVersionMismatch : public VersionBuildError +{ +public: + MinecraftVersionMismatch(QString fileId, QString mcVersion, QString parentMcVersion) + : VersionBuildError(QObject::tr("The patch %1 is for a different version of Minecraft " + "(%2) than that of the instance (%3).") + .arg(fileId) + .arg(mcVersion) + .arg(parentMcVersion)) {}; + virtual ~MinecraftVersionMismatch() {}; +}; + struct RawLibrary; typedef std::shared_ptr RawLibraryPtr; struct RawLibrary @@ -61,7 +87,7 @@ struct VersionFile { public: /* methods */ static VersionFilePtr fromJson(const QJsonDocument &doc, const QString &filename, - const bool requireOrder, const bool isFTB = false); + const bool requireOrder, const bool isFTB = false); static OneSixLibraryPtr createLibrary(RawLibraryPtr lib); int findLibrary(QList haystack, const QString &needle); diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp index 48601d57..a057ecdd 100644 --- a/logic/VersionFinal.cpp +++ b/logic/VersionFinal.cpp @@ -112,7 +112,7 @@ std::shared_ptr VersionFinal::fromJson(const QJsonObject &obj) { OneSixVersionBuilder::readJsonAndApplyToVersion(version.get(), obj); } - catch(MMCError err) + catch(MMCError & err) { return 0; } -- cgit