aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/minecraft')
-rw-r--r--launcher/minecraft/Agent.h2
-rw-r--r--launcher/minecraft/PackProfile.cpp72
-rw-r--r--launcher/minecraft/PackProfile.h7
3 files changed, 74 insertions, 7 deletions
diff --git a/launcher/minecraft/Agent.h b/launcher/minecraft/Agent.h
index 01109daf..374e6e94 100644
--- a/launcher/minecraft/Agent.h
+++ b/launcher/minecraft/Agent.h
@@ -10,7 +10,7 @@ typedef std::shared_ptr<Agent> AgentPtr;
class Agent {
public:
- Agent(LibraryPtr library, QString &argument)
+ Agent(LibraryPtr library, const QString &argument)
{
m_library = library;
m_argument = argument;
diff --git a/launcher/minecraft/PackProfile.cpp b/launcher/minecraft/PackProfile.cpp
index 6ce525eb..bbdf51d8 100644
--- a/launcher/minecraft/PackProfile.cpp
+++ b/launcher/minecraft/PackProfile.cpp
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
+ * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* 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
@@ -47,7 +48,6 @@
#include "Exception.h"
#include "minecraft/OneSixVersionFormat.h"
#include "FileSystem.h"
-#include "meta/Index.h"
#include "minecraft/MinecraftInstance.h"
#include "Json.h"
@@ -55,7 +55,6 @@
#include "PackProfile_p.h"
#include "ComponentUpdateTask.h"
-#include "Application.h"
#include "modplatform/ModAPI.h"
static const QMap<QString, ModAPI::ModLoaderType> modloaderMapping{
@@ -738,6 +737,11 @@ void PackProfile::installCustomJar(QString selectedFile)
installCustomJar_internal(selectedFile);
}
+void PackProfile::installAgents(QStringList selectedFiles)
+{
+ installAgents_internal(selectedFiles);
+}
+
bool PackProfile::installEmpty(const QString& uid, const QString& name)
{
QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
@@ -832,8 +836,7 @@ bool PackProfile::installJarMods_internal(QStringList filepaths)
for(auto filepath:filepaths)
{
QFileInfo sourceInfo(filepath);
- auto uuid = QUuid::createUuid();
- QString id = uuid.toString().remove('{').remove('}');
+ QString id = QUuid::createUuid().toString(QUuid::WithoutBraces);
QString target_filename = id + ".jar";
QString target_id = "org.multimc.jarmod." + id;
QString target_name = sourceInfo.completeBaseName() + " (jar mod)";
@@ -939,6 +942,65 @@ bool PackProfile::installCustomJar_internal(QString filepath)
return true;
}
+bool PackProfile::installAgents_internal(QStringList filepaths)
+{
+ // FIXME code duplication
+ const QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
+ if (!FS::ensureFolderPathExists(patchDir))
+ return false;
+
+ const QString libDir = d->m_instance->getLocalLibraryPath();
+ if (!FS::ensureFolderPathExists(libDir))
+ return false;
+
+ for (const QString& source : filepaths) {
+ const QFileInfo sourceInfo(source);
+ const QString id = QUuid::createUuid().toString(QUuid::WithoutBraces);
+ const QString targetBaseName = id + ".jar";
+ const QString targetId = "org.prismlauncher.agent." + id;
+ const QString targetName = sourceInfo.completeBaseName() + " (agent)";
+ const QString target = FS::PathCombine(d->m_instance->getLocalLibraryPath(), targetBaseName);
+
+ const QFileInfo targetInfo(target);
+ if (targetInfo.exists())
+ return false;
+
+ if (!QFile::copy(source, target))
+ return false;
+
+ auto versionFile = std::make_shared<VersionFile>();
+
+ auto agent = std::make_shared<Library>();
+
+ agent->setRawName("org.prismlauncher.agents:" + id + ":1");
+ agent->setFilename(targetBaseName);
+ agent->setDisplayName(sourceInfo.completeBaseName());
+ agent->setHint("local");
+
+ versionFile->agents.append(std::make_shared<Agent>(agent, QString()));
+
+ versionFile->name = targetName;
+ versionFile->uid = targetId;
+
+ QFile patchFile(FS::PathCombine(patchDir, targetId + ".json"));
+
+ if (!patchFile.open(QFile::WriteOnly)) {
+ qCritical() << "Error opening" << patchFile.fileName() << "for reading:" << patchFile.errorString();
+ return false;
+ }
+
+ patchFile.write(OneSixVersionFormat::versionFileToJson(versionFile).toJson());
+ patchFile.close();
+
+ appendComponent(new Component(this, versionFile->uid, versionFile));
+ }
+
+ scheduleSave();
+ invalidateLaunchProfile();
+
+ return true;
+}
+
std::shared_ptr<LaunchProfile> PackProfile::getProfile() const
{
if(!d->m_profile)
diff --git a/launcher/minecraft/PackProfile.h b/launcher/minecraft/PackProfile.h
index 807511a2..2330cca1 100644
--- a/launcher/minecraft/PackProfile.h
+++ b/launcher/minecraft/PackProfile.h
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
+ * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* 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
@@ -85,6 +86,9 @@ public:
/// install a jar/zip as a replacement for the main jar
void installCustomJar(QString selectedFile);
+ /// install Java agent files
+ void installAgents(QStringList selectedFiles);
+
enum MoveDirection { MoveUp, MoveDown };
/// move component file # up or down the list
void move(const int index, const MoveDirection direction);
@@ -167,6 +171,7 @@ private:
bool load();
bool installJarMods_internal(QStringList filepaths);
bool installCustomJar_internal(QString filepath);
+ bool installAgents_internal(QStringList filepaths);
bool removeComponent_internal(ComponentPtr patch);
private: /* data */