Added JavaPath function

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-02-08 19:45:46 +02:00
parent 82b15268bc
commit ba990e075b
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
5 changed files with 36 additions and 5 deletions

View File

@ -48,7 +48,6 @@
#include "net/PasteUpload.h"
#include "pathmatcher/MultiMatcher.h"
#include "pathmatcher/SimplePrefixMatcher.h"
#include "settings/INIFile.h"
#include "ui/InstanceWindow.h"
#include "ui/MainWindow.h"
@ -106,8 +105,6 @@
#include "icons/IconList.h"
#include "net/HttpMetaCache.h"
#include "java/JavaUtils.h"
#include "updater/ExternalUpdater.h"
#include "tools/JProfiler.h"
@ -1833,3 +1830,7 @@ QUrl Application::normalizeImportUrl(QString const& url)
return QUrl::fromUserInput(url);
}
}
const QString Application::javaPath()
{
return FS::PathCombine(m_dataPath, "java");
}

View File

@ -162,6 +162,9 @@ class Application : public QApplication {
/// the data path the application is using
const QString& dataRoot() { return m_dataPath; }
/// the java installed path the application is using
const QString javaPath();
bool isPortable() { return m_portable; }
const Capabilities capabilities() { return m_capabilities; }

View File

@ -337,6 +337,7 @@ QList<QString> JavaUtils::FindJavaPaths()
}
candidates.append(getMinecraftJavaBundle());
candidates.append(getPrismJavaBundle());
candidates = addJavasFromEnv(candidates);
candidates.removeDuplicates();
return candidates;
@ -363,6 +364,7 @@ QList<QString> JavaUtils::FindJavaPaths()
javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Commands/java");
}
javas.append(getMinecraftJavaBundle());
javas.append(getPrismJavaBundle());
javas = addJavasFromEnv(javas);
javas.removeDuplicates();
return javas;
@ -393,7 +395,6 @@ QList<QString> JavaUtils::FindJavaPaths()
scanJavaDir(snap + dirPath);
}
};
scanJavaDir(FS::PathCombine(APPLICATION->dataRoot(), "java"));
// oracle RPMs
scanJavaDirs("/usr/java");
// general locations used by distro packaging
@ -416,6 +417,7 @@ QList<QString> JavaUtils::FindJavaPaths()
scanJavaDirs(FS::PathCombine(home, ".sdkman/candidates/java"));
javas.append(getMinecraftJavaBundle());
javas.append(getPrismJavaBundle());
javas = addJavasFromEnv(javas);
javas.removeDuplicates();
return javas;
@ -429,6 +431,8 @@ QList<QString> JavaUtils::FindJavaPaths()
javas.append(this->GetDefaultJava()->path);
javas.append(getMinecraftJavaBundle());
javas.append(getPrismJavaBundle());
javas.removeDuplicates();
return addJavasFromEnv(javas);
}
#endif
@ -484,3 +488,25 @@ QStringList getMinecraftJavaBundle()
}
return javas;
}
QStringList getPrismJavaBundle()
{
QList<QString> javas;
QDir dir(APPLICATION->javaPath());
if (!dir.exists())
return javas;
QString executable = "java";
#if defined(Q_OS_WIN32)
executable += "w.exe";
#endif
auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (auto& entry : entries) {
QString prefix;
prefix = entry.canonicalFilePath();
javas.append(FS::PathCombine(prefix, "jre", "bin", executable));
javas.append(FS::PathCombine(prefix, "bin", executable));
}
return javas;
}

View File

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

View File

@ -85,7 +85,7 @@ void Downloader::accept()
return;
}
Task::Ptr task;
auto final_path = FS::PathCombine(APPLICATION->dataRoot(), "java", meta->vendor, meta->m_name);
auto final_path = FS::PathCombine(APPLICATION->javaPath(), meta->m_name);
switch (meta->downloadType) {
case Java::DownloadType::Manifest:
task = makeShared<ManifestDownloadTask>(meta->url, final_path, meta->checksumType, meta->checksumHash);