Add action to update all TitleDB titles, make URL install buffer allocation use max constants.

This commit is contained in:
Steveice10 2017-02-26 09:21:43 -08:00
parent 39e1718c8d
commit e72c6c1cea
7 changed files with 72 additions and 24 deletions

View File

@ -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);
@ -52,3 +55,4 @@ 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);
void action_update_titledb(linked_list* items, list_item* selected);

View File

@ -1,14 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#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);
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.");
}
}

View File

@ -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);

View File

@ -425,22 +425,33 @@ 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) {
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;
}
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))) {
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 {
error_display_res(NULL, NULL, R_FBI_OUT_OF_MEMORY, "Failed to allocate URL text buffer.");
}
}
void remoteinstall_forget_last_request() {

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}