1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2026 Project Tick
// SPDX-FileContributor: Project Tick Team
/*
* ProjT Launcher - Minecraft Launcher
* Copyright (C) 2026 Project Tick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "JavaCommon.h"
#include "java/services/RuntimeProbeTask.hpp"
#include "ui/dialogs/CustomMessageBox.h"
#include <QRegularExpression>
bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget* parent)
{
static const QRegularExpression s_memRegex("-Xm[sx]");
static const QRegularExpression s_versionRegex("-version:.*");
if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(s_memRegex) || jvmargs.contains("-XX-MaxHeapSize")
|| jvmargs.contains("-XX:InitialHeapSize"))
{
auto warnStr = QObject::tr(
"You tried to manually set a JVM memory option (using \"-XX:PermSize\", \"-XX-MaxHeapSize\", "
"\"-XX:InitialHeapSize\", \"-Xmx\" "
"or \"-Xms\").\n"
"There are dedicated boxes for these in the settings (Java tab, in the Memory group at the top).\n"
"This message will be displayed until you remove them from the JVM arguments.");
CustomMessageBox::selectable(parent, QObject::tr("JVM arguments warning"), warnStr, QMessageBox::Warning)
->exec();
return false;
}
// block lunacy with passing required version to the JVM
if (jvmargs.contains(s_versionRegex))
{
auto warnStr = QObject::tr("You tried to pass required Java version argument to the JVM (using "
"\"-version:xxx\"). This is not safe and will not be "
"allowed.\n"
"This message will be displayed until you remove this from the JVM arguments.");
CustomMessageBox::selectable(parent, QObject::tr("JVM arguments warning"), warnStr, QMessageBox::Warning)
->exec();
return false;
}
return true;
}
void JavaCommon::javaWasOk(QWidget* parent, const projt::java::RuntimeProbeTask::ProbeReport& result)
{
QString text;
text += QObject::tr("Java test succeeded!<br />Platform reported: %1<br />Java version "
"reported: %2<br />Java vendor "
"reported: %3<br />")
.arg(result.platformArch, result.version.toString(), result.vendor);
if (result.stderrLog.size())
{
auto htmlError = result.stderrLog;
htmlError.replace('\n', "<br />");
text += QObject::tr("<br />Warnings:<br /><font color=\"orange\">%1</font>").arg(htmlError);
}
CustomMessageBox::selectable(parent, QObject::tr("Java test success"), text, QMessageBox::Information)->show();
}
void JavaCommon::javaArgsWereBad(QWidget* parent, const projt::java::RuntimeProbeTask::ProbeReport& result)
{
auto htmlError = result.stderrLog;
QString text;
htmlError.replace('\n', "<br />");
text += QObject::tr("The specified Java binary didn't work with the arguments you provided:<br />");
text += QString("<font color=\"red\">%1</font>").arg(htmlError);
CustomMessageBox::selectable(parent, QObject::tr("Java test failure"), text, QMessageBox::Warning)->show();
}
void JavaCommon::javaBinaryWasBad(QWidget* parent, const projt::java::RuntimeProbeTask::ProbeReport& result)
{
QString text;
text += QObject::tr("The specified Java binary didn't work.<br />You should press 'Detect', "
"or set the path to the Java executable.<br />");
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))
{
emit finished();
return;
}
if (projt::java::RuntimeProbeTask::probeJarPath().isEmpty())
{
javaCheckNotFound(m_parent);
emit finished();
return;
}
projt::java::RuntimeProbeTask::ProbeSettings settings;
settings.binaryPath = m_path;
checker.reset(new projt::java::RuntimeProbeTask(settings));
connect(checker.get(), &projt::java::RuntimeProbeTask::probeFinished, this, &JavaCommon::TestCheck::checkFinished);
checker->start();
}
void JavaCommon::TestCheck::checkFinished(const projt::java::RuntimeProbeTask::ProbeReport& result)
{
if (result.status != projt::java::RuntimeProbeTask::ProbeReport::Status::Valid)
{
javaBinaryWasBad(m_parent, result);
emit finished();
return;
}
projt::java::RuntimeProbeTask::ProbeSettings settings;
settings.binaryPath = m_path;
settings.extraArgs = m_args;
settings.minMem = m_minMem;
settings.maxMem = m_maxMem;
settings.permGen = result.version.needsPermGen() ? m_permGen : 0;
checker.reset(new projt::java::RuntimeProbeTask(settings));
connect(checker.get(),
&projt::java::RuntimeProbeTask::probeFinished,
this,
&JavaCommon::TestCheck::checkFinishedWithArgs);
checker->start();
}
void JavaCommon::TestCheck::checkFinishedWithArgs(const projt::java::RuntimeProbeTask::ProbeReport& result)
{
if (result.status == projt::java::RuntimeProbeTask::ProbeReport::Status::Valid)
{
javaWasOk(m_parent, result);
emit finished();
return;
}
javaArgsWereBad(m_parent, result);
emit finished();
}
|