fix: correctly set all managed pack fields in Modrinth pack

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-07-31 19:50:09 -03:00
parent 3a9d58e31c
commit be769d07f1
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 27 additions and 11 deletions

View File

@ -5,7 +5,6 @@
#include "InstanceList.h"
#include "Json.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
#include "modplatform/helpers/OverrideUtils.h"
@ -43,8 +42,8 @@ bool ModrinthCreationTask::updateInstance()
if (!parseManifest(index_path, m_files))
return false;
auto version_id = inst->getManagedPackVersionID();
auto version_str = !version_id.isEmpty() ? tr(" (version %1)").arg(version_id) : "";
auto version_name = inst->getManagedPackVersionName();
auto version_str = !version_name.isEmpty() ? tr(" (version %1)").arg(version_name) : "";
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 "
@ -66,7 +65,7 @@ bool ModrinthCreationTask::updateInstance()
QFileInfo old_index_file(old_index_path);
if (old_index_file.exists()) {
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!
auto files_iterator = m_files.begin();
@ -121,6 +120,8 @@ bool ModrinthCreationTask::updateInstance()
setOverride(true);
qDebug() << "Will override instance!";
m_instance = inst;
// We let it go through the createInstance() stage, just with a couple modifications for updating
return false;
}
@ -189,7 +190,7 @@ bool ModrinthCreationTask::createInstance()
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.saveNow();
@ -229,10 +230,17 @@ bool ModrinthCreationTask::createInstance()
loop.exec();
if (m_instance) {
auto inst = m_instance.value();
inst->copyManagedPack(instance);
inst->setName(instance.name());
}
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 {
auto doc = Json::requireDocument(index_path);
@ -244,8 +252,10 @@ bool ModrinthCreationTask::parseManifest(QString index_path, std::vector<Modrint
throw JSONValidationError("Unknown game: " + game);
}
m_managed_version_id = Json::ensureString(obj, "versionId", "Managed ID");
m_managed_name = Json::ensureString(obj, "name", "Managed Name");
if (set_managed_info) {
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");
bool had_optional = false;
@ -348,7 +358,7 @@ QString ModrinthCreationTask::getManagedPackID() const
{
if (!m_source_url.isEmpty()) {
QRegularExpression regex(R"(data\/(.*)\/versions)");
return regex.match(m_source_url).captured(0);
return regex.match(m_source_url).captured(1);
}
return {};

View File

@ -2,6 +2,10 @@
#include "InstanceCreationTask.h"
#include <optional>
#include "minecraft/MinecraftInstance.h"
#include "modplatform/modrinth/ModrinthPackManifest.h"
#include "net/NetJob.h"
@ -11,7 +15,7 @@ class ModrinthCreationTask final : public InstanceCreationTask {
public:
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);
setParentSettings(global_settings);
@ -24,7 +28,7 @@ class ModrinthCreationTask final : public InstanceCreationTask {
bool createInstance() override;
private:
bool parseManifest(QString, std::vector<Modrinth::File>&);
bool parseManifest(QString, std::vector<Modrinth::File>&, bool set_managed_info = true);
QString getManagedPackID() const;
private:
@ -36,4 +40,6 @@ class ModrinthCreationTask final : public InstanceCreationTask {
std::vector<Modrinth::File> m_files;
NetJob::Ptr m_files_job;
std::optional<InstancePtr> m_instance;
};