Use mtime from TitleDB instead of updated_at.

This commit is contained in:
Steveice10 2018-05-09 23:38:48 -07:00
parent 169147dab0
commit d9e12f8fdd
7 changed files with 51 additions and 37 deletions

View File

@ -31,11 +31,11 @@ static void action_install_titledb_finished_url(void* data, u32 index) {
titledb_cache_entry entry; titledb_cache_entry entry;
if(installData->cia) { if(installData->cia) {
entry.id = info->cia.id; entry.id = info->cia.id;
strncpy(entry.updatedAt, info->cia.updatedAt, sizeof(entry.updatedAt)); strncpy(entry.mtime, info->cia.mtime, sizeof(entry.mtime));
strncpy(entry.version, info->cia.version, sizeof(entry.version)); strncpy(entry.version, info->cia.version, sizeof(entry.version));
} else { } else {
entry.id = info->tdsx.id; entry.id = info->tdsx.id;
strncpy(entry.updatedAt, info->tdsx.updatedAt, sizeof(entry.updatedAt)); strncpy(entry.mtime, info->tdsx.mtime, sizeof(entry.mtime));
strncpy(entry.version, info->tdsx.version, sizeof(entry.version)); strncpy(entry.version, info->tdsx.version, sizeof(entry.version));
} }

View File

@ -36,11 +36,11 @@ static void action_update_titledb_finished_url(void* data, u32 index) {
titledb_cache_entry entry; titledb_cache_entry entry;
if(updateData->cia[index]) { if(updateData->cia[index]) {
entry.id = info->cia.id; entry.id = info->cia.id;
strncpy(entry.updatedAt, info->cia.updatedAt, sizeof(entry.updatedAt)); strncpy(entry.mtime, info->cia.mtime, sizeof(entry.mtime));
strncpy(entry.version, info->cia.version, sizeof(entry.version)); strncpy(entry.version, info->cia.version, sizeof(entry.version));
} else { } else {
entry.id = info->tdsx.id; entry.id = info->tdsx.id;
strncpy(entry.updatedAt, info->tdsx.updatedAt, sizeof(entry.updatedAt)); strncpy(entry.mtime, info->tdsx.mtime, sizeof(entry.mtime));
strncpy(entry.version, info->tdsx.version, sizeof(entry.version)); strncpy(entry.version, info->tdsx.version, sizeof(entry.version));
} }

View File

@ -111,7 +111,7 @@ static bool task_populate_titledb_cache_get(u32 id, bool cia, titledb_cache_entr
json_t* idJson = json_object_get(obj, "id"); json_t* idJson = json_object_get(obj, "id");
if(json_is_integer(idJson)) { if(json_is_integer(idJson)) {
entry->id = (u32) json_integer_value(idJson); entry->id = (u32) json_integer_value(idJson);
strncpy(entry->updatedAt, json_object_get_string(obj, "updated_at", "Unknown"), sizeof(entry->updatedAt)); strncpy(entry->mtime, json_object_get_string(obj, "mtime", "Unknown"), sizeof(entry->mtime));
strncpy(entry->version, json_object_get_string(obj, "version", "Unknown"), sizeof(entry->version)); strncpy(entry->version, json_object_get_string(obj, "version", "Unknown"), sizeof(entry->version));
return true; return true;
@ -125,7 +125,7 @@ void task_populate_titledb_cache_set(u32 id, bool cia, titledb_cache_entry* entr
json_t* obj = task_populate_titledb_cache_get_base(id, cia, true); json_t* obj = task_populate_titledb_cache_get_base(id, cia, true);
if(json_is_object(obj)) { if(json_is_object(obj)) {
json_object_set(obj, "id", json_integer(entry->id)); json_object_set(obj, "id", json_integer(entry->id));
json_object_set(obj, "updated_at", json_string(entry->updatedAt)); json_object_set(obj, "mtime", json_string(entry->mtime));
json_object_set(obj, "version", json_string(entry->version)); json_object_set(obj, "version", json_string(entry->version));
task_populate_titledb_cache_save(); task_populate_titledb_cache_save();
@ -195,9 +195,9 @@ static void task_populate_titledb_thread(void* arg) {
json_t* root = NULL; json_t* root = NULL;
if(R_SUCCEEDED(res = http_download_json("https://api.titledb.com/v1/entry?nested=true" if(R_SUCCEEDED(res = http_download_json("https://api.titledb.com/v1/entry?nested=true"
"&only=id&only=name&only=author&only=headline&only=category&only=updated_at" "&only=id&only=name&only=author&only=headline&only=category"
"&only=cia.id&only=cia.updated_at&only=cia.version&only=cia.size&only=cia.titleid" "&only=cia.id&only=cia.mtime&only=cia.version&only=cia.size&only=cia.titleid"
"&only=tdsx.id&only=tdsx.updated_at&only=tdsx.version&only=tdsx.size&only=tdsx.smdh.id", "&only=tdsx.id&only=tdsx.mtime&only=tdsx.version&only=tdsx.size&only=tdsx.smdh.id",
&root, 1024 * 1024))) { &root, 1024 * 1024))) {
if(json_is_array(root)) { if(json_is_array(root)) {
for(u32 i = 0; i < json_array_size(root) && R_SUCCEEDED(res); i++) { for(u32 i = 0; i < json_array_size(root) && R_SUCCEEDED(res); i++) {
@ -214,7 +214,6 @@ static void task_populate_titledb_thread(void* arg) {
if(titledbInfo != NULL) { if(titledbInfo != NULL) {
titledbInfo->id = (u32) json_object_get_integer(entry, "id", 0); titledbInfo->id = (u32) json_object_get_integer(entry, "id", 0);
strncpy(titledbInfo->category, json_object_get_string(entry, "category", "Unknown"), sizeof(titledbInfo->category)); strncpy(titledbInfo->category, json_object_get_string(entry, "category", "Unknown"), sizeof(titledbInfo->category));
strncpy(titledbInfo->updatedAt, json_object_get_string(entry, "updated_at", "Unknown"), sizeof(titledbInfo->updatedAt));
strncpy(titledbInfo->meta.shortDescription, json_object_get_string(entry, "name", ""), sizeof(titledbInfo->meta.shortDescription)); strncpy(titledbInfo->meta.shortDescription, json_object_get_string(entry, "name", ""), sizeof(titledbInfo->meta.shortDescription));
strncpy(titledbInfo->meta.publisher, json_object_get_string(entry, "author", ""), sizeof(titledbInfo->meta.publisher)); strncpy(titledbInfo->meta.publisher, json_object_get_string(entry, "author", ""), sizeof(titledbInfo->meta.publisher));
@ -236,12 +235,12 @@ static void task_populate_titledb_thread(void* arg) {
for(u32 j = 0; j < json_array_size(cias); j++) { for(u32 j = 0; j < json_array_size(cias); j++) {
json_t* cia = json_array_get(cias, j); json_t* cia = json_array_get(cias, j);
if(json_is_object(cia)) { if(json_is_object(cia)) {
const char* updatedAt = json_object_get_string(cia, "updated_at", "Unknown"); const char* mtime = json_object_get_string(cia, "mtime", "Unknown");
if(!titledbInfo->cia.exists || task_populate_titledb_compare_dates(updatedAt, titledbInfo->cia.updatedAt, sizeof(titledbInfo->cia.updatedAt)) >= 0) { if(!titledbInfo->cia.exists || task_populate_titledb_compare_dates(mtime, titledbInfo->cia.mtime, sizeof(titledbInfo->cia.mtime)) >= 0) {
titledbInfo->cia.exists = true; titledbInfo->cia.exists = true;
titledbInfo->cia.id = (u32) json_object_get_integer(cia, "id", 0); titledbInfo->cia.id = (u32) json_object_get_integer(cia, "id", 0);
strncpy(titledbInfo->cia.updatedAt, updatedAt, sizeof(titledbInfo->cia.updatedAt)); strncpy(titledbInfo->cia.mtime, mtime, sizeof(titledbInfo->cia.mtime));
strncpy(titledbInfo->cia.version, json_object_get_string(cia, "version", "Unknown"), sizeof(titledbInfo->cia.version)); strncpy(titledbInfo->cia.version, json_object_get_string(cia, "version", "Unknown"), sizeof(titledbInfo->cia.version));
titledbInfo->cia.size = (u32) json_object_get_integer(cia, "size", 0); titledbInfo->cia.size = (u32) json_object_get_integer(cia, "size", 0);
titledbInfo->cia.titleId = strtoull(json_object_get_string(cia, "titleid", "0"), NULL, 16); titledbInfo->cia.titleId = strtoull(json_object_get_string(cia, "titleid", "0"), NULL, 16);
@ -255,12 +254,12 @@ static void task_populate_titledb_thread(void* arg) {
for(u32 j = 0; j < json_array_size(tdsxs); j++) { for(u32 j = 0; j < json_array_size(tdsxs); j++) {
json_t* tdsx = json_array_get(tdsxs, j); json_t* tdsx = json_array_get(tdsxs, j);
if(json_is_object(tdsx)) { if(json_is_object(tdsx)) {
const char* updatedAt = json_object_get_string(tdsx, "updated_at", "Unknown"); const char* mtime = json_object_get_string(tdsx, "mtime", "Unknown");
if(!titledbInfo->tdsx.exists || task_populate_titledb_compare_dates(updatedAt, titledbInfo->tdsx.updatedAt, sizeof(titledbInfo->tdsx.updatedAt)) >= 0) { if(!titledbInfo->tdsx.exists || task_populate_titledb_compare_dates(mtime, titledbInfo->tdsx.mtime, sizeof(titledbInfo->tdsx.mtime)) >= 0) {
titledbInfo->tdsx.exists = true; titledbInfo->tdsx.exists = true;
titledbInfo->tdsx.id = (u32) json_object_get_integer(tdsx, "id", 0); titledbInfo->tdsx.id = (u32) json_object_get_integer(tdsx, "id", 0);
strncpy(titledbInfo->tdsx.updatedAt, updatedAt, sizeof(titledbInfo->tdsx.updatedAt)); strncpy(titledbInfo->tdsx.mtime, mtime, sizeof(titledbInfo->tdsx.mtime));
strncpy(titledbInfo->tdsx.version, json_object_get_string(tdsx, "version", "Unknown"), sizeof(titledbInfo->tdsx.version)); strncpy(titledbInfo->tdsx.version, json_object_get_string(tdsx, "version", "Unknown"), sizeof(titledbInfo->tdsx.version));
titledbInfo->tdsx.size = (u32) json_object_get_integer(tdsx, "size", 0); titledbInfo->tdsx.size = (u32) json_object_get_integer(tdsx, "size", 0);
@ -275,6 +274,21 @@ static void task_populate_titledb_thread(void* arg) {
} }
} }
char* latestTime = "Unknown";
if(titledbInfo->cia.exists && titledbInfo->tdsx.exists) {
if(task_populate_titledb_compare_dates(titledbInfo->cia.mtime, titledbInfo->tdsx.mtime, sizeof(titledbInfo->cia.mtime)) >= 0) {
latestTime = titledbInfo->cia.mtime;
} else {
latestTime = titledbInfo->tdsx.mtime;
}
} else if(titledbInfo->cia.exists) {
latestTime = titledbInfo->cia.mtime;
} else if(titledbInfo->tdsx.exists) {
latestTime = titledbInfo->tdsx.mtime;
}
strncpy(titledbInfo->mtime, latestTime, sizeof(titledbInfo->mtime));
if((titledbInfo->cia.exists || titledbInfo->tdsx.exists) && (data->filter == NULL || data->filter(data->userData, titledbInfo))) { if((titledbInfo->cia.exists || titledbInfo->tdsx.exists) && (data->filter == NULL || data->filter(data->userData, titledbInfo))) {
strncpy(item->name, titledbInfo->meta.shortDescription, LIST_ITEM_NAME_MAX); strncpy(item->name, titledbInfo->meta.shortDescription, LIST_ITEM_NAME_MAX);
item->data = titledbInfo; item->data = titledbInfo;

View File

@ -5,7 +5,7 @@ typedef struct list_item_s list_item;
typedef struct titledb_cache_entry_s { typedef struct titledb_cache_entry_s {
u32 id; u32 id;
char updatedAt[32]; char mtime[32];
char version[32]; char version[32];
} titledb_cache_entry; } titledb_cache_entry;
@ -13,7 +13,7 @@ typedef struct titledb_cia_info_s {
bool exists; bool exists;
u32 id; u32 id;
char updatedAt[32]; char mtime[32];
char version[32]; char version[32];
u64 size; u64 size;
u64 titleId; u64 titleId;
@ -32,7 +32,7 @@ typedef struct titledb_tdsx_info_s {
bool exists; bool exists;
u32 id; u32 id;
char updatedAt[32]; char mtime[32];
char version[32]; char version[32];
u64 size; u64 size;
titledb_smdh_info smdh; titledb_smdh_info smdh;
@ -45,7 +45,7 @@ typedef struct titledb_info_s {
u32 id; u32 id;
char category[64]; char category[64];
char headline[512]; char headline[512];
char updatedAt[32]; char mtime[32];
titledb_cia_info cia; titledb_cia_info cia;
titledb_tdsx_info tdsx; titledb_tdsx_info tdsx;

View File

@ -279,8 +279,8 @@ void task_draw_titledb_info(ui_view* view, void* data, float x1, float y1, float
task_draw_meta_info(view, &info->meta, x1, y1, x2, y2); task_draw_meta_info(view, &info->meta, x1, y1, x2, y2);
char updatedAt[32]; char mtime[32];
task_format_date(updatedAt, info->updatedAt, sizeof(updatedAt)); task_format_date(mtime, info->mtime, sizeof(mtime));
char infoText[1024]; char infoText[1024];
@ -292,7 +292,7 @@ void task_draw_titledb_info(ui_view* view, void* data, float x1, float y1, float
"Update Available: %s", "Update Available: %s",
info->headline, info->headline,
info->category, info->category,
updatedAt, mtime,
(info->cia.installed && info->cia.installedInfo.id != info->cia.id) || (info->tdsx.installed && info->tdsx.installedInfo.id != info->tdsx.id) ? "Yes" : "No"); (info->cia.installed && info->cia.installedInfo.id != info->cia.id) || (info->tdsx.installed && info->tdsx.installedInfo.id != info->tdsx.id) ? "Yes" : "No");
float infoWidth; float infoWidth;
@ -308,11 +308,11 @@ void task_draw_titledb_info_cia(ui_view* view, void* data, float x1, float y1, f
task_draw_meta_info(view, &info->meta, x1, y1, x2, y2); task_draw_meta_info(view, &info->meta, x1, y1, x2, y2);
char dbUpdatedAt[32]; char dbMtime[32];
task_format_date(dbUpdatedAt, info->cia.updatedAt, sizeof(dbUpdatedAt)); task_format_date(dbMtime, info->cia.mtime, sizeof(dbMtime));
char localUpdatedAt[32]; char localMtime[32];
task_format_date(localUpdatedAt, info->cia.installedInfo.updatedAt, sizeof(localUpdatedAt)); task_format_date(localMtime, info->cia.installedInfo.mtime, sizeof(localMtime));
char infoText[512]; char infoText[512];
@ -326,8 +326,8 @@ void task_draw_titledb_info_cia(ui_view* view, void* data, float x1, float y1, f
"Update Available: %s", "Update Available: %s",
info->cia.titleId, info->cia.titleId,
ui_get_display_size(info->cia.size), ui_get_display_size_units(info->cia.size), ui_get_display_size(info->cia.size), ui_get_display_size_units(info->cia.size),
dbUpdatedAt, dbMtime,
info->cia.installed ? localUpdatedAt : "Not Installed", info->cia.installed ? localMtime : "Not Installed",
info->cia.version, info->cia.version,
info->cia.installed ? info->cia.installedInfo.version : "Not Installed", info->cia.installed ? info->cia.installedInfo.version : "Not Installed",
info->cia.installed && info->cia.installedInfo.id != info->cia.id ? "Yes" : "No"); info->cia.installed && info->cia.installedInfo.id != info->cia.id ? "Yes" : "No");
@ -345,11 +345,11 @@ void task_draw_titledb_info_tdsx(ui_view* view, void* data, float x1, float y1,
task_draw_meta_info(view, &info->meta, x1, y1, x2, y2); task_draw_meta_info(view, &info->meta, x1, y1, x2, y2);
char dbUpdatedAt[32]; char dbMtime[32];
task_format_date(dbUpdatedAt, info->tdsx.updatedAt, sizeof(dbUpdatedAt)); task_format_date(dbMtime, info->tdsx.mtime, sizeof(dbMtime));
char localUpdatedAt[32]; char localMtime[32];
task_format_date(localUpdatedAt, info->tdsx.installedInfo.updatedAt, sizeof(localUpdatedAt)); task_format_date(localMtime, info->tdsx.installedInfo.mtime, sizeof(localMtime));
char infoText[512]; char infoText[512];
@ -361,8 +361,8 @@ void task_draw_titledb_info_tdsx(ui_view* view, void* data, float x1, float y1,
"Local Version: %s\n" "Local Version: %s\n"
"Update Available: %s", "Update Available: %s",
ui_get_display_size(info->tdsx.size), ui_get_display_size_units(info->tdsx.size), ui_get_display_size(info->tdsx.size), ui_get_display_size_units(info->tdsx.size),
dbUpdatedAt, dbMtime,
info->tdsx.installed ? localUpdatedAt : "Not Installed", info->tdsx.installed ? localMtime : "Not Installed",
info->tdsx.version, info->tdsx.version,
info->tdsx.installed ? info->tdsx.installedInfo.version : "Not Installed", info->tdsx.installed ? info->tdsx.installedInfo.version : "Not Installed",
info->tdsx.installed && info->tdsx.installedInfo.id != info->tdsx.id ? "Yes" : "No"); info->tdsx.installed && info->tdsx.installedInfo.id != info->tdsx.id ? "Yes" : "No");

View File

@ -196,7 +196,7 @@ static int titledb_compare(void* data, const void* p1, const void* p2) {
if(listData->sortByName) { if(listData->sortByName) {
return strncasecmp(info1->name, info2->name, sizeof(info1->name)); return strncasecmp(info1->name, info2->name, sizeof(info1->name));
} else if(listData->sortByUpdate) { } else if(listData->sortByUpdate) {
return strncasecmp(data2->updatedAt, data1->updatedAt, sizeof(data2->updatedAt)); return strncasecmp(data2->mtime, data1->mtime, sizeof(data2->mtime));
} else { } else {
return 0; return 0;
} }

View File

@ -77,7 +77,7 @@ static void update_check_update(ui_view* view, void* data, float* progress, char
|| (major == latestMajor && minor > latestMinor) || (major == latestMajor && minor > latestMinor)
|| (major == latestMajor && minor == latestMinor && micro > latestMicro)) { || (major == latestMajor && minor == latestMinor && micro > latestMicro)) {
updateData->data.id = subId; updateData->data.id = subId;
strncpy(updateData->data.updatedAt, updatedAt, sizeof(updateData->data.updatedAt)); strncpy(updateData->data.mtime, updatedAt, sizeof(updateData->data.mtime));
strncpy(updateData->data.version, version, sizeof(updateData->data.version)); strncpy(updateData->data.version, version, sizeof(updateData->data.version));
latestMajor = major; latestMajor = major;