Added the downloading of the mods
This commit is contained in:
parent
4d599eb118
commit
9e6fa8f29a
@ -14,12 +14,41 @@
|
||||
*/
|
||||
|
||||
#include "ModDownloadTask.h"
|
||||
#include "Application.h"
|
||||
|
||||
ModDownloadTask::ModDownloadTask(const QUrl sourceUrl) {
|
||||
m_sourceUrl = sourceUrl;
|
||||
ModDownloadTask::ModDownloadTask(const QUrl sourceUrl,const QString filename, const std::shared_ptr<ModFolderModel> mods)
|
||||
: m_sourceUrl(sourceUrl), mods(mods), filename(filename) {
|
||||
}
|
||||
|
||||
void ModDownloadTask::executeTask() {
|
||||
//TODO actually install the mod
|
||||
emitSucceeded();
|
||||
setStatus(tr("Downloading mod:\n%1").arg(m_sourceUrl.toString()));
|
||||
|
||||
m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network()));
|
||||
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::progress, this, &ModDownloadTask::downloadProgressChanged);
|
||||
connect(m_filesNetJob.get(), &NetJob::failed, this, &ModDownloadTask::downloadFailed);
|
||||
m_filesNetJob->start();
|
||||
}
|
||||
|
||||
void ModDownloadTask::downloadSucceeded()
|
||||
{
|
||||
emitSucceeded();
|
||||
m_filesNetJob.reset();
|
||||
}
|
||||
|
||||
void ModDownloadTask::downloadFailed(QString reason)
|
||||
{
|
||||
emitFailed(reason);
|
||||
m_filesNetJob.reset();
|
||||
}
|
||||
|
||||
void ModDownloadTask::downloadProgressChanged(qint64 current, qint64 total)
|
||||
{
|
||||
emit progress(current, total);
|
||||
}
|
||||
|
||||
bool ModDownloadTask::abort() {
|
||||
return m_filesNetJob->abort();
|
||||
}
|
||||
|
||||
|
@ -16,20 +16,33 @@
|
||||
#pragma once
|
||||
#include "QObjectPtr.h"
|
||||
#include "tasks/Task.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "net/NetJob.h"
|
||||
#include <QUrl>
|
||||
|
||||
|
||||
class ModDownloadTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ModDownloadTask(const QUrl sourceUrl);
|
||||
explicit ModDownloadTask(const QUrl sourceUrl, const QString filename, const std::shared_ptr<ModFolderModel> mods);
|
||||
|
||||
public slots:
|
||||
bool abort() override;
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
void executeTask() override;
|
||||
|
||||
private:
|
||||
QUrl m_sourceUrl;
|
||||
std::shared_ptr<NetJob> m_filesNetJob;
|
||||
const std::shared_ptr<ModFolderModel> mods;
|
||||
const QString filename;
|
||||
|
||||
void downloadProgressChanged(qint64 current, qint64 total);
|
||||
|
||||
void downloadFailed(QString reason);
|
||||
|
||||
void downloadSucceeded();
|
||||
};
|
||||
|
||||
|
||||
|
@ -37,7 +37,9 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray
|
||||
file.mcVersion = versionArray[0].toString();
|
||||
file.version = Json::requireString(obj, "name");
|
||||
//TODO show all the files ?
|
||||
file.downloadUrl = Json::requireString(Json::requireArray(obj, "files")[0].toObject(),"url");
|
||||
auto parent = Json::requireArray(obj, "files")[0].toObject();
|
||||
file.downloadUrl = Json::requireString(parent, "url");
|
||||
file.fileName = Json::requireString(parent, "filename");
|
||||
unsortedVersions.append(file);
|
||||
}
|
||||
auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool
|
||||
|
@ -22,6 +22,7 @@ struct IndexedVersion {
|
||||
QString mcVersion;
|
||||
QString downloadUrl;
|
||||
QString date;
|
||||
QString fileName;
|
||||
};
|
||||
|
||||
struct IndexedPack
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
|
||||
ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
: QDialog(parent), mods(mods)
|
||||
{
|
||||
setObjectName(QStringLiteral("ModDownloadDialog"));
|
||||
resize(400, 347);
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
void setSuggestedMod(const QString & name = QString(), ModDownloadTask * task = nullptr);
|
||||
|
||||
ModDownloadTask * getTask();
|
||||
const std::shared_ptr<ModFolderModel> &mods;
|
||||
|
||||
public slots:
|
||||
void accept() override;
|
||||
|
@ -165,7 +165,7 @@ void ModrinthPage::suggestCurrent()
|
||||
return;
|
||||
}
|
||||
|
||||
dialog->setSuggestedMod(current.name, new ModDownloadTask(selectedVersion));
|
||||
dialog->setSuggestedMod(current.name, new ModDownloadTask(selectedVersion, current.versions.at(0).fileName ,dialog->mods));
|
||||
}
|
||||
|
||||
void ModrinthPage::onVersionSelectionChanged(QString data)
|
||||
|
Loading…
Reference in New Issue
Block a user