mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
Some small cleanups (#4772)
This commit is contained in:
commit
04786023b0
18 changed files with 50 additions and 112 deletions
|
|
@ -130,7 +130,7 @@
|
|||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <dlfcn.h>
|
||||
#include "MangoHud.h"
|
||||
#include "LibraryUtils.h"
|
||||
#include "gamemode_client.h"
|
||||
#endif
|
||||
|
||||
|
|
@ -1834,7 +1834,7 @@ void Application::updateCapabilities()
|
|||
if (gamemode_query_status() >= 0)
|
||||
m_capabilities |= SupportsGameMode;
|
||||
|
||||
if (!MangoHud::getLibraryString().isEmpty())
|
||||
if (!LibraryUtils::findMangoHud().isEmpty())
|
||||
m_capabilities |= SupportsMangoHud;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1842,8 +1842,8 @@ void Application::updateCapabilities()
|
|||
void Application::detectLibraries()
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
m_detectedGLFWPath = MangoHud::findLibrary(BuildConfig.GLFW_LIBRARY_NAME);
|
||||
m_detectedOpenALPath = MangoHud::findLibrary(BuildConfig.OPENAL_LIBRARY_NAME);
|
||||
m_detectedGLFWPath = LibraryUtils::find(BuildConfig.GLFW_LIBRARY_NAME);
|
||||
m_detectedOpenALPath = LibraryUtils::find(BuildConfig.OPENAL_LIBRARY_NAME);
|
||||
qDebug() << "Detected native libraries:" << m_detectedGLFWPath << m_detectedOpenALPath;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@ class Index;
|
|||
#define APPLICATION_DYN (dynamic_cast<Application*>(QCoreApplication::instance()))
|
||||
|
||||
class Application : public QApplication {
|
||||
// friends for the purpose of limiting access to deprecated stuff
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Status { StartingUp, Failed, Succeeded, Initialized };
|
||||
|
|
|
|||
|
|
@ -75,9 +75,6 @@ set(CORE_SOURCES
|
|||
# RW lock protected map
|
||||
RWStorage.h
|
||||
|
||||
# A variable that has an implicit default value and keeps track of changes
|
||||
DefaultVariable.h
|
||||
|
||||
# a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
|
||||
QObjectPtr.h
|
||||
|
||||
|
|
@ -110,9 +107,9 @@ if (UNIX AND NOT CYGWIN AND NOT APPLE)
|
|||
set(CORE_SOURCES
|
||||
${CORE_SOURCES}
|
||||
|
||||
# MangoHud
|
||||
MangoHud.h
|
||||
MangoHud.cpp
|
||||
# LibraryUtils
|
||||
LibraryUtils.h
|
||||
LibraryUtils.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
template <typename T>
|
||||
class DefaultVariable {
|
||||
public:
|
||||
DefaultVariable(const T& value) { defaultValue = value; }
|
||||
DefaultVariable<T>& operator=(const T& value)
|
||||
{
|
||||
currentValue = value;
|
||||
is_default = currentValue == defaultValue;
|
||||
is_explicit = true;
|
||||
return *this;
|
||||
}
|
||||
operator const T&() const { return is_default ? defaultValue : currentValue; }
|
||||
bool isDefault() const { return is_default; }
|
||||
bool isExplicit() const { return is_explicit; }
|
||||
|
||||
private:
|
||||
T currentValue;
|
||||
T defaultValue;
|
||||
bool is_default = true;
|
||||
bool is_explicit = false;
|
||||
};
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "FileSystem.h"
|
||||
#include "Json.h"
|
||||
#include "MangoHud.h"
|
||||
#include "LibraryUtils.h"
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#ifndef _GNU_SOURCE
|
||||
|
|
@ -36,9 +36,9 @@
|
|||
#include <linux/limits.h>
|
||||
#endif
|
||||
|
||||
namespace MangoHud {
|
||||
namespace LibraryUtils {
|
||||
|
||||
QString getLibraryString()
|
||||
QString findMangoHud()
|
||||
{
|
||||
/**
|
||||
* Guess MangoHud install location by searching for vulkan layers in this order:
|
||||
|
|
@ -123,7 +123,7 @@ QString getLibraryString()
|
|||
|
||||
#ifdef __GLIBC__
|
||||
// Check whether mangohud is usable on a glibc based system
|
||||
QString libraryPath = findLibrary(libraryName);
|
||||
QString libraryPath = find(libraryName);
|
||||
if (!libraryPath.isEmpty()) {
|
||||
return libraryPath;
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ QString getLibraryString()
|
|||
return {};
|
||||
}
|
||||
|
||||
QString findLibrary(QString libName)
|
||||
QString find(QString libName)
|
||||
{
|
||||
#ifdef __GLIBC__
|
||||
const char* library = libName.toLocal8Bit().constData();
|
||||
|
|
@ -161,11 +161,11 @@ QString findLibrary(QString libName)
|
|||
dlclose(handle);
|
||||
return fullPath;
|
||||
#else
|
||||
qWarning() << "MangoHud::findLibrary is not implemented on this platform";
|
||||
qWarning() << "LibraryUtils::find is not implemented on this platform";
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
} // namespace MangoHud
|
||||
} // namespace LibraryUtils
|
||||
|
||||
#ifdef UNDEF_GNU_SOURCE
|
||||
#undef _GNU_SOURCE
|
||||
|
|
@ -21,9 +21,9 @@
|
|||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
namespace MangoHud {
|
||||
namespace LibraryUtils {
|
||||
|
||||
QString getLibraryString();
|
||||
QString findMangoHud();
|
||||
|
||||
QString findLibrary(QString libName);
|
||||
} // namespace MangoHud
|
||||
QString find(QString libName);
|
||||
} // namespace LibraryUtils
|
||||
|
|
@ -67,5 +67,5 @@ class PSaveFile : public QSaveFile {
|
|||
QString m_absoluteFilePath;
|
||||
};
|
||||
#else
|
||||
#define PSaveFile QSaveFile
|
||||
using PSaveFile = QSaveFile;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
#include "FileSystem.h"
|
||||
|
||||
class FileLinkApp : public QCoreApplication {
|
||||
// friends for the purpose of limiting access to deprecated stuff
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Status { Starting, Failed, Succeeded, Initialized };
|
||||
|
|
|
|||
|
|
@ -4,26 +4,10 @@
|
|||
|
||||
#include "Library.h"
|
||||
|
||||
class Agent;
|
||||
|
||||
using AgentPtr = std::shared_ptr<Agent>;
|
||||
|
||||
class Agent {
|
||||
public:
|
||||
Agent(LibraryPtr library, const QString& argument)
|
||||
{
|
||||
m_library = library;
|
||||
m_argument = argument;
|
||||
}
|
||||
|
||||
public: /* methods */
|
||||
LibraryPtr library() { return m_library; }
|
||||
QString argument() { return m_argument; }
|
||||
|
||||
protected: /* data */
|
||||
struct Agent {
|
||||
/// The library pointing to the jar this Java agent is contained within
|
||||
LibraryPtr m_library;
|
||||
LibraryPtr library;
|
||||
|
||||
/// The argument to the Java agent, passed after an = if present
|
||||
QString m_argument;
|
||||
QString argument;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,12 +38,10 @@
|
|||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include "DefaultVariable.h"
|
||||
|
||||
struct GradleSpecifier {
|
||||
GradleSpecifier() { m_valid = false; }
|
||||
GradleSpecifier(QString value) { operator=(value); }
|
||||
GradleSpecifier& operator=(const QString& value)
|
||||
GradleSpecifier(const QString& value)
|
||||
{
|
||||
/*
|
||||
org.gradle.test.classifiers : service : 1.0 : jdk15 @ jar
|
||||
|
|
@ -62,7 +60,7 @@ struct GradleSpecifier {
|
|||
m_valid = match.hasMatch();
|
||||
if (!m_valid) {
|
||||
m_invalidValue = value;
|
||||
return *this;
|
||||
return;
|
||||
}
|
||||
auto elements = match.captured();
|
||||
m_groupId = match.captured(1);
|
||||
|
|
@ -72,7 +70,6 @@ struct GradleSpecifier {
|
|||
if (match.lastCapturedIndex() >= 5) {
|
||||
m_extension = match.captured(5);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
QString serialize() const
|
||||
{
|
||||
|
|
@ -83,8 +80,8 @@ struct GradleSpecifier {
|
|||
if (!m_classifier.isEmpty()) {
|
||||
retval += ":" + m_classifier;
|
||||
}
|
||||
if (m_extension.isExplicit()) {
|
||||
retval += "@" + m_extension;
|
||||
if (m_extension.has_value()) {
|
||||
retval += "@" + m_extension.value();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -97,7 +94,7 @@ struct GradleSpecifier {
|
|||
if (!m_classifier.isEmpty()) {
|
||||
filename += "-" + m_classifier;
|
||||
}
|
||||
filename += "." + m_extension;
|
||||
filename += "." + m_extension.value_or("jar");
|
||||
return filename;
|
||||
}
|
||||
QString toPath(const QString& filenameOverride = QString()) const
|
||||
|
|
@ -122,26 +119,13 @@ struct GradleSpecifier {
|
|||
inline QString artifactId() const { return m_artifactId; }
|
||||
inline void setClassifier(const QString& classifier) { m_classifier = classifier; }
|
||||
inline QString classifier() const { return m_classifier; }
|
||||
inline QString extension() const { return m_extension; }
|
||||
inline std::optional<QString> extension() const { return m_extension; }
|
||||
inline QString artifactPrefix() const { return m_groupId + ":" + m_artifactId; }
|
||||
bool matchName(const GradleSpecifier& other) const
|
||||
{
|
||||
return other.artifactId() == artifactId() && other.groupId() == groupId() && other.classifier() == classifier();
|
||||
}
|
||||
bool operator==(const GradleSpecifier& other) const
|
||||
{
|
||||
if (m_groupId != other.m_groupId)
|
||||
return false;
|
||||
if (m_artifactId != other.m_artifactId)
|
||||
return false;
|
||||
if (m_version != other.m_version)
|
||||
return false;
|
||||
if (m_classifier != other.m_classifier)
|
||||
return false;
|
||||
if (m_extension != other.m_extension)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool operator ==(const GradleSpecifier &other) const = default;
|
||||
|
||||
private:
|
||||
QString m_invalidValue;
|
||||
|
|
@ -149,6 +133,6 @@ struct GradleSpecifier {
|
|||
QString m_artifactId;
|
||||
QString m_version;
|
||||
QString m_classifier;
|
||||
DefaultVariable<QString> m_extension = DefaultVariable<QString>("jar");
|
||||
std::optional<QString> m_extension;
|
||||
bool m_valid = false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -213,9 +213,9 @@ void LaunchProfile::applyMavenFile(LibraryPtr mavenFile, const RuntimeContext& r
|
|||
m_mavenFiles.append(Library::limitedCopy(mavenFile));
|
||||
}
|
||||
|
||||
void LaunchProfile::applyAgent(AgentPtr agent, const RuntimeContext& runtimeContext)
|
||||
void LaunchProfile::applyAgent(const Agent& agent, const RuntimeContext& runtimeContext)
|
||||
{
|
||||
auto lib = agent->library();
|
||||
auto lib = agent.library;
|
||||
if (!lib->isActive(runtimeContext)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -330,7 +330,7 @@ const QList<LibraryPtr>& LaunchProfile::getMavenFiles() const
|
|||
return m_mavenFiles;
|
||||
}
|
||||
|
||||
const QList<AgentPtr>& LaunchProfile::getAgents() const
|
||||
const QList<Agent>& LaunchProfile::getAgents() const
|
||||
{
|
||||
return m_agents;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class LaunchProfile : public ProblemProvider {
|
|||
void applyMods(const QList<LibraryPtr>& jarMods);
|
||||
void applyLibrary(LibraryPtr library, const RuntimeContext& runtimeContext);
|
||||
void applyMavenFile(LibraryPtr library, const RuntimeContext& runtimeContext);
|
||||
void applyAgent(AgentPtr agent, const RuntimeContext& runtimeContext);
|
||||
void applyAgent(const Agent& agent, const RuntimeContext& runtimeContext);
|
||||
void applyCompatibleJavaMajors(QList<int>& javaMajor);
|
||||
void applyCompatibleJavaName(QString javaName);
|
||||
void applyMainJar(LibraryPtr jar);
|
||||
|
|
@ -79,7 +79,7 @@ class LaunchProfile : public ProblemProvider {
|
|||
const QList<LibraryPtr>& getLibraries() const;
|
||||
const QList<LibraryPtr>& getNativeLibraries() const;
|
||||
const QList<LibraryPtr>& getMavenFiles() const;
|
||||
const QList<AgentPtr>& getAgents() const;
|
||||
const QList<Agent>& getAgents() const;
|
||||
const QList<int>& getCompatibleJavaMajors() const;
|
||||
const QString getCompatibleJavaName() const;
|
||||
const LibraryPtr getMainJar() const;
|
||||
|
|
@ -132,7 +132,7 @@ class LaunchProfile : public ProblemProvider {
|
|||
QList<LibraryPtr> m_mavenFiles;
|
||||
|
||||
/// the list of java agents to add to JVM arguments
|
||||
QList<AgentPtr> m_agents;
|
||||
QList<Agent> m_agents;
|
||||
|
||||
/// the main jar
|
||||
LibraryPtr m_mainJar;
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@
|
|||
#include <QWindow>
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include "MangoHud.h"
|
||||
#include "LibraryUtils.h"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_QTDBUS
|
||||
|
|
@ -529,10 +529,10 @@ QStringList MinecraftInstance::extraArguments()
|
|||
}
|
||||
}
|
||||
auto agents = m_components->getProfile()->getAgents();
|
||||
for (auto agent : agents) {
|
||||
for (const auto& agent : agents) {
|
||||
QStringList jar, temp1, temp2, temp3;
|
||||
agent->library()->getApplicableFiles(runtimeContext(), jar, temp1, temp2, temp3, getLocalLibraryPath());
|
||||
list.append("-javaagent:" + jar[0] + (agent->argument().isEmpty() ? "" : "=" + agent->argument()));
|
||||
agent.library->getApplicableFiles(runtimeContext(), jar, temp1, temp2, temp3, getLocalLibraryPath());
|
||||
list.append("-javaagent:" + jar[0] + (agent.argument.isEmpty() ? "" : "=" + agent.argument));
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -700,7 +700,7 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment()
|
|||
if (auto value = env.value("LD_PRELOAD"); !value.isEmpty())
|
||||
preloadList = value.split(QLatin1String(":"));
|
||||
|
||||
auto mangoHudLibString = MangoHud::getLibraryString();
|
||||
auto mangoHudLibString = LibraryUtils::findMangoHud();
|
||||
if (!mangoHudLibString.isEmpty()) {
|
||||
QFileInfo mangoHudLib(mangoHudLibString);
|
||||
QString libPath = mangoHudLib.absolutePath();
|
||||
|
|
|
|||
|
|
@ -209,8 +209,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument& doc
|
|||
QString arg = "";
|
||||
readString(agentObj, "argument", arg);
|
||||
|
||||
AgentPtr agent(new Agent(lib, arg));
|
||||
out->agents.append(agent);
|
||||
out->agents.append(Agent{ lib, arg });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -305,10 +304,10 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr& patch
|
|||
writeStringList(root, "+jvmArgs", patch->addnJvmArguments);
|
||||
if (!patch->agents.isEmpty()) {
|
||||
QJsonArray array;
|
||||
for (auto value : patch->agents) {
|
||||
QJsonObject agentOut = OneSixVersionFormat::libraryToJson(value->library().get());
|
||||
if (!value->argument().isEmpty())
|
||||
agentOut.insert("argument", value->argument());
|
||||
for (const auto& value : patch->agents) {
|
||||
QJsonObject agentOut = OneSixVersionFormat::libraryToJson(value.library.get());
|
||||
if (!value.argument.isEmpty())
|
||||
agentOut.insert("argument", value.argument);
|
||||
|
||||
array.append(agentOut);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -917,7 +917,7 @@ bool PackProfile::installAgents_internal(QStringList filepaths)
|
|||
agent->setDisplayName(sourceInfo.completeBaseName());
|
||||
agent->setHint("local");
|
||||
|
||||
versionFile->agents.append(std::make_shared<Agent>(agent, QString()));
|
||||
versionFile->agents.append(Agent{agent, QString()});
|
||||
|
||||
versionFile->name = targetName;
|
||||
versionFile->uid = targetId;
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ class VersionFile : public ProblemContainer {
|
|||
QList<LibraryPtr> mavenFiles;
|
||||
|
||||
/// Prism Launcher: list of agents to add to JVM arguments
|
||||
QList<AgentPtr> agents;
|
||||
QList<Agent> agents;
|
||||
|
||||
/// The main jar (Minecraft version library, normally)
|
||||
LibraryPtr mainJar;
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ void LibrariesTask::executeTask()
|
|||
libArtifactPool.append(profile->getLibraries());
|
||||
libArtifactPool.append(profile->getNativeLibraries());
|
||||
libArtifactPool.append(profile->getMavenFiles());
|
||||
for (auto agent : profile->getAgents()) {
|
||||
libArtifactPool.append(agent->library());
|
||||
for (const auto& agent : profile->getAgents()) {
|
||||
libArtifactPool.append(agent.library);
|
||||
}
|
||||
libArtifactPool.append(profile->getMainJar());
|
||||
processArtifactPool(libArtifactPool, failedLocalLibraries, inst->getLocalLibraryPath());
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@
|
|||
#include "GitHubRelease.h"
|
||||
|
||||
class PrismUpdaterApp : public QApplication {
|
||||
// friends for the purpose of limiting access to deprecated stuff
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Status { Starting, Failed, Succeeded, Initialized, Aborted };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue