Skip to content

Commit

Permalink
Use cjson lib for update check
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Apr 7, 2022
1 parent 2921dc8 commit 04bab83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
1 change: 0 additions & 1 deletion source/cheats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 17 additions & 31 deletions source/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <orbis/libkernel.h>
#include <orbis/SaveData.h>
#include <orbis/UserService.h>
#include <cjson/cJSON.h>

#include "types.h"
#include "menu.h"
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 04bab83

Please sign in to comment.