aboutsummaryrefslogtreecommitdiff
path: root/launcher/RuntimeContext.h
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-10-08 20:12:40 +0200
committerGitHub <noreply@github.com>2022-10-08 20:12:40 +0200
commitfafc9cf9ca86fd66db09e9ccc1cdb53520fd7c16 (patch)
tree61de3976ba124736c1ad5d10f5d9c8b17537f394 /launcher/RuntimeContext.h
parente436f471a074401be3a48f19eff577c040e9b192 (diff)
parent3111e6a7212ae914041fce6d851d7662975dc1be (diff)
downloadPrismLauncher-fafc9cf9ca86fd66db09e9ccc1cdb53520fd7c16.tar.gz
PrismLauncher-fafc9cf9ca86fd66db09e9ccc1cdb53520fd7c16.tar.bz2
PrismLauncher-fafc9cf9ca86fd66db09e9ccc1cdb53520fd7c16.zip
Merge pull request #1033 from Scrumplex/multi-arch-support
Diffstat (limited to 'launcher/RuntimeContext.h')
-rw-r--r--launcher/RuntimeContext.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/launcher/RuntimeContext.h b/launcher/RuntimeContext.h
new file mode 100644
index 00000000..c1b71318
--- /dev/null
+++ b/launcher/RuntimeContext.h
@@ -0,0 +1,80 @@
+// 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/>.
+ */
+
+#pragma once
+
+#include <QSet>
+#include <QString>
+#include "settings/SettingsObject.h"
+
+struct RuntimeContext {
+ QString javaArchitecture;
+ QString javaRealArchitecture;
+ QString javaPath;
+ QString system;
+
+ QString mappedJavaRealArchitecture() const {
+ if (javaRealArchitecture == "aarch64") {
+ return "arm64";
+ }
+ return javaRealArchitecture;
+ }
+
+ void updateFromInstanceSettings(SettingsObjectPtr instanceSettings) {
+ javaArchitecture = instanceSettings->get("JavaArchitecture").toString();
+ javaRealArchitecture = instanceSettings->get("JavaRealArchitecture").toString();
+ javaPath = instanceSettings->get("JavaPath").toString();
+ system = currentSystem();
+ }
+
+ QString getClassifier() const {
+ return system + "-" + mappedJavaRealArchitecture();
+ }
+
+ // "Legacy" refers to the fact that Mojang assumed that these are the only two architectures
+ bool isLegacyArch() const {
+ QSet<QString> legacyArchitectures{"amd64", "x86_64", "i386", "i686", "x86"};
+ return legacyArchitectures.contains(mappedJavaRealArchitecture());
+ }
+
+ bool classifierMatches(QString target) const {
+ // 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;
+ }
+
+ static QString currentSystem() {
+#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
+ }
+};