feat: add button to import component JSONs
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
@ -49,6 +49,7 @@
|
||||
#include "minecraft/OneSixVersionFormat.h"
|
||||
#include "FileSystem.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/ProfileUtils.h"
|
||||
#include "Json.h"
|
||||
|
||||
#include "PackProfile.h"
|
||||
@ -737,6 +738,11 @@ void PackProfile::installCustomJar(QString selectedFile)
|
||||
installCustomJar_internal(selectedFile);
|
||||
}
|
||||
|
||||
void PackProfile::installComponents(QStringList selectedFiles)
|
||||
{
|
||||
installComponents_internal(selectedFiles);
|
||||
}
|
||||
|
||||
void PackProfile::installAgents(QStringList selectedFiles)
|
||||
{
|
||||
installAgents_internal(selectedFiles);
|
||||
@ -939,6 +945,32 @@ bool PackProfile::installCustomJar_internal(QString filepath)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PackProfile::installComponents_internal(QStringList filepaths)
|
||||
{
|
||||
const QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
|
||||
if (!FS::ensureFolderPathExists(patchDir))
|
||||
return false;
|
||||
|
||||
for (const QString& source : filepaths) {
|
||||
const QFileInfo sourceInfo(source);
|
||||
|
||||
auto versionFile = ProfileUtils::parseJsonFile(sourceInfo, false);
|
||||
const QString target = FS::PathCombine(patchDir, versionFile->uid + ".json");
|
||||
|
||||
if (!QFile::copy(source, target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
appendComponent(new Component(this, versionFile->uid, versionFile));
|
||||
}
|
||||
|
||||
scheduleSave();
|
||||
invalidateLaunchProfile();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PackProfile::installAgents_internal(QStringList filepaths)
|
||||
{
|
||||
// FIXME code duplication
|
||||
|
@ -86,6 +86,9 @@ public:
|
||||
/// install a jar/zip as a replacement for the main jar
|
||||
void installCustomJar(QString selectedFile);
|
||||
|
||||
/// install MMC/Prism component files
|
||||
void installComponents(QStringList selectedFiles);
|
||||
|
||||
/// install Java agent files
|
||||
void installAgents(QStringList selectedFiles);
|
||||
|
||||
@ -171,6 +174,7 @@ private:
|
||||
bool load();
|
||||
bool installJarMods_internal(QStringList filepaths);
|
||||
bool installCustomJar_internal(QString filepath);
|
||||
bool installComponents_internal(QStringList filepaths);
|
||||
bool installAgents_internal(QStringList filepaths);
|
||||
bool removeComponent_internal(ComponentPtr patch);
|
||||
|
||||
|
Reference in New Issue
Block a user