summaryrefslogtreecommitdiffstats
path: root/logic/lists/JavaVersionList.cpp
diff options
context:
space:
mode:
authorSky <git@bunnies.cc>2013-12-11 03:54:39 +0000
committerSky <git@bunnies.cc>2013-12-11 04:54:00 +0000
commitafa5e14e2074343270ff205e042f102c03dface0 (patch)
tree1b72b755c5b7292742b048aec4b4a77af8dec4ac /logic/lists/JavaVersionList.cpp
parentab69c1b9e6c25e92ded4a6ac6774e468a2e08b7b (diff)
downloadMultiMC-afa5e14e2074343270ff205e042f102c03dface0.tar
MultiMC-afa5e14e2074343270ff205e042f102c03dface0.tar.gz
MultiMC-afa5e14e2074343270ff205e042f102c03dface0.tar.lz
MultiMC-afa5e14e2074343270ff205e042f102c03dface0.tar.xz
MultiMC-afa5e14e2074343270ff205e042f102c03dface0.zip
Better (but unsorted) Java detection
Diffstat (limited to 'logic/lists/JavaVersionList.cpp')
-rw-r--r--logic/lists/JavaVersionList.cpp87
1 files changed, 64 insertions, 23 deletions
diff --git a/logic/lists/JavaVersionList.cpp b/logic/lists/JavaVersionList.cpp
index 3dc1969b..bc177f09 100644
--- a/logic/lists/JavaVersionList.cpp
+++ b/logic/lists/JavaVersionList.cpp
@@ -21,7 +21,8 @@
#include <QRegExp>
#include "logger/QsLog.h"
-#include <logic/JavaUtils.h>
+#include "logic/JavaCheckerJob.h"
+#include "logic/JavaUtils.h"
JavaVersionList::JavaVersionList(QObject *parent) : BaseVersionList(parent)
{
@@ -49,7 +50,7 @@ int JavaVersionList::count() const
int JavaVersionList::columnCount(const QModelIndex &parent) const
{
- return 4;
+ return 3;
}
QVariant JavaVersionList::data(const QModelIndex &index, int role) const
@@ -75,9 +76,6 @@ QVariant JavaVersionList::data(const QModelIndex &index, int role) const
case 2:
return version->path;
- case 3:
- return version->recommended ? tr("Yes") : tr("No");
-
default:
return QVariant();
}
@@ -109,9 +107,6 @@ QVariant JavaVersionList::headerData(int section, Qt::Orientation orientation, i
case 2:
return "Path";
- case 3:
- return "Recommended";
-
default:
return QVariant();
}
@@ -128,9 +123,6 @@ QVariant JavaVersionList::headerData(int section, Qt::Orientation orientation, i
case 2:
return "Path to this Java version.";
- case 3:
- return "Whether the version is recommended or not.";
-
default:
return QVariant();
}
@@ -142,15 +134,15 @@ QVariant JavaVersionList::headerData(int section, Qt::Orientation orientation, i
BaseVersionPtr JavaVersionList::getTopRecommended() const
{
- for (int i = 0; i < m_vlist.length(); i++)
+ auto first = m_vlist.first();
+ if(first != nullptr)
{
- auto ver = std::dynamic_pointer_cast<JavaVersion>(m_vlist.at(i));
- if (ver->recommended)
- {
- return m_vlist.at(i);
- }
+ return first;
+ }
+ else
+ {
+ return BaseVersionPtr();
}
- return BaseVersionPtr();
}
void JavaVersionList::updateListData(QList<BaseVersionPtr> versions)
@@ -182,17 +174,66 @@ void JavaListLoadTask::executeTask()
{
setStatus("Detecting Java installations...");
+ QSet<QString> candidate_paths;
JavaUtils ju;
- QList<JavaVersionPtr> javas = ju.FindJavaPaths();
+
+ QList<JavaVersionPtr> candidates = ju.FindJavaPaths();
+
+ for(JavaVersionPtr &candidate : candidates)
+ {
+ candidate_paths.insert(candidate->path);
+ }
+
+ auto job = new JavaCheckerJob("Java detection");
+ connect(job, SIGNAL(finished(QList<JavaCheckResult>)), this, SLOT(javaCheckerFinished(QList<JavaCheckResult>)));
+ connect(job, SIGNAL(progress(int, int)), this, SLOT(checkerProgress(int, int)));
+
+ for(const QString candidate : candidate_paths)
+ {
+ auto candidate_checker = new JavaChecker();
+ candidate_checker->path = candidate;
+ job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker));
+ }
+
+ QLOG_DEBUG() << "Starting java checker job with" << job->size() << "candidates";
+ job->start();
+}
+
+void JavaListLoadTask::checkerProgress(int current, int total)
+{
+ float progress = (current * 100.0) / (current + total);
+ this->setProgress((int) progress);
+}
+
+void JavaListLoadTask::javaCheckerFinished(QList<JavaCheckResult> results)
+{
+ QList<JavaVersionPtr> candidates;
+
+ QLOG_DEBUG() << "Got Java checker results:";
+ for(JavaCheckResult result : results)
+ {
+ if(result.valid)
+ {
+ JavaVersionPtr javaVersion(new JavaVersion());
+
+ javaVersion->id = result.javaVersion;
+ javaVersion->arch = result.mojangPlatform;
+ javaVersion->path = result.path;
+ candidates.append(javaVersion);
+
+ QLOG_DEBUG() << javaVersion->id << javaVersion->arch << javaVersion->path;
+ }
+ }
QList<BaseVersionPtr> javas_bvp;
- for (int i = 0; i < javas.length(); i++)
+ for (auto &java : candidates)
{
- BaseVersionPtr java = std::dynamic_pointer_cast<BaseVersion>(javas.at(i));
+ //QLOG_INFO() << java->id << java->arch << " at " << java->path;
+ BaseVersionPtr bp_java = std::dynamic_pointer_cast<BaseVersion>(java);
- if (java)
+ if (bp_java)
{
- javas_bvp.append(java);
+ javas_bvp.append(bp_java);
}
}