Work towards liteloader support. Fix creating new instance
This commit is contained in:
parent
d166b48072
commit
0a592ab99b
@ -96,7 +96,7 @@ void DerpModEditDialog::updateVersionControls()
|
|||||||
{
|
{
|
||||||
bool customVersion = m_inst->versionIsCustom();
|
bool customVersion = m_inst->versionIsCustom();
|
||||||
ui->forgeBtn->setEnabled(true);
|
ui->forgeBtn->setEnabled(true);
|
||||||
ui->liteloaderBtn->setEnabled(LiteLoaderInstaller(m_inst->intendedVersionId()).canApply());
|
ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst));
|
||||||
ui->customEditorBtn->setEnabled(customVersion);
|
ui->customEditorBtn->setEnabled(customVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,8 +165,8 @@ void DerpModEditDialog::on_forgeBtn_clicked()
|
|||||||
|
|
||||||
void DerpModEditDialog::on_liteloaderBtn_clicked()
|
void DerpModEditDialog::on_liteloaderBtn_clicked()
|
||||||
{
|
{
|
||||||
LiteLoaderInstaller liteloader(m_inst->intendedVersionId());
|
LiteLoaderInstaller liteloader;
|
||||||
if (!liteloader.canApply())
|
if (!liteloader.canApply(m_inst))
|
||||||
{
|
{
|
||||||
QMessageBox::critical(
|
QMessageBox::critical(
|
||||||
this, tr("LiteLoader"),
|
this, tr("LiteLoader"),
|
||||||
@ -174,7 +174,7 @@ void DerpModEditDialog::on_liteloaderBtn_clicked()
|
|||||||
"into this version of Minecraft"));
|
"into this version of Minecraft"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!liteloader.apply(m_version))
|
if (!liteloader.add(m_inst))
|
||||||
{
|
{
|
||||||
QMessageBox::critical(
|
QMessageBox::critical(
|
||||||
this, tr("LiteLoader"),
|
this, tr("LiteLoader"),
|
||||||
|
@ -35,9 +35,15 @@ DerpInstance::DerpInstance(const QString &rootDir, SettingsObject *settings, QOb
|
|||||||
d->m_settings->registerSetting("IntendedVersion", "");
|
d->m_settings->registerSetting("IntendedVersion", "");
|
||||||
d->m_settings->registerSetting("ShouldUpdate", false);
|
d->m_settings->registerSetting("ShouldUpdate", false);
|
||||||
d->version.reset(new DerpVersion(this, this));
|
d->version.reset(new DerpVersion(this, this));
|
||||||
|
if (QDir(instanceRoot()).exists("version.json"))
|
||||||
|
{
|
||||||
reloadFullVersion();
|
reloadFullVersion();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clearFullVersion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<Task> DerpInstance::doUpdate(bool only_prepare)
|
std::shared_ptr<Task> DerpInstance::doUpdate(bool only_prepare)
|
||||||
{
|
{
|
||||||
@ -280,9 +286,8 @@ bool DerpInstance::setIntendedVersionId(QString version)
|
|||||||
{
|
{
|
||||||
settings().set("IntendedVersion", version);
|
settings().set("IntendedVersion", version);
|
||||||
setShouldUpdate(true);
|
setShouldUpdate(true);
|
||||||
auto pathOrig = PathCombine(instanceRoot(), "version.json");
|
QFile::remove(PathCombine(instanceRoot(), "version.json"));
|
||||||
QFile::remove(pathOrig);
|
clearFullVersion();
|
||||||
reloadFullVersion();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,6 +332,13 @@ bool DerpInstance::reloadFullVersion(QWidget *widgetParent)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DerpInstance::clearFullVersion()
|
||||||
|
{
|
||||||
|
I_D(DerpInstance);
|
||||||
|
d->version->clear();
|
||||||
|
emit versionReloaded();
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<DerpVersion> DerpInstance::getFullVersion()
|
std::shared_ptr<DerpVersion> DerpInstance::getFullVersion()
|
||||||
{
|
{
|
||||||
I_D(DerpInstance);
|
I_D(DerpInstance);
|
||||||
|
@ -53,6 +53,8 @@ public:
|
|||||||
|
|
||||||
/// reload the full version json files. return true on success!
|
/// reload the full version json files. return true on success!
|
||||||
bool reloadFullVersion(QWidget *widgetParent = 0);
|
bool reloadFullVersion(QWidget *widgetParent = 0);
|
||||||
|
/// clears all version information in preparation for an update
|
||||||
|
void clearFullVersion();
|
||||||
/// get the current full version info
|
/// get the current full version info
|
||||||
std::shared_ptr<DerpVersion> getFullVersion();
|
std::shared_ptr<DerpVersion> getFullVersion();
|
||||||
/// is the current version original, or custom?
|
/// is the current version original, or custom?
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
DerpVersion::DerpVersion(DerpInstance *instance, QObject *parent)
|
DerpVersion::DerpVersion(DerpInstance *instance, QObject *parent)
|
||||||
: QAbstractListModel(parent), m_instance(instance)
|
: QAbstractListModel(parent), m_instance(instance)
|
||||||
{
|
{
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DerpVersion::reload(QWidget *widgetParent)
|
bool DerpVersion::reload(QWidget *widgetParent)
|
||||||
@ -29,6 +30,20 @@ bool DerpVersion::reload(QWidget *widgetParent)
|
|||||||
return DerpVersionBuilder::build(this, m_instance, 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> > DerpVersion::getActiveNormalLibs()
|
||||||
{
|
{
|
||||||
QList<std::shared_ptr<DerpLibrary> > output;
|
QList<std::shared_ptr<DerpLibrary> > output;
|
||||||
|
@ -39,6 +39,7 @@ public:
|
|||||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
bool reload(QWidget *widgetParent);
|
bool reload(QWidget *widgetParent);
|
||||||
|
void clear();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<std::shared_ptr<DerpLibrary>> getActiveNormalLibs();
|
QList<std::shared_ptr<DerpLibrary>> getActiveNormalLibs();
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "DerpVersion.h"
|
#include "DerpVersion.h"
|
||||||
#include "DerpInstance.h"
|
#include "DerpInstance.h"
|
||||||
@ -45,7 +46,7 @@ bool DerpVersionBuilder::build(DerpVersion *version, DerpInstance *instance, QWi
|
|||||||
|
|
||||||
bool DerpVersionBuilder::build()
|
bool DerpVersionBuilder::build()
|
||||||
{
|
{
|
||||||
clear();
|
m_version->clear();
|
||||||
|
|
||||||
QDir root(m_instance->instanceRoot());
|
QDir root(m_instance->instanceRoot());
|
||||||
QDir patches(root.absoluteFilePath("patches/"));
|
QDir patches(root.absoluteFilePath("patches/"));
|
||||||
@ -112,20 +113,6 @@ bool DerpVersionBuilder::build()
|
|||||||
return true;
|
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)
|
void applyString(const QJsonObject &obj, const QString &key, QString &out)
|
||||||
{
|
{
|
||||||
if (obj.contains(key) && obj.value(key).isString())
|
if (obj.contains(key) && obj.value(key).isString())
|
||||||
@ -181,6 +168,7 @@ bool DerpVersionBuilder::apply(const QJsonObject &object)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// libraries
|
// libraries
|
||||||
|
if (object.contains("libraries"))
|
||||||
{
|
{
|
||||||
auto librariesValue = object.value("libraries");
|
auto librariesValue = object.value("libraries");
|
||||||
if (!librariesValue.isArray())
|
if (!librariesValue.isArray())
|
||||||
|
@ -15,12 +15,18 @@
|
|||||||
|
|
||||||
#include "LiteLoaderInstaller.h"
|
#include "LiteLoaderInstaller.h"
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
|
#include "logger/QsLog.h"
|
||||||
|
|
||||||
#include "DerpVersion.h"
|
#include "DerpVersion.h"
|
||||||
#include "DerpLibrary.h"
|
#include "DerpLibrary.h"
|
||||||
|
#include "DerpInstance.h"
|
||||||
|
|
||||||
QMap<QString, QString> LiteLoaderInstaller::m_launcherWrapperVersionMapping;
|
QMap<QString, QString> LiteLoaderInstaller::m_launcherWrapperVersionMapping;
|
||||||
|
|
||||||
LiteLoaderInstaller::LiteLoaderInstaller(const QString &mcVersion) : m_mcVersion(mcVersion)
|
LiteLoaderInstaller::LiteLoaderInstaller()
|
||||||
{
|
{
|
||||||
if (m_launcherWrapperVersionMapping.isEmpty())
|
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);
|
|
||||||
|
|
||||||
to->mainClass = "net.minecraft.launchwrapper.Launch";
|
|
||||||
if (!to->minecraftArguments.contains(
|
|
||||||
" --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker"))
|
|
||||||
{
|
|
||||||
to->minecraftArguments.append(
|
|
||||||
" --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LiteLoaderInstaller::add(DerpInstance *to)
|
||||||
|
{
|
||||||
|
if (!patchesDir(to->instanceRoot()).exists())
|
||||||
|
{
|
||||||
|
QDir(to->instanceRoot()).mkdir("patches");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isApplied(to))
|
||||||
|
{
|
||||||
|
if (!remove(to))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject obj;
|
||||||
|
|
||||||
|
obj.insert("mainClass", QString("net.minecraft.launchwrapper.Launch"));
|
||||||
|
obj.insert("+minecraftArguments", QString(" --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker"));
|
||||||
|
obj.insert("order", 10);
|
||||||
|
|
||||||
|
QJsonArray libraries;
|
||||||
|
|
||||||
|
// launchwrapper
|
||||||
|
{
|
||||||
|
DerpLibrary launchwrapperLib("net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[to->intendedVersionId()]);
|
||||||
|
launchwrapperLib.finalize();
|
||||||
|
QJsonObject lwLibObj = launchwrapperLib.toJson();
|
||||||
|
lwLibObj.insert("insert", QString("beginning"));
|
||||||
|
libraries.append(lwLibObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.insert("+libraries", libraries);
|
||||||
|
|
||||||
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiteLoaderInstaller::applyLaunchwrapper(std::shared_ptr<DerpVersion> to)
|
bool LiteLoaderInstaller::remove(DerpInstance *from)
|
||||||
{
|
{
|
||||||
const QString intendedVersion = m_launcherWrapperVersionMapping[m_mcVersion];
|
return QFile::remove(filename(from->instanceRoot()));
|
||||||
|
|
||||||
QMutableListIterator<std::shared_ptr<DerpLibrary>> it(to->libraries);
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
it.next();
|
|
||||||
if (it.value()->rawName().startsWith("net.minecraft:launchwrapper:"))
|
|
||||||
{
|
|
||||||
if (it.value()->version() >= intendedVersion)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<DerpLibrary> lib(new DerpLibrary(
|
QString LiteLoaderInstaller::filename(const QString &root) const
|
||||||
"net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[m_mcVersion]));
|
|
||||||
lib->finalize();
|
|
||||||
to->libraries.prepend(lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LiteLoaderInstaller::applyLiteLoader(std::shared_ptr<DerpVersion> to)
|
|
||||||
{
|
{
|
||||||
QMutableListIterator<std::shared_ptr<DerpLibrary>> it(to->libraries);
|
return patchesDir(root).absoluteFilePath(id() + ".json");
|
||||||
while (it.hasNext())
|
}
|
||||||
|
QDir LiteLoaderInstaller::patchesDir(const QString &root) const
|
||||||
{
|
{
|
||||||
it.next();
|
return QDir(root + "/patches/");
|
||||||
if (it.value()->rawName().startsWith("com.mumfrey:liteloader:"))
|
|
||||||
{
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
@ -19,21 +19,25 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class DerpVersion;
|
class DerpVersion;
|
||||||
|
class DerpInstance;
|
||||||
|
class QDir;
|
||||||
|
|
||||||
|
// TODO base class
|
||||||
class LiteLoaderInstaller
|
class LiteLoaderInstaller
|
||||||
{
|
{
|
||||||
public:
|
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:
|
private:
|
||||||
QString m_mcVersion;
|
virtual QString id() const { return "com.mumfrey.liteloader"; }
|
||||||
|
QString filename(const QString &root) const;
|
||||||
void applyLaunchwrapper(std::shared_ptr<DerpVersion> to);
|
QDir patchesDir(const QString &root) const;
|
||||||
void applyLiteLoader(std::shared_ptr<DerpVersion> to);
|
|
||||||
|
|
||||||
static QMap<QString, QString> m_launcherWrapperVersionMapping;
|
static QMap<QString, QString> m_launcherWrapperVersionMapping;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user