From a008efd24e81441a23ff3e81320ac3522251327e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 2 Jan 2016 00:35:54 +0100 Subject: GH-1365 rework java version parsing and sorting --- logic/CMakeLists.txt | 12 +- logic/java/JavaChecker.h | 7 +- logic/java/JavaInstall.cpp | 28 +++++ logic/java/JavaInstall.h | 38 ++++++ logic/java/JavaInstallList.cpp | 186 +++++++++++++++++++++++++++++ logic/java/JavaInstallList.h | 71 +++++++++++ logic/java/JavaUtils.cpp | 28 ++--- logic/java/JavaUtils.h | 8 +- logic/java/JavaVersion.cpp | 112 +++++++++++++++++ logic/java/JavaVersion.h | 30 +++++ logic/java/JavaVersionList.cpp | 218 ---------------------------------- logic/java/JavaVersionList.h | 99 --------------- logic/launch/steps/CheckJava.cpp | 4 +- logic/minecraft/MinecraftInstance.cpp | 5 +- logic/minecraft/VersionFilterData.cpp | 1 - logic/minecraft/VersionFilterData.h | 2 - 16 files changed, 500 insertions(+), 349 deletions(-) create mode 100644 logic/java/JavaInstall.cpp create mode 100644 logic/java/JavaInstall.h create mode 100644 logic/java/JavaInstallList.cpp create mode 100644 logic/java/JavaInstallList.h create mode 100644 logic/java/JavaVersion.cpp create mode 100644 logic/java/JavaVersion.h delete mode 100644 logic/java/JavaVersionList.cpp delete mode 100644 logic/java/JavaVersionList.h (limited to 'logic') diff --git a/logic/CMakeLists.txt b/logic/CMakeLists.txt index 6d03e3bd..0398cffe 100644 --- a/logic/CMakeLists.txt +++ b/logic/CMakeLists.txt @@ -260,12 +260,16 @@ set(LOGIC_SOURCES # Java related code java/JavaChecker.h java/JavaChecker.cpp - java/JavaUtils.h - java/JavaUtils.cpp - java/JavaVersionList.h - java/JavaVersionList.cpp java/JavaCheckerJob.h java/JavaCheckerJob.cpp + java/JavaInstall.h + java/JavaInstall.cpp + java/JavaInstallList.h + java/JavaInstallList.cpp + java/JavaUtils.h + java/JavaUtils.cpp + java/JavaVersion.h + java/JavaVersion.cpp # Assets minecraft/AssetsUtils.h diff --git a/logic/java/JavaChecker.h b/logic/java/JavaChecker.h index 3399f07e..650e7ce3 100644 --- a/logic/java/JavaChecker.h +++ b/logic/java/JavaChecker.h @@ -5,15 +5,16 @@ #include "multimc_logic_export.h" -class JavaChecker; +#include "JavaVersion.h" +class JavaChecker; -struct JavaCheckResult +struct MULTIMC_LOGIC_EXPORT JavaCheckResult { QString path; QString mojangPlatform; QString realPlatform; - QString javaVersion; + JavaVersion javaVersion; QString errorLog; bool valid = false; bool is_64bit = false; diff --git a/logic/java/JavaInstall.cpp b/logic/java/JavaInstall.cpp new file mode 100644 index 00000000..bb262b6e --- /dev/null +++ b/logic/java/JavaInstall.cpp @@ -0,0 +1,28 @@ +#include "JavaInstall.h" +#include + +bool JavaInstall::operator<(const JavaInstall &rhs) +{ + auto archCompare = Strings::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive); + if(archCompare != 0) + return archCompare < 0; + if(id < rhs.id) + { + return true; + } + if(id > rhs.id) + { + return false; + } + return Strings::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0; +} + +bool JavaInstall::operator==(const JavaInstall &rhs) +{ + return arch == rhs.arch && id == rhs.id && path == rhs.path; +} + +bool JavaInstall::operator>(const JavaInstall &rhs) +{ + return (!operator<(rhs)) && (!operator==(rhs)); +} diff --git a/logic/java/JavaInstall.h b/logic/java/JavaInstall.h new file mode 100644 index 00000000..882c7386 --- /dev/null +++ b/logic/java/JavaInstall.h @@ -0,0 +1,38 @@ +#pragma once + +#include "BaseVersion.h" +#include "JavaVersion.h" + +struct JavaInstall : public BaseVersion +{ + JavaInstall(){} + JavaInstall(QString id, QString arch, QString path) + : id(id), arch(arch), path(path) + { + } + virtual QString descriptor() + { + return id.toString(); + } + + virtual QString name() + { + return id.toString(); + } + + virtual QString typeString() const + { + return arch; + } + + bool operator<(const JavaInstall & rhs); + bool operator==(const JavaInstall & rhs); + bool operator>(const JavaInstall & rhs); + + JavaVersion id; + QString arch; + QString path; + bool recommended = false; +}; + +typedef std::shared_ptr JavaInstallPtr; diff --git a/logic/java/JavaInstallList.cpp b/logic/java/JavaInstallList.cpp new file mode 100644 index 00000000..fbd8ee9b --- /dev/null +++ b/logic/java/JavaInstallList.cpp @@ -0,0 +1,186 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + +#include "java/JavaInstallList.h" +#include "java/JavaCheckerJob.h" +#include "java/JavaUtils.h" +#include "MMCStrings.h" +#include "minecraft/VersionFilterData.h" + +JavaInstallList::JavaInstallList(QObject *parent) : BaseVersionList(parent) +{ +} + +Task *JavaInstallList::getLoadTask() +{ + return new JavaListLoadTask(this); +} + +const BaseVersionPtr JavaInstallList::at(int i) const +{ + return m_vlist.at(i); +} + +bool JavaInstallList::isLoaded() +{ + return m_loaded; +} + +int JavaInstallList::count() const +{ + return m_vlist.count(); +} + +QVariant JavaInstallList::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > count()) + return QVariant(); + + auto version = std::dynamic_pointer_cast(m_vlist[index.row()]); + switch (role) + { + case VersionPointerRole: + return qVariantFromValue(m_vlist[index.row()]); + case VersionIdRole: + return version->descriptor(); + case VersionRole: + return version->id.toString(); + case RecommendedRole: + return version->recommended; + case PathRole: + return version->path; + case ArchitectureRole: + return version->arch; + default: + return QVariant(); + } +} + +BaseVersionList::RoleList JavaInstallList::providesRoles() +{ + return {VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, ArchitectureRole}; +} + + +void JavaInstallList::updateListData(QList versions) +{ + beginResetModel(); + m_vlist = versions; + m_loaded = true; + sortVersions(); + if(m_vlist.size()) + { + auto best = std::dynamic_pointer_cast(m_vlist[0]); + best->recommended = true; + } + endResetModel(); +} + +bool sortJavas(BaseVersionPtr left, BaseVersionPtr right) +{ + auto rleft = std::dynamic_pointer_cast(left); + auto rright = std::dynamic_pointer_cast(right); + return (*rleft) > (*rright); +} + +void JavaInstallList::sortVersions() +{ + beginResetModel(); + std::sort(m_vlist.begin(), m_vlist.end(), sortJavas); + endResetModel(); +} + +JavaListLoadTask::JavaListLoadTask(JavaInstallList *vlist) : Task() +{ + m_list = vlist; + m_currentRecommended = NULL; +} + +JavaListLoadTask::~JavaListLoadTask() +{ +} + +void JavaListLoadTask::executeTask() +{ + setStatus(tr("Detecting Java installations...")); + + JavaUtils ju; + QList candidate_paths = ju.FindJavaPaths(); + + m_job = std::shared_ptr(new JavaCheckerJob("Java detection")); + connect(m_job.get(), SIGNAL(finished(QList)), this, SLOT(javaCheckerFinished(QList))); + connect(m_job.get(), &Task::progress, this, &Task::setProgress); + + qDebug() << "Probing the following Java paths: "; + int id = 0; + for(QString candidate : candidate_paths) + { + qDebug() << " " << candidate; + + auto candidate_checker = new JavaChecker(); + candidate_checker->m_path = candidate; + candidate_checker->m_id = id; + m_job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker)); + + id++; + } + + m_job->start(); +} + +void JavaListLoadTask::javaCheckerFinished(QList results) +{ + QList candidates; + + qDebug() << "Found the following valid Java installations:"; + for(JavaCheckResult result : results) + { + if(result.valid) + { + JavaInstallPtr javaVersion(new JavaInstall()); + + javaVersion->id = result.javaVersion; + javaVersion->arch = result.mojangPlatform; + javaVersion->path = result.path; + candidates.append(javaVersion); + + qDebug() << " " << javaVersion->id.toString() << javaVersion->arch << javaVersion->path; + } + } + + QList javas_bvp; + for (auto java : candidates) + { + //qDebug() << java->id << java->arch << " at " << java->path; + BaseVersionPtr bp_java = std::dynamic_pointer_cast(java); + + if (bp_java) + { + javas_bvp.append(java); + } + } + + m_list->updateListData(javas_bvp); + emitSucceeded(); +} diff --git a/logic/java/JavaInstallList.h b/logic/java/JavaInstallList.h new file mode 100644 index 00000000..f2ec20f7 --- /dev/null +++ b/logic/java/JavaInstallList.h @@ -0,0 +1,71 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include "BaseVersionList.h" +#include "tasks/Task.h" + +#include "JavaCheckerJob.h" +#include "JavaInstall.h" + +#include "multimc_logic_export.h" + +class JavaListLoadTask; + +class MULTIMC_LOGIC_EXPORT JavaInstallList : public BaseVersionList +{ + Q_OBJECT +public: + explicit JavaInstallList(QObject *parent = 0); + + virtual Task *getLoadTask() override; + virtual bool isLoaded() override; + virtual const BaseVersionPtr at(int i) const override; + virtual int count() const override; + virtual void sortVersions() override; + + virtual QVariant data(const QModelIndex &index, int role) const override; + virtual RoleList providesRoles() override; + +public slots: + virtual void updateListData(QList versions) override; + +protected: + QList m_vlist; + + bool m_loaded = false; +}; + +class JavaListLoadTask : public Task +{ + Q_OBJECT + +public: + explicit JavaListLoadTask(JavaInstallList *vlist); + ~JavaListLoadTask(); + + virtual void executeTask(); +public slots: + void javaCheckerFinished(QList results); + +protected: + std::shared_ptr m_job; + JavaInstallList *m_list; + JavaInstall *m_currentRecommended; +}; diff --git a/logic/java/JavaUtils.cpp b/logic/java/JavaUtils.cpp index 7c3cc2a1..9dfb7897 100644 --- a/logic/java/JavaUtils.cpp +++ b/logic/java/JavaUtils.cpp @@ -23,15 +23,15 @@ #include #include "java/JavaUtils.h" #include "java/JavaCheckerJob.h" -#include "java/JavaVersionList.h" +#include "java/JavaInstallList.h" JavaUtils::JavaUtils() { } -JavaVersionPtr JavaUtils::MakeJavaPtr(QString path, QString id, QString arch) +JavaInstallPtr JavaUtils::MakeJavaPtr(QString path, QString id, QString arch) { - JavaVersionPtr javaVersion(new JavaVersion()); + JavaInstallPtr javaVersion(new JavaInstall()); javaVersion->id = id; javaVersion->arch = arch; @@ -40,9 +40,9 @@ JavaVersionPtr JavaUtils::MakeJavaPtr(QString path, QString id, QString arch) return javaVersion; } -JavaVersionPtr JavaUtils::GetDefaultJava() +JavaInstallPtr JavaUtils::GetDefaultJava() { - JavaVersionPtr javaVersion(new JavaVersion()); + JavaInstallPtr javaVersion(new JavaInstall()); javaVersion->id = "java"; javaVersion->arch = "unknown"; @@ -52,9 +52,9 @@ JavaVersionPtr JavaUtils::GetDefaultJava() } #if WINDOWS -QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName) +QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName) { - QList javas; + QList javas; QString archType = "unknown"; if (keyType == KEY_WOW64_64KEY) @@ -114,7 +114,7 @@ QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString &valueSz); // Now, we construct the version object and add it to the list. - JavaVersionPtr javaVersion(new JavaVersion()); + JavaInstallPtr javaVersion(new JavaInstall()); javaVersion->id = subKeyName; javaVersion->arch = archType; @@ -137,15 +137,15 @@ QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString QList JavaUtils::FindJavaPaths() { - QList java_candidates; + QList java_candidates; - QList JRE64s = this->FindJavaFromRegistryKey( + QList JRE64s = this->FindJavaFromRegistryKey( KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); - QList JDK64s = this->FindJavaFromRegistryKey( + QList JDK64s = this->FindJavaFromRegistryKey( KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); - QList JRE32s = this->FindJavaFromRegistryKey( + QList JRE32s = this->FindJavaFromRegistryKey( KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); - QList JDK32s = this->FindJavaFromRegistryKey( + QList JDK32s = this->FindJavaFromRegistryKey( KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); java_candidates.append(JRE64s); @@ -159,7 +159,7 @@ QList JavaUtils::FindJavaPaths() java_candidates.append(MakeJavaPtr(this->GetDefaultJava()->path)); QList candidates; - for(JavaVersionPtr java_candidate : java_candidates) + for(JavaInstallPtr java_candidate : java_candidates) { if(!candidates.contains(java_candidate->path)) { diff --git a/logic/java/JavaUtils.h b/logic/java/JavaUtils.h index 78693b37..b671d0a5 100644 --- a/logic/java/JavaUtils.h +++ b/logic/java/JavaUtils.h @@ -20,7 +20,7 @@ #include "JavaCheckerJob.h" #include "JavaChecker.h" -#include "JavaVersionList.h" +#include "JavaInstallList.h" #ifdef Q_OS_WIN #include @@ -34,11 +34,11 @@ class MULTIMC_LOGIC_EXPORT JavaUtils : public QObject public: JavaUtils(); - JavaVersionPtr MakeJavaPtr(QString path, QString id = "unknown", QString arch = "unknown"); + JavaInstallPtr MakeJavaPtr(QString path, QString id = "unknown", QString arch = "unknown"); QList FindJavaPaths(); - JavaVersionPtr GetDefaultJava(); + JavaInstallPtr GetDefaultJava(); #ifdef Q_OS_WIN - QList FindJavaFromRegistryKey(DWORD keyType, QString keyName); + QList FindJavaFromRegistryKey(DWORD keyType, QString keyName); #endif }; diff --git a/logic/java/JavaVersion.cpp b/logic/java/JavaVersion.cpp new file mode 100644 index 00000000..84fc48a4 --- /dev/null +++ b/logic/java/JavaVersion.cpp @@ -0,0 +1,112 @@ +#include "JavaVersion.h" +#include + +#include +#include + +JavaVersion & JavaVersion::operator=(const QString & javaVersionString) +{ + string = javaVersionString; + + auto getCapturedInteger = [](const QRegularExpressionMatch & match, const QString &what) -> int + { + auto str = match.captured(what); + if(str.isEmpty()) + { + return 0; + } + return str.toInt(); + }; + + QRegularExpression pattern; + if(javaVersionString.startsWith("1.")) + { + pattern = QRegularExpression ("1[.](?[0-9]+)([.](?[0-9]+))?(_(?[0-9]+)?)?(-(?[a-zA-Z0-9]+))?"); + } + else + { + pattern = QRegularExpression("(?[0-9]+)([.](?[0-9]+))?([.](?[0-9]+))?(-(?[a-zA-Z0-9]+))?"); + } + + auto match = pattern.match(string); + parseable = match.hasMatch(); + major = getCapturedInteger(match, "major"); + minor = getCapturedInteger(match, "minor"); + security = getCapturedInteger(match, "security"); + prerelease = match.captured("prerelease"); + return *this; +} + +JavaVersion::JavaVersion(const QString &rhs) +{ + operator=(rhs); +} + +QString JavaVersion::toString() +{ + return string; +} + +bool JavaVersion::requiresPermGen() +{ + if(parseable) + { + return major < 8; + } + return true; +} + +bool JavaVersion::operator<(const JavaVersion &rhs) +{ + if(parseable && rhs.parseable) + { + if(major < rhs.major) + return true; + if(major > rhs.major) + return false; + if(minor < rhs.minor) + return true; + if(minor > rhs.minor) + return false; + if(security < rhs.security) + return true; + if(security > rhs.security) + return false; + + // everything else being equal, consider prerelease status + bool thisPre = !prerelease.isEmpty(); + bool rhsPre = !rhs.prerelease.isEmpty(); + if(thisPre && !rhsPre) + { + // this is a prerelease and the other one isn't -> lesser + return true; + } + else if(!thisPre && rhsPre) + { + // this isn't a prerelease and the other one is -> greater + return false; + } + else if(thisPre && rhsPre) + { + // both are prereleases - use natural compare... + return Strings::naturalCompare(prerelease, rhs.prerelease, Qt::CaseSensitive) < 0; + } + // neither is prerelease, so they are the same -> this cannot be less than rhs + return false; + } + else return Strings::naturalCompare(string, rhs.string, Qt::CaseSensitive) < 0; +} + +bool JavaVersion::operator==(const JavaVersion &rhs) +{ + if(parseable && rhs.parseable) + { + return major == rhs.major && minor == rhs.minor && security == rhs.security && prerelease == rhs.prerelease; + } + return string == rhs.string; +} + +bool JavaVersion::operator>(const JavaVersion &rhs) +{ + return (!operator<(rhs)) && (!operator==(rhs)); +} diff --git a/logic/java/JavaVersion.h b/logic/java/JavaVersion.h new file mode 100644 index 00000000..f9a733d3 --- /dev/null +++ b/logic/java/JavaVersion.h @@ -0,0 +1,30 @@ +#pragma once + +#include "multimc_logic_export.h" +#include + +class MULTIMC_LOGIC_EXPORT JavaVersion +{ + friend class JavaVersionTest; +public: + JavaVersion() {}; + JavaVersion(const QString & rhs); + + JavaVersion & operator=(const QString & rhs); + + bool operator<(const JavaVersion & rhs); + bool operator==(const JavaVersion & rhs); + bool operator>(const JavaVersion & rhs); + + bool requiresPermGen(); + + QString toString(); + +private: + QString string; + int major = 0; + int minor = 0; + int security = 0; + bool parseable = false; + QString prerelease; +}; diff --git a/logic/java/JavaVersionList.cpp b/logic/java/JavaVersionList.cpp deleted file mode 100644 index e3929f45..00000000 --- a/logic/java/JavaVersionList.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include - -#include "java/JavaVersionList.h" -#include "java/JavaCheckerJob.h" -#include "java/JavaUtils.h" -#include "MMCStrings.h" -#include "minecraft/VersionFilterData.h" - -JavaVersionList::JavaVersionList(QObject *parent) : BaseVersionList(parent) -{ -} - -Task *JavaVersionList::getLoadTask() -{ - return new JavaListLoadTask(this); -} - -const BaseVersionPtr JavaVersionList::at(int i) const -{ - return m_vlist.at(i); -} - -bool JavaVersionList::isLoaded() -{ - return m_loaded; -} - -int JavaVersionList::count() const -{ - return m_vlist.count(); -} - -QVariant JavaVersionList::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (index.row() > count()) - return QVariant(); - - auto version = std::dynamic_pointer_cast(m_vlist[index.row()]); - switch (role) - { - case VersionPointerRole: - return qVariantFromValue(m_vlist[index.row()]); - case VersionIdRole: - return version->descriptor(); - case VersionRole: - return version->id; - case RecommendedRole: - return version->recommended; - case PathRole: - return version->path; - case ArchitectureRole: - return version->arch; - default: - return QVariant(); - } -} - -BaseVersionList::RoleList JavaVersionList::providesRoles() -{ - return {VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, ArchitectureRole}; -} - - -void JavaVersionList::updateListData(QList versions) -{ - beginResetModel(); - m_vlist = versions; - m_loaded = true; - // manual testing fakery - /* - m_vlist.push_back(std::make_shared("1.6.0_33", "64", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.6.0_44", "64", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.6.0_55", "64", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.7.0_44", "64", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.8.0_44", "64", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.6.0_33", "32", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.6.0_44", "32", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.6.0_55", "32", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.7.0_44", "32", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.8.0_44", "32", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.9.0_1231", "32", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.9.0_1", "32", "/foo/bar/baz")); - m_vlist.push_back(std::make_shared("1.9.0_1", "64", "/foo/bar/baz")); - */ - sortVersions(); - if(m_vlist.size()) - { - auto best = std::dynamic_pointer_cast(m_vlist[0]); - best->recommended = true; - } - endResetModel(); -} - -bool sortJavas(BaseVersionPtr left, BaseVersionPtr right) -{ - auto rleft = std::dynamic_pointer_cast(left); - auto rright = std::dynamic_pointer_cast(right); - // prefer higher arch - auto archCompare = Strings::naturalCompare(rleft->arch, rright->arch, Qt::CaseInsensitive); - if(archCompare != 0) - return archCompare > 0; - // dirty hack - 1.9 and above is too new - auto labove19 = Strings::naturalCompare(rleft->name(), g_VersionFilterData.discouragedJavaVersion, Qt::CaseInsensitive) >= 0; - auto rabove19 = Strings::naturalCompare(rright->name(), g_VersionFilterData.discouragedJavaVersion, Qt::CaseInsensitive) >= 0; - if(labove19 == rabove19) - { - // prefer higher versions in general - auto nameCompare = Strings::naturalCompare(rleft->name(), rright->name(), Qt::CaseInsensitive); - if(nameCompare != 0) - return nameCompare > 0; - // if all else is equal, sort by path - return Strings::naturalCompare(rleft->path, rright->path, Qt::CaseInsensitive) < 0; - } - return labove19 < rabove19; -} - -void JavaVersionList::sortVersions() -{ - beginResetModel(); - std::sort(m_vlist.begin(), m_vlist.end(), sortJavas); - endResetModel(); -} - -JavaListLoadTask::JavaListLoadTask(JavaVersionList *vlist) : Task() -{ - m_list = vlist; - m_currentRecommended = NULL; -} - -JavaListLoadTask::~JavaListLoadTask() -{ -} - -void JavaListLoadTask::executeTask() -{ - setStatus(tr("Detecting Java installations...")); - - JavaUtils ju; - QList candidate_paths = ju.FindJavaPaths(); - - m_job = std::shared_ptr(new JavaCheckerJob("Java detection")); - connect(m_job.get(), SIGNAL(finished(QList)), this, SLOT(javaCheckerFinished(QList))); - connect(m_job.get(), &Task::progress, this, &Task::setProgress); - - qDebug() << "Probing the following Java paths: "; - int id = 0; - for(QString candidate : candidate_paths) - { - qDebug() << " " << candidate; - - auto candidate_checker = new JavaChecker(); - candidate_checker->m_path = candidate; - candidate_checker->m_id = id; - m_job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker)); - - id++; - } - - m_job->start(); -} - -void JavaListLoadTask::javaCheckerFinished(QList results) -{ - QList candidates; - - qDebug() << "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); - - qDebug() << " " << javaVersion->id << javaVersion->arch << javaVersion->path; - } - } - - QList javas_bvp; - for (auto java : candidates) - { - //qDebug() << java->id << java->arch << " at " << java->path; - BaseVersionPtr bp_java = std::dynamic_pointer_cast(java); - - if (bp_java) - { - javas_bvp.append(java); - } - } - - m_list->updateListData(javas_bvp); - emitSucceeded(); -} diff --git a/logic/java/JavaVersionList.h b/logic/java/JavaVersionList.h deleted file mode 100644 index 3acb5343..00000000 --- a/logic/java/JavaVersionList.h +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "BaseVersionList.h" -#include "tasks/Task.h" -#include "java/JavaCheckerJob.h" - -#include "multimc_logic_export.h" - -class JavaListLoadTask; - -struct JavaVersion : public BaseVersion -{ - JavaVersion(){} - JavaVersion(QString id, QString arch, QString path) - : id(id), arch(arch), path(path) - { - } - virtual QString descriptor() - { - return id; - } - - virtual QString name() - { - return id; - } - - virtual QString typeString() const - { - return arch; - } - - QString id; - QString arch; - QString path; - bool recommended = false; -}; - -typedef std::shared_ptr JavaVersionPtr; - -class MULTIMC_LOGIC_EXPORT JavaVersionList : public BaseVersionList -{ - Q_OBJECT -public: - explicit JavaVersionList(QObject *parent = 0); - - virtual Task *getLoadTask() override; - virtual bool isLoaded() override; - virtual const BaseVersionPtr at(int i) const override; - virtual int count() const override; - virtual void sortVersions() override; - - virtual QVariant data(const QModelIndex &index, int role) const override; - virtual RoleList providesRoles() override; - -public slots: - virtual void updateListData(QList versions) override; - -protected: - QList m_vlist; - - bool m_loaded = false; -}; - -class JavaListLoadTask : public Task -{ - Q_OBJECT - -public: - explicit JavaListLoadTask(JavaVersionList *vlist); - ~JavaListLoadTask(); - - virtual void executeTask(); -public slots: - void javaCheckerFinished(QList results); - -protected: - std::shared_ptr m_job; - JavaVersionList *m_list; - JavaVersion *m_currentRecommended; -}; diff --git a/logic/launch/steps/CheckJava.cpp b/logic/launch/steps/CheckJava.cpp index 66f7cc2b..a4eaa307 100644 --- a/logic/launch/steps/CheckJava.cpp +++ b/logic/launch/steps/CheckJava.cpp @@ -83,9 +83,9 @@ void CheckJava::checkJavaFinished(JavaCheckResult result) else { auto instance = m_parent->instance(); - emit logLine(tr("Java version is %1!\n").arg(result.javaVersion), + emit logLine(tr("Java version is %1!\n").arg(result.javaVersion.toString()), MessageLevel::MultiMC); - instance->settings()->set("JavaVersion", result.javaVersion); + instance->settings()->set("JavaVersion", result.javaVersion.toString()); instance->settings()->set("JavaTimestamp", m_javaUnixTime); emitSucceeded(); } diff --git a/logic/minecraft/MinecraftInstance.cpp b/logic/minecraft/MinecraftInstance.cpp index 05dedf1d..405ccd26 100644 --- a/logic/minecraft/MinecraftInstance.cpp +++ b/logic/minecraft/MinecraftInstance.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #define IBUS "@im=ibus" @@ -104,8 +105,8 @@ QStringList MinecraftInstance::javaArguments() const args << QString("-Xmx%1m").arg(settings()->get("MaxMemAlloc").toInt()); // No PermGen in newer java. - auto javaVersion = settings()->get("JavaVersion"); - if(Strings::naturalCompare(javaVersion.toString(), "1.8.0", Qt::CaseInsensitive) < 0) + JavaVersion javaVersion(settings()->get("JavaVersion").toString()); + if(javaVersion.requiresPermGen()) { auto permgen = settings()->get("PermGen").toInt(); if (permgen != 64) diff --git a/logic/minecraft/VersionFilterData.cpp b/logic/minecraft/VersionFilterData.cpp index 8270a490..0c4a6e3d 100644 --- a/logic/minecraft/VersionFilterData.cpp +++ b/logic/minecraft/VersionFilterData.cpp @@ -72,5 +72,4 @@ VersionFilterData::VersionFilterData() // Version list magic recommendedMinecraftVersion = "1.7.10"; - discouragedJavaVersion = "1.9.0"; } diff --git a/logic/minecraft/VersionFilterData.h b/logic/minecraft/VersionFilterData.h index 98db2484..f7d4ebe7 100644 --- a/logic/minecraft/VersionFilterData.h +++ b/logic/minecraft/VersionFilterData.h @@ -28,7 +28,5 @@ struct VersionFilterData QSet lwjglWhitelist; // Currently recommended minecraft version QString recommendedMinecraftVersion; - // Currently discouraged java version (anything equal and above will be discouraged) - QString discouragedJavaVersion; }; extern VersionFilterData MULTIMC_LOGIC_EXPORT g_VersionFilterData; -- cgit v1.2.3