refactor: introduce RuntimeContext

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-07-11 09:01:07 +02:00
parent 9ec1c00887
commit 09e85e948c
No known key found for this signature in database
GPG Key ID: C10411294912A422
26 changed files with 152 additions and 169 deletions

View File

@ -358,3 +358,8 @@ shared_qobject_ptr<LaunchTask> BaseInstance::getLaunchTask()
{ {
return m_launchProcess; return m_launchProcess;
} }
void BaseInstance::updateRuntimeContext()
{
// NOOP
}

View File

@ -54,6 +54,7 @@
#include "net/Mode.h" #include "net/Mode.h"
#include "minecraft/launch/MinecraftServerTarget.h" #include "minecraft/launch/MinecraftServerTarget.h"
#include "RuntimeContext.h"
class QDir; class QDir;
class Task; class Task;
@ -219,6 +220,12 @@ public:
virtual QString typeName() const = 0; virtual QString typeName() const = 0;
void updateRuntimeContext();
RuntimeContext runtimeContext() const
{
return m_runtimeContext;
}
bool hasVersionBroken() const bool hasVersionBroken() const
{ {
return m_hasBrokenVersion; return m_hasBrokenVersion;
@ -304,6 +311,7 @@ protected: /* data */
bool m_isRunning = false; bool m_isRunning = false;
shared_qobject_ptr<LaunchTask> m_launchProcess; shared_qobject_ptr<LaunchTask> m_launchProcess;
QDateTime m_timeStarted; QDateTime m_timeStarted;
RuntimeContext m_runtimeContext;
private: /* data */ private: /* data */
Status m_status = Status::Present; Status m_status = Status::Present;

View File

@ -26,6 +26,7 @@ set(CORE_SOURCES
MMCZip.cpp MMCZip.cpp
MMCStrings.h MMCStrings.h
MMCStrings.cpp MMCStrings.cpp
RuntimeContext.h
# Basic instance manipulation tasks (derived from InstanceTask) # Basic instance manipulation tasks (derived from InstanceTask)
InstanceCreationTask.h InstanceCreationTask.h
@ -288,8 +289,6 @@ set(MINECRAFT_SOURCES
minecraft/Rule.h minecraft/Rule.h
minecraft/OneSixVersionFormat.cpp minecraft/OneSixVersionFormat.cpp
minecraft/OneSixVersionFormat.h minecraft/OneSixVersionFormat.h
minecraft/OpSys.cpp
minecraft/OpSys.h
minecraft/ParseUtils.cpp minecraft/ParseUtils.cpp
minecraft/ParseUtils.h minecraft/ParseUtils.h
minecraft/ProfileUtils.cpp minecraft/ProfileUtils.cpp

View File

@ -84,4 +84,8 @@ public:
QString modsRoot() const override { QString modsRoot() const override {
return QString(); return QString();
} }
void updateRuntimeContext()
{
// NOOP
}
}; };

39
launcher/RuntimeContext.h Normal file
View File

@ -0,0 +1,39 @@
#pragma once
#include <QString>
#include "settings/SettingsObject.h"
struct RuntimeContext {
QString javaArchitecture;
QString javaRealArchitecture;
QString javaPath;
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();
}
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
}
};

View File

@ -60,7 +60,7 @@ void Component::applyTo(LaunchProfile* profile)
auto vfile = getVersionFile(); auto vfile = getVersionFile();
if(vfile) if(vfile)
{ {
vfile->applyTo(profile); vfile->applyTo(profile, m_parent->runtimeContext());
} }
else else
{ {

View File

@ -173,9 +173,9 @@ void LaunchProfile::applyCompatibleJavaMajors(QList<int>& javaMajor)
m_compatibleJavaMajors.append(javaMajor); m_compatibleJavaMajors.append(javaMajor);
} }
void LaunchProfile::applyLibrary(LibraryPtr library) void LaunchProfile::applyLibrary(LibraryPtr library, const RuntimeContext & runtimeContext)
{ {
if(!library->isActive()) if(!library->isActive(runtimeContext))
{ {
return; return;
} }
@ -205,9 +205,9 @@ void LaunchProfile::applyLibrary(LibraryPtr library)
} }
} }
void LaunchProfile::applyMavenFile(LibraryPtr mavenFile) void LaunchProfile::applyMavenFile(LibraryPtr mavenFile, const RuntimeContext & runtimeContext)
{ {
if(!mavenFile->isActive()) if(!mavenFile->isActive(runtimeContext))
{ {
return; return;
} }
@ -221,10 +221,10 @@ void LaunchProfile::applyMavenFile(LibraryPtr mavenFile)
m_mavenFiles.append(Library::limitedCopy(mavenFile)); m_mavenFiles.append(Library::limitedCopy(mavenFile));
} }
void LaunchProfile::applyAgent(AgentPtr agent) void LaunchProfile::applyAgent(AgentPtr agent, const RuntimeContext & runtimeContext)
{ {
auto lib = agent->library(); auto lib = agent->library();
if(!lib->isActive()) if(!lib->isActive(runtimeContext))
{ {
return; return;
} }
@ -354,7 +354,7 @@ const QList<int> & LaunchProfile::getCompatibleJavaMajors() const
} }
void LaunchProfile::getLibraryFiles( void LaunchProfile::getLibraryFiles(
const QString& architecture, const RuntimeContext & runtimeContext,
QStringList& jars, QStringList& jars,
QStringList& nativeJars, QStringList& nativeJars,
const QString& overridePath, const QString& overridePath,
@ -366,7 +366,7 @@ void LaunchProfile::getLibraryFiles(
nativeJars.clear(); nativeJars.clear();
for (auto lib : getLibraries()) for (auto lib : getLibraries())
{ {
lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath); lib->getApplicableFiles(runtimeContext, jars, nativeJars, native32, native64, overridePath);
} }
// NOTE: order is important here, add main jar last to the lists // NOTE: order is important here, add main jar last to the lists
if(m_mainJar) if(m_mainJar)
@ -379,18 +379,18 @@ void LaunchProfile::getLibraryFiles(
} }
else else
{ {
m_mainJar->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath); m_mainJar->getApplicableFiles(runtimeContext, jars, nativeJars, native32, native64, overridePath);
} }
} }
for (auto lib : getNativeLibraries()) for (auto lib : getNativeLibraries())
{ {
lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath); lib->getApplicableFiles(runtimeContext, jars, nativeJars, native32, native64, overridePath);
} }
if(architecture == "32") if(runtimeContext.javaArchitecture == "32")
{ {
nativeJars.append(native32); nativeJars.append(native32);
} }
else if(architecture == "64") else if(runtimeContext.javaArchitecture == "64")
{ {
nativeJars.append(native64); nativeJars.append(native64);
} }

View File

@ -56,9 +56,9 @@ public: /* application of profile variables from patches */
void applyTweakers(const QStringList &tweakers); void applyTweakers(const QStringList &tweakers);
void applyJarMods(const QList<LibraryPtr> &jarMods); void applyJarMods(const QList<LibraryPtr> &jarMods);
void applyMods(const QList<LibraryPtr> &jarMods); void applyMods(const QList<LibraryPtr> &jarMods);
void applyLibrary(LibraryPtr library); void applyLibrary(LibraryPtr library, const RuntimeContext & runtimeContext);
void applyMavenFile(LibraryPtr library); void applyMavenFile(LibraryPtr library, const RuntimeContext & runtimeContext);
void applyAgent(AgentPtr agent); void applyAgent(AgentPtr agent, const RuntimeContext & runtimeContext);
void applyCompatibleJavaMajors(QList<int>& javaMajor); void applyCompatibleJavaMajors(QList<int>& javaMajor);
void applyMainJar(LibraryPtr jar); void applyMainJar(LibraryPtr jar);
void applyProblemSeverity(ProblemSeverity severity); void applyProblemSeverity(ProblemSeverity severity);
@ -83,7 +83,7 @@ public: /* getters for profile variables */
const QList<int> & getCompatibleJavaMajors() const; const QList<int> & getCompatibleJavaMajors() const;
const LibraryPtr getMainJar() const; const LibraryPtr getMainJar() const;
void getLibraryFiles( void getLibraryFiles(
const QString & architecture, const RuntimeContext & runtimeContext,
QStringList & jars, QStringList & jars,
QStringList & nativeJars, QStringList & nativeJars,
const QString & overridePath, const QString & overridePath,

View File

@ -7,7 +7,7 @@
#include <BuildConfig.h> #include <BuildConfig.h>
void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& native, QStringList& native32, void Library::getApplicableFiles(const RuntimeContext & runtimeContext, QStringList& jar, QStringList& native, QStringList& native32,
QStringList& native64, const QString &overridePath) const QStringList& native64, const QString &overridePath) const
{ {
bool local = isLocal(); bool local = isLocal();
@ -21,7 +21,7 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na
} }
return out.absoluteFilePath(); return out.absoluteFilePath();
}; };
QString raw_storage = storageSuffix(system); QString raw_storage = storageSuffix(runtimeContext);
if(isNative()) if(isNative())
{ {
if (raw_storage.contains("${arch}")) if (raw_storage.contains("${arch}"))
@ -45,7 +45,7 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na
} }
QList<NetAction::Ptr> Library::getDownloads( QList<NetAction::Ptr> Library::getDownloads(
OpSys system, const RuntimeContext & runtimeContext,
class HttpMetaCache* cache, class HttpMetaCache* cache,
QStringList& failedLocalFiles, QStringList& failedLocalFiles,
const QString & overridePath const QString & overridePath
@ -107,14 +107,14 @@ QList<NetAction::Ptr> Library::getDownloads(
return true; return true;
}; };
QString raw_storage = storageSuffix(system); QString raw_storage = storageSuffix(runtimeContext);
if(m_mojangDownloads) if(m_mojangDownloads)
{ {
if(isNative()) if(isNative())
{ {
if(m_nativeClassifiers.contains(system)) if(m_nativeClassifiers.contains(runtimeContext.currentSystem()))
{ {
auto nativeClassifier = m_nativeClassifiers[system]; auto nativeClassifier = m_nativeClassifiers[runtimeContext.currentSystem()];
if(nativeClassifier.contains("${arch}")) if(nativeClassifier.contains("${arch}"))
{ {
auto nat32Classifier = nativeClassifier; auto nat32Classifier = nativeClassifier;
@ -203,7 +203,7 @@ QList<NetAction::Ptr> Library::getDownloads(
return out; return out;
} }
bool Library::isActive() const bool Library::isActive(const RuntimeContext & runtimeContext) const
{ {
bool result = true; bool result = true;
if (m_rules.empty()) if (m_rules.empty())
@ -223,7 +223,7 @@ bool Library::isActive() const
} }
if (isNative()) if (isNative())
{ {
result = result && m_nativeClassifiers.contains(currentSystem); result = result && m_nativeClassifiers.contains(runtimeContext.currentSystem());
} }
return result; return result;
} }
@ -257,7 +257,7 @@ QString Library::storagePrefix() const
return m_storagePrefix; return m_storagePrefix;
} }
QString Library::filename(OpSys system) const QString Library::filename(const RuntimeContext & runtimeContext) const
{ {
if(!m_filename.isEmpty()) if(!m_filename.isEmpty())
{ {
@ -271,9 +271,9 @@ QString Library::filename(OpSys system) const
// otherwise native, override classifiers. Mojang HACK! // otherwise native, override classifiers. Mojang HACK!
GradleSpecifier nativeSpec = m_name; GradleSpecifier nativeSpec = m_name;
if (m_nativeClassifiers.contains(system)) if (m_nativeClassifiers.contains(runtimeContext.currentSystem()))
{ {
nativeSpec.setClassifier(m_nativeClassifiers[system]); nativeSpec.setClassifier(m_nativeClassifiers[runtimeContext.currentSystem()]);
} }
else else
{ {
@ -282,14 +282,14 @@ QString Library::filename(OpSys system) const
return nativeSpec.getFileName(); return nativeSpec.getFileName();
} }
QString Library::displayName(OpSys system) const QString Library::displayName(const RuntimeContext & runtimeContext) const
{ {
if(!m_displayname.isEmpty()) if(!m_displayname.isEmpty())
return m_displayname; return m_displayname;
return filename(system); return filename(runtimeContext);
} }
QString Library::storageSuffix(OpSys system) const QString Library::storageSuffix(const RuntimeContext & runtimeContext) const
{ {
// non-native? use only the gradle specifier // non-native? use only the gradle specifier
if (!isNative()) if (!isNative())
@ -299,9 +299,9 @@ QString Library::storageSuffix(OpSys system) const
// otherwise native, override classifiers. Mojang HACK! // otherwise native, override classifiers. Mojang HACK!
GradleSpecifier nativeSpec = m_name; GradleSpecifier nativeSpec = m_name;
if (m_nativeClassifiers.contains(system)) if (m_nativeClassifiers.contains(runtimeContext.currentSystem()))
{ {
nativeSpec.setClassifier(m_nativeClassifiers[system]); nativeSpec.setClassifier(m_nativeClassifiers[runtimeContext.currentSystem()]);
} }
else else
{ {

View File

@ -10,9 +10,9 @@
#include <memory> #include <memory>
#include "Rule.h" #include "Rule.h"
#include "minecraft/OpSys.h"
#include "GradleSpecifier.h" #include "GradleSpecifier.h"
#include "MojangDownloadInfo.h" #include "MojangDownloadInfo.h"
#include "RuntimeContext.h"
class Library; class Library;
class MinecraftInstance; class MinecraftInstance;
@ -98,7 +98,7 @@ public: /* methods */
m_repositoryURL = base_url; m_repositoryURL = base_url;
} }
void getApplicableFiles(OpSys system, QStringList & jar, QStringList & native, void getApplicableFiles(const RuntimeContext & runtimeContext, QStringList & jar, QStringList & native,
QStringList & native32, QStringList & native64, const QString & overridePath) const; QStringList & native32, QStringList & native64, const QString & overridePath) const;
void setAbsoluteUrl(const QString &absolute_url) void setAbsoluteUrl(const QString &absolute_url)
@ -112,7 +112,7 @@ public: /* methods */
} }
/// Get the file name of the library /// Get the file name of the library
QString filename(OpSys system) const; QString filename(const RuntimeContext & runtimeContext) const;
// DEPRECATED: set a display name, used by jar mods only // DEPRECATED: set a display name, used by jar mods only
void setDisplayName(const QString & displayName) void setDisplayName(const QString & displayName)
@ -121,7 +121,7 @@ public: /* methods */
} }
/// Get the file name of the library /// Get the file name of the library
QString displayName(OpSys system) const; QString displayName(const RuntimeContext & runtimeContext) const;
void setMojangDownloadInfo(MojangLibraryDownloadInfo::Ptr info) void setMojangDownloadInfo(MojangLibraryDownloadInfo::Ptr info)
{ {
@ -140,7 +140,7 @@ public: /* methods */
} }
/// Returns true if the library should be loaded (or extracted, in case of natives) /// Returns true if the library should be loaded (or extracted, in case of natives)
bool isActive() const; bool isActive(const RuntimeContext & runtimeContext) const;
/// Returns true if the library is contained in an instance and false if it is shared /// Returns true if the library is contained in an instance and false if it is shared
bool isLocal() const; bool isLocal() const;
@ -152,7 +152,7 @@ public: /* methods */
bool isForge() const; bool isForge() const;
// Get a list of downloads for this library // Get a list of downloads for this library
QList<NetAction::Ptr> getDownloads(OpSys system, class HttpMetaCache * cache, QList<NetAction::Ptr> getDownloads(const RuntimeContext & runtimeContext, class HttpMetaCache * cache,
QStringList & failedLocalFiles, const QString & overridePath) const; QStringList & failedLocalFiles, const QString & overridePath) const;
private: /* methods */ private: /* methods */
@ -163,7 +163,7 @@ private: /* methods */
QString storagePrefix() const; QString storagePrefix() const;
/// Get the relative file path where the library should be saved /// Get the relative file path where the library should be saved
QString storageSuffix(OpSys system) const; QString storageSuffix(const RuntimeContext & runtimeContext) const;
QString hint() const QString hint() const
{ {
@ -204,7 +204,7 @@ protected: /* data */
QStringList m_extractExcludes; QStringList m_extractExcludes;
/// native suffixes per OS /// native suffixes per OS
QMap<OpSys, QString> m_nativeClassifiers; QMap<QString, QString> m_nativeClassifiers;
/// true if the library had a rules section (even empty) /// true if the library had a rules section (even empty)
bool applyRules = false; bool applyRules = false;

View File

@ -191,6 +191,13 @@ void MinecraftInstance::loadSpecificSettings()
qDebug() << "Instance-type specific settings were loaded!"; qDebug() << "Instance-type specific settings were loaded!";
setSpecificSettingsLoaded(true); setSpecificSettingsLoaded(true);
updateRuntimeContext();
}
void MinecraftInstance::updateRuntimeContext()
{
m_runtimeContext.updateFromInstanceSettings(m_settings);
} }
QString MinecraftInstance::typeName() const QString MinecraftInstance::typeName() const
@ -328,9 +335,8 @@ QDir MinecraftInstance::versionsPath() const
QStringList MinecraftInstance::getClassPath() QStringList MinecraftInstance::getClassPath()
{ {
QStringList jars, nativeJars; QStringList jars, nativeJars;
auto javaArchitecture = settings()->get("JavaArchitecture").toString();
auto profile = m_components->getProfile(); auto profile = m_components->getProfile();
profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); profile->getLibraryFiles(runtimeContext(), jars, nativeJars, getLocalLibraryPath(), binRoot());
return jars; return jars;
} }
@ -343,9 +349,8 @@ QString MinecraftInstance::getMainClass() const
QStringList MinecraftInstance::getNativeJars() QStringList MinecraftInstance::getNativeJars()
{ {
QStringList jars, nativeJars; QStringList jars, nativeJars;
auto javaArchitecture = settings()->get("JavaArchitecture").toString();
auto profile = m_components->getProfile(); auto profile = m_components->getProfile();
profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); profile->getLibraryFiles(runtimeContext(), jars, nativeJars, getLocalLibraryPath(), binRoot());
return nativeJars; return nativeJars;
} }
@ -369,7 +374,7 @@ QStringList MinecraftInstance::extraArguments()
for (auto agent : agents) for (auto agent : agents)
{ {
QStringList jar, temp1, temp2, temp3; QStringList jar, temp1, temp2, temp3;
agent->library()->getApplicableFiles(currentSystem, jar, temp1, temp2, temp3, getLocalLibraryPath()); agent->library()->getApplicableFiles(runtimeContext(), jar, temp1, temp2, temp3, getLocalLibraryPath());
list.append("-javaagent:"+jar[0]+(agent->argument().isEmpty() ? "" : "="+agent->argument())); list.append("-javaagent:"+jar[0]+(agent->argument().isEmpty() ? "" : "="+agent->argument()));
} }
return list; return list;
@ -626,8 +631,7 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS
// libraries and class path. // libraries and class path.
{ {
QStringList jars, nativeJars; QStringList jars, nativeJars;
auto javaArchitecture = settings()->get("JavaArchitecture").toString(); profile->getLibraryFiles(runtimeContext(), jars, nativeJars, getLocalLibraryPath(), binRoot());
profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot());
for(auto file: jars) for(auto file: jars)
{ {
launchScript += "cp " + file + "\n"; launchScript += "cp " + file + "\n";
@ -683,8 +687,7 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr
{ {
out << "Libraries:"; out << "Libraries:";
QStringList jars, nativeJars; QStringList jars, nativeJars;
auto javaArchitecture = settings->get("JavaArchitecture").toString(); profile->getLibraryFiles(runtimeContext(), jars, nativeJars, getLocalLibraryPath(), binRoot());
profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot());
auto printLibFile = [&](const QString & path) auto printLibFile = [&](const QString & path)
{ {
QFileInfo info(path); QFileInfo info(path);
@ -749,8 +752,8 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr
out << "Jar Mods:"; out << "Jar Mods:";
for(auto & jarmod: jarMods) for(auto & jarmod: jarMods)
{ {
auto displayname = jarmod->displayName(currentSystem); auto displayname = jarmod->displayName(runtimeContext());
auto realname = jarmod->filename(currentSystem); auto realname = jarmod->filename(runtimeContext());
if(displayname != realname) if(displayname != realname)
{ {
out << " " + displayname + " (" + realname + ")"; out << " " + displayname + " (" + realname + ")";
@ -912,6 +915,7 @@ QString MinecraftInstance::getStatusbarDescription()
Task::Ptr MinecraftInstance::createUpdateTask(Net::Mode mode) Task::Ptr MinecraftInstance::createUpdateTask(Net::Mode mode)
{ {
updateRuntimeContext();
switch (mode) switch (mode)
{ {
case Net::Mode::Offline: case Net::Mode::Offline:
@ -928,6 +932,7 @@ Task::Ptr MinecraftInstance::createUpdateTask(Net::Mode mode)
shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin) shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin)
{ {
updateRuntimeContext();
// FIXME: get rid of shared_from_this ... // FIXME: get rid of shared_from_this ...
auto process = LaunchTask::create(std::dynamic_pointer_cast<MinecraftInstance>(shared_from_this())); auto process = LaunchTask::create(std::dynamic_pointer_cast<MinecraftInstance>(shared_from_this()));
auto pptr = process.get(); auto pptr = process.get();
@ -1158,7 +1163,7 @@ QList<Mod*> MinecraftInstance::getJarMods() const
for (auto jarmod : profile->getJarMods()) for (auto jarmod : profile->getJarMods())
{ {
QStringList jar, temp1, temp2, temp3; QStringList jar, temp1, temp2, temp3;
jarmod->getApplicableFiles(currentSystem, jar, temp1, temp2, temp3, jarmodsPath().absolutePath()); jarmod->getApplicableFiles(runtimeContext(), jar, temp1, temp2, temp3, jarmodsPath().absolutePath());
// QString filePath = jarmodsPath().absoluteFilePath(jarmod->filename(currentSystem)); // QString filePath = jarmodsPath().absoluteFilePath(jarmod->filename(currentSystem));
mods.push_back(new Mod(QFileInfo(jar[0]))); mods.push_back(new Mod(QFileInfo(jar[0])));
} }

View File

@ -72,6 +72,8 @@ public:
/** Returns whether the instance, with its version, has support for demo mode. */ /** Returns whether the instance, with its version, has support for demo mode. */
[[nodiscard]] bool supportsDemo() const; [[nodiscard]] bool supportsDemo() const;
void updateRuntimeContext();
////// Profile management ////// ////// Profile management //////
std::shared_ptr<PackProfile> getPackProfile() const; std::shared_ptr<PackProfile> getPackProfile() const;

View File

@ -362,11 +362,8 @@ LibraryPtr MojangVersionFormat::libraryFromJson(ProblemContainer & problems, con
{ {
qWarning() << filename << "contains an invalid native (skipping)"; qWarning() << filename << "contains an invalid native (skipping)";
} }
OpSys opSys = OpSys_fromString(it.key()); // FIXME: Skip unknown platforms
if (opSys != Os_Other) out->m_nativeClassifiers[it.key()] = it.value().toString();
{
out->m_nativeClassifiers[opSys] = it.value().toString();
}
} }
} }
if (libObj.contains("rules")) if (libObj.contains("rules"))
@ -395,7 +392,7 @@ QJsonObject MojangVersionFormat::libraryToJson(Library *library)
auto iter = library->m_nativeClassifiers.begin(); auto iter = library->m_nativeClassifiers.begin();
while (iter != library->m_nativeClassifiers.end()) while (iter != library->m_nativeClassifiers.end())
{ {
nativeList.insert(OpSys_toString(iter.key()), iter.value()); nativeList.insert(iter.key(), iter.value());
iter++; iter++;
} }
libRoot.insert("natives", nativeList); libRoot.insert("natives", nativeList);

View File

@ -1,46 +0,0 @@
/* 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.
*/
#include "OpSys.h"
OpSys OpSys_fromString(QString name)
{
if (name == "freebsd")
return Os_FreeBSD;
if (name == "linux")
return Os_Linux;
if (name == "windows")
return Os_Windows;
if (name == "osx")
return Os_OSX;
return Os_Other;
}
QString OpSys_toString(OpSys name)
{
switch (name)
{
case Os_FreeBSD:
return "freebsd";
case Os_Linux:
return "linux";
case Os_OSX:
return "osx";
case Os_Windows:
return "windows";
default:
return "other";
}
}

View File

@ -1,38 +0,0 @@
/* 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.
*/
#pragma once
#include <QString>
enum OpSys
{
Os_Windows,
Os_FreeBSD,
Os_Linux,
Os_OSX,
Os_Other
};
OpSys OpSys_fromString(QString);
QString OpSys_toString(OpSys);
#ifdef Q_OS_WIN32
#define currentSystem Os_Windows
#elif defined Q_OS_MAC
#define currentSystem Os_OSX
#elif defined Q_OS_FREEBSD
#define currentSystem Os_FreeBSD
#else
#define currentSystem Os_Linux
#endif

View File

@ -273,6 +273,11 @@ void PackProfile::scheduleSave()
d->m_saveTimer.start(); d->m_saveTimer.start();
} }
RuntimeContext PackProfile::runtimeContext()
{
return d->m_instance->runtimeContext();
}
QString PackProfile::componentsFilePath() const QString PackProfile::componentsFilePath() const
{ {
return FS::PathCombine(d->m_instance->instanceRoot(), "mmc-pack.json"); return FS::PathCombine(d->m_instance->instanceRoot(), "mmc-pack.json");
@ -784,7 +789,7 @@ bool PackProfile::removeComponent_internal(ComponentPtr patch)
return true; return true;
} }
QStringList jar, temp1, temp2, temp3; QStringList jar, temp1, temp2, temp3;
jarMod->getApplicableFiles(currentSystem, jar, temp1, temp2, temp3, d->m_instance->jarmodsPath().absolutePath()); jarMod->getApplicableFiles(d->m_instance->runtimeContext(), jar, temp1, temp2, temp3, d->m_instance->jarmodsPath().absolutePath());
QFileInfo finfo (jar[0]); QFileInfo finfo (jar[0]);
if(finfo.exists()) if(finfo.exists())
{ {

View File

@ -104,6 +104,9 @@ public:
/// if there is a save scheduled, do it now. /// if there is a save scheduled, do it now.
void saveNow(); void saveNow();
/// helper method, returns RuntimeContext of instance
RuntimeContext runtimeContext();
signals: signals:
void minecraftChanged(); void minecraftChanged();

View File

@ -60,10 +60,10 @@ QList<std::shared_ptr<Rule>> rulesFromJsonV4(const QJsonObject &objectWithRules)
auto osNameVal = osObj.value("name"); auto osNameVal = osObj.value("name");
if (!osNameVal.isString()) if (!osNameVal.isString())
continue; continue;
OpSys requiredOs = OpSys_fromString(osNameVal.toString()); QString osName = osNameVal.toString();
QString versionRegex = osObj.value("version").toString(); QString versionRegex = osObj.value("version").toString();
// add a new OS rule // add a new OS rule
rules.append(OsRule::create(action, requiredOs, versionRegex)); rules.append(OsRule::create(action, osName, versionRegex));
} }
return rules; return rules;
} }
@ -81,7 +81,7 @@ QJsonObject OsRule::toJson()
ruleObj.insert("action", m_result == Allow ? QString("allow") : QString("disallow")); ruleObj.insert("action", m_result == Allow ? QString("allow") : QString("disallow"));
QJsonObject osObj; QJsonObject osObj;
{ {
osObj.insert("name", OpSys_toString(m_system)); osObj.insert("name", m_system);
if(!m_version_regexp.isEmpty()) if(!m_version_regexp.isEmpty())
{ {
osObj.insert("version", m_version_regexp); osObj.insert("version", m_version_regexp);

View File

@ -19,7 +19,7 @@
#include <QList> #include <QList>
#include <QJsonObject> #include <QJsonObject>
#include <memory> #include <memory>
#include "OpSys.h" #include "RuntimeContext.h"
class Library; class Library;
class Rule; class Rule;
@ -58,23 +58,23 @@ class OsRule : public Rule
{ {
private: private:
// the OS // the OS
OpSys m_system; QString m_system;
// the OS version regexp // the OS version regexp
QString m_version_regexp; QString m_version_regexp;
protected: protected:
virtual bool applies(const Library *) virtual bool applies(const Library *)
{ {
return (m_system == currentSystem); return (m_system == RuntimeContext::currentSystem());
} }
OsRule(RuleAction result, OpSys system, QString version_regexp) OsRule(RuleAction result, QString system, QString version_regexp)
: Rule(result), m_system(system), m_version_regexp(version_regexp) : Rule(result), m_system(system), m_version_regexp(version_regexp)
{ {
} }
public: public:
virtual QJsonObject toJson(); virtual QJsonObject toJson();
static std::shared_ptr<OsRule> create(RuleAction result, OpSys system, static std::shared_ptr<OsRule> create(RuleAction result, QString system,
QString version_regexp) QString version_regexp)
{ {
return std::shared_ptr<OsRule>(new OsRule(result, system, version_regexp)); return std::shared_ptr<OsRule>(new OsRule(result, system, version_regexp));

View File

@ -51,7 +51,7 @@ static bool isMinecraftVersion(const QString &uid)
return uid == "net.minecraft"; return uid == "net.minecraft";
} }
void VersionFile::applyTo(LaunchProfile *profile) void VersionFile::applyTo(LaunchProfile *profile, const RuntimeContext & runtimeContext)
{ {
// Only real Minecraft can set those. Don't let anything override them. // Only real Minecraft can set those. Don't let anything override them.
if (isMinecraftVersion(uid)) if (isMinecraftVersion(uid))
@ -77,15 +77,15 @@ void VersionFile::applyTo(LaunchProfile *profile)
for (auto library : libraries) for (auto library : libraries)
{ {
profile->applyLibrary(library); profile->applyLibrary(library, runtimeContext);
} }
for (auto mavenFile : mavenFiles) for (auto mavenFile : mavenFiles)
{ {
profile->applyMavenFile(mavenFile); profile->applyMavenFile(mavenFile, runtimeContext);
} }
for (auto agent : agents) for (auto agent : agents)
{ {
profile->applyAgent(agent); profile->applyAgent(agent, runtimeContext);
} }
profile->applyProblemSeverity(getProblemSeverity()); profile->applyProblemSeverity(getProblemSeverity());
} }

View File

@ -41,7 +41,6 @@
#include <QSet> #include <QSet>
#include <memory> #include <memory>
#include "minecraft/OpSys.h"
#include "minecraft/Rule.h" #include "minecraft/Rule.h"
#include "ProblemProvider.h" #include "ProblemProvider.h"
#include "Library.h" #include "Library.h"
@ -60,7 +59,7 @@ class VersionFile : public ProblemContainer
friend class MojangVersionFormat; friend class MojangVersionFormat;
friend class OneSixVersionFormat; friend class OneSixVersionFormat;
public: /* methods */ public: /* methods */
void applyTo(LaunchProfile* profile); void applyTo(LaunchProfile* profile, const RuntimeContext & runtimeContext);
public: /* data */ public: /* data */
/// PolyMC: order hint for this version file if no explicit order is set /// PolyMC: order hint for this version file if no explicit order is set

View File

@ -16,7 +16,6 @@
#include "ModMinecraftJar.h" #include "ModMinecraftJar.h"
#include "launch/LaunchTask.h" #include "launch/LaunchTask.h"
#include "MMCZip.h" #include "MMCZip.h"
#include "minecraft/OpSys.h"
#include "FileSystem.h" #include "FileSystem.h"
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
@ -50,7 +49,7 @@ void ModMinecraftJar::executeTask()
{ {
auto mainJar = profile->getMainJar(); auto mainJar = profile->getMainJar();
QStringList jars, temp1, temp2, temp3, temp4; QStringList jars, temp1, temp2, temp3, temp4;
mainJar->getApplicableFiles(currentSystem, jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath()); mainJar->getApplicableFiles(m_inst->runtimeContext(), jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath());
auto sourceJarPath = jars[0]; auto sourceJarPath = jars[0];
if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods)) if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods))
{ {

View File

@ -16,7 +16,6 @@
#include "ScanModFolders.h" #include "ScanModFolders.h"
#include "launch/LaunchTask.h" #include "launch/LaunchTask.h"
#include "MMCZip.h" #include "MMCZip.h"
#include "minecraft/OpSys.h"
#include "FileSystem.h" #include "FileSystem.h"
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "minecraft/mod/ModFolderModel.h" #include "minecraft/mod/ModFolderModel.h"

View File

@ -34,7 +34,7 @@ void LibrariesTask::executeTask()
emitFailed(tr("Null jar is specified in the metadata, aborting.")); emitFailed(tr("Null jar is specified in the metadata, aborting."));
return false; return false;
} }
auto dls = lib->getDownloads(currentSystem, metacache.get(), errors, localPath); auto dls = lib->getDownloads(inst->runtimeContext(), metacache.get(), errors, localPath);
for(auto dl : dls) for(auto dl : dls)
{ {
downloadJob->addNetAction(dl); downloadJob->addNetAction(dl);

View File

@ -274,6 +274,9 @@ void InstanceSettingsPage::applySettings()
{ {
m_settings->reset("JoinServerOnLaunchAddress"); m_settings->reset("JoinServerOnLaunchAddress");
} }
// FIXME: This should probably be called by a signal instead
m_instance->updateRuntimeContext();
} }
void InstanceSettingsPage::loadSettings() void InstanceSettingsPage::loadSettings()

View File

@ -87,7 +87,7 @@ slots:
void test_legacy_native() void test_legacy_native()
{ {
Library test("test.package:testname:testversion"); Library test("test.package:testname:testversion");
test.m_nativeClassifiers[OpSys::Os_Linux]="linux"; test.m_nativeClassifiers["linux"] = "linux";
QCOMPARE(test.isNative(), true); QCOMPARE(test.isNative(), true);
test.setRepositoryURL("file://foo/bar"); test.setRepositoryURL("file://foo/bar");
{ {
@ -108,9 +108,9 @@ slots:
void test_legacy_native_arch() void test_legacy_native_arch()
{ {
Library test("test.package:testname:testversion"); Library test("test.package:testname:testversion");
test.m_nativeClassifiers[OpSys::Os_Linux]="linux-${arch}"; test.m_nativeClassifiers["linux"]="linux-${arch}";
test.m_nativeClassifiers[OpSys::Os_OSX]="osx-${arch}"; test.m_nativeClassifiers["osx"]="osx-${arch}";
test.m_nativeClassifiers[OpSys::Os_Windows]="windows-${arch}"; test.m_nativeClassifiers["windows"]="windows-${arch}";
QCOMPARE(test.isNative(), true); QCOMPARE(test.isNative(), true);
test.setRepositoryURL("file://foo/bar"); test.setRepositoryURL("file://foo/bar");
{ {
@ -159,7 +159,7 @@ slots:
void test_legacy_native_arch_local_override() void test_legacy_native_arch_local_override()
{ {
Library test("test.package:testname:testversion"); Library test("test.package:testname:testversion");
test.m_nativeClassifiers[OpSys::Os_Linux]="linux-${arch}"; test.m_nativeClassifiers["linux"]="linux-${arch}";
test.setHint("local"); test.setHint("local");
QCOMPARE(test.isNative(), true); QCOMPARE(test.isNative(), true);
test.setRepositoryURL("file://foo/bar"); test.setRepositoryURL("file://foo/bar");