fix: correctly set all managed pack fields in Modrinth pack
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
3a9d58e31c
commit
be769d07f1
@ -5,7 +5,6 @@
|
|||||||
#include "InstanceList.h"
|
#include "InstanceList.h"
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
|
||||||
#include "minecraft/MinecraftInstance.h"
|
|
||||||
#include "minecraft/PackProfile.h"
|
#include "minecraft/PackProfile.h"
|
||||||
|
|
||||||
#include "modplatform/helpers/OverrideUtils.h"
|
#include "modplatform/helpers/OverrideUtils.h"
|
||||||
@ -43,8 +42,8 @@ bool ModrinthCreationTask::updateInstance()
|
|||||||
if (!parseManifest(index_path, m_files))
|
if (!parseManifest(index_path, m_files))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto version_id = inst->getManagedPackVersionID();
|
auto version_name = inst->getManagedPackVersionName();
|
||||||
auto version_str = !version_id.isEmpty() ? tr(" (version %1)").arg(version_id) : "";
|
auto version_str = !version_name.isEmpty() ? tr(" (version %1)").arg(version_name) : "";
|
||||||
|
|
||||||
auto info = CustomMessageBox::selectable(m_parent, tr("Similar modpack was found!"),
|
auto info = CustomMessageBox::selectable(m_parent, tr("Similar modpack was found!"),
|
||||||
tr("One or more of your instances are from this same modpack%1. Do you want to create a "
|
tr("One or more of your instances are from this same modpack%1. Do you want to create a "
|
||||||
@ -66,7 +65,7 @@ bool ModrinthCreationTask::updateInstance()
|
|||||||
QFileInfo old_index_file(old_index_path);
|
QFileInfo old_index_file(old_index_path);
|
||||||
if (old_index_file.exists()) {
|
if (old_index_file.exists()) {
|
||||||
std::vector<Modrinth::File> old_files;
|
std::vector<Modrinth::File> old_files;
|
||||||
parseManifest(old_index_path, old_files);
|
parseManifest(old_index_path, old_files, false);
|
||||||
|
|
||||||
// Let's remove all duplicated, identical resources!
|
// Let's remove all duplicated, identical resources!
|
||||||
auto files_iterator = m_files.begin();
|
auto files_iterator = m_files.begin();
|
||||||
@ -121,6 +120,8 @@ bool ModrinthCreationTask::updateInstance()
|
|||||||
setOverride(true);
|
setOverride(true);
|
||||||
qDebug() << "Will override instance!";
|
qDebug() << "Will override instance!";
|
||||||
|
|
||||||
|
m_instance = inst;
|
||||||
|
|
||||||
// We let it go through the createInstance() stage, just with a couple modifications for updating
|
// We let it go through the createInstance() stage, just with a couple modifications for updating
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -189,7 +190,7 @@ bool ModrinthCreationTask::createInstance()
|
|||||||
instance.setIconKey("modrinth");
|
instance.setIconKey("modrinth");
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.setManagedPack("modrinth", getManagedPackID(), m_managed_name, m_managed_id, {});
|
instance.setManagedPack("modrinth", getManagedPackID(), m_managed_name, m_managed_version_id, version());
|
||||||
instance.setName(name());
|
instance.setName(name());
|
||||||
instance.saveNow();
|
instance.saveNow();
|
||||||
|
|
||||||
@ -229,10 +230,17 @@ bool ModrinthCreationTask::createInstance()
|
|||||||
|
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
if (m_instance) {
|
||||||
|
auto inst = m_instance.value();
|
||||||
|
|
||||||
|
inst->copyManagedPack(instance);
|
||||||
|
inst->setName(instance.name());
|
||||||
|
}
|
||||||
|
|
||||||
return ended_well;
|
return ended_well;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModrinthCreationTask::parseManifest(QString index_path, std::vector<Modrinth::File>& files)
|
bool ModrinthCreationTask::parseManifest(QString index_path, std::vector<Modrinth::File>& files, bool set_managed_info)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto doc = Json::requireDocument(index_path);
|
auto doc = Json::requireDocument(index_path);
|
||||||
@ -244,8 +252,10 @@ bool ModrinthCreationTask::parseManifest(QString index_path, std::vector<Modrint
|
|||||||
throw JSONValidationError("Unknown game: " + game);
|
throw JSONValidationError("Unknown game: " + game);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_managed_version_id = Json::ensureString(obj, "versionId", "Managed ID");
|
if (set_managed_info) {
|
||||||
m_managed_name = Json::ensureString(obj, "name", "Managed Name");
|
m_managed_version_id = Json::ensureString(obj, "versionId", {}, "Managed ID");
|
||||||
|
m_managed_name = Json::ensureString(obj, "name", {}, "Managed Name");
|
||||||
|
}
|
||||||
|
|
||||||
auto jsonFiles = Json::requireIsArrayOf<QJsonObject>(obj, "files", "modrinth.index.json");
|
auto jsonFiles = Json::requireIsArrayOf<QJsonObject>(obj, "files", "modrinth.index.json");
|
||||||
bool had_optional = false;
|
bool had_optional = false;
|
||||||
@ -348,7 +358,7 @@ QString ModrinthCreationTask::getManagedPackID() const
|
|||||||
{
|
{
|
||||||
if (!m_source_url.isEmpty()) {
|
if (!m_source_url.isEmpty()) {
|
||||||
QRegularExpression regex(R"(data\/(.*)\/versions)");
|
QRegularExpression regex(R"(data\/(.*)\/versions)");
|
||||||
return regex.match(m_source_url).captured(0);
|
return regex.match(m_source_url).captured(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
#include "InstanceCreationTask.h"
|
#include "InstanceCreationTask.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include "minecraft/MinecraftInstance.h"
|
||||||
|
|
||||||
#include "modplatform/modrinth/ModrinthPackManifest.h"
|
#include "modplatform/modrinth/ModrinthPackManifest.h"
|
||||||
|
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
@ -11,7 +15,7 @@ class ModrinthCreationTask final : public InstanceCreationTask {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ModrinthCreationTask(QString staging_path, SettingsObjectPtr global_settings, QWidget* parent, QString source_url = {})
|
ModrinthCreationTask(QString staging_path, SettingsObjectPtr global_settings, QWidget* parent, QString source_url = {})
|
||||||
: InstanceCreationTask(), m_parent(parent)
|
: InstanceCreationTask(), m_parent(parent), m_source_url(std::move(source_url))
|
||||||
{
|
{
|
||||||
setStagingPath(staging_path);
|
setStagingPath(staging_path);
|
||||||
setParentSettings(global_settings);
|
setParentSettings(global_settings);
|
||||||
@ -24,7 +28,7 @@ class ModrinthCreationTask final : public InstanceCreationTask {
|
|||||||
bool createInstance() override;
|
bool createInstance() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool parseManifest(QString, std::vector<Modrinth::File>&);
|
bool parseManifest(QString, std::vector<Modrinth::File>&, bool set_managed_info = true);
|
||||||
QString getManagedPackID() const;
|
QString getManagedPackID() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -36,4 +40,6 @@ class ModrinthCreationTask final : public InstanceCreationTask {
|
|||||||
|
|
||||||
std::vector<Modrinth::File> m_files;
|
std::vector<Modrinth::File> m_files;
|
||||||
NetJob::Ptr m_files_job;
|
NetJob::Ptr m_files_job;
|
||||||
|
|
||||||
|
std::optional<InstancePtr> m_instance;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user