Merge pull request #3729 from jamierocks/atl-loader-targets
Various ATLauncher improvements and bug fixes
This commit is contained in:
commit
2f1e8e82a3
@ -18,8 +18,9 @@
|
||||
|
||||
namespace ATLauncher {
|
||||
|
||||
PackInstallTask::PackInstallTask(QString pack, QString version)
|
||||
PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString pack, QString version)
|
||||
{
|
||||
m_support = support;
|
||||
m_pack = pack;
|
||||
m_version_name = version;
|
||||
}
|
||||
@ -154,21 +155,54 @@ QString PackInstallTask::getVersionForLoader(QString uid)
|
||||
auto vlist = ENV.metadataIndex()->get(uid);
|
||||
if(!vlist)
|
||||
{
|
||||
emitFailed(tr("Failed to get local metadata index for ") + uid);
|
||||
emitFailed(tr("Failed to get local metadata index for %1").arg(uid));
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
// todo: filter by Minecraft version
|
||||
if(!vlist->isLoaded()) {
|
||||
vlist->load(Net::Mode::Online);
|
||||
}
|
||||
|
||||
if(m_version.loader.recommended || m_version.loader.latest) {
|
||||
for (int i = 0; i < vlist->versions().size(); i++) {
|
||||
auto version = vlist->versions().at(i);
|
||||
auto reqs = version->requires();
|
||||
|
||||
// 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 (m_version.loader.type != "fabric") {
|
||||
auto iter = std::find_if(reqs.begin(), reqs.end(), [](const Meta::Require &req) {
|
||||
return req.uid == "net.minecraft";
|
||||
});
|
||||
if (iter == reqs.end()) continue;
|
||||
if (iter->equalsVersion != m_version.minecraft) continue;
|
||||
}
|
||||
|
||||
if (m_version.loader.recommended) {
|
||||
return vlist.get()->getRecommended().get()->descriptor();
|
||||
// first recommended build we find, we use.
|
||||
if (!version->isRecommended()) continue;
|
||||
}
|
||||
else if(m_version.loader.latest) {
|
||||
return vlist.get()->at(0)->descriptor();
|
||||
|
||||
return version->descriptor();
|
||||
}
|
||||
|
||||
emitFailed(tr("Failed to find version for %1 loader").arg(m_version.loader.type));
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
else if(m_version.loader.choose) {
|
||||
// todo: implement
|
||||
// Fabric Loader doesn't depend on a given Minecraft version.
|
||||
if (m_version.loader.type == "fabric") {
|
||||
return m_support->chooseVersion(vlist, Q_NULLPTR);
|
||||
}
|
||||
|
||||
return m_support->chooseVersion(vlist, m_version.minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_version.loader.version == Q_NULLPTR || m_version.loader.version.isEmpty()) {
|
||||
emitFailed(tr("No loader version set for modpack!"));
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
return m_version.loader.version;
|
||||
@ -428,6 +462,9 @@ void PackInstallTask::downloadMods()
|
||||
jarmods.clear();
|
||||
jobPtr.reset(new NetJob(tr("Mod download")));
|
||||
for(const auto& mod : m_version.mods) {
|
||||
// skip non-client mods
|
||||
if (!mod.client) continue;
|
||||
|
||||
// skip optional mods for now
|
||||
if(mod.optional) continue;
|
||||
|
||||
@ -451,7 +488,6 @@ void PackInstallTask::downloadMods()
|
||||
auto cacheName = fileName.completeBaseName() + "-" + mod.md5 + "." + fileName.suffix();
|
||||
|
||||
if (mod.type == ModType::Extract || mod.type == ModType::TexturePackExtract || mod.type == ModType::ResourcePackExtract) {
|
||||
|
||||
auto entry = ENV.metacache()->resolveEntry("ATLauncherPacks", cacheName);
|
||||
entry->setStale(true);
|
||||
modsToExtract.insert(entry->getFullPath(), mod);
|
||||
@ -522,7 +558,7 @@ void PackInstallTask::onModsDownloaded() {
|
||||
qDebug() << "PackInstallTask::onModsDownloaded: " << QThread::currentThreadId();
|
||||
jobPtr.reset();
|
||||
|
||||
if(modsToExtract.size() || modsToDecomp.size() || modsToCopy.size()) {
|
||||
if(!modsToExtract.empty() || !modsToDecomp.empty() || !modsToCopy.empty()) {
|
||||
m_modExtractFuture = QtConcurrent::run(QThreadPool::globalInstance(), this, &PackInstallTask::extractMods, modsToExtract, modsToDecomp, modsToCopy);
|
||||
connect(&m_modExtractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &PackInstallTask::onModsExtracted);
|
||||
connect(&m_modExtractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, [&]()
|
||||
@ -629,6 +665,7 @@ void PackInstallTask::install()
|
||||
|
||||
// Use a component to add libraries BEFORE Minecraft
|
||||
if(!createLibrariesComponent(instance.instanceRoot(), components)) {
|
||||
emitFailed(tr("Failed to create libraries component"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -666,6 +703,7 @@ void PackInstallTask::install()
|
||||
// Use a component to fill in the rest of the data
|
||||
// todo: use more detection
|
||||
if(!createPackComponent(instance.instanceRoot(), components)) {
|
||||
emitFailed(tr("Failed to create pack component"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,23 @@
|
||||
|
||||
namespace ATLauncher {
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT UserInteractionSupport {
|
||||
|
||||
public:
|
||||
/**
|
||||
* Requests a user interaction to select a component version from a given version list
|
||||
* and constrained to a given Minecraft version.
|
||||
*/
|
||||
virtual QString chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) = 0;
|
||||
|
||||
};
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT PackInstallTask : public InstanceTask
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PackInstallTask(QString pack, QString version);
|
||||
explicit PackInstallTask(UserInteractionSupport *support, QString pack, QString version);
|
||||
virtual ~PackInstallTask(){}
|
||||
|
||||
bool abort() override;
|
||||
@ -54,6 +65,8 @@ private:
|
||||
void install();
|
||||
|
||||
private:
|
||||
UserInteractionSupport *m_support;
|
||||
|
||||
NetJobPtr jobPtr;
|
||||
QByteArray response;
|
||||
|
||||
@ -76,9 +89,6 @@ private:
|
||||
QFuture<bool> m_modExtractFuture;
|
||||
QFutureWatcher<bool> m_modExtractFutureWatcher;
|
||||
|
||||
QFuture<bool> m_decompFuture;
|
||||
QFutureWatcher<bool> m_decompFutureWatcher;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -81,12 +81,21 @@ static ATLauncher::ModType parseModType(QString rawType) {
|
||||
|
||||
static void loadVersionLoader(ATLauncher::VersionLoader & p, QJsonObject & obj) {
|
||||
p.type = Json::requireString(obj, "type");
|
||||
p.latest = Json::ensureBoolean(obj, QString("latest"), false);
|
||||
p.choose = Json::ensureBoolean(obj, QString("choose"), false);
|
||||
p.recommended = Json::ensureBoolean(obj, QString("recommended"), false);
|
||||
|
||||
auto metadata = Json::requireObject(obj, "metadata");
|
||||
p.version = Json::requireString(metadata, "version");
|
||||
p.latest = Json::ensureBoolean(metadata, QString("latest"), false);
|
||||
p.recommended = Json::ensureBoolean(metadata, QString("recommended"), false);
|
||||
|
||||
// Minecraft Forge
|
||||
if (p.type == "forge") {
|
||||
p.version = Json::ensureString(metadata, "version", "");
|
||||
}
|
||||
|
||||
// Fabric Loader
|
||||
if (p.type == "fabric") {
|
||||
p.version = Json::ensureString(metadata, "loader", "");
|
||||
}
|
||||
}
|
||||
|
||||
static void loadVersionLibrary(ATLauncher::VersionLibrary & p, QJsonObject & obj) {
|
||||
@ -135,6 +144,7 @@ static void loadVersionMod(ATLauncher::VersionMod & p, QJsonObject & obj) {
|
||||
}
|
||||
|
||||
p.optional = Json::ensureBoolean(obj, QString("optional"), false);
|
||||
p.client = Json::ensureBoolean(obj, QString("client"), false);
|
||||
}
|
||||
|
||||
void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
|
||||
@ -169,6 +179,8 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(obj.contains("mods")) {
|
||||
auto mods = Json::requireArray(obj, "mods");
|
||||
for (const auto modRaw : mods)
|
||||
{
|
||||
@ -178,3 +190,4 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
|
||||
v.mods.append(mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,7 @@ struct VersionMod
|
||||
QString decompFile;
|
||||
|
||||
bool optional;
|
||||
bool client;
|
||||
};
|
||||
|
||||
struct PackVersion
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "dialogs/NewInstanceDialog.h"
|
||||
#include <modplatform/atlauncher/ATLPackInstallTask.h>
|
||||
#include <BuildConfig.h>
|
||||
#include <dialogs/VersionSelectDialog.h>
|
||||
|
||||
AtlPage::AtlPage(NewInstanceDialog* dialog, QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::AtlPage), dialog(dialog)
|
||||
@ -50,7 +51,7 @@ void AtlPage::openedImpl()
|
||||
void AtlPage::suggestCurrent()
|
||||
{
|
||||
if(isOpened) {
|
||||
dialog->setSuggestedPack(selected.name, new ATLauncher::PackInstallTask(selected.safeName, selectedVersion));
|
||||
dialog->setSuggestedPack(selected.name, new ATLauncher::PackInstallTask(this, selected.safeName, selectedVersion));
|
||||
}
|
||||
|
||||
auto editedLogoName = selected.safeName;
|
||||
@ -112,3 +113,39 @@ void AtlPage::onVersionSelectionChanged(QString data)
|
||||
selectedVersion = data;
|
||||
suggestCurrent();
|
||||
}
|
||||
|
||||
QString AtlPage::chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) {
|
||||
VersionSelectDialog vselect(vlist.get(), "Choose Version", MMC->activeWindow(), false);
|
||||
if (minecraftVersion != Q_NULLPTR) {
|
||||
vselect.setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion);
|
||||
vselect.setEmptyString(tr("No versions are currently available for Minecraft %1").arg(minecraftVersion));
|
||||
}
|
||||
else {
|
||||
vselect.setEmptyString(tr("No versions are currently available"));
|
||||
}
|
||||
vselect.setEmptyErrorString(tr("Couldn't load or download the version lists!"));
|
||||
|
||||
// select recommended build
|
||||
for (int i = 0; i < vlist->versions().size(); i++) {
|
||||
auto version = vlist->versions().at(i);
|
||||
auto reqs = version->requires();
|
||||
|
||||
// filter by minecraft version, if the loader depends on a certain version.
|
||||
if (minecraftVersion != Q_NULLPTR) {
|
||||
auto iter = std::find_if(reqs.begin(), reqs.end(), [](const Meta::Require &req) {
|
||||
return req.uid == "net.minecraft";
|
||||
});
|
||||
if (iter == reqs.end()) continue;
|
||||
if (iter->equalsVersion != minecraftVersion) continue;
|
||||
}
|
||||
|
||||
// first recommended build we find, we use.
|
||||
if (version->isRecommended()) {
|
||||
vselect.setCurrentVersion(version->descriptor());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vselect.exec();
|
||||
return vselect.selectedVersion()->descriptor();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "AtlListModel.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <modplatform/atlauncher/ATLPackInstallTask.h>
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "pages/BasePage.h"
|
||||
@ -31,7 +32,7 @@ namespace Ui
|
||||
|
||||
class NewInstanceDialog;
|
||||
|
||||
class AtlPage : public QWidget, public BasePage
|
||||
class AtlPage : public QWidget, public BasePage, public ATLauncher::UserInteractionSupport
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -61,6 +62,8 @@ public:
|
||||
private:
|
||||
void suggestCurrent();
|
||||
|
||||
QString chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) override;
|
||||
|
||||
private slots:
|
||||
void triggerSearch();
|
||||
void resetSearch();
|
||||
|
Loading…
Reference in New Issue
Block a user