Added the downloading of the mods
This commit is contained in:
parent
4d599eb118
commit
9e6fa8f29a
@ -14,12 +14,41 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ModDownloadTask.h"
|
#include "ModDownloadTask.h"
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
ModDownloadTask::ModDownloadTask(const QUrl sourceUrl) {
|
ModDownloadTask::ModDownloadTask(const QUrl sourceUrl,const QString filename, const std::shared_ptr<ModFolderModel> mods)
|
||||||
m_sourceUrl = sourceUrl;
|
: m_sourceUrl(sourceUrl), mods(mods), filename(filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModDownloadTask::executeTask() {
|
void ModDownloadTask::executeTask() {
|
||||||
//TODO actually install the mod
|
setStatus(tr("Downloading mod:\n%1").arg(m_sourceUrl.toString()));
|
||||||
emitSucceeded();
|
|
||||||
|
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
|
#pragma once
|
||||||
#include "QObjectPtr.h"
|
#include "QObjectPtr.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
|
#include "net/NetJob.h"
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
|
||||||
class ModDownloadTask : public Task {
|
class ModDownloadTask : public Task {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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:
|
protected:
|
||||||
//! Entry point for tasks.
|
//! Entry point for tasks.
|
||||||
void executeTask() override;
|
void executeTask() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUrl m_sourceUrl;
|
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.mcVersion = versionArray[0].toString();
|
||||||
file.version = Json::requireString(obj, "name");
|
file.version = Json::requireString(obj, "name");
|
||||||
//TODO show all the files ?
|
//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);
|
unsortedVersions.append(file);
|
||||||
}
|
}
|
||||||
auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool
|
auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool
|
||||||
|
@ -22,6 +22,7 @@ struct IndexedVersion {
|
|||||||
QString mcVersion;
|
QString mcVersion;
|
||||||
QString downloadUrl;
|
QString downloadUrl;
|
||||||
QString date;
|
QString date;
|
||||||
|
QString fileName;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IndexedPack
|
struct IndexedPack
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
|
|
||||||
ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget *parent)
|
ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent), mods(mods)
|
||||||
{
|
{
|
||||||
setObjectName(QStringLiteral("ModDownloadDialog"));
|
setObjectName(QStringLiteral("ModDownloadDialog"));
|
||||||
resize(400, 347);
|
resize(400, 347);
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
void setSuggestedMod(const QString & name = QString(), ModDownloadTask * task = nullptr);
|
void setSuggestedMod(const QString & name = QString(), ModDownloadTask * task = nullptr);
|
||||||
|
|
||||||
ModDownloadTask * getTask();
|
ModDownloadTask * getTask();
|
||||||
|
const std::shared_ptr<ModFolderModel> &mods;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void accept() override;
|
void accept() override;
|
||||||
|
@ -165,7 +165,7 @@ void ModrinthPage::suggestCurrent()
|
|||||||
return;
|
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)
|
void ModrinthPage::onVersionSelectionChanged(QString data)
|
||||||
|
Loading…
Reference in New Issue
Block a user