mirror of
https://gitlab.com/Theopse/fbi-i18n-zh.git
synced 2025-04-06 03:58:02 +08:00
Modify updater to pull from TitleDB.
This commit is contained in:
parent
36c4ca784c
commit
a466e3da13
@ -18,42 +18,52 @@ static void update_check_update(ui_view* view, void* data, float* progress, char
|
||||
Result res = 0;
|
||||
|
||||
json_t* json = NULL;
|
||||
if(R_SUCCEEDED(res = task_download_json_sync("https://api.github.com/repos/Steveice10/FBI/releases/latest", &json, 16 * 1024))) {
|
||||
if(json_is_object(json)) {
|
||||
json_t* name = json_object_get(json, "name");
|
||||
json_t* assets = json_object_get(json, "assets");
|
||||
if(R_SUCCEEDED(res = task_download_json_sync("https://api.titledb.com/v1/entry?nested=true&only=cia.id&only=cia.version&only=tdsx.id&only=tdsx.version&_filters=%7B%22name%22%3A%20%22FBI%22%7D", &json, 16 * 1024))) {
|
||||
const char* type = fs_get_3dsx_path() != NULL ? "tdsx" : "cia";
|
||||
|
||||
if(json_is_string(name) && json_is_array(assets)) {
|
||||
char versionString[16];
|
||||
snprintf(versionString, sizeof(versionString), "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO);
|
||||
json_t* entry = NULL;
|
||||
json_t* objs = NULL;
|
||||
if(json_is_array(json) && json_array_size(json) == 1
|
||||
&& json_is_object(entry = json_array_get(json, 0))
|
||||
&& json_is_array(objs = json_object_get(entry, type))) {
|
||||
if(json_array_size(json) > 0) {
|
||||
u32 latestId = 0;
|
||||
u32 latestMajor = 0;
|
||||
u32 latestMinor = 0;
|
||||
u32 latestMicro = 0;
|
||||
|
||||
if(strncmp(json_string_value(name), versionString, json_string_length(name)) != 0) {
|
||||
const char* url = NULL;
|
||||
for(u32 i = 0; i < json_array_size(objs); i++) {
|
||||
json_t* obj = json_array_get(objs, i);
|
||||
if(json_is_object(obj)) {
|
||||
json_t* idJson = json_object_get(obj, "id");
|
||||
json_t* versionJson = json_object_get(obj, "version");
|
||||
if(json_is_integer(idJson) && json_is_string(versionJson)) {
|
||||
u32 id = (u32) json_integer_value(idJson);
|
||||
const char* version = json_string_value(versionJson);
|
||||
|
||||
for(u32 i = 0; i < json_array_size(assets); i++) {
|
||||
json_t* val = json_array_get(assets, i);
|
||||
if(json_is_object(val)) {
|
||||
json_t* assetName = json_object_get(val, "name");
|
||||
json_t* assetUrl = json_object_get(val, "browser_download_url");
|
||||
u32 major = 0;
|
||||
u32 minor = 0;
|
||||
u32 micro = 0;
|
||||
sscanf(version, "%lu.%lu.%lu", &major, &minor, µ);
|
||||
|
||||
if(json_is_string(assetName) && json_is_string(assetUrl)) {
|
||||
if(strncmp(json_string_value(assetName), fs_get_3dsx_path() != NULL ? "FBI.3dsx" : "FBI.cia", json_string_length(assetName)) == 0) {
|
||||
url = json_string_value(assetUrl);
|
||||
break;
|
||||
}
|
||||
if(major > latestMajor
|
||||
|| (major == latestMajor && minor > latestMinor)
|
||||
|| (major == latestMajor && minor == latestMinor && micro > latestMicro)) {
|
||||
latestId = id;
|
||||
latestMajor = major;
|
||||
latestMinor = minor;
|
||||
latestMicro = micro;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(url != NULL) {
|
||||
strncpy(updateURL, url, DOWNLOAD_URL_MAX);
|
||||
hasUpdate = true;
|
||||
} else {
|
||||
res = R_APP_BAD_DATA;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = R_APP_BAD_DATA;
|
||||
|
||||
if(latestMajor > VERSION_MAJOR
|
||||
|| (latestMajor == VERSION_MAJOR && latestMinor > VERSION_MINOR)
|
||||
|| (latestMajor == VERSION_MAJOR && latestMinor == VERSION_MINOR && latestMicro > VERSION_MICRO)) {
|
||||
snprintf(updateURL, DOWNLOAD_URL_MAX, "https://3ds.titledb.com/v1/%s/%lu/download", type, latestId);
|
||||
hasUpdate = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = R_APP_BAD_DATA;
|
||||
|
Loading…
x
Reference in New Issue
Block a user