Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into feature/java-downloader
This commit is contained in:
commit
4d24213aa3
@ -48,7 +48,6 @@
|
||||
#include "net/PasteUpload.h"
|
||||
#include "pathmatcher/MultiMatcher.h"
|
||||
#include "pathmatcher/SimplePrefixMatcher.h"
|
||||
#include "settings/INIFile.h"
|
||||
#include "tools/GenericProfiler.h"
|
||||
#include "ui/InstanceWindow.h"
|
||||
#include "ui/MainWindow.h"
|
||||
@ -107,7 +106,7 @@
|
||||
#include "icons/IconList.h"
|
||||
#include "net/HttpMetaCache.h"
|
||||
|
||||
#include "java/JavaUtils.h"
|
||||
#include "java/JavaInstallList.h"
|
||||
|
||||
#include "updater/ExternalUpdater.h"
|
||||
|
||||
@ -153,6 +152,7 @@
|
||||
#endif
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
#include <windows.h>
|
||||
#include "WindowsConsole.h"
|
||||
#endif
|
||||
|
||||
|
@ -35,7 +35,7 @@ class JavaInstallList : public BaseVersionList {
|
||||
public:
|
||||
explicit JavaInstallList(QObject* parent = 0, bool onlyManagedVersions = false);
|
||||
|
||||
Task::Ptr getLoadTask() override;
|
||||
[[nodiscard]] Task::Ptr getLoadTask() override;
|
||||
bool isLoaded() override;
|
||||
const BaseVersion::Ptr at(int i) const override;
|
||||
int count() const override;
|
||||
|
@ -15,19 +15,26 @@
|
||||
|
||||
#include "BaseEntity.h"
|
||||
|
||||
#include "Exception.h"
|
||||
#include "FileSystem.h"
|
||||
#include "Json.h"
|
||||
#include "modplatform/helpers/HashUtils.h"
|
||||
#include "net/ApiDownload.h"
|
||||
#include "net/ChecksumValidator.h"
|
||||
#include "net/HttpMetaCache.h"
|
||||
#include "net/Mode.h"
|
||||
#include "net/NetJob.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "BuildConfig.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace Meta {
|
||||
|
||||
class ParsingValidator : public Net::Validator {
|
||||
public: /* con/des */
|
||||
ParsingValidator(Meta::BaseEntity* entity) : m_entity(entity) {};
|
||||
virtual ~ParsingValidator() {};
|
||||
ParsingValidator(BaseEntity* entity) : m_entity(entity) {};
|
||||
virtual ~ParsingValidator() = default;
|
||||
|
||||
public: /* methods */
|
||||
bool init(QNetworkRequest&) override
|
||||
@ -61,92 +68,131 @@ class ParsingValidator : public Net::Validator {
|
||||
|
||||
private: /* data */
|
||||
QByteArray m_data;
|
||||
Meta::BaseEntity* m_entity;
|
||||
BaseEntity* m_entity;
|
||||
};
|
||||
|
||||
Meta::BaseEntity::~BaseEntity() {}
|
||||
|
||||
QUrl Meta::BaseEntity::url() const
|
||||
QUrl BaseEntity::url() const
|
||||
{
|
||||
auto s = APPLICATION->settings();
|
||||
QString metaOverride = s->get("MetaURLOverride").toString();
|
||||
if (metaOverride.isEmpty()) {
|
||||
return QUrl(BuildConfig.META_URL).resolved(localFilename());
|
||||
} else {
|
||||
return QUrl(metaOverride).resolved(localFilename());
|
||||
}
|
||||
return QUrl(metaOverride).resolved(localFilename());
|
||||
}
|
||||
|
||||
bool Meta::BaseEntity::loadLocalFile()
|
||||
Task::Ptr BaseEntity::loadTask(Net::Mode mode)
|
||||
{
|
||||
const QString fname = QDir("meta").absoluteFilePath(localFilename());
|
||||
if (!QFile::exists(fname)) {
|
||||
return false;
|
||||
}
|
||||
// TODO: check if the file has the expected checksum
|
||||
try {
|
||||
auto doc = Json::requireDocument(fname, fname);
|
||||
auto obj = Json::requireObject(doc, fname);
|
||||
parse(obj);
|
||||
return true;
|
||||
} catch (const Exception& e) {
|
||||
qDebug() << QString("Unable to parse file %1: %2").arg(fname, e.cause());
|
||||
// just make sure it's gone and we never consider it again.
|
||||
return !FS::deletePath(fname);
|
||||
if (m_task && m_task->isRunning()) {
|
||||
return m_task;
|
||||
}
|
||||
m_task.reset(new BaseEntityLoadTask(this, mode));
|
||||
return m_task;
|
||||
}
|
||||
|
||||
void Meta::BaseEntity::load(Net::Mode loadType)
|
||||
bool BaseEntity::isLoaded() const
|
||||
{
|
||||
// load local file if nothing is loaded yet
|
||||
if (!isLoaded()) {
|
||||
if (loadLocalFile()) {
|
||||
m_loadStatus = LoadStatus::Local;
|
||||
// consider it loaded only if the main hash is either empty and was remote loadded or the hashes match and was loaded
|
||||
return m_sha256.isEmpty() ? m_load_status == LoadStatus::Remote : m_load_status != LoadStatus::NotLoaded && m_sha256 == m_file_sha256;
|
||||
}
|
||||
|
||||
void BaseEntity::setSha256(QString sha256)
|
||||
{
|
||||
m_sha256 = sha256;
|
||||
}
|
||||
|
||||
BaseEntity::LoadStatus BaseEntity::status() const
|
||||
{
|
||||
return m_load_status;
|
||||
}
|
||||
|
||||
BaseEntityLoadTask::BaseEntityLoadTask(BaseEntity* parent, Net::Mode mode) : m_entity(parent), m_mode(mode) {}
|
||||
|
||||
void BaseEntityLoadTask::executeTask()
|
||||
{
|
||||
const QString fname = QDir("meta").absoluteFilePath(m_entity->localFilename());
|
||||
auto hashMatches = false;
|
||||
// the file exists on disk try to load it
|
||||
if (QFile::exists(fname)) {
|
||||
try {
|
||||
QByteArray fileData;
|
||||
// read local file if nothing is loaded yet
|
||||
if (m_entity->m_load_status == BaseEntity::LoadStatus::NotLoaded || m_entity->m_file_sha256.isEmpty()) {
|
||||
setStatus(tr("Loading local file"));
|
||||
fileData = FS::read(fname);
|
||||
m_entity->m_file_sha256 = Hashing::hash(fileData, Hashing::Algorithm::Sha256);
|
||||
}
|
||||
|
||||
// on online the hash needs to match
|
||||
hashMatches = m_entity->m_sha256 == m_entity->m_file_sha256;
|
||||
if (m_mode == Net::Mode::Online && !m_entity->m_sha256.isEmpty() && !hashMatches) {
|
||||
throw Exception("mismatched checksum");
|
||||
}
|
||||
|
||||
// load local file
|
||||
if (m_entity->m_load_status == BaseEntity::LoadStatus::NotLoaded) {
|
||||
auto doc = Json::requireDocument(fileData, fname);
|
||||
auto obj = Json::requireObject(doc, fname);
|
||||
m_entity->parse(obj);
|
||||
m_entity->m_load_status = BaseEntity::LoadStatus::Local;
|
||||
}
|
||||
|
||||
} catch (const Exception& e) {
|
||||
qDebug() << QString("Unable to parse file %1: %2").arg(fname, e.cause());
|
||||
// just make sure it's gone and we never consider it again.
|
||||
FS::deletePath(fname);
|
||||
m_entity->m_load_status = BaseEntity::LoadStatus::NotLoaded;
|
||||
}
|
||||
}
|
||||
// if we need remote update, run the update task
|
||||
if (loadType == Net::Mode::Offline || !shouldStartRemoteUpdate()) {
|
||||
auto wasLoadedOffline = m_entity->m_load_status != BaseEntity::LoadStatus::NotLoaded && m_mode == Net::Mode::Offline;
|
||||
// if has is not present allways fetch from remote(e.g. the main index file), else only fetch if hash doesn't match
|
||||
auto wasLoadedRemote = m_entity->m_sha256.isEmpty() ? m_entity->m_load_status == BaseEntity::LoadStatus::Remote : hashMatches;
|
||||
if (wasLoadedOffline || wasLoadedRemote) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
m_updateTask.reset(new NetJob(QObject::tr("Download of meta file %1").arg(localFilename()), APPLICATION->network()));
|
||||
auto url = this->url();
|
||||
auto entry = APPLICATION->metacache()->resolveEntry("meta", localFilename());
|
||||
m_task.reset(new NetJob(QObject::tr("Download of meta file %1").arg(m_entity->localFilename()), APPLICATION->network()));
|
||||
auto url = m_entity->url();
|
||||
auto entry = APPLICATION->metacache()->resolveEntry("meta", m_entity->localFilename());
|
||||
entry->setStale(true);
|
||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||
/*
|
||||
* The validator parses the file and loads it into the object.
|
||||
* If that fails, the file is not written to storage.
|
||||
*/
|
||||
dl->addValidator(new ParsingValidator(this));
|
||||
m_updateTask->addNetAction(dl);
|
||||
m_updateStatus = UpdateStatus::InProgress;
|
||||
QObject::connect(m_updateTask.get(), &NetJob::succeeded, [&]() {
|
||||
m_loadStatus = LoadStatus::Remote;
|
||||
m_updateStatus = UpdateStatus::Succeeded;
|
||||
m_updateTask.reset();
|
||||
if (!m_entity->m_sha256.isEmpty())
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Algorithm::Sha256, m_entity->m_sha256));
|
||||
dl->addValidator(new ParsingValidator(m_entity));
|
||||
m_task->addNetAction(dl);
|
||||
m_task->setAskRetry(false);
|
||||
connect(m_task.get(), &Task::failed, this, &BaseEntityLoadTask::emitFailed);
|
||||
connect(m_task.get(), &Task::succeeded, this, &BaseEntityLoadTask::emitSucceeded);
|
||||
connect(m_task.get(), &Task::succeeded, this, [this]() {
|
||||
m_entity->m_load_status = BaseEntity::LoadStatus::Remote;
|
||||
m_entity->m_file_sha256 = m_entity->m_sha256;
|
||||
});
|
||||
QObject::connect(m_updateTask.get(), &NetJob::failed, [&]() {
|
||||
m_updateStatus = UpdateStatus::Failed;
|
||||
m_updateTask.reset();
|
||||
});
|
||||
m_updateTask->start();
|
||||
|
||||
connect(m_task.get(), &Task::progress, this, &Task::setProgress);
|
||||
connect(m_task.get(), &Task::stepProgress, this, &BaseEntityLoadTask::propagateStepProgress);
|
||||
connect(m_task.get(), &Task::status, this, &Task::setStatus);
|
||||
connect(m_task.get(), &Task::details, this, &Task::setDetails);
|
||||
|
||||
m_task->start();
|
||||
}
|
||||
|
||||
bool Meta::BaseEntity::isLoaded() const
|
||||
bool BaseEntityLoadTask::canAbort() const
|
||||
{
|
||||
return m_loadStatus > LoadStatus::NotLoaded;
|
||||
return m_task ? m_task->canAbort() : false;
|
||||
}
|
||||
|
||||
bool Meta::BaseEntity::shouldStartRemoteUpdate() const
|
||||
bool BaseEntityLoadTask::abort()
|
||||
{
|
||||
// TODO: version-locks and offline mode?
|
||||
return m_updateStatus != UpdateStatus::InProgress;
|
||||
}
|
||||
|
||||
Task::Ptr Meta::BaseEntity::getCurrentTask()
|
||||
{
|
||||
if (m_updateStatus == UpdateStatus::InProgress) {
|
||||
return m_updateTask;
|
||||
if (m_task) {
|
||||
Task::abort();
|
||||
return m_task->abort();
|
||||
}
|
||||
return nullptr;
|
||||
return Task::abort();
|
||||
}
|
||||
|
||||
} // namespace Meta
|
||||
|
@ -17,38 +17,57 @@
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
#include "QObjectPtr.h"
|
||||
|
||||
#include "net/Mode.h"
|
||||
#include "net/NetJob.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace Meta {
|
||||
class BaseEntityLoadTask;
|
||||
class BaseEntity {
|
||||
friend BaseEntityLoadTask;
|
||||
|
||||
public: /* types */
|
||||
using Ptr = std::shared_ptr<BaseEntity>;
|
||||
enum class LoadStatus { NotLoaded, Local, Remote };
|
||||
enum class UpdateStatus { NotDone, InProgress, Failed, Succeeded };
|
||||
|
||||
public:
|
||||
virtual ~BaseEntity();
|
||||
|
||||
virtual void parse(const QJsonObject& obj) = 0;
|
||||
virtual ~BaseEntity() = default;
|
||||
|
||||
virtual QString localFilename() const = 0;
|
||||
virtual QUrl url() const;
|
||||
|
||||
bool isLoaded() const;
|
||||
bool shouldStartRemoteUpdate() const;
|
||||
LoadStatus status() const;
|
||||
|
||||
void load(Net::Mode loadType);
|
||||
Task::Ptr getCurrentTask();
|
||||
/* for parsers */
|
||||
void setSha256(QString sha256);
|
||||
|
||||
protected: /* methods */
|
||||
bool loadLocalFile();
|
||||
virtual void parse(const QJsonObject& obj) = 0;
|
||||
[[nodiscard]] Task::Ptr loadTask(Net::Mode loadType = Net::Mode::Online);
|
||||
|
||||
protected:
|
||||
QString m_sha256; // the expected sha256
|
||||
QString m_file_sha256; // the file sha256
|
||||
|
||||
private:
|
||||
LoadStatus m_loadStatus = LoadStatus::NotLoaded;
|
||||
UpdateStatus m_updateStatus = UpdateStatus::NotDone;
|
||||
NetJob::Ptr m_updateTask;
|
||||
LoadStatus m_load_status = LoadStatus::NotLoaded;
|
||||
Task::Ptr m_task;
|
||||
};
|
||||
|
||||
class BaseEntityLoadTask : public Task {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BaseEntityLoadTask(BaseEntity* parent, Net::Mode mode);
|
||||
~BaseEntityLoadTask() override = default;
|
||||
|
||||
virtual void executeTask() override;
|
||||
virtual bool canAbort() const override;
|
||||
virtual bool abort() override;
|
||||
|
||||
private:
|
||||
BaseEntity* m_entity;
|
||||
Net::Mode m_mode;
|
||||
NetJob::Ptr m_task;
|
||||
};
|
||||
} // namespace Meta
|
||||
|
@ -16,7 +16,10 @@
|
||||
#include "Index.h"
|
||||
|
||||
#include "JsonFormat.h"
|
||||
#include "QObjectPtr.h"
|
||||
#include "VersionList.h"
|
||||
#include "meta/BaseEntity.h"
|
||||
#include "tasks/SequentialTask.h"
|
||||
|
||||
namespace Meta {
|
||||
Index::Index(QObject* parent) : QAbstractListModel(parent) {}
|
||||
@ -51,14 +54,17 @@ QVariant Index::data(const QModelIndex& index, int role) const
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int Index::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : m_lists.size();
|
||||
}
|
||||
|
||||
int Index::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : 1;
|
||||
}
|
||||
|
||||
QVariant Index::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0) {
|
||||
@ -79,6 +85,7 @@ VersionList::Ptr Index::get(const QString& uid)
|
||||
if (!out) {
|
||||
out = std::make_shared<VersionList>(uid);
|
||||
m_uids[uid] = out;
|
||||
m_lists.append(out);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@ -96,7 +103,7 @@ void Index::parse(const QJsonObject& obj)
|
||||
|
||||
void Index::merge(const std::shared_ptr<Index>& other)
|
||||
{
|
||||
const QVector<VersionList::Ptr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
|
||||
const QVector<VersionList::Ptr> lists = other->m_lists;
|
||||
// initial load, no need to merge
|
||||
if (m_lists.isEmpty()) {
|
||||
beginResetModel();
|
||||
@ -123,7 +130,33 @@ void Index::merge(const std::shared_ptr<Index>& other)
|
||||
|
||||
void Index::connectVersionList(const int row, const VersionList::Ptr& list)
|
||||
{
|
||||
connect(list.get(), &VersionList::nameChanged, this,
|
||||
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << Qt::DisplayRole); });
|
||||
connect(list.get(), &VersionList::nameChanged, this, [this, row] { emit dataChanged(index(row), index(row), { Qt::DisplayRole }); });
|
||||
}
|
||||
|
||||
Task::Ptr Index::loadVersion(const QString& uid, const QString& version, Net::Mode mode, bool force)
|
||||
{
|
||||
if (mode == Net::Mode::Offline) {
|
||||
return get(uid, version)->loadTask(mode);
|
||||
}
|
||||
|
||||
auto versionList = get(uid);
|
||||
auto loadTask = makeShared<SequentialTask>(
|
||||
this, tr("Load meta for %1:%2", "This is for the task name that loads the meta index.").arg(uid, version));
|
||||
if (status() != BaseEntity::LoadStatus::Remote || force) {
|
||||
loadTask->addTask(this->loadTask(mode));
|
||||
}
|
||||
loadTask->addTask(versionList->loadTask(mode));
|
||||
loadTask->addTask(versionList->getVersion(version)->loadTask(mode));
|
||||
return loadTask;
|
||||
}
|
||||
|
||||
Version::Ptr Index::getLoadedVersion(const QString& uid, const QString& version)
|
||||
{
|
||||
QEventLoop ev;
|
||||
auto task = loadVersion(uid, version);
|
||||
QObject::connect(task.get(), &Task::finished, &ev, &QEventLoop::quit);
|
||||
task->start();
|
||||
ev.exec();
|
||||
return get(uid, version);
|
||||
}
|
||||
} // namespace Meta
|
||||
|
@ -16,10 +16,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <memory>
|
||||
|
||||
#include "BaseEntity.h"
|
||||
#include "meta/VersionList.h"
|
||||
#include "net/Mode.h"
|
||||
|
||||
class Task;
|
||||
|
||||
@ -30,6 +30,7 @@ class Index : public QAbstractListModel, public BaseEntity {
|
||||
public:
|
||||
explicit Index(QObject* parent = nullptr);
|
||||
explicit Index(const QVector<VersionList::Ptr>& lists, QObject* parent = nullptr);
|
||||
virtual ~Index() = default;
|
||||
|
||||
enum { UidRole = Qt::UserRole, NameRole, ListPtrRole };
|
||||
|
||||
@ -47,8 +48,15 @@ class Index : public QAbstractListModel, public BaseEntity {
|
||||
|
||||
QVector<VersionList::Ptr> lists() const { return m_lists; }
|
||||
|
||||
Task::Ptr loadVersion(const QString& uid, const QString& version = {}, Net::Mode mode = Net::Mode::Online, bool force = false);
|
||||
|
||||
// this blocks until the version is loaded
|
||||
Version::Ptr getLoadedVersion(const QString& uid, const QString& version);
|
||||
|
||||
public: // for usage by parsers only
|
||||
void merge(const std::shared_ptr<Index>& other);
|
||||
|
||||
protected:
|
||||
void parse(const QJsonObject& obj) override;
|
||||
|
||||
private:
|
||||
|
@ -41,6 +41,7 @@ static std::shared_ptr<Index> parseIndexInternal(const QJsonObject& obj)
|
||||
std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject& obj) {
|
||||
VersionList::Ptr list = std::make_shared<VersionList>(requireString(obj, "uid"));
|
||||
list->setName(ensureString(obj, "name", QString()));
|
||||
list->setSha256(ensureString(obj, "sha256", QString()));
|
||||
return list;
|
||||
});
|
||||
return std::make_shared<Index>(lists);
|
||||
@ -58,6 +59,9 @@ static Version::Ptr parseCommonVersion(const QString& uid, const QJsonObject& ob
|
||||
parseRequires(obj, &reqs, "requires");
|
||||
parseRequires(obj, &conflicts, "conflicts");
|
||||
version->setRequires(reqs, conflicts);
|
||||
if (auto sha256 = ensureString(obj, "sha256", QString()); !sha256.isEmpty()) {
|
||||
version->setSha256(sha256);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <memory>
|
||||
|
||||
#include <set>
|
||||
#include "Exception.h"
|
||||
#include "meta/BaseEntity.h"
|
||||
|
||||
namespace Meta {
|
||||
class Index;
|
||||
|
@ -18,12 +18,9 @@
|
||||
#include <QDateTime>
|
||||
|
||||
#include "JsonFormat.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
|
||||
Meta::Version::Version(const QString& uid, const QString& version) : BaseVersion(), m_uid(uid), m_version(version) {}
|
||||
|
||||
Meta::Version::~Version() {}
|
||||
|
||||
QString Meta::Version::descriptor()
|
||||
{
|
||||
return m_version;
|
||||
@ -71,6 +68,9 @@ void Meta::Version::mergeFromList(const Meta::Version::Ptr& other)
|
||||
if (m_volatile != other->m_volatile) {
|
||||
setVolatile(other->m_volatile);
|
||||
}
|
||||
if (!other->m_sha256.isEmpty()) {
|
||||
m_sha256 = other->m_sha256;
|
||||
}
|
||||
}
|
||||
|
||||
void Meta::Version::merge(const Version::Ptr& other)
|
||||
|
@ -38,7 +38,7 @@ class Version : public QObject, public BaseVersion, public BaseEntity {
|
||||
using Ptr = std::shared_ptr<Version>;
|
||||
|
||||
explicit Version(const QString& uid, const QString& version);
|
||||
virtual ~Version();
|
||||
virtual ~Version() = default;
|
||||
|
||||
QString descriptor() override;
|
||||
QString name() override;
|
||||
@ -52,7 +52,7 @@ class Version : public QObject, public BaseVersion, public BaseEntity {
|
||||
const Meta::RequireSet& requiredSet() const { return m_requires; }
|
||||
VersionFilePtr data() const { return m_data; }
|
||||
bool isRecommended() const { return m_recommended; }
|
||||
bool isLoaded() const { return m_data != nullptr; }
|
||||
bool isLoaded() const { return m_data != nullptr && BaseEntity::isLoaded(); }
|
||||
|
||||
void merge(const Version::Ptr& other);
|
||||
void mergeFromList(const Version::Ptr& other);
|
||||
|
@ -17,8 +17,13 @@
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Index.h"
|
||||
#include "JsonFormat.h"
|
||||
#include "Version.h"
|
||||
#include "meta/BaseEntity.h"
|
||||
#include "net/Mode.h"
|
||||
#include "tasks/SequentialTask.h"
|
||||
|
||||
namespace Meta {
|
||||
VersionList::VersionList(const QString& uid, QObject* parent) : BaseVersionList(parent), m_uid(uid)
|
||||
@ -28,8 +33,11 @@ VersionList::VersionList(const QString& uid, QObject* parent) : BaseVersionList(
|
||||
|
||||
Task::Ptr VersionList::getLoadTask()
|
||||
{
|
||||
load(Net::Mode::Online);
|
||||
return getCurrentTask();
|
||||
auto loadTask =
|
||||
makeShared<SequentialTask>(this, tr("Load meta for %1", "This is for the task name that loads the meta index.").arg(m_uid));
|
||||
loadTask->addTask(APPLICATION->metadataIndex()->loadTask(Net::Mode::Online));
|
||||
loadTask->addTask(this->loadTask(Net::Mode::Online));
|
||||
return loadTask;
|
||||
}
|
||||
|
||||
bool VersionList::isLoaded()
|
||||
@ -142,6 +150,8 @@ Version::Ptr VersionList::getVersion(const QString& version)
|
||||
if (!out) {
|
||||
out = std::make_shared<Version>(m_uid, version);
|
||||
m_lookup[version] = out;
|
||||
setupAddedVersion(m_versions.size(), out);
|
||||
m_versions.append(out);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@ -202,6 +212,9 @@ void VersionList::mergeFromIndex(const VersionList::Ptr& other)
|
||||
if (m_name != other->m_name) {
|
||||
setName(other->m_name);
|
||||
}
|
||||
if (!other->m_sha256.isEmpty()) {
|
||||
m_sha256 = other->m_sha256;
|
||||
}
|
||||
}
|
||||
|
||||
void VersionList::merge(const VersionList::Ptr& other)
|
||||
@ -209,23 +222,27 @@ void VersionList::merge(const VersionList::Ptr& other)
|
||||
if (m_name != other->m_name) {
|
||||
setName(other->m_name);
|
||||
}
|
||||
if (!other->m_sha256.isEmpty()) {
|
||||
m_sha256 = other->m_sha256;
|
||||
}
|
||||
|
||||
// TODO: do not reset the whole model. maybe?
|
||||
beginResetModel();
|
||||
m_versions.clear();
|
||||
if (other->m_versions.isEmpty()) {
|
||||
qWarning() << "Empty list loaded ...";
|
||||
}
|
||||
for (const Version::Ptr& version : other->m_versions) {
|
||||
for (auto version : other->m_versions) {
|
||||
// we already have the version. merge the contents
|
||||
if (m_lookup.contains(version->version())) {
|
||||
m_lookup.value(version->version())->mergeFromList(version);
|
||||
auto existing = m_lookup.value(version->version());
|
||||
existing->mergeFromList(version);
|
||||
version = existing;
|
||||
} else {
|
||||
m_lookup.insert(version->uid(), version);
|
||||
m_lookup.insert(version->version(), version);
|
||||
// connect it.
|
||||
setupAddedVersion(m_versions.size(), version);
|
||||
m_versions.append(version);
|
||||
}
|
||||
// connect it.
|
||||
setupAddedVersion(m_versions.size(), version);
|
||||
m_versions.append(version);
|
||||
m_recommended = getBetterVersion(m_recommended, version);
|
||||
}
|
||||
endResetModel();
|
||||
@ -233,14 +250,15 @@ void VersionList::merge(const VersionList::Ptr& other)
|
||||
|
||||
void VersionList::setupAddedVersion(const int row, const Version::Ptr& version)
|
||||
{
|
||||
// FIXME: do not disconnect from everythin, disconnect only the lambdas here
|
||||
version->disconnect();
|
||||
disconnect(version.get(), &Version::requiresChanged, this, nullptr);
|
||||
disconnect(version.get(), &Version::timeChanged, this, nullptr);
|
||||
disconnect(version.get(), &Version::typeChanged, this, nullptr);
|
||||
|
||||
connect(version.get(), &Version::requiresChanged, this,
|
||||
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << RequiresRole); });
|
||||
connect(version.get(), &Version::timeChanged, this,
|
||||
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TimeRole << SortRole); });
|
||||
connect(version.get(), &Version::typeChanged, this,
|
||||
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TypeRole); });
|
||||
[this, row]() { emit dataChanged(index(row), index(row), { TimeRole, SortRole }); });
|
||||
connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), { TypeRole }); });
|
||||
}
|
||||
|
||||
BaseVersion::Ptr VersionList::getRecommended() const
|
||||
@ -248,4 +266,14 @@ BaseVersion::Ptr VersionList::getRecommended() const
|
||||
return m_recommended;
|
||||
}
|
||||
|
||||
void VersionList::waitToLoad()
|
||||
{
|
||||
if (isLoaded())
|
||||
return;
|
||||
QEventLoop ev;
|
||||
auto task = getLoadTask();
|
||||
QObject::connect(task.get(), &Task::finished, &ev, &QEventLoop::quit);
|
||||
task->start();
|
||||
ev.exec();
|
||||
}
|
||||
} // namespace Meta
|
||||
|
@ -30,13 +30,14 @@ class VersionList : public BaseVersionList, public BaseEntity {
|
||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||
public:
|
||||
explicit VersionList(const QString& uid, QObject* parent = nullptr);
|
||||
virtual ~VersionList() = default;
|
||||
|
||||
using Ptr = std::shared_ptr<VersionList>;
|
||||
|
||||
enum Roles { UidRole = Qt::UserRole + 100, TimeRole, RequiresRole, VersionPtrRole };
|
||||
|
||||
Task::Ptr getLoadTask() override;
|
||||
bool isLoaded() override;
|
||||
[[nodiscard]] Task::Ptr getLoadTask() override;
|
||||
const BaseVersion::Ptr at(int i) const override;
|
||||
int count() const override;
|
||||
void sortVersions() override;
|
||||
@ -60,6 +61,9 @@ class VersionList : public BaseVersionList, public BaseEntity {
|
||||
|
||||
QVector<Version::Ptr> versions() const { return m_versions; }
|
||||
|
||||
// this blocks until the version list is loaded
|
||||
void waitToLoad();
|
||||
|
||||
public: // for usage only by parsers
|
||||
void setName(const QString& name);
|
||||
void setVersions(const QVector<Version::Ptr>& versions);
|
||||
|
@ -283,8 +283,7 @@ Net::NetRequest::Ptr AssetObject::getDownloadAction()
|
||||
if ((!objectFile.isFile()) || (objectFile.size() != size)) {
|
||||
auto objectDL = Net::ApiDownload::makeFile(getUrl(), objectFile.filePath());
|
||||
if (hash.size()) {
|
||||
auto rawHash = QByteArray::fromHex(hash.toLatin1());
|
||||
objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash));
|
||||
objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, hash));
|
||||
}
|
||||
objectDL->setProgress(objectDL->getProgress(), size);
|
||||
return objectDL;
|
||||
|
@ -56,18 +56,6 @@ Component::Component(PackProfile* parent, const QString& uid)
|
||||
m_uid = uid;
|
||||
}
|
||||
|
||||
Component::Component(PackProfile* parent, std::shared_ptr<Meta::Version> version)
|
||||
{
|
||||
assert(parent);
|
||||
m_parent = parent;
|
||||
|
||||
m_metaVersion = version;
|
||||
m_uid = version->uid();
|
||||
m_version = m_cachedVersion = version->version();
|
||||
m_cachedName = version->name();
|
||||
m_loaded = version->isLoaded();
|
||||
}
|
||||
|
||||
Component::Component(PackProfile* parent, const QString& uid, std::shared_ptr<VersionFile> file)
|
||||
{
|
||||
assert(parent);
|
||||
@ -102,9 +90,6 @@ void Component::applyTo(LaunchProfile* profile)
|
||||
std::shared_ptr<class VersionFile> Component::getVersionFile() const
|
||||
{
|
||||
if (m_metaVersion) {
|
||||
if (!m_metaVersion->isLoaded()) {
|
||||
m_metaVersion->load(Net::Mode::Online);
|
||||
}
|
||||
return m_metaVersion->data();
|
||||
} else {
|
||||
return m_file;
|
||||
@ -131,29 +116,35 @@ int Component::getOrder()
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Component::setOrder(int order)
|
||||
{
|
||||
m_orderOverride = true;
|
||||
m_order = order;
|
||||
}
|
||||
|
||||
QString Component::getID()
|
||||
{
|
||||
return m_uid;
|
||||
}
|
||||
|
||||
QString Component::getName()
|
||||
{
|
||||
if (!m_cachedName.isEmpty())
|
||||
return m_cachedName;
|
||||
return m_uid;
|
||||
}
|
||||
|
||||
QString Component::getVersion()
|
||||
{
|
||||
return m_cachedVersion;
|
||||
}
|
||||
|
||||
QString Component::getFilename()
|
||||
{
|
||||
return m_parent->patchFilePathForUid(m_uid);
|
||||
}
|
||||
|
||||
QDateTime Component::getReleaseDateTime()
|
||||
{
|
||||
if (m_metaVersion) {
|
||||
@ -198,17 +189,14 @@ bool Component::isCustom()
|
||||
|
||||
bool Component::isCustomizable()
|
||||
{
|
||||
if (m_metaVersion) {
|
||||
if (getVersionFile()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return m_metaVersion && getVersionFile();
|
||||
}
|
||||
|
||||
bool Component::isRemovable()
|
||||
{
|
||||
return !m_important;
|
||||
}
|
||||
|
||||
bool Component::isRevertible()
|
||||
{
|
||||
if (isCustom()) {
|
||||
@ -218,18 +206,18 @@ bool Component::isRevertible()
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Component::isMoveable()
|
||||
{
|
||||
// HACK, FIXME: this was too dumb and wouldn't follow dependency constraints anyway. For now hardcoded to 'true'.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Component::isVersionChangeable()
|
||||
{
|
||||
auto list = getVersionList();
|
||||
if (list) {
|
||||
if (!list->isLoaded()) {
|
||||
list->load(Net::Mode::Online);
|
||||
}
|
||||
list->waitToLoad();
|
||||
return list->count() != 0;
|
||||
}
|
||||
return false;
|
||||
|
@ -22,7 +22,6 @@ class Component : public QObject, public ProblemProvider {
|
||||
Component(PackProfile* parent, const QString& uid);
|
||||
|
||||
// DEPRECATED: remove these constructors?
|
||||
Component(PackProfile* parent, std::shared_ptr<Meta::Version> version);
|
||||
Component(PackProfile* parent, const QString& uid, std::shared_ptr<VersionFile> file);
|
||||
|
||||
virtual ~Component() {}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "net/Mode.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
/*
|
||||
* This is responsible for loading the components of a component list AND resolving dependency issues between them
|
||||
@ -93,9 +94,9 @@ static LoadResult loadComponent(ComponentPtr component, Task::Ptr& loadTask, Net
|
||||
component->m_loaded = true;
|
||||
result = LoadResult::LoadedLocal;
|
||||
} else {
|
||||
metaVersion->load(netmode);
|
||||
loadTask = metaVersion->getCurrentTask();
|
||||
if (loadTask)
|
||||
loadTask = APPLICATION->metadataIndex()->loadVersion(component->m_uid, component->m_version, netmode);
|
||||
loadTask->start();
|
||||
if (netmode == Net::Mode::Online)
|
||||
result = LoadResult::RequiresRemote;
|
||||
else if (metaVersion->isLoaded())
|
||||
result = LoadResult::LoadedLocal;
|
||||
@ -133,21 +134,6 @@ static LoadResult loadPackProfile(ComponentPtr component, Task::Ptr& loadTask, N
|
||||
}
|
||||
*/
|
||||
|
||||
static LoadResult loadIndex(Task::Ptr& loadTask, Net::Mode netmode)
|
||||
{
|
||||
// FIXME: DECIDE. do we want to run the update task anyway?
|
||||
if (APPLICATION->metadataIndex()->isLoaded()) {
|
||||
qDebug() << "Index is already loaded";
|
||||
return LoadResult::LoadedLocal;
|
||||
}
|
||||
APPLICATION->metadataIndex()->load(netmode);
|
||||
loadTask = APPLICATION->metadataIndex()->getCurrentTask();
|
||||
if (loadTask) {
|
||||
return LoadResult::RequiresRemote;
|
||||
}
|
||||
// FIXME: this is assuming the load succeeded... did it really?
|
||||
return LoadResult::LoadedLocal;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ComponentUpdateTask::loadComponents()
|
||||
@ -156,23 +142,7 @@ void ComponentUpdateTask::loadComponents()
|
||||
size_t taskIndex = 0;
|
||||
size_t componentIndex = 0;
|
||||
d->remoteLoadSuccessful = true;
|
||||
// load the main index (it is needed to determine if components can revert)
|
||||
{
|
||||
// FIXME: tear out as a method? or lambda?
|
||||
Task::Ptr indexLoadTask;
|
||||
auto singleResult = loadIndex(indexLoadTask, d->netmode);
|
||||
result = composeLoadResult(result, singleResult);
|
||||
if (indexLoadTask) {
|
||||
qDebug() << "Remote loading is being run for metadata index";
|
||||
RemoteLoadStatus status;
|
||||
status.type = RemoteLoadStatus::Type::Index;
|
||||
d->remoteLoadStatusList.append(status);
|
||||
connect(indexLoadTask.get(), &Task::succeeded, [=]() { remoteLoadSucceeded(taskIndex); });
|
||||
connect(indexLoadTask.get(), &Task::failed, [=](const QString& error) { remoteLoadFailed(taskIndex, error); });
|
||||
connect(indexLoadTask.get(), &Task::aborted, [=]() { remoteLoadFailed(taskIndex, tr("Aborted")); });
|
||||
taskIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// load all the components OR their lists...
|
||||
for (auto component : d->m_list->d->components) {
|
||||
Task::Ptr loadTask;
|
||||
@ -206,12 +176,13 @@ void ComponentUpdateTask::loadComponents()
|
||||
result = composeLoadResult(result, singleResult);
|
||||
if (loadTask) {
|
||||
qDebug() << "Remote loading is being run for" << component->getName();
|
||||
connect(loadTask.get(), &Task::succeeded, [=]() { remoteLoadSucceeded(taskIndex); });
|
||||
connect(loadTask.get(), &Task::failed, [=](const QString& error) { remoteLoadFailed(taskIndex, error); });
|
||||
connect(loadTask.get(), &Task::aborted, [=]() { remoteLoadFailed(taskIndex, tr("Aborted")); });
|
||||
connect(loadTask.get(), &Task::succeeded, this, [this, taskIndex]() { remoteLoadSucceeded(taskIndex); });
|
||||
connect(loadTask.get(), &Task::failed, this, [this, taskIndex](const QString& error) { remoteLoadFailed(taskIndex, error); });
|
||||
connect(loadTask.get(), &Task::aborted, this, [this, taskIndex]() { remoteLoadFailed(taskIndex, tr("Aborted")); });
|
||||
RemoteLoadStatus status;
|
||||
status.type = loadType;
|
||||
status.PackProfileIndex = componentIndex;
|
||||
status.task = loadTask;
|
||||
d->remoteLoadStatusList.append(status);
|
||||
taskIndex++;
|
||||
}
|
||||
@ -518,7 +489,14 @@ void ComponentUpdateTask::resolveDependencies(bool checkOnly)
|
||||
|
||||
void ComponentUpdateTask::remoteLoadSucceeded(size_t taskIndex)
|
||||
{
|
||||
if (static_cast<size_t>(d->remoteLoadStatusList.size()) < taskIndex) {
|
||||
qWarning() << "Got task index outside of results" << taskIndex;
|
||||
return;
|
||||
}
|
||||
auto& taskSlot = d->remoteLoadStatusList[taskIndex];
|
||||
disconnect(taskSlot.task.get(), &Task::succeeded, this, nullptr);
|
||||
disconnect(taskSlot.task.get(), &Task::failed, this, nullptr);
|
||||
disconnect(taskSlot.task.get(), &Task::aborted, this, nullptr);
|
||||
if (taskSlot.finished) {
|
||||
qWarning() << "Got multiple results from remote load task" << taskIndex;
|
||||
return;
|
||||
@ -538,7 +516,14 @@ void ComponentUpdateTask::remoteLoadSucceeded(size_t taskIndex)
|
||||
|
||||
void ComponentUpdateTask::remoteLoadFailed(size_t taskIndex, const QString& msg)
|
||||
{
|
||||
if (static_cast<size_t>(d->remoteLoadStatusList.size()) < taskIndex) {
|
||||
qWarning() << "Got task index outside of results" << taskIndex;
|
||||
return;
|
||||
}
|
||||
auto& taskSlot = d->remoteLoadStatusList[taskIndex];
|
||||
disconnect(taskSlot.task.get(), &Task::succeeded, this, nullptr);
|
||||
disconnect(taskSlot.task.get(), &Task::failed, this, nullptr);
|
||||
disconnect(taskSlot.task.get(), &Task::aborted, this, nullptr);
|
||||
if (taskSlot.finished) {
|
||||
qWarning() << "Got multiple results from remote load task" << taskIndex;
|
||||
return;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QString>
|
||||
#include <cstddef>
|
||||
#include "net/Mode.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
class PackProfile;
|
||||
|
||||
@ -13,6 +14,7 @@ struct RemoteLoadStatus {
|
||||
bool finished = false;
|
||||
bool succeeded = false;
|
||||
QString error;
|
||||
Task::Ptr task;
|
||||
};
|
||||
|
||||
struct ComponentUpdateTaskData {
|
||||
|
@ -147,9 +147,8 @@ QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeC
|
||||
options |= Net::Download::Option::MakeEternal;
|
||||
|
||||
if (sha1.size()) {
|
||||
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
|
||||
auto dl = Net::ApiDownload::makeCached(url, entry, options);
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, sha1));
|
||||
qDebug() << "Checksummed Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
|
||||
out.append(dl);
|
||||
} else {
|
||||
|
@ -16,32 +16,22 @@
|
||||
#include "MinecraftUpdate.h"
|
||||
#include "MinecraftInstance.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <FileSystem.h>
|
||||
#include "BaseInstance.h"
|
||||
#include "minecraft/Library.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
|
||||
#include "tasks/SequentialTask.h"
|
||||
#include "update/AssetUpdateTask.h"
|
||||
#include "update/FMLLibrariesTask.h"
|
||||
#include "update/FoldersTask.h"
|
||||
#include "update/LibrariesTask.h"
|
||||
|
||||
#include <meta/Index.h>
|
||||
#include <meta/Version.h>
|
||||
|
||||
MinecraftUpdate::MinecraftUpdate(MinecraftInstance* inst, QObject* parent) : Task(parent), m_inst(inst) {}
|
||||
MinecraftUpdate::MinecraftUpdate(MinecraftInstance* inst, QObject* parent) : SequentialTask(parent), m_inst(inst) {}
|
||||
|
||||
void MinecraftUpdate::executeTask()
|
||||
{
|
||||
m_tasks.clear();
|
||||
m_queue.clear();
|
||||
// create folders
|
||||
{
|
||||
m_tasks.append(makeShared<FoldersTask>(m_inst));
|
||||
addTask(makeShared<FoldersTask>(m_inst));
|
||||
}
|
||||
|
||||
// add metadata update task if necessary
|
||||
@ -50,121 +40,24 @@ void MinecraftUpdate::executeTask()
|
||||
components->reload(Net::Mode::Online);
|
||||
auto task = components->getCurrentTask();
|
||||
if (task) {
|
||||
m_tasks.append(task);
|
||||
addTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
// libraries download
|
||||
{
|
||||
m_tasks.append(makeShared<LibrariesTask>(m_inst));
|
||||
addTask(makeShared<LibrariesTask>(m_inst));
|
||||
}
|
||||
|
||||
// FML libraries download and copy into the instance
|
||||
{
|
||||
m_tasks.append(makeShared<FMLLibrariesTask>(m_inst));
|
||||
addTask(makeShared<FMLLibrariesTask>(m_inst));
|
||||
}
|
||||
|
||||
// assets update
|
||||
{
|
||||
m_tasks.append(makeShared<AssetUpdateTask>(m_inst));
|
||||
addTask(makeShared<AssetUpdateTask>(m_inst));
|
||||
}
|
||||
|
||||
if (!m_preFailure.isEmpty()) {
|
||||
emitFailed(m_preFailure);
|
||||
return;
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
void MinecraftUpdate::next()
|
||||
{
|
||||
if (m_abort) {
|
||||
emitFailed(tr("Aborted by user."));
|
||||
return;
|
||||
}
|
||||
if (m_failed_out_of_order) {
|
||||
emitFailed(m_fail_reason);
|
||||
return;
|
||||
}
|
||||
m_currentTask++;
|
||||
if (m_currentTask > 0) {
|
||||
auto task = m_tasks[m_currentTask - 1];
|
||||
disconnect(task.get(), &Task::succeeded, this, &MinecraftUpdate::subtaskSucceeded);
|
||||
disconnect(task.get(), &Task::failed, this, &MinecraftUpdate::subtaskFailed);
|
||||
disconnect(task.get(), &Task::aborted, this, &Task::abort);
|
||||
disconnect(task.get(), &Task::progress, this, &MinecraftUpdate::progress);
|
||||
disconnect(task.get(), &Task::stepProgress, this, &MinecraftUpdate::propagateStepProgress);
|
||||
disconnect(task.get(), &Task::status, this, &MinecraftUpdate::setStatus);
|
||||
disconnect(task.get(), &Task::details, this, &MinecraftUpdate::setDetails);
|
||||
}
|
||||
if (m_currentTask == m_tasks.size()) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
auto task = m_tasks[m_currentTask];
|
||||
// if the task is already finished by the time we look at it, skip it
|
||||
if (task->isFinished()) {
|
||||
qCritical() << "MinecraftUpdate: Skipping finished subtask" << m_currentTask << ":" << task.get();
|
||||
next();
|
||||
}
|
||||
connect(task.get(), &Task::succeeded, this, &MinecraftUpdate::subtaskSucceeded);
|
||||
connect(task.get(), &Task::failed, this, &MinecraftUpdate::subtaskFailed);
|
||||
connect(task.get(), &Task::aborted, this, &Task::abort);
|
||||
connect(task.get(), &Task::progress, this, &MinecraftUpdate::progress);
|
||||
connect(task.get(), &Task::stepProgress, this, &MinecraftUpdate::propagateStepProgress);
|
||||
connect(task.get(), &Task::status, this, &MinecraftUpdate::setStatus);
|
||||
connect(task.get(), &Task::details, this, &MinecraftUpdate::setDetails);
|
||||
// if the task is already running, do not start it again
|
||||
if (!task->isRunning()) {
|
||||
task->start();
|
||||
}
|
||||
}
|
||||
|
||||
void MinecraftUpdate::subtaskSucceeded()
|
||||
{
|
||||
if (isFinished()) {
|
||||
qCritical() << "MinecraftUpdate: Subtask" << sender() << "succeeded, but work was already done!";
|
||||
return;
|
||||
}
|
||||
auto senderTask = QObject::sender();
|
||||
auto currentTask = m_tasks[m_currentTask].get();
|
||||
if (senderTask != currentTask) {
|
||||
qDebug() << "MinecraftUpdate: Subtask" << sender() << "succeeded out of order.";
|
||||
return;
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
void MinecraftUpdate::subtaskFailed(QString error)
|
||||
{
|
||||
if (isFinished()) {
|
||||
qCritical() << "MinecraftUpdate: Subtask" << sender() << "failed, but work was already done!";
|
||||
return;
|
||||
}
|
||||
auto senderTask = QObject::sender();
|
||||
auto currentTask = m_tasks[m_currentTask].get();
|
||||
if (senderTask != currentTask) {
|
||||
qDebug() << "MinecraftUpdate: Subtask" << sender() << "failed out of order.";
|
||||
m_failed_out_of_order = true;
|
||||
m_fail_reason = error;
|
||||
return;
|
||||
}
|
||||
emitFailed(error);
|
||||
}
|
||||
|
||||
bool MinecraftUpdate::abort()
|
||||
{
|
||||
if (!m_abort) {
|
||||
m_abort = true;
|
||||
auto task = m_tasks[m_currentTask];
|
||||
if (task->canAbort()) {
|
||||
return task->abort();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MinecraftUpdate::canAbort() const
|
||||
{
|
||||
return true;
|
||||
SequentialTask::executeTask();
|
||||
}
|
||||
|
@ -15,43 +15,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include "tasks/SequentialTask.h"
|
||||
|
||||
#include <quazip/quazip.h>
|
||||
#include "minecraft/VersionFilterData.h"
|
||||
#include "net/NetJob.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
class MinecraftVersion;
|
||||
class MinecraftInstance;
|
||||
|
||||
// FIXME: This looks very similar to a SequentialTask. Maybe we can reduce code duplications? :^)
|
||||
|
||||
class MinecraftUpdate : public Task {
|
||||
// this needs to be a task because components->reload does stuff that may block
|
||||
class MinecraftUpdate : public SequentialTask {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MinecraftUpdate(MinecraftInstance* inst, QObject* parent = 0);
|
||||
virtual ~MinecraftUpdate() {};
|
||||
virtual ~MinecraftUpdate() = default;
|
||||
|
||||
void executeTask() override;
|
||||
bool canAbort() const override;
|
||||
|
||||
private slots:
|
||||
bool abort() override;
|
||||
void subtaskSucceeded();
|
||||
void subtaskFailed(QString error);
|
||||
|
||||
private:
|
||||
void next();
|
||||
|
||||
private:
|
||||
MinecraftInstance* m_inst = nullptr;
|
||||
QList<Task::Ptr> m_tasks;
|
||||
QString m_preFailure;
|
||||
int m_currentTask = -1;
|
||||
bool m_abort = false;
|
||||
bool m_failed_out_of_order = false;
|
||||
QString m_fail_reason;
|
||||
};
|
||||
|
@ -32,8 +32,7 @@ void AssetUpdateTask::executeTask()
|
||||
auto hexSha1 = assets->sha1.toLatin1();
|
||||
qDebug() << "Asset index SHA1:" << hexSha1;
|
||||
auto dl = Net::ApiDownload::makeCached(indexUrl, entry);
|
||||
auto rawSha1 = QByteArray::fromHex(assets->sha1.toLatin1());
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, assets->sha1));
|
||||
job->addNetAction(dl);
|
||||
|
||||
downloadJob.reset(job);
|
||||
|
@ -343,9 +343,7 @@ QString PackInstallTask::getVersionForLoader(QString uid)
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
if (!vlist->isLoaded()) {
|
||||
vlist->load(Net::Mode::Online);
|
||||
}
|
||||
vlist->waitToLoad();
|
||||
|
||||
if (m_version.loader.recommended || m_version.loader.latest) {
|
||||
for (int i = 0; i < vlist->versions().size(); i++) {
|
||||
@ -638,8 +636,7 @@ void PackInstallTask::installConfigs()
|
||||
|
||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||
if (!m_version.configs.sha1.isEmpty()) {
|
||||
auto rawSha1 = QByteArray::fromHex(m_version.configs.sha1.toLatin1());
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, m_version.configs.sha1));
|
||||
}
|
||||
jobPtr->addNetAction(dl);
|
||||
archivePath = entry->getFullPath();
|
||||
@ -758,8 +755,7 @@ void PackInstallTask::downloadMods()
|
||||
|
||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||
if (!mod.md5.isEmpty()) {
|
||||
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, mod.md5));
|
||||
}
|
||||
jobPtr->addNetAction(dl);
|
||||
} else if (mod.type == ModType::Decomp) {
|
||||
@ -769,8 +765,7 @@ void PackInstallTask::downloadMods()
|
||||
|
||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||
if (!mod.md5.isEmpty()) {
|
||||
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, mod.md5));
|
||||
}
|
||||
jobPtr->addNetAction(dl);
|
||||
} else {
|
||||
@ -783,8 +778,7 @@ void PackInstallTask::downloadMods()
|
||||
|
||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||
if (!mod.md5.isEmpty()) {
|
||||
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, mod.md5));
|
||||
}
|
||||
jobPtr->addNetAction(dl);
|
||||
|
||||
@ -1075,36 +1069,7 @@ void PackInstallTask::install()
|
||||
|
||||
static Meta::Version::Ptr getComponentVersion(const QString& uid, const QString& version)
|
||||
{
|
||||
auto vlist = APPLICATION->metadataIndex()->get(uid);
|
||||
if (!vlist)
|
||||
return {};
|
||||
|
||||
if (!vlist->isLoaded()) {
|
||||
QEventLoop loadVersionLoop;
|
||||
auto task = vlist->getLoadTask();
|
||||
QObject::connect(task.get(), &Task::finished, &loadVersionLoop, &QEventLoop::quit);
|
||||
if (!task->isRunning())
|
||||
task->start();
|
||||
|
||||
loadVersionLoop.exec();
|
||||
}
|
||||
|
||||
auto ver = vlist->getVersion(version);
|
||||
if (!ver)
|
||||
return {};
|
||||
|
||||
if (!ver->isLoaded()) {
|
||||
QEventLoop loadVersionLoop;
|
||||
ver->load(Net::Mode::Online);
|
||||
auto task = ver->getCurrentTask();
|
||||
QObject::connect(task.get(), &Task::finished, &loadVersionLoop, &QEventLoop::quit);
|
||||
if (!task->isRunning())
|
||||
task->start();
|
||||
|
||||
loadVersionLoop.exec();
|
||||
}
|
||||
|
||||
return ver;
|
||||
return APPLICATION->metadataIndex()->getLoadedVersion(uid, version);
|
||||
}
|
||||
|
||||
} // namespace ATLauncher
|
||||
|
@ -246,7 +246,7 @@ void FlamePackExportTask::makeApiRequest()
|
||||
pendingHashes.clear();
|
||||
getProjectsInfo();
|
||||
});
|
||||
connect(task.get(), &NetJob::failed, this, &FlamePackExportTask::getProjectsInfo);
|
||||
connect(task.get(), &Task::failed, this, &FlamePackExportTask::getProjectsInfo);
|
||||
task->start();
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "ModrinthPackExportTask.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QCryptographicHash>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
@ -28,6 +29,7 @@
|
||||
#include "minecraft/mod/MetadataHandler.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "modplatform/helpers/HashUtils.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
const QStringList ModrinthPackExportTask::PREFIXES({ "mods/", "coremods/", "resourcepacks/", "texturepacks/", "shaderpacks/" });
|
||||
const QStringList ModrinthPackExportTask::FILE_EXTENSIONS({ "jar", "litemod", "zip" });
|
||||
@ -154,8 +156,8 @@ void ModrinthPackExportTask::makeApiRequest()
|
||||
setStatus(tr("Finding versions for hashes..."));
|
||||
auto response = std::make_shared<QByteArray>();
|
||||
task = api.currentVersions(pendingHashes.values(), "sha512", response);
|
||||
connect(task.get(), &NetJob::succeeded, [this, response]() { parseApiResponse(response); });
|
||||
connect(task.get(), &NetJob::failed, this, &ModrinthPackExportTask::emitFailed);
|
||||
connect(task.get(), &Task::succeeded, [this, response]() { parseApiResponse(response); });
|
||||
connect(task.get(), &Task::failed, this, &ModrinthPackExportTask::emitFailed);
|
||||
task->start();
|
||||
}
|
||||
}
|
||||
|
@ -114,8 +114,7 @@ void Technic::SolderPackInstallTask::fileListSucceeded()
|
||||
|
||||
auto dl = Net::ApiDownload::makeFile(mod.url, path);
|
||||
if (!mod.md5.isEmpty()) {
|
||||
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, mod.md5));
|
||||
}
|
||||
m_filesNetJob->addNetAction(dl);
|
||||
|
||||
|
@ -43,6 +43,9 @@
|
||||
namespace Net {
|
||||
class ChecksumValidator : public Validator {
|
||||
public:
|
||||
ChecksumValidator(QCryptographicHash::Algorithm algorithm, QString expectedHex)
|
||||
: Net::ChecksumValidator(algorithm, QByteArray::fromHex(expectedHex.toLatin1()))
|
||||
{}
|
||||
ChecksumValidator(QCryptographicHash::Algorithm algorithm, QByteArray expected = QByteArray())
|
||||
: m_checksum(algorithm), m_expected(expected) {};
|
||||
virtual ~ChecksumValidator() = default;
|
||||
|
@ -592,8 +592,7 @@ void TranslationsModel::downloadTranslation(QString key)
|
||||
entry->setStale(true);
|
||||
|
||||
auto dl = Net::Download::makeCached(QUrl(BuildConfig.TRANSLATIONS_BASE_URL + lang->file_name), entry);
|
||||
auto rawHash = QByteArray::fromHex(lang->file_sha1.toLatin1());
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash));
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, lang->file_sha1));
|
||||
dl->setProgress(dl->getProgress(), lang->file_size);
|
||||
|
||||
d->m_dl_job.reset(new NetJob("Translation for " + key, APPLICATION->network()));
|
||||
|
@ -41,6 +41,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
|
@ -321,14 +321,9 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
|
||||
updateUi();
|
||||
}
|
||||
|
||||
void ResourcePage::onVersionSelectionChanged(QString versionData)
|
||||
void ResourcePage::onVersionSelectionChanged(int index)
|
||||
{
|
||||
if (versionData.isNull() || versionData.isEmpty()) {
|
||||
m_selected_version_index = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
m_selected_version_index = m_ui->versionSelectionBox->currentData().toInt();
|
||||
m_selected_version_index = index;
|
||||
updateSelectionButton();
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ class ResourcePage : public QWidget, public BasePage {
|
||||
virtual void triggerSearch() = 0;
|
||||
|
||||
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
||||
void onVersionSelectionChanged(QString data);
|
||||
void onVersionSelectionChanged(int index);
|
||||
void onResourceSelected();
|
||||
|
||||
// NOTE: Can't use [[nodiscard]] here because of https://bugreports.qt.io/browse/QTBUG-58628 on Qt 5.12
|
||||
|
@ -17,9 +17,9 @@ TexturePackResourceModel::TexturePackResourceModel(BaseInstance const& inst, Res
|
||||
{
|
||||
if (!m_version_list->isLoaded()) {
|
||||
qDebug() << "Loading version list...";
|
||||
auto task = m_version_list->getLoadTask();
|
||||
if (!task->isRunning())
|
||||
task->start();
|
||||
m_task = m_version_list->getLoadTask();
|
||||
if (!m_task->isRunning())
|
||||
m_task->start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,8 @@ void waitOnVersionListLoad(Meta::VersionList::Ptr version_list)
|
||||
|
||||
auto task = version_list->getLoadTask();
|
||||
QObject::connect(task.get(), &Task::finished, &load_version_list_loop, &QEventLoop::quit);
|
||||
|
||||
if (!task->isRunning())
|
||||
task->start();
|
||||
load_version_list_loop.exec();
|
||||
if (time_limit_for_list_load.isActive())
|
||||
time_limit_for_list_load.stop();
|
||||
|
@ -22,6 +22,7 @@ class TexturePackResourceModel : public ResourcePackResourceModel {
|
||||
|
||||
protected:
|
||||
Meta::VersionList::Ptr m_version_list;
|
||||
Task::Ptr m_task;
|
||||
};
|
||||
|
||||
} // namespace ResourceDownload
|
||||
|
@ -84,7 +84,7 @@ FlamePage::FlamePage(NewInstanceDialog* dialog, QWidget* parent)
|
||||
|
||||
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlamePage::onSelectionChanged);
|
||||
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlamePage::onVersionSelectionChanged);
|
||||
connect(ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FlamePage::onVersionSelectionChanged);
|
||||
|
||||
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
|
||||
ui->packDescription->setMetaEntry("FlamePacks");
|
||||
@ -240,17 +240,17 @@ void FlamePage::suggestCurrent()
|
||||
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
|
||||
}
|
||||
|
||||
void FlamePage::onVersionSelectionChanged(QString version)
|
||||
void FlamePage::onVersionSelectionChanged(int index)
|
||||
{
|
||||
bool is_blocked = false;
|
||||
ui->versionSelectionBox->currentData().toInt(&is_blocked);
|
||||
|
||||
if (version.isNull() || version.isEmpty() || is_blocked) {
|
||||
if (index == -1 || is_blocked) {
|
||||
m_selected_version_index = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
m_selected_version_index = ui->versionSelectionBox->currentIndex();
|
||||
m_selected_version_index = index;
|
||||
|
||||
Q_ASSERT(current.versions.at(m_selected_version_index).downloadUrl == ui->versionSelectionBox->currentData().toString());
|
||||
|
||||
|
@ -78,7 +78,7 @@ class FlamePage : public QWidget, public BasePage {
|
||||
private slots:
|
||||
void triggerSearch();
|
||||
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
||||
void onVersionSelectionChanged(QString data);
|
||||
void onVersionSelectionChanged(int index);
|
||||
|
||||
private:
|
||||
Ui::FlamePage* ui = nullptr;
|
||||
|
@ -60,7 +60,7 @@ FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance) :
|
||||
// so it's best not to connect them in the parent's contructor...
|
||||
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameModPage::onSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameModPage::onVersionSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FlameModPage::onVersionSelectionChanged);
|
||||
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameModPage::onResourceSelected);
|
||||
|
||||
m_ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
@ -94,7 +94,8 @@ FlameResourcePackPage::FlameResourcePackPage(ResourcePackDownloadDialog* dialog,
|
||||
// so it's best not to connect them in the parent's contructor...
|
||||
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameResourcePackPage::onSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameResourcePackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&FlameResourcePackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameResourcePackPage::onResourceSelected);
|
||||
|
||||
m_ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
@ -128,7 +129,8 @@ FlameTexturePackPage::FlameTexturePackPage(TexturePackDownloadDialog* dialog, Ba
|
||||
// so it's best not to connect them in the parent's contructor...
|
||||
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameTexturePackPage::onSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameTexturePackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&FlameTexturePackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameTexturePackPage::onResourceSelected);
|
||||
|
||||
m_ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
@ -162,7 +164,8 @@ FlameShaderPackPage::FlameShaderPackPage(ShaderPackDownloadDialog* dialog, BaseI
|
||||
// so it's best not to connect them in the parent's constructor...
|
||||
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameShaderPackPage::onSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameShaderPackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&FlameShaderPackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameShaderPackPage::onResourceSelected);
|
||||
|
||||
m_ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
|
@ -85,7 +85,7 @@ ModrinthPage::ModrinthPage(NewInstanceDialog* dialog, QWidget* parent)
|
||||
|
||||
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged);
|
||||
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged);
|
||||
connect(ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ModrinthPage::onVersionSelectionChanged);
|
||||
|
||||
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
|
||||
ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
@ -342,9 +342,9 @@ void ModrinthPage::triggerSearch()
|
||||
m_fetch_progress.watch(m_model->activeSearchJob().get());
|
||||
}
|
||||
|
||||
void ModrinthPage::onVersionSelectionChanged(QString version)
|
||||
void ModrinthPage::onVersionSelectionChanged(int index)
|
||||
{
|
||||
if (version.isNull() || version.isEmpty()) {
|
||||
if (index == -1) {
|
||||
selectedVersion = "";
|
||||
return;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ class ModrinthPage : public QWidget, public BasePage {
|
||||
|
||||
private slots:
|
||||
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
||||
void onVersionSelectionChanged(QString data);
|
||||
void onVersionSelectionChanged(int index);
|
||||
void triggerSearch();
|
||||
|
||||
private:
|
||||
|
@ -58,7 +58,8 @@ ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instan
|
||||
// so it's best not to connect them in the parent's constructor...
|
||||
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthModPage::onSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthModPage::onVersionSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&ModrinthModPage::onVersionSelectionChanged);
|
||||
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModrinthModPage::onResourceSelected);
|
||||
|
||||
m_ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
@ -76,7 +77,8 @@ ModrinthResourcePackPage::ModrinthResourcePackPage(ResourcePackDownloadDialog* d
|
||||
// so it's best not to connect them in the parent's constructor...
|
||||
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthResourcePackPage::onSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthResourcePackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&ModrinthResourcePackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModrinthResourcePackPage::onResourceSelected);
|
||||
|
||||
m_ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
@ -94,7 +96,8 @@ ModrinthTexturePackPage::ModrinthTexturePackPage(TexturePackDownloadDialog* dial
|
||||
// so it's best not to connect them in the parent's constructor...
|
||||
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthTexturePackPage::onSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthTexturePackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&ModrinthTexturePackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModrinthTexturePackPage::onResourceSelected);
|
||||
|
||||
m_ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
@ -112,7 +115,8 @@ ModrinthShaderPackPage::ModrinthShaderPackPage(ShaderPackDownloadDialog* dialog,
|
||||
// so it's best not to connect them in the parent's constructor...
|
||||
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthShaderPackPage::onSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthShaderPackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&ModrinthShaderPackPage::onVersionSelectionChanged);
|
||||
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModrinthShaderPackPage::onResourceSelected);
|
||||
|
||||
m_ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
|
@ -129,16 +129,12 @@ void VersionSelectWidget::closeEvent(QCloseEvent* event)
|
||||
|
||||
void VersionSelectWidget::loadList()
|
||||
{
|
||||
auto newTask = m_vlist->getLoadTask();
|
||||
if (!newTask) {
|
||||
return;
|
||||
}
|
||||
loadTask = newTask.get();
|
||||
connect(loadTask, &Task::succeeded, this, &VersionSelectWidget::onTaskSucceeded);
|
||||
connect(loadTask, &Task::failed, this, &VersionSelectWidget::onTaskFailed);
|
||||
connect(loadTask, &Task::progress, this, &VersionSelectWidget::changeProgress);
|
||||
if (!loadTask->isRunning()) {
|
||||
loadTask->start();
|
||||
m_load_task = m_vlist->getLoadTask();
|
||||
connect(m_load_task.get(), &Task::succeeded, this, &VersionSelectWidget::onTaskSucceeded);
|
||||
connect(m_load_task.get(), &Task::failed, this, &VersionSelectWidget::onTaskFailed);
|
||||
connect(m_load_task.get(), &Task::progress, this, &VersionSelectWidget::changeProgress);
|
||||
if (!m_load_task->isRunning()) {
|
||||
m_load_task->start();
|
||||
}
|
||||
sneakyProgressBar->setHidden(false);
|
||||
}
|
||||
@ -150,7 +146,7 @@ void VersionSelectWidget::onTaskSucceeded()
|
||||
}
|
||||
sneakyProgressBar->setHidden(true);
|
||||
preselect();
|
||||
loadTask = nullptr;
|
||||
m_load_task.reset();
|
||||
}
|
||||
|
||||
void VersionSelectWidget::onTaskFailed(const QString& reason)
|
||||
|
@ -98,7 +98,7 @@ class VersionSelectWidget : public QWidget {
|
||||
BaseVersionList* m_vlist = nullptr;
|
||||
VersionProxyModel* m_proxyModel = nullptr;
|
||||
int resizeOnColumn = 0;
|
||||
Task* loadTask;
|
||||
Task::Ptr m_load_task;
|
||||
bool preselectedAlready = false;
|
||||
|
||||
QVBoxLayout* verticalLayout = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user