From 04bab83d59bcca1cfaa1b53e2e89dc8f71f3319b Mon Sep 17 00:00:00 2001 From: bucanero Date: Thu, 7 Apr 2022 10:23:27 -0300 Subject: [PATCH] Use cjson lib for update check --- source/cheats.c | 1 - source/main.c | 2 +- source/settings.c | 48 +++++++++++++++++------------------------------ 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/source/cheats.c b/source/cheats.c index 7bb3924..ac12710 100644 --- a/source/cheats.c +++ b/source/cheats.c @@ -749,7 +749,6 @@ static void read_json_games(const char* userPath, list_t *list) long bsize; char *buffer = readTextFile(fullPath, &bsize); - cJSON *cheat = cJSON_Parse(buffer); const cJSON *jobject; diff --git a/source/main.c b/source/main.c index 464753f..ec33dd4 100644 --- a/source/main.c +++ b/source/main.c @@ -560,7 +560,7 @@ void SetMenu(int id) case MENU_PATCH_VIEW: //Cheat View Menu menu_old_sel[MENU_PATCH_VIEW] = 0; if (apollo_config.doAni) - Draw_CheatsMenu_View_Ani("Patch view"); + Draw_CheatsMenu_View_Ani("Code view"); break; case MENU_SAVE_DETAILS: //Save Detail View Menu diff --git a/source/settings.c b/source/settings.c index c340986..d765570 100644 --- a/source/settings.c +++ b/source/settings.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "types.h" #include "menu.h" @@ -143,62 +144,47 @@ void update_callback(int sel) long size = 0; buffer = readTextFile(GOLDCHEATS_LOCAL_CACHE "ver.check", &size); + cJSON *json = cJSON_Parse(buffer); - if (!buffer) + if (!json) + { + LOG("JSON parse Error: %s\n", buffer); + free(buffer); return; + } LOG("received %u bytes", size); - static const char find[] = "\"name\":\"GoldHEN Cheats Manager v"; - const char* start = strstr(buffer, find); - if (!start) + const cJSON *ver = cJSON_GetObjectItemCaseSensitive(json, "tag_name"); + const cJSON *url = cJSON_GetObjectItemCaseSensitive(json, "assets"); + url = cJSON_GetObjectItemCaseSensitive(cJSON_GetArrayItem(url, 0), "browser_download_url"); + + if (!cJSON_IsString(ver) || !cJSON_IsString(url)) { LOG("no name found"); goto end_update; } - LOG("found name"); - start += sizeof(find) - 1; - - char* end = strchr(start, '"'); - if (!end) - { - LOG("no end of name found"); - goto end_update; - } - *end = 0; - LOG("latest version is %s", start); + LOG("latest version is %s", ver->valuestring); - if (strcasecmp(GOLDCHEATS_VERSION, start) == 0) + if (strcasecmp(GOLDCHEATS_VERSION, ver->valuestring + 1) == 0) { LOG("no need to update"); goto end_update; } - start = strstr(end+1, "\"browser_download_url\":\""); - if (!start) - goto end_update; - - start += 24; - end = strchr(start, '"'); - if (!end) - { - LOG("no download URL found"); - goto end_update; - } - - *end = 0; - LOG("download URL is %s", start); + LOG("download URL is %s", url->valuestring); if (show_dialog(1, "New version available! Download update?")) { - if (http_download(start, "", "/data/goldcheats.pkg", 1)) + if (http_download(url->valuestring, "", "/data/goldcheats.pkg", 1)) show_message("Update downloaded to /data/goldcheats.pkg"); else show_message("Download error!"); } end_update: + cJSON_Delete(json); free(buffer); return; }