ATLauncher: Reduce boilerplate code for fetching versions

This commit is contained in:
Jamie Mansfield 2022-05-01 22:42:29 +01:00
parent c329730de8
commit f5f59203a2
No known key found for this signature in database
GPG Key ID: 36F61598F39F67B0

View File

@ -58,6 +58,8 @@
namespace ATLauncher { namespace ATLauncher {
static Meta::VersionPtr getComponentVersion(const QString& uid, const QString& version);
PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString pack, QString version) PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString pack, QString version)
{ {
m_support = support; m_support = support;
@ -115,19 +117,11 @@ void PackInstallTask::onDownloadSucceeded()
} }
m_version = version; m_version = version;
auto vlist = APPLICATION->metadataIndex()->get("net.minecraft"); auto ver = getComponentVersion("net.minecraft", m_version.minecraft);
if(!vlist)
{
emitFailed(tr("Failed to get local metadata index for %1").arg("net.minecraft"));
return;
}
auto ver = vlist->getVersion(m_version.minecraft);
if (!ver) { if (!ver) {
emitFailed(tr("Failed to get local metadata index for '%1' v%2").arg("net.minecraft").arg(m_version.minecraft)); emitFailed(tr("Failed to get local metadata index for '%1' v%2").arg("net.minecraft", m_version.minecraft));
return; return;
} }
ver->load(Net::Mode::Online);
minecraftVersion = ver; minecraftVersion = ver;
if(m_version.noConfigs) { if(m_version.noConfigs) {
@ -359,17 +353,10 @@ bool PackInstallTask::createLibrariesComponent(QString instanceRoot, std::shared
for(const auto & lib : m_version.libraries) { for(const auto & lib : m_version.libraries) {
// If the library is LiteLoader, we need to ignore it and handle it separately. // If the library is LiteLoader, we need to ignore it and handle it separately.
if (liteLoaderMap.contains(lib.md5)) { if (liteLoaderMap.contains(lib.md5)) {
auto vlist = APPLICATION->metadataIndex()->get("com.mumfrey.liteloader"); auto ver = getComponentVersion("com.mumfrey.liteloader", liteLoaderMap.value(lib.md5));
if (vlist) { if (ver) {
if (!vlist->isLoaded()) componentsToInstall.insert("com.mumfrey.liteloader", ver);
vlist->load(Net::Mode::Online); continue;
auto ver = vlist->getVersion(liteLoaderMap.value(lib.md5));
if (ver) {
ver->load(Net::Mode::Online);
componentsToInstall.insert("com.mumfrey.liteloader", ver);
continue;
}
} }
} }
@ -643,17 +630,10 @@ void PackInstallTask::downloadMods()
auto path = FS::PathCombine(m_stagingPath, "minecraft", relpath, mod.file); auto path = FS::PathCombine(m_stagingPath, "minecraft", relpath, mod.file);
if(mod.type == ModType::Forge) { if(mod.type == ModType::Forge) {
auto vlist = APPLICATION->metadataIndex()->get("net.minecraftforge"); auto ver = getComponentVersion("net.minecraftforge", mod.version);
if(vlist) if (ver) {
{ componentsToInstall.insert("net.minecraftforge", ver);
if (!vlist->isLoaded()) continue;
vlist->load(Net::Mode::Online);
auto ver = vlist->getVersion(mod.version);
if(ver) {
ver->load(Net::Mode::Online);
componentsToInstall.insert("net.minecraftforge", ver);
continue;
}
} }
qDebug() << "Jarmod: " + path; qDebug() << "Jarmod: " + path;
@ -850,4 +830,23 @@ void PackInstallTask::install()
emitSucceeded(); emitSucceeded();
} }
static Meta::VersionPtr getComponentVersion(const QString& uid, const QString& version)
{
auto vlist = APPLICATION->metadataIndex()->get(uid);
if (!vlist)
return {};
if (!vlist->isLoaded())
vlist->load(Net::Mode::Online);
auto ver = vlist->getVersion(version);
if (!ver)
return {};
if (!ver->isLoaded())
ver->load(Net::Mode::Online);
return ver;
}
} }