From 928bb8346734c27a80c2456ae120e3a8533e3ab0 Mon Sep 17 00:00:00 2001 From: Starwarsfan2099 Date: Tue, 8 Jul 2025 19:28:11 -0400 Subject: [PATCH] Better error checking for JSON objects and check for different root object. --- source/api/mod.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source/api/mod.cpp b/source/api/mod.cpp index 5f36c21..192c1bc 100644 --- a/source/api/mod.cpp +++ b/source/api/mod.cpp @@ -103,14 +103,24 @@ bool File::findRomfsRecursive(const nlohmann::json& obj) { void File::loadFile() { auto json = net::downloadRequest(fmt::format("https://gamebanana.com/apiv11/File/{}", fileID)); - if(json.at("_aMetadata").at("_aArchiveFileTree").is_object()) { - auto archiveFileTree = json.at("_aMetadata").at("_aArchiveFileTree"); - for (const auto& item : archiveFileTree.items()) { - if (item.value().is_object()) { - if (findRomfsRecursive(item.value())) { - this->romfs = true; - break; - } + nlohmann::json archiveFileTree = json; + // Check if the correct json object is present. + if (json.contains("_aArchiveFileTree") && json["_aArchiveFileTree"].is_object()) { + archiveFileTree = json["_aArchiveFileTree"]; + } else if (json.contains("_aMetadata") && + json["_aMetadata"].contains("_aArchiveFileTree") && + json["_aMetadata"]["_aArchiveFileTree"].is_object()) { + archiveFileTree = json["_aMetadata"]["_aArchiveFileTree"]; + } else { + brls::Logger::error("Could not find correct JSON object: {}", json.dump(2)); + return; + } + + for (const auto& item : archiveFileTree.items()) { + if (item.value().is_object()) { + if (findRomfsRecursive(item.value())) { + this->romfs = true; + break; } } }