Added management for downloaded javas from prism

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-02-09 22:47:39 +02:00
parent 0a3303bcbd
commit 27d662e642
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
7 changed files with 143 additions and 7 deletions

View File

@ -46,7 +46,9 @@
#include "java/JavaUtils.h"
#include "tasks/ConcurrentTask.h"
JavaInstallList::JavaInstallList(QObject* parent) : BaseVersionList(parent) {}
JavaInstallList::JavaInstallList(QObject* parent, bool onlyManagedVersions)
: BaseVersionList(parent), m_only_managed_versions(onlyManagedVersions)
{}
Task::Ptr JavaInstallList::getLoadTask()
{
@ -66,7 +68,7 @@ void JavaInstallList::load()
{
if (m_status != Status::InProgress) {
m_status = Status::InProgress;
m_load_task.reset(new JavaListLoadTask(this));
m_load_task.reset(new JavaListLoadTask(this, m_only_managed_versions));
m_load_task->start();
}
}
@ -148,7 +150,7 @@ void JavaInstallList::sortVersions()
endResetModel();
}
JavaListLoadTask::JavaListLoadTask(JavaInstallList* vlist) : Task()
JavaListLoadTask::JavaListLoadTask(JavaInstallList* vlist, bool onlyManagedVersions) : Task(), m_only_managed_versions(onlyManagedVersions)
{
m_list = vlist;
m_current_recommended = NULL;
@ -159,7 +161,7 @@ void JavaListLoadTask::executeTask()
setStatus(tr("Detecting Java installations..."));
JavaUtils ju;
QList<QString> candidate_paths = ju.FindJavaPaths();
QList<QString> candidate_paths = m_only_managed_versions ? getPrismJavaBundle() : ju.FindJavaPaths();
ConcurrentTask::Ptr job(new ConcurrentTask(this, "Java detection", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt()));
m_job.reset(job);

View File

@ -33,7 +33,7 @@ class JavaInstallList : public BaseVersionList {
enum class Status { NotDone, InProgress, Done };
public:
explicit JavaInstallList(QObject* parent = 0);
explicit JavaInstallList(QObject* parent = 0, bool onlyManagedVersions = false);
Task::Ptr getLoadTask() override;
bool isLoaded() override;
@ -55,13 +55,14 @@ class JavaInstallList : public BaseVersionList {
Status m_status = Status::NotDone;
shared_qobject_ptr<JavaListLoadTask> m_load_task;
QList<BaseVersion::Ptr> m_vlist;
bool m_only_managed_versions;
};
class JavaListLoadTask : public Task {
Q_OBJECT
public:
explicit JavaListLoadTask(JavaInstallList* vlist);
explicit JavaListLoadTask(JavaInstallList* vlist, bool onlyManagedVersions = false);
virtual ~JavaListLoadTask() = default;
protected:
@ -74,4 +75,5 @@ class JavaListLoadTask : public Task {
JavaInstallList* m_list;
JavaInstall* m_current_recommended;
QList<JavaChecker::Result> m_results;
bool m_only_managed_versions;
};

View File

@ -338,6 +338,7 @@ QList<QString> JavaUtils::FindJavaPaths()
candidates.append(getMinecraftJavaBundle());
candidates.append(getPrismJavaBundle());
candidates.append(getPrismExtraJavaPaths());
candidates = addJavasFromEnv(candidates);
candidates.removeDuplicates();
return candidates;
@ -365,6 +366,7 @@ QList<QString> JavaUtils::FindJavaPaths()
}
javas.append(getMinecraftJavaBundle());
javas.append(getPrismJavaBundle());
javas.append(getPrismExtraJavaPaths());
javas = addJavasFromEnv(javas);
javas.removeDuplicates();
return javas;
@ -418,6 +420,7 @@ QList<QString> JavaUtils::FindJavaPaths()
javas.append(getMinecraftJavaBundle());
javas.append(getPrismJavaBundle());
javas.append(getPrismExtraJavaPaths());
javas = addJavasFromEnv(javas);
javas.removeDuplicates();
return javas;
@ -432,6 +435,7 @@ QList<QString> JavaUtils::FindJavaPaths()
javas.append(getMinecraftJavaBundle());
javas.append(getPrismJavaBundle());
javas.append(getPrismExtraJavaPaths());
javas.removeDuplicates();
return addJavasFromEnv(javas);
}
@ -515,6 +519,33 @@ QStringList getPrismJavaBundle()
scanJavaDir(APPLICATION->javaPath());
return javas;
}
QStringList getPrismExtraJavaPaths()
{
QList<QString> javas;
QString executable = "java";
#if defined(Q_OS_WIN32)
executable += "w.exe";
#endif
auto scanDir = [&](QString prefix) {
javas.append(FS::PathCombine(prefix, "jre", "bin", executable));
javas.append(FS::PathCombine(prefix, "bin", executable));
javas.append(FS::PathCombine(prefix, executable));
};
auto scanJavaDir = [&](const QString& dirPath) {
QDir dir(dirPath);
if (!dir.exists())
return;
auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (auto& entry : entries) {
scanDir(entry.canonicalFilePath());
}
};
auto extra_paths = APPLICATION->settings()->get("JavaExtraSearchPaths").toStringList();
for (auto& entry : extra_paths) {
scanDir(entry);

View File

@ -27,6 +27,7 @@ QString stripVariableEntries(QString name, QString target, QString remove);
QProcessEnvironment CleanEnviroment();
QStringList getMinecraftJavaBundle();
QStringList getPrismJavaBundle();
QStringList getPrismExtraJavaPaths();
class JavaUtils : public QObject {
Q_OBJECT

View File

@ -36,6 +36,8 @@
#include "JavaPage.h"
#include "JavaCommon.h"
#include "java/JavaInstall.h"
#include "ui/dialogs/CustomMessageBox.h"
#include "ui/java/JavaDownloader.h"
#include "ui_JavaPage.h"
@ -59,6 +61,11 @@ JavaPage::JavaPage(QWidget* parent) : QWidget(parent), ui(new Ui::JavaPage)
{
ui->setupUi(this);
ui->managedJavaList->initialize(new JavaInstallList(this, true));
ui->managedJavaList->selectCurrent();
ui->managedJavaList->setEmptyString(tr("No java versions are currently available in the meta"));
ui->managedJavaList->setEmptyErrorString(tr("Couldn't load or download the java version lists!"));
loadSettings();
updateThresholds();
}
@ -244,3 +251,36 @@ void JavaPage::on_removeExtraPathButton_clicked()
}
APPLICATION->settings()->set("JavaExtraSearchPaths", m_extra_paths->stringList());
}
void JavaPage::on_downloadJavaButton_clicked()
{
on_javaDownloadBtn_clicked();
}
void JavaPage::on_removeJavaButton_clicked()
{
auto version = ui->managedJavaList->selectedVersion();
auto dcast = std::dynamic_pointer_cast<JavaInstall>(version);
if (!dcast) {
return;
}
QDir dir(APPLICATION->javaPath());
auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (auto& entry : entries) {
if (dcast->path.startsWith(entry.canonicalFilePath())) {
auto response = CustomMessageBox::selectable(this, tr("Confirm Deletion"),
tr("You are about to remove \"%1\" java version.\n"
"Are you sure?")
.arg(entry.fileName()),
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response == QMessageBox::Yes) {
FS::deletePath(entry.canonicalFilePath());
ui->managedJavaList->loadList();
}
break;
}
}
}

View File

@ -75,6 +75,8 @@ class JavaPage : public QWidget, public BasePage {
void on_javaDownloadBtn_clicked();
void on_addExtraPathButton_clicked();
void on_removeExtraPathButton_clicked();
void on_downloadJavaButton_clicked();
void on_removeJavaButton_clicked();
void on_maxMemSpinBox_valueChanged(int i);
void checkerFinished();

View File

@ -32,7 +32,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="general">
<attribute name="title">
@ -317,6 +317,56 @@
<string>Management</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Downloaded Java Versions</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="VersionSelectWidget" name="managedJavaList" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="managedJavaBtnLayout">
<item>
<widget class="QPushButton" name="downloadJavaButton">
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeJavaButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="extraJavaPathsGroupBox">
<property name="title">
@ -379,6 +429,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>VersionSelectWidget</class>
<extends>QWidget</extends>
<header>ui/widgets/VersionSelectWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>minMemSpinBox</tabstop>
<tabstop>maxMemSpinBox</tabstop>