summaryrefslogtreecommitdiffstats
path: root/logic/LiteLoaderInstaller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'logic/LiteLoaderInstaller.cpp')
-rw-r--r--logic/LiteLoaderInstaller.cpp117
1 files changed, 67 insertions, 50 deletions
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/");
}