diff options
Diffstat (limited to 'logic/lists/JavaVersionList.cpp')
-rw-r--r-- | logic/lists/JavaVersionList.cpp | 83 |
1 files changed, 59 insertions, 24 deletions
diff --git a/logic/lists/JavaVersionList.cpp b/logic/lists/JavaVersionList.cpp index 3dc1969b..d2f0972c 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) @@ -183,20 +175,63 @@ void JavaListLoadTask::executeTask() setStatus("Detecting Java installations..."); JavaUtils ju; - QList<JavaVersionPtr> javas = ju.FindJavaPaths(); + QList<QString> candidate_paths = ju.FindJavaPaths(); + + 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))); + + QLOG_DEBUG() << "Probing the following Java paths: "; + for(QString candidate : candidate_paths) + { + QLOG_DEBUG() << " " << candidate; + + auto candidate_checker = new JavaChecker(); + candidate_checker->path = candidate; + job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker)); + } + + job->start(); +} + +void JavaListLoadTask::checkerProgress(int current, int total) +{ + float progress = (current * 100.0) / total; + this->setProgress((int) progress); +} + +void JavaListLoadTask::javaCheckerFinished(QList<JavaCheckResult> results) +{ + QList<JavaVersionPtr> candidates; + + QLOG_DEBUG() << "Found the following valid Java installations:"; + 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); } } m_list->updateListData(javas_bvp); - emitSucceeded(); } |