aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-12-02 06:40:18 -0800
committerGitHub <noreply@github.com>2022-12-02 06:40:18 -0800
commitab23f542c648f09e989b2fa650031e169567a3d6 (patch)
tree4d52c134f563ab45ecfb9582e662ab46bab9ee6a
parentfa98bf1ee7cfd9fcbc956b2c603f72398d0d69ce (diff)
parent31dc82b1a64fef40ab8fadbbb80d7641456bbb0a (diff)
downloadPrismLauncher-ab23f542c648f09e989b2fa650031e169567a3d6.tar.gz
PrismLauncher-ab23f542c648f09e989b2fa650031e169567a3d6.tar.bz2
PrismLauncher-ab23f542c648f09e989b2fa650031e169567a3d6.zip
Merge pull request #423 from TheKodeToad/addagent
Fixes https://github.com/PrismLauncher/PrismLauncher/issues/414
-rw-r--r--launcher/minecraft/Agent.h2
-rw-r--r--launcher/minecraft/PackProfile.cpp82
-rw-r--r--launcher/minecraft/PackProfile.h7
-rw-r--r--launcher/ui/pages/instance/VersionPage.cpp16
-rw-r--r--launcher/ui/pages/instance/VersionPage.h4
-rw-r--r--launcher/ui/pages/instance/VersionPage.ui9
6 files changed, 104 insertions, 16 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..43fa3f8d 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,18 +836,14 @@ 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_id = "custom.jarmod." + id;
QString target_name = sourceInfo.completeBaseName() + " (jar mod)";
QString finalPath = FS::PathCombine(d->m_instance->jarModsDir(), target_filename);
QFileInfo targetInfo(finalPath);
- if(targetInfo.exists())
- {
- return false;
- }
+ Q_ASSERT(!targetInfo.exists());
if (!QFile::copy(sourceInfo.absoluteFilePath(),QFileInfo(finalPath).absoluteFilePath()))
{
@@ -852,7 +852,7 @@ bool PackProfile::installJarMods_internal(QStringList filepaths)
auto f = std::make_shared<VersionFile>();
auto jarMod = std::make_shared<Library>();
- jarMod->setRawName(GradleSpecifier("org.multimc.jarmods:" + id + ":1"));
+ jarMod->setRawName(GradleSpecifier("custom.jarmods:" + id + ":1"));
jarMod->setFilename(target_filename);
jarMod->setDisplayName(sourceInfo.completeBaseName());
jarMod->setHint("local");
@@ -892,7 +892,7 @@ bool PackProfile::installCustomJar_internal(QString filepath)
return false;
}
- auto specifier = GradleSpecifier("org.multimc:customjar:1");
+ auto specifier = GradleSpecifier("custom:customjar:1");
QFileInfo sourceInfo(filepath);
QString target_filename = specifier.getFileName();
QString target_id = specifier.artifactId();
@@ -939,6 +939,64 @@ 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 = "custom.agent." + id;
+ const QString targetName = sourceInfo.completeBaseName() + " (agent)";
+ const QString target = FS::PathCombine(d->m_instance->getLocalLibraryPath(), targetBaseName);
+
+ const QFileInfo targetInfo(target);
+ Q_ASSERT(!targetInfo.exists());
+
+ if (!QFile::copy(source, target))
+ return false;
+
+ auto versionFile = std::make_shared<VersionFile>();
+
+ auto agent = std::make_shared<Library>();
+
+ agent->setRawName("custom.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 */
diff --git a/launcher/ui/pages/instance/VersionPage.cpp b/launcher/ui/pages/instance/VersionPage.cpp
index a021c633..7f98cba2 100644
--- a/launcher/ui/pages/instance/VersionPage.cpp
+++ b/launcher/ui/pages/instance/VersionPage.cpp
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
+ * Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* 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
@@ -270,6 +271,7 @@ void VersionPage::updateButtons(int row)
ui->actionInstall_mods->setEnabled(controlsEnabled);
ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled);
ui->actionAdd_to_Minecraft_jar->setEnabled(controlsEnabled);
+ ui->actionAdd_Agents->setEnabled(controlsEnabled);
}
bool VersionPage::reloadPackProfile()
@@ -342,6 +344,18 @@ void VersionPage::on_actionReplace_Minecraft_jar_triggered()
updateButtons();
}
+
+void VersionPage::on_actionAdd_Agents_triggered()
+{
+ QStringList list = GuiUtil::BrowseForFiles("agent", tr("Select agents"), tr("Java agents (*.jar)"),
+ APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget());
+
+ if (!list.isEmpty())
+ m_profile->installAgents(list);
+
+ updateButtons();
+}
+
void VersionPage::on_actionMove_up_triggered()
{
try
diff --git a/launcher/ui/pages/instance/VersionPage.h b/launcher/ui/pages/instance/VersionPage.h
index 979311fc..23d2a1b3 100644
--- a/launcher/ui/pages/instance/VersionPage.h
+++ b/launcher/ui/pages/instance/VersionPage.h
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
+ * Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
+ * 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
@@ -82,6 +83,7 @@ private slots:
void on_actionMove_down_triggered();
void on_actionAdd_to_Minecraft_jar_triggered();
void on_actionReplace_Minecraft_jar_triggered();
+ void on_actionAdd_Agents_triggered();
void on_actionRevert_triggered();
void on_actionEdit_triggered();
void on_actionInstall_mods_triggered();
diff --git a/launcher/ui/pages/instance/VersionPage.ui b/launcher/ui/pages/instance/VersionPage.ui
index 14b7cd9f..74b9568a 100644
--- a/launcher/ui/pages/instance/VersionPage.ui
+++ b/launcher/ui/pages/instance/VersionPage.ui
@@ -109,6 +109,7 @@
<addaction name="separator"/>
<addaction name="actionAdd_to_Minecraft_jar"/>
<addaction name="actionReplace_Minecraft_jar"/>
+ <addaction name="actionAdd_Agents"/>
<addaction name="actionAdd_Empty"/>
<addaction name="separator"/>
<addaction name="actionMinecraftFolder"/>
@@ -226,6 +227,14 @@
<string>Replace Minecraft.jar</string>
</property>
</action>
+ <action name="actionAdd_Agents">
+ <property name="text">
+ <string>Add Agents</string>
+ </property>
+ <property name="toolTip">
+ <string>Add Java agents.</string>
+ </property>
+ </action>
<action name="actionAdd_Empty">
<property name="text">
<string>Add Empty</string>