aboutsummaryrefslogtreecommitdiff
path: root/logic
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2014-03-10 19:24:29 +0100
committerJan Dalheimer <jan@dalheimer.de>2014-03-10 19:24:29 +0100
commitfcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb (patch)
tree851d8f8b6e6734e26fd2e4dc7b7477630329ff01 /logic
parent73fc9c79cff979e9023df0b1a77848c67b590681 (diff)
parentd11f10ea1ed54336254838ff068258d2d42e0774 (diff)
downloadPrismLauncher-fcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb.tar.gz
PrismLauncher-fcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb.tar.bz2
PrismLauncher-fcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb.zip
Merge branch 'develop' into feature_badges
Conflicts: logic/OneSixInstance.cpp
Diffstat (limited to 'logic')
-rw-r--r--logic/BaseInstaller.cpp2
-rw-r--r--logic/BaseInstance.cpp5
-rw-r--r--logic/BaseInstance.h2
-rw-r--r--logic/ForgeInstaller.cpp6
-rw-r--r--logic/ForgeInstaller.h4
-rw-r--r--logic/LiteLoaderInstaller.cpp4
-rw-r--r--logic/MMCJson.cpp61
-rw-r--r--logic/MMCJson.h46
-rw-r--r--logic/MinecraftProcess.cpp199
-rw-r--r--logic/MinecraftProcess.h7
-rw-r--r--logic/OneSixFTBInstance.cpp81
-rw-r--r--logic/OneSixInstance.cpp59
-rw-r--r--logic/OneSixInstance.h18
-rw-r--r--logic/OneSixInstance_p.h6
-rw-r--r--logic/OneSixLibrary.h3
-rw-r--r--logic/OneSixUpdate.cpp48
-rw-r--r--logic/OneSixVersion.cpp221
-rw-r--r--logic/OneSixVersionBuilder.cpp1111
-rw-r--r--logic/OneSixVersionBuilder.h31
-rw-r--r--logic/VersionFile.cpp535
-rw-r--r--logic/VersionFile.h127
-rw-r--r--logic/VersionFinal.cpp183
-rw-r--r--logic/VersionFinal.h (renamed from logic/OneSixVersion.h)23
-rw-r--r--logic/lists/LiteLoaderVersionList.cpp55
-rw-r--r--logic/lists/LiteLoaderVersionList.h11
-rw-r--r--logic/net/PasteUpload.cpp11
-rw-r--r--logic/net/PasteUpload.h2
27 files changed, 1420 insertions, 1441 deletions
diff --git a/logic/BaseInstaller.cpp b/logic/BaseInstaller.cpp
index 92aa0c92..669fd0ac 100644
--- a/logic/BaseInstaller.cpp
+++ b/logic/BaseInstaller.cpp
@@ -17,7 +17,7 @@
#include <QFile>
-#include "OneSixVersion.h"
+#include "VersionFinal.h"
#include "OneSixLibrary.h"
#include "OneSixInstance.h"
diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp
index 24af20cf..c7b29548 100644
--- a/logic/BaseInstance.cpp
+++ b/logic/BaseInstance.cpp
@@ -168,6 +168,11 @@ bool BaseInstance::canLaunch() const
return !flags().contains(VersionBrokenFlag);
}
+bool BaseInstance::reload()
+{
+ return settings().reload();
+}
+
QString BaseInstance::baseJar() const
{
I_D(BaseInstance);
diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h
index 443b0eaa..d38ae409 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/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp
index 3e18d17f..6f238c21 100644
--- a/logic/ForgeInstaller.cpp
+++ b/logic/ForgeInstaller.cpp
@@ -14,7 +14,7 @@
*/
#include "ForgeInstaller.h"
-#include "OneSixVersion.h"
+#include "VersionFinal.h"
#include "OneSixLibrary.h"
#include "net/HttpMetaCache.h"
#include <quazip.h>
@@ -33,7 +33,7 @@
ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
{
- std::shared_ptr<OneSixVersion> newVersion;
+ std::shared_ptr<VersionFinal> newVersion;
m_universal_url = universal_url;
QuaZip zip(filename);
@@ -66,7 +66,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
// read the forge version info
{
- newVersion = OneSixVersion::fromJson(versionInfoVal.toObject());
+ newVersion = VersionFinal::fromJson(versionInfoVal.toObject());
if (!newVersion)
return;
}
diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h
index c5052092..df029f38 100644
--- a/logic/ForgeInstaller.h
+++ b/logic/ForgeInstaller.h
@@ -20,7 +20,7 @@
#include <QString>
#include <memory>
-class OneSixVersion;
+class VersionFinal;
class ForgeInstaller : public BaseInstaller
{
@@ -33,7 +33,7 @@ public:
private:
// the version, read from the installer
- std::shared_ptr<OneSixVersion> m_forge_version;
+ std::shared_ptr<VersionFinal> m_forge_version;
QString internalPath;
QString finalPath;
QString realVersionId;
diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp
index 126027fb..bb4b07ca 100644
--- a/logic/LiteLoaderInstaller.cpp
+++ b/logic/LiteLoaderInstaller.cpp
@@ -20,7 +20,7 @@
#include "logger/QsLog.h"
-#include "OneSixVersion.h"
+#include "VersionFinal.h"
#include "OneSixLibrary.h"
#include "OneSixInstance.h"
@@ -69,7 +69,7 @@ bool LiteLoaderInstaller::add(OneSixInstance *to)
obj.insert("+libraries", libraries);
obj.insert("name", QString("LiteLoader"));
obj.insert("fileId", id());
- obj.insert("version", to->intendedVersionId());
+ obj.insert("version", m_version->version);
obj.insert("mcVersion", to->intendedVersionId());
QFile file(filename(to->instanceRoot()));
diff --git a/logic/MMCJson.cpp b/logic/MMCJson.cpp
new file mode 100644
index 00000000..25cc2de3
--- /dev/null
+++ b/logic/MMCJson.cpp
@@ -0,0 +1,61 @@
+#include "MMCJson.h"
+#include <QString>
+#include <math.h>
+
+bool MMCJson::ensureBoolean(const QJsonValue val, const QString what)
+{
+ if (!val.isBool())
+ throw JSONValidationError(what + " is not boolean");
+ return val.isBool();
+}
+
+QJsonValue MMCJson::ensureExists(QJsonValue val, const QString what)
+{
+ if(val.isNull())
+ throw JSONValidationError(what + " does not exist");
+ return val;
+}
+
+QJsonArray MMCJson::ensureArray(const QJsonValue val, const QString what)
+{
+ if (!val.isArray())
+ throw JSONValidationError(what + " is not an array");
+ return val.toArray();
+}
+
+double MMCJson::ensureDouble(const QJsonValue val, const QString what)
+{
+ if (!val.isDouble())
+ throw JSONValidationError(what + " is not a number");
+ double ret = val.toDouble();
+}
+
+int MMCJson::ensureInteger(const QJsonValue val, const QString what)
+{
+ double ret = ensureDouble(val, what);
+ if (fmod(ret, 1) != 0)
+ throw JSONValidationError(what + " is not an integer");
+ return ret;
+}
+
+QJsonObject MMCJson::ensureObject(const QJsonValue val, const QString what)
+{
+ if (!val.isObject())
+ throw JSONValidationError(what + " is not an object");
+ return val.toObject();
+}
+
+QJsonObject MMCJson::ensureObject(const QJsonDocument val, const QString what)
+{
+ if (!val.isObject())
+ throw JSONValidationError(what + " is not an object");
+ return val.object();
+}
+
+QString MMCJson::ensureString(const QJsonValue val, const QString what)
+{
+ if (!val.isString())
+ throw JSONValidationError(what + " is not a string");
+ return val.toString();
+}
+
diff --git a/logic/MMCJson.h b/logic/MMCJson.h
new file mode 100644
index 00000000..71ded435
--- /dev/null
+++ b/logic/MMCJson.h
@@ -0,0 +1,46 @@
+/**
+ * Some de-bullshitting for Qt JSON failures.
+ *
+ * Simple exception-throwing
+ */
+
+#pragma once
+#include <QJsonValue>
+#include <QJsonObject>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include "MMCError.h"
+
+class JSONValidationError : public MMCError
+{
+public:
+ JSONValidationError(QString cause) : MMCError(cause) {};
+ virtual ~JSONValidationError() noexcept {}
+};
+
+namespace MMCJson
+{
+/// make sure the value exists. throw otherwise.
+QJsonValue ensureExists(QJsonValue val, const QString what = "value");
+
+/// make sure the value is converted into an object. throw otherwise.
+QJsonObject ensureObject(const QJsonValue val, const QString what = "value");
+
+/// make sure the document is converted into an object. throw otherwise.
+QJsonObject ensureObject(const QJsonDocument val, const QString what = "value");
+
+/// make sure the value is converted into an array. throw otherwise.
+QJsonArray ensureArray(const QJsonValue val, QString what = "value");
+
+/// make sure the value is converted into a string. throw otherwise.
+QString ensureString(const QJsonValue val, QString what = "value");
+
+/// make sure the value is converted into a boolean. throw otherwise.
+bool ensureBoolean(const QJsonValue val, QString what = "value");
+
+/// make sure the value is converted into an integer. throw otherwise.
+int ensureInteger(const QJsonValue val, QString what = "value");
+
+/// make sure the value is converted into a double precision floating number. throw otherwise.
+double ensureDouble(const QJsonValue val, QString what = "value");
+}
diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp
index 89cd71ed..effa1095 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, "<SESSION ID>");
in.replace(m_session->access_token, "<ACCESS TOKEN>");
in.replace(m_session->client_token, "<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,129 @@ 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<QString, QString> MinecraftProcess::getVariables() const
+{
+ QMap<QString, QString> 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());
+ args << "-Duser.language=en";
+ 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<QString, QString> getVariables() const;
+ QString substituteVariables(const QString &cmd) const;
+
+ QStringList javaArguments() const;
+
protected
slots:
void finish(int, QProcess::ExitStatus status);
diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp
index 07b123b6..172830bb 100644
--- a/logic/OneSixFTBInstance.cpp
+++ b/logic/OneSixFTBInstance.cpp
@@ -1,6 +1,6 @@
#include "OneSixFTBInstance.h"
-#include "OneSixVersion.h"
+#include "VersionFinal.h"
#include "OneSixLibrary.h"
#include "tasks/SequentialTask.h"
#include "ForgeInstaller.h"
@@ -10,76 +10,6 @@
#include "MultiMC.h"
#include "pathutils.h"
-class OneSixFTBInstanceForge : public Task
-{
- Q_OBJECT
-public:
- explicit OneSixFTBInstanceForge(const QString &version, OneSixFTBInstance *inst, QObject *parent = 0) :
- Task(parent), instance(inst), version("Forge " + version)
- {
- }
-
- void executeTask()
- {
- for (int i = 0; i < MMC->forgelist()->count(); ++i)
- {
- if (MMC->forgelist()->at(i)->name() == version)
- {
- forgeVersion = std::dynamic_pointer_cast<ForgeVersion>(MMC->forgelist()->at(i));
- break;
- }
- }
- if (!forgeVersion)
- {
- emitFailed(QString("Couldn't find forge version ") + version );
- return;
- }
- entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename);
- if (entry->stale)
- {
- setStatus(tr("Downloading Forge..."));
- fjob = new NetJob("Forge download");
- fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry));
- connect(fjob, &NetJob::failed, [this](){emitFailed(m_failReason);});
- connect(fjob, &NetJob::succeeded, this, &OneSixFTBInstanceForge::installForge);
- connect(fjob, &NetJob::progress, [this](qint64 c, qint64 total){ setProgress(100 * c / total); });
- fjob->start();
- }
- else
- {
- installForge();
- }
- }
-
-private
-slots:
- void installForge()
- {
- setStatus(tr("Installing Forge..."));
- QString forgePath = entry->getFullPath();
- ForgeInstaller forge(forgePath, forgeVersion->universal_url);
- if (!instance->reloadVersion())
- {
- emitFailed(tr("Couldn't load the version config"));
- return;
- }
- auto version = instance->getFullVersion();
- if (!forge.add(instance))
- {
- emitFailed(tr("Couldn't install Forge"));
- return;
- }
- emitSucceeded();
- }
-
-private:
- OneSixFTBInstance *instance;
- QString version;
- ForgeVersionPtr forgeVersion;
- MetaEntryPtr entry;
- NetJob *fjob;
-};
-
OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) :
OneSixInstance(rootDir, settings, parent)
{
@@ -87,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 148fbc09..ccc25845 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -19,7 +19,7 @@
#include "OneSixInstance_p.h"
#include "OneSixUpdate.h"
-#include "OneSixVersion.h"
+#include "VersionFinal.h"
#include "pathutils.h"
#include "logger/QsLog.h"
#include "assets/AssetsUtils.h"
@@ -27,6 +27,7 @@
#include "icons/IconList.h"
#include "MinecraftProcess.h"
#include "gui/dialogs/OneSixModEditDialog.h"
+#include <MMCError.h>
OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, QObject *parent)
: BaseInstance(new OneSixInstancePrivate(), rootDir, settings, parent)
@@ -34,15 +35,23 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings,
I_D(OneSixInstance);
d->m_settings->registerSetting("IntendedVersion", "");
d->m_settings->registerSetting("ShouldUpdate", false);
- d->version.reset(new OneSixVersion(this, this));
- d->vanillaVersion.reset(new OneSixVersion(this, this));
+ d->version.reset(new VersionFinal(this, this));
+ d->vanillaVersion.reset(new VersionFinal(this, this));
}
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
{
@@ -79,7 +88,7 @@ QString replaceTokensIn(QString text, QMap<QString, QString> with)
return result;
}
-QDir OneSixInstance::reconstructAssets(std::shared_ptr<OneSixVersion> version)
+QDir OneSixInstance::reconstructAssets(std::shared_ptr<VersionFinal> version)
{
QDir assetsDir = QDir("assets/");
QDir indexDir = QDir(PathCombine(assetsDir.path(), "indexes"));
@@ -316,25 +325,26 @@ QString OneSixInstance::currentVersionId() const
return intendedVersionId();
}
-bool OneSixInstance::reloadVersion(QWidget *widgetParent)
+void OneSixInstance::reloadVersion()
{
I_D(OneSixInstance);
- bool ret = d->version->reload(widgetParent, false, externalPatches());
- if (ret)
- {
- ret = d->vanillaVersion->reload(widgetParent, true, externalPatches());
- }
- if (ret)
+ try
{
+ d->version->reload(false, externalPatches());
+ d->vanillaVersion->reload(true, externalPatches());
d->m_flags.remove(VersionBrokenFlag);
emit versionReloaded();
}
- else
+ catch(MMCError & error)
{
+ d->version->clear();
+ d->vanillaVersion->clear();
d->m_flags.insert(VersionBrokenFlag);
+ //TODO: rethrow to show some error message(s)?
+ emit versionReloaded();
+ throw;
}
- return ret;
}
void OneSixInstance::clearVersion()
@@ -345,13 +355,13 @@ void OneSixInstance::clearVersion()
emit versionReloaded();
}
-std::shared_ptr<OneSixVersion> OneSixInstance::getFullVersion() const
+std::shared_ptr<VersionFinal> OneSixInstance::getFullVersion() const
{
I_D(const OneSixInstance);
return d->version;
}
-std::shared_ptr<OneSixVersion> OneSixInstance::getVanillaVersion() const
+std::shared_ptr<VersionFinal> OneSixInstance::getVanillaVersion() const
{
I_D(const OneSixInstance);
return d->vanillaVersion;
@@ -413,6 +423,23 @@ bool OneSixInstance::providesVersionFile() const
return false;
}
+bool OneSixInstance::reload()
+{
+ if(BaseInstance::reload())
+ {
+ try
+ {
+ reloadVersion();
+ return true;
+ }
+ catch (...)
+ {
+ return false;
+ }
+ }
+ return false;
+}
+
QString OneSixInstance::loaderModsDir() const
{
return PathCombine(minecraftRoot(), "mods");
diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h
index 06fd9de3..7a049922 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
@@ -53,14 +53,18 @@ public:
virtual QDialog *createModEditDialog(QWidget *parent) override;
- /// reload the full version json files. return true on success!
- bool reloadVersion(QWidget *widgetParent = 0);
+ /**
+ * 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
- std::shared_ptr<OneSixVersion> getFullVersion() const;
+ std::shared_ptr<VersionFinal> getFullVersion() const;
/// gets the current version info, but only for version.json
- std::shared_ptr<OneSixVersion> getVanillaVersion() const;
+ std::shared_ptr<VersionFinal> getVanillaVersion() const;
/// is the current version original, or custom?
virtual bool versionIsCustom() override;
@@ -75,10 +79,12 @@ public:
virtual QStringList externalPatches() const;
virtual bool providesVersionFile() const;
+ bool reload() override;
+
signals:
void versionReloaded();
private:
QStringList processMinecraftArgs(AuthSessionPtr account);
- QDir reconstructAssets(std::shared_ptr<OneSixVersion> version);
+ QDir reconstructAssets(std::shared_ptr<VersionFinal> version);
};
diff --git a/logic/OneSixInstance_p.h b/logic/OneSixInstance_p.h
index 0cc46f33..2dffa62c 100644
--- a/logic/OneSixInstance_p.h
+++ b/logic/OneSixInstance_p.h
@@ -16,13 +16,13 @@
#pragma once
#include "BaseInstance_p.h"
-#include "OneSixVersion.h"
+#include "VersionFinal.h"
#include "ModList.h"
struct OneSixInstancePrivate : public BaseInstancePrivate
{
- std::shared_ptr<OneSixVersion> version;
- std::shared_ptr<OneSixVersion> vanillaVersion;
+ std::shared_ptr<VersionFinal> version;