2022-05-02 18:33:21 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* PolyMC - Minecraft Launcher
|
2022-05-15 12:20:05 +01:00
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
2022-05-02 18:33:21 +01:00
|
|
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
2020-06-07 16:46:12 +01:00
|
|
|
*
|
2022-05-02 18:33:21 +01:00
|
|
|
* 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.
|
2020-06-07 16:46:12 +01:00
|
|
|
*
|
2022-05-02 18:33:21 +01:00
|
|
|
* 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.
|
2020-06-07 16:46:12 +01:00
|
|
|
*
|
2022-05-02 18:33:21 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following copyright and
|
|
|
|
* permission notice:
|
|
|
|
*
|
|
|
|
* Copyright 2013-2021 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2020-06-07 16:46:12 +01:00
|
|
|
*/
|
|
|
|
|
2016-10-02 23:55:54 +01:00
|
|
|
#include "InstanceImportTask.h"
|
2022-07-08 23:44:44 +01:00
|
|
|
|
2022-04-22 02:12:14 +01:00
|
|
|
#include "Application.h"
|
2016-10-02 23:55:54 +01:00
|
|
|
#include "FileSystem.h"
|
|
|
|
#include "MMCZip.h"
|
|
|
|
#include "NullInstance.h"
|
2022-07-08 23:44:44 +01:00
|
|
|
|
2023-05-21 09:46:28 +01:00
|
|
|
#include "QObjectPtr.h"
|
2022-04-22 02:12:14 +01:00
|
|
|
#include "icons/IconList.h"
|
2019-05-31 20:52:58 +01:00
|
|
|
#include "icons/IconUtils.h"
|
2017-04-21 21:23:31 +01:00
|
|
|
|
2020-06-07 16:46:12 +01:00
|
|
|
#include "modplatform/technic/TechnicPackProcessor.h"
|
2022-07-08 01:10:41 +01:00
|
|
|
#include "modplatform/modrinth/ModrinthInstanceCreationTask.h"
|
2022-07-08 22:44:43 +01:00
|
|
|
#include "modplatform/flame/FlameInstanceCreationTask.h"
|
2016-10-02 23:55:54 +01:00
|
|
|
|
2022-07-08 23:44:44 +01:00
|
|
|
#include "settings/INISettingsObject.h"
|
2022-05-16 02:16:52 +01:00
|
|
|
|
2022-07-08 23:44:44 +01:00
|
|
|
#include <QtConcurrentRun>
|
2022-01-31 14:25:36 +00:00
|
|
|
#include <algorithm>
|
2021-11-21 22:21:12 +00:00
|
|
|
|
2022-07-08 23:44:44 +01:00
|
|
|
#include <quazip/quazipdir.h>
|
|
|
|
|
2022-11-25 13:17:43 +00:00
|
|
|
InstanceImportTask::InstanceImportTask(const QUrl sourceUrl, QWidget* parent, QMap<QString, QString>&& extra_info)
|
|
|
|
: m_sourceUrl(sourceUrl), m_extra_info(extra_info), m_parent(parent)
|
2022-11-12 14:42:07 +00:00
|
|
|
{}
|
2016-10-02 23:55:54 +01:00
|
|
|
|
2022-04-07 22:56:34 +01:00
|
|
|
bool InstanceImportTask::abort()
|
|
|
|
{
|
2022-07-31 22:21:59 +01:00
|
|
|
if (!canAbort())
|
|
|
|
return false;
|
|
|
|
|
2022-05-28 00:41:57 +01:00
|
|
|
if (m_filesNetJob)
|
|
|
|
m_filesNetJob->abort();
|
2023-02-24 23:34:43 +00:00
|
|
|
if (m_extractFuture.isRunning()) {
|
|
|
|
// NOTE: The tasks created by QtConcurrent::run() can't actually get cancelled,
|
|
|
|
// but we can use this call to check the state when the extraction finishes.
|
|
|
|
m_extractFuture.cancel();
|
|
|
|
m_extractFuture.waitForFinished();
|
|
|
|
}
|
2022-04-07 22:56:34 +01:00
|
|
|
|
2022-07-31 22:21:59 +01:00
|
|
|
return Task::abort();
|
2022-04-07 22:56:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-02 23:55:54 +01:00
|
|
|
void InstanceImportTask::executeTask()
|
|
|
|
{
|
2022-08-21 13:26:27 +01:00
|
|
|
setAbortable(true);
|
2022-07-31 22:21:59 +01:00
|
|
|
|
2022-07-08 23:44:44 +01:00
|
|
|
if (m_sourceUrl.isLocalFile()) {
|
2018-07-15 13:51:05 +01:00
|
|
|
m_archivePath = m_sourceUrl.toLocalFile();
|
|
|
|
processZipPack();
|
2022-07-08 23:44:44 +01:00
|
|
|
} else {
|
2018-07-15 13:51:05 +01:00
|
|
|
setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString()));
|
|
|
|
m_downloadRequired = true;
|
2016-10-02 23:55:54 +01:00
|
|
|
|
2022-07-08 23:44:44 +01:00
|
|
|
const QString path(m_sourceUrl.host() + '/' + m_sourceUrl.path());
|
|
|
|
|
2021-11-21 22:21:12 +00:00
|
|
|
auto entry = APPLICATION->metacache()->resolveEntry("general", path);
|
2018-07-15 13:51:05 +01:00
|
|
|
entry->setStale(true);
|
2022-07-08 23:44:44 +01:00
|
|
|
m_archivePath = entry->getFullPath();
|
|
|
|
|
2023-01-24 19:52:09 +00:00
|
|
|
m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network()));
|
2018-07-15 13:51:05 +01:00
|
|
|
m_filesNetJob->addNetAction(Net::Download::makeCached(m_sourceUrl, entry));
|
2022-07-08 23:44:44 +01:00
|
|
|
|
|
|
|
connect(m_filesNetJob.get(), &NetJob::succeeded, this, &InstanceImportTask::downloadSucceeded);
|
|
|
|
connect(m_filesNetJob.get(), &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged);
|
2023-07-26 21:20:30 +01:00
|
|
|
connect(m_filesNetJob.get(), &NetJob::stepProgress, this, &InstanceImportTask::propagateStepProgress);
|
2022-07-08 23:44:44 +01:00
|
|
|
connect(m_filesNetJob.get(), &NetJob::failed, this, &InstanceImportTask::downloadFailed);
|
2022-07-28 19:58:04 +01:00
|
|
|
connect(m_filesNetJob.get(), &NetJob::aborted, this, &InstanceImportTask::downloadAborted);
|
2022-07-08 23:44:44 +01:00
|
|
|
|
2021-12-31 04:27:59 +00:00
|
|
|
m_filesNetJob->start();
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2016-10-02 23:55:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceImportTask::downloadSucceeded()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
processZipPack();
|
|
|
|
m_filesNetJob.reset();
|
2016-10-02 23:55:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceImportTask::downloadFailed(QString reason)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
emitFailed(reason);
|
|
|
|
m_filesNetJob.reset();
|
2016-10-02 23:55:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceImportTask::downloadProgressChanged(qint64 current, qint64 total)
|
|
|
|
{
|
2022-07-08 23:44:44 +01:00
|
|
|
setProgress(current, total);
|
2016-10-02 23:55:54 +01:00
|
|
|
}
|
|
|
|
|
2022-07-28 19:58:04 +01:00
|
|
|
void InstanceImportTask::downloadAborted()
|
|
|
|
{
|
|
|
|
emitAborted();
|
|
|
|
m_filesNetJob.reset();
|
|
|
|
}
|
|
|
|
|
2017-09-04 07:17:25 +01:00
|
|
|
void InstanceImportTask::processZipPack()
|
2016-10-02 23:55:54 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
setStatus(tr("Extracting modpack"));
|
|
|
|
QDir extractDir(m_stagingPath);
|
|
|
|
qDebug() << "Attempting to create instance from" << m_archivePath;
|
2016-10-26 17:12:33 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// open the zip and find relevant files in it
|
|
|
|
m_packZip.reset(new QuaZip(m_archivePath));
|
|
|
|
if (!m_packZip->open(QuaZip::mdUnzip))
|
|
|
|
{
|
|
|
|
emitFailed(tr("Unable to open supplied modpack zip file."));
|
|
|
|
return;
|
|
|
|
}
|
2017-09-04 07:17:25 +01:00
|
|
|
|
2022-05-24 20:43:38 +01:00
|
|
|
QuaZipDir packZipDir(m_packZip.get());
|
|
|
|
|
|
|
|
// https://docs.modrinth.com/docs/modpacks/format_definition/#storage
|
|
|
|
bool modrinthFound = packZipDir.exists("/modrinth.index.json");
|
|
|
|
bool technicFound = packZipDir.exists("/bin/modpack.jar") || packZipDir.exists("/bin/version.json");
|
2018-07-15 13:51:05 +01:00
|
|
|
QString root;
|
2022-05-24 20:43:38 +01:00
|
|
|
|
|
|
|
// NOTE: Prioritize modpack platforms that aren't searched for recursively.
|
|
|
|
// Especially Flame has a very common filename for its manifest, which may appear inside overrides for example
|
|
|
|
if(modrinthFound)
|
2018-07-15 13:51:05 +01:00
|
|
|
{
|
2022-05-24 20:43:38 +01:00
|
|
|
// process as Modrinth pack
|
|
|
|
qDebug() << "Modrinth:" << modrinthFound;
|
|
|
|
m_modpackType = ModpackType::Modrinth;
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2020-06-07 16:46:12 +01:00
|
|
|
else if (technicFound)
|
|
|
|
{
|
|
|
|
// process as Technic pack
|
|
|
|
qDebug() << "Technic:" << technicFound;
|
|
|
|
extractDir.mkpath(".minecraft");
|
|
|
|
extractDir.cd(".minecraft");
|
|
|
|
m_modpackType = ModpackType::Technic;
|
|
|
|
}
|
2022-05-24 20:43:38 +01:00
|
|
|
else
|
2022-01-31 14:25:36 +00:00
|
|
|
{
|
2022-12-01 18:15:15 +00:00
|
|
|
QStringList paths_to_ignore { "overrides/" };
|
2022-05-24 20:43:38 +01:00
|
|
|
|
2022-12-01 18:15:15 +00:00
|
|
|
if (QString mmcRoot = MMCZip::findFolderOfFileInZip(m_packZip.get(), "instance.cfg", paths_to_ignore); !mmcRoot.isNull()) {
|
2022-05-24 20:43:38 +01:00
|
|
|
// process as MultiMC instance/pack
|
|
|
|
qDebug() << "MultiMC:" << mmcRoot;
|
|
|
|
root = mmcRoot;
|
|
|
|
m_modpackType = ModpackType::MultiMC;
|
2022-12-01 18:15:15 +00:00
|
|
|
} else if (QString flameRoot = MMCZip::findFolderOfFileInZip(m_packZip.get(), "manifest.json", paths_to_ignore); !flameRoot.isNull()) {
|
2022-05-24 20:43:38 +01:00
|
|
|
// process as Flame pack
|
|
|
|
qDebug() << "Flame:" << flameRoot;
|
|
|
|
root = flameRoot;
|
|
|
|
m_modpackType = ModpackType::Flame;
|
|
|
|
}
|
2022-01-31 14:25:36 +00:00
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
if(m_modpackType == ModpackType::Unknown)
|
|
|
|
{
|
|
|
|
emitFailed(tr("Archive does not contain a recognized modpack type."));
|
|
|
|
return;
|
|
|
|
}
|
2017-09-04 07:17:25 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// make sure we extract just the pack
|
|
|
|
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractSubDir, m_packZip.get(), root, extractDir.absolutePath());
|
|
|
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &InstanceImportTask::extractFinished);
|
|
|
|
m_extractFutureWatcher.setFuture(m_extractFuture);
|
2016-10-26 17:12:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceImportTask::extractFinished()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
m_packZip.reset();
|
2023-02-24 23:34:43 +00:00
|
|
|
|
|
|
|
if (m_extractFuture.isCanceled())
|
|
|
|
return;
|
|
|
|
if (!m_extractFuture.result().has_value()) {
|
2018-07-15 13:51:05 +01:00
|
|
|
emitFailed(tr("Failed to extract modpack"));
|
|
|
|
return;
|
|
|
|
}
|
2023-02-24 23:34:43 +00:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
QDir extractDir(m_stagingPath);
|
2017-04-21 21:23:31 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
qDebug() << "Fixing permissions for extracted pack files...";
|
|
|
|
QDirIterator it(extractDir, QDirIterator::Subdirectories);
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
auto filepath = it.next();
|
|
|
|
QFileInfo file(filepath);
|
|
|
|
auto permissions = QFile::permissions(filepath);
|
|
|
|
auto origPermissions = permissions;
|
|
|
|
if(file.isDir())
|
|
|
|
{
|
|
|
|
// Folder +rwx for current user
|
|
|
|
permissions |= QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser | QFileDevice::Permission::ExeUser;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// File +rw for current user
|
|
|
|
permissions |= QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser;
|
|
|
|
}
|
|
|
|
if(origPermissions != permissions)
|
|
|
|
{
|
|
|
|
if(!QFile::setPermissions(filepath, permissions))
|
|
|
|
{
|
|
|
|
logWarning(tr("Could not fix permissions for %1").arg(filepath));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "Fixed" << filepath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-21 21:23:31 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
switch(m_modpackType)
|
|
|
|
{
|
|
|
|
case ModpackType::MultiMC:
|
|
|
|
processMultiMC();
|
|
|
|
return;
|
2020-06-07 16:46:12 +01:00
|
|
|
case ModpackType::Technic:
|
|
|
|
processTechnic();
|
|
|
|
return;
|
2022-01-31 14:25:36 +00:00
|
|
|
case ModpackType::Flame:
|
|
|
|
processFlame();
|
|
|
|
return;
|
|
|
|
case ModpackType::Modrinth:
|
|
|
|
processModrinth();
|
|
|
|
return;
|
2018-07-15 13:51:05 +01:00
|
|
|
case ModpackType::Unknown:
|
|
|
|
emitFailed(tr("Archive does not contain a recognized modpack type."));
|
|
|
|
return;
|
|
|
|
}
|
2017-04-20 04:22:04 +01:00
|
|
|
}
|
|
|
|
|
2017-09-04 07:17:25 +01:00
|
|
|
void InstanceImportTask::processFlame()
|
2017-04-20 04:22:04 +01:00
|
|
|
{
|
2023-05-21 09:46:28 +01:00
|
|
|
shared_qobject_ptr<FlameCreationTask> inst_creation_task = nullptr;
|
2022-12-13 03:31:41 +00:00
|
|
|
if (!m_extra_info.isEmpty()) {
|
|
|
|
auto pack_id_it = m_extra_info.constFind("pack_id");
|
|
|
|
Q_ASSERT(pack_id_it != m_extra_info.constEnd());
|
|
|
|
auto pack_id = pack_id_it.value();
|
|
|
|
|
|
|
|
auto pack_version_id_it = m_extra_info.constFind("pack_version_id");
|
|
|
|
Q_ASSERT(pack_version_id_it != m_extra_info.constEnd());
|
|
|
|
auto pack_version_id = pack_version_id_it.value();
|
|
|
|
|
|
|
|
QString original_instance_id;
|
|
|
|
auto original_instance_id_it = m_extra_info.constFind("original_instance_id");
|
|
|
|
if (original_instance_id_it != m_extra_info.constEnd())
|
|
|
|
original_instance_id = original_instance_id_it.value();
|
|
|
|
|
2023-05-21 09:46:28 +01:00
|
|
|
inst_creation_task = makeShared<FlameCreationTask>(m_stagingPath, m_globalSettings, m_parent, pack_id, pack_version_id, original_instance_id);
|
2022-12-13 03:31:41 +00:00
|
|
|
} else {
|
|
|
|
// FIXME: Find a way to get IDs in directly imported ZIPs
|
2023-05-21 09:46:28 +01:00
|
|
|
inst_creation_task = makeShared<FlameCreationTask>(m_stagingPath, m_globalSettings, m_parent, QString(), QString());
|
2022-12-13 03:31:41 +00:00
|
|
|
}
|
2022-07-08 22:44:43 +01:00
|
|
|
|
2022-07-14 20:13:23 +01:00
|
|
|
inst_creation_task->setName(*this);
|
2022-07-08 22:44:43 +01:00
|
|
|
inst_creation_task->setIcon(m_instIcon);
|
|
|
|
inst_creation_task->setGroup(m_instGroup);
|
2022-10-14 18:36:48 +01:00
|
|
|
inst_creation_task->setConfirmUpdate(shouldConfirmUpdate());
|
2022-07-08 22:44:43 +01:00
|
|
|
|
2023-05-21 09:46:28 +01:00
|
|
|
connect(inst_creation_task.get(), &Task::succeeded, this, [this, inst_creation_task] {
|
2022-12-03 13:15:38 +00:00
|
|
|
setOverride(inst_creation_task->shouldOverride(), inst_creation_task->originalInstanceID());
|
2022-07-08 22:44:43 +01:00
|
|
|
emitSucceeded();
|
|
|
|
});
|
2023-05-21 09:46:28 +01:00
|
|
|
connect(inst_creation_task.get(), &Task::failed, this, &InstanceImportTask::emitFailed);
|
|
|
|
connect(inst_creation_task.get(), &Task::progress, this, &InstanceImportTask::setProgress);
|
2023-07-26 21:20:30 +01:00
|
|
|
connect(inst_creation_task.get(), &Task::stepProgress, this, &InstanceImportTask::propagateStepProgress);
|
2023-05-21 09:46:28 +01:00
|
|
|
connect(inst_creation_task.get(), &Task::status, this, &InstanceImportTask::setStatus);
|
|
|
|
connect(inst_creation_task.get(), &Task::details, this, &InstanceImportTask::setDetails);
|
|
|
|
|
|
|
|
connect(this, &Task::aborted, inst_creation_task.get(), &InstanceCreationTask::abort);
|
|
|
|
connect(inst_creation_task.get(), &Task::aborted, this, &Task::abort);
|
|
|
|
connect(inst_creation_task.get(), &Task::abortStatusChanged, this, &Task::setAbortable);
|
2022-05-28 20:53:12 +01:00
|
|
|
|
2022-07-08 22:44:43 +01:00
|
|
|
inst_creation_task->start();
|
2017-04-20 04:22:04 +01:00
|
|
|
}
|
|
|
|
|
2020-06-07 16:46:12 +01:00
|
|
|
void InstanceImportTask::processTechnic()
|
|
|
|
{
|
2023-01-24 19:52:09 +00:00
|
|
|
shared_qobject_ptr<Technic::TechnicPackProcessor> packProcessor{ new Technic::TechnicPackProcessor };
|
2020-06-07 16:46:12 +01:00
|
|
|
connect(packProcessor.get(), &Technic::TechnicPackProcessor::succeeded, this, &InstanceImportTask::emitSucceeded);
|
|
|
|
connect(packProcessor.get(), &Technic::TechnicPackProcessor::failed, this, &InstanceImportTask::emitFailed);
|
2022-07-14 20:13:23 +01:00
|
|
|
packProcessor->run(m_globalSettings, name(), m_instIcon, m_stagingPath);
|
2020-06-07 16:46:12 +01:00
|
|
|
}
|
|
|
|
|
2017-09-04 07:17:25 +01:00
|
|
|
void InstanceImportTask::processMultiMC()
|
2017-04-20 04:22:04 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
|
|
|
|
auto instanceSettings = std::make_shared<INISettingsObject>(configPath);
|
2016-10-02 23:55:54 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
NullInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
|
2016-10-02 23:55:54 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// reset time played on import... because packs.
|
|
|
|
instance.resetTimePlayed();
|
2016-10-02 23:55:54 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// set a new nice name
|
2022-07-14 20:13:23 +01:00
|
|
|
instance.setName(name());
|
2016-10-02 23:55:54 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// if the icon was specified by user, use that. otherwise pull icon from the pack
|
2022-05-16 02:16:52 +01:00
|
|
|
if (m_instIcon != "default") {
|
2018-07-15 13:51:05 +01:00
|
|
|
instance.setIconKey(m_instIcon);
|
2022-05-16 02:16:52 +01:00
|
|
|
} else {
|
2018-07-15 13:51:05 +01:00
|
|
|
m_instIcon = instance.iconKey();
|
2019-05-31 20:52:58 +01:00
|
|
|
|
|
|
|
auto importIconPath = IconUtils::findBestIconIn(instance.instanceRoot(), m_instIcon);
|
2022-05-16 02:16:52 +01:00
|
|
|
if (!importIconPath.isNull() && QFile::exists(importIconPath)) {
|
2018-07-15 13:51:05 +01:00
|
|
|
// import icon
|
2021-11-21 22:21:12 +00:00
|
|
|
auto iconList = APPLICATION->icons();
|
2022-05-16 02:16:52 +01:00
|
|
|
if (iconList->iconFileExists(m_instIcon)) {
|
2018-07-15 13:51:05 +01:00
|
|
|
iconList->deleteIcon(m_instIcon);
|
|
|
|
}
|
2022-05-16 02:16:52 +01:00
|
|
|
iconList->installIcons({ importIconPath });
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
emitSucceeded();
|
2016-10-02 23:55:54 +01:00
|
|
|
}
|
2022-01-31 14:25:36 +00:00
|
|
|
|
2022-05-16 02:16:52 +01:00
|
|
|
void InstanceImportTask::processModrinth()
|
|
|
|
{
|
2022-12-13 03:31:41 +00:00
|
|
|
ModrinthCreationTask* inst_creation_task = nullptr;
|
|
|
|
if (!m_extra_info.isEmpty()) {
|
|
|
|
auto pack_id_it = m_extra_info.constFind("pack_id");
|
|
|
|
Q_ASSERT(pack_id_it != m_extra_info.constEnd());
|
|
|
|
auto pack_id = pack_id_it.value();
|
|
|
|
|
|
|
|
QString pack_version_id;
|
|
|
|
auto pack_version_id_it = m_extra_info.constFind("pack_version_id");
|
|
|
|
if (pack_version_id_it != m_extra_info.constEnd())
|
|
|
|
pack_version_id = pack_version_id_it.value();
|
|
|
|
|
|
|
|
QString original_instance_id;
|
|
|
|
auto original_instance_id_it = m_extra_info.constFind("original_instance_id");
|
|
|
|
if (original_instance_id_it != m_extra_info.constEnd())
|
|
|
|
original_instance_id = original_instance_id_it.value();
|
|
|
|
|
|
|
|
inst_creation_task = new ModrinthCreationTask(m_stagingPath, m_globalSettings, m_parent, pack_id, pack_version_id, original_instance_id);
|
|
|
|
} else {
|
|
|
|
QString pack_id;
|
|
|
|
if (!m_sourceUrl.isEmpty()) {
|
2023-02-07 17:21:00 +00:00
|
|
|
QRegularExpression regex(R"(data\/([^\/]*)\/versions)");
|
2022-12-13 03:31:41 +00:00
|
|
|
pack_id = regex.match(m_sourceUrl.toString()).captured(1);
|
|
|
|
}
|
2022-12-03 13:15:38 +00:00
|
|
|
|
2022-12-13 03:31:41 +00:00
|
|
|
// FIXME: Find a way to get the ID in directly imported ZIPs
|
|
|
|
inst_creation_task = new ModrinthCreationTask(m_stagingPath, m_globalSettings, m_parent, pack_id);
|
|
|
|
}
|
2022-01-31 14:25:36 +00:00
|
|
|
|
2022-07-14 20:13:23 +01:00
|
|
|
inst_creation_task->setName(*this);
|
2022-07-08 01:10:41 +01:00
|
|
|
inst_creation_task->setIcon(m_instIcon);
|
|
|
|
inst_creation_task->setGroup(m_instGroup);
|
2022-10-14 18:36:48 +01:00
|
|
|
inst_creation_task->setConfirmUpdate(shouldConfirmUpdate());
|
2022-06-11 17:43:09 +01:00
|
|
|
|
2022-07-08 17:00:44 +01:00
|
|
|
connect(inst_creation_task, &Task::succeeded, this, [this, inst_creation_task] {
|
2022-12-03 13:15:38 +00:00
|
|
|
setOverride(inst_creation_task->shouldOverride(), inst_creation_task->originalInstanceID());
|
2022-07-08 17:00:44 +01:00
|
|
|
emitSucceeded();
|
|
|
|
});
|
2022-07-08 01:10:41 +01:00
|
|
|
connect(inst_creation_task, &Task::failed, this, &InstanceImportTask::emitFailed);
|
|
|
|
connect(inst_creation_task, &Task::progress, this, &InstanceImportTask::setProgress);
|
2023-07-26 21:20:30 +01:00
|
|
|
connect(inst_creation_task, &Task::stepProgress, this, &InstanceImportTask::propagateStepProgress);
|
2022-07-08 01:10:41 +01:00
|
|
|
connect(inst_creation_task, &Task::status, this, &InstanceImportTask::setStatus);
|
2023-04-01 03:25:01 +01:00
|
|
|
connect(inst_creation_task, &Task::details, this, &InstanceImportTask::setDetails);
|
2022-07-08 17:00:44 +01:00
|
|
|
connect(inst_creation_task, &Task::finished, inst_creation_task, &InstanceCreationTask::deleteLater);
|
2022-07-08 01:10:41 +01:00
|
|
|
|
2022-07-08 17:00:44 +01:00
|
|
|
connect(this, &Task::aborted, inst_creation_task, &InstanceCreationTask::abort);
|
2022-08-01 00:29:12 +01:00
|
|
|
connect(inst_creation_task, &Task::aborted, this, &Task::abort);
|
2022-08-21 13:26:27 +01:00
|
|
|
connect(inst_creation_task, &Task::abortStatusChanged, this, &Task::setAbortable);
|
2022-07-08 01:10:41 +01:00
|
|
|
|
|
|
|
inst_creation_task->start();
|
2022-01-31 14:25:36 +00:00
|
|
|
}
|