Added FTBAPP Import
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
9499066375
commit
843c2d67eb
@ -498,6 +498,11 @@ set(FTB_SOURCES
|
|||||||
modplatform/legacy_ftb/PrivatePackManager.cpp
|
modplatform/legacy_ftb/PrivatePackManager.cpp
|
||||||
|
|
||||||
modplatform/legacy_ftb/PackHelpers.h
|
modplatform/legacy_ftb/PackHelpers.h
|
||||||
|
|
||||||
|
modplatform/import_ftb/PackInstallTask.h
|
||||||
|
modplatform/import_ftb/PackInstallTask.cpp
|
||||||
|
modplatform/import_ftb/PackHelpers.h
|
||||||
|
modplatform/import_ftb/PackHelpers.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FLAME_SOURCES
|
set(FLAME_SOURCES
|
||||||
@ -867,6 +872,11 @@ SET(LAUNCHER_SOURCES
|
|||||||
ui/pages/modplatform/legacy_ftb/ListModel.h
|
ui/pages/modplatform/legacy_ftb/ListModel.h
|
||||||
ui/pages/modplatform/legacy_ftb/ListModel.cpp
|
ui/pages/modplatform/legacy_ftb/ListModel.cpp
|
||||||
|
|
||||||
|
ui/pages/modplatform/import_ftb/ImportFTBPage.cpp
|
||||||
|
ui/pages/modplatform/import_ftb/ImportFTBPage.h
|
||||||
|
ui/pages/modplatform/import_ftb/ListModel.h
|
||||||
|
ui/pages/modplatform/import_ftb/ListModel.cpp
|
||||||
|
|
||||||
ui/pages/modplatform/flame/FlameModel.cpp
|
ui/pages/modplatform/flame/FlameModel.cpp
|
||||||
ui/pages/modplatform/flame/FlameModel.h
|
ui/pages/modplatform/flame/FlameModel.h
|
||||||
ui/pages/modplatform/flame/FlamePage.cpp
|
ui/pages/modplatform/flame/FlamePage.cpp
|
||||||
@ -1039,6 +1049,7 @@ qt_wrap_ui(LAUNCHER_UI
|
|||||||
ui/pages/modplatform/ResourcePage.ui
|
ui/pages/modplatform/ResourcePage.ui
|
||||||
ui/pages/modplatform/flame/FlamePage.ui
|
ui/pages/modplatform/flame/FlamePage.ui
|
||||||
ui/pages/modplatform/legacy_ftb/Page.ui
|
ui/pages/modplatform/legacy_ftb/Page.ui
|
||||||
|
ui/pages/modplatform/import_ftb/ImportFTBPage.ui
|
||||||
ui/pages/modplatform/ImportPage.ui
|
ui/pages/modplatform/ImportPage.ui
|
||||||
ui/pages/modplatform/modrinth/ModrinthPage.ui
|
ui/pages/modplatform/modrinth/ModrinthPage.ui
|
||||||
ui/pages/modplatform/technic/TechnicPage.ui
|
ui/pages/modplatform/technic/TechnicPage.ui
|
||||||
|
87
launcher/modplatform/import_ftb/PackHelpers.cpp
Normal file
87
launcher/modplatform/import_ftb/PackHelpers.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "modplatform/import_ftb/PackHelpers.h"
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "Json.h"
|
||||||
|
|
||||||
|
namespace FTBImportAPP {
|
||||||
|
|
||||||
|
Modpack parseDirectory(QString path)
|
||||||
|
{
|
||||||
|
Modpack modpack{ path };
|
||||||
|
auto instanceFile = QFileInfo(FS::PathCombine(path, "instance.json"));
|
||||||
|
if (!instanceFile.exists() || !instanceFile.isFile())
|
||||||
|
return {};
|
||||||
|
try {
|
||||||
|
auto doc = Json::requireDocument(instanceFile.absoluteFilePath(), "FTB_APP instance JSON file");
|
||||||
|
const auto root = doc.object();
|
||||||
|
modpack.uuid = Json::requireString(root, "uuid", "uuid");
|
||||||
|
modpack.id = Json::requireInteger(root, "id", "id");
|
||||||
|
modpack.versionId = Json::requireInteger(root, "versionId", "versionId");
|
||||||
|
modpack.name = Json::requireString(root, "name", "name");
|
||||||
|
modpack.version = Json::requireString(root, "version", "version");
|
||||||
|
modpack.mcVersion = Json::requireString(root, "mcVersion", "mcVersion");
|
||||||
|
modpack.jvmArgs = Json::requireVariant(root, "jvmArgs", "jvmArgs");
|
||||||
|
} catch (const Exception& e) {
|
||||||
|
qDebug() << "Couldn't load ftb instance json: " << e.cause();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
auto versionsFile = QFileInfo(FS::PathCombine(path, "version.json"));
|
||||||
|
if (!versionsFile.exists() || !versionsFile.isFile())
|
||||||
|
return {};
|
||||||
|
try {
|
||||||
|
auto doc = Json::requireDocument(versionsFile.absoluteFilePath(), "FTB_APP version JSON file");
|
||||||
|
const auto root = doc.object();
|
||||||
|
auto targets = Json::requireArray(root, "targets", "targets");
|
||||||
|
|
||||||
|
for (auto target : targets) {
|
||||||
|
auto obj = Json::requireObject(target, "target");
|
||||||
|
auto name = Json::requireString(obj, "name", "name");
|
||||||
|
auto version = Json::requireString(obj, "version", "version");
|
||||||
|
if (name == "forge") {
|
||||||
|
modpack.loaderType = ResourceAPI::Forge;
|
||||||
|
modpack.version = version;
|
||||||
|
break;
|
||||||
|
} else if (name == "fabric") {
|
||||||
|
modpack.loaderType = ResourceAPI::Fabric;
|
||||||
|
modpack.version = version;
|
||||||
|
break;
|
||||||
|
} else if (name == "quilt") {
|
||||||
|
modpack.loaderType = ResourceAPI::Quilt;
|
||||||
|
modpack.version = version;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const Exception& e) {
|
||||||
|
qDebug() << "Couldn't load ftb version json: " << e.cause();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
auto iconFile = QFileInfo(FS::PathCombine(path, "folder.jpg"));
|
||||||
|
if (iconFile.exists() && iconFile.isFile()) {
|
||||||
|
modpack.icon = QIcon(iconFile.absoluteFilePath());
|
||||||
|
}
|
||||||
|
return modpack;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace FTBImportAPP
|
55
launcher/modplatform/import_ftb/PackHelpers.h
Normal file
55
launcher/modplatform/import_ftb/PackHelpers.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QList>
|
||||||
|
#include <QMetaType>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
#include "modplatform/ResourceAPI.h"
|
||||||
|
|
||||||
|
namespace FTBImportAPP {
|
||||||
|
|
||||||
|
struct Modpack {
|
||||||
|
QString path;
|
||||||
|
|
||||||
|
// json data
|
||||||
|
QString uuid;
|
||||||
|
int id;
|
||||||
|
int versionId;
|
||||||
|
QString name;
|
||||||
|
QString version;
|
||||||
|
QString mcVersion;
|
||||||
|
// not needed for instance creation
|
||||||
|
QVariant jvmArgs;
|
||||||
|
|
||||||
|
std::optional<ResourceAPI::ModLoaderType> loaderType;
|
||||||
|
QString loaderVersion;
|
||||||
|
|
||||||
|
QIcon icon;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef QList<Modpack> ModpackList;
|
||||||
|
|
||||||
|
Modpack parseDirectory(QString path);
|
||||||
|
|
||||||
|
} // namespace FTBImportAPP
|
||||||
|
|
||||||
|
// We need it for the proxy model
|
||||||
|
Q_DECLARE_METATYPE(FTBImportAPP::Modpack)
|
102
launcher/modplatform/import_ftb/PackInstallTask.cpp
Normal file
102
launcher/modplatform/import_ftb/PackInstallTask.cpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PackInstallTask.h"
|
||||||
|
|
||||||
|
#include <QtConcurrent>
|
||||||
|
|
||||||
|
#include "BaseInstance.h"
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "minecraft/MinecraftInstance.h"
|
||||||
|
#include "minecraft/PackProfile.h"
|
||||||
|
#include "modplatform/ResourceAPI.h"
|
||||||
|
#include "modplatform/import_ftb/PackHelpers.h"
|
||||||
|
#include "settings/INISettingsObject.h"
|
||||||
|
|
||||||
|
namespace FTBImportAPP {
|
||||||
|
|
||||||
|
void PackInstallTask::executeTask()
|
||||||
|
{
|
||||||
|
setStatus(tr("Copy files"));
|
||||||
|
setAbortable(false);
|
||||||
|
progress(1, 2);
|
||||||
|
|
||||||
|
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this] {
|
||||||
|
FS::copy folderCopy(m_pack.path, FS::PathCombine(m_stagingPath, ".minecraft"));
|
||||||
|
folderCopy.followSymlinks(true);
|
||||||
|
return folderCopy();
|
||||||
|
});
|
||||||
|
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::finished, this, &PackInstallTask::copySettings);
|
||||||
|
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::canceled, this, &PackInstallTask::emitAborted);
|
||||||
|
m_copyFutureWatcher.setFuture(m_copyFuture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PackInstallTask::copySettings()
|
||||||
|
{
|
||||||
|
setStatus(tr("Copy settings"));
|
||||||
|
progress(2, 2);
|
||||||
|
QString instanceConfigPath = FS::PathCombine(m_stagingPath, "instance.cfg");
|
||||||
|
auto instanceSettings = std::make_shared<INISettingsObject>(instanceConfigPath);
|
||||||
|
instanceSettings->suspendSave();
|
||||||
|
instanceSettings->registerSetting("InstanceType", "OneSix");
|
||||||
|
instanceSettings->set("InstanceType", "OneSix");
|
||||||
|
|
||||||
|
if (m_pack.jvmArgs.isValid() && !m_pack.jvmArgs.toString().isEmpty()) {
|
||||||
|
instanceSettings->registerSetting("OverrideJavaArgs", true);
|
||||||
|
instanceSettings->set("OverrideJavaArgs", true);
|
||||||
|
instanceSettings->registerSetting("JvmArgs", m_pack.jvmArgs.toString());
|
||||||
|
instanceSettings->set("JvmArgs", m_pack.jvmArgs.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
|
||||||
|
auto components = instance.getPackProfile();
|
||||||
|
components->buildingFromScratch();
|
||||||
|
components->setComponentVersion("net.minecraft", m_pack.mcVersion, true);
|
||||||
|
|
||||||
|
auto modloader = m_pack.loaderType;
|
||||||
|
if (modloader.has_value())
|
||||||
|
switch (modloader.value()) {
|
||||||
|
case ResourceAPI::Forge: {
|
||||||
|
components->setComponentVersion("net.minecraftforge", m_pack.version, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ResourceAPI::Fabric: {
|
||||||
|
components->setComponentVersion("net.fabricmc.fabric-loader", m_pack.version, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ResourceAPI::Quilt: {
|
||||||
|
components->setComponentVersion("org.quiltmc.quilt-loader", m_pack.version, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ResourceAPI::Cauldron:
|
||||||
|
break;
|
||||||
|
case ResourceAPI::LiteLoader:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
components->saveNow();
|
||||||
|
|
||||||
|
instance.setName(name());
|
||||||
|
if (m_instIcon == "default")
|
||||||
|
m_instIcon = "ftb_logo";
|
||||||
|
instance.setIconKey(m_instIcon);
|
||||||
|
instanceSettings->resumeSave();
|
||||||
|
|
||||||
|
emitSucceeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace FTBImportAPP
|
49
launcher/modplatform/import_ftb/PackInstallTask.h
Normal file
49
launcher/modplatform/import_ftb/PackInstallTask.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QFuture>
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
|
||||||
|
#include "InstanceTask.h"
|
||||||
|
#include "PackHelpers.h"
|
||||||
|
|
||||||
|
namespace FTBImportAPP {
|
||||||
|
|
||||||
|
class PackInstallTask : public InstanceTask {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit PackInstallTask(Modpack pack) : m_pack(pack) {}
|
||||||
|
virtual ~PackInstallTask() = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void executeTask() override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void copySettings();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QFuture<bool> m_copyFuture;
|
||||||
|
QFutureWatcher<bool> m_copyFutureWatcher;
|
||||||
|
|
||||||
|
Modpack m_pack;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace FTBImportAPP
|
@ -33,38 +33,37 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Application.h"
|
|
||||||
#include "NewInstanceDialog.h"
|
#include "NewInstanceDialog.h"
|
||||||
|
#include "Application.h"
|
||||||
|
#include "ui/pages/modplatform/import_ftb/ImportFTBPage.h"
|
||||||
#include "ui_NewInstanceDialog.h"
|
#include "ui_NewInstanceDialog.h"
|
||||||
|
|
||||||
#include <BaseVersion.h>
|
#include <BaseVersion.h>
|
||||||
|
#include <InstanceList.h>
|
||||||
#include <icons/IconList.h>
|
#include <icons/IconList.h>
|
||||||
#include <tasks/Task.h>
|
#include <tasks/Task.h>
|
||||||
#include <InstanceList.h>
|
|
||||||
|
|
||||||
#include "VersionSelectDialog.h"
|
|
||||||
#include "ProgressDialog.h"
|
|
||||||
#include "IconPickerDialog.h"
|
#include "IconPickerDialog.h"
|
||||||
|
#include "ProgressDialog.h"
|
||||||
|
#include "VersionSelectDialog.h"
|
||||||
|
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QValidator>
|
#include <QValidator>
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "ui/widgets/PageContainer.h"
|
|
||||||
#include "ui/pages/modplatform/CustomPage.h"
|
#include "ui/pages/modplatform/CustomPage.h"
|
||||||
#include "ui/pages/modplatform/atlauncher/AtlPage.h"
|
|
||||||
#include "ui/pages/modplatform/legacy_ftb/Page.h"
|
|
||||||
#include "ui/pages/modplatform/flame/FlamePage.h"
|
|
||||||
#include "ui/pages/modplatform/ImportPage.h"
|
#include "ui/pages/modplatform/ImportPage.h"
|
||||||
|
#include "ui/pages/modplatform/atlauncher/AtlPage.h"
|
||||||
|
#include "ui/pages/modplatform/flame/FlamePage.h"
|
||||||
|
#include "ui/pages/modplatform/legacy_ftb/Page.h"
|
||||||
#include "ui/pages/modplatform/modrinth/ModrinthPage.h"
|
#include "ui/pages/modplatform/modrinth/ModrinthPage.h"
|
||||||
#include "ui/pages/modplatform/technic/TechnicPage.h"
|
#include "ui/pages/modplatform/technic/TechnicPage.h"
|
||||||
|
#include "ui/widgets/PageContainer.h"
|
||||||
|
|
||||||
|
NewInstanceDialog::NewInstanceDialog(const QString& initialGroup, const QString& url, QWidget* parent)
|
||||||
|
|
||||||
NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString & url, QWidget *parent)
|
|
||||||
: QDialog(parent), ui(new Ui::NewInstanceDialog)
|
: QDialog(parent), ui(new Ui::NewInstanceDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -168,6 +167,7 @@ QList<BasePage *> NewInstanceDialog::getPages()
|
|||||||
if (APPLICATION->capabilities() & Application::SupportsFlame)
|
if (APPLICATION->capabilities() & Application::SupportsFlame)
|
||||||
pages.append(new FlamePage(this));
|
pages.append(new FlamePage(this));
|
||||||
pages.append(new LegacyFTB::Page(this));
|
pages.append(new LegacyFTB::Page(this));
|
||||||
|
pages.append(new FTBImportAPP::ImportFTBPage(this));
|
||||||
pages.append(new ModrinthPage(this));
|
pages.append(new ModrinthPage(this));
|
||||||
pages.append(new TechnicPage(this));
|
pages.append(new TechnicPage(this));
|
||||||
|
|
||||||
|
104
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp
Normal file
104
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ImportFTBPage.h"
|
||||||
|
#include "ui_ImportFTBPage.h"
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "ListModel.h"
|
||||||
|
#include "modplatform/import_ftb/PackInstallTask.h"
|
||||||
|
#include "ui/dialogs/NewInstanceDialog.h"
|
||||||
|
|
||||||
|
namespace FTBImportAPP {
|
||||||
|
|
||||||
|
ImportFTBPage::ImportFTBPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), dialog(dialog), ui(new Ui::ImportFTBPage)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
{
|
||||||
|
listModel = new ListModel(this);
|
||||||
|
|
||||||
|
ui->modpackList->setModel(listModel);
|
||||||
|
ui->modpackList->setSortingEnabled(true);
|
||||||
|
ui->modpackList->header()->hide();
|
||||||
|
ui->modpackList->setIndentation(0);
|
||||||
|
ui->modpackList->setIconSize(QSize(42, 42));
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(ui->modpackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &ImportFTBPage::onPublicPackSelectionChanged);
|
||||||
|
|
||||||
|
ui->modpackList->selectionModel()->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImportFTBPage::~ImportFTBPage()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportFTBPage::openedImpl()
|
||||||
|
{
|
||||||
|
if (!initialized) {
|
||||||
|
listModel->update();
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
suggestCurrent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportFTBPage::retranslate()
|
||||||
|
{
|
||||||
|
ui->retranslateUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportFTBPage::suggestCurrent()
|
||||||
|
{
|
||||||
|
if (!isOpened)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (selected.path.isEmpty()) {
|
||||||
|
dialog->setSuggestedPack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog->setSuggestedPack(selected.name, new PackInstallTask(selected));
|
||||||
|
QString editedLogoName = QString("ftb_%1").arg(selected.id);
|
||||||
|
dialog->setSuggestedIconFromFile(FS::PathCombine(selected.path, "folder.jpg"), editedLogoName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportFTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||||
|
{
|
||||||
|
if (!now.isValid()) {
|
||||||
|
onPackSelectionChanged();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Modpack selectedPack = listModel->data(now, Qt::UserRole).value<Modpack>();
|
||||||
|
onPackSelectionChanged(&selectedPack);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportFTBPage::onPackSelectionChanged(Modpack* pack)
|
||||||
|
{
|
||||||
|
if (pack) {
|
||||||
|
selected = *pack;
|
||||||
|
suggestCurrent();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isOpened)
|
||||||
|
dialog->setSuggestedPack();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace FTBImportAPP
|
67
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h
Normal file
67
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QTextBrowser>
|
||||||
|
#include <QTreeView>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
#include "modplatform/import_ftb/PackHelpers.h"
|
||||||
|
#include "ui/pages/BasePage.h"
|
||||||
|
#include "ui/pages/modplatform/import_ftb/ListModel.h"
|
||||||
|
|
||||||
|
class NewInstanceDialog;
|
||||||
|
|
||||||
|
namespace FTBImportAPP {
|
||||||
|
namespace Ui {
|
||||||
|
class ImportFTBPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ImportFTBPage : public QWidget, public BasePage {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ImportFTBPage(NewInstanceDialog* dialog, QWidget* parent = 0);
|
||||||
|
virtual ~ImportFTBPage();
|
||||||
|
QString displayName() const override { return "FTB App Import"; }
|
||||||
|
QIcon icon() const override { return APPLICATION->getThemedIcon("ftb_logo"); }
|
||||||
|
QString id() const override { return "import_ftb"; }
|
||||||
|
QString helpPage() const override { return "FTB-platform"; }
|
||||||
|
bool shouldDisplay() const override { return true; }
|
||||||
|
void openedImpl() override;
|
||||||
|
void retranslate() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void suggestCurrent();
|
||||||
|
void onPackSelectionChanged(Modpack* pack = nullptr);
|
||||||
|
private slots:
|
||||||
|
void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool initialized = false;
|
||||||
|
Modpack selected;
|
||||||
|
ListModel* listModel = nullptr;
|
||||||
|
|
||||||
|
NewInstanceDialog* dialog = nullptr;
|
||||||
|
Ui::ImportFTBPage* ui = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace FTBImportAPP
|
28
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui
Normal file
28
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>FTBImportAPP::ImportFTBPage</class>
|
||||||
|
<widget class="QWidget" name="FTBImportAPP::ImportFTBPage">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1461</width>
|
||||||
|
<height>1011</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeView" name="modpackList">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
89
launcher/ui/pages/modplatform/import_ftb/ListModel.cpp
Normal file
89
launcher/ui/pages/modplatform/import_ftb/ListModel.cpp
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ListModel.h"
|
||||||
|
#include <qnamespace.h>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDirIterator>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "modplatform/import_ftb/PackHelpers.h"
|
||||||
|
|
||||||
|
namespace FTBImportAPP {
|
||||||
|
|
||||||
|
QString getPath()
|
||||||
|
{
|
||||||
|
QString partialPath;
|
||||||
|
#if defined(Q_OS_OSX)
|
||||||
|
partialPath = FS::PathCombine(QDir::homePath(), "Library/Application Support");
|
||||||
|
#elif defined(Q_OS_WIN32)
|
||||||
|
partialPath = QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA", "");
|
||||||
|
#else
|
||||||
|
partialPath = QDir::homePath();
|
||||||
|
#endif
|
||||||
|
return FS::PathCombine(partialPath, ".ftba");
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString ListModel::FTB_APP_PATH = getPath();
|
||||||
|
|
||||||
|
void ListModel::update()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
modpacks.clear();
|
||||||
|
|
||||||
|
QString instancesPath = FS::PathCombine(FTB_APP_PATH, "instances");
|
||||||
|
if (auto instancesInfo = QFileInfo(instancesPath); instancesInfo.exists() && instancesInfo.isDir()) {
|
||||||
|
QDirIterator directoryIterator(instancesPath, QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable | QDir::Hidden,
|
||||||
|
QDirIterator::FollowSymlinks);
|
||||||
|
while (directoryIterator.hasNext()) {
|
||||||
|
auto modpack = parseDirectory(directoryIterator.next());
|
||||||
|
if (!modpack.path.isEmpty())
|
||||||
|
modpacks.append(modpack);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "Couldn't find ftb instances folder: " << instancesPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ListModel::data(const QModelIndex& index, int role) const
|
||||||
|
{
|
||||||
|
int pos = index.row();
|
||||||
|
if (pos >= modpacks.size() || pos < 0 || !index.isValid()) {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pack = modpacks.at(pos);
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
return pack.name;
|
||||||
|
} else if (role == Qt::DecorationRole) {
|
||||||
|
return pack.icon;
|
||||||
|
} else if (role == Qt::UserRole) {
|
||||||
|
QVariant v;
|
||||||
|
v.setValue(pack);
|
||||||
|
return v;
|
||||||
|
} else if (role == Qt::ToolTipRole) {
|
||||||
|
return tr("Minecraft %1").arg(pack.mcVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
} // namespace FTBImportAPP
|
46
launcher/ui/pages/modplatform/import_ftb/ListModel.h
Normal file
46
launcher/ui/pages/modplatform/import_ftb/ListModel.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QVariant>
|
||||||
|
#include "modplatform/import_ftb/PackHelpers.h"
|
||||||
|
|
||||||
|
namespace FTBImportAPP {
|
||||||
|
|
||||||
|
class ListModel : public QAbstractListModel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ListModel(QObject* parent) : QAbstractListModel(parent) {}
|
||||||
|
virtual ~ListModel() = default;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex& parent) const { return modpacks.size(); }
|
||||||
|
int columnCount(const QModelIndex& parent) const { return 1; }
|
||||||
|
QVariant data(const QModelIndex& index, int role) const;
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
static const QString FTB_APP_PATH;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ModpackList modpacks;
|
||||||
|
};
|
||||||
|
} // namespace FTBImportAPP
|
Loading…
Reference in New Issue
Block a user