fix: use more robust method of finding matches for major version

This uses the proper version list to find all MC versions matching the
major number (_don't say anything about SemVer_ 🔫).

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-07-30 17:38:02 -03:00
parent 1b0ca47682
commit 8a65726e9d
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
4 changed files with 45 additions and 4 deletions

View File

@ -140,6 +140,13 @@ VersionPtr VersionList::getVersion(const QString &version)
return out;
}
bool VersionList::hasVersion(QString version) const
{
auto ver = std::find_if(m_versions.constBegin(), m_versions.constEnd(),
[&](Meta::VersionPtr const& a){ return a->version() == version; });
return (ver != m_versions.constEnd());
}
void VersionList::setName(const QString &name)
{
m_name = name;

View File

@ -66,6 +66,7 @@ public:
QString humanReadable() const;
VersionPtr getVersion(const QString &version);
bool hasVersion(QString version) const;
QVector<VersionPtr> versions() const
{

View File

@ -1,6 +1,8 @@
#include "ModFilterWidget.h"
#include "ui_ModFilterWidget.h"
#include "Application.h"
ModFilterWidget::ModFilterWidget(Version def, QWidget* parent)
: QTabWidget(parent), m_filter(new Filter()), ui(new Ui::ModFilterWidget)
{
@ -16,6 +18,24 @@ ModFilterWidget::ModFilterWidget(Version def, QWidget* parent)
m_filter->versions.push_front(def);
m_version_list = APPLICATION->metadataIndex()->get("net.minecraft");
if (!m_version_list->isLoaded()) {
QEventLoop load_version_list_loop;
auto task = m_version_list->getLoadTask();
connect(task.get(), &Task::failed, [this]{
ui->majorVersionButton->setText(tr("Major version match (failed to get version index)"));
disableVersionButton(VersionButtonID::Major);
});
connect(task.get(), &Task::finished, &load_version_list_loop, &QEventLoop::quit);
if (!task->isRunning())
task->start();
load_version_list_loop.exec();
}
setHidden(true);
}
@ -76,7 +96,7 @@ void ModFilterWidget::onVersionFilterChanged(int id)
//ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between);
//ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between);
int index = 0;
int index = 1;
auto cast_id = (VersionButtonID) id;
if (cast_id != m_version_id) {
@ -93,10 +113,15 @@ void ModFilterWidget::onVersionFilterChanged(int id)
break;
case(VersionButtonID::Major): {
auto versionSplit = mcVersionStr().split(".");
for(auto i = Version(QString("%1.%2").arg(versionSplit[0], versionSplit[1])); i <= mcVersion(); index++){
m_filter->versions.push_front(i);
i = Version(QString("%1.%2.%3").arg(versionSplit[0], versionSplit[1], QString("%1").arg(index)));
auto major_version = QString("%1.%2").arg(versionSplit[0], versionSplit[1]);
QString version_str = major_version;
while (m_version_list->hasVersion(version_str)) {
m_filter->versions.emplace_back(version_str);
version_str = QString("%1.%2").arg(major_version, QString::number(index++));
}
break;
}
case(VersionButtonID::All):

View File

@ -4,6 +4,10 @@
#include <QButtonGroup>
#include "Version.h"
#include "meta/Index.h"
#include "meta/VersionList.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
@ -61,8 +65,12 @@ private:
MinecraftInstance* m_instance = nullptr;
/* Version stuff */
QButtonGroup m_mcVersion_buttons;
Meta::VersionListPtr m_version_list;
/* Used to tell if the filter was changed since the last getFilter() call */
VersionButtonID m_last_version_id = VersionButtonID::Strict;
VersionButtonID m_version_id = VersionButtonID::Strict;