NOISSUE continue refactoring things to make tests pass

This commit is contained in:
Petr Mrázek
2021-11-21 23:21:12 +01:00
parent c2c56a2f6c
commit 69213b1206
103 changed files with 634 additions and 773 deletions

View File

@ -2,7 +2,8 @@
#include "PrivatePackManager.h"
#include <QDomDocument>
#include <BuildConfig.h>
#include "BuildConfig.h"
#include "Application.h"
namespace LegacyFTB {
@ -11,21 +12,20 @@ void PackFetchTask::fetch()
publicPacks.clear();
thirdPartyPacks.clear();
NetJob *netJob = new NetJob("LegacyFTB::ModpackFetch");
jobPtr = new NetJob("LegacyFTB::ModpackFetch");
QUrl publicPacksUrl = QUrl(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/modpacks.xml");
qDebug() << "Downloading public version info from" << publicPacksUrl.toString();
netJob->addNetAction(Net::Download::makeByteArray(publicPacksUrl, &publicModpacksXmlFileData));
jobPtr->addNetAction(Net::Download::makeByteArray(publicPacksUrl, &publicModpacksXmlFileData));
QUrl thirdPartyUrl = QUrl(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/thirdparty.xml");
qDebug() << "Downloading thirdparty version info from" << thirdPartyUrl.toString();
netJob->addNetAction(Net::Download::makeByteArray(thirdPartyUrl, &thirdPartyModpacksXmlFileData));
jobPtr->addNetAction(Net::Download::makeByteArray(thirdPartyUrl, &thirdPartyModpacksXmlFileData));
QObject::connect(netJob, &NetJob::succeeded, this, &PackFetchTask::fileDownloadFinished);
QObject::connect(netJob, &NetJob::failed, this, &PackFetchTask::fileDownloadFailed);
QObject::connect(jobPtr.get(), &NetJob::succeeded, this, &PackFetchTask::fileDownloadFinished);
QObject::connect(jobPtr.get(), &NetJob::failed, this, &PackFetchTask::fileDownloadFailed);
jobPtr.reset(netJob);
netJob->start();
jobPtr->start(m_network);
}
void PackFetchTask::fetchPrivate(const QStringList & toFetch)
@ -63,7 +63,7 @@ void PackFetchTask::fetchPrivate(const QStringList & toFetch)
delete data;
});
job->start();
job->start(m_network);
}
}

View File

@ -13,14 +13,15 @@ class PackFetchTask : public QObject {
Q_OBJECT
public:
PackFetchTask() = default;
PackFetchTask(shared_qobject_ptr<QNetworkAccessManager> network) : QObject(nullptr), m_network(network) {};
virtual ~PackFetchTask() = default;
void fetch();
void fetchPrivate(const QStringList &toFetch);
private:
NetJobPtr jobPtr;
shared_qobject_ptr<QNetworkAccessManager> m_network;
NetJob::Ptr jobPtr;
QByteArray publicModpacksXmlFileData;
QByteArray thirdPartyModpacksXmlFileData;

View File

@ -1,24 +1,25 @@
#include "PackInstallTask.h"
#include "Env.h"
#include "MMCZip.h"
#include <QtConcurrent>
#include "MMCZip.h"
#include "BaseInstance.h"
#include "FileSystem.h"
#include "settings/INISettingsObject.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
#include "minecraft/GradleSpecifier.h"
#include "BuildConfig.h"
#include <QtConcurrent>
#include "BuildConfig.h"
#include "Application.h"
namespace LegacyFTB {
PackInstallTask::PackInstallTask(Modpack pack, QString version)
PackInstallTask::PackInstallTask(shared_qobject_ptr<QNetworkAccessManager> network, Modpack pack, QString version)
{
m_pack = pack;
m_version = version;
m_network = network;
}
void PackInstallTask::executeTask()
@ -31,8 +32,8 @@ void PackInstallTask::downloadPack()
setStatus(tr("Downloading zip for %1").arg(m_pack.name));
auto packoffset = QString("%1/%2/%3").arg(m_pack.dir, m_version.replace(".", "_"), m_pack.file);
auto entry = ENV->metacache()->resolveEntry("FTBPacks", packoffset);
NetJob *job = new NetJob("Download FTB Pack");
auto entry = APPLICATION->metacache()->resolveEntry("FTBPacks", packoffset);
netJobContainer = new NetJob("Download FTB Pack");
entry->setStale(true);
QString url;
@ -44,14 +45,13 @@ void PackInstallTask::downloadPack()
{
url = QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "modpacks/%1").arg(packoffset);
}
job->addNetAction(Net::Download::makeCached(url, entry));
netJobContainer->addNetAction(Net::Download::makeCached(url, entry));
archivePath = entry->getFullPath();
netJobContainer.reset(job);
connect(job, &NetJob::succeeded, this, &PackInstallTask::onDownloadSucceeded);
connect(job, &NetJob::failed, this, &PackInstallTask::onDownloadFailed);
connect(job, &NetJob::progress, this, &PackInstallTask::onDownloadProgress);
job->start();
connect(netJobContainer.get(), &NetJob::succeeded, this, &PackInstallTask::onDownloadSucceeded);
connect(netJobContainer.get(), &NetJob::failed, this, &PackInstallTask::onDownloadFailed);
connect(netJobContainer.get(), &NetJob::progress, this, &PackInstallTask::onDownloadProgress);
netJobContainer->start(m_network);
progress(1, 4);
}

View File

@ -8,6 +8,8 @@
#include "meta/VersionList.h"
#include "PackHelpers.h"
#include "net/NetJob.h"
#include <nonstd/optional>
namespace LegacyFTB {
@ -17,7 +19,7 @@ class PackInstallTask : public InstanceTask
Q_OBJECT
public:
explicit PackInstallTask(Modpack pack, QString version);
explicit PackInstallTask(shared_qobject_ptr<QNetworkAccessManager> network, Modpack pack, QString version);
virtual ~PackInstallTask(){}
bool canAbort() const override { return true; }
@ -41,11 +43,12 @@ private slots:
void onUnzipCanceled();
private: /* data */
shared_qobject_ptr<QNetworkAccessManager> m_network;
bool abortable = false;
std::unique_ptr<QuaZip> m_packZip;
QFuture<nonstd::optional<QStringList>> m_extractFuture;
QFutureWatcher<nonstd::optional<QStringList>> m_extractFutureWatcher;
NetJobPtr netJobContainer;
NetJob::Ptr netJobContainer;
QString archivePath;
Modpack m_pack;