summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2014-01-22 15:20:48 +0100
committerJan Dalheimer <jan@dalheimer.de>2014-01-22 15:20:48 +0100
commit0a592ab99bc68ad918f74206edf2a77cc257683c (patch)
tree9222c666b871f0e49bb1b6150d102bca8d2b552c /logic
parentd166b4807223ec7cd0df6f26e05a2f364dc6121c (diff)
downloadMultiMC-0a592ab99bc68ad918f74206edf2a77cc257683c.tar
MultiMC-0a592ab99bc68ad918f74206edf2a77cc257683c.tar.gz
MultiMC-0a592ab99bc68ad918f74206edf2a77cc257683c.tar.lz
MultiMC-0a592ab99bc68ad918f74206edf2a77cc257683c.tar.xz
MultiMC-0a592ab99bc68ad918f74206edf2a77cc257683c.zip
Work towards liteloader support. Fix creating new instance
Diffstat (limited to 'logic')
-rw-r--r--logic/DerpInstance.cpp22
-rw-r--r--logic/DerpInstance.h2
-rw-r--r--logic/DerpVersion.cpp15
-rw-r--r--logic/DerpVersion.h1
-rw-r--r--logic/DerpVersionBuilder.cpp18
-rw-r--r--logic/LiteLoaderInstaller.cpp117
-rw-r--r--logic/LiteLoaderInstaller.h18
7 files changed, 116 insertions, 77 deletions
diff --git a/logic/DerpInstance.cpp b/logic/DerpInstance.cpp
index 672ba6c4..e6b92b1f 100644
--- a/logic/DerpInstance.cpp
+++ b/logic/DerpInstance.cpp
@@ -35,10 +35,16 @@ DerpInstance::DerpInstance(const QString &rootDir, SettingsObject *settings, QOb
d->m_settings->registerSetting("IntendedVersion", "");
d->m_settings->registerSetting("ShouldUpdate", false);
d->version.reset(new DerpVersion(this, this));
- reloadFullVersion();
+ if (QDir(instanceRoot()).exists("version.json"))
+ {
+ reloadFullVersion();
+ }
+ else
+ {
+ clearFullVersion();
+ }
}
-
std::shared_ptr<Task> DerpInstance::doUpdate(bool only_prepare)
{
return std::shared_ptr<Task>(new DerpUpdate(this, only_prepare));
@@ -280,9 +286,8 @@ bool DerpInstance::setIntendedVersionId(QString version)
{
settings().set("IntendedVersion", version);
setShouldUpdate(true);
- auto pathOrig = PathCombine(instanceRoot(), "version.json");
- QFile::remove(pathOrig);
- reloadFullVersion();
+ QFile::remove(PathCombine(instanceRoot(), "version.json"));
+ clearFullVersion();
return true;
}
@@ -327,6 +332,13 @@ bool DerpInstance::reloadFullVersion(QWidget *widgetParent)
return ret;
}
+void DerpInstance::clearFullVersion()
+{
+ I_D(DerpInstance);
+ d->version->clear();
+ emit versionReloaded();
+}
+
std::shared_ptr<DerpVersion> DerpInstance::getFullVersion()
{
I_D(DerpInstance);
diff --git a/logic/DerpInstance.h b/logic/DerpInstance.h
index 37d3df52..46f953c0 100644
--- a/logic/DerpInstance.h
+++ b/logic/DerpInstance.h
@@ -53,6 +53,8 @@ public:
/// reload the full version json files. return true on success!
bool reloadFullVersion(QWidget *widgetParent = 0);
+ /// clears all version information in preparation for an update
+ void clearFullVersion();
/// get the current full version info
std::shared_ptr<DerpVersion> getFullVersion();
/// is the current version original, or custom?
diff --git a/logic/DerpVersion.cpp b/logic/DerpVersion.cpp
index f13ac620..cabb2b24 100644
--- a/logic/DerpVersion.cpp
+++ b/logic/DerpVersion.cpp
@@ -22,6 +22,7 @@
DerpVersion::DerpVersion(DerpInstance *instance, QObject *parent)
: QAbstractListModel(parent), m_instance(instance)
{
+ clear();
}
bool DerpVersion::reload(QWidget *widgetParent)
@@ -29,6 +30,20 @@ bool DerpVersion::reload(QWidget *widgetParent)
return DerpVersionBuilder::build(this, m_instance, widgetParent);
}
+void DerpVersion::clear()
+{
+ id.clear();
+ time.clear();
+ releaseTime.clear();
+ type.clear();
+ assets.clear();
+ processArguments.clear();
+ minecraftArguments.clear();
+ minimumLauncherVersion = 0xDEADBEAF;
+ mainClass.clear();
+ libraries.clear();
+}
+
QList<std::shared_ptr<DerpLibrary> > DerpVersion::getActiveNormalLibs()
{
QList<std::shared_ptr<DerpLibrary> > output;
diff --git a/logic/DerpVersion.h b/logic/DerpVersion.h
index cadfa850..f2132ad8 100644
--- a/logic/DerpVersion.h
+++ b/logic/DerpVersion.h
@@ -39,6 +39,7 @@ public:
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
bool reload(QWidget *widgetParent);
+ void clear();
public:
QList<std::shared_ptr<DerpLibrary>> getActiveNormalLibs();
diff --git a/logic/DerpVersionBuilder.cpp b/logic/DerpVersionBuilder.cpp
index d8091f32..b0da8205 100644
--- a/logic/DerpVersionBuilder.cpp
+++ b/logic/DerpVersionBuilder.cpp
@@ -24,6 +24,7 @@
#include <QMessageBox>
#include <QObject>
#include <QDir>
+#include <QDebug>
#include "DerpVersion.h"
#include "DerpInstance.h"
@@ -45,7 +46,7 @@ bool DerpVersionBuilder::build(DerpVersion *version, DerpInstance *instance, QWi
bool DerpVersionBuilder::build()
{
- clear();
+ m_version->clear();
QDir root(m_instance->instanceRoot());
QDir patches(root.absoluteFilePath("patches/"));
@@ -112,20 +113,6 @@ bool DerpVersionBuilder::build()
return true;
}
-void DerpVersionBuilder::clear()
-{
- m_version->id.clear();
- m_version->time.clear();
- m_version->releaseTime.clear();
- m_version->type.clear();
- m_version->assets.clear();
- m_version->processArguments.clear();
- m_version->minecraftArguments.clear();
- m_version->minimumLauncherVersion = 0xDEADBEAF;
- m_version->mainClass.clear();
- m_version->libraries.clear();
-}
-
void applyString(const QJsonObject &obj, const QString &key, QString &out)
{
if (obj.contains(key) && obj.value(key).isString())
@@ -181,6 +168,7 @@ bool DerpVersionBuilder::apply(const QJsonObject &object)
}
// libraries
+ if (object.contains("libraries"))
{
auto librariesValue = object.value("libraries");
if (!librariesValue.isArray())
diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp
index 8a120eab..8aed47e7 100644
--- a/logic/LiteLoaderInstaller.cpp
+++ b/logic/LiteLoaderInstaller.cpp
@@ -15,12 +15,18 @@
#include "LiteLoaderInstaller.h"
+#include <QJsonArray>
+#include <QJsonDocument>
+
+#include "logger/QsLog.h"
+
#include "DerpVersion.h"
#include "DerpLibrary.h"
+#include "DerpInstance.h"
QMap<QString, QString> LiteLoaderInstaller::m_launcherWrapperVersionMapping;
-LiteLoaderInstaller::LiteLoaderInstaller(const QString &mcVersion) : m_mcVersion(mcVersion)
+LiteLoaderInstaller::LiteLoaderInstaller()
{
if (m_launcherWrapperVersionMapping.isEmpty())
{
@@ -31,71 +37,82 @@ LiteLoaderInstaller::LiteLoaderInstaller(const QString &mcVersion) : m_mcVersion
}
}
-bool LiteLoaderInstaller::canApply() const
+bool LiteLoaderInstaller::canApply(DerpInstance *instance) const
{
- return m_launcherWrapperVersionMapping.contains(m_mcVersion);
+ return m_launcherWrapperVersionMapping.contains(instance->intendedVersionId());
}
-bool LiteLoaderInstaller::apply(std::shared_ptr<DerpVersion> to)
+bool LiteLoaderInstaller::isApplied(DerpInstance *on)
{
- // DERPFIX
+ return QFile::exists(filename(on->instanceRoot()));
+}
- applyLaunchwrapper(to);
- applyLiteLoader(to);
+bool LiteLoaderInstaller::add(DerpInstance *to)
+{
+ if (!patchesDir(to->instanceRoot()).exists())
+ {
+ QDir(to->instanceRoot()).mkdir("patches");
+ }
- to->mainClass = "net.minecraft.launchwrapper.Launch";
- if (!to->minecraftArguments.contains(
- " --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker"))
+ if (isApplied(to))
{
- to->minecraftArguments.append(
- " --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker");
+ if (!remove(to))
+ {
+ return false;
+ }
}
- return true;
-}
+ QJsonObject obj;
-void LiteLoaderInstaller::applyLaunchwrapper(std::shared_ptr<DerpVersion> to)
-{
- const QString intendedVersion = m_launcherWrapperVersionMapping[m_mcVersion];
+ obj.insert("mainClass", QString("net.minecraft.launchwrapper.Launch"));
+ obj.insert("+minecraftArguments", QString(" --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker"));
+ obj.insert("order", 10);
+
+ QJsonArray libraries;
- QMutableListIterator<std::shared_ptr<DerpLibrary>> it(to->libraries);
- while (it.hasNext())
+ // launchwrapper
{
- it.next();
- if (it.value()->rawName().startsWith("net.minecraft:launchwrapper:"))
- {
- if (it.value()->version() >= intendedVersion)
- {
- return;
- }
- else
- {
- it.remove();
- }
- }
+ DerpLibrary launchwrapperLib("net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[to->intendedVersionId()]);
+ launchwrapperLib.finalize();
+ QJsonObject lwLibObj = launchwrapperLib.toJson();
+ lwLibObj.insert("insert", QString("beginning"));
+ libraries.append(lwLibObj);
}
- std::shared_ptr<DerpLibrary> lib(new DerpLibrary(
- "net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[m_mcVersion]));
- lib->finalize();
- to->libraries.prepend(lib);
-}
+ // liteloader
+ {
+ DerpLibrary liteloaderLib("com.mumfrey:liteloader:" + to->intendedVersionId());
+ liteloaderLib.setBaseUrl("http://dl.liteloader.com/versions/");
+ liteloaderLib.finalize();
+ QJsonObject llLibObj = liteloaderLib.toJson();
+ llLibObj.insert("insert", QString("beginning"));
+ libraries.append(llLibObj);
+ }
-void LiteLoaderInstaller::applyLiteLoader(std::shared_ptr<DerpVersion> to)
-{
- QMutableListIterator<std::shared_ptr<DerpLibrary>> it(to->libraries);
- while (it.hasNext())
+ obj.insert("+libraries", libraries);
+
+ QFile file(filename(to->instanceRoot()));
+ if (!file.open(QFile::WriteOnly))
{
- it.next();
- if (it.value()->rawName().startsWith("com.mumfrey:liteloader:"))
- {
- it.remove();
- }
+ QLOG_ERROR() << "Error opening" << file.fileName() << "for reading:" << file.errorString();
+ return false;
}
+ file.write(QJsonDocument(obj).toJson());
+ file.close();
- std::shared_ptr<DerpLibrary> lib(
- new DerpLibrary("com.mumfrey:liteloader:" + m_mcVersion));
- lib->setBaseUrl("http://dl.liteloader.com/versions/");
- lib->finalize();
- to->libraries.prepend(lib);
+ return true;
+}
+
+bool LiteLoaderInstaller::remove(DerpInstance *from)
+{
+ return QFile::remove(filename(from->instanceRoot()));
+}
+
+QString LiteLoaderInstaller::filename(const QString &root) const
+{
+ return patchesDir(root).absoluteFilePath(id() + ".json");
+}
+QDir LiteLoaderInstaller::patchesDir(const QString &root) const
+{
+ return QDir(root + "/patches/");
}
diff --git a/logic/LiteLoaderInstaller.h b/logic/LiteLoaderInstaller.h
index d7b8ce77..48ef4baf 100644
--- a/logic/LiteLoaderInstaller.h
+++ b/logic/LiteLoaderInstaller.h
@@ -19,21 +19,25 @@
#include <memory>
class DerpVersion;
+class DerpInstance;
+class QDir;
+// TODO base class
class LiteLoaderInstaller
{
public:
- LiteLoaderInstaller(const QString &mcVersion);
+ LiteLoaderInstaller();
- bool canApply() const;
+ bool canApply(DerpInstance *instance) const;
+ bool isApplied(DerpInstance *on);
- bool apply(std::shared_ptr<DerpVersion> to);
+ bool add(DerpInstance *to);
+ bool remove(DerpInstance *from);
private:
- QString m_mcVersion;
-
- void applyLaunchwrapper(std::shared_ptr<DerpVersion> to);
- void applyLiteLoader(std::shared_ptr<DerpVersion> to);
+ virtual QString id() const { return "com.mumfrey.liteloader"; }
+ QString filename(const QString &root) const;
+ QDir patchesDir(const QString &root) const;
static QMap<QString, QString> m_launcherWrapperVersionMapping;
};