11#include " cortex_upd_cmd.h"
22#include " httplib.h"
3- #include " nlohmann/json.hpp"
43#include " server_stop_cmd.h"
54#include " utils/archive_utils.h"
65#include " utils/file_manager_utils.h"
6+ #include " utils/json_helper.h"
77#include " utils/logging_utils.h"
88#include " utils/scope_exit.h"
99#include " utils/system_info_utils.h"
@@ -144,26 +144,26 @@ std::optional<std::string> CheckNewUpdate(
144144 if (auto res = cli.Get (release_path)) {
145145 if (res->status == httplib::StatusCode::OK_200) {
146146 try {
147- auto get_latest = [](const nlohmann::json & data) -> std::string {
147+ auto get_latest = [](const Json::Value & data) -> std::string {
148148 if (data.empty ()) {
149149 return " " ;
150150 }
151151
152152 if (CORTEX_VARIANT == file_manager_utils::kBetaVariant ) {
153153 for (auto & d : data) {
154- if (auto tag = d[" tag_name" ].get <std::string> ();
154+ if (auto tag = d[" tag_name" ].asString ();
155155 tag.find (kBetaComp ) != std::string::npos) {
156156 return tag;
157157 }
158158 }
159- return data[0 ][" tag_name" ].get <std::string> ();
159+ return data[0 ][" tag_name" ].asString ();
160160 } else {
161- return data[" tag_name" ].get <std::string> ();
161+ return data[" tag_name" ].asString ();
162162 }
163163 return " " ;
164164 };
165165
166- auto json_res = nlohmann::json::parse (res->body );
166+ auto json_res = json_helper::ParseJsonString (res->body );
167167 std::string latest_version = get_latest (json_res);
168168 if (latest_version.empty ()) {
169169 CTL_WRN (" Release not found!" );
@@ -178,7 +178,7 @@ std::optional<std::string> CheckNewUpdate(
178178 if (current_version != latest_version) {
179179 return latest_version;
180180 }
181- } catch (const nlohmann::json::parse_error & e) {
181+ } catch (const std::exception & e) {
182182 CTL_INF (" JSON parse error: " << e.what ());
183183 return std::nullopt ;
184184 }
@@ -321,7 +321,7 @@ bool CortexUpdCmd::GetStable(const std::string& v) {
321321 if (auto res = cli.Get (release_path)) {
322322 if (res->status == httplib::StatusCode::OK_200) {
323323 try {
324- auto json_data = nlohmann::json::parse (res->body );
324+ auto json_data = json_helper::ParseJsonString (res->body );
325325 if (json_data.empty ()) {
326326 CLI_LOG (" Version not found: " << v);
327327 return false ;
@@ -333,7 +333,7 @@ bool CortexUpdCmd::GetStable(const std::string& v) {
333333 !downloaded_exe_path) {
334334 return false ;
335335 }
336- } catch (const nlohmann::json::parse_error & e) {
336+ } catch (const std::exception & e) {
337337 CLI_LOG_ERROR (" JSON parse error: " << e.what ());
338338 return false ;
339339 }
@@ -377,12 +377,12 @@ bool CortexUpdCmd::GetBeta(const std::string& v) {
377377 if (auto res = cli.Get (release_path)) {
378378 if (res->status == httplib::StatusCode::OK_200) {
379379 try {
380- auto json_res = nlohmann::json::parse (res->body );
380+ auto json_res = json_helper::ParseJsonString (res->body );
381381
382- nlohmann::json json_data;
382+ Json::Value json_data;
383383 for (auto & jr : json_res) {
384384 // Get the latest beta or match version
385- if (auto tag = jr[" tag_name" ].get <std::string> ();
385+ if (auto tag = jr[" tag_name" ].asString ();
386386 (v.empty () && tag.find (kBetaComp ) != std::string::npos) ||
387387 (tag == v)) {
388388 json_data = jr;
@@ -401,7 +401,7 @@ bool CortexUpdCmd::GetBeta(const std::string& v) {
401401 !downloaded_exe_path) {
402402 return false ;
403403 }
404- } catch (const nlohmann::json::parse_error & e) {
404+ } catch (const std::exception & e) {
405405 CLI_LOG_ERROR (" JSON parse error: " << e.what ());
406406 return false ;
407407 }
@@ -433,10 +433,10 @@ bool CortexUpdCmd::GetBeta(const std::string& v) {
433433}
434434
435435std::optional<std::string> CortexUpdCmd::HandleGithubRelease (
436- const nlohmann::json & assets, const std::string& os_arch) {
436+ const Json::Value & assets, const std::string& os_arch) {
437437 std::string matched_variant = " " ;
438438 for (auto & asset : assets) {
439- auto asset_name = asset[" name" ].get <std::string> ();
439+ auto asset_name = asset[" name" ].asString ();
440440 if (asset_name.find (kCortexBinary ) != std::string::npos &&
441441 asset_name.find (os_arch) != std::string::npos &&
442442 asset_name.find (kReleaseFormat ) != std::string::npos) {
@@ -452,10 +452,10 @@ std::optional<std::string> CortexUpdCmd::HandleGithubRelease(
452452 CTL_INF (" Matched variant: " << matched_variant);
453453
454454 for (auto & asset : assets) {
455- auto asset_name = asset[" name" ].get <std::string> ();
455+ auto asset_name = asset[" name" ].asString ();
456456 if (asset_name == matched_variant) {
457- auto download_url = asset[" browser_download_url" ].get <std::string> ();
458- auto file_name = asset[" name" ].get <std::string> ();
457+ auto download_url = asset[" browser_download_url" ].asString ();
458+ auto file_name = asset[" name" ].asString ();
459459 CTL_INF (" Download url: " << download_url);
460460
461461 auto local_path =
0 commit comments