Merge pull request #2528 from Trial97/validate_metadata
validate metadata on instance launch
This commit is contained in:
commit
1b756b99bb
@ -47,7 +47,6 @@
|
|||||||
#include "net/PasteUpload.h"
|
#include "net/PasteUpload.h"
|
||||||
#include "pathmatcher/MultiMatcher.h"
|
#include "pathmatcher/MultiMatcher.h"
|
||||||
#include "pathmatcher/SimplePrefixMatcher.h"
|
#include "pathmatcher/SimplePrefixMatcher.h"
|
||||||
#include "settings/INIFile.h"
|
|
||||||
#include "tools/GenericProfiler.h"
|
#include "tools/GenericProfiler.h"
|
||||||
#include "ui/InstanceWindow.h"
|
#include "ui/InstanceWindow.h"
|
||||||
#include "ui/MainWindow.h"
|
#include "ui/MainWindow.h"
|
||||||
@ -106,7 +105,7 @@
|
|||||||
#include "icons/IconList.h"
|
#include "icons/IconList.h"
|
||||||
#include "net/HttpMetaCache.h"
|
#include "net/HttpMetaCache.h"
|
||||||
|
|
||||||
#include "java/JavaUtils.h"
|
#include "java/JavaInstallList.h"
|
||||||
|
|
||||||
#include "updater/ExternalUpdater.h"
|
#include "updater/ExternalUpdater.h"
|
||||||
|
|
||||||
@ -151,6 +150,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined Q_OS_WIN32
|
#if defined Q_OS_WIN32
|
||||||
|
#include <windows.h>
|
||||||
#include "WindowsConsole.h"
|
#include "WindowsConsole.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class JavaInstallList : public BaseVersionList {
|
|||||||
public:
|
public:
|
||||||
explicit JavaInstallList(QObject* parent = 0);
|
explicit JavaInstallList(QObject* parent = 0);
|
||||||
|
|
||||||
Task::Ptr getLoadTask() override;
|
[[nodiscard]] Task::Ptr getLoadTask() override;
|
||||||
bool isLoaded() override;
|
bool isLoaded() override;
|
||||||
const BaseVersion::Ptr at(int i) const override;
|
const BaseVersion::Ptr at(int i) const override;
|
||||||
int count() const override;
|
int count() const override;
|
||||||
|
@ -15,19 +15,26 @@
|
|||||||
|
|
||||||
#include "BaseEntity.h"
|
#include "BaseEntity.h"
|
||||||
|
|
||||||
|
#include "Exception.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
#include "modplatform/helpers/HashUtils.h"
|
||||||
#include "net/ApiDownload.h"
|
#include "net/ApiDownload.h"
|
||||||
|
#include "net/ChecksumValidator.h"
|
||||||
#include "net/HttpMetaCache.h"
|
#include "net/HttpMetaCache.h"
|
||||||
|
#include "net/Mode.h"
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
|
namespace Meta {
|
||||||
|
|
||||||
class ParsingValidator : public Net::Validator {
|
class ParsingValidator : public Net::Validator {
|
||||||
public: /* con/des */
|
public: /* con/des */
|
||||||
ParsingValidator(Meta::BaseEntity* entity) : m_entity(entity) {};
|
ParsingValidator(BaseEntity* entity) : m_entity(entity) {};
|
||||||
virtual ~ParsingValidator() {};
|
virtual ~ParsingValidator() = default;
|
||||||
|
|
||||||
public: /* methods */
|
public: /* methods */
|
||||||
bool init(QNetworkRequest&) override
|
bool init(QNetworkRequest&) override
|
||||||
@ -61,92 +68,131 @@ class ParsingValidator : public Net::Validator {
|
|||||||
|
|
||||||
private: /* data */
|
private: /* data */
|
||||||
QByteArray m_data;
|
QByteArray m_data;
|
||||||
Meta::BaseEntity* m_entity;
|
BaseEntity* m_entity;
|
||||||
};
|
};
|
||||||
|
|
||||||
Meta::BaseEntity::~BaseEntity() {}
|
QUrl BaseEntity::url() const
|
||||||
|
|
||||||
QUrl Meta::BaseEntity::url() const
|
|
||||||
{
|
{
|
||||||
auto s = APPLICATION->settings();
|
auto s = APPLICATION->settings();
|
||||||
QString metaOverride = s->get("MetaURLOverride").toString();
|
QString metaOverride = s->get("MetaURLOverride").toString();
|
||||||
if (metaOverride.isEmpty()) {
|
if (metaOverride.isEmpty()) {
|
||||||
return QUrl(BuildConfig.META_URL).resolved(localFilename());
|
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 (m_task && m_task->isRunning()) {
|
||||||
if (!QFile::exists(fname)) {
|
return m_task;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
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
|
// consider it loaded only if the main hash is either empty and was remote loadded or the hashes match and was loaded
|
||||||
if (!isLoaded()) {
|
return m_sha256.isEmpty() ? m_load_status == LoadStatus::Remote : m_load_status != LoadStatus::NotLoaded && m_sha256 == m_file_sha256;
|
||||||
if (loadLocalFile()) {
|
}
|
||||||
m_loadStatus = LoadStatus::Local;
|
|
||||||
|
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 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;
|
return;
|
||||||
}
|
}
|
||||||
m_updateTask.reset(new NetJob(QObject::tr("Download of meta file %1").arg(localFilename()), APPLICATION->network()));
|
m_task.reset(new NetJob(QObject::tr("Download of meta file %1").arg(m_entity->localFilename()), APPLICATION->network()));
|
||||||
auto url = this->url();
|
auto url = m_entity->url();
|
||||||
auto entry = APPLICATION->metacache()->resolveEntry("meta", localFilename());
|
auto entry = APPLICATION->metacache()->resolveEntry("meta", m_entity->localFilename());
|
||||||
entry->setStale(true);
|
entry->setStale(true);
|
||||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||||
/*
|
/*
|
||||||
* The validator parses the file and loads it into the object.
|
* The validator parses the file and loads it into the object.
|
||||||
* If that fails, the file is not written to storage.
|
* If that fails, the file is not written to storage.
|
||||||
*/
|
*/
|
||||||
dl->addValidator(new ParsingValidator(this));
|
if (!m_entity->m_sha256.isEmpty())
|
||||||
m_updateTask->addNetAction(dl);
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Algorithm::Sha256, m_entity->m_sha256));
|
||||||
m_updateStatus = UpdateStatus::InProgress;
|
dl->addValidator(new ParsingValidator(m_entity));
|
||||||
QObject::connect(m_updateTask.get(), &NetJob::succeeded, [&]() {
|
m_task->addNetAction(dl);
|
||||||
m_loadStatus = LoadStatus::Remote;
|
m_task->setAskRetry(false);
|
||||||
m_updateStatus = UpdateStatus::Succeeded;
|
connect(m_task.get(), &Task::failed, this, &BaseEntityLoadTask::emitFailed);
|
||||||
m_updateTask.reset();
|
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;
|
connect(m_task.get(), &Task::progress, this, &Task::setProgress);
|
||||||
m_updateTask.reset();
|
connect(m_task.get(), &Task::stepProgress, this, &BaseEntityLoadTask::propagateStepProgress);
|
||||||
});
|
connect(m_task.get(), &Task::status, this, &Task::setStatus);
|
||||||
m_updateTask->start();
|
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?
|
if (m_task) {
|
||||||
return m_updateStatus != UpdateStatus::InProgress;
|
Task::abort();
|
||||||
}
|
return m_task->abort();
|
||||||
|
|
||||||
Task::Ptr Meta::BaseEntity::getCurrentTask()
|
|
||||||
{
|
|
||||||
if (m_updateStatus == UpdateStatus::InProgress) {
|
|
||||||
return m_updateTask;
|
|
||||||
}
|
}
|
||||||
return nullptr;
|
return Task::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Meta
|
||||||
|
@ -17,38 +17,57 @@
|
|||||||
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "QObjectPtr.h"
|
|
||||||
|
|
||||||
#include "net/Mode.h"
|
#include "net/Mode.h"
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
namespace Meta {
|
namespace Meta {
|
||||||
|
class BaseEntityLoadTask;
|
||||||
class BaseEntity {
|
class BaseEntity {
|
||||||
|
friend BaseEntityLoadTask;
|
||||||
|
|
||||||
public: /* types */
|
public: /* types */
|
||||||
using Ptr = std::shared_ptr<BaseEntity>;
|
using Ptr = std::shared_ptr<BaseEntity>;
|
||||||
enum class LoadStatus { NotLoaded, Local, Remote };
|
enum class LoadStatus { NotLoaded, Local, Remote };
|
||||||
enum class UpdateStatus { NotDone, InProgress, Failed, Succeeded };
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~BaseEntity();
|
virtual ~BaseEntity() = default;
|
||||||
|
|
||||||
virtual void parse(const QJsonObject& obj) = 0;
|
|
||||||
|
|
||||||
virtual QString localFilename() const = 0;
|
virtual QString localFilename() const = 0;
|
||||||
virtual QUrl url() const;
|
virtual QUrl url() const;
|
||||||
|
|
||||||
bool isLoaded() const;
|
bool isLoaded() const;
|
||||||
bool shouldStartRemoteUpdate() const;
|
LoadStatus status() const;
|
||||||
|
|
||||||
void load(Net::Mode loadType);
|
/* for parsers */
|
||||||
Task::Ptr getCurrentTask();
|
void setSha256(QString sha256);
|
||||||
|
|
||||||
protected: /* methods */
|
virtual void parse(const QJsonObject& obj) = 0;
|
||||||
bool loadLocalFile();
|
[[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:
|
private:
|
||||||
LoadStatus m_loadStatus = LoadStatus::NotLoaded;
|
LoadStatus m_load_status = LoadStatus::NotLoaded;
|
||||||
UpdateStatus m_updateStatus = UpdateStatus::NotDone;
|
Task::Ptr m_task;
|
||||||
NetJob::Ptr m_updateTask;
|
};
|
||||||
|
|
||||||
|
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
|
} // namespace Meta
|
||||||
|
@ -16,7 +16,10 @@
|
|||||||
#include "Index.h"
|
#include "Index.h"
|
||||||
|
|
||||||
#include "JsonFormat.h"
|
#include "JsonFormat.h"
|
||||||
|
#include "QObjectPtr.h"
|
||||||
#include "VersionList.h"
|
#include "VersionList.h"
|
||||||
|
#include "meta/BaseEntity.h"
|
||||||
|
#include "tasks/SequentialTask.h"
|
||||||
|
|
||||||
namespace Meta {
|
namespace Meta {
|
||||||
Index::Index(QObject* parent) : QAbstractListModel(parent) {}
|
Index::Index(QObject* parent) : QAbstractListModel(parent) {}
|
||||||
@ -51,14 +54,17 @@ QVariant Index::data(const QModelIndex& index, int role) const
|
|||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Index::rowCount(const QModelIndex& parent) const
|
int Index::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return parent.isValid() ? 0 : m_lists.size();
|
return parent.isValid() ? 0 : m_lists.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Index::columnCount(const QModelIndex& parent) const
|
int Index::columnCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return parent.isValid() ? 0 : 1;
|
return parent.isValid() ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Index::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant Index::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0) {
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0) {
|
||||||
@ -79,6 +85,7 @@ VersionList::Ptr Index::get(const QString& uid)
|
|||||||
if (!out) {
|
if (!out) {
|
||||||
out = std::make_shared<VersionList>(uid);
|
out = std::make_shared<VersionList>(uid);
|
||||||
m_uids[uid] = out;
|
m_uids[uid] = out;
|
||||||
|
m_lists.append(out);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -96,7 +103,7 @@ void Index::parse(const QJsonObject& obj)
|
|||||||
|
|
||||||
void Index::merge(const std::shared_ptr<Index>& other)
|
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
|
// initial load, no need to merge
|
||||||
if (m_lists.isEmpty()) {
|
if (m_lists.isEmpty()) {
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
@ -123,7 +130,33 @@ void Index::merge(const std::shared_ptr<Index>& other)
|
|||||||
|
|
||||||
void Index::connectVersionList(const int row, const VersionList::Ptr& list)
|
void Index::connectVersionList(const int row, const VersionList::Ptr& list)
|
||||||
{
|
{
|
||||||
connect(list.get(), &VersionList::nameChanged, this,
|
connect(list.get(), &VersionList::nameChanged, this, [this, row] { emit dataChanged(index(row), index(row), { Qt::DisplayRole }); });
|
||||||
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << 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
|
} // namespace Meta
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "BaseEntity.h"
|
#include "BaseEntity.h"
|
||||||
#include "meta/VersionList.h"
|
#include "meta/VersionList.h"
|
||||||
|
#include "net/Mode.h"
|
||||||
|
|
||||||
class Task;
|
class Task;
|
||||||
|
|
||||||
@ -30,6 +30,7 @@ class Index : public QAbstractListModel, public BaseEntity {
|
|||||||
public:
|
public:
|
||||||
explicit Index(QObject* parent = nullptr);
|
explicit Index(QObject* parent = nullptr);
|
||||||
explicit Index(const QVector<VersionList::Ptr>& lists, QObject* parent = nullptr);
|
explicit Index(const QVector<VersionList::Ptr>& lists, QObject* parent = nullptr);
|
||||||
|
virtual ~Index() = default;
|
||||||
|
|
||||||
enum { UidRole = Qt::UserRole, NameRole, ListPtrRole };
|
enum { UidRole = Qt::UserRole, NameRole, ListPtrRole };
|
||||||
|
|
||||||
@ -47,8 +48,15 @@ class Index : public QAbstractListModel, public BaseEntity {
|
|||||||
|
|
||||||
QVector<VersionList::Ptr> lists() const { return m_lists; }
|
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
|
public: // for usage by parsers only
|
||||||
void merge(const std::shared_ptr<Index>& other);
|
void merge(const std::shared_ptr<Index>& other);
|
||||||
|
|
||||||
|
protected:
|
||||||
void parse(const QJsonObject& obj) override;
|
void parse(const QJsonObject& obj) override;
|
||||||
|
|
||||||
private:
|
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) {
|
std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject& obj) {
|
||||||
VersionList::Ptr list = std::make_shared<VersionList>(requireString(obj, "uid"));
|
VersionList::Ptr list = std::make_shared<VersionList>(requireString(obj, "uid"));
|
||||||
list->setName(ensureString(obj, "name", QString()));
|
list->setName(ensureString(obj, "name", QString()));
|
||||||
|
list->setSha256(ensureString(obj, "sha256", QString()));
|
||||||
return list;
|
return list;
|
||||||
});
|
});
|
||||||
return std::make_shared<Index>(lists);
|
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, &reqs, "requires");
|
||||||
parseRequires(obj, &conflicts, "conflicts");
|
parseRequires(obj, &conflicts, "conflicts");
|
||||||
version->setRequires(reqs, conflicts);
|
version->setRequires(reqs, conflicts);
|
||||||
|
if (auto sha256 = ensureString(obj, "sha256", QString()); !sha256.isEmpty()) {
|
||||||
|
version->setSha256(sha256);
|
||||||
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,11 +16,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "meta/BaseEntity.h"
|
|
||||||
|
|
||||||
namespace Meta {
|
namespace Meta {
|
||||||
class Index;
|
class Index;
|
||||||
|
@ -18,12 +18,9 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
#include "JsonFormat.h"
|
#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(const QString& uid, const QString& version) : BaseVersion(), m_uid(uid), m_version(version) {}
|
||||||
|
|
||||||
Meta::Version::~Version() {}
|
|
||||||
|
|
||||||
QString Meta::Version::descriptor()
|
QString Meta::Version::descriptor()
|
||||||
{
|
{
|
||||||
return m_version;
|
return m_version;
|
||||||
@ -71,6 +68,9 @@ void Meta::Version::mergeFromList(const Meta::Version::Ptr& other)
|
|||||||
if (m_volatile != other->m_volatile) {
|
if (m_volatile != other->m_volatile) {
|
||||||
setVolatile(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)
|
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>;
|
using Ptr = std::shared_ptr<Version>;
|
||||||
|
|
||||||
explicit Version(const QString& uid, const QString& version);
|
explicit Version(const QString& uid, const QString& version);
|
||||||
virtual ~Version();
|
virtual ~Version() = default;
|
||||||
|
|
||||||
QString descriptor() override;
|
QString descriptor() override;
|
||||||
QString name() override;
|
QString name() override;
|
||||||
@ -52,7 +52,7 @@ class Version : public QObject, public BaseVersion, public BaseEntity {
|
|||||||
const Meta::RequireSet& requiredSet() const { return m_requires; }
|
const Meta::RequireSet& requiredSet() const { return m_requires; }
|
||||||
VersionFilePtr data() const { return m_data; }
|
VersionFilePtr data() const { return m_data; }
|
||||||
bool isRecommended() const { return m_recommended; }
|
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 merge(const Version::Ptr& other);
|
||||||
void mergeFromList(const Version::Ptr& other);
|
void mergeFromList(const Version::Ptr& other);
|
||||||
|
@ -17,8 +17,13 @@
|
|||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
#include "Index.h"
|
||||||
#include "JsonFormat.h"
|
#include "JsonFormat.h"
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
|
#include "meta/BaseEntity.h"
|
||||||
|
#include "net/Mode.h"
|
||||||
|
#include "tasks/SequentialTask.h"
|
||||||
|
|
||||||
namespace Meta {
|
namespace Meta {
|
||||||
VersionList::VersionList(const QString& uid, QObject* parent) : BaseVersionList(parent), m_uid(uid)
|
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()
|
Task::Ptr VersionList::getLoadTask()
|
||||||
{
|
{
|
||||||
load(Net::Mode::Online);
|
auto loadTask =
|
||||||
return getCurrentTask();
|
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()
|
bool VersionList::isLoaded()
|
||||||
@ -131,6 +139,8 @@ Version::Ptr VersionList::getVersion(const QString& version)
|
|||||||
if (!out) {
|
if (!out) {
|
||||||
out = std::make_shared<Version>(m_uid, version);
|
out = std::make_shared<Version>(m_uid, version);
|
||||||
m_lookup[version] = out;
|
m_lookup[version] = out;
|
||||||
|
setupAddedVersion(m_versions.size(), out);
|
||||||
|
m_versions.append(out);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -191,6 +201,9 @@ void VersionList::mergeFromIndex(const VersionList::Ptr& other)
|
|||||||
if (m_name != other->m_name) {
|
if (m_name != other->m_name) {
|
||||||
setName(other->m_name);
|
setName(other->m_name);
|
||||||
}
|
}
|
||||||
|
if (!other->m_sha256.isEmpty()) {
|
||||||
|
m_sha256 = other->m_sha256;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VersionList::merge(const VersionList::Ptr& other)
|
void VersionList::merge(const VersionList::Ptr& other)
|
||||||
@ -198,23 +211,27 @@ void VersionList::merge(const VersionList::Ptr& other)
|
|||||||
if (m_name != other->m_name) {
|
if (m_name != other->m_name) {
|
||||||
setName(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?
|
// TODO: do not reset the whole model. maybe?
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_versions.clear();
|
|
||||||
if (other->m_versions.isEmpty()) {
|
if (other->m_versions.isEmpty()) {
|
||||||
qWarning() << "Empty list loaded ...";
|
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
|
// we already have the version. merge the contents
|
||||||
if (m_lookup.contains(version->version())) {
|
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 {
|
} 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);
|
m_recommended = getBetterVersion(m_recommended, version);
|
||||||
}
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
@ -222,14 +239,15 @@ void VersionList::merge(const VersionList::Ptr& other)
|
|||||||
|
|
||||||
void VersionList::setupAddedVersion(const int row, const Version::Ptr& version)
|
void VersionList::setupAddedVersion(const int row, const Version::Ptr& version)
|
||||||
{
|
{
|
||||||
// FIXME: do not disconnect from everythin, disconnect only the lambdas here
|
disconnect(version.get(), &Version::requiresChanged, this, nullptr);
|
||||||
version->disconnect();
|
disconnect(version.get(), &Version::timeChanged, this, nullptr);
|
||||||
|
disconnect(version.get(), &Version::typeChanged, this, nullptr);
|
||||||
|
|
||||||
connect(version.get(), &Version::requiresChanged, this,
|
connect(version.get(), &Version::requiresChanged, this,
|
||||||
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << RequiresRole); });
|
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << RequiresRole); });
|
||||||
connect(version.get(), &Version::timeChanged, this,
|
connect(version.get(), &Version::timeChanged, this,
|
||||||
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TimeRole << SortRole); });
|
[this, row]() { emit dataChanged(index(row), index(row), { TimeRole, SortRole }); });
|
||||||
connect(version.get(), &Version::typeChanged, this,
|
connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), { TypeRole }); });
|
||||||
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TypeRole); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseVersion::Ptr VersionList::getRecommended() const
|
BaseVersion::Ptr VersionList::getRecommended() const
|
||||||
@ -237,4 +255,14 @@ BaseVersion::Ptr VersionList::getRecommended() const
|
|||||||
return m_recommended;
|
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
|
} // namespace Meta
|
||||||
|
@ -30,13 +30,14 @@ class VersionList : public BaseVersionList, public BaseEntity {
|
|||||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||||
public:
|
public:
|
||||||
explicit VersionList(const QString& uid, QObject* parent = nullptr);
|
explicit VersionList(const QString& uid, QObject* parent = nullptr);
|
||||||
|
virtual ~VersionList() = default;
|
||||||
|
|
||||||
using Ptr = std::shared_ptr<VersionList>;
|
using Ptr = std::shared_ptr<VersionList>;
|
||||||
|
|
||||||
enum Roles { UidRole = Qt::UserRole + 100, TimeRole, RequiresRole, VersionPtrRole };
|
enum Roles { UidRole = Qt::UserRole + 100, TimeRole, RequiresRole, VersionPtrRole };
|
||||||
|
|
||||||
Task::Ptr getLoadTask() override;
|
|
||||||
bool isLoaded() override;
|
bool isLoaded() override;
|
||||||
|
[[nodiscard]] Task::Ptr getLoadTask() override;
|
||||||
const BaseVersion::Ptr at(int i) const override;
|
const BaseVersion::Ptr at(int i) const override;
|
||||||
int count() const override;
|
int count() const override;
|
||||||
void sortVersions() override;
|
void sortVersions() override;
|
||||||
@ -58,6 +59,9 @@ class VersionList : public BaseVersionList, public BaseEntity {
|
|||||||
|
|
||||||
QVector<Version::Ptr> versions() const { return m_versions; }
|
QVector<Version::Ptr> versions() const { return m_versions; }
|
||||||
|
|
||||||
|
// this blocks until the version list is loaded
|
||||||
|
void waitToLoad();
|
||||||
|
|
||||||
public: // for usage only by parsers
|
public: // for usage only by parsers
|
||||||
void setName(const QString& name);
|
void setName(const QString& name);
|
||||||
void setVersions(const QVector<Version::Ptr>& versions);
|
void setVersions(const QVector<Version::Ptr>& versions);
|
||||||
|
@ -283,8 +283,7 @@ Net::NetRequest::Ptr AssetObject::getDownloadAction()
|
|||||||
if ((!objectFile.isFile()) || (objectFile.size() != size)) {
|
if ((!objectFile.isFile()) || (objectFile.size() != size)) {
|
||||||
auto objectDL = Net::ApiDownload::makeFile(getUrl(), objectFile.filePath());
|
auto objectDL = Net::ApiDownload::makeFile(getUrl(), objectFile.filePath());
|
||||||
if (hash.size()) {
|
if (hash.size()) {
|
||||||
auto rawHash = QByteArray::fromHex(hash.toLatin1());
|
objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, hash));
|
||||||
objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash));
|
|
||||||
}
|
}
|
||||||
objectDL->setProgress(objectDL->getProgress(), size);
|
objectDL->setProgress(objectDL->getProgress(), size);
|
||||||
return objectDL;
|
return objectDL;
|
||||||
|
@ -56,18 +56,6 @@ Component::Component(PackProfile* parent, const QString& uid)
|
|||||||
m_uid = 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)
|
Component::Component(PackProfile* parent, const QString& uid, std::shared_ptr<VersionFile> file)
|
||||||
{
|
{
|
||||||
assert(parent);
|
assert(parent);
|
||||||
@ -102,9 +90,6 @@ void Component::applyTo(LaunchProfile* profile)
|
|||||||
std::shared_ptr<class VersionFile> Component::getVersionFile() const
|
std::shared_ptr<class VersionFile> Component::getVersionFile() const
|
||||||
{
|
{
|
||||||
if (m_metaVersion) {
|
if (m_metaVersion) {
|
||||||
if (!m_metaVersion->isLoaded()) {
|
|
||||||
m_metaVersion->load(Net::Mode::Online);
|
|
||||||
}
|
|
||||||
return m_metaVersion->data();
|
return m_metaVersion->data();
|
||||||
} else {
|
} else {
|
||||||
return m_file;
|
return m_file;
|
||||||
@ -131,29 +116,35 @@ int Component::getOrder()
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Component::setOrder(int order)
|
void Component::setOrder(int order)
|
||||||
{
|
{
|
||||||
m_orderOverride = true;
|
m_orderOverride = true;
|
||||||
m_order = order;
|
m_order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Component::getID()
|
QString Component::getID()
|
||||||
{
|
{
|
||||||
return m_uid;
|
return m_uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Component::getName()
|
QString Component::getName()
|
||||||
{
|
{
|
||||||
if (!m_cachedName.isEmpty())
|
if (!m_cachedName.isEmpty())
|
||||||
return m_cachedName;
|
return m_cachedName;
|
||||||
return m_uid;
|
return m_uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Component::getVersion()
|
QString Component::getVersion()
|
||||||
{
|
{
|
||||||
return m_cachedVersion;
|
return m_cachedVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Component::getFilename()
|
QString Component::getFilename()
|
||||||
{
|
{
|
||||||
return m_parent->patchFilePathForUid(m_uid);
|
return m_parent->patchFilePathForUid(m_uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime Component::getReleaseDateTime()
|
QDateTime Component::getReleaseDateTime()
|
||||||
{
|
{
|
||||||
if (m_metaVersion) {
|
if (m_metaVersion) {
|
||||||
@ -198,17 +189,14 @@ bool Component::isCustom()
|
|||||||
|
|
||||||
bool Component::isCustomizable()
|
bool Component::isCustomizable()
|
||||||
{
|
{
|
||||||
if (m_metaVersion) {
|
return m_metaVersion && getVersionFile();
|
||||||
if (getVersionFile()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Component::isRemovable()
|
bool Component::isRemovable()
|
||||||
{
|
{
|
||||||
return !m_important;
|
return !m_important;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Component::isRevertible()
|
bool Component::isRevertible()
|
||||||
{
|
{
|
||||||
if (isCustom()) {
|
if (isCustom()) {
|
||||||
@ -218,18 +206,18 @@ bool Component::isRevertible()
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Component::isMoveable()
|
bool Component::isMoveable()
|
||||||
{
|
{
|
||||||
// HACK, FIXME: this was too dumb and wouldn't follow dependency constraints anyway. For now hardcoded to 'true'.
|
// HACK, FIXME: this was too dumb and wouldn't follow dependency constraints anyway. For now hardcoded to 'true'.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Component::isVersionChangeable()
|
bool Component::isVersionChangeable()
|
||||||
{
|
{
|
||||||
auto list = getVersionList();
|
auto list = getVersionList();
|
||||||
if (list) {
|
if (list) {
|
||||||
if (!list->isLoaded()) {
|
list->waitToLoad();
|
||||||
list->load(Net::Mode::Online);
|
|
||||||
}
|
|
||||||
return list->count() != 0;
|
return list->count() != 0;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -22,7 +22,6 @@ class Component : public QObject, public ProblemProvider {
|
|||||||
Component(PackProfile* parent, const QString& uid);
|
Component(PackProfile* parent, const QString& uid);
|
||||||
|
|
||||||
// DEPRECATED: remove these constructors?
|
// DEPRECATED: remove these constructors?
|
||||||
Component(PackProfile* parent, std::shared_ptr<Meta::Version> version);
|
|
||||||
Component(PackProfile* parent, const QString& uid, std::shared_ptr<VersionFile> file);
|
Component(PackProfile* parent, const QString& uid, std::shared_ptr<VersionFile> file);
|
||||||
|
|
||||||
virtual ~Component() {}
|
virtual ~Component() {}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "net/Mode.h"
|
#include "net/Mode.h"
|
||||||
|
|
||||||
#include "Application.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
|
* 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;
|
component->m_loaded = true;
|
||||||
result = LoadResult::LoadedLocal;
|
result = LoadResult::LoadedLocal;
|
||||||
} else {
|
} else {
|
||||||
metaVersion->load(netmode);
|
loadTask = APPLICATION->metadataIndex()->loadVersion(component->m_uid, component->m_version, netmode);
|
||||||
loadTask = metaVersion->getCurrentTask();
|
loadTask->start();
|
||||||
if (loadTask)
|
if (netmode == Net::Mode::Online)
|
||||||
result = LoadResult::RequiresRemote;
|
result = LoadResult::RequiresRemote;
|
||||||
else if (metaVersion->isLoaded())
|
else if (metaVersion->isLoaded())
|
||||||
result = LoadResult::LoadedLocal;
|
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
|
} // namespace
|
||||||
|
|
||||||
void ComponentUpdateTask::loadComponents()
|
void ComponentUpdateTask::loadComponents()
|
||||||
@ -156,23 +142,7 @@ void ComponentUpdateTask::loadComponents()
|
|||||||
size_t taskIndex = 0;
|
size_t taskIndex = 0;
|
||||||
size_t componentIndex = 0;
|
size_t componentIndex = 0;
|
||||||
d->remoteLoadSuccessful = true;
|
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...
|
// load all the components OR their lists...
|
||||||
for (auto component : d->m_list->d->components) {
|
for (auto component : d->m_list->d->components) {
|
||||||
Task::Ptr loadTask;
|
Task::Ptr loadTask;
|
||||||
@ -206,12 +176,13 @@ void ComponentUpdateTask::loadComponents()
|
|||||||
result = composeLoadResult(result, singleResult);
|
result = composeLoadResult(result, singleResult);
|
||||||
if (loadTask) {
|
if (loadTask) {
|
||||||
qDebug() << "Remote loading is being run for" << component->getName();
|
qDebug() << "Remote loading is being run for" << component->getName();
|
||||||
connect(loadTask.get(), &Task::succeeded, [=]() { remoteLoadSucceeded(taskIndex); });
|
connect(loadTask.get(), &Task::succeeded, this, [this, taskIndex]() { remoteLoadSucceeded(taskIndex); });
|
||||||
connect(loadTask.get(), &Task::failed, [=](const QString& error) { remoteLoadFailed(taskIndex, error); });
|
connect(loadTask.get(), &Task::failed, this, [this, taskIndex](const QString& error) { remoteLoadFailed(taskIndex, error); });
|
||||||
connect(loadTask.get(), &Task::aborted, [=]() { remoteLoadFailed(taskIndex, tr("Aborted")); });
|
connect(loadTask.get(), &Task::aborted, this, [this, taskIndex]() { remoteLoadFailed(taskIndex, tr("Aborted")); });
|
||||||
RemoteLoadStatus status;
|
RemoteLoadStatus status;
|
||||||
status.type = loadType;
|
status.type = loadType;
|
||||||
status.PackProfileIndex = componentIndex;
|
status.PackProfileIndex = componentIndex;
|
||||||
|
status.task = loadTask;
|
||||||
d->remoteLoadStatusList.append(status);
|
d->remoteLoadStatusList.append(status);
|
||||||
taskIndex++;
|
taskIndex++;
|
||||||
}
|
}
|
||||||
@ -518,7 +489,14 @@ void ComponentUpdateTask::resolveDependencies(bool checkOnly)
|
|||||||
|
|
||||||
void ComponentUpdateTask::remoteLoadSucceeded(size_t taskIndex)
|
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];
|
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) {
|
if (taskSlot.finished) {
|
||||||
qWarning() << "Got multiple results from remote load task" << taskIndex;
|
qWarning() << "Got multiple results from remote load task" << taskIndex;
|
||||||
return;
|
return;
|
||||||
@ -538,7 +516,14 @@ void ComponentUpdateTask::remoteLoadSucceeded(size_t taskIndex)
|
|||||||
|
|
||||||
void ComponentUpdateTask::remoteLoadFailed(size_t taskIndex, const QString& msg)
|
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];
|
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) {
|
if (taskSlot.finished) {
|
||||||
qWarning() << "Got multiple results from remote load task" << taskIndex;
|
qWarning() << "Got multiple results from remote load task" << taskIndex;
|
||||||
return;
|
return;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include "net/Mode.h"
|
#include "net/Mode.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
class PackProfile;
|
class PackProfile;
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ struct RemoteLoadStatus {
|
|||||||
bool finished = false;
|
bool finished = false;
|
||||||
bool succeeded = false;
|
bool succeeded = false;
|
||||||
QString error;
|
QString error;
|
||||||
|
Task::Ptr task;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ComponentUpdateTaskData {
|
struct ComponentUpdateTaskData {
|
||||||
|
@ -147,9 +147,8 @@ QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeC
|
|||||||
options |= Net::Download::Option::MakeEternal;
|
options |= Net::Download::Option::MakeEternal;
|
||||||
|
|
||||||
if (sha1.size()) {
|
if (sha1.size()) {
|
||||||
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
|
|
||||||
auto dl = Net::ApiDownload::makeCached(url, entry, options);
|
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;
|
qDebug() << "Checksummed Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
|
||||||
out.append(dl);
|
out.append(dl);
|
||||||
} else {
|
} else {
|
||||||
|
@ -32,8 +32,7 @@ void AssetUpdateTask::executeTask()
|
|||||||
auto hexSha1 = assets->sha1.toLatin1();
|
auto hexSha1 = assets->sha1.toLatin1();
|
||||||
qDebug() << "Asset index SHA1:" << hexSha1;
|
qDebug() << "Asset index SHA1:" << hexSha1;
|
||||||
auto dl = Net::ApiDownload::makeCached(indexUrl, entry);
|
auto dl = Net::ApiDownload::makeCached(indexUrl, entry);
|
||||||
auto rawSha1 = QByteArray::fromHex(assets->sha1.toLatin1());
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, assets->sha1));
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
|
||||||
job->addNetAction(dl);
|
job->addNetAction(dl);
|
||||||
|
|
||||||
downloadJob.reset(job);
|
downloadJob.reset(job);
|
||||||
|
@ -343,9 +343,7 @@ QString PackInstallTask::getVersionForLoader(QString uid)
|
|||||||
return Q_NULLPTR;
|
return Q_NULLPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vlist->isLoaded()) {
|
vlist->waitToLoad();
|
||||||
vlist->load(Net::Mode::Online);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_version.loader.recommended || m_version.loader.latest) {
|
if (m_version.loader.recommended || m_version.loader.latest) {
|
||||||
for (int i = 0; i < vlist->versions().size(); i++) {
|
for (int i = 0; i < vlist->versions().size(); i++) {
|
||||||
@ -638,8 +636,7 @@ void PackInstallTask::installConfigs()
|
|||||||
|
|
||||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||||
if (!m_version.configs.sha1.isEmpty()) {
|
if (!m_version.configs.sha1.isEmpty()) {
|
||||||
auto rawSha1 = QByteArray::fromHex(m_version.configs.sha1.toLatin1());
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, m_version.configs.sha1));
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
|
||||||
}
|
}
|
||||||
jobPtr->addNetAction(dl);
|
jobPtr->addNetAction(dl);
|
||||||
archivePath = entry->getFullPath();
|
archivePath = entry->getFullPath();
|
||||||
@ -758,8 +755,7 @@ void PackInstallTask::downloadMods()
|
|||||||
|
|
||||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||||
if (!mod.md5.isEmpty()) {
|
if (!mod.md5.isEmpty()) {
|
||||||
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, mod.md5));
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
|
|
||||||
}
|
}
|
||||||
jobPtr->addNetAction(dl);
|
jobPtr->addNetAction(dl);
|
||||||
} else if (mod.type == ModType::Decomp) {
|
} else if (mod.type == ModType::Decomp) {
|
||||||
@ -769,8 +765,7 @@ void PackInstallTask::downloadMods()
|
|||||||
|
|
||||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||||
if (!mod.md5.isEmpty()) {
|
if (!mod.md5.isEmpty()) {
|
||||||
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, mod.md5));
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
|
|
||||||
}
|
}
|
||||||
jobPtr->addNetAction(dl);
|
jobPtr->addNetAction(dl);
|
||||||
} else {
|
} else {
|
||||||
@ -783,8 +778,7 @@ void PackInstallTask::downloadMods()
|
|||||||
|
|
||||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||||
if (!mod.md5.isEmpty()) {
|
if (!mod.md5.isEmpty()) {
|
||||||
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, mod.md5));
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
|
|
||||||
}
|
}
|
||||||
jobPtr->addNetAction(dl);
|
jobPtr->addNetAction(dl);
|
||||||
|
|
||||||
@ -1075,36 +1069,7 @@ void PackInstallTask::install()
|
|||||||
|
|
||||||
static Meta::Version::Ptr getComponentVersion(const QString& uid, const QString& version)
|
static Meta::Version::Ptr getComponentVersion(const QString& uid, const QString& version)
|
||||||
{
|
{
|
||||||
auto vlist = APPLICATION->metadataIndex()->get(uid);
|
return APPLICATION->metadataIndex()->getLoadedVersion(uid, version);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ATLauncher
|
} // namespace ATLauncher
|
||||||
|
@ -246,7 +246,7 @@ void FlamePackExportTask::makeApiRequest()
|
|||||||
pendingHashes.clear();
|
pendingHashes.clear();
|
||||||
getProjectsInfo();
|
getProjectsInfo();
|
||||||
});
|
});
|
||||||
connect(task.get(), &NetJob::failed, this, &FlamePackExportTask::getProjectsInfo);
|
connect(task.get(), &Task::failed, this, &FlamePackExportTask::getProjectsInfo);
|
||||||
task->start();
|
task->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "ModrinthPackExportTask.h"
|
#include "ModrinthPackExportTask.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -28,6 +29,7 @@
|
|||||||
#include "minecraft/mod/MetadataHandler.h"
|
#include "minecraft/mod/MetadataHandler.h"
|
||||||
#include "minecraft/mod/ModFolderModel.h"
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
#include "modplatform/helpers/HashUtils.h"
|
#include "modplatform/helpers/HashUtils.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
const QStringList ModrinthPackExportTask::PREFIXES({ "mods/", "coremods/", "resourcepacks/", "texturepacks/", "shaderpacks/" });
|
const QStringList ModrinthPackExportTask::PREFIXES({ "mods/", "coremods/", "resourcepacks/", "texturepacks/", "shaderpacks/" });
|
||||||
const QStringList ModrinthPackExportTask::FILE_EXTENSIONS({ "jar", "litemod", "zip" });
|
const QStringList ModrinthPackExportTask::FILE_EXTENSIONS({ "jar", "litemod", "zip" });
|
||||||
@ -154,8 +156,8 @@ void ModrinthPackExportTask::makeApiRequest()
|
|||||||
setStatus(tr("Finding versions for hashes..."));
|
setStatus(tr("Finding versions for hashes..."));
|
||||||
auto response = std::make_shared<QByteArray>();
|
auto response = std::make_shared<QByteArray>();
|
||||||
task = api.currentVersions(pendingHashes.values(), "sha512", response);
|
task = api.currentVersions(pendingHashes.values(), "sha512", response);
|
||||||
connect(task.get(), &NetJob::succeeded, [this, response]() { parseApiResponse(response); });
|
connect(task.get(), &Task::succeeded, [this, response]() { parseApiResponse(response); });
|
||||||
connect(task.get(), &NetJob::failed, this, &ModrinthPackExportTask::emitFailed);
|
connect(task.get(), &Task::failed, this, &ModrinthPackExportTask::emitFailed);
|
||||||
task->start();
|
task->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,8 +114,7 @@ void Technic::SolderPackInstallTask::fileListSucceeded()
|
|||||||
|
|
||||||
auto dl = Net::ApiDownload::makeFile(mod.url, path);
|
auto dl = Net::ApiDownload::makeFile(mod.url, path);
|
||||||
if (!mod.md5.isEmpty()) {
|
if (!mod.md5.isEmpty()) {
|
||||||
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, mod.md5));
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
|
|
||||||
}
|
}
|
||||||
m_filesNetJob->addNetAction(dl);
|
m_filesNetJob->addNetAction(dl);
|
||||||
|
|
||||||
|
@ -43,6 +43,9 @@
|
|||||||
namespace Net {
|
namespace Net {
|
||||||
class ChecksumValidator : public Validator {
|
class ChecksumValidator : public Validator {
|
||||||
public:
|
public:
|
||||||
|
ChecksumValidator(QCryptographicHash::Algorithm algorithm, QString expectedHex)
|
||||||
|
: Net::ChecksumValidator(algorithm, QByteArray::fromHex(expectedHex.toLatin1()))
|
||||||
|
{}
|
||||||
ChecksumValidator(QCryptographicHash::Algorithm algorithm, QByteArray expected = QByteArray())
|
ChecksumValidator(QCryptographicHash::Algorithm algorithm, QByteArray expected = QByteArray())
|
||||||
: m_checksum(algorithm), m_expected(expected) {};
|
: m_checksum(algorithm), m_expected(expected) {};
|
||||||
virtual ~ChecksumValidator() = default;
|
virtual ~ChecksumValidator() = default;
|
||||||
|
@ -592,8 +592,7 @@ void TranslationsModel::downloadTranslation(QString key)
|
|||||||
entry->setStale(true);
|
entry->setStale(true);
|
||||||
|
|
||||||
auto dl = Net::Download::makeCached(QUrl(BuildConfig.TRANSLATIONS_BASE_URL + lang->file_name), entry);
|
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, lang->file_sha1));
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash));
|
|
||||||
dl->setProgress(dl->getProgress(), lang->file_size);
|
dl->setProgress(dl->getProgress(), lang->file_size);
|
||||||
|
|
||||||
d->m_dl_job.reset(new NetJob("Translation for " + key, APPLICATION->network()));
|
d->m_dl_job.reset(new NetJob("Translation for " + key, APPLICATION->network()));
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "minecraft/PackProfile.h"
|
#include "minecraft/PackProfile.h"
|
||||||
|
@ -17,9 +17,9 @@ TexturePackResourceModel::TexturePackResourceModel(BaseInstance const& inst, Res
|
|||||||
{
|
{
|
||||||
if (!m_version_list->isLoaded()) {
|
if (!m_version_list->isLoaded()) {
|
||||||
qDebug() << "Loading version list...";
|
qDebug() << "Loading version list...";
|
||||||
auto task = m_version_list->getLoadTask();
|
m_task = m_version_list->getLoadTask();
|
||||||
if (!task->isRunning())
|
if (!m_task->isRunning())
|
||||||
task->start();
|
m_task->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,8 @@ void waitOnVersionListLoad(Meta::VersionList::Ptr version_list)
|
|||||||
|
|
||||||
auto task = version_list->getLoadTask();
|
auto task = version_list->getLoadTask();
|
||||||
QObject::connect(task.get(), &Task::finished, &load_version_list_loop, &QEventLoop::quit);
|
QObject::connect(task.get(), &Task::finished, &load_version_list_loop, &QEventLoop::quit);
|
||||||
|
if (!task->isRunning())
|
||||||
|
task->start();
|
||||||
load_version_list_loop.exec();
|
load_version_list_loop.exec();
|
||||||
if (time_limit_for_list_load.isActive())
|
if (time_limit_for_list_load.isActive())
|
||||||
time_limit_for_list_load.stop();
|
time_limit_for_list_load.stop();
|
||||||
|
@ -22,6 +22,7 @@ class TexturePackResourceModel : public ResourcePackResourceModel {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
Meta::VersionList::Ptr m_version_list;
|
Meta::VersionList::Ptr m_version_list;
|
||||||
|
Task::Ptr m_task;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ResourceDownload
|
} // namespace ResourceDownload
|
||||||
|
@ -129,16 +129,12 @@ void VersionSelectWidget::closeEvent(QCloseEvent* event)
|
|||||||
|
|
||||||
void VersionSelectWidget::loadList()
|
void VersionSelectWidget::loadList()
|
||||||
{
|
{
|
||||||
auto newTask = m_vlist->getLoadTask();
|
m_load_task = m_vlist->getLoadTask();
|
||||||
if (!newTask) {
|
connect(m_load_task.get(), &Task::succeeded, this, &VersionSelectWidget::onTaskSucceeded);
|
||||||
return;
|
connect(m_load_task.get(), &Task::failed, this, &VersionSelectWidget::onTaskFailed);
|
||||||
}
|
connect(m_load_task.get(), &Task::progress, this, &VersionSelectWidget::changeProgress);
|
||||||
loadTask = newTask.get();
|
if (!m_load_task->isRunning()) {
|
||||||
connect(loadTask, &Task::succeeded, this, &VersionSelectWidget::onTaskSucceeded);
|
m_load_task->start();
|
||||||
connect(loadTask, &Task::failed, this, &VersionSelectWidget::onTaskFailed);
|
|
||||||
connect(loadTask, &Task::progress, this, &VersionSelectWidget::changeProgress);
|
|
||||||
if (!loadTask->isRunning()) {
|
|
||||||
loadTask->start();
|
|
||||||
}
|
}
|
||||||
sneakyProgressBar->setHidden(false);
|
sneakyProgressBar->setHidden(false);
|
||||||
}
|
}
|
||||||
@ -150,7 +146,7 @@ void VersionSelectWidget::onTaskSucceeded()
|
|||||||
}
|
}
|
||||||
sneakyProgressBar->setHidden(true);
|
sneakyProgressBar->setHidden(true);
|
||||||
preselect();
|
preselect();
|
||||||
loadTask = nullptr;
|
m_load_task.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VersionSelectWidget::onTaskFailed(const QString& reason)
|
void VersionSelectWidget::onTaskFailed(const QString& reason)
|
||||||
|
@ -98,7 +98,7 @@ class VersionSelectWidget : public QWidget {
|
|||||||
BaseVersionList* m_vlist = nullptr;
|
BaseVersionList* m_vlist = nullptr;
|
||||||
VersionProxyModel* m_proxyModel = nullptr;
|
VersionProxyModel* m_proxyModel = nullptr;
|
||||||
int resizeOnColumn = 0;
|
int resizeOnColumn = 0;
|
||||||
Task* loadTask;
|
Task::Ptr m_load_task;
|
||||||
bool preselectedAlready = false;
|
bool preselectedAlready = false;
|
||||||
|
|
||||||
QVBoxLayout* verticalLayout = nullptr;
|
QVBoxLayout* verticalLayout = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user