mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
fix: force metadata version list refreshes to reload
manual refreshes on version selection screens could reuse cached metadata and skip downloading updated manifests, so new versions would not appear until Prism was restarted. pass an explicit forced reload through the shared version list loading path and use it from refresh actions so manual refresh always reloads metadata Signed-off-by: morsz <morsz@morsz.dev>
This commit is contained in:
parent
013bb5cac3
commit
2219c37d7f
15 changed files with 34 additions and 25 deletions
|
|
@ -63,7 +63,7 @@ class BaseVersionList : public QAbstractListModel {
|
||||||
* The task returned by this function should reset the model when it's done.
|
* The task returned by this function should reset the model when it's done.
|
||||||
* \return A pointer to a task that reloads the version list.
|
* \return A pointer to a task that reloads the version list.
|
||||||
*/
|
*/
|
||||||
virtual Task::Ptr getLoadTask() = 0;
|
virtual Task::Ptr getLoadTask(bool forceReload = false) = 0;
|
||||||
|
|
||||||
//! Checks whether or not the list is loaded. If this returns false, the list should be
|
//! Checks whether or not the list is loaded. If this returns false, the list should be
|
||||||
// loaded.
|
// loaded.
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,9 @@ JavaInstallList::JavaInstallList(QObject* parent, bool onlyManagedVersions)
|
||||||
: BaseVersionList(parent), m_only_managed_versions(onlyManagedVersions)
|
: BaseVersionList(parent), m_only_managed_versions(onlyManagedVersions)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Task::Ptr JavaInstallList::getLoadTask()
|
Task::Ptr JavaInstallList::getLoadTask(bool forceReload)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(forceReload)
|
||||||
load();
|
load();
|
||||||
return getCurrentTask();
|
return getCurrentTask();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class JavaInstallList : public BaseVersionList {
|
||||||
public:
|
public:
|
||||||
explicit JavaInstallList(QObject* parent = 0, bool onlyManagedVersions = false);
|
explicit JavaInstallList(QObject* parent = 0, bool onlyManagedVersions = false);
|
||||||
|
|
||||||
Task::Ptr getLoadTask() override;
|
Task::Ptr getLoadTask(bool forceReload = false) 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;
|
||||||
|
|
|
||||||
|
|
@ -82,12 +82,12 @@ QUrl BaseEntity::url() const
|
||||||
return QUrl(metaOverride).resolved(localFilename());
|
return QUrl(metaOverride).resolved(localFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::Ptr BaseEntity::loadTask(Net::Mode mode)
|
Task::Ptr BaseEntity::loadTask(Net::Mode mode, bool forceReload)
|
||||||
{
|
{
|
||||||
if (m_task && m_task->isRunning()) {
|
if (m_task && m_task->isRunning()) {
|
||||||
return m_task;
|
return m_task;
|
||||||
}
|
}
|
||||||
m_task.reset(new BaseEntityLoadTask(this, mode));
|
m_task.reset(new BaseEntityLoadTask(this, mode, forceReload));
|
||||||
return m_task;
|
return m_task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +107,9 @@ BaseEntity::LoadStatus BaseEntity::status() const
|
||||||
return m_load_status;
|
return m_load_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseEntityLoadTask::BaseEntityLoadTask(BaseEntity* parent, Net::Mode mode) : m_entity(parent), m_mode(mode) {}
|
BaseEntityLoadTask::BaseEntityLoadTask(BaseEntity* parent, Net::Mode mode, bool forceReload)
|
||||||
|
: m_entity(parent), m_mode(mode), m_force_reload(forceReload)
|
||||||
|
{}
|
||||||
|
|
||||||
void BaseEntityLoadTask::executeTask()
|
void BaseEntityLoadTask::executeTask()
|
||||||
{
|
{
|
||||||
|
|
@ -149,13 +151,18 @@ void BaseEntityLoadTask::executeTask()
|
||||||
auto wasLoadedOffline = m_entity->m_load_status != BaseEntity::LoadStatus::NotLoaded && m_mode == Net::Mode::Offline;
|
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
|
// 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;
|
auto wasLoadedRemote = m_entity->m_sha256.isEmpty() ? m_entity->m_load_status == BaseEntity::LoadStatus::Remote : hashMatches;
|
||||||
if (wasLoadedOffline || wasLoadedRemote) {
|
if (wasLoadedOffline || (wasLoadedRemote && !m_force_reload)) {
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_task.reset(new NetJob(QObject::tr("Download of meta file %1").arg(m_entity->localFilename()), APPLICATION->network()));
|
m_task.reset(new NetJob(QObject::tr("Download of meta file %1").arg(m_entity->localFilename()), APPLICATION->network()));
|
||||||
auto url = m_entity->url();
|
auto url = m_entity->url();
|
||||||
auto entry = APPLICATION->metacache()->resolveEntry("meta", m_entity->localFilename());
|
auto entry = APPLICATION->metacache()->resolveEntry("meta", m_entity->localFilename());
|
||||||
|
if (m_force_reload) {
|
||||||
|
// clear validators so manual refreshes fetch a fresh body
|
||||||
|
entry->setETag({});
|
||||||
|
entry->setRemoteChangedTimestamp({});
|
||||||
|
}
|
||||||
entry->setStale(true);
|
entry->setStale(true);
|
||||||
auto dl = Net::ApiDownload::makeCached(url, entry);
|
auto dl = Net::ApiDownload::makeCached(url, entry);
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class BaseEntity {
|
||||||
void setSha256(QString sha256);
|
void setSha256(QString sha256);
|
||||||
|
|
||||||
virtual void parse(const QJsonObject& obj) = 0;
|
virtual void parse(const QJsonObject& obj) = 0;
|
||||||
[[nodiscard]] Task::Ptr loadTask(Net::Mode loadType = Net::Mode::Online);
|
[[nodiscard]] Task::Ptr loadTask(Net::Mode loadType = Net::Mode::Online, bool forceReload = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_sha256; // the expected sha256
|
QString m_sha256; // the expected sha256
|
||||||
|
|
@ -58,7 +58,7 @@ class BaseEntityLoadTask : public Task {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit BaseEntityLoadTask(BaseEntity* parent, Net::Mode mode);
|
explicit BaseEntityLoadTask(BaseEntity* parent, Net::Mode mode, bool forceReload);
|
||||||
~BaseEntityLoadTask() override = default;
|
~BaseEntityLoadTask() override = default;
|
||||||
|
|
||||||
virtual void executeTask() override;
|
virtual void executeTask() override;
|
||||||
|
|
@ -68,6 +68,7 @@ class BaseEntityLoadTask : public Task {
|
||||||
private:
|
private:
|
||||||
BaseEntity* m_entity;
|
BaseEntity* m_entity;
|
||||||
Net::Mode m_mode;
|
Net::Mode m_mode;
|
||||||
|
bool m_force_reload = false;
|
||||||
NetJob::Ptr m_task;
|
NetJob::Ptr m_task;
|
||||||
};
|
};
|
||||||
} // namespace Meta
|
} // namespace Meta
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,11 @@ VersionList::VersionList(const QString& uid, QObject* parent) : BaseVersionList(
|
||||||
setObjectName("Version list: " + uid);
|
setObjectName("Version list: " + uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::Ptr VersionList::getLoadTask()
|
Task::Ptr VersionList::getLoadTask(bool forceReload)
|
||||||
{
|
{
|
||||||
auto loadTask = makeShared<SequentialTask>(tr("Load meta for %1", "This is for the task name that loads the meta index.").arg(m_uid));
|
auto loadTask = makeShared<SequentialTask>(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(APPLICATION->metadataIndex()->loadTask(Net::Mode::Online, forceReload));
|
||||||
loadTask->addTask(this->loadTask(Net::Mode::Online));
|
loadTask->addTask(this->loadTask(Net::Mode::Online, forceReload));
|
||||||
return loadTask;
|
return loadTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class VersionList : public BaseVersionList, public BaseEntity {
|
||||||
enum Roles { UidRole = Qt::UserRole + 100, TimeRole, RequiresRole, VersionPtrRole };
|
enum Roles { UidRole = Qt::UserRole + 100, TimeRole, RequiresRole, VersionPtrRole };
|
||||||
|
|
||||||
bool isLoaded() override;
|
bool isLoaded() override;
|
||||||
Task::Ptr getLoadTask() override;
|
Task::Ptr getLoadTask(bool forceReload = false) 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;
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ InstallLoaderDialog::InstallLoaderDialog(PackProfile* profile, const QString& ui
|
||||||
buttonLayout->setContentsMargins(0, 0, 6, 6);
|
buttonLayout->setContentsMargins(0, 0, 6, 6);
|
||||||
#endif
|
#endif
|
||||||
auto refreshButton = new QPushButton(tr("&Refresh"), this);
|
auto refreshButton = new QPushButton(tr("&Refresh"), this);
|
||||||
connect(refreshButton, &QPushButton::clicked, this, [this] { pageCast(container->selectedPage())->loadList(); });
|
connect(refreshButton, &QPushButton::clicked, this, [this] { pageCast(container->selectedPage())->loadList(true); });
|
||||||
buttonLayout->addWidget(refreshButton);
|
buttonLayout->addWidget(refreshButton);
|
||||||
|
|
||||||
buttons->setOrientation(Qt::Horizontal);
|
buttons->setOrientation(Qt::Horizontal);
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ BaseVersion::Ptr VersionSelectDialog::selectedVersion() const
|
||||||
|
|
||||||
void VersionSelectDialog::on_refreshButton_clicked()
|
void VersionSelectDialog::on_refreshButton_clicked()
|
||||||
{
|
{
|
||||||
m_versionWidget->loadList();
|
m_versionWidget->loadList(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VersionSelectDialog::setExactFilter(BaseVersionList::ModelRoles role, QString filter)
|
void VersionSelectDialog::setExactFilter(BaseVersionList::ModelRoles role, QString filter)
|
||||||
|
|
|
||||||
|
|
@ -121,8 +121,8 @@ class InstallJavaPage : public QWidget, public BasePage {
|
||||||
void selectSearch() { javaVersionSelect->selectSearch(); }
|
void selectSearch() { javaVersionSelect->selectSearch(); }
|
||||||
void loadList()
|
void loadList()
|
||||||
{
|
{
|
||||||
majorVersionSelect->loadList();
|
majorVersionSelect->loadList(true);
|
||||||
javaVersionSelect->loadList();
|
javaVersionSelect->loadList(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ VersionList::VersionList(Meta::Version::Ptr version, QObject* parent) : BaseVers
|
||||||
sortVersions();
|
sortVersions();
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::Ptr VersionList::getLoadTask()
|
Task::Ptr VersionList::getLoadTask(bool forceReload)
|
||||||
{
|
{
|
||||||
auto task = m_version->loadTask(Net::Mode::Online);
|
auto task = m_version->loadTask(Net::Mode::Online, forceReload);
|
||||||
connect(task.get(), &Task::finished, this, &VersionList::sortVersions);
|
connect(task.get(), &Task::finished, this, &VersionList::sortVersions);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class VersionList : public BaseVersionList {
|
||||||
public:
|
public:
|
||||||
explicit VersionList(Meta::Version::Ptr m_version, QObject* parent = 0);
|
explicit VersionList(Meta::Version::Ptr m_version, QObject* parent = 0);
|
||||||
|
|
||||||
Task::Ptr getLoadTask() override;
|
Task::Ptr getLoadTask(bool forceReload = false) 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;
|
||||||
|
|
|
||||||
|
|
@ -80,14 +80,14 @@ void CustomPage::openedImpl()
|
||||||
|
|
||||||
void CustomPage::refresh()
|
void CustomPage::refresh()
|
||||||
{
|
{
|
||||||
ui->versionList->loadList();
|
ui->versionList->loadList(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPage::loaderRefresh()
|
void CustomPage::loaderRefresh()
|
||||||
{
|
{
|
||||||
if (ui->noneFilter->isChecked())
|
if (ui->noneFilter->isChecked())
|
||||||
return;
|
return;
|
||||||
ui->loaderVersionList->loadList();
|
ui->loaderVersionList->loadList(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPage::filterChanged()
|
void CustomPage::filterChanged()
|
||||||
|
|
|
||||||
|
|
@ -127,9 +127,9 @@ void VersionSelectWidget::closeEvent(QCloseEvent* event)
|
||||||
QWidget::closeEvent(event);
|
QWidget::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VersionSelectWidget::loadList()
|
void VersionSelectWidget::loadList(bool forceReload)
|
||||||
{
|
{
|
||||||
m_load_task = m_vlist->getLoadTask();
|
m_load_task = m_vlist->getLoadTask(forceReload);
|
||||||
connect(m_load_task.get(), &Task::succeeded, this, &VersionSelectWidget::onTaskSucceeded);
|
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::failed, this, &VersionSelectWidget::onTaskFailed);
|
||||||
connect(m_load_task.get(), &Task::progress, this, &VersionSelectWidget::changeProgress);
|
connect(m_load_task.get(), &Task::progress, this, &VersionSelectWidget::changeProgress);
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class VersionSelectWidget : public QWidget {
|
||||||
void initialize(BaseVersionList* vlist, bool forceLoad = false);
|
void initialize(BaseVersionList* vlist, bool forceLoad = false);
|
||||||
|
|
||||||
//! Starts a task that loads the list.
|
//! Starts a task that loads the list.
|
||||||
void loadList();
|
void loadList(bool forceReload = false);
|
||||||
|
|
||||||
bool hasVersions() const;
|
bool hasVersions() const;
|
||||||
BaseVersion::Ptr selectedVersion() const;
|
BaseVersion::Ptr selectedVersion() const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue