Added smart file selection
This might fail in a few special cases
This commit is contained in:
parent
f6de472da2
commit
621e0ba4a8
@ -8,7 +8,7 @@ ModDownloadTask::ModDownloadTask(const QUrl sourceUrl,const QString filename, co
|
|||||||
void ModDownloadTask::executeTask() {
|
void ModDownloadTask::executeTask() {
|
||||||
setStatus(tr("Downloading mod:\n%1").arg(m_sourceUrl.toString()));
|
setStatus(tr("Downloading mod:\n%1").arg(m_sourceUrl.toString()));
|
||||||
|
|
||||||
m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network()));
|
m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network()));
|
||||||
m_filesNetJob->addNetAction(Net::Download::makeFile(m_sourceUrl, mods->dir().absoluteFilePath(filename)));
|
m_filesNetJob->addNetAction(Net::Download::makeFile(m_sourceUrl, mods->dir().absoluteFilePath(filename)));
|
||||||
connect(m_filesNetJob.get(), &NetJob::succeeded, this, &ModDownloadTask::downloadSucceeded);
|
connect(m_filesNetJob.get(), &NetJob::succeeded, this, &ModDownloadTask::downloadSucceeded);
|
||||||
connect(m_filesNetJob.get(), &NetJob::progress, this, &ModDownloadTask::downloadProgressChanged);
|
connect(m_filesNetJob.get(), &NetJob::progress, this, &ModDownloadTask::downloadProgressChanged);
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
|
#include "BaseInstance.h"
|
||||||
|
#include "minecraft/MinecraftInstance.h"
|
||||||
|
#include "minecraft/PackProfile.h"
|
||||||
|
|
||||||
|
|
||||||
void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj)
|
void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj)
|
||||||
{
|
{
|
||||||
@ -20,9 +24,12 @@ void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj)
|
|||||||
pack.authors.append(packAuthor); //TODO delete this ? only one author ever exists
|
pack.authors.append(packAuthor); //TODO delete this ? only one author ever exists
|
||||||
}
|
}
|
||||||
|
|
||||||
void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray & arr, const shared_qobject_ptr<QNetworkAccessManager>& network)
|
void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray & arr, const shared_qobject_ptr<QNetworkAccessManager>& network, BaseInstance * inst)
|
||||||
{
|
{
|
||||||
QVector<Modrinth::IndexedVersion> unsortedVersions;
|
QVector<Modrinth::IndexedVersion> unsortedVersions;
|
||||||
|
bool hasFabric = !((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty();
|
||||||
|
QString mcVersion = ((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.minecraft");
|
||||||
|
|
||||||
for(auto versionIter: arr) {
|
for(auto versionIter: arr) {
|
||||||
auto obj = versionIter.toObject();
|
auto obj = versionIter.toObject();
|
||||||
Modrinth::IndexedVersion file;
|
Modrinth::IndexedVersion file;
|
||||||
@ -33,7 +40,6 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray
|
|||||||
if (versionArray.empty()) {
|
if (versionArray.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// pick the latest version supported
|
|
||||||
for(auto mcVer : versionArray){
|
for(auto mcVer : versionArray){
|
||||||
file.mcVersion.append(mcVer.toString());
|
file.mcVersion.append(mcVer.toString());
|
||||||
}
|
}
|
||||||
@ -42,8 +48,35 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray
|
|||||||
file.loaders.append(loader.toString());
|
file.loaders.append(loader.toString());
|
||||||
}
|
}
|
||||||
file.version = Json::requireString(obj, "name");
|
file.version = Json::requireString(obj, "name");
|
||||||
//TODO show all the files ?
|
|
||||||
auto parent = Json::requireArray(obj, "files")[0].toObject();
|
auto files = Json::requireArray(obj, "files");
|
||||||
|
int i = 0;
|
||||||
|
while (files.count() > 1 && i < files.count()){
|
||||||
|
//try to resolve the correct file
|
||||||
|
auto parent = files[i].toObject();
|
||||||
|
auto fileName = Json::requireString(parent, "filename");
|
||||||
|
//avoid grabbing "dev" files
|
||||||
|
if(fileName.contains("javadocs",Qt::CaseInsensitive) || fileName.contains("sources",Qt::CaseInsensitive)){
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//grab the correct mod loader
|
||||||
|
if(fileName.contains("forge",Qt::CaseInsensitive) || fileName.contains("fabric",Qt::CaseInsensitive) ){
|
||||||
|
if(hasFabric){
|
||||||
|
if(fileName.contains("forge",Qt::CaseInsensitive)){
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(fileName.contains("fabric",Qt::CaseInsensitive)){
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto parent = files[i].toObject();
|
||||||
file.downloadUrl = Json::requireString(parent, "url");
|
file.downloadUrl = Json::requireString(parent, "url");
|
||||||
file.fileName = Json::requireString(parent, "filename");
|
file.fileName = Json::requireString(parent, "filename");
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QObjectPtr.h>
|
#include <QObjectPtr.h>
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
|
#include "BaseInstance.h"
|
||||||
|
|
||||||
namespace Modrinth {
|
namespace Modrinth {
|
||||||
|
|
||||||
@ -41,8 +42,7 @@ struct IndexedPack
|
|||||||
};
|
};
|
||||||
|
|
||||||
void loadIndexedPack(IndexedPack & m, QJsonObject & obj);
|
void loadIndexedPack(IndexedPack & m, QJsonObject & obj);
|
||||||
void loadIndexedPackVersions(IndexedPack & m, QJsonArray & arr, const shared_qobject_ptr<QNetworkAccessManager>& network);
|
void loadIndexedPackVersions(IndexedPack &pack, QJsonArray &arr, const shared_qobject_ptr<QNetworkAccessManager> &network, BaseInstance *inst);
|
||||||
void versionJobFinished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Modrinth::IndexedPack)
|
Q_DECLARE_METATYPE(Modrinth::IndexedPack)
|
||||||
|
@ -128,7 +128,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
QJsonArray arr = doc.array();
|
QJsonArray arr = doc.array();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Modrinth::loadIndexedPackVersions(current, arr, APPLICATION->network());
|
Modrinth::loadIndexedPackVersions(current, arr, APPLICATION->network(), m_instance);
|
||||||
}
|
}
|
||||||
catch(const JSONValidationError &e)
|
catch(const JSONValidationError &e)
|
||||||
{
|
{
|
||||||
@ -145,7 +145,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl));
|
ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl));
|
||||||
}
|
}
|
||||||
if(ui->versionSelectionBox->count() == 0){
|
if(ui->versionSelectionBox->count() == 0){
|
||||||
ui->versionSelectionBox->addItem("No Valid Version found !", QVariant(""));
|
ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
suggestCurrent();
|
suggestCurrent();
|
||||||
@ -158,7 +158,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl));
|
ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl));
|
||||||
}
|
}
|
||||||
if(ui->versionSelectionBox->count() == 0){
|
if(ui->versionSelectionBox->count() == 0){
|
||||||
ui->versionSelectionBox->addItem("No Valid Version found !", QVariant(""));
|
ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(""));
|
||||||
}
|
}
|
||||||
suggestCurrent();
|
suggestCurrent();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user