2022-05-26 22:18:54 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* PolyMC - Minecraft Launcher
|
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
|
|
*
|
|
|
|
* 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, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following copyright and
|
|
|
|
* permission notice:
|
|
|
|
*
|
|
|
|
* Copyright 2013-2021 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-05-04 00:20:48 +01:00
|
|
|
#include "JavaCommon.h"
|
2022-06-14 21:00:24 +01:00
|
|
|
#include "java/JavaUtils.h"
|
2021-11-22 02:55:16 +00:00
|
|
|
#include "ui/dialogs/CustomMessageBox.h"
|
2022-11-03 19:41:55 +00:00
|
|
|
|
2022-05-02 18:48:37 +01:00
|
|
|
#include <QRegularExpression>
|
2015-05-04 00:20:48 +01:00
|
|
|
|
|
|
|
bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget *parent)
|
|
|
|
{
|
2022-05-02 18:48:37 +01:00
|
|
|
if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(QRegularExpression("-Xm[sx]"))
|
2018-07-15 13:51:05 +01:00
|
|
|
|| jvmargs.contains("-XX-MaxHeapSize") || jvmargs.contains("-XX:InitialHeapSize"))
|
|
|
|
{
|
|
|
|
auto warnStr = QObject::tr(
|
2022-03-18 12:19:09 +00:00
|
|
|
"You tried to manually set a JVM memory option (using \"-XX:PermSize\", \"-XX-MaxHeapSize\", \"-XX:InitialHeapSize\", \"-Xmx\" or \"-Xms\").\n"
|
2018-07-15 13:51:05 +01:00
|
|
|
"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;
|
|
|
|
}
|
2022-04-06 21:45:57 +01:00
|
|
|
// block lunacy with passing required version to the JVM
|
2022-05-02 18:48:37 +01:00
|
|
|
if (jvmargs.contains(QRegularExpression("-version:.*"))) {
|
2022-04-06 21:45:57 +01:00
|
|
|
auto warnStr = QObject::tr(
|
2022-04-08 10:16:00 +01:00
|
|
|
"You tried to pass required Java version argument to the JVM (using \"-version:xxx\"). This is not safe and will not be allowed.\n"
|
2022-04-06 21:45:57 +01:00
|
|
|
"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;
|
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
return true;
|
2015-05-04 00:20:48 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 05:52:09 +00:00
|
|
|
void JavaCommon::javaWasOk(QWidget *parent, JavaCheckResult result)
|
2015-05-04 00:20:48 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
QString text;
|
|
|
|
text += QObject::tr("Java test succeeded!<br />Platform reported: %1<br />Java version "
|
2020-09-07 21:28:41 +01:00
|
|
|
"reported: %2<br />Java vendor "
|
|
|
|
"reported: %3<br />").arg(result.realPlatform, result.javaVersion.toString(), result.javaVendor);
|
2018-07-15 13:51:05 +01:00
|
|
|
if (result.errorLog.size())
|
|
|
|
{
|
|
|
|
auto htmlError = result.errorLog;
|
|
|
|
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();
|
2015-05-04 00:20:48 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 05:52:09 +00:00
|
|
|
void JavaCommon::javaArgsWereBad(QWidget *parent, JavaCheckResult result)
|
2015-05-04 00:20:48 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
auto htmlError = result.errorLog;
|
|
|
|
QString text;
|
|
|
|
htmlError.replace('\n', "<br />");
|
2022-03-18 12:19:09 +00:00
|
|
|
text += QObject::tr("The specified Java binary didn't work with the arguments you provided:<br />");
|
2018-07-15 13:51:05 +01:00
|
|
|
text += QString("<font color=\"red\">%1</font>").arg(htmlError);
|
|
|
|
CustomMessageBox::selectable(parent, QObject::tr("Java test failure"), text, QMessageBox::Warning)->show();
|
2015-05-04 00:20:48 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 05:52:09 +00:00
|
|
|
void JavaCommon::javaBinaryWasBad(QWidget *parent, JavaCheckResult result)
|
2015-05-04 00:20:48 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
QString text;
|
|
|
|
text += QObject::tr(
|
2022-03-18 12:19:09 +00:00
|
|
|
"The specified Java binary didn't work.<br />You should use the auto-detect feature, "
|
|
|
|
"or set the path to the Java executable.<br />");
|
2018-07-15 13:51:05 +01:00
|
|
|
CustomMessageBox::selectable(parent, QObject::tr("Java test failure"), text, QMessageBox::Warning)->show();
|
2015-05-04 00:20:48 +01:00
|
|
|
}
|
|
|
|
|
2022-06-14 21:00:24 +01:00
|
|
|
void JavaCommon::javaCheckNotFound(QWidget *parent)
|
|
|
|
{
|
|
|
|
QString text;
|
2022-07-16 20:26:23 +01:00
|
|
|
text += QObject::tr("Java checker library could not be found. Please check your installation.");
|
2022-06-14 21:00:24 +01:00
|
|
|
CustomMessageBox::selectable(parent, QObject::tr("Java test failure"), text, QMessageBox::Warning)->show();
|
|
|
|
}
|
|
|
|
|
2015-05-04 00:20:48 +01:00
|
|
|
void JavaCommon::TestCheck::run()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if (!JavaCommon::checkJVMArgs(m_args, m_parent))
|
|
|
|
{
|
|
|
|
emit finished();
|
|
|
|
return;
|
|
|
|
}
|
2022-06-14 21:00:24 +01:00
|
|
|
if (JavaUtils::getJavaCheckPath().isEmpty()) {
|
|
|
|
javaCheckNotFound(m_parent);
|
|
|
|
emit finished();
|
|
|
|
return;
|
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
checker.reset(new JavaChecker());
|
|
|
|
connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this,
|
|
|
|
SLOT(checkFinished(JavaCheckResult)));
|
|
|
|
checker->m_path = m_path;
|
|
|
|
checker->performCheck();
|
2015-05-04 00:20:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void JavaCommon::TestCheck::checkFinished(JavaCheckResult result)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if (result.validity != JavaCheckResult::Validity::Valid)
|
|
|
|
{
|
|
|
|
javaBinaryWasBad(m_parent, result);
|
|
|
|
emit finished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
checker.reset(new JavaChecker());
|
|
|
|
connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this,
|
|
|
|
SLOT(checkFinishedWithArgs(JavaCheckResult)));
|
|
|
|
checker->m_path = m_path;
|
|
|
|
checker->m_args = m_args;
|
|
|
|
checker->m_minMem = m_minMem;
|
|
|
|
checker->m_maxMem = m_maxMem;
|
|
|
|
if (result.javaVersion.requiresPermGen())
|
|
|
|
{
|
|
|
|
checker->m_permGen = m_permGen;
|
|
|
|
}
|
|
|
|
checker->performCheck();
|
2015-05-04 00:20:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void JavaCommon::TestCheck::checkFinishedWithArgs(JavaCheckResult result)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if (result.validity == JavaCheckResult::Validity::Valid)
|
|
|
|
{
|
|
|
|
javaWasOk(m_parent, result);
|
|
|
|
emit finished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
javaArgsWereBad(m_parent, result);
|
|
|
|
emit finished();
|
2015-05-04 00:20:48 +01:00
|
|
|
}
|
2017-04-30 14:12:46 +01:00
|
|
|
|