From e72c6c1cea4457ef23ad7457c5c4b5699c577130 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Sun, 26 Feb 2017 09:21:43 -0800 Subject: [PATCH] Add action to update all TitleDB titles, make URL install buffer allocation use max constants. --- source/ui/section/action/action.h | 6 +++- source/ui/section/action/installtitledb.c | 37 +++++++++++++++++++++-- source/ui/section/action/urlinstall.c | 15 ++++----- source/ui/section/remoteinstall.c | 29 ++++++++++++------ source/ui/section/task/listtitledb.c | 6 ++-- source/ui/section/task/task.h | 1 + source/ui/section/titledb.c | 2 ++ 7 files changed, 72 insertions(+), 24 deletions(-) diff --git a/source/ui/section/action/action.h b/source/ui/section/action/action.h index 8fc659e..53fb922 100644 --- a/source/ui/section/action/action.h +++ b/source/ui/section/action/action.h @@ -4,6 +4,9 @@ typedef struct ticket_info_s ticket_info; typedef struct linked_list_s linked_list; typedef struct list_item_s list_item; +#define INSTALL_URL_MAX 1024 +#define INSTALL_URLS_MAX 128 + void action_browse_boss_ext_save_data(linked_list* items, list_item* selected); void action_browse_user_ext_save_data(linked_list* items, list_item* selected); void action_delete_ext_save_data(linked_list* items, list_item* selected); @@ -51,4 +54,5 @@ void action_delete_secure_value(linked_list* items, list_item* selected); void action_url_install(const char* confirmMessage, const char* urls, void* finishedData, void (*finished)(void* data)); -void action_install_titledb(linked_list* items, list_item* selected); \ No newline at end of file +void action_install_titledb(linked_list* items, list_item* selected); +void action_update_titledb(linked_list* items, list_item* selected); \ No newline at end of file diff --git a/source/ui/section/action/installtitledb.c b/source/ui/section/action/installtitledb.c index 82ad645..e231fd4 100644 --- a/source/ui/section/action/installtitledb.c +++ b/source/ui/section/action/installtitledb.c @@ -1,14 +1,45 @@ #include +#include #include <3ds.h> #include "action.h" #include "../task/task.h" +#include "../../error.h" #include "../../list.h" +#include "../../../core/linkedlist.h" void action_install_titledb(linked_list* items, list_item* selected) { - char url[128]; - snprintf(url, sizeof(url), "https://api.titledb.com/v0/proxy/%016llX", ((titledb_info*) selected->data)->titleId); + char* url = (char*) calloc(1, INSTALL_URL_MAX); + if(url != NULL) { + snprintf(url, INSTALL_URL_MAX, "https://api.titledb.com/v0/proxy/%016llX", ((titledb_info*) selected->data)->titleId); + action_url_install("Install the selected title from TitleDB?", url, NULL, NULL); - action_url_install("Install the selected title from TitleDB?", url, NULL, NULL); + free(url); + } else { + error_display_res(NULL, NULL, R_FBI_OUT_OF_MEMORY, "Failed to allocate URL text buffer."); + } +} + +void action_update_titledb(linked_list* items, list_item* selected) { + char* urls = (char*) calloc(1, INSTALL_URL_MAX * INSTALL_URLS_MAX); + if(urls != NULL) { + linked_list_iter iter; + linked_list_iterate(items, &iter); + + size_t pos = 0; + while(linked_list_iter_has_next(&iter) && pos < INSTALL_URL_MAX * INSTALL_URLS_MAX) { + titledb_info* info = (titledb_info*) ((list_item*) linked_list_iter_next(&iter))->data; + + if(info->installed) { + pos += snprintf(urls + pos, (INSTALL_URL_MAX * INSTALL_URLS_MAX) - pos, "https://api.titledb.com/v0/proxy/%016llX\n", info->titleId); + } + } + + action_url_install("Update installed titles from TitleDB?", urls, NULL, NULL); + + free(urls); + } else { + error_display_res(NULL, NULL, R_FBI_OUT_OF_MEMORY, "Failed to allocate URL text buffer."); + } } \ No newline at end of file diff --git a/source/ui/section/action/urlinstall.c b/source/ui/section/action/urlinstall.c index 8322ed6..c5a5589 100644 --- a/source/ui/section/action/urlinstall.c +++ b/source/ui/section/action/urlinstall.c @@ -13,11 +13,8 @@ #include "../../../core/screen.h" #include "../../../core/util.h" -#define URL_MAX 1024 -#define URLS_MAX 128 - typedef struct { - char urls[URLS_MAX][URL_MAX]; + char urls[INSTALL_URLS_MAX][INSTALL_URL_MAX]; void* finishedData; void (*finished)(void* data); @@ -306,7 +303,7 @@ void action_url_install(const char* confirmMessage, const char* urls, void* fini size_t payloadLen = strlen(urls); if(payloadLen > 0) { const char* currStart = urls; - while(data->installInfo.total < URLS_MAX && currStart - urls < payloadLen) { + while(data->installInfo.total < INSTALL_URLS_MAX && currStart - urls < payloadLen) { const char* currEnd = strchr(currStart, '\n'); if(currEnd == NULL) { currEnd = urls + payloadLen; @@ -315,15 +312,15 @@ void action_url_install(const char* confirmMessage, const char* urls, void* fini u32 len = currEnd - currStart; if((len < 7 || strncmp(currStart, "http://", 7) != 0) && (len < 8 || strncmp(currStart, "https://", 8) != 0)) { - if(len > URL_MAX - 7) { - len = URL_MAX - 7; + if(len > INSTALL_URL_MAX - 7) { + len = INSTALL_URL_MAX - 7; } strncpy(data->urls[data->installInfo.total], "http://", 7); strncpy(&data->urls[data->installInfo.total][7], currStart, len); } else { - if(len > URL_MAX) { - len = URL_MAX; + if(len > INSTALL_URL_MAX) { + len = INSTALL_URL_MAX; } strncpy(data->urls[data->installInfo.total], currStart, len); diff --git a/source/ui/section/remoteinstall.c b/source/ui/section/remoteinstall.c index be5dd03..ec371d5 100644 --- a/source/ui/section/remoteinstall.c +++ b/source/ui/section/remoteinstall.c @@ -425,21 +425,32 @@ void remoteinstall_manually_enter_urls() { swkbdSetFeatures(&swkbd, SWKBD_MULTILINE); swkbdSetHintText(&swkbd, "Enter URL(s)"); - char textBuf[1024]; - if(swkbdInputText(&swkbd, textBuf, sizeof(textBuf)) == SWKBD_BUTTON_CONFIRM) { - remoteinstall_set_last_urls(textBuf); + char* textBuf = (char*) calloc(1, INSTALL_URL_MAX * INSTALL_URLS_MAX); + if(textBuf != NULL) { + if(swkbdInputText(&swkbd, textBuf, INSTALL_URL_MAX * INSTALL_URLS_MAX) == SWKBD_BUTTON_CONFIRM) { + remoteinstall_set_last_urls(textBuf); - action_url_install("Install from the entered URL(s)?", textBuf, NULL, NULL); - return; + action_url_install("Install from the entered URL(s)?", textBuf, NULL, NULL); + } + + free(textBuf); + } else { + error_display_res(NULL, NULL, R_FBI_OUT_OF_MEMORY, "Failed to allocate URL text buffer."); } } void remoteinstall_repeat_last_request() { - char textBuf[4096]; - if(remoteinstall_get_last_urls(textBuf, sizeof(textBuf))) { - action_url_install("Install from the last requested URL(s)?", textBuf, NULL, NULL); + char* textBuf = (char*) calloc(1, INSTALL_URL_MAX * INSTALL_URLS_MAX); + if(textBuf != NULL) { + if(remoteinstall_get_last_urls(textBuf, INSTALL_URL_MAX * INSTALL_URLS_MAX)) { + action_url_install("Install from the last requested URL(s)?", textBuf, NULL, NULL); + } else { + prompt_display("Failure", "No previously requested URL(s) could be found.", COLOR_TEXT, false, NULL, NULL, NULL); + } + + free(textBuf); } else { - prompt_display("Failure", "No previously requested URL(s) could be found.", COLOR_TEXT, false, NULL, NULL, NULL); + error_display_res(NULL, NULL, R_FBI_OUT_OF_MEMORY, "Failed to allocate URL text buffer."); } } diff --git a/source/ui/section/task/listtitledb.c b/source/ui/section/task/listtitledb.c index 1138045..9f4eb82 100644 --- a/source/ui/section/task/listtitledb.c +++ b/source/ui/section/task/listtitledb.c @@ -86,14 +86,16 @@ static void task_populate_titledb_thread(void* arg) { } } + AM_TitleEntry entry; + titledbInfo->installed = R_SUCCEEDED(AM_GetTitleInfo(util_get_title_destination(titledbInfo->titleId), 1, &titledbInfo->titleId, &entry)); + if(strlen(titledbInfo->meta.shortDescription) > 0) { strncpy(item->name, titledbInfo->meta.shortDescription, LIST_ITEM_NAME_MAX); } else { snprintf(item->name, LIST_ITEM_NAME_MAX, "%016llX", titledbInfo->titleId); } - AM_TitleEntry entry; - if(R_SUCCEEDED(AM_GetTitleInfo(util_get_title_destination(titledbInfo->titleId), 1, &titledbInfo->titleId, &entry))) { + if(titledbInfo->installed) { item->color = COLOR_INSTALLED; } else { item->color = COLOR_NOT_INSTALLED; diff --git a/source/ui/section/task/task.h b/source/ui/section/task/task.h index 62d3e4d..6b8cf34 100644 --- a/source/ui/section/task/task.h +++ b/source/ui/section/task/task.h @@ -73,6 +73,7 @@ typedef struct file_info_s { typedef struct titledb_info_s { u64 titleId; u64 size; + bool installed; meta_info meta; } titledb_info; diff --git a/source/ui/section/titledb.c b/source/ui/section/titledb.c index 2833431..b64192d 100644 --- a/source/ui/section/titledb.c +++ b/source/ui/section/titledb.c @@ -13,6 +13,7 @@ #include "../../core/screen.h" static list_item install = {"Install", COLOR_TEXT, action_install_titledb}; +static list_item update_all = {"Update All", COLOR_TEXT, action_update_titledb}; typedef struct { populate_titledb_data populateData; @@ -56,6 +57,7 @@ static void titledb_action_update(ui_view* view, void* data, linked_list* items, if(linked_list_size(items) == 0) { linked_list_add(items, &install); + linked_list_add(items, &update_all); } }