mirror of
https://github.com/PrismLauncher/PrismLauncher
synced 2026-04-23 09:05:03 +00:00
Agent: Simplify and avoid unnecessary shared_ptr
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
77ebf65c7d
commit
248eb13ab9
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Reference in a new issue