Merge pull request #423 from TheKodeToad/addagent
Fixes https://github.com/PrismLauncher/PrismLauncher/issues/414
This commit is contained in:
commit
ab23f542c6
@ -10,7 +10,7 @@ typedef std::shared_ptr<Agent> AgentPtr;
|
|||||||
|
|
||||||
class Agent {
|
class Agent {
|
||||||
public:
|
public:
|
||||||
Agent(LibraryPtr library, QString &argument)
|
Agent(LibraryPtr library, const QString &argument)
|
||||||
{
|
{
|
||||||
m_library = library;
|
m_library = library;
|
||||||
m_argument = argument;
|
m_argument = argument;
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// 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 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -47,7 +48,6 @@
|
|||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "minecraft/OneSixVersionFormat.h"
|
#include "minecraft/OneSixVersionFormat.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "meta/Index.h"
|
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
|
||||||
@ -55,7 +55,6 @@
|
|||||||
#include "PackProfile_p.h"
|
#include "PackProfile_p.h"
|
||||||
#include "ComponentUpdateTask.h"
|
#include "ComponentUpdateTask.h"
|
||||||
|
|
||||||
#include "Application.h"
|
|
||||||
#include "modplatform/ModAPI.h"
|
#include "modplatform/ModAPI.h"
|
||||||
|
|
||||||
static const QMap<QString, ModAPI::ModLoaderType> modloaderMapping{
|
static const QMap<QString, ModAPI::ModLoaderType> modloaderMapping{
|
||||||
@ -738,6 +737,11 @@ void PackProfile::installCustomJar(QString selectedFile)
|
|||||||
installCustomJar_internal(selectedFile);
|
installCustomJar_internal(selectedFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PackProfile::installAgents(QStringList selectedFiles)
|
||||||
|
{
|
||||||
|
installAgents_internal(selectedFiles);
|
||||||
|
}
|
||||||
|
|
||||||
bool PackProfile::installEmpty(const QString& uid, const QString& name)
|
bool PackProfile::installEmpty(const QString& uid, const QString& name)
|
||||||
{
|
{
|
||||||
QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
|
QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
|
||||||
@ -832,18 +836,14 @@ bool PackProfile::installJarMods_internal(QStringList filepaths)
|
|||||||
for(auto filepath:filepaths)
|
for(auto filepath:filepaths)
|
||||||
{
|
{
|
||||||
QFileInfo sourceInfo(filepath);
|
QFileInfo sourceInfo(filepath);
|
||||||
auto uuid = QUuid::createUuid();
|
QString id = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||||
QString id = uuid.toString().remove('{').remove('}');
|
|
||||||
QString target_filename = id + ".jar";
|
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 target_name = sourceInfo.completeBaseName() + " (jar mod)";
|
||||||
QString finalPath = FS::PathCombine(d->m_instance->jarModsDir(), target_filename);
|
QString finalPath = FS::PathCombine(d->m_instance->jarModsDir(), target_filename);
|
||||||
|
|
||||||
QFileInfo targetInfo(finalPath);
|
QFileInfo targetInfo(finalPath);
|
||||||
if(targetInfo.exists())
|
Q_ASSERT(!targetInfo.exists());
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!QFile::copy(sourceInfo.absoluteFilePath(),QFileInfo(finalPath).absoluteFilePath()))
|
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 f = std::make_shared<VersionFile>();
|
||||||
auto jarMod = std::make_shared<Library>();
|
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->setFilename(target_filename);
|
||||||
jarMod->setDisplayName(sourceInfo.completeBaseName());
|
jarMod->setDisplayName(sourceInfo.completeBaseName());
|
||||||
jarMod->setHint("local");
|
jarMod->setHint("local");
|
||||||
@ -892,7 +892,7 @@ bool PackProfile::installCustomJar_internal(QString filepath)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto specifier = GradleSpecifier("org.multimc:customjar:1");
|
auto specifier = GradleSpecifier("custom:customjar:1");
|
||||||
QFileInfo sourceInfo(filepath);
|
QFileInfo sourceInfo(filepath);
|
||||||
QString target_filename = specifier.getFileName();
|
QString target_filename = specifier.getFileName();
|
||||||
QString target_id = specifier.artifactId();
|
QString target_id = specifier.artifactId();
|
||||||
@ -939,6 +939,64 @@ bool PackProfile::installCustomJar_internal(QString filepath)
|
|||||||
return true;
|
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
|
std::shared_ptr<LaunchProfile> PackProfile::getProfile() const
|
||||||
{
|
{
|
||||||
if(!d->m_profile)
|
if(!d->m_profile)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// 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 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* 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
|
/// install a jar/zip as a replacement for the main jar
|
||||||
void installCustomJar(QString selectedFile);
|
void installCustomJar(QString selectedFile);
|
||||||
|
|
||||||
|
/// install Java agent files
|
||||||
|
void installAgents(QStringList selectedFiles);
|
||||||
|
|
||||||
enum MoveDirection { MoveUp, MoveDown };
|
enum MoveDirection { MoveUp, MoveDown };
|
||||||
/// move component file # up or down the list
|
/// move component file # up or down the list
|
||||||
void move(const int index, const MoveDirection direction);
|
void move(const int index, const MoveDirection direction);
|
||||||
@ -167,6 +171,7 @@ private:
|
|||||||
bool load();
|
bool load();
|
||||||
bool installJarMods_internal(QStringList filepaths);
|
bool installJarMods_internal(QStringList filepaths);
|
||||||
bool installCustomJar_internal(QString filepath);
|
bool installCustomJar_internal(QString filepath);
|
||||||
|
bool installAgents_internal(QStringList filepaths);
|
||||||
bool removeComponent_internal(ComponentPtr patch);
|
bool removeComponent_internal(ComponentPtr patch);
|
||||||
|
|
||||||
private: /* data */
|
private: /* data */
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// 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 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* 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
|
* 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
|
* 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->actionInstall_mods->setEnabled(controlsEnabled);
|
||||||
ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled);
|
ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled);
|
||||||
ui->actionAdd_to_Minecraft_jar->setEnabled(controlsEnabled);
|
ui->actionAdd_to_Minecraft_jar->setEnabled(controlsEnabled);
|
||||||
|
ui->actionAdd_Agents->setEnabled(controlsEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VersionPage::reloadPackProfile()
|
bool VersionPage::reloadPackProfile()
|
||||||
@ -342,6 +344,18 @@ void VersionPage::on_actionReplace_Minecraft_jar_triggered()
|
|||||||
updateButtons();
|
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()
|
void VersionPage::on_actionMove_up_triggered()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// 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 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* 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_actionMove_down_triggered();
|
||||||
void on_actionAdd_to_Minecraft_jar_triggered();
|
void on_actionAdd_to_Minecraft_jar_triggered();
|
||||||
void on_actionReplace_Minecraft_jar_triggered();
|
void on_actionReplace_Minecraft_jar_triggered();
|
||||||
|
void on_actionAdd_Agents_triggered();
|
||||||
void on_actionRevert_triggered();
|
void on_actionRevert_triggered();
|
||||||
void on_actionEdit_triggered();
|
void on_actionEdit_triggered();
|
||||||
void on_actionInstall_mods_triggered();
|
void on_actionInstall_mods_triggered();
|
||||||
|
@ -109,6 +109,7 @@
|
|||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionAdd_to_Minecraft_jar"/>
|
<addaction name="actionAdd_to_Minecraft_jar"/>
|
||||||
<addaction name="actionReplace_Minecraft_jar"/>
|
<addaction name="actionReplace_Minecraft_jar"/>
|
||||||
|
<addaction name="actionAdd_Agents"/>
|
||||||
<addaction name="actionAdd_Empty"/>
|
<addaction name="actionAdd_Empty"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionMinecraftFolder"/>
|
<addaction name="actionMinecraftFolder"/>
|
||||||
@ -226,6 +227,14 @@
|
|||||||
<string>Replace Minecraft.jar</string>
|
<string>Replace Minecraft.jar</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</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">
|
<action name="actionAdd_Empty">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add Empty</string>
|
<string>Add Empty</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user