aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-07-06 17:40:09 +0200
committerGitHub <noreply@github.com>2022-07-06 17:40:09 +0200
commitf1902a44716201d9d6431cab762663cd749b58eb (patch)
tree4f952a91312804ab44cd12bb7db10b044eadce0c /launcher
parent04b865adaec8f7af1a148e004c67c0483dbcc67b (diff)
parent474d77ac574c24918759413c2a77dc657e1e8581 (diff)
downloadPrismLauncher-f1902a44716201d9d6431cab762663cd749b58eb.tar.gz
PrismLauncher-f1902a44716201d9d6431cab762663cd749b58eb.tar.bz2
PrismLauncher-f1902a44716201d9d6431cab762663cd749b58eb.zip
Merge pull request #794 from Scrumplex/resolve-jars-dynamically
Diffstat (limited to 'launcher')
-rw-r--r--launcher/Application.cpp21
-rw-r--r--launcher/Application.h7
-rw-r--r--launcher/JavaCommon.cpp13
-rw-r--r--launcher/JavaCommon.h10
-rw-r--r--launcher/java/JavaChecker.cpp8
-rw-r--r--launcher/java/JavaUtils.cpp6
-rw-r--r--launcher/java/JavaUtils.h2
-rw-r--r--launcher/launch/steps/CheckJava.cpp9
-rw-r--r--launcher/minecraft/launch/LauncherPartLaunch.cpp11
-rw-r--r--launcher/ui/pages/global/JavaPage.cpp5
-rw-r--r--launcher/ui/pages/instance/InstanceSettingsPage.cpp6
-rw-r--r--launcher/ui/widgets/JavaSettingsWidget.cpp5
12 files changed, 87 insertions, 16 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index 757d852f..0ef641ba 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -334,10 +334,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
// on macOS, touch the root to force Finder to reload the .app metadata (and fix any icon change issues)
FS::updateTimestamp(m_rootPath);
#endif
-
-#ifdef LAUNCHER_JARS_LOCATION
- m_jarsPath = TOSTRING(LAUNCHER_JARS_LOCATION);
-#endif
}
QString adjustedBy;
@@ -1562,13 +1558,22 @@ shared_qobject_ptr<Meta::Index> Application::metadataIndex()
return m_metadataIndex;
}
-QString Application::getJarsPath()
+QString Application::getJarPath(QString jarFile)
{
- if(m_jarsPath.isEmpty())
+ QStringList potentialPaths = {
+#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
+ FS::PathCombine(m_rootPath, "share/jars"),
+#endif
+ FS::PathCombine(m_rootPath, "jars"),
+ FS::PathCombine(applicationDirPath(), "jars")
+ };
+ for(QString p : potentialPaths)
{
- return FS::PathCombine(QCoreApplication::applicationDirPath(), "jars");
+ QString jarPath = FS::PathCombine(p, jarFile);
+ if (QFileInfo(jarPath).isFile())
+ return jarPath;
}
- return FS::PathCombine(m_rootPath, m_jarsPath);
+ return {};
}
QString Application::getMSAClientID()
diff --git a/launcher/Application.h b/launcher/Application.h
index 09007160..18461ad8 100644
--- a/launcher/Application.h
+++ b/launcher/Application.h
@@ -157,7 +157,11 @@ public:
shared_qobject_ptr<Meta::Index> metadataIndex();
- QString getJarsPath();
+ /*!
+ * Finds and returns the full path to a jar file.
+ * Returns a null-string if it could not be found.
+ */
+ QString getJarPath(QString jarFile);
QString getMSAClientID();
QString getCurseKey();
@@ -241,7 +245,6 @@ private:
std::shared_ptr<GenericPageProvider> m_globalSettingsProvider;
std::map<QString, std::unique_ptr<ITheme>> m_themes;
std::unique_ptr<MCEditTool> m_mcedit;
- QString m_jarsPath;
QSet<QString> m_features;
QMap<QString, std::shared_ptr<BaseProfilerFactory>> m_profilers;
diff --git a/launcher/JavaCommon.cpp b/launcher/JavaCommon.cpp
index 17278d86..ae6cd247 100644
--- a/launcher/JavaCommon.cpp
+++ b/launcher/JavaCommon.cpp
@@ -1,4 +1,5 @@
#include "JavaCommon.h"
+#include "java/JavaUtils.h"
#include "ui/dialogs/CustomMessageBox.h"
#include <MMCStrings.h>
@@ -65,6 +66,13 @@ void JavaCommon::javaBinaryWasBad(QWidget *parent, JavaCheckResult result)
CustomMessageBox::selectable(parent, QObject::tr("Java test failure"), text, QMessageBox::Warning)->show();
}
+void JavaCommon::javaCheckNotFound(QWidget *parent)
+{
+ QString text;
+ text += QObject::tr("Java checker library could not be found. Please check your installation");
+ CustomMessageBox::selectable(parent, QObject::tr("Java test failure"), text, QMessageBox::Warning)->show();
+}
+
void JavaCommon::TestCheck::run()
{
if (!JavaCommon::checkJVMArgs(m_args, m_parent))
@@ -72,6 +80,11 @@ void JavaCommon::TestCheck::run()
emit finished();
return;
}
+ if (JavaUtils::getJavaCheckPath().isEmpty()) {
+ javaCheckNotFound(m_parent);
+ emit finished();
+ return;
+ }
checker.reset(new JavaChecker());
connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this,
SLOT(checkFinished(JavaCheckResult)));
diff --git a/launcher/JavaCommon.h b/launcher/JavaCommon.h
index ca98145c..59cb7a67 100644
--- a/launcher/JavaCommon.h
+++ b/launcher/JavaCommon.h
@@ -10,12 +10,14 @@ namespace JavaCommon
{
bool checkJVMArgs(QString args, QWidget *parent);
- // Show a dialog saying that the Java binary was not usable
- void javaBinaryWasBad(QWidget *parent, JavaCheckResult result);
- // Show a dialog saying that the Java binary was not usable because of bad options
- void javaArgsWereBad(QWidget *parent, JavaCheckResult result);
// Show a dialog saying that the Java binary was usable
void javaWasOk(QWidget *parent, JavaCheckResult result);
+ // Show a dialog saying that the Java binary was not usable because of bad options
+ void javaArgsWereBad(QWidget *parent, JavaCheckResult result);
+ // Show a dialog saying that the Java binary was not usable
+ void javaBinaryWasBad(QWidget *parent, JavaCheckResult result);
+ // Show a dialog if we couldn't find Java Checker
+ void javaCheckNotFound(QWidget *parent);
class TestCheck : public QObject
{
diff --git a/launcher/java/JavaChecker.cpp b/launcher/java/JavaChecker.cpp
index 946599c5..15b22260 100644
--- a/launcher/java/JavaChecker.cpp
+++ b/launcher/java/JavaChecker.cpp
@@ -16,7 +16,13 @@ JavaChecker::JavaChecker(QObject *parent) : QObject(parent)
void JavaChecker::performCheck()
{
- QString checkerJar = FS::PathCombine(APPLICATION->getJarsPath(), "JavaCheck.jar");
+ QString checkerJar = JavaUtils::getJavaCheckPath();
+
+ if (checkerJar.isEmpty())
+ {
+ qDebug() << "Java checker library could not be found. Please check your installation.";
+ return;
+ }
QStringList args;
diff --git a/launcher/java/JavaUtils.cpp b/launcher/java/JavaUtils.cpp
index 65a8b1db..24a1556e 100644
--- a/launcher/java/JavaUtils.cpp
+++ b/launcher/java/JavaUtils.cpp
@@ -24,6 +24,7 @@
#include "java/JavaUtils.h"
#include "java/JavaInstallList.h"
#include "FileSystem.h"
+#include "Application.h"
#define IBUS "@im=ibus"
@@ -437,3 +438,8 @@ QList<QString> JavaUtils::FindJavaPaths()
return addJavasFromEnv(javas);
}
#endif
+
+QString JavaUtils::getJavaCheckPath()
+{
+ return APPLICATION->getJarPath("JavaCheck.jar");
+}
diff --git a/launcher/java/JavaUtils.h b/launcher/java/JavaUtils.h
index 3152d143..26d8003b 100644
--- a/launcher/java/JavaUtils.h
+++ b/launcher/java/JavaUtils.h
@@ -39,4 +39,6 @@ public:
#ifdef Q_OS_WIN
QList<JavaInstallPtr> FindJavaFromRegistryKey(DWORD keyType, QString keyName, QString keyJavaDir, QString subkeySuffix = "");
#endif
+
+ static QString getJavaCheckPath();
};
diff --git a/launcher/launch/steps/CheckJava.cpp b/launcher/launch/steps/CheckJava.cpp
index ef5db2c9..db56b652 100644
--- a/launcher/launch/steps/CheckJava.cpp
+++ b/launcher/launch/steps/CheckJava.cpp
@@ -34,6 +34,7 @@
*/
#include "CheckJava.h"
+#include "java/JavaUtils.h"
#include <launch/LaunchTask.h>
#include <FileSystem.h>
#include <QStandardPaths>
@@ -71,6 +72,14 @@ void CheckJava::executeTask()
emit logLine("Java path is:\n" + m_javaPath + "\n\n", MessageLevel::Launcher);
}
+ if (JavaUtils::getJavaCheckPath().isEmpty())
+ {
+ const char *reason = QT_TR_NOOP("Java checker library could not be found. Please check your installation.");
+ emit logLine(tr(reason), MessageLevel::Fatal);
+ emitFailed(tr(reason));
+ return;
+ }
+
QFileInfo javaInfo(realJavaPath);
qlonglong javaUnixTime = javaInfo.lastModified().toMSecsSinceEpoch();
auto storedUnixTime = settings->get("JavaTimestamp").toLongLong();
diff --git a/launcher/minecraft/launch/LauncherPartLaunch.cpp b/launcher/minecraft/launch/LauncherPartLaunch.cpp
index ea73ba60..9965ef89 100644
--- a/launcher/minecraft/launch/LauncherPartLaunch.cpp
+++ b/launcher/minecraft/launch/LauncherPartLaunch.cpp
@@ -96,6 +96,15 @@ bool fitsInLocal8bit(const QString & string)
void LauncherPartLaunch::executeTask()
{
+ QString jarPath = APPLICATION->getJarPath("NewLaunch.jar");
+ if (jarPath.isEmpty())
+ {
+ const char *reason = QT_TR_NOOP("Launcher library could not be found. Please check your installation.");
+ emit logLine(tr(reason), MessageLevel::Fatal);
+ emitFailed(tr(reason));
+ return;
+ }
+
auto instance = m_parent->instance();
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
@@ -112,7 +121,7 @@ void LauncherPartLaunch::executeTask()
m_process.setDetachable(true);
auto classPath = minecraftInstance->getClassPath();
- classPath.prepend(FS::PathCombine(APPLICATION->getJarsPath(), "NewLaunch.jar"));
+ classPath.prepend(jarPath);
auto natPath = minecraftInstance->getNativePath();
#ifdef Q_OS_WIN
diff --git a/launcher/ui/pages/global/JavaPage.cpp b/launcher/ui/pages/global/JavaPage.cpp
index 025771e8..2cee15bf 100644
--- a/launcher/ui/pages/global/JavaPage.cpp
+++ b/launcher/ui/pages/global/JavaPage.cpp
@@ -127,6 +127,11 @@ void JavaPage::loadSettings()
void JavaPage::on_javaDetectBtn_clicked()
{
+ if (JavaUtils::getJavaCheckPath().isEmpty()) {
+ JavaCommon::javaCheckNotFound(this);
+ return;
+ }
+
JavaInstallPtr java;
VersionSelectDialog vselect(APPLICATION->javalist().get(), tr("Select a Java version"), this, true);
diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp
index 459447c8..1d8cd1d7 100644
--- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp
+++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp
@@ -50,6 +50,7 @@
#include "Application.h"
#include "java/JavaInstallList.h"
+#include "java/JavaUtils.h"
#include "FileSystem.h"
@@ -362,6 +363,11 @@ void InstanceSettingsPage::loadSettings()
void InstanceSettingsPage::on_javaDetectBtn_clicked()
{
+ if (JavaUtils::getJavaCheckPath().isEmpty()) {
+ JavaCommon::javaCheckNotFound(this);
+ return;
+ }
+
JavaInstallPtr java;
VersionSelectDialog vselect(APPLICATION->javalist().get(), tr("Select a Java version"), this, true);
diff --git a/launcher/ui/widgets/JavaSettingsWidget.cpp b/launcher/ui/widgets/JavaSettingsWidget.cpp
index 340518b1..f0765909 100644
--- a/launcher/ui/widgets/JavaSettingsWidget.cpp
+++ b/launcher/ui/widgets/JavaSettingsWidget.cpp
@@ -11,6 +11,7 @@
#include <sys.h>
+#include "JavaCommon.h"
#include "java/JavaInstall.h"
#include "java/JavaUtils.h"
#include "FileSystem.h"
@@ -133,6 +134,10 @@ void JavaSettingsWidget::initialize()
void JavaSettingsWidget::refresh()
{
+ if (JavaUtils::getJavaCheckPath().isEmpty()) {
+ JavaCommon::javaCheckNotFound(this);
+ return;
+ }
m_versionWidget->loadList();
}