summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
Diffstat (limited to 'logic')
-rw-r--r--logic/BaseInstaller.cpp66
-rw-r--r--logic/BaseInstaller.h39
-rw-r--r--logic/DerpFTBInstance.cpp2
-rw-r--r--logic/DerpVersion.cpp47
-rw-r--r--logic/DerpVersion.h4
-rw-r--r--logic/DerpVersionBuilder.cpp37
-rw-r--r--logic/DerpVersionBuilder.h2
-rw-r--r--logic/ForgeInstaller.cpp48
-rw-r--r--logic/ForgeInstaller.h9
-rw-r--r--logic/LiteLoaderInstaller.cpp32
-rw-r--r--logic/LiteLoaderInstaller.h22
11 files changed, 232 insertions, 76 deletions
diff --git a/logic/BaseInstaller.cpp b/logic/BaseInstaller.cpp
new file mode 100644
index 00000000..74a8e909
--- /dev/null
+++ b/logic/BaseInstaller.cpp
@@ -0,0 +1,66 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "BaseInstaller.h"
+
+#include <QFile>
+
+#include "DerpVersion.h"
+#include "DerpLibrary.h"
+#include "DerpInstance.h"
+
+#include "cmdutils.h"
+
+BaseInstaller::BaseInstaller()
+{
+
+}
+
+bool BaseInstaller::isApplied(DerpInstance *on)
+{
+ return QFile::exists(filename(on->instanceRoot()));
+}
+
+bool BaseInstaller::add(DerpInstance *to)
+{
+ if (!patchesDir(to->instanceRoot()).exists())
+ {
+ QDir(to->instanceRoot()).mkdir("patches");
+ }
+
+ if (isApplied(to))
+ {
+ if (!remove(to))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool BaseInstaller::remove(DerpInstance *from)
+{
+ return QFile::remove(filename(from->instanceRoot()));
+}
+
+QString BaseInstaller::filename(const QString &root) const
+{
+ return patchesDir(root).absoluteFilePath(id() + ".json");
+}
+QDir BaseInstaller::patchesDir(const QString &root) const
+{
+ return QDir(root + "/patches/");
+}
diff --git a/logic/BaseInstaller.h b/logic/BaseInstaller.h
new file mode 100644
index 00000000..08f78bfc
--- /dev/null
+++ b/logic/BaseInstaller.h
@@ -0,0 +1,39 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <memory>
+
+class DerpInstance;
+class QDir;
+class QString;
+
+class BaseInstaller
+{
+public:
+ BaseInstaller();
+
+ virtual bool canApply(DerpInstance *instance) const { return true; }
+ bool isApplied(DerpInstance *on);
+
+ virtual bool add(DerpInstance *to);
+ virtual bool remove(DerpInstance *from);
+
+protected:
+ virtual QString id() const = 0;
+ QString filename(const QString &root) const;
+ QDir patchesDir(const QString &root) const;
+};
diff --git a/logic/DerpFTBInstance.cpp b/logic/DerpFTBInstance.cpp
index f9aeeca0..9b687461 100644
--- a/logic/DerpFTBInstance.cpp
+++ b/logic/DerpFTBInstance.cpp
@@ -61,7 +61,7 @@ slots:
return;
}
auto version = instance->getFullVersion();
- if (!forge.apply(version))
+ if (!forge.add(instance))
{
emitFailed(tr("Couldn't install Forge"));
return;
diff --git a/logic/DerpVersion.cpp b/logic/DerpVersion.cpp
index cabb2b24..f4a8dd97 100644
--- a/logic/DerpVersion.cpp
+++ b/logic/DerpVersion.cpp
@@ -44,6 +44,26 @@ void DerpVersion::clear()
libraries.clear();
}
+void DerpVersion::dump() const
+{
+ qDebug().nospace() << "DerpVersion("
+ << "\n\tid=" << id
+ << "\n\ttime=" << time
+ << "\n\treleaseTime=" << releaseTime
+ << "\n\ttype=" << type
+ << "\n\tassets=" << assets
+ << "\n\tprocessArguments=" << processArguments
+ << "\n\tminecraftArguments=" << minecraftArguments
+ << "\n\tminimumLauncherVersion=" << minimumLauncherVersion
+ << "\n\tmainClass=" << mainClass
+ << "\n\tlibraries=";
+ for (auto lib : libraries)
+ {
+ qDebug().nospace() << "\n\t\t" << lib.get();
+ }
+ qDebug().nospace() << "\n)";
+}
+
QList<std::shared_ptr<DerpLibrary> > DerpVersion::getActiveNormalLibs()
{
QList<std::shared_ptr<DerpLibrary> > output;
@@ -70,6 +90,16 @@ QList<std::shared_ptr<DerpLibrary> > DerpVersion::getActiveNativeLibs()
return output;
}
+std::shared_ptr<DerpVersion> DerpVersion::fromJson(const QJsonObject &obj)
+{
+ std::shared_ptr<DerpVersion> version(new DerpVersion(0));
+ if (DerpVersionBuilder::read(version.get(), obj))
+ {
+ return version;
+ }
+ return 0;
+}
+
QVariant DerpVersion::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
@@ -143,22 +173,7 @@ int DerpVersion::columnCount(const QModelIndex &parent) const
QDebug operator<<(QDebug &dbg, const DerpVersion *version)
{
- dbg.nospace() << "DerpVersion("
- << "\n\tid=" << version->id
- << "\n\ttime=" << version->time
- << "\n\treleaseTime=" << version->releaseTime
- << "\n\ttype=" << version->type
- << "\n\tassets=" << version->assets
- << "\n\tprocessArguments=" << version->processArguments
- << "\n\tminecraftArguments=" << version->minecraftArguments
- << "\n\tminimumLauncherVersion=" << version->minimumLauncherVersion
- << "\n\tmainClass=" << version->mainClass
- << "\n\tlibraries=";
- for (auto lib : version->libraries)
- {
- dbg.nospace() << "\n\t\t" << lib.get();
- }
- dbg.nospace() << "\n)";
+ version->dump();
return dbg.maybeSpace();
}
QDebug operator<<(QDebug &dbg, const DerpLibrary *library)
diff --git a/logic/DerpVersion.h b/logic/DerpVersion.h
index f2132ad8..4481d146 100644
--- a/logic/DerpVersion.h
+++ b/logic/DerpVersion.h
@@ -41,10 +41,14 @@ public:
bool reload(QWidget *widgetParent);
void clear();
+ void dump() const;
+
public:
QList<std::shared_ptr<DerpLibrary>> getActiveNormalLibs();
QList<std::shared_ptr<DerpLibrary>> getActiveNativeLibs();
+ static std::shared_ptr<DerpVersion> fromJson(const QJsonObject &obj);
+
// data members
public:
/// the ID - determines which jar to use! ACTUALLY IMPORTANT!
diff --git a/logic/DerpVersionBuilder.cpp b/logic/DerpVersionBuilder.cpp
index eb215cca..20f43404 100644
--- a/logic/DerpVersionBuilder.cpp
+++ b/logic/DerpVersionBuilder.cpp
@@ -29,6 +29,7 @@
#include "DerpVersion.h"
#include "DerpInstance.h"
#include "DerpRule.h"
+#include "logger/QsLog.h"
DerpVersionBuilder::DerpVersionBuilder()
{
@@ -44,6 +45,15 @@ bool DerpVersionBuilder::build(DerpVersion *version, DerpInstance *instance, QWi
return builder.build();
}
+bool DerpVersionBuilder::read(DerpVersion *version, const QJsonObject &obj)
+{
+ DerpVersionBuilder builder;
+ builder.m_version = version;
+ builder.m_instance = 0;
+ builder.m_widgetParent = 0;
+ return builder.read(obj);
+}
+
bool DerpVersionBuilder::build()
{
m_version->clear();
@@ -55,6 +65,7 @@ bool DerpVersionBuilder::build()
// version.json
{
+ QLOG_INFO() << "Reading version.json";
QJsonObject obj;
if (!read(QFileInfo(root.absoluteFilePath("version.json")), &obj))
{
@@ -73,6 +84,7 @@ bool DerpVersionBuilder::build()
QMap<int, QJsonObject> objects;
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
{
+ QLOG_INFO() << "Reading" << info.fileName();
QJsonObject obj;
if (!read(info, &obj))
{
@@ -87,6 +99,7 @@ bool DerpVersionBuilder::build()
}
for (auto object : objects.values())
{
+ qDebug() << "Applying object with order" << objects.key(object);
if (!apply(object))
{
return false;
@@ -98,6 +111,7 @@ bool DerpVersionBuilder::build()
{
if (QFile::exists(root.absoluteFilePath("custom.json")))
{
+ QLOG_INFO() << "Reading custom.json";
QJsonObject obj;
if (!read(QFileInfo(root.absoluteFilePath("custom.json")), &obj))
{
@@ -113,6 +127,13 @@ bool DerpVersionBuilder::build()
return true;
}
+bool DerpVersionBuilder::read(const QJsonObject &obj)
+{
+ m_version->clear();
+
+ return apply(obj);
+}
+
void applyString(const QJsonObject &obj, const QString &key, QString &out, const bool onlyOverride = true)
{
if (obj.contains(key) && obj.value(key).isString())
@@ -142,7 +163,9 @@ bool DerpVersionBuilder::apply(const QJsonObject &object)
{
applyString(object, "id", m_version->id);
applyString(object, "mainClass", m_version->mainClass);
+ applyString(object, "minecraftArguments", m_version->minecraftArguments, false);
applyString(object, "processArguments", m_version->processArguments, false);
+ if (m_version->minecraftArguments.isEmpty())
{
const QString toCompare = m_version->processArguments.toLower();
if (toCompare == "legacy")
@@ -158,7 +181,6 @@ bool DerpVersionBuilder::apply(const QJsonObject &object)
m_version->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}";
}
}
- applyString(object, "minecraftArguments", m_version->minecraftArguments, false);
applyString(object, "type", m_version->type);
applyString(object, "releaseTime", m_version->releaseTime);
applyString(object, "time", m_version->time);
@@ -282,6 +304,18 @@ bool DerpVersionBuilder::applyLibrary(const QJsonObject &lib, const DerpVersionB
std::shared_ptr<DerpLibrary> library;
+ if (lib.value("insert").toString() != "apply" && type == Add)
+ {
+ QMutableListIterator<std::shared_ptr<DerpLibrary> > it(m_version->libraries);
+ while (it.hasNext())
+ {
+ if (it.next()->rawName() == name)
+ {
+ it.remove();
+ }
+ }
+ }
+
if (lib.value("insert").toString() == "apply" && type == Add)
{
library = m_version->libraries[findLibrary(m_version->libraries, name)];
@@ -343,7 +377,6 @@ bool DerpVersionBuilder::applyLibrary(const QJsonObject &lib, const DerpVersionB
library->finalize();
if (type == Override)
{
- qDebug() << "appending" << library->rawName();
m_version->libraries.append(library);
}
else if (lib.value("insert").toString() != "apply")
diff --git a/logic/DerpVersionBuilder.h b/logic/DerpVersionBuilder.h
index 5354cb0e..b94cd8e9 100644
--- a/logic/DerpVersionBuilder.h
+++ b/logic/DerpVersionBuilder.h
@@ -28,6 +28,7 @@ class DerpVersionBuilder
DerpVersionBuilder();
public:
static bool build(DerpVersion *version, DerpInstance *instance, QWidget *widgetParent);
+ static bool read(DerpVersion *version, const QJsonObject &obj);
private:
DerpVersion *m_version;
@@ -42,6 +43,7 @@ private:
};
bool build();
+ bool read(const QJsonObject &obj);
void clear();
bool apply(const QJsonObject &object);
diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp
index 29735a7d..35663ddd 100644
--- a/logic/ForgeInstaller.cpp
+++ b/logic/ForgeInstaller.cpp
@@ -22,13 +22,13 @@
#include <pathutils.h>
#include <QStringList>
#include "MultiMC.h"
+#include "DerpInstance.h"
#include <QJsonDocument>
+#include <QJsonArray>
#include <QSaveFile>
#include <QCryptographicHash>
-// DERPFIX
-
ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
{
std::shared_ptr<DerpVersion> newVersion;
@@ -64,7 +64,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
// read the forge version info
{
- // DERPFIX newVersion = DerpVersion::fromJson(versionInfoVal.toObject());
+ newVersion = DerpVersion::fromJson(versionInfoVal.toObject());
if (!newVersion)
return;
}
@@ -109,12 +109,22 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
realVersionId = m_forge_version->id = installObj.value("minecraft").toString();
}
-bool ForgeInstaller::apply(std::shared_ptr<DerpVersion> to)
+bool ForgeInstaller::add(DerpInstance *to)
{
+ if (!BaseInstaller::add(to))
+ {
+ return false;
+ }
+
+ QJsonObject obj;
+ obj.insert("order", 5);
+
if (!m_forge_version)
return false;
int sliding_insert_window = 0;
{
+ QJsonArray librariesPlus;
+
// for each library in the version we are adding (except for the blacklisted)
QSet<QString> blacklist{"lwjgl", "lwjgl_util", "lwjgl-platform"};
for (auto lib : m_forge_version->libraries)
@@ -133,27 +143,43 @@ bool ForgeInstaller::apply(std::shared_ptr<DerpVersion> to)
if (blacklist.contains(libName))
continue;
- // find an entry that matches this one
+ QJsonObject libObj = lib->toJson();
+
bool found = false;
- for (auto tolib : to->libraries)
+ // find an entry that matches this one
+ for (auto tolib : to->getFullVersion()->libraries)
{
if (tolib->name() != libName)
continue;
found = true;
// replace lib
- tolib = lib;
+ libObj.insert("insert", QString("apply"));
break;
}
if (!found)
{
// add lib
- to->libraries.insert(sliding_insert_window, lib);
+ QJsonObject insertObj;
+ insertObj.insert("before", to->getFullVersion()->libraries.at(sliding_insert_window)->rawName());
+ libObj.insert("insert", insertObj);
sliding_insert_window++;
}
+ librariesPlus.append(libObj);
}
- to->mainClass = m_forge_version->mainClass;
- to->minecraftArguments = m_forge_version->minecraftArguments;
- to->processArguments = m_forge_version->processArguments;
+ obj.insert("+libraries", librariesPlus);
+ obj.insert("mainClass", m_forge_version->mainClass);
+ obj.insert("minecraftArguments", m_forge_version->minecraftArguments);
+ obj.insert("processArguments", m_forge_version->processArguments);
+ }
+
+ QFile file(filename(to->instanceRoot()));
+ if (!file.open(QFile::WriteOnly))
+ {
+ QLOG_ERROR() << "Error opening" << file.fileName() << "for reading:" << file.errorString();
+ return false;
}
+ file.write(QJsonDocument(obj).toJson());
+ file.close();
+
return true;
}
diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h
index 65cad87c..6490b5bf 100644
--- a/logic/ForgeInstaller.h
+++ b/logic/ForgeInstaller.h
@@ -14,17 +14,22 @@
*/
#pragma once
+
+#include "BaseInstaller.h"
+
#include <QString>
#include <memory>
class DerpVersion;
-class ForgeInstaller
+class ForgeInstaller : public BaseInstaller
{
public:
ForgeInstaller(QString filename, QString universal_url);
- bool apply(std::shared_ptr<DerpVersion> to);
+ bool add(DerpInstance *to) override;
+
+ QString id() const override { return "net.minecraftforge"; }
private:
// the version, read from the installer
diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp
index d582f03a..71c7011f 100644
--- a/logic/LiteLoaderInstaller.cpp
+++ b/logic/LiteLoaderInstaller.cpp
@@ -27,6 +27,7 @@
QMap<QString, QString> LiteLoaderInstaller::m_launcherWrapperVersionMapping;
LiteLoaderInstaller::LiteLoaderInstaller()
+ : BaseInstaller()
{
if (m_launcherWrapperVersionMapping.isEmpty())
{
@@ -42,24 +43,11 @@ bool LiteLoaderInstaller::canApply(DerpInstance *instance) const
return m_launcherWrapperVersionMapping.contains(instance->intendedVersionId());
}
-bool LiteLoaderInstaller::isApplied(DerpInstance *on)
-{
- return QFile::exists(filename(on->instanceRoot()));
-}
-
bool LiteLoaderInstaller::add(DerpInstance *to)
{
- if (!patchesDir(to->instanceRoot()).exists())
- {
- QDir(to->instanceRoot()).mkdir("patches");
- }
-
- if (isApplied(to))
+ if (!BaseInstaller::add(to))
{
- if (!remove(to))
- {
- return false;
- }
+ return false;
}
QJsonObject obj;
@@ -102,17 +90,3 @@ bool LiteLoaderInstaller::add(DerpInstance *to)
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 48ef4baf..c128ee22 100644
--- a/logic/LiteLoaderInstaller.h
+++ b/logic/LiteLoaderInstaller.h
@@ -14,30 +14,22 @@
*/
#pragma once
+
+#include "BaseInstaller.h"
+
#include <QString>
#include <QMap>
-#include <memory>
-class DerpVersion;
-class DerpInstance;
-class QDir;
-
-// TODO base class
-class LiteLoaderInstaller
+class LiteLoaderInstaller : public BaseInstaller
{
public:
LiteLoaderInstaller();
- bool canApply(DerpInstance *instance) const;
- bool isApplied(DerpInstance *on);
-
- bool add(DerpInstance *to);
- bool remove(DerpInstance *from);
+ bool canApply(DerpInstance *instance) const override;
+ bool add(DerpInstance *to) override;
private:
- virtual QString id() const { return "com.mumfrey.liteloader"; }
- QString filename(const QString &root) const;
- QDir patchesDir(const QString &root) const;
+ virtual QString id() const override { return "com.mumfrey.liteloader"; }
static QMap<QString, QString> m_launcherWrapperVersionMapping;
};