Some small cleanups (#4772)

This commit is contained in:
Alexandru Ionut Tripon 2026-03-18 20:29:26 +00:00 committed by GitHub
commit 04786023b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 50 additions and 112 deletions

View file

@ -130,7 +130,7 @@
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
#include <dlfcn.h> #include <dlfcn.h>
#include "MangoHud.h" #include "LibraryUtils.h"
#include "gamemode_client.h" #include "gamemode_client.h"
#endif #endif
@ -1834,7 +1834,7 @@ void Application::updateCapabilities()
if (gamemode_query_status() >= 0) if (gamemode_query_status() >= 0)
m_capabilities |= SupportsGameMode; m_capabilities |= SupportsGameMode;
if (!MangoHud::getLibraryString().isEmpty()) if (!LibraryUtils::findMangoHud().isEmpty())
m_capabilities |= SupportsMangoHud; m_capabilities |= SupportsMangoHud;
#endif #endif
} }
@ -1842,8 +1842,8 @@ void Application::updateCapabilities()
void Application::detectLibraries() void Application::detectLibraries()
{ {
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
m_detectedGLFWPath = MangoHud::findLibrary(BuildConfig.GLFW_LIBRARY_NAME); m_detectedGLFWPath = LibraryUtils::find(BuildConfig.GLFW_LIBRARY_NAME);
m_detectedOpenALPath = MangoHud::findLibrary(BuildConfig.OPENAL_LIBRARY_NAME); m_detectedOpenALPath = LibraryUtils::find(BuildConfig.OPENAL_LIBRARY_NAME);
qDebug() << "Detected native libraries:" << m_detectedGLFWPath << m_detectedOpenALPath; qDebug() << "Detected native libraries:" << m_detectedGLFWPath << m_detectedOpenALPath;
#endif #endif
} }

View file

@ -97,7 +97,6 @@ class Index;
#define APPLICATION_DYN (dynamic_cast<Application*>(QCoreApplication::instance())) #define APPLICATION_DYN (dynamic_cast<Application*>(QCoreApplication::instance()))
class Application : public QApplication { class Application : public QApplication {
// friends for the purpose of limiting access to deprecated stuff
Q_OBJECT Q_OBJECT
public: public:
enum Status { StartingUp, Failed, Succeeded, Initialized }; enum Status { StartingUp, Failed, Succeeded, Initialized };

View file

@ -75,9 +75,6 @@ set(CORE_SOURCES
# RW lock protected map # RW lock protected map
RWStorage.h 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 # a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
QObjectPtr.h QObjectPtr.h
@ -110,9 +107,9 @@ if (UNIX AND NOT CYGWIN AND NOT APPLE)
set(CORE_SOURCES set(CORE_SOURCES
${CORE_SOURCES} ${CORE_SOURCES}
# MangoHud # LibraryUtils
MangoHud.h LibraryUtils.h
MangoHud.cpp LibraryUtils.cpp
) )
endif() endif()

View file

@ -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;
};

View file

@ -25,7 +25,7 @@
#include "FileSystem.h" #include "FileSystem.h"
#include "Json.h" #include "Json.h"
#include "MangoHud.h" #include "LibraryUtils.h"
#ifdef __GLIBC__ #ifdef __GLIBC__
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
@ -36,9 +36,9 @@
#include <linux/limits.h> #include <linux/limits.h>
#endif #endif
namespace MangoHud { namespace LibraryUtils {
QString getLibraryString() QString findMangoHud()
{ {
/** /**
* Guess MangoHud install location by searching for vulkan layers in this order: * Guess MangoHud install location by searching for vulkan layers in this order:
@ -123,7 +123,7 @@ QString getLibraryString()
#ifdef __GLIBC__ #ifdef __GLIBC__
// Check whether mangohud is usable on a glibc based system // Check whether mangohud is usable on a glibc based system
QString libraryPath = findLibrary(libraryName); QString libraryPath = find(libraryName);
if (!libraryPath.isEmpty()) { if (!libraryPath.isEmpty()) {
return libraryPath; return libraryPath;
} }
@ -138,7 +138,7 @@ QString getLibraryString()
return {}; return {};
} }
QString findLibrary(QString libName) QString find(QString libName)
{ {
#ifdef __GLIBC__ #ifdef __GLIBC__
const char* library = libName.toLocal8Bit().constData(); const char* library = libName.toLocal8Bit().constData();
@ -161,11 +161,11 @@ QString findLibrary(QString libName)
dlclose(handle); dlclose(handle);
return fullPath; return fullPath;
#else #else
qWarning() << "MangoHud::findLibrary is not implemented on this platform"; qWarning() << "LibraryUtils::find is not implemented on this platform";
return {}; return {};
#endif #endif
} }
} // namespace MangoHud } // namespace LibraryUtils
#ifdef UNDEF_GNU_SOURCE #ifdef UNDEF_GNU_SOURCE
#undef _GNU_SOURCE #undef _GNU_SOURCE

View file

@ -21,9 +21,9 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
namespace MangoHud { namespace LibraryUtils {
QString getLibraryString(); QString findMangoHud();
QString findLibrary(QString libName); QString find(QString libName);
} // namespace MangoHud } // namespace LibraryUtils

View file

@ -67,5 +67,5 @@ class PSaveFile : public QSaveFile {
QString m_absoluteFilePath; QString m_absoluteFilePath;
}; };
#else #else
#define PSaveFile QSaveFile using PSaveFile = QSaveFile;
#endif #endif

View file

@ -38,7 +38,6 @@
#include "FileSystem.h" #include "FileSystem.h"
class FileLinkApp : public QCoreApplication { class FileLinkApp : public QCoreApplication {
// friends for the purpose of limiting access to deprecated stuff
Q_OBJECT Q_OBJECT
public: public:
enum Status { Starting, Failed, Succeeded, Initialized }; enum Status { Starting, Failed, Succeeded, Initialized };

View file

@ -4,26 +4,10 @@
#include "Library.h" #include "Library.h"
class Agent; struct 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 */
/// The library pointing to the jar this Java agent is contained within /// 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 /// The argument to the Java agent, passed after an = if present
QString m_argument; QString argument;
}; };

View file

@ -38,12 +38,10 @@
#include <QRegularExpression> #include <QRegularExpression>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include "DefaultVariable.h"
struct GradleSpecifier { struct GradleSpecifier {
GradleSpecifier() { m_valid = false; } GradleSpecifier() { m_valid = false; }
GradleSpecifier(QString value) { operator=(value); } GradleSpecifier(const QString& value)
GradleSpecifier& operator=(const QString& value)
{ {
/* /*
org.gradle.test.classifiers : service : 1.0 : jdk15 @ jar org.gradle.test.classifiers : service : 1.0 : jdk15 @ jar
@ -62,7 +60,7 @@ struct GradleSpecifier {
m_valid = match.hasMatch(); m_valid = match.hasMatch();
if (!m_valid) { if (!m_valid) {
m_invalidValue = value; m_invalidValue = value;
return *this; return;
} }
auto elements = match.captured(); auto elements = match.captured();
m_groupId = match.captured(1); m_groupId = match.captured(1);
@ -72,7 +70,6 @@ struct GradleSpecifier {
if (match.lastCapturedIndex() >= 5) { if (match.lastCapturedIndex() >= 5) {
m_extension = match.captured(5); m_extension = match.captured(5);
} }
return *this;
} }
QString serialize() const QString serialize() const
{ {
@ -83,8 +80,8 @@ struct GradleSpecifier {
if (!m_classifier.isEmpty()) { if (!m_classifier.isEmpty()) {
retval += ":" + m_classifier; retval += ":" + m_classifier;
} }
if (m_extension.isExplicit()) { if (m_extension.has_value()) {
retval += "@" + m_extension; retval += "@" + m_extension.value();
} }
return retval; return retval;
} }
@ -97,7 +94,7 @@ struct GradleSpecifier {
if (!m_classifier.isEmpty()) { if (!m_classifier.isEmpty()) {
filename += "-" + m_classifier; filename += "-" + m_classifier;
} }
filename += "." + m_extension; filename += "." + m_extension.value_or("jar");
return filename; return filename;
} }
QString toPath(const QString& filenameOverride = QString()) const QString toPath(const QString& filenameOverride = QString()) const
@ -122,26 +119,13 @@ struct GradleSpecifier {
inline QString artifactId() const { return m_artifactId; } inline QString artifactId() const { return m_artifactId; }
inline void setClassifier(const QString& classifier) { m_classifier = classifier; } inline void setClassifier(const QString& classifier) { m_classifier = classifier; }
inline QString classifier() const { return m_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; } inline QString artifactPrefix() const { return m_groupId + ":" + m_artifactId; }
bool matchName(const GradleSpecifier& other) const bool matchName(const GradleSpecifier& other) const
{ {
return other.artifactId() == artifactId() && other.groupId() == groupId() && other.classifier() == classifier(); return other.artifactId() == artifactId() && other.groupId() == groupId() && other.classifier() == classifier();
} }
bool operator==(const GradleSpecifier& other) const bool operator ==(const GradleSpecifier &other) const = default;
{
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;
}
private: private:
QString m_invalidValue; QString m_invalidValue;
@ -149,6 +133,6 @@ struct GradleSpecifier {
QString m_artifactId; QString m_artifactId;
QString m_version; QString m_version;
QString m_classifier; QString m_classifier;
DefaultVariable<QString> m_extension = DefaultVariable<QString>("jar"); std::optional<QString> m_extension;
bool m_valid = false; bool m_valid = false;
}; };

View file

@ -213,9 +213,9 @@ void LaunchProfile::applyMavenFile(LibraryPtr mavenFile, const RuntimeContext& r
m_mavenFiles.append(Library::limitedCopy(mavenFile)); 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)) { if (!lib->isActive(runtimeContext)) {
return; return;
} }
@ -330,7 +330,7 @@ const QList<LibraryPtr>& LaunchProfile::getMavenFiles() const
return m_mavenFiles; return m_mavenFiles;
} }
const QList<AgentPtr>& LaunchProfile::getAgents() const const QList<Agent>& LaunchProfile::getAgents() const
{ {
return m_agents; return m_agents;
} }

View file

@ -57,7 +57,7 @@ class LaunchProfile : public ProblemProvider {
void applyMods(const QList<LibraryPtr>& jarMods); void applyMods(const QList<LibraryPtr>& jarMods);
void applyLibrary(LibraryPtr library, const RuntimeContext& runtimeContext); void applyLibrary(LibraryPtr library, const RuntimeContext& runtimeContext);
void applyMavenFile(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 applyCompatibleJavaMajors(QList<int>& javaMajor);
void applyCompatibleJavaName(QString javaName); void applyCompatibleJavaName(QString javaName);
void applyMainJar(LibraryPtr jar); void applyMainJar(LibraryPtr jar);
@ -79,7 +79,7 @@ class LaunchProfile : public ProblemProvider {
const QList<LibraryPtr>& getLibraries() const; const QList<LibraryPtr>& getLibraries() const;
const QList<LibraryPtr>& getNativeLibraries() const; const QList<LibraryPtr>& getNativeLibraries() const;
const QList<LibraryPtr>& getMavenFiles() const; const QList<LibraryPtr>& getMavenFiles() const;
const QList<AgentPtr>& getAgents() const; const QList<Agent>& getAgents() const;
const QList<int>& getCompatibleJavaMajors() const; const QList<int>& getCompatibleJavaMajors() const;
const QString getCompatibleJavaName() const; const QString getCompatibleJavaName() const;
const LibraryPtr getMainJar() const; const LibraryPtr getMainJar() const;
@ -132,7 +132,7 @@ class LaunchProfile : public ProblemProvider {
QList<LibraryPtr> m_mavenFiles; QList<LibraryPtr> m_mavenFiles;
/// the list of java agents to add to JVM arguments /// the list of java agents to add to JVM arguments
QList<AgentPtr> m_agents; QList<Agent> m_agents;
/// the main jar /// the main jar
LibraryPtr m_mainJar; LibraryPtr m_mainJar;

View file

@ -97,7 +97,7 @@
#include <QWindow> #include <QWindow>
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
#include "MangoHud.h" #include "LibraryUtils.h"
#endif #endif
#ifdef WITH_QTDBUS #ifdef WITH_QTDBUS
@ -529,10 +529,10 @@ QStringList MinecraftInstance::extraArguments()
} }
} }
auto agents = m_components->getProfile()->getAgents(); auto agents = m_components->getProfile()->getAgents();
for (auto agent : agents) { for (const auto& agent : agents) {
QStringList jar, temp1, temp2, temp3; QStringList jar, temp1, temp2, temp3;
agent->library()->getApplicableFiles(runtimeContext(), 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));
} }
{ {
@ -700,7 +700,7 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment()
if (auto value = env.value("LD_PRELOAD"); !value.isEmpty()) if (auto value = env.value("LD_PRELOAD"); !value.isEmpty())
preloadList = value.split(QLatin1String(":")); preloadList = value.split(QLatin1String(":"));
auto mangoHudLibString = MangoHud::getLibraryString(); auto mangoHudLibString = LibraryUtils::findMangoHud();
if (!mangoHudLibString.isEmpty()) { if (!mangoHudLibString.isEmpty()) {
QFileInfo mangoHudLib(mangoHudLibString); QFileInfo mangoHudLib(mangoHudLibString);
QString libPath = mangoHudLib.absolutePath(); QString libPath = mangoHudLib.absolutePath();

View file

@ -209,8 +209,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument& doc
QString arg = ""; QString arg = "";
readString(agentObj, "argument", arg); readString(agentObj, "argument", arg);
AgentPtr agent(new Agent(lib, arg)); out->agents.append(Agent{ lib, arg });
out->agents.append(agent);
} }
} }
@ -305,10 +304,10 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr& patch
writeStringList(root, "+jvmArgs", patch->addnJvmArguments); writeStringList(root, "+jvmArgs", patch->addnJvmArguments);
if (!patch->agents.isEmpty()) { if (!patch->agents.isEmpty()) {
QJsonArray array; QJsonArray array;
for (auto value : patch->agents) { for (const auto& value : patch->agents) {
QJsonObject agentOut = OneSixVersionFormat::libraryToJson(value->library().get()); QJsonObject agentOut = OneSixVersionFormat::libraryToJson(value.library.get());
if (!value->argument().isEmpty()) if (!value.argument.isEmpty())
agentOut.insert("argument", value->argument()); agentOut.insert("argument", value.argument);
array.append(agentOut); array.append(agentOut);
} }

View file

@ -917,7 +917,7 @@ bool PackProfile::installAgents_internal(QStringList filepaths)
agent->setDisplayName(sourceInfo.completeBaseName()); agent->setDisplayName(sourceInfo.completeBaseName());
agent->setHint("local"); agent->setHint("local");
versionFile->agents.append(std::make_shared<Agent>(agent, QString())); versionFile->agents.append(Agent{agent, QString()});
versionFile->name = targetName; versionFile->name = targetName;
versionFile->uid = targetId; versionFile->uid = targetId;

View file

@ -126,7 +126,7 @@ class VersionFile : public ProblemContainer {
QList<LibraryPtr> mavenFiles; QList<LibraryPtr> mavenFiles;
/// Prism Launcher: list of agents to add to JVM arguments /// Prism Launcher: list of agents to add to JVM arguments
QList<AgentPtr> agents; QList<Agent> agents;
/// The main jar (Minecraft version library, normally) /// The main jar (Minecraft version library, normally)
LibraryPtr mainJar; LibraryPtr mainJar;

View file

@ -44,8 +44,8 @@ void LibrariesTask::executeTask()
libArtifactPool.append(profile->getLibraries()); libArtifactPool.append(profile->getLibraries());
libArtifactPool.append(profile->getNativeLibraries()); libArtifactPool.append(profile->getNativeLibraries());
libArtifactPool.append(profile->getMavenFiles()); libArtifactPool.append(profile->getMavenFiles());
for (auto agent : profile->getAgents()) { for (const auto& agent : profile->getAgents()) {
libArtifactPool.append(agent->library()); libArtifactPool.append(agent.library);
} }
libArtifactPool.append(profile->getMainJar()); libArtifactPool.append(profile->getMainJar());
processArtifactPool(libArtifactPool, failedLocalLibraries, inst->getLocalLibraryPath()); processArtifactPool(libArtifactPool, failedLocalLibraries, inst->getLocalLibraryPath());

View file

@ -46,7 +46,6 @@
#include "GitHubRelease.h" #include "GitHubRelease.h"
class PrismUpdaterApp : public QApplication { class PrismUpdaterApp : public QApplication {
// friends for the purpose of limiting access to deprecated stuff
Q_OBJECT Q_OBJECT
public: public:
enum Status { Starting, Failed, Succeeded, Initialized, Aborted }; enum Status { Starting, Failed, Succeeded, Initialized, Aborted };