Merge pull request #636 from flowln/fix_component_version_when_updating

Correctly set component versions in Modrinth pack updating
This commit is contained in:
Sefa Eyeoglu 2022-12-17 17:26:34 +01:00
parent 45870497c6
commit 3476bbebd9
No known key found for this signature in database
GPG Key ID: C10411294912A422
2 changed files with 26 additions and 24 deletions

View File

@ -202,14 +202,14 @@ bool ModrinthCreationTask::createInstance()
auto components = instance.getPackProfile(); auto components = instance.getPackProfile();
components->buildingFromScratch(); components->buildingFromScratch();
components->setComponentVersion("net.minecraft", minecraftVersion, true); components->setComponentVersion("net.minecraft", m_minecraft_version, true);
if (!fabricVersion.isEmpty()) if (!m_fabric_version.isEmpty())
components->setComponentVersion("net.fabricmc.fabric-loader", fabricVersion); components->setComponentVersion("net.fabricmc.fabric-loader", m_fabric_version);
if (!quiltVersion.isEmpty()) if (!m_quilt_version.isEmpty())
components->setComponentVersion("org.quiltmc.quilt-loader", quiltVersion); components->setComponentVersion("org.quiltmc.quilt-loader", m_quilt_version);
if (!forgeVersion.isEmpty()) if (!m_forge_version.isEmpty())
components->setComponentVersion("net.minecraftforge", forgeVersion); components->setComponentVersion("net.minecraftforge", m_forge_version);
if (m_instIcon != "default") { if (m_instIcon != "default") {
instance.setIconKey(m_instIcon); instance.setIconKey(m_instIcon);
@ -279,7 +279,7 @@ bool ModrinthCreationTask::createInstance()
return ended_well; return ended_well;
} }
bool ModrinthCreationTask::parseManifest(const QString& index_path, std::vector<Modrinth::File>& files, bool set_managed_info, bool show_optional_dialog) bool ModrinthCreationTask::parseManifest(const QString& index_path, std::vector<Modrinth::File>& files, bool set_internal_data, bool show_optional_dialog)
{ {
try { try {
auto doc = Json::requireDocument(index_path); auto doc = Json::requireDocument(index_path);
@ -291,7 +291,7 @@ bool ModrinthCreationTask::parseManifest(const QString& index_path, std::vector<
throw JSONValidationError("Unknown game: " + game); throw JSONValidationError("Unknown game: " + game);
} }
if (set_managed_info) { if (set_internal_data) {
if (m_managed_version_id.isEmpty()) if (m_managed_version_id.isEmpty())
m_managed_version_id = Json::ensureString(obj, "versionId", {}, "Managed ID"); m_managed_version_id = Json::ensureString(obj, "versionId", {}, "Managed ID");
m_managed_name = Json::ensureString(obj, "name", {}, "Managed Name"); m_managed_name = Json::ensureString(obj, "name", {}, "Managed Name");
@ -367,19 +367,21 @@ bool ModrinthCreationTask::parseManifest(const QString& index_path, std::vector<
files.push_back(file); files.push_back(file);
} }
auto dependencies = Json::requireObject(obj, "dependencies", "modrinth.index.json"); if (set_internal_data) {
for (auto it = dependencies.begin(), end = dependencies.end(); it != end; ++it) { auto dependencies = Json::requireObject(obj, "dependencies", "modrinth.index.json");
QString name = it.key(); for (auto it = dependencies.begin(), end = dependencies.end(); it != end; ++it) {
if (name == "minecraft") { QString name = it.key();
minecraftVersion = Json::requireString(*it, "Minecraft version"); if (name == "minecraft") {
} else if (name == "fabric-loader") { m_minecraft_version = Json::requireString(*it, "Minecraft version");
fabricVersion = Json::requireString(*it, "Fabric Loader version"); } else if (name == "fabric-loader") {
} else if (name == "quilt-loader") { m_fabric_version = Json::requireString(*it, "Fabric Loader version");
quiltVersion = Json::requireString(*it, "Quilt Loader version"); } else if (name == "quilt-loader") {
} else if (name == "forge") { m_quilt_version = Json::requireString(*it, "Quilt Loader version");
forgeVersion = Json::requireString(*it, "Forge version"); } else if (name == "forge") {
} else { m_forge_version = Json::requireString(*it, "Forge version");
throw JSONValidationError("Unknown dependency type: " + name); } else {
throw JSONValidationError("Unknown dependency type: " + name);
}
} }
} }
} else { } else {

View File

@ -37,12 +37,12 @@ class ModrinthCreationTask final : public InstanceCreationTask {
bool createInstance() override; bool createInstance() override;
private: private:
bool parseManifest(const QString&, std::vector<Modrinth::File>&, bool set_managed_info = true, bool show_optional_dialog = true); bool parseManifest(const QString&, std::vector<Modrinth::File>&, bool set_internal_data = true, bool show_optional_dialog = true);
private: private:
QWidget* m_parent = nullptr; QWidget* m_parent = nullptr;
QString minecraftVersion, fabricVersion, quiltVersion, forgeVersion; QString m_minecraft_version, m_fabric_version, m_quilt_version, m_forge_version;
QString m_managed_id, m_managed_version_id, m_managed_name; QString m_managed_id, m_managed_version_id, m_managed_name;
std::vector<Modrinth::File> m_files; std::vector<Modrinth::File> m_files;