aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-07-30 17:38:02 -0300
committerflow <flowlnlnln@gmail.com>2022-09-07 08:27:53 -0300
commit8a65726e9dbe990a898a49d4ce05d61ad5b06852 (patch)
tree3cfc332dcb81ed2722ad242165902b3782cea4ae
parent1b0ca476824ad3d704de70720184d2f1e194d2f5 (diff)
downloadPrismLauncher-8a65726e9dbe990a898a49d4ce05d61ad5b06852.tar.gz
PrismLauncher-8a65726e9dbe990a898a49d4ce05d61ad5b06852.tar.bz2
PrismLauncher-8a65726e9dbe990a898a49d4ce05d61ad5b06852.zip
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_ :gun:). Signed-off-by: flow <flowlnlnln@gmail.com>
-rw-r--r--launcher/meta/VersionList.cpp7
-rw-r--r--launcher/meta/VersionList.h1
-rw-r--r--launcher/ui/widgets/ModFilterWidget.cpp33
-rw-r--r--launcher/ui/widgets/ModFilterWidget.h8
4 files changed, 45 insertions, 4 deletions
diff --git a/launcher/meta/VersionList.cpp b/launcher/meta/VersionList.cpp
index 6d23ce9a..f609e94c 100644
--- a/launcher/meta/VersionList.cpp
+++ b/launcher/meta/VersionList.cpp
@@ -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;
diff --git a/launcher/meta/VersionList.h b/launcher/meta/VersionList.h
index 378255df..a6db2fd7 100644
--- a/launcher/meta/VersionList.h
+++ b/launcher/meta/VersionList.h
@@ -66,6 +66,7 @@ public:
QString humanReadable() const;
VersionPtr getVersion(const QString &version);
+ bool hasVersion(QString version) const;
QVector<VersionPtr> versions() const
{
diff --git a/launcher/ui/widgets/ModFilterWidget.cpp b/launcher/ui/widgets/ModFilterWidget.cpp
index 4ab34375..a4010aee 100644
--- a/launcher/ui/widgets/ModFilterWidget.cpp
+++ b/launcher/ui/widgets/ModFilterWidget.cpp
@@ -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):
diff --git a/launcher/ui/widgets/ModFilterWidget.h b/launcher/ui/widgets/ModFilterWidget.h
index 334fc672..cf429174 100644
--- a/launcher/ui/widgets/ModFilterWidget.h
+++ b/launcher/ui/widgets/ModFilterWidget.h
@@ -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;