2022-10-08 19:09:53 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
2023-08-04 18:41:47 +01:00
|
|
|
* Prism Launcher - Minecraft Launcher
|
2022-10-08 19:09:53 +01:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2022-07-11 08:01:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-08-06 23:06:32 +01:00
|
|
|
#include <QSet>
|
2022-07-11 08:01:07 +01:00
|
|
|
#include <QString>
|
|
|
|
#include "settings/SettingsObject.h"
|
|
|
|
|
|
|
|
struct RuntimeContext {
|
|
|
|
QString javaArchitecture;
|
|
|
|
QString javaRealArchitecture;
|
|
|
|
QString javaPath;
|
2022-08-06 23:06:32 +01:00
|
|
|
QString system;
|
2022-07-11 08:01:07 +01:00
|
|
|
|
2022-10-15 11:43:15 +01:00
|
|
|
QString mappedJavaRealArchitecture() const
|
|
|
|
{
|
2022-10-15 11:41:16 +01:00
|
|
|
if (javaRealArchitecture == "amd64")
|
|
|
|
return "x86_64";
|
|
|
|
if (javaRealArchitecture == "i386" || javaRealArchitecture == "i686")
|
|
|
|
return "x86";
|
|
|
|
if (javaRealArchitecture == "aarch64")
|
2022-07-11 08:01:07 +01:00
|
|
|
return "arm64";
|
2022-10-15 11:41:16 +01:00
|
|
|
if (javaRealArchitecture == "arm" || javaRealArchitecture == "armhf")
|
|
|
|
return "arm32";
|
2022-07-11 08:01:07 +01:00
|
|
|
return javaRealArchitecture;
|
|
|
|
}
|
|
|
|
|
2022-10-15 11:43:15 +01:00
|
|
|
void updateFromInstanceSettings(SettingsObjectPtr instanceSettings)
|
|
|
|
{
|
2022-07-11 08:01:07 +01:00
|
|
|
javaArchitecture = instanceSettings->get("JavaArchitecture").toString();
|
|
|
|
javaRealArchitecture = instanceSettings->get("JavaRealArchitecture").toString();
|
|
|
|
javaPath = instanceSettings->get("JavaPath").toString();
|
2022-08-06 23:06:32 +01:00
|
|
|
system = currentSystem();
|
|
|
|
}
|
|
|
|
|
2022-10-15 11:43:15 +01:00
|
|
|
QString getClassifier() const { return system + "-" + mappedJavaRealArchitecture(); }
|
2022-08-06 23:06:32 +01:00
|
|
|
|
|
|
|
// "Legacy" refers to the fact that Mojang assumed that these are the only two architectures
|
2022-10-15 11:43:15 +01:00
|
|
|
bool isLegacyArch() const
|
|
|
|
{
|
2022-10-15 11:41:16 +01:00
|
|
|
const QString mapped = mappedJavaRealArchitecture();
|
|
|
|
return mapped == "x86_64" || mapped == "x86";
|
2022-08-06 23:06:32 +01:00
|
|
|
}
|
|
|
|
|
2022-10-15 11:43:15 +01:00
|
|
|
bool classifierMatches(QString target) const
|
|
|
|
{
|
2022-08-06 23:06:32 +01:00
|
|
|
// try to match precise classifier "[os]-[arch]"
|
|
|
|
bool x = target == getClassifier();
|
|
|
|
// try to match imprecise classifier on legacy architectures "[os]"
|
|
|
|
if (!x && isLegacyArch())
|
|
|
|
x = target == system;
|
|
|
|
|
|
|
|
return x;
|
2022-07-11 08:01:07 +01:00
|
|
|
}
|
|
|
|
|
2022-10-15 11:43:15 +01:00
|
|
|
static QString currentSystem()
|
|
|
|
{
|
2022-07-11 08:01:07 +01:00
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
return "linux";
|
|
|
|
#elif defined(Q_OS_MACOS)
|
|
|
|
return "osx";
|
|
|
|
#elif defined(Q_OS_WINDOWS)
|
|
|
|
return "windows";
|
|
|
|
#elif defined(Q_OS_FREEBSD)
|
|
|
|
return "freebsd";
|
|
|
|
#elif defined(Q_OS_OPENBSD)
|
|
|
|
return "openbsd";
|
|
|
|
#else
|
|
|
|
return "unknown";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|