MCPcopy Create free account
hub / github.com/PrismLauncher/PrismLauncher / executeTask

Method executeTask

launcher/launch/steps/CheckJava.cpp:44–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42#include "java/JavaUtils.h"
43
44void CheckJava::executeTask()
45{
46 auto instance = m_parent->instance();
47 auto settings = instance->settings();
48
49 QString javaPathSetting = settings->get("JavaPath").toString();
50 m_javaPath = FS::ResolveExecutable(javaPathSetting);
51
52 bool perInstance = settings->get("OverrideJava").toBool() || settings->get("OverrideJavaLocation").toBool();
53
54 auto realJavaPath = QStandardPaths::findExecutable(m_javaPath);
55 if (realJavaPath.isEmpty()) {
56 if (perInstance) {
57 emit logLine(QString("The Java binary \"%1\" couldn't be found. Please fix the Java path "
58 "override in the instance's settings or disable it.")
59 .arg(javaPathSetting),
60 MessageLevel::Warning);
61 } else {
62 emit logLine(QString("The Java binary \"%1\" couldn't be found. Please set up Java in "
63 "the settings.")
64 .arg(javaPathSetting),
65 MessageLevel::Warning);
66 }
67 emitFailed(QString("Java path is not valid."));
68 return;
69 } else {
70 emit logLine("Java path is:\n " + m_javaPath, MessageLevel::Launcher);
71 }
72
73 if (JavaUtils::getJavaCheckPath().isEmpty()) {
74 const char* reason = QT_TR_NOOP("Java checker library could not be found. Please check your installation.");
75 emit logLine(tr(reason), MessageLevel::Fatal);
76 emitFailed(tr(reason));
77 return;
78 }
79
80 QFileInfo javaInfo(realJavaPath);
81 qint64 javaUnixTime = javaInfo.lastModified().toMSecsSinceEpoch();
82 auto storedSignature = settings->get("JavaSignature").toString();
83 auto storedArchitecture = settings->get("JavaArchitecture").toString();
84 auto storedRealArchitecture = settings->get("JavaRealArchitecture").toString();
85 auto storedVersion = settings->get("JavaVersion").toString();
86 auto storedVendor = settings->get("JavaVendor").toString();
87
88 QCryptographicHash hash(QCryptographicHash::Sha1);
89 hash.addData(QByteArray::number(javaUnixTime));
90 hash.addData(m_javaPath.toUtf8());
91 m_javaSignature = hash.result().toHex();
92
93 // if timestamps are not the same, or something is missing, check!
94 if (m_javaSignature != storedSignature || storedVersion.size() == 0 || storedArchitecture.size() == 0 ||
95 storedRealArchitecture.size() == 0 || storedVendor.size() == 0) {
96 m_JavaChecker.reset(new JavaChecker(realJavaPath, "", 0, 0, 0, 0));
97 emit logLine(QString("Checking Java version..."), MessageLevel::Launcher);
98 connect(m_JavaChecker.get(), &JavaChecker::checkFinished, this, &CheckJava::checkJavaFinished);
99 m_JavaChecker->start();
100 return;
101 } else {

Callers

nothing calls this directly

Calls 12

ResolveExecutableFunction · 0.85
QStringClass · 0.50
instanceMethod · 0.45
settingsMethod · 0.45
toStringMethod · 0.45
getMethod · 0.45
isEmptyMethod · 0.45
resultMethod · 0.45
sizeMethod · 0.45
resetMethod · 0.45
startMethod · 0.45
updateRuntimeContextMethod · 0.45

Tested by

no test coverage detected