From 6e2869834f59ae4863e63a16de97aa3019723b26 Mon Sep 17 00:00:00 2001 From: flow Date: Sat, 4 Jun 2022 16:22:46 -0300 Subject: feat: add mod update dialog This subclasses the Review mods dialog to make a "Update review" one. Also, all the necessary components built until now are put together in a coherent unity that checks and generates metadata on-the-fly and checks for mod updates, while giving and receiving feedback to the user. Signed-off-by: flow --- launcher/modplatform/flame/FlameCheckUpdate.cpp | 19 +++++-------------- launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp | 5 ++++- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'launcher/modplatform') diff --git a/launcher/modplatform/flame/FlameCheckUpdate.cpp b/launcher/modplatform/flame/FlameCheckUpdate.cpp index f1983fa4..12d99029 100644 --- a/launcher/modplatform/flame/FlameCheckUpdate.cpp +++ b/launcher/modplatform/flame/FlameCheckUpdate.cpp @@ -74,16 +74,13 @@ void FlameCheckUpdate::executeTask() setStatus(tr("Preparing mods for CurseForge...")); setProgress(0, 5); - QHash mappings; + QHash mappings; // Create all hashes - QStringList hashes; std::list murmur_hashes; auto best_hash_type = ProviderCaps.hashType(ModPlatform::Provider::FLAME).first(); for (auto mod : m_mods) { - auto hash = mod.metadata()->hash; - QByteArray jar_data; try { @@ -106,14 +103,7 @@ void FlameCheckUpdate::executeTask() auto murmur_hash = MurmurHash2(jar_data_treated, jar_data_treated.length()); murmur_hashes.emplace_back(murmur_hash); - // Sadly the API can only handle one hash type per call, se we - // need to generate a new hash if the current one is innadequate - // (though it will rarely happen, if at all) - if (mod.metadata()->hash_format != best_hash_type) - hash = QString(ProviderCaps.hash(ModPlatform::Provider::FLAME, jar_data, best_hash_type).toHex()); - - hashes.append(hash); - mappings.insert(hash, mod); + mappings.insert(mod.metadata()->mod_id().toInt(), mod); } auto* response = new QByteArray(); @@ -154,9 +144,10 @@ void FlameCheckUpdate::executeTask() return; } - auto mod_iter = mappings.find(current_ver.hash); + auto mod_iter = mappings.find(current_ver.addonId.toInt()); if (mod_iter == mappings.end()) { qCritical() << "Failed to remap mod from Flame!"; + qDebug() << match_obj; continue; } @@ -191,7 +182,7 @@ void FlameCheckUpdate::executeTask() continue; } - if (!latest_ver.hash.isEmpty() && current_ver.hash != latest_ver.hash) { + if (!latest_ver.hash.isEmpty() && (current_ver.hash != latest_ver.hash || mod.status() == ModStatus::NotInstalled)) { // Fake pack with the necessary info to pass to the download task :) ModPlatform::IndexedPack pack; pack.name = mod.name(); diff --git a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp index 81a2652a..981c4216 100644 --- a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp +++ b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp @@ -81,11 +81,14 @@ void ModrinthCheckUpdate::executeTask() try { for (auto hash : mappings.keys()) { auto project_obj = doc[hash].toObject(); + + // If the returned project is empty, but we have Modrinth metadata, + // it means this specific version is not available if (project_obj.isEmpty()) { qDebug() << "Mod " << mappings.find(hash).value().name() << " got an empty response."; qDebug() << "Hash: " << hash; - emit checkFailed(mappings.find(hash).value(), tr("Couldn't find mod in Modrinth")); + emit checkFailed(mappings.find(hash).value(), tr("Couldn't find the latest version of this mod with the correct mod loader and game version.")); continue; } -- cgit