Merge pull request #1402 from Trial97/flame_import
feat:made flame instace creation use metadata for recommended version
This commit is contained in:
commit
6ffcfcd7e9
@ -57,15 +57,11 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
#include "meta/Index.h"
|
||||||
|
#include "meta/VersionList.h"
|
||||||
#include "minecraft/World.h"
|
#include "minecraft/World.h"
|
||||||
#include "minecraft/mod/tasks/LocalResourceParse.h"
|
#include "minecraft/mod/tasks/LocalResourceParse.h"
|
||||||
|
|
||||||
|
|
||||||
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
|
|
||||||
{ "1.4.2", "6.0.1.355" },
|
|
||||||
{ "1.4.7", "6.6.2.534" },
|
|
||||||
{ "1.5.2", "7.8.1.737" } };
|
|
||||||
|
|
||||||
static const FlameAPI api;
|
static const FlameAPI api;
|
||||||
|
|
||||||
bool FlameCreationTask::abort()
|
bool FlameCreationTask::abort()
|
||||||
@ -259,6 +255,56 @@ bool FlameCreationTask::updateInstance()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FlameCreationTask::getVersionForLoader(QString uid, QString loaderType, QString loaderVersion, QString mcVersion)
|
||||||
|
{
|
||||||
|
if (loaderVersion == "recommended") {
|
||||||
|
auto vlist = APPLICATION->metadataIndex()->get(uid);
|
||||||
|
if (!vlist) {
|
||||||
|
setError(tr("Failed to get local metadata index for %1").arg(uid));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vlist->isLoaded()) {
|
||||||
|
QEventLoop loadVersionLoop;
|
||||||
|
auto task = vlist->getLoadTask();
|
||||||
|
connect(task.get(), &Task::finished, &loadVersionLoop, &QEventLoop::quit);
|
||||||
|
if (!task->isRunning())
|
||||||
|
task->start();
|
||||||
|
|
||||||
|
loadVersionLoop.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto version : vlist->versions()) {
|
||||||
|
// first recommended build we find, we use.
|
||||||
|
if (!version->isRecommended())
|
||||||
|
continue;
|
||||||
|
auto reqs = version->requiredSet();
|
||||||
|
|
||||||
|
// filter by minecraft version, if the loader depends on a certain version.
|
||||||
|
// not all mod loaders depend on a given Minecraft version, so we won't do this
|
||||||
|
// filtering for those loaders.
|
||||||
|
if (loaderType == "forge") {
|
||||||
|
auto iter = std::find_if(reqs.begin(), reqs.end(), [mcVersion](const Meta::Require& req) {
|
||||||
|
return req.uid == "net.minecraft" && req.equalsVersion == mcVersion;
|
||||||
|
});
|
||||||
|
if (iter == reqs.end())
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return version->descriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
setError(tr("Failed to find version for %1 loader").arg(loaderType));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loaderVersion.isEmpty()) {
|
||||||
|
emitFailed(tr("No loader version set for modpack!"));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return loaderVersion;
|
||||||
|
}
|
||||||
|
|
||||||
bool FlameCreationTask::createInstance()
|
bool FlameCreationTask::createInstance()
|
||||||
{
|
{
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
@ -297,22 +343,29 @@ bool FlameCreationTask::createInstance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString forgeVersion;
|
QString loaderType;
|
||||||
QString fabricVersion;
|
QString loaderUid;
|
||||||
// TODO: is Quilt relevant here?
|
QString loaderVersion;
|
||||||
|
|
||||||
for (auto& loader : m_pack.minecraft.modLoaders) {
|
for (auto& loader : m_pack.minecraft.modLoaders) {
|
||||||
auto id = loader.id;
|
auto id = loader.id;
|
||||||
if (id.startsWith("forge-")) {
|
if (id.startsWith("forge-")) {
|
||||||
id.remove("forge-");
|
id.remove("forge-");
|
||||||
forgeVersion = id;
|
loaderType = "forge";
|
||||||
continue;
|
loaderUid = "net.minecraftforge";
|
||||||
}
|
} else if (loaderType == "fabric") {
|
||||||
if (id.startsWith("fabric-")) {
|
|
||||||
id.remove("fabric-");
|
id.remove("fabric-");
|
||||||
fabricVersion = id;
|
loaderType = "fabric";
|
||||||
|
loaderUid = "net.fabricmc.fabric-loader";
|
||||||
|
} else if (loaderType == "quilt") {
|
||||||
|
id.remove("quilt-");
|
||||||
|
loaderType = "quilt";
|
||||||
|
loaderUid = "org.quiltmc.quilt-loader";
|
||||||
|
} else {
|
||||||
|
logWarning(tr("Unknown mod loader in manifest: %1").arg(id));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
logWarning(tr("Unknown mod loader in manifest: %1").arg(id));
|
loaderVersion = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
|
QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
|
||||||
@ -329,19 +382,12 @@ bool FlameCreationTask::createInstance()
|
|||||||
auto components = instance.getPackProfile();
|
auto components = instance.getPackProfile();
|
||||||
components->buildingFromScratch();
|
components->buildingFromScratch();
|
||||||
components->setComponentVersion("net.minecraft", mcVersion, true);
|
components->setComponentVersion("net.minecraft", mcVersion, true);
|
||||||
if (!forgeVersion.isEmpty()) {
|
if (!loaderType.isEmpty()) {
|
||||||
// FIXME: dirty, nasty, hack. Proper solution requires dependency resolution and knowledge of the metadata.
|
auto version = getVersionForLoader(loaderUid, loaderType, loaderVersion, mcVersion);
|
||||||
if (forgeVersion == "recommended") {
|
if (version.isEmpty())
|
||||||
if (forgemap.contains(mcVersion)) {
|
return false;
|
||||||
forgeVersion = forgemap[mcVersion];
|
components->setComponentVersion(loaderUid, version);
|
||||||
} else {
|
|
||||||
logWarning(tr("Could not map recommended Forge version for Minecraft %1").arg(mcVersion));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
components->setComponentVersion("net.minecraftforge", forgeVersion);
|
|
||||||
}
|
|
||||||
if (!fabricVersion.isEmpty())
|
|
||||||
components->setComponentVersion("net.fabricmc.fabric-loader", fabricVersion);
|
|
||||||
|
|
||||||
if (m_instIcon != "default") {
|
if (m_instIcon != "default") {
|
||||||
instance.setIconKey(m_instIcon);
|
instance.setIconKey(m_instIcon);
|
||||||
@ -545,7 +591,6 @@ void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
|
|||||||
setAbortable(true);
|
setAbortable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FlameCreationTask::validateZIPResouces()
|
void FlameCreationTask::validateZIPResouces()
|
||||||
{
|
{
|
||||||
qDebug() << "Validating whether resources stored as .zip are in the right place";
|
qDebug() << "Validating whether resources stored as .zip are in the right place";
|
||||||
|
@ -57,10 +57,7 @@ class FlameCreationTask final : public InstanceCreationTask {
|
|||||||
QString id,
|
QString id,
|
||||||
QString version_id,
|
QString version_id,
|
||||||
QString original_instance_id = {})
|
QString original_instance_id = {})
|
||||||
: InstanceCreationTask()
|
: InstanceCreationTask(), m_parent(parent), m_managed_id(std::move(id)), m_managed_version_id(std::move(version_id))
|
||||||
, m_parent(parent)
|
|
||||||
, m_managed_id(std::move(id))
|
|
||||||
, m_managed_version_id(std::move(version_id))
|
|
||||||
{
|
{
|
||||||
setStagingPath(staging_path);
|
setStagingPath(staging_path);
|
||||||
setParentSettings(global_settings);
|
setParentSettings(global_settings);
|
||||||
@ -78,6 +75,7 @@ class FlameCreationTask final : public InstanceCreationTask {
|
|||||||
void setupDownloadJob(QEventLoop&);
|
void setupDownloadJob(QEventLoop&);
|
||||||
void copyBlockedMods(QList<BlockedMod> const& blocked_mods);
|
void copyBlockedMods(QList<BlockedMod> const& blocked_mods);
|
||||||
void validateZIPResouces();
|
void validateZIPResouces();
|
||||||
|
QString getVersionForLoader(QString uid, QString loaderType, QString version, QString mcVersion);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget* m_parent = nullptr;
|
QWidget* m_parent = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user