Merge pull request #735 from Scrumplex/import-component

This commit is contained in:
Sefa Eyeoglu 2023-03-01 09:49:47 +01:00 committed by GitHub
commit 4878f1a438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 9 deletions

View File

@ -1,7 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2022-2023 Sefa Eyeoglu <contact@scrumplex.net>
//
// SPDX-License-Identifier: GPL-3.0-only AND Apache-2.0
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022-2023 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
@ -49,6 +52,7 @@
#include "minecraft/OneSixVersionFormat.h"
#include "FileSystem.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/ProfileUtils.h"
#include "Json.h"
#include "PackProfile.h"
@ -730,16 +734,47 @@ void PackProfile::invalidateLaunchProfile()
void PackProfile::installJarMods(QStringList selectedFiles)
{
// FIXME: get rid of _internal
installJarMods_internal(selectedFiles);
}
void PackProfile::installCustomJar(QString selectedFile)
{
// FIXME: get rid of _internal
installCustomJar_internal(selectedFile);
}
bool PackProfile::installComponents(QStringList selectedFiles)
{
const QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
if (!FS::ensureFolderPathExists(patchDir))
return false;
bool result = true;
for (const QString& source : selectedFiles) {
const QFileInfo sourceInfo(source);
auto versionFile = ProfileUtils::parseJsonFile(sourceInfo, false);
const QString target = FS::PathCombine(patchDir, versionFile->uid + ".json");
if (!QFile::copy(source, target)) {
qWarning() << "Component" << source << "could not be copied to target" << target;
result = false;
continue;
}
appendComponent(new Component(this, versionFile->uid, versionFile));
}
scheduleSave();
invalidateLaunchProfile();
return result;
}
void PackProfile::installAgents(QStringList selectedFiles)
{
// FIXME: get rid of _internal
installAgents_internal(selectedFiles);
}

View File

@ -1,7 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2022-2023 Sefa Eyeoglu <contact@scrumplex.net>
//
// SPDX-License-Identifier: GPL-3.0-only AND Apache-2.0
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022-2023 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
@ -86,6 +89,9 @@ public:
/// install a jar/zip as a replacement for the main jar
void installCustomJar(QString selectedFile);
/// install MMC/Prism component files
bool installComponents(QStringList selectedFiles);
/// install Java agent files
void installAgents(QStringList selectedFiles);

View File

@ -1,8 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2022-2023 Sefa Eyeoglu <contact@scrumplex.net>
//
// SPDX-License-Identifier: GPL-3.0-only AND Apache-2.0
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022-2023 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
@ -282,6 +285,7 @@ void VersionPage::updateButtons(int row)
ui->actionRevert->setEnabled(controlsEnabled && patch && patch->isRevertible());
ui->actionDownload_All->setEnabled(controlsEnabled);
ui->actionAdd_Empty->setEnabled(controlsEnabled);
ui->actionImport_Components->setEnabled(controlsEnabled);
ui->actionReload->setEnabled(controlsEnabled);
ui->actionInstall_mods->setEnabled(controlsEnabled);
ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled);
@ -375,6 +379,20 @@ void VersionPage::on_actionReplace_Minecraft_jar_triggered()
updateButtons();
}
void VersionPage::on_actionImport_Components_triggered()
{
QStringList list = GuiUtil::BrowseForFiles("component", tr("Select components"), tr("Components (*.json)"),
APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget());
if (!list.isEmpty()) {
if (!m_profile->installComponents(list)) {
QMessageBox::warning(this, tr("Failed to import components"),
tr("Some components could not be imported. Check logs for details"));
}
}
updateButtons();
}
void VersionPage::on_actionAdd_Agents_triggered()
{

View File

@ -1,7 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2022-2023 Sefa Eyeoglu <contact@scrumplex.net>
//
// SPDX-License-Identifier: GPL-3.0-only AND Apache-2.0
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2022-2023 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
@ -86,6 +90,7 @@ private slots:
void on_actionMove_down_triggered();
void on_actionAdd_to_Minecraft_jar_triggered();
void on_actionReplace_Minecraft_jar_triggered();
void on_actionImport_Components_triggered();
void on_actionAdd_Agents_triggered();
void on_actionRevert_triggered();
void on_actionEdit_triggered();

View File

@ -108,6 +108,7 @@
<addaction name="actionReplace_Minecraft_jar"/>
<addaction name="actionAdd_Agents"/>
<addaction name="actionAdd_Empty"/>
<addaction name="actionImport_Components"/>
<addaction name="separator"/>
<addaction name="actionMinecraftFolder"/>
<addaction name="actionLibrariesFolder"/>
@ -226,10 +227,10 @@
</action>
<action name="actionAdd_Agents">
<property name="text">
<string>Add Agents</string>
<string>Add Agents</string>
</property>
<property name="toolTip">
<string>Add Java agents.</string>
<string>Add Java agents.</string>
</property>
</action>
<action name="actionAdd_Empty">
@ -272,6 +273,14 @@
<string>Open the instance's local libraries folder.</string>
</property>
</action>
<action name="actionImport_Components">
<property name="text">
<string>Import Components</string>
</property>
<property name="toolTip">
<string>Import existing component JSON files.</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>