From 5f8c9e540f7b3a7b6322307ae86e724f094c1d52 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sat, 2 Dec 2023 22:36:49 +0100 Subject: [PATCH] fix: modify boiii.json parser --- src/client/std_include.hpp | 2 ++ src/client/updater/file_updater.cpp | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/client/std_include.hpp b/src/client/std_include.hpp index 55b7466d..a5b0c265 100644 --- a/src/client/std_include.hpp +++ b/src/client/std_include.hpp @@ -64,6 +64,8 @@ #undef min #endif +#undef GetObject + #include #include #include diff --git a/src/client/updater/file_updater.cpp b/src/client/updater/file_updater.cpp index c87c2a1f..17e1ffe8 100644 --- a/src/client/updater/file_updater.cpp +++ b/src/client/updater/file_updater.cpp @@ -34,9 +34,9 @@ namespace updater std::vector parse_file_infos(const std::string& json) { rapidjson::Document doc{}; - doc.Parse(json.data(), json.size()); + const rapidjson::ParseResult result = doc.Parse(json.data(), json.size()); - if (!doc.IsArray()) + if (!result || !doc.IsArray()) { return {}; } @@ -45,19 +45,19 @@ namespace updater for (const auto& element : doc.GetArray()) { - if (!element.IsArray()) + if (!element.IsObject()) { continue; } - auto array = element.GetArray(); + auto file = element.GetObject(); file_info info{}; - info.name.assign(array[0].GetString(), array[0].GetStringLength()); - info.size = array[1].GetInt64(); - info.hash.assign(array[2].GetString(), array[2].GetStringLength()); + info.name = file["name"].GetString(); + info.size = file["size"].GetUint64(); + info.hash = file["hash"].GetString(); - files.emplace_back(std::move(info)); + files.emplace_back(info); } return files;